Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / SALOME_PYQT / SalomePyQt / SalomePyQt.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19
20 #include "SALOME_PYQT_Module.h" // this include must be first!!!
21 #include "SalomePyQt.h"
22
23 #include <qapplication.h>
24 #include <qmenubar.h>
25 #include <qwidget.h>
26 #include <qpopupmenu.h>
27 #include <qimage.h>
28 #include <qstringlist.h>
29
30 #include "SALOME_Event.hxx"
31
32 #include "SUIT_Session.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Tools.h"
36 #include "STD_MDIDesktop.h"
37 #include "SalomeApp_Application.h"
38 #include "SalomeApp_Study.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "OB_Browser.h"
41 #include "QtxAction.h"
42
43 using namespace std;
44
45 /*!
46   \return active application object [ static ]
47 */
48 static SalomeApp_Application* getApplication() {
49   if ( SUIT_Session::session() )
50     return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
51   return NULL;
52 }
53
54 /*!
55   \return active study or 0 if there is no study opened [ static ]
56 */
57 static SalomeApp_Study* getActiveStudy()
58 {
59   if ( getApplication() )
60     return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
61   return 0;
62 }
63
64 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
65
66 /*!
67   Creates or finds the selection object (one per study).
68 */
69 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
70 {
71   SALOME_Selection* sel = 0;
72   if ( app && SelMap.find( app ) != SelMap.end() )
73     sel = SelMap[ app ];
74   else 
75     sel = SelMap[ app ] = new SALOME_Selection( app );
76   return sel;
77 }
78
79 /*!
80   Selection constructor.
81 */
82 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
83 {
84   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
85   if ( app ) {
86     mySelMgr = app->selectionMgr();
87     connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
88     connect( mySelMgr, SIGNAL( destroyed() ),        this, SLOT  ( onSelMgrDestroyed() ) );
89   }
90 }
91 /*!
92   Selection destructor. Removes selection object from the map.
93 */
94 SALOME_Selection::~SALOME_Selection()
95 {
96   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
97   if ( app && SelMap.find( app ) != SelMap.end() )
98     SelMap.remove( app );
99 }
100
101 /*!
102   Watches for the selection manager destroying when study is closed.
103 */
104 void SALOME_Selection::onSelMgrDestroyed()
105 {
106   mySelMgr = 0;
107 }
108
109 /*!
110   Clears the selection.
111 */
112 void SALOME_Selection::Clear()
113 {
114   class TEvent: public SALOME_Event {
115     LightApp_SelectionMgr* mySelMgr;
116   public:
117     TEvent( LightApp_SelectionMgr* selMgr ) 
118       : mySelMgr( selMgr ) {}
119     virtual void Execute() {
120       if ( mySelMgr )
121         mySelMgr->clearSelected();
122     }
123   };
124   ProcessVoidEvent( new TEvent( mySelMgr ) );
125 }
126
127 /*!
128   Clears the selection.
129 */
130 void SALOME_Selection::ClearIObjects()
131 {
132   Clear();
133 }
134
135 /*!
136   Removes all selection filters.
137 */
138 void SALOME_Selection::ClearFilters()
139 {
140   class TEvent: public SALOME_Event {
141     LightApp_SelectionMgr* mySelMgr;
142   public:
143     TEvent( LightApp_SelectionMgr* selMgr ) 
144       : mySelMgr( selMgr ) {}
145     virtual void Execute() {
146       if ( mySelMgr )
147         mySelMgr->clearFilters();
148     }
149   };
150   ProcessVoidEvent( new TEvent( mySelMgr ) );
151 }
152
153 /*!
154   \return desktop (0 if error)
155 */
156 class TGetDesktopEvent: public SALOME_Event {
157 public:
158   typedef QWidget* TResult;
159   TResult myResult;
160   TGetDesktopEvent() : myResult( 0 ) {}
161   virtual void Execute() {
162     if ( getApplication() )
163       myResult = (QWidget*)( getApplication()->desktop() );
164   }
165 };
166
167 /*!
168   \return desktop
169 */
170 QWidget* SalomePyQt::getDesktop()
171 {
172   return ProcessEvent( new TGetDesktopEvent() );
173 }
174
175 /*!
176   \return workspace widget (0 if error)
177 */
178 class TGetMainFrameEvent: public SALOME_Event {
179 public:
180   typedef QWidget* TResult;
181   TResult myResult;
182   TGetMainFrameEvent() : myResult( 0 ) {}
183   virtual void Execute() {
184     if ( getApplication() ) {
185       SUIT_Desktop* aDesktop = getApplication()->desktop();
186       myResult = (QWidget*)( aDesktop->centralWidget() );
187     }
188   }
189 };
190
191 /*!
192   \return workspace widget (0 if error)
193 */
194 QWidget* SalomePyQt::getMainFrame()
195 {
196   return ProcessEvent( new TGetMainFrameEvent() );
197 }
198
199 /*!
200   SalomePyQt::getMainMenuBar
201   Gets main menu. Returns 0 in error.
202 */
203 class TGetMainMenuBarEvent: public SALOME_Event {
204 public:
205   typedef QMenuBar* TResult;
206   TResult myResult;
207   TGetMainMenuBarEvent() : myResult( 0 ) {}
208   virtual void Execute() {
209     if ( SalomeApp_Application* anApp = getApplication() ) {
210       myResult = anApp->desktop()->menuBar();
211     }
212   }
213 };
214
215 /*!
216   \return main menu
217   \retval 0 in error.
218 */
219 QMenuBar* SalomePyQt::getMainMenuBar() 
220 {
221   return ProcessEvent( new TGetMainMenuBarEvent() );
222 }
223
224 /*!
225   SalomePyQt::getPopupMenu
226   Gets an main menu's child popup menu by its id
227 */
228 class TGetPopupMenuEvent: public SALOME_Event {
229 public:
230   typedef QPopupMenu* TResult;
231   TResult  myResult;
232   MenuName myMenuName;
233   TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
234   virtual void Execute() {
235     if ( SalomeApp_Application* anApp = getApplication() ) {
236       QMenuBar* menuBar = anApp->desktop()->menuBar();
237       if ( menuBar ) {
238         QString menu;
239         switch( myMenuName) {
240         case File:
241           menu = QObject::tr( "MEN_DESK_FILE" );        break;
242         case View:
243           menu = QObject::tr( "MEN_DESK_VIEW" );        break;
244         case Edit:
245           menu = QObject::tr( "MEN_DESK_EDIT" );        break;
246         case Preferences:
247           menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
248         case Tools:
249           menu = QObject::tr( "MEN_DESK_TOOLS" );       break;
250         case Window:
251           menu = QObject::tr( "MEN_DESK_WINDOW" );      break;
252         case Help:
253           menu = QObject::tr( "MEN_DESK_HELP" );        break;
254         }
255         for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
256           QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
257           if ( item && item->text() == menu && item->popup() )
258             myResult = item->popup();
259         }
260       }
261     }
262   }
263 };
264
265 /*!
266   \return popup menu
267   \param menu - menu name
268 */
269 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
270 {
271   return ProcessEvent( new TGetPopupMenuEvent( menu ) );
272 }
273
274 /*!
275   SalomePyQt::getStudyId
276   Returns active study's ID or 0 if there is no active study.
277 */
278 class TGetStudyIdEvent: public SALOME_Event {
279 public:
280   typedef int TResult;
281   TResult myResult;
282   TGetStudyIdEvent() : myResult( 0 ) {}
283   virtual void Execute() {
284     if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
285       myResult = aStudy->studyDS()->StudyId();
286     }
287   }
288 };
289
290 /*!
291   SalomePyQt::getStudyId
292   Returns active study's ID or 0 if there is no active study.
293 */
294 int SalomePyQt::getStudyId()
295 {
296   return ProcessEvent( new TGetStudyIdEvent() );
297 }
298
299 /*!
300   SalomePyQt::getSelection
301   Creates a Selection object (to provide a compatibility with previous SALOME GUI).
302 */
303 class TGetSelectionEvent: public SALOME_Event {
304 public:
305   typedef SALOME_Selection* TResult;
306   TResult myResult;
307   TGetSelectionEvent() : myResult( 0 ) {}
308   virtual void Execute() {
309     myResult = SALOME_Selection::GetSelection( getApplication() );
310   }
311 };
312
313 /*!
314   Creates a Selection object (to provide a compatibility with previous SALOME GUI).
315   \return just created selection object
316 */
317 SALOME_Selection* SalomePyQt::getSelection()
318 {
319   return ProcessEvent( new TGetSelectionEvent() );
320 }
321
322 /*!
323   SalomePyQt::putInfo
324   Puts an information message to the desktop's status bar
325   (with optional delay parameter given in seconds)
326 */
327 class TPutInfoEvent: public SALOME_Event {
328   QString myMsg;
329   int     mySecs;
330 public:
331   TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
332   virtual void Execute() {
333     if ( SalomeApp_Application* anApp = getApplication() ) {
334       anApp->putInfo( myMsg, mySecs * 1000 );
335     }
336   }
337 };
338
339 /*!
340   Puts an information message to the desktop's status bar
341   (with optional delay parameter given in seconds)
342   \param msg - message text 
343   \param sec - delay in seconds
344 */
345 void SalomePyQt::putInfo( const QString& msg, const int sec )
346 {
347   ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
348 }
349
350 /*!
351   SalomePyQt::getActiveComponent
352   Returns an active component name or empty string if there is no active component
353 */
354 class TGetActiveComponentEvent: public SALOME_Event {
355 public:
356   typedef QString TResult;
357   TResult myResult;
358   TGetActiveComponentEvent() {}
359   virtual void Execute() {
360     if ( SalomeApp_Application* anApp = getApplication() ) {
361       if ( CAM_Module* mod = anApp->activeModule() ) {
362         myResult = mod->name("");
363       }
364     }
365   }
366 };
367
368 /*!
369   \return an active component name or empty string if there is no active component
370 */
371 const QString SalomePyQt::getActiveComponent()
372 {
373   return ProcessEvent( new TGetActiveComponentEvent() );
374 }
375
376 /*!
377   SalomePyQt::updateObjBrowser
378   Updates an Object Browser of a given study.
379   If <studyId> <= 0 the active study's object browser is updated.
380   <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
381 */
382 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
383 {  
384   class TEvent: public SALOME_Event {
385     int  myStudyId;
386     bool myUpdateSelection;
387   public:
388     TEvent( const int studyId, bool updateSelection ) 
389       : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
390     virtual void Execute() {
391       if ( SUIT_Session::session() ) {
392         if ( getActiveStudy() && myStudyId <= 0 )
393           myStudyId = getActiveStudy()->id();
394         if ( myStudyId > 0 ) {
395           QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
396           QPtrListIterator<SUIT_Application> it( apps );
397           for( ; it.current(); ++it ) {
398             SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
399             if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
400               anApp->updateObjectBrowser();
401           }
402         }
403       }
404     }
405   };
406   ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
407 }
408
409 const char* DEFAULT_SECTION = "SalomePyQt";
410
411 /*!
412   SalomePyQt::addStringSetting
413   Adds a string setting to the application preferences
414   <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
415   This function is obsolete. Use addSetting() instead.
416 */
417 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
418 {
419   class TEvent: public SALOME_Event {
420     QString myName;
421     QString myValue;
422     bool    myAutoValue;
423   public:
424     TEvent( const QString& name, const QString& value, bool autoValue ) 
425       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
426     virtual void Execute() {
427       if ( SUIT_Session::session() ) {
428         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
429         QStringList sl = QStringList::split( ":", myName );
430         QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
431         QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
432         if ( !_sec.isEmpty() && !_nam.isEmpty() )
433           resMgr->setValue( _sec, _nam, myValue );
434       }
435     }
436   };
437   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
438 }
439
440 /*!
441   SalomePyQt::addIntSetting
442   Adds an integer setting to the application preferences
443   <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
444   This function is obsolete. Use addSetting() instead.
445 */
446 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
447 {
448   class TEvent: public SALOME_Event {
449     QString myName;
450     int     myValue;
451     bool    myAutoValue;
452   public:
453     TEvent( const QString& name, const int value, bool autoValue ) 
454       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
455     virtual void Execute() {
456       if ( SUIT_Session::session() ) {
457         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
458         QStringList sl = QStringList::split( ":", myName );
459         QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
460         QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
461         if ( !_sec.isEmpty() && !_nam.isEmpty() )
462           resMgr->setValue( _sec, _nam, myValue );
463       }
464     }
465   };
466   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
467 }
468
469 /*!
470   SalomePyQt::addDoubleSetting
471   Adds an double setting to the application preferences
472   <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
473   This function is obsolete. Use addSetting() instead.
474 */
475 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
476 {
477   class TEvent: public SALOME_Event {
478     QString myName;
479     double  myValue;
480     bool    myAutoValue;
481   public:
482     TEvent( const QString& name, const double value, bool autoValue ) 
483       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
484     virtual void Execute() {
485       if ( SUIT_Session::session() ) {
486         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
487         QStringList sl = QStringList::split( ":", myName );
488         QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
489         QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
490         if ( !_sec.isEmpty() && !_nam.isEmpty() )
491           resMgr->setValue( _sec, _nam, myValue );
492       }
493     }
494   };
495   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
496 }
497
498 /*!
499   SalomePyQt::removeSettings
500   Removes a setting from the application preferences
501   This function is obsolete. Use removeSetting() instead.
502 */
503 void SalomePyQt::removeSettings( const QString& name )
504 {
505   class TEvent: public SALOME_Event {
506     QString myName;
507   public:
508     TEvent( const QString& name ) : myName( name ) {}
509     virtual void Execute() {
510       if ( SUIT_Session::session() ) {
511         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
512         QStringList sl = QStringList::split( ":", myName );
513         QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
514         QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
515         if ( !_sec.isEmpty() && !_nam.isEmpty() )
516           resMgr->remove( _sec, _nam );
517       }
518     }
519   };
520   ProcessVoidEvent( new TEvent( name ) );
521 }
522
523 /*!
524   SalomePyQt::getSetting
525   Gets a setting value (as string)
526   This function is obsolete. Use stringSetting(), integerSetting(), 
527   boolSetting(), stringSetting() or colorSetting() instead.
528 */
529 class TGetSettingEvent: public SALOME_Event {
530 public:
531   typedef QString TResult;
532   TResult myResult;
533   QString myName;
534   TGetSettingEvent( const QString& name ) : myName( name ) {}
535   virtual void Execute() {
536     if ( SUIT_Session::session() ) {
537       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
538       QStringList sl = QStringList::split( ":", myName );
539       QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
540       QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
541       myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
542     }
543   }
544 };
545
546 /*!
547   \return a setting value (as string)
548   This function is obsolete. Use stringSetting(), integerSetting(), 
549   boolSetting(), stringSetting() or colorSetting() instead.
550 */
551 QString SalomePyQt::getSetting( const QString& name )
552 {
553   return ProcessEvent( new TGetSettingEvent( name ) );
554 }
555
556 /*!
557   SalomePyQt::addSetting
558   Adds a double setting to the application preferences
559 */
560 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
561 {
562   class TEvent: public SALOME_Event {
563     QString mySection;
564     QString myName;
565     double  myValue;
566   public:
567     TEvent( const QString& section, const QString& name, double value ) 
568       : mySection( section ), myName( name ), myValue( value ) {}
569     virtual void Execute() {
570       if ( SUIT_Session::session() ) {
571         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
572         if ( !mySection.isEmpty() && !myName.isEmpty() )
573           resMgr->setValue( mySection, myName, myValue );
574       }
575     }
576   };
577   ProcessVoidEvent( new TEvent( section, name, value ) );
578 }
579
580 /*!
581   SalomePyQt::addSetting
582   Adds an integer setting to the application preferences
583 */
584 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
585 {
586   class TEvent: public SALOME_Event {
587     QString mySection;
588     QString myName;
589     int     myValue;
590   public:
591     TEvent( const QString& section, const QString& name, int value ) 
592       : mySection( section ), myName( name ), myValue( value ) {}
593     virtual void Execute() {
594       if ( SUIT_Session::session() ) {
595         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
596         if ( !mySection.isEmpty() && !myName.isEmpty() )
597           resMgr->setValue( mySection, myName, myValue );
598       }
599     }
600   };
601   ProcessVoidEvent( new TEvent( section, name, value ) );
602 }
603
604 /*!
605   SalomePyQt::addSetting
606   Adds a string setting to the application preferences
607 */
608 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
609 {
610   class TEvent: public SALOME_Event {
611     QString mySection;
612     QString myName;
613     QString myValue;
614   public:
615     TEvent( const QString& section, const QString& name, const QString& value ) 
616       : mySection( section ), myName( name ), myValue( value ) {}
617     virtual void Execute() {
618       if ( SUIT_Session::session() ) {
619         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
620         if ( !mySection.isEmpty() && !myName.isEmpty() )
621           resMgr->setValue( mySection, myName, myValue );
622       }
623     }
624   };
625   ProcessVoidEvent( new TEvent( section, name, value ) );
626 }
627
628 /*!
629   SalomePyQt::addSetting
630   Adds a color setting to the application preferences
631 */
632 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
633 {
634   class TEvent: public SALOME_Event {
635     QString mySection;
636     QString myName;
637     QColor  myValue;
638   public:
639     TEvent( const QString& section, const QString& name, const QColor& value ) 
640       : mySection( section ), myName( name ), myValue( value ) {}
641     virtual void Execute() {
642       if ( SUIT_Session::session() ) {
643         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
644         if ( !mySection.isEmpty() && !myName.isEmpty() )
645           resMgr->setValue( mySection, myName, myValue );
646       }
647     }
648   };
649   ProcessVoidEvent( new TEvent( section, name, value ) );
650 }
651
652 /*!
653   SalomePyQt::integerSetting
654   Gets an integer setting from the application preferences
655 */
656 class TGetIntSettingEvent: public SALOME_Event {
657 public:
658   typedef int TResult;
659   TResult myResult;
660   QString mySection;
661   QString myName;
662   TResult myDefault;
663   TGetIntSettingEvent( const QString& section, const QString& name, const int def ) 
664     : mySection( section ), myName( name ), myDefault( def ) {}
665   virtual void Execute() {
666     if ( SUIT_Session::session() ) {
667       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
668       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
669     }
670   }
671 };
672
673 /*!
674   \return an integer setting from the application preferences
675 */
676 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
677 {
678   return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
679 }
680
681 /*!
682   SalomePyQt::doubleSetting
683   Gets a double setting from the application preferences
684 */
685 class TGetDblSettingEvent: public SALOME_Event {
686 public:
687   typedef double TResult;
688   TResult myResult;
689   QString mySection;
690   QString myName;
691   TResult myDefault;
692   TGetDblSettingEvent( const QString& section, const QString& name, const double def ) 
693     : mySection( section ), myName( name ), myDefault( def ) {}
694   virtual void Execute() {
695     if ( SUIT_Session::session() ) {
696       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
697       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
698     }
699   }
700 };
701
702 /*!
703   \return an double setting from the application preferences
704 */
705 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
706 {
707   return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
708 }
709
710 /*!
711   SalomePyQt::boolSetting
712   Gets a boolean setting from the application preferences
713 */
714 class TGetBoolSettingEvent: public SALOME_Event {
715 public:
716   typedef bool TResult;
717   TResult myResult;
718   QString mySection;
719   QString myName;
720   TResult myDefault;
721   TGetBoolSettingEvent( const QString& section, const QString& name, const bool def ) 
722     : mySection( section ), myName( name ), myDefault( def ) {}
723   virtual void Execute() {
724     if ( SUIT_Session::session() ) {
725       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
726       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
727     }
728   }
729 };
730
731 /*!
732   \return an boolean setting from the application preferences
733 */
734 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
735 {
736   return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
737 }
738
739 /*!
740   SalomePyQt::stringSetting
741   Gets a string setting from the application preferences
742 */
743 class TGetStrSettingEvent: public SALOME_Event {
744 public:
745   typedef QString TResult;
746   TResult myResult;
747   QString mySection;
748   QString myName;
749   TResult myDefault;
750   TGetStrSettingEvent( const QString& section, const QString& name, const QString& def ) 
751     : mySection( section ), myName( name ), myDefault( def ) {}
752   virtual void Execute() {
753     if ( SUIT_Session::session() ) {
754       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
755       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
756     }
757   }
758 };
759
760 /*!
761   \return an string setting from the application preferences
762 */
763 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
764 {
765   return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
766 }
767
768 /*!
769   SalomePyQt::colorSetting
770   Gets a color setting from the application preferences
771 */
772 class TGetColorSettingEvent: public SALOME_Event {
773 public:
774   typedef QColor TResult;
775   TResult myResult;
776   QString mySection;
777   QString myName;
778   TResult myDefault;
779   TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def ) 
780     : mySection( section ), myName( name ), myDefault( def ) {}
781   virtual void Execute() {
782     if ( SUIT_Session::session() ) {
783       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
784       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
785     }
786   }
787 };
788
789 /*!
790   \return a color setting from the application preferences
791 */
792 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
793 {
794   return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
795 }
796
797 /*!
798   SalomePyQt::removeSetting
799   Removes a setting from the application preferences
800 */
801 void SalomePyQt::removeSetting( const QString& section, const QString& name )
802 {
803   class TEvent: public SALOME_Event {
804     QString mySection;
805     QString myName;
806   public:
807     TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
808     virtual void Execute() {
809       if ( SUIT_Session::session() ) {
810         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
811         if ( !mySection.isEmpty() && !myName.isEmpty() )
812           resMgr->remove( mySection, myName );
813       }
814     }
815   };
816   ProcessVoidEvent( new TEvent( section, name ) );
817 }
818
819 /*!
820   SalomePyQt::getFileName
821   Displays 'Open/Save file' dialog box and returns a user's choice (file name)
822 */
823 class TGetFileNameEvent: public SALOME_Event {
824 public:
825   typedef QString TResult;
826   TResult     myResult;
827   QWidget*    myParent;
828   QString     myInitial;
829   QStringList myFilters;
830   QString     myCaption;
831   bool        myOpen;
832   TGetFileNameEvent( QWidget*           parent, 
833                      const QString&     initial, 
834                      const QStringList& filters, 
835                      const QString&     caption,
836                      bool               open ) 
837     : myParent ( parent ), 
838       myInitial( initial ), 
839       myFilters( filters ), 
840       myCaption( caption ), 
841       myOpen ( open ) {}
842   virtual void Execute() {
843     if ( SalomeApp_Application* anApp = getApplication() ) {
844       myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
845     }
846   }
847 };
848
849 /*!
850   Displays 'Open/Save file' dialog box and returns a user's choice (file name)
851 */
852 QString SalomePyQt::getFileName( QWidget*           parent, 
853                                  const QString&     initial, 
854                                  const QStringList& filters, 
855                                  const QString&     caption,
856                                  bool               open )
857 {
858   return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
859 }
860
861 /*!
862   SalomePyQt::getOpenFileNames
863   Displays 'Open files' dialog box and returns a user's choice (a list of file names)
864 */
865 class TGetOpenFileNamesEvent: public SALOME_Event {
866 public:
867   typedef QStringList TResult;
868   TResult     myResult;
869   QWidget*    myParent;
870   QString     myInitial;
871   QStringList myFilters;
872   QString     myCaption;
873   TGetOpenFileNamesEvent( QWidget*           parent, 
874                           const QString&     initial, 
875                           const QStringList& filters, 
876                           const QString&     caption ) 
877     : myParent ( parent ), 
878       myInitial( initial ), 
879       myFilters( filters ), 
880       myCaption( caption ) {}
881   virtual void Execute() {
882     if ( SalomeApp_Application* anApp = getApplication() ) {
883       myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
884     }
885   }
886 };
887
888 /*!
889   Displays 'Open files' dialog box and returns a user's choice (a list of file names)
890 */
891 QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
892                                           const QString&     initial, 
893                                           const QStringList& filters, 
894                                           const QString&     caption )
895 {
896   return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
897 }
898
899 /*!
900   SalomePyQt::getExistingDirectory
901   Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
902 */
903 class TGetExistingDirectoryEvent: public SALOME_Event {
904 public:
905   typedef QString TResult;
906   TResult     myResult;
907   QWidget*    myParent;
908   QString     myInitial;
909   QString     myCaption;
910   TGetExistingDirectoryEvent( QWidget*           parent, 
911                               const QString&     initial, 
912                               const QString&     caption ) 
913     : myParent ( parent ), 
914       myInitial( initial ), 
915       myCaption( caption ) {}
916   virtual void Execute() {
917     if ( SalomeApp_Application* anApp = getApplication() ) {
918       myResult = anApp->getDirectory( myInitial, myCaption, myParent );
919     }
920   }
921 };
922
923 /*!
924   Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
925 */
926 QString SalomePyQt::getExistingDirectory( QWidget*       parent,
927                                           const QString& initial,
928                                           const QString& caption )
929 {
930   return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
931 }
932
933 /*!
934   SalomePyQt::helpContext
935   Opens external browser to display 'context help' information
936   current implementation does nothing.
937 */
938 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
939   class TEvent: public SALOME_Event {
940     QString mySource;
941     QString myContext;
942   public:
943     TEvent( const QString& source, const QString& context ) 
944       : mySource( source ), myContext( context ) {}
945     virtual void Execute() {
946       if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
947         // VSR: TODO
948         // anApp->helpContext( mySource, myContext );
949       }
950     }
951   };
952   ProcessVoidEvent( new TEvent( source, context ) );
953 }
954
955 /*!
956   SalomePyQt::dumpView
957   Dumps the contents of the currently active view to the image file 
958   in the given format (JPEG, PNG, BMP are supported)
959 */
960 class TDumpViewEvent: public SALOME_Event {
961 public:
962   typedef bool TResult;
963   TResult myResult;
964   QString myFileName;
965   TDumpViewEvent( const QString& filename ) 
966     : myResult ( false ), myFileName( filename ) {}
967   virtual void Execute() {
968     if ( SalomeApp_Application* anApp = getApplication() ) {
969       SUIT_ViewManager* vm = anApp->activeViewManager();
970       if ( vm ) { 
971         SUIT_ViewWindow* vw = vm->getActiveView();
972         if ( vw ) {
973           QImage im = vw->dumpView();
974           if ( !im.isNull() && !myFileName.isEmpty() ) {
975             QString fmt = SUIT_Tools::extension( myFileName ).upper();
976             if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
977             if ( fmt == "JPG" )  fmt = "JPEG";
978             myResult = im.save( myFileName, fmt.latin1() );
979           }
980         }
981       }
982     }
983   }
984 };
985
986 /*!
987   Dumps the contents of the currently active view to the image file 
988   in the given format (JPEG, PNG, BMP are supported)
989 */
990 bool SalomePyQt::dumpView( const QString& filename )
991 {
992   return ProcessEvent( new TDumpViewEvent( filename ) );
993 }
994
995 /*!
996   SalomePyQt::defaultMenuGroup
997   Returns default menu group
998 */
999 class TDefMenuGroupEvent: public SALOME_Event {
1000 public:
1001   typedef int TResult;
1002   TResult myResult;
1003   TDefMenuGroupEvent() : myResult( -1 ) {}
1004   virtual void Execute() {
1005     myResult = SALOME_PYQT_Module::defaultMenuGroup();
1006   }
1007 };
1008
1009 /*!
1010   \return default menu group
1011 */
1012 int SalomePyQt::defaultMenuGroup()
1013 {
1014   return ProcessEvent( new TDefMenuGroupEvent() );
1015 }
1016
1017 /*!
1018   SalomePyQt::createTool
1019   These methods allow operating with the toolbars:
1020   - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
1021     this method returns an id of the toolbar;
1022   - add action with given id (must be created previously) and optional index to the existing toolbar
1023     (toobar is identified either by its id or by its name)
1024     these methods return an id of the action.
1025   If error occurs, the -1 value is returned.
1026 */
1027 class CrTool
1028 {
1029 public:
1030   CrTool( const QString& tBar ) 
1031     : myCase( 0 ), myTbName( tBar ) {}
1032   CrTool( const int id, const int tBar, const int idx ) 
1033     : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1034   CrTool( const int id, const QString& tBar, const int idx )
1035     : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1036   CrTool( QtxAction* action, const int tbId, const int id, const int idx )
1037     : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1038   CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
1039     : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1040
1041   int execute( SALOME_PYQT_Module* module ) const
1042   {
1043     if ( module ) {
1044       switch ( myCase ) {
1045       case 0:
1046         return module->createTool( myTbName );
1047       case 1:
1048         return module->createTool( myId, myTbId, myIndex );
1049       case 2:
1050         return module->createTool( myId, myTbName, myIndex );
1051       case 3:
1052         return module->createTool( myAction, myTbId, myId, myIndex );
1053       case 4:
1054         return module->createTool( myAction, myTbName, myId, myIndex );
1055       }
1056     }
1057     return -1;
1058   }
1059 private:
1060    int        myCase;
1061    QString    myTbName;
1062    int        myTbId;
1063    QtxAction* myAction;
1064    int        myId;
1065    int        myIndex;
1066 };
1067 class TCreateToolEvent: public SALOME_Event {
1068 public:
1069   typedef int TResult;
1070   TResult myResult;
1071   const CrTool& myCrTool;
1072   TCreateToolEvent( const CrTool& crTool ) 
1073     : myResult( -1 ), myCrTool( crTool ) {}
1074   virtual void Execute() {
1075     if ( SalomeApp_Application* anApp = getApplication() ) {
1076       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1077       if ( !module )
1078         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1079       myResult = myCrTool.execute( module );
1080     }
1081   }
1082 };
1083
1084 /*!
1085   create new toolbar or get existing by name 
1086 */
1087 int SalomePyQt::createTool( const QString& tBar )
1088 {
1089   return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1090 }
1091 /*! add action with id and index to the existing tollbar
1092 */
1093 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1094 {
1095   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1096 }
1097 /*! add action with id and index to the existing tollbar
1098 */
1099 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1100 {
1101   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1102 }
1103 /*! add action with id and index to the existing tollbar
1104 */
1105 int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
1106 {
1107   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1108 }
1109 /*! add action with id and index to the existing tollbar
1110 */
1111 int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
1112 {
1113   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1114 }
1115
1116 /*!
1117   SalomePyQt::createMenu
1118   These methods allow operating with the main menu:
1119   - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter, 
1120     if it is empty or -1, it means that main menu is created, otherwise submenu is created);
1121     this method returns an id of the menu/submenu;
1122   - add action with given id (must be created previously) and optional index and group number to the existing menu
1123     or submenu (menu name or id us passed as parameter)
1124     these methods return an id of the action.
1125   If error occurs, the -1 value is returned.
1126 */
1127 class CrMenu
1128 {
1129 public:
1130   CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) 
1131     : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1132   CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) 
1133     : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1134   CrMenu( const int id, const int menu, const int group, const int idx ) 
1135     : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1136   CrMenu( const int id, const QString& menu, const int group, const int idx ) 
1137     : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1138   CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx ) 
1139     : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1140   CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx ) 
1141     : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1142
1143   int execute( SALOME_PYQT_Module* module ) const
1144   {
1145     if ( module ) {
1146       switch ( myCase ) {
1147       case 0:
1148         return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1149       case 1:
1150         return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1151       case 2:
1152         return module->createMenu( myId, myMenuId, myGroup, myIndex );
1153       case 3:
1154         return module->createMenu( myId, myMenuName, myGroup, myIndex );
1155       case 4:
1156         return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1157       case 5:
1158         return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1159       }
1160     }
1161     return -1;
1162   }
1163 private:
1164    int        myCase;
1165    QString    myMenuName;
1166    int        myMenuId;
1167    QString    mySubMenuName;
1168    int        myGroup;
1169    QtxAction* myAction;
1170    int        myId;
1171    int        myIndex;
1172 };
1173 class TCreateMenuEvent: public SALOME_Event {
1174 public:
1175   typedef int TResult;
1176   TResult myResult;
1177   const CrMenu& myCrMenu;
1178   TCreateMenuEvent( const CrMenu& crMenu ) 
1179     : myResult( -1 ), myCrMenu( crMenu ) {}
1180   virtual void Execute() {
1181     if ( SalomeApp_Application* anApp = getApplication() ) {
1182       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1183       if ( !module )
1184         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1185       myResult = myCrMenu.execute( module );
1186     }
1187   }
1188 };
1189 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1190 {
1191   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1192 }
1193
1194 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1195 {
1196   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1197 }
1198
1199 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1200 {
1201   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1202 }
1203
1204 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1205 {
1206   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1207 }
1208
1209 int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
1210 {
1211   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1212 }
1213
1214 int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
1215 {
1216   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1217 }
1218
1219 /*!
1220   SalomePyQt::createSeparator
1221   Create a separator action which can be then used in the menu or toolbar.
1222 */
1223 class TCreateSepEvent: public SALOME_Event {
1224 public:
1225   typedef QtxAction* TResult;
1226   TResult myResult;
1227   TCreateSepEvent() 
1228     : myResult( 0 ) {}
1229   virtual void Execute() {
1230     if ( SalomeApp_Application* anApp = getApplication() ) {
1231       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1232       if ( !module )
1233         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1234       if ( module )
1235         myResult = (QtxAction*)module->createSeparator();
1236     }
1237   }
1238 };
1239 QtxAction* SalomePyQt::createSeparator()
1240 {
1241   return ProcessEvent( new TCreateSepEvent() );
1242 }
1243
1244 /*!
1245   SalomePyQt::createAction
1246   Create an action which can be then used in the menu or toolbar:
1247   - id         : the unique id action to be registered to;
1248   - menuText   : action text which should appear in menu;
1249   - tipText    : text which should appear in the tooltip;
1250   - statusText : text which should appear in the status bar when action is activated;
1251   - icon       : the name of the icon file (the actual icon file name can be coded in the translation files);
1252   - key        : the key accelrator for the action
1253   - toggle     : if true the action is checkable
1254 */
1255 class TCreateActionEvent: public SALOME_Event {
1256 public:
1257   typedef QtxAction* TResult;
1258   TResult myResult;
1259   int     myId;
1260   QString myMenuText;
1261   QString myTipText;
1262   QString myStatusText;
1263   QString myIcon;
1264   int     myKey;
1265   bool    myToggle;
1266   TCreateActionEvent( const int id, const QString& menuText, const QString& tipText, 
1267                       const QString& statusText, const QString& icon, const int key, const bool toggle ) 
1268     : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1269       myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1270   virtual void Execute() {
1271     if ( SalomeApp_Application* anApp = getApplication() ) {
1272       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1273       if ( !module )
1274         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1275       if ( module )
1276         myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1277     }
1278   }
1279 };
1280 QtxAction* SalomePyQt::createAction( const int id,           const QString& menuText, 
1281                                      const QString& tipText, const QString& statusText, 
1282                                      const QString& icon,    const int key, const bool toggle )
1283 {
1284   return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1285 }
1286
1287 /*!
1288   SalomePyQt::action
1289   Get an action by its id. Returns 0 if the action with such id was not registered.
1290 */
1291 class TActionEvent: public SALOME_Event {
1292 public:
1293   typedef QtxAction* TResult;
1294   TResult myResult;
1295   int     myId;
1296   TActionEvent( const int id )
1297     : myResult( 0 ), myId( id ) {}
1298   virtual void Execute() {
1299     if ( SalomeApp_Application* anApp = getApplication() ) {
1300       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1301       if ( !module )
1302         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1303       if ( module )
1304         myResult = (QtxAction*)module->action( myId );
1305     }
1306   }
1307 };
1308 QtxAction* SalomePyQt::action( const int id )
1309 {
1310   return ProcessEvent( new TActionEvent( id ) );
1311 }
1312
1313 /*!
1314   SalomePyQt::actionId
1315   Get an action id. Returns -1 if the action was not registered.
1316 */
1317 class TActionIdEvent: public SALOME_Event {
1318 public:
1319   typedef  int TResult;
1320   TResult  myResult;
1321   const QtxAction* myAction;
1322   TActionIdEvent( const QtxAction* action )
1323     : myResult( -1 ), myAction( action ) {}
1324   virtual void Execute() {
1325     if ( SalomeApp_Application* anApp = getApplication() ) {
1326       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1327       if ( !module )
1328         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1329       if ( module )
1330         myResult = module->actionId( myAction );
1331     }
1332   }
1333 };
1334 int SalomePyQt::actionId( const QtxAction* a )
1335 {
1336   return ProcessEvent( new TActionIdEvent( a ) );
1337 }
1338
1339 /*!
1340   SalomePyQt::clearMenu
1341   Clears given menu (recursively if necessary)
1342 */
1343 class TClearMenuEvent: public SALOME_Event {
1344 public:
1345   typedef  bool TResult;
1346   TResult  myResult;
1347   int      myId;
1348   int      myMenu;
1349   bool     myRemoveActions;
1350   TClearMenuEvent( const int id, const int menu, const bool removeActions )
1351     : myResult( false ), myId( id ), myMenu( menu ), myRemoveActions( removeActions ) {}
1352   virtual void Execute() {
1353     if ( SalomeApp_Application* anApp = getApplication() ) {
1354       SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1355       if ( !module )
1356         module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1357       if ( module )
1358         myResult = module->clearMenu( myId, myMenu, myRemoveActions );
1359     }
1360   }
1361 };
1362 bool SalomePyQt::clearMenu( const int id, const int menu, const bool removeActions )
1363 {
1364   return ProcessEvent( new TClearMenuEvent( id, menu, removeActions ) );
1365 }
1366