选择零件实体加入到选择的操作里

  1 #include <stdarg.h>
  2 //#include <stdio.h>
  3 #include <uf.h>
  4 #include <uf_object_types.h>
  5 #include <uf_part.h>
  6 #include <uf_ui.h>
  7 #include <uf_ui_ont.h>
  8 #include <uf_disp.h>
  9 #include <uf_retiring.h>
 10 #include <uf_obj.h>
 11 #include <uf_cam.h>
 12 #include <uf_camgeom.h>
 13 #include <uf_param.h>
 14 #include <string.h>
 15 #include <vector>
 16 
 17 //#define  MAX_CAMGEOM   200
 18 
 19 static int init_proc_body(UF_UI_selection_p_t select, void *user_data);
 20 static void init_camgeom_app_data(UF_CAMGEOM_app_data_p_t app_data);
 21 
 22 void ugdebugep(int line, const char* format, ...)
 23 {
 24     static char buf[1024];
 25     va_list     ap;
 26 
 27     sprintf(buf, "(%03d)", line);
 28     UF_UI_open_listing_window();
 29     UF_UI_write_listing_window(buf);
 30     va_start(ap, format);
 31     vsprintf(buf, format, ap);
 32     
 33     va_end(ap);
 34     UF_UI_write_listing_window(buf);
 35     UF_UI_write_listing_window("\n");
 36     
 37 }
 38 void pauseMsgbox(int line)
 39 {
 40     static char buf[16];
 41     sprintf(buf, "at line %d", line);
 42     uc1601(buf, 1);
 43 }
 44 #define  dp(...) ugdebugep(__LINE__ ,__VA_ARGS__);
 45 #define  markline ugdebugep(__LINE__ ,"at line");
 46 #define  dpause pauseMsgbox(__LINE__)
 47 
 48 
 49 static void do_camgeom_api(void)
 50 {
 51     //UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM] = { NULL };
 52     UF_CAMGEOM_app_data_p_t* app_data_list=NULL;
 53     tag_t                   *oper_tag = NULL , *entity_list = NULL;
 54     //entity_list[MAX_CAMGEOM] = { NULL_TAG };
 55     int                            i,entity_count = 0, oper_count = 0, err_code = 0, type = 0, subtype = 0;
 56     tag_t                   *entity_eid = NULL_TAG, view = NULL_TAG;
 57     logical                 auto_wall_selection = FALSE;
 58 
 59     //for (i = 0; i < MAX_CAMGEOM; i++) app_data_list[i] = NULL;
 60     if (UF_PART_ask_display_part() != null_tag)
 61     {        
 62         UF_UI_ONT_ask_selected_nodes(&oper_count, &oper_tag);        
 63         if (oper_count > 0)
 64         {
 65 
 66             
 67             
 68             char Cue[] = "选择";
 69             char Title[] = "功能测试";
 70             int Scope = UF_UI_SEL_SCOPE_NO_CHANGE;
 71             int Response, entity_count = 0;            
 72             UF_UI_select_with_class_dialog(Cue, Title, Scope, init_proc_body, NULL, &Response, &entity_count, &entity_eid);            
 73 
 74             //申请内存 
 75             app_data_list = new UF_CAMGEOM_app_data_p_t[entity_count];        
 76 
 77             
 78 
 79             for (size_t m = 0; m < entity_count; m++)
 80             {    
 81                 //entity_list[m] = entity_eid[m];
 82 
 83                 app_data_list[m] = new UF_CAMGEOM_app_data_t;
 84 
 85                 init_camgeom_app_data(app_data_list[m]);
 86 
 87                 UF_DISP_set_highlight(entity_eid[m], 0);
 88             
 89             }
 90 
 91             
 92 
 93             if (entity_count > 0)
 94             {
 95                 
 96                 for (i = 0; i < oper_count; i++)
 97                 {
 98                     
 99                     UF_OBJ_ask_type_and_subtype(oper_tag[i], &type, &subtype);
100                     if (type == UF_machining_operation_type)
101                     {                        
102                         UF_CAMGEOM_append_items(oper_tag[i], UF_CAM_part, entity_count, entity_eid, app_data_list);
103                     }
104                 }
105             }
106 
107             
108 
109             for (size_t m = 0; m < entity_count; m++)
110             {
111                 delete app_data_list[m];
112             }
113             delete []app_data_list;
114 
115             UF_free(entity_eid);
116         }
117     }
118 }
119 
120 static int init_proc_body(    UF_UI_selection_p_t select,    void* user_data)
121 {
122     int nums = 1;
123     UF_UI_mask_t masks[] = {     UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY };
124 
125     if ((UF_UI_set_sel_mask(select,    UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,    nums, masks)) == 0)
126     {
127         return (UF_UI_SEL_SUCCESS);
128     }
129     else
130     {
131         return (UF_UI_SEL_FAILURE);
132     }
133 }
134 
135 static void init_camgeom_app_data(UF_CAMGEOM_app_data_p_t app_data)
136 {
137     if (app_data)
138     {
139         app_data->has_stock = 0;
140         app_data->has_cut_stock = 0;
141         app_data->has_tolerances = 0;
142         app_data->has_feedrate = 0;
143         app_data->has_offset = 0;
144         app_data->has_avoidance_type = 0;
145         app_data->stock = 0.0;
146         app_data->cut_stock[0] = 0.0;
147         app_data->cut_stock[1] = 0.0;
148         app_data->cut_stock[2] = 0.0;
149         app_data->tolerances[0] = 0.0;
150         app_data->tolerances[1] = 0.0;
151         app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute;
152         app_data->feedrate_value = 10.0;
153         app_data->offset = 0.0;
154         app_data->avoidance_type = UF_CAM_avoidance_type_warning;
155     }
156 }
157 
158 
159 void ufusr(char *param, int *retcode, int param_len)
160 {
161     UF_initialize();
162 
163     do_camgeom_api();
164 
165     UF_terminate();
166 }
167 
168 int ufusr_ask_unload(void)
169 {
170     return (UF_UNLOAD_IMMEDIATELY);
171 }
172 /************************************************************/

特别感谢"梅子酱"同学的改进

posted @ 2020-05-11 15:32  老婆饼里有老婆  阅读(394)  评论(0编辑  收藏  举报