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