1 // Copyright (C) 2007-2024 CEA, EDF, 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 #ifndef DISABLE_PV3DVIEWER
57 #include "PV3DViewer_ViewManager.h"
58 #include "PV3DViewer_ViewModel.h"
59 #endif // DISABLE_PV3DVIEWER
60 #include "QtxActionMenuMgr.h"
61 #include "QtxWorkstack.h"
62 #include "QtxTreeView.h"
63 #include "QtxInfoPanel.h"
64 #include "SALOME_Event.h"
65 #include "STD_TabDesktop.h"
66 #include "SUIT_DataBrowser.h"
67 #include "SUIT_ResourceMgr.h"
68 #include "SUIT_Session.h"
69 #include "SUIT_Tools.h"
70 #include "SUIT_ViewManager.h"
71 #include "SUIT_ViewWindow.h"
72 #include "PyConsole_Console.h"
75 #include <QApplication>
76 #include <QPaintEvent>
77 #include <QCoreApplication>
78 #include <QVBoxLayout>
80 #include <utilities.h>
85 \brief Get the currently active application.
87 \return active application object or 0 if there is no any
89 LightApp_Application* getApplication()
91 if ( SUIT_Session::session() )
92 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
97 \brief Get the currently active study.
99 \return active study or 0 if there is no study opened
101 LightApp_Study* getActiveStudy()
103 if ( getApplication() )
104 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
109 \brief Get the currently active module.
111 This function returns correct result only if Python-based
112 module is currently active. Otherwize, 0 is returned.
114 LightApp_Module* getActiveModule()
116 LightApp_Module* module = 0;
117 if ( LightApp_Application* anApp = getApplication() ) {
118 module = PyModuleHelper::getInitModule();
120 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
126 \brief Get the currently active Python module's helper.
128 This function returns correct result only if Python-based
129 module is currently active. Otherwize, 0 is returned.
131 PyModuleHelper* getPythonHelper()
133 LightApp_Module* module = getActiveModule();
134 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
139 \brief Get SALOME verbose level
141 \return \c true if SALOME debug output is allowed or \c false otherwise
145 bool isVerbose = false;
146 if ( getenv( "SALOME_VERBOSE" ) ) {
147 QString envVar = getenv( "SALOME_VERBOSE" );
149 int value = envVar.toInt( &ok );
150 isVerbose = ok && value != 0;
156 \brief Get menu item title
158 \param menuId menu identifier
159 \return menu title (localized)
161 QString getMenuName( const QString& menuId )
163 QStringList contexts;
164 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
165 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
166 QString menuName = menuId;
167 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
168 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
173 \brief Load module icon
175 \param module module name
176 \param fileName path to the icon file
179 QIcon loadIconInternal( const QString& module, const QString& fileName )
183 LightApp_Application* app = getApplication();
185 if ( app && !fileName.isEmpty() ) {
186 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
187 QApplication::translate( module.toLatin1().data(),
188 fileName.toUtf8().data() ) );
189 if ( !pixmap.isNull() )
190 icon = QIcon( pixmap );
196 \brief Gets window with specified identifier
198 \param id window identifier
199 \return pointer on the window
201 SUIT_ViewWindow* getWnd( const int id )
203 SUIT_ViewWindow* resWnd = 0;
205 LightApp_Application* app = getApplication();
207 ViewManagerList vmlist = app->viewManagers();
208 foreach( SUIT_ViewManager* vm, vmlist ) {
209 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
210 foreach ( SUIT_ViewWindow* vw, vwlist ) {
211 if ( id == vw->getId() ) {
222 \brief Map of created selection objects.
225 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
228 \brief Default resource file section name.
231 const char* DEFAULT_SECTION = "SalomePyQt";
235 QWidget* myActiveWindow;
236 QWidget* myFocusedWidget;
239 myActiveWindow = QApplication::activeWindow();
240 myFocusedWidget = QApplication::focusWidget();
241 QApplication::setActiveWindow( getApplication()->desktop() );
245 if ( myActiveWindow )
246 QApplication::setActiveWindow( myActiveWindow );
247 if ( myFocusedWidget )
248 myFocusedWidget->setFocus();
254 \class SALOME_Selection
255 \brief The class represents selection which can be used in Python.
259 \brief Get the selection object for the specified application.
261 Finds or creates the selection object (one per study).
263 \param app application object
264 \return selection object or 0 if \a app is invalid
266 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
268 SALOME_Selection* sel = 0;
269 if ( app && SelMap.find( app ) != SelMap.end() )
272 sel = SelMap[ app ] = new SALOME_Selection( app );
279 \param p parent object
281 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
283 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
285 mySelMgr = app->selectionMgr();
286 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
287 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
294 SALOME_Selection::~SALOME_Selection()
296 LightApp_Application* app = 0;
297 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
298 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
299 if ( it.value() == this ) app = it.key();
301 if ( app ) SelMap.remove( app );
305 \brief Called when selection manager is destroyed (usually
306 when the study is closed).
308 void SALOME_Selection::onSelMgrDestroyed()
314 \brief Clear the selection.
316 void SALOME_Selection::Clear()
318 class TEvent: public SALOME_Event
320 LightApp_SelectionMgr* mySelMgr;
322 TEvent( LightApp_SelectionMgr* selMgr )
323 : mySelMgr( selMgr ) {}
324 virtual void Execute()
327 mySelMgr->clearSelected();
330 ProcessVoidEvent( new TEvent( mySelMgr ) );
334 \brief Clear the selection.
336 void SALOME_Selection::ClearIObjects()
342 Removes all selection filters.
344 void SALOME_Selection::ClearFilters()
346 class TEvent: public SALOME_Event
348 LightApp_SelectionMgr* mySelMgr;
350 TEvent( LightApp_SelectionMgr* selMgr )
351 : mySelMgr( selMgr ) {}
352 virtual void Execute()
355 mySelMgr->clearFilters();
358 ProcessVoidEvent( new TEvent( mySelMgr ) );
362 \class UserDefinedContent
363 \brief The class represents base class for user defined widget that
364 can be inserted to the Preferences dialog.
370 UserDefinedContent::UserDefinedContent()
376 \brief Called from Preferences dialog to store settings to the resource file.
378 void UserDefinedContent::store()
383 \brief Called from Preferences dialog to restore settings from the resource file.
385 void UserDefinedContent::retrieve()
390 \class SgPyQtUserDefinedContent
391 \brief A Wrapper for UserDefinedContent class.
394 class SgPyQtUserDefinedContent: public QtxUserDefinedContent
397 SgPyQtUserDefinedContent(UserDefinedContent*);
398 virtual ~SgPyQtUserDefinedContent();
400 void store( QtxResourceMgr*, QtxPreferenceMgr* );
401 void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
404 UserDefinedContent* myContent;
408 \brief Create custom item for Preferences dialog wrapping widget passed from Python.
411 SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
412 : QtxUserDefinedContent( 0 ), myContent( content )
414 QVBoxLayout* l = new QVBoxLayout( this );
415 l->setContentsMargins( 0, 0, 0, 0 );
416 l->addWidget( myContent );
423 SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
428 \brief Called from Preferences dialog to store settings to the resource file.
431 void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
437 \brief Called from Preferences dialog to restore settings from the resource file.
440 void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
442 myContent->retrieve();
447 \brief The class provides utility functions which can be used in the Python
448 to operate with the SALOME GUI.
450 All the functionality of this class is implemented as static methods, so they
451 can be called with the class name prefixed or via creation of the class instance.
452 For example, next both ways of SalomePyQt class usage are legal:
454 from SalomePyQt import *
456 # using SalomePyQt class instance
457 desktop = sg.getDesktop()
458 # using SalomePyQt class directly
459 menubar = SalomePyQt.getMainMenuBar()
464 \fn QString SalomePyQt::getAppName();
465 \brief Get application name
466 \return application name
469 QString SalomePyQt::getAppName()
471 LightApp_Application* app = getApplication();
472 return app == 0 ? QString() : QString(app->metaObject()->className()).split("_").first();
476 \fn bool SalomePyQt::isLightApp();
477 \brief Check if SALOME GUI is running in "light" mode.
478 \return \c true if this is a "light" application; \c false otherwise
481 bool SalomePyQt::isLightApp()
483 return SalomePyQt::getAppName() != "SalomeApp";
487 \fn QWidget* SalomePyQt::getDesktop();
488 \brief Get the active application's desktop window.
489 \return desktop window or 0 if there is no any
492 class TGetDesktopEvent: public SALOME_Event
495 typedef QWidget* TResult;
497 TGetDesktopEvent() : myResult( 0 ) {}
498 virtual void Execute()
500 if ( getApplication() )
501 myResult = (QWidget*)( getApplication()->desktop() );
504 QWidget* SalomePyQt::getDesktop()
506 return ProcessEvent( new TGetDesktopEvent() );
510 \fn QWidget* SalomePyQt::getMainFrame();
511 \brief Get current application's main frame widget [obsolete].
513 Main frame widget is an internal widget of the application
514 desktop window (workspace).
516 \return workspace widget (0 on any error)
519 class TGetMainFrameEvent: public SALOME_Event
522 typedef QWidget* TResult;
524 TGetMainFrameEvent() : myResult( 0 ) {}
525 virtual void Execute()
527 if ( getApplication() ) {
528 SUIT_Desktop* aDesktop = getApplication()->desktop();
529 myResult = (QWidget*)( aDesktop->centralWidget() );
533 QWidget* SalomePyQt::getMainFrame()
535 return ProcessEvent( new TGetMainFrameEvent() );
539 \fn QMenuBar* SalomePyQt::getMainMenuBar();
540 \brief Get current application desktop's main menu.
541 \return main menu object (0 on any error)
544 class TGetMainMenuBarEvent: public SALOME_Event
547 typedef QMenuBar* TResult;
549 TGetMainMenuBarEvent() : myResult( 0 ) {}
550 virtual void Execute()
552 if ( LightApp_Application* anApp = getApplication() ) {
553 myResult = anApp->desktop()->menuBar();
557 QMenuBar* SalomePyQt::getMainMenuBar()
559 return ProcessEvent( new TGetMainMenuBarEvent() );
563 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
564 \brief Get main menu's child popup submenu by its identifier.
566 This function is obsolete.
567 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
569 \param menu menu identifier
570 \return popup submenu object or 0 if it does not exist
574 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
575 \brief Get main menu's child popup submenu by its name.
577 The function creates menu if it does not exist.
579 \param menu menu name
580 \return popup submenu object (0 on any error)
583 class TGetPopupMenuEvent: public SALOME_Event
586 typedef QMenu* TResult;
589 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
590 virtual void Execute()
592 LightApp_Application* anApp = getApplication();
593 if ( anApp && !myMenuName.isEmpty() ) {
594 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
595 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
600 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
605 menuName = getMenuName( "MEN_DESK_FILE" ); break;
607 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
609 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
611 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
613 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
615 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
617 menuName = getMenuName( "MEN_DESK_HELP" ); break;
619 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
621 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
623 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
627 \fn QTreeView* SalomePyQt::getObjectBrowser();
628 \brief Get object browser
629 \return object browser for the active study or 0 in case of error
632 class TGetObjectBrowserEvent: public SALOME_Event
635 typedef QTreeView* TResult;
637 TGetObjectBrowserEvent() : myResult( 0 ) {}
638 virtual void Execute()
640 LightApp_Application* anApp = getApplication();
641 if ( anApp && anApp->objectBrowser() ) {
642 myResult = anApp->objectBrowser()->treeView();
646 QTreeView* SalomePyQt::getObjectBrowser()
648 return ProcessEvent( new TGetObjectBrowserEvent() );
652 \fn SALOME_Selection* SalomePyQt::getSelection();
653 \brief Get the selection object for the current study.
655 Creates a Selection object if it has not been created yet.
657 \return selection object (0 on error)
660 class TGetSelectionEvent: public SALOME_Event
663 typedef SALOME_Selection* TResult;
665 TGetSelectionEvent() : myResult( 0 ) {}
666 virtual void Execute()
668 myResult = SALOME_Selection::GetSelection( getApplication() );
671 SALOME_Selection* SalomePyQt::getSelection()
673 return ProcessEvent( new TGetSelectionEvent() );
677 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
678 \brief Send local selection for notification.
680 The list of locally selected objects (study entries) is sent for notification of
681 other listening entities (modules, viewers...).
684 class TSetSelectionEvent: public SALOME_Event
686 QStringList myEntryList;
688 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
689 virtual void Execute()
691 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
692 if ( !module ) return;
693 module->setLocalSelected(myEntryList);
696 void SalomePyQt::setSelection( const QStringList& entryList)
698 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
702 \fn void SalomePyQt::enableSelector();
703 \brief enable PyQt_Selector (on module activation, for instance)
706 class TEnableSelectorEvent: public SALOME_Event
709 TEnableSelectorEvent() {}
710 virtual void Execute()
712 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
713 if ( !module ) return;
714 module->enableSelector();
717 void SalomePyQt::enableSelector()
719 return ProcessVoidEvent( new TEnableSelectorEvent() );
724 \fn void SalomePyQt::disableSelector();
725 \brief disable PyQt_Selector (on module activation, for instance)
728 class TdisableSelectorEvent: public SALOME_Event
731 TdisableSelectorEvent() {}
732 virtual void Execute()
734 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
735 if ( !module ) return;
736 module->disableSelector();
739 void SalomePyQt::disableSelector()
741 return ProcessVoidEvent( new TdisableSelectorEvent() );
746 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
747 \brief Put an information message to the current application's
750 Optional second delay parameter (\a sec) can be used to specify
751 time of the message diplaying in seconds. If this parameter is less
752 or equal to zero, the constant message will be put.
754 \param msg message text
755 \param sec message displaying time in seconds
758 class TPutInfoEvent: public SALOME_Event
763 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
764 virtual void Execute()
766 if ( LightApp_Application* anApp = getApplication() ) {
767 anApp->putInfo( myMsg, mySecs * 1000 );
771 void SalomePyQt::putInfo( const QString& msg, const int sec )
773 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
777 \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
778 \brief Show notification in the application's desktop window.
780 Optional third delay parameter (\a sec) can be used to specify
781 time of the notification diplaying in seconds. If this parameter is less
782 or equal to zero, the permanent notification will be put.
784 Notification can be forcibly hidden via hideNotification() method.
786 \param msg message text
787 \param title title text
788 \param sec notification displaying time in seconds
789 \return unique ID of the notification (can be used to hide notification)
790 \sa hideNotification()
793 class TShowNotifyEvent: public SALOME_Event
804 TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
805 virtual void Execute()
807 if ( LightApp_Application* anApp = getApplication() ) {
808 myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
813 int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
815 return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
819 \fn void SalomePyQt::hideNotification( const QString& msg );
820 \brief Remove notification with given message text from the application's desktop.
822 \param msg message text
823 \sa showNotification()
827 \fn void SalomePyQt::hideNotification( const int id );
828 \brief Remove notification with given \a id from the application's desktop.
830 \param id notification id
831 \sa showNotification()
834 class THideNotifyEvent: public SALOME_Event
840 THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
841 THideNotifyEvent( const int id ) : myId( id ) {}
842 virtual void Execute()
844 if ( LightApp_Application* anApp = getApplication() ) {
846 anApp->hideNotification( myId );
848 anApp->hideNotification( myMsg );
853 void SalomePyQt::hideNotification( const QString& msg )
855 ProcessVoidEvent( new THideNotifyEvent( msg ) );
858 void SalomePyQt::hideNotification( const int id )
860 ProcessVoidEvent( new THideNotifyEvent( id ) );
864 \fn QStringList SalomePyQt::getComponents();
865 \brief Get all modules used in current GUI session.
866 \return List of modules
869 class TGetComponentsEvent: public SALOME_Event
872 typedef QStringList TResult;
874 TGetComponentsEvent() {}
875 virtual void Execute()
877 if ( LightApp_Application* anApp = getApplication() )
880 anApp->modules( titles, false );
881 foreach ( QString title, titles )
883 myResult << anApp->moduleName( title );
888 QStringList SalomePyQt::getComponents()
890 return ProcessEvent( new TGetComponentsEvent() );
894 \fn const QString SalomePyQt::getActiveComponent();
895 \brief Get the currently active module name (for the current study).
896 \return active module name or empty string if there is no active module
899 class TGetActiveComponentEvent: public SALOME_Event
902 typedef QString TResult;
904 TGetActiveComponentEvent() {}
905 virtual void Execute()
907 if ( LightApp_Application* anApp = getApplication() ) {
908 if ( CAM_Module* mod = anApp->activeModule() ) {
909 myResult = mod->name();
914 const QString SalomePyQt::getActiveComponent()
916 return ProcessEvent( new TGetActiveComponentEvent() );
920 \fn PyObject* SalomePyQt::getActivePythonModule();
921 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
922 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
925 class TGetActivePyModuleEvent: public SALOME_Event
928 typedef PyObject* TResult;
930 TGetActivePyModuleEvent() : myResult( Py_None ) {}
931 virtual void Execute()
933 PyModuleHelper* helper = getPythonHelper();
935 myResult = (PyObject*)helper->pythonModule();
938 PyObject* SalomePyQt::getActivePythonModule()
940 return ProcessEvent( new TGetActivePyModuleEvent() );
944 \fn bool SalomePyQt::activateModule( const QString& modName );
945 \brief Activates SALOME module with the given name
946 \return True if the module has been activated and False otherwise.
949 class TActivateModuleEvent: public SALOME_Event
952 typedef bool TResult;
954 QString myModuleName;
955 TActivateModuleEvent( const QString& modName )
956 : myResult( false ), myModuleName( modName ) {}
957 virtual void Execute()
959 if ( LightApp_Application* anApp = getApplication() ) {
961 myResult = anApp->activateModule( myModuleName );
965 bool SalomePyQt::activateModule( const QString& modName )
967 return ProcessEvent( new TActivateModuleEvent( modName ) );
971 \fn void SalomePyQt::registerModule( const QString& modName);
972 \brief Registers module in the study tree
975 void SalomePyQt::registerModule( const QString& modName)
977 class TEvent: public SALOME_Event
981 TEvent(const QString& name): myName(name) {}
982 virtual void Execute()
984 if ( LightApp_Application* anApp = getApplication() ) {
985 anApp->desktop()->emitMessage(QString("register_module_in_study/%1").arg(myName));
989 ProcessVoidEvent( new TEvent(modName) );
993 \brief Update an Object Browser of the study.
995 void SalomePyQt::updateObjBrowser()
997 class TEvent: public SALOME_Event
1001 virtual void Execute()
1003 if ( SUIT_Session::session() ) {
1004 if ( getActiveStudy() ) {
1005 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
1006 QList<SUIT_Application*>::Iterator it;
1007 for( it = apps.begin(); it != apps.end(); ++it ) {
1008 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
1009 if ( anApp && anApp->activeStudy() ) {
1010 anApp->updateObjectBrowser();
1018 ProcessVoidEvent( new TEvent() );
1023 SalomePyQt::isModified()
1024 \return The modification status of the data model
1025 for the currently active Python module
1026 \note This function is supported for "light" Python-based SALOME modules only.
1029 class TIsModifiedEvent: public SALOME_Event
1032 typedef bool TResult;
1034 TIsModifiedEvent() : myResult( false ) {}
1035 virtual void Execute()
1037 LightApp_Module* module = getActiveModule();
1041 SALOME_PYQT_DataModelLight* aModel =
1042 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1044 myResult = aModel->isModified();
1047 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
1051 bool SalomePyQt::isModified()
1053 return ProcessEvent(new TIsModifiedEvent());
1057 SalomePyQt::setModified()
1059 Sets the modification status of the data model for
1060 the currently active Python module. This method should be used
1061 by the Python code in order to enable/disable "Save" operation
1062 depending on the module's data state.
1064 \note This function is supported for "light" Python-based SALOME modules only.
1066 \param New modification status of the data model
1070 void SalomePyQt::setModified( bool flag )
1072 class TEvent: public SALOME_Event
1078 virtual void Execute()
1080 LightApp_Module* module = getActiveModule();
1084 SALOME_PYQT_DataModelLight* model =
1085 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
1087 LightApp_Application* app = module->getApp();
1089 if ( model && app ) {
1090 model->setModified( myFlag );
1091 app->updateActions();
1094 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
1098 ProcessVoidEvent( new TEvent( flag ) );
1102 \brief Add string setting to the application preferences.
1104 The parameter \a autoValue is obsolete parameter and currently is not used.
1105 This parameter will be removed in future, so try to avoid its usage in
1108 This function is obsolete. Use one of addSetting() instead.
1110 \param name setting name (it should be of kind <section:setting> where
1111 \c section is resources section name and \c setting is setting name)
1112 \param value new setting value
1113 \param autoValue (not used)
1115 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
1117 class TEvent: public SALOME_Event
1123 TEvent( const QString& name, const QString& value, bool autoValue )
1124 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1125 virtual void Execute()
1127 if ( SUIT_Session::session() ) {
1128 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1129 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1130 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1131 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1132 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1133 resMgr->setValue( _sec, _nam, myValue );
1137 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1141 \brief Add integer setting to the application preferences.
1143 The parameter \a autoValue is obsolete parameter and currently is not used.
1144 This parameter will be removed in future, so try to avoid its usage in
1147 This function is obsolete. Use one of addSetting() instead.
1149 \param name setting name (it should be of kind <section:setting> where
1150 \c section is resources section name and \c setting is setting name)
1151 \param value new setting value
1152 \param autoValue (not used)
1154 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
1156 class TEvent: public SALOME_Event
1162 TEvent( const QString& name, const int value, bool autoValue )
1163 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1164 virtual void Execute()
1166 if ( SUIT_Session::session() ) {
1167 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1168 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1169 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1170 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1171 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1172 resMgr->setValue( _sec, _nam, myValue );
1176 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1180 \brief Add double setting to the application preferences.
1182 The parameter \a autoValue is obsolete parameter and currently is not used.
1183 This parameter will be removed in future, so try to avoid its usage in
1186 This function is obsolete. Use one of addSetting() instead.
1188 \param name setting name (it should be of kind <section:setting> where
1189 \c section is resources section name and \c setting is setting name)
1190 \param value new setting value
1191 \param autoValue (not used)
1193 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
1195 class TEvent: public SALOME_Event
1201 TEvent( const QString& name, const double value, bool autoValue )
1202 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1203 virtual void Execute()
1205 if ( SUIT_Session::session() ) {
1206 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1207 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1208 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1209 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1210 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1211 resMgr->setValue( _sec, _nam, myValue );
1215 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1219 \brief Add boolean setting to the application preferences.
1221 The parameter \a autoValue is obsolete parameter and currently is not used.
1222 This parameter will be removed in future, so try to avoid its usage in
1225 This function is obsolete. Use one of addSetting() instead.
1227 \param name setting name (it should be of kind <section:setting> where
1228 \c section is resources section name and \c setting is setting name)
1229 \param value new setting value
1230 \param autoValue (not used)
1232 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
1234 class TEvent: public SALOME_Event
1240 TEvent( const QString& name, const bool value, bool autoValue )
1241 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
1242 virtual void Execute()
1244 if ( SUIT_Session::session() ) {
1245 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1246 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1247 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1248 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1249 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1250 resMgr->setValue( _sec, _nam, myValue );
1254 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
1258 \brief Remove setting from the application preferences.
1260 This function is obsolete. Use removeSetting() instead.
1262 \param name setting name (it should be of kind <section:setting> where
1263 \c section is resources section name and \c setting is setting name)
1265 void SalomePyQt::removeSettings( const QString& name )
1267 class TEvent: public SALOME_Event
1271 TEvent( const QString& name ) : myName( name ) {}
1272 virtual void Execute()
1274 if ( SUIT_Session::session() ) {
1275 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1276 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1277 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1278 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1279 if ( !_sec.isEmpty() && !_nam.isEmpty() )
1280 resMgr->remove( _sec, _nam );
1284 ProcessVoidEvent( new TEvent( name ) );
1288 \fn QString SalomePyQt::getSetting( const QString& name );
1289 \brief Get application setting value (as string represenation).
1291 This function is obsolete. Use stringSetting(), integerSetting(),
1292 boolSetting(), stringSetting() or colorSetting() instead.
1294 \param name setting name (it should be of kind <section:setting> where
1295 \c section is resources section name and \c setting is setting name)
1296 \return setting name (empty string if setting name is invalid)
1299 class TGetSettingEvent: public SALOME_Event
1302 typedef QString TResult;
1305 TGetSettingEvent( const QString& name ) : myName( name ) {}
1306 virtual void Execute()
1308 if ( SUIT_Session::session() ) {
1309 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1310 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1311 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1312 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1313 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1317 QString SalomePyQt::getSetting( const QString& name )
1319 return ProcessEvent( new TGetSettingEvent( name ) );
1323 \fn QString SalomePyQt::constant( const QString& name );
1324 \brief Get constant's value from application's resource manager.
1326 \param name name of the constant
1327 \return value of the constant
1332 class TGetConstantEvent: public SALOME_Event
1335 typedef QString TResult;
1338 TGetConstantEvent( const QString& name ) : myName( name ) {}
1339 virtual void Execute()
1341 if ( SUIT_Session::session() )
1342 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1345 QString SalomePyQt::constant( const QString& name )
1347 return ProcessEvent( new TGetConstantEvent( name ) );
1351 \brief Add constant to the application's resource manager.
1353 This function is useful to specify programmatically specific
1354 variables that are referenced in the resource setting.
1356 For example, some resource value can be set as "$(myroot)/data/files".
1357 Then, "mypath" constant can be set programmatically by the application
1358 depending on run-time requirements.
1360 \param section resources file section name
1361 \param name name of the constant
1362 \param value value of the constant
1366 void SalomePyQt::setConstant( const QString& name, const QString& value )
1368 class TEvent: public SALOME_Event
1370 QString myName, myValue;
1372 TEvent( const QString& name, const QString& value )
1373 : myName( name ), myValue( value ) {}
1374 virtual void Execute()
1376 if ( SUIT_Session::session() )
1377 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1380 ProcessVoidEvent( new TEvent( name, value ) );
1384 \brief Add double setting to the application preferences.
1385 \param section resources file section name
1386 \param name setting name
1387 \param value new setting value
1389 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1391 class TEvent: public SALOME_Event
1397 TEvent( const QString& section, const QString& name, double value )
1398 : mySection( section ), myName( name ), myValue( value ) {}
1399 virtual void Execute()
1401 if ( SUIT_Session::session() ) {
1402 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1403 if ( !mySection.isEmpty() && !myName.isEmpty() )
1404 resMgr->setValue( mySection, myName, myValue );
1408 ProcessVoidEvent( new TEvent( section, name, value ) );
1412 \brief Add integer setting to the application preferences.
1413 \param section resources file section name
1414 \param name setting name
1415 \param value new setting value
1417 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1419 class TEvent: public SALOME_Event
1425 TEvent( const QString& section, const QString& name, int value )
1426 : mySection( section ), myName( name ), myValue( value ) {}
1427 virtual void Execute()
1429 if ( SUIT_Session::session() ) {
1430 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1431 if ( !mySection.isEmpty() && !myName.isEmpty() )
1432 resMgr->setValue( mySection, myName, myValue );
1436 ProcessVoidEvent( new TEvent( section, name, value ) );
1440 \brief Add boolean setting to the application preferences.
1441 \param section resources file section name
1442 \param name setting name
1443 \param value new setting value
1444 \param dumb this parameter is used in order to avoid sip compilation error
1445 because of conflicting int and bool types
1447 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1449 class TEvent: public SALOME_Event
1455 TEvent( const QString& section, const QString& name, bool value )
1456 : mySection( section ), myName( name ), myValue( value ) {}
1457 virtual void Execute()
1459 if ( SUIT_Session::session() ) {
1460 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1461 if ( !mySection.isEmpty() && !myName.isEmpty() )
1462 resMgr->setValue( mySection, myName, myValue );
1466 ProcessVoidEvent( new TEvent( section, name, value ) );
1470 \brief Add string setting to the application preferences.
1471 \param section resources file section name
1472 \param name setting name
1473 \param value new setting value
1475 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1477 class TEvent: public SALOME_Event
1483 TEvent( const QString& section, const QString& name, const QString& value )
1484 : mySection( section ), myName( name ), myValue( value ) {}
1485 virtual void Execute()
1487 if ( SUIT_Session::session() ) {
1488 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1489 if ( !mySection.isEmpty() && !myName.isEmpty() )
1490 resMgr->setValue( mySection, myName, myValue );
1494 ProcessVoidEvent( new TEvent( section, name, value ) );
1498 \brief Add color setting to the application preferences.
1499 \param section resources file section name
1500 \param name setting name
1501 \param value new setting value
1503 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1505 class TEvent: public SALOME_Event
1511 TEvent( const QString& section, const QString& name, const QColor& value )
1512 : mySection( section ), myName( name ), myValue( value ) {}
1513 virtual void Execute()
1515 if ( SUIT_Session::session() ) {
1516 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1517 if ( !mySection.isEmpty() && !myName.isEmpty() )
1518 resMgr->setValue( mySection, myName, myValue );
1522 ProcessVoidEvent( new TEvent( section, name, value ) );
1526 \brief Add byte array setting to the application preferences.
1527 \param section resources file section name
1528 \param name setting name
1529 \param value new setting value
1531 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1533 class TEvent: public SALOME_Event
1539 TEvent( const QString& section, const QString& name, const QByteArray& value )
1540 : mySection( section ), myName( name ), myValue( value ) {}
1541 virtual void Execute()
1543 if ( SUIT_Session::session() ) {
1544 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1545 if ( !mySection.isEmpty() && !myName.isEmpty() )
1546 resMgr->setValue( mySection, myName, myValue );
1550 ProcessVoidEvent( new TEvent( section, name, value ) );
1554 \brief Add font setting to the application preferences.
1555 \param section resources file section name
1556 \param name setting name
1557 \param value new setting value
1559 void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
1561 class TEvent: public SALOME_Event
1567 TEvent( const QString& section, const QString& name, const QFont& value )
1568 : mySection( section ), myName( name ), myValue( value ) {}
1569 virtual void Execute()
1571 if ( SUIT_Session::session() ) {
1572 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1573 if ( !mySection.isEmpty() && !myName.isEmpty() )
1574 resMgr->setValue( mySection, myName, myValue );
1578 ProcessVoidEvent( new TEvent( section, name, value ) );
1582 \fn int SalomePyQt::integerSetting( const QString& section,
1583 const QString& name,
1585 \brief Get integer setting from the application preferences.
1586 \param section resources file section name
1587 \param name setting name
1588 \param def default value which is returned if the setting is not found
1589 \return setting value
1592 class TGetIntSettingEvent: public SALOME_Event
1595 typedef int TResult;
1600 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1601 : mySection( section ), myName( name ), myDefault( def ) {}
1602 virtual void Execute()
1604 if ( SUIT_Session::session() ) {
1605 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1606 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1610 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1612 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1616 \fn double SalomePyQt::doubleSetting( const QString& section,
1617 const QString& name,
1619 \brief Get double setting from the application preferences.
1620 \param section resources file section name
1621 \param name setting name
1622 \param def default value which is returned if the setting is not found
1623 \return setting value
1626 class TGetDblSettingEvent: public SALOME_Event
1629 typedef double TResult;
1634 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1635 : mySection( section ), myName( name ), myDefault( def ) {}
1636 virtual void Execute()
1638 if ( SUIT_Session::session() ) {
1639 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1640 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1644 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1646 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1650 \fn bool SalomePyQt::boolSetting( const QString& section,
1651 const QString& name,
1653 \brief Get boolean setting from the application preferences.
1654 \param section resources file section name
1655 \param name setting name
1656 \param def default value which is returned if the setting is not found
1657 \return setting value
1660 class TGetBoolSettingEvent: public SALOME_Event
1663 typedef bool TResult;
1668 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1669 : mySection( section ), myName( name ), myDefault( def ) {}
1670 virtual void Execute()
1672 if ( SUIT_Session::session() ) {
1673 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1674 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1678 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1680 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1684 \fn QString SalomePyQt::stringSetting( const QString& section,
1685 const QString& name,
1688 \brief Get string setting from the application preferences.
1689 \param section resources file section name
1690 \param name setting name
1691 \param def default value which is returned if the setting is not found
1692 \param subst \c true to make substitution, \c false to get "raw" value
1693 \return setting value
1696 class TGetStrSettingEvent: public SALOME_Event
1699 typedef QString TResult;
1705 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1706 : mySection( section ), myName( name ), mySubst( subst ), myDefault( def ) {}
1707 virtual void Execute()
1709 if ( SUIT_Session::session() ) {
1710 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1711 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1715 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1717 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1721 \fn QColor SalomePyQt::colorSetting( const QString& section,
1722 const QString& name,
1724 \brief Get color setting from the application preferences.
1725 \param section resources file section name
1726 \param name setting name
1727 \param def default value which is returned if the setting is not found
1728 \return setting value
1731 class TGetColorSettingEvent: public SALOME_Event
1734 typedef QColor TResult;
1739 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1740 : mySection( section ), myName( name ), myDefault( def ) {}
1741 virtual void Execute()
1743 if ( SUIT_Session::session() ) {
1744 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1745 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1749 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1751 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1755 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1756 const QString& name,
1757 const QByteArray& def );
1758 \brief Get byte array setting from the application preferences.
1759 \param section resources file section name
1760 \param name setting name
1761 \param def default value which is returned if the setting is not found
1762 \return setting value
1765 class TGetByteArraySettingEvent: public SALOME_Event
1768 typedef QByteArray TResult;
1773 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1774 : mySection( section ), myName( name ), myDefault( def ) {}
1775 virtual void Execute()
1777 if ( SUIT_Session::session() ) {
1778 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1779 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1783 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1785 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1789 \fn QByteArray SalomePyQt::fontSetting( const QString& section,
1790 const QString& name,
1792 \brief Get font setting from the application preferences.
1793 \param section resources file section name
1794 \param name setting name
1795 \param def default value which is returned if the setting is not found
1796 \return setting value
1799 class TGetFontSettingEvent: public SALOME_Event
1802 typedef QFont TResult;
1807 TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
1808 : mySection( section ), myName( name ), myDefault( def ) {}
1809 virtual void Execute()
1811 if ( SUIT_Session::session() ) {
1812 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1813 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
1817 QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
1819 return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
1823 \brief Remove setting from the application preferences.
1824 \param section resources file section name
1825 \param name setting name
1827 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1829 class TEvent: public SALOME_Event
1834 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1835 virtual void Execute()
1837 if ( SUIT_Session::session() ) {
1838 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1839 if ( !mySection.isEmpty() && !myName.isEmpty() )
1840 resMgr->remove( mySection, myName );
1844 ProcessVoidEvent( new TEvent( section, name ) );
1848 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1849 \brief Check setting existence in the application preferences.
1850 \param section resources file section name
1851 \param name setting name
1852 \return \c true if setting exists
1855 class THasSettingEvent: public SALOME_Event
1858 typedef bool TResult;
1862 THasSettingEvent( const QString& section, const QString& name )
1863 : mySection( section ), myName( name ) {}
1864 virtual void Execute()
1866 if ( SUIT_Session::session() ) {
1867 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1868 myResult = resMgr->hasValue( mySection, myName );
1872 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1874 return ProcessEvent( new THasSettingEvent( section, name ) );
1878 \fn QStringList SalomePyQt::parameters( const QString& section );
1879 \brief Get names of preference items stored within the given section.
1880 \param section resources file section's name
1881 \return \c list of preferences items
1885 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1886 \brief Get names of preference items stored within the given section.
1887 \param section resources file section's name
1888 \return \c list of preferences items
1891 class TParametersEvent: public SALOME_Event
1894 typedef QStringList TResult;
1896 QStringList mySection;
1897 TParametersEvent( const QString& section )
1899 mySection << section;
1901 TParametersEvent( const QStringList& section )
1902 : mySection( section )
1904 virtual void Execute()
1906 if ( SUIT_Session::session() ) {
1907 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1908 myResult = resMgr->parameters( mySection );
1912 QStringList SalomePyQt::parameters( const QString& section )
1914 return ProcessEvent( new TParametersEvent( section ) );
1916 QStringList SalomePyQt::parameters( const QStringList& section )
1918 return ProcessEvent( new TParametersEvent( section ) );
1922 \fn QString SalomePyQt::getFileName( QWidget* parent,
1923 const QString& initial,
1924 const QStringList& filters,
1925 const QString& caption,
1927 \brief Show 'Open/Save file' dialog box for file selection
1928 and return a user's choice (selected file name).
1929 \param parent parent widget
1930 \param initial initial directory the dialog box to be opened in
1931 \param filters list of files filters (wildcards)
1932 \param caption dialog box title
1933 \param open if \c true, "Open File" dialog box is shown;
1934 otherwise "Save File" dialog box is shown
1935 \return selected file name (null string if user cancels operation)
1938 class TGetFileNameEvent: public SALOME_Event
1941 typedef QString TResult;
1945 QStringList myFilters;
1948 TGetFileNameEvent( QWidget* parent,
1949 const QString& initial,
1950 const QStringList& filters,
1951 const QString& caption,
1953 : myParent ( parent ),
1954 myInitial( initial ),
1955 myFilters( filters ),
1956 myCaption( caption ),
1958 virtual void Execute()
1960 if ( LightApp_Application* anApp = getApplication() ) {
1961 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1962 myCaption, myParent );
1966 QString SalomePyQt::getFileName( QWidget* parent,
1967 const QString& initial,
1968 const QStringList& filters,
1969 const QString& caption,
1972 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1976 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1977 const QString& initial,
1978 const QStringList& filters,
1979 const QString& caption );
1980 \brief Show 'Open files' dialog box for multiple files selection
1981 and return a user's choice (selected file names list).
1982 \param parent parent widget
1983 \param initial initial directory the dialog box to be opened in
1984 \param filters list of files filters (wildcards)
1985 \param caption dialog box title
1986 \return selected file names list (empty list if user cancels operation)
1989 class TGetOpenFileNamesEvent: public SALOME_Event
1992 typedef QStringList TResult;
1996 QStringList myFilters;
1998 TGetOpenFileNamesEvent( QWidget* parent,
1999 const QString& initial,
2000 const QStringList& filters,
2001 const QString& caption )
2002 : myParent ( parent ),
2003 myInitial( initial ),
2004 myFilters( filters ),
2005 myCaption( caption ) {}
2006 virtual void Execute()
2008 if ( LightApp_Application* anApp = getApplication() ) {
2009 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
2013 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
2014 const QString& initial,
2015 const QStringList& filters,
2016 const QString& caption )
2018 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
2022 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
2023 const QString& initial,
2024 const QString& caption );
2025 \brief Show 'Get Directory' dialog box for the directory selection
2026 and return a user's choice (selected directory name).
2027 \param parent parent widget
2028 \param initial initial directory the dialog box to be opened in
2029 \param caption dialog box title
2030 \return selected directory name (null string if user cancels operation)
2033 class TGetExistingDirectoryEvent: public SALOME_Event
2036 typedef QString TResult;
2041 TGetExistingDirectoryEvent( QWidget* parent,
2042 const QString& initial,
2043 const QString& caption )
2044 : myParent ( parent ),
2045 myInitial( initial ),
2046 myCaption( caption ) {}
2047 virtual void Execute()
2049 if ( LightApp_Application* anApp = getApplication() ) {
2050 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
2054 QString SalomePyQt::getExistingDirectory( QWidget* parent,
2055 const QString& initial,
2056 const QString& caption )
2058 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
2062 \fn QString SalomePyQt::loadIcon( const QString& filename );
2063 \brief Load an icon from the module resources by the specified file name.
2064 \param fileName icon file name
2068 class TLoadIconEvent: public SALOME_Event
2071 typedef QIcon TResult;
2075 TLoadIconEvent( const QString& module, const QString& filename )
2076 : myModule( module ),
2077 myFileName ( filename ) {}
2078 virtual void Execute()
2080 myResult = loadIconInternal( myModule, myFileName );
2083 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
2085 return ProcessEvent( new TLoadIconEvent( module, filename ) );
2089 \brief Open external browser to display context help information.
2092 Current implementation does nothing.
2094 \param source documentation (HTML) file name
2095 \param context context (for example, HTML ancor name)
2097 void SalomePyQt::helpContext( const QString& source, const QString& context )
2099 class TEvent: public SALOME_Event
2104 TEvent( const QString& source, const QString& context )
2105 : mySource( source ), myContext( context ) {}
2106 virtual void Execute()
2108 if ( LightApp_Application* anApp = getApplication() ) {
2109 anApp->onHelpContextModule( "", mySource, myContext );
2113 ProcessVoidEvent( new TEvent( source, context ) );
2117 \fn int SalomePyQt::defaultMenuGroup();
2118 \brief Get detault menu group identifier which can be used when
2119 creating menus (insert custom menu commands).
2120 \return default menu group ID
2123 class TDefMenuGroupEvent: public SALOME_Event
2126 typedef int TResult;
2128 TDefMenuGroupEvent() : myResult( -1 ) {}
2129 virtual void Execute()
2131 myResult = PyModuleHelper::defaultMenuGroup();
2134 int SalomePyQt::defaultMenuGroup()
2136 return ProcessEvent( new TDefMenuGroupEvent() );
2142 CrTool( const QString& tBar, const QString& nBar )
2143 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
2144 CrTool( const int id, const int tBar, const int idx )
2145 : myCase( 1 ), myTbId( tBar ), myId( id ), myIndex( idx ) {}
2146 CrTool( const int id, const QString& tBar, const int idx )
2147 : myCase( 2 ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
2148 CrTool( QAction* action, const int tbId, const int id, const int idx )
2149 : myCase( 3 ), myTbId( tbId ), myAction( action ), myId( id ), myIndex( idx ) {}
2150 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
2151 : myCase( 4 ), myTbTitle( tBar ), myAction( action ), myId( id ), myIndex( idx ) {}
2157 if ( getActiveModule() )
2158 return getActiveModule()->createTool( myTbTitle, myTbName );
2159 else if ( getApplication() )
2160 return getApplication()->createTool( myTbTitle, myTbName );
2163 if ( getActiveModule() )
2164 return getActiveModule()->createTool( myId, myTbId, myIndex );
2165 else if ( getApplication() )
2166 return getApplication()->createTool( myId, myTbId, myIndex );
2169 if ( getActiveModule() )
2170 return getActiveModule()->createTool( myId, myTbTitle, myIndex );
2171 else if ( getApplication() )
2172 return getApplication()->createTool( myId, myTbTitle, myIndex );
2175 if ( getActiveModule() )
2176 return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
2177 else if ( getApplication() )
2178 return getApplication()->createTool( myAction, myTbId, myId, myIndex );
2181 if ( getActiveModule() )
2182 return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
2183 else if ( getApplication() )
2184 return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
2201 class TCreateToolEvent: public SALOME_Event
2204 typedef int TResult;
2206 const CrTool& myCrTool;
2207 TCreateToolEvent( const CrTool& crTool )
2208 : myResult( -1 ), myCrTool( crTool ) {}
2209 virtual void Execute()
2211 myResult = myCrTool.execute();
2216 \brief Create toolbar with specified name.
2217 \param tBar toolbar title (language-dependent)
2218 \param nBar toolbar name (language-independent) [optional]
2219 \return toolbar ID or -1 if toolbar creation is failed
2221 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
2223 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
2227 \brief Insert action with specified \a id to the toolbar.
2229 \param tBar toolbar ID
2230 \param idx required index in the toolbar
2231 \return action ID or -1 if action could not be added
2233 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
2235 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2239 \brief Insert action with specified \a id to the toolbar.
2241 \param tBar toolbar name
2242 \param idx required index in the toolbar
2243 \return action ID or -1 if action could not be added
2245 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
2247 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
2251 \brief Insert action to the toolbar.
2253 \param tBar toolbar ID
2254 \param id required action ID
2255 \param idx required index in the toolbar
2256 \return action ID or -1 if action could not be added
2258 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
2260 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2265 \brief Clear given toolbar.
2266 \param title toolbar's title
2268 void SalomePyQt::clearTool( const QString& title )
2270 class TEvent: public SALOME_Event
2274 TEvent( const QString& title )
2275 : myTitle( title ) {}
2276 virtual void Execute()
2278 if ( getActiveModule() )
2279 return getActiveModule()->clearTool( myTitle );
2280 else if ( getApplication() )
2281 return getApplication()->clearTool( myTitle );
2284 ProcessVoidEvent( new TEvent( title ) );
2288 \brief Insert action to the toolbar.
2290 \param tBar toolbar name
2291 \param id required action ID
2292 \param idx required index in the toolbar
2293 \return action ID or -1 if action could not be added
2295 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
2297 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
2303 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2304 : myCase( 0 ), myMenuId( menu ), mySubMenuName( subMenu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2305 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2306 : myCase( 1 ), myMenuName( menu ), mySubMenuName( subMenu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2307 CrMenu( const int id, const int menu, const int group, const int idx )
2308 : myCase( 2 ), myMenuId( menu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2309 CrMenu( const int id, const QString& menu, const int group, const int idx )
2310 : myCase( 3 ), myMenuName( menu ), myGroup( group ), myId( id ), myIndex( idx ) {}
2311 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
2312 : myCase( 4 ), myMenuId( menu ), myGroup( group ), myAction( action ), myId( id ), myIndex( idx ) {}
2313 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
2314 : myCase( 5 ), myMenuName( menu ), myGroup( group ), myAction( action ), myId( id ), myIndex( idx ) {}
2320 if ( getActiveModule() )
2321 return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2322 else if ( getApplication() )
2323 return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
2326 if ( getActiveModule() )
2327 return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2328 else if ( getApplication() )
2329 return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
2332 if ( getActiveModule() )
2333 return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
2334 else if ( getApplication() )
2335 return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
2338 if ( getActiveModule() )
2339 return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
2340 else if ( getApplication() )
2341 return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
2344 if ( getActiveModule() )
2345 return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2346 else if ( getApplication() )
2347 return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
2350 if ( getActiveModule() )
2351 return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2352 else if ( getApplication() )
2353 return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
2364 QString mySubMenuName;
2371 class TCreateMenuEvent: public SALOME_Event
2374 typedef int TResult;
2376 const CrMenu& myCrMenu;
2377 TCreateMenuEvent( const CrMenu& crMenu )
2378 : myResult( -1 ), myCrMenu( crMenu ) {}
2379 virtual void Execute()
2381 myResult = myCrMenu.execute();
2386 \brief Create main menu.
2387 \param subMenu menu name
2388 \param menu parent menu ID
2389 \param id required menu ID
2390 \param group menu group ID
2391 \param idx required index in the menu
2392 \return menu ID or -1 if menu could not be added
2394 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
2396 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2400 \brief Create main menu.
2401 \param subMenu menu name
2402 \param menu parent menu name (list of menu names separated by "|")
2403 \param id required menu ID
2404 \param group menu group ID
2405 \param idx required index in the menu
2406 \return menu ID or -1 if menu could not be added
2408 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2410 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
2414 \brief Insert action to the main menu.
2416 \param menu parent menu ID
2417 \param group menu group ID
2418 \param idx required index in the menu
2419 \return action ID or -1 if action could not be added
2421 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
2423 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2427 \brief Insert action to the main menu.
2429 \param menu parent menu name (list of menu names separated by "|")
2430 \param group menu group ID
2431 \param idx required index in the menu
2432 \return action ID or -1 if action could not be added
2434 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2436 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2440 \brief Insert action to the main menu.
2442 \param menu parent menu ID
2443 \param group menu group ID
2444 \param idx required index in the menu
2445 \return action ID or -1 if action could not be added
2447 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2449 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2453 \brief Insert action to the main menu.
2455 \param menu parent menu name (list of menu names separated by "|")
2456 \param group menu group ID
2457 \param idx required index in the menu
2458 \return action ID or -1 if action could not be added
2460 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2462 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2466 \fn QAction* SalomePyQt::createSeparator();
2467 \brief Create separator action which can be used in the menu or toolbar.
2468 \return new separator action
2471 class TCreateSepEvent: public SALOME_Event
2474 typedef QAction* TResult;
2478 virtual void Execute()
2480 LightApp_Module* module = getActiveModule();
2482 myResult = (QAction*)module->separator();
2485 QAction* SalomePyQt::createSeparator()
2487 return ProcessEvent( new TCreateSepEvent() );
2491 \fn QAction* SalomePyQt::createAction( const int id,
2492 const QString& menuText,
2493 const QString& tipText,
2494 const QString& statusText,
2495 const QString& icon,
2497 const bool toggle );
2498 \brief Create an action which can be then used in the menu or toolbar.
2499 \param id the unique id action to be registered to
2500 \param menuText action text which should appear in menu
2501 \param tipText text which should appear in the tooltip
2502 \param statusText text which should appear in the status bar when action is activated
2503 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2504 \param key the key accelrator for the action
2505 \param toggle if \c true the action is checkable
2508 class TCreateActionEvent: public SALOME_Event
2511 typedef QAction* TResult;
2516 QString myStatusText;
2520 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2521 const QString& statusText, const QString& icon, const int key, const bool toggle )
2522 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2523 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2524 virtual void Execute()
2526 LightApp_Module* module = getActiveModule();
2528 QIcon icon = loadIconInternal( module->name(), myIcon );
2529 myResult = (QAction*)module->action( myId );
2531 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2532 myResult->setToolTip( myTipText );
2533 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2534 myResult->setText( myMenuText );
2535 if ( myResult->icon().isNull() && !icon.isNull() )
2536 myResult->setIcon( icon );
2537 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2538 myResult->setStatusTip( myStatusText );
2539 if ( myResult->shortcut().isEmpty() && myKey )
2540 myResult->setShortcut( myKey );
2541 if ( myResult->isCheckable() != myToggle )
2542 myResult->setCheckable( myToggle );
2545 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2547 // for Python module, automatically connect action to callback slot
2548 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2549 if ( helper ) helper->connectAction( myResult );
2553 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2554 const QString& tipText, const QString& statusText,
2555 const QString& icon, const int key, const bool toggle )
2557 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2561 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2562 \brief Create an action group which can be then used in the menu or toolbar
2563 \param id : the unique id action group to be registered to
2564 \param exclusive : if \c true the action group does exclusive toggling
2567 struct TCreateActionGroupEvent: public SALOME_Event
2569 typedef QtxActionGroup* TResult;
2573 TCreateActionGroupEvent( const int id, const bool exclusive )
2574 : myId( id ), myExclusive( exclusive ) {}
2575 virtual void Execute()
2577 LightApp_Module* module = getActiveModule();
2579 myResult = module->createActionGroup( myId, myExclusive );
2582 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2584 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2588 \fn QAction* SalomePyQt::action( const int id );
2589 \brief Get action by specified identifier.
2590 \return action or 0 if action is not registered
2593 class TActionEvent: public SALOME_Event
2596 typedef QAction* TResult;
2599 TActionEvent( const int id )
2600 : myResult( 0 ), myId( id ) {}
2601 virtual void Execute()
2603 LightApp_Module* module = getActiveModule();
2605 myResult = (QAction*)module->action( myId );
2608 QAction* SalomePyQt::action( const int id )
2610 return ProcessEvent( new TActionEvent( id ) );
2614 \fn int SalomePyQt::actionId( const QAction* a );
2615 \brief Get an action identifier.
2616 \return action ID or -1 if action is not registered
2619 class TActionIdEvent: public SALOME_Event
2622 typedef int TResult;
2624 const QAction* myAction;
2625 TActionIdEvent( const QAction* action )
2626 : myResult( -1 ), myAction( action ) {}
2627 virtual void Execute()
2629 LightApp_Module* module = getActiveModule();
2631 myResult = module->actionId( myAction );
2634 int SalomePyQt::actionId( const QAction* a )
2636 return ProcessEvent( new TActionIdEvent( a ) );
2640 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2641 \brief Add global (not module-related) preferences group.
2642 \param label global preferences group name
2643 \return preferences group identifier
2646 class TAddGlobalPrefEvent: public SALOME_Event
2649 typedef int TResult;
2652 TAddGlobalPrefEvent( const QString& label )
2653 : myResult( -1 ), myLabel( label ) {}
2654 virtual void Execute()
2656 LightApp_Module* module = getActiveModule();
2658 LightApp_Preferences* pref = module->getApp()->preferences();
2660 myResult = pref->addPreference( myLabel, -1 );
2664 int SalomePyQt::addGlobalPreference( const QString& label )
2666 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2670 \fn int SalomePyQt::addPreference( const QString& label );
2671 \brief Add module-related preferences group.
2672 \param label preferences group name
2673 \return preferences group identifier
2676 class TAddPrefEvent: public SALOME_Event
2679 typedef int TResult;
2682 TAddPrefEvent( const QString& label )
2683 : myResult( -1 ), myLabel( label ) {}
2684 virtual void Execute()
2686 LightApp_Module* module = getActiveModule();
2688 LightApp_Preferences* pref = module->getApp()->preferences();
2690 int cId = pref->addPreference( module->moduleName(), -1 );
2692 myResult = pref->addPreference( myLabel, cId );
2697 int SalomePyQt::addPreference( const QString& label )
2699 return ProcessEvent( new TAddPrefEvent( label ) );
2703 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2704 const QString& section, const QString& param );
2705 \brief Add module-related preferences.
2706 \param label preferences group name
2707 \param pId parent preferences group id
2708 \param type preferences type
2709 \param section resources file section name
2710 \param param resources file setting name
2711 \return preferences identifier
2714 class TAddPrefParamEvent: public SALOME_Event
2717 typedef int TResult;
2724 TAddPrefParamEvent( const QString& label,
2725 const int pId, const int type,
2726 const QString& section,
2727 const QString& param )
2729 myLabel( label ), myPId( pId ), myType( type ),
2730 mySection( section ), myParam ( param ) {}
2731 virtual void Execute()
2733 LightApp_Module* module = getActiveModule();
2735 LightApp_Preferences* pref = module->getApp()->preferences();
2737 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2741 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2742 const QString& section, const QString& param )
2744 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2748 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2749 \brief Get the preferences property.
2750 \param id preferences identifier
2751 \param prop preferences property name
2752 \return preferences property value or null QVariant if property is not set
2755 class TPrefPropEvent: public SALOME_Event
2758 typedef QVariant TResult;
2762 TPrefPropEvent( const int id, const QString& prop )
2763 : myId( id ), myProp( prop ) {}
2764 virtual void Execute()
2766 LightApp_Module* module = getActiveModule();
2768 LightApp_Preferences* pref = module->getApp()->preferences();
2770 myResult = pref->itemProperty( myProp, myId );
2774 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2776 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2780 \brief Set the preferences property.
2781 \param id preferences identifier
2782 \param prop preferences property name
2783 \param var preferences property value
2785 void SalomePyQt::setPreferenceProperty( const int id,
2786 const QString& prop,
2787 const QVariant& var )
2789 class TEvent: public SALOME_Event
2795 TEvent( const int id, const QString& prop, const QVariant& var )
2796 : myId( id ), myProp( prop ), myVar( var ) {}
2797 virtual void Execute()
2799 LightApp_Module* module = getActiveModule();
2801 LightApp_Preferences* pref = module->getApp()->preferences();
2803 pref->setItemProperty( myProp, myVar, myId );
2807 ProcessVoidEvent( new TEvent( id, prop, var ) );
2811 \brief Set specific widget as a custom preferences item.
2812 \param id preferences identifier
2813 \param prop preferences property name
2814 \param widget custom widget
2816 void SalomePyQt::setPreferencePropertyWg( const int id,
2817 const QString& prop,
2818 UserDefinedContent* widget )
2820 class TEvent: public SALOME_Event
2824 UserDefinedContent* myWidget;
2826 TEvent( const int id, const QString& prop, UserDefinedContent* widget )
2827 : myId( id ), myProp( prop ), myWidget( widget ) {}
2828 virtual void Execute()
2830 LightApp_Module* module = getActiveModule();
2832 LightApp_Preferences* pref = module->getApp()->preferences();
2834 pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
2839 ProcessVoidEvent( new TEvent( id, prop, widget ) );
2843 \brief Add the property value to the list of values.
2845 This method allows creating properties which are QList<QVariant>
2846 - there is no way to pass such values directly to QVariant parameter with PyQt.
2848 \param id preferences identifier
2849 \param prop preferences property name
2850 \param idx preferences property index
2851 \param var preferences property value for the index \a idx
2853 void SalomePyQt::addPreferenceProperty( const int id,
2854 const QString& prop,
2856 const QVariant& var )
2858 class TEvent: public SALOME_Event
2865 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2866 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2867 virtual void Execute()
2869 LightApp_Module* module = getActiveModule();
2871 LightApp_Preferences* pref = module->getApp()->preferences();
2873 QVariant var = pref->itemProperty( myProp, myId );
2874 if ( var.isValid() ) {
2875 if ( var.type() == QVariant::StringList ) {
2876 QStringList sl = var.toStringList();
2877 if ( myIdx >= 0 && myIdx < sl.count() )
2878 sl[myIdx] = myVar.toString();
2880 sl.append( myVar.toString() );
2881 pref->setItemProperty( myProp, sl, myId );
2883 else if ( var.type() == QVariant::List ) {
2884 QList<QVariant> vl = var.toList();
2885 if ( myIdx >= 0 && myIdx < vl.count() )
2889 pref->setItemProperty( myProp, vl, myId );
2895 pref->setItemProperty( myProp, vl, myId );
2901 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2905 \brief Put the message to the Log messages output window
2906 \param msg message text (it can be of simple rich text format)
2907 \param addSeparator boolean flag which specifies if it is necessary
2908 to separate the message with predefined separator
2910 void SalomePyQt::message( const QString& msg, bool addSeparator )
2912 class TEvent: public SALOME_Event
2917 TEvent( const QString& msg, bool addSeparator )
2918 : myMsg( msg ), myAddSep( addSeparator ) {}
2919 virtual void Execute()
2921 if ( LightApp_Application* anApp = getApplication() ) {
2922 LogWindow* lw = anApp->logWindow();
2924 lw->putMessage( myMsg, myAddSep );
2928 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2932 \brief Set the title to the Help panel.
2933 \param title Title text (empty string removes title)
2935 void SalomePyQt::infoSetTitle( const QString& title )
2937 class TEvent: public SALOME_Event
2941 TEvent( const QString& title )
2942 : myTitle( title ) {}
2943 virtual void Execute()
2945 if ( LightApp_Application* anApp = getApplication() ) {
2946 QtxInfoPanel* ip = anApp->infoPanel();
2948 ip->setTitle( myTitle );
2952 ProcessVoidEvent( new TEvent( title ) );
2956 \fn int SalomePyQt::infoAddLabel( const QString& text, const int groupId )
2957 \brief Insert left-aligned text label into the Help panel
2958 \param text Label text
2959 \param groupId Parent group's identifier (defaults to -1 for top-level group)
2960 \return Label's identifier
2963 class TInfoAddLabel2paramEvent: public SALOME_Event
2966 typedef int TResult;
2970 TInfoAddLabel2paramEvent( const QString& text, const int groupId )
2971 : myText( text ), myGroupId( groupId ) {}
2972 virtual void Execute()
2974 if ( LightApp_Application* anApp = getApplication() ) {
2975 QtxInfoPanel* ip = anApp->infoPanel();
2977 myResult = ip->addLabel( myText, myGroupId );
2981 int SalomePyQt::infoAddLabel( const QString& text, const int groupId )
2983 return ProcessEvent( new TInfoAddLabel2paramEvent( text, groupId ) );
2987 \fn int SalomePyQt::infoAddLabel( const QString& text, Qt::Alignment alignment, const int groupId )
2988 \brief Insert text label into the Help panel
2989 \param text Label text
2990 \param alignment Alignment flag for text label
2991 \param groupId Parent group's identifier (defaults to -1 for top-level group)
2992 \return Label's identifier
2995 class TInfoAddLabel3paramEvent: public SALOME_Event
2998 typedef int TResult;
3001 Qt::Alignment myAlignment;
3003 TInfoAddLabel3paramEvent( const QString& text, Qt::Alignment alignment, const int groupId )
3004 : myText( text ), myAlignment( alignment ), myGroupId( groupId ) {}
3005 virtual void Execute()
3007 if ( LightApp_Application* anApp = getApplication() ) {
3008 QtxInfoPanel* ip = anApp->infoPanel();
3010 myResult = ip->addLabel( myText, myAlignment, myGroupId );
3014 int SalomePyQt::infoAddLabel( const QString& text, Qt::Alignment alignment, const int groupId )
3016 return ProcessEvent( new TInfoAddLabel3paramEvent( text, alignment, groupId ) );
3020 \fn int SalomePyQt::infoAddAction( QAction* action, const int groupId )
3021 \brief Insert action button into the Help panel
3022 \param action Action being added
3023 \param groupId Parent group's identifier (defaults to -1 for top-level group)
3024 \return Action's identifier
3027 class TInfoAddActionEvent: public SALOME_Event
3030 typedef int TResult;
3034 TInfoAddActionEvent( QAction* action, const int groupId )
3035 : myAction( action ), myGroupId( groupId ) {}
3036 virtual void Execute()
3038 if ( LightApp_Application* anApp = getApplication() ) {
3039 QtxInfoPanel* ip = anApp->infoPanel();
3041 myResult = ip->addAction( myAction, myGroupId );
3045 int SalomePyQt::infoAddAction( QAction* action, const int groupId )
3047 return ProcessEvent( new TInfoAddActionEvent( action, groupId ) );
3051 \fn int SalomePyQt::infoAddGroup( const QString& text, const int groupId )
3052 \brief Create a (sub-)group in the Help panel
3053 \param text Group title
3054 \param groupId Parent group's identifier (defaults to -1 for top-level group)
3055 \return Group's identifier
3058 class TInfoAddGroupEvent: public SALOME_Event
3061 typedef int TResult;
3065 TInfoAddGroupEvent( const QString& text, const int groupId )
3066 : myText( text ), myGroupId( groupId ) {}
3067 virtual void Execute()
3069 if ( LightApp_Application* anApp = getApplication() ) {
3070 QtxInfoPanel* ip = anApp->infoPanel();
3072 myResult = ip->addGroup( myText, myGroupId );
3076 int SalomePyQt::infoAddGroup( const QString& text, const int groupId )
3078 return ProcessEvent( new TInfoAddGroupEvent( text, groupId ) );
3082 \brief Remove item from the Help panel
3083 \param id Item's (label's, action's, group's, ...) identifier
3085 void SalomePyQt::infoRemove( const int id )
3087 class TEvent: public SALOME_Event
3091 TEvent( const int id )
3093 virtual void Execute()
3095 if ( LightApp_Application* anApp = getApplication() ) {
3096 QtxInfoPanel* ip = anApp->infoPanel();
3102 ProcessVoidEvent( new TEvent( id ) );
3106 \brief Clear Help panel's contents
3107 \param groupId Group's identifier (default is -1, to clear whole panel)
3109 void SalomePyQt::infoClear( const int groupId )
3111 class TEvent: public SALOME_Event
3115 TEvent( const int groupId )
3116 : myGroupId( groupId ) {}
3117 virtual void Execute()
3119 if ( LightApp_Application* anApp = getApplication() ) {
3120 QtxInfoPanel* ip = anApp->infoPanel();
3122 ip->clear( myGroupId );
3126 ProcessVoidEvent( new TEvent( groupId ) );
3130 \brief Set item's visibility in the Help panel
3131 \param id Item's (label's, action's, group's, ...) identifier
3132 \param visible Visibility flag
3134 void SalomePyQt::infoSetVisible( const int id, bool visible )
3136 class TEvent: public SALOME_Event
3141 TEvent( const int id, bool visible )
3142 : myId( id ), myVisible( visible ) {}
3143 virtual void Execute()
3145 if ( LightApp_Application* anApp = getApplication() ) {
3146 QtxInfoPanel* ip = anApp->infoPanel();
3148 ip->setVisible( myId, myVisible );
3152 ProcessVoidEvent( new TEvent( id, visible ) );
3156 \brief Enable/disable item in the Help panel
3157 \param id Item's (label's, action's, group's, ...) identifier
3158 \param enabled Enabled state
3160 void SalomePyQt::infoSetEnabled( const int id, bool enabled )
3162 class TEvent: public SALOME_Event
3167 TEvent( const int id, bool enabled )
3168 : myId( id ), myEnabled( enabled ) {}
3169 virtual void Execute()
3171 if ( LightApp_Application* anApp = getApplication() ) {
3172 QtxInfoPanel* ip = anApp->infoPanel();
3174 ip->setEnabled( myId, myEnabled );
3178 ProcessVoidEvent( new TEvent( id, enabled ) );
3182 \brief Remove all the messages from the Log messages output window.
3184 void SalomePyQt::clearMessages()
3186 class TEvent: public SALOME_Event
3190 virtual void Execute()
3192 if ( LightApp_Application* anApp = getApplication() ) {
3193 LogWindow* lw = anApp->logWindow();
3199 ProcessVoidEvent( new TEvent() );
3203 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
3204 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
3205 to the image file in the specified format.
3207 For the current moment JPEG, PNG and BMP images formats are supported.
3208 The image format is defined automatically by the file name extension.
3209 By default, BMP format is used.
3211 \param filename image file name
3212 \return operation status (\c true on success)
3215 class TDumpViewEvent: public SALOME_Event
3218 typedef bool TResult;
3222 TDumpViewEvent( const QString& filename, const int id )
3223 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
3224 virtual void Execute()
3226 SUIT_ViewWindow* wnd = 0;
3228 if ( LightApp_Application* anApp = getApplication() ) {
3229 SUIT_ViewManager* vm = anApp->activeViewManager();
3231 wnd = vm->getActiveView();
3233 myWndId = wnd->getId();
3236 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3239 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
3240 #ifndef DISABLE_PLOT2DVIEWER
3241 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3243 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
3244 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
3245 qApp->processEvents();
3246 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
3247 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
3251 #endif // DISABLE_PLOT2DVIEWER
3252 QImage im = wnd->dumpView();
3253 if ( !im.isNull() && !myFileName.isEmpty() ) {
3254 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
3255 if ( fmt == "JPG" ) fmt = "JPEG";
3256 myResult = im.save( myFileName, fmt.toLatin1() );
3261 bool SalomePyQt::dumpView( const QString& filename, const int id )
3263 return ProcessEvent( new TDumpViewEvent( filename, id ) );
3267 \fn QList<int> SalomePyQt::getViews();
3268 \brief Get list of integer identifiers of all the currently opened views
3269 \return list of integer identifiers of all the currently opened views
3272 class TGetViews: public SALOME_Event
3275 typedef QList<int> TResult;
3278 virtual void Execute()
3281 LightApp_Application* app = getApplication();
3283 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3285 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3286 SUIT_ViewWindow* wnd;
3287 foreach ( wnd, wndlist )
3288 myResult.append( wnd->getId() );
3293 QList<int> SalomePyQt::getViews()
3295 return ProcessEvent( new TGetViews() );
3299 \fn int SalomePyQt::getActiveView();
3300 \brief Get integer identifier of the currently active view
3301 \return integer identifier of the currently active view
3304 class TGetActiveView: public SALOME_Event
3307 typedef int TResult;
3311 virtual void Execute()
3313 LightApp_Application* app = getApplication();
3315 SUIT_ViewManager* viewMgr = app->activeViewManager();
3317 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3319 myResult = wnd->getId();
3324 int SalomePyQt::getActiveView()
3326 return ProcessEvent( new TGetActiveView() );
3330 \fn QString SalomePyQt::getViewType( const int id );
3331 \brief Get type of the specified view, e.g. "OCCViewer"
3332 \param id window identifier
3336 class TGetViewType: public SALOME_Event
3339 typedef QString TResult;
3342 TGetViewType( const int id )
3344 virtual void Execute()
3346 SUIT_ViewWindow* wnd = getWnd( myWndId );
3348 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3350 myResult = viewMgr->getType();
3354 QString SalomePyQt::getViewType( const int id )
3356 return ProcessEvent( new TGetViewType( id ) );
3360 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
3361 \brief Change view caption
3362 \param id window identifier
3363 \param title new window title
3364 \return \c true if operation is completed successfully and \c false otherwise
3367 class TSetViewTitle: public SALOME_Event
3370 typedef bool TResult;
3374 TSetViewTitle( const int id, const QString& title )
3375 : myResult( false ),
3378 virtual void Execute()
3380 SUIT_ViewWindow* wnd = getWnd( myWndId );
3382 wnd->setWindowTitle( myTitle );
3387 bool SalomePyQt::setViewTitle( const int id, const QString& title )
3389 return ProcessEvent( new TSetViewTitle( id, title ) );
3393 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
3394 \brief Set view size
3395 \param w window width
3396 \param h window height
3397 \param id window identifier
3398 \return \c true if operation is completed successfully and \c false otherwise
3401 class TSetViewSize: public SALOME_Event
3404 typedef bool TResult;
3409 TSetViewSize( const int w, const int h, const int id )
3410 : myResult( false ),
3414 virtual void Execute()
3416 SUIT_ViewWindow* wnd = 0;
3418 if ( LightApp_Application* anApp = getApplication() ) {
3419 SUIT_ViewManager* vm = anApp->activeViewManager();
3421 wnd = vm->getActiveView();
3425 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3428 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3430 QString type = viewMgr->getType();
3431 if ( type == "OCCViewer") {
3432 #ifndef DISABLE_OCCVIEWER
3433 // specific processing for OCC viewer:
3434 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3435 // - if there is only one sub-view active; it will be resized;
3436 // - if there are several sub-views, each of them will be resized.
3437 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3438 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3439 if ( occView && occView->getView( i ) ) {
3440 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
3444 #endif // DISABLE_OCCVIEWER
3446 else if ( type == "ParaView") {
3447 #ifndef DISABLE_PVVIEWER
3448 // specific processing for ParaView viewer:
3449 // hierarchy of ParaView viewer is much complex than for usual view;
3450 // we look for sub-widget named "Viewport"
3451 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3452 if ( !lst.isEmpty() ) {
3453 lst[0]->resize( myWndWidth, myWndHeight );
3456 #endif // DISABLE_PVVIEWER
3458 else if ( type == "ParaView3D") {
3459 #ifndef DISABLE_PV3DVIEWER
3460 // specific processing for ParaView3D viewer:
3461 // hierarchy of ParaView3D viewer is much more complex than for usual view;
3462 // we look for sub-widget named "Viewport"
3463 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
3464 if ( !lst.isEmpty() ) {
3465 lst[0]->resize( myWndWidth, myWndHeight );
3468 #endif // DISABLE_PV3DVIEWER
3471 if ( wnd->centralWidget() ) {
3472 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
3480 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
3482 return ProcessEvent( new TSetViewSize( w, h, id ) );
3486 \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
3487 \brief Set view rotation point
3488 \param x coordinate X view rotation point
3489 \param y coordinate Y view rotation point
3490 \param z coordinate Z view rotation point
3491 \param id window identifier
3492 \return \c true if operation is completed successfully and \c false otherwise
3495 class TSetViewRotationPoint: public SALOME_Event
3498 typedef bool TResult;
3504 TSetViewRotationPoint( const double x, const double y, const double z, const int id )
3505 : myResult( false ),
3510 virtual void Execute()
3512 SUIT_ViewWindow* wnd = 0;
3514 if ( LightApp_Application* anApp = getApplication() ) {
3515 SUIT_ViewManager* vm = anApp->activeViewManager();
3517 wnd = vm->getActiveView();
3521 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
3524 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3526 QString type = viewMgr->getType();
3527 if ( type == "OCCViewer") {
3528 #ifndef DISABLE_OCCVIEWER
3529 // specific processing for OCC viewer:
3530 // OCC view can embed up to 4 sub-views, split according to the specified layout;
3531 // - if there is only one sub-view active; its rotation point will be changed;
3532 // - if there are several sub-views, rotaion points of each of them will be changed.
3533 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
3535 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
3536 if ( occView && occView->getView( i ) ) {
3537 occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
3542 #endif // DISABLE_OCCVIEWER
3544 else if ( type == "VTKViewer") {
3545 #ifndef DISABLE_VTKVIEWER
3546 SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
3549 double aCenter[3] = { myX, myY, myZ };
3550 vtkView->activateSetRotationSelected( (void*)aCenter );
3553 #endif // DISABLE_VTKVIEWER
3559 bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
3561 return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
3565 \fn QString SalomePyQt::getViewTitle( const int id );
3566 \brief Get view caption
3567 \param id window identifier
3568 \return view caption
3571 class TGetViewTitle: public SALOME_Event
3574 typedef QString TResult;
3577 TGetViewTitle( const int id )
3579 virtual void Execute()
3581 SUIT_ViewWindow* wnd = getWnd( myWndId );
3583 myResult = wnd->windowTitle();
3586 QString SalomePyQt::getViewTitle( const int id )
3588 return ProcessEvent( new TGetViewTitle( id ) );
3592 \fn QList<int> SalomePyQt::findViews( const QString& type );
3593 \brief Get list of integer identifiers of all the
3594 currently opened views of the specified type
3595 \param type viewer type
3596 \return list of integer identifiers
3599 class TFindViews: public SALOME_Event
3602 typedef QList<int> TResult;
3605 TFindViews( const QString& type )
3607 virtual void Execute()
3610 LightApp_Application* app = getApplication();
3612 ViewManagerList vmList;
3613 app->viewManagers( myType, vmList );
3614 SUIT_ViewManager* viewMgr;
3615 foreach ( viewMgr, vmList ) {
3616 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
3617 for ( int i = 0, n = vec.size(); i < n; i++ ) {
3618 SUIT_ViewWindow* wnd = vec[ i ];
3621 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
3622 myResult.append( wnd->getId() );
3629 QList<int> SalomePyQt::findViews( const QString& type )
3631 return ProcessEvent( new TFindViews( type ) );
3635 \fn bool SalomePyQt::activateView( const int id );
3636 \brief Activate view
3637 \param id window identifier
3638 \return \c true if operation is completed successfully and \c false otherwise
3641 class TActivateView: public SALOME_Event
3644 typedef bool TResult;
3647 TActivateView( const int id )
3648 : myResult( false ),
3650 virtual void Execute()
3652 SUIT_ViewWindow* wnd = getWnd( myWndId );
3653 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3655 Activator activator;
3661 bool SalomePyQt::activateView( const int id )
3663 return ProcessEvent( new TActivateView( id ) );
3667 \fn bool SalomePyQt::activateManagerAndView( const int id );
3668 \brief Activate view manager and view: useful for a view embedded in a module main Window
3669 \param id window identifier
3670 \return \c true if operation is completed successfully and \c false otherwise
3673 class TActivateViewManagerAndView: public SALOME_Event
3676 typedef bool TResult;
3679 TActivateViewManagerAndView( const int id )
3680 : myResult( false ),
3682 virtual void Execute()
3684 SUIT_ViewWindow* wnd = getWnd( myWndId );
3685 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
3688 LightApp_Application* app = getApplication();
3689 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
3695 bool SalomePyQt::activateViewManagerAndView( const int id )
3697 return ProcessEvent( new TActivateViewManagerAndView( id ) );
3704 class TGetViewWidget: public SALOME_Event
3707 typedef QWidget* TResult;
3710 TGetViewWidget( const int id )
3713 virtual void Execute()
3715 SUIT_ViewWindow* wnd = getWnd( myWndId );
3717 myResult = (QWidget*)wnd;
3721 QWidget* SalomePyQt::getViewWidget( const int id)
3723 return ProcessEvent( new TGetViewWidget( id ) );
3728 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
3729 \brief Create new view and activate it
3730 \param type viewer type
3734 \return integer identifier of created view (or -1 if view could not be created)
3737 class TCreateView: public SALOME_Event
3740 typedef int TResult;
3747 TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
3753 myDetached(detached) {}
3754 virtual void Execute()
3756 LightApp_Application* app = getApplication();
3758 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
3760 QWidget* wnd = viewMgr->getActiveView();
3761 myResult = viewMgr->getActiveView()->getId();
3764 wnd->setVisible(false);
3765 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
3769 if (myWidth > 0 && myHeight > 0) {
3770 #ifndef DISABLE_PLOT2DVIEWER
3771 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3772 if ( wnd2D ) wnd = wnd2D->getViewFrame();
3773 #endif // DISABLE_PLOT2DVIEWER
3774 wnd->setGeometry( 0, 0, myWidth, myHeight );
3781 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
3783 int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
3784 QCoreApplication::processEvents();
3789 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3790 \brief Create new view with custom widget embedded and activate it
3791 \param type viewer type
3792 \param w custom widget
3793 \return integer identifier of created view (or -1 if view could not be created)
3796 class TCreateViewWg: public SALOME_Event
3799 typedef int TResult;
3803 TCreateViewWg( const QString& theType, QWidget* w )
3807 virtual void Execute()
3809 LightApp_Application* app = getApplication();
3811 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3813 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3815 myResult = wnd->getId();
3820 int SalomePyQt::createView( const QString& type, QWidget* w )
3822 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3823 QCoreApplication::processEvents();
3828 \fn bool SalomePyQt::closeView( const int id );
3830 \param id window identifier
3831 \return \c true if operation is completed successfully and \c false otherwise
3834 class TCloseView: public SALOME_Event
3837 typedef bool TResult;
3840 TCloseView( const int id )
3841 : myResult( false ),
3843 virtual void Execute()
3845 SUIT_ViewWindow* wnd = getWnd( myWndId );
3847 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3855 bool SalomePyQt::closeView( const int id )
3857 return ProcessEvent( new TCloseView( id ) );
3861 \fn int SalomePyQt::cloneView( const int id );
3862 \brief Clone view (if this operation is supported for specified view type)
3863 \param id window identifier
3864 \return integer identifier of the cloned view or -1 or operation could not be performed
3867 class TCloneView: public SALOME_Event
3870 typedef int TResult;
3873 TCloneView( const int id )
3876 virtual void Execute()
3878 SUIT_ViewWindow* wnd = getWnd( myWndId );
3880 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3882 #ifndef DISABLE_OCCVIEWER
3883 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3884 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3885 occView->onCloneView();
3886 wnd = viewMgr->getActiveView();
3888 myResult = wnd->getId();
3890 #endif // DISABLE_OCCVIEWER
3891 #ifndef DISABLE_PLOT2DVIEWER
3892 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3893 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3894 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3895 if ( viewMgr2d && srcWnd2d ) {
3896 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3897 myResult = resWnd->getId();
3900 #endif // DISABLE_OCCVIEWER
3905 int SalomePyQt::cloneView( const int id )
3907 return ProcessEvent( new TCloneView( id ) );
3911 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3912 \brief Set view visibility.
3913 \param id window identifier
3914 \param visible new visiblity
3917 void SalomePyQt::setViewVisible( const int id, const bool visible )
3919 class TEvent: public SALOME_Event
3924 TEvent( const int id, const bool visible )
3925 : myWndId( id ), myVisible( visible ) {}
3926 virtual void Execute()
3928 SUIT_ViewWindow* wnd = getWnd( myWndId );
3929 if ( wnd ) wnd->setVisible( myVisible );
3932 ProcessVoidEvent( new TEvent( id, visible ) );
3936 \fn bool SalomePyQt::isViewVisible( const int id );
3937 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3938 \param id window identifier
3939 \return \c true if view is visible and \c false otherwise
3942 class TIsViewVisible: public SALOME_Event
3945 typedef bool TResult;
3948 TIsViewVisible( const int id )
3949 : myResult( false ),
3951 virtual void Execute()
3953 SUIT_ViewWindow* wnd = getWnd( myWndId );
3956 QWidget* p = wnd->parentWidget();
3957 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3961 bool SalomePyQt::isViewVisible( const int id )
3963 return ProcessEvent( new TIsViewVisible( id ) );
3967 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3968 \brief Set / clear view's "closable" option. By default any view is closable
3969 (i.e. can be closed by the user).
3970 \param id window identifier
3971 \param on new "closable" option's value
3974 void SalomePyQt::setViewClosable( const int id, const bool on )
3976 class TEvent: public SALOME_Event
3981 TEvent( const int id, const bool on )
3982 : myWndId( id ), myOn( on ) {}
3983 virtual void Execute()
3985 SUIT_ViewWindow* wnd = getWnd( myWndId );
3986 if ( wnd ) wnd->setClosable( myOn );
3989 ProcessVoidEvent( new TEvent( id, on ) );
3993 \fn bool SalomePyQt::isViewClosable( const int id );
3994 \brief Check whether view is closable (i.e. can be closed by the user)
3995 \param id window identifier
3996 \return \c true if view is closable or \c false otherwise
3999 class TIsViewClosable: public SALOME_Event
4002 typedef bool TResult;
4005 TIsViewClosable( const int id )
4008 virtual void Execute()
4010 SUIT_ViewWindow* wnd = getWnd( myWndId );
4012 myResult = wnd->closable();
4016 bool SalomePyQt::isViewClosable( const int id )
4018 return ProcessEvent( new TIsViewClosable( id ) );
4022 \fn bool SalomePyQt::groupAllViews();
4023 \brief Group all views to the single tab area
4024 \return \c true if operation is completed successfully and \c false otherwise
4027 class TGroupAllViews: public SALOME_Event
4030 typedef bool TResult;
4033 : myResult( false ) {}
4034 virtual void Execute()
4036 LightApp_Application* app = getApplication();
4038 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4040 QtxWorkstack* wStack = tabDesk->workstack();
4049 bool SalomePyQt::groupAllViews()
4051 return ProcessEvent( new TGroupAllViews() );
4055 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
4056 \brief Split tab area to which view with identifier belongs to
4057 \param id window identifier
4058 \param ori orientation of split operation
4059 \param action action to be performed
4060 \return \c true if operation is completed successfully \c false otherwise
4063 class TSplitView: public SALOME_Event
4066 typedef bool TResult;
4071 TSplitView( const int id,
4072 const Orientation ori,
4073 const Action action )
4074 : myResult( false ),
4077 myAction( action ) {}
4078 virtual void Execute()
4080 SUIT_ViewWindow* wnd = getWnd( myWndId );
4083 // wnd->setFocus(); ???
4086 if ( getApplication() ) {
4087 STD_TabDesktop* desk =
4088 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
4090 QtxWorkstack* wStack = desk->workstack();
4092 Qt::Orientation qtOri =
4093 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
4095 QtxWorkstack::SplitType sType;
4096 if ( myAction == MoveWidget )
4097 sType = QtxWorkstack::SplitMove;
4098 else if ( myAction == LeaveWidget )
4099 sType = QtxWorkstack::SplitStay;
4101 sType = QtxWorkstack::SplitAt;
4103 wStack->Split( wnd, qtOri, sType );
4111 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
4113 return ProcessEvent( new TSplitView( id, ori, action ) );
4117 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
4118 \brief Move view with the first identifier to the same area which
4119 another view with the second identifier belongs to
4120 \param id source window identifier
4121 \param id_to destination window identifier
4122 param before specifies whether the first viewt has to be moved before or after
4124 \return \c true if operation is completed successfully and \c false otherwise
4127 class TMoveView: public SALOME_Event
4130 typedef bool TResult;
4135 TMoveView( const int id, const int id_to, const bool before )
4136 : myResult( false ),
4139 myIsBefore( before ) {}
4140 virtual void Execute()
4142 SUIT_ViewWindow* wnd = getWnd( myWndId );
4143 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
4144 if ( wnd && wnd_to ) {
4145 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
4146 getApplication()->desktop() )->workstack();
4148 myResult = wStack->move( wnd, wnd_to, myIsBefore );
4152 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
4154 return ProcessEvent( new TMoveView( id, id_to, before ) );
4158 \fn QList<int> SalomePyQt::neighbourViews( const int id );
4159 \brief Get list of views identifiers that belongs to the same area as
4160 specified view (excluding it)
4161 \param id window identifier
4162 \return list of views identifiers
4165 class TNeighbourViews: public SALOME_Event
4168 typedef QList<int> TResult;
4171 TNeighbourViews( const int id )
4173 virtual void Execute()
4176 SUIT_ViewWindow* wnd = getWnd( myWndId );
4178 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
4179 getApplication()->desktop() )->workstack();
4181 QWidgetList wgList = wStack->windowList( wnd );
4183 foreach ( wg, wgList ) {
4184 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
4185 if ( tmpWnd && tmpWnd != wnd )
4186 myResult.append( tmpWnd->getId() );
4192 QList<int> SalomePyQt::neighbourViews( const int id )
4194 return ProcessEvent( new TNeighbourViews( id ) );
4199 \fn void SalomePyQt::createRoot();
4200 \brief Initialize root data object.
4202 Does nothing if root is already initialized.
4205 void SalomePyQt::createRoot()
4207 class TEvent: public SALOME_Event
4211 virtual void Execute()
4213 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4215 SALOME_PYQT_DataModelLight* dm =
4216 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
4221 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
4225 ProcessVoidEvent( new TEvent() );
4229 \fn QString SalomePyQt::createObject( const QString& parent );
4230 \brief Create empty data object
4231 \param parent entry of parent data object
4232 \return entry of created data object
4235 class TCreateEmptyObjectEvent: public SALOME_Event
4238 typedef QString TResult;
4241 TCreateEmptyObjectEvent( const QString& parent )
4242 : myParent( parent ) {}
4243 virtual void Execute()
4245 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4247 myResult = module->createObject( myParent );
4250 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
4254 QString SalomePyQt::createObject( const QString& parent )
4256 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
4260 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
4261 const QString& tooltip,const QString& parent );
4262 \brief Create new data object with specified name, icon and tooltip
4263 \param name data object name
4264 \param icon data object icon
4265 \param toolTip data object tooltip
4266 \param parent entry of parent data object
4267 \return entry of created data object
4270 class TCreateObjectEvent: public SALOME_Event
4273 typedef QString TResult;
4279 TCreateObjectEvent( const QString& name,
4280 const QString& icon,
4281 const QString& tooltip,
4282 const QString& parent )
4283 : myParent( parent ),
4286 myToolTip( tooltip ) {}
4287 virtual void Execute()
4289 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4291 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
4294 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
4298 QString SalomePyQt::createObject( const QString& name,
4299 const QString& icon,
4300 const QString& toolTip,
4301 const QString& parent )
4303 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
4308 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
4309 \brief Set data object name
4310 \param entry data object entry
4311 \param name data object name
4313 class TSetNameEvent: public SALOME_Event
4318 TSetNameEvent( const QString& entry,
4319 const QString& name )
4322 virtual void Execute()
4324 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4326 module->setName( myEntry, myName );
4329 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
4333 void SalomePyQt::setName( const QString& entry, const QString& name )
4335 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
4339 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
4340 \brief Set data object icon
4341 \param entry data object entry
4342 \param icon data object icon file name (icon is loaded from module resources)
4345 class TSetIconEvent: public SALOME_Event
4350 TSetIconEvent( const QString& entry,
4351 const QString& icon )
4354 virtual void Execute()
4356 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4358 module->setIcon( myEntry, myIcon );
4361 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
4366 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
4368 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
4372 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
4373 \brief Set data object tooltip
4374 \param entry data object entry
4375 \param toolTip data object tooltip
4378 class TSetToolTipEvent: public SALOME_Event
4383 TSetToolTipEvent( const QString& entry,
4384 const QString& toolTip )
4386 myToolTip( toolTip ) {}
4387 virtual void Execute()
4389 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4391 module->setToolTip( myEntry, myToolTip );
4394 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
4398 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
4400 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
4404 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
4405 \brief Set reference to another data object
4406 \param entry data object entry
4407 \param refEntry referenced data object entry
4410 class TSetRefEvent: public SALOME_Event
4415 TSetRefEvent( const QString& entry,
4416 const QString& refEntry )
4418 myRefEntry( refEntry ) {}
4419 virtual void Execute()
4421 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4423 module->setReference( myEntry, myRefEntry );
4426 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
4430 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
4432 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
4436 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
4437 \brief Set data object color
4438 \param entry data object entry
4439 \param color data object color
4442 class TSetColorEvent: public SALOME_Event
4447 TSetColorEvent( const QString& entry,
4448 const QColor& color )
4451 virtual void Execute()
4453 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4455 module->setColor( myEntry, myColor );
4458 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
4462 void SalomePyQt::setColor( const QString& entry, const QColor& color )
4464 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
4468 \fn QString SalomePyQt::getName( const QString& entry );
4469 \brief Get data object name
4470 \param entry data object entry
4471 \return data object name
4474 class TGetNameEvent: public SALOME_Event
4477 typedef QString TResult;
4480 TGetNameEvent( const QString& entry )
4481 : myEntry( entry ) {}
4482 virtual void Execute()
4484 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4486 myResult = module->getName( myEntry );
4489 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
4493 QString SalomePyQt::getName( const QString& entry )
4495 return ProcessEvent( new TGetNameEvent( entry ) );
4499 \fn QString SalomePyQt::getToolTip( const QString& entry );
4500 \brief Get data object tooltip
4501 \param entry data object entry
4502 \return data object tooltip
4505 class TGetToolTipEvent: public SALOME_Event
4508 typedef QString TResult;
4511 TGetToolTipEvent( const QString& entry )
4512 : myEntry( entry ) {}
4513 virtual void Execute()
4515 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4517 myResult = module->getToolTip( myEntry );
4520 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
4524 QString SalomePyQt::getToolTip( const QString& entry )
4526 return ProcessEvent( new TGetToolTipEvent( entry ) );
4530 \fn QString SalomePyQt::getReference( const QString& entry );
4531 \brief Get entry of the referenced object (if there's any)
4532 \param entry data object entry
4533 \return referenced data object entry
4536 class TGetRefEvent: public SALOME_Event
4539 typedef QString TResult;
4542 TGetRefEvent( const QString& entry )
4543 : myEntry( entry ) {}
4544 virtual void Execute()
4546 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4548 myResult = module->getReference( myEntry );
4551 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
4555 QString SalomePyQt::getReference( const QString& entry )
4557 return ProcessEvent( new TGetRefEvent( entry ) );
4561 \fn QColor SalomePyQt::getColor( const QString& entry );
4562 \brief Get data object color
4563 \param entry data object entry
4564 \return data object color
4567 class TGetColorEvent: public SALOME_Event
4570 typedef QColor TResult;
4573 TGetColorEvent( const QString& entry )
4574 : myEntry( entry ) {}
4575 virtual void Execute()
4577 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4579 myResult = module->getColor( myEntry );
4582 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
4586 QColor SalomePyQt::getColor( const QString& entry )
4588 return ProcessEvent( new TGetColorEvent( entry ) );
4592 \fn void SalomePyQt::removeChildren( const QString& entry );
4593 \brief Remove all child data objects from specified data object
4594 \param entry data object entry
4597 class TRemoveChildEvent: public SALOME_Event
4601 TRemoveChildEvent( const QString& entry )
4602 : myEntry( entry ) {}
4603 virtual void Execute()
4605 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4607 module->removeChildren( myEntry );
4610 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
4614 void SalomePyQt::removeChildren( const QString& entry )
4616 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
4618 void SalomePyQt::removeChild( const QString& entry )
4620 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
4621 removeChildren( entry );
4625 \fn void SalomePyQt::removeObject( const QString& entry );
4626 \brief Remove object by entry
4627 \param entry data object entry
4630 class TRemoveObjectEvent: public SALOME_Event
4635 TRemoveObjectEvent( const QString& entry )
4636 : myEntry( entry ) {}
4637 virtual void Execute()
4639 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4641 module->removeObject( myEntry );
4644 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
4648 void SalomePyQt::removeObject( const QString& entry )
4650 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
4654 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
4655 \brief Get entries of all child data objects of specified data object
4656 \param entry data object entry
4657 \param recursive \c true for recursive processing
4660 class TGetChildrenEvent: public SALOME_Event
4663 typedef QStringList TResult;
4667 TGetChildrenEvent( const QString& entry, const bool recursive )
4669 myRecursive( recursive ) {}
4670 virtual void Execute()
4672 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4674 myResult = module->getChildren( myEntry, myRecursive );
4677 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
4681 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
4683 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
4686 #ifndef DISABLE_PLOT2DVIEWER
4687 // Next set of methods relates to the Plot2d viewer functionality
4690 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4691 \brief Display theCurve in view
4692 \param id window identifier
4693 \param theCurve curve to display
4696 class TDisplayCurve: public SALOME_Event
4700 Plot2d_Curve* myCurve;
4701 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4702 virtual void Execute() {
4703 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4705 wnd->getViewFrame()->displayCurve( myCurve );
4708 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
4710 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
4714 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4715 \brief Erase theCurve in view
4716 \param id window identifier
4717 \param theCurve curve to erase
4720 class TEraseCurve: public SALOME_Event
4724 Plot2d_Curve* myCurve;
4725 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
4726 virtual void Execute() {
4727 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4728 wnd->getViewFrame()->eraseCurve( myCurve );
4731 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
4733 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
4737 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
4738 \brief Delete theCurve from all views
4739 \param theCurve curve to delete
4742 class TDeleteCurve: public SALOME_Event
4745 Plot2d_Curve* myCurve;
4746 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
4747 virtual void Execute() {
4748 LightApp_Application* app = getApplication();
4750 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
4752 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
4753 SUIT_ViewWindow* wnd;
4754 foreach ( wnd, wndlist ) {
4755 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
4757 aP2d->getViewFrame()->eraseObject( myCurve );
4763 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
4765 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
4769 \brief updateCurves (repaint) curves in view window.
4771 void SalomePyQt::updateCurves( const int id )
4773 class TEvent: public SALOME_Event
4777 TEvent( const int id ) : myWndId( id ) {}
4778 virtual void Execute()
4780 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4782 wnd->getViewFrame()->DisplayAll();
4785 ProcessVoidEvent( new TEvent( id ) );
4789 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4790 \brief Get title of corresponding type
4791 \param id window identifier
4792 \param type is type of title
4793 \return title of corresponding type
4796 class TGetPlot2dTitle: public SALOME_Event
4799 typedef QString TResult;
4803 TGetPlot2dTitle(const int id, ObjectType type) :
4806 virtual void Execute() {
4807 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4809 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4812 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4814 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4819 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4820 \brief Set title of corresponding type
4821 \param id window identifier
4823 \param type is type of title
4827 class TSetPlot2dTitle: public SALOME_Event
4831 Plot2d_Curve* myCurve;
4835 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4840 virtual void Execute() {
4841 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4842 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4845 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4847 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4851 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4852 \brief Get list of Plot2d view ranges
4853 \param id window identifier
4854 \return list of view ranges (XMin, XMax, YMin, YMax)
4857 class TFitRangeByCurves: public SALOME_Event
4860 typedef QList<double> TResult;
4863 TFitRangeByCurves( const int id )
4865 virtual void Execute()
4868 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4870 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4871 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4872 myResult.append( XMin );
4873 myResult.append( XMax );
4874 myResult.append( YMin );
4875 myResult.append( YMax );
4879 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4881 return ProcessEvent( new TFitRangeByCurves( id ) );
4885 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4886 \brief Get list of current Plot2d view ranges
4887 \param id window identifier
4888 \return list of view ranges (XMin, XMax, YMin, YMax)
4891 class TFitRangeCurrent: public SALOME_Event
4894 typedef QList<double> TResult;
4897 TFitRangeCurrent( const int id )
4899 virtual void Execute()
4902 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4904 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4905 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4906 myResult.append( XMin );
4907 myResult.append( XMax );
4908 myResult.append( YMin );
4909 myResult.append( YMax );
4913 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4915 return ProcessEvent( new TFitRangeCurrent( id ) );
4919 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4920 \brief Set range of Plot2d view
4921 \param id window identifier
4928 class TPlot2dFitRange: public SALOME_Event
4936 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4942 virtual void Execute() {
4943 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4945 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4948 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4950 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4953 // End of methods related to the Plot2d viewer functionality
4954 #endif // DISABLE_PLOT2DVIEWER
4957 \brief Process Qt event loop
4959 void SalomePyQt::processEvents()
4961 QCoreApplication::processEvents();
4965 \brief Set visibility state for given object
4966 \param theEntry study ID of the object
4967 \param theState visibility state
4969 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4971 class TEvent: public SALOME_Event
4976 TEvent( const QString& theEntry, int theState ):
4977 myEntry( theEntry ), myState( theState ) {}
4978 virtual void Execute()
4980 LightApp_Study* aStudy = getActiveStudy();
4983 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4986 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4990 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4991 \brief Get visibility state for given object
4992 \param theEntry study ID of the object
4993 \return visibility state
4996 class TGetVisibilityStateEvent: public SALOME_Event
4999 typedef int TResult;
5002 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
5003 virtual void Execute()
5005 LightApp_Study* aStudy = getActiveStudy();
5007 myResult = aStudy->visibilityState( myEntry );
5010 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
5012 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
5016 \brief Set position of given object in the tree
5017 \param theEntry study ID of the object
5018 \param thePos position
5020 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
5022 class TEvent: public SALOME_Event
5027 TEvent( const QString& theEntry, int thePos ):
5028 myEntry( theEntry ), myPos( thePos ) {}
5029 virtual void Execute()
5031 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
5033 module->setObjectPosition( myEntry, myPos );
5036 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
5040 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
5041 \brief Get position of given object in the tree
5042 \param theEntry study ID of the object
5046 class TGetObjectPositionEvent: public SALOME_Event
5049 typedef int TResult;
5052 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
5053 virtual void Execute()
5055 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
5057 myResult = module->getObjectPosition( myEntry );
5060 int SalomePyQt::getObjectPosition( const QString& theEntry )
5062 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
5066 \brief Start recordind a log of Python commands from embedded console
5067 \param theFileName output lof file name
5069 void SalomePyQt::startPyLog( const QString& theFileName )
5071 class TEvent: public SALOME_Event
5075 TEvent( const QString& theFileName ):
5076 myFileName( theFileName ) {}
5077 virtual void Execute()
5079 if ( getApplication() ) {
5080 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
5081 if ( pyConsole ) pyConsole->startLog( myFileName );
5085 ProcessVoidEvent( new TEvent( theFileName ) );
5089 \brief Stop recordind a log of Python commands from embedded console
5091 void SalomePyQt::stopPyLog()
5093 class TEvent: public SALOME_Event
5097 virtual void Execute()
5099 if ( getApplication() ) {
5100 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
5101 if ( pyConsole ) pyConsole->stopLog();
5105 ProcessVoidEvent( new TEvent() );
5109 \brief Log GUI event.
5110 \param eventDescription GUI event description.
5112 void SalomePyQt::logUserEvent( const QString& eventDescription )
5114 class TEvent: public SALOME_Event
5116 QString myEventDescription;
5118 TEvent( const QString& theDescription ) : myEventDescription( theDescription ) {}
5119 virtual void Execute()
5121 LightApp_Application::logUserEvent( myEventDescription );
5124 ProcessVoidEvent( new TEvent( eventDescription ) );
5128 \brief Log given action.
5129 \param action GUI action being logged.
5130 \param moduleName optional name of module, owning an action
5132 void SalomePyQt::logAction( QAction* action, const QString& moduleName )
5134 class TEvent: public SALOME_Event
5137 QString myModuleName;
5139 TEvent( QAction* theAction, const QString& theModuleName ) : myAction( theAction ), myModuleName( theModuleName ) {}
5140 virtual void Execute()
5142 LightApp_Application::logAction( myAction, myModuleName );
5145 ProcessVoidEvent( new TEvent( action, moduleName ) );
5149 \brief Enable/disable action logging.
5151 void SalomePyQt::setActionLoggingEnabled( bool enabled )
5153 class TEvent: public SALOME_Event
5157 TEvent( bool theEnabled ) : myEnabled( theEnabled ) {}
5158 virtual void Execute()
5160 LightApp_Module* module = getActiveModule();
5162 module->setActionLoggingEnabled( myEnabled );
5165 ProcessVoidEvent( new TEvent( enabled ) );