选择平面,创建中心线
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include "uf_layer.h"
#include <stdio.h>
#include <uf.h>
#include <uf_modl.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_object_types.h>
#include <uf_ui.h>
#include <uf_part.h>
#include "uf_obj.h"
#include "math.h"
static int init_proc(UF_UI_selection_p_t select,void* user_data)
{
int num_triples = 2; //只选择一种类型
UF_UI_mask_t mask_triples[] = {UF_cylinder_subtype,0,0,
UF_bounded_plane_subtype,1,0};
if((UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
num_triples, mask_triples)) == 0)
{
return (UF_UI_SEL_SUCCESS);
}
else
{
return (UF_UI_SEL_FAILURE);
}
}
static void Create_Center(void)
{
tag_t user_wcs;
UF_CSYS_ask_wcs(&user_wcs);
char cue[] = "简简单单:请选择单个平面";
char title[] = "简简单单:对象选择对话框";
int response=0;
tag_t object;
int count=0;
double cursor;
tag_t view;
l10:
UF_UI_select_with_single_dialog(cue,title,0,init_proc, NULL,&response,&object,cursor,&view);
if(response==UF_UI_BACK) return; //如果点后退就跳转到L10
if(response==UF_UI_CANCEL) return; //如果点取消就退出
UF_DISP_set_highlight(object,0); //取消高亮显示
int type;
double point,dir_z, box;
double radius,rad_data;
int norm_dir;
UF_MODL_ask_face_data (object,&type,point,dir_z,box,&radius,&rad_data,&norm_dir); //得到面的法向norm_dir,+1为正向,-1为负向
tag_t matrix_id;
tag_t csys_id;
double matrix_values;
UF_CSYS_ask_matrix_of_object (object,&matrix_id); //得到面的矩阵ID
UF_CSYS_ask_matrix_values(matrix_id,matrix_values); //赋值给matrix_values
if(norm_dir<0) //判断面的法向是否相反
{
matrix_values=-matrix_values;
matrix_values=-matrix_values;
matrix_values=-matrix_values;
matrix_values=-matrix_values;
matrix_values=-matrix_values;
matrix_values=-matrix_values;
UF_CSYS_create_matrix(matrix_values,&matrix_id);
}
UF_CSYS_create_temp_csys(point,matrix_id,&csys_id);
UF_CSYS_set_wcs(csys_id); //设置面的坐标系(位置不一定精确,可以通过后面修正)
UF_CSYS_set_wcs_display(0); //不显示坐标系(解决显示移动)
double boundingbox;
double boundingbox2;
double boundingbox3;
UF_MODL_ask_bounding_box_exact(object,csys_id,boundingbox,boundingbox2,boundingbox3);
if(type ==UF_cylinder_subtype)
{
double cyl1_pt;
tag_t cyl_line,cyl_pt;
UF_CURVE_line_t cyl1_line_coords;
double WCS_pt;
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS,point,UF_CSYS_ROOT_WCS_COORDS, cyl1_pt); //绝对坐标转wcs
cyl1_pt = WCS_pt;
cyl1_line_coords.start_point = cyl1_pt;
cyl1_line_coords.start_point = cyl1_pt;
cyl1_line_coords.start_point = cyl1_pt;
cyl1_line_coords.end_point = cyl1_pt;
cyl1_line_coords.end_point = cyl1_pt;
cyl1_line_coords.end_point = cyl1_pt + boundingbox3;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.start_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.start_point); //wcs转绝对坐标
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.end_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.end_point); //wcs转绝对坐标
UF_CURVE_create_line(&cyl1_line_coords,&cyl_line);
UF_OBJ_set_color(cyl_line,186);
UF_OBJ_set_font(cyl_line,UF_OBJ_FONT_CENTERLINE); //设置线型
UF_CSYS_set_wcs(user_wcs);
UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动)
goto l10;
}
double WCS_pt,center_pt;
tag_t xp1,xp2,yp1,yp2,c_pt,Xline,Yline;
UF_CURVE_line_t Xline_coords,Yline_coords;
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
center_pt = WCS_pt + boundingbox3/2;
center_pt = WCS_pt + boundingbox3/2;
center_pt = WCS_pt;
Xline_coords.start_point = WCS_pt + boundingbox3/2; //X方向wcs的值+面X方向的大小1/2
Xline_coords.start_point = WCS_pt;
Xline_coords.start_point = WCS_pt;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.start_point,UF_CSYS_ROOT_COORDS, Xline_coords.start_point); //wcs转绝对坐标
// UF_CURVE_create_point(Xline_coords.start_point,&xp1);
Xline_coords.end_point = WCS_pt + boundingbox3/2; //X方向wcs的值+面X方向的大小1/2
Xline_coords.end_point = WCS_pt + boundingbox3; //Y方向wcs的值+面Y方向的大小
Xline_coords.end_point = WCS_pt;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.end_point,UF_CSYS_ROOT_COORDS, Xline_coords.end_point); //wcs转绝对坐标
// UF_CURVE_create_point(Xline_coords.end_point,&xp2);
Yline_coords.start_point = WCS_pt;
Yline_coords.start_point = WCS_pt + boundingbox3/2;
Yline_coords.start_point = WCS_pt;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.start_point,UF_CSYS_ROOT_COORDS, Yline_coords.start_point); //wcs转绝对坐标
// UF_CURVE_create_point(Yline_coords.start_point,&yp1);
Yline_coords.end_point = WCS_pt + boundingbox3; //X方向wcs的值+面X方向的大小
Yline_coords.end_point = WCS_pt + boundingbox3/2;
Yline_coords.end_point = WCS_pt;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.end_point,UF_CSYS_ROOT_COORDS, Yline_coords.end_point); //wcs转绝对坐标
// UF_CURVE_create_point(Yline_coords.end_point,&yp2);
UF_CURVE_create_line(&Xline_coords,&Xline); //创建中心线
UF_CURVE_create_line(&Yline_coords,&Yline);
UF_OBJ_set_color(Xline,186); //设置颜色
UF_OBJ_set_color(Yline,186);
UF_OBJ_set_font(Xline,UF_OBJ_FONT_CENTERLINE); //设置线型
UF_OBJ_set_font(Yline,UF_OBJ_FONT_CENTERLINE); //设置线型
UF_CSYS_set_wcs(user_wcs);
UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动)
goto l10;
}
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
/* Initialize the API environment */
if( UF_initialize() )
{
return;
}
Create_Center();
UF_terminate();
}
extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_IMMEDIATELY );
}
呵呵,终于写好啦:lol 简简单单 发表于 2014-12-12 02:44
呵呵,终于写好啦
不错啊 老师多多指点才行:) 简简单单 发表于 2014-12-12 04:01
老师多多指点才行
后面把 UI加进去 就很强大了 好人一生平安!楼主好人啊
页:
[1]