马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
//////////////////////////////////////////////////////////////////////////////
//
// asm03.cpp
//
// Description:
// Contains Unigraphics entry points for the application.
//
//////////////////////////////////////////////////////////////////////////////
// Include files
#include <uf.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_assem.h>
#include <uf_part.h>
#include <uf_object_types.h>
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std:strstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include "asm03.h"
//----------------------------------------------------------------------------
// Activation Methods
//----------------------------------------------------------------------------
// Unigraphics Startup
// This entry point activates the application at Unigraphics startup
extern "C" DllExport void ufsta( char *param, int *returnCode, int rlen )
{
/* Initialize the API environment */
int errorCode = UF_initialize();
if ( 0 == errorCode )
{
/* TODO: Add your application code here */
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];
double box[6];
double radius;
double 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();
return;
}
/*char name[256+1];
int k;
k=UF_PART_ask_part_name (first_plan, name);
uc1601(name,1);*/
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[132+1];
char refset_name[30+1];
char instance_name[30+1];
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(second_plan,0);
}
}
while(!(type==22 [$& response==5))]
if(response!=5)
{
uc1601("没有选择面",1);
UF_terminate();
return;
}
tag_t to_part_occ;
ret=UF_ASSEM_ask_parent_component(second_plan,[$to_part_occ)]
is_occ=UF_ASSEM_is_occurrence(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_solve_mc([$ftf,&status,&dof,transform)]
//UF_get_fail_message(ret,message);
if(ret==0 || status==UF_ASSEM_mc_solved)
{
uc1601("ok!",1);
ret=UF_ASSEM_apply_mc_data([$ftf,&struct_status,&status)]
UF_DISP_refresh();
UF_MODL_update();
}
UF_DISP_set_highlight(first_plan,0);
UF_DISP_set_highlight(second_plan,0);
/* Terminate the API environment */
errorCode = UF_terminate();
}
/* Print out any error messages */
 rintErrorMessage( errorCode );
}
//----------------------------------------------------------------------------
// 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 "C" int ufusr_ask_unload( void )
{
return( UF_UNLOAD_UG_TERMINATE );
}
/* PrintErrorMessage
**
** Prints error messages to standard error and the Unigraphics status
** line. */
static void PrintErrorMessage( int errorCode )
{
if ( 0 != errorCode )
{
/* Retrieve the associated error message */
char message[133];
UF_get_fail_message( errorCode, message );
/* Print out the message */
UF_UI_set_status( message );
// Construct a buffer to hold the text.
ostrstream error_message;
// Initialize the buffer with the required text.
error_message << endl
<< "Error:" << endl
<< message
<< endl << endl << ends;
// Write the message to standard error
cerr << error_message.str();
}
}
我试了这个程序,这个程序没有错误但没有结果。
我是这样做的,先新建 1.prt,然后装配两个 2.prt,3.prt。
然后把上面的程序运行,先选择 1.prt的一个平面,然后再选择 2.prt的一个平面,最终 还是没有结果,请问斑竹这是什么问题,请指点指点我吧,这问题费了我不少时间呢,写毕业设计急需,谢谢!!! |