Salome HOME
Add method to Python API (SalomePyQt) to register module in the study tree
[modules/gui.git] / src / SALOME_PYQT / SalomePyQt / SalomePyQt.cxx
1 // Copyright (C) 2007-2020  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 // File   : SalomePyQt.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25
26 #ifdef WIN32
27 // E.A. : On windows with python 2.6, there is a conflict
28 // E.A. : between pymath.h and Standard_math.h which define
29 // E.A. : some same symbols : acosh, asinh, ...
30 #include <Standard_math.hxx>
31 #include <pymath.h>
32 #endif
33
34 #include "SALOME_PYQT_ModuleLight.h" // this include must be first!!!
35 #include "SALOME_PYQT_DataModelLight.h"
36 #include "SALOME_PYQT_PyModule.h"
37 #include "SalomePyQt.h"
38
39 #include "LightApp_SelectionMgr.h"
40 #include "LogWindow.h"
41 #ifndef DISABLE_OCCVIEWER
42 #include "OCCViewer_ViewWindow.h"
43 #include "OCCViewer_ViewFrame.h"
44 #endif // DISABLE_OCCVIEWER
45 #ifndef DISABLE_VTKVIEWER
46 #include "SVTK_ViewWindow.h"
47 #endif // DISABLE_VTKVIEWER
48 #ifndef DISABLE_PLOT2DVIEWER
49 #include "Plot2d_ViewManager.h"
50 #include "Plot2d_ViewWindow.h"
51 #endif // DISABLE_PLOT2DVIEWER
52 #ifndef DISABLE_PVVIEWER
53 #include "PVViewer_ViewManager.h"
54 #include "PVViewer_ViewModel.h"
55 #endif // DISABLE_PVVIEWER
56 #include "QtxActionMenuMgr.h"
57 #include "QtxWorkstack.h"
58 #include "QtxTreeView.h"
59 #include "SALOME_Event.h"
60 #include "STD_TabDesktop.h"
61 #include "SUIT_DataBrowser.h"
62 #include "SUIT_ResourceMgr.h"
63 #include "SUIT_Session.h"
64 #include "SUIT_Tools.h"
65 #include "SUIT_ViewManager.h"
66 #include "SUIT_ViewWindow.h"
67 #include "PyConsole_Console.h"
68
69 #include <QAction>
70 #include <QApplication>
71 #include <QPaintEvent>
72 #include <QCoreApplication>
73 #include <QVBoxLayout>
74
75 #include <utilities.h>
76
77 namespace
78 {
79   /*!
80     \brief Get the currently active application.
81     \internal
82     \return active application object or 0 if there is no any
83   */
84   LightApp_Application* getApplication()
85   {
86     if ( SUIT_Session::session() )
87       return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
88     return 0;
89   }
90   
91   /*!
92     \brief Get the currently active study.
93     \internal
94     \return active study or 0 if there is no study opened
95   */
96   LightApp_Study* getActiveStudy()
97   {
98     if ( getApplication() )
99       return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
100     return 0;
101   }
102
103   /*!
104     \brief Get the currently active module.
105     \internal
106     This function returns correct result only if Python-based
107     module is currently active. Otherwize, 0 is returned.
108   */
109   LightApp_Module* getActiveModule()
110   {
111     LightApp_Module* module = 0;
112     if ( LightApp_Application* anApp = getApplication() ) {
113       module = PyModuleHelper::getInitModule();
114       if ( !module )
115         module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
116     }
117     return module;
118   }
119   
120   /*!
121     \brief Get the currently active Python module's helper.
122     \internal
123     This function returns correct result only if Python-based
124     module is currently active. Otherwize, 0 is returned.
125   */
126   PyModuleHelper* getPythonHelper()
127   {
128     LightApp_Module* module = getActiveModule();
129     PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
130     return helper;
131   }
132   
133   /*!
134     \brief Get SALOME verbose level
135     \internal
136     \return \c true if SALOME debug output is allowed or \c false otherwise
137   */
138   bool verbose()
139   {
140     bool isVerbose = false;
141     if ( getenv( "SALOME_VERBOSE" ) ) {
142       QString envVar = getenv( "SALOME_VERBOSE" );
143       bool ok;
144       int value = envVar.toInt( &ok );
145       isVerbose = ok && value != 0;
146     }
147     return isVerbose;
148   }
149
150   /*!
151     \brief Get menu item title
152     \internal
153     \param menuId menu identifier
154     \return menu title (localized)
155   */
156   QString getMenuName( const QString& menuId )
157   {
158     QStringList contexts;
159     contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
160       "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
161     QString menuName = menuId;
162     for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
163       menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
164     return menuName;
165   }
166
167   /*!
168     \brief Load module icon
169     \internal
170     \param module module name
171     \param fileName path to the icon file
172     \return icon
173   */
174   QIcon loadIconInternal( const QString& module, const QString& fileName )
175   {
176     QIcon icon;
177     
178     LightApp_Application* app = getApplication();
179     
180     if ( app && !fileName.isEmpty() ) {
181       QPixmap pixmap = app->resourceMgr()->loadPixmap( module, 
182                                                        QApplication::translate( module.toLatin1().data(), 
183                                                                                 fileName.toUtf8().data() ) );
184       if ( !pixmap.isNull() )
185         icon = QIcon( pixmap );
186     }
187     return icon;
188   }
189
190   /*!
191     \brief Gets window with specified identifier 
192     \internal
193     \param id window identifier 
194     \return pointer on the window
195   */
196   SUIT_ViewWindow* getWnd( const int id )
197   {
198     SUIT_ViewWindow* resWnd = 0;
199     
200     LightApp_Application* app = getApplication();
201     if ( app ) {
202       ViewManagerList vmlist = app->viewManagers();
203       foreach( SUIT_ViewManager* vm, vmlist ) {
204         QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
205         foreach ( SUIT_ViewWindow* vw, vwlist ) {
206           if ( id == vw->getId() ) {
207             resWnd = vw;
208             break;
209           }
210         }
211       }
212     }
213     return resWnd;
214   }
215
216   /*!
217     \brief Map of created selection objects.
218     \internal
219   */
220   QMap<LightApp_Application*, SALOME_Selection*> SelMap;
221
222   /*!
223     \brief Default resource file section name.
224     \internal
225   */
226   const char* DEFAULT_SECTION = "SalomePyQt";
227 }
228
229 /*!
230   \class SALOME_Selection
231   \brief The class represents selection which can be used in Python.
232 */
233
234 /*!
235   \brief Get the selection object for the specified application.
236
237   Finds or creates the selection object (one per study).
238
239   \param app application object
240   \return selection object or 0 if \a app is invalid
241 */
242 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
243 {
244   SALOME_Selection* sel = 0;
245   if ( app && SelMap.find( app ) != SelMap.end() )
246     sel = SelMap[ app ];
247   else 
248     sel = SelMap[ app ] = new SALOME_Selection( app );
249   return sel;
250 }
251
252
253 /*!
254   \brief Constructor.
255   \param p parent object
256 */
257 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
258 {
259   LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
260   if ( app ) {
261     mySelMgr = app->selectionMgr();
262     connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
263     connect( mySelMgr, SIGNAL( destroyed() ),        this, SLOT  ( onSelMgrDestroyed() ) );
264   }
265 }
266
267 /*!
268   \brief Destructor.
269 */
270 SALOME_Selection::~SALOME_Selection()
271 {
272   LightApp_Application* app = 0;
273   QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
274   for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
275     if ( it.value() == this ) app = it.key();
276   }
277   if ( app ) SelMap.remove( app );
278 }
279
280 /*!
281   \brief Called when selection manager is destroyed (usually 
282   when the study is closed).
283 */
284 void SALOME_Selection::onSelMgrDestroyed()
285 {
286   mySelMgr = 0;
287 }
288
289 /*!
290   \brief Clear the selection.
291 */
292 void SALOME_Selection::Clear()
293 {
294   class TEvent: public SALOME_Event
295   {
296     LightApp_SelectionMgr* mySelMgr;
297   public:
298     TEvent( LightApp_SelectionMgr* selMgr ) 
299       : mySelMgr( selMgr ) {}
300     virtual void Execute() 
301     {
302       if ( mySelMgr )
303         mySelMgr->clearSelected();
304     }
305   };
306   ProcessVoidEvent( new TEvent( mySelMgr ) );
307 }
308
309 /*!
310   \brief Clear the selection.
311 */
312 void SALOME_Selection::ClearIObjects()
313 {
314   Clear();
315 }
316
317 /*!
318   Removes all selection filters.
319 */
320 void SALOME_Selection::ClearFilters()
321 {
322   class TEvent: public SALOME_Event 
323   {
324     LightApp_SelectionMgr* mySelMgr;
325   public:
326     TEvent( LightApp_SelectionMgr* selMgr ) 
327       : mySelMgr( selMgr ) {}
328     virtual void Execute() 
329     {
330       if ( mySelMgr )
331         mySelMgr->clearFilters();
332     }
333   };
334   ProcessVoidEvent( new TEvent( mySelMgr ) );
335 }
336
337 /*!
338   \class UserDefinedContent
339   \brief The class represents base class for user defined widget that
340   can be inserted to the Preferences dialog.
341 */
342
343 /*!
344   \brief Constructor
345 */
346 UserDefinedContent::UserDefinedContent()
347   : QWidget()
348 {
349 }
350
351 /*!
352   \brief Called from Preferences dialog to store settings to the resource file.
353 */
354 void UserDefinedContent::store()
355 {
356 }
357
358 /*!
359   \brief Called from Preferences dialog to restore settings from the resource file.
360 */
361 void UserDefinedContent::retrieve()
362 {
363 }
364
365 /*!
366   \class SgPyQtUserDefinedContent
367   \brief A Wrapper for UserDefinedContent class.
368   \internal
369 */
370 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
371 {
372 public:
373   SgPyQtUserDefinedContent(UserDefinedContent*);
374   virtual ~SgPyQtUserDefinedContent();
375
376   void store( QtxResourceMgr*, QtxPreferenceMgr* );
377   void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
378
379 private:
380   UserDefinedContent* myContent;
381 };
382
383 /*!
384   \brief Create custom item for Preferences dialog wrapping widget passed from Python.
385   \internal
386 */
387 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
388   : QtxUserDefinedContent( 0 ), myContent( content )
389 {
390   QVBoxLayout* l = new QVBoxLayout( this );
391   l->setContentsMargins( 0, 0, 0, 0 );
392   l->addWidget( myContent );
393 }
394
395 /*!
396   \brief Destructor.
397   \internal
398 */
399 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
400 {
401 }
402
403 /*!
404   \brief Called from Preferences dialog to store settings to the resource file.
405   \internal
406 */
407 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
408 {
409   myContent->store();
410 }
411
412 /*!
413   \brief Called from Preferences dialog to restore settings from the resource file.
414   \internal
415 */
416 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
417 {
418   myContent->retrieve();
419 }
420
421 /*!
422   \class SalomePyQt
423   \brief The class provides utility functions which can be used in the Python
424   to operate with the SALOME GUI.
425
426   All the functionality of this class is implemented as static methods, so they
427   can be called with the class name prefixed or via creation of the class instance.
428   For example, next both ways of SalomePyQt class usage are legal:
429   \code
430   from SalomePyQt import *
431   sg = SalomePyQt()
432   # using SalomePyQt class instance
433   desktop = sg.getDesktop()
434   # using SalomePyQt class directly
435   menubar = SalomePyQt.getMainMenuBar()
436   \endcode
437 */
438
439 /*!
440   \fn QString SalomePyQt::getAppName();
441   \brief Get application name
442   \return application name
443 */
444
445 QString SalomePyQt::getAppName()
446 {
447   LightApp_Application* app = getApplication();
448   return app == 0 ? QString() : QString(app->metaObject()->className()).split("_").first();
449 }
450
451 /*!
452   \fn bool SalomePyQt::isLightApp();
453   \brief Check if SALOME GUI is running in "light" mode.
454   \return \c true if this is a "light" application; \c false otherwise
455 */
456
457 bool SalomePyQt::isLightApp()
458 {
459   return SalomePyQt::getAppName() != "SalomeApp";
460 }
461
462 /*!
463   \fn QWidget* SalomePyQt::getDesktop();
464   \brief Get the active application's desktop window.
465   \return desktop window or 0 if there is no any
466 */
467
468 class TGetDesktopEvent: public SALOME_Event 
469 {
470 public:
471   typedef QWidget* TResult;
472   TResult myResult;
473   TGetDesktopEvent() : myResult( 0 ) {}
474   virtual void Execute()
475   {
476     if ( getApplication() )
477       myResult = (QWidget*)( getApplication()->desktop() );
478   }
479 };
480 QWidget* SalomePyQt::getDesktop()
481 {
482   return ProcessEvent( new TGetDesktopEvent() );
483 }
484
485 /*!
486   \fn QWidget* SalomePyQt::getMainFrame();
487   \brief Get current application's main frame widget [obsolete].
488
489   Main frame widget is an internal widget of the application 
490   desktop window (workspace).
491
492   \return workspace widget (0 on any error)
493 */
494
495 class TGetMainFrameEvent: public SALOME_Event
496 {
497 public:
498   typedef QWidget* TResult;
499   TResult myResult;
500   TGetMainFrameEvent() : myResult( 0 ) {}
501   virtual void Execute()
502   {
503     if ( getApplication() ) {
504       SUIT_Desktop* aDesktop = getApplication()->desktop();
505       myResult = (QWidget*)( aDesktop->centralWidget() );
506     }
507   }
508 };
509 QWidget* SalomePyQt::getMainFrame()
510 {
511   return ProcessEvent( new TGetMainFrameEvent() );
512 }
513
514 /*!
515   \fn QMenuBar* SalomePyQt::getMainMenuBar();
516   \brief Get current application desktop's main menu.
517   \return main menu object (0 on any error)
518 */
519
520 class TGetMainMenuBarEvent: public SALOME_Event
521 {
522 public:
523   typedef QMenuBar* TResult;
524   TResult myResult;
525   TGetMainMenuBarEvent() : myResult( 0 ) {}
526   virtual void Execute()
527   {
528     if ( LightApp_Application* anApp = getApplication() ) {
529       myResult = anApp->desktop()->menuBar();
530     }
531   }
532 };
533 QMenuBar* SalomePyQt::getMainMenuBar() 
534 {
535   return ProcessEvent( new TGetMainMenuBarEvent() );
536 }
537
538 /*!
539   \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
540   \brief Get main menu's child popup submenu by its identifier.
541   
542   This function is obsolete. 
543   Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
544
545   \param menu menu identifier
546   \return popup submenu object or 0 if it does not exist
547 */
548
549 /*!
550   \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
551   \brief Get main menu's child popup submenu by its name.
552   
553   The function creates menu if it does not exist.
554
555   \param menu menu name
556   \return popup submenu object (0 on any error)
557 */
558
559 class TGetPopupMenuEvent: public SALOME_Event
560 {
561 public:
562   typedef QMenu* TResult;
563   TResult myResult;
564   QString myMenuName;
565   TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
566   virtual void Execute()
567   {
568     LightApp_Application* anApp = getApplication();
569     if ( anApp && !myMenuName.isEmpty() ) {
570       QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
571       myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
572     }
573   }
574 };
575
576 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
577 {
578   QString menuName;
579   switch( menu ) {
580   case File:
581     menuName = getMenuName( "MEN_DESK_FILE" );        break;
582   case View:
583     menuName = getMenuName( "MEN_DESK_VIEW" );        break;
584   case Edit:
585     menuName = getMenuName( "MEN_DESK_EDIT" );        break;
586   case Preferences:
587     menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
588   case Tools:
589     menuName = getMenuName( "MEN_DESK_TOOLS" );       break;
590   case Window:
591     menuName = getMenuName( "MEN_DESK_WINDOW" );      break;
592   case Help:
593     menuName = getMenuName( "MEN_DESK_HELP" );        break;
594   }
595   return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
596 }
597 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
598 {
599   return ProcessEvent( new TGetPopupMenuEvent( menu ) );
600 }
601
602 /*!
603   \fn QTreeView* SalomePyQt::getObjectBrowser();
604   \brief Get object browser
605   \return object browser for the active study or 0 in case of error
606 */
607
608 class TGetObjectBrowserEvent: public SALOME_Event
609 {
610 public:
611   typedef QTreeView* TResult;
612   TResult myResult;
613   TGetObjectBrowserEvent() : myResult( 0 ) {}
614   virtual void Execute()
615   {
616     LightApp_Application* anApp = getApplication();
617     if ( anApp && anApp->objectBrowser() ) {
618       myResult = anApp->objectBrowser()->treeView();
619     }
620   }
621 };
622 QTreeView* SalomePyQt::getObjectBrowser()
623 {
624   return ProcessEvent( new TGetObjectBrowserEvent() );
625 }
626
627 /*!
628   \fn SALOME_Selection* SalomePyQt::getSelection();
629   \brief Get the selection object for the current study.
630
631   Creates a Selection object if it has not been created yet.
632
633   \return selection object (0 on error)
634 */
635
636 class TGetSelectionEvent: public SALOME_Event 
637 {
638 public:
639   typedef SALOME_Selection* TResult;
640   TResult myResult;
641   TGetSelectionEvent() : myResult( 0 ) {}
642   virtual void Execute() 
643   {
644     myResult = SALOME_Selection::GetSelection( getApplication() );
645   }
646 };
647 SALOME_Selection* SalomePyQt::getSelection()
648 {
649   return ProcessEvent( new TGetSelectionEvent() );
650 }
651
652 /*!
653   \fn QStringList* SalomePyQt::setSelection(const QStringList& );
654   \brief Send local selection for notification.
655
656   The list of locally selected objects (study entries) is sent for notification of
657   other listening entities (modules, viewers...).
658 */
659
660 class TSetSelectionEvent: public SALOME_Event
661 {
662   QStringList myEntryList;
663 public:
664   TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
665   virtual void Execute()
666   {
667         SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
668         if ( !module ) return;
669         module->setLocalSelected(myEntryList);
670   }
671 };
672 void SalomePyQt::setSelection( const QStringList& entryList)
673 {
674   return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
675 }
676
677 /*!
678   \fn void SalomePyQt::enableSelector();
679   \brief enable PyQt_Selector (on module activation, for instance)
680 */
681
682 class TEnableSelectorEvent: public SALOME_Event
683 {
684 public:
685         TEnableSelectorEvent() {}
686   virtual void Execute()
687   {
688         SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
689         if ( !module ) return;
690         module->enableSelector();
691   }
692 };
693 void SalomePyQt::enableSelector()
694 {
695   return ProcessVoidEvent( new TEnableSelectorEvent() );
696 }
697
698
699 /*!
700   \fn void SalomePyQt::disableSelector();
701   \brief disable PyQt_Selector (on module activation, for instance)
702 */
703
704 class TdisableSelectorEvent: public SALOME_Event
705 {
706 public:
707         TdisableSelectorEvent() {}
708   virtual void Execute()
709   {
710         SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
711         if ( !module ) return;
712         module->disableSelector();
713   }
714 };
715 void SalomePyQt::disableSelector()
716 {
717   return ProcessVoidEvent( new TdisableSelectorEvent() );
718 }
719
720
721 /*!
722   \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
723   \brief Put an information message to the current application's 
724   desktop status bar.
725
726   Optional second delay parameter (\a sec) can be used to specify
727   time of the message diplaying in seconds. If this parameter is less
728   or equal to zero, the constant message will be put.
729
730   \param msg message text 
731   \param sec message displaying time in seconds
732 */
733
734 class TPutInfoEvent: public SALOME_Event
735 {
736   QString myMsg;
737   int     mySecs;
738 public:
739   TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
740   virtual void Execute()
741   {
742     if ( LightApp_Application* anApp = getApplication() ) {
743       anApp->putInfo( myMsg, mySecs * 1000 );
744     }
745   }
746 };
747 void SalomePyQt::putInfo( const QString& msg, const int sec )
748 {
749   ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
750 }
751
752 /*!
753   \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
754   \brief Show notification in the application's desktop window.
755
756   Optional third delay parameter (\a sec) can be used to specify
757   time of the notification diplaying in seconds. If this parameter is less
758   or equal to zero, the permanent notification will be put.
759
760   Notification can be forcibly hidden via hideNotification() method.
761
762   \param msg message text 
763   \param title title text 
764   \param sec notification displaying time in seconds
765   \return unique ID of the notification (can be used to hide notification)
766   \sa hideNotification()
767 */
768
769 class TShowNotifyEvent: public SALOME_Event
770 {
771   QString myMsg;
772   QString myTitle;
773   int     mySecs;
774
775 public:
776   typedef int TResult;
777   TResult myResult;
778
779 public:
780   TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
781   virtual void Execute()
782   {
783     if ( LightApp_Application* anApp = getApplication() ) {
784       myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
785     }
786   }
787 };
788
789 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
790 {
791   return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
792 }
793
794 /*!
795   \fn void SalomePyQt::hideNotification( const QString& msg );
796   \brief Remove notification with given message text from the application's desktop.
797
798   \param msg message text
799   \sa showNotification()
800 */
801
802 /*!
803   \fn void SalomePyQt::hideNotification( const int id );
804   \brief Remove notification with given \a id from the application's desktop.
805
806   \param id notification id
807   \sa showNotification()
808 */
809
810 class THideNotifyEvent: public SALOME_Event
811 {
812   int     myId;
813   QString myMsg;
814
815 public:
816   THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
817   THideNotifyEvent( const int id ) : myId( id ) {}
818   virtual void Execute()
819   {
820     if ( LightApp_Application* anApp = getApplication() ) {
821       if ( myId >= 0 )
822        anApp->hideNotification( myId );
823       else
824        anApp->hideNotification( myMsg );
825     }
826   }
827 };
828
829 void SalomePyQt::hideNotification( const QString& msg )
830 {
831   ProcessVoidEvent( new THideNotifyEvent( msg ) );
832 }
833
834 void SalomePyQt::hideNotification( const int id )
835 {
836   ProcessVoidEvent( new THideNotifyEvent( id ) );
837 }
838
839 /*!
840   \fn QStringList SalomePyQt::getComponents();
841   \brief Get all modules used in current GUI session.
842   \return List of modules
843 */
844
845 class TGetComponentsEvent: public SALOME_Event
846 {
847 public:
848   typedef QStringList TResult;
849   TResult myResult;
850   TGetComponentsEvent() {}
851   virtual void Execute() 
852   {
853     if ( LightApp_Application* anApp = getApplication() )
854     {
855       QStringList titles;
856       anApp->modules( titles, false );
857       foreach ( QString title, titles )
858       {
859         myResult << anApp->moduleName( title );
860       }
861     }
862   }
863 };
864 QStringList SalomePyQt::getComponents()
865 {
866   return ProcessEvent( new TGetComponentsEvent() );
867 }
868
869 /*!
870   \fn const QString SalomePyQt::getActiveComponent();
871   \brief Get the currently active module name (for the current study).
872   \return active module name or empty string if there is no active module
873 */
874
875 class TGetActiveComponentEvent: public SALOME_Event
876 {
877 public:
878   typedef QString TResult;
879   TResult myResult;
880   TGetActiveComponentEvent() {}
881   virtual void Execute() 
882   {
883     if ( LightApp_Application* anApp = getApplication() ) {
884       if ( CAM_Module* mod = anApp->activeModule() ) {
885         myResult = mod->name();
886       }
887     }
888   }
889 };
890 const QString SalomePyQt::getActiveComponent()
891 {
892   return ProcessEvent( new TGetActiveComponentEvent() );
893 }
894
895 /*!
896   \fn PyObject* SalomePyQt::getActivePythonModule();
897   \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
898   \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
899 */
900
901 class TGetActivePyModuleEvent: public SALOME_Event
902 {
903 public:
904   typedef PyObject* TResult;
905   TResult myResult;
906   TGetActivePyModuleEvent() : myResult( Py_None ) {}
907   virtual void Execute() 
908   {
909     PyModuleHelper* helper = getPythonHelper();
910     if ( helper )
911       myResult = (PyObject*)helper->pythonModule();
912   }
913 };
914 PyObject* SalomePyQt::getActivePythonModule()
915 {
916   return ProcessEvent( new TGetActivePyModuleEvent() );
917 }
918
919 /*!
920   \fn bool SalomePyQt::activateModule( const QString& modName );
921   \brief Activates SALOME module with the given name
922   \return True if the module has been activated and False otherwise.
923 */
924
925 class TActivateModuleEvent: public SALOME_Event
926 {
927 public:
928   typedef bool TResult;
929   TResult myResult;
930   QString myModuleName;
931   TActivateModuleEvent( const QString& modName ) 
932   : myResult( false ), myModuleName( modName ) {}
933   virtual void Execute() 
934   {
935     if ( LightApp_Application* anApp = getApplication() ) {
936       myResult = anApp->activateModule( myModuleName );
937     }
938   }
939 };
940 bool SalomePyQt::activateModule( const QString& modName )
941 {
942   return ProcessEvent( new TActivateModuleEvent( modName ) );
943 }
944
945 /*!
946   \fn void SalomePyQt::registerModule( const QString& modName);
947   \brief Registers module in the study tree
948 */
949
950 void SalomePyQt::registerModule( const QString& modName)
951 {
952   class TEvent: public SALOME_Event
953   {
954     QString myName;
955   public:
956     TEvent(const QString& name): myName(name) {}
957     virtual void Execute()
958     {
959       if ( LightApp_Application* anApp = getApplication() ) {
960         anApp->desktop()->emitMessage(QString("register_module_in_study/%1").arg(myName));
961       }
962     }
963   };
964   ProcessVoidEvent( new TEvent(modName) );
965 }
966
967 /*!
968   \brief Update an Object Browser of the study.
969 */
970 void SalomePyQt::updateObjBrowser()
971 {  
972   class TEvent: public SALOME_Event
973   {
974   public:
975     TEvent() {}
976     virtual void Execute()
977     {
978       if ( SUIT_Session::session() ) {
979         if ( getActiveStudy() ) {
980           QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
981           QList<SUIT_Application*>::Iterator it;
982           for( it = apps.begin(); it != apps.end(); ++it ) {
983             LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
984             if ( anApp && anApp->activeStudy() ) {
985               anApp->updateObjectBrowser();
986               return;
987             }
988           }
989         }
990       }
991     }
992   };
993   ProcessVoidEvent( new TEvent() );
994 }
995
996
997 /*!
998   SalomePyQt::isModified()
999   \return The modification status of the data model
1000   for the currently active Python module
1001   \note This function is supported for "light" Python-based SALOME modules only.
1002   \sa setModified()
1003 */
1004 class TIsModifiedEvent: public SALOME_Event
1005 {
1006 public:
1007   typedef bool TResult;
1008   TResult myResult;
1009   TIsModifiedEvent() : myResult( false ) {}
1010   virtual void Execute() 
1011   {
1012     LightApp_Module* module = getActiveModule();
1013     if ( !module )
1014       return;
1015     
1016     SALOME_PYQT_DataModelLight* aModel =
1017       dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1018     if ( aModel ) {
1019       myResult = aModel->isModified();
1020     }
1021     else {
1022       if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
1023     }
1024   }
1025 };
1026 bool SalomePyQt::isModified()
1027 {
1028   return ProcessEvent(new TIsModifiedEvent());
1029 }
1030
1031 /*!
1032   SalomePyQt::setModified()
1033
1034   Sets the modification status of the data model for 
1035   the currently active Python module. This method should be used
1036   by the Python code in order to enable/disable "Save" operation
1037   depending on the module's data state.
1038
1039   \note This function is supported for "light" Python-based SALOME modules only.
1040
1041   \param New modification status of the data model
1042
1043   \sa isModified()
1044 */
1045 void SalomePyQt::setModified( bool flag )
1046 {  
1047   class TEvent: public SALOME_Event
1048   {
1049     bool myFlag;
1050   public:
1051     TEvent( bool flag ) 
1052       : myFlag( flag ) {}
1053     virtual void Execute()
1054     {
1055       LightApp_Module* module = getActiveModule();
1056       if ( !module )
1057         return;
1058
1059       SALOME_PYQT_DataModelLight* model =
1060         dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1061
1062       LightApp_Application* app = module->getApp();
1063
1064       if ( model && app ) {
1065         model->setModified( myFlag );
1066         app->updateActions();
1067       }
1068       else {
1069         if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1070       }
1071     }
1072   };
1073   ProcessVoidEvent( new TEvent( flag ) );
1074 }
1075
1076 /*!
1077   \brief Add string setting to the application preferences.
1078
1079   The parameter \a autoValue is obsolete parameter and currently is not used.
1080   This parameter will be removed in future, so try to avoid its usage in 
1081   your code.
1082
1083   This function is obsolete. Use one of addSetting() instead.
1084
1085   \param name setting name (it should be of kind <section:setting> where
1086   \c section is resources section name and \c setting is setting name)
1087   \param value new setting value
1088   \param autoValue (not used)
1089 */
1090 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1091 {
1092   class TEvent: public SALOME_Event
1093   {
1094     QString myName;
1095     QString myValue;
1096     bool    myAutoValue;
1097   public:
1098     TEvent( const QString& name, const QString& value, bool autoValue ) 
1099       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1100     virtual void Execute()
1101     {
1102       if ( SUIT_Session::session() ) {
1103         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1104         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1105         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1106         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1107         if ( !_sec.isEmpty() && !_nam.isEmpty() )
1108           resMgr->setValue( _sec, _nam, myValue );
1109       }
1110     }
1111   };
1112   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1113 }
1114
1115 /*!
1116   \brief Add integer setting to the application preferences.
1117
1118   The parameter \a autoValue is obsolete parameter and currently is not used.
1119   This parameter will be removed in future, so try to avoid its usage in 
1120   your code.
1121
1122   This function is obsolete. Use one of addSetting() instead.
1123
1124   \param name setting name (it should be of kind <section:setting> where
1125   \c section is resources section name and \c setting is setting name)
1126   \param value new setting value
1127   \param autoValue (not used)
1128 */
1129 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1130 {
1131   class TEvent: public SALOME_Event 
1132   {
1133     QString myName;
1134     int     myValue;
1135     bool    myAutoValue;
1136   public:
1137     TEvent( const QString& name, const int value, bool autoValue ) 
1138       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1139     virtual void Execute()
1140     {
1141       if ( SUIT_Session::session() ) {
1142         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1143         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1144         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1145         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1146         if ( !_sec.isEmpty() && !_nam.isEmpty() )
1147           resMgr->setValue( _sec, _nam, myValue );
1148       }
1149     }
1150   };
1151   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1152 }
1153
1154 /*!
1155   \brief Add double setting to the application preferences.
1156
1157   The parameter \a autoValue is obsolete parameter and currently is not used.
1158   This parameter will be removed in future, so try to avoid its usage in 
1159   your code.
1160
1161   This function is obsolete. Use one of addSetting() instead.
1162
1163   \param name setting name (it should be of kind <section:setting> where
1164   \c section is resources section name and \c setting is setting name)
1165   \param value new setting value
1166   \param autoValue (not used)
1167 */
1168 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1169 {
1170   class TEvent: public SALOME_Event 
1171   {
1172     QString myName;
1173     double  myValue;
1174     bool    myAutoValue;
1175   public:
1176     TEvent( const QString& name, const double value, bool autoValue ) 
1177       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1178     virtual void Execute() 
1179     {
1180       if ( SUIT_Session::session() ) {
1181         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1182         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1183         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1184         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1185         if ( !_sec.isEmpty() && !_nam.isEmpty() )
1186           resMgr->setValue( _sec, _nam, myValue );
1187       }
1188     }
1189   };
1190   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1191 }
1192
1193 /*!
1194   \brief Add boolean setting to the application preferences.
1195
1196   The parameter \a autoValue is obsolete parameter and currently is not used.
1197   This parameter will be removed in future, so try to avoid its usage in 
1198   your code.
1199
1200   This function is obsolete. Use one of addSetting() instead.
1201
1202   \param name setting name (it should be of kind <section:setting> where
1203   \c section is resources section name and \c setting is setting name)
1204   \param value new setting value
1205   \param autoValue (not used)
1206 */
1207 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1208 {
1209   class TEvent: public SALOME_Event 
1210   {
1211     QString myName;
1212     bool    myValue;
1213     bool    myAutoValue;
1214   public:
1215     TEvent( const QString& name, const bool value, bool autoValue ) 
1216       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1217     virtual void Execute() 
1218     {
1219       if ( SUIT_Session::session() ) {
1220         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1221         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1222         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1223         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1224         if ( !_sec.isEmpty() && !_nam.isEmpty() )
1225           resMgr->setValue( _sec, _nam, myValue );
1226       }
1227     }
1228   };
1229   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1230 }
1231
1232 /*!
1233   \brief Remove setting from the application preferences.
1234
1235   This function is obsolete. Use removeSetting() instead.
1236
1237   \param name setting name (it should be of kind <section:setting> where
1238   \c section is resources section name and \c setting is setting name)
1239 */
1240 void SalomePyQt::removeSettings( const QString& name )
1241 {
1242   class TEvent: public SALOME_Event
1243   {
1244     QString myName;
1245   public:
1246     TEvent( const QString& name ) : myName( name ) {}
1247     virtual void Execute()
1248     {
1249       if ( SUIT_Session::session() ) {
1250         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1251         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1252         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1253         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1254         if ( !_sec.isEmpty() && !_nam.isEmpty() )
1255           resMgr->remove( _sec, _nam );
1256       }
1257     }
1258   };
1259   ProcessVoidEvent( new TEvent( name ) );
1260 }
1261
1262 /*!
1263   \fn QString SalomePyQt::getSetting( const QString& name );
1264   \brief Get application setting value (as string represenation).
1265
1266   This function is obsolete. Use stringSetting(), integerSetting(), 
1267   boolSetting(), stringSetting() or colorSetting() instead.
1268
1269   \param name setting name (it should be of kind <section:setting> where
1270   \c section is resources section name and \c setting is setting name)
1271   \return setting name (empty string if setting name is invalid)
1272 */
1273
1274 class TGetSettingEvent: public SALOME_Event 
1275 {
1276 public:
1277   typedef QString TResult;
1278   TResult myResult;
1279   QString myName;
1280   TGetSettingEvent( const QString& name ) : myName( name ) {}
1281   virtual void Execute() 
1282   {
1283     if ( SUIT_Session::session() ) {
1284       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1285       QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1286       QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1287       QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1288       myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1289     }
1290   }
1291 };
1292 QString SalomePyQt::getSetting( const QString& name )
1293 {
1294   return ProcessEvent( new TGetSettingEvent( name ) );
1295 }
1296
1297 /*!
1298   \fn QString SalomePyQt::constant( const QString& name );
1299   \brief Get constant's value from application's resource manager.
1300
1301   \param name name of the constant 
1302   \return value of the constant
1303
1304   \sa setConstant()
1305 */
1306
1307 class TGetConstantEvent: public SALOME_Event 
1308 {
1309 public:
1310   typedef QString TResult;
1311   TResult myResult;
1312   QString myName;
1313   TGetConstantEvent( const QString& name ) : myName( name ) {}
1314   virtual void Execute() 
1315   {
1316     if ( SUIT_Session::session() )
1317       myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1318   }
1319 };
1320 QString SalomePyQt::constant( const QString& name )
1321 {
1322   return ProcessEvent( new TGetConstantEvent( name ) );
1323 }
1324
1325 /*!
1326   \brief Add constant to the application's resource manager.
1327
1328   This function is useful to specify programmatically specific
1329   variables that are referenced in the resource setting.
1330
1331   For example, some resource value can be set as "$(myroot)/data/files".
1332   Then, "mypath" constant can be set programmatically by the application
1333   depending on run-time requirements.
1334   
1335   \param section resources file section name 
1336   \param name name of the constant 
1337   \param value value of the constant 
1338
1339   \sa constant()
1340 */
1341 void SalomePyQt::setConstant( const QString& name, const QString& value )
1342 {
1343   class TEvent: public SALOME_Event 
1344   {
1345     QString myName, myValue;
1346   public:
1347     TEvent( const QString& name, const QString& value ) 
1348       : myName( name ), myValue( value ) {}
1349     virtual void Execute() 
1350     {
1351       if ( SUIT_Session::session() )
1352         SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1353     }
1354   };
1355   ProcessVoidEvent( new TEvent( name, value ) );
1356 }
1357
1358 /*!
1359   \brief Add double setting to the application preferences.
1360   \param section resources file section name 
1361   \param name setting name
1362   \param value new setting value
1363 */
1364 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1365 {
1366   class TEvent: public SALOME_Event 
1367   {
1368     QString mySection;
1369     QString myName;
1370     double  myValue;
1371   public:
1372     TEvent( const QString& section, const QString& name, double value ) 
1373       : mySection( section ), myName( name ), myValue( value ) {}
1374     virtual void Execute() 
1375     {
1376       if ( SUIT_Session::session() ) {
1377         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1378         if ( !mySection.isEmpty() && !myName.isEmpty() )
1379           resMgr->setValue( mySection, myName, myValue );
1380       }
1381     }
1382   };
1383   ProcessVoidEvent( new TEvent( section, name, value ) );
1384 }
1385
1386 /*!
1387   \brief Add integer setting to the application preferences.
1388   \param section resources file section name 
1389   \param name setting name
1390   \param value new setting value
1391 */
1392 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1393 {
1394   class TEvent: public SALOME_Event 
1395   {
1396     QString mySection;
1397     QString myName;
1398     int     myValue;
1399   public:
1400     TEvent( const QString& section, const QString& name, int value ) 
1401       : mySection( section ), myName( name ), myValue( value ) {}
1402     virtual void Execute() 
1403     {
1404       if ( SUIT_Session::session() ) {
1405         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1406         if ( !mySection.isEmpty() && !myName.isEmpty() )
1407           resMgr->setValue( mySection, myName, myValue );
1408       }
1409     }
1410   };
1411   ProcessVoidEvent( new TEvent( section, name, value ) );
1412 }
1413
1414 /*!
1415   \brief Add boolean setting to the application preferences.
1416   \param section resources file section name 
1417   \param name setting name
1418   \param value new setting value
1419   \param dumb this parameter is used in order to avoid sip compilation error 
1420   because of conflicting int and bool types
1421 */
1422 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1423 {
1424   class TEvent: public SALOME_Event 
1425   {
1426     QString mySection;
1427     QString myName;
1428     bool    myValue;
1429   public:
1430     TEvent( const QString& section, const QString& name, bool value ) 
1431       : mySection( section ), myName( name ), myValue( value ) {}
1432     virtual void Execute() 
1433     {
1434       if ( SUIT_Session::session() ) {
1435         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1436         if ( !mySection.isEmpty() && !myName.isEmpty() )
1437           resMgr->setValue( mySection, myName, myValue );
1438       }
1439     }
1440   };
1441   ProcessVoidEvent( new TEvent( section, name, value ) );
1442 }
1443
1444 /*!
1445   \brief Add string setting to the application preferences.
1446   \param section resources file section name 
1447   \param name setting name
1448   \param value new setting value
1449 */
1450 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1451 {
1452   class TEvent: public SALOME_Event 
1453   {
1454     QString mySection;
1455     QString myName;
1456     QString myValue;
1457   public:
1458     TEvent( const QString& section, const QString& name, const QString& value ) 
1459       : mySection( section ), myName( name ), myValue( value ) {}
1460     virtual void Execute() 
1461     {
1462       if ( SUIT_Session::session() ) {
1463         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1464         if ( !mySection.isEmpty() && !myName.isEmpty() )
1465           resMgr->setValue( mySection, myName, myValue );
1466       }
1467     }
1468   };
1469   ProcessVoidEvent( new TEvent( section, name, value ) );
1470 }
1471
1472 /*!
1473   \brief Add color setting to the application preferences.
1474   \param section resources file section name 
1475   \param name setting name
1476   \param value new setting value
1477 */
1478 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1479 {
1480   class TEvent: public SALOME_Event 
1481   {
1482     QString mySection;
1483     QString myName;
1484     QColor  myValue;
1485   public:
1486     TEvent( const QString& section, const QString& name, const QColor& value ) 
1487       : mySection( section ), myName( name ), myValue( value ) {}
1488     virtual void Execute() 
1489     {
1490       if ( SUIT_Session::session() ) {
1491         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1492         if ( !mySection.isEmpty() && !myName.isEmpty() )
1493           resMgr->setValue( mySection, myName, myValue );
1494       }
1495     }
1496   };
1497   ProcessVoidEvent( new TEvent( section, name, value ) );
1498 }
1499
1500 /*!
1501   \brief Add byte array setting to the application preferences.
1502   \param section resources file section name 
1503   \param name setting name
1504   \param value new setting value
1505 */
1506 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1507 {
1508   class TEvent: public SALOME_Event 
1509   {
1510     QString    mySection;
1511     QString    myName;
1512     QByteArray myValue;
1513   public:
1514     TEvent( const QString& section, const QString& name, const QByteArray& value ) 
1515       : mySection( section ), myName( name ), myValue( value ) {}
1516     virtual void Execute() 
1517     {
1518       if ( SUIT_Session::session() ) {
1519         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1520         if ( !mySection.isEmpty() && !myName.isEmpty() )
1521           resMgr->setValue( mySection, myName, myValue );
1522       }
1523     }
1524   };
1525   ProcessVoidEvent( new TEvent( section, name, value ) );
1526 }
1527
1528 /*!
1529   \brief Add font setting to the application preferences.
1530   \param section resources file section name 
1531   \param name setting name
1532   \param value new setting value
1533 */
1534 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1535 {
1536   class TEvent: public SALOME_Event 
1537   {
1538     QString    mySection;
1539     QString    myName;
1540     QFont      myValue;
1541   public:
1542     TEvent( const QString& section, const QString& name, const QFont& value ) 
1543       : mySection( section ), myName( name ), myValue( value ) {}
1544     virtual void Execute() 
1545     {
1546       if ( SUIT_Session::session() ) {
1547         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1548         if ( !mySection.isEmpty() && !myName.isEmpty() )
1549           resMgr->setValue( mySection, myName, myValue );
1550       }
1551     }
1552   };
1553   ProcessVoidEvent( new TEvent( section, name, value ) );
1554 }
1555
1556 /*!
1557   \fn int SalomePyQt::integerSetting( const QString& section, 
1558                                       const QString& name, 
1559                                       const int def );
1560   \brief Get integer setting from the application preferences.
1561   \param section resources file section name 
1562   \param name setting name
1563   \param def default value which is returned if the setting is not found
1564   \return setting value
1565 */
1566
1567 class TGetIntSettingEvent: public SALOME_Event 
1568 {
1569 public:
1570   typedef int TResult;
1571   TResult myResult;
1572   QString mySection;
1573   QString myName;
1574   TResult myDefault;
1575   TGetIntSettingEvent( const QString& section, const QString& name, const int def ) 
1576     : mySection( section ), myName( name ), myDefault( def ) {}
1577   virtual void Execute() 
1578   {
1579     if ( SUIT_Session::session() ) {
1580       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1581       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1582     }
1583   }
1584 };
1585 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1586 {
1587   return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1588 }
1589
1590 /*!
1591   \fn double SalomePyQt::doubleSetting( const QString& section, 
1592                                         const QString& name, 
1593                                         const double def );
1594   \brief Get double setting from the application preferences.
1595   \param section resources file section name 
1596   \param name setting name
1597   \param def default value which is returned if the setting is not found
1598   \return setting value
1599 */
1600
1601 class TGetDblSettingEvent: public SALOME_Event 
1602 {
1603 public:
1604   typedef double TResult;
1605   TResult myResult;
1606   QString mySection;
1607   QString myName;
1608   TResult myDefault;
1609   TGetDblSettingEvent( const QString& section, const QString& name, const double def ) 
1610     : mySection( section ), myName( name ), myDefault( def ) {}
1611   virtual void Execute() 
1612   {
1613     if ( SUIT_Session::session() ) {
1614       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1615       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1616     }
1617   }
1618 };
1619 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1620 {
1621   return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1622 }
1623
1624 /*!
1625   \fn bool SalomePyQt::boolSetting( const QString& section, 
1626                                     const QString& name, 
1627                                     const bool def );
1628   \brief Get boolean setting from the application preferences.
1629   \param section resources file section name 
1630   \param name setting name
1631   \param def default value which is returned if the setting is not found
1632   \return setting value
1633 */
1634
1635 class TGetBoolSettingEvent: public SALOME_Event 
1636 {
1637 public:
1638   typedef bool TResult;
1639   TResult myResult;
1640   QString mySection;
1641   QString myName;
1642   TResult myDefault;
1643   TGetBoolSettingEvent( const QString& section, const QString& name, const bool def ) 
1644     : mySection( section ), myName( name ), myDefault( def ) {}
1645   virtual void Execute() 
1646   {
1647     if ( SUIT_Session::session() ) {
1648       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1649       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1650     }
1651   }
1652 };
1653 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1654 {
1655   return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1656 }
1657
1658 /*!
1659   \fn QString SalomePyQt::stringSetting( const QString& section, 
1660                                          const QString& name, 
1661                                          const QString& def, 
1662                                          const bool subst );
1663   \brief Get string setting from the application preferences.
1664   \param section resources file section name 
1665   \param name setting name
1666   \param def default value which is returned if the setting is not found
1667   \param subst \c true to make substitution, \c false to get "raw" value
1668   \return setting value
1669 */
1670
1671 class TGetStrSettingEvent: public SALOME_Event
1672 {
1673 public:
1674   typedef QString TResult;
1675   TResult myResult;
1676   QString mySection;
1677   QString myName;
1678   bool mySubst;
1679   TResult myDefault;
1680   TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst ) 
1681     : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1682   virtual void Execute() 
1683   {
1684     if ( SUIT_Session::session() ) {
1685       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1686       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1687     }
1688   }
1689 };
1690 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1691 {
1692   return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1693 }
1694
1695 /*!
1696   \fn QColor SalomePyQt::colorSetting( const QString& section, 
1697                                        const QString& name, 
1698                                        const QColor def );
1699   \brief Get color setting from the application preferences.
1700   \param section resources file section name 
1701   \param name setting name
1702   \param def default value which is returned if the setting is not found
1703   \return setting value
1704 */
1705
1706 class TGetColorSettingEvent: public SALOME_Event 
1707 {
1708 public:
1709   typedef QColor TResult;
1710   TResult myResult;
1711   QString mySection;
1712   QString myName;
1713   TResult myDefault;
1714   TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def ) 
1715     : mySection( section ), myName( name ), myDefault( def ) {}
1716   virtual void Execute() 
1717   {
1718     if ( SUIT_Session::session() ) {
1719       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1720       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1721     }
1722   }
1723 };
1724 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1725 {
1726   return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1727 }
1728
1729 /*!
1730   \fn QByteArray SalomePyQt::byteArraySetting( const QString& section, 
1731                                                const QString& name, 
1732                                                const QByteArray& def );
1733   \brief Get byte array setting from the application preferences.
1734   \param section resources file section name 
1735   \param name setting name
1736   \param def default value which is returned if the setting is not found
1737   \return setting value
1738 */
1739
1740 class TGetByteArraySettingEvent: public SALOME_Event 
1741 {
1742 public:
1743   typedef QByteArray TResult;
1744   TResult myResult;
1745   QString mySection;
1746   QString myName;
1747   TResult myDefault;
1748   TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def ) 
1749     : mySection( section ), myName( name ), myDefault( def ) {}
1750   virtual void Execute() 
1751   {
1752     if ( SUIT_Session::session() ) {
1753       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1754       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1755     }
1756   }
1757 };
1758 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1759 {
1760   return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1761 }
1762
1763 /*!
1764   \fn QByteArray SalomePyQt::fontSetting( const QString& section, 
1765                                           const QString& name, 
1766                                           const QFont& def );
1767   \brief Get font setting from the application preferences.
1768   \param section resources file section name 
1769   \param name setting name
1770   \param def default value which is returned if the setting is not found
1771   \return setting value
1772 */
1773
1774 class TGetFontSettingEvent: public SALOME_Event 
1775 {
1776 public:
1777   typedef QFont TResult;
1778   TResult myResult;
1779   QString mySection;
1780   QString myName;
1781   TResult myDefault;
1782   TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def ) 
1783     : mySection( section ), myName( name ), myDefault( def ) {}
1784   virtual void Execute() 
1785   {
1786     if ( SUIT_Session::session() ) {
1787       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1788       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1789     }
1790   }
1791 };
1792 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1793 {
1794   return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1795 }
1796
1797 /*!
1798   \brief Remove setting from the application preferences.
1799   \param section resources file section name 
1800   \param name setting name
1801 */
1802 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1803 {
1804   class TEvent: public SALOME_Event 
1805   {
1806     QString mySection;
1807     QString myName;
1808   public:
1809     TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1810     virtual void Execute() 
1811     {
1812       if ( SUIT_Session::session() ) {
1813         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1814         if ( !mySection.isEmpty() && !myName.isEmpty() )
1815           resMgr->remove( mySection, myName );
1816       }
1817     }
1818   };
1819   ProcessVoidEvent( new TEvent( section, name ) );
1820 }
1821
1822 /*!
1823   \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1824   \brief Check setting existence in the application preferences.
1825   \param section resources file section name 
1826   \param name setting name
1827   \return \c true if setting exists
1828 */
1829
1830 class THasSettingEvent: public SALOME_Event 
1831 {
1832 public:
1833   typedef bool TResult;
1834   TResult myResult;
1835   QString mySection;
1836   QString myName;
1837   THasSettingEvent( const QString& section, const QString& name ) 
1838     : mySection( section ), myName( name ) {}
1839   virtual void Execute() 
1840   {
1841     if ( SUIT_Session::session() ) {
1842       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1843       myResult = resMgr->hasValue( mySection, myName );
1844     }
1845   }
1846 };
1847 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1848 {
1849   return ProcessEvent( new THasSettingEvent( section, name ) );
1850 }
1851
1852 /*!
1853   \fn QStringList SalomePyQt::parameters( const QString& section );
1854   \brief Get names of preference items stored within the given section.
1855   \param section resources file section's name 
1856   \return \c list of preferences items
1857 */
1858
1859 /*!
1860   \fn QStringList SalomePyQt::parameters( const QStringList& section );
1861   \brief Get names of preference items stored within the given section.
1862   \param section resources file section's name 
1863   \return \c list of preferences items
1864 */
1865
1866 class TParametersEvent: public SALOME_Event 
1867 {
1868 public:
1869   typedef QStringList TResult;
1870   TResult myResult;
1871   QStringList mySection;
1872   TParametersEvent( const QString& section ) 
1873   {
1874     mySection << section;
1875   }
1876   TParametersEvent( const QStringList& section ) 
1877     : mySection( section )
1878   {}
1879   virtual void Execute() 
1880   {
1881     if ( SUIT_Session::session() ) {
1882       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1883       myResult = resMgr->parameters( mySection );
1884     }
1885   }
1886 };
1887 QStringList SalomePyQt::parameters( const QString& section )
1888 {
1889   return ProcessEvent( new TParametersEvent( section ) );
1890 }
1891 QStringList SalomePyQt::parameters( const QStringList& section )
1892 {
1893   return ProcessEvent( new TParametersEvent( section ) );
1894 }
1895
1896 /*!
1897   \fn QString SalomePyQt::getFileName( QWidget*           parent, 
1898                                        const QString&     initial, 
1899                                        const QStringList& filters, 
1900                                        const QString&     caption,
1901                                        bool               open );
1902   \brief Show 'Open/Save file' dialog box for file selection 
1903          and return a user's choice (selected file name).
1904   \param parent parent widget
1905   \param initial initial directory the dialog box to be opened in
1906   \param filters list of files filters (wildcards)
1907   \param caption dialog box title
1908   \param open if \c true, "Open File" dialog box is shown; 
1909          otherwise "Save File" dialog box is shown
1910   \return selected file name (null string if user cancels operation)
1911 */
1912
1913 class TGetFileNameEvent: public SALOME_Event 
1914 {
1915 public:
1916   typedef QString TResult;
1917   TResult     myResult;
1918   QWidget*    myParent;
1919   QString     myInitial;
1920   QStringList myFilters;
1921   QString     myCaption;
1922   bool        myOpen;
1923   TGetFileNameEvent( QWidget*           parent, 
1924                      const QString&     initial, 
1925                      const QStringList& filters, 
1926                      const QString&     caption,
1927                      bool               open ) 
1928     : myParent ( parent ), 
1929       myInitial( initial ), 
1930       myFilters( filters ), 
1931       myCaption( caption ), 
1932       myOpen ( open ) {}
1933   virtual void Execute() 
1934   {
1935     if ( LightApp_Application* anApp = getApplication() ) {
1936       myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), 
1937                                      myCaption, myParent );
1938     }
1939   }
1940 };
1941 QString SalomePyQt::getFileName( QWidget*           parent, 
1942                                  const QString&     initial, 
1943                                  const QStringList& filters, 
1944                                  const QString&     caption,
1945                                  bool               open )
1946 {
1947   return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1948 }
1949
1950 /*!
1951   \fn QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
1952                                                 const QString&     initial, 
1953                                                 const QStringList& filters, 
1954                                                 const QString&     caption );
1955   \brief Show 'Open files' dialog box for multiple files selection
1956          and return a user's choice (selected file names list).
1957   \param parent parent widget
1958   \param initial initial directory the dialog box to be opened in
1959   \param filters list of files filters (wildcards)
1960   \param caption dialog box title
1961   \return selected file names list (empty list if user cancels operation)
1962 */
1963
1964 class TGetOpenFileNamesEvent: public SALOME_Event 
1965 {
1966 public:
1967   typedef QStringList TResult;
1968   TResult     myResult;
1969   QWidget*    myParent;
1970   QString     myInitial;
1971   QStringList myFilters;
1972   QString     myCaption;
1973   TGetOpenFileNamesEvent( QWidget*           parent, 
1974                           const QString&     initial, 
1975                           const QStringList& filters, 
1976                           const QString&     caption ) 
1977     : myParent ( parent ), 
1978       myInitial( initial ), 
1979       myFilters( filters ), 
1980       myCaption( caption ) {}
1981   virtual void Execute() 
1982   {
1983     if ( LightApp_Application* anApp = getApplication() ) {
1984       myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1985     }
1986   }
1987 };
1988 QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
1989                                           const QString&     initial, 
1990                                           const QStringList& filters, 
1991                                           const QString&     caption )
1992 {
1993   return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1994 }
1995
1996 /*!
1997   \fn QString SalomePyQt::getExistingDirectory( QWidget*       parent,
1998                                                 const QString& initial,
1999                                                 const QString& caption );
2000   \brief Show 'Get Directory' dialog box for the directory selection
2001          and return a user's choice (selected directory name).
2002   \param parent parent widget
2003   \param initial initial directory the dialog box to be opened in
2004   \param caption dialog box title
2005   \return selected directory name (null string if user cancels operation)
2006 */
2007
2008 class TGetExistingDirectoryEvent: public SALOME_Event 
2009 {
2010 public:
2011   typedef QString TResult;
2012   TResult     myResult;
2013   QWidget*    myParent;
2014   QString     myInitial;
2015   QString     myCaption;
2016   TGetExistingDirectoryEvent( QWidget*           parent, 
2017                               const QString&     initial, 
2018                               const QString&     caption ) 
2019     : myParent ( parent ), 
2020       myInitial( initial ), 
2021       myCaption( caption ) {}
2022   virtual void Execute() 
2023   {
2024     if ( LightApp_Application* anApp = getApplication() ) {
2025       myResult = anApp->getDirectory( myInitial, myCaption, myParent );
2026     }
2027   }
2028 };
2029 QString SalomePyQt::getExistingDirectory( QWidget*       parent,
2030                                           const QString& initial,
2031                                           const QString& caption )
2032 {
2033   return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
2034 }
2035
2036 /*!
2037   \fn QString SalomePyQt::loadIcon( const QString& filename );
2038   \brief Load an icon from the module resources by the specified file name.
2039   \param fileName icon file name
2040   \return icon object
2041 */
2042
2043 class TLoadIconEvent: public SALOME_Event 
2044 {
2045 public:
2046   typedef QIcon TResult;
2047   TResult     myResult;
2048   QString     myModule;
2049   QString     myFileName;
2050   TLoadIconEvent( const QString& module, const QString& filename ) 
2051     : myModule( module ), 
2052       myFileName ( filename ) {}
2053   virtual void Execute() 
2054   {
2055     myResult = loadIconInternal( myModule, myFileName );
2056   }
2057 };
2058 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2059 {
2060   return ProcessEvent( new TLoadIconEvent( module, filename ) );
2061 }
2062
2063 /*!
2064   \brief Open external browser to display context help information.
2065   \todo
2066
2067   Current implementation does nothing.
2068
2069   \param source documentation (HTML) file name
2070   \param context context (for example, HTML ancor name)
2071 */
2072 void SalomePyQt::helpContext( const QString& source, const QString& context ) 
2073 {
2074   class TEvent: public SALOME_Event 
2075   {
2076     QString mySource;
2077     QString myContext;
2078   public:
2079     TEvent( const QString& source, const QString& context ) 
2080       : mySource( source ), myContext( context ) {}
2081     virtual void Execute() 
2082     {
2083       if ( LightApp_Application* anApp = getApplication() ) {
2084         anApp->onHelpContextModule( "", mySource, myContext );
2085       }
2086     }
2087   };
2088   ProcessVoidEvent( new TEvent( source, context ) );
2089 }
2090
2091 /*!
2092   \fn int SalomePyQt::defaultMenuGroup();
2093   \brief Get detault menu group identifier which can be used when 
2094   creating menus (insert custom menu commands).
2095   \return default menu group ID
2096 */
2097
2098 class TDefMenuGroupEvent: public SALOME_Event 
2099 {
2100 public:
2101   typedef int TResult;
2102   TResult myResult;
2103   TDefMenuGroupEvent() : myResult( -1 ) {}
2104   virtual void Execute() 
2105   {
2106     myResult = PyModuleHelper::defaultMenuGroup();
2107   }
2108 };
2109 int SalomePyQt::defaultMenuGroup()
2110 {
2111   return ProcessEvent( new TDefMenuGroupEvent() );
2112 }
2113
2114 class CrTool
2115 {
2116 public:
2117   CrTool( const QString& tBar, const QString& nBar ) 
2118     : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar)  {}
2119   CrTool( const int id, const int tBar, const int idx ) 
2120     : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
2121   CrTool( const int id, const QString& tBar, const int idx )
2122     : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
2123   CrTool( QAction* action, const int tbId, const int id, const int idx )
2124     : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
2125   CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2126     : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2127
2128   int execute() const
2129   {
2130     switch ( myCase ) {
2131     case 0:
2132       if ( getActiveModule() )
2133         return getActiveModule()->createTool( myTbTitle, myTbName );
2134       else if ( getApplication() )
2135         return getApplication()->createTool( myTbTitle, myTbName );
2136     case 1:
2137       if ( getActiveModule() )
2138         return getActiveModule()->createTool( myId, myTbId, myIndex );
2139       else if ( getApplication() )
2140         return getApplication()->createTool( myId, myTbId, myIndex );
2141     case 2:
2142       if ( getActiveModule() )
2143         return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2144       else if ( getApplication() )
2145         return getApplication()->createTool( myId, myTbTitle, myIndex );
2146     case 3:
2147       if ( getActiveModule() )
2148         return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2149       else if ( getApplication() )
2150         return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2151     case 4:
2152       if ( getActiveModule() )
2153         return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2154       else if ( getApplication() )
2155         return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2156     }
2157     return -1;
2158   }
2159 private:
2160    int        myCase;
2161    QString    myTbTitle;
2162    QString    myTbName;
2163    int        myTbId;
2164    QAction*   myAction;
2165    int        myId;
2166    int        myIndex;
2167 };
2168
2169 class TCreateToolEvent: public SALOME_Event 
2170 {
2171 public:
2172   typedef int TResult;
2173   TResult myResult;
2174   const CrTool& myCrTool;
2175   TCreateToolEvent( const CrTool& crTool ) 
2176     : myResult( -1 ), myCrTool( crTool ) {}
2177   virtual void Execute() 
2178   {
2179     myResult = myCrTool.execute();
2180   }
2181 };
2182
2183 /*!
2184   \brief Create toolbar with specified name.
2185   \param tBar toolbar title (language-dependent)
2186   \param nBar toolbar name (language-independent) [optional]
2187   \return toolbar ID or -1 if toolbar creation is failed
2188 */
2189 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2190 {
2191   return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2192 }
2193
2194 /*! 
2195   \brief Insert action with specified \a id to the toolbar.
2196   \param id action ID
2197   \param tBar toolbar ID
2198   \param idx required index in the toolbar
2199   \return action ID or -1 if action could not be added
2200 */
2201 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2202 {
2203   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2204 }
2205
2206 /*!
2207   \brief Insert action with specified \a id to the toolbar.
2208   \param id action ID
2209   \param tBar toolbar name
2210   \param idx required index in the toolbar
2211   \return action ID or -1 if action could not be added
2212 */
2213 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2214 {
2215   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2216 }
2217
2218 /*!
2219   \brief Insert action to the toolbar.
2220   \param a action
2221   \param tBar toolbar ID
2222   \param id required action ID
2223   \param idx required index in the toolbar
2224   \return action ID or -1 if action could not be added
2225 */
2226 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2227 {
2228   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2229 }
2230
2231
2232 /*!
2233   \brief Clear given toolbar.
2234   \param title toolbar's title
2235 */
2236 void SalomePyQt::clearTool( const QString& title )
2237 {
2238   class TEvent: public SALOME_Event
2239   {
2240     QString myTitle;
2241   public:
2242     TEvent( const QString& title ) 
2243       : myTitle( title ) {}
2244     virtual void Execute() 
2245     {
2246       if ( getActiveModule() )
2247         return getActiveModule()->clearTool( myTitle );
2248       else if ( getApplication() )
2249         return getApplication()->clearTool( myTitle );
2250     }
2251   };
2252   ProcessVoidEvent( new TEvent( title ) );
2253 }
2254
2255 /*!
2256   \brief Insert action to the toolbar.
2257   \param a action
2258   \param tBar toolbar name
2259   \param id required action ID
2260   \param idx required index in the toolbar
2261   \return action ID or -1 if action could not be added
2262 */
2263 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2264 {
2265   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2266 }
2267
2268 class CrMenu
2269 {
2270 public:
2271   CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) 
2272     : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2273   CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) 
2274     : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2275   CrMenu( const int id, const int menu, const int group, const int idx ) 
2276     : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2277   CrMenu( const int id, const QString& menu, const int group, const int idx ) 
2278     : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2279   CrMenu( QAction* action, const int menu, const int id, const int group, const int idx ) 
2280     : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2281   CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) 
2282     : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2283
2284   int execute() const
2285   {
2286     switch ( myCase ) {
2287     case 0:
2288       if ( getActiveModule() )
2289         return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2290       else if ( getApplication() )
2291         return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2292     case 1:
2293       if ( getActiveModule() )
2294         return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2295       else if ( getApplication() )
2296         return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2297     case 2:
2298       if ( getActiveModule() )
2299         return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2300       else if ( getApplication() )
2301         return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2302     case 3:
2303       if ( getActiveModule() )
2304         return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2305       else if ( getApplication() )
2306         return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2307     case 4:
2308       if ( getActiveModule() )
2309         return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2310       else if ( getApplication() )
2311         return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2312     case 5:
2313       if ( getActiveModule() )
2314         return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2315       else if ( getApplication() )
2316         return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2317     }
2318     return -1;
2319   }
2320 private:
2321    int        myCase;
2322    QString    myMenuName;
2323    int        myMenuId;
2324    QString    mySubMenuName;
2325    int        myGroup;
2326    QAction*   myAction;
2327    int        myId;
2328    int        myIndex;
2329 };
2330
2331 class TCreateMenuEvent: public SALOME_Event
2332 {
2333 public:
2334   typedef int TResult;
2335   TResult myResult;
2336   const CrMenu& myCrMenu;
2337   TCreateMenuEvent( const CrMenu& crMenu ) 
2338     : myResult( -1 ), myCrMenu( crMenu ) {}
2339   virtual void Execute()
2340   {
2341     myResult = myCrMenu.execute();
2342   }
2343 };
2344
2345 /*!
2346   \brief Create main menu.
2347   \param subMenu menu name
2348   \param menu parent menu ID
2349   \param id required menu ID
2350   \param group menu group ID
2351   \param idx required index in the menu
2352   \return menu ID or -1 if menu could not be added
2353 */
2354 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2355 {
2356   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2357 }
2358
2359 /*!
2360   \brief Create main menu.
2361   \param subMenu menu name
2362   \param menu parent menu name (list of menu names separated by "|")
2363   \param id required menu ID
2364   \param group menu group ID
2365   \param idx required index in the menu
2366   \return menu ID or -1 if menu could not be added
2367 */
2368 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2369 {
2370   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2371 }
2372
2373 /*!
2374   \brief Insert action to the main menu.
2375   \param id action ID
2376   \param menu parent menu ID
2377   \param group menu group ID
2378   \param idx required index in the menu
2379   \return action ID or -1 if action could not be added
2380 */
2381 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2382 {
2383   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2384 }
2385
2386 /*!
2387   \brief Insert action to the main menu.
2388   \param id action ID
2389   \param menu parent menu name (list of menu names separated by "|")
2390   \param group menu group ID
2391   \param idx required index in the menu
2392   \return action ID or -1 if action could not be added
2393 */
2394 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2395 {
2396   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2397 }
2398
2399 /*!
2400   \brief Insert action to the main menu.
2401   \param a action
2402   \param menu parent menu ID
2403   \param group menu group ID
2404   \param idx required index in the menu
2405   \return action ID or -1 if action could not be added
2406 */
2407 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2408 {
2409   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2410 }
2411
2412 /*!
2413   \brief Insert action to the main menu.
2414   \param a action
2415   \param menu parent menu name (list of menu names separated by "|")
2416   \param group menu group ID
2417   \param idx required index in the menu
2418   \return action ID or -1 if action could not be added
2419 */
2420 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2421 {
2422   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2423 }
2424
2425 /*!
2426   \fn QAction* SalomePyQt::createSeparator();
2427   \brief Create separator action which can be used in the menu or toolbar.
2428   \return new separator action
2429 */
2430
2431 class TCreateSepEvent: public SALOME_Event 
2432 {
2433 public:
2434   typedef QAction* TResult;
2435   TResult myResult;
2436   TCreateSepEvent() 
2437     : myResult( 0 ) {}
2438   virtual void Execute() 
2439   {
2440     LightApp_Module* module = getActiveModule();
2441     if ( module )
2442       myResult = (QAction*)module->separator();
2443   }
2444 };
2445 QAction* SalomePyQt::createSeparator()
2446 {
2447   return ProcessEvent( new TCreateSepEvent() );
2448 }
2449
2450 /*!
2451   \fn QAction* SalomePyQt::createAction( const int      id,
2452                                          const QString& menuText, 
2453                                          const QString& tipText, 
2454                                          const QString& statusText, 
2455                                          const QString& icon,
2456                                          const int      key, 
2457                                          const bool     toggle );
2458   \brief Create an action which can be then used in the menu or toolbar.
2459   \param id the unique id action to be registered to
2460   \param menuText action text which should appear in menu
2461   \param tipText text which should appear in the tooltip
2462   \param statusText text which should appear in the status bar when action is activated
2463   \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2464   \param key the key accelrator for the action
2465   \param toggle if \c true the action is checkable
2466 */
2467
2468 class TCreateActionEvent: public SALOME_Event 
2469 {
2470 public:
2471   typedef QAction* TResult;
2472   TResult myResult;
2473   int     myId;
2474   QString myMenuText;
2475   QString myTipText;
2476   QString myStatusText;
2477   QString myIcon;
2478   int     myKey;
2479   bool    myToggle;
2480   TCreateActionEvent( const int id, const QString& menuText, const QString& tipText, 
2481                       const QString& statusText, const QString& icon, const int key, const bool toggle ) 
2482     : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2483       myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2484   virtual void Execute()
2485   {
2486     LightApp_Module* module = getActiveModule();
2487     if ( module ) {
2488       QIcon icon = loadIconInternal( module->name(), myIcon );
2489       myResult = (QAction*)module->action( myId );
2490       if ( myResult ) {
2491         if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() ) 
2492           myResult->setToolTip( myTipText );
2493         if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2494           myResult->setText( myMenuText );
2495         if ( myResult->icon().isNull() && !icon.isNull() ) 
2496           myResult->setIcon( icon );
2497         if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2498           myResult->setStatusTip( myStatusText );
2499         if ( myResult->shortcut().isEmpty() && myKey )
2500           myResult->setShortcut( myKey );
2501         if ( myResult->isCheckable() != myToggle )
2502           myResult->setCheckable( myToggle );
2503       }
2504       else {
2505         myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2506       }
2507       // for Python module, automatically connect action to callback slot
2508       PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2509       if ( helper ) helper->connectAction( myResult );
2510     }
2511   }
2512 };
2513 QAction* SalomePyQt::createAction( const int id,           const QString& menuText, 
2514                                    const QString& tipText, const QString& statusText, 
2515                                    const QString& icon,    const int key, const bool toggle )
2516 {
2517   return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2518 }
2519
2520 /*!
2521   \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2522   \brief Create an action group which can be then used in the menu or toolbar
2523   \param id         : the unique id action group to be registered to
2524   \param exclusive  : if \c true the action group does exclusive toggling
2525 */
2526
2527 struct TCreateActionGroupEvent: public SALOME_Event 
2528 {
2529   typedef QtxActionGroup* TResult;
2530   TResult myResult;
2531   int     myId;
2532   bool    myExclusive;
2533   TCreateActionGroupEvent( const int id, const bool exclusive )
2534     : myId( id ), myExclusive( exclusive ) {}
2535   virtual void Execute()
2536   {
2537     LightApp_Module* module = getActiveModule();
2538     if ( module )
2539       myResult = module->createActionGroup( myId, myExclusive );
2540   }
2541 };
2542 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2543 {
2544   return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2545 }
2546
2547 /*!
2548   \fn QAction* SalomePyQt::action( const int id );
2549   \brief Get action by specified identifier.
2550   \return action or 0 if action is not registered
2551 */
2552
2553 class TActionEvent: public SALOME_Event 
2554 {
2555 public:
2556   typedef QAction* TResult;
2557   TResult myResult;
2558   int     myId;
2559   TActionEvent( const int id )
2560     : myResult( 0 ), myId( id ) {}
2561   virtual void Execute()
2562   {
2563     LightApp_Module* module = getActiveModule();
2564     if ( module )
2565       myResult = (QAction*)module->action( myId );
2566   }
2567 };
2568 QAction* SalomePyQt::action( const int id )
2569 {
2570   return ProcessEvent( new TActionEvent( id ) );
2571 }
2572
2573 /*!
2574   \fn int SalomePyQt::actionId( const QAction* a );
2575   \brief Get an action identifier. 
2576   \return action ID or -1 if action is not registered
2577 */
2578
2579 class TActionIdEvent: public SALOME_Event 
2580 {
2581 public:
2582   typedef  int TResult;
2583   TResult  myResult;
2584   const QAction* myAction;
2585   TActionIdEvent( const QAction* action )
2586     : myResult( -1 ), myAction( action ) {}
2587   virtual void Execute()
2588   {
2589     LightApp_Module* module = getActiveModule();
2590     if ( module )
2591       myResult = module->actionId( myAction );
2592   }
2593 };
2594 int SalomePyQt::actionId( const QAction* a )
2595 {
2596   return ProcessEvent( new TActionIdEvent( a ) );
2597 }
2598
2599 /*!
2600   \fn int SalomePyQt::addGlobalPreference( const QString& label );
2601   \brief Add global (not module-related) preferences group.
2602   \param label global preferences group name
2603   \return preferences group identifier
2604 */
2605
2606 class TAddGlobalPrefEvent: public SALOME_Event
2607 {
2608 public:
2609   typedef int TResult;
2610   TResult myResult;
2611   QString myLabel;
2612   TAddGlobalPrefEvent( const QString& label )
2613     : myResult( -1 ), myLabel( label ) {}
2614   virtual void Execute() 
2615   {
2616     LightApp_Module* module = getActiveModule();
2617     if ( module ) {
2618       LightApp_Preferences* pref = module->getApp()->preferences();
2619       if ( pref )
2620         myResult = pref->addPreference( myLabel, -1 );
2621     }
2622   }
2623 };
2624 int SalomePyQt::addGlobalPreference( const QString& label )
2625 {
2626   return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2627 }
2628
2629 /*!
2630   \fn int SalomePyQt::addPreference( const QString& label );
2631   \brief Add module-related preferences group.
2632   \param label preferences group name
2633   \return preferences group identifier
2634 */
2635
2636 class TAddPrefEvent: public SALOME_Event 
2637 {
2638 public:
2639   typedef int TResult;
2640   TResult myResult;
2641   QString myLabel;
2642   TAddPrefEvent( const QString& label )
2643     : myResult( -1 ), myLabel( label ) {}
2644   virtual void Execute() 
2645   {
2646     LightApp_Module* module = getActiveModule();
2647     if ( module ) {
2648       LightApp_Preferences* pref = module->getApp()->preferences();
2649       if ( pref ) {
2650         int cId = pref->addPreference( module->moduleName(), -1 );
2651         if ( cId != -1 )
2652           myResult = pref->addPreference( myLabel, cId );
2653       }
2654     }
2655   }
2656 };
2657 int SalomePyQt::addPreference( const QString& label )
2658 {
2659   return ProcessEvent( new TAddPrefEvent( label ) );
2660 }
2661
2662 /*!
2663   \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2664                                      const QString& section, const QString& param );
2665   \brief Add module-related preferences.
2666   \param label preferences group name
2667   \param pId parent preferences group id
2668   \param type preferences type
2669   \param section resources file section name
2670   \param param resources file setting name
2671   \return preferences identifier
2672 */
2673
2674 class TAddPrefParamEvent: public SALOME_Event
2675 {
2676 public:
2677   typedef int TResult;
2678   TResult myResult;
2679   QString myLabel;
2680   int     myPId;
2681   int     myType;
2682   QString mySection;
2683   QString myParam;
2684   TAddPrefParamEvent( const QString& label, 
2685                       const int pId, const int type,
2686                       const QString& section, 
2687                       const QString& param )
2688     : myResult( -1 ),
2689       myLabel( label ), myPId( pId ), myType( type ), 
2690       mySection( section ), myParam ( param ) {}
2691   virtual void Execute()
2692   {
2693     LightApp_Module* module = getActiveModule();
2694     if ( module ) {
2695       LightApp_Preferences* pref = module->getApp()->preferences();
2696       if ( pref )
2697         myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2698     }
2699   }
2700 };
2701 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2702                                const QString& section, const QString& param )
2703 {
2704   return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2705 }
2706
2707 /*!
2708   \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2709   \brief Get the preferences property.
2710   \param id preferences identifier
2711   \param prop preferences property name
2712   \return preferences property value or null QVariant if property is not set
2713 */
2714
2715 class TPrefPropEvent: public SALOME_Event
2716 {
2717 public:
2718   typedef QVariant TResult;
2719   TResult myResult;
2720   int     myId;
2721   QString myProp;
2722   TPrefPropEvent( const int id, const QString& prop )
2723     : myId( id ), myProp( prop ) {}
2724   virtual void Execute()
2725   {
2726     LightApp_Module* module = getActiveModule();
2727     if ( module ) {
2728       LightApp_Preferences* pref = module->getApp()->preferences();
2729       if ( pref )
2730         myResult = pref->itemProperty( myProp, myId );
2731     }
2732   }
2733 };
2734 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2735 {
2736   return ProcessEvent( new TPrefPropEvent( id, prop ) );
2737 }
2738
2739 /*!
2740   \brief Set the preferences property.
2741   \param id preferences identifier
2742   \param prop preferences property name
2743   \param var preferences property value
2744 */
2745 void SalomePyQt::setPreferenceProperty( const int id, 
2746                                         const QString& prop,
2747                                         const QVariant& var )
2748 {
2749   class TEvent: public SALOME_Event
2750   {
2751     int      myId;
2752     QString  myProp;
2753     QVariant myVar;
2754   public:
2755     TEvent( const int id, const QString& prop, const QVariant& var ) 
2756       : myId( id ), myProp( prop ), myVar( var ) {}
2757     virtual void Execute() 
2758     {
2759       LightApp_Module* module = getActiveModule();
2760       if ( module ) {
2761         LightApp_Preferences* pref = module->getApp()->preferences();
2762         if ( pref )
2763           pref->setItemProperty( myProp, myVar, myId );
2764       }
2765     }
2766   };
2767   ProcessVoidEvent( new TEvent( id, prop, var ) );
2768 }
2769
2770 /*!
2771   \brief Set specific widget as a custom preferences item.
2772   \param id preferences identifier
2773   \param prop preferences property name
2774   \param widget custom widget
2775 */
2776 void SalomePyQt::setPreferencePropertyWg( const int id, 
2777                                           const QString& prop,
2778                                           UserDefinedContent* widget )
2779 {
2780   class TEvent: public SALOME_Event
2781   {
2782     int      myId;
2783     QString  myProp;
2784     UserDefinedContent* myWidget;
2785   public:
2786     TEvent( const int id, const QString& prop, UserDefinedContent* widget ) 
2787       : myId( id ), myProp( prop ), myWidget( widget ) {}
2788     virtual void Execute() 
2789     {
2790       LightApp_Module* module = getActiveModule();
2791       if ( module ) {
2792         LightApp_Preferences* pref = module->getApp()->preferences();
2793         if ( pref ) {
2794           pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2795         }
2796       }
2797     }
2798   };
2799   ProcessVoidEvent( new TEvent( id, prop, widget ) );
2800 }
2801
2802 /*!
2803   \brief Add the property value to the list of values.
2804
2805   This method allows creating properties which are QList<QVariant>
2806   - there is no way to pass such values directly to QVariant parameter with PyQt.
2807
2808   \param id preferences identifier
2809   \param prop preferences property name
2810   \param idx preferences property index
2811   \param var preferences property value for the index \a idx
2812 */
2813 void SalomePyQt::addPreferenceProperty( const int id, 
2814                                         const QString& prop,
2815                                         const int idx, 
2816                                         const QVariant& var )
2817 {
2818   class TEvent: public SALOME_Event
2819   {
2820     int      myId;
2821     QString  myProp;
2822     int      myIdx;
2823     QVariant myVar;
2824   public:
2825     TEvent( const int id, const QString& prop, const int idx, const QVariant& var ) 
2826       : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2827     virtual void Execute()
2828     {
2829       LightApp_Module* module = getActiveModule();
2830       if ( module ) {
2831         LightApp_Preferences* pref = module->getApp()->preferences();
2832         if ( pref ) {
2833           QVariant var =  pref->itemProperty( myProp, myId );
2834           if ( var.isValid() ) {
2835             if ( var.type() == QVariant::StringList ) {
2836               QStringList sl = var.toStringList();
2837               if ( myIdx >= 0 && myIdx < sl.count() ) 
2838                 sl[myIdx] = myVar.toString();
2839               else
2840                 sl.append( myVar.toString() );
2841               pref->setItemProperty( myProp, sl, myId );
2842             }
2843             else if ( var.type() == QVariant::List ) {
2844               QList<QVariant> vl = var.toList();
2845               if ( myIdx >= 0 && myIdx < vl.count() ) 
2846                 vl[myIdx] = myVar;
2847               else
2848                 vl.append( myVar );
2849               pref->setItemProperty( myProp, vl, myId );
2850             }
2851           }
2852           else {
2853             QList<QVariant> vl;
2854             vl.append( myVar );
2855             pref->setItemProperty( myProp, vl, myId );
2856           }
2857         }
2858       }
2859     }
2860   };
2861   ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2862 }
2863
2864 /*!
2865   \brief Put the message to the Log messages output window
2866   \param msg message text (it can be of simple rich text format)
2867   \param addSeparator boolean flag which specifies if it is necessary 
2868          to separate the message with predefined separator
2869 */
2870 void SalomePyQt::message( const QString& msg, bool addSeparator )
2871 {
2872   class TEvent: public SALOME_Event
2873   {
2874     QString  myMsg;
2875     bool     myAddSep;
2876   public:
2877     TEvent( const QString& msg, bool addSeparator ) 
2878       : myMsg( msg ), myAddSep( addSeparator ) {}
2879     virtual void Execute()
2880     {
2881       if ( LightApp_Application* anApp = getApplication() ) {
2882         LogWindow* lw = anApp->logWindow();
2883         if ( lw )
2884           lw->putMessage( myMsg, myAddSep );
2885       }
2886     }
2887   };
2888   ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2889 }
2890
2891 /*!
2892   \brief Remove all the messages from the Log messages output window.
2893 */
2894 void SalomePyQt::clearMessages()
2895 {
2896   class TEvent: public SALOME_Event
2897   {
2898   public:
2899     TEvent() {}
2900     virtual void Execute()
2901     {
2902       if ( LightApp_Application* anApp = getApplication() ) {
2903         LogWindow* lw = anApp->logWindow();
2904         if ( lw )
2905           lw->clear();
2906       }
2907     }
2908   };
2909   ProcessVoidEvent( new TEvent() );
2910 }
2911
2912 /*!
2913   \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2914   \brief Dump the contents of the id view window. If id is 0 then current active view is processed. 
2915   to the image file in the specified format.
2916
2917   For the current moment JPEG, PNG and BMP images formats are supported.
2918   The image format is defined automatically by the file name extension.
2919   By default, BMP format is used.
2920
2921   \param filename image file name
2922   \return operation status (\c true on success)
2923 */
2924
2925 class TDumpViewEvent: public SALOME_Event 
2926 {
2927 public:
2928   typedef bool TResult;
2929   TResult myResult;
2930   QString myFileName;
2931   int myWndId;
2932   TDumpViewEvent( const QString& filename, const int id ) 
2933     : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2934   virtual void Execute() 
2935   {
2936     SUIT_ViewWindow* wnd = 0;
2937     if ( !myWndId ) {
2938       if ( LightApp_Application* anApp = getApplication() ) {
2939         SUIT_ViewManager* vm = anApp->activeViewManager();
2940         if ( vm )
2941           wnd = vm->getActiveView();
2942       }
2943       myWndId = wnd->getId();
2944     }
2945     else {
2946       wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2947     }
2948     if ( wnd ) {
2949       QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2950 #ifndef DISABLE_PLOT2DVIEWER
2951       Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2952       if ( wnd2D ) {
2953         qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2954         qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2955         qApp->processEvents();
2956         if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2957           myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2958           return;
2959         }
2960       }
2961 #endif // DISABLE_PLOT2DVIEWER
2962       QImage im = wnd->dumpView();
2963       if ( !im.isNull() && !myFileName.isEmpty() ) {
2964         if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2965         if ( fmt == "JPG" )  fmt = "JPEG";
2966         myResult = im.save( myFileName, fmt.toLatin1() );
2967       }
2968     }
2969   }
2970 };
2971 bool SalomePyQt::dumpView( const QString& filename, const int id )
2972 {
2973   return ProcessEvent( new TDumpViewEvent( filename, id ) );
2974 }
2975
2976 /*!
2977   \fn QList<int> SalomePyQt::getViews();
2978   \brief Get list of integer identifiers of all the currently opened views
2979   \return list of integer identifiers of all the currently opened views
2980 */
2981
2982 class TGetViews: public SALOME_Event
2983 {
2984 public:
2985   typedef QList<int> TResult;
2986   TResult myResult;
2987   TGetViews() {}
2988   virtual void Execute() 
2989   {
2990     myResult.clear();
2991     LightApp_Application* app  = getApplication();
2992     if ( app ) {
2993       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2994       if ( tabDesk ) {
2995         QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2996         SUIT_ViewWindow* wnd;
2997         foreach ( wnd, wndlist )
2998           myResult.append( wnd->getId() );
2999       }
3000     }
3001   }
3002 };
3003 QList<int> SalomePyQt::getViews()
3004 {
3005   return ProcessEvent( new TGetViews() );
3006 }
3007
3008 /*!
3009   \fn int SalomePyQt::getActiveView();
3010   \brief Get integer identifier of the currently active view
3011   \return integer identifier of the currently active view
3012 */
3013
3014 class TGetActiveView: public SALOME_Event
3015 {
3016 public:
3017   typedef int TResult;
3018   TResult myResult;
3019   TGetActiveView()
3020     : myResult( -1 ) {}
3021   virtual void Execute() 
3022   {
3023     LightApp_Application* app = getApplication();
3024     if ( app ) {
3025       SUIT_ViewManager* viewMgr = app->activeViewManager();
3026       if ( viewMgr ) {
3027         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3028         if ( wnd )
3029           myResult = wnd->getId();
3030       }
3031     }
3032   }
3033 };
3034 int SalomePyQt::getActiveView()
3035 {
3036   return ProcessEvent( new TGetActiveView() );
3037 }
3038
3039 /*!                      
3040   \fn QString SalomePyQt::getViewType( const int id );
3041   \brief Get type of the specified view, e.g. "OCCViewer"
3042   \param id window identifier
3043   \return view type
3044 */ 
3045
3046 class TGetViewType: public SALOME_Event
3047 {
3048 public:
3049   typedef QString TResult;
3050   TResult myResult;
3051   int myWndId;
3052   TGetViewType( const int id )
3053     : myWndId( id ) {}
3054   virtual void Execute() 
3055   {
3056     SUIT_ViewWindow* wnd = getWnd( myWndId );
3057     if ( wnd ) {
3058       SUIT_ViewManager* viewMgr = wnd->getViewManager();
3059       if ( viewMgr )
3060         myResult = viewMgr->getType();
3061     }
3062   }
3063 };
3064 QString SalomePyQt::getViewType( const int id )
3065 {
3066   return ProcessEvent( new TGetViewType( id ) );
3067 }
3068
3069 /*!
3070   \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3071   \brief Change view caption  
3072   \param id window identifier
3073   \param title new window title
3074   \return \c true if operation is completed successfully and \c false otherwise 
3075 */
3076
3077 class TSetViewTitle: public SALOME_Event
3078 {
3079 public:
3080   typedef bool TResult;
3081   TResult myResult;
3082   int myWndId;
3083   QString myTitle;
3084   TSetViewTitle( const int id, const QString& title )
3085     : myResult( false ),
3086       myWndId( id ),
3087       myTitle( title ) {}
3088   virtual void Execute() 
3089   {
3090     SUIT_ViewWindow* wnd = getWnd( myWndId );
3091     if ( wnd ) {
3092       wnd->setWindowTitle( myTitle );
3093       myResult = true;
3094     }
3095   }
3096 };
3097 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3098 {
3099   return ProcessEvent( new TSetViewTitle( id, title ) );
3100 }
3101
3102 /*!
3103   \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3104   \brief Set view size
3105   \param w window width
3106   \param h window height
3107   \param id window identifier
3108   \return \c true if operation is completed successfully and \c false otherwise 
3109 */
3110
3111 class TSetViewSize: public SALOME_Event
3112 {
3113 public:
3114   typedef bool TResult;
3115   TResult myResult;
3116   int myWndWidth;
3117   int myWndHeight;
3118   int myWndId;
3119   TSetViewSize( const int w, const int h, const int id )
3120     : myResult( false ),
3121       myWndWidth( w ),
3122       myWndHeight( h ),
3123       myWndId( id ) {}
3124   virtual void Execute() 
3125   {
3126     SUIT_ViewWindow* wnd = 0;
3127     if ( !myWndId ) {
3128       if ( LightApp_Application* anApp = getApplication() ) {
3129         SUIT_ViewManager* vm = anApp->activeViewManager();
3130         if ( vm )
3131           wnd = vm->getActiveView();
3132       }
3133     }
3134     else {
3135       wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3136     }
3137     if ( wnd ) {
3138       SUIT_ViewManager* viewMgr = wnd->getViewManager();
3139       if ( viewMgr ) {
3140         QString type = viewMgr->getType();
3141         if ( type == "OCCViewer") {
3142 #ifndef DISABLE_OCCVIEWER
3143           // specific processing for OCC viewer:
3144           // OCC view can embed up to 4 sub-views, split according to the specified layout;
3145           // - if there is only one sub-view active; it will be resized;
3146           // - if there are several sub-views, each of them will be resized.
3147           OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3148           for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3149             if ( occView && occView->getView( i ) ) {
3150               occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3151               myResult = true;
3152             }
3153           }
3154 #endif // DISABLE_OCCVIEWER
3155         }
3156         else if ( type == "ParaView") {
3157 #ifndef DISABLE_PVVIEWER
3158           // specific processing for ParaView viewer:
3159           // hierarchy of ParaView viewer is much complex than for usual view;
3160           // we look for sub-widget named "Viewport"
3161           QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3162           if ( !lst.isEmpty() ) {
3163             lst[0]->resize( myWndWidth, myWndHeight );
3164             myResult = true;
3165           }
3166 #endif // DISABLE_PVVIEWER
3167         }
3168         else {
3169           if ( wnd->centralWidget() ) {
3170             wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3171             myResult = true;
3172           }
3173         }
3174       }
3175     }
3176   }
3177 };
3178 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3179 {
3180   return ProcessEvent( new TSetViewSize( w, h, id ) );
3181 }
3182
3183 /*!
3184   \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3185   \brief Set view rotation point
3186   \param x coordinate X view rotation point
3187   \param y coordinate Y view rotation point
3188   \param z coordinate Z view rotation point
3189   \param id window identifier
3190   \return \c true if operation is completed successfully and \c false otherwise 
3191 */
3192
3193 class TSetViewRotationPoint: public SALOME_Event
3194 {
3195 public:
3196   typedef bool TResult;
3197   TResult myResult;
3198   double myX;
3199   double myY;
3200   double myZ;
3201   int myWndId;
3202   TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3203     : myResult( false ),
3204       myX( x ),
3205       myY( y ),
3206       myZ( z ),
3207       myWndId( id ) {}
3208   virtual void Execute() 
3209   {
3210     SUIT_ViewWindow* wnd = 0;
3211     if ( !myWndId ) {
3212       if ( LightApp_Application* anApp = getApplication() ) {
3213         SUIT_ViewManager* vm = anApp->activeViewManager();
3214         if ( vm )
3215           wnd = vm->getActiveView();
3216       }
3217     }
3218     else {
3219       wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3220     }
3221     if ( wnd ) {
3222       SUIT_ViewManager* viewMgr = wnd->getViewManager();
3223       if ( viewMgr ) {
3224         QString type = viewMgr->getType();
3225         if ( type == "OCCViewer") {
3226 #ifndef DISABLE_OCCVIEWER
3227           // specific processing for OCC viewer:
3228           // OCC view can embed up to 4 sub-views, split according to the specified layout;
3229           // - if there is only one sub-view active; its rotation point will be changed;
3230           // - if there are several sub-views, rotaion points of each of them will be changed.
3231           OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3232           if ( occView ) {
3233             for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3234               if ( occView && occView->getView( i ) ) {
3235                 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3236                 myResult = true;
3237               }
3238             }
3239           }
3240 #endif // DISABLE_OCCVIEWER
3241         }
3242         else if ( type == "VTKViewer") {
3243 #ifndef DISABLE_VTKVIEWER
3244           SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3245           if ( vtkView )
3246           {
3247             double aCenter[3] = { myX, myY, myZ };
3248             vtkView->activateSetRotationSelected( (void*)aCenter );
3249             myResult = true;
3250           }
3251 #endif // DISABLE_VTKVIEWER
3252         }
3253       }
3254     }
3255   }
3256 };
3257 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3258 {
3259   return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3260 }
3261
3262 /*!
3263   \fn QString SalomePyQt::getViewTitle( const int id );
3264   \brief Get view caption  
3265   \param id window identifier
3266   \return view caption  
3267 */
3268
3269 class TGetViewTitle: public SALOME_Event
3270 {
3271 public:
3272   typedef QString TResult;
3273   TResult myResult;
3274   int myWndId;
3275   TGetViewTitle( const int id )
3276     : myWndId( id ) {}
3277   virtual void Execute() 
3278   {
3279     SUIT_ViewWindow* wnd = getWnd( myWndId );
3280     if ( wnd )
3281       myResult = wnd->windowTitle();
3282   }
3283 };
3284 QString SalomePyQt::getViewTitle( const int id )
3285 {
3286   return ProcessEvent( new TGetViewTitle( id ) );
3287 }
3288
3289 /*!
3290   \fn QList<int> SalomePyQt::findViews( const QString& type );
3291   \brief Get list of integer identifiers of all the 
3292          currently opened views of the specified type
3293   \param type viewer type
3294   \return list of integer identifiers 
3295 */
3296
3297 class TFindViews: public SALOME_Event
3298 {
3299 public:
3300   typedef QList<int> TResult;
3301   TResult myResult;
3302   QString myType;
3303   TFindViews( const QString& type )
3304     : myType( type ) {}
3305   virtual void Execute() 
3306   {
3307     myResult.clear();
3308     LightApp_Application* app  = getApplication();
3309     if ( app ) {
3310       ViewManagerList vmList;
3311       app->viewManagers( myType, vmList );
3312       SUIT_ViewManager* viewMgr;
3313       foreach ( viewMgr, vmList ) {
3314         QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3315         for ( int i = 0, n = vec.size(); i < n; i++ ) {
3316           SUIT_ViewWindow* wnd = vec[ i ];
3317           if ( wnd )
3318             {
3319               MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3320               myResult.append( wnd->getId() );
3321             }
3322         }
3323       }
3324     }
3325   }
3326 };
3327 QList<int> SalomePyQt::findViews( const QString& type )
3328 {
3329   return ProcessEvent( new TFindViews( type ) );
3330 }
3331
3332 /*!
3333   \fn bool SalomePyQt::activateView( const int id );
3334   \brief Activate view
3335   \param id window identifier
3336   \return \c true if operation is completed successfully and \c false otherwise 
3337 */
3338
3339 class TActivateView: public SALOME_Event
3340 {
3341 public:
3342   typedef bool TResult;
3343   TResult myResult;
3344   int myWndId;
3345   TActivateView( const int id )
3346     : myResult( false ),
3347       myWndId( id ) {}
3348   virtual void Execute() 
3349   {
3350     SUIT_ViewWindow* wnd = getWnd( myWndId );
3351     MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3352     if ( wnd ) {
3353       wnd->setFocus();
3354       myResult = true;
3355     }
3356   }
3357 };
3358 bool SalomePyQt::activateView( const int id )
3359 {
3360   return ProcessEvent( new TActivateView( id ) );
3361 }
3362
3363 /*!
3364   \fn bool SalomePyQt::activateManagerAndView( const int id );
3365   \brief Activate view manager and view: useful for a view embedded in a module main Window
3366   \param id window identifier
3367   \return \c true if operation is completed successfully and \c false otherwise
3368  */
3369
3370 class TActivateViewManagerAndView: public SALOME_Event
3371 {
3372 public:
3373   typedef bool TResult;
3374   TResult myResult;
3375   int myWndId;
3376   TActivateViewManagerAndView( const int id )
3377     : myResult( false ),
3378       myWndId( id ) {}
3379   virtual void Execute()
3380   {
3381     SUIT_ViewWindow* wnd = getWnd( myWndId );
3382     MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3383     if ( wnd )
3384       {
3385         LightApp_Application* app  = getApplication();
3386         app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3387         wnd->setFocus();
3388         myResult = true;
3389       }
3390   }
3391 };
3392 bool SalomePyQt::activateViewManagerAndView( const int id )
3393 {
3394   return ProcessEvent( new TActivateViewManagerAndView( id ) );
3395 }
3396
3397 /*!
3398  *
3399  */
3400
3401 class TGetViewWidget: public SALOME_Event
3402 {
3403 public:
3404   typedef QWidget* TResult;
3405   TResult myResult;
3406   int myWndId;
3407   TGetViewWidget( const int id )
3408     : myResult( 0 ),
3409       myWndId( id ) {}
3410   virtual void Execute()
3411   {
3412     SUIT_ViewWindow* wnd = getWnd( myWndId );
3413     if ( wnd ) {
3414         myResult = (QWidget*)wnd;
3415     }
3416   }
3417 };
3418 QWidget* SalomePyQt::getViewWidget( const int id)
3419 {
3420   return ProcessEvent( new TGetViewWidget( id ) );
3421 }
3422
3423
3424 /*!
3425   \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3426   \brief Create new view and activate it
3427   \param type viewer type
3428   \param visible
3429   \param width
3430   \param height
3431   \return integer identifier of created view (or -1 if view could not be created)
3432 */
3433
3434 class TCreateView: public SALOME_Event
3435 {
3436 public:
3437   typedef int TResult;
3438   TResult myResult;
3439   QString myType;
3440   bool myVisible;
3441   int myWidth;
3442   int myHeight;
3443   bool myDetached;
3444   TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3445     : myResult( -1 ),
3446       myType( theType ),
3447       myVisible(visible),
3448       myWidth(width),
3449       myHeight(height),
3450       myDetached(detached) {}
3451   virtual void Execute() 
3452   {
3453     LightApp_Application* app  = getApplication();
3454     if ( app ) {
3455       SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3456       if ( viewMgr ) {
3457         QWidget* wnd = viewMgr->getActiveView();
3458         myResult = viewMgr->getActiveView()->getId();
3459         if ( wnd ) {
3460           if ( !myVisible )
3461             wnd->setVisible(false);
3462           if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3463             myWidth = 1024;
3464             myHeight = 768;
3465           }
3466           if (myWidth > 0 && myHeight > 0) {
3467 #ifndef DISABLE_PLOT2DVIEWER
3468             Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3469             if ( wnd2D ) wnd = wnd2D->getViewFrame();
3470 #endif // DISABLE_PLOT2DVIEWER
3471             wnd->setGeometry( 0, 0, myWidth, myHeight );
3472           }
3473         }
3474       }
3475     }
3476   }
3477 };
3478 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3479 {
3480   int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3481   QCoreApplication::processEvents();
3482   return ret;
3483 }
3484
3485 /*!
3486   \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3487   \brief Create new view with custom widget embedded and activate it
3488   \param type viewer type
3489   \param w custom widget
3490   \return integer identifier of created view (or -1 if view could not be created)
3491 */
3492
3493 class TCreateViewWg: public SALOME_Event
3494 {
3495 public:
3496   typedef int TResult;
3497   TResult myResult;
3498   QString myType;
3499   QWidget* myWidget;
3500   TCreateViewWg( const QString& theType, QWidget* w )
3501     : myResult( -1 ),
3502       myType( theType ),
3503       myWidget( w ) {}
3504   virtual void Execute() 
3505   {
3506     LightApp_Application* app  = getApplication();
3507     if ( app ) {
3508       SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3509       if ( viewMgr ) {
3510         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3511         if ( wnd )
3512           myResult = wnd->getId();
3513       }
3514     }
3515   }
3516 };
3517 int SalomePyQt::createView( const QString& type, QWidget* w )
3518 {
3519   int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3520   QCoreApplication::processEvents();
3521   return ret;
3522 }
3523
3524 /*!
3525   \fn bool SalomePyQt::closeView( const int id );
3526   \brief Close view
3527   \param id window identifier
3528   \return \c true if operation is completed successfully and \c false otherwise 
3529 */
3530
3531 class TCloseView: public SALOME_Event
3532 {
3533 public:
3534   typedef bool TResult;
3535   TResult myResult;
3536   int myWndId;
3537   TCloseView( const int id )
3538     : myResult( false ),
3539       myWndId( id ) {}
3540   virtual void Execute() 
3541   {
3542     SUIT_ViewWindow* wnd = getWnd( myWndId );
3543     if ( wnd ) {
3544       SUIT_ViewManager* viewMgr = wnd->getViewManager();
3545       if ( viewMgr ) {
3546         wnd->close();
3547         myResult = true;
3548       }
3549     }
3550   }
3551 };
3552 bool SalomePyQt::closeView( const int id )
3553 {
3554   return ProcessEvent( new TCloseView( id ) );
3555 }
3556
3557 /*!
3558   \fn int SalomePyQt::cloneView( const int id );
3559   \brief Clone view (if this operation is supported for specified view type)
3560   \param id window identifier
3561   \return integer identifier of the cloned view or -1 or operation could not be performed
3562 */
3563
3564 class TCloneView: public SALOME_Event
3565 {
3566 public:
3567   typedef int TResult;
3568   TResult myResult;
3569   int myWndId;
3570   TCloneView( const int id )
3571     : myResult( -1 ),
3572       myWndId( id ) {}
3573   virtual void Execute() 
3574   {
3575     SUIT_ViewWindow* wnd = getWnd( myWndId );
3576     if ( wnd ) {
3577       SUIT_ViewManager* viewMgr = wnd->getViewManager();
3578       if ( viewMgr ) {
3579 #ifndef DISABLE_OCCVIEWER
3580         if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3581           OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3582           occView->onCloneView();
3583           wnd = viewMgr->getActiveView();
3584           if ( wnd )
3585             myResult = wnd->getId();
3586         }
3587 #endif // DISABLE_OCCVIEWER
3588 #ifndef DISABLE_PLOT2DVIEWER
3589         if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3590           Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3591           Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3592           if ( viewMgr2d && srcWnd2d ) {
3593             Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3594             myResult = resWnd->getId();
3595           }
3596         }
3597 #endif // DISABLE_OCCVIEWER
3598       }
3599     }
3600   }
3601 };
3602 int SalomePyQt::cloneView( const int id )
3603 {
3604   return ProcessEvent( new TCloneView( id ) );
3605 }
3606
3607 /*!
3608   \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3609   \brief Set view visibility.
3610   \param id window identifier
3611   \param visible new visiblity
3612 */
3613
3614 void SalomePyQt::setViewVisible( const int id, const bool visible )
3615 {
3616   class TEvent: public SALOME_Event
3617   {
3618     int myWndId;
3619     bool myVisible;
3620   public:
3621     TEvent( const int id, const bool visible )
3622       : myWndId( id ), myVisible( visible ) {}
3623     virtual void Execute()
3624     {
3625       SUIT_ViewWindow* wnd = getWnd( myWndId );
3626       if ( wnd ) wnd->setVisible( myVisible );
3627     }
3628   };
3629   ProcessVoidEvent( new TEvent( id, visible ) );
3630 }
3631
3632 /*!
3633   \fn bool SalomePyQt::isViewVisible( const int id );
3634   \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3635   \param id window identifier
3636   \return \c true if view is visible and \c false otherwise 
3637 */
3638
3639 class TIsViewVisible: public SALOME_Event
3640 {
3641 public:
3642   typedef bool TResult;
3643   TResult myResult;
3644   int myWndId;
3645   TIsViewVisible( const int id )
3646     : myResult( false ),
3647       myWndId( id ) {}
3648   virtual void Execute() 
3649   {
3650     SUIT_ViewWindow* wnd = getWnd( myWndId );
3651     if ( wnd )
3652     {
3653       QWidget* p = wnd->parentWidget();
3654       myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3655     }
3656   }
3657 };
3658 bool SalomePyQt::isViewVisible( const int id )
3659 {
3660   return ProcessEvent( new TIsViewVisible( id ) );
3661 }
3662   
3663 /*!
3664   \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3665   \brief Set / clear view's "closable" option. By default any view is closable
3666         (i.e. can be closed by the user).
3667   \param id window identifier
3668   \param on new "closable" option's value
3669 */
3670
3671 void SalomePyQt::setViewClosable( const int id, const bool on )
3672 {
3673   class TEvent: public SALOME_Event
3674   {
3675     int myWndId;
3676     bool myOn;
3677   public:
3678     TEvent( const int id, const bool on )
3679       : myWndId( id ), myOn( on ) {}
3680     virtual void Execute()
3681     {
3682       SUIT_ViewWindow* wnd = getWnd( myWndId );
3683       if ( wnd ) wnd->setClosable( myOn );
3684     }
3685   };
3686   ProcessVoidEvent( new TEvent( id, on ) );
3687 }
3688
3689 /*!
3690   \fn bool SalomePyQt::isViewClosable( const int id );
3691   \brief Check whether view is closable (i.e. can be closed by the user)
3692   \param id window identifier
3693   \return \c true if view is closable or \c false otherwise 
3694 */
3695
3696 class TIsViewClosable: public SALOME_Event
3697 {
3698 public:
3699   typedef bool TResult;
3700   TResult myResult;
3701   int myWndId;
3702   TIsViewClosable( const int id )
3703     : myResult( true ),
3704       myWndId( id ) {}
3705   virtual void Execute() 
3706   {
3707     SUIT_ViewWindow* wnd = getWnd( myWndId );
3708     if ( wnd )
3709       myResult = wnd->closable();
3710   }
3711 };
3712
3713 bool SalomePyQt::isViewClosable( const int id )
3714 {
3715   return ProcessEvent( new TIsViewClosable( id ) );
3716 }
3717
3718 /*!
3719   \fn bool SalomePyQt::groupAllViews();
3720   \brief Group all views to the single tab area
3721   \return \c true if operation is completed successfully and \c false otherwise 
3722 */
3723
3724 class TGroupAllViews: public SALOME_Event
3725 {
3726 public:
3727   typedef bool TResult;
3728   TResult myResult;
3729   TGroupAllViews()
3730     : myResult( false ) {}
3731   virtual void Execute() 
3732   {
3733     LightApp_Application* app  = getApplication();
3734     if ( app ) {
3735       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3736       if ( tabDesk ) {
3737         QtxWorkstack* wStack = tabDesk->workstack();
3738         if ( wStack ) {
3739           wStack->stack();
3740           myResult = true;
3741         }
3742       }
3743     }
3744   }
3745 };
3746 bool SalomePyQt::groupAllViews()
3747 {
3748   return ProcessEvent( new TGroupAllViews() );
3749 }
3750
3751 /*!
3752   \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3753   \brief Split tab area to which view with identifier belongs to
3754   \param id window identifier
3755   \param ori orientation of split operation
3756   \param action action to be performed
3757   \return \c true if operation is completed successfully \c false otherwise 
3758 */
3759
3760 class TSplitView: public SALOME_Event
3761 {
3762 public:
3763   typedef bool TResult;
3764   TResult myResult;
3765   int myWndId;
3766   Orientation myOri;
3767   Action myAction;
3768   TSplitView( const int id, 
3769               const Orientation ori, 
3770               const Action action )
3771     : myResult( false ),
3772       myWndId( id ),
3773       myOri( ori ),
3774       myAction( action ) {}
3775   virtual void Execute() 
3776   {
3777     SUIT_ViewWindow* wnd = getWnd( myWndId );
3778     if ( wnd ) {
3779       // activate view
3780       // wnd->setFocus(); ???
3781
3782       // split workstack
3783       if ( getApplication() ) {
3784         STD_TabDesktop* desk = 
3785           dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3786         if ( desk ) {
3787           QtxWorkstack* wStack = desk->workstack();
3788           if ( wStack ) {
3789             Qt::Orientation qtOri = 
3790               ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3791
3792             QtxWorkstack::SplitType sType;
3793             if ( myAction == MoveWidget )
3794               sType = QtxWorkstack::SplitMove;
3795             else if ( myAction == LeaveWidget )
3796               sType = QtxWorkstack::SplitStay;
3797             else 
3798               sType = QtxWorkstack::SplitAt;
3799
3800             wStack->Split( wnd, qtOri, sType );
3801             myResult = true;
3802           }
3803         }
3804       }
3805     }
3806   }
3807 };
3808 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3809 {
3810   return ProcessEvent( new TSplitView( id, ori, action ) );
3811 }
3812
3813 /*!
3814   \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3815   \brief Move view with the first identifier to the same area which 
3816          another view with the second identifier belongs to
3817   \param id source window identifier
3818   \param id_to destination window identifier  
3819   param before specifies whether the first viewt has to be moved before or after 
3820         the second view
3821   \return \c true if operation is completed successfully and \c false otherwise 
3822 */
3823
3824 class TMoveView: public SALOME_Event
3825 {
3826 public:
3827   typedef bool TResult;
3828   TResult myResult;
3829   int myWndId;
3830   int myWndToId;
3831   bool myIsBefore;
3832   TMoveView( const int id, const int id_to, const bool before )
3833     : myResult( false ),
3834     myWndId( id ),
3835     myWndToId( id_to ),
3836     myIsBefore( before ) {}
3837   virtual void Execute() 
3838   {
3839     SUIT_ViewWindow* wnd = getWnd( myWndId );
3840     SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3841     if ( wnd && wnd_to ) {
3842       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
3843         getApplication()->desktop() )->workstack();
3844       if ( wStack )
3845         myResult = wStack->move( wnd, wnd_to, myIsBefore );
3846     }
3847   }
3848 };
3849 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3850 {
3851   return ProcessEvent( new TMoveView( id, id_to, before ) );
3852 }
3853
3854 /*!
3855   \fn QList<int> SalomePyQt::neighbourViews( const int id );
3856   \brief Get list of views identifiers that belongs to the same area as 
3857          specified view (excluding it)
3858   \param id window identifier
3859   \return list of views identifiers
3860 */
3861
3862 class TNeighbourViews: public SALOME_Event
3863 {
3864 public:
3865   typedef QList<int> TResult;
3866   TResult myResult;
3867   int myWndId;
3868   TNeighbourViews( const int id )
3869     : myWndId( id ) {}
3870   virtual void Execute() 
3871   {
3872     myResult.clear();
3873     SUIT_ViewWindow* wnd = getWnd( myWndId );
3874     if ( wnd ) {
3875       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
3876         getApplication()->desktop() )->workstack();
3877       if ( wStack ) {
3878         QWidgetList wgList = wStack->windowList( wnd );
3879         QWidget* wg;
3880         foreach ( wg, wgList ) {
3881           SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3882           if ( tmpWnd && tmpWnd != wnd )
3883             myResult.append( tmpWnd->getId() );
3884         }
3885       }
3886     }
3887   }
3888 };
3889 QList<int> SalomePyQt::neighbourViews( const int id )
3890 {
3891   return ProcessEvent( new TNeighbourViews( id ) );
3892 }
3893
3894
3895 /*!
3896   \fn void SalomePyQt::createRoot();
3897   \brief Initialize root data object.
3898
3899   Does nothing if root is already initialized.
3900 */
3901
3902 void SalomePyQt::createRoot()
3903 {
3904   class TEvent: public SALOME_Event
3905   {
3906   public:
3907     TEvent() {}
3908     virtual void Execute() 
3909     {
3910       SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3911       if ( module ) {
3912         SALOME_PYQT_DataModelLight* dm =
3913           dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3914         if ( dm )
3915           dm->getRoot();
3916       }
3917       else {
3918         if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3919       }
3920     }
3921   };
3922   ProcessVoidEvent( new TEvent() );
3923 }
3924
3925 /*!
3926   \fn QString SalomePyQt::createObject( const QString& parent );
3927   \brief Create empty data object
3928   \param parent entry of parent data object
3929   \return entry of created data object
3930 */
3931
3932 class TCreateEmptyObjectEvent: public SALOME_Event
3933 {
3934 public:
3935   typedef QString TResult;
3936   TResult  myResult;
3937   QString  myParent;
3938   TCreateEmptyObjectEvent( const QString& parent )
3939     : myParent( parent ) {}
3940   virtual void Execute() 
3941   {
3942     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3943     if ( module ) {
3944        myResult = module->createObject( myParent );
3945     }
3946     else {
3947       if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3948     }
3949   }
3950 };
3951 QString SalomePyQt::createObject( const QString& parent )
3952 {
3953   return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3954 }
3955
3956 /*!
3957   \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3958                                         const QString& tooltip,const QString& parent );
3959   \brief Create new data object with specified name, icon and tooltip
3960   \param name data object name
3961   \param icon data object icon
3962   \param toolTip data object tooltip
3963   \param parent entry of parent data object
3964   \return entry of created data object
3965 */
3966
3967 class TCreateObjectEvent: public SALOME_Event 
3968 {
3969 public:
3970   typedef QString TResult;
3971   TResult myResult;
3972   QString myParent;
3973   QString myName;
3974   QString myIcon;
3975   QString myToolTip;
3976   TCreateObjectEvent( const QString& name,
3977                       const QString& icon,
3978                       const QString& tooltip,
3979                       const QString& parent )
3980     : myName( name ),
3981       myIcon( icon ),
3982       myToolTip( tooltip ),
3983       myParent( parent ) {}
3984   virtual void Execute()
3985   {
3986     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3987     if ( module ) {
3988       myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3989     }
3990     else {
3991       if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3992     }
3993   }
3994 };
3995 QString SalomePyQt::createObject( const QString& name,
3996                                   const QString& icon,
3997                                   const QString& toolTip,
3998                                   const QString& parent )
3999 {
4000   return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
4001 }
4002
4003
4004 /*!
4005   \fn void SalomePyQt::setName( const QString& entry, const QString& name );
4006   \brief Set data object name
4007   \param entry data object entry
4008   \param name data object name
4009 */
4010 class TSetNameEvent: public SALOME_Event
4011 {
4012 public:
4013   QString myEntry;
4014   QString myName;
4015   TSetNameEvent( const QString& entry,
4016                  const QString& name )
4017   : myEntry( entry ),
4018     myName( name ) {}
4019   virtual void Execute()
4020   {
4021     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4022     if ( module ) {
4023       module->setName( myEntry, myName );
4024     }
4025     else {
4026       if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
4027     }
4028   }
4029 };
4030 void SalomePyQt::setName( const QString& entry, const QString& name )
4031 {
4032   ProcessVoidEvent( new TSetNameEvent( entry, name ) );
4033 }
4034
4035 /*!
4036   \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
4037   \brief Set data object icon
4038   \param entry data object entry
4039   \param icon data object icon file name (icon is loaded from module resources)
4040 */
4041
4042 class TSetIconEvent: public SALOME_Event
4043 {
4044 public:
4045   QString myEntry;
4046   QString myIcon;
4047   TSetIconEvent( const QString& entry,
4048                  const QString& icon )
4049   : myEntry( entry ),
4050     myIcon( icon ) {}
4051   virtual void Execute()
4052   {
4053     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4054     if ( module ) {
4055       module->setIcon( myEntry, myIcon );
4056     }
4057     else {
4058       if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4059     }
4060   }
4061 };
4062
4063 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4064 {
4065   ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4066 }
4067
4068 /*!
4069   \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4070   \brief Set data object tooltip
4071   \param entry data object entry
4072   \param toolTip data object tooltip
4073 */
4074
4075 class TSetToolTipEvent: public SALOME_Event
4076 {
4077 public:
4078   QString myEntry;
4079   QString myToolTip;
4080   TSetToolTipEvent( const QString& entry,
4081                     const QString& toolTip )
4082     : myEntry( entry ),
4083       myToolTip( toolTip ) {}
4084   virtual void Execute()
4085   {
4086     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4087     if ( module ) {
4088       module->setToolTip( myEntry, myToolTip );
4089     }
4090     else {
4091       if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4092     }
4093   }
4094 };
4095 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4096 {
4097   ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4098 }
4099
4100 /*!
4101   \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4102   \brief Set reference to another data object
4103   \param entry data object entry
4104   \param refEntry referenced data object entry
4105 */
4106
4107 class TSetRefEvent: public SALOME_Event
4108 {
4109 public:
4110   QString myEntry;
4111   QString myRefEntry;
4112   TSetRefEvent( const QString& entry,
4113                 const QString& refEntry )
4114     : myEntry( entry ),
4115       myRefEntry( refEntry ) {}
4116   virtual void Execute()
4117   {
4118     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4119     if ( module ) {
4120       module->setReference( myEntry, myRefEntry );
4121     }
4122     else {
4123       if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4124     }
4125   }
4126 };
4127 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4128 {
4129   ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4130 }
4131
4132 /*!
4133   \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4134   \brief Set data object color
4135   \param entry data object entry
4136   \param color data object color
4137  */
4138
4139 class TSetColorEvent: public SALOME_Event
4140 {
4141 public:
4142   QString myEntry;
4143   QColor  myColor;
4144   TSetColorEvent( const QString& entry,
4145                   const QColor& color )
4146     : myEntry( entry ),
4147       myColor( color ) {}
4148   virtual void Execute()
4149   {
4150     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4151     if ( module ) {
4152       module->setColor( myEntry, myColor );
4153     }
4154     else {
4155       if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4156     }
4157   }
4158 };
4159 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4160 {
4161   ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4162 }
4163
4164 /*!
4165   \fn QString SalomePyQt::getName( const QString& entry );
4166   \brief Get data object name
4167   \param entry data object entry
4168   \return data object name
4169 */
4170
4171 class TGetNameEvent: public SALOME_Event
4172 {
4173 public:
4174   typedef QString TResult;
4175   TResult myResult;
4176   QString myEntry;
4177   TGetNameEvent( const QString& entry )
4178     : myEntry( entry ) {}
4179   virtual void Execute()
4180   {
4181     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4182     if ( module ) {
4183       myResult = module->getName( myEntry );
4184     }
4185     else {
4186       if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4187     }
4188   }
4189 };
4190 QString SalomePyQt::getName( const QString& entry )
4191 {
4192   return ProcessEvent( new TGetNameEvent( entry ) );
4193 }
4194
4195 /*!
4196   \fn QString SalomePyQt::getToolTip( const QString& entry );
4197   \brief Get data object tooltip
4198   \param entry data object entry
4199   \return data object tooltip
4200 */
4201
4202 class TGetToolTipEvent: public SALOME_Event
4203 {
4204 public:
4205   typedef QString TResult;
4206   TResult myResult;
4207   QString myEntry;
4208   TGetToolTipEvent( const QString& entry )
4209   : myEntry( entry ) {}
4210   virtual void Execute()
4211   {
4212     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4213     if ( module ) {
4214       myResult = module->getToolTip( myEntry );
4215     }
4216     else {
4217       if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4218     }
4219   }
4220 };
4221 QString SalomePyQt::getToolTip( const QString& entry )
4222 {
4223   return ProcessEvent( new TGetToolTipEvent( entry ) );
4224 }
4225
4226 /*
4227   \fn QString SalomePyQt::getReference( const QString& entry );
4228   \brief Get entry of the referenced object (if there's any)
4229   \param entry data object entry
4230   \return referenced data object entry
4231 */
4232
4233 class TGetRefEvent: public SALOME_Event
4234 {
4235 public:
4236   typedef QString TResult;
4237   TResult myResult;
4238   QString myEntry;
4239   TGetRefEvent( const QString& entry )
4240   : myEntry( entry ) {}
4241   virtual void Execute()
4242   {
4243     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4244     if ( module ) {
4245       myResult = module->getReference( myEntry );
4246     }
4247     else {
4248       if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4249     }
4250   }
4251 };
4252 QString SalomePyQt::getReference( const QString& entry )
4253 {
4254   return ProcessEvent( new TGetRefEvent( entry ) );
4255 }
4256
4257 /*!
4258   \fn QColor SalomePyQt::getColor( const QString& entry );
4259   \brief Get data object color
4260   \param entry data object entry
4261   \return data object color
4262 */
4263
4264 class TGetColorEvent: public SALOME_Event
4265 {
4266 public:
4267   typedef QColor TResult;
4268   TResult myResult;
4269   QString myEntry;
4270   TGetColorEvent( const QString& entry )
4271   : myEntry( entry ) {}
4272   virtual void Execute()
4273   {
4274     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4275     if ( module ) {
4276       myResult = module->getColor( myEntry );
4277     }
4278     else {
4279       if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4280     }
4281   }
4282 };
4283 QColor SalomePyQt::getColor( const QString& entry )
4284 {
4285   return ProcessEvent( new TGetColorEvent( entry ) );
4286 }
4287
4288 /*!
4289   \fn void SalomePyQt::removeChildren( const QString& entry );
4290   \brief Remove all child data objects from specified data object
4291   \param entry data object entry
4292 */
4293
4294 class TRemoveChildEvent: public SALOME_Event
4295 {
4296 public:
4297   QString myEntry;
4298   TRemoveChildEvent( const QString& entry )
4299   : myEntry( entry ) {}
4300   virtual void Execute()
4301   {
4302     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4303     if ( module ) {
4304       module->removeChildren( myEntry );
4305     }
4306     else {
4307       if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4308     }
4309   }
4310 };
4311 void SalomePyQt::removeChildren( const QString& entry )
4312 {
4313   ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4314 }
4315 void SalomePyQt::removeChild( const QString& entry )
4316 {
4317   if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4318   removeChildren( entry );
4319 }
4320
4321 /*!
4322   \fn void SalomePyQt::removeObject( const QString& entry );
4323   \brief Remove object by entry
4324   \param entry data object entry
4325 */
4326
4327 class TRemoveObjectEvent: public SALOME_Event
4328 {
4329 public:
4330   QString myEntry;
4331   
4332   TRemoveObjectEvent( const QString& entry )
4333   : myEntry( entry ) {}
4334   virtual void Execute()
4335   {
4336     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4337     if ( module ) {
4338       module->removeObject( myEntry );
4339     }
4340     else {
4341       if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4342     }
4343   }
4344 };
4345 void SalomePyQt::removeObject( const QString& entry )
4346 {
4347   ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4348 }
4349
4350 /*!
4351   \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4352   \brief Get entries of all child data objects of specified data object
4353   \param entry data object entry
4354   \param recursive \c true for recursive processing
4355 */
4356
4357 class TGetChildrenEvent: public SALOME_Event
4358 {
4359 public:
4360   typedef QStringList TResult;
4361   TResult myResult;
4362   QString myEntry;
4363   bool    myRecursive; 
4364   TGetChildrenEvent( const QString& entry, const bool recursive )
4365     : myEntry( entry ),
4366       myRecursive( recursive ) {}
4367   virtual void Execute()
4368   {
4369     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4370     if ( module ) {
4371       myResult = module->getChildren( myEntry, myRecursive );
4372     }
4373     else {
4374       if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4375     }
4376   }
4377 };
4378 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4379 {
4380   return ProcessEvent( new TGetChildrenEvent( entry, recursive ) ); 
4381 }
4382
4383 #ifndef DISABLE_PLOT2DVIEWER
4384 // Next set of methods relates to the Plot2d viewer functionality
4385
4386 /*!
4387   \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4388   \brief Display theCurve in view
4389   \param id window identifier
4390   \param theCurve curve to display
4391 */
4392
4393 class TDisplayCurve: public SALOME_Event
4394 {
4395 public:
4396   int myWndId;
4397   Plot2d_Curve* myCurve;
4398   TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4399   virtual void Execute() {
4400     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4401     if ( wnd )
4402       wnd->getViewFrame()->displayCurve( myCurve );
4403   }
4404 };
4405 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4406 {
4407   ProcessVoidEvent( new TDisplayCurve( id, theCurve ) ); 
4408 }
4409
4410 /*!
4411   \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4412   \brief Erase theCurve in view
4413   \param id window identifier
4414   \param theCurve curve to erase
4415 */
4416
4417 class TEraseCurve: public SALOME_Event
4418 {
4419 public:
4420   int myWndId;
4421   Plot2d_Curve* myCurve;
4422   TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4423   virtual void Execute() {
4424     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4425     wnd->getViewFrame()->eraseCurve( myCurve );
4426   }
4427 };
4428 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4429 {
4430   ProcessVoidEvent( new TEraseCurve( id, theCurve ) ); 
4431 }
4432
4433 /*!
4434   \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4435   \brief Delete theCurve from all views
4436   \param theCurve curve to delete
4437 */
4438
4439 class TDeleteCurve: public SALOME_Event
4440 {
4441 public:
4442   Plot2d_Curve* myCurve;
4443   TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4444   virtual void Execute() {
4445     LightApp_Application* app  = getApplication();
4446     if ( app ) {
4447       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4448       if ( tabDesk ) {
4449         QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4450         SUIT_ViewWindow* wnd;
4451         foreach ( wnd, wndlist ) {
4452           Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4453           if ( aP2d )
4454             aP2d->getViewFrame()->eraseObject( myCurve );
4455         }
4456       }
4457     }
4458   }
4459 };
4460 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4461 {
4462   ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4463 }
4464
4465 /*!
4466   \brief updateCurves (repaint) curves in view window.
4467 */
4468 void SalomePyQt::updateCurves( const int id )
4469 {
4470   class TEvent: public SALOME_Event
4471   {
4472   public:
4473     int myWndId;
4474     TEvent( const int id ) : myWndId( id ) {}
4475     virtual void Execute()
4476     {
4477       Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4478       if ( wnd )
4479         wnd->getViewFrame()->DisplayAll();
4480     }
4481   };
4482   ProcessVoidEvent( new TEvent( id ) );
4483 }
4484
4485 /*!
4486   \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4487   \brief Get title of corresponding type
4488   \param id window identifier
4489   \param type is type of title
4490   \return title of corresponding type
4491 */
4492
4493 class TGetPlot2dTitle: public SALOME_Event
4494 {
4495 public:
4496   typedef QString TResult;
4497   TResult myResult;
4498   int myWndId;
4499   ObjectType myType;
4500   TGetPlot2dTitle(const int id, ObjectType type) :
4501     myWndId( id ),
4502     myType( type ) {}
4503   virtual void Execute() {
4504     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4505     if ( wnd )
4506       myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4507   }
4508 };
4509 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4510 {
4511   return ProcessEvent( new TGetPlot2dTitle( id, type ) ); 
4512 }
4513
4514
4515 /*!
4516   \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4517   \brief Set title of corresponding type
4518   \param id window identifier
4519   \param title
4520   \param type is type of title
4521   \param show
4522 */
4523
4524 class TSetPlot2dTitle: public SALOME_Event
4525 {
4526 public:
4527   int myWndId;
4528   Plot2d_Curve* myCurve;
4529   QString myTitle;
4530   ObjectType myType;
4531   bool myShow;
4532   TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4533     myWndId( id ),
4534     myTitle( title ),
4535     myType( type ),
4536     myShow( show ) {}
4537   virtual void Execute() {
4538     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4539     wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4540   }
4541 };
4542 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4543 {
4544   ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) ); 
4545 }
4546
4547 /*!
4548   \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4549   \brief Get list of Plot2d view ranges
4550   \param id window identifier
4551   \return list of view ranges (XMin, XMax, YMin, YMax)
4552 */
4553
4554 class TFitRangeByCurves: public SALOME_Event
4555 {
4556 public:
4557   typedef QList<double> TResult;
4558   TResult myResult;
4559   int myWndId;
4560   TFitRangeByCurves( const int id )
4561     : myWndId( id ) {}
4562   virtual void Execute() 
4563   {
4564     myResult.clear();
4565     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4566     if ( wnd ) {
4567       double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4568       wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4569       myResult.append( XMin );
4570       myResult.append( XMax );
4571       myResult.append( YMin );
4572       myResult.append( YMax );
4573     }
4574   }
4575 };
4576 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4577 {
4578   return ProcessEvent( new TFitRangeByCurves( id ) );
4579 }
4580
4581 /*!
4582   \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4583   \brief Get list of current Plot2d view ranges
4584   \param id window identifier
4585   \return list of view ranges (XMin, XMax, YMin, YMax)
4586 */
4587
4588 class TFitRangeCurrent: public SALOME_Event
4589 {
4590 public:
4591   typedef QList<double> TResult;
4592   TResult myResult;
4593   int myWndId;
4594   TFitRangeCurrent( const int id )
4595     : myWndId( id ) {}
4596   virtual void Execute() 
4597   {
4598     myResult.clear();
4599     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4600     if ( wnd ) {
4601       double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4602       wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4603       myResult.append( XMin );
4604       myResult.append( XMax );
4605       myResult.append( YMin );
4606       myResult.append( YMax );
4607     }
4608   }
4609 };
4610 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4611 {
4612   return ProcessEvent( new TFitRangeCurrent( id ) );
4613 }
4614
4615 /*!
4616   \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4617   \brief Set range of Plot2d view
4618   \param id window identifier
4619   \param XMin
4620   \param XMax
4621   \param YMin
4622   \param YMax
4623 */
4624
4625 class TPlot2dFitRange: public SALOME_Event
4626 {
4627 public:
4628   int myWndId;
4629   double myXMin;
4630   double myXMax;
4631   double myYMin;
4632   double myYMax;
4633   TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4634     myWndId( id ),
4635     myXMin( XMin ),
4636     myXMax( XMax ),
4637     myYMin( YMin ),
4638     myYMax( YMax ) {}
4639   virtual void Execute() {
4640     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4641     if ( wnd )
4642       wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4643   }
4644 };
4645 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4646 {
4647   ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) ); 
4648 }
4649
4650 // End of methods related to the Plot2d viewer functionality
4651 #endif // DISABLE_PLOT2DVIEWER
4652
4653 /*!
4654   \brief Process Qt event loop
4655 */
4656 void SalomePyQt::processEvents()
4657 {
4658   QCoreApplication::processEvents();
4659 }
4660
4661 /*!
4662   \brief Set visibility state for given object
4663   \param theEntry study ID of the object
4664   \param theState visibility state
4665 */
4666 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4667 {
4668   class TEvent: public SALOME_Event
4669   {
4670     QString myEntry;
4671     int myState;
4672   public:
4673     TEvent( const QString& theEntry, int theState ):
4674       myEntry( theEntry ), myState( theState ) {}
4675     virtual void Execute() 
4676     {
4677       LightApp_Study* aStudy = getActiveStudy();
4678       if ( !aStudy )
4679         return;
4680       aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4681     }
4682   };
4683   ProcessVoidEvent( new TEvent( theEntry, theState ) );
4684 }
4685
4686 /*!
4687   \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4688   \brief Get visibility state for given object
4689   \param theEntry study ID of the object
4690   \return visibility state
4691 */
4692
4693 class TGetVisibilityStateEvent: public SALOME_Event 
4694 {
4695 public:
4696   typedef int TResult;
4697   TResult myResult;
4698   QString myEntry;
4699   TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4700   virtual void Execute()
4701   {
4702     LightApp_Study* aStudy = getActiveStudy();
4703     if ( aStudy )
4704       myResult = aStudy->visibilityState( myEntry );
4705   }
4706 };
4707 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4708 {
4709   return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4710 }
4711
4712 /*!
4713   \brief Set position of given object in the tree
4714   \param theEntry study ID of the object
4715   \param thePos position
4716 */
4717 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4718 {
4719   class TEvent: public SALOME_Event
4720   {
4721     QString myEntry;
4722     int myPos;
4723   public:
4724     TEvent( const QString& theEntry, int thePos ):
4725       myEntry( theEntry ), myPos( thePos ) {}
4726     virtual void Execute() 
4727     {
4728       SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4729       if ( module )
4730         module->setObjectPosition( myEntry, myPos );
4731     }
4732   };
4733   ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4734 }
4735
4736 /*!
4737   \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4738   \brief Get position of given object in the tree
4739   \param theEntry study ID of the object
4740   \return position
4741 */
4742
4743 class TGetObjectPositionEvent: public SALOME_Event 
4744 {
4745 public:
4746   typedef int TResult;
4747   TResult myResult;
4748   QString myEntry;
4749   TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4750   virtual void Execute()
4751   {
4752     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4753     if ( module )
4754       myResult = module->getObjectPosition( myEntry );
4755   }
4756 };
4757 int SalomePyQt::getObjectPosition( const QString& theEntry )
4758 {
4759   return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4760 }
4761
4762 /*!
4763   \brief Start recordind a log of Python commands from embedded console
4764   \param theFileName output lof file name
4765 */
4766 void SalomePyQt::startPyLog( const QString& theFileName )
4767 {
4768   class TEvent: public SALOME_Event
4769   {
4770     QString myFileName;
4771   public:
4772     TEvent( const QString& theFileName ):
4773       myFileName( theFileName ) {}
4774     virtual void Execute() 
4775     {
4776       if ( getApplication() ) {
4777         PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4778         if ( pyConsole ) pyConsole->startLog( myFileName );
4779       }
4780     }
4781   };
4782   ProcessVoidEvent( new TEvent( theFileName ) );
4783 }
4784
4785 /*!
4786   \brief Stop recordind a log of Python commands from embedded console
4787 */
4788 void SalomePyQt::stopPyLog()
4789 {
4790   class TEvent: public SALOME_Event
4791   {
4792   public:
4793     TEvent() {}
4794     virtual void Execute() 
4795     {
4796       if ( getApplication() ) {
4797         PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4798         if ( pyConsole ) pyConsole->stopLog();
4799       }
4800     }
4801   };
4802   ProcessVoidEvent( new TEvent() );
4803 }