|
楼主 |
发表于 2012-7-17 11:22
|
显示全部楼层
#define PRO_USE_VAR_ARGS 1
/*------------------------------------------------------------------*\
Pro/Toolkit includes
\*------------------------------------------------------------------*/
#include <stdio.h>
#include "process.h"
#include "stdlib.h"
#include <ProToolkit.h>
#include <ProObjects.h>
#include <ProSolid.h>
#include <ProParameter.h>
#include <ProParamval.h>
#include <ProMdl.h>
#include <ProModelitem.h>
#include <ProDimension.h>
#include <ProMenuBar.h>
#include <ProMessage.h>
#include <ProUtil.h>
#include <ProFeature.h>
#include <ProFeatType.h>
#include <prodgmstruc.h>
//add by hxl 20120516
#include <ProCabling.h>
//add by hxl 20120521
#include <ProMdl.h>
#include <ProDtmPnt.h>
/*------------------------------------------------------------------*\
Application includes
\*------------------------------------------------------------------*/
#include <TestError.h>
#include <TestParams.h>
#include <ProWstring.h>
#include <ProSelection.h>
#include <ProObjects.h>
typedef enum
{
Usr_MODIFY_PARAMETER=1,
Usr_MODIFY_DIMENSION
} UsrChoice;
typedef struct
{
UsrChoice option;
ProName name;
double value;
} UsrParam;
int UsrCreatePnt(double OFST_CSYS_X_VAL
,double OFST_CSYS_Y_VAL
,double OFST_CSYS_Z_VAL);
void UsrElemtreeElementAdd(ProElemId id
,ProElement parent
,void* value
,ProValueDataType type
,ProElement* element);
static ProError status;
/*=====================================================================*\
FUNCTION: UsrMenuAction
PURPOSE: Menu button action function for exercise 9
\*=====================================================================*/
ProError UsrMenuAction ()
{
ProError status;
int n_sel=0;
ProSelection *sel;
ProModelitem feature;
status=ProSelect("surface",1,NULL,NULL,NULL,NULL,&sel,&n_sel);
if(status!=PRO_TK_NO_ERROR||n_sel<0)
return(PRO_TK_USER_ABORT);
status=ProSelectionModelitemGet(*sel,&feature);
if (status==PRO_TK_NO_ERROR)
{
ProName msg_file;
ProStringToWstring(msg_file,"Information.txt");
ProMessageDisplay(msg_file,"USER sel item id is:%0d",feature.id);
}
return(PRO_TK_NO_ERROR);
}
int UsrCreatePnt(double OFST_CSYS_X_VAL
,double OFST_CSYS_Y_VAL
,double OFST_CSYS_Z_VAL)
{
ProMdl cur_mdl;
ProName name;
ProModelitem cur_mdlit;
ProSelection ref_csys;
ProElement elem_tree,element,elem_ayyay,elem_const;
double dvalue;
ProSolid solid;
ProModelitem model_modelitem;
ProSelection mdl_sel;
ProFeature feature;
ProErrorlist errors;
int ivalue;
ProElementAlloc(PRO_E_FEATURE_TREE,&elem_tree);
//PRO_E_FEATURE_TYPE
ivalue = PRO_FEAT_DATUM_POINT;
UsrElemtreeElementAdd(PRO_E_FEATURE_TYPE,elem_tree
,&ivalue,PRO_VALUE_TYPE_INT,&element);
//PRO_E_DPOINT_TYPE
ivalue = PRO_DPOINT_TYPE_OFFSET_CSYS;
UsrElemtreeElementAdd(PRO_E_DPOINT_TYPE,elem_tree
,&ivalue,PRO_VALUE_TYPE_INT,&element);
ivalue = PRO_DTMPNT_OFFCSYS_CARTESIAN;
UsrElemtreeElementAdd(PRO_E_DPOINT_OFST_CSYS_TYPE,elem_tree
,&ivalue,PRO_VALUE_TYPE_INT,&element);
//PRO_E_DPOINT_OFST_CSYS_REF
ProMdlCurrentGet(&cur_mdl);
ProStringToWstring(name,"PRT_CSYS_DEF");
ProModelitemByNameInit(cur_mdl,PRO_CSYS,name,&cur_mdlit);
ProSelectionAlloc(NULL,&cur_mdlit,&ref_csys);
UsrElemtreeElementAdd(PRO_E_DPOINT_OFST_CSYS_REF,elem_tree
,&ref_csys,PRO_VALUE_TYPE_SELECTION,&element);
ivalue = PRO_B_FALSE;
UsrElemtreeElementAdd(PRO_E_DPOINT_OFST_CSYS_WITH_DIMS,elem_tree
,&ivalue,PRO_VALUE_TYPE_INT,&element);
//PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY
ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY,&elem_ayyay);
ProElemtreeElementAdd(elem_tree,NULL,elem_ayyay);
//PRO_E_DPOINT_OFST_CSYS_PNT
ProElementAlloc(PRO_E_DTMPLN_CONSTRAINT,&elem_const);
ProElemtreeElementAdd(elem_ayyay,NULL,elem_const);
//PRO_E_DPOINT_OFST_CSYS_DIR1_VAL
dvalue = OFST_CSYS_X_VAL;
UsrElemtreeElementAdd(PRO_E_DPOINT_OFST_CSYS_DIR1_VAL,elem_const
,&dvalue,PRO_VALUE_TYPE_DOUBLE,&element);
//PRO_E_DPOINT_OFST_CSYS_DIR2_VAL
dvalue = OFST_CSYS_Y_VAL;
UsrElemtreeElementAdd(PRO_E_DPOINT_OFST_CSYS_DIR2_VAL,elem_const
,&dvalue,PRO_VALUE_TYPE_DOUBLE,&element);
//PRO_E_DPOINT_OFST_CSYS_WITH_DIMS
dvalue = OFST_CSYS_Z_VAL;
UsrElemtreeElementAdd(PRO_E_DPOINT_OFST_CSYS_DIR3_VAL,elem_const
,&dvalue,PRO_VALUE_TYPE_DOUBLE,&element);
ProMdlCurrentGet((ProMdl*)&solid);
ProMdlToModelitem(solid,&model_modelitem);
ProSelectionAlloc(NULL,&model_modelitem,&mdl_sel);
ProFeatureCreate(mdl_sel,elem_tree,NULL,0,&feature,&errors);
ProElementFree(&elem_tree);
ProSelectionFree(&mdl_sel);
return 1;
}
void UsrElemtreeElementAdd(ProElemId id
,ProElement parent
,void* value
,ProValueDataType type
,ProElement* element)
{
ProValueData value_data;
ProValue pvalue;
value_data.type = type;
switch(type)
{
case PRO_VALUE_TYPE_INT :
value_data.v.i = *(int*)value;
break;
case PRO_VALUE_TYPE_DOUBLE :
value_data.v.d = *(double*)value;
break;
case PRO_VALUE_TYPE_POINTER :
value_data.v.p = *(void**)value;
break;
case PRO_VALUE_TYPE_STRING :
value_data.v.s = *(char**)value;
break;
case PRO_VALUE_TYPE_WSTRING :
value_data.v.w = *(wchar_t**)value;
break;
case PRO_VALUE_TYPE_SELECTION :
value_data.v.r = *(ProSelection*)value;
break;
case PRO_VALUE_TYPE_TRANSFORM :
value_data.v.t = *(double***)value;
break;
case PRO_VALUE_TYPE_BOOLEAN :
value_data.v.i = *(int*)value;
break;
}
//设置特征树元素的值
ProElementAlloc(id,element);
ProValueAlloc(&pvalue);
ProValueDataSet(pvalue,&value_data);
ProElementValueSet(*element,pvalue);
//将特征元素添加到特征元素树中
ProElemtreeElementAdd(parent,NULL,*element);
}
static uiCmdAccessState TestAccessDefault(uiCmdAccessMode access_mode)
{
return (ACCESS_AVAILABLE);
}
/*====================================================================*\
FUNCTION : user_initialize()
PURPOSE : Pro/TOOLKIT standard initialize - define menus.
\*====================================================================*/
int user_initialize (int argc, char* argv [], char* proe_version, char* build_code)
{
uiCmdCmdId cmd_id,cmd_id1;
ProError status;
ProTestErrlogOpen ("Module9.log", proe_version, build_code);
status = ProCmdActionAdd ("Exercise9",
(uiCmdCmdActFn)UsrMenuAction,
uiProe2ndImmediate, TestAccessDefault,
PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
status = ProCmdActionAdd ("Exercise10",
(uiCmdCmdActFn)UsrMenuAction,
uiProe2ndImmediate, TestAccessDefault,
PRO_B_TRUE, PRO_B_TRUE, &cmd_id1);
status=ProMenubarMenuAdd ("CHECK", "CHECK","Utilities", PRO_B_TRUE, L"exercise_9.txt");
status = ProMenubarmenuPushbuttonAdd ("CHECK", "Exercise9", "Exercise9",
"Exercise9", NULL,
PRO_B_TRUE, cmd_id, L"exercise_9.txt");
ProCmdDesignate(cmd_id,"Exercise9","Exercise9 Help","Exercise9",L"exercise_9.txt");
ProCmdIconSet(cmd_id,"bolt.gif");
status = ProMenubarmenuPushbuttonAdd ("CHECK", "Exercise10", "Exercise10",
"Exercise10", NULL,
PRO_B_TRUE, cmd_id1, L"exercise_9.txt");
ProCmdIconSet(cmd_id1,"nut.gif");
ProCmdDesignate(cmd_id1,"Exercise10","Exercise10 Help","Exercise10",L"exercise_9.txt");
return (PRO_TK_NO_ERROR);
}
/*====================================================================*\
FUNCTION : user_terminate()
PURPOSE : Pro/TOOLKIT standard termination
\*====================================================================*/
void user_terminate ()
{
ProTestErrlogClose ();
}
这是完整版的代码 我是新手拿了别人的在上面做了改动 我的目的是选择模型相应的面就能显示出模型面的ID但是选择面之后PROE就自动退出了
主要功能实现的代码在就是之前给出的那个
[ 本帖最后由 wwangyufei 于 2012-7-17 11:24 编辑 ] |
|