UG二次开发模板(3)功能模板
功能模板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文件中定义的IDUF_STYLER_ask_value(dialog_id,&value); //读值/*赋值到变量中,变量在.h文件中定义,根据对话框定义不同类型:real,string,strings, integer ,integers , real, reals*/ XXX=value.value.real;//赋值 value.item_id=XXX; //在.h文件中定义的IDvalue.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; //指定设置控件的激活状态value.item_id= XXX ; //在.h文件中定义的IDvalue.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
//UF_UI_SEL_TYPE_SINGLE_DESELECTION
//UF_UI_SEL_TYPE_ROBUST_SELECTION 能选择
//UF_UI_SEL_TYPE_SINGLE_POSITION
//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 , int line);
void row_change ( double AB , int row); double xyz;///交点坐标 double AB = { { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0,0}}; double dot_product; UF_VEC3_dot ( dir, center, &dot_product); AB = dir; AB = dir; AB = dir; AB = dot_product; double dot_product1; UF_VEC3_dot ( dir1, center1, &dot_product1); AB = dir1; AB = dir1; AB = dir1; AB = dot_product1; double dot_product2; UF_VEC3_dot ( dir2, floor_center, &dot_product2); AB = dir2; AB = dir2; AB = dir2; AB = dot_product2; for ( int j = 0; j < 3; j++) { change ( AB, j); row_change ( AB, j); } xyz = AB ; xyz = AB - AB * xyz ; xyz = AB - AB * xyz - AB * xyz; 子函数:void change ( double AB, 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 ); if ( max_x > max) {
max = max_x; bj= i; } } for ( int j = 0; j < 4; j++) { buffer = AB ; AB = AB ; AB = buffer; }} //初等行变换void row_change ( doubleAB , int row){ for ( int j = row; j < 3 ; j++) { double divisor = AB ; if ( 0 != divisor) { for ( int i = row; i < 4; i++) { AB = AB / divisor; } } } for ( int k = ( row + 1); k < 3; k++) { if ( 0 != AB ) { for ( int l = 0; l < 4; l++) { AB = AB - AB ; } } }}
5,筛选边界 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>
1)平移uf59432)缩放uf59443)旋转uf5945double matrix [ 16 ]; int status; doubleangle=0;//旋转角度uf5945(center,dir,&angle,matrix,&status);//center物体中心,dir法向 const int objects=1;//数量 const intmove=1; // 1 :复制 2 :粘贴 const intlayer=-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)投影uf5946double matrix [ 16 ]; int status; uf5946(object,matrix,&status);//object:投影面或线,dir法向 const int objects=1;//数量 const intmove=1; // 1 :复制 2 :粘贴 const intlayer=-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
7,裁剪片体 tag_t*trim_objects;trim_objects =new tag_t;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;
UF_MODL_vector_defined_by_union_tdir1; UF_MODL_vector_direction_t dir2; dir2.xyz =dir; dir2.xyz =dir; dir2.xyz =dir; dir1.direction=dir2; projection_method.defined_by=dir1; double point_coords ; point_coords=center; point_coords=center; point_coords=center; 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"};//偏移的距离 intnum_curves;tag_t *offset_curves;UF_CURVE_offset_distance_data_toffset_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;
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= 1;ge->dir= 1;//指定线从开始到结束ge->id= arc_id;//指定边界的id doubletol; tol =.001;//直线公差tol = .5* (PI/180);//圆弧公差tol =.02;//不起作用 UF_CALL(UF_MODL_create_bplane(ge,tol,&bplane)); 10,选择1),点选择tag_t point_tag;double point; UF_UI_POINT_base_method_tbase_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){
} 2),向量选择 intmode = UF_UI_INFERRED ; intdisp_flag = UF_UI_DISP_TEMP_VECTOR;doublevec;doublevec_pnt;intres_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,vec_pnt, vec_pnt, vec, vec, vec );} 3),平面选择 tag_tplane_eid=NULL_TAG;double orientation ={0,0,0,0,0,0,0,0,0}; double origin = {0,0,0}; double pts = {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;
for (i=3; i<6; i++) pts = origin + orientation; FTN(uf5374)(origin,pts,&pts,&plane_eid); } 11,临时点,线 void display_temporary_point_line( double point1, double point2){ 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_twcs_id,matrix_id; double matrix[ 9 ]; //wcs_origin:工作坐标系原点,vec:工作坐标系轴向量,point_origin:点到原点的矢量 double wcs_origin, vec,point_origin; //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);
//2,得到工作坐标系轴向量 UF_MTX3_x_vec(matrix, vec); UF_MTX3_y_vec(matrix, vec); UF_MTX3_z_vec(matrix, vec); 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,&point); }} 13,三点求圆心#include<iostream.h>
#include<math.h>
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; }
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_boxvoid 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,
&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;
string1=newchar; string1=UF_TAG_ask_handle_of_tag(object); for(int i=0;i<过滤的数目;i++) { char *string2; string2=newchar; string2=UF_TAG_ask_handle_of_tag(物体ID); if(strcmp(string1,string2)==0) { find_face=FALSE;//不接受 } delete[]string2; } delete []string1; return find_face;
这大好模板,支持
页:
[1]