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