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 \fn int SalomePyQt::integerSetting( const QString& section,
1403 const QString& name,
1405 \brief Get integer setting from the application preferences.
1406 \param section resources file section name
1407 \param name setting name
1408 \param def default value which is returned if the setting is not found
1409 \return setting value
1412 class TGetIntSettingEvent: public SALOME_Event
1415 typedef int TResult;
1420 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1421 : mySection( section ), myName( name ), myDefault( def ) {}
1422 virtual void Execute()
1424 if ( SUIT_Session::session() ) {
1425 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1426 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1430 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1432 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1436 \fn double SalomePyQt::doubleSetting( const QString& section,
1437 const QString& name,
1439 \brief Get double setting from the application preferences.
1440 \param section resources file section name
1441 \param name setting name
1442 \param def default value which is returned if the setting is not found
1443 \return setting value
1446 class TGetDblSettingEvent: public SALOME_Event
1449 typedef double TResult;
1454 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1455 : mySection( section ), myName( name ), myDefault( def ) {}
1456 virtual void Execute()
1458 if ( SUIT_Session::session() ) {
1459 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1460 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1464 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1466 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1470 \fn bool SalomePyQt::boolSetting( const QString& section,
1471 const QString& name,
1473 \brief Get boolean setting from the application preferences.
1474 \param section resources file section name
1475 \param name setting name
1476 \param def default value which is returned if the setting is not found
1477 \return setting value
1480 class TGetBoolSettingEvent: public SALOME_Event
1483 typedef bool TResult;
1488 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1489 : mySection( section ), myName( name ), myDefault( def ) {}
1490 virtual void Execute()
1492 if ( SUIT_Session::session() ) {
1493 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1494 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1498 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1500 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1504 \fn QString SalomePyQt::stringSetting( const QString& section,
1505 const QString& name,
1508 \brief Get string setting from the application preferences.
1509 \param section resources file section name
1510 \param name setting name
1511 \param def default value which is returned if the setting is not found
1512 \param subst \c true to make substitution, \c false to get "raw" value
1513 \return setting value
1516 class TGetStrSettingEvent: public SALOME_Event
1519 typedef QString TResult;
1525 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1526 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1527 virtual void Execute()
1529 if ( SUIT_Session::session() ) {
1530 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1531 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1535 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1537 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1541 \fn QColor SalomePyQt::colorSetting( const QString& section,
1542 const QString& name,
1544 \brief Get color setting from the application preferences.
1545 \param section resources file section name
1546 \param name setting name
1547 \param def default value which is returned if the setting is not found
1548 \return setting value
1551 class TGetColorSettingEvent: public SALOME_Event
1554 typedef QColor TResult;
1559 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1560 : mySection( section ), myName( name ), myDefault( def ) {}
1561 virtual void Execute()
1563 if ( SUIT_Session::session() ) {
1564 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1565 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1569 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1571 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1575 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1576 const QString& name,
1577 const QByteArray def );
1578 \brief Get byte array setting from the application preferences.
1579 \param section resources file section name
1580 \param name setting name
1581 \param def default value which is returned if the setting is not found
1582 \return setting value
1585 class TGetByteArraySettingEvent: public SALOME_Event
1588 typedef QByteArray TResult;
1593 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1594 : mySection( section ), myName( name ), myDefault( def ) {}
1595 virtual void Execute()
1597 if ( SUIT_Session::session() ) {
1598 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1599 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1603 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1605 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1609 \brief Remove setting from the application preferences.
1610 \param section resources file section name
1611 \param name setting name
1613 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1615 class TEvent: public SALOME_Event
1620 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1621 virtual void Execute()
1623 if ( SUIT_Session::session() ) {
1624 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1625 if ( !mySection.isEmpty() && !myName.isEmpty() )
1626 resMgr->remove( mySection, myName );
1630 ProcessVoidEvent( new TEvent( section, name ) );
1634 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1635 \brief Check setting existence in the application preferences.
1636 \param section resources file section name
1637 \param name setting name
1638 \return \c true if setting exists
1641 class THasSettingEvent: public SALOME_Event
1644 typedef bool TResult;
1648 THasSettingEvent( const QString& section, const QString& name )
1649 : mySection( section ), myName( name ) {}
1650 virtual void Execute()
1652 if ( SUIT_Session::session() ) {
1653 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1654 myResult = resMgr->hasValue( mySection, myName );
1658 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1660 return ProcessEvent( new THasSettingEvent( section, name ) );
1664 \fn QStringList SalomePyQt::parameters( const QString& section );
1665 \brief Get names of preference items stored within the given section.
1666 \param section resources file section's name
1667 \return \c list of preferences items
1671 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1672 \brief Get names of preference items stored within the given section.
1673 \param section resources file section's name
1674 \return \c list of preferences items
1677 class TParametersEvent: public SALOME_Event
1680 typedef QStringList TResult;
1682 QStringList mySection;
1683 TParametersEvent( const QString& section )
1685 mySection << section;
1687 TParametersEvent( const QStringList& section )
1688 : mySection( section )
1690 virtual void Execute()
1692 if ( SUIT_Session::session() ) {
1693 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1694 myResult = resMgr->parameters( mySection );
1698 QStringList SalomePyQt::parameters( const QString& section )
1700 return ProcessEvent( new TParametersEvent( section ) );
1702 QStringList SalomePyQt::parameters( const QStringList& section )
1704 return ProcessEvent( new TParametersEvent( section ) );
1708 \fn QString SalomePyQt::getFileName( QWidget* parent,
1709 const QString& initial,
1710 const QStringList& filters,
1711 const QString& caption,
1713 \brief Show 'Open/Save file' dialog box for file selection
1714 and return a user's choice (selected file name).
1715 \param parent parent widget
1716 \param initial initial directory the dialog box to be opened in
1717 \param filters list of files filters (wildcards)
1718 \param caption dialog box title
1719 \param open if \c true, "Open File" dialog box is shown;
1720 otherwise "Save File" dialog box is shown
1721 \return selected file name (null string if user cancels operation)
1724 class TGetFileNameEvent: public SALOME_Event
1727 typedef QString TResult;
1731 QStringList myFilters;
1734 TGetFileNameEvent( QWidget* parent,
1735 const QString& initial,
1736 const QStringList& filters,
1737 const QString& caption,
1739 : myParent ( parent ),
1740 myInitial( initial ),
1741 myFilters( filters ),
1742 myCaption( caption ),
1744 virtual void Execute()
1746 if ( LightApp_Application* anApp = getApplication() ) {
1747 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1748 myCaption, myParent );
1752 QString SalomePyQt::getFileName( QWidget* parent,
1753 const QString& initial,
1754 const QStringList& filters,
1755 const QString& caption,
1758 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1762 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1763 const QString& initial,
1764 const QStringList& filters,
1765 const QString& caption );
1766 \brief Show 'Open files' dialog box for multiple files selection
1767 and return a user's choice (selected file names list).
1768 \param parent parent widget
1769 \param initial initial directory the dialog box to be opened in
1770 \param filters list of files filters (wildcards)
1771 \param caption dialog box title
1772 \return selected file names list (empty list if user cancels operation)
1775 class TGetOpenFileNamesEvent: public SALOME_Event
1778 typedef QStringList TResult;
1782 QStringList myFilters;
1784 TGetOpenFileNamesEvent( QWidget* parent,
1785 const QString& initial,
1786 const QStringList& filters,
1787 const QString& caption )
1788 : myParent ( parent ),
1789 myInitial( initial ),
1790 myFilters( filters ),
1791 myCaption( caption ) {}
1792 virtual void Execute()
1794 if ( LightApp_Application* anApp = getApplication() ) {
1795 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1799 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1800 const QString& initial,
1801 const QStringList& filters,
1802 const QString& caption )
1804 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1808 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1809 const QString& initial,
1810 const QString& caption );
1811 \brief Show 'Get Directory' dialog box for the directory selection
1812 and return a user's choice (selected directory name).
1813 \param parent parent widget
1814 \param initial initial directory the dialog box to be opened in
1815 \param caption dialog box title
1816 \return selected directory name (null string if user cancels operation)
1819 class TGetExistingDirectoryEvent: public SALOME_Event
1822 typedef QString TResult;
1827 TGetExistingDirectoryEvent( QWidget* parent,
1828 const QString& initial,
1829 const QString& caption )
1830 : myParent ( parent ),
1831 myInitial( initial ),
1832 myCaption( caption ) {}
1833 virtual void Execute()
1835 if ( LightApp_Application* anApp = getApplication() ) {
1836 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1840 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1841 const QString& initial,
1842 const QString& caption )
1844 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1848 \fn QString SalomePyQt::loadIcon( const QString& filename );
1849 \brief Load an icon from the module resources by the specified file name.
1850 \param fileName icon file name
1854 class TLoadIconEvent: public SALOME_Event
1857 typedef QIcon TResult;
1861 TLoadIconEvent( const QString& module, const QString& filename )
1862 : myModule( module ),
1863 myFileName ( filename ) {}
1864 virtual void Execute()
1866 myResult = loadIconInternal( myModule, myFileName );
1869 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1871 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1875 \brief Open external browser to display context help information.
1878 Current implementation does nothing.
1880 \param source documentation (HTML) file name
1881 \param context context (for example, HTML ancor name)
1883 void SalomePyQt::helpContext( const QString& source, const QString& context )
1885 class TEvent: public SALOME_Event
1890 TEvent( const QString& source, const QString& context )
1891 : mySource( source ), myContext( context ) {}
1892 virtual void Execute()
1894 if ( LightApp_Application* anApp = getApplication() ) {
1895 anApp->onHelpContextModule( "", mySource, myContext );
1899 ProcessVoidEvent( new TEvent( source, context ) );
1903 \fn int SalomePyQt::defaultMenuGroup();
1904 \brief Get detault menu group identifier which can be used when
1905 creating menus (insert custom menu commands).
1906 \return default menu group ID
1909 class TDefMenuGroupEvent: public SALOME_Event
1912 typedef int TResult;
1914 TDefMenuGroupEvent() : myResult( -1 ) {}
1915 virtual void Execute()
1917 myResult = PyModuleHelper::defaultMenuGroup();
1920 int SalomePyQt::defaultMenuGroup()
1922 return ProcessEvent( new TDefMenuGroupEvent() );
1928 CrTool( const QString& tBar, const QString& nBar )
1929 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1930 CrTool( const int id, const int tBar, const int idx )
1931 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1932 CrTool( const int id, const QString& tBar, const int idx )
1933 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1934 CrTool( QAction* action, const int tbId, const int id, const int idx )
1935 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1936 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1937 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1939 int execute( LightApp_Module* module ) const
1944 return module->createTool( myTbTitle, myTbName );
1946 return module->createTool( myId, myTbId, myIndex );
1948 return module->createTool( myId, myTbTitle, myIndex );
1950 return module->createTool( myAction, myTbId, myId, myIndex );
1952 return module->createTool( myAction, myTbTitle, myId, myIndex );
1967 class TCreateToolEvent: public SALOME_Event
1970 typedef int TResult;
1972 const CrTool& myCrTool;
1973 TCreateToolEvent( const CrTool& crTool )
1974 : myResult( -1 ), myCrTool( crTool ) {}
1975 virtual void Execute()
1977 LightApp_Module* module = getActiveModule();
1979 myResult = myCrTool.execute( module );
1984 \brief Create toolbar with specified name.
1985 \param tBar toolbar title (language-dependent)
1986 \param nBar toolbar name (language-independent) [optional]
1987 \return toolbar ID or -1 if toolbar creation is failed
1989 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1991 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1995 \brief Insert action with specified \a id to the toolbar.
1997 \param tBar toolbar ID
1998 \param idx required index in the toolbar
1999 \return action ID or -1 if action could not be added
2001 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2003 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2007 \brief Insert action with specified \a id to the toolbar.
2009 \param tBar toolbar name
2010 \param idx required index in the toolbar
2011 \return action ID or -1 if action could not be added
2013 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2015 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2019 \brief Insert action to the toolbar.
2021 \param tBar toolbar ID
2022 \param id required action ID
2023 \param idx required index in the toolbar
2024 \return action ID or -1 if action could not be added
2026 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2028 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2032 \brief Insert action to the toolbar.
2034 \param tBar toolbar name
2035 \param id required action ID
2036 \param idx required index in the toolbar
2037 \return action ID or -1 if action could not be added
2039 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2041 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2047 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2048 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2049 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2050 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2051 CrMenu( const int id, const int menu, const int group, const int idx )
2052 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2053 CrMenu( const int id, const QString& menu, const int group, const int idx )
2054 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2055 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2056 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2057 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2058 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2060 int execute( LightApp_Module* module ) const
2065 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2067 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2069 return module->createMenu( myId, myMenuId, myGroup, myIndex );
2071 return module->createMenu( myId, myMenuName, myGroup, myIndex );
2073 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2075 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2084 QString mySubMenuName;
2091 class TCreateMenuEvent: public SALOME_Event
2094 typedef int TResult;
2096 const CrMenu& myCrMenu;
2097 TCreateMenuEvent( const CrMenu& crMenu )
2098 : myResult( -1 ), myCrMenu( crMenu ) {}
2099 virtual void Execute()
2101 LightApp_Module* module = getActiveModule();
2103 myResult = myCrMenu.execute( module );
2108 \brief Create main menu.
2109 \param subMenu menu name
2110 \param menu parent menu ID
2111 \param id required menu ID
2112 \param group menu group ID
2113 \param idx required index in the menu
2114 \return menu ID or -1 if menu could not be added
2116 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2118 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2122 \brief Create main menu.
2123 \param subMenu menu name
2124 \param menu parent menu name (list of menu names separated by "|")
2125 \param id required menu ID
2126 \param group menu group ID
2127 \param idx required index in the menu
2128 \return menu ID or -1 if menu could not be added
2130 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2132 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2136 \brief Insert action to the main menu.
2138 \param menu parent menu ID
2139 \param group menu group ID
2140 \param idx required index in the menu
2141 \return action ID or -1 if action could not be added
2143 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2145 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2149 \brief Insert action to the main menu.
2151 \param menu parent menu name (list of menu names separated by "|")
2152 \param group menu group ID
2153 \param idx required index in the menu
2154 \return action ID or -1 if action could not be added
2156 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2158 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2162 \brief Insert action to the main menu.
2164 \param menu parent menu ID
2165 \param group menu group ID
2166 \param idx required index in the menu
2167 \return action ID or -1 if action could not be added
2169 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2171 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2175 \brief Insert action to the main menu.
2177 \param menu parent menu name (list of menu names separated by "|")
2178 \param group menu group ID
2179 \param idx required index in the menu
2180 \return action ID or -1 if action could not be added
2182 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2184 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2188 \fn QAction* SalomePyQt::createSeparator();
2189 \brief Create separator action which can be used in the menu or toolbar.
2190 \return new separator action
2193 class TCreateSepEvent: public SALOME_Event
2196 typedef QAction* TResult;
2200 virtual void Execute()
2202 LightApp_Module* module = getActiveModule();
2204 myResult = (QAction*)module->separator();
2207 QAction* SalomePyQt::createSeparator()
2209 return ProcessEvent( new TCreateSepEvent() );
2213 \fn QAction* SalomePyQt::createAction( const int id,
2214 const QString& menuText,
2215 const QString& tipText,
2216 const QString& statusText,
2217 const QString& icon,
2219 const bool toggle );
2220 \brief Create an action which can be then used in the menu or toolbar.
2221 \param id the unique id action to be registered to
2222 \param menuText action text which should appear in menu
2223 \param tipText text which should appear in the tooltip
2224 \param statusText text which should appear in the status bar when action is activated
2225 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2226 \param key the key accelrator for the action
2227 \param toggle if \c true the action is checkable
2230 class TCreateActionEvent: public SALOME_Event
2233 typedef QAction* TResult;
2238 QString myStatusText;
2242 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2243 const QString& statusText, const QString& icon, const int key, const bool toggle )
2244 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2245 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2246 virtual void Execute()
2248 LightApp_Module* module = getActiveModule();
2250 QIcon icon = loadIconInternal( module->name(), myIcon );
2251 myResult = (QAction*)module->action( myId );
2253 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2254 myResult->setToolTip( myTipText );
2255 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2256 myResult->setText( myMenuText );
2257 if ( myResult->icon().isNull() && !icon.isNull() )
2258 myResult->setIcon( icon );
2259 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2260 myResult->setStatusTip( myStatusText );
2261 if ( myResult->shortcut().isEmpty() && myKey )
2262 myResult->setShortcut( myKey );
2263 if ( myResult->isCheckable() != myToggle )
2264 myResult->setCheckable( myToggle );
2267 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2269 // for Python module, automatically connect action to callback slot
2270 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2271 if ( helper ) helper->connectAction( myResult );
2275 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2276 const QString& tipText, const QString& statusText,
2277 const QString& icon, const int key, const bool toggle )
2279 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2283 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2284 \brief Create an action group which can be then used in the menu or toolbar
2285 \param id : the unique id action group to be registered to
2286 \param exclusive : if \c true the action group does exclusive toggling
2289 struct TCreateActionGroupEvent: public SALOME_Event
2291 typedef QtxActionGroup* TResult;
2295 TCreateActionGroupEvent( const int id, const bool exclusive )
2296 : myId( id ), myExclusive( exclusive ) {}
2297 virtual void Execute()
2299 LightApp_Module* module = getActiveModule();
2301 myResult = module->createActionGroup( myId, myExclusive );
2304 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2306 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2310 \fn QAction* SalomePyQt::action( const int id );
2311 \brief Get action by specified identifier.
2312 \return action or 0 if action is not registered
2315 class TActionEvent: public SALOME_Event
2318 typedef QAction* TResult;
2321 TActionEvent( const int id )
2322 : myResult( 0 ), myId( id ) {}
2323 virtual void Execute()
2325 LightApp_Module* module = getActiveModule();
2327 myResult = (QAction*)module->action( myId );
2330 QAction* SalomePyQt::action( const int id )
2332 return ProcessEvent( new TActionEvent( id ) );
2336 \fn int SalomePyQt::actionId( const QAction* a );
2337 \brief Get an action identifier.
2338 \return action ID or -1 if action is not registered
2341 class TActionIdEvent: public SALOME_Event
2344 typedef int TResult;
2346 const QAction* myAction;
2347 TActionIdEvent( const QAction* action )
2348 : myResult( -1 ), myAction( action ) {}
2349 virtual void Execute()
2351 LightApp_Module* module = getActiveModule();
2353 myResult = module->actionId( myAction );
2356 int SalomePyQt::actionId( const QAction* a )
2358 return ProcessEvent( new TActionIdEvent( a ) );
2362 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2363 \brief Add global (not module-related) preferences group.
2364 \param label global preferences group name
2365 \return preferences group identifier
2368 class TAddGlobalPrefEvent: public SALOME_Event
2371 typedef int TResult;
2374 TAddGlobalPrefEvent( const QString& label )
2375 : myResult( -1 ), myLabel( label ) {}
2376 virtual void Execute()
2378 LightApp_Module* module = getActiveModule();
2380 LightApp_Preferences* pref = module->getApp()->preferences();
2382 myResult = pref->addPreference( myLabel, -1 );
2386 int SalomePyQt::addGlobalPreference( const QString& label )
2388 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2392 \fn int SalomePyQt::addPreference( const QString& label );
2393 \brief Add module-related preferences group.
2394 \param label preferences group name
2395 \return preferences group identifier
2398 class TAddPrefEvent: public SALOME_Event
2401 typedef int TResult;
2404 TAddPrefEvent( const QString& label )
2405 : myResult( -1 ), myLabel( label ) {}
2406 virtual void Execute()
2408 LightApp_Module* module = getActiveModule();
2410 LightApp_Preferences* pref = module->getApp()->preferences();
2412 int cId = pref->addPreference( module->moduleName(), -1 );
2414 myResult = pref->addPreference( myLabel, cId );
2419 int SalomePyQt::addPreference( const QString& label )
2421 return ProcessEvent( new TAddPrefEvent( label ) );
2425 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2426 const QString& section, const QString& param );
2427 \brief Add module-related preferences.
2428 \param label preferences group name
2429 \param pId parent preferences group id
2430 \param type preferences type
2431 \param section resources file section name
2432 \param param resources file setting name
2433 \return preferences identifier
2436 class TAddPrefParamEvent: public SALOME_Event
2439 typedef int TResult;
2446 TAddPrefParamEvent( const QString& label,
2447 const int pId, const int type,
2448 const QString& section,
2449 const QString& param )
2451 myLabel( label ), myPId( pId ), myType( type ),
2452 mySection( section ), myParam ( param ) {}
2453 virtual void Execute()
2455 LightApp_Module* module = getActiveModule();
2457 LightApp_Preferences* pref = module->getApp()->preferences();
2459 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2463 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2464 const QString& section, const QString& param )
2466 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2470 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2471 \brief Get the preferences property.
2472 \param id preferences identifier
2473 \param prop preferences property name
2474 \return preferences property value or null QVariant if property is not set
2477 class TPrefPropEvent: public SALOME_Event
2480 typedef QVariant TResult;
2484 TPrefPropEvent( const int id, const QString& prop )
2485 : myId( id ), myProp( prop ) {}
2486 virtual void Execute()
2488 LightApp_Module* module = getActiveModule();
2490 LightApp_Preferences* pref = module->getApp()->preferences();
2492 myResult = pref->itemProperty( myProp, myId );
2496 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2498 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2502 \brief Set the preferences property.
2503 \param id preferences identifier
2504 \param prop preferences property name
2505 \param var preferences property value
2507 void SalomePyQt::setPreferenceProperty( const int id,
2508 const QString& prop,
2509 const QVariant& var )
2511 class TEvent: public SALOME_Event
2517 TEvent( const int id, const QString& prop, const QVariant& var )
2518 : myId( id ), myProp( prop ), myVar( var ) {}
2519 virtual void Execute()
2521 LightApp_Module* module = getActiveModule();
2523 LightApp_Preferences* pref = module->getApp()->preferences();
2525 pref->setItemProperty( myProp, myVar, myId );
2529 ProcessVoidEvent( new TEvent( id, prop, var ) );
2533 \brief Set specific widget as a custom preferences item.
2534 \param id preferences identifier
2535 \param prop preferences property name
2536 \param widget custom widget
2538 void SalomePyQt::setPreferencePropertyWg( const int id,
2539 const QString& prop,
2540 UserDefinedContent* widget )
2542 class TEvent: public SALOME_Event
2546 UserDefinedContent* myWidget;
2548 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2549 : myId( id ), myProp( prop ), myWidget( widget ) {}
2550 virtual void Execute()
2552 LightApp_Module* module = getActiveModule();
2554 LightApp_Preferences* pref = module->getApp()->preferences();
2556 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2561 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2565 \brief Add the property value to the list of values.
2567 This method allows creating properties which are QList<QVariant>
2568 - there is no way to pass such values directly to QVariant parameter with PyQt.
2570 \param id preferences identifier
2571 \param prop preferences property name
2572 \param idx preferences property index
2573 \param var preferences property value for the index \a idx
2575 void SalomePyQt::addPreferenceProperty( const int id,
2576 const QString& prop,
2578 const QVariant& var )
2580 class TEvent: public SALOME_Event
2587 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2588 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2589 virtual void Execute()
2591 LightApp_Module* module = getActiveModule();
2593 LightApp_Preferences* pref = module->getApp()->preferences();
2595 QVariant var = pref->itemProperty( myProp, myId );
2596 if ( var.isValid() ) {
2597 if ( var.type() == QVariant::StringList ) {
2598 QStringList sl = var.toStringList();
2599 if ( myIdx >= 0 && myIdx < sl.count() )
2600 sl[myIdx] = myVar.toString();
2602 sl.append( myVar.toString() );
2603 pref->setItemProperty( myProp, sl, myId );
2605 else if ( var.type() == QVariant::List ) {
2606 QList<QVariant> vl = var.toList();
2607 if ( myIdx >= 0 && myIdx < vl.count() )
2611 pref->setItemProperty( myProp, vl, myId );
2617 pref->setItemProperty( myProp, vl, myId );
2623 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2627 \brief Put the message to the Log messages output window
2628 \param msg message text (it can be of simple rich text format)
2629 \param addSeparator boolean flag which specifies if it is necessary
2630 to separate the message with predefined separator
2632 void SalomePyQt::message( const QString& msg, bool addSeparator )
2634 class TEvent: public SALOME_Event
2639 TEvent( const QString& msg, bool addSeparator )
2640 : myMsg( msg ), myAddSep( addSeparator ) {}
2641 virtual void Execute()
2643 if ( LightApp_Application* anApp = getApplication() ) {
2644 LogWindow* lw = anApp->logWindow();
2646 lw->putMessage( myMsg, myAddSep );
2650 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2654 \brief Remove all the messages from the Log messages output window.
2656 void SalomePyQt::clearMessages()
2658 class TEvent: public SALOME_Event
2662 virtual void Execute()
2664 if ( LightApp_Application* anApp = getApplication() ) {
2665 LogWindow* lw = anApp->logWindow();
2671 ProcessVoidEvent( new TEvent() );
2675 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2676 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2677 to the image file in the specified format.
2679 For the current moment JPEG, PNG and BMP images formats are supported.
2680 The image format is defined automatically by the file name extension.
2681 By default, BMP format is used.
2683 \param filename image file name
2684 \return operation status (\c true on success)
2687 class TDumpViewEvent: public SALOME_Event
2690 typedef bool TResult;
2694 TDumpViewEvent( const QString& filename, const int id )
2695 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2696 virtual void Execute()
2698 SUIT_ViewWindow* wnd = 0;
2700 if ( LightApp_Application* anApp = getApplication() ) {
2701 SUIT_ViewManager* vm = anApp->activeViewManager();
2703 wnd = vm->getActiveView();
2705 myWndId = wnd->getId();
2708 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2711 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2712 #ifndef DISABLE_PLOT2DVIEWER
2713 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2715 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2716 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2717 qApp->processEvents();
2718 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2719 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2723 #endif // DISABLE_PLOT2DVIEWER
2724 QImage im = wnd->dumpView();
2725 if ( !im.isNull() && !myFileName.isEmpty() ) {
2726 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2727 if ( fmt == "JPG" ) fmt = "JPEG";
2728 myResult = im.save( myFileName, fmt.toLatin1() );
2733 bool SalomePyQt::dumpView( const QString& filename, const int id )
2735 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2739 \fn QList<int> SalomePyQt::getViews();
2740 \brief Get list of integer identifiers of all the currently opened views
2741 \return list of integer identifiers of all the currently opened views
2744 class TGetViews: public SALOME_Event
2747 typedef QList<int> TResult;
2750 virtual void Execute()
2753 LightApp_Application* app = getApplication();
2755 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2757 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2758 SUIT_ViewWindow* wnd;
2759 foreach ( wnd, wndlist )
2760 myResult.append( wnd->getId() );
2765 QList<int> SalomePyQt::getViews()
2767 return ProcessEvent( new TGetViews() );
2771 \fn int SalomePyQt::getActiveView();
2772 \brief Get integer identifier of the currently active view
2773 \return integer identifier of the currently active view
2776 class TGetActiveView: public SALOME_Event
2779 typedef int TResult;
2783 virtual void Execute()
2785 LightApp_Application* app = getApplication();
2787 SUIT_ViewManager* viewMgr = app->activeViewManager();
2789 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2791 myResult = wnd->getId();
2796 int SalomePyQt::getActiveView()
2798 return ProcessEvent( new TGetActiveView() );
2802 \fn QString SalomePyQt::getViewType( const int id );
2803 \brief Get type of the specified view, e.g. "OCCViewer"
2804 \param id window identifier
2808 class TGetViewType: public SALOME_Event
2811 typedef QString TResult;
2814 TGetViewType( const int id )
2816 virtual void Execute()
2818 SUIT_ViewWindow* wnd = getWnd( myWndId );
2820 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2822 myResult = viewMgr->getType();
2826 QString SalomePyQt::getViewType( const int id )
2828 return ProcessEvent( new TGetViewType( id ) );
2832 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2833 \brief Change view caption
2834 \param id window identifier
2835 \param title new window title
2836 \return \c true if operation is completed successfully and \c false otherwise
2839 class TSetViewTitle: public SALOME_Event
2842 typedef bool TResult;
2846 TSetViewTitle( const int id, const QString& title )
2847 : myResult( false ),
2850 virtual void Execute()
2852 SUIT_ViewWindow* wnd = getWnd( myWndId );
2854 wnd->setWindowTitle( myTitle );
2859 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2861 return ProcessEvent( new TSetViewTitle( id, title ) );
2865 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2866 \brief Set view size
2867 \param w window width
2868 \param h window height
2869 \param id window identifier
2870 \return \c true if operation is completed successfully and \c false otherwise
2873 class TSetViewSize: public SALOME_Event
2876 typedef bool TResult;
2881 TSetViewSize( const int w, const int h, const int id )
2882 : myResult( false ),
2886 virtual void Execute()
2888 SUIT_ViewWindow* wnd = 0;
2890 if ( LightApp_Application* anApp = getApplication() ) {
2891 SUIT_ViewManager* vm = anApp->activeViewManager();
2893 wnd = vm->getActiveView();
2897 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2900 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2902 QString type = viewMgr->getType();
2903 if ( type == "OCCViewer") {
2904 #ifndef DISABLE_OCCVIEWER
2905 // specific processing for OCC viewer:
2906 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2907 // - if there is only one sub-view active; it will be resized;
2908 // - if there are several sub-views, each of them will be resized.
2909 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2910 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2911 if ( occView && occView->getView( i ) ) {
2912 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2916 #endif // DISABLE_OCCVIEWER
2918 else if ( type == "ParaView") {
2919 #ifndef DISABLE_PVVIEWER
2920 // specific processing for ParaView viewer:
2921 // hierarchy of ParaView viewer is much complex than for usual view;
2922 // we look for sub-widget named "Viewport"
2923 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2924 if ( !lst.isEmpty() ) {
2925 lst[0]->resize( myWndWidth, myWndHeight );
2928 #endif // DISABLE_PVVIEWER
2931 if ( wnd->centralWidget() ) {
2932 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2940 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2942 return ProcessEvent( new TSetViewSize( w, h, id ) );
2946 \fn QString SalomePyQt::getViewTitle( const int id );
2947 \brief Get view caption
2948 \param id window identifier
2949 \return view caption
2952 class TGetViewTitle: public SALOME_Event
2955 typedef QString TResult;
2958 TGetViewTitle( const int id )
2960 virtual void Execute()
2962 SUIT_ViewWindow* wnd = getWnd( myWndId );
2964 myResult = wnd->windowTitle();
2967 QString SalomePyQt::getViewTitle( const int id )
2969 return ProcessEvent( new TGetViewTitle( id ) );
2973 \fn QList<int> SalomePyQt::findViews( const QString& type );
2974 \brief Get list of integer identifiers of all the
2975 currently opened views of the specified type
2976 \param type viewer type
2977 \return list of integer identifiers
2980 class TFindViews: public SALOME_Event
2983 typedef QList<int> TResult;
2986 TFindViews( const QString& type )
2988 virtual void Execute()
2991 LightApp_Application* app = getApplication();
2993 ViewManagerList vmList;
2994 app->viewManagers( myType, vmList );
2995 SUIT_ViewManager* viewMgr;
2996 foreach ( viewMgr, vmList ) {
2997 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2998 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2999 SUIT_ViewWindow* wnd = vec[ i ];
3002 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3003 myResult.append( wnd->getId() );
3010 QList<int> SalomePyQt::findViews( const QString& type )
3012 return ProcessEvent( new TFindViews( type ) );
3016 \fn bool SalomePyQt::activateView( const int id );
3017 \brief Activate view
3018 \param id window identifier
3019 \return \c true if operation is completed successfully and \c false otherwise
3022 class TActivateView: public SALOME_Event
3025 typedef bool TResult;
3028 TActivateView( const int id )
3029 : myResult( false ),
3031 virtual void Execute()
3033 SUIT_ViewWindow* wnd = getWnd( myWndId );
3034 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3041 bool SalomePyQt::activateView( const int id )
3043 return ProcessEvent( new TActivateView( id ) );
3047 \fn bool SalomePyQt::activateManagerAndView( const int id );
3048 \brief Activate view manager and view: useful for a view embedded in a module main Window
3049 \param id window identifier
3050 \return \c true if operation is completed successfully and \c false otherwise
3053 class TActivateViewManagerAndView: public SALOME_Event
3056 typedef bool TResult;
3059 TActivateViewManagerAndView( const int id )
3060 : myResult( false ),
3062 virtual void Execute()
3064 SUIT_ViewWindow* wnd = getWnd( myWndId );
3065 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3068 LightApp_Application* app = getApplication();
3069 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3075 bool SalomePyQt::activateViewManagerAndView( const int id )
3077 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3084 class TGetViewWidget: public SALOME_Event
3087 typedef QWidget* TResult;
3090 TGetViewWidget( const int id )
3093 virtual void Execute()
3095 SUIT_ViewWindow* wnd = getWnd( myWndId );
3097 myResult = (QWidget*)wnd;
3101 QWidget* SalomePyQt::getViewWidget( const int id)
3103 return ProcessEvent( new TGetViewWidget( id ) );
3108 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3109 \brief Create new view and activate it
3110 \param type viewer type
3114 \return integer identifier of created view (or -1 if view could not be created)
3117 class TCreateView: public SALOME_Event
3120 typedef int TResult;
3127 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3133 myDetached(detached) {}
3134 virtual void Execute()
3136 LightApp_Application* app = getApplication();
3138 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3140 QWidget* wnd = viewMgr->getActiveView();
3141 myResult = viewMgr->getActiveView()->getId();
3144 wnd->setVisible(false);
3145 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3149 if (myWidth > 0 && myHeight > 0) {
3150 #ifndef DISABLE_PLOT2DVIEWER
3151 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3152 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3153 #endif // DISABLE_PLOT2DVIEWER
3154 wnd->setGeometry( 0, 0, myWidth, myHeight );
3161 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3163 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3164 QCoreApplication::processEvents();
3169 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3170 \brief Create new view with custom widget embedded and activate it
3171 \param type viewer type
3172 \param w custom widget
3173 \return integer identifier of created view (or -1 if view could not be created)
3176 class TCreateViewWg: public SALOME_Event
3179 typedef int TResult;
3183 TCreateViewWg( const QString& theType, QWidget* w )
3187 virtual void Execute()
3189 LightApp_Application* app = getApplication();
3191 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3193 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3195 myResult = wnd->getId();
3200 int SalomePyQt::createView( const QString& type, QWidget* w )
3202 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3203 QCoreApplication::processEvents();
3208 \fn bool SalomePyQt::closeView( const int id );
3210 \param id window identifier
3211 \return \c true if operation is completed successfully and \c false otherwise
3214 class TCloseView: public SALOME_Event
3217 typedef bool TResult;
3220 TCloseView( const int id )
3221 : myResult( false ),
3223 virtual void Execute()
3225 SUIT_ViewWindow* wnd = getWnd( myWndId );
3227 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3235 bool SalomePyQt::closeView( const int id )
3237 return ProcessEvent( new TCloseView( id ) );
3241 \fn int SalomePyQt::cloneView( const int id );
3242 \brief Clone view (if this operation is supported for specified view type)
3243 \param id window identifier
3244 \return integer identifier of the cloned view or -1 or operation could not be performed
3247 class TCloneView: public SALOME_Event
3250 typedef int TResult;
3253 TCloneView( const int id )
3256 virtual void Execute()
3258 SUIT_ViewWindow* wnd = getWnd( myWndId );
3260 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3262 #ifndef DISABLE_OCCVIEWER
3263 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3264 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3265 occView->onCloneView();
3266 wnd = viewMgr->getActiveView();
3268 myResult = wnd->getId();
3270 #endif // DISABLE_OCCVIEWER
3271 #ifndef DISABLE_PLOT2DVIEWER
3272 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3273 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3274 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3275 if ( viewMgr2d && srcWnd2d ) {
3276 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3277 myResult = resWnd->getId();
3280 #endif // DISABLE_OCCVIEWER
3285 int SalomePyQt::cloneView( const int id )
3287 return ProcessEvent( new TCloneView( id ) );
3291 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3292 \brief Set view visibility.
3293 \param id window identifier
3294 \param visible new visiblity
3297 void SalomePyQt::setViewVisible( const int id, const bool visible )
3299 class TEvent: public SALOME_Event
3304 TEvent( const int id, const bool visible )
3305 : myWndId( id ), myVisible( visible ) {}
3306 virtual void Execute()
3308 SUIT_ViewWindow* wnd = getWnd( myWndId );
3309 if ( wnd ) wnd->setVisible( myVisible );
3312 ProcessVoidEvent( new TEvent( id, visible ) );
3316 \fn bool SalomePyQt::isViewVisible( const int id );
3317 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3318 \param id window identifier
3319 \return \c true if view is visible and \c false otherwise
3322 class TIsViewVisible: public SALOME_Event
3325 typedef bool TResult;
3328 TIsViewVisible( const int id )
3329 : myResult( false ),
3331 virtual void Execute()
3333 SUIT_ViewWindow* wnd = getWnd( myWndId );
3336 QWidget* p = wnd->parentWidget();
3337 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3341 bool SalomePyQt::isViewVisible( const int id )
3343 return ProcessEvent( new TIsViewVisible( id ) );
3347 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3348 \brief Set / clear view's "closable" option. By default any view is closable
3349 (i.e. can be closed by the user).
3350 \param id window identifier
3351 \param on new "closable" option's value
3354 void SalomePyQt::setViewClosable( const int id, const bool on )
3356 class TEvent: public SALOME_Event
3361 TEvent( const int id, const bool on )
3362 : myWndId( id ), myOn( on ) {}
3363 virtual void Execute()
3365 SUIT_ViewWindow* wnd = getWnd( myWndId );
3366 if ( wnd ) wnd->setClosable( myOn );
3369 ProcessVoidEvent( new TEvent( id, on ) );
3373 \fn bool SalomePyQt::isViewClosable( const int id );
3374 \brief Check whether view is closable (i.e. can be closed by the user)
3375 \param id window identifier
3376 \return \c true if view is closable or \c false otherwise
3379 class TIsViewClosable: public SALOME_Event
3382 typedef bool TResult;
3385 TIsViewClosable( const int id )
3388 virtual void Execute()
3390 SUIT_ViewWindow* wnd = getWnd( myWndId );
3392 myResult = wnd->closable();
3396 bool SalomePyQt::isViewClosable( const int id )
3398 return ProcessEvent( new TIsViewClosable( id ) );
3402 \fn bool SalomePyQt::groupAllViews();
3403 \brief Group all views to the single tab area
3404 \return \c true if operation is completed successfully and \c false otherwise
3407 class TGroupAllViews: public SALOME_Event
3410 typedef bool TResult;
3413 : myResult( false ) {}
3414 virtual void Execute()
3416 LightApp_Application* app = getApplication();
3418 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3420 QtxWorkstack* wStack = tabDesk->workstack();
3429 bool SalomePyQt::groupAllViews()
3431 return ProcessEvent( new TGroupAllViews() );
3435 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3436 \brief Split tab area to which view with identifier belongs to
3437 \param id window identifier
3438 \param ori orientation of split operation
3439 \param action action to be performed
3440 \return \c true if operation is completed successfully \c false otherwise
3443 class TSplitView: public SALOME_Event
3446 typedef bool TResult;
3451 TSplitView( const int id,
3452 const Orientation ori,
3453 const Action action )
3454 : myResult( false ),
3457 myAction( action ) {}
3458 virtual void Execute()
3460 SUIT_ViewWindow* wnd = getWnd( myWndId );
3463 // wnd->setFocus(); ???
3466 if ( getApplication() ) {
3467 STD_TabDesktop* desk =
3468 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3470 QtxWorkstack* wStack = desk->workstack();
3472 Qt::Orientation qtOri =
3473 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3475 QtxWorkstack::SplitType sType;
3476 if ( myAction == MoveWidget )
3477 sType = QtxWorkstack::SplitMove;
3478 else if ( myAction == LeaveWidget )
3479 sType = QtxWorkstack::SplitStay;
3481 sType = QtxWorkstack::SplitAt;
3483 wStack->Split( wnd, qtOri, sType );
3491 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3493 return ProcessEvent( new TSplitView( id, ori, action ) );
3497 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3498 \brief Move view with the first identifier to the same area which
3499 another view with the second identifier belongs to
3500 \param id source window identifier
3501 \param id_to destination window identifier
3502 param before specifies whether the first viewt has to be moved before or after
3504 \return \c true if operation is completed successfully and \c false otherwise
3507 class TMoveView: public SALOME_Event
3510 typedef bool TResult;
3515 TMoveView( const int id, const int id_to, const bool before )
3516 : myResult( false ),
3519 myIsBefore( before ) {}
3520 virtual void Execute()
3522 SUIT_ViewWindow* wnd = getWnd( myWndId );
3523 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3524 if ( wnd && wnd_to ) {
3525 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3526 getApplication()->desktop() )->workstack();
3528 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3532 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3534 return ProcessEvent( new TMoveView( id, id_to, before ) );
3538 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3539 \brief Get list of views identifiers that belongs to the same area as
3540 specified view (excluding it)
3541 \param id window identifier
3542 \return list of views identifiers
3545 class TNeighbourViews: public SALOME_Event
3548 typedef QList<int> TResult;
3551 TNeighbourViews( const int id )
3553 virtual void Execute()
3556 SUIT_ViewWindow* wnd = getWnd( myWndId );
3558 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3559 getApplication()->desktop() )->workstack();
3561 QWidgetList wgList = wStack->windowList( wnd );
3563 foreach ( wg, wgList ) {
3564 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3565 if ( tmpWnd && tmpWnd != wnd )
3566 myResult.append( tmpWnd->getId() );
3572 QList<int> SalomePyQt::neighbourViews( const int id )
3574 return ProcessEvent( new TNeighbourViews( id ) );
3579 \fn void SalomePyQt::createRoot();
3580 \brief Initialize root data object.
3582 Does nothing if root is already initialized.
3585 void SalomePyQt::createRoot()
3587 class TEvent: public SALOME_Event
3591 virtual void Execute()
3593 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3595 SALOME_PYQT_DataModelLight* dm =
3596 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3601 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3605 ProcessVoidEvent( new TEvent() );
3609 \fn QString SalomePyQt::createObject( const QString& parent );
3610 \brief Create empty data object
3611 \param parent entry of parent data object
3612 \return entry of created data object
3615 class TCreateEmptyObjectEvent: public SALOME_Event
3618 typedef QString TResult;
3621 TCreateEmptyObjectEvent( const QString& parent )
3622 : myParent( parent ) {}
3623 virtual void Execute()
3625 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3627 myResult = module->createObject( myParent );
3630 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3634 QString SalomePyQt::createObject( const QString& parent )
3636 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3640 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3641 const QString& tooltip,const QString& parent );
3642 \brief Create new data object with specified name, icon and tooltip
3643 \param name data object name
3644 \param icon data object icon
3645 \param toolTip data object tooltip
3646 \param parent entry of parent data object
3647 \return entry of created data object
3650 class TCreateObjectEvent: public SALOME_Event
3653 typedef QString TResult;
3659 TCreateObjectEvent( const QString& name,
3660 const QString& icon,
3661 const QString& tooltip,
3662 const QString& parent )
3665 myToolTip( tooltip ),
3666 myParent( parent ) {}
3667 virtual void Execute()
3669 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3671 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3674 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3678 QString SalomePyQt::createObject( const QString& name,
3679 const QString& icon,
3680 const QString& toolTip,
3681 const QString& parent )
3683 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3688 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3689 \brief Set data object name
3690 \param entry data object entry
3691 \param name data object name
3693 class TSetNameEvent: public SALOME_Event
3698 TSetNameEvent( const QString& entry,
3699 const QString& name )
3702 virtual void Execute()
3704 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3706 module->setName( myEntry, myName );
3709 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3713 void SalomePyQt::setName( const QString& entry, const QString& name )
3715 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3719 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3720 \brief Set data object icon
3721 \param entry data object entry
3722 \param icon data object icon file name (icon is loaded from module resources)
3725 class TSetIconEvent: public SALOME_Event
3730 TSetIconEvent( const QString& entry,
3731 const QString& icon )
3734 virtual void Execute()
3736 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3738 module->setIcon( myEntry, myIcon );
3741 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3746 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3748 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3752 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3753 \brief Set data object tooltip
3754 \param entry data object entry
3755 \param toolTip data object tooltip
3758 class TSetToolTipEvent: public SALOME_Event
3763 TSetToolTipEvent( const QString& entry,
3764 const QString& toolTip )
3766 myToolTip( toolTip ) {}
3767 virtual void Execute()
3769 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3771 module->setToolTip( myEntry, myToolTip );
3774 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3778 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3780 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3784 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3785 \brief Set reference to another data object
3786 \param entry data object entry
3787 \param refEntry referenced data object entry
3790 class TSetRefEvent: public SALOME_Event
3795 TSetRefEvent( const QString& entry,
3796 const QString& refEntry )
3798 myRefEntry( refEntry ) {}
3799 virtual void Execute()
3801 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3803 module->setReference( myEntry, myRefEntry );
3806 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3810 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3812 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3816 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3817 \brief Set data object color
3818 \param entry data object entry
3819 \param color data object color
3822 class TSetColorEvent: public SALOME_Event
3827 TSetColorEvent( const QString& entry,
3828 const QColor& color )
3831 virtual void Execute()
3833 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3835 module->setColor( myEntry, myColor );
3838 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3842 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3844 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3848 \fn QString SalomePyQt::getName( const QString& entry );
3849 \brief Get data object name
3850 \param entry data object entry
3851 \return data object name
3854 class TGetNameEvent: public SALOME_Event
3857 typedef QString TResult;
3860 TGetNameEvent( const QString& entry )
3861 : myEntry( entry ) {}
3862 virtual void Execute()
3864 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3866 myResult = module->getName( myEntry );
3869 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3873 QString SalomePyQt::getName( const QString& entry )
3875 return ProcessEvent( new TGetNameEvent( entry ) );
3879 \fn QString SalomePyQt::getToolTip( const QString& entry );
3880 \brief Get data object tooltip
3881 \param entry data object entry
3882 \return data object tooltip
3885 class TGetToolTipEvent: public SALOME_Event
3888 typedef QString TResult;
3891 TGetToolTipEvent( const QString& entry )
3892 : myEntry( entry ) {}
3893 virtual void Execute()
3895 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3897 myResult = module->getToolTip( myEntry );
3900 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3904 QString SalomePyQt::getToolTip( const QString& entry )
3906 return ProcessEvent( new TGetToolTipEvent( entry ) );
3910 \fn QString SalomePyQt::getReference( const QString& entry );
3911 \brief Get entry of the referenced object (if there's any)
3912 \param entry data object entry
3913 \return referenced data object entry
3916 class TGetRefEvent: public SALOME_Event
3919 typedef QString TResult;
3922 TGetRefEvent( const QString& entry )
3923 : myEntry( entry ) {}
3924 virtual void Execute()
3926 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3928 myResult = module->getReference( myEntry );
3931 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3935 QString SalomePyQt::getReference( const QString& entry )
3937 return ProcessEvent( new TGetRefEvent( entry ) );
3941 \fn QColor SalomePyQt::getColor( const QString& entry );
3942 \brief Get data object color
3943 \param entry data object entry
3944 \return data object color
3947 class TGetColorEvent: public SALOME_Event
3950 typedef QColor TResult;
3953 TGetColorEvent( const QString& entry )
3954 : myEntry( entry ) {}
3955 virtual void Execute()
3957 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3959 myResult = module->getColor( myEntry );
3962 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3966 QColor SalomePyQt::getColor( const QString& entry )
3968 return ProcessEvent( new TGetColorEvent( entry ) );
3972 \fn void SalomePyQt::removeChildren( const QString& entry );
3973 \brief Remove all child data objects from specified data object
3974 \param entry data object entry
3977 class TRemoveChildEvent: public SALOME_Event
3981 TRemoveChildEvent( const QString& entry )
3982 : myEntry( entry ) {}
3983 virtual void Execute()
3985 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3987 module->removeChildren( myEntry );
3990 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3994 void SalomePyQt::removeChildren( const QString& entry )
3996 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3998 void SalomePyQt::removeChild( const QString& entry )
4000 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4001 removeChildren( entry );
4005 \fn void SalomePyQt::removeObject( const QString& entry );
4006 \brief Remove object by entry
4007 \param entry data object entry
4010 class TRemoveObjectEvent: public SALOME_Event
4015 TRemoveObjectEvent( const QString& entry )
4016 : myEntry( entry ) {}
4017 virtual void Execute()
4019 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4021 module->removeObject( myEntry );
4024 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4028 void SalomePyQt::removeObject( const QString& entry )
4030 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4034 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4035 \brief Get entries of all child data objects of specified data object
4036 \param entry data object entry
4037 \param recursive \c true for recursive processing
4040 class TGetChildrenEvent: public SALOME_Event
4043 typedef QStringList TResult;
4047 TGetChildrenEvent( const QString& entry, const bool recursive )
4049 myRecursive( recursive ) {}
4050 virtual void Execute()
4052 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4054 myResult = module->getChildren( myEntry, myRecursive );
4057 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4061 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4063 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4066 #ifndef DISABLE_PLOT2DVIEWER
4067 // Next set of methods relates to the Plot2d viewer functionality
4070 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4071 \brief Display theCurve in view
4072 \param id window identifier
4073 \param theCurve curve to display
4076 class TDisplayCurve: public SALOME_Event
4080 Plot2d_Curve* myCurve;
4081 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4082 virtual void Execute() {
4083 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4085 wnd->getViewFrame()->displayCurve( myCurve );
4088 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4090 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4094 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4095 \brief Erase theCurve in view
4096 \param id window identifier
4097 \param theCurve curve to erase
4100 class TEraseCurve: public SALOME_Event
4104 Plot2d_Curve* myCurve;
4105 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4106 virtual void Execute() {
4107 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4108 wnd->getViewFrame()->eraseCurve( myCurve );
4111 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4113 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4117 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4118 \brief Delete theCurve from all views
4119 \param theCurve curve to delete
4122 class TDeleteCurve: public SALOME_Event
4125 Plot2d_Curve* myCurve;
4126 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4127 virtual void Execute() {
4128 LightApp_Application* app = getApplication();
4130 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4132 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4133 SUIT_ViewWindow* wnd;
4134 foreach ( wnd, wndlist ) {
4135 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4137 aP2d->getViewFrame()->eraseObject( myCurve );
4143 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4145 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4149 \brief updateCurves (repaint) curves in view window.
4151 void SalomePyQt::updateCurves( const int id )
4153 class TEvent: public SALOME_Event
4157 TEvent( const int id ) : myWndId( id ) {}
4158 virtual void Execute()
4160 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4162 wnd->getViewFrame()->DisplayAll();
4165 ProcessVoidEvent( new TEvent( id ) );
4169 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4170 \brief Get title of corresponding type
4171 \param id window identifier
4172 \param type is type of title
4173 \return title of corresponding type
4176 class TGetPlot2dTitle: public SALOME_Event
4179 typedef QString TResult;
4183 TGetPlot2dTitle(const int id, ObjectType type) :
4186 virtual void Execute() {
4187 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4189 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4192 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4194 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4199 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4200 \brief Set title of corresponding type
4201 \param id window identifier
4203 \param type is type of title
4207 class TSetPlot2dTitle: public SALOME_Event
4211 Plot2d_Curve* myCurve;
4215 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4220 virtual void Execute() {
4221 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4222 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4225 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4227 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4231 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4232 \brief Get list of Plot2d view ranges
4233 \param id window identifier
4234 \return list of view ranges (XMin, XMax, YMin, YMax)
4237 class TFitRangeByCurves: public SALOME_Event
4240 typedef QList<double> TResult;
4243 TFitRangeByCurves( const int id )
4245 virtual void Execute()
4248 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4250 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4251 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4252 myResult.append( XMin );
4253 myResult.append( XMax );
4254 myResult.append( YMin );
4255 myResult.append( YMax );
4259 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4261 return ProcessEvent( new TFitRangeByCurves( id ) );
4265 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4266 \brief Get list of current Plot2d view ranges
4267 \param id window identifier
4268 \return list of view ranges (XMin, XMax, YMin, YMax)
4271 class TFitRangeCurrent: public SALOME_Event
4274 typedef QList<double> TResult;
4277 TFitRangeCurrent( const int id )
4279 virtual void Execute()
4282 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4284 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4285 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4286 myResult.append( XMin );
4287 myResult.append( XMax );
4288 myResult.append( YMin );
4289 myResult.append( YMax );
4293 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4295 return ProcessEvent( new TFitRangeCurrent( id ) );
4299 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4300 \brief Set range of Plot2d view
4301 \param id window identifier
4308 class TPlot2dFitRange: public SALOME_Event
4316 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4322 virtual void Execute() {
4323 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4325 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4328 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4330 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4333 // End of methods related to the Plot2d viewer functionality
4334 #endif // DISABLE_PLOT2DVIEWER
4337 \brief Process Qt event loop
4339 void SalomePyQt::processEvents()
4341 QCoreApplication::processEvents();
4345 \brief Set visibility state for given object
4346 \param theEntry study ID of the object
4347 \param theState visibility state
4349 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4351 class TEvent: public SALOME_Event
4356 TEvent( const QString& theEntry, int theState ):
4357 myEntry( theEntry ), myState( theState ) {}
4358 virtual void Execute()
4360 LightApp_Study* aStudy = getActiveStudy();
4363 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4366 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4370 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4371 \brief Get visibility state for given object
4372 \param theEntry study ID of the object
4373 \return visibility state
4376 class TGetVisibilityStateEvent: public SALOME_Event
4379 typedef int TResult;
4382 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4383 virtual void Execute()
4385 LightApp_Study* aStudy = getActiveStudy();
4387 myResult = aStudy->visibilityState( myEntry );
4390 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4392 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4396 \brief Set position of given object in the tree
4397 \param theEntry study ID of the object
4398 \param thePos position
4400 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4402 class TEvent: public SALOME_Event
4407 TEvent( const QString& theEntry, int thePos ):
4408 myEntry( theEntry ), myPos( thePos ) {}
4409 virtual void Execute()
4411 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4413 module->setObjectPosition( myEntry, myPos );
4416 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4420 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4421 \brief Get position of given object in the tree
4422 \param theEntry study ID of the object
4426 class TGetObjectPositionEvent: public SALOME_Event
4429 typedef int TResult;
4432 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4433 virtual void Execute()
4435 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4437 myResult = module->getObjectPosition( myEntry );
4440 int SalomePyQt::getObjectPosition( const QString& theEntry )
4442 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4446 \brief Start recordind a log of Python commands from embedded console
4447 \param theFileName output lof file name
4449 void SalomePyQt::startPyLog( const QString& theFileName )
4451 class TEvent: public SALOME_Event
4455 TEvent( const QString& theFileName ):
4456 myFileName( theFileName ) {}
4457 virtual void Execute()
4459 if ( getApplication() ) {
4460 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4461 if ( pyConsole ) pyConsole->startLog( myFileName );
4465 ProcessVoidEvent( new TEvent( theFileName ) );
4469 \brief Stop recordind a log of Python commands from embedded console
4471 void SalomePyQt::stopPyLog()
4473 class TEvent: public SALOME_Event
4477 virtual void Execute()
4479 if ( getApplication() ) {
4480 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4481 if ( pyConsole ) pyConsole->stopLog();
4485 ProcessVoidEvent( new TEvent() );