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 SALOME_Selection* SalomePyQt::getSelection();
603 \brief Get the selection object for the current study.
605 Creates a Selection object if it has not been created yet.
607 \return selection object (0 on error)
610 class TGetSelectionEvent: public SALOME_Event
613 typedef SALOME_Selection* TResult;
615 TGetSelectionEvent() : myResult( 0 ) {}
616 virtual void Execute()
618 myResult = SALOME_Selection::GetSelection( getApplication() );
621 SALOME_Selection* SalomePyQt::getSelection()
623 return ProcessEvent( new TGetSelectionEvent() );
627 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
628 \brief Send local selection for notification.
630 The list of locally selected objects (study entries) is sent for notification of
631 other listening entities (modules, viewers...).
634 class TSetSelectionEvent: public SALOME_Event
636 QStringList myEntryList;
638 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
639 virtual void Execute()
641 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
642 if ( !module ) return;
643 module->setLocalSelected(myEntryList);
646 void SalomePyQt::setSelection( const QStringList& entryList)
648 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
652 \fn void SalomePyQt::enableSelector();
653 \brief enable PyQt_Selector (on module activation, for instance)
656 class TEnableSelectorEvent: public SALOME_Event
659 TEnableSelectorEvent() {}
660 virtual void Execute()
662 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
663 if ( !module ) return;
664 module->enableSelector();
667 void SalomePyQt::enableSelector()
669 return ProcessVoidEvent( new TEnableSelectorEvent() );
674 \fn void SalomePyQt::disableSelector();
675 \brief disable PyQt_Selector (on module activation, for instance)
678 class TdisableSelectorEvent: public SALOME_Event
681 TdisableSelectorEvent() {}
682 virtual void Execute()
684 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
685 if ( !module ) return;
686 module->disableSelector();
689 void SalomePyQt::disableSelector()
691 return ProcessVoidEvent( new TdisableSelectorEvent() );
696 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
697 \brief Put an information message to the current application's
700 Optional second delay parameter (\a sec) can be used to specify
701 time of the message diplaying in seconds. If this parameter is less
702 or equal to zero, the constant message will be put.
704 \param msg message text
705 \param sec message displaying time in seconds
708 class TPutInfoEvent: public SALOME_Event
713 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
714 virtual void Execute()
716 if ( LightApp_Application* anApp = getApplication() ) {
717 anApp->putInfo( myMsg, mySecs * 1000 );
721 void SalomePyQt::putInfo( const QString& msg, const int sec )
723 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
727 \fn const QString SalomePyQt::getActiveComponent();
728 \brief Get the currently active module name (for the current study).
729 \return active module name or empty string if there is no active module
732 class TGetActiveComponentEvent: public SALOME_Event
735 typedef QString TResult;
737 TGetActiveComponentEvent() {}
738 virtual void Execute()
740 if ( LightApp_Application* anApp = getApplication() ) {
741 if ( CAM_Module* mod = anApp->activeModule() ) {
742 myResult = mod->name();
747 const QString SalomePyQt::getActiveComponent()
749 return ProcessEvent( new TGetActiveComponentEvent() );
753 \fn PyObject* SalomePyQt::getActivePythonModule();
754 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
755 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
758 class TGetActivePyModuleEvent: public SALOME_Event
761 typedef PyObject* TResult;
763 TGetActivePyModuleEvent() : myResult( Py_None ) {}
764 virtual void Execute()
766 PyModuleHelper* helper = getPythonHelper();
768 myResult = (PyObject*)helper->pythonModule();
771 PyObject* SalomePyQt::getActivePythonModule()
773 return ProcessEvent( new TGetActivePyModuleEvent() );
777 \fn bool SalomePyQt::activateModule( const QString& modName );
778 \brief Activates SALOME module with the given name
779 \return True if the module has been activated and False otherwise.
782 class TActivateModuleEvent: public SALOME_Event
785 typedef bool TResult;
787 QString myModuleName;
788 TActivateModuleEvent( const QString& modName )
789 : myResult( false ), myModuleName( modName ) {}
790 virtual void Execute()
792 if ( LightApp_Application* anApp = getApplication() ) {
793 myResult = anApp->activateModule( myModuleName );
797 bool SalomePyQt::activateModule( const QString& modName )
799 return ProcessEvent( new TActivateModuleEvent( modName ) );
803 \brief Update an Object Browser of the study.
805 void SalomePyQt::updateObjBrowser()
807 class TEvent: public SALOME_Event
811 virtual void Execute()
813 if ( SUIT_Session::session() ) {
814 if ( getActiveStudy() ) {
815 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
816 QList<SUIT_Application*>::Iterator it;
817 for( it = apps.begin(); it != apps.end(); ++it ) {
818 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
819 if ( anApp && anApp->activeStudy() ) {
820 anApp->updateObjectBrowser();
828 ProcessVoidEvent( new TEvent() );
833 SalomePyQt::isModified()
834 \return The modification status of the data model
835 for the currently active Python module
836 \note This function is supported for "light" Python-based SALOME modules only.
839 class TIsModifiedEvent: public SALOME_Event
842 typedef bool TResult;
844 TIsModifiedEvent() : myResult( false ) {}
845 virtual void Execute()
847 LightApp_Module* module = getActiveModule();
851 SALOME_PYQT_DataModelLight* aModel =
852 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
854 myResult = aModel->isModified();
857 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
861 bool SalomePyQt::isModified()
863 return ProcessEvent(new TIsModifiedEvent());
867 SalomePyQt::setModified()
869 Sets the modification status of the data model for
870 the currently active Python module. This method should be used
871 by the Python code in order to enable/disable "Save" operation
872 depending on the module's data state.
874 \note This function is supported for "light" Python-based SALOME modules only.
876 \param New modification status of the data model
880 void SalomePyQt::setModified( bool flag )
882 class TEvent: public SALOME_Event
888 virtual void Execute()
890 LightApp_Module* module = getActiveModule();
894 SALOME_PYQT_DataModelLight* model =
895 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
897 LightApp_Application* app = module->getApp();
899 if ( model && app ) {
900 model->setModified( myFlag );
901 app->updateActions();
904 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
908 ProcessVoidEvent( new TEvent( flag ) );
912 \brief Add string setting to the application preferences.
914 The parameter \a autoValue is obsolete parameter and currently is not used.
915 This parameter will be removed in future, so try to avoid its usage in
918 This function is obsolete. Use one of addSetting() instead.
920 \param name setting name (it should be of kind <section:setting> where
921 \c section is resources section name and \c setting is setting name)
922 \param value new setting value
923 \param autoValue (not used)
925 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
927 class TEvent: public SALOME_Event
933 TEvent( const QString& name, const QString& value, bool autoValue )
934 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
935 virtual void Execute()
937 if ( SUIT_Session::session() ) {
938 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
939 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
940 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
941 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
942 if ( !_sec.isEmpty() && !_nam.isEmpty() )
943 resMgr->setValue( _sec, _nam, myValue );
947 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
951 \brief Add integer setting to the application preferences.
953 The parameter \a autoValue is obsolete parameter and currently is not used.
954 This parameter will be removed in future, so try to avoid its usage in
957 This function is obsolete. Use one of addSetting() instead.
959 \param name setting name (it should be of kind <section:setting> where
960 \c section is resources section name and \c setting is setting name)
961 \param value new setting value
962 \param autoValue (not used)
964 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
966 class TEvent: public SALOME_Event
972 TEvent( const QString& name, const int value, bool autoValue )
973 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
974 virtual void Execute()
976 if ( SUIT_Session::session() ) {
977 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
978 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
979 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
980 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
981 if ( !_sec.isEmpty() && !_nam.isEmpty() )
982 resMgr->setValue( _sec, _nam, myValue );
986 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
990 \brief Add double setting to the application preferences.
992 The parameter \a autoValue is obsolete parameter and currently is not used.
993 This parameter will be removed in future, so try to avoid its usage in
996 This function is obsolete. Use one of addSetting() instead.
998 \param name setting name (it should be of kind <section:setting> where
999 \c section is resources section name and \c setting is setting name)
1000 \param value new setting value
1001 \param autoValue (not used)
1003 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1005 class TEvent: public SALOME_Event
1011 TEvent( const QString& name, const double value, bool autoValue )
1012 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1013 virtual void Execute()
1015 if ( SUIT_Session::session() ) {
1016 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1017 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1018 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1019 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1020 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1021 resMgr->setValue( _sec, _nam, myValue );
1025 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1029 \brief Add boolean setting to the application preferences.
1031 The parameter \a autoValue is obsolete parameter and currently is not used.
1032 This parameter will be removed in future, so try to avoid its usage in
1035 This function is obsolete. Use one of addSetting() instead.
1037 \param name setting name (it should be of kind <section:setting> where
1038 \c section is resources section name and \c setting is setting name)
1039 \param value new setting value
1040 \param autoValue (not used)
1042 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1044 class TEvent: public SALOME_Event
1050 TEvent( const QString& name, const bool value, bool autoValue )
1051 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1052 virtual void Execute()
1054 if ( SUIT_Session::session() ) {
1055 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1056 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1057 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1058 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1059 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1060 resMgr->setValue( _sec, _nam, myValue );
1064 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1068 \brief Remove setting from the application preferences.
1070 This function is obsolete. Use removeSetting() instead.
1072 \param name setting name (it should be of kind <section:setting> where
1073 \c section is resources section name and \c setting is setting name)
1075 void SalomePyQt::removeSettings( const QString& name )
1077 class TEvent: public SALOME_Event
1081 TEvent( const QString& name ) : myName( name ) {}
1082 virtual void Execute()
1084 if ( SUIT_Session::session() ) {
1085 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1086 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1087 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1088 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1089 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1090 resMgr->remove( _sec, _nam );
1094 ProcessVoidEvent( new TEvent( name ) );
1098 \fn QString SalomePyQt::getSetting( const QString& name );
1099 \brief Get application setting value (as string represenation).
1101 This function is obsolete. Use stringSetting(), integerSetting(),
1102 boolSetting(), stringSetting() or colorSetting() instead.
1104 \param name setting name (it should be of kind <section:setting> where
1105 \c section is resources section name and \c setting is setting name)
1106 \return setting name (empty string if setting name is invalid)
1109 class TGetSettingEvent: public SALOME_Event
1112 typedef QString TResult;
1115 TGetSettingEvent( const QString& name ) : myName( name ) {}
1116 virtual void Execute()
1118 if ( SUIT_Session::session() ) {
1119 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1120 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1121 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1122 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1123 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1127 QString SalomePyQt::getSetting( const QString& name )
1129 return ProcessEvent( new TGetSettingEvent( name ) );
1133 \fn QString SalomePyQt::constant( const QString& name );
1134 \brief Get constant's value from application's resource manager.
1136 \param name name of the constant
1137 \return value of the constant
1142 class TGetConstantEvent: public SALOME_Event
1145 typedef QString TResult;
1148 TGetConstantEvent( const QString& name ) : myName( name ) {}
1149 virtual void Execute()
1151 if ( SUIT_Session::session() )
1152 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1155 QString SalomePyQt::constant( const QString& name )
1157 return ProcessEvent( new TGetConstantEvent( name ) );
1161 \brief Add constant to the application's resource manager.
1163 This function is useful to specify programmatically specific
1164 variables that are referenced in the resource setting.
1166 For example, some resource value can be set as "$(myroot)/data/files".
1167 Then, "mypath" constant can be set programmatically by the application
1168 depending on run-time requirements.
1170 \param section resources file section name
1171 \param name name of the constant
1172 \param value value of the constant
1176 void SalomePyQt::setConstant( const QString& name, const QString& value )
1178 class TEvent: public SALOME_Event
1180 QString myName, myValue;
1182 TEvent( const QString& name, const QString& value )
1183 : myName( name ), myValue( value ) {}
1184 virtual void Execute()
1186 if ( SUIT_Session::session() )
1187 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1190 ProcessVoidEvent( new TEvent( name, value ) );
1194 \brief Add double setting to the application preferences.
1195 \param section resources file section name
1196 \param name setting name
1197 \param value new setting value
1199 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1201 class TEvent: public SALOME_Event
1207 TEvent( const QString& section, const QString& name, double value )
1208 : mySection( section ), myName( name ), myValue( value ) {}
1209 virtual void Execute()
1211 if ( SUIT_Session::session() ) {
1212 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1213 if ( !mySection.isEmpty() && !myName.isEmpty() )
1214 resMgr->setValue( mySection, myName, myValue );
1218 ProcessVoidEvent( new TEvent( section, name, value ) );
1222 \brief Add integer setting to the application preferences.
1223 \param section resources file section name
1224 \param name setting name
1225 \param value new setting value
1227 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1229 class TEvent: public SALOME_Event
1235 TEvent( const QString& section, const QString& name, int value )
1236 : mySection( section ), myName( name ), myValue( value ) {}
1237 virtual void Execute()
1239 if ( SUIT_Session::session() ) {
1240 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1241 if ( !mySection.isEmpty() && !myName.isEmpty() )
1242 resMgr->setValue( mySection, myName, myValue );
1246 ProcessVoidEvent( new TEvent( section, name, value ) );
1250 \brief Add boolean setting to the application preferences.
1251 \param section resources file section name
1252 \param name setting name
1253 \param value new setting value
1254 \param dumb this parameter is used in order to avoid sip compilation error
1255 because of conflicting int and bool types
1257 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1259 class TEvent: public SALOME_Event
1265 TEvent( const QString& section, const QString& name, bool value )
1266 : mySection( section ), myName( name ), myValue( value ) {}
1267 virtual void Execute()
1269 if ( SUIT_Session::session() ) {
1270 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1271 if ( !mySection.isEmpty() && !myName.isEmpty() )
1272 resMgr->setValue( mySection, myName, myValue );
1276 ProcessVoidEvent( new TEvent( section, name, value ) );
1280 \brief Add string setting to the application preferences.
1281 \param section resources file section name
1282 \param name setting name
1283 \param value new setting value
1285 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1287 class TEvent: public SALOME_Event
1293 TEvent( const QString& section, const QString& name, const QString& value )
1294 : mySection( section ), myName( name ), myValue( value ) {}
1295 virtual void Execute()
1297 if ( SUIT_Session::session() ) {
1298 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1299 if ( !mySection.isEmpty() && !myName.isEmpty() )
1300 resMgr->setValue( mySection, myName, myValue );
1304 ProcessVoidEvent( new TEvent( section, name, value ) );
1308 \brief Add color setting to the application preferences.
1309 \param section resources file section name
1310 \param name setting name
1311 \param value new setting value
1313 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1315 class TEvent: public SALOME_Event
1321 TEvent( const QString& section, const QString& name, const QColor& value )
1322 : mySection( section ), myName( name ), myValue( value ) {}
1323 virtual void Execute()
1325 if ( SUIT_Session::session() ) {
1326 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1327 if ( !mySection.isEmpty() && !myName.isEmpty() )
1328 resMgr->setValue( mySection, myName, myValue );
1332 ProcessVoidEvent( new TEvent( section, name, value ) );
1336 \brief Add byte array setting to the application preferences.
1337 \param section resources file section name
1338 \param name setting name
1339 \param value new setting value
1341 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1343 class TEvent: public SALOME_Event
1349 TEvent( const QString& section, const QString& name, const QByteArray& value )
1350 : mySection( section ), myName( name ), myValue( value ) {}
1351 virtual void Execute()
1353 if ( SUIT_Session::session() ) {
1354 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1355 if ( !mySection.isEmpty() && !myName.isEmpty() )
1356 resMgr->setValue( mySection, myName, myValue );
1360 ProcessVoidEvent( new TEvent( section, name, value ) );
1364 \brief Add font setting to the application preferences.
1365 \param section resources file section name
1366 \param name setting name
1367 \param value new setting value
1369 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1371 class TEvent: public SALOME_Event
1377 TEvent( const QString& section, const QString& name, const QFont& value )
1378 : mySection( section ), myName( name ), myValue( value ) {}
1379 virtual void Execute()
1381 if ( SUIT_Session::session() ) {
1382 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1383 if ( !mySection.isEmpty() && !myName.isEmpty() )
1384 resMgr->setValue( mySection, myName, myValue );
1388 ProcessVoidEvent( new TEvent( section, name, value ) );
1392 \fn int SalomePyQt::integerSetting( const QString& section,
1393 const QString& name,
1395 \brief Get integer setting from the application preferences.
1396 \param section resources file section name
1397 \param name setting name
1398 \param def default value which is returned if the setting is not found
1399 \return setting value
1402 class TGetIntSettingEvent: public SALOME_Event
1405 typedef int TResult;
1410 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1411 : mySection( section ), myName( name ), myDefault( def ) {}
1412 virtual void Execute()
1414 if ( SUIT_Session::session() ) {
1415 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1416 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1420 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1422 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1426 \fn double SalomePyQt::doubleSetting( const QString& section,
1427 const QString& name,
1429 \brief Get double setting from the application preferences.
1430 \param section resources file section name
1431 \param name setting name
1432 \param def default value which is returned if the setting is not found
1433 \return setting value
1436 class TGetDblSettingEvent: public SALOME_Event
1439 typedef double TResult;
1444 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1445 : mySection( section ), myName( name ), myDefault( def ) {}
1446 virtual void Execute()
1448 if ( SUIT_Session::session() ) {
1449 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1450 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1454 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1456 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1460 \fn bool SalomePyQt::boolSetting( const QString& section,
1461 const QString& name,
1463 \brief Get boolean setting from the application preferences.
1464 \param section resources file section name
1465 \param name setting name
1466 \param def default value which is returned if the setting is not found
1467 \return setting value
1470 class TGetBoolSettingEvent: public SALOME_Event
1473 typedef bool TResult;
1478 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1479 : mySection( section ), myName( name ), myDefault( def ) {}
1480 virtual void Execute()
1482 if ( SUIT_Session::session() ) {
1483 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1484 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1488 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1490 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1494 \fn QString SalomePyQt::stringSetting( const QString& section,
1495 const QString& name,
1498 \brief Get string setting from the application preferences.
1499 \param section resources file section name
1500 \param name setting name
1501 \param def default value which is returned if the setting is not found
1502 \param subst \c true to make substitution, \c false to get "raw" value
1503 \return setting value
1506 class TGetStrSettingEvent: public SALOME_Event
1509 typedef QString TResult;
1515 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1516 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1517 virtual void Execute()
1519 if ( SUIT_Session::session() ) {
1520 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1521 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1525 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1527 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1531 \fn QColor SalomePyQt::colorSetting( const QString& section,
1532 const QString& name,
1534 \brief Get color setting from the application preferences.
1535 \param section resources file section name
1536 \param name setting name
1537 \param def default value which is returned if the setting is not found
1538 \return setting value
1541 class TGetColorSettingEvent: public SALOME_Event
1544 typedef QColor TResult;
1549 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1550 : mySection( section ), myName( name ), myDefault( def ) {}
1551 virtual void Execute()
1553 if ( SUIT_Session::session() ) {
1554 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1555 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1559 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1561 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1565 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1566 const QString& name,
1567 const QByteArray& def );
1568 \brief Get byte array setting from the application preferences.
1569 \param section resources file section name
1570 \param name setting name
1571 \param def default value which is returned if the setting is not found
1572 \return setting value
1575 class TGetByteArraySettingEvent: public SALOME_Event
1578 typedef QByteArray TResult;
1583 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1584 : mySection( section ), myName( name ), myDefault( def ) {}
1585 virtual void Execute()
1587 if ( SUIT_Session::session() ) {
1588 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1589 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1593 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1595 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1599 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1600 const QString& name,
1602 \brief Get font setting from the application preferences.
1603 \param section resources file section name
1604 \param name setting name
1605 \param def default value which is returned if the setting is not found
1606 \return setting value
1609 class TGetFontSettingEvent: public SALOME_Event
1612 typedef QFont TResult;
1617 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1618 : mySection( section ), myName( name ), myDefault( def ) {}
1619 virtual void Execute()
1621 if ( SUIT_Session::session() ) {
1622 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1623 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1627 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1629 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1633 \brief Remove setting from the application preferences.
1634 \param section resources file section name
1635 \param name setting name
1637 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1639 class TEvent: public SALOME_Event
1644 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1645 virtual void Execute()
1647 if ( SUIT_Session::session() ) {
1648 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1649 if ( !mySection.isEmpty() && !myName.isEmpty() )
1650 resMgr->remove( mySection, myName );
1654 ProcessVoidEvent( new TEvent( section, name ) );
1658 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1659 \brief Check setting existence in the application preferences.
1660 \param section resources file section name
1661 \param name setting name
1662 \return \c true if setting exists
1665 class THasSettingEvent: public SALOME_Event
1668 typedef bool TResult;
1672 THasSettingEvent( const QString& section, const QString& name )
1673 : mySection( section ), myName( name ) {}
1674 virtual void Execute()
1676 if ( SUIT_Session::session() ) {
1677 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1678 myResult = resMgr->hasValue( mySection, myName );
1682 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1684 return ProcessEvent( new THasSettingEvent( section, name ) );
1688 \fn QStringList SalomePyQt::parameters( const QString& section );
1689 \brief Get names of preference items stored within the given section.
1690 \param section resources file section's name
1691 \return \c list of preferences items
1695 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1696 \brief Get names of preference items stored within the given section.
1697 \param section resources file section's name
1698 \return \c list of preferences items
1701 class TParametersEvent: public SALOME_Event
1704 typedef QStringList TResult;
1706 QStringList mySection;
1707 TParametersEvent( const QString& section )
1709 mySection << section;
1711 TParametersEvent( const QStringList& section )
1712 : mySection( section )
1714 virtual void Execute()
1716 if ( SUIT_Session::session() ) {
1717 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1718 myResult = resMgr->parameters( mySection );
1722 QStringList SalomePyQt::parameters( const QString& section )
1724 return ProcessEvent( new TParametersEvent( section ) );
1726 QStringList SalomePyQt::parameters( const QStringList& section )
1728 return ProcessEvent( new TParametersEvent( section ) );
1732 \fn QString SalomePyQt::getFileName( QWidget* parent,
1733 const QString& initial,
1734 const QStringList& filters,
1735 const QString& caption,
1737 \brief Show 'Open/Save file' dialog box for file selection
1738 and return a user's choice (selected file name).
1739 \param parent parent widget
1740 \param initial initial directory the dialog box to be opened in
1741 \param filters list of files filters (wildcards)
1742 \param caption dialog box title
1743 \param open if \c true, "Open File" dialog box is shown;
1744 otherwise "Save File" dialog box is shown
1745 \return selected file name (null string if user cancels operation)
1748 class TGetFileNameEvent: public SALOME_Event
1751 typedef QString TResult;
1755 QStringList myFilters;
1758 TGetFileNameEvent( QWidget* parent,
1759 const QString& initial,
1760 const QStringList& filters,
1761 const QString& caption,
1763 : myParent ( parent ),
1764 myInitial( initial ),
1765 myFilters( filters ),
1766 myCaption( caption ),
1768 virtual void Execute()
1770 if ( LightApp_Application* anApp = getApplication() ) {
1771 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1772 myCaption, myParent );
1776 QString SalomePyQt::getFileName( QWidget* parent,
1777 const QString& initial,
1778 const QStringList& filters,
1779 const QString& caption,
1782 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1786 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1787 const QString& initial,
1788 const QStringList& filters,
1789 const QString& caption );
1790 \brief Show 'Open files' dialog box for multiple files selection
1791 and return a user's choice (selected file names list).
1792 \param parent parent widget
1793 \param initial initial directory the dialog box to be opened in
1794 \param filters list of files filters (wildcards)
1795 \param caption dialog box title
1796 \return selected file names list (empty list if user cancels operation)
1799 class TGetOpenFileNamesEvent: public SALOME_Event
1802 typedef QStringList TResult;
1806 QStringList myFilters;
1808 TGetOpenFileNamesEvent( QWidget* parent,
1809 const QString& initial,
1810 const QStringList& filters,
1811 const QString& caption )
1812 : myParent ( parent ),
1813 myInitial( initial ),
1814 myFilters( filters ),
1815 myCaption( caption ) {}
1816 virtual void Execute()
1818 if ( LightApp_Application* anApp = getApplication() ) {
1819 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1823 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1824 const QString& initial,
1825 const QStringList& filters,
1826 const QString& caption )
1828 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1832 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1833 const QString& initial,
1834 const QString& caption );
1835 \brief Show 'Get Directory' dialog box for the directory selection
1836 and return a user's choice (selected directory name).
1837 \param parent parent widget
1838 \param initial initial directory the dialog box to be opened in
1839 \param caption dialog box title
1840 \return selected directory name (null string if user cancels operation)
1843 class TGetExistingDirectoryEvent: public SALOME_Event
1846 typedef QString TResult;
1851 TGetExistingDirectoryEvent( QWidget* parent,
1852 const QString& initial,
1853 const QString& caption )
1854 : myParent ( parent ),
1855 myInitial( initial ),
1856 myCaption( caption ) {}
1857 virtual void Execute()
1859 if ( LightApp_Application* anApp = getApplication() ) {
1860 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1864 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1865 const QString& initial,
1866 const QString& caption )
1868 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1872 \fn QString SalomePyQt::loadIcon( const QString& filename );
1873 \brief Load an icon from the module resources by the specified file name.
1874 \param fileName icon file name
1878 class TLoadIconEvent: public SALOME_Event
1881 typedef QIcon TResult;
1885 TLoadIconEvent( const QString& module, const QString& filename )
1886 : myModule( module ),
1887 myFileName ( filename ) {}
1888 virtual void Execute()
1890 myResult = loadIconInternal( myModule, myFileName );
1893 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1895 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1899 \brief Open external browser to display context help information.
1902 Current implementation does nothing.
1904 \param source documentation (HTML) file name
1905 \param context context (for example, HTML ancor name)
1907 void SalomePyQt::helpContext( const QString& source, const QString& context )
1909 class TEvent: public SALOME_Event
1914 TEvent( const QString& source, const QString& context )
1915 : mySource( source ), myContext( context ) {}
1916 virtual void Execute()
1918 if ( LightApp_Application* anApp = getApplication() ) {
1919 anApp->onHelpContextModule( "", mySource, myContext );
1923 ProcessVoidEvent( new TEvent( source, context ) );
1927 \fn int SalomePyQt::defaultMenuGroup();
1928 \brief Get detault menu group identifier which can be used when
1929 creating menus (insert custom menu commands).
1930 \return default menu group ID
1933 class TDefMenuGroupEvent: public SALOME_Event
1936 typedef int TResult;
1938 TDefMenuGroupEvent() : myResult( -1 ) {}
1939 virtual void Execute()
1941 myResult = PyModuleHelper::defaultMenuGroup();
1944 int SalomePyQt::defaultMenuGroup()
1946 return ProcessEvent( new TDefMenuGroupEvent() );
1952 CrTool( const QString& tBar, const QString& nBar )
1953 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1954 CrTool( const int id, const int tBar, const int idx )
1955 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1956 CrTool( const int id, const QString& tBar, const int idx )
1957 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1958 CrTool( QAction* action, const int tbId, const int id, const int idx )
1959 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1960 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1961 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1963 int execute( LightApp_Module* module ) const
1968 return module->createTool( myTbTitle, myTbName );
1970 return module->createTool( myId, myTbId, myIndex );
1972 return module->createTool( myId, myTbTitle, myIndex );
1974 return module->createTool( myAction, myTbId, myId, myIndex );
1976 return module->createTool( myAction, myTbTitle, myId, myIndex );
1991 class TCreateToolEvent: public SALOME_Event
1994 typedef int TResult;
1996 const CrTool& myCrTool;
1997 TCreateToolEvent( const CrTool& crTool )
1998 : myResult( -1 ), myCrTool( crTool ) {}
1999 virtual void Execute()
2001 LightApp_Module* module = getActiveModule();
2003 myResult = myCrTool.execute( module );
2008 \brief Create toolbar with specified name.
2009 \param tBar toolbar title (language-dependent)
2010 \param nBar toolbar name (language-independent) [optional]
2011 \return toolbar ID or -1 if toolbar creation is failed
2013 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2015 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2019 \brief Insert action with specified \a id to the toolbar.
2021 \param tBar toolbar ID
2022 \param idx required index in the toolbar
2023 \return action ID or -1 if action could not be added
2025 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2027 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2031 \brief Insert action with specified \a id to the toolbar.
2033 \param tBar toolbar name
2034 \param idx required index in the toolbar
2035 \return action ID or -1 if action could not be added
2037 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2039 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2043 \brief Insert action to the toolbar.
2045 \param tBar toolbar ID
2046 \param id required action ID
2047 \param idx required index in the toolbar
2048 \return action ID or -1 if action could not be added
2050 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2052 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2056 \brief Insert action to the toolbar.
2058 \param tBar toolbar name
2059 \param id required action ID
2060 \param idx required index in the toolbar
2061 \return action ID or -1 if action could not be added
2063 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2065 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2071 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2072 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2073 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2074 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2075 CrMenu( const int id, const int menu, const int group, const int idx )
2076 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2077 CrMenu( const int id, const QString& menu, const int group, const int idx )
2078 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2079 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2080 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2081 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2082 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2084 int execute( LightApp_Module* module ) const
2089 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2091 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2093 return module->createMenu( myId, myMenuId, myGroup, myIndex );
2095 return module->createMenu( myId, myMenuName, myGroup, myIndex );
2097 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2099 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2108 QString mySubMenuName;
2115 class TCreateMenuEvent: public SALOME_Event
2118 typedef int TResult;
2120 const CrMenu& myCrMenu;
2121 TCreateMenuEvent( const CrMenu& crMenu )
2122 : myResult( -1 ), myCrMenu( crMenu ) {}
2123 virtual void Execute()
2125 LightApp_Module* module = getActiveModule();
2127 myResult = myCrMenu.execute( module );
2132 \brief Create main menu.
2133 \param subMenu menu name
2134 \param menu parent menu ID
2135 \param id required menu ID
2136 \param group menu group ID
2137 \param idx required index in the menu
2138 \return menu ID or -1 if menu could not be added
2140 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2142 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2146 \brief Create main menu.
2147 \param subMenu menu name
2148 \param menu parent menu name (list of menu names separated by "|")
2149 \param id required menu ID
2150 \param group menu group ID
2151 \param idx required index in the menu
2152 \return menu ID or -1 if menu could not be added
2154 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2156 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2160 \brief Insert action to the main menu.
2162 \param menu parent menu ID
2163 \param group menu group ID
2164 \param idx required index in the menu
2165 \return action ID or -1 if action could not be added
2167 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2169 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2173 \brief Insert action to the main menu.
2175 \param menu parent menu name (list of menu names separated by "|")
2176 \param group menu group ID
2177 \param idx required index in the menu
2178 \return action ID or -1 if action could not be added
2180 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2182 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2186 \brief Insert action to the main menu.
2188 \param menu parent menu ID
2189 \param group menu group ID
2190 \param idx required index in the menu
2191 \return action ID or -1 if action could not be added
2193 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2195 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2199 \brief Insert action to the main menu.
2201 \param menu parent menu name (list of menu names separated by "|")
2202 \param group menu group ID
2203 \param idx required index in the menu
2204 \return action ID or -1 if action could not be added
2206 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2208 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2212 \fn QAction* SalomePyQt::createSeparator();
2213 \brief Create separator action which can be used in the menu or toolbar.
2214 \return new separator action
2217 class TCreateSepEvent: public SALOME_Event
2220 typedef QAction* TResult;
2224 virtual void Execute()
2226 LightApp_Module* module = getActiveModule();
2228 myResult = (QAction*)module->separator();
2231 QAction* SalomePyQt::createSeparator()
2233 return ProcessEvent( new TCreateSepEvent() );
2237 \fn QAction* SalomePyQt::createAction( const int id,
2238 const QString& menuText,
2239 const QString& tipText,
2240 const QString& statusText,
2241 const QString& icon,
2243 const bool toggle );
2244 \brief Create an action which can be then used in the menu or toolbar.
2245 \param id the unique id action to be registered to
2246 \param menuText action text which should appear in menu
2247 \param tipText text which should appear in the tooltip
2248 \param statusText text which should appear in the status bar when action is activated
2249 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2250 \param key the key accelrator for the action
2251 \param toggle if \c true the action is checkable
2254 class TCreateActionEvent: public SALOME_Event
2257 typedef QAction* TResult;
2262 QString myStatusText;
2266 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2267 const QString& statusText, const QString& icon, const int key, const bool toggle )
2268 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2269 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2270 virtual void Execute()
2272 LightApp_Module* module = getActiveModule();
2274 QIcon icon = loadIconInternal( module->name(), myIcon );
2275 myResult = (QAction*)module->action( myId );
2277 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2278 myResult->setToolTip( myTipText );
2279 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2280 myResult->setText( myMenuText );
2281 if ( myResult->icon().isNull() && !icon.isNull() )
2282 myResult->setIcon( icon );
2283 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2284 myResult->setStatusTip( myStatusText );
2285 if ( myResult->shortcut().isEmpty() && myKey )
2286 myResult->setShortcut( myKey );
2287 if ( myResult->isCheckable() != myToggle )
2288 myResult->setCheckable( myToggle );
2291 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2293 // for Python module, automatically connect action to callback slot
2294 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2295 if ( helper ) helper->connectAction( myResult );
2299 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2300 const QString& tipText, const QString& statusText,
2301 const QString& icon, const int key, const bool toggle )
2303 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2307 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2308 \brief Create an action group which can be then used in the menu or toolbar
2309 \param id : the unique id action group to be registered to
2310 \param exclusive : if \c true the action group does exclusive toggling
2313 struct TCreateActionGroupEvent: public SALOME_Event
2315 typedef QtxActionGroup* TResult;
2319 TCreateActionGroupEvent( const int id, const bool exclusive )
2320 : myId( id ), myExclusive( exclusive ) {}
2321 virtual void Execute()
2323 LightApp_Module* module = getActiveModule();
2325 myResult = module->createActionGroup( myId, myExclusive );
2328 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2330 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2334 \fn QAction* SalomePyQt::action( const int id );
2335 \brief Get action by specified identifier.
2336 \return action or 0 if action is not registered
2339 class TActionEvent: public SALOME_Event
2342 typedef QAction* TResult;
2345 TActionEvent( const int id )
2346 : myResult( 0 ), myId( id ) {}
2347 virtual void Execute()
2349 LightApp_Module* module = getActiveModule();
2351 myResult = (QAction*)module->action( myId );
2354 QAction* SalomePyQt::action( const int id )
2356 return ProcessEvent( new TActionEvent( id ) );
2360 \fn int SalomePyQt::actionId( const QAction* a );
2361 \brief Get an action identifier.
2362 \return action ID or -1 if action is not registered
2365 class TActionIdEvent: public SALOME_Event
2368 typedef int TResult;
2370 const QAction* myAction;
2371 TActionIdEvent( const QAction* action )
2372 : myResult( -1 ), myAction( action ) {}
2373 virtual void Execute()
2375 LightApp_Module* module = getActiveModule();
2377 myResult = module->actionId( myAction );
2380 int SalomePyQt::actionId( const QAction* a )
2382 return ProcessEvent( new TActionIdEvent( a ) );
2386 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2387 \brief Add global (not module-related) preferences group.
2388 \param label global preferences group name
2389 \return preferences group identifier
2392 class TAddGlobalPrefEvent: public SALOME_Event
2395 typedef int TResult;
2398 TAddGlobalPrefEvent( const QString& label )
2399 : myResult( -1 ), myLabel( label ) {}
2400 virtual void Execute()
2402 LightApp_Module* module = getActiveModule();
2404 LightApp_Preferences* pref = module->getApp()->preferences();
2406 myResult = pref->addPreference( myLabel, -1 );
2410 int SalomePyQt::addGlobalPreference( const QString& label )
2412 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2416 \fn int SalomePyQt::addPreference( const QString& label );
2417 \brief Add module-related preferences group.
2418 \param label preferences group name
2419 \return preferences group identifier
2422 class TAddPrefEvent: public SALOME_Event
2425 typedef int TResult;
2428 TAddPrefEvent( const QString& label )
2429 : myResult( -1 ), myLabel( label ) {}
2430 virtual void Execute()
2432 LightApp_Module* module = getActiveModule();
2434 LightApp_Preferences* pref = module->getApp()->preferences();
2436 int cId = pref->addPreference( module->moduleName(), -1 );
2438 myResult = pref->addPreference( myLabel, cId );
2443 int SalomePyQt::addPreference( const QString& label )
2445 return ProcessEvent( new TAddPrefEvent( label ) );
2449 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2450 const QString& section, const QString& param );
2451 \brief Add module-related preferences.
2452 \param label preferences group name
2453 \param pId parent preferences group id
2454 \param type preferences type
2455 \param section resources file section name
2456 \param param resources file setting name
2457 \return preferences identifier
2460 class TAddPrefParamEvent: public SALOME_Event
2463 typedef int TResult;
2470 TAddPrefParamEvent( const QString& label,
2471 const int pId, const int type,
2472 const QString& section,
2473 const QString& param )
2475 myLabel( label ), myPId( pId ), myType( type ),
2476 mySection( section ), myParam ( param ) {}
2477 virtual void Execute()
2479 LightApp_Module* module = getActiveModule();
2481 LightApp_Preferences* pref = module->getApp()->preferences();
2483 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2487 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2488 const QString& section, const QString& param )
2490 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2494 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2495 \brief Get the preferences property.
2496 \param id preferences identifier
2497 \param prop preferences property name
2498 \return preferences property value or null QVariant if property is not set
2501 class TPrefPropEvent: public SALOME_Event
2504 typedef QVariant TResult;
2508 TPrefPropEvent( const int id, const QString& prop )
2509 : myId( id ), myProp( prop ) {}
2510 virtual void Execute()
2512 LightApp_Module* module = getActiveModule();
2514 LightApp_Preferences* pref = module->getApp()->preferences();
2516 myResult = pref->itemProperty( myProp, myId );
2520 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2522 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2526 \brief Set the preferences property.
2527 \param id preferences identifier
2528 \param prop preferences property name
2529 \param var preferences property value
2531 void SalomePyQt::setPreferenceProperty( const int id,
2532 const QString& prop,
2533 const QVariant& var )
2535 class TEvent: public SALOME_Event
2541 TEvent( const int id, const QString& prop, const QVariant& var )
2542 : myId( id ), myProp( prop ), myVar( var ) {}
2543 virtual void Execute()
2545 LightApp_Module* module = getActiveModule();
2547 LightApp_Preferences* pref = module->getApp()->preferences();
2549 pref->setItemProperty( myProp, myVar, myId );
2553 ProcessVoidEvent( new TEvent( id, prop, var ) );
2557 \brief Set specific widget as a custom preferences item.
2558 \param id preferences identifier
2559 \param prop preferences property name
2560 \param widget custom widget
2562 void SalomePyQt::setPreferencePropertyWg( const int id,
2563 const QString& prop,
2564 UserDefinedContent* widget )
2566 class TEvent: public SALOME_Event
2570 UserDefinedContent* myWidget;
2572 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2573 : myId( id ), myProp( prop ), myWidget( widget ) {}
2574 virtual void Execute()
2576 LightApp_Module* module = getActiveModule();
2578 LightApp_Preferences* pref = module->getApp()->preferences();
2580 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2585 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2589 \brief Add the property value to the list of values.
2591 This method allows creating properties which are QList<QVariant>
2592 - there is no way to pass such values directly to QVariant parameter with PyQt.
2594 \param id preferences identifier
2595 \param prop preferences property name
2596 \param idx preferences property index
2597 \param var preferences property value for the index \a idx
2599 void SalomePyQt::addPreferenceProperty( const int id,
2600 const QString& prop,
2602 const QVariant& var )
2604 class TEvent: public SALOME_Event
2611 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2612 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2613 virtual void Execute()
2615 LightApp_Module* module = getActiveModule();
2617 LightApp_Preferences* pref = module->getApp()->preferences();
2619 QVariant var = pref->itemProperty( myProp, myId );
2620 if ( var.isValid() ) {
2621 if ( var.type() == QVariant::StringList ) {
2622 QStringList sl = var.toStringList();
2623 if ( myIdx >= 0 && myIdx < sl.count() )
2624 sl[myIdx] = myVar.toString();
2626 sl.append( myVar.toString() );
2627 pref->setItemProperty( myProp, sl, myId );
2629 else if ( var.type() == QVariant::List ) {
2630 QList<QVariant> vl = var.toList();
2631 if ( myIdx >= 0 && myIdx < vl.count() )
2635 pref->setItemProperty( myProp, vl, myId );
2641 pref->setItemProperty( myProp, vl, myId );
2647 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2651 \brief Put the message to the Log messages output window
2652 \param msg message text (it can be of simple rich text format)
2653 \param addSeparator boolean flag which specifies if it is necessary
2654 to separate the message with predefined separator
2656 void SalomePyQt::message( const QString& msg, bool addSeparator )
2658 class TEvent: public SALOME_Event
2663 TEvent( const QString& msg, bool addSeparator )
2664 : myMsg( msg ), myAddSep( addSeparator ) {}
2665 virtual void Execute()
2667 if ( LightApp_Application* anApp = getApplication() ) {
2668 LogWindow* lw = anApp->logWindow();
2670 lw->putMessage( myMsg, myAddSep );
2674 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2678 \brief Remove all the messages from the Log messages output window.
2680 void SalomePyQt::clearMessages()
2682 class TEvent: public SALOME_Event
2686 virtual void Execute()
2688 if ( LightApp_Application* anApp = getApplication() ) {
2689 LogWindow* lw = anApp->logWindow();
2695 ProcessVoidEvent( new TEvent() );
2699 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2700 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2701 to the image file in the specified format.
2703 For the current moment JPEG, PNG and BMP images formats are supported.
2704 The image format is defined automatically by the file name extension.
2705 By default, BMP format is used.
2707 \param filename image file name
2708 \return operation status (\c true on success)
2711 class TDumpViewEvent: public SALOME_Event
2714 typedef bool TResult;
2718 TDumpViewEvent( const QString& filename, const int id )
2719 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2720 virtual void Execute()
2722 SUIT_ViewWindow* wnd = 0;
2724 if ( LightApp_Application* anApp = getApplication() ) {
2725 SUIT_ViewManager* vm = anApp->activeViewManager();
2727 wnd = vm->getActiveView();
2729 myWndId = wnd->getId();
2732 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2735 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2736 #ifndef DISABLE_PLOT2DVIEWER
2737 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2739 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2740 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2741 qApp->processEvents();
2742 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2743 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2747 #endif // DISABLE_PLOT2DVIEWER
2748 QImage im = wnd->dumpView();
2749 if ( !im.isNull() && !myFileName.isEmpty() ) {
2750 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2751 if ( fmt == "JPG" ) fmt = "JPEG";
2752 myResult = im.save( myFileName, fmt.toLatin1() );
2757 bool SalomePyQt::dumpView( const QString& filename, const int id )
2759 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2763 \fn QList<int> SalomePyQt::getViews();
2764 \brief Get list of integer identifiers of all the currently opened views
2765 \return list of integer identifiers of all the currently opened views
2768 class TGetViews: public SALOME_Event
2771 typedef QList<int> TResult;
2774 virtual void Execute()
2777 LightApp_Application* app = getApplication();
2779 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2781 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2782 SUIT_ViewWindow* wnd;
2783 foreach ( wnd, wndlist )
2784 myResult.append( wnd->getId() );
2789 QList<int> SalomePyQt::getViews()
2791 return ProcessEvent( new TGetViews() );
2795 \fn int SalomePyQt::getActiveView();
2796 \brief Get integer identifier of the currently active view
2797 \return integer identifier of the currently active view
2800 class TGetActiveView: public SALOME_Event
2803 typedef int TResult;
2807 virtual void Execute()
2809 LightApp_Application* app = getApplication();
2811 SUIT_ViewManager* viewMgr = app->activeViewManager();
2813 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2815 myResult = wnd->getId();
2820 int SalomePyQt::getActiveView()
2822 return ProcessEvent( new TGetActiveView() );
2826 \fn QString SalomePyQt::getViewType( const int id );
2827 \brief Get type of the specified view, e.g. "OCCViewer"
2828 \param id window identifier
2832 class TGetViewType: public SALOME_Event
2835 typedef QString TResult;
2838 TGetViewType( const int id )
2840 virtual void Execute()
2842 SUIT_ViewWindow* wnd = getWnd( myWndId );
2844 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2846 myResult = viewMgr->getType();
2850 QString SalomePyQt::getViewType( const int id )
2852 return ProcessEvent( new TGetViewType( id ) );
2856 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2857 \brief Change view caption
2858 \param id window identifier
2859 \param title new window title
2860 \return \c true if operation is completed successfully and \c false otherwise
2863 class TSetViewTitle: public SALOME_Event
2866 typedef bool TResult;
2870 TSetViewTitle( const int id, const QString& title )
2871 : myResult( false ),
2874 virtual void Execute()
2876 SUIT_ViewWindow* wnd = getWnd( myWndId );
2878 wnd->setWindowTitle( myTitle );
2883 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2885 return ProcessEvent( new TSetViewTitle( id, title ) );
2889 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2890 \brief Set view size
2891 \param w window width
2892 \param h window height
2893 \param id window identifier
2894 \return \c true if operation is completed successfully and \c false otherwise
2897 class TSetViewSize: public SALOME_Event
2900 typedef bool TResult;
2905 TSetViewSize( const int w, const int h, const int id )
2906 : myResult( false ),
2910 virtual void Execute()
2912 SUIT_ViewWindow* wnd = 0;
2914 if ( LightApp_Application* anApp = getApplication() ) {
2915 SUIT_ViewManager* vm = anApp->activeViewManager();
2917 wnd = vm->getActiveView();
2921 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2924 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2926 QString type = viewMgr->getType();
2927 if ( type == "OCCViewer") {
2928 #ifndef DISABLE_OCCVIEWER
2929 // specific processing for OCC viewer:
2930 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2931 // - if there is only one sub-view active; it will be resized;
2932 // - if there are several sub-views, each of them will be resized.
2933 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2934 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2935 if ( occView && occView->getView( i ) ) {
2936 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2940 #endif // DISABLE_OCCVIEWER
2942 else if ( type == "ParaView") {
2943 #ifndef DISABLE_PVVIEWER
2944 // specific processing for ParaView viewer:
2945 // hierarchy of ParaView viewer is much complex than for usual view;
2946 // we look for sub-widget named "Viewport"
2947 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2948 if ( !lst.isEmpty() ) {
2949 lst[0]->resize( myWndWidth, myWndHeight );
2952 #endif // DISABLE_PVVIEWER
2955 if ( wnd->centralWidget() ) {
2956 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2964 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2966 return ProcessEvent( new TSetViewSize( w, h, id ) );
2970 \fn QString SalomePyQt::getViewTitle( const int id );
2971 \brief Get view caption
2972 \param id window identifier
2973 \return view caption
2976 class TGetViewTitle: public SALOME_Event
2979 typedef QString TResult;
2982 TGetViewTitle( const int id )
2984 virtual void Execute()
2986 SUIT_ViewWindow* wnd = getWnd( myWndId );
2988 myResult = wnd->windowTitle();
2991 QString SalomePyQt::getViewTitle( const int id )
2993 return ProcessEvent( new TGetViewTitle( id ) );
2997 \fn QList<int> SalomePyQt::findViews( const QString& type );
2998 \brief Get list of integer identifiers of all the
2999 currently opened views of the specified type
3000 \param type viewer type
3001 \return list of integer identifiers
3004 class TFindViews: public SALOME_Event
3007 typedef QList<int> TResult;
3010 TFindViews( const QString& type )
3012 virtual void Execute()
3015 LightApp_Application* app = getApplication();
3017 ViewManagerList vmList;
3018 app->viewManagers( myType, vmList );
3019 SUIT_ViewManager* viewMgr;
3020 foreach ( viewMgr, vmList ) {
3021 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3022 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3023 SUIT_ViewWindow* wnd = vec[ i ];
3026 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3027 myResult.append( wnd->getId() );
3034 QList<int> SalomePyQt::findViews( const QString& type )
3036 return ProcessEvent( new TFindViews( type ) );
3040 \fn bool SalomePyQt::activateView( const int id );
3041 \brief Activate view
3042 \param id window identifier
3043 \return \c true if operation is completed successfully and \c false otherwise
3046 class TActivateView: public SALOME_Event
3049 typedef bool TResult;
3052 TActivateView( const int id )
3053 : myResult( false ),
3055 virtual void Execute()
3057 SUIT_ViewWindow* wnd = getWnd( myWndId );
3058 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3065 bool SalomePyQt::activateView( const int id )
3067 return ProcessEvent( new TActivateView( id ) );
3071 \fn bool SalomePyQt::activateManagerAndView( const int id );
3072 \brief Activate view manager and view: useful for a view embedded in a module main Window
3073 \param id window identifier
3074 \return \c true if operation is completed successfully and \c false otherwise
3077 class TActivateViewManagerAndView: public SALOME_Event
3080 typedef bool TResult;
3083 TActivateViewManagerAndView( const int id )
3084 : myResult( false ),
3086 virtual void Execute()
3088 SUIT_ViewWindow* wnd = getWnd( myWndId );
3089 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3092 LightApp_Application* app = getApplication();
3093 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3099 bool SalomePyQt::activateViewManagerAndView( const int id )
3101 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3108 class TGetViewWidget: public SALOME_Event
3111 typedef QWidget* TResult;
3114 TGetViewWidget( const int id )
3117 virtual void Execute()
3119 SUIT_ViewWindow* wnd = getWnd( myWndId );
3121 myResult = (QWidget*)wnd;
3125 QWidget* SalomePyQt::getViewWidget( const int id)
3127 return ProcessEvent( new TGetViewWidget( id ) );
3132 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3133 \brief Create new view and activate it
3134 \param type viewer type
3138 \return integer identifier of created view (or -1 if view could not be created)
3141 class TCreateView: public SALOME_Event
3144 typedef int TResult;
3151 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3157 myDetached(detached) {}
3158 virtual void Execute()
3160 LightApp_Application* app = getApplication();
3162 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3164 QWidget* wnd = viewMgr->getActiveView();
3165 myResult = viewMgr->getActiveView()->getId();
3168 wnd->setVisible(false);
3169 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3173 if (myWidth > 0 && myHeight > 0) {
3174 #ifndef DISABLE_PLOT2DVIEWER
3175 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3176 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3177 #endif // DISABLE_PLOT2DVIEWER
3178 wnd->setGeometry( 0, 0, myWidth, myHeight );
3185 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3187 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3188 QCoreApplication::processEvents();
3193 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3194 \brief Create new view with custom widget embedded and activate it
3195 \param type viewer type
3196 \param w custom widget
3197 \return integer identifier of created view (or -1 if view could not be created)
3200 class TCreateViewWg: public SALOME_Event
3203 typedef int TResult;
3207 TCreateViewWg( const QString& theType, QWidget* w )
3211 virtual void Execute()
3213 LightApp_Application* app = getApplication();
3215 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3217 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3219 myResult = wnd->getId();
3224 int SalomePyQt::createView( const QString& type, QWidget* w )
3226 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3227 QCoreApplication::processEvents();
3232 \fn bool SalomePyQt::closeView( const int id );
3234 \param id window identifier
3235 \return \c true if operation is completed successfully and \c false otherwise
3238 class TCloseView: public SALOME_Event
3241 typedef bool TResult;
3244 TCloseView( const int id )
3245 : myResult( false ),
3247 virtual void Execute()
3249 SUIT_ViewWindow* wnd = getWnd( myWndId );
3251 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3259 bool SalomePyQt::closeView( const int id )
3261 return ProcessEvent( new TCloseView( id ) );
3265 \fn int SalomePyQt::cloneView( const int id );
3266 \brief Clone view (if this operation is supported for specified view type)
3267 \param id window identifier
3268 \return integer identifier of the cloned view or -1 or operation could not be performed
3271 class TCloneView: public SALOME_Event
3274 typedef int TResult;
3277 TCloneView( const int id )
3280 virtual void Execute()
3282 SUIT_ViewWindow* wnd = getWnd( myWndId );
3284 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3286 #ifndef DISABLE_OCCVIEWER
3287 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3288 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3289 occView->onCloneView();
3290 wnd = viewMgr->getActiveView();
3292 myResult = wnd->getId();
3294 #endif // DISABLE_OCCVIEWER
3295 #ifndef DISABLE_PLOT2DVIEWER
3296 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3297 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3298 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3299 if ( viewMgr2d && srcWnd2d ) {
3300 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3301 myResult = resWnd->getId();
3304 #endif // DISABLE_OCCVIEWER
3309 int SalomePyQt::cloneView( const int id )
3311 return ProcessEvent( new TCloneView( id ) );
3315 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3316 \brief Set view visibility.
3317 \param id window identifier
3318 \param visible new visiblity
3321 void SalomePyQt::setViewVisible( const int id, const bool visible )
3323 class TEvent: public SALOME_Event
3328 TEvent( const int id, const bool visible )
3329 : myWndId( id ), myVisible( visible ) {}
3330 virtual void Execute()
3332 SUIT_ViewWindow* wnd = getWnd( myWndId );
3333 if ( wnd ) wnd->setVisible( myVisible );
3336 ProcessVoidEvent( new TEvent( id, visible ) );
3340 \fn bool SalomePyQt::isViewVisible( const int id );
3341 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3342 \param id window identifier
3343 \return \c true if view is visible and \c false otherwise
3346 class TIsViewVisible: public SALOME_Event
3349 typedef bool TResult;
3352 TIsViewVisible( const int id )
3353 : myResult( false ),
3355 virtual void Execute()
3357 SUIT_ViewWindow* wnd = getWnd( myWndId );
3360 QWidget* p = wnd->parentWidget();
3361 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3365 bool SalomePyQt::isViewVisible( const int id )
3367 return ProcessEvent( new TIsViewVisible( id ) );
3371 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3372 \brief Set / clear view's "closable" option. By default any view is closable
3373 (i.e. can be closed by the user).
3374 \param id window identifier
3375 \param on new "closable" option's value
3378 void SalomePyQt::setViewClosable( const int id, const bool on )
3380 class TEvent: public SALOME_Event
3385 TEvent( const int id, const bool on )
3386 : myWndId( id ), myOn( on ) {}
3387 virtual void Execute()
3389 SUIT_ViewWindow* wnd = getWnd( myWndId );
3390 if ( wnd ) wnd->setClosable( myOn );
3393 ProcessVoidEvent( new TEvent( id, on ) );
3397 \fn bool SalomePyQt::isViewClosable( const int id );
3398 \brief Check whether view is closable (i.e. can be closed by the user)
3399 \param id window identifier
3400 \return \c true if view is closable or \c false otherwise
3403 class TIsViewClosable: public SALOME_Event
3406 typedef bool TResult;
3409 TIsViewClosable( const int id )
3412 virtual void Execute()
3414 SUIT_ViewWindow* wnd = getWnd( myWndId );
3416 myResult = wnd->closable();
3420 bool SalomePyQt::isViewClosable( const int id )
3422 return ProcessEvent( new TIsViewClosable( id ) );
3426 \fn bool SalomePyQt::groupAllViews();
3427 \brief Group all views to the single tab area
3428 \return \c true if operation is completed successfully and \c false otherwise
3431 class TGroupAllViews: public SALOME_Event
3434 typedef bool TResult;
3437 : myResult( false ) {}
3438 virtual void Execute()
3440 LightApp_Application* app = getApplication();
3442 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3444 QtxWorkstack* wStack = tabDesk->workstack();
3453 bool SalomePyQt::groupAllViews()
3455 return ProcessEvent( new TGroupAllViews() );
3459 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3460 \brief Split tab area to which view with identifier belongs to
3461 \param id window identifier
3462 \param ori orientation of split operation
3463 \param action action to be performed
3464 \return \c true if operation is completed successfully \c false otherwise
3467 class TSplitView: public SALOME_Event
3470 typedef bool TResult;
3475 TSplitView( const int id,
3476 const Orientation ori,
3477 const Action action )
3478 : myResult( false ),
3481 myAction( action ) {}
3482 virtual void Execute()
3484 SUIT_ViewWindow* wnd = getWnd( myWndId );
3487 // wnd->setFocus(); ???
3490 if ( getApplication() ) {
3491 STD_TabDesktop* desk =
3492 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3494 QtxWorkstack* wStack = desk->workstack();
3496 Qt::Orientation qtOri =
3497 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3499 QtxWorkstack::SplitType sType;
3500 if ( myAction == MoveWidget )
3501 sType = QtxWorkstack::SplitMove;
3502 else if ( myAction == LeaveWidget )
3503 sType = QtxWorkstack::SplitStay;
3505 sType = QtxWorkstack::SplitAt;
3507 wStack->Split( wnd, qtOri, sType );
3515 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3517 return ProcessEvent( new TSplitView( id, ori, action ) );
3521 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3522 \brief Move view with the first identifier to the same area which
3523 another view with the second identifier belongs to
3524 \param id source window identifier
3525 \param id_to destination window identifier
3526 param before specifies whether the first viewt has to be moved before or after
3528 \return \c true if operation is completed successfully and \c false otherwise
3531 class TMoveView: public SALOME_Event
3534 typedef bool TResult;
3539 TMoveView( const int id, const int id_to, const bool before )
3540 : myResult( false ),
3543 myIsBefore( before ) {}
3544 virtual void Execute()
3546 SUIT_ViewWindow* wnd = getWnd( myWndId );
3547 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3548 if ( wnd && wnd_to ) {
3549 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3550 getApplication()->desktop() )->workstack();
3552 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3556 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3558 return ProcessEvent( new TMoveView( id, id_to, before ) );
3562 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3563 \brief Get list of views identifiers that belongs to the same area as
3564 specified view (excluding it)
3565 \param id window identifier
3566 \return list of views identifiers
3569 class TNeighbourViews: public SALOME_Event
3572 typedef QList<int> TResult;
3575 TNeighbourViews( const int id )
3577 virtual void Execute()
3580 SUIT_ViewWindow* wnd = getWnd( myWndId );
3582 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3583 getApplication()->desktop() )->workstack();
3585 QWidgetList wgList = wStack->windowList( wnd );
3587 foreach ( wg, wgList ) {
3588 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3589 if ( tmpWnd && tmpWnd != wnd )
3590 myResult.append( tmpWnd->getId() );
3596 QList<int> SalomePyQt::neighbourViews( const int id )
3598 return ProcessEvent( new TNeighbourViews( id ) );
3603 \fn void SalomePyQt::createRoot();
3604 \brief Initialize root data object.
3606 Does nothing if root is already initialized.
3609 void SalomePyQt::createRoot()
3611 class TEvent: public SALOME_Event
3615 virtual void Execute()
3617 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3619 SALOME_PYQT_DataModelLight* dm =
3620 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3625 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3629 ProcessVoidEvent( new TEvent() );
3633 \fn QString SalomePyQt::createObject( const QString& parent );
3634 \brief Create empty data object
3635 \param parent entry of parent data object
3636 \return entry of created data object
3639 class TCreateEmptyObjectEvent: public SALOME_Event
3642 typedef QString TResult;
3645 TCreateEmptyObjectEvent( const QString& parent )
3646 : myParent( parent ) {}
3647 virtual void Execute()
3649 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3651 myResult = module->createObject( myParent );
3654 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3658 QString SalomePyQt::createObject( const QString& parent )
3660 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3664 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3665 const QString& tooltip,const QString& parent );
3666 \brief Create new data object with specified name, icon and tooltip
3667 \param name data object name
3668 \param icon data object icon
3669 \param toolTip data object tooltip
3670 \param parent entry of parent data object
3671 \return entry of created data object
3674 class TCreateObjectEvent: public SALOME_Event
3677 typedef QString TResult;
3683 TCreateObjectEvent( const QString& name,
3684 const QString& icon,
3685 const QString& tooltip,
3686 const QString& parent )
3689 myToolTip( tooltip ),
3690 myParent( parent ) {}
3691 virtual void Execute()
3693 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3695 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3698 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3702 QString SalomePyQt::createObject( const QString& name,
3703 const QString& icon,
3704 const QString& toolTip,
3705 const QString& parent )
3707 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3712 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3713 \brief Set data object name
3714 \param entry data object entry
3715 \param name data object name
3717 class TSetNameEvent: public SALOME_Event
3722 TSetNameEvent( const QString& entry,
3723 const QString& name )
3726 virtual void Execute()
3728 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3730 module->setName( myEntry, myName );
3733 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3737 void SalomePyQt::setName( const QString& entry, const QString& name )
3739 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3743 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3744 \brief Set data object icon
3745 \param entry data object entry
3746 \param icon data object icon file name (icon is loaded from module resources)
3749 class TSetIconEvent: public SALOME_Event
3754 TSetIconEvent( const QString& entry,
3755 const QString& icon )
3758 virtual void Execute()
3760 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3762 module->setIcon( myEntry, myIcon );
3765 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3770 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3772 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3776 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3777 \brief Set data object tooltip
3778 \param entry data object entry
3779 \param toolTip data object tooltip
3782 class TSetToolTipEvent: public SALOME_Event
3787 TSetToolTipEvent( const QString& entry,
3788 const QString& toolTip )
3790 myToolTip( toolTip ) {}
3791 virtual void Execute()
3793 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3795 module->setToolTip( myEntry, myToolTip );
3798 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3802 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3804 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3808 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3809 \brief Set reference to another data object
3810 \param entry data object entry
3811 \param refEntry referenced data object entry
3814 class TSetRefEvent: public SALOME_Event
3819 TSetRefEvent( const QString& entry,
3820 const QString& refEntry )
3822 myRefEntry( refEntry ) {}
3823 virtual void Execute()
3825 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3827 module->setReference( myEntry, myRefEntry );
3830 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3834 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3836 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3840 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3841 \brief Set data object color
3842 \param entry data object entry
3843 \param color data object color
3846 class TSetColorEvent: public SALOME_Event
3851 TSetColorEvent( const QString& entry,
3852 const QColor& color )
3855 virtual void Execute()
3857 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3859 module->setColor( myEntry, myColor );
3862 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3866 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3868 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3872 \fn QString SalomePyQt::getName( const QString& entry );
3873 \brief Get data object name
3874 \param entry data object entry
3875 \return data object name
3878 class TGetNameEvent: public SALOME_Event
3881 typedef QString TResult;
3884 TGetNameEvent( const QString& entry )
3885 : myEntry( entry ) {}
3886 virtual void Execute()
3888 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3890 myResult = module->getName( myEntry );
3893 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3897 QString SalomePyQt::getName( const QString& entry )
3899 return ProcessEvent( new TGetNameEvent( entry ) );
3903 \fn QString SalomePyQt::getToolTip( const QString& entry );
3904 \brief Get data object tooltip
3905 \param entry data object entry
3906 \return data object tooltip
3909 class TGetToolTipEvent: public SALOME_Event
3912 typedef QString TResult;
3915 TGetToolTipEvent( const QString& entry )
3916 : myEntry( entry ) {}
3917 virtual void Execute()
3919 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3921 myResult = module->getToolTip( myEntry );
3924 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3928 QString SalomePyQt::getToolTip( const QString& entry )
3930 return ProcessEvent( new TGetToolTipEvent( entry ) );
3934 \fn QString SalomePyQt::getReference( const QString& entry );
3935 \brief Get entry of the referenced object (if there's any)
3936 \param entry data object entry
3937 \return referenced data object entry
3940 class TGetRefEvent: public SALOME_Event
3943 typedef QString TResult;
3946 TGetRefEvent( const QString& entry )
3947 : myEntry( entry ) {}
3948 virtual void Execute()
3950 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3952 myResult = module->getReference( myEntry );
3955 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3959 QString SalomePyQt::getReference( const QString& entry )
3961 return ProcessEvent( new TGetRefEvent( entry ) );
3965 \fn QColor SalomePyQt::getColor( const QString& entry );
3966 \brief Get data object color
3967 \param entry data object entry
3968 \return data object color
3971 class TGetColorEvent: public SALOME_Event
3974 typedef QColor TResult;
3977 TGetColorEvent( const QString& entry )
3978 : myEntry( entry ) {}
3979 virtual void Execute()
3981 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3983 myResult = module->getColor( myEntry );
3986 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3990 QColor SalomePyQt::getColor( const QString& entry )
3992 return ProcessEvent( new TGetColorEvent( entry ) );
3996 \fn void SalomePyQt::removeChildren( const QString& entry );
3997 \brief Remove all child data objects from specified data object
3998 \param entry data object entry
4001 class TRemoveChildEvent: public SALOME_Event
4005 TRemoveChildEvent( const QString& entry )
4006 : myEntry( entry ) {}
4007 virtual void Execute()
4009 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4011 module->removeChildren( myEntry );
4014 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4018 void SalomePyQt::removeChildren( const QString& entry )
4020 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4022 void SalomePyQt::removeChild( const QString& entry )
4024 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4025 removeChildren( entry );
4029 \fn void SalomePyQt::removeObject( const QString& entry );
4030 \brief Remove object by entry
4031 \param entry data object entry
4034 class TRemoveObjectEvent: public SALOME_Event
4039 TRemoveObjectEvent( const QString& entry )
4040 : myEntry( entry ) {}
4041 virtual void Execute()
4043 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4045 module->removeObject( myEntry );
4048 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4052 void SalomePyQt::removeObject( const QString& entry )
4054 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4058 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4059 \brief Get entries of all child data objects of specified data object
4060 \param entry data object entry
4061 \param recursive \c true for recursive processing
4064 class TGetChildrenEvent: public SALOME_Event
4067 typedef QStringList TResult;
4071 TGetChildrenEvent( const QString& entry, const bool recursive )
4073 myRecursive( recursive ) {}
4074 virtual void Execute()
4076 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4078 myResult = module->getChildren( myEntry, myRecursive );
4081 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4085 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4087 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4090 #ifndef DISABLE_PLOT2DVIEWER
4091 // Next set of methods relates to the Plot2d viewer functionality
4094 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4095 \brief Display theCurve in view
4096 \param id window identifier
4097 \param theCurve curve to display
4100 class TDisplayCurve: public SALOME_Event
4104 Plot2d_Curve* myCurve;
4105 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4106 virtual void Execute() {
4107 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4109 wnd->getViewFrame()->displayCurve( myCurve );
4112 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4114 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4118 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4119 \brief Erase theCurve in view
4120 \param id window identifier
4121 \param theCurve curve to erase
4124 class TEraseCurve: public SALOME_Event
4128 Plot2d_Curve* myCurve;
4129 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4130 virtual void Execute() {
4131 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4132 wnd->getViewFrame()->eraseCurve( myCurve );
4135 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4137 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4141 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4142 \brief Delete theCurve from all views
4143 \param theCurve curve to delete
4146 class TDeleteCurve: public SALOME_Event
4149 Plot2d_Curve* myCurve;
4150 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4151 virtual void Execute() {
4152 LightApp_Application* app = getApplication();
4154 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4156 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4157 SUIT_ViewWindow* wnd;
4158 foreach ( wnd, wndlist ) {
4159 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4161 aP2d->getViewFrame()->eraseObject( myCurve );
4167 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4169 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4173 \brief updateCurves (repaint) curves in view window.
4175 void SalomePyQt::updateCurves( const int id )
4177 class TEvent: public SALOME_Event
4181 TEvent( const int id ) : myWndId( id ) {}
4182 virtual void Execute()
4184 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4186 wnd->getViewFrame()->DisplayAll();
4189 ProcessVoidEvent( new TEvent( id ) );
4193 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4194 \brief Get title of corresponding type
4195 \param id window identifier
4196 \param type is type of title
4197 \return title of corresponding type
4200 class TGetPlot2dTitle: public SALOME_Event
4203 typedef QString TResult;
4207 TGetPlot2dTitle(const int id, ObjectType type) :
4210 virtual void Execute() {
4211 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4213 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4216 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4218 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4223 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4224 \brief Set title of corresponding type
4225 \param id window identifier
4227 \param type is type of title
4231 class TSetPlot2dTitle: public SALOME_Event
4235 Plot2d_Curve* myCurve;
4239 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4244 virtual void Execute() {
4245 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4246 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4249 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4251 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4255 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4256 \brief Get list of Plot2d view ranges
4257 \param id window identifier
4258 \return list of view ranges (XMin, XMax, YMin, YMax)
4261 class TFitRangeByCurves: public SALOME_Event
4264 typedef QList<double> TResult;
4267 TFitRangeByCurves( const int id )
4269 virtual void Execute()
4272 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4274 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4275 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4276 myResult.append( XMin );
4277 myResult.append( XMax );
4278 myResult.append( YMin );
4279 myResult.append( YMax );
4283 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4285 return ProcessEvent( new TFitRangeByCurves( id ) );
4289 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4290 \brief Get list of current Plot2d view ranges
4291 \param id window identifier
4292 \return list of view ranges (XMin, XMax, YMin, YMax)
4295 class TFitRangeCurrent: public SALOME_Event
4298 typedef QList<double> TResult;
4301 TFitRangeCurrent( const int id )
4303 virtual void Execute()
4306 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4308 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4309 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4310 myResult.append( XMin );
4311 myResult.append( XMax );
4312 myResult.append( YMin );
4313 myResult.append( YMax );
4317 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4319 return ProcessEvent( new TFitRangeCurrent( id ) );
4323 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4324 \brief Set range of Plot2d view
4325 \param id window identifier
4332 class TPlot2dFitRange: public SALOME_Event
4340 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4346 virtual void Execute() {
4347 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4349 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4352 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4354 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4357 // End of methods related to the Plot2d viewer functionality
4358 #endif // DISABLE_PLOT2DVIEWER
4361 \brief Process Qt event loop
4363 void SalomePyQt::processEvents()
4365 QCoreApplication::processEvents();
4369 \brief Set visibility state for given object
4370 \param theEntry study ID of the object
4371 \param theState visibility state
4373 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4375 class TEvent: public SALOME_Event
4380 TEvent( const QString& theEntry, int theState ):
4381 myEntry( theEntry ), myState( theState ) {}
4382 virtual void Execute()
4384 LightApp_Study* aStudy = getActiveStudy();
4387 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4390 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4394 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4395 \brief Get visibility state for given object
4396 \param theEntry study ID of the object
4397 \return visibility state
4400 class TGetVisibilityStateEvent: public SALOME_Event
4403 typedef int TResult;
4406 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4407 virtual void Execute()
4409 LightApp_Study* aStudy = getActiveStudy();
4411 myResult = aStudy->visibilityState( myEntry );
4414 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4416 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4420 \brief Set position of given object in the tree
4421 \param theEntry study ID of the object
4422 \param thePos position
4424 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4426 class TEvent: public SALOME_Event
4431 TEvent( const QString& theEntry, int thePos ):
4432 myEntry( theEntry ), myPos( thePos ) {}
4433 virtual void Execute()
4435 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4437 module->setObjectPosition( myEntry, myPos );
4440 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4444 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4445 \brief Get position of given object in the tree
4446 \param theEntry study ID of the object
4450 class TGetObjectPositionEvent: public SALOME_Event
4453 typedef int TResult;
4456 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4457 virtual void Execute()
4459 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4461 myResult = module->getObjectPosition( myEntry );
4464 int SalomePyQt::getObjectPosition( const QString& theEntry )
4466 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4470 \brief Start recordind a log of Python commands from embedded console
4471 \param theFileName output lof file name
4473 void SalomePyQt::startPyLog( const QString& theFileName )
4475 class TEvent: public SALOME_Event
4479 TEvent( const QString& theFileName ):
4480 myFileName( theFileName ) {}
4481 virtual void Execute()
4483 if ( getApplication() ) {
4484 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4485 if ( pyConsole ) pyConsole->startLog( myFileName );
4489 ProcessVoidEvent( new TEvent( theFileName ) );
4493 \brief Stop recordind a log of Python commands from embedded console
4495 void SalomePyQt::stopPyLog()
4497 class TEvent: public SALOME_Event
4501 virtual void Execute()
4503 if ( getApplication() ) {
4504 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4505 if ( pyConsole ) pyConsole->stopLog();
4509 ProcessVoidEvent( new TEvent() );