1 // Copyright (C) 2007-2020 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_VTKVIEWER
46 #include "SVTK_ViewWindow.h"
47 #endif // DISABLE_VTKVIEWER
48 #ifndef DISABLE_PLOT2DVIEWER
49 #include "Plot2d_ViewManager.h"
50 #include "Plot2d_ViewWindow.h"
51 #endif // DISABLE_PLOT2DVIEWER
52 #ifndef DISABLE_PVVIEWER
53 #include "PVViewer_ViewManager.h"
54 #include "PVViewer_ViewModel.h"
55 #endif // DISABLE_PVVIEWER
56 #include "QtxActionMenuMgr.h"
57 #include "QtxWorkstack.h"
58 #include "QtxTreeView.h"
59 #include "SALOME_Event.h"
60 #include "STD_TabDesktop.h"
61 #include "SUIT_DataBrowser.h"
62 #include "SUIT_ResourceMgr.h"
63 #include "SUIT_Session.h"
64 #include "SUIT_Tools.h"
65 #include "SUIT_ViewManager.h"
66 #include "SUIT_ViewWindow.h"
67 #include "PyConsole_Console.h"
70 #include <QApplication>
71 #include <QPaintEvent>
72 #include <QCoreApplication>
73 #include <QVBoxLayout>
75 #include <utilities.h>
80 \brief Get the currently active application.
82 \return active application object or 0 if there is no any
84 LightApp_Application* getApplication()
86 if ( SUIT_Session::session() )
87 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
92 \brief Get the currently active study.
94 \return active study or 0 if there is no study opened
96 LightApp_Study* getActiveStudy()
98 if ( getApplication() )
99 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
104 \brief Get the currently active module.
106 This function returns correct result only if Python-based
107 module is currently active. Otherwize, 0 is returned.
109 LightApp_Module* getActiveModule()
111 LightApp_Module* module = 0;
112 if ( LightApp_Application* anApp = getApplication() ) {
113 module = PyModuleHelper::getInitModule();
115 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
121 \brief Get the currently active Python module's helper.
123 This function returns correct result only if Python-based
124 module is currently active. Otherwize, 0 is returned.
126 PyModuleHelper* getPythonHelper()
128 LightApp_Module* module = getActiveModule();
129 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
134 \brief Get SALOME verbose level
136 \return \c true if SALOME debug output is allowed or \c false otherwise
140 bool isVerbose = false;
141 if ( getenv( "SALOME_VERBOSE" ) ) {
142 QString envVar = getenv( "SALOME_VERBOSE" );
144 int value = envVar.toInt( &ok );
145 isVerbose = ok && value != 0;
151 \brief Get menu item title
153 \param menuId menu identifier
154 \return menu title (localized)
156 QString getMenuName( const QString& menuId )
158 QStringList contexts;
159 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
160 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
161 QString menuName = menuId;
162 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
163 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
168 \brief Load module icon
170 \param module module name
171 \param fileName path to the icon file
174 QIcon loadIconInternal( const QString& module, const QString& fileName )
178 LightApp_Application* app = getApplication();
180 if ( app && !fileName.isEmpty() ) {
181 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
182 QApplication::translate( module.toLatin1().data(),
183 fileName.toUtf8().data() ) );
184 if ( !pixmap.isNull() )
185 icon = QIcon( pixmap );
191 \brief Gets window with specified identifier
193 \param id window identifier
194 \return pointer on the window
196 SUIT_ViewWindow* getWnd( const int id )
198 SUIT_ViewWindow* resWnd = 0;
200 LightApp_Application* app = getApplication();
202 ViewManagerList vmlist = app->viewManagers();
203 foreach( SUIT_ViewManager* vm, vmlist ) {
204 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
205 foreach ( SUIT_ViewWindow* vw, vwlist ) {
206 if ( id == vw->getId() ) {
217 \brief Map of created selection objects.
220 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
223 \brief Default resource file section name.
226 const char* DEFAULT_SECTION = "SalomePyQt";
230 \class SALOME_Selection
231 \brief The class represents selection which can be used in Python.
235 \brief Get the selection object for the specified application.
237 Finds or creates the selection object (one per study).
239 \param app application object
240 \return selection object or 0 if \a app is invalid
242 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
244 SALOME_Selection* sel = 0;
245 if ( app && SelMap.find( app ) != SelMap.end() )
248 sel = SelMap[ app ] = new SALOME_Selection( app );
255 \param p parent object
257 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
259 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
261 mySelMgr = app->selectionMgr();
262 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
263 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
270 SALOME_Selection::~SALOME_Selection()
272 LightApp_Application* app = 0;
273 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
274 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
275 if ( it.value() == this ) app = it.key();
277 if ( app ) SelMap.remove( app );
281 \brief Called when selection manager is destroyed (usually
282 when the study is closed).
284 void SALOME_Selection::onSelMgrDestroyed()
290 \brief Clear the selection.
292 void SALOME_Selection::Clear()
294 class TEvent: public SALOME_Event
296 LightApp_SelectionMgr* mySelMgr;
298 TEvent( LightApp_SelectionMgr* selMgr )
299 : mySelMgr( selMgr ) {}
300 virtual void Execute()
303 mySelMgr->clearSelected();
306 ProcessVoidEvent( new TEvent( mySelMgr ) );
310 \brief Clear the selection.
312 void SALOME_Selection::ClearIObjects()
318 Removes all selection filters.
320 void SALOME_Selection::ClearFilters()
322 class TEvent: public SALOME_Event
324 LightApp_SelectionMgr* mySelMgr;
326 TEvent( LightApp_SelectionMgr* selMgr )
327 : mySelMgr( selMgr ) {}
328 virtual void Execute()
331 mySelMgr->clearFilters();
334 ProcessVoidEvent( new TEvent( mySelMgr ) );
338 \class UserDefinedContent
339 \brief The class represents base class for user defined widget that
340 can be inserted to the Preferences dialog.
346 UserDefinedContent::UserDefinedContent()
352 \brief Called from Preferences dialog to store settings to the resource file.
354 void UserDefinedContent::store()
359 \brief Called from Preferences dialog to restore settings from the resource file.
361 void UserDefinedContent::retrieve()
366 \class SgPyQtUserDefinedContent
367 \brief A Wrapper for UserDefinedContent class.
370 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
373 SgPyQtUserDefinedContent(UserDefinedContent*);
374 virtual ~SgPyQtUserDefinedContent();
376 void store( QtxResourceMgr*, QtxPreferenceMgr* );
377 void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
380 UserDefinedContent* myContent;
384 \brief Create custom item for Preferences dialog wrapping widget passed from Python.
387 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
388 : QtxUserDefinedContent( 0 ), myContent( content )
390 QVBoxLayout* l = new QVBoxLayout( this );
391 l->setContentsMargins( 0, 0, 0, 0 );
392 l->addWidget( myContent );
399 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
404 \brief Called from Preferences dialog to store settings to the resource file.
407 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
413 \brief Called from Preferences dialog to restore settings from the resource file.
416 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
418 myContent->retrieve();
423 \brief The class provides utility functions which can be used in the Python
424 to operate with the SALOME GUI.
426 All the functionality of this class is implemented as static methods, so they
427 can be called with the class name prefixed or via creation of the class instance.
428 For example, next both ways of SalomePyQt class usage are legal:
430 from SalomePyQt import *
432 # using SalomePyQt class instance
433 desktop = sg.getDesktop()
434 # using SalomePyQt class directly
435 menubar = SalomePyQt.getMainMenuBar()
440 \fn QString SalomePyQt::getAppName();
441 \brief Get application name
442 \return application name
445 QString SalomePyQt::getAppName()
447 LightApp_Application* app = getApplication();
448 return app == 0 ? QString() : QString(app->metaObject()->className()).split("_").first();
452 \fn bool SalomePyQt::isLightApp();
453 \brief Check if SALOME GUI is running in "light" mode.
454 \return \c true if this is a "light" application; \c false otherwise
457 bool SalomePyQt::isLightApp()
459 return SalomePyQt::getAppName() != "SalomeApp";
463 \fn QWidget* SalomePyQt::getDesktop();
464 \brief Get the active application's desktop window.
465 \return desktop window or 0 if there is no any
468 class TGetDesktopEvent: public SALOME_Event
471 typedef QWidget* TResult;
473 TGetDesktopEvent() : myResult( 0 ) {}
474 virtual void Execute()
476 if ( getApplication() )
477 myResult = (QWidget*)( getApplication()->desktop() );
480 QWidget* SalomePyQt::getDesktop()
482 return ProcessEvent( new TGetDesktopEvent() );
486 \fn QWidget* SalomePyQt::getMainFrame();
487 \brief Get current application's main frame widget [obsolete].
489 Main frame widget is an internal widget of the application
490 desktop window (workspace).
492 \return workspace widget (0 on any error)
495 class TGetMainFrameEvent: public SALOME_Event
498 typedef QWidget* TResult;
500 TGetMainFrameEvent() : myResult( 0 ) {}
501 virtual void Execute()
503 if ( getApplication() ) {
504 SUIT_Desktop* aDesktop = getApplication()->desktop();
505 myResult = (QWidget*)( aDesktop->centralWidget() );
509 QWidget* SalomePyQt::getMainFrame()
511 return ProcessEvent( new TGetMainFrameEvent() );
515 \fn QMenuBar* SalomePyQt::getMainMenuBar();
516 \brief Get current application desktop's main menu.
517 \return main menu object (0 on any error)
520 class TGetMainMenuBarEvent: public SALOME_Event
523 typedef QMenuBar* TResult;
525 TGetMainMenuBarEvent() : myResult( 0 ) {}
526 virtual void Execute()
528 if ( LightApp_Application* anApp = getApplication() ) {
529 myResult = anApp->desktop()->menuBar();
533 QMenuBar* SalomePyQt::getMainMenuBar()
535 return ProcessEvent( new TGetMainMenuBarEvent() );
539 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
540 \brief Get main menu's child popup submenu by its identifier.
542 This function is obsolete.
543 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
545 \param menu menu identifier
546 \return popup submenu object or 0 if it does not exist
550 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
551 \brief Get main menu's child popup submenu by its name.
553 The function creates menu if it does not exist.
555 \param menu menu name
556 \return popup submenu object (0 on any error)
559 class TGetPopupMenuEvent: public SALOME_Event
562 typedef QMenu* TResult;
565 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
566 virtual void Execute()
568 LightApp_Application* anApp = getApplication();
569 if ( anApp && !myMenuName.isEmpty() ) {
570 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
571 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
576 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
581 menuName = getMenuName( "MEN_DESK_FILE" ); break;
583 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
585 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
587 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
589 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
591 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
593 menuName = getMenuName( "MEN_DESK_HELP" ); break;
595 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
597 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
599 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
603 \fn QTreeView* SalomePyQt::getObjectBrowser();
604 \brief Get object browser
605 \return object browser for the active study or 0 in case of error
608 class TGetObjectBrowserEvent: public SALOME_Event
611 typedef QTreeView* TResult;
613 TGetObjectBrowserEvent() : myResult( 0 ) {}
614 virtual void Execute()
616 LightApp_Application* anApp = getApplication();
617 if ( anApp && anApp->objectBrowser() ) {
618 myResult = anApp->objectBrowser()->treeView();
622 QTreeView* SalomePyQt::getObjectBrowser()
624 return ProcessEvent( new TGetObjectBrowserEvent() );
628 \fn SALOME_Selection* SalomePyQt::getSelection();
629 \brief Get the selection object for the current study.
631 Creates a Selection object if it has not been created yet.
633 \return selection object (0 on error)
636 class TGetSelectionEvent: public SALOME_Event
639 typedef SALOME_Selection* TResult;
641 TGetSelectionEvent() : myResult( 0 ) {}
642 virtual void Execute()
644 myResult = SALOME_Selection::GetSelection( getApplication() );
647 SALOME_Selection* SalomePyQt::getSelection()
649 return ProcessEvent( new TGetSelectionEvent() );
653 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
654 \brief Send local selection for notification.
656 The list of locally selected objects (study entries) is sent for notification of
657 other listening entities (modules, viewers...).
660 class TSetSelectionEvent: public SALOME_Event
662 QStringList myEntryList;
664 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
665 virtual void Execute()
667 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
668 if ( !module ) return;
669 module->setLocalSelected(myEntryList);
672 void SalomePyQt::setSelection( const QStringList& entryList)
674 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
678 \fn void SalomePyQt::enableSelector();
679 \brief enable PyQt_Selector (on module activation, for instance)
682 class TEnableSelectorEvent: public SALOME_Event
685 TEnableSelectorEvent() {}
686 virtual void Execute()
688 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
689 if ( !module ) return;
690 module->enableSelector();
693 void SalomePyQt::enableSelector()
695 return ProcessVoidEvent( new TEnableSelectorEvent() );
700 \fn void SalomePyQt::disableSelector();
701 \brief disable PyQt_Selector (on module activation, for instance)
704 class TdisableSelectorEvent: public SALOME_Event
707 TdisableSelectorEvent() {}
708 virtual void Execute()
710 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
711 if ( !module ) return;
712 module->disableSelector();
715 void SalomePyQt::disableSelector()
717 return ProcessVoidEvent( new TdisableSelectorEvent() );
722 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
723 \brief Put an information message to the current application's
726 Optional second delay parameter (\a sec) can be used to specify
727 time of the message diplaying in seconds. If this parameter is less
728 or equal to zero, the constant message will be put.
730 \param msg message text
731 \param sec message displaying time in seconds
734 class TPutInfoEvent: public SALOME_Event
739 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
740 virtual void Execute()
742 if ( LightApp_Application* anApp = getApplication() ) {
743 anApp->putInfo( myMsg, mySecs * 1000 );
747 void SalomePyQt::putInfo( const QString& msg, const int sec )
749 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
753 \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
754 \brief Show notification in the application's desktop window.
756 Optional third delay parameter (\a sec) can be used to specify
757 time of the notification diplaying in seconds. If this parameter is less
758 or equal to zero, the permanent notification will be put.
760 Notification can be forcibly hidden via hideNotification() method.
762 \param msg message text
763 \param title title text
764 \param sec notification displaying time in seconds
765 \return unique ID of the notification (can be used to hide notification)
766 \sa hideNotification()
769 class TShowNotifyEvent: public SALOME_Event
780 TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
781 virtual void Execute()
783 if ( LightApp_Application* anApp = getApplication() ) {
784 myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
789 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
791 return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
795 \fn void SalomePyQt::hideNotification( const QString& msg );
796 \brief Remove notification with given message text from the application's desktop.
798 \param msg message text
799 \sa showNotification()
803 \fn void SalomePyQt::hideNotification( const int id );
804 \brief Remove notification with given \a id from the application's desktop.
806 \param id notification id
807 \sa showNotification()
810 class THideNotifyEvent: public SALOME_Event
816 THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
817 THideNotifyEvent( const int id ) : myId( id ) {}
818 virtual void Execute()
820 if ( LightApp_Application* anApp = getApplication() ) {
822 anApp->hideNotification( myId );
824 anApp->hideNotification( myMsg );
829 void SalomePyQt::hideNotification( const QString& msg )
831 ProcessVoidEvent( new THideNotifyEvent( msg ) );
834 void SalomePyQt::hideNotification( const int id )
836 ProcessVoidEvent( new THideNotifyEvent( id ) );
840 \fn QStringList SalomePyQt::getComponents();
841 \brief Get all modules used in current GUI session.
842 \return List of modules
845 class TGetComponentsEvent: public SALOME_Event
848 typedef QStringList TResult;
850 TGetComponentsEvent() {}
851 virtual void Execute()
853 if ( LightApp_Application* anApp = getApplication() )
856 anApp->modules( titles, false );
857 foreach ( QString title, titles )
859 myResult << anApp->moduleName( title );
864 QStringList SalomePyQt::getComponents()
866 return ProcessEvent( new TGetComponentsEvent() );
870 \fn const QString SalomePyQt::getActiveComponent();
871 \brief Get the currently active module name (for the current study).
872 \return active module name or empty string if there is no active module
875 class TGetActiveComponentEvent: public SALOME_Event
878 typedef QString TResult;
880 TGetActiveComponentEvent() {}
881 virtual void Execute()
883 if ( LightApp_Application* anApp = getApplication() ) {
884 if ( CAM_Module* mod = anApp->activeModule() ) {
885 myResult = mod->name();
890 const QString SalomePyQt::getActiveComponent()
892 return ProcessEvent( new TGetActiveComponentEvent() );
896 \fn PyObject* SalomePyQt::getActivePythonModule();
897 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
898 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
901 class TGetActivePyModuleEvent: public SALOME_Event
904 typedef PyObject* TResult;
906 TGetActivePyModuleEvent() : myResult( Py_None ) {}
907 virtual void Execute()
909 PyModuleHelper* helper = getPythonHelper();
911 myResult = (PyObject*)helper->pythonModule();
914 PyObject* SalomePyQt::getActivePythonModule()
916 return ProcessEvent( new TGetActivePyModuleEvent() );
920 \fn bool SalomePyQt::activateModule( const QString& modName );
921 \brief Activates SALOME module with the given name
922 \return True if the module has been activated and False otherwise.
925 class TActivateModuleEvent: public SALOME_Event
928 typedef bool TResult;
930 QString myModuleName;
931 TActivateModuleEvent( const QString& modName )
932 : myResult( false ), myModuleName( modName ) {}
933 virtual void Execute()
935 if ( LightApp_Application* anApp = getApplication() ) {
936 myResult = anApp->activateModule( myModuleName );
940 bool SalomePyQt::activateModule( const QString& modName )
942 return ProcessEvent( new TActivateModuleEvent( modName ) );
946 \brief Update an Object Browser of the study.
948 void SalomePyQt::updateObjBrowser()
950 class TEvent: public SALOME_Event
954 virtual void Execute()
956 if ( SUIT_Session::session() ) {
957 if ( getActiveStudy() ) {
958 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
959 QList<SUIT_Application*>::Iterator it;
960 for( it = apps.begin(); it != apps.end(); ++it ) {
961 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
962 if ( anApp && anApp->activeStudy() ) {
963 anApp->updateObjectBrowser();
971 ProcessVoidEvent( new TEvent() );
976 SalomePyQt::isModified()
977 \return The modification status of the data model
978 for the currently active Python module
979 \note This function is supported for "light" Python-based SALOME modules only.
982 class TIsModifiedEvent: public SALOME_Event
985 typedef bool TResult;
987 TIsModifiedEvent() : myResult( false ) {}
988 virtual void Execute()
990 LightApp_Module* module = getActiveModule();
994 SALOME_PYQT_DataModelLight* aModel =
995 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
997 myResult = aModel->isModified();
1000 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
1004 bool SalomePyQt::isModified()
1006 return ProcessEvent(new TIsModifiedEvent());
1010 SalomePyQt::setModified()
1012 Sets the modification status of the data model for
1013 the currently active Python module. This method should be used
1014 by the Python code in order to enable/disable "Save" operation
1015 depending on the module's data state.
1017 \note This function is supported for "light" Python-based SALOME modules only.
1019 \param New modification status of the data model
1023 void SalomePyQt::setModified( bool flag )
1025 class TEvent: public SALOME_Event
1031 virtual void Execute()
1033 LightApp_Module* module = getActiveModule();
1037 SALOME_PYQT_DataModelLight* model =
1038 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1040 LightApp_Application* app = module->getApp();
1042 if ( model && app ) {
1043 model->setModified( myFlag );
1044 app->updateActions();
1047 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1051 ProcessVoidEvent( new TEvent( flag ) );
1055 \brief Add string setting to the application preferences.
1057 The parameter \a autoValue is obsolete parameter and currently is not used.
1058 This parameter will be removed in future, so try to avoid its usage in
1061 This function is obsolete. Use one of addSetting() instead.
1063 \param name setting name (it should be of kind <section:setting> where
1064 \c section is resources section name and \c setting is setting name)
1065 \param value new setting value
1066 \param autoValue (not used)
1068 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1070 class TEvent: public SALOME_Event
1076 TEvent( const QString& name, const QString& value, bool autoValue )
1077 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1078 virtual void Execute()
1080 if ( SUIT_Session::session() ) {
1081 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1082 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1083 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1084 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1085 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1086 resMgr->setValue( _sec, _nam, myValue );
1090 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1094 \brief Add integer setting to the application preferences.
1096 The parameter \a autoValue is obsolete parameter and currently is not used.
1097 This parameter will be removed in future, so try to avoid its usage in
1100 This function is obsolete. Use one of addSetting() instead.
1102 \param name setting name (it should be of kind <section:setting> where
1103 \c section is resources section name and \c setting is setting name)
1104 \param value new setting value
1105 \param autoValue (not used)
1107 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1109 class TEvent: public SALOME_Event
1115 TEvent( const QString& name, const int value, bool autoValue )
1116 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1117 virtual void Execute()
1119 if ( SUIT_Session::session() ) {
1120 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1121 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1122 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1123 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1124 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1125 resMgr->setValue( _sec, _nam, myValue );
1129 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1133 \brief Add double setting to the application preferences.
1135 The parameter \a autoValue is obsolete parameter and currently is not used.
1136 This parameter will be removed in future, so try to avoid its usage in
1139 This function is obsolete. Use one of addSetting() instead.
1141 \param name setting name (it should be of kind <section:setting> where
1142 \c section is resources section name and \c setting is setting name)
1143 \param value new setting value
1144 \param autoValue (not used)
1146 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1148 class TEvent: public SALOME_Event
1154 TEvent( const QString& name, const double value, bool autoValue )
1155 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1156 virtual void Execute()
1158 if ( SUIT_Session::session() ) {
1159 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1160 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1161 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1162 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1163 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1164 resMgr->setValue( _sec, _nam, myValue );
1168 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1172 \brief Add boolean setting to the application preferences.
1174 The parameter \a autoValue is obsolete parameter and currently is not used.
1175 This parameter will be removed in future, so try to avoid its usage in
1178 This function is obsolete. Use one of addSetting() instead.
1180 \param name setting name (it should be of kind <section:setting> where
1181 \c section is resources section name and \c setting is setting name)
1182 \param value new setting value
1183 \param autoValue (not used)
1185 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1187 class TEvent: public SALOME_Event
1193 TEvent( const QString& name, const bool value, bool autoValue )
1194 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1195 virtual void Execute()
1197 if ( SUIT_Session::session() ) {
1198 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1199 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1200 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1201 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1202 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1203 resMgr->setValue( _sec, _nam, myValue );
1207 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1211 \brief Remove setting from the application preferences.
1213 This function is obsolete. Use removeSetting() instead.
1215 \param name setting name (it should be of kind <section:setting> where
1216 \c section is resources section name and \c setting is setting name)
1218 void SalomePyQt::removeSettings( const QString& name )
1220 class TEvent: public SALOME_Event
1224 TEvent( const QString& name ) : myName( name ) {}
1225 virtual void Execute()
1227 if ( SUIT_Session::session() ) {
1228 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1229 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1230 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1231 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1232 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1233 resMgr->remove( _sec, _nam );
1237 ProcessVoidEvent( new TEvent( name ) );
1241 \fn QString SalomePyQt::getSetting( const QString& name );
1242 \brief Get application setting value (as string represenation).
1244 This function is obsolete. Use stringSetting(), integerSetting(),
1245 boolSetting(), stringSetting() or colorSetting() instead.
1247 \param name setting name (it should be of kind <section:setting> where
1248 \c section is resources section name and \c setting is setting name)
1249 \return setting name (empty string if setting name is invalid)
1252 class TGetSettingEvent: public SALOME_Event
1255 typedef QString TResult;
1258 TGetSettingEvent( const QString& name ) : myName( name ) {}
1259 virtual void Execute()
1261 if ( SUIT_Session::session() ) {
1262 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1263 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1264 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1265 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1266 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1270 QString SalomePyQt::getSetting( const QString& name )
1272 return ProcessEvent( new TGetSettingEvent( name ) );
1276 \fn QString SalomePyQt::constant( const QString& name );
1277 \brief Get constant's value from application's resource manager.
1279 \param name name of the constant
1280 \return value of the constant
1285 class TGetConstantEvent: public SALOME_Event
1288 typedef QString TResult;
1291 TGetConstantEvent( const QString& name ) : myName( name ) {}
1292 virtual void Execute()
1294 if ( SUIT_Session::session() )
1295 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1298 QString SalomePyQt::constant( const QString& name )
1300 return ProcessEvent( new TGetConstantEvent( name ) );
1304 \brief Add constant to the application's resource manager.
1306 This function is useful to specify programmatically specific
1307 variables that are referenced in the resource setting.
1309 For example, some resource value can be set as "$(myroot)/data/files".
1310 Then, "mypath" constant can be set programmatically by the application
1311 depending on run-time requirements.
1313 \param section resources file section name
1314 \param name name of the constant
1315 \param value value of the constant
1319 void SalomePyQt::setConstant( const QString& name, const QString& value )
1321 class TEvent: public SALOME_Event
1323 QString myName, myValue;
1325 TEvent( const QString& name, const QString& value )
1326 : myName( name ), myValue( value ) {}
1327 virtual void Execute()
1329 if ( SUIT_Session::session() )
1330 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1333 ProcessVoidEvent( new TEvent( name, value ) );
1337 \brief Add double setting to the application preferences.
1338 \param section resources file section name
1339 \param name setting name
1340 \param value new setting value
1342 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1344 class TEvent: public SALOME_Event
1350 TEvent( const QString& section, const QString& name, double value )
1351 : mySection( section ), myName( name ), myValue( value ) {}
1352 virtual void Execute()
1354 if ( SUIT_Session::session() ) {
1355 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1356 if ( !mySection.isEmpty() && !myName.isEmpty() )
1357 resMgr->setValue( mySection, myName, myValue );
1361 ProcessVoidEvent( new TEvent( section, name, value ) );
1365 \brief Add integer setting to the application preferences.
1366 \param section resources file section name
1367 \param name setting name
1368 \param value new setting value
1370 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1372 class TEvent: public SALOME_Event
1378 TEvent( const QString& section, const QString& name, int value )
1379 : mySection( section ), myName( name ), myValue( value ) {}
1380 virtual void Execute()
1382 if ( SUIT_Session::session() ) {
1383 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1384 if ( !mySection.isEmpty() && !myName.isEmpty() )
1385 resMgr->setValue( mySection, myName, myValue );
1389 ProcessVoidEvent( new TEvent( section, name, value ) );
1393 \brief Add boolean setting to the application preferences.
1394 \param section resources file section name
1395 \param name setting name
1396 \param value new setting value
1397 \param dumb this parameter is used in order to avoid sip compilation error
1398 because of conflicting int and bool types
1400 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1402 class TEvent: public SALOME_Event
1408 TEvent( const QString& section, const QString& name, bool value )
1409 : mySection( section ), myName( name ), myValue( value ) {}
1410 virtual void Execute()
1412 if ( SUIT_Session::session() ) {
1413 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1414 if ( !mySection.isEmpty() && !myName.isEmpty() )
1415 resMgr->setValue( mySection, myName, myValue );
1419 ProcessVoidEvent( new TEvent( section, name, value ) );
1423 \brief Add string setting to the application preferences.
1424 \param section resources file section name
1425 \param name setting name
1426 \param value new setting value
1428 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1430 class TEvent: public SALOME_Event
1436 TEvent( const QString& section, const QString& name, const QString& value )
1437 : mySection( section ), myName( name ), myValue( value ) {}
1438 virtual void Execute()
1440 if ( SUIT_Session::session() ) {
1441 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1442 if ( !mySection.isEmpty() && !myName.isEmpty() )
1443 resMgr->setValue( mySection, myName, myValue );
1447 ProcessVoidEvent( new TEvent( section, name, value ) );
1451 \brief Add color setting to the application preferences.
1452 \param section resources file section name
1453 \param name setting name
1454 \param value new setting value
1456 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1458 class TEvent: public SALOME_Event
1464 TEvent( const QString& section, const QString& name, const QColor& value )
1465 : mySection( section ), myName( name ), myValue( value ) {}
1466 virtual void Execute()
1468 if ( SUIT_Session::session() ) {
1469 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1470 if ( !mySection.isEmpty() && !myName.isEmpty() )
1471 resMgr->setValue( mySection, myName, myValue );
1475 ProcessVoidEvent( new TEvent( section, name, value ) );
1479 \brief Add byte array setting to the application preferences.
1480 \param section resources file section name
1481 \param name setting name
1482 \param value new setting value
1484 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1486 class TEvent: public SALOME_Event
1492 TEvent( const QString& section, const QString& name, const QByteArray& value )
1493 : mySection( section ), myName( name ), myValue( value ) {}
1494 virtual void Execute()
1496 if ( SUIT_Session::session() ) {
1497 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1498 if ( !mySection.isEmpty() && !myName.isEmpty() )
1499 resMgr->setValue( mySection, myName, myValue );
1503 ProcessVoidEvent( new TEvent( section, name, value ) );
1507 \brief Add font setting to the application preferences.
1508 \param section resources file section name
1509 \param name setting name
1510 \param value new setting value
1512 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1514 class TEvent: public SALOME_Event
1520 TEvent( const QString& section, const QString& name, const QFont& value )
1521 : mySection( section ), myName( name ), myValue( value ) {}
1522 virtual void Execute()
1524 if ( SUIT_Session::session() ) {
1525 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1526 if ( !mySection.isEmpty() && !myName.isEmpty() )
1527 resMgr->setValue( mySection, myName, myValue );
1531 ProcessVoidEvent( new TEvent( section, name, value ) );
1535 \fn int SalomePyQt::integerSetting( const QString& section,
1536 const QString& name,
1538 \brief Get integer setting from the application preferences.
1539 \param section resources file section name
1540 \param name setting name
1541 \param def default value which is returned if the setting is not found
1542 \return setting value
1545 class TGetIntSettingEvent: public SALOME_Event
1548 typedef int TResult;
1553 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1554 : mySection( section ), myName( name ), myDefault( def ) {}
1555 virtual void Execute()
1557 if ( SUIT_Session::session() ) {
1558 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1559 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1563 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1565 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1569 \fn double SalomePyQt::doubleSetting( const QString& section,
1570 const QString& name,
1572 \brief Get double setting from the application preferences.
1573 \param section resources file section name
1574 \param name setting name
1575 \param def default value which is returned if the setting is not found
1576 \return setting value
1579 class TGetDblSettingEvent: public SALOME_Event
1582 typedef double TResult;
1587 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1588 : mySection( section ), myName( name ), myDefault( def ) {}
1589 virtual void Execute()
1591 if ( SUIT_Session::session() ) {
1592 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1593 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1597 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1599 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1603 \fn bool SalomePyQt::boolSetting( const QString& section,
1604 const QString& name,
1606 \brief Get boolean setting from the application preferences.
1607 \param section resources file section name
1608 \param name setting name
1609 \param def default value which is returned if the setting is not found
1610 \return setting value
1613 class TGetBoolSettingEvent: public SALOME_Event
1616 typedef bool TResult;
1621 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1622 : mySection( section ), myName( name ), myDefault( def ) {}
1623 virtual void Execute()
1625 if ( SUIT_Session::session() ) {
1626 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1627 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1631 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1633 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1637 \fn QString SalomePyQt::stringSetting( const QString& section,
1638 const QString& name,
1641 \brief Get string setting from the application preferences.
1642 \param section resources file section name
1643 \param name setting name
1644 \param def default value which is returned if the setting is not found
1645 \param subst \c true to make substitution, \c false to get "raw" value
1646 \return setting value
1649 class TGetStrSettingEvent: public SALOME_Event
1652 typedef QString TResult;
1658 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1659 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1660 virtual void Execute()
1662 if ( SUIT_Session::session() ) {
1663 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1664 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1668 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1670 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1674 \fn QColor SalomePyQt::colorSetting( const QString& section,
1675 const QString& name,
1677 \brief Get color setting from the application preferences.
1678 \param section resources file section name
1679 \param name setting name
1680 \param def default value which is returned if the setting is not found
1681 \return setting value
1684 class TGetColorSettingEvent: public SALOME_Event
1687 typedef QColor TResult;
1692 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1693 : mySection( section ), myName( name ), myDefault( def ) {}
1694 virtual void Execute()
1696 if ( SUIT_Session::session() ) {
1697 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1698 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1702 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1704 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1708 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1709 const QString& name,
1710 const QByteArray& def );
1711 \brief Get byte array setting from the application preferences.
1712 \param section resources file section name
1713 \param name setting name
1714 \param def default value which is returned if the setting is not found
1715 \return setting value
1718 class TGetByteArraySettingEvent: public SALOME_Event
1721 typedef QByteArray TResult;
1726 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1727 : mySection( section ), myName( name ), myDefault( def ) {}
1728 virtual void Execute()
1730 if ( SUIT_Session::session() ) {
1731 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1732 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1736 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1738 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1742 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1743 const QString& name,
1745 \brief Get font setting from the application preferences.
1746 \param section resources file section name
1747 \param name setting name
1748 \param def default value which is returned if the setting is not found
1749 \return setting value
1752 class TGetFontSettingEvent: public SALOME_Event
1755 typedef QFont TResult;
1760 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1761 : mySection( section ), myName( name ), myDefault( def ) {}
1762 virtual void Execute()
1764 if ( SUIT_Session::session() ) {
1765 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1766 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1770 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1772 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1776 \brief Remove setting from the application preferences.
1777 \param section resources file section name
1778 \param name setting name
1780 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1782 class TEvent: public SALOME_Event
1787 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1788 virtual void Execute()
1790 if ( SUIT_Session::session() ) {
1791 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1792 if ( !mySection.isEmpty() && !myName.isEmpty() )
1793 resMgr->remove( mySection, myName );
1797 ProcessVoidEvent( new TEvent( section, name ) );
1801 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1802 \brief Check setting existence in the application preferences.
1803 \param section resources file section name
1804 \param name setting name
1805 \return \c true if setting exists
1808 class THasSettingEvent: public SALOME_Event
1811 typedef bool TResult;
1815 THasSettingEvent( const QString& section, const QString& name )
1816 : mySection( section ), myName( name ) {}
1817 virtual void Execute()
1819 if ( SUIT_Session::session() ) {
1820 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1821 myResult = resMgr->hasValue( mySection, myName );
1825 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1827 return ProcessEvent( new THasSettingEvent( section, name ) );
1831 \fn QStringList SalomePyQt::parameters( const QString& section );
1832 \brief Get names of preference items stored within the given section.
1833 \param section resources file section's name
1834 \return \c list of preferences items
1838 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1839 \brief Get names of preference items stored within the given section.
1840 \param section resources file section's name
1841 \return \c list of preferences items
1844 class TParametersEvent: public SALOME_Event
1847 typedef QStringList TResult;
1849 QStringList mySection;
1850 TParametersEvent( const QString& section )
1852 mySection << section;
1854 TParametersEvent( const QStringList& section )
1855 : mySection( section )
1857 virtual void Execute()
1859 if ( SUIT_Session::session() ) {
1860 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1861 myResult = resMgr->parameters( mySection );
1865 QStringList SalomePyQt::parameters( const QString& section )
1867 return ProcessEvent( new TParametersEvent( section ) );
1869 QStringList SalomePyQt::parameters( const QStringList& section )
1871 return ProcessEvent( new TParametersEvent( section ) );
1875 \fn QString SalomePyQt::getFileName( QWidget* parent,
1876 const QString& initial,
1877 const QStringList& filters,
1878 const QString& caption,
1880 \brief Show 'Open/Save file' dialog box for file selection
1881 and return a user's choice (selected file name).
1882 \param parent parent widget
1883 \param initial initial directory the dialog box to be opened in
1884 \param filters list of files filters (wildcards)
1885 \param caption dialog box title
1886 \param open if \c true, "Open File" dialog box is shown;
1887 otherwise "Save File" dialog box is shown
1888 \return selected file name (null string if user cancels operation)
1891 class TGetFileNameEvent: public SALOME_Event
1894 typedef QString TResult;
1898 QStringList myFilters;
1901 TGetFileNameEvent( QWidget* parent,
1902 const QString& initial,
1903 const QStringList& filters,
1904 const QString& caption,
1906 : myParent ( parent ),
1907 myInitial( initial ),
1908 myFilters( filters ),
1909 myCaption( caption ),
1911 virtual void Execute()
1913 if ( LightApp_Application* anApp = getApplication() ) {
1914 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1915 myCaption, myParent );
1919 QString SalomePyQt::getFileName( QWidget* parent,
1920 const QString& initial,
1921 const QStringList& filters,
1922 const QString& caption,
1925 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1929 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1930 const QString& initial,
1931 const QStringList& filters,
1932 const QString& caption );
1933 \brief Show 'Open files' dialog box for multiple files selection
1934 and return a user's choice (selected file names list).
1935 \param parent parent widget
1936 \param initial initial directory the dialog box to be opened in
1937 \param filters list of files filters (wildcards)
1938 \param caption dialog box title
1939 \return selected file names list (empty list if user cancels operation)
1942 class TGetOpenFileNamesEvent: public SALOME_Event
1945 typedef QStringList TResult;
1949 QStringList myFilters;
1951 TGetOpenFileNamesEvent( QWidget* parent,
1952 const QString& initial,
1953 const QStringList& filters,
1954 const QString& caption )
1955 : myParent ( parent ),
1956 myInitial( initial ),
1957 myFilters( filters ),
1958 myCaption( caption ) {}
1959 virtual void Execute()
1961 if ( LightApp_Application* anApp = getApplication() ) {
1962 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1966 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1967 const QString& initial,
1968 const QStringList& filters,
1969 const QString& caption )
1971 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1975 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1976 const QString& initial,
1977 const QString& caption );
1978 \brief Show 'Get Directory' dialog box for the directory selection
1979 and return a user's choice (selected directory name).
1980 \param parent parent widget
1981 \param initial initial directory the dialog box to be opened in
1982 \param caption dialog box title
1983 \return selected directory name (null string if user cancels operation)
1986 class TGetExistingDirectoryEvent: public SALOME_Event
1989 typedef QString TResult;
1994 TGetExistingDirectoryEvent( QWidget* parent,
1995 const QString& initial,
1996 const QString& caption )
1997 : myParent ( parent ),
1998 myInitial( initial ),
1999 myCaption( caption ) {}
2000 virtual void Execute()
2002 if ( LightApp_Application* anApp = getApplication() ) {
2003 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
2007 QString SalomePyQt::getExistingDirectory( QWidget* parent,
2008 const QString& initial,
2009 const QString& caption )
2011 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
2015 \fn QString SalomePyQt::loadIcon( const QString& filename );
2016 \brief Load an icon from the module resources by the specified file name.
2017 \param fileName icon file name
2021 class TLoadIconEvent: public SALOME_Event
2024 typedef QIcon TResult;
2028 TLoadIconEvent( const QString& module, const QString& filename )
2029 : myModule( module ),
2030 myFileName ( filename ) {}
2031 virtual void Execute()
2033 myResult = loadIconInternal( myModule, myFileName );
2036 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2038 return ProcessEvent( new TLoadIconEvent( module, filename ) );
2042 \brief Open external browser to display context help information.
2045 Current implementation does nothing.
2047 \param source documentation (HTML) file name
2048 \param context context (for example, HTML ancor name)
2050 void SalomePyQt::helpContext( const QString& source, const QString& context )
2052 class TEvent: public SALOME_Event
2057 TEvent( const QString& source, const QString& context )
2058 : mySource( source ), myContext( context ) {}
2059 virtual void Execute()
2061 if ( LightApp_Application* anApp = getApplication() ) {
2062 anApp->onHelpContextModule( "", mySource, myContext );
2066 ProcessVoidEvent( new TEvent( source, context ) );
2070 \fn int SalomePyQt::defaultMenuGroup();
2071 \brief Get detault menu group identifier which can be used when
2072 creating menus (insert custom menu commands).
2073 \return default menu group ID
2076 class TDefMenuGroupEvent: public SALOME_Event
2079 typedef int TResult;
2081 TDefMenuGroupEvent() : myResult( -1 ) {}
2082 virtual void Execute()
2084 myResult = PyModuleHelper::defaultMenuGroup();
2087 int SalomePyQt::defaultMenuGroup()
2089 return ProcessEvent( new TDefMenuGroupEvent() );
2095 CrTool( const QString& tBar, const QString& nBar )
2096 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
2097 CrTool( const int id, const int tBar, const int idx )
2098 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
2099 CrTool( const int id, const QString& tBar, const int idx )
2100 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
2101 CrTool( QAction* action, const int tbId, const int id, const int idx )
2102 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
2103 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2104 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2110 if ( getActiveModule() )
2111 return getActiveModule()->createTool( myTbTitle, myTbName );
2112 else if ( getApplication() )
2113 return getApplication()->createTool( myTbTitle, myTbName );
2115 if ( getActiveModule() )
2116 return getActiveModule()->createTool( myId, myTbId, myIndex );
2117 else if ( getApplication() )
2118 return getApplication()->createTool( myId, myTbId, myIndex );
2120 if ( getActiveModule() )
2121 return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2122 else if ( getApplication() )
2123 return getApplication()->createTool( myId, myTbTitle, myIndex );
2125 if ( getActiveModule() )
2126 return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2127 else if ( getApplication() )
2128 return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2130 if ( getActiveModule() )
2131 return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2132 else if ( getApplication() )
2133 return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2147 class TCreateToolEvent: public SALOME_Event
2150 typedef int TResult;
2152 const CrTool& myCrTool;
2153 TCreateToolEvent( const CrTool& crTool )
2154 : myResult( -1 ), myCrTool( crTool ) {}
2155 virtual void Execute()
2157 myResult = myCrTool.execute();
2162 \brief Create toolbar with specified name.
2163 \param tBar toolbar title (language-dependent)
2164 \param nBar toolbar name (language-independent) [optional]
2165 \return toolbar ID or -1 if toolbar creation is failed
2167 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2169 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2173 \brief Insert action with specified \a id to the toolbar.
2175 \param tBar toolbar ID
2176 \param idx required index in the toolbar
2177 \return action ID or -1 if action could not be added
2179 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2181 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2185 \brief Insert action with specified \a id to the toolbar.
2187 \param tBar toolbar name
2188 \param idx required index in the toolbar
2189 \return action ID or -1 if action could not be added
2191 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2193 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2197 \brief Insert action to the toolbar.
2199 \param tBar toolbar ID
2200 \param id required action ID
2201 \param idx required index in the toolbar
2202 \return action ID or -1 if action could not be added
2204 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2206 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2211 \brief Clear given toolbar.
2212 \param title toolbar's title
2214 void SalomePyQt::clearTool( const QString& title )
2216 class TEvent: public SALOME_Event
2220 TEvent( const QString& title )
2221 : myTitle( title ) {}
2222 virtual void Execute()
2224 if ( getActiveModule() )
2225 return getActiveModule()->clearTool( myTitle );
2226 else if ( getApplication() )
2227 return getApplication()->clearTool( myTitle );
2230 ProcessVoidEvent( new TEvent( title ) );
2234 \brief Insert action to the toolbar.
2236 \param tBar toolbar name
2237 \param id required action ID
2238 \param idx required index in the toolbar
2239 \return action ID or -1 if action could not be added
2241 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2243 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2249 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2250 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2251 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2252 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2253 CrMenu( const int id, const int menu, const int group, const int idx )
2254 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2255 CrMenu( const int id, const QString& menu, const int group, const int idx )
2256 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2257 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2258 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2259 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2260 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2266 if ( getActiveModule() )
2267 return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2268 else if ( getApplication() )
2269 return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2271 if ( getActiveModule() )
2272 return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2273 else if ( getApplication() )
2274 return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2276 if ( getActiveModule() )
2277 return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2278 else if ( getApplication() )
2279 return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2281 if ( getActiveModule() )
2282 return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2283 else if ( getApplication() )
2284 return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2286 if ( getActiveModule() )
2287 return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2288 else if ( getApplication() )
2289 return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2291 if ( getActiveModule() )
2292 return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2293 else if ( getApplication() )
2294 return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2302 QString mySubMenuName;
2309 class TCreateMenuEvent: public SALOME_Event
2312 typedef int TResult;
2314 const CrMenu& myCrMenu;
2315 TCreateMenuEvent( const CrMenu& crMenu )
2316 : myResult( -1 ), myCrMenu( crMenu ) {}
2317 virtual void Execute()
2319 myResult = myCrMenu.execute();
2324 \brief Create main menu.
2325 \param subMenu menu name
2326 \param menu parent menu ID
2327 \param id required menu ID
2328 \param group menu group ID
2329 \param idx required index in the menu
2330 \return menu ID or -1 if menu could not be added
2332 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2334 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2338 \brief Create main menu.
2339 \param subMenu menu name
2340 \param menu parent menu name (list of menu names separated by "|")
2341 \param id required menu ID
2342 \param group menu group ID
2343 \param idx required index in the menu
2344 \return menu ID or -1 if menu could not be added
2346 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2348 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2352 \brief Insert action to the main menu.
2354 \param menu parent menu ID
2355 \param group menu group ID
2356 \param idx required index in the menu
2357 \return action ID or -1 if action could not be added
2359 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2361 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2365 \brief Insert action to the main menu.
2367 \param menu parent menu name (list of menu names separated by "|")
2368 \param group menu group ID
2369 \param idx required index in the menu
2370 \return action ID or -1 if action could not be added
2372 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2374 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2378 \brief Insert action to the main menu.
2380 \param menu parent menu ID
2381 \param group menu group ID
2382 \param idx required index in the menu
2383 \return action ID or -1 if action could not be added
2385 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2387 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2391 \brief Insert action to the main menu.
2393 \param menu parent menu name (list of menu names separated by "|")
2394 \param group menu group ID
2395 \param idx required index in the menu
2396 \return action ID or -1 if action could not be added
2398 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2400 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2404 \fn QAction* SalomePyQt::createSeparator();
2405 \brief Create separator action which can be used in the menu or toolbar.
2406 \return new separator action
2409 class TCreateSepEvent: public SALOME_Event
2412 typedef QAction* TResult;
2416 virtual void Execute()
2418 LightApp_Module* module = getActiveModule();
2420 myResult = (QAction*)module->separator();
2423 QAction* SalomePyQt::createSeparator()
2425 return ProcessEvent( new TCreateSepEvent() );
2429 \fn QAction* SalomePyQt::createAction( const int id,
2430 const QString& menuText,
2431 const QString& tipText,
2432 const QString& statusText,
2433 const QString& icon,
2435 const bool toggle );
2436 \brief Create an action which can be then used in the menu or toolbar.
2437 \param id the unique id action to be registered to
2438 \param menuText action text which should appear in menu
2439 \param tipText text which should appear in the tooltip
2440 \param statusText text which should appear in the status bar when action is activated
2441 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2442 \param key the key accelrator for the action
2443 \param toggle if \c true the action is checkable
2446 class TCreateActionEvent: public SALOME_Event
2449 typedef QAction* TResult;
2454 QString myStatusText;
2458 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2459 const QString& statusText, const QString& icon, const int key, const bool toggle )
2460 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2461 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2462 virtual void Execute()
2464 LightApp_Module* module = getActiveModule();
2466 QIcon icon = loadIconInternal( module->name(), myIcon );
2467 myResult = (QAction*)module->action( myId );
2469 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2470 myResult->setToolTip( myTipText );
2471 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2472 myResult->setText( myMenuText );
2473 if ( myResult->icon().isNull() && !icon.isNull() )
2474 myResult->setIcon( icon );
2475 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2476 myResult->setStatusTip( myStatusText );
2477 if ( myResult->shortcut().isEmpty() && myKey )
2478 myResult->setShortcut( myKey );
2479 if ( myResult->isCheckable() != myToggle )
2480 myResult->setCheckable( myToggle );
2483 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2485 // for Python module, automatically connect action to callback slot
2486 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2487 if ( helper ) helper->connectAction( myResult );
2491 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2492 const QString& tipText, const QString& statusText,
2493 const QString& icon, const int key, const bool toggle )
2495 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2499 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2500 \brief Create an action group which can be then used in the menu or toolbar
2501 \param id : the unique id action group to be registered to
2502 \param exclusive : if \c true the action group does exclusive toggling
2505 struct TCreateActionGroupEvent: public SALOME_Event
2507 typedef QtxActionGroup* TResult;
2511 TCreateActionGroupEvent( const int id, const bool exclusive )
2512 : myId( id ), myExclusive( exclusive ) {}
2513 virtual void Execute()
2515 LightApp_Module* module = getActiveModule();
2517 myResult = module->createActionGroup( myId, myExclusive );
2520 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2522 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2526 \fn QAction* SalomePyQt::action( const int id );
2527 \brief Get action by specified identifier.
2528 \return action or 0 if action is not registered
2531 class TActionEvent: public SALOME_Event
2534 typedef QAction* TResult;
2537 TActionEvent( const int id )
2538 : myResult( 0 ), myId( id ) {}
2539 virtual void Execute()
2541 LightApp_Module* module = getActiveModule();
2543 myResult = (QAction*)module->action( myId );
2546 QAction* SalomePyQt::action( const int id )
2548 return ProcessEvent( new TActionEvent( id ) );
2552 \fn int SalomePyQt::actionId( const QAction* a );
2553 \brief Get an action identifier.
2554 \return action ID or -1 if action is not registered
2557 class TActionIdEvent: public SALOME_Event
2560 typedef int TResult;
2562 const QAction* myAction;
2563 TActionIdEvent( const QAction* action )
2564 : myResult( -1 ), myAction( action ) {}
2565 virtual void Execute()
2567 LightApp_Module* module = getActiveModule();
2569 myResult = module->actionId( myAction );
2572 int SalomePyQt::actionId( const QAction* a )
2574 return ProcessEvent( new TActionIdEvent( a ) );
2578 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2579 \brief Add global (not module-related) preferences group.
2580 \param label global preferences group name
2581 \return preferences group identifier
2584 class TAddGlobalPrefEvent: public SALOME_Event
2587 typedef int TResult;
2590 TAddGlobalPrefEvent( const QString& label )
2591 : myResult( -1 ), myLabel( label ) {}
2592 virtual void Execute()
2594 LightApp_Module* module = getActiveModule();
2596 LightApp_Preferences* pref = module->getApp()->preferences();
2598 myResult = pref->addPreference( myLabel, -1 );
2602 int SalomePyQt::addGlobalPreference( const QString& label )
2604 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2608 \fn int SalomePyQt::addPreference( const QString& label );
2609 \brief Add module-related preferences group.
2610 \param label preferences group name
2611 \return preferences group identifier
2614 class TAddPrefEvent: public SALOME_Event
2617 typedef int TResult;
2620 TAddPrefEvent( const QString& label )
2621 : myResult( -1 ), myLabel( label ) {}
2622 virtual void Execute()
2624 LightApp_Module* module = getActiveModule();
2626 LightApp_Preferences* pref = module->getApp()->preferences();
2628 int cId = pref->addPreference( module->moduleName(), -1 );
2630 myResult = pref->addPreference( myLabel, cId );
2635 int SalomePyQt::addPreference( const QString& label )
2637 return ProcessEvent( new TAddPrefEvent( label ) );
2641 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2642 const QString& section, const QString& param );
2643 \brief Add module-related preferences.
2644 \param label preferences group name
2645 \param pId parent preferences group id
2646 \param type preferences type
2647 \param section resources file section name
2648 \param param resources file setting name
2649 \return preferences identifier
2652 class TAddPrefParamEvent: public SALOME_Event
2655 typedef int TResult;
2662 TAddPrefParamEvent( const QString& label,
2663 const int pId, const int type,
2664 const QString& section,
2665 const QString& param )
2667 myLabel( label ), myPId( pId ), myType( type ),
2668 mySection( section ), myParam ( param ) {}
2669 virtual void Execute()
2671 LightApp_Module* module = getActiveModule();
2673 LightApp_Preferences* pref = module->getApp()->preferences();
2675 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2679 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2680 const QString& section, const QString& param )
2682 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2686 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2687 \brief Get the preferences property.
2688 \param id preferences identifier
2689 \param prop preferences property name
2690 \return preferences property value or null QVariant if property is not set
2693 class TPrefPropEvent: public SALOME_Event
2696 typedef QVariant TResult;
2700 TPrefPropEvent( const int id, const QString& prop )
2701 : myId( id ), myProp( prop ) {}
2702 virtual void Execute()
2704 LightApp_Module* module = getActiveModule();
2706 LightApp_Preferences* pref = module->getApp()->preferences();
2708 myResult = pref->itemProperty( myProp, myId );
2712 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2714 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2718 \brief Set the preferences property.
2719 \param id preferences identifier
2720 \param prop preferences property name
2721 \param var preferences property value
2723 void SalomePyQt::setPreferenceProperty( const int id,
2724 const QString& prop,
2725 const QVariant& var )
2727 class TEvent: public SALOME_Event
2733 TEvent( const int id, const QString& prop, const QVariant& var )
2734 : myId( id ), myProp( prop ), myVar( var ) {}
2735 virtual void Execute()
2737 LightApp_Module* module = getActiveModule();
2739 LightApp_Preferences* pref = module->getApp()->preferences();
2741 pref->setItemProperty( myProp, myVar, myId );
2745 ProcessVoidEvent( new TEvent( id, prop, var ) );
2749 \brief Set specific widget as a custom preferences item.
2750 \param id preferences identifier
2751 \param prop preferences property name
2752 \param widget custom widget
2754 void SalomePyQt::setPreferencePropertyWg( const int id,
2755 const QString& prop,
2756 UserDefinedContent* widget )
2758 class TEvent: public SALOME_Event
2762 UserDefinedContent* myWidget;
2764 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2765 : myId( id ), myProp( prop ), myWidget( widget ) {}
2766 virtual void Execute()
2768 LightApp_Module* module = getActiveModule();
2770 LightApp_Preferences* pref = module->getApp()->preferences();
2772 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2777 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2781 \brief Add the property value to the list of values.
2783 This method allows creating properties which are QList<QVariant>
2784 - there is no way to pass such values directly to QVariant parameter with PyQt.
2786 \param id preferences identifier
2787 \param prop preferences property name
2788 \param idx preferences property index
2789 \param var preferences property value for the index \a idx
2791 void SalomePyQt::addPreferenceProperty( const int id,
2792 const QString& prop,
2794 const QVariant& var )
2796 class TEvent: public SALOME_Event
2803 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2804 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2805 virtual void Execute()
2807 LightApp_Module* module = getActiveModule();
2809 LightApp_Preferences* pref = module->getApp()->preferences();
2811 QVariant var = pref->itemProperty( myProp, myId );
2812 if ( var.isValid() ) {
2813 if ( var.type() == QVariant::StringList ) {
2814 QStringList sl = var.toStringList();
2815 if ( myIdx >= 0 && myIdx < sl.count() )
2816 sl[myIdx] = myVar.toString();
2818 sl.append( myVar.toString() );
2819 pref->setItemProperty( myProp, sl, myId );
2821 else if ( var.type() == QVariant::List ) {
2822 QList<QVariant> vl = var.toList();
2823 if ( myIdx >= 0 && myIdx < vl.count() )
2827 pref->setItemProperty( myProp, vl, myId );
2833 pref->setItemProperty( myProp, vl, myId );
2839 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2843 \brief Put the message to the Log messages output window
2844 \param msg message text (it can be of simple rich text format)
2845 \param addSeparator boolean flag which specifies if it is necessary
2846 to separate the message with predefined separator
2848 void SalomePyQt::message( const QString& msg, bool addSeparator )
2850 class TEvent: public SALOME_Event
2855 TEvent( const QString& msg, bool addSeparator )
2856 : myMsg( msg ), myAddSep( addSeparator ) {}
2857 virtual void Execute()
2859 if ( LightApp_Application* anApp = getApplication() ) {
2860 LogWindow* lw = anApp->logWindow();
2862 lw->putMessage( myMsg, myAddSep );
2866 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2870 \brief Remove all the messages from the Log messages output window.
2872 void SalomePyQt::clearMessages()
2874 class TEvent: public SALOME_Event
2878 virtual void Execute()
2880 if ( LightApp_Application* anApp = getApplication() ) {
2881 LogWindow* lw = anApp->logWindow();
2887 ProcessVoidEvent( new TEvent() );
2891 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2892 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2893 to the image file in the specified format.
2895 For the current moment JPEG, PNG and BMP images formats are supported.
2896 The image format is defined automatically by the file name extension.
2897 By default, BMP format is used.
2899 \param filename image file name
2900 \return operation status (\c true on success)
2903 class TDumpViewEvent: public SALOME_Event
2906 typedef bool TResult;
2910 TDumpViewEvent( const QString& filename, const int id )
2911 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2912 virtual void Execute()
2914 SUIT_ViewWindow* wnd = 0;
2916 if ( LightApp_Application* anApp = getApplication() ) {
2917 SUIT_ViewManager* vm = anApp->activeViewManager();
2919 wnd = vm->getActiveView();
2921 myWndId = wnd->getId();
2924 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2927 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2928 #ifndef DISABLE_PLOT2DVIEWER
2929 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2931 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2932 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2933 qApp->processEvents();
2934 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2935 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2939 #endif // DISABLE_PLOT2DVIEWER
2940 QImage im = wnd->dumpView();
2941 if ( !im.isNull() && !myFileName.isEmpty() ) {
2942 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2943 if ( fmt == "JPG" ) fmt = "JPEG";
2944 myResult = im.save( myFileName, fmt.toLatin1() );
2949 bool SalomePyQt::dumpView( const QString& filename, const int id )
2951 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2955 \fn QList<int> SalomePyQt::getViews();
2956 \brief Get list of integer identifiers of all the currently opened views
2957 \return list of integer identifiers of all the currently opened views
2960 class TGetViews: public SALOME_Event
2963 typedef QList<int> TResult;
2966 virtual void Execute()
2969 LightApp_Application* app = getApplication();
2971 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2973 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2974 SUIT_ViewWindow* wnd;
2975 foreach ( wnd, wndlist )
2976 myResult.append( wnd->getId() );
2981 QList<int> SalomePyQt::getViews()
2983 return ProcessEvent( new TGetViews() );
2987 \fn int SalomePyQt::getActiveView();
2988 \brief Get integer identifier of the currently active view
2989 \return integer identifier of the currently active view
2992 class TGetActiveView: public SALOME_Event
2995 typedef int TResult;
2999 virtual void Execute()
3001 LightApp_Application* app = getApplication();
3003 SUIT_ViewManager* viewMgr = app->activeViewManager();
3005 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3007 myResult = wnd->getId();
3012 int SalomePyQt::getActiveView()
3014 return ProcessEvent( new TGetActiveView() );
3018 \fn QString SalomePyQt::getViewType( const int id );
3019 \brief Get type of the specified view, e.g. "OCCViewer"
3020 \param id window identifier
3024 class TGetViewType: public SALOME_Event
3027 typedef QString TResult;
3030 TGetViewType( const int id )
3032 virtual void Execute()
3034 SUIT_ViewWindow* wnd = getWnd( myWndId );
3036 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3038 myResult = viewMgr->getType();
3042 QString SalomePyQt::getViewType( const int id )
3044 return ProcessEvent( new TGetViewType( id ) );
3048 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3049 \brief Change view caption
3050 \param id window identifier
3051 \param title new window title
3052 \return \c true if operation is completed successfully and \c false otherwise
3055 class TSetViewTitle: public SALOME_Event
3058 typedef bool TResult;
3062 TSetViewTitle( const int id, const QString& title )
3063 : myResult( false ),
3066 virtual void Execute()
3068 SUIT_ViewWindow* wnd = getWnd( myWndId );
3070 wnd->setWindowTitle( myTitle );
3075 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3077 return ProcessEvent( new TSetViewTitle( id, title ) );
3081 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3082 \brief Set view size
3083 \param w window width
3084 \param h window height
3085 \param id window identifier
3086 \return \c true if operation is completed successfully and \c false otherwise
3089 class TSetViewSize: public SALOME_Event
3092 typedef bool TResult;
3097 TSetViewSize( const int w, const int h, const int id )
3098 : myResult( false ),
3102 virtual void Execute()
3104 SUIT_ViewWindow* wnd = 0;
3106 if ( LightApp_Application* anApp = getApplication() ) {
3107 SUIT_ViewManager* vm = anApp->activeViewManager();
3109 wnd = vm->getActiveView();
3113 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3116 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3118 QString type = viewMgr->getType();
3119 if ( type == "OCCViewer") {
3120 #ifndef DISABLE_OCCVIEWER
3121 // specific processing for OCC viewer:
3122 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3123 // - if there is only one sub-view active; it will be resized;
3124 // - if there are several sub-views, each of them will be resized.
3125 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3126 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3127 if ( occView && occView->getView( i ) ) {
3128 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3132 #endif // DISABLE_OCCVIEWER
3134 else if ( type == "ParaView") {
3135 #ifndef DISABLE_PVVIEWER
3136 // specific processing for ParaView viewer:
3137 // hierarchy of ParaView viewer is much complex than for usual view;
3138 // we look for sub-widget named "Viewport"
3139 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3140 if ( !lst.isEmpty() ) {
3141 lst[0]->resize( myWndWidth, myWndHeight );
3144 #endif // DISABLE_PVVIEWER
3147 if ( wnd->centralWidget() ) {
3148 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3156 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3158 return ProcessEvent( new TSetViewSize( w, h, id ) );
3162 \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3163 \brief Set view rotation point
3164 \param x coordinate X view rotation point
3165 \param y coordinate Y view rotation point
3166 \param z coordinate Z view rotation point
3167 \param id window identifier
3168 \return \c true if operation is completed successfully and \c false otherwise
3171 class TSetViewRotationPoint: public SALOME_Event
3174 typedef bool TResult;
3180 TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3181 : myResult( false ),
3186 virtual void Execute()
3188 SUIT_ViewWindow* wnd = 0;
3190 if ( LightApp_Application* anApp = getApplication() ) {
3191 SUIT_ViewManager* vm = anApp->activeViewManager();
3193 wnd = vm->getActiveView();
3197 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3200 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3202 QString type = viewMgr->getType();
3203 if ( type == "OCCViewer") {
3204 #ifndef DISABLE_OCCVIEWER
3205 // specific processing for OCC viewer:
3206 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3207 // - if there is only one sub-view active; its rotation point will be changed;
3208 // - if there are several sub-views, rotaion points of each of them will be changed.
3209 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3211 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3212 if ( occView && occView->getView( i ) ) {
3213 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3218 #endif // DISABLE_OCCVIEWER
3220 else if ( type == "VTKViewer") {
3221 #ifndef DISABLE_VTKVIEWER
3222 SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3225 double aCenter[3] = { myX, myY, myZ };
3226 vtkView->activateSetRotationSelected( (void*)aCenter );
3229 #endif // DISABLE_VTKVIEWER
3235 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3237 return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3241 \fn QString SalomePyQt::getViewTitle( const int id );
3242 \brief Get view caption
3243 \param id window identifier
3244 \return view caption
3247 class TGetViewTitle: public SALOME_Event
3250 typedef QString TResult;
3253 TGetViewTitle( const int id )
3255 virtual void Execute()
3257 SUIT_ViewWindow* wnd = getWnd( myWndId );
3259 myResult = wnd->windowTitle();
3262 QString SalomePyQt::getViewTitle( const int id )
3264 return ProcessEvent( new TGetViewTitle( id ) );
3268 \fn QList<int> SalomePyQt::findViews( const QString& type );
3269 \brief Get list of integer identifiers of all the
3270 currently opened views of the specified type
3271 \param type viewer type
3272 \return list of integer identifiers
3275 class TFindViews: public SALOME_Event
3278 typedef QList<int> TResult;
3281 TFindViews( const QString& type )
3283 virtual void Execute()
3286 LightApp_Application* app = getApplication();
3288 ViewManagerList vmList;
3289 app->viewManagers( myType, vmList );
3290 SUIT_ViewManager* viewMgr;
3291 foreach ( viewMgr, vmList ) {
3292 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3293 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3294 SUIT_ViewWindow* wnd = vec[ i ];
3297 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3298 myResult.append( wnd->getId() );
3305 QList<int> SalomePyQt::findViews( const QString& type )
3307 return ProcessEvent( new TFindViews( type ) );
3311 \fn bool SalomePyQt::activateView( const int id );
3312 \brief Activate view
3313 \param id window identifier
3314 \return \c true if operation is completed successfully and \c false otherwise
3317 class TActivateView: public SALOME_Event
3320 typedef bool TResult;
3323 TActivateView( const int id )
3324 : myResult( false ),
3326 virtual void Execute()
3328 SUIT_ViewWindow* wnd = getWnd( myWndId );
3329 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3336 bool SalomePyQt::activateView( const int id )
3338 return ProcessEvent( new TActivateView( id ) );
3342 \fn bool SalomePyQt::activateManagerAndView( const int id );
3343 \brief Activate view manager and view: useful for a view embedded in a module main Window
3344 \param id window identifier
3345 \return \c true if operation is completed successfully and \c false otherwise
3348 class TActivateViewManagerAndView: public SALOME_Event
3351 typedef bool TResult;
3354 TActivateViewManagerAndView( const int id )
3355 : myResult( false ),
3357 virtual void Execute()
3359 SUIT_ViewWindow* wnd = getWnd( myWndId );
3360 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3363 LightApp_Application* app = getApplication();
3364 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3370 bool SalomePyQt::activateViewManagerAndView( const int id )
3372 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3379 class TGetViewWidget: public SALOME_Event
3382 typedef QWidget* TResult;
3385 TGetViewWidget( const int id )
3388 virtual void Execute()
3390 SUIT_ViewWindow* wnd = getWnd( myWndId );
3392 myResult = (QWidget*)wnd;
3396 QWidget* SalomePyQt::getViewWidget( const int id)
3398 return ProcessEvent( new TGetViewWidget( id ) );
3403 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3404 \brief Create new view and activate it
3405 \param type viewer type
3409 \return integer identifier of created view (or -1 if view could not be created)
3412 class TCreateView: public SALOME_Event
3415 typedef int TResult;
3422 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3428 myDetached(detached) {}
3429 virtual void Execute()
3431 LightApp_Application* app = getApplication();
3433 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3435 QWidget* wnd = viewMgr->getActiveView();
3436 myResult = viewMgr->getActiveView()->getId();
3439 wnd->setVisible(false);
3440 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3444 if (myWidth > 0 && myHeight > 0) {
3445 #ifndef DISABLE_PLOT2DVIEWER
3446 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3447 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3448 #endif // DISABLE_PLOT2DVIEWER
3449 wnd->setGeometry( 0, 0, myWidth, myHeight );
3456 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3458 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3459 QCoreApplication::processEvents();
3464 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3465 \brief Create new view with custom widget embedded and activate it
3466 \param type viewer type
3467 \param w custom widget
3468 \return integer identifier of created view (or -1 if view could not be created)
3471 class TCreateViewWg: public SALOME_Event
3474 typedef int TResult;
3478 TCreateViewWg( const QString& theType, QWidget* w )
3482 virtual void Execute()
3484 LightApp_Application* app = getApplication();
3486 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3488 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3490 myResult = wnd->getId();
3495 int SalomePyQt::createView( const QString& type, QWidget* w )
3497 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3498 QCoreApplication::processEvents();
3503 \fn bool SalomePyQt::closeView( const int id );
3505 \param id window identifier
3506 \return \c true if operation is completed successfully and \c false otherwise
3509 class TCloseView: public SALOME_Event
3512 typedef bool TResult;
3515 TCloseView( const int id )
3516 : myResult( false ),
3518 virtual void Execute()
3520 SUIT_ViewWindow* wnd = getWnd( myWndId );
3522 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3530 bool SalomePyQt::closeView( const int id )
3532 return ProcessEvent( new TCloseView( id ) );
3536 \fn int SalomePyQt::cloneView( const int id );
3537 \brief Clone view (if this operation is supported for specified view type)
3538 \param id window identifier
3539 \return integer identifier of the cloned view or -1 or operation could not be performed
3542 class TCloneView: public SALOME_Event
3545 typedef int TResult;
3548 TCloneView( const int id )
3551 virtual void Execute()
3553 SUIT_ViewWindow* wnd = getWnd( myWndId );
3555 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3557 #ifndef DISABLE_OCCVIEWER
3558 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3559 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3560 occView->onCloneView();
3561 wnd = viewMgr->getActiveView();
3563 myResult = wnd->getId();
3565 #endif // DISABLE_OCCVIEWER
3566 #ifndef DISABLE_PLOT2DVIEWER
3567 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3568 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3569 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3570 if ( viewMgr2d && srcWnd2d ) {
3571 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3572 myResult = resWnd->getId();
3575 #endif // DISABLE_OCCVIEWER
3580 int SalomePyQt::cloneView( const int id )
3582 return ProcessEvent( new TCloneView( id ) );
3586 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3587 \brief Set view visibility.
3588 \param id window identifier
3589 \param visible new visiblity
3592 void SalomePyQt::setViewVisible( const int id, const bool visible )
3594 class TEvent: public SALOME_Event
3599 TEvent( const int id, const bool visible )
3600 : myWndId( id ), myVisible( visible ) {}
3601 virtual void Execute()
3603 SUIT_ViewWindow* wnd = getWnd( myWndId );
3604 if ( wnd ) wnd->setVisible( myVisible );
3607 ProcessVoidEvent( new TEvent( id, visible ) );
3611 \fn bool SalomePyQt::isViewVisible( const int id );
3612 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3613 \param id window identifier
3614 \return \c true if view is visible and \c false otherwise
3617 class TIsViewVisible: public SALOME_Event
3620 typedef bool TResult;
3623 TIsViewVisible( const int id )
3624 : myResult( false ),
3626 virtual void Execute()
3628 SUIT_ViewWindow* wnd = getWnd( myWndId );
3631 QWidget* p = wnd->parentWidget();
3632 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3636 bool SalomePyQt::isViewVisible( const int id )
3638 return ProcessEvent( new TIsViewVisible( id ) );
3642 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3643 \brief Set / clear view's "closable" option. By default any view is closable
3644 (i.e. can be closed by the user).
3645 \param id window identifier
3646 \param on new "closable" option's value
3649 void SalomePyQt::setViewClosable( const int id, const bool on )
3651 class TEvent: public SALOME_Event
3656 TEvent( const int id, const bool on )
3657 : myWndId( id ), myOn( on ) {}
3658 virtual void Execute()
3660 SUIT_ViewWindow* wnd = getWnd( myWndId );
3661 if ( wnd ) wnd->setClosable( myOn );
3664 ProcessVoidEvent( new TEvent( id, on ) );
3668 \fn bool SalomePyQt::isViewClosable( const int id );
3669 \brief Check whether view is closable (i.e. can be closed by the user)
3670 \param id window identifier
3671 \return \c true if view is closable or \c false otherwise
3674 class TIsViewClosable: public SALOME_Event
3677 typedef bool TResult;
3680 TIsViewClosable( const int id )
3683 virtual void Execute()
3685 SUIT_ViewWindow* wnd = getWnd( myWndId );
3687 myResult = wnd->closable();
3691 bool SalomePyQt::isViewClosable( const int id )
3693 return ProcessEvent( new TIsViewClosable( id ) );
3697 \fn bool SalomePyQt::groupAllViews();
3698 \brief Group all views to the single tab area
3699 \return \c true if operation is completed successfully and \c false otherwise
3702 class TGroupAllViews: public SALOME_Event
3705 typedef bool TResult;
3708 : myResult( false ) {}
3709 virtual void Execute()
3711 LightApp_Application* app = getApplication();
3713 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3715 QtxWorkstack* wStack = tabDesk->workstack();
3724 bool SalomePyQt::groupAllViews()
3726 return ProcessEvent( new TGroupAllViews() );
3730 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3731 \brief Split tab area to which view with identifier belongs to
3732 \param id window identifier
3733 \param ori orientation of split operation
3734 \param action action to be performed
3735 \return \c true if operation is completed successfully \c false otherwise
3738 class TSplitView: public SALOME_Event
3741 typedef bool TResult;
3746 TSplitView( const int id,
3747 const Orientation ori,
3748 const Action action )
3749 : myResult( false ),
3752 myAction( action ) {}
3753 virtual void Execute()
3755 SUIT_ViewWindow* wnd = getWnd( myWndId );
3758 // wnd->setFocus(); ???
3761 if ( getApplication() ) {
3762 STD_TabDesktop* desk =
3763 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3765 QtxWorkstack* wStack = desk->workstack();
3767 Qt::Orientation qtOri =
3768 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3770 QtxWorkstack::SplitType sType;
3771 if ( myAction == MoveWidget )
3772 sType = QtxWorkstack::SplitMove;
3773 else if ( myAction == LeaveWidget )
3774 sType = QtxWorkstack::SplitStay;
3776 sType = QtxWorkstack::SplitAt;
3778 wStack->Split( wnd, qtOri, sType );
3786 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3788 return ProcessEvent( new TSplitView( id, ori, action ) );
3792 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3793 \brief Move view with the first identifier to the same area which
3794 another view with the second identifier belongs to
3795 \param id source window identifier
3796 \param id_to destination window identifier
3797 param before specifies whether the first viewt has to be moved before or after
3799 \return \c true if operation is completed successfully and \c false otherwise
3802 class TMoveView: public SALOME_Event
3805 typedef bool TResult;
3810 TMoveView( const int id, const int id_to, const bool before )
3811 : myResult( false ),
3814 myIsBefore( before ) {}
3815 virtual void Execute()
3817 SUIT_ViewWindow* wnd = getWnd( myWndId );
3818 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3819 if ( wnd && wnd_to ) {
3820 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3821 getApplication()->desktop() )->workstack();
3823 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3827 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3829 return ProcessEvent( new TMoveView( id, id_to, before ) );
3833 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3834 \brief Get list of views identifiers that belongs to the same area as
3835 specified view (excluding it)
3836 \param id window identifier
3837 \return list of views identifiers
3840 class TNeighbourViews: public SALOME_Event
3843 typedef QList<int> TResult;
3846 TNeighbourViews( const int id )
3848 virtual void Execute()
3851 SUIT_ViewWindow* wnd = getWnd( myWndId );
3853 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3854 getApplication()->desktop() )->workstack();
3856 QWidgetList wgList = wStack->windowList( wnd );
3858 foreach ( wg, wgList ) {
3859 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3860 if ( tmpWnd && tmpWnd != wnd )
3861 myResult.append( tmpWnd->getId() );
3867 QList<int> SalomePyQt::neighbourViews( const int id )
3869 return ProcessEvent( new TNeighbourViews( id ) );
3874 \fn void SalomePyQt::createRoot();
3875 \brief Initialize root data object.
3877 Does nothing if root is already initialized.
3880 void SalomePyQt::createRoot()
3882 class TEvent: public SALOME_Event
3886 virtual void Execute()
3888 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3890 SALOME_PYQT_DataModelLight* dm =
3891 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3896 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3900 ProcessVoidEvent( new TEvent() );
3904 \fn QString SalomePyQt::createObject( const QString& parent );
3905 \brief Create empty data object
3906 \param parent entry of parent data object
3907 \return entry of created data object
3910 class TCreateEmptyObjectEvent: public SALOME_Event
3913 typedef QString TResult;
3916 TCreateEmptyObjectEvent( const QString& parent )
3917 : myParent( parent ) {}
3918 virtual void Execute()
3920 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3922 myResult = module->createObject( myParent );
3925 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3929 QString SalomePyQt::createObject( const QString& parent )
3931 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3935 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3936 const QString& tooltip,const QString& parent );
3937 \brief Create new data object with specified name, icon and tooltip
3938 \param name data object name
3939 \param icon data object icon
3940 \param toolTip data object tooltip
3941 \param parent entry of parent data object
3942 \return entry of created data object
3945 class TCreateObjectEvent: public SALOME_Event
3948 typedef QString TResult;
3954 TCreateObjectEvent( const QString& name,
3955 const QString& icon,
3956 const QString& tooltip,
3957 const QString& parent )
3960 myToolTip( tooltip ),
3961 myParent( parent ) {}
3962 virtual void Execute()
3964 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3966 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3969 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3973 QString SalomePyQt::createObject( const QString& name,
3974 const QString& icon,
3975 const QString& toolTip,
3976 const QString& parent )
3978 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3983 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3984 \brief Set data object name
3985 \param entry data object entry
3986 \param name data object name
3988 class TSetNameEvent: public SALOME_Event
3993 TSetNameEvent( const QString& entry,
3994 const QString& name )
3997 virtual void Execute()
3999 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4001 module->setName( myEntry, myName );
4004 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
4008 void SalomePyQt::setName( const QString& entry, const QString& name )
4010 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
4014 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
4015 \brief Set data object icon
4016 \param entry data object entry
4017 \param icon data object icon file name (icon is loaded from module resources)
4020 class TSetIconEvent: public SALOME_Event
4025 TSetIconEvent( const QString& entry,
4026 const QString& icon )
4029 virtual void Execute()
4031 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4033 module->setIcon( myEntry, myIcon );
4036 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4041 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4043 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4047 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4048 \brief Set data object tooltip
4049 \param entry data object entry
4050 \param toolTip data object tooltip
4053 class TSetToolTipEvent: public SALOME_Event
4058 TSetToolTipEvent( const QString& entry,
4059 const QString& toolTip )
4061 myToolTip( toolTip ) {}
4062 virtual void Execute()
4064 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4066 module->setToolTip( myEntry, myToolTip );
4069 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4073 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4075 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4079 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4080 \brief Set reference to another data object
4081 \param entry data object entry
4082 \param refEntry referenced data object entry
4085 class TSetRefEvent: public SALOME_Event
4090 TSetRefEvent( const QString& entry,
4091 const QString& refEntry )
4093 myRefEntry( refEntry ) {}
4094 virtual void Execute()
4096 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4098 module->setReference( myEntry, myRefEntry );
4101 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4105 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4107 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4111 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4112 \brief Set data object color
4113 \param entry data object entry
4114 \param color data object color
4117 class TSetColorEvent: public SALOME_Event
4122 TSetColorEvent( const QString& entry,
4123 const QColor& color )
4126 virtual void Execute()
4128 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4130 module->setColor( myEntry, myColor );
4133 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4137 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4139 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4143 \fn QString SalomePyQt::getName( const QString& entry );
4144 \brief Get data object name
4145 \param entry data object entry
4146 \return data object name
4149 class TGetNameEvent: public SALOME_Event
4152 typedef QString TResult;
4155 TGetNameEvent( const QString& entry )
4156 : myEntry( entry ) {}
4157 virtual void Execute()
4159 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4161 myResult = module->getName( myEntry );
4164 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4168 QString SalomePyQt::getName( const QString& entry )
4170 return ProcessEvent( new TGetNameEvent( entry ) );
4174 \fn QString SalomePyQt::getToolTip( const QString& entry );
4175 \brief Get data object tooltip
4176 \param entry data object entry
4177 \return data object tooltip
4180 class TGetToolTipEvent: public SALOME_Event
4183 typedef QString TResult;
4186 TGetToolTipEvent( const QString& entry )
4187 : myEntry( entry ) {}
4188 virtual void Execute()
4190 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4192 myResult = module->getToolTip( myEntry );
4195 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4199 QString SalomePyQt::getToolTip( const QString& entry )
4201 return ProcessEvent( new TGetToolTipEvent( entry ) );
4205 \fn QString SalomePyQt::getReference( const QString& entry );
4206 \brief Get entry of the referenced object (if there's any)
4207 \param entry data object entry
4208 \return referenced data object entry
4211 class TGetRefEvent: public SALOME_Event
4214 typedef QString TResult;
4217 TGetRefEvent( const QString& entry )
4218 : myEntry( entry ) {}
4219 virtual void Execute()
4221 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4223 myResult = module->getReference( myEntry );
4226 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4230 QString SalomePyQt::getReference( const QString& entry )
4232 return ProcessEvent( new TGetRefEvent( entry ) );
4236 \fn QColor SalomePyQt::getColor( const QString& entry );
4237 \brief Get data object color
4238 \param entry data object entry
4239 \return data object color
4242 class TGetColorEvent: public SALOME_Event
4245 typedef QColor TResult;
4248 TGetColorEvent( const QString& entry )
4249 : myEntry( entry ) {}
4250 virtual void Execute()
4252 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4254 myResult = module->getColor( myEntry );
4257 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4261 QColor SalomePyQt::getColor( const QString& entry )
4263 return ProcessEvent( new TGetColorEvent( entry ) );
4267 \fn void SalomePyQt::removeChildren( const QString& entry );
4268 \brief Remove all child data objects from specified data object
4269 \param entry data object entry
4272 class TRemoveChildEvent: public SALOME_Event
4276 TRemoveChildEvent( const QString& entry )
4277 : myEntry( entry ) {}
4278 virtual void Execute()
4280 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4282 module->removeChildren( myEntry );
4285 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4289 void SalomePyQt::removeChildren( const QString& entry )
4291 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4293 void SalomePyQt::removeChild( const QString& entry )
4295 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4296 removeChildren( entry );
4300 \fn void SalomePyQt::removeObject( const QString& entry );
4301 \brief Remove object by entry
4302 \param entry data object entry
4305 class TRemoveObjectEvent: public SALOME_Event
4310 TRemoveObjectEvent( const QString& entry )
4311 : myEntry( entry ) {}
4312 virtual void Execute()
4314 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4316 module->removeObject( myEntry );
4319 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4323 void SalomePyQt::removeObject( const QString& entry )
4325 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4329 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4330 \brief Get entries of all child data objects of specified data object
4331 \param entry data object entry
4332 \param recursive \c true for recursive processing
4335 class TGetChildrenEvent: public SALOME_Event
4338 typedef QStringList TResult;
4342 TGetChildrenEvent( const QString& entry, const bool recursive )
4344 myRecursive( recursive ) {}
4345 virtual void Execute()
4347 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4349 myResult = module->getChildren( myEntry, myRecursive );
4352 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4356 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4358 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4361 #ifndef DISABLE_PLOT2DVIEWER
4362 // Next set of methods relates to the Plot2d viewer functionality
4365 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4366 \brief Display theCurve in view
4367 \param id window identifier
4368 \param theCurve curve to display
4371 class TDisplayCurve: public SALOME_Event
4375 Plot2d_Curve* myCurve;
4376 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4377 virtual void Execute() {
4378 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4380 wnd->getViewFrame()->displayCurve( myCurve );
4383 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4385 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4389 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4390 \brief Erase theCurve in view
4391 \param id window identifier
4392 \param theCurve curve to erase
4395 class TEraseCurve: public SALOME_Event
4399 Plot2d_Curve* myCurve;
4400 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4401 virtual void Execute() {
4402 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4403 wnd->getViewFrame()->eraseCurve( myCurve );
4406 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4408 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4412 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4413 \brief Delete theCurve from all views
4414 \param theCurve curve to delete
4417 class TDeleteCurve: public SALOME_Event
4420 Plot2d_Curve* myCurve;
4421 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4422 virtual void Execute() {
4423 LightApp_Application* app = getApplication();
4425 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4427 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4428 SUIT_ViewWindow* wnd;
4429 foreach ( wnd, wndlist ) {
4430 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4432 aP2d->getViewFrame()->eraseObject( myCurve );
4438 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4440 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4444 \brief updateCurves (repaint) curves in view window.
4446 void SalomePyQt::updateCurves( const int id )
4448 class TEvent: public SALOME_Event
4452 TEvent( const int id ) : myWndId( id ) {}
4453 virtual void Execute()
4455 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4457 wnd->getViewFrame()->DisplayAll();
4460 ProcessVoidEvent( new TEvent( id ) );
4464 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4465 \brief Get title of corresponding type
4466 \param id window identifier
4467 \param type is type of title
4468 \return title of corresponding type
4471 class TGetPlot2dTitle: public SALOME_Event
4474 typedef QString TResult;
4478 TGetPlot2dTitle(const int id, ObjectType type) :
4481 virtual void Execute() {
4482 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4484 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4487 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4489 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4494 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4495 \brief Set title of corresponding type
4496 \param id window identifier
4498 \param type is type of title
4502 class TSetPlot2dTitle: public SALOME_Event
4506 Plot2d_Curve* myCurve;
4510 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4515 virtual void Execute() {
4516 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4517 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4520 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4522 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4526 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4527 \brief Get list of Plot2d view ranges
4528 \param id window identifier
4529 \return list of view ranges (XMin, XMax, YMin, YMax)
4532 class TFitRangeByCurves: public SALOME_Event
4535 typedef QList<double> TResult;
4538 TFitRangeByCurves( const int id )
4540 virtual void Execute()
4543 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4545 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4546 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4547 myResult.append( XMin );
4548 myResult.append( XMax );
4549 myResult.append( YMin );
4550 myResult.append( YMax );
4554 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4556 return ProcessEvent( new TFitRangeByCurves( id ) );
4560 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4561 \brief Get list of current Plot2d view ranges
4562 \param id window identifier
4563 \return list of view ranges (XMin, XMax, YMin, YMax)
4566 class TFitRangeCurrent: public SALOME_Event
4569 typedef QList<double> TResult;
4572 TFitRangeCurrent( const int id )
4574 virtual void Execute()
4577 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4579 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4580 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4581 myResult.append( XMin );
4582 myResult.append( XMax );
4583 myResult.append( YMin );
4584 myResult.append( YMax );
4588 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4590 return ProcessEvent( new TFitRangeCurrent( id ) );
4594 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4595 \brief Set range of Plot2d view
4596 \param id window identifier
4603 class TPlot2dFitRange: public SALOME_Event
4611 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4617 virtual void Execute() {
4618 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4620 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4623 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4625 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4628 // End of methods related to the Plot2d viewer functionality
4629 #endif // DISABLE_PLOT2DVIEWER
4632 \brief Process Qt event loop
4634 void SalomePyQt::processEvents()
4636 QCoreApplication::processEvents();
4640 \brief Set visibility state for given object
4641 \param theEntry study ID of the object
4642 \param theState visibility state
4644 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4646 class TEvent: public SALOME_Event
4651 TEvent( const QString& theEntry, int theState ):
4652 myEntry( theEntry ), myState( theState ) {}
4653 virtual void Execute()
4655 LightApp_Study* aStudy = getActiveStudy();
4658 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4661 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4665 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4666 \brief Get visibility state for given object
4667 \param theEntry study ID of the object
4668 \return visibility state
4671 class TGetVisibilityStateEvent: public SALOME_Event
4674 typedef int TResult;
4677 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4678 virtual void Execute()
4680 LightApp_Study* aStudy = getActiveStudy();
4682 myResult = aStudy->visibilityState( myEntry );
4685 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4687 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4691 \brief Set position of given object in the tree
4692 \param theEntry study ID of the object
4693 \param thePos position
4695 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4697 class TEvent: public SALOME_Event
4702 TEvent( const QString& theEntry, int thePos ):
4703 myEntry( theEntry ), myPos( thePos ) {}
4704 virtual void Execute()
4706 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4708 module->setObjectPosition( myEntry, myPos );
4711 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4715 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4716 \brief Get position of given object in the tree
4717 \param theEntry study ID of the object
4721 class TGetObjectPositionEvent: public SALOME_Event
4724 typedef int TResult;
4727 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4728 virtual void Execute()
4730 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4732 myResult = module->getObjectPosition( myEntry );
4735 int SalomePyQt::getObjectPosition( const QString& theEntry )
4737 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4741 \brief Start recordind a log of Python commands from embedded console
4742 \param theFileName output lof file name
4744 void SalomePyQt::startPyLog( const QString& theFileName )
4746 class TEvent: public SALOME_Event
4750 TEvent( const QString& theFileName ):
4751 myFileName( theFileName ) {}
4752 virtual void Execute()
4754 if ( getApplication() ) {
4755 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4756 if ( pyConsole ) pyConsole->startLog( myFileName );
4760 ProcessVoidEvent( new TEvent( theFileName ) );
4764 \brief Stop recordind a log of Python commands from embedded console
4766 void SalomePyQt::stopPyLog()
4768 class TEvent: public SALOME_Event
4772 virtual void Execute()
4774 if ( getApplication() ) {
4775 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4776 if ( pyConsole ) pyConsole->stopLog();
4780 ProcessVoidEvent( new TEvent() );