Salome HOME
Allow setting / getting QByteArray preference item in Python modules.
[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   \brief Add double setting to the application preferences.
1015   \param section resources file section name 
1016   \param name setting name
1017   \param value new setting value
1018 */
1019 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1020 {
1021   class TEvent: public SALOME_Event 
1022   {
1023     QString mySection;
1024     QString myName;
1025     double  myValue;
1026   public:
1027     TEvent( const QString& section, const QString& name, double value ) 
1028       : mySection( section ), myName( name ), myValue( value ) {}
1029     virtual void Execute() 
1030     {
1031       if ( SUIT_Session::session() ) {
1032         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1033         if ( !mySection.isEmpty() && !myName.isEmpty() )
1034           resMgr->setValue( mySection, myName, myValue );
1035       }
1036     }
1037   };
1038   ProcessVoidEvent( new TEvent( section, name, value ) );
1039 }
1040
1041 /*!
1042   \brief Add integer setting to the application preferences.
1043   \param section resources file section name 
1044   \param name setting name
1045   \param value new setting value
1046 */
1047 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1048 {
1049   class TEvent: public SALOME_Event 
1050   {
1051     QString mySection;
1052     QString myName;
1053     int     myValue;
1054   public:
1055     TEvent( const QString& section, const QString& name, int value ) 
1056       : mySection( section ), myName( name ), myValue( value ) {}
1057     virtual void Execute() 
1058     {
1059       if ( SUIT_Session::session() ) {
1060         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1061         if ( !mySection.isEmpty() && !myName.isEmpty() )
1062           resMgr->setValue( mySection, myName, myValue );
1063       }
1064     }
1065   };
1066   ProcessVoidEvent( new TEvent( section, name, value ) );
1067 }
1068
1069 /*!
1070   \brief Add boolean setting to the application preferences.
1071   \param section resources file section name 
1072   \param name setting name
1073   \param value new setting value
1074   \param dumb this parameter is used in order to avoid sip compilation error 
1075   because of conflicting int and bool types
1076 */
1077 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1078 {
1079   class TEvent: public SALOME_Event 
1080   {
1081     QString mySection;
1082     QString myName;
1083     bool    myValue;
1084   public:
1085     TEvent( const QString& section, const QString& name, bool value ) 
1086       : mySection( section ), myName( name ), myValue( value ) {}
1087     virtual void Execute() 
1088     {
1089       if ( SUIT_Session::session() ) {
1090         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1091         if ( !mySection.isEmpty() && !myName.isEmpty() )
1092           resMgr->setValue( mySection, myName, myValue );
1093       }
1094     }
1095   };
1096   ProcessVoidEvent( new TEvent( section, name, value ) );
1097 }
1098
1099 /*!
1100   \brief Add string setting to the application preferences.
1101   \param section resources file section name 
1102   \param name setting name
1103   \param value new setting value
1104 */
1105 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1106 {
1107   class TEvent: public SALOME_Event 
1108   {
1109     QString mySection;
1110     QString myName;
1111     QString myValue;
1112   public:
1113     TEvent( const QString& section, const QString& name, const QString& value ) 
1114       : mySection( section ), myName( name ), myValue( value ) {}
1115     virtual void Execute() 
1116     {
1117       if ( SUIT_Session::session() ) {
1118         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1119         if ( !mySection.isEmpty() && !myName.isEmpty() )
1120           resMgr->setValue( mySection, myName, myValue );
1121       }
1122     }
1123   };
1124   ProcessVoidEvent( new TEvent( section, name, value ) );
1125 }
1126
1127 /*!
1128   \brief Add color setting to the application preferences.
1129   \param section resources file section name 
1130   \param name setting name
1131   \param value new setting value
1132 */
1133 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1134 {
1135   class TEvent: public SALOME_Event 
1136   {
1137     QString mySection;
1138     QString myName;
1139     QColor  myValue;
1140   public:
1141     TEvent( const QString& section, const QString& name, const QColor& value ) 
1142       : mySection( section ), myName( name ), myValue( value ) {}
1143     virtual void Execute() 
1144     {
1145       if ( SUIT_Session::session() ) {
1146         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1147         if ( !mySection.isEmpty() && !myName.isEmpty() )
1148           resMgr->setValue( mySection, myName, myValue );
1149       }
1150     }
1151   };
1152   ProcessVoidEvent( new TEvent( section, name, value ) );
1153 }
1154
1155 /*!
1156   \brief Add byte array setting to the application preferences.
1157   \param section resources file section name 
1158   \param name setting name
1159   \param value new setting value
1160 */
1161 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1162 {
1163   class TEvent: public SALOME_Event 
1164   {
1165     QString    mySection;
1166     QString    myName;
1167     QByteArray myValue;
1168   public:
1169     TEvent( const QString& section, const QString& name, const QByteArray& value ) 
1170       : mySection( section ), myName( name ), myValue( value ) {}
1171     virtual void Execute() 
1172     {
1173       if ( SUIT_Session::session() ) {
1174         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1175         if ( !mySection.isEmpty() && !myName.isEmpty() )
1176           resMgr->setValue( mySection, myName, myValue );
1177       }
1178     }
1179   };
1180   ProcessVoidEvent( new TEvent( section, name, value ) );
1181 }
1182
1183 /*!
1184   \fn int SalomePyQt::integerSetting( const QString& section, 
1185                                       const QString& name, 
1186                                       const int def );
1187   \brief Get integer setting from the application preferences.
1188   \param section resources file section name 
1189   \param name setting name
1190   \param def default value which is returned if the setting is not found
1191   \return setting value
1192 */
1193
1194 class TGetIntSettingEvent: public SALOME_Event 
1195 {
1196 public:
1197   typedef int TResult;
1198   TResult myResult;
1199   QString mySection;
1200   QString myName;
1201   TResult myDefault;
1202   TGetIntSettingEvent( const QString& section, const QString& name, const int def ) 
1203     : mySection( section ), myName( name ), myDefault( def ) {}
1204   virtual void Execute() 
1205   {
1206     if ( SUIT_Session::session() ) {
1207       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1208       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1209     }
1210   }
1211 };
1212 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1213 {
1214   return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1215 }
1216
1217 /*!
1218   \fn double SalomePyQt::doubleSetting( const QString& section, 
1219                                         const QString& name, 
1220                                         const double def );
1221   \brief Get double setting from the application preferences.
1222   \param section resources file section name 
1223   \param name setting name
1224   \param def default value which is returned if the setting is not found
1225   \return setting value
1226 */
1227
1228 class TGetDblSettingEvent: public SALOME_Event 
1229 {
1230 public:
1231   typedef double TResult;
1232   TResult myResult;
1233   QString mySection;
1234   QString myName;
1235   TResult myDefault;
1236   TGetDblSettingEvent( const QString& section, const QString& name, const double def ) 
1237     : mySection( section ), myName( name ), myDefault( def ) {}
1238   virtual void Execute() 
1239   {
1240     if ( SUIT_Session::session() ) {
1241       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1242       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1243     }
1244   }
1245 };
1246 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1247 {
1248   return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1249 }
1250
1251 /*!
1252   \fn bool SalomePyQt::boolSetting( const QString& section, 
1253                                     const QString& name, 
1254                                     const bool def );
1255   \brief Get boolean setting from the application preferences.
1256   \param section resources file section name 
1257   \param name setting name
1258   \param def default value which is returned if the setting is not found
1259   \return setting value
1260 */
1261
1262 class TGetBoolSettingEvent: public SALOME_Event 
1263 {
1264 public:
1265   typedef bool TResult;
1266   TResult myResult;
1267   QString mySection;
1268   QString myName;
1269   TResult myDefault;
1270   TGetBoolSettingEvent( const QString& section, const QString& name, const bool def ) 
1271     : mySection( section ), myName( name ), myDefault( def ) {}
1272   virtual void Execute() 
1273   {
1274     if ( SUIT_Session::session() ) {
1275       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1276       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1277     }
1278   }
1279 };
1280 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1281 {
1282   return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1283 }
1284
1285 /*!
1286   \fn QString SalomePyQt::stringSetting( const QString& section, 
1287                                          const QString& name, 
1288                                          const QString& def );
1289   \brief Get string setting from the application preferences.
1290   \param section resources file section name 
1291   \param name setting name
1292   \param def default value which is returned if the setting is not found
1293   \return setting value
1294 */
1295
1296 class TGetStrSettingEvent: public SALOME_Event
1297 {
1298 public:
1299   typedef QString TResult;
1300   TResult myResult;
1301   QString mySection;
1302   QString myName;
1303   TResult myDefault;
1304   TGetStrSettingEvent( const QString& section, const QString& name, const QString& def ) 
1305     : mySection( section ), myName( name ), myDefault( def ) {}
1306   virtual void Execute() 
1307   {
1308     if ( SUIT_Session::session() ) {
1309       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1310       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1311     }
1312   }
1313 };
1314 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1315 {
1316   return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1317 }
1318
1319 /*!
1320   \fn QColor SalomePyQt::colorSetting( const QString& section, 
1321                                        const QString& name, 
1322                                        const QColor def );
1323   \brief Get color setting from the application preferences.
1324   \param section resources file section name 
1325   \param name setting name
1326   \param def default value which is returned if the setting is not found
1327   \return setting value
1328 */
1329
1330 class TGetColorSettingEvent: public SALOME_Event 
1331 {
1332 public:
1333   typedef QColor TResult;
1334   TResult myResult;
1335   QString mySection;
1336   QString myName;
1337   TResult myDefault;
1338   TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def ) 
1339     : mySection( section ), myName( name ), myDefault( def ) {}
1340   virtual void Execute() 
1341   {
1342     if ( SUIT_Session::session() ) {
1343       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1344       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1345     }
1346   }
1347 };
1348 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1349 {
1350   return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1351 }
1352
1353 /*!
1354   \fn QByteArray SalomePyQt::byteArraySetting( const QString& section, 
1355                                                const QString& name, 
1356                                                const QByteArray def );
1357   \brief Get byte array setting from the application preferences.
1358   \param section resources file section name 
1359   \param name setting name
1360   \param def default value which is returned if the setting is not found
1361   \return setting value
1362 */
1363
1364 class TGetByteArraySettingEvent: public SALOME_Event 
1365 {
1366 public:
1367   typedef QByteArray TResult;
1368   TResult myResult;
1369   QString mySection;
1370   QString myName;
1371   TResult myDefault;
1372   TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def ) 
1373     : mySection( section ), myName( name ), myDefault( def ) {}
1374   virtual void Execute() 
1375   {
1376     if ( SUIT_Session::session() ) {
1377       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1378       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1379     }
1380   }
1381 };
1382 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1383 {
1384   return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1385 }
1386
1387 /*!
1388   \brief Remove setting from the application preferences.
1389   \param section resources file section name 
1390   \param name setting name
1391 */
1392 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1393 {
1394   class TEvent: public SALOME_Event 
1395   {
1396     QString mySection;
1397     QString myName;
1398   public:
1399     TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1400     virtual void Execute() 
1401     {
1402       if ( SUIT_Session::session() ) {
1403         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1404         if ( !mySection.isEmpty() && !myName.isEmpty() )
1405           resMgr->remove( mySection, myName );
1406       }
1407     }
1408   };
1409   ProcessVoidEvent( new TEvent( section, name ) );
1410 }
1411
1412 /*!
1413   \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1414   \brief Check setting existence in the application preferences.
1415   \param section resources file section name 
1416   \param name setting name
1417   \return \c true if setting exists
1418 */
1419
1420 class THasSettingEvent: public SALOME_Event 
1421 {
1422 public:
1423   typedef bool TResult;
1424   TResult myResult;
1425   QString mySection;
1426   QString myName;
1427   THasSettingEvent( const QString& section, const QString& name ) 
1428     : mySection( section ), myName( name ) {}
1429   virtual void Execute() 
1430   {
1431     if ( SUIT_Session::session() ) {
1432       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1433       myResult = resMgr->hasValue( mySection, myName );
1434     }
1435   }
1436 };
1437 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1438 {
1439   return ProcessEvent( new THasSettingEvent( section, name ) );
1440 }
1441
1442 /*!
1443   \fn QString SalomePyQt::getFileName( QWidget*           parent, 
1444                                        const QString&     initial, 
1445                                        const QStringList& filters, 
1446                                        const QString&     caption,
1447                                        bool               open );
1448   \brief Show 'Open/Save file' dialog box for file selection 
1449          and return a user's choice (selected file name).
1450   \param parent parent widget
1451   \param initial initial directory the dialog box to be opened in
1452   \param filters list of files filters (wildcards)
1453   \param caption dialog box title
1454   \param open if \c true, "Open File" dialog box is shown; 
1455          otherwise "Save File" dialog box is shown
1456   \return selected file name (null string if user cancels operation)
1457 */
1458
1459 class TGetFileNameEvent: public SALOME_Event 
1460 {
1461 public:
1462   typedef QString TResult;
1463   TResult     myResult;
1464   QWidget*    myParent;
1465   QString     myInitial;
1466   QStringList myFilters;
1467   QString     myCaption;
1468   bool        myOpen;
1469   TGetFileNameEvent( QWidget*           parent, 
1470                      const QString&     initial, 
1471                      const QStringList& filters, 
1472                      const QString&     caption,
1473                      bool               open ) 
1474     : myParent ( parent ), 
1475       myInitial( initial ), 
1476       myFilters( filters ), 
1477       myCaption( caption ), 
1478       myOpen ( open ) {}
1479   virtual void Execute() 
1480   {
1481     if ( LightApp_Application* anApp = getApplication() ) {
1482       myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), 
1483                                      myCaption, myParent );
1484     }
1485   }
1486 };
1487 QString SalomePyQt::getFileName( QWidget*           parent, 
1488                                  const QString&     initial, 
1489                                  const QStringList& filters, 
1490                                  const QString&     caption,
1491                                  bool               open )
1492 {
1493   return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1494 }
1495
1496 /*!
1497   \fn QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
1498                                                 const QString&     initial, 
1499                                                 const QStringList& filters, 
1500                                                 const QString&     caption );
1501   \brief Show 'Open files' dialog box for multiple files selection
1502          and return a user's choice (selected file names list).
1503   \param parent parent widget
1504   \param initial initial directory the dialog box to be opened in
1505   \param filters list of files filters (wildcards)
1506   \param caption dialog box title
1507   \return selected file names list (empty list if user cancels operation)
1508 */
1509
1510 class TGetOpenFileNamesEvent: public SALOME_Event 
1511 {
1512 public:
1513   typedef QStringList TResult;
1514   TResult     myResult;
1515   QWidget*    myParent;
1516   QString     myInitial;
1517   QStringList myFilters;
1518   QString     myCaption;
1519   TGetOpenFileNamesEvent( QWidget*           parent, 
1520                           const QString&     initial, 
1521                           const QStringList& filters, 
1522                           const QString&     caption ) 
1523     : myParent ( parent ), 
1524       myInitial( initial ), 
1525       myFilters( filters ), 
1526       myCaption( caption ) {}
1527   virtual void Execute() 
1528   {
1529     if ( LightApp_Application* anApp = getApplication() ) {
1530       myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1531     }
1532   }
1533 };
1534 QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
1535                                           const QString&     initial, 
1536                                           const QStringList& filters, 
1537                                           const QString&     caption )
1538 {
1539   return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1540 }
1541
1542 /*!
1543   \fn QString SalomePyQt::getExistingDirectory( QWidget*       parent,
1544                                                 const QString& initial,
1545                                                 const QString& caption );
1546   \brief Show 'Get Directory' dialog box for the directory selection
1547          and return a user's choice (selected directory name).
1548   \param parent parent widget
1549   \param initial initial directory the dialog box to be opened in
1550   \param caption dialog box title
1551   \return selected directory name (null string if user cancels operation)
1552 */
1553
1554 class TGetExistingDirectoryEvent: public SALOME_Event 
1555 {
1556 public:
1557   typedef QString TResult;
1558   TResult     myResult;
1559   QWidget*    myParent;
1560   QString     myInitial;
1561   QString     myCaption;
1562   TGetExistingDirectoryEvent( QWidget*           parent, 
1563                               const QString&     initial, 
1564                               const QString&     caption ) 
1565     : myParent ( parent ), 
1566       myInitial( initial ), 
1567       myCaption( caption ) {}
1568   virtual void Execute() 
1569   {
1570     if ( LightApp_Application* anApp = getApplication() ) {
1571       myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1572     }
1573   }
1574 };
1575 QString SalomePyQt::getExistingDirectory( QWidget*       parent,
1576                                           const QString& initial,
1577                                           const QString& caption )
1578 {
1579   return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1580 }
1581
1582 /*!
1583   \fn QString SalomePyQt::loadIcon( const QString& filename );
1584   \brief Load an icon from the module resources by the specified file name.
1585   \param fileName icon file name
1586   \return icon object
1587 */
1588
1589 class TLoadIconEvent: public SALOME_Event 
1590 {
1591 public:
1592   typedef QIcon TResult;
1593   TResult     myResult;
1594   QString     myModule;
1595   QString     myFileName;
1596   TLoadIconEvent( const QString& module, const QString& filename ) 
1597     : myModule( module ), 
1598       myFileName ( filename ) {}
1599   virtual void Execute() 
1600   {
1601     myResult = loadIconInternal( myModule, myFileName );
1602   }
1603 };
1604 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1605 {
1606   return ProcessEvent( new TLoadIconEvent( module, filename ) );
1607 }
1608
1609 /*!
1610   \brief Open external browser to display context help information.
1611   \todo
1612
1613   Current implementation does nothing.
1614
1615   \param source documentation (HTML) file name
1616   \param context context (for example, HTML ancor name)
1617 */
1618 void SalomePyQt::helpContext( const QString& source, const QString& context ) 
1619 {
1620   class TEvent: public SALOME_Event 
1621   {
1622     QString mySource;
1623     QString myContext;
1624   public:
1625     TEvent( const QString& source, const QString& context ) 
1626       : mySource( source ), myContext( context ) {}
1627     virtual void Execute() 
1628     {
1629       if ( LightApp_Application* anApp = getApplication() ) {
1630         anApp->onHelpContextModule( "", mySource, myContext );
1631       }
1632     }
1633   };
1634   ProcessVoidEvent( new TEvent( source, context ) );
1635 }
1636
1637 /*!
1638   \fn int SalomePyQt::defaultMenuGroup();
1639   \brief Get detault menu group identifier which can be used when 
1640   creating menus (insert custom menu commands).
1641   \return default menu group ID
1642 */
1643
1644 class TDefMenuGroupEvent: public SALOME_Event 
1645 {
1646 public:
1647   typedef int TResult;
1648   TResult myResult;
1649   TDefMenuGroupEvent() : myResult( -1 ) {}
1650   virtual void Execute() 
1651   {
1652     myResult = PyModuleHelper::defaultMenuGroup();
1653   }
1654 };
1655 int SalomePyQt::defaultMenuGroup()
1656 {
1657   return ProcessEvent( new TDefMenuGroupEvent() );
1658 }
1659
1660 class CrTool
1661 {
1662 public:
1663   CrTool( const QString& tBar, const QString& nBar ) 
1664     : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar)  {}
1665   CrTool( const int id, const int tBar, const int idx ) 
1666     : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1667   CrTool( const int id, const QString& tBar, const int idx )
1668     : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1669   CrTool( QAction* action, const int tbId, const int id, const int idx )
1670     : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1671   CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1672     : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1673
1674   int execute( LightApp_Module* module ) const
1675   {
1676     if ( module ) {
1677       switch ( myCase ) {
1678       case 0:
1679         return module->createTool( myTbTitle, myTbName );
1680       case 1:
1681         return module->createTool( myId, myTbId, myIndex );
1682       case 2:
1683         return module->createTool( myId, myTbTitle, myIndex );
1684       case 3:
1685         return module->createTool( myAction, myTbId, myId, myIndex );
1686       case 4:
1687         return module->createTool( myAction, myTbTitle, myId, myIndex );
1688       }
1689     }
1690     return -1;
1691   }
1692 private:
1693    int        myCase;
1694    QString    myTbTitle;
1695    QString    myTbName;
1696    int        myTbId;
1697    QAction*   myAction;
1698    int        myId;
1699    int        myIndex;
1700 };
1701
1702 class TCreateToolEvent: public SALOME_Event 
1703 {
1704 public:
1705   typedef int TResult;
1706   TResult myResult;
1707   const CrTool& myCrTool;
1708   TCreateToolEvent( const CrTool& crTool ) 
1709     : myResult( -1 ), myCrTool( crTool ) {}
1710   virtual void Execute() 
1711   {
1712     LightApp_Module* module = getActiveModule();
1713     if ( module )
1714       myResult = myCrTool.execute( module );
1715   }
1716 };
1717
1718 /*!
1719   \brief Create toolbar with specified name.
1720   \param tBar toolbar title (language-dependent)
1721   \param nBar toolbar name (language-independent) [optional]
1722   \return toolbar ID or -1 if toolbar creation is failed
1723 */
1724 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1725 {
1726   return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1727 }
1728
1729 /*! 
1730   \brief Insert action with specified \a id to the toolbar.
1731   \param id action ID
1732   \param tBar toolbar ID
1733   \param idx required index in the toolbar
1734   \return action ID or -1 if action could not be added
1735 */
1736 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1737 {
1738   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1739 }
1740
1741 /*!
1742   \brief Insert action with specified \a id to the toolbar.
1743   \param id action ID
1744   \param tBar toolbar name
1745   \param idx required index in the toolbar
1746   \return action ID or -1 if action could not be added
1747 */
1748 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1749 {
1750   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1751 }
1752
1753 /*!
1754   \brief Insert action to the toolbar.
1755   \param a action
1756   \param tBar toolbar ID
1757   \param id required action ID
1758   \param idx required index in the toolbar
1759   \return action ID or -1 if action could not be added
1760 */
1761 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1762 {
1763   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1764 }
1765
1766 /*!
1767   \brief Insert action to the toolbar.
1768   \param a action
1769   \param tBar toolbar name
1770   \param id required action ID
1771   \param idx required index in the toolbar
1772   \return action ID or -1 if action could not be added
1773 */
1774 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1775 {
1776   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1777 }
1778
1779 class CrMenu
1780 {
1781 public:
1782   CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) 
1783     : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1784   CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) 
1785     : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1786   CrMenu( const int id, const int menu, const int group, const int idx ) 
1787     : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1788   CrMenu( const int id, const QString& menu, const int group, const int idx ) 
1789     : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1790   CrMenu( QAction* action, const int menu, const int id, const int group, const int idx ) 
1791     : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1792   CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) 
1793     : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1794
1795   int execute( LightApp_Module* module ) const
1796   {
1797     if ( module ) {
1798       switch ( myCase ) {
1799       case 0:
1800         return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1801       case 1:
1802         return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1803       case 2:
1804         return module->createMenu( myId, myMenuId, myGroup, myIndex );
1805       case 3:
1806         return module->createMenu( myId, myMenuName, myGroup, myIndex );
1807       case 4:
1808         return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1809       case 5:
1810         return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1811       }
1812     }
1813     return -1;
1814   }
1815 private:
1816    int        myCase;
1817    QString    myMenuName;
1818    int        myMenuId;
1819    QString    mySubMenuName;
1820    int        myGroup;
1821    QAction*   myAction;
1822    int        myId;
1823    int        myIndex;
1824 };
1825
1826 class TCreateMenuEvent: public SALOME_Event
1827 {
1828 public:
1829   typedef int TResult;
1830   TResult myResult;
1831   const CrMenu& myCrMenu;
1832   TCreateMenuEvent( const CrMenu& crMenu ) 
1833     : myResult( -1 ), myCrMenu( crMenu ) {}
1834   virtual void Execute()
1835   {
1836     LightApp_Module* module = getActiveModule();
1837     if ( module )
1838       myResult = myCrMenu.execute( module );
1839   }
1840 };
1841
1842 /*!
1843   \brief Create main menu.
1844   \param subMenu menu name
1845   \param menu parent menu ID
1846   \param id required menu ID
1847   \param group menu group ID
1848   \param idx required index in the menu
1849   \return menu ID or -1 if menu could not be added
1850 */
1851 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1852 {
1853   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1854 }
1855
1856 /*!
1857   \brief Create main menu.
1858   \param subMenu menu name
1859   \param menu parent menu name (list of menu names separated by "|")
1860   \param id required menu ID
1861   \param group menu group ID
1862   \param idx required index in the menu
1863   \return menu ID or -1 if menu could not be added
1864 */
1865 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1866 {
1867   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1868 }
1869
1870 /*!
1871   \brief Insert action to the main menu.
1872   \param id action ID
1873   \param menu parent menu ID
1874   \param group menu group ID
1875   \param idx required index in the menu
1876   \return action ID or -1 if action could not be added
1877 */
1878 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1879 {
1880   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1881 }
1882
1883 /*!
1884   \brief Insert action to the main menu.
1885   \param id action ID
1886   \param menu parent menu name (list of menu names separated by "|")
1887   \param group menu group ID
1888   \param idx required index in the menu
1889   \return action ID or -1 if action could not be added
1890 */
1891 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1892 {
1893   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1894 }
1895
1896 /*!
1897   \brief Insert action to the main menu.
1898   \param a action
1899   \param menu parent menu ID
1900   \param group menu group ID
1901   \param idx required index in the menu
1902   \return action ID or -1 if action could not be added
1903 */
1904 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1905 {
1906   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1907 }
1908
1909 /*!
1910   \brief Insert action to the main menu.
1911   \param a action
1912   \param menu parent menu name (list of menu names separated by "|")
1913   \param group menu group ID
1914   \param idx required index in the menu
1915   \return action ID or -1 if action could not be added
1916 */
1917 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1918 {
1919   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1920 }
1921
1922 /*!
1923   \fn QAction* SalomePyQt::createSeparator();
1924   \brief Create separator action which can be used in the menu or toolbar.
1925   \return new separator action
1926 */
1927
1928 class TCreateSepEvent: public SALOME_Event 
1929 {
1930 public:
1931   typedef QAction* TResult;
1932   TResult myResult;
1933   TCreateSepEvent() 
1934     : myResult( 0 ) {}
1935   virtual void Execute() 
1936   {
1937     LightApp_Module* module = getActiveModule();
1938     if ( module )
1939       myResult = (QAction*)module->separator();
1940   }
1941 };
1942 QAction* SalomePyQt::createSeparator()
1943 {
1944   return ProcessEvent( new TCreateSepEvent() );
1945 }
1946
1947 /*!
1948   \fn QAction* SalomePyQt::createAction( const int      id,
1949                                          const QString& menuText, 
1950                                          const QString& tipText, 
1951                                          const QString& statusText, 
1952                                          const QString& icon,
1953                                          const int      key, 
1954                                          const bool     toggle );
1955   \brief Create an action which can be then used in the menu or toolbar.
1956   \param id the unique id action to be registered to
1957   \param menuText action text which should appear in menu
1958   \param tipText text which should appear in the tooltip
1959   \param statusText text which should appear in the status bar when action is activated
1960   \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1961   \param key the key accelrator for the action
1962   \param toggle if \c true the action is checkable
1963 */
1964
1965 class TCreateActionEvent: public SALOME_Event 
1966 {
1967 public:
1968   typedef QAction* TResult;
1969   TResult myResult;
1970   int     myId;
1971   QString myMenuText;
1972   QString myTipText;
1973   QString myStatusText;
1974   QString myIcon;
1975   int     myKey;
1976   bool    myToggle;
1977   TCreateActionEvent( const int id, const QString& menuText, const QString& tipText, 
1978                       const QString& statusText, const QString& icon, const int key, const bool toggle ) 
1979     : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1980       myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1981   virtual void Execute()
1982   {
1983     LightApp_Module* module = getActiveModule();
1984     if ( module ) {
1985       QIcon icon = loadIconInternal( module->name(), myIcon );
1986       myResult = (QAction*)module->action( myId );
1987       if ( myResult ) {
1988         if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() ) 
1989           myResult->setToolTip( myTipText );
1990         if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1991           myResult->setText( myMenuText );
1992         if ( myResult->icon().isNull() && !icon.isNull() ) 
1993           myResult->setIcon( icon );
1994         if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1995           myResult->setStatusTip( myStatusText );
1996         if ( myResult->shortcut().isEmpty() && myKey )
1997           myResult->setShortcut( myKey );
1998         if ( myResult->isCheckable() != myToggle )
1999           myResult->setCheckable( myToggle );
2000       }
2001       else {
2002         myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2003       }
2004       // for Python module, automatically connect action to callback slot
2005       PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2006       if ( helper ) helper->connectAction( myResult );
2007     }
2008   }
2009 };
2010 QAction* SalomePyQt::createAction( const int id,           const QString& menuText, 
2011                                    const QString& tipText, const QString& statusText, 
2012                                    const QString& icon,    const int key, const bool toggle )
2013 {
2014   return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2015 }
2016
2017 /*!
2018   \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2019   \brief Create an action group which can be then used in the menu or toolbar
2020   \param id         : the unique id action group to be registered to
2021   \param exclusive  : if \c true the action group does exclusive toggling
2022 */
2023
2024 struct TCreateActionGroupEvent: public SALOME_Event 
2025 {
2026   typedef QtxActionGroup* TResult;
2027   TResult myResult;
2028   int     myId;
2029   bool    myExclusive;
2030   TCreateActionGroupEvent( const int id, const bool exclusive )
2031     : myId( id ), myExclusive( exclusive ) {}
2032   virtual void Execute()
2033   {
2034     LightApp_Module* module = getActiveModule();
2035     if ( module )
2036       myResult = module->createActionGroup( myId, myExclusive );
2037   }
2038 };
2039 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2040 {
2041   return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2042 }
2043
2044 /*!
2045   \fn QAction* SalomePyQt::action( const int id );
2046   \brief Get action by specified identifier.
2047   \return action or 0 if action is not registered
2048 */
2049
2050 class TActionEvent: public SALOME_Event 
2051 {
2052 public:
2053   typedef QAction* TResult;
2054   TResult myResult;
2055   int     myId;
2056   TActionEvent( const int id )
2057     : myResult( 0 ), myId( id ) {}
2058   virtual void Execute()
2059   {
2060     LightApp_Module* module = getActiveModule();
2061     if ( module )
2062       myResult = (QAction*)module->action( myId );
2063   }
2064 };
2065 QAction* SalomePyQt::action( const int id )
2066 {
2067   return ProcessEvent( new TActionEvent( id ) );
2068 }
2069
2070 /*!
2071   \fn int SalomePyQt::actionId( const QAction* a );
2072   \brief Get an action identifier. 
2073   \return action ID or -1 if action is not registered
2074 */
2075
2076 class TActionIdEvent: public SALOME_Event 
2077 {
2078 public:
2079   typedef  int TResult;
2080   TResult  myResult;
2081   const QAction* myAction;
2082   TActionIdEvent( const QAction* action )
2083     : myResult( -1 ), myAction( action ) {}
2084   virtual void Execute()
2085   {
2086     LightApp_Module* module = getActiveModule();
2087     if ( module )
2088       myResult = module->actionId( myAction );
2089   }
2090 };
2091 int SalomePyQt::actionId( const QAction* a )
2092 {
2093   return ProcessEvent( new TActionIdEvent( a ) );
2094 }
2095
2096 /*!
2097   \fn int SalomePyQt::addGlobalPreference( const QString& label );
2098   \brief Add global (not module-related) preferences group.
2099   \param label global preferences group name
2100   \return preferences group identifier
2101 */
2102
2103 class TAddGlobalPrefEvent: public SALOME_Event
2104 {
2105 public:
2106   typedef int TResult;
2107   TResult myResult;
2108   QString myLabel;
2109   TAddGlobalPrefEvent( const QString& label )
2110     : myResult( -1 ), myLabel( label ) {}
2111   virtual void Execute() 
2112   {
2113     LightApp_Module* module = getActiveModule();
2114     if ( module ) {
2115       LightApp_Preferences* pref = module->getApp()->preferences();
2116       if ( pref )
2117         myResult = pref->addPreference( myLabel, -1 );
2118     }
2119   }
2120 };
2121 int SalomePyQt::addGlobalPreference( const QString& label )
2122 {
2123   return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2124 }
2125
2126 /*!
2127   \fn int SalomePyQt::addPreference( const QString& label );
2128   \brief Add module-related preferences group.
2129   \param label preferences group name
2130   \return preferences group identifier
2131 */
2132
2133 class TAddPrefEvent: public SALOME_Event 
2134 {
2135 public:
2136   typedef int TResult;
2137   TResult myResult;
2138   QString myLabel;
2139   TAddPrefEvent( const QString& label )
2140     : myResult( -1 ), myLabel( label ) {}
2141   virtual void Execute() 
2142   {
2143     LightApp_Module* module = getActiveModule();
2144     if ( module ) {
2145       LightApp_Preferences* pref = module->getApp()->preferences();
2146       if ( pref ) {
2147         int cId = pref->addPreference( module->moduleName(), -1 );
2148         if ( cId != -1 )
2149           myResult = pref->addPreference( myLabel, cId );
2150       }
2151     }
2152   }
2153 };
2154 int SalomePyQt::addPreference( const QString& label )
2155 {
2156   return ProcessEvent( new TAddPrefEvent( label ) );
2157 }
2158
2159 /*!
2160   \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2161                                      const QString& section, const QString& param );
2162   \brief Add module-related preferences.
2163   \param label preferences group name
2164   \param pId parent preferences group id
2165   \param type preferences type
2166   \param section resources file section name
2167   \param param resources file setting name
2168   \return preferences identifier
2169 */
2170
2171 class TAddPrefParamEvent: public SALOME_Event
2172 {
2173 public:
2174   typedef int TResult;
2175   TResult myResult;
2176   QString myLabel;
2177   int     myPId;
2178   int     myType;
2179   QString mySection;
2180   QString myParam;
2181   TAddPrefParamEvent( const QString& label, 
2182                       const int pId, const int type,
2183                       const QString& section, 
2184                       const QString& param )
2185     : myResult( -1 ),
2186       myLabel( label ), myPId( pId ), myType( type ), 
2187       mySection( section ), myParam ( param ) {}
2188   virtual void Execute()
2189   {
2190     LightApp_Module* module = getActiveModule();
2191     if ( module ) {
2192       LightApp_Preferences* pref = module->getApp()->preferences();
2193       if ( pref )
2194         myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2195     }
2196   }
2197 };
2198 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2199                                const QString& section, const QString& param )
2200 {
2201   return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2202 }
2203
2204 /*!
2205   \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2206   \brief Get the preferences property.
2207   \param id preferences identifier
2208   \param prop preferences property name
2209   \return preferences property value or null QVariant if property is not set
2210 */
2211
2212 class TPrefPropEvent: public SALOME_Event
2213 {
2214 public:
2215   typedef QVariant TResult;
2216   TResult myResult;
2217   int     myId;
2218   QString myProp;
2219   TPrefPropEvent( const int id, const QString& prop )
2220     : myId( id ), myProp( prop ) {}
2221   virtual void Execute()
2222   {
2223     LightApp_Module* module = getActiveModule();
2224     if ( module ) {
2225       LightApp_Preferences* pref = module->getApp()->preferences();
2226       if ( pref )
2227         myResult = pref->itemProperty( myProp, myId );
2228     }
2229   }
2230 };
2231 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2232 {
2233   return ProcessEvent( new TPrefPropEvent( id, prop ) );
2234 }
2235
2236 /*!
2237   \brief Set the preferences property.
2238   \param id preferences identifier
2239   \param prop preferences property name
2240   \param var preferences property value
2241 */
2242 void SalomePyQt::setPreferenceProperty( const int id, 
2243                                         const QString& prop,
2244                                         const QVariant& var )
2245 {
2246   class TEvent: public SALOME_Event
2247   {
2248     int      myId;
2249     QString  myProp;
2250     QVariant myVar;
2251   public:
2252     TEvent( const int id, const QString& prop, const QVariant& var ) 
2253       : myId( id ), myProp( prop ), myVar( var ) {}
2254     virtual void Execute() 
2255     {
2256       LightApp_Module* module = getActiveModule();
2257       if ( module ) {
2258         LightApp_Preferences* pref = module->getApp()->preferences();
2259         if ( pref )
2260           pref->setItemProperty( myProp, myVar, myId );
2261       }
2262     }
2263   };
2264   ProcessVoidEvent( new TEvent( id, prop, var) );
2265 }
2266
2267 /*!
2268   \brief Add the property value to the list of values.
2269
2270   This method allows creating properties which are QList<QVariant>
2271   - there is no way to pass such values directly to QVariant parameter with PyQt.
2272
2273   \param id preferences identifier
2274   \param prop preferences property name
2275   \param idx preferences property index
2276   \param var preferences property value for the index \a idx
2277 */
2278 void SalomePyQt::addPreferenceProperty( const int id, 
2279                                         const QString& prop,
2280                                         const int idx, 
2281                                         const QVariant& var )
2282 {
2283   class TEvent: public SALOME_Event
2284   {
2285     int      myId;
2286     QString  myProp;
2287     int      myIdx;
2288     QVariant myVar;
2289   public:
2290     TEvent( const int id, const QString& prop, const int idx, const QVariant& var ) 
2291       : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2292     virtual void Execute()
2293     {
2294       LightApp_Module* module = getActiveModule();
2295       if ( module ) {
2296         LightApp_Preferences* pref = module->getApp()->preferences();
2297         if ( pref ) {
2298           QVariant var =  pref->itemProperty( myProp, myId );
2299           if ( var.isValid() ) {
2300             if ( var.type() == QVariant::StringList ) {
2301               QStringList sl = var.toStringList();
2302               if ( myIdx >= 0 && myIdx < sl.count() ) 
2303                 sl[myIdx] = myVar.toString();
2304               else
2305                 sl.append( myVar.toString() );
2306               pref->setItemProperty( myProp, sl, myId );
2307             }
2308             else if ( var.type() == QVariant::List ) {
2309               QList<QVariant> vl = var.toList();
2310               if ( myIdx >= 0 && myIdx < vl.count() ) 
2311                 vl[myIdx] = myVar;
2312               else
2313                 vl.append( myVar );
2314               pref->setItemProperty( myProp, vl, myId );
2315             }
2316           }
2317           else {
2318             QList<QVariant> vl;
2319             vl.append( myVar );
2320             pref->setItemProperty( myProp, vl, myId );
2321           }
2322         }
2323       }
2324     }
2325   };
2326   ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2327 }
2328
2329 /*!
2330   \brief Put the message to the Log messages output window
2331   \param msg message text (it can be of simple rich text format)
2332   \param addSeparator boolean flag which specifies if it is necessary 
2333          to separate the message with predefined separator
2334 */
2335 void SalomePyQt::message( const QString& msg, bool addSeparator )
2336 {
2337   class TEvent: public SALOME_Event
2338   {
2339     QString  myMsg;
2340     bool     myAddSep;
2341   public:
2342     TEvent( const QString& msg, bool addSeparator ) 
2343       : myMsg( msg ), myAddSep( addSeparator ) {}
2344     virtual void Execute()
2345     {
2346       if ( LightApp_Application* anApp = getApplication() ) {
2347         LogWindow* lw = anApp->logWindow();
2348         if ( lw )
2349           lw->putMessage( myMsg, myAddSep );
2350       }
2351     }
2352   };
2353   ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2354 }
2355
2356 /*!
2357   \brief Remove all the messages from the Log messages output window.
2358 */
2359 void SalomePyQt::clearMessages()
2360 {
2361   class TEvent: public SALOME_Event
2362   {
2363   public:
2364     TEvent() {}
2365     virtual void Execute()
2366     {
2367       if ( LightApp_Application* anApp = getApplication() ) {
2368         LogWindow* lw = anApp->logWindow();
2369         if ( lw )
2370           lw->clear();
2371       }
2372     }
2373   };
2374   ProcessVoidEvent( new TEvent() );
2375 }
2376
2377 /*!
2378   \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2379   \brief Dump the contents of the id view window. If id is 0 then current active view is processed. 
2380   to the image file in the specified format.
2381
2382   For the current moment JPEG, PNG and BMP images formats are supported.
2383   The image format is defined automatically by the file name extension.
2384   By default, BMP format is used.
2385
2386   \param filename image file name
2387   \return operation status (\c true on success)
2388 */
2389
2390 class TDumpViewEvent: public SALOME_Event 
2391 {
2392 public:
2393   typedef bool TResult;
2394   TResult myResult;
2395   QString myFileName;
2396   int myWndId;
2397   TDumpViewEvent( const QString& filename, const int id ) 
2398     : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2399   virtual void Execute() 
2400   {
2401     SUIT_ViewWindow* wnd = 0;
2402     if ( !myWndId ) {
2403       if ( LightApp_Application* anApp = getApplication() ) {
2404         SUIT_ViewManager* vm = anApp->activeViewManager();
2405         if ( vm )
2406           wnd = vm->getActiveView();
2407       }
2408       myWndId = wnd->getId();
2409     }
2410     else {
2411       wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2412     }
2413     if ( wnd ) {
2414       QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2415 #ifndef DISABLE_PLOT2DVIEWER
2416       Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2417       if ( wnd2D ) {
2418         qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2419         qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2420         qApp->processEvents();
2421         if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2422           myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2423           return;
2424         }
2425       }
2426 #endif // DISABLE_PLOT2DVIEWER
2427       QImage im = wnd->dumpView();
2428       if ( !im.isNull() && !myFileName.isEmpty() ) {
2429         if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2430         if ( fmt == "JPG" )  fmt = "JPEG";
2431         myResult = im.save( myFileName, fmt.toLatin1() );
2432       }
2433     }
2434   }
2435 };
2436 bool SalomePyQt::dumpView( const QString& filename, const int id )
2437 {
2438   return ProcessEvent( new TDumpViewEvent( filename, id ) );
2439 }
2440
2441 /*!
2442   \fn QList<int> SalomePyQt::getViews();
2443   \brief Get list of integer identifiers of all the currently opened views
2444   \return list of integer identifiers of all the currently opened views
2445 */
2446
2447 class TGetViews: public SALOME_Event
2448 {
2449 public:
2450   typedef QList<int> TResult;
2451   TResult myResult;
2452   TGetViews() {}
2453   virtual void Execute() 
2454   {
2455     myResult.clear();
2456     LightApp_Application* app  = getApplication();
2457     if ( app ) {
2458       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2459       if ( tabDesk ) {
2460         QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2461         SUIT_ViewWindow* wnd;
2462         foreach ( wnd, wndlist )
2463           myResult.append( wnd->getId() );
2464       }
2465     }
2466   }
2467 };
2468 QList<int> SalomePyQt::getViews()
2469 {
2470   return ProcessEvent( new TGetViews() );
2471 }
2472
2473 /*!
2474   \fn int SalomePyQt::getActiveView();
2475   \brief Get integer identifier of the currently active view
2476   \return integer identifier of the currently active view
2477 */
2478
2479 class TGetActiveView: public SALOME_Event
2480 {
2481 public:
2482   typedef int TResult;
2483   TResult myResult;
2484   TGetActiveView()
2485     : myResult( -1 ) {}
2486   virtual void Execute() 
2487   {
2488     LightApp_Application* app = getApplication();
2489     if ( app ) {
2490       SUIT_ViewManager* viewMgr = app->activeViewManager();
2491       if ( viewMgr ) {
2492         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2493         if ( wnd )
2494           myResult = wnd->getId();
2495       }
2496     }
2497   }
2498 };
2499 int SalomePyQt::getActiveView()
2500 {
2501   return ProcessEvent( new TGetActiveView() );
2502 }
2503
2504 /*!                      
2505   \fn QString SalomePyQt::getViewType( const int id );
2506   \brief Get type of the specified view, e.g. "OCCViewer"
2507   \param id window identifier
2508   \return view type
2509 */ 
2510
2511 class TGetViewType: public SALOME_Event
2512 {
2513 public:
2514   typedef QString TResult;
2515   TResult myResult;
2516   int myWndId;
2517   TGetViewType( const int id )
2518     : myWndId( id ) {}
2519   virtual void Execute() 
2520   {
2521     SUIT_ViewWindow* wnd = getWnd( myWndId );
2522     if ( wnd ) {
2523       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2524       if ( viewMgr )
2525         myResult = viewMgr->getType();
2526     }
2527   }
2528 };
2529 QString SalomePyQt::getViewType( const int id )
2530 {
2531   return ProcessEvent( new TGetViewType( id ) );
2532 }
2533
2534 /*!
2535   \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2536   \brief Change view caption  
2537   \param id window identifier
2538   \param title new window title
2539   \return \c true if operation is completed successfully and \c false otherwise 
2540 */
2541
2542 class TSetViewTitle: public SALOME_Event
2543 {
2544 public:
2545   typedef bool TResult;
2546   TResult myResult;
2547   int myWndId;
2548   QString myTitle;
2549   TSetViewTitle( const int id, const QString& title )
2550     : myResult( false ),
2551       myWndId( id ),
2552       myTitle( title ) {}
2553   virtual void Execute() 
2554   {
2555     SUIT_ViewWindow* wnd = getWnd( myWndId );
2556     if ( wnd ) {
2557       wnd->setWindowTitle( myTitle );
2558       myResult = true;
2559     }
2560   }
2561 };
2562 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2563 {
2564   return ProcessEvent( new TSetViewTitle( id, title ) );
2565 }
2566
2567 /*!
2568   \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2569   \brief Set view size
2570   \param w window width
2571   \param h window height
2572   \param id window identifier
2573   \return \c true if operation is completed successfully and \c false otherwise 
2574 */
2575
2576 class TSetViewSize: public SALOME_Event
2577 {
2578 public:
2579   typedef bool TResult;
2580   TResult myResult;
2581   int myWndWidth;
2582   int myWndHeight;
2583   int myWndId;
2584   TSetViewSize( const int w, const int h, const int id )
2585     : myResult( false ),
2586       myWndWidth( w ),
2587       myWndHeight( h ),
2588       myWndId( id ) {}
2589   virtual void Execute() 
2590   {
2591     SUIT_ViewWindow* wnd = 0;
2592     if ( !myWndId ) {
2593       if ( LightApp_Application* anApp = getApplication() ) {
2594         SUIT_ViewManager* vm = anApp->activeViewManager();
2595         if ( vm )
2596           wnd = vm->getActiveView();
2597       }
2598     }
2599     else {
2600       wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2601     }
2602     if ( wnd ) {
2603       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2604       if ( viewMgr ) {
2605         QString type = viewMgr->getType();
2606         if ( type == "OCCViewer") {
2607 #ifndef DISABLE_OCCVIEWER
2608           // specific processing for OCC viewer:
2609           // OCC view can embed up to 4 sub-views, split according to the specified layout;
2610           // - if there is only one sub-view active; it will be resized;
2611           // - if there are several sub-views, each of them will be resized.
2612           OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2613           for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2614             if ( occView && occView->getView( i ) ) {
2615               occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2616               myResult = true;
2617             }
2618           }
2619 #endif // DISABLE_OCCVIEWER
2620         }
2621         else if ( type == "ParaView") {
2622 #ifndef DISABLE_PVVIEWER
2623           // specific processing for ParaView viewer:
2624           // hierarchy of ParaView viewer is much complex than for usual view;
2625           // we look for sub-widget named "Viewport"
2626           QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2627           if ( !lst.isEmpty() ) {
2628             lst[0]->resize( myWndWidth, myWndHeight );
2629             myResult = true;
2630           }
2631 #endif // DISABLE_PVVIEWER
2632         }
2633         else {
2634           if ( wnd->centralWidget() ) {
2635             wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2636             myResult = true;
2637           }
2638         }
2639       }
2640     }
2641   }
2642 };
2643 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2644 {
2645   return ProcessEvent( new TSetViewSize( w, h, id ) );
2646 }
2647
2648 /*!
2649   \fn QString SalomePyQt::getViewTitle( const int id );
2650   \brief Get view caption  
2651   \param id window identifier
2652   \return view caption  
2653 */
2654
2655 class TGetViewTitle: public SALOME_Event
2656 {
2657 public:
2658   typedef QString TResult;
2659   TResult myResult;
2660   int myWndId;
2661   TGetViewTitle( const int id )
2662     : myWndId( id ) {}
2663   virtual void Execute() 
2664   {
2665     SUIT_ViewWindow* wnd = getWnd( myWndId );
2666     if ( wnd )
2667       myResult = wnd->windowTitle();
2668   }
2669 };
2670 QString SalomePyQt::getViewTitle( const int id )
2671 {
2672   return ProcessEvent( new TGetViewTitle( id ) );
2673 }
2674
2675 /*!
2676   \fn QList<int> SalomePyQt::findViews( const QString& type );
2677   \brief Get list of integer identifiers of all the 
2678          currently opened views of the specified type
2679   \param type viewer type
2680   \return list of integer identifiers 
2681 */
2682
2683 class TFindViews: public SALOME_Event
2684 {
2685 public:
2686   typedef QList<int> TResult;
2687   TResult myResult;
2688   QString myType;
2689   TFindViews( const QString& type )
2690     : myType( type ) {}
2691   virtual void Execute() 
2692   {
2693     myResult.clear();
2694     LightApp_Application* app  = getApplication();
2695     if ( app ) {
2696       ViewManagerList vmList;
2697       app->viewManagers( myType, vmList );
2698       SUIT_ViewManager* viewMgr;
2699       foreach ( viewMgr, vmList ) {
2700         QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2701         for ( int i = 0, n = vec.size(); i < n; i++ ) {
2702           SUIT_ViewWindow* wnd = vec[ i ];
2703           if ( wnd )
2704             myResult.append( wnd->getId() );
2705         }
2706       }
2707     }
2708   }
2709 };
2710 QList<int> SalomePyQt::findViews( const QString& type )
2711 {
2712   return ProcessEvent( new TFindViews( type ) );
2713 }
2714
2715 /*!
2716   \fn bool SalomePyQt::activateView( const int id );
2717   \brief Activate view
2718   \param id window identifier
2719   \return \c true if operation is completed successfully and \c false otherwise 
2720 */
2721
2722 class TActivateView: public SALOME_Event
2723 {
2724 public:
2725   typedef bool TResult;
2726   TResult myResult;
2727   int myWndId;
2728   TActivateView( const int id )
2729     : myResult( false ),
2730       myWndId( id ) {}
2731   virtual void Execute() 
2732   {
2733     SUIT_ViewWindow* wnd = getWnd( myWndId );
2734     if ( wnd ) {
2735       wnd->setFocus();
2736       myResult = true;
2737     }
2738   }
2739 };
2740 bool SalomePyQt::activateView( const int id )
2741 {
2742   return ProcessEvent( new TActivateView( id ) );
2743 }
2744
2745 /*!
2746   \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2747   \brief Create new view and activate it
2748   \param type viewer type
2749   \param visible
2750   \param width
2751   \param height
2752   \return integer identifier of created view (or -1 if view could not be created)
2753 */
2754
2755 class TCreateView: public SALOME_Event
2756 {
2757 public:
2758   typedef int TResult;
2759   TResult myResult;
2760   QString myType;
2761   bool myVisible;
2762   int myWidth;
2763   int myHeight;
2764   TCreateView( const QString& theType, bool visible, const int width, const int height )
2765     : myResult( -1 ),
2766       myType( theType ),
2767       myVisible(visible),
2768       myWidth(width),
2769       myHeight(height) {}
2770   virtual void Execute() 
2771   {
2772     LightApp_Application* app  = getApplication();
2773     if ( app ) {
2774       SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2775       if ( viewMgr ) {
2776         QWidget* wnd = viewMgr->getActiveView();
2777         myResult = viewMgr->getActiveView()->getId();
2778         if ( wnd ) {
2779           if ( !myVisible )
2780             wnd->setVisible(false);
2781           if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2782             myWidth = 1024;
2783             myHeight = 768;
2784           }
2785           if (myWidth > 0 && myHeight > 0) {
2786 #ifndef DISABLE_PLOT2DVIEWER
2787             Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2788             if ( wnd2D ) wnd = wnd2D->getViewFrame();
2789 #endif // DISABLE_PLOT2DVIEWER
2790             wnd->setGeometry( 0, 0, myWidth, myHeight );
2791           }
2792         }
2793       }
2794     }
2795   }
2796 };
2797 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2798 {
2799   int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2800   QCoreApplication::processEvents();
2801   return ret;
2802 }
2803
2804 /*!
2805   \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2806   \brief Create new view with custom widget embedded and activate it
2807   \param type viewer type
2808   \param w custom widget
2809   \return integer identifier of created view (or -1 if view could not be created)
2810 */
2811
2812 class TCreateViewWg: public SALOME_Event
2813 {
2814 public:
2815   typedef int TResult;
2816   TResult myResult;
2817   QString myType;
2818   QWidget* myWidget;
2819   TCreateViewWg( const QString& theType, QWidget* w )
2820     : myResult( -1 ),
2821       myType( theType ),
2822       myWidget( w ) {}
2823   virtual void Execute() 
2824   {
2825     LightApp_Application* app  = getApplication();
2826     if ( app ) {
2827       SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2828       if ( viewMgr ) {
2829         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2830         if ( wnd )
2831           myResult = wnd->getId();
2832       }
2833     }
2834   }
2835 };
2836 int SalomePyQt::createView( const QString& type, QWidget* w )
2837 {
2838   int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2839   QCoreApplication::processEvents();
2840   return ret;
2841 }
2842
2843 /*!
2844   \fn bool SalomePyQt::closeView( const int id );
2845   \brief Close view
2846   \param id window identifier
2847   \return \c true if operation is completed successfully and \c false otherwise 
2848 */
2849
2850 class TCloseView: public SALOME_Event
2851 {
2852 public:
2853   typedef bool TResult;
2854   TResult myResult;
2855   int myWndId;
2856   TCloseView( const int id )
2857     : myResult( false ),
2858       myWndId( id ) {}
2859   virtual void Execute() 
2860   {
2861     SUIT_ViewWindow* wnd = getWnd( myWndId );
2862     if ( wnd ) {
2863       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2864       if ( viewMgr ) {
2865         wnd->close();
2866         myResult = true;
2867       }
2868     }
2869   }
2870 };
2871 bool SalomePyQt::closeView( const int id )
2872 {
2873   return ProcessEvent( new TCloseView( id ) );
2874 }
2875
2876 /*!
2877   \fn int SalomePyQt::cloneView( const int id );
2878   \brief Clone view (if this operation is supported for specified view type)
2879   \param id window identifier
2880   \return integer identifier of the cloned view or -1 or operation could not be performed
2881 */
2882
2883 class TCloneView: public SALOME_Event
2884 {
2885 public:
2886   typedef int TResult;
2887   TResult myResult;
2888   int myWndId;
2889   TCloneView( const int id )
2890     : myResult( -1 ),
2891       myWndId( id ) {}
2892   virtual void Execute() 
2893   {
2894     SUIT_ViewWindow* wnd = getWnd( myWndId );
2895     if ( wnd ) {
2896       SUIT_ViewManager* viewMgr = wnd->getViewManager();
2897       if ( viewMgr ) {
2898 #ifndef DISABLE_OCCVIEWER
2899         if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
2900           OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2901           occView->onCloneView();
2902           wnd = viewMgr->getActiveView();
2903           if ( wnd )
2904             myResult = wnd->getId();
2905         }
2906 #endif // DISABLE_OCCVIEWER
2907 #ifndef DISABLE_PLOT2DVIEWER
2908         if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
2909           Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2910           Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2911           if ( viewMgr2d && srcWnd2d ) {
2912             Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2913             myResult = resWnd->getId();
2914           }
2915         }
2916 #endif // DISABLE_OCCVIEWER
2917       }
2918     }
2919   }
2920 };
2921 int SalomePyQt::cloneView( const int id )
2922 {
2923   return ProcessEvent( new TCloneView( id ) );
2924 }
2925
2926 /*!
2927   \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2928   \brief Set view visibility.
2929   \param id window identifier
2930   \param visible new visiblity
2931 */
2932
2933 void SalomePyQt::setViewVisible( const int id, const bool visible )
2934 {
2935   class TEvent: public SALOME_Event
2936   {
2937     int myWndId;
2938     bool myVisible;
2939   public:
2940     TEvent( const int id, const bool visible )
2941       : myWndId( id ), myVisible( visible ) {}
2942     virtual void Execute()
2943     {
2944       SUIT_ViewWindow* wnd = getWnd( myWndId );
2945       if ( wnd ) wnd->setVisible( myVisible );
2946     }
2947   };
2948   ProcessVoidEvent( new TEvent( id, visible ) );
2949 }
2950
2951 /*!
2952   \fn bool SalomePyQt::isViewVisible( const int id );
2953   \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2954   \param id window identifier
2955   \return \c true if view is visible and \c false otherwise 
2956 */
2957
2958 class TIsViewVisible: public SALOME_Event
2959 {
2960 public:
2961   typedef bool TResult;
2962   TResult myResult;
2963   int myWndId;
2964   TIsViewVisible( const int id )
2965     : myResult( false ),
2966       myWndId( id ) {}
2967   virtual void Execute() 
2968   {
2969     SUIT_ViewWindow* wnd = getWnd( myWndId );
2970     if ( wnd )
2971     {
2972       QWidget* p = wnd->parentWidget();
2973       myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2974     }
2975   }
2976 };
2977 bool SalomePyQt::isViewVisible( const int id )
2978 {
2979   return ProcessEvent( new TIsViewVisible( id ) );
2980 }
2981   
2982 /*!
2983   \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2984   \brief Set / clear view's "closable" option. By default any view is closable
2985         (i.e. can be closed by the user).
2986   \param id window identifier
2987   \param on new "closable" option's value
2988 */
2989
2990 void SalomePyQt::setViewClosable( const int id, const bool on )
2991 {
2992   class TEvent: public SALOME_Event
2993   {
2994     int myWndId;
2995     bool myOn;
2996   public:
2997     TEvent( const int id, const bool on )
2998       : myWndId( id ), myOn( on ) {}
2999     virtual void Execute()
3000     {
3001       SUIT_ViewWindow* wnd = getWnd( myWndId );
3002       if ( wnd ) wnd->setClosable( myOn );
3003     }
3004   };
3005   ProcessVoidEvent( new TEvent( id, on ) );
3006 }
3007
3008 /*!
3009   \fn bool SalomePyQt::isViewClosable( const int id );
3010   \brief Check whether view is closable (i.e. can be closed by the user)
3011   \param id window identifier
3012   \return \c true if view is closable or \c false otherwise 
3013 */
3014
3015 class TIsViewClosable: public SALOME_Event
3016 {
3017 public:
3018   typedef bool TResult;
3019   TResult myResult;
3020   int myWndId;
3021   TIsViewClosable( const int id )
3022     : myResult( true ),
3023       myWndId( id ) {}
3024   virtual void Execute() 
3025   {
3026     SUIT_ViewWindow* wnd = getWnd( myWndId );
3027     if ( wnd )
3028       myResult = wnd->closable();
3029   }
3030 };
3031
3032 bool SalomePyQt::isViewClosable( const int id )
3033 {
3034   return ProcessEvent( new TIsViewClosable( id ) );
3035 }
3036
3037 /*!
3038   \fn bool SalomePyQt::groupAllViews();
3039   \brief Group all views to the single tab area
3040   \return \c true if operation is completed successfully and \c false otherwise 
3041 */
3042
3043 class TGroupAllViews: public SALOME_Event
3044 {
3045 public:
3046   typedef bool TResult;
3047   TResult myResult;
3048   TGroupAllViews()
3049     : myResult( false ) {}
3050   virtual void Execute() 
3051   {
3052     LightApp_Application* app  = getApplication();
3053     if ( app ) {
3054       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3055       if ( tabDesk ) {
3056         QtxWorkstack* wStack = tabDesk->workstack();
3057         if ( wStack ) {
3058           wStack->stack();
3059           myResult = true;
3060         }
3061       }
3062     }
3063   }
3064 };
3065 bool SalomePyQt::groupAllViews()
3066 {
3067   return ProcessEvent( new TGroupAllViews() );
3068 }
3069
3070 /*!
3071   \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3072   \brief Split tab area to which view with identifier belongs to
3073   \param id window identifier
3074   \param ori orientation of split operation
3075   \param action action to be performed
3076   \return \c true if operation is completed successfully \c false otherwise 
3077 */
3078
3079 class TSplitView: public SALOME_Event
3080 {
3081 public:
3082   typedef bool TResult;
3083   TResult myResult;
3084   int myWndId;
3085   Orientation myOri;
3086   Action myAction;
3087   TSplitView( const int id, 
3088               const Orientation ori, 
3089               const Action action )
3090     : myResult( false ),
3091       myWndId( id ),
3092       myOri( ori ),
3093       myAction( action ) {}
3094   virtual void Execute() 
3095   {
3096     SUIT_ViewWindow* wnd = getWnd( myWndId );
3097     if ( wnd ) {
3098       // activate view
3099       // wnd->setFocus(); ???
3100
3101       // split workstack
3102       if ( getApplication() ) {
3103         STD_TabDesktop* desk = 
3104           dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3105         if ( desk ) {
3106           QtxWorkstack* wStack = desk->workstack();
3107           if ( wStack ) {
3108             Qt::Orientation qtOri = 
3109               ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3110
3111             QtxWorkstack::SplitType sType;
3112             if ( myAction == MoveWidget )
3113               sType = QtxWorkstack::SplitMove;
3114             else if ( myAction == LeaveWidget )
3115               sType = QtxWorkstack::SplitStay;
3116             else 
3117               sType = QtxWorkstack::SplitAt;
3118
3119             wStack->Split( wnd, qtOri, sType );
3120             myResult = true;
3121           }
3122         }
3123       }
3124     }
3125   }
3126 };
3127 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3128 {
3129   return ProcessEvent( new TSplitView( id, ori, action ) );
3130 }
3131
3132 /*!
3133   \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3134   \brief Move view with the first identifier to the same area which 
3135          another view with the second identifier belongs to
3136   \param id source window identifier
3137   \param id_to destination window identifier  
3138   param before specifies whether the first viewt has to be moved before or after 
3139         the second view
3140   \return \c true if operation is completed successfully and \c false otherwise 
3141 */
3142
3143 class TMoveView: public SALOME_Event
3144 {
3145 public:
3146   typedef bool TResult;
3147   TResult myResult;
3148   int myWndId;
3149   int myWndToId;
3150   bool myIsBefore;
3151   TMoveView( const int id, const int id_to, const bool before )
3152     : myResult( false ),
3153     myWndId( id ),
3154     myWndToId( id_to ),
3155     myIsBefore( before ) {}
3156   virtual void Execute() 
3157   {
3158     SUIT_ViewWindow* wnd = getWnd( myWndId );
3159     SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3160     if ( wnd && wnd_to ) {
3161       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
3162         getApplication()->desktop() )->workstack();
3163       if ( wStack )
3164         myResult = wStack->move( wnd, wnd_to, myIsBefore );
3165     }
3166   }
3167 };
3168 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3169 {
3170   return ProcessEvent( new TMoveView( id, id_to, before ) );
3171 }
3172
3173 /*!
3174   \fn QList<int> SalomePyQt::neighbourViews( const int id );
3175   \brief Get list of views identifiers that belongs to the same area as 
3176          specified view (excluding it)
3177   \param id window identifier
3178   \return list of views identifiers
3179 */
3180
3181 class TNeighbourViews: public SALOME_Event
3182 {
3183 public:
3184   typedef QList<int> TResult;
3185   TResult myResult;
3186   int myWndId;
3187   TNeighbourViews( const int id )
3188     : myWndId( id ) {}
3189   virtual void Execute() 
3190   {
3191     myResult.clear();
3192     SUIT_ViewWindow* wnd = getWnd( myWndId );
3193     if ( wnd ) {
3194       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
3195         getApplication()->desktop() )->workstack();
3196       if ( wStack ) {
3197         QWidgetList wgList = wStack->windowList( wnd );
3198         QWidget* wg;
3199         foreach ( wg, wgList ) {
3200           SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3201           if ( tmpWnd && tmpWnd != wnd )
3202             myResult.append( tmpWnd->getId() );
3203         }
3204       }
3205     }
3206   }
3207 };
3208 QList<int> SalomePyQt::neighbourViews( const int id )
3209 {
3210   return ProcessEvent( new TNeighbourViews( id ) );
3211 }
3212
3213
3214 /*!
3215   \fn QString SalomePyQt::createObject( const QString& parent );
3216   \brief Create empty data object
3217   \param parent entry of parent data object
3218   \return entry of created data object
3219 */
3220
3221 class TCreateEmptyObjectEvent: public SALOME_Event
3222 {
3223 public:
3224   typedef QString TResult;
3225   TResult  myResult;
3226   QString  myParent;
3227   TCreateEmptyObjectEvent( const QString& parent )
3228     : myParent( parent ) {}
3229   virtual void Execute() 
3230   {
3231     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3232     if ( module ) {
3233        myResult = module->createObject( myParent );
3234     }
3235     else {
3236       if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3237     }
3238   }
3239 };
3240 QString SalomePyQt::createObject( const QString& parent )
3241 {
3242   return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3243 }
3244
3245 /*!
3246   \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3247                                         const QString& tooltip,const QString& parent );
3248   \brief Create new data object with specified name, icon and tooltip
3249   \param name data object name
3250   \param icon data object icon
3251   \param toolTip data object tooltip
3252   \param parent entry of parent data object
3253   \return entry of created data object
3254 */
3255
3256 class TCreateObjectEvent: public SALOME_Event 
3257 {
3258 public:
3259   typedef QString TResult;
3260   TResult myResult;
3261   QString myParent;
3262   QString myName;
3263   QString myIcon;
3264   QString myToolTip;
3265   TCreateObjectEvent( const QString& name,
3266                       const QString& icon,
3267                       const QString& tooltip,
3268                       const QString& parent )
3269     : myName( name ),
3270       myIcon( icon ),
3271       myToolTip( tooltip ),
3272       myParent( parent ) {}
3273   virtual void Execute()
3274   {
3275     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3276     if ( module ) {
3277       myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3278     }
3279     else {
3280       if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3281     }
3282   }
3283 };
3284 QString SalomePyQt::createObject( const QString& name,
3285                                   const QString& icon,
3286                                   const QString& toolTip,
3287                                   const QString& parent )
3288 {
3289   return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3290 }
3291
3292
3293 /*!
3294   \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3295   \brief Set data object name
3296   \param entry data object entry
3297   \param name data object name
3298 */
3299 class TSetNameEvent: public SALOME_Event
3300 {
3301 public:
3302   QString myEntry;
3303   QString myName;
3304   TSetNameEvent( const QString& entry,
3305                  const QString& name )
3306   : myEntry( entry ),
3307     myName( name ) {}
3308   virtual void Execute()
3309   {
3310     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3311     if ( module ) {
3312       module->setName( myEntry, myName );
3313     }
3314     else {
3315       if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3316     }
3317   }
3318 };
3319 void SalomePyQt::setName( const QString& entry, const QString& name )
3320 {
3321   ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3322 }
3323
3324 /*!
3325   \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3326   \brief Set data object icon
3327   \param entry data object entry
3328   \param icon data object icon file name (icon is loaded from module resources)
3329 */
3330
3331 class TSetIconEvent: public SALOME_Event
3332 {
3333 public:
3334   QString myEntry;
3335   QString myIcon;
3336   TSetIconEvent( const QString& entry,
3337                  const QString& icon )
3338   : myEntry( entry ),
3339     myIcon( icon ) {}
3340   virtual void Execute()
3341   {
3342     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3343     if ( module ) {
3344       module->setIcon( myEntry, myIcon );
3345     }
3346     else {
3347       if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3348     }
3349   }
3350 };
3351
3352 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3353 {
3354   ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3355 }
3356
3357 /*!
3358   \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3359   \brief Set data object tooltip
3360   \param entry data object entry
3361   \param toolTip data object tooltip
3362 */
3363
3364 class TSetToolTipEvent: public SALOME_Event
3365 {
3366 public:
3367   QString myEntry;
3368   QString myToolTip;
3369   TSetToolTipEvent( const QString& entry,
3370                     const QString& toolTip )
3371     : myEntry( entry ),
3372       myToolTip( toolTip ) {}
3373   virtual void Execute()
3374   {
3375     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3376     if ( module ) {
3377       module->setToolTip( myEntry, myToolTip );
3378     }
3379     else {
3380       if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3381     }
3382   }
3383 };
3384 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3385 {
3386   ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3387 }
3388
3389 /*!
3390   \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3391   \brief Set reference to another data object
3392   \param entry data object entry
3393   \param refEntry referenced data object entry
3394 */
3395
3396 class TSetRefEvent: public SALOME_Event
3397 {
3398 public:
3399   QString myEntry;
3400   QString myRefEntry;
3401   TSetRefEvent( const QString& entry,
3402                 const QString& refEntry )
3403     : myEntry( entry ),
3404       myRefEntry( refEntry ) {}
3405   virtual void Execute()
3406   {
3407     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3408     if ( module ) {
3409       module->setReference( myEntry, myRefEntry );
3410     }
3411     else {
3412       if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3413     }
3414   }
3415 };
3416 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3417 {
3418   ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3419 }
3420
3421 /*!
3422   \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3423   \brief Set data object color
3424   \param entry data object entry
3425   \param color data object color
3426  */
3427
3428 class TSetColorEvent: public SALOME_Event
3429 {
3430 public:
3431   QString myEntry;
3432   QColor  myColor;
3433   TSetColorEvent( const QString& entry,
3434                   const QColor& color )
3435     : myEntry( entry ),
3436       myColor( color ) {}
3437   virtual void Execute()
3438   {
3439     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3440     if ( module ) {
3441       module->setColor( myEntry, myColor );
3442     }
3443     else {
3444       if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3445     }
3446   }
3447 };
3448 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3449 {
3450   ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3451 }
3452
3453 /*!
3454   \fn QString SalomePyQt::getName( const QString& entry );
3455   \brief Get data object name
3456   \param entry data object entry
3457   \return data object name
3458 */
3459
3460 class TGetNameEvent: public SALOME_Event
3461 {
3462 public:
3463   typedef QString TResult;
3464   TResult myResult;
3465   QString myEntry;
3466   TGetNameEvent( const QString& entry )
3467     : myEntry( entry ) {}
3468   virtual void Execute()
3469   {
3470     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3471     if ( module ) {
3472       myResult = module->getName( myEntry );
3473     }
3474     else {
3475       if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3476     }
3477   }
3478 };
3479 QString SalomePyQt::getName( const QString& entry )
3480 {
3481   return ProcessEvent( new TGetNameEvent( entry ) );
3482 }
3483
3484 /*!
3485   \fn QString SalomePyQt::getToolTip( const QString& entry );
3486   \brief Get data object tooltip
3487   \param entry data object entry
3488   \return data object tooltip
3489 */
3490
3491 class TGetToolTipEvent: public SALOME_Event
3492 {
3493 public:
3494   typedef QString TResult;
3495   TResult myResult;
3496   QString myEntry;
3497   TGetToolTipEvent( const QString& entry )
3498   : myEntry( entry ) {}
3499   virtual void Execute()
3500   {
3501     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3502     if ( module ) {
3503       myResult = module->getToolTip( myEntry );
3504     }
3505     else {
3506       if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3507     }
3508   }
3509 };
3510 QString SalomePyQt::getToolTip( const QString& entry )
3511 {
3512   return ProcessEvent( new TGetToolTipEvent( entry ) );
3513 }
3514
3515 /*
3516   \fn QString SalomePyQt::getReference( const QString& entry );
3517   \brief Get entry of the referenced object (if there's any)
3518   \param entry data object entry
3519   \return referenced data object entry
3520 */
3521
3522 class TGetRefEvent: public SALOME_Event
3523 {
3524 public:
3525   typedef QString TResult;
3526   TResult myResult;
3527   QString myEntry;
3528   TGetRefEvent( const QString& entry )
3529   : myEntry( entry ) {}
3530   virtual void Execute()
3531   {
3532     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3533     if ( module ) {
3534       myResult = module->getReference( myEntry );
3535     }
3536     else {
3537       if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3538     }
3539   }
3540 };
3541 QString SalomePyQt::getReference( const QString& entry )
3542 {
3543   return ProcessEvent( new TGetRefEvent( entry ) );
3544 }
3545
3546 /*!
3547   \fn QColor SalomePyQt::getColor( const QString& entry );
3548   \brief Get data object color
3549   \param entry data object entry
3550   \return data object color
3551 */
3552
3553 class TGetColorEvent: public SALOME_Event
3554 {
3555 public:
3556   typedef QColor TResult;
3557   TResult myResult;
3558   QString myEntry;
3559   TGetColorEvent( const QString& entry )
3560   : myEntry( entry ) {}
3561   virtual void Execute()
3562   {
3563     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3564     if ( module ) {
3565       myResult = module->getColor( myEntry );
3566     }
3567     else {
3568       if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3569     }
3570   }
3571 };
3572 QColor SalomePyQt::getColor( const QString& entry )
3573 {
3574   return ProcessEvent( new TGetColorEvent( entry ) );
3575 }
3576
3577 /*!
3578   \fn void SalomePyQt::removeChildren( const QString& entry );
3579   \brief Remove all child data objects from specified data object
3580   \param entry data object entry
3581 */
3582
3583 class TRemoveChildEvent: public SALOME_Event
3584 {
3585 public:
3586   QString myEntry;
3587   TRemoveChildEvent( const QString& entry )
3588   : myEntry( entry ) {}
3589   virtual void Execute()
3590   {
3591     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3592     if ( module ) {
3593       module->removeChildren( myEntry );
3594     }
3595     else {
3596       if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3597     }
3598   }
3599 };
3600 void SalomePyQt::removeChildren( const QString& entry )
3601 {
3602   ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3603 }
3604 void SalomePyQt::removeChild( const QString& entry )
3605 {
3606   if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3607   removeChildren( entry );
3608 }
3609
3610 /*!
3611   \fn void SalomePyQt::removeObject( const QString& entry );
3612   \brief Remove object by entry
3613   \param entry data object entry
3614 */
3615
3616 class TRemoveObjectEvent: public SALOME_Event
3617 {
3618 public:
3619   QString myEntry;
3620   
3621   TRemoveObjectEvent( const QString& entry )
3622   : myEntry( entry ) {}
3623   virtual void Execute()
3624   {
3625     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3626     if ( module ) {
3627       module->removeObject( myEntry );
3628     }
3629     else {
3630       if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3631     }
3632   }
3633 };
3634 void SalomePyQt::removeObject( const QString& entry )
3635 {
3636   ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3637 }
3638
3639 /*!
3640   \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3641   \brief Get entries of all child data objects of specified data object
3642   \param entry data object entry
3643   \param recursive \c true for recursive processing
3644 */
3645
3646 class TGetChildrenEvent: public SALOME_Event
3647 {
3648 public:
3649   typedef QStringList TResult;
3650   TResult myResult;
3651   QString myEntry;
3652   bool    myRecursive; 
3653   TGetChildrenEvent( const QString& entry, const bool recursive )
3654     : myEntry( entry ),
3655       myRecursive( recursive ) {}
3656   virtual void Execute()
3657   {
3658     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3659     if ( module ) {
3660       myResult = module->getChildren( myEntry, myRecursive );
3661     }
3662     else {
3663       if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3664     }
3665   }
3666 };
3667 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3668 {
3669   return ProcessEvent( new TGetChildrenEvent( entry, recursive ) ); 
3670 }
3671
3672 #ifndef DISABLE_PLOT2DVIEWER
3673 // Next set of methods relates to the Plot2d viewer functionality
3674
3675 /*!
3676   \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3677   \brief Display theCurve in view
3678   \param id window identifier
3679   \param theCurve curve to display
3680 */
3681
3682 class TDisplayCurve: public SALOME_Event
3683 {
3684 public:
3685   int myWndId;
3686   Plot2d_Curve* myCurve;
3687   TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3688   virtual void Execute() {
3689     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3690     if ( wnd )
3691       wnd->getViewFrame()->displayCurve( myCurve );
3692   }
3693 };
3694 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3695 {
3696   ProcessVoidEvent( new TDisplayCurve( id, theCurve ) ); 
3697 }
3698
3699 /*!
3700   \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3701   \brief Erase theCurve in view
3702   \param id window identifier
3703   \param theCurve curve to erase
3704 */
3705
3706 class TEraseCurve: public SALOME_Event
3707 {
3708 public:
3709   int myWndId;
3710   Plot2d_Curve* myCurve;
3711   TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3712   virtual void Execute() {
3713     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3714     wnd->getViewFrame()->eraseCurve( myCurve );
3715   }
3716 };
3717 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3718 {
3719   ProcessVoidEvent( new TEraseCurve( id, theCurve ) ); 
3720 }
3721
3722 /*!
3723   \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3724   \brief Delete theCurve from all views
3725   \param theCurve curve to delete
3726 */
3727
3728 class TDeleteCurve: public SALOME_Event
3729 {
3730 public:
3731   Plot2d_Curve* myCurve;
3732   TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3733   virtual void Execute() {
3734     LightApp_Application* app  = getApplication();
3735     if ( app ) {
3736       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3737       if ( tabDesk ) {
3738         QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3739         SUIT_ViewWindow* wnd;
3740         foreach ( wnd, wndlist ) {
3741           Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3742           if ( aP2d )
3743             aP2d->getViewFrame()->eraseObject( myCurve );
3744         }
3745       }
3746     }
3747   }
3748 };
3749 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3750 {
3751   ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3752 }
3753
3754 /*!
3755   \brief updateCurves (repaint) curves in view window.
3756 */
3757 void SalomePyQt::updateCurves( const int id )
3758 {
3759   class TEvent: public SALOME_Event
3760   {
3761   public:
3762     int myWndId;
3763     TEvent( const int id ) : myWndId( id ) {}
3764     virtual void Execute()
3765     {
3766       Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3767       if ( wnd )
3768         wnd->getViewFrame()->DisplayAll();
3769     }
3770   };
3771   ProcessVoidEvent( new TEvent( id ) );
3772 }
3773
3774 /*!
3775   \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3776   \brief Get title of corresponding type
3777   \param id window identifier
3778   \param type is type of title
3779   \return title of corresponding type
3780 */
3781
3782 class TGetPlot2dTitle: public SALOME_Event
3783 {
3784 public:
3785   typedef QString TResult;
3786   TResult myResult;
3787   int myWndId;
3788   ObjectType myType;
3789   TGetPlot2dTitle(const int id, ObjectType type) :
3790     myWndId( id ),
3791     myType( type ) {}
3792   virtual void Execute() {
3793     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3794     if ( wnd )
3795       myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
3796   }
3797 };
3798 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
3799 {
3800   return ProcessEvent( new TGetPlot2dTitle( id, type ) ); 
3801 }
3802
3803
3804 /*!
3805   \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3806   \brief Set title of corresponding type
3807   \param id window identifier
3808   \param title
3809   \param type is type of title
3810   \param show
3811 */
3812
3813 class TSetPlot2dTitle: public SALOME_Event
3814 {
3815 public:
3816   int myWndId;
3817   Plot2d_Curve* myCurve;
3818   QString myTitle;
3819   ObjectType myType;
3820   bool myShow;
3821   TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
3822     myWndId( id ),
3823     myTitle( title ),
3824     myType( type ),
3825     myShow( show ) {}
3826   virtual void Execute() {
3827     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3828     wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
3829   }
3830 };
3831 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
3832 {
3833   ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) ); 
3834 }
3835
3836 /*!
3837   \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3838   \brief Get list of Plot2d view ranges
3839   \param id window identifier
3840   \return list of view ranges (XMin, XMax, YMin, YMax)
3841 */
3842
3843 class TFitRangeByCurves: public SALOME_Event
3844 {
3845 public:
3846   typedef QList<double> TResult;
3847   TResult myResult;
3848   int myWndId;
3849   TFitRangeByCurves( const int id )
3850     : myWndId( id ) {}
3851   virtual void Execute() 
3852   {
3853     myResult.clear();
3854     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3855     if ( wnd ) {
3856       double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3857       wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3858       myResult.append( XMin );
3859       myResult.append( XMax );
3860       myResult.append( YMin );
3861       myResult.append( YMax );
3862     }
3863   }
3864 };
3865 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3866 {
3867   return ProcessEvent( new TFitRangeByCurves( id ) );
3868 }
3869
3870 /*!
3871   \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3872   \brief Get list of current Plot2d view ranges
3873   \param id window identifier
3874   \return list of view ranges (XMin, XMax, YMin, YMax)
3875 */
3876
3877 class TFitRangeCurrent: public SALOME_Event
3878 {
3879 public:
3880   typedef QList<double> TResult;
3881   TResult myResult;
3882   int myWndId;
3883   TFitRangeCurrent( const int id )
3884     : myWndId( id ) {}
3885   virtual void Execute() 
3886   {
3887     myResult.clear();
3888     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3889     if ( wnd ) {
3890       double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3891       wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3892       myResult.append( XMin );
3893       myResult.append( XMax );
3894       myResult.append( YMin );
3895       myResult.append( YMax );
3896     }
3897   }
3898 };
3899 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3900 {
3901   return ProcessEvent( new TFitRangeCurrent( id ) );
3902 }
3903
3904 /*!
3905   \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3906   \brief Set range of Plot2d view
3907   \param id window identifier
3908   \param XMin
3909   \param XMax
3910   \param YMin
3911   \param YMax
3912 */
3913
3914 class TPlot2dFitRange: public SALOME_Event
3915 {
3916 public:
3917   int myWndId;
3918   double myXMin;
3919   double myXMax;
3920   double myYMin;
3921   double myYMax;
3922   TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
3923     myWndId( id ),
3924     myXMin( XMin ),
3925     myXMax( XMax ),
3926     myYMin( YMin ),
3927     myYMax( YMax ) {}
3928   virtual void Execute() {
3929     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3930     if ( wnd )
3931       wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
3932   }
3933 };
3934 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3935 {
3936   ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) ); 
3937 }
3938
3939 // End of methods related to the Plot2d viewer functionality
3940 #endif // DISABLE_PLOT2DVIEWER
3941
3942 /*!
3943   \brief Process Qt event loop
3944 */
3945 void SalomePyQt::processEvents()
3946 {
3947   QCoreApplication::processEvents();
3948 }
3949
3950 /*!
3951   \brief Set visibility state for given object
3952   \param theEntry study ID of the object
3953   \param theState visibility state
3954 */
3955 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
3956 {
3957   class TEvent: public SALOME_Event
3958   {
3959     QString myEntry;
3960     int myState;
3961   public:
3962     TEvent( const QString& theEntry, int theState ):
3963       myEntry( theEntry ), myState( theState ) {}
3964     virtual void Execute() 
3965     {
3966       LightApp_Study* aStudy = getActiveStudy();
3967       if ( !aStudy )
3968         return;
3969       aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
3970     }
3971   };
3972   ProcessVoidEvent( new TEvent( theEntry, theState ) );
3973 }
3974
3975 /*!
3976   \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3977   \brief Get visibility state for given object
3978   \param theEntry study ID of the object
3979   \return visibility state
3980 */
3981
3982 class TGetVisibilityStateEvent: public SALOME_Event 
3983 {
3984 public:
3985   typedef int TResult;
3986   TResult myResult;
3987   QString myEntry;
3988   TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
3989   virtual void Execute()
3990   {
3991     LightApp_Study* aStudy = getActiveStudy();
3992     if ( aStudy )
3993       myResult = aStudy->visibilityState( myEntry );
3994   }
3995 };
3996 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3997 {
3998   return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
3999 }
4000
4001 /*!
4002   \brief Set position of given object in the tree
4003   \param theEntry study ID of the object
4004   \param thePos position
4005 */
4006 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4007 {
4008   class TEvent: public SALOME_Event
4009   {
4010     QString myEntry;
4011     int myPos;
4012   public:
4013     TEvent( const QString& theEntry, int thePos ):
4014       myEntry( theEntry ), myPos( thePos ) {}
4015     virtual void Execute() 
4016     {
4017       SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4018       if ( module )
4019         module->setObjectPosition( myEntry, myPos );
4020     }
4021   };
4022   ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4023 }
4024
4025 /*!
4026   \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4027   \brief Get position of given object in the tree
4028   \param theEntry study ID of the object
4029   \return position
4030 */
4031
4032 class TGetObjectPositionEvent: public SALOME_Event 
4033 {
4034 public:
4035   typedef int TResult;
4036   TResult myResult;
4037   QString myEntry;
4038   TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4039   virtual void Execute()
4040   {
4041     SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4042     if ( module )
4043       myResult = module->getObjectPosition( myEntry );
4044   }
4045 };
4046 int SalomePyQt::getObjectPosition( const QString& theEntry )
4047 {
4048   return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4049 }
4050
4051 /*!
4052   \brief Start recordind a log of Python commands from embedded console
4053   \param theFileName output lof file name
4054 */
4055 void SalomePyQt::startPyLog( const QString& theFileName )
4056 {
4057   class TEvent: public SALOME_Event
4058   {
4059     QString myFileName;
4060   public:
4061     TEvent( const QString& theFileName ):
4062       myFileName( theFileName ) {}
4063     virtual void Execute() 
4064     {
4065       if ( getApplication() ) {
4066         PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4067         if ( pyConsole ) pyConsole->startLog( myFileName );
4068       }
4069     }
4070   };
4071   ProcessVoidEvent( new TEvent( theFileName ) );
4072 }
4073
4074 /*!
4075   \brief Stop recordind a log of Python commands from embedded console
4076 */
4077 void SalomePyQt::stopPyLog()
4078 {
4079   class TEvent: public SALOME_Event
4080   {
4081   public:
4082     TEvent() {}
4083     virtual void Execute() 
4084     {
4085       if ( getApplication() ) {
4086         PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4087         if ( pyConsole ) pyConsole->stopLog();
4088       }
4089     }
4090   };
4091   ProcessVoidEvent( new TEvent() );
4092 }