CATIA技术交流论坛

 找回密码
 点击注册
查看: 551|回复: 0

CATIA CAA 二次开发详细教程 第十讲:文档操作方法、创建、加载、保存

[复制链接]

1684

主题

1726

帖子

4266

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4266
发表于 2018-1-26 14:24:55 | 显示全部楼层 |阅读模式
一、创建(Create the new document)
    CATDocument* pDoc = NULL;
    rc = CATDocumentServices::New("Part",pDoc); if (NULL != pDoc) {
    cout << "New document created OK" << endl << flush; } else {
    cout << "ERROR in creating New document" << endl << flush;
    return 2; }
    Now that the session is opened, you can create a new document using the New static method of CATDocumentServices. This method creates a document and initializes it, allowing it to be loaded and stored and making it editable. In this use case, a pre-defined document type, "Part", is used as a document type. In interactive mode, this is the name that appears when performing a File/New operation. It is not the file extension, which, in this case, is "CATPart".

二、打开(Load the document)
    CATDocument *pDoc = NULL;
    rc = CATDocumentServices::Open(argv[1],
    pDoc); if (SUCCEEDED(rc) && (NULL != pDoc)) {  
    cout << "Document opened OK" << endl << flush; } else {
    cout << "ERROR in opening an existing document" << endl << flush;
    return 2; }
    Now that the session is opened, you can load an existing document using the Open static method of CATDocumentServices. This method needs, as a first parameter, the entire storage path name and document name of the existing document that we want to load into the session. In this use case, we enter this information as an argument to the program. The second parameter of the Open method returns a CATDocument pointer to the document it has loaded.Once the document exists in the session, you can work with objects within it, using specific interfaces external to the ObjectModelerBase framework.

三、获取当前文档
CATFrmEditor * pEditor   = GetEditor(); if (NULL != pEditor )
{
   cout << "Editor got OK" << endl << flush; } else {
   cout << "ERROR in getting the current editor" << endl << flush;    return 1; }
CATDocument *pDoc = pEditor->GetDocument(); if (NULL != pDoc) {
   cout << "Document opened OK" << endl << flush; } else {
   cout << "ERROR in opening an existing document" << endl << flush;    return 2; }

四、提取根容器(Retrieving the Document Root Container)
    CATInit *piInitOnDoc = NULL;
    rc = pDoc -> QueryInterface (IID_CATInit, (void**) &piInitOnDoc);
    if (FAILED(rc)) { cout << "ERROR in QueryInterface on CATInit for doc" << endl << flush;    return 3; }   
    const CATIdent idCATIContainer = "CATIContainer";
    CATIContainer *piRootContainer = NULL;
    piRootContainer = (CATIContainer*) piInitOnDoc -> GetRootContainer(idCATIContainer);
    if (NULL == piRootContainer) { cout << "ERROR in GetRootContainer" << endl << flush;    return 4; }
    The document root container is retrieved using the CATInit::GetRootContainer method. The CATIContainer handle retrieved through GetRootContainer will be necessary whenever you want to create or manipulate objects in the document.

五、保存文档(Save the Document)
5.1 另存
rc = CATDocumentServices::SaveAs (*pDoc, argv[1]);
    if (SUCCEEDED(rc)) {
    cout << "Document saved OK" << endl << flush; } else {
    cout << "ERROR in saving document" << endl << flush;
    return 5; }
    To save the new document, use the SaveAs static method of CATDocumentServices. This method takes the pointer to the document created by New as a first parameter, and the storage path name and document name under which the document is to be stored as a second parameter. In this use case, we pass the storage path name and document name as an argument to the program.

5.2 保存
    rc = CATDocumentServices::Save (*pDoc); if (SUCCEEDED(rc)) {
       cout << "Document saved OK" << endl << flush; } else {
       cout << "ERROR in saving document" << endl << flush;
       return 3; }
    To save the new document under the same name, use the Save static method of CATDocumentServices. This method takes the CATDocument pointer to the document as the only parameter.

六、删除(Remove the document)
    rc = CATDocumentServices::Remove (*pDoc); if (SUCCEEDED(rc)) {
        cout << "Document removed OK" << endl << flush; } else {
        cout << "ERROR in removing document" << endl << flush;
        return 6; }
    If you ever needed to re-open the document during this same session, it would then be necessary to also remove it from the session after having saved it. Otherwise, you need not worry about it since deleting the session will automatically remove the document as well. To remove the document, you should use the Remove static method of CATDocumentServices.

七、按指定文档格式保存(Exporting a Document Format Type)
7.1 Defining the New Document Format Type
    CATProduct_OmbExportType  CATIExportTypeManagerlibCAAOmbExportType
    A new document format type is simply defined by adding a new entry in the current framework's dictionary. This new entry will cause the File/SaveAs dialog box to list the new format type among the types defined to the save operation. The first parameter, CATProduct_OmbExportType, indicates that the exporting document is a Product-type document (i.e., a document having a .CATProduct suffix) and that the exported document format type is "OmbExportType", which will also be the suffix of the saved document. The second parameter indicates that this new document type will implement the CATIExportTypeManager interface in order to define the specific save operations necessary to export the new document. The last parameter is the name of the library in which the implementation module is to be found.
7.2 Implementing CATIExportTypeManager  
    See the Object Modeler articles [2] for a detailed explanation about interface implementations.
    The implementation of CATIExportTypeManager is found in the CAAOmbExportType.m module defining the CAAEOmbExportTypeData implementation class.
    CATImplementClass( CAAEOmbEExportTypeData, CodeExtension,CATBaseUnknown,CATProduct_OmbExportType );
    The CATImplementClass macro defines the implementation class CAAEOmbExportTypeData as a code extension implementing the CATProduct_OmbExportType late type.
    #include "TIE_CATIExportTypeManager.h"
    TIE_CATIExportTypeManager( CAAEOmbExportTypeData );
    The above statement indicates that this is an implementation of the CATIExport
    TypeManager interface.
        HRESULT CAAEOmbExportTypeData::ExportData ( CATDocument *pDoc, CATUnicodeString path ) {
        cout << "************** Begin ExportData 1" << endl << flush;
        HRESULT rc = CATDocumentServices::SaveAs (*pDoc,path);   
        return rc; }
    In this case, the document is simply saved using the SaveAs method of CATDocumentServices. However, it is in this method that you must code any specific save operations necessary for your new document type.

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点击注册

本版积分规则

手机|小黑屋|CATIA技术交流论坛

GMT+8, 2019-12-7 03:15 , Processed in 0.032687 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表