📄 project_model.c
字号:
#include <uf_part.h>
#include <uf_assem.h>
#include <stdlib.h>
#include <uf_ui.h>
#include <stdio.h>
#include <math.h>
#include <uf_view.h>
#include "Project_Model.h"
#include "Project_Matrix.h"
#include "Project_VA_Move_dialog.h"
void Project_VA_Model_Movement_Free(VA_movement *move)
{
if(move==NULL)
return;
Project_VA_Model_Movement_Free(move->next);
free(move);
}
void Project_VA_Model_Moves_Free(VA_movements *moves)
{
if(moves==NULL)
return;
Project_VA_Model_Movement_Free(moves->head);
}
void Project_VA_Model_Component_Free(VA_component *comp)
{
if(comp->children!=NULL)
Project_VA_Model_Component_Free(comp->children);
if(comp->next!=NULL)
Project_VA_Model_Component_Free(comp->next);
free(comp);
}
void Project_VA_Model_Free(VA_assembly *asm)
{
if(asm==NULL)
return;
if(asm->head_comp!=NULL)
Project_VA_Model_Component_Free(asm->head_comp);
if(asm->moves!=NULL)
Project_VA_Model_Moves_Free(asm->moves);
free(asm);
asm=NULL;
return;
}
int Project_VA_Component_Resume(VA_component *p_comp)
{
int n_instances, failures[1] ;
tag_t instances[1] ;
logical log=FALSE;
int err;
n_instances=1;
instances[0]=p_comp->instance_tag;
UF_ASSEM_ask_suppress_state(p_comp->instance_tag,&log);
if(log==TRUE)
{
UF_ASSEM_unsuppress_instances(n_instances, instances, failures );
err=failures[0];
return err;
}
return UG_NO_ERROR;
}
int Project_VA_Model_Refresh(VA_assembly *asm,int root_tag)
{
VACompLoadLocationData appdata;
VA_component* comp=NULL;
double origin[3];double csys_matrix[9];
extern VA_assembly *p_gbl_asm;
if (p_gbl_asm!=NULL) Project_VA_Model_Free(p_gbl_asm);
p_gbl_asm=(VA_assembly*)malloc(sizeof(VA_assembly));
p_gbl_asm->moves=(VA_movements *)malloc(sizeof(VA_movements));
p_gbl_asm->moves->head=NULL;
p_gbl_asm->moves->tail=NULL;
p_gbl_asm->moves->move_num=0;
strcpy(p_gbl_asm->file_name,"");
comp=(VA_component *)malloc(sizeof(VA_component));
p_gbl_asm->head_comp=comp;
comp->occurence_tag=root_tag;
comp->instance_tag=UF_ASSEM_ask_prototype_of_occ (root_tag);
UF_PART_ask_units(comp->instance_tag,&comp->unit);
UF_ASSEM_ask_component_data(root_tag,comp->part_name,comp->refset_name,
comp->instance_name,origin,csys_matrix,comp->ini_pos);
/////////////////////////////////////////////////////////////////////////
if(strcmp(comp->instance_name,"")==0)
strcpy(comp->instance_name,"BaseAssembly");
comp->children=NULL;
comp->next=NULL;
comp->parent=NULL;
comp->type=1;
appdata.parent=comp;
appdata.prev=NULL;
Project_VA_Model_Load_From_UG(root_tag,&appdata);
return UG_NO_ERROR;
}
void Project_VA_Model_Load_From_UG(int parent_tag,VACompLoadLocationData* appdata)
{
VACompLoadLocationData *pdata;
VACompLoadLocationData data;
VA_component* comp=NULL;
tag_t *child_part_occs,*cpo_for_type;
double origin[3],csys_matrix[9];
int partNum,partnum_for_type,i;
char message[100];
UF_initialize();
pdata=(VACompLoadLocationData*)appdata;
partNum=UF_ASSEM_ask_part_occ_children(parent_tag,&child_part_occs);
for(i=0;i<partNum;i++)
{
comp=(VA_component*)malloc(sizeof(VA_component));
comp->occurence_tag=child_part_occs[i];
comp->instance_tag=UF_ASSEM_ask_inst_of_part_occ(comp->occurence_tag);
UF_ASSEM_ask_component_data(comp->instance_tag,comp->part_name,comp->refset_name,
comp->instance_name,origin,csys_matrix,comp->ini_pos);
/////////////////////////////////////////////////////////////////////////
if(strcmp(comp->instance_name,"")==0)
{
strcpy(comp->instance_name,"None");
uc1601("有instance_name为空的实例",1);
sprintf(message,"%d",comp->instance_tag);
uc1601(message,1);
}
UF_ASSEM_ask_transform_of_occ(comp->occurence_tag,comp->ini_pos);
UF_PART_ask_units(comp->instance_tag,&comp->unit);
comp->parent=pdata->parent;
comp->children=NULL;
comp->next=NULL;
if(pdata->prev==NULL)
pdata->parent->children=comp;
else
pdata->prev->next=comp;
partnum_for_type=UF_ASSEM_ask_part_occ_children(comp->occurence_tag,&cpo_for_type);
if(partnum_for_type==0)
comp->type=0;
else if(partnum_for_type>0)
comp->type=1;
pdata->prev=comp;
if(comp->type==1)
{
data.parent=comp;
data.prev=NULL;
Project_VA_Model_Load_From_UG(comp->occurence_tag,&data);
}
}
UF_free(child_part_occs);
UF_free(cpo_for_type);
}
static int init_proc(UF_UI_selection_p_t select,void* user_data)
{
int num_triples = 1;
UF_UI_mask_t mask_triples[] = {UF_component_type,UF_part_occurrence_subtype, 0};
int err;
err=UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
num_triples, mask_triples);
if(err==0)
return (UF_UI_SEL_SUCCESS);
return (UF_UI_SEL_FAILURE);
}
int Project_VA_Model_Append_Move(VA_movement *p_move)
{
extern VA_assembly *p_gbl_asm;
VA_component *p_comp;
char prompt[200];
tag_t comp_tag,view,supress_instances[1];
int response,mode=UF_UI_NEGATIVE_ZC_AXIS;
double cursor[3],direction[3],dir_ori[3];
double v=0.0,step_length;
int action,i,failures[1];
double trans_pos[4][4],pos[4][4],ini_pos[4][4];
double new_origin[3],new_csys_matrix[6];
do
{
UF_UI_select_with_single_dialog("选择装配组件","选择组件",UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,
init_proc,NULL,&response,&comp_tag,cursor,&view);
if(response==UF_UI_CANCEL)
return UG_ERROR;
if(p_gbl_asm->head_comp->occurence_tag==comp_tag)
{
UF_DISP_set_highlight(comp_tag,1);
p_move->comp=p_gbl_asm->head_comp;
strcpy(prompt,"您选择的组件是\t");
strcat(prompt,p_move->comp->instance_name);
UF_UI_set_status(prompt);
break;
}
p_comp=p_gbl_asm->head_comp->children;
while(p_comp!=NULL)
{
if(p_comp->occurence_tag==comp_tag)
{
strcpy(prompt,"您选择的组件是\t");
strcat(prompt,p_comp->instance_name);
UF_UI_set_status(prompt);
p_move->comp=p_comp;
break;
}
p_comp=p_comp->next;
}
if(response==UF_UI_OK)
break;
}while(1);
response=-1;
UF_UI_specify_vector("选择移动方向",&mode,UF_UI_DISP_TEMP_VECTOR,direction,dir_ori,&response);
if(response!=UF_UI_OK)
return UG_ERROR;
step_length=5.0;
do
{
response=-1;
LaunchMovePlanningDialog(&response ,&action);
if(response==UF_UI_OK)
action=response;
if(action==MOVE_PLUS)
v=v+step_length;
else if(action==MOVE_MINUS)
v=v-step_length;
else if(action==ADJUST_SEPT_SIZE)
{
char cp[1][16];
int ip5,back;
double s_l[1];
strcpy(cp[0],"请输入移动步长");
s_l[0]=5.0;
back=uc1609("请输入移动步长",cp,1,s_l,&ip5);
if(back==4)
step_length=s_l[0];
continue;
}
else if(action==UF_UI_OK)
{
if(fabs(v)<1e-6)
return UG_ERROR;
supress_instances[0]=p_move->comp->instance_tag;
UF_ASSEM_suppress_instances(1,supress_instances,failures);
break;
}
for(i=0;i<3;i++)
{
p_move->translation[i]=direction[i]*v;
p_move->point[i]=0.0;
p_move->rotation[i]=0.0;
}
p_move->rotation[0]=1.0;
p_move->angle=0.0;
Project_Matrix_Get_From_Move(p_move->translation,p_move->point,
p_move->rotation,p_move->angle,trans_pos);
Project_MatrixGet_Transpose(p_move->comp->ini_pos,ini_pos);
Project_Matrix_Product(ini_pos,trans_pos,pos);
for(i=0;i<3;i++)
{
new_origin[i]=pos[3][i];
new_csys_matrix[i]=pos[0][i];
}
for(i=0;i<3;i++)
new_csys_matrix[i+3]=pos[1][i];
UF_ASSEM_suppress_mc(p_move->comp->occurence_tag,TRUE);
UF_ASSEM_reposition_instance(p_move->comp->instance_tag,new_origin,new_csys_matrix);
}while(1);
return UG_NO_ERROR;
}
void Project_VA_Display_Move(VA_movement *p_move)
{
double new_origin[3],new_csys_matrix[6];
double move_trans[4][4],ini_pos[4][4],pos[4][4];
double ini_point[3],trans_point[3];
UF_OBJ_disp_props_t prop;
UF_DISP_view_type_t view_type=UF_DISP_USE_WORK_VIEW;
int i;
tag_t work_view;
for(i=0;i<3;i++)
{
new_origin[i]=p_move->comp->ini_pos[i][3];
new_csys_matrix[i]=p_move->comp->ini_pos[i][0];
}
for(i=0;i<3;i++)
new_csys_matrix[i+3]=p_move->comp->ini_pos[i][1];
UF_ASSEM_suppress_mc(p_move->comp->occurence_tag,TRUE);
UF_ASSEM_reposition_instance(p_move->comp->instance_tag,new_origin,new_csys_matrix);
Project_Matrix_Get_From_Move(p_move->translation,p_move->point,
p_move->rotation,p_move->angle,move_trans);
Project_MatrixGet_Transpose(p_move->comp->ini_pos,ini_pos);
Project_Matrix_Product(ini_pos,move_trans,pos);
//pos放置的是变换之后的矩阵,UG矩阵的转置矩阵。ini_pos是组件的初始UG位姿矩阵
for(i=0;i<3;i++)
{
ini_point[i]=p_move->comp->ini_pos[i][3];
trans_point[i]=pos[3][i];
}
UF_VIEW_ask_work_view(&work_view);
UF_DISP_refresh();
prop.layer=1;
prop.color=UF_OBJ_YELLOW;
prop.blank_status=UF_OBJ_NOT_BLANKED;
prop.line_width=UF_OBJ_WIDTH_THICK;
prop.highlight_status=TRUE;
prop.font=0;
UF_DISP_display_temporary_line(work_view,view_type,ini_point,trans_point,&prop);
}
void Project_VA_Animation_Move(VA_movement *p_move)
{
int i,j;
double trans[3];
double anim_step[4][4];
double anim_pos[4][4],key_pos[4][4];
double new_origin[3],new_csys_matrix[6];
UF_DISP_refresh();
Project_MatrixGet_Transpose(p_move->comp->ini_pos,anim_pos);
Project_Matrix_Copy(anim_pos,key_pos);
for(i=1;i<=30;i++)
{
Project_Vector_Scale(p_move->translation,1.0/20.0*i,trans);
Project_Matrix_Get_From_Move(trans,p_move->point,p_move->rotation,
p_move->angle,anim_step);
Project_Matrix_Product(key_pos,anim_step,anim_pos);
for(j=0;j<3;j++)
{
new_origin[j]=anim_pos[3][j];
new_csys_matrix[j]=anim_pos[0][j];
}
for(j=0;j<3;j++)
new_csys_matrix[j+3]=anim_pos[1][j];
UF_ASSEM_suppress_mc(p_move->comp->occurence_tag,TRUE);
UF_ASSEM_reposition_instance(p_move->comp->instance_tag,new_origin,new_csys_matrix);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -