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