Catia的二次开发(2)

2018-11-19 20:33

{ cout << \

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 << \OK\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 << \removed OK\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 CATIExportTypeManager libCAAOmbExportType

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 \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 #include

\

TIE_CATIExportTypeManager( CAAEOmbExportTypeData ); The above statement indicates that this is an implementation of the

CATIExportTypeManager interface.

HRESULT

CAAEOmbExportTypeData::ExportData

(

CATDocument

*pDoc,

CATUnicodeString path ) { cout << \HRESULT rc = CATDocumentServices::SaveAs (*pDoc, path); } return rc;

as

a

code

extension

implementing

the

CATProduct_OmbExportType late type.

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 界面二次开发方法

下面的例子说明了如何使用 CAA C++开发方式来建立一个 CATIA 内部程序。实现的功能是新建一个 独立的工作台(workbench),并在其下面实现添加自定义菜单,添加工具条以及按钮图标,插入 CATIA 风 格的对话框。并生成对界面功能的响应,建立 command,实现调用对话框,以及通过输入参数直接用代码 生成一个三维模型,并在 CATIA 主窗口中显示。

1、 新建独立的 workbench

CATIA V5 将某类包含一系列交互命令的一些工具条分组显示在不同的工作台(workbench)中, 这样有 利于工具的查找和使用。通过自己新建的 workbench 可以将自己二次开发形成的一系列命令集中显示在一 个工作台中,便于以后的操作。工作台的建立需要以下几个步骤。

创建工作台厂(factory)的接口(interface);

创建工作台厂;

创建工作台描述类;

创建响应命令(command)的标题;

创建工作台并排列图标按钮响应;

提供图片及提示等资源并将新建的工作台插入开始菜单;

创建工作台的显示界面。

插入新建的工作台 MyWorkBench 后的 CATIA 开始菜单如图 3 所示,它与 CATIA 现

有的模块成为并 列关系。现在进入 MyWorkBench 工作台里面没有任何工具条及按钮,下面添加这部分工具。

生成的新的工作台

2、 添加工具条及按钮

首先创建按钮的描述类 CAAAfrGeoCreationWkb,派生于 CATBaseUnknown 类。CATBaseUnknow n 是创建用户界面并实现界面的基类,所有的接口都是从 IUnknown/CATBaseUnknown 继承的。这个类中 建立了两个函数分别为 CATCmdWorkbench *的 CreateWorkbench()函数和无返回值类型的 CreateComm ands()。前面的函数是用来实现顺序插入工具条、按钮图标以及菜单,后面的函数是实现对插入按钮以及 菜单和响应函数的关联。

在 CreateWorkbench()函数中用到了宏 NewAccess(className,variableName,objectName)。CATIA 的工作场(workshop)或者工作台(workbench)可以被看作是一个入口的集合包,使用

NewAccess

宏可以创

建一个这样的入口。

使用

SetAccessChild(variableName,childName)以及 SetAccessNext (variableName, nextName)这两个宏则可以连接入口。其中 className 表示被创建类的类型,包括以下几种类型:CATC mdContainer,CATCmdWorkshop,CATCmdSeparator,CATCmdStarter。下面就是创建了一个按钮的 容器,也就是工具条,并在其中添加按钮的部分代码。

NewAccess(CATCmdContainer,pCAAAfrTB1EltTlb,CAAAfrTB1EltTlb);//创建工具条 pCAAAfrTB1Elt Tlb

SetAccessChild(pCAAAfrGeoCreationWkb, pCAAAfrTB1EltTlb); //工具条加入工作台

//创建按钮 cmd1,并设置其响应宏为 CAAAfrCmd1Hdr,最后将其加入工具条 TB1 中

NewAccess(CATCmdStarter,pCAAAfrTTB1EltCmd1Str,CAAAfrTTB1EltCmd1Str);

SetAccessCommand(pCAAAfrTTB1EltCmd1Str,\

SetAccessChild(pCAAAfrTB1EltTlb,pCAAAfrTTB1EltCmd1Str);

接下来绘制一个图标,并在 CAAAfrGeoCreationWkbHeader.CATRsc 中将其关联,具体如下,则 cm d1 按钮显示的是 CAACmd1.Bmp 图标。

CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.Icon.Normal = \

在 CAAAfrGeoCreationWkbHeader.CATNls 文件中设置新建按钮的标题以及提示内容

CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.Category = \

CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.Title = \

CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.ShortHelp = \

添加两个工具条并插入一系列按钮的效果图如下面图 4 所示。

图 4 、5 新添加的按钮

添加的菜单

3、添加菜单

菜单的添加与添加按钮类似,也是在 CreateWorkbench()函数中,只不过是在宏中的参数与添加按钮 并不一样。添加后的效果图如图 5 所示

NewAccess(CATCmdContainer, pCAAAfrGeoCreationMbr, CAAAfrGeoCreationMbr);

NewAccess(CATCmdContainer, pCATAfrInsertMnu, CATAfrInsertMnu);

SetAccessChild(pCAAAfrGeoCreationMbr, pCATAfrInsertMnu);

NewAccess(CATCmdSeparator, CAAAfrGeoCreationInsertSep);

pCAAAfrGeoCreationInsertSep,


Catia的二次开发(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:内部排序算法性能分析之数据结构课程设计

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: