CATIA二次开发解读

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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 .dico .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
command headers 5 Create the workbench and arrange the commands 6 Provide the resources and insert the workbench into the Start menu 7 Create the workbench exposed interface Step Where LocalInterfaces and src LocalInterfaces and src LocalInterfaces and src CreateCommands method CreateWorkbench method
1 Create the workbench factory interface
Resource files ProtectedInterfaces and src
3.2 建立Workbench 的Factory Interface
(Creating the Workbench Factory Interface)
3.2.1 命名
CAAIAfrGeoCreationWkbFactory
3.2.2 头文件(the header file )
CAAIAfrGeoCreationWkbFactory.h
#include <CATIGenericFactory.h> extern IID IID_CAAIAfrGeoCreationWkbFactory; class CAAIAfrGeoCreationWkbFactory : public CATIGenericFactory { CATDeclareInterface; public : };
A factory interface is a CAA interface, that is, an abstract class that derives from CATIGenericFactory. As any interface, it has an IID declared as IID_ followed by the interface name, and includes the
CATDeclareInterface macro that declares that this abstract class is an interface. No additional 3
method than those of CATIGenericFactory is necessary. Don't forget the public keyword required by the TIE compiler.(???)
3.2.3 源文件(The source file )
CAAIAfrGeoCreationWkbFactory.cpp
#include <CAAIAfrGeoCreationWkbFactory.h> IID IID_CAAIAfrGeoCreationWkbFactory = { 0xb32eed10, 0xd4c1, 0x11d3, {0xb7, 0xf5, 0x00, 0x08, 0xc7, 0x4f, 0xe8, 0xdd} }; CATImplementInterface(CAAIAfrGeoCreationWkbFactory, CATIGenericFactory);
The CATImplementInterface macro is used in conjunction with CATDeclareInterface in the header file to make an interface from this abstract class and to declare that it OM-derives from CATIGenericfactory.
3.2.4 TIE 文件(The TIE tsrc file)
TIE_CAAIAfrGeoCreationWkbFactory.tsrc
#include "CAAIAfrGeoCreationWkbFactory.h"
The Multi-Workspace Application Builder (mkmk) will generate the TIE for this interface for you, that is, the TIE_CAAIAfrGeoCreationWkbFactory.h file in the ProtectedGenerated directory.
3.3 建立Workbench 的Factory
(Creating the Workbench Factory)
3.3.1 注意事项
The factory class that creates workbench instances must concatenate the name of the class to
instantiate, that is, the workbench description class CAAAfrGeoCreationWkb, with the string Factory. This gives CAAAfrGeoCreationWkbFactory.
3.3.2 头文件
CAAAfrGeoCreationWkbFactory.h
#include "CATWorkshopConfigurationFactory.h"
CATDeclareConfigurationFactory(CAAAfrGeoCreationWkb);
The CATDeclareConfigurationFactory macro argument is the name of the workbench description class.
4
3.3.3 源文件
CAAAfrGeoCreationWkbFactory.cpp
#include <CAAAfrGeoCreationWkb.h> #include <CAAAfrGeoCreationWkbFactory.h>
#include <TIE_CAAIAfrGeoCreationWkbFactory.h> CATImplementConfigurationFactory(CAAAfrGeoCreationWkb, CAAIAfrGeoCreationWkbFactory);
The CATImplementConfigurationFactory arguments are the name of the workbench description class and the name of the workbench factory interface respectively. The CATDeclareConfigurationFactory and CATImplementConfigurationFactory macros create the
workbench factory implementation class as a data extension of the CATApplicationFrame component
3.3.4 更新字典
3.3.
4.1 The interface dictionary that is a file whose name is the framework name suffixed by dico, such as CAAApplicationFrame.dico, and that you should create or update in the framework CNext/code/dictionary directory. The interface dictionary contains the following declaration to state that the CATApplicationFrame component implements the CAAIAfrGeoCreationWkbFactory interface, by means of the extension class created by the macros, whose code is located in the libCAAAfrGeoCreationWbench shared library or DLL:(不太明白)
CATApplicationFrame CAAIAfrGeoCreationWkbFactory libCAAAfrGeoCreationWbench
3.3.
4.2 The factory dictionary that is a file whose name is the framework name suffixed by fact, such as CAAApplicationFrame.fact, and that you should create or update in the framework CNext/code/dictionary directory. The factory dictionary contains the following declaration to state that the CAAIAfrGeoCreationWkbFactory interface is an interface to a factory whose implementation creates a CAAAfrGeoCreationWkb class instance: CAAAfrGeoCreationWkb CAAIAfrGeoCreationWkbFactory
3.4 定义与实现Workbench 类
(Creating the Workbench Description Class)
3.4.1 说明
The CAAAfrGeoCreationWkb class implements the CATICAAAfrGeometryWksConfiguration interface exposed by the CAAGeometry workshop . It includes the following methods: ? ? ?
CreateCommands to instantiate the command headers for the commands of the workbench
CreateWorkbench to create the containers for the workbench, the menus, and the toolbars, and
arrange the commands in the menus and toolbars
GetCustomInterfaces which returns the names of the interfaces exposed by the workbench to
enable its customization
5
GetAddinInterface which returns the name of the interface exposed by the workbench to create add-ins.
3.4.2 头文件
CAAAfrGeoCreationWkb.h
#include "CATBaseUnknown.h" #include "CATListPV.h" class CATCmdWorkbench; class CAAAfrGeoCreationWkb : public CATBaseUnknown { CATDeclareClass; public: CAAAfrGeoCreationWkb(); virtual ~CAAAfrGeoCreationWkb(); void CATClassId void private: CAAAfrGeoCreationWkb(const CAAAfrGeoCreationWkb &iObjectToCopy); }; CreateCommands(); GetAddinInterface(); GetCustomInterfaces(CATListPV * oDefaultIIDList , CATListPV * oCustomIIDList) ;
CATCmdWorkbench * CreateWorkbench();
The CAAAfrGeoCreationWkb class C++-derives from CATBaseUnknown. The
CATDeclareClass macro declares that the class CAAAfrGeoCreationWkb belongs to a component. The class has a constructor, a destructor, the four methods of the CATIWorkbench interface, and a copy constructor. Note that the copy constructor is set as private. This prevents the compiler from creating the copy constructor as public without you know. This copy constructor is not implemented in the source file.
3.4.3 源文件
CAAAfrGeoCreationWkb.cpp
#include <CAAAfrGeoCreationWkb.h>
#include <CATCommandHeader.h> // See Creating the Command Headers MacDeclareHeader(CAAAfrGeoCreationWkbHeader); #include <CATCreateWorkshop.h> CATImplementClass(CAAAfrGeoCreationWkb, Implementation, CATBaseUnknown, CATNull); #include <TIE_CATICAAAfrGeometryWksConfiguration.h> 6
TIE_CATICAAAfrGeometryWksConfiguration(CAAAfrGeoCreationWkb); CAAAfrGeoCreationWkb::CAAAfrGeoCreationWkb() {} CAAAfrGeoCreationWkb::~CAAAfrGeoCreationWkb() {} void CAAAfrGeoCreationWkb::CreateCommands() { ... // See Creating the Command Headers } CATCmdWorkbench * CAAAfrGeoCreationWkb::CreateWorkbench() { ... // See Creating the Workbench and Arranging the Commands } CATClassId CAAAfrGeoCreationWkb::GetAddinInterface() { return "CAAIAfrGeoCreationWkbAddin"; } void CAAAfrGeoCreationWkb::GetCustomInterfaces(CATListPV * oDefaultIIDList, CATListPV * oCustomIIDList) {}
class states that it implements the CATICAAAfrGeometryWksConfiguration interface 3.4.3.2 TIE_ CATImplementClass 宏declaring that the CAAAfrGeoCreationWkb class is a component main class [2], thanks to the
Implementation keyword, and that it OM-derives from CATBaseUnknown [2]. The fourth parameter must
always be set to CATNull for component main classes. 3.4.3.3 创建命令标签(Creating the Command Headers)(见《命令标签》)3.4.3.3.1 命令标签Each command available in your workbench must have a command header. A command header is an instance of a command header class, and different commands can share the same command header class to create their command header. 3.4.3.3.2 创建命令标签类CAAAfrGeoCreationWkbHeader command header class is careated in CAAAfrGeoCreationWkb.cpp:
#include <CATCommandHeader.h> MacDeclareHeader(CAAAfrGeoCreationWkbHeader);
7
The MacDeclareHeader macro creates the header file and the source file for the CAAAfrGeoCreationWkbHeader class, and associates with this class the resource files CAAAfrGeoCreationWkbHeader.CATNls and CAAAfrGeoCreationWkbHeader.CATRsc.
3.4.3.3.3 定义命令标签Create the code to instantiate your command headers in the empty CreateCommands method. This method should contain one instantiation statement of the command header class per command. Each statement has the following form, for example for the Cuboid command.
void CAAAfrGeoCreationWkb::CreateCommands() { ... new CAAAfrGeoCreationWkbHeader("CAAAfrCuboidHdr", "CAADegGeoCommands", "CAADegCreateCuboidCmd", (void *) NULL); ... }
其中:
1)CAAAfruboidHdr is the identifier you need to assign to the command header. It will be used
afterwards: (1)To associate the command starters you will define to put the command in a menu and in toolbars with the command header. (2)To build the variables that define the command header resources, such as the name seen by the end user in his/her own language in the menu, or the icon to display in a toolbar.
2)CAADegGeoCommands is the name of the shared library or DLL containing the Cuboid command's
code, without the prefix lib, and without the suffix depending on the operating system.
3)CAADegCreateCuboidCmd is the name of the Cuboid command class
4)the last argument is the possible pointer to the object to pass to the command when executing
can perform several actions depending on the active document and data, such as "update" or "update all", or "cut" or "copy". 3.4.3.4 Creating the Workbench and Arranging the Commands 3.4.3.4.1 创建workbench using the NewAccess macro:
CATCmdWorkbench * CAAAfrGeoCreationWkb::CreateWorkbench()
{ NewAccess(CATCmdWorkbench,pCAAAfrGeoCreationWkb,CAAAfrGeoCreationWkb); ... // See Creating the Containers for the Toolbars and the Menu Bar return pCAAAfrGeoCreationWkb; } pCAAAfrGeoCreationWkb is the variable used to handle the workbench instance pointer, and CAAAfrGeoCreationWkb is the workbench identifier. Note that the workbench class name and the
workbench identifier must be identical to take into account the workbench resources in the Start menu.
8
They appear both in bold typeface. This identifier is also used to name the workbench resource files CAAAfrGeoCreationWkb.CATNls and CAAAfrGeoCreationWkb.CATRsc. The workbench resources, and how to provide them, are described in Creating Resources for Workbenches. 3.4.3.4.2 创建containers
... NewAccess(CATCmdContainer,pCAAAfrSolidEltTlb,CAAAfrSolidEltTlb); SetAccessChild(pCAAAfrGeoCreationWkb, pCAAAfrSolidEltTlb); ... // See Creating the Solids Toolbar Content AddToolbarView(pCAAAfrSolidEltTlb,1,Right);
NewAccess(CATCmdContainer,pCAAAfrSurfacicEltTlb,CAAAfrSurfacicEltTlb); SetAccessNext(pCAAAfrSolidEltTlb,pCAAAfrSurfacicEltTlb); ... // See Creating the Surfaces Toolbar Content AddToolbarView(pCAAAfrSurfacicEltTlb,-1,Right);
See Creating the Menu Bar Content
SetWorkbenchMenu(pCAAAfrGeoCreationWkb,pCAAAfrGeoCreationMbr); ...
其中:(1)The Solids toolbar is created as an instance of the CATCmdContainer class using the NewAccess macro. pCAAAfrSolidEltTlb is the variable used to handle the Solids toolbar command container instance pointer, and CAAAfrSolidEltTlb is the identifier used to refer to it in the workbench resource files. This identifier must be unique among all the toolbar identifiers that can be found within the application. The Solids toolbar is set as the child of the workbench using the SetAccessChild macro, and its default location is defined using the AddToolbarView macro, where 1 means that the Solids toolbar is visible by default (-1 means invisible), and Right means that the toolbar is docked at the right side of the application window. (2)The Surfaces toolbar is created in the same way, but it is set next to the Solids toolbar using the SetAccessNext macro. It is invisible (-1 means invisible) by default, and is also docked at the right side of
the application window. (3)The menu bar is also created as an instance of the CATCmdContainer class and is referred to using the pCAAAfrGeoCreationMbr pointer. Its identifier is CAAAfrGeoCreationMbr and is used for its resources. It is set as the workbench's menu bar using the SetWorkbenchMenu macro.
9
The toolbar 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. 1)添加Solids 工具条按钮(Creating the Solids Toolbar Content)
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,"CAAAfrCuboidHdr"); SetAccessChild(pCAAAfrSolidEltTlb,pCAAAfrTSolidEltCuboidStr);
NewAccess(CATCmdStarter,pCAAAfrTSolidEltSphereStr,CAAAfrTSolidEltSphereStr); SetAccessCommand(pCAAAfrTSolidEltSphereStr,"CAAAfrSphereHdr");
SetAccessNext(pCAAAfrTSolidEltCuboidStr,pCAAAfrTSolidEltSphereStr);
NewAccess(CATCmdStarter,pCAAAfrTSolidEltTorusStr,CAAAfrTSolidEltTorusStr); SetAccessCommand(pCAAAfrTSolidEltTorusStr,"CAAAfrTorusHdr");
SetAccessNext(pCAAAfrTSolidEltSphereStr,pCAAAfrTSolidEltTorusStr);
NewAccess(CATCmdStarter,pCAAAfrTSolidEltCylinder1Str,CAAAfrTSolidEltCylinder1Str); SetAccessCommand(pCAAAfrTSolidEltCylinder1Str,"CAAAfrCylinder1Hdr"); SetAccessNext(pCAAAfrTSolidEltTorusStr,pCAAAfrTSolidEltCylinder1Str);
NewAccess(CATCmdStarter,pCAAAfrTSolidEltCylinder2Str,CAAAfrTSolidEltCylinder2Str); SetAccessCommand(pCAAAfrTSolidEltCylinder2Str,"CAAAfrCylinder2Hdr"); 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,"CAAAfrRevolSurfHdr");
SetAccessChild(pCAAAfrSurfacicEltTlb,pCAAAfrTSurfRevolStr);
NewAccess(CATCmdStarter,pCAAAfrTSurfNurbsStr,CAAAfrTSurfNurbsStr); SetAccessCommand(pCAAAfrTSurfNurbsStr,"CAAAfrNurbsSurfHdr");
SetAccessNext(pCAAAfrTSurfRevolStr,pCAAAfrTSurfNurbsStr);
SetAccessCommand(pCAAAfrTSurfOffsetStr,"CAAAfrOffsetSurfHdr");
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,CAAAfrGeoCreationInsertSe p); SetAccessChild(pCATAfrInsertMnu,pCAAAfrGeoCreationInsertSep);
NewAccess(CATCmdContainer,pCAAAfrSolidEltSnu,CAAAfrSolidEltSnu);
12
SetAccessNext(pCAAAfrGeoCreationInsertSep,pCAAAfrSolidEltSnu);
NewAccess(CATCmdStarter,pCAAAfrMSolidCuboidStr,CAAAfrMSolidCuboidStr); SetAccessChild(pCAAAfrSolidEltSnu,pCAAAfrMSolidCuboidStr); SetAccessCommand(pCAAAfrMSolidCuboidStr,"CAAAfrCuboidHdr");
NewAccess(CATCmdStarter,pCAAAfrMSolidSphereStr,CAAAfrMSolidSphereStr); SetAccessNext(pCAAAfrMSolidCuboidStr,pCAAAfrMSolidSphereStr); SetAccessCommand(pCAAAfrMSolidSphereStr,"CAAAfrSphereHdr");
NewAccess(CATCmdStarter,pCAAAfrMSolidTorusStr,CAAAfrMSolidTorusStr); SetAccessNext(pCAAAfrMSolidSphereStr,pCAAAfrMSolidTorusStr); SetAccessCommand(pCAAAfrMSolidTorusStr,"CAAAfrTorusHdr");
NewAccess(CATCmdStarter,pCAAAfrMSolidCylinder1Str,CAAAfrMSolidCylinder1Str); SetAccessNext(pCAAAfrMSolidTorusStr,pCAAAfrMSolidCylinder1Str); SetAccessCommand(pCAAAfrMSolidCylinder1Str,"CAAAfrCylinder1Hdr");
NewAccess(CATCmdStarter,pCAAAfrMSolidCylinder2Str,CAAAfrMSolidCylinder2Str); SetAccessNext(pCAAAfrMSolidCylinder1Str,pCAAAfrMSolidCylinder2Str); SetAccessCommand(pCAAAfrMSolidCylinder2Str,"CAAAfrCylinder2Hdr"); ...
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,"CAAAfrRevolSurfHdr");
NewAccess(CATCmdStarter,pCAAAfrMSurfNurbsStr,CAAAfrMSurfNurbsStr); SetAccessNext(pCAAAfrMSurfRevolStr,pCAAAfrMSurfNurbsStr); SetAccessCommand(pCAAAfrMSurfNurbsStr,"CAAAfrNurbsSurfHdr");
13
SetAccessNext(pCAAAfrMSurfNurbsStr,pCAAAfrMSurfOffsetStr); SetAccessCommand(pCAAAfrMSurfOffsetStr,"CAAAfrOffsetSurfHdr"); ...
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。

相关文档
最新文档