CATIA-V5-几何体的创建

//---------------------------------------------------------------------------------------
// 创建几何体
//---------------------------------------------------------------------------------------
HRESULT SJDPulicMethodClass::CreateOrFindPRTTool(
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!");
    }
    spiGSFeat = piMRFc->CreatePRTTool(istrGSMName,spPartOnRoot);
    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;
}
CATEndTry

    if (piPartCntOnRoot != NULL)
    {
        piPartCntOnRoot->Release();
        piPartCntOnRoot = NULL;
    }

    if (piMRFc != NULL)
    {
        piMRFc->Release();
        piMRFc = NULL;
    }

    return rc;

}

你可能感兴趣的:(CATIA-V5-几何体的创建)