//检查开始 传出执行结果 int CSDMdlAttrUnitCheck::CheckAction(void *pData, const CheckRule &checkRule, CheckResult &checkResult) { //遍历模型 得到当前的单位制 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 (!IsFilterValid(checkRule.strRuleName, pMdl)) { checkResult.nResultType = CHECK_RESULT_INVALID_MODEL; return checkResult.nResultType; } // 检查输入值有效性 if (checkRule.arrRuleContent.GetCount() < 1) { checkResult.nResultType = CHECK_RESULT_INVALID_INPUT; return checkResult.nResultType; } ProUnitsystem sysUnit; if (ProMdlPrincipalunitsystemGet(pMdl, &sysUnit) == PRO_TK_NO_ERROR)//括号内判断是否得到了当前模型单位 { if (checkRule.arrRuleContent[0].CompareNoCase(sysUnit.name)==0)//字符串不能直接用等号进行比较 恒等于零表示符合规则描述 { checkResult.nResultType=CHECK_RESULT_NO_ERROR; return checkResult.nResultType; } else { checkResult.nResultType=CHECK_RESULT_ERROR_VALUE; return checkResult.nResultType; } } return CHECK_RESULT_ITEM_NOT_FOUND; }
// 处理过程 BOOL CSDMdlAttrUnitCheck::DoAction(void *pData, const CheckData &checkData) { ProMdl pMdl=(ProMdl)pData; ProUnitsystem sysUnit; ProMdlPrincipalunitsystemGet(pMdl, &sysUnit);//得到当前模型的单位 wcsncpy_s(sysUnit.name,PRO_NAME_SIZE,(LPCTSTR)checkData.checkRule.arrRuleContent[0],_TRUNCATE);//proname 本质是一个32位长的字符串 转换函数 ProUnitConvertType convertType = PRO_UNITCONVERT_SAME_SIZE; if (checkData.checkRule.arrRuleContent.GetSize() > 1) { int nConvertType = _wtoi(checkData.checkRule.arrRuleContent[1]); if (nConvertType == 0) convertType = PRO_UNITCONVERT_SAME_SIZE; else convertType = PRO_UNITCONVERT_SAME_DIMS; } if (ProMdlPrincipalunitsystemSet(pMdl, &sysUnit, convertType,PRO_B_TRUE, PRO_VALUE_UNUSED)==PRO_TK_NO_ERROR)//将获得的当前值设置 { return TRUE; } else return FALSE; }
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; } }
bool make_solid_templated( ProSolid& in_original, ProSolid& out_template ) { ProError rc; char pro_str[128]; log4cpp::Category& log_cf = log4cpp::Category::getInstance(LOGCAT_CONSOLEANDLOGFILE); ProUnitsystem original_system; switch( rc = ProMdlPrincipalunitsystemGet(in_original, &original_system) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: log_cf.errorStream() << "failed getting the principal unit-system."; break; default: log_cf.errorStream() << "could not aquire the unit system = " << rc; return false; } /* ProUnititem* original_mass_unit; switch( rc = ProMdlUnitsCollect( in_original, PRO_UNITTYPE_MASS, &original_mass_unit) ) { case PRO_TK_NO_ERROR: break; default: log_cf.errorStream() << "could not collect unit systems = " << rc; return false; } */ ProUnitsystem* template_systems; //ProUnititem template_units; switch( rc = ProMdlUnitsystemsCollect( out_template, &template_systems) ) { case PRO_TK_NO_ERROR: break; default: log_cf.errorStream() << "could not collect unit systems = " << rc; return false; } ProUnitsystem template_system; int size_template_systems; ProArraySizeGet( template_systems, &size_template_systems ); for( int ix=0; ix < size_template_systems; ++ix ) { int names_matched; ProWstringCompare(template_systems[ix].name, original_system.name, PRO_VALUE_UNUSED, &names_matched); if (names_matched != 0) continue; template_system = template_systems[ix]; break; } switch( rc = ProMdlPrincipalunitsystemSet(out_template, &template_system, PRO_UNITCONVERT_SAME_SIZE, PRO_B_TRUE, PRO_VALUE_UNUSED) ) { case PRO_TK_NO_ERROR: break; case PRO_TK_BAD_INPUTS: log_cf.errorStream() << "could not set the units in the shrinkwrap : " << ProWstringToString(pro_str, template_system.name); break; default: log_cf.errorStream() << "could not set units in shinkwrap = " << rc; return false; } return true; }