Копирование подсборки в координаты точек поверхности. Порядок действий:
- Выбор компоненты для тиражирования
- Выбор базовой систему координат CSYS
- Выбор поверхности
- Запрос точек на поверхности
- Копирование компоненты
Код на 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> #include <uf_mtx.h> #include <uf_assem.h> #include <uf_csys.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 component_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_component_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 csys_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_coordinate_system_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 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 point_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 print_mtx3(double mtx[3],char* mes,int line) { fprintf(prterr,"\n %s line=%d\n",mes,line); fprintf(prterr,"\n\t%12.4f\t%12.4f\t%12.4f\n", mtx[0],mtx[1],m 2471 tx[2]); } void print_mtx9(double mtx[9],char* mes,int line) { fprintf(prterr,"\n %s line=%d\n",mes,line); fprintf(prterr,"\t%12.4f\t%12.4f\t%12.4f\n", mtx[0],mtx[1],mtx[2]); fprintf(prterr,"\t%12.4f\t%12.4f\t%12.4f\n", mtx[3],mtx[4],mtx[5]); fprintf(prterr,"\t%12.4f\t%12.4f\t%12.4f\n", mtx[6],mtx[7],mtx[8]); } void do_it() { tag_t* component_group; int component_count; //выбор компонент label_get_components: { char* message="Выбери компоненты"; char* title="Выбери компоненты"; int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY; int response; int count; tag_p_t object; errorCode=UF_UI_select_with_class_dialog (message,title,scope,component_init_proc,NULL,&response,&count,&object);PRTERR; switch(response) { case UF_UI_BACK: goto label_get_components; case UF_UI_CANCEL: goto term; case UF_UI_OK: break; } if(count==0) { uc1601("необходимо выбрать компоненты!",1); goto label_get_components; } int i; for(i=0;i<count;i++) { //set highlight off errorCode=UF_DISP_set_highlight(object[i],0);PRTERR; } component_group=object; component_count=count; } //выбор базовой системы координат tag_t csys_tag; double csys_origin[3]; double matrix_values[9]; label_get_csys: // { char* message="Выбери базовую csys"; char* title="Выбери базовую csys"; int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY; int response; tag_t object; double cursor[3]; tag_t view; tag_t matrix_id; errorCode=UF_UI_select_with_single_dialog (message,title,scope,csys_init_proc,NULL,&response,&object,cursor,&view);PRTERR; switch(response) { case UF_UI_BACK: goto label_get_components; 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("Необходимо выбрать базовую csys",1); goto label_get_csys; } //set highlight off errorCode=UF_DISP_set_highlight(object,0);PRTERR; csys_tag=object; errorCode=UF_CSYS_ask_csys_info (csys_tag,&matrix_id,csys_origin);PRTERR; errorCode=UF_CSYS_ask_matrix_values (matrix_id,matrix_values);PRTERR; } //выбор грани tag_t face_tag; label_get_face: // { char* message="Выбери базовую face"; char* title="Выбери базовую face"; 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_csys; 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("Будьте любезны выбрать базовую face",1); goto label_get_face; } //set highlight off errorCode=UF_DISP_set_highlight(object,0);PRTERR; face_tag=object; } tag_t* point_group; int point_count; //выбор точек label_get_points: { char* message="Выбери точки"; char* title="Выбери точки"; int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY; int response; int count; tag_p_t object; errorCode=UF_UI_select_with_class_dialog (message,title,scope,point_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; point_count=count; } //тиражирование компонент { int i,j; double point_coords[3]; double parm[2]; double face_pnt[3]; double u1[3],v1[3],u2[3],v2[3],unit_norm[3],radii[2]; double mtx9[9]; char part_name[ 256 + 1 ]; char refset_name[ 30 + 1 ]; char instance_name[ ( 128 + 1 ) ]; double origin[ 3 ]; double csys_matrix[ 9 ]; double transform[ 4 ][ 4 ]; tag_t instance; UF_PART_load_status_t error_status; double mtx16[16]; //цикл по точкам поверхности for(i=0;i<point_count;i++) { //получить координаты точки <point_coords> errorCode=UF_CURVE_ask_point_data(point_group[i],point_coords);PRTERR; //получить параметры в точке поверхности <parm> errorCode=UF_MODL_ask_face_parm(face_tag,point_coords,parm,face_pnt);PRTERR; //получить производные по u v errorCode=UF_MODL_ask_face_props(face_tag,parm,face_pnt,u1,v1,u2,v2,unit_norm,radii);PRTERR; //нормализовать u и v errorCode=UF_MTX3_initialize (u1,v1,mtx9); if(errorCode) { uc1601("Matrix cannot be defined",1); fprintf(prterr,"\n 1 = Matrix cannot be defined line=%d\n",__LINE__); } //построить преобразование от базовой системы координат в систему координат точки поверхности errorCode=UF_MTX4_csys_to_csys (csys_origin,matrix_values+0,matrix_values+3,point_coords,mtx9+0,mtx9+3,mtx16);PRTERR; //print_mtx9(mtx9,"mtx9",__LINE__); //цикл по компонентам агрегата for(j=0;j<component_count;j++) { //получить данные компонента errorCode=UF_ASSEM_ask_component_data (component_group[j],part_name,refset_name, instance_name,origin,csys_matrix,transform);PRTERR; //print_mtx9(csys_matrix,"csys_matrix до преобразования",__LINE__); //print_mtx3(origin,"origin",__LINE__); //превратить направляющие косинусы в точки UF_VEC3_add(origin,csys_matrix+0,csys_matrix+0); UF_VEC3_add(origin,csys_matrix+3,csys_matrix+3); //print_mtx9(csys_matrix,"csys_matrix направляющие косинусы перешли в точки",__LINE__); //перевести точки в новую систему координат UF_MTX4_vec3_multiply (origin,mtx16,origin); //print_mtx3(origin,"origin новый",__LINE__); UF_MTX4_vec3_multiply (csys_matrix+0,mtx16,csys_matrix+0); UF_MTX4_vec3_multiply (csys_matrix+3,mtx16,csys_matrix+3); //print_mtx9(csys_matrix,"csys_matrix направляющие косинусы перешли в новые точки",__LINE__); UF_VEC3_sub (csys_matrix+0,origin,csys_matrix+0); UF_VEC3_sub (csys_matrix+3,origin,csys_matrix+3); //print_mtx9(csys_matrix,"csys_matrix новые направляющие косинусы ",__LINE__); errorCode=UF_ASSEM_add_part_to_assembly (part,part_name,refset_name,instance_name,origin,csys_matrix,0,&instance,&error_status);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<bolt_gaika_shaiba> 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<bolt_gaika_shaiba> 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 ); }
|