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