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