1 // Copyright (C) 2007-2013 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 "SALOME_PYQT_PyModule.h"
37 #include "SalomePyQt.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "LogWindow.h"
41 #include "OCCViewer_ViewWindow.h"
42 #include "Plot2d_ViewManager.h"
43 #include "Plot2d_ViewWindow.h"
44 #include "QtxActionMenuMgr.h"
45 #include "QtxWorkstack.h"
46 #include "QtxTreeView.h"
47 #include "SALOME_Event.h"
48 #include "STD_TabDesktop.h"
49 #include "SUIT_DataBrowser.h"
50 #include "SUIT_ResourceMgr.h"
51 #include "SUIT_Session.h"
52 #include "SUIT_Tools.h"
55 #include <QApplication>
58 \brief Get the currently active application.
60 \return active application object or 0 if there is no any
62 static LightApp_Application* getApplication()
64 if ( SUIT_Session::session() )
65 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
70 \brief Get the currently active study.
72 \return active study or 0 if there is no study opened
74 static LightApp_Study* getActiveStudy()
76 if ( getApplication() )
77 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
82 \brief Get the currently active module.
84 This function returns correct result only if Python-based
85 module is currently active. Otherwize, 0 is returned.
87 static LightApp_Module* getActiveModule()
89 LightApp_Module* module = 0;
90 if ( LightApp_Application* anApp = getApplication() ) {
91 module = PyModuleHelper::getInitModule();
93 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
99 \brief Get the currently active Python module's helper.
101 This function returns correct result only if Python-based
102 module is currently active. Otherwize, 0 is returned.
104 static PyModuleHelper* getPythonHelper()
106 LightApp_Module* module = getActiveModule();
107 PyModuleHelper* helper = module ? qFindChild<PyModuleHelper*>( module, "python_module_helper" ) : 0;
112 \brief Get SALOME verbose level
114 \return \c true if SALOME debug output is allowed or \c false otherwise
116 static bool verbose()
118 bool isVerbose = false;
119 if ( getenv( "SALOME_VERBOSE" ) ) {
120 QString envVar = getenv( "SALOME_VERBOSE" );
122 int value = envVar.toInt( &ok );
123 isVerbose = ok && value != 0;
129 \class SALOME_Selection
130 \brief The class represents selection which can be used in Python.
134 \brief Map of created selection objects.
137 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
140 \brief Get the selection object for the specified application.
142 Finds or creates the selection object (one per study).
144 \param app application object
145 \return selection object or 0 if \a app is invalid
147 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
149 SALOME_Selection* sel = 0;
150 if ( app && SelMap.find( app ) != SelMap.end() )
153 sel = SelMap[ app ] = new SALOME_Selection( app );
159 \param p parent object
161 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
163 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
165 mySelMgr = app->selectionMgr();
166 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
167 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
174 SALOME_Selection::~SALOME_Selection()
176 LightApp_Application* app = 0;
177 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
178 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
179 if ( it.value() == this ) app = it.key();
181 if ( app ) SelMap.remove( app );
185 \brief Called when selection manager is destroyed (usually
186 when the study is closed).
188 void SALOME_Selection::onSelMgrDestroyed()
194 \brief Clear the selection.
196 void SALOME_Selection::Clear()
198 class TEvent: public SALOME_Event
200 LightApp_SelectionMgr* mySelMgr;
202 TEvent( LightApp_SelectionMgr* selMgr )
203 : mySelMgr( selMgr ) {}
204 virtual void Execute()
207 mySelMgr->clearSelected();
210 ProcessVoidEvent( new TEvent( mySelMgr ) );
214 \brief Clear the selection.
216 void SALOME_Selection::ClearIObjects()
222 Removes all selection filters.
224 void SALOME_Selection::ClearFilters()
226 class TEvent: public SALOME_Event
228 LightApp_SelectionMgr* mySelMgr;
230 TEvent( LightApp_SelectionMgr* selMgr )
231 : mySelMgr( selMgr ) {}
232 virtual void Execute()
235 mySelMgr->clearFilters();
238 ProcessVoidEvent( new TEvent( mySelMgr ) );
243 \brief The class provides utility functions which can be used in the Python
244 to operate with the SALOME GUI.
246 All the functionality of this class is implemented as static methods, so they
247 can be called with the class name prefixed or via creation of the class instance.
248 For example, next both ways of SalomePyQt class usage are legal:
250 from SalomePyQt import *
252 # using SalomePyQt class instance
253 desktop = sg.getDesktop()
254 # using SalomePyQt class directly
255 menubar = SalomePyQt.getMainMenuBar()
260 \fn QWidget* SalomePyQt::getDesktop();
261 \brief Get the active application's desktop window.
262 \return desktop window or 0 if there is no any
265 class TGetDesktopEvent: public SALOME_Event
268 typedef QWidget* TResult;
270 TGetDesktopEvent() : myResult( 0 ) {}
271 virtual void Execute()
273 if ( getApplication() )
274 myResult = (QWidget*)( getApplication()->desktop() );
277 QWidget* SalomePyQt::getDesktop()
279 return ProcessEvent( new TGetDesktopEvent() );
283 \fn QWidget* SalomePyQt::getMainFrame();
284 \brief Get current application's main frame widget [obsolete].
286 Main frame widget is an internal widget of the application
287 desktop window (workspace).
289 \return workspace widget (0 on any error)
292 class TGetMainFrameEvent: public SALOME_Event
295 typedef QWidget* TResult;
297 TGetMainFrameEvent() : myResult( 0 ) {}
298 virtual void Execute()
300 if ( getApplication() ) {
301 SUIT_Desktop* aDesktop = getApplication()->desktop();
302 myResult = (QWidget*)( aDesktop->centralWidget() );
306 QWidget* SalomePyQt::getMainFrame()
308 return ProcessEvent( new TGetMainFrameEvent() );
312 \fn QMenuBar* SalomePyQt::getMainMenuBar();
313 \brief Get current application desktop's main menu.
314 \return main menu object (0 on any error)
317 class TGetMainMenuBarEvent: public SALOME_Event
320 typedef QMenuBar* TResult;
322 TGetMainMenuBarEvent() : myResult( 0 ) {}
323 virtual void Execute()
325 if ( LightApp_Application* anApp = getApplication() ) {
326 myResult = anApp->desktop()->menuBar();
330 QMenuBar* SalomePyQt::getMainMenuBar()
332 return ProcessEvent( new TGetMainMenuBarEvent() );
336 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
337 \brief Get main menu's child popup submenu by its identifier.
339 This function is obsolete.
340 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
342 \param menu menu identifier
343 \return popup submenu object or 0 if it does not exist
347 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
348 \brief Get main menu's child popup submenu by its name.
350 The function creates menu if it does not exist.
352 \param menu menu name
353 \return popup submenu object (0 on any error)
356 class TGetPopupMenuEvent: public SALOME_Event
359 typedef QMenu* TResult;
362 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
363 virtual void Execute()
365 LightApp_Application* anApp = getApplication();
366 if ( anApp && !myMenuName.isEmpty() ) {
367 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
368 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
374 \brief Get menu item title
376 \param menuId menu identifier
377 \return menu title (localized)
379 static QString getMenuName( const QString& menuId )
381 QStringList contexts;
382 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
383 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
384 QString menuName = menuId;
385 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
386 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
390 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
395 menuName = getMenuName( "MEN_DESK_FILE" ); break;
397 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
399 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
401 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
403 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
405 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
407 menuName = getMenuName( "MEN_DESK_HELP" ); break;
409 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
411 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
413 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
417 \fn QTreeView* SalomePyQt::getObjectBrowser();
418 \brief Get object browser
419 \return object browser for the active study or 0 in case of error
422 class TGetObjectBrowserEvent: public SALOME_Event
425 typedef QTreeView* TResult;
427 TGetObjectBrowserEvent() : myResult( 0 ) {}
428 virtual void Execute()
430 LightApp_Application* anApp = getApplication();
432 myResult = anApp->objectBrowser()->treeView();
436 QTreeView* SalomePyQt::getObjectBrowser()
438 return ProcessEvent( new TGetObjectBrowserEvent() );
442 \fn int SalomePyQt::getStudyId();
443 \brief Get active study's identifier.
444 \return active study ID or 0 if there is no active study
447 class TGetStudyIdEvent: public SALOME_Event
452 TGetStudyIdEvent() : myResult( 0 ) {}
453 virtual void Execute()
455 if ( LightApp_Study* aStudy = getActiveStudy() ) {
456 myResult = aStudy->id();
460 int SalomePyQt::getStudyId()
462 return ProcessEvent( new TGetStudyIdEvent() );
466 \fn SALOME_Selection* SalomePyQt::getSelection();
467 \brief Get the selection object for the current study.
469 Creates a Selection object if it has not been created yet.
471 \return selection object (0 on error)
474 class TGetSelectionEvent: public SALOME_Event
477 typedef SALOME_Selection* TResult;
479 TGetSelectionEvent() : myResult( 0 ) {}
480 virtual void Execute()
482 myResult = SALOME_Selection::GetSelection( getApplication() );
485 SALOME_Selection* SalomePyQt::getSelection()
487 return ProcessEvent( new TGetSelectionEvent() );
491 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
492 \brief Put an information message to the current application's
495 Optional second delay parameter (\a sec) can be used to specify
496 time of the message diplaying in seconds. If this parameter is less
497 or equal to zero, the constant message will be put.
499 \param msg message text
500 \param sec message displaying time in seconds
503 class TPutInfoEvent: public SALOME_Event
508 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
509 virtual void Execute()
511 if ( LightApp_Application* anApp = getApplication() ) {
512 anApp->putInfo( myMsg, mySecs * 1000 );
516 void SalomePyQt::putInfo( const QString& msg, const int sec )
518 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
522 \fn const QString SalomePyQt::getActiveComponent();
523 \brief Get the currently active module name (for the current study).
524 \return active module name or empty string if there is no active module
527 class TGetActiveComponentEvent: public SALOME_Event
530 typedef QString TResult;
532 TGetActiveComponentEvent() {}
533 virtual void Execute()
535 if ( LightApp_Application* anApp = getApplication() ) {
536 if ( CAM_Module* mod = anApp->activeModule() ) {
537 myResult = mod->name();
542 const QString SalomePyQt::getActiveComponent()
544 return ProcessEvent( new TGetActiveComponentEvent() );
548 \fn PyObject* SalomePyQt::getActivePythonModule();
549 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
550 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
553 class TGetActivePyModuleEvent: public SALOME_Event
556 typedef PyObject* TResult;
558 TGetActivePyModuleEvent() : myResult( Py_None ) {}
559 virtual void Execute()
561 PyModuleHelper* helper = getPythonHelper();
563 myResult = (PyObject*)helper->pythonModule();
566 PyObject* SalomePyQt::getActivePythonModule()
568 return ProcessEvent( new TGetActivePyModuleEvent() );
572 \fn bool SalomePyQt::activateModule( const QString& modName );
573 \brief Activates SALOME module with the given name
574 \return True if the module has been activated and False otherwise.
577 class TActivateModuleEvent: public SALOME_Event
580 typedef bool TResult;
582 QString myModuleName;
583 TActivateModuleEvent( const QString& modName )
584 : myResult( false ), myModuleName( modName ) {}
585 virtual void Execute()
587 if ( LightApp_Application* anApp = getApplication() ) {
588 myResult = anApp->activateModule( myModuleName );
592 bool SalomePyQt::activateModule( const QString& modName )
594 return ProcessEvent( new TActivateModuleEvent( modName ) );
598 \brief Update an Object Browser of the specified (by identifier) study.
600 If \a studyId <= 0 the active study's object browser is updated.
601 The \a updateSelection parameter is obsolete and currently is not used.
602 This parameter will be removed in future, so try to avoid its usage in
605 \brief studyId study identifier
606 \brief updateSelection update selection flag (not used)
609 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
611 class TEvent: public SALOME_Event
614 bool myUpdateSelection;
616 TEvent( const int studyId, bool updateSelection )
617 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
618 virtual void Execute()
620 if ( SUIT_Session::session() ) {
621 if ( getActiveStudy() && myStudyId <= 0 )
622 myStudyId = getActiveStudy()->id();
623 if ( myStudyId > 0 ) {
624 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
625 QList<SUIT_Application*>::Iterator it;
626 for( it = apps.begin(); it != apps.end(); ++it ) {
627 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
628 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
629 anApp->updateObjectBrowser();
637 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
642 SalomePyQt::isModified()
643 \return The modification status of the data model
644 for the currently active Python module
645 \note This function is supported for "light" Python-based SALOME modules only.
648 class TIsModifiedEvent: public SALOME_Event
651 typedef bool TResult;
653 TIsModifiedEvent() : myResult( false ) {}
654 virtual void Execute()
656 LightApp_Module* module = getActiveModule();
660 SALOME_PYQT_DataModelLight* aModel =
661 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
663 myResult = aModel->isModified();
666 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
670 bool SalomePyQt::isModified()
672 return ProcessEvent(new TIsModifiedEvent());
676 SalomePyQt::setModified()
678 Sets the modification status of the data model for
679 the currently active Python module. This method should be used
680 by the Python code in order to enable/disable "Save" operation
681 depending on the module's data state.
683 \note This function is supported for "light" Python-based SALOME modules only.
685 \param New modification status of the data model
689 void SalomePyQt::setModified( bool flag )
691 class TEvent: public SALOME_Event
697 virtual void Execute()
699 LightApp_Module* module = getActiveModule();
703 SALOME_PYQT_DataModelLight* model =
704 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
706 LightApp_Application* app = module->getApp();
708 if ( model && app ) {
709 model->setModified( myFlag );
710 app->updateActions();
713 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
717 ProcessVoidEvent( new TEvent( flag ) );
721 \brief Default resource file section name.
724 static const char* DEFAULT_SECTION = "SalomePyQt";
727 \brief Add string setting to the application preferences.
729 The parameter \a autoValue is obsolete parameter and currently is not used.
730 This parameter will be removed in future, so try to avoid its usage in
733 This function is obsolete. Use one of addSetting() instead.
735 \param name setting name (it should be of kind <section:setting> where
736 \c section is resources section name and \c setting is setting name)
737 \param value new setting value
738 \param autoValue (not used)
740 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
742 class TEvent: public SALOME_Event
748 TEvent( const QString& name, const QString& value, bool autoValue )
749 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
750 virtual void Execute()
752 if ( SUIT_Session::session() ) {
753 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
754 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
755 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
756 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
757 if ( !_sec.isEmpty() && !_nam.isEmpty() )
758 resMgr->setValue( _sec, _nam, myValue );
762 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
766 \brief Add integer setting to the application preferences.
768 The parameter \a autoValue is obsolete parameter and currently is not used.
769 This parameter will be removed in future, so try to avoid its usage in
772 This function is obsolete. Use one of addSetting() instead.
774 \param name setting name (it should be of kind <section:setting> where
775 \c section is resources section name and \c setting is setting name)
776 \param value new setting value
777 \param autoValue (not used)
779 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
781 class TEvent: public SALOME_Event
787 TEvent( const QString& name, const int value, bool autoValue )
788 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
789 virtual void Execute()
791 if ( SUIT_Session::session() ) {
792 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
793 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
794 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
795 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
796 if ( !_sec.isEmpty() && !_nam.isEmpty() )
797 resMgr->setValue( _sec, _nam, myValue );
801 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
805 \brief Add double setting to the application preferences.
807 The parameter \a autoValue is obsolete parameter and currently is not used.
808 This parameter will be removed in future, so try to avoid its usage in
811 This function is obsolete. Use one of addSetting() instead.
813 \param name setting name (it should be of kind <section:setting> where
814 \c section is resources section name and \c setting is setting name)
815 \param value new setting value
816 \param autoValue (not used)
818 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
820 class TEvent: public SALOME_Event
826 TEvent( const QString& name, const double value, bool autoValue )
827 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
828 virtual void Execute()
830 if ( SUIT_Session::session() ) {
831 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
832 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
833 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
834 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
835 if ( !_sec.isEmpty() && !_nam.isEmpty() )
836 resMgr->setValue( _sec, _nam, myValue );
840 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
844 \brief Add boolean setting to the application preferences.
846 The parameter \a autoValue is obsolete parameter and currently is not used.
847 This parameter will be removed in future, so try to avoid its usage in
850 This function is obsolete. Use one of addSetting() 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)
854 \param value new setting value
855 \param autoValue (not used)
857 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
859 class TEvent: public SALOME_Event
865 TEvent( const QString& name, const bool value, bool autoValue )
866 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
867 virtual void Execute()
869 if ( SUIT_Session::session() ) {
870 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
871 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
872 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
873 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
874 if ( !_sec.isEmpty() && !_nam.isEmpty() )
875 resMgr->setValue( _sec, _nam, myValue );
879 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
883 \brief Remove setting from the application preferences.
885 This function is obsolete. Use removeSetting() instead.
887 \param name setting name (it should be of kind <section:setting> where
888 \c section is resources section name and \c setting is setting name)
890 void SalomePyQt::removeSettings( const QString& name )
892 class TEvent: public SALOME_Event
896 TEvent( const QString& name ) : myName( name ) {}
897 virtual void Execute()
899 if ( SUIT_Session::session() ) {
900 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
901 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
902 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
903 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
904 if ( !_sec.isEmpty() && !_nam.isEmpty() )
905 resMgr->remove( _sec, _nam );
909 ProcessVoidEvent( new TEvent( name ) );
913 \fn QString SalomePyQt::getSetting( const QString& name );
914 \brief Get application setting value (as string represenation).
916 This function is obsolete. Use stringSetting(), integerSetting(),
917 boolSetting(), stringSetting() or colorSetting() instead.
919 \param name setting name (it should be of kind <section:setting> where
920 \c section is resources section name and \c setting is setting name)
921 \return setting name (empty string if setting name is invalid)
924 class TGetSettingEvent: public SALOME_Event
927 typedef QString TResult;
930 TGetSettingEvent( const QString& name ) : myName( name ) {}
931 virtual void Execute()
933 if ( SUIT_Session::session() ) {
934 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
935 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
936 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
937 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
938 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
942 QString SalomePyQt::getSetting( const QString& name )
944 return ProcessEvent( new TGetSettingEvent( name ) );
948 \brief Add double setting to the application preferences.
949 \param section resources file section name
950 \param name setting name
951 \param value new setting value
953 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
955 class TEvent: public SALOME_Event
961 TEvent( const QString& section, const QString& name, double value )
962 : mySection( section ), myName( name ), myValue( value ) {}
963 virtual void Execute()
965 if ( SUIT_Session::session() ) {
966 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
967 if ( !mySection.isEmpty() && !myName.isEmpty() )
968 resMgr->setValue( mySection, myName, myValue );
972 ProcessVoidEvent( new TEvent( section, name, value ) );
976 \brief Add integer setting to the application preferences.
977 \param section resources file section name
978 \param name setting name
979 \param value new setting value
981 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
983 class TEvent: public SALOME_Event
989 TEvent( const QString& section, const QString& name, int value )
990 : mySection( section ), myName( name ), myValue( value ) {}
991 virtual void Execute()
993 if ( SUIT_Session::session() ) {
994 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
995 if ( !mySection.isEmpty() && !myName.isEmpty() )
996 resMgr->setValue( mySection, myName, myValue );
1000 ProcessVoidEvent( new TEvent( section, name, value ) );
1004 \brief Add boolean setting to the application preferences.
1005 \param section resources file section name
1006 \param name setting name
1007 \param value new setting value
1008 \param dumb this parameter is used in order to avoid sip compilation error
1009 because of conflicting int and bool types
1011 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1013 class TEvent: public SALOME_Event
1019 TEvent( const QString& section, const QString& name, bool value )
1020 : mySection( section ), myName( name ), myValue( value ) {}
1021 virtual void Execute()
1023 if ( SUIT_Session::session() ) {
1024 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1025 if ( !mySection.isEmpty() && !myName.isEmpty() )
1026 resMgr->setValue( mySection, myName, myValue );
1030 ProcessVoidEvent( new TEvent( section, name, value ) );
1034 \brief Add string setting to the application preferences.
1035 \param section resources file section name
1036 \param name setting name
1037 \param value new setting value
1039 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1041 class TEvent: public SALOME_Event
1047 TEvent( const QString& section, const QString& name, const QString& value )
1048 : mySection( section ), myName( name ), myValue( value ) {}
1049 virtual void Execute()
1051 if ( SUIT_Session::session() ) {
1052 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1053 if ( !mySection.isEmpty() && !myName.isEmpty() )
1054 resMgr->setValue( mySection, myName, myValue );
1058 ProcessVoidEvent( new TEvent( section, name, value ) );
1062 \brief Add color setting to the application preferences.
1063 \param section resources file section name
1064 \param name setting name
1065 \param value new setting value
1067 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1069 class TEvent: public SALOME_Event
1075 TEvent( const QString& section, const QString& name, const QColor& value )
1076 : mySection( section ), myName( name ), myValue( value ) {}
1077 virtual void Execute()
1079 if ( SUIT_Session::session() ) {
1080 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1081 if ( !mySection.isEmpty() && !myName.isEmpty() )
1082 resMgr->setValue( mySection, myName, myValue );
1086 ProcessVoidEvent( new TEvent( section, name, value ) );
1090 \fn int SalomePyQt::integerSetting( const QString& section,
1091 const QString& name,
1093 \brief Get integer setting from the application preferences.
1094 \param section resources file section name
1095 \param name setting name
1096 \param def default value which is returned if the setting is not found
1097 \return setting value
1100 class TGetIntSettingEvent: public SALOME_Event
1103 typedef int TResult;
1108 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1109 : mySection( section ), myName( name ), myDefault( def ) {}
1110 virtual void Execute()
1112 if ( SUIT_Session::session() ) {
1113 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1114 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1118 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1120 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1124 \fn double SalomePyQt::doubleSetting( const QString& section,
1125 const QString& name,
1127 \brief Get double setting from the application preferences.
1128 \param section resources file section name
1129 \param name setting name
1130 \param def default value which is returned if the setting is not found
1131 \return setting value
1134 class TGetDblSettingEvent: public SALOME_Event
1137 typedef double TResult;
1142 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1143 : mySection( section ), myName( name ), myDefault( def ) {}
1144 virtual void Execute()
1146 if ( SUIT_Session::session() ) {
1147 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1148 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1152 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1154 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1158 \fn bool SalomePyQt::boolSetting( const QString& section,
1159 const QString& name,
1161 \brief Get boolean setting from the application preferences.
1162 \param section resources file section name
1163 \param name setting name
1164 \param def default value which is returned if the setting is not found
1165 \return setting value
1168 class TGetBoolSettingEvent: public SALOME_Event
1171 typedef bool TResult;
1176 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1177 : mySection( section ), myName( name ), myDefault( def ) {}
1178 virtual void Execute()
1180 if ( SUIT_Session::session() ) {
1181 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1182 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1186 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1188 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1192 \fn QString SalomePyQt::stringSetting( const QString& section,
1193 const QString& name,
1194 const QString& def );
1195 \brief Get string setting from the application preferences.
1196 \param section resources file section name
1197 \param name setting name
1198 \param def default value which is returned if the setting is not found
1199 \return setting value
1202 class TGetStrSettingEvent: public SALOME_Event
1205 typedef QString TResult;
1210 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1211 : mySection( section ), myName( name ), myDefault( def ) {}
1212 virtual void Execute()
1214 if ( SUIT_Session::session() ) {
1215 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1216 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1220 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1222 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1226 \fn QColor SalomePyQt::colorSetting( const QString& section,
1227 const QString& name,
1229 \brief Get color setting from the application preferences.
1230 \param section resources file section name
1231 \param name setting name
1232 \param def default value which is returned if the setting is not found
1233 \return setting value
1236 class TGetColorSettingEvent: public SALOME_Event
1239 typedef QColor TResult;
1244 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1245 : mySection( section ), myName( name ), myDefault( def ) {}
1246 virtual void Execute()
1248 if ( SUIT_Session::session() ) {
1249 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1250 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1254 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1256 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1260 \brief Remove setting from the application preferences.
1261 \param section resources file section name
1262 \param name setting name
1264 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1266 class TEvent: public SALOME_Event
1271 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1272 virtual void Execute()
1274 if ( SUIT_Session::session() ) {
1275 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1276 if ( !mySection.isEmpty() && !myName.isEmpty() )
1277 resMgr->remove( mySection, myName );
1281 ProcessVoidEvent( new TEvent( section, name ) );
1285 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1286 \brief Check setting existence in the application preferences.
1287 \param section resources file section name
1288 \param name setting name
1289 \return \c true if setting exists
1292 class THasColorSettingEvent: public SALOME_Event
1295 typedef bool TResult;
1299 THasColorSettingEvent( const QString& section, const QString& name )
1300 : mySection( section ), myName( name ) {}
1301 virtual void Execute()
1303 if ( SUIT_Session::session() ) {
1304 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1305 myResult = resMgr->hasValue( mySection, myName );
1309 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1311 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1315 \fn QString SalomePyQt::getFileName( QWidget* parent,
1316 const QString& initial,
1317 const QStringList& filters,
1318 const QString& caption,
1320 \brief Show 'Open/Save file' dialog box for file selection
1321 and return a user's choice (selected file name).
1322 \param parent parent widget
1323 \param initial initial directory the dialog box to be opened in
1324 \param filters list of files filters (wildcards)
1325 \param caption dialog box title
1326 \param open if \c true, "Open File" dialog box is shown;
1327 otherwise "Save File" dialog box is shown
1328 \return selected file name (null string if user cancels operation)
1331 class TGetFileNameEvent: public SALOME_Event
1334 typedef QString TResult;
1338 QStringList myFilters;
1341 TGetFileNameEvent( QWidget* parent,
1342 const QString& initial,
1343 const QStringList& filters,
1344 const QString& caption,
1346 : myParent ( parent ),
1347 myInitial( initial ),
1348 myFilters( filters ),
1349 myCaption( caption ),
1351 virtual void Execute()
1353 if ( LightApp_Application* anApp = getApplication() ) {
1354 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1355 myCaption, myParent );
1359 QString SalomePyQt::getFileName( QWidget* parent,
1360 const QString& initial,
1361 const QStringList& filters,
1362 const QString& caption,
1365 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1369 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1370 const QString& initial,
1371 const QStringList& filters,
1372 const QString& caption );
1373 \brief Show 'Open files' dialog box for multiple files selection
1374 and return a user's choice (selected file names list).
1375 \param parent parent widget
1376 \param initial initial directory the dialog box to be opened in
1377 \param filters list of files filters (wildcards)
1378 \param caption dialog box title
1379 \return selected file names list (empty list if user cancels operation)
1382 class TGetOpenFileNamesEvent: public SALOME_Event
1385 typedef QStringList TResult;
1389 QStringList myFilters;
1391 TGetOpenFileNamesEvent( QWidget* parent,
1392 const QString& initial,
1393 const QStringList& filters,
1394 const QString& caption )
1395 : myParent ( parent ),
1396 myInitial( initial ),
1397 myFilters( filters ),
1398 myCaption( caption ) {}
1399 virtual void Execute()
1401 if ( LightApp_Application* anApp = getApplication() ) {
1402 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1406 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1407 const QString& initial,
1408 const QStringList& filters,
1409 const QString& caption )
1411 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1415 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1416 const QString& initial,
1417 const QString& caption );
1418 \brief Show 'Get Directory' dialog box for the directory selection
1419 and return a user's choice (selected directory name).
1420 \param parent parent widget
1421 \param initial initial directory the dialog box to be opened in
1422 \param caption dialog box title
1423 \return selected directory name (null string if user cancels operation)
1426 class TGetExistingDirectoryEvent: public SALOME_Event
1429 typedef QString TResult;
1434 TGetExistingDirectoryEvent( QWidget* parent,
1435 const QString& initial,
1436 const QString& caption )
1437 : myParent ( parent ),
1438 myInitial( initial ),
1439 myCaption( caption ) {}
1440 virtual void Execute()
1442 if ( LightApp_Application* anApp = getApplication() ) {
1443 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1447 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1448 const QString& initial,
1449 const QString& caption )
1451 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1455 \fn QString SalomePyQt::loadIcon( const QString& filename );
1456 \brief Load an icon from the module resources by the specified file name.
1457 \param fileName icon file name
1461 static QIcon loadIconInternal( const QString& module, const QString& fileName )
1465 LightApp_Application* app = getApplication();
1467 if ( app && !fileName.isEmpty() ) {
1468 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
1469 QApplication::translate( module.toLatin1().data(),
1470 fileName.toLatin1().data() ) );
1471 if ( !pixmap.isNull() )
1472 icon = QIcon( pixmap );
1477 class TLoadIconEvent: public SALOME_Event
1480 typedef QIcon TResult;
1484 TLoadIconEvent( const QString& module, const QString& filename )
1485 : myModule( module ),
1486 myFileName ( filename ) {}
1487 virtual void Execute()
1489 myResult = loadIconInternal( myModule, myFileName );
1492 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1494 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1498 \brief Open external browser to display context help information.
1501 Current implementation does nothing.
1503 \param source documentation (HTML) file name
1504 \param context context (for example, HTML ancor name)
1506 void SalomePyQt::helpContext( const QString& source, const QString& context )
1508 class TEvent: public SALOME_Event
1513 TEvent( const QString& source, const QString& context )
1514 : mySource( source ), myContext( context ) {}
1515 virtual void Execute()
1517 if ( LightApp_Application* anApp = getApplication() ) {
1518 anApp->onHelpContextModule( "", mySource, myContext );
1522 ProcessVoidEvent( new TEvent( source, context ) );
1526 \fn bool SalomePyQt::dumpView( const QString& filename );
1527 \brief Dump the contents of the currently active view window
1528 to the image file in the specified format.
1530 For the current moment JPEG, PNG and BMP images formats are supported.
1531 The image format is defined automatically by the file name extension.
1532 By default, BMP format is used.
1534 \param filename image file name
1535 \return operation status (\c true on success)
1538 class TDumpViewEvent: public SALOME_Event
1541 typedef bool TResult;
1544 TDumpViewEvent( const QString& filename )
1545 : myResult ( false ), myFileName( filename ) {}
1546 virtual void Execute()
1548 if ( LightApp_Application* anApp = getApplication() ) {
1549 SUIT_ViewManager* vm = anApp->activeViewManager();
1551 SUIT_ViewWindow* vw = vm->getActiveView();
1553 QImage im = vw->dumpView();
1554 if ( !im.isNull() && !myFileName.isEmpty() ) {
1555 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
1556 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
1557 if ( fmt == "JPG" ) fmt = "JPEG";
1558 myResult = im.save( myFileName, fmt.toLatin1() );
1565 bool SalomePyQt::dumpView( const QString& filename )
1567 return ProcessEvent( new TDumpViewEvent( filename ) );
1571 \fn int SalomePyQt::defaultMenuGroup();
1572 \brief Get detault menu group identifier which can be used when
1573 creating menus (insert custom menu commands).
1574 \return default menu group ID
1577 class TDefMenuGroupEvent: public SALOME_Event
1580 typedef int TResult;
1582 TDefMenuGroupEvent() : myResult( -1 ) {}
1583 virtual void Execute()
1585 myResult = PyModuleHelper::defaultMenuGroup();
1588 int SalomePyQt::defaultMenuGroup()
1590 return ProcessEvent( new TDefMenuGroupEvent() );
1596 CrTool( const QString& tBar )
1597 : myCase( 0 ), myTbName( tBar ) {}
1598 CrTool( const int id, const int tBar, const int idx )
1599 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1600 CrTool( const int id, const QString& tBar, const int idx )
1601 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1602 CrTool( QAction* action, const int tbId, const int id, const int idx )
1603 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1604 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1605 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1607 int execute( LightApp_Module* module ) const
1612 return module->createTool( myTbName );
1614 return module->createTool( myId, myTbId, myIndex );
1616 return module->createTool( myId, myTbName, myIndex );
1618 return module->createTool( myAction, myTbId, myId, myIndex );
1620 return module->createTool( myAction, myTbName, myId, myIndex );
1634 class TCreateToolEvent: public SALOME_Event
1637 typedef int TResult;
1639 const CrTool& myCrTool;
1640 TCreateToolEvent( const CrTool& crTool )
1641 : myResult( -1 ), myCrTool( crTool ) {}
1642 virtual void Execute()
1644 LightApp_Module* module = getActiveModule();
1646 myResult = myCrTool.execute( module );
1651 \brief Create toolbar with specified name.
1652 \param tBar toolbar name
1653 \return toolbar ID or -1 if toolbar creation is failed
1655 int SalomePyQt::createTool( const QString& tBar )
1657 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1661 \brief Insert action with specified \a id to the toolbar.
1663 \param tBar toolbar ID
1664 \param idx required index in the toolbar
1665 \return action ID or -1 if action could not be added
1667 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1669 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1673 \brief Insert action with specified \a id to the toolbar.
1675 \param tBar toolbar name
1676 \param idx required index in the toolbar
1677 \return action ID or -1 if action could not be added
1679 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1681 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1685 \brief Insert action to the toolbar.
1687 \param tBar toolbar ID
1688 \param id required action ID
1689 \param idx required index in the toolbar
1690 \return action ID or -1 if action could not be added
1692 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1694 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1698 \brief Insert action to the toolbar.
1700 \param tBar toolbar name
1701 \param id required action ID
1702 \param idx required index in the toolbar
1703 \return action ID or -1 if action could not be added
1705 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1707 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1713 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1714 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1715 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1716 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1717 CrMenu( const int id, const int menu, const int group, const int idx )
1718 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1719 CrMenu( const int id, const QString& menu, const int group, const int idx )
1720 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1721 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1722 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1723 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1724 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1726 int execute( LightApp_Module* module ) const
1731 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1733 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1735 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1737 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1739 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1741 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1750 QString mySubMenuName;
1757 class TCreateMenuEvent: public SALOME_Event
1760 typedef int TResult;
1762 const CrMenu& myCrMenu;
1763 TCreateMenuEvent( const CrMenu& crMenu )
1764 : myResult( -1 ), myCrMenu( crMenu ) {}
1765 virtual void Execute()
1767 LightApp_Module* module = getActiveModule();
1769 myResult = myCrMenu.execute( module );
1774 \brief Create main menu.
1775 \param subMenu menu name
1776 \param menu parent menu ID
1777 \param id required menu ID
1778 \param group menu group ID
1779 \param idx required index in the menu
1780 \return menu ID or -1 if menu could not be added
1782 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1784 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1788 \brief Create main menu.
1789 \param subMenu menu name
1790 \param menu parent menu name (list of menu names separated by "|")
1791 \param id required menu ID
1792 \param group menu group ID
1793 \param idx required index in the menu
1794 \return menu ID or -1 if menu could not be added
1796 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1798 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1802 \brief Insert action to the main menu.
1804 \param menu parent menu ID
1805 \param group menu group ID
1806 \param idx required index in the menu
1807 \return action ID or -1 if action could not be added
1809 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1811 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1815 \brief Insert action to the main menu.
1817 \param menu parent menu name (list of menu names separated by "|")
1818 \param group menu group ID
1819 \param idx required index in the menu
1820 \return action ID or -1 if action could not be added
1822 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1824 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1828 \brief Insert action to the main menu.
1830 \param menu parent menu ID
1831 \param group menu group ID
1832 \param idx required index in the menu
1833 \return action ID or -1 if action could not be added
1835 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1837 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1841 \brief Insert action to the main menu.
1843 \param menu parent menu name (list of menu names separated by "|")
1844 \param group menu group ID
1845 \param idx required index in the menu
1846 \return action ID or -1 if action could not be added
1848 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1850 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1854 \fn QAction* SalomePyQt::createSeparator();
1855 \brief Create separator action which can be used in the menu or toolbar.
1856 \return new separator action
1859 class TCreateSepEvent: public SALOME_Event
1862 typedef QAction* TResult;
1866 virtual void Execute()
1868 LightApp_Module* module = getActiveModule();
1870 myResult = (QAction*)module->separator();
1873 QAction* SalomePyQt::createSeparator()
1875 return ProcessEvent( new TCreateSepEvent() );
1879 \fn QAction* SalomePyQt::createAction( const int id,
1880 const QString& menuText,
1881 const QString& tipText,
1882 const QString& statusText,
1883 const QString& icon,
1885 const bool toggle );
1886 \brief Create an action which can be then used in the menu or toolbar.
1887 \param id the unique id action to be registered to
1888 \param menuText action text which should appear in menu
1889 \param tipText text which should appear in the tooltip
1890 \param statusText text which should appear in the status bar when action is activated
1891 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1892 \param key the key accelrator for the action
1893 \param toggle if \c true the action is checkable
1896 class TCreateActionEvent: public SALOME_Event
1899 typedef QAction* TResult;
1904 QString myStatusText;
1908 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1909 const QString& statusText, const QString& icon, const int key, const bool toggle )
1910 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1911 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1912 virtual void Execute()
1914 LightApp_Module* module = getActiveModule();
1916 QIcon icon = loadIconInternal( module->name(), myIcon );
1917 myResult = (QAction*)module->action( myId );
1919 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1920 myResult->setToolTip( myTipText );
1921 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1922 myResult->setText( myMenuText );
1923 if ( myResult->icon().isNull() && !icon.isNull() )
1924 myResult->setIcon( icon );
1925 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1926 myResult->setStatusTip( myStatusText );
1927 if ( myResult->shortcut().isEmpty() && myKey )
1928 myResult->setShortcut( myKey );
1929 if ( myResult->isCheckable() != myToggle )
1930 myResult->setCheckable( myToggle );
1933 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1935 // for Python module, automatically connect action to callback slot
1936 PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1937 if ( helper ) helper->connectAction( myResult );
1941 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1942 const QString& tipText, const QString& statusText,
1943 const QString& icon, const int key, const bool toggle )
1945 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1949 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1950 \brief Create an action group which can be then used in the menu or toolbar
1951 \param id : the unique id action group to be registered to
1952 \param exclusive : if \c true the action group does exclusive toggling
1955 struct TCreateActionGroupEvent: public SALOME_Event
1957 typedef QtxActionGroup* TResult;
1961 TCreateActionGroupEvent( const int id, const bool exclusive )
1962 : myId( id ), myExclusive( exclusive ) {}
1963 virtual void Execute()
1965 LightApp_Module* module = getActiveModule();
1967 myResult = module->createActionGroup( myId, myExclusive );
1970 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1972 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1976 \fn QAction* SalomePyQt::action( const int id );
1977 \brief Get action by specified identifier.
1978 \return action or 0 if action is not registered
1981 class TActionEvent: public SALOME_Event
1984 typedef QAction* TResult;
1987 TActionEvent( const int id )
1988 : myResult( 0 ), myId( id ) {}
1989 virtual void Execute()
1991 LightApp_Module* module = getActiveModule();
1993 myResult = (QAction*)module->action( myId );
1996 QAction* SalomePyQt::action( const int id )
1998 return ProcessEvent( new TActionEvent( id ) );
2002 \fn int SalomePyQt::actionId( const QAction* a );
2003 \brief Get an action identifier.
2004 \return action ID or -1 if action is not registered
2007 class TActionIdEvent: public SALOME_Event
2010 typedef int TResult;
2012 const QAction* myAction;
2013 TActionIdEvent( const QAction* action )
2014 : myResult( -1 ), myAction( action ) {}
2015 virtual void Execute()
2017 LightApp_Module* module = getActiveModule();
2019 myResult = module->actionId( myAction );
2022 int SalomePyQt::actionId( const QAction* a )
2024 return ProcessEvent( new TActionIdEvent( a ) );
2028 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2029 \brief Add global (not module-related) preferences group.
2030 \param label global preferences group name
2031 \return preferences group identifier
2034 class TAddGlobalPrefEvent: public SALOME_Event
2037 typedef int TResult;
2040 TAddGlobalPrefEvent( const QString& label )
2041 : myResult( -1 ), myLabel( label ) {}
2042 virtual void Execute()
2044 LightApp_Module* module = getActiveModule();
2046 LightApp_Preferences* pref = module->getApp()->preferences();
2048 myResult = pref->addPreference( myLabel, -1 );
2052 int SalomePyQt::addGlobalPreference( const QString& label )
2054 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2058 \fn int SalomePyQt::addPreference( const QString& label );
2059 \brief Add module-related preferences group.
2060 \param label preferences group name
2061 \return preferences group identifier
2064 class TAddPrefEvent: public SALOME_Event
2067 typedef int TResult;
2070 TAddPrefEvent( const QString& label )
2071 : myResult( -1 ), myLabel( label ) {}
2072 virtual void Execute()
2074 LightApp_Module* module = getActiveModule();
2076 LightApp_Preferences* pref = module->getApp()->preferences();
2078 int cId = pref->addPreference( module->moduleName(), -1 );
2080 myResult = pref->addPreference( myLabel, cId );
2085 int SalomePyQt::addPreference( const QString& label )
2087 return ProcessEvent( new TAddPrefEvent( label ) );
2091 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2092 const QString& section, const QString& param );
2093 \brief Add module-related preferences.
2094 \param label preferences group name
2095 \param pId parent preferences group id
2096 \param type preferences type
2097 \param section resources file section name
2098 \param param resources file setting name
2099 \return preferences identifier
2102 class TAddPrefParamEvent: public SALOME_Event
2105 typedef int TResult;
2112 TAddPrefParamEvent( const QString& label,
2113 const int pId, const int type,
2114 const QString& section,
2115 const QString& param )
2117 myLabel( label ), myPId( pId ), myType( type ),
2118 mySection( section ), myParam ( param ) {}
2119 virtual void Execute()
2121 LightApp_Module* module = getActiveModule();
2123 LightApp_Preferences* pref = module->getApp()->preferences();
2125 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2129 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2130 const QString& section, const QString& param )
2132 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2136 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2137 \brief Get the preferences property.
2138 \param id preferences identifier
2139 \param prop preferences property name
2140 \return preferences property value or null QVariant if property is not set
2143 class TPrefPropEvent: public SALOME_Event
2146 typedef QVariant TResult;
2150 TPrefPropEvent( const int id, const QString& prop )
2151 : myId( id ), myProp( prop ) {}
2152 virtual void Execute()
2154 LightApp_Module* module = getActiveModule();
2156 LightApp_Preferences* pref = module->getApp()->preferences();
2158 myResult = pref->itemProperty( myProp, myId );
2162 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2164 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2168 \brief Set the preferences property.
2169 \param id preferences identifier
2170 \param prop preferences property name
2171 \param var preferences property value
2173 void SalomePyQt::setPreferenceProperty( const int id,
2174 const QString& prop,
2175 const QVariant& var )
2177 class TEvent: public SALOME_Event
2183 TEvent( const int id, const QString& prop, const QVariant& var )
2184 : myId( id ), myProp( prop ), myVar( var ) {}
2185 virtual void Execute()
2187 LightApp_Module* module = getActiveModule();
2189 LightApp_Preferences* pref = module->getApp()->preferences();
2191 pref->setItemProperty( myProp, myVar, myId );
2195 ProcessVoidEvent( new TEvent( id, prop, var) );
2199 \brief Add the property value to the list of values.
2201 This method allows creating properties which are QList<QVariant>
2202 - there is no way to pass such values directly to QVariant parameter with PyQt.
2204 \param id preferences identifier
2205 \param prop preferences property name
2206 \param idx preferences property index
2207 \param var preferences property value for the index \a idx
2209 void SalomePyQt::addPreferenceProperty( const int id,
2210 const QString& prop,
2212 const QVariant& var )
2214 class TEvent: public SALOME_Event
2221 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2222 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2223 virtual void Execute()
2225 LightApp_Module* module = getActiveModule();
2227 LightApp_Preferences* pref = module->getApp()->preferences();
2229 QVariant var = pref->itemProperty( myProp, myId );
2230 if ( var.isValid() ) {
2231 if ( var.type() == QVariant::StringList ) {
2232 QStringList sl = var.toStringList();
2233 if ( myIdx >= 0 && myIdx < sl.count() )
2234 sl[myIdx] = myVar.toString();
2236 sl.append( myVar.toString() );
2237 pref->setItemProperty( myProp, sl, myId );
2239 else if ( var.type() == QVariant::List ) {
2240 QList<QVariant> vl = var.toList();
2241 if ( myIdx >= 0 && myIdx < vl.count() )
2245 pref->setItemProperty( myProp, vl, myId );
2251 pref->setItemProperty( myProp, vl, myId );
2257 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2261 \brief Put the message to the Log messages output window
2262 \param msg message text (it can be of simple rich text format)
2263 \param addSeparator boolean flag which specifies if it is necessary
2264 to separate the message with predefined separator
2266 void SalomePyQt::message( const QString& msg, bool addSeparator )
2268 class TEvent: public SALOME_Event
2273 TEvent( const QString& msg, bool addSeparator )
2274 : myMsg( msg ), myAddSep( addSeparator ) {}
2275 virtual void Execute()
2277 if ( LightApp_Application* anApp = getApplication() ) {
2278 LogWindow* lw = anApp->logWindow();
2280 lw->putMessage( myMsg, myAddSep );
2284 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2288 \brief Remove all the messages from the Log messages output window.
2290 void SalomePyQt::clearMessages()
2292 class TEvent: public SALOME_Event
2296 virtual void Execute()
2298 if ( LightApp_Application* anApp = getApplication() ) {
2299 LogWindow* lw = anApp->logWindow();
2305 ProcessVoidEvent( new TEvent() );
2309 \brief Gets window with specified identifier
2311 \param id window identifier
2312 \return pointer on the window
2314 static SUIT_ViewWindow* getWnd( const int id )
2316 SUIT_ViewWindow* resWnd = 0;
2318 LightApp_Application* app = getApplication();
2321 ViewManagerList vmlist = app->viewManagers();
2322 foreach( SUIT_ViewManager* vm, vmlist )
2324 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2325 foreach ( SUIT_ViewWindow* vw, vwlist )
2327 if ( id == vw->getId() )
2340 \fn QList<int> SalomePyQt::getViews();
2341 \brief Get list of integer identifiers of all the currently opened views
2342 \return list of integer identifiers of all the currently opened views
2345 class TGetViews: public SALOME_Event
2348 typedef QList<int> TResult;
2351 virtual void Execute()
2354 LightApp_Application* app = getApplication();
2357 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2360 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2361 SUIT_ViewWindow* wnd;
2362 foreach ( wnd, wndlist )
2363 myResult.append( wnd->getId() );
2368 QList<int> SalomePyQt::getViews()
2370 return ProcessEvent( new TGetViews() );
2374 \fn int SalomePyQt::getActiveView();
2375 \brief Get integer identifier of the currently active view
2376 \return integer identifier of the currently active view
2379 class TGetActiveView: public SALOME_Event
2382 typedef int TResult;
2386 virtual void Execute()
2388 LightApp_Application* app = getApplication();
2391 SUIT_ViewManager* viewMgr = app->activeViewManager();
2394 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2396 myResult = wnd->getId();
2401 int SalomePyQt::getActiveView()
2403 return ProcessEvent( new TGetActiveView() );
2407 \fn QString SalomePyQt::getViewType( const int id );
2408 \brief Get type of the specified view, e.g. "OCCViewer"
2409 \param id window identifier
2413 class TGetViewType: public SALOME_Event
2416 typedef QString TResult;
2419 TGetViewType( const int id )
2421 virtual void Execute()
2423 SUIT_ViewWindow* wnd = getWnd( myWndId );
2426 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2428 myResult = viewMgr->getType();
2432 QString SalomePyQt::getViewType( const int id )
2434 return ProcessEvent( new TGetViewType( id ) );
2438 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2439 \brief Change view caption
2440 \param id window identifier
2441 \param title new window title
2442 \return \c true if operation is completed successfully and \c false otherwise
2445 class TSetViewTitle: public SALOME_Event
2448 typedef bool TResult;
2452 TSetViewTitle( const int id, const QString& title )
2453 : myResult( false ),
2456 virtual void Execute()
2458 SUIT_ViewWindow* wnd = getWnd( myWndId );
2461 wnd->setWindowTitle( myTitle );
2466 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2468 return ProcessEvent( new TSetViewTitle( id, title ) );
2473 \fn QString SalomePyQt::getViewTitle( const int id );
2474 \brief Get view caption
2475 \param id window identifier
2476 \return view caption
2479 class TGetViewTitle: public SALOME_Event
2482 typedef QString TResult;
2485 TGetViewTitle( const int id )
2487 virtual void Execute()
2489 SUIT_ViewWindow* wnd = getWnd( myWndId );
2491 myResult = wnd->windowTitle();
2494 QString SalomePyQt::getViewTitle( const int id )
2496 return ProcessEvent( new TGetViewTitle( id ) );
2500 \fn QList<int> SalomePyQt::findViews( const QString& type );
2501 \brief Get list of integer identifiers of all the
2502 currently opened views of the specified type
2503 \param type viewer type
2504 \return list of integer identifiers
2507 class TFindViews: public SALOME_Event
2510 typedef QList<int> TResult;
2513 TFindViews( const QString& type )
2515 virtual void Execute()
2518 LightApp_Application* app = getApplication();
2521 ViewManagerList vmList;
2522 app->viewManagers( myType, vmList );
2523 SUIT_ViewManager* viewMgr;
2524 foreach ( viewMgr, vmList )
2526 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2527 for ( int i = 0, n = vec.size(); i < n; i++ )
2529 SUIT_ViewWindow* wnd = vec[ i ];
2531 myResult.append( wnd->getId() );
2537 QList<int> SalomePyQt::findViews( const QString& type )
2539 return ProcessEvent( new TFindViews( type ) );
2543 \fn bool SalomePyQt::activateView( const int id );
2544 \brief Activate view
2545 \param id window identifier
2546 \return \c true if operation is completed successfully and \c false otherwise
2549 class TActivateView: public SALOME_Event
2552 typedef bool TResult;
2555 TActivateView( const int id )
2556 : myResult( false ),
2558 virtual void Execute()
2560 SUIT_ViewWindow* wnd = getWnd( myWndId );
2568 bool SalomePyQt::activateView( const int id )
2570 return ProcessEvent( new TActivateView( id ) );
2574 \fn int SalomePyQt::createView( const QString& type );
2575 \brief Create new view and activate it
2576 \param type viewer type
2577 \return integer identifier of created view (or -1 if view could not be created)
2580 class TCreateView: public SALOME_Event
2583 typedef int TResult;
2586 TCreateView( const QString& theType )
2588 myType( theType ) {}
2589 virtual void Execute()
2591 LightApp_Application* app = getApplication();
2594 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2597 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2599 myResult = wnd->getId();
2604 int SalomePyQt::createView( const QString& type )
2606 return ProcessEvent( new TCreateView( type ) );
2610 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2611 \brief Create new view with custom widget embedded and activate it
2612 \param type viewer type
2613 \param w custom widget
2614 \return integer identifier of created view (or -1 if view could not be created)
2617 class TCreateViewWg: public SALOME_Event
2620 typedef int TResult;
2624 TCreateViewWg( const QString& theType, QWidget* w )
2628 virtual void Execute()
2630 LightApp_Application* app = getApplication();
2633 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2636 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2638 myResult = wnd->getId();
2643 int SalomePyQt::createView( const QString& type, QWidget* w )
2645 return ProcessEvent( new TCreateViewWg( type, w ) );
2649 \fn bool SalomePyQt::closeView( const int id );
2651 \param id window identifier
2652 \return \c true if operation is completed successfully and \c false otherwise
2655 class TCloseView: public SALOME_Event
2658 typedef bool TResult;
2661 TCloseView( const int id )
2662 : myResult( false ),
2664 virtual void Execute()
2666 SUIT_ViewWindow* wnd = getWnd( myWndId );
2669 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2678 bool SalomePyQt::closeView( const int id )
2680 return ProcessEvent( new TCloseView( id ) );
2684 \fn int SalomePyQt::cloneView( const int id );
2685 \brief Clone view (if this operation is supported for specified view type)
2686 \param id window identifier
2687 \return integer identifier of the cloned view or -1 or operation could not be performed
2690 class TCloneView: public SALOME_Event
2693 typedef int TResult;
2696 TCloneView( const int id )
2699 virtual void Execute()
2701 SUIT_ViewWindow* wnd = getWnd( myWndId );
2704 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2707 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2709 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2710 occView->onCloneView();
2712 wnd = viewMgr->getActiveView();
2714 myResult = wnd->getId();
2716 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2718 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2719 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2720 if ( viewMgr2d && srcWnd2d )
2722 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2723 myResult = resWnd->getId();
2730 int SalomePyQt::cloneView( const int id )
2732 return ProcessEvent( new TCloneView( id ) );
2736 \fn bool SalomePyQt::isViewVisible( const int id );
2737 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2738 \param id window identifier
2739 \return \c true if view is visible and \c false otherwise
2742 class TIsViewVisible: public SALOME_Event
2745 typedef bool TResult;
2748 TIsViewVisible( const int id )
2749 : myResult( false ),
2751 virtual void Execute()
2753 SUIT_ViewWindow* wnd = getWnd( myWndId );
2756 QWidget* p = wnd->parentWidget();
2757 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2761 bool SalomePyQt::isViewVisible( const int id )
2763 return ProcessEvent( new TIsViewVisible( id ) );
2767 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2768 \brief Set / clear view's "closable" option. By default any view is closable
2769 (i.e. can be closed by the user).
2770 \param id window identifier
2771 \param on new "closable" option's value
2774 void SalomePyQt::setViewClosable( const int id, const bool on )
2776 class TEvent: public SALOME_Event
2781 TEvent( const int id, const bool on )
2782 : myWndId( id ), myOn( on ) {}
2783 virtual void Execute()
2785 SUIT_ViewWindow* wnd = getWnd( myWndId );
2786 if ( wnd ) wnd->setClosable( myOn );
2789 ProcessVoidEvent( new TEvent( id, on ) );
2793 \fn bool SalomePyQt::isViewClosable( const int id );
2794 \brief Check whether view is closable (i.e. can be closed by the user)
2795 \param id window identifier
2796 \return \c true if view is closable or \c false otherwise
2799 class TIsViewClosable: public SALOME_Event
2802 typedef bool TResult;
2805 TIsViewClosable( const int id )
2808 virtual void Execute()
2810 SUIT_ViewWindow* wnd = getWnd( myWndId );
2812 myResult = wnd->closable();
2816 bool SalomePyQt::isViewClosable( const int id )
2818 return ProcessEvent( new TIsViewClosable( id ) );
2822 \fn bool SalomePyQt::groupAllViews();
2823 \brief Group all views to the single tab area
2824 \return \c true if operation is completed successfully and \c false otherwise
2827 class TGroupAllViews: public SALOME_Event
2830 typedef bool TResult;
2833 : myResult( false ) {}
2834 virtual void Execute()
2836 LightApp_Application* app = getApplication();
2839 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2842 QtxWorkstack* wStack = tabDesk->workstack();
2852 bool SalomePyQt::groupAllViews()
2854 return ProcessEvent( new TGroupAllViews() );
2858 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2859 \brief Split tab area to which view with identifier belongs to
2860 \param id window identifier
2861 \param ori orientation of split operation
2862 \param action action to be performed
2863 \return \c true if operation is completed successfully \c false otherwise
2866 class TSplitView: public SALOME_Event
2869 typedef bool TResult;
2874 TSplitView( const int id,
2875 const Orientation ori,
2876 const Action action )
2877 : myResult( false ),
2880 myAction( action ) {}
2881 virtual void Execute()
2883 SUIT_ViewWindow* wnd = getWnd( myWndId );
2887 // wnd->setFocus(); ???
2890 if ( getApplication() )
2892 STD_TabDesktop* desk =
2893 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2896 QtxWorkstack* wStack = desk->workstack();
2899 Qt::Orientation qtOri =
2900 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2902 QtxWorkstack::SplitType sType;
2903 if ( myAction == MoveWidget )
2904 sType = QtxWorkstack::SplitMove;
2905 else if ( myAction == LeaveWidget )
2906 sType = QtxWorkstack::SplitStay;
2908 sType = QtxWorkstack::SplitAt;
2910 wStack->Split( wnd, qtOri, sType );
2918 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2920 return ProcessEvent( new TSplitView( id, ori, action ) );
2924 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
2925 \brief Move view with the first identifier to the same area which
2926 another view with the second identifier belongs to
2927 \param id source window identifier
2928 \param id_to destination window identifier
2929 param before specifies whether the first viewt has to be moved before or after
2931 \return \c true if operation is completed successfully and \c false otherwise
2934 class TMoveView: public SALOME_Event
2937 typedef bool TResult;
2942 TMoveView( const int id, const int id_to, const bool before )
2943 : myResult( false ),
2946 myIsBefore( before ) {}
2947 virtual void Execute()
2949 SUIT_ViewWindow* wnd = getWnd( myWndId );
2950 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
2951 if ( wnd && wnd_to )
2953 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
2954 getApplication()->desktop() )->workstack();
2956 myResult = wStack->move( wnd, wnd_to, myIsBefore );
2960 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
2962 return ProcessEvent( new TMoveView( id, id_to, before ) );
2966 \fn QList<int> SalomePyQt::neighbourViews( const int id );
2967 \brief Get list of views identifiers that belongs to the same area as
2968 specified view (excluding it)
2969 \param id window identifier
2970 \return list of views identifiers
2973 class TNeighbourViews: public SALOME_Event
2976 typedef QList<int> TResult;
2979 TNeighbourViews( const int id )
2981 virtual void Execute()
2984 SUIT_ViewWindow* wnd = getWnd( myWndId );
2987 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
2988 getApplication()->desktop() )->workstack();
2991 QWidgetList wgList = wStack->windowList( wnd );
2993 foreach ( wg, wgList )
2995 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
2996 if ( tmpWnd && tmpWnd != wnd )
2997 myResult.append( tmpWnd->getId() );
3003 QList<int> SalomePyQt::neighbourViews( const int id )
3005 return ProcessEvent( new TNeighbourViews( id ) );
3010 \fn QString SalomePyQt::createObject( const QString& parent );
3011 \brief Create empty data object
3012 \param parent entry of parent data object
3013 \return entry of created data object
3016 class TCreateEmptyObjectEvent: public SALOME_Event
3019 typedef QString TResult;
3022 TCreateEmptyObjectEvent( const QString& parent )
3023 : myParent( parent ) {}
3024 virtual void Execute()
3026 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3028 myResult = module->createObject( myParent );
3031 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3035 QString SalomePyQt::createObject( const QString& parent )
3037 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3041 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3042 const QString& tooltip,const QString& parent );
3043 \brief Create new data object with specified name, icon and tooltip
3044 \param name data object name
3045 \param icon data object icon
3046 \param toolTip data object tooltip
3047 \param parent entry of parent data object
3048 \return entry of created data object
3051 class TCreateObjectEvent: public SALOME_Event
3054 typedef QString TResult;
3060 TCreateObjectEvent( const QString& name,
3061 const QString& icon,
3062 const QString& tooltip,
3063 const QString& parent )
3066 myToolTip( tooltip ),
3067 myParent( parent ) {}
3068 virtual void Execute()
3070 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3072 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3075 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3079 QString SalomePyQt::createObject( const QString& name,
3080 const QString& icon,
3081 const QString& toolTip,
3082 const QString& parent )
3084 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3089 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3090 \brief Set data object name
3091 \param entry data object entry
3092 \param name data object name
3094 class TSetNameEvent: public SALOME_Event
3099 TSetNameEvent( const QString& entry,
3100 const QString& name )
3103 virtual void Execute()
3105 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3107 module->setName( myEntry, myName );
3110 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3114 void SalomePyQt::setName( const QString& entry, const QString& name )
3116 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3120 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3121 \brief Set data object icon
3122 \param entry data object entry
3123 \param icon data object icon file name (icon is loaded from module resources)
3126 class TSetIconEvent: public SALOME_Event
3131 TSetIconEvent( const QString& entry,
3132 const QString& icon )
3135 virtual void Execute()
3137 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3139 module->setIcon( myEntry, myIcon );
3142 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3147 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3149 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3153 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3154 \brief Set data object tooltip
3155 \param entry data object entry
3156 \param toolTip data object tooltip
3159 class TSetToolTipEvent: public SALOME_Event
3164 TSetToolTipEvent( const QString& entry,
3165 const QString& toolTip )
3167 myToolTip( toolTip ) {}
3168 virtual void Execute()
3170 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3172 module->setToolTip( myEntry, myToolTip );
3175 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3179 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3181 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3185 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3186 \brief Set reference to another data object
3187 \param entry data object entry
3188 \param refEntry referenced data object entry
3191 class TSetRefEvent: public SALOME_Event
3196 TSetRefEvent( const QString& entry,
3197 const QString& refEntry )
3199 myRefEntry( refEntry ) {}
3200 virtual void Execute()
3202 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3204 module->setReference( myEntry, myRefEntry );
3207 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3211 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3213 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3217 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3218 \brief Set data object color
3219 \param entry data object entry
3220 \param color data object color
3223 class TSetColorEvent: public SALOME_Event
3228 TSetColorEvent( const QString& entry,
3229 const QColor& color )
3232 virtual void Execute()
3234 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3236 module->setColor( myEntry, myColor );
3239 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3243 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3245 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3249 \fn QString SalomePyQt::getName( const QString& entry );
3250 \brief Get data object name
3251 \param entry data object entry
3252 \return data object name
3255 class TGetNameEvent: public SALOME_Event
3258 typedef QString TResult;
3261 TGetNameEvent( const QString& entry )
3262 : myEntry( entry ) {}
3263 virtual void Execute()
3265 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3267 myResult = module->getName( myEntry );
3270 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3274 QString SalomePyQt::getName( const QString& entry )
3276 return ProcessEvent( new TGetNameEvent( entry ) );
3280 \fn QString SalomePyQt::getToolTip( const QString& entry );
3281 \brief Get data object tooltip
3282 \param entry data object entry
3283 \return data object tooltip
3286 class TGetToolTipEvent: public SALOME_Event
3289 typedef QString TResult;
3292 TGetToolTipEvent( const QString& entry )
3293 : myEntry( entry ) {}
3294 virtual void Execute()
3296 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3298 myResult = module->getToolTip( myEntry );
3301 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3305 QString SalomePyQt::getToolTip( const QString& entry )
3307 return ProcessEvent( new TGetToolTipEvent( entry ) );
3311 \fn QString SalomePyQt::getReference( const QString& entry );
3312 \brief Get entry of the referenced object (if there's any)
3313 \param entry data object entry
3314 \return referenced data object entry
3317 class TGetRefEvent: public SALOME_Event
3320 typedef QString TResult;
3323 TGetRefEvent( const QString& entry )
3324 : myEntry( entry ) {}
3325 virtual void Execute()
3327 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3329 myResult = module->getReference( myEntry );
3332 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3336 QString SalomePyQt::getReference( const QString& entry )
3338 return ProcessEvent( new TGetRefEvent( entry ) );
3342 \fn QColor SalomePyQt::getColor( const QString& entry );
3343 \brief Get data object color
3344 \param entry data object entry
3345 \return data object color
3348 class TGetColorEvent: public SALOME_Event
3351 typedef QColor TResult;
3354 TGetColorEvent( const QString& entry )
3355 : myEntry( entry ) {}
3356 virtual void Execute()
3358 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3360 myResult = module->getColor( myEntry );
3363 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3367 QColor SalomePyQt::getColor( const QString& entry )
3369 return ProcessEvent( new TGetColorEvent( entry ) );
3373 \fn void SalomePyQt::removeChildren( const QString& entry );
3374 \brief Remove all child data objects from specified data object
3375 \param entry data object entry
3378 class TRemoveChildEvent: public SALOME_Event
3382 TRemoveChildEvent( const QString& entry )
3383 : myEntry( entry ) {}
3384 virtual void Execute()
3386 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3388 module->removeChildren( myEntry );
3391 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3395 void SalomePyQt::removeChildren( const QString& entry )
3397 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3399 void SalomePyQt::removeChild( const QString& entry )
3401 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3402 removeChildren( entry );
3406 \fn void SalomePyQt::removeObject( const QString& entry );
3407 \brief Remove object by entry
3408 \param entry data object entry
3411 class TRemoveObjectEvent: public SALOME_Event
3416 TRemoveObjectEvent( const QString& entry )
3417 : myEntry( entry ) {}
3418 virtual void Execute()
3420 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3422 module->removeObject( myEntry );
3425 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3429 void SalomePyQt::removeObject( const QString& entry )
3431 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3435 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3436 \brief Get entries of all child data objects of specified data object
3437 \param entry data object entry
3438 \param recursive \c true for recursive processing
3441 class TGetChildrenEvent: public SALOME_Event
3444 typedef QStringList TResult;
3448 TGetChildrenEvent( const QString& entry, const bool recursive )
3450 myRecursive( recursive ) {}
3451 virtual void Execute()
3453 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3455 myResult = module->getChildren( myEntry, myRecursive );
3458 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3462 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3464 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );