1 // Copyright (C) 2007-2022 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 QWidget* myActiveWindow;
232 QWidget* myFocusedWidget;
235 myActiveWindow = QApplication::activeWindow();
236 myFocusedWidget = QApplication::focusWidget();
237 QApplication::setActiveWindow( getApplication()->desktop() );
241 if ( myActiveWindow )
242 QApplication::setActiveWindow( myActiveWindow );
243 if ( myFocusedWidget )
244 myFocusedWidget->setFocus();
250 \class SALOME_Selection
251 \brief The class represents selection which can be used in Python.
255 \brief Get the selection object for the specified application.
257 Finds or creates the selection object (one per study).
259 \param app application object
260 \return selection object or 0 if \a app is invalid
262 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
264 SALOME_Selection* sel = 0;
265 if ( app && SelMap.find( app ) != SelMap.end() )
268 sel = SelMap[ app ] = new SALOME_Selection( app );
275 \param p parent object
277 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
279 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
281 mySelMgr = app->selectionMgr();
282 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
283 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
290 SALOME_Selection::~SALOME_Selection()
292 LightApp_Application* app = 0;
293 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
294 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
295 if ( it.value() == this ) app = it.key();
297 if ( app ) SelMap.remove( app );
301 \brief Called when selection manager is destroyed (usually
302 when the study is closed).
304 void SALOME_Selection::onSelMgrDestroyed()
310 \brief Clear the selection.
312 void SALOME_Selection::Clear()
314 class TEvent: public SALOME_Event
316 LightApp_SelectionMgr* mySelMgr;
318 TEvent( LightApp_SelectionMgr* selMgr )
319 : mySelMgr( selMgr ) {}
320 virtual void Execute()
323 mySelMgr->clearSelected();
326 ProcessVoidEvent( new TEvent( mySelMgr ) );
330 \brief Clear the selection.
332 void SALOME_Selection::ClearIObjects()
338 Removes all selection filters.
340 void SALOME_Selection::ClearFilters()
342 class TEvent: public SALOME_Event
344 LightApp_SelectionMgr* mySelMgr;
346 TEvent( LightApp_SelectionMgr* selMgr )
347 : mySelMgr( selMgr ) {}
348 virtual void Execute()
351 mySelMgr->clearFilters();
354 ProcessVoidEvent( new TEvent( mySelMgr ) );
358 \class UserDefinedContent
359 \brief The class represents base class for user defined widget that
360 can be inserted to the Preferences dialog.
366 UserDefinedContent::UserDefinedContent()
372 \brief Called from Preferences dialog to store settings to the resource file.
374 void UserDefinedContent::store()
379 \brief Called from Preferences dialog to restore settings from the resource file.
381 void UserDefinedContent::retrieve()
386 \class SgPyQtUserDefinedContent
387 \brief A Wrapper for UserDefinedContent class.
390 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
393 SgPyQtUserDefinedContent(UserDefinedContent*);
394 virtual ~SgPyQtUserDefinedContent();
396 void store( QtxResourceMgr*, QtxPreferenceMgr* );
397 void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
400 UserDefinedContent* myContent;
404 \brief Create custom item for Preferences dialog wrapping widget passed from Python.
407 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
408 : QtxUserDefinedContent( 0 ), myContent( content )
410 QVBoxLayout* l = new QVBoxLayout( this );
411 l->setContentsMargins( 0, 0, 0, 0 );
412 l->addWidget( myContent );
419 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
424 \brief Called from Preferences dialog to store settings to the resource file.
427 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
433 \brief Called from Preferences dialog to restore settings from the resource file.
436 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
438 myContent->retrieve();
443 \brief The class provides utility functions which can be used in the Python
444 to operate with the SALOME GUI.
446 All the functionality of this class is implemented as static methods, so they
447 can be called with the class name prefixed or via creation of the class instance.
448 For example, next both ways of SalomePyQt class usage are legal:
450 from SalomePyQt import *
452 # using SalomePyQt class instance
453 desktop = sg.getDesktop()
454 # using SalomePyQt class directly
455 menubar = SalomePyQt.getMainMenuBar()
460 \fn QString SalomePyQt::getAppName();
461 \brief Get application name
462 \return application name
465 QString SalomePyQt::getAppName()
467 LightApp_Application* app = getApplication();
468 return app == 0 ? QString() : QString(app->metaObject()->className()).split("_").first();
472 \fn bool SalomePyQt::isLightApp();
473 \brief Check if SALOME GUI is running in "light" mode.
474 \return \c true if this is a "light" application; \c false otherwise
477 bool SalomePyQt::isLightApp()
479 return SalomePyQt::getAppName() != "SalomeApp";
483 \fn QWidget* SalomePyQt::getDesktop();
484 \brief Get the active application's desktop window.
485 \return desktop window or 0 if there is no any
488 class TGetDesktopEvent: public SALOME_Event
491 typedef QWidget* TResult;
493 TGetDesktopEvent() : myResult( 0 ) {}
494 virtual void Execute()
496 if ( getApplication() )
497 myResult = (QWidget*)( getApplication()->desktop() );
500 QWidget* SalomePyQt::getDesktop()
502 return ProcessEvent( new TGetDesktopEvent() );
506 \fn QWidget* SalomePyQt::getMainFrame();
507 \brief Get current application's main frame widget [obsolete].
509 Main frame widget is an internal widget of the application
510 desktop window (workspace).
512 \return workspace widget (0 on any error)
515 class TGetMainFrameEvent: public SALOME_Event
518 typedef QWidget* TResult;
520 TGetMainFrameEvent() : myResult( 0 ) {}
521 virtual void Execute()
523 if ( getApplication() ) {
524 SUIT_Desktop* aDesktop = getApplication()->desktop();
525 myResult = (QWidget*)( aDesktop->centralWidget() );
529 QWidget* SalomePyQt::getMainFrame()
531 return ProcessEvent( new TGetMainFrameEvent() );
535 \fn QMenuBar* SalomePyQt::getMainMenuBar();
536 \brief Get current application desktop's main menu.
537 \return main menu object (0 on any error)
540 class TGetMainMenuBarEvent: public SALOME_Event
543 typedef QMenuBar* TResult;
545 TGetMainMenuBarEvent() : myResult( 0 ) {}
546 virtual void Execute()
548 if ( LightApp_Application* anApp = getApplication() ) {
549 myResult = anApp->desktop()->menuBar();
553 QMenuBar* SalomePyQt::getMainMenuBar()
555 return ProcessEvent( new TGetMainMenuBarEvent() );
559 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
560 \brief Get main menu's child popup submenu by its identifier.
562 This function is obsolete.
563 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
565 \param menu menu identifier
566 \return popup submenu object or 0 if it does not exist
570 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
571 \brief Get main menu's child popup submenu by its name.
573 The function creates menu if it does not exist.
575 \param menu menu name
576 \return popup submenu object (0 on any error)
579 class TGetPopupMenuEvent: public SALOME_Event
582 typedef QMenu* TResult;
585 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
586 virtual void Execute()
588 LightApp_Application* anApp = getApplication();
589 if ( anApp && !myMenuName.isEmpty() ) {
590 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
591 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
596 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
601 menuName = getMenuName( "MEN_DESK_FILE" ); break;
603 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
605 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
607 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
609 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
611 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
613 menuName = getMenuName( "MEN_DESK_HELP" ); break;
615 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
617 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
619 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
623 \fn QTreeView* SalomePyQt::getObjectBrowser();
624 \brief Get object browser
625 \return object browser for the active study or 0 in case of error
628 class TGetObjectBrowserEvent: public SALOME_Event
631 typedef QTreeView* TResult;
633 TGetObjectBrowserEvent() : myResult( 0 ) {}
634 virtual void Execute()
636 LightApp_Application* anApp = getApplication();
637 if ( anApp && anApp->objectBrowser() ) {
638 myResult = anApp->objectBrowser()->treeView();
642 QTreeView* SalomePyQt::getObjectBrowser()
644 return ProcessEvent( new TGetObjectBrowserEvent() );
648 \fn SALOME_Selection* SalomePyQt::getSelection();
649 \brief Get the selection object for the current study.
651 Creates a Selection object if it has not been created yet.
653 \return selection object (0 on error)
656 class TGetSelectionEvent: public SALOME_Event
659 typedef SALOME_Selection* TResult;
661 TGetSelectionEvent() : myResult( 0 ) {}
662 virtual void Execute()
664 myResult = SALOME_Selection::GetSelection( getApplication() );
667 SALOME_Selection* SalomePyQt::getSelection()
669 return ProcessEvent( new TGetSelectionEvent() );
673 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
674 \brief Send local selection for notification.
676 The list of locally selected objects (study entries) is sent for notification of
677 other listening entities (modules, viewers...).
680 class TSetSelectionEvent: public SALOME_Event
682 QStringList myEntryList;
684 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
685 virtual void Execute()
687 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
688 if ( !module ) return;
689 module->setLocalSelected(myEntryList);
692 void SalomePyQt::setSelection( const QStringList& entryList)
694 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
698 \fn void SalomePyQt::enableSelector();
699 \brief enable PyQt_Selector (on module activation, for instance)
702 class TEnableSelectorEvent: public SALOME_Event
705 TEnableSelectorEvent() {}
706 virtual void Execute()
708 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
709 if ( !module ) return;
710 module->enableSelector();
713 void SalomePyQt::enableSelector()
715 return ProcessVoidEvent( new TEnableSelectorEvent() );
720 \fn void SalomePyQt::disableSelector();
721 \brief disable PyQt_Selector (on module activation, for instance)
724 class TdisableSelectorEvent: public SALOME_Event
727 TdisableSelectorEvent() {}
728 virtual void Execute()
730 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
731 if ( !module ) return;
732 module->disableSelector();
735 void SalomePyQt::disableSelector()
737 return ProcessVoidEvent( new TdisableSelectorEvent() );
742 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
743 \brief Put an information message to the current application's
746 Optional second delay parameter (\a sec) can be used to specify
747 time of the message diplaying in seconds. If this parameter is less
748 or equal to zero, the constant message will be put.
750 \param msg message text
751 \param sec message displaying time in seconds
754 class TPutInfoEvent: public SALOME_Event
759 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
760 virtual void Execute()
762 if ( LightApp_Application* anApp = getApplication() ) {
763 anApp->putInfo( myMsg, mySecs * 1000 );
767 void SalomePyQt::putInfo( const QString& msg, const int sec )
769 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
773 \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
774 \brief Show notification in the application's desktop window.
776 Optional third delay parameter (\a sec) can be used to specify
777 time of the notification diplaying in seconds. If this parameter is less
778 or equal to zero, the permanent notification will be put.
780 Notification can be forcibly hidden via hideNotification() method.
782 \param msg message text
783 \param title title text
784 \param sec notification displaying time in seconds
785 \return unique ID of the notification (can be used to hide notification)
786 \sa hideNotification()
789 class TShowNotifyEvent: public SALOME_Event
800 TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
801 virtual void Execute()
803 if ( LightApp_Application* anApp = getApplication() ) {
804 myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
809 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
811 return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
815 \fn void SalomePyQt::hideNotification( const QString& msg );
816 \brief Remove notification with given message text from the application's desktop.
818 \param msg message text
819 \sa showNotification()
823 \fn void SalomePyQt::hideNotification( const int id );
824 \brief Remove notification with given \a id from the application's desktop.
826 \param id notification id
827 \sa showNotification()
830 class THideNotifyEvent: public SALOME_Event
836 THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
837 THideNotifyEvent( const int id ) : myId( id ) {}
838 virtual void Execute()
840 if ( LightApp_Application* anApp = getApplication() ) {
842 anApp->hideNotification( myId );
844 anApp->hideNotification( myMsg );
849 void SalomePyQt::hideNotification( const QString& msg )
851 ProcessVoidEvent( new THideNotifyEvent( msg ) );
854 void SalomePyQt::hideNotification( const int id )
856 ProcessVoidEvent( new THideNotifyEvent( id ) );
860 \fn QStringList SalomePyQt::getComponents();
861 \brief Get all modules used in current GUI session.
862 \return List of modules
865 class TGetComponentsEvent: public SALOME_Event
868 typedef QStringList TResult;
870 TGetComponentsEvent() {}
871 virtual void Execute()
873 if ( LightApp_Application* anApp = getApplication() )
876 anApp->modules( titles, false );
877 foreach ( QString title, titles )
879 myResult << anApp->moduleName( title );
884 QStringList SalomePyQt::getComponents()
886 return ProcessEvent( new TGetComponentsEvent() );
890 \fn const QString SalomePyQt::getActiveComponent();
891 \brief Get the currently active module name (for the current study).
892 \return active module name or empty string if there is no active module
895 class TGetActiveComponentEvent: public SALOME_Event
898 typedef QString TResult;
900 TGetActiveComponentEvent() {}
901 virtual void Execute()
903 if ( LightApp_Application* anApp = getApplication() ) {
904 if ( CAM_Module* mod = anApp->activeModule() ) {
905 myResult = mod->name();
910 const QString SalomePyQt::getActiveComponent()
912 return ProcessEvent( new TGetActiveComponentEvent() );
916 \fn PyObject* SalomePyQt::getActivePythonModule();
917 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
918 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
921 class TGetActivePyModuleEvent: public SALOME_Event
924 typedef PyObject* TResult;
926 TGetActivePyModuleEvent() : myResult( Py_None ) {}
927 virtual void Execute()
929 PyModuleHelper* helper = getPythonHelper();
931 myResult = (PyObject*)helper->pythonModule();
934 PyObject* SalomePyQt::getActivePythonModule()
936 return ProcessEvent( new TGetActivePyModuleEvent() );
940 \fn bool SalomePyQt::activateModule( const QString& modName );
941 \brief Activates SALOME module with the given name
942 \return True if the module has been activated and False otherwise.
945 class TActivateModuleEvent: public SALOME_Event
948 typedef bool TResult;
950 QString myModuleName;
951 TActivateModuleEvent( const QString& modName )
952 : myResult( false ), myModuleName( modName ) {}
953 virtual void Execute()
955 if ( LightApp_Application* anApp = getApplication() ) {
957 myResult = anApp->activateModule( myModuleName );
961 bool SalomePyQt::activateModule( const QString& modName )
963 return ProcessEvent( new TActivateModuleEvent( modName ) );
967 \fn void SalomePyQt::registerModule( const QString& modName);
968 \brief Registers module in the study tree
971 void SalomePyQt::registerModule( const QString& modName)
973 class TEvent: public SALOME_Event
977 TEvent(const QString& name): myName(name) {}
978 virtual void Execute()
980 if ( LightApp_Application* anApp = getApplication() ) {
981 anApp->desktop()->emitMessage(QString("register_module_in_study/%1").arg(myName));
985 ProcessVoidEvent( new TEvent(modName) );
989 \brief Update an Object Browser of the study.
991 void SalomePyQt::updateObjBrowser()
993 class TEvent: public SALOME_Event
997 virtual void Execute()
999 if ( SUIT_Session::session() ) {
1000 if ( getActiveStudy() ) {
1001 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
1002 QList<SUIT_Application*>::Iterator it;
1003 for( it = apps.begin(); it != apps.end(); ++it ) {
1004 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
1005 if ( anApp && anApp->activeStudy() ) {
1006 anApp->updateObjectBrowser();
1014 ProcessVoidEvent( new TEvent() );
1019 SalomePyQt::isModified()
1020 \return The modification status of the data model
1021 for the currently active Python module
1022 \note This function is supported for "light" Python-based SALOME modules only.
1025 class TIsModifiedEvent: public SALOME_Event
1028 typedef bool TResult;
1030 TIsModifiedEvent() : myResult( false ) {}
1031 virtual void Execute()
1033 LightApp_Module* module = getActiveModule();
1037 SALOME_PYQT_DataModelLight* aModel =
1038 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1040 myResult = aModel->isModified();
1043 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
1047 bool SalomePyQt::isModified()
1049 return ProcessEvent(new TIsModifiedEvent());
1053 SalomePyQt::setModified()
1055 Sets the modification status of the data model for
1056 the currently active Python module. This method should be used
1057 by the Python code in order to enable/disable "Save" operation
1058 depending on the module's data state.
1060 \note This function is supported for "light" Python-based SALOME modules only.
1062 \param New modification status of the data model
1066 void SalomePyQt::setModified( bool flag )
1068 class TEvent: public SALOME_Event
1074 virtual void Execute()
1076 LightApp_Module* module = getActiveModule();
1080 SALOME_PYQT_DataModelLight* model =
1081 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1083 LightApp_Application* app = module->getApp();
1085 if ( model && app ) {
1086 model->setModified( myFlag );
1087 app->updateActions();
1090 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1094 ProcessVoidEvent( new TEvent( flag ) );
1098 \brief Add string setting to the application preferences.
1100 The parameter \a autoValue is obsolete parameter and currently is not used.
1101 This parameter will be removed in future, so try to avoid its usage in
1104 This function is obsolete. Use one of addSetting() instead.
1106 \param name setting name (it should be of kind <section:setting> where
1107 \c section is resources section name and \c setting is setting name)
1108 \param value new setting value
1109 \param autoValue (not used)
1111 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1113 class TEvent: public SALOME_Event
1119 TEvent( const QString& name, const QString& value, bool autoValue )
1120 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1121 virtual void Execute()
1123 if ( SUIT_Session::session() ) {
1124 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1125 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1126 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1127 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1128 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1129 resMgr->setValue( _sec, _nam, myValue );
1133 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1137 \brief Add integer setting to the application preferences.
1139 The parameter \a autoValue is obsolete parameter and currently is not used.
1140 This parameter will be removed in future, so try to avoid its usage in
1143 This function is obsolete. Use one of addSetting() instead.
1145 \param name setting name (it should be of kind <section:setting> where
1146 \c section is resources section name and \c setting is setting name)
1147 \param value new setting value
1148 \param autoValue (not used)
1150 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1152 class TEvent: public SALOME_Event
1158 TEvent( const QString& name, const int value, bool autoValue )
1159 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1160 virtual void Execute()
1162 if ( SUIT_Session::session() ) {
1163 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1164 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1165 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1166 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1167 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1168 resMgr->setValue( _sec, _nam, myValue );
1172 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1176 \brief Add double setting to the application preferences.
1178 The parameter \a autoValue is obsolete parameter and currently is not used.
1179 This parameter will be removed in future, so try to avoid its usage in
1182 This function is obsolete. Use one of addSetting() instead.
1184 \param name setting name (it should be of kind <section:setting> where
1185 \c section is resources section name and \c setting is setting name)
1186 \param value new setting value
1187 \param autoValue (not used)
1189 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1191 class TEvent: public SALOME_Event
1197 TEvent( const QString& name, const double value, bool autoValue )
1198 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1199 virtual void Execute()
1201 if ( SUIT_Session::session() ) {
1202 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1203 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1204 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1205 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1206 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1207 resMgr->setValue( _sec, _nam, myValue );
1211 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1215 \brief Add boolean setting to the application preferences.
1217 The parameter \a autoValue is obsolete parameter and currently is not used.
1218 This parameter will be removed in future, so try to avoid its usage in
1221 This function is obsolete. Use one of addSetting() instead.
1223 \param name setting name (it should be of kind <section:setting> where
1224 \c section is resources section name and \c setting is setting name)
1225 \param value new setting value
1226 \param autoValue (not used)
1228 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1230 class TEvent: public SALOME_Event
1236 TEvent( const QString& name, const bool value, bool autoValue )
1237 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1238 virtual void Execute()
1240 if ( SUIT_Session::session() ) {
1241 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1242 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1243 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1244 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1245 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1246 resMgr->setValue( _sec, _nam, myValue );
1250 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1254 \brief Remove setting from the application preferences.
1256 This function is obsolete. Use removeSetting() instead.
1258 \param name setting name (it should be of kind <section:setting> where
1259 \c section is resources section name and \c setting is setting name)
1261 void SalomePyQt::removeSettings( const QString& name )
1263 class TEvent: public SALOME_Event
1267 TEvent( const QString& name ) : myName( name ) {}
1268 virtual void Execute()
1270 if ( SUIT_Session::session() ) {
1271 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1272 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1273 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1274 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1275 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1276 resMgr->remove( _sec, _nam );
1280 ProcessVoidEvent( new TEvent( name ) );
1284 \fn QString SalomePyQt::getSetting( const QString& name );
1285 \brief Get application setting value (as string represenation).
1287 This function is obsolete. Use stringSetting(), integerSetting(),
1288 boolSetting(), stringSetting() or colorSetting() instead.
1290 \param name setting name (it should be of kind <section:setting> where
1291 \c section is resources section name and \c setting is setting name)
1292 \return setting name (empty string if setting name is invalid)
1295 class TGetSettingEvent: public SALOME_Event
1298 typedef QString TResult;
1301 TGetSettingEvent( const QString& name ) : myName( name ) {}
1302 virtual void Execute()
1304 if ( SUIT_Session::session() ) {
1305 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1306 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1307 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1308 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1309 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1313 QString SalomePyQt::getSetting( const QString& name )
1315 return ProcessEvent( new TGetSettingEvent( name ) );
1319 \fn QString SalomePyQt::constant( const QString& name );
1320 \brief Get constant's value from application's resource manager.
1322 \param name name of the constant
1323 \return value of the constant
1328 class TGetConstantEvent: public SALOME_Event
1331 typedef QString TResult;
1334 TGetConstantEvent( const QString& name ) : myName( name ) {}
1335 virtual void Execute()
1337 if ( SUIT_Session::session() )
1338 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1341 QString SalomePyQt::constant( const QString& name )
1343 return ProcessEvent( new TGetConstantEvent( name ) );
1347 \brief Add constant to the application's resource manager.
1349 This function is useful to specify programmatically specific
1350 variables that are referenced in the resource setting.
1352 For example, some resource value can be set as "$(myroot)/data/files".
1353 Then, "mypath" constant can be set programmatically by the application
1354 depending on run-time requirements.
1356 \param section resources file section name
1357 \param name name of the constant
1358 \param value value of the constant
1362 void SalomePyQt::setConstant( const QString& name, const QString& value )
1364 class TEvent: public SALOME_Event
1366 QString myName, myValue;
1368 TEvent( const QString& name, const QString& value )
1369 : myName( name ), myValue( value ) {}
1370 virtual void Execute()
1372 if ( SUIT_Session::session() )
1373 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1376 ProcessVoidEvent( new TEvent( name, value ) );
1380 \brief Add double setting to the application preferences.
1381 \param section resources file section name
1382 \param name setting name
1383 \param value new setting value
1385 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1387 class TEvent: public SALOME_Event
1393 TEvent( const QString& section, const QString& name, double value )
1394 : mySection( section ), myName( name ), myValue( value ) {}
1395 virtual void Execute()
1397 if ( SUIT_Session::session() ) {
1398 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1399 if ( !mySection.isEmpty() && !myName.isEmpty() )
1400 resMgr->setValue( mySection, myName, myValue );
1404 ProcessVoidEvent( new TEvent( section, name, value ) );
1408 \brief Add integer setting to the application preferences.
1409 \param section resources file section name
1410 \param name setting name
1411 \param value new setting value
1413 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1415 class TEvent: public SALOME_Event
1421 TEvent( const QString& section, const QString& name, int value )
1422 : mySection( section ), myName( name ), myValue( value ) {}
1423 virtual void Execute()
1425 if ( SUIT_Session::session() ) {
1426 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1427 if ( !mySection.isEmpty() && !myName.isEmpty() )
1428 resMgr->setValue( mySection, myName, myValue );
1432 ProcessVoidEvent( new TEvent( section, name, value ) );
1436 \brief Add boolean setting to the application preferences.
1437 \param section resources file section name
1438 \param name setting name
1439 \param value new setting value
1440 \param dumb this parameter is used in order to avoid sip compilation error
1441 because of conflicting int and bool types
1443 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1445 class TEvent: public SALOME_Event
1451 TEvent( const QString& section, const QString& name, bool value )
1452 : mySection( section ), myName( name ), myValue( value ) {}
1453 virtual void Execute()
1455 if ( SUIT_Session::session() ) {
1456 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1457 if ( !mySection.isEmpty() && !myName.isEmpty() )
1458 resMgr->setValue( mySection, myName, myValue );
1462 ProcessVoidEvent( new TEvent( section, name, value ) );
1466 \brief Add string setting to the application preferences.
1467 \param section resources file section name
1468 \param name setting name
1469 \param value new setting value
1471 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1473 class TEvent: public SALOME_Event
1479 TEvent( const QString& section, const QString& name, const QString& value )
1480 : mySection( section ), myName( name ), myValue( value ) {}
1481 virtual void Execute()
1483 if ( SUIT_Session::session() ) {
1484 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1485 if ( !mySection.isEmpty() && !myName.isEmpty() )
1486 resMgr->setValue( mySection, myName, myValue );
1490 ProcessVoidEvent( new TEvent( section, name, value ) );
1494 \brief Add color setting to the application preferences.
1495 \param section resources file section name
1496 \param name setting name
1497 \param value new setting value
1499 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1501 class TEvent: public SALOME_Event
1507 TEvent( const QString& section, const QString& name, const QColor& value )
1508 : mySection( section ), myName( name ), myValue( value ) {}
1509 virtual void Execute()
1511 if ( SUIT_Session::session() ) {
1512 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1513 if ( !mySection.isEmpty() && !myName.isEmpty() )
1514 resMgr->setValue( mySection, myName, myValue );
1518 ProcessVoidEvent( new TEvent( section, name, value ) );
1522 \brief Add byte array setting to the application preferences.
1523 \param section resources file section name
1524 \param name setting name
1525 \param value new setting value
1527 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1529 class TEvent: public SALOME_Event
1535 TEvent( const QString& section, const QString& name, const QByteArray& value )
1536 : mySection( section ), myName( name ), myValue( value ) {}
1537 virtual void Execute()
1539 if ( SUIT_Session::session() ) {
1540 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1541 if ( !mySection.isEmpty() && !myName.isEmpty() )
1542 resMgr->setValue( mySection, myName, myValue );
1546 ProcessVoidEvent( new TEvent( section, name, value ) );
1550 \brief Add font setting to the application preferences.
1551 \param section resources file section name
1552 \param name setting name
1553 \param value new setting value
1555 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1557 class TEvent: public SALOME_Event
1563 TEvent( const QString& section, const QString& name, const QFont& value )
1564 : mySection( section ), myName( name ), myValue( value ) {}
1565 virtual void Execute()
1567 if ( SUIT_Session::session() ) {
1568 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1569 if ( !mySection.isEmpty() && !myName.isEmpty() )
1570 resMgr->setValue( mySection, myName, myValue );
1574 ProcessVoidEvent( new TEvent( section, name, value ) );
1578 \fn int SalomePyQt::integerSetting( const QString& section,
1579 const QString& name,
1581 \brief Get integer setting from the application preferences.
1582 \param section resources file section name
1583 \param name setting name
1584 \param def default value which is returned if the setting is not found
1585 \return setting value
1588 class TGetIntSettingEvent: public SALOME_Event
1591 typedef int TResult;
1596 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1597 : mySection( section ), myName( name ), myDefault( def ) {}
1598 virtual void Execute()
1600 if ( SUIT_Session::session() ) {
1601 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1602 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1606 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1608 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1612 \fn double SalomePyQt::doubleSetting( const QString& section,
1613 const QString& name,
1615 \brief Get double setting from the application preferences.
1616 \param section resources file section name
1617 \param name setting name
1618 \param def default value which is returned if the setting is not found
1619 \return setting value
1622 class TGetDblSettingEvent: public SALOME_Event
1625 typedef double TResult;
1630 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1631 : mySection( section ), myName( name ), myDefault( def ) {}
1632 virtual void Execute()
1634 if ( SUIT_Session::session() ) {
1635 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1636 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1640 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1642 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1646 \fn bool SalomePyQt::boolSetting( const QString& section,
1647 const QString& name,
1649 \brief Get boolean setting from the application preferences.
1650 \param section resources file section name
1651 \param name setting name
1652 \param def default value which is returned if the setting is not found
1653 \return setting value
1656 class TGetBoolSettingEvent: public SALOME_Event
1659 typedef bool TResult;
1664 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1665 : mySection( section ), myName( name ), myDefault( def ) {}
1666 virtual void Execute()
1668 if ( SUIT_Session::session() ) {
1669 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1670 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1674 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1676 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1680 \fn QString SalomePyQt::stringSetting( const QString& section,
1681 const QString& name,
1684 \brief Get string setting from the application preferences.
1685 \param section resources file section name
1686 \param name setting name
1687 \param def default value which is returned if the setting is not found
1688 \param subst \c true to make substitution, \c false to get "raw" value
1689 \return setting value
1692 class TGetStrSettingEvent: public SALOME_Event
1695 typedef QString TResult;
1701 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1702 : mySection( section ), myName( name ), mySubst( subst ), myDefault( def ) {}
1703 virtual void Execute()
1705 if ( SUIT_Session::session() ) {
1706 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1707 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1711 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1713 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1717 \fn QColor SalomePyQt::colorSetting( const QString& section,
1718 const QString& name,
1720 \brief Get color setting from the application preferences.
1721 \param section resources file section name
1722 \param name setting name
1723 \param def default value which is returned if the setting is not found
1724 \return setting value
1727 class TGetColorSettingEvent: public SALOME_Event
1730 typedef QColor TResult;
1735 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1736 : mySection( section ), myName( name ), myDefault( def ) {}
1737 virtual void Execute()
1739 if ( SUIT_Session::session() ) {
1740 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1741 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1745 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1747 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1751 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1752 const QString& name,
1753 const QByteArray& def );
1754 \brief Get byte array setting from the application preferences.
1755 \param section resources file section name
1756 \param name setting name
1757 \param def default value which is returned if the setting is not found
1758 \return setting value
1761 class TGetByteArraySettingEvent: public SALOME_Event
1764 typedef QByteArray TResult;
1769 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1770 : mySection( section ), myName( name ), myDefault( def ) {}
1771 virtual void Execute()
1773 if ( SUIT_Session::session() ) {
1774 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1775 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1779 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1781 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1785 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1786 const QString& name,
1788 \brief Get font setting from the application preferences.
1789 \param section resources file section name
1790 \param name setting name
1791 \param def default value which is returned if the setting is not found
1792 \return setting value
1795 class TGetFontSettingEvent: public SALOME_Event
1798 typedef QFont TResult;
1803 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1804 : mySection( section ), myName( name ), myDefault( def ) {}
1805 virtual void Execute()
1807 if ( SUIT_Session::session() ) {
1808 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1809 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1813 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1815 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1819 \brief Remove setting from the application preferences.
1820 \param section resources file section name
1821 \param name setting name
1823 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1825 class TEvent: public SALOME_Event
1830 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1831 virtual void Execute()
1833 if ( SUIT_Session::session() ) {
1834 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1835 if ( !mySection.isEmpty() && !myName.isEmpty() )
1836 resMgr->remove( mySection, myName );
1840 ProcessVoidEvent( new TEvent( section, name ) );
1844 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1845 \brief Check setting existence in the application preferences.
1846 \param section resources file section name
1847 \param name setting name
1848 \return \c true if setting exists
1851 class THasSettingEvent: public SALOME_Event
1854 typedef bool TResult;
1858 THasSettingEvent( const QString& section, const QString& name )
1859 : mySection( section ), myName( name ) {}
1860 virtual void Execute()
1862 if ( SUIT_Session::session() ) {
1863 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1864 myResult = resMgr->hasValue( mySection, myName );
1868 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1870 return ProcessEvent( new THasSettingEvent( section, name ) );
1874 \fn QStringList SalomePyQt::parameters( const QString& section );
1875 \brief Get names of preference items stored within the given section.
1876 \param section resources file section's name
1877 \return \c list of preferences items
1881 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1882 \brief Get names of preference items stored within the given section.
1883 \param section resources file section's name
1884 \return \c list of preferences items
1887 class TParametersEvent: public SALOME_Event
1890 typedef QStringList TResult;
1892 QStringList mySection;
1893 TParametersEvent( const QString& section )
1895 mySection << section;
1897 TParametersEvent( const QStringList& section )
1898 : mySection( section )
1900 virtual void Execute()
1902 if ( SUIT_Session::session() ) {
1903 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1904 myResult = resMgr->parameters( mySection );
1908 QStringList SalomePyQt::parameters( const QString& section )
1910 return ProcessEvent( new TParametersEvent( section ) );
1912 QStringList SalomePyQt::parameters( const QStringList& section )
1914 return ProcessEvent( new TParametersEvent( section ) );
1918 \fn QString SalomePyQt::getFileName( QWidget* parent,
1919 const QString& initial,
1920 const QStringList& filters,
1921 const QString& caption,
1923 \brief Show 'Open/Save file' dialog box for file selection
1924 and return a user's choice (selected file name).
1925 \param parent parent widget
1926 \param initial initial directory the dialog box to be opened in
1927 \param filters list of files filters (wildcards)
1928 \param caption dialog box title
1929 \param open if \c true, "Open File" dialog box is shown;
1930 otherwise "Save File" dialog box is shown
1931 \return selected file name (null string if user cancels operation)
1934 class TGetFileNameEvent: public SALOME_Event
1937 typedef QString TResult;
1941 QStringList myFilters;
1944 TGetFileNameEvent( QWidget* parent,
1945 const QString& initial,
1946 const QStringList& filters,
1947 const QString& caption,
1949 : myParent ( parent ),
1950 myInitial( initial ),
1951 myFilters( filters ),
1952 myCaption( caption ),
1954 virtual void Execute()
1956 if ( LightApp_Application* anApp = getApplication() ) {
1957 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1958 myCaption, myParent );
1962 QString SalomePyQt::getFileName( QWidget* parent,
1963 const QString& initial,
1964 const QStringList& filters,
1965 const QString& caption,
1968 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1972 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1973 const QString& initial,
1974 const QStringList& filters,
1975 const QString& caption );
1976 \brief Show 'Open files' dialog box for multiple files selection
1977 and return a user's choice (selected file names list).
1978 \param parent parent widget
1979 \param initial initial directory the dialog box to be opened in
1980 \param filters list of files filters (wildcards)
1981 \param caption dialog box title
1982 \return selected file names list (empty list if user cancels operation)
1985 class TGetOpenFileNamesEvent: public SALOME_Event
1988 typedef QStringList TResult;
1992 QStringList myFilters;
1994 TGetOpenFileNamesEvent( QWidget* parent,
1995 const QString& initial,
1996 const QStringList& filters,
1997 const QString& caption )
1998 : myParent ( parent ),
1999 myInitial( initial ),
2000 myFilters( filters ),
2001 myCaption( caption ) {}
2002 virtual void Execute()
2004 if ( LightApp_Application* anApp = getApplication() ) {
2005 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
2009 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
2010 const QString& initial,
2011 const QStringList& filters,
2012 const QString& caption )
2014 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
2018 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
2019 const QString& initial,
2020 const QString& caption );
2021 \brief Show 'Get Directory' dialog box for the directory selection
2022 and return a user's choice (selected directory name).
2023 \param parent parent widget
2024 \param initial initial directory the dialog box to be opened in
2025 \param caption dialog box title
2026 \return selected directory name (null string if user cancels operation)
2029 class TGetExistingDirectoryEvent: public SALOME_Event
2032 typedef QString TResult;
2037 TGetExistingDirectoryEvent( QWidget* parent,
2038 const QString& initial,
2039 const QString& caption )
2040 : myParent ( parent ),
2041 myInitial( initial ),
2042 myCaption( caption ) {}
2043 virtual void Execute()
2045 if ( LightApp_Application* anApp = getApplication() ) {
2046 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
2050 QString SalomePyQt::getExistingDirectory( QWidget* parent,
2051 const QString& initial,
2052 const QString& caption )
2054 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
2058 \fn QString SalomePyQt::loadIcon( const QString& filename );
2059 \brief Load an icon from the module resources by the specified file name.
2060 \param fileName icon file name
2064 class TLoadIconEvent: public SALOME_Event
2067 typedef QIcon TResult;
2071 TLoadIconEvent( const QString& module, const QString& filename )
2072 : myModule( module ),
2073 myFileName ( filename ) {}
2074 virtual void Execute()
2076 myResult = loadIconInternal( myModule, myFileName );
2079 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2081 return ProcessEvent( new TLoadIconEvent( module, filename ) );
2085 \brief Open external browser to display context help information.
2088 Current implementation does nothing.
2090 \param source documentation (HTML) file name
2091 \param context context (for example, HTML ancor name)
2093 void SalomePyQt::helpContext( const QString& source, const QString& context )
2095 class TEvent: public SALOME_Event
2100 TEvent( const QString& source, const QString& context )
2101 : mySource( source ), myContext( context ) {}
2102 virtual void Execute()
2104 if ( LightApp_Application* anApp = getApplication() ) {
2105 anApp->onHelpContextModule( "", mySource, myContext );
2109 ProcessVoidEvent( new TEvent( source, context ) );
2113 \fn int SalomePyQt::defaultMenuGroup();
2114 \brief Get detault menu group identifier which can be used when
2115 creating menus (insert custom menu commands).
2116 \return default menu group ID
2119 class TDefMenuGroupEvent: public SALOME_Event
2122 typedef int TResult;
2124 TDefMenuGroupEvent() : myResult( -1 ) {}
2125 virtual void Execute()
2127 myResult = PyModuleHelper::defaultMenuGroup();
2130 int SalomePyQt::defaultMenuGroup()
2132 return ProcessEvent( new TDefMenuGroupEvent() );
2138 CrTool( const QString& tBar, const QString& nBar )
2139 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
2140 CrTool( const int id, const int tBar, const int idx )
2141 : myCase( 1 ), myTbId( tBar ), myId( id ), myIndex( idx ) {}
2142 CrTool( const int id, const QString& tBar, const int idx )
2143 : myCase( 2 ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2144 CrTool( QAction* action, const int tbId, const int id, const int idx )
2145 : myCase( 3 ), myTbId( tbId ), myAction( action ), myId( id ), myIndex( idx ) {}
2146 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2147 : myCase( 4 ), myTbTitle( tBar ), myAction( action ), myId( id ), myIndex( idx ) {}
2153 if ( getActiveModule() )
2154 return getActiveModule()->createTool( myTbTitle, myTbName );
2155 else if ( getApplication() )
2156 return getApplication()->createTool( myTbTitle, myTbName );
2159 if ( getActiveModule() )
2160 return getActiveModule()->createTool( myId, myTbId, myIndex );
2161 else if ( getApplication() )
2162 return getApplication()->createTool( myId, myTbId, myIndex );
2165 if ( getActiveModule() )
2166 return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2167 else if ( getApplication() )
2168 return getApplication()->createTool( myId, myTbTitle, myIndex );
2171 if ( getActiveModule() )
2172 return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2173 else if ( getApplication() )
2174 return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2177 if ( getActiveModule() )
2178 return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2179 else if ( getApplication() )
2180 return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2197 class TCreateToolEvent: public SALOME_Event
2200 typedef int TResult;
2202 const CrTool& myCrTool;
2203 TCreateToolEvent( const CrTool& crTool )
2204 : myResult( -1 ), myCrTool( crTool ) {}
2205 virtual void Execute()
2207 myResult = myCrTool.execute();
2212 \brief Create toolbar with specified name.
2213 \param tBar toolbar title (language-dependent)
2214 \param nBar toolbar name (language-independent) [optional]
2215 \return toolbar ID or -1 if toolbar creation is failed
2217 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2219 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2223 \brief Insert action with specified \a id to the toolbar.
2225 \param tBar toolbar ID
2226 \param idx required index in the toolbar
2227 \return action ID or -1 if action could not be added
2229 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2231 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2235 \brief Insert action with specified \a id to the toolbar.
2237 \param tBar toolbar name
2238 \param idx required index in the toolbar
2239 \return action ID or -1 if action could not be added
2241 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2243 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2247 \brief Insert action to the toolbar.
2249 \param tBar toolbar ID
2250 \param id required action ID
2251 \param idx required index in the toolbar
2252 \return action ID or -1 if action could not be added
2254 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2256 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2261 \brief Clear given toolbar.
2262 \param title toolbar's title
2264 void SalomePyQt::clearTool( const QString& title )
2266 class TEvent: public SALOME_Event
2270 TEvent( const QString& title )
2271 : myTitle( title ) {}
2272 virtual void Execute()
2274 if ( getActiveModule() )
2275 return getActiveModule()->clearTool( myTitle );
2276 else if ( getApplication() )
2277 return getApplication()->clearTool( myTitle );
2280 ProcessVoidEvent( new TEvent( title ) );
2284 \brief Insert action to the toolbar.
2286 \param tBar toolbar name
2287 \param id required action ID
2288 \param idx required index in the toolbar
2289 \return action ID or -1 if action could not be added
2291 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2293 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2299 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2300 : myCase( 0 ), myMenuId( menu ), mySubMenuName( subMenu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2301 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2302 : myCase( 1 ), myMenuName( menu ), mySubMenuName( subMenu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2303 CrMenu( const int id, const int menu, const int group, const int idx )
2304 : myCase( 2 ), myMenuId( menu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2305 CrMenu( const int id, const QString& menu, const int group, const int idx )
2306 : myCase( 3 ), myMenuName( menu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2307 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2308 : myCase( 4 ), myMenuId( menu ), myGroup( group ), myAction( action ), myId( id ), myIndex( idx ) {}
2309 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2310 : myCase( 5 ), myMenuName( menu ), myGroup( group ), myAction( action ), myId( id ), myIndex( idx ) {}
2316 if ( getActiveModule() )
2317 return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2318 else if ( getApplication() )
2319 return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2322 if ( getActiveModule() )
2323 return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2324 else if ( getApplication() )
2325 return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2328 if ( getActiveModule() )
2329 return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2330 else if ( getApplication() )
2331 return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2334 if ( getActiveModule() )
2335 return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2336 else if ( getApplication() )
2337 return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2340 if ( getActiveModule() )
2341 return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2342 else if ( getApplication() )
2343 return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2346 if ( getActiveModule() )
2347 return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2348 else if ( getApplication() )
2349 return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2360 QString mySubMenuName;
2367 class TCreateMenuEvent: public SALOME_Event
2370 typedef int TResult;
2372 const CrMenu& myCrMenu;
2373 TCreateMenuEvent( const CrMenu& crMenu )
2374 : myResult( -1 ), myCrMenu( crMenu ) {}
2375 virtual void Execute()
2377 myResult = myCrMenu.execute();
2382 \brief Create main menu.
2383 \param subMenu menu name
2384 \param menu parent menu ID
2385 \param id required menu ID
2386 \param group menu group ID
2387 \param idx required index in the menu
2388 \return menu ID or -1 if menu could not be added
2390 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2392 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2396 \brief Create main menu.
2397 \param subMenu menu name
2398 \param menu parent menu name (list of menu names separated by "|")
2399 \param id required menu ID
2400 \param group menu group ID
2401 \param idx required index in the menu
2402 \return menu ID or -1 if menu could not be added
2404 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2406 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2410 \brief Insert action to the main menu.
2412 \param menu parent menu ID
2413 \param group menu group ID
2414 \param idx required index in the menu
2415 \return action ID or -1 if action could not be added
2417 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2419 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2423 \brief Insert action to the main menu.
2425 \param menu parent menu name (list of menu names separated by "|")
2426 \param group menu group ID
2427 \param idx required index in the menu
2428 \return action ID or -1 if action could not be added
2430 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2432 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2436 \brief Insert action to the main menu.
2438 \param menu parent menu ID
2439 \param group menu group ID
2440 \param idx required index in the menu
2441 \return action ID or -1 if action could not be added
2443 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2445 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2449 \brief Insert action to the main menu.
2451 \param menu parent menu name (list of menu names separated by "|")
2452 \param group menu group ID
2453 \param idx required index in the menu
2454 \return action ID or -1 if action could not be added
2456 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2458 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2462 \fn QAction* SalomePyQt::createSeparator();
2463 \brief Create separator action which can be used in the menu or toolbar.
2464 \return new separator action
2467 class TCreateSepEvent: public SALOME_Event
2470 typedef QAction* TResult;
2474 virtual void Execute()
2476 LightApp_Module* module = getActiveModule();
2478 myResult = (QAction*)module->separator();
2481 QAction* SalomePyQt::createSeparator()
2483 return ProcessEvent( new TCreateSepEvent() );
2487 \fn QAction* SalomePyQt::createAction( const int id,
2488 const QString& menuText,
2489 const QString& tipText,
2490 const QString& statusText,
2491 const QString& icon,
2493 const bool toggle );
2494 \brief Create an action which can be then used in the menu or toolbar.
2495 \param id the unique id action to be registered to
2496 \param menuText action text which should appear in menu
2497 \param tipText text which should appear in the tooltip
2498 \param statusText text which should appear in the status bar when action is activated
2499 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2500 \param key the key accelrator for the action
2501 \param toggle if \c true the action is checkable
2504 class TCreateActionEvent: public SALOME_Event
2507 typedef QAction* TResult;
2512 QString myStatusText;
2516 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2517 const QString& statusText, const QString& icon, const int key, const bool toggle )
2518 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2519 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2520 virtual void Execute()
2522 LightApp_Module* module = getActiveModule();
2524 QIcon icon = loadIconInternal( module->name(), myIcon );
2525 myResult = (QAction*)module->action( myId );
2527 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2528 myResult->setToolTip( myTipText );
2529 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2530 myResult->setText( myMenuText );
2531 if ( myResult->icon().isNull() && !icon.isNull() )
2532 myResult->setIcon( icon );
2533 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2534 myResult->setStatusTip( myStatusText );
2535 if ( myResult->shortcut().isEmpty() && myKey )
2536 myResult->setShortcut( myKey );
2537 if ( myResult->isCheckable() != myToggle )
2538 myResult->setCheckable( myToggle );
2541 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2543 // for Python module, automatically connect action to callback slot
2544 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2545 if ( helper ) helper->connectAction( myResult );
2549 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2550 const QString& tipText, const QString& statusText,
2551 const QString& icon, const int key, const bool toggle )
2553 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2557 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2558 \brief Create an action group which can be then used in the menu or toolbar
2559 \param id : the unique id action group to be registered to
2560 \param exclusive : if \c true the action group does exclusive toggling
2563 struct TCreateActionGroupEvent: public SALOME_Event
2565 typedef QtxActionGroup* TResult;
2569 TCreateActionGroupEvent( const int id, const bool exclusive )
2570 : myId( id ), myExclusive( exclusive ) {}
2571 virtual void Execute()
2573 LightApp_Module* module = getActiveModule();
2575 myResult = module->createActionGroup( myId, myExclusive );
2578 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2580 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2584 \fn QAction* SalomePyQt::action( const int id );
2585 \brief Get action by specified identifier.
2586 \return action or 0 if action is not registered
2589 class TActionEvent: public SALOME_Event
2592 typedef QAction* TResult;
2595 TActionEvent( const int id )
2596 : myResult( 0 ), myId( id ) {}
2597 virtual void Execute()
2599 LightApp_Module* module = getActiveModule();
2601 myResult = (QAction*)module->action( myId );
2604 QAction* SalomePyQt::action( const int id )
2606 return ProcessEvent( new TActionEvent( id ) );
2610 \fn int SalomePyQt::actionId( const QAction* a );
2611 \brief Get an action identifier.
2612 \return action ID or -1 if action is not registered
2615 class TActionIdEvent: public SALOME_Event
2618 typedef int TResult;
2620 const QAction* myAction;
2621 TActionIdEvent( const QAction* action )
2622 : myResult( -1 ), myAction( action ) {}
2623 virtual void Execute()
2625 LightApp_Module* module = getActiveModule();
2627 myResult = module->actionId( myAction );
2630 int SalomePyQt::actionId( const QAction* a )
2632 return ProcessEvent( new TActionIdEvent( a ) );
2636 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2637 \brief Add global (not module-related) preferences group.
2638 \param label global preferences group name
2639 \return preferences group identifier
2642 class TAddGlobalPrefEvent: public SALOME_Event
2645 typedef int TResult;
2648 TAddGlobalPrefEvent( const QString& label )
2649 : myResult( -1 ), myLabel( label ) {}
2650 virtual void Execute()
2652 LightApp_Module* module = getActiveModule();
2654 LightApp_Preferences* pref = module->getApp()->preferences();
2656 myResult = pref->addPreference( myLabel, -1 );
2660 int SalomePyQt::addGlobalPreference( const QString& label )
2662 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2666 \fn int SalomePyQt::addPreference( const QString& label );
2667 \brief Add module-related preferences group.
2668 \param label preferences group name
2669 \return preferences group identifier
2672 class TAddPrefEvent: public SALOME_Event
2675 typedef int TResult;
2678 TAddPrefEvent( const QString& label )
2679 : myResult( -1 ), myLabel( label ) {}
2680 virtual void Execute()
2682 LightApp_Module* module = getActiveModule();
2684 LightApp_Preferences* pref = module->getApp()->preferences();
2686 int cId = pref->addPreference( module->moduleName(), -1 );
2688 myResult = pref->addPreference( myLabel, cId );
2693 int SalomePyQt::addPreference( const QString& label )
2695 return ProcessEvent( new TAddPrefEvent( label ) );
2699 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2700 const QString& section, const QString& param );
2701 \brief Add module-related preferences.
2702 \param label preferences group name
2703 \param pId parent preferences group id
2704 \param type preferences type
2705 \param section resources file section name
2706 \param param resources file setting name
2707 \return preferences identifier
2710 class TAddPrefParamEvent: public SALOME_Event
2713 typedef int TResult;
2720 TAddPrefParamEvent( const QString& label,
2721 const int pId, const int type,
2722 const QString& section,
2723 const QString& param )
2725 myLabel( label ), myPId( pId ), myType( type ),
2726 mySection( section ), myParam ( param ) {}
2727 virtual void Execute()
2729 LightApp_Module* module = getActiveModule();
2731 LightApp_Preferences* pref = module->getApp()->preferences();
2733 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2737 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2738 const QString& section, const QString& param )
2740 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2744 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2745 \brief Get the preferences property.
2746 \param id preferences identifier
2747 \param prop preferences property name
2748 \return preferences property value or null QVariant if property is not set
2751 class TPrefPropEvent: public SALOME_Event
2754 typedef QVariant TResult;
2758 TPrefPropEvent( const int id, const QString& prop )
2759 : myId( id ), myProp( prop ) {}
2760 virtual void Execute()
2762 LightApp_Module* module = getActiveModule();
2764 LightApp_Preferences* pref = module->getApp()->preferences();
2766 myResult = pref->itemProperty( myProp, myId );
2770 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2772 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2776 \brief Set the preferences property.
2777 \param id preferences identifier
2778 \param prop preferences property name
2779 \param var preferences property value
2781 void SalomePyQt::setPreferenceProperty( const int id,
2782 const QString& prop,
2783 const QVariant& var )
2785 class TEvent: public SALOME_Event
2791 TEvent( const int id, const QString& prop, const QVariant& var )
2792 : myId( id ), myProp( prop ), myVar( var ) {}
2793 virtual void Execute()
2795 LightApp_Module* module = getActiveModule();
2797 LightApp_Preferences* pref = module->getApp()->preferences();
2799 pref->setItemProperty( myProp, myVar, myId );
2803 ProcessVoidEvent( new TEvent( id, prop, var ) );
2807 \brief Set specific widget as a custom preferences item.
2808 \param id preferences identifier
2809 \param prop preferences property name
2810 \param widget custom widget
2812 void SalomePyQt::setPreferencePropertyWg( const int id,
2813 const QString& prop,
2814 UserDefinedContent* widget )
2816 class TEvent: public SALOME_Event
2820 UserDefinedContent* myWidget;
2822 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2823 : myId( id ), myProp( prop ), myWidget( widget ) {}
2824 virtual void Execute()
2826 LightApp_Module* module = getActiveModule();
2828 LightApp_Preferences* pref = module->getApp()->preferences();
2830 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2835 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2839 \brief Add the property value to the list of values.
2841 This method allows creating properties which are QList<QVariant>
2842 - there is no way to pass such values directly to QVariant parameter with PyQt.
2844 \param id preferences identifier
2845 \param prop preferences property name
2846 \param idx preferences property index
2847 \param var preferences property value for the index \a idx
2849 void SalomePyQt::addPreferenceProperty( const int id,
2850 const QString& prop,
2852 const QVariant& var )
2854 class TEvent: public SALOME_Event
2861 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2862 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2863 virtual void Execute()
2865 LightApp_Module* module = getActiveModule();
2867 LightApp_Preferences* pref = module->getApp()->preferences();
2869 QVariant var = pref->itemProperty( myProp, myId );
2870 if ( var.isValid() ) {
2871 if ( var.type() == QVariant::StringList ) {
2872 QStringList sl = var.toStringList();
2873 if ( myIdx >= 0 && myIdx < sl.count() )
2874 sl[myIdx] = myVar.toString();
2876 sl.append( myVar.toString() );
2877 pref->setItemProperty( myProp, sl, myId );
2879 else if ( var.type() == QVariant::List ) {
2880 QList<QVariant> vl = var.toList();
2881 if ( myIdx >= 0 && myIdx < vl.count() )
2885 pref->setItemProperty( myProp, vl, myId );
2891 pref->setItemProperty( myProp, vl, myId );
2897 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2901 \brief Put the message to the Log messages output window
2902 \param msg message text (it can be of simple rich text format)
2903 \param addSeparator boolean flag which specifies if it is necessary
2904 to separate the message with predefined separator
2906 void SalomePyQt::message( const QString& msg, bool addSeparator )
2908 class TEvent: public SALOME_Event
2913 TEvent( const QString& msg, bool addSeparator )
2914 : myMsg( msg ), myAddSep( addSeparator ) {}
2915 virtual void Execute()
2917 if ( LightApp_Application* anApp = getApplication() ) {
2918 LogWindow* lw = anApp->logWindow();
2920 lw->putMessage( myMsg, myAddSep );
2924 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2928 \brief Set the title to the Help panel.
2929 \param title Title text (empty string removes title)
2931 void SalomePyQt::infoSetTitle( const QString& title )
2933 class TEvent: public SALOME_Event
2937 TEvent( const QString& title )
2938 : myTitle( title ) {}
2939 virtual void Execute()
2941 if ( LightApp_Application* anApp = getApplication() ) {
2942 QtxInfoPanel* ip = anApp->infoPanel();
2944 ip->setTitle( myTitle );
2948 ProcessVoidEvent( new TEvent( title ) );
2952 \fn int SalomePyQt::infoAddLabel( const QString& text, const int groupId )
2953 \brief Insert left-aligned text label into the Help panel
2954 \param text Label text
2955 \param groupId Parent group's identifier (defaults to -1 for top-level group)
2956 \return Label's identifier
2959 class TInfoAddLabel2paramEvent: public SALOME_Event
2962 typedef int TResult;
2966 TInfoAddLabel2paramEvent( const QString& text, const int groupId )
2967 : myText( text ), myGroupId( groupId ) {}
2968 virtual void Execute()
2970 if ( LightApp_Application* anApp = getApplication() ) {
2971 QtxInfoPanel* ip = anApp->infoPanel();
2973 myResult = ip->addLabel( myText, myGroupId );
2977 int SalomePyQt::infoAddLabel( const QString& text, const int groupId )
2979 return ProcessEvent( new TInfoAddLabel2paramEvent( text, groupId ) );
2983 \fn int SalomePyQt::infoAddLabel( const QString& text, Qt::Alignment alignment, const int groupId )
2984 \brief Insert text label into the Help panel
2985 \param text Label text
2986 \param alignment Alignment flag for text label
2987 \param groupId Parent group's identifier (defaults to -1 for top-level group)
2988 \return Label's identifier
2991 class TInfoAddLabel3paramEvent: public SALOME_Event
2994 typedef int TResult;
2997 Qt::Alignment myAlignment;
2999 TInfoAddLabel3paramEvent( const QString& text, Qt::Alignment alignment, const int groupId )
3000 : myText( text ), myAlignment( alignment ), myGroupId( groupId ) {}
3001 virtual void Execute()
3003 if ( LightApp_Application* anApp = getApplication() ) {
3004 QtxInfoPanel* ip = anApp->infoPanel();
3006 myResult = ip->addLabel( myText, myAlignment, myGroupId );
3010 int SalomePyQt::infoAddLabel( const QString& text, Qt::Alignment alignment, const int groupId )
3012 return ProcessEvent( new TInfoAddLabel3paramEvent( text, alignment, groupId ) );
3016 \fn int SalomePyQt::infoAddAction( QAction* action, const int groupId )
3017 \brief Insert action button into the Help panel
3018 \param action Action being added
3019 \param groupId Parent group's identifier (defaults to -1 for top-level group)
3020 \return Action's identifier
3023 class TInfoAddActionEvent: public SALOME_Event
3026 typedef int TResult;
3030 TInfoAddActionEvent( QAction* action, const int groupId )
3031 : myAction( action ), myGroupId( groupId ) {}
3032 virtual void Execute()
3034 if ( LightApp_Application* anApp = getApplication() ) {
3035 QtxInfoPanel* ip = anApp->infoPanel();
3037 myResult = ip->addAction( myAction, myGroupId );
3041 int SalomePyQt::infoAddAction( QAction* action, const int groupId )
3043 return ProcessEvent( new TInfoAddActionEvent( action, groupId ) );
3047 \fn int SalomePyQt::infoAddGroup( const QString& text, const int groupId )
3048 \brief Create a (sub-)group in the Help panel
3049 \param text Group title
3050 \param groupId Parent group's identifier (defaults to -1 for top-level group)
3051 \return Group's identifier
3054 class TInfoAddGroupEvent: public SALOME_Event
3057 typedef int TResult;
3061 TInfoAddGroupEvent( const QString& text, const int groupId )
3062 : myText( text ), myGroupId( groupId ) {}
3063 virtual void Execute()
3065 if ( LightApp_Application* anApp = getApplication() ) {
3066 QtxInfoPanel* ip = anApp->infoPanel();
3068 myResult = ip->addGroup( myText, myGroupId );
3072 int SalomePyQt::infoAddGroup( const QString& text, const int groupId )
3074 return ProcessEvent( new TInfoAddGroupEvent( text, groupId ) );
3078 \brief Remove item from the Help panel
3079 \param id Item's (label's, action's, group's, ...) identifier
3081 void SalomePyQt::infoRemove( const int id )
3083 class TEvent: public SALOME_Event
3087 TEvent( const int id )
3089 virtual void Execute()
3091 if ( LightApp_Application* anApp = getApplication() ) {
3092 QtxInfoPanel* ip = anApp->infoPanel();
3098 ProcessVoidEvent( new TEvent( id ) );
3102 \brief Clear Help panel's contents
3103 \param groupId Group's identifier (default is -1, to clear whole panel)
3105 void SalomePyQt::infoClear( const int groupId )
3107 class TEvent: public SALOME_Event
3111 TEvent( const int groupId )
3112 : myGroupId( groupId ) {}
3113 virtual void Execute()
3115 if ( LightApp_Application* anApp = getApplication() ) {
3116 QtxInfoPanel* ip = anApp->infoPanel();
3118 ip->clear( myGroupId );
3122 ProcessVoidEvent( new TEvent( groupId ) );
3126 \brief Set item's visibility in the Help panel
3127 \param id Item's (label's, action's, group's, ...) identifier
3128 \param visible Visibility flag
3130 void SalomePyQt::infoSetVisible( const int id, bool visible )
3132 class TEvent: public SALOME_Event
3137 TEvent( const int id, bool visible )
3138 : myId( id ), myVisible( visible ) {}
3139 virtual void Execute()
3141 if ( LightApp_Application* anApp = getApplication() ) {
3142 QtxInfoPanel* ip = anApp->infoPanel();
3144 ip->setVisible( myId, myVisible );
3148 ProcessVoidEvent( new TEvent( id, visible ) );
3152 \brief Enable/disable item in the Help panel
3153 \param id Item's (label's, action's, group's, ...) identifier
3154 \param enabled Enabled state
3156 void SalomePyQt::infoSetEnabled( const int id, bool enabled )
3158 class TEvent: public SALOME_Event
3163 TEvent( const int id, bool enabled )
3164 : myId( id ), myEnabled( enabled ) {}
3165 virtual void Execute()
3167 if ( LightApp_Application* anApp = getApplication() ) {
3168 QtxInfoPanel* ip = anApp->infoPanel();
3170 ip->setEnabled( myId, myEnabled );
3174 ProcessVoidEvent( new TEvent( id, enabled ) );
3178 \brief Remove all the messages from the Log messages output window.
3180 void SalomePyQt::clearMessages()
3182 class TEvent: public SALOME_Event
3186 virtual void Execute()
3188 if ( LightApp_Application* anApp = getApplication() ) {
3189 LogWindow* lw = anApp->logWindow();
3195 ProcessVoidEvent( new TEvent() );
3199 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
3200 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
3201 to the image file in the specified format.
3203 For the current moment JPEG, PNG and BMP images formats are supported.
3204 The image format is defined automatically by the file name extension.
3205 By default, BMP format is used.
3207 \param filename image file name
3208 \return operation status (\c true on success)
3211 class TDumpViewEvent: public SALOME_Event
3214 typedef bool TResult;
3218 TDumpViewEvent( const QString& filename, const int id )
3219 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
3220 virtual void Execute()
3222 SUIT_ViewWindow* wnd = 0;
3224 if ( LightApp_Application* anApp = getApplication() ) {
3225 SUIT_ViewManager* vm = anApp->activeViewManager();
3227 wnd = vm->getActiveView();
3229 myWndId = wnd->getId();
3232 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3235 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
3236 #ifndef DISABLE_PLOT2DVIEWER
3237 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3239 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
3240 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
3241 qApp->processEvents();
3242 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
3243 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
3247 #endif // DISABLE_PLOT2DVIEWER
3248 QImage im = wnd->dumpView();
3249 if ( !im.isNull() && !myFileName.isEmpty() ) {
3250 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
3251 if ( fmt == "JPG" ) fmt = "JPEG";
3252 myResult = im.save( myFileName, fmt.toLatin1() );
3257 bool SalomePyQt::dumpView( const QString& filename, const int id )
3259 return ProcessEvent( new TDumpViewEvent( filename, id ) );
3263 \fn QList<int> SalomePyQt::getViews();
3264 \brief Get list of integer identifiers of all the currently opened views
3265 \return list of integer identifiers of all the currently opened views
3268 class TGetViews: public SALOME_Event
3271 typedef QList<int> TResult;
3274 virtual void Execute()
3277 LightApp_Application* app = getApplication();
3279 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3281 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3282 SUIT_ViewWindow* wnd;
3283 foreach ( wnd, wndlist )
3284 myResult.append( wnd->getId() );
3289 QList<int> SalomePyQt::getViews()
3291 return ProcessEvent( new TGetViews() );
3295 \fn int SalomePyQt::getActiveView();
3296 \brief Get integer identifier of the currently active view
3297 \return integer identifier of the currently active view
3300 class TGetActiveView: public SALOME_Event
3303 typedef int TResult;
3307 virtual void Execute()
3309 LightApp_Application* app = getApplication();
3311 SUIT_ViewManager* viewMgr = app->activeViewManager();
3313 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3315 myResult = wnd->getId();
3320 int SalomePyQt::getActiveView()
3322 return ProcessEvent( new TGetActiveView() );
3326 \fn QString SalomePyQt::getViewType( const int id );
3327 \brief Get type of the specified view, e.g. "OCCViewer"
3328 \param id window identifier
3332 class TGetViewType: public SALOME_Event
3335 typedef QString TResult;
3338 TGetViewType( const int id )
3340 virtual void Execute()
3342 SUIT_ViewWindow* wnd = getWnd( myWndId );
3344 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3346 myResult = viewMgr->getType();
3350 QString SalomePyQt::getViewType( const int id )
3352 return ProcessEvent( new TGetViewType( id ) );
3356 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3357 \brief Change view caption
3358 \param id window identifier
3359 \param title new window title
3360 \return \c true if operation is completed successfully and \c false otherwise
3363 class TSetViewTitle: public SALOME_Event
3366 typedef bool TResult;
3370 TSetViewTitle( const int id, const QString& title )
3371 : myResult( false ),
3374 virtual void Execute()
3376 SUIT_ViewWindow* wnd = getWnd( myWndId );
3378 wnd->setWindowTitle( myTitle );
3383 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3385 return ProcessEvent( new TSetViewTitle( id, title ) );
3389 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3390 \brief Set view size
3391 \param w window width
3392 \param h window height
3393 \param id window identifier
3394 \return \c true if operation is completed successfully and \c false otherwise
3397 class TSetViewSize: public SALOME_Event
3400 typedef bool TResult;
3405 TSetViewSize( const int w, const int h, const int id )
3406 : myResult( false ),
3410 virtual void Execute()
3412 SUIT_ViewWindow* wnd = 0;
3414 if ( LightApp_Application* anApp = getApplication() ) {
3415 SUIT_ViewManager* vm = anApp->activeViewManager();
3417 wnd = vm->getActiveView();
3421 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3424 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3426 QString type = viewMgr->getType();
3427 if ( type == "OCCViewer") {
3428 #ifndef DISABLE_OCCVIEWER
3429 // specific processing for OCC viewer:
3430 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3431 // - if there is only one sub-view active; it will be resized;
3432 // - if there are several sub-views, each of them will be resized.
3433 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3434 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3435 if ( occView && occView->getView( i ) ) {
3436 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3440 #endif // DISABLE_OCCVIEWER
3442 else if ( type == "ParaView") {
3443 #ifndef DISABLE_PVVIEWER
3444 // specific processing for ParaView viewer:
3445 // hierarchy of ParaView viewer is much complex than for usual view;
3446 // we look for sub-widget named "Viewport"
3447 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3448 if ( !lst.isEmpty() ) {
3449 lst[0]->resize( myWndWidth, myWndHeight );
3452 #endif // DISABLE_PVVIEWER
3455 if ( wnd->centralWidget() ) {
3456 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3464 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3466 return ProcessEvent( new TSetViewSize( w, h, id ) );
3470 \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3471 \brief Set view rotation point
3472 \param x coordinate X view rotation point
3473 \param y coordinate Y view rotation point
3474 \param z coordinate Z view rotation point
3475 \param id window identifier
3476 \return \c true if operation is completed successfully and \c false otherwise
3479 class TSetViewRotationPoint: public SALOME_Event
3482 typedef bool TResult;
3488 TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3489 : myResult( false ),
3494 virtual void Execute()
3496 SUIT_ViewWindow* wnd = 0;
3498 if ( LightApp_Application* anApp = getApplication() ) {
3499 SUIT_ViewManager* vm = anApp->activeViewManager();
3501 wnd = vm->getActiveView();
3505 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3508 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3510 QString type = viewMgr->getType();
3511 if ( type == "OCCViewer") {
3512 #ifndef DISABLE_OCCVIEWER
3513 // specific processing for OCC viewer:
3514 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3515 // - if there is only one sub-view active; its rotation point will be changed;
3516 // - if there are several sub-views, rotaion points of each of them will be changed.
3517 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3519 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3520 if ( occView && occView->getView( i ) ) {
3521 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3526 #endif // DISABLE_OCCVIEWER
3528 else if ( type == "VTKViewer") {
3529 #ifndef DISABLE_VTKVIEWER
3530 SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3533 double aCenter[3] = { myX, myY, myZ };
3534 vtkView->activateSetRotationSelected( (void*)aCenter );
3537 #endif // DISABLE_VTKVIEWER
3543 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3545 return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3549 \fn QString SalomePyQt::getViewTitle( const int id );
3550 \brief Get view caption
3551 \param id window identifier
3552 \return view caption
3555 class TGetViewTitle: public SALOME_Event
3558 typedef QString TResult;
3561 TGetViewTitle( const int id )
3563 virtual void Execute()
3565 SUIT_ViewWindow* wnd = getWnd( myWndId );
3567 myResult = wnd->windowTitle();
3570 QString SalomePyQt::getViewTitle( const int id )
3572 return ProcessEvent( new TGetViewTitle( id ) );
3576 \fn QList<int> SalomePyQt::findViews( const QString& type );
3577 \brief Get list of integer identifiers of all the
3578 currently opened views of the specified type
3579 \param type viewer type
3580 \return list of integer identifiers
3583 class TFindViews: public SALOME_Event
3586 typedef QList<int> TResult;
3589 TFindViews( const QString& type )
3591 virtual void Execute()
3594 LightApp_Application* app = getApplication();
3596 ViewManagerList vmList;
3597 app->viewManagers( myType, vmList );
3598 SUIT_ViewManager* viewMgr;
3599 foreach ( viewMgr, vmList ) {
3600 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3601 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3602 SUIT_ViewWindow* wnd = vec[ i ];
3605 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3606 myResult.append( wnd->getId() );
3613 QList<int> SalomePyQt::findViews( const QString& type )
3615 return ProcessEvent( new TFindViews( type ) );
3619 \fn bool SalomePyQt::activateView( const int id );
3620 \brief Activate view
3621 \param id window identifier
3622 \return \c true if operation is completed successfully and \c false otherwise
3625 class TActivateView: public SALOME_Event
3628 typedef bool TResult;
3631 TActivateView( const int id )
3632 : myResult( false ),
3634 virtual void Execute()
3636 SUIT_ViewWindow* wnd = getWnd( myWndId );
3637 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3639 Activator activator;
3645 bool SalomePyQt::activateView( const int id )
3647 return ProcessEvent( new TActivateView( id ) );
3651 \fn bool SalomePyQt::activateManagerAndView( const int id );
3652 \brief Activate view manager and view: useful for a view embedded in a module main Window
3653 \param id window identifier
3654 \return \c true if operation is completed successfully and \c false otherwise
3657 class TActivateViewManagerAndView: public SALOME_Event
3660 typedef bool TResult;
3663 TActivateViewManagerAndView( const int id )
3664 : myResult( false ),
3666 virtual void Execute()
3668 SUIT_ViewWindow* wnd = getWnd( myWndId );
3669 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3672 LightApp_Application* app = getApplication();
3673 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3679 bool SalomePyQt::activateViewManagerAndView( const int id )
3681 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3688 class TGetViewWidget: public SALOME_Event
3691 typedef QWidget* TResult;
3694 TGetViewWidget( const int id )
3697 virtual void Execute()
3699 SUIT_ViewWindow* wnd = getWnd( myWndId );
3701 myResult = (QWidget*)wnd;
3705 QWidget* SalomePyQt::getViewWidget( const int id)
3707 return ProcessEvent( new TGetViewWidget( id ) );
3712 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3713 \brief Create new view and activate it
3714 \param type viewer type
3718 \return integer identifier of created view (or -1 if view could not be created)
3721 class TCreateView: public SALOME_Event
3724 typedef int TResult;
3731 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3737 myDetached(detached) {}
3738 virtual void Execute()
3740 LightApp_Application* app = getApplication();
3742 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3744 QWidget* wnd = viewMgr->getActiveView();
3745 myResult = viewMgr->getActiveView()->getId();
3748 wnd->setVisible(false);
3749 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3753 if (myWidth > 0 && myHeight > 0) {
3754 #ifndef DISABLE_PLOT2DVIEWER
3755 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3756 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3757 #endif // DISABLE_PLOT2DVIEWER
3758 wnd->setGeometry( 0, 0, myWidth, myHeight );
3765 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3767 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3768 QCoreApplication::processEvents();
3773 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3774 \brief Create new view with custom widget embedded and activate it
3775 \param type viewer type
3776 \param w custom widget
3777 \return integer identifier of created view (or -1 if view could not be created)
3780 class TCreateViewWg: public SALOME_Event
3783 typedef int TResult;
3787 TCreateViewWg( const QString& theType, QWidget* w )
3791 virtual void Execute()
3793 LightApp_Application* app = getApplication();
3795 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3797 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3799 myResult = wnd->getId();
3804 int SalomePyQt::createView( const QString& type, QWidget* w )
3806 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3807 QCoreApplication::processEvents();
3812 \fn bool SalomePyQt::closeView( const int id );
3814 \param id window identifier
3815 \return \c true if operation is completed successfully and \c false otherwise
3818 class TCloseView: public SALOME_Event
3821 typedef bool TResult;
3824 TCloseView( const int id )
3825 : myResult( false ),
3827 virtual void Execute()
3829 SUIT_ViewWindow* wnd = getWnd( myWndId );
3831 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3839 bool SalomePyQt::closeView( const int id )
3841 return ProcessEvent( new TCloseView( id ) );
3845 \fn int SalomePyQt::cloneView( const int id );
3846 \brief Clone view (if this operation is supported for specified view type)
3847 \param id window identifier
3848 \return integer identifier of the cloned view or -1 or operation could not be performed
3851 class TCloneView: public SALOME_Event
3854 typedef int TResult;
3857 TCloneView( const int id )
3860 virtual void Execute()
3862 SUIT_ViewWindow* wnd = getWnd( myWndId );
3864 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3866 #ifndef DISABLE_OCCVIEWER
3867 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3868 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3869 occView->onCloneView();
3870 wnd = viewMgr->getActiveView();
3872 myResult = wnd->getId();
3874 #endif // DISABLE_OCCVIEWER
3875 #ifndef DISABLE_PLOT2DVIEWER
3876 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3877 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3878 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3879 if ( viewMgr2d && srcWnd2d ) {
3880 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3881 myResult = resWnd->getId();
3884 #endif // DISABLE_OCCVIEWER
3889 int SalomePyQt::cloneView( const int id )
3891 return ProcessEvent( new TCloneView( id ) );
3895 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3896 \brief Set view visibility.
3897 \param id window identifier
3898 \param visible new visiblity
3901 void SalomePyQt::setViewVisible( const int id, const bool visible )
3903 class TEvent: public SALOME_Event
3908 TEvent( const int id, const bool visible )
3909 : myWndId( id ), myVisible( visible ) {}
3910 virtual void Execute()
3912 SUIT_ViewWindow* wnd = getWnd( myWndId );
3913 if ( wnd ) wnd->setVisible( myVisible );
3916 ProcessVoidEvent( new TEvent( id, visible ) );
3920 \fn bool SalomePyQt::isViewVisible( const int id );
3921 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3922 \param id window identifier
3923 \return \c true if view is visible and \c false otherwise
3926 class TIsViewVisible: public SALOME_Event
3929 typedef bool TResult;
3932 TIsViewVisible( const int id )
3933 : myResult( false ),
3935 virtual void Execute()
3937 SUIT_ViewWindow* wnd = getWnd( myWndId );
3940 QWidget* p = wnd->parentWidget();
3941 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3945 bool SalomePyQt::isViewVisible( const int id )
3947 return ProcessEvent( new TIsViewVisible( id ) );
3951 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3952 \brief Set / clear view's "closable" option. By default any view is closable
3953 (i.e. can be closed by the user).
3954 \param id window identifier
3955 \param on new "closable" option's value
3958 void SalomePyQt::setViewClosable( const int id, const bool on )
3960 class TEvent: public SALOME_Event
3965 TEvent( const int id, const bool on )
3966 : myWndId( id ), myOn( on ) {}
3967 virtual void Execute()
3969 SUIT_ViewWindow* wnd = getWnd( myWndId );
3970 if ( wnd ) wnd->setClosable( myOn );
3973 ProcessVoidEvent( new TEvent( id, on ) );
3977 \fn bool SalomePyQt::isViewClosable( const int id );
3978 \brief Check whether view is closable (i.e. can be closed by the user)
3979 \param id window identifier
3980 \return \c true if view is closable or \c false otherwise
3983 class TIsViewClosable: public SALOME_Event
3986 typedef bool TResult;
3989 TIsViewClosable( const int id )
3992 virtual void Execute()
3994 SUIT_ViewWindow* wnd = getWnd( myWndId );
3996 myResult = wnd->closable();
4000 bool SalomePyQt::isViewClosable( const int id )
4002 return ProcessEvent( new TIsViewClosable( id ) );
4006 \fn bool SalomePyQt::groupAllViews();
4007 \brief Group all views to the single tab area
4008 \return \c true if operation is completed successfully and \c false otherwise
4011 class TGroupAllViews: public SALOME_Event
4014 typedef bool TResult;
4017 : myResult( false ) {}
4018 virtual void Execute()
4020 LightApp_Application* app = getApplication();
4022 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4024 QtxWorkstack* wStack = tabDesk->workstack();
4033 bool SalomePyQt::groupAllViews()
4035 return ProcessEvent( new TGroupAllViews() );
4039 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
4040 \brief Split tab area to which view with identifier belongs to
4041 \param id window identifier
4042 \param ori orientation of split operation
4043 \param action action to be performed
4044 \return \c true if operation is completed successfully \c false otherwise
4047 class TSplitView: public SALOME_Event
4050 typedef bool TResult;
4055 TSplitView( const int id,
4056 const Orientation ori,
4057 const Action action )
4058 : myResult( false ),
4061 myAction( action ) {}
4062 virtual void Execute()
4064 SUIT_ViewWindow* wnd = getWnd( myWndId );
4067 // wnd->setFocus(); ???
4070 if ( getApplication() ) {
4071 STD_TabDesktop* desk =
4072 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
4074 QtxWorkstack* wStack = desk->workstack();
4076 Qt::Orientation qtOri =
4077 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
4079 QtxWorkstack::SplitType sType;
4080 if ( myAction == MoveWidget )
4081 sType = QtxWorkstack::SplitMove;
4082 else if ( myAction == LeaveWidget )
4083 sType = QtxWorkstack::SplitStay;
4085 sType = QtxWorkstack::SplitAt;
4087 wStack->Split( wnd, qtOri, sType );
4095 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
4097 return ProcessEvent( new TSplitView( id, ori, action ) );
4101 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
4102 \brief Move view with the first identifier to the same area which
4103 another view with the second identifier belongs to
4104 \param id source window identifier
4105 \param id_to destination window identifier
4106 param before specifies whether the first viewt has to be moved before or after
4108 \return \c true if operation is completed successfully and \c false otherwise
4111 class TMoveView: public SALOME_Event
4114 typedef bool TResult;
4119 TMoveView( const int id, const int id_to, const bool before )
4120 : myResult( false ),
4123 myIsBefore( before ) {}
4124 virtual void Execute()
4126 SUIT_ViewWindow* wnd = getWnd( myWndId );
4127 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
4128 if ( wnd && wnd_to ) {
4129 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
4130 getApplication()->desktop() )->workstack();
4132 myResult = wStack->move( wnd, wnd_to, myIsBefore );
4136 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
4138 return ProcessEvent( new TMoveView( id, id_to, before ) );
4142 \fn QList<int> SalomePyQt::neighbourViews( const int id );
4143 \brief Get list of views identifiers that belongs to the same area as
4144 specified view (excluding it)
4145 \param id window identifier
4146 \return list of views identifiers
4149 class TNeighbourViews: public SALOME_Event
4152 typedef QList<int> TResult;
4155 TNeighbourViews( const int id )
4157 virtual void Execute()
4160 SUIT_ViewWindow* wnd = getWnd( myWndId );
4162 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
4163 getApplication()->desktop() )->workstack();
4165 QWidgetList wgList = wStack->windowList( wnd );
4167 foreach ( wg, wgList ) {
4168 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
4169 if ( tmpWnd && tmpWnd != wnd )
4170 myResult.append( tmpWnd->getId() );
4176 QList<int> SalomePyQt::neighbourViews( const int id )
4178 return ProcessEvent( new TNeighbourViews( id ) );
4183 \fn void SalomePyQt::createRoot();
4184 \brief Initialize root data object.
4186 Does nothing if root is already initialized.
4189 void SalomePyQt::createRoot()
4191 class TEvent: public SALOME_Event
4195 virtual void Execute()
4197 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4199 SALOME_PYQT_DataModelLight* dm =
4200 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
4205 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
4209 ProcessVoidEvent( new TEvent() );
4213 \fn QString SalomePyQt::createObject( const QString& parent );
4214 \brief Create empty data object
4215 \param parent entry of parent data object
4216 \return entry of created data object
4219 class TCreateEmptyObjectEvent: public SALOME_Event
4222 typedef QString TResult;
4225 TCreateEmptyObjectEvent( const QString& parent )
4226 : myParent( parent ) {}
4227 virtual void Execute()
4229 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4231 myResult = module->createObject( myParent );
4234 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
4238 QString SalomePyQt::createObject( const QString& parent )
4240 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
4244 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
4245 const QString& tooltip,const QString& parent );
4246 \brief Create new data object with specified name, icon and tooltip
4247 \param name data object name
4248 \param icon data object icon
4249 \param toolTip data object tooltip
4250 \param parent entry of parent data object
4251 \return entry of created data object
4254 class TCreateObjectEvent: public SALOME_Event
4257 typedef QString TResult;
4263 TCreateObjectEvent( const QString& name,
4264 const QString& icon,
4265 const QString& tooltip,
4266 const QString& parent )
4267 : myParent( parent ),
4270 myToolTip( tooltip ) {}
4271 virtual void Execute()
4273 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4275 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
4278 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
4282 QString SalomePyQt::createObject( const QString& name,
4283 const QString& icon,
4284 const QString& toolTip,
4285 const QString& parent )
4287 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
4292 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
4293 \brief Set data object name
4294 \param entry data object entry
4295 \param name data object name
4297 class TSetNameEvent: public SALOME_Event
4302 TSetNameEvent( const QString& entry,
4303 const QString& name )
4306 virtual void Execute()
4308 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4310 module->setName( myEntry, myName );
4313 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
4317 void SalomePyQt::setName( const QString& entry, const QString& name )
4319 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
4323 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
4324 \brief Set data object icon
4325 \param entry data object entry
4326 \param icon data object icon file name (icon is loaded from module resources)
4329 class TSetIconEvent: public SALOME_Event
4334 TSetIconEvent( const QString& entry,
4335 const QString& icon )
4338 virtual void Execute()
4340 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4342 module->setIcon( myEntry, myIcon );
4345 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4350 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4352 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4356 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4357 \brief Set data object tooltip
4358 \param entry data object entry
4359 \param toolTip data object tooltip
4362 class TSetToolTipEvent: public SALOME_Event
4367 TSetToolTipEvent( const QString& entry,
4368 const QString& toolTip )
4370 myToolTip( toolTip ) {}
4371 virtual void Execute()
4373 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4375 module->setToolTip( myEntry, myToolTip );
4378 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4382 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4384 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4388 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4389 \brief Set reference to another data object
4390 \param entry data object entry
4391 \param refEntry referenced data object entry
4394 class TSetRefEvent: public SALOME_Event
4399 TSetRefEvent( const QString& entry,
4400 const QString& refEntry )
4402 myRefEntry( refEntry ) {}
4403 virtual void Execute()
4405 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4407 module->setReference( myEntry, myRefEntry );
4410 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4414 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4416 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4420 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4421 \brief Set data object color
4422 \param entry data object entry
4423 \param color data object color
4426 class TSetColorEvent: public SALOME_Event
4431 TSetColorEvent( const QString& entry,
4432 const QColor& color )
4435 virtual void Execute()
4437 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4439 module->setColor( myEntry, myColor );
4442 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4446 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4448 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4452 \fn QString SalomePyQt::getName( const QString& entry );
4453 \brief Get data object name
4454 \param entry data object entry
4455 \return data object name
4458 class TGetNameEvent: public SALOME_Event
4461 typedef QString TResult;
4464 TGetNameEvent( const QString& entry )
4465 : myEntry( entry ) {}
4466 virtual void Execute()
4468 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4470 myResult = module->getName( myEntry );
4473 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4477 QString SalomePyQt::getName( const QString& entry )
4479 return ProcessEvent( new TGetNameEvent( entry ) );
4483 \fn QString SalomePyQt::getToolTip( const QString& entry );
4484 \brief Get data object tooltip
4485 \param entry data object entry
4486 \return data object tooltip
4489 class TGetToolTipEvent: public SALOME_Event
4492 typedef QString TResult;
4495 TGetToolTipEvent( const QString& entry )
4496 : myEntry( entry ) {}
4497 virtual void Execute()
4499 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4501 myResult = module->getToolTip( myEntry );
4504 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4508 QString SalomePyQt::getToolTip( const QString& entry )
4510 return ProcessEvent( new TGetToolTipEvent( entry ) );
4514 \fn QString SalomePyQt::getReference( const QString& entry );
4515 \brief Get entry of the referenced object (if there's any)
4516 \param entry data object entry
4517 \return referenced data object entry
4520 class TGetRefEvent: public SALOME_Event
4523 typedef QString TResult;
4526 TGetRefEvent( const QString& entry )
4527 : myEntry( entry ) {}
4528 virtual void Execute()
4530 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4532 myResult = module->getReference( myEntry );
4535 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4539 QString SalomePyQt::getReference( const QString& entry )
4541 return ProcessEvent( new TGetRefEvent( entry ) );
4545 \fn QColor SalomePyQt::getColor( const QString& entry );
4546 \brief Get data object color
4547 \param entry data object entry
4548 \return data object color
4551 class TGetColorEvent: public SALOME_Event
4554 typedef QColor TResult;
4557 TGetColorEvent( const QString& entry )
4558 : myEntry( entry ) {}
4559 virtual void Execute()
4561 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4563 myResult = module->getColor( myEntry );
4566 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4570 QColor SalomePyQt::getColor( const QString& entry )
4572 return ProcessEvent( new TGetColorEvent( entry ) );
4576 \fn void SalomePyQt::removeChildren( const QString& entry );
4577 \brief Remove all child data objects from specified data object
4578 \param entry data object entry
4581 class TRemoveChildEvent: public SALOME_Event
4585 TRemoveChildEvent( const QString& entry )
4586 : myEntry( entry ) {}
4587 virtual void Execute()
4589 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4591 module->removeChildren( myEntry );
4594 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4598 void SalomePyQt::removeChildren( const QString& entry )
4600 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4602 void SalomePyQt::removeChild( const QString& entry )
4604 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4605 removeChildren( entry );
4609 \fn void SalomePyQt::removeObject( const QString& entry );
4610 \brief Remove object by entry
4611 \param entry data object entry
4614 class TRemoveObjectEvent: public SALOME_Event
4619 TRemoveObjectEvent( const QString& entry )
4620 : myEntry( entry ) {}
4621 virtual void Execute()
4623 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4625 module->removeObject( myEntry );
4628 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4632 void SalomePyQt::removeObject( const QString& entry )
4634 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4638 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4639 \brief Get entries of all child data objects of specified data object
4640 \param entry data object entry
4641 \param recursive \c true for recursive processing
4644 class TGetChildrenEvent: public SALOME_Event
4647 typedef QStringList TResult;
4651 TGetChildrenEvent( const QString& entry, const bool recursive )
4653 myRecursive( recursive ) {}
4654 virtual void Execute()
4656 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4658 myResult = module->getChildren( myEntry, myRecursive );
4661 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4665 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4667 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4670 #ifndef DISABLE_PLOT2DVIEWER
4671 // Next set of methods relates to the Plot2d viewer functionality
4674 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4675 \brief Display theCurve in view
4676 \param id window identifier
4677 \param theCurve curve to display
4680 class TDisplayCurve: public SALOME_Event
4684 Plot2d_Curve* myCurve;
4685 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4686 virtual void Execute() {
4687 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4689 wnd->getViewFrame()->displayCurve( myCurve );
4692 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4694 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4698 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4699 \brief Erase theCurve in view
4700 \param id window identifier
4701 \param theCurve curve to erase
4704 class TEraseCurve: public SALOME_Event
4708 Plot2d_Curve* myCurve;
4709 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4710 virtual void Execute() {
4711 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4712 wnd->getViewFrame()->eraseCurve( myCurve );
4715 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4717 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4721 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4722 \brief Delete theCurve from all views
4723 \param theCurve curve to delete
4726 class TDeleteCurve: public SALOME_Event
4729 Plot2d_Curve* myCurve;
4730 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4731 virtual void Execute() {
4732 LightApp_Application* app = getApplication();
4734 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4736 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4737 SUIT_ViewWindow* wnd;
4738 foreach ( wnd, wndlist ) {
4739 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4741 aP2d->getViewFrame()->eraseObject( myCurve );
4747 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4749 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4753 \brief updateCurves (repaint) curves in view window.
4755 void SalomePyQt::updateCurves( const int id )
4757 class TEvent: public SALOME_Event
4761 TEvent( const int id ) : myWndId( id ) {}
4762 virtual void Execute()
4764 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4766 wnd->getViewFrame()->DisplayAll();
4769 ProcessVoidEvent( new TEvent( id ) );
4773 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4774 \brief Get title of corresponding type
4775 \param id window identifier
4776 \param type is type of title
4777 \return title of corresponding type
4780 class TGetPlot2dTitle: public SALOME_Event
4783 typedef QString TResult;
4787 TGetPlot2dTitle(const int id, ObjectType type) :
4790 virtual void Execute() {
4791 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4793 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4796 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4798 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4803 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4804 \brief Set title of corresponding type
4805 \param id window identifier
4807 \param type is type of title
4811 class TSetPlot2dTitle: public SALOME_Event
4815 Plot2d_Curve* myCurve;
4819 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4824 virtual void Execute() {
4825 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4826 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4829 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4831 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4835 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4836 \brief Get list of Plot2d view ranges
4837 \param id window identifier
4838 \return list of view ranges (XMin, XMax, YMin, YMax)
4841 class TFitRangeByCurves: public SALOME_Event
4844 typedef QList<double> TResult;
4847 TFitRangeByCurves( const int id )
4849 virtual void Execute()
4852 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4854 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4855 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4856 myResult.append( XMin );
4857 myResult.append( XMax );
4858 myResult.append( YMin );
4859 myResult.append( YMax );
4863 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4865 return ProcessEvent( new TFitRangeByCurves( id ) );
4869 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4870 \brief Get list of current Plot2d view ranges
4871 \param id window identifier
4872 \return list of view ranges (XMin, XMax, YMin, YMax)
4875 class TFitRangeCurrent: public SALOME_Event
4878 typedef QList<double> TResult;
4881 TFitRangeCurrent( const int id )
4883 virtual void Execute()
4886 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4888 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4889 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4890 myResult.append( XMin );
4891 myResult.append( XMax );
4892 myResult.append( YMin );
4893 myResult.append( YMax );
4897 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4899 return ProcessEvent( new TFitRangeCurrent( id ) );
4903 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4904 \brief Set range of Plot2d view
4905 \param id window identifier
4912 class TPlot2dFitRange: public SALOME_Event
4920 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4926 virtual void Execute() {
4927 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4929 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4932 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4934 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4937 // End of methods related to the Plot2d viewer functionality
4938 #endif // DISABLE_PLOT2DVIEWER
4941 \brief Process Qt event loop
4943 void SalomePyQt::processEvents()
4945 QCoreApplication::processEvents();
4949 \brief Set visibility state for given object
4950 \param theEntry study ID of the object
4951 \param theState visibility state
4953 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4955 class TEvent: public SALOME_Event
4960 TEvent( const QString& theEntry, int theState ):
4961 myEntry( theEntry ), myState( theState ) {}
4962 virtual void Execute()
4964 LightApp_Study* aStudy = getActiveStudy();
4967 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4970 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4974 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4975 \brief Get visibility state for given object
4976 \param theEntry study ID of the object
4977 \return visibility state
4980 class TGetVisibilityStateEvent: public SALOME_Event
4983 typedef int TResult;
4986 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4987 virtual void Execute()
4989 LightApp_Study* aStudy = getActiveStudy();
4991 myResult = aStudy->visibilityState( myEntry );
4994 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4996 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
5000 \brief Set position of given object in the tree
5001 \param theEntry study ID of the object
5002 \param thePos position
5004 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
5006 class TEvent: public SALOME_Event
5011 TEvent( const QString& theEntry, int thePos ):
5012 myEntry( theEntry ), myPos( thePos ) {}
5013 virtual void Execute()
5015 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
5017 module->setObjectPosition( myEntry, myPos );
5020 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
5024 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
5025 \brief Get position of given object in the tree
5026 \param theEntry study ID of the object
5030 class TGetObjectPositionEvent: public SALOME_Event
5033 typedef int TResult;
5036 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
5037 virtual void Execute()
5039 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
5041 myResult = module->getObjectPosition( myEntry );
5044 int SalomePyQt::getObjectPosition( const QString& theEntry )
5046 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
5050 \brief Start recordind a log of Python commands from embedded console
5051 \param theFileName output lof file name
5053 void SalomePyQt::startPyLog( const QString& theFileName )
5055 class TEvent: public SALOME_Event
5059 TEvent( const QString& theFileName ):
5060 myFileName( theFileName ) {}
5061 virtual void Execute()
5063 if ( getApplication() ) {
5064 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
5065 if ( pyConsole ) pyConsole->startLog( myFileName );
5069 ProcessVoidEvent( new TEvent( theFileName ) );
5073 \brief Stop recordind a log of Python commands from embedded console
5075 void SalomePyQt::stopPyLog()
5077 class TEvent: public SALOME_Event
5081 virtual void Execute()
5083 if ( getApplication() ) {
5084 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
5085 if ( pyConsole ) pyConsole->stopLog();
5089 ProcessVoidEvent( new TEvent() );