CATIA二次开发

更新时间:2023-09-22 10:30:01 阅读量: 经管营销 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

CATIA+CAA+二次开发详细教程(1)-基础概念

CAA 第一讲

CATIA CAA 第一讲:基本概念 1. 什么是组件?

CAA,全称 Component Application Architecture,组件应用架构。这个东西对不搞软件 的人来说可能很陌生,我也很陌生啊,原来光知道―面向对象的技术‖就很牛逼了, ―组件 技术‖难道更牛逼吗? 既然类和组件有着这么多类似的地方, 那么传统的面向对象编程和面向组件编程有什么 区别呢?简单的说, 面向对象关注的是组合在一个二进制可执行文件中的各个类的关系, 而 面向组件的编程关注的是在彼此独立的基础上模块之间的交互性, 这种交互性使得你并不需 要熟悉它们内部的工作原理。 这两种方法最基本的不同在于它们对最终的应用程序的观点。在传统的面向对象编程 中,尽管你可以精心的把所有的商业逻辑分布在不同的类中,一旦这些类被编译,它们就被 固化成了一个巨大的二进制代码。 所有的类共享同一个物理单元 (通常是一个可执行文件) 、 被操作系统认为是同一个进程, 使用同一个地址空间以及共享相同的安全策略等等。 如果多 个开发者在同一份代码上进行开发,他们甚至还要共享源文件。在这种情况下,修改一个类 可能会让整个项目被重新链接,并重新进行必要的测试,更严重的,还有可能要修改其他的 类。 但是, 在面向组件开发中, 应用程序是由一系列可以互相交互的二进制模块组合而成的。 一个具体的二进制组件可能并不能完成什么工作。 有些组件是为了提供一些常规服务而编写 的,例如通信的封装或者文件访问组件。也有一些是为了某些特定应用而专门开发的。一个 应用程序的设计者可以通过把这些不同的组件提供的功能粘合在一起来实现他们需要的商 业逻辑。很多面向组件的技术——例如: COM 、 J2EE 、 CORBA 和 .NET 都为二进制组件 提供了的无缝链接的机制。而唯一的不同就

是你需要在组件通信上花费的力气。 把一个二进制应用程序分解成不同的二进制组件的动机和把不同的类放到不同的文件 中是类似的。 后者使得不同的类的开发人员可以彼此独立的工作, 尽管即时修改了一个类也 要重新链接整个应用程序,但是你只需要重新编译被修改的部分就可以了。 但是, 面向组件的开发还是和简单软件项目的管理更复杂一些。 因为一个面向组件的应 用程序是一个二进制代码块的集合,你可以把组件当作是 LEGO 的积木块一样,随心所欲 的拆装它们。如果你需要修改一个组件的实现,只需要修改那个组件就可以了,而组件的客 户机不需要重新编译也不需要重新开发。 对于那些不常用到的组件, 组件甚至可以在一个程 序运行的时候被更新。 这些改进和增强使得组件可以立即进行更新, 而所有该组件的客户都 将立即受益。无论是在同一台机器上还是通过网络远程访问。 面向组件的应用程序也更易于扩展。 当你需要实现新的需求的时候, 你可以提供一个新的组 件, 而不去影响那些和新需求无关的组件。 这些特点使得面向组件的开发降低了大型软件项 目长期维护的成本,这是一个最实际的商业问题,也正是如此,组件技术才如此迅速的被接 受。 面向组件的应用程序通常可以更快的响应市场, 因为你可以有很大的选择空间, 不仅仅 是自己开发的组件,还可以从第三方厂商来购买某些组件,从而避免了重复制造轮子。这 里, VB 就是一个很好的例子,丰富的 ActiveX 控件使得很多人在快速开发中得到了享受。 1

用户界面开发——实例说明 ——Creating a Workbench 一、目标 1.1 目标

Showing how to create a workbench to be added to a given workshop.

1.2 显示界面(workbench )

Like the workshop, the workbench is an object that gathers the commands to work on the document and arrange them in toolbars and menus.

1.3 命令标签(command header)

Command headers are used to make the link between the workbench and the commands.

二、CAAAfrGeoCreationWbench 实例说明 2.1 功能

The CAAAfrGeoCreationWbench use case creates a workbench named CAA Geometrical Creation for the CAAGeometry document. Its specifications cover most of the cases you will meet. Two toolbars are provided: The Solids toolbar. It includes five new commands: Cuboid, Sphere, Torus, and Cylinder 1 and 2. The Surfaces toolbar. It includes three new commands: Revolution Surface, Nurbs Surface, and Offset Surface. The only change in the menu bar is the addition of these commands in the Insert menu using two submenus below the existing ones. 1

2.2 运行

运行 CATIA 系统,并依次选择 Start->Infrastructure->CAA V5: Geometrical Creation: This creates a new CAAGeometry document with the CAA V5: Geometrical Creation workbench active.

2.3 框架组成

CAAAfrGeoCreationWkb CAAAfrGeoCreationWkbFactory

CAAIAfrGeoCreationWkbFactory Workbench description class Factory class for the workbench class Factory interface implemented by CAAAfrGeoCreationWkbFactory

TIE_CAAIAfrGeoCreationWkbFactory TIE class for the factory interface

CAAIAfrGeoCreationWkbAddin Add-in interface exposed by the workbench and that all its add-ins must implement

TIE_CAAIAfrGeoCreationWkbAddin TIE class for the add-in interface

三、程序结构(Step-by-Step) 3.1 编程准备 3.1.1 确认

? ? Make sure that the workshop to which it is dedicated exposes the CATIxxxConfiguration interface, where xxx is the workshop identifier, in a PublicInterfaces or ProtectedInterfaces directory. Create the module directory to store the workbench code along with its two subdirectories LocalInterfaces and src. Then you will need to create the following files. In the framework's ProtectedInterfaces directory CAAIAfrGeoCreationWkbAddin.h The header file of the workbench exposed interface to enable clients to create add-ins In the

CAAAfrGeoCreationWbench.m\\LocalInterfaces directory CAAIAfrGeoCreationWkbFactory.h CAAAfrGeoCreationWkbFactory.h CAAAfrGeoCreationWkb.h The header file of the

workbench factory interface The header file of the workbench factory class The header file of the workbench description class

In the CAAAfrGeoCreationWbench.m\\src directory CAAIAfrGeoCreationWkbAddin.cpp CAAIAfrGeoCreationWkbFactory.cpp CAAAfrGeoCreationWkbFactory.cpp CAAAfrGeoCreationWkb.cpp TIE_CAAIAfrGeoCreationWkbAddin.tsrc

TIE_CAAIAfrGeoCreationWkbFactory.tsrc The source file of the workbench exposed interface to enable clients to create add-ins The source file of the workbench factory interface The source file of the workbench factory class The source file of the workbench description class The file to create the TIE for CAAIAfrGeometryWksAddin The file to create the TIE for 2

CAAIAfrGeometryWksFactory In the dictionary, that is the CNext\\code\\dictionary directory, referenced at run time using the CATDictionaryPath environment variable, create or update CAAApplicationFrame.edu.dico CAAApplicationFrame.edu.fact CATMsgCatalogPath environment variable CAAAfrGeoCreationWkb.CATNls

CAAAfrGeoCreationWkbHeader.CATRsc The workbench message file The interface dictionary The factory dictionary

In the CNext\\resources\\msgcatalog directory, referenced at run time using the

CAAAfrGeoCreationWkbHeader.CATNls and The command header resource files

3.1.2 开发步骤

# 2 Create the workbench factory 3 Create the workbench description class 4 Create the

This toolbar contains four commands: Cuboid, Sphere, Torus, and Cylinder. You should, for each command: (1)Create a command starter using the NewAccess macro (2)Associate the command starter, using the SetAccessCommand macro, with the appropriate command header identifier defined in the CreateCommands method (3)Arrange the command starters in the toolbar using the SetAccessChild and SetAccessNext macros

... NewAccess(CATCmdStarter,pCAAAfrTSolidEltCuboidStr,CAAAfrTSolidEltCuboidStr); SetAccessCommand(pCAAAfrTSolidEltCuboidStr,\SetAccessChild(pCAAAfrSolidEltTlb,pCAAAfrTSolidEltCuboidStr);

NewAccess(CATCmdStarter,pCAAAfrTSolidEltSphereStr,CAAAfrTSolidEltSphereStr); SetAccessCommand(pCAAAfrTSolidEltSphereStr,\SetAccessNext(pCAAAfrTSolidEltCuboidStr,pCAAAfrTSolidEltSphereStr); NewAccess(CATCmdStarter,pCAAAfrTSolidEltTorusStr,CAAAfrTSolidEltTorusStr); SetAccessCommand(pCAAAfrTSolidEltTorusStr,\SetAccessNext(pCAAAfrTSolidEltSphereStr,pCAAAfrTSolidEltTorusStr);

NewAccess(CATCmdStarter,pCAAAfrTSolidEltCylinder1Str,CAAAfrTSolidEltCylinder1Str); SetAccessCommand(pCAAAfrTSolidEltCylinder1Str,\SetAccessNext(pCAAAfrTSolidEltTorusStr,pCAAAfrTSolidEltCylinder1Str);

NewAccess(CATCmdStarter,pCAAAfrTSolidEltCylinder2Str,CAAAfrTSolidEltCylinder2Str); SetAccessCommand(pCAAAfrTSolidEltCylinder2Str,\SetAccessNext(pCAAAfrTSolidEltCylinder1Str,pCAAAfrTSolidEltCylinder2Str); ...

Three macros are required for each command. For example, the Cuboid command is processed as follows:

10

1) First create the command starter as a CATCmdStarter instance using the NewAccess macro. pCAAAfrTSolidEltCuboidStr is the variable used to handle a pointer to that instance, and CAAAfrTSolidEltCuboidStr is its identifier. 2) Then associate the Cuboid command header with this command starter using the

SetAccessCommand macro. The second parameter is the Cuboid command header

identifier defined as the first parameter of the command header consrtuctor. Refer to Creating the Command Headers 3) Finally set the Cuboid command starter as the child of the Solids toolbar. Proceed in the same way for the other commands, except that they are set as next of one another using the SetAccessNext macro. 2)添加 Surfaces 工具条按钮(Creating the Surfaces Toolbar Content)

This toolbar contains three commands: Revolution Surface, Nurbs Surface, and Offset Surface. You should, for each command: (1)Create a command starter using the NewAccess macro (2)Associate the command starter, using the SetAccessCommand macro, with the appropriate command header identifier defined in the CreateCommands method (3)Arrange the command starters in the toolbar using the SetAccessChild and SetAccessNext macros ... NewAccess(CATCmdStarter,pCAAAfrTSurfRevolStr,CAAAfrTSurfRevolStr); SetAccessCommand(pCAAAfrTSurfRevolStr,\SetAccessChild(pCAAAfrSurfacicEltTlb,pCAAAfrTSurfRevolStr);

NewAccess(CATCmdStarter,pCAAAfrTSurfNurbsStr,CAAAfrTSurfNurbsStr); SetAccessCommand(pCAAAfrTSurfNurbsStr,\SetAccessNext(pCAAAfrTSurfRevolStr,pCAAAfrTSurfNurbsStr);

NewAccess(CATCmdStarter,pCAAAfrTSurfOffsetStr,CAAAfrTSurfOffsetStr);

SetAccessCommand(pCAAAfrTSurfOffsetStr,\SetAccessNext(pCAAAfrTSurfNurbsStr,pCAAAfrTSurfOffsetStr); ...

Three macros are required for each command. For example, the Revolution Surface command is processed as follows: (1)First create the command starter as a CATCmdStarter instance using the NewAccess macro.

pCAAAfrTSurfRevolStr is the variable used to handle a pointer to that instance, and CAAAfrTSurfRevolStr is its identifier. 11

(2)Then associate the Revolution Surface command header with this command starter using the

SetAccessCommand macro. The second parameter is the Revolution Surface command header identifier

defined as the first parameter of the command header consrtuctor. Refer to Creating the Command Headers (3)Finally set the Revolution Surface command starter as the child of the Surfaces toolbar. Proceed in the same way for the other commands, except that they are set as next of one another using the SetAccessNext macro. 3)添加菜单项(Creating the Menu Bar Content) Menus and submenus are created as CATCmdContainer instances, and menu items as CATCmdStarter instances. The menu bar you create will be merged when the workbench is loaded or activated at run time with the workshop menu bar, itself resulting in the merge of the default menu bar, that is, the one that exists when no document is active, with the one defined for the workshop. You can neither remove a menu from the default menu bar or from the menu bar defined for the workshop, nor change the menu order. You can add submenus to menus. You can also add submenus to your own submenus, but not to existing submenus.

You should: (1)Create a command container for each menu and submenu using the NewAccess macro (2)Create a command starter for each command using the NewAccess macro (3) Associate each command starter, using the SetAccessCommand macro, with the appropriate command header identifier defined in the CreateCommands method (4)Arrange the command starters in the menu using the SetAccessChild, and SetAccessNext macros ——Insert Menu - Solids Submenu

... NewAccess(CATCmdContainer,pCATAfrInsertMnu,CATAfrInsertMnu); SetAccessChild(pCAAAfrGeoCreationMbr,pCATAfrInsertMnu);

NewAccess(CATCmdSeparator,pCAAAfrGeoCreationInsertSep,CAAAfrGeoCreationInsertSep); SetAccessChild(pCATAfrInsertMnu,pCAAAfrGeoCreationInsertSep); NewAccess(CATCmdContainer,pCAAAfrSolidEltSnu,CAAAfrSolidEltSnu); 12

SetAccessNext(pCAAAfrGeoCreationInsertSep,pCAAAfrSolidEltSnu);

NewAccess(CATCmdStarter,pCAAAfrMSolidCuboidStr,CAAAfrMSolidCuboidStr); SetAccessChild(pCAAAfrSolidEltSnu,pCAAAfrMSolidCuboidStr); SetAccessCommand(pCAAAfrMSolidCuboidStr,\

NewAccess(CATCmdStarter,pCAAAfrMSolidSphereStr,CAAAfrMSolidSphereStr); SetAccessNext(pCAAAfrMSolidCuboidStr,pCAAAfrMSolidSphereStr); SetAccessCommand(pCAAAfrMSolidSphereStr,\

NewAccess(CATCmdStarter,pCAAAfrMSolidTorusStr,CAAAfrMSolidTorusStr); SetAccessNext(pCAAAfrMSolidSphereStr,pCAAAfrMSolidTorusStr); SetAccessCommand(pCAAAfrMSolidTorusStr,\

NewAccess(CATCmdStarter,pCAAAfrMSolidCylinder1Str,CAAAfrMSolidCylinder1Str); SetAccessNext(pCAAAfrMSolidTorusStr,pCAAAfrMSolidCylinder1Str); SetAccessCommand(pCAAAfrMSolidCylinder1Str,\

NewAccess(CATCmdStarter,pCAAAfrMSolidCylinder2Str,CAAAfrMSolidCylinder2Str); SetAccessNext(pCAAAfrMSolidCylinder1Str,pCAAAfrMSolidCylinder2Str); SetAccessCommand(pCAAAfrMSolidCylinder2Str,\

The Insert menu command container is created, even if it already exists. Then the Solids submenu command container is created and set as the child of the Insert menu command container. Since no other positioning information is given, it should lay below the last submenu or command of the workshop menu bar, that is the Plane command. Then the Cuboid command starter is created and set as the child of the Solids submenu command container, and the others are cretaed and set next of one another. ——Insert Menu - Surfaces Submenu ... NewAccess(CATCmdContainer,pCAAAfrSurfacicEltSnu,CAAAfrSurfacicEltSnu) ; SetAccessNext(pCAAAfrSolidEltSnu,pCAAAfrSurfacicEltSnu);

NewAccess(CATCmdStarter,pCAAAfrMSurfRevolStr,CAAAfrMSurfRevolStr); SetAccessChild(pCAAAfrSurfacicEltSnu,pCAAAfrMSurfRevolStr); SetAccessCommand(pCAAAfrMSurfRevolStr,\NewAccess(CATCmdStarter,pCAAAfrMSurfNurbsStr,CAAAfrMSurfNurbsStr); SetAccessNext(pCAAAfrMSurfRevolStr,pCAAAfrMSurfNurbsStr); SetAccessCommand(pCAAAfrMSurfNurbsStr,\ 13

NewAccess(CATCmdStarter,pCAAAfrMSurfOffsetStr,CAAAfrMSurfOffsetStr);

SetAccessNext(pCAAAfrMSurfNurbsStr,pCAAAfrMSurfOffsetStr); SetAccessCommand(pCAAAfrMSurfOffsetStr,\

The Surfaces submenu command container is created and set next to the Solids submenu command container. Then the Revolution Surface command starter is created and set as the child of the Surfaces submenu command container, and the others are cretaed and set next of one another. The menu and submenu resources, and how to provide them, are described in Creating Resources for Workbenches. See also Providing the Resources and Inserting the Workbench into the Start Menu for an overview of all the resources to create. 3.4.3.5 GetCustomInterfaces 方法 The GetCustomInterfaces method must be empty. The names of the interface exposed by the workbench to enable clients to create add-ins is returned by the GetAddinInterface method.

3.4.4 修改字典(Updating the Dictionary)

Update the interface dictionary, that is a file named, for example, CAAApplicationFrame.dico, whose directory's pathname is concatenated at run time in the CATDictionaryPath environment variable, and containing the following declaration to state that the CAAAfrGeoCreationWkb class implements the CATICAAAfrGeometryWksConfiguration interface, and whose code is located in the libCAAAfrGeoCreationWbench shared library or DLL. The update is in bold typeface:

CATApplicationFrame CAAIAfrGeoCreationWkbFactory libCAAAfrGeoCreationWbench CAAAfrGeoCreationWkb CATICAAAfrGeometryWksConfiguration libCAAAfrGeoCreationWbench

3.5 创建资源及嵌入 Workbench

(Providing the Resources and Inserting the Workbench into the Start Menu)

3.5.1 workbench 资源( The workbench and command container resources) 3.5.1.1 文本资源 The resource file containing the title and help messages in the English language, and that can be translated into other languages. It is suffixed using CATNls The resource files must have the workbench identifier as file name, that is

CAAAfrGeoCreationWkb. This identifier is declared in the CreateWorkbench method of the workbench description class, as the third parameter of the NewAccess macro that creates the workbench.

NewAccess(CATCmdWorkbench,pCAAAfrGeoCreationWkb,CAAAfrGeoCreationWkb);

The workbench resource files are then CAAAfrGeoCreationWkb.CATNls and

CAAAfrGeoCreationWkb.CATRsc. These files are located in the CNext\\resources\\msgcatalog directory of the framework containing the workbench module. This directory includes subdirectories, one for each language into which the title and messages of the

CAAAfrGeoCreationWkb.CATNls file can be translated. The resource files contain: o o o Workbench: the title, messages, and icons to be displayed in the Start menu Toolbars: their titles Menus and submenus: their titles, icons, and mnemonics 14

Icon boxes: their titles.

Each resource is provided using a key and a text, or a file name without suffix, separated by the equal sign. The key is built as a concatenation of the object identifier you defined as the third parameter of the

NewAccess macro, a dot, and a keyword designating the appropriate resource. The message is

enclosed

using double quotes and ended using a semicolon. For example, the CAAAfrGeoCreationWkb workbench title is defined as follows:

CAAAfrGeoCreationWkb.Title = \

The CAAAfrGeoCreationWkb.CATNls file contains: ? The resources for the workbench itself: the title used in the Start menu, its associated help message, the short help displayed when the mouse is over the workbench icon, and the long help ? ? // WORKBENCH

//---------------------------------------------------------------------------CAAAfrGeoCreationWkb.Title CAAAfrGeoCreationWkb.Help Elements\two toolsbars: - One for some Solid Elements - The other for some Surfacic Elements\//---------------------------------------------------------------------------// TOOLBAR

//---------------------------------------------------------------------------CAAAfrSolidEltTlb.Title CAAAfrSurfacicEltTlb.Title = \Creation Workbench. It is used to demonstrate workbenches. = \Creation\

CAAAfrGeoCreationWkb.ShortHelp = \

The titles of the toolbars and icon boxes The titles and mnemonics of the menus and submenus.

//----------------------------------------------------------------------------

//---------------------------------------------------------------------------// SUB - MENU //---------------------------------------------------------------------------CAAAfrSolidEltSnu.Title

CAAAfrSolidEltSnu.Mnemonic CAAAfrSurfacicEltSnu.Title = \

CAAAfrSurfacicEltSnu.Mnemonic = \

3.5.1.2 位图资源 CAAAfrGeoCreationWkb.CATRsc 15

This file contains the category, that is the submenu of the Start menu where the workbench should appear, and the names of the icons to be associated with the workbench for the Start menu.

CAAAfrGeoCreationWkb.Category = \

// Icons for the Welcome window 64x64 CAAAfrGeoCreationWkb.Icon.NormalPnl = \\\

CAAAfrGeoCreationWkb.Icon.NormalCtx = \CAAAfrGeoCreationWkb.Icon.PressedlCtx = \CAAAfrGeoCreationWkb.Icon.FocusedlCtx = \for the workbench toolbar 24x24 CAAAfrGeoCreationWkb.Icon.NormalRep = \\\

It is in this file that you declare if the workbench is warm start compliant [3]. The

CAAGeometry document is not warm start compliant, so its workbenches are not compliant too.

3.5.2 command header 资源

The command header resources in the command header resource files: titles, messages, icons, and the accelerators associated with the commands. The resource files searched for at run time should have the same name than you command header class, that is CAAAfrGeoCreationWkbHeader. 3.5.2.1 文本资源

本文来源:https://www.bwwdw.com/article/y1yd.html

Top