1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SalomePyQt.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 // E.A. : On windows with python 2.6, there is a conflict
28 // E.A. : between pymath.h and Standard_math.h which define
29 // E.A. : some same symbols : acosh, asinh, ...
30 #include <Standard_math.hxx>
34 #include "SALOME_PYQT_ModuleLight.h" // this include must be first!!!
35 #include "SALOME_PYQT_DataModelLight.h"
36 #include "SALOME_PYQT_PyModule.h"
37 #include "SalomePyQt.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "LogWindow.h"
41 #ifndef DISABLE_OCCVIEWER
42 #include "OCCViewer_ViewWindow.h"
43 #include "OCCViewer_ViewFrame.h"
44 #endif // DISABLE_OCCVIEWER
45 #ifndef DISABLE_PLOT2DVIEWER
46 #include "Plot2d_ViewManager.h"
47 #include "Plot2d_ViewWindow.h"
48 #endif // DISABLE_PLOT2DVIEWER
49 #ifndef DISABLE_PVVIEWER
50 #include "PVViewer_ViewManager.h"
51 #include "PVViewer_ViewModel.h"
52 #endif // DISABLE_PVVIEWER
53 #include "QtxActionMenuMgr.h"
54 #include "QtxWorkstack.h"
55 #include "QtxTreeView.h"
56 #include "SALOME_Event.h"
57 #include "STD_TabDesktop.h"
58 #include "SUIT_DataBrowser.h"
59 #include "SUIT_ResourceMgr.h"
60 #include "SUIT_Session.h"
61 #include "SUIT_Tools.h"
62 #include "SUIT_ViewManager.h"
63 #include "SUIT_ViewWindow.h"
64 #include "PyConsole_Console.h"
67 #include <QApplication>
68 #include <QPaintEvent>
69 #include <QCoreApplication>
71 #include <utilities.h>
75 \brief Get the currently active application.
77 \return active application object or 0 if there is no any
79 LightApp_Application* getApplication()
81 if ( SUIT_Session::session() )
82 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
87 \brief Get the currently active study.
89 \return active study or 0 if there is no study opened
91 LightApp_Study* getActiveStudy()
93 if ( getApplication() )
94 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
99 \brief Get the currently active module.
101 This function returns correct result only if Python-based
102 module is currently active. Otherwize, 0 is returned.
104 LightApp_Module* getActiveModule()
106 LightApp_Module* module = 0;
107 if ( LightApp_Application* anApp = getApplication() ) {
108 module = PyModuleHelper::getInitModule();
110 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
116 \brief Get the currently active Python module's helper.
118 This function returns correct result only if Python-based
119 module is currently active. Otherwize, 0 is returned.
121 PyModuleHelper* getPythonHelper()
123 LightApp_Module* module = getActiveModule();
124 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
129 \brief Get SALOME verbose level
131 \return \c true if SALOME debug output is allowed or \c false otherwise
135 bool isVerbose = false;
136 if ( getenv( "SALOME_VERBOSE" ) ) {
137 QString envVar = getenv( "SALOME_VERBOSE" );
139 int value = envVar.toInt( &ok );
140 isVerbose = ok && value != 0;
146 \brief Get menu item title
148 \param menuId menu identifier
149 \return menu title (localized)
151 QString getMenuName( const QString& menuId )
153 QStringList contexts;
154 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
155 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
156 QString menuName = menuId;
157 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
158 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
163 \brief Load module icon
165 \param module module name
166 \param fileName path to the icon file
169 QIcon loadIconInternal( const QString& module, const QString& fileName )
173 LightApp_Application* app = getApplication();
175 if ( app && !fileName.isEmpty() ) {
176 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
177 QApplication::translate( module.toLatin1().data(),
178 fileName.toLatin1().data() ) );
179 if ( !pixmap.isNull() )
180 icon = QIcon( pixmap );
186 \brief Gets window with specified identifier
188 \param id window identifier
189 \return pointer on the window
191 SUIT_ViewWindow* getWnd( const int id )
193 SUIT_ViewWindow* resWnd = 0;
195 LightApp_Application* app = getApplication();
197 ViewManagerList vmlist = app->viewManagers();
198 foreach( SUIT_ViewManager* vm, vmlist ) {
199 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
200 foreach ( SUIT_ViewWindow* vw, vwlist ) {
201 if ( id == vw->getId() ) {
212 \brief Map of created selection objects.
215 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
218 \brief Default resource file section name.
221 const char* DEFAULT_SECTION = "SalomePyQt";
225 \class SALOME_Selection
226 \brief The class represents selection which can be used in Python.
230 \brief Get the selection object for the specified application.
232 Finds or creates the selection object (one per study).
234 \param app application object
235 \return selection object or 0 if \a app is invalid
237 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
239 SALOME_Selection* sel = 0;
240 if ( app && SelMap.find( app ) != SelMap.end() )
243 sel = SelMap[ app ] = new SALOME_Selection( app );
249 \param p parent object
251 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
253 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
255 mySelMgr = app->selectionMgr();
256 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
257 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
264 SALOME_Selection::~SALOME_Selection()
266 LightApp_Application* app = 0;
267 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
268 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
269 if ( it.value() == this ) app = it.key();
271 if ( app ) SelMap.remove( app );
275 \brief Called when selection manager is destroyed (usually
276 when the study is closed).
278 void SALOME_Selection::onSelMgrDestroyed()
284 \brief Clear the selection.
286 void SALOME_Selection::Clear()
288 class TEvent: public SALOME_Event
290 LightApp_SelectionMgr* mySelMgr;
292 TEvent( LightApp_SelectionMgr* selMgr )
293 : mySelMgr( selMgr ) {}
294 virtual void Execute()
297 mySelMgr->clearSelected();
300 ProcessVoidEvent( new TEvent( mySelMgr ) );
304 \brief Clear the selection.
306 void SALOME_Selection::ClearIObjects()
312 Removes all selection filters.
314 void SALOME_Selection::ClearFilters()
316 class TEvent: public SALOME_Event
318 LightApp_SelectionMgr* mySelMgr;
320 TEvent( LightApp_SelectionMgr* selMgr )
321 : mySelMgr( selMgr ) {}
322 virtual void Execute()
325 mySelMgr->clearFilters();
328 ProcessVoidEvent( new TEvent( mySelMgr ) );
333 \brief The class provides utility functions which can be used in the Python
334 to operate with the SALOME GUI.
336 All the functionality of this class is implemented as static methods, so they
337 can be called with the class name prefixed or via creation of the class instance.
338 For example, next both ways of SalomePyQt class usage are legal:
340 from SalomePyQt import *
342 # using SalomePyQt class instance
343 desktop = sg.getDesktop()
344 # using SalomePyQt class directly
345 menubar = SalomePyQt.getMainMenuBar()
350 \fn QWidget* SalomePyQt::getDesktop();
351 \brief Get the active application's desktop window.
352 \return desktop window or 0 if there is no any
355 class TGetDesktopEvent: public SALOME_Event
358 typedef QWidget* TResult;
360 TGetDesktopEvent() : myResult( 0 ) {}
361 virtual void Execute()
363 if ( getApplication() )
364 myResult = (QWidget*)( getApplication()->desktop() );
367 QWidget* SalomePyQt::getDesktop()
369 return ProcessEvent( new TGetDesktopEvent() );
373 \fn QWidget* SalomePyQt::getMainFrame();
374 \brief Get current application's main frame widget [obsolete].
376 Main frame widget is an internal widget of the application
377 desktop window (workspace).
379 \return workspace widget (0 on any error)
382 class TGetMainFrameEvent: public SALOME_Event
385 typedef QWidget* TResult;
387 TGetMainFrameEvent() : myResult( 0 ) {}
388 virtual void Execute()
390 if ( getApplication() ) {
391 SUIT_Desktop* aDesktop = getApplication()->desktop();
392 myResult = (QWidget*)( aDesktop->centralWidget() );
396 QWidget* SalomePyQt::getMainFrame()
398 return ProcessEvent( new TGetMainFrameEvent() );
402 \fn QMenuBar* SalomePyQt::getMainMenuBar();
403 \brief Get current application desktop's main menu.
404 \return main menu object (0 on any error)
407 class TGetMainMenuBarEvent: public SALOME_Event
410 typedef QMenuBar* TResult;
412 TGetMainMenuBarEvent() : myResult( 0 ) {}
413 virtual void Execute()
415 if ( LightApp_Application* anApp = getApplication() ) {
416 myResult = anApp->desktop()->menuBar();
420 QMenuBar* SalomePyQt::getMainMenuBar()
422 return ProcessEvent( new TGetMainMenuBarEvent() );
426 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
427 \brief Get main menu's child popup submenu by its identifier.
429 This function is obsolete.
430 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
432 \param menu menu identifier
433 \return popup submenu object or 0 if it does not exist
437 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
438 \brief Get main menu's child popup submenu by its name.
440 The function creates menu if it does not exist.
442 \param menu menu name
443 \return popup submenu object (0 on any error)
446 class TGetPopupMenuEvent: public SALOME_Event
449 typedef QMenu* TResult;
452 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
453 virtual void Execute()
455 LightApp_Application* anApp = getApplication();
456 if ( anApp && !myMenuName.isEmpty() ) {
457 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
458 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
463 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
468 menuName = getMenuName( "MEN_DESK_FILE" ); break;
470 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
472 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
474 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
476 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
478 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
480 menuName = getMenuName( "MEN_DESK_HELP" ); break;
482 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
484 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
486 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
490 \fn QTreeView* SalomePyQt::getObjectBrowser();
491 \brief Get object browser
492 \return object browser for the active study or 0 in case of error
495 class TGetObjectBrowserEvent: public SALOME_Event
498 typedef QTreeView* TResult;
500 TGetObjectBrowserEvent() : myResult( 0 ) {}
501 virtual void Execute()
503 LightApp_Application* anApp = getApplication();
504 if ( anApp && anApp->objectBrowser() ) {
505 myResult = anApp->objectBrowser()->treeView();
509 QTreeView* SalomePyQt::getObjectBrowser()
511 return ProcessEvent( new TGetObjectBrowserEvent() );
515 \fn int SalomePyQt::getStudyId();
516 \brief Get active study's identifier.
517 \return active study ID or 0 if there is no active study
520 class TGetStudyIdEvent: public SALOME_Event
525 TGetStudyIdEvent() : myResult( 0 ) {}
526 virtual void Execute()
528 if ( LightApp_Study* aStudy = getActiveStudy() ) {
529 myResult = aStudy->id();
533 int SalomePyQt::getStudyId()
535 return ProcessEvent( new TGetStudyIdEvent() );
539 \fn SALOME_Selection* SalomePyQt::getSelection();
540 \brief Get the selection object for the current study.
542 Creates a Selection object if it has not been created yet.
544 \return selection object (0 on error)
547 class TGetSelectionEvent: public SALOME_Event
550 typedef SALOME_Selection* TResult;
552 TGetSelectionEvent() : myResult( 0 ) {}
553 virtual void Execute()
555 myResult = SALOME_Selection::GetSelection( getApplication() );
558 SALOME_Selection* SalomePyQt::getSelection()
560 return ProcessEvent( new TGetSelectionEvent() );
564 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
565 \brief Put an information message to the current application's
568 Optional second delay parameter (\a sec) can be used to specify
569 time of the message diplaying in seconds. If this parameter is less
570 or equal to zero, the constant message will be put.
572 \param msg message text
573 \param sec message displaying time in seconds
576 class TPutInfoEvent: public SALOME_Event
581 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
582 virtual void Execute()
584 if ( LightApp_Application* anApp = getApplication() ) {
585 anApp->putInfo( myMsg, mySecs * 1000 );
589 void SalomePyQt::putInfo( const QString& msg, const int sec )
591 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
595 \fn const QString SalomePyQt::getActiveComponent();
596 \brief Get the currently active module name (for the current study).
597 \return active module name or empty string if there is no active module
600 class TGetActiveComponentEvent: public SALOME_Event
603 typedef QString TResult;
605 TGetActiveComponentEvent() {}
606 virtual void Execute()
608 if ( LightApp_Application* anApp = getApplication() ) {
609 if ( CAM_Module* mod = anApp->activeModule() ) {
610 myResult = mod->name();
615 const QString SalomePyQt::getActiveComponent()
617 return ProcessEvent( new TGetActiveComponentEvent() );
621 \fn PyObject* SalomePyQt::getActivePythonModule();
622 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
623 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
626 class TGetActivePyModuleEvent: public SALOME_Event
629 typedef PyObject* TResult;
631 TGetActivePyModuleEvent() : myResult( Py_None ) {}
632 virtual void Execute()
634 PyModuleHelper* helper = getPythonHelper();
636 myResult = (PyObject*)helper->pythonModule();
639 PyObject* SalomePyQt::getActivePythonModule()
641 return ProcessEvent( new TGetActivePyModuleEvent() );
645 \fn bool SalomePyQt::activateModule( const QString& modName );
646 \brief Activates SALOME module with the given name
647 \return True if the module has been activated and False otherwise.
650 class TActivateModuleEvent: public SALOME_Event
653 typedef bool TResult;
655 QString myModuleName;
656 TActivateModuleEvent( const QString& modName )
657 : myResult( false ), myModuleName( modName ) {}
658 virtual void Execute()
660 if ( LightApp_Application* anApp = getApplication() ) {
661 myResult = anApp->activateModule( myModuleName );
665 bool SalomePyQt::activateModule( const QString& modName )
667 return ProcessEvent( new TActivateModuleEvent( modName ) );
671 \brief Update an Object Browser of the specified (by identifier) study.
673 If \a studyId <= 0 the active study's object browser is updated.
674 The \a updateSelection parameter is obsolete and currently is not used.
675 This parameter will be removed in future, so try to avoid its usage in
678 \brief studyId study identifier
679 \brief updateSelection update selection flag (not used)
682 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
684 class TEvent: public SALOME_Event
687 bool myUpdateSelection;
689 TEvent( const int studyId, bool updateSelection )
690 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
691 virtual void Execute()
693 if ( SUIT_Session::session() ) {
694 if ( getActiveStudy() && myStudyId <= 0 )
695 myStudyId = getActiveStudy()->id();
696 if ( myStudyId > 0 ) {
697 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
698 QList<SUIT_Application*>::Iterator it;
699 for( it = apps.begin(); it != apps.end(); ++it ) {
700 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
701 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
702 anApp->updateObjectBrowser();
710 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
715 SalomePyQt::isModified()
716 \return The modification status of the data model
717 for the currently active Python module
718 \note This function is supported for "light" Python-based SALOME modules only.
721 class TIsModifiedEvent: public SALOME_Event
724 typedef bool TResult;
726 TIsModifiedEvent() : myResult( false ) {}
727 virtual void Execute()
729 LightApp_Module* module = getActiveModule();
733 SALOME_PYQT_DataModelLight* aModel =
734 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
736 myResult = aModel->isModified();
739 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
743 bool SalomePyQt::isModified()
745 return ProcessEvent(new TIsModifiedEvent());
749 SalomePyQt::setModified()
751 Sets the modification status of the data model for
752 the currently active Python module. This method should be used
753 by the Python code in order to enable/disable "Save" operation
754 depending on the module's data state.
756 \note This function is supported for "light" Python-based SALOME modules only.
758 \param New modification status of the data model
762 void SalomePyQt::setModified( bool flag )
764 class TEvent: public SALOME_Event
770 virtual void Execute()
772 LightApp_Module* module = getActiveModule();
776 SALOME_PYQT_DataModelLight* model =
777 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
779 LightApp_Application* app = module->getApp();
781 if ( model && app ) {
782 model->setModified( myFlag );
783 app->updateActions();
786 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
790 ProcessVoidEvent( new TEvent( flag ) );
794 \brief Add string setting to the application preferences.
796 The parameter \a autoValue is obsolete parameter and currently is not used.
797 This parameter will be removed in future, so try to avoid its usage in
800 This function is obsolete. Use one of addSetting() instead.
802 \param name setting name (it should be of kind <section:setting> where
803 \c section is resources section name and \c setting is setting name)
804 \param value new setting value
805 \param autoValue (not used)
807 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
809 class TEvent: public SALOME_Event
815 TEvent( const QString& name, const QString& value, bool autoValue )
816 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
817 virtual void Execute()
819 if ( SUIT_Session::session() ) {
820 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
821 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
822 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
823 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
824 if ( !_sec.isEmpty() && !_nam.isEmpty() )
825 resMgr->setValue( _sec, _nam, myValue );
829 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
833 \brief Add integer setting to the application preferences.
835 The parameter \a autoValue is obsolete parameter and currently is not used.
836 This parameter will be removed in future, so try to avoid its usage in
839 This function is obsolete. Use one of addSetting() instead.
841 \param name setting name (it should be of kind <section:setting> where
842 \c section is resources section name and \c setting is setting name)
843 \param value new setting value
844 \param autoValue (not used)
846 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
848 class TEvent: public SALOME_Event
854 TEvent( const QString& name, const int value, bool autoValue )
855 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
856 virtual void Execute()
858 if ( SUIT_Session::session() ) {
859 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
860 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
861 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
862 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
863 if ( !_sec.isEmpty() && !_nam.isEmpty() )
864 resMgr->setValue( _sec, _nam, myValue );
868 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
872 \brief Add double setting to the application preferences.
874 The parameter \a autoValue is obsolete parameter and currently is not used.
875 This parameter will be removed in future, so try to avoid its usage in
878 This function is obsolete. Use one of addSetting() instead.
880 \param name setting name (it should be of kind <section:setting> where
881 \c section is resources section name and \c setting is setting name)
882 \param value new setting value
883 \param autoValue (not used)
885 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
887 class TEvent: public SALOME_Event
893 TEvent( const QString& name, const double value, bool autoValue )
894 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
895 virtual void Execute()
897 if ( SUIT_Session::session() ) {
898 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
899 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
900 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
901 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
902 if ( !_sec.isEmpty() && !_nam.isEmpty() )
903 resMgr->setValue( _sec, _nam, myValue );
907 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
911 \brief Add boolean setting to the application preferences.
913 The parameter \a autoValue is obsolete parameter and currently is not used.
914 This parameter will be removed in future, so try to avoid its usage in
917 This function is obsolete. Use one of addSetting() instead.
919 \param name setting name (it should be of kind <section:setting> where
920 \c section is resources section name and \c setting is setting name)
921 \param value new setting value
922 \param autoValue (not used)
924 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
926 class TEvent: public SALOME_Event
932 TEvent( const QString& name, const bool value, bool autoValue )
933 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
934 virtual void Execute()
936 if ( SUIT_Session::session() ) {
937 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
938 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
939 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
940 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
941 if ( !_sec.isEmpty() && !_nam.isEmpty() )
942 resMgr->setValue( _sec, _nam, myValue );
946 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
950 \brief Remove setting from the application preferences.
952 This function is obsolete. Use removeSetting() instead.
954 \param name setting name (it should be of kind <section:setting> where
955 \c section is resources section name and \c setting is setting name)
957 void SalomePyQt::removeSettings( const QString& name )
959 class TEvent: public SALOME_Event
963 TEvent( const QString& name ) : myName( name ) {}
964 virtual void Execute()
966 if ( SUIT_Session::session() ) {
967 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
968 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
969 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
970 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
971 if ( !_sec.isEmpty() && !_nam.isEmpty() )
972 resMgr->remove( _sec, _nam );
976 ProcessVoidEvent( new TEvent( name ) );
980 \fn QString SalomePyQt::getSetting( const QString& name );
981 \brief Get application setting value (as string represenation).
983 This function is obsolete. Use stringSetting(), integerSetting(),
984 boolSetting(), stringSetting() or colorSetting() instead.
986 \param name setting name (it should be of kind <section:setting> where
987 \c section is resources section name and \c setting is setting name)
988 \return setting name (empty string if setting name is invalid)
991 class TGetSettingEvent: public SALOME_Event
994 typedef QString TResult;
997 TGetSettingEvent( const QString& name ) : myName( name ) {}
998 virtual void Execute()
1000 if ( SUIT_Session::session() ) {
1001 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1002 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1003 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1004 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1005 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1009 QString SalomePyQt::getSetting( const QString& name )
1011 return ProcessEvent( new TGetSettingEvent( name ) );
1015 \fn QString SalomePyQt::constant( const QString& name );
1016 \brief Get constant's value from application's resource manager.
1018 \param name name of the constant
1019 \return value of the constant
1024 class TGetConstantEvent: public SALOME_Event
1027 typedef QString TResult;
1030 TGetConstantEvent( const QString& name ) : myName( name ) {}
1031 virtual void Execute()
1033 if ( SUIT_Session::session() )
1034 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1037 QString SalomePyQt::constant( const QString& name )
1039 return ProcessEvent( new TGetConstantEvent( name ) );
1043 \brief Add constant to the application's resource manager.
1045 This function is useful to specify programmatically specific
1046 variables that are referenced in the resource setting.
1048 For example, some resource value can be set as "$(myroot)/data/files".
1049 Then, "mypath" constant can be set programmatically by the application
1050 depending on run-time requirements.
1052 \param section resources file section name
1053 \param name name of the constant
1054 \param value value of the constant
1058 void SalomePyQt::setConstant( const QString& name, const QString& value )
1060 class TEvent: public SALOME_Event
1062 QString myName, myValue;
1064 TEvent( const QString& name, const QString& value )
1065 : myName( name ), myValue( value ) {}
1066 virtual void Execute()
1068 if ( SUIT_Session::session() )
1069 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1072 ProcessVoidEvent( new TEvent( name, value ) );
1076 \brief Add double setting to the application preferences.
1077 \param section resources file section name
1078 \param name setting name
1079 \param value new setting value
1081 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1083 class TEvent: public SALOME_Event
1089 TEvent( const QString& section, const QString& name, double value )
1090 : mySection( section ), myName( name ), myValue( value ) {}
1091 virtual void Execute()
1093 if ( SUIT_Session::session() ) {
1094 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1095 if ( !mySection.isEmpty() && !myName.isEmpty() )
1096 resMgr->setValue( mySection, myName, myValue );
1100 ProcessVoidEvent( new TEvent( section, name, value ) );
1104 \brief Add integer setting to the application preferences.
1105 \param section resources file section name
1106 \param name setting name
1107 \param value new setting value
1109 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1111 class TEvent: public SALOME_Event
1117 TEvent( const QString& section, const QString& name, int value )
1118 : mySection( section ), myName( name ), myValue( value ) {}
1119 virtual void Execute()
1121 if ( SUIT_Session::session() ) {
1122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1123 if ( !mySection.isEmpty() && !myName.isEmpty() )
1124 resMgr->setValue( mySection, myName, myValue );
1128 ProcessVoidEvent( new TEvent( section, name, value ) );
1132 \brief Add boolean setting to the application preferences.
1133 \param section resources file section name
1134 \param name setting name
1135 \param value new setting value
1136 \param dumb this parameter is used in order to avoid sip compilation error
1137 because of conflicting int and bool types
1139 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1141 class TEvent: public SALOME_Event
1147 TEvent( const QString& section, const QString& name, bool value )
1148 : mySection( section ), myName( name ), myValue( value ) {}
1149 virtual void Execute()
1151 if ( SUIT_Session::session() ) {
1152 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1153 if ( !mySection.isEmpty() && !myName.isEmpty() )
1154 resMgr->setValue( mySection, myName, myValue );
1158 ProcessVoidEvent( new TEvent( section, name, value ) );
1162 \brief Add string setting to the application preferences.
1163 \param section resources file section name
1164 \param name setting name
1165 \param value new setting value
1167 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1169 class TEvent: public SALOME_Event
1175 TEvent( const QString& section, const QString& name, const QString& value )
1176 : mySection( section ), myName( name ), myValue( value ) {}
1177 virtual void Execute()
1179 if ( SUIT_Session::session() ) {
1180 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1181 if ( !mySection.isEmpty() && !myName.isEmpty() )
1182 resMgr->setValue( mySection, myName, myValue );
1186 ProcessVoidEvent( new TEvent( section, name, value ) );
1190 \brief Add color setting to the application preferences.
1191 \param section resources file section name
1192 \param name setting name
1193 \param value new setting value
1195 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1197 class TEvent: public SALOME_Event
1203 TEvent( const QString& section, const QString& name, const QColor& value )
1204 : mySection( section ), myName( name ), myValue( value ) {}
1205 virtual void Execute()
1207 if ( SUIT_Session::session() ) {
1208 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1209 if ( !mySection.isEmpty() && !myName.isEmpty() )
1210 resMgr->setValue( mySection, myName, myValue );
1214 ProcessVoidEvent( new TEvent( section, name, value ) );
1218 \brief Add byte array setting to the application preferences.
1219 \param section resources file section name
1220 \param name setting name
1221 \param value new setting value
1223 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1225 class TEvent: public SALOME_Event
1231 TEvent( const QString& section, const QString& name, const QByteArray& value )
1232 : mySection( section ), myName( name ), myValue( value ) {}
1233 virtual void Execute()
1235 if ( SUIT_Session::session() ) {
1236 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1237 if ( !mySection.isEmpty() && !myName.isEmpty() )
1238 resMgr->setValue( mySection, myName, myValue );
1242 ProcessVoidEvent( new TEvent( section, name, value ) );
1246 \fn int SalomePyQt::integerSetting( const QString& section,
1247 const QString& name,
1249 \brief Get integer setting from the application preferences.
1250 \param section resources file section name
1251 \param name setting name
1252 \param def default value which is returned if the setting is not found
1253 \return setting value
1256 class TGetIntSettingEvent: public SALOME_Event
1259 typedef int TResult;
1264 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1265 : mySection( section ), myName( name ), myDefault( def ) {}
1266 virtual void Execute()
1268 if ( SUIT_Session::session() ) {
1269 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1270 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1274 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1276 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1280 \fn double SalomePyQt::doubleSetting( const QString& section,
1281 const QString& name,
1283 \brief Get double setting from the application preferences.
1284 \param section resources file section name
1285 \param name setting name
1286 \param def default value which is returned if the setting is not found
1287 \return setting value
1290 class TGetDblSettingEvent: public SALOME_Event
1293 typedef double TResult;
1298 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1299 : mySection( section ), myName( name ), myDefault( def ) {}
1300 virtual void Execute()
1302 if ( SUIT_Session::session() ) {
1303 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1304 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1308 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1310 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1314 \fn bool SalomePyQt::boolSetting( const QString& section,
1315 const QString& name,
1317 \brief Get boolean setting from the application preferences.
1318 \param section resources file section name
1319 \param name setting name
1320 \param def default value which is returned if the setting is not found
1321 \return setting value
1324 class TGetBoolSettingEvent: public SALOME_Event
1327 typedef bool TResult;
1332 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1333 : mySection( section ), myName( name ), myDefault( def ) {}
1334 virtual void Execute()
1336 if ( SUIT_Session::session() ) {
1337 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1338 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1342 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1344 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1348 \fn QString SalomePyQt::stringSetting( const QString& section,
1349 const QString& name,
1352 \brief Get string setting from the application preferences.
1353 \param section resources file section name
1354 \param name setting name
1355 \param def default value which is returned if the setting is not found
1356 \param subst \c true to make substitution, \c false to get "raw" value
1357 \return setting value
1360 class TGetStrSettingEvent: public SALOME_Event
1363 typedef QString TResult;
1369 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1370 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1371 virtual void Execute()
1373 if ( SUIT_Session::session() ) {
1374 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1375 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1379 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1381 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1385 \fn QColor SalomePyQt::colorSetting( const QString& section,
1386 const QString& name,
1388 \brief Get color setting from the application preferences.
1389 \param section resources file section name
1390 \param name setting name
1391 \param def default value which is returned if the setting is not found
1392 \return setting value
1395 class TGetColorSettingEvent: public SALOME_Event
1398 typedef QColor TResult;
1403 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1404 : mySection( section ), myName( name ), myDefault( def ) {}
1405 virtual void Execute()
1407 if ( SUIT_Session::session() ) {
1408 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1409 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1413 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1415 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1419 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1420 const QString& name,
1421 const QByteArray def );
1422 \brief Get byte array setting from the application preferences.
1423 \param section resources file section name
1424 \param name setting name
1425 \param def default value which is returned if the setting is not found
1426 \return setting value
1429 class TGetByteArraySettingEvent: public SALOME_Event
1432 typedef QByteArray TResult;
1437 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1438 : mySection( section ), myName( name ), myDefault( def ) {}
1439 virtual void Execute()
1441 if ( SUIT_Session::session() ) {
1442 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1443 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1447 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1449 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1453 \brief Remove setting from the application preferences.
1454 \param section resources file section name
1455 \param name setting name
1457 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1459 class TEvent: public SALOME_Event
1464 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1465 virtual void Execute()
1467 if ( SUIT_Session::session() ) {
1468 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1469 if ( !mySection.isEmpty() && !myName.isEmpty() )
1470 resMgr->remove( mySection, myName );
1474 ProcessVoidEvent( new TEvent( section, name ) );
1478 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1479 \brief Check setting existence in the application preferences.
1480 \param section resources file section name
1481 \param name setting name
1482 \return \c true if setting exists
1485 class THasSettingEvent: public SALOME_Event
1488 typedef bool TResult;
1492 THasSettingEvent( const QString& section, const QString& name )
1493 : mySection( section ), myName( name ) {}
1494 virtual void Execute()
1496 if ( SUIT_Session::session() ) {
1497 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1498 myResult = resMgr->hasValue( mySection, myName );
1502 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1504 return ProcessEvent( new THasSettingEvent( section, name ) );
1508 \fn QStringList SalomePyQt::parameters( const QString& section );
1509 \brief Get names of preference items stored within the given section.
1510 \param section resources file section's name
1511 \return \c list of preferences items
1515 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1516 \brief Get names of preference items stored within the given section.
1517 \param section resources file section's name
1518 \return \c list of preferences items
1521 class TParametersEvent: public SALOME_Event
1524 typedef QStringList TResult;
1526 QStringList mySection;
1527 TParametersEvent( const QString& section )
1529 mySection << section;
1531 TParametersEvent( const QStringList& section )
1532 : mySection( section )
1534 virtual void Execute()
1536 if ( SUIT_Session::session() ) {
1537 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1538 myResult = resMgr->parameters( mySection );
1542 QStringList SalomePyQt::parameters( const QString& section )
1544 return ProcessEvent( new TParametersEvent( section ) );
1546 QStringList SalomePyQt::parameters( const QStringList& section )
1548 return ProcessEvent( new TParametersEvent( section ) );
1552 \fn QString SalomePyQt::getFileName( QWidget* parent,
1553 const QString& initial,
1554 const QStringList& filters,
1555 const QString& caption,
1557 \brief Show 'Open/Save file' dialog box for file selection
1558 and return a user's choice (selected file name).
1559 \param parent parent widget
1560 \param initial initial directory the dialog box to be opened in
1561 \param filters list of files filters (wildcards)
1562 \param caption dialog box title
1563 \param open if \c true, "Open File" dialog box is shown;
1564 otherwise "Save File" dialog box is shown
1565 \return selected file name (null string if user cancels operation)
1568 class TGetFileNameEvent: public SALOME_Event
1571 typedef QString TResult;
1575 QStringList myFilters;
1578 TGetFileNameEvent( QWidget* parent,
1579 const QString& initial,
1580 const QStringList& filters,
1581 const QString& caption,
1583 : myParent ( parent ),
1584 myInitial( initial ),
1585 myFilters( filters ),
1586 myCaption( caption ),
1588 virtual void Execute()
1590 if ( LightApp_Application* anApp = getApplication() ) {
1591 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1592 myCaption, myParent );
1596 QString SalomePyQt::getFileName( QWidget* parent,
1597 const QString& initial,
1598 const QStringList& filters,
1599 const QString& caption,
1602 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1606 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1607 const QString& initial,
1608 const QStringList& filters,
1609 const QString& caption );
1610 \brief Show 'Open files' dialog box for multiple files selection
1611 and return a user's choice (selected file names list).
1612 \param parent parent widget
1613 \param initial initial directory the dialog box to be opened in
1614 \param filters list of files filters (wildcards)
1615 \param caption dialog box title
1616 \return selected file names list (empty list if user cancels operation)
1619 class TGetOpenFileNamesEvent: public SALOME_Event
1622 typedef QStringList TResult;
1626 QStringList myFilters;
1628 TGetOpenFileNamesEvent( QWidget* parent,
1629 const QString& initial,
1630 const QStringList& filters,
1631 const QString& caption )
1632 : myParent ( parent ),
1633 myInitial( initial ),
1634 myFilters( filters ),
1635 myCaption( caption ) {}
1636 virtual void Execute()
1638 if ( LightApp_Application* anApp = getApplication() ) {
1639 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1643 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1644 const QString& initial,
1645 const QStringList& filters,
1646 const QString& caption )
1648 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1652 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1653 const QString& initial,
1654 const QString& caption );
1655 \brief Show 'Get Directory' dialog box for the directory selection
1656 and return a user's choice (selected directory name).
1657 \param parent parent widget
1658 \param initial initial directory the dialog box to be opened in
1659 \param caption dialog box title
1660 \return selected directory name (null string if user cancels operation)
1663 class TGetExistingDirectoryEvent: public SALOME_Event
1666 typedef QString TResult;
1671 TGetExistingDirectoryEvent( QWidget* parent,
1672 const QString& initial,
1673 const QString& caption )
1674 : myParent ( parent ),
1675 myInitial( initial ),
1676 myCaption( caption ) {}
1677 virtual void Execute()
1679 if ( LightApp_Application* anApp = getApplication() ) {
1680 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1684 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1685 const QString& initial,
1686 const QString& caption )
1688 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1692 \fn QString SalomePyQt::loadIcon( const QString& filename );
1693 \brief Load an icon from the module resources by the specified file name.
1694 \param fileName icon file name
1698 class TLoadIconEvent: public SALOME_Event
1701 typedef QIcon TResult;
1705 TLoadIconEvent( const QString& module, const QString& filename )
1706 : myModule( module ),
1707 myFileName ( filename ) {}
1708 virtual void Execute()
1710 myResult = loadIconInternal( myModule, myFileName );
1713 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1715 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1719 \brief Open external browser to display context help information.
1722 Current implementation does nothing.
1724 \param source documentation (HTML) file name
1725 \param context context (for example, HTML ancor name)
1727 void SalomePyQt::helpContext( const QString& source, const QString& context )
1729 class TEvent: public SALOME_Event
1734 TEvent( const QString& source, const QString& context )
1735 : mySource( source ), myContext( context ) {}
1736 virtual void Execute()
1738 if ( LightApp_Application* anApp = getApplication() ) {
1739 anApp->onHelpContextModule( "", mySource, myContext );
1743 ProcessVoidEvent( new TEvent( source, context ) );
1747 \fn int SalomePyQt::defaultMenuGroup();
1748 \brief Get detault menu group identifier which can be used when
1749 creating menus (insert custom menu commands).
1750 \return default menu group ID
1753 class TDefMenuGroupEvent: public SALOME_Event
1756 typedef int TResult;
1758 TDefMenuGroupEvent() : myResult( -1 ) {}
1759 virtual void Execute()
1761 myResult = PyModuleHelper::defaultMenuGroup();
1764 int SalomePyQt::defaultMenuGroup()
1766 return ProcessEvent( new TDefMenuGroupEvent() );
1772 CrTool( const QString& tBar, const QString& nBar )
1773 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1774 CrTool( const int id, const int tBar, const int idx )
1775 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1776 CrTool( const int id, const QString& tBar, const int idx )
1777 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1778 CrTool( QAction* action, const int tbId, const int id, const int idx )
1779 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1780 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1781 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1783 int execute( LightApp_Module* module ) const
1788 return module->createTool( myTbTitle, myTbName );
1790 return module->createTool( myId, myTbId, myIndex );
1792 return module->createTool( myId, myTbTitle, myIndex );
1794 return module->createTool( myAction, myTbId, myId, myIndex );
1796 return module->createTool( myAction, myTbTitle, myId, myIndex );
1811 class TCreateToolEvent: public SALOME_Event
1814 typedef int TResult;
1816 const CrTool& myCrTool;
1817 TCreateToolEvent( const CrTool& crTool )
1818 : myResult( -1 ), myCrTool( crTool ) {}
1819 virtual void Execute()
1821 LightApp_Module* module = getActiveModule();
1823 myResult = myCrTool.execute( module );
1828 \brief Create toolbar with specified name.
1829 \param tBar toolbar title (language-dependent)
1830 \param nBar toolbar name (language-independent) [optional]
1831 \return toolbar ID or -1 if toolbar creation is failed
1833 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1835 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1839 \brief Insert action with specified \a id to the toolbar.
1841 \param tBar toolbar ID
1842 \param idx required index in the toolbar
1843 \return action ID or -1 if action could not be added
1845 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1847 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1851 \brief Insert action with specified \a id to the toolbar.
1853 \param tBar toolbar name
1854 \param idx required index in the toolbar
1855 \return action ID or -1 if action could not be added
1857 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1859 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1863 \brief Insert action to the toolbar.
1865 \param tBar toolbar ID
1866 \param id required action ID
1867 \param idx required index in the toolbar
1868 \return action ID or -1 if action could not be added
1870 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1872 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1876 \brief Insert action to the toolbar.
1878 \param tBar toolbar name
1879 \param id required action ID
1880 \param idx required index in the toolbar
1881 \return action ID or -1 if action could not be added
1883 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1885 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1891 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1892 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1893 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1894 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1895 CrMenu( const int id, const int menu, const int group, const int idx )
1896 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1897 CrMenu( const int id, const QString& menu, const int group, const int idx )
1898 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1899 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1900 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1901 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1902 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1904 int execute( LightApp_Module* module ) const
1909 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1911 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1913 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1915 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1917 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1919 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1928 QString mySubMenuName;
1935 class TCreateMenuEvent: public SALOME_Event
1938 typedef int TResult;
1940 const CrMenu& myCrMenu;
1941 TCreateMenuEvent( const CrMenu& crMenu )
1942 : myResult( -1 ), myCrMenu( crMenu ) {}
1943 virtual void Execute()
1945 LightApp_Module* module = getActiveModule();
1947 myResult = myCrMenu.execute( module );
1952 \brief Create main menu.
1953 \param subMenu menu name
1954 \param menu parent menu ID
1955 \param id required menu ID
1956 \param group menu group ID
1957 \param idx required index in the menu
1958 \return menu ID or -1 if menu could not be added
1960 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1962 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1966 \brief Create main menu.
1967 \param subMenu menu name
1968 \param menu parent menu name (list of menu names separated by "|")
1969 \param id required menu ID
1970 \param group menu group ID
1971 \param idx required index in the menu
1972 \return menu ID or -1 if menu could not be added
1974 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1976 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1980 \brief Insert action to the main menu.
1982 \param menu parent menu ID
1983 \param group menu group ID
1984 \param idx required index in the menu
1985 \return action ID or -1 if action could not be added
1987 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1989 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1993 \brief Insert action to the main menu.
1995 \param menu parent menu name (list of menu names separated by "|")
1996 \param group menu group ID
1997 \param idx required index in the menu
1998 \return action ID or -1 if action could not be added
2000 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2002 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2006 \brief Insert action to the main menu.
2008 \param menu parent menu ID
2009 \param group menu group ID
2010 \param idx required index in the menu
2011 \return action ID or -1 if action could not be added
2013 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2015 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2019 \brief Insert action to the main menu.
2021 \param menu parent menu name (list of menu names separated by "|")
2022 \param group menu group ID
2023 \param idx required index in the menu
2024 \return action ID or -1 if action could not be added
2026 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2028 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2032 \fn QAction* SalomePyQt::createSeparator();
2033 \brief Create separator action which can be used in the menu or toolbar.
2034 \return new separator action
2037 class TCreateSepEvent: public SALOME_Event
2040 typedef QAction* TResult;
2044 virtual void Execute()
2046 LightApp_Module* module = getActiveModule();
2048 myResult = (QAction*)module->separator();
2051 QAction* SalomePyQt::createSeparator()
2053 return ProcessEvent( new TCreateSepEvent() );
2057 \fn QAction* SalomePyQt::createAction( const int id,
2058 const QString& menuText,
2059 const QString& tipText,
2060 const QString& statusText,
2061 const QString& icon,
2063 const bool toggle );
2064 \brief Create an action which can be then used in the menu or toolbar.
2065 \param id the unique id action to be registered to
2066 \param menuText action text which should appear in menu
2067 \param tipText text which should appear in the tooltip
2068 \param statusText text which should appear in the status bar when action is activated
2069 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2070 \param key the key accelrator for the action
2071 \param toggle if \c true the action is checkable
2074 class TCreateActionEvent: public SALOME_Event
2077 typedef QAction* TResult;
2082 QString myStatusText;
2086 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2087 const QString& statusText, const QString& icon, const int key, const bool toggle )
2088 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2089 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2090 virtual void Execute()
2092 LightApp_Module* module = getActiveModule();
2094 QIcon icon = loadIconInternal( module->name(), myIcon );
2095 myResult = (QAction*)module->action( myId );
2097 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2098 myResult->setToolTip( myTipText );
2099 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2100 myResult->setText( myMenuText );
2101 if ( myResult->icon().isNull() && !icon.isNull() )
2102 myResult->setIcon( icon );
2103 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2104 myResult->setStatusTip( myStatusText );
2105 if ( myResult->shortcut().isEmpty() && myKey )
2106 myResult->setShortcut( myKey );
2107 if ( myResult->isCheckable() != myToggle )
2108 myResult->setCheckable( myToggle );
2111 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2113 // for Python module, automatically connect action to callback slot
2114 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2115 if ( helper ) helper->connectAction( myResult );
2119 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2120 const QString& tipText, const QString& statusText,
2121 const QString& icon, const int key, const bool toggle )
2123 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2127 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2128 \brief Create an action group which can be then used in the menu or toolbar
2129 \param id : the unique id action group to be registered to
2130 \param exclusive : if \c true the action group does exclusive toggling
2133 struct TCreateActionGroupEvent: public SALOME_Event
2135 typedef QtxActionGroup* TResult;
2139 TCreateActionGroupEvent( const int id, const bool exclusive )
2140 : myId( id ), myExclusive( exclusive ) {}
2141 virtual void Execute()
2143 LightApp_Module* module = getActiveModule();
2145 myResult = module->createActionGroup( myId, myExclusive );
2148 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2150 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2154 \fn QAction* SalomePyQt::action( const int id );
2155 \brief Get action by specified identifier.
2156 \return action or 0 if action is not registered
2159 class TActionEvent: public SALOME_Event
2162 typedef QAction* TResult;
2165 TActionEvent( const int id )
2166 : myResult( 0 ), myId( id ) {}
2167 virtual void Execute()
2169 LightApp_Module* module = getActiveModule();
2171 myResult = (QAction*)module->action( myId );
2174 QAction* SalomePyQt::action( const int id )
2176 return ProcessEvent( new TActionEvent( id ) );
2180 \fn int SalomePyQt::actionId( const QAction* a );
2181 \brief Get an action identifier.
2182 \return action ID or -1 if action is not registered
2185 class TActionIdEvent: public SALOME_Event
2188 typedef int TResult;
2190 const QAction* myAction;
2191 TActionIdEvent( const QAction* action )
2192 : myResult( -1 ), myAction( action ) {}
2193 virtual void Execute()
2195 LightApp_Module* module = getActiveModule();
2197 myResult = module->actionId( myAction );
2200 int SalomePyQt::actionId( const QAction* a )
2202 return ProcessEvent( new TActionIdEvent( a ) );
2206 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2207 \brief Add global (not module-related) preferences group.
2208 \param label global preferences group name
2209 \return preferences group identifier
2212 class TAddGlobalPrefEvent: public SALOME_Event
2215 typedef int TResult;
2218 TAddGlobalPrefEvent( const QString& label )
2219 : myResult( -1 ), myLabel( label ) {}
2220 virtual void Execute()
2222 LightApp_Module* module = getActiveModule();
2224 LightApp_Preferences* pref = module->getApp()->preferences();
2226 myResult = pref->addPreference( myLabel, -1 );
2230 int SalomePyQt::addGlobalPreference( const QString& label )
2232 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2236 \fn int SalomePyQt::addPreference( const QString& label );
2237 \brief Add module-related preferences group.
2238 \param label preferences group name
2239 \return preferences group identifier
2242 class TAddPrefEvent: public SALOME_Event
2245 typedef int TResult;
2248 TAddPrefEvent( const QString& label )
2249 : myResult( -1 ), myLabel( label ) {}
2250 virtual void Execute()
2252 LightApp_Module* module = getActiveModule();
2254 LightApp_Preferences* pref = module->getApp()->preferences();
2256 int cId = pref->addPreference( module->moduleName(), -1 );
2258 myResult = pref->addPreference( myLabel, cId );
2263 int SalomePyQt::addPreference( const QString& label )
2265 return ProcessEvent( new TAddPrefEvent( label ) );
2269 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2270 const QString& section, const QString& param );
2271 \brief Add module-related preferences.
2272 \param label preferences group name
2273 \param pId parent preferences group id
2274 \param type preferences type
2275 \param section resources file section name
2276 \param param resources file setting name
2277 \return preferences identifier
2280 class TAddPrefParamEvent: public SALOME_Event
2283 typedef int TResult;
2290 TAddPrefParamEvent( const QString& label,
2291 const int pId, const int type,
2292 const QString& section,
2293 const QString& param )
2295 myLabel( label ), myPId( pId ), myType( type ),
2296 mySection( section ), myParam ( param ) {}
2297 virtual void Execute()
2299 LightApp_Module* module = getActiveModule();
2301 LightApp_Preferences* pref = module->getApp()->preferences();
2303 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2307 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2308 const QString& section, const QString& param )
2310 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2314 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2315 \brief Get the preferences property.
2316 \param id preferences identifier
2317 \param prop preferences property name
2318 \return preferences property value or null QVariant if property is not set
2321 class TPrefPropEvent: public SALOME_Event
2324 typedef QVariant TResult;
2328 TPrefPropEvent( const int id, const QString& prop )
2329 : myId( id ), myProp( prop ) {}
2330 virtual void Execute()
2332 LightApp_Module* module = getActiveModule();
2334 LightApp_Preferences* pref = module->getApp()->preferences();
2336 myResult = pref->itemProperty( myProp, myId );
2340 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2342 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2346 \brief Set the preferences property.
2347 \param id preferences identifier
2348 \param prop preferences property name
2349 \param var preferences property value
2351 void SalomePyQt::setPreferenceProperty( const int id,
2352 const QString& prop,
2353 const QVariant& var )
2355 class TEvent: public SALOME_Event
2361 TEvent( const int id, const QString& prop, const QVariant& var )
2362 : myId( id ), myProp( prop ), myVar( var ) {}
2363 virtual void Execute()
2365 LightApp_Module* module = getActiveModule();
2367 LightApp_Preferences* pref = module->getApp()->preferences();
2369 pref->setItemProperty( myProp, myVar, myId );
2373 ProcessVoidEvent( new TEvent( id, prop, var) );
2377 \brief Add the property value to the list of values.
2379 This method allows creating properties which are QList<QVariant>
2380 - there is no way to pass such values directly to QVariant parameter with PyQt.
2382 \param id preferences identifier
2383 \param prop preferences property name
2384 \param idx preferences property index
2385 \param var preferences property value for the index \a idx
2387 void SalomePyQt::addPreferenceProperty( const int id,
2388 const QString& prop,
2390 const QVariant& var )
2392 class TEvent: public SALOME_Event
2399 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2400 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2401 virtual void Execute()
2403 LightApp_Module* module = getActiveModule();
2405 LightApp_Preferences* pref = module->getApp()->preferences();
2407 QVariant var = pref->itemProperty( myProp, myId );
2408 if ( var.isValid() ) {
2409 if ( var.type() == QVariant::StringList ) {
2410 QStringList sl = var.toStringList();
2411 if ( myIdx >= 0 && myIdx < sl.count() )
2412 sl[myIdx] = myVar.toString();
2414 sl.append( myVar.toString() );
2415 pref->setItemProperty( myProp, sl, myId );
2417 else if ( var.type() == QVariant::List ) {
2418 QList<QVariant> vl = var.toList();
2419 if ( myIdx >= 0 && myIdx < vl.count() )
2423 pref->setItemProperty( myProp, vl, myId );
2429 pref->setItemProperty( myProp, vl, myId );
2435 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2439 \brief Put the message to the Log messages output window
2440 \param msg message text (it can be of simple rich text format)
2441 \param addSeparator boolean flag which specifies if it is necessary
2442 to separate the message with predefined separator
2444 void SalomePyQt::message( const QString& msg, bool addSeparator )
2446 class TEvent: public SALOME_Event
2451 TEvent( const QString& msg, bool addSeparator )
2452 : myMsg( msg ), myAddSep( addSeparator ) {}
2453 virtual void Execute()
2455 if ( LightApp_Application* anApp = getApplication() ) {
2456 LogWindow* lw = anApp->logWindow();
2458 lw->putMessage( myMsg, myAddSep );
2462 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2466 \brief Remove all the messages from the Log messages output window.
2468 void SalomePyQt::clearMessages()
2470 class TEvent: public SALOME_Event
2474 virtual void Execute()
2476 if ( LightApp_Application* anApp = getApplication() ) {
2477 LogWindow* lw = anApp->logWindow();
2483 ProcessVoidEvent( new TEvent() );
2487 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2488 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2489 to the image file in the specified format.
2491 For the current moment JPEG, PNG and BMP images formats are supported.
2492 The image format is defined automatically by the file name extension.
2493 By default, BMP format is used.
2495 \param filename image file name
2496 \return operation status (\c true on success)
2499 class TDumpViewEvent: public SALOME_Event
2502 typedef bool TResult;
2506 TDumpViewEvent( const QString& filename, const int id )
2507 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2508 virtual void Execute()
2510 SUIT_ViewWindow* wnd = 0;
2512 if ( LightApp_Application* anApp = getApplication() ) {
2513 SUIT_ViewManager* vm = anApp->activeViewManager();
2515 wnd = vm->getActiveView();
2517 myWndId = wnd->getId();
2520 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2523 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2524 #ifndef DISABLE_PLOT2DVIEWER
2525 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2527 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2528 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2529 qApp->processEvents();
2530 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2531 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2535 #endif // DISABLE_PLOT2DVIEWER
2536 QImage im = wnd->dumpView();
2537 if ( !im.isNull() && !myFileName.isEmpty() ) {
2538 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2539 if ( fmt == "JPG" ) fmt = "JPEG";
2540 myResult = im.save( myFileName, fmt.toLatin1() );
2545 bool SalomePyQt::dumpView( const QString& filename, const int id )
2547 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2551 \fn QList<int> SalomePyQt::getViews();
2552 \brief Get list of integer identifiers of all the currently opened views
2553 \return list of integer identifiers of all the currently opened views
2556 class TGetViews: public SALOME_Event
2559 typedef QList<int> TResult;
2562 virtual void Execute()
2565 LightApp_Application* app = getApplication();
2567 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2569 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2570 SUIT_ViewWindow* wnd;
2571 foreach ( wnd, wndlist )
2572 myResult.append( wnd->getId() );
2577 QList<int> SalomePyQt::getViews()
2579 return ProcessEvent( new TGetViews() );
2583 \fn int SalomePyQt::getActiveView();
2584 \brief Get integer identifier of the currently active view
2585 \return integer identifier of the currently active view
2588 class TGetActiveView: public SALOME_Event
2591 typedef int TResult;
2595 virtual void Execute()
2597 LightApp_Application* app = getApplication();
2599 SUIT_ViewManager* viewMgr = app->activeViewManager();
2601 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2603 myResult = wnd->getId();
2608 int SalomePyQt::getActiveView()
2610 return ProcessEvent( new TGetActiveView() );
2614 \fn QString SalomePyQt::getViewType( const int id );
2615 \brief Get type of the specified view, e.g. "OCCViewer"
2616 \param id window identifier
2620 class TGetViewType: public SALOME_Event
2623 typedef QString TResult;
2626 TGetViewType( const int id )
2628 virtual void Execute()
2630 SUIT_ViewWindow* wnd = getWnd( myWndId );
2632 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2634 myResult = viewMgr->getType();
2638 QString SalomePyQt::getViewType( const int id )
2640 return ProcessEvent( new TGetViewType( id ) );
2644 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2645 \brief Change view caption
2646 \param id window identifier
2647 \param title new window title
2648 \return \c true if operation is completed successfully and \c false otherwise
2651 class TSetViewTitle: public SALOME_Event
2654 typedef bool TResult;
2658 TSetViewTitle( const int id, const QString& title )
2659 : myResult( false ),
2662 virtual void Execute()
2664 SUIT_ViewWindow* wnd = getWnd( myWndId );
2666 wnd->setWindowTitle( myTitle );
2671 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2673 return ProcessEvent( new TSetViewTitle( id, title ) );
2677 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2678 \brief Set view size
2679 \param w window width
2680 \param h window height
2681 \param id window identifier
2682 \return \c true if operation is completed successfully and \c false otherwise
2685 class TSetViewSize: public SALOME_Event
2688 typedef bool TResult;
2693 TSetViewSize( const int w, const int h, const int id )
2694 : myResult( false ),
2698 virtual void Execute()
2700 SUIT_ViewWindow* wnd = 0;
2702 if ( LightApp_Application* anApp = getApplication() ) {
2703 SUIT_ViewManager* vm = anApp->activeViewManager();
2705 wnd = vm->getActiveView();
2709 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2712 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2714 QString type = viewMgr->getType();
2715 if ( type == "OCCViewer") {
2716 #ifndef DISABLE_OCCVIEWER
2717 // specific processing for OCC viewer:
2718 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2719 // - if there is only one sub-view active; it will be resized;
2720 // - if there are several sub-views, each of them will be resized.
2721 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2722 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2723 if ( occView && occView->getView( i ) ) {
2724 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2728 #endif // DISABLE_OCCVIEWER
2730 else if ( type == "ParaView") {
2731 #ifndef DISABLE_PVVIEWER
2732 // specific processing for ParaView viewer:
2733 // hierarchy of ParaView viewer is much complex than for usual view;
2734 // we look for sub-widget named "Viewport"
2735 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2736 if ( !lst.isEmpty() ) {
2737 lst[0]->resize( myWndWidth, myWndHeight );
2740 #endif // DISABLE_PVVIEWER
2743 if ( wnd->centralWidget() ) {
2744 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2752 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2754 return ProcessEvent( new TSetViewSize( w, h, id ) );
2758 \fn QString SalomePyQt::getViewTitle( const int id );
2759 \brief Get view caption
2760 \param id window identifier
2761 \return view caption
2764 class TGetViewTitle: public SALOME_Event
2767 typedef QString TResult;
2770 TGetViewTitle( const int id )
2772 virtual void Execute()
2774 SUIT_ViewWindow* wnd = getWnd( myWndId );
2776 myResult = wnd->windowTitle();
2779 QString SalomePyQt::getViewTitle( const int id )
2781 return ProcessEvent( new TGetViewTitle( id ) );
2785 \fn QList<int> SalomePyQt::findViews( const QString& type );
2786 \brief Get list of integer identifiers of all the
2787 currently opened views of the specified type
2788 \param type viewer type
2789 \return list of integer identifiers
2792 class TFindViews: public SALOME_Event
2795 typedef QList<int> TResult;
2798 TFindViews( const QString& type )
2800 virtual void Execute()
2803 LightApp_Application* app = getApplication();
2805 ViewManagerList vmList;
2806 app->viewManagers( myType, vmList );
2807 SUIT_ViewManager* viewMgr;
2808 foreach ( viewMgr, vmList ) {
2809 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2810 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2811 SUIT_ViewWindow* wnd = vec[ i ];
2814 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
2815 myResult.append( wnd->getId() );
2822 QList<int> SalomePyQt::findViews( const QString& type )
2824 return ProcessEvent( new TFindViews( type ) );
2828 \fn bool SalomePyQt::activateView( const int id );
2829 \brief Activate view
2830 \param id window identifier
2831 \return \c true if operation is completed successfully and \c false otherwise
2834 class TActivateView: public SALOME_Event
2837 typedef bool TResult;
2840 TActivateView( const int id )
2841 : myResult( false ),
2843 virtual void Execute()
2845 SUIT_ViewWindow* wnd = getWnd( myWndId );
2846 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
2853 bool SalomePyQt::activateView( const int id )
2855 return ProcessEvent( new TActivateView( id ) );
2862 class TActivateViewManagerAndView: public SALOME_Event
2865 typedef bool TResult;
2868 TActivateViewManagerAndView( const int id )
2869 : myResult( false ),
2871 virtual void Execute()
2873 SUIT_ViewWindow* wnd = getWnd( myWndId );
2874 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
2877 LightApp_Application* app = getApplication();
2878 app->setActiveViewManager(wnd->getViewManager());
2884 bool SalomePyQt::activateViewManagerAndView( const int id )
2886 return ProcessEvent( new TActivateViewManagerAndView( id ) );
2893 class TGetViewWidget: public SALOME_Event
2896 typedef QWidget* TResult;
2899 TGetViewWidget( const int id )
2902 virtual void Execute()
2904 SUIT_ViewWindow* wnd = getWnd( myWndId );
2906 myResult = (QWidget*)wnd;
2910 QWidget* SalomePyQt::getViewWidget( const int id)
2912 return ProcessEvent( new TGetViewWidget( id ) );
2917 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2918 \brief Create new view and activate it
2919 \param type viewer type
2923 \return integer identifier of created view (or -1 if view could not be created)
2926 class TCreateView: public SALOME_Event
2929 typedef int TResult;
2935 TCreateView( const QString& theType, bool visible, const int width, const int height )
2941 virtual void Execute()
2943 LightApp_Application* app = getApplication();
2945 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2947 QWidget* wnd = viewMgr->getActiveView();
2948 myResult = viewMgr->getActiveView()->getId();
2951 wnd->setVisible(false);
2952 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2956 if (myWidth > 0 && myHeight > 0) {
2957 #ifndef DISABLE_PLOT2DVIEWER
2958 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2959 if ( wnd2D ) wnd = wnd2D->getViewFrame();
2960 #endif // DISABLE_PLOT2DVIEWER
2961 wnd->setGeometry( 0, 0, myWidth, myHeight );
2968 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2970 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2971 QCoreApplication::processEvents();
2976 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2977 \brief Create new view with custom widget embedded and activate it
2978 \param type viewer type
2979 \param w custom widget
2980 \return integer identifier of created view (or -1 if view could not be created)
2983 class TCreateViewWg: public SALOME_Event
2986 typedef int TResult;
2990 TCreateViewWg( const QString& theType, QWidget* w )
2994 virtual void Execute()
2996 LightApp_Application* app = getApplication();
2998 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3000 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3002 myResult = wnd->getId();
3007 int SalomePyQt::createView( const QString& type, QWidget* w )
3009 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3010 QCoreApplication::processEvents();
3015 \fn bool SalomePyQt::closeView( const int id );
3017 \param id window identifier
3018 \return \c true if operation is completed successfully and \c false otherwise
3021 class TCloseView: public SALOME_Event
3024 typedef bool TResult;
3027 TCloseView( const int id )
3028 : myResult( false ),
3030 virtual void Execute()
3032 SUIT_ViewWindow* wnd = getWnd( myWndId );
3034 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3042 bool SalomePyQt::closeView( const int id )
3044 return ProcessEvent( new TCloseView( id ) );
3048 \fn int SalomePyQt::cloneView( const int id );
3049 \brief Clone view (if this operation is supported for specified view type)
3050 \param id window identifier
3051 \return integer identifier of the cloned view or -1 or operation could not be performed
3054 class TCloneView: public SALOME_Event
3057 typedef int TResult;
3060 TCloneView( const int id )
3063 virtual void Execute()
3065 SUIT_ViewWindow* wnd = getWnd( myWndId );
3067 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3069 #ifndef DISABLE_OCCVIEWER
3070 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3071 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3072 occView->onCloneView();
3073 wnd = viewMgr->getActiveView();
3075 myResult = wnd->getId();
3077 #endif // DISABLE_OCCVIEWER
3078 #ifndef DISABLE_PLOT2DVIEWER
3079 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3080 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3081 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3082 if ( viewMgr2d && srcWnd2d ) {
3083 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3084 myResult = resWnd->getId();
3087 #endif // DISABLE_OCCVIEWER
3092 int SalomePyQt::cloneView( const int id )
3094 return ProcessEvent( new TCloneView( id ) );
3098 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3099 \brief Set view visibility.
3100 \param id window identifier
3101 \param visible new visiblity
3104 void SalomePyQt::setViewVisible( const int id, const bool visible )
3106 class TEvent: public SALOME_Event
3111 TEvent( const int id, const bool visible )
3112 : myWndId( id ), myVisible( visible ) {}
3113 virtual void Execute()
3115 SUIT_ViewWindow* wnd = getWnd( myWndId );
3116 if ( wnd ) wnd->setVisible( myVisible );
3119 ProcessVoidEvent( new TEvent( id, visible ) );
3123 \fn bool SalomePyQt::isViewVisible( const int id );
3124 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3125 \param id window identifier
3126 \return \c true if view is visible and \c false otherwise
3129 class TIsViewVisible: public SALOME_Event
3132 typedef bool TResult;
3135 TIsViewVisible( const int id )
3136 : myResult( false ),
3138 virtual void Execute()
3140 SUIT_ViewWindow* wnd = getWnd( myWndId );
3143 QWidget* p = wnd->parentWidget();
3144 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3148 bool SalomePyQt::isViewVisible( const int id )
3150 return ProcessEvent( new TIsViewVisible( id ) );
3154 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3155 \brief Set / clear view's "closable" option. By default any view is closable
3156 (i.e. can be closed by the user).
3157 \param id window identifier
3158 \param on new "closable" option's value
3161 void SalomePyQt::setViewClosable( const int id, const bool on )
3163 class TEvent: public SALOME_Event
3168 TEvent( const int id, const bool on )
3169 : myWndId( id ), myOn( on ) {}
3170 virtual void Execute()
3172 SUIT_ViewWindow* wnd = getWnd( myWndId );
3173 if ( wnd ) wnd->setClosable( myOn );
3176 ProcessVoidEvent( new TEvent( id, on ) );
3180 \fn bool SalomePyQt::isViewClosable( const int id );
3181 \brief Check whether view is closable (i.e. can be closed by the user)
3182 \param id window identifier
3183 \return \c true if view is closable or \c false otherwise
3186 class TIsViewClosable: public SALOME_Event
3189 typedef bool TResult;
3192 TIsViewClosable( const int id )
3195 virtual void Execute()
3197 SUIT_ViewWindow* wnd = getWnd( myWndId );
3199 myResult = wnd->closable();
3203 bool SalomePyQt::isViewClosable( const int id )
3205 return ProcessEvent( new TIsViewClosable( id ) );
3209 \fn bool SalomePyQt::groupAllViews();
3210 \brief Group all views to the single tab area
3211 \return \c true if operation is completed successfully and \c false otherwise
3214 class TGroupAllViews: public SALOME_Event
3217 typedef bool TResult;
3220 : myResult( false ) {}
3221 virtual void Execute()
3223 LightApp_Application* app = getApplication();
3225 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3227 QtxWorkstack* wStack = tabDesk->workstack();
3236 bool SalomePyQt::groupAllViews()
3238 return ProcessEvent( new TGroupAllViews() );
3242 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3243 \brief Split tab area to which view with identifier belongs to
3244 \param id window identifier
3245 \param ori orientation of split operation
3246 \param action action to be performed
3247 \return \c true if operation is completed successfully \c false otherwise
3250 class TSplitView: public SALOME_Event
3253 typedef bool TResult;
3258 TSplitView( const int id,
3259 const Orientation ori,
3260 const Action action )
3261 : myResult( false ),
3264 myAction( action ) {}
3265 virtual void Execute()
3267 SUIT_ViewWindow* wnd = getWnd( myWndId );
3270 // wnd->setFocus(); ???
3273 if ( getApplication() ) {
3274 STD_TabDesktop* desk =
3275 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3277 QtxWorkstack* wStack = desk->workstack();
3279 Qt::Orientation qtOri =
3280 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3282 QtxWorkstack::SplitType sType;
3283 if ( myAction == MoveWidget )
3284 sType = QtxWorkstack::SplitMove;
3285 else if ( myAction == LeaveWidget )
3286 sType = QtxWorkstack::SplitStay;
3288 sType = QtxWorkstack::SplitAt;
3290 wStack->Split( wnd, qtOri, sType );
3298 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3300 return ProcessEvent( new TSplitView( id, ori, action ) );
3304 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3305 \brief Move view with the first identifier to the same area which
3306 another view with the second identifier belongs to
3307 \param id source window identifier
3308 \param id_to destination window identifier
3309 param before specifies whether the first viewt has to be moved before or after
3311 \return \c true if operation is completed successfully and \c false otherwise
3314 class TMoveView: public SALOME_Event
3317 typedef bool TResult;
3322 TMoveView( const int id, const int id_to, const bool before )
3323 : myResult( false ),
3326 myIsBefore( before ) {}
3327 virtual void Execute()
3329 SUIT_ViewWindow* wnd = getWnd( myWndId );
3330 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3331 if ( wnd && wnd_to ) {
3332 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3333 getApplication()->desktop() )->workstack();
3335 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3339 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3341 return ProcessEvent( new TMoveView( id, id_to, before ) );
3345 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3346 \brief Get list of views identifiers that belongs to the same area as
3347 specified view (excluding it)
3348 \param id window identifier
3349 \return list of views identifiers
3352 class TNeighbourViews: public SALOME_Event
3355 typedef QList<int> TResult;
3358 TNeighbourViews( const int id )
3360 virtual void Execute()
3363 SUIT_ViewWindow* wnd = getWnd( myWndId );
3365 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3366 getApplication()->desktop() )->workstack();
3368 QWidgetList wgList = wStack->windowList( wnd );
3370 foreach ( wg, wgList ) {
3371 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3372 if ( tmpWnd && tmpWnd != wnd )
3373 myResult.append( tmpWnd->getId() );
3379 QList<int> SalomePyQt::neighbourViews( const int id )
3381 return ProcessEvent( new TNeighbourViews( id ) );
3386 \fn void SalomePyQt::createRoot();
3387 \brief Initialize root data object.
3389 Does nothing if root is already initialized.
3392 void SalomePyQt::createRoot()
3394 class TEvent: public SALOME_Event
3398 virtual void Execute()
3400 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3402 SALOME_PYQT_DataModelLight* dm =
3403 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3408 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3412 ProcessVoidEvent( new TEvent() );
3416 \fn QString SalomePyQt::createObject( const QString& parent );
3417 \brief Create empty data object
3418 \param parent entry of parent data object
3419 \return entry of created data object
3422 class TCreateEmptyObjectEvent: public SALOME_Event
3425 typedef QString TResult;
3428 TCreateEmptyObjectEvent( const QString& parent )
3429 : myParent( parent ) {}
3430 virtual void Execute()
3432 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3434 myResult = module->createObject( myParent );
3437 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3441 QString SalomePyQt::createObject( const QString& parent )
3443 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3447 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3448 const QString& tooltip,const QString& parent );
3449 \brief Create new data object with specified name, icon and tooltip
3450 \param name data object name
3451 \param icon data object icon
3452 \param toolTip data object tooltip
3453 \param parent entry of parent data object
3454 \return entry of created data object
3457 class TCreateObjectEvent: public SALOME_Event
3460 typedef QString TResult;
3466 TCreateObjectEvent( const QString& name,
3467 const QString& icon,
3468 const QString& tooltip,
3469 const QString& parent )
3472 myToolTip( tooltip ),
3473 myParent( parent ) {}
3474 virtual void Execute()
3476 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3478 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3481 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3485 QString SalomePyQt::createObject( const QString& name,
3486 const QString& icon,
3487 const QString& toolTip,
3488 const QString& parent )
3490 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3495 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3496 \brief Set data object name
3497 \param entry data object entry
3498 \param name data object name
3500 class TSetNameEvent: public SALOME_Event
3505 TSetNameEvent( const QString& entry,
3506 const QString& name )
3509 virtual void Execute()
3511 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3513 module->setName( myEntry, myName );
3516 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3520 void SalomePyQt::setName( const QString& entry, const QString& name )
3522 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3526 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3527 \brief Set data object icon
3528 \param entry data object entry
3529 \param icon data object icon file name (icon is loaded from module resources)
3532 class TSetIconEvent: public SALOME_Event
3537 TSetIconEvent( const QString& entry,
3538 const QString& icon )
3541 virtual void Execute()
3543 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3545 module->setIcon( myEntry, myIcon );
3548 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3553 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3555 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3559 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3560 \brief Set data object tooltip
3561 \param entry data object entry
3562 \param toolTip data object tooltip
3565 class TSetToolTipEvent: public SALOME_Event
3570 TSetToolTipEvent( const QString& entry,
3571 const QString& toolTip )
3573 myToolTip( toolTip ) {}
3574 virtual void Execute()
3576 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3578 module->setToolTip( myEntry, myToolTip );
3581 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3585 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3587 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3591 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3592 \brief Set reference to another data object
3593 \param entry data object entry
3594 \param refEntry referenced data object entry
3597 class TSetRefEvent: public SALOME_Event
3602 TSetRefEvent( const QString& entry,
3603 const QString& refEntry )
3605 myRefEntry( refEntry ) {}
3606 virtual void Execute()
3608 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3610 module->setReference( myEntry, myRefEntry );
3613 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3617 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3619 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3623 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3624 \brief Set data object color
3625 \param entry data object entry
3626 \param color data object color
3629 class TSetColorEvent: public SALOME_Event
3634 TSetColorEvent( const QString& entry,
3635 const QColor& color )
3638 virtual void Execute()
3640 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3642 module->setColor( myEntry, myColor );
3645 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3649 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3651 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3655 \fn QString SalomePyQt::getName( const QString& entry );
3656 \brief Get data object name
3657 \param entry data object entry
3658 \return data object name
3661 class TGetNameEvent: public SALOME_Event
3664 typedef QString TResult;
3667 TGetNameEvent( const QString& entry )
3668 : myEntry( entry ) {}
3669 virtual void Execute()
3671 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3673 myResult = module->getName( myEntry );
3676 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3680 QString SalomePyQt::getName( const QString& entry )
3682 return ProcessEvent( new TGetNameEvent( entry ) );
3686 \fn QString SalomePyQt::getToolTip( const QString& entry );
3687 \brief Get data object tooltip
3688 \param entry data object entry
3689 \return data object tooltip
3692 class TGetToolTipEvent: public SALOME_Event
3695 typedef QString TResult;
3698 TGetToolTipEvent( const QString& entry )
3699 : myEntry( entry ) {}
3700 virtual void Execute()
3702 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3704 myResult = module->getToolTip( myEntry );
3707 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3711 QString SalomePyQt::getToolTip( const QString& entry )
3713 return ProcessEvent( new TGetToolTipEvent( entry ) );
3717 \fn QString SalomePyQt::getReference( const QString& entry );
3718 \brief Get entry of the referenced object (if there's any)
3719 \param entry data object entry
3720 \return referenced data object entry
3723 class TGetRefEvent: public SALOME_Event
3726 typedef QString TResult;
3729 TGetRefEvent( const QString& entry )
3730 : myEntry( entry ) {}
3731 virtual void Execute()
3733 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3735 myResult = module->getReference( myEntry );
3738 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3742 QString SalomePyQt::getReference( const QString& entry )
3744 return ProcessEvent( new TGetRefEvent( entry ) );
3748 \fn QColor SalomePyQt::getColor( const QString& entry );
3749 \brief Get data object color
3750 \param entry data object entry
3751 \return data object color
3754 class TGetColorEvent: public SALOME_Event
3757 typedef QColor TResult;
3760 TGetColorEvent( const QString& entry )
3761 : myEntry( entry ) {}
3762 virtual void Execute()
3764 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3766 myResult = module->getColor( myEntry );
3769 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3773 QColor SalomePyQt::getColor( const QString& entry )
3775 return ProcessEvent( new TGetColorEvent( entry ) );
3779 \fn void SalomePyQt::removeChildren( const QString& entry );
3780 \brief Remove all child data objects from specified data object
3781 \param entry data object entry
3784 class TRemoveChildEvent: public SALOME_Event
3788 TRemoveChildEvent( const QString& entry )
3789 : myEntry( entry ) {}
3790 virtual void Execute()
3792 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3794 module->removeChildren( myEntry );
3797 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3801 void SalomePyQt::removeChildren( const QString& entry )
3803 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3805 void SalomePyQt::removeChild( const QString& entry )
3807 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3808 removeChildren( entry );
3812 \fn void SalomePyQt::removeObject( const QString& entry );
3813 \brief Remove object by entry
3814 \param entry data object entry
3817 class TRemoveObjectEvent: public SALOME_Event
3822 TRemoveObjectEvent( const QString& entry )
3823 : myEntry( entry ) {}
3824 virtual void Execute()
3826 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3828 module->removeObject( myEntry );
3831 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3835 void SalomePyQt::removeObject( const QString& entry )
3837 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3841 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3842 \brief Get entries of all child data objects of specified data object
3843 \param entry data object entry
3844 \param recursive \c true for recursive processing
3847 class TGetChildrenEvent: public SALOME_Event
3850 typedef QStringList TResult;
3854 TGetChildrenEvent( const QString& entry, const bool recursive )
3856 myRecursive( recursive ) {}
3857 virtual void Execute()
3859 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3861 myResult = module->getChildren( myEntry, myRecursive );
3864 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3868 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3870 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3873 #ifndef DISABLE_PLOT2DVIEWER
3874 // Next set of methods relates to the Plot2d viewer functionality
3877 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3878 \brief Display theCurve in view
3879 \param id window identifier
3880 \param theCurve curve to display
3883 class TDisplayCurve: public SALOME_Event
3887 Plot2d_Curve* myCurve;
3888 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3889 virtual void Execute() {
3890 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3892 wnd->getViewFrame()->displayCurve( myCurve );
3895 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3897 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
3901 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3902 \brief Erase theCurve in view
3903 \param id window identifier
3904 \param theCurve curve to erase
3907 class TEraseCurve: public SALOME_Event
3911 Plot2d_Curve* myCurve;
3912 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3913 virtual void Execute() {
3914 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3915 wnd->getViewFrame()->eraseCurve( myCurve );
3918 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3920 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
3924 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3925 \brief Delete theCurve from all views
3926 \param theCurve curve to delete
3929 class TDeleteCurve: public SALOME_Event
3932 Plot2d_Curve* myCurve;
3933 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3934 virtual void Execute() {
3935 LightApp_Application* app = getApplication();
3937 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3939 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3940 SUIT_ViewWindow* wnd;
3941 foreach ( wnd, wndlist ) {
3942 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3944 aP2d->getViewFrame()->eraseObject( myCurve );
3950 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3952 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3956 \brief updateCurves (repaint) curves in view window.
3958 void SalomePyQt::updateCurves( const int id )
3960 class TEvent: public SALOME_Event
3964 TEvent( const int id ) : myWndId( id ) {}
3965 virtual void Execute()
3967 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3969 wnd->getViewFrame()->DisplayAll();
3972 ProcessVoidEvent( new TEvent( id ) );
3976 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3977 \brief Get title of corresponding type
3978 \param id window identifier
3979 \param type is type of title
3980 \return title of corresponding type
3983 class TGetPlot2dTitle: public SALOME_Event
3986 typedef QString TResult;
3990 TGetPlot2dTitle(const int id, ObjectType type) :
3993 virtual void Execute() {
3994 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3996 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
3999 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4001 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4006 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4007 \brief Set title of corresponding type
4008 \param id window identifier
4010 \param type is type of title
4014 class TSetPlot2dTitle: public SALOME_Event
4018 Plot2d_Curve* myCurve;
4022 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4027 virtual void Execute() {
4028 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4029 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4032 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4034 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4038 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4039 \brief Get list of Plot2d view ranges
4040 \param id window identifier
4041 \return list of view ranges (XMin, XMax, YMin, YMax)
4044 class TFitRangeByCurves: public SALOME_Event
4047 typedef QList<double> TResult;
4050 TFitRangeByCurves( const int id )
4052 virtual void Execute()
4055 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4057 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4058 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4059 myResult.append( XMin );
4060 myResult.append( XMax );
4061 myResult.append( YMin );
4062 myResult.append( YMax );
4066 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4068 return ProcessEvent( new TFitRangeByCurves( id ) );
4072 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4073 \brief Get list of current Plot2d view ranges
4074 \param id window identifier
4075 \return list of view ranges (XMin, XMax, YMin, YMax)
4078 class TFitRangeCurrent: public SALOME_Event
4081 typedef QList<double> TResult;
4084 TFitRangeCurrent( const int id )
4086 virtual void Execute()
4089 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4091 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4092 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4093 myResult.append( XMin );
4094 myResult.append( XMax );
4095 myResult.append( YMin );
4096 myResult.append( YMax );
4100 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4102 return ProcessEvent( new TFitRangeCurrent( id ) );
4106 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4107 \brief Set range of Plot2d view
4108 \param id window identifier
4115 class TPlot2dFitRange: public SALOME_Event
4123 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4129 virtual void Execute() {
4130 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4132 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4135 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4137 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4140 // End of methods related to the Plot2d viewer functionality
4141 #endif // DISABLE_PLOT2DVIEWER
4144 \brief Process Qt event loop
4146 void SalomePyQt::processEvents()
4148 QCoreApplication::processEvents();
4152 \brief Set visibility state for given object
4153 \param theEntry study ID of the object
4154 \param theState visibility state
4156 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4158 class TEvent: public SALOME_Event
4163 TEvent( const QString& theEntry, int theState ):
4164 myEntry( theEntry ), myState( theState ) {}
4165 virtual void Execute()
4167 LightApp_Study* aStudy = getActiveStudy();
4170 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4173 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4177 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4178 \brief Get visibility state for given object
4179 \param theEntry study ID of the object
4180 \return visibility state
4183 class TGetVisibilityStateEvent: public SALOME_Event
4186 typedef int TResult;
4189 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4190 virtual void Execute()
4192 LightApp_Study* aStudy = getActiveStudy();
4194 myResult = aStudy->visibilityState( myEntry );
4197 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4199 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4203 \brief Set position of given object in the tree
4204 \param theEntry study ID of the object
4205 \param thePos position
4207 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4209 class TEvent: public SALOME_Event
4214 TEvent( const QString& theEntry, int thePos ):
4215 myEntry( theEntry ), myPos( thePos ) {}
4216 virtual void Execute()
4218 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4220 module->setObjectPosition( myEntry, myPos );
4223 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4227 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4228 \brief Get position of given object in the tree
4229 \param theEntry study ID of the object
4233 class TGetObjectPositionEvent: public SALOME_Event
4236 typedef int TResult;
4239 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4240 virtual void Execute()
4242 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4244 myResult = module->getObjectPosition( myEntry );
4247 int SalomePyQt::getObjectPosition( const QString& theEntry )
4249 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4253 \brief Start recordind a log of Python commands from embedded console
4254 \param theFileName output lof file name
4256 void SalomePyQt::startPyLog( const QString& theFileName )
4258 class TEvent: public SALOME_Event
4262 TEvent( const QString& theFileName ):
4263 myFileName( theFileName ) {}
4264 virtual void Execute()
4266 if ( getApplication() ) {
4267 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4268 if ( pyConsole ) pyConsole->startLog( myFileName );
4272 ProcessVoidEvent( new TEvent( theFileName ) );
4276 \brief Stop recordind a log of Python commands from embedded console
4278 void SalomePyQt::stopPyLog()
4280 class TEvent: public SALOME_Event
4284 virtual void Execute()
4286 if ( getApplication() ) {
4287 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4288 if ( pyConsole ) pyConsole->stopLog();
4292 ProcessVoidEvent( new TEvent() );