謝謝你的回覆
我嘗試依照你的步驟來做, 但是當呼叫 CATCreateDistanceMinTopo() 時, 有exception throw出來.
以下是我寫的code
pPathElm1->InitToLeafElement();
CATBaseUnknown* pSelEntity1 = pPathElm1->NextFatherElement();
pPathElm2->InitToLeafElement();
CATBaseUnknown* pSelEntity2 = pPathElm2->NextFatherElement();
// Create the CATBody containing the selected face/point
CATIBRepAccess *pBRep1 = NULL, *pBRep2 = NULL;
hr = pSelEntity1->QueryInterface(IID_CATIBRepAccess, (void**)&pBRep1);
hr = pSelEntity2->QueryInterface(IID_CATIBRepAccess, (void**)&pBRep2);
CATBody_var spBody1 = pBRep1->CreateBody(); // Get the CATBody
CATBody_var spBody2 = pBRep2->CreateBody(); // Get the CATBody
// Get the CATGeoFactory of selected entity 1
CATILinkableObject* pLinkableObj;
CATDocument* pDoc = NULL;
hr = pSelEntity1->QueryInterface(IID_CATILinkableObject, (void**)&pLinkableObj);
CATDocument* pDoc = pLinkableObj->GetDocument();
CATIContainerOfDocument* pContainerOfDoc = NULL;
hr = pDoc->QueryInterface(IID_CATIContainerOfDocument, (void**)&pContainerOfDoc);
CATIContainer* pResultContainer = NULL;
pContainerOfDoc->GetResultContainer(pResultContainer);
CATGeoFactory* pGeoFact = NULL;
hr = pResultContainer->QueryInterface(IID_CATGeoFactory, (void**)&pGeoFact);
// Clone and get the compatible CATGeoFactory
CATCloneManager cloneMgr(pGeoFact, CatCGMFullDuplicate); // Full Duplication
cloneMgr.Add(spBody1); // Add the selected body 1
cloneMgr.Run();
CATICGMObject* pClonedObj = cloneMgr.ReadImage(spBody1);
CATGeoFactory* pCompatibleGeoFact = pClonedObj->GetContainer();
CATSoftwareConfiguration *pSoftConfig = new CATSoftwareConfiguration();
CATTopData topData(pSoftConfig, NULL);
CATTry
{
// Measure distance between two selected entities
CATDistanceMinBodyBody* pMinDist = CATCreateDistanceMinTopo(pCompatibleGeoFact, &topData, spBody1, spBody2, BASIC);
minDistance = pMinDist->GetDistance();
delete pMinDist; pMinDist = NULL;
}
CATCatch(CATError, pError)
{
CATUnicodeString e1 = pError->GetNLSDiagnostic();
CATUnicodeString e2 = pError->GetNLSMessage();
const char* c1 = e1.ConvertToChar();
const char* c2 = e2.ConvertToChar();
}
CATEndTry
在 GetNLSMessage() 中, 它說geometry container incompatible. 我不知道是什麼, 請問有什麼方法解決呢?
謝謝 |