Swaping Show Mode

Use Case

Abstract

This article discusses the CAAMmrSetShowModeCmd use case. This use case is an interactive command that enables to swap Hide/Show mode of a geometrical feature in a Part Document. It illustrates the possiblility to force the visu synchronisation within an interactive command. 

What You Will Learn With This Use Case

The purpose of this Use Case is to show how to force visu synchronisation in an interactive command that modifies the visu properties of geometrical features, using the CATIMmiPartModelEventManagement interface.

As a reminder, the model world and the visualization world are independent and any geometry modification triggers a visualization update using the CATIModelEvents interface. The treatment of this update event is postponed till the end of the command transaction.

In some cases,  it can be usefull to get the result of the visualization update immediately within the command.It's the purpose of the CATIMmiPartModelEventManagement interface.

This visualization synchronisation can also be usefull when an interactive command creates a large number of geometries, for performance reasons. As an example, if user creates hundreds of points in the same command, it will introduce performance issues as each point creation sends a visualization event, requesting to be drawn. In this particular case it is interesting to “flush” the stored events after each point creation, as each point has to be drawn anyway, and as storing events cost more and more, if you have many objects modified.

The CAAMmrSetShowModeCmd Use Case

CAAMmrSetShowModeCmd is a use case of the CAAMechanicalModeler.edu framework that mainly illustrates the MecModInterfaces framework capabilities. 

What Does CAAMmrSetShowModeCmd do

This Use Case is an Interactive Exclusive State Command that enables user to swap the Hide/Show status of a selected geometrical feature. To begin with, the Use Case integrates a Hide/Show State Command, viewed as , in the "Spec Tree" toolbar, a Part Workshop Add-in within CATIA, as depicted below. [Fig. 1].

Fig.1 "Spec Tree" Toolbar, a Part Workshop Add-in

When the command is activated, user selects a geometrical element and its show mode is swapted. The fact that visualization update is done immediately or not, is checked within the command and shown in the output traces.

The console outputs are described below:

CAAMmrSetShowModeCmd Activate
Selected feature is a geometrical feature
As expected, the feature is now hidden in the 3D

 CAAMmrSetShowModeCmd Activate
Selected feature is a geometrical feature
As expected, the feature isn't hidden

How to Launch CAAMmrSetShowModeCmd

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

  • Launch CATIA
  • Open or Create a Part Document with some geometry.
  • On the Tools menu click Customize and check that the Spec Tree toolbar exists. User can set the visibility of this toolbar with the View->Toolbars option.
  • Click on the Show Mode command.
  • Select a geometrical feature and check that the output traces give the expected result.
  •  

    Addin Access

    The  Spec Tree  Add-in to the  Part Workshop within CATIA, is available thanks to a data extension of the CAAMmrPartWksAddin component [2]. This requires the following entries to be uncommented in the CAAMechanicalModeler.edu.dico file.

    ...
    CAAMmrPartWksAddin CATIWorkbenchAddin libCAAMmrPartWksAddin
    CAAMmrPartWksAddin CATIPrtWksAddin libCAAMmrPartWksAddin
    ...

    Where to Find the CAAMmrSetShowModeCmd Code

    The CAAMmrSetShowModeCmd use case is made of a class defined in the CAAMmrCommands.m module of the CAAMechanicalModeler.edu framework:

    InstallRootDirectory\CAAMechanicalModeler.edu\CAAMmrCommands.m\

    The use case also pre-reqs the following module:

    InstallRootDirectory\CAAMechanicalModeler.edu\CAAMmrPartWksAddin.m\

    where InstallRootDirectory [3] is the directory where the CAA CD-ROM is installed.

    Step-by-Step

    The steps in the CAAMmrUcSetShowModeCmd use case are:

    1. Building the StateCommand
    2. Implementing the Callback to an Incoming Transition associated with this State Command

    Building the StateCommand

    The first step implements a State Command [1]. This implementation occurs in the State Command BuildGraph method.

     The State Command has a state prompting the end user to select a geometrical feature. The selection is restricted to those entities that implement CATIGeometricalElement.

    	CATPathElementAgent* _daObjectToSelect;
    ...
    	_daObjectToSelect = new CATPathElementAgent("SelMechanicalFeature");
    	_daObjectToSelect->AddElementType(IID_CATIGeometricalElement);
    ...

    This state has an incoming transition to itself associated with it, as a result of which it remains eternally prompting the end-user to select an entity whose show mode will be swapted. An action associated with this incoming transition,   CAAMmrSetShowModeCmd::SwapShowMode switches the show mode of the selected feature.

    Implementing the Callback to an Incoming Transition associated with the State Command

    Here we detail the implementation of the Callback associated with the State Command. This callback is triggered in response to the user selecting a geometrical feature, in the spec tree or in the geometry area of CATIA. It retrieves the selected feature, seeks its current show mode and switches its state (hide/show)

    Retrieving the Feature from the Selection Agent

    To begin with, it retrieves the chosen feature from the Selection Agent.

    // Within the State Command Class
    CATPathElementAgent* _daObjectToSelect;
    ...
    CATPathElement* pathModel = _daObjectToSelect->GetValue();
    CATBaseUnknown* pSelectedObj = NULL;
    
    if ((NULL != pathModel) && (pathModel->GetSize()>0))
    {
      // Seek the last element of the path. 
      pSelectedObj = (*pathModel)[pathModel->GetSize()-1];
      if (NULL == pSelectedObj)
    	return TRUE ;
    
      // Seek the CATIMmiUseGeometricalElement type on the selected feature
      CATIGeometricalElement_var spMmiMechFeat = pSelectedObj;
    ...

    On selecting an entity within CATIA, the Selection Agent, a CATPathElementAgent object, _daObjectToSelect  is valuated. The call to GetValue of the Selection Agent returns the chosen entity, as a CATPathElement object, *pathModel.

    This object consists of the selected entity, with all its ancestors up to the product model hierarchy until Root. We retrieve the last element in this list, which is the selecteted feature, for further processing.

    Getting the Feature's visualization status and changing it

    We next seek the show mode of the selected feature. If visible, it is switched to hiden mode and vice versa.

    ...
    // Query the CATIVisProperties Interface
    CATIVisProperties_var MyFeatureProperties = spMmiMechFeat;
    
    if (NULL_var != MyFeatureProperties)
    {
      CATVisPropertiesValues visValues;
    
      // Get the current value of the show attribute
      rc = MyFeatureProperties->GetPropertiesAtt(visValues,CATVPShow,CATVPGlobalType);  
         
      // Swap the value of show attribute
      if (SUCCEEDED(rc))
      {
        CATShowAttribut ShowAttr  =  CATShowAttr;
        visValues.GetShowAttr(ShowAttr); 
     
        if (ShowAttr == CATShowAttr)
          ShowAttr = CATNoShowAttr;
        else if (ShowAttr == CATNoShowAttr)
          ShowAttr = CATShowAttr;
         
        visValues.SetShow(ShowAttr);
    
        // Modify the property
        rc = MyFeatureProperties->SetPropertiesAtt(visValues,CATVPShow,CATVPGlobalType);  
    ...

    The CATIVisProperties::GetPropertiesAtt call returns a CATShowAttribut, ShowAttr (CATShowAttr, if visible, else CATNoShowAttr).

    We inverse the value of ShowAttr and change the mode of the feature by calling the SetPropertiesAtt method.

    The CATIVisProperties::SetPropertiesAtt call has modified the visu properties of the feature. A visualization update is now necessary.

    Sending a visualization event

    The visualization update is done by sending a visu modification notification, CATModifyVisProperties, using the CATIModelEvents interface.
    ...
    // Sending the visualization event to refresh the 3D
    CATIModelEvents_var MyFeatureModelEvents = spMmiMechFeat;
    if (SUCCEEDED(rc) && NULL_var != MyFeatureModelEvents)
    {
      CATModifyVisProperties ModifyNotification(spMmiMechFeat, NULL, CATVPGlobalType, CATVPShow, visValues); 
      MyFeatureModelEvents->Dispatch(ModifyNotification);
     
    ...

    This visualization event will be processed at the end of the transaction, which is sufficient for most commands and imperceptible to the end user.

    Synchronizing visualization

    The visualization event can be forced to be processed immediately thanks to CATIMmiPartModelEventManagement interface.
    ...
    //ask for the immediate process of visu events
    CATIMechanicalFeature_var spMechFeat = spMmiMechFeat;
    if (NULL_var != spMechFeat)
    {
      CATISpecObject_var spPart = spMechFeat->GetPart();
     
      if (NULL_var != spPart)
      {
        CATIMmiPartModelEventManagement * PartModelEvtMgnt = NULL;
        rc = spPart->QueryInterface(IID_CATIMmiPartModelEventManagement,(void**)&PartModelEvtMgnt);
        if (SUCCEEDED(rc)&& NULL != PartModelEvtMgnt)
        {
          PartModelEvtMgnt->CommitNow();
          PartModelEvtMgnt->Release();
          PartModelEvtMgnt = NULL;
        }
      }
    }
    ...

    This event should be invoked on the Part Feature to which belongs the impacted geometrical feature. The Part feature is obtained by calling the GetPart method of CATIMechanicalFeature interface.
    The visualization synchronisation is done by calling the CommitNow method of CATIMmiPartModelEventManagement interface on the Part feature.

    In Short

    This use case shows, through an interactive command,  how to modify the visualization attributes of a geometrical feature in a 3D Shape. It shows how to update the visualization of the modified feature and mostly how to synchronize this visualization event immediately thanks to the CATIMmiPartModelEventManagement interface.

    References

    [1] Getting stated with State Dialog Commands
    [2] Creating an Add-in
    [3] Building and Launching a CAA Use Case

    History

    Version: 1 [Sep 2011] Document created