Version: 6.3.1

The src directory

The src contains all source files required to build CORBA engine and (optionally) GUI libraries of the module. Each of these entities usually has (but this is not actually obligatory) its own directory.

The Makefile.am simply triggers the path of sub-directories described by the SUBDIRS target.

  • The src/HELLO directory

This directory contains the C++ source files that implement the engine library of the module. The Makefile.am defines the rules used to build the engine library from these source files. The name of the module engine library is predefined and should be set as lib<MODULE>Engine.so where <MODULE> is a name of the module. In the case of the HELLO module, the name of the engine library should be libHELLOEngine.so.

The HELLO.h, HELLO.cxx files implement HELLO class that is derived from the HELLO_Gen interface of the POA_HELLO_ORB CORBA module and the SALOME_Component_i class (base implementation of SALOME module engine exported by the KERNEL module).

In particular, HELLO class implements makeBanner() function that is defined in the IDL interface HELLO_ORB::HELLO_Gen.

char* HELLO::makeBanner(const char* name)
{
  string banner = "Hello, ";
  banner += name;
  return CORBA::string_dup(banner.c_str());
}

In addition, HELLO.cxx implements a factory function which is used by the SALOME container to create an instance of the HELLO CORBA engine by demand:

extern "C"
{
  PortableServer::ObjectId* HELLOEngine_factory(
    CORBA::ORB_ptr orb,
    PortableServer::POA_ptr poa,
    PortableServer::ObjectId* contId,
    const char* instanceName,
    const char* interfaceName)
  {
    HELLO* myHELLO = new HELLO(orb, poa, contId, instanceName, interfaceName);
    return myHELLO->getId() ;
  }
}
  • The src/HELLOGUI directory

This directory contains the C++ source files that implement the GUI library of HELLO module. By default, the name of the module GUI library is predefined and should be set as lib<MODULE>.so where <MODULE> is a name of the module. In the case of the HELLO module, the name of the GUI library should be libHELLO.so. It is also possible to use custom name of the GUI library of a module, but in this case, in order to be possible to use this module in SALOME GUI desktop, the name of the GUI library should be defined in the corresponding SalomeApp.xml file, in the module's main section, e.g.:

  <section name="HELLO">
    <parameter name="name" value="Hello"/>
    <parameter name="icon" value="HELLO.png"/>
    <parameter name="library" value="libMyHelloGUIlibrary.so"/>
  </section>

The implementation of GUI library of the HELLO module should be done according to the architecture and rules specified by the SALOME GUI module. The main GUI module class (HELLOGUI in our case) should be derived from the SalomeApp_Module class.

The developer has to redefine a set of methods which define the module behavior in GUI, for example, create menus, toolbars, define context popup menus, objects selection behavior, implement dialog boxes etc.

Here below is a short description of these methods. For more details please refer to the SALOME GUI module documentation.

  • initialize() - module first initialization; usually used to create GUI actions, menus, toolbars and so on;
  • activateModule() - module activation; perform actions which should be done when the module is activated by the user, for example, show related menus and toolbars;
  • deactivateModule() - module deactivation; perform actions which should be done when the module is deactivated by the user, for example, hide related menus and toolbars;
  • windows() - get a list and a position of the windows to be associated with the module; these windows will be automatically opened and positioned according to the setting defined by the value returned by this function;
  • viewManagers() - get a list of the compatible viewers; these viewers will be automatically opened/raised on the module activation;
  • contextMenuPopup() - create and return context popup menu according to the current selection;
  • createPreferences() - initialize module's preferences;
  • preferencesChanged() - callback function that is called when some module's preference is changed by the user; allows to perform the corresponding actions;
  • createSelection() - create and return menu selection object; this is a part of the context popup menu definition API
  • engineIOR() - to get the reference to the module CORBA engine

Note, that all of these methods are optional and need not be obligatory implemented because SalomeApp_Module class provides a base implementation of these functions. It's sometimes enough to implement only some of them, depending on the module needs.

In the case of HELLO module, only the following methods are implemented:

  • engineIOR() that initializes HELLO module's eggine:
QString HELLOGUI::engineIOR() const
{
  CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHELLOGen( getApp() ) );
  return QString( anIOR.in() );
}
  • initialize() that creates single action for engine's makeBanner() service:
void HELLOGUI::initialize( CAM_Application* app )
{
  // invoke parent implementation
  SalomeApp_Module::initialize( app );
  // initialize eigine
  InitHELLOGen( dynamic_cast<SalomeApp_Application*>( app ) );
  // get GUI resources manager 
  QWidget* aParent = application()->desktop();
  SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
  // create action
  QPixmap aPixmap = aResourceMgr->loadPixmap( "HELLO",tr( "ICON_GET_BANNER" ) );
  createAction( 901, tr( "TLT_GET_BANNER" ), QIcon( aPixmap ), 
                tr( "MEN_GET_BANNER" ), tr( "STS_GET_BANNER" ),
                0, aParent, false,
                this, SLOT( OnGetBanner() ) );
  // create menu
  int aMenuId;
  aMenuId = createMenu( tr( "MEN_HELLO" ), -1, -1, 30 );
  createMenu( 901, aMenuId, 10 );
  // create toolbar
  int aToolId = createTool ( tr( "TOOL_HELLO" ) );
  createTool( 901, aToolId );
}
  • activateModule() that activates menus and toolbars
bool HELLOGUI::activateModule( SUIT_Study* theStudy )
{
  bool bOk = SalomeApp_Module::activateModule( theStudy );
  setMenuShown( true );
  setToolShown( true );
  return bOk;
}
  • deactivateModule() that deactivates menus and toolbars
bool HELLOGUI::deactivateModule( SUIT_Study* theStudy )
{
  setMenuShown( false );
  setToolShown( false );
  return SalomeApp_Module::deactivateModule( theStudy );
}

An implemention of the OnGetBanner() method is quite simple. It shows the small dialog box allowing user to enter the name, and then uses reference to the module CORBA engine to invoke its makeBanner() service:

void HELLOGUI::OnGetBanner()
{
  // Dialog to get the Name
  bool ok = FALSE;
  QString myName = QInputDialog::getText( getApp()->desktop(),
                                          tr( "QUE_HELLO_LABEL" ),
                                          tr( "QUE_HELLO_NAME" ),
                                          QLineEdit::Normal,
                                          QString::null, &ok );
  // if we got a name, get a HELLO component and ask for makeBanner
  if ( ok && !myName.isEmpty())
  {
    // invoke CORBA service of an engine
    HELLO_ORB::HELLO_Gen_ptr hellogen = HELLOGUI::InitHELLOGen( getApp() );
    QString banner = hellogen->makeBanner( (const char*)myName.toLatin1() );
    // show result in the message box
    SUIT_MessageBox::information( getApp()->desktop(),
                                  tr( "INF_HELLO_BANNER" ),
                                  banner, tr( "BUT_OK" ) );
  }
}

In addition, HELLOGUI.cxx implements a factory function which is used by the SALOME GUI to create an instance of the HELLO GUI class instance by demand:

extern "C" {
  CAM_Module* createModule()
  {
    return new HELLOGUI();
  }
}

<< Previous
>> Next

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS