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