]> SALOME platform Git repositories - modules/gui.git/blob - src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
Salome HOME
Merge from V6_main 01/04/2013
[modules/gui.git] / src / SALOME_PYQT / SalomePyQt / SalomePyQt.cxx
1 // Copyright (C) 2007-2013  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.
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 WNT
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 #include "OCCViewer_ViewWindow.h"
42 #include "Plot2d_ViewManager.h"
43 #include "Plot2d_ViewWindow.h"
44 #include "QtxActionMenuMgr.h"
45 #include "QtxWorkstack.h"
46 #include "QtxTreeView.h"
47 #include "SALOME_Event.h"
48 #include "STD_TabDesktop.h"
49 #include "SUIT_DataBrowser.h"
50 #include "SUIT_ResourceMgr.h"
51 #include "SUIT_Session.h"
52 #include "SUIT_Tools.h"
53
54 #include <QAction>
55 #include <QApplication>
56
57 /*!
58   \brief Get the currently active application.
59   \internal
60   \return active application object or 0 if there is no any
61 */
62 static LightApp_Application* getApplication()
63 {
64   if ( SUIT_Session::session() )
65     return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
66   return 0;
67 }
68
69 /*!
70   \brief Get the currently active study.
71   \internal
72   \return active study or 0 if there is no study opened
73 */
74 static LightApp_Study* getActiveStudy()
75 {
76   if ( getApplication() )
77     return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
78   return 0;
79 }
80
81 /*!
82   \brief Get the currently active module.
83   \internal
84   This function returns correct result only if Python-based
85   module is currently active. Otherwize, 0 is returned.
86 */
87 static LightApp_Module* getActiveModule()
88 {
89   LightApp_Module* module = 0;
90   if ( LightApp_Application* anApp = getApplication() ) {
91     module = PyModuleHelper::getInitModule();
92     if ( !module )
93       module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
94   }
95   return module;
96 }
97
98 /*!
99   \brief Get the currently active Python module's helper.
100   \internal
101   This function returns correct result only if Python-based
102   module is currently active. Otherwize, 0 is returned.
103 */
104 static PyModuleHelper* getPythonHelper()
105 {
106   LightApp_Module* module = getActiveModule();
107   PyModuleHelper* helper = module ? qFindChild<PyModuleHelper*>( module, "python_module_helper" ) : 0;
108   return helper;
109 }
110
111 /*!
112   \brief Get SALOME verbose level
113   \internal
114   \return \c true if SALOME debug output is allowed or \c false otherwise
115 */
116 static bool verbose()
117 {
118   bool isVerbose = false;
119   if ( getenv( "SALOME_VERBOSE" ) ) {
120     QString envVar = getenv( "SALOME_VERBOSE" );
121     bool ok;
122     int value = envVar.toInt( &ok );
123     isVerbose = ok && value != 0;
124   }
125   return isVerbose;
126 }
127
128 /*!
129   \class SALOME_Selection
130   \brief The class represents selection which can be used in Python.
131 */
132
133 /*!
134   \brief Map of created selection objects.
135   \internal
136 */
137 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
138
139 /*!
140   \brief Get the selection object for the specified application.
141
142   Finds or creates the selection object (one per study).
143
144   \param app application object
145   \return selection object or 0 if \a app is invalid
146 */
147 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
148 {
149   SALOME_Selection* sel = 0;
150   if ( app && SelMap.find( app ) != SelMap.end() )
151     sel = SelMap[ app ];
152   else 
153     sel = SelMap[ app ] = new SALOME_Selection( app );
154   return sel;
155 }
156
157 /*!
158   \brief Constructor.
159   \param p parent object
160 */
161 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
162 {
163   LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
164   if ( app ) {
165     mySelMgr = app->selectionMgr();
166     connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
167     connect( mySelMgr, SIGNAL( destroyed() ),        this, SLOT  ( onSelMgrDestroyed() ) );
168   }
169 }
170
171 /*!
172   \brief Destructor.
173 */
174 SALOME_Selection::~SALOME_Selection()
175 {
176   LightApp_Application* app = 0;
177   QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
178   for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
179     if ( it.value() == this ) app = it.key();
180   }
181   if ( app ) SelMap.remove( app );
182 }
183
184 /*!
185   \brief Called when selection manager is destroyed (usually 
186   when the study is closed).
187 */
188 void SALOME_Selection::onSelMgrDestroyed()
189 {
190   mySelMgr = 0;
191 }
192
193 /*!
194   \brief Clear the selection.
195 */
196 void SALOME_Selection::Clear()
197 {
198   class TEvent: public SALOME_Event
199   {
200     LightApp_SelectionMgr* mySelMgr;
201   public:
202     TEvent( LightApp_SelectionMgr* selMgr ) 
203       : mySelMgr( selMgr ) {}
204     virtual void Execute() 
205     {
206       if ( mySelMgr )
207         mySelMgr->clearSelected();
208     }
209   };
210   ProcessVoidEvent( new TEvent( mySelMgr ) );
211 }
212
213 /*!
214   \brief Clear the selection.
215 */
216 void SALOME_Selection::ClearIObjects()
217 {
218   Clear();
219 }
220
221 /*!
222   Removes all selection filters.
223 */
224 void SALOME_Selection::ClearFilters()
225 {
226   class TEvent: public SALOME_Event 
227   {
228     LightApp_SelectionMgr* mySelMgr;
229   public:
230     TEvent( LightApp_SelectionMgr* selMgr ) 
231       : mySelMgr( selMgr ) {}
232     virtual void Execute() 
233     {
234       if ( mySelMgr )
235         mySelMgr->clearFilters();
236     }
237   };
238   ProcessVoidEvent( new TEvent( mySelMgr ) );
239 }
240
241 /*!
242   \class SalomePyQt
243   \brief The class provides utility functions which can be used in the Python
244   to operate with the SALOME GUI.
245
246   All the functionality of this class is implemented as static methods, so they
247   can be called with the class name prefixed or via creation of the class instance.
248   For example, next both ways of SalomePyQt class usage are legal:
249   \code
250   from SalomePyQt import *
251   sg = SalomePyQt()
252   # using SalomePyQt class instance
253   desktop = sg.getDesktop()
254   # using SalomePyQt class directly
255   menubar = SalomePyQt.getMainMenuBar()
256   \endcode
257 */
258
259 /*!
260   \fn QWidget* SalomePyQt::getDesktop();
261   \brief Get the active application's desktop window.
262   \return desktop window or 0 if there is no any
263 */
264
265 class TGetDesktopEvent: public SALOME_Event 
266 {
267 public:
268   typedef QWidget* TResult;
269   TResult myResult;
270   TGetDesktopEvent() : myResult( 0 ) {}
271   virtual void Execute()
272   {
273     if ( getApplication() )
274       myResult = (QWidget*)( getApplication()->desktop() );
275   }
276 };
277 QWidget* SalomePyQt::getDesktop()
278 {
279   return ProcessEvent( new TGetDesktopEvent() );
280 }
281
282 /*!
283   \fn QWidget* SalomePyQt::getMainFrame();
284   \brief Get current application's main frame widget [obsolete].
285
286   Main frame widget is an internal widget of the application 
287   desktop window (workspace).
288
289   \return workspace widget (0 on any error)
290 */
291
292 class TGetMainFrameEvent: public SALOME_Event
293 {
294 public:
295   typedef QWidget* TResult;
296   TResult myResult;
297   TGetMainFrameEvent() : myResult( 0 ) {}
298   virtual void Execute()
299   {
300     if ( getApplication() ) {
301       SUIT_Desktop* aDesktop = getApplication()->desktop();
302       myResult = (QWidget*)( aDesktop->centralWidget() );
303     }
304   }
305 };
306 QWidget* SalomePyQt::getMainFrame()
307 {
308   return ProcessEvent( new TGetMainFrameEvent() );
309 }
310
311 /*!
312   \fn QMenuBar* SalomePyQt::getMainMenuBar();
313   \brief Get current application desktop's main menu.
314   \return main menu object (0 on any error)
315 */
316
317 class TGetMainMenuBarEvent: public SALOME_Event
318 {
319 public:
320   typedef QMenuBar* TResult;
321   TResult myResult;
322   TGetMainMenuBarEvent() : myResult( 0 ) {}
323   virtual void Execute()
324   {
325     if ( LightApp_Application* anApp = getApplication() ) {
326       myResult = anApp->desktop()->menuBar();
327     }
328   }
329 };
330 QMenuBar* SalomePyQt::getMainMenuBar() 
331 {
332   return ProcessEvent( new TGetMainMenuBarEvent() );
333 }
334
335 /*!
336   \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
337   \brief Get main menu's child popup submenu by its identifier.
338   
339   This function is obsolete. 
340   Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
341
342   \param menu menu identifier
343   \return popup submenu object or 0 if it does not exist
344 */
345
346 /*!
347   \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
348   \brief Get main menu's child popup submenu by its name.
349   
350   The function creates menu if it does not exist.
351
352   \param menu menu name
353   \return popup submenu object (0 on any error)
354 */
355
356 class TGetPopupMenuEvent: public SALOME_Event
357 {
358 public:
359   typedef QMenu* TResult;
360   TResult myResult;
361   QString myMenuName;
362   TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
363   virtual void Execute()
364   {
365     LightApp_Application* anApp = getApplication();
366     if ( anApp && !myMenuName.isEmpty() ) {
367       QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
368       myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
369     }
370   }
371 };
372
373 /*!
374   \brief Get menu item title
375   \internal
376   \param menuId menu identifier
377   \return menu title (localized)
378 */
379 static QString getMenuName( const QString& menuId )
380 {
381   QStringList contexts;
382   contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
383     "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
384   QString menuName = menuId;
385   for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
386     menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
387   return menuName;
388 }
389
390 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
391 {
392   QString menuName;
393   switch( menu ) {
394   case File:
395     menuName = getMenuName( "MEN_DESK_FILE" );        break;
396   case View:
397     menuName = getMenuName( "MEN_DESK_VIEW" );        break;
398   case Edit:
399     menuName = getMenuName( "MEN_DESK_EDIT" );        break;
400   case Preferences:
401     menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
402   case Tools:
403     menuName = getMenuName( "MEN_DESK_TOOLS" );       break;
404   case Window:
405     menuName = getMenuName( "MEN_DESK_WINDOW" );      break;
406   case Help:
407     menuName = getMenuName( "MEN_DESK_HELP" );        break;
408   }
409   return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
410 }
411 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
412 {
413   return ProcessEvent( new TGetPopupMenuEvent( menu ) );
414 }
415
416 /*!
417   \fn QTreeView* SalomePyQt::getObjectBrowser();
418   \brief Get object browser
419   \return object browser for the active study or 0 in case of error
420 */
421
422 class TGetObjectBrowserEvent: public SALOME_Event
423 {
424 public:
425   typedef QTreeView* TResult;
426   TResult myResult;
427   TGetObjectBrowserEvent() : myResult( 0 ) {}
428   virtual void Execute()
429   {
430     LightApp_Application* anApp = getApplication();
431     if ( anApp ) {
432       myResult = anApp->objectBrowser()->treeView();
433     }
434   }
435 };
436 QTreeView* SalomePyQt::getObjectBrowser()
437 {
438   return ProcessEvent( new TGetObjectBrowserEvent() );
439 }
440
441 /*!
442   \fn int SalomePyQt::getStudyId();
443   \brief Get active study's identifier.
444   \return active study ID or 0 if there is no active study
445 */
446
447 class TGetStudyIdEvent: public SALOME_Event
448 {
449 public:
450   typedef int TResult;
451   TResult myResult;
452   TGetStudyIdEvent() : myResult( 0 ) {}
453   virtual void Execute()
454   {
455     if ( LightApp_Study* aStudy = getActiveStudy() ) {
456       myResult = aStudy->id();
457     }
458   }
459 };
460 int SalomePyQt::getStudyId()
461 {
462   return ProcessEvent( new TGetStudyIdEvent() );
463 }
464
465 /*!
466   \fn SALOME_Selection* SalomePyQt::getSelection();
467   \brief Get the selection object for the current study.
468
469   Creates a Selection object if it has not been created yet.
470
471   \return selection object (0 on error)
472 */
473
474 class TGetSelectionEvent: public SALOME_Event 
475 {
476 public:
477   typedef SALOME_Selection* TResult;
478   TResult myResult;
479   TGetSelectionEvent() : myResult( 0 ) {}
480   virtual void Execute() 
481   {
482     myResult = SALOME_Selection::GetSelection( getApplication() );
483   }
484 };
485 SALOME_Selection* SalomePyQt::getSelection()
486 {
487   return ProcessEvent( new TGetSelectionEvent() );
488 }
489
490 /*!
491   \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
492   \brief Put an information message to the current application's 
493   desktop status bar.
494
495   Optional second delay parameter (\a sec) can be used to specify
496   time of the message diplaying in seconds. If this parameter is less
497   or equal to zero, the constant message will be put.
498
499   \param msg message text 
500   \param sec message displaying time in seconds
501 */
502
503 class TPutInfoEvent: public SALOME_Event
504 {
505   QString myMsg;
506   int     mySecs;
507 public:
508   TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
509   virtual void Execute()
510   {
511     if ( LightApp_Application* anApp = getApplication() ) {
512       anApp->putInfo( myMsg, mySecs * 1000 );
513     }
514   }
515 };
516 void SalomePyQt::putInfo( const QString& msg, const int sec )
517 {
518   ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
519 }
520
521 /*!
522   \fn const QString SalomePyQt::getActiveComponent();
523   \brief Get the currently active module name (for the current study).
524   \return active module name or empty string if there is no active module
525 */
526
527 class TGetActiveComponentEvent: public SALOME_Event
528 {
529 public:
530   typedef QString TResult;
531   TResult myResult;
532   TGetActiveComponentEvent() {}
533   virtual void Execute() 
534   {
535     if ( LightApp_Application* anApp = getApplication() ) {
536       if ( CAM_Module* mod = anApp->activeModule() ) {
537         myResult = mod->name();
538       }
539     }
540   }
541 };
542 const QString SalomePyQt::getActiveComponent()
543 {
544   return ProcessEvent( new TGetActiveComponentEvent() );
545 }
546
547 /*!
548   \fn PyObject* SalomePyQt::getActivePythonModule();
549   \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
550   \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
551 */
552
553 class TGetActivePyModuleEvent: public SALOME_Event
554 {
555 public:
556   typedef PyObject* TResult;
557   TResult myResult;
558   TGetActivePyModuleEvent() : myResult( Py_None ) {}
559   virtual void Execute() 
560   {
561     PyModuleHelper* helper = getPythonHelper();
562     if ( helper )
563       myResult = (PyObject*)helper->pythonModule();
564   }
565 };
566 PyObject* SalomePyQt::getActivePythonModule()
567 {
568   return ProcessEvent( new TGetActivePyModuleEvent() );
569 }
570
571 /*!
572   \fn bool SalomePyQt::activateModule( const QString& modName );
573   \brief Activates SALOME module with the given name
574   \return True if the module has been activated and False otherwise.
575 */
576
577 class TActivateModuleEvent: public SALOME_Event
578 {
579 public:
580   typedef bool TResult;
581   TResult myResult;
582   QString myModuleName;
583   TActivateModuleEvent( const QString& modName ) 
584   : myResult( false ), myModuleName( modName ) {}
585   virtual void Execute() 
586   {
587     if ( LightApp_Application* anApp = getApplication() ) {
588       myResult = anApp->activateModule( myModuleName );
589     }
590   }
591 };
592 bool SalomePyQt::activateModule( const QString& modName )
593 {
594   return ProcessEvent( new TActivateModuleEvent( modName ) );
595 }
596
597 /*!
598   \brief Update an Object Browser of the specified (by identifier) study.
599
600   If \a studyId <= 0 the active study's object browser is updated.
601   The \a updateSelection parameter is obsolete and currently is not used. 
602   This parameter will be removed in future, so try to avoid its usage in 
603   your code.
604
605   \brief studyId study identifier
606   \brief updateSelection update selection flag (not used)
607   \sa getActiveStudy()
608 */
609 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
610 {  
611   class TEvent: public SALOME_Event
612   {
613     int  myStudyId;
614     bool myUpdateSelection;
615   public:
616     TEvent( const int studyId, bool updateSelection ) 
617       : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
618     virtual void Execute()
619     {
620       if ( SUIT_Session::session() ) {
621         if ( getActiveStudy() && myStudyId <= 0 )
622           myStudyId = getActiveStudy()->id();
623         if ( myStudyId > 0 ) {
624           QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
625           QList<SUIT_Application*>::Iterator it;
626           for( it = apps.begin(); it != apps.end(); ++it ) {
627             LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
628             if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
629               anApp->updateObjectBrowser();
630               return;
631             }
632           }
633         }
634       }
635     }
636   };
637   ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
638 }
639
640
641 /*!
642   SalomePyQt::isModified()
643   \return The modification status of the data model
644   for the currently active Python module
645   \note This function is supported for "light" Python-based SALOME modules only.
646   \sa setModified()
647 */
648 class TIsModifiedEvent: public SALOME_Event
649 {
650 public:
651   typedef bool TResult;
652   TResult myResult;
653   TIsModifiedEvent() : myResult( false ) {}
654   virtual void Execute() 
655   {
656     LightApp_Module* module = getActiveModule();
657     if ( !module )
658       return;
659     
660     SALOME_PYQT_DataModelLight* aModel =
661       dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
662     if ( aModel ) {
663       myResult = aModel->isModified();
664     }
665     else {
666       if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
667     }
668   }
669 };
670 bool SalomePyQt::isModified()
671 {
672   return ProcessEvent(new TIsModifiedEvent());
673 }
674
675 /*!
676   SalomePyQt::setModified()
677
678   Sets the modification status of the data model for 
679   the currently active Python module. This method should be used
680   by the Python code in order to enable/disable "Save" operation
681   depending on the module's data state.
682
683   \note This function is supported for "light" Python-based SALOME modules only.
684
685   \param New modification status of the data model
686
687   \sa isModified()
688 */
689 void SalomePyQt::setModified( bool flag )
690 {  
691   class TEvent: public SALOME_Event
692   {
693     bool myFlag;
694   public:
695     TEvent( bool flag ) 
696       : myFlag( flag ) {}
697     virtual void Execute()
698     {
699       LightApp_Module* module = getActiveModule();
700       if ( !module )
701         return;
702
703       SALOME_PYQT_DataModelLight* model =
704         dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
705
706       LightApp_Application* app = module->getApp();
707
708       if ( model && app ) {
709         model->setModified( myFlag );
710         app->updateActions();
711       }
712       else {
713         if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
714       }
715     }
716   };
717   ProcessVoidEvent( new TEvent( flag ) );
718 }
719
720 /*!
721   \brief Default resource file section name.
722   \internal
723 */
724 static const char* DEFAULT_SECTION = "SalomePyQt";
725
726 /*!
727   \brief Add string setting to the application preferences.
728
729   The parameter \a autoValue is obsolete parameter and currently is not used.
730   This parameter will be removed in future, so try to avoid its usage in 
731   your code.
732
733   This function is obsolete. Use one of addSetting() instead.
734
735   \param name setting name (it should be of kind <section:setting> where
736   \c section is resources section name and \c setting is setting name)
737   \param value new setting value
738   \param autoValue (not used)
739 */
740 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
741 {
742   class TEvent: public SALOME_Event
743   {
744     QString myName;
745     QString myValue;
746     bool    myAutoValue;
747   public:
748     TEvent( const QString& name, const QString& value, bool autoValue ) 
749       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
750     virtual void Execute()
751     {
752       if ( SUIT_Session::session() ) {
753         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
754         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
755         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
756         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
757         if ( !_sec.isEmpty() && !_nam.isEmpty() )
758           resMgr->setValue( _sec, _nam, myValue );
759       }
760     }
761   };
762   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
763 }
764
765 /*!
766   \brief Add integer setting to the application preferences.
767
768   The parameter \a autoValue is obsolete parameter and currently is not used.
769   This parameter will be removed in future, so try to avoid its usage in 
770   your code.
771
772   This function is obsolete. Use one of addSetting() instead.
773
774   \param name setting name (it should be of kind <section:setting> where
775   \c section is resources section name and \c setting is setting name)
776   \param value new setting value
777   \param autoValue (not used)
778 */
779 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
780 {
781   class TEvent: public SALOME_Event 
782   {
783     QString myName;
784     int     myValue;
785     bool    myAutoValue;
786   public:
787     TEvent( const QString& name, const int value, bool autoValue ) 
788       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
789     virtual void Execute()
790     {
791       if ( SUIT_Session::session() ) {
792         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
793         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
794         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
795         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
796         if ( !_sec.isEmpty() && !_nam.isEmpty() )
797           resMgr->setValue( _sec, _nam, myValue );
798       }
799     }
800   };
801   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
802 }
803
804 /*!
805   \brief Add double setting to the application preferences.
806
807   The parameter \a autoValue is obsolete parameter and currently is not used.
808   This parameter will be removed in future, so try to avoid its usage in 
809   your code.
810
811   This function is obsolete. Use one of addSetting() instead.
812
813   \param name setting name (it should be of kind <section:setting> where
814   \c section is resources section name and \c setting is setting name)
815   \param value new setting value
816   \param autoValue (not used)
817 */
818 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
819 {
820   class TEvent: public SALOME_Event 
821   {
822     QString myName;
823     double  myValue;
824     bool    myAutoValue;
825   public:
826     TEvent( const QString& name, const double value, bool autoValue ) 
827       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
828     virtual void Execute() 
829     {
830       if ( SUIT_Session::session() ) {
831         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
832         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
833         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
834         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
835         if ( !_sec.isEmpty() && !_nam.isEmpty() )
836           resMgr->setValue( _sec, _nam, myValue );
837       }
838     }
839   };
840   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
841 }
842
843 /*!
844   \brief Add boolean setting to the application preferences.
845
846   The parameter \a autoValue is obsolete parameter and currently is not used.
847   This parameter will be removed in future, so try to avoid its usage in 
848   your code.
849
850   This function is obsolete. Use one of addSetting() instead.
851
852   \param name setting name (it should be of kind <section:setting> where
853   \c section is resources section name and \c setting is setting name)
854   \param value new setting value
855   \param autoValue (not used)
856 */
857 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
858 {
859   class TEvent: public SALOME_Event 
860   {
861     QString myName;
862     bool    myValue;
863     bool    myAutoValue;
864   public:
865     TEvent( const QString& name, const bool value, bool autoValue ) 
866       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
867     virtual void Execute() 
868     {
869       if ( SUIT_Session::session() ) {
870         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
871         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
872         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
873         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
874         if ( !_sec.isEmpty() && !_nam.isEmpty() )
875           resMgr->setValue( _sec, _nam, myValue );
876       }
877     }
878   };
879   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
880 }
881
882 /*!
883   \brief Remove setting from the application preferences.
884
885   This function is obsolete. Use removeSetting() instead.
886
887   \param name setting name (it should be of kind <section:setting> where
888   \c section is resources section name and \c setting is setting name)
889 */
890 void SalomePyQt::removeSettings( const QString& name )
891 {
892   class TEvent: public SALOME_Event
893   {
894     QString myName;
895   public:
896     TEvent( const QString& name ) : myName( name ) {}
897     virtual void Execute()
898     {
899       if ( SUIT_Session::session() ) {
900         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
901         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
902         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
903         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
904         if ( !_sec.isEmpty() && !_nam.isEmpty() )
905           resMgr->remove( _sec, _nam );
906       }
907     }
908   };
909   ProcessVoidEvent( new TEvent( name ) );
910 }
911
912 /*!
913   \fn QString SalomePyQt::getSetting( const QString& name );
914   \brief Get application setting value (as string represenation).
915
916   This function is obsolete. Use stringSetting(), integerSetting(), 
917   boolSetting(), stringSetting() or colorSetting() instead.
918
919   \param name setting name (it should be of kind <section:setting> where
920   \c section is resources section name and \c setting is setting name)
921   \return setting name (empty string if setting name is invalid)
922 */
923
924 class TGetSettingEvent: public SALOME_Event 
925 {
926 public:
927   typedef QString TResult;
928   TResult myResult;
929   QString myName;
930   TGetSettingEvent( const QString& name ) : myName( name ) {}
931   virtual void Execute() 
932   {
933     if ( SUIT_Session::session() ) {
934       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
935       QStringList sl = myName.split( ":", QString::SkipEmptyParts );
936       QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
937       QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
938       myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
939     }
940   }
941 };
942 QString SalomePyQt::getSetting( const QString& name )
943 {
944   return ProcessEvent( new TGetSettingEvent( name ) );
945 }
946
947 /*!
948   \brief Add double setting to the application preferences.
949   \param section resources file section name 
950   \param name setting name
951   \param value new setting value
952 */
953 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
954 {
955   class TEvent: public SALOME_Event 
956   {
957     QString mySection;
958     QString myName;
959     double  myValue;
960   public:
961     TEvent( const QString& section, const QString& name, double value ) 
962       : mySection( section ), myName( name ), myValue( value ) {}
963     virtual void Execute() 
964     {
965       if ( SUIT_Session::session() ) {
966         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
967         if ( !mySection.isEmpty() && !myName.isEmpty() )
968           resMgr->setValue( mySection, myName, myValue );
969       }
970     }
971   };
972   ProcessVoidEvent( new TEvent( section, name, value ) );
973 }
974
975 /*!
976   \brief Add integer setting to the application preferences.
977   \param section resources file section name 
978   \param name setting name
979   \param value new setting value
980 */
981 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
982 {
983   class TEvent: public SALOME_Event 
984   {
985     QString mySection;
986     QString myName;
987     int     myValue;
988   public:
989     TEvent( const QString& section, const QString& name, int value ) 
990       : mySection( section ), myName( name ), myValue( value ) {}
991     virtual void Execute() 
992     {
993       if ( SUIT_Session::session() ) {
994         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
995         if ( !mySection.isEmpty() && !myName.isEmpty() )
996           resMgr->setValue( mySection, myName, myValue );
997       }
998     }
999   };
1000   ProcessVoidEvent( new TEvent( section, name, value ) );
1001 }
1002
1003 /*!
1004   \brief Add boolean setting to the application preferences.
1005   \param section resources file section name 
1006   \param name setting name
1007   \param value new setting value
1008   \param dumb this parameter is used in order to avoid sip compilation error 
1009   because of conflicting int and bool types
1010 */
1011 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1012 {
1013   class TEvent: public SALOME_Event 
1014   {
1015     QString mySection;
1016     QString myName;
1017     bool    myValue;
1018   public:
1019     TEvent( const QString& section, const QString& name, bool value ) 
1020       : mySection( section ), myName( name ), myValue( value ) {}
1021     virtual void Execute() 
1022     {
1023       if ( SUIT_Session::session() ) {
1024         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1025         if ( !mySection.isEmpty() && !myName.isEmpty() )
1026           resMgr->setValue( mySection, myName, myValue );
1027       }
1028     }
1029   };
1030   ProcessVoidEvent( new TEvent( section, name, value ) );
1031 }
1032
1033 /*!
1034   \brief Add string setting to the application preferences.
1035   \param section resources file section name 
1036   \param name setting name
1037   \param value new setting value
1038 */
1039 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1040 {
1041   class TEvent: public SALOME_Event 
1042   {
1043     QString mySection;
1044     QString myName;
1045     QString myValue;
1046   public:
1047     TEvent( const QString& section, const QString& name, const QString& value ) 
1048       : mySection( section ), myName( name ), myValue( value ) {}
1049     virtual void Execute() 
1050     {
1051       if ( SUIT_Session::session() ) {
1052         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1053         if ( !mySection.isEmpty() && !myName.isEmpty() )
1054           resMgr->setValue( mySection, myName, myValue );
1055       }
1056     }
1057   };
1058   ProcessVoidEvent( new TEvent( section, name, value ) );
1059 }
1060
1061 /*!
1062   \brief Add color setting to the application preferences.
1063   \param section resources file section name 
1064   \param name setting name
1065   \param value new setting value
1066 */
1067 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1068 {
1069   class TEvent: public SALOME_Event 
1070   {
1071     QString mySection;
1072     QString myName;
1073     QColor  myValue;
1074   public:
1075     TEvent( const QString& section, const QString& name, const QColor& value ) 
1076       : mySection( section ), myName( name ), myValue( value ) {}
1077     virtual void Execute() 
1078     {
1079       if ( SUIT_Session::session() ) {
1080         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1081         if ( !mySection.isEmpty() && !myName.isEmpty() )
1082           resMgr->setValue( mySection, myName, myValue );
1083       }
1084     }
1085   };
1086   ProcessVoidEvent( new TEvent( section, name, value ) );
1087 }
1088
1089 /*!
1090   \fn int SalomePyQt::integerSetting( const QString& section, 
1091                                       const QString& name, 
1092                                       const int def );
1093   \brief Get integer setting from the application preferences.
1094   \param section resources file section name 
1095   \param name setting name
1096   \param def default value which is returned if the setting is not found
1097   \return setting value
1098 */
1099
1100 class TGetIntSettingEvent: public SALOME_Event 
1101 {
1102 public:
1103   typedef int TResult;
1104   TResult myResult;
1105   QString mySection;
1106   QString myName;
1107   TResult myDefault;
1108   TGetIntSettingEvent( const QString& section, const QString& name, const int def ) 
1109     : mySection( section ), myName( name ), myDefault( def ) {}
1110   virtual void Execute() 
1111   {
1112     if ( SUIT_Session::session() ) {
1113       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1114       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1115     }
1116   }
1117 };
1118 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1119 {
1120   return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1121 }
1122
1123 /*!
1124   \fn double SalomePyQt::doubleSetting( const QString& section, 
1125                                         const QString& name, 
1126                                         const double def );
1127   \brief Get double setting from the application preferences.
1128   \param section resources file section name 
1129   \param name setting name
1130   \param def default value which is returned if the setting is not found
1131   \return setting value
1132 */
1133
1134 class TGetDblSettingEvent: public SALOME_Event 
1135 {
1136 public:
1137   typedef double TResult;
1138   TResult myResult;
1139   QString mySection;
1140   QString myName;
1141   TResult myDefault;
1142   TGetDblSettingEvent( const QString& section, const QString& name, const double def ) 
1143     : mySection( section ), myName( name ), myDefault( def ) {}
1144   virtual void Execute() 
1145   {
1146     if ( SUIT_Session::session() ) {
1147       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1148       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1149     }
1150   }
1151 };
1152 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1153 {
1154   return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1155 }
1156
1157 /*!
1158   \fn bool SalomePyQt::boolSetting( const QString& section, 
1159                                     const QString& name, 
1160                                     const bool def );
1161   \brief Get boolean setting from the application preferences.
1162   \param section resources file section name 
1163   \param name setting name
1164   \param def default value which is returned if the setting is not found
1165   \return setting value
1166 */
1167
1168 class TGetBoolSettingEvent: public SALOME_Event 
1169 {
1170 public:
1171   typedef bool TResult;
1172   TResult myResult;
1173   QString mySection;
1174   QString myName;
1175   TResult myDefault;
1176   TGetBoolSettingEvent( const QString& section, const QString& name, const bool def ) 
1177     : mySection( section ), myName( name ), myDefault( def ) {}
1178   virtual void Execute() 
1179   {
1180     if ( SUIT_Session::session() ) {
1181       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1182       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1183     }
1184   }
1185 };
1186 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1187 {
1188   return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1189 }
1190
1191 /*!
1192   \fn QString SalomePyQt::stringSetting( const QString& section, 
1193                                          const QString& name, 
1194                                          const QString& def );
1195   \brief Get string setting from the application preferences.
1196   \param section resources file section name 
1197   \param name setting name
1198   \param def default value which is returned if the setting is not found
1199   \return setting value
1200 */
1201
1202 class TGetStrSettingEvent: public SALOME_Event
1203 {
1204 public:
1205   typedef QString TResult;
1206   TResult myResult;
1207   QString mySection;
1208   QString myName;
1209   TResult myDefault;
1210   TGetStrSettingEvent( const QString& section, const QString& name, const QString& def ) 
1211     : mySection( section ), myName( name ), myDefault( def ) {}
1212   virtual void Execute() 
1213   {
1214     if ( SUIT_Session::session() ) {
1215       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1216       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1217     }
1218   }
1219 };
1220 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1221 {
1222   return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1223 }
1224
1225 /*!
1226   \fn QColor SalomePyQt::colorSetting( const QString& section, 
1227                                        const QString& name, 
1228                                        const QColor def );
1229   \brief Get color setting from the application preferences.
1230   \param section resources file section name 
1231   \param name setting name
1232   \param def default value which is returned if the setting is not found
1233   \return setting value
1234 */
1235
1236 class TGetColorSettingEvent: public SALOME_Event 
1237 {
1238 public:
1239   typedef QColor TResult;
1240   TResult myResult;
1241   QString mySection;
1242   QString myName;
1243   TResult myDefault;
1244   TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def ) 
1245     : mySection( section ), myName( name ), myDefault( def ) {}
1246   virtual void Execute() 
1247   {
1248     if ( SUIT_Session::session() ) {
1249       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1250       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1251     }
1252   }
1253 };
1254 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1255 {
1256   return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1257 }
1258
1259 /*!
1260   \brief Remove setting from the application preferences.
1261   \param section resources file section name 
1262   \param name setting name
1263 */
1264 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1265 {
1266   class TEvent: public SALOME_Event 
1267   {
1268     QString mySection;
1269     QString myName;
1270   public:
1271     TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1272     virtual void Execute() 
1273     {
1274       if ( SUIT_Session::session() ) {
1275         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1276         if ( !mySection.isEmpty() && !myName.isEmpty() )
1277           resMgr->remove( mySection, myName );
1278       }
1279     }
1280   };
1281   ProcessVoidEvent( new TEvent( section, name ) );
1282 }
1283
1284 /*!
1285   \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1286   \brief Check setting existence in the application preferences.
1287   \param section resources file section name 
1288   \param name setting name
1289   \return \c true if setting exists
1290 */
1291
1292 class THasColorSettingEvent: public SALOME_Event 
1293 {
1294 public:
1295   typedef bool TResult;
1296   TResult myResult;
1297   QString mySection;
1298   QString myName;
1299   THasColorSettingEvent( const QString& section, const QString& name ) 
1300     : mySection( section ), myName( name ) {}
1301   virtual void Execute() 
1302   {
1303     if ( SUIT_Session::session() ) {
1304       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1305       myResult = resMgr->hasValue( mySection, myName );
1306     }
1307   }
1308 };
1309 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1310 {
1311   return ProcessEvent( new THasColorSettingEvent( section, name ) );
1312 }
1313
1314 /*!
1315   \fn QString SalomePyQt::getFileName( QWidget*           parent, 
1316                                        const QString&     initial, 
1317                                        const QStringList& filters, 
1318                                        const QString&     caption,
1319                                        bool               open );
1320   \brief Show 'Open/Save file' dialog box for file selection 
1321          and return a user's choice (selected file name).
1322   \param parent parent widget
1323   \param initial initial directory the dialog box to be opened in
1324   \param filters list of files filters (wildcards)
1325   \param caption dialog box title
1326   \param open if \c true, "Open File" dialog box is shown; 
1327          otherwise "Save File" dialog box is shown
1328   \return selected file name (null string if user cancels operation)
1329 */
1330
1331 class TGetFileNameEvent: public SALOME_Event 
1332 {
1333 public:
1334   typedef QString TResult;
1335   TResult     myResult;
1336   QWidget*    myParent;
1337   QString     myInitial;
1338   QStringList myFilters;
1339   QString     myCaption;
1340   bool        myOpen;
1341   TGetFileNameEvent( QWidget*           parent, 
1342                      const QString&     initial, 
1343                      const QStringList& filters, 
1344                      const QString&     caption,
1345                      bool               open ) 
1346     : myParent ( parent ), 
1347       myInitial( initial ), 
1348       myFilters( filters ), 
1349       myCaption( caption ), 
1350       myOpen ( open ) {}
1351   virtual void Execute() 
1352   {
1353     if ( LightApp_Application* anApp = getApplication() ) {
1354       myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), 
1355                                      myCaption, myParent );
1356     }
1357   }
1358 };
1359 QString SalomePyQt::getFileName( QWidget*           parent, 
1360                                  const QString&     initial, 
1361                                  const QStringList& filters, 
1362                                  const QString&     caption,
1363                                  bool               open )
1364 {
1365   return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1366 }
1367
1368 /*!
1369   \fn QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
1370                                                 const QString&     initial, 
1371                                                 const QStringList& filters, 
1372                                                 const QString&     caption );
1373   \brief Show 'Open files' dialog box for multiple files selection
1374          and return a user's choice (selected file names list).
1375   \param parent parent widget
1376   \param initial initial directory the dialog box to be opened in
1377   \param filters list of files filters (wildcards)
1378   \param caption dialog box title
1379   \return selected file names list (empty list if user cancels operation)
1380 */
1381
1382 class TGetOpenFileNamesEvent: public SALOME_Event 
1383 {
1384 public:
1385   typedef QStringList TResult;
1386   TResult     myResult;
1387   QWidget*    myParent;
1388   QString     myInitial;
1389   QStringList myFilters;
1390   QString     myCaption;
1391   TGetOpenFileNamesEvent( QWidget*           parent, 
1392                           const QString&     initial, 
1393                           const QStringList& filters, 
1394                           const QString&     caption ) 
1395     : myParent ( parent ), 
1396       myInitial( initial ), 
1397       myFilters( filters ), 
1398       myCaption( caption ) {}
1399   virtual void Execute() 
1400   {
1401     if ( LightApp_Application* anApp = getApplication() ) {
1402       myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1403     }
1404   }
1405 };
1406 QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
1407                                           const QString&     initial, 
1408                                           const QStringList& filters, 
1409                                           const QString&     caption )
1410 {
1411   return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1412 }
1413
1414 /*!
1415   \fn QString SalomePyQt::getExistingDirectory( QWidget*       parent,
1416                                                 const QString& initial,
1417                                                 const QString& caption );
1418   \brief Show 'Get Directory' dialog box for the directory selection
1419          and return a user's choice (selected directory name).
1420   \param parent parent widget
1421   \param initial initial directory the dialog box to be opened in
1422   \param caption dialog box title
1423   \return selected directory name (null string if user cancels operation)
1424 */
1425
1426 class TGetExistingDirectoryEvent: public SALOME_Event 
1427 {
1428 public:
1429   typedef QString TResult;
1430   TResult     myResult;
1431   QWidget*    myParent;
1432   QString     myInitial;
1433   QString     myCaption;
1434   TGetExistingDirectoryEvent( QWidget*           parent, 
1435                               const QString&     initial, 
1436                               const QString&     caption ) 
1437     : myParent ( parent ), 
1438       myInitial( initial ), 
1439       myCaption( caption ) {}
1440   virtual void Execute() 
1441   {
1442     if ( LightApp_Application* anApp = getApplication() ) {
1443       myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1444     }
1445   }
1446 };
1447 QString SalomePyQt::getExistingDirectory( QWidget*       parent,
1448                                           const QString& initial,
1449                                           const QString& caption )
1450 {
1451   return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1452 }
1453
1454 /*!
1455   \fn QString SalomePyQt::loadIcon( const QString& filename );
1456   \brief Load an icon from the module resources by the specified file name.
1457   \param fileName icon file name
1458   \return icon object
1459 */
1460
1461 static QIcon loadIconInternal( const QString& module, const QString& fileName )
1462 {
1463   QIcon icon;
1464
1465   LightApp_Application* app = getApplication();
1466
1467   if ( app && !fileName.isEmpty() ) {
1468     QPixmap pixmap = app->resourceMgr()->loadPixmap( module, 
1469                                                      QApplication::translate( module.toLatin1().data(), 
1470                                                                               fileName.toLatin1().data() ) );
1471     if ( !pixmap.isNull() )
1472       icon = QIcon( pixmap );
1473   }
1474   return icon;
1475 }
1476
1477 class TLoadIconEvent: public SALOME_Event 
1478 {
1479 public:
1480   typedef QIcon TResult;
1481   TResult     myResult;
1482   QString     myModule;
1483   QString     myFileName;
1484   TLoadIconEvent( const QString& module, const QString& filename ) 
1485     : myModule( module ), 
1486       myFileName ( filename ) {}
1487   virtual void Execute() 
1488   {
1489     myResult = loadIconInternal( myModule, myFileName );
1490   }
1491 };
1492 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1493 {
1494   return ProcessEvent( new TLoadIconEvent( module, filename ) );
1495 }
1496
1497 /*!
1498   \brief Open external browser to display context help information.
1499   \todo
1500
1501   Current implementation does nothing.
1502
1503   \param source documentation (HTML) file name
1504   \param context context (for example, HTML ancor name)
1505 */
1506 void SalomePyQt::helpContext( const QString& source, const QString& context ) 
1507 {
1508   class TEvent: public SALOME_Event 
1509   {
1510     QString mySource;
1511     QString myContext;
1512   public:
1513     TEvent( const QString& source, const QString& context ) 
1514       : mySource( source ), myContext( context ) {}
1515     virtual void Execute() 
1516     {
1517       if ( LightApp_Application* anApp = getApplication() ) {
1518         anApp->onHelpContextModule( "", mySource, myContext );
1519       }
1520     }
1521   };
1522   ProcessVoidEvent( new TEvent( source, context ) );
1523 }
1524
1525 /*!
1526   \fn bool SalomePyQt::dumpView( const QString& filename );
1527   \brief Dump the contents of the currently active view window 
1528   to the image file in the specified format.
1529
1530   For the current moment JPEG, PNG and BMP images formats are supported.
1531   The image format is defined automatically by the file name extension.
1532   By default, BMP format is used.
1533
1534   \param filename image file name
1535   \return operation status (\c true on success)
1536 */
1537
1538 class TDumpViewEvent: public SALOME_Event 
1539 {
1540 public:
1541   typedef bool TResult;
1542   TResult myResult;
1543   QString myFileName;
1544   TDumpViewEvent( const QString& filename ) 
1545     : myResult ( false ), myFileName( filename ) {}
1546   virtual void Execute() 
1547   {
1548     if ( LightApp_Application* anApp = getApplication() ) {
1549       SUIT_ViewManager* vm = anApp->activeViewManager();
1550       if ( vm ) { 
1551         SUIT_ViewWindow* vw = vm->getActiveView();
1552         if ( vw ) {
1553           QImage im = vw->dumpView();
1554           if ( !im.isNull() && !myFileName.isEmpty() ) {
1555             QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
1556             if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
1557             if ( fmt == "JPG" )  fmt = "JPEG";
1558             myResult = im.save( myFileName, fmt.toLatin1() );
1559           }
1560         }
1561       }
1562     }
1563   }
1564 };
1565 bool SalomePyQt::dumpView( const QString& filename )
1566 {
1567   return ProcessEvent( new TDumpViewEvent( filename ) );
1568 }
1569
1570 /*!
1571   \fn int SalomePyQt::defaultMenuGroup();
1572   \brief Get detault menu group identifier which can be used when 
1573   creating menus (insert custom menu commands).
1574   \return default menu group ID
1575 */
1576
1577 class TDefMenuGroupEvent: public SALOME_Event 
1578 {
1579 public:
1580   typedef int TResult;
1581   TResult myResult;
1582   TDefMenuGroupEvent() : myResult( -1 ) {}
1583   virtual void Execute() 
1584   {
1585     myResult = PyModuleHelper::defaultMenuGroup();
1586   }
1587 };
1588 int SalomePyQt::defaultMenuGroup()
1589 {
1590   return ProcessEvent( new TDefMenuGroupEvent() );
1591 }
1592
1593 class CrTool
1594 {
1595 public:
1596   CrTool( const QString& tBar ) 
1597     : myCase( 0 ), myTbName( tBar ) {}
1598   CrTool( const int id, const int tBar, const int idx ) 
1599     : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1600   CrTool( const int id, const QString& tBar, const int idx )
1601     : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1602   CrTool( QAction* action, const int tbId, const int id, const int idx )
1603     : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1604   CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1605     : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1606
1607   int execute( LightApp_Module* module ) const
1608   {
1609     if ( module ) {
1610       switch ( myCase ) {
1611       case 0:
1612         return module->createTool( myTbName );
1613       case 1:
1614         return module->createTool( myId, myTbId, myIndex );
1615       case 2:
1616         return module->createTool( myId, myTbName, myIndex );
1617       case 3:
1618         return module->createTool( myAction, myTbId, myId, myIndex );
1619       case 4:
1620         return module->createTool( myAction, myTbName, myId, myIndex );
1621       }
1622     }
1623     return -1;
1624   }
1625 private:
1626    int        myCase;
1627    QString    myTbName;
1628    int        myTbId;
1629    QAction*   myAction;
1630    int        myId;
1631    int        myIndex;
1632 };
1633
1634 class TCreateToolEvent: public SALOME_Event 
1635 {
1636 public:
1637   typedef int TResult;
1638   TResult myResult;
1639   const CrTool& myCrTool;
1640   TCreateToolEvent( const CrTool& crTool ) 
1641     : myResult( -1 ), myCrTool( crTool ) {}
1642   virtual void Execute() 
1643   {
1644     LightApp_Module* module = getActiveModule();
1645     if ( module )
1646       myResult = myCrTool.execute( module );
1647   }
1648 };
1649
1650 /*!
1651   \brief Create toolbar with specified name.
1652   \param tBar toolbar name
1653   \return toolbar ID or -1 if toolbar creation is failed
1654 */
1655 int SalomePyQt::createTool( const QString& tBar )
1656 {
1657   return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1658 }
1659
1660 /*! 
1661   \brief Insert action with specified \a id to the toolbar.
1662   \param id action ID
1663   \param tBar toolbar ID
1664   \param idx required index in the toolbar
1665   \return action ID or -1 if action could not be added
1666 */
1667 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1668 {
1669   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1670 }
1671
1672 /*!
1673   \brief Insert action with specified \a id to the toolbar.
1674   \param id action ID
1675   \param tBar toolbar name
1676   \param idx required index in the toolbar
1677   \return action ID or -1 if action could not be added
1678 */
1679 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1680 {
1681   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1682 }
1683
1684 /*!
1685   \brief Insert action to the toolbar.
1686   \param a action
1687   \param tBar toolbar ID
1688   \param id required action ID
1689   \param idx required index in the toolbar
1690   \return action ID or -1 if action could not be added
1691 */
1692 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1693 {
1694   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1695 }
1696
1697 /*!
1698   \brief Insert action to the toolbar.
1699   \param a action
1700   \param tBar toolbar name
1701   \param id required action ID
1702   \param idx required index in the toolbar
1703   \return action ID or -1 if action could not be added
1704 */
1705 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1706 {
1707   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1708 }
1709
1710 class CrMenu
1711 {
1712 public:
1713   CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) 
1714     : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1715   CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) 
1716     : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1717   CrMenu( const int id, const int menu, const int group, const int idx ) 
1718     : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1719   CrMenu( const int id, const QString& menu, const int group, const int idx ) 
1720     : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1721   CrMenu( QAction* action, const int menu, const int id, const int group, const int idx ) 
1722     : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1723   CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) 
1724     : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1725
1726   int execute( LightApp_Module* module ) const
1727   {
1728     if ( module ) {
1729       switch ( myCase ) {
1730       case 0:
1731         return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1732       case 1:
1733         return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1734       case 2:
1735         return module->createMenu( myId, myMenuId, myGroup, myIndex );
1736       case 3:
1737         return module->createMenu( myId, myMenuName, myGroup, myIndex );
1738       case 4:
1739         return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1740       case 5:
1741         return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1742       }
1743     }
1744     return -1;
1745   }
1746 private:
1747    int        myCase;
1748    QString    myMenuName;
1749    int        myMenuId;
1750    QString    mySubMenuName;
1751    int        myGroup;
1752    QAction*   myAction;
1753    int        myId;
1754    int        myIndex;
1755 };
1756
1757 class TCreateMenuEvent: public SALOME_Event
1758 {
1759 public:
1760   typedef int TResult;
1761   TResult myResult;
1762   const CrMenu& myCrMenu;
1763   TCreateMenuEvent( const CrMenu& crMenu ) 
1764     : myResult( -1 ), myCrMenu( crMenu ) {}
1765   virtual void Execute()
1766   {
1767     LightApp_Module* module = getActiveModule();
1768     if ( module )
1769       myResult = myCrMenu.execute( module );
1770   }
1771 };
1772
1773 /*!
1774   \brief Create main menu.
1775   \param subMenu menu name
1776   \param menu parent menu ID
1777   \param id required menu ID
1778   \param group menu group ID
1779   \param idx required index in the menu
1780   \return menu ID or -1 if menu could not be added
1781 */
1782 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1783 {
1784   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1785 }
1786
1787 /*!
1788   \brief Create main menu.
1789   \param subMenu menu name
1790   \param menu parent menu name (list of menu names separated by "|")
1791   \param id required menu ID
1792   \param group menu group ID
1793   \param idx required index in the menu
1794   \return menu ID or -1 if menu could not be added
1795 */
1796 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1797 {
1798   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1799 }
1800
1801 /*!
1802   \brief Insert action to the main menu.
1803   \param id action ID
1804   \param menu parent menu ID
1805   \param group menu group ID
1806   \param idx required index in the menu
1807   \return action ID or -1 if action could not be added
1808 */
1809 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1810 {
1811   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1812 }
1813
1814 /*!
1815   \brief Insert action to the main menu.
1816   \param id action ID
1817   \param menu parent menu name (list of menu names separated by "|")
1818   \param group menu group ID
1819   \param idx required index in the menu
1820   \return action ID or -1 if action could not be added
1821 */
1822 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1823 {
1824   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1825 }
1826
1827 /*!
1828   \brief Insert action to the main menu.
1829   \param a action
1830   \param menu parent menu ID
1831   \param group menu group ID
1832   \param idx required index in the menu
1833   \return action ID or -1 if action could not be added
1834 */
1835 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1836 {
1837   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1838 }
1839
1840 /*!
1841   \brief Insert action to the main menu.
1842   \param a action
1843   \param menu parent menu name (list of menu names separated by "|")
1844   \param group menu group ID
1845   \param idx required index in the menu
1846   \return action ID or -1 if action could not be added
1847 */
1848 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1849 {
1850   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1851 }
1852
1853 /*!
1854   \fn QAction* SalomePyQt::createSeparator();
1855   \brief Create separator action which can be used in the menu or toolbar.
1856   \return new separator action
1857 */
1858
1859 class TCreateSepEvent: public SALOME_Event 
1860 {
1861 public:
1862   typedef QAction* TResult;
1863   TResult myResult;
1864   TCreateSepEvent() 
1865     : myResult( 0 ) {}
1866   virtual void Execute() 
1867   {
1868     LightApp_Module* module = getActiveModule();
1869     if ( module )
1870       myResult = (QAction*)module->separator();
1871   }
1872 };
1873 QAction* SalomePyQt::createSeparator()
1874 {
1875   return ProcessEvent( new TCreateSepEvent() );
1876 }
1877
1878 /*!
1879   \fn QAction* SalomePyQt::createAction( const int      id,
1880                                          const QString& menuText, 
1881                                          const QString& tipText, 
1882                                          const QString& statusText, 
1883                                          const QString& icon,
1884                                          const int      key, 
1885                                          const bool     toggle );
1886   \brief Create an action which can be then used in the menu or toolbar.
1887   \param id the unique id action to be registered to
1888   \param menuText action text which should appear in menu
1889   \param tipText text which should appear in the tooltip
1890   \param statusText text which should appear in the status bar when action is activated
1891   \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1892   \param key the key accelrator for the action
1893   \param toggle if \c true the action is checkable
1894 */
1895
1896 class TCreateActionEvent: public SALOME_Event 
1897 {
1898 public:
1899   typedef QAction* TResult;
1900   TResult myResult;
1901   int     myId;
1902   QString myMenuText;
1903   QString myTipText;
1904   QString myStatusText;
1905   QString myIcon;
1906   int     myKey;
1907   bool    myToggle;
1908   TCreateActionEvent( const int id, const QString& menuText, const QString& tipText, 
1909                       const QString& statusText, const QString& icon, const int key, const bool toggle ) 
1910     : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1911       myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1912   virtual void Execute()
1913   {
1914     LightApp_Module* module = getActiveModule();
1915     if ( module ) {
1916       QIcon icon = loadIconInternal( module->name(), myIcon );
1917       myResult = (QAction*)module->action( myId );
1918       if ( myResult ) {
1919         if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() ) 
1920           myResult->setToolTip( myTipText );
1921         if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1922           myResult->setText( myMenuText );
1923         if ( myResult->icon().isNull() && !icon.isNull() ) 
1924           myResult->setIcon( icon );
1925         if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1926           myResult->setStatusTip( myStatusText );
1927         if ( myResult->shortcut().isEmpty() && myKey )
1928           myResult->setShortcut( myKey );
1929         if ( myResult->isCheckable() != myToggle )
1930           myResult->setCheckable( myToggle );
1931       }
1932       else {
1933         myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1934       }
1935       // for Python module, automatically connect action to callback slot
1936       PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1937       if ( helper ) helper->connectAction( myResult );
1938     }
1939   }
1940 };
1941 QAction* SalomePyQt::createAction( const int id,           const QString& menuText, 
1942                                    const QString& tipText, const QString& statusText, 
1943                                    const QString& icon,    const int key, const bool toggle )
1944 {
1945   return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1946 }
1947
1948 /*!
1949   \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1950   \brief Create an action group which can be then used in the menu or toolbar
1951   \param id         : the unique id action group to be registered to
1952   \param exclusive  : if \c true the action group does exclusive toggling
1953 */
1954
1955 struct TCreateActionGroupEvent: public SALOME_Event 
1956 {
1957   typedef QtxActionGroup* TResult;
1958   TResult myResult;
1959   int     myId;
1960   bool    myExclusive;
1961   TCreateActionGroupEvent( const int id, const bool exclusive )
1962     : myId( id ), myExclusive( exclusive ) {}
1963   virtual void Execute()
1964   {
1965     LightApp_Module* module = getActiveModule();
1966     if ( module )
1967       myResult = module->createActionGroup( myId, myExclusive );
1968   }
1969 };
1970 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1971 {
1972   return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1973 }
1974
1975 /*!
1976   \fn QAction* SalomePyQt::action( const int id );
1977   \brief Get action by specified identifier.
1978   \return action or 0 if action is not registered
1979 */
1980
1981 class TActionEvent: public SALOME_Event 
1982 {
1983 public:
1984   typedef QAction* TResult;
1985   TResult myResult;
1986   int     myId;
1987   TActionEvent( const int id )
1988     : myResult( 0 ), myId( id ) {}
1989   virtual void Execute()
1990   {
1991     LightApp_Module* module = getActiveModule();
1992     if ( module )
1993       myResult = (QAction*)module->action( myId );
1994   }
1995 };
1996 QAction* SalomePyQt::action( const int id )
1997 {
1998   return ProcessEvent( new TActionEvent( id ) );
1999 }
2000
2001 /*!
2002   \fn int SalomePyQt::actionId( const QAction* a );
2003   \brief Get an action identifier. 
2004   \return action ID or -1 if action is not registered
2005 */
2006
2007 class TActionIdEvent: public SALOME_Event 
2008 {
2009 public:
2010   typedef  int TResult;
2011   TResult  myResult;
2012   const QAction* myAction;
2013   TActionIdEvent( const QAction* action )
2014     : myResult( -1 ), myAction( action ) {}
2015   virtual void Execute()
2016   {
2017     LightApp_Module* module = getActiveModule();
2018     if ( module )
2019       myResult = module->actionId( myAction );
2020   }
2021 };
2022 int SalomePyQt::actionId( const QAction* a )
2023 {
2024   return ProcessEvent( new TActionIdEvent( a ) );
2025 }
2026
2027 /*!
2028   \fn int SalomePyQt::addGlobalPreference( const QString& label );
2029   \brief Add global (not module-related) preferences group.
2030   \param label global preferences group name
2031   \return preferences group identifier
2032 */
2033
2034 class TAddGlobalPrefEvent: public SALOME_Event
2035 {
2036 public:
2037   typedef int TResult;
2038   TResult myResult;
2039   QString myLabel;
2040   TAddGlobalPrefEvent( const QString& label )
2041     : myResult( -1 ), myLabel( label ) {}
2042   virtual void Execute() 
2043   {
2044     LightApp_Module* module = getActiveModule();
2045     if ( module ) {
2046       LightApp_Preferences* pref = module->getApp()->preferences();
2047       if ( pref )
2048         myResult = pref->addPreference( myLabel, -1 );
2049     }
2050   }
2051 };
2052 int SalomePyQt::addGlobalPreference( const QString& label )
2053 {
2054   return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2055 }
2056
2057 /*!
2058   \fn int SalomePyQt::addPreference( const QString& label );
2059   \brief Add module-related preferences group.
2060   \param label preferences group name
2061   \return preferences group identifier
2062 */
2063
2064 class TAddPrefEvent: public SALOME_Event 
2065 {
2066 public:
2067   typedef int TResult;
2068   TResult myResult;
2069   QString myLabel;
2070   TAddPrefEvent( const QString& label )
2071     : myResult( -1 ), myLabel( label ) {}
2072   virtual void Execute() 
2073   {
2074     LightApp_Module* module = getActiveModule();
2075     if ( module ) {
2076       LightApp_Preferences* pref = module->getApp()->preferences();
2077       if ( pref ) {
2078         int cId = pref->addPreference( module->moduleName(), -1 );
2079         if ( cId != -1 )
2080           myResult = pref->addPreference( myLabel, cId );
2081       }
2082     }
2083   }
2084 };
2085 int SalomePyQt::addPreference( const QString& label )
2086 {
2087   return ProcessEvent( new TAddPrefEvent( label ) );
2088 }
2089
2090 /*!
2091   \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2092                                      const QString& section, const QString& param );
2093   \brief Add module-related preferences.
2094   \param label preferences group name
2095   \param pId parent preferences group id
2096   \param type preferences type
2097   \param section resources file section name
2098   \param param resources file setting name
2099   \return preferences identifier
2100 */
2101
2102 class TAddPrefParamEvent: public SALOME_Event
2103 {
2104 public:
2105   typedef int TResult;
2106   TResult myResult;
2107   QString myLabel;
2108   int     myPId;
2109   int     myType;
2110   QString mySection;
2111   QString myParam;
2112   TAddPrefParamEvent( const QString& label, 
2113                       const int pId, const int type,
2114                       const QString& section, 
2115                       const QString& param )
2116     : myResult( -1 ),
2117       myLabel( label ), myPId( pId ), myType( type ), 
2118       mySection( section ), myParam ( param ) {}
2119   virtual void Execute()
2120   {
2121     LightApp_Module* module = getActiveModule();
2122     if ( module ) {
2123       LightApp_Preferences* pref = module->getApp()->preferences();
2124       if ( pref )
2125         myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2126     }
2127   }
2128 };
2129 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2130                                const QString& section, const QString& param )
2131 {
2132   return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2133 }
2134
2135 /*!
2136   \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2137   \brief Get the preferences property.
2138   \param id preferences identifier
2139   \param prop preferences property name
2140   \return preferences property value or null QVariant if property is not set
2141 */
2142
2143 class TPrefPropEvent: public SALOME_Event
2144 {
2145 public:
2146   typedef QVariant TResult;
2147   TResult myResult;
2148   int     myId;
2149   QString myProp;
2150   TPrefPropEvent( const int id, const QString& prop )
2151     : myId( id ), myProp( prop ) {}
2152   virtual void Execute()
2153   {
2154     LightApp_Module* module = getActiveModule();
2155     if ( module ) {
2156       LightApp_Preferences* pref = module->getApp()->preferences();
2157       if ( pref )
2158         myResult = pref->itemProperty( myProp, myId );
2159     }
2160   }
2161 };
2162 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2163 {
2164   return ProcessEvent( new TPrefPropEvent( id, prop ) );
2165 }
2166
2167 /*!
2168   \brief Set the preferences property.
2169   \param id preferences identifier
2170   \param prop preferences property name
2171   \param var preferences property value
2172 */
2173 void SalomePyQt::setPreferenceProperty( const int id, 
2174                                         const QString& prop,
2175                                         const QVariant& var )
2176 {
2177   class TEvent: public SALOME_Event
2178   {
2179     int      myId;
2180     QString  myProp;
2181     QVariant myVar;
2182   public:
2183     TEvent( const int id, const QString& prop, const QVariant& var ) 
2184       : myId( id ), myProp( prop ), myVar( var ) {}
2185     virtual void Execute() 
2186     {
2187       LightApp_Module* module = getActiveModule();
2188       if ( module ) {
2189         LightApp_Preferences* pref = module->getApp()->preferences();
2190         if ( pref )
2191           pref->setItemProperty( myProp, myVar, myId );
2192       }
2193     }
2194   };
2195   ProcessVoidEvent( new TEvent( id, prop, var) );
2196 }
2197
2198 /*!
2199   \brief Add the property value to the list of values.
2200
2201   This method allows creating properties which are QList<QVariant>
2202   - there is no way to pass such values directly to QVariant parameter with PyQt.
2203
2204   \param id preferences identifier
2205   \param prop preferences property name
2206   \param idx preferences property index
2207   \param var preferences property value for the index \a idx
2208 */
2209 void SalomePyQt::addPreferenceProperty( const int id, 
2210                                         const QString& prop,
2211                                         const int idx, 
2212                                         const QVariant& var )
2213 {
2214   class TEvent: public SALOME_Event
2215   {
2216     int      myId;
2217     QString  myProp;
2218     int      myIdx;
2219     QVariant myVar;
2220   public:
2221     TEvent( const int id, const QString& prop, const int idx, const QVariant& var ) 
2222       : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2223     virtual void Execute()
2224     {
2225       LightApp_Module* module = getActiveModule();
2226       if ( module ) {
2227         LightApp_Preferences* pref = module->getApp()->preferences();
2228         if ( pref ) {
2229           QVariant var =  pref->itemProperty( myProp, myId );
2230           if ( var.isValid() ) {
2231             if ( var.type() == QVariant::StringList ) {
2232               QStringList sl = var.toStringList();
2233               if ( myIdx >= 0 && myIdx < sl.count() ) 
2234                 sl[myIdx] = myVar.toString();
2235               else
2236                 sl.append( myVar.toString() );
2237               pref->setItemProperty( myProp, sl, myId );
2238             }
2239             else if ( var.type() == QVariant::List ) {
2240               QList<QVariant> vl = var.toList();
2241               if ( myIdx >= 0 && myIdx < vl.count() ) 
2242                 vl[myIdx] = myVar;
2243               else
2244                 vl.append( myVar );
2245               pref->setItemProperty( myProp, vl, myId );
2246             }
2247           }
2248           else {
2249             QList<QVariant> vl;
2250             vl.append( myVar );
2251             pref->setItemProperty( myProp, vl, myId );
2252           }
2253         }
2254       }
2255     }
2256   };
2257   ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2258 }
2259
2260 /*!
2261   \brief Put the message to the Log messages output window
2262   \param msg message text (it can be of simple rich text format)
2263   \param addSeparator boolean flag which specifies if it is necessary 
2264          to separate the message with predefined separator
2265 */
2266 void SalomePyQt::message( const QString& msg, bool addSeparator )
2267 {
2268   class TEvent: public SALOME_Event
2269   {
2270     QString  myMsg;
2271     bool     myAddSep;
2272   public:
2273     TEvent( const QString& msg, bool addSeparator ) 
2274       : myMsg( msg ), myAddSep( addSeparator ) {}
2275     virtual void Execute()
2276     {
2277       if ( LightApp_Application* anApp = getApplication() ) {
2278         LogWindow* lw = anApp->logWindow();
2279         if ( lw )
2280           lw->putMessage( myMsg, myAddSep );
2281       }
2282     }
2283   };
2284   ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2285 }
2286
2287 /*!
2288   \brief Remove all the messages from the Log messages output window.
2289 */
2290 void SalomePyQt::clearMessages()
2291 {
2292   class TEvent: public SALOME_Event
2293   {
2294   public:
2295     TEvent() {}
2296     virtual void Execute()
2297     {
2298       if ( LightApp_Application* anApp = getApplication() ) {
2299         LogWindow* lw = anApp->logWindow();
2300         if ( lw )
2301           lw->clear();
2302       }
2303     }
2304   };
2305   ProcessVoidEvent( new TEvent() );
2306 }
2307
2308 /*!
2309   \brief Gets window with specified identifier 
2310   \internal
2311   \param id window identifier 
2312   \return pointer on the window
2313 */
2314 static SUIT_ViewWindow* getWnd( const int id )
2315 {
2316   SUIT_ViewWindow* resWnd = 0;
2317
2318   LightApp_Application* app = getApplication();
2319   if ( app )
2320   {
2321     ViewManagerList vmlist = app->viewManagers();
2322     foreach( SUIT_ViewManager* vm, vmlist )
2323     {
2324       QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2325       foreach ( SUIT_ViewWindow* vw, vwlist )
2326       {
2327         if ( id == vw->getId() )
2328         {
2329           resWnd = vw;
2330           break;
2331         }
2332       }
2333     }
2334   }
2335
2336   return resWnd;
2337 }
2338
2339 /*!
2340   \fn QList<int> SalomePyQt::getViews();
2341   \brief Get list of integer identifiers of all the currently opened views
2342   \return list of integer identifiers of all the currently opened views
2343 */
2344
2345 class TGetViews: public SALOME_Event
2346 {
2347 public:
2348   typedef QList<int> TResult;
2349   TResult myResult;
2350   TGetViews() {}
2351   virtual void Execute() 
2352   {
2353     myResult.clear();
2354     LightApp_Application* app  = getApplication();
2355     if ( app )
2356     {
2357       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2358       if ( tabDesk )
2359       {
2360         QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2361         SUIT_ViewWindow* wnd;
2362         foreach ( wnd, wndlist )
2363           myResult.append( wnd->getId() );
2364       }
2365     }
2366   }
2367 };
2368 QList<int> SalomePyQt::getViews()
2369 {
2370   return ProcessEvent( new TGetViews() );
2371 }
2372
2373 /*!
2374   \fn int SalomePyQt::getActiveView();
2375   \brief Get integer identifier of the currently active view
2376   \return integer identifier of the currently active view
2377 */
2378
2379 class TGetActiveView: public SALOME_Event
2380 {
2381 public:
2382   typedef int TResult;
2383   TResult myResult;
2384   TGetActiveView()
2385     : myResult( -1 ) {}
2386   virtual void Execute() 
2387   {
2388     LightApp_Application* app = getApplication();
2389     if ( app )
2390     {
2391       SUIT_ViewManager* viewMgr = app->activeViewManager();
2392       if ( viewMgr )
2393       {
2394         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2395         if ( wnd )
2396           myResult = wnd->getId();
2397       }
2398     }
2399   }
2400 };
2401 int SalomePyQt::getActiveView()
2402 {
2403   return ProcessEvent( new TGetActiveView() );
2404 }
2405
2406 /*!                      
2407   \fn QString SalomePyQt::getViewType( const int id );
2408   \brief Get type of the specified view, e.g. "OCCViewer"
2409   \param id window identifier
2410   \return view type
2411 */ 
2412
2413 class TGetViewType: public SALOME_Event
2414 {
2415 public:
2416   typedef QString TResult;
2417   TResult myResult;
2418   int myWndId;
2419   TGetViewType( const int id )
2420     : myWndId( id ) {}
2421   virtual void Execute() 
2422   {
2423     SUIT_ViewWindow* wnd = getWnd( myWndId );
2424     if ( wnd )
2425     {
2426       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2427       if ( viewMgr )
2428         myResult = viewMgr->getType();
2429     }
2430   }
2431 };
2432 QString SalomePyQt::getViewType( const int id )
2433 {
2434   return ProcessEvent( new TGetViewType( id ) );
2435 }
2436
2437 /*!
2438   \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2439   \brief Change view caption  
2440   \param id window identifier
2441   \param title new window title
2442   \return \c true if operation is completed successfully and \c false otherwise 
2443 */
2444
2445 class TSetViewTitle: public SALOME_Event
2446 {
2447 public:
2448   typedef bool TResult;
2449   TResult myResult;
2450   int myWndId;
2451   QString myTitle;
2452   TSetViewTitle( const int id, const QString& title )
2453     : myResult( false ),
2454       myWndId( id ),
2455       myTitle( title ) {}
2456   virtual void Execute() 
2457   {
2458     SUIT_ViewWindow* wnd = getWnd( myWndId );
2459     if ( wnd )
2460     {
2461       wnd->setWindowTitle( myTitle );
2462       myResult = true;
2463     }
2464   }
2465 };
2466 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2467 {
2468   return ProcessEvent( new TSetViewTitle( id, title ) );
2469 }
2470
2471
2472 /*!
2473   \fn QString SalomePyQt::getViewTitle( const int id );
2474   \brief Get view caption  
2475   \param id window identifier
2476   \return view caption  
2477 */
2478
2479 class TGetViewTitle: public SALOME_Event
2480 {
2481 public:
2482   typedef QString TResult;
2483   TResult myResult;
2484   int myWndId;
2485   TGetViewTitle( const int id )
2486     : myWndId( id ) {}
2487   virtual void Execute() 
2488   {
2489     SUIT_ViewWindow* wnd = getWnd( myWndId );
2490     if ( wnd )
2491       myResult = wnd->windowTitle();
2492   }
2493 };
2494 QString SalomePyQt::getViewTitle( const int id )
2495 {
2496   return ProcessEvent( new TGetViewTitle( id ) );
2497 }
2498
2499 /*!
2500   \fn QList<int> SalomePyQt::findViews( const QString& type );
2501   \brief Get list of integer identifiers of all the 
2502          currently opened views of the specified type
2503   \param type viewer type
2504   \return list of integer identifiers 
2505 */
2506
2507 class TFindViews: public SALOME_Event
2508 {
2509 public:
2510   typedef QList<int> TResult;
2511   TResult myResult;
2512   QString myType;
2513   TFindViews( const QString& type )
2514     : myType( type ) {}
2515   virtual void Execute() 
2516   {
2517     myResult.clear();
2518     LightApp_Application* app  = getApplication();
2519     if ( app )
2520     {
2521       ViewManagerList vmList;
2522       app->viewManagers( myType, vmList );
2523       SUIT_ViewManager* viewMgr;
2524       foreach ( viewMgr, vmList )
2525       {
2526         QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2527         for ( int i = 0, n = vec.size(); i < n; i++ )
2528         {
2529           SUIT_ViewWindow* wnd = vec[ i ];
2530           if ( wnd )
2531             myResult.append( wnd->getId() );
2532         }
2533       }
2534     }
2535   }
2536 };
2537 QList<int> SalomePyQt::findViews( const QString& type )
2538 {
2539   return ProcessEvent( new TFindViews( type ) );
2540 }
2541
2542 /*!
2543   \fn bool SalomePyQt::activateView( const int id );
2544   \brief Activate view
2545   \param id window identifier
2546   \return \c true if operation is completed successfully and \c false otherwise 
2547 */
2548
2549 class TActivateView: public SALOME_Event
2550 {
2551 public:
2552   typedef bool TResult;
2553   TResult myResult;
2554   int myWndId;
2555   TActivateView( const int id )
2556     : myResult( false ),
2557       myWndId( id ) {}
2558   virtual void Execute() 
2559   {
2560     SUIT_ViewWindow* wnd = getWnd( myWndId );
2561     if ( wnd )
2562     {
2563       wnd->setFocus();
2564       myResult = true;
2565     }
2566   }
2567 };
2568 bool SalomePyQt::activateView( const int id )
2569 {
2570   return ProcessEvent( new TActivateView( id ) );
2571 }
2572
2573 /*!
2574   \fn int SalomePyQt::createView( const QString& type );
2575   \brief Create new view and activate it
2576   \param type viewer type
2577   \return integer identifier of created view (or -1 if view could not be created)
2578 */
2579
2580 class TCreateView: public SALOME_Event
2581 {
2582 public:
2583   typedef int TResult;
2584   TResult myResult;
2585   QString myType;
2586   TCreateView( const QString& theType )
2587     : myResult( -1 ),
2588       myType( theType ) {}
2589   virtual void Execute() 
2590   {
2591     LightApp_Application* app  = getApplication();
2592     if ( app )
2593     {
2594       SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2595       if ( viewMgr )
2596       {
2597         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2598         if ( wnd )
2599           myResult = wnd->getId();
2600       }
2601     }
2602   }
2603 };
2604 int SalomePyQt::createView( const QString& type )
2605 {
2606   return ProcessEvent( new TCreateView( type ) );
2607 }
2608
2609 /*!
2610   \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2611   \brief Create new view with custom widget embedded and activate it
2612   \param type viewer type
2613   \param w custom widget
2614   \return integer identifier of created view (or -1 if view could not be created)
2615 */
2616
2617 class TCreateViewWg: public SALOME_Event
2618 {
2619 public:
2620   typedef int TResult;
2621   TResult myResult;
2622   QString myType;
2623   QWidget* myWidget;
2624   TCreateViewWg( const QString& theType, QWidget* w )
2625     : myResult( -1 ),
2626       myType( theType ),
2627       myWidget( w ) {}
2628   virtual void Execute() 
2629   {
2630     LightApp_Application* app  = getApplication();
2631     if ( app )
2632     {
2633       SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2634       if ( viewMgr )
2635       {
2636         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2637         if ( wnd )
2638           myResult = wnd->getId();
2639       }
2640     }
2641   }
2642 };
2643 int SalomePyQt::createView( const QString& type, QWidget* w )
2644 {
2645   return ProcessEvent( new TCreateViewWg( type, w ) );
2646 }
2647
2648 /*!
2649   \fn bool SalomePyQt::closeView( const int id );
2650   \brief Close view
2651   \param id window identifier
2652   \return \c true if operation is completed successfully and \c false otherwise 
2653 */
2654
2655 class TCloseView: public SALOME_Event
2656 {
2657 public:
2658   typedef bool TResult;
2659   TResult myResult;
2660   int myWndId;
2661   TCloseView( const int id )
2662     : myResult( false ),
2663       myWndId( id ) {}
2664   virtual void Execute() 
2665   {
2666     SUIT_ViewWindow* wnd = getWnd( myWndId );
2667     if ( wnd )
2668     {
2669       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2670       if ( viewMgr )
2671       {
2672         wnd->close();
2673         myResult = true;
2674       }
2675     }
2676   }
2677 };
2678 bool SalomePyQt::closeView( const int id )
2679 {
2680   return ProcessEvent( new TCloseView( id ) );
2681 }
2682
2683 /*!
2684   \fn int SalomePyQt::cloneView( const int id );
2685   \brief Clone view (if this operation is supported for specified view type)
2686   \param id window identifier
2687   \return integer identifier of the cloned view or -1 or operation could not be performed
2688 */
2689
2690 class TCloneView: public SALOME_Event
2691 {
2692 public:
2693   typedef int TResult;
2694   TResult myResult;
2695   int myWndId;
2696   TCloneView( const int id )
2697     : myResult( -1 ),
2698       myWndId( id ) {}
2699   virtual void Execute() 
2700   {
2701     SUIT_ViewWindow* wnd = getWnd( myWndId );
2702     if ( wnd )
2703     {
2704       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2705       if ( viewMgr )
2706       {
2707         if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2708         {
2709           OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2710           occView->onCloneView();
2711
2712           wnd = viewMgr->getActiveView();
2713           if ( wnd )
2714             myResult = wnd->getId();
2715         }
2716         else if ( wnd->inherits( "Plot2d_ViewWindow" ) ) 
2717         {
2718           Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2719           Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2720           if ( viewMgr2d && srcWnd2d )
2721           {
2722             Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2723             myResult = resWnd->getId();
2724           }
2725         }
2726       }
2727     }
2728   }
2729 };
2730 int SalomePyQt::cloneView( const int id )
2731 {
2732   return ProcessEvent( new TCloneView( id ) );
2733 }
2734
2735 /*!
2736   \fn bool SalomePyQt::isViewVisible( const int id );
2737   \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2738   \param id window identifier
2739   \return \c true if view is visible and \c false otherwise 
2740 */
2741
2742 class TIsViewVisible: public SALOME_Event
2743 {
2744 public:
2745   typedef bool TResult;
2746   TResult myResult;
2747   int myWndId;
2748   TIsViewVisible( const int id )
2749     : myResult( false ),
2750       myWndId( id ) {}
2751   virtual void Execute() 
2752   {
2753     SUIT_ViewWindow* wnd = getWnd( myWndId );
2754     if ( wnd )
2755     {
2756       QWidget* p = wnd->parentWidget();
2757       myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2758     }
2759   }
2760 };
2761 bool SalomePyQt::isViewVisible( const int id )
2762 {
2763   return ProcessEvent( new TIsViewVisible( id ) );
2764 }
2765   
2766 /*!
2767   \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2768   \brief Set / clear view's "closable" option. By default any view is closable
2769         (i.e. can be closed by the user).
2770   \param id window identifier
2771   \param on new "closable" option's value
2772 */
2773
2774 void SalomePyQt::setViewClosable( const int id, const bool on )
2775 {
2776   class TEvent: public SALOME_Event
2777   {
2778     int myWndId;
2779     bool myOn;
2780   public:
2781     TEvent( const int id, const bool on )
2782       : myWndId( id ), myOn( on ) {}
2783     virtual void Execute()
2784     {
2785       SUIT_ViewWindow* wnd = getWnd( myWndId );
2786       if ( wnd ) wnd->setClosable( myOn );
2787     }
2788   };
2789   ProcessVoidEvent( new TEvent( id, on ) );
2790 }
2791
2792 /*!
2793   \fn bool SalomePyQt::isViewClosable( const int id );
2794   \brief Check whether view is closable (i.e. can be closed by the user)
2795   \param id window identifier
2796   \return \c true if view is closable or \c false otherwise 
2797 */
2798
2799 class TIsViewClosable: public SALOME_Event
2800 {
2801 public:
2802   typedef bool TResult;
2803   TResult myResult;
2804   int myWndId;
2805   TIsViewClosable( const int id )
2806     : myResult( true ),
2807       myWndId( id ) {}
2808   virtual void Execute() 
2809   {
2810     SUIT_ViewWindow* wnd = getWnd( myWndId );
2811     if ( wnd )
2812       myResult = wnd->closable();
2813   }
2814 };
2815
2816 bool SalomePyQt::isViewClosable( const int id )
2817 {
2818   return ProcessEvent( new TIsViewClosable( id ) );
2819 }
2820
2821 /*!
2822   \fn bool SalomePyQt::groupAllViews();
2823   \brief Group all views to the single tab area
2824   \return \c true if operation is completed successfully and \c false otherwise 
2825 */
2826
2827 class TGroupAllViews: public SALOME_Event
2828 {
2829 public:
2830   typedef bool TResult;
2831   TResult myResult;
2832   TGroupAllViews()
2833     : myResult( false ) {}
2834   virtual void Execute() 
2835   {
2836     LightApp_Application* app  = getApplication();
2837     if ( app )
2838     {
2839       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2840       if ( tabDesk )
2841       {
2842         QtxWorkstack* wStack = tabDesk->workstack();
2843         if ( wStack )
2844         {
2845           wStack->stack();
2846           myResult = true;
2847         }
2848       }
2849     }
2850   }
2851 };
2852 bool SalomePyQt::groupAllViews()
2853 {
2854   return ProcessEvent( new TGroupAllViews() );
2855 }
2856
2857 /*!
2858   \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2859   \brief Split tab area to which view with identifier belongs to
2860   \param id window identifier
2861   \param ori orientation of split operation
2862   \param action action to be performed
2863   \return \c true if operation is completed successfully \c false otherwise 
2864 */
2865
2866 class TSplitView: public SALOME_Event
2867 {
2868 public:
2869   typedef bool TResult;
2870   TResult myResult;
2871   int myWndId;
2872   Orientation myOri;
2873   Action myAction;
2874   TSplitView( const int id, 
2875               const Orientation ori, 
2876               const Action action )
2877     : myResult( false ),
2878       myWndId( id ),
2879       myOri( ori ),
2880       myAction( action ) {}
2881   virtual void Execute() 
2882   {
2883     SUIT_ViewWindow* wnd = getWnd( myWndId );
2884     if ( wnd )
2885     {
2886       // activate view
2887       // wnd->setFocus(); ???
2888
2889       // split workstack
2890       if ( getApplication() )
2891       {
2892         STD_TabDesktop* desk = 
2893           dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2894         if ( desk )
2895         {
2896           QtxWorkstack* wStack = desk->workstack();
2897           if ( wStack )
2898           {
2899             Qt::Orientation qtOri = 
2900               ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2901
2902             QtxWorkstack::SplitType sType;
2903             if ( myAction == MoveWidget )
2904               sType = QtxWorkstack::SplitMove;
2905             else if ( myAction == LeaveWidget )
2906               sType = QtxWorkstack::SplitStay;
2907             else 
2908               sType = QtxWorkstack::SplitAt;
2909
2910             wStack->Split( wnd, qtOri, sType );
2911             myResult = true;
2912           }
2913         }
2914       }
2915     }
2916   }
2917 };
2918 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2919 {
2920   return ProcessEvent( new TSplitView( id, ori, action ) );
2921 }
2922
2923 /*!
2924   \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
2925   \brief Move view with the first identifier to the same area which 
2926          another view with the second identifier belongs to
2927   \param id source window identifier
2928   \param id_to destination window identifier  
2929   param before specifies whether the first viewt has to be moved before or after 
2930         the second view
2931   \return \c true if operation is completed successfully and \c false otherwise 
2932 */
2933
2934 class TMoveView: public SALOME_Event
2935 {
2936 public:
2937   typedef bool TResult;
2938   TResult myResult;
2939   int myWndId;
2940   int myWndToId;
2941   bool myIsBefore;
2942   TMoveView( const int id, const int id_to, const bool before )
2943     : myResult( false ),
2944     myWndId( id ),
2945     myWndToId( id_to ),
2946     myIsBefore( before ) {}
2947   virtual void Execute() 
2948   {
2949     SUIT_ViewWindow* wnd = getWnd( myWndId );
2950     SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
2951     if ( wnd && wnd_to )
2952     {
2953       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
2954         getApplication()->desktop() )->workstack();
2955       if ( wStack )
2956         myResult = wStack->move( wnd, wnd_to, myIsBefore );
2957     }
2958   }
2959 };
2960 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
2961 {
2962   return ProcessEvent( new TMoveView( id, id_to, before ) );
2963 }
2964
2965 /*!
2966   \fn QList<int> SalomePyQt::neighbourViews( const int id );
2967   \brief Get list of views identifiers that belongs to the same area as 
2968          specified view (excluding it)
2969   \param id window identifier
2970   \return list of views identifiers
2971 */
2972
2973 class TNeighbourViews: public SALOME_Event
2974 {
2975 public:
2976   typedef QList<int> TResult;
2977   TResult myResult;
2978   int myWndId;
2979   TNeighbourViews( const int id )
2980     : myWndId( id ) {}
2981   virtual void Execute() 
2982   {
2983     myResult.clear();
2984     SUIT_ViewWindow* wnd = getWnd( myWndId );
2985     if ( wnd )
2986     {
2987       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
2988         getApplication()->desktop() )->workstack();
2989       if ( wStack )
2990       {
2991         QWidgetList wgList = wStack->windowList( wnd );
2992         QWidget* wg;
2993         foreach ( wg, wgList )
2994         {
2995           SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
2996           if ( tmpWnd && tmpWnd != wnd )
2997             myResult.append( tmpWnd->getId() );
2998         }
2999       }
3000     }
3001   }
3002 };
3003 QList<int> SalomePyQt::neighbourViews( const int id )
3004 {
3005   return ProcessEvent( new TNeighbourViews( id ) );
3006 }
3007
3008
3009 /*!
3010   \fn QString SalomePyQt::createObject( const QString& parent );
3011   \brief Create empty data object
3012   \param parent entry of parent data object
3013   \return entry of created data object
3014 */
3015
3016 class TCreateEmptyObjectEvent: public SALOME_Event
3017 {
3018 public:
3019   typedef QString TResult;
3020   TResult  myResult;
3021   QString  myParent;
3022   TCreateEmptyObjectEvent( const QString& parent )
3023     : myParent( parent ) {}
3024   virtual void Execute() 
3025   {
3026     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3027     if ( module ) {
3028        myResult = module->createObject( myParent );
3029     }
3030     else {
3031       if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3032     }
3033   }
3034 };
3035 QString SalomePyQt::createObject( const QString& parent )
3036 {
3037   return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3038 }
3039
3040 /*!
3041   \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3042                                         const QString& tooltip,const QString& parent );
3043   \brief Create new data object with specified name, icon and tooltip
3044   \param name data object name
3045   \param icon data object icon
3046   \param toolTip data object tooltip
3047   \param parent entry of parent data object
3048   \return entry of created data object
3049 */
3050
3051 class TCreateObjectEvent: public SALOME_Event 
3052 {
3053 public:
3054   typedef QString TResult;
3055   TResult myResult;
3056   QString myParent;
3057   QString myName;
3058   QString myIcon;
3059   QString myToolTip;
3060   TCreateObjectEvent( const QString& name,
3061                       const QString& icon,
3062                       const QString& tooltip,
3063                       const QString& parent )
3064     : myName( name ),
3065       myIcon( icon ),
3066       myToolTip( tooltip ),
3067       myParent( parent ) {}
3068   virtual void Execute()
3069   {
3070     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3071     if ( module ) {
3072       myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3073     }
3074     else {
3075       if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3076     }
3077   }
3078 };
3079 QString SalomePyQt::createObject( const QString& name,
3080                                   const QString& icon,
3081                                   const QString& toolTip,
3082                                   const QString& parent )
3083 {
3084   return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3085 }
3086
3087
3088 /*!
3089   \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3090   \brief Set data object name
3091   \param entry data object entry
3092   \param name data object name
3093 */
3094 class TSetNameEvent: public SALOME_Event
3095 {
3096 public:
3097   QString myEntry;
3098   QString myName;
3099   TSetNameEvent( const QString& entry,
3100                  const QString& name )
3101   : myEntry( entry ),
3102     myName( name ) {}
3103   virtual void Execute()
3104   {
3105     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3106     if ( module ) {
3107       module->setName( myEntry, myName );
3108     }
3109     else {
3110       if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3111     }
3112   }
3113 };
3114 void SalomePyQt::setName( const QString& entry, const QString& name )
3115 {
3116   ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3117 }
3118
3119 /*!
3120   \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3121   \brief Set data object icon
3122   \param entry data object entry
3123   \param icon data object icon file name (icon is loaded from module resources)
3124 */
3125
3126 class TSetIconEvent: public SALOME_Event
3127 {
3128 public:
3129   QString myEntry;
3130   QString myIcon;
3131   TSetIconEvent( const QString& entry,
3132                  const QString& icon )
3133   : myEntry( entry ),
3134     myIcon( icon ) {}
3135   virtual void Execute()
3136   {
3137     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3138     if ( module ) {
3139       module->setIcon( myEntry, myIcon );
3140     }
3141     else {
3142       if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3143     }
3144   }
3145 };
3146
3147 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3148 {
3149   ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3150 }
3151
3152 /*!
3153   \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3154   \brief Set data object tooltip
3155   \param entry data object entry
3156   \param toolTip data object tooltip
3157 */
3158
3159 class TSetToolTipEvent: public SALOME_Event
3160 {
3161 public:
3162   QString myEntry;
3163   QString myToolTip;
3164   TSetToolTipEvent( const QString& entry,
3165                     const QString& toolTip )
3166     : myEntry( entry ),
3167       myToolTip( toolTip ) {}
3168   virtual void Execute()
3169   {
3170     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3171     if ( module ) {
3172       module->setToolTip( myEntry, myToolTip );
3173     }
3174     else {
3175       if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3176     }
3177   }
3178 };
3179 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3180 {
3181   ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3182 }
3183
3184 /*!
3185   \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3186   \brief Set reference to another data object
3187   \param entry data object entry
3188   \param refEntry referenced data object entry
3189 */
3190
3191 class TSetRefEvent: public SALOME_Event
3192 {
3193 public:
3194   QString myEntry;
3195   QString myRefEntry;
3196   TSetRefEvent( const QString& entry,
3197                 const QString& refEntry )
3198     : myEntry( entry ),
3199       myRefEntry( refEntry ) {}
3200   virtual void Execute()
3201   {
3202     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3203     if ( module ) {
3204       module->setReference( myEntry, myRefEntry );
3205     }
3206     else {
3207       if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3208     }
3209   }
3210 };
3211 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3212 {
3213   ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3214 }
3215
3216 /*!
3217   \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3218   \brief Set data object color
3219   \param entry data object entry
3220   \param color data object color
3221  */
3222
3223 class TSetColorEvent: public SALOME_Event
3224 {
3225 public:
3226   QString myEntry;
3227   QColor  myColor;
3228   TSetColorEvent( const QString& entry,
3229                   const QColor& color )
3230     : myEntry( entry ),
3231       myColor( color ) {}
3232   virtual void Execute()
3233   {
3234     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3235     if ( module ) {
3236       module->setColor( myEntry, myColor );
3237     }
3238     else {
3239       if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3240     }
3241   }
3242 };
3243 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3244 {
3245   ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3246 }
3247
3248 /*!
3249   \fn QString SalomePyQt::getName( const QString& entry );
3250   \brief Get data object name
3251   \param entry data object entry
3252   \return data object name
3253 */
3254
3255 class TGetNameEvent: public SALOME_Event
3256 {
3257 public:
3258   typedef QString TResult;
3259   TResult myResult;
3260   QString myEntry;
3261   TGetNameEvent( const QString& entry )
3262     : myEntry( entry ) {}
3263   virtual void Execute()
3264   {
3265     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3266     if ( module ) {
3267       myResult = module->getName( myEntry );
3268     }
3269     else {
3270       if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3271     }
3272   }
3273 };
3274 QString SalomePyQt::getName( const QString& entry )
3275 {
3276   return ProcessEvent( new TGetNameEvent( entry ) );
3277 }
3278
3279 /*!
3280   \fn QString SalomePyQt::getToolTip( const QString& entry );
3281   \brief Get data object tooltip
3282   \param entry data object entry
3283   \return data object tooltip
3284 */
3285
3286 class TGetToolTipEvent: public SALOME_Event
3287 {
3288 public:
3289   typedef QString TResult;
3290   TResult myResult;
3291   QString myEntry;
3292   TGetToolTipEvent( const QString& entry )
3293   : myEntry( entry ) {}
3294   virtual void Execute()
3295   {
3296     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3297     if ( module ) {
3298       myResult = module->getToolTip( myEntry );
3299     }
3300     else {
3301       if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3302     }
3303   }
3304 };
3305 QString SalomePyQt::getToolTip( const QString& entry )
3306 {
3307   return ProcessEvent( new TGetToolTipEvent( entry ) );
3308 }
3309
3310 /*
3311   \fn QString SalomePyQt::getReference( const QString& entry );
3312   \brief Get entry of the referenced object (if there's any)
3313   \param entry data object entry
3314   \return referenced data object entry
3315 */
3316
3317 class TGetRefEvent: public SALOME_Event
3318 {
3319 public:
3320   typedef QString TResult;
3321   TResult myResult;
3322   QString myEntry;
3323   TGetRefEvent( const QString& entry )
3324   : myEntry( entry ) {}
3325   virtual void Execute()
3326   {
3327     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3328     if ( module ) {
3329       myResult = module->getReference( myEntry );
3330     }
3331     else {
3332       if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3333     }
3334   }
3335 };
3336 QString SalomePyQt::getReference( const QString& entry )
3337 {
3338   return ProcessEvent( new TGetRefEvent( entry ) );
3339 }
3340
3341 /*!
3342   \fn QColor SalomePyQt::getColor( const QString& entry );
3343   \brief Get data object color
3344   \param entry data object entry
3345   \return data object color
3346 */
3347
3348 class TGetColorEvent: public SALOME_Event
3349 {
3350 public:
3351   typedef QColor TResult;
3352   TResult myResult;
3353   QString myEntry;
3354   TGetColorEvent( const QString& entry )
3355   : myEntry( entry ) {}
3356   virtual void Execute()
3357   {
3358     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3359     if ( module ) {
3360       myResult = module->getColor( myEntry );
3361     }
3362     else {
3363       if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3364     }
3365   }
3366 };
3367 QColor SalomePyQt::getColor( const QString& entry )
3368 {
3369   return ProcessEvent( new TGetColorEvent( entry ) );
3370 }
3371
3372 /*!
3373   \fn void SalomePyQt::removeChildren( const QString& entry );
3374   \brief Remove all child data objects from specified data object
3375   \param entry data object entry
3376 */
3377
3378 class TRemoveChildEvent: public SALOME_Event
3379 {
3380 public:
3381   QString myEntry;
3382   TRemoveChildEvent( const QString& entry )
3383   : myEntry( entry ) {}
3384   virtual void Execute()
3385   {
3386     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3387     if ( module ) {
3388       module->removeChildren( myEntry );
3389     }
3390     else {
3391       if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3392     }
3393   }
3394 };
3395 void SalomePyQt::removeChildren( const QString& entry )
3396 {
3397   ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3398 }
3399 void SalomePyQt::removeChild( const QString& entry )
3400 {
3401   if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3402   removeChildren( entry );
3403 }
3404
3405 /*!
3406   \fn void SalomePyQt::removeObject( const QString& entry );
3407   \brief Remove object by entry
3408   \param entry data object entry
3409 */
3410
3411 class TRemoveObjectEvent: public SALOME_Event
3412 {
3413 public:
3414   QString myEntry;
3415   
3416   TRemoveObjectEvent( const QString& entry )
3417   : myEntry( entry ) {}
3418   virtual void Execute()
3419   {
3420     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3421     if ( module ) {
3422       module->removeObject( myEntry );
3423     }
3424     else {
3425       if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3426     }
3427   }
3428 };
3429 void SalomePyQt::removeObject( const QString& entry )
3430 {
3431   ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3432 }
3433
3434 /*!
3435   \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3436   \brief Get entries of all child data objects of specified data object
3437   \param entry data object entry
3438   \param recursive \c true for recursive processing
3439 */
3440
3441 class TGetChildrenEvent: public SALOME_Event
3442 {
3443 public:
3444   typedef QStringList TResult;
3445   TResult myResult;
3446   QString myEntry;
3447   bool    myRecursive; 
3448   TGetChildrenEvent( const QString& entry, const bool recursive )
3449     : myEntry( entry ),
3450       myRecursive( recursive ) {}
3451   virtual void Execute()
3452   {
3453     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3454     if ( module ) {
3455       myResult = module->getChildren( myEntry, myRecursive );
3456     }
3457     else {
3458       if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3459     }
3460   }
3461 };
3462 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3463 {
3464   return ProcessEvent( new TGetChildrenEvent( entry, recursive ) ); 
3465 }