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