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