/*----------------------------------------------------------------------------- File: batch.c Description: demo of batch mode PTC File Date Version Author Vers Comment --------- ------- -------- ----- --------------------------------------------- 04-Dec-97 H-02-02 Philippe $$1 setup 26-Oct-98 I-01-24 AKH $$2 make complete demo program 28-Oct-98 I-01-24 AKH $$3 Fix argument of ProSectionSolve in UserMakeSlot -----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include "ProToolkit.h" #include "ProArray.h" #include "ProCore.h" #include "ProFeatType.h" #include "ProFeatForm.h" #include "ProModFeat.h" #include "ProElement.h" #include "ProExtrude.h" #include "ProGeomitem.h" #include "ProGeomitemdata.h" #include "ProMdl.h" #include "ProSection.h" #include "ProSecdim.h" #include "ProSelection.h" #include "ProStdSection.h" #include "ProObjects.h" #include "ProUtil.h" /*--------------------------------------------------------------------*\ C System includes \*--------------------------------------------------------------------*/ #include /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "user_tk_error.h" #include "UtilCollect.h" #include "UtilTree.h" #include "UtilString.h" #include "UtilMath.h" /*--------------------------------------------------------------------*\ Macros \*--------------------------------------------------------------------*/ #define SIZEOFARR(a) (sizeof(a)/(sizeof(a[0]))) #define VectorCmp(a,b) (fabs(ProUtilPointsDist(a,b))3.14); return x; } /*=============================================================*\ Function: UserMakeSlot Purpose: Make new feature (SLOT). \*=============================================================*/ ProError UserMakeSlot(ProMdl model, ProFeature *feature, ProArcdata p_arc, ProSelection arc_sel) { static ElemTreeData tree[]={ {0, PRO_E_FEATURE_TREE, {-1}}, {1, PRO_E_FEATURE_TYPE, {PRO_VALUE_TYPE_INT, PRO_FEAT_SLOT}}, {1, PRO_E_FEATURE_FORM, {PRO_VALUE_TYPE_INT, PRO_EXTRUDE}}, {1, PRO_E_STD_SECTION, {-1}}, {2, PRO_E_STD_SEC_SETUP, {-1}}, {3, PRO_E_STD_SECTION_PLANE, {-1}}, {4, PRO_E_STD_SEC_PLANE, {PRO_VALUE_TYPE_SELECTION}}, {4, PRO_E_STD_SEC_PLANE_VIEW_DIR, {PRO_VALUE_TYPE_INT, PRO_SEC_VIEW_DIR_SIDE_TWO}}, {4, PRO_E_STD_SEC_PLANE_ORIENT_DIR, {PRO_VALUE_TYPE_INT, PRO_SEC_ORIENT_DIR_LEFT}}, {4, PRO_E_STD_SEC_PLANE_ORIENT_REF, {PRO_VALUE_TYPE_SELECTION}}, {1, PRO_E_STD_EXT_DEPTH, {-1}}, {2, PRO_E_EXT_DEPTH_FROM, {-1}}, {3, PRO_E_EXT_DEPTH_FROM_TYPE, {PRO_VALUE_TYPE_INT, PRO_EXT_DEPTH_FROM_ALL}}, {2, PRO_E_EXT_DEPTH_TO, {-1}}, {3, PRO_E_EXT_DEPTH_TO_TYPE, {PRO_VALUE_TYPE_INT, PRO_EXT_DEPTH_TO_ALL}} }; static ProElempathItem path_items[] = { {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SECTION}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_SKETCHER} }; static ProElempathItem path_1[] = { {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SECTION}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SEC_SETUP}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SECTION_PLANE}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SEC_PLANE} }; static ProElempathItem path_2[] = { {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SECTION}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SEC_SETUP}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SECTION_PLANE}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SEC_PLANE_ORIENT_REF} }; static ElemTreeData sketch[]={ {1, PRO_E_SKETCHER, {PRO_VALUE_TYPE_POINTER}} }; int circle_id, arc_id; ProError status; ProErrorlist errs; ProWSecerror errors; ProValue value; ProValueData value_data; ProFeature newFeature; ProFeatureCreateOptions opts[1]; ProModelitem model_item; ProSelection model_sel; ProElement elem_tree; ProElempath path; ProElement elem_sec; ProSection section; Pro2dCircledef circle; Pro2dEntdef *p_ent; Pro2dArcdef *p_2darc; /*====================================================================*\ Copy PRO_E_STD_SEC_PLANE from source feature tree to the new feature tree \*====================================================================*/ status = ProElempathAlloc(&path); status = ProElempathDataSet(path, path_1, 4); status = ProFeatureElemValueGet(feature, path, &value); status = ProValueDataGet(value, &value_data); status = ProSelectionCopy(value_data.v.r,&tree[6].data.v.r); status = ProElempathFree(&path); /*====================================================================*\ Copy PRO_E_STD_SEC_PLANE_ORIENT_REF from source feature tree to the new feature tree \*====================================================================*/ status = ProElempathAlloc(&path); status = ProElempathDataSet(path, path_2, 4); status = ProFeatureElemValueGet(feature, path, &value); status = ProValueDataGet(value, &value_data); status = ProSelectionCopy(value_data.v.r,&tree[9].data.v.r); status = ProElempathFree(&path); /*====================================================================*\ Create incomplete feature. \*====================================================================*/ opts[0]=PRO_FEAT_CR_INCOMPLETE_FEAT; status = ProMdlToModelitem(model, &model_item); status = ProSelectionAlloc(NULL, &model_item, &model_sel); status = ProUtilElemtreeCreate(tree, SIZEOFARR(tree), NULL, &elem_tree); status = ProFeatureCreate(model_sel, elem_tree, opts, 1, &newFeature, &errs); if (status!=PRO_TK_NO_ERROR) { return(PRO_TK_GENERAL_ERROR); } status = ProSelectionFree(&model_sel); /*====================================================================*\ Get SECTION from feature tree. \*====================================================================*/ status = ProElempathAlloc(&path); status = ProElempathDataSet(path, path_items, 2); status = ProFeatureElemValueGet(&newFeature, path, &value); status = ProValueDataGet(value, &value_data); section= (ProSection)value_data.v.p; status = ProElempathFree(&path); /*====================================================================*\ Add one of ARC to the section and make new circle based on ARC data. \*====================================================================*/ status = ProSectionEntityFromProjection(section, arc_sel, &arc_id); status = ProSectionEntityGet(section,arc_id,&p_ent); p_2darc=(Pro2dArcdef*)p_ent; circle.type = PRO_2D_CIRCLE; circle.center[0] = p_2darc->center[0]; circle.center[1] = p_2darc->center[1]; circle.radius = p_2darc->radius; status = ProSectionEntityAdd(section, (Pro2dEntdef*)&circle, &circle_id); /*====================================================================*\ Solve complete section. \*====================================================================*/ status = ProSecerrorAlloc(&errors); status = ProSectionSolve(section, &errors); if (status!=PRO_TK_NO_ERROR) { return(PRO_TK_GENERAL_ERROR); } /*====================================================================*\ Define sketch data on the feature tree. \*====================================================================*/ sketch[0].data.v.p = (void*)section; status = ProElempathAlloc(&path); status = ProElempathDataSet(path, path_items, 1); status = ProElemtreeElementGet(elem_tree, path, &elem_sec); status = ProElempathFree(&path); status = ProUtilElemtreeCreate(sketch, 1, elem_sec, &elem_sec); /*====================================================================*\ Redefine complete feature. \*====================================================================*/ opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS; status = ProFeatureRedefine(NULL, &newFeature, elem_tree, opts, 1, &errs); if (status!=PRO_TK_NO_ERROR) { return(PRO_TK_GENERAL_ERROR); } /*====================================================================*\ Free feature tree. \*====================================================================*/ status = ProSelectionFree(&tree[6].data.v.r); status = ProSelectionFree(&tree[9].data.v.r); status = ProElementFree(&elem_tree); return (PRO_TK_NO_ERROR); } /*=============================================================*\ Function: UserInsHoles Purpose: Find the circular datum curves and replace them with holes. \*=============================================================*/ ProError UserInsHoles(ProMdl p_part) { int feature_num, geomitem_num, component_num, i,j,k,n, p_id; ProError status; ProFeattype f_type; ProEnttype crv_type; ProCurve p_curve; ProFeature *p_feature; ProGeomitem *p_geomitem, p_geom; CurveComponent *p_component; ProGeomitemdata *arc1, *arc2; ProArcdata dt_arc1, dt_arc2; ProSelection p_sel; /*==========================================================================*\ Collect all datum curves on the current part. \*==========================================================================*/ status = ProUtilCollectDtmCurveFeat((ProSolid)p_part,&p_feature); status = ProArraySizeGet((ProArray)p_feature, &feature_num); if (feature_num>0) for(i=0; i0) for(j=0; jdata.p_curve_data->arc); dt_arc2=(arc2->data.p_curve_data->arc);; if(UserChkCircle(dt_arc1,dt_arc2)) { /*==========================================================================*\ It's circle. Make hole. \*==========================================================================*/ status = ProCurveToGeomitem((ProSolid)p_part, p_component[1].p_curve, &p_geom); status = ProSelectionAlloc(NULL,(ProModelitem*)&p_geom,&p_sel); UserMakeSlot(p_part,&p_feature[i],dt_arc1,p_sel); status = ProSelectionFree(&p_sel); } } } ProArrayFree((ProArray*)&p_component); } }; ProArrayFree((ProArray*)&p_geomitem); } status = ProArrayFree((ProArray*)&p_feature); return (PRO_TK_NO_ERROR); } /*===========================================================================*\ Load the part specified by the command line argument, and replace its datum curves with holes. \*===========================================================================*/ int user_initialize( int argc, char *argv[] ) { ProMdl p_part; ProName name_wchar; ProError err; char *part_name; /*---------------------------------------------------------------------------*\ Set up the part name from the argument list. Note that Pro/ENGINEER arguments for Pro/TOOLKIT have a leading '+' or '-' \*---------------------------------------------------------------------------*/ if (argc>1){ part_name = argv[1]; part_name++; ProStringToWstring(name_wchar,part_name); } else{ ProEngineerEnd(); } /*---------------------------------------------------------------------------*\ retrieve part \*---------------------------------------------------------------------------*/ err=ProMdlRetrieve(name_wchar,PRO_PART,&p_part); if (err!=PRO_TK_NO_ERROR) { ProEngineerEnd(); } /*---------------------------------------------------------------------------*\ Add the holes to the part \*---------------------------------------------------------------------------*/ UserInsHoles (p_part); /*---------------------------------------------------------------------------*\ Save the part \*---------------------------------------------------------------------------*/ ProMdlSave(p_part); /*---------------------------------------------------------------------------*\ Terminate the Pro/ENGINEER session. \*---------------------------------------------------------------------------*/ ProEngineerEnd(); return (0); } /*===========================================================================*\ Report successful termination of the program. \*===========================================================================*/ void user_terminate() { printf ("Pro/TOOLKIT application terminated successfully\n"); }