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 \fn int SalomePyQt::integerSetting( const QString& section,
1365 const QString& name,
1367 \brief Get integer setting from the application preferences.
1368 \param section resources file section name
1369 \param name setting name
1370 \param def default value which is returned if the setting is not found
1371 \return setting value
1374 class TGetIntSettingEvent: public SALOME_Event
1377 typedef int TResult;
1382 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1383 : mySection( section ), myName( name ), myDefault( def ) {}
1384 virtual void Execute()
1386 if ( SUIT_Session::session() ) {
1387 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1388 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1392 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1394 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1398 \fn double SalomePyQt::doubleSetting( const QString& section,
1399 const QString& name,
1401 \brief Get double setting from the application preferences.
1402 \param section resources file section name
1403 \param name setting name
1404 \param def default value which is returned if the setting is not found
1405 \return setting value
1408 class TGetDblSettingEvent: public SALOME_Event
1411 typedef double TResult;
1416 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1417 : mySection( section ), myName( name ), myDefault( def ) {}
1418 virtual void Execute()
1420 if ( SUIT_Session::session() ) {
1421 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1422 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1426 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1428 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1432 \fn bool SalomePyQt::boolSetting( const QString& section,
1433 const QString& name,
1435 \brief Get boolean setting from the application preferences.
1436 \param section resources file section name
1437 \param name setting name
1438 \param def default value which is returned if the setting is not found
1439 \return setting value
1442 class TGetBoolSettingEvent: public SALOME_Event
1445 typedef bool TResult;
1450 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1451 : mySection( section ), myName( name ), myDefault( def ) {}
1452 virtual void Execute()
1454 if ( SUIT_Session::session() ) {
1455 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1456 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1460 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1462 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1466 \fn QString SalomePyQt::stringSetting( const QString& section,
1467 const QString& name,
1470 \brief Get string setting from the application preferences.
1471 \param section resources file section name
1472 \param name setting name
1473 \param def default value which is returned if the setting is not found
1474 \param subst \c true to make substitution, \c false to get "raw" value
1475 \return setting value
1478 class TGetStrSettingEvent: public SALOME_Event
1481 typedef QString TResult;
1487 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1488 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1489 virtual void Execute()
1491 if ( SUIT_Session::session() ) {
1492 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1493 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1497 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1499 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1503 \fn QColor SalomePyQt::colorSetting( const QString& section,
1504 const QString& name,
1506 \brief Get color setting from the application preferences.
1507 \param section resources file section name
1508 \param name setting name
1509 \param def default value which is returned if the setting is not found
1510 \return setting value
1513 class TGetColorSettingEvent: public SALOME_Event
1516 typedef QColor TResult;
1521 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1522 : mySection( section ), myName( name ), myDefault( def ) {}
1523 virtual void Execute()
1525 if ( SUIT_Session::session() ) {
1526 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1527 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1531 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1533 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1537 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1538 const QString& name,
1539 const QByteArray def );
1540 \brief Get byte array setting from the application preferences.
1541 \param section resources file section name
1542 \param name setting name
1543 \param def default value which is returned if the setting is not found
1544 \return setting value
1547 class TGetByteArraySettingEvent: public SALOME_Event
1550 typedef QByteArray TResult;
1555 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1556 : mySection( section ), myName( name ), myDefault( def ) {}
1557 virtual void Execute()
1559 if ( SUIT_Session::session() ) {
1560 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1561 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1565 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1567 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1571 \brief Remove setting from the application preferences.
1572 \param section resources file section name
1573 \param name setting name
1575 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1577 class TEvent: public SALOME_Event
1582 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1583 virtual void Execute()
1585 if ( SUIT_Session::session() ) {
1586 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1587 if ( !mySection.isEmpty() && !myName.isEmpty() )
1588 resMgr->remove( mySection, myName );
1592 ProcessVoidEvent( new TEvent( section, name ) );
1596 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1597 \brief Check setting existence in the application preferences.
1598 \param section resources file section name
1599 \param name setting name
1600 \return \c true if setting exists
1603 class THasSettingEvent: public SALOME_Event
1606 typedef bool TResult;
1610 THasSettingEvent( const QString& section, const QString& name )
1611 : mySection( section ), myName( name ) {}
1612 virtual void Execute()
1614 if ( SUIT_Session::session() ) {
1615 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1616 myResult = resMgr->hasValue( mySection, myName );
1620 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1622 return ProcessEvent( new THasSettingEvent( section, name ) );
1626 \fn QStringList SalomePyQt::parameters( const QString& section );
1627 \brief Get names of preference items stored within the given section.
1628 \param section resources file section's name
1629 \return \c list of preferences items
1633 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1634 \brief Get names of preference items stored within the given section.
1635 \param section resources file section's name
1636 \return \c list of preferences items
1639 class TParametersEvent: public SALOME_Event
1642 typedef QStringList TResult;
1644 QStringList mySection;
1645 TParametersEvent( const QString& section )
1647 mySection << section;
1649 TParametersEvent( const QStringList& section )
1650 : mySection( section )
1652 virtual void Execute()
1654 if ( SUIT_Session::session() ) {
1655 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1656 myResult = resMgr->parameters( mySection );
1660 QStringList SalomePyQt::parameters( const QString& section )
1662 return ProcessEvent( new TParametersEvent( section ) );
1664 QStringList SalomePyQt::parameters( const QStringList& section )
1666 return ProcessEvent( new TParametersEvent( section ) );
1670 \fn QString SalomePyQt::getFileName( QWidget* parent,
1671 const QString& initial,
1672 const QStringList& filters,
1673 const QString& caption,
1675 \brief Show 'Open/Save file' dialog box for file selection
1676 and return a user's choice (selected file name).
1677 \param parent parent widget
1678 \param initial initial directory the dialog box to be opened in
1679 \param filters list of files filters (wildcards)
1680 \param caption dialog box title
1681 \param open if \c true, "Open File" dialog box is shown;
1682 otherwise "Save File" dialog box is shown
1683 \return selected file name (null string if user cancels operation)
1686 class TGetFileNameEvent: public SALOME_Event
1689 typedef QString TResult;
1693 QStringList myFilters;
1696 TGetFileNameEvent( QWidget* parent,
1697 const QString& initial,
1698 const QStringList& filters,
1699 const QString& caption,
1701 : myParent ( parent ),
1702 myInitial( initial ),
1703 myFilters( filters ),
1704 myCaption( caption ),
1706 virtual void Execute()
1708 if ( LightApp_Application* anApp = getApplication() ) {
1709 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1710 myCaption, myParent );
1714 QString SalomePyQt::getFileName( QWidget* parent,
1715 const QString& initial,
1716 const QStringList& filters,
1717 const QString& caption,
1720 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1724 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1725 const QString& initial,
1726 const QStringList& filters,
1727 const QString& caption );
1728 \brief Show 'Open files' dialog box for multiple files selection
1729 and return a user's choice (selected file names list).
1730 \param parent parent widget
1731 \param initial initial directory the dialog box to be opened in
1732 \param filters list of files filters (wildcards)
1733 \param caption dialog box title
1734 \return selected file names list (empty list if user cancels operation)
1737 class TGetOpenFileNamesEvent: public SALOME_Event
1740 typedef QStringList TResult;
1744 QStringList myFilters;
1746 TGetOpenFileNamesEvent( QWidget* parent,
1747 const QString& initial,
1748 const QStringList& filters,
1749 const QString& caption )
1750 : myParent ( parent ),
1751 myInitial( initial ),
1752 myFilters( filters ),
1753 myCaption( caption ) {}
1754 virtual void Execute()
1756 if ( LightApp_Application* anApp = getApplication() ) {
1757 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1761 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1762 const QString& initial,
1763 const QStringList& filters,
1764 const QString& caption )
1766 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1770 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1771 const QString& initial,
1772 const QString& caption );
1773 \brief Show 'Get Directory' dialog box for the directory selection
1774 and return a user's choice (selected directory name).
1775 \param parent parent widget
1776 \param initial initial directory the dialog box to be opened in
1777 \param caption dialog box title
1778 \return selected directory name (null string if user cancels operation)
1781 class TGetExistingDirectoryEvent: public SALOME_Event
1784 typedef QString TResult;
1789 TGetExistingDirectoryEvent( QWidget* parent,
1790 const QString& initial,
1791 const QString& caption )
1792 : myParent ( parent ),
1793 myInitial( initial ),
1794 myCaption( caption ) {}
1795 virtual void Execute()
1797 if ( LightApp_Application* anApp = getApplication() ) {
1798 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1802 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1803 const QString& initial,
1804 const QString& caption )
1806 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1810 \fn QString SalomePyQt::loadIcon( const QString& filename );
1811 \brief Load an icon from the module resources by the specified file name.
1812 \param fileName icon file name
1816 class TLoadIconEvent: public SALOME_Event
1819 typedef QIcon TResult;
1823 TLoadIconEvent( const QString& module, const QString& filename )
1824 : myModule( module ),
1825 myFileName ( filename ) {}
1826 virtual void Execute()
1828 myResult = loadIconInternal( myModule, myFileName );
1831 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1833 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1837 \brief Open external browser to display context help information.
1840 Current implementation does nothing.
1842 \param source documentation (HTML) file name
1843 \param context context (for example, HTML ancor name)
1845 void SalomePyQt::helpContext( const QString& source, const QString& context )
1847 class TEvent: public SALOME_Event
1852 TEvent( const QString& source, const QString& context )
1853 : mySource( source ), myContext( context ) {}
1854 virtual void Execute()
1856 if ( LightApp_Application* anApp = getApplication() ) {
1857 anApp->onHelpContextModule( "", mySource, myContext );
1861 ProcessVoidEvent( new TEvent( source, context ) );
1865 \fn int SalomePyQt::defaultMenuGroup();
1866 \brief Get detault menu group identifier which can be used when
1867 creating menus (insert custom menu commands).
1868 \return default menu group ID
1871 class TDefMenuGroupEvent: public SALOME_Event
1874 typedef int TResult;
1876 TDefMenuGroupEvent() : myResult( -1 ) {}
1877 virtual void Execute()
1879 myResult = PyModuleHelper::defaultMenuGroup();
1882 int SalomePyQt::defaultMenuGroup()
1884 return ProcessEvent( new TDefMenuGroupEvent() );
1890 CrTool( const QString& tBar, const QString& nBar )
1891 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1892 CrTool( const int id, const int tBar, const int idx )
1893 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1894 CrTool( const int id, const QString& tBar, const int idx )
1895 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1896 CrTool( QAction* action, const int tbId, const int id, const int idx )
1897 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1898 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1899 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1901 int execute( LightApp_Module* module ) const
1906 return module->createTool( myTbTitle, myTbName );
1908 return module->createTool( myId, myTbId, myIndex );
1910 return module->createTool( myId, myTbTitle, myIndex );
1912 return module->createTool( myAction, myTbId, myId, myIndex );
1914 return module->createTool( myAction, myTbTitle, myId, myIndex );
1929 class TCreateToolEvent: public SALOME_Event
1932 typedef int TResult;
1934 const CrTool& myCrTool;
1935 TCreateToolEvent( const CrTool& crTool )
1936 : myResult( -1 ), myCrTool( crTool ) {}
1937 virtual void Execute()
1939 LightApp_Module* module = getActiveModule();
1941 myResult = myCrTool.execute( module );
1946 \brief Create toolbar with specified name.
1947 \param tBar toolbar title (language-dependent)
1948 \param nBar toolbar name (language-independent) [optional]
1949 \return toolbar ID or -1 if toolbar creation is failed
1951 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1953 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1957 \brief Insert action with specified \a id to the toolbar.
1959 \param tBar toolbar ID
1960 \param idx required index in the toolbar
1961 \return action ID or -1 if action could not be added
1963 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1965 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1969 \brief Insert action with specified \a id to the toolbar.
1971 \param tBar toolbar name
1972 \param idx required index in the toolbar
1973 \return action ID or -1 if action could not be added
1975 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1977 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1981 \brief Insert action to the toolbar.
1983 \param tBar toolbar ID
1984 \param id required action ID
1985 \param idx required index in the toolbar
1986 \return action ID or -1 if action could not be added
1988 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1990 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1994 \brief Insert action to the toolbar.
1996 \param tBar toolbar name
1997 \param id required action ID
1998 \param idx required index in the toolbar
1999 \return action ID or -1 if action could not be added
2001 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2003 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2009 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2010 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2011 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2012 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2013 CrMenu( const int id, const int menu, const int group, const int idx )
2014 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2015 CrMenu( const int id, const QString& menu, const int group, const int idx )
2016 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2017 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2018 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2019 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2020 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2022 int execute( LightApp_Module* module ) const
2027 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2029 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2031 return module->createMenu( myId, myMenuId, myGroup, myIndex );
2033 return module->createMenu( myId, myMenuName, myGroup, myIndex );
2035 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2037 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2046 QString mySubMenuName;
2053 class TCreateMenuEvent: public SALOME_Event
2056 typedef int TResult;
2058 const CrMenu& myCrMenu;
2059 TCreateMenuEvent( const CrMenu& crMenu )
2060 : myResult( -1 ), myCrMenu( crMenu ) {}
2061 virtual void Execute()
2063 LightApp_Module* module = getActiveModule();
2065 myResult = myCrMenu.execute( module );
2070 \brief Create main menu.
2071 \param subMenu menu name
2072 \param menu parent menu ID
2073 \param id required menu ID
2074 \param group menu group ID
2075 \param idx required index in the menu
2076 \return menu ID or -1 if menu could not be added
2078 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2080 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2084 \brief Create main menu.
2085 \param subMenu menu name
2086 \param menu parent menu name (list of menu names separated by "|")
2087 \param id required menu ID
2088 \param group menu group ID
2089 \param idx required index in the menu
2090 \return menu ID or -1 if menu could not be added
2092 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2094 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2098 \brief Insert action to the main menu.
2100 \param menu parent menu ID
2101 \param group menu group ID
2102 \param idx required index in the menu
2103 \return action ID or -1 if action could not be added
2105 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2107 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2111 \brief Insert action to the main menu.
2113 \param menu parent menu name (list of menu names separated by "|")
2114 \param group menu group ID
2115 \param idx required index in the menu
2116 \return action ID or -1 if action could not be added
2118 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2120 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2124 \brief Insert action to the main menu.
2126 \param menu parent menu ID
2127 \param group menu group ID
2128 \param idx required index in the menu
2129 \return action ID or -1 if action could not be added
2131 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2133 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2137 \brief Insert action to the main menu.
2139 \param menu parent menu name (list of menu names separated by "|")
2140 \param group menu group ID
2141 \param idx required index in the menu
2142 \return action ID or -1 if action could not be added
2144 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2146 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2150 \fn QAction* SalomePyQt::createSeparator();
2151 \brief Create separator action which can be used in the menu or toolbar.
2152 \return new separator action
2155 class TCreateSepEvent: public SALOME_Event
2158 typedef QAction* TResult;
2162 virtual void Execute()
2164 LightApp_Module* module = getActiveModule();
2166 myResult = (QAction*)module->separator();
2169 QAction* SalomePyQt::createSeparator()
2171 return ProcessEvent( new TCreateSepEvent() );
2175 \fn QAction* SalomePyQt::createAction( const int id,
2176 const QString& menuText,
2177 const QString& tipText,
2178 const QString& statusText,
2179 const QString& icon,
2181 const bool toggle );
2182 \brief Create an action which can be then used in the menu or toolbar.
2183 \param id the unique id action to be registered to
2184 \param menuText action text which should appear in menu
2185 \param tipText text which should appear in the tooltip
2186 \param statusText text which should appear in the status bar when action is activated
2187 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2188 \param key the key accelrator for the action
2189 \param toggle if \c true the action is checkable
2192 class TCreateActionEvent: public SALOME_Event
2195 typedef QAction* TResult;
2200 QString myStatusText;
2204 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2205 const QString& statusText, const QString& icon, const int key, const bool toggle )
2206 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2207 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2208 virtual void Execute()
2210 LightApp_Module* module = getActiveModule();
2212 QIcon icon = loadIconInternal( module->name(), myIcon );
2213 myResult = (QAction*)module->action( myId );
2215 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2216 myResult->setToolTip( myTipText );
2217 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2218 myResult->setText( myMenuText );
2219 if ( myResult->icon().isNull() && !icon.isNull() )
2220 myResult->setIcon( icon );
2221 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2222 myResult->setStatusTip( myStatusText );
2223 if ( myResult->shortcut().isEmpty() && myKey )
2224 myResult->setShortcut( myKey );
2225 if ( myResult->isCheckable() != myToggle )
2226 myResult->setCheckable( myToggle );
2229 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2231 // for Python module, automatically connect action to callback slot
2232 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2233 if ( helper ) helper->connectAction( myResult );
2237 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2238 const QString& tipText, const QString& statusText,
2239 const QString& icon, const int key, const bool toggle )
2241 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2245 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2246 \brief Create an action group which can be then used in the menu or toolbar
2247 \param id : the unique id action group to be registered to
2248 \param exclusive : if \c true the action group does exclusive toggling
2251 struct TCreateActionGroupEvent: public SALOME_Event
2253 typedef QtxActionGroup* TResult;
2257 TCreateActionGroupEvent( const int id, const bool exclusive )
2258 : myId( id ), myExclusive( exclusive ) {}
2259 virtual void Execute()
2261 LightApp_Module* module = getActiveModule();
2263 myResult = module->createActionGroup( myId, myExclusive );
2266 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2268 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2272 \fn QAction* SalomePyQt::action( const int id );
2273 \brief Get action by specified identifier.
2274 \return action or 0 if action is not registered
2277 class TActionEvent: public SALOME_Event
2280 typedef QAction* TResult;
2283 TActionEvent( const int id )
2284 : myResult( 0 ), myId( id ) {}
2285 virtual void Execute()
2287 LightApp_Module* module = getActiveModule();
2289 myResult = (QAction*)module->action( myId );
2292 QAction* SalomePyQt::action( const int id )
2294 return ProcessEvent( new TActionEvent( id ) );
2298 \fn int SalomePyQt::actionId( const QAction* a );
2299 \brief Get an action identifier.
2300 \return action ID or -1 if action is not registered
2303 class TActionIdEvent: public SALOME_Event
2306 typedef int TResult;
2308 const QAction* myAction;
2309 TActionIdEvent( const QAction* action )
2310 : myResult( -1 ), myAction( action ) {}
2311 virtual void Execute()
2313 LightApp_Module* module = getActiveModule();
2315 myResult = module->actionId( myAction );
2318 int SalomePyQt::actionId( const QAction* a )
2320 return ProcessEvent( new TActionIdEvent( a ) );
2324 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2325 \brief Add global (not module-related) preferences group.
2326 \param label global preferences group name
2327 \return preferences group identifier
2330 class TAddGlobalPrefEvent: public SALOME_Event
2333 typedef int TResult;
2336 TAddGlobalPrefEvent( const QString& label )
2337 : myResult( -1 ), myLabel( label ) {}
2338 virtual void Execute()
2340 LightApp_Module* module = getActiveModule();
2342 LightApp_Preferences* pref = module->getApp()->preferences();
2344 myResult = pref->addPreference( myLabel, -1 );
2348 int SalomePyQt::addGlobalPreference( const QString& label )
2350 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2354 \fn int SalomePyQt::addPreference( const QString& label );
2355 \brief Add module-related preferences group.
2356 \param label preferences group name
2357 \return preferences group identifier
2360 class TAddPrefEvent: public SALOME_Event
2363 typedef int TResult;
2366 TAddPrefEvent( const QString& label )
2367 : myResult( -1 ), myLabel( label ) {}
2368 virtual void Execute()
2370 LightApp_Module* module = getActiveModule();
2372 LightApp_Preferences* pref = module->getApp()->preferences();
2374 int cId = pref->addPreference( module->moduleName(), -1 );
2376 myResult = pref->addPreference( myLabel, cId );
2381 int SalomePyQt::addPreference( const QString& label )
2383 return ProcessEvent( new TAddPrefEvent( label ) );
2387 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2388 const QString& section, const QString& param );
2389 \brief Add module-related preferences.
2390 \param label preferences group name
2391 \param pId parent preferences group id
2392 \param type preferences type
2393 \param section resources file section name
2394 \param param resources file setting name
2395 \return preferences identifier
2398 class TAddPrefParamEvent: public SALOME_Event
2401 typedef int TResult;
2408 TAddPrefParamEvent( const QString& label,
2409 const int pId, const int type,
2410 const QString& section,
2411 const QString& param )
2413 myLabel( label ), myPId( pId ), myType( type ),
2414 mySection( section ), myParam ( param ) {}
2415 virtual void Execute()
2417 LightApp_Module* module = getActiveModule();
2419 LightApp_Preferences* pref = module->getApp()->preferences();
2421 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2425 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2426 const QString& section, const QString& param )
2428 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2432 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2433 \brief Get the preferences property.
2434 \param id preferences identifier
2435 \param prop preferences property name
2436 \return preferences property value or null QVariant if property is not set
2439 class TPrefPropEvent: public SALOME_Event
2442 typedef QVariant TResult;
2446 TPrefPropEvent( const int id, const QString& prop )
2447 : myId( id ), myProp( prop ) {}
2448 virtual void Execute()
2450 LightApp_Module* module = getActiveModule();
2452 LightApp_Preferences* pref = module->getApp()->preferences();
2454 myResult = pref->itemProperty( myProp, myId );
2458 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2460 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2464 \brief Set the preferences property.
2465 \param id preferences identifier
2466 \param prop preferences property name
2467 \param var preferences property value
2469 void SalomePyQt::setPreferenceProperty( const int id,
2470 const QString& prop,
2471 const QVariant& var )
2473 class TEvent: public SALOME_Event
2479 TEvent( const int id, const QString& prop, const QVariant& var )
2480 : myId( id ), myProp( prop ), myVar( var ) {}
2481 virtual void Execute()
2483 LightApp_Module* module = getActiveModule();
2485 LightApp_Preferences* pref = module->getApp()->preferences();
2487 pref->setItemProperty( myProp, myVar, myId );
2491 ProcessVoidEvent( new TEvent( id, prop, var ) );
2495 \brief Set specific widget as a custom preferences item.
2496 \param id preferences identifier
2497 \param prop preferences property name
2498 \param widget custom widget
2500 void SalomePyQt::setPreferencePropertyWg( const int id,
2501 const QString& prop,
2502 UserDefinedContent* widget )
2504 class TEvent: public SALOME_Event
2508 UserDefinedContent* myWidget;
2510 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2511 : myId( id ), myProp( prop ), myWidget( widget ) {}
2512 virtual void Execute()
2514 LightApp_Module* module = getActiveModule();
2516 LightApp_Preferences* pref = module->getApp()->preferences();
2518 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2523 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2527 \brief Add the property value to the list of values.
2529 This method allows creating properties which are QList<QVariant>
2530 - there is no way to pass such values directly to QVariant parameter with PyQt.
2532 \param id preferences identifier
2533 \param prop preferences property name
2534 \param idx preferences property index
2535 \param var preferences property value for the index \a idx
2537 void SalomePyQt::addPreferenceProperty( const int id,
2538 const QString& prop,
2540 const QVariant& var )
2542 class TEvent: public SALOME_Event
2549 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2550 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2551 virtual void Execute()
2553 LightApp_Module* module = getActiveModule();
2555 LightApp_Preferences* pref = module->getApp()->preferences();
2557 QVariant var = pref->itemProperty( myProp, myId );
2558 if ( var.isValid() ) {
2559 if ( var.type() == QVariant::StringList ) {
2560 QStringList sl = var.toStringList();
2561 if ( myIdx >= 0 && myIdx < sl.count() )
2562 sl[myIdx] = myVar.toString();
2564 sl.append( myVar.toString() );
2565 pref->setItemProperty( myProp, sl, myId );
2567 else if ( var.type() == QVariant::List ) {
2568 QList<QVariant> vl = var.toList();
2569 if ( myIdx >= 0 && myIdx < vl.count() )
2573 pref->setItemProperty( myProp, vl, myId );
2579 pref->setItemProperty( myProp, vl, myId );
2585 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2589 \brief Put the message to the Log messages output window
2590 \param msg message text (it can be of simple rich text format)
2591 \param addSeparator boolean flag which specifies if it is necessary
2592 to separate the message with predefined separator
2594 void SalomePyQt::message( const QString& msg, bool addSeparator )
2596 class TEvent: public SALOME_Event
2601 TEvent( const QString& msg, bool addSeparator )
2602 : myMsg( msg ), myAddSep( addSeparator ) {}
2603 virtual void Execute()
2605 if ( LightApp_Application* anApp = getApplication() ) {
2606 LogWindow* lw = anApp->logWindow();
2608 lw->putMessage( myMsg, myAddSep );
2612 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2616 \brief Remove all the messages from the Log messages output window.
2618 void SalomePyQt::clearMessages()
2620 class TEvent: public SALOME_Event
2624 virtual void Execute()
2626 if ( LightApp_Application* anApp = getApplication() ) {
2627 LogWindow* lw = anApp->logWindow();
2633 ProcessVoidEvent( new TEvent() );
2637 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2638 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2639 to the image file in the specified format.
2641 For the current moment JPEG, PNG and BMP images formats are supported.
2642 The image format is defined automatically by the file name extension.
2643 By default, BMP format is used.
2645 \param filename image file name
2646 \return operation status (\c true on success)
2649 class TDumpViewEvent: public SALOME_Event
2652 typedef bool TResult;
2656 TDumpViewEvent( const QString& filename, const int id )
2657 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2658 virtual void Execute()
2660 SUIT_ViewWindow* wnd = 0;
2662 if ( LightApp_Application* anApp = getApplication() ) {
2663 SUIT_ViewManager* vm = anApp->activeViewManager();
2665 wnd = vm->getActiveView();
2667 myWndId = wnd->getId();
2670 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2673 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2674 #ifndef DISABLE_PLOT2DVIEWER
2675 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2677 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2678 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2679 qApp->processEvents();
2680 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2681 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2685 #endif // DISABLE_PLOT2DVIEWER
2686 QImage im = wnd->dumpView();
2687 if ( !im.isNull() && !myFileName.isEmpty() ) {
2688 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2689 if ( fmt == "JPG" ) fmt = "JPEG";
2690 myResult = im.save( myFileName, fmt.toLatin1() );
2695 bool SalomePyQt::dumpView( const QString& filename, const int id )
2697 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2701 \fn QList<int> SalomePyQt::getViews();
2702 \brief Get list of integer identifiers of all the currently opened views
2703 \return list of integer identifiers of all the currently opened views
2706 class TGetViews: public SALOME_Event
2709 typedef QList<int> TResult;
2712 virtual void Execute()
2715 LightApp_Application* app = getApplication();
2717 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2719 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2720 SUIT_ViewWindow* wnd;
2721 foreach ( wnd, wndlist )
2722 myResult.append( wnd->getId() );
2727 QList<int> SalomePyQt::getViews()
2729 return ProcessEvent( new TGetViews() );
2733 \fn int SalomePyQt::getActiveView();
2734 \brief Get integer identifier of the currently active view
2735 \return integer identifier of the currently active view
2738 class TGetActiveView: public SALOME_Event
2741 typedef int TResult;
2745 virtual void Execute()
2747 LightApp_Application* app = getApplication();
2749 SUIT_ViewManager* viewMgr = app->activeViewManager();
2751 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2753 myResult = wnd->getId();
2758 int SalomePyQt::getActiveView()
2760 return ProcessEvent( new TGetActiveView() );
2764 \fn QString SalomePyQt::getViewType( const int id );
2765 \brief Get type of the specified view, e.g. "OCCViewer"
2766 \param id window identifier
2770 class TGetViewType: public SALOME_Event
2773 typedef QString TResult;
2776 TGetViewType( const int id )
2778 virtual void Execute()
2780 SUIT_ViewWindow* wnd = getWnd( myWndId );
2782 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2784 myResult = viewMgr->getType();
2788 QString SalomePyQt::getViewType( const int id )
2790 return ProcessEvent( new TGetViewType( id ) );
2794 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2795 \brief Change view caption
2796 \param id window identifier
2797 \param title new window title
2798 \return \c true if operation is completed successfully and \c false otherwise
2801 class TSetViewTitle: public SALOME_Event
2804 typedef bool TResult;
2808 TSetViewTitle( const int id, const QString& title )
2809 : myResult( false ),
2812 virtual void Execute()
2814 SUIT_ViewWindow* wnd = getWnd( myWndId );
2816 wnd->setWindowTitle( myTitle );
2821 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2823 return ProcessEvent( new TSetViewTitle( id, title ) );
2827 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2828 \brief Set view size
2829 \param w window width
2830 \param h window height
2831 \param id window identifier
2832 \return \c true if operation is completed successfully and \c false otherwise
2835 class TSetViewSize: public SALOME_Event
2838 typedef bool TResult;
2843 TSetViewSize( const int w, const int h, const int id )
2844 : myResult( false ),
2848 virtual void Execute()
2850 SUIT_ViewWindow* wnd = 0;
2852 if ( LightApp_Application* anApp = getApplication() ) {
2853 SUIT_ViewManager* vm = anApp->activeViewManager();
2855 wnd = vm->getActiveView();
2859 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2862 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2864 QString type = viewMgr->getType();
2865 if ( type == "OCCViewer") {
2866 #ifndef DISABLE_OCCVIEWER
2867 // specific processing for OCC viewer:
2868 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2869 // - if there is only one sub-view active; it will be resized;
2870 // - if there are several sub-views, each of them will be resized.
2871 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2872 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2873 if ( occView && occView->getView( i ) ) {
2874 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2878 #endif // DISABLE_OCCVIEWER
2880 else if ( type == "ParaView") {
2881 #ifndef DISABLE_PVVIEWER
2882 // specific processing for ParaView viewer:
2883 // hierarchy of ParaView viewer is much complex than for usual view;
2884 // we look for sub-widget named "Viewport"
2885 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2886 if ( !lst.isEmpty() ) {
2887 lst[0]->resize( myWndWidth, myWndHeight );
2890 #endif // DISABLE_PVVIEWER
2893 if ( wnd->centralWidget() ) {
2894 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2902 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2904 return ProcessEvent( new TSetViewSize( w, h, id ) );
2908 \fn QString SalomePyQt::getViewTitle( const int id );
2909 \brief Get view caption
2910 \param id window identifier
2911 \return view caption
2914 class TGetViewTitle: public SALOME_Event
2917 typedef QString TResult;
2920 TGetViewTitle( const int id )
2922 virtual void Execute()
2924 SUIT_ViewWindow* wnd = getWnd( myWndId );
2926 myResult = wnd->windowTitle();
2929 QString SalomePyQt::getViewTitle( const int id )
2931 return ProcessEvent( new TGetViewTitle( id ) );
2935 \fn QList<int> SalomePyQt::findViews( const QString& type );
2936 \brief Get list of integer identifiers of all the
2937 currently opened views of the specified type
2938 \param type viewer type
2939 \return list of integer identifiers
2942 class TFindViews: public SALOME_Event
2945 typedef QList<int> TResult;
2948 TFindViews( const QString& type )
2950 virtual void Execute()
2953 LightApp_Application* app = getApplication();
2955 ViewManagerList vmList;
2956 app->viewManagers( myType, vmList );
2957 SUIT_ViewManager* viewMgr;
2958 foreach ( viewMgr, vmList ) {
2959 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2960 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2961 SUIT_ViewWindow* wnd = vec[ i ];
2964 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
2965 myResult.append( wnd->getId() );
2972 QList<int> SalomePyQt::findViews( const QString& type )
2974 return ProcessEvent( new TFindViews( type ) );
2978 \fn bool SalomePyQt::activateView( const int id );
2979 \brief Activate view
2980 \param id window identifier
2981 \return \c true if operation is completed successfully and \c false otherwise
2984 class TActivateView: public SALOME_Event
2987 typedef bool TResult;
2990 TActivateView( const int id )
2991 : myResult( false ),
2993 virtual void Execute()
2995 SUIT_ViewWindow* wnd = getWnd( myWndId );
2996 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3003 bool SalomePyQt::activateView( const int id )
3005 return ProcessEvent( new TActivateView( id ) );
3009 \fn bool SalomePyQt::activateManagerAndView( const int id );
3010 \brief Activate view manager and view: useful for a view embedded in a module main Window
3011 \param id window identifier
3012 \return \c true if operation is completed successfully and \c false otherwise
3015 class TActivateViewManagerAndView: public SALOME_Event
3018 typedef bool TResult;
3021 TActivateViewManagerAndView( const int id )
3022 : myResult( false ),
3024 virtual void Execute()
3026 SUIT_ViewWindow* wnd = getWnd( myWndId );
3027 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3030 LightApp_Application* app = getApplication();
3031 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3037 bool SalomePyQt::activateViewManagerAndView( const int id )
3039 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3046 class TGetViewWidget: public SALOME_Event
3049 typedef QWidget* TResult;
3052 TGetViewWidget( const int id )
3055 virtual void Execute()
3057 SUIT_ViewWindow* wnd = getWnd( myWndId );
3059 myResult = (QWidget*)wnd;
3063 QWidget* SalomePyQt::getViewWidget( const int id)
3065 return ProcessEvent( new TGetViewWidget( id ) );
3070 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3071 \brief Create new view and activate it
3072 \param type viewer type
3076 \return integer identifier of created view (or -1 if view could not be created)
3079 class TCreateView: public SALOME_Event
3082 typedef int TResult;
3089 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3095 myDetached(detached) {}
3096 virtual void Execute()
3098 LightApp_Application* app = getApplication();
3100 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3102 QWidget* wnd = viewMgr->getActiveView();
3103 myResult = viewMgr->getActiveView()->getId();
3106 wnd->setVisible(false);
3107 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3111 if (myWidth > 0 && myHeight > 0) {
3112 #ifndef DISABLE_PLOT2DVIEWER
3113 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3114 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3115 #endif // DISABLE_PLOT2DVIEWER
3116 wnd->setGeometry( 0, 0, myWidth, myHeight );
3123 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3125 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3126 QCoreApplication::processEvents();
3131 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3132 \brief Create new view with custom widget embedded and activate it
3133 \param type viewer type
3134 \param w custom widget
3135 \return integer identifier of created view (or -1 if view could not be created)
3138 class TCreateViewWg: public SALOME_Event
3141 typedef int TResult;
3145 TCreateViewWg( const QString& theType, QWidget* w )
3149 virtual void Execute()
3151 LightApp_Application* app = getApplication();
3153 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3155 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3157 myResult = wnd->getId();
3162 int SalomePyQt::createView( const QString& type, QWidget* w )
3164 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3165 QCoreApplication::processEvents();
3170 \fn bool SalomePyQt::closeView( const int id );
3172 \param id window identifier
3173 \return \c true if operation is completed successfully and \c false otherwise
3176 class TCloseView: public SALOME_Event
3179 typedef bool TResult;
3182 TCloseView( const int id )
3183 : myResult( false ),
3185 virtual void Execute()
3187 SUIT_ViewWindow* wnd = getWnd( myWndId );
3189 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3197 bool SalomePyQt::closeView( const int id )
3199 return ProcessEvent( new TCloseView( id ) );
3203 \fn int SalomePyQt::cloneView( const int id );
3204 \brief Clone view (if this operation is supported for specified view type)
3205 \param id window identifier
3206 \return integer identifier of the cloned view or -1 or operation could not be performed
3209 class TCloneView: public SALOME_Event
3212 typedef int TResult;
3215 TCloneView( const int id )
3218 virtual void Execute()
3220 SUIT_ViewWindow* wnd = getWnd( myWndId );
3222 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3224 #ifndef DISABLE_OCCVIEWER
3225 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3226 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3227 occView->onCloneView();
3228 wnd = viewMgr->getActiveView();
3230 myResult = wnd->getId();
3232 #endif // DISABLE_OCCVIEWER
3233 #ifndef DISABLE_PLOT2DVIEWER
3234 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3235 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3236 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3237 if ( viewMgr2d && srcWnd2d ) {
3238 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3239 myResult = resWnd->getId();
3242 #endif // DISABLE_OCCVIEWER
3247 int SalomePyQt::cloneView( const int id )
3249 return ProcessEvent( new TCloneView( id ) );
3253 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3254 \brief Set view visibility.
3255 \param id window identifier
3256 \param visible new visiblity
3259 void SalomePyQt::setViewVisible( const int id, const bool visible )
3261 class TEvent: public SALOME_Event
3266 TEvent( const int id, const bool visible )
3267 : myWndId( id ), myVisible( visible ) {}
3268 virtual void Execute()
3270 SUIT_ViewWindow* wnd = getWnd( myWndId );
3271 if ( wnd ) wnd->setVisible( myVisible );
3274 ProcessVoidEvent( new TEvent( id, visible ) );
3278 \fn bool SalomePyQt::isViewVisible( const int id );
3279 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3280 \param id window identifier
3281 \return \c true if view is visible and \c false otherwise
3284 class TIsViewVisible: public SALOME_Event
3287 typedef bool TResult;
3290 TIsViewVisible( const int id )
3291 : myResult( false ),
3293 virtual void Execute()
3295 SUIT_ViewWindow* wnd = getWnd( myWndId );
3298 QWidget* p = wnd->parentWidget();
3299 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3303 bool SalomePyQt::isViewVisible( const int id )
3305 return ProcessEvent( new TIsViewVisible( id ) );
3309 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3310 \brief Set / clear view's "closable" option. By default any view is closable
3311 (i.e. can be closed by the user).
3312 \param id window identifier
3313 \param on new "closable" option's value
3316 void SalomePyQt::setViewClosable( const int id, const bool on )
3318 class TEvent: public SALOME_Event
3323 TEvent( const int id, const bool on )
3324 : myWndId( id ), myOn( on ) {}
3325 virtual void Execute()
3327 SUIT_ViewWindow* wnd = getWnd( myWndId );
3328 if ( wnd ) wnd->setClosable( myOn );
3331 ProcessVoidEvent( new TEvent( id, on ) );
3335 \fn bool SalomePyQt::isViewClosable( const int id );
3336 \brief Check whether view is closable (i.e. can be closed by the user)
3337 \param id window identifier
3338 \return \c true if view is closable or \c false otherwise
3341 class TIsViewClosable: public SALOME_Event
3344 typedef bool TResult;
3347 TIsViewClosable( const int id )
3350 virtual void Execute()
3352 SUIT_ViewWindow* wnd = getWnd( myWndId );
3354 myResult = wnd->closable();
3358 bool SalomePyQt::isViewClosable( const int id )
3360 return ProcessEvent( new TIsViewClosable( id ) );
3364 \fn bool SalomePyQt::groupAllViews();
3365 \brief Group all views to the single tab area
3366 \return \c true if operation is completed successfully and \c false otherwise
3369 class TGroupAllViews: public SALOME_Event
3372 typedef bool TResult;
3375 : myResult( false ) {}
3376 virtual void Execute()
3378 LightApp_Application* app = getApplication();
3380 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3382 QtxWorkstack* wStack = tabDesk->workstack();
3391 bool SalomePyQt::groupAllViews()
3393 return ProcessEvent( new TGroupAllViews() );
3397 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3398 \brief Split tab area to which view with identifier belongs to
3399 \param id window identifier
3400 \param ori orientation of split operation
3401 \param action action to be performed
3402 \return \c true if operation is completed successfully \c false otherwise
3405 class TSplitView: public SALOME_Event
3408 typedef bool TResult;
3413 TSplitView( const int id,
3414 const Orientation ori,
3415 const Action action )
3416 : myResult( false ),
3419 myAction( action ) {}
3420 virtual void Execute()
3422 SUIT_ViewWindow* wnd = getWnd( myWndId );
3425 // wnd->setFocus(); ???
3428 if ( getApplication() ) {
3429 STD_TabDesktop* desk =
3430 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3432 QtxWorkstack* wStack = desk->workstack();
3434 Qt::Orientation qtOri =
3435 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3437 QtxWorkstack::SplitType sType;
3438 if ( myAction == MoveWidget )
3439 sType = QtxWorkstack::SplitMove;
3440 else if ( myAction == LeaveWidget )
3441 sType = QtxWorkstack::SplitStay;
3443 sType = QtxWorkstack::SplitAt;
3445 wStack->Split( wnd, qtOri, sType );
3453 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3455 return ProcessEvent( new TSplitView( id, ori, action ) );
3459 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3460 \brief Move view with the first identifier to the same area which
3461 another view with the second identifier belongs to
3462 \param id source window identifier
3463 \param id_to destination window identifier
3464 param before specifies whether the first viewt has to be moved before or after
3466 \return \c true if operation is completed successfully and \c false otherwise
3469 class TMoveView: public SALOME_Event
3472 typedef bool TResult;
3477 TMoveView( const int id, const int id_to, const bool before )
3478 : myResult( false ),
3481 myIsBefore( before ) {}
3482 virtual void Execute()
3484 SUIT_ViewWindow* wnd = getWnd( myWndId );
3485 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3486 if ( wnd && wnd_to ) {
3487 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3488 getApplication()->desktop() )->workstack();
3490 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3494 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3496 return ProcessEvent( new TMoveView( id, id_to, before ) );
3500 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3501 \brief Get list of views identifiers that belongs to the same area as
3502 specified view (excluding it)
3503 \param id window identifier
3504 \return list of views identifiers
3507 class TNeighbourViews: public SALOME_Event
3510 typedef QList<int> TResult;
3513 TNeighbourViews( const int id )
3515 virtual void Execute()
3518 SUIT_ViewWindow* wnd = getWnd( myWndId );
3520 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3521 getApplication()->desktop() )->workstack();
3523 QWidgetList wgList = wStack->windowList( wnd );
3525 foreach ( wg, wgList ) {
3526 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3527 if ( tmpWnd && tmpWnd != wnd )
3528 myResult.append( tmpWnd->getId() );
3534 QList<int> SalomePyQt::neighbourViews( const int id )
3536 return ProcessEvent( new TNeighbourViews( id ) );
3541 \fn void SalomePyQt::createRoot();
3542 \brief Initialize root data object.
3544 Does nothing if root is already initialized.
3547 void SalomePyQt::createRoot()
3549 class TEvent: public SALOME_Event
3553 virtual void Execute()
3555 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3557 SALOME_PYQT_DataModelLight* dm =
3558 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3563 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3567 ProcessVoidEvent( new TEvent() );
3571 \fn QString SalomePyQt::createObject( const QString& parent );
3572 \brief Create empty data object
3573 \param parent entry of parent data object
3574 \return entry of created data object
3577 class TCreateEmptyObjectEvent: public SALOME_Event
3580 typedef QString TResult;
3583 TCreateEmptyObjectEvent( const QString& parent )
3584 : myParent( parent ) {}
3585 virtual void Execute()
3587 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3589 myResult = module->createObject( myParent );
3592 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3596 QString SalomePyQt::createObject( const QString& parent )
3598 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3602 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3603 const QString& tooltip,const QString& parent );
3604 \brief Create new data object with specified name, icon and tooltip
3605 \param name data object name
3606 \param icon data object icon
3607 \param toolTip data object tooltip
3608 \param parent entry of parent data object
3609 \return entry of created data object
3612 class TCreateObjectEvent: public SALOME_Event
3615 typedef QString TResult;
3621 TCreateObjectEvent( const QString& name,
3622 const QString& icon,
3623 const QString& tooltip,
3624 const QString& parent )
3627 myToolTip( tooltip ),
3628 myParent( parent ) {}
3629 virtual void Execute()
3631 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3633 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3636 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3640 QString SalomePyQt::createObject( const QString& name,
3641 const QString& icon,
3642 const QString& toolTip,
3643 const QString& parent )
3645 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3650 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3651 \brief Set data object name
3652 \param entry data object entry
3653 \param name data object name
3655 class TSetNameEvent: public SALOME_Event
3660 TSetNameEvent( const QString& entry,
3661 const QString& name )
3664 virtual void Execute()
3666 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3668 module->setName( myEntry, myName );
3671 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3675 void SalomePyQt::setName( const QString& entry, const QString& name )
3677 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3681 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3682 \brief Set data object icon
3683 \param entry data object entry
3684 \param icon data object icon file name (icon is loaded from module resources)
3687 class TSetIconEvent: public SALOME_Event
3692 TSetIconEvent( const QString& entry,
3693 const QString& icon )
3696 virtual void Execute()
3698 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3700 module->setIcon( myEntry, myIcon );
3703 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3708 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3710 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3714 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3715 \brief Set data object tooltip
3716 \param entry data object entry
3717 \param toolTip data object tooltip
3720 class TSetToolTipEvent: public SALOME_Event
3725 TSetToolTipEvent( const QString& entry,
3726 const QString& toolTip )
3728 myToolTip( toolTip ) {}
3729 virtual void Execute()
3731 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3733 module->setToolTip( myEntry, myToolTip );
3736 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3740 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3742 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3746 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3747 \brief Set reference to another data object
3748 \param entry data object entry
3749 \param refEntry referenced data object entry
3752 class TSetRefEvent: public SALOME_Event
3757 TSetRefEvent( const QString& entry,
3758 const QString& refEntry )
3760 myRefEntry( refEntry ) {}
3761 virtual void Execute()
3763 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3765 module->setReference( myEntry, myRefEntry );
3768 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3772 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3774 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3778 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3779 \brief Set data object color
3780 \param entry data object entry
3781 \param color data object color
3784 class TSetColorEvent: public SALOME_Event
3789 TSetColorEvent( const QString& entry,
3790 const QColor& color )
3793 virtual void Execute()
3795 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3797 module->setColor( myEntry, myColor );
3800 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3804 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3806 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3810 \fn QString SalomePyQt::getName( const QString& entry );
3811 \brief Get data object name
3812 \param entry data object entry
3813 \return data object name
3816 class TGetNameEvent: public SALOME_Event
3819 typedef QString TResult;
3822 TGetNameEvent( const QString& entry )
3823 : myEntry( entry ) {}
3824 virtual void Execute()
3826 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3828 myResult = module->getName( myEntry );
3831 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3835 QString SalomePyQt::getName( const QString& entry )
3837 return ProcessEvent( new TGetNameEvent( entry ) );
3841 \fn QString SalomePyQt::getToolTip( const QString& entry );
3842 \brief Get data object tooltip
3843 \param entry data object entry
3844 \return data object tooltip
3847 class TGetToolTipEvent: public SALOME_Event
3850 typedef QString TResult;
3853 TGetToolTipEvent( const QString& entry )
3854 : myEntry( entry ) {}
3855 virtual void Execute()
3857 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3859 myResult = module->getToolTip( myEntry );
3862 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3866 QString SalomePyQt::getToolTip( const QString& entry )
3868 return ProcessEvent( new TGetToolTipEvent( entry ) );
3872 \fn QString SalomePyQt::getReference( const QString& entry );
3873 \brief Get entry of the referenced object (if there's any)
3874 \param entry data object entry
3875 \return referenced data object entry
3878 class TGetRefEvent: public SALOME_Event
3881 typedef QString TResult;
3884 TGetRefEvent( const QString& entry )
3885 : myEntry( entry ) {}
3886 virtual void Execute()
3888 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3890 myResult = module->getReference( myEntry );
3893 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3897 QString SalomePyQt::getReference( const QString& entry )
3899 return ProcessEvent( new TGetRefEvent( entry ) );
3903 \fn QColor SalomePyQt::getColor( const QString& entry );
3904 \brief Get data object color
3905 \param entry data object entry
3906 \return data object color
3909 class TGetColorEvent: public SALOME_Event
3912 typedef QColor TResult;
3915 TGetColorEvent( const QString& entry )
3916 : myEntry( entry ) {}
3917 virtual void Execute()
3919 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3921 myResult = module->getColor( myEntry );
3924 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3928 QColor SalomePyQt::getColor( const QString& entry )
3930 return ProcessEvent( new TGetColorEvent( entry ) );
3934 \fn void SalomePyQt::removeChildren( const QString& entry );
3935 \brief Remove all child data objects from specified data object
3936 \param entry data object entry
3939 class TRemoveChildEvent: public SALOME_Event
3943 TRemoveChildEvent( const QString& entry )
3944 : myEntry( entry ) {}
3945 virtual void Execute()
3947 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3949 module->removeChildren( myEntry );
3952 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3956 void SalomePyQt::removeChildren( const QString& entry )
3958 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3960 void SalomePyQt::removeChild( const QString& entry )
3962 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3963 removeChildren( entry );
3967 \fn void SalomePyQt::removeObject( const QString& entry );
3968 \brief Remove object by entry
3969 \param entry data object entry
3972 class TRemoveObjectEvent: public SALOME_Event
3977 TRemoveObjectEvent( const QString& entry )
3978 : myEntry( entry ) {}
3979 virtual void Execute()
3981 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3983 module->removeObject( myEntry );
3986 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3990 void SalomePyQt::removeObject( const QString& entry )
3992 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3996 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3997 \brief Get entries of all child data objects of specified data object
3998 \param entry data object entry
3999 \param recursive \c true for recursive processing
4002 class TGetChildrenEvent: public SALOME_Event
4005 typedef QStringList TResult;
4009 TGetChildrenEvent( const QString& entry, const bool recursive )
4011 myRecursive( recursive ) {}
4012 virtual void Execute()
4014 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4016 myResult = module->getChildren( myEntry, myRecursive );
4019 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4023 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4025 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4028 #ifndef DISABLE_PLOT2DVIEWER
4029 // Next set of methods relates to the Plot2d viewer functionality
4032 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4033 \brief Display theCurve in view
4034 \param id window identifier
4035 \param theCurve curve to display
4038 class TDisplayCurve: public SALOME_Event
4042 Plot2d_Curve* myCurve;
4043 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4044 virtual void Execute() {
4045 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4047 wnd->getViewFrame()->displayCurve( myCurve );
4050 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4052 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4056 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4057 \brief Erase theCurve in view
4058 \param id window identifier
4059 \param theCurve curve to erase
4062 class TEraseCurve: public SALOME_Event
4066 Plot2d_Curve* myCurve;
4067 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4068 virtual void Execute() {
4069 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4070 wnd->getViewFrame()->eraseCurve( myCurve );
4073 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4075 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4079 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4080 \brief Delete theCurve from all views
4081 \param theCurve curve to delete
4084 class TDeleteCurve: public SALOME_Event
4087 Plot2d_Curve* myCurve;
4088 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4089 virtual void Execute() {
4090 LightApp_Application* app = getApplication();
4092 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4094 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4095 SUIT_ViewWindow* wnd;
4096 foreach ( wnd, wndlist ) {
4097 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4099 aP2d->getViewFrame()->eraseObject( myCurve );
4105 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4107 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4111 \brief updateCurves (repaint) curves in view window.
4113 void SalomePyQt::updateCurves( const int id )
4115 class TEvent: public SALOME_Event
4119 TEvent( const int id ) : myWndId( id ) {}
4120 virtual void Execute()
4122 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4124 wnd->getViewFrame()->DisplayAll();
4127 ProcessVoidEvent( new TEvent( id ) );
4131 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4132 \brief Get title of corresponding type
4133 \param id window identifier
4134 \param type is type of title
4135 \return title of corresponding type
4138 class TGetPlot2dTitle: public SALOME_Event
4141 typedef QString TResult;
4145 TGetPlot2dTitle(const int id, ObjectType type) :
4148 virtual void Execute() {
4149 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4151 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4154 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4156 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4161 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4162 \brief Set title of corresponding type
4163 \param id window identifier
4165 \param type is type of title
4169 class TSetPlot2dTitle: public SALOME_Event
4173 Plot2d_Curve* myCurve;
4177 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4182 virtual void Execute() {
4183 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4184 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4187 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4189 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4193 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4194 \brief Get list of Plot2d view ranges
4195 \param id window identifier
4196 \return list of view ranges (XMin, XMax, YMin, YMax)
4199 class TFitRangeByCurves: public SALOME_Event
4202 typedef QList<double> TResult;
4205 TFitRangeByCurves( const int id )
4207 virtual void Execute()
4210 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4212 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4213 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4214 myResult.append( XMin );
4215 myResult.append( XMax );
4216 myResult.append( YMin );
4217 myResult.append( YMax );
4221 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4223 return ProcessEvent( new TFitRangeByCurves( id ) );
4227 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4228 \brief Get list of current Plot2d view ranges
4229 \param id window identifier
4230 \return list of view ranges (XMin, XMax, YMin, YMax)
4233 class TFitRangeCurrent: public SALOME_Event
4236 typedef QList<double> TResult;
4239 TFitRangeCurrent( const int id )
4241 virtual void Execute()
4244 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4246 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4247 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4248 myResult.append( XMin );
4249 myResult.append( XMax );
4250 myResult.append( YMin );
4251 myResult.append( YMax );
4255 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4257 return ProcessEvent( new TFitRangeCurrent( id ) );
4261 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4262 \brief Set range of Plot2d view
4263 \param id window identifier
4270 class TPlot2dFitRange: public SALOME_Event
4278 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4284 virtual void Execute() {
4285 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4287 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4290 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4292 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4295 // End of methods related to the Plot2d viewer functionality
4296 #endif // DISABLE_PLOT2DVIEWER
4299 \brief Process Qt event loop
4301 void SalomePyQt::processEvents()
4303 QCoreApplication::processEvents();
4307 \brief Set visibility state for given object
4308 \param theEntry study ID of the object
4309 \param theState visibility state
4311 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4313 class TEvent: public SALOME_Event
4318 TEvent( const QString& theEntry, int theState ):
4319 myEntry( theEntry ), myState( theState ) {}
4320 virtual void Execute()
4322 LightApp_Study* aStudy = getActiveStudy();
4325 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4328 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4332 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4333 \brief Get visibility state for given object
4334 \param theEntry study ID of the object
4335 \return visibility state
4338 class TGetVisibilityStateEvent: public SALOME_Event
4341 typedef int TResult;
4344 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4345 virtual void Execute()
4347 LightApp_Study* aStudy = getActiveStudy();
4349 myResult = aStudy->visibilityState( myEntry );
4352 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4354 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4358 \brief Set position of given object in the tree
4359 \param theEntry study ID of the object
4360 \param thePos position
4362 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4364 class TEvent: public SALOME_Event
4369 TEvent( const QString& theEntry, int thePos ):
4370 myEntry( theEntry ), myPos( thePos ) {}
4371 virtual void Execute()
4373 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4375 module->setObjectPosition( myEntry, myPos );
4378 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4382 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4383 \brief Get position of given object in the tree
4384 \param theEntry study ID of the object
4388 class TGetObjectPositionEvent: public SALOME_Event
4391 typedef int TResult;
4394 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4395 virtual void Execute()
4397 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4399 myResult = module->getObjectPosition( myEntry );
4402 int SalomePyQt::getObjectPosition( const QString& theEntry )
4404 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4408 \brief Start recordind a log of Python commands from embedded console
4409 \param theFileName output lof file name
4411 void SalomePyQt::startPyLog( const QString& theFileName )
4413 class TEvent: public SALOME_Event
4417 TEvent( const QString& theFileName ):
4418 myFileName( theFileName ) {}
4419 virtual void Execute()
4421 if ( getApplication() ) {
4422 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4423 if ( pyConsole ) pyConsole->startLog( myFileName );
4427 ProcessVoidEvent( new TEvent( theFileName ) );
4431 \brief Stop recordind a log of Python commands from embedded console
4433 void SalomePyQt::stopPyLog()
4435 class TEvent: public SALOME_Event
4439 virtual void Execute()
4441 if ( getApplication() ) {
4442 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4443 if ( pyConsole ) pyConsole->stopLog();
4447 ProcessVoidEvent( new TEvent() );