3D PLM Enterprise Architecture |
User Interface - Frame |
Making Your Document Independent Command Available in All WorkbenchesUsing CATIAfrGeneralWksAddin |
Use Case |
AbstractThis article shows how to insert a document independent command in all workbenches of a V5 application. |
This use case is intended to show you how to create a toolbar and modify the menu bar to integrate your document independent command in all workbenches. You will learn to implement an interface, the CATIAfrGeneralWksAddin interface, which is an Add-in [1] of the "General" workshop [2]. This workshop contains the commands which are always available even if no document is open: New, Open, Cut,....
[Top]
CAAAfrGeneralWksAddin is a use case of the CAAApplicationFrame.edu framework that illustrates ApplicationFrame framework capabilities.
[Top]
The CAAAfrGeneralWksAddin creates an add-in to the General workshop. Is is made up of:
The General toolbar. It contains in first position the Search Demonstrator [3] command, then the Viewer Feedback demonstrator [9] command, and at last the "Add Item in MRU" command [11].
The Search Demonstrator command is included in the Edit menu, just before Search, whereas the Viewer Feedback demonstrator command is set in the View menu.
[Top]
To launch CAAAfrGeneralWksAddin , you will need to set up the build time environment, then compile CAAAfrGeneralWksAddin along with its prerequisites, set up the run time environment, and then execute the use case [4].
But just before launching the execution, edit the CAAApplicationFrame.edu.dico interface dictionary file located in the dictionary directory of the CAAApplicationFrame.edu framework:
Windows | InstallRootDirectory\CAAApplicationFrame.edu\CNext\code\dictionary\ |
UNIX | InstallRootDirectory/CAAApplicationFrame.edu/CNext/code/dictionary/ |
In this file, remove the "#" character before the two following lines:
... #CAAAfrGeneralWksAddin CATIWorkbenchAddin libCAAAfrGeneralWksAddin #CAAAfrGeneralWksAddin CATIAfrGeneralWksAddin libCAAAfrGeneralWksAddin ... |
and run mkCreateRuntimeView.
[Top]
The CAAAfrGeneralWksAddin use case is made of a single class named CAAAfrGeneralWksAdn located in the CAAAfrGeneralWksAddin.m module of the CAAApplicationFrame.edu framework:
Windows | InstallRootDirectory\CAAApplicationFrame.edu\CAAAfrGeneralWksAddin.m\ |
Unix | InstallRootDirectory/CAAApplicationFrame.edu/CAAAfrGeneralWksAddin.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
To create the add-in, you should create the module directory to store the add-in code along with its two subdirectories LocalInterfaces and src. For this example, this directory is named CAAAfrGeneralWksAddin.m and can be found in the CAAApplicationFrame.edu framework. Then you will need to create the following files.
In the CAAAfrGeneralWksAddin.m\LocalInterfaces directory: | |
|
The header file of the add-in description class |
In the CAAAfrGeneralWksAddin.m\src directory: | |
|
The header file of the add-in description class |
In the dictionary, that is the CNext\code\dictionary directory, referenced at run time using the CATDictionaryPath environment variable, create or update: | |
|
The interface dictionary |
In the CNext\resources\msgcatalog directory, referenced at run time using the CATMsgCatalogPath environment variable: | |
|
The add-in message file |
|
The command header resource files |
There are four logical steps in CAAAfrGeneralWksAddin:
# | Step | Where |
---|---|---|
1 | Create the add-in description class | LocalInterfaces and src |
2 | Create the command headers | CreateCommands method |
3 | Create the add-in and arrange the commands | CreateToolbars method |
4 | Provide the resources |
[Top]
#include "CATBaseUnknown.h" class CATCmdContainer; class CAAAfrGeneralWksAdn : public CATBaseUnknown { CATDeclareClass; public: CAAAfrGeneralWksAdn(); virtual ~CAAAfrGeneralWksAdn(); // Creates the command headers void CreateCommands(); // Arranges the commands in toolbars and menubar CATCmdContainer * CreateToolbars(); private : // Copy constructor, not implemented // Set as private to prevent from compiler automatic creation as public. CAAAfrGeneralWksAdn(const CAAAfrGeneralWksAdn &iObjectToCopy); // Assigment operator, not implemented // Set as private to prevent from compiler automatic creation as public. CAAAfrGeneralWksAdn & operator = (const CAAAfrGeneralWksAdn &iObjectToCopy); }; |
// Local Framework #include "CAAAfrGeneralWksAdn.h" // ApplicationFrame Framework #include <CATCreateWorkshop.h> // To use NewAccess - SetAccess - SetAccessChild ... // Declaration of a new Command Header Class #include "CATCommandHeader.h" // See Creating the Command Headers MacDeclareHeader(CAAAfrGeneralWksAddinHeader); CATImplementClass(CAAAfrGeneralWksAdn, DataExtension, CATBaseUnknown, CAAAfrGeneralWksAddin); #include <TIE_CATIAfrGeneralWksAddin.h> TIE_CATIAfrGeneralWksAddin(CAAAfrGeneralWksAdn); CAAAfrGeneralWksAdn::CAAAfrGeneralWksAdn() {} CAAAfrGeneralWksAdn::CAAAfrGeneralWksAdn() {} void CAAAfrGeneralWksAdn::CreateCommands() { ... // See Creating the Command Headers } CATCmdContainer * CAAAfrGeneralWksAdn::CreateToolbars() { ... // See Creating the Toolbar and Arranging the Commands } |
The CAAAfrGeneralWksAdn class states that it implements the CATIAfrGeneralWksAddin
interface thanks to the TIE_
CATIAfrGeneralWksAddin
macro. The
CATImplementClass
macro declares that the CAAAfrGeneralWksAdn
class is a data extension, thanks to the DataExtension
keyword,
that extends CAAAfrGeneralWksAddin. The third argument must always
be set as CATBaseUnknown or CATNull for any kind of extension.
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 CAAAfrGeneralWksAddin component implements the CATIAfrGeneralWksAddin interface, and whose code is located in the libCAAAfrGeneralWksAddin shared library or DLL.
|
Note that the component main class name is used to refer to the component in the interface dictionary, and never the extension class names. Note also that the shared library or DLL to associate with the component/interface pair is the one that contains the code created by the call to the TIE macro (This is generally the same library than the one that contains the interface implementation code, since the TIE macro is usually included in the extension class source file.) This is because when a client asks a component for an interface pointer, the TIE class is instantiated first, and it either retrieves the existing instance of the appropriate extension class, or otherwise instantiates it.
[Top]
Before reading this section, you can you refer to the "The Command Headers" article [5] to have an overview of the command header concepts, and more precisely you have the "Defining Headers in CATIAfrGeneralWksAddin implementations" section, which details the specificities of command headers created in this general add-in.
This is done by the CreateCommands
method. Each command
available in your add-in should be represent by a command header. A command header is an
instance of a command header class.
The command header class, named
CAAAfrGeneralWksAddinHeader, is created using the MacDeclareHeader
macro.
#include "CATCommandHeader.h" MacDeclareHeader(CAAAfrGeneralWksAddinHeader); |
The MacDeclareHeader
macro creates the header file and the
source file for the CAAAfrGeneralWksAddinHeader class, and associates with
this class the resource files CAAAfrGeneralWksAddinHeader.CATNls and
CAAAfrGeneralWksAddinHeader.CATRsc. See Providing the
Resources.
CreateCommands
method. This method should contain one instantiation statement of the
command header class per command header. Each statement has the following
form.
void CAAAfrGeneralWksAdn::CreateCommands() { ... new CAAAfrGeneralWksAddinHeader("CAAAfrSearchHdr", "CAACafSearch", "CAACafSearchCmd", (void *)NULL); ... } |
The command header constructor has the following arguments:
CAAAfrSearchHdr
is the identifier you need to assign to the command
header. It will be used afterwards:
CAACafSearch
is the name of the shared library or DLL containing the
Search Demonstrator command's code, without the prefix lib, and without
the suffix depending on the operating system.
CAACafSearchCmd
is the name of the Search Demonstrator command class
The command header associated with the Viewer Feedback demonstrator - see What Does CAAAfrGeneralWksAddin Do - is described in the use case [10].
The command header associated with the Most Recent Used header is described in the use case [11].
[Top]
Finally, we'll create the toolbar and arrange the commands. This is the job
of the CreateToolbars
method.
CATCmdContainer * CAAAfrGeneralWksAdn::CreateToolbars() { NewAccess(CATCmdContainer, pCAAAfrGeneralWksTlb, CAAAfrGeneralWksTlb); NewAccess(CATCmdStarter, pCAAAfrSearchStr, CAAMmrGeneralSearchStr); SetAccessCommand(pCAAAfrSearchStr, "CAAAfrSearchHdr"); SetAccessChild(pCAAAfrGeneralWksTlb, pCAAAfrSearchStr); NewAccess(CATCmdStarter, pCAAAfrViewerFeedbackStr, CAAAfrViewerFeedbackStr); SetAccessCommand(pCAAAfrViewerFeedbackStr, "CAAAfrViewerFeedbackHdr"); SetAccessNext(pCAAAfrSearchStr, pCAAAfrViewerFeedbackStr); NewAccess(CATCmdStarter, pCAAAfrMRUAddElementStr, CAAAfrMRUAddElementStr); SetAccessCommand(pCAAAfrMRUAddElementStr, "CAAAfrMRUAddElementHdr"); SetAccessNext(pCAAAfrViewerFeedbackStr, pCAAAfrMRUAddElementStr); AddToolbarView(pCAAAfrGeneralWksTlb, 1, Right); ... } |
Here is what's happen:
NewAccess
macro. pCAAAfrGeneralWksTlb
is the
variable used to handle the General toolbar command container instance
pointer, and CAAAfrGeneralWksTlb
is the identifier used to refer to it in
the add-in resource files. This identifier must be unique among all the
toolbar identifiers that can be found within the application [6].
The General toolbar default location is defined using the AddToolbarView
macro, where 1
means that the toolbar is visible by
default (-1
means invisible), and Right
means
that the toolbar is docked at the right side of the application window.
NewAccess
macro. pCAAAfrSearchStr
is the
variable used to handle a pointer to that instance, and CAAMmrGeneralSearchStr
is its identifier.
SetAccessCommand
macro. The second
parameter is the command header identifier defined as the
first parameter of the command header constructor. Refer to Creating
the Command Headers
SetAccessChild
macro or next of
the previous starter with the SetAccessNext
macro.
CATCmdContainer * CAAAfrGeneralWksAdn::CreateToolbars() { ... NewAccess(CATCmdContainer,pCAAAfrGeneralWksMbr,CAAAfrGeneralWksMbr); NewAccess(CATCmdContainer,pCAAAfrGeneralEditMnu,CATAfrEditMnu); SetAccessChild(pCAAAfrGeneralWksMbr,pCAAAfrGeneralEditMnu); NewAccess(CATCmdStarter,pCAAAfrGeneralEditSearchStr,CAAAfrGeneralEditSearchStr); SetAccessChild(pCAAAfrGeneralEditMnu,pCAAAfrGeneralEditSearchStr); SetAccessCommand(pCAAAfrGeneralEditSearchStr,"CAAAfrSearchHdr"); SetAccessAnchorName(pCAAAfrGeneralEditSearchStr,"CATAfrEditSearchStr"); NewAccess(CATCmdContainer,pCAAAfrGeneralView,CATAfrView); SetAccessNext(pCAAAfrGeneralEditMnu,pCAAAfrGeneralView); NewAccess(CATCmdStarter,pCAAAfrGeneralViewFBStr,CAAAfrGeneralViewFBStr); SetAccessChild(pCAAAfrGeneralView,pCAAAfrGeneralViewFBStr); SetAccessCommand(pCAAAfrGeneralViewFBStr,"CAAAfrViewerFeedbackHdr"); SetAddinMenu(pCAAAfrGeneralWksTlb,pCAAAfrGeneralWksMbr); ... } |
Here is what's happen:
pCAAAfrGeneralWksMbr,
is created to receive two
menus:
CATAfrEditMnu
, the name of the
Edit menu. pCAAAfrGeneralEditMnu is a child of pCAAAfrGeneralWksMbr
CATAfrView
, the name of the View
menu. pCAAAfrGeneralView is the next of pCAAAfrGeneralEditMnu.
NewAccess
macro. pCAAAfrGeneralEditSearchStr
is the
variable used to handle a pointer to that instance, and CAAAfrGeneralEditSearchStr
is its identifier.
SetAccessCommand
macro. The second
parameter is the command header identifier defined as the
first parameter of the command header constructor. Refer to Creating
the Command Headers
In this case, a last macro has been used: NewAccessAnchorName
which enables you to locate the Search Demonstrator command
just before the Search command (CATAfrEditSearchStr
)
[5]
The container, pCAAAfrGeneralWksMbr
, declared as menu
thanks to the SetAddinMenu
method. The first argument of
this method, pCAAAfrGeneralWksTlb
, is the first chained
toolbar, those returned by the method- see the next section. The second
argument is the container itself pCAAAfrGeneralWksMbr
.
CATCmdContainer * CAAAfrGeneralWksAdn::CreateToolbars() { ... return pCAAAfrGeneralWksTlb; } |
The first chained toolbar, pCAAAfrGeneralWksTlb
, is
returned by this method.
[Top]
You should provide the resources for the toolbar, the menu and for all its commands. They are classified into the following:
The CAAAfrGeneralWksAdn.CATNls:
CAAAfrGeneralWksTlb.Title = "General" ; |
The CAAAfrGeneralWksAddinHeader.CATNls:
CAAAfrGeneralWksAddinHeader.CAAAfrSearchHdr.Category = "Edit" ; CAAAfrGeneralWksAddinHeader.CAAAfrSearchHdr.Title = "Search Demonstrator..." ; CAAAfrGeneralWksAddinHeader.CAAAfrSearchHdr.ShortHelp = "Search Demonstrator" ; CAAAfrGeneralWksAddinHeader.CAAAfrSearchHdr.Help = "Demonstrator of the Search CAA API" ; CAAAfrGeneralWksAddinHeader.CAAAfrSearchHdr.LongHelp = "Search Demonstrator This Command launches some queries on the current document. The result is put into the HSO." ; |
The CAAAfrGeneralWksAddinHeader.CATRsc:
CAAAfrGeneralWksAddinHeader.CAAAfrSearchHdr.Icon.Normal = "I_CAASearch" ; |
For the resources of the CAAAfrViewerFeedbackHdr command header, refer to the CAAAfrViewerFeedbackHdr use case [10].
[Top]
This use case explains how by implementing the CATIAfrGeneralWksAddin interface you can add your document independent command in all workbenches.
[Top]
Version: 1 [May 2003] | Document created |
[Top] |
Copyright © 2003, Dassault Systèmes. All rights reserved.