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 QWidget* SalomePyQt::getDesktop();
441 \brief Get the active application's desktop window.
442 \return desktop window or 0 if there is no any
445 class TGetDesktopEvent: public SALOME_Event
448 typedef QWidget* TResult;
450 TGetDesktopEvent() : myResult( 0 ) {}
451 virtual void Execute()
453 if ( getApplication() )
454 myResult = (QWidget*)( getApplication()->desktop() );
457 QWidget* SalomePyQt::getDesktop()
459 return ProcessEvent( new TGetDesktopEvent() );
463 \fn QWidget* SalomePyQt::getMainFrame();
464 \brief Get current application's main frame widget [obsolete].
466 Main frame widget is an internal widget of the application
467 desktop window (workspace).
469 \return workspace widget (0 on any error)
472 class TGetMainFrameEvent: public SALOME_Event
475 typedef QWidget* TResult;
477 TGetMainFrameEvent() : myResult( 0 ) {}
478 virtual void Execute()
480 if ( getApplication() ) {
481 SUIT_Desktop* aDesktop = getApplication()->desktop();
482 myResult = (QWidget*)( aDesktop->centralWidget() );
486 QWidget* SalomePyQt::getMainFrame()
488 return ProcessEvent( new TGetMainFrameEvent() );
492 \fn QMenuBar* SalomePyQt::getMainMenuBar();
493 \brief Get current application desktop's main menu.
494 \return main menu object (0 on any error)
497 class TGetMainMenuBarEvent: public SALOME_Event
500 typedef QMenuBar* TResult;
502 TGetMainMenuBarEvent() : myResult( 0 ) {}
503 virtual void Execute()
505 if ( LightApp_Application* anApp = getApplication() ) {
506 myResult = anApp->desktop()->menuBar();
510 QMenuBar* SalomePyQt::getMainMenuBar()
512 return ProcessEvent( new TGetMainMenuBarEvent() );
516 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
517 \brief Get main menu's child popup submenu by its identifier.
519 This function is obsolete.
520 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
522 \param menu menu identifier
523 \return popup submenu object or 0 if it does not exist
527 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
528 \brief Get main menu's child popup submenu by its name.
530 The function creates menu if it does not exist.
532 \param menu menu name
533 \return popup submenu object (0 on any error)
536 class TGetPopupMenuEvent: public SALOME_Event
539 typedef QMenu* TResult;
542 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
543 virtual void Execute()
545 LightApp_Application* anApp = getApplication();
546 if ( anApp && !myMenuName.isEmpty() ) {
547 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
548 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
553 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
558 menuName = getMenuName( "MEN_DESK_FILE" ); break;
560 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
562 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
564 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
566 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
568 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
570 menuName = getMenuName( "MEN_DESK_HELP" ); break;
572 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
574 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
576 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
580 \fn QTreeView* SalomePyQt::getObjectBrowser();
581 \brief Get object browser
582 \return object browser for the active study or 0 in case of error
585 class TGetObjectBrowserEvent: public SALOME_Event
588 typedef QTreeView* TResult;
590 TGetObjectBrowserEvent() : myResult( 0 ) {}
591 virtual void Execute()
593 LightApp_Application* anApp = getApplication();
594 if ( anApp && anApp->objectBrowser() ) {
595 myResult = anApp->objectBrowser()->treeView();
599 QTreeView* SalomePyQt::getObjectBrowser()
601 return ProcessEvent( new TGetObjectBrowserEvent() );
605 \fn SALOME_Selection* SalomePyQt::getSelection();
606 \brief Get the selection object for the current study.
608 Creates a Selection object if it has not been created yet.
610 \return selection object (0 on error)
613 class TGetSelectionEvent: public SALOME_Event
616 typedef SALOME_Selection* TResult;
618 TGetSelectionEvent() : myResult( 0 ) {}
619 virtual void Execute()
621 myResult = SALOME_Selection::GetSelection( getApplication() );
624 SALOME_Selection* SalomePyQt::getSelection()
626 return ProcessEvent( new TGetSelectionEvent() );
630 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
631 \brief Send local selection for notification.
633 The list of locally selected objects (study entries) is sent for notification of
634 other listening entities (modules, viewers...).
637 class TSetSelectionEvent: public SALOME_Event
639 QStringList myEntryList;
641 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
642 virtual void Execute()
644 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
645 if ( !module ) return;
646 module->setLocalSelected(myEntryList);
649 void SalomePyQt::setSelection( const QStringList& entryList)
651 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
655 \fn void SalomePyQt::enableSelector();
656 \brief enable PyQt_Selector (on module activation, for instance)
659 class TEnableSelectorEvent: public SALOME_Event
662 TEnableSelectorEvent() {}
663 virtual void Execute()
665 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
666 if ( !module ) return;
667 module->enableSelector();
670 void SalomePyQt::enableSelector()
672 return ProcessVoidEvent( new TEnableSelectorEvent() );
677 \fn void SalomePyQt::disableSelector();
678 \brief disable PyQt_Selector (on module activation, for instance)
681 class TdisableSelectorEvent: public SALOME_Event
684 TdisableSelectorEvent() {}
685 virtual void Execute()
687 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
688 if ( !module ) return;
689 module->disableSelector();
692 void SalomePyQt::disableSelector()
694 return ProcessVoidEvent( new TdisableSelectorEvent() );
699 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
700 \brief Put an information message to the current application's
703 Optional second delay parameter (\a sec) can be used to specify
704 time of the message diplaying in seconds. If this parameter is less
705 or equal to zero, the constant message will be put.
707 \param msg message text
708 \param sec message displaying time in seconds
711 class TPutInfoEvent: public SALOME_Event
716 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
717 virtual void Execute()
719 if ( LightApp_Application* anApp = getApplication() ) {
720 anApp->putInfo( myMsg, mySecs * 1000 );
724 void SalomePyQt::putInfo( const QString& msg, const int sec )
726 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
730 \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
731 \brief Show notification in the application's desktop window.
733 Optional third delay parameter (\a sec) can be used to specify
734 time of the notification diplaying in seconds. If this parameter is less
735 or equal to zero, the permanent notification will be put.
737 Notification can be forcibly hidden via hideNotification() method.
739 \param msg message text
740 \param title title text
741 \param sec notification displaying time in seconds
742 \return unique ID of the notification (can be used to hide notification)
743 \sa hideNotification()
746 class TShowNotifyEvent: public SALOME_Event
757 TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
758 virtual void Execute()
760 if ( LightApp_Application* anApp = getApplication() ) {
761 myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
766 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
768 return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
772 \fn void SalomePyQt::hideNotification( const QString& msg );
773 \brief Remove notification with given message text from the application's desktop.
775 \param msg message text
776 \sa showNotification()
780 \fn void SalomePyQt::hideNotification( const int id );
781 \brief Remove notification with given \a id from the application's desktop.
783 \param id notification id
784 \sa showNotification()
787 class THideNotifyEvent: public SALOME_Event
793 THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
794 THideNotifyEvent( const int id ) : myId( id ) {}
795 virtual void Execute()
797 if ( LightApp_Application* anApp = getApplication() ) {
799 anApp->hideNotification( myId );
801 anApp->hideNotification( myMsg );
806 void SalomePyQt::hideNotification( const QString& msg )
808 ProcessVoidEvent( new THideNotifyEvent( msg ) );
811 void SalomePyQt::hideNotification( const int id )
813 ProcessVoidEvent( new THideNotifyEvent( id ) );
817 \fn QStringList SalomePyQt::getComponents();
818 \brief Get all modules used in current GUI session.
819 \return List of modules
822 class TGetComponentsEvent: public SALOME_Event
825 typedef QStringList TResult;
827 TGetComponentsEvent() {}
828 virtual void Execute()
830 if ( LightApp_Application* anApp = getApplication() )
833 anApp->modules( titles, false );
834 foreach ( QString title, titles )
836 myResult << anApp->moduleName( title );
841 QStringList SalomePyQt::getComponents()
843 return ProcessEvent( new TGetComponentsEvent() );
847 \fn const QString SalomePyQt::getActiveComponent();
848 \brief Get the currently active module name (for the current study).
849 \return active module name or empty string if there is no active module
852 class TGetActiveComponentEvent: public SALOME_Event
855 typedef QString TResult;
857 TGetActiveComponentEvent() {}
858 virtual void Execute()
860 if ( LightApp_Application* anApp = getApplication() ) {
861 if ( CAM_Module* mod = anApp->activeModule() ) {
862 myResult = mod->name();
867 const QString SalomePyQt::getActiveComponent()
869 return ProcessEvent( new TGetActiveComponentEvent() );
873 \fn PyObject* SalomePyQt::getActivePythonModule();
874 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
875 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
878 class TGetActivePyModuleEvent: public SALOME_Event
881 typedef PyObject* TResult;
883 TGetActivePyModuleEvent() : myResult( Py_None ) {}
884 virtual void Execute()
886 PyModuleHelper* helper = getPythonHelper();
888 myResult = (PyObject*)helper->pythonModule();
891 PyObject* SalomePyQt::getActivePythonModule()
893 return ProcessEvent( new TGetActivePyModuleEvent() );
897 \fn bool SalomePyQt::activateModule( const QString& modName );
898 \brief Activates SALOME module with the given name
899 \return True if the module has been activated and False otherwise.
902 class TActivateModuleEvent: public SALOME_Event
905 typedef bool TResult;
907 QString myModuleName;
908 TActivateModuleEvent( const QString& modName )
909 : myResult( false ), myModuleName( modName ) {}
910 virtual void Execute()
912 if ( LightApp_Application* anApp = getApplication() ) {
913 myResult = anApp->activateModule( myModuleName );
917 bool SalomePyQt::activateModule( const QString& modName )
919 return ProcessEvent( new TActivateModuleEvent( modName ) );
923 \brief Update an Object Browser of the study.
925 void SalomePyQt::updateObjBrowser()
927 class TEvent: public SALOME_Event
931 virtual void Execute()
933 if ( SUIT_Session::session() ) {
934 if ( getActiveStudy() ) {
935 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
936 QList<SUIT_Application*>::Iterator it;
937 for( it = apps.begin(); it != apps.end(); ++it ) {
938 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
939 if ( anApp && anApp->activeStudy() ) {
940 anApp->updateObjectBrowser();
948 ProcessVoidEvent( new TEvent() );
953 SalomePyQt::isModified()
954 \return The modification status of the data model
955 for the currently active Python module
956 \note This function is supported for "light" Python-based SALOME modules only.
959 class TIsModifiedEvent: public SALOME_Event
962 typedef bool TResult;
964 TIsModifiedEvent() : myResult( false ) {}
965 virtual void Execute()
967 LightApp_Module* module = getActiveModule();
971 SALOME_PYQT_DataModelLight* aModel =
972 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
974 myResult = aModel->isModified();
977 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
981 bool SalomePyQt::isModified()
983 return ProcessEvent(new TIsModifiedEvent());
987 SalomePyQt::setModified()
989 Sets the modification status of the data model for
990 the currently active Python module. This method should be used
991 by the Python code in order to enable/disable "Save" operation
992 depending on the module's data state.
994 \note This function is supported for "light" Python-based SALOME modules only.
996 \param New modification status of the data model
1000 void SalomePyQt::setModified( bool flag )
1002 class TEvent: public SALOME_Event
1008 virtual void Execute()
1010 LightApp_Module* module = getActiveModule();
1014 SALOME_PYQT_DataModelLight* model =
1015 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1017 LightApp_Application* app = module->getApp();
1019 if ( model && app ) {
1020 model->setModified( myFlag );
1021 app->updateActions();
1024 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1028 ProcessVoidEvent( new TEvent( flag ) );
1032 \brief Add string setting to the application preferences.
1034 The parameter \a autoValue is obsolete parameter and currently is not used.
1035 This parameter will be removed in future, so try to avoid its usage in
1038 This function is obsolete. Use one of addSetting() instead.
1040 \param name setting name (it should be of kind <section:setting> where
1041 \c section is resources section name and \c setting is setting name)
1042 \param value new setting value
1043 \param autoValue (not used)
1045 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1047 class TEvent: public SALOME_Event
1053 TEvent( const QString& name, const QString& value, bool autoValue )
1054 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1055 virtual void Execute()
1057 if ( SUIT_Session::session() ) {
1058 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1059 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1060 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1061 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1062 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1063 resMgr->setValue( _sec, _nam, myValue );
1067 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1071 \brief Add integer setting to the application preferences.
1073 The parameter \a autoValue is obsolete parameter and currently is not used.
1074 This parameter will be removed in future, so try to avoid its usage in
1077 This function is obsolete. Use one of addSetting() instead.
1079 \param name setting name (it should be of kind <section:setting> where
1080 \c section is resources section name and \c setting is setting name)
1081 \param value new setting value
1082 \param autoValue (not used)
1084 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1086 class TEvent: public SALOME_Event
1092 TEvent( const QString& name, const int value, bool autoValue )
1093 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1094 virtual void Execute()
1096 if ( SUIT_Session::session() ) {
1097 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1098 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1099 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1100 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1101 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1102 resMgr->setValue( _sec, _nam, myValue );
1106 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1110 \brief Add double setting to the application preferences.
1112 The parameter \a autoValue is obsolete parameter and currently is not used.
1113 This parameter will be removed in future, so try to avoid its usage in
1116 This function is obsolete. Use one of addSetting() instead.
1118 \param name setting name (it should be of kind <section:setting> where
1119 \c section is resources section name and \c setting is setting name)
1120 \param value new setting value
1121 \param autoValue (not used)
1123 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1125 class TEvent: public SALOME_Event
1131 TEvent( const QString& name, const double value, bool autoValue )
1132 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1133 virtual void Execute()
1135 if ( SUIT_Session::session() ) {
1136 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1137 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1138 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1139 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1140 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1141 resMgr->setValue( _sec, _nam, myValue );
1145 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1149 \brief Add boolean setting to the application preferences.
1151 The parameter \a autoValue is obsolete parameter and currently is not used.
1152 This parameter will be removed in future, so try to avoid its usage in
1155 This function is obsolete. Use one of addSetting() instead.
1157 \param name setting name (it should be of kind <section:setting> where
1158 \c section is resources section name and \c setting is setting name)
1159 \param value new setting value
1160 \param autoValue (not used)
1162 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1164 class TEvent: public SALOME_Event
1170 TEvent( const QString& name, const bool value, bool autoValue )
1171 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1172 virtual void Execute()
1174 if ( SUIT_Session::session() ) {
1175 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1176 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1177 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1178 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1179 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1180 resMgr->setValue( _sec, _nam, myValue );
1184 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1188 \brief Remove setting from the application preferences.
1190 This function is obsolete. Use removeSetting() instead.
1192 \param name setting name (it should be of kind <section:setting> where
1193 \c section is resources section name and \c setting is setting name)
1195 void SalomePyQt::removeSettings( const QString& name )
1197 class TEvent: public SALOME_Event
1201 TEvent( const QString& name ) : myName( name ) {}
1202 virtual void Execute()
1204 if ( SUIT_Session::session() ) {
1205 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1206 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1207 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1208 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1209 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1210 resMgr->remove( _sec, _nam );
1214 ProcessVoidEvent( new TEvent( name ) );
1218 \fn QString SalomePyQt::getSetting( const QString& name );
1219 \brief Get application setting value (as string represenation).
1221 This function is obsolete. Use stringSetting(), integerSetting(),
1222 boolSetting(), stringSetting() or colorSetting() instead.
1224 \param name setting name (it should be of kind <section:setting> where
1225 \c section is resources section name and \c setting is setting name)
1226 \return setting name (empty string if setting name is invalid)
1229 class TGetSettingEvent: public SALOME_Event
1232 typedef QString TResult;
1235 TGetSettingEvent( const QString& name ) : myName( name ) {}
1236 virtual void Execute()
1238 if ( SUIT_Session::session() ) {
1239 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1240 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1241 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1242 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1243 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1247 QString SalomePyQt::getSetting( const QString& name )
1249 return ProcessEvent( new TGetSettingEvent( name ) );
1253 \fn QString SalomePyQt::constant( const QString& name );
1254 \brief Get constant's value from application's resource manager.
1256 \param name name of the constant
1257 \return value of the constant
1262 class TGetConstantEvent: public SALOME_Event
1265 typedef QString TResult;
1268 TGetConstantEvent( const QString& name ) : myName( name ) {}
1269 virtual void Execute()
1271 if ( SUIT_Session::session() )
1272 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1275 QString SalomePyQt::constant( const QString& name )
1277 return ProcessEvent( new TGetConstantEvent( name ) );
1281 \brief Add constant to the application's resource manager.
1283 This function is useful to specify programmatically specific
1284 variables that are referenced in the resource setting.
1286 For example, some resource value can be set as "$(myroot)/data/files".
1287 Then, "mypath" constant can be set programmatically by the application
1288 depending on run-time requirements.
1290 \param section resources file section name
1291 \param name name of the constant
1292 \param value value of the constant
1296 void SalomePyQt::setConstant( const QString& name, const QString& value )
1298 class TEvent: public SALOME_Event
1300 QString myName, myValue;
1302 TEvent( const QString& name, const QString& value )
1303 : myName( name ), myValue( value ) {}
1304 virtual void Execute()
1306 if ( SUIT_Session::session() )
1307 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1310 ProcessVoidEvent( new TEvent( name, value ) );
1314 \brief Add double setting to the application preferences.
1315 \param section resources file section name
1316 \param name setting name
1317 \param value new setting value
1319 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1321 class TEvent: public SALOME_Event
1327 TEvent( const QString& section, const QString& name, double value )
1328 : mySection( section ), myName( name ), myValue( value ) {}
1329 virtual void Execute()
1331 if ( SUIT_Session::session() ) {
1332 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1333 if ( !mySection.isEmpty() && !myName.isEmpty() )
1334 resMgr->setValue( mySection, myName, myValue );
1338 ProcessVoidEvent( new TEvent( section, name, value ) );
1342 \brief Add integer setting to the application preferences.
1343 \param section resources file section name
1344 \param name setting name
1345 \param value new setting value
1347 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1349 class TEvent: public SALOME_Event
1355 TEvent( const QString& section, const QString& name, int value )
1356 : mySection( section ), myName( name ), myValue( value ) {}
1357 virtual void Execute()
1359 if ( SUIT_Session::session() ) {
1360 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1361 if ( !mySection.isEmpty() && !myName.isEmpty() )
1362 resMgr->setValue( mySection, myName, myValue );
1366 ProcessVoidEvent( new TEvent( section, name, value ) );
1370 \brief Add boolean setting to the application preferences.
1371 \param section resources file section name
1372 \param name setting name
1373 \param value new setting value
1374 \param dumb this parameter is used in order to avoid sip compilation error
1375 because of conflicting int and bool types
1377 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1379 class TEvent: public SALOME_Event
1385 TEvent( const QString& section, const QString& name, bool value )
1386 : mySection( section ), myName( name ), myValue( value ) {}
1387 virtual void Execute()
1389 if ( SUIT_Session::session() ) {
1390 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1391 if ( !mySection.isEmpty() && !myName.isEmpty() )
1392 resMgr->setValue( mySection, myName, myValue );
1396 ProcessVoidEvent( new TEvent( section, name, value ) );
1400 \brief Add string setting to the application preferences.
1401 \param section resources file section name
1402 \param name setting name
1403 \param value new setting value
1405 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1407 class TEvent: public SALOME_Event
1413 TEvent( const QString& section, const QString& name, const QString& value )
1414 : mySection( section ), myName( name ), myValue( value ) {}
1415 virtual void Execute()
1417 if ( SUIT_Session::session() ) {
1418 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1419 if ( !mySection.isEmpty() && !myName.isEmpty() )
1420 resMgr->setValue( mySection, myName, myValue );
1424 ProcessVoidEvent( new TEvent( section, name, value ) );
1428 \brief Add color setting to the application preferences.
1429 \param section resources file section name
1430 \param name setting name
1431 \param value new setting value
1433 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1435 class TEvent: public SALOME_Event
1441 TEvent( const QString& section, const QString& name, const QColor& value )
1442 : mySection( section ), myName( name ), myValue( value ) {}
1443 virtual void Execute()
1445 if ( SUIT_Session::session() ) {
1446 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1447 if ( !mySection.isEmpty() && !myName.isEmpty() )
1448 resMgr->setValue( mySection, myName, myValue );
1452 ProcessVoidEvent( new TEvent( section, name, value ) );
1456 \brief Add byte array setting to the application preferences.
1457 \param section resources file section name
1458 \param name setting name
1459 \param value new setting value
1461 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1463 class TEvent: public SALOME_Event
1469 TEvent( const QString& section, const QString& name, const QByteArray& value )
1470 : mySection( section ), myName( name ), myValue( value ) {}
1471 virtual void Execute()
1473 if ( SUIT_Session::session() ) {
1474 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1475 if ( !mySection.isEmpty() && !myName.isEmpty() )
1476 resMgr->setValue( mySection, myName, myValue );
1480 ProcessVoidEvent( new TEvent( section, name, value ) );
1484 \brief Add font setting to the application preferences.
1485 \param section resources file section name
1486 \param name setting name
1487 \param value new setting value
1489 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1491 class TEvent: public SALOME_Event
1497 TEvent( const QString& section, const QString& name, const QFont& value )
1498 : mySection( section ), myName( name ), myValue( value ) {}
1499 virtual void Execute()
1501 if ( SUIT_Session::session() ) {
1502 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1503 if ( !mySection.isEmpty() && !myName.isEmpty() )
1504 resMgr->setValue( mySection, myName, myValue );
1508 ProcessVoidEvent( new TEvent( section, name, value ) );
1512 \fn int SalomePyQt::integerSetting( const QString& section,
1513 const QString& name,
1515 \brief Get integer setting from the application preferences.
1516 \param section resources file section name
1517 \param name setting name
1518 \param def default value which is returned if the setting is not found
1519 \return setting value
1522 class TGetIntSettingEvent: public SALOME_Event
1525 typedef int TResult;
1530 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1531 : mySection( section ), myName( name ), myDefault( def ) {}
1532 virtual void Execute()
1534 if ( SUIT_Session::session() ) {
1535 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1536 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1540 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1542 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1546 \fn double SalomePyQt::doubleSetting( const QString& section,
1547 const QString& name,
1549 \brief Get double setting from the application preferences.
1550 \param section resources file section name
1551 \param name setting name
1552 \param def default value which is returned if the setting is not found
1553 \return setting value
1556 class TGetDblSettingEvent: public SALOME_Event
1559 typedef double TResult;
1564 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1565 : mySection( section ), myName( name ), myDefault( def ) {}
1566 virtual void Execute()
1568 if ( SUIT_Session::session() ) {
1569 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1570 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1574 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1576 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1580 \fn bool SalomePyQt::boolSetting( const QString& section,
1581 const QString& name,
1583 \brief Get boolean setting from the application preferences.
1584 \param section resources file section name
1585 \param name setting name
1586 \param def default value which is returned if the setting is not found
1587 \return setting value
1590 class TGetBoolSettingEvent: public SALOME_Event
1593 typedef bool TResult;
1598 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1599 : mySection( section ), myName( name ), myDefault( def ) {}
1600 virtual void Execute()
1602 if ( SUIT_Session::session() ) {
1603 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1604 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1608 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1610 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1614 \fn QString SalomePyQt::stringSetting( const QString& section,
1615 const QString& name,
1618 \brief Get string setting from the application preferences.
1619 \param section resources file section name
1620 \param name setting name
1621 \param def default value which is returned if the setting is not found
1622 \param subst \c true to make substitution, \c false to get "raw" value
1623 \return setting value
1626 class TGetStrSettingEvent: public SALOME_Event
1629 typedef QString TResult;
1635 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1636 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1637 virtual void Execute()
1639 if ( SUIT_Session::session() ) {
1640 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1641 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1645 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1647 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1651 \fn QColor SalomePyQt::colorSetting( const QString& section,
1652 const QString& name,
1654 \brief Get color setting from the application preferences.
1655 \param section resources file section name
1656 \param name setting name
1657 \param def default value which is returned if the setting is not found
1658 \return setting value
1661 class TGetColorSettingEvent: public SALOME_Event
1664 typedef QColor TResult;
1669 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1670 : mySection( section ), myName( name ), myDefault( def ) {}
1671 virtual void Execute()
1673 if ( SUIT_Session::session() ) {
1674 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1675 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1679 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1681 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1685 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1686 const QString& name,
1687 const QByteArray& def );
1688 \brief Get byte array setting from the application preferences.
1689 \param section resources file section name
1690 \param name setting name
1691 \param def default value which is returned if the setting is not found
1692 \return setting value
1695 class TGetByteArraySettingEvent: public SALOME_Event
1698 typedef QByteArray TResult;
1703 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1704 : mySection( section ), myName( name ), myDefault( def ) {}
1705 virtual void Execute()
1707 if ( SUIT_Session::session() ) {
1708 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1709 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1713 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1715 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1719 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1720 const QString& name,
1722 \brief Get font setting from the application preferences.
1723 \param section resources file section name
1724 \param name setting name
1725 \param def default value which is returned if the setting is not found
1726 \return setting value
1729 class TGetFontSettingEvent: public SALOME_Event
1732 typedef QFont TResult;
1737 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1738 : mySection( section ), myName( name ), myDefault( def ) {}
1739 virtual void Execute()
1741 if ( SUIT_Session::session() ) {
1742 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1743 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1747 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1749 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1753 \brief Remove setting from the application preferences.
1754 \param section resources file section name
1755 \param name setting name
1757 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1759 class TEvent: public SALOME_Event
1764 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1765 virtual void Execute()
1767 if ( SUIT_Session::session() ) {
1768 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1769 if ( !mySection.isEmpty() && !myName.isEmpty() )
1770 resMgr->remove( mySection, myName );
1774 ProcessVoidEvent( new TEvent( section, name ) );
1778 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1779 \brief Check setting existence in the application preferences.
1780 \param section resources file section name
1781 \param name setting name
1782 \return \c true if setting exists
1785 class THasSettingEvent: public SALOME_Event
1788 typedef bool TResult;
1792 THasSettingEvent( const QString& section, const QString& name )
1793 : mySection( section ), myName( name ) {}
1794 virtual void Execute()
1796 if ( SUIT_Session::session() ) {
1797 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1798 myResult = resMgr->hasValue( mySection, myName );
1802 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1804 return ProcessEvent( new THasSettingEvent( section, name ) );
1808 \fn QStringList SalomePyQt::parameters( const QString& section );
1809 \brief Get names of preference items stored within the given section.
1810 \param section resources file section's name
1811 \return \c list of preferences items
1815 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1816 \brief Get names of preference items stored within the given section.
1817 \param section resources file section's name
1818 \return \c list of preferences items
1821 class TParametersEvent: public SALOME_Event
1824 typedef QStringList TResult;
1826 QStringList mySection;
1827 TParametersEvent( const QString& section )
1829 mySection << section;
1831 TParametersEvent( const QStringList& section )
1832 : mySection( section )
1834 virtual void Execute()
1836 if ( SUIT_Session::session() ) {
1837 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1838 myResult = resMgr->parameters( mySection );
1842 QStringList SalomePyQt::parameters( const QString& section )
1844 return ProcessEvent( new TParametersEvent( section ) );
1846 QStringList SalomePyQt::parameters( const QStringList& section )
1848 return ProcessEvent( new TParametersEvent( section ) );
1852 \fn QString SalomePyQt::getFileName( QWidget* parent,
1853 const QString& initial,
1854 const QStringList& filters,
1855 const QString& caption,
1857 \brief Show 'Open/Save file' dialog box for file selection
1858 and return a user's choice (selected file name).
1859 \param parent parent widget
1860 \param initial initial directory the dialog box to be opened in
1861 \param filters list of files filters (wildcards)
1862 \param caption dialog box title
1863 \param open if \c true, "Open File" dialog box is shown;
1864 otherwise "Save File" dialog box is shown
1865 \return selected file name (null string if user cancels operation)
1868 class TGetFileNameEvent: public SALOME_Event
1871 typedef QString TResult;
1875 QStringList myFilters;
1878 TGetFileNameEvent( QWidget* parent,
1879 const QString& initial,
1880 const QStringList& filters,
1881 const QString& caption,
1883 : myParent ( parent ),
1884 myInitial( initial ),
1885 myFilters( filters ),
1886 myCaption( caption ),
1888 virtual void Execute()
1890 if ( LightApp_Application* anApp = getApplication() ) {
1891 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1892 myCaption, myParent );
1896 QString SalomePyQt::getFileName( QWidget* parent,
1897 const QString& initial,
1898 const QStringList& filters,
1899 const QString& caption,
1902 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1906 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1907 const QString& initial,
1908 const QStringList& filters,
1909 const QString& caption );
1910 \brief Show 'Open files' dialog box for multiple files selection
1911 and return a user's choice (selected file names list).
1912 \param parent parent widget
1913 \param initial initial directory the dialog box to be opened in
1914 \param filters list of files filters (wildcards)
1915 \param caption dialog box title
1916 \return selected file names list (empty list if user cancels operation)
1919 class TGetOpenFileNamesEvent: public SALOME_Event
1922 typedef QStringList TResult;
1926 QStringList myFilters;
1928 TGetOpenFileNamesEvent( QWidget* parent,
1929 const QString& initial,
1930 const QStringList& filters,
1931 const QString& caption )
1932 : myParent ( parent ),
1933 myInitial( initial ),
1934 myFilters( filters ),
1935 myCaption( caption ) {}
1936 virtual void Execute()
1938 if ( LightApp_Application* anApp = getApplication() ) {
1939 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1943 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1944 const QString& initial,
1945 const QStringList& filters,
1946 const QString& caption )
1948 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1952 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1953 const QString& initial,
1954 const QString& caption );
1955 \brief Show 'Get Directory' dialog box for the directory selection
1956 and return a user's choice (selected directory name).
1957 \param parent parent widget
1958 \param initial initial directory the dialog box to be opened in
1959 \param caption dialog box title
1960 \return selected directory name (null string if user cancels operation)
1963 class TGetExistingDirectoryEvent: public SALOME_Event
1966 typedef QString TResult;
1971 TGetExistingDirectoryEvent( QWidget* parent,
1972 const QString& initial,
1973 const QString& caption )
1974 : myParent ( parent ),
1975 myInitial( initial ),
1976 myCaption( caption ) {}
1977 virtual void Execute()
1979 if ( LightApp_Application* anApp = getApplication() ) {
1980 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1984 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1985 const QString& initial,
1986 const QString& caption )
1988 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1992 \fn QString SalomePyQt::loadIcon( const QString& filename );
1993 \brief Load an icon from the module resources by the specified file name.
1994 \param fileName icon file name
1998 class TLoadIconEvent: public SALOME_Event
2001 typedef QIcon TResult;
2005 TLoadIconEvent( const QString& module, const QString& filename )
2006 : myModule( module ),
2007 myFileName ( filename ) {}
2008 virtual void Execute()
2010 myResult = loadIconInternal( myModule, myFileName );
2013 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2015 return ProcessEvent( new TLoadIconEvent( module, filename ) );
2019 \brief Open external browser to display context help information.
2022 Current implementation does nothing.
2024 \param source documentation (HTML) file name
2025 \param context context (for example, HTML ancor name)
2027 void SalomePyQt::helpContext( const QString& source, const QString& context )
2029 class TEvent: public SALOME_Event
2034 TEvent( const QString& source, const QString& context )
2035 : mySource( source ), myContext( context ) {}
2036 virtual void Execute()
2038 if ( LightApp_Application* anApp = getApplication() ) {
2039 anApp->onHelpContextModule( "", mySource, myContext );
2043 ProcessVoidEvent( new TEvent( source, context ) );
2047 \fn int SalomePyQt::defaultMenuGroup();
2048 \brief Get detault menu group identifier which can be used when
2049 creating menus (insert custom menu commands).
2050 \return default menu group ID
2053 class TDefMenuGroupEvent: public SALOME_Event
2056 typedef int TResult;
2058 TDefMenuGroupEvent() : myResult( -1 ) {}
2059 virtual void Execute()
2061 myResult = PyModuleHelper::defaultMenuGroup();
2064 int SalomePyQt::defaultMenuGroup()
2066 return ProcessEvent( new TDefMenuGroupEvent() );
2072 CrTool( const QString& tBar, const QString& nBar )
2073 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
2074 CrTool( const int id, const int tBar, const int idx )
2075 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
2076 CrTool( const int id, const QString& tBar, const int idx )
2077 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
2078 CrTool( QAction* action, const int tbId, const int id, const int idx )
2079 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
2080 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2081 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2087 if ( getActiveModule() )
2088 return getActiveModule()->createTool( myTbTitle, myTbName );
2089 else if ( getApplication() )
2090 return getApplication()->createTool( myTbTitle, myTbName );
2092 if ( getActiveModule() )
2093 return getActiveModule()->createTool( myId, myTbId, myIndex );
2094 else if ( getApplication() )
2095 return getApplication()->createTool( myId, myTbId, myIndex );
2097 if ( getActiveModule() )
2098 return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2099 else if ( getApplication() )
2100 return getApplication()->createTool( myId, myTbTitle, myIndex );
2102 if ( getActiveModule() )
2103 return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2104 else if ( getApplication() )
2105 return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2107 if ( getActiveModule() )
2108 return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2109 else if ( getApplication() )
2110 return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2124 class TCreateToolEvent: public SALOME_Event
2127 typedef int TResult;
2129 const CrTool& myCrTool;
2130 TCreateToolEvent( const CrTool& crTool )
2131 : myResult( -1 ), myCrTool( crTool ) {}
2132 virtual void Execute()
2134 myResult = myCrTool.execute();
2139 \brief Create toolbar with specified name.
2140 \param tBar toolbar title (language-dependent)
2141 \param nBar toolbar name (language-independent) [optional]
2142 \return toolbar ID or -1 if toolbar creation is failed
2144 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2146 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2150 \brief Insert action with specified \a id to the toolbar.
2152 \param tBar toolbar ID
2153 \param idx required index in the toolbar
2154 \return action ID or -1 if action could not be added
2156 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2158 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2162 \brief Insert action with specified \a id to the toolbar.
2164 \param tBar toolbar name
2165 \param idx required index in the toolbar
2166 \return action ID or -1 if action could not be added
2168 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2170 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2174 \brief Insert action to the toolbar.
2176 \param tBar toolbar ID
2177 \param id required action ID
2178 \param idx required index in the toolbar
2179 \return action ID or -1 if action could not be added
2181 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2183 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2188 \brief Clear given toolbar.
2189 \param title toolbar's title
2191 void SalomePyQt::clearTool( const QString& title )
2193 class TEvent: public SALOME_Event
2197 TEvent( const QString& title )
2198 : myTitle( title ) {}
2199 virtual void Execute()
2201 if ( getActiveModule() )
2202 return getActiveModule()->clearTool( myTitle );
2203 else if ( getApplication() )
2204 return getApplication()->clearTool( myTitle );
2207 ProcessVoidEvent( new TEvent( title ) );
2211 \brief Insert action to the toolbar.
2213 \param tBar toolbar name
2214 \param id required action ID
2215 \param idx required index in the toolbar
2216 \return action ID or -1 if action could not be added
2218 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2220 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2226 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2227 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2228 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2229 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2230 CrMenu( const int id, const int menu, const int group, const int idx )
2231 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2232 CrMenu( const int id, const QString& menu, const int group, const int idx )
2233 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2234 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2235 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2236 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2237 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2243 if ( getActiveModule() )
2244 return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2245 else if ( getApplication() )
2246 return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2248 if ( getActiveModule() )
2249 return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2250 else if ( getApplication() )
2251 return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2253 if ( getActiveModule() )
2254 return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2255 else if ( getApplication() )
2256 return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2258 if ( getActiveModule() )
2259 return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2260 else if ( getApplication() )
2261 return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2263 if ( getActiveModule() )
2264 return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2265 else if ( getApplication() )
2266 return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2268 if ( getActiveModule() )
2269 return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2270 else if ( getApplication() )
2271 return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2279 QString mySubMenuName;
2286 class TCreateMenuEvent: public SALOME_Event
2289 typedef int TResult;
2291 const CrMenu& myCrMenu;
2292 TCreateMenuEvent( const CrMenu& crMenu )
2293 : myResult( -1 ), myCrMenu( crMenu ) {}
2294 virtual void Execute()
2296 myResult = myCrMenu.execute();
2301 \brief Create main menu.
2302 \param subMenu menu name
2303 \param menu parent menu ID
2304 \param id required menu ID
2305 \param group menu group ID
2306 \param idx required index in the menu
2307 \return menu ID or -1 if menu could not be added
2309 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2311 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2315 \brief Create main menu.
2316 \param subMenu menu name
2317 \param menu parent menu name (list of menu names separated by "|")
2318 \param id required menu ID
2319 \param group menu group ID
2320 \param idx required index in the menu
2321 \return menu ID or -1 if menu could not be added
2323 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2325 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2329 \brief Insert action to the main menu.
2331 \param menu parent menu ID
2332 \param group menu group ID
2333 \param idx required index in the menu
2334 \return action ID or -1 if action could not be added
2336 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2338 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2342 \brief Insert action to the main menu.
2344 \param menu parent menu name (list of menu names separated by "|")
2345 \param group menu group ID
2346 \param idx required index in the menu
2347 \return action ID or -1 if action could not be added
2349 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2351 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2355 \brief Insert action to the main menu.
2357 \param menu parent menu ID
2358 \param group menu group ID
2359 \param idx required index in the menu
2360 \return action ID or -1 if action could not be added
2362 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2364 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2368 \brief Insert action to the main menu.
2370 \param menu parent menu name (list of menu names separated by "|")
2371 \param group menu group ID
2372 \param idx required index in the menu
2373 \return action ID or -1 if action could not be added
2375 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2377 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2381 \fn QAction* SalomePyQt::createSeparator();
2382 \brief Create separator action which can be used in the menu or toolbar.
2383 \return new separator action
2386 class TCreateSepEvent: public SALOME_Event
2389 typedef QAction* TResult;
2393 virtual void Execute()
2395 LightApp_Module* module = getActiveModule();
2397 myResult = (QAction*)module->separator();
2400 QAction* SalomePyQt::createSeparator()
2402 return ProcessEvent( new TCreateSepEvent() );
2406 \fn QAction* SalomePyQt::createAction( const int id,
2407 const QString& menuText,
2408 const QString& tipText,
2409 const QString& statusText,
2410 const QString& icon,
2412 const bool toggle );
2413 \brief Create an action which can be then used in the menu or toolbar.
2414 \param id the unique id action to be registered to
2415 \param menuText action text which should appear in menu
2416 \param tipText text which should appear in the tooltip
2417 \param statusText text which should appear in the status bar when action is activated
2418 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2419 \param key the key accelrator for the action
2420 \param toggle if \c true the action is checkable
2423 class TCreateActionEvent: public SALOME_Event
2426 typedef QAction* TResult;
2431 QString myStatusText;
2435 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2436 const QString& statusText, const QString& icon, const int key, const bool toggle )
2437 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2438 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2439 virtual void Execute()
2441 LightApp_Module* module = getActiveModule();
2443 QIcon icon = loadIconInternal( module->name(), myIcon );
2444 myResult = (QAction*)module->action( myId );
2446 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2447 myResult->setToolTip( myTipText );
2448 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2449 myResult->setText( myMenuText );
2450 if ( myResult->icon().isNull() && !icon.isNull() )
2451 myResult->setIcon( icon );
2452 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2453 myResult->setStatusTip( myStatusText );
2454 if ( myResult->shortcut().isEmpty() && myKey )
2455 myResult->setShortcut( myKey );
2456 if ( myResult->isCheckable() != myToggle )
2457 myResult->setCheckable( myToggle );
2460 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2462 // for Python module, automatically connect action to callback slot
2463 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2464 if ( helper ) helper->connectAction( myResult );
2468 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2469 const QString& tipText, const QString& statusText,
2470 const QString& icon, const int key, const bool toggle )
2472 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2476 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2477 \brief Create an action group which can be then used in the menu or toolbar
2478 \param id : the unique id action group to be registered to
2479 \param exclusive : if \c true the action group does exclusive toggling
2482 struct TCreateActionGroupEvent: public SALOME_Event
2484 typedef QtxActionGroup* TResult;
2488 TCreateActionGroupEvent( const int id, const bool exclusive )
2489 : myId( id ), myExclusive( exclusive ) {}
2490 virtual void Execute()
2492 LightApp_Module* module = getActiveModule();
2494 myResult = module->createActionGroup( myId, myExclusive );
2497 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2499 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2503 \fn QAction* SalomePyQt::action( const int id );
2504 \brief Get action by specified identifier.
2505 \return action or 0 if action is not registered
2508 class TActionEvent: public SALOME_Event
2511 typedef QAction* TResult;
2514 TActionEvent( const int id )
2515 : myResult( 0 ), myId( id ) {}
2516 virtual void Execute()
2518 LightApp_Module* module = getActiveModule();
2520 myResult = (QAction*)module->action( myId );
2523 QAction* SalomePyQt::action( const int id )
2525 return ProcessEvent( new TActionEvent( id ) );
2529 \fn int SalomePyQt::actionId( const QAction* a );
2530 \brief Get an action identifier.
2531 \return action ID or -1 if action is not registered
2534 class TActionIdEvent: public SALOME_Event
2537 typedef int TResult;
2539 const QAction* myAction;
2540 TActionIdEvent( const QAction* action )
2541 : myResult( -1 ), myAction( action ) {}
2542 virtual void Execute()
2544 LightApp_Module* module = getActiveModule();
2546 myResult = module->actionId( myAction );
2549 int SalomePyQt::actionId( const QAction* a )
2551 return ProcessEvent( new TActionIdEvent( a ) );
2555 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2556 \brief Add global (not module-related) preferences group.
2557 \param label global preferences group name
2558 \return preferences group identifier
2561 class TAddGlobalPrefEvent: public SALOME_Event
2564 typedef int TResult;
2567 TAddGlobalPrefEvent( const QString& label )
2568 : myResult( -1 ), myLabel( label ) {}
2569 virtual void Execute()
2571 LightApp_Module* module = getActiveModule();
2573 LightApp_Preferences* pref = module->getApp()->preferences();
2575 myResult = pref->addPreference( myLabel, -1 );
2579 int SalomePyQt::addGlobalPreference( const QString& label )
2581 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2585 \fn int SalomePyQt::addPreference( const QString& label );
2586 \brief Add module-related preferences group.
2587 \param label preferences group name
2588 \return preferences group identifier
2591 class TAddPrefEvent: public SALOME_Event
2594 typedef int TResult;
2597 TAddPrefEvent( const QString& label )
2598 : myResult( -1 ), myLabel( label ) {}
2599 virtual void Execute()
2601 LightApp_Module* module = getActiveModule();
2603 LightApp_Preferences* pref = module->getApp()->preferences();
2605 int cId = pref->addPreference( module->moduleName(), -1 );
2607 myResult = pref->addPreference( myLabel, cId );
2612 int SalomePyQt::addPreference( const QString& label )
2614 return ProcessEvent( new TAddPrefEvent( label ) );
2618 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2619 const QString& section, const QString& param );
2620 \brief Add module-related preferences.
2621 \param label preferences group name
2622 \param pId parent preferences group id
2623 \param type preferences type
2624 \param section resources file section name
2625 \param param resources file setting name
2626 \return preferences identifier
2629 class TAddPrefParamEvent: public SALOME_Event
2632 typedef int TResult;
2639 TAddPrefParamEvent( const QString& label,
2640 const int pId, const int type,
2641 const QString& section,
2642 const QString& param )
2644 myLabel( label ), myPId( pId ), myType( type ),
2645 mySection( section ), myParam ( param ) {}
2646 virtual void Execute()
2648 LightApp_Module* module = getActiveModule();
2650 LightApp_Preferences* pref = module->getApp()->preferences();
2652 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2656 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2657 const QString& section, const QString& param )
2659 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2663 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2664 \brief Get the preferences property.
2665 \param id preferences identifier
2666 \param prop preferences property name
2667 \return preferences property value or null QVariant if property is not set
2670 class TPrefPropEvent: public SALOME_Event
2673 typedef QVariant TResult;
2677 TPrefPropEvent( const int id, const QString& prop )
2678 : myId( id ), myProp( prop ) {}
2679 virtual void Execute()
2681 LightApp_Module* module = getActiveModule();
2683 LightApp_Preferences* pref = module->getApp()->preferences();
2685 myResult = pref->itemProperty( myProp, myId );
2689 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2691 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2695 \brief Set the preferences property.
2696 \param id preferences identifier
2697 \param prop preferences property name
2698 \param var preferences property value
2700 void SalomePyQt::setPreferenceProperty( const int id,
2701 const QString& prop,
2702 const QVariant& var )
2704 class TEvent: public SALOME_Event
2710 TEvent( const int id, const QString& prop, const QVariant& var )
2711 : myId( id ), myProp( prop ), myVar( var ) {}
2712 virtual void Execute()
2714 LightApp_Module* module = getActiveModule();
2716 LightApp_Preferences* pref = module->getApp()->preferences();
2718 pref->setItemProperty( myProp, myVar, myId );
2722 ProcessVoidEvent( new TEvent( id, prop, var ) );
2726 \brief Set specific widget as a custom preferences item.
2727 \param id preferences identifier
2728 \param prop preferences property name
2729 \param widget custom widget
2731 void SalomePyQt::setPreferencePropertyWg( const int id,
2732 const QString& prop,
2733 UserDefinedContent* widget )
2735 class TEvent: public SALOME_Event
2739 UserDefinedContent* myWidget;
2741 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2742 : myId( id ), myProp( prop ), myWidget( widget ) {}
2743 virtual void Execute()
2745 LightApp_Module* module = getActiveModule();
2747 LightApp_Preferences* pref = module->getApp()->preferences();
2749 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2754 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2758 \brief Add the property value to the list of values.
2760 This method allows creating properties which are QList<QVariant>
2761 - there is no way to pass such values directly to QVariant parameter with PyQt.
2763 \param id preferences identifier
2764 \param prop preferences property name
2765 \param idx preferences property index
2766 \param var preferences property value for the index \a idx
2768 void SalomePyQt::addPreferenceProperty( const int id,
2769 const QString& prop,
2771 const QVariant& var )
2773 class TEvent: public SALOME_Event
2780 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2781 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2782 virtual void Execute()
2784 LightApp_Module* module = getActiveModule();
2786 LightApp_Preferences* pref = module->getApp()->preferences();
2788 QVariant var = pref->itemProperty( myProp, myId );
2789 if ( var.isValid() ) {
2790 if ( var.type() == QVariant::StringList ) {
2791 QStringList sl = var.toStringList();
2792 if ( myIdx >= 0 && myIdx < sl.count() )
2793 sl[myIdx] = myVar.toString();
2795 sl.append( myVar.toString() );
2796 pref->setItemProperty( myProp, sl, myId );
2798 else if ( var.type() == QVariant::List ) {
2799 QList<QVariant> vl = var.toList();
2800 if ( myIdx >= 0 && myIdx < vl.count() )
2804 pref->setItemProperty( myProp, vl, myId );
2810 pref->setItemProperty( myProp, vl, myId );
2816 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2820 \brief Put the message to the Log messages output window
2821 \param msg message text (it can be of simple rich text format)
2822 \param addSeparator boolean flag which specifies if it is necessary
2823 to separate the message with predefined separator
2825 void SalomePyQt::message( const QString& msg, bool addSeparator )
2827 class TEvent: public SALOME_Event
2832 TEvent( const QString& msg, bool addSeparator )
2833 : myMsg( msg ), myAddSep( addSeparator ) {}
2834 virtual void Execute()
2836 if ( LightApp_Application* anApp = getApplication() ) {
2837 LogWindow* lw = anApp->logWindow();
2839 lw->putMessage( myMsg, myAddSep );
2843 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2847 \brief Remove all the messages from the Log messages output window.
2849 void SalomePyQt::clearMessages()
2851 class TEvent: public SALOME_Event
2855 virtual void Execute()
2857 if ( LightApp_Application* anApp = getApplication() ) {
2858 LogWindow* lw = anApp->logWindow();
2864 ProcessVoidEvent( new TEvent() );
2868 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2869 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2870 to the image file in the specified format.
2872 For the current moment JPEG, PNG and BMP images formats are supported.
2873 The image format is defined automatically by the file name extension.
2874 By default, BMP format is used.
2876 \param filename image file name
2877 \return operation status (\c true on success)
2880 class TDumpViewEvent: public SALOME_Event
2883 typedef bool TResult;
2887 TDumpViewEvent( const QString& filename, const int id )
2888 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2889 virtual void Execute()
2891 SUIT_ViewWindow* wnd = 0;
2893 if ( LightApp_Application* anApp = getApplication() ) {
2894 SUIT_ViewManager* vm = anApp->activeViewManager();
2896 wnd = vm->getActiveView();
2898 myWndId = wnd->getId();
2901 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2904 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2905 #ifndef DISABLE_PLOT2DVIEWER
2906 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2908 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2909 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2910 qApp->processEvents();
2911 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2912 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2916 #endif // DISABLE_PLOT2DVIEWER
2917 QImage im = wnd->dumpView();
2918 if ( !im.isNull() && !myFileName.isEmpty() ) {
2919 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2920 if ( fmt == "JPG" ) fmt = "JPEG";
2921 myResult = im.save( myFileName, fmt.toLatin1() );
2926 bool SalomePyQt::dumpView( const QString& filename, const int id )
2928 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2932 \fn QList<int> SalomePyQt::getViews();
2933 \brief Get list of integer identifiers of all the currently opened views
2934 \return list of integer identifiers of all the currently opened views
2937 class TGetViews: public SALOME_Event
2940 typedef QList<int> TResult;
2943 virtual void Execute()
2946 LightApp_Application* app = getApplication();
2948 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2950 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2951 SUIT_ViewWindow* wnd;
2952 foreach ( wnd, wndlist )
2953 myResult.append( wnd->getId() );
2958 QList<int> SalomePyQt::getViews()
2960 return ProcessEvent( new TGetViews() );
2964 \fn int SalomePyQt::getActiveView();
2965 \brief Get integer identifier of the currently active view
2966 \return integer identifier of the currently active view
2969 class TGetActiveView: public SALOME_Event
2972 typedef int TResult;
2976 virtual void Execute()
2978 LightApp_Application* app = getApplication();
2980 SUIT_ViewManager* viewMgr = app->activeViewManager();
2982 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2984 myResult = wnd->getId();
2989 int SalomePyQt::getActiveView()
2991 return ProcessEvent( new TGetActiveView() );
2995 \fn QString SalomePyQt::getViewType( const int id );
2996 \brief Get type of the specified view, e.g. "OCCViewer"
2997 \param id window identifier
3001 class TGetViewType: public SALOME_Event
3004 typedef QString TResult;
3007 TGetViewType( const int id )
3009 virtual void Execute()
3011 SUIT_ViewWindow* wnd = getWnd( myWndId );
3013 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3015 myResult = viewMgr->getType();
3019 QString SalomePyQt::getViewType( const int id )
3021 return ProcessEvent( new TGetViewType( id ) );
3025 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3026 \brief Change view caption
3027 \param id window identifier
3028 \param title new window title
3029 \return \c true if operation is completed successfully and \c false otherwise
3032 class TSetViewTitle: public SALOME_Event
3035 typedef bool TResult;
3039 TSetViewTitle( const int id, const QString& title )
3040 : myResult( false ),
3043 virtual void Execute()
3045 SUIT_ViewWindow* wnd = getWnd( myWndId );
3047 wnd->setWindowTitle( myTitle );
3052 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3054 return ProcessEvent( new TSetViewTitle( id, title ) );
3058 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3059 \brief Set view size
3060 \param w window width
3061 \param h window height
3062 \param id window identifier
3063 \return \c true if operation is completed successfully and \c false otherwise
3066 class TSetViewSize: public SALOME_Event
3069 typedef bool TResult;
3074 TSetViewSize( const int w, const int h, const int id )
3075 : myResult( false ),
3079 virtual void Execute()
3081 SUIT_ViewWindow* wnd = 0;
3083 if ( LightApp_Application* anApp = getApplication() ) {
3084 SUIT_ViewManager* vm = anApp->activeViewManager();
3086 wnd = vm->getActiveView();
3090 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3093 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3095 QString type = viewMgr->getType();
3096 if ( type == "OCCViewer") {
3097 #ifndef DISABLE_OCCVIEWER
3098 // specific processing for OCC viewer:
3099 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3100 // - if there is only one sub-view active; it will be resized;
3101 // - if there are several sub-views, each of them will be resized.
3102 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3103 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3104 if ( occView && occView->getView( i ) ) {
3105 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3109 #endif // DISABLE_OCCVIEWER
3111 else if ( type == "ParaView") {
3112 #ifndef DISABLE_PVVIEWER
3113 // specific processing for ParaView viewer:
3114 // hierarchy of ParaView viewer is much complex than for usual view;
3115 // we look for sub-widget named "Viewport"
3116 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3117 if ( !lst.isEmpty() ) {
3118 lst[0]->resize( myWndWidth, myWndHeight );
3121 #endif // DISABLE_PVVIEWER
3124 if ( wnd->centralWidget() ) {
3125 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3133 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3135 return ProcessEvent( new TSetViewSize( w, h, id ) );
3139 \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3140 \brief Set view rotation point
3141 \param x coordinate X view rotation point
3142 \param y coordinate Y view rotation point
3143 \param z coordinate Z view rotation point
3144 \param id window identifier
3145 \return \c true if operation is completed successfully and \c false otherwise
3148 class TSetViewRotationPoint: public SALOME_Event
3151 typedef bool TResult;
3157 TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3158 : myResult( false ),
3163 virtual void Execute()
3165 SUIT_ViewWindow* wnd = 0;
3167 if ( LightApp_Application* anApp = getApplication() ) {
3168 SUIT_ViewManager* vm = anApp->activeViewManager();
3170 wnd = vm->getActiveView();
3174 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3177 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3179 QString type = viewMgr->getType();
3180 if ( type == "OCCViewer") {
3181 #ifndef DISABLE_OCCVIEWER
3182 // specific processing for OCC viewer:
3183 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3184 // - if there is only one sub-view active; its rotation point will be changed;
3185 // - if there are several sub-views, rotaion points of each of them will be changed.
3186 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3188 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3189 if ( occView && occView->getView( i ) ) {
3190 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3195 #endif // DISABLE_OCCVIEWER
3197 else if ( type == "VTKViewer") {
3198 #ifndef DISABLE_VTKVIEWER
3199 SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3202 double aCenter[3] = { myX, myY, myZ };
3203 vtkView->activateSetRotationSelected( (void*)aCenter );
3206 #endif // DISABLE_VTKVIEWER
3212 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3214 return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3218 \fn QString SalomePyQt::getViewTitle( const int id );
3219 \brief Get view caption
3220 \param id window identifier
3221 \return view caption
3224 class TGetViewTitle: public SALOME_Event
3227 typedef QString TResult;
3230 TGetViewTitle( const int id )
3232 virtual void Execute()
3234 SUIT_ViewWindow* wnd = getWnd( myWndId );
3236 myResult = wnd->windowTitle();
3239 QString SalomePyQt::getViewTitle( const int id )
3241 return ProcessEvent( new TGetViewTitle( id ) );
3245 \fn QList<int> SalomePyQt::findViews( const QString& type );
3246 \brief Get list of integer identifiers of all the
3247 currently opened views of the specified type
3248 \param type viewer type
3249 \return list of integer identifiers
3252 class TFindViews: public SALOME_Event
3255 typedef QList<int> TResult;
3258 TFindViews( const QString& type )
3260 virtual void Execute()
3263 LightApp_Application* app = getApplication();
3265 ViewManagerList vmList;
3266 app->viewManagers( myType, vmList );
3267 SUIT_ViewManager* viewMgr;
3268 foreach ( viewMgr, vmList ) {
3269 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3270 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3271 SUIT_ViewWindow* wnd = vec[ i ];
3274 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3275 myResult.append( wnd->getId() );
3282 QList<int> SalomePyQt::findViews( const QString& type )
3284 return ProcessEvent( new TFindViews( type ) );
3288 \fn bool SalomePyQt::activateView( const int id );
3289 \brief Activate view
3290 \param id window identifier
3291 \return \c true if operation is completed successfully and \c false otherwise
3294 class TActivateView: public SALOME_Event
3297 typedef bool TResult;
3300 TActivateView( const int id )
3301 : myResult( false ),
3303 virtual void Execute()
3305 SUIT_ViewWindow* wnd = getWnd( myWndId );
3306 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3313 bool SalomePyQt::activateView( const int id )
3315 return ProcessEvent( new TActivateView( id ) );
3319 \fn bool SalomePyQt::activateManagerAndView( const int id );
3320 \brief Activate view manager and view: useful for a view embedded in a module main Window
3321 \param id window identifier
3322 \return \c true if operation is completed successfully and \c false otherwise
3325 class TActivateViewManagerAndView: public SALOME_Event
3328 typedef bool TResult;
3331 TActivateViewManagerAndView( const int id )
3332 : myResult( false ),
3334 virtual void Execute()
3336 SUIT_ViewWindow* wnd = getWnd( myWndId );
3337 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3340 LightApp_Application* app = getApplication();
3341 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3347 bool SalomePyQt::activateViewManagerAndView( const int id )
3349 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3356 class TGetViewWidget: public SALOME_Event
3359 typedef QWidget* TResult;
3362 TGetViewWidget( const int id )
3365 virtual void Execute()
3367 SUIT_ViewWindow* wnd = getWnd( myWndId );
3369 myResult = (QWidget*)wnd;
3373 QWidget* SalomePyQt::getViewWidget( const int id)
3375 return ProcessEvent( new TGetViewWidget( id ) );
3380 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3381 \brief Create new view and activate it
3382 \param type viewer type
3386 \return integer identifier of created view (or -1 if view could not be created)
3389 class TCreateView: public SALOME_Event
3392 typedef int TResult;
3399 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3405 myDetached(detached) {}
3406 virtual void Execute()
3408 LightApp_Application* app = getApplication();
3410 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3412 QWidget* wnd = viewMgr->getActiveView();
3413 myResult = viewMgr->getActiveView()->getId();
3416 wnd->setVisible(false);
3417 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3421 if (myWidth > 0 && myHeight > 0) {
3422 #ifndef DISABLE_PLOT2DVIEWER
3423 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3424 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3425 #endif // DISABLE_PLOT2DVIEWER
3426 wnd->setGeometry( 0, 0, myWidth, myHeight );
3433 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3435 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3436 QCoreApplication::processEvents();
3441 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3442 \brief Create new view with custom widget embedded and activate it
3443 \param type viewer type
3444 \param w custom widget
3445 \return integer identifier of created view (or -1 if view could not be created)
3448 class TCreateViewWg: public SALOME_Event
3451 typedef int TResult;
3455 TCreateViewWg( const QString& theType, QWidget* w )
3459 virtual void Execute()
3461 LightApp_Application* app = getApplication();
3463 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3465 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3467 myResult = wnd->getId();
3472 int SalomePyQt::createView( const QString& type, QWidget* w )
3474 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3475 QCoreApplication::processEvents();
3480 \fn bool SalomePyQt::closeView( const int id );
3482 \param id window identifier
3483 \return \c true if operation is completed successfully and \c false otherwise
3486 class TCloseView: public SALOME_Event
3489 typedef bool TResult;
3492 TCloseView( const int id )
3493 : myResult( false ),
3495 virtual void Execute()
3497 SUIT_ViewWindow* wnd = getWnd( myWndId );
3499 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3507 bool SalomePyQt::closeView( const int id )
3509 return ProcessEvent( new TCloseView( id ) );
3513 \fn int SalomePyQt::cloneView( const int id );
3514 \brief Clone view (if this operation is supported for specified view type)
3515 \param id window identifier
3516 \return integer identifier of the cloned view or -1 or operation could not be performed
3519 class TCloneView: public SALOME_Event
3522 typedef int TResult;
3525 TCloneView( const int id )
3528 virtual void Execute()
3530 SUIT_ViewWindow* wnd = getWnd( myWndId );
3532 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3534 #ifndef DISABLE_OCCVIEWER
3535 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3536 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3537 occView->onCloneView();
3538 wnd = viewMgr->getActiveView();
3540 myResult = wnd->getId();
3542 #endif // DISABLE_OCCVIEWER
3543 #ifndef DISABLE_PLOT2DVIEWER
3544 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3545 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3546 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3547 if ( viewMgr2d && srcWnd2d ) {
3548 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3549 myResult = resWnd->getId();
3552 #endif // DISABLE_OCCVIEWER
3557 int SalomePyQt::cloneView( const int id )
3559 return ProcessEvent( new TCloneView( id ) );
3563 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3564 \brief Set view visibility.
3565 \param id window identifier
3566 \param visible new visiblity
3569 void SalomePyQt::setViewVisible( const int id, const bool visible )
3571 class TEvent: public SALOME_Event
3576 TEvent( const int id, const bool visible )
3577 : myWndId( id ), myVisible( visible ) {}
3578 virtual void Execute()
3580 SUIT_ViewWindow* wnd = getWnd( myWndId );
3581 if ( wnd ) wnd->setVisible( myVisible );
3584 ProcessVoidEvent( new TEvent( id, visible ) );
3588 \fn bool SalomePyQt::isViewVisible( const int id );
3589 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3590 \param id window identifier
3591 \return \c true if view is visible and \c false otherwise
3594 class TIsViewVisible: public SALOME_Event
3597 typedef bool TResult;
3600 TIsViewVisible( const int id )
3601 : myResult( false ),
3603 virtual void Execute()
3605 SUIT_ViewWindow* wnd = getWnd( myWndId );
3608 QWidget* p = wnd->parentWidget();
3609 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3613 bool SalomePyQt::isViewVisible( const int id )
3615 return ProcessEvent( new TIsViewVisible( id ) );
3619 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3620 \brief Set / clear view's "closable" option. By default any view is closable
3621 (i.e. can be closed by the user).
3622 \param id window identifier
3623 \param on new "closable" option's value
3626 void SalomePyQt::setViewClosable( const int id, const bool on )
3628 class TEvent: public SALOME_Event
3633 TEvent( const int id, const bool on )
3634 : myWndId( id ), myOn( on ) {}
3635 virtual void Execute()
3637 SUIT_ViewWindow* wnd = getWnd( myWndId );
3638 if ( wnd ) wnd->setClosable( myOn );
3641 ProcessVoidEvent( new TEvent( id, on ) );
3645 \fn bool SalomePyQt::isViewClosable( const int id );
3646 \brief Check whether view is closable (i.e. can be closed by the user)
3647 \param id window identifier
3648 \return \c true if view is closable or \c false otherwise
3651 class TIsViewClosable: public SALOME_Event
3654 typedef bool TResult;
3657 TIsViewClosable( const int id )
3660 virtual void Execute()
3662 SUIT_ViewWindow* wnd = getWnd( myWndId );
3664 myResult = wnd->closable();
3668 bool SalomePyQt::isViewClosable( const int id )
3670 return ProcessEvent( new TIsViewClosable( id ) );
3674 \fn bool SalomePyQt::groupAllViews();
3675 \brief Group all views to the single tab area
3676 \return \c true if operation is completed successfully and \c false otherwise
3679 class TGroupAllViews: public SALOME_Event
3682 typedef bool TResult;
3685 : myResult( false ) {}
3686 virtual void Execute()
3688 LightApp_Application* app = getApplication();
3690 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3692 QtxWorkstack* wStack = tabDesk->workstack();
3701 bool SalomePyQt::groupAllViews()
3703 return ProcessEvent( new TGroupAllViews() );
3707 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3708 \brief Split tab area to which view with identifier belongs to
3709 \param id window identifier
3710 \param ori orientation of split operation
3711 \param action action to be performed
3712 \return \c true if operation is completed successfully \c false otherwise
3715 class TSplitView: public SALOME_Event
3718 typedef bool TResult;
3723 TSplitView( const int id,
3724 const Orientation ori,
3725 const Action action )
3726 : myResult( false ),
3729 myAction( action ) {}
3730 virtual void Execute()
3732 SUIT_ViewWindow* wnd = getWnd( myWndId );
3735 // wnd->setFocus(); ???
3738 if ( getApplication() ) {
3739 STD_TabDesktop* desk =
3740 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3742 QtxWorkstack* wStack = desk->workstack();
3744 Qt::Orientation qtOri =
3745 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3747 QtxWorkstack::SplitType sType;
3748 if ( myAction == MoveWidget )
3749 sType = QtxWorkstack::SplitMove;
3750 else if ( myAction == LeaveWidget )
3751 sType = QtxWorkstack::SplitStay;
3753 sType = QtxWorkstack::SplitAt;
3755 wStack->Split( wnd, qtOri, sType );
3763 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3765 return ProcessEvent( new TSplitView( id, ori, action ) );
3769 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3770 \brief Move view with the first identifier to the same area which
3771 another view with the second identifier belongs to
3772 \param id source window identifier
3773 \param id_to destination window identifier
3774 param before specifies whether the first viewt has to be moved before or after
3776 \return \c true if operation is completed successfully and \c false otherwise
3779 class TMoveView: public SALOME_Event
3782 typedef bool TResult;
3787 TMoveView( const int id, const int id_to, const bool before )
3788 : myResult( false ),
3791 myIsBefore( before ) {}
3792 virtual void Execute()
3794 SUIT_ViewWindow* wnd = getWnd( myWndId );
3795 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3796 if ( wnd && wnd_to ) {
3797 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3798 getApplication()->desktop() )->workstack();
3800 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3804 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3806 return ProcessEvent( new TMoveView( id, id_to, before ) );
3810 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3811 \brief Get list of views identifiers that belongs to the same area as
3812 specified view (excluding it)
3813 \param id window identifier
3814 \return list of views identifiers
3817 class TNeighbourViews: public SALOME_Event
3820 typedef QList<int> TResult;
3823 TNeighbourViews( const int id )
3825 virtual void Execute()
3828 SUIT_ViewWindow* wnd = getWnd( myWndId );
3830 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3831 getApplication()->desktop() )->workstack();
3833 QWidgetList wgList = wStack->windowList( wnd );
3835 foreach ( wg, wgList ) {
3836 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3837 if ( tmpWnd && tmpWnd != wnd )
3838 myResult.append( tmpWnd->getId() );
3844 QList<int> SalomePyQt::neighbourViews( const int id )
3846 return ProcessEvent( new TNeighbourViews( id ) );
3851 \fn void SalomePyQt::createRoot();
3852 \brief Initialize root data object.
3854 Does nothing if root is already initialized.
3857 void SalomePyQt::createRoot()
3859 class TEvent: public SALOME_Event
3863 virtual void Execute()
3865 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3867 SALOME_PYQT_DataModelLight* dm =
3868 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3873 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3877 ProcessVoidEvent( new TEvent() );
3881 \fn QString SalomePyQt::createObject( const QString& parent );
3882 \brief Create empty data object
3883 \param parent entry of parent data object
3884 \return entry of created data object
3887 class TCreateEmptyObjectEvent: public SALOME_Event
3890 typedef QString TResult;
3893 TCreateEmptyObjectEvent( const QString& parent )
3894 : myParent( parent ) {}
3895 virtual void Execute()
3897 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3899 myResult = module->createObject( myParent );
3902 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3906 QString SalomePyQt::createObject( const QString& parent )
3908 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3912 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3913 const QString& tooltip,const QString& parent );
3914 \brief Create new data object with specified name, icon and tooltip
3915 \param name data object name
3916 \param icon data object icon
3917 \param toolTip data object tooltip
3918 \param parent entry of parent data object
3919 \return entry of created data object
3922 class TCreateObjectEvent: public SALOME_Event
3925 typedef QString TResult;
3931 TCreateObjectEvent( const QString& name,
3932 const QString& icon,
3933 const QString& tooltip,
3934 const QString& parent )
3937 myToolTip( tooltip ),
3938 myParent( parent ) {}
3939 virtual void Execute()
3941 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3943 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3946 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3950 QString SalomePyQt::createObject( const QString& name,
3951 const QString& icon,
3952 const QString& toolTip,
3953 const QString& parent )
3955 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3960 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3961 \brief Set data object name
3962 \param entry data object entry
3963 \param name data object name
3965 class TSetNameEvent: public SALOME_Event
3970 TSetNameEvent( const QString& entry,
3971 const QString& name )
3974 virtual void Execute()
3976 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3978 module->setName( myEntry, myName );
3981 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3985 void SalomePyQt::setName( const QString& entry, const QString& name )
3987 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3991 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3992 \brief Set data object icon
3993 \param entry data object entry
3994 \param icon data object icon file name (icon is loaded from module resources)
3997 class TSetIconEvent: public SALOME_Event
4002 TSetIconEvent( const QString& entry,
4003 const QString& icon )
4006 virtual void Execute()
4008 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4010 module->setIcon( myEntry, myIcon );
4013 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4018 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4020 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4024 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4025 \brief Set data object tooltip
4026 \param entry data object entry
4027 \param toolTip data object tooltip
4030 class TSetToolTipEvent: public SALOME_Event
4035 TSetToolTipEvent( const QString& entry,
4036 const QString& toolTip )
4038 myToolTip( toolTip ) {}
4039 virtual void Execute()
4041 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4043 module->setToolTip( myEntry, myToolTip );
4046 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4050 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4052 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4056 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4057 \brief Set reference to another data object
4058 \param entry data object entry
4059 \param refEntry referenced data object entry
4062 class TSetRefEvent: public SALOME_Event
4067 TSetRefEvent( const QString& entry,
4068 const QString& refEntry )
4070 myRefEntry( refEntry ) {}
4071 virtual void Execute()
4073 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4075 module->setReference( myEntry, myRefEntry );
4078 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4082 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4084 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4088 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4089 \brief Set data object color
4090 \param entry data object entry
4091 \param color data object color
4094 class TSetColorEvent: public SALOME_Event
4099 TSetColorEvent( const QString& entry,
4100 const QColor& color )
4103 virtual void Execute()
4105 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4107 module->setColor( myEntry, myColor );
4110 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4114 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4116 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4120 \fn QString SalomePyQt::getName( const QString& entry );
4121 \brief Get data object name
4122 \param entry data object entry
4123 \return data object name
4126 class TGetNameEvent: public SALOME_Event
4129 typedef QString TResult;
4132 TGetNameEvent( const QString& entry )
4133 : myEntry( entry ) {}
4134 virtual void Execute()
4136 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4138 myResult = module->getName( myEntry );
4141 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4145 QString SalomePyQt::getName( const QString& entry )
4147 return ProcessEvent( new TGetNameEvent( entry ) );
4151 \fn QString SalomePyQt::getToolTip( const QString& entry );
4152 \brief Get data object tooltip
4153 \param entry data object entry
4154 \return data object tooltip
4157 class TGetToolTipEvent: public SALOME_Event
4160 typedef QString TResult;
4163 TGetToolTipEvent( const QString& entry )
4164 : myEntry( entry ) {}
4165 virtual void Execute()
4167 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4169 myResult = module->getToolTip( myEntry );
4172 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4176 QString SalomePyQt::getToolTip( const QString& entry )
4178 return ProcessEvent( new TGetToolTipEvent( entry ) );
4182 \fn QString SalomePyQt::getReference( const QString& entry );
4183 \brief Get entry of the referenced object (if there's any)
4184 \param entry data object entry
4185 \return referenced data object entry
4188 class TGetRefEvent: public SALOME_Event
4191 typedef QString TResult;
4194 TGetRefEvent( const QString& entry )
4195 : myEntry( entry ) {}
4196 virtual void Execute()
4198 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4200 myResult = module->getReference( myEntry );
4203 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4207 QString SalomePyQt::getReference( const QString& entry )
4209 return ProcessEvent( new TGetRefEvent( entry ) );
4213 \fn QColor SalomePyQt::getColor( const QString& entry );
4214 \brief Get data object color
4215 \param entry data object entry
4216 \return data object color
4219 class TGetColorEvent: public SALOME_Event
4222 typedef QColor TResult;
4225 TGetColorEvent( const QString& entry )
4226 : myEntry( entry ) {}
4227 virtual void Execute()
4229 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4231 myResult = module->getColor( myEntry );
4234 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4238 QColor SalomePyQt::getColor( const QString& entry )
4240 return ProcessEvent( new TGetColorEvent( entry ) );
4244 \fn void SalomePyQt::removeChildren( const QString& entry );
4245 \brief Remove all child data objects from specified data object
4246 \param entry data object entry
4249 class TRemoveChildEvent: public SALOME_Event
4253 TRemoveChildEvent( const QString& entry )
4254 : myEntry( entry ) {}
4255 virtual void Execute()
4257 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4259 module->removeChildren( myEntry );
4262 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4266 void SalomePyQt::removeChildren( const QString& entry )
4268 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4270 void SalomePyQt::removeChild( const QString& entry )
4272 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4273 removeChildren( entry );
4277 \fn void SalomePyQt::removeObject( const QString& entry );
4278 \brief Remove object by entry
4279 \param entry data object entry
4282 class TRemoveObjectEvent: public SALOME_Event
4287 TRemoveObjectEvent( const QString& entry )
4288 : myEntry( entry ) {}
4289 virtual void Execute()
4291 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4293 module->removeObject( myEntry );
4296 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4300 void SalomePyQt::removeObject( const QString& entry )
4302 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4306 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4307 \brief Get entries of all child data objects of specified data object
4308 \param entry data object entry
4309 \param recursive \c true for recursive processing
4312 class TGetChildrenEvent: public SALOME_Event
4315 typedef QStringList TResult;
4319 TGetChildrenEvent( const QString& entry, const bool recursive )
4321 myRecursive( recursive ) {}
4322 virtual void Execute()
4324 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4326 myResult = module->getChildren( myEntry, myRecursive );
4329 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4333 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4335 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4338 #ifndef DISABLE_PLOT2DVIEWER
4339 // Next set of methods relates to the Plot2d viewer functionality
4342 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4343 \brief Display theCurve in view
4344 \param id window identifier
4345 \param theCurve curve to display
4348 class TDisplayCurve: public SALOME_Event
4352 Plot2d_Curve* myCurve;
4353 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4354 virtual void Execute() {
4355 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4357 wnd->getViewFrame()->displayCurve( myCurve );
4360 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4362 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4366 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4367 \brief Erase theCurve in view
4368 \param id window identifier
4369 \param theCurve curve to erase
4372 class TEraseCurve: public SALOME_Event
4376 Plot2d_Curve* myCurve;
4377 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4378 virtual void Execute() {
4379 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4380 wnd->getViewFrame()->eraseCurve( myCurve );
4383 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4385 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4389 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4390 \brief Delete theCurve from all views
4391 \param theCurve curve to delete
4394 class TDeleteCurve: public SALOME_Event
4397 Plot2d_Curve* myCurve;
4398 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4399 virtual void Execute() {
4400 LightApp_Application* app = getApplication();
4402 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4404 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4405 SUIT_ViewWindow* wnd;
4406 foreach ( wnd, wndlist ) {
4407 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4409 aP2d->getViewFrame()->eraseObject( myCurve );
4415 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4417 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4421 \brief updateCurves (repaint) curves in view window.
4423 void SalomePyQt::updateCurves( const int id )
4425 class TEvent: public SALOME_Event
4429 TEvent( const int id ) : myWndId( id ) {}
4430 virtual void Execute()
4432 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4434 wnd->getViewFrame()->DisplayAll();
4437 ProcessVoidEvent( new TEvent( id ) );
4441 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4442 \brief Get title of corresponding type
4443 \param id window identifier
4444 \param type is type of title
4445 \return title of corresponding type
4448 class TGetPlot2dTitle: public SALOME_Event
4451 typedef QString TResult;
4455 TGetPlot2dTitle(const int id, ObjectType type) :
4458 virtual void Execute() {
4459 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4461 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4464 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4466 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4471 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4472 \brief Set title of corresponding type
4473 \param id window identifier
4475 \param type is type of title
4479 class TSetPlot2dTitle: public SALOME_Event
4483 Plot2d_Curve* myCurve;
4487 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4492 virtual void Execute() {
4493 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4494 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4497 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4499 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4503 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4504 \brief Get list of Plot2d view ranges
4505 \param id window identifier
4506 \return list of view ranges (XMin, XMax, YMin, YMax)
4509 class TFitRangeByCurves: public SALOME_Event
4512 typedef QList<double> TResult;
4515 TFitRangeByCurves( const int id )
4517 virtual void Execute()
4520 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4522 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4523 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4524 myResult.append( XMin );
4525 myResult.append( XMax );
4526 myResult.append( YMin );
4527 myResult.append( YMax );
4531 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4533 return ProcessEvent( new TFitRangeByCurves( id ) );
4537 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4538 \brief Get list of current Plot2d view ranges
4539 \param id window identifier
4540 \return list of view ranges (XMin, XMax, YMin, YMax)
4543 class TFitRangeCurrent: public SALOME_Event
4546 typedef QList<double> TResult;
4549 TFitRangeCurrent( const int id )
4551 virtual void Execute()
4554 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4556 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4557 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4558 myResult.append( XMin );
4559 myResult.append( XMax );
4560 myResult.append( YMin );
4561 myResult.append( YMax );
4565 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4567 return ProcessEvent( new TFitRangeCurrent( id ) );
4571 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4572 \brief Set range of Plot2d view
4573 \param id window identifier
4580 class TPlot2dFitRange: public SALOME_Event
4588 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4594 virtual void Execute() {
4595 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4597 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4600 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4602 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4605 // End of methods related to the Plot2d viewer functionality
4606 #endif // DISABLE_PLOT2DVIEWER
4609 \brief Process Qt event loop
4611 void SalomePyQt::processEvents()
4613 QCoreApplication::processEvents();
4617 \brief Set visibility state for given object
4618 \param theEntry study ID of the object
4619 \param theState visibility state
4621 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4623 class TEvent: public SALOME_Event
4628 TEvent( const QString& theEntry, int theState ):
4629 myEntry( theEntry ), myState( theState ) {}
4630 virtual void Execute()
4632 LightApp_Study* aStudy = getActiveStudy();
4635 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4638 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4642 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4643 \brief Get visibility state for given object
4644 \param theEntry study ID of the object
4645 \return visibility state
4648 class TGetVisibilityStateEvent: public SALOME_Event
4651 typedef int TResult;
4654 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4655 virtual void Execute()
4657 LightApp_Study* aStudy = getActiveStudy();
4659 myResult = aStudy->visibilityState( myEntry );
4662 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4664 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4668 \brief Set position of given object in the tree
4669 \param theEntry study ID of the object
4670 \param thePos position
4672 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4674 class TEvent: public SALOME_Event
4679 TEvent( const QString& theEntry, int thePos ):
4680 myEntry( theEntry ), myPos( thePos ) {}
4681 virtual void Execute()
4683 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4685 module->setObjectPosition( myEntry, myPos );
4688 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4692 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4693 \brief Get position of given object in the tree
4694 \param theEntry study ID of the object
4698 class TGetObjectPositionEvent: public SALOME_Event
4701 typedef int TResult;
4704 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4705 virtual void Execute()
4707 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4709 myResult = module->getObjectPosition( myEntry );
4712 int SalomePyQt::getObjectPosition( const QString& theEntry )
4714 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4718 \brief Start recordind a log of Python commands from embedded console
4719 \param theFileName output lof file name
4721 void SalomePyQt::startPyLog( const QString& theFileName )
4723 class TEvent: public SALOME_Event
4727 TEvent( const QString& theFileName ):
4728 myFileName( theFileName ) {}
4729 virtual void Execute()
4731 if ( getApplication() ) {
4732 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4733 if ( pyConsole ) pyConsole->startLog( myFileName );
4737 ProcessVoidEvent( new TEvent( theFileName ) );
4741 \brief Stop recordind a log of Python commands from embedded console
4743 void SalomePyQt::stopPyLog()
4745 class TEvent: public SALOME_Event
4749 virtual void Execute()
4751 if ( getApplication() ) {
4752 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4753 if ( pyConsole ) pyConsole->stopLog();
4757 ProcessVoidEvent( new TEvent() );