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