请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
功能模板 1,制作对话框 1)进入User InterfaceStyler,设计好对话框,将Launch Dialog From改为Callback保存 2)将生成的对话框文件放在模板文件夹下,以记事本格式打开XX. _template.C文件,将extern int <enter the name ofyour function> ( int *response )改为extern int XXX ( int*response )后保存。 3)打开VC的Templet,依次点击Tools->options->directories,将XX.h所在的文件夹包含进去。 4)在Templet.cpp中加入#include"XX_template.c" #include "XX.h" 5)在程序内写入 intresponse; XXX (&response);点击F7,编译成功。 2,对话框求值,设值 UF_STYLER_item_value_type_tvalue; value.item_attr=UF_STYLER_VALUE; value.item_id=XXX; //在.h文件中定义的ID UF_STYLER_ask_value(dialog_id,&value); //读值 /*赋值到变量中,变量在.h文件中定义,根据对话框定义不同类型:real,string,strings, integer ,integers , real, reals*/ XXX=value.value.real;//赋值 value.item_id=XXX; //在.h文件中定义的ID value.count=1;//拉伸条移动 UF_STYLER_set_value(dialog_id,&value);//设值 UF_STYLER_free_value(&value); //释放空间 3, 1),设置控件的激活状态 UF_STYLER_item_value_type_t value; value.item_attr=UF_STYLER_SENSITIVITY; //指定设置控件的激活状态 ( X7 I1 y3 [/ |* ?# e$ | x
value.item_id= XXX ; //在.h文件中定义的ID value.value.integer=FALSE; // FALSE为不激活,TRUE为激活 UF_STYLER_set_value(dialog_id,&value); 2),设置对话框是否能选择物体 UF_UI_mask_t all_mask[] = { UF_circle_type,0, 0, UF_cylinder_type,0, 0, UF_line_type,0, 0 }; UF_STYLER_item_value_type_t value; value.item_attr=UF_STYLER_SELECTION; value.item_id=UF_STYLER_DIALOG_INDEX; UF_STYLER_ask_value(dialog_id0,&value); UF_UI_set_sel_type(value.value.selection,UF_UI_SEL_TYPE_INACTIVE_SELECTION );//不能选择 // UF_UI_SEL_TYPE_SINGLE_SELECTION - ?4 J& k3 R( D6 o
//UF_UI_SEL_TYPE_SINGLE_DESELECTION
. }; E4 w+ J% T; ~# @. w- }//UF_UI_SEL_TYPE_ROBUST_SELECTION 能选择- h! L6 p0 [* A
//UF_UI_SEL_TYPE_SINGLE_POSITION
" ~2 ~& F7 u4 Q3 T4 c- q, N8 |% C//UF_UI_SEL_TYPE_RECTANGLE_POSITION if ( ( UF_UI_set_sel_mask ( value.value.selection, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,2, all_mask ) ) ) { return(UF_UI_CB_CONTINUE_DIALOG); } 2,查询选择物体 UF_STYLER_item_value_type_tvalue; value.item_attr=UF_STYLER_SELECTION; value.item_id=UF_STYLER_DIALOG_INDEX; UF_STYLER_ask_value(dialog_id0,&value); UF_UI_ask_sel_object_list(value.value.selection,&count,&objects); 4,求三面交点 头文件 void change( double AB [3][4], int line);
* z% o" s }5 e: ^/ Wvoid row_change ( double AB [3][4], int row);
double xyz[3];///交点坐标 double AB [3][4] = { { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0,0}}; double dot_product; UF_VEC3_dot ( dir, center, &dot_product); AB [0][0] = dir[0]; AB [0][1] = dir[1]; AB [0][2] = dir[2]; AB [0][3] = dot_product; double dot_product1; UF_VEC3_dot ( dir1, center1, &dot_product1); AB [1][0] = dir1[0]; AB [1][1] = dir1[1]; AB [1][2] = dir1[2]; AB [1][3] = dot_product1; double dot_product2; UF_VEC3_dot ( dir2, floor_center, &dot_product2); AB [2][0] = dir2[0]; AB [2][1] = dir2[1]; AB [2][2] = dir2[2]; AB [2][3] = dot_product2; for ( int j = 0; j < 3; j++) { change ( AB, j); row_change ( AB, j); } xyz [2] = AB [2][3]; xyz [1] = AB [1][3] - AB [1][2] * xyz [2]; xyz [0] = AB [0][3] - AB [0][2] * xyz [2] - AB [0][1] * xyz[1]; 子函数: void change ( double AB[3][4], int line) { double max = 0; double buffer = 0; int bj = -1; double max_x = 0; for ( int i = line; i < 3; i++) { max_x = fabs( AB [line]); if ( max_x > max) {
2 B, b' Q; ]6 y. a+ ]/ I+ [ max = max_x;
bj = i; } } for ( int j = 0; j < 4; j++) { buffer = AB [bj][j]; AB [bj][j] = AB [line][j]; AB [line][j] = buffer; } } //初等行变换 void row_change ( doubleAB [3][4], int row) { for ( int j = row; j < 3 ; j++) { double divisor = AB [j][row]; if ( 0 != divisor) { for ( int i = row; i < 4; i++) { AB [j] = AB [j] / divisor; } } } for ( int k = ( row + 1); k < 3; k++) { if ( 0 != AB [k][row]) { for ( int l = 0; l < 4; l++) { AB [k][l] = AB [k][l] - AB [row][l]; } } } }
) B% Z% }/ C. |* @: u. S5,筛选边界
uf_loop_p_t loops_list=NULL;//回环ID UF_MODL_ask_face_loops(face,&loops_list );//查询回环 int loops_count=0;//回环数量 UF_MODL_ask_loop_list_count(loops_list,&loops_count);//查询回环数量 for (int l_i=0; l_i<loops_count; l_i++) { int loops_type=0;//回环类型 uf_list_p_t edge_list=NULL;//边缘菜单指针ID UF_MODL_ask_loop_list_item(loops_list,l_i,&loops_type,&edge_list); if (1==loops_type)// 边界=1, 洞=2, 其他=3 { int edge_count=0;//边缘数量 UF_MODL_ask_list_count ( edge_list, &edge_count ); tag_t edge_id=NULL;//边缘ID for(int edge_i=0; edge_i<edge_count;edge_i++) { UF_MODL_ask_list_item( edge_list,edge_i,&edge_id); UF_MODL_create_curve_from_edge(edge_id,&edge_id); } } } 6,transform转移 #include<uf_trns.h> 2 L* r' w, S) J5 ~4 H* {, A4 h
1)平移uf5943 2)缩放uf5944 3)旋转uf5945 double matrix [ 16 ]; int status; double angle=0;//旋转角度 uf5945(center,dir,&angle,matrix,&status); //center物体中心,dir法向 const int objects=1;//数量 const int move=1; // 1 :复制 2 :粘贴 const int layer=-1;//0:最初层; -1: 工作层; 1 - 256 : 指定层 const int trace_curves=2; //轨迹状态, 1 开, 2 关 uf5947(matrix,&obj_tag,&n_objects,&move, &layer,&trace_curves,NULL,NULL,&status); 4)投影uf5946 double matrix [ 16 ]; int status; uf5946(object,matrix,&status);//object:投影面或线,dir法向 const int objects=1;//数量 const int move=1; // 1 :复制 2 :粘贴 const int layer=-1;//0:最初层; -1: 工作层; 1 - 256 : 指定层 const int trace_curves=2; //轨迹状态, 1 开, 2 关 uf5947(matrix,&obj_tag,&n_objects,&move, &layer,&trace_curves,NULL,NULL,&status); 5)偏移相加 uf5942
6 A4 d/ Y- W8 _0 ^! O. i* }, f* a$ b7,裁剪片体
tag_t *trim_objects; trim_objects =new tag_t[count]; trim_objects =bound_id; voidtrim_sheet() { UF_MODL_vector_t projection_method ; projection_method.reverse_vector=0; projection_method.vector_type=UF_MODL_VECTOR_DIRECTION;
( z w* z# N1 v, K% _. G UF_MODL_vector_defined_by_union_tdir1;
UF_MODL_vector_direction_t dir2; dir2.xyz [0]=dir[0]; dir2.xyz [1]=dir[1]; dir2.xyz [2]=dir[2]; dir1.direction=dir2; projection_method.defined_by=dir1; double point_coords[3] ; point_coords[0]=center[0]; point_coords[1]=center[1]; point_coords[2]=center[2]; int gap_point_count ; double *gap_points; tag_t feature_obj_eid; UF_MODL_create_trimmed_sheet(sel_sheet,edge_count,trim_objects,&projection_method, 0,1,point_coords,0.1,&gap_point_count,&gap_points,&feature_obj_eid); } 8,offset偏移 char distance_str[] = {"10.0"};//偏移的距离 int num_curves; tag_t *offset_curves; UF_CURVE_offset_distance_data_t offset_distance; offset_distance.distance= distance_str; offset_distance.roUGh_type=1; UF_STRING_t input_string; input_string.id=curve_id;//加入想要偏移的线 input_string.num=1; //偏移矢量方向数量 input_string.string=&string_count;//偏移线的数量 intstring_dir=UF_MODL_CURVE_START_FROM_END; input_string.dir=&string_dir; UF_CURVE_offset_data_toffset_data; $ u* z0 S& R* C, o3 G2 V* |
offset_data.offset_def.distance_type1= &offset_distance; offset_data.input_curves= &input_string; offset_data.approximation_tolerance= 0.01; offset_data.string_tolerance=0.001; offset_data.offset_def.distance_type1= &offset_distance; offset_data.offset_type= UF_CURVE_OFFSET_DISTANCE_TANGENT; UF_CALL(UF_CURVE_create_offset_curve(&offset_data, &num_curves,&offset_curves)); 9,创建平面 UF_STRING_tgenerator; UF_STRING_p_tge = &generator; UF_MODL_init_string_list(ge); UF_MODL_create_string_list(1,12,ge); ge->string[0]= 1; ge->dir[0]= 1;//指定线从开始到结束 ge->id[0]= arc_id;//指定边界的id doubletol[3]; tol[0] =.001;//直线公差 tol[1] = .5* (PI/180);//圆弧公差 tol[2] =.02;//不起作用 UF_CALL(UF_MODL_create_bplane(ge,tol,&bplane)); 10,选择 1),点选择 tag_t point_tag; double point[3]; UF_UI_POINT_base_method_t base_method=UF_UI_POINT_INFERRED ; intpoint_res; UF_CALL(UF_UI_point_construct("选择起点",&base_method,&point_tag, point,&point_res)); if(point_res=UF_UI_OK&&NULL_TAG!=point_tag) { + F8 d! W) a! Z
} 2),向量选择 int mode = UF_UI_INFERRED ; int disp_flag = UF_UI_DISP_TEMP_VECTOR; double vec[3]; double vec_pnt[3]; int res_vec = 0; UF_initialize(); ifail= UF_UI_specify_vector( "Choose aVector",&mode,disp_flag, vec,vec_pnt,&res_vec); if( ifail != 0 || res_vec!= UF_UI_OK ) { UF_UI_ONT_refresh(); printf("No vector selected \n" ); } else { printf("Vect base (%f, %f, %f), direction (%f, %f, %f) \n", vec_pnt[0],vec_pnt[1], vec_pnt[2], vec[0], vec[1], vec[2] ); } 3),平面选择 tag_t plane_eid=NULL_TAG; double orientation[9] ={0,0,0,0,0,0,0,0,0}; double origin[3] = {0,0,0}; double pts[6] = {0,0,0,0,0,0}; int i, error_code = 0; int mode, display, response; mode = 1; display = 0; UF_initialize(); error_code = UF_UI_specify_plane( "Select Plane", &mode, display, &response, orientation, origin,&plane_eid); if ( !error_code && response != 1&& response != 2) { for (i=0; i<3; i++) pts = origin + orientation;
|& E8 R' S- e. s8 | for (i=3; i<6; i++)
pts = origin[i-3] + orientation; FTN(uf5374)(origin,pts,&pts[3],&plane_eid); } 11,临时点,线 void display_temporary_point_line( double point1[3], double point2[3]) { UF_DISP_view_type_twhich_views = UF_DISP_USE_WORK_VIEW; UF_OBJ_disp_props_ TColor; color.layer= 201; color.color= 186; color.blank_status= UF_OBJ_NOT_BLANKED; color.line_width= UF_OBJ_WIDTH_NORMAL; color.font=0; color.highlight_status= FALSE; UF_DISP_poly_marker_tmarker_type = UF_DISP_POINT; UF_DISP_display_temporary_point ( NULL,which_views, point1, &color, marker_type); UF_DISP_display_temporary_point ( NULL,which_views, point2, &color, marker_type); UF_DISP_display_temporary_line ( NULL,which_views, point1, point2, &color); } 12,WCS与绝对坐标转换 voidcycs_wcs(double point[]) { tag_t wcs_id,matrix_id; double matrix[ 9 ]; //wcs_origin:工作坐标系原点,vec:工作坐标系轴向量,point_origin:点到原点的矢量 double wcs_origin[3], vec[3][3],point_origin[3]; //1,得到工作坐标系 UF_CSYS_ask_wcs(&wcs_id); UF_CSYS_ask_csys_info(wcs_id,&matrix_id,wcs_origin); UF_CSYS_ask_matrix_values(matrix_id,matrix); 7 s. Y- |* S6 g3 u+ z4 p4 q
//2,得到工作坐标系轴向量 UF_MTX3_x_vec(matrix, vec[0]); UF_MTX3_y_vec(matrix, vec[1]); UF_MTX3_z_vec(matrix, vec[2]); for(inti=0;i<3;i++) { double tol; //3,得到点到工作坐标系原点矢量 UF_VEC3_unitize(vec,0.000001,&tol,vec); //4,得到点到工作坐标系原点矢量 point_origin=point-wcs_origin; } for(intj=0;j<3;j++) { UF_VEC3_dot(point_origin,vec[j],&point[j]); } } 13,三点求圆心 #include<iostream.h>
1 g n p2 l( Q: v2 a#include<math.h>
9 u M0 B3 [0 l$ k" T
* F- Y; [0 u. { s2 b: ?int main() { int x1,y1,x3,y3; double a,b,c,d,e,f; doubler,k1,k2,x,y,x2,y2; cout<<"请输入x1,y1,x2,y2,x3,y3"<<endl; cin>>x1>>y1>>x2>>y2>>x3>>y3; if((y1==y2)&&(y2==y3)) { cout<<"三点不构成圆!"<<endl; return 0; } if((y1!=y2)&&(y2!=y3)) { k1=(x2-x1)/(y2-y1); k2=(x3-x2)/(y3-y2); } if(k1==k2) { cout<<"三点不构成圆!"<<endl; return 0; }
2 Y$ n- v8 P# t& s! ^1 W C9 U a=2*(x2-x1);
b=2*(y2-y1); c=x2*x2+y2*y2-x1*x1-y1*y1; d=2*(x3-x2); e=2*(y3-y2); f=x3*x3+y3*y3-x2*x2-y2*y2; x=(b*f-e*c)/(b*d-e*a); y=(d*c-a*f)/(b*d-e*a); cout<<"圆心为("<<x<<","<<y<<")"<<endl; r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)); cout<<"半径为"<<r<<endl; return 0; } 14,查找圆心 UF_EVAL_p_tevaluator ; UF_EVAL_arc_tarc ; UF_EVAL_initialize(obj_tag,&evaluator); UF_EVAL_ask_arc(evaluator,&arc); UF_VEC3_copy(arc.center,point); 15, message_box void message_box(int *res_mes) { UF_UI_message_buttons_sbuttons; buttons.button1=TRUE; buttons.button2=FALSE; buttons.button3=TRUE; buttons.label1="OK"; buttons.label3="CANEL"; buttons.response1=UF_UI_OK; buttons.response3=UF_UI_CANCEL; char *string_msg; char*material_msg="ALL selcted objects will be removed"; string_msg =material_msg; UF_CALL(UF_UI_message_dialog("", UF_UI_MESSAGE_WARNING, 6 q/ Q G2 T: J
&material_msg, 1, TRUE, &buttons, res_mes )); } 16,选择过滤 static int init_add_face( UF_UI_selection_p_t select, void *client_data) { int nums = 1; UF_UI_mask_tmasks[] = { UF_solid_type,0, UF_UI_SEL_FEATURE_ANY_FACE}; if( (UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,nums,masks)==0) &&(UF_UI_set_sel_procs(select,filter_proc_circle,NULL,client_data)==0) ) { return(UF_UI_SEL_SUCCESS); } else { return(UF_UI_SEL_FAILURE); } } int find_tag( void * client_data,//用以传输过滤资料 tag_t object//现在鼠标所选物体ID ) { user_data *obj; obj=(user_data*)client_data; int find_face=true;//接受 char *string1;
A7 Y! ~0 Q; [! i string1=newchar[133];
string1=UF_TAG_ask_handle_of_tag(object); for(int i=0;i<过滤的数目;i++) { char *string2; string2=newchar[133]; string2=UF_TAG_ask_handle_of_tag(物体ID); if(strcmp(string1,string2)==0) { find_face=FALSE;//不接受 } delete[]string2; } delete []string1; return find_face;
/ a' B% D. H5 i5 f/ P" J |