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