Catia 二次開發
CATIA V5在開發之初就遵循面向對象的設計思想(OO),構建了完全基於組件的體系結構(PPR: Products,Process,Resource),有效地解決了維護、管理、擴展的困難,並大量使用了最新的計算機技術和標准以及軟件工程技術,其中包括基於組件架構思想的JAVA BEAN 、COM/OLE、CORBA 技術和Web技術、C++語言、Visual Basic Journaling 、STEP-SDAI、XML、OpenGL等,這使CATIA V5具有與眾不同的鮮明的特點:數據結構單一,各個模塊全相關,某些模塊之間還是雙向相關;端到端的集成系統,擁有強大的專業應用擴展能力。
1.軟件組件結構(SCI: Software Component Infrastructure)的基本概念
軟件組件結構(SCI)是軟件工程繼過程模型和面向對象模型的下一代邏輯模型。面向對象技術已在許多重要應用中取得成功。
但是,隨着更多面向對象解決方法的開發和使用,很顯然的是,單單采用面向對象技術難以與軟件日益增長的復雜性抗衡。因為,對象只構成應用程序的一部分。它完全不能把握應用程序的結構(控制流)。只能通過重用類庫里有的類來實現有限的重用。但實際情況是,大量應用程序,特別是同一領域(DOMAIN)中的應用程序,分享相似的結構。不同的程序員使用不同的技術去把握和實現這些相似的結構。結果,這些結構並沒有經過通常的面向對象技術而被重用。
面向對象技術只能通過重用類庫已有的類來實現有限的重用,而軟件組件結構(SCI)提供了最高層次的代碼重用。
軟件組件結構(SCI:Software Component Infrastructure)有三個基本的概念:框架(FRAMEWORK)、組件(Component)和對象總線(Products Bus)。
組件(Component):是軟件的基本量子(單元)。組件既應當足夠小,以便於維護;又應足夠大,可具備相當的功能,可以被打包和插用。由於傳統的客戶/服務器應用不能應付軟件應用日益增加的復雜性。它們不能加入到即插即用的環境之中。組件的特征提供了將一個應用程序分成若干個組件的機制。每個組件提供了一個相當專門的功能,它向框架的其余部分描述自己,以便別的組件能夠訪問它的功能。描述是通過說明性語言如IDL實現的,它本質上是把組件的接口與實現分離開來。由於組件是可單獨維護、升級的,因此,組件不直接與別的組件通信是至關重要的。它必須通過使用框架或對象總線來實現組件之間的交互。
框架(FRAMEWORK):框架提供對所有應用程序有用的功能(如接口、存儲)。它提供了統一的總設計。框架是對相似應用程序集合的一個部分(統一但不完整)解決方案。開發者的任務是用這不完整的解決方案加上必要的代碼建立完整的應用。在領域(DOMAIN)內的一個應用包括不變部分和可變部分。不變部分由框架把握,一般可占到80%,可變部分由開發者把握,一般可占到20% 。開發者通過向框架添加變化部分的代碼把握其動作,而形成新的特定應用。框架根據是否針對特殊領域還是若干領域,可分為水平框架、垂直框架、復合文擋框架。
對象總線:對象總線是基本的中間件。它允許成千上萬能夠相互理解接口定義語言IDL的對象相互發生作用。這種作用對對象來說是完全透明的。對象總線把組件和框架的能力擴展到開放網絡和其它伙伴應用程序。它使成千上萬獨立的軟件單元在由不同操作系統、語言、硬件平台和編譯工具組成的環境下互相無縫地交互運作。對象總線不僅提供對象之間的連接,它還提供對在總線上所有對象都有用的核心服務集(對象服務)。如:生命周期服務程序、安全性、持久性、命名等。 通過組件構造/修改軟件,用框架把握軟件結構,用對象總線連接事務,支持即插即用(Plug & Play)功能的擴展。 2.CATIA V5體系結構(Architecture Infrastructure) CATIA V5的體系結構(Architecture Infrastructure)是一種面向行業應用的垂直框架體系結構,組件是CAD/CAM系統的各種幾何特征和管理、分析單元。框架是一些應用如:2D/3D建模、分析、混合建模、制圖、數控加工等,CATIA V5也稱為領域(DOMAIN)或應用(APPLICATION)。並通過3D PLM PPR(PRODUCTS,PROCESS, RESOURCE)HUB產品總線連接起來。
1、Application window和document window類似於mfc中的CMainFrame和CView的關系
2、workshop是workbench的一個集合
3、CATIWorkbenchTransition interface
4、CATApplicationFrame
5、CATFrmEditor 類起檢索按鈕是否可用的功能等
6、In Short
The CAA V5 application window includes commands which are common to all documents in menus and in the standard toolbar. Each document type is associated with a workshop which includes commands arranged in menus and toolbars which are added to the common menus and to the standard toolbar. Changing the active document to another document changes the active workshop if the new active document's type is different from the type of the previous document. A workshop can include workbenches to gather commands dedicated to specific tasks to structure the end user interface. One workbench only can be active at a time.
7、The application layout is provided by the non-exposed CATApplicationDocument class
8、The main methods of the CATApplicationFrame class are:
GetFrame This static method returns the unique instance of this class.
SetMessage To set a message in the status bar.
GetApplicationDocument This method returns the CATApplicationDocument class instance
GetMainWindow This method returns:
9、CATIDocumentEdit interface is used to create the default window to display the document
10、The CATFrmLayout Class
This class manages all the windows created. It
11、The CATFrmLayout class enables you to activate a new window
12、You have to respect only one rule: all the dialog objects must be inside a frame created by the CATFrmWindow class:
13、HRESULT CAAEMyInterface::CreateWindow()
{
1/ Creating the new window
2/ Managing the base name
3/ Declaring the window as current
}
...
14、In Short
This article enables you to understand the role of the main objects defining or managing the V5 interactive application.
CATApplicationFrame
This class has only one instance during the session. You essentially use it to retrieve the dialog parent of your dialog box.
CATFrmLayout
This class has only one instance during the session. Its role is to manage all the document windows. You use it to retrieve windows and to define the current one.
CATFrmEditor
This class controls the visualization and the interactivity of the document. It is the C, in the MVC paradigm, where M is the document and V the window.
CATFrmWindow
It is the base class of all the classes defining a window to display a document.
15、The CATApplicationFrame class
This CATApplicationDocument class instance is built by the CATApplicationFrame class instance.
The main methods of the CATApplicationFrame class are:
GetFrame This static method returns the unique instance of this class.
SetMessage To set a message in the status bar.
GetApplicationDocument This method returns the CATApplicationDocument class instance
GetMainWindow This method returns:
MyDialogBox will be automatically hidden when the editor will be deactivated. Therefore if you need a dialog box always visible, and independent of the life of the document, its parent must be the CATApplicationDocument class instance returned by the GetApplicationDocument method. You can also read the "Defining Headers in CATIAfrGeneralWksAddin Implementations" section in the technical article about the command headers
A property sheet is a tabbed dialog box, each tab containing a property page
This CATEditorManager object is used by the application to create and manage property pages
The CSO contents is retrieved and passed to the ExtractFromSelection method of each property editor
These methods are those of the CATIEditProperties interface and are either pure virtual or empty in their CATEditor implementation. You should provide their body to make them play the following role:
ExtractFromSelection returns the list of objects found in the Current Set of Objects (CSO) that implement the property interface
GetEditorTitle returns the property page title
SetEditorSize lets you request which size you need to accommodate your property page, among the possible values: small, medium, or large
BuildEditor instantiates the associated dialog class
SetPropertyValue sets the values and options in the property page dialog from the objects
CommitModification applies to the selected objects the modifications made to values and options in the property page dialog.
CancelModification is empty, but exists and could be used to delete temporary objects that could possibly be allocated in previous methods
CloseWindowFromEditor is called whenever the end user selects another property page.
The methods ExtractFromSelection, GetEditorTitle, SetEditorSize, BuildEditor, and SetPropertyValue are executed in this order when instantiating the property page.
When the end user clicks:
OK, the CommitModification method is executed and the window is closed
Apply, the CommitModification method is executed, but the window is not closed
Cancel, the CancelModification method is executed and the window is closed
Close, the window is closed.
SetPropertyValue, CommitModification, and CancelModification call in turn the methods with the same name of the associated dialog class.
Current Set of Objects (CSO),
In memory the setting file is represented by a setting repository, an instance of the CATSettingRepository class
A property page divided in sections
This dialog is a class that derives from CATDlgFrame
Creating a property page for the Tools/Options menu implies to create a property page editor factory, a property page editor class instantiated by this factory, and to supply a property page dialog class gathering the controls to access the parameters and values you let the end user access and modify.
Setting Attributes versus Parameters
The setting repository contains setting attributes accessible thanks to the ReadSetting and WriteSetting methods. Using these methods ties the code to the formats and locations of the attributes
Model View Controller (MVC
What Is a CAA Command?
A CAA command is an instance of a class deriving from the CATCommand class and that supports these interactive mechanisms:
Desactivate is called when a shared command takes the focus from the active command
A command header instance is always an instance of a class deriving from the CATCommandHeader class
To avoid to fill up uselessly the list of CATCommandHeader instances, it is recommended to make the command header instantiation only in the following methods because these methods are called once for each instance of editor: CreateCommands of the workbench implementations [4] CreateCommands of the add-in implementations (*) [5]
To create a standard command header class, you can use the MacDeclareHeader macro. It creates for you a class which derives from CATCommandHeader which is the base class for command headers and should never be directly instantiated.
This Dialog command contains:
The list of current entities. This list is always in this order:
The workshop defined by the frame application (CATAfrGeneralWks)
The current workshop (those of the current UI-active object)
The Add-ins of the current workshop
The current workbench
The Add-ins of the current workbench
The Dialog box must manage its life cycle. When the end user clicks the Close button, or the Close/Cancel buttons if they exist, the Dialog box is deleted (by a RequestDelayedDestruction on itself)
command header stands for a command and avoids to load the command when the end user does not require it. A command header is an instance of a command header class. This class can be used for several commands, and can be created either using a macro or explicitly if the command header should manage availability information or customize its representation.
It is possible to re-use command header identifiers, but there are two rules to respect:
In a workbench or in an add-in (workshop/workbench) avoid to use an identifier coming from another workbench or workbench's Add-in.
In a contextual menu do not use an identifier coming from a workbench or a workbench's Add-in, but only coming from the workshop or an workshop's add-in.
The "Workshop Exposition" command enables you to retrieve the command header identifiers.
There are two command header resource files:
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 file containing the icons and other resources that should not be translated. It suffixed by CATRsc
In Short
The command header resources are provided in two files whose names are the command header class, or the name set by the CATImplementHeaderResources macro in the command header cpp file. One file is for those that can be translated and is suffixed CATNls, the other for the icon names or pointer to a help file and is suffixed CATRsc. The resources are provided using keys built with the identifier of the object to which they apply.
In Short
The workshop resources are provided in two files whose names are the workshop identifier. One file is for those that can be translated and is suffixed CATNls, the other for the icon names and is suffixed CATRsc. The resources are provided using keys built with the identifier of the object to which they apply.
public class CATCommandHeader
Class to create a command header.
Role: Each command you want to make available in your workshop or workbench must have a command header. It holds the necessary information to load the command, such as the name of the shared library in which the command's executable code is located, the name of the command class, and the data to pass to the command's code when this command becomes the current one.
The command header has resources for each command to display, such as the command name shown to the end user, its ToolTip displayed in a balloon, it help message, and its icon. This enables the workshop or workbench to be displayed, that is loaded in memory, without any of its commands being itself loaded, except the default one, spares memory space, and improves performance. The end user can see the icons in the toolbars, the items in the menu bar, can ask for help on a given command, without the command being loaded. It is only when he/she clicks on the menu item or on the icon that the command code is actually loaded.
You cannot directly instanciate a CATCommandHeader, you must derive this class. The easiest way is using the MacDeclareHeader macro such that:
#include "CATCommandHeader.h"
MacDeclareHeader(MyHeader);
System Macro CATImplementClass
Macro CATImplementClass (Class,Typeofclass,Basemeta,Impmeta)
Declares an implementation or extension class.
Role: Declares that the current class is either an implementation or an extension class. The class must derive from CATBaseUnknown. Use this macro in the class source (.cpp) file in conjunction with CATDeclareClass in the class header file. End it with a semicolon.
System Macro CATDeclareClass
Macro CATDeclareClass (private)
Declares an implementation or extension class.
Role: Declares that the current class is either an implementation or an extension class. The class must derive from CATBaseUnknown. Use this macro in the class header file in conjunction with CATImplementClass in the class source (.cpp) file. End it with a semicolon.
--------------------------------------------------------------------------------
This object is included in the file: CATMacForIUnknown.h