CATIA二次开发.docx

上传人:b****8 文档编号:27977009 上传时间:2023-07-07 格式:DOCX 页数:25 大小:29.65KB
下载 相关 举报
CATIA二次开发.docx_第1页
第1页 / 共25页
CATIA二次开发.docx_第2页
第2页 / 共25页
CATIA二次开发.docx_第3页
第3页 / 共25页
CATIA二次开发.docx_第4页
第4页 / 共25页
CATIA二次开发.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

CATIA二次开发.docx

《CATIA二次开发.docx》由会员分享,可在线阅读,更多相关《CATIA二次开发.docx(25页珍藏版)》请在冰豆网上搜索。

CATIA二次开发.docx

CATIA二次开发

CATIA+CAA+二次开发详细教程

(1)-基础概念

CAA第一讲

CATIACAA第一讲:

基本概念

1.什么是组件?

CAA,全称ComponentApplicationArchitecture,组件应用架构。

这个东西对不搞软件的人来说可能很陌生,我也很陌生啊,原来光知道“面向对象的技术”就很牛逼了,“组件技术”难道更牛逼吗?

既然类和组件有着这么多类似的地方,那么传统的面向对象编程和面向组件编程有什么区别呢?

简单的说,面向对象关注的是组合在一个二进制可执行文件中的各个类的关系,而面向组件的编程关注的是在彼此独立的基础上模块之间的交互性,这种交互性使得你并不需要熟悉它们内部的工作原理。

这两种方法最基本的不同在于它们对最终的应用程序的观点。

在传统的面向对象编程中,尽管你可以精心的把所有的商业逻辑分布在不同的类中,一旦这些类被编译,它们就被固化成了一个巨大的二进制代码。

所有的类共享同一个物理单元(通常是一个可执行文件)、被操作系统认为是同一个进程,使用同一个地址空间以及共享相同的安全策略等等。

如果多个开发者在同一份代码上进行开发,他们甚至还要共享源文件。

在这种情况下,修改一个类可能会让整个项目被重新链接,并重新进行必要的测试,更严重的,还有可能要修改其他的类。

但是,在面向组件开发中,应用程序是由一系列可以互相交互的二进制模块组合而成的。

一个具体的二进制组件可能并不能完成什么工作。

有些组件是为了提供一些常规服务而编写的,例如通信的封装或者文件访问组件。

也有一些是为了某些特定应用而专门开发的。

一个应用程序的设计者可以通过把这些不同的组件提供的功能粘合在一起来实现他们需要的商业逻辑。

很多面向组件的技术——例如:

COM、J2EE、CORBA和.NET都为二进制组件提供了的无缝链接的机制。

而唯一的不同就是你需要在组件通信上花费的力气。

把一个二进制应用程序分解成不同的二进制组件的动机和把不同的类放到不同的文件中是类似的。

后者使得不同的类的开发人员可以彼此独立的工作,尽管即时修改了一个类也要重新链接整个应用程序,但是你只需要重新编译被修改的部分就可以了。

但是,面向组件的开发还是和简单软件项目的管理更复杂一些。

因为一个面向组件的应用程序是一个二进制代码块的集合,你可以把组件当作是LEGO的积木块一样,随心所欲的拆装它们。

如果你需要修改一个组件的实现,只需要修改那个组件就可以了,而组件的客户机不需要重新编译也不需要重新开发。

对于那些不常用到的组件,组件甚至可以在一个程序运行的时候被更新。

这些改进和增强使得组件可以立即进行更新,而所有该组件的客户都将立即受益。

无论是在同一台机器上还是通过网络远程访问。

面向组件的应用程序也更易于扩展。

当你需要实现新的需求的时候,你可以提供一个新的组件,而不去影响那些和新需求无关的组件。

这些特点使得面向组件的开发降低了大型软件项目长期维护的成本,这是一个最实际的商业问题,也正是如此,组件技术才如此迅速的被接受。

面向组件的应用程序通常可以更快的响应市场,因为你可以有很大的选择空间,不仅仅是自己开发的组件,还可以从第三方厂商来购买某些组件,从而避免了重复制造轮子。

这里,VB就是一个很好的例子,丰富的ActiveX控件使得很多人在快速开发中得到了享受。

1

用户界面开发——实例说明

——CreatingaWorkbench

一、目标

1.1目标

Showinghowtocreateaworkbenchtobeaddedtoagivenworkshop.

1.2显示界面(workbench)

Liketheworkshop,theworkbenchisanobjectthatgathersthecommandstoworkonthedocumentandarrangethemintoolbarsandmenus.

1.3命令标签(commandheader)

Commandheadersareusedtomakethelinkbetweentheworkbenchandthecommands.

二、CAAAfrGeoCreationWbench实例说明

2.1功能

TheCAAAfrGeoCreationWbenchusecasecreatesaworkbenchnamedCAAGeometricalCreationfortheCAAGeometrydocument.Itsspecificationscovermostofthecasesyouwillmeet.Twotoolbarsareprovided:

TheSolidstoolbar.Itincludesfivenewcommands:

Cuboid,Sphere,Torus,andCylinder1and2.TheSurfacestoolbar.Itincludesthreenewcommands:

RevolutionSurface,NurbsSurface,andOffsetSurface.TheonlychangeinthemenubaristheadditionofthesecommandsintheInsertmenuusingtwosubmenusbelowtheexistingones.

1

2.2运行

运行CATIA系统,并依次选择Start->Infrastructure->CAAV5:

GeometricalCreation:

ThiscreatesanewCAAGeometrydocumentwiththeCAAV5:

GeometricalCreationworkbenchactive.

2.3框架组成

CAAAfrGeoCreationWkbCAAAfrGeoCreationWkbFactoryCAAIAfrGeoCreationWkbFactoryWorkbenchdescriptionclassFactoryclassfortheworkbenchclassFactoryinterfaceimplementedbyCAAAfrGeoCreationWkbFactory

TIE_CAAIAfrGeoCreationWkbFactoryTIEclassforthefactoryinterfaceCAAIAfrGeoCreationWkbAddinAdd-ininterfaceexposedbytheworkbenchandthatallitsadd-insmustimplement

TIE_CAAIAfrGeoCreationWkbAddinTIEclassfortheadd-ininterface

三、程序结构(Step-by-Step)

3.1编程准备3.1.1确认

?

?

MakesurethattheworkshoptowhichitisdedicatedexposestheCATIxxxConfigurationinterface,wherexxxistheworkshopidentifier,inaPublicInterfacesorProtectedInterfacesdirectory.CreatethemoduledirectorytostoretheworkbenchcodealongwithitstwosubdirectoriesLocalInterfacesandsrc.Thenyouwillneedtocreatethefollowingfiles.Intheframework'sProtectedInterfacesdirectoryCAAIAfrGeoCreationWkbAddin.hTheheaderfileoftheworkbenchexposedinterfacetoenableclientstocreateadd-insIntheCAAAfrGeoCreationWbench.m\LocalInterfacesdirectoryCAAIAfrGeoCreationWkbFactory.hCAAAfrGeoCreationWkbFactory.hCAAAfrGeoCreationWkb.hTheheaderfileoftheworkbenchfactoryinterfaceTheheaderfileoftheworkbenchfactoryclassTheheaderfileoftheworkbenchdescriptionclass

IntheCAAAfrGeoCreationWbench.m\srcdirectoryCAAIAfrGeoCreationWkbAddin.cppCAAIAfrGeoCreationWkbFactory.cppCAAAfrGeoCreationWkbFactory.cppCAAAfrGeoCreationWkb.cppTIE_CAAIAfrGeoCreationWkbAddin.tsrcTIE_CAAIAfrGeoCreationWkbFactory.tsrcThesourcefileoftheworkbenchexposedinterfacetoenableclientstocreateadd-insThesourcefileoftheworkbenchfactoryinterfaceThesourcefileoftheworkbenchfactoryclassThesourcefileoftheworkbenchdescriptionclassThefiletocreatetheTIEforCAAIAfrGeometryWksAddinThefiletocreatetheTIEfor

2

CAAIAfrGeometryWksFactoryInthedictionary,thatistheCNext\code\dictionarydirectory,referencedatruntimeusingtheCATDictionaryPathenvironmentvariable,createorupdateCAAApplicationFrame.edu.dicoCAAApplicationFrame.edu.factCATMsgCatalogPathenvironmentvariableCAAAfrGeoCreationWkb.CATNlsCAAAfrGeoCreationWkbHeader.CATRscTheworkbenchmessagefileTheinterfacedictionaryThefactorydictionary

IntheCNext\resources\msgcatalogdirectory,referencedatruntimeusingthe

CAAAfrGeoCreationWkbHeader.CATNlsandThecommandheaderresourcefiles

3.1.2开发步骤

#2Createtheworkbenchfactory3Createtheworkbenchdescriptionclass4Createthecommandheaders5Createtheworkbenchandarrangethecommands6ProvidetheresourcesandinserttheworkbenchintotheStartmenu7CreatetheworkbenchexposedinterfaceStepWhereLocalInterfacesandsrcLocalInterfacesandsrcLocalInterfacesandsrc

CreateCommandsmethodCreateWorkbenchmethod

1Createtheworkbenchfactoryinterface

ResourcefilesProtectedInterfacesandsrc

3.2建立Workbench的FactoryInterface

(CreatingtheWorkbenchFactoryInterface)

3.2.1命名

CAAIAfrGeoCreationWkbFactory

3.2.2头文件(theheaderfile)

CAAIAfrGeoCreationWkbFactory.h

#includeexternIIDIID_CAAIAfrGeoCreationWkbFactory;classCAAIAfrGeoCreationWkbFactory:

publicCATIGenericFactory{CATDeclareInterface;public:

};

AfactoryinterfaceisaCAAinterface,thatis,anabstractclassthatderivesfromCATIGenericFactory.Asanyinterface,ithasanIIDdeclaredasIID_followedbytheinterfacename,andincludesthe

CATDeclareInterfacemacrothatdeclaresthatthisabstractclassisaninterface.Noadditional3

methodthanthoseofCATIGenericFactoryisnecessary.Don'tforgetthepublickeywordrequiredbytheTIEcompiler.(?

3.2.3源文件(Thesourcefile)

CAAIAfrGeoCreationWkbFactory.cpp

#includeIIDIID_CAAIAfrGeoCreationWkbFactory={0xb32eed10,0xd4c1,0x11d3,{0xb7,0xf5,0x00,0x08,0xc7,0x4f,0xe8,0xdd}};CATImplementInterface(CAAIAfrGeoCreationWkbFactory,CATIGenericFactory);

TheCATImplementInterfacemacroisusedinconjunctionwithCATDeclareInterfaceintheheaderfiletomakeaninterfacefromthisabstractclassandtodeclarethatitOM-derivesfromCATIGenericfactory.

3.2.4TIE文件(TheTIEtsrcfile)

TIE_CAAIAfrGeoCreationWkbFactory.tsrc

#include"CAAIAfrGeoCreationWkbFactory.h"

TheMulti-WorkspaceApplicationBuilder(mkmk)willgeneratetheTIEforthisinterfaceforyou,thatis,theTIE_CAAIAfrGeoCreationWkbFactory.hfileintheProtectedGenerateddirectory.

3.3建立Workbench的Factory

(CreatingtheWorkbenchFactory)

3.3.1注意事项

Thefactoryclassthatcreatesworkbenchinstancesmustconcatenatethenameoftheclasstoinstantiate,thatis,theworkbenchdescriptionclassCAAAfrGeoCreationWkb,withthestringFactory.ThisgivesCAAAfrGeoCreationWkbFactory.

3.3.2头文件

CAAAfrGeoCreationWkbFactory.h

#include"CATWorkshopConfigurationFactory.h"CATDeclareConfigurationFactory(CAAAfrGeoCreationWkb);

TheCATDeclareConfigurationFactorymacroargumentisthenameoftheworkbenchdescriptionclass.

4

3.3.3源文件

CAAAfrGeoCreationWkbFactory.cpp

#include#include#includeCATImplementConfigurationFactory(CAAAfrGeoCreationWkb,CAAIAfrGeoCreationWkbFactory);

TheCATImplementConfigurationFactoryargumentsarethenameoftheworkbenchdescriptionclassandthenameoftheworkbenchfactoryinterfacerespectively.The

CATDeclareConfigurationFactoryandCATImplementConfigurationFactorymacroscreatethe

workbenchfactoryimplementationclassasadataextensionoftheCATApplicationFramecomponent

3.3.4更新字典

3.3.4.1Theinterfacedictionarythatisafilewhosenameistheframeworknamesuffixedbydico,suchasCAAApplicationFrame.dico,andthatyoushouldcreateorupdateintheframeworkCNext/code/dictionarydirectory.TheinterfacedictionarycontainsthefollowingdeclarationtostatethattheCATApplicationFramecomponentimplementstheCAAIAfrGeoCreationWkbFactoryinterface,bymeansoftheextensionclasscreatedbythemacros,whosecodeislocatedinthelibCAAAfrGeoCreationWbenchsharedlibraryorDLL:

(不太明白)

CATApplicationFrameCAAIAfrGeoCreationWkbFactorylibCAAAfrGeoCreationWbench

3.3.4.2Thefactorydictionarythatisafilewhosenameistheframeworknamesuffixedbyfact,suchasCAAApplicationFrame.fact,andthatyoushouldcreateorupdateintheframeworkCNext/code/dictionarydirectory.ThefactorydictionarycontainsthefollowingdeclarationtostatethattheCAAIAfrGeoCreationWkbFactoryinterfaceisaninterfacetoafactorywhoseimplementationcreatesaCAAAfrGeoCreationWkbclassinstance:

CAAAfrGeoCreationWkbCAAIAfrGeoCreationWkbFactory

3.4定义与实现Workbench类

(CreatingtheWorkbenchDescriptionClass)

3.4.1说明

TheCAAAfrGeoCreationWkbclassimplementstheCATICAAAfrGeometryWksConfigurationinterfaceexposedbytheCAAGeometryworkshop.Itincludesthefollowingmethods:

?

?

?

CreateCommandstoinstantiatethecommandheadersforthecommandsoftheworkbenchCreateWorkbenchtocreatethecontainersfortheworkbench,themenus,andthetoolbars,and

arrangethecommandsinthemenusandtoolbars

GetCustomInterfaceswhichreturnsthenamesoftheinterfac

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 电子电路

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1