OPENC函数 UF_MODL UF_EVAL UF_VEC(孔位提点和孔的长度)(UF_MODL_ask_face_loops UF_EVAL_ask_arc UF_VEC3_distance等)

  1 //设置class_dialog选择过滤
  2 static int init_proc(UF_UI_selection_p_t select,void* user_data)
  3 {
  4     //过滤类别的个数
  5     int num_triples = 1;
  6     //
  7     UF_UI_mask_t mask_triples[] = {UF_face_type,0,0};
  8 
  9     if((UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples, mask_triples)) == 0)
 10     {
 11         return (UF_UI_SEL_SUCCESS);
 12     }
 13     else
 14     {
 15         return (UF_UI_SEL_FAILURE);
 16     }
 17     /*
 18         此处添加过滤可查看  uf_object_types.h  头文件
 19     */
 20 }
 21 extern DllExport void ufsta( char *param, int *returnCode, int rlen )
 22 {
 23     /* Initialize the API environment */
 24     if( UF_CALL(UF_initialize()) ) 
 25     {
 26         /* Failed to initialize */
 27         return;
 28     }
 29     
 30     /* TODO: Add your application code here */
 31     UF_initialize();
 32 
 33     //select_with_class_dialog
 34     char message[]="类选择对话框";
 35     char title[]="按类选择:";
 36     int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
 37     int response=0;
 38     int count=0;
 39     tag_t* objects=NULL;
 40     //ask_face_loops
 41     uf_loop_t *loop_list=NULL;
 42     //ask_loop_list_count
 43     int loops_count=0;
 44     //ask_loop_list_item
 45     int type=2;
 46     uf_list_t*hole_list=NULL;
 47     //ask_list_count
 48     int hole_edge_count=0;
 49     int face_count=0;
 50     int cylinder_count=0;
 51     //ask_list_item
 52     tag_t hole_edge_tag=NULL_TAG;
 53     tag_t face_tag=NULL_TAG;
 54     tag_t cylinder_tag_1=NULL_TAG;
 55     tag_t cylinder_tag_2=NULL_TAG;
 56     //ask_edge_type
 57     int edge_type_1=0;
 58     int edge_type_2=0;
 59     int face_type=0;
 60     //EVAL_initialize
 61     UF_EVAL_p_t evaluator_1=NULL;
 62     UF_EVAL_p_t evaluator_2=NULL;
 63     UF_EVAL_arc_t arc_1;
 64     UF_EVAL_arc_t arc_2;
 65     //ask_edge_faces
 66     uf_list_t *face_list=NULL;
 67     uf_list_t *edge_list=NULL;
 68     //CURVE_create_point
 69     double point[3]={0.0};
 70     tag_t point_tag=NULL_TAG;
 71     UF_UI_select_with_class_dialog (message,title,scope,init_proc,NULL,&response,&count,&objects);
 72     if (response == UF_UI_OK && count > 0)
 73     {
 74         for (int i=0; i<count; i++)
 75         {
 76             //面上所有的loops
 77             UF_MODL_ask_face_loops (objects[i],&loop_list);
 78             //loops的个数
 79             UF_MODL_ask_loop_list_count(loop_list,&loops_count);
 80             for (int j=0;j<loops_count;j++)
 81             {
 82                 //loops的分为内和外  这个是取内的
 83                 UF_MODL_ask_loop_list_item(loop_list,j,&type,&hole_list);
 84                 if (type==2)
 85                 {
 86                     //hole_list中链表的个数
 87                     UF_MODL_ask_list_count(hole_list,&hole_edge_count);
 88                     for (int k=0;k<hole_edge_count;k++)
 89                     {
 90                         //链表中的边tag
 91                         UF_MODL_ask_list_item (hole_list,k,&hole_edge_tag);
 92                         //边找面
 93                         UF_MODL_ask_edge_faces(hole_edge_tag,&face_list);
 94                         //面链表中的个数
 95                         UF_MODL_ask_list_count(face_list,&face_count);
 96                         for (int m=0;m<face_count;m++)
 97                         {
 98                             //链表中的边tag
 99                             UF_MODL_ask_list_item (face_list,m,&face_tag);
100                             UF_MODL_ask_face_type(face_tag,&face_type);
101                             if (face_type==UF_MODL_CYLINDRICAL_FACE)
102                             {
103                                 //面找边
104                                 UF_MODL_ask_face_edges(face_tag,&edge_list);
105                                 //圆柱的边链表
106                                 UF_MODL_ask_list_count(edge_list,&cylinder_count);
107                                 if (cylinder_count==2)//圆柱就两个边
108                                 {    
109                                     //得到圆柱边的tag
110                                     UF_MODL_ask_list_item (edge_list,0,&cylinder_tag_1);
111                                     UF_MODL_ask_list_item (edge_list,1,&cylinder_tag_2);
112                                     //得到边的类型
113                                     UF_MODL_ask_edge_type(cylinder_tag_1,&edge_type_1);
114                                     UF_MODL_ask_edge_type(cylinder_tag_2,&edge_type_2);
115                                     //曲线边分析
116                                     UF_EVAL_initialize(cylinder_tag_1,&evaluator_1);
117                                     UF_EVAL_initialize(cylinder_tag_2,&evaluator_2);
118                                     //得到圆心
119                                     UF_EVAL_ask_arc(evaluator_1,&arc_1);
120                                     UF_EVAL_ask_arc(evaluator_2,&arc_2);
121                                     if (edge_type_1== UF_MODL_CIRCULAR_EDGE && edge_type_2== UF_MODL_CIRCULAR_EDGE)
122                                     {
123                                         double cly_distance=0.0;
124                                         UF_VEC3_distance(arc_1.center,arc_2.center,&cly_distance);
125                                         char msg[256];
126                                         sprintf_s(msg,"圆柱的长度为:%0.2f\n",cly_distance);
127                                         UF_UI_open_listing_window();
128                                         UF_UI_write_listing_window(msg);
129                                     }
130                                 }
131                             } 
132                         }
133                     }
134                 } 
135             
136             //取消高亮显示
137             UF_DISP_set_highlight(objects[i], 0);}
138         }
139     }
140     //释放内存
141     UF_EVAL_free(evaluator_2);
142     UF_EVAL_free(evaluator_1);
143     UF_MODL_delete_list(&edge_list);
144     UF_MODL_delete_list(&hole_list);
145     UF_MODL_delete_loop_list(&loop_list);
146     UF_free(objects);
147 
148     UF_terminate();
149     /*
150     1.注意循环嵌套别乱了。建议多做打印测试
151     2.曲线边分析
152     3.if else 可以自己加(在最后加else)
153     4.可以做“孔位提点的工具”思路就是这个思路 用 UF_VEC3_copy 和 UF_CURVE_create_point 
154     */
155     /* Terminate the API environment */
156     UF_CALL(UF_terminate());
157 }

posted @ 2020-01-02 13:16  你好我叫赵老师  阅读(695)  评论(0编辑  收藏  举报