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 "QtxInfoPanel.h"
60 #include "SALOME_Event.h"
61 #include "STD_TabDesktop.h"
62 #include "SUIT_DataBrowser.h"
63 #include "SUIT_ResourceMgr.h"
64 #include "SUIT_Session.h"
65 #include "SUIT_Tools.h"
66 #include "SUIT_ViewManager.h"
67 #include "SUIT_ViewWindow.h"
68 #include "PyConsole_Console.h"
71 #include <QApplication>
72 #include <QPaintEvent>
73 #include <QCoreApplication>
74 #include <QVBoxLayout>
76 #include <utilities.h>
81 \brief Get the currently active application.
83 \return active application object or 0 if there is no any
85 LightApp_Application* getApplication()
87 if ( SUIT_Session::session() )
88 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
93 \brief Get the currently active study.
95 \return active study or 0 if there is no study opened
97 LightApp_Study* getActiveStudy()
99 if ( getApplication() )
100 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
105 \brief Get the currently active module.
107 This function returns correct result only if Python-based
108 module is currently active. Otherwize, 0 is returned.
110 LightApp_Module* getActiveModule()
112 LightApp_Module* module = 0;
113 if ( LightApp_Application* anApp = getApplication() ) {
114 module = PyModuleHelper::getInitModule();
116 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
122 \brief Get the currently active Python module's helper.
124 This function returns correct result only if Python-based
125 module is currently active. Otherwize, 0 is returned.
127 PyModuleHelper* getPythonHelper()
129 LightApp_Module* module = getActiveModule();
130 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
135 \brief Get SALOME verbose level
137 \return \c true if SALOME debug output is allowed or \c false otherwise
141 bool isVerbose = false;
142 if ( getenv( "SALOME_VERBOSE" ) ) {
143 QString envVar = getenv( "SALOME_VERBOSE" );
145 int value = envVar.toInt( &ok );
146 isVerbose = ok && value != 0;
152 \brief Get menu item title
154 \param menuId menu identifier
155 \return menu title (localized)
157 QString getMenuName( const QString& menuId )
159 QStringList contexts;
160 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
161 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
162 QString menuName = menuId;
163 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
164 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
169 \brief Load module icon
171 \param module module name
172 \param fileName path to the icon file
175 QIcon loadIconInternal( const QString& module, const QString& fileName )
179 LightApp_Application* app = getApplication();
181 if ( app && !fileName.isEmpty() ) {
182 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
183 QApplication::translate( module.toLatin1().data(),
184 fileName.toUtf8().data() ) );
185 if ( !pixmap.isNull() )
186 icon = QIcon( pixmap );
192 \brief Gets window with specified identifier
194 \param id window identifier
195 \return pointer on the window
197 SUIT_ViewWindow* getWnd( const int id )
199 SUIT_ViewWindow* resWnd = 0;
201 LightApp_Application* app = getApplication();
203 ViewManagerList vmlist = app->viewManagers();
204 foreach( SUIT_ViewManager* vm, vmlist ) {
205 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
206 foreach ( SUIT_ViewWindow* vw, vwlist ) {
207 if ( id == vw->getId() ) {
218 \brief Map of created selection objects.
221 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
224 \brief Default resource file section name.
227 const char* DEFAULT_SECTION = "SalomePyQt";
231 \class SALOME_Selection
232 \brief The class represents selection which can be used in Python.
236 \brief Get the selection object for the specified application.
238 Finds or creates the selection object (one per study).
240 \param app application object
241 \return selection object or 0 if \a app is invalid
243 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
245 SALOME_Selection* sel = 0;
246 if ( app && SelMap.find( app ) != SelMap.end() )
249 sel = SelMap[ app ] = new SALOME_Selection( app );
256 \param p parent object
258 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
260 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
262 mySelMgr = app->selectionMgr();
263 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
264 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
271 SALOME_Selection::~SALOME_Selection()
273 LightApp_Application* app = 0;
274 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
275 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
276 if ( it.value() == this ) app = it.key();
278 if ( app ) SelMap.remove( app );
282 \brief Called when selection manager is destroyed (usually
283 when the study is closed).
285 void SALOME_Selection::onSelMgrDestroyed()
291 \brief Clear the selection.
293 void SALOME_Selection::Clear()
295 class TEvent: public SALOME_Event
297 LightApp_SelectionMgr* mySelMgr;
299 TEvent( LightApp_SelectionMgr* selMgr )
300 : mySelMgr( selMgr ) {}
301 virtual void Execute()
304 mySelMgr->clearSelected();
307 ProcessVoidEvent( new TEvent( mySelMgr ) );
311 \brief Clear the selection.
313 void SALOME_Selection::ClearIObjects()
319 Removes all selection filters.
321 void SALOME_Selection::ClearFilters()
323 class TEvent: public SALOME_Event
325 LightApp_SelectionMgr* mySelMgr;
327 TEvent( LightApp_SelectionMgr* selMgr )
328 : mySelMgr( selMgr ) {}
329 virtual void Execute()
332 mySelMgr->clearFilters();
335 ProcessVoidEvent( new TEvent( mySelMgr ) );
339 \class UserDefinedContent
340 \brief The class represents base class for user defined widget that
341 can be inserted to the Preferences dialog.
347 UserDefinedContent::UserDefinedContent()
353 \brief Called from Preferences dialog to store settings to the resource file.
355 void UserDefinedContent::store()
360 \brief Called from Preferences dialog to restore settings from the resource file.
362 void UserDefinedContent::retrieve()
367 \class SgPyQtUserDefinedContent
368 \brief A Wrapper for UserDefinedContent class.
371 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
374 SgPyQtUserDefinedContent(UserDefinedContent*);
375 virtual ~SgPyQtUserDefinedContent();
377 void store( QtxResourceMgr*, QtxPreferenceMgr* );
378 void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
381 UserDefinedContent* myContent;
385 \brief Create custom item for Preferences dialog wrapping widget passed from Python.
388 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
389 : QtxUserDefinedContent( 0 ), myContent( content )
391 QVBoxLayout* l = new QVBoxLayout( this );
392 l->setContentsMargins( 0, 0, 0, 0 );
393 l->addWidget( myContent );
400 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
405 \brief Called from Preferences dialog to store settings to the resource file.
408 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
414 \brief Called from Preferences dialog to restore settings from the resource file.
417 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
419 myContent->retrieve();
424 \brief The class provides utility functions which can be used in the Python
425 to operate with the SALOME GUI.
427 All the functionality of this class is implemented as static methods, so they
428 can be called with the class name prefixed or via creation of the class instance.
429 For example, next both ways of SalomePyQt class usage are legal:
431 from SalomePyQt import *
433 # using SalomePyQt class instance
434 desktop = sg.getDesktop()
435 # using SalomePyQt class directly
436 menubar = SalomePyQt.getMainMenuBar()
441 \fn QString SalomePyQt::getAppName();
442 \brief Get application name
443 \return application name
446 QString SalomePyQt::getAppName()
448 LightApp_Application* app = getApplication();
449 return app == 0 ? QString() : QString(app->metaObject()->className()).split("_").first();
453 \fn bool SalomePyQt::isLightApp();
454 \brief Check if SALOME GUI is running in "light" mode.
455 \return \c true if this is a "light" application; \c false otherwise
458 bool SalomePyQt::isLightApp()
460 return SalomePyQt::getAppName() != "SalomeApp";
464 \fn QWidget* SalomePyQt::getDesktop();
465 \brief Get the active application's desktop window.
466 \return desktop window or 0 if there is no any
469 class TGetDesktopEvent: public SALOME_Event
472 typedef QWidget* TResult;
474 TGetDesktopEvent() : myResult( 0 ) {}
475 virtual void Execute()
477 if ( getApplication() )
478 myResult = (QWidget*)( getApplication()->desktop() );
481 QWidget* SalomePyQt::getDesktop()
483 return ProcessEvent( new TGetDesktopEvent() );
487 \fn QWidget* SalomePyQt::getMainFrame();
488 \brief Get current application's main frame widget [obsolete].
490 Main frame widget is an internal widget of the application
491 desktop window (workspace).
493 \return workspace widget (0 on any error)
496 class TGetMainFrameEvent: public SALOME_Event
499 typedef QWidget* TResult;
501 TGetMainFrameEvent() : myResult( 0 ) {}
502 virtual void Execute()
504 if ( getApplication() ) {
505 SUIT_Desktop* aDesktop = getApplication()->desktop();
506 myResult = (QWidget*)( aDesktop->centralWidget() );
510 QWidget* SalomePyQt::getMainFrame()
512 return ProcessEvent( new TGetMainFrameEvent() );
516 \fn QMenuBar* SalomePyQt::getMainMenuBar();
517 \brief Get current application desktop's main menu.
518 \return main menu object (0 on any error)
521 class TGetMainMenuBarEvent: public SALOME_Event
524 typedef QMenuBar* TResult;
526 TGetMainMenuBarEvent() : myResult( 0 ) {}
527 virtual void Execute()
529 if ( LightApp_Application* anApp = getApplication() ) {
530 myResult = anApp->desktop()->menuBar();
534 QMenuBar* SalomePyQt::getMainMenuBar()
536 return ProcessEvent( new TGetMainMenuBarEvent() );
540 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
541 \brief Get main menu's child popup submenu by its identifier.
543 This function is obsolete.
544 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
546 \param menu menu identifier
547 \return popup submenu object or 0 if it does not exist
551 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
552 \brief Get main menu's child popup submenu by its name.
554 The function creates menu if it does not exist.
556 \param menu menu name
557 \return popup submenu object (0 on any error)
560 class TGetPopupMenuEvent: public SALOME_Event
563 typedef QMenu* TResult;
566 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
567 virtual void Execute()
569 LightApp_Application* anApp = getApplication();
570 if ( anApp && !myMenuName.isEmpty() ) {
571 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
572 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
577 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
582 menuName = getMenuName( "MEN_DESK_FILE" ); break;
584 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
586 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
588 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
590 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
592 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
594 menuName = getMenuName( "MEN_DESK_HELP" ); break;
596 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
598 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
600 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
604 \fn QTreeView* SalomePyQt::getObjectBrowser();
605 \brief Get object browser
606 \return object browser for the active study or 0 in case of error
609 class TGetObjectBrowserEvent: public SALOME_Event
612 typedef QTreeView* TResult;
614 TGetObjectBrowserEvent() : myResult( 0 ) {}
615 virtual void Execute()
617 LightApp_Application* anApp = getApplication();
618 if ( anApp && anApp->objectBrowser() ) {
619 myResult = anApp->objectBrowser()->treeView();
623 QTreeView* SalomePyQt::getObjectBrowser()
625 return ProcessEvent( new TGetObjectBrowserEvent() );
629 \fn SALOME_Selection* SalomePyQt::getSelection();
630 \brief Get the selection object for the current study.
632 Creates a Selection object if it has not been created yet.
634 \return selection object (0 on error)
637 class TGetSelectionEvent: public SALOME_Event
640 typedef SALOME_Selection* TResult;
642 TGetSelectionEvent() : myResult( 0 ) {}
643 virtual void Execute()
645 myResult = SALOME_Selection::GetSelection( getApplication() );
648 SALOME_Selection* SalomePyQt::getSelection()
650 return ProcessEvent( new TGetSelectionEvent() );
654 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
655 \brief Send local selection for notification.
657 The list of locally selected objects (study entries) is sent for notification of
658 other listening entities (modules, viewers...).
661 class TSetSelectionEvent: public SALOME_Event
663 QStringList myEntryList;
665 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
666 virtual void Execute()
668 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
669 if ( !module ) return;
670 module->setLocalSelected(myEntryList);
673 void SalomePyQt::setSelection( const QStringList& entryList)
675 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
679 \fn void SalomePyQt::enableSelector();
680 \brief enable PyQt_Selector (on module activation, for instance)
683 class TEnableSelectorEvent: public SALOME_Event
686 TEnableSelectorEvent() {}
687 virtual void Execute()
689 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
690 if ( !module ) return;
691 module->enableSelector();
694 void SalomePyQt::enableSelector()
696 return ProcessVoidEvent( new TEnableSelectorEvent() );
701 \fn void SalomePyQt::disableSelector();
702 \brief disable PyQt_Selector (on module activation, for instance)
705 class TdisableSelectorEvent: public SALOME_Event
708 TdisableSelectorEvent() {}
709 virtual void Execute()
711 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
712 if ( !module ) return;
713 module->disableSelector();
716 void SalomePyQt::disableSelector()
718 return ProcessVoidEvent( new TdisableSelectorEvent() );
723 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
724 \brief Put an information message to the current application's
727 Optional second delay parameter (\a sec) can be used to specify
728 time of the message diplaying in seconds. If this parameter is less
729 or equal to zero, the constant message will be put.
731 \param msg message text
732 \param sec message displaying time in seconds
735 class TPutInfoEvent: public SALOME_Event
740 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
741 virtual void Execute()
743 if ( LightApp_Application* anApp = getApplication() ) {
744 anApp->putInfo( myMsg, mySecs * 1000 );
748 void SalomePyQt::putInfo( const QString& msg, const int sec )
750 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
754 \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
755 \brief Show notification in the application's desktop window.
757 Optional third delay parameter (\a sec) can be used to specify
758 time of the notification diplaying in seconds. If this parameter is less
759 or equal to zero, the permanent notification will be put.
761 Notification can be forcibly hidden via hideNotification() method.
763 \param msg message text
764 \param title title text
765 \param sec notification displaying time in seconds
766 \return unique ID of the notification (can be used to hide notification)
767 \sa hideNotification()
770 class TShowNotifyEvent: public SALOME_Event
781 TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
782 virtual void Execute()
784 if ( LightApp_Application* anApp = getApplication() ) {
785 myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
790 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
792 return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
796 \fn void SalomePyQt::hideNotification( const QString& msg );
797 \brief Remove notification with given message text from the application's desktop.
799 \param msg message text
800 \sa showNotification()
804 \fn void SalomePyQt::hideNotification( const int id );
805 \brief Remove notification with given \a id from the application's desktop.
807 \param id notification id
808 \sa showNotification()
811 class THideNotifyEvent: public SALOME_Event
817 THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
818 THideNotifyEvent( const int id ) : myId( id ) {}
819 virtual void Execute()
821 if ( LightApp_Application* anApp = getApplication() ) {
823 anApp->hideNotification( myId );
825 anApp->hideNotification( myMsg );
830 void SalomePyQt::hideNotification( const QString& msg )
832 ProcessVoidEvent( new THideNotifyEvent( msg ) );
835 void SalomePyQt::hideNotification( const int id )
837 ProcessVoidEvent( new THideNotifyEvent( id ) );
841 \fn QStringList SalomePyQt::getComponents();
842 \brief Get all modules used in current GUI session.
843 \return List of modules
846 class TGetComponentsEvent: public SALOME_Event
849 typedef QStringList TResult;
851 TGetComponentsEvent() {}
852 virtual void Execute()
854 if ( LightApp_Application* anApp = getApplication() )
857 anApp->modules( titles, false );
858 foreach ( QString title, titles )
860 myResult << anApp->moduleName( title );
865 QStringList SalomePyQt::getComponents()
867 return ProcessEvent( new TGetComponentsEvent() );
871 \fn const QString SalomePyQt::getActiveComponent();
872 \brief Get the currently active module name (for the current study).
873 \return active module name or empty string if there is no active module
876 class TGetActiveComponentEvent: public SALOME_Event
879 typedef QString TResult;
881 TGetActiveComponentEvent() {}
882 virtual void Execute()
884 if ( LightApp_Application* anApp = getApplication() ) {
885 if ( CAM_Module* mod = anApp->activeModule() ) {
886 myResult = mod->name();
891 const QString SalomePyQt::getActiveComponent()
893 return ProcessEvent( new TGetActiveComponentEvent() );
897 \fn PyObject* SalomePyQt::getActivePythonModule();
898 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
899 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
902 class TGetActivePyModuleEvent: public SALOME_Event
905 typedef PyObject* TResult;
907 TGetActivePyModuleEvent() : myResult( Py_None ) {}
908 virtual void Execute()
910 PyModuleHelper* helper = getPythonHelper();
912 myResult = (PyObject*)helper->pythonModule();
915 PyObject* SalomePyQt::getActivePythonModule()
917 return ProcessEvent( new TGetActivePyModuleEvent() );
921 \fn bool SalomePyQt::activateModule( const QString& modName );
922 \brief Activates SALOME module with the given name
923 \return True if the module has been activated and False otherwise.
926 class TActivateModuleEvent: public SALOME_Event
929 typedef bool TResult;
931 QString myModuleName;
932 TActivateModuleEvent( const QString& modName )
933 : myResult( false ), myModuleName( modName ) {}
934 virtual void Execute()
936 if ( LightApp_Application* anApp = getApplication() ) {
937 myResult = anApp->activateModule( myModuleName );
941 bool SalomePyQt::activateModule( const QString& modName )
943 return ProcessEvent( new TActivateModuleEvent( modName ) );
947 \fn void SalomePyQt::registerModule( const QString& modName);
948 \brief Registers module in the study tree
951 void SalomePyQt::registerModule( const QString& modName)
953 class TEvent: public SALOME_Event
957 TEvent(const QString& name): myName(name) {}
958 virtual void Execute()
960 if ( LightApp_Application* anApp = getApplication() ) {
961 anApp->desktop()->emitMessage(QString("register_module_in_study/%1").arg(myName));
965 ProcessVoidEvent( new TEvent(modName) );
969 \brief Update an Object Browser of the study.
971 void SalomePyQt::updateObjBrowser()
973 class TEvent: public SALOME_Event
977 virtual void Execute()
979 if ( SUIT_Session::session() ) {
980 if ( getActiveStudy() ) {
981 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
982 QList<SUIT_Application*>::Iterator it;
983 for( it = apps.begin(); it != apps.end(); ++it ) {
984 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
985 if ( anApp && anApp->activeStudy() ) {
986 anApp->updateObjectBrowser();
994 ProcessVoidEvent( new TEvent() );
999 SalomePyQt::isModified()
1000 \return The modification status of the data model
1001 for the currently active Python module
1002 \note This function is supported for "light" Python-based SALOME modules only.
1005 class TIsModifiedEvent: public SALOME_Event
1008 typedef bool TResult;
1010 TIsModifiedEvent() : myResult( false ) {}
1011 virtual void Execute()
1013 LightApp_Module* module = getActiveModule();
1017 SALOME_PYQT_DataModelLight* aModel =
1018 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1020 myResult = aModel->isModified();
1023 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
1027 bool SalomePyQt::isModified()
1029 return ProcessEvent(new TIsModifiedEvent());
1033 SalomePyQt::setModified()
1035 Sets the modification status of the data model for
1036 the currently active Python module. This method should be used
1037 by the Python code in order to enable/disable "Save" operation
1038 depending on the module's data state.
1040 \note This function is supported for "light" Python-based SALOME modules only.
1042 \param New modification status of the data model
1046 void SalomePyQt::setModified( bool flag )
1048 class TEvent: public SALOME_Event
1054 virtual void Execute()
1056 LightApp_Module* module = getActiveModule();
1060 SALOME_PYQT_DataModelLight* model =
1061 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1063 LightApp_Application* app = module->getApp();
1065 if ( model && app ) {
1066 model->setModified( myFlag );
1067 app->updateActions();
1070 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1074 ProcessVoidEvent( new TEvent( flag ) );
1078 \brief Add string setting to the application preferences.
1080 The parameter \a autoValue is obsolete parameter and currently is not used.
1081 This parameter will be removed in future, so try to avoid its usage in
1084 This function is obsolete. Use one of addSetting() instead.
1086 \param name setting name (it should be of kind <section:setting> where
1087 \c section is resources section name and \c setting is setting name)
1088 \param value new setting value
1089 \param autoValue (not used)
1091 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1093 class TEvent: public SALOME_Event
1099 TEvent( const QString& name, const QString& value, bool autoValue )
1100 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1101 virtual void Execute()
1103 if ( SUIT_Session::session() ) {
1104 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1105 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1106 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1107 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1108 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1109 resMgr->setValue( _sec, _nam, myValue );
1113 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1117 \brief Add integer setting to the application preferences.
1119 The parameter \a autoValue is obsolete parameter and currently is not used.
1120 This parameter will be removed in future, so try to avoid its usage in
1123 This function is obsolete. Use one of addSetting() instead.
1125 \param name setting name (it should be of kind <section:setting> where
1126 \c section is resources section name and \c setting is setting name)
1127 \param value new setting value
1128 \param autoValue (not used)
1130 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1132 class TEvent: public SALOME_Event
1138 TEvent( const QString& name, const int value, bool autoValue )
1139 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1140 virtual void Execute()
1142 if ( SUIT_Session::session() ) {
1143 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1144 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1145 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1146 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1147 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1148 resMgr->setValue( _sec, _nam, myValue );
1152 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1156 \brief Add double setting to the application preferences.
1158 The parameter \a autoValue is obsolete parameter and currently is not used.
1159 This parameter will be removed in future, so try to avoid its usage in
1162 This function is obsolete. Use one of addSetting() instead.
1164 \param name setting name (it should be of kind <section:setting> where
1165 \c section is resources section name and \c setting is setting name)
1166 \param value new setting value
1167 \param autoValue (not used)
1169 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1171 class TEvent: public SALOME_Event
1177 TEvent( const QString& name, const double value, bool autoValue )
1178 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1179 virtual void Execute()
1181 if ( SUIT_Session::session() ) {
1182 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1183 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1184 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1185 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1186 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1187 resMgr->setValue( _sec, _nam, myValue );
1191 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1195 \brief Add boolean setting to the application preferences.
1197 The parameter \a autoValue is obsolete parameter and currently is not used.
1198 This parameter will be removed in future, so try to avoid its usage in
1201 This function is obsolete. Use one of addSetting() instead.
1203 \param name setting name (it should be of kind <section:setting> where
1204 \c section is resources section name and \c setting is setting name)
1205 \param value new setting value
1206 \param autoValue (not used)
1208 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1210 class TEvent: public SALOME_Event
1216 TEvent( const QString& name, const bool value, bool autoValue )
1217 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1218 virtual void Execute()
1220 if ( SUIT_Session::session() ) {
1221 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1222 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1223 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1224 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1225 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1226 resMgr->setValue( _sec, _nam, myValue );
1230 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1234 \brief Remove setting from the application preferences.
1236 This function is obsolete. Use removeSetting() instead.
1238 \param name setting name (it should be of kind <section:setting> where
1239 \c section is resources section name and \c setting is setting name)
1241 void SalomePyQt::removeSettings( const QString& name )
1243 class TEvent: public SALOME_Event
1247 TEvent( const QString& name ) : myName( name ) {}
1248 virtual void Execute()
1250 if ( SUIT_Session::session() ) {
1251 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1252 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1253 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1254 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1255 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1256 resMgr->remove( _sec, _nam );
1260 ProcessVoidEvent( new TEvent( name ) );
1264 \fn QString SalomePyQt::getSetting( const QString& name );
1265 \brief Get application setting value (as string represenation).
1267 This function is obsolete. Use stringSetting(), integerSetting(),
1268 boolSetting(), stringSetting() or colorSetting() instead.
1270 \param name setting name (it should be of kind <section:setting> where
1271 \c section is resources section name and \c setting is setting name)
1272 \return setting name (empty string if setting name is invalid)
1275 class TGetSettingEvent: public SALOME_Event
1278 typedef QString TResult;
1281 TGetSettingEvent( const QString& name ) : myName( name ) {}
1282 virtual void Execute()
1284 if ( SUIT_Session::session() ) {
1285 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1286 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1287 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1288 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1289 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1293 QString SalomePyQt::getSetting( const QString& name )
1295 return ProcessEvent( new TGetSettingEvent( name ) );
1299 \fn QString SalomePyQt::constant( const QString& name );
1300 \brief Get constant's value from application's resource manager.
1302 \param name name of the constant
1303 \return value of the constant
1308 class TGetConstantEvent: public SALOME_Event
1311 typedef QString TResult;
1314 TGetConstantEvent( const QString& name ) : myName( name ) {}
1315 virtual void Execute()
1317 if ( SUIT_Session::session() )
1318 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1321 QString SalomePyQt::constant( const QString& name )
1323 return ProcessEvent( new TGetConstantEvent( name ) );
1327 \brief Add constant to the application's resource manager.
1329 This function is useful to specify programmatically specific
1330 variables that are referenced in the resource setting.
1332 For example, some resource value can be set as "$(myroot)/data/files".
1333 Then, "mypath" constant can be set programmatically by the application
1334 depending on run-time requirements.
1336 \param section resources file section name
1337 \param name name of the constant
1338 \param value value of the constant
1342 void SalomePyQt::setConstant( const QString& name, const QString& value )
1344 class TEvent: public SALOME_Event
1346 QString myName, myValue;
1348 TEvent( const QString& name, const QString& value )
1349 : myName( name ), myValue( value ) {}
1350 virtual void Execute()
1352 if ( SUIT_Session::session() )
1353 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1356 ProcessVoidEvent( new TEvent( name, value ) );
1360 \brief Add double setting to the application preferences.
1361 \param section resources file section name
1362 \param name setting name
1363 \param value new setting value
1365 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1367 class TEvent: public SALOME_Event
1373 TEvent( const QString& section, const QString& name, double value )
1374 : mySection( section ), myName( name ), myValue( value ) {}
1375 virtual void Execute()
1377 if ( SUIT_Session::session() ) {
1378 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1379 if ( !mySection.isEmpty() && !myName.isEmpty() )
1380 resMgr->setValue( mySection, myName, myValue );
1384 ProcessVoidEvent( new TEvent( section, name, value ) );
1388 \brief Add integer setting to the application preferences.
1389 \param section resources file section name
1390 \param name setting name
1391 \param value new setting value
1393 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1395 class TEvent: public SALOME_Event
1401 TEvent( const QString& section, const QString& name, int value )
1402 : mySection( section ), myName( name ), myValue( value ) {}
1403 virtual void Execute()
1405 if ( SUIT_Session::session() ) {
1406 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1407 if ( !mySection.isEmpty() && !myName.isEmpty() )
1408 resMgr->setValue( mySection, myName, myValue );
1412 ProcessVoidEvent( new TEvent( section, name, value ) );
1416 \brief Add boolean setting to the application preferences.
1417 \param section resources file section name
1418 \param name setting name
1419 \param value new setting value
1420 \param dumb this parameter is used in order to avoid sip compilation error
1421 because of conflicting int and bool types
1423 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1425 class TEvent: public SALOME_Event
1431 TEvent( const QString& section, const QString& name, bool value )
1432 : mySection( section ), myName( name ), myValue( value ) {}
1433 virtual void Execute()
1435 if ( SUIT_Session::session() ) {
1436 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1437 if ( !mySection.isEmpty() && !myName.isEmpty() )
1438 resMgr->setValue( mySection, myName, myValue );
1442 ProcessVoidEvent( new TEvent( section, name, value ) );
1446 \brief Add string setting to the application preferences.
1447 \param section resources file section name
1448 \param name setting name
1449 \param value new setting value
1451 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1453 class TEvent: public SALOME_Event
1459 TEvent( const QString& section, const QString& name, const QString& value )
1460 : mySection( section ), myName( name ), myValue( value ) {}
1461 virtual void Execute()
1463 if ( SUIT_Session::session() ) {
1464 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1465 if ( !mySection.isEmpty() && !myName.isEmpty() )
1466 resMgr->setValue( mySection, myName, myValue );
1470 ProcessVoidEvent( new TEvent( section, name, value ) );
1474 \brief Add color setting to the application preferences.
1475 \param section resources file section name
1476 \param name setting name
1477 \param value new setting value
1479 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1481 class TEvent: public SALOME_Event
1487 TEvent( const QString& section, const QString& name, const QColor& value )
1488 : mySection( section ), myName( name ), myValue( value ) {}
1489 virtual void Execute()
1491 if ( SUIT_Session::session() ) {
1492 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1493 if ( !mySection.isEmpty() && !myName.isEmpty() )
1494 resMgr->setValue( mySection, myName, myValue );
1498 ProcessVoidEvent( new TEvent( section, name, value ) );
1502 \brief Add byte array setting to the application preferences.
1503 \param section resources file section name
1504 \param name setting name
1505 \param value new setting value
1507 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1509 class TEvent: public SALOME_Event
1515 TEvent( const QString& section, const QString& name, const QByteArray& value )
1516 : mySection( section ), myName( name ), myValue( value ) {}
1517 virtual void Execute()
1519 if ( SUIT_Session::session() ) {
1520 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1521 if ( !mySection.isEmpty() && !myName.isEmpty() )
1522 resMgr->setValue( mySection, myName, myValue );
1526 ProcessVoidEvent( new TEvent( section, name, value ) );
1530 \brief Add font setting to the application preferences.
1531 \param section resources file section name
1532 \param name setting name
1533 \param value new setting value
1535 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1537 class TEvent: public SALOME_Event
1543 TEvent( const QString& section, const QString& name, const QFont& value )
1544 : mySection( section ), myName( name ), myValue( value ) {}
1545 virtual void Execute()
1547 if ( SUIT_Session::session() ) {
1548 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1549 if ( !mySection.isEmpty() && !myName.isEmpty() )
1550 resMgr->setValue( mySection, myName, myValue );
1554 ProcessVoidEvent( new TEvent( section, name, value ) );
1558 \fn int SalomePyQt::integerSetting( const QString& section,
1559 const QString& name,
1561 \brief Get integer setting from the application preferences.
1562 \param section resources file section name
1563 \param name setting name
1564 \param def default value which is returned if the setting is not found
1565 \return setting value
1568 class TGetIntSettingEvent: public SALOME_Event
1571 typedef int TResult;
1576 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1577 : mySection( section ), myName( name ), myDefault( def ) {}
1578 virtual void Execute()
1580 if ( SUIT_Session::session() ) {
1581 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1582 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1586 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1588 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1592 \fn double SalomePyQt::doubleSetting( const QString& section,
1593 const QString& name,
1595 \brief Get double setting from the application preferences.
1596 \param section resources file section name
1597 \param name setting name
1598 \param def default value which is returned if the setting is not found
1599 \return setting value
1602 class TGetDblSettingEvent: public SALOME_Event
1605 typedef double TResult;
1610 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1611 : mySection( section ), myName( name ), myDefault( def ) {}
1612 virtual void Execute()
1614 if ( SUIT_Session::session() ) {
1615 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1616 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1620 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1622 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1626 \fn bool SalomePyQt::boolSetting( const QString& section,
1627 const QString& name,
1629 \brief Get boolean setting from the application preferences.
1630 \param section resources file section name
1631 \param name setting name
1632 \param def default value which is returned if the setting is not found
1633 \return setting value
1636 class TGetBoolSettingEvent: public SALOME_Event
1639 typedef bool TResult;
1644 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1645 : mySection( section ), myName( name ), myDefault( def ) {}
1646 virtual void Execute()
1648 if ( SUIT_Session::session() ) {
1649 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1650 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1654 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1656 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1660 \fn QString SalomePyQt::stringSetting( const QString& section,
1661 const QString& name,
1664 \brief Get string setting from the application preferences.
1665 \param section resources file section name
1666 \param name setting name
1667 \param def default value which is returned if the setting is not found
1668 \param subst \c true to make substitution, \c false to get "raw" value
1669 \return setting value
1672 class TGetStrSettingEvent: public SALOME_Event
1675 typedef QString TResult;
1681 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1682 : mySection( section ), myName( name ), mySubst( subst ), myDefault( def ) {}
1683 virtual void Execute()
1685 if ( SUIT_Session::session() ) {
1686 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1687 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1691 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1693 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1697 \fn QColor SalomePyQt::colorSetting( const QString& section,
1698 const QString& name,
1700 \brief Get color setting from the application preferences.
1701 \param section resources file section name
1702 \param name setting name
1703 \param def default value which is returned if the setting is not found
1704 \return setting value
1707 class TGetColorSettingEvent: public SALOME_Event
1710 typedef QColor TResult;
1715 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1716 : mySection( section ), myName( name ), myDefault( def ) {}
1717 virtual void Execute()
1719 if ( SUIT_Session::session() ) {
1720 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1721 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1725 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1727 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1731 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1732 const QString& name,
1733 const QByteArray& def );
1734 \brief Get byte array setting from the application preferences.
1735 \param section resources file section name
1736 \param name setting name
1737 \param def default value which is returned if the setting is not found
1738 \return setting value
1741 class TGetByteArraySettingEvent: public SALOME_Event
1744 typedef QByteArray TResult;
1749 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1750 : mySection( section ), myName( name ), myDefault( def ) {}
1751 virtual void Execute()
1753 if ( SUIT_Session::session() ) {
1754 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1755 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1759 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1761 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1765 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1766 const QString& name,
1768 \brief Get font setting from the application preferences.
1769 \param section resources file section name
1770 \param name setting name
1771 \param def default value which is returned if the setting is not found
1772 \return setting value
1775 class TGetFontSettingEvent: public SALOME_Event
1778 typedef QFont TResult;
1783 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1784 : mySection( section ), myName( name ), myDefault( def ) {}
1785 virtual void Execute()
1787 if ( SUIT_Session::session() ) {
1788 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1789 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1793 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1795 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1799 \brief Remove setting from the application preferences.
1800 \param section resources file section name
1801 \param name setting name
1803 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1805 class TEvent: public SALOME_Event
1810 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1811 virtual void Execute()
1813 if ( SUIT_Session::session() ) {
1814 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1815 if ( !mySection.isEmpty() && !myName.isEmpty() )
1816 resMgr->remove( mySection, myName );
1820 ProcessVoidEvent( new TEvent( section, name ) );
1824 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1825 \brief Check setting existence in the application preferences.
1826 \param section resources file section name
1827 \param name setting name
1828 \return \c true if setting exists
1831 class THasSettingEvent: public SALOME_Event
1834 typedef bool TResult;
1838 THasSettingEvent( const QString& section, const QString& name )
1839 : mySection( section ), myName( name ) {}
1840 virtual void Execute()
1842 if ( SUIT_Session::session() ) {
1843 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1844 myResult = resMgr->hasValue( mySection, myName );
1848 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1850 return ProcessEvent( new THasSettingEvent( section, name ) );
1854 \fn QStringList SalomePyQt::parameters( const QString& section );
1855 \brief Get names of preference items stored within the given section.
1856 \param section resources file section's name
1857 \return \c list of preferences items
1861 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1862 \brief Get names of preference items stored within the given section.
1863 \param section resources file section's name
1864 \return \c list of preferences items
1867 class TParametersEvent: public SALOME_Event
1870 typedef QStringList TResult;
1872 QStringList mySection;
1873 TParametersEvent( const QString& section )
1875 mySection << section;
1877 TParametersEvent( const QStringList& section )
1878 : mySection( section )
1880 virtual void Execute()
1882 if ( SUIT_Session::session() ) {
1883 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1884 myResult = resMgr->parameters( mySection );
1888 QStringList SalomePyQt::parameters( const QString& section )
1890 return ProcessEvent( new TParametersEvent( section ) );
1892 QStringList SalomePyQt::parameters( const QStringList& section )
1894 return ProcessEvent( new TParametersEvent( section ) );
1898 \fn QString SalomePyQt::getFileName( QWidget* parent,
1899 const QString& initial,
1900 const QStringList& filters,
1901 const QString& caption,
1903 \brief Show 'Open/Save file' dialog box for file selection
1904 and return a user's choice (selected file name).
1905 \param parent parent widget
1906 \param initial initial directory the dialog box to be opened in
1907 \param filters list of files filters (wildcards)
1908 \param caption dialog box title
1909 \param open if \c true, "Open File" dialog box is shown;
1910 otherwise "Save File" dialog box is shown
1911 \return selected file name (null string if user cancels operation)
1914 class TGetFileNameEvent: public SALOME_Event
1917 typedef QString TResult;
1921 QStringList myFilters;
1924 TGetFileNameEvent( QWidget* parent,
1925 const QString& initial,
1926 const QStringList& filters,
1927 const QString& caption,
1929 : myParent ( parent ),
1930 myInitial( initial ),
1931 myFilters( filters ),
1932 myCaption( caption ),
1934 virtual void Execute()
1936 if ( LightApp_Application* anApp = getApplication() ) {
1937 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1938 myCaption, myParent );
1942 QString SalomePyQt::getFileName( QWidget* parent,
1943 const QString& initial,
1944 const QStringList& filters,
1945 const QString& caption,
1948 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1952 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1953 const QString& initial,
1954 const QStringList& filters,
1955 const QString& caption );
1956 \brief Show 'Open files' dialog box for multiple files selection
1957 and return a user's choice (selected file names list).
1958 \param parent parent widget
1959 \param initial initial directory the dialog box to be opened in
1960 \param filters list of files filters (wildcards)
1961 \param caption dialog box title
1962 \return selected file names list (empty list if user cancels operation)
1965 class TGetOpenFileNamesEvent: public SALOME_Event
1968 typedef QStringList TResult;
1972 QStringList myFilters;
1974 TGetOpenFileNamesEvent( QWidget* parent,
1975 const QString& initial,
1976 const QStringList& filters,
1977 const QString& caption )
1978 : myParent ( parent ),
1979 myInitial( initial ),
1980 myFilters( filters ),
1981 myCaption( caption ) {}
1982 virtual void Execute()
1984 if ( LightApp_Application* anApp = getApplication() ) {
1985 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1989 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1990 const QString& initial,
1991 const QStringList& filters,
1992 const QString& caption )
1994 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1998 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1999 const QString& initial,
2000 const QString& caption );
2001 \brief Show 'Get Directory' dialog box for the directory selection
2002 and return a user's choice (selected directory name).
2003 \param parent parent widget
2004 \param initial initial directory the dialog box to be opened in
2005 \param caption dialog box title
2006 \return selected directory name (null string if user cancels operation)
2009 class TGetExistingDirectoryEvent: public SALOME_Event
2012 typedef QString TResult;
2017 TGetExistingDirectoryEvent( QWidget* parent,
2018 const QString& initial,
2019 const QString& caption )
2020 : myParent ( parent ),
2021 myInitial( initial ),
2022 myCaption( caption ) {}
2023 virtual void Execute()
2025 if ( LightApp_Application* anApp = getApplication() ) {
2026 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
2030 QString SalomePyQt::getExistingDirectory( QWidget* parent,
2031 const QString& initial,
2032 const QString& caption )
2034 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
2038 \fn QString SalomePyQt::loadIcon( const QString& filename );
2039 \brief Load an icon from the module resources by the specified file name.
2040 \param fileName icon file name
2044 class TLoadIconEvent: public SALOME_Event
2047 typedef QIcon TResult;
2051 TLoadIconEvent( const QString& module, const QString& filename )
2052 : myModule( module ),
2053 myFileName ( filename ) {}
2054 virtual void Execute()
2056 myResult = loadIconInternal( myModule, myFileName );
2059 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2061 return ProcessEvent( new TLoadIconEvent( module, filename ) );
2065 \brief Open external browser to display context help information.
2068 Current implementation does nothing.
2070 \param source documentation (HTML) file name
2071 \param context context (for example, HTML ancor name)
2073 void SalomePyQt::helpContext( const QString& source, const QString& context )
2075 class TEvent: public SALOME_Event
2080 TEvent( const QString& source, const QString& context )
2081 : mySource( source ), myContext( context ) {}
2082 virtual void Execute()
2084 if ( LightApp_Application* anApp = getApplication() ) {
2085 anApp->onHelpContextModule( "", mySource, myContext );
2089 ProcessVoidEvent( new TEvent( source, context ) );
2093 \fn int SalomePyQt::defaultMenuGroup();
2094 \brief Get detault menu group identifier which can be used when
2095 creating menus (insert custom menu commands).
2096 \return default menu group ID
2099 class TDefMenuGroupEvent: public SALOME_Event
2102 typedef int TResult;
2104 TDefMenuGroupEvent() : myResult( -1 ) {}
2105 virtual void Execute()
2107 myResult = PyModuleHelper::defaultMenuGroup();
2110 int SalomePyQt::defaultMenuGroup()
2112 return ProcessEvent( new TDefMenuGroupEvent() );
2118 CrTool( const QString& tBar, const QString& nBar )
2119 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
2120 CrTool( const int id, const int tBar, const int idx )
2121 : myCase( 1 ), myTbId( tBar ), myId( id ), myIndex( idx ) {}
2122 CrTool( const int id, const QString& tBar, const int idx )
2123 : myCase( 2 ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2124 CrTool( QAction* action, const int tbId, const int id, const int idx )
2125 : myCase( 3 ), myTbId( tbId ), myAction( action ), myId( id ), myIndex( idx ) {}
2126 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2127 : myCase( 4 ), myTbTitle( tBar ), myAction( action ), myId( id ), myIndex( idx ) {}
2133 if ( getActiveModule() )
2134 return getActiveModule()->createTool( myTbTitle, myTbName );
2135 else if ( getApplication() )
2136 return getApplication()->createTool( myTbTitle, myTbName );
2139 if ( getActiveModule() )
2140 return getActiveModule()->createTool( myId, myTbId, myIndex );
2141 else if ( getApplication() )
2142 return getApplication()->createTool( myId, myTbId, myIndex );
2145 if ( getActiveModule() )
2146 return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2147 else if ( getApplication() )
2148 return getApplication()->createTool( myId, myTbTitle, myIndex );
2151 if ( getActiveModule() )
2152 return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2153 else if ( getApplication() )
2154 return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2157 if ( getActiveModule() )
2158 return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2159 else if ( getApplication() )
2160 return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2177 class TCreateToolEvent: public SALOME_Event
2180 typedef int TResult;
2182 const CrTool& myCrTool;
2183 TCreateToolEvent( const CrTool& crTool )
2184 : myResult( -1 ), myCrTool( crTool ) {}
2185 virtual void Execute()
2187 myResult = myCrTool.execute();
2192 \brief Create toolbar with specified name.
2193 \param tBar toolbar title (language-dependent)
2194 \param nBar toolbar name (language-independent) [optional]
2195 \return toolbar ID or -1 if toolbar creation is failed
2197 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2199 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2203 \brief Insert action with specified \a id to the toolbar.
2205 \param tBar toolbar ID
2206 \param idx required index in the toolbar
2207 \return action ID or -1 if action could not be added
2209 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2211 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2215 \brief Insert action with specified \a id to the toolbar.
2217 \param tBar toolbar name
2218 \param idx required index in the toolbar
2219 \return action ID or -1 if action could not be added
2221 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2223 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2227 \brief Insert action to the toolbar.
2229 \param tBar toolbar ID
2230 \param id required action ID
2231 \param idx required index in the toolbar
2232 \return action ID or -1 if action could not be added
2234 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2236 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2241 \brief Clear given toolbar.
2242 \param title toolbar's title
2244 void SalomePyQt::clearTool( const QString& title )
2246 class TEvent: public SALOME_Event
2250 TEvent( const QString& title )
2251 : myTitle( title ) {}
2252 virtual void Execute()
2254 if ( getActiveModule() )
2255 return getActiveModule()->clearTool( myTitle );
2256 else if ( getApplication() )
2257 return getApplication()->clearTool( myTitle );
2260 ProcessVoidEvent( new TEvent( title ) );
2264 \brief Insert action to the toolbar.
2266 \param tBar toolbar name
2267 \param id required action ID
2268 \param idx required index in the toolbar
2269 \return action ID or -1 if action could not be added
2271 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2273 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2279 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2280 : myCase( 0 ), myMenuId( menu ), mySubMenuName( subMenu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2281 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2282 : myCase( 1 ), myMenuName( menu ), mySubMenuName( subMenu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2283 CrMenu( const int id, const int menu, const int group, const int idx )
2284 : myCase( 2 ), myMenuId( menu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2285 CrMenu( const int id, const QString& menu, const int group, const int idx )
2286 : myCase( 3 ), myMenuName( menu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2287 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2288 : myCase( 4 ), myMenuId( menu ), myGroup( group ), myAction( action ), myId( id ), myIndex( idx ) {}
2289 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2290 : myCase( 5 ), myMenuName( menu ), myGroup( group ), myAction( action ), myId( id ), myIndex( idx ) {}
2296 if ( getActiveModule() )
2297 return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2298 else if ( getApplication() )
2299 return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2302 if ( getActiveModule() )
2303 return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2304 else if ( getApplication() )
2305 return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2308 if ( getActiveModule() )
2309 return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2310 else if ( getApplication() )
2311 return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2314 if ( getActiveModule() )
2315 return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2316 else if ( getApplication() )
2317 return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2320 if ( getActiveModule() )
2321 return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2322 else if ( getApplication() )
2323 return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2326 if ( getActiveModule() )
2327 return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2328 else if ( getApplication() )
2329 return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2340 QString mySubMenuName;
2347 class TCreateMenuEvent: public SALOME_Event
2350 typedef int TResult;
2352 const CrMenu& myCrMenu;
2353 TCreateMenuEvent( const CrMenu& crMenu )
2354 : myResult( -1 ), myCrMenu( crMenu ) {}
2355 virtual void Execute()
2357 myResult = myCrMenu.execute();
2362 \brief Create main menu.
2363 \param subMenu menu name
2364 \param menu parent menu ID
2365 \param id required menu ID
2366 \param group menu group ID
2367 \param idx required index in the menu
2368 \return menu ID or -1 if menu could not be added
2370 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2372 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2376 \brief Create main menu.
2377 \param subMenu menu name
2378 \param menu parent menu name (list of menu names separated by "|")
2379 \param id required menu ID
2380 \param group menu group ID
2381 \param idx required index in the menu
2382 \return menu ID or -1 if menu could not be added
2384 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2386 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2390 \brief Insert action to the main menu.
2392 \param menu parent menu ID
2393 \param group menu group ID
2394 \param idx required index in the menu
2395 \return action ID or -1 if action could not be added
2397 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2399 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2403 \brief Insert action to the main menu.
2405 \param menu parent menu name (list of menu names separated by "|")
2406 \param group menu group ID
2407 \param idx required index in the menu
2408 \return action ID or -1 if action could not be added
2410 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2412 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2416 \brief Insert action to the main menu.
2418 \param menu parent menu ID
2419 \param group menu group ID
2420 \param idx required index in the menu
2421 \return action ID or -1 if action could not be added
2423 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2425 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2429 \brief Insert action to the main menu.
2431 \param menu parent menu name (list of menu names separated by "|")
2432 \param group menu group ID
2433 \param idx required index in the menu
2434 \return action ID or -1 if action could not be added
2436 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2438 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2442 \fn QAction* SalomePyQt::createSeparator();
2443 \brief Create separator action which can be used in the menu or toolbar.
2444 \return new separator action
2447 class TCreateSepEvent: public SALOME_Event
2450 typedef QAction* TResult;
2454 virtual void Execute()
2456 LightApp_Module* module = getActiveModule();
2458 myResult = (QAction*)module->separator();
2461 QAction* SalomePyQt::createSeparator()
2463 return ProcessEvent( new TCreateSepEvent() );
2467 \fn QAction* SalomePyQt::createAction( const int id,
2468 const QString& menuText,
2469 const QString& tipText,
2470 const QString& statusText,
2471 const QString& icon,
2473 const bool toggle );
2474 \brief Create an action which can be then used in the menu or toolbar.
2475 \param id the unique id action to be registered to
2476 \param menuText action text which should appear in menu
2477 \param tipText text which should appear in the tooltip
2478 \param statusText text which should appear in the status bar when action is activated
2479 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2480 \param key the key accelrator for the action
2481 \param toggle if \c true the action is checkable
2484 class TCreateActionEvent: public SALOME_Event
2487 typedef QAction* TResult;
2492 QString myStatusText;
2496 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2497 const QString& statusText, const QString& icon, const int key, const bool toggle )
2498 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2499 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2500 virtual void Execute()
2502 LightApp_Module* module = getActiveModule();
2504 QIcon icon = loadIconInternal( module->name(), myIcon );
2505 myResult = (QAction*)module->action( myId );
2507 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2508 myResult->setToolTip( myTipText );
2509 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2510 myResult->setText( myMenuText );
2511 if ( myResult->icon().isNull() && !icon.isNull() )
2512 myResult->setIcon( icon );
2513 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2514 myResult->setStatusTip( myStatusText );
2515 if ( myResult->shortcut().isEmpty() && myKey )
2516 myResult->setShortcut( myKey );
2517 if ( myResult->isCheckable() != myToggle )
2518 myResult->setCheckable( myToggle );
2521 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2523 // for Python module, automatically connect action to callback slot
2524 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2525 if ( helper ) helper->connectAction( myResult );
2529 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2530 const QString& tipText, const QString& statusText,
2531 const QString& icon, const int key, const bool toggle )
2533 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2537 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2538 \brief Create an action group which can be then used in the menu or toolbar
2539 \param id : the unique id action group to be registered to
2540 \param exclusive : if \c true the action group does exclusive toggling
2543 struct TCreateActionGroupEvent: public SALOME_Event
2545 typedef QtxActionGroup* TResult;
2549 TCreateActionGroupEvent( const int id, const bool exclusive )
2550 : myId( id ), myExclusive( exclusive ) {}
2551 virtual void Execute()
2553 LightApp_Module* module = getActiveModule();
2555 myResult = module->createActionGroup( myId, myExclusive );
2558 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2560 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2564 \fn QAction* SalomePyQt::action( const int id );
2565 \brief Get action by specified identifier.
2566 \return action or 0 if action is not registered
2569 class TActionEvent: public SALOME_Event
2572 typedef QAction* TResult;
2575 TActionEvent( const int id )
2576 : myResult( 0 ), myId( id ) {}
2577 virtual void Execute()
2579 LightApp_Module* module = getActiveModule();
2581 myResult = (QAction*)module->action( myId );
2584 QAction* SalomePyQt::action( const int id )
2586 return ProcessEvent( new TActionEvent( id ) );
2590 \fn int SalomePyQt::actionId( const QAction* a );
2591 \brief Get an action identifier.
2592 \return action ID or -1 if action is not registered
2595 class TActionIdEvent: public SALOME_Event
2598 typedef int TResult;
2600 const QAction* myAction;
2601 TActionIdEvent( const QAction* action )
2602 : myResult( -1 ), myAction( action ) {}
2603 virtual void Execute()
2605 LightApp_Module* module = getActiveModule();
2607 myResult = module->actionId( myAction );
2610 int SalomePyQt::actionId( const QAction* a )
2612 return ProcessEvent( new TActionIdEvent( a ) );
2616 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2617 \brief Add global (not module-related) preferences group.
2618 \param label global preferences group name
2619 \return preferences group identifier
2622 class TAddGlobalPrefEvent: public SALOME_Event
2625 typedef int TResult;
2628 TAddGlobalPrefEvent( const QString& label )
2629 : myResult( -1 ), myLabel( label ) {}
2630 virtual void Execute()
2632 LightApp_Module* module = getActiveModule();
2634 LightApp_Preferences* pref = module->getApp()->preferences();
2636 myResult = pref->addPreference( myLabel, -1 );
2640 int SalomePyQt::addGlobalPreference( const QString& label )
2642 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2646 \fn int SalomePyQt::addPreference( const QString& label );
2647 \brief Add module-related preferences group.
2648 \param label preferences group name
2649 \return preferences group identifier
2652 class TAddPrefEvent: public SALOME_Event
2655 typedef int TResult;
2658 TAddPrefEvent( const QString& label )
2659 : myResult( -1 ), myLabel( label ) {}
2660 virtual void Execute()
2662 LightApp_Module* module = getActiveModule();
2664 LightApp_Preferences* pref = module->getApp()->preferences();
2666 int cId = pref->addPreference( module->moduleName(), -1 );
2668 myResult = pref->addPreference( myLabel, cId );
2673 int SalomePyQt::addPreference( const QString& label )
2675 return ProcessEvent( new TAddPrefEvent( label ) );
2679 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2680 const QString& section, const QString& param );
2681 \brief Add module-related preferences.
2682 \param label preferences group name
2683 \param pId parent preferences group id
2684 \param type preferences type
2685 \param section resources file section name
2686 \param param resources file setting name
2687 \return preferences identifier
2690 class TAddPrefParamEvent: public SALOME_Event
2693 typedef int TResult;
2700 TAddPrefParamEvent( const QString& label,
2701 const int pId, const int type,
2702 const QString& section,
2703 const QString& param )
2705 myLabel( label ), myPId( pId ), myType( type ),
2706 mySection( section ), myParam ( param ) {}
2707 virtual void Execute()
2709 LightApp_Module* module = getActiveModule();
2711 LightApp_Preferences* pref = module->getApp()->preferences();
2713 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2717 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2718 const QString& section, const QString& param )
2720 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2724 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2725 \brief Get the preferences property.
2726 \param id preferences identifier
2727 \param prop preferences property name
2728 \return preferences property value or null QVariant if property is not set
2731 class TPrefPropEvent: public SALOME_Event
2734 typedef QVariant TResult;
2738 TPrefPropEvent( const int id, const QString& prop )
2739 : myId( id ), myProp( prop ) {}
2740 virtual void Execute()
2742 LightApp_Module* module = getActiveModule();
2744 LightApp_Preferences* pref = module->getApp()->preferences();
2746 myResult = pref->itemProperty( myProp, myId );
2750 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2752 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2756 \brief Set the preferences property.
2757 \param id preferences identifier
2758 \param prop preferences property name
2759 \param var preferences property value
2761 void SalomePyQt::setPreferenceProperty( const int id,
2762 const QString& prop,
2763 const QVariant& var )
2765 class TEvent: public SALOME_Event
2771 TEvent( const int id, const QString& prop, const QVariant& var )
2772 : myId( id ), myProp( prop ), myVar( var ) {}
2773 virtual void Execute()
2775 LightApp_Module* module = getActiveModule();
2777 LightApp_Preferences* pref = module->getApp()->preferences();
2779 pref->setItemProperty( myProp, myVar, myId );
2783 ProcessVoidEvent( new TEvent( id, prop, var ) );
2787 \brief Set specific widget as a custom preferences item.
2788 \param id preferences identifier
2789 \param prop preferences property name
2790 \param widget custom widget
2792 void SalomePyQt::setPreferencePropertyWg( const int id,
2793 const QString& prop,
2794 UserDefinedContent* widget )
2796 class TEvent: public SALOME_Event
2800 UserDefinedContent* myWidget;
2802 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2803 : myId( id ), myProp( prop ), myWidget( widget ) {}
2804 virtual void Execute()
2806 LightApp_Module* module = getActiveModule();
2808 LightApp_Preferences* pref = module->getApp()->preferences();
2810 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2815 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2819 \brief Add the property value to the list of values.
2821 This method allows creating properties which are QList<QVariant>
2822 - there is no way to pass such values directly to QVariant parameter with PyQt.
2824 \param id preferences identifier
2825 \param prop preferences property name
2826 \param idx preferences property index
2827 \param var preferences property value for the index \a idx
2829 void SalomePyQt::addPreferenceProperty( const int id,
2830 const QString& prop,
2832 const QVariant& var )
2834 class TEvent: public SALOME_Event
2841 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2842 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2843 virtual void Execute()
2845 LightApp_Module* module = getActiveModule();
2847 LightApp_Preferences* pref = module->getApp()->preferences();
2849 QVariant var = pref->itemProperty( myProp, myId );
2850 if ( var.isValid() ) {
2851 if ( var.type() == QVariant::StringList ) {
2852 QStringList sl = var.toStringList();
2853 if ( myIdx >= 0 && myIdx < sl.count() )
2854 sl[myIdx] = myVar.toString();
2856 sl.append( myVar.toString() );
2857 pref->setItemProperty( myProp, sl, myId );
2859 else if ( var.type() == QVariant::List ) {
2860 QList<QVariant> vl = var.toList();
2861 if ( myIdx >= 0 && myIdx < vl.count() )
2865 pref->setItemProperty( myProp, vl, myId );
2871 pref->setItemProperty( myProp, vl, myId );
2877 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2881 \brief Put the message to the Log messages output window
2882 \param msg message text (it can be of simple rich text format)
2883 \param addSeparator boolean flag which specifies if it is necessary
2884 to separate the message with predefined separator
2886 void SalomePyQt::message( const QString& msg, bool addSeparator )
2888 class TEvent: public SALOME_Event
2893 TEvent( const QString& msg, bool addSeparator )
2894 : myMsg( msg ), myAddSep( addSeparator ) {}
2895 virtual void Execute()
2897 if ( LightApp_Application* anApp = getApplication() ) {
2898 LogWindow* lw = anApp->logWindow();
2900 lw->putMessage( myMsg, myAddSep );
2904 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2908 \brief Set the title to the Help panel.
2909 \param title Title text (empty string removes title)
2911 void SalomePyQt::infoSetTitle( const QString& title )
2913 class TEvent: public SALOME_Event
2917 TEvent( const QString& title )
2918 : myTitle( title ) {}
2919 virtual void Execute()
2921 if ( LightApp_Application* anApp = getApplication() ) {
2922 QtxInfoPanel* ip = anApp->infoPanel();
2924 ip->setTitle( myTitle );
2928 ProcessVoidEvent( new TEvent( title ) );
2932 \fn int SalomePyQt::infoAddLabel( const QString& text, const int groupId )
2933 \brief Insert left-aligned text label into the Help panel
2934 \param text Label text
2935 \param groupId Parent group's identifier (defaults to -1 for top-level group)
2936 \return Label's identifier
2939 class TInfoAddLabel2paramEvent: public SALOME_Event
2942 typedef int TResult;
2946 TInfoAddLabel2paramEvent( const QString& text, const int groupId )
2947 : myText( text ), myGroupId( groupId ) {}
2948 virtual void Execute()
2950 if ( LightApp_Application* anApp = getApplication() ) {
2951 QtxInfoPanel* ip = anApp->infoPanel();
2953 myResult = ip->addLabel( myText, myGroupId );
2957 int SalomePyQt::infoAddLabel( const QString& text, const int groupId )
2959 return ProcessEvent( new TInfoAddLabel2paramEvent( text, groupId ) );
2963 \fn int SalomePyQt::infoAddLabel( const QString& text, Qt::Alignment alignment, const int groupId )
2964 \brief Insert text label into the Help panel
2965 \param text Label text
2966 \param alignment Alignment flag for text label
2967 \param groupId Parent group's identifier (defaults to -1 for top-level group)
2968 \return Label's identifier
2971 class TInfoAddLabel3paramEvent: public SALOME_Event
2974 typedef int TResult;
2977 Qt::Alignment myAlignment;
2979 TInfoAddLabel3paramEvent( const QString& text, Qt::Alignment alignment, const int groupId )
2980 : myText( text ), myAlignment( alignment ), myGroupId( groupId ) {}
2981 virtual void Execute()
2983 if ( LightApp_Application* anApp = getApplication() ) {
2984 QtxInfoPanel* ip = anApp->infoPanel();
2986 myResult = ip->addLabel( myText, myAlignment, myGroupId );
2990 int SalomePyQt::infoAddLabel( const QString& text, Qt::Alignment alignment, const int groupId )
2992 return ProcessEvent( new TInfoAddLabel3paramEvent( text, alignment, groupId ) );
2996 \fn int SalomePyQt::infoAddAction( QAction* action, const int groupId )
2997 \brief Insert action button into the Help panel
2998 \param action Action being added
2999 \param groupId Parent group's identifier (defaults to -1 for top-level group)
3000 \return Action's identifier
3003 class TInfoAddActionEvent: public SALOME_Event
3006 typedef int TResult;
3010 TInfoAddActionEvent( QAction* action, const int groupId )
3011 : myAction( action ), myGroupId( groupId ) {}
3012 virtual void Execute()
3014 if ( LightApp_Application* anApp = getApplication() ) {
3015 QtxInfoPanel* ip = anApp->infoPanel();
3017 myResult = ip->addAction( myAction, myGroupId );
3021 int SalomePyQt::infoAddAction( QAction* action, const int groupId )
3023 return ProcessEvent( new TInfoAddActionEvent( action, groupId ) );
3027 \fn int SalomePyQt::infoAddGroup( const QString& text, const int groupId )
3028 \brief Create a (sub-)group in the Help panel
3029 \param text Group title
3030 \param groupId Parent group's identifier (defaults to -1 for top-level group)
3031 \return Group's identifier
3034 class TInfoAddGroupEvent: public SALOME_Event
3037 typedef int TResult;
3041 TInfoAddGroupEvent( const QString& text, const int groupId )
3042 : myText( text ), myGroupId( groupId ) {}
3043 virtual void Execute()
3045 if ( LightApp_Application* anApp = getApplication() ) {
3046 QtxInfoPanel* ip = anApp->infoPanel();
3048 myResult = ip->addGroup( myText, myGroupId );
3052 int SalomePyQt::infoAddGroup( const QString& text, const int groupId )
3054 return ProcessEvent( new TInfoAddGroupEvent( text, groupId ) );
3058 \brief Remove item from the Help panel
3059 \param id Item's (label's, action's, group's, ...) identifier
3061 void SalomePyQt::infoRemove( const int id )
3063 class TEvent: public SALOME_Event
3067 TEvent( const int id )
3069 virtual void Execute()
3071 if ( LightApp_Application* anApp = getApplication() ) {
3072 QtxInfoPanel* ip = anApp->infoPanel();
3078 ProcessVoidEvent( new TEvent( id ) );
3082 \brief Clear Help panel's contents
3083 \param groupId Group's identifier (default is -1, to clear whole panel)
3085 void SalomePyQt::infoClear( const int groupId )
3087 class TEvent: public SALOME_Event
3091 TEvent( const int groupId )
3092 : myGroupId( groupId ) {}
3093 virtual void Execute()
3095 if ( LightApp_Application* anApp = getApplication() ) {
3096 QtxInfoPanel* ip = anApp->infoPanel();
3098 ip->clear( myGroupId );
3102 ProcessVoidEvent( new TEvent( groupId ) );
3106 \brief Set item's visibility in the Help panel
3107 \param id Item's (label's, action's, group's, ...) identifier
3108 \param visible Visibility flag
3110 void SalomePyQt::infoSetVisible( const int id, bool visible )
3112 class TEvent: public SALOME_Event
3117 TEvent( const int id, bool visible )
3118 : myId( id ), myVisible( visible ) {}
3119 virtual void Execute()
3121 if ( LightApp_Application* anApp = getApplication() ) {
3122 QtxInfoPanel* ip = anApp->infoPanel();
3124 ip->setVisible( myId, myVisible );
3128 ProcessVoidEvent( new TEvent( id, visible ) );
3132 \brief Enable/disable item in the Help panel
3133 \param id Item's (label's, action's, group's, ...) identifier
3134 \param enabled Enabled state
3136 void SalomePyQt::infoSetEnabled( const int id, bool enabled )
3138 class TEvent: public SALOME_Event
3143 TEvent( const int id, bool enabled )
3144 : myId( id ), myEnabled( enabled ) {}
3145 virtual void Execute()
3147 if ( LightApp_Application* anApp = getApplication() ) {
3148 QtxInfoPanel* ip = anApp->infoPanel();
3150 ip->setEnabled( myId, myEnabled );
3154 ProcessVoidEvent( new TEvent( id, enabled ) );
3158 \brief Remove all the messages from the Log messages output window.
3160 void SalomePyQt::clearMessages()
3162 class TEvent: public SALOME_Event
3166 virtual void Execute()
3168 if ( LightApp_Application* anApp = getApplication() ) {
3169 LogWindow* lw = anApp->logWindow();
3175 ProcessVoidEvent( new TEvent() );
3179 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
3180 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
3181 to the image file in the specified format.
3183 For the current moment JPEG, PNG and BMP images formats are supported.
3184 The image format is defined automatically by the file name extension.
3185 By default, BMP format is used.
3187 \param filename image file name
3188 \return operation status (\c true on success)
3191 class TDumpViewEvent: public SALOME_Event
3194 typedef bool TResult;
3198 TDumpViewEvent( const QString& filename, const int id )
3199 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
3200 virtual void Execute()
3202 SUIT_ViewWindow* wnd = 0;
3204 if ( LightApp_Application* anApp = getApplication() ) {
3205 SUIT_ViewManager* vm = anApp->activeViewManager();
3207 wnd = vm->getActiveView();
3209 myWndId = wnd->getId();
3212 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3215 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
3216 #ifndef DISABLE_PLOT2DVIEWER
3217 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3219 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
3220 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
3221 qApp->processEvents();
3222 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
3223 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
3227 #endif // DISABLE_PLOT2DVIEWER
3228 QImage im = wnd->dumpView();
3229 if ( !im.isNull() && !myFileName.isEmpty() ) {
3230 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
3231 if ( fmt == "JPG" ) fmt = "JPEG";
3232 myResult = im.save( myFileName, fmt.toLatin1() );
3237 bool SalomePyQt::dumpView( const QString& filename, const int id )
3239 return ProcessEvent( new TDumpViewEvent( filename, id ) );
3243 \fn QList<int> SalomePyQt::getViews();
3244 \brief Get list of integer identifiers of all the currently opened views
3245 \return list of integer identifiers of all the currently opened views
3248 class TGetViews: public SALOME_Event
3251 typedef QList<int> TResult;
3254 virtual void Execute()
3257 LightApp_Application* app = getApplication();
3259 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3261 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3262 SUIT_ViewWindow* wnd;
3263 foreach ( wnd, wndlist )
3264 myResult.append( wnd->getId() );
3269 QList<int> SalomePyQt::getViews()
3271 return ProcessEvent( new TGetViews() );
3275 \fn int SalomePyQt::getActiveView();
3276 \brief Get integer identifier of the currently active view
3277 \return integer identifier of the currently active view
3280 class TGetActiveView: public SALOME_Event
3283 typedef int TResult;
3287 virtual void Execute()
3289 LightApp_Application* app = getApplication();
3291 SUIT_ViewManager* viewMgr = app->activeViewManager();
3293 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3295 myResult = wnd->getId();
3300 int SalomePyQt::getActiveView()
3302 return ProcessEvent( new TGetActiveView() );
3306 \fn QString SalomePyQt::getViewType( const int id );
3307 \brief Get type of the specified view, e.g. "OCCViewer"
3308 \param id window identifier
3312 class TGetViewType: public SALOME_Event
3315 typedef QString TResult;
3318 TGetViewType( const int id )
3320 virtual void Execute()
3322 SUIT_ViewWindow* wnd = getWnd( myWndId );
3324 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3326 myResult = viewMgr->getType();
3330 QString SalomePyQt::getViewType( const int id )
3332 return ProcessEvent( new TGetViewType( id ) );
3336 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3337 \brief Change view caption
3338 \param id window identifier
3339 \param title new window title
3340 \return \c true if operation is completed successfully and \c false otherwise
3343 class TSetViewTitle: public SALOME_Event
3346 typedef bool TResult;
3350 TSetViewTitle( const int id, const QString& title )
3351 : myResult( false ),
3354 virtual void Execute()
3356 SUIT_ViewWindow* wnd = getWnd( myWndId );
3358 wnd->setWindowTitle( myTitle );
3363 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3365 return ProcessEvent( new TSetViewTitle( id, title ) );
3369 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3370 \brief Set view size
3371 \param w window width
3372 \param h window height
3373 \param id window identifier
3374 \return \c true if operation is completed successfully and \c false otherwise
3377 class TSetViewSize: public SALOME_Event
3380 typedef bool TResult;
3385 TSetViewSize( const int w, const int h, const int id )
3386 : myResult( false ),
3390 virtual void Execute()
3392 SUIT_ViewWindow* wnd = 0;
3394 if ( LightApp_Application* anApp = getApplication() ) {
3395 SUIT_ViewManager* vm = anApp->activeViewManager();
3397 wnd = vm->getActiveView();
3401 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3404 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3406 QString type = viewMgr->getType();
3407 if ( type == "OCCViewer") {
3408 #ifndef DISABLE_OCCVIEWER
3409 // specific processing for OCC viewer:
3410 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3411 // - if there is only one sub-view active; it will be resized;
3412 // - if there are several sub-views, each of them will be resized.
3413 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3414 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3415 if ( occView && occView->getView( i ) ) {
3416 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3420 #endif // DISABLE_OCCVIEWER
3422 else if ( type == "ParaView") {
3423 #ifndef DISABLE_PVVIEWER
3424 // specific processing for ParaView viewer:
3425 // hierarchy of ParaView viewer is much complex than for usual view;
3426 // we look for sub-widget named "Viewport"
3427 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3428 if ( !lst.isEmpty() ) {
3429 lst[0]->resize( myWndWidth, myWndHeight );
3432 #endif // DISABLE_PVVIEWER
3435 if ( wnd->centralWidget() ) {
3436 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3444 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3446 return ProcessEvent( new TSetViewSize( w, h, id ) );
3450 \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3451 \brief Set view rotation point
3452 \param x coordinate X view rotation point
3453 \param y coordinate Y view rotation point
3454 \param z coordinate Z view rotation point
3455 \param id window identifier
3456 \return \c true if operation is completed successfully and \c false otherwise
3459 class TSetViewRotationPoint: public SALOME_Event
3462 typedef bool TResult;
3468 TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3469 : myResult( false ),
3474 virtual void Execute()
3476 SUIT_ViewWindow* wnd = 0;
3478 if ( LightApp_Application* anApp = getApplication() ) {
3479 SUIT_ViewManager* vm = anApp->activeViewManager();
3481 wnd = vm->getActiveView();
3485 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3488 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3490 QString type = viewMgr->getType();
3491 if ( type == "OCCViewer") {
3492 #ifndef DISABLE_OCCVIEWER
3493 // specific processing for OCC viewer:
3494 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3495 // - if there is only one sub-view active; its rotation point will be changed;
3496 // - if there are several sub-views, rotaion points of each of them will be changed.
3497 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3499 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3500 if ( occView && occView->getView( i ) ) {
3501 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3506 #endif // DISABLE_OCCVIEWER
3508 else if ( type == "VTKViewer") {
3509 #ifndef DISABLE_VTKVIEWER
3510 SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3513 double aCenter[3] = { myX, myY, myZ };
3514 vtkView->activateSetRotationSelected( (void*)aCenter );
3517 #endif // DISABLE_VTKVIEWER
3523 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3525 return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3529 \fn QString SalomePyQt::getViewTitle( const int id );
3530 \brief Get view caption
3531 \param id window identifier
3532 \return view caption
3535 class TGetViewTitle: public SALOME_Event
3538 typedef QString TResult;
3541 TGetViewTitle( const int id )
3543 virtual void Execute()
3545 SUIT_ViewWindow* wnd = getWnd( myWndId );
3547 myResult = wnd->windowTitle();
3550 QString SalomePyQt::getViewTitle( const int id )
3552 return ProcessEvent( new TGetViewTitle( id ) );
3556 \fn QList<int> SalomePyQt::findViews( const QString& type );
3557 \brief Get list of integer identifiers of all the
3558 currently opened views of the specified type
3559 \param type viewer type
3560 \return list of integer identifiers
3563 class TFindViews: public SALOME_Event
3566 typedef QList<int> TResult;
3569 TFindViews( const QString& type )
3571 virtual void Execute()
3574 LightApp_Application* app = getApplication();
3576 ViewManagerList vmList;
3577 app->viewManagers( myType, vmList );
3578 SUIT_ViewManager* viewMgr;
3579 foreach ( viewMgr, vmList ) {
3580 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3581 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3582 SUIT_ViewWindow* wnd = vec[ i ];
3585 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3586 myResult.append( wnd->getId() );
3593 QList<int> SalomePyQt::findViews( const QString& type )
3595 return ProcessEvent( new TFindViews( type ) );
3599 \fn bool SalomePyQt::activateView( const int id );
3600 \brief Activate view
3601 \param id window identifier
3602 \return \c true if operation is completed successfully and \c false otherwise
3605 class TActivateView: public SALOME_Event
3608 typedef bool TResult;
3611 TActivateView( const int id )
3612 : myResult( false ),
3614 virtual void Execute()
3616 SUIT_ViewWindow* wnd = getWnd( myWndId );
3617 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3624 bool SalomePyQt::activateView( const int id )
3626 return ProcessEvent( new TActivateView( id ) );
3630 \fn bool SalomePyQt::activateManagerAndView( const int id );
3631 \brief Activate view manager and view: useful for a view embedded in a module main Window
3632 \param id window identifier
3633 \return \c true if operation is completed successfully and \c false otherwise
3636 class TActivateViewManagerAndView: public SALOME_Event
3639 typedef bool TResult;
3642 TActivateViewManagerAndView( const int id )
3643 : myResult( false ),
3645 virtual void Execute()
3647 SUIT_ViewWindow* wnd = getWnd( myWndId );
3648 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3651 LightApp_Application* app = getApplication();
3652 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3658 bool SalomePyQt::activateViewManagerAndView( const int id )
3660 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3667 class TGetViewWidget: public SALOME_Event
3670 typedef QWidget* TResult;
3673 TGetViewWidget( const int id )
3676 virtual void Execute()
3678 SUIT_ViewWindow* wnd = getWnd( myWndId );
3680 myResult = (QWidget*)wnd;
3684 QWidget* SalomePyQt::getViewWidget( const int id)
3686 return ProcessEvent( new TGetViewWidget( id ) );
3691 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3692 \brief Create new view and activate it
3693 \param type viewer type
3697 \return integer identifier of created view (or -1 if view could not be created)
3700 class TCreateView: public SALOME_Event
3703 typedef int TResult;
3710 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3716 myDetached(detached) {}
3717 virtual void Execute()
3719 LightApp_Application* app = getApplication();
3721 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3723 QWidget* wnd = viewMgr->getActiveView();
3724 myResult = viewMgr->getActiveView()->getId();
3727 wnd->setVisible(false);
3728 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3732 if (myWidth > 0 && myHeight > 0) {
3733 #ifndef DISABLE_PLOT2DVIEWER
3734 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3735 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3736 #endif // DISABLE_PLOT2DVIEWER
3737 wnd->setGeometry( 0, 0, myWidth, myHeight );
3744 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3746 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3747 QCoreApplication::processEvents();
3752 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3753 \brief Create new view with custom widget embedded and activate it
3754 \param type viewer type
3755 \param w custom widget
3756 \return integer identifier of created view (or -1 if view could not be created)
3759 class TCreateViewWg: public SALOME_Event
3762 typedef int TResult;
3766 TCreateViewWg( const QString& theType, QWidget* w )
3770 virtual void Execute()
3772 LightApp_Application* app = getApplication();
3774 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3776 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3778 myResult = wnd->getId();
3783 int SalomePyQt::createView( const QString& type, QWidget* w )
3785 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3786 QCoreApplication::processEvents();
3791 \fn bool SalomePyQt::closeView( const int id );
3793 \param id window identifier
3794 \return \c true if operation is completed successfully and \c false otherwise
3797 class TCloseView: public SALOME_Event
3800 typedef bool TResult;
3803 TCloseView( const int id )
3804 : myResult( false ),
3806 virtual void Execute()
3808 SUIT_ViewWindow* wnd = getWnd( myWndId );
3810 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3818 bool SalomePyQt::closeView( const int id )
3820 return ProcessEvent( new TCloseView( id ) );
3824 \fn int SalomePyQt::cloneView( const int id );
3825 \brief Clone view (if this operation is supported for specified view type)
3826 \param id window identifier
3827 \return integer identifier of the cloned view or -1 or operation could not be performed
3830 class TCloneView: public SALOME_Event
3833 typedef int TResult;
3836 TCloneView( const int id )
3839 virtual void Execute()
3841 SUIT_ViewWindow* wnd = getWnd( myWndId );
3843 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3845 #ifndef DISABLE_OCCVIEWER
3846 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3847 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3848 occView->onCloneView();
3849 wnd = viewMgr->getActiveView();
3851 myResult = wnd->getId();
3853 #endif // DISABLE_OCCVIEWER
3854 #ifndef DISABLE_PLOT2DVIEWER
3855 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3856 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3857 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3858 if ( viewMgr2d && srcWnd2d ) {
3859 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3860 myResult = resWnd->getId();
3863 #endif // DISABLE_OCCVIEWER
3868 int SalomePyQt::cloneView( const int id )
3870 return ProcessEvent( new TCloneView( id ) );
3874 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3875 \brief Set view visibility.
3876 \param id window identifier
3877 \param visible new visiblity
3880 void SalomePyQt::setViewVisible( const int id, const bool visible )
3882 class TEvent: public SALOME_Event
3887 TEvent( const int id, const bool visible )
3888 : myWndId( id ), myVisible( visible ) {}
3889 virtual void Execute()
3891 SUIT_ViewWindow* wnd = getWnd( myWndId );
3892 if ( wnd ) wnd->setVisible( myVisible );
3895 ProcessVoidEvent( new TEvent( id, visible ) );
3899 \fn bool SalomePyQt::isViewVisible( const int id );
3900 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3901 \param id window identifier
3902 \return \c true if view is visible and \c false otherwise
3905 class TIsViewVisible: public SALOME_Event
3908 typedef bool TResult;
3911 TIsViewVisible( const int id )
3912 : myResult( false ),
3914 virtual void Execute()
3916 SUIT_ViewWindow* wnd = getWnd( myWndId );
3919 QWidget* p = wnd->parentWidget();
3920 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3924 bool SalomePyQt::isViewVisible( const int id )
3926 return ProcessEvent( new TIsViewVisible( id ) );
3930 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3931 \brief Set / clear view's "closable" option. By default any view is closable
3932 (i.e. can be closed by the user).
3933 \param id window identifier
3934 \param on new "closable" option's value
3937 void SalomePyQt::setViewClosable( const int id, const bool on )
3939 class TEvent: public SALOME_Event
3944 TEvent( const int id, const bool on )
3945 : myWndId( id ), myOn( on ) {}
3946 virtual void Execute()
3948 SUIT_ViewWindow* wnd = getWnd( myWndId );
3949 if ( wnd ) wnd->setClosable( myOn );
3952 ProcessVoidEvent( new TEvent( id, on ) );
3956 \fn bool SalomePyQt::isViewClosable( const int id );
3957 \brief Check whether view is closable (i.e. can be closed by the user)
3958 \param id window identifier
3959 \return \c true if view is closable or \c false otherwise
3962 class TIsViewClosable: public SALOME_Event
3965 typedef bool TResult;
3968 TIsViewClosable( const int id )
3971 virtual void Execute()
3973 SUIT_ViewWindow* wnd = getWnd( myWndId );
3975 myResult = wnd->closable();
3979 bool SalomePyQt::isViewClosable( const int id )
3981 return ProcessEvent( new TIsViewClosable( id ) );
3985 \fn bool SalomePyQt::groupAllViews();
3986 \brief Group all views to the single tab area
3987 \return \c true if operation is completed successfully and \c false otherwise
3990 class TGroupAllViews: public SALOME_Event
3993 typedef bool TResult;
3996 : myResult( false ) {}
3997 virtual void Execute()
3999 LightApp_Application* app = getApplication();
4001 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4003 QtxWorkstack* wStack = tabDesk->workstack();
4012 bool SalomePyQt::groupAllViews()
4014 return ProcessEvent( new TGroupAllViews() );
4018 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
4019 \brief Split tab area to which view with identifier belongs to
4020 \param id window identifier
4021 \param ori orientation of split operation
4022 \param action action to be performed
4023 \return \c true if operation is completed successfully \c false otherwise
4026 class TSplitView: public SALOME_Event
4029 typedef bool TResult;
4034 TSplitView( const int id,
4035 const Orientation ori,
4036 const Action action )
4037 : myResult( false ),
4040 myAction( action ) {}
4041 virtual void Execute()
4043 SUIT_ViewWindow* wnd = getWnd( myWndId );
4046 // wnd->setFocus(); ???
4049 if ( getApplication() ) {
4050 STD_TabDesktop* desk =
4051 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
4053 QtxWorkstack* wStack = desk->workstack();
4055 Qt::Orientation qtOri =
4056 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
4058 QtxWorkstack::SplitType sType;
4059 if ( myAction == MoveWidget )
4060 sType = QtxWorkstack::SplitMove;
4061 else if ( myAction == LeaveWidget )
4062 sType = QtxWorkstack::SplitStay;
4064 sType = QtxWorkstack::SplitAt;
4066 wStack->Split( wnd, qtOri, sType );
4074 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
4076 return ProcessEvent( new TSplitView( id, ori, action ) );
4080 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
4081 \brief Move view with the first identifier to the same area which
4082 another view with the second identifier belongs to
4083 \param id source window identifier
4084 \param id_to destination window identifier
4085 param before specifies whether the first viewt has to be moved before or after
4087 \return \c true if operation is completed successfully and \c false otherwise
4090 class TMoveView: public SALOME_Event
4093 typedef bool TResult;
4098 TMoveView( const int id, const int id_to, const bool before )
4099 : myResult( false ),
4102 myIsBefore( before ) {}
4103 virtual void Execute()
4105 SUIT_ViewWindow* wnd = getWnd( myWndId );
4106 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
4107 if ( wnd && wnd_to ) {
4108 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
4109 getApplication()->desktop() )->workstack();
4111 myResult = wStack->move( wnd, wnd_to, myIsBefore );
4115 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
4117 return ProcessEvent( new TMoveView( id, id_to, before ) );
4121 \fn QList<int> SalomePyQt::neighbourViews( const int id );
4122 \brief Get list of views identifiers that belongs to the same area as
4123 specified view (excluding it)
4124 \param id window identifier
4125 \return list of views identifiers
4128 class TNeighbourViews: public SALOME_Event
4131 typedef QList<int> TResult;
4134 TNeighbourViews( const int id )
4136 virtual void Execute()
4139 SUIT_ViewWindow* wnd = getWnd( myWndId );
4141 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
4142 getApplication()->desktop() )->workstack();
4144 QWidgetList wgList = wStack->windowList( wnd );
4146 foreach ( wg, wgList ) {
4147 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
4148 if ( tmpWnd && tmpWnd != wnd )
4149 myResult.append( tmpWnd->getId() );
4155 QList<int> SalomePyQt::neighbourViews( const int id )
4157 return ProcessEvent( new TNeighbourViews( id ) );
4162 \fn void SalomePyQt::createRoot();
4163 \brief Initialize root data object.
4165 Does nothing if root is already initialized.
4168 void SalomePyQt::createRoot()
4170 class TEvent: public SALOME_Event
4174 virtual void Execute()
4176 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4178 SALOME_PYQT_DataModelLight* dm =
4179 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
4184 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
4188 ProcessVoidEvent( new TEvent() );
4192 \fn QString SalomePyQt::createObject( const QString& parent );
4193 \brief Create empty data object
4194 \param parent entry of parent data object
4195 \return entry of created data object
4198 class TCreateEmptyObjectEvent: public SALOME_Event
4201 typedef QString TResult;
4204 TCreateEmptyObjectEvent( const QString& parent )
4205 : myParent( parent ) {}
4206 virtual void Execute()
4208 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4210 myResult = module->createObject( myParent );
4213 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
4217 QString SalomePyQt::createObject( const QString& parent )
4219 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
4223 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
4224 const QString& tooltip,const QString& parent );
4225 \brief Create new data object with specified name, icon and tooltip
4226 \param name data object name
4227 \param icon data object icon
4228 \param toolTip data object tooltip
4229 \param parent entry of parent data object
4230 \return entry of created data object
4233 class TCreateObjectEvent: public SALOME_Event
4236 typedef QString TResult;
4242 TCreateObjectEvent( const QString& name,
4243 const QString& icon,
4244 const QString& tooltip,
4245 const QString& parent )
4246 : myParent( parent ),
4249 myToolTip( tooltip ) {}
4250 virtual void Execute()
4252 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4254 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
4257 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
4261 QString SalomePyQt::createObject( const QString& name,
4262 const QString& icon,
4263 const QString& toolTip,
4264 const QString& parent )
4266 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
4271 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
4272 \brief Set data object name
4273 \param entry data object entry
4274 \param name data object name
4276 class TSetNameEvent: public SALOME_Event
4281 TSetNameEvent( const QString& entry,
4282 const QString& name )
4285 virtual void Execute()
4287 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4289 module->setName( myEntry, myName );
4292 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
4296 void SalomePyQt::setName( const QString& entry, const QString& name )
4298 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
4302 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
4303 \brief Set data object icon
4304 \param entry data object entry
4305 \param icon data object icon file name (icon is loaded from module resources)
4308 class TSetIconEvent: public SALOME_Event
4313 TSetIconEvent( const QString& entry,
4314 const QString& icon )
4317 virtual void Execute()
4319 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4321 module->setIcon( myEntry, myIcon );
4324 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4329 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4331 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4335 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4336 \brief Set data object tooltip
4337 \param entry data object entry
4338 \param toolTip data object tooltip
4341 class TSetToolTipEvent: public SALOME_Event
4346 TSetToolTipEvent( const QString& entry,
4347 const QString& toolTip )
4349 myToolTip( toolTip ) {}
4350 virtual void Execute()
4352 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4354 module->setToolTip( myEntry, myToolTip );
4357 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4361 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4363 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4367 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4368 \brief Set reference to another data object
4369 \param entry data object entry
4370 \param refEntry referenced data object entry
4373 class TSetRefEvent: public SALOME_Event
4378 TSetRefEvent( const QString& entry,
4379 const QString& refEntry )
4381 myRefEntry( refEntry ) {}
4382 virtual void Execute()
4384 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4386 module->setReference( myEntry, myRefEntry );
4389 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4393 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4395 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4399 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4400 \brief Set data object color
4401 \param entry data object entry
4402 \param color data object color
4405 class TSetColorEvent: public SALOME_Event
4410 TSetColorEvent( const QString& entry,
4411 const QColor& color )
4414 virtual void Execute()
4416 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4418 module->setColor( myEntry, myColor );
4421 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4425 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4427 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4431 \fn QString SalomePyQt::getName( const QString& entry );
4432 \brief Get data object name
4433 \param entry data object entry
4434 \return data object name
4437 class TGetNameEvent: public SALOME_Event
4440 typedef QString TResult;
4443 TGetNameEvent( const QString& entry )
4444 : myEntry( entry ) {}
4445 virtual void Execute()
4447 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4449 myResult = module->getName( myEntry );
4452 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4456 QString SalomePyQt::getName( const QString& entry )
4458 return ProcessEvent( new TGetNameEvent( entry ) );
4462 \fn QString SalomePyQt::getToolTip( const QString& entry );
4463 \brief Get data object tooltip
4464 \param entry data object entry
4465 \return data object tooltip
4468 class TGetToolTipEvent: public SALOME_Event
4471 typedef QString TResult;
4474 TGetToolTipEvent( const QString& entry )
4475 : myEntry( entry ) {}
4476 virtual void Execute()
4478 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4480 myResult = module->getToolTip( myEntry );
4483 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4487 QString SalomePyQt::getToolTip( const QString& entry )
4489 return ProcessEvent( new TGetToolTipEvent( entry ) );
4493 \fn QString SalomePyQt::getReference( const QString& entry );
4494 \brief Get entry of the referenced object (if there's any)
4495 \param entry data object entry
4496 \return referenced data object entry
4499 class TGetRefEvent: public SALOME_Event
4502 typedef QString TResult;
4505 TGetRefEvent( const QString& entry )
4506 : myEntry( entry ) {}
4507 virtual void Execute()
4509 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4511 myResult = module->getReference( myEntry );
4514 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4518 QString SalomePyQt::getReference( const QString& entry )
4520 return ProcessEvent( new TGetRefEvent( entry ) );
4524 \fn QColor SalomePyQt::getColor( const QString& entry );
4525 \brief Get data object color
4526 \param entry data object entry
4527 \return data object color
4530 class TGetColorEvent: public SALOME_Event
4533 typedef QColor TResult;
4536 TGetColorEvent( const QString& entry )
4537 : myEntry( entry ) {}
4538 virtual void Execute()
4540 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4542 myResult = module->getColor( myEntry );
4545 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4549 QColor SalomePyQt::getColor( const QString& entry )
4551 return ProcessEvent( new TGetColorEvent( entry ) );
4555 \fn void SalomePyQt::removeChildren( const QString& entry );
4556 \brief Remove all child data objects from specified data object
4557 \param entry data object entry
4560 class TRemoveChildEvent: public SALOME_Event
4564 TRemoveChildEvent( const QString& entry )
4565 : myEntry( entry ) {}
4566 virtual void Execute()
4568 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4570 module->removeChildren( myEntry );
4573 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4577 void SalomePyQt::removeChildren( const QString& entry )
4579 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4581 void SalomePyQt::removeChild( const QString& entry )
4583 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4584 removeChildren( entry );
4588 \fn void SalomePyQt::removeObject( const QString& entry );
4589 \brief Remove object by entry
4590 \param entry data object entry
4593 class TRemoveObjectEvent: public SALOME_Event
4598 TRemoveObjectEvent( const QString& entry )
4599 : myEntry( entry ) {}
4600 virtual void Execute()
4602 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4604 module->removeObject( myEntry );
4607 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4611 void SalomePyQt::removeObject( const QString& entry )
4613 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4617 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4618 \brief Get entries of all child data objects of specified data object
4619 \param entry data object entry
4620 \param recursive \c true for recursive processing
4623 class TGetChildrenEvent: public SALOME_Event
4626 typedef QStringList TResult;
4630 TGetChildrenEvent( const QString& entry, const bool recursive )
4632 myRecursive( recursive ) {}
4633 virtual void Execute()
4635 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4637 myResult = module->getChildren( myEntry, myRecursive );
4640 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4644 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4646 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4649 #ifndef DISABLE_PLOT2DVIEWER
4650 // Next set of methods relates to the Plot2d viewer functionality
4653 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4654 \brief Display theCurve in view
4655 \param id window identifier
4656 \param theCurve curve to display
4659 class TDisplayCurve: public SALOME_Event
4663 Plot2d_Curve* myCurve;
4664 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4665 virtual void Execute() {
4666 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4668 wnd->getViewFrame()->displayCurve( myCurve );
4671 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4673 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4677 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4678 \brief Erase theCurve in view
4679 \param id window identifier
4680 \param theCurve curve to erase
4683 class TEraseCurve: public SALOME_Event
4687 Plot2d_Curve* myCurve;
4688 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4689 virtual void Execute() {
4690 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4691 wnd->getViewFrame()->eraseCurve( myCurve );
4694 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4696 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4700 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4701 \brief Delete theCurve from all views
4702 \param theCurve curve to delete
4705 class TDeleteCurve: public SALOME_Event
4708 Plot2d_Curve* myCurve;
4709 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4710 virtual void Execute() {
4711 LightApp_Application* app = getApplication();
4713 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4715 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4716 SUIT_ViewWindow* wnd;
4717 foreach ( wnd, wndlist ) {
4718 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4720 aP2d->getViewFrame()->eraseObject( myCurve );
4726 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4728 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4732 \brief updateCurves (repaint) curves in view window.
4734 void SalomePyQt::updateCurves( const int id )
4736 class TEvent: public SALOME_Event
4740 TEvent( const int id ) : myWndId( id ) {}
4741 virtual void Execute()
4743 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4745 wnd->getViewFrame()->DisplayAll();
4748 ProcessVoidEvent( new TEvent( id ) );
4752 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4753 \brief Get title of corresponding type
4754 \param id window identifier
4755 \param type is type of title
4756 \return title of corresponding type
4759 class TGetPlot2dTitle: public SALOME_Event
4762 typedef QString TResult;
4766 TGetPlot2dTitle(const int id, ObjectType type) :
4769 virtual void Execute() {
4770 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4772 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4775 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4777 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4782 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4783 \brief Set title of corresponding type
4784 \param id window identifier
4786 \param type is type of title
4790 class TSetPlot2dTitle: public SALOME_Event
4794 Plot2d_Curve* myCurve;
4798 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4803 virtual void Execute() {
4804 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4805 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4808 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4810 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4814 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4815 \brief Get list of Plot2d view ranges
4816 \param id window identifier
4817 \return list of view ranges (XMin, XMax, YMin, YMax)
4820 class TFitRangeByCurves: public SALOME_Event
4823 typedef QList<double> TResult;
4826 TFitRangeByCurves( const int id )
4828 virtual void Execute()
4831 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4833 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4834 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4835 myResult.append( XMin );
4836 myResult.append( XMax );
4837 myResult.append( YMin );
4838 myResult.append( YMax );
4842 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4844 return ProcessEvent( new TFitRangeByCurves( id ) );
4848 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4849 \brief Get list of current Plot2d view ranges
4850 \param id window identifier
4851 \return list of view ranges (XMin, XMax, YMin, YMax)
4854 class TFitRangeCurrent: public SALOME_Event
4857 typedef QList<double> TResult;
4860 TFitRangeCurrent( const int id )
4862 virtual void Execute()
4865 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4867 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4868 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4869 myResult.append( XMin );
4870 myResult.append( XMax );
4871 myResult.append( YMin );
4872 myResult.append( YMax );
4876 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4878 return ProcessEvent( new TFitRangeCurrent( id ) );
4882 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4883 \brief Set range of Plot2d view
4884 \param id window identifier
4891 class TPlot2dFitRange: public SALOME_Event
4899 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4905 virtual void Execute() {
4906 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4908 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4911 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4913 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4916 // End of methods related to the Plot2d viewer functionality
4917 #endif // DISABLE_PLOT2DVIEWER
4920 \brief Process Qt event loop
4922 void SalomePyQt::processEvents()
4924 QCoreApplication::processEvents();
4928 \brief Set visibility state for given object
4929 \param theEntry study ID of the object
4930 \param theState visibility state
4932 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4934 class TEvent: public SALOME_Event
4939 TEvent( const QString& theEntry, int theState ):
4940 myEntry( theEntry ), myState( theState ) {}
4941 virtual void Execute()
4943 LightApp_Study* aStudy = getActiveStudy();
4946 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4949 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4953 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4954 \brief Get visibility state for given object
4955 \param theEntry study ID of the object
4956 \return visibility state
4959 class TGetVisibilityStateEvent: public SALOME_Event
4962 typedef int TResult;
4965 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4966 virtual void Execute()
4968 LightApp_Study* aStudy = getActiveStudy();
4970 myResult = aStudy->visibilityState( myEntry );
4973 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4975 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4979 \brief Set position of given object in the tree
4980 \param theEntry study ID of the object
4981 \param thePos position
4983 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4985 class TEvent: public SALOME_Event
4990 TEvent( const QString& theEntry, int thePos ):
4991 myEntry( theEntry ), myPos( thePos ) {}
4992 virtual void Execute()
4994 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4996 module->setObjectPosition( myEntry, myPos );
4999 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
5003 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
5004 \brief Get position of given object in the tree
5005 \param theEntry study ID of the object
5009 class TGetObjectPositionEvent: public SALOME_Event
5012 typedef int TResult;
5015 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
5016 virtual void Execute()
5018 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
5020 myResult = module->getObjectPosition( myEntry );
5023 int SalomePyQt::getObjectPosition( const QString& theEntry )
5025 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
5029 \brief Start recordind a log of Python commands from embedded console
5030 \param theFileName output lof file name
5032 void SalomePyQt::startPyLog( const QString& theFileName )
5034 class TEvent: public SALOME_Event
5038 TEvent( const QString& theFileName ):
5039 myFileName( theFileName ) {}
5040 virtual void Execute()
5042 if ( getApplication() ) {
5043 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
5044 if ( pyConsole ) pyConsole->startLog( myFileName );
5048 ProcessVoidEvent( new TEvent( theFileName ) );
5052 \brief Stop recordind a log of Python commands from embedded console
5054 void SalomePyQt::stopPyLog()
5056 class TEvent: public SALOME_Event
5060 virtual void Execute()
5062 if ( getApplication() ) {
5063 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
5064 if ( pyConsole ) pyConsole->stopLog();
5068 ProcessVoidEvent( new TEvent() );