3D PLM Enterprise Architecture

User Interface - Frame

Inserting Commands in Contextual Menus

Implementing CATIContextualMenu
Use Case

Abstract

This article shows how to insert commands in the contextual menu when the Select command is the active one. 


What You Will Learn With This Use Case

This use case is intended to show you how insert commands in the contextual menu of an object when the Select command is the current command. So in other words this article explains how to implement the CATIContextualMenu  interface. 

[Top]

The CAACafContextualMenu Use Case

CAACafContextualMenu is a use case of the CAACATIAApplicationFrm.edu framework that illustrates CATIAApplicationFrame framework capabilities.

[Top]

What Does CAACafContextualMenu Do

CAACafContextualMenu enables you to display the following contextual menu when you right click on an Ellipse during  the Select command life:

This menu is separated in third parts: 

  1. The items added in the menu by the current window. Center Graph, Reframe On ... are items added by the CATFrmGraphAnd3DWindow class. This part is independent of the CATIContextualMenu implementation on the Ellipse. 
  2. The items defined in the contextual menu of the UIActive object [1] and added in the menu by the CATIContextualMenu implementation on the Ellipse 
  3. The items defined and added by the CATIContextualMenu implementation on the Ellipse in the menu

These two commands are Ellipse and Circle, two commands defined in the workshop of the "CAA Geometry" document. To reuse it, you should retrieve their command header identifiers [2].  The "Workshop Exposition" command enables you to find them.

Launch CATIA, when the application is ready:

In the CAAAfrGeometryWks.txt find out the "Ellipse " and "Circle" strings: 

The identifiers of the command header instances are the Id strings, so CAAAfrEllipseHdr and CAAAfrCircleHdr for the "Ellipse " and "Circle" commands respectively. These two identifiers will be associated with the starters of the menu. 

[Top]

How to Launch CAACafContextualMenu

See the section entitled "How to Launch the CAAGeometry Use Case" in the "The CAAGeometry Sample" use case for a detailed description of how this use case should be launched. For the specific scenario :

[Top]

Where to Find the CAACafContextualMenu Code

The CAACafContextualMenu use case is made of one single class, the CAAECafContextualMenuEllipse class, located in the CAACafContextualMenu.m module of the CAACATIAApplicationFrm.edu framework:

Windows InstallRootDirectory\CAACATIAApplicationFrm.edu\CAACafContextualMenu.m\
Unix InstallRootDirectory/CAACATIAApplicationFrm.edu/CAACafContextualMenu.m/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

To implement the CATIContextualMenu interface, there are two steps: 

  1. Creating the Contextual Menu Description Class
  2. Creating the Contextual Menu 

[Top]

Creating the Contextual Menu Description Class

  1. Create the CAAECafContextualMenuEllipse.h file
  2. #include "CATExtIContextualMenu.h"
    
    class CAAECafContextualMenuEllipse : public CATExtIContextualMenu
    {
      CATDeclareClass;
    
      public:
    
        CAAECafContextualMenuEllipse();
        virtual ~CAAECafContextualMenuEllipse();
    
      private:
        CAAECafContextualMenuEllipse(const CAAECafContextualMenuEllipse &iObjectToCopy);
        CAAECafContextualMenuEllipse& operator = (const CAAECafContextualMenuEllipse
                                                               &iObjectToCopy);
    
    };

    The implementation class derives from the CATExtIContextualMenu adapter class.

  3. Create the CAAECafContextualMenuEllipse.cpp file
  4. #include "CAAECafContextualMenuEllipse.h"
    #include "CATCreateWorkshop.h"
    
    CATImplementClass(CAAECafContextualMenuEllipse, 
                            DataExtension,CATBaseUnknown,
                            CAASysEllipse);
    
    #include "TIE_CATIContextualMenu.h"
    TIE_CATIContextualMenu(CAAECafContextualMenuEllipse);
    ...

    The CAAECafContextualMenuEllipse class states that it implements the CATIContextualMenu interface thanks to the TIE_CATIContextualMenu macro. The CATImplementClass macro declares that the CAAECafContextualMenuEllipse class is a data extension, thanks to the DataExtension keyword, that extends CAASysEllipse. The third argument must always be set as CATBaseUnknown or CATNull for any kind of extension.

    ...
    CAAEMmrCombinedCurveContSubMenu::CAAEMmrCombinedCurveContSubMenu()
                          				   
    {
        Creating the Contextual Menu
    }
    
    CAAEMmrCombinedCurveContSubMenu::~CAAEMmrCombinedCurveContSubMenu()
    {
    }
    

    The constructor contains the main code, and the destructor is empty.

  5. Updating the Interface Dictionary
  6. Update the interface dictionary, that is a file named, for example, CAACATIAApplicationFrm.dico, whose directory's pathname is concatenated at run time in the CATDictionaryPath environment variable, and containing the following declaration to state that the CAASysEllipse component implements the CATIContextualMenu interface, and whose code is located in the libCAACafContextualMenu shared library or DLL.

    CAASysEllipse CATIContextualMenu libCAACafContextualMenu

Creating the  Contextual Menu 

In this use case, the contextual menu associated with the UIActive object is first retrieved. It is possible thanks to the GetContextualMenu method of the adapter class. This menu, pMenu, is completed with the two commands (Circle and Ellipse). A separator is also added.

   ...
   CATCmdContainer * pMenu = NULL ; 

   CATExtIContextualMenu::GetContextualMenu(pMenu);

   if ( NULL != pMenu )
   {
      NewAccess(CATCmdStarter,pStEllipse,CAACafContextualMenuEllipseStr);
      NewAccess(CATCmdStarter,pStCircle,CAACafContextualMenuCircleStr);
      NewAccess(CATCmdSeparator,pSep1,CAACafContextualMenuSep);

      SetAccessCommand(pStEllipse,"CAAAfrEllipseHdr");
      SetAccessCommand(pStCircle,"CAAAfrCircleHdr");
      
      AddAccessChild(pMenu,pStEllipse);
      
      SetAccessNext(pStEllipse,pStCircle);
      SetAccessNext(pStCircle,pSep1);

      
   }
   ...

The menu, pMenu, is completed thanks macros contained in the CATCreateWorkshop file:

The picture below shows _pMenu before and after :

Note1 : The GetContextualMenu method returns a pointer on a CATCmdContainer instance class. The CATExtIContextualMenu class keeps this pointer, and at the CATExtIContextualMenu class instance destruction, the container and the accesses created in this current implementation will be released.

Note2 : In this use case, the contextual menu of the UIActive object has been retrieved and completed. But it is also possible to create your own contextual menu. You overwrite the GetContextualMenu method which returns your own CATCmdContainer class instance. This instance will be created in the constructor (if constant menu) or in the GetContextualMenu  method (if variable menu). 

Note3: A CATCmdContainer class instance destruction (by a Release call) implies automatically the destruction of its children.

[Top]


In Short

This use case explains how to implement a contextual menu and how to retrieve command header identifiers.

[Top]


References

[1] Application Frame Overview
[2] The Command Headers
[Top]

History

Version: 1 [Fev 2003] Document created
[Top]

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