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/
20 #include "SALOME_PYQT_Module.h" // this include must be first!!!
21 #include "SalomePyQt.h"
23 #include <qapplication.h>
26 #include <qpopupmenu.h>
28 #include <qstringlist.h>
30 #include "SALOME_Event.hxx"
32 #include "SUIT_Session.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Tools.h"
36 #include "STD_MDIDesktop.h"
37 #include "SalomeApp_Application.h"
38 #include "SalomeApp_Study.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "OB_Browser.h"
41 #include "QtxAction.h"
46 \return active application object [ static ]
48 static SalomeApp_Application* getApplication() {
49 if ( SUIT_Session::session() )
50 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
55 \return active study or 0 if there is no study opened [ static ]
57 static SalomeApp_Study* getActiveStudy()
59 if ( getApplication() )
60 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
64 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
67 Creates or finds the selection object (one per study).
69 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
71 SALOME_Selection* sel = 0;
72 if ( app && SelMap.find( app ) != SelMap.end() )
75 sel = SelMap[ app ] = new SALOME_Selection( app );
80 Selection constructor.
82 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
84 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
86 mySelMgr = app->selectionMgr();
87 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
88 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
92 Selection destructor. Removes selection object from the map.
94 SALOME_Selection::~SALOME_Selection()
96 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
97 if ( app && SelMap.find( app ) != SelMap.end() )
102 Watches for the selection manager destroying when study is closed.
104 void SALOME_Selection::onSelMgrDestroyed()
110 Clears the selection.
112 void SALOME_Selection::Clear()
114 class TEvent: public SALOME_Event {
115 LightApp_SelectionMgr* mySelMgr;
117 TEvent( LightApp_SelectionMgr* selMgr )
118 : mySelMgr( selMgr ) {}
119 virtual void Execute() {
121 mySelMgr->clearSelected();
124 ProcessVoidEvent( new TEvent( mySelMgr ) );
128 Clears the selection.
130 void SALOME_Selection::ClearIObjects()
136 Removes all selection filters.
138 void SALOME_Selection::ClearFilters()
140 class TEvent: public SALOME_Event {
141 LightApp_SelectionMgr* mySelMgr;
143 TEvent( LightApp_SelectionMgr* selMgr )
144 : mySelMgr( selMgr ) {}
145 virtual void Execute() {
147 mySelMgr->clearFilters();
150 ProcessVoidEvent( new TEvent( mySelMgr ) );
154 \return desktop (0 if error)
156 class TGetDesktopEvent: public SALOME_Event {
158 typedef QWidget* TResult;
160 TGetDesktopEvent() : myResult( 0 ) {}
161 virtual void Execute() {
162 if ( getApplication() )
163 myResult = (QWidget*)( getApplication()->desktop() );
170 QWidget* SalomePyQt::getDesktop()
172 return ProcessEvent( new TGetDesktopEvent() );
176 \return workspace widget (0 if error)
178 class TGetMainFrameEvent: public SALOME_Event {
180 typedef QWidget* TResult;
182 TGetMainFrameEvent() : myResult( 0 ) {}
183 virtual void Execute() {
184 if ( getApplication() ) {
185 SUIT_Desktop* aDesktop = getApplication()->desktop();
186 myResult = (QWidget*)( aDesktop->centralWidget() );
192 \return workspace widget (0 if error)
194 QWidget* SalomePyQt::getMainFrame()
196 return ProcessEvent( new TGetMainFrameEvent() );
200 SalomePyQt::getMainMenuBar
201 Gets main menu. Returns 0 in error.
203 class TGetMainMenuBarEvent: public SALOME_Event {
205 typedef QMenuBar* TResult;
207 TGetMainMenuBarEvent() : myResult( 0 ) {}
208 virtual void Execute() {
209 if ( SalomeApp_Application* anApp = getApplication() ) {
210 myResult = anApp->desktop()->menuBar();
219 QMenuBar* SalomePyQt::getMainMenuBar()
221 return ProcessEvent( new TGetMainMenuBarEvent() );
225 SalomePyQt::getPopupMenu
226 Gets an main menu's child popup menu by its id
228 class TGetPopupMenuEvent: public SALOME_Event {
230 typedef QPopupMenu* TResult;
233 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
234 virtual void Execute() {
235 if ( SalomeApp_Application* anApp = getApplication() ) {
236 QMenuBar* menuBar = anApp->desktop()->menuBar();
239 switch( myMenuName) {
241 menu = QObject::tr( "MEN_DESK_FILE" ); break;
243 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
245 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
247 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
249 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
251 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
253 menu = QObject::tr( "MEN_DESK_HELP" ); break;
255 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
256 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
257 if ( item && item->text() == menu && item->popup() )
258 myResult = item->popup();
267 \param menu - menu name
269 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
271 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
275 SalomePyQt::getStudyId
276 Returns active study's ID or 0 if there is no active study.
278 class TGetStudyIdEvent: public SALOME_Event {
282 TGetStudyIdEvent() : myResult( 0 ) {}
283 virtual void Execute() {
284 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
285 myResult = aStudy->studyDS()->StudyId();
291 SalomePyQt::getStudyId
292 Returns active study's ID or 0 if there is no active study.
294 int SalomePyQt::getStudyId()
296 return ProcessEvent( new TGetStudyIdEvent() );
300 SalomePyQt::getSelection
301 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
303 class TGetSelectionEvent: public SALOME_Event {
305 typedef SALOME_Selection* TResult;
307 TGetSelectionEvent() : myResult( 0 ) {}
308 virtual void Execute() {
309 myResult = SALOME_Selection::GetSelection( getApplication() );
314 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
315 \return just created selection object
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 );
340 Puts an information message to the desktop's status bar
341 (with optional delay parameter given in seconds)
342 \param msg - message text
343 \param sec - delay in seconds
345 void SalomePyQt::putInfo( const QString& msg, const int sec )
347 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
351 SalomePyQt::getActiveComponent
352 Returns an active component name or empty string if there is no active component
354 class TGetActiveComponentEvent: public SALOME_Event {
356 typedef QString TResult;
358 TGetActiveComponentEvent() {}
359 virtual void Execute() {
360 if ( SalomeApp_Application* anApp = getApplication() ) {
361 if ( CAM_Module* mod = anApp->activeModule() ) {
362 myResult = mod->name("");
369 \return an active component name or empty string if there is no active component
371 const QString SalomePyQt::getActiveComponent()
373 return ProcessEvent( new TGetActiveComponentEvent() );
377 SalomePyQt::updateObjBrowser
378 Updates an Object Browser of a given study.
379 If <studyId> <= 0 the active study's object browser is updated.
380 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
382 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
384 class TEvent: public SALOME_Event {
386 bool myUpdateSelection;
388 TEvent( const int studyId, bool updateSelection )
389 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
390 virtual void Execute() {
391 if ( SUIT_Session::session() ) {
392 if ( getActiveStudy() && myStudyId <= 0 )
393 myStudyId = getActiveStudy()->id();
394 if ( myStudyId > 0 ) {
395 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
396 QPtrListIterator<SUIT_Application> it( apps );
397 for( ; it.current(); ++it ) {
398 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
399 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
400 anApp->updateObjectBrowser();
406 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
409 const char* DEFAULT_SECTION = "SalomePyQt";
412 SalomePyQt::addStringSetting
413 Adds a string setting to the application preferences
414 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
415 This function is obsolete. Use addSetting() instead.
417 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
419 class TEvent: public SALOME_Event {
424 TEvent( const QString& name, const QString& value, bool autoValue )
425 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
426 virtual void Execute() {
427 if ( SUIT_Session::session() ) {
428 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
429 QStringList sl = QStringList::split( ":", myName );
430 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
431 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
432 if ( !_sec.isEmpty() && !_nam.isEmpty() )
433 resMgr->setValue( _sec, _nam, myValue );
437 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
441 SalomePyQt::addIntSetting
442 Adds an integer setting to the application preferences
443 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
444 This function is obsolete. Use addSetting() instead.
446 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
448 class TEvent: public SALOME_Event {
453 TEvent( const QString& name, const int value, bool autoValue )
454 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
455 virtual void Execute() {
456 if ( SUIT_Session::session() ) {
457 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
458 QStringList sl = QStringList::split( ":", myName );
459 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
460 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
461 if ( !_sec.isEmpty() && !_nam.isEmpty() )
462 resMgr->setValue( _sec, _nam, myValue );
466 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
470 SalomePyQt::addDoubleSetting
471 Adds an double setting to the application preferences
472 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
473 This function is obsolete. Use addSetting() instead.
475 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
477 class TEvent: public SALOME_Event {
482 TEvent( const QString& name, const double value, bool autoValue )
483 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
484 virtual void Execute() {
485 if ( SUIT_Session::session() ) {
486 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
487 QStringList sl = QStringList::split( ":", myName );
488 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
489 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
490 if ( !_sec.isEmpty() && !_nam.isEmpty() )
491 resMgr->setValue( _sec, _nam, myValue );
495 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
499 SalomePyQt::removeSettings
500 Removes a setting from the application preferences
501 This function is obsolete. Use removeSetting() instead.
503 void SalomePyQt::removeSettings( const QString& name )
505 class TEvent: public SALOME_Event {
508 TEvent( const QString& name ) : myName( name ) {}
509 virtual void Execute() {
510 if ( SUIT_Session::session() ) {
511 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
512 QStringList sl = QStringList::split( ":", myName );
513 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
514 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
515 if ( !_sec.isEmpty() && !_nam.isEmpty() )
516 resMgr->remove( _sec, _nam );
520 ProcessVoidEvent( new TEvent( name ) );
524 SalomePyQt::getSetting
525 Gets a setting value (as string)
526 This function is obsolete. Use stringSetting(), integerSetting(),
527 boolSetting(), stringSetting() or colorSetting() instead.
529 class TGetSettingEvent: public SALOME_Event {
531 typedef QString TResult;
534 TGetSettingEvent( const QString& name ) : myName( name ) {}
535 virtual void Execute() {
536 if ( SUIT_Session::session() ) {
537 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
538 QStringList sl = QStringList::split( ":", myName );
539 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
540 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
541 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
547 \return a setting value (as string)
548 This function is obsolete. Use stringSetting(), integerSetting(),
549 boolSetting(), stringSetting() or colorSetting() instead.
551 QString SalomePyQt::getSetting( const QString& name )
553 return ProcessEvent( new TGetSettingEvent( name ) );
557 SalomePyQt::addSetting
558 Adds a double setting to the application preferences
560 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
562 class TEvent: public SALOME_Event {
567 TEvent( const QString& section, const QString& name, double value )
568 : mySection( section ), myName( name ), myValue( value ) {}
569 virtual void Execute() {
570 if ( SUIT_Session::session() ) {
571 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
572 if ( !mySection.isEmpty() && !myName.isEmpty() )
573 resMgr->setValue( mySection, myName, myValue );
577 ProcessVoidEvent( new TEvent( section, name, value ) );
581 SalomePyQt::addSetting
582 Adds an integer setting to the application preferences
584 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
586 class TEvent: public SALOME_Event {
591 TEvent( const QString& section, const QString& name, int value )
592 : mySection( section ), myName( name ), myValue( value ) {}
593 virtual void Execute() {
594 if ( SUIT_Session::session() ) {
595 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
596 if ( !mySection.isEmpty() && !myName.isEmpty() )
597 resMgr->setValue( mySection, myName, myValue );
601 ProcessVoidEvent( new TEvent( section, name, value ) );
605 SalomePyQt::addSetting
606 Adds a string setting to the application preferences
608 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
610 class TEvent: public SALOME_Event {
615 TEvent( const QString& section, const QString& name, const QString& value )
616 : mySection( section ), myName( name ), myValue( value ) {}
617 virtual void Execute() {
618 if ( SUIT_Session::session() ) {
619 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
620 if ( !mySection.isEmpty() && !myName.isEmpty() )
621 resMgr->setValue( mySection, myName, myValue );
625 ProcessVoidEvent( new TEvent( section, name, value ) );
629 SalomePyQt::addSetting
630 Adds a color setting to the application preferences
632 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
634 class TEvent: public SALOME_Event {
639 TEvent( const QString& section, const QString& name, const QColor& value )
640 : mySection( section ), myName( name ), myValue( value ) {}
641 virtual void Execute() {
642 if ( SUIT_Session::session() ) {
643 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
644 if ( !mySection.isEmpty() && !myName.isEmpty() )
645 resMgr->setValue( mySection, myName, myValue );
649 ProcessVoidEvent( new TEvent( section, name, value ) );
653 SalomePyQt::integerSetting
654 Gets an integer setting from the application preferences
656 class TGetIntSettingEvent: public SALOME_Event {
663 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
664 : mySection( section ), myName( name ), myDefault( def ) {}
665 virtual void Execute() {
666 if ( SUIT_Session::session() ) {
667 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
668 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
674 \return an integer setting from the application preferences
676 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
678 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
682 SalomePyQt::doubleSetting
683 Gets a double setting from the application preferences
685 class TGetDblSettingEvent: public SALOME_Event {
687 typedef double TResult;
692 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
693 : mySection( section ), myName( name ), myDefault( def ) {}
694 virtual void Execute() {
695 if ( SUIT_Session::session() ) {
696 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
697 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
703 \return an double setting from the application preferences
705 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
707 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
711 SalomePyQt::boolSetting
712 Gets a boolean setting from the application preferences
714 class TGetBoolSettingEvent: public SALOME_Event {
716 typedef bool TResult;
721 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
722 : mySection( section ), myName( name ), myDefault( def ) {}
723 virtual void Execute() {
724 if ( SUIT_Session::session() ) {
725 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
726 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
732 \return an boolean setting from the application preferences
734 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
736 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
740 SalomePyQt::stringSetting
741 Gets a string setting from the application preferences
743 class TGetStrSettingEvent: public SALOME_Event {
745 typedef QString TResult;
750 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
751 : mySection( section ), myName( name ), myDefault( def ) {}
752 virtual void Execute() {
753 if ( SUIT_Session::session() ) {
754 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
755 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
761 \return an string setting from the application preferences
763 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
765 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
769 SalomePyQt::colorSetting
770 Gets a color setting from the application preferences
772 class TGetColorSettingEvent: public SALOME_Event {
774 typedef QColor TResult;
779 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
780 : mySection( section ), myName( name ), myDefault( def ) {}
781 virtual void Execute() {
782 if ( SUIT_Session::session() ) {
783 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
784 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
790 \return a color setting from the application preferences
792 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
794 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
798 SalomePyQt::removeSetting
799 Removes a setting from the application preferences
801 void SalomePyQt::removeSetting( const QString& section, const QString& name )
803 class TEvent: public SALOME_Event {
807 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
808 virtual void Execute() {
809 if ( SUIT_Session::session() ) {
810 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
811 if ( !mySection.isEmpty() && !myName.isEmpty() )
812 resMgr->remove( mySection, myName );
816 ProcessVoidEvent( new TEvent( section, name ) );
820 SalomePyQt::getFileName
821 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
823 class TGetFileNameEvent: public SALOME_Event {
825 typedef QString TResult;
829 QStringList myFilters;
832 TGetFileNameEvent( QWidget* parent,
833 const QString& initial,
834 const QStringList& filters,
835 const QString& caption,
837 : myParent ( parent ),
838 myInitial( initial ),
839 myFilters( filters ),
840 myCaption( caption ),
842 virtual void Execute() {
843 if ( SalomeApp_Application* anApp = getApplication() ) {
844 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
850 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
852 QString SalomePyQt::getFileName( QWidget* parent,
853 const QString& initial,
854 const QStringList& filters,
855 const QString& caption,
858 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
862 SalomePyQt::getOpenFileNames
863 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
865 class TGetOpenFileNamesEvent: public SALOME_Event {
867 typedef QStringList TResult;
871 QStringList myFilters;
873 TGetOpenFileNamesEvent( QWidget* parent,
874 const QString& initial,
875 const QStringList& filters,
876 const QString& caption )
877 : myParent ( parent ),
878 myInitial( initial ),
879 myFilters( filters ),
880 myCaption( caption ) {}
881 virtual void Execute() {
882 if ( SalomeApp_Application* anApp = getApplication() ) {
883 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
889 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
891 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
892 const QString& initial,
893 const QStringList& filters,
894 const QString& caption )
896 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
900 SalomePyQt::getExistingDirectory
901 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
903 class TGetExistingDirectoryEvent: public SALOME_Event {
905 typedef QString TResult;
910 TGetExistingDirectoryEvent( QWidget* parent,
911 const QString& initial,
912 const QString& caption )
913 : myParent ( parent ),
914 myInitial( initial ),
915 myCaption( caption ) {}
916 virtual void Execute() {
917 if ( SalomeApp_Application* anApp = getApplication() ) {
918 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
924 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
926 QString SalomePyQt::getExistingDirectory( QWidget* parent,
927 const QString& initial,
928 const QString& caption )
930 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
934 SalomePyQt::helpContext
935 Opens external browser to display 'context help' information
936 current implementation does nothing.
938 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
939 class TEvent: public SALOME_Event {
943 TEvent( const QString& source, const QString& context )
944 : mySource( source ), myContext( context ) {}
945 virtual void Execute() {
946 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
948 // anApp->helpContext( mySource, myContext );
952 ProcessVoidEvent( new TEvent( source, context ) );
957 Dumps the contents of the currently active view to the image file
958 in the given format (JPEG, PNG, BMP are supported)
960 class TDumpViewEvent: public SALOME_Event {
962 typedef bool TResult;
965 TDumpViewEvent( const QString& filename )
966 : myResult ( false ), myFileName( filename ) {}
967 virtual void Execute() {
968 if ( SalomeApp_Application* anApp = getApplication() ) {
969 SUIT_ViewManager* vm = anApp->activeViewManager();
971 SUIT_ViewWindow* vw = vm->getActiveView();
973 QImage im = vw->dumpView();
974 if ( !im.isNull() && !myFileName.isEmpty() ) {
975 QString fmt = SUIT_Tools::extension( myFileName ).upper();
976 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
977 if ( fmt == "JPG" ) fmt = "JPEG";
978 myResult = im.save( myFileName, fmt.latin1() );
987 Dumps the contents of the currently active view to the image file
988 in the given format (JPEG, PNG, BMP are supported)
990 bool SalomePyQt::dumpView( const QString& filename )
992 return ProcessEvent( new TDumpViewEvent( filename ) );
996 SalomePyQt::defaultMenuGroup
997 Returns default menu group
999 class TDefMenuGroupEvent: public SALOME_Event {
1001 typedef int TResult;
1003 TDefMenuGroupEvent() : myResult( -1 ) {}
1004 virtual void Execute() {
1005 myResult = SALOME_PYQT_Module::defaultMenuGroup();
1010 \return default menu group
1012 int SalomePyQt::defaultMenuGroup()
1014 return ProcessEvent( new TDefMenuGroupEvent() );
1018 SalomePyQt::createTool
1019 These methods allow operating with the toolbars:
1020 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
1021 this method returns an id of the toolbar;
1022 - add action with given id (must be created previously) and optional index to the existing toolbar
1023 (toobar is identified either by its id or by its name)
1024 these methods return an id of the action.
1025 If error occurs, the -1 value is returned.
1030 CrTool( const QString& tBar )
1031 : myCase( 0 ), myTbName( tBar ) {}
1032 CrTool( const int id, const int tBar, const int idx )
1033 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1034 CrTool( const int id, const QString& tBar, const int idx )
1035 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1036 CrTool( QtxAction* action, const int tbId, const int id, const int idx )
1037 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1038 CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
1039 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1041 int execute( SALOME_PYQT_Module* module ) const
1046 return module->createTool( myTbName );
1048 return module->createTool( myId, myTbId, myIndex );
1050 return module->createTool( myId, myTbName, myIndex );
1052 return module->createTool( myAction, myTbId, myId, myIndex );
1054 return module->createTool( myAction, myTbName, myId, myIndex );
1063 QtxAction* myAction;
1067 class TCreateToolEvent: public SALOME_Event {
1069 typedef int TResult;
1071 const CrTool& myCrTool;
1072 TCreateToolEvent( const CrTool& crTool )
1073 : myResult( -1 ), myCrTool( crTool ) {}
1074 virtual void Execute() {
1075 if ( SalomeApp_Application* anApp = getApplication() ) {
1076 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1078 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1079 myResult = myCrTool.execute( module );
1085 create new toolbar or get existing by name
1087 int SalomePyQt::createTool( const QString& tBar )
1089 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1091 /*! add action with id and index to the existing tollbar
1093 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1095 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1097 /*! add action with id and index to the existing tollbar
1099 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1101 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1103 /*! add action with id and index to the existing tollbar
1105 int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
1107 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1109 /*! add action with id and index to the existing tollbar
1111 int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
1113 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1117 SalomePyQt::createMenu
1118 These methods allow operating with the main menu:
1119 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
1120 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
1121 this method returns an id of the menu/submenu;
1122 - add action with given id (must be created previously) and optional index and group number to the existing menu
1123 or submenu (menu name or id us passed as parameter)
1124 these methods return an id of the action.
1125 If error occurs, the -1 value is returned.
1130 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1131 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1132 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1133 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1134 CrMenu( const int id, const int menu, const int group, const int idx )
1135 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1136 CrMenu( const int id, const QString& menu, const int group, const int idx )
1137 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1138 CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx )
1139 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1140 CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx )
1141 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1143 int execute( SALOME_PYQT_Module* module ) const
1148 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1150 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1152 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1154 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1156 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1158 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1167 QString mySubMenuName;
1169 QtxAction* myAction;
1173 class TCreateMenuEvent: public SALOME_Event {
1175 typedef int TResult;
1177 const CrMenu& myCrMenu;
1178 TCreateMenuEvent( const CrMenu& crMenu )
1179 : myResult( -1 ), myCrMenu( crMenu ) {}
1180 virtual void Execute() {
1181 if ( SalomeApp_Application* anApp = getApplication() ) {
1182 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1184 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1185 myResult = myCrMenu.execute( module );
1189 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1191 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1194 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1196 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1199 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1201 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1204 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1206 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1209 int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
1211 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1214 int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
1216 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1220 SalomePyQt::createSeparator
1221 Create a separator action which can be then used in the menu or toolbar.
1223 class TCreateSepEvent: public SALOME_Event {
1225 typedef QtxAction* TResult;
1229 virtual void Execute() {
1230 if ( SalomeApp_Application* anApp = getApplication() ) {
1231 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1233 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1235 myResult = (QtxAction*)module->createSeparator();
1239 QtxAction* SalomePyQt::createSeparator()
1241 return ProcessEvent( new TCreateSepEvent() );
1245 SalomePyQt::createAction
1246 Create an action which can be then used in the menu or toolbar:
1247 - id : the unique id action to be registered to;
1248 - menuText : action text which should appear in menu;
1249 - tipText : text which should appear in the tooltip;
1250 - statusText : text which should appear in the status bar when action is activated;
1251 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1252 - key : the key accelrator for the action
1253 - toggle : if true the action is checkable
1255 class TCreateActionEvent: public SALOME_Event {
1257 typedef QtxAction* TResult;
1262 QString myStatusText;
1266 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1267 const QString& statusText, const QString& icon, const int key, const bool toggle )
1268 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1269 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1270 virtual void Execute() {
1271 if ( SalomeApp_Application* anApp = getApplication() ) {
1272 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1274 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1276 myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1280 QtxAction* SalomePyQt::createAction( const int id, const QString& menuText,
1281 const QString& tipText, const QString& statusText,
1282 const QString& icon, const int key, const bool toggle )
1284 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1289 Get an action by its id. Returns 0 if the action with such id was not registered.
1291 class TActionEvent: public SALOME_Event {
1293 typedef QtxAction* TResult;
1296 TActionEvent( const int id )
1297 : myResult( 0 ), myId( id ) {}
1298 virtual void Execute() {
1299 if ( SalomeApp_Application* anApp = getApplication() ) {
1300 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1302 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1304 myResult = (QtxAction*)module->action( myId );
1308 QtxAction* SalomePyQt::action( const int id )
1310 return ProcessEvent( new TActionEvent( id ) );
1314 SalomePyQt::actionId
1315 Get an action id. Returns -1 if the action was not registered.
1317 class TActionIdEvent: public SALOME_Event {
1319 typedef int TResult;
1321 const QtxAction* myAction;
1322 TActionIdEvent( const QtxAction* action )
1323 : myResult( -1 ), myAction( action ) {}
1324 virtual void Execute() {
1325 if ( SalomeApp_Application* anApp = getApplication() ) {
1326 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1328 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1330 myResult = module->actionId( myAction );
1334 int SalomePyQt::actionId( const QtxAction* a )
1336 return ProcessEvent( new TActionIdEvent( a ) );
1340 SalomePyQt::clearMenu
1341 Clears given menu (recursively if necessary)
1343 class TClearMenuEvent: public SALOME_Event {
1345 typedef bool TResult;
1349 bool myRemoveActions;
1350 TClearMenuEvent( const int id, const int menu, const bool removeActions )
1351 : myResult( false ), myId( id ), myMenu( menu ), myRemoveActions( removeActions ) {}
1352 virtual void Execute() {
1353 if ( SalomeApp_Application* anApp = getApplication() ) {
1354 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1356 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1358 myResult = module->clearMenu( myId, myMenu, myRemoveActions );
1362 bool SalomePyQt::clearMenu( const int id, const int menu, const bool removeActions )
1364 return ProcessEvent( new TClearMenuEvent( id, menu, removeActions ) );