1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 //=============================================================================
20 // File : SalomePyQt.cxx
22 // Author : Vadim SANDLER
24 // Copyright : 2003-2005 CEA/DEN, EDF R&D
26 //=============================================================================
28 #include "SALOME_PYQT_Module.h" // this include must be first!!!
29 #include "SalomePyQt.h"
31 #include <qapplication.h>
34 #include <qpopupmenu.h>
35 #include <qstringlist.h>
37 #include "SALOME_Event.hxx"
39 #include "SUIT_Session.h"
40 #include "SUIT_Desktop.h"
41 #include "SUIT_ResourceMgr.h"
42 #include "SUIT_Tools.h"
43 #include "STD_MDIDesktop.h"
44 #include "SalomeApp_Application.h"
45 #include "SalomeApp_Study.h"
46 #include "LightApp_SelectionMgr.h"
47 #include "OB_Browser.h"
48 #include "QtxAction.h"
52 //====================================================================================
54 //====================================================================================
57 Returns active application object [ static ]
59 static SalomeApp_Application* getApplication() {
60 if ( SUIT_Session::session() )
61 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
67 Gets active study or 0 if there is no study opened [ static ]
69 static SalomeApp_Study* getActiveStudy()
71 if ( getApplication() )
72 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
76 //====================================================================================
77 // SALOME_Selection class.
78 //====================================================================================
79 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
82 SALOME_Selection::GetSelection
83 Creates or finds the selection object (one per study).
85 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
87 SALOME_Selection* sel = 0;
88 if ( app && SelMap.find( app ) != SelMap.end() )
91 sel = SelMap[ app ] = new SALOME_Selection( app );
96 SALOME_Selection::SALOME_Selection
97 Selection constructor.
99 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
101 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
103 mySelMgr = app->selectionMgr();
104 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
105 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
109 SALOME_Selection::~SALOME_Selection
110 Selection destructor. Removes selection object from the map.
112 SALOME_Selection::~SALOME_Selection()
114 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
115 if ( app && SelMap.find( app ) != SelMap.end() )
116 SelMap.remove( app );
120 SALOME_Selection::onSelMgrDestroyed
121 Watches for the selection manager destroying when study is closed.
123 void SALOME_Selection::onSelMgrDestroyed()
129 SALOME_Selection::Clear
130 Clears the selection.
132 void SALOME_Selection::Clear()
134 class TEvent: public SALOME_Event {
135 LightApp_SelectionMgr* mySelMgr;
137 TEvent( LightApp_SelectionMgr* selMgr )
138 : mySelMgr( selMgr ) {}
139 virtual void Execute() {
141 mySelMgr->clearSelected();
144 ProcessVoidEvent( new TEvent( mySelMgr ) );
148 SALOME_Selection::ClearIObjects
149 Clears the selection.
151 void SALOME_Selection::ClearIObjects()
157 SALOME_Selection::ClearFilters
158 Removes all selection filters.
160 void SALOME_Selection::ClearFilters()
162 class TEvent: public SALOME_Event {
163 LightApp_SelectionMgr* mySelMgr;
165 TEvent( LightApp_SelectionMgr* selMgr )
166 : mySelMgr( selMgr ) {}
167 virtual void Execute() {
169 mySelMgr->clearFilters();
172 ProcessVoidEvent( new TEvent( mySelMgr ) );
175 //====================================================================================
177 //====================================================================================
180 SalomePyQt::getDesktop
181 Gets desktop. Returns 0 in error.
183 class TGetDesktopEvent: public SALOME_Event {
185 typedef QWidget* TResult;
187 TGetDesktopEvent() : myResult( 0 ) {}
188 virtual void Execute() {
189 if ( getApplication() )
190 myResult = (QWidget*)( getApplication()->desktop() );
193 QWidget* SalomePyQt::getDesktop()
195 return ProcessEvent( new TGetDesktopEvent() );
199 SalomePyQt::getMainFrame
200 Gets workspace widget. Returns 0 in error.
202 class TGetMainFrameEvent: public SALOME_Event {
204 typedef QWidget* TResult;
206 TGetMainFrameEvent() : myResult( 0 ) {}
207 virtual void Execute() {
208 if ( getApplication() ) {
209 SUIT_Desktop* aDesktop = getApplication()->desktop();
210 myResult = (QWidget*)( aDesktop->centralWidget() );
214 QWidget* SalomePyQt::getMainFrame()
216 return ProcessEvent( new TGetMainFrameEvent() );
220 SalomePyQt::getMainMenuBar
221 Gets main menu. Returns 0 in error.
223 class TGetMainMenuBarEvent: public SALOME_Event {
225 typedef QMenuBar* TResult;
227 TGetMainMenuBarEvent() : myResult( 0 ) {}
228 virtual void Execute() {
229 if ( SalomeApp_Application* anApp = getApplication() ) {
230 myResult = anApp->desktop()->menuBar();
234 QMenuBar* SalomePyQt::getMainMenuBar()
236 return ProcessEvent( new TGetMainMenuBarEvent() );
240 SalomePyQt::getPopupMenu
241 Gets an main menu's child popup menu by its id
243 class TGetPopupMenuEvent: public SALOME_Event {
245 typedef QPopupMenu* TResult;
248 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
249 virtual void Execute() {
250 if ( SalomeApp_Application* anApp = getApplication() ) {
251 QMenuBar* menuBar = anApp->desktop()->menuBar();
254 switch( myMenuName) {
256 menu = QObject::tr( "MEN_DESK_FILE" ); break;
258 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
260 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
262 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
264 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
266 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
268 menu = QObject::tr( "MEN_DESK_HELP" ); break;
270 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
271 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
272 if ( item && item->text() == menu && item->popup() )
273 myResult = item->popup();
279 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
281 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
285 SalomePyQt::getStudyId
286 Returns active study's ID or 0 if there is no active study.
288 class TGetStudyIdEvent: public SALOME_Event {
292 TGetStudyIdEvent() : myResult( 0 ) {}
293 virtual void Execute() {
294 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
295 myResult = aStudy->studyDS()->StudyId();
299 int SalomePyQt::getStudyId()
301 return ProcessEvent( new TGetStudyIdEvent() );
305 SalomePyQt::getSelection
306 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
308 class TGetSelectionEvent: public SALOME_Event {
310 typedef SALOME_Selection* TResult;
312 TGetSelectionEvent() : myResult( 0 ) {}
313 virtual void Execute() {
314 myResult = SALOME_Selection::GetSelection( getApplication() );
317 SALOME_Selection* SalomePyQt::getSelection()
319 return ProcessEvent( new TGetSelectionEvent() );
324 Puts an information message to the desktop's status bar
325 (with optional delay parameter given in seconds)
327 class TPutInfoEvent: public SALOME_Event {
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 );
338 void SalomePyQt::putInfo( const QString& msg, const int sec )
340 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
344 SalomePyQt::getActiveComponent
345 Returns an active component name or empty string if there is no active component
347 class TGetActiveComponentEvent: public SALOME_Event {
349 typedef QString TResult;
351 TGetActiveComponentEvent() {}
352 virtual void Execute() {
353 if ( SalomeApp_Application* anApp = getApplication() ) {
354 if ( CAM_Module* mod = anApp->activeModule() ) {
355 myResult = mod->name("");
360 const QString SalomePyQt::getActiveComponent()
362 return ProcessEvent( new TGetActiveComponentEvent() );
366 SalomePyQt::updateObjBrowser
367 Updates an Object Browser of a given study.
368 If <studyId> <= 0 the active study's object browser is updated.
369 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
371 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
373 class TEvent: public SALOME_Event {
375 bool myUpdateSelection;
377 TEvent( const int studyId, bool updateSelection )
378 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
379 virtual void Execute() {
380 if ( SUIT_Session::session() ) {
381 if ( getActiveStudy() && myStudyId <= 0 )
382 myStudyId = getActiveStudy()->id();
383 if ( myStudyId > 0 ) {
384 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
385 QPtrListIterator<SUIT_Application> it( apps );
386 for( ; it.current(); ++it ) {
387 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
388 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
389 anApp->updateObjectBrowser();
395 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
398 const char* DEFAULT_SECTION = "SalomePyQt";
401 SalomePyQt::addStringSetting
402 Adds a string setting to the application preferences
403 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
404 This function is obsolete. Use addSetting() instead.
406 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
408 class TEvent: public SALOME_Event {
413 TEvent( const QString& name, const QString& value, bool autoValue )
414 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
415 virtual void Execute() {
416 if ( SUIT_Session::session() ) {
417 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
418 QStringList sl = QStringList::split( ":", myName );
419 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
420 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
421 if ( !_sec.isEmpty() && !_nam.isEmpty() )
422 resMgr->setValue( _sec, _nam, myValue );
426 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
430 SalomePyQt::addIntSetting
431 Adds an integer setting to the application preferences
432 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
433 This function is obsolete. Use addSetting() instead.
435 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
437 class TEvent: public SALOME_Event {
442 TEvent( const QString& name, const int value, bool autoValue )
443 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
444 virtual void Execute() {
445 if ( SUIT_Session::session() ) {
446 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
447 QStringList sl = QStringList::split( ":", myName );
448 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
449 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
450 if ( !_sec.isEmpty() && !_nam.isEmpty() )
451 resMgr->setValue( _sec, _nam, myValue );
455 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
459 SalomePyQt::addDoubleSetting
460 Adds an double setting to the application preferences
461 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
462 This function is obsolete. Use addSetting() instead.
464 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
466 class TEvent: public SALOME_Event {
471 TEvent( const QString& name, const double value, bool autoValue )
472 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
473 virtual void Execute() {
474 if ( SUIT_Session::session() ) {
475 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
476 QStringList sl = QStringList::split( ":", myName );
477 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
478 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
479 if ( !_sec.isEmpty() && !_nam.isEmpty() )
480 resMgr->setValue( _sec, _nam, myValue );
484 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
488 SalomePyQt::removeSettings
489 Removes a setting from the application preferences
490 This function is obsolete. Use removeSetting() instead.
492 void SalomePyQt::removeSettings( const QString& name )
494 class TEvent: public SALOME_Event {
497 TEvent( const QString& name ) : myName( name ) {}
498 virtual void Execute() {
499 if ( SUIT_Session::session() ) {
500 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
501 QStringList sl = QStringList::split( ":", myName );
502 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
503 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
504 if ( !_sec.isEmpty() && !_nam.isEmpty() )
505 resMgr->remove( _sec, _nam );
509 ProcessVoidEvent( new TEvent( name ) );
513 SalomePyQt::getSetting
514 Gets a setting value (as string)
515 This function is obsolete. Use stringSetting(), integerSetting(),
516 boolSetting(), stringSetting() or colorSetting() instead.
518 class TGetSettingEvent: public SALOME_Event {
520 typedef QString TResult;
523 TGetSettingEvent( const QString& name ) : myName( name ) {}
524 virtual void Execute() {
525 if ( SUIT_Session::session() ) {
526 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
527 QStringList sl = QStringList::split( ":", myName );
528 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
529 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
530 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
534 QString SalomePyQt::getSetting( const QString& name )
536 return ProcessEvent( new TGetSettingEvent( name ) );
540 SalomePyQt::addSetting
541 Adds a double setting to the application preferences
543 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
545 class TEvent: public SALOME_Event {
550 TEvent( const QString& section, const QString& name, double value )
551 : mySection( section ), myName( name ), myValue( value ) {}
552 virtual void Execute() {
553 if ( SUIT_Session::session() ) {
554 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
555 if ( !mySection.isEmpty() && !myName.isEmpty() )
556 resMgr->setValue( mySection, myName, myValue );
560 ProcessVoidEvent( new TEvent( section, name, value ) );
564 SalomePyQt::addSetting
565 Adds an integer setting to the application preferences
567 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
569 class TEvent: public SALOME_Event {
574 TEvent( const QString& section, const QString& name, int value )
575 : mySection( section ), myName( name ), myValue( value ) {}
576 virtual void Execute() {
577 if ( SUIT_Session::session() ) {
578 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
579 if ( !mySection.isEmpty() && !myName.isEmpty() )
580 resMgr->setValue( mySection, myName, myValue );
584 ProcessVoidEvent( new TEvent( section, name, value ) );
588 SalomePyQt::addSetting
589 Adds a string setting to the application preferences
591 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
593 class TEvent: public SALOME_Event {
598 TEvent( const QString& section, const QString& name, const QString& value )
599 : mySection( section ), myName( name ), myValue( value ) {}
600 virtual void Execute() {
601 if ( SUIT_Session::session() ) {
602 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
603 if ( !mySection.isEmpty() && !myName.isEmpty() )
604 resMgr->setValue( mySection, myName, myValue );
608 ProcessVoidEvent( new TEvent( section, name, value ) );
612 SalomePyQt::addSetting
613 Adds a color setting to the application preferences
615 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
617 class TEvent: public SALOME_Event {
622 TEvent( const QString& section, const QString& name, const QColor& value )
623 : mySection( section ), myName( name ), myValue( value ) {}
624 virtual void Execute() {
625 if ( SUIT_Session::session() ) {
626 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
627 if ( !mySection.isEmpty() && !myName.isEmpty() )
628 resMgr->setValue( mySection, myName, myValue );
632 ProcessVoidEvent( new TEvent( section, name, value ) );
636 SalomePyQt::integerSetting
637 Gets an integer setting from the application preferences
639 class TGetIntSettingEvent: public SALOME_Event {
646 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
647 : mySection( section ), myName( name ), myDefault( def ) {}
648 virtual void Execute() {
649 if ( SUIT_Session::session() ) {
650 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
651 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
655 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
657 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
661 SalomePyQt::doubleSetting
662 Gets a double setting from the application preferences
664 class TGetDblSettingEvent: public SALOME_Event {
666 typedef double TResult;
671 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
672 : mySection( section ), myName( name ), myDefault( def ) {}
673 virtual void Execute() {
674 if ( SUIT_Session::session() ) {
675 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
676 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
680 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
682 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
686 SalomePyQt::boolSetting
687 Gets a boolean setting from the application preferences
689 class TGetBoolSettingEvent: public SALOME_Event {
691 typedef bool TResult;
696 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
697 : mySection( section ), myName( name ), myDefault( def ) {}
698 virtual void Execute() {
699 if ( SUIT_Session::session() ) {
700 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
701 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
705 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
707 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
711 SalomePyQt::stringSetting
712 Gets a string setting from the application preferences
714 class TGetStrSettingEvent: public SALOME_Event {
716 typedef QString TResult;
721 TGetStrSettingEvent( const QString& section, const QString& name, const QString& 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->stringValue( mySection, myName, myDefault ) : myDefault;
730 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
732 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
736 SalomePyQt::colorSetting
737 Gets a color setting from the application preferences
739 class TGetColorSettingEvent: public SALOME_Event {
741 typedef QColor TResult;
746 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
747 : mySection( section ), myName( name ), myDefault( def ) {}
748 virtual void Execute() {
749 if ( SUIT_Session::session() ) {
750 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
751 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
755 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
757 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
761 SalomePyQt::removeSetting
762 Removes a setting from the application preferences
764 void SalomePyQt::removeSetting( const QString& section, const QString& name )
766 class TEvent: public SALOME_Event {
770 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
771 virtual void Execute() {
772 if ( SUIT_Session::session() ) {
773 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
774 if ( !mySection.isEmpty() && !myName.isEmpty() )
775 resMgr->remove( mySection, myName );
779 ProcessVoidEvent( new TEvent( section, name ) );
783 SalomePyQt::getFileName
784 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
786 class TGetFileNameEvent: public SALOME_Event {
788 typedef QString TResult;
792 QStringList myFilters;
795 TGetFileNameEvent( QWidget* parent,
796 const QString& initial,
797 const QStringList& filters,
798 const QString& caption,
800 : myParent ( parent ),
801 myInitial( initial ),
802 myFilters( filters ),
803 myCaption( caption ),
805 virtual void Execute() {
806 if ( SalomeApp_Application* anApp = getApplication() ) {
807 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
811 QString SalomePyQt::getFileName( QWidget* parent,
812 const QString& initial,
813 const QStringList& filters,
814 const QString& caption,
817 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
821 SalomePyQt::getOpenFileNames
822 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
824 class TGetOpenFileNamesEvent: public SALOME_Event {
826 typedef QStringList TResult;
830 QStringList myFilters;
832 TGetOpenFileNamesEvent( QWidget* parent,
833 const QString& initial,
834 const QStringList& filters,
835 const QString& caption )
836 : myParent ( parent ),
837 myInitial( initial ),
838 myFilters( filters ),
839 myCaption( caption ) {}
840 virtual void Execute() {
841 if ( SalomeApp_Application* anApp = getApplication() ) {
842 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
846 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
847 const QString& initial,
848 const QStringList& filters,
849 const QString& caption )
851 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
855 SalomePyQt::getExistingDirectory
856 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
858 class TGetExistingDirectoryEvent: public SALOME_Event {
860 typedef QString TResult;
865 TGetExistingDirectoryEvent( QWidget* parent,
866 const QString& initial,
867 const QString& caption )
868 : myParent ( parent ),
869 myInitial( initial ),
870 myCaption( caption ) {}
871 virtual void Execute() {
872 if ( SalomeApp_Application* anApp = getApplication() ) {
873 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
877 QString SalomePyQt::getExistingDirectory( QWidget* parent,
878 const QString& initial,
879 const QString& caption )
881 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
885 SalomePyQt::helpContext
886 Opens external browser to display 'context help' information
887 current implementation does nothing.
889 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
890 class TEvent: public SALOME_Event {
894 TEvent( const QString& source, const QString& context )
895 : mySource( source ), myContext( context ) {}
896 virtual void Execute() {
897 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
899 // anApp->helpContext( mySource, myContext );
903 ProcessVoidEvent( new TEvent( source, context ) );
908 Dumps the contents of the currently active view to the image file
909 in the given format (JPEG, PNG, BMP are supported)
911 class TDumpViewEvent: public SALOME_Event {
913 typedef bool TResult;
916 TDumpViewEvent( const QString& filename )
917 : myResult ( false ), myFileName( filename ) {}
918 virtual void Execute() {
919 if ( SalomeApp_Application* anApp = getApplication() ) {
920 SUIT_ViewManager* vm = anApp->activeViewManager();
922 SUIT_ViewWindow* vw = vm->getActiveView();
924 QImage im = vw->dumpView();
925 if ( !im.isNull() && !myFileName.isEmpty() ) {
926 QString fmt = SUIT_Tools::extension( myFileName ).upper();
927 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
928 if ( fmt == "JPG" ) fmt = "JPEG";
929 myResult = im.save( myFileName, fmt.latin1() );
936 bool SalomePyQt::dumpView( const QString& filename )
938 return ProcessEvent( new TDumpViewEvent( filename ) );
942 SalomePyQt::createTool
943 These methods allow operating with the toolbars:
944 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
945 this method returns an id of the toolbar;
946 - add action with given id (must be created previously) and optional index to the existing toolbar
947 (toobar is identified either by its id or by its name)
948 these methods return an id of the action.
949 If error occurs, the -1 value is returned.
954 CrTool( const QString& tBar )
955 : myCase( 0 ), myTbName( tBar ) {}
956 CrTool( const int id, const int tBar, const int idx )
957 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
958 CrTool( const int id, const QString& tBar, const int idx )
959 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
960 CrTool( QtxAction* action, const int tbId, const int id, const int idx )
961 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
962 CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
963 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
965 int execute( SALOME_PYQT_Module* module ) const
970 return module->createTool( myTbName );
972 return module->createTool( myId, myTbId, myIndex );
974 return module->createTool( myId, myTbName, myIndex );
976 return module->createTool( myAction, myTbId, myId, myIndex );
978 return module->createTool( myAction, myTbName, myId, myIndex );
991 class TCreateToolEvent: public SALOME_Event {
995 const CrTool& myCrTool;
996 TCreateToolEvent( const CrTool& crTool )
997 : myResult( -1 ), myCrTool( crTool ) {}
998 virtual void Execute() {
999 if ( SalomeApp_Application* anApp = getApplication() ) {
1000 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1002 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1003 myResult = myCrTool.execute( module );
1007 // create new toolbar or get existing by name
1008 int SalomePyQt::createTool( const QString& tBar )
1010 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1012 // add action with id and index to the existing tollbar
1013 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1015 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1017 // add action with id and index to the existing tollbar
1018 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1020 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1022 // add action with id and index to the existing tollbar
1023 int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
1025 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1027 // add action with id and index to the existing tollbar
1028 int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
1030 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1034 SalomePyQt::createMenu
1035 These methods allow operating with the main menu:
1036 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
1037 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
1038 this method returns an id of the menu/submenu;
1039 - add action with given id (must be created previously) and optional index and group number to the existing menu
1040 or submenu (menu name or id us passed as parameter)
1041 these methods return an id of the action.
1042 If error occurs, the -1 value is returned.
1047 CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
1048 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1049 CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1050 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1051 CrMenu( const int id, const int menu, const int group, const int idx )
1052 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1053 CrMenu( const int id, const QString& menu, const int group, const int idx )
1054 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1055 CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx )
1056 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1057 CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx )
1058 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1060 int execute( SALOME_PYQT_Module* module ) const
1065 return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
1067 return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
1069 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1071 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1073 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1075 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1084 QString mySubMenuName;
1086 QtxAction* myAction;
1090 class TCreateMenuEvent: public SALOME_Event {
1092 typedef int TResult;
1094 const CrMenu& myCrMenu;
1095 TCreateMenuEvent( const CrMenu& crMenu )
1096 : myResult( -1 ), myCrMenu( crMenu ) {}
1097 virtual void Execute() {
1098 if ( SalomeApp_Application* anApp = getApplication() ) {
1099 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1101 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1102 myResult = myCrMenu.execute( module );
1106 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
1108 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1111 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1113 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1116 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1118 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1121 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1123 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1126 int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
1128 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1131 int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
1133 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1137 SalomePyQt::createSeparator
1138 Create a separator action which can be then used in the menu or toolbar.
1140 class TCreateSepEvent: public SALOME_Event {
1142 typedef QtxAction* TResult;
1146 virtual void Execute() {
1147 if ( SalomeApp_Application* anApp = getApplication() ) {
1148 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1150 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1152 myResult = (QtxAction*)module->createSeparator();
1156 QtxAction* SalomePyQt::createSeparator()
1158 return ProcessEvent( new TCreateSepEvent() );
1162 SalomePyQt::createAction
1163 Create an action which can be then used in the menu or toolbar:
1164 - id : the unique id action to be registered to;
1165 - menuText : action text which should appear in menu;
1166 - tipText : text which should appear in the tooltip;
1167 - statusText : text which should appear in the status bar when action is activated;
1168 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1169 - key : the key accelrator for the action
1170 - toggle : if true the action is checkable
1172 class TCreateActionEvent: public SALOME_Event {
1174 typedef QtxAction* TResult;
1179 QString myStatusText;
1183 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1184 const QString& statusText, const QString& icon, const int key, const bool toggle )
1185 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1186 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1187 virtual void Execute() {
1188 if ( SalomeApp_Application* anApp = getApplication() ) {
1189 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1191 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1193 myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1197 QtxAction* SalomePyQt::createAction( const int id, const QString& menuText,
1198 const QString& tipText, const QString& statusText,
1199 const QString& icon, const int key, const bool toggle )
1201 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1206 Get an action by its id. Returns 0 if the action with such id was not registered.
1208 class TActionEvent: public SALOME_Event {
1210 typedef QtxAction* TResult;
1213 TActionEvent( const int id )
1214 : myResult( 0 ), myId( id ) {}
1215 virtual void Execute() {
1216 if ( SalomeApp_Application* anApp = getApplication() ) {
1217 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1219 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1221 myResult = (QtxAction*)module->action( myId );
1225 QtxAction* SalomePyQt::action( const int id )
1227 return ProcessEvent( new TActionEvent( id ) );
1231 SalomePyQt::actionId
1232 Get an action id. Returns -1 if the action was not registered.
1234 class TActionIdEvent: public SALOME_Event {
1236 typedef int TResult;
1238 const QtxAction* myAction;
1239 TActionIdEvent( const QtxAction* action )
1240 : myResult( -1 ), myAction( action ) {}
1241 virtual void Execute() {
1242 if ( SalomeApp_Application* anApp = getApplication() ) {
1243 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1245 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1247 myResult = module->actionId( myAction );
1251 int SalomePyQt::actionId( const QtxAction* a )
1253 return ProcessEvent( new TActionIdEvent( a ) );