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