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