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>
36 #include <qstringlist.h>
38 #include "SALOME_Event.hxx"
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"
53 //====================================================================================
55 //====================================================================================
58 Returns active application object [ static ]
60 static SalomeApp_Application* getApplication() {
61 if ( SUIT_Session::session() )
62 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
68 Gets active study or 0 if there is no study opened [ static ]
70 static SalomeApp_Study* getActiveStudy()
72 if ( getApplication() )
73 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
77 //====================================================================================
78 // SALOME_Selection class.
79 //====================================================================================
80 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
83 SALOME_Selection::GetSelection
84 Creates or finds the selection object (one per study).
86 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
88 SALOME_Selection* sel = 0;
89 if ( app && SelMap.find( app ) != SelMap.end() )
92 sel = SelMap[ app ] = new SALOME_Selection( app );
97 SALOME_Selection::SALOME_Selection
98 Selection constructor.
100 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
102 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
104 mySelMgr = app->selectionMgr();
105 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
106 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
110 SALOME_Selection::~SALOME_Selection
111 Selection destructor. Removes selection object from the map.
113 SALOME_Selection::~SALOME_Selection()
115 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
116 if ( app && SelMap.find( app ) != SelMap.end() )
117 SelMap.remove( app );
121 SALOME_Selection::onSelMgrDestroyed
122 Watches for the selection manager destroying when study is closed.
124 void SALOME_Selection::onSelMgrDestroyed()
130 SALOME_Selection::Clear
131 Clears the selection.
133 void SALOME_Selection::Clear()
135 class TEvent: public SALOME_Event {
136 LightApp_SelectionMgr* mySelMgr;
138 TEvent( LightApp_SelectionMgr* selMgr )
139 : mySelMgr( selMgr ) {}
140 virtual void Execute() {
142 mySelMgr->clearSelected();
145 ProcessVoidEvent( new TEvent( mySelMgr ) );
149 SALOME_Selection::ClearIObjects
150 Clears the selection.
152 void SALOME_Selection::ClearIObjects()
158 SALOME_Selection::ClearFilters
159 Removes all selection filters.
161 void SALOME_Selection::ClearFilters()
163 class TEvent: public SALOME_Event {
164 LightApp_SelectionMgr* mySelMgr;
166 TEvent( LightApp_SelectionMgr* selMgr )
167 : mySelMgr( selMgr ) {}
168 virtual void Execute() {
170 mySelMgr->clearFilters();
173 ProcessVoidEvent( new TEvent( mySelMgr ) );
176 //====================================================================================
178 //====================================================================================
181 SalomePyQt::getDesktop
182 Gets desktop. Returns 0 in error.
184 class TGetDesktopEvent: public SALOME_Event {
186 typedef QWidget* TResult;
188 TGetDesktopEvent() : myResult( 0 ) {}
189 virtual void Execute() {
190 if ( getApplication() )
191 myResult = (QWidget*)( getApplication()->desktop() );
194 QWidget* SalomePyQt::getDesktop()
196 return ProcessEvent( new TGetDesktopEvent() );
200 SalomePyQt::getMainFrame
201 Gets workspace widget. Returns 0 in error.
203 class TGetMainFrameEvent: public SALOME_Event {
205 typedef QWidget* TResult;
207 TGetMainFrameEvent() : myResult( 0 ) {}
208 virtual void Execute() {
209 if ( getApplication() ) {
210 SUIT_Desktop* aDesktop = getApplication()->desktop();
211 myResult = (QWidget*)( aDesktop->centralWidget() );
215 QWidget* SalomePyQt::getMainFrame()
217 return ProcessEvent( new TGetMainFrameEvent() );
221 SalomePyQt::getMainMenuBar
222 Gets main menu. Returns 0 in error.
224 class TGetMainMenuBarEvent: public SALOME_Event {
226 typedef QMenuBar* TResult;
228 TGetMainMenuBarEvent() : myResult( 0 ) {}
229 virtual void Execute() {
230 if ( SalomeApp_Application* anApp = getApplication() ) {
231 myResult = anApp->desktop()->menuBar();
235 QMenuBar* SalomePyQt::getMainMenuBar()
237 return ProcessEvent( new TGetMainMenuBarEvent() );
241 SalomePyQt::getPopupMenu
242 Gets an main menu's child popup menu by its id
244 class TGetPopupMenuEvent: public SALOME_Event {
246 typedef QPopupMenu* TResult;
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();
255 switch( myMenuName) {
257 menu = QObject::tr( "MEN_DESK_FILE" ); break;
259 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
261 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
263 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
265 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
267 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
269 menu = QObject::tr( "MEN_DESK_HELP" ); break;
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();
280 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
282 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
286 SalomePyQt::getStudyId
287 Returns active study's ID or 0 if there is no active study.
289 class TGetStudyIdEvent: public SALOME_Event {
293 TGetStudyIdEvent() : myResult( 0 ) {}
294 virtual void Execute() {
295 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
296 myResult = aStudy->studyDS()->StudyId();
300 int SalomePyQt::getStudyId()
302 return ProcessEvent( new TGetStudyIdEvent() );
306 SalomePyQt::getSelection
307 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
309 class TGetSelectionEvent: public SALOME_Event {
311 typedef SALOME_Selection* TResult;
313 TGetSelectionEvent() : myResult( 0 ) {}
314 virtual void Execute() {
315 myResult = SALOME_Selection::GetSelection( getApplication() );
318 SALOME_Selection* SalomePyQt::getSelection()
320 return ProcessEvent( new TGetSelectionEvent() );
325 Puts an information message to the desktop's status bar
326 (with optional delay parameter given in seconds)
328 class TPutInfoEvent: public SALOME_Event {
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 );
339 void SalomePyQt::putInfo( const QString& msg, const int sec )
341 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
345 SalomePyQt::getActiveComponent
346 Returns an active component name or empty string if there is no active component
348 class TGetActiveComponentEvent: public SALOME_Event {
350 typedef QString TResult;
352 TGetActiveComponentEvent() {}
353 virtual void Execute() {
354 if ( SalomeApp_Application* anApp = getApplication() ) {
355 if ( CAM_Module* mod = anApp->activeModule() ) {
356 myResult = mod->name("");
361 const QString SalomePyQt::getActiveComponent()
363 return ProcessEvent( new TGetActiveComponentEvent() );
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.
372 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
374 class TEvent: public SALOME_Event {
376 bool myUpdateSelection;
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();
396 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
399 const char* DEFAULT_SECTION = "SalomePyQt";
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.
407 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
409 class TEvent: public SALOME_Event {
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 );
427 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
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.
436 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
438 class TEvent: public SALOME_Event {
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 );
456 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
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.
465 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
467 class TEvent: public SALOME_Event {
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 );
485 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
489 SalomePyQt::removeSettings
490 Removes a setting from the application preferences
491 This function is obsolete. Use removeSetting() instead.
493 void SalomePyQt::removeSettings( const QString& name )
495 class TEvent: public SALOME_Event {
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 );
510 ProcessVoidEvent( new TEvent( name ) );
514 SalomePyQt::getSetting
515 Gets a setting value (as string)
516 This function is obsolete. Use stringSetting(), integerSetting(),
517 boolSetting(), stringSetting() or colorSetting() instead.
519 class TGetSettingEvent: public SALOME_Event {
521 typedef QString TResult;
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( "" );
535 QString SalomePyQt::getSetting( const QString& name )
537 return ProcessEvent( new TGetSettingEvent( name ) );
541 SalomePyQt::addSetting
542 Adds a double setting to the application preferences
544 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
546 class TEvent: public SALOME_Event {
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 );
561 ProcessVoidEvent( new TEvent( section, name, value ) );
565 SalomePyQt::addSetting
566 Adds an integer setting to the application preferences
568 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
570 class TEvent: public SALOME_Event {
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 );
585 ProcessVoidEvent( new TEvent( section, name, value ) );
589 SalomePyQt::addSetting
590 Adds a string setting to the application preferences
592 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
594 class TEvent: public SALOME_Event {
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 );
609 ProcessVoidEvent( new TEvent( section, name, value ) );
613 SalomePyQt::addSetting
614 Adds a color setting to the application preferences
616 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
618 class TEvent: public SALOME_Event {
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 );
633 ProcessVoidEvent( new TEvent( section, name, value ) );
637 SalomePyQt::integerSetting
638 Gets an integer setting from the application preferences
640 class TGetIntSettingEvent: public SALOME_Event {
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;
656 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
658 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
662 SalomePyQt::doubleSetting
663 Gets a double setting from the application preferences
665 class TGetDblSettingEvent: public SALOME_Event {
667 typedef double TResult;
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;
681 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
683 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
687 SalomePyQt::boolSetting
688 Gets a boolean setting from the application preferences
690 class TGetBoolSettingEvent: public SALOME_Event {
692 typedef bool TResult;
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;
706 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
708 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
712 SalomePyQt::stringSetting
713 Gets a string setting from the application preferences
715 class TGetStrSettingEvent: public SALOME_Event {
717 typedef QString TResult;
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;
731 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
733 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
737 SalomePyQt::colorSetting
738 Gets a color setting from the application preferences
740 class TGetColorSettingEvent: public SALOME_Event {
742 typedef QColor TResult;
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;
756 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
758 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
762 SalomePyQt::removeSetting
763 Removes a setting from the application preferences
765 void SalomePyQt::removeSetting( const QString& section, const QString& name )
767 class TEvent: public SALOME_Event {
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 );
780 ProcessVoidEvent( new TEvent( section, name ) );
784 SalomePyQt::getFileName
785 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
787 class TGetFileNameEvent: public SALOME_Event {
789 typedef QString TResult;
793 QStringList myFilters;
796 TGetFileNameEvent( QWidget* parent,
797 const QString& initial,
798 const QStringList& filters,
799 const QString& caption,
801 : myParent ( parent ),
802 myInitial( initial ),
803 myFilters( filters ),
804 myCaption( caption ),
806 virtual void Execute() {
807 if ( SalomeApp_Application* anApp = getApplication() ) {
808 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
812 QString SalomePyQt::getFileName( QWidget* parent,
813 const QString& initial,
814 const QStringList& filters,
815 const QString& caption,
818 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
822 SalomePyQt::getOpenFileNames
823 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
825 class TGetOpenFileNamesEvent: public SALOME_Event {
827 typedef QStringList TResult;
831 QStringList myFilters;
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 );
847 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
848 const QString& initial,
849 const QStringList& filters,
850 const QString& caption )
852 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
856 SalomePyQt::getExistingDirectory
857 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
859 class TGetExistingDirectoryEvent: public SALOME_Event {
861 typedef QString TResult;
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 );
878 QString SalomePyQt::getExistingDirectory( QWidget* parent,
879 const QString& initial,
880 const QString& caption )
882 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
886 SalomePyQt::helpContext
887 Opens external browser to display 'context help' information
888 current implementation does nothing.
890 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
891 class TEvent: public SALOME_Event {
895 TEvent( const QString& source, const QString& context )
896 : mySource( source ), myContext( context ) {}
897 virtual void Execute() {
898 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
900 // anApp->helpContext( mySource, myContext );
904 ProcessVoidEvent( new TEvent( source, context ) );
909 Dumps the contents of the currently active view to the image file
910 in the given format (JPEG, PNG, BMP are supported)
912 class TDumpViewEvent: public SALOME_Event {
914 typedef bool TResult;
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();
923 SUIT_ViewWindow* vw = vm->getActiveView();
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() );
937 bool SalomePyQt::dumpView( const QString& filename )
939 return ProcessEvent( new TDumpViewEvent( filename ) );
943 SalomePyQt::createTool
944 These methods allow operating with the toolbars:
945 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
946 this method returns an id of the toolbar;
947 - add action with given id (must be created previously) and optional index to the existing toolbar
948 (toobar is identified either by its id or by its name)
949 these methods return an id of the action.
950 If error occurs, the -1 value is returned.
955 CrTool( const QString& tBar )
956 : myCase( 0 ), myTbName( tBar ) {}
957 CrTool( const int id, const int tBar, const int idx )
958 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
959 CrTool( const int id, const QString& tBar, const int idx )
960 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
961 CrTool( QtxAction* action, const int tbId, const int id, const int idx )
962 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
963 CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
964 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
966 int execute( SALOME_PYQT_Module* module ) const
971 return module->createTool( myTbName );
973 return module->createTool( myId, myTbId, myIndex );
975 return module->createTool( myId, myTbName, myIndex );
977 return module->createTool( myAction, myTbId, myId, myIndex );
979 return module->createTool( myAction, myTbName, myId, myIndex );
992 class TCreateToolEvent: public SALOME_Event {
996 const CrTool& myCrTool;
997 TCreateToolEvent( const CrTool& crTool )
998 : myResult( -1 ), myCrTool( crTool ) {}
999 virtual void Execute() {
1000 if ( SalomeApp_Application* anApp = getApplication() ) {
1001 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1003 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1004 myResult = myCrTool.execute( module );
1008 // create new toolbar or get existing by name
1009 int SalomePyQt::createTool( const QString& tBar )
1011 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1013 // add action with id and index to the existing tollbar
1014 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1016 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1018 // add action with id and index to the existing tollbar
1019 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1021 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1023 // add action with id and index to the existing tollbar
1024 int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
1026 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1028 // add action with id and index to the existing tollbar
1029 int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
1031 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1035 SalomePyQt::createMenu
1036 These methods allow operating with the main menu:
1037 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
1038 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
1039 this method returns an id of the menu/submenu;
1040 - add action with given id (must be created previously) and optional index and group number to the existing menu
1041 or submenu (menu name or id us passed as parameter)
1042 these methods return an id of the action.
1043 If error occurs, the -1 value is returned.
1048 CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
1049 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1050 CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1051 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1052 CrMenu( const int id, const int menu, const int group, const int idx )
1053 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1054 CrMenu( const int id, const QString& menu, const int group, const int idx )
1055 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1056 CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx )
1057 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1058 CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx )
1059 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1061 int execute( SALOME_PYQT_Module* module ) const
1066 return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
1068 return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
1070 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1072 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1074 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1076 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1085 QString mySubMenuName;
1087 QtxAction* myAction;
1091 class TCreateMenuEvent: public SALOME_Event {
1093 typedef int TResult;
1095 const CrMenu& myCrMenu;
1096 TCreateMenuEvent( const CrMenu& crMenu )
1097 : myResult( -1 ), myCrMenu( crMenu ) {}
1098 virtual void Execute() {
1099 if ( SalomeApp_Application* anApp = getApplication() ) {
1100 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1102 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1103 myResult = myCrMenu.execute( module );
1107 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
1109 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1112 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1114 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1117 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1119 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1122 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1124 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1127 int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
1129 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1132 int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
1134 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1138 SalomePyQt::createSeparator
1139 Create a separator action which can be then used in the menu or toolbar.
1141 class TCreateSepEvent: public SALOME_Event {
1143 typedef QtxAction* TResult;
1147 virtual void Execute() {
1148 if ( SalomeApp_Application* anApp = getApplication() ) {
1149 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1151 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1153 myResult = (QtxAction*)module->createSeparator();
1157 QtxAction* SalomePyQt::createSeparator()
1159 return ProcessEvent( new TCreateSepEvent() );
1163 SalomePyQt::createAction
1164 Create an action which can be then used in the menu or toolbar:
1165 - id : the unique id action to be registered to;
1166 - menuText : action text which should appear in menu;
1167 - tipText : text which should appear in the tooltip;
1168 - statusText : text which should appear in the status bar when action is activated;
1169 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1170 - key : the key accelrator for the action
1171 - toggle : if true the action is checkable
1173 class TCreateActionEvent: public SALOME_Event {
1175 typedef QtxAction* TResult;
1180 QString myStatusText;
1184 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1185 const QString& statusText, const QString& icon, const int key, const bool toggle )
1186 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1187 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1188 virtual void Execute() {
1189 if ( SalomeApp_Application* anApp = getApplication() ) {
1190 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1192 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1194 myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1198 QtxAction* SalomePyQt::createAction( const int id, const QString& menuText,
1199 const QString& tipText, const QString& statusText,
1200 const QString& icon, const int key, const bool toggle )
1202 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1207 Get an action by its id. Returns 0 if the action with such id was not registered.
1209 class TActionEvent: public SALOME_Event {
1211 typedef QtxAction* TResult;
1214 TActionEvent( const int id )
1215 : myResult( 0 ), myId( id ) {}
1216 virtual void Execute() {
1217 if ( SalomeApp_Application* anApp = getApplication() ) {
1218 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1220 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1222 myResult = (QtxAction*)module->action( myId );
1226 QtxAction* SalomePyQt::action( const int id )
1228 return ProcessEvent( new TActionEvent( id ) );
1232 SalomePyQt::actionId
1233 Get an action id. Returns -1 if the action was not registered.
1235 class TActionIdEvent: public SALOME_Event {
1237 typedef int TResult;
1239 const QtxAction* myAction;
1240 TActionIdEvent( const QtxAction* action )
1241 : myResult( -1 ), myAction( action ) {}
1242 virtual void Execute() {
1243 if ( SalomeApp_Application* anApp = getApplication() ) {
1244 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1246 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1248 myResult = module->actionId( myAction );
1252 int SalomePyQt::actionId( const QtxAction* a )
1254 return ProcessEvent( new TActionIdEvent( a ) );