Исходники для Unigraphics NX построение дуги по заданной системе координат, центру и углу


Добавил:DMT
Дата создания:5 апреля 2008, 20:54
Дата обновления:5 апреля 2008, 21:15
Просмотров:4869 последний сегодня, 0:45
Комментариев: 0

Построение дуги по системе координат, центру и углу

Построение дуги по заданной системе координат, центру и углу.
Код на C++
  1. /* Include files */
  2. #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
  3. # include <strstream>
  4. # include <iostream>
  5. using std::ostrstream;
  6. using std::endl;
  7. using std::ends;
  8. using std::cerr;
  9. #else
  10. # include <strstream.h>
  11. # include <iostream.h>
  12. #endif
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <math.h>
  19.  
  20. #include <uf.h>
  21. #include <uf_ui.h>
  22. #include <uf_exit.h>
  23. #include <uf_obj.h>
  24. #include <uf_object_types.h>
  25. #include <uf_disp.h>
  26. #include <uf_modl.h>
  27. #include <uf_part.h>
  28. #include <uf_vec.h>
  29.  
  30. #include <uf_curve.h>
  31. #include <uf_csys.h>
  32. #include <uf_defs.h>
  33. #include <uf_mtx.h>
  34.  
  35.  
  36. static FILE* prterr;
  37. static int errorCode;
  38. static tag_t part;
  39.  
  40. #define PRTERR if(errorCode)\
  41. {PrintErrorMessage(errorCode,__LINE__);errorCode=0;goto term;}
  42.  
  43. //процедура расшифровки кода ошибки
  44. static void PrintErrorMessage(int errorCode, int line)
  45. {
  46. if(errorCode)
  47. {
  48. char message[133];
  49.  
  50. UF_get_fail_message(errorCode,message);
  51. UF_UI_set_status(message);
  52. fprintf(prterr,"errorCode=%d\tmessage=%s\tline=%d\n",errorCode,message,line);
  53. fflush(prterr);
  54. }
  55. }
  56.  
  57. void do_it()
  58. {
  59. goto label_acr_3p;
  60.  
  61. //построение дуги по системе координат, центр и угол
  62. {
  63. tag_t arc_tag45;
  64. UF_CURVE_arc_t arc_coord45;
  65. double mat45[9];
  66.  
  67. /* Use X-axis for rotation. */
  68. double rot_axis[3] = {1.0,0.0,0.0};
  69.  
  70. /* Use 45 degrees as rotation angle */
  71. double angle45 = 45 * DEGRA;
  72.  
  73. /* Center of arc with respect to (0,0,0) of Absolute CSYS. */
  74. double vec[3] = {3.0,-2.0,1.5};
  75.  
  76. /* Create 45 degree orientation matrix. */
  77. UF_MTX3_rotate_about_axis(rot_axis,angle45,mat45);
  78.  
  79. /* Obtain mapped coordinates. */
  80. UF_MTX3_vec_multiply(vec,mat45,arc_coord45.arc_center);
  81. /* Fill out the data structure for the arc */
  82. errorCode=UF_CSYS_create_matrix(mat45,&arc_coord45.matrix_tag);PRTERR;
  83. arc_coord45.start_angle = 0.0;
  84. arc_coord45.end_angle = 360.0 * DEGRA;
  85. arc_coord45.radius = 2.0;/* Create the arc. */
  86. errorCode=UF_CURVE_create_arc(&arc_coord45,&arc_tag45);PRTERR;
  87. }
  88.  
  89. label_acr_3p:
  90. //построение дуги по 3-м точкам
  91. {
  92. int create_flag=1;
  93. double first_point[ 3 ]={1,0,0};
  94. double second_point[ 3 ]={0,1,0};
  95. double third_point[ 3 ]={1,1,1};
  96. tag_t arc_tag;
  97. errorCode=UF_CURVE_create_arc_thru_3pts
  98. (create_flag,first_point,second_point,third_point,&arc_tag);PRTERR;
  99. }
  100. goto term;
  101. term:
  102. return;
  103. }
  104.  
  105. /*****************************************************************************
  106. ** Activation Methods
  107. *****************************************************************************/
  108. /* Explicit Activation
  109. ** This entry point is used to activate the application explicitly, as in
  110. ** "File->Execute UG/Open->User Function..." */
  111. extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
  112. {
  113.  
  114. 836
  115. b8a
  116. //переменные обработки времени
  117. struct tm* newtime;
  118. time_t acloc
  119. 7a4
  120. k,start_time,finish_time;
  121. double work_time;
  122. int min,sec;
  123. time(&start_time);
  124. //попытка открыть файл ошибок на D:
  125. if((prterr=fopen("D:\\prterr.txt","w"))!=NULL)
  126. {
  127. //uc1601("жми ОК и работай дальше",1);
  128. goto label_clock;
  129. }
  130. //попытка открыть файл ошибок на C:\TEMP
  131. if((prterr=fopen("C:\\temp\\prterr.txt","w"))!=NULL)
  132. {
  133. //uc1601("жми ОК и работай дальше",1);
  134. goto label_clock;
  135. }
  136. //файл ошибок разместить не удалось
  137. uc1601("не могу разместить файл ошибок",1);
  138. return;
  139.  
  140.  
  141. label_clock:
  142. time(&aclock);
  143. newtime=localtime(&aclock);
  144.  
  145. fprintf(prterr,"\n<create_arc> HAS STARTED line=%d\n\n",__LINE__);
  146.  
  147. fprintf(prterr,"время начала работы программы: %s\n\n",asctime(newtime));
  148.  
  149. errorCode=UF_initialize();PRTERR;
  150.  
  151.  
  152. //проверь открытие файла модели или сборки
  153. part=UF_PART_ask_display_part();
  154. if(part==NULL_TAG)
  155. {
  156. uc1601("открой непустой файл!",1);
  157. fprintf(prterr,"\n открой непустой файл line=%d\n",__LINE__);
  158. goto term;
  159. }
  160. /* TODO: Add your application code here */
  161. do_it();
  162. errorCode=UF_terminate();PRTERR;
  163.  
  164. term:
  165. time(&finish_time);
  166. work_time=difftime(finish_time,start_time);
  167. min=(int)work_time/60;
  168. sec=(int)(work_time-min*60);
  169.  
  170. fprintf(prterr,"\n<create_arc> HAS ENDED line=%d\n\n",__LINE__);
  171. fprintf(prterr,"working time is %u min %u sec\n",min,sec);
  172.  
  173. fflush(prterr);
  174. fclose(prterr);
  175. return;
  176. }
  177.  
  178. /*****************************************************************************
  179. ** Utilities
  180. *****************************************************************************/
  181.  
  182. /* Unload Handler
  183. ** This function specifies when to unload your application from Unigraphics.
  184. ** If your application registers a callback (from a MenuScript item or a
  185. ** User Defined Object for example), this function MUST return
  186. ** "UF_UNLOAD_UG_TERMINATE". */
  187. extern int ufusr_ask_unload( void )
  188. {
  189. return( UF_UNLOAD_IMMEDIATELY );
  190. }
При использовании обязательна ссылка на http://DMTSoft.ru
up