📄 samp6.c
字号:
/*load head file*/
#include<ProToolkit.h>#include<Pro2dEntdef.h>#include<ProANSI.h>#include<ProAnimate.h>#include<ProArray.h>#include<ProAsmcomp.h>#include<ProAsmcomppath.h>#include<ProAssembly.h>#include<ProAxis.h>#include<ProChamfer.h>#include<ProClCmd.h>#include<ProColor.h>#include<ProComm.h>#include<ProConst.h>#include<ProContour.h>#include<ProContourdata.h>#include<ProCore.h>#include<ProCsys.h>#include<ProCsysdata.h>#include<ProCurve.h>#include<ProCurvedata.h>#include<ProDatumdata.h>#include<ProDisplist.h>#include<ProDtmAxis.h>#include<ProDtmCrv.h>#include<ProDtmCrvSketch.h>#include<ProDtmCsys.h>#include<ProDtmPln.h>#include<ProEdge.h>#include<ProEdgedata.h>#include<ProElemId.h>#include<ProElement.h>#include<ProElempath.h>#include<ProExpldstate.h>#include<ProExtdata.h>#include<ProExtobj.h>#include<ProExtobjCB.h>#include<ProExtobjDisp.h>#include<ProExtobjRef.h>#include<ProExtobjSel.h>#include<ProExtrude.h>#include<ProFaminstance.h>#include<ProFamtable.h>#include<ProFeatForm.h>#include<ProFeatType.h>#include<ProFeature.h>#include<ProFixture.h>#include<ProFlatSrf.h>#include<ProForeignCurve.h>#include<ProGeomitem.h>#include<ProGeomitemdata.h>#include<ProGraphic.h>#include<ProGroup.h>#include<ProHardware.h>#include<ProImportfeat.h>#include<ProIntfData.h>#include<ProItemerr.h>#include<ProLayer.h>#include<ProLayerR19.h>#include<ProMaterial.h>#include<ProMdl.h>#include<ProMenu.h>#include<ProMenuBar.h>#include<ProMessage.h>#include<ProMfg.h>#include<ProMfgoper.h>#include<ProModFeat.h>#include<ProMode.h>#include<ProModelitem.h>#include<ProNcseq.h>#include<ProNcseqElem.h>#include<ProNote.h>#include<ProNotify.h>#include<ProObjects.h>#include<ProParameter.h>#include<ProParamval.h>#include<ProPart.h>#include<ProPattern.h>#include<ProPecktable.h>#include<ProPoint.h>#include<ProProcstep.h>#include<ProQuilt.h>#include<ProQuiltdata.h>#include<ProRelSet.h>#include<ProReplace.h>#include<ProRevolve.h>#include<ProRmdt.h>#include<ProRule.h>#include<ProSecConstr.h>#include<ProSecdim.h>#include<ProSecdimType.h>#include<ProSecerror.h>#include<ProSection.h>#include<ProSelection.h>#include<ProSheetmetal.h>#include<ProSimprep.h>#include<ProSimprepdata.h>#include<ProSizeConst.h>#include<ProSolid.h>#include<ProStdSection.h>#include<ProSurface.h>#include<ProSurfacedata.h>#include<ProSweep.h>#include<ProTool.h>#include<ProToolElem.h>#include<ProToolinput.h>#include<ProUICmd.h>#include<ProUtil.h>#include<ProValue.h>#include<ProVerstamp.h>#include<ProView.h>#include<ProWcell.h>#include<ProWchar.h>#include<ProWindows.h>#include<ProWorkspace.h>#include<ProWstring.h>#include "UtilMath.h"
#include "TestError.h"
/*---------------------- Function Prototypes -------------------------*/
ProError UserSectionCreateExample();
ProError ProDemoSectCreate();
/*------------------------- Global Data -----------------------------*/
typedef char ProUtilCname[PRO_NAME_SIZE];
ProFileName UserMsg;
/*--------------------------------------------------------------------*\Application global data\*--------------------------------------------------------------------*/static uiCmdAccessState TestAccessDefault(uiCmdAccessMode access_mode){ return (ACCESS_AVAILABLE);}/*===========================================================================*\ Function : main Purpose : Test the ProToolkitMain() function. main is optional function.\*===========================================================================*/main(argc, argv)int argc;char **argv;{ ProToolkitMain(argc, argv); return(0);}/*====================================================================*\FUNCTION : user_initialize()PURPOSE : Pro/DEVELOP standard initialize - define menu button\*====================================================================*/int user_initialize( int argc, char *argv[], wchar_t errbuf[80]){
ProError status;
uiCmdCmdId cmd_id;
/*----------------------------------------------------------------*\
消息文件
\*----------------------------------------------------------------*/
ProStringToWstring (UserMsg, "msg.txt");
status = ProMessageDisplay (UserMsg, "USER %0s", "Demo of creating section.\n");
/*---------------------------------------------------------------------*\
Add new button to the menu bar
\*---------------------------------------------------------------------*/
status = ProCmdActionAdd("MyCmd",
(uiCmdCmdActFn)UserSectionCreateExample,
uiProe2ndImmediate, TestAccessDefault,
PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
status = ProMenubarmenuPushbuttonAdd(
"File", "MyCmd", "Create Section", "Create Section",
"File.psh_exit", PRO_B_TRUE, cmd_id, UserMsg);
return (0);
}
/*====================================================================*\
FUNCTION : user_terminate()
PURPOSE : To handle any termination actions
\*====================================================================*/
void user_terminate()
{
}
/*===========================================================*\
FUNCTION : UserSectionCreateExample()
PURPOSE : Invokes the function to create the Section model
\*===========================================================*/
ProError UserSectionCreateExample()
{
ProError status;
double width;
double height;
double bite_radius;
double bite_height;
char *name = "sect_sample";
ProBoolean alloc;
char filename[PRO_NAME_SIZE];
ProSection section;
int win_id;
ProMacro wmacro;
char *macro = "#MODE;#SKETCHER;#SEARCH/RETR;#IN SESSION;#SECT_SAMPLE.SEC;";
width = 300;
height = 200;
bite_radius = 80;
bite_height = 100;
alloc = PRO_B_TRUE;
status = ProDemoSectCreate( width, height, bite_radius,
bite_height, name, alloc, §ion );
ERROR_CHECK( "UserSectionCreateExample", "ProDemoSectCreate", status );
ProStringToWstring( wmacro, macro );
ProMacroLoad(wmacro);
return ( PRO_TK_NO_ERROR );
}
/*===========================================================*\
FUNCTION : ProDemoSectCreate()
PURPOSE : Creates a section model whose shape is a
rectangle with a semi-circular "bite" from
the left side.
\*===========================================================*/
ProError ProDemoSectCreate(
double width, /* (In) The rectangle width */
double height, /* (In) The rectangle height */
double bite_radius, /* (In) The radius of the bite */
double bite_height, /* (In) The height of the bite */
ProUtilCname name, /* (In) The sketch name */
ProBoolean alloc, /* (In) mem Alloc specifier */
ProSection *p_section) /* (In/Out) The section handle for the
sketch */
{
ProError status, solve_status;
ProSection section;
ProName wname;
Pro2dArcdef arc;
Pro2dLinedef line;
int bottom_id, right_id, top_id,
left_top_id,left_bottom_id, arc_id;
int width_dim, height_dim, bite_height_dim,
bite_radius_dim;
ProSectionPointType pnt_types[2];
Pro2dPnt point;
int n_errors, e;
ProWSecerror errors;
ProMsg wmsg;
char msg[PRO_PATH_SIZE];
int dims[2];
/*-----------------------------------------------------------*\
Check that the dimensions are possible.
\*-----------------------------------------------------------*/
if (width < EPSM6 || height < EPSM6)
return (-1);
if (bite_height <= bite_radius)
return (-1);
if (bite_height + bite_radius > height)
return (-1);
if (bite_radius >= width)
return (-1);
/*-----------------------------------------------------------*\
Allocate the handle for the 2-D section.
\*-----------------------------------------------------------*/
if (alloc == PRO_B_TRUE)
{
status = ProSection2DAlloc (§ion);
}
else
section = *p_section;
/*-----------------------------------------------------------*\
Set the name of the section.
\*-----------------------------------------------------------*/
pro_str_to_wstr (wname, name);
status = ProSectionNameSet (section, wname);
/*-----------------------------------------------------------*\
Set the epsilon value.
\*-----------------------------------------------------------*/
status = ProSectionEpsilonSet (section, 0.5);
/*-----------------------------------------------------------*\
Add a straight-line entity for the bottom of the rectangle.
\*-----------------------------------------------------------*/
line.type = PRO_2D_LINE;
line.end1[0] = 0.0;
line.end1[1] = 0.0;
line.end2[0] = width + 0.1;
line.end2[1] = 0.0;
status = ProSectionEntityAdd (section,
(Pro2dEntdef*)&line, &bottom_id);
/*-----------------------------------------------------------*\
...right
\*-----------------------------------------------------------*/
line.type = PRO_2D_LINE;
line.end1[0] = width + 0.1;
line.end1[1] = 0.0;
line.end2[0] = width;
line.end2[1] = height;
status = ProSectionEntityAdd (section,
(Pro2dEntdef*)&line, &right_id);
/*-----------------------------------------------------------*\
...top
\*-----------------------------------------------------------*/
line.type = PRO_2D_LINE;
line.end1[0] = width;
line.end1[1] = height;
line.end2[0] = 0.0;
line.end2[1] = height;
status = ProSectionEntityAdd (section, (Pro2dEntdef*)&line,
&top_id);
/*-----------------------------------------------------------*\
...left above the bite
\*-----------------------------------------------------------*/
line.type = PRO_2D_LINE;
line.end1[0] = 0.0;
line.end1[1] = bite_height - bite_radius;
line.end2[0] = 0.0;
line.end2[1] = 0.0;
status = ProSectionEntityAdd (section, (Pro2dEntdef*)&line,
&left_top_id);
/*-----------------------------------------------------------*\
...left below the bite
\*-----------------------------------------------------------*/
line.type = PRO_2D_LINE;
line.end1[0] = 0.0;
line.end1[1] = height;
line.end2[0] = 0.0;
line.end2[1] = bite_height + bite_radius;
status = ProSectionEntityAdd (section, (Pro2dEntdef*)&line,
&left_bottom_id);
/*-----------------------------------------------------------*\
Add an arc entity for the bite itself.
\*-----------------------------------------------------------*/
arc.type = PRO_2D_ARC;
arc.center[0] = 0.0;
arc.center[1] = bite_height;
arc.start_angle = PI * 1.5; /* 270 degrees counterclockwise
from the X axis */
arc.end_angle = PI / 2.0; /* 90 degrees counterclockwise
from the X axis */
arc.radius = bite_radius;
status = ProSectionEntityAdd (section, (Pro2dEntdef*)&arc,
&arc_id);
/*-----------------------------------------------------------*\
Add a dimension for the width (the length of the top
entity).
\*-----------------------------------------------------------*/
point[0] = width/2.0;
point[1] = height + 10.0;
pnt_types[0] = PRO_ENT_WHOLE;
status = ProSecdimCreate (section, &top_id, pnt_types, 1,
PRO_TK_DIM_LINE, point, &width_dim);
/*-----------------------------------------------------------*\
Add a dimension for the height (the length of the
right entity).
\*-----------------------------------------------------------*/
point[0] = width + 1.0;
point[1] = height/2.0;
pnt_types[0] = PRO_ENT_WHOLE;
status = ProSecdimCreate (section, &right_id, pnt_types, 1,
PRO_TK_DIM_LINE, point, &height_dim);
/*-----------------------------------------------------------*\
Add a dimension for the height of the bite.
\*-----------------------------------------------------------*/
point[0] = -1.0;
point[1] = bite_height/2.0;
dims[0] = bottom_id;
dims[1] = arc_id;
pnt_types[0] = PRO_ENT_WHOLE;
pnt_types[1] = PRO_ENT_CENTER;
status = ProSecdimCreate (section, dims, pnt_types, 2,
PRO_TK_DIM_LINE_POINT, point, &bite_height_dim);
/*-----------------------------------------------------------*\
Add a dimension for the radius of the bite.
\*-----------------------------------------------------------*/
point[0] = bite_radius + 1.0;
point[1] = bite_height;
pnt_types[0] = PRO_ENT_WHOLE;
status = ProSecdimCreate (section, &arc_id, pnt_types, 1,
PRO_TK_DIM_RAD, point, &bite_radius_dim);
/*-----------------------------------------------------------*\
Claim memory for the error structure.
\*-----------------------------------------------------------*/
status = ProSecerrorAlloc (&errors);
/*-----------------------------------------------------------*\
Solve the section.
\*-----------------------------------------------------------*/
solve_status = ProSectionSolve (section, &errors);
/*-----------------------------------------------------------*\
If the solve failed, report error messages and exit.
\*-----------------------------------------------------------*/
if (solve_status != PRO_TK_NO_ERROR)
{
status = ProSecerrorCount (&errors, &n_errors);
for (e = 0; e < n_errors; e++)
{
status = ProSecerrorMsgGet (errors, e, wmsg);
ProWstringToString (msg, wmsg);
printf ("Error %d message : %s\n",e, msg);
}
return (-1);
}
status = ProSecerrorFree (&errors);
/*-----------------------------------------------------------*\
Save the section.
\*-----------------------------------------------------------*/
status = ProMdlSave (section);
/*-----------------------------------------------------------*\
Return the section handle
\*-----------------------------------------------------------*/
*p_section = section;
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -