Back to index

salome-gui  6.5.0
Public Slots | Public Member Functions | Protected Types | Protected Slots | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes
StandardApp_Module Class Reference

This class is provided as the base class for the standard gui part of a SALOME module. More...

#include <StandardApp_Module.hxx>

List of all members.

Public Slots

bool deactivateModule (SUIT_Study *)
bool activateModule (SUIT_Study *)

Public Member Functions

 StandardApp_Module ()
void initialize (CAM_Application *)
QString engineIOR () const
virtual void windows (QMap< int, int > &theMap) const
int createStandardAction (const QString &label, QObject *slotobject, const char *slotmember, const QString &iconName=QString(), const QString &tooltip=QString(), const int identifier=ACTIONID_UNDEFINED)
 This function creates an action and connects it to a button in the toolbar and to an item in the menu associated to this module.
void addActionInToolbar (int actionId)
 Integrate the action in the default toolbar.
void addActionInMenubar (int actionId)
 Integrate the action in the default menu.
void addActionInPopupMenu (int actionId, const QString &rule="client='ObjectBrowser'")
 Add the specified action as an item in the popup menu, with the specified visible rule.

Protected Types

enum  DockLayoutType { DOCKLAYOUT_BOTTOM_HLARGE, DOCKLAYOUT_LEFT_VLARGE }

Protected Slots

void OnTest ()

Protected Member Functions

virtual void createModuleWidgets ()
 This function can be used to create additionnal widget for this module GUI (e.g.
virtual void createModuleActions ()
 This function can be used to defined the list of actions for this module GUI.
void createStudyComponent (SUIT_Study *)
 This creates a root entry in the active study for this module, i.e a SComponent with the name of the module and the icon specified for the module.
virtual bool createStudyComponentAtActivation ()
 This function should be implemented in a specialized class and must return true if you want to automatically create a study component for this module at activation step (when you first load the module for a given study).
virtual
Engines::EngineComponent_ptr 
getEngine () const =0
virtual QString studyIconName ()
 This specifies the filename for the icon to be used for the study component associated to the module.
QIcon createIcon (const QString &iconName)
int newActionId ()
virtual void setDockLayout (DockLayoutType layoutType)
 This can be used to switch the layout of main application dockwidgets to one of the predefined configuration (see enum DockLayoutType).
virtual void unsetDockLayout ()
 This function restores the layout state that was previously in place before the last setDockLayout call.

Protected Attributes

SUIT_ResourceMgr * _resourceMgr
int _defaultMenuId
int _defaultToolbarId

Static Protected Attributes

static int ACTIONID_DEFAULT_INIT_VALUE = 910
static int ACTIONID_UNDEFINED = -1

Private Attributes

int _actionId_internalCount
Qt::DockWidgetArea _areaAtBottomLeftCorner
Qt::DockWidgetArea _areaAtBottomRightCorner

Detailed Description

This class is provided as the base class for the standard gui part of a SALOME module.

To define a gui part, you just have to implement the virtual functions:

The gui part of a SALOME module is an extension of the SALOME client Application for this module. Technically speaking, it consists in a plugin that provides a derived class of CAM_Module (provided by the GUI module).

A standard gui is the standard design for most of SALOME module (object browser on the left, viewer on the rigth, python console on the bottom, and toolbox in the toolbar with standard definition of the tool function). This standard design suggests also to specify the engine associated to the module by implementing the virtual pure function getEngine(). The engine of a module is the SALOME component that is associated to the study component for this module, and generally which is responsible for the persistency functions or data management for the module.

See a use case example in the test module Xsalome provided by the test package (tst/module/gui/Xsalome.hxx and tst/module/gui/factory.cxx in the XSALOME library).

Definition at line 59 of file StandardApp_Module.hxx.


Member Enumeration Documentation

Enumerator:
DOCKLAYOUT_BOTTOM_HLARGE 
DOCKLAYOUT_LEFT_VLARGE 

Definition at line 118 of file StandardApp_Module.hxx.

                      {
    DOCKLAYOUT_BOTTOM_HLARGE, // Bottom is Horizontal Large
    DOCKLAYOUT_LEFT_VLARGE,   // Left is Vertical Large
  };

Constructor & Destructor Documentation

Definition at line 40 of file StandardApp_Module.cxx.

                                       :
  SalomeApp_Module( "" ),
  LightApp_Module( "" )
{
  // Note that it's no use to specify here the moduleName because it's
  // automatically determined by the name of the GUI library
  // (lib<moduleName>.so) just before initialize step. If you want
  // nevertheless to setup the module name you should specified this
  // name in the initialize function below using the CAM_module
  // function setModuleName(QString&). You are warn then that the
  // loading of resource files may be incorect and should be manually
  // managed. In conclusion, if you don't need a special
  // configuration, please conform to the standard convention: if
  // <moduleName> is the name of the module as declared in the GUI
  // configuration file (SalomeApp.xml), then you just have to provide
  // a library whose name is lib<moduleName>.so and which contains a
  // factory "extern C" function 'CAM_Module* createModule()'
}

Member Function Documentation

bool StandardApp_Module::activateModule ( SUIT_Study theStudy) [slot]

Definition at line 261 of file StandardApp_Module.cxx.

{
  bool bOk = SalomeApp_Module::activateModule( theStudy );

  setMenuShown( true );
  setToolShown( true );

  if ( this->createStudyComponentAtActivation() ) {
    this->createStudyComponent(theStudy);
  }

  return bOk;
}

Here is the call graph for this function:

Integrate the action in the default menu.

Definition at line 157 of file StandardApp_Module.cxx.

                                                        {
  this->createMenu( actionId, _defaultMenuId, 10 );
}
void StandardApp_Module::addActionInPopupMenu ( int  actionId,
const QString &  rule = "client='ObjectBrowser'" 
)

Add the specified action as an item in the popup menu, with the specified visible rule.

The default is "visible for object browser".

Definition at line 165 of file StandardApp_Module.cxx.

                                                                              {
  // _GBO_ for a fine customization of the rule (for example with a
  // test on the type of the selected object), see the LIGTH module:
  // implement "LightApp_Selection*    createSelection() const;"
  int parentId = -1;
  QtxPopupMgr* mgr = this->popupMgr();
  mgr->insert ( this->action( actionId ), parentId, 0 );
  mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
}

Integrate the action in the default toolbar.

Definition at line 150 of file StandardApp_Module.cxx.

                                                        {
  this->createTool( actionId, _defaultToolbarId );
}

Here is the caller graph for this function:

QIcon StandardApp_Module::createIcon ( const QString &  iconName) [protected]

Definition at line 92 of file StandardApp_Module.cxx.

                                                            {
  // The icon file is supposed to be available througth the resource
  // manager, i.e. in the folder containing the XSALOME resources (see
  // specification in the module file SalomeApp.xml).
  QPixmap aPixmap = _resourceMgr->loadPixmap( QCHARSTAR(moduleName()), iconName );
  return QIcon( aPixmap );
}

Here is the caller graph for this function:

This function can be used to defined the list of actions for this module GUI.

It can be redefined in a specialized version of this class. Depending on wether you use the method "createStandardAction" or not, the actions will be automatically plugged in the toolbar and the menu associated to the module.

Definition at line 192 of file StandardApp_Module.cxx.

                                             {
  int actionId = this->createStandardAction("Test", this, SLOT(OnTest()),
                                       "f1.png", "Run the default test function");
  this->addActionInToolbar(actionId);
}

Here is the call graph for this function:

Here is the caller graph for this function:

This function can be used to create additionnal widget for this module GUI (e.g.

docked widget). It can be redefined in a specialized version of this class.

Definition at line 180 of file StandardApp_Module.cxx.

                                             {
  // Nothing to do in this default gui
}

Here is the caller graph for this function:

int StandardApp_Module::createStandardAction ( const QString &  label,
QObject slotobject,
const char *  slotmember,
const QString &  iconName = QString(),
const QString &  tooltip = QString(),
const int  identifier = ACTIONID_UNDEFINED 
)

This function creates an action and connects it to a button in the toolbar and to an item in the menu associated to this module.

This function applies a common and standard procedure with a maximum of default values. If no identifier is specified, then a static internal counter is used to associate an identifier to the created action. In any case, the action identifier is returned.

Note that the action (object of type QAction) can be retrieved using the method "QAction * action(int identifier)" of the super class.

Definition at line 117 of file StandardApp_Module.cxx.

{

  // If the tooltip is not defined, we choose instead the label text.
  QString effToolTip(tooltip);
  if ( effToolTip.isEmpty() )
    effToolTip = label;

  QIcon actionIcon = this->createIcon(iconName);

  // If the identifier is not specified, then we use an internal
  // counter.
  int effIdentifier = identifier;
  if ( effIdentifier == StandardApp_Module::ACTIONID_UNDEFINED ) {
    effIdentifier=newActionId();
  }

  // Creating the action
  QAction * action= this->createAction( effIdentifier, label, actionIcon, 
                                        label, effToolTip, 0, getApp()->desktop(),
                                        false, slotobject, slotmember);

  return effIdentifier;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This creates a root entry in the active study for this module, i.e a SComponent with the name of the module and the icon specified for the module.

This component is associated to the engine (return by getEngine()) if the engine is a SALOMEDS::Driver.

Definition at line 291 of file StandardApp_Module.cxx.

                                                                  {

  SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
  CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
  SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(theStudy->id());

  SALOMEDS::SComponent_var aFather = aDSStudy->FindComponent(QCHARSTAR(moduleName()));
  if (aFather->_is_nil())
    {
      SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
      aFather = aStudyBuilder->NewComponent(QCHARSTAR(moduleName()));
      SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
      SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
      aName->SetValue(QCHARSTAR(moduleName()));
      aName->Destroy();
      anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
      SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
      aPixMap->SetPixMap(QCHARSTAR(studyIconName()));

      // WARN: The engine should be associated to the SComponent IF
      // AND ONLY IF it is a SALOMEDS::Driver. Otherwise, there is no
      // need to do that, and it could even lead to exception
      // raising (eh, you work on SALOME isn't it?)
      SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(this->getEngine());
      if ( ! driver->_is_nil() ) {
       STDLOG("Associate the SComponent to the engine");
       aStudyBuilder->DefineComponentInstance(aFather, this->getEngine());
      }
    }

}

Here is the call graph for this function:

Here is the caller graph for this function:

This function should be implemented in a specialized class and must return true if you want to automatically create a study component for this module at activation step (when you first load the module for a given study).

The default function return true.

Definition at line 281 of file StandardApp_Module.cxx.

                                                          {
  return true;
}

Here is the caller graph for this function:

bool StandardApp_Module::deactivateModule ( SUIT_Study theStudy) [slot]

Definition at line 325 of file StandardApp_Module.cxx.

{
  setMenuShown( false );
  setToolShown( false );

  return SalomeApp_Module::deactivateModule( theStudy );
}
QString StandardApp_Module::engineIOR ( ) const

Definition at line 207 of file StandardApp_Module.cxx.

{
  CORBA::String_var anIOR = getApp()->orb()->object_to_string(getEngine());
  return QString( anIOR.in() );
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual Engines::EngineComponent_ptr StandardApp_Module::getEngine ( ) const [protected, pure virtual]

Here is the caller graph for this function:

Definition at line 63 of file StandardApp_Module.cxx.

{
  //
  // ----------------------------------------------------------------
  // Standard initialization
  // ----------------------------------------------------------------
  //
  SalomeApp_Module::initialize( app );
  _resourceMgr = app->resourceMgr();
  // Please note that the moduleName() function is inherited from
  // CAM_module classe, and that its value is determined automatically
  // from the name specified in the SalomeApp.xml associated to this
  // module and which corresponds to the name of the GUI library
  // (lib<moduleName>.so). For XSALOME, see
  // share/salome/resources/xsalome/SalomeApp.xml in the install
  // directory.
  _defaultMenuId = this->createMenu( QCHARSTAR(moduleName()), -1, -1, 30 );
  _defaultToolbarId = this->createTool ( QCHARSTAR(moduleName()) );
  _actionId_internalCount = StandardApp_Module::ACTIONID_DEFAULT_INIT_VALUE;

  //
  // ----------------------------------------------------------------
  // The following initializes the GUI widget and associated actions
  // ----------------------------------------------------------------
  // These functions may be redefined in specialized version of this class
  this->createModuleWidgets();
  this->createModuleActions();
}

Here is the call graph for this function:

int StandardApp_Module::newActionId ( ) [protected]

Definition at line 100 of file StandardApp_Module.cxx.

Here is the caller graph for this function:

void StandardApp_Module::OnTest ( ) [protected, slot]

Definition at line 333 of file StandardApp_Module.cxx.

{
  // Just for test
  STDLOG("OnTest: engine IOR = "<<QCHARSTAR(engineIOR()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StandardApp_Module::setDockLayout ( DockLayoutType  layoutType) [protected, virtual]

This can be used to switch the layout of main application dockwidgets to one of the predefined configuration (see enum DockLayoutType).

When a layout is set, the previous layout is memorized and can be restored using the unsetDockLayout function (1 step undo). It is typically to be used in the functions activateModule to setup the layout and deactivateModule to unset the layout, i.e. restore to the previous state.

Definition at line 236 of file StandardApp_Module.cxx.

                                                                {
  SUIT_Desktop* desk = getApp()->desktop();
  _areaAtBottomLeftCorner = desk->corner(Qt::BottomLeftCorner);
  _areaAtBottomRightCorner = desk->corner(Qt::BottomRightCorner);
  
  if ( layoutType == DOCKLAYOUT_LEFT_VLARGE ) {
    desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
    desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
  } else {
    desk->setCorner(Qt::BottomLeftCorner, Qt::BottomDockWidgetArea);
    desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);    
  }
}
QString StandardApp_Module::studyIconName ( ) [protected, virtual]

This specifies the filename for the icon to be used for the study component associated to the module.

Note that this icon could be different than the module icon which is defined by the SalomeApp.xml file dedicated to this module (see the shared resources folder dedicated to the module) and which is used for the toolbar of the SALOME application.

Definition at line 221 of file StandardApp_Module.cxx.

{
  // By default, we return the module icone name
  return iconName(); // inherited from CAM_Module
}

Here is the caller graph for this function:

void StandardApp_Module::unsetDockLayout ( ) [protected, virtual]

This function restores the layout state that was previously in place before the last setDockLayout call.

Definition at line 254 of file StandardApp_Module.cxx.

                                         {
  SUIT_Desktop* desk = getApp()->desktop();
  desk->setCorner(Qt::BottomLeftCorner, _areaAtBottomLeftCorner);
  desk->setCorner(Qt::BottomRightCorner, _areaAtBottomRightCorner);
}
void StandardApp_Module::windows ( QMap< int, int > &  theMap) const [virtual]

Definition at line 199 of file StandardApp_Module.cxx.

{
  theMap.clear();
  theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
  theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
}

Member Data Documentation

Definition at line 133 of file StandardApp_Module.hxx.

Qt::DockWidgetArea StandardApp_Module::_areaAtBottomLeftCorner [private]

Definition at line 134 of file StandardApp_Module.hxx.

Qt::DockWidgetArea StandardApp_Module::_areaAtBottomRightCorner [private]

Definition at line 135 of file StandardApp_Module.hxx.

Definition at line 126 of file StandardApp_Module.hxx.

Definition at line 127 of file StandardApp_Module.hxx.

SUIT_ResourceMgr* StandardApp_Module::_resourceMgr [protected]

Definition at line 125 of file StandardApp_Module.hxx.

int StandardApp_Module::ACTIONID_DEFAULT_INIT_VALUE = 910 [static, protected]

Definition at line 129 of file StandardApp_Module.hxx.

int StandardApp_Module::ACTIONID_UNDEFINED = -1 [static, protected]

Definition at line 130 of file StandardApp_Module.hxx.


The documentation for this class was generated from the following files: