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