1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SalomePyQt.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 // E.A. : On windows with python 2.6, there is a conflict
28 // E.A. : between pymath.h and Standard_math.h which define
29 // E.A. : some same symbols : acosh, asinh, ...
30 #include <Standard_math.hxx>
34 #include "SALOME_PYQT_ModuleLight.h" // this include must be first!!!
35 #include "SALOME_PYQT_DataModelLight.h"
36 #include "SALOME_PYQT_PyModule.h"
37 #include "SalomePyQt.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "LogWindow.h"
41 #ifndef DISABLE_OCCVIEWER
42 #include "OCCViewer_ViewWindow.h"
43 #include "OCCViewer_ViewFrame.h"
44 #endif // DISABLE_OCCVIEWER
45 #ifndef DISABLE_VTKVIEWER
46 #include "SVTK_ViewWindow.h"
47 #endif // DISABLE_VTKVIEWER
48 #ifndef DISABLE_PLOT2DVIEWER
49 #include "Plot2d_ViewManager.h"
50 #include "Plot2d_ViewWindow.h"
51 #endif // DISABLE_PLOT2DVIEWER
52 #ifndef DISABLE_PVVIEWER
53 #include "PVViewer_ViewManager.h"
54 #include "PVViewer_ViewModel.h"
55 #endif // DISABLE_PVVIEWER
56 #include "QtxActionMenuMgr.h"
57 #include "QtxWorkstack.h"
58 #include "QtxTreeView.h"
59 #include "SALOME_Event.h"
60 #include "STD_TabDesktop.h"
61 #include "SUIT_DataBrowser.h"
62 #include "SUIT_ResourceMgr.h"
63 #include "SUIT_Session.h"
64 #include "SUIT_Tools.h"
65 #include "SUIT_ViewManager.h"
66 #include "SUIT_ViewWindow.h"
67 #include "PyConsole_Console.h"
70 #include <QApplication>
71 #include <QPaintEvent>
72 #include <QCoreApplication>
73 #include <QVBoxLayout>
75 #include <utilities.h>
80 \brief Get the currently active application.
82 \return active application object or 0 if there is no any
84 LightApp_Application* getApplication()
86 if ( SUIT_Session::session() )
87 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
92 \brief Get the currently active study.
94 \return active study or 0 if there is no study opened
96 LightApp_Study* getActiveStudy()
98 if ( getApplication() )
99 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
104 \brief Get the currently active module.
106 This function returns correct result only if Python-based
107 module is currently active. Otherwize, 0 is returned.
109 LightApp_Module* getActiveModule()
111 LightApp_Module* module = 0;
112 if ( LightApp_Application* anApp = getApplication() ) {
113 module = PyModuleHelper::getInitModule();
115 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
121 \brief Get the currently active Python module's helper.
123 This function returns correct result only if Python-based
124 module is currently active. Otherwize, 0 is returned.
126 PyModuleHelper* getPythonHelper()
128 LightApp_Module* module = getActiveModule();
129 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
134 \brief Get SALOME verbose level
136 \return \c true if SALOME debug output is allowed or \c false otherwise
140 bool isVerbose = false;
141 if ( getenv( "SALOME_VERBOSE" ) ) {
142 QString envVar = getenv( "SALOME_VERBOSE" );
144 int value = envVar.toInt( &ok );
145 isVerbose = ok && value != 0;
151 \brief Get menu item title
153 \param menuId menu identifier
154 \return menu title (localized)
156 QString getMenuName( const QString& menuId )
158 QStringList contexts;
159 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
160 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
161 QString menuName = menuId;
162 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
163 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
168 \brief Load module icon
170 \param module module name
171 \param fileName path to the icon file
174 QIcon loadIconInternal( const QString& module, const QString& fileName )
178 LightApp_Application* app = getApplication();
180 if ( app && !fileName.isEmpty() ) {
181 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
182 QApplication::translate( module.toLatin1().data(),
183 fileName.toUtf8().data() ) );
184 if ( !pixmap.isNull() )
185 icon = QIcon( pixmap );
191 \brief Gets window with specified identifier
193 \param id window identifier
194 \return pointer on the window
196 SUIT_ViewWindow* getWnd( const int id )
198 SUIT_ViewWindow* resWnd = 0;
200 LightApp_Application* app = getApplication();
202 ViewManagerList vmlist = app->viewManagers();
203 foreach( SUIT_ViewManager* vm, vmlist ) {
204 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
205 foreach ( SUIT_ViewWindow* vw, vwlist ) {
206 if ( id == vw->getId() ) {
217 \brief Map of created selection objects.
220 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
223 \brief Default resource file section name.
226 const char* DEFAULT_SECTION = "SalomePyQt";
230 \class SALOME_Selection
231 \brief The class represents selection which can be used in Python.
235 \brief Get the selection object for the specified application.
237 Finds or creates the selection object (one per study).
239 \param app application object
240 \return selection object or 0 if \a app is invalid
242 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
244 SALOME_Selection* sel = 0;
245 if ( app && SelMap.find( app ) != SelMap.end() )
248 sel = SelMap[ app ] = new SALOME_Selection( app );
255 \param p parent object
257 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
259 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
261 mySelMgr = app->selectionMgr();
262 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
263 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
270 SALOME_Selection::~SALOME_Selection()
272 LightApp_Application* app = 0;
273 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
274 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
275 if ( it.value() == this ) app = it.key();
277 if ( app ) SelMap.remove( app );
281 \brief Called when selection manager is destroyed (usually
282 when the study is closed).
284 void SALOME_Selection::onSelMgrDestroyed()
290 \brief Clear the selection.
292 void SALOME_Selection::Clear()
294 class TEvent: public SALOME_Event
296 LightApp_SelectionMgr* mySelMgr;
298 TEvent( LightApp_SelectionMgr* selMgr )
299 : mySelMgr( selMgr ) {}
300 virtual void Execute()
303 mySelMgr->clearSelected();
306 ProcessVoidEvent( new TEvent( mySelMgr ) );
310 \brief Clear the selection.
312 void SALOME_Selection::ClearIObjects()
318 Removes all selection filters.
320 void SALOME_Selection::ClearFilters()
322 class TEvent: public SALOME_Event
324 LightApp_SelectionMgr* mySelMgr;
326 TEvent( LightApp_SelectionMgr* selMgr )
327 : mySelMgr( selMgr ) {}
328 virtual void Execute()
331 mySelMgr->clearFilters();
334 ProcessVoidEvent( new TEvent( mySelMgr ) );
338 \class UserDefinedContent
339 \brief The class represents base class for user defined widget that
340 can be inserted to the Preferences dialog.
346 UserDefinedContent::UserDefinedContent()
352 \brief Called from Preferences dialog to store settings to the resource file.
354 void UserDefinedContent::store()
359 \brief Called from Preferences dialog to restore settings from the resource file.
361 void UserDefinedContent::retrieve()
366 \class SgPyQtUserDefinedContent
367 \brief A Wrapper for UserDefinedContent class.
370 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
373 SgPyQtUserDefinedContent(UserDefinedContent*);
374 virtual ~SgPyQtUserDefinedContent();
376 void store( QtxResourceMgr*, QtxPreferenceMgr* );
377 void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
380 UserDefinedContent* myContent;
384 \brief Create custom item for Preferences dialog wrapping widget passed from Python.
387 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
388 : QtxUserDefinedContent( 0 ), myContent( content )
390 QVBoxLayout* l = new QVBoxLayout( this );
391 l->setContentsMargins( 0, 0, 0, 0 );
392 l->addWidget( myContent );
399 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
404 \brief Called from Preferences dialog to store settings to the resource file.
407 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
413 \brief Called from Preferences dialog to restore settings from the resource file.
416 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
418 myContent->retrieve();
423 \brief The class provides utility functions which can be used in the Python
424 to operate with the SALOME GUI.
426 All the functionality of this class is implemented as static methods, so they
427 can be called with the class name prefixed or via creation of the class instance.
428 For example, next both ways of SalomePyQt class usage are legal:
430 from SalomePyQt import *
432 # using SalomePyQt class instance
433 desktop = sg.getDesktop()
434 # using SalomePyQt class directly
435 menubar = SalomePyQt.getMainMenuBar()
440 \fn QString SalomePyQt::getAppName();
441 \brief Get application name
442 \return application name
445 QString SalomePyQt::getAppName()
447 LightApp_Application* app = getApplication();
448 return app == 0 ? QString() : QString(app->metaObject()->className()).split("_").first();
452 \fn bool SalomePyQt::isLightApp();
453 \brief Check if SALOME GUI is running in "light" mode.
454 \return \c true if this is a "light" application; \c false otherwise
457 bool SalomePyQt::isLightApp()
459 return SalomePyQt::getAppName() != "SalomeApp";
463 \fn QWidget* SalomePyQt::getDesktop();
464 \brief Get the active application's desktop window.
465 \return desktop window or 0 if there is no any
468 class TGetDesktopEvent: public SALOME_Event
471 typedef QWidget* TResult;
473 TGetDesktopEvent() : myResult( 0 ) {}
474 virtual void Execute()
476 if ( getApplication() )
477 myResult = (QWidget*)( getApplication()->desktop() );
480 QWidget* SalomePyQt::getDesktop()
482 return ProcessEvent( new TGetDesktopEvent() );
486 \fn QWidget* SalomePyQt::getMainFrame();
487 \brief Get current application's main frame widget [obsolete].
489 Main frame widget is an internal widget of the application
490 desktop window (workspace).
492 \return workspace widget (0 on any error)
495 class TGetMainFrameEvent: public SALOME_Event
498 typedef QWidget* TResult;
500 TGetMainFrameEvent() : myResult( 0 ) {}
501 virtual void Execute()
503 if ( getApplication() ) {
504 SUIT_Desktop* aDesktop = getApplication()->desktop();
505 myResult = (QWidget*)( aDesktop->centralWidget() );
509 QWidget* SalomePyQt::getMainFrame()
511 return ProcessEvent( new TGetMainFrameEvent() );
515 \fn QMenuBar* SalomePyQt::getMainMenuBar();
516 \brief Get current application desktop's main menu.
517 \return main menu object (0 on any error)
520 class TGetMainMenuBarEvent: public SALOME_Event
523 typedef QMenuBar* TResult;
525 TGetMainMenuBarEvent() : myResult( 0 ) {}
526 virtual void Execute()
528 if ( LightApp_Application* anApp = getApplication() ) {
529 myResult = anApp->desktop()->menuBar();
533 QMenuBar* SalomePyQt::getMainMenuBar()
535 return ProcessEvent( new TGetMainMenuBarEvent() );
539 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
540 \brief Get main menu's child popup submenu by its identifier.
542 This function is obsolete.
543 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
545 \param menu menu identifier
546 \return popup submenu object or 0 if it does not exist
550 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
551 \brief Get main menu's child popup submenu by its name.
553 The function creates menu if it does not exist.
555 \param menu menu name
556 \return popup submenu object (0 on any error)
559 class TGetPopupMenuEvent: public SALOME_Event
562 typedef QMenu* TResult;
565 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
566 virtual void Execute()
568 LightApp_Application* anApp = getApplication();
569 if ( anApp && !myMenuName.isEmpty() ) {
570 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
571 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
576 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
581 menuName = getMenuName( "MEN_DESK_FILE" ); break;
583 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
585 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
587 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
589 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
591 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
593 menuName = getMenuName( "MEN_DESK_HELP" ); break;
595 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
597 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
599 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
603 \fn QTreeView* SalomePyQt::getObjectBrowser();
604 \brief Get object browser
605 \return object browser for the active study or 0 in case of error
608 class TGetObjectBrowserEvent: public SALOME_Event
611 typedef QTreeView* TResult;
613 TGetObjectBrowserEvent() : myResult( 0 ) {}
614 virtual void Execute()
616 LightApp_Application* anApp = getApplication();
617 if ( anApp && anApp->objectBrowser() ) {
618 myResult = anApp->objectBrowser()->treeView();
622 QTreeView* SalomePyQt::getObjectBrowser()
624 return ProcessEvent( new TGetObjectBrowserEvent() );
628 \fn SALOME_Selection* SalomePyQt::getSelection();
629 \brief Get the selection object for the current study.
631 Creates a Selection object if it has not been created yet.
633 \return selection object (0 on error)
636 class TGetSelectionEvent: public SALOME_Event
639 typedef SALOME_Selection* TResult;
641 TGetSelectionEvent() : myResult( 0 ) {}
642 virtual void Execute()
644 myResult = SALOME_Selection::GetSelection( getApplication() );
647 SALOME_Selection* SalomePyQt::getSelection()
649 return ProcessEvent( new TGetSelectionEvent() );
653 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
654 \brief Send local selection for notification.
656 The list of locally selected objects (study entries) is sent for notification of
657 other listening entities (modules, viewers...).
660 class TSetSelectionEvent: public SALOME_Event
662 QStringList myEntryList;
664 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
665 virtual void Execute()
667 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
668 if ( !module ) return;
669 module->setLocalSelected(myEntryList);
672 void SalomePyQt::setSelection( const QStringList& entryList)
674 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
678 \fn void SalomePyQt::enableSelector();
679 \brief enable PyQt_Selector (on module activation, for instance)
682 class TEnableSelectorEvent: public SALOME_Event
685 TEnableSelectorEvent() {}
686 virtual void Execute()
688 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
689 if ( !module ) return;
690 module->enableSelector();
693 void SalomePyQt::enableSelector()
695 return ProcessVoidEvent( new TEnableSelectorEvent() );
700 \fn void SalomePyQt::disableSelector();
701 \brief disable PyQt_Selector (on module activation, for instance)
704 class TdisableSelectorEvent: public SALOME_Event
707 TdisableSelectorEvent() {}
708 virtual void Execute()
710 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
711 if ( !module ) return;
712 module->disableSelector();
715 void SalomePyQt::disableSelector()
717 return ProcessVoidEvent( new TdisableSelectorEvent() );
722 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
723 \brief Put an information message to the current application's
726 Optional second delay parameter (\a sec) can be used to specify
727 time of the message diplaying in seconds. If this parameter is less
728 or equal to zero, the constant message will be put.
730 \param msg message text
731 \param sec message displaying time in seconds
734 class TPutInfoEvent: public SALOME_Event
739 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
740 virtual void Execute()
742 if ( LightApp_Application* anApp = getApplication() ) {
743 anApp->putInfo( myMsg, mySecs * 1000 );
747 void SalomePyQt::putInfo( const QString& msg, const int sec )
749 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
753 \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
754 \brief Show notification in the application's desktop window.
756 Optional third delay parameter (\a sec) can be used to specify
757 time of the notification diplaying in seconds. If this parameter is less
758 or equal to zero, the permanent notification will be put.
760 Notification can be forcibly hidden via hideNotification() method.
762 \param msg message text
763 \param title title text
764 \param sec notification displaying time in seconds
765 \return unique ID of the notification (can be used to hide notification)
766 \sa hideNotification()
769 class TShowNotifyEvent: public SALOME_Event
780 TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
781 virtual void Execute()
783 if ( LightApp_Application* anApp = getApplication() ) {
784 myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
789 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
791 return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
795 \fn void SalomePyQt::hideNotification( const QString& msg );
796 \brief Remove notification with given message text from the application's desktop.
798 \param msg message text
799 \sa showNotification()
803 \fn void SalomePyQt::hideNotification( const int id );
804 \brief Remove notification with given \a id from the application's desktop.
806 \param id notification id
807 \sa showNotification()
810 class THideNotifyEvent: public SALOME_Event
816 THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
817 THideNotifyEvent( const int id ) : myId( id ) {}
818 virtual void Execute()
820 if ( LightApp_Application* anApp = getApplication() ) {
822 anApp->hideNotification( myId );
824 anApp->hideNotification( myMsg );
829 void SalomePyQt::hideNotification( const QString& msg )
831 ProcessVoidEvent( new THideNotifyEvent( msg ) );
834 void SalomePyQt::hideNotification( const int id )
836 ProcessVoidEvent( new THideNotifyEvent( id ) );
840 \fn QStringList SalomePyQt::getComponents();
841 \brief Get all modules used in current GUI session.
842 \return List of modules
845 class TGetComponentsEvent: public SALOME_Event
848 typedef QStringList TResult;
850 TGetComponentsEvent() {}
851 virtual void Execute()
853 if ( LightApp_Application* anApp = getApplication() )
856 anApp->modules( titles, false );
857 foreach ( QString title, titles )
859 myResult << anApp->moduleName( title );
864 QStringList SalomePyQt::getComponents()
866 return ProcessEvent( new TGetComponentsEvent() );
870 \fn const QString SalomePyQt::getActiveComponent();
871 \brief Get the currently active module name (for the current study).
872 \return active module name or empty string if there is no active module
875 class TGetActiveComponentEvent: public SALOME_Event
878 typedef QString TResult;
880 TGetActiveComponentEvent() {}
881 virtual void Execute()
883 if ( LightApp_Application* anApp = getApplication() ) {
884 if ( CAM_Module* mod = anApp->activeModule() ) {
885 myResult = mod->name();
890 const QString SalomePyQt::getActiveComponent()
892 return ProcessEvent( new TGetActiveComponentEvent() );
896 \fn PyObject* SalomePyQt::getActivePythonModule();
897 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
898 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
901 class TGetActivePyModuleEvent: public SALOME_Event
904 typedef PyObject* TResult;
906 TGetActivePyModuleEvent() : myResult( Py_None ) {}
907 virtual void Execute()
909 PyModuleHelper* helper = getPythonHelper();
911 myResult = (PyObject*)helper->pythonModule();
914 PyObject* SalomePyQt::getActivePythonModule()
916 return ProcessEvent( new TGetActivePyModuleEvent() );
920 \fn bool SalomePyQt::activateModule( const QString& modName );
921 \brief Activates SALOME module with the given name
922 \return True if the module has been activated and False otherwise.
925 class TActivateModuleEvent: public SALOME_Event
928 typedef bool TResult;
930 QString myModuleName;
931 TActivateModuleEvent( const QString& modName )
932 : myResult( false ), myModuleName( modName ) {}
933 virtual void Execute()
935 if ( LightApp_Application* anApp = getApplication() ) {
936 myResult = anApp->activateModule( myModuleName );
940 bool SalomePyQt::activateModule( const QString& modName )
942 return ProcessEvent( new TActivateModuleEvent( modName ) );
946 \fn void SalomePyQt::registerModule( const QString& modName);
947 \brief Registers module in the study tree
950 void SalomePyQt::registerModule( const QString& modName)
952 class TEvent: public SALOME_Event
956 TEvent(const QString& name): myName(name) {}
957 virtual void Execute()
959 if ( LightApp_Application* anApp = getApplication() ) {
960 anApp->desktop()->emitMessage(QString("register_module_in_study/%1").arg(myName));
964 ProcessVoidEvent( new TEvent(modName) );
968 \brief Update an Object Browser of the study.
970 void SalomePyQt::updateObjBrowser()
972 class TEvent: public SALOME_Event
976 virtual void Execute()
978 if ( SUIT_Session::session() ) {
979 if ( getActiveStudy() ) {
980 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
981 QList<SUIT_Application*>::Iterator it;
982 for( it = apps.begin(); it != apps.end(); ++it ) {
983 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
984 if ( anApp && anApp->activeStudy() ) {
985 anApp->updateObjectBrowser();
993 ProcessVoidEvent( new TEvent() );
998 SalomePyQt::isModified()
999 \return The modification status of the data model
1000 for the currently active Python module
1001 \note This function is supported for "light" Python-based SALOME modules only.
1004 class TIsModifiedEvent: public SALOME_Event
1007 typedef bool TResult;
1009 TIsModifiedEvent() : myResult( false ) {}
1010 virtual void Execute()
1012 LightApp_Module* module = getActiveModule();
1016 SALOME_PYQT_DataModelLight* aModel =
1017 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1019 myResult = aModel->isModified();
1022 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
1026 bool SalomePyQt::isModified()
1028 return ProcessEvent(new TIsModifiedEvent());
1032 SalomePyQt::setModified()
1034 Sets the modification status of the data model for
1035 the currently active Python module. This method should be used
1036 by the Python code in order to enable/disable "Save" operation
1037 depending on the module's data state.
1039 \note This function is supported for "light" Python-based SALOME modules only.
1041 \param New modification status of the data model
1045 void SalomePyQt::setModified( bool flag )
1047 class TEvent: public SALOME_Event
1053 virtual void Execute()
1055 LightApp_Module* module = getActiveModule();
1059 SALOME_PYQT_DataModelLight* model =
1060 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1062 LightApp_Application* app = module->getApp();
1064 if ( model && app ) {
1065 model->setModified( myFlag );
1066 app->updateActions();
1069 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1073 ProcessVoidEvent( new TEvent( flag ) );
1077 \brief Add string setting to the application preferences.
1079 The parameter \a autoValue is obsolete parameter and currently is not used.
1080 This parameter will be removed in future, so try to avoid its usage in
1083 This function is obsolete. Use one of addSetting() instead.
1085 \param name setting name (it should be of kind <section:setting> where
1086 \c section is resources section name and \c setting is setting name)
1087 \param value new setting value
1088 \param autoValue (not used)
1090 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1092 class TEvent: public SALOME_Event
1098 TEvent( const QString& name, const QString& value, bool autoValue )
1099 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1100 virtual void Execute()
1102 if ( SUIT_Session::session() ) {
1103 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1104 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1105 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1106 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1107 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1108 resMgr->setValue( _sec, _nam, myValue );
1112 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1116 \brief Add integer setting to the application preferences.
1118 The parameter \a autoValue is obsolete parameter and currently is not used.
1119 This parameter will be removed in future, so try to avoid its usage in
1122 This function is obsolete. Use one of addSetting() instead.
1124 \param name setting name (it should be of kind <section:setting> where
1125 \c section is resources section name and \c setting is setting name)
1126 \param value new setting value
1127 \param autoValue (not used)
1129 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1131 class TEvent: public SALOME_Event
1137 TEvent( const QString& name, const int value, bool autoValue )
1138 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1139 virtual void Execute()
1141 if ( SUIT_Session::session() ) {
1142 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1143 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1144 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1145 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1146 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1147 resMgr->setValue( _sec, _nam, myValue );
1151 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1155 \brief Add double setting to the application preferences.
1157 The parameter \a autoValue is obsolete parameter and currently is not used.
1158 This parameter will be removed in future, so try to avoid its usage in
1161 This function is obsolete. Use one of addSetting() instead.
1163 \param name setting name (it should be of kind <section:setting> where
1164 \c section is resources section name and \c setting is setting name)
1165 \param value new setting value
1166 \param autoValue (not used)
1168 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1170 class TEvent: public SALOME_Event
1176 TEvent( const QString& name, const double value, bool autoValue )
1177 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1178 virtual void Execute()
1180 if ( SUIT_Session::session() ) {
1181 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1182 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1183 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1184 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1185 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1186 resMgr->setValue( _sec, _nam, myValue );
1190 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1194 \brief Add boolean setting to the application preferences.
1196 The parameter \a autoValue is obsolete parameter and currently is not used.
1197 This parameter will be removed in future, so try to avoid its usage in
1200 This function is obsolete. Use one of addSetting() instead.
1202 \param name setting name (it should be of kind <section:setting> where
1203 \c section is resources section name and \c setting is setting name)
1204 \param value new setting value
1205 \param autoValue (not used)
1207 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1209 class TEvent: public SALOME_Event
1215 TEvent( const QString& name, const bool value, bool autoValue )
1216 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1217 virtual void Execute()
1219 if ( SUIT_Session::session() ) {
1220 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1221 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1222 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1223 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1224 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1225 resMgr->setValue( _sec, _nam, myValue );
1229 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1233 \brief Remove setting from the application preferences.
1235 This function is obsolete. Use removeSetting() instead.
1237 \param name setting name (it should be of kind <section:setting> where
1238 \c section is resources section name and \c setting is setting name)
1240 void SalomePyQt::removeSettings( const QString& name )
1242 class TEvent: public SALOME_Event
1246 TEvent( const QString& name ) : myName( name ) {}
1247 virtual void Execute()
1249 if ( SUIT_Session::session() ) {
1250 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1251 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1252 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1253 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1254 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1255 resMgr->remove( _sec, _nam );
1259 ProcessVoidEvent( new TEvent( name ) );
1263 \fn QString SalomePyQt::getSetting( const QString& name );
1264 \brief Get application setting value (as string represenation).
1266 This function is obsolete. Use stringSetting(), integerSetting(),
1267 boolSetting(), stringSetting() or colorSetting() instead.
1269 \param name setting name (it should be of kind <section:setting> where
1270 \c section is resources section name and \c setting is setting name)
1271 \return setting name (empty string if setting name is invalid)
1274 class TGetSettingEvent: public SALOME_Event
1277 typedef QString TResult;
1280 TGetSettingEvent( const QString& name ) : myName( name ) {}
1281 virtual void Execute()
1283 if ( SUIT_Session::session() ) {
1284 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1285 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1286 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1287 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1288 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1292 QString SalomePyQt::getSetting( const QString& name )
1294 return ProcessEvent( new TGetSettingEvent( name ) );
1298 \fn QString SalomePyQt::constant( const QString& name );
1299 \brief Get constant's value from application's resource manager.
1301 \param name name of the constant
1302 \return value of the constant
1307 class TGetConstantEvent: public SALOME_Event
1310 typedef QString TResult;
1313 TGetConstantEvent( const QString& name ) : myName( name ) {}
1314 virtual void Execute()
1316 if ( SUIT_Session::session() )
1317 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1320 QString SalomePyQt::constant( const QString& name )
1322 return ProcessEvent( new TGetConstantEvent( name ) );
1326 \brief Add constant to the application's resource manager.
1328 This function is useful to specify programmatically specific
1329 variables that are referenced in the resource setting.
1331 For example, some resource value can be set as "$(myroot)/data/files".
1332 Then, "mypath" constant can be set programmatically by the application
1333 depending on run-time requirements.
1335 \param section resources file section name
1336 \param name name of the constant
1337 \param value value of the constant
1341 void SalomePyQt::setConstant( const QString& name, const QString& value )
1343 class TEvent: public SALOME_Event
1345 QString myName, myValue;
1347 TEvent( const QString& name, const QString& value )
1348 : myName( name ), myValue( value ) {}
1349 virtual void Execute()
1351 if ( SUIT_Session::session() )
1352 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1355 ProcessVoidEvent( new TEvent( name, value ) );
1359 \brief Add double setting to the application preferences.
1360 \param section resources file section name
1361 \param name setting name
1362 \param value new setting value
1364 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1366 class TEvent: public SALOME_Event
1372 TEvent( const QString& section, const QString& name, double value )
1373 : mySection( section ), myName( name ), myValue( value ) {}
1374 virtual void Execute()
1376 if ( SUIT_Session::session() ) {
1377 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1378 if ( !mySection.isEmpty() && !myName.isEmpty() )
1379 resMgr->setValue( mySection, myName, myValue );
1383 ProcessVoidEvent( new TEvent( section, name, value ) );
1387 \brief Add integer setting to the application preferences.
1388 \param section resources file section name
1389 \param name setting name
1390 \param value new setting value
1392 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1394 class TEvent: public SALOME_Event
1400 TEvent( const QString& section, const QString& name, int value )
1401 : mySection( section ), myName( name ), myValue( value ) {}
1402 virtual void Execute()
1404 if ( SUIT_Session::session() ) {
1405 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1406 if ( !mySection.isEmpty() && !myName.isEmpty() )
1407 resMgr->setValue( mySection, myName, myValue );
1411 ProcessVoidEvent( new TEvent( section, name, value ) );
1415 \brief Add boolean setting to the application preferences.
1416 \param section resources file section name
1417 \param name setting name
1418 \param value new setting value
1419 \param dumb this parameter is used in order to avoid sip compilation error
1420 because of conflicting int and bool types
1422 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1424 class TEvent: public SALOME_Event
1430 TEvent( const QString& section, const QString& name, bool value )
1431 : mySection( section ), myName( name ), myValue( value ) {}
1432 virtual void Execute()
1434 if ( SUIT_Session::session() ) {
1435 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1436 if ( !mySection.isEmpty() && !myName.isEmpty() )
1437 resMgr->setValue( mySection, myName, myValue );
1441 ProcessVoidEvent( new TEvent( section, name, value ) );
1445 \brief Add string setting to the application preferences.
1446 \param section resources file section name
1447 \param name setting name
1448 \param value new setting value
1450 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1452 class TEvent: public SALOME_Event
1458 TEvent( const QString& section, const QString& name, const QString& value )
1459 : mySection( section ), myName( name ), myValue( value ) {}
1460 virtual void Execute()
1462 if ( SUIT_Session::session() ) {
1463 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1464 if ( !mySection.isEmpty() && !myName.isEmpty() )
1465 resMgr->setValue( mySection, myName, myValue );
1469 ProcessVoidEvent( new TEvent( section, name, value ) );
1473 \brief Add color setting to the application preferences.
1474 \param section resources file section name
1475 \param name setting name
1476 \param value new setting value
1478 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1480 class TEvent: public SALOME_Event
1486 TEvent( const QString& section, const QString& name, const QColor& value )
1487 : mySection( section ), myName( name ), myValue( value ) {}
1488 virtual void Execute()
1490 if ( SUIT_Session::session() ) {
1491 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1492 if ( !mySection.isEmpty() && !myName.isEmpty() )
1493 resMgr->setValue( mySection, myName, myValue );
1497 ProcessVoidEvent( new TEvent( section, name, value ) );
1501 \brief Add byte array setting to the application preferences.
1502 \param section resources file section name
1503 \param name setting name
1504 \param value new setting value
1506 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1508 class TEvent: public SALOME_Event
1514 TEvent( const QString& section, const QString& name, const QByteArray& value )
1515 : mySection( section ), myName( name ), myValue( value ) {}
1516 virtual void Execute()
1518 if ( SUIT_Session::session() ) {
1519 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1520 if ( !mySection.isEmpty() && !myName.isEmpty() )
1521 resMgr->setValue( mySection, myName, myValue );
1525 ProcessVoidEvent( new TEvent( section, name, value ) );
1529 \brief Add font setting to the application preferences.
1530 \param section resources file section name
1531 \param name setting name
1532 \param value new setting value
1534 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1536 class TEvent: public SALOME_Event
1542 TEvent( const QString& section, const QString& name, const QFont& value )
1543 : mySection( section ), myName( name ), myValue( value ) {}
1544 virtual void Execute()
1546 if ( SUIT_Session::session() ) {
1547 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1548 if ( !mySection.isEmpty() && !myName.isEmpty() )
1549 resMgr->setValue( mySection, myName, myValue );
1553 ProcessVoidEvent( new TEvent( section, name, value ) );
1557 \fn int SalomePyQt::integerSetting( const QString& section,
1558 const QString& name,
1560 \brief Get integer setting from the application preferences.
1561 \param section resources file section name
1562 \param name setting name
1563 \param def default value which is returned if the setting is not found
1564 \return setting value
1567 class TGetIntSettingEvent: public SALOME_Event
1570 typedef int TResult;
1575 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1576 : mySection( section ), myName( name ), myDefault( def ) {}
1577 virtual void Execute()
1579 if ( SUIT_Session::session() ) {
1580 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1581 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1585 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1587 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1591 \fn double SalomePyQt::doubleSetting( const QString& section,
1592 const QString& name,
1594 \brief Get double setting from the application preferences.
1595 \param section resources file section name
1596 \param name setting name
1597 \param def default value which is returned if the setting is not found
1598 \return setting value
1601 class TGetDblSettingEvent: public SALOME_Event
1604 typedef double TResult;
1609 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1610 : mySection( section ), myName( name ), myDefault( def ) {}
1611 virtual void Execute()
1613 if ( SUIT_Session::session() ) {
1614 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1615 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1619 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1621 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1625 \fn bool SalomePyQt::boolSetting( const QString& section,
1626 const QString& name,
1628 \brief Get boolean setting from the application preferences.
1629 \param section resources file section name
1630 \param name setting name
1631 \param def default value which is returned if the setting is not found
1632 \return setting value
1635 class TGetBoolSettingEvent: public SALOME_Event
1638 typedef bool TResult;
1643 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1644 : mySection( section ), myName( name ), myDefault( def ) {}
1645 virtual void Execute()
1647 if ( SUIT_Session::session() ) {
1648 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1649 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1653 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1655 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1659 \fn QString SalomePyQt::stringSetting( const QString& section,
1660 const QString& name,
1663 \brief Get string setting from the application preferences.
1664 \param section resources file section name
1665 \param name setting name
1666 \param def default value which is returned if the setting is not found
1667 \param subst \c true to make substitution, \c false to get "raw" value
1668 \return setting value
1671 class TGetStrSettingEvent: public SALOME_Event
1674 typedef QString TResult;
1680 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1681 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1682 virtual void Execute()
1684 if ( SUIT_Session::session() ) {
1685 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1686 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1690 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1692 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1696 \fn QColor SalomePyQt::colorSetting( const QString& section,
1697 const QString& name,
1699 \brief Get color setting from the application preferences.
1700 \param section resources file section name
1701 \param name setting name
1702 \param def default value which is returned if the setting is not found
1703 \return setting value
1706 class TGetColorSettingEvent: public SALOME_Event
1709 typedef QColor TResult;
1714 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1715 : mySection( section ), myName( name ), myDefault( def ) {}
1716 virtual void Execute()
1718 if ( SUIT_Session::session() ) {
1719 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1720 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1724 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1726 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1730 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1731 const QString& name,
1732 const QByteArray& def );
1733 \brief Get byte array setting from the application preferences.
1734 \param section resources file section name
1735 \param name setting name
1736 \param def default value which is returned if the setting is not found
1737 \return setting value
1740 class TGetByteArraySettingEvent: public SALOME_Event
1743 typedef QByteArray TResult;
1748 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1749 : mySection( section ), myName( name ), myDefault( def ) {}
1750 virtual void Execute()
1752 if ( SUIT_Session::session() ) {
1753 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1754 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1758 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1760 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1764 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1765 const QString& name,
1767 \brief Get font setting from the application preferences.
1768 \param section resources file section name
1769 \param name setting name
1770 \param def default value which is returned if the setting is not found
1771 \return setting value
1774 class TGetFontSettingEvent: public SALOME_Event
1777 typedef QFont TResult;
1782 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1783 : mySection( section ), myName( name ), myDefault( def ) {}
1784 virtual void Execute()
1786 if ( SUIT_Session::session() ) {
1787 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1788 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1792 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1794 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1798 \brief Remove setting from the application preferences.
1799 \param section resources file section name
1800 \param name setting name
1802 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1804 class TEvent: public SALOME_Event
1809 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1810 virtual void Execute()
1812 if ( SUIT_Session::session() ) {
1813 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1814 if ( !mySection.isEmpty() && !myName.isEmpty() )
1815 resMgr->remove( mySection, myName );
1819 ProcessVoidEvent( new TEvent( section, name ) );
1823 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1824 \brief Check setting existence in the application preferences.
1825 \param section resources file section name
1826 \param name setting name
1827 \return \c true if setting exists
1830 class THasSettingEvent: public SALOME_Event
1833 typedef bool TResult;
1837 THasSettingEvent( const QString& section, const QString& name )
1838 : mySection( section ), myName( name ) {}
1839 virtual void Execute()
1841 if ( SUIT_Session::session() ) {
1842 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1843 myResult = resMgr->hasValue( mySection, myName );
1847 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1849 return ProcessEvent( new THasSettingEvent( section, name ) );
1853 \fn QStringList SalomePyQt::parameters( const QString& section );
1854 \brief Get names of preference items stored within the given section.
1855 \param section resources file section's name
1856 \return \c list of preferences items
1860 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1861 \brief Get names of preference items stored within the given section.
1862 \param section resources file section's name
1863 \return \c list of preferences items
1866 class TParametersEvent: public SALOME_Event
1869 typedef QStringList TResult;
1871 QStringList mySection;
1872 TParametersEvent( const QString& section )
1874 mySection << section;
1876 TParametersEvent( const QStringList& section )
1877 : mySection( section )
1879 virtual void Execute()
1881 if ( SUIT_Session::session() ) {
1882 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1883 myResult = resMgr->parameters( mySection );
1887 QStringList SalomePyQt::parameters( const QString& section )
1889 return ProcessEvent( new TParametersEvent( section ) );
1891 QStringList SalomePyQt::parameters( const QStringList& section )
1893 return ProcessEvent( new TParametersEvent( section ) );
1897 \fn QString SalomePyQt::getFileName( QWidget* parent,
1898 const QString& initial,
1899 const QStringList& filters,
1900 const QString& caption,
1902 \brief Show 'Open/Save file' dialog box for file selection
1903 and return a user's choice (selected file name).
1904 \param parent parent widget
1905 \param initial initial directory the dialog box to be opened in
1906 \param filters list of files filters (wildcards)
1907 \param caption dialog box title
1908 \param open if \c true, "Open File" dialog box is shown;
1909 otherwise "Save File" dialog box is shown
1910 \return selected file name (null string if user cancels operation)
1913 class TGetFileNameEvent: public SALOME_Event
1916 typedef QString TResult;
1920 QStringList myFilters;
1923 TGetFileNameEvent( QWidget* parent,
1924 const QString& initial,
1925 const QStringList& filters,
1926 const QString& caption,
1928 : myParent ( parent ),
1929 myInitial( initial ),
1930 myFilters( filters ),
1931 myCaption( caption ),
1933 virtual void Execute()
1935 if ( LightApp_Application* anApp = getApplication() ) {
1936 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1937 myCaption, myParent );
1941 QString SalomePyQt::getFileName( QWidget* parent,
1942 const QString& initial,
1943 const QStringList& filters,
1944 const QString& caption,
1947 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1951 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1952 const QString& initial,
1953 const QStringList& filters,
1954 const QString& caption );
1955 \brief Show 'Open files' dialog box for multiple files selection
1956 and return a user's choice (selected file names list).
1957 \param parent parent widget
1958 \param initial initial directory the dialog box to be opened in
1959 \param filters list of files filters (wildcards)
1960 \param caption dialog box title
1961 \return selected file names list (empty list if user cancels operation)
1964 class TGetOpenFileNamesEvent: public SALOME_Event
1967 typedef QStringList TResult;
1971 QStringList myFilters;
1973 TGetOpenFileNamesEvent( QWidget* parent,
1974 const QString& initial,
1975 const QStringList& filters,
1976 const QString& caption )
1977 : myParent ( parent ),
1978 myInitial( initial ),
1979 myFilters( filters ),
1980 myCaption( caption ) {}
1981 virtual void Execute()
1983 if ( LightApp_Application* anApp = getApplication() ) {
1984 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1988 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1989 const QString& initial,
1990 const QStringList& filters,
1991 const QString& caption )
1993 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1997 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1998 const QString& initial,
1999 const QString& caption );
2000 \brief Show 'Get Directory' dialog box for the directory selection
2001 and return a user's choice (selected directory name).
2002 \param parent parent widget
2003 \param initial initial directory the dialog box to be opened in
2004 \param caption dialog box title
2005 \return selected directory name (null string if user cancels operation)
2008 class TGetExistingDirectoryEvent: public SALOME_Event
2011 typedef QString TResult;
2016 TGetExistingDirectoryEvent( QWidget* parent,
2017 const QString& initial,
2018 const QString& caption )
2019 : myParent ( parent ),
2020 myInitial( initial ),
2021 myCaption( caption ) {}
2022 virtual void Execute()
2024 if ( LightApp_Application* anApp = getApplication() ) {
2025 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
2029 QString SalomePyQt::getExistingDirectory( QWidget* parent,
2030 const QString& initial,
2031 const QString& caption )
2033 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
2037 \fn QString SalomePyQt::loadIcon( const QString& filename );
2038 \brief Load an icon from the module resources by the specified file name.
2039 \param fileName icon file name
2043 class TLoadIconEvent: public SALOME_Event
2046 typedef QIcon TResult;
2050 TLoadIconEvent( const QString& module, const QString& filename )
2051 : myModule( module ),
2052 myFileName ( filename ) {}
2053 virtual void Execute()
2055 myResult = loadIconInternal( myModule, myFileName );
2058 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2060 return ProcessEvent( new TLoadIconEvent( module, filename ) );
2064 \brief Open external browser to display context help information.
2067 Current implementation does nothing.
2069 \param source documentation (HTML) file name
2070 \param context context (for example, HTML ancor name)
2072 void SalomePyQt::helpContext( const QString& source, const QString& context )
2074 class TEvent: public SALOME_Event
2079 TEvent( const QString& source, const QString& context )
2080 : mySource( source ), myContext( context ) {}
2081 virtual void Execute()
2083 if ( LightApp_Application* anApp = getApplication() ) {
2084 anApp->onHelpContextModule( "", mySource, myContext );
2088 ProcessVoidEvent( new TEvent( source, context ) );
2092 \fn int SalomePyQt::defaultMenuGroup();
2093 \brief Get detault menu group identifier which can be used when
2094 creating menus (insert custom menu commands).
2095 \return default menu group ID
2098 class TDefMenuGroupEvent: public SALOME_Event
2101 typedef int TResult;
2103 TDefMenuGroupEvent() : myResult( -1 ) {}
2104 virtual void Execute()
2106 myResult = PyModuleHelper::defaultMenuGroup();
2109 int SalomePyQt::defaultMenuGroup()
2111 return ProcessEvent( new TDefMenuGroupEvent() );
2117 CrTool( const QString& tBar, const QString& nBar )
2118 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
2119 CrTool( const int id, const int tBar, const int idx )
2120 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
2121 CrTool( const int id, const QString& tBar, const int idx )
2122 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
2123 CrTool( QAction* action, const int tbId, const int id, const int idx )
2124 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
2125 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2126 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2132 if ( getActiveModule() )
2133 return getActiveModule()->createTool( myTbTitle, myTbName );
2134 else if ( getApplication() )
2135 return getApplication()->createTool( myTbTitle, myTbName );
2137 if ( getActiveModule() )
2138 return getActiveModule()->createTool( myId, myTbId, myIndex );
2139 else if ( getApplication() )
2140 return getApplication()->createTool( myId, myTbId, myIndex );
2142 if ( getActiveModule() )
2143 return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2144 else if ( getApplication() )
2145 return getApplication()->createTool( myId, myTbTitle, myIndex );
2147 if ( getActiveModule() )
2148 return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2149 else if ( getApplication() )
2150 return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2152 if ( getActiveModule() )
2153 return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2154 else if ( getApplication() )
2155 return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2169 class TCreateToolEvent: public SALOME_Event
2172 typedef int TResult;
2174 const CrTool& myCrTool;
2175 TCreateToolEvent( const CrTool& crTool )
2176 : myResult( -1 ), myCrTool( crTool ) {}
2177 virtual void Execute()
2179 myResult = myCrTool.execute();
2184 \brief Create toolbar with specified name.
2185 \param tBar toolbar title (language-dependent)
2186 \param nBar toolbar name (language-independent) [optional]
2187 \return toolbar ID or -1 if toolbar creation is failed
2189 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2191 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2195 \brief Insert action with specified \a id to the toolbar.
2197 \param tBar toolbar ID
2198 \param idx required index in the toolbar
2199 \return action ID or -1 if action could not be added
2201 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2203 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2207 \brief Insert action with specified \a id to the toolbar.
2209 \param tBar toolbar name
2210 \param idx required index in the toolbar
2211 \return action ID or -1 if action could not be added
2213 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2215 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2219 \brief Insert action to the toolbar.
2221 \param tBar toolbar ID
2222 \param id required action ID
2223 \param idx required index in the toolbar
2224 \return action ID or -1 if action could not be added
2226 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2228 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2233 \brief Clear given toolbar.
2234 \param title toolbar's title
2236 void SalomePyQt::clearTool( const QString& title )
2238 class TEvent: public SALOME_Event
2242 TEvent( const QString& title )
2243 : myTitle( title ) {}
2244 virtual void Execute()
2246 if ( getActiveModule() )
2247 return getActiveModule()->clearTool( myTitle );
2248 else if ( getApplication() )
2249 return getApplication()->clearTool( myTitle );
2252 ProcessVoidEvent( new TEvent( title ) );
2256 \brief Insert action to the toolbar.
2258 \param tBar toolbar name
2259 \param id required action ID
2260 \param idx required index in the toolbar
2261 \return action ID or -1 if action could not be added
2263 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2265 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2271 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2272 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2273 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2274 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2275 CrMenu( const int id, const int menu, const int group, const int idx )
2276 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
2277 CrMenu( const int id, const QString& menu, const int group, const int idx )
2278 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
2279 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2280 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2281 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2282 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
2288 if ( getActiveModule() )
2289 return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2290 else if ( getApplication() )
2291 return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2293 if ( getActiveModule() )
2294 return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2295 else if ( getApplication() )
2296 return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2298 if ( getActiveModule() )
2299 return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2300 else if ( getApplication() )
2301 return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2303 if ( getActiveModule() )
2304 return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2305 else if ( getApplication() )
2306 return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2308 if ( getActiveModule() )
2309 return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2310 else if ( getApplication() )
2311 return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2313 if ( getActiveModule() )
2314 return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2315 else if ( getApplication() )
2316 return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2324 QString mySubMenuName;
2331 class TCreateMenuEvent: public SALOME_Event
2334 typedef int TResult;
2336 const CrMenu& myCrMenu;
2337 TCreateMenuEvent( const CrMenu& crMenu )
2338 : myResult( -1 ), myCrMenu( crMenu ) {}
2339 virtual void Execute()
2341 myResult = myCrMenu.execute();
2346 \brief Create main menu.
2347 \param subMenu menu name
2348 \param menu parent menu ID
2349 \param id required menu ID
2350 \param group menu group ID
2351 \param idx required index in the menu
2352 \return menu ID or -1 if menu could not be added
2354 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2356 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2360 \brief Create main menu.
2361 \param subMenu menu name
2362 \param menu parent menu name (list of menu names separated by "|")
2363 \param id required menu ID
2364 \param group menu group ID
2365 \param idx required index in the menu
2366 \return menu ID or -1 if menu could not be added
2368 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2370 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2374 \brief Insert action to the main menu.
2376 \param menu parent menu ID
2377 \param group menu group ID
2378 \param idx required index in the menu
2379 \return action ID or -1 if action could not be added
2381 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2383 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2387 \brief Insert action to the main menu.
2389 \param menu parent menu name (list of menu names separated by "|")
2390 \param group menu group ID
2391 \param idx required index in the menu
2392 \return action ID or -1 if action could not be added
2394 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2396 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2400 \brief Insert action to the main menu.
2402 \param menu parent menu ID
2403 \param group menu group ID
2404 \param idx required index in the menu
2405 \return action ID or -1 if action could not be added
2407 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2409 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2413 \brief Insert action to the main menu.
2415 \param menu parent menu name (list of menu names separated by "|")
2416 \param group menu group ID
2417 \param idx required index in the menu
2418 \return action ID or -1 if action could not be added
2420 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2422 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2426 \fn QAction* SalomePyQt::createSeparator();
2427 \brief Create separator action which can be used in the menu or toolbar.
2428 \return new separator action
2431 class TCreateSepEvent: public SALOME_Event
2434 typedef QAction* TResult;
2438 virtual void Execute()
2440 LightApp_Module* module = getActiveModule();
2442 myResult = (QAction*)module->separator();
2445 QAction* SalomePyQt::createSeparator()
2447 return ProcessEvent( new TCreateSepEvent() );
2451 \fn QAction* SalomePyQt::createAction( const int id,
2452 const QString& menuText,
2453 const QString& tipText,
2454 const QString& statusText,
2455 const QString& icon,
2457 const bool toggle );
2458 \brief Create an action which can be then used in the menu or toolbar.
2459 \param id the unique id action to be registered to
2460 \param menuText action text which should appear in menu
2461 \param tipText text which should appear in the tooltip
2462 \param statusText text which should appear in the status bar when action is activated
2463 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2464 \param key the key accelrator for the action
2465 \param toggle if \c true the action is checkable
2468 class TCreateActionEvent: public SALOME_Event
2471 typedef QAction* TResult;
2476 QString myStatusText;
2480 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2481 const QString& statusText, const QString& icon, const int key, const bool toggle )
2482 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2483 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2484 virtual void Execute()
2486 LightApp_Module* module = getActiveModule();
2488 QIcon icon = loadIconInternal( module->name(), myIcon );
2489 myResult = (QAction*)module->action( myId );
2491 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2492 myResult->setToolTip( myTipText );
2493 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2494 myResult->setText( myMenuText );
2495 if ( myResult->icon().isNull() && !icon.isNull() )
2496 myResult->setIcon( icon );
2497 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2498 myResult->setStatusTip( myStatusText );
2499 if ( myResult->shortcut().isEmpty() && myKey )
2500 myResult->setShortcut( myKey );
2501 if ( myResult->isCheckable() != myToggle )
2502 myResult->setCheckable( myToggle );
2505 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2507 // for Python module, automatically connect action to callback slot
2508 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2509 if ( helper ) helper->connectAction( myResult );
2513 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2514 const QString& tipText, const QString& statusText,
2515 const QString& icon, const int key, const bool toggle )
2517 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2521 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2522 \brief Create an action group which can be then used in the menu or toolbar
2523 \param id : the unique id action group to be registered to
2524 \param exclusive : if \c true the action group does exclusive toggling
2527 struct TCreateActionGroupEvent: public SALOME_Event
2529 typedef QtxActionGroup* TResult;
2533 TCreateActionGroupEvent( const int id, const bool exclusive )
2534 : myId( id ), myExclusive( exclusive ) {}
2535 virtual void Execute()
2537 LightApp_Module* module = getActiveModule();
2539 myResult = module->createActionGroup( myId, myExclusive );
2542 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2544 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2548 \fn QAction* SalomePyQt::action( const int id );
2549 \brief Get action by specified identifier.
2550 \return action or 0 if action is not registered
2553 class TActionEvent: public SALOME_Event
2556 typedef QAction* TResult;
2559 TActionEvent( const int id )
2560 : myResult( 0 ), myId( id ) {}
2561 virtual void Execute()
2563 LightApp_Module* module = getActiveModule();
2565 myResult = (QAction*)module->action( myId );
2568 QAction* SalomePyQt::action( const int id )
2570 return ProcessEvent( new TActionEvent( id ) );
2574 \fn int SalomePyQt::actionId( const QAction* a );
2575 \brief Get an action identifier.
2576 \return action ID or -1 if action is not registered
2579 class TActionIdEvent: public SALOME_Event
2582 typedef int TResult;
2584 const QAction* myAction;
2585 TActionIdEvent( const QAction* action )
2586 : myResult( -1 ), myAction( action ) {}
2587 virtual void Execute()
2589 LightApp_Module* module = getActiveModule();
2591 myResult = module->actionId( myAction );
2594 int SalomePyQt::actionId( const QAction* a )
2596 return ProcessEvent( new TActionIdEvent( a ) );
2600 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2601 \brief Add global (not module-related) preferences group.
2602 \param label global preferences group name
2603 \return preferences group identifier
2606 class TAddGlobalPrefEvent: public SALOME_Event
2609 typedef int TResult;
2612 TAddGlobalPrefEvent( const QString& label )
2613 : myResult( -1 ), myLabel( label ) {}
2614 virtual void Execute()
2616 LightApp_Module* module = getActiveModule();
2618 LightApp_Preferences* pref = module->getApp()->preferences();
2620 myResult = pref->addPreference( myLabel, -1 );
2624 int SalomePyQt::addGlobalPreference( const QString& label )
2626 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2630 \fn int SalomePyQt::addPreference( const QString& label );
2631 \brief Add module-related preferences group.
2632 \param label preferences group name
2633 \return preferences group identifier
2636 class TAddPrefEvent: public SALOME_Event
2639 typedef int TResult;
2642 TAddPrefEvent( const QString& label )
2643 : myResult( -1 ), myLabel( label ) {}
2644 virtual void Execute()
2646 LightApp_Module* module = getActiveModule();
2648 LightApp_Preferences* pref = module->getApp()->preferences();
2650 int cId = pref->addPreference( module->moduleName(), -1 );
2652 myResult = pref->addPreference( myLabel, cId );
2657 int SalomePyQt::addPreference( const QString& label )
2659 return ProcessEvent( new TAddPrefEvent( label ) );
2663 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2664 const QString& section, const QString& param );
2665 \brief Add module-related preferences.
2666 \param label preferences group name
2667 \param pId parent preferences group id
2668 \param type preferences type
2669 \param section resources file section name
2670 \param param resources file setting name
2671 \return preferences identifier
2674 class TAddPrefParamEvent: public SALOME_Event
2677 typedef int TResult;
2684 TAddPrefParamEvent( const QString& label,
2685 const int pId, const int type,
2686 const QString& section,
2687 const QString& param )
2689 myLabel( label ), myPId( pId ), myType( type ),
2690 mySection( section ), myParam ( param ) {}
2691 virtual void Execute()
2693 LightApp_Module* module = getActiveModule();
2695 LightApp_Preferences* pref = module->getApp()->preferences();
2697 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2701 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2702 const QString& section, const QString& param )
2704 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2708 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2709 \brief Get the preferences property.
2710 \param id preferences identifier
2711 \param prop preferences property name
2712 \return preferences property value or null QVariant if property is not set
2715 class TPrefPropEvent: public SALOME_Event
2718 typedef QVariant TResult;
2722 TPrefPropEvent( const int id, const QString& prop )
2723 : myId( id ), myProp( prop ) {}
2724 virtual void Execute()
2726 LightApp_Module* module = getActiveModule();
2728 LightApp_Preferences* pref = module->getApp()->preferences();
2730 myResult = pref->itemProperty( myProp, myId );
2734 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2736 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2740 \brief Set the preferences property.
2741 \param id preferences identifier
2742 \param prop preferences property name
2743 \param var preferences property value
2745 void SalomePyQt::setPreferenceProperty( const int id,
2746 const QString& prop,
2747 const QVariant& var )
2749 class TEvent: public SALOME_Event
2755 TEvent( const int id, const QString& prop, const QVariant& var )
2756 : myId( id ), myProp( prop ), myVar( var ) {}
2757 virtual void Execute()
2759 LightApp_Module* module = getActiveModule();
2761 LightApp_Preferences* pref = module->getApp()->preferences();
2763 pref->setItemProperty( myProp, myVar, myId );
2767 ProcessVoidEvent( new TEvent( id, prop, var ) );
2771 \brief Set specific widget as a custom preferences item.
2772 \param id preferences identifier
2773 \param prop preferences property name
2774 \param widget custom widget
2776 void SalomePyQt::setPreferencePropertyWg( const int id,
2777 const QString& prop,
2778 UserDefinedContent* widget )
2780 class TEvent: public SALOME_Event
2784 UserDefinedContent* myWidget;
2786 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2787 : myId( id ), myProp( prop ), myWidget( widget ) {}
2788 virtual void Execute()
2790 LightApp_Module* module = getActiveModule();
2792 LightApp_Preferences* pref = module->getApp()->preferences();
2794 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2799 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2803 \brief Add the property value to the list of values.
2805 This method allows creating properties which are QList<QVariant>
2806 - there is no way to pass such values directly to QVariant parameter with PyQt.
2808 \param id preferences identifier
2809 \param prop preferences property name
2810 \param idx preferences property index
2811 \param var preferences property value for the index \a idx
2813 void SalomePyQt::addPreferenceProperty( const int id,
2814 const QString& prop,
2816 const QVariant& var )
2818 class TEvent: public SALOME_Event
2825 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2826 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2827 virtual void Execute()
2829 LightApp_Module* module = getActiveModule();
2831 LightApp_Preferences* pref = module->getApp()->preferences();
2833 QVariant var = pref->itemProperty( myProp, myId );
2834 if ( var.isValid() ) {
2835 if ( var.type() == QVariant::StringList ) {
2836 QStringList sl = var.toStringList();
2837 if ( myIdx >= 0 && myIdx < sl.count() )
2838 sl[myIdx] = myVar.toString();
2840 sl.append( myVar.toString() );
2841 pref->setItemProperty( myProp, sl, myId );
2843 else if ( var.type() == QVariant::List ) {
2844 QList<QVariant> vl = var.toList();
2845 if ( myIdx >= 0 && myIdx < vl.count() )
2849 pref->setItemProperty( myProp, vl, myId );
2855 pref->setItemProperty( myProp, vl, myId );
2861 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2865 \brief Put the message to the Log messages output window
2866 \param msg message text (it can be of simple rich text format)
2867 \param addSeparator boolean flag which specifies if it is necessary
2868 to separate the message with predefined separator
2870 void SalomePyQt::message( const QString& msg, bool addSeparator )
2872 class TEvent: public SALOME_Event
2877 TEvent( const QString& msg, bool addSeparator )
2878 : myMsg( msg ), myAddSep( addSeparator ) {}
2879 virtual void Execute()
2881 if ( LightApp_Application* anApp = getApplication() ) {
2882 LogWindow* lw = anApp->logWindow();
2884 lw->putMessage( myMsg, myAddSep );
2888 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2892 \brief Remove all the messages from the Log messages output window.
2894 void SalomePyQt::clearMessages()
2896 class TEvent: public SALOME_Event
2900 virtual void Execute()
2902 if ( LightApp_Application* anApp = getApplication() ) {
2903 LogWindow* lw = anApp->logWindow();
2909 ProcessVoidEvent( new TEvent() );
2913 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2914 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2915 to the image file in the specified format.
2917 For the current moment JPEG, PNG and BMP images formats are supported.
2918 The image format is defined automatically by the file name extension.
2919 By default, BMP format is used.
2921 \param filename image file name
2922 \return operation status (\c true on success)
2925 class TDumpViewEvent: public SALOME_Event
2928 typedef bool TResult;
2932 TDumpViewEvent( const QString& filename, const int id )
2933 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2934 virtual void Execute()
2936 SUIT_ViewWindow* wnd = 0;
2938 if ( LightApp_Application* anApp = getApplication() ) {
2939 SUIT_ViewManager* vm = anApp->activeViewManager();
2941 wnd = vm->getActiveView();
2943 myWndId = wnd->getId();
2946 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2949 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2950 #ifndef DISABLE_PLOT2DVIEWER
2951 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2953 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2954 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2955 qApp->processEvents();
2956 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2957 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2961 #endif // DISABLE_PLOT2DVIEWER
2962 QImage im = wnd->dumpView();
2963 if ( !im.isNull() && !myFileName.isEmpty() ) {
2964 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2965 if ( fmt == "JPG" ) fmt = "JPEG";
2966 myResult = im.save( myFileName, fmt.toLatin1() );
2971 bool SalomePyQt::dumpView( const QString& filename, const int id )
2973 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2977 \fn QList<int> SalomePyQt::getViews();
2978 \brief Get list of integer identifiers of all the currently opened views
2979 \return list of integer identifiers of all the currently opened views
2982 class TGetViews: public SALOME_Event
2985 typedef QList<int> TResult;
2988 virtual void Execute()
2991 LightApp_Application* app = getApplication();
2993 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2995 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2996 SUIT_ViewWindow* wnd;
2997 foreach ( wnd, wndlist )
2998 myResult.append( wnd->getId() );
3003 QList<int> SalomePyQt::getViews()
3005 return ProcessEvent( new TGetViews() );
3009 \fn int SalomePyQt::getActiveView();
3010 \brief Get integer identifier of the currently active view
3011 \return integer identifier of the currently active view
3014 class TGetActiveView: public SALOME_Event
3017 typedef int TResult;
3021 virtual void Execute()
3023 LightApp_Application* app = getApplication();
3025 SUIT_ViewManager* viewMgr = app->activeViewManager();
3027 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3029 myResult = wnd->getId();
3034 int SalomePyQt::getActiveView()
3036 return ProcessEvent( new TGetActiveView() );
3040 \fn QString SalomePyQt::getViewType( const int id );
3041 \brief Get type of the specified view, e.g. "OCCViewer"
3042 \param id window identifier
3046 class TGetViewType: public SALOME_Event
3049 typedef QString TResult;
3052 TGetViewType( const int id )
3054 virtual void Execute()
3056 SUIT_ViewWindow* wnd = getWnd( myWndId );
3058 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3060 myResult = viewMgr->getType();
3064 QString SalomePyQt::getViewType( const int id )
3066 return ProcessEvent( new TGetViewType( id ) );
3070 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3071 \brief Change view caption
3072 \param id window identifier
3073 \param title new window title
3074 \return \c true if operation is completed successfully and \c false otherwise
3077 class TSetViewTitle: public SALOME_Event
3080 typedef bool TResult;
3084 TSetViewTitle( const int id, const QString& title )
3085 : myResult( false ),
3088 virtual void Execute()
3090 SUIT_ViewWindow* wnd = getWnd( myWndId );
3092 wnd->setWindowTitle( myTitle );
3097 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3099 return ProcessEvent( new TSetViewTitle( id, title ) );
3103 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3104 \brief Set view size
3105 \param w window width
3106 \param h window height
3107 \param id window identifier
3108 \return \c true if operation is completed successfully and \c false otherwise
3111 class TSetViewSize: public SALOME_Event
3114 typedef bool TResult;
3119 TSetViewSize( const int w, const int h, const int id )
3120 : myResult( false ),
3124 virtual void Execute()
3126 SUIT_ViewWindow* wnd = 0;
3128 if ( LightApp_Application* anApp = getApplication() ) {
3129 SUIT_ViewManager* vm = anApp->activeViewManager();
3131 wnd = vm->getActiveView();
3135 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3138 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3140 QString type = viewMgr->getType();
3141 if ( type == "OCCViewer") {
3142 #ifndef DISABLE_OCCVIEWER
3143 // specific processing for OCC viewer:
3144 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3145 // - if there is only one sub-view active; it will be resized;
3146 // - if there are several sub-views, each of them will be resized.
3147 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3148 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3149 if ( occView && occView->getView( i ) ) {
3150 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3154 #endif // DISABLE_OCCVIEWER
3156 else if ( type == "ParaView") {
3157 #ifndef DISABLE_PVVIEWER
3158 // specific processing for ParaView viewer:
3159 // hierarchy of ParaView viewer is much complex than for usual view;
3160 // we look for sub-widget named "Viewport"
3161 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3162 if ( !lst.isEmpty() ) {
3163 lst[0]->resize( myWndWidth, myWndHeight );
3166 #endif // DISABLE_PVVIEWER
3169 if ( wnd->centralWidget() ) {
3170 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3178 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3180 return ProcessEvent( new TSetViewSize( w, h, id ) );
3184 \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3185 \brief Set view rotation point
3186 \param x coordinate X view rotation point
3187 \param y coordinate Y view rotation point
3188 \param z coordinate Z view rotation point
3189 \param id window identifier
3190 \return \c true if operation is completed successfully and \c false otherwise
3193 class TSetViewRotationPoint: public SALOME_Event
3196 typedef bool TResult;
3202 TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3203 : myResult( false ),
3208 virtual void Execute()
3210 SUIT_ViewWindow* wnd = 0;
3212 if ( LightApp_Application* anApp = getApplication() ) {
3213 SUIT_ViewManager* vm = anApp->activeViewManager();
3215 wnd = vm->getActiveView();
3219 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3222 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3224 QString type = viewMgr->getType();
3225 if ( type == "OCCViewer") {
3226 #ifndef DISABLE_OCCVIEWER
3227 // specific processing for OCC viewer:
3228 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3229 // - if there is only one sub-view active; its rotation point will be changed;
3230 // - if there are several sub-views, rotaion points of each of them will be changed.
3231 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3233 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3234 if ( occView && occView->getView( i ) ) {
3235 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3240 #endif // DISABLE_OCCVIEWER
3242 else if ( type == "VTKViewer") {
3243 #ifndef DISABLE_VTKVIEWER
3244 SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3247 double aCenter[3] = { myX, myY, myZ };
3248 vtkView->activateSetRotationSelected( (void*)aCenter );
3251 #endif // DISABLE_VTKVIEWER
3257 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3259 return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3263 \fn QString SalomePyQt::getViewTitle( const int id );
3264 \brief Get view caption
3265 \param id window identifier
3266 \return view caption
3269 class TGetViewTitle: public SALOME_Event
3272 typedef QString TResult;
3275 TGetViewTitle( const int id )
3277 virtual void Execute()
3279 SUIT_ViewWindow* wnd = getWnd( myWndId );
3281 myResult = wnd->windowTitle();
3284 QString SalomePyQt::getViewTitle( const int id )
3286 return ProcessEvent( new TGetViewTitle( id ) );
3290 \fn QList<int> SalomePyQt::findViews( const QString& type );
3291 \brief Get list of integer identifiers of all the
3292 currently opened views of the specified type
3293 \param type viewer type
3294 \return list of integer identifiers
3297 class TFindViews: public SALOME_Event
3300 typedef QList<int> TResult;
3303 TFindViews( const QString& type )
3305 virtual void Execute()
3308 LightApp_Application* app = getApplication();
3310 ViewManagerList vmList;
3311 app->viewManagers( myType, vmList );
3312 SUIT_ViewManager* viewMgr;
3313 foreach ( viewMgr, vmList ) {
3314 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3315 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3316 SUIT_ViewWindow* wnd = vec[ i ];
3319 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3320 myResult.append( wnd->getId() );
3327 QList<int> SalomePyQt::findViews( const QString& type )
3329 return ProcessEvent( new TFindViews( type ) );
3333 \fn bool SalomePyQt::activateView( const int id );
3334 \brief Activate view
3335 \param id window identifier
3336 \return \c true if operation is completed successfully and \c false otherwise
3339 class TActivateView: public SALOME_Event
3342 typedef bool TResult;
3345 TActivateView( const int id )
3346 : myResult( false ),
3348 virtual void Execute()
3350 SUIT_ViewWindow* wnd = getWnd( myWndId );
3351 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3358 bool SalomePyQt::activateView( const int id )
3360 return ProcessEvent( new TActivateView( id ) );
3364 \fn bool SalomePyQt::activateManagerAndView( const int id );
3365 \brief Activate view manager and view: useful for a view embedded in a module main Window
3366 \param id window identifier
3367 \return \c true if operation is completed successfully and \c false otherwise
3370 class TActivateViewManagerAndView: public SALOME_Event
3373 typedef bool TResult;
3376 TActivateViewManagerAndView( const int id )
3377 : myResult( false ),
3379 virtual void Execute()
3381 SUIT_ViewWindow* wnd = getWnd( myWndId );
3382 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3385 LightApp_Application* app = getApplication();
3386 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3392 bool SalomePyQt::activateViewManagerAndView( const int id )
3394 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3401 class TGetViewWidget: public SALOME_Event
3404 typedef QWidget* TResult;
3407 TGetViewWidget( const int id )
3410 virtual void Execute()
3412 SUIT_ViewWindow* wnd = getWnd( myWndId );
3414 myResult = (QWidget*)wnd;
3418 QWidget* SalomePyQt::getViewWidget( const int id)
3420 return ProcessEvent( new TGetViewWidget( id ) );
3425 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3426 \brief Create new view and activate it
3427 \param type viewer type
3431 \return integer identifier of created view (or -1 if view could not be created)
3434 class TCreateView: public SALOME_Event
3437 typedef int TResult;
3444 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3450 myDetached(detached) {}
3451 virtual void Execute()
3453 LightApp_Application* app = getApplication();
3455 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3457 QWidget* wnd = viewMgr->getActiveView();
3458 myResult = viewMgr->getActiveView()->getId();
3461 wnd->setVisible(false);
3462 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3466 if (myWidth > 0 && myHeight > 0) {
3467 #ifndef DISABLE_PLOT2DVIEWER
3468 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3469 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3470 #endif // DISABLE_PLOT2DVIEWER
3471 wnd->setGeometry( 0, 0, myWidth, myHeight );
3478 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3480 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3481 QCoreApplication::processEvents();
3486 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3487 \brief Create new view with custom widget embedded and activate it
3488 \param type viewer type
3489 \param w custom widget
3490 \return integer identifier of created view (or -1 if view could not be created)
3493 class TCreateViewWg: public SALOME_Event
3496 typedef int TResult;
3500 TCreateViewWg( const QString& theType, QWidget* w )
3504 virtual void Execute()
3506 LightApp_Application* app = getApplication();
3508 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3510 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3512 myResult = wnd->getId();
3517 int SalomePyQt::createView( const QString& type, QWidget* w )
3519 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3520 QCoreApplication::processEvents();
3525 \fn bool SalomePyQt::closeView( const int id );
3527 \param id window identifier
3528 \return \c true if operation is completed successfully and \c false otherwise
3531 class TCloseView: public SALOME_Event
3534 typedef bool TResult;
3537 TCloseView( const int id )
3538 : myResult( false ),
3540 virtual void Execute()
3542 SUIT_ViewWindow* wnd = getWnd( myWndId );
3544 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3552 bool SalomePyQt::closeView( const int id )
3554 return ProcessEvent( new TCloseView( id ) );
3558 \fn int SalomePyQt::cloneView( const int id );
3559 \brief Clone view (if this operation is supported for specified view type)
3560 \param id window identifier
3561 \return integer identifier of the cloned view or -1 or operation could not be performed
3564 class TCloneView: public SALOME_Event
3567 typedef int TResult;
3570 TCloneView( const int id )
3573 virtual void Execute()
3575 SUIT_ViewWindow* wnd = getWnd( myWndId );
3577 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3579 #ifndef DISABLE_OCCVIEWER
3580 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3581 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3582 occView->onCloneView();
3583 wnd = viewMgr->getActiveView();
3585 myResult = wnd->getId();
3587 #endif // DISABLE_OCCVIEWER
3588 #ifndef DISABLE_PLOT2DVIEWER
3589 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3590 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3591 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3592 if ( viewMgr2d && srcWnd2d ) {
3593 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3594 myResult = resWnd->getId();
3597 #endif // DISABLE_OCCVIEWER
3602 int SalomePyQt::cloneView( const int id )
3604 return ProcessEvent( new TCloneView( id ) );
3608 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3609 \brief Set view visibility.
3610 \param id window identifier
3611 \param visible new visiblity
3614 void SalomePyQt::setViewVisible( const int id, const bool visible )
3616 class TEvent: public SALOME_Event
3621 TEvent( const int id, const bool visible )
3622 : myWndId( id ), myVisible( visible ) {}
3623 virtual void Execute()
3625 SUIT_ViewWindow* wnd = getWnd( myWndId );
3626 if ( wnd ) wnd->setVisible( myVisible );
3629 ProcessVoidEvent( new TEvent( id, visible ) );
3633 \fn bool SalomePyQt::isViewVisible( const int id );
3634 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3635 \param id window identifier
3636 \return \c true if view is visible and \c false otherwise
3639 class TIsViewVisible: public SALOME_Event
3642 typedef bool TResult;
3645 TIsViewVisible( const int id )
3646 : myResult( false ),
3648 virtual void Execute()
3650 SUIT_ViewWindow* wnd = getWnd( myWndId );
3653 QWidget* p = wnd->parentWidget();
3654 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3658 bool SalomePyQt::isViewVisible( const int id )
3660 return ProcessEvent( new TIsViewVisible( id ) );
3664 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3665 \brief Set / clear view's "closable" option. By default any view is closable
3666 (i.e. can be closed by the user).
3667 \param id window identifier
3668 \param on new "closable" option's value
3671 void SalomePyQt::setViewClosable( const int id, const bool on )
3673 class TEvent: public SALOME_Event
3678 TEvent( const int id, const bool on )
3679 : myWndId( id ), myOn( on ) {}
3680 virtual void Execute()
3682 SUIT_ViewWindow* wnd = getWnd( myWndId );
3683 if ( wnd ) wnd->setClosable( myOn );
3686 ProcessVoidEvent( new TEvent( id, on ) );
3690 \fn bool SalomePyQt::isViewClosable( const int id );
3691 \brief Check whether view is closable (i.e. can be closed by the user)
3692 \param id window identifier
3693 \return \c true if view is closable or \c false otherwise
3696 class TIsViewClosable: public SALOME_Event
3699 typedef bool TResult;
3702 TIsViewClosable( const int id )
3705 virtual void Execute()
3707 SUIT_ViewWindow* wnd = getWnd( myWndId );
3709 myResult = wnd->closable();
3713 bool SalomePyQt::isViewClosable( const int id )
3715 return ProcessEvent( new TIsViewClosable( id ) );
3719 \fn bool SalomePyQt::groupAllViews();
3720 \brief Group all views to the single tab area
3721 \return \c true if operation is completed successfully and \c false otherwise
3724 class TGroupAllViews: public SALOME_Event
3727 typedef bool TResult;
3730 : myResult( false ) {}
3731 virtual void Execute()
3733 LightApp_Application* app = getApplication();
3735 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3737 QtxWorkstack* wStack = tabDesk->workstack();
3746 bool SalomePyQt::groupAllViews()
3748 return ProcessEvent( new TGroupAllViews() );
3752 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3753 \brief Split tab area to which view with identifier belongs to
3754 \param id window identifier
3755 \param ori orientation of split operation
3756 \param action action to be performed
3757 \return \c true if operation is completed successfully \c false otherwise
3760 class TSplitView: public SALOME_Event
3763 typedef bool TResult;
3768 TSplitView( const int id,
3769 const Orientation ori,
3770 const Action action )
3771 : myResult( false ),
3774 myAction( action ) {}
3775 virtual void Execute()
3777 SUIT_ViewWindow* wnd = getWnd( myWndId );
3780 // wnd->setFocus(); ???
3783 if ( getApplication() ) {
3784 STD_TabDesktop* desk =
3785 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3787 QtxWorkstack* wStack = desk->workstack();
3789 Qt::Orientation qtOri =
3790 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3792 QtxWorkstack::SplitType sType;
3793 if ( myAction == MoveWidget )
3794 sType = QtxWorkstack::SplitMove;
3795 else if ( myAction == LeaveWidget )
3796 sType = QtxWorkstack::SplitStay;
3798 sType = QtxWorkstack::SplitAt;
3800 wStack->Split( wnd, qtOri, sType );
3808 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3810 return ProcessEvent( new TSplitView( id, ori, action ) );
3814 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3815 \brief Move view with the first identifier to the same area which
3816 another view with the second identifier belongs to
3817 \param id source window identifier
3818 \param id_to destination window identifier
3819 param before specifies whether the first viewt has to be moved before or after
3821 \return \c true if operation is completed successfully and \c false otherwise
3824 class TMoveView: public SALOME_Event
3827 typedef bool TResult;
3832 TMoveView( const int id, const int id_to, const bool before )
3833 : myResult( false ),
3836 myIsBefore( before ) {}
3837 virtual void Execute()
3839 SUIT_ViewWindow* wnd = getWnd( myWndId );
3840 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3841 if ( wnd && wnd_to ) {
3842 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3843 getApplication()->desktop() )->workstack();
3845 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3849 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3851 return ProcessEvent( new TMoveView( id, id_to, before ) );
3855 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3856 \brief Get list of views identifiers that belongs to the same area as
3857 specified view (excluding it)
3858 \param id window identifier
3859 \return list of views identifiers
3862 class TNeighbourViews: public SALOME_Event
3865 typedef QList<int> TResult;
3868 TNeighbourViews( const int id )
3870 virtual void Execute()
3873 SUIT_ViewWindow* wnd = getWnd( myWndId );
3875 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3876 getApplication()->desktop() )->workstack();
3878 QWidgetList wgList = wStack->windowList( wnd );
3880 foreach ( wg, wgList ) {
3881 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3882 if ( tmpWnd && tmpWnd != wnd )
3883 myResult.append( tmpWnd->getId() );
3889 QList<int> SalomePyQt::neighbourViews( const int id )
3891 return ProcessEvent( new TNeighbourViews( id ) );
3896 \fn void SalomePyQt::createRoot();
3897 \brief Initialize root data object.
3899 Does nothing if root is already initialized.
3902 void SalomePyQt::createRoot()
3904 class TEvent: public SALOME_Event
3908 virtual void Execute()
3910 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3912 SALOME_PYQT_DataModelLight* dm =
3913 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3918 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3922 ProcessVoidEvent( new TEvent() );
3926 \fn QString SalomePyQt::createObject( const QString& parent );
3927 \brief Create empty data object
3928 \param parent entry of parent data object
3929 \return entry of created data object
3932 class TCreateEmptyObjectEvent: public SALOME_Event
3935 typedef QString TResult;
3938 TCreateEmptyObjectEvent( const QString& parent )
3939 : myParent( parent ) {}
3940 virtual void Execute()
3942 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3944 myResult = module->createObject( myParent );
3947 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3951 QString SalomePyQt::createObject( const QString& parent )
3953 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3957 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3958 const QString& tooltip,const QString& parent );
3959 \brief Create new data object with specified name, icon and tooltip
3960 \param name data object name
3961 \param icon data object icon
3962 \param toolTip data object tooltip
3963 \param parent entry of parent data object
3964 \return entry of created data object
3967 class TCreateObjectEvent: public SALOME_Event
3970 typedef QString TResult;
3976 TCreateObjectEvent( const QString& name,
3977 const QString& icon,
3978 const QString& tooltip,
3979 const QString& parent )
3982 myToolTip( tooltip ),
3983 myParent( parent ) {}
3984 virtual void Execute()
3986 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3988 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3991 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3995 QString SalomePyQt::createObject( const QString& name,
3996 const QString& icon,
3997 const QString& toolTip,
3998 const QString& parent )
4000 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
4005 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
4006 \brief Set data object name
4007 \param entry data object entry
4008 \param name data object name
4010 class TSetNameEvent: public SALOME_Event
4015 TSetNameEvent( const QString& entry,
4016 const QString& name )
4019 virtual void Execute()
4021 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4023 module->setName( myEntry, myName );
4026 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
4030 void SalomePyQt::setName( const QString& entry, const QString& name )
4032 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
4036 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
4037 \brief Set data object icon
4038 \param entry data object entry
4039 \param icon data object icon file name (icon is loaded from module resources)
4042 class TSetIconEvent: public SALOME_Event
4047 TSetIconEvent( const QString& entry,
4048 const QString& icon )
4051 virtual void Execute()
4053 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4055 module->setIcon( myEntry, myIcon );
4058 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4063 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4065 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4069 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4070 \brief Set data object tooltip
4071 \param entry data object entry
4072 \param toolTip data object tooltip
4075 class TSetToolTipEvent: public SALOME_Event
4080 TSetToolTipEvent( const QString& entry,
4081 const QString& toolTip )
4083 myToolTip( toolTip ) {}
4084 virtual void Execute()
4086 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4088 module->setToolTip( myEntry, myToolTip );
4091 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4095 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4097 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4101 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4102 \brief Set reference to another data object
4103 \param entry data object entry
4104 \param refEntry referenced data object entry
4107 class TSetRefEvent: public SALOME_Event
4112 TSetRefEvent( const QString& entry,
4113 const QString& refEntry )
4115 myRefEntry( refEntry ) {}
4116 virtual void Execute()
4118 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4120 module->setReference( myEntry, myRefEntry );
4123 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4127 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4129 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4133 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4134 \brief Set data object color
4135 \param entry data object entry
4136 \param color data object color
4139 class TSetColorEvent: public SALOME_Event
4144 TSetColorEvent( const QString& entry,
4145 const QColor& color )
4148 virtual void Execute()
4150 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4152 module->setColor( myEntry, myColor );
4155 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4159 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4161 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4165 \fn QString SalomePyQt::getName( const QString& entry );
4166 \brief Get data object name
4167 \param entry data object entry
4168 \return data object name
4171 class TGetNameEvent: public SALOME_Event
4174 typedef QString TResult;
4177 TGetNameEvent( const QString& entry )
4178 : myEntry( entry ) {}
4179 virtual void Execute()
4181 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4183 myResult = module->getName( myEntry );
4186 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4190 QString SalomePyQt::getName( const QString& entry )
4192 return ProcessEvent( new TGetNameEvent( entry ) );
4196 \fn QString SalomePyQt::getToolTip( const QString& entry );
4197 \brief Get data object tooltip
4198 \param entry data object entry
4199 \return data object tooltip
4202 class TGetToolTipEvent: public SALOME_Event
4205 typedef QString TResult;
4208 TGetToolTipEvent( const QString& entry )
4209 : myEntry( entry ) {}
4210 virtual void Execute()
4212 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4214 myResult = module->getToolTip( myEntry );
4217 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4221 QString SalomePyQt::getToolTip( const QString& entry )
4223 return ProcessEvent( new TGetToolTipEvent( entry ) );
4227 \fn QString SalomePyQt::getReference( const QString& entry );
4228 \brief Get entry of the referenced object (if there's any)
4229 \param entry data object entry
4230 \return referenced data object entry
4233 class TGetRefEvent: public SALOME_Event
4236 typedef QString TResult;
4239 TGetRefEvent( const QString& entry )
4240 : myEntry( entry ) {}
4241 virtual void Execute()
4243 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4245 myResult = module->getReference( myEntry );
4248 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4252 QString SalomePyQt::getReference( const QString& entry )
4254 return ProcessEvent( new TGetRefEvent( entry ) );
4258 \fn QColor SalomePyQt::getColor( const QString& entry );
4259 \brief Get data object color
4260 \param entry data object entry
4261 \return data object color
4264 class TGetColorEvent: public SALOME_Event
4267 typedef QColor TResult;
4270 TGetColorEvent( const QString& entry )
4271 : myEntry( entry ) {}
4272 virtual void Execute()
4274 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4276 myResult = module->getColor( myEntry );
4279 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4283 QColor SalomePyQt::getColor( const QString& entry )
4285 return ProcessEvent( new TGetColorEvent( entry ) );
4289 \fn void SalomePyQt::removeChildren( const QString& entry );
4290 \brief Remove all child data objects from specified data object
4291 \param entry data object entry
4294 class TRemoveChildEvent: public SALOME_Event
4298 TRemoveChildEvent( const QString& entry )
4299 : myEntry( entry ) {}
4300 virtual void Execute()
4302 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4304 module->removeChildren( myEntry );
4307 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4311 void SalomePyQt::removeChildren( const QString& entry )
4313 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4315 void SalomePyQt::removeChild( const QString& entry )
4317 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4318 removeChildren( entry );
4322 \fn void SalomePyQt::removeObject( const QString& entry );
4323 \brief Remove object by entry
4324 \param entry data object entry
4327 class TRemoveObjectEvent: public SALOME_Event
4332 TRemoveObjectEvent( const QString& entry )
4333 : myEntry( entry ) {}
4334 virtual void Execute()
4336 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4338 module->removeObject( myEntry );
4341 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4345 void SalomePyQt::removeObject( const QString& entry )
4347 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4351 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4352 \brief Get entries of all child data objects of specified data object
4353 \param entry data object entry
4354 \param recursive \c true for recursive processing
4357 class TGetChildrenEvent: public SALOME_Event
4360 typedef QStringList TResult;
4364 TGetChildrenEvent( const QString& entry, const bool recursive )
4366 myRecursive( recursive ) {}
4367 virtual void Execute()
4369 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4371 myResult = module->getChildren( myEntry, myRecursive );
4374 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4378 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4380 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4383 #ifndef DISABLE_PLOT2DVIEWER
4384 // Next set of methods relates to the Plot2d viewer functionality
4387 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4388 \brief Display theCurve in view
4389 \param id window identifier
4390 \param theCurve curve to display
4393 class TDisplayCurve: public SALOME_Event
4397 Plot2d_Curve* myCurve;
4398 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4399 virtual void Execute() {
4400 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4402 wnd->getViewFrame()->displayCurve( myCurve );
4405 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4407 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4411 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4412 \brief Erase theCurve in view
4413 \param id window identifier
4414 \param theCurve curve to erase
4417 class TEraseCurve: public SALOME_Event
4421 Plot2d_Curve* myCurve;
4422 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4423 virtual void Execute() {
4424 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4425 wnd->getViewFrame()->eraseCurve( myCurve );
4428 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4430 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4434 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4435 \brief Delete theCurve from all views
4436 \param theCurve curve to delete
4439 class TDeleteCurve: public SALOME_Event
4442 Plot2d_Curve* myCurve;
4443 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4444 virtual void Execute() {
4445 LightApp_Application* app = getApplication();
4447 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4449 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4450 SUIT_ViewWindow* wnd;
4451 foreach ( wnd, wndlist ) {
4452 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4454 aP2d->getViewFrame()->eraseObject( myCurve );
4460 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4462 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4466 \brief updateCurves (repaint) curves in view window.
4468 void SalomePyQt::updateCurves( const int id )
4470 class TEvent: public SALOME_Event
4474 TEvent( const int id ) : myWndId( id ) {}
4475 virtual void Execute()
4477 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4479 wnd->getViewFrame()->DisplayAll();
4482 ProcessVoidEvent( new TEvent( id ) );
4486 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4487 \brief Get title of corresponding type
4488 \param id window identifier
4489 \param type is type of title
4490 \return title of corresponding type
4493 class TGetPlot2dTitle: public SALOME_Event
4496 typedef QString TResult;
4500 TGetPlot2dTitle(const int id, ObjectType type) :
4503 virtual void Execute() {
4504 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4506 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4509 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4511 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4516 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4517 \brief Set title of corresponding type
4518 \param id window identifier
4520 \param type is type of title
4524 class TSetPlot2dTitle: public SALOME_Event
4528 Plot2d_Curve* myCurve;
4532 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4537 virtual void Execute() {
4538 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4539 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4542 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4544 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4548 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4549 \brief Get list of Plot2d view ranges
4550 \param id window identifier
4551 \return list of view ranges (XMin, XMax, YMin, YMax)
4554 class TFitRangeByCurves: public SALOME_Event
4557 typedef QList<double> TResult;
4560 TFitRangeByCurves( const int id )
4562 virtual void Execute()
4565 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4567 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4568 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4569 myResult.append( XMin );
4570 myResult.append( XMax );
4571 myResult.append( YMin );
4572 myResult.append( YMax );
4576 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4578 return ProcessEvent( new TFitRangeByCurves( id ) );
4582 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4583 \brief Get list of current Plot2d view ranges
4584 \param id window identifier
4585 \return list of view ranges (XMin, XMax, YMin, YMax)
4588 class TFitRangeCurrent: public SALOME_Event
4591 typedef QList<double> TResult;
4594 TFitRangeCurrent( const int id )
4596 virtual void Execute()
4599 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4601 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4602 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4603 myResult.append( XMin );
4604 myResult.append( XMax );
4605 myResult.append( YMin );
4606 myResult.append( YMax );
4610 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4612 return ProcessEvent( new TFitRangeCurrent( id ) );
4616 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4617 \brief Set range of Plot2d view
4618 \param id window identifier
4625 class TPlot2dFitRange: public SALOME_Event
4633 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4639 virtual void Execute() {
4640 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4642 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4645 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4647 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4650 // End of methods related to the Plot2d viewer functionality
4651 #endif // DISABLE_PLOT2DVIEWER
4654 \brief Process Qt event loop
4656 void SalomePyQt::processEvents()
4658 QCoreApplication::processEvents();
4662 \brief Set visibility state for given object
4663 \param theEntry study ID of the object
4664 \param theState visibility state
4666 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4668 class TEvent: public SALOME_Event
4673 TEvent( const QString& theEntry, int theState ):
4674 myEntry( theEntry ), myState( theState ) {}
4675 virtual void Execute()
4677 LightApp_Study* aStudy = getActiveStudy();
4680 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4683 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4687 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4688 \brief Get visibility state for given object
4689 \param theEntry study ID of the object
4690 \return visibility state
4693 class TGetVisibilityStateEvent: public SALOME_Event
4696 typedef int TResult;
4699 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4700 virtual void Execute()
4702 LightApp_Study* aStudy = getActiveStudy();
4704 myResult = aStudy->visibilityState( myEntry );
4707 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4709 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4713 \brief Set position of given object in the tree
4714 \param theEntry study ID of the object
4715 \param thePos position
4717 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4719 class TEvent: public SALOME_Event
4724 TEvent( const QString& theEntry, int thePos ):
4725 myEntry( theEntry ), myPos( thePos ) {}
4726 virtual void Execute()
4728 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4730 module->setObjectPosition( myEntry, myPos );
4733 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4737 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4738 \brief Get position of given object in the tree
4739 \param theEntry study ID of the object
4743 class TGetObjectPositionEvent: public SALOME_Event
4746 typedef int TResult;
4749 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4750 virtual void Execute()
4752 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4754 myResult = module->getObjectPosition( myEntry );
4757 int SalomePyQt::getObjectPosition( const QString& theEntry )
4759 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4763 \brief Start recordind a log of Python commands from embedded console
4764 \param theFileName output lof file name
4766 void SalomePyQt::startPyLog( const QString& theFileName )
4768 class TEvent: public SALOME_Event
4772 TEvent( const QString& theFileName ):
4773 myFileName( theFileName ) {}
4774 virtual void Execute()
4776 if ( getApplication() ) {
4777 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4778 if ( pyConsole ) pyConsole->startLog( myFileName );
4782 ProcessVoidEvent( new TEvent( theFileName ) );
4786 \brief Stop recordind a log of Python commands from embedded console
4788 void SalomePyQt::stopPyLog()
4790 class TEvent: public SALOME_Event
4794 virtual void Execute()
4796 if ( getApplication() ) {
4797 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4798 if ( pyConsole ) pyConsole->stopLog();
4802 ProcessVoidEvent( new TEvent() );