简介:使用CATIA CAA进行碰撞检测没有官方的文档,相关的接口也无法从DOC文件中找到使用方法,以下是通过尝试和整理总结的在CATIA CAA中进行碰撞检测的方法,包含了需要额外引入的框架和模块。
一、使用 COM(V5Automation)接口进行碰撞检测
方法概述
通过 COM 接口访问 CATIA 的碰撞检测功能,主要通过获取 CATIAClashes 接口来创建碰撞检测对象,设置检测参数并执行计算。Automation相关的模块一般以CATIA前缀,区分于CAA的CATI前缀。
代码精简示例
cpp
#include <iostream>
#include <CATDocumentServices.h>
#include <CATIDocRoots.h>
#include <CATIProduct.h>
#include <CATIAlias.h>
#include <CATIAClashes.h>
#include <CATIAClash.h>
#include <CATIClashResult.h>
#include <CATIConflict.h>
void ClashDetectionWithCOM() {
HRESULT hr = E_FAIL;
CATDocument *pDoc = NULL;
// 打开CATIA文档
hr = CATDocumentServices::OpenDocument("文件路径", pDoc);
if (FAILED(hr) || !pDoc) {
std::cout << "打开文档失败" << std::endl;
return;
}
// 获取文档根对象
CATIDocRoots *piDocRootsOnDoc = NULL;
hr = pDoc->QueryInterface(IID_CATIDocRoots, (void **)&piDocRootsOnDoc);
pDoc->Release();
pDoc = NULL;
if (FAILED(hr) || !piDocRootsOnDoc) {
std::cout << "获取文档根对象失败" << std::endl;
return;
}
CATListValCATBaseUnknown_var *pRootProducts = piDocRootsOnDoc->GiveDocRoots();
piDocRootsOnDoc->Release();
// 获取根产品
CATIProduct_var spRootProduct = (*pRootProducts)[1];
delete pRootProducts;
// 获取碰撞检测接口
CATIAProduct_var spRootPrd = NULL_var;
hr = spRootProduct->QueryInterface(IID_CATIAProduct, (void **)&spRootPrd);
CATBSTR clashesBSTR;
CATUnicodeString clashesName = "Clashes";
clashesName.ConvertToBSTR(&clashesBSTR);
CATBaseDispatch* pBaseDispatch = NULL;
// 获取CATBaseDispatch对象用于转换为CATIAClashes对象
hr = spRootPrd->GetTechnologicalObject(clashesBSTR, pBaseDispatch);
CATFreeString(clashesBSTR);
CATIAClashes* pCATIAClashes = NULL;
hr = pBaseDispatch->QueryInterface(IID_CATIAClashes, (void **)&pCATIAClashes);
pBaseDispatch->Release();
// 创建碰撞检测对象
CATIAClash* pCATIAClash = NULL;
hr = pCATIAClashes->Add(pCATIAClash);
pCATIAClashes->Release();
// 设置碰撞检测参数并执行计算,将CATIAClash转换为CATIClash
CATIClash* pClash = NULL;
hr = pCATIAClash->QueryInterface(IID_CATIClash, (void **)&pClash);
pCATIAClash->Release();
// 初始化两个检测对象列表,存入CATIProduct对象
CATListValCATBaseUnknown_var list1;
CATListValCATBaseUnknown_var list2;
if(SUCCEEDED(hr) && pClash) {
pClash->SetGroupMode(CATGroupModeBetweenTwo);
// 设置分组...
pClash->SetGroup(1, list1);
pClash->SetGroup(2, list2);
pClash->SetComputationCase(CATComputationCaseClashContact);
pClash->Compute();
// 处理碰撞结果
CATIClashResult* pClashResult = NULL;
hr = pClash->GetResult(pClashResult);
pClash->Release();
if (SUCCEEDED(hr) && pClashResult) {
int count = 0;
pClashResult->CountConflicts(count);
// 遍历碰撞结果...
pClashResult->Release();
}
}
}
需要引入的头文件
-
CATDocumentServices.h:提供文档操作服务 -
CATIDocRoots.h:用于获取文档根对象 -
CATIProduct.h:产品接口定义 -
CATIAlias.h:产品别名接口 -
CATIAClashes.h:碰撞检测集合接口 -
CATIAClash.h:单个碰撞检测接口 -
CATIClashResult.h:碰撞检测结果接口 -
CATIConflict.h:单个碰撞冲突接口
需要额外添加的 Framework 和模块
Framework:
SpaceAnalysisInterfaces:碰撞检测分析相关接口框架ProductStructureInterfaces: 产品结构相关接口框架
模块:
-
CATSaiSpaceAnalysisItf:碰撞检测分析模块 -
ProductStructurePubIDL:产品结构相关自动化接口模块 -
SpaceAnalysisItf:碰撞检测分析自动化接口模块
二、使用 CAA 的 CATIClashFactory 进行碰撞检测
方法概述
通过 CAA(Component Application Architecture)框架的 CATIClashFactory 接口创建碰撞检测对象,这种方法更直接地利用 CAA 组件架构,通常用于开发 CATIA 插件或扩展功能。
代码精简示例
cpp
#include <iostream>
#include <CATDocumentServices.h>
#include <CATIDocRoots.h>
#include <CATIProduct.h>
#include <CATIAlias.h>
#include <CATIClashFactory.h>
#include <CATIClash.h>
#include <CATIClashResult.h>
#include <CATIConflict.h>
void ClashDetectionWithCAAFactory() {
HRESULT hr = E_FAIL;
CATDocument *pDoc = NULL;
// 打开CATIA文档
hr = CATDocumentServices::OpenDocument("文件路径", pDoc);
if (FAILED(hr) || !pDoc) {
std::cout << "打开文档失败" << std::endl;
return;
}
// 获取CATIClashFactory接口
CATIClashFactory* pClashFactory = NULL;
hr = pDoc->QueryInterface(IID_CATIClashFactory, (void**)&pClashFactory);
pDoc->Release();
if (FAILED(hr) || !pClashFactory) {
std::cout << "获取碰撞工厂失败" << std::endl;
return;
}
// 获取文档根对象和根产品
CATIDocRoots *piDocRootsOnDoc = NULL;
hr = pDoc->QueryInterface(IID_CATIDocRoots, (void **)&piDocRootsOnDoc);
pDoc->Release();
CATListValCATBaseUnknown_var *pRootProducts = piDocRootsOnDoc->GiveDocRoots();
piDocRootsOnDoc->Release();
CATIProduct_var spRootProduct = (*pRootProducts)[1];
delete pRootProducts;
// 初始化两个检测对象列表,存入CATIProduct对象
CATListValCATBaseUnknown_var list1;
CATListValCATBaseUnknown_var list2;
// 使用CATIClashFactory创建碰撞检测对象
CATIClash* pClash = NULL;
pClashFactory->Create(pClash);
pClashFactory->Release();
// 设置碰撞检测参数并执行计算
if (pClash) {
pClash->SetComputationCase(CATComputationCaseClashContact);
pClash->SetGroupMode(CATGroupModeBetweenTwo);
// 设置分组...
pClash->SetGroup(1, list1);
pClash->SetGroup(2, list2);
pClash->Compute();
// 处理碰撞结果
CATIClashResult* pClashResult = NULL;
hr = pClash->GetResult(pClashResult);
pClash->Release();
if (SUCCEEDED(hr) && pClashResult) {
int count = 0;
pClashResult->CountConflicts(count);
// 遍历碰撞结果...
pClashResult->Release();
}
}
}
需要引入的头文件
-
CATDocumentServices.h:提供文档操作服务 -
CATIDocRoots.h:用于获取文档根对象 -
CATIProduct.h:产品接口定义 -
CATIAlias.h:产品别名接口 -
CATIClashFactory.h:CAA 碰撞工厂接口 -
CATIClash.h:碰撞检测接口 -
CATIClashResult.h:碰撞检测结果接口 -
CATIConflict.h:单个碰撞冲突接口
需要额外添加的 Framework 和模块
Framework:
-
SpaceAnalysisInterfaces:碰撞检测分析相关接口框架
模块:
-
CATSaiSpaceAnalysisItf:碰撞检测分析模块