CATIA二次开发_第1页
CATIA二次开发_第2页
CATIA二次开发_第3页
CATIA二次开发_第4页
CATIA二次开发_第5页
已阅读5页,还剩46页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、CATIA+CAA+二次开发详细教程(1)-基础概念CAA 第一讲CATIA CAA 第一讲:基本概念1. 什么是组件?CAA,全称 Component Application Architecture,组件应用架构。这个东西对不搞软件 的人来说可能很陌生,我也很陌生啊,原来光知道“面向对象的技术”就很牛逼了, “组件 技术”难道更牛逼吗? 既然类和组件有着这么多类似的地方, 那么传统的面向对象编程和面向组件编程有什么 区别呢?简单的说, 面向对象关注的是组合在一个二进制可执行文件中的各个类的关系, 而 面向组件的编程关注的是在彼此独立的基础上模块之间的交互性, 这种交互性使得你并不需 要熟悉

2、它们内部的工作原理。 这两种方法最基本的不同在于它们对最终的应用程序的观点。在传统的面向对象编程 中,尽管你可以精心的把所有的商业逻辑分布在不同的类中,一旦这些类被编译,它们就被 固化成了一个巨大的二进制代码。 所有的类共享同一个物理单元 (通常是一个可执行文件) 、 被操作系统认为是同一个进程, 使用同一个地址空间以及共享相同的安全策略等等。 如果多 个开发者在同一份代码上进行开发,他们甚至还要共享源文件。在这种情况下,修改一个类 可能会让整个项目被重新链接,并重新进行必要的测试,更严重的,还有可能要修改其他的 类。 但是, 在面向组件开发中, 应用程序是由一系列可以互相交互的二进制模块组合

3、而成的。 一个具体的二进制组件可能并不能完成什么工作。 有些组件是为了提供一些常规服务而编写 的,例如通信的封装或者文件访问组件。也有一些是为了某些特定应用而专门开发的。一个 应用程序的设计者可以通过把这些不同的组件提供的功能粘合在一起来实现他们需要的商 业逻辑。很多面向组件的技术例如: COM 、 J2EE 、 CORBA 和 .NET 都为二进制组件 提供了的无缝链接的机制。而唯一的不同就是你需要在组件通信上花费的力气。 把一个二进制应用程序分解成不同的二进制组件的动机和把不同的类放到不同的文件 中是类似的。 后者使得不同的类的开发人员可以彼此独立的工作, 尽管即时修改了一个类也 要重新链

4、接整个应用程序,但是你只需要重新编译被修改的部分就可以了。 但是, 面向组件的开发还是和简单软件项目的管理更复杂一些。 因为一个面向组件的应 用程序是一个二进制代码块的集合,你可以把组件当作是 LEGO 的积木块一样,随心所欲 的拆装它们。如果你需要修改一个组件的实现,只需要修改那个组件就可以了,而组件的客 户机不需要重新编译也不需要重新开发。 对于那些不常用到的组件, 组件甚至可以在一个程 序运行的时候被更新。 这些改进和增强使得组件可以立即进行更新, 而所有该组件的客户都 将立即受益。无论是在同一台机器上还是通过网络远程访问。 面向组件的应用程序也更易于扩展。 当你需要实现新的需求的时候,

5、 你可以提供一个新的组 件, 而不去影响那些和新需求无关的组件。 这些特点使得面向组件的开发降低了大型软件项 目长期维护的成本,这是一个最实际的商业问题,也正是如此,组件技术才如此迅速的被接 受。 面向组件的应用程序通常可以更快的响应市场, 因为你可以有很大的选择空间, 不仅仅 是自己开发的组件,还可以从第三方厂商来购买某些组件,从而避免了重复制造轮子。这 里, VB 就是一个很好的例子,丰富的 ActiveX 控件使得很多人在快速开发中得到了享受。1用户界面开发实例说明Creating a Workbench一、目标1.1 目标Showing how to create a workbenc

6、h 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.二、CAAA

7、frGeoCreationWbench 实例说明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,

8、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.12.2 运行运行 CATIA 系统,并依次选择 Start->

9、;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 Fac

10、tory interface implemented by CAAAfrGeoCreationWkbFactoryTIE_CAAIAfrGeoCreationWkbFactory TIE class for the factory interface CAAIAfrGeoCreationWkbAddin Add-in interface exposed by the workbench and that all its add-ins must implementTIE_CAAIAfrGeoCreationWkbAddin TIE class for the add-in interface三

11、、程序结构(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 it

12、s 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.mLoc

13、alInterfaces 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 classIn the CAAAfrGeoCreationWbench.msrc directory

14、 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 o

15、f 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 for2CAAIAfrGeometryWksFactory In the dictionary, that is the CNextcodedictionary direc

16、tory, referenced at run time using the CATDictionaryPath environment variable, create or update CAAApplicationF.dico CAAApplicationF.fact CATMsgCatalogPath environment variable CAAAfrGeoCreationWkb.CATNls CAAAfrGeoCreationWkbHeader.CATRsc The workbench message file The interface dict

17、ionary The factory dictionaryIn the CNextresourcesmsgcatalog directory, referenced at run time using theCAAAfrGeoCreationWkbHeader.CATNls and The command header resource files3.1.2 开发步骤# 2 Create the workbench factory 3 Create the workbench description class 4 Create the command headers 5 Create the

18、 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 srcCreateCommands method CreateWorkbench method1 Create the workbench facto

19、ry interfaceResource files ProtectedInterfaces and src3.2 建立 Workbench 的 Factory Interface(Creating the Workbench Factory Interface)3.2.1 命名CAAIAfrGeoCreationWkbFactory3.2.2 头文件(the header file )CAAIAfrGeoCreationWkbFactory.h#include <CATIGenericFactory.h> extern IID IID_CAAIAfrGeoCreationWkbF

20、actory; 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

21、 theCATDeclareInterface macro that declares that this abstract class is an interface. No additional 3method 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 <CAAIA

22、frGeoCreationWkbFactory.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

23、 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

24、 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,

25、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 CATDeclareConfiguration

26、Factory macro argument is the name of the workbench description class.43.3.3 源文件CAAAfrGeoCreationWkbFactory.cpp#include <CAAAfrGeoCreationWkb.h> #include <CAAAfrGeoCreationWkbFactory.h> #include <TIE_CAAIAfrGeoCreationWkbFactory.h> CATImplementConfigurationFactory(CAAAfrGeoCreation

27、Wkb, CAAIAfrGeoCreationWkbFactory);The CATImplementConfigurationFactory arguments are the name of the workbench description class and the name of the workbench factory interface respectively. TheCATDeclareConfigurationFactory and CATImplementConfigurationFactory macros create theworkbench factory im

28、plementation class as a data extension of the CATApplicationFrame component3.3.4 更新字典 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 direct

29、ory. 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

30、:(不太明白)CATApplicationFrame CAAIAfrGeoCreationWkbFactory libCAAAfrGeoCreationWbench 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.

31、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 CAAIAfrGeoCreationWkbFactory3.4 定义与实现 Workbench 类(Creating the Workb

32、ench 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

33、to create the containers for the workbench, the menus, and the toolbars, andarrange the commands in the menus and toolbarsGetCustomInterfaces which returns the names of the interfaces exposed by the workbench toenable its customization5GetAddinInterface which returns the name of the interface expose

34、d by the workbench to createadd-ins.3.4.2 头文件CAAAfrGeoCreationWkb.h#include "CATBaseUnknown.h" #include "CATListPV.h" class CATCmdWorkbench; class CAAAfrGeoCreationWkb : public CATBaseUnknown CATDeclareClass; public: CAAAfrGeoCreationWkb(); virtual CAAAfrGeoCreationWkb(); void CA

35、TClassId void private: CAAAfrGeoCreationWkb(const CAAAfrGeoCreationWkb &iObjectToCopy); ; CreateCommands(); GetAddinInterface(); GetCustomInterfaces(CATListPV * oDefaultIIDList , CATListPV * oCustomIIDList) ;CATCmdWorkbench * CreateWorkbench();The CAAAfrGeoCreationWkb class C+-derives from CATBa

36、seUnknown. 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 f

37、rom 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(CAAAfrGeoCreationW

38、kbHeader); #include <CATCreateWorkshop.h> CATImplementClass(CAAAfrGeoCreationWkb, Implementation, CATBaseUnknown, CATNull); #include <TIE_CATICAAAfrGeometryWksConfiguration.h> 6TIE_CATICAAAfrGeometryWksConfiguration(CAAAfrGeoCreationWkb); CAAAfrGeoCreationWkb:CAAAfrGeoCreationWkb() CAAAf

39、rGeoCreationWkb:CAAAfrGeoCreationWkb() void CAAAfrGeoCreationWkb:CreateCommands() . / See Creating the Command Headers CATCmdWorkbench * CAAAfrGeoCreationWkb:CreateWorkbench() . / See Creating the Workbench and Arranging the Commands CATClassId CAAAfrGeoCreationWkb:GetAddinInterface() return "C

40、AAIAfrGeoCreationWkbAddin" void CAAAfrGeoCreationWkb:GetCustomInterfaces(CATListPV * oDefaultIIDList, CATListPV * oCustomIIDList) TIE_CATICAAAfrGeometryWksConfiguration 宏 The CAAAfrGeoCreationWkb class states that it implements the CATICAAAfrGeometryWksConfiguration interface TI

41、E_ CATImplementClass 宏 declaring that the CAAAfrGeoCreationWkb class is a component main class 2, thanks to theImplementation keyword, and that it OM-derives from CATBaseUnknown 2. The fourth parameter mustalways be set to CATNull for component main classes. 创建命令标签(Creating the Command Heade

42、rs) (见命令标签) .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. .2 创建命令标签类 CAAAfrGeoCreationWkbHeader comma

43、nd header class is careated in CAAAfrGeoCreationWkb.cpp:#include <CATCommandHeader.h> MacDeclareHeader(CAAAfrGeoCreationWkbHeader);7The MacDeclareHeader macro creates the header file and the source file for the CAAAfrGeoCreationWkbHeader class, and associates with this class the resource files

44、 CAAAfrGeoCreationWkbHeader.CATNls and CAAAfrGeoCreationWkbHeader.CATRsc. .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 fo

45、llowing 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 th

46、e command header. It will be usedafterwards: (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

47、 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'scode, without the prefix lib, and without the suffix depending on the operating system.3)CAADegCreateCuboidCmd is the name of the Cuboid command class4)the l

48、ast argument is the possible pointer to the object to pass to the command when executing it. It is often a character string that indicates the action to carry out when the same command can perform several actions depending on the active document and data, such as "update" or "update a

49、ll", or "cut" or "copy". Creating the Workbench and Arranging the Commands .1 创建 workbench using the NewAccess macro:CATCmdWorkbench * CAAAfrGeoCreationWkb:CreateWorkbench() NewAccess(CATCmdWorkbench,pCAAAfrGeoCreationWkb,CAAAfrGeoCreationWkb); . / See Creatin

50、g 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 theworkbench identifier must be identical

51、 to take into account the workbench resources in the Start menu.8They 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 Creati

52、ng Resources for Workbenches. .2 创建 containers. NewAccess(CATCmdContainer,pCAAAfrSolidEltTlb,CAAAfrSolidEltTlb); SetAccessChild(pCAAAfrGeoCreationWkb, pCAAAfrSolidEltTlb); . / See Creating the Solids Toolbar Content AddToolbarView(pCAAAfrSolidEltTlb,1,Right); NewAccess(CATCmdContainer,pCAAAfr

53、SurfacicEltTlb,CAAAfrSurfacicEltTlb); SetAccessNext(pCAAAfrSolidEltTlb,pCAAAfrSurfacicEltTlb); . / See Creating the Surfaces Toolbar Content AddToolbarView(pCAAAfrSurfacicEltTlb,-1,Right); NewAccess(CATCmdContainer,pCAAAfrGeoCreationMbr,CAAAfrGeoCreationMbr); . / See Creating the Menu Bar Content Se

54、tWorkbenchMenu(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

55、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 u

56、sing 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

57、theSetAccessNext macro. It is invisible (-1 means invisible) by default, and is also docked at the right side ofthe 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 CAAAfrGeoC

58、reationMbr and is used for its resources. It is set as the workbench's menu bar using the SetWorkbenchMenu macro.9The 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

59、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 identifie

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论