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