// ------------------------------------------------
/** CreateOrFindGSMTool
@brief [创建GSM TOOL]
@param[in] ipiCont Container
@param[in] istrGSMName GSM Name
@param[out] ospiGSMCL 输出的GSM Feature
@param[in] inCreateSpeed 快速度更新标志
@retval HRESULT:
S_OK 成功
Other 失败@note
-
@attention [注意事项说明]
/
// -----------------------------------------------
HRESULT SJDPulicMethodClass::CreateOrFindGSMTool(
CATIContainer ipiCont,
CATUnicodeString& istrGSMName,
CATISpecObject_var& ospiGSMCL,
int inCreateSpeed)
{
HRESULT rc = S_OK;CATIPrtContainer * piPartCntOnRoot = NULL;
CATIMechanicalRootFactory* piMRFc = NULL;
CATISpecObject_var spiGSFeat = NULL_var; // 暂存的图形集CATTry
{
// 获取Part Container
rc = ipiCont->QueryInterface(IID_CATIPrtContainer,(void**)&piPartCntOnRoot);
if (!SUCCEEDED(rc) || piPartCntOnRoot == NULL)
{
THROWAERROR("Error!");
}// 获取顶级Part CATISpecObject_var spPartOnRoot = piPartCntOnRoot->GetPart(); if (spPartOnRoot == NULL_var) { THROWAERROR("Error!"); } CATIPartRequest_var spiReqOnPart = spPartOnRoot; if (spiReqOnPart == NULL_var) { THROWAERROR("Error!"); } CATUnicodeString uAliasName = ""; CATUnicodeString uSubString = ""; int iFindPos = 0; int iNum = 0; int iTempNum = 0; if (inCreateSpeed == 0) // 不查找操作 { // 遍历所有集合集 CATListValCATBaseUnknown_var listOfUnGS; rc = spiReqOnPart->GetAllBodies("MfDefault3DView",listOfUnGS); if (!SUCCEEDED(rc)) { THROWAERROR("Error!"); } for (int i = 1; i <= listOfUnGS.Size();i++) { CATIAlias_var spiAs = listOfUnGS[i]; if (spiAs == NULL_var) { continue; } uAliasName = spiAs->GetAlias(); iFindPos = uAliasName.SearchSubString(istrGSMName); if (iFindPos != -1) { iTempNum = uAliasName.GetLengthInChar() - istrGSMName.GetLengthInChar(); uSubString=uAliasName.SubString(iFindPos + istrGSMName.GetLengthInChar(),iTempNum); // 将尾数转化为数字 uSubString.ConvertToNum(&iTempNum); if (iTempNum > iNum) { iNum = iTempNum; } } } } // 如果没找到 CATUnicodeString uStrTemp = ""; if (spiGSFeat == NULL_var || inCreateSpeed == 1) { iNum = iNum + 1; uStrTemp.BuildFromNum(iNum); istrGSMName = istrGSMName + uStrTemp; } // 创建几何集 rc = ipiCont->QueryInterface(IID_CATIMechanicalRootFactory,(void**)&piMRFc); if (!SUCCEEDED(rc) || piMRFc == NULL) { THROWAERROR("Error!"); } rc = piMRFc->CreateGeometricalSet(istrGSMName,spPartOnRoot,spiGSFeat); if (!SUCCEEDED(rc) || spiGSFeat == NULL_var) { THROWAERROR("Error!"); } ospiGSMCL = spiGSFeat; rc = S_OK;
}
CATCatch(CATMfErrUpdate , pUpdateError){
rc = E_INVALIDARG;
}
CATCatch(CATError , pError){
rc = E_INVALIDARG;
}
CATEndTryif (piPartCntOnRoot != NULL)
{
piPartCntOnRoot->Release();
piPartCntOnRoot = NULL;
}if (piMRFc != NULL)
{
piMRFc->Release();
piMRFc = NULL;
}return rc;
}