Salome HOME
Make HELLO component appear into "salome sesionless"
[samples/hello.git] / src / HELLOGUI / HELLOGUI.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HELLOGUI.h"
24 #include "HELLO_version.h"
25 #include "HELLO_Component_Generator.hxx"
26
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_Study.h>
29 #include <SalomeApp_DataObject.h>
30
31 #include <LightApp_SelectionMgr.h>
32
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36
37 #include <QtxPopupMgr.h>
38
39 #include <SALOME_ListIO.hxx>
40
41 #include <SALOME_LifeCycleCORBA.hxx>
42 #include <SALOMEDS_SObject.hxx>
43 #include <SALOMEDS_Study.hxx>
44 #include "SALOME_NamingService_Abstract.hxx"
45 #include "SALOME_KernelServices.hxx"
46
47 #include <QInputDialog>
48
49 //! The only instance of the reference to engine
50 HELLO_ORB::HELLO_Gen_var HELLOGUI::myEngine;
51
52 /*!
53   \brief Constructor
54   
55   Creates an instance of the HELLO GUI module.
56   Initializes (loads if necessary) HELLO module engine.
57 */
58 HELLOGUI::HELLOGUI() :
59   SalomeApp_Module( "HELLO" ) // module name
60 {
61   init(); // internal initialization
62 }
63
64 /*!
65   \brief Destructor
66   
67   Destroys any allocated resources.
68 */  
69 HELLOGUI::~HELLOGUI()
70 {
71   // nothing to do
72 }
73
74 /*!
75   \brief Get a reference to the HELLO module CORBA engine
76
77   \note This function returns vartype in order to minimize possible crashes
78   when using this function with assignment operations.
79   On the other hand, this simplifies usage of this function when using it outside
80   the assignment operations, to minimize memory leaks caused by orphan CORBA
81   references (no need to take care of reference counting).
82
83   \return reference to the module engine
84 */
85 HELLO_ORB::HELLO_Gen_var HELLOGUI::engine()
86 {
87   init(); // initialize engine, if necessary
88   return myEngine;
89 }
90
91 /*!
92   \brief Module initialization.
93
94   Overloaded from CAM_Module class.
95   
96   Perform general module initialization (like creation of actions,
97   menus, toolbars, etc).
98
99   \note This function is invoked only once, when the module
100   is first time activated by the user.
101   The study associated with the application might not exist
102   (created or opened) when this function is invoked, so it is not
103   recommended to perform any study-dependant actions here.
104
105   \param app pointer to the current application instance
106 */
107 void HELLOGUI::initialize( CAM_Application* app )
108 {
109   // call the parent implementation
110   SalomeApp_Module::initialize( app );
111
112   // get reference to the desktop (used as a parent for actions)
113   QWidget* dsk = app->desktop();
114   // get resources manager
115   SUIT_ResourceMgr* resMgr = app->resourceMgr();
116
117   // create actions
118   // ... Test me operation
119   createAction( OpTestMe,                                               // operation id
120                 tr( "TLT_OP_TESTME" ),                                  // tooltip
121                 resMgr->loadPixmap( "HELLO",tr( "ICON_OP_TESTME" ) ),   // icon
122                 tr( "MEN_OP_TESTME" ),                                  // menu title
123                 tr( "STS_OP_TESTME" ),                                  // status tip
124                 0,                                                      // accelerator (not set)
125                 dsk,                                                    // parent
126                 false,                                                  // togglable flag (no)
127                 this,                                                   // action receiver
128                 SLOT( testMe() ) );                                     // action slot
129   // ... Hello operation
130   createAction( OpHello,                                                // operation id
131                 tr( "TLT_OP_HELLO" ),                                   // tooltip
132                 resMgr->loadPixmap( "HELLO",tr( "ICON_OP_HELLO" ) ),    // icon
133                 tr( "MEN_OP_HELLO" ),                                   // menu title
134                 tr( "STS_OP_HELLO" ),                                   // status tip
135                 0,                                                      // accelerator (not set)
136                 dsk,                                                    // parent
137                 false,                                                  // togglable flag (no)
138                 this,                                                   // action receiver
139                 SLOT( hello() ) );                                      // action slot
140   // ... Goodbye operation
141   createAction( OpGoodbye,                                              // operation id
142                 tr( "TLT_OP_GOODBYE" ),                                 // tooltip
143                 resMgr->loadPixmap( "HELLO",tr( "ICON_OP_GOODBYE" ) ),  // icon
144                 tr( "MEN_OP_GOODBYE" ),                                 // menu title
145                 tr( "STS_OP_GOODBYE" ),                                 // status tip
146                 0,                                                      // accelerator (not set)
147                 dsk,                                                    // parent
148                 false,                                                  // togglable flag (no)
149                 this,                                                   // action receiver
150                 SLOT( goodbye() ) );                                    // action slot
151
152   // create menus
153   int menuId;
154   menuId = createMenu( tr( "MEN_FILE" ), -1, -1 );                      // File menu
155   createMenu( separator(), menuId, -1, 10 );                            // add separator to File menu
156   menuId = createMenu( tr( "MEN_FILE_HELLO" ), menuId, -1, 10 );        // File - Hello submenu
157   createMenu( OpTestMe, menuId );                                       // File - Hello - Test me
158   menuId = createMenu( tr( "MEN_HELLO" ), -1, -1, 30 );                 // Hello menu
159   createMenu( OpHello, menuId, 10 );                                    // Hello - Hello
160   createMenu( OpGoodbye, menuId, 10 );                                  // Hello - Goodbye
161
162   // create toolbars
163   int aToolId;
164   aToolId = createTool ( tr( "TOOL_TEST" ), QString( "HelloTest" ) );   // Test toolbar
165   createTool( OpTestMe, aToolId );                                      // Test - Test me
166   aToolId = createTool ( tr( "TOOL_HELLO" ), QString( "HelloMain" ) );  // Hello toolbar
167   createTool( OpHello, aToolId );                                       // Hello - Hello
168   createTool( OpGoodbye, aToolId );                                     // Hello - Goodbye
169
170   // set-up popup menu
171   QtxPopupMgr* mgr = popupMgr();
172   mgr->insert( action( OpHello ),   -1, -1 );                           // Hello
173   mgr->insert( action( OpGoodbye ), -1, -1 );                           // Goodbye
174   mgr->insert( separator(),         -1, -1 );                           // -----------
175   mgr->insert( action( OpTestMe ),  -1, -1 );                           // Test me
176   QString baseRule = "client='ObjectBrowser' and selcount=1 and $component={'HELLO'}";
177   mgr->setRule( action( OpHello ),   baseRule + " and isComponent",  QtxPopupMgr::VisibleRule );
178   mgr->setRule( action( OpGoodbye ), baseRule + " and !isComponent", QtxPopupMgr::VisibleRule );
179 }
180
181 /*!
182   \brief Get module engine IOR
183
184   Overloaded from SalomeApp_Module class.
185
186   \return string representing module engine IOR
187 */
188 QString HELLOGUI::engineIOR() const
189 {
190   init(); // initialize engine, if necessary
191   CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
192   return QString( anIOR.in() );
193 }
194
195 /*!
196   \brief Get module icon.
197
198   Overloaded from CAM_Module class.
199
200   Load and return the module icon pixmap. This icon is shown
201   in the Object browser, in modules toolbar, etc.
202
203   Default implementation uses iconName() function to retrieve the name
204   of the image file to be used as the module icon; tries to load this
205   file from module's resources and create pixmap from it.
206   Returns valid QPixmap instance if image is loaded correctly.
207   This function can be customized to provide another way to get module icon.
208
209   \return module icon pixmap
210   \sa iconName()
211 */
212 QPixmap HELLOGUI::moduleIcon() const
213 {
214   // nothing to do, in this example just call the parent implementation
215   return SalomeApp_Module::moduleIcon();
216 }
217
218 /*!
219   \brief Get module icon's file name.
220
221   Overloaded from CAM_Module class.
222
223   This function is used to get module icon image file name.
224   Default implementation tries to retrieve the name of the
225   icon file from the application using moduleIcon() function, which
226   in its turn retrieves the information about the module icon
227   from the configuration file (e.g. SalomeApp.xml, LightApp.xml).
228   This function can be customized to provide another way to get module icon's
229   file name.
230
231   \return module icon file name
232   \sa moduleIcon()
233 */
234 QString HELLOGUI::iconName() const
235 {
236   // nothing to do, in this example just call the parent implementation
237   return SalomeApp_Module::iconName();
238 }
239
240 /*!
241   \brief Request dockable windows to be available when module is active.
242
243   Overloaded from LightApp_Module class.
244
245   Fills and returns the list of dockable windows which should be
246   available when the module is active. It is a map of integer values
247   where \c key is an enumerator from LightApp_Application::WindowTypes
248   enumeration, specifying window type, and \c value is an enumerator
249   from Qt::DockWidgetArea, specifying the window's default position
250   in the main window layout.
251
252   Empty map means no dockable windows available when the module is active.
253
254   \param theMap this map should be filled to specify the list of
255                 required dockable windows withe their default positions
256 */
257 void HELLOGUI::windows( QMap<int, int>& theMap ) const
258 {
259   // want Object browser, in the left area
260   theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
261                  Qt::LeftDockWidgetArea );
262 #ifndef DISABLE_PYCONSOLE
263   // want Python console, in the bottom area
264   theMap.insert( SalomeApp_Application::WT_PyConsole,
265                  Qt::BottomDockWidgetArea );
266 #endif
267 }
268
269 /*!
270   \brief Request view windows (types) to be activated when module is activated..
271
272   Overloaded from LightApp_Module class.
273
274   Fills and returns the list of 3D/2D view windows types compatible
275   with this module. The views of the specified type(s) will be automatically
276   activated (raised to the top of view stack) each time when the module
277   is activated by the user (the views will be automatically created if they
278   do not exist at the module activation).
279   Empty list means no compatible view windows for the module.
280
281   Example:
282   \code
283   theList.append( OCCViewer_Viewer::Type() );
284   theList.append( SVTK_Viewer::Type() );
285   \endcode
286
287   \param theList this list should be filled to specify the list of
288                  compatible view window types
289 */
290 void HELLOGUI::viewManagers( QStringList& /*theList*/ ) const
291 {
292   // no compatible view managers, nothing to do here
293 }
294
295 /*!
296   \brief Create popup selection handler.
297
298   Overloaded from LightApp_Module class.
299
300   This function can be used to create custom popup menu handler.
301   The application takes ownership over the returned pointer, 
302   so you should not destroy it.
303   
304   This function is part of the context popup menu management mechanism.
305   Selection object (instance of LightApp_Selection class or its successor)
306   analizes the currently selected items and defines selection-dependant
307   variables which are processed by the popup manager (QtxPopupMgr class).
308   
309   These variables can be included into the lexical constructions, named
310   "rules", which are associated with the popup menu actions (refer to the
311   QtxPopupMgr class for more details).
312
313   Exampe:
314   \code
315   // obtain popup manager
316   QtxPopupMgr* mgr = popupMgr();
317   // create new action, with ID = 100
318   createAction( 100, "Action", QIcon(), "Action", "My action", 0, application()->desktop(),
319                 false, this, SLOT( OnMyAction() ) );
320   // define popup rule for action
321   QString rule = "client='ObjectBrowser' and $type in {'MyType1' 'MyType2'} and selcount=1";
322   // set visibility rule for action
323   mgr->setRule( 100, rule, QtxPopupMgr::VisibleRule );
324   \endcode
325
326   In the above code, \a selcount variable is automatically defined 
327   by LightApp_Selection class, but \a type variable should be set by
328   the successor class. Note, that LightApp_Selection class implements
329   several useful variables which can be used in the lexical rules.
330   
331   \return new selection object
332   \sa contextMenuPopup()
333 */
334 LightApp_Selection* HELLOGUI::createSelection() const
335 {
336   // nothing to do, in this example just call the parent implementation
337   // see also initialize()
338   return SalomeApp_Module::createSelection();
339 }
340
341 /*!
342   \brief Create displayer object.
343
344   Overloaded from LightApp_Module class.
345
346   This function can be used to create and return custom displayer object.
347   The application does not take the ownership over the returned value.
348
349   Displayer is a part of the presentations management system.
350   If can be used to implement visualization operations, like create, show
351   or hide presentation in the viewer of specific type, etc.
352
353   \return pointer to the module displayer
354  */
355 LightApp_Displayer* HELLOGUI::displayer()
356 {
357   // nothing to do, in this example just call the parent implementation
358   return SalomeApp_Module::displayer();
359 }
360
361 /*!
362   \brief Create context popup menu.
363
364   Overloaded from CAM_Module class.
365
366   This function can be used to customize context popup menu management.
367   The module should fill \a menu with the items (e.g. by inserting own
368   QAction items). The menu contents can be context-depending, the parameter
369   \a type can be used to test the context of the popup menu invocation
370   (e.g. "ObjectBrowser").
371   Parameter \a title can be used to return the string value to be used
372   popup menu title if required.
373
374   Default implementation from LightApp_Module class calls createSelection()
375   function to create popup selection handler and initialized the popup menu
376   using popup manager.
377     
378   \param type popup menu context
379   \param menu pointer to the popup menu
380   \param title custom popup menu title can be returned here
381   \sa createSelection()
382 */
383 void HELLOGUI::contextMenuPopup( const QString& type, QMenu* menu, QString& title )
384 {
385   // nothing to do, in this example just call the parent implementation
386   // see also initialize()
387   return SalomeApp_Module::contextMenuPopup( type, menu, title );
388 }
389
390 /*!
391   \brief Export module preferences.
392
393   Overloaded from LightApp_Module class.
394
395   This function is invoked only once when the common "Preferences"
396   dialog box is first time activated by the user (via the "File/Preferences"
397   menu command) or when module is first time activated.
398
399   This function should be used to export module preferences to the 
400   common "Preferences" dialog box and associate them with the corresponding
401   widgets. The preferences items are arranged to the tree-like structure, where
402   top-level items represent just a containers for the underlying items.
403   Each low-level preferences item is linked to the resources item (via "section"
404   and "parameter" attributes). See QtxResourceMgr class for more details about
405   resources management.
406
407   Example:
408   \code
409   // create top-level preferences tab page
410   int settingsId = addPreference( "Settings" );
411   // create general settings group box
412   int generalId = addPreference( tr( "General" ), settingsId );
413   // set group box property - number of columns - to 2
414   setPreferenceProperty( generalId, "columns", 2 );
415   // create shading color preferences item (color button)
416   addPreference( "Shading color", generalId, LightApp_Preferences::Color,
417                  "HELLO", "shading_color" );
418   // create precision preferences item (spin box)
419   int precisionId = addPreference( tr( "GEOM_PREF_length_precision" ), generalId,
420                  LightApp_Preferences::IntSpin, "HELLO", "precision" );
421   // set precision preferences item properties
422   setPreferenceProperty( precisionId, "min", 0 );
423   setPreferenceProperty( precisionId, "max", 10 );
424   \endcode
425
426   \sa preferencesChanged()
427 */
428 void HELLOGUI::createPreferences()
429 {
430   // no module preferences, nothing to do here
431 }
432
433 /*!
434   \brief Process preference item change event.
435
436   Overloaded from LightApp_Module class.
437
438   This function is called every time when the preference item
439   owned by this module is changed by the user (usually this occurs when
440   the user presses "OK" or "Apply" button in the "Preferences" dialog box).
441
442   The module can perform any specific actions if necessary to response
443   to the preferences changes.
444
445   \param section resources item section name
446   \param parameter resources item parameter name
447
448   \sa createPreferences()
449 */
450 void HELLOGUI::preferencesChanged( const QString& section, const QString& parameter )
451 {
452   // nothing to do, in this example just call the parent implementation
453   SalomeApp_Module::preferencesChanged( section, parameter );
454 }
455
456 /*!
457   \brief Store visual state.
458
459   Overloaded from SalomeApp_Module class.
460   
461   This method is called just before the study document is saved,
462   so the module has a possibility to store any visual parameters
463   in the AttributeParameter study attribute (if required).
464
465   \param savePoint save point unique identifier
466 */
467 void HELLOGUI::storeVisualParameters( int /*savePoint*/ )
468 {
469   // no specific visual state, nothing to do here
470 }
471
472 /*!
473   \brief Restore visual state.
474
475   Overloaded from SalomeApp_Module class.
476   
477   This method is called after the study document is opened,
478   so the module has a possibility to restore the visual parameters
479   from the AttributeParameter study attribute (if required).
480
481   \param savePoint save point unique identifier
482 */
483 void HELLOGUI::restoreVisualParameters( int /*savePoint*/ )
484 {
485   // no specific visual state, nothing to do here
486 }
487
488 /*!
489   \brief Handle active study changing action.
490
491   Overloaded from LightApp_Module class.
492   
493   This function is called each time when the active study is changed
494   (usually this happens when users switches between different studies'
495   desktops).
496
497   Can be used to perform any relevant actions.
498 */
499 void HELLOGUI::studyActivated()
500 {
501   // no any specific action required, nothing to do here
502 }
503
504 /*!
505   \brief Check if the module can perform "copy" operation.
506
507   Overloaded from LightApp_Module class.
508   
509   This function is a part of the general copy/paste mechanism.
510
511   Can be re-implemented to customize the copy/paste handling 
512   in the module. Default implementation returns \c false.
513
514   \return \c true if the module can perform "copy" operation or \c false otherwise
515   \sa canPaste(), copy(), paste()
516 */
517 bool HELLOGUI::canCopy() const
518 {
519   // copy/paste is not supported, in this example just call the parent implementation
520   return SalomeApp_Module::canCopy();
521 }
522
523 /*!
524   \brief Check if the module can perform "paste" operation.
525
526   Overloaded from LightApp_Module class.
527   
528   This function is a part of the general copy/paste mechanism.
529
530   Can be re-implemented to customize the copy/paste handling 
531   in the module. Default implementation returns \c false.
532
533   \return \c true if the module can perform "paste" operation or \c false otherwise
534   \sa canCopy(), copy(), paste()
535 */
536 bool HELLOGUI::canPaste() const
537 {
538   // copy/paste is not supported, in this example just call the parent implementation
539   return SalomeApp_Module::canPaste();
540 }
541
542 /*!
543   \brief Perform "copy" operation.
544
545   Overloaded from LightApp_Module class.
546   
547   This function is a part of the general copy/paste mechanism.
548
549   Can be re-implemented to customize the copy/paste handling 
550   in the module. Default implementation does nothing.
551
552   \sa canCopy(), canPaste(), paste()
553 */
554 void HELLOGUI::copy()
555 {
556   // copy/paste is not supported, nothing to do here
557 }
558
559 /*!
560   \brief Perform "paste" operation.
561
562   Overloaded from LightApp_Module class.
563   
564   This function is a part of the general copy/paste mechanism.
565
566   Can be re-implemented to customize the copy/paste handling 
567   in the module. Default implementation does nothing.
568
569   \sa canCopy(), canPaste(), copy()
570 */
571 void HELLOGUI::paste()
572 {
573   // copy/paste is not supported, nothing to do here
574 }
575
576 /*!
577   \brief Check if the module allows "drag" operation of its objects.
578
579   Overloaded from LightApp_Module class.
580   
581   This function is a part of the general drag-n-drop mechanism.
582   The goal of this function is to check data object passed as a parameter
583   and decide if it can be dragged or no.
584
585   \param what data object being tested for drag operation
586   \return \c true if module allows dragging of the specified object
587   \sa isDropAccepted(), dropObjects()
588 */
589 bool HELLOGUI::isDraggable( const SUIT_DataObject* what ) const
590 {
591   // we allow dragging any HELLO object, except the top-level component
592   const SalomeApp_ModuleObject* aModObj = dynamic_cast<const SalomeApp_ModuleObject*>( what );
593   return ( aModObj == 0 );
594 }
595
596 /*!
597   \brief Check if the module allows "drop" operation on the given object.
598
599   Overloaded from LightApp_Module class.
600
601   This function is a part of the general drag-n-drop mechanism.
602   The goal of this function is to check data object passed as a parameter
603   and decide if it can be used as a target for the "drop" operation.
604   The processing of the drop operation itself is done in the dropObjects() function.
605
606   \param where target data object
607   \return \c true if module supports dropping on the \a where data object
608   \sa isDraggable(), dropObjects()
609 */
610 bool HELLOGUI::isDropAccepted( const SUIT_DataObject* where ) const
611 {
612   // we allow dropping of all objects
613   // (temporarily implementation, we also need to check objects being dragged)
614   return true;
615 }
616
617 /*!
618   \brief Complete drag-n-drop operation.
619   
620   Overloaded from LightApp_Module class.
621
622   This function is a part of the general drag-n-drop mechanism.
623   Its goal is to handle dropping of the objects being dragged according
624   to the chosen operation (copy or move). The dropping is performed in the
625   context of the parent data object \a where and the \a row (position in the 
626   children index) at which the data should be dropped. If \a row is equal to -1,
627   this means that objects are added to the end of the children list.
628
629   \param what objects being dropped
630   \param where target data object
631   \param row child index at which the drop operation is performed
632   \param action drag-n-drop operation (Qt::DropAction) - copy or move
633
634   \sa isDraggable(), isDropAccepted()
635 */
636 void HELLOGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
637                             const int row, Qt::DropAction action )
638 {
639   if (action != Qt::CopyAction && action != Qt::MoveAction)
640     return; // unsupported action
641
642   // get parent object
643   SalomeApp_DataObject* dataObj = dynamic_cast<SalomeApp_DataObject*>( where );
644   if ( !dataObj ) return; // wrong parent
645   _PTR(SObject) parentObj = dataObj->object();
646
647   // collect objects being dropped
648   HELLO_ORB::object_list_var objects = new HELLO_ORB::object_list();
649   objects->length( what.count() );
650   int count = 0;
651   for ( int i = 0; i < what.count(); i++ ) {
652     dataObj = dynamic_cast<SalomeApp_DataObject*>( what[i] );
653     if ( !dataObj ) continue;  // skip wrong objects
654     _PTR(SObject) sobj = dataObj->object();
655     objects[i] = _CAST(SObject, sobj)->GetSObject();
656     count++;
657   }
658   objects->length( count );
659
660   // call engine function
661   engine()->copyOrMove( objects.in(),                              // what
662                         _CAST(SObject, parentObj)->GetSObject(),   // where
663                         row,                                       // row
664                         action == Qt::CopyAction );                // isCopy
665
666   // update Object browser
667   getApp()->updateObjectBrowser( false );
668 }
669
670 /*!
671   \brief Module activation.
672   
673   Overloaded from CAM_Module class.
674   
675   This function is called each time the module is activated
676   by the user. It is usually used to perform any relevant actions,
677   like displaying menus and toolbars, connecting specific signals/slots, etc.
678   
679   \param theStudy current study object
680   \return \c true if activation is completed correctly or \c false
681           if module activation fails
682   
683   \sa deactivateModule()
684 */
685 bool HELLOGUI::activateModule( SUIT_Study* theStudy )
686 {
687   // call parent implementation
688   bool bOk = SalomeApp_Module::activateModule( theStudy );
689
690   // show own menus
691   setMenuShown( true );
692   // show own toolbars
693   setToolShown( true );
694
695   // return the activation status
696   return bOk;
697 }
698
699 /*!
700   \brief Module deactivation.
701   
702   Overloaded from CAM_Module class.
703   
704   This function is called each time the module is deactivated
705   by the user. It is usually used to perform any relevant actions,
706   like hiding menus and toolbars, disconnecting specific signals/slots, etc.
707   
708   \param theStudy current study object
709   \return \c true if deactivation is completed correctly or \c false
710           if module deactivation fails
711
712   \sa activateModule()
713 */
714 bool HELLOGUI::deactivateModule( SUIT_Study* theStudy )
715 {
716   // hide own menus
717   setMenuShown( false );
718   // hide own toolbars
719   setToolShown( false );
720
721   // call parent implementation and return the activation status
722   return SalomeApp_Module::deactivateModule( theStudy );
723 }
724
725 /*!
726   \brief Create specific operation object.
727   
728   Overloaded from LightApp_Module class.
729   
730   This function is a part of operation management mechanism.
731   It can be used to create module specific operations, if module
732   implements transaction handling basing on the GUI operations instances.
733
734   This function is automatically called from startOperation() function.
735   After operation is created, it can be started/stopped/paused/resumed etc.
736   Compatibility between diferent simultaneously running operations is also
737   checked by invoking of the corresponding methods of the LightApp_Operation
738   class.
739
740   The application takes ownership over the returned pointer, 
741   so you should not destroy it.
742
743   Default implementation in LightApp_Module class processes common Show/Hide
744   operations.
745
746   \param id unique operation identifier
747   \return new operation object
748 */
749 LightApp_Operation* HELLOGUI::createOperation( const int id ) const
750 {
751   // no specific operations, in this example just call the parent implementation
752   return SalomeApp_Module::createOperation( id );
753 }
754
755 /*!
756   \brief Action slot: Test me
757 */
758 void HELLOGUI::testMe()
759 {
760   SUIT_MessageBox::information( getApp()->desktop(),
761                                 tr( "INF_TESTME_TITLE" ),
762                                 tr( "INF_TESTME_MSG" ),
763                                 tr( "BUT_OK" ) );
764 }
765
766 /*!
767   \brief Action slot: Hello
768 */
769 void HELLOGUI::hello()
770 {
771   // request user name
772   bool ok;
773   QString name = QInputDialog::getText( getApp()->desktop(), tr( "QUE_HELLO_TITLE" ), tr( "QUE_ENTER_NAME" ),
774                                         QLineEdit::Normal, QString::null, &ok );
775
776   if ( ok && !name.trimmed().isEmpty() ) {
777     // say hello to SALOME
778     HELLO_ORB::status status = engine()->hello( (const char*)name.toLatin1() );
779
780     // update Object browser
781     getApp()->updateObjectBrowser(true);
782
783     // process operation status
784     switch( status ) {
785     case HELLO_ORB::OP_OK:
786       // everything's OK
787       SUIT_MessageBox::information( getApp()->desktop(),
788                                     tr( "INF_HELLO_TITLE" ), 
789                                     tr( "INF_HELLO_MSG" ).arg( name ),
790                                     tr( "BUT_OK" ) );
791       break;
792     case HELLO_ORB::OP_ERR_ALREADY_MET:
793       // error: already said hello
794       SUIT_MessageBox::warning( getApp()->desktop(),
795                                 tr( "INF_HELLO_TITLE" ), 
796                                 tr( "ERR_HELLO_ALREADY_MET" ).arg( name ),
797                                 tr( "BUT_OK" ) );
798       break;
799     case HELLO_ORB::OP_ERR_UNKNOWN:
800     default:
801       // other errors
802       SUIT_MessageBox::critical( getApp()->desktop(),
803                                  tr( "INF_HELLO_TITLE" ), 
804                                  tr( "ERR_ERROR" ),
805                                  tr( "BUT_OK" ) );
806       break;
807     }
808   }
809 }
810
811 /*!
812   \brief Action slot: Goodbye
813 */
814 void HELLOGUI::goodbye()
815 {
816   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
817   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
818   _PTR(Study) studyDS = study->studyDS();
819   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
820
821   QString name;
822
823   // get selection
824   SALOME_ListIO selected;
825   aSelMgr->selectedObjects( selected );
826   if ( selected.Extent() == 1 ) {
827     Handle(SALOME_InteractiveObject) io = selected.First();
828     _PTR(SObject) so = studyDS->FindObjectID( io->getEntry() );
829     if ( so ) { 
830       _PTR(SComponent) comp = so->GetFatherComponent();
831       if ( comp && comp->ComponentDataType() == "HELLO" && io->getEntry() != comp->GetID() ) {
832         name = so->GetName().c_str();
833       }
834     }
835   }
836
837   // request user name if not specified
838   if ( name.isEmpty() ) {
839     bool ok;
840     name = QInputDialog::getText( getApp()->desktop(), tr( "QUE_GOODBYE_TITLE" ), tr( "QUE_ENTER_NAME" ),
841                                   QLineEdit::Normal, QString::null, &ok );
842   }
843
844   if ( !name.trimmed().isEmpty() ) {
845     // say goodby to SALOME
846     HELLO_ORB::status status = engine()->goodbye( (const char*)name.toLatin1() );
847
848     // update Object browser
849     getApp()->updateObjectBrowser(true);
850
851     // process operation status
852     switch( status ) {
853     case HELLO_ORB::OP_OK:
854       // everything's OK
855       SUIT_MessageBox::information( getApp()->desktop(),
856                                     tr( "INF_GOODBYE_TITLE" ), 
857                                     tr( "INF_GOODBYE_MSG" ).arg( name ),
858                                     tr( "BUT_OK" ) );
859       break;
860     case HELLO_ORB::OP_ERR_DID_NOT_MEET:
861       // error: did not say hello yet
862       SUIT_MessageBox::warning( getApp()->desktop(),
863                                 tr( "INF_GOODBYE_TITLE" ), 
864                                 tr( "ERR_GOODBYE_DID_NOT_MEET" ).arg( name ),
865                                 tr( "BUT_OK" ) );
866       break;
867     case HELLO_ORB::OP_ERR_UNKNOWN:
868     default:
869       // other errors
870       SUIT_MessageBox::critical( getApp()->desktop(),
871                                  tr( "INF_GOODBYE_TITLE" ), 
872                                  tr( "ERR_ERROR" ),
873                                  tr( "BUT_OK" ) );
874       break;
875     }
876   }
877 }
878
879 /*!
880   \brief Perform internal initialization
881   
882   In particular, this function initializes module engine.
883 */
884 void HELLOGUI::init()
885 {
886   // initialize HELLO module engine (load, if necessary)
887   if ( CORBA::is_nil( myEngine ) )
888   {
889     SALOME_NamingService_Abstract *ns = SalomeApp_Application::namingService();
890     Engines::EngineComponent_var comp;
891     if(ns->IsTrueNS())
892     {
893       comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "HELLO" );
894     }
895     else
896     {
897       comp = RetrieveHELLOInstance();
898       CORBA::Object_var comp2 = CORBA::Object::_narrow(comp);
899       KERNEL::RegisterCompo("HELLO",comp2);
900     }
901     myEngine = HELLO_ORB::HELLO_Gen::_narrow( comp );
902   }
903 }
904
905 // Export the module
906 extern "C" {
907   // FACTORY FUNCTION: create an instance of the Hello module GUI
908   HELLO_EXPORT
909   CAM_Module* createModule()
910   {
911     return new HELLOGUI();
912   }
913   // VERSIONING FUNCTION: get Hello module's version identifier
914   HELLO_EXPORT
915   char* getModuleVersion() 
916   {
917     return (char*)HELLO_VERSION_STR; // HELLO_VERSION_STR is defined in HELLO_version.h
918   }
919 }