1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SalomePyQt.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include <SALOME_PYQT_Module.h> // this include must be first!!!
26 #include "SalomePyQt.h"
28 #include <QApplication>
32 #include <QStringList>
35 #include <SALOME_Event.h>
37 #include <QtxActionMenuMgr.h>
38 #include <QtxActionGroup.h>
39 #include <QtxWorkstack.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_ViewWindow.h>
46 #include <STD_TabDesktop.h>
47 #include <SalomeApp_Application.h>
48 #include <SalomeApp_Study.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LogWindow.h>
51 #include <OCCViewer_ViewWindow.h>
52 #include <Plot2d_ViewManager.h>
53 #include <Plot2d_ViewWindow.h>
56 \brief Get the currently active application.
58 \return active application object or 0 if there is no any
60 static SalomeApp_Application* getApplication()
62 if ( SUIT_Session::session() )
63 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
68 \brief Get the currently active study.
70 \return active study or 0 if there is no study opened
72 static SalomeApp_Study* getActiveStudy()
74 if ( getApplication() )
75 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
80 \brief Get the currently active module.
82 This function returns correct result only if Python-based
83 module is currently active. Otherwize, 0 is returned.
85 static SALOME_PYQT_Module* getActiveModule()
87 SALOME_PYQT_Module* module = 0;
88 if ( SalomeApp_Application* anApp = getApplication() ) {
89 module = SALOME_PYQT_Module::getInitModule();
91 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
97 \class SALOME_Selection
98 \brief The class represents selection which can be used in Python.
102 \brief Map of created selection objects.
105 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
108 \brief Get the selection object for the specified application.
110 Finds or creates the selection object (one per study).
112 \param app application object
113 \return selection object or 0 if \a app is invalid
115 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
117 SALOME_Selection* sel = 0;
118 if ( app && SelMap.find( app ) != SelMap.end() )
121 sel = SelMap[ app ] = new SALOME_Selection( app );
127 \param p parent object
129 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
131 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
133 mySelMgr = app->selectionMgr();
134 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
135 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
141 SALOME_Selection::~SALOME_Selection()
143 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
144 if ( app && SelMap.find( app ) != SelMap.end() )
145 SelMap.remove( app );
149 \brief Called when selection manager is destroyed (usually
150 when the study is closed).
152 void SALOME_Selection::onSelMgrDestroyed()
158 \brief Clear the selection.
160 void SALOME_Selection::Clear()
162 class TEvent: public SALOME_Event {
163 LightApp_SelectionMgr* mySelMgr;
165 TEvent( LightApp_SelectionMgr* selMgr )
166 : mySelMgr( selMgr ) {}
167 virtual void Execute() {
169 mySelMgr->clearSelected();
172 ProcessVoidEvent( new TEvent( mySelMgr ) );
176 \brief Clear the selection.
178 void SALOME_Selection::ClearIObjects()
184 Removes all selection filters.
186 void SALOME_Selection::ClearFilters()
188 class TEvent: public SALOME_Event {
189 LightApp_SelectionMgr* mySelMgr;
191 TEvent( LightApp_SelectionMgr* selMgr )
192 : mySelMgr( selMgr ) {}
193 virtual void Execute() {
195 mySelMgr->clearFilters();
198 ProcessVoidEvent( new TEvent( mySelMgr ) );
203 \brief The class provides utility functions which can be used in the Python
204 to operate with the SALOME GUI.
206 All the functionality of this class is implemented as static methods, so they
207 can be called with the class name prefixed or via creation of the class instance.
208 For example, next both ways of SalomePyQt class usage are legal:
210 from SalomePyQt import *
212 # using SalomePyQt class instance
213 desktop = sg.getDesktop()
214 # using SalomePyQt class directly
215 menubar = SalomePyQt.getMainMenuBar()
220 \fn QWidget* SalomePyQt::getDesktop();
221 \brief Get the active application's desktop window.
222 \return desktop window or 0 if there is no any
225 class TGetDesktopEvent: public SALOME_Event
228 typedef QWidget* TResult;
230 TGetDesktopEvent() : myResult( 0 ) {}
231 virtual void Execute()
233 if ( getApplication() )
234 myResult = (QWidget*)( getApplication()->desktop() );
237 QWidget* SalomePyQt::getDesktop()
239 return ProcessEvent( new TGetDesktopEvent() );
243 \fn QWidget* SalomePyQt::getMainFrame();
244 \brief Get current application's main frame widget [obsolete].
246 Main frame widget is an internal widget of the application
247 desktop window (workspace).
249 \return workspace widget (0 on any error)
252 class TGetMainFrameEvent: public SALOME_Event
255 typedef QWidget* TResult;
257 TGetMainFrameEvent() : myResult( 0 ) {}
258 virtual void Execute()
260 if ( getApplication() ) {
261 SUIT_Desktop* aDesktop = getApplication()->desktop();
262 myResult = (QWidget*)( aDesktop->centralWidget() );
266 QWidget* SalomePyQt::getMainFrame()
268 return ProcessEvent( new TGetMainFrameEvent() );
272 \fn QMenuBar* SalomePyQt::getMainMenuBar();
273 \brief Get current application desktop's main menu.
274 \return main menu object (0 on any error)
277 class TGetMainMenuBarEvent: public SALOME_Event
280 typedef QMenuBar* TResult;
282 TGetMainMenuBarEvent() : myResult( 0 ) {}
283 virtual void Execute()
285 if ( SalomeApp_Application* anApp = getApplication() ) {
286 myResult = anApp->desktop()->menuBar();
290 QMenuBar* SalomePyQt::getMainMenuBar()
292 return ProcessEvent( new TGetMainMenuBarEvent() );
296 QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
297 \brief Get main menu's child popup submenu by its identifier.
299 This function is obsolete.
300 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
302 \param menu menu identifier
303 \return popup submenu object or 0 if it does not exist
307 QMenu* SalomePyQt::getPopupMenu( const QString& menu );
308 \brief Get main menu's child popup submenu by its name.
310 The function creates menu if it does not exist.
312 \param menu menu name
313 \return popup submenu object (0 on any error)
316 class TGetPopupMenuEvent: public SALOME_Event
319 typedef QMenu* TResult;
322 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
323 virtual void Execute()
325 SalomeApp_Application* anApp = getApplication();
326 if ( anApp && !myMenuName.isEmpty() ) {
327 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
328 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
333 static QString getMenuName( const QString& menuId )
335 QStringList contexts;
336 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
337 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
338 QString menuName = menuId;
339 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
340 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
344 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
349 menuName = getMenuName( "MEN_DESK_FILE" ); break;
351 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
353 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
355 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
357 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
359 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
361 menuName = getMenuName( "MEN_DESK_HELP" ); break;
363 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
365 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
367 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
371 \fn int SalomePyQt::getStudyId();
372 \brief Get active study's identifier.
373 \return active study ID or 0 if there is no active study
376 class TGetStudyIdEvent: public SALOME_Event
381 TGetStudyIdEvent() : myResult( 0 ) {}
382 virtual void Execute()
384 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
385 myResult = aStudy->studyDS()->StudyId();
389 int SalomePyQt::getStudyId()
391 return ProcessEvent( new TGetStudyIdEvent() );
395 \fn SALOME_Selection* SalomePyQt::getSelection()
396 \brief Get the selection object for the current study.
398 Creates a Selection object if it has not been created yet.
400 \return selection object (0 on error)
403 class TGetSelectionEvent: public SALOME_Event
406 typedef SALOME_Selection* TResult;
408 TGetSelectionEvent() : myResult( 0 ) {}
409 virtual void Execute()
411 myResult = SALOME_Selection::GetSelection( getApplication() );
414 SALOME_Selection* SalomePyQt::getSelection()
416 return ProcessEvent( new TGetSelectionEvent() );
420 \fn void SalomePyQt::putInfo( const QString& msg, const int sec )
421 \brief Put an information message to the current application's
424 Optional second delay parameter (\a sec) can be used to specify
425 time of the message diplaying in seconds. If this parameter is less
426 or equal to zero, the constant message will be put.
428 \param msg message text
429 \param sec message displaying time in seconds
432 class TPutInfoEvent: public SALOME_Event
437 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
438 virtual void Execute()
440 if ( SalomeApp_Application* anApp = getApplication() ) {
441 anApp->putInfo( myMsg, mySecs * 1000 );
445 void SalomePyQt::putInfo( const QString& msg, const int sec )
447 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
451 \fn const QString SalomePyQt::getActiveComponent();
452 \brief Get the currently active module name (for the current study).
453 \return active module name or empty string if there is no active module
456 class TGetActiveComponentEvent: public SALOME_Event
459 typedef QString TResult;
461 TGetActiveComponentEvent() {}
462 virtual void Execute()
464 if ( SalomeApp_Application* anApp = getApplication() ) {
465 if ( CAM_Module* mod = anApp->activeModule() ) {
466 myResult = mod->name();
471 const QString SalomePyQt::getActiveComponent()
473 return ProcessEvent( new TGetActiveComponentEvent() );
477 \brief Update an Object Browser of the specified (by identifier) study.
479 If \a studyId <= 0 the active study's object browser is updated.
480 The \a updateSelection parameter is obsolete and currently is not used.
481 This parameter will be removed in future, so try to avoid its usage in
484 \brief studyId study identifier
485 \brief updateSelection update selection flag (not used)
488 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
490 class TEvent: public SALOME_Event
493 bool myUpdateSelection;
495 TEvent( const int studyId, bool updateSelection )
496 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
497 virtual void Execute()
499 if ( SUIT_Session::session() ) {
500 if ( getActiveStudy() && myStudyId <= 0 )
501 myStudyId = getActiveStudy()->id();
502 if ( myStudyId > 0 ) {
503 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
504 QList<SUIT_Application*>::Iterator it;
505 for( it = apps.begin(); it != apps.end(); ++it ) {
506 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( *it );
507 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
508 anApp->updateObjectBrowser();
516 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
520 \brief Default resource file section name.
523 static const char* DEFAULT_SECTION = "SalomePyQt";
526 \brief Add string setting to the application preferences.
528 The parameter \a autoValue is obsolete parameter and currently is not used.
529 This parameter will be removed in future, so try to avoid its usage in
532 This function is obsolete. Use one of addSetting() instead.
534 \param name setting name (it should be of kind <section:setting> where
535 \c section is resources section name and \c setting is setting name)
536 \param value new setting value
537 \param autoValue (not used)
539 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
541 class TEvent: public SALOME_Event
547 TEvent( const QString& name, const QString& value, bool autoValue )
548 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
549 virtual void Execute() {
550 if ( SUIT_Session::session() ) {
551 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
552 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
553 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
554 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
555 if ( !_sec.isEmpty() && !_nam.isEmpty() )
556 resMgr->setValue( _sec, _nam, myValue );
560 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
564 \brief Add integer setting to the application preferences.
566 The parameter \a autoValue is obsolete parameter and currently is not used.
567 This parameter will be removed in future, so try to avoid its usage in
570 This function is obsolete. Use one of addSetting() instead.
572 \param name setting name (it should be of kind <section:setting> where
573 \c section is resources section name and \c setting is setting name)
574 \param value new setting value
575 \param autoValue (not used)
577 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
579 class TEvent: public SALOME_Event
585 TEvent( const QString& name, const int value, bool autoValue )
586 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
587 virtual void Execute()
589 if ( SUIT_Session::session() ) {
590 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
591 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
592 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
593 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
594 if ( !_sec.isEmpty() && !_nam.isEmpty() )
595 resMgr->setValue( _sec, _nam, myValue );
599 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
603 \brief Add double setting to the application preferences.
605 The parameter \a autoValue is obsolete parameter and currently is not used.
606 This parameter will be removed in future, so try to avoid its usage in
609 This function is obsolete. Use one of addSetting() instead.
611 \param name setting name (it should be of kind <section:setting> where
612 \c section is resources section name and \c setting is setting name)
613 \param value new setting value
614 \param autoValue (not used)
616 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
618 class TEvent: public SALOME_Event
624 TEvent( const QString& name, const double value, bool autoValue )
625 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
626 virtual void Execute()
628 if ( SUIT_Session::session() ) {
629 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
630 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
631 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
632 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
633 if ( !_sec.isEmpty() && !_nam.isEmpty() )
634 resMgr->setValue( _sec, _nam, myValue );
638 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
642 \brief Add boolean setting to the application preferences.
644 The parameter \a autoValue is obsolete parameter and currently is not used.
645 This parameter will be removed in future, so try to avoid its usage in
648 This function is obsolete. Use one of addSetting() instead.
650 \param name setting name (it should be of kind <section:setting> where
651 \c section is resources section name and \c setting is setting name)
652 \param value new setting value
653 \param autoValue (not used)
655 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
657 class TEvent: public SALOME_Event
663 TEvent( const QString& name, const bool value, bool autoValue )
664 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
665 virtual void Execute()
667 if ( SUIT_Session::session() ) {
668 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
669 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
670 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
671 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
672 if ( !_sec.isEmpty() && !_nam.isEmpty() )
673 resMgr->setValue( _sec, _nam, myValue );
677 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
681 \brief Remove setting from the application preferences.
683 This function is obsolete. Use removeSetting() instead.
685 \param name setting name (it should be of kind <section:setting> where
686 \c section is resources section name and \c setting is setting name)
688 void SalomePyQt::removeSettings( const QString& name )
690 class TEvent: public SALOME_Event {
693 TEvent( const QString& name ) : myName( name ) {}
694 virtual void Execute() {
695 if ( SUIT_Session::session() ) {
696 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
697 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
698 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
699 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
700 if ( !_sec.isEmpty() && !_nam.isEmpty() )
701 resMgr->remove( _sec, _nam );
705 ProcessVoidEvent( new TEvent( name ) );
709 \fn QString SalomePyQt::getSetting( const QString& name );
710 \brief Get application setting value (as string represenation).
712 This function is obsolete. Use stringSetting(), integerSetting(),
713 boolSetting(), stringSetting() or colorSetting() instead.
715 \param name setting name (it should be of kind <section:setting> where
716 \c section is resources section name and \c setting is setting name)
717 \return setting name (empty string if setting name is invalid)
720 class TGetSettingEvent: public SALOME_Event
723 typedef QString TResult;
726 TGetSettingEvent( const QString& name ) : myName( name ) {}
727 virtual void Execute()
729 if ( SUIT_Session::session() ) {
730 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
731 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
732 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
733 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
734 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
738 QString SalomePyQt::getSetting( const QString& name )
740 return ProcessEvent( new TGetSettingEvent( name ) );
744 \brief Add double setting to the application preferences.
745 \param section resources file section name
746 \param name setting name
747 \param value new setting value
749 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
751 class TEvent: public SALOME_Event
757 TEvent( const QString& section, const QString& name, double value )
758 : mySection( section ), myName( name ), myValue( value ) {}
759 virtual void Execute()
761 if ( SUIT_Session::session() ) {
762 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
763 if ( !mySection.isEmpty() && !myName.isEmpty() )
764 resMgr->setValue( mySection, myName, myValue );
768 ProcessVoidEvent( new TEvent( section, name, value ) );
772 \brief Add integer setting to the application preferences.
773 \param section resources file section name
774 \param name setting name
775 \param value new setting value
777 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
779 class TEvent: public SALOME_Event
785 TEvent( const QString& section, const QString& name, int value )
786 : mySection( section ), myName( name ), myValue( value ) {}
787 virtual void Execute()
789 if ( SUIT_Session::session() ) {
790 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
791 if ( !mySection.isEmpty() && !myName.isEmpty() )
792 resMgr->setValue( mySection, myName, myValue );
796 ProcessVoidEvent( new TEvent( section, name, value ) );
800 \brief Add boolean setting to the application preferences.
801 \param section resources file section name
802 \param name setting name
803 \param value new setting value
804 \param dumb this parameter is used in order to avoid sip compilation error
805 because of conflicting int and bool types
807 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
809 class TEvent: public SALOME_Event
815 TEvent( const QString& section, const QString& name, bool value )
816 : mySection( section ), myName( name ), myValue( value ) {}
817 virtual void Execute()
819 if ( SUIT_Session::session() ) {
820 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
821 if ( !mySection.isEmpty() && !myName.isEmpty() )
822 resMgr->setValue( mySection, myName, myValue );
826 ProcessVoidEvent( new TEvent( section, name, value ) );
830 \brief Add string setting to the application preferences.
831 \param section resources file section name
832 \param name setting name
833 \param value new setting value
835 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
837 class TEvent: public SALOME_Event
843 TEvent( const QString& section, const QString& name, const QString& value )
844 : mySection( section ), myName( name ), myValue( value ) {}
845 virtual void Execute()
847 if ( SUIT_Session::session() ) {
848 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
849 if ( !mySection.isEmpty() && !myName.isEmpty() )
850 resMgr->setValue( mySection, myName, myValue );
854 ProcessVoidEvent( new TEvent( section, name, value ) );
858 \brief Add color setting to the application preferences.
859 \param section resources file section name
860 \param name setting name
861 \param value new setting value
863 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
865 class TEvent: public SALOME_Event
871 TEvent( const QString& section, const QString& name, const QColor& value )
872 : mySection( section ), myName( name ), myValue( value ) {}
873 virtual void Execute()
875 if ( SUIT_Session::session() ) {
876 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
877 if ( !mySection.isEmpty() && !myName.isEmpty() )
878 resMgr->setValue( mySection, myName, myValue );
882 ProcessVoidEvent( new TEvent( section, name, value ) );
886 \fn int SalomePyQt::integerSetting( const QString& section,
889 \brief Get integer setting from the application preferences.
890 \param section resources file section name
891 \param name setting name
892 \param def default value which is returned if the setting is not found
893 \return setting value
896 class TGetIntSettingEvent: public SALOME_Event
904 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
905 : mySection( section ), myName( name ), myDefault( def ) {}
906 virtual void Execute()
908 if ( SUIT_Session::session() ) {
909 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
910 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
914 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
916 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
920 \fn double SalomePyQt::doubleSetting( const QString& section,
923 \brief Get double setting from the application preferences.
924 \param section resources file section name
925 \param name setting name
926 \param def default value which is returned if the setting is not found
927 \return setting value
930 class TGetDblSettingEvent: public SALOME_Event
933 typedef double TResult;
938 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
939 : mySection( section ), myName( name ), myDefault( def ) {}
940 virtual void Execute()
942 if ( SUIT_Session::session() ) {
943 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
944 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
948 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
950 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
954 \fn bool SalomePyQt::boolSetting( const QString& section,
957 \brief Get boolean setting from the application preferences.
958 \param section resources file section name
959 \param name setting name
960 \param def default value which is returned if the setting is not found
961 \return setting value
964 class TGetBoolSettingEvent: public SALOME_Event
967 typedef bool TResult;
972 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
973 : mySection( section ), myName( name ), myDefault( def ) {}
974 virtual void Execute()
976 if ( SUIT_Session::session() ) {
977 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
978 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
982 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
984 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
988 \fn QString SalomePyQt::stringSetting( const QString& section,
990 const QString& def );
991 \brief Get string setting from the application preferences.
992 \param section resources file section name
993 \param name setting name
994 \param def default value which is returned if the setting is not found
995 \return setting value
998 class TGetStrSettingEvent: public SALOME_Event
1001 typedef QString TResult;
1006 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1007 : mySection( section ), myName( name ), myDefault( def ) {}
1008 virtual void Execute()
1010 if ( SUIT_Session::session() ) {
1011 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1012 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1016 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1018 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1022 \fn QColor SalomePyQt::colorSetting( const QString& section,
1023 const QString& name,
1025 \brief Get color setting from the application preferences.
1026 \param section resources file section name
1027 \param name setting name
1028 \param def default value which is returned if the setting is not found
1029 \return setting value
1032 class TGetColorSettingEvent: public SALOME_Event
1035 typedef QColor TResult;
1040 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1041 : mySection( section ), myName( name ), myDefault( def ) {}
1042 virtual void Execute()
1044 if ( SUIT_Session::session() ) {
1045 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1046 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1050 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1052 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1056 \brief Remove setting from the application preferences.
1057 \param section resources file section name
1058 \param name setting name
1060 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1062 class TEvent: public SALOME_Event
1067 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1068 virtual void Execute()
1070 if ( SUIT_Session::session() ) {
1071 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1072 if ( !mySection.isEmpty() && !myName.isEmpty() )
1073 resMgr->remove( mySection, myName );
1077 ProcessVoidEvent( new TEvent( section, name ) );
1081 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1082 \brief Check setting existence in the application preferences.
1083 \param section resources file section name
1084 \param name setting name
1085 \return \c true if setting exists
1088 class THasColorSettingEvent: public SALOME_Event
1091 typedef bool TResult;
1095 THasColorSettingEvent( const QString& section, const QString& name )
1096 : mySection( section ), myName( name ) {}
1097 virtual void Execute()
1099 if ( SUIT_Session::session() ) {
1100 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1101 myResult = resMgr->hasValue( mySection, myName );
1105 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1107 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1111 \fn QString SalomePyQt::getFileName( QWidget* parent,
1112 const QString& initial,
1113 const QStringList& filters,
1114 const QString& caption,
1116 \brief Show 'Open/Save file' dialog box for file selection
1117 and return a user's choice (selected file name).
1118 \param parent parent widget
1119 \param initial initial directory the dialog box to be opened in
1120 \param filters list of files filters (wildcards)
1121 \param caption dialog box title
1122 \param open if \c true, "Open File" dialog box is shown;
1123 otherwise "Save File" dialog box is shown
1124 \return selected file name (null string if user cancels operation)
1127 class TGetFileNameEvent: public SALOME_Event
1130 typedef QString TResult;
1134 QStringList myFilters;
1137 TGetFileNameEvent( QWidget* parent,
1138 const QString& initial,
1139 const QStringList& filters,
1140 const QString& caption,
1142 : myParent ( parent ),
1143 myInitial( initial ),
1144 myFilters( filters ),
1145 myCaption( caption ),
1147 virtual void Execute()
1149 if ( SalomeApp_Application* anApp = getApplication() ) {
1150 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1151 myCaption, myParent );
1155 QString SalomePyQt::getFileName( QWidget* parent,
1156 const QString& initial,
1157 const QStringList& filters,
1158 const QString& caption,
1161 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1165 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1166 const QString& initial,
1167 const QStringList& filters,
1168 const QString& caption );
1169 \brief Show 'Open files' dialog box for multiple files selection
1170 and return a user's choice (selected file names list).
1171 \param parent parent widget
1172 \param initial initial directory the dialog box to be opened in
1173 \param filters list of files filters (wildcards)
1174 \param caption dialog box title
1175 \return selected file names list (empty list if user cancels operation)
1178 class TGetOpenFileNamesEvent: public SALOME_Event
1181 typedef QStringList TResult;
1185 QStringList myFilters;
1187 TGetOpenFileNamesEvent( QWidget* parent,
1188 const QString& initial,
1189 const QStringList& filters,
1190 const QString& caption )
1191 : myParent ( parent ),
1192 myInitial( initial ),
1193 myFilters( filters ),
1194 myCaption( caption ) {}
1195 virtual void Execute()
1197 if ( SalomeApp_Application* anApp = getApplication() ) {
1198 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1202 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1203 const QString& initial,
1204 const QStringList& filters,
1205 const QString& caption )
1207 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1211 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1212 const QString& initial,
1213 const QString& caption );
1214 \brief Show 'Get Directory' dialog box for the directory selection
1215 and return a user's choice (selected directory name).
1216 \param parent parent widget
1217 \param initial initial directory the dialog box to be opened in
1218 \param caption dialog box title
1219 \return selected directory name (null string if user cancels operation)
1222 class TGetExistingDirectoryEvent: public SALOME_Event
1225 typedef QString TResult;
1230 TGetExistingDirectoryEvent( QWidget* parent,
1231 const QString& initial,
1232 const QString& caption )
1233 : myParent ( parent ),
1234 myInitial( initial ),
1235 myCaption( caption ) {}
1236 virtual void Execute()
1238 if ( SalomeApp_Application* anApp = getApplication() ) {
1239 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1243 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1244 const QString& initial,
1245 const QString& caption )
1247 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1251 \brief Open external browser to display context help information.
1254 Current implementation does nothing.
1256 \param source documentation (HTML) file name
1257 \param context context (for example, HTML ancor name)
1259 void SalomePyQt::helpContext( const QString& source, const QString& context )
1261 class TEvent: public SALOME_Event
1266 TEvent( const QString& source, const QString& context )
1267 : mySource( source ), myContext( context ) {}
1268 virtual void Execute()
1270 if ( SalomeApp_Application* anApp = getApplication() ) {
1271 anApp->onHelpContextModule( "", mySource, myContext );
1275 ProcessVoidEvent( new TEvent( source, context ) );
1279 \fn bool SalomePyQt::dumpView( const QString& filename );
1280 \brief Dump the contents of the currently active view window
1281 to the image file in the specified format.
1283 For the current moment JPEG, PNG and BMP images formats are supported.
1284 The image format is defined automatically by the file name extension.
1285 By default, BMP format is used.
1287 \param filename image file name
1288 \return operation status (\c true on success)
1291 class TDumpViewEvent: public SALOME_Event
1294 typedef bool TResult;
1297 TDumpViewEvent( const QString& filename )
1298 : myResult ( false ), myFileName( filename ) {}
1299 virtual void Execute()
1301 if ( SalomeApp_Application* anApp = getApplication() ) {
1302 SUIT_ViewManager* vm = anApp->activeViewManager();
1304 SUIT_ViewWindow* vw = vm->getActiveView();
1306 QImage im = vw->dumpView();
1307 if ( !im.isNull() && !myFileName.isEmpty() ) {
1308 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
1309 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
1310 if ( fmt == "JPG" ) fmt = "JPEG";
1311 myResult = im.save( myFileName, fmt.toLatin1() );
1318 bool SalomePyQt::dumpView( const QString& filename )
1320 return ProcessEvent( new TDumpViewEvent( filename ) );
1324 \fn int SalomePyQt::defaultMenuGroup();
1325 \brief Get detault menu group identifier which can be used when
1326 creating menus (insert custom menu commands).
1327 \return default menu group ID
1330 class TDefMenuGroupEvent: public SALOME_Event
1333 typedef int TResult;
1335 TDefMenuGroupEvent() : myResult( -1 ) {}
1336 virtual void Execute()
1338 myResult = SALOME_PYQT_Module::defaultMenuGroup();
1341 int SalomePyQt::defaultMenuGroup()
1343 return ProcessEvent( new TDefMenuGroupEvent() );
1349 CrTool( const QString& tBar )
1350 : myCase( 0 ), myTbName( tBar ) {}
1351 CrTool( const int id, const int tBar, const int idx )
1352 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1353 CrTool( const int id, const QString& tBar, const int idx )
1354 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1355 CrTool( QAction* action, const int tbId, const int id, const int idx )
1356 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1357 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1358 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1360 int execute( SALOME_PYQT_Module* module ) const
1365 return module->createTool( myTbName );
1367 return module->createTool( myId, myTbId, myIndex );
1369 return module->createTool( myId, myTbName, myIndex );
1371 return module->createTool( myAction, myTbId, myId, myIndex );
1373 return module->createTool( myAction, myTbName, myId, myIndex );
1387 class TCreateToolEvent: public SALOME_Event
1390 typedef int TResult;
1392 const CrTool& myCrTool;
1393 TCreateToolEvent( const CrTool& crTool )
1394 : myResult( -1 ), myCrTool( crTool ) {}
1395 virtual void Execute()
1397 SALOME_PYQT_Module* module = getActiveModule();
1399 myResult = myCrTool.execute( module );
1404 \brief Create toolbar with specified name.
1405 \param tBar toolbar name
1406 \return toolbar ID or -1 if toolbar creation is failed
1408 int SalomePyQt::createTool( const QString& tBar )
1410 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1414 \brief Insert action with specified \a id to the toolbar.
1416 \param tBar toolbar ID
1417 \param idx required index in the toolbar
1418 \return action ID or -1 if action could not be added
1420 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1422 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1426 \brief Insert action with specified \a id to the toolbar.
1428 \param tBar toolbar name
1429 \param idx required index in the toolbar
1430 \return action ID or -1 if action could not be added
1432 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1434 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1438 \brief Insert action to the toolbar.
1440 \param tBar toolbar ID
1441 \param id required action ID
1442 \param idx required index in the toolbar
1443 \return action ID or -1 if action could not be added
1445 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1447 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1451 \brief Insert action to the toolbar.
1453 \param tBar toolbar name
1454 \param id required action ID
1455 \param idx required index in the toolbar
1456 \return action ID or -1 if action could not be added
1458 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1460 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1466 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1467 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1468 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1469 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1470 CrMenu( const int id, const int menu, const int group, const int idx )
1471 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1472 CrMenu( const int id, const QString& menu, const int group, const int idx )
1473 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1474 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1475 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1476 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1477 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1479 int execute( SALOME_PYQT_Module* module ) const
1484 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1486 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1488 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1490 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1492 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1494 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1503 QString mySubMenuName;
1510 class TCreateMenuEvent: public SALOME_Event
1513 typedef int TResult;
1515 const CrMenu& myCrMenu;
1516 TCreateMenuEvent( const CrMenu& crMenu )
1517 : myResult( -1 ), myCrMenu( crMenu ) {}
1518 virtual void Execute()
1520 SALOME_PYQT_Module* module = getActiveModule();
1522 myResult = myCrMenu.execute( module );
1527 \brief Create main menu.
1528 \param subMenu menu name
1529 \param menu parent menu ID
1530 \param id required menu ID
1531 \param group menu group ID
1532 \param idx required index in the menu
1533 \return menu ID or -1 if menu could not be added
1535 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1537 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1541 \brief Create main menu.
1542 \param subMenu menu name
1543 \param menu parent menu name (list of menu names separated by "|")
1544 \param id required menu ID
1545 \param group menu group ID
1546 \param idx required index in the menu
1547 \return menu ID or -1 if menu could not be added
1549 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1551 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1555 \brief Insert action to the main menu.
1557 \param menu parent menu ID
1558 \param group menu group ID
1559 \param idx required index in the menu
1560 \return action ID or -1 if action could not be added
1562 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1564 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1568 \brief Insert action to the main menu.
1570 \param menu parent menu name (list of menu names separated by "|")
1571 \param group menu group ID
1572 \param idx required index in the menu
1573 \return action ID or -1 if action could not be added
1575 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1577 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1581 \brief Insert action to the main menu.
1583 \param menu parent menu ID
1584 \param group menu group ID
1585 \param idx required index in the menu
1586 \return action ID or -1 if action could not be added
1588 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1590 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1594 \brief Insert action to the main menu.
1596 \param menu parent menu name (list of menu names separated by "|")
1597 \param group menu group ID
1598 \param idx required index in the menu
1599 \return action ID or -1 if action could not be added
1601 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1603 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1607 \fn QAction* SalomePyQt::createSeparator();
1608 \brief Create separator action which can be used in the menu or toolbar.
1609 \return new separator action
1612 class TCreateSepEvent: public SALOME_Event
1615 typedef QAction* TResult;
1619 virtual void Execute()
1621 SALOME_PYQT_Module* module = getActiveModule();
1623 myResult = (QAction*)module->separator();
1626 QAction* SalomePyQt::createSeparator()
1628 return ProcessEvent( new TCreateSepEvent() );
1632 \fn QAction* SalomePyQt::createAction( const int id,
1633 const QString& menuText,
1634 const QString& tipText,
1635 const QString& statusText,
1636 const QString& icon,
1639 \brief Create an action which can be then used in the menu or toolbar.
1640 \param id the unique id action to be registered to
1641 \param menuText action text which should appear in menu
1642 \param tipText text which should appear in the tooltip
1643 \param statusText text which should appear in the status bar when action is activated
1644 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1645 \param key the key accelrator for the action
1646 \param toggle if \c true the action is checkable
1649 class TCreateActionEvent: public SALOME_Event
1652 typedef QAction* TResult;
1657 QString myStatusText;
1661 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1662 const QString& statusText, const QString& icon, const int key, const bool toggle )
1663 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1664 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1665 virtual void Execute()
1667 SALOME_PYQT_Module* module = getActiveModule();
1669 myResult = (QAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1672 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1673 const QString& tipText, const QString& statusText,
1674 const QString& icon, const int key, const bool toggle )
1676 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1680 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1681 \brief Create an action group which can be then used in the menu or toolbar
1682 \param id : the unique id action group to be registered to
1683 \param exclusive : if \c true the action group does exclusive toggling
1686 struct TcreateActionGroupEvent: public SALOME_Event {
1687 typedef QtxActionGroup* TResult;
1691 TcreateActionGroupEvent( const int id, const bool exclusive )
1692 : myId( id ), myExclusive( exclusive ) {}
1693 virtual void Execute()
1695 SALOME_PYQT_Module* module = getActiveModule();
1697 myResult = module->createActionGroup( myId, myExclusive );
1700 QtxActionGroup* SalomePyQt::createActionGroup(const int id, const bool exclusive)
1702 return ProcessEvent( new TcreateActionGroupEvent( id, exclusive ) );
1706 \fn QAction* SalomePyQt::action( const int id )
1707 \brief Get action by specified identifier.
1708 \return action or 0 if action is not registered
1711 class TActionEvent: public SALOME_Event
1714 typedef QAction* TResult;
1717 TActionEvent( const int id )
1718 : myResult( 0 ), myId( id ) {}
1719 virtual void Execute()
1721 SALOME_PYQT_Module* module = getActiveModule();
1723 myResult = (QAction*)module->action( myId );
1726 QAction* SalomePyQt::action( const int id )
1728 return ProcessEvent( new TActionEvent( id ) );
1732 \fn int SalomePyQt::actionId( const QAction* a );
1733 \brief Get an action identifier.
1734 \return action ID or -1 if action is not registered
1737 class TActionIdEvent: public SALOME_Event
1740 typedef int TResult;
1742 const QAction* myAction;
1743 TActionIdEvent( const QAction* action )
1744 : myResult( -1 ), myAction( action ) {}
1745 virtual void Execute()
1747 SALOME_PYQT_Module* module = getActiveModule();
1749 myResult = module->actionId( myAction );
1752 int SalomePyQt::actionId( const QAction* a )
1754 return ProcessEvent( new TActionIdEvent( a ) );
1758 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1759 \brief Add global (not module-related) preferences group.
1760 \param label global preferences group name
1761 \return preferences group identifier
1764 class TAddGlobalPrefEvent: public SALOME_Event
1767 typedef int TResult;
1770 TAddGlobalPrefEvent( const QString& label )
1771 : myResult( -1 ), myLabel( label ) {}
1772 virtual void Execute()
1774 SALOME_PYQT_Module* module = getActiveModule();
1776 myResult = module->addGlobalPreference( myLabel );
1779 int SalomePyQt::addGlobalPreference( const QString& label )
1781 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
1785 \fn int SalomePyQt::addPreference( const QString& label );
1786 \brief Add module-related preferences group.
1787 \param label preferences group name
1788 \return preferences group identifier
1791 class TAddPrefEvent: public SALOME_Event
1794 typedef int TResult;
1797 TAddPrefEvent( const QString& label )
1798 : myResult( -1 ), myLabel( label ) {}
1799 virtual void Execute()
1801 SALOME_PYQT_Module* module = getActiveModule();
1803 myResult = module->addPreference( myLabel );
1806 int SalomePyQt::addPreference( const QString& label )
1808 return ProcessEvent( new TAddPrefEvent( label ) );
1812 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
1813 const QString& section, const QString& param );
1814 \brief Add module-related preferences.
1815 \param label preferences group name
1816 \param pId parent preferences group id
1817 \param type preferences type
1818 \param section resources file section name
1819 \param param resources file setting name
1820 \return preferences identifier
1823 class TAddPrefParamEvent: public SALOME_Event
1826 typedef int TResult;
1833 TAddPrefParamEvent( const QString& label,
1834 const int pId, const int type,
1835 const QString& section,
1836 const QString& param )
1838 myLabel( label ), myPId( pId ), myType( type ),
1839 mySection( section ), myParam ( param ) {}
1840 virtual void Execute()
1842 SALOME_PYQT_Module* module = getActiveModule();
1844 myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam );
1847 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
1848 const QString& section, const QString& param )
1850 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
1854 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
1855 \brief Get the preferences property.
1856 \param id preferences identifier
1857 \param prop preferences property name
1858 \return preferences property value or null QVariant if property is not set
1861 class TPrefPropEvent: public SALOME_Event
1864 typedef QVariant TResult;
1868 TPrefPropEvent( const int id, const QString& prop )
1869 : myId( id ), myProp( prop ) {}
1870 virtual void Execute()
1872 SALOME_PYQT_Module* module = getActiveModule();
1874 myResult = module->preferenceProperty( myId, myProp );
1877 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
1879 return ProcessEvent( new TPrefPropEvent( id, prop ) );
1883 \brief Set the preferences property.
1884 \param id preferences identifier
1885 \param prop preferences property name
1886 \param var preferences property value
1888 void SalomePyQt::setPreferenceProperty( const int id,
1889 const QString& prop,
1890 const QVariant& var )
1892 class TEvent: public SALOME_Event
1898 TEvent( const int id, const QString& prop, const QVariant& var )
1899 : myId( id ), myProp( prop ), myVar( var ) {}
1900 virtual void Execute()
1902 SALOME_PYQT_Module* module = getActiveModule();
1904 module->setPreferenceProperty( myId, myProp, myVar );
1907 ProcessVoidEvent( new TEvent( id, prop, var) );
1911 \brief Add the property value to the list of values.
1913 This method allows creating properties which are QList<QVariant>
1914 - there is no way to pass such values directly to QVariant parameter with PyQt.
1916 \param id preferences identifier
1917 \param prop preferences property name
1918 \param idx preferences property index
1919 \param var preferences property value for the index \a idx
1921 void SalomePyQt::addPreferenceProperty( const int id,
1922 const QString& prop,
1924 const QVariant& var )
1926 class TEvent: public SALOME_Event
1933 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
1934 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
1935 virtual void Execute()
1937 SALOME_PYQT_Module* module = getActiveModule();
1939 QVariant var = module->preferenceProperty( myId, myProp );
1940 if ( var.isValid() ) {
1941 if ( var.type() == QVariant::StringList ) {
1942 QStringList sl = var.toStringList();
1943 if ( myIdx >= 0 && myIdx < sl.count() )
1944 sl[myIdx] = myVar.toString();
1946 sl.append( myVar.toString() );
1947 module->setPreferenceProperty( myId, myProp, sl );
1949 else if ( var.type() == QVariant::List ) {
1950 QList<QVariant> vl = var.toList();
1951 if ( myIdx >= 0 && myIdx < vl.count() )
1955 module->setPreferenceProperty( myId, myProp, vl );
1961 module->setPreferenceProperty( myId, myProp, vl );
1966 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
1970 \brief Put the message to the Log messages output window
1971 \param msg message text (it can be of simple rich text format)
1972 \param addSeparator boolean flag which specifies if it is necessary
1973 to separate the message with predefined separator
1975 void SalomePyQt::message( const QString& msg, bool addSeparator )
1977 class TEvent: public SALOME_Event
1982 TEvent( const QString& msg, bool addSeparator )
1983 : myMsg( msg ), myAddSep( addSeparator ) {}
1984 virtual void Execute()
1986 if ( SalomeApp_Application* anApp = getApplication() ) {
1987 LogWindow* lw = anApp->logWindow();
1989 lw->putMessage( myMsg, myAddSep );
1993 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
1997 \brief Remove all the messages from the Log messages output window.
1999 void SalomePyQt::clearMessages()
2001 class TEvent: public SALOME_Event
2005 virtual void Execute()
2007 if ( SalomeApp_Application* anApp = getApplication() ) {
2008 LogWindow* lw = anApp->logWindow();
2014 ProcessVoidEvent( new TEvent() );
2018 \brief Gets window with specified identifier
2020 \param id window identifier
2021 \return pointer on the window
2023 static SUIT_ViewWindow* getWnd( const int id )
2025 SUIT_ViewWindow* resWnd = 0;
2027 SalomeApp_Application* app = getApplication();
2030 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2033 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2034 SUIT_ViewWindow* wnd;
2035 foreach ( wnd, wndlist )
2037 if ( id == wnd->getId() )
2050 \fn QList<int> SalomePyQt::getViews()
2051 \brief Get list of integer identifiers of all the currently opened views
2052 \return list of integer identifiers of all the currently opened views
2055 class TGetViews: public SALOME_Event
2058 typedef QList<int> TResult;
2061 virtual void Execute()
2064 SalomeApp_Application* app = getApplication();
2067 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2070 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2071 SUIT_ViewWindow* wnd;
2072 foreach ( wnd, wndlist )
2073 myResult.append( wnd->getId() );
2078 QList<int> SalomePyQt::getViews()
2080 return ProcessEvent( new TGetViews() );
2084 \fn int SalomePyQt::getActiveView()
2085 \brief Get integer identifier of the currently active view
2086 \return integer identifier of the currently active view
2089 class TGetActiveView: public SALOME_Event
2092 typedef int TResult;
2096 virtual void Execute()
2098 SalomeApp_Application* app = getApplication();
2101 SUIT_ViewManager* viewMgr = app->activeViewManager();
2104 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2106 myResult = wnd->getId();
2111 int SalomePyQt::getActiveView()
2113 return ProcessEvent( new TGetActiveView() );
2117 \fn QString SalomePyQt::getViewType( const int id )
2118 \brief Get type of the specified view, e.g. "OCCViewer"
2119 \param id window identifier
2123 class TGetViewType: public SALOME_Event
2126 typedef QString TResult;
2129 TGetViewType( const int id )
2131 virtual void Execute()
2133 SUIT_ViewWindow* wnd = getWnd( myWndId );
2136 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2138 myResult = viewMgr->getType();
2142 QString SalomePyQt::getViewType( const int id )
2144 return ProcessEvent( new TGetViewType( id ) );
2148 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title )
2149 \brief Change view caption
2150 \param id window identifier
2151 \param title new window title
2152 \return \c true if operation is completed successfully and \c false otherwise
2155 class TSetViewTitle: public SALOME_Event
2158 typedef bool TResult;
2162 TSetViewTitle( const int id, const QString& title )
2163 : myResult( false ),
2166 virtual void Execute()
2168 SUIT_ViewWindow* wnd = getWnd( myWndId );
2171 wnd->setWindowTitle( myTitle );
2176 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2178 return ProcessEvent( new TSetViewTitle( id, title ) );
2183 \fn QString SalomePyQt::getViewTitle( const int id )
2184 \brief Get view caption
2185 \param id window identifier
2186 \return view caption
2189 class TGetViewTitle: public SALOME_Event
2192 typedef QString TResult;
2195 TGetViewTitle( const int id )
2197 virtual void Execute()
2199 SUIT_ViewWindow* wnd = getWnd( myWndId );
2201 myResult = wnd->windowTitle();
2204 QString SalomePyQt::getViewTitle( const int id )
2206 return ProcessEvent( new TGetViewTitle( id ) );
2210 \fn QList<int> SalomePyQt::findViews( const QString& type )
2211 \brief Get list of integer identifiers of all the
2212 currently opened views of the specified type
2213 \param type viewer type
2214 \return list of integer identifiers
2217 class TFindViews: public SALOME_Event
2220 typedef QList<int> TResult;
2223 TFindViews( const QString& type )
2225 virtual void Execute()
2228 SalomeApp_Application* app = getApplication();
2231 ViewManagerList vmList;
2232 app->viewManagers( myType, vmList );
2233 SUIT_ViewManager* viewMgr;
2234 foreach ( viewMgr, vmList )
2236 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2237 for ( int i = 0, n = vec.size(); i < n; i++ )
2239 SUIT_ViewWindow* wnd = vec[ i ];
2241 myResult.append( wnd->getId() );
2247 QList<int> SalomePyQt::findViews( const QString& type )
2249 return ProcessEvent( new TFindViews( type ) );
2253 \fn bool SalomePyQt::activateView( const int id )
2254 \brief Activate view
2255 \param id window identifier
2256 \return \c true if operation is completed successfully and \c false otherwise
2259 class TActivateView: public SALOME_Event
2262 typedef bool TResult;
2265 TActivateView( const int id )
2266 : myResult( false ),
2268 virtual void Execute()
2270 SUIT_ViewWindow* wnd = getWnd( myWndId );
2278 bool SalomePyQt::activateView( const int id )
2280 return ProcessEvent( new TActivateView( id ) );
2284 \fn int SalomePyQt::createView( const QString& type )
2285 \brief Create new view and activate it
2286 \param type viewer type
2287 \return integer identifier of created view (or -1 if view could not be created)
2290 class TCreateView: public SALOME_Event
2293 typedef int TResult;
2296 TCreateView( const QString& theType )
2298 myType( theType ) {}
2299 virtual void Execute()
2301 SalomeApp_Application* app = getApplication();
2304 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2307 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2309 myResult = wnd->getId();
2314 int SalomePyQt::createView( const QString& type )
2316 return ProcessEvent( new TCreateView( type ) );
2320 \fn bool SalomePyQt::closeView( const int id )
2322 \param id window identifier
2323 \return \c true if operation is completed successfully and \c false otherwise
2326 class TCloseView: public SALOME_Event
2329 typedef bool TResult;
2332 TCloseView( const int id )
2333 : myResult( false ),
2335 virtual void Execute()
2337 SUIT_ViewWindow* wnd = getWnd( myWndId );
2340 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2349 bool SalomePyQt::closeView( const int id )
2351 return ProcessEvent( new TCloseView( id ) );
2355 \fn int SalomePyQt::cloneView( const int id )
2356 \brief Clone view (if this operation is supported for specified view type)
2357 \param id window identifier
2358 \return integer identifier of the cloned view or -1 or operation could not be performed
2361 class TCloneView: public SALOME_Event
2364 typedef int TResult;
2367 TCloneView( const int id )
2370 virtual void Execute()
2372 SUIT_ViewWindow* wnd = getWnd( myWndId );
2375 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2378 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2380 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2381 occView->onCloneView();
2383 wnd = viewMgr->getActiveView();
2385 myResult = wnd->getId();
2387 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2389 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2390 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2391 if ( viewMgr2d && srcWnd2d )
2393 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2394 myResult = resWnd->getId();
2401 int SalomePyQt::cloneView( const int id )
2403 return ProcessEvent( new TCloneView( id ) );
2407 \fn bool SalomePyQt::isViewVisible( const int id )
2408 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2409 \param id window identifier
2410 \return \c true if view is visible and \c false otherwise
2413 class TIsViewVisible: public SALOME_Event
2416 typedef bool TResult;
2419 TIsViewVisible( const int id )
2420 : myResult( false ),
2422 virtual void Execute()
2424 SUIT_ViewWindow* wnd = getWnd( myWndId );
2427 QWidget* p = wnd->parentWidget();
2428 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2432 bool SalomePyQt::isViewVisible( const int id )
2434 return ProcessEvent( new TIsViewVisible( id ) );
2438 \fn bool SalomePyQt::groupAllViews()
2439 \brief Group all views to the single tab area
2440 \return \c true if operation is completed successfully and \c false otherwise
2443 class TGroupAllViews: public SALOME_Event
2446 typedef bool TResult;
2449 : myResult( false ) {}
2450 virtual void Execute()
2452 SalomeApp_Application* app = getApplication();
2455 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2458 QtxWorkstack* wStack = tabDesk->workstack();
2468 bool SalomePyQt::groupAllViews()
2470 return ProcessEvent( new TGroupAllViews() );
2474 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2475 \brief Split tab area to which view with identifier belongs to
2476 \param id window identifier
2477 \param ori orientation of split operation
2478 \param action action to be performed
2479 \return \c true if operation is completed successfully \c false otherwise
2482 class TSplitView: public SALOME_Event
2485 typedef bool TResult;
2490 TSplitView( const int id,
2491 const Orientation ori,
2492 const Action action )
2493 : myResult( false ),
2496 myAction( action ) {}
2497 virtual void Execute()
2499 SUIT_ViewWindow* wnd = getWnd( myWndId );
2503 // wnd->setFocus(); ???
2506 if ( getApplication() )
2508 STD_TabDesktop* desk =
2509 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2512 QtxWorkstack* wStack = desk->workstack();
2515 Qt::Orientation qtOri =
2516 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2518 QtxWorkstack::SplitType sType;
2519 if ( myAction == MoveWidget )
2520 sType = QtxWorkstack::SplitMove;
2521 else if ( myAction == LeaveWidget )
2522 sType = QtxWorkstack::SplitStay;
2524 sType = QtxWorkstack::SplitAt;
2526 wStack->Split( wnd, qtOri, sType );
2534 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2536 return ProcessEvent( new TSplitView( id, ori, action ) );
2540 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
2541 \brief Move view with the first identifier to the same area which
2542 another view with the second identifier belongs to
2543 \param id source window identifier
2544 \param id_to destination window identifier
2545 param before specifies whether the first viewt has to be moved before or after
2547 \return \c true if operation is completed successfully and \c false otherwise
2550 class TMoveView: public SALOME_Event
2553 typedef bool TResult;
2558 TMoveView( const int id, const int id_to, const bool before )
2559 : myResult( false ),
2562 myIsBefore( before ) {}
2563 virtual void Execute()
2565 SUIT_ViewWindow* wnd = getWnd( myWndId );
2566 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
2567 if ( wnd && wnd_to )
2569 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
2570 getApplication()->desktop() )->workstack();
2572 myResult = wStack->move( wnd, wnd_to, myIsBefore );
2576 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
2578 return ProcessEvent( new TMoveView( id, id_to, before ) );
2582 \fn QList<int> SalomePyQt::neighbourViews( const int id )
2583 \brief Get list of views identifiers that belongs to the same area as
2584 specified view (excluding it)
2585 \param id window identifier
2586 \return list of views identifiers
2589 class TNeighbourViews: public SALOME_Event
2592 typedef QList<int> TResult;
2595 TNeighbourViews( const int id )
2597 virtual void Execute()
2600 SUIT_ViewWindow* wnd = getWnd( myWndId );
2603 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
2604 getApplication()->desktop() )->workstack();
2607 QWidgetList wgList = wStack->windowList( wnd );
2609 foreach ( wg, wgList )
2611 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
2612 if ( tmpWnd && tmpWnd != wnd )
2613 myResult.append( tmpWnd->getId() );
2619 QList<int> SalomePyQt::neighbourViews( const int id )
2621 return ProcessEvent( new TNeighbourViews( id ) );