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