3D PLM PPR Hub Open Gateway

Product Modeler

Adding a Toolbar to the Product Structure Workbench

Implementing the CATIPrsConfigurationAddin Interface

Use Case

Abstract

This article presents the CAAPuiPrsConfigAddin use case which illustrates how to create a toolbar that is active in the Product Structure workbench.


What You Will Learn With This Use Case

By implementing the CATIPrsConfigurationAddin, a toolbar with its commands can be made active in the Product Structure workshop. For a toolbar to be active in any Product Structure workshop, please refer to article [6].

[Top]

The CAAPuiPrsConfigAddin Use Case

CAAPuiPrsConfigAddin is a use case of the CAAProductStructureUI.edu framework that illustrates the ProductStructureUI framework capabilities.

[Top]

What Does CAAPuiPrsConfigAddin Do

The goal of CAAPuiPrsConfigAddin is to demonstrate how to implement the CATIPrsConfigurationAddin interface. It consists of the following parts:

Our toolbar appears on top of the CATIA frame and contains a single command represented by the icon.

[Top]

How to Launch CAAPuiPrsConfigAddin

To launch CAAPuiPrsConfigAddin:

  1. Set the current directory to InstallRoot/CAAProductStructureUI.edu
  2. Set up  the build time environment and build the CAAPuiPrsConfigAddin.m module (see reference [1])
  3. Edit the  CNext/code/dictionary/CAAProductStructureUI.edu.dico dictionary by uncommenting the line containing CATIPrsConfigurationAddin
    # CAAPuiPrsConfigAddin use case
    #CAAPuiPrsConfigAddin CATIPrsConfigurationAddin libCAAPuiPrsConfigAddin
  4. Install the dictionary and other resource files by executing mkCreateRuntimeView
  5. Start CATIA by executing mkrun
  6. Display the toolbar named "Toolbar 2" if necessary:



     
  7. Click on the command and a dialog box will appear:


     

[Top]

Where to Find the CAAPuiPrsConfigAddin Code

CAAPuiPrsConfigAddin code is located in the CAAPuiPrsConfigAddin.m module of the CAAProductStructureUI.edu framework.

[Top]

Step-by-Step

There are three parts in CAAPuiPrsConfigAddin:

  1. Toolbar Creation and Layout
  2. Command Implementation
  3. User Interface

We will now detail each of those sections:

[Top]

Toolbar Creation and Layout

The implementation of CATIPrsConfigurationAddin is provided by our CAAPuiPrsConfigAddin class. Its purpose is to create the toolbar and to do the layout the commands on it. Only two methods need be defined: CreateToolbars and CreateCommands.

...
class CAAPuiPrsConfigAddin: public CATBaseUnknown {

CATDeclareClass;

public:

        // Standard constructors and destructors for an implementation class
        // -----------------------------------------------------------------
        CAAPuiPrsConfigAddin();
        virtual ~CAAPuiPrsConfigAddin();

        /**
         * @see ApplicationFrame.CATIWorkbenchAddin#CreateToolbars
         */
        CATCmdContainer * CreateToolbars();

        /**
         * @see ApplicationFrame.CATIWorkbenchAddin#CreateCommands
         */
        void CreateCommands();

private:
        // The copy constructor and the equal operator must not be implemented
        // -------------------------------------------------------------------
        CAAPuiPrsConfigAddin(CAAPuiPrsConfigAddin &);
        CAAPuiPrsConfigAddin& operator=(CAAPuiPrsConfigAddin&);

};
...

The purpose of the CreateToolbars method is to create all the command headers of our toolbar. In this case a toolbar named CAAToolbar with a command named CAAPuiPrsConfigAddinCmd1 is created.

...
CATCmdContainer * CAAPuiPrsConfigAddin::CreateToolbars ()
{
        CAAPuiPrsConfigAddinTRACE(">> CAAPuiPrsConfigAddin::CreateToolbars()");

        // Declaration of toolbar for Addin
        NewAccess(CATCmdContainer, pToolbarContainer,
                  CAAPuiPrsConfigAddinToolbar);
        NewAccess(CATCmdStarter, pCommandStarter,
                  CAAPuiPrsConfigAddinStarter);

        // Arranging the command within the toolbar
        SetAccessCommand(pCommandStarter, "CAAPuiPrsConfigAddinCmd1");
        SetAccessChild(pToolbarContainer, pCommandStarter);

        int visibleFlag = 1;
        AddToolbarView (pToolbarContainer, visibleFlag, Top);

        CAAPuiPrsConfigAddinTRACE("<< CAAPuiPrsConfigAddin::CreateToolbars()");
        return pToolbarContainer;
}

...

The purpose of the CreateCommands method is to create all the command headers of our toolbar. Instead of using the MacDeclareHeader macro to define the CAAPuiPrsConfigAddinHeader command header class (like in the Creating a Product Workbench and Adding a Toolbar to all Product Workbenches use cases), it is defined "manually" with extra code to handle ENOVIA LCA integration. Please refer to article [7] for more information.

Here a command named CAAPuiPrsConfigAddinCmd1 is created. It is located in the CAAPuiPrsConfigAddin shared library and its class is CAAPuiPrsConfigAddinCmd. The ShowProduct identifier will be used to locate resources related to this command.

...

#include "CAAPuiPrsConfigAddinHeader.h"

...

void CAAPuiPrsConfigAddin::CreateCommands ()
{
        CAAPuiPrsConfigAddinTRACE(">> CAAPuiPrsConfigAddin::CreateCommands()");

        // Instantiates the command header for the command
        new CAAPuiPrsConfigAddinHeader
                ("CAAPuiPrsConfigAddinCmd1", // command name
                 "CAAPuiPrsConfigAddin",     // lib name
                 "CAAPuiPrsConfigAddinCmd",  // class name
                 (void*) NULL);

        CAAPuiPrsConfigAddinTRACE("<< CAAPuiPrsConfigAddin::CreateCommands()");
}
...

[Top]

Command Implementation

The command that gets executed must be of a class named CAAPuiPrsConfigAddinCmd as specified by CAAPuiPrsConfigAddin::CreateCommands. This class must also derives from the CATCommand class. The only method we need to override is the Activate method.

...
class CAAPuiPrsConfigAddinCmd: public CATCommand {

public:

        CAAPuiPrsConfigAddinCmd();
        virtual ~CAAPuiPrsConfigAddinCmd();

        /**
         * Activates our command.
         * @param iFromClient 
         * The command that requests to activate the current one.
         * @param iEvtDat
         * The notification sent.
         */
        virtual CATStatusChangeRC Activate(CATCommand * iFromClient,
                                           CATNotification * iEvtDat);
};
...

In the Activate method, we just get the current window and display its title in a dialog box

...
CATStatusChangeRC CAAPuiPrsConfigAddinCmd::Activate(CATCommand *iFromClient, 
CATNotification *iEvtDat)
{
        CAAPuiPrsConfigAddinTRACE (">> CAAPuiPrsConfigAddinCmd::Activate");

        CATApplicationFrame *pApplication = CATApplicationFrame::GetFrame(); 
        if (NULL != pApplication) { 
                CATDlgWindow * pMainWindow = pApplication->GetMainWindow();
                CATDlgNotify *pNotifyDlg = new CATDlgNotify
                        (pMainWindow, "CAAPuiPrsConfigAddin", CATDlgNfyOK);
                if (NULL != pNotifyDlg) {
                        pNotifyDlg->DisplayBlocked
                                ("Hello World!",
                                 "CAAPuiPrsConfigAddin UseCase");
                        pNotifyDlg->RequestDelayedDestruction(); 
                }
        }
        RequestDelayedDestruction();

        CAAPuiPrsConfigAddinTRACE ("<< CAAPuiPrsConfigAddinCmd::Activate");
        return CATStatusChangeRCCompleted;
}
...

Now that we have completed the code implementation, we need to take care of the user interface with the help of resource files.

[Top]

User Interface

There are two visible objects: the toolbar and its command.

The title of the toolbar named CAAPuiPrsConfigAddinToolbar is defined by the CAAPuiPrsConfigAddin.CATNls which can be found in install_root/CAAProductStructureUI.edu/CNext/resources/msgcatalog directory.

CAAPuiPrsConfigAddinToolbar.Title = "Toolbar 2";

The resources of the CAAPuiPrsConfigAddinCmd1 are defined by three files:

  1. CAAPuiPrsConfigAddinHeader.CATNls (located in the install_root/CAAProductStructureUI.edu/CNext/resources/msgcatalog directory):

    CAAPuiPrsConfigAddinHeader.CAAPuiPrsConfigAddinCmd1.Title = "cmd2";
    CAAPuiPrsConfigAddinHeader.CAAPuiPrsConfigAddinCmd1.Help = "cmd2 long help text";
    CAAPuiPrsConfigAddinHeader.CAAPuiPrsConfigAddinCmd1.ShortHelp = "cmd2 info";


    These texts correspond to the screen tip, the documentation line and the command prompt input:

     

  2. CAAPuiPrsConfigAddinHeader.CATRsc (located in the install_root/CAAProductStructureUI.edu/CNext/resources/msgcatalog directory) defines the bitmap name for the command icon:

    CAAPuiPrsConfigAddinHeader.CAAPuiPrsConfigAddinCmd1.Icon.Normal="CAAPuiPrsConfigAddin_I";

     

  3. CAAPuiPrsConfigAddin_I.gif (located in the install_root/CAAProductStructureUI.edu/CNext/resources/graphic/icons/normal directory) contains the bitmap the command icon:

     

[Top]


In Short

This use case has demonstrated how to create a toolbar with a command:

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[2] Application Frame Overview
[3] The CAA Command Model
[4] Creating an Add-in
[5] Creating a Product Workbench
[6] Adding a Toolbar to all Product Workbenches
[7] Integration with ENOVIA LCA
[Top]

History

Version: 1.2 [Aug 2004] Document revised
Version: 1.1 [Feb 2004] "Integration with ENOVIA LCA" reference added
Version: 1 [Oct 2003] Document created
[Top]

Copyright © 2003, Dassault Systèmes. All rights reserved.