1 // Copyright (C) 2007-2012 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
23 // File : SalomePyQt.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 // E.A. : On windows with python 2.6, there is a conflict
28 // E.A. : between pymath.h and Standard_math.h which define
29 // E.A. : some same symbols : acosh, asinh, ...
30 #include <Standard_math.hxx>
34 #include <SALOME_PYQT_ModuleLight.h> // this include must be first!!!
35 #include <SALOME_PYQT_DataModelLight.h>
36 #include "SalomePyQt.h"
38 #include <QApplication>
42 #include <QStringList>
45 #include <SALOME_Event.h>
47 #include <QtxActionMenuMgr.h>
48 #include <QtxActionGroup.h>
49 #include <QtxWorkstack.h>
50 #include <QtxTreeView.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Tools.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_ViewWindow.h>
57 #include <SUIT_DataBrowser.h>
58 #include <STD_TabDesktop.h>
59 #include <LightApp_Application.h>
60 #include <LightApp_Study.h>
61 #include <LightApp_SelectionMgr.h>
62 #include <LogWindow.h>
63 #include <OCCViewer_ViewWindow.h>
64 #include <Plot2d_ViewManager.h>
65 #include <Plot2d_ViewWindow.h>
68 \brief Get the currently active application.
70 \return active application object or 0 if there is no any
72 static LightApp_Application* getApplication()
74 if ( SUIT_Session::session() )
75 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
80 \brief Get the currently active study.
82 \return active study or 0 if there is no study opened
84 static LightApp_Study* getActiveStudy()
86 if ( getApplication() )
87 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
92 \brief Get the currently active module.
94 This function returns correct result only if Python-based
95 module is currently active. Otherwize, 0 is returned.
97 static SALOME_PYQT_ModuleLight* getActiveModule()
99 SALOME_PYQT_ModuleLight* module = 0;
100 if ( LightApp_Application* anApp = getApplication() ) {
101 module = SALOME_PYQT_ModuleLight::getInitModule();
103 module = dynamic_cast<SALOME_PYQT_ModuleLight*>( anApp->activeModule() );
109 \class SALOME_Selection
110 \brief The class represents selection which can be used in Python.
114 \brief Map of created selection objects.
117 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
120 \brief Get the selection object for the specified application.
122 Finds or creates the selection object (one per study).
124 \param app application object
125 \return selection object or 0 if \a app is invalid
127 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
129 SALOME_Selection* sel = 0;
130 if ( app && SelMap.find( app ) != SelMap.end() )
133 sel = SelMap[ app ] = new SALOME_Selection( app );
139 \param p parent object
141 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
143 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
145 mySelMgr = app->selectionMgr();
146 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
147 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
154 SALOME_Selection::~SALOME_Selection()
156 LightApp_Application* app = 0;
157 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
158 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
159 if ( it.value() == this ) app = it.key();
161 if ( app ) SelMap.remove( app );
165 \brief Called when selection manager is destroyed (usually
166 when the study is closed).
168 void SALOME_Selection::onSelMgrDestroyed()
174 \brief Clear the selection.
176 void SALOME_Selection::Clear()
178 class TEvent: public SALOME_Event {
179 LightApp_SelectionMgr* mySelMgr;
181 TEvent( LightApp_SelectionMgr* selMgr )
182 : mySelMgr( selMgr ) {}
183 virtual void Execute() {
185 mySelMgr->clearSelected();
188 ProcessVoidEvent( new TEvent( mySelMgr ) );
192 \brief Clear the selection.
194 void SALOME_Selection::ClearIObjects()
200 Removes all selection filters.
202 void SALOME_Selection::ClearFilters()
204 class TEvent: public SALOME_Event {
205 LightApp_SelectionMgr* mySelMgr;
207 TEvent( LightApp_SelectionMgr* selMgr )
208 : mySelMgr( selMgr ) {}
209 virtual void Execute() {
211 mySelMgr->clearFilters();
214 ProcessVoidEvent( new TEvent( mySelMgr ) );
219 \brief The class provides utility functions which can be used in the Python
220 to operate with the SALOME GUI.
222 All the functionality of this class is implemented as static methods, so they
223 can be called with the class name prefixed or via creation of the class instance.
224 For example, next both ways of SalomePyQt class usage are legal:
226 from SalomePyQt import *
228 # using SalomePyQt class instance
229 desktop = sg.getDesktop()
230 # using SalomePyQt class directly
231 menubar = SalomePyQt.getMainMenuBar()
236 \fn QWidget* SalomePyQt::getDesktop();
237 \brief Get the active application's desktop window.
238 \return desktop window or 0 if there is no any
241 class TGetDesktopEvent: public SALOME_Event
244 typedef QWidget* TResult;
246 TGetDesktopEvent() : myResult( 0 ) {}
247 virtual void Execute()
249 if ( getApplication() )
250 myResult = (QWidget*)( getApplication()->desktop() );
253 QWidget* SalomePyQt::getDesktop()
255 return ProcessEvent( new TGetDesktopEvent() );
259 \fn QWidget* SalomePyQt::getMainFrame();
260 \brief Get current application's main frame widget [obsolete].
262 Main frame widget is an internal widget of the application
263 desktop window (workspace).
265 \return workspace widget (0 on any error)
268 class TGetMainFrameEvent: public SALOME_Event
271 typedef QWidget* TResult;
273 TGetMainFrameEvent() : myResult( 0 ) {}
274 virtual void Execute()
276 if ( getApplication() ) {
277 SUIT_Desktop* aDesktop = getApplication()->desktop();
278 myResult = (QWidget*)( aDesktop->centralWidget() );
282 QWidget* SalomePyQt::getMainFrame()
284 return ProcessEvent( new TGetMainFrameEvent() );
288 \fn QMenuBar* SalomePyQt::getMainMenuBar();
289 \brief Get current application desktop's main menu.
290 \return main menu object (0 on any error)
293 class TGetMainMenuBarEvent: public SALOME_Event
296 typedef QMenuBar* TResult;
298 TGetMainMenuBarEvent() : myResult( 0 ) {}
299 virtual void Execute()
301 if ( LightApp_Application* anApp = getApplication() ) {
302 myResult = anApp->desktop()->menuBar();
306 QMenuBar* SalomePyQt::getMainMenuBar()
308 return ProcessEvent( new TGetMainMenuBarEvent() );
312 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
313 \brief Get main menu's child popup submenu by its identifier.
315 This function is obsolete.
316 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
318 \param menu menu identifier
319 \return popup submenu object or 0 if it does not exist
323 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
324 \brief Get main menu's child popup submenu by its name.
326 The function creates menu if it does not exist.
328 \param menu menu name
329 \return popup submenu object (0 on any error)
332 class TGetPopupMenuEvent: public SALOME_Event
335 typedef QMenu* TResult;
338 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
339 virtual void Execute()
341 LightApp_Application* anApp = getApplication();
342 if ( anApp && !myMenuName.isEmpty() ) {
343 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
344 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
350 \brief Get menu item title
352 \param menuId menu identifier
353 \return menu title (localized)
355 static QString getMenuName( const QString& menuId )
357 QStringList contexts;
358 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
359 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
360 QString menuName = menuId;
361 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
362 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
366 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
371 menuName = getMenuName( "MEN_DESK_FILE" ); break;
373 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
375 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
377 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
379 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
381 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
383 menuName = getMenuName( "MEN_DESK_HELP" ); break;
385 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
387 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
389 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
393 \fn QTreeView* SalomePyQt::getObjectBrowser();
394 \brief Get object browser
395 \return object browser for the active study or 0 in case of error
398 class TGetObjectBrowserEvent: public SALOME_Event
401 typedef QTreeView* TResult;
403 TGetObjectBrowserEvent() : myResult( 0 ) {}
404 virtual void Execute()
406 LightApp_Application* anApp = getApplication();
408 myResult = anApp->objectBrowser()->treeView();
412 QTreeView* SalomePyQt::getObjectBrowser()
414 return ProcessEvent( new TGetObjectBrowserEvent() );
418 \fn int SalomePyQt::getStudyId();
419 \brief Get active study's identifier.
420 \return active study ID or 0 if there is no active study
423 class TGetStudyIdEvent: public SALOME_Event
428 TGetStudyIdEvent() : myResult( 0 ) {}
429 virtual void Execute()
431 if ( LightApp_Study* aStudy = getActiveStudy() ) {
432 myResult = aStudy->id();
436 int SalomePyQt::getStudyId()
438 return ProcessEvent( new TGetStudyIdEvent() );
442 \fn SALOME_Selection* SalomePyQt::getSelection()
443 \brief Get the selection object for the current study.
445 Creates a Selection object if it has not been created yet.
447 \return selection object (0 on error)
450 class TGetSelectionEvent: public SALOME_Event
453 typedef SALOME_Selection* TResult;
455 TGetSelectionEvent() : myResult( 0 ) {}
456 virtual void Execute()
458 myResult = SALOME_Selection::GetSelection( getApplication() );
461 SALOME_Selection* SalomePyQt::getSelection()
463 return ProcessEvent( new TGetSelectionEvent() );
467 \fn void SalomePyQt::putInfo( const QString& msg, const int sec )
468 \brief Put an information message to the current application's
471 Optional second delay parameter (\a sec) can be used to specify
472 time of the message diplaying in seconds. If this parameter is less
473 or equal to zero, the constant message will be put.
475 \param msg message text
476 \param sec message displaying time in seconds
479 class TPutInfoEvent: public SALOME_Event
484 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
485 virtual void Execute()
487 if ( LightApp_Application* anApp = getApplication() ) {
488 anApp->putInfo( myMsg, mySecs * 1000 );
492 void SalomePyQt::putInfo( const QString& msg, const int sec )
494 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
498 \fn const QString SalomePyQt::getActiveComponent();
499 \brief Get the currently active module name (for the current study).
500 \return active module name or empty string if there is no active module
503 class TGetActiveComponentEvent: public SALOME_Event
506 typedef QString TResult;
508 TGetActiveComponentEvent() {}
509 virtual void Execute()
511 if ( LightApp_Application* anApp = getApplication() ) {
512 if ( CAM_Module* mod = anApp->activeModule() ) {
513 myResult = mod->name();
518 const QString SalomePyQt::getActiveComponent()
520 return ProcessEvent( new TGetActiveComponentEvent() );
524 \fn PyObject* SalomePyQt::getActivePythonModule()
525 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
526 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
529 class TGetActivePyModuleEvent: public SALOME_Event
532 typedef PyObject* TResult;
534 TGetActivePyModuleEvent() : myResult( 0 ) {}
535 virtual void Execute()
537 SALOME_PYQT_ModuleLight* module = getActiveModule();
539 myResult = (PyObject*)module->getPythonModule();
542 PyObject* SalomePyQt::getActivePythonModule()
544 return ProcessEvent( new TGetActivePyModuleEvent() );
548 \fn bool SalomePyQt::activateModule( const QString& modName )
549 \brief Activates SALOME module with the given name
550 \return True if the module has been activated and False otherwise.
553 class TActivateModuleEvent: public SALOME_Event
556 typedef bool TResult;
558 QString myModuleName;
559 TActivateModuleEvent( const QString& modName )
560 : myResult( false ), myModuleName( modName ) {}
561 virtual void Execute()
563 if ( LightApp_Application* anApp = getApplication() ) {
564 myResult = anApp->activateModule( myModuleName );
568 bool SalomePyQt::activateModule( const QString& modName )
570 return ProcessEvent( new TActivateModuleEvent( modName ) );
574 \brief Update an Object Browser of the specified (by identifier) study.
576 If \a studyId <= 0 the active study's object browser is updated.
577 The \a updateSelection parameter is obsolete and currently is not used.
578 This parameter will be removed in future, so try to avoid its usage in
581 \brief studyId study identifier
582 \brief updateSelection update selection flag (not used)
585 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
587 class TEvent: public SALOME_Event
590 bool myUpdateSelection;
592 TEvent( const int studyId, bool updateSelection )
593 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
594 virtual void Execute()
596 if ( SUIT_Session::session() ) {
597 if ( getActiveStudy() && myStudyId <= 0 )
598 myStudyId = getActiveStudy()->id();
599 if ( myStudyId > 0 ) {
600 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
601 QList<SUIT_Application*>::Iterator it;
602 for( it = apps.begin(); it != apps.end(); ++it ) {
603 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
604 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
605 anApp->updateObjectBrowser();
613 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
618 SalomePyQt::isModified()
619 \return The modification status of the data model
620 for the currently active Python module
623 class TIsModifiedEvent: public SALOME_Event
626 typedef bool TResult;
628 TIsModifiedEvent() : myResult( false ) {}
629 virtual void Execute()
631 SALOME_PYQT_ModuleLight* module = getActiveModule();
635 SALOME_PYQT_DataModelLight* aModel =
636 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
638 myResult = aModel->isModified();
641 bool SalomePyQt::isModified()
643 return ProcessEvent(new TIsModifiedEvent());
647 SalomePyQt::setModified()
649 Sets the modification status of the data model for
650 the currently active Python module. This method should be used
651 by the Python code in order to enable/disable "Save" operation
652 depending on the module's data state.
654 \param New modification status of the data model
658 void SalomePyQt::setModified( bool flag )
660 class TEvent: public SALOME_Event
666 virtual void Execute()
668 SALOME_PYQT_ModuleLight* module = getActiveModule();
672 SALOME_PYQT_DataModelLight* aModel =
673 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
674 LightApp_Application* aLApp =
675 dynamic_cast<LightApp_Application*>( module->application() );
676 if ( !aModel || !aLApp )
679 aModel->setModified( myFlag );
680 aLApp->updateActions();
683 ProcessVoidEvent( new TEvent( flag ) );
687 \brief Default resource file section name.
690 static const char* DEFAULT_SECTION = "SalomePyQt";
693 \brief Add string setting to the application preferences.
695 The parameter \a autoValue is obsolete parameter and currently is not used.
696 This parameter will be removed in future, so try to avoid its usage in
699 This function is obsolete. Use one of addSetting() instead.
701 \param name setting name (it should be of kind <section:setting> where
702 \c section is resources section name and \c setting is setting name)
703 \param value new setting value
704 \param autoValue (not used)
706 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
708 class TEvent: public SALOME_Event
714 TEvent( const QString& name, const QString& value, bool autoValue )
715 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
716 virtual void Execute() {
717 if ( SUIT_Session::session() ) {
718 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
719 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
720 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
721 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
722 if ( !_sec.isEmpty() && !_nam.isEmpty() )
723 resMgr->setValue( _sec, _nam, myValue );
727 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
731 \brief Add integer setting to the application preferences.
733 The parameter \a autoValue is obsolete parameter and currently is not used.
734 This parameter will be removed in future, so try to avoid its usage in
737 This function is obsolete. Use one of addSetting() instead.
739 \param name setting name (it should be of kind <section:setting> where
740 \c section is resources section name and \c setting is setting name)
741 \param value new setting value
742 \param autoValue (not used)
744 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
746 class TEvent: public SALOME_Event
752 TEvent( const QString& name, const int value, bool autoValue )
753 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
754 virtual void Execute()
756 if ( SUIT_Session::session() ) {
757 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
758 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
759 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
760 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
761 if ( !_sec.isEmpty() && !_nam.isEmpty() )
762 resMgr->setValue( _sec, _nam, myValue );
766 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
770 \brief Add double setting to the application preferences.
772 The parameter \a autoValue is obsolete parameter and currently is not used.
773 This parameter will be removed in future, so try to avoid its usage in
776 This function is obsolete. Use one of addSetting() instead.
778 \param name setting name (it should be of kind <section:setting> where
779 \c section is resources section name and \c setting is setting name)
780 \param value new setting value
781 \param autoValue (not used)
783 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
785 class TEvent: public SALOME_Event
791 TEvent( const QString& name, const double value, bool autoValue )
792 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
793 virtual void Execute()
795 if ( SUIT_Session::session() ) {
796 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
797 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
798 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
799 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
800 if ( !_sec.isEmpty() && !_nam.isEmpty() )
801 resMgr->setValue( _sec, _nam, myValue );
805 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
809 \brief Add boolean setting to the application preferences.
811 The parameter \a autoValue is obsolete parameter and currently is not used.
812 This parameter will be removed in future, so try to avoid its usage in
815 This function is obsolete. Use one of addSetting() instead.
817 \param name setting name (it should be of kind <section:setting> where
818 \c section is resources section name and \c setting is setting name)
819 \param value new setting value
820 \param autoValue (not used)
822 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
824 class TEvent: public SALOME_Event
830 TEvent( const QString& name, const bool value, bool autoValue )
831 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
832 virtual void Execute()
834 if ( SUIT_Session::session() ) {
835 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
836 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
837 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
838 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
839 if ( !_sec.isEmpty() && !_nam.isEmpty() )
840 resMgr->setValue( _sec, _nam, myValue );
844 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
848 \brief Remove setting from the application preferences.
850 This function is obsolete. Use removeSetting() instead.
852 \param name setting name (it should be of kind <section:setting> where
853 \c section is resources section name and \c setting is setting name)
855 void SalomePyQt::removeSettings( const QString& name )
857 class TEvent: public SALOME_Event {
860 TEvent( const QString& name ) : myName( name ) {}
861 virtual void Execute() {
862 if ( SUIT_Session::session() ) {
863 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
864 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
865 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
866 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
867 if ( !_sec.isEmpty() && !_nam.isEmpty() )
868 resMgr->remove( _sec, _nam );
872 ProcessVoidEvent( new TEvent( name ) );
876 \fn QString SalomePyQt::getSetting( const QString& name );
877 \brief Get application setting value (as string represenation).
879 This function is obsolete. Use stringSetting(), integerSetting(),
880 boolSetting(), stringSetting() or colorSetting() instead.
882 \param name setting name (it should be of kind <section:setting> where
883 \c section is resources section name and \c setting is setting name)
884 \return setting name (empty string if setting name is invalid)
887 class TGetSettingEvent: public SALOME_Event
890 typedef QString TResult;
893 TGetSettingEvent( const QString& name ) : myName( name ) {}
894 virtual void Execute()
896 if ( SUIT_Session::session() ) {
897 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
898 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
899 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
900 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
901 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
905 QString SalomePyQt::getSetting( const QString& name )
907 return ProcessEvent( new TGetSettingEvent( name ) );
911 \brief Add double setting to the application preferences.
912 \param section resources file section name
913 \param name setting name
914 \param value new setting value
916 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
918 class TEvent: public SALOME_Event
924 TEvent( const QString& section, const QString& name, double value )
925 : mySection( section ), myName( name ), myValue( value ) {}
926 virtual void Execute()
928 if ( SUIT_Session::session() ) {
929 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
930 if ( !mySection.isEmpty() && !myName.isEmpty() )
931 resMgr->setValue( mySection, myName, myValue );
935 ProcessVoidEvent( new TEvent( section, name, value ) );
939 \brief Add integer setting to the application preferences.
940 \param section resources file section name
941 \param name setting name
942 \param value new setting value
944 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
946 class TEvent: public SALOME_Event
952 TEvent( const QString& section, const QString& name, int value )
953 : mySection( section ), myName( name ), myValue( value ) {}
954 virtual void Execute()
956 if ( SUIT_Session::session() ) {
957 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
958 if ( !mySection.isEmpty() && !myName.isEmpty() )
959 resMgr->setValue( mySection, myName, myValue );
963 ProcessVoidEvent( new TEvent( section, name, value ) );
967 \brief Add boolean setting to the application preferences.
968 \param section resources file section name
969 \param name setting name
970 \param value new setting value
971 \param dumb this parameter is used in order to avoid sip compilation error
972 because of conflicting int and bool types
974 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
976 class TEvent: public SALOME_Event
982 TEvent( const QString& section, const QString& name, bool value )
983 : mySection( section ), myName( name ), myValue( value ) {}
984 virtual void Execute()
986 if ( SUIT_Session::session() ) {
987 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
988 if ( !mySection.isEmpty() && !myName.isEmpty() )
989 resMgr->setValue( mySection, myName, myValue );
993 ProcessVoidEvent( new TEvent( section, name, value ) );
997 \brief Add string setting to the application preferences.
998 \param section resources file section name
999 \param name setting name
1000 \param value new setting value
1002 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1004 class TEvent: public SALOME_Event
1010 TEvent( const QString& section, const QString& name, const QString& value )
1011 : mySection( section ), myName( name ), myValue( value ) {}
1012 virtual void Execute()
1014 if ( SUIT_Session::session() ) {
1015 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1016 if ( !mySection.isEmpty() && !myName.isEmpty() )
1017 resMgr->setValue( mySection, myName, myValue );
1021 ProcessVoidEvent( new TEvent( section, name, value ) );
1025 \brief Add color setting to the application preferences.
1026 \param section resources file section name
1027 \param name setting name
1028 \param value new setting value
1030 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1032 class TEvent: public SALOME_Event
1038 TEvent( const QString& section, const QString& name, const QColor& value )
1039 : mySection( section ), myName( name ), myValue( value ) {}
1040 virtual void Execute()
1042 if ( SUIT_Session::session() ) {
1043 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1044 if ( !mySection.isEmpty() && !myName.isEmpty() )
1045 resMgr->setValue( mySection, myName, myValue );
1049 ProcessVoidEvent( new TEvent( section, name, value ) );
1053 \fn int SalomePyQt::integerSetting( const QString& section,
1054 const QString& name,
1056 \brief Get integer setting from the application preferences.
1057 \param section resources file section name
1058 \param name setting name
1059 \param def default value which is returned if the setting is not found
1060 \return setting value
1063 class TGetIntSettingEvent: public SALOME_Event
1066 typedef int TResult;
1071 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1072 : mySection( section ), myName( name ), myDefault( def ) {}
1073 virtual void Execute()
1075 if ( SUIT_Session::session() ) {
1076 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1077 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1081 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1083 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1087 \fn double SalomePyQt::doubleSetting( const QString& section,
1088 const QString& name,
1090 \brief Get double setting from the application preferences.
1091 \param section resources file section name
1092 \param name setting name
1093 \param def default value which is returned if the setting is not found
1094 \return setting value
1097 class TGetDblSettingEvent: public SALOME_Event
1100 typedef double TResult;
1105 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1106 : mySection( section ), myName( name ), myDefault( def ) {}
1107 virtual void Execute()
1109 if ( SUIT_Session::session() ) {
1110 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1111 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1115 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1117 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1121 \fn bool SalomePyQt::boolSetting( const QString& section,
1122 const QString& name,
1124 \brief Get boolean setting from the application preferences.
1125 \param section resources file section name
1126 \param name setting name
1127 \param def default value which is returned if the setting is not found
1128 \return setting value
1131 class TGetBoolSettingEvent: public SALOME_Event
1134 typedef bool TResult;
1139 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1140 : mySection( section ), myName( name ), myDefault( def ) {}
1141 virtual void Execute()
1143 if ( SUIT_Session::session() ) {
1144 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1145 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1149 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1151 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1155 \fn QString SalomePyQt::stringSetting( const QString& section,
1156 const QString& name,
1157 const QString& def );
1158 \brief Get string setting from the application preferences.
1159 \param section resources file section name
1160 \param name setting name
1161 \param def default value which is returned if the setting is not found
1162 \return setting value
1165 class TGetStrSettingEvent: public SALOME_Event
1168 typedef QString TResult;
1173 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1174 : mySection( section ), myName( name ), myDefault( def ) {}
1175 virtual void Execute()
1177 if ( SUIT_Session::session() ) {
1178 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1179 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1183 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1185 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1189 \fn QColor SalomePyQt::colorSetting( const QString& section,
1190 const QString& name,
1192 \brief Get color setting from the application preferences.
1193 \param section resources file section name
1194 \param name setting name
1195 \param def default value which is returned if the setting is not found
1196 \return setting value
1199 class TGetColorSettingEvent: public SALOME_Event
1202 typedef QColor TResult;
1207 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1208 : mySection( section ), myName( name ), myDefault( def ) {}
1209 virtual void Execute()
1211 if ( SUIT_Session::session() ) {
1212 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1213 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1217 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1219 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1223 \brief Remove setting from the application preferences.
1224 \param section resources file section name
1225 \param name setting name
1227 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1229 class TEvent: public SALOME_Event
1234 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1235 virtual void Execute()
1237 if ( SUIT_Session::session() ) {
1238 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1239 if ( !mySection.isEmpty() && !myName.isEmpty() )
1240 resMgr->remove( mySection, myName );
1244 ProcessVoidEvent( new TEvent( section, name ) );
1248 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1249 \brief Check setting existence in the application preferences.
1250 \param section resources file section name
1251 \param name setting name
1252 \return \c true if setting exists
1255 class THasColorSettingEvent: public SALOME_Event
1258 typedef bool TResult;
1262 THasColorSettingEvent( const QString& section, const QString& name )
1263 : mySection( section ), myName( name ) {}
1264 virtual void Execute()
1266 if ( SUIT_Session::session() ) {
1267 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1268 myResult = resMgr->hasValue( mySection, myName );
1272 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1274 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1278 \fn QString SalomePyQt::getFileName( QWidget* parent,
1279 const QString& initial,
1280 const QStringList& filters,
1281 const QString& caption,
1283 \brief Show 'Open/Save file' dialog box for file selection
1284 and return a user's choice (selected file name).
1285 \param parent parent widget
1286 \param initial initial directory the dialog box to be opened in
1287 \param filters list of files filters (wildcards)
1288 \param caption dialog box title
1289 \param open if \c true, "Open File" dialog box is shown;
1290 otherwise "Save File" dialog box is shown
1291 \return selected file name (null string if user cancels operation)
1294 class TGetFileNameEvent: public SALOME_Event
1297 typedef QString TResult;
1301 QStringList myFilters;
1304 TGetFileNameEvent( QWidget* parent,
1305 const QString& initial,
1306 const QStringList& filters,
1307 const QString& caption,
1309 : myParent ( parent ),
1310 myInitial( initial ),
1311 myFilters( filters ),
1312 myCaption( caption ),
1314 virtual void Execute()
1316 if ( LightApp_Application* anApp = getApplication() ) {
1317 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1318 myCaption, myParent );
1322 QString SalomePyQt::getFileName( QWidget* parent,
1323 const QString& initial,
1324 const QStringList& filters,
1325 const QString& caption,
1328 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1332 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1333 const QString& initial,
1334 const QStringList& filters,
1335 const QString& caption );
1336 \brief Show 'Open files' dialog box for multiple files selection
1337 and return a user's choice (selected file names list).
1338 \param parent parent widget
1339 \param initial initial directory the dialog box to be opened in
1340 \param filters list of files filters (wildcards)
1341 \param caption dialog box title
1342 \return selected file names list (empty list if user cancels operation)
1345 class TGetOpenFileNamesEvent: public SALOME_Event
1348 typedef QStringList TResult;
1352 QStringList myFilters;
1354 TGetOpenFileNamesEvent( QWidget* parent,
1355 const QString& initial,
1356 const QStringList& filters,
1357 const QString& caption )
1358 : myParent ( parent ),
1359 myInitial( initial ),
1360 myFilters( filters ),
1361 myCaption( caption ) {}
1362 virtual void Execute()
1364 if ( LightApp_Application* anApp = getApplication() ) {
1365 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1369 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1370 const QString& initial,
1371 const QStringList& filters,
1372 const QString& caption )
1374 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1378 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1379 const QString& initial,
1380 const QString& caption );
1381 \brief Show 'Get Directory' dialog box for the directory selection
1382 and return a user's choice (selected directory name).
1383 \param parent parent widget
1384 \param initial initial directory the dialog box to be opened in
1385 \param caption dialog box title
1386 \return selected directory name (null string if user cancels operation)
1389 class TGetExistingDirectoryEvent: public SALOME_Event
1392 typedef QString TResult;
1397 TGetExistingDirectoryEvent( QWidget* parent,
1398 const QString& initial,
1399 const QString& caption )
1400 : myParent ( parent ),
1401 myInitial( initial ),
1402 myCaption( caption ) {}
1403 virtual void Execute()
1405 if ( LightApp_Application* anApp = getApplication() ) {
1406 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1410 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1411 const QString& initial,
1412 const QString& caption )
1414 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1418 \fn QString SalomePyQt::loadIcon( const QString& filename );
1419 \brief Load an icon from the module resources by the specified file name.
1420 \param filename icon file name
1423 class TLoadIconEvent: public SALOME_Event
1426 typedef QIcon TResult;
1430 TLoadIconEvent( const QString& module, const QString& filename )
1431 : myModule( module ),
1432 myFileName ( filename ) {}
1433 virtual void Execute()
1435 if ( LightApp_Application* anApp = getApplication() ) {
1436 if ( !myFileName.isEmpty() ) {
1437 QPixmap pixmap = anApp->resourceMgr()->loadPixmap( myModule,
1438 QApplication::translate( myModule.toLatin1().data(),
1439 myFileName.toLatin1().data() ) );
1440 if ( !pixmap.isNull() )
1441 myResult = QIcon( pixmap );
1446 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1448 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1452 \brief Open external browser to display context help information.
1455 Current implementation does nothing.
1457 \param source documentation (HTML) file name
1458 \param context context (for example, HTML ancor name)
1460 void SalomePyQt::helpContext( const QString& source, const QString& context )
1462 class TEvent: public SALOME_Event
1467 TEvent( const QString& source, const QString& context )
1468 : mySource( source ), myContext( context ) {}
1469 virtual void Execute()
1471 if ( LightApp_Application* anApp = getApplication() ) {
1472 anApp->onHelpContextModule( "", mySource, myContext );
1476 ProcessVoidEvent( new TEvent( source, context ) );
1480 \fn bool SalomePyQt::dumpView( const QString& filename );
1481 \brief Dump the contents of the currently active view window
1482 to the image file in the specified format.
1484 For the current moment JPEG, PNG and BMP images formats are supported.
1485 The image format is defined automatically by the file name extension.
1486 By default, BMP format is used.
1488 \param filename image file name
1489 \return operation status (\c true on success)
1492 class TDumpViewEvent: public SALOME_Event
1495 typedef bool TResult;
1498 TDumpViewEvent( const QString& filename )
1499 : myResult ( false ), myFileName( filename ) {}
1500 virtual void Execute()
1502 if ( LightApp_Application* anApp = getApplication() ) {
1503 SUIT_ViewManager* vm = anApp->activeViewManager();
1505 SUIT_ViewWindow* vw = vm->getActiveView();
1507 QImage im = vw->dumpView();
1508 if ( !im.isNull() && !myFileName.isEmpty() ) {
1509 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
1510 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
1511 if ( fmt == "JPG" ) fmt = "JPEG";
1512 myResult = im.save( myFileName, fmt.toLatin1() );
1519 bool SalomePyQt::dumpView( const QString& filename )
1521 return ProcessEvent( new TDumpViewEvent( filename ) );
1525 \fn int SalomePyQt::defaultMenuGroup();
1526 \brief Get detault menu group identifier which can be used when
1527 creating menus (insert custom menu commands).
1528 \return default menu group ID
1531 class TDefMenuGroupEvent: public SALOME_Event
1534 typedef int TResult;
1536 TDefMenuGroupEvent() : myResult( -1 ) {}
1537 virtual void Execute()
1539 myResult = SALOME_PYQT_ModuleLight::defaultMenuGroup();
1542 int SalomePyQt::defaultMenuGroup()
1544 return ProcessEvent( new TDefMenuGroupEvent() );
1550 CrTool( const QString& tBar )
1551 : myCase( 0 ), myTbName( tBar ) {}
1552 CrTool( const int id, const int tBar, const int idx )
1553 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1554 CrTool( const int id, const QString& tBar, const int idx )
1555 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1556 CrTool( QAction* action, const int tbId, const int id, const int idx )
1557 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1558 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1559 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1561 int execute( SALOME_PYQT_ModuleLight* module ) const
1566 return module->createTool( myTbName );
1568 return module->createTool( myId, myTbId, myIndex );
1570 return module->createTool( myId, myTbName, myIndex );
1572 return module->createTool( myAction, myTbId, myId, myIndex );
1574 return module->createTool( myAction, myTbName, myId, myIndex );
1588 class TCreateToolEvent: public SALOME_Event
1591 typedef int TResult;
1593 const CrTool& myCrTool;
1594 TCreateToolEvent( const CrTool& crTool )
1595 : myResult( -1 ), myCrTool( crTool ) {}
1596 virtual void Execute()
1598 SALOME_PYQT_ModuleLight* module = getActiveModule();
1600 myResult = myCrTool.execute( module );
1605 \brief Create toolbar with specified name.
1606 \param tBar toolbar name
1607 \return toolbar ID or -1 if toolbar creation is failed
1609 int SalomePyQt::createTool( const QString& tBar )
1611 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1615 \brief Insert action with specified \a id to the toolbar.
1617 \param tBar toolbar ID
1618 \param idx required index in the toolbar
1619 \return action ID or -1 if action could not be added
1621 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1623 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1627 \brief Insert action with specified \a id to the toolbar.
1629 \param tBar toolbar name
1630 \param idx required index in the toolbar
1631 \return action ID or -1 if action could not be added
1633 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1635 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1639 \brief Insert action to the toolbar.
1641 \param tBar toolbar ID
1642 \param id required action ID
1643 \param idx required index in the toolbar
1644 \return action ID or -1 if action could not be added
1646 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1648 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1652 \brief Insert action to the toolbar.
1654 \param tBar toolbar name
1655 \param id required action ID
1656 \param idx required index in the toolbar
1657 \return action ID or -1 if action could not be added
1659 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1661 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1667 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1668 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1669 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1670 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1671 CrMenu( const int id, const int menu, const int group, const int idx )
1672 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1673 CrMenu( const int id, const QString& menu, const int group, const int idx )
1674 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1675 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1676 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1677 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1678 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1680 int execute( LightApp_Module* module ) const
1685 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1687 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1689 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1691 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1693 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1695 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1704 QString mySubMenuName;
1711 class TCreateMenuEvent: public SALOME_Event
1714 typedef int TResult;
1716 const CrMenu& myCrMenu;
1717 TCreateMenuEvent( const CrMenu& crMenu )
1718 : myResult( -1 ), myCrMenu( crMenu ) {}
1719 virtual void Execute()
1721 if ( LightApp_Application* anApp = getApplication() )
1723 LightApp_Module* module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
1725 myResult = myCrMenu.execute( module );
1731 \brief Create main menu.
1732 \param subMenu menu name
1733 \param menu parent menu ID
1734 \param id required menu ID
1735 \param group menu group ID
1736 \param idx required index in the menu
1737 \return menu ID or -1 if menu could not be added
1739 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1741 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1745 \brief Create main menu.
1746 \param subMenu menu name
1747 \param menu parent menu name (list of menu names separated by "|")
1748 \param id required menu ID
1749 \param group menu group ID
1750 \param idx required index in the menu
1751 \return menu ID or -1 if menu could not be added
1753 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1755 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1759 \brief Insert action to the main menu.
1761 \param menu parent menu ID
1762 \param group menu group ID
1763 \param idx required index in the menu
1764 \return action ID or -1 if action could not be added
1766 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1768 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1772 \brief Insert action to the main menu.
1774 \param menu parent menu name (list of menu names separated by "|")
1775 \param group menu group ID
1776 \param idx required index in the menu
1777 \return action ID or -1 if action could not be added
1779 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1781 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1785 \brief Insert action to the main menu.
1787 \param menu parent menu ID
1788 \param group menu group ID
1789 \param idx required index in the menu
1790 \return action ID or -1 if action could not be added
1792 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1794 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1798 \brief Insert action to the main menu.
1800 \param menu parent menu name (list of menu names separated by "|")
1801 \param group menu group ID
1802 \param idx required index in the menu
1803 \return action ID or -1 if action could not be added
1805 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1807 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1811 \fn QAction* SalomePyQt::createSeparator();
1812 \brief Create separator action which can be used in the menu or toolbar.
1813 \return new separator action
1816 class TCreateSepEvent: public SALOME_Event
1819 typedef QAction* TResult;
1823 virtual void Execute()
1825 SALOME_PYQT_ModuleLight* module = getActiveModule();
1827 myResult = (QAction*)module->separator();
1830 QAction* SalomePyQt::createSeparator()
1832 return ProcessEvent( new TCreateSepEvent() );
1836 \fn QAction* SalomePyQt::createAction( const int id,
1837 const QString& menuText,
1838 const QString& tipText,
1839 const QString& statusText,
1840 const QString& icon,
1843 \brief Create an action which can be then used in the menu or toolbar.
1844 \param id the unique id action to be registered to
1845 \param menuText action text which should appear in menu
1846 \param tipText text which should appear in the tooltip
1847 \param statusText text which should appear in the status bar when action is activated
1848 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1849 \param key the key accelrator for the action
1850 \param toggle if \c true the action is checkable
1853 class TCreateActionEvent: public SALOME_Event
1856 typedef QAction* TResult;
1861 QString myStatusText;
1865 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1866 const QString& statusText, const QString& icon, const int key, const bool toggle )
1867 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1868 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1869 virtual void Execute()
1871 SALOME_PYQT_ModuleLight* module = getActiveModule();
1873 myResult = (QAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1876 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1877 const QString& tipText, const QString& statusText,
1878 const QString& icon, const int key, const bool toggle )
1880 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1884 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1885 \brief Create an action group which can be then used in the menu or toolbar
1886 \param id : the unique id action group to be registered to
1887 \param exclusive : if \c true the action group does exclusive toggling
1890 struct TcreateActionGroupEvent: public SALOME_Event {
1891 typedef QtxActionGroup* TResult;
1895 TcreateActionGroupEvent( const int id, const bool exclusive )
1896 : myId( id ), myExclusive( exclusive ) {}
1897 virtual void Execute()
1899 SALOME_PYQT_ModuleLight* module = getActiveModule();
1901 myResult = module->createActionGroup( myId, myExclusive );
1904 QtxActionGroup* SalomePyQt::createActionGroup(const int id, const bool exclusive)
1906 return ProcessEvent( new TcreateActionGroupEvent( id, exclusive ) );
1910 \fn QAction* SalomePyQt::action( const int id )
1911 \brief Get action by specified identifier.
1912 \return action or 0 if action is not registered
1915 class TActionEvent: public SALOME_Event
1918 typedef QAction* TResult;
1921 TActionEvent( const int id )
1922 : myResult( 0 ), myId( id ) {}
1923 virtual void Execute()
1925 SALOME_PYQT_ModuleLight* module = getActiveModule();
1927 myResult = (QAction*)module->action( myId );
1930 QAction* SalomePyQt::action( const int id )
1932 return ProcessEvent( new TActionEvent( id ) );
1936 \fn int SalomePyQt::actionId( const QAction* a );
1937 \brief Get an action identifier.
1938 \return action ID or -1 if action is not registered
1941 class TActionIdEvent: public SALOME_Event
1944 typedef int TResult;
1946 const QAction* myAction;
1947 TActionIdEvent( const QAction* action )
1948 : myResult( -1 ), myAction( action ) {}
1949 virtual void Execute()
1951 SALOME_PYQT_ModuleLight* module = getActiveModule();
1953 myResult = module->actionId( myAction );
1956 int SalomePyQt::actionId( const QAction* a )
1958 return ProcessEvent( new TActionIdEvent( a ) );
1962 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1963 \brief Add global (not module-related) preferences group.
1964 \param label global preferences group name
1965 \return preferences group identifier
1968 class TAddGlobalPrefEvent: public SALOME_Event
1971 typedef int TResult;
1974 TAddGlobalPrefEvent( const QString& label )
1975 : myResult( -1 ), myLabel( label ) {}
1976 virtual void Execute()
1978 SALOME_PYQT_ModuleLight* module = getActiveModule();
1980 myResult = module->addGlobalPreference( myLabel );
1983 int SalomePyQt::addGlobalPreference( const QString& label )
1985 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
1989 \fn int SalomePyQt::addPreference( const QString& label );
1990 \brief Add module-related preferences group.
1991 \param label preferences group name
1992 \return preferences group identifier
1995 class TAddPrefEvent: public SALOME_Event
1998 typedef int TResult;
2001 TAddPrefEvent( const QString& label )
2002 : myResult( -1 ), myLabel( label ) {}
2003 virtual void Execute()
2005 SALOME_PYQT_ModuleLight* module = getActiveModule();
2007 myResult = module->addPreference( myLabel );
2010 int SalomePyQt::addPreference( const QString& label )
2012 return ProcessEvent( new TAddPrefEvent( label ) );
2016 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2017 const QString& section, const QString& param );
2018 \brief Add module-related preferences.
2019 \param label preferences group name
2020 \param pId parent preferences group id
2021 \param type preferences type
2022 \param section resources file section name
2023 \param param resources file setting name
2024 \return preferences identifier
2027 class TAddPrefParamEvent: public SALOME_Event
2030 typedef int TResult;
2037 TAddPrefParamEvent( const QString& label,
2038 const int pId, const int type,
2039 const QString& section,
2040 const QString& param )
2042 myLabel( label ), myPId( pId ), myType( type ),
2043 mySection( section ), myParam ( param ) {}
2044 virtual void Execute()
2046 SALOME_PYQT_ModuleLight* module = getActiveModule();
2048 myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam );
2051 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2052 const QString& section, const QString& param )
2054 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2058 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2059 \brief Get the preferences property.
2060 \param id preferences identifier
2061 \param prop preferences property name
2062 \return preferences property value or null QVariant if property is not set
2065 class TPrefPropEvent: public SALOME_Event
2068 typedef QVariant TResult;
2072 TPrefPropEvent( const int id, const QString& prop )
2073 : myId( id ), myProp( prop ) {}
2074 virtual void Execute()
2076 SALOME_PYQT_ModuleLight* module = getActiveModule();
2078 myResult = module->preferenceProperty( myId, myProp );
2081 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2083 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2087 \brief Set the preferences property.
2088 \param id preferences identifier
2089 \param prop preferences property name
2090 \param var preferences property value
2092 void SalomePyQt::setPreferenceProperty( const int id,
2093 const QString& prop,
2094 const QVariant& var )
2096 class TEvent: public SALOME_Event
2102 TEvent( const int id, const QString& prop, const QVariant& var )
2103 : myId( id ), myProp( prop ), myVar( var ) {}
2104 virtual void Execute()
2106 SALOME_PYQT_ModuleLight* module = getActiveModule();
2108 module->setPreferenceProperty( myId, myProp, myVar );
2111 ProcessVoidEvent( new TEvent( id, prop, var) );
2115 \brief Add the property value to the list of values.
2117 This method allows creating properties which are QList<QVariant>
2118 - there is no way to pass such values directly to QVariant parameter with PyQt.
2120 \param id preferences identifier
2121 \param prop preferences property name
2122 \param idx preferences property index
2123 \param var preferences property value for the index \a idx
2125 void SalomePyQt::addPreferenceProperty( const int id,
2126 const QString& prop,
2128 const QVariant& var )
2130 class TEvent: public SALOME_Event
2137 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2138 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2139 virtual void Execute()
2141 SALOME_PYQT_ModuleLight* module = getActiveModule();
2143 QVariant var = module->preferenceProperty( myId, myProp );
2144 if ( var.isValid() ) {
2145 if ( var.type() == QVariant::StringList ) {
2146 QStringList sl = var.toStringList();
2147 if ( myIdx >= 0 && myIdx < sl.count() )
2148 sl[myIdx] = myVar.toString();
2150 sl.append( myVar.toString() );
2151 module->setPreferenceProperty( myId, myProp, sl );
2153 else if ( var.type() == QVariant::List ) {
2154 QList<QVariant> vl = var.toList();
2155 if ( myIdx >= 0 && myIdx < vl.count() )
2159 module->setPreferenceProperty( myId, myProp, vl );
2165 module->setPreferenceProperty( myId, myProp, vl );
2170 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2174 \brief Put the message to the Log messages output window
2175 \param msg message text (it can be of simple rich text format)
2176 \param addSeparator boolean flag which specifies if it is necessary
2177 to separate the message with predefined separator
2179 void SalomePyQt::message( const QString& msg, bool addSeparator )
2181 class TEvent: public SALOME_Event
2186 TEvent( const QString& msg, bool addSeparator )
2187 : myMsg( msg ), myAddSep( addSeparator ) {}
2188 virtual void Execute()
2190 if ( LightApp_Application* anApp = getApplication() ) {
2191 LogWindow* lw = anApp->logWindow();
2193 lw->putMessage( myMsg, myAddSep );
2197 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2201 \brief Remove all the messages from the Log messages output window.
2203 void SalomePyQt::clearMessages()
2205 class TEvent: public SALOME_Event
2209 virtual void Execute()
2211 if ( LightApp_Application* anApp = getApplication() ) {
2212 LogWindow* lw = anApp->logWindow();
2218 ProcessVoidEvent( new TEvent() );
2222 \brief Gets window with specified identifier
2224 \param id window identifier
2225 \return pointer on the window
2227 static SUIT_ViewWindow* getWnd( const int id )
2229 SUIT_ViewWindow* resWnd = 0;
2231 LightApp_Application* app = getApplication();
2234 ViewManagerList vmlist = app->viewManagers();
2235 foreach( SUIT_ViewManager* vm, vmlist )
2237 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2238 foreach ( SUIT_ViewWindow* vw, vwlist )
2240 if ( id == vw->getId() )
2253 \fn QList<int> SalomePyQt::getViews()
2254 \brief Get list of integer identifiers of all the currently opened views
2255 \return list of integer identifiers of all the currently opened views
2258 class TGetViews: public SALOME_Event
2261 typedef QList<int> TResult;
2264 virtual void Execute()
2267 LightApp_Application* app = getApplication();
2270 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2273 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2274 SUIT_ViewWindow* wnd;
2275 foreach ( wnd, wndlist )
2276 myResult.append( wnd->getId() );
2281 QList<int> SalomePyQt::getViews()
2283 return ProcessEvent( new TGetViews() );
2287 \fn int SalomePyQt::getActiveView()
2288 \brief Get integer identifier of the currently active view
2289 \return integer identifier of the currently active view
2292 class TGetActiveView: public SALOME_Event
2295 typedef int TResult;
2299 virtual void Execute()
2301 LightApp_Application* app = getApplication();
2304 SUIT_ViewManager* viewMgr = app->activeViewManager();
2307 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2309 myResult = wnd->getId();
2314 int SalomePyQt::getActiveView()
2316 return ProcessEvent( new TGetActiveView() );
2320 \fn QString SalomePyQt::getViewType( const int id )
2321 \brief Get type of the specified view, e.g. "OCCViewer"
2322 \param id window identifier
2326 class TGetViewType: public SALOME_Event
2329 typedef QString TResult;
2332 TGetViewType( const int id )
2334 virtual void Execute()
2336 SUIT_ViewWindow* wnd = getWnd( myWndId );
2339 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2341 myResult = viewMgr->getType();
2345 QString SalomePyQt::getViewType( const int id )
2347 return ProcessEvent( new TGetViewType( id ) );
2351 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title )
2352 \brief Change view caption
2353 \param id window identifier
2354 \param title new window title
2355 \return \c true if operation is completed successfully and \c false otherwise
2358 class TSetViewTitle: public SALOME_Event
2361 typedef bool TResult;
2365 TSetViewTitle( const int id, const QString& title )
2366 : myResult( false ),
2369 virtual void Execute()
2371 SUIT_ViewWindow* wnd = getWnd( myWndId );
2374 wnd->setWindowTitle( myTitle );
2379 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2381 return ProcessEvent( new TSetViewTitle( id, title ) );
2386 \fn QString SalomePyQt::getViewTitle( const int id )
2387 \brief Get view caption
2388 \param id window identifier
2389 \return view caption
2392 class TGetViewTitle: public SALOME_Event
2395 typedef QString TResult;
2398 TGetViewTitle( const int id )
2400 virtual void Execute()
2402 SUIT_ViewWindow* wnd = getWnd( myWndId );
2404 myResult = wnd->windowTitle();
2407 QString SalomePyQt::getViewTitle( const int id )
2409 return ProcessEvent( new TGetViewTitle( id ) );
2413 \fn QList<int> SalomePyQt::findViews( const QString& type )
2414 \brief Get list of integer identifiers of all the
2415 currently opened views of the specified type
2416 \param type viewer type
2417 \return list of integer identifiers
2420 class TFindViews: public SALOME_Event
2423 typedef QList<int> TResult;
2426 TFindViews( const QString& type )
2428 virtual void Execute()
2431 LightApp_Application* app = getApplication();
2434 ViewManagerList vmList;
2435 app->viewManagers( myType, vmList );
2436 SUIT_ViewManager* viewMgr;
2437 foreach ( viewMgr, vmList )
2439 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2440 for ( int i = 0, n = vec.size(); i < n; i++ )
2442 SUIT_ViewWindow* wnd = vec[ i ];
2444 myResult.append( wnd->getId() );
2450 QList<int> SalomePyQt::findViews( const QString& type )
2452 return ProcessEvent( new TFindViews( type ) );
2456 \fn bool SalomePyQt::activateView( const int id )
2457 \brief Activate view
2458 \param id window identifier
2459 \return \c true if operation is completed successfully and \c false otherwise
2462 class TActivateView: public SALOME_Event
2465 typedef bool TResult;
2468 TActivateView( const int id )
2469 : myResult( false ),
2471 virtual void Execute()
2473 SUIT_ViewWindow* wnd = getWnd( myWndId );
2481 bool SalomePyQt::activateView( const int id )
2483 return ProcessEvent( new TActivateView( id ) );
2487 \fn int SalomePyQt::createView( const QString& type )
2488 \brief Create new view and activate it
2489 \param type viewer type
2490 \return integer identifier of created view (or -1 if view could not be created)
2493 class TCreateView: public SALOME_Event
2496 typedef int TResult;
2499 TCreateView( const QString& theType )
2501 myType( theType ) {}
2502 virtual void Execute()
2504 LightApp_Application* app = getApplication();
2507 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2510 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2512 myResult = wnd->getId();
2517 int SalomePyQt::createView( const QString& type )
2519 return ProcessEvent( new TCreateView( type ) );
2523 \fn int SalomePyQt::createView( const QString& type, QWidget* w )
2524 \brief Create new view with custom widget embedded and activate it
2525 \param type viewer type
2526 \param w custom widget
2527 \return integer identifier of created view (or -1 if view could not be created)
2530 class TCreateViewWg: public SALOME_Event
2533 typedef int TResult;
2537 TCreateViewWg( const QString& theType, QWidget* w )
2541 virtual void Execute()
2543 LightApp_Application* app = getApplication();
2546 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2549 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2551 myResult = wnd->getId();
2556 int SalomePyQt::createView( const QString& type, QWidget* w )
2558 return ProcessEvent( new TCreateViewWg( type, w ) );
2562 \fn bool SalomePyQt::closeView( const int id )
2564 \param id window identifier
2565 \return \c true if operation is completed successfully and \c false otherwise
2568 class TCloseView: public SALOME_Event
2571 typedef bool TResult;
2574 TCloseView( const int id )
2575 : myResult( false ),
2577 virtual void Execute()
2579 SUIT_ViewWindow* wnd = getWnd( myWndId );
2582 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2591 bool SalomePyQt::closeView( const int id )
2593 return ProcessEvent( new TCloseView( id ) );
2597 \fn int SalomePyQt::cloneView( const int id )
2598 \brief Clone view (if this operation is supported for specified view type)
2599 \param id window identifier
2600 \return integer identifier of the cloned view or -1 or operation could not be performed
2603 class TCloneView: public SALOME_Event
2606 typedef int TResult;
2609 TCloneView( const int id )
2612 virtual void Execute()
2614 SUIT_ViewWindow* wnd = getWnd( myWndId );
2617 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2620 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2622 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2623 occView->onCloneView();
2625 wnd = viewMgr->getActiveView();
2627 myResult = wnd->getId();
2629 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2631 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2632 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2633 if ( viewMgr2d && srcWnd2d )
2635 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2636 myResult = resWnd->getId();
2643 int SalomePyQt::cloneView( const int id )
2645 return ProcessEvent( new TCloneView( id ) );
2649 \fn bool SalomePyQt::isViewVisible( const int id )
2650 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2651 \param id window identifier
2652 \return \c true if view is visible and \c false otherwise
2655 class TIsViewVisible: public SALOME_Event
2658 typedef bool TResult;
2661 TIsViewVisible( const int id )
2662 : myResult( false ),
2664 virtual void Execute()
2666 SUIT_ViewWindow* wnd = getWnd( myWndId );
2669 QWidget* p = wnd->parentWidget();
2670 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2674 bool SalomePyQt::isViewVisible( const int id )
2676 return ProcessEvent( new TIsViewVisible( id ) );
2680 \fn bool SalomePyQt::setViewClosable( const int id, const bool on )
2681 \brief Set / clear view's "closable" option. By default any view is closable
2682 (i.e. can be closed by the user).
2683 \param id window identifier
2684 \param on new "closable" option's value
2687 void SalomePyQt::setViewClosable( const int id, const bool on )
2689 class TEvent: public SALOME_Event
2694 TEvent( const int id, const bool on )
2695 : myWndId( id ), myOn( on ) {}
2696 virtual void Execute()
2698 SUIT_ViewWindow* wnd = getWnd( myWndId );
2699 if ( wnd ) wnd->setClosable( myOn );
2702 ProcessVoidEvent( new TEvent( id, on ) );
2706 \fn bool SalomePyQt::isViewClosable( const int id )
2707 \brief Check whether view is closable (i.e. can be closed by the user)
2708 \param id window identifier
2709 \return \c true if view is closable or \c false otherwise
2712 class TIsViewClosable: public SALOME_Event
2715 typedef bool TResult;
2718 TIsViewClosable( const int id )
2721 virtual void Execute()
2723 SUIT_ViewWindow* wnd = getWnd( myWndId );
2725 myResult = wnd->closable();
2729 bool SalomePyQt::isViewClosable( const int id )
2731 return ProcessEvent( new TIsViewClosable( id ) );
2735 \fn bool SalomePyQt::groupAllViews()
2736 \brief Group all views to the single tab area
2737 \return \c true if operation is completed successfully and \c false otherwise
2740 class TGroupAllViews: public SALOME_Event
2743 typedef bool TResult;
2746 : myResult( false ) {}
2747 virtual void Execute()
2749 LightApp_Application* app = getApplication();
2752 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2755 QtxWorkstack* wStack = tabDesk->workstack();
2765 bool SalomePyQt::groupAllViews()
2767 return ProcessEvent( new TGroupAllViews() );
2771 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2772 \brief Split tab area to which view with identifier belongs to
2773 \param id window identifier
2774 \param ori orientation of split operation
2775 \param action action to be performed
2776 \return \c true if operation is completed successfully \c false otherwise
2779 class TSplitView: public SALOME_Event
2782 typedef bool TResult;
2787 TSplitView( const int id,
2788 const Orientation ori,
2789 const Action action )
2790 : myResult( false ),
2793 myAction( action ) {}
2794 virtual void Execute()
2796 SUIT_ViewWindow* wnd = getWnd( myWndId );
2800 // wnd->setFocus(); ???
2803 if ( getApplication() )
2805 STD_TabDesktop* desk =
2806 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2809 QtxWorkstack* wStack = desk->workstack();
2812 Qt::Orientation qtOri =
2813 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2815 QtxWorkstack::SplitType sType;
2816 if ( myAction == MoveWidget )
2817 sType = QtxWorkstack::SplitMove;
2818 else if ( myAction == LeaveWidget )
2819 sType = QtxWorkstack::SplitStay;
2821 sType = QtxWorkstack::SplitAt;
2823 wStack->Split( wnd, qtOri, sType );
2831 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2833 return ProcessEvent( new TSplitView( id, ori, action ) );
2837 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
2838 \brief Move view with the first identifier to the same area which
2839 another view with the second identifier belongs to
2840 \param id source window identifier
2841 \param id_to destination window identifier
2842 param before specifies whether the first viewt has to be moved before or after
2844 \return \c true if operation is completed successfully and \c false otherwise
2847 class TMoveView: public SALOME_Event
2850 typedef bool TResult;
2855 TMoveView( const int id, const int id_to, const bool before )
2856 : myResult( false ),
2859 myIsBefore( before ) {}
2860 virtual void Execute()
2862 SUIT_ViewWindow* wnd = getWnd( myWndId );
2863 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
2864 if ( wnd && wnd_to )
2866 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
2867 getApplication()->desktop() )->workstack();
2869 myResult = wStack->move( wnd, wnd_to, myIsBefore );
2873 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
2875 return ProcessEvent( new TMoveView( id, id_to, before ) );
2879 \fn QList<int> SalomePyQt::neighbourViews( const int id )
2880 \brief Get list of views identifiers that belongs to the same area as
2881 specified view (excluding it)
2882 \param id window identifier
2883 \return list of views identifiers
2886 class TNeighbourViews: public SALOME_Event
2889 typedef QList<int> TResult;
2892 TNeighbourViews( const int id )
2894 virtual void Execute()
2897 SUIT_ViewWindow* wnd = getWnd( myWndId );
2900 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
2901 getApplication()->desktop() )->workstack();
2904 QWidgetList wgList = wStack->windowList( wnd );
2906 foreach ( wg, wgList )
2908 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
2909 if ( tmpWnd && tmpWnd != wnd )
2910 myResult.append( tmpWnd->getId() );
2916 QList<int> SalomePyQt::neighbourViews( const int id )
2918 return ProcessEvent( new TNeighbourViews( id ) );
2923 SalomePyQt::createObject(parent)
2924 Create empty data object
2926 class TCreateEmptyObjectEvent: public SALOME_Event {
2928 typedef QString TResult;
2931 TCreateEmptyObjectEvent(const QString& parent) : myParent( parent ) {}
2932 virtual void Execute() {
2933 SALOME_PYQT_ModuleLight* module = getActiveModule();
2935 myResult = (QString)module->createObject(myParent);
2938 QString SalomePyQt::createObject(const QString& parent)
2940 return ProcessEvent( new TCreateEmptyObjectEvent(parent) );
2944 SalomePyQt::createObject( name, icon, tooltip, parent )
2945 Create data object with name, icon and tooltip
2947 class TCreateObjectEvent: public SALOME_Event {
2949 typedef QString TResult;
2955 TCreateObjectEvent(const QString& name,
2956 const QString& iconname,
2957 const QString& tooltip,
2958 const QString& parent) : myName(name),
2959 myIconName(iconname),
2961 myParent( parent ){}
2962 virtual void Execute() {
2963 SALOME_PYQT_ModuleLight* module = getActiveModule();
2965 myResult = (QString)module->createObject(myName, myIconName,
2966 myToolTip, myParent);
2969 QString SalomePyQt::createObject(const QString& name,
2970 const QString& iconname,
2971 const QString& tooltip,
2972 const QString& parent)
2974 return ProcessEvent( new TCreateObjectEvent(name, iconname, tooltip, parent) );
2979 SalomePyQt::setName(obj,name)
2982 class TSetNameEvent: public SALOME_Event
2987 TSetNameEvent( const QString& obj,
2988 const QString& name) : myObj(obj),
2990 virtual void Execute() {
2991 SALOME_PYQT_ModuleLight* module = getActiveModule();
2993 module->setName(myObj,myName);
2996 void SalomePyQt::setName(const QString& obj,const QString& name)
2998 ProcessVoidEvent(new TSetNameEvent(obj,name));
3003 SalomePyQt::setIcon(obj,icon)
3006 class TSetIconEvent: public SALOME_Event
3011 TSetIconEvent( const QString& obj,
3012 const QString& iconname) : myObj(obj),
3013 myIconName(iconname) {}
3014 virtual void Execute() {
3015 SALOME_PYQT_ModuleLight* module = getActiveModule();
3017 module->setIcon(myObj,myIconName);
3021 void SalomePyQt::setIcon(const QString& obj,const QString& iconname)
3023 ProcessVoidEvent(new TSetIconEvent(obj,iconname));
3027 SalomePyQt::setToolTip(obj,tooltip)
3030 class TSetToolTipEvent: public SALOME_Event
3035 TSetToolTipEvent( const QString& obj,
3036 const QString& tooltip) : myObj(obj),
3037 myToolTip(tooltip) {}
3038 virtual void Execute() {
3039 SALOME_PYQT_ModuleLight* module = getActiveModule();
3041 module->setToolTip(myObj,myToolTip);
3044 void SalomePyQt::setToolTip(const QString& obj,const QString& tooltip)
3046 ProcessVoidEvent(new TSetToolTipEvent(obj,tooltip));
3050 SalomePyQt::setReference(obj,refEntry)
3051 Set entry to referenced object
3053 class TSetRefEvent: public SALOME_Event
3058 TSetRefEvent( const QString& obj,
3059 const QString& refEntry) : myObj(obj),
3060 myRefEntry(refEntry) {}
3061 virtual void Execute() {
3062 SALOME_PYQT_ModuleLight* module = getActiveModule();
3064 module->setReference(myObj,myRefEntry);
3067 void SalomePyQt::setReference(const QString& obj,const QString& refEntry)
3069 ProcessVoidEvent(new TSetRefEvent(obj,refEntry));
3073 SalomePyQt::setColor(obj,color)
3076 class TSetColorEvent: public SALOME_Event
3081 TSetColorEvent( const QString& obj,
3082 const QColor& color) : myObj(obj),
3084 virtual void Execute() {
3085 SALOME_PYQT_ModuleLight* module = getActiveModule();
3087 module->setColor(myObj,myColor);
3090 void SalomePyQt::setColor(const QString& obj,const QColor& color)
3092 ProcessVoidEvent(new TSetColorEvent(obj,color));
3096 SalomePyQt::getName(obj)
3097 Return name of object
3099 class TGetNameEvent: public SALOME_Event
3102 typedef QString TResult;
3105 TGetNameEvent( const QString& obj ) : myObj(obj) {}
3106 virtual void Execute() {
3107 SALOME_PYQT_ModuleLight* module = getActiveModule();
3109 myResult = (QString) module->getName(myObj);
3113 QString SalomePyQt::getName(const QString& obj)
3115 return ProcessEvent(new TGetNameEvent(obj));
3119 SalomePyQt::getToolTip(obj)
3120 Return tool tip of object
3122 class TGetToolTipEvent: public SALOME_Event
3125 typedef QString TResult;
3128 TGetToolTipEvent( const QString& obj ) : myObj(obj) {}
3129 virtual void Execute() {
3130 SALOME_PYQT_ModuleLight* module = getActiveModule();
3132 myResult = (QString)module->getToolTip(myObj);
3135 QString SalomePyQt::getToolTip(const QString& obj)
3137 return ProcessEvent(new TGetToolTipEvent(obj));
3141 SalomePyQt::getReference(obj)
3142 Return entry of the referenced object (if any)
3144 class TGetRefEvent: public SALOME_Event
3147 typedef QString TResult;
3150 TGetRefEvent( const QString& obj ) : myObj(obj) {}
3151 virtual void Execute() {
3152 SALOME_PYQT_ModuleLight* module = getActiveModule();
3154 myResult = module->getReference(myObj);
3157 QString SalomePyQt::getReference(const QString& obj)
3159 return ProcessEvent(new TGetRefEvent(obj));
3163 SalomePyQt::getColor(obj)
3164 Return the color of the object
3166 class TGetColorEvent: public SALOME_Event
3169 typedef QColor TResult;
3172 TGetColorEvent( const QString& obj ) : myObj(obj) {}
3173 virtual void Execute() {
3174 SALOME_PYQT_ModuleLight* module = getActiveModule();
3176 myResult = module->getColor(myObj);
3179 QColor SalomePyQt::getColor(const QString& obj)
3181 return ProcessEvent(new TGetColorEvent(obj));
3185 SalomePyQt::removeChild(obj)
3186 Remove childrens from object
3188 class TRemoveChildEvent: public SALOME_Event
3192 TRemoveChildEvent(const QString& obj) : myObj(obj) {}
3194 virtual void Execute() {
3195 SALOME_PYQT_ModuleLight* module = getActiveModule();
3197 module->removeChild(myObj);
3200 void SalomePyQt::removeChild(const QString& obj)
3202 ProcessVoidEvent(new TRemoveChildEvent(obj));
3207 SalomePyQt::removeObject(obj)
3210 class TRemoveObjectEvent: public SALOME_Event
3215 TRemoveObjectEvent( const QString& obj) : myObj(obj) {}
3216 virtual void Execute() {
3217 SALOME_PYQT_ModuleLight* module = getActiveModule();
3219 module->removeObject(myObj);
3222 void SalomePyQt::removeObject(const QString& obj)
3224 ProcessVoidEvent(new TRemoveObjectEvent(obj));
3228 SalomePyQt::getChildren(obj)
3229 Return the list of the child objects
3230 if rec == true then function get all sub children.
3233 class TGetChildrenEvent: public SALOME_Event
3236 typedef QStringList TResult;
3240 TGetChildrenEvent(const QString& obj, const bool rec) : myObj(obj),
3242 virtual void Execute() {
3243 SALOME_PYQT_ModuleLight* module = getActiveModule();
3245 myResult = (QStringList)module->getChildren(myObj,myRec);
3248 QStringList SalomePyQt::getChildren(const QString& obj, const bool rec)
3250 return ProcessEvent( new TGetChildrenEvent(obj,rec) );