干涉检查接口Framework及头文件:
// SpaceAnalysisInterfaces Framework
#include "CATIClash.h"
#include "CATIClashFactory.h"
#include "CATIClashResult.h"
#include "CATIConflict.h"
mk文件中追加:CATSaiSpaceAnalysisItf
/************************************************************************/
/* 干涉检查 */
/************************************************************************/
// SavePart零件包含干涉检查实体,使用AgainstAll模式与其他零件执行干涉检查
_listBUnkOnClashPart.RemoveAll();
_listBUnkOnClashPart.Append(_spProductOnSave);
// 通过CATDocument指针,获取CATIClashFactory
CATIClashFactory* pClashFactory = NULL;
hr = pDocumentOnAssy->QueryInterface(IID_CATIClashFactory,(void**)&pClashFactory);
if (pClashFactory != NULL)
{
// 创建干涉检查特征
CATIClash* pClashOnWeldAround;
pClashFactory->Create(pClashOnWeldAround);
// 指定干涉检查的场景:干涉、接触或间隙等
pClashOnWeldAround->SetComputationCase(CATComputationCaseClashContact);
// 指定干涉检查的模式:指定零件与其他所有零件检查干涉情况
pClashOnWeldAround->SetGroupMode(CATGroupModeAgainstAll);
// 指定干涉检查的零件分组1
pClashOnWeldAround->SetGroup(1, _listBUnkOnClashPart);
// 指定干涉检查的零件分组2(干涉模式为CATGroupModeBetweenTwo,使用零件分组2)
//pClashOnWeldAround->SetGroup(2, _listBUnkOnAllPart);
// 指定干涉检查的零件分组
//pClashOnWeldAround->SetClearance(1.0);
// 执行干涉检查
pClashOnWeldAround->Compute();
// 获取干涉检查结果的指针
CATIClashResult* pClashResult = NULL;
hr = pClashOnWeldAround->GetResult(pClashResult);
// 获取干涉检查结果
int nbConflict = 0;
pClashResult->CountConflicts(nbConflict);
for (int nIdxConflict = 0; nIdxConflict < nbConflict; nIdxConflict++)
{
// 获取干涉冲突
CATIConflict* pConflict = NULL;
pClashResult->GetConflict(nIdxConflict, pConflict);
// 获取干涉冲突的类型
CATResultType resultType = CATTypeClash;
pConflict->GetResultType(resultType);
if (resultType != CATTypeClash)
{
pConflict->Release();
pConflict = NULL;
continue;
}
// 获取干涉冲突的干涉值
double dClashValue = 0.0;
pConflict->GetValue(dClashValue);
if (dClashValue < 0.0)
{
cout << "Clash Value : " << dClashValue << endl;
// 获取干涉冲突的干涉点
double* pPointCOG = NULL;
double* pSecondPoint = NULL;
hr = pConflict->GetMinOrExtractionVectorCoordinates(pPointCOG, pSecondPoint);
// 获取干涉冲突的两个零件
CATIProduct* spiProduct1 = NULL;
CATUnicodeString ustrShapeName1;
hr = pConflict->GetFirstProduct(spiProduct1, ustrShapeName1);
CATIProduct* spiProduct2 = NULL;
CATUnicodeString ustrShapeName2;
hr = pConflict->GetSecondProduct(spiProduct2, ustrShapeName2);
}
pConflict->Release();
pConflict = NULL;
}
pClashResult->Release();
pClashResult = NULL;
pClashOnWeldAround->Release();
pClashOnWeldAround = NULL;
}
pClashFactory->Release();
pClashFactory = NULL;
完成干涉检查之后,获取两个要素之间的干涉点:
int iNumberOfConflicts = 0;
hr = spiClashResult->CountConflicts (iNumberOfConflicts);
if (FAILED(hr))
{
return FALSE;
}
double dMaxCalshValue = 0.0;
if (iNumberOfConflicts != 0)
{
double dClashValue = 0.0;
double* dFirstPoint = new double[3];
double* dSecondPoint = new double[3];
for (int iLoop = 0; iLoop < iNumberOfConflicts;iLoop++)
{
CATIConflict* pConflict = NULL;
hr = spiClashResult->GetConflict (iLoop, pConflict);
if (!(FAILED(hr) || NULL == pConflict))
{
dClashValue = 0.0;
// 计算干涉值
pConflict->GetValue (dClashValue);
// 获取干涉点
pConflict->GetMinOrExtractionVectorCoordinates ( dFirstPoint, dSecondPoint);
if (fabs(dClashValue) > dMaxCalshValue)
{
dMaxCalshValue = dClashValue;
mathWrkPoint1 = CATMathPoint(dFirstPoint[0],dFirstPoint[1],dFirstPoint[2]);
mathWrkPoint2 = CATMathPoint(dSecondPoint[0],dSecondPoint[1],dSecondPoint[2]);
}
}
pConflict->Release();
pConflict = NULL;
}
if (dFirstPoint != NULL){delete[] dFirstPoint; dFirstPoint = NULL;}
if (dSecondPoint != NULL){delete[] dSecondPoint; dSecondPoint = NULL;}
}
当干涉发生在两个装配要素之间,计算出的干涉点的坐标是以各个装配要素的坐标系为主坐标系。
网友评论