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