2014-08-05 14:13:38|?次阅读|上传:huigezrx【已有?条评论】发表评论
关键词:C/C++, CAA, CATIA|来源:唯设编程网
CAA制图模型概述(Drafting Modeler Overview)介绍了CAA开发关于工程制图的一些基本概念,本文是一个CAA创建工程图的实例,该实例介绍如何在工程图文件中创建图纸(sheets)和交互视图(interactive views)。程序首先创建一个构成工程图的基本制图结构,一张图(sheet)和两个视图(这些视图没有在图中显示)。然后在第二张图中创建额外的视图。最终实现的效果如下:

int main(int iArgc, // Number of arguments (1)
char** iArgv) // Path to the new *.CATDrawing document
{
// Checks arguments
if(2 != iArgc) return 1;
const char *fileName = iArgv[1];
// 1.Creating and Initializing the Document
// ===============================
// Creates a session
CATSession *pSampleSession = NULL;
HRESULT hr = ::CATIDftDocumentServices("SampleSession",pSampleSession);
if (FAILED(hr)) return 1;
CATDocument* pDoc = NULL;
hr = CATDocumentServices::New("CATDrawing", pDoc);
if (FAILED(hr) || !pDoc)
{
::Delete_Session("SampleSession");
return 2;
}
这部分展示了通常创建一个CATIA文档的步骤。注意其中使用的是CATIDftDocumentServices全局函数,CATIDftDocumentServices同样也是一个接口,该接口的GetDrawing函数提供工程图(drawing)的操作入口。
// Gets the drawing feature and drawing container
CATIDftDrawing *piDftDrawing = NULL;
CATIDftDocumentServices *piDftDocServices = NULL;
CATIContainer_var spDrwCont;
if (SUCCEEDED(pDoc->QueryInterface(IID_CATIDftDocumentServices, (void **)&piDftDocServices)))
{
if (SUCCEEDED(piDftDocServices->GetDrawing(IID_CATIDftDrawing, (void **)&piDftDrawing)))
{
if (piDftDrawing)
{
// Gets the drawing container
CATISpecObject *piSpecObj=NULL;
if (SUCCEEDED(piDftDrawing->QueryInterface(IID_CATISpecObject,(void **)&piSpecObj)))
{
spDrwCont = piSpecObj->GetFeatContainer();
piSpecObj->Release();
piSpecObj=NULL;
}
}
}
piDftDocServices->Release();
piDftDocServices=NULL;
}
工程图文档的根节点特征(root feature)是Drawing,这个特征实现了CATIDrawing接口。我们可以使用CATIDftDocumentServices接口获取指向CATIDrawing的指针,CADIDftDocumentServices接口由文档(document)实现。GetDrawing方法的第一个参数是你想要从工程图(drawing)上面获取的接口ID。
// Gets standard manager from the drawing container.
CATIDftStandardManager *piStdmgr = NULL;
if (SUCCEEDED(spDrwCont->QueryInterface(IID_CATIDftStandardManager,(void**)&piStdmgr)))
{
// Finds a standard in the list of allowed standards (ie. the list
//of xml files in the resources/standard/drafting directory)
CATIStringList *piListstd = NULL;
if ( SUCCEEDED(piStdmgr->GetAvailableStandards(&piListstd)) && piListstd )
{
unsigned int nbrstd = 0;
piListstd->Count(&nbrstd);
for (unsigned int indice = 0; indice < nbrstd; indice ++)
{
wchar_t *wstd = NULL;
if ( SUCCEEDED ( piListstd->Item ( indice, &wstd ) ) && wstd )
{
const CATUnicodeString ANSI_UncS = "ANSI";
CATUnicodeString stdname;
stdname.BuildFromWChar(wstd);
if ( stdname == ANSI_UncS )
{
// Import the ANSI standard in the document
piStdmgr->ImportStandard (wstd);
break;
}
}
if (wstd) {delete[] wstd; wstd = NULL;}
}
piListstd->Release(); piListstd=NULL;
}
piStdmgr->Release (); piStdmgr=NULL;
}
CATIDftStandardManager接口由工程图应用程序适当的容器实现。GetAvailableStandards方法返回可用的标准列表。ImportStandard方法允许在工程图文档应用一个标准。