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