/** Update Component modifications from Creo to CyPhy (Creo Update (Export)). Pre-conditions: * MetaLink is running and CyPhy and CAD-assebler are connected * Creo is opened in AVM component editing mode. - CyPhy switches Creo to AVM component editing mode. - CyPhy starts CAD-assembler in component editing mode. Action: * Perform AVM component edits in Creo - add a datum - modify a parameter * Press the Update Cyphy Component button. Post-condition: * The updates are reflected in the CyPhy component. */ ProError DoUpdateComponent() { ProError status = PRO_TK_NO_ERROR; ProMdlType type; wchar_t msg[1000]; ProMdl mdl; *msg = 0; if (isis::GlobalModelData::Instance.mode == isis::COMPONENTEDIT) { ProMdlCurrentGet(&mdl); } else { mdl = getSelectedMdl(); } if (!mdl) { ErrorDialog(L"No model has been selected."); return status; } ProMdlTypeGet(mdl, &type); if (type != PRO_MDL_PART && type != PRO_MDL_ASSEMBLY) { ErrorDialog(L"Selected model has to be either part or assembly."); return status; } UpdateComponent(mdl); return status; }
uiCmdAccessState UserAccessDefault(uiCmdAccessMode access_mode) { UNUSED_ALWAYS(access_mode); ProMdl curmdl = NULL; if (ProMdlCurrentGet(&curmdl) != PRO_TK_NO_ERROR) return ACCESS_UNAVAILABLE; ProMdlType type; ProMdlTypeGet(curmdl, &type); if (type == PRO_MDL_PART || type == PRO_ASSEMBLY) return ACCESS_AVAILABLE; else return ACCESS_UNAVAILABLE; }
// 生成包覆体 void OnCreateBodyActFn() { /*if (!QuickCheckValidLicense(SMART_PROFESSIONAL)) return;*/ AFX_MANAGE_STATE(AfxGetStaticModuleState()); DestroyAllDialog(); CancelSelectDialog(); Sleep(50); // 检查当前模型环境 ProMdl pMdl = GetCurrentMdl(); if (pMdl == NULL) { MessageBox(NULL, L"当前环境未发现模型!", L"提示", MB_OK|MB_ICONWARNING); return; } ProMdlType typeMdl; ProMdlTypeGet(pMdl, &typeMdl); if (typeMdl != PRO_MDL_ASSEMBLY) { MessageBox(NULL, L"该功能仅在装配环境下有效!", L"提示", MB_OK|MB_ICONWARNING); return; } //ExportElemTreeXML(); // 选择一个面组 vector<ProSelection> arrSelQlt; ShowMessageTip(L"Tips.选择要加厚的包覆面..."); if (SelectObject(arrSelQlt, "dtmqlt")) { // 输入整体加厚值 double dThickValue; ShowMessageTip(L"指定厚度值,不能为0,负值表示向内加厚:"); if (ProMessageDoubleRead(NULL, &dThickValue) == PRO_TK_NO_ERROR) { // 创建发布几何 int nPubFeatID = CreatePublishGeom(pMdl, arrSelQlt[0]); ProName nameAsm; ProMdlNameGet(pMdl, nameAsm); CString strNamePart = nameAsm; ProName namePart; for (int i=101; ;i++) { CString strTemp; strTemp.Format(L"%s_%d", nameAsm, i); wcsncpy_s(namePart, PRO_NAME_SIZE, strTemp, _TRUNCATE); ProMdl pMdlTemp; if (ProMdlInit(namePart, PRO_MDL_PART, &pMdlTemp) == PRO_TK_E_NOT_FOUND) break; } // 新建一个零件 ProAsmcomp compPart; ProAsmcompCreateCopy(ProMdlToAssembly(pMdl), namePart, PRO_MDL_PART, NULL, PRO_B_FALSE, &compPart); //ProSolidRegenerate(pMdl); ProMdl pMdlPart; ProAsmcompMdlGet(&compPart, &pMdlPart); ProModelitem itemAsm; ProMdlToModelitem(pMdl, &itemAsm); ProSelection selAsm; ProSelectionAlloc(NULL, &itemAsm, &selAsm); ProFeature featPub; featPub.id = nPubFeatID; featPub.owner = pMdl; featPub.type = PRO_FEATURE; ProSelection selPubFeat; ProSelectionAlloc(NULL, &featPub, &selPubFeat); // 创建复制几何 ProModelitem itemCopyQuilt; CreateCopyGeom(pMdlPart, selAsm, selPubFeat, itemCopyQuilt); ProSelection selCopyQuilt; ProSelectionAlloc(NULL, &itemCopyQuilt, &selCopyQuilt); // 弹出提示:是否要对单个面设置厚度 if (MessageBox(NULL, L"是否要对单个面设置厚度", L"提示", MB_YESNO|MB_ICONQUESTION) == IDYES) { ProMdlDisplay(pMdlPart); int nWndIDPart; ProMdlWindowGet(pMdlPart, &nWndIDPart); ProWindowActivate(nWndIDPart); // 弹出对话框 if (g_pDlgThick != NULL) { if (g_pDlgThick->GetSafeHwnd() != NULL) g_pDlgThick->DestroyWindow(); SAFE_DELETE_POINTER(g_pDlgThick); } g_pDlgThick = new CDlgSetThick(); g_pDlgThick->InitSurfData(pMdl, selCopyQuilt, dThickValue); g_pDlgThick->Create(IDD_DLG_SETTHICK); g_pDlgThick->ShowWindow(SW_SHOW); } else { ThickQuilt(pMdlPart, selCopyQuilt, dThickValue); } } } InvalidateDrawing(); ProMessageClear(); }
ProError visit_component_action( ProFeature* in_feature, ProError in_status, Appdata in_app_data ) { ProError rs; ProMdl model; switch( rs = ProAsmcompMdlGet(in_feature, &model) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified feature is not a valid component feature."; return PRO_TK_GENERAL_ERROR; case PRO_TK_E_NOT_FOUND: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "Assembly component model is not a solid or is not in memory."; return PRO_TK_GENERAL_ERROR; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unexpected error: " << rs; return PRO_TK_GENERAL_ERROR; } ProSolid solid = static_cast<ProSolid>(model); ProMdlType component_type; switch( rs = ProMdlTypeGet(model, &component_type) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid."; return PRO_TK_GENERAL_ERROR; case PRO_TK_GENERAL_ERROR: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The information could not be obtained."; return PRO_TK_GENERAL_ERROR; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unexpected error: " << rs; return PRO_TK_GENERAL_ERROR; } ProAsmcomp component = static_cast<ProAsmcomp>(*in_feature); Appdata app_data; app_data.level = in_app_data.level+1; app_data.path.owner = static_cast<ProSolid>(component.owner); app_data.path.owner = in_app_data.path.owner; app_data.path.table_num = in_app_data.path.table_num + 1; for( int ix=0; ix < app_data.path.table_num; ++ix ) { app_data.path.comp_id_table[ix] = in_app_data.path.comp_id_table[ix]; } app_data.path.comp_id_table[app_data.path.table_num] = in_feature->id; switch( component_type ) { case PRO_ASSEMBLY: { ProAppData* app_data_vp = reinterpret_cast<ProAppData*>(&app_data); switch( rs = ProSolidFeatVisit(solid, visit_action, filter_action, app_data_vp) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_E_NOT_FOUND: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "filter produced no component features."; break; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "Any other value is the value returned " << " by the action function (visiting stopped)." << rs; } } break; case PRO_PART: { ProMdl self; switch( rs = ProModelitemMdlGet(in_feature, &self) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "feature has no model. " << in_feature->id; } char assembly_name[PRO_NAME_SIZE]; { ProName wname; switch( rs = ProMdlNameGet(self, wname) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid. " << in_feature->id; throw std::runtime_error("selector feature name failed"); case PRO_TK_E_NOT_FOUND: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified item does not have a name. "; break; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "ill specified error: " << rs; throw std::runtime_error("selector feature name failed"); } ProWstringToString(assembly_name, wname); } char model_name[PRO_PATH_SIZE]; { wchar_t* wname; ProBoolean is_modifiable; switch( rs = ProMdlCommonnameGet(self, &wname, &is_modifiable) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid. " << in_feature->id; throw std::runtime_error("selector feature name failed"); case PRO_TK_E_NOT_FOUND: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified item does not have a name. "; break; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "ill specified error: " << rs; throw std::runtime_error("selector feature name failed"); } ProWstringToString(model_name, wname); ProWstringFree(wname); } char item_name[PRO_NAME_SIZE]; { ProName wname; switch( rs = ProModelitemNameGet(in_feature, wname) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid. " << in_feature->id; throw std::runtime_error("selector feature name failed"); case PRO_TK_E_NOT_FOUND: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified item does not have a name. "; break; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "ill specified error: " << rs; throw std::runtime_error("selector feature name failed"); } ProWstringToString(item_name, wname); } // If you request the transformation from the member to the // assembly, this is PRO_B_TRUE. Otherwise, this is PRO_B_FALSE. ProBoolean bottom_up = PRO_B_TRUE; ProMatrix transformation; // retrieve the transformation matrix, given the component path. switch( rs = ProAsmcomppathTrfGet(&app_data.path, bottom_up, transformation) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "transform get, the input argument is invalid: " << app_data.path.comp_id_table; return PRO_TK_GENERAL_ERROR; case PRO_TK_GENERAL_ERROR: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified component path was wrong, or contained missing members."; return PRO_TK_GENERAL_ERROR; default: isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unexpected error: " << rs; return PRO_TK_GENERAL_ERROR; } isis_LOG(lg, isis_FILE, isis_INFO) << "transformation: " << assembly_name << " : " << model_name << " : " << item_name; isis_LOG(lg, isis_FILE, isis_INFO) << "["; for( int ix=0; ix < 4; ++ix ) { isis_LOG(lg, isis_FILE, isis_INFO) << "\n\t["; for( int jx=0; jx < 4; ++jx ) { isis_LOG(lg, isis_FILE, isis_INFO) << '\t' << transformation[ix][jx]; } isis_LOG(lg, isis_FILE, isis_INFO) << "]"; } isis_LOG(lg, isis_FILE, isis_INFO) << "]\n"; return PRO_TK_NO_ERROR; } default: { isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unknown-component-type: " << component_type; } } return PRO_TK_NO_ERROR; }
void DatumRefResolver::HandleDatumPlane(ProSelection datum, vector<ProSelection> & result) { ProAsmcomppath comppath; isis_ProSelectionAsmcomppathGet(datum, &comppath); ProModelitem mitem; isis_ProSelectionModelitemGet(datum, &mitem); ProFeature* feat; ProFeature f; if (mitem.type == PRO_FEATURE) { feat = &mitem; } else if (mitem.type == PRO_SURFACE || mitem.type == PRO_AXIS || mitem.type == PRO_EDGE || mitem.type == PRO_CSYS) { ProError err = isis_ProGeomitemFeatureGet ((ProGeomitem*)&mitem, &f); if (err != PRO_TK_NO_ERROR) { throw isis::application_exception("ProGeomitemFeatureGet error"); } feat = &f; } else { throw isis::application_exception("DatumRefResolver::Resolve(): Unsupported datum type, only AXIS, PLANE and CSYS are supported. Datum type is:" + std::to_string((long long)mitem.type)); } ProElement elemTree; isis_ProFeatureElemtreeExtract (feat, &comppath, PRO_FEAT_EXTRACT_NO_OPTS, &elemTree ); ProElempathItem constraints_path_items[] = { {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_DTMPLN_CONSTRAINTS}, }; /*wostringstream ostr; ostr << feat->id; ostr << L"elemtree.xml"; ProPath filepath; wcscpy(filepath, ostr.str().c_str()); isis_ProElemtreeWrite(elemTree, PRO_ELEMTREE_XML, filepath);*/ ProElempath contraints_elem_path; isis_ProElempathAlloc(&contraints_elem_path); isis_ProElempathDataSet(contraints_elem_path, constraints_path_items, sizeof(constraints_path_items)/sizeof(ProElempathItem)); int count; isis_ProElementArrayCount(elemTree, contraints_elem_path, &count); //isis::CreoMessageDialog(std::to_string((long long)count)); // Get constraint array ProElement* constraintarray; isis_ProArrayAlloc(count,sizeof(ProElement),1,(ProArray*) &constraintarray); isis_ProElementArrayGet(elemTree, contraints_elem_path, &constraintarray); // Iterate through constraints for (int i = 0; i < count; i++) { ProElempathItem set_path_items[] = { {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_DTMPLN_CONSTRAINTS}, {PRO_ELEM_PATH_ITEM_TYPE_INDEX, i}, {PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_DTMPLN_CONSTR_REF}, }; ProElement constraint; ProReference ref; int setid; ProElempath elem_path; ProElempathAlloc(&elem_path); isis_ProElempathDataSet(elem_path, set_path_items, sizeof(set_path_items)/sizeof(ProElempathItem)); isis_ProElemtreeElementGet(elemTree, elem_path, &constraint); ProError err = ProElementReferenceGet(constraint, 0, &ref); if (err == PRO_TK_EMPTY) { AddIfMissing(datum, result); continue; } else if (err != PRO_TK_NO_ERROR) { throw isis::application_exception("ProElemtreeElementGet error :" + std::to_string((long long)err)); } ProMdl refowner; err = ProReferenceOwnerGet(ref, &refowner); if (err != PRO_TK_NO_ERROR) { throw isis::application_exception("ProReferenceOwnerGet error"); } /*ProName name; err = ProMdlNameGet(refowner, name); if (err != PRO_TK_NO_ERROR) { throw isis::application_exception("ProMdlNameGet error"); }*/ ProMdlType mdltype; err = ProMdlTypeGet(refowner, &mdltype); if (err != PRO_TK_NO_ERROR) { throw isis::application_exception("ProMdlTypeGet error"); } ProSelection selection; ProReferenceToSelection(ref, &selection); if (mdltype==PRO_MDL_PART) { //isis::CreoMessageDialog(name); AddIfMissing(selection, result); } else { Resolve(selection, result); //throw isis::application_exception("Datum is not derived from a part"); } //result.push_back(refowner); //ProSelection } }
int CSDMdlAttrQuaCheck::CheckAction(void *pData, const CheckRule &checkRule, CheckResult &checkResult) { ProError status; ProMdl pMdl = (ProMdl)pData; if (NULL == pMdl) { checkResult.nResultType = CHECK_RESULT_INVALID_MODEL; return checkResult.nResultType; } if (!IsMdlTypeValid(pMdl, checkRule.dwMdlFilter)) { checkResult.nResultType = CHECK_RESULT_INVALID_MODEL; return checkResult.nResultType; } // 检查输入值有效性 if (checkRule.arrRuleContent.GetCount() < 3) { checkResult.nResultType = CHECK_RESULT_INVALID_INPUT; return checkResult.nResultType; } if (!IsNumber(checkRule.arrRuleContent.GetAt(1)) || !IsPoistive(checkRule.arrRuleContent.GetAt(2))) { checkResult.nResultType = CHECK_RESULT_INVALID_INPUT; return checkResult.nResultType; } if (_wtof(checkRule.arrRuleContent.GetAt(1)) < 0 || _wtof(checkRule.arrRuleContent.GetAt(1)) > _wtof(checkRule.arrRuleContent.GetAt(2))) { checkResult.nResultType = CHECK_RESULT_INVALID_INPUT; return checkResult.nResultType; } ProMdlType MdlType; status = ProMdlTypeGet(pMdl, &MdlType); if (MdlType == PRO_MDL_ASSEMBLY || MdlType == PRO_MDL_PART) { ProMassProperty MassPro; status = ProSolidMassPropertyGet((ProSolid)pMdl, NULL, &MassPro); ProUnitsystem sysUnit; status = ProMdlPrincipalunitsystemGet(pMdl, &sysUnit); ProUnititem unitMass; status = ProUnitsystemUnitGet(&sysUnit, PRO_UNITTYPE_MASS, &unitMass); CString strUnitMass = unitMass.name; double dQuaKiloValue = MassPro.mass; //模型质量 //模型质量转化为以KG为单位 if (strUnitMass.CompareNoCase(L"kg") == 0) { dQuaKiloValue; } else if (strUnitMass.CompareNoCase(L"g") == 0) { dQuaKiloValue = MassPro.mass/1000; } else if (strUnitMass.CompareNoCase(L"lbm") == 0) { dQuaKiloValue = MassPro.mass*0.4536; } if(MdlType == PRO_MDL_ASSEMBLY) { double dMaxValue = _wtof(checkRule.arrRuleContent.GetAt(2)); //规则值转化为以KG为单位 if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Kilogram") == 0) { dMaxValue; } else if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Gram") == 0) { dMaxValue = dMaxValue/1000; } else if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Pound") == 0) { dMaxValue = dMaxValue*0.4536; } else if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Newton") == 0) { dMaxValue = dMaxValue/9.8; } if (dQuaKiloValue > dMaxValue) { checkResult.nResultType = CHECK_RESULT_INVALID_VALUE; return CHECK_RESULT_INVALID_VALUE; } else { checkResult.nResultType = CHECK_RESULT_NO_ERROR; return CHECK_RESULT_NO_ERROR; } } else { double dMinValue = _wtof(checkRule.arrRuleContent.GetAt(1)); //规则值转化为以KG为单位 if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Kilogram") == 0) { dMinValue; } else if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Gram") == 0) { dMinValue = dMinValue/1000; } else if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Pound") == 0) { dMinValue = dMinValue*0.4536; } else if (checkRule.arrRuleContent.GetAt(0).CompareNoCase(L"Newton") == 0) { dMinValue = dMinValue/9.8; } if (dQuaKiloValue < dMinValue) { checkResult.nResultType = CHECK_RESULT_INVALID_VALUE; return CHECK_RESULT_INVALID_VALUE; } else { checkResult.nResultType = CHECK_RESULT_NO_ERROR; return CHECK_RESULT_NO_ERROR; } } } else { checkResult.nResultType = CHECK_RESULT_INVALID_INPUT; return CHECK_RESULT_INVALID_INPUT; } }