3D PLM Enterprise Architecture

User Interfaces - Commands

Editing Object During a Command

How to stack a workbench using CATEditAgent class
Use Case

Abstract

This article shows how to use the CATEditAgent class to stack a workbench during a state command. In particular, it details how to edit a sketch during a Part command.


What You Will Learn With This Use Case

This use case is intended to show you how to use the CATEditAgent class to stack a workbench during a state command in order to edit an object. Activate this agent launches the specified workbench, and the end user comes back to the interrupted command by exiting the stacked workbench. After the edition, the edited object is set in the selection set (CATCSO). This use case explains how to:

[Top]

The CAAPriEditSketch Use Case

CAAPriEditSketch is a use case of the CAAPartInterfaces.edu framework that illustrates DialogEngine and ApplicationFrame framework capabilities.

[Top]

What Does CAAPriEditSketch Do

CAAPriEditSketch is a use case which edits a Pad. This command is integrated in a Part Design add-in. 

Fig.1: The Part Design Add-in

This add-in contains one toolbar (the "Frame tools" toolbar) which has one command the "Part Modification" command . This command enables the end user to edit a pad which has a sketch as profile.

Fig.2: The Part Modification Command
The "Pad Modification" command ( ) launches the "Pad Modification" dialog box. This dialog object contains the sketch icon () to edit the profile of the selected Pad. The name of the profile is displayed just beside the sketch icon. (here is it Sketch.1). The use case explains how the state command is awaked when the end user clicks the sketch icon, and how the Sketcher workbench can be launched. 

When the sketch icon  is pushed, the Sketcher workbench is launched. Only a set of commands are available. 

Fig.3: The Sketcher Workbench
The Sketcher workbench is active until the end user clicks the exit ( ) command. The sketch associated with the Pad can be modified. The available commands are some global commands, such as Exit, Center Graph, Print ..., but only three specific commands to the Sketcher workbench:

The "Part Modification" command is a state command which uses the CATEditAgent. Its UML statechart diagram [1] is the following:

Fig.4: The UML state chart for the Part Modification Command

[Top]

How to Launch CAAPriEditSketch

To launch CAAPriEditSketch , you will need to set up the build time environment, then compile CAAPriEditSketch along with its prerequisites, set up the run time environment, and then execute the use case [2].

But just before launching the execution, edit the CAAPartInterfaces.edu.dico interface dictionary file located in the dictionary directory of the CAAPartInterfaces.edu framework:

Windows InstallRootDirectory\CAAPartInterfaces.edu\CNext\code\dictionary\
UNIX InstallRootDirectory/CAAPartInterfaces.edu/CNext/code/dictionary/

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

In this file, remove the "#" character before the two following lines:

...
#CAAPriPrtCfgAddin     CATIPrtCfgAddin             libCAAPriPrtCfgAddin
#CAAPriPrtCfgAddin     CATIWorkbenchAddin          libCAAPriPrtCfgAddin
...

Then, in the window where you run the mkrun command, do not type the module name on the command line, but type CNEXT instead. When the application is ready, do the following:

 

[Top]

Where to Find the CAAPriEditSketch Code

The CAAPriEditSketch use case is made of several classes located 

[Top]

Step-by-Step

There are five logical steps in CAAPriEditSketch:

  1. Creating the Edit Agent 
  2. Creating Agent to Trigger the Sketcher Workbench Activation
  3. Creating States
  4. Creating Transitions
  5. Providing the Object to Edit

[Top]

Creating the Edit Agent 

The edit agent is a dialog agent created as usual in the BuildGraph method [4] of a state command.

...
   _pEditAgent = new CATEditAgent("EditAgentId");
...

Once the edit agent is created, you have to specify the following information:

All these methods can be called outside the BuildGraph method, and can be called several times once the edit agent is created. There are information used each time the edit agent is activated. 

[Top]

Creating Agent to Trigger the Sketcher Workbench Activation

You are always in the BuildGraph method of the CAAPriEditSketchCmd state command.

...
        _pTriggerAgent = new CATDialogAgent("TriggerAgentid");
        _pTriggerAgent->AcceptOnNotify(_pDialogBox,"CAAPriEditSketchNotification");
...

_pTriggerAgent, a data member of the CAAPriEditSketchCmd class, is a CATDialogAgent class instance . It is created in the BuildGraph method, and released in the class destructor thanks to the RequestDelayedDestruction method. 

TriggerAgentid is the agent identifier. This name is used to retrieve the undo/redo titles in the command resource file. This file is located in the CNext/resources/msgcatalog directory of the CAAPartInterfaces.edu framework.  This agent is valuated when the CAAPriEditSketchDlg dialog box sends a CAAPriEditSketchNotification notification. 

This agent is important as it is explained in the next sections. 

[Top]

Creating States

After the agent creations, the second step of a BuildGraph method is to create the states. The Fig.4 shows the UML diagram of the CAAPriEditSketchCmd state command. There are two important states:

The first one, InputPadState, which enables the end user to select a Pad, is outside the scope of this use case and therefore, not explained.

DialogState

...
        CATPanelState * pDialogState = new CATPanelState(this,"DialogStateId",_pDialogBox);
        if ( NULL != pDialogState )
        {
           AddDialogState(pDialogState);
           pDialogState->AddDialogAgent(_pTriggerAgent); 
        }
...

The DialogStateId state is a CATPanelState class. This class creates agents to react to the end user action on Ok and Cancel buttons of the dialog box given as argument. Refer to the specific article to understand this class [7]. On this state, _pTriggerAgent has been added. pDialogState must be released at the end of the BuildGraph method.

EditSketchState

...
        CATDialogState * pEditSketchState = AddDialogState("EditSketchStateId");
        if ( NULL != pEditSketchState )
        {
           pEditSketchState->AddDialogAgent(_pEditAgent);
        }
...

The EditSketchStateId is a simple CATDialogState class created by the AddDialogState method. The only one agent associated with this state is _pEditAgent the edit agent. pEditSketchState will be automatically released at the end of the command.

The CATEditAgent dialog agent is itself a CATStateCommand class. A state command used as agent must always be the unique agent of a state.  It is the reason for which the _pTriggerAgent is important. It enables to activate the EditSketchState state, since it will be not possible to associate with the DialogState state the _pEditAgent agent. 

[Top]

Creating Transitions

The last step of a BuildGraph method is to create transitions. There are the following transitions Fig.4:

From DialogState to EditSketchState

...
           CATDialogTransition * pEditSketchTransition = AddTransition(pDialogState,pEditSketchState,
                    IsOutputSetCondition(_pTriggerAgent),
                    Action((ActionMethod) & CAAPriEditSketchCmd::TriggerEditSketch));   
...

From EditSketchState to DialogState

...
           CATDialogTransition * pBackTransition = AddTransition(pEditSketchState,pDialogState,
                    IsOutputSetCondition(_pEditAgent),
                    Action((ActionMethod) & CAAPriEditSketchCmd::EditSketch)); 
...

[Top]

Providing the Object To Edit

The ProvideProfileToEdit method is called each time the edit agent is activated. The goal of this method is to provide the object to edit by the edit agent. This object will be set in the selection set (CATCSO) when the edit agent will reach the final state. The value returned by this method is released by the edit agent. Once the ProvideProfileToEdit method is called, the GetValue method of the CATEditAgent class returns it. 

...
CATPathElement * CAAPriEditSketchCmd::ProvideProfileToEdit(CATClassId iDummy)
{
   CATPathElement * pPathToReturn = NULL ;

   if ( (NULL == GetEditor()) || (NULL == _pFeatureAgent) ) return NULL ;

   CATBaseUnknown * pSelectedElt= _pFeatureAgent->GetElementValue();

   CATISpecObject * pISpecObjectOnProfile = NULL ;
   HRESULT rc = FindProfile(pSelectedElt,&pISpecObjectOnProfile) ;

   if ( SUCCEEDED(rc) && (NULL!=pISpecObjectOnProfile))
   {
      CATIBuildPath *piBuildPath = NULL;
      rc = pISpecObjectOnProfile->QueryInterface( IID_CATIBuildPath, (void**) &piBuildPath );
                                                       
      if ( SUCCEEDED(rc) )
      {
         CATPathElement Context = GetEditor()->GetUIActiveObject();
         rc = piBuildPath->ExtractPathElement(&Context,&pPathToReturn);

         piBuildPath->Release();
         piBuildPath = NULL ;
      }
      
      pISpecObjectOnProfile->Release();
      pISpecObjectOnProfile = NULL ;
   }

   return pPathToReturn ;
}
...

In this use case, the object to return is the sketch associated with the selected pad. In fact, to be exact it is the complete path of this sketch: from the root (the MechanicalPart) to the sketch itself.

 _pFeatureAgent is the agent to select a Pad. It is a CATFeatureImportAgent filtered with the CATIPad interface. The GetElementValue method retrieves the selected pad. The local FindProfile method extracts from the pad its sketch. Refer to the code for details. pISpecObjectOnProfile is a CATISpecObject interface pointer on a sketch ( an object implementing CATISketch). The CATIBuildPath interface enables you to build the path from the root ( the context) to the sketch.

[Top]


In Short

This use case explains how to create a dialog agent to stack a workbench into a state command. This agent is a CATEditAgent .

[Top]


References

[1] Describing State Dialog Command Using UML
[2] Building and Launching a CAA V5 Use Case
[3] Creating an Add-in of the Part Design Workbench
[4] Implementing the Statechart Diagram
[5] Application Frame overview
[6] The Command Headers
[7] Associating a Dialog Box with a State
[Top]

History

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

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