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