Данный исходник демонстрирует создание отверстий на поверхности модели. Задаётся поверхность на которой будут создаваться отверстия, параметры отверстий("диаметр","глубина","завышение") и точки на поверхности. Точки будут являтся центрами для цилиндров, которые в свою очередь будут вычитаться из поверхности тела образуя отверстия.
Код на C++ /* Include files */ #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun ) # include <strstream> # include <iostream> using std::ostrstream; using std::endl; using std::ends; using std::cerr; #else # include <strstream.h> # include <iostream.h> #endif #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> #include <math.h> #include <uf.h> #include <uf_ui.h> #include <uf_exit.h> #include <uf_obj.h> #include <uf_object_types.h> #include <uf_disp.h> #include <uf_modl.h> #include <uf_part.h> #include <uf_vec.h> static FILE* prterr; static int errorCode; static tag_t part; #define PRTERR if(errorCode)\ {PrintErrorMessage(errorCode,__LINE__);goto term;} //процедура расшифровки кода ошибки static void PrintErrorMessage(int errorCode, int line) { if(errorCode) { char message[133]; UF_get_fail_message(errorCode,message); UF_UI_set_status(message); fprintf(prterr,"errorCode=%d\tmessage=%s\tline=%d\n",errorCode,message,line); fflush(prterr); errorCode=0; } } int face_init_proc(UF_UI_selection_p_t select, void* user_data) { int ret_code; int num_triples=1; UF_UI_mask_t mask_triples[]={UF_face_type,0,0}; ret_code=UF_UI_set_sel_mask (select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples,mask_triples); if(ret_code==0) return UF_UI_SEL_SUCCESS; return UF_UI_SEL_FAILURE; } int points_init_proc(UF_UI_selection_p_t select, void* user_data) { int ret_code; int num_triples=1; UF_UI_mask_t mask_triples[]={UF_point_type,0,0}; ret_code=UF_UI_set_sel_mask (select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples,mask_triples); if(ret_code==0) return UF_UI_SEL_SUCCESS; return UF_UI_SEL_FAILURE; } void do_it() { tag_t face_tag; tag_t body_obj_id; label_get_face: // { char* message="Выбери грань"; char* title="Выбери грань"; int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY; int response; tag_t object; double cursor[3]; tag_t view; errorCode=UF_UI_select_with_single_dialog (message,title,scope,face_init_proc,NULL,&response,&object,cursor,&view);PRTERR; switch(response) { case UF_UI_BACK: goto label_get_face; case UF_UI_CANCEL: goto term; case UF_UI_OK: break; case UF_UI_OBJECT_SELECTED: break; case UF_UI_OBJECT_SELECTED_BY_NAME: break; } if(object==NULL_TAG) { uc1601("Будьте любезны выбрать грань",1); goto label_get_face; } //set highlight off errorCode=UF_DISP_set_highlight(object,0);PRTERR; face_tag=object; errorCode=UF_MODL_ask_face_body(face_tag,&body_obj_id);PRTERR; } int count; tag_p_t point_group; //выбор точек на поверхности label_get_points: { char* message="Выбери точки"; char* title="Выбери точки"; int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY; int response; tag_p_t object; errorCode=UF_UI_select_with_class_dialog (message,title,scope,points_init_proc,NULL,&response,&count,&object);PRTERR; switch(response) { case UF_UI_BACK: goto label_get_face; case UF_UI_CANCEL: goto term; case UF_UI_OK: break; } if(count==0) { uc1601("будьте любезны выбрать точки!",1); goto label_get_points; } int i; for(i=0;i<count;i++) { //set highlight off errorCode=UF_DISP_set_highlight(object[i],0);PRTERR; } point_group=object; } double ra4[]={3.0,4.0,2.0}; //запроси параметры отверстия { int ret_code; char* cp1="укажи параметры отверстия"; int ip3=3; char cp2[][16]={"диаметр","глубина","завышение"}; ret_code=uc1609(cp1,cp2,ip3,ra4,0); switch(ret_code) { case 1: goto label_get_points; case 2: goto term; case 3: break; case 4: break; case 8: fprintf(prterr,"\n Disallowed state, unable to bring up dialog line%d\n",__LINE__); goto term; } } //определяем нормаль в точке поверхности { double parm[ 2 ]; double face_pnt[ 3 ]; int i; double point_coords[3]; double u1[ 3 ]; double v1[ 3 ]; double u2[ 3 ]; double v2[ 3 ]; double unit_norm[ 3 ]; double radii[ 2 ]; UF_FEATURE_SIGN sign=UF_POSITIVE;/*UF_NEGATIVE;*/ double origin[3]; double negated_vector[3]; tag_t cyl_tag; char diam[100]; char height[100]; for(i=0;i<count;i++) { errorCode=UF_CURVE_ask_point_data(point_group[i],point_coords);PRTERR; errorCode=UF_MODL_ask_face_parm(face_tag,point_coords,parm,face_pnt);PRTERR; errorCode=UF_MODL_ask_face_props(face_tag,parm,face_pnt,u1,v1,u2,v2,unit_norm,radii);PRTERR; UF_VEC3_linear_comb(1,point_coords,ra4[2],unit_norm,origin); UF_VEC3_negate(unit_norm,negated_vector); sprintf(diam,"%f",ra4[0]); sprintf(height,"%f",ra4[1]+ra4[2]); errorCode=UF_MODL_create_cylinder (sign,body_obj_id,origin,height,diam,negated_vector,&cyl_tag);PRTERR; } } goto term; term: return; } /***************************************************************************** ** Activation Methods *****************************************************************************/ /* Explicit Activation ** This entry point is used to activate the application explicitly, as in ** "File->Execute UG/Open->User Function..." */ extern DllExport void ufusr( char *parm, int *returnCode, int rlen ) { //переменные обработки времени struct tm* newtime; time_t aclock,start_time,finish_time; double work_time; int min,sec; time(&start_time); //попытка открыть файл ошибок на D: if((prterr=fopen("D:\\prterr.txt","w"))!=NULL) { //uc1601("жми ОК и работай дальше",1); goto label_clock; } //попытка открыть файл ошибок на C:\TEMP if((prterr=fopen("C:\\temp\\prterr.txt","w"))!=NULL) { //uc1601("жми ОК и работай дальше",1); goto label_clock; } //файл ошибок разместить не удалось uc1601("не могу разместить файл ошибок",1); return; label_clock: time(&aclock); newtime=localtime(&aclock); fprintf(prterr,"\n<create_hole_at_surface> HAS STARTED line=%d\n\n",__LINE__); fprintf(prterr,"время начала работы программы: %s\n\n",asctime(newtime)); errorCode=UF_initialize();PRTERR; //проверь открытие файла модели или сборки part=UF_PART_ask_display_part(); if(part==NULL_TAG) { uc1601("открой непустой файл!",1); fprintf(prterr,"\n открой непустой файл line=%d\n",__LINE__); goto term; } /* TODO: Add your application code here */ do_it(); errorCode=UF_terminate();PRTERR; term: time(&finish_time); work_time=difftime(finish_time,start_time); min=(int)work_time/60; sec=(int)(work_time-min*60); fprintf(prterr,"\n<create_hole_at_surface> HAS ENDED line=%d\n\n",__LINE__); fprintf(prterr,"working time is %u min %u sec\n",min,sec); fflush(prterr); fclose(prterr); return; } /***************************************************************************** ** Utilities *****************************************************************************/ /* Unload Handler ** This function specifies when to unload your application from Unigraphics. ** If your application registers a callback (from a MenuScript item or a ** User Defined Object for example), this function MUST return ** "UF_UNLOAD_UG_TERMINATE". */ extern int ufusr_ask_unload( void ) { return( UF_UNLOAD_IMMEDIATELY ); }
|