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