1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 #ifndef DISABLE_OCCVIEWER
42 #include "OCCViewer_ViewWindow.h"
43 #include "OCCViewer_ViewFrame.h"
44 #endif // DISABLE_OCCVIEWER
45 #ifndef DISABLE_PLOT2DVIEWER
46 #include "Plot2d_ViewManager.h"
47 #include "Plot2d_ViewWindow.h"
48 #endif // DISABLE_PLOT2DVIEWER
49 #ifndef DISABLE_PVVIEWER
50 #include "PVViewer_ViewManager.h"
51 #include "PVViewer_ViewModel.h"
52 #endif // DISABLE_PVVIEWER
53 #include "QtxActionMenuMgr.h"
54 #include "QtxWorkstack.h"
55 #include "QtxTreeView.h"
56 #include "SALOME_Event.h"
57 #include "STD_TabDesktop.h"
58 #include "SUIT_DataBrowser.h"
59 #include "SUIT_ResourceMgr.h"
60 #include "SUIT_Session.h"
61 #include "SUIT_Tools.h"
62 #include "SUIT_ViewManager.h"
63 #include "SUIT_ViewWindow.h"
64 #include "PyConsole_Console.h"
67 #include <QApplication>
68 #include <QPaintEvent>
69 #include <QCoreApplication>
70 #include <QVBoxLayout>
72 #include <utilities.h>
77 \brief Get the currently active application.
79 \return active application object or 0 if there is no any
81 LightApp_Application* getApplication()
83 if ( SUIT_Session::session() )
84 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
89 \brief Get the currently active study.
91 \return active study or 0 if there is no study opened
93 LightApp_Study* getActiveStudy()
95 if ( getApplication() )
96 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
101 \brief Get the currently active module.
103 This function returns correct result only if Python-based
104 module is currently active. Otherwize, 0 is returned.
106 LightApp_Module* getActiveModule()
108 LightApp_Module* module = 0;
109 if ( LightApp_Application* anApp = getApplication() ) {
110 module = PyModuleHelper::getInitModule();
112 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
118 \brief Get the currently active Python module's helper.
120 This function returns correct result only if Python-based
121 module is currently active. Otherwize, 0 is returned.
123 PyModuleHelper* getPythonHelper()
125 LightApp_Module* module = getActiveModule();
126 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
131 \brief Get SALOME verbose level
133 \return \c true if SALOME debug output is allowed or \c false otherwise
137 bool isVerbose = false;
138 if ( getenv( "SALOME_VERBOSE" ) ) {
139 QString envVar = getenv( "SALOME_VERBOSE" );
141 int value = envVar.toInt( &ok );
142 isVerbose = ok && value != 0;
148 \brief Get menu item title
150 \param menuId menu identifier
151 \return menu title (localized)
153 QString getMenuName( const QString& menuId )
155 QStringList contexts;
156 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
157 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
158 QString menuName = menuId;
159 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
160 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
165 \brief Load module icon
167 \param module module name
168 \param fileName path to the icon file
171 QIcon loadIconInternal( const QString& module, const QString& fileName )
175 LightApp_Application* app = getApplication();
177 if ( app && !fileName.isEmpty() ) {
178 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
179 QApplication::translate( module.toLatin1().data(),
180 fileName.toLatin1().data() ) );
181 if ( !pixmap.isNull() )
182 icon = QIcon( pixmap );
188 \brief Gets window with specified identifier
190 \param id window identifier
191 \return pointer on the window
193 SUIT_ViewWindow* getWnd( const int id )
195 SUIT_ViewWindow* resWnd = 0;
197 LightApp_Application* app = getApplication();
199 ViewManagerList vmlist = app->viewManagers();
200 foreach( SUIT_ViewManager* vm, vmlist ) {
201 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
202 foreach ( SUIT_ViewWindow* vw, vwlist ) {
203 if ( id == vw->getId() ) {
214 \brief Map of created selection objects.
217 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
220 \brief Default resource file section name.
223 const char* DEFAULT_SECTION = "SalomePyQt";
227 \class SALOME_Selection
228 \brief The class represents selection which can be used in Python.
232 \brief Get the selection object for the specified application.
234 Finds or creates the selection object (one per study).
236 \param app application object
237 \return selection object or 0 if \a app is invalid
239 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
241 SALOME_Selection* sel = 0;
242 if ( app && SelMap.find( app ) != SelMap.end() )
245 sel = SelMap[ app ] = new SALOME_Selection( app );
252 \param p parent object
254 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
256 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
258 mySelMgr = app->selectionMgr();
259 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
260 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
267 SALOME_Selection::~SALOME_Selection()
269 LightApp_Application* app = 0;
270 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
271 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
272 if ( it.value() == this ) app = it.key();
274 if ( app ) SelMap.remove( app );
278 \brief Called when selection manager is destroyed (usually
279 when the study is closed).
281 void SALOME_Selection::onSelMgrDestroyed()
287 \brief Clear the selection.
289 void SALOME_Selection::Clear()
291 class TEvent: public SALOME_Event
293 LightApp_SelectionMgr* mySelMgr;
295 TEvent( LightApp_SelectionMgr* selMgr )
296 : mySelMgr( selMgr ) {}
297 virtual void Execute()
300 mySelMgr->clearSelected();
303 ProcessVoidEvent( new TEvent( mySelMgr ) );
307 \brief Clear the selection.
309 void SALOME_Selection::ClearIObjects()
315 Removes all selection filters.
317 void SALOME_Selection::ClearFilters()
319 class TEvent: public SALOME_Event
321 LightApp_SelectionMgr* mySelMgr;
323 TEvent( LightApp_SelectionMgr* selMgr )
324 : mySelMgr( selMgr ) {}
325 virtual void Execute()
328 mySelMgr->clearFilters();
331 ProcessVoidEvent( new TEvent( mySelMgr ) );
335 \class UserDefinedContent
336 \brief The class represents base class for user defined widget that
337 can be inserted to the Preferences dialog.
343 UserDefinedContent::UserDefinedContent()
349 \brief Called from Preferences dialog to store settings to the resource file.
351 void UserDefinedContent::store()
356 \brief Called from Preferences dialog to restore settings from the resource file.
358 void UserDefinedContent::retrieve()
363 \class SgPyQtUserDefinedContent
364 \brief A Wrapper for UserDefinedContent class.
367 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
370 SgPyQtUserDefinedContent(UserDefinedContent*);
371 virtual ~SgPyQtUserDefinedContent();
373 void store( QtxResourceMgr*, QtxPreferenceMgr* );
374 void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
377 UserDefinedContent* myContent;
381 \brief Create custom item for Preferences dialog wrapping widget passed from Python.
384 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
385 : QtxUserDefinedContent( 0 ), myContent( content )
387 QVBoxLayout* l = new QVBoxLayout( this );
388 l->setContentsMargins( 0, 0, 0, 0 );
389 l->addWidget( myContent );
396 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
401 \brief Called from Preferences dialog to store settings to the resource file.
404 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
410 \brief Called from Preferences dialog to restore settings from the resource file.
413 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
415 myContent->retrieve();
420 \brief The class provides utility functions which can be used in the Python
421 to operate with the SALOME GUI.
423 All the functionality of this class is implemented as static methods, so they
424 can be called with the class name prefixed or via creation of the class instance.
425 For example, next both ways of SalomePyQt class usage are legal:
427 from SalomePyQt import *
429 # using SalomePyQt class instance
430 desktop = sg.getDesktop()
431 # using SalomePyQt class directly
432 menubar = SalomePyQt.getMainMenuBar()
437 \fn QWidget* SalomePyQt::getDesktop();
438 \brief Get the active application's desktop window.
439 \return desktop window or 0 if there is no any
442 class TGetDesktopEvent: public SALOME_Event
445 typedef QWidget* TResult;
447 TGetDesktopEvent() : myResult( 0 ) {}
448 virtual void Execute()
450 if ( getApplication() )
451 myResult = (QWidget*)( getApplication()->desktop() );
454 QWidget* SalomePyQt::getDesktop()
456 return ProcessEvent( new TGetDesktopEvent() );
460 \fn QWidget* SalomePyQt::getMainFrame();
461 \brief Get current application's main frame widget [obsolete].
463 Main frame widget is an internal widget of the application
464 desktop window (workspace).
466 \return workspace widget (0 on any error)
469 class TGetMainFrameEvent: public SALOME_Event
472 typedef QWidget* TResult;
474 TGetMainFrameEvent() : myResult( 0 ) {}
475 virtual void Execute()
477 if ( getApplication() ) {
478 SUIT_Desktop* aDesktop = getApplication()->desktop();
479 myResult = (QWidget*)( aDesktop->centralWidget() );
483 QWidget* SalomePyQt::getMainFrame()
485 return ProcessEvent( new TGetMainFrameEvent() );
489 \fn QMenuBar* SalomePyQt::getMainMenuBar();
490 \brief Get current application desktop's main menu.
491 \return main menu object (0 on any error)
494 class TGetMainMenuBarEvent: public SALOME_Event
497 typedef QMenuBar* TResult;
499 TGetMainMenuBarEvent() : myResult( 0 ) {}
500 virtual void Execute()
502 if ( LightApp_Application* anApp = getApplication() ) {
503 myResult = anApp->desktop()->menuBar();
507 QMenuBar* SalomePyQt::getMainMenuBar()
509 return ProcessEvent( new TGetMainMenuBarEvent() );
513 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
514 \brief Get main menu's child popup submenu by its identifier.
516 This function is obsolete.
517 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
519 \param menu menu identifier
520 \return popup submenu object or 0 if it does not exist
524 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
525 \brief Get main menu's child popup submenu by its name.
527 The function creates menu if it does not exist.
529 \param menu menu name
530 \return popup submenu object (0 on any error)
533 class TGetPopupMenuEvent: public SALOME_Event
536 typedef QMenu* TResult;
539 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
540 virtual void Execute()
542 LightApp_Application* anApp = getApplication();
543 if ( anApp && !myMenuName.isEmpty() ) {
544 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
545 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
550 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
555 menuName = getMenuName( "MEN_DESK_FILE" ); break;
557 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
559 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
561 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
563 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
565 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
567 menuName = getMenuName( "MEN_DESK_HELP" ); break;
569 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
571 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
573 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
577 \fn QTreeView* SalomePyQt::getObjectBrowser();
578 \brief Get object browser
579 \return object browser for the active study or 0 in case of error
582 class TGetObjectBrowserEvent: public SALOME_Event
585 typedef QTreeView* TResult;
587 TGetObjectBrowserEvent() : myResult( 0 ) {}
588 virtual void Execute()
590 LightApp_Application* anApp = getApplication();
591 if ( anApp && anApp->objectBrowser() ) {
592 myResult = anApp->objectBrowser()->treeView();
596 QTreeView* SalomePyQt::getObjectBrowser()
598 return ProcessEvent( new TGetObjectBrowserEvent() );
602 \fn int SalomePyQt::getStudyId();
603 \brief Get active study's identifier.
604 \return active study ID or 0 if there is no active study
607 class TGetStudyIdEvent: public SALOME_Event
612 TGetStudyIdEvent() : myResult( 0 ) {}
613 virtual void Execute()
615 if ( LightApp_Study* aStudy = getActiveStudy() ) {
616 myResult = aStudy->id();
620 int SalomePyQt::getStudyId()
622 return ProcessEvent( new TGetStudyIdEvent() );
626 \fn SALOME_Selection* SalomePyQt::getSelection();
627 \brief Get the selection object for the current study.
629 Creates a Selection object if it has not been created yet.
631 \return selection object (0 on error)
634 class TGetSelectionEvent: public SALOME_Event
637 typedef SALOME_Selection* TResult;
639 TGetSelectionEvent() : myResult( 0 ) {}
640 virtual void Execute()
642 myResult = SALOME_Selection::GetSelection( getApplication() );
645 SALOME_Selection* SalomePyQt::getSelection()
647 return ProcessEvent( new TGetSelectionEvent() );
651 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
652 \brief Send local selection for notification.
654 The list of locally selected objects (study entries) is sent for notification of
655 other listening entities (modules, viewers...).
658 class TSetSelectionEvent: public SALOME_Event
660 QStringList myEntryList;
662 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
663 virtual void Execute()
665 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
666 if ( !module ) return;
667 module->setLocalSelected(myEntryList);
670 void SalomePyQt::setSelection( const QStringList& entryList)
672 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
676 \fn void SalomePyQt::enableSelector();
677 \brief enable PyQt_Selector (on module activation, for instance)
680 class TEnableSelectorEvent: public SALOME_Event
683 TEnableSelectorEvent() {}
684 virtual void Execute()
686 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
687 if ( !module ) return;
688 module->enableSelector();
691 void SalomePyQt::enableSelector()
693 return ProcessVoidEvent( new TEnableSelectorEvent() );
698 \fn void SalomePyQt::disableSelector();
699 \brief disable PyQt_Selector (on module activation, for instance)
702 class TdisableSelectorEvent: public SALOME_Event
705 TdisableSelectorEvent() {}
706 virtual void Execute()
708 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
709 if ( !module ) return;
710 module->disableSelector();
713 void SalomePyQt::disableSelector()
715 return ProcessVoidEvent( new TdisableSelectorEvent() );
720 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
721 \brief Put an information message to the current application's
724 Optional second delay parameter (\a sec) can be used to specify
725 time of the message diplaying in seconds. If this parameter is less
726 or equal to zero, the constant message will be put.
728 \param msg message text
729 \param sec message displaying time in seconds
732 class TPutInfoEvent: public SALOME_Event
737 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
738 virtual void Execute()
740 if ( LightApp_Application* anApp = getApplication() ) {
741 anApp->putInfo( myMsg, mySecs * 1000 );
745 void SalomePyQt::putInfo( const QString& msg, const int sec )
747 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
751 \fn const QString SalomePyQt::getActiveComponent();
752 \brief Get the currently active module name (for the current study).
753 \return active module name or empty string if there is no active module
756 class TGetActiveComponentEvent: public SALOME_Event
759 typedef QString TResult;
761 TGetActiveComponentEvent() {}
762 virtual void Execute()
764 if ( LightApp_Application* anApp = getApplication() ) {
765 if ( CAM_Module* mod = anApp->activeModule() ) {
766 myResult = mod->name();
771 const QString SalomePyQt::getActiveComponent()
773 return ProcessEvent( new TGetActiveComponentEvent() );
777 \fn PyObject* SalomePyQt::getActivePythonModule();
778 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
779 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
782 class TGetActivePyModuleEvent: public SALOME_Event
785 typedef PyObject* TResult;
787 TGetActivePyModuleEvent() : myResult( Py_None ) {}
788 virtual void Execute()
790 PyModuleHelper* helper = getPythonHelper();
792 myResult = (PyObject*)helper->pythonModule();
795 PyObject* SalomePyQt::getActivePythonModule()
797 return ProcessEvent( new TGetActivePyModuleEvent() );
801 \fn bool SalomePyQt::activateModule( const QString& modName );
802 \brief Activates SALOME module with the given name
803 \return True if the module has been activated and False otherwise.
806 class TActivateModuleEvent: public SALOME_Event
809 typedef bool TResult;
811 QString myModuleName;
812 TActivateModuleEvent( const QString& modName )
813 : myResult( false ), myModuleName( modName ) {}
814 virtual void Execute()
816 if ( LightApp_Application* anApp = getApplication() ) {
817 myResult = anApp->activateModule( myModuleName );
821 bool SalomePyQt::activateModule( const QString& modName )
823 return ProcessEvent( new TActivateModuleEvent( modName ) );
827 \brief Update an Object Browser of the specified (by identifier) study.
829 If \a studyId <= 0 the active study's object browser is updated.
830 The \a updateSelection parameter is obsolete and currently is not used.
831 This parameter will be removed in future, so try to avoid its usage in
834 \brief studyId study identifier
835 \brief updateSelection update selection flag (not used)
838 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
840 class TEvent: public SALOME_Event
843 bool myUpdateSelection;
845 TEvent( const int studyId, bool updateSelection )
846 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
847 virtual void Execute()
849 if ( SUIT_Session::session() ) {
850 if ( getActiveStudy() && myStudyId <= 0 )
851 myStudyId = getActiveStudy()->id();
852 if ( myStudyId > 0 ) {
853 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
854 QList<SUIT_Application*>::Iterator it;
855 for( it = apps.begin(); it != apps.end(); ++it ) {
856 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
857 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
858 anApp->updateObjectBrowser();
866 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
871 SalomePyQt::isModified()
872 \return The modification status of the data model
873 for the currently active Python module
874 \note This function is supported for "light" Python-based SALOME modules only.
877 class TIsModifiedEvent: public SALOME_Event
880 typedef bool TResult;
882 TIsModifiedEvent() : myResult( false ) {}
883 virtual void Execute()
885 LightApp_Module* module = getActiveModule();
889 SALOME_PYQT_DataModelLight* aModel =
890 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
892 myResult = aModel->isModified();
895 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
899 bool SalomePyQt::isModified()
901 return ProcessEvent(new TIsModifiedEvent());
905 SalomePyQt::setModified()
907 Sets the modification status of the data model for
908 the currently active Python module. This method should be used
909 by the Python code in order to enable/disable "Save" operation
910 depending on the module's data state.
912 \note This function is supported for "light" Python-based SALOME modules only.
914 \param New modification status of the data model
918 void SalomePyQt::setModified( bool flag )
920 class TEvent: public SALOME_Event
926 virtual void Execute()
928 LightApp_Module* module = getActiveModule();
932 SALOME_PYQT_DataModelLight* model =
933 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
935 LightApp_Application* app = module->getApp();
937 if ( model && app ) {
938 model->setModified( myFlag );
939 app->updateActions();
942 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
946 ProcessVoidEvent( new TEvent( flag ) );
950 \brief Add string setting to the application preferences.
952 The parameter \a autoValue is obsolete parameter and currently is not used.
953 This parameter will be removed in future, so try to avoid its usage in
956 This function is obsolete. Use one of addSetting() instead.
958 \param name setting name (it should be of kind <section:setting> where
959 \c section is resources section name and \c setting is setting name)
960 \param value new setting value
961 \param autoValue (not used)
963 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
965 class TEvent: public SALOME_Event
971 TEvent( const QString& name, const QString& value, bool autoValue )
972 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
973 virtual void Execute()
975 if ( SUIT_Session::session() ) {
976 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
977 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
978 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
979 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
980 if ( !_sec.isEmpty() && !_nam.isEmpty() )
981 resMgr->setValue( _sec, _nam, myValue );
985 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
989 \brief Add integer setting to the application preferences.
991 The parameter \a autoValue is obsolete parameter and currently is not used.
992 This parameter will be removed in future, so try to avoid its usage in
995 This function is obsolete. Use one of addSetting() instead.
997 \param name setting name (it should be of kind <section:setting> where
998 \c section is resources section name and \c setting is setting name)
999 \param value new setting value
1000 \param autoValue (not used)
1002 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1004 class TEvent: public SALOME_Event
1010 TEvent( const QString& name, const int value, bool autoValue )
1011 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1012 virtual void Execute()
1014 if ( SUIT_Session::session() ) {
1015 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1016 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1017 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1018 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1019 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1020 resMgr->setValue( _sec, _nam, myValue );
1024 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1028 \brief Add double setting to the application preferences.
1030 The parameter \a autoValue is obsolete parameter and currently is not used.
1031 This parameter will be removed in future, so try to avoid its usage in
1034 This function is obsolete. Use one of addSetting() instead.
1036 \param name setting name (it should be of kind <section:setting> where
1037 \c section is resources section name and \c setting is setting name)
1038 \param value new setting value
1039 \param autoValue (not used)
1041 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1043 class TEvent: public SALOME_Event
1049 TEvent( const QString& name, const double value, bool autoValue )
1050 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1051 virtual void Execute()
1053 if ( SUIT_Session::session() ) {
1054 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1055 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1056 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1057 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1058 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1059 resMgr->setValue( _sec, _nam, myValue );
1063 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1067 \brief Add boolean setting to the application preferences.
1069 The parameter \a autoValue is obsolete parameter and currently is not used.
1070 This parameter will be removed in future, so try to avoid its usage in
1073 This function is obsolete. Use one of addSetting() instead.
1075 \param name setting name (it should be of kind <section:setting> where
1076 \c section is resources section name and \c setting is setting name)
1077 \param value new setting value
1078 \param autoValue (not used)
1080 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1082 class TEvent: public SALOME_Event
1088 TEvent( const QString& name, const bool value, bool autoValue )
1089 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1090 virtual void Execute()
1092 if ( SUIT_Session::session() ) {
1093 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1094 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1095 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1096 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1097 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1098 resMgr->setValue( _sec, _nam, myValue );
1102 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1106 \brief Remove setting from the application preferences.
1108 This function is obsolete. Use removeSetting() instead.
1110 \param name setting name (it should be of kind <section:setting> where
1111 \c section is resources section name and \c setting is setting name)
1113 void SalomePyQt::removeSettings( const QString& name )
1115 class TEvent: public SALOME_Event
1119 TEvent( const QString& name ) : myName( name ) {}
1120 virtual void Execute()
1122 if ( SUIT_Session::session() ) {
1123 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1124 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1125 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1126 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1127 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1128 resMgr->remove( _sec, _nam );
1132 ProcessVoidEvent( new TEvent( name ) );
1136 \fn QString SalomePyQt::getSetting( const QString& name );
1137 \brief Get application setting value (as string represenation).
1139 This function is obsolete. Use stringSetting(), integerSetting(),
1140 boolSetting(), stringSetting() or colorSetting() instead.
1142 \param name setting name (it should be of kind <section:setting> where
1143 \c section is resources section name and \c setting is setting name)
1144 \return setting name (empty string if setting name is invalid)
1147 class TGetSettingEvent: public SALOME_Event
1150 typedef QString TResult;
1153 TGetSettingEvent( const QString& name ) : myName( name ) {}
1154 virtual void Execute()
1156 if ( SUIT_Session::session() ) {
1157 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1158 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1159 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1160 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1161 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1165 QString SalomePyQt::getSetting( const QString& name )
1167 return ProcessEvent( new TGetSettingEvent( name ) );
1171 \fn QString SalomePyQt::constant( const QString& name );
1172 \brief Get constant's value from application's resource manager.
1174 \param name name of the constant
1175 \return value of the constant
1180 class TGetConstantEvent: public SALOME_Event
1183 typedef QString TResult;
1186 TGetConstantEvent( const QString& name ) : myName( name ) {}
1187 virtual void Execute()
1189 if ( SUIT_Session::session() )
1190 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1193 QString SalomePyQt::constant( const QString& name )
1195 return ProcessEvent( new TGetConstantEvent( name ) );
1199 \brief Add constant to the application's resource manager.
1201 This function is useful to specify programmatically specific
1202 variables that are referenced in the resource setting.
1204 For example, some resource value can be set as "$(myroot)/data/files".
1205 Then, "mypath" constant can be set programmatically by the application
1206 depending on run-time requirements.
1208 \param section resources file section name
1209 \param name name of the constant
1210 \param value value of the constant
1214 void SalomePyQt::setConstant( const QString& name, const QString& value )
1216 class TEvent: public SALOME_Event
1218 QString myName, myValue;
1220 TEvent( const QString& name, const QString& value )
1221 : myName( name ), myValue( value ) {}
1222 virtual void Execute()
1224 if ( SUIT_Session::session() )
1225 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1228 ProcessVoidEvent( new TEvent( name, value ) );
1232 \brief Add double setting to the application preferences.
1233 \param section resources file section name
1234 \param name setting name
1235 \param value new setting value
1237 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1239 class TEvent: public SALOME_Event
1245 TEvent( const QString& section, const QString& name, double value )
1246 : mySection( section ), myName( name ), myValue( value ) {}
1247 virtual void Execute()
1249 if ( SUIT_Session::session() ) {
1250 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1251 if ( !mySection.isEmpty() && !myName.isEmpty() )
1252 resMgr->setValue( mySection, myName, myValue );
1256 ProcessVoidEvent( new TEvent( section, name, value ) );
1260 \brief Add integer setting to the application preferences.
1261 \param section resources file section name
1262 \param name setting name
1263 \param value new setting value
1265 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1267 class TEvent: public SALOME_Event
1273 TEvent( const QString& section, const QString& name, int value )
1274 : mySection( section ), myName( name ), myValue( value ) {}
1275 virtual void Execute()
1277 if ( SUIT_Session::session() ) {
1278 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1279 if ( !mySection.isEmpty() && !myName.isEmpty() )
1280 resMgr->setValue( mySection, myName, myValue );
1284 ProcessVoidEvent( new TEvent( section, name, value ) );
1288 \brief Add boolean setting to the application preferences.
1289 \param section resources file section name
1290 \param name setting name
1291 \param value new setting value
1292 \param dumb this parameter is used in order to avoid sip compilation error
1293 because of conflicting int and bool types
1295 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1297 class TEvent: public SALOME_Event
1303 TEvent( const QString& section, const QString& name, bool value )
1304 : mySection( section ), myName( name ), myValue( value ) {}
1305 virtual void Execute()
1307 if ( SUIT_Session::session() ) {
1308 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1309 if ( !mySection.isEmpty() && !myName.isEmpty() )
1310 resMgr->setValue( mySection, myName, myValue );
1314 ProcessVoidEvent( new TEvent( section, name, value ) );
1318 \brief Add string setting to the application preferences.
1319 \param section resources file section name
1320 \param name setting name
1321 \param value new setting value
1323 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1325 class TEvent: public SALOME_Event
1331 TEvent( const QString& section, const QString& name, const QString& value )
1332 : mySection( section ), myName( name ), myValue( value ) {}
1333 virtual void Execute()
1335 if ( SUIT_Session::session() ) {
1336 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1337 if ( !mySection.isEmpty() && !myName.isEmpty() )
1338 resMgr->setValue( mySection, myName, myValue );
1342 ProcessVoidEvent( new TEvent( section, name, value ) );
1346 \brief Add color setting to the application preferences.
1347 \param section resources file section name
1348 \param name setting name
1349 \param value new setting value
1351 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1353 class TEvent: public SALOME_Event
1359 TEvent( const QString& section, const QString& name, const QColor& value )
1360 : mySection( section ), myName( name ), myValue( value ) {}
1361 virtual void Execute()
1363 if ( SUIT_Session::session() ) {
1364 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1365 if ( !mySection.isEmpty() && !myName.isEmpty() )
1366 resMgr->setValue( mySection, myName, myValue );
1370 ProcessVoidEvent( new TEvent( section, name, value ) );
1374 \brief Add byte array setting to the application preferences.
1375 \param section resources file section name
1376 \param name setting name
1377 \param value new setting value
1379 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1381 class TEvent: public SALOME_Event
1387 TEvent( const QString& section, const QString& name, const QByteArray& value )
1388 : mySection( section ), myName( name ), myValue( value ) {}
1389 virtual void Execute()
1391 if ( SUIT_Session::session() ) {
1392 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1393 if ( !mySection.isEmpty() && !myName.isEmpty() )
1394 resMgr->setValue( mySection, myName, myValue );
1398 ProcessVoidEvent( new TEvent( section, name, value ) );
1402 \brief Add font setting to the application preferences.
1403 \param section resources file section name
1404 \param name setting name
1405 \param value new setting value
1407 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1409 class TEvent: public SALOME_Event
1415 TEvent( const QString& section, const QString& name, const QFont& value )
1416 : mySection( section ), myName( name ), myValue( value ) {}
1417 virtual void Execute()
1419 if ( SUIT_Session::session() ) {
1420 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1421 if ( !mySection.isEmpty() && !myName.isEmpty() )
1422 resMgr->setValue( mySection, myName, myValue );
1426 ProcessVoidEvent( new TEvent( section, name, value ) );
1430 \fn int SalomePyQt::integerSetting( const QString& section,
1431 const QString& name,
1433 \brief Get integer setting from the application preferences.
1434 \param section resources file section name
1435 \param name setting name
1436 \param def default value which is returned if the setting is not found
1437 \return setting value
1440 class TGetIntSettingEvent: public SALOME_Event
1443 typedef int TResult;
1448 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1449 : mySection( section ), myName( name ), myDefault( def ) {}
1450 virtual void Execute()
1452 if ( SUIT_Session::session() ) {
1453 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1454 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1458 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1460 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1464 \fn double SalomePyQt::doubleSetting( const QString& section,
1465 const QString& name,
1467 \brief Get double setting from the application preferences.
1468 \param section resources file section name
1469 \param name setting name
1470 \param def default value which is returned if the setting is not found
1471 \return setting value
1474 class TGetDblSettingEvent: public SALOME_Event
1477 typedef double TResult;
1482 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1483 : mySection( section ), myName( name ), myDefault( def ) {}
1484 virtual void Execute()
1486 if ( SUIT_Session::session() ) {
1487 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1488 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1492 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1494 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1498 \fn bool SalomePyQt::boolSetting( const QString& section,
1499 const QString& name,
1501 \brief Get boolean setting from the application preferences.
1502 \param section resources file section name
1503 \param name setting name
1504 \param def default value which is returned if the setting is not found
1505 \return setting value
1508 class TGetBoolSettingEvent: public SALOME_Event
1511 typedef bool TResult;
1516 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1517 : mySection( section ), myName( name ), myDefault( def ) {}
1518 virtual void Execute()
1520 if ( SUIT_Session::session() ) {
1521 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1522 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1526 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1528 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1532 \fn QString SalomePyQt::stringSetting( const QString& section,
1533 const QString& name,
1536 \brief Get string setting from the application preferences.
1537 \param section resources file section name
1538 \param name setting name
1539 \param def default value which is returned if the setting is not found
1540 \param subst \c true to make substitution, \c false to get "raw" value
1541 \return setting value
1544 class TGetStrSettingEvent: public SALOME_Event
1547 typedef QString TResult;
1553 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1554 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1555 virtual void Execute()
1557 if ( SUIT_Session::session() ) {
1558 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1559 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1563 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1565 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1569 \fn QColor SalomePyQt::colorSetting( const QString& section,
1570 const QString& name,
1572 \brief Get color setting from the application preferences.
1573 \param section resources file section name
1574 \param name setting name
1575 \param def default value which is returned if the setting is not found
1576 \return setting value
1579 class TGetColorSettingEvent: public SALOME_Event
1582 typedef QColor TResult;
1587 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1588 : mySection( section ), myName( name ), myDefault( def ) {}
1589 virtual void Execute()
1591 if ( SUIT_Session::session() ) {
1592 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1593 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1597 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1599 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1603 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1604 const QString& name,
1605 const QByteArray& def );
1606 \brief Get byte array setting from the application preferences.
1607 \param section resources file section name
1608 \param name setting name
1609 \param def default value which is returned if the setting is not found
1610 \return setting value
1613 class TGetByteArraySettingEvent: public SALOME_Event
1616 typedef QByteArray TResult;
1621 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1622 : mySection( section ), myName( name ), myDefault( def ) {}
1623 virtual void Execute()
1625 if ( SUIT_Session::session() ) {
1626 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1627 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1631 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1633 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1637 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1638 const QString& name,
1640 \brief Get font setting from the application preferences.
1641 \param section resources file section name
1642 \param name setting name
1643 \param def default value which is returned if the setting is not found
1644 \return setting value
1647 class TGetFontSettingEvent: public SALOME_Event
1650 typedef QFont TResult;
1655 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1656 : mySection( section ), myName( name ), myDefault( def ) {}
1657 virtual void Execute()
1659 if ( SUIT_Session::session() ) {
1660 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1661 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1665 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1667 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1671 \brief Remove setting from the application preferences.
1672 \param section resources file section name
1673 \param name setting name
1675 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1677 class TEvent: public SALOME_Event
1682 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1683 virtual void Execute()
1685 if ( SUIT_Session::session() ) {
1686 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1687 if ( !mySection.isEmpty() && !myName.isEmpty() )
1688 resMgr->remove( mySection, myName );
1692 ProcessVoidEvent( new TEvent( section, name ) );
1696 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1697 \brief Check setting existence in the application preferences.
1698 \param section resources file section name
1699 \param name setting name
1700 \return \c true if setting exists
1703 class THasSettingEvent: public SALOME_Event
1706 typedef bool TResult;
1710 THasSettingEvent( const QString& section, const QString& name )
1711 : mySection( section ), myName( name ) {}
1712 virtual void Execute()
1714 if ( SUIT_Session::session() ) {
1715 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1716 myResult = resMgr->hasValue( mySection, myName );
1720 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1722 return ProcessEvent( new THasSettingEvent( section, name ) );
1726 \fn QStringList SalomePyQt::parameters( const QString& section );
1727 \brief Get names of preference items stored within the given section.
1728 \param section resources file section's name
1729 \return \c list of preferences items
1733 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1734 \brief Get names of preference items stored within the given section.
1735 \param section resources file section's name
1736 \return \c list of preferences items
1739 class TParametersEvent: public SALOME_Event
1742 typedef QStringList TResult;
1744 QStringList mySection;
1745 TParametersEvent( const QString& section )
1747 mySection << section;
1749 TParametersEvent( const QStringList& section )
1750 : mySection( section )
1752 virtual void Execute()
1754 if ( SUIT_Session::session() ) {
1755 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1756 myResult = resMgr->parameters( mySection );
1760 QStringList SalomePyQt::parameters( const QString& section )
1762 return ProcessEvent( new TParametersEvent( section ) );
1764 QStringList SalomePyQt::parameters( const QStringList& section )
1766 return ProcessEvent( new TParametersEvent( section ) );
1770 \fn QString SalomePyQt::getFileName( QWidget* parent,
1771 const QString& initial,
1772 const QStringList& filters,
1773 const QString& caption,
1775 \brief Show 'Open/Save file' dialog box for file selection
1776 and return a user's choice (selected file name).
1777 \param parent parent widget
1778 \param initial initial directory the dialog box to be opened in
1779 \param filters list of files filters (wildcards)
1780 \param caption dialog box title
1781 \param open if \c true, "Open File" dialog box is shown;
1782 otherwise "Save File" dialog box is shown
1783 \return selected file name (null string if user cancels operation)
1786 class TGetFileNameEvent: public SALOME_Event
1789 typedef QString TResult;
1793 QStringList myFilters;
1796 TGetFileNameEvent( QWidget* parent,
1797 const QString& initial,
1798 const QStringList& filters,
1799 const QString& caption,
1801 : myParent ( parent ),
1802 myInitial( initial ),
1803 myFilters( filters ),
1804 myCaption( caption ),
1806 virtual void Execute()
1808 if ( LightApp_Application* anApp = getApplication() ) {
1809 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1810 myCaption, myParent );
1814 QString SalomePyQt::getFileName( QWidget* parent,
1815 const QString& initial,
1816 const QStringList& filters,
1817 const QString& caption,
1820 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1824 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1825 const QString& initial,
1826 const QStringList& filters,
1827 const QString& caption );
1828 \brief Show 'Open files' dialog box for multiple files selection
1829 and return a user's choice (selected file names list).
1830 \param parent parent widget
1831 \param initial initial directory the dialog box to be opened in
1832 \param filters list of files filters (wildcards)
1833 \param caption dialog box title
1834 \return selected file names list (empty list if user cancels operation)
1837 class TGetOpenFileNamesEvent: public SALOME_Event
1840 typedef QStringList TResult;
1844 QStringList myFilters;
1846 TGetOpenFileNamesEvent( QWidget* parent,
1847 const QString& initial,
1848 const QStringList& filters,
1849 const QString& caption )
1850 : myParent ( parent ),
1851 myInitial( initial ),
1852 myFilters( filters ),
1853 myCaption( caption ) {}
1854 virtual void Execute()
1856 if ( LightApp_Application* anApp = getApplication() ) {
1857 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1861 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1862 const QString& initial,
1863 const QStringList& filters,
1864 const QString& caption )
1866 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1870 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1871 const QString& initial,
1872 const QString& caption );
1873 \brief Show 'Get Directory' dialog box for the directory selection
1874 and return a user's choice (selected directory name).
1875 \param parent parent widget
1876 \param initial initial directory the dialog box to be opened in
1877 \param caption dialog box title
1878 \return selected directory name (null string if user cancels operation)
1881 class TGetExistingDirectoryEvent: public SALOME_Event
1884 typedef QString TResult;
1889 TGetExistingDirectoryEvent( QWidget* parent,
1890 const QString& initial,
1891 const QString& caption )
1892 : myParent ( parent ),
1893 myInitial( initial ),
1894 myCaption( caption ) {}
1895 virtual void Execute()
1897 if ( LightApp_Application* anApp = getApplication() ) {
1898 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1902 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1903 const QString& initial,
1904 const QString& caption )
1906 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1910 \fn QString SalomePyQt::loadIcon( const QString& filename );
1911 \brief Load an icon from the module resources by the specified file name.
1912 \param fileName icon file name
1916 class TLoadIconEvent: public SALOME_Event
1919 typedef QIcon TResult;
1923 TLoadIconEvent( const QString& module, const QString& filename )
1924 : myModule( module ),
1925 myFileName ( filename ) {}
1926 virtual void Execute()
1928 myResult = loadIconInternal( myModule, myFileName );
1931 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1933 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1937 \brief Open external browser to display context help information.
1940 Current implementation does nothing.
1942 \param source documentation (HTML) file name
1943 \param context context (for example, HTML ancor name)
1945 void SalomePyQt::helpContext( const QString& source, const QString& context )
1947 class TEvent: public SALOME_Event
1952 TEvent( const QString& source, const QString& context )
1953 : mySource( source ), myContext( context ) {}
1954 virtual void Execute()
1956 if ( LightApp_Application* anApp = getApplication() ) {
1957 anApp->onHelpContextModule( "", mySource, myContext );
1961 ProcessVoidEvent( new TEvent( source, context ) );
1965 \fn int SalomePyQt::defaultMenuGroup();
1966 \brief Get detault menu group identifier which can be used when
1967 creating menus (insert custom menu commands).
1968 \return default menu group ID
1971 class TDefMenuGroupEvent: public SALOME_Event
1974 typedef int TResult;
1976 TDefMenuGroupEvent() : myResult( -1 ) {}
1977 virtual void Execute()
1979 myResult = PyModuleHelper::defaultMenuGroup();
1982 int SalomePyQt::defaultMenuGroup()
1984 return ProcessEvent( new TDefMenuGroupEvent() );
1990 CrTool( const QString& tBar, const QString& nBar )
1991 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1992 CrTool( const int id, const int tBar, const int idx )
1993 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1994 CrTool( const int id, const QString& tBar, const int idx )
1995 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1996 CrTool( QAction* action, const int tbId, const int id, const int idx )
1997 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1998 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1999 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2001 int execute( LightApp_Module* module ) const
2006 return module->createTool( myTbTitle, myTbName );
2008 return module->createTool( myId, myTbId, myIndex );
2010 return module->createTool( myId, myTbTitle, myIndex );
2012 return module->createTool( myAction, myTbId, myId, myIndex );
2014 return module->createTool( myAction, myTbTitle, myId, myIndex );
2029 class TCreateToolEvent: public SALOME_Event
2032 typedef int TResult;
2034 const CrTool& myCrTool;
2035 TCreateToolEvent( const CrTool& crTool )
2036 : myResult( -1 ), myCrTool( crTool ) {}
2037 virtual void Execute()
2039 LightApp_Module* module = getActiveModule();
2041 myResult = myCrTool.execute( module );
2046 \brief Create toolbar with specified name.
2047 \param tBar toolbar title (language-dependent)
2048 \param nBar toolbar name (language-independent) [optional]
2049 \return toolbar ID or -1 if toolbar creation is failed
2051 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2053 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2057 \brief Insert action with specified \a id to the toolbar.
2059 \param tBar toolbar ID
2060 \param idx required index in the toolbar
2061 \return action ID or -1 if action could not be added
2063 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2065 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2069 \brief Insert action with specified \a id to the toolbar.
2071 \param tBar toolbar name
2072 \param idx required index in the toolbar
2073 \return action ID or -1 if action could not be added
2075 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2077 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2081 \brief Insert action to the toolbar.
2083 \param tBar toolbar ID
2084 \param id required action ID
2085 \param idx required index in the toolbar
2086 \return action ID or -1 if action could not be added
2088 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2090 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2094 \brief Insert action to the toolbar.
2096 \param tBar toolbar name
2097 \param id required action ID
2098 \param idx required index in the toolbar
2099 \return action ID or -1 if action could not be added
2101 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2103 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2109 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2110 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2111 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2112 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2113 CrMenu( const int id, const int menu, const int group, const int idx )
2114 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2115 CrMenu( const int id, const QString& menu, const int group, const int idx )
2116 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2117 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2118 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2119 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2120 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2122 int execute( LightApp_Module* module ) const
2127 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2129 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2131 return module->createMenu( myId, myMenuId, myGroup, myIndex );
2133 return module->createMenu( myId, myMenuName, myGroup, myIndex );
2135 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2137 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2146 QString mySubMenuName;
2153 class TCreateMenuEvent: public SALOME_Event
2156 typedef int TResult;
2158 const CrMenu& myCrMenu;
2159 TCreateMenuEvent( const CrMenu& crMenu )
2160 : myResult( -1 ), myCrMenu( crMenu ) {}
2161 virtual void Execute()
2163 LightApp_Module* module = getActiveModule();
2165 myResult = myCrMenu.execute( module );
2170 \brief Create main menu.
2171 \param subMenu menu name
2172 \param menu parent menu ID
2173 \param id required menu ID
2174 \param group menu group ID
2175 \param idx required index in the menu
2176 \return menu ID or -1 if menu could not be added
2178 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2180 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2184 \brief Create main menu.
2185 \param subMenu menu name
2186 \param menu parent menu name (list of menu names separated by "|")
2187 \param id required menu ID
2188 \param group menu group ID
2189 \param idx required index in the menu
2190 \return menu ID or -1 if menu could not be added
2192 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2194 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2198 \brief Insert action to the main menu.
2200 \param menu parent menu ID
2201 \param group menu group ID
2202 \param idx required index in the menu
2203 \return action ID or -1 if action could not be added
2205 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2207 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2211 \brief Insert action to the main menu.
2213 \param menu parent menu name (list of menu names separated by "|")
2214 \param group menu group ID
2215 \param idx required index in the menu
2216 \return action ID or -1 if action could not be added
2218 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2220 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2224 \brief Insert action to the main menu.
2226 \param menu parent menu ID
2227 \param group menu group ID
2228 \param idx required index in the menu
2229 \return action ID or -1 if action could not be added
2231 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2233 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2237 \brief Insert action to the main menu.
2239 \param menu parent menu name (list of menu names separated by "|")
2240 \param group menu group ID
2241 \param idx required index in the menu
2242 \return action ID or -1 if action could not be added
2244 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2246 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2250 \fn QAction* SalomePyQt::createSeparator();
2251 \brief Create separator action which can be used in the menu or toolbar.
2252 \return new separator action
2255 class TCreateSepEvent: public SALOME_Event
2258 typedef QAction* TResult;
2262 virtual void Execute()
2264 LightApp_Module* module = getActiveModule();
2266 myResult = (QAction*)module->separator();
2269 QAction* SalomePyQt::createSeparator()
2271 return ProcessEvent( new TCreateSepEvent() );
2275 \fn QAction* SalomePyQt::createAction( const int id,
2276 const QString& menuText,
2277 const QString& tipText,
2278 const QString& statusText,
2279 const QString& icon,
2281 const bool toggle );
2282 \brief Create an action which can be then used in the menu or toolbar.
2283 \param id the unique id action to be registered to
2284 \param menuText action text which should appear in menu
2285 \param tipText text which should appear in the tooltip
2286 \param statusText text which should appear in the status bar when action is activated
2287 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2288 \param key the key accelrator for the action
2289 \param toggle if \c true the action is checkable
2292 class TCreateActionEvent: public SALOME_Event
2295 typedef QAction* TResult;
2300 QString myStatusText;
2304 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2305 const QString& statusText, const QString& icon, const int key, const bool toggle )
2306 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2307 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2308 virtual void Execute()
2310 LightApp_Module* module = getActiveModule();
2312 QIcon icon = loadIconInternal( module->name(), myIcon );
2313 myResult = (QAction*)module->action( myId );
2315 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2316 myResult->setToolTip( myTipText );
2317 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2318 myResult->setText( myMenuText );
2319 if ( myResult->icon().isNull() && !icon.isNull() )
2320 myResult->setIcon( icon );
2321 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2322 myResult->setStatusTip( myStatusText );
2323 if ( myResult->shortcut().isEmpty() && myKey )
2324 myResult->setShortcut( myKey );
2325 if ( myResult->isCheckable() != myToggle )
2326 myResult->setCheckable( myToggle );
2329 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2331 // for Python module, automatically connect action to callback slot
2332 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2333 if ( helper ) helper->connectAction( myResult );
2337 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2338 const QString& tipText, const QString& statusText,
2339 const QString& icon, const int key, const bool toggle )
2341 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2345 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2346 \brief Create an action group which can be then used in the menu or toolbar
2347 \param id : the unique id action group to be registered to
2348 \param exclusive : if \c true the action group does exclusive toggling
2351 struct TCreateActionGroupEvent: public SALOME_Event
2353 typedef QtxActionGroup* TResult;
2357 TCreateActionGroupEvent( const int id, const bool exclusive )
2358 : myId( id ), myExclusive( exclusive ) {}
2359 virtual void Execute()
2361 LightApp_Module* module = getActiveModule();
2363 myResult = module->createActionGroup( myId, myExclusive );
2366 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2368 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2372 \fn QAction* SalomePyQt::action( const int id );
2373 \brief Get action by specified identifier.
2374 \return action or 0 if action is not registered
2377 class TActionEvent: public SALOME_Event
2380 typedef QAction* TResult;
2383 TActionEvent( const int id )
2384 : myResult( 0 ), myId( id ) {}
2385 virtual void Execute()
2387 LightApp_Module* module = getActiveModule();
2389 myResult = (QAction*)module->action( myId );
2392 QAction* SalomePyQt::action( const int id )
2394 return ProcessEvent( new TActionEvent( id ) );
2398 \fn int SalomePyQt::actionId( const QAction* a );
2399 \brief Get an action identifier.
2400 \return action ID or -1 if action is not registered
2403 class TActionIdEvent: public SALOME_Event
2406 typedef int TResult;
2408 const QAction* myAction;
2409 TActionIdEvent( const QAction* action )
2410 : myResult( -1 ), myAction( action ) {}
2411 virtual void Execute()
2413 LightApp_Module* module = getActiveModule();
2415 myResult = module->actionId( myAction );
2418 int SalomePyQt::actionId( const QAction* a )
2420 return ProcessEvent( new TActionIdEvent( a ) );
2424 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2425 \brief Add global (not module-related) preferences group.
2426 \param label global preferences group name
2427 \return preferences group identifier
2430 class TAddGlobalPrefEvent: public SALOME_Event
2433 typedef int TResult;
2436 TAddGlobalPrefEvent( const QString& label )
2437 : myResult( -1 ), myLabel( label ) {}
2438 virtual void Execute()
2440 LightApp_Module* module = getActiveModule();
2442 LightApp_Preferences* pref = module->getApp()->preferences();
2444 myResult = pref->addPreference( myLabel, -1 );
2448 int SalomePyQt::addGlobalPreference( const QString& label )
2450 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2454 \fn int SalomePyQt::addPreference( const QString& label );
2455 \brief Add module-related preferences group.
2456 \param label preferences group name
2457 \return preferences group identifier
2460 class TAddPrefEvent: public SALOME_Event
2463 typedef int TResult;
2466 TAddPrefEvent( const QString& label )
2467 : myResult( -1 ), myLabel( label ) {}
2468 virtual void Execute()
2470 LightApp_Module* module = getActiveModule();
2472 LightApp_Preferences* pref = module->getApp()->preferences();
2474 int cId = pref->addPreference( module->moduleName(), -1 );
2476 myResult = pref->addPreference( myLabel, cId );
2481 int SalomePyQt::addPreference( const QString& label )
2483 return ProcessEvent( new TAddPrefEvent( label ) );
2487 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2488 const QString& section, const QString& param );
2489 \brief Add module-related preferences.
2490 \param label preferences group name
2491 \param pId parent preferences group id
2492 \param type preferences type
2493 \param section resources file section name
2494 \param param resources file setting name
2495 \return preferences identifier
2498 class TAddPrefParamEvent: public SALOME_Event
2501 typedef int TResult;
2508 TAddPrefParamEvent( const QString& label,
2509 const int pId, const int type,
2510 const QString& section,
2511 const QString& param )
2513 myLabel( label ), myPId( pId ), myType( type ),
2514 mySection( section ), myParam ( param ) {}
2515 virtual void Execute()
2517 LightApp_Module* module = getActiveModule();
2519 LightApp_Preferences* pref = module->getApp()->preferences();
2521 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2525 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2526 const QString& section, const QString& param )
2528 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2532 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2533 \brief Get the preferences property.
2534 \param id preferences identifier
2535 \param prop preferences property name
2536 \return preferences property value or null QVariant if property is not set
2539 class TPrefPropEvent: public SALOME_Event
2542 typedef QVariant TResult;
2546 TPrefPropEvent( const int id, const QString& prop )
2547 : myId( id ), myProp( prop ) {}
2548 virtual void Execute()
2550 LightApp_Module* module = getActiveModule();
2552 LightApp_Preferences* pref = module->getApp()->preferences();
2554 myResult = pref->itemProperty( myProp, myId );
2558 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2560 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2564 \brief Set the preferences property.
2565 \param id preferences identifier
2566 \param prop preferences property name
2567 \param var preferences property value
2569 void SalomePyQt::setPreferenceProperty( const int id,
2570 const QString& prop,
2571 const QVariant& var )
2573 class TEvent: public SALOME_Event
2579 TEvent( const int id, const QString& prop, const QVariant& var )
2580 : myId( id ), myProp( prop ), myVar( var ) {}
2581 virtual void Execute()
2583 LightApp_Module* module = getActiveModule();
2585 LightApp_Preferences* pref = module->getApp()->preferences();
2587 pref->setItemProperty( myProp, myVar, myId );
2591 ProcessVoidEvent( new TEvent( id, prop, var ) );
2595 \brief Set specific widget as a custom preferences item.
2596 \param id preferences identifier
2597 \param prop preferences property name
2598 \param widget custom widget
2600 void SalomePyQt::setPreferencePropertyWg( const int id,
2601 const QString& prop,
2602 UserDefinedContent* widget )
2604 class TEvent: public SALOME_Event
2608 UserDefinedContent* myWidget;
2610 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2611 : myId( id ), myProp( prop ), myWidget( widget ) {}
2612 virtual void Execute()
2614 LightApp_Module* module = getActiveModule();
2616 LightApp_Preferences* pref = module->getApp()->preferences();
2618 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2623 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2627 \brief Add the property value to the list of values.
2629 This method allows creating properties which are QList<QVariant>
2630 - there is no way to pass such values directly to QVariant parameter with PyQt.
2632 \param id preferences identifier
2633 \param prop preferences property name
2634 \param idx preferences property index
2635 \param var preferences property value for the index \a idx
2637 void SalomePyQt::addPreferenceProperty( const int id,
2638 const QString& prop,
2640 const QVariant& var )
2642 class TEvent: public SALOME_Event
2649 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2650 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2651 virtual void Execute()
2653 LightApp_Module* module = getActiveModule();
2655 LightApp_Preferences* pref = module->getApp()->preferences();
2657 QVariant var = pref->itemProperty( myProp, myId );
2658 if ( var.isValid() ) {
2659 if ( var.type() == QVariant::StringList ) {
2660 QStringList sl = var.toStringList();
2661 if ( myIdx >= 0 && myIdx < sl.count() )
2662 sl[myIdx] = myVar.toString();
2664 sl.append( myVar.toString() );
2665 pref->setItemProperty( myProp, sl, myId );
2667 else if ( var.type() == QVariant::List ) {
2668 QList<QVariant> vl = var.toList();
2669 if ( myIdx >= 0 && myIdx < vl.count() )
2673 pref->setItemProperty( myProp, vl, myId );
2679 pref->setItemProperty( myProp, vl, myId );
2685 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2689 \brief Put the message to the Log messages output window
2690 \param msg message text (it can be of simple rich text format)
2691 \param addSeparator boolean flag which specifies if it is necessary
2692 to separate the message with predefined separator
2694 void SalomePyQt::message( const QString& msg, bool addSeparator )
2696 class TEvent: public SALOME_Event
2701 TEvent( const QString& msg, bool addSeparator )
2702 : myMsg( msg ), myAddSep( addSeparator ) {}
2703 virtual void Execute()
2705 if ( LightApp_Application* anApp = getApplication() ) {
2706 LogWindow* lw = anApp->logWindow();
2708 lw->putMessage( myMsg, myAddSep );
2712 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2716 \brief Remove all the messages from the Log messages output window.
2718 void SalomePyQt::clearMessages()
2720 class TEvent: public SALOME_Event
2724 virtual void Execute()
2726 if ( LightApp_Application* anApp = getApplication() ) {
2727 LogWindow* lw = anApp->logWindow();
2733 ProcessVoidEvent( new TEvent() );
2737 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2738 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2739 to the image file in the specified format.
2741 For the current moment JPEG, PNG and BMP images formats are supported.
2742 The image format is defined automatically by the file name extension.
2743 By default, BMP format is used.
2745 \param filename image file name
2746 \return operation status (\c true on success)
2749 class TDumpViewEvent: public SALOME_Event
2752 typedef bool TResult;
2756 TDumpViewEvent( const QString& filename, const int id )
2757 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2758 virtual void Execute()
2760 SUIT_ViewWindow* wnd = 0;
2762 if ( LightApp_Application* anApp = getApplication() ) {
2763 SUIT_ViewManager* vm = anApp->activeViewManager();
2765 wnd = vm->getActiveView();
2767 myWndId = wnd->getId();
2770 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2773 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2774 #ifndef DISABLE_PLOT2DVIEWER
2775 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2777 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2778 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2779 qApp->processEvents();
2780 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2781 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2785 #endif // DISABLE_PLOT2DVIEWER
2786 QImage im = wnd->dumpView();
2787 if ( !im.isNull() && !myFileName.isEmpty() ) {
2788 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2789 if ( fmt == "JPG" ) fmt = "JPEG";
2790 myResult = im.save( myFileName, fmt.toLatin1() );
2795 bool SalomePyQt::dumpView( const QString& filename, const int id )
2797 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2801 \fn QList<int> SalomePyQt::getViews();
2802 \brief Get list of integer identifiers of all the currently opened views
2803 \return list of integer identifiers of all the currently opened views
2806 class TGetViews: public SALOME_Event
2809 typedef QList<int> TResult;
2812 virtual void Execute()
2815 LightApp_Application* app = getApplication();
2817 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2819 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2820 SUIT_ViewWindow* wnd;
2821 foreach ( wnd, wndlist )
2822 myResult.append( wnd->getId() );
2827 QList<int> SalomePyQt::getViews()
2829 return ProcessEvent( new TGetViews() );
2833 \fn int SalomePyQt::getActiveView();
2834 \brief Get integer identifier of the currently active view
2835 \return integer identifier of the currently active view
2838 class TGetActiveView: public SALOME_Event
2841 typedef int TResult;
2845 virtual void Execute()
2847 LightApp_Application* app = getApplication();
2849 SUIT_ViewManager* viewMgr = app->activeViewManager();
2851 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2853 myResult = wnd->getId();
2858 int SalomePyQt::getActiveView()
2860 return ProcessEvent( new TGetActiveView() );
2864 \fn QString SalomePyQt::getViewType( const int id );
2865 \brief Get type of the specified view, e.g. "OCCViewer"
2866 \param id window identifier
2870 class TGetViewType: public SALOME_Event
2873 typedef QString TResult;
2876 TGetViewType( const int id )
2878 virtual void Execute()
2880 SUIT_ViewWindow* wnd = getWnd( myWndId );
2882 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2884 myResult = viewMgr->getType();
2888 QString SalomePyQt::getViewType( const int id )
2890 return ProcessEvent( new TGetViewType( id ) );
2894 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2895 \brief Change view caption
2896 \param id window identifier
2897 \param title new window title
2898 \return \c true if operation is completed successfully and \c false otherwise
2901 class TSetViewTitle: public SALOME_Event
2904 typedef bool TResult;
2908 TSetViewTitle( const int id, const QString& title )
2909 : myResult( false ),
2912 virtual void Execute()
2914 SUIT_ViewWindow* wnd = getWnd( myWndId );
2916 wnd->setWindowTitle( myTitle );
2921 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2923 return ProcessEvent( new TSetViewTitle( id, title ) );
2927 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2928 \brief Set view size
2929 \param w window width
2930 \param h window height
2931 \param id window identifier
2932 \return \c true if operation is completed successfully and \c false otherwise
2935 class TSetViewSize: public SALOME_Event
2938 typedef bool TResult;
2943 TSetViewSize( const int w, const int h, const int id )
2944 : myResult( false ),
2948 virtual void Execute()
2950 SUIT_ViewWindow* wnd = 0;
2952 if ( LightApp_Application* anApp = getApplication() ) {
2953 SUIT_ViewManager* vm = anApp->activeViewManager();
2955 wnd = vm->getActiveView();
2959 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2962 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2964 QString type = viewMgr->getType();
2965 if ( type == "OCCViewer") {
2966 #ifndef DISABLE_OCCVIEWER
2967 // specific processing for OCC viewer:
2968 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2969 // - if there is only one sub-view active; it will be resized;
2970 // - if there are several sub-views, each of them will be resized.
2971 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2972 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2973 if ( occView && occView->getView( i ) ) {
2974 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2978 #endif // DISABLE_OCCVIEWER
2980 else if ( type == "ParaView") {
2981 #ifndef DISABLE_PVVIEWER
2982 // specific processing for ParaView viewer:
2983 // hierarchy of ParaView viewer is much complex than for usual view;
2984 // we look for sub-widget named "Viewport"
2985 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2986 if ( !lst.isEmpty() ) {
2987 lst[0]->resize( myWndWidth, myWndHeight );
2990 #endif // DISABLE_PVVIEWER
2993 if ( wnd->centralWidget() ) {
2994 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3002 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3004 return ProcessEvent( new TSetViewSize( w, h, id ) );
3008 \fn QString SalomePyQt::getViewTitle( const int id );
3009 \brief Get view caption
3010 \param id window identifier
3011 \return view caption
3014 class TGetViewTitle: public SALOME_Event
3017 typedef QString TResult;
3020 TGetViewTitle( const int id )
3022 virtual void Execute()
3024 SUIT_ViewWindow* wnd = getWnd( myWndId );
3026 myResult = wnd->windowTitle();
3029 QString SalomePyQt::getViewTitle( const int id )
3031 return ProcessEvent( new TGetViewTitle( id ) );
3035 \fn QList<int> SalomePyQt::findViews( const QString& type );
3036 \brief Get list of integer identifiers of all the
3037 currently opened views of the specified type
3038 \param type viewer type
3039 \return list of integer identifiers
3042 class TFindViews: public SALOME_Event
3045 typedef QList<int> TResult;
3048 TFindViews( const QString& type )
3050 virtual void Execute()
3053 LightApp_Application* app = getApplication();
3055 ViewManagerList vmList;
3056 app->viewManagers( myType, vmList );
3057 SUIT_ViewManager* viewMgr;
3058 foreach ( viewMgr, vmList ) {
3059 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3060 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3061 SUIT_ViewWindow* wnd = vec[ i ];
3064 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3065 myResult.append( wnd->getId() );
3072 QList<int> SalomePyQt::findViews( const QString& type )
3074 return ProcessEvent( new TFindViews( type ) );
3078 \fn bool SalomePyQt::activateView( const int id );
3079 \brief Activate view
3080 \param id window identifier
3081 \return \c true if operation is completed successfully and \c false otherwise
3084 class TActivateView: public SALOME_Event
3087 typedef bool TResult;
3090 TActivateView( const int id )
3091 : myResult( false ),
3093 virtual void Execute()
3095 SUIT_ViewWindow* wnd = getWnd( myWndId );
3096 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3103 bool SalomePyQt::activateView( const int id )
3105 return ProcessEvent( new TActivateView( id ) );
3109 \fn bool SalomePyQt::activateManagerAndView( const int id );
3110 \brief Activate view manager and view: useful for a view embedded in a module main Window
3111 \param id window identifier
3112 \return \c true if operation is completed successfully and \c false otherwise
3115 class TActivateViewManagerAndView: public SALOME_Event
3118 typedef bool TResult;
3121 TActivateViewManagerAndView( const int id )
3122 : myResult( false ),
3124 virtual void Execute()
3126 SUIT_ViewWindow* wnd = getWnd( myWndId );
3127 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3130 LightApp_Application* app = getApplication();
3131 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3137 bool SalomePyQt::activateViewManagerAndView( const int id )
3139 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3146 class TGetViewWidget: public SALOME_Event
3149 typedef QWidget* TResult;
3152 TGetViewWidget( const int id )
3155 virtual void Execute()
3157 SUIT_ViewWindow* wnd = getWnd( myWndId );
3159 myResult = (QWidget*)wnd;
3163 QWidget* SalomePyQt::getViewWidget( const int id)
3165 return ProcessEvent( new TGetViewWidget( id ) );
3170 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3171 \brief Create new view and activate it
3172 \param type viewer type
3176 \return integer identifier of created view (or -1 if view could not be created)
3179 class TCreateView: public SALOME_Event
3182 typedef int TResult;
3189 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3195 myDetached(detached) {}
3196 virtual void Execute()
3198 LightApp_Application* app = getApplication();
3200 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3202 QWidget* wnd = viewMgr->getActiveView();
3203 myResult = viewMgr->getActiveView()->getId();
3206 wnd->setVisible(false);
3207 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3211 if (myWidth > 0 && myHeight > 0) {
3212 #ifndef DISABLE_PLOT2DVIEWER
3213 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3214 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3215 #endif // DISABLE_PLOT2DVIEWER
3216 wnd->setGeometry( 0, 0, myWidth, myHeight );
3223 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3225 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3226 QCoreApplication::processEvents();
3231 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3232 \brief Create new view with custom widget embedded and activate it
3233 \param type viewer type
3234 \param w custom widget
3235 \return integer identifier of created view (or -1 if view could not be created)
3238 class TCreateViewWg: public SALOME_Event
3241 typedef int TResult;
3245 TCreateViewWg( const QString& theType, QWidget* w )
3249 virtual void Execute()
3251 LightApp_Application* app = getApplication();
3253 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3255 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3257 myResult = wnd->getId();
3262 int SalomePyQt::createView( const QString& type, QWidget* w )
3264 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3265 QCoreApplication::processEvents();
3270 \fn bool SalomePyQt::closeView( const int id );
3272 \param id window identifier
3273 \return \c true if operation is completed successfully and \c false otherwise
3276 class TCloseView: public SALOME_Event
3279 typedef bool TResult;
3282 TCloseView( const int id )
3283 : myResult( false ),
3285 virtual void Execute()
3287 SUIT_ViewWindow* wnd = getWnd( myWndId );
3289 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3297 bool SalomePyQt::closeView( const int id )
3299 return ProcessEvent( new TCloseView( id ) );
3303 \fn int SalomePyQt::cloneView( const int id );
3304 \brief Clone view (if this operation is supported for specified view type)
3305 \param id window identifier
3306 \return integer identifier of the cloned view or -1 or operation could not be performed
3309 class TCloneView: public SALOME_Event
3312 typedef int TResult;
3315 TCloneView( const int id )
3318 virtual void Execute()
3320 SUIT_ViewWindow* wnd = getWnd( myWndId );
3322 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3324 #ifndef DISABLE_OCCVIEWER
3325 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3326 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3327 occView->onCloneView();
3328 wnd = viewMgr->getActiveView();
3330 myResult = wnd->getId();
3332 #endif // DISABLE_OCCVIEWER
3333 #ifndef DISABLE_PLOT2DVIEWER
3334 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3335 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3336 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3337 if ( viewMgr2d && srcWnd2d ) {
3338 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3339 myResult = resWnd->getId();
3342 #endif // DISABLE_OCCVIEWER
3347 int SalomePyQt::cloneView( const int id )
3349 return ProcessEvent( new TCloneView( id ) );
3353 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3354 \brief Set view visibility.
3355 \param id window identifier
3356 \param visible new visiblity
3359 void SalomePyQt::setViewVisible( const int id, const bool visible )
3361 class TEvent: public SALOME_Event
3366 TEvent( const int id, const bool visible )
3367 : myWndId( id ), myVisible( visible ) {}
3368 virtual void Execute()
3370 SUIT_ViewWindow* wnd = getWnd( myWndId );
3371 if ( wnd ) wnd->setVisible( myVisible );
3374 ProcessVoidEvent( new TEvent( id, visible ) );
3378 \fn bool SalomePyQt::isViewVisible( const int id );
3379 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3380 \param id window identifier
3381 \return \c true if view is visible and \c false otherwise
3384 class TIsViewVisible: public SALOME_Event
3387 typedef bool TResult;
3390 TIsViewVisible( const int id )
3391 : myResult( false ),
3393 virtual void Execute()
3395 SUIT_ViewWindow* wnd = getWnd( myWndId );
3398 QWidget* p = wnd->parentWidget();
3399 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3403 bool SalomePyQt::isViewVisible( const int id )
3405 return ProcessEvent( new TIsViewVisible( id ) );
3409 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3410 \brief Set / clear view's "closable" option. By default any view is closable
3411 (i.e. can be closed by the user).
3412 \param id window identifier
3413 \param on new "closable" option's value
3416 void SalomePyQt::setViewClosable( const int id, const bool on )
3418 class TEvent: public SALOME_Event
3423 TEvent( const int id, const bool on )
3424 : myWndId( id ), myOn( on ) {}
3425 virtual void Execute()
3427 SUIT_ViewWindow* wnd = getWnd( myWndId );
3428 if ( wnd ) wnd->setClosable( myOn );
3431 ProcessVoidEvent( new TEvent( id, on ) );
3435 \fn bool SalomePyQt::isViewClosable( const int id );
3436 \brief Check whether view is closable (i.e. can be closed by the user)
3437 \param id window identifier
3438 \return \c true if view is closable or \c false otherwise
3441 class TIsViewClosable: public SALOME_Event
3444 typedef bool TResult;
3447 TIsViewClosable( const int id )
3450 virtual void Execute()
3452 SUIT_ViewWindow* wnd = getWnd( myWndId );
3454 myResult = wnd->closable();
3458 bool SalomePyQt::isViewClosable( const int id )
3460 return ProcessEvent( new TIsViewClosable( id ) );
3464 \fn bool SalomePyQt::groupAllViews();
3465 \brief Group all views to the single tab area
3466 \return \c true if operation is completed successfully and \c false otherwise
3469 class TGroupAllViews: public SALOME_Event
3472 typedef bool TResult;
3475 : myResult( false ) {}
3476 virtual void Execute()
3478 LightApp_Application* app = getApplication();
3480 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3482 QtxWorkstack* wStack = tabDesk->workstack();
3491 bool SalomePyQt::groupAllViews()
3493 return ProcessEvent( new TGroupAllViews() );
3497 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3498 \brief Split tab area to which view with identifier belongs to
3499 \param id window identifier
3500 \param ori orientation of split operation
3501 \param action action to be performed
3502 \return \c true if operation is completed successfully \c false otherwise
3505 class TSplitView: public SALOME_Event
3508 typedef bool TResult;
3513 TSplitView( const int id,
3514 const Orientation ori,
3515 const Action action )
3516 : myResult( false ),
3519 myAction( action ) {}
3520 virtual void Execute()
3522 SUIT_ViewWindow* wnd = getWnd( myWndId );
3525 // wnd->setFocus(); ???
3528 if ( getApplication() ) {
3529 STD_TabDesktop* desk =
3530 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3532 QtxWorkstack* wStack = desk->workstack();
3534 Qt::Orientation qtOri =
3535 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3537 QtxWorkstack::SplitType sType;
3538 if ( myAction == MoveWidget )
3539 sType = QtxWorkstack::SplitMove;
3540 else if ( myAction == LeaveWidget )
3541 sType = QtxWorkstack::SplitStay;
3543 sType = QtxWorkstack::SplitAt;
3545 wStack->Split( wnd, qtOri, sType );
3553 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3555 return ProcessEvent( new TSplitView( id, ori, action ) );
3559 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3560 \brief Move view with the first identifier to the same area which
3561 another view with the second identifier belongs to
3562 \param id source window identifier
3563 \param id_to destination window identifier
3564 param before specifies whether the first viewt has to be moved before or after
3566 \return \c true if operation is completed successfully and \c false otherwise
3569 class TMoveView: public SALOME_Event
3572 typedef bool TResult;
3577 TMoveView( const int id, const int id_to, const bool before )
3578 : myResult( false ),
3581 myIsBefore( before ) {}
3582 virtual void Execute()
3584 SUIT_ViewWindow* wnd = getWnd( myWndId );
3585 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3586 if ( wnd && wnd_to ) {
3587 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3588 getApplication()->desktop() )->workstack();
3590 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3594 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3596 return ProcessEvent( new TMoveView( id, id_to, before ) );
3600 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3601 \brief Get list of views identifiers that belongs to the same area as
3602 specified view (excluding it)
3603 \param id window identifier
3604 \return list of views identifiers
3607 class TNeighbourViews: public SALOME_Event
3610 typedef QList<int> TResult;
3613 TNeighbourViews( const int id )
3615 virtual void Execute()
3618 SUIT_ViewWindow* wnd = getWnd( myWndId );
3620 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3621 getApplication()->desktop() )->workstack();
3623 QWidgetList wgList = wStack->windowList( wnd );
3625 foreach ( wg, wgList ) {
3626 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3627 if ( tmpWnd && tmpWnd != wnd )
3628 myResult.append( tmpWnd->getId() );
3634 QList<int> SalomePyQt::neighbourViews( const int id )
3636 return ProcessEvent( new TNeighbourViews( id ) );
3641 \fn void SalomePyQt::createRoot();
3642 \brief Initialize root data object.
3644 Does nothing if root is already initialized.
3647 void SalomePyQt::createRoot()
3649 class TEvent: public SALOME_Event
3653 virtual void Execute()
3655 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3657 SALOME_PYQT_DataModelLight* dm =
3658 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3663 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3667 ProcessVoidEvent( new TEvent() );
3671 \fn QString SalomePyQt::createObject( const QString& parent );
3672 \brief Create empty data object
3673 \param parent entry of parent data object
3674 \return entry of created data object
3677 class TCreateEmptyObjectEvent: public SALOME_Event
3680 typedef QString TResult;
3683 TCreateEmptyObjectEvent( const QString& parent )
3684 : myParent( parent ) {}
3685 virtual void Execute()
3687 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3689 myResult = module->createObject( myParent );
3692 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3696 QString SalomePyQt::createObject( const QString& parent )
3698 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3702 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3703 const QString& tooltip,const QString& parent );
3704 \brief Create new data object with specified name, icon and tooltip
3705 \param name data object name
3706 \param icon data object icon
3707 \param toolTip data object tooltip
3708 \param parent entry of parent data object
3709 \return entry of created data object
3712 class TCreateObjectEvent: public SALOME_Event
3715 typedef QString TResult;
3721 TCreateObjectEvent( const QString& name,
3722 const QString& icon,
3723 const QString& tooltip,
3724 const QString& parent )
3727 myToolTip( tooltip ),
3728 myParent( parent ) {}
3729 virtual void Execute()
3731 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3733 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3736 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3740 QString SalomePyQt::createObject( const QString& name,
3741 const QString& icon,
3742 const QString& toolTip,
3743 const QString& parent )
3745 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3750 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3751 \brief Set data object name
3752 \param entry data object entry
3753 \param name data object name
3755 class TSetNameEvent: public SALOME_Event
3760 TSetNameEvent( const QString& entry,
3761 const QString& name )
3764 virtual void Execute()
3766 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3768 module->setName( myEntry, myName );
3771 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3775 void SalomePyQt::setName( const QString& entry, const QString& name )
3777 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3781 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3782 \brief Set data object icon
3783 \param entry data object entry
3784 \param icon data object icon file name (icon is loaded from module resources)
3787 class TSetIconEvent: public SALOME_Event
3792 TSetIconEvent( const QString& entry,
3793 const QString& icon )
3796 virtual void Execute()
3798 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3800 module->setIcon( myEntry, myIcon );
3803 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3808 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3810 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3814 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3815 \brief Set data object tooltip
3816 \param entry data object entry
3817 \param toolTip data object tooltip
3820 class TSetToolTipEvent: public SALOME_Event
3825 TSetToolTipEvent( const QString& entry,
3826 const QString& toolTip )
3828 myToolTip( toolTip ) {}
3829 virtual void Execute()
3831 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3833 module->setToolTip( myEntry, myToolTip );
3836 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3840 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3842 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3846 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3847 \brief Set reference to another data object
3848 \param entry data object entry
3849 \param refEntry referenced data object entry
3852 class TSetRefEvent: public SALOME_Event
3857 TSetRefEvent( const QString& entry,
3858 const QString& refEntry )
3860 myRefEntry( refEntry ) {}
3861 virtual void Execute()
3863 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3865 module->setReference( myEntry, myRefEntry );
3868 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3872 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3874 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3878 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3879 \brief Set data object color
3880 \param entry data object entry
3881 \param color data object color
3884 class TSetColorEvent: public SALOME_Event
3889 TSetColorEvent( const QString& entry,
3890 const QColor& color )
3893 virtual void Execute()
3895 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3897 module->setColor( myEntry, myColor );
3900 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3904 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3906 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3910 \fn QString SalomePyQt::getName( const QString& entry );
3911 \brief Get data object name
3912 \param entry data object entry
3913 \return data object name
3916 class TGetNameEvent: public SALOME_Event
3919 typedef QString TResult;
3922 TGetNameEvent( const QString& entry )
3923 : myEntry( entry ) {}
3924 virtual void Execute()
3926 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3928 myResult = module->getName( myEntry );
3931 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3935 QString SalomePyQt::getName( const QString& entry )
3937 return ProcessEvent( new TGetNameEvent( entry ) );
3941 \fn QString SalomePyQt::getToolTip( const QString& entry );
3942 \brief Get data object tooltip
3943 \param entry data object entry
3944 \return data object tooltip
3947 class TGetToolTipEvent: public SALOME_Event
3950 typedef QString TResult;
3953 TGetToolTipEvent( const QString& entry )
3954 : myEntry( entry ) {}
3955 virtual void Execute()
3957 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3959 myResult = module->getToolTip( myEntry );
3962 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3966 QString SalomePyQt::getToolTip( const QString& entry )
3968 return ProcessEvent( new TGetToolTipEvent( entry ) );
3972 \fn QString SalomePyQt::getReference( const QString& entry );
3973 \brief Get entry of the referenced object (if there's any)
3974 \param entry data object entry
3975 \return referenced data object entry
3978 class TGetRefEvent: public SALOME_Event
3981 typedef QString TResult;
3984 TGetRefEvent( const QString& entry )
3985 : myEntry( entry ) {}
3986 virtual void Execute()
3988 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3990 myResult = module->getReference( myEntry );
3993 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3997 QString SalomePyQt::getReference( const QString& entry )
3999 return ProcessEvent( new TGetRefEvent( entry ) );
4003 \fn QColor SalomePyQt::getColor( const QString& entry );
4004 \brief Get data object color
4005 \param entry data object entry
4006 \return data object color
4009 class TGetColorEvent: public SALOME_Event
4012 typedef QColor TResult;
4015 TGetColorEvent( const QString& entry )
4016 : myEntry( entry ) {}
4017 virtual void Execute()
4019 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4021 myResult = module->getColor( myEntry );
4024 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4028 QColor SalomePyQt::getColor( const QString& entry )
4030 return ProcessEvent( new TGetColorEvent( entry ) );
4034 \fn void SalomePyQt::removeChildren( const QString& entry );
4035 \brief Remove all child data objects from specified data object
4036 \param entry data object entry
4039 class TRemoveChildEvent: public SALOME_Event
4043 TRemoveChildEvent( const QString& entry )
4044 : myEntry( entry ) {}
4045 virtual void Execute()
4047 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4049 module->removeChildren( myEntry );
4052 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4056 void SalomePyQt::removeChildren( const QString& entry )
4058 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4060 void SalomePyQt::removeChild( const QString& entry )
4062 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4063 removeChildren( entry );
4067 \fn void SalomePyQt::removeObject( const QString& entry );
4068 \brief Remove object by entry
4069 \param entry data object entry
4072 class TRemoveObjectEvent: public SALOME_Event
4077 TRemoveObjectEvent( const QString& entry )
4078 : myEntry( entry ) {}
4079 virtual void Execute()
4081 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4083 module->removeObject( myEntry );
4086 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4090 void SalomePyQt::removeObject( const QString& entry )
4092 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4096 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4097 \brief Get entries of all child data objects of specified data object
4098 \param entry data object entry
4099 \param recursive \c true for recursive processing
4102 class TGetChildrenEvent: public SALOME_Event
4105 typedef QStringList TResult;
4109 TGetChildrenEvent( const QString& entry, const bool recursive )
4111 myRecursive( recursive ) {}
4112 virtual void Execute()
4114 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4116 myResult = module->getChildren( myEntry, myRecursive );
4119 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4123 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4125 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4128 #ifndef DISABLE_PLOT2DVIEWER
4129 // Next set of methods relates to the Plot2d viewer functionality
4132 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4133 \brief Display theCurve in view
4134 \param id window identifier
4135 \param theCurve curve to display
4138 class TDisplayCurve: public SALOME_Event
4142 Plot2d_Curve* myCurve;
4143 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4144 virtual void Execute() {
4145 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4147 wnd->getViewFrame()->displayCurve( myCurve );
4150 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4152 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4156 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4157 \brief Erase theCurve in view
4158 \param id window identifier
4159 \param theCurve curve to erase
4162 class TEraseCurve: public SALOME_Event
4166 Plot2d_Curve* myCurve;
4167 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4168 virtual void Execute() {
4169 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4170 wnd->getViewFrame()->eraseCurve( myCurve );
4173 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4175 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4179 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4180 \brief Delete theCurve from all views
4181 \param theCurve curve to delete
4184 class TDeleteCurve: public SALOME_Event
4187 Plot2d_Curve* myCurve;
4188 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4189 virtual void Execute() {
4190 LightApp_Application* app = getApplication();
4192 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4194 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4195 SUIT_ViewWindow* wnd;
4196 foreach ( wnd, wndlist ) {
4197 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4199 aP2d->getViewFrame()->eraseObject( myCurve );
4205 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4207 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4211 \brief updateCurves (repaint) curves in view window.
4213 void SalomePyQt::updateCurves( const int id )
4215 class TEvent: public SALOME_Event
4219 TEvent( const int id ) : myWndId( id ) {}
4220 virtual void Execute()
4222 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4224 wnd->getViewFrame()->DisplayAll();
4227 ProcessVoidEvent( new TEvent( id ) );
4231 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4232 \brief Get title of corresponding type
4233 \param id window identifier
4234 \param type is type of title
4235 \return title of corresponding type
4238 class TGetPlot2dTitle: public SALOME_Event
4241 typedef QString TResult;
4245 TGetPlot2dTitle(const int id, ObjectType type) :
4248 virtual void Execute() {
4249 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4251 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4254 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4256 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4261 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4262 \brief Set title of corresponding type
4263 \param id window identifier
4265 \param type is type of title
4269 class TSetPlot2dTitle: public SALOME_Event
4273 Plot2d_Curve* myCurve;
4277 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4282 virtual void Execute() {
4283 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4284 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4287 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4289 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4293 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4294 \brief Get list of Plot2d view ranges
4295 \param id window identifier
4296 \return list of view ranges (XMin, XMax, YMin, YMax)
4299 class TFitRangeByCurves: public SALOME_Event
4302 typedef QList<double> TResult;
4305 TFitRangeByCurves( const int id )
4307 virtual void Execute()
4310 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4312 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4313 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4314 myResult.append( XMin );
4315 myResult.append( XMax );
4316 myResult.append( YMin );
4317 myResult.append( YMax );
4321 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4323 return ProcessEvent( new TFitRangeByCurves( id ) );
4327 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4328 \brief Get list of current Plot2d view ranges
4329 \param id window identifier
4330 \return list of view ranges (XMin, XMax, YMin, YMax)
4333 class TFitRangeCurrent: public SALOME_Event
4336 typedef QList<double> TResult;
4339 TFitRangeCurrent( const int id )
4341 virtual void Execute()
4344 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4346 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4347 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4348 myResult.append( XMin );
4349 myResult.append( XMax );
4350 myResult.append( YMin );
4351 myResult.append( YMax );
4355 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4357 return ProcessEvent( new TFitRangeCurrent( id ) );
4361 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4362 \brief Set range of Plot2d view
4363 \param id window identifier
4370 class TPlot2dFitRange: public SALOME_Event
4378 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4384 virtual void Execute() {
4385 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4387 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4390 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4392 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4395 // End of methods related to the Plot2d viewer functionality
4396 #endif // DISABLE_PLOT2DVIEWER
4399 \brief Process Qt event loop
4401 void SalomePyQt::processEvents()
4403 QCoreApplication::processEvents();
4407 \brief Set visibility state for given object
4408 \param theEntry study ID of the object
4409 \param theState visibility state
4411 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4413 class TEvent: public SALOME_Event
4418 TEvent( const QString& theEntry, int theState ):
4419 myEntry( theEntry ), myState( theState ) {}
4420 virtual void Execute()
4422 LightApp_Study* aStudy = getActiveStudy();
4425 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4428 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4432 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4433 \brief Get visibility state for given object
4434 \param theEntry study ID of the object
4435 \return visibility state
4438 class TGetVisibilityStateEvent: public SALOME_Event
4441 typedef int TResult;
4444 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4445 virtual void Execute()
4447 LightApp_Study* aStudy = getActiveStudy();
4449 myResult = aStudy->visibilityState( myEntry );
4452 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4454 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4458 \brief Set position of given object in the tree
4459 \param theEntry study ID of the object
4460 \param thePos position
4462 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4464 class TEvent: public SALOME_Event
4469 TEvent( const QString& theEntry, int thePos ):
4470 myEntry( theEntry ), myPos( thePos ) {}
4471 virtual void Execute()
4473 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4475 module->setObjectPosition( myEntry, myPos );
4478 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4482 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4483 \brief Get position of given object in the tree
4484 \param theEntry study ID of the object
4488 class TGetObjectPositionEvent: public SALOME_Event
4491 typedef int TResult;
4494 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4495 virtual void Execute()
4497 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4499 myResult = module->getObjectPosition( myEntry );
4502 int SalomePyQt::getObjectPosition( const QString& theEntry )
4504 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4508 \brief Start recordind a log of Python commands from embedded console
4509 \param theFileName output lof file name
4511 void SalomePyQt::startPyLog( const QString& theFileName )
4513 class TEvent: public SALOME_Event
4517 TEvent( const QString& theFileName ):
4518 myFileName( theFileName ) {}
4519 virtual void Execute()
4521 if ( getApplication() ) {
4522 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4523 if ( pyConsole ) pyConsole->startLog( myFileName );
4527 ProcessVoidEvent( new TEvent( theFileName ) );
4531 \brief Stop recordind a log of Python commands from embedded console
4533 void SalomePyQt::stopPyLog()
4535 class TEvent: public SALOME_Event
4539 virtual void Execute()
4541 if ( getApplication() ) {
4542 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4543 if ( pyConsole ) pyConsole->stopLog();
4547 ProcessVoidEvent( new TEvent() );