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