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