(4)编写代码,程序中有详细的注释,不多解释
/*======================================*\
头文件
\*======================================*/
#include "roToolkit.h"
#include "roUtil.h"
#include "roMenu.h"
#include "roMenubar.h"
#include "roUIDialog.h"
#include "ProUIPushbutton.h"
#include "ProUICheckbutton.h"
#include "ProUIList.h"
#include "ProUISpinbox.h"
#include "ProUILabel.h"
#include "ProUIRadiogroup.h"
#include "ProArray.h"
#include "ProUIInputpanel.h"
#include "malloc.h"
#include "stdlib.h"
#include "Pro2dEntdef.h"
#include "ProElement.h"
#include "ProFeatForm.h"
#include "ProFeatType.h"
#include "ProStdSection.h"
#include "ProWindows.h"
#include "ProModelitem.h"
#include "ProRevolve.h"
#include "ProSolid.h"
#include "ProElempath.h"
#include <ProDtmPln.h>
/*===================================*\
函数声明,各函数的功能后面再描述
\*==================================*/
void OK_Action(char*,char*,ProAppData);
void Cancel_Action(char*,char*,ProAppData);
void Check_Action(char*,char*,ProAppData);
void ListSelect_Action(char*,char*,ProAppData);
int ShowDialog();
static uiCmdAccessState AccessDefault(uiCmdAccessMode);
void ListSelectAction(char*,char*,ProAppData);
void CheckEditSetAction(char*,char*,ProAppData);
void usrCreateRevolveFeat(ProGeomitem,ProGeomitem,
ProGeomitem,int*,double);
void usrElemtreeElementAdd(ProElemId,ProElement,void*,
ProValueDataType,ProElement*);
int usrSectionGet(ProFeature*,int,ProSection*);
int usrSectionBuild(ProGeomitem *,ProGeomitem*,
ProSection,int,int*);
int usrCreateSection(ProSection,int,int*);
void usrFeatDel();
void CreatDefDtm();
void UsrGeomitemPlnGet(ProFeature,ProGeomitem *);
int DefaultDtmActFn();
/*==========================================*\
声明全局变量
\*==========================================*/
static int D1[]={60,65,70,75,80},//列表中D1一列的数值
D2[]={45,50,55,60,65}, //D2列的数值
L1[]={100,120,140,160,200},//L1列的数值
L2[]={80,100,120,140,180};//L2列的数值
static int n_line=5;//列表的行数
char *dialog_name="mydlg";//对话框名,资源文件要与之同名
ProGeomitem front,top,right; //参考平面
ProFeature feature;//保存程序创建的特征
int dim[4];//用来保存列表框中被选中的一行的参数值
/*===========================================*\
function: user_initialize()
添加菜单,菜单名为Show Dialog;菜单响应函数为ShowDialog()
\*===========================================*/
extern "C" int user_initialize()
{
ProError status;
ProFileName mf;
uiCmdCmdId cmd_id;
ProStringToWstring(mf,"usrmsg.txt");
status=ProCmdActionAdd("Show Dialog",
(uiCmdCmdActFn)ShowDialog,uiCmdPrioDefault,
AccessDefault,PRO_B_TRUE,PRO_B_TRUE,[$cmd_id)]
status=ProMenubarmenuPushbuttonAdd("Utilities","Show Dialog",
"USER Menu","USER Menu Help",
NULL,PRO_B_TRUE,cmd_id,mf);
return status;
}
/*===============================================================*\
function: user_terminate()
\*===============================================================*/
extern "C" void user_terminate()
{
}
/*==========================================*\
function: ShowDialog()菜单响应函数
\*==========================================*/
int ShowDialog()
{
ProError status;
int Dialog_status;
char** names; //列表框各行的名称,作为程序访问指定行的标识
wchar_t** label;//列表框每一行的标签,标签就是每一行显示的内容
/*----------------------------------
为两个数组分配内存
-----------------------------------*/
ProArrayAlloc(n_line,sizeof(wchar_t*),1,(ProArray*)[$labels)]
ProArrayAlloc(n_line,sizeof(char*),1,(ProArray*)[$names)]
/*----------------------------------
数组中各元素初始化
-----------------------------------*/
for(int i=0;i<n_line;i++)
{
labels = (wchar_t *)calloc(PRO_NAME_SIZE, sizeof(wchar_t));
names = (char *)calloc(PRO_NAME_SIZE, sizeof(char));
}
/*---------------------------------------------------
列表框选项名赋值,每一行的名字分别为1、2、3、4、5
----------------------------------------------------*/
names[0]="1";
names[1]="2";
names[2]="3";
names[3]="4";
names[4]="5";
/*---------------------------------------------------------
列表框标签赋值,如果每行有多列各列之间用tab键或者\t隔开,
不是空格
----------------------------------------------------------*/
ProStringToWstring(labels[0],"60 45 100 80");
ProStringToWstring(labels[1],"65 50 120 100");
ProStringToWstring(labels[2],"70\t55\t140\t120");
ProStringToWstring(labels[3],"75\t60\t160\t140");
ProStringToWstring(labels[4],"80\t65\t200\t180");
/*----------------------------------------
把对话框资源加载进内存
----------------------------------------*/
status=ProUIDialogCreate(dialog_name,dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox("Dialog Create error!");
return status;
}
/*---------------------------------------
设置列表框选项名
---------------------------------------*/
ProUIListNamesSet(dialog_name,"List1",n_line,names);
/*---------------------------------------
设置列表框各行标签
--------------------------------------*/
ProUIListLabelsSet(dialog_name,"List1",n_line,labels);
/*----------------------------------------
释放内存
----------------------------------------*/
ProArrayFree((ProArray*)[$names)]
ProArrayFree((ProArray*)[$labels)]
/*----------------------------------------
设置微调按钮(SpinBox)的默认值
----------------------------------------*/
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD1",D1[0]);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD2",D2[0]);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL1",L1[0]);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL2",L2[0]);
/*-------------------------------------
设定对话框元件动作函数
---------------------------------------*/
//设置OK按钮的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"OK",
OK_Action,NULL);
//设置Cancel按钮的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"Cancel",
Cancel_Action,NULL);
//设置列表框选项的动作函数
ProUIListSelectActionSet(dialog_name,"List1",
ListSelectAction,NULL);
//设置CheckButton的动作函数
ProUICheckbuttonActivateActionSet(dialog_name,
"CheckEditSet",CheckEditSetAction,NULL);
/*------------------------------------
显示激活对话框
------------------------------------*/
status=ProUIDialogActivate(dialog_name,[$Dialog_status)]
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox("Dialog Activate error!");
return status;
}
/*------------------------------------
从内存中清除对话框资源
-------------------------------------*/
status=ProUIDialogDestroy(dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox("Dialog destroy erroe!");
return status;
}
return TRUE;
}
/*==========================================*\
function: AccessDefault()
\*==========================================*/
static uiCmdAccessState AccessDefault(uiCmdAccessMode
access_mode)
{
return (ACCESS_AVAILABLE);
}
/*===========================================*\
function: Cancel_Action() Cancel按钮的动作函数定义
功能:退出对话框
\*==========================================*/
void Cancel_Action(char* dialog,char* componets,ProAppData data)
{
ProUIDialogExit(dialog_name,1);
}
/*===========================================*\
function: ListSelectAction() 列表框选项的动作函数定义
功能:当选择列表框某一行时,将这一行的各个参数显示
在相应的SpinBox中
\*========================================*/
void ListSelectAction(char* dialog,char* component,
ProAppData data)
{
char** names;//列表框名称
int n_names;//列表框标签
int i;
ProBoolean set;//Checkbutton是否被选中的标志
ProArrayAlloc(0,sizeof(char*),1,(ProArray*)[$names)]//为数组分配内存
//确定选择的列表框选项名
ProUIListSelectednamesGet(dialog,component,[$n_names,&names)]
//n_names表示选择的项数,本例中只能选择一项
if(n_names!=1)
{
return;
}
//获得Checkbutton的状态
ProUICheckbuttonGetState(dialog,"CheckEditSet",[$set)]
//如果Checkbutton被设置,则允许修改SpinBox中的参数
if(set)
{
//将所选列表框中的参数写入Spinbox
i=atoi(names[0])-1;
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD1",D1);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD2",D2);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL1",L1);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL2",L2);
}
}
/*===========================================*\
function:CheckEditSetAction() Checkbutton动作函数设置
功能:当被设置时允许修改Spinbox中的内容,反之不允许修改
\*===========================================*/
void CheckEditSetAction(char* dialog,char* component,
ProAppData data)
{
ProBoolean set;//状态标志
ProUICheckbuttonGetState(dialog,component,[$set)]//获取Chenkbutton状态
if(set)//如果被设置
{
ProUISpinboxEditable(dialog,"SpinBoxD1");//四个Spinbox
ProUISpinboxEditable(dialog,"SpinBoxD2");//设置为可用
ProUISpinboxEditable(dialog,"SpinBoxL1");//
ProUISpinboxEditable(dialog,"SpinBoxL2");//
ProUISpinboxIncrementSet(dialog,"SpinBoxD1",1);//微调按钮
ProUISpinboxIncrementSet(dialog,"SpinBoxD2",1);//的微调量
ProUISpinboxIncrementSet(dialog,"SpinBoxL1",1);//设置为1
ProUISpinboxIncrementSet(dialog,"SpinBoxL2",1);//
}
else//如果没设置
{
ProUISpinboxReadOnly(dialog,"SpinBoxD1");//四个Spinbox
ProUISpinboxReadOnly(dialog,"SpinBoxD2");//设置位
ProUISpinboxReadOnly(dialog,"SpinBoxL1");//只读
ProUISpinboxReadOnly(dialog,"SpinBoxL2");//
ProUISpinboxIncrementSet(dialog,"SpinBoxD1",0);//微调按钮
ProUISpinboxIncrementSet(dialog,"SpinBoxD2",0);//的微调量
ProUISpinboxIncrementSet(dialog,"SpinBoxL1",0);//设置为0,即
ProUISpinboxIncrementSet(dialog,"SpinBoxL2",0);//微调按钮失去作用
}
}
/*=============================================================*\
function: OK_Action() OK按钮的动作函数设置
功能:读取Spinbox中的参数值,然后调用usrCreateRevolveFeat()创建
旋转特征
\*==========================================================*/
void OK_Action(char* dialog,char* componets,ProAppData data)
{
//获得SpinBox输入
ProUISpinboxIntegerGet(dialog,"SpinBoxD1",[$dim[0])]
ProUISpinboxIntegerGet(dialog,"SpinBoxD2",[$dim[1])]
ProUISpinboxIntegerGet(dialog,"SpinBoxL1",[$dim[2])]
ProUISpinboxIntegerGet(dialog,"SpinBoxL2",[$dim[3])]
if (DefaultDtmActFn())//创建基准面
{
usrFeatDel();//删除旧特征
ProUIDialogExit(dialog,1);//退出对话框
usrCreateRevolveFeat(top,front,right,dim,360);//创建新特征
}
}
/*============================================================*\
function: usrCreateRevolveFeat()
功能:填充旋转特征元素树,以创建旋转特征
\*=============================================================*/
void usrCreateRevolveFeat(ProGeomitem BasePln, //(In)草绘平面
ProGeomitem PlnRef1, //(In)参照平面1
ProGeomitem PlnRef2, //(In)参照平面2
int *dimValue, //(In)截面数据数组
double angle) //(In)旋转角度
{
ProError status;
ProSolid solid;
ProSection section;
ProElement elem_tree, element, stdsec_elem, setup_elem,
angle_elem,anglefrom_elem,angleto_elem, secpln_elem;
ProFeatureCreateOptions opts[1];
ProModelitem modelitem;
ProSelection sel;
ProErrorlist errors;
ProMdlCurrentGet((ProMdl*)[$solid)]
/*------------------------------------------------------------*\
为特征树分配内存
\*------------------------------------------------------------*/
ProElementAlloc(PRO_E_FEATURE_TREE, [$elem_tree)]
/*------------------------------------------------------------*\
向特征树添加特征类型元素
\*-----------------------------------------------------------*/
int ivalue=PRO_FEAT_PROTRUSION;
usrElemtreeElementAdd(PRO_E_FEATURE_TYPE,elem_tree,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*-------------------------------------------------------------*\
向特征树添加特征形式元素
\*------------------------------------------------------------*/
ivalue=PRO_REVOLVE;
usrElemtreeElementAdd(PRO_E_FEATURE_FORM,elem_tree,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*-------------------------------------------------------------*\
向特征树添加标准截面元素
\*------------------------------------------------------------*/
ProElementAlloc(PRO_E_STD_SECTION, [$stdsec_elem)]
ProElemtreeElementAdd(elem_tree, NULL, stdsec_elem);
/*------------------------------------------------------------*\
向特征树添加标准截面设置元素
\*-----------------------------------------------------------*/
ProElementAlloc(PRO_E_STD_SEC_SETUP, [$setup_elem)]
ProElemtreeElementAdd(stdsec_elem, NULL, setup_elem);
/*------------------------------------------------------------*\
向特征树添加草绘平面元素
\*------------------------------------------------------------*/
ProElementAlloc(PRO_E_STD_SECTION_PLANE, [$secpln_elem)]
ProElemtreeElementAdd(setup_elem, NULL, secpln_elem);
/*------------------------------------------------------------*\
向特征树添加草绘平面设置元素
\*-----------------------------------------------------------*/
ProSelectionAlloc(NULL, [$BasePln, &sel)]
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE,secpln_elem,
[$sel,PRO_VALUE_TYPE_SELECTION,&element)]
ProSelectionFree([$sel)]
/*-----------------------------------------------------------*\
向特征树添加草绘平面视图方向设置元素
\*-----------------------------------------------------------*/
ivalue=PRO_SEC_VIEW_DIR_SIDE_ONE;
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE_VIEW_DIR,secpln_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
向特征树添加草绘平面定位方向设置元素
\*---------------------------------------------------------------*/
ivalue=PRO_SEC_ORIENT_DIR_UP;
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE_ORIENT_DIR,secpln_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
向特征树添加草绘平面定位方向参照面设置元素
\*---------------------------------------------------------------*/
ProSelectionAlloc(NULL, [$PlnRef1, &sel)]
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE_ORIENT_REF,secpln_elem,
[$sel,PRO_VALUE_TYPE_SELECTION,&element)]
ProSelectionFree([$sel)]
/*---------------------------------------------------------------*\
向特征树添加标准截面草绘元素
\*---------------------------------------------------------------*/
ivalue=PRO_SEC_SKETCH;
usrElemtreeElementAdd(PRO_E_STD_SEC_METHOD,setup_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
创建非完全特征
\*---------------------------------------------------------------*/
ProMdlCurrentGet((ProMdl*)[$solid)]
ProMdlToModelitem(solid, [$modelitem)]
ProSelectionAlloc(NULL, [$modelitem, &sel)]
opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
status=ProFeatureCreate(sel, elem_tree, opts, 1, [$feature, &errors)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("create incomplete feature error");
ProSelectionFree([$sel)]
/*---------------------------------------------------------------*\
从数据库中获得截面元素
\*---------------------------------------------------------------*/
usrSectionGet([$feature,PRO_E_STD_SECTION,§ion)]
/*---------------------------------------------------------------*\
构建和求解截面
\*---------------------------------------------------------------*/
usrSectionBuild([$PlnRef1, &PlnRef2, section,0,dimValue)]
/*---------------------------------------------------------------*\
将草绘器元素添加到特征元素树中
\*---------------------------------------------------------------*/
usrElemtreeElementAdd(PRO_E_SKETCHER,stdsec_elem,
[$section,PRO_VALUE_TYPE_POINTER,&element)]
/*---------------------------------------------------------------*\
旋转角度定义
\*---------------------------------------------------------------*/
ProElementAlloc(PRO_E_REV_ANGLE, [$angle_elem)]
ProElemtreeElementAdd(elem_tree, NULL, angle_elem);
/*---------------------------------------------------------------*\
起始面定义
\*---------------------------------------------------------------*/
ProElementAlloc(PRO_E_REV_ANGLE_FROM, [$anglefrom_elem)]
ProElemtreeElementAdd(angle_elem, NULL, anglefrom_elem);
/*---------------------------------------------------------------*\
旋转形式为给定角度
\*---------------------------------------------------------------*/
ivalue=PRO_REV_ANG_FROM_ANGLE;
usrElemtreeElementAdd(PRO_E_REV_ANGLE_FROM_TYPE,anglefrom_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
角度值设置
\*---------------------------------------------------------------*/
double anglefrom=0;
usrElemtreeElementAdd(PRO_E_REV_ANGLE_FROM_VAL,anglefrom_elem,
[$anglefrom,PRO_VALUE_TYPE_DOUBLE,&element)]
/*--------------------------------------------------------------*\
终止面定义
\*---------------------------------------------------------------*/
ProElementAlloc(PRO_E_REV_ANGLE_TO, [$angleto_elem)]
ProElemtreeElementAdd(angle_elem, NULL, angleto_elem);
/*---------------------------------------------------------------*\
终止面类型
\*--------------------------------------------------------------*/
ivalue=PRO_REV_ANG_TO_ANGLE;
usrElemtreeElementAdd(PRO_E_REV_ANGLE_TO_TYPE,angleto_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
终止面角度值
\*---------------------------------------------------------------*/
usrElemtreeElementAdd(PRO_E_REV_ANGLE_TO_VAL,angleto_elem,
[$angle,PRO_VALUE_TYPE_DOUBLE,&element)]
/*--------------------------------------------------------------------*\
向特征元素树添加新的角度定义元素后重定义特征
\*--------------------------------------------------------------------*/
status=ProFeatureRedefine(NULL, [$feature, elem_tree, opts, 1, &errors)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("redefine erroe");
if(status==PRO_TK_BAD_INPUTS)
AfxMessageBox("bad,input");
ProSectionFree([$section)]
/*---------------------------------------------------
重新调整窗口
---------------------------------------------------*/
int wnd;
ProWindowCurrentGet([$wnd)]
ProWindowRefit(wnd);
}
/*===============================================================*\
函数: UsrElemtreeElementAdd()
功能:设置特征元素之值,并将特征元素添加到特征元素树中
\*=================================================================*/
void usrElemtreeElementAdd(ProElemId id,//(In)特征元素标识符
ProElement parent, //(In)上级元素
void *value, //(In)特征元素值
ProValueDataType type,//(In)特征元素值类型
ProElement *element //(In)特征元素
)
{
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);
}
/*================================================================*\
FUNCTION : usrSectionGet()
从指定特征的元素树中选出草绘器(PRO_E_SKETCHER)元素之值
\*================================================================*/
int usrSectionGet(ProFeature *feature, //(In) 特征句柄
int elemId, //(In) 截面标识符
ProSection *section) //(Out) 截面元素
{
ProError status;
ProElempath path;
ProElempathItem path_items[2];
ProValue value;
ProValueData value_data;
*section = NULL;
//设置特征截面元素的路径
path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
path_items[0].path_item.elem_id = elemId;
path_items[1].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
path_items[1].path_item.elem_id = PRO_E_SKETCHER;
ProElempathAlloc([$path)]
ProElempathDataSet (path, path_items, 2);
//从指定特征中得到路径为path的元素值(非透明的ProValue对象)
status =ProFeatureElemValueGet(feature, path, [$value)]
if(status != PRO_TK_NO_ERROR)
{
AfxMessageBox("get path error");
return(0);}
ProElempathFree([$path)]
//从非透明的ProValue对象得到用户可以访问的数据对象ProValueData
ProValueDataGet(value, [$value_data)]
//获得截面元素指针
*section = (ProSection)value_data.v.p;
return(1);
}
/*==================================================================*\
function: usrSectionBuild()
功能:生成截面草图并求解
\*================================================================*/
int usrSectionBuild(ProGeomitem *refPln1,//(In) 草绘截面参照基准1
ProGeomitem *refPln2, //(In) 草绘截面参照基准2
ProSection section, //(In) 截面元素
int index, //(In) 草图序号
int *dimValue) //(In) 截面数据数组
{
ProSelection sel;
int ent_id;
ProWSecerror serrors;
ProError status;
/*--------------------------------------------------------------------
调用UsrCreateSection()函数作截面草图
--------------------------------------------------------------------*/
if(!usrCreateSection(section,index,dimValue))
{
AfxMessageBox("Section Error!");
return(0);
}
/*--------------------------------------------------------------------
生成参照基准
--------------------------------------------------------------------*/
ProSelectionAlloc(NULL, refPln1, [$sel)]
status=ProSectionEntityFromProjection(section, sel, [$ent_id)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("生成参照基准1出错");
ProSelectionFree([$sel)]
ProSelectionAlloc(NULL, refPln2, [$sel)]
status=ProSectionEntityFromProjection(section, sel, [$ent_id)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("生成参照基准2出错");
ProSelectionFree([$sel)]
/*--------------------------------------------------------------------
自动标注截面
--------------------------------------------------------------------*/
ProSecerrorAlloc([$serrors)]
status=ProSectionAutodim(section, [$serrors)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("自动标注截面出错");
ProSecerrorFree([$serrors)]
return(1);
}
/*===================================================================*\
function: usrCreateSection()
功能:创建截面
\*==============================================================*/
int usrCreateSection(ProSection section,int index,int *dimValue)
{
Pro2dLinedef line[6];
int line_id[6];
double PointX[6],PointY[6];
int i;
switch (index)
{
case 0: //计算截面上各点坐标
PointX[0]=0;
PointY[0]=0;
PointX[1]=PointX[0];
PointY[1]=PointY[0]+dimValue[2]-dimValue[3];
PointX[2]=PointX[0]-dimValue[1]/2;
PointY[2]=PointY[1];
PointX[3]=PointX[2];
PointY[3]=dimValue[2];
PointX[4]=-dimValue[0]/2;
PointY[4]=PointY[3];
PointX[5]=PointX[4];
PointY[5]=PointY[0];
for (i=0;i<6;i++)
{//作草图
line.end1[0]=PointX;
line.end1[1]=PointY;
line.end2[0]=PointX[(i==5)?0:i+1];
line.end2[1]=PointY[(i==5)?0:i+1];
line.type=PRO_2D_LINE;
ProSectionEntityAdd (section,(Pro2dEntdef*)[$line, &line_id)]
}
//旋转轴
line[0].end1[0]=0;
line[0].end1[1]=-10;
line[0].end2[0]=0;
line[0].end2[1]=10;
line[0].type=PRO_2D_CENTER_LINE;
ProSectionEntityAdd (section,(Pro2dEntdef*)[$line[0], &line_id[0])]
break;
default:
break;
}
return (1);
}
/*===================================================================*\
Function: usrFeatDel()(删除当前特征)
\*===============================================================*/
void usrFeatDel()
{
ProSolid solid;
ProMdlCurrentGet((ProMdl*)[$solid)]
ProFeatureDelete(solid, [$feature.id,1,NULL,0)]
ProWindowRepaint(-1);
}
/*============================================================*\
FUNCTION : UsrCreatDefDtm (创建基准面)
\*===============================================================*/
int UsrCreatDefDtm(ProDtmplnConstrType pro_dtmpln_def,
ProName dtm_name,ProGeomitem *pln)
{
ProError status;
ProElement elem_tree,elem_type,elem_consts,elem_const,
elem_const_type;
ProValueData value_data;
ProValue value;
ProModelitem model_modelitem;
ProSelection mdl_sel;
ProFeature feature;
ProErrorlist errors;
ProSolid solid;
/*---------------------------------------------------------------*\
为特征树顶层元素elem_tree分配内存
\*---------------------------------------------------------------*/
ProElementAlloc (PRO_E_FEATURE_TREE, [$elem_tree)]
/*----------------------------------------------------------------*\
向特征树添加特征类型元素elem_ftype
\*----------------------------------------------------------------*/
//设置特征元素之值
ProElementAlloc (PRO_E_FEATURE_TYPE, [$elem_type)]
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_FEAT_DATUM;
ProValueAlloc ([$value)]
ProValueDataSet (value, [$value_data)]
ProElementValueSet (elem_type, value);
//将特征元素添加到特征元素树中
ProElemtreeElementAdd (elem_tree, NULL, elem_type);
/*----------------------------------------------------------------*\
向特征树添加约束平面集元素elem_consts
\*----------------------------------------------------------------*/
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINTS, [$elem_consts)]
ProElemtreeElementAdd (elem_tree, NULL, elem_consts);
/*----------------------------------------------------------------*\
向约束平面集元素添加子元素elem_const
\*----------------------------------------------------------------*/
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINT, [$ elem_const)]
ProElemtreeElementAdd (elem_consts, NULL, elem_const);
/*----------------------------------------------------------------*\
设置基准面类型元素,并添加到特征树中
\*----------------------------------------------------------------*/
ProElementAlloc (PRO_E_DTMPLN_CONSTR_TYPE, [$elem_const_type)]
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = pro_dtmpln_def;
ProValueAlloc ([$value)]
ProValueDataSet (value, [$value_data)]
ProElementValueSet(elem_const_type, value);
ProElemtreeElementAdd (elem_const, NULL,elem_const_type);
/*----------------------------------------------------------------*\
获得当前模型项的选择对象
\*----------------------------------------------------------------*/
ProMdlCurrentGet((ProMdl*)[$solid)]
ProMdlToModelitem(solid, [$model_modelitem)]
ProSelectionAlloc(NULL, [$model_modelitem, &mdl_sel)]
/*----------------------------------------------------------------*\
创建基准平面
\*----------------------------------------------------------------*/
ProFeatureCreate (mdl_sel, elem_tree, NULL, 0,[$feature,&errors)]
/*----------------------------------------------------------------*\
设置基准面名称
\*----------------------------------------------------------------*/
status=ProModelitemNameSet([$feature,dtm_name)]
/*----------------------------------------------------------------*\
重定义
\*----------------------------------------------------------------*/
status=ProFeatureRedefine(NULL, [$feature, elem_tree, NULL, 0, &errors)]
UsrGeomitemPlnGet(feature,pln);
/*----------------------------------------------------------------*\
释放内存空间
\*----------------------------------------------------------------*/
ProElementFree ([$elem_tree)]
ProSelectionFree ([$mdl_sel)]
return (status);
}
/*====================================================================*\
FUNCTION : CreatDefDtm (创建三个默认基准面)
\*====================================================================*/
void CreatDefDtm()
{
ProName dtm_name;
UsrCreatDefDtm(PRO_DTMPLN_DEF_X,
ProStringToWstring (dtm_name, "RIGHT"),[$right)]
UsrCreatDefDtm(PRO_DTMPLN_DEF_Y,
ProStringToWstring (dtm_name, "TOP"),[$top)]
UsrCreatDefDtm(PRO_DTMPLN_DEF_Z,
ProStringToWstring (dtm_name, "FRONT"),[$front)]
}
/*====================================================================*\
FUNCTION : GemitemAction (获得ProGeomitem指针的动作函数)
\*====================================================================*/
ProError GemitemAction(ProGeomitem* p_geomitems,
ProError status,ProAppData app_data)
{
memcpy(app_data, p_geomitems, sizeof(ProGeomitem));
return(PRO_TK_E_FOUND);
}
/*====================================================================*\
FUNCTION : UsrGeomitemPlnGet (获得基准面ProGeomitem指针)
\*====================================================================*/
void UsrGeomitemPlnGet(ProFeature feature,ProGeomitem *geomitem)
{
ProFeatureGeomitemVisit(&feature, PRO_SURFACE,
(ProGeomitemAction)GemitemAction,NULL,geomitem);
}
/*================================================================*\
FUNCTION: DefaultDtmActFn 创建默认基准面
\*================================================================*/
int DefaultDtmActFn()
{
ProSolid solid;
// ProGeomitem **p_data;
if (ProMdlCurrentGet((ProMdl*)&solid)!=PRO_TK_NO_ERROR)
{
AfxMessageBox("零件文档尚未建立,请先新建零件!");
ProUIDialogExit(dialog_name,1);
return false;
}
if (front.type!=PRO_SURFACE || top.type!=PRO_SURFACE
|| right.type!=PRO_SURFACE)
{//创建默认基准面
CreatDefDtm();
}
return true;
} |