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.
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() ; } }
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.
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:
QString HELLOGUI::engineIOR() const { CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHELLOGen( getApp() ) ); return QString( anIOR.in() ); }
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 ); }
bool HELLOGUI::activateModule( SUIT_Study* theStudy ) { bool bOk = SalomeApp_Module::activateModule( theStudy ); setMenuShown( true ); setToolShown( true ); return bOk; }
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(); } }