|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
int ZB_action_peihe_cb ( int dialog_id,
void * client_data,
UF_STYLER_item_value_type_p_t callback_data)
{
/* Make sure User Function is available. */
if ( UF_initialize() != 0)
return ( UF_UI_CB_CONTINUE_DIALOG );
/* ---- Enter your callback code here ----- */
//选择两个平面
int errorCode;
char message[133];
message[0]='\0';
strcpy(message,"请选择第一个平面");
UF_UI_selection_options_t opts;
UF_UI_mask_t mask;
int response;
tag_t view;
double cursor[3];
int unhighlight=0;
opts.other_options=0;
opts.reserved=NULL;
opts.num_mask_triples=1;
opts.mask_triples=[$mask]
opts.mask_triples->object_type=UF_face_type;
opts.mask_triples->object_subtype=UF_bounded_plane_subtype;
opts.mask_triples->solid_type=UF_UI_SEL_FEATURE_ANY_FACE;
opts.scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
int type;
double point[3];
double dir[3],box[6],radius,rad_data;
int norm_dir;
tag_t first_plan;
do
{
int irc=UF_UI_select_single(message,
[$opts,&response,&first_plan,cursor,&view)]
UF_MODL_ask_face_data(first_plan,&type,point,dir,
box,[$radius,&rad_data,&norm_dir)]
if(type!=22)
{
uc1601("请选择一个平面",1);
UF_DISP_set_highlight(first_plan,0);
}
}
while(!(type==22 [$&response==5))]
if(response!=5)
{
uc1601("没有选择平面",1);
UF_terminate();
}
int ret;
tag_t from_part_occ;
ret=UF_ASSEM_ask_parent_component(first_plan,[$from_part_occ)]
logical is_occ=UF_ASSEM_is_occurrence(from_part_occ);
tag_t from_part_ins=UF_ASSEM_ask_inst_of_part_occ(from_part_occ);
char part_name[133];
char refset_name[31];
char instance_name[31];
double origin[3];
double csys_matrix[9];
double transform[4][4];
ret=UF_ASSEM_ask_component_data(from_part_occ,part_name,
refset_name,instance_name,origin,csys_matrix,transform);
uc1601(instance_name,1);
message[0]='\0';
strcpy(message,"请选择第二个平面");
tag_t second_plan;
do
{
int irc=UF_UI_select_single(message,[$opts,&response,&second_plan,cursor,&view)]
UF_MODL_ask_face_data(second_plan,&type,point,dir,box,
[$radius,&rad_data,&norm_dir)]
if(type!=22)
{
uc1601("请选择另一个平面",1);
UF_DISP_set_highlight(first_plan,0);
}
}
while(!(type==22 [$& response==5))]
if(response!=5)
{
uc1601("没有选择平面",1);
UF_terminate();
}
tag_t to_part_occ;
ret=UF_ASSEM_ask_parent_component(second_plan,[$to_part_occ)]
tag_t to_part_ins=UF_ASSEM_ask_inst_of_part_occ(to_part_occ);
ret=UF_ASSEM_ask_component_data(to_part_occ,part_name,refset_name,instance_name,origin,csys_matrix,transform);
uc1601(instance_name,1);
//构造配合关系
UF_ASSEM_mating_condition_t ftf;
ftf.mated_object=from_part_ins;
ftf.name=NULL;
ftf.user_name=FALSE;
ftf.constraints[0].from_status=UF_ASSEM_ok;
ftf.constraints[0].to_status=UF_ASSEM_ok;
ftf.constraints[0].mate_type=UF_ASSEM_v16_mate;
ftf.constraints[0].from_type=UF_ASSEM_planar_face;
ftf.constraints[0].to_type=UF_ASSEM_planar_face;
ftf.constraints[0].from=UF_ASSEM_ask_prototype_of_occ(first_plan);
ftf.constraints[0].from_part_occ=from_part_occ;
ftf.constraints[0].to=UF_ASSEM_ask_prototype_of_occ(second_plan);
ftf.constraints[0].to_part_occ=to_part_occ;
ftf.constraints[0].offset=NULL_TAG;
ftf.constraints[0].name="face to face";
ftf.constraints[0].user_name=TRUE;
ftf.num_constraints=1;
ftf.suppressed=FALSE;
UF_ASSEM_mc_status_t status;
UF_ASSEM_mc_structure_state_t struct_status;
UF_ASSEM_dof_t dof;
ret=UF_ASSEM_init_mc([$ftf)]
UF_get_fail_message(ret,message);
uc1601(message,1);
ret=UF_ASSEM_solve_mc([$ftf,&status,&dof,transform)]
UF_get_fail_message(ret,message);
uc1601(message,1);
if(ret==0 || status==UF_ASSEM_mc_solved)
{
uc1601("成功配合",1);
ret=UF_ASSEM_apply_mc_data([$ftf,&struct_status,&status)]
UF_DISP_refresh();
UF_MODL_update();
}
else
uc1601("失败",1);
UF_DISP_set_highlight(first_plan,0);
UF_DISP_set_highlight(second_plan,0);
errorCode=UF_terminate();
UF_terminate ();
/* Callback acknowledged, do not terminate dialog */
return (UF_UI_CB_CONTINUE_DIALOG);
/* or Callback acknowledged, terminate dialog. */
/* return ( UF_UI_CB_EXIT_DIALOG ); */
} |
|