/*====================================================================*\ FILE : UgMfgOperCreate.c PURPOSE : Pro/TOOLKIT User Guide Example HISTORY.. DATE BUILD AUTHOR MODIFICATIONS 04-dec-97 H-02-02 mgs $$1 Created \*====================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern ProLine msg_fil17; #define MSG_FIL ProStringToWstring(msg_fil17,"msg_ugmfg.txt") typedef struct { ProMfg model; int workcell; ProBoolean wc_found; ProSelection csys; ProBoolean csys_found; } OperEnts ; /*====================================================================*\ Function : UserCsysIdGet Purpose : Get the id of the csys feature's geometry \*====================================================================*/ ProError UserCsysIdGet ( ProGeomitem *geom_item, ProError err, ProAppData id ) { *(int*) id = geom_item->id; return PRO_TK_NO_ERROR; } /*====================================================================*\ Function : UserOperEnitiesCollect Purpose : Collect worckcell and csys and use them to create an operation \*====================================================================*/ ProError UserOperEnitiesCollect ( ProFeature *feature, ProError err, ProAppData entities ) { ProError status; ProFeattype feat_type; ProWcellType wcell_type; OperEnts *oper_ents = (OperEnts*)entities; ProSelection selection; int id; ProError UserWpieceSelCreate ( ProMfg, int, ProType, ProSelection*); status = ProFeatureTypeGet(feature, &feat_type); ERROR_CHECK("UserOperEnitiesCollect","ProFeatureTypeGet()",status); if (status == PRO_TK_NO_ERROR) { if ( !oper_ents->wc_found && feat_type == PRO_FEAT_WORKCELL) { status = ProWcellTypeGet((ProWcell*)feature, &wcell_type); ERROR_CHECK("UserOperEnitiesCollect","ProWcellTypeGet()",status); if ( PRO_WCELL_LATHE == wcell_type) { oper_ents->workcell = feature->id; oper_ents->wc_found = PRO_B_TRUE; } } else if (!oper_ents->csys_found && feat_type == PRO_FEAT_CSYS) { status = ProFeatureSelectionGet(feature,&selection); ERROR_CHECK("UserOperEnitiesCollect","ProFeatureSelectionCreate()",status); ProSelectionCopy(selection, &(oper_ents->csys)); /* status = ProFeatureGeomitemVisit(feature, PRO_CSYS, UserCsysIdGet, NULL, (ProAppData) &id); ERROR_CHECK("UserOperEnitiesCollect","ProFeatureGeomitemVisit",status); status = UserWpieceSelCreate(oper_ents->model, id, PRO_CSYS, &(oper_ents->csys)); ERROR_CHECK("UserOperEnitiesCollect","UserWpieceSelCreate",status); */ oper_ents->csys_found = PRO_B_TRUE; } } if ( oper_ents->wc_found && oper_ents->csys_found) return PRO_TK_STOP_VISIT; else return PRO_TK_NO_ERROR; } /*====================================================================*\ FUNCTION : UserOperCreate PURPOSE : Top level operation creation function \*====================================================================*/ int UserOperCreate () { ProMdl mfg_model; ProError status; ProSolid mfg_solid; OperEnts entities; ProError UserOperationCreate (); wchar_t feat_name[PRO_NAME_SIZE], def_wname[PRO_NAME_SIZE]; char def_name[] = "DemoOp", str[PRO_LINE_SIZE]; status = ProMdlCurrentGet(&mfg_model); ERROR_CHECK("UserOperCreate","ProMdlCurrentGet",status); /*--------------------------------------------------------------------*\ Get the manufacturing solid (workpiece) \*--------------------------------------------------------------------*/ status = ProMfgSolidGet((ProMfg)mfg_model, &mfg_solid); ERROR_CHECK("UserOperCreate","ProMfgSolidGet",status); /*--------------------------------------------------------------------*\ Initialize search state \*--------------------------------------------------------------------*/ entities.wc_found = entities.csys_found = PRO_B_FALSE; entities.model = (ProMfg)mfg_model; status = ProSolidFeatVisit ( mfg_solid, UserOperEnitiesCollect,NULL, (ProAppData) &entities ); ERROR_CHECK("UserOperCreate","ProSolidFeatVisit",status); /*--------------------------------------------------------------------*\ If both csys and wcell entities were found then create the feature \*--------------------------------------------------------------------*/ if (entities.wc_found==PRO_B_TRUE && entities.csys_found==PRO_B_TRUE) { ProMessageDisplay(MSG_FIL, "USER Enter operation name: "); ProStringToWstring(def_wname, def_name); ProUtilStringGet(feat_name, def_wname, PRO_NAME_SIZE); status = UserOperationCreate((ProMfg)mfg_model, feat_name, entities.workcell, entities.csys ); ERROR_CHECK("UserOperCreate","UserOperationCreate",status); } else { if (entities.wc_found == PRO_B_FALSE) { fprintf(stderr, "A suitable worckcell was not found\n"); } if (entities.csys_found==PRO_B_FALSE) { fprintf(stderr, "A suitable coord-sys was not found\n"); } } return ((int)status); } /*++++++++++++++UG_CODE_SAMPLE_STARTS_HERE++++++++++++++++++++++++++++*/ /*====================================================================*\ Function : UserOperationCreate Purpose : Create operation using element tree \*====================================================================*/ ProError UserOperationCreate ( ProMfg mfg_model, ProName feat_name, int wcell_id, ProSelection csys_sel ) { ProError err = PRO_TK_NO_ERROR; ProElement oper_elem = (ProElement)NULL; /* Individual element */ ProElement oper_elem_tree = (ProElement)NULL; /* Entire tree */ ProValueData value_data; ProValue value = (ProValue)NULL; ProErrorlist errors; ProSelection selection; ProFeature oper_feature; int i = 0; ProError UserWpieceSelCreate ( ProMfg, int, ProType, ProSelection*); static ElemTable oper_elem_table[] = { { PRO_E_FEATURE_TYPE, PRO_VALUE_TYPE_INT }, { PRO_E_WCELL, PRO_VALUE_TYPE_INT }, { PRO_E_MACH_CSYS, PRO_VALUE_TYPE_SELECTION }, { PRO_E_FEAT_NAME, PRO_VALUE_TYPE_WSTRING }}; int oper_elem_type_size = sizeof(oper_elem_table)/ sizeof(ElemTable); err = ProElementAlloc(PRO_E_FEATURE_TREE, &oper_elem_tree); ERROR_CHECK("UserOperationCreate","ProElementAlloc()", err); for (i=0 ; i < oper_elem_type_size; i++) { err = ProElementAlloc(oper_elem_table[i].elem_type, &oper_elem); ERROR_CHECK("UserOperationCreate","ProElementAlloc()", err); switch (oper_elem_table[i].elem_type) { case PRO_E_FEATURE_TYPE: value_data.v.i = PRO_FEAT_OPERATION; break; case PRO_E_WCELL: value_data.v.i = wcell_id; break; case PRO_E_MACH_CSYS: err = ProSelectionCopy(csys_sel, &(value_data.v.r)); ERROR_CHECK("UserOperationCreate","ProSelectionCopy()",err); break; case PRO_E_FEAT_NAME: value_data.v.w = (wchar_t*) malloc (sizeof(ProName)); if (value_data.v.w) ProUtilWstrcpy(value_data.v.w,feat_name); else err = PRO_TK_BAD_INPUTS; break; default: fprintf(stderr, "Error setting element type\n"); return PRO_TK_GENERAL_ERROR; break; } if ( oper_elem_table[i].val_type != ARRAY) { value_data.type = oper_elem_table[i].val_type; err = ProValueAlloc ( &value ); if (err == PRO_TK_NO_ERROR) { err = ProValueDataSet (value, &value_data); ERROR_CHECK("UserOperationCreate", "ProValueDataSet()", err); } if ( err == PRO_TK_NO_ERROR ) { err = ProElementValueSet ( oper_elem, value ); ERROR_CHECK("UserOperationCreate", "ProElementValueSet()", err); } } if ( err == PRO_TK_NO_ERROR ) { err = ProElemtreeElementAdd (oper_elem_tree, NULL, oper_elem ); ERROR_CHECK("UserOperationCreate", "ProElemtreeElementAdd()", err); } } ProUtilElementtreePrint(oper_elem_tree, PRO_TEST_INFO_WINDOW, NULL ); if (err == PRO_TK_NO_ERROR ) err = UserWpieceSelCreate (mfg_model, PRO_TK_NOT_USED, PRO_TK_NOT_USED, &selection); if (err == PRO_TK_NO_ERROR) { err = ProFeatureCreate(selection, oper_elem_tree, NULL, 0, &oper_feature, &errors); ERROR_CHECK("UserOperationCreate", "ProFeatureCreate()", err); } err = ProElementFree(&oper_elem_tree); ERROR_CHECK("UserOperationCreate", "ProElementFree()", err); return ((int)err); } /*++++++++++++++UG_CODE_SAMPLE_ENDS_HERE++++++++++++++++++++++++++++++*/ #undef MSG_FIL