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