Исходники для Unigraphics NX создание отверстий на тонкостенном листе по точкам поверхности


Добавил:DMT
Дата создания:5 апреля 2008, 21:14
Дата обновления:5 апреля 2008, 21:14
Просмотров:5183 последний сегодня, 10:54
Комментариев: 2

Создание отверстий на тонкостенном листе по точкам поверхности

Данный исходник демонстрирует создание отверстий на поверхности модели. Задаётся поверхность на которой будут создаваться отверстия, параметры отверстий("диаметр","глубина","завышение") и точки на поверхности. Точки будут являтся центрами для цилиндров, которые в свою очередь будут вычитаться из поверхности тела образуя отверстия.
Код на C++
  1.  
  2. /* Include files */
  3. #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
  4. # include <strstream>
  5. # include <iostream>
  6. using std::ostrstream;
  7. using std::endl;
  8. using std::ends;
  9. using std::cerr;
  10. #else
  11. # include <strstream.h>
  12. # include <iostream.h>
  13. #endif
  14.  
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <time.h>
  19. #include <math.h>
  20.  
  21. #include <uf.h>
  22. #include <uf_ui.h>
  23. #include <uf_exit.h>
  24. #include <uf_obj.h>
  25. #include <uf_object_types.h>
  26. #include <uf_disp.h>
  27. #include <uf_modl.h>
  28. #include <uf_part.h>
  29. #include <uf_vec.h>
  30.  
  31. static FILE* prterr;
  32. static int errorCode;
  33. static tag_t part;
  34.  
  35. #define PRTERR if(errorCode)\
  36. {PrintErrorMessage(errorCode,__LINE__);goto term;}
  37.  
  38. //процедура расшифровки кода ошибки
  39. static void PrintErrorMessage(int errorCode, int line)
  40. {
  41. if(errorCode)
  42. {
  43. char message[133];
  44.  
  45. UF_get_fail_message(errorCode,message);
  46. UF_UI_set_status(message);
  47. fprintf(prterr,"errorCode=%d\tmessage=%s\tline=%d\n",errorCode,message,line);
  48. fflush(prterr);
  49. errorCode=0;
  50. }
  51. }
  52.  
  53. int face_init_proc(UF_UI_selection_p_t select, void* user_data)
  54. {
  55. int ret_code;
  56. int num_triples=1;
  57. UF_UI_mask_t mask_triples[]={UF_face_type,0,0};
  58.  
  59. ret_code=UF_UI_set_sel_mask
  60. (select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples,mask_triples);
  61.  
  62. if(ret_code==0)
  63. return UF_UI_SEL_SUCCESS;
  64.  
  65. return UF_UI_SEL_FAILURE;
  66.  
  67. }
  68.  
  69. int points_init_proc(UF_UI_selection_p_t select, void* user_data)
  70. {
  71. int ret_code;
  72. int num_triples=1;
  73. UF_UI_mask_t mask_triples[]={UF_point_type,0,0};
  74.  
  75. ret_code=UF_UI_set_sel_mask
  76. (select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples,mask_triples);
  77.  
  78. if(ret_code==0)
  79. return UF_UI_SEL_SUCCESS;
  80.  
  81. return UF_UI_SEL_FAILURE;
  82.  
  83. }
  84.  
  85. void do_it()
  86. {
  87. tag_t face_tag;
  88. tag_t body_obj_id;
  89. label_get_face:
  90. //
  91. {
  92. char* message="Выбери грань";
  93. char* title="Выбери грань";
  94. int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
  95. int response;
  96. tag_t object;
  97. double cursor[3];
  98. tag_t view;
  99.  
  100. errorCode=UF_UI_select_with_single_dialog
  101. (message,title,scope,face_init_proc,NULL,&response,&object,cursor,&view);PRTERR;
  102. switch(response)
  103. {
  104. case UF_UI_BACK:
  105. goto label_get_face;
  106.  
  107. case UF_UI_CANCEL:
  108. goto term;
  109.  
  110. case UF_UI_OK:
  111. break;
  112.  
  113. case UF_UI_OBJECT_SELECTED:
  114. break;
  115.  
  116. case UF_UI_OBJECT_SELECTED_BY_NAME:
  117. break;
  118. }
  119. if(object==NULL_TAG)
  120. {
  121. uc1601("Будьте любезны выбрать грань",1);
  122. goto label_get_face;
  123. }
  124.  
  125. //set highlight off
  126. errorCode=UF_DISP_set_highlight(object,0);PRTERR;
  127.  
  128. face_tag=object;
  129.  
  130. errorCode=UF_MODL_ask_face_body(face_tag,&body_obj_id);PRTERR;
  131.  
  132. }
  133. int count;
  134. tag_p_t point_group;
  135.  
  136. //выбор точек на поверхности
  137. label_get_points:
  138. {
  139. char* message="Выбери точки";
  140. char* title="Выбери точки";
  141. int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
  142. int response;
  143. tag_p_t object;
  144.  
  145. errorCode=UF_UI_select_with_class_dialog
  146. (message,title,scope,points_init_proc,NULL,&response,&count,&object);PRTERR;
  147. switch(response)
  148. {
  149. case UF_UI_BACK:
  150. goto label_get_face;
  151. case UF_UI_CANCEL:
  152. goto term;
  153. case UF_UI_OK:
  154. break;
  155. }
  156. if(count==0)
  157. {
  158. uc1601("будьте любезны выбрать точки!",1);
  159. goto label_get_points;
  160. }
  161. int i;
  162. for(i=0;i<count;i++)
  163. {
  164. //set highlight off
  165. errorCode=UF_DISP_set_highlight(object[i],0);PRTERR;
  166. }
  167. point_group=object;
  168.  
  169. }
  170.  
  171. double ra4[]={3.0,4.0,2.0};
  172. //запроси параметры отверстия
  173. {
  174. int ret_code;
  175. char* cp1="укажи параметры отверстия";
  176. int ip3=3;
  177. char cp2[][16]={"диаметр","глубина","завышение"};
  178.  
  179. ret_code=uc1609(cp1,cp2,ip3,ra4,0);
  180.  
  181. switch(ret_code)
  182. {
  183. case 1:
  184. goto label_get_points;
  185. case 2:
  186. goto term;
  187. case 3:
  188. break;
  189. case 4:
  190. break;
  191. case 8:
  192. fprintf(prterr,"\n Disallowed state, unable to bring up dialog line%d\n",__LINE__);
  193. goto term;
  194. }
  195.  
  196. }
  197.  
  198. //определяем нормаль в точке поверхности
  199. {
  200. double parm[ 2 ];
  201. double face_pnt[ 3 ];
  202. int i;
  203. double point_coords[3];
  204. double u1[ 3 ];
  205. double v1[ 3 ];
  206. double u2[ 3 ];
  207. double v2[ 3 ];
  208. double unit_norm[ 3 ];
  209. double radii[ 2 ];
  210. UF_FEATURE_SIGN sign=UF_POSITIVE;/*UF_NEGATIVE;*/
  211. double origin[3];
  212. double negated_vector[3];
  213. tag_t cyl_tag;
  214. char diam[100];
  215. char height[100];
  216.  
  217.  
  218. for(i=0;i<count;i++)
  219. {
  220. errorCode=UF_CURVE_ask_point_data(point_group[i],point_coords);PRTERR;
  221.  
  222. errorCode=UF_MODL_ask_face_parm(face_tag,point_coords,parm,face_pnt);PRTERR;
  223.  
  224. errorCode=UF_MODL_ask_face_props(face_tag,parm,face_pnt,u1,v1,u2,v2,unit_norm,radii);PRTERR;
  225.  
  226. UF_VEC3_linear_comb(1,point_coords,ra4[2],unit_norm,origin);
  227. UF_VEC3_negate(unit_norm,negated_vector);
  228. sprintf(diam,"%f",ra4[0]);
  229. sprintf(height,"%f",ra4[1]+ra4[2]);
  230.  
  231. errorCode=UF_MODL_create_cylinder
  232. (sign,body_obj_id,origin,height,diam,negated_vector,&cyl_tag);PRTERR;
  233.  
  234. }
  235.  
  236. }
  237. goto term;
  238. term:
  239. return;
  240. }
  241.  
  242. /*****************************************************************************
  243. ** Activation Methods
  244. *****************************************************************************/
  245. /* Explicit Activation
  246. ** This entry point is used to activate the application explicitly, as in
  247. ** "File->Execute UG/Open->User Function..." */
  248. extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
  249. {
  250. //переменные обработки времени
  251. struct tm* newtime;
  252. time_t aclock,start_time,finish_time;
  253. double work_time;
  254. int min,sec;
  255.  
  256. time(&start_time);
  257.  
  258. //попытка открыть файл ошибок на D:
  259. if((prterr=fopen("D:\\prterr.txt","w"))!=NULL)
  260. {
  261. //uc1601("жми ОК и работай дальше",1);
  262. goto label_clock;
  263. }
  264.  
  265. //попытка открыть файл ошибок на C:\TEMP
  266. if((prterr=fopen("C:\\temp\\prterr.txt","w"))!=NULL)
  267. {
  268. //uc1601("жми ОК и работай дальше",1);
  269. goto label_clock;
  270. }
  271.  
  272. //файл ошибок разместить не удалось
  273. uc1601("не могу разместить файл ошибок",1);
  274. return;
  275.  
  276.  
  277. label_clock:
  278. time(&aclock);
  279. newtime=localtime(&aclock);
  280.  
  281. fprintf(prterr,"\n<create_hole_at_surface> HAS STARTED line=%d\n\n",__LINE__);
  282.  
  283. fprintf(prterr,"время начала работы программы: %s\n\n",asctime(newtime));
  284.  
  285. errorCode=UF_initialize();PRTERR;
  286.  
  287.  
  288. //проверь открытие файла модели или сборки
  289. part=UF_PART_ask_display_part();
  290. if(part==NULL_TAG)
  291. {
  292. uc1601("открой непустой файл!",1);
  293. fprintf(prterr,"\n открой непустой файл line=%d\n",__LINE__);
  294. goto term;
  295. }
  296.  
  297.  
  298. /* TODO: Add your application code here */
  299. do_it();
  300.  
  301.  
  302. errorCode=UF_terminate();PRTERR;
  303.  
  304. term:
  305. time(&finish_time);
  306. work_time=difftime(finish_time,start_time);
  307. min=(int)work_time/60;
  308. sec=(int)(work_time-min*60);
  309.  
  310. fprintf(prterr,"\n<create_hole_at_surface> HAS ENDED line=%d\n\n",__LINE__);
  311. fprintf(prterr,"working time is %u min %u sec\n",min,sec);
  312.  
  313. fflush(prterr);
  314. fclose(prterr);
  315.  
  316. return;
  317.  
  318.  
  319. }
  320.  
  321.  
  322.  
  323. /*****************************************************************************
  324. ** Utilities
  325. *****************************************************************************/
  326.  
  327. /* Unload Handler
  328. ** This function specifies when to unload your application from Unigraphics.
  329. ** If your application registers a callback (from a MenuScript item or a
  330. ** User Defined Object for example), this function MUST return
  331. ** "UF_UNLOAD_UG_TERMINATE". */
  332. extern int ufusr_ask_unload( void )
  333. {
  334. return( UF_UNLOAD_IMMEDIATELY );
  335. }
При использовании обязательна ссылка на http://DMTSoft.ru
up

Комментарии для "Исходники для Unigraphics NX создание отверстий на тонкостенном листе по точкам поверхности"


Пользователь: хамелеон
Сообщений: 1
Статус: Незримый
Зарегистрирован:
31 августа 2008, 22:40
Был:31 августа 2008, 22:45
хамелеон
smsup
Дата: 31 августа 2008, 22:45 Сообщение № 1
sm
Пользователь: aggressive
Сообщений: 2
Статус: Незримый
Зарегистрирован:
26 июня 2009, 20:02
Был:28 июня 2009, 23:56
aggressive
smsup
Дата: 26 июня 2009, 20:05 Сообщение № 2
Код хороший, но неполный. Создаются цилиндрики, которые потом не вычитаются из тела. Где можно поглядеть полный код?