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