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 );
250 \param p parent object
252 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
254 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
256 mySelMgr = app->selectionMgr();
257 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
258 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
265 SALOME_Selection::~SALOME_Selection()
267 LightApp_Application* app = 0;
268 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
269 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
270 if ( it.value() == this ) app = it.key();
272 if ( app ) SelMap.remove( app );
276 \brief Called when selection manager is destroyed (usually
277 when the study is closed).
279 void SALOME_Selection::onSelMgrDestroyed()
285 \brief Clear the selection.
287 void SALOME_Selection::Clear()
289 class TEvent: public SALOME_Event
291 LightApp_SelectionMgr* mySelMgr;
293 TEvent( LightApp_SelectionMgr* selMgr )
294 : mySelMgr( selMgr ) {}
295 virtual void Execute()
298 mySelMgr->clearSelected();
301 ProcessVoidEvent( new TEvent( mySelMgr ) );
305 \brief Clear the selection.
307 void SALOME_Selection::ClearIObjects()
313 Removes all selection filters.
315 void SALOME_Selection::ClearFilters()
317 class TEvent: public SALOME_Event
319 LightApp_SelectionMgr* mySelMgr;
321 TEvent( LightApp_SelectionMgr* selMgr )
322 : mySelMgr( selMgr ) {}
323 virtual void Execute()
326 mySelMgr->clearFilters();
329 ProcessVoidEvent( new TEvent( mySelMgr ) );
334 \brief The class provides utility functions which can be used in the Python
335 to operate with the SALOME GUI.
337 All the functionality of this class is implemented as static methods, so they
338 can be called with the class name prefixed or via creation of the class instance.
339 For example, next both ways of SalomePyQt class usage are legal:
341 from SalomePyQt import *
343 # using SalomePyQt class instance
344 desktop = sg.getDesktop()
345 # using SalomePyQt class directly
346 menubar = SalomePyQt.getMainMenuBar()
351 \fn QWidget* SalomePyQt::getDesktop();
352 \brief Get the active application's desktop window.
353 \return desktop window or 0 if there is no any
356 class TGetDesktopEvent: public SALOME_Event
359 typedef QWidget* TResult;
361 TGetDesktopEvent() : myResult( 0 ) {}
362 virtual void Execute()
364 if ( getApplication() )
365 myResult = (QWidget*)( getApplication()->desktop() );
368 QWidget* SalomePyQt::getDesktop()
370 return ProcessEvent( new TGetDesktopEvent() );
374 \fn QWidget* SalomePyQt::getMainFrame();
375 \brief Get current application's main frame widget [obsolete].
377 Main frame widget is an internal widget of the application
378 desktop window (workspace).
380 \return workspace widget (0 on any error)
383 class TGetMainFrameEvent: public SALOME_Event
386 typedef QWidget* TResult;
388 TGetMainFrameEvent() : myResult( 0 ) {}
389 virtual void Execute()
391 if ( getApplication() ) {
392 SUIT_Desktop* aDesktop = getApplication()->desktop();
393 myResult = (QWidget*)( aDesktop->centralWidget() );
397 QWidget* SalomePyQt::getMainFrame()
399 return ProcessEvent( new TGetMainFrameEvent() );
403 \fn QMenuBar* SalomePyQt::getMainMenuBar();
404 \brief Get current application desktop's main menu.
405 \return main menu object (0 on any error)
408 class TGetMainMenuBarEvent: public SALOME_Event
411 typedef QMenuBar* TResult;
413 TGetMainMenuBarEvent() : myResult( 0 ) {}
414 virtual void Execute()
416 if ( LightApp_Application* anApp = getApplication() ) {
417 myResult = anApp->desktop()->menuBar();
421 QMenuBar* SalomePyQt::getMainMenuBar()
423 return ProcessEvent( new TGetMainMenuBarEvent() );
427 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
428 \brief Get main menu's child popup submenu by its identifier.
430 This function is obsolete.
431 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
433 \param menu menu identifier
434 \return popup submenu object or 0 if it does not exist
438 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
439 \brief Get main menu's child popup submenu by its name.
441 The function creates menu if it does not exist.
443 \param menu menu name
444 \return popup submenu object (0 on any error)
447 class TGetPopupMenuEvent: public SALOME_Event
450 typedef QMenu* TResult;
453 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
454 virtual void Execute()
456 LightApp_Application* anApp = getApplication();
457 if ( anApp && !myMenuName.isEmpty() ) {
458 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
459 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
464 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
469 menuName = getMenuName( "MEN_DESK_FILE" ); break;
471 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
473 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
475 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
477 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
479 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
481 menuName = getMenuName( "MEN_DESK_HELP" ); break;
483 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
485 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
487 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
491 \fn QTreeView* SalomePyQt::getObjectBrowser();
492 \brief Get object browser
493 \return object browser for the active study or 0 in case of error
496 class TGetObjectBrowserEvent: public SALOME_Event
499 typedef QTreeView* TResult;
501 TGetObjectBrowserEvent() : myResult( 0 ) {}
502 virtual void Execute()
504 LightApp_Application* anApp = getApplication();
505 if ( anApp && anApp->objectBrowser() ) {
506 myResult = anApp->objectBrowser()->treeView();
510 QTreeView* SalomePyQt::getObjectBrowser()
512 return ProcessEvent( new TGetObjectBrowserEvent() );
516 \fn int SalomePyQt::getStudyId();
517 \brief Get active study's identifier.
518 \return active study ID or 0 if there is no active study
521 class TGetStudyIdEvent: public SALOME_Event
526 TGetStudyIdEvent() : myResult( 0 ) {}
527 virtual void Execute()
529 if ( LightApp_Study* aStudy = getActiveStudy() ) {
530 myResult = aStudy->id();
534 int SalomePyQt::getStudyId()
536 return ProcessEvent( new TGetStudyIdEvent() );
540 \fn SALOME_Selection* SalomePyQt::getSelection();
541 \brief Get the selection object for the current study.
543 Creates a Selection object if it has not been created yet.
545 \return selection object (0 on error)
548 class TGetSelectionEvent: public SALOME_Event
551 typedef SALOME_Selection* TResult;
553 TGetSelectionEvent() : myResult( 0 ) {}
554 virtual void Execute()
556 myResult = SALOME_Selection::GetSelection( getApplication() );
559 SALOME_Selection* SalomePyQt::getSelection()
561 return ProcessEvent( new TGetSelectionEvent() );
565 \fn QStringList* SalomePyQt::setSelection(const QStringList& );
566 \brief Send local selection for notification.
568 The list of locally selected objects (study entries) is sent for notification of
569 other listening entities (modules, viewers...).
572 class TSetSelectionEvent: public SALOME_Event
574 QStringList myEntryList;
576 TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {}
577 virtual void Execute()
579 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
580 if ( !module ) return;
581 module->setLocalSelected(myEntryList);
584 void SalomePyQt::setSelection( const QStringList& entryList)
586 return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
590 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
591 \brief Put an information message to the current application's
594 Optional second delay parameter (\a sec) can be used to specify
595 time of the message diplaying in seconds. If this parameter is less
596 or equal to zero, the constant message will be put.
598 \param msg message text
599 \param sec message displaying time in seconds
602 class TPutInfoEvent: public SALOME_Event
607 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
608 virtual void Execute()
610 if ( LightApp_Application* anApp = getApplication() ) {
611 anApp->putInfo( myMsg, mySecs * 1000 );
615 void SalomePyQt::putInfo( const QString& msg, const int sec )
617 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
621 \fn const QString SalomePyQt::getActiveComponent();
622 \brief Get the currently active module name (for the current study).
623 \return active module name or empty string if there is no active module
626 class TGetActiveComponentEvent: public SALOME_Event
629 typedef QString TResult;
631 TGetActiveComponentEvent() {}
632 virtual void Execute()
634 if ( LightApp_Application* anApp = getApplication() ) {
635 if ( CAM_Module* mod = anApp->activeModule() ) {
636 myResult = mod->name();
641 const QString SalomePyQt::getActiveComponent()
643 return ProcessEvent( new TGetActiveComponentEvent() );
647 \fn PyObject* SalomePyQt::getActivePythonModule();
648 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
649 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
652 class TGetActivePyModuleEvent: public SALOME_Event
655 typedef PyObject* TResult;
657 TGetActivePyModuleEvent() : myResult( Py_None ) {}
658 virtual void Execute()
660 PyModuleHelper* helper = getPythonHelper();
662 myResult = (PyObject*)helper->pythonModule();
665 PyObject* SalomePyQt::getActivePythonModule()
667 return ProcessEvent( new TGetActivePyModuleEvent() );
671 \fn bool SalomePyQt::activateModule( const QString& modName );
672 \brief Activates SALOME module with the given name
673 \return True if the module has been activated and False otherwise.
676 class TActivateModuleEvent: public SALOME_Event
679 typedef bool TResult;
681 QString myModuleName;
682 TActivateModuleEvent( const QString& modName )
683 : myResult( false ), myModuleName( modName ) {}
684 virtual void Execute()
686 if ( LightApp_Application* anApp = getApplication() ) {
687 myResult = anApp->activateModule( myModuleName );
691 bool SalomePyQt::activateModule( const QString& modName )
693 return ProcessEvent( new TActivateModuleEvent( modName ) );
697 \brief Update an Object Browser of the specified (by identifier) study.
699 If \a studyId <= 0 the active study's object browser is updated.
700 The \a updateSelection parameter is obsolete and currently is not used.
701 This parameter will be removed in future, so try to avoid its usage in
704 \brief studyId study identifier
705 \brief updateSelection update selection flag (not used)
708 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
710 class TEvent: public SALOME_Event
713 bool myUpdateSelection;
715 TEvent( const int studyId, bool updateSelection )
716 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
717 virtual void Execute()
719 if ( SUIT_Session::session() ) {
720 if ( getActiveStudy() && myStudyId <= 0 )
721 myStudyId = getActiveStudy()->id();
722 if ( myStudyId > 0 ) {
723 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
724 QList<SUIT_Application*>::Iterator it;
725 for( it = apps.begin(); it != apps.end(); ++it ) {
726 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
727 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
728 anApp->updateObjectBrowser();
736 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
741 SalomePyQt::isModified()
742 \return The modification status of the data model
743 for the currently active Python module
744 \note This function is supported for "light" Python-based SALOME modules only.
747 class TIsModifiedEvent: public SALOME_Event
750 typedef bool TResult;
752 TIsModifiedEvent() : myResult( false ) {}
753 virtual void Execute()
755 LightApp_Module* module = getActiveModule();
759 SALOME_PYQT_DataModelLight* aModel =
760 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
762 myResult = aModel->isModified();
765 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
769 bool SalomePyQt::isModified()
771 return ProcessEvent(new TIsModifiedEvent());
775 SalomePyQt::setModified()
777 Sets the modification status of the data model for
778 the currently active Python module. This method should be used
779 by the Python code in order to enable/disable "Save" operation
780 depending on the module's data state.
782 \note This function is supported for "light" Python-based SALOME modules only.
784 \param New modification status of the data model
788 void SalomePyQt::setModified( bool flag )
790 class TEvent: public SALOME_Event
796 virtual void Execute()
798 LightApp_Module* module = getActiveModule();
802 SALOME_PYQT_DataModelLight* model =
803 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
805 LightApp_Application* app = module->getApp();
807 if ( model && app ) {
808 model->setModified( myFlag );
809 app->updateActions();
812 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
816 ProcessVoidEvent( new TEvent( flag ) );
820 \brief Add string setting to the application preferences.
822 The parameter \a autoValue is obsolete parameter and currently is not used.
823 This parameter will be removed in future, so try to avoid its usage in
826 This function is obsolete. Use one of addSetting() instead.
828 \param name setting name (it should be of kind <section:setting> where
829 \c section is resources section name and \c setting is setting name)
830 \param value new setting value
831 \param autoValue (not used)
833 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
835 class TEvent: public SALOME_Event
841 TEvent( const QString& name, const QString& value, bool autoValue )
842 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
843 virtual void Execute()
845 if ( SUIT_Session::session() ) {
846 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
847 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
848 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
849 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
850 if ( !_sec.isEmpty() && !_nam.isEmpty() )
851 resMgr->setValue( _sec, _nam, myValue );
855 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
859 \brief Add integer setting to the application preferences.
861 The parameter \a autoValue is obsolete parameter and currently is not used.
862 This parameter will be removed in future, so try to avoid its usage in
865 This function is obsolete. Use one of addSetting() instead.
867 \param name setting name (it should be of kind <section:setting> where
868 \c section is resources section name and \c setting is setting name)
869 \param value new setting value
870 \param autoValue (not used)
872 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
874 class TEvent: public SALOME_Event
880 TEvent( const QString& name, const int value, bool autoValue )
881 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
882 virtual void Execute()
884 if ( SUIT_Session::session() ) {
885 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
886 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
887 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
888 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
889 if ( !_sec.isEmpty() && !_nam.isEmpty() )
890 resMgr->setValue( _sec, _nam, myValue );
894 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
898 \brief Add double setting to the application preferences.
900 The parameter \a autoValue is obsolete parameter and currently is not used.
901 This parameter will be removed in future, so try to avoid its usage in
904 This function is obsolete. Use one of addSetting() instead.
906 \param name setting name (it should be of kind <section:setting> where
907 \c section is resources section name and \c setting is setting name)
908 \param value new setting value
909 \param autoValue (not used)
911 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
913 class TEvent: public SALOME_Event
919 TEvent( const QString& name, const double value, bool autoValue )
920 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
921 virtual void Execute()
923 if ( SUIT_Session::session() ) {
924 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
925 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
926 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
927 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
928 if ( !_sec.isEmpty() && !_nam.isEmpty() )
929 resMgr->setValue( _sec, _nam, myValue );
933 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
937 \brief Add boolean setting to the application preferences.
939 The parameter \a autoValue is obsolete parameter and currently is not used.
940 This parameter will be removed in future, so try to avoid its usage in
943 This function is obsolete. Use one of addSetting() instead.
945 \param name setting name (it should be of kind <section:setting> where
946 \c section is resources section name and \c setting is setting name)
947 \param value new setting value
948 \param autoValue (not used)
950 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
952 class TEvent: public SALOME_Event
958 TEvent( const QString& name, const bool value, bool autoValue )
959 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
960 virtual void Execute()
962 if ( SUIT_Session::session() ) {
963 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
964 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
965 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
966 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
967 if ( !_sec.isEmpty() && !_nam.isEmpty() )
968 resMgr->setValue( _sec, _nam, myValue );
972 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
976 \brief Remove setting from the application preferences.
978 This function is obsolete. Use removeSetting() instead.
980 \param name setting name (it should be of kind <section:setting> where
981 \c section is resources section name and \c setting is setting name)
983 void SalomePyQt::removeSettings( const QString& name )
985 class TEvent: public SALOME_Event
989 TEvent( const QString& name ) : myName( name ) {}
990 virtual void Execute()
992 if ( SUIT_Session::session() ) {
993 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
994 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
995 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
996 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
997 if ( !_sec.isEmpty() && !_nam.isEmpty() )
998 resMgr->remove( _sec, _nam );
1002 ProcessVoidEvent( new TEvent( name ) );
1006 \fn QString SalomePyQt::getSetting( const QString& name );
1007 \brief Get application setting value (as string represenation).
1009 This function is obsolete. Use stringSetting(), integerSetting(),
1010 boolSetting(), stringSetting() or colorSetting() instead.
1012 \param name setting name (it should be of kind <section:setting> where
1013 \c section is resources section name and \c setting is setting name)
1014 \return setting name (empty string if setting name is invalid)
1017 class TGetSettingEvent: public SALOME_Event
1020 typedef QString TResult;
1023 TGetSettingEvent( const QString& name ) : myName( name ) {}
1024 virtual void Execute()
1026 if ( SUIT_Session::session() ) {
1027 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1028 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1029 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1030 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1031 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1035 QString SalomePyQt::getSetting( const QString& name )
1037 return ProcessEvent( new TGetSettingEvent( name ) );
1041 \fn QString SalomePyQt::constant( const QString& name );
1042 \brief Get constant's value from application's resource manager.
1044 \param name name of the constant
1045 \return value of the constant
1050 class TGetConstantEvent: public SALOME_Event
1053 typedef QString TResult;
1056 TGetConstantEvent( const QString& name ) : myName( name ) {}
1057 virtual void Execute()
1059 if ( SUIT_Session::session() )
1060 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1063 QString SalomePyQt::constant( const QString& name )
1065 return ProcessEvent( new TGetConstantEvent( name ) );
1069 \brief Add constant to the application's resource manager.
1071 This function is useful to specify programmatically specific
1072 variables that are referenced in the resource setting.
1074 For example, some resource value can be set as "$(myroot)/data/files".
1075 Then, "mypath" constant can be set programmatically by the application
1076 depending on run-time requirements.
1078 \param section resources file section name
1079 \param name name of the constant
1080 \param value value of the constant
1084 void SalomePyQt::setConstant( const QString& name, const QString& value )
1086 class TEvent: public SALOME_Event
1088 QString myName, myValue;
1090 TEvent( const QString& name, const QString& value )
1091 : myName( name ), myValue( value ) {}
1092 virtual void Execute()
1094 if ( SUIT_Session::session() )
1095 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1098 ProcessVoidEvent( new TEvent( name, value ) );
1102 \brief Add double setting to the application preferences.
1103 \param section resources file section name
1104 \param name setting name
1105 \param value new setting value
1107 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1109 class TEvent: public SALOME_Event
1115 TEvent( const QString& section, const QString& name, double value )
1116 : mySection( section ), myName( name ), myValue( value ) {}
1117 virtual void Execute()
1119 if ( SUIT_Session::session() ) {
1120 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1121 if ( !mySection.isEmpty() && !myName.isEmpty() )
1122 resMgr->setValue( mySection, myName, myValue );
1126 ProcessVoidEvent( new TEvent( section, name, value ) );
1130 \brief Add integer setting to the application preferences.
1131 \param section resources file section name
1132 \param name setting name
1133 \param value new setting value
1135 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1137 class TEvent: public SALOME_Event
1143 TEvent( const QString& section, const QString& name, int value )
1144 : mySection( section ), myName( name ), myValue( value ) {}
1145 virtual void Execute()
1147 if ( SUIT_Session::session() ) {
1148 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1149 if ( !mySection.isEmpty() && !myName.isEmpty() )
1150 resMgr->setValue( mySection, myName, myValue );
1154 ProcessVoidEvent( new TEvent( section, name, value ) );
1158 \brief Add boolean setting to the application preferences.
1159 \param section resources file section name
1160 \param name setting name
1161 \param value new setting value
1162 \param dumb this parameter is used in order to avoid sip compilation error
1163 because of conflicting int and bool types
1165 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1167 class TEvent: public SALOME_Event
1173 TEvent( const QString& section, const QString& name, bool value )
1174 : mySection( section ), myName( name ), myValue( value ) {}
1175 virtual void Execute()
1177 if ( SUIT_Session::session() ) {
1178 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1179 if ( !mySection.isEmpty() && !myName.isEmpty() )
1180 resMgr->setValue( mySection, myName, myValue );
1184 ProcessVoidEvent( new TEvent( section, name, value ) );
1188 \brief Add string setting to the application preferences.
1189 \param section resources file section name
1190 \param name setting name
1191 \param value new setting value
1193 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1195 class TEvent: public SALOME_Event
1201 TEvent( const QString& section, const QString& name, const QString& value )
1202 : mySection( section ), myName( name ), myValue( value ) {}
1203 virtual void Execute()
1205 if ( SUIT_Session::session() ) {
1206 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1207 if ( !mySection.isEmpty() && !myName.isEmpty() )
1208 resMgr->setValue( mySection, myName, myValue );
1212 ProcessVoidEvent( new TEvent( section, name, value ) );
1216 \brief Add color setting to the application preferences.
1217 \param section resources file section name
1218 \param name setting name
1219 \param value new setting value
1221 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1223 class TEvent: public SALOME_Event
1229 TEvent( const QString& section, const QString& name, const QColor& value )
1230 : mySection( section ), myName( name ), myValue( value ) {}
1231 virtual void Execute()
1233 if ( SUIT_Session::session() ) {
1234 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1235 if ( !mySection.isEmpty() && !myName.isEmpty() )
1236 resMgr->setValue( mySection, myName, myValue );
1240 ProcessVoidEvent( new TEvent( section, name, value ) );
1244 \brief Add byte array setting to the application preferences.
1245 \param section resources file section name
1246 \param name setting name
1247 \param value new setting value
1249 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1251 class TEvent: public SALOME_Event
1257 TEvent( const QString& section, const QString& name, const QByteArray& value )
1258 : mySection( section ), myName( name ), myValue( value ) {}
1259 virtual void Execute()
1261 if ( SUIT_Session::session() ) {
1262 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1263 if ( !mySection.isEmpty() && !myName.isEmpty() )
1264 resMgr->setValue( mySection, myName, myValue );
1268 ProcessVoidEvent( new TEvent( section, name, value ) );
1272 \fn int SalomePyQt::integerSetting( const QString& section,
1273 const QString& name,
1275 \brief Get integer setting from the application preferences.
1276 \param section resources file section name
1277 \param name setting name
1278 \param def default value which is returned if the setting is not found
1279 \return setting value
1282 class TGetIntSettingEvent: public SALOME_Event
1285 typedef int TResult;
1290 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1291 : mySection( section ), myName( name ), myDefault( def ) {}
1292 virtual void Execute()
1294 if ( SUIT_Session::session() ) {
1295 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1296 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1300 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1302 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1306 \fn double SalomePyQt::doubleSetting( const QString& section,
1307 const QString& name,
1309 \brief Get double setting from the application preferences.
1310 \param section resources file section name
1311 \param name setting name
1312 \param def default value which is returned if the setting is not found
1313 \return setting value
1316 class TGetDblSettingEvent: public SALOME_Event
1319 typedef double TResult;
1324 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1325 : mySection( section ), myName( name ), myDefault( def ) {}
1326 virtual void Execute()
1328 if ( SUIT_Session::session() ) {
1329 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1330 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1334 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1336 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1340 \fn bool SalomePyQt::boolSetting( const QString& section,
1341 const QString& name,
1343 \brief Get boolean setting from the application preferences.
1344 \param section resources file section name
1345 \param name setting name
1346 \param def default value which is returned if the setting is not found
1347 \return setting value
1350 class TGetBoolSettingEvent: public SALOME_Event
1353 typedef bool TResult;
1358 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1359 : mySection( section ), myName( name ), myDefault( def ) {}
1360 virtual void Execute()
1362 if ( SUIT_Session::session() ) {
1363 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1364 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1368 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1370 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1374 \fn QString SalomePyQt::stringSetting( const QString& section,
1375 const QString& name,
1378 \brief Get string setting from the application preferences.
1379 \param section resources file section name
1380 \param name setting name
1381 \param def default value which is returned if the setting is not found
1382 \param subst \c true to make substitution, \c false to get "raw" value
1383 \return setting value
1386 class TGetStrSettingEvent: public SALOME_Event
1389 typedef QString TResult;
1395 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1396 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1397 virtual void Execute()
1399 if ( SUIT_Session::session() ) {
1400 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1401 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1405 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1407 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1411 \fn QColor SalomePyQt::colorSetting( const QString& section,
1412 const QString& name,
1414 \brief Get color setting from the application preferences.
1415 \param section resources file section name
1416 \param name setting name
1417 \param def default value which is returned if the setting is not found
1418 \return setting value
1421 class TGetColorSettingEvent: public SALOME_Event
1424 typedef QColor TResult;
1429 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1430 : mySection( section ), myName( name ), myDefault( def ) {}
1431 virtual void Execute()
1433 if ( SUIT_Session::session() ) {
1434 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1435 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1439 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1441 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1445 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1446 const QString& name,
1447 const QByteArray def );
1448 \brief Get byte array setting from the application preferences.
1449 \param section resources file section name
1450 \param name setting name
1451 \param def default value which is returned if the setting is not found
1452 \return setting value
1455 class TGetByteArraySettingEvent: public SALOME_Event
1458 typedef QByteArray TResult;
1463 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1464 : mySection( section ), myName( name ), myDefault( def ) {}
1465 virtual void Execute()
1467 if ( SUIT_Session::session() ) {
1468 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1469 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1473 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1475 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1479 \brief Remove setting from the application preferences.
1480 \param section resources file section name
1481 \param name setting name
1483 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1485 class TEvent: public SALOME_Event
1490 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1491 virtual void Execute()
1493 if ( SUIT_Session::session() ) {
1494 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1495 if ( !mySection.isEmpty() && !myName.isEmpty() )
1496 resMgr->remove( mySection, myName );
1500 ProcessVoidEvent( new TEvent( section, name ) );
1504 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1505 \brief Check setting existence in the application preferences.
1506 \param section resources file section name
1507 \param name setting name
1508 \return \c true if setting exists
1511 class THasSettingEvent: public SALOME_Event
1514 typedef bool TResult;
1518 THasSettingEvent( const QString& section, const QString& name )
1519 : mySection( section ), myName( name ) {}
1520 virtual void Execute()
1522 if ( SUIT_Session::session() ) {
1523 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1524 myResult = resMgr->hasValue( mySection, myName );
1528 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1530 return ProcessEvent( new THasSettingEvent( section, name ) );
1534 \fn QStringList SalomePyQt::parameters( const QString& section );
1535 \brief Get names of preference items stored within the given section.
1536 \param section resources file section's name
1537 \return \c list of preferences items
1541 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1542 \brief Get names of preference items stored within the given section.
1543 \param section resources file section's name
1544 \return \c list of preferences items
1547 class TParametersEvent: public SALOME_Event
1550 typedef QStringList TResult;
1552 QStringList mySection;
1553 TParametersEvent( const QString& section )
1555 mySection << section;
1557 TParametersEvent( const QStringList& section )
1558 : mySection( section )
1560 virtual void Execute()
1562 if ( SUIT_Session::session() ) {
1563 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1564 myResult = resMgr->parameters( mySection );
1568 QStringList SalomePyQt::parameters( const QString& section )
1570 return ProcessEvent( new TParametersEvent( section ) );
1572 QStringList SalomePyQt::parameters( const QStringList& section )
1574 return ProcessEvent( new TParametersEvent( section ) );
1578 \fn QString SalomePyQt::getFileName( QWidget* parent,
1579 const QString& initial,
1580 const QStringList& filters,
1581 const QString& caption,
1583 \brief Show 'Open/Save file' dialog box for file selection
1584 and return a user's choice (selected file name).
1585 \param parent parent widget
1586 \param initial initial directory the dialog box to be opened in
1587 \param filters list of files filters (wildcards)
1588 \param caption dialog box title
1589 \param open if \c true, "Open File" dialog box is shown;
1590 otherwise "Save File" dialog box is shown
1591 \return selected file name (null string if user cancels operation)
1594 class TGetFileNameEvent: public SALOME_Event
1597 typedef QString TResult;
1601 QStringList myFilters;
1604 TGetFileNameEvent( QWidget* parent,
1605 const QString& initial,
1606 const QStringList& filters,
1607 const QString& caption,
1609 : myParent ( parent ),
1610 myInitial( initial ),
1611 myFilters( filters ),
1612 myCaption( caption ),
1614 virtual void Execute()
1616 if ( LightApp_Application* anApp = getApplication() ) {
1617 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1618 myCaption, myParent );
1622 QString SalomePyQt::getFileName( QWidget* parent,
1623 const QString& initial,
1624 const QStringList& filters,
1625 const QString& caption,
1628 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1632 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1633 const QString& initial,
1634 const QStringList& filters,
1635 const QString& caption );
1636 \brief Show 'Open files' dialog box for multiple files selection
1637 and return a user's choice (selected file names list).
1638 \param parent parent widget
1639 \param initial initial directory the dialog box to be opened in
1640 \param filters list of files filters (wildcards)
1641 \param caption dialog box title
1642 \return selected file names list (empty list if user cancels operation)
1645 class TGetOpenFileNamesEvent: public SALOME_Event
1648 typedef QStringList TResult;
1652 QStringList myFilters;
1654 TGetOpenFileNamesEvent( QWidget* parent,
1655 const QString& initial,
1656 const QStringList& filters,
1657 const QString& caption )
1658 : myParent ( parent ),
1659 myInitial( initial ),
1660 myFilters( filters ),
1661 myCaption( caption ) {}
1662 virtual void Execute()
1664 if ( LightApp_Application* anApp = getApplication() ) {
1665 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1669 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1670 const QString& initial,
1671 const QStringList& filters,
1672 const QString& caption )
1674 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1678 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1679 const QString& initial,
1680 const QString& caption );
1681 \brief Show 'Get Directory' dialog box for the directory selection
1682 and return a user's choice (selected directory name).
1683 \param parent parent widget
1684 \param initial initial directory the dialog box to be opened in
1685 \param caption dialog box title
1686 \return selected directory name (null string if user cancels operation)
1689 class TGetExistingDirectoryEvent: public SALOME_Event
1692 typedef QString TResult;
1697 TGetExistingDirectoryEvent( QWidget* parent,
1698 const QString& initial,
1699 const QString& caption )
1700 : myParent ( parent ),
1701 myInitial( initial ),
1702 myCaption( caption ) {}
1703 virtual void Execute()
1705 if ( LightApp_Application* anApp = getApplication() ) {
1706 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1710 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1711 const QString& initial,
1712 const QString& caption )
1714 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1718 \fn QString SalomePyQt::loadIcon( const QString& filename );
1719 \brief Load an icon from the module resources by the specified file name.
1720 \param fileName icon file name
1724 class TLoadIconEvent: public SALOME_Event
1727 typedef QIcon TResult;
1731 TLoadIconEvent( const QString& module, const QString& filename )
1732 : myModule( module ),
1733 myFileName ( filename ) {}
1734 virtual void Execute()
1736 myResult = loadIconInternal( myModule, myFileName );
1739 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1741 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1745 \brief Open external browser to display context help information.
1748 Current implementation does nothing.
1750 \param source documentation (HTML) file name
1751 \param context context (for example, HTML ancor name)
1753 void SalomePyQt::helpContext( const QString& source, const QString& context )
1755 class TEvent: public SALOME_Event
1760 TEvent( const QString& source, const QString& context )
1761 : mySource( source ), myContext( context ) {}
1762 virtual void Execute()
1764 if ( LightApp_Application* anApp = getApplication() ) {
1765 anApp->onHelpContextModule( "", mySource, myContext );
1769 ProcessVoidEvent( new TEvent( source, context ) );
1773 \fn int SalomePyQt::defaultMenuGroup();
1774 \brief Get detault menu group identifier which can be used when
1775 creating menus (insert custom menu commands).
1776 \return default menu group ID
1779 class TDefMenuGroupEvent: public SALOME_Event
1782 typedef int TResult;
1784 TDefMenuGroupEvent() : myResult( -1 ) {}
1785 virtual void Execute()
1787 myResult = PyModuleHelper::defaultMenuGroup();
1790 int SalomePyQt::defaultMenuGroup()
1792 return ProcessEvent( new TDefMenuGroupEvent() );
1798 CrTool( const QString& tBar, const QString& nBar )
1799 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1800 CrTool( const int id, const int tBar, const int idx )
1801 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1802 CrTool( const int id, const QString& tBar, const int idx )
1803 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1804 CrTool( QAction* action, const int tbId, const int id, const int idx )
1805 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1806 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1807 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1809 int execute( LightApp_Module* module ) const
1814 return module->createTool( myTbTitle, myTbName );
1816 return module->createTool( myId, myTbId, myIndex );
1818 return module->createTool( myId, myTbTitle, myIndex );
1820 return module->createTool( myAction, myTbId, myId, myIndex );
1822 return module->createTool( myAction, myTbTitle, myId, myIndex );
1837 class TCreateToolEvent: public SALOME_Event
1840 typedef int TResult;
1842 const CrTool& myCrTool;
1843 TCreateToolEvent( const CrTool& crTool )
1844 : myResult( -1 ), myCrTool( crTool ) {}
1845 virtual void Execute()
1847 LightApp_Module* module = getActiveModule();
1849 myResult = myCrTool.execute( module );
1854 \brief Create toolbar with specified name.
1855 \param tBar toolbar title (language-dependent)
1856 \param nBar toolbar name (language-independent) [optional]
1857 \return toolbar ID or -1 if toolbar creation is failed
1859 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1861 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1865 \brief Insert action with specified \a id to the toolbar.
1867 \param tBar toolbar ID
1868 \param idx required index in the toolbar
1869 \return action ID or -1 if action could not be added
1871 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1873 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1877 \brief Insert action with specified \a id to the toolbar.
1879 \param tBar toolbar name
1880 \param idx required index in the toolbar
1881 \return action ID or -1 if action could not be added
1883 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1885 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1889 \brief Insert action to the toolbar.
1891 \param tBar toolbar ID
1892 \param id required action ID
1893 \param idx required index in the toolbar
1894 \return action ID or -1 if action could not be added
1896 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1898 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1902 \brief Insert action to the toolbar.
1904 \param tBar toolbar name
1905 \param id required action ID
1906 \param idx required index in the toolbar
1907 \return action ID or -1 if action could not be added
1909 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1911 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1917 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1918 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1919 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1920 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1921 CrMenu( const int id, const int menu, const int group, const int idx )
1922 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1923 CrMenu( const int id, const QString& menu, const int group, const int idx )
1924 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1925 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1926 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1927 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1928 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1930 int execute( LightApp_Module* module ) const
1935 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1937 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1939 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1941 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1943 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1945 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1954 QString mySubMenuName;
1961 class TCreateMenuEvent: public SALOME_Event
1964 typedef int TResult;
1966 const CrMenu& myCrMenu;
1967 TCreateMenuEvent( const CrMenu& crMenu )
1968 : myResult( -1 ), myCrMenu( crMenu ) {}
1969 virtual void Execute()
1971 LightApp_Module* module = getActiveModule();
1973 myResult = myCrMenu.execute( module );
1978 \brief Create main menu.
1979 \param subMenu menu name
1980 \param menu parent menu ID
1981 \param id required menu ID
1982 \param group menu group ID
1983 \param idx required index in the menu
1984 \return menu ID or -1 if menu could not be added
1986 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1988 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1992 \brief Create main menu.
1993 \param subMenu menu name
1994 \param menu parent menu name (list of menu names separated by "|")
1995 \param id required menu ID
1996 \param group menu group ID
1997 \param idx required index in the menu
1998 \return menu ID or -1 if menu could not be added
2000 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
2002 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, 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( const int id, const int menu, const int group, const int idx )
2015 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, 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( const int id, const QString& menu, const int group, const int idx )
2028 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2032 \brief Insert action to the main menu.
2034 \param menu parent menu ID
2035 \param group menu group ID
2036 \param idx required index in the menu
2037 \return action ID or -1 if action could not be added
2039 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2041 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2045 \brief Insert action to the main menu.
2047 \param menu parent menu name (list of menu names separated by "|")
2048 \param group menu group ID
2049 \param idx required index in the menu
2050 \return action ID or -1 if action could not be added
2052 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2054 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2058 \fn QAction* SalomePyQt::createSeparator();
2059 \brief Create separator action which can be used in the menu or toolbar.
2060 \return new separator action
2063 class TCreateSepEvent: public SALOME_Event
2066 typedef QAction* TResult;
2070 virtual void Execute()
2072 LightApp_Module* module = getActiveModule();
2074 myResult = (QAction*)module->separator();
2077 QAction* SalomePyQt::createSeparator()
2079 return ProcessEvent( new TCreateSepEvent() );
2083 \fn QAction* SalomePyQt::createAction( const int id,
2084 const QString& menuText,
2085 const QString& tipText,
2086 const QString& statusText,
2087 const QString& icon,
2089 const bool toggle );
2090 \brief Create an action which can be then used in the menu or toolbar.
2091 \param id the unique id action to be registered to
2092 \param menuText action text which should appear in menu
2093 \param tipText text which should appear in the tooltip
2094 \param statusText text which should appear in the status bar when action is activated
2095 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2096 \param key the key accelrator for the action
2097 \param toggle if \c true the action is checkable
2100 class TCreateActionEvent: public SALOME_Event
2103 typedef QAction* TResult;
2108 QString myStatusText;
2112 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2113 const QString& statusText, const QString& icon, const int key, const bool toggle )
2114 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2115 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2116 virtual void Execute()
2118 LightApp_Module* module = getActiveModule();
2120 QIcon icon = loadIconInternal( module->name(), myIcon );
2121 myResult = (QAction*)module->action( myId );
2123 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2124 myResult->setToolTip( myTipText );
2125 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2126 myResult->setText( myMenuText );
2127 if ( myResult->icon().isNull() && !icon.isNull() )
2128 myResult->setIcon( icon );
2129 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2130 myResult->setStatusTip( myStatusText );
2131 if ( myResult->shortcut().isEmpty() && myKey )
2132 myResult->setShortcut( myKey );
2133 if ( myResult->isCheckable() != myToggle )
2134 myResult->setCheckable( myToggle );
2137 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2139 // for Python module, automatically connect action to callback slot
2140 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2141 if ( helper ) helper->connectAction( myResult );
2145 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2146 const QString& tipText, const QString& statusText,
2147 const QString& icon, const int key, const bool toggle )
2149 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2153 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2154 \brief Create an action group which can be then used in the menu or toolbar
2155 \param id : the unique id action group to be registered to
2156 \param exclusive : if \c true the action group does exclusive toggling
2159 struct TCreateActionGroupEvent: public SALOME_Event
2161 typedef QtxActionGroup* TResult;
2165 TCreateActionGroupEvent( const int id, const bool exclusive )
2166 : myId( id ), myExclusive( exclusive ) {}
2167 virtual void Execute()
2169 LightApp_Module* module = getActiveModule();
2171 myResult = module->createActionGroup( myId, myExclusive );
2174 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2176 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2180 \fn QAction* SalomePyQt::action( const int id );
2181 \brief Get action by specified identifier.
2182 \return action or 0 if action is not registered
2185 class TActionEvent: public SALOME_Event
2188 typedef QAction* TResult;
2191 TActionEvent( const int id )
2192 : myResult( 0 ), myId( id ) {}
2193 virtual void Execute()
2195 LightApp_Module* module = getActiveModule();
2197 myResult = (QAction*)module->action( myId );
2200 QAction* SalomePyQt::action( const int id )
2202 return ProcessEvent( new TActionEvent( id ) );
2206 \fn int SalomePyQt::actionId( const QAction* a );
2207 \brief Get an action identifier.
2208 \return action ID or -1 if action is not registered
2211 class TActionIdEvent: public SALOME_Event
2214 typedef int TResult;
2216 const QAction* myAction;
2217 TActionIdEvent( const QAction* action )
2218 : myResult( -1 ), myAction( action ) {}
2219 virtual void Execute()
2221 LightApp_Module* module = getActiveModule();
2223 myResult = module->actionId( myAction );
2226 int SalomePyQt::actionId( const QAction* a )
2228 return ProcessEvent( new TActionIdEvent( a ) );
2232 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2233 \brief Add global (not module-related) preferences group.
2234 \param label global preferences group name
2235 \return preferences group identifier
2238 class TAddGlobalPrefEvent: public SALOME_Event
2241 typedef int TResult;
2244 TAddGlobalPrefEvent( const QString& label )
2245 : myResult( -1 ), myLabel( label ) {}
2246 virtual void Execute()
2248 LightApp_Module* module = getActiveModule();
2250 LightApp_Preferences* pref = module->getApp()->preferences();
2252 myResult = pref->addPreference( myLabel, -1 );
2256 int SalomePyQt::addGlobalPreference( const QString& label )
2258 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2262 \fn int SalomePyQt::addPreference( const QString& label );
2263 \brief Add module-related preferences group.
2264 \param label preferences group name
2265 \return preferences group identifier
2268 class TAddPrefEvent: public SALOME_Event
2271 typedef int TResult;
2274 TAddPrefEvent( const QString& label )
2275 : myResult( -1 ), myLabel( label ) {}
2276 virtual void Execute()
2278 LightApp_Module* module = getActiveModule();
2280 LightApp_Preferences* pref = module->getApp()->preferences();
2282 int cId = pref->addPreference( module->moduleName(), -1 );
2284 myResult = pref->addPreference( myLabel, cId );
2289 int SalomePyQt::addPreference( const QString& label )
2291 return ProcessEvent( new TAddPrefEvent( label ) );
2295 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2296 const QString& section, const QString& param );
2297 \brief Add module-related preferences.
2298 \param label preferences group name
2299 \param pId parent preferences group id
2300 \param type preferences type
2301 \param section resources file section name
2302 \param param resources file setting name
2303 \return preferences identifier
2306 class TAddPrefParamEvent: public SALOME_Event
2309 typedef int TResult;
2316 TAddPrefParamEvent( const QString& label,
2317 const int pId, const int type,
2318 const QString& section,
2319 const QString& param )
2321 myLabel( label ), myPId( pId ), myType( type ),
2322 mySection( section ), myParam ( param ) {}
2323 virtual void Execute()
2325 LightApp_Module* module = getActiveModule();
2327 LightApp_Preferences* pref = module->getApp()->preferences();
2329 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2333 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2334 const QString& section, const QString& param )
2336 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2340 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2341 \brief Get the preferences property.
2342 \param id preferences identifier
2343 \param prop preferences property name
2344 \return preferences property value or null QVariant if property is not set
2347 class TPrefPropEvent: public SALOME_Event
2350 typedef QVariant TResult;
2354 TPrefPropEvent( const int id, const QString& prop )
2355 : myId( id ), myProp( prop ) {}
2356 virtual void Execute()
2358 LightApp_Module* module = getActiveModule();
2360 LightApp_Preferences* pref = module->getApp()->preferences();
2362 myResult = pref->itemProperty( myProp, myId );
2366 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2368 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2372 \brief Set the preferences property.
2373 \param id preferences identifier
2374 \param prop preferences property name
2375 \param var preferences property value
2377 void SalomePyQt::setPreferenceProperty( const int id,
2378 const QString& prop,
2379 const QVariant& var )
2381 class TEvent: public SALOME_Event
2387 TEvent( const int id, const QString& prop, const QVariant& var )
2388 : myId( id ), myProp( prop ), myVar( var ) {}
2389 virtual void Execute()
2391 LightApp_Module* module = getActiveModule();
2393 LightApp_Preferences* pref = module->getApp()->preferences();
2395 pref->setItemProperty( myProp, myVar, myId );
2399 ProcessVoidEvent( new TEvent( id, prop, var) );
2403 \brief Add the property value to the list of values.
2405 This method allows creating properties which are QList<QVariant>
2406 - there is no way to pass such values directly to QVariant parameter with PyQt.
2408 \param id preferences identifier
2409 \param prop preferences property name
2410 \param idx preferences property index
2411 \param var preferences property value for the index \a idx
2413 void SalomePyQt::addPreferenceProperty( const int id,
2414 const QString& prop,
2416 const QVariant& var )
2418 class TEvent: public SALOME_Event
2425 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2426 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2427 virtual void Execute()
2429 LightApp_Module* module = getActiveModule();
2431 LightApp_Preferences* pref = module->getApp()->preferences();
2433 QVariant var = pref->itemProperty( myProp, myId );
2434 if ( var.isValid() ) {
2435 if ( var.type() == QVariant::StringList ) {
2436 QStringList sl = var.toStringList();
2437 if ( myIdx >= 0 && myIdx < sl.count() )
2438 sl[myIdx] = myVar.toString();
2440 sl.append( myVar.toString() );
2441 pref->setItemProperty( myProp, sl, myId );
2443 else if ( var.type() == QVariant::List ) {
2444 QList<QVariant> vl = var.toList();
2445 if ( myIdx >= 0 && myIdx < vl.count() )
2449 pref->setItemProperty( myProp, vl, myId );
2455 pref->setItemProperty( myProp, vl, myId );
2461 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2465 \brief Put the message to the Log messages output window
2466 \param msg message text (it can be of simple rich text format)
2467 \param addSeparator boolean flag which specifies if it is necessary
2468 to separate the message with predefined separator
2470 void SalomePyQt::message( const QString& msg, bool addSeparator )
2472 class TEvent: public SALOME_Event
2477 TEvent( const QString& msg, bool addSeparator )
2478 : myMsg( msg ), myAddSep( addSeparator ) {}
2479 virtual void Execute()
2481 if ( LightApp_Application* anApp = getApplication() ) {
2482 LogWindow* lw = anApp->logWindow();
2484 lw->putMessage( myMsg, myAddSep );
2488 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2492 \brief Remove all the messages from the Log messages output window.
2494 void SalomePyQt::clearMessages()
2496 class TEvent: public SALOME_Event
2500 virtual void Execute()
2502 if ( LightApp_Application* anApp = getApplication() ) {
2503 LogWindow* lw = anApp->logWindow();
2509 ProcessVoidEvent( new TEvent() );
2513 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2514 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2515 to the image file in the specified format.
2517 For the current moment JPEG, PNG and BMP images formats are supported.
2518 The image format is defined automatically by the file name extension.
2519 By default, BMP format is used.
2521 \param filename image file name
2522 \return operation status (\c true on success)
2525 class TDumpViewEvent: public SALOME_Event
2528 typedef bool TResult;
2532 TDumpViewEvent( const QString& filename, const int id )
2533 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2534 virtual void Execute()
2536 SUIT_ViewWindow* wnd = 0;
2538 if ( LightApp_Application* anApp = getApplication() ) {
2539 SUIT_ViewManager* vm = anApp->activeViewManager();
2541 wnd = vm->getActiveView();
2543 myWndId = wnd->getId();
2546 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2549 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2550 #ifndef DISABLE_PLOT2DVIEWER
2551 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2553 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2554 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2555 qApp->processEvents();
2556 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2557 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2561 #endif // DISABLE_PLOT2DVIEWER
2562 QImage im = wnd->dumpView();
2563 if ( !im.isNull() && !myFileName.isEmpty() ) {
2564 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2565 if ( fmt == "JPG" ) fmt = "JPEG";
2566 myResult = im.save( myFileName, fmt.toLatin1() );
2571 bool SalomePyQt::dumpView( const QString& filename, const int id )
2573 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2577 \fn QList<int> SalomePyQt::getViews();
2578 \brief Get list of integer identifiers of all the currently opened views
2579 \return list of integer identifiers of all the currently opened views
2582 class TGetViews: public SALOME_Event
2585 typedef QList<int> TResult;
2588 virtual void Execute()
2591 LightApp_Application* app = getApplication();
2593 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2595 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2596 SUIT_ViewWindow* wnd;
2597 foreach ( wnd, wndlist )
2598 myResult.append( wnd->getId() );
2603 QList<int> SalomePyQt::getViews()
2605 return ProcessEvent( new TGetViews() );
2609 \fn int SalomePyQt::getActiveView();
2610 \brief Get integer identifier of the currently active view
2611 \return integer identifier of the currently active view
2614 class TGetActiveView: public SALOME_Event
2617 typedef int TResult;
2621 virtual void Execute()
2623 LightApp_Application* app = getApplication();
2625 SUIT_ViewManager* viewMgr = app->activeViewManager();
2627 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2629 myResult = wnd->getId();
2634 int SalomePyQt::getActiveView()
2636 return ProcessEvent( new TGetActiveView() );
2640 \fn QString SalomePyQt::getViewType( const int id );
2641 \brief Get type of the specified view, e.g. "OCCViewer"
2642 \param id window identifier
2646 class TGetViewType: public SALOME_Event
2649 typedef QString TResult;
2652 TGetViewType( const int id )
2654 virtual void Execute()
2656 SUIT_ViewWindow* wnd = getWnd( myWndId );
2658 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2660 myResult = viewMgr->getType();
2664 QString SalomePyQt::getViewType( const int id )
2666 return ProcessEvent( new TGetViewType( id ) );
2670 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2671 \brief Change view caption
2672 \param id window identifier
2673 \param title new window title
2674 \return \c true if operation is completed successfully and \c false otherwise
2677 class TSetViewTitle: public SALOME_Event
2680 typedef bool TResult;
2684 TSetViewTitle( const int id, const QString& title )
2685 : myResult( false ),
2688 virtual void Execute()
2690 SUIT_ViewWindow* wnd = getWnd( myWndId );
2692 wnd->setWindowTitle( myTitle );
2697 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2699 return ProcessEvent( new TSetViewTitle( id, title ) );
2703 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2704 \brief Set view size
2705 \param w window width
2706 \param h window height
2707 \param id window identifier
2708 \return \c true if operation is completed successfully and \c false otherwise
2711 class TSetViewSize: public SALOME_Event
2714 typedef bool TResult;
2719 TSetViewSize( const int w, const int h, const int id )
2720 : myResult( false ),
2724 virtual void Execute()
2726 SUIT_ViewWindow* wnd = 0;
2728 if ( LightApp_Application* anApp = getApplication() ) {
2729 SUIT_ViewManager* vm = anApp->activeViewManager();
2731 wnd = vm->getActiveView();
2735 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2738 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2740 QString type = viewMgr->getType();
2741 if ( type == "OCCViewer") {
2742 #ifndef DISABLE_OCCVIEWER
2743 // specific processing for OCC viewer:
2744 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2745 // - if there is only one sub-view active; it will be resized;
2746 // - if there are several sub-views, each of them will be resized.
2747 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2748 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2749 if ( occView && occView->getView( i ) ) {
2750 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2754 #endif // DISABLE_OCCVIEWER
2756 else if ( type == "ParaView") {
2757 #ifndef DISABLE_PVVIEWER
2758 // specific processing for ParaView viewer:
2759 // hierarchy of ParaView viewer is much complex than for usual view;
2760 // we look for sub-widget named "Viewport"
2761 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2762 if ( !lst.isEmpty() ) {
2763 lst[0]->resize( myWndWidth, myWndHeight );
2766 #endif // DISABLE_PVVIEWER
2769 if ( wnd->centralWidget() ) {
2770 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2778 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2780 return ProcessEvent( new TSetViewSize( w, h, id ) );
2784 \fn QString SalomePyQt::getViewTitle( const int id );
2785 \brief Get view caption
2786 \param id window identifier
2787 \return view caption
2790 class TGetViewTitle: public SALOME_Event
2793 typedef QString TResult;
2796 TGetViewTitle( const int id )
2798 virtual void Execute()
2800 SUIT_ViewWindow* wnd = getWnd( myWndId );
2802 myResult = wnd->windowTitle();
2805 QString SalomePyQt::getViewTitle( const int id )
2807 return ProcessEvent( new TGetViewTitle( id ) );
2811 \fn QList<int> SalomePyQt::findViews( const QString& type );
2812 \brief Get list of integer identifiers of all the
2813 currently opened views of the specified type
2814 \param type viewer type
2815 \return list of integer identifiers
2818 class TFindViews: public SALOME_Event
2821 typedef QList<int> TResult;
2824 TFindViews( const QString& type )
2826 virtual void Execute()
2829 LightApp_Application* app = getApplication();
2831 ViewManagerList vmList;
2832 app->viewManagers( myType, vmList );
2833 SUIT_ViewManager* viewMgr;
2834 foreach ( viewMgr, vmList ) {
2835 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2836 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2837 SUIT_ViewWindow* wnd = vec[ i ];
2840 MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
2841 myResult.append( wnd->getId() );
2848 QList<int> SalomePyQt::findViews( const QString& type )
2850 return ProcessEvent( new TFindViews( type ) );
2854 \fn bool SalomePyQt::activateView( const int id );
2855 \brief Activate view
2856 \param id window identifier
2857 \return \c true if operation is completed successfully and \c false otherwise
2860 class TActivateView: public SALOME_Event
2863 typedef bool TResult;
2866 TActivateView( const int id )
2867 : myResult( false ),
2869 virtual void Execute()
2871 SUIT_ViewWindow* wnd = getWnd( myWndId );
2872 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
2879 bool SalomePyQt::activateView( const int id )
2881 return ProcessEvent( new TActivateView( id ) );
2885 \fn bool SalomePyQt::activateManagerAndView( const int id );
2886 \brief Activate view manager and view: useful for a view embedded in a module main Window
2887 \param id window identifier
2888 \return \c true if operation is completed successfully and \c false otherwise
2891 class TActivateViewManagerAndView: public SALOME_Event
2894 typedef bool TResult;
2897 TActivateViewManagerAndView( const int id )
2898 : myResult( false ),
2900 virtual void Execute()
2902 SUIT_ViewWindow* wnd = getWnd( myWndId );
2903 MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
2906 LightApp_Application* app = getApplication();
2907 app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
2913 bool SalomePyQt::activateViewManagerAndView( const int id )
2915 return ProcessEvent( new TActivateViewManagerAndView( id ) );
2922 class TGetViewWidget: public SALOME_Event
2925 typedef QWidget* TResult;
2928 TGetViewWidget( const int id )
2931 virtual void Execute()
2933 SUIT_ViewWindow* wnd = getWnd( myWndId );
2935 myResult = (QWidget*)wnd;
2939 QWidget* SalomePyQt::getViewWidget( const int id)
2941 return ProcessEvent( new TGetViewWidget( id ) );
2946 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2947 \brief Create new view and activate it
2948 \param type viewer type
2952 \return integer identifier of created view (or -1 if view could not be created)
2955 class TCreateView: public SALOME_Event
2958 typedef int TResult;
2964 TCreateView( const QString& theType, bool visible, const int width, const int height )
2970 virtual void Execute()
2972 LightApp_Application* app = getApplication();
2974 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2976 QWidget* wnd = viewMgr->getActiveView();
2977 myResult = viewMgr->getActiveView()->getId();
2980 wnd->setVisible(false);
2981 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2985 if (myWidth > 0 && myHeight > 0) {
2986 #ifndef DISABLE_PLOT2DVIEWER
2987 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2988 if ( wnd2D ) wnd = wnd2D->getViewFrame();
2989 #endif // DISABLE_PLOT2DVIEWER
2990 wnd->setGeometry( 0, 0, myWidth, myHeight );
2997 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2999 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
3000 QCoreApplication::processEvents();
3005 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
3006 \brief Create new view with custom widget embedded and activate it
3007 \param type viewer type
3008 \param w custom widget
3009 \return integer identifier of created view (or -1 if view could not be created)
3012 class TCreateViewWg: public SALOME_Event
3015 typedef int TResult;
3019 TCreateViewWg( const QString& theType, QWidget* w )
3023 virtual void Execute()
3025 LightApp_Application* app = getApplication();
3027 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
3029 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
3031 myResult = wnd->getId();
3036 int SalomePyQt::createView( const QString& type, QWidget* w )
3038 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
3039 QCoreApplication::processEvents();
3044 \fn bool SalomePyQt::closeView( const int id );
3046 \param id window identifier
3047 \return \c true if operation is completed successfully and \c false otherwise
3050 class TCloseView: public SALOME_Event
3053 typedef bool TResult;
3056 TCloseView( const int id )
3057 : myResult( false ),
3059 virtual void Execute()
3061 SUIT_ViewWindow* wnd = getWnd( myWndId );
3063 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3071 bool SalomePyQt::closeView( const int id )
3073 return ProcessEvent( new TCloseView( id ) );
3077 \fn int SalomePyQt::cloneView( const int id );
3078 \brief Clone view (if this operation is supported for specified view type)
3079 \param id window identifier
3080 \return integer identifier of the cloned view or -1 or operation could not be performed
3083 class TCloneView: public SALOME_Event
3086 typedef int TResult;
3089 TCloneView( const int id )
3092 virtual void Execute()
3094 SUIT_ViewWindow* wnd = getWnd( myWndId );
3096 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3098 #ifndef DISABLE_OCCVIEWER
3099 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3100 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3101 occView->onCloneView();
3102 wnd = viewMgr->getActiveView();
3104 myResult = wnd->getId();
3106 #endif // DISABLE_OCCVIEWER
3107 #ifndef DISABLE_PLOT2DVIEWER
3108 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3109 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3110 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3111 if ( viewMgr2d && srcWnd2d ) {
3112 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3113 myResult = resWnd->getId();
3116 #endif // DISABLE_OCCVIEWER
3121 int SalomePyQt::cloneView( const int id )
3123 return ProcessEvent( new TCloneView( id ) );
3127 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3128 \brief Set view visibility.
3129 \param id window identifier
3130 \param visible new visiblity
3133 void SalomePyQt::setViewVisible( const int id, const bool visible )
3135 class TEvent: public SALOME_Event
3140 TEvent( const int id, const bool visible )
3141 : myWndId( id ), myVisible( visible ) {}
3142 virtual void Execute()
3144 SUIT_ViewWindow* wnd = getWnd( myWndId );
3145 if ( wnd ) wnd->setVisible( myVisible );
3148 ProcessVoidEvent( new TEvent( id, visible ) );
3152 \fn bool SalomePyQt::isViewVisible( const int id );
3153 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3154 \param id window identifier
3155 \return \c true if view is visible and \c false otherwise
3158 class TIsViewVisible: public SALOME_Event
3161 typedef bool TResult;
3164 TIsViewVisible( const int id )
3165 : myResult( false ),
3167 virtual void Execute()
3169 SUIT_ViewWindow* wnd = getWnd( myWndId );
3172 QWidget* p = wnd->parentWidget();
3173 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3177 bool SalomePyQt::isViewVisible( const int id )
3179 return ProcessEvent( new TIsViewVisible( id ) );
3183 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3184 \brief Set / clear view's "closable" option. By default any view is closable
3185 (i.e. can be closed by the user).
3186 \param id window identifier
3187 \param on new "closable" option's value
3190 void SalomePyQt::setViewClosable( const int id, const bool on )
3192 class TEvent: public SALOME_Event
3197 TEvent( const int id, const bool on )
3198 : myWndId( id ), myOn( on ) {}
3199 virtual void Execute()
3201 SUIT_ViewWindow* wnd = getWnd( myWndId );
3202 if ( wnd ) wnd->setClosable( myOn );
3205 ProcessVoidEvent( new TEvent( id, on ) );
3209 \fn bool SalomePyQt::isViewClosable( const int id );
3210 \brief Check whether view is closable (i.e. can be closed by the user)
3211 \param id window identifier
3212 \return \c true if view is closable or \c false otherwise
3215 class TIsViewClosable: public SALOME_Event
3218 typedef bool TResult;
3221 TIsViewClosable( const int id )
3224 virtual void Execute()
3226 SUIT_ViewWindow* wnd = getWnd( myWndId );
3228 myResult = wnd->closable();
3232 bool SalomePyQt::isViewClosable( const int id )
3234 return ProcessEvent( new TIsViewClosable( id ) );
3238 \fn bool SalomePyQt::groupAllViews();
3239 \brief Group all views to the single tab area
3240 \return \c true if operation is completed successfully and \c false otherwise
3243 class TGroupAllViews: public SALOME_Event
3246 typedef bool TResult;
3249 : myResult( false ) {}
3250 virtual void Execute()
3252 LightApp_Application* app = getApplication();
3254 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3256 QtxWorkstack* wStack = tabDesk->workstack();
3265 bool SalomePyQt::groupAllViews()
3267 return ProcessEvent( new TGroupAllViews() );
3271 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3272 \brief Split tab area to which view with identifier belongs to
3273 \param id window identifier
3274 \param ori orientation of split operation
3275 \param action action to be performed
3276 \return \c true if operation is completed successfully \c false otherwise
3279 class TSplitView: public SALOME_Event
3282 typedef bool TResult;
3287 TSplitView( const int id,
3288 const Orientation ori,
3289 const Action action )
3290 : myResult( false ),
3293 myAction( action ) {}
3294 virtual void Execute()
3296 SUIT_ViewWindow* wnd = getWnd( myWndId );
3299 // wnd->setFocus(); ???
3302 if ( getApplication() ) {
3303 STD_TabDesktop* desk =
3304 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3306 QtxWorkstack* wStack = desk->workstack();
3308 Qt::Orientation qtOri =
3309 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3311 QtxWorkstack::SplitType sType;
3312 if ( myAction == MoveWidget )
3313 sType = QtxWorkstack::SplitMove;
3314 else if ( myAction == LeaveWidget )
3315 sType = QtxWorkstack::SplitStay;
3317 sType = QtxWorkstack::SplitAt;
3319 wStack->Split( wnd, qtOri, sType );
3327 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3329 return ProcessEvent( new TSplitView( id, ori, action ) );
3333 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3334 \brief Move view with the first identifier to the same area which
3335 another view with the second identifier belongs to
3336 \param id source window identifier
3337 \param id_to destination window identifier
3338 param before specifies whether the first viewt has to be moved before or after
3340 \return \c true if operation is completed successfully and \c false otherwise
3343 class TMoveView: public SALOME_Event
3346 typedef bool TResult;
3351 TMoveView( const int id, const int id_to, const bool before )
3352 : myResult( false ),
3355 myIsBefore( before ) {}
3356 virtual void Execute()
3358 SUIT_ViewWindow* wnd = getWnd( myWndId );
3359 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3360 if ( wnd && wnd_to ) {
3361 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3362 getApplication()->desktop() )->workstack();
3364 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3368 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3370 return ProcessEvent( new TMoveView( id, id_to, before ) );
3374 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3375 \brief Get list of views identifiers that belongs to the same area as
3376 specified view (excluding it)
3377 \param id window identifier
3378 \return list of views identifiers
3381 class TNeighbourViews: public SALOME_Event
3384 typedef QList<int> TResult;
3387 TNeighbourViews( const int id )
3389 virtual void Execute()
3392 SUIT_ViewWindow* wnd = getWnd( myWndId );
3394 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3395 getApplication()->desktop() )->workstack();
3397 QWidgetList wgList = wStack->windowList( wnd );
3399 foreach ( wg, wgList ) {
3400 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3401 if ( tmpWnd && tmpWnd != wnd )
3402 myResult.append( tmpWnd->getId() );
3408 QList<int> SalomePyQt::neighbourViews( const int id )
3410 return ProcessEvent( new TNeighbourViews( id ) );
3415 \fn void SalomePyQt::createRoot();
3416 \brief Initialize root data object.
3418 Does nothing if root is already initialized.
3421 void SalomePyQt::createRoot()
3423 class TEvent: public SALOME_Event
3427 virtual void Execute()
3429 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3431 SALOME_PYQT_DataModelLight* dm =
3432 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3437 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3441 ProcessVoidEvent( new TEvent() );
3445 \fn QString SalomePyQt::createObject( const QString& parent );
3446 \brief Create empty data object
3447 \param parent entry of parent data object
3448 \return entry of created data object
3451 class TCreateEmptyObjectEvent: public SALOME_Event
3454 typedef QString TResult;
3457 TCreateEmptyObjectEvent( const QString& parent )
3458 : myParent( parent ) {}
3459 virtual void Execute()
3461 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3463 myResult = module->createObject( myParent );
3466 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3470 QString SalomePyQt::createObject( const QString& parent )
3472 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3476 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3477 const QString& tooltip,const QString& parent );
3478 \brief Create new data object with specified name, icon and tooltip
3479 \param name data object name
3480 \param icon data object icon
3481 \param toolTip data object tooltip
3482 \param parent entry of parent data object
3483 \return entry of created data object
3486 class TCreateObjectEvent: public SALOME_Event
3489 typedef QString TResult;
3495 TCreateObjectEvent( const QString& name,
3496 const QString& icon,
3497 const QString& tooltip,
3498 const QString& parent )
3501 myToolTip( tooltip ),
3502 myParent( parent ) {}
3503 virtual void Execute()
3505 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3507 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3510 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3514 QString SalomePyQt::createObject( const QString& name,
3515 const QString& icon,
3516 const QString& toolTip,
3517 const QString& parent )
3519 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3524 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3525 \brief Set data object name
3526 \param entry data object entry
3527 \param name data object name
3529 class TSetNameEvent: public SALOME_Event
3534 TSetNameEvent( const QString& entry,
3535 const QString& name )
3538 virtual void Execute()
3540 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3542 module->setName( myEntry, myName );
3545 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3549 void SalomePyQt::setName( const QString& entry, const QString& name )
3551 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3555 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3556 \brief Set data object icon
3557 \param entry data object entry
3558 \param icon data object icon file name (icon is loaded from module resources)
3561 class TSetIconEvent: public SALOME_Event
3566 TSetIconEvent( const QString& entry,
3567 const QString& icon )
3570 virtual void Execute()
3572 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3574 module->setIcon( myEntry, myIcon );
3577 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3582 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3584 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3588 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3589 \brief Set data object tooltip
3590 \param entry data object entry
3591 \param toolTip data object tooltip
3594 class TSetToolTipEvent: public SALOME_Event
3599 TSetToolTipEvent( const QString& entry,
3600 const QString& toolTip )
3602 myToolTip( toolTip ) {}
3603 virtual void Execute()
3605 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3607 module->setToolTip( myEntry, myToolTip );
3610 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3614 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3616 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3620 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3621 \brief Set reference to another data object
3622 \param entry data object entry
3623 \param refEntry referenced data object entry
3626 class TSetRefEvent: public SALOME_Event
3631 TSetRefEvent( const QString& entry,
3632 const QString& refEntry )
3634 myRefEntry( refEntry ) {}
3635 virtual void Execute()
3637 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3639 module->setReference( myEntry, myRefEntry );
3642 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3646 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3648 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3652 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3653 \brief Set data object color
3654 \param entry data object entry
3655 \param color data object color
3658 class TSetColorEvent: public SALOME_Event
3663 TSetColorEvent( const QString& entry,
3664 const QColor& color )
3667 virtual void Execute()
3669 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3671 module->setColor( myEntry, myColor );
3674 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3678 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3680 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3684 \fn QString SalomePyQt::getName( const QString& entry );
3685 \brief Get data object name
3686 \param entry data object entry
3687 \return data object name
3690 class TGetNameEvent: public SALOME_Event
3693 typedef QString TResult;
3696 TGetNameEvent( const QString& entry )
3697 : myEntry( entry ) {}
3698 virtual void Execute()
3700 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3702 myResult = module->getName( myEntry );
3705 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3709 QString SalomePyQt::getName( const QString& entry )
3711 return ProcessEvent( new TGetNameEvent( entry ) );
3715 \fn QString SalomePyQt::getToolTip( const QString& entry );
3716 \brief Get data object tooltip
3717 \param entry data object entry
3718 \return data object tooltip
3721 class TGetToolTipEvent: public SALOME_Event
3724 typedef QString TResult;
3727 TGetToolTipEvent( const QString& entry )
3728 : myEntry( entry ) {}
3729 virtual void Execute()
3731 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3733 myResult = module->getToolTip( myEntry );
3736 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3740 QString SalomePyQt::getToolTip( const QString& entry )
3742 return ProcessEvent( new TGetToolTipEvent( entry ) );
3746 \fn QString SalomePyQt::getReference( const QString& entry );
3747 \brief Get entry of the referenced object (if there's any)
3748 \param entry data object entry
3749 \return referenced data object entry
3752 class TGetRefEvent: public SALOME_Event
3755 typedef QString TResult;
3758 TGetRefEvent( const QString& entry )
3759 : myEntry( entry ) {}
3760 virtual void Execute()
3762 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3764 myResult = module->getReference( myEntry );
3767 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3771 QString SalomePyQt::getReference( const QString& entry )
3773 return ProcessEvent( new TGetRefEvent( entry ) );
3777 \fn QColor SalomePyQt::getColor( const QString& entry );
3778 \brief Get data object color
3779 \param entry data object entry
3780 \return data object color
3783 class TGetColorEvent: public SALOME_Event
3786 typedef QColor TResult;
3789 TGetColorEvent( const QString& entry )
3790 : myEntry( entry ) {}
3791 virtual void Execute()
3793 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3795 myResult = module->getColor( myEntry );
3798 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3802 QColor SalomePyQt::getColor( const QString& entry )
3804 return ProcessEvent( new TGetColorEvent( entry ) );
3808 \fn void SalomePyQt::removeChildren( const QString& entry );
3809 \brief Remove all child data objects from specified data object
3810 \param entry data object entry
3813 class TRemoveChildEvent: public SALOME_Event
3817 TRemoveChildEvent( const QString& entry )
3818 : myEntry( entry ) {}
3819 virtual void Execute()
3821 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3823 module->removeChildren( myEntry );
3826 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3830 void SalomePyQt::removeChildren( const QString& entry )
3832 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3834 void SalomePyQt::removeChild( const QString& entry )
3836 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3837 removeChildren( entry );
3841 \fn void SalomePyQt::removeObject( const QString& entry );
3842 \brief Remove object by entry
3843 \param entry data object entry
3846 class TRemoveObjectEvent: public SALOME_Event
3851 TRemoveObjectEvent( const QString& entry )
3852 : myEntry( entry ) {}
3853 virtual void Execute()
3855 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3857 module->removeObject( myEntry );
3860 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3864 void SalomePyQt::removeObject( const QString& entry )
3866 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3870 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3871 \brief Get entries of all child data objects of specified data object
3872 \param entry data object entry
3873 \param recursive \c true for recursive processing
3876 class TGetChildrenEvent: public SALOME_Event
3879 typedef QStringList TResult;
3883 TGetChildrenEvent( const QString& entry, const bool recursive )
3885 myRecursive( recursive ) {}
3886 virtual void Execute()
3888 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3890 myResult = module->getChildren( myEntry, myRecursive );
3893 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3897 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3899 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3902 #ifndef DISABLE_PLOT2DVIEWER
3903 // Next set of methods relates to the Plot2d viewer functionality
3906 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3907 \brief Display theCurve in view
3908 \param id window identifier
3909 \param theCurve curve to display
3912 class TDisplayCurve: public SALOME_Event
3916 Plot2d_Curve* myCurve;
3917 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3918 virtual void Execute() {
3919 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3921 wnd->getViewFrame()->displayCurve( myCurve );
3924 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3926 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
3930 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3931 \brief Erase theCurve in view
3932 \param id window identifier
3933 \param theCurve curve to erase
3936 class TEraseCurve: public SALOME_Event
3940 Plot2d_Curve* myCurve;
3941 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3942 virtual void Execute() {
3943 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3944 wnd->getViewFrame()->eraseCurve( myCurve );
3947 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3949 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
3953 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3954 \brief Delete theCurve from all views
3955 \param theCurve curve to delete
3958 class TDeleteCurve: public SALOME_Event
3961 Plot2d_Curve* myCurve;
3962 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3963 virtual void Execute() {
3964 LightApp_Application* app = getApplication();
3966 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3968 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3969 SUIT_ViewWindow* wnd;
3970 foreach ( wnd, wndlist ) {
3971 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3973 aP2d->getViewFrame()->eraseObject( myCurve );
3979 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3981 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3985 \brief updateCurves (repaint) curves in view window.
3987 void SalomePyQt::updateCurves( const int id )
3989 class TEvent: public SALOME_Event
3993 TEvent( const int id ) : myWndId( id ) {}
3994 virtual void Execute()
3996 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3998 wnd->getViewFrame()->DisplayAll();
4001 ProcessVoidEvent( new TEvent( id ) );
4005 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
4006 \brief Get title of corresponding type
4007 \param id window identifier
4008 \param type is type of title
4009 \return title of corresponding type
4012 class TGetPlot2dTitle: public SALOME_Event
4015 typedef QString TResult;
4019 TGetPlot2dTitle(const int id, ObjectType type) :
4022 virtual void Execute() {
4023 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4025 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
4028 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
4030 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
4035 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
4036 \brief Set title of corresponding type
4037 \param id window identifier
4039 \param type is type of title
4043 class TSetPlot2dTitle: public SALOME_Event
4047 Plot2d_Curve* myCurve;
4051 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
4056 virtual void Execute() {
4057 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4058 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
4061 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
4063 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
4067 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4068 \brief Get list of Plot2d view ranges
4069 \param id window identifier
4070 \return list of view ranges (XMin, XMax, YMin, YMax)
4073 class TFitRangeByCurves: public SALOME_Event
4076 typedef QList<double> TResult;
4079 TFitRangeByCurves( const int id )
4081 virtual void Execute()
4084 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4086 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4087 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4088 myResult.append( XMin );
4089 myResult.append( XMax );
4090 myResult.append( YMin );
4091 myResult.append( YMax );
4095 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4097 return ProcessEvent( new TFitRangeByCurves( id ) );
4101 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4102 \brief Get list of current Plot2d view ranges
4103 \param id window identifier
4104 \return list of view ranges (XMin, XMax, YMin, YMax)
4107 class TFitRangeCurrent: public SALOME_Event
4110 typedef QList<double> TResult;
4113 TFitRangeCurrent( const int id )
4115 virtual void Execute()
4118 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4120 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4121 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4122 myResult.append( XMin );
4123 myResult.append( XMax );
4124 myResult.append( YMin );
4125 myResult.append( YMax );
4129 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4131 return ProcessEvent( new TFitRangeCurrent( id ) );
4135 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4136 \brief Set range of Plot2d view
4137 \param id window identifier
4144 class TPlot2dFitRange: public SALOME_Event
4152 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4158 virtual void Execute() {
4159 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4161 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4164 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4166 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4169 // End of methods related to the Plot2d viewer functionality
4170 #endif // DISABLE_PLOT2DVIEWER
4173 \brief Process Qt event loop
4175 void SalomePyQt::processEvents()
4177 QCoreApplication::processEvents();
4181 \brief Set visibility state for given object
4182 \param theEntry study ID of the object
4183 \param theState visibility state
4185 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4187 class TEvent: public SALOME_Event
4192 TEvent( const QString& theEntry, int theState ):
4193 myEntry( theEntry ), myState( theState ) {}
4194 virtual void Execute()
4196 LightApp_Study* aStudy = getActiveStudy();
4199 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4202 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4206 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4207 \brief Get visibility state for given object
4208 \param theEntry study ID of the object
4209 \return visibility state
4212 class TGetVisibilityStateEvent: public SALOME_Event
4215 typedef int TResult;
4218 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4219 virtual void Execute()
4221 LightApp_Study* aStudy = getActiveStudy();
4223 myResult = aStudy->visibilityState( myEntry );
4226 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4228 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4232 \brief Set position of given object in the tree
4233 \param theEntry study ID of the object
4234 \param thePos position
4236 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4238 class TEvent: public SALOME_Event
4243 TEvent( const QString& theEntry, int thePos ):
4244 myEntry( theEntry ), myPos( thePos ) {}
4245 virtual void Execute()
4247 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4249 module->setObjectPosition( myEntry, myPos );
4252 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4256 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4257 \brief Get position of given object in the tree
4258 \param theEntry study ID of the object
4262 class TGetObjectPositionEvent: public SALOME_Event
4265 typedef int TResult;
4268 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4269 virtual void Execute()
4271 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4273 myResult = module->getObjectPosition( myEntry );
4276 int SalomePyQt::getObjectPosition( const QString& theEntry )
4278 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4282 \brief Start recordind a log of Python commands from embedded console
4283 \param theFileName output lof file name
4285 void SalomePyQt::startPyLog( const QString& theFileName )
4287 class TEvent: public SALOME_Event
4291 TEvent( const QString& theFileName ):
4292 myFileName( theFileName ) {}
4293 virtual void Execute()
4295 if ( getApplication() ) {
4296 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4297 if ( pyConsole ) pyConsole->startLog( myFileName );
4301 ProcessVoidEvent( new TEvent( theFileName ) );
4305 \brief Stop recordind a log of Python commands from embedded console
4307 void SalomePyQt::stopPyLog()
4309 class TEvent: public SALOME_Event
4313 virtual void Execute()
4315 if ( getApplication() ) {
4316 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4317 if ( pyConsole ) pyConsole->stopLog();
4321 ProcessVoidEvent( new TEvent() );