3D PLM Enterprise Architecture

User Interface - Frame

Editing Objects

Make your objects editable
Use Case

Abstract

This article shows how to make an object editable, and how to create the associated dialog.


What You Will Learn With This Use Case

This use case is intended to show how to create make an object editable, and which object to provide to edit it.

[Top]

The CAAAfrGeoEdition Use Case

CAAAfrGeoEdition is a use case of the CAAApplicationFrame.edu framework that illustrates the ApplicationFrame framework capabilities.

[Top]

What Does CAAAfrGeoEdition Do

The CAAAfrGeoEdition use case makes the Point object an editable object, and provides it with an editing command and an editing dialog.

CAAAfrPointEditMenu.gif (27004 bytes)

[Top]

How to Launch CAAAfrGeoEdition

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 :

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 CAAAfrGeoEdition Code

The CAAAfrGeoEdition use case is made of three classes located in the CAAAfrGeoEdition.m module of the CAAApplicationFrame.edu framework:

Windows InstallRootDirectory\CAAApplicationFrame.edu\CAAAfrGeoEdition.m\
Unix InstallRootDirectory/CAAApplicationFrame.edu/CAAAfrGeoEdition.m/

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

These classes are:

CAAEAfrEditPoint Extension class for the CAASysPoint component
CAAAfrPointEditCmd Editing command class
CAAAfrPointEditDlg Dialog class associated with the editing command class

[Top]

Step-by-Step

To make an object editable, there are three steps:

# Step Where
1 Make the point object implement the CATIEdit interface CAAEAfrEditPoint class
2 Create the editing command CAAAfrPointEditCmd class
3 Create the editing dialog CAAAfrPointEditDlg class

[Top]

Making the Point Object Implement the CATIEdit Interface

The CATIEdit interface mainly provides the Activate method that should return the CATCommand class instance that actually enables the object edition. Activate is called whenever the end user intends to edit the object by double clicking or through the object's contextual menu.

To make the CAASysPoint component implements the CATIEdit interface, we create a class that derives from the CATExtIEdit adapter class as a data extension of the CAASysPoint class, and that provides code for the Activate method. The other methods of the CATIEdit interface are inherited from CATExtIEdit.

  1. Create the header file for the CAAEAfrEditPoint class
    #include "CATExtIEdit.h"   //Needed to derive from CATExtIEdit
    
    class CAAEAfrEditPoint : public CATExtIEdit
    {
      CATDeclareClass;
      public :
        CAAEAfrEditPoint();
        virtual ~CAAEAfrEditPoint();
        virtual CATCommand  * Activate(CATPathElement * iPath);
      private :
        CAAEAfrEditPoint(const CAAEAfrEditPoint &iObjectToCopy);
    };

    The CATDeclareClass macro declares that CAAEAfrEditPoint belongs to a component. It only redefine the Activate method of CATIEdit.

  2. In the class source file, insert the object modeler part
    ...
    CATImplementClass(CAAEAfrEditPoint,
                      DataExtension,
                      CATBaseUnknown,
                      CAASysPoint);
    
    #include "TIE_CATIEdit.h"
    TIE_CATIEdit(CAAEAfrEditPoint);
    ...

    The CATImplementClass macro reads: CAAEAfrEditPoint is a data extension of CAASysPoint. The third argument must always be set as CATBaseUnknown or CATNull for any kind of extension. The TIE macro creates the TIE class for the CATIEdit interface.

  3. Implement the Activate method
    ...
    CATCommand * CAAEAfrEditPoint::Activate(CATPathElement * pPath)
    {
      CAAAfrPointEditCmd *  pEdtCmd = NULL;
      CAAISysPoint * pISysPointOnPoint = NULL;                
      HRESULT rc = QueryInterface(IID_CAAISysPoint, (void**)&pISysPointOnPoint);
      if (SUCCEEDED(rc))
      {
        CAAAfrPointEditCmd *  pEdtCmd = new CAAAfrPointEditCmd(pISysPointOnPoint);
        pISysPointOnPoint->Release();
      }
      return (CATCommand*) pEdtCmd;
    }

    The Activate method:

[Top]

Creating the Editing Command

The point editing command is named CAAAfrPointEditCmd and directly derives from CATCommand. In addition to the three methods inherited from CATCommand and redefined to manage its availability and lifecycle, that is, Activate, Desactivate, and Cancel, the command has also the CloseBox method that is called when the end user closes the dialog box to request the dialog destruction. The command data members are a pointer to the dialog and a pointer to the CAAISysPoint interface.

The CAAAfrPointEditCmd.cpp file is as follows. Let's examine its body in an event driven way.

[Top]

Creating the Editing Dialog

The editing command is the dialog box created using the Activate method of the CATIEdit interface implementation. It highly depends on the object to edit and is designed and coded as any other dialog box, that is with an empty constructor and a Build method. The dialog box for the CAASysPoint class is as follows:

CAAAfrPointEditor.jpg (9014 bytes) This dialog box shows three spinners to display and change the point x, y, and z coordinates. The OK button applies the new parameter values and closes the dialog box. The Apply button only applies the new parameter values, but the dialog box remains displayed. The Cancel button closes the window and restores the coordinate initial values.

The CAAAfrPointEditDlg class derives from the CATDlgDialog class, which is the base class for all dialog boxes. The constructor takes a pointer to the CAAISysPoint interface. This is the main interface implemented by the object, and this pointer will be useful to get the object's parameter values to build the dialog box, and to modify the object when the end user clicks OK or Apply.

The Build method creates the controls, arranges them in the dialog box, and sets the labels and numerical values from resource files or using the pointer to the CAAISysPoint interface. It sets the callbacks for the OK, Apply, and Cancel push buttons, and for the window closing event, that is, ClickOK, ClickApply, ClickCancel, and CloseBox respectively.

We'll examine the callback methods, then CloseBox, and finally ModifyModelAndVisu that modifies the document and request for a display refresh.

  1. ClickOK
    void CAAAfrPointEditDlg::ClickOK(CATCommand * iSendingCommmand,
                                     CATNotification * iSentNotification,
                                     CATCommandClientData UsefulData)
    {
      ModifyModelAndVisu(_XSpinner->GetCurrentValue(),
                         _YSpinner->GetCurrentValue(),
                         _ZSpinner->GetCurrentValue());
      CloseBox();
    }

    This method is executed whenever the end user clicks the OK push button. It first modifies the point and the display thanks to the ModifyModelAndVisu method using the current values of the spinners and calls the CloseBox method that takes appropriate actions to close the dialog.

  2. ClickApply
    void CAAAfrPointEditDlg::ClickApply(CATCommand * iSendingCommmand,
                                        CATNotification * iSentNotification,
                                        CATCommandClientData UsefulData)
    {
      ModifyModelAndVisu(_XSpinner->GetCurrentValue(),
                         _YSpinner->GetCurrentValue(),
                         _ZSpinner->GetCurrentValue());
    }

    This method is executed whenever the end user clicks the Apply push button. It just modifies the point and the display like ClickOK, but leaves the dialog box displayed.

  3. ClickCancel
    void CAAAfrPointEditDlg::ClickCancel(CATCommand * iSendingCommmand,
                                         CATNotification * iSentNotification,
                                         CATCommandClientData UsefulData)
    {
      ModifyModelAndVisu(_Xfirst,_Yfirst,_Zfirst);
      CloseBox();
    }

    This method is executed whenever the end user clicks the Cancel push button. It just restores the point and the display using the point initial coordinates, and closes the dialog.

  4. ClickClose
    void CAAAfrPointEditDlg::ClickClose(CATCommand * iSendingCommmand,
                                        CATNotification * iSentNotification,
                                        CATCommandClientData UsefulData)
    {
      CloseBox();
    }

    This method is executed whenever the end user closes the dialog. It calls the CloseBox method.

  5. CloseBox
    void CAAAfrPointEditDlg::CloseBox()
    {
      SetVisibility(CATDlgHide);
    
      RemoveAnalyseNotificationCB(this, this->GetDiaOKNotification(),NULL);
      RemoveAnalyseNotificationCB(this, this->GetDiaAPPLYNotification(),NULL);
      RemoveAnalyseNotificationCB(this, this->GetDiaCANCELNotification(),NULL);
      RemoveAnalyseNotificationCB(this, this->GetWindCloseNotification(),NULL);
    
      SendNotification(GetFather(),CATDlgDialog::GetWindCloseNotification());
    }

    This method hides the dialog, and sends a notification to state that the dialog should be closed This notification is sent to the dialog father, set to the frame window as the first parameter of its constructor. This notification moves from a command to its parent along the command tree structure up to the first command that have set a callback for this notification and for this dialog. Since there are few chances that such a command exists, the notification reaches the command selector that resends it to the active command, which fortunately has set such a callback execute its own CloseBox method when such a notification is received from the dialog.

  6. The ModifyModelAndVisu method modifies the point in the document and sends a notification to request the display to update accordingly.
    void CAAAfrPointEditDlg::ModifyModelAndVisu(const float iX, const float iY, const float iZ)
    {
      _pPointEdit->SetCoord(iX, iY, iZ);
    
      CATIModelEvents * pModelEvents = NULL;
      HRESULT rc = _pPointEdit -> QueryInterface(IID_CATIModelEvents, (void**)&pModelEvents);
      if (SUCCEEDED(rc))
      {
        CATModify * pNotif = new CATModify(pModelEvents);
        pModelEvents->Dispatch(*pNotif);
        delete pNotif;
        pModelEvents->Release();
      } 
    }

[Top]


In Short

Any object can be edited using a dialog when the end user double clicks a representation of the object when the Select command is the active one, or from the object contextual menu, provided the object implements the Activate method of the CATIEdit interface.

The object editing command is then made active. This command must be created in the exclusive mode to ensure that both its availability and its lifecycle are correctly managed by the command selector. The associated dialog box dedicated to editing the object is like any other dialog box. It updates the object's data using methods provided by the object, and its representation(s) by dispatching notifications to the visualiaztion manager, both by means of callbacks set on its different controls.

[Top]


References

[Top]

History

Version: 1 [Jan 2000] Document created
[Top]

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