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