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