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>
74 \brief Get the currently active application.
76 \return active application object or 0 if there is no any
78 LightApp_Application* getApplication()
80 if ( SUIT_Session::session() )
81 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
86 \brief Get the currently active study.
88 \return active study or 0 if there is no study opened
90 LightApp_Study* getActiveStudy()
92 if ( getApplication() )
93 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
98 \brief Get the currently active module.
100 This function returns correct result only if Python-based
101 module is currently active. Otherwize, 0 is returned.
103 LightApp_Module* getActiveModule()
105 LightApp_Module* module = 0;
106 if ( LightApp_Application* anApp = getApplication() ) {
107 module = PyModuleHelper::getInitModule();
109 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
115 \brief Get the currently active Python module's helper.
117 This function returns correct result only if Python-based
118 module is currently active. Otherwize, 0 is returned.
120 PyModuleHelper* getPythonHelper()
122 LightApp_Module* module = getActiveModule();
123 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
128 \brief Get SALOME verbose level
130 \return \c true if SALOME debug output is allowed or \c false otherwise
134 bool isVerbose = false;
135 if ( getenv( "SALOME_VERBOSE" ) ) {
136 QString envVar = getenv( "SALOME_VERBOSE" );
138 int value = envVar.toInt( &ok );
139 isVerbose = ok && value != 0;
145 \brief Get menu item title
147 \param menuId menu identifier
148 \return menu title (localized)
150 QString getMenuName( const QString& menuId )
152 QStringList contexts;
153 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
154 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
155 QString menuName = menuId;
156 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
157 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
162 \brief Load module icon
164 \param module module name
165 \param fileName path to the icon file
168 QIcon loadIconInternal( const QString& module, const QString& fileName )
172 LightApp_Application* app = getApplication();
174 if ( app && !fileName.isEmpty() ) {
175 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
176 QApplication::translate( module.toLatin1().data(),
177 fileName.toLatin1().data() ) );
178 if ( !pixmap.isNull() )
179 icon = QIcon( pixmap );
185 \brief Gets window with specified identifier
187 \param id window identifier
188 \return pointer on the window
190 SUIT_ViewWindow* getWnd( const int id )
192 SUIT_ViewWindow* resWnd = 0;
194 LightApp_Application* app = getApplication();
196 ViewManagerList vmlist = app->viewManagers();
197 foreach( SUIT_ViewManager* vm, vmlist ) {
198 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
199 foreach ( SUIT_ViewWindow* vw, vwlist ) {
200 if ( id == vw->getId() ) {
211 \brief Map of created selection objects.
214 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
217 \brief Default resource file section name.
220 const char* DEFAULT_SECTION = "SalomePyQt";
224 \class SALOME_Selection
225 \brief The class represents selection which can be used in Python.
229 \brief Get the selection object for the specified application.
231 Finds or creates the selection object (one per study).
233 \param app application object
234 \return selection object or 0 if \a app is invalid
236 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
238 SALOME_Selection* sel = 0;
239 if ( app && SelMap.find( app ) != SelMap.end() )
242 sel = SelMap[ app ] = new SALOME_Selection( app );
248 \param p parent object
250 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
252 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
254 mySelMgr = app->selectionMgr();
255 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
256 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
263 SALOME_Selection::~SALOME_Selection()
265 LightApp_Application* app = 0;
266 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
267 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
268 if ( it.value() == this ) app = it.key();
270 if ( app ) SelMap.remove( app );
274 \brief Called when selection manager is destroyed (usually
275 when the study is closed).
277 void SALOME_Selection::onSelMgrDestroyed()
283 \brief Clear the selection.
285 void SALOME_Selection::Clear()
287 class TEvent: public SALOME_Event
289 LightApp_SelectionMgr* mySelMgr;
291 TEvent( LightApp_SelectionMgr* selMgr )
292 : mySelMgr( selMgr ) {}
293 virtual void Execute()
296 mySelMgr->clearSelected();
299 ProcessVoidEvent( new TEvent( mySelMgr ) );
303 \brief Clear the selection.
305 void SALOME_Selection::ClearIObjects()
311 Removes all selection filters.
313 void SALOME_Selection::ClearFilters()
315 class TEvent: public SALOME_Event
317 LightApp_SelectionMgr* mySelMgr;
319 TEvent( LightApp_SelectionMgr* selMgr )
320 : mySelMgr( selMgr ) {}
321 virtual void Execute()
324 mySelMgr->clearFilters();
327 ProcessVoidEvent( new TEvent( mySelMgr ) );
332 \brief The class provides utility functions which can be used in the Python
333 to operate with the SALOME GUI.
335 All the functionality of this class is implemented as static methods, so they
336 can be called with the class name prefixed or via creation of the class instance.
337 For example, next both ways of SalomePyQt class usage are legal:
339 from SalomePyQt import *
341 # using SalomePyQt class instance
342 desktop = sg.getDesktop()
343 # using SalomePyQt class directly
344 menubar = SalomePyQt.getMainMenuBar()
349 \fn QWidget* SalomePyQt::getDesktop();
350 \brief Get the active application's desktop window.
351 \return desktop window or 0 if there is no any
354 class TGetDesktopEvent: public SALOME_Event
357 typedef QWidget* TResult;
359 TGetDesktopEvent() : myResult( 0 ) {}
360 virtual void Execute()
362 if ( getApplication() )
363 myResult = (QWidget*)( getApplication()->desktop() );
366 QWidget* SalomePyQt::getDesktop()
368 return ProcessEvent( new TGetDesktopEvent() );
372 \fn QWidget* SalomePyQt::getMainFrame();
373 \brief Get current application's main frame widget [obsolete].
375 Main frame widget is an internal widget of the application
376 desktop window (workspace).
378 \return workspace widget (0 on any error)
381 class TGetMainFrameEvent: public SALOME_Event
384 typedef QWidget* TResult;
386 TGetMainFrameEvent() : myResult( 0 ) {}
387 virtual void Execute()
389 if ( getApplication() ) {
390 SUIT_Desktop* aDesktop = getApplication()->desktop();
391 myResult = (QWidget*)( aDesktop->centralWidget() );
395 QWidget* SalomePyQt::getMainFrame()
397 return ProcessEvent( new TGetMainFrameEvent() );
401 \fn QMenuBar* SalomePyQt::getMainMenuBar();
402 \brief Get current application desktop's main menu.
403 \return main menu object (0 on any error)
406 class TGetMainMenuBarEvent: public SALOME_Event
409 typedef QMenuBar* TResult;
411 TGetMainMenuBarEvent() : myResult( 0 ) {}
412 virtual void Execute()
414 if ( LightApp_Application* anApp = getApplication() ) {
415 myResult = anApp->desktop()->menuBar();
419 QMenuBar* SalomePyQt::getMainMenuBar()
421 return ProcessEvent( new TGetMainMenuBarEvent() );
425 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
426 \brief Get main menu's child popup submenu by its identifier.
428 This function is obsolete.
429 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
431 \param menu menu identifier
432 \return popup submenu object or 0 if it does not exist
436 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
437 \brief Get main menu's child popup submenu by its name.
439 The function creates menu if it does not exist.
441 \param menu menu name
442 \return popup submenu object (0 on any error)
445 class TGetPopupMenuEvent: public SALOME_Event
448 typedef QMenu* TResult;
451 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
452 virtual void Execute()
454 LightApp_Application* anApp = getApplication();
455 if ( anApp && !myMenuName.isEmpty() ) {
456 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
457 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
462 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
467 menuName = getMenuName( "MEN_DESK_FILE" ); break;
469 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
471 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
473 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
475 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
477 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
479 menuName = getMenuName( "MEN_DESK_HELP" ); break;
481 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
483 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
485 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
489 \fn QTreeView* SalomePyQt::getObjectBrowser();
490 \brief Get object browser
491 \return object browser for the active study or 0 in case of error
494 class TGetObjectBrowserEvent: public SALOME_Event
497 typedef QTreeView* TResult;
499 TGetObjectBrowserEvent() : myResult( 0 ) {}
500 virtual void Execute()
502 LightApp_Application* anApp = getApplication();
503 if ( anApp && anApp->objectBrowser() ) {
504 myResult = anApp->objectBrowser()->treeView();
508 QTreeView* SalomePyQt::getObjectBrowser()
510 return ProcessEvent( new TGetObjectBrowserEvent() );
514 \fn int SalomePyQt::getStudyId();
515 \brief Get active study's identifier.
516 \return active study ID or 0 if there is no active study
519 class TGetStudyIdEvent: public SALOME_Event
524 TGetStudyIdEvent() : myResult( 0 ) {}
525 virtual void Execute()
527 if ( LightApp_Study* aStudy = getActiveStudy() ) {
528 myResult = aStudy->id();
532 int SalomePyQt::getStudyId()
534 return ProcessEvent( new TGetStudyIdEvent() );
538 \fn SALOME_Selection* SalomePyQt::getSelection();
539 \brief Get the selection object for the current study.
541 Creates a Selection object if it has not been created yet.
543 \return selection object (0 on error)
546 class TGetSelectionEvent: public SALOME_Event
549 typedef SALOME_Selection* TResult;
551 TGetSelectionEvent() : myResult( 0 ) {}
552 virtual void Execute()
554 myResult = SALOME_Selection::GetSelection( getApplication() );
557 SALOME_Selection* SalomePyQt::getSelection()
559 return ProcessEvent( new TGetSelectionEvent() );
563 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
564 \brief Put an information message to the current application's
567 Optional second delay parameter (\a sec) can be used to specify
568 time of the message diplaying in seconds. If this parameter is less
569 or equal to zero, the constant message will be put.
571 \param msg message text
572 \param sec message displaying time in seconds
575 class TPutInfoEvent: public SALOME_Event
580 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
581 virtual void Execute()
583 if ( LightApp_Application* anApp = getApplication() ) {
584 anApp->putInfo( myMsg, mySecs * 1000 );
588 void SalomePyQt::putInfo( const QString& msg, const int sec )
590 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
594 \fn const QString SalomePyQt::getActiveComponent();
595 \brief Get the currently active module name (for the current study).
596 \return active module name or empty string if there is no active module
599 class TGetActiveComponentEvent: public SALOME_Event
602 typedef QString TResult;
604 TGetActiveComponentEvent() {}
605 virtual void Execute()
607 if ( LightApp_Application* anApp = getApplication() ) {
608 if ( CAM_Module* mod = anApp->activeModule() ) {
609 myResult = mod->name();
614 const QString SalomePyQt::getActiveComponent()
616 return ProcessEvent( new TGetActiveComponentEvent() );
620 \fn PyObject* SalomePyQt::getActivePythonModule();
621 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
622 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
625 class TGetActivePyModuleEvent: public SALOME_Event
628 typedef PyObject* TResult;
630 TGetActivePyModuleEvent() : myResult( Py_None ) {}
631 virtual void Execute()
633 PyModuleHelper* helper = getPythonHelper();
635 myResult = (PyObject*)helper->pythonModule();
638 PyObject* SalomePyQt::getActivePythonModule()
640 return ProcessEvent( new TGetActivePyModuleEvent() );
644 \fn bool SalomePyQt::activateModule( const QString& modName );
645 \brief Activates SALOME module with the given name
646 \return True if the module has been activated and False otherwise.
649 class TActivateModuleEvent: public SALOME_Event
652 typedef bool TResult;
654 QString myModuleName;
655 TActivateModuleEvent( const QString& modName )
656 : myResult( false ), myModuleName( modName ) {}
657 virtual void Execute()
659 if ( LightApp_Application* anApp = getApplication() ) {
660 myResult = anApp->activateModule( myModuleName );
664 bool SalomePyQt::activateModule( const QString& modName )
666 return ProcessEvent( new TActivateModuleEvent( modName ) );
670 \brief Update an Object Browser of the specified (by identifier) study.
672 If \a studyId <= 0 the active study's object browser is updated.
673 The \a updateSelection parameter is obsolete and currently is not used.
674 This parameter will be removed in future, so try to avoid its usage in
677 \brief studyId study identifier
678 \brief updateSelection update selection flag (not used)
681 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
683 class TEvent: public SALOME_Event
686 bool myUpdateSelection;
688 TEvent( const int studyId, bool updateSelection )
689 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
690 virtual void Execute()
692 if ( SUIT_Session::session() ) {
693 if ( getActiveStudy() && myStudyId <= 0 )
694 myStudyId = getActiveStudy()->id();
695 if ( myStudyId > 0 ) {
696 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
697 QList<SUIT_Application*>::Iterator it;
698 for( it = apps.begin(); it != apps.end(); ++it ) {
699 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
700 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
701 anApp->updateObjectBrowser();
709 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
714 SalomePyQt::isModified()
715 \return The modification status of the data model
716 for the currently active Python module
717 \note This function is supported for "light" Python-based SALOME modules only.
720 class TIsModifiedEvent: public SALOME_Event
723 typedef bool TResult;
725 TIsModifiedEvent() : myResult( false ) {}
726 virtual void Execute()
728 LightApp_Module* module = getActiveModule();
732 SALOME_PYQT_DataModelLight* aModel =
733 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
735 myResult = aModel->isModified();
738 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
742 bool SalomePyQt::isModified()
744 return ProcessEvent(new TIsModifiedEvent());
748 SalomePyQt::setModified()
750 Sets the modification status of the data model for
751 the currently active Python module. This method should be used
752 by the Python code in order to enable/disable "Save" operation
753 depending on the module's data state.
755 \note This function is supported for "light" Python-based SALOME modules only.
757 \param New modification status of the data model
761 void SalomePyQt::setModified( bool flag )
763 class TEvent: public SALOME_Event
769 virtual void Execute()
771 LightApp_Module* module = getActiveModule();
775 SALOME_PYQT_DataModelLight* model =
776 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
778 LightApp_Application* app = module->getApp();
780 if ( model && app ) {
781 model->setModified( myFlag );
782 app->updateActions();
785 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
789 ProcessVoidEvent( new TEvent( flag ) );
793 \brief Add string setting to the application preferences.
795 The parameter \a autoValue is obsolete parameter and currently is not used.
796 This parameter will be removed in future, so try to avoid its usage in
799 This function is obsolete. Use one of addSetting() instead.
801 \param name setting name (it should be of kind <section:setting> where
802 \c section is resources section name and \c setting is setting name)
803 \param value new setting value
804 \param autoValue (not used)
806 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
808 class TEvent: public SALOME_Event
814 TEvent( const QString& name, const QString& value, bool autoValue )
815 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
816 virtual void Execute()
818 if ( SUIT_Session::session() ) {
819 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
820 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
821 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
822 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
823 if ( !_sec.isEmpty() && !_nam.isEmpty() )
824 resMgr->setValue( _sec, _nam, myValue );
828 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
832 \brief Add integer setting to the application preferences.
834 The parameter \a autoValue is obsolete parameter and currently is not used.
835 This parameter will be removed in future, so try to avoid its usage in
838 This function is obsolete. Use one of addSetting() instead.
840 \param name setting name (it should be of kind <section:setting> where
841 \c section is resources section name and \c setting is setting name)
842 \param value new setting value
843 \param autoValue (not used)
845 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
847 class TEvent: public SALOME_Event
853 TEvent( const QString& name, const int value, bool autoValue )
854 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
855 virtual void Execute()
857 if ( SUIT_Session::session() ) {
858 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
859 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
860 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
861 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
862 if ( !_sec.isEmpty() && !_nam.isEmpty() )
863 resMgr->setValue( _sec, _nam, myValue );
867 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
871 \brief Add double setting to the application preferences.
873 The parameter \a autoValue is obsolete parameter and currently is not used.
874 This parameter will be removed in future, so try to avoid its usage in
877 This function is obsolete. Use one of addSetting() instead.
879 \param name setting name (it should be of kind <section:setting> where
880 \c section is resources section name and \c setting is setting name)
881 \param value new setting value
882 \param autoValue (not used)
884 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
886 class TEvent: public SALOME_Event
892 TEvent( const QString& name, const double value, bool autoValue )
893 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
894 virtual void Execute()
896 if ( SUIT_Session::session() ) {
897 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
898 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
899 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
900 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
901 if ( !_sec.isEmpty() && !_nam.isEmpty() )
902 resMgr->setValue( _sec, _nam, myValue );
906 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
910 \brief Add boolean setting to the application preferences.
912 The parameter \a autoValue is obsolete parameter and currently is not used.
913 This parameter will be removed in future, so try to avoid its usage in
916 This function is obsolete. Use one of addSetting() instead.
918 \param name setting name (it should be of kind <section:setting> where
919 \c section is resources section name and \c setting is setting name)
920 \param value new setting value
921 \param autoValue (not used)
923 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
925 class TEvent: public SALOME_Event
931 TEvent( const QString& name, const bool value, bool autoValue )
932 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
933 virtual void Execute()
935 if ( SUIT_Session::session() ) {
936 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
937 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
938 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
939 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
940 if ( !_sec.isEmpty() && !_nam.isEmpty() )
941 resMgr->setValue( _sec, _nam, myValue );
945 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
949 \brief Remove setting from the application preferences.
951 This function is obsolete. Use removeSetting() instead.
953 \param name setting name (it should be of kind <section:setting> where
954 \c section is resources section name and \c setting is setting name)
956 void SalomePyQt::removeSettings( const QString& name )
958 class TEvent: public SALOME_Event
962 TEvent( const QString& name ) : myName( name ) {}
963 virtual void Execute()
965 if ( SUIT_Session::session() ) {
966 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
967 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
968 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
969 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
970 if ( !_sec.isEmpty() && !_nam.isEmpty() )
971 resMgr->remove( _sec, _nam );
975 ProcessVoidEvent( new TEvent( name ) );
979 \fn QString SalomePyQt::getSetting( const QString& name );
980 \brief Get application setting value (as string represenation).
982 This function is obsolete. Use stringSetting(), integerSetting(),
983 boolSetting(), stringSetting() or colorSetting() instead.
985 \param name setting name (it should be of kind <section:setting> where
986 \c section is resources section name and \c setting is setting name)
987 \return setting name (empty string if setting name is invalid)
990 class TGetSettingEvent: public SALOME_Event
993 typedef QString TResult;
996 TGetSettingEvent( const QString& name ) : myName( name ) {}
997 virtual void Execute()
999 if ( SUIT_Session::session() ) {
1000 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1001 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1002 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1003 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1004 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1008 QString SalomePyQt::getSetting( const QString& name )
1010 return ProcessEvent( new TGetSettingEvent( name ) );
1014 \fn QString SalomePyQt::constant( const QString& name );
1015 \brief Get constant's value from application's resource manager.
1017 \param name name of the constant
1018 \return value of the constant
1023 class TGetConstantEvent: public SALOME_Event
1026 typedef QString TResult;
1029 TGetConstantEvent( const QString& name ) : myName( name ) {}
1030 virtual void Execute()
1032 if ( SUIT_Session::session() )
1033 myResult = SUIT_Session::session()->resourceMgr()->constant( myName );
1036 QString SalomePyQt::constant( const QString& name )
1038 return ProcessEvent( new TGetConstantEvent( name ) );
1042 \brief Add constant to the application's resource manager.
1044 This function is useful to specify programmatically specific
1045 variables that are referenced in the resource setting.
1047 For example, some resource value can be set as "$(myroot)/data/files".
1048 Then, "mypath" constant can be set programmatically by the application
1049 depending on run-time requirements.
1051 \param section resources file section name
1052 \param name name of the constant
1053 \param value value of the constant
1057 void SalomePyQt::setConstant( const QString& name, const QString& value )
1059 class TEvent: public SALOME_Event
1061 QString myName, myValue;
1063 TEvent( const QString& name, const QString& value )
1064 : myName( name ), myValue( value ) {}
1065 virtual void Execute()
1067 if ( SUIT_Session::session() )
1068 SUIT_Session::session()->resourceMgr()->setConstant( myName, myValue );
1071 ProcessVoidEvent( new TEvent( name, value ) );
1075 \brief Add double setting to the application preferences.
1076 \param section resources file section name
1077 \param name setting name
1078 \param value new setting value
1080 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1082 class TEvent: public SALOME_Event
1088 TEvent( const QString& section, const QString& name, double value )
1089 : mySection( section ), myName( name ), myValue( value ) {}
1090 virtual void Execute()
1092 if ( SUIT_Session::session() ) {
1093 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1094 if ( !mySection.isEmpty() && !myName.isEmpty() )
1095 resMgr->setValue( mySection, myName, myValue );
1099 ProcessVoidEvent( new TEvent( section, name, value ) );
1103 \brief Add integer setting to the application preferences.
1104 \param section resources file section name
1105 \param name setting name
1106 \param value new setting value
1108 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1110 class TEvent: public SALOME_Event
1116 TEvent( const QString& section, const QString& name, int value )
1117 : mySection( section ), myName( name ), myValue( value ) {}
1118 virtual void Execute()
1120 if ( SUIT_Session::session() ) {
1121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1122 if ( !mySection.isEmpty() && !myName.isEmpty() )
1123 resMgr->setValue( mySection, myName, myValue );
1127 ProcessVoidEvent( new TEvent( section, name, value ) );
1131 \brief Add boolean setting to the application preferences.
1132 \param section resources file section name
1133 \param name setting name
1134 \param value new setting value
1135 \param dumb this parameter is used in order to avoid sip compilation error
1136 because of conflicting int and bool types
1138 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1140 class TEvent: public SALOME_Event
1146 TEvent( const QString& section, const QString& name, bool value )
1147 : mySection( section ), myName( name ), myValue( value ) {}
1148 virtual void Execute()
1150 if ( SUIT_Session::session() ) {
1151 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1152 if ( !mySection.isEmpty() && !myName.isEmpty() )
1153 resMgr->setValue( mySection, myName, myValue );
1157 ProcessVoidEvent( new TEvent( section, name, value ) );
1161 \brief Add string setting to the application preferences.
1162 \param section resources file section name
1163 \param name setting name
1164 \param value new setting value
1166 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1168 class TEvent: public SALOME_Event
1174 TEvent( const QString& section, const QString& name, const QString& value )
1175 : mySection( section ), myName( name ), myValue( value ) {}
1176 virtual void Execute()
1178 if ( SUIT_Session::session() ) {
1179 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1180 if ( !mySection.isEmpty() && !myName.isEmpty() )
1181 resMgr->setValue( mySection, myName, myValue );
1185 ProcessVoidEvent( new TEvent( section, name, value ) );
1189 \brief Add color setting to the application preferences.
1190 \param section resources file section name
1191 \param name setting name
1192 \param value new setting value
1194 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1196 class TEvent: public SALOME_Event
1202 TEvent( const QString& section, const QString& name, const QColor& value )
1203 : mySection( section ), myName( name ), myValue( value ) {}
1204 virtual void Execute()
1206 if ( SUIT_Session::session() ) {
1207 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1208 if ( !mySection.isEmpty() && !myName.isEmpty() )
1209 resMgr->setValue( mySection, myName, myValue );
1213 ProcessVoidEvent( new TEvent( section, name, value ) );
1217 \brief Add byte array setting to the application preferences.
1218 \param section resources file section name
1219 \param name setting name
1220 \param value new setting value
1222 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1224 class TEvent: public SALOME_Event
1230 TEvent( const QString& section, const QString& name, const QByteArray& value )
1231 : mySection( section ), myName( name ), myValue( value ) {}
1232 virtual void Execute()
1234 if ( SUIT_Session::session() ) {
1235 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1236 if ( !mySection.isEmpty() && !myName.isEmpty() )
1237 resMgr->setValue( mySection, myName, myValue );
1241 ProcessVoidEvent( new TEvent( section, name, value ) );
1245 \fn int SalomePyQt::integerSetting( const QString& section,
1246 const QString& name,
1248 \brief Get integer setting from the application preferences.
1249 \param section resources file section name
1250 \param name setting name
1251 \param def default value which is returned if the setting is not found
1252 \return setting value
1255 class TGetIntSettingEvent: public SALOME_Event
1258 typedef int TResult;
1263 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1264 : mySection( section ), myName( name ), myDefault( def ) {}
1265 virtual void Execute()
1267 if ( SUIT_Session::session() ) {
1268 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1269 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1273 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1275 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1279 \fn double SalomePyQt::doubleSetting( const QString& section,
1280 const QString& name,
1282 \brief Get double setting from the application preferences.
1283 \param section resources file section name
1284 \param name setting name
1285 \param def default value which is returned if the setting is not found
1286 \return setting value
1289 class TGetDblSettingEvent: public SALOME_Event
1292 typedef double TResult;
1297 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1298 : mySection( section ), myName( name ), myDefault( def ) {}
1299 virtual void Execute()
1301 if ( SUIT_Session::session() ) {
1302 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1303 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1307 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1309 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1313 \fn bool SalomePyQt::boolSetting( const QString& section,
1314 const QString& name,
1316 \brief Get boolean setting from the application preferences.
1317 \param section resources file section name
1318 \param name setting name
1319 \param def default value which is returned if the setting is not found
1320 \return setting value
1323 class TGetBoolSettingEvent: public SALOME_Event
1326 typedef bool TResult;
1331 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1332 : mySection( section ), myName( name ), myDefault( def ) {}
1333 virtual void Execute()
1335 if ( SUIT_Session::session() ) {
1336 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1337 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1341 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1343 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1347 \fn QString SalomePyQt::stringSetting( const QString& section,
1348 const QString& name,
1351 \brief Get string setting from the application preferences.
1352 \param section resources file section name
1353 \param name setting name
1354 \param def default value which is returned if the setting is not found
1355 \param subst \c true to make substitution, \c false to get "raw" value
1356 \return setting value
1359 class TGetStrSettingEvent: public SALOME_Event
1362 typedef QString TResult;
1368 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def, const bool subst )
1369 : mySection( section ), myName( name ), myDefault( def ), mySubst( subst ) {}
1370 virtual void Execute()
1372 if ( SUIT_Session::session() ) {
1373 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1374 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault, mySubst ) : myDefault;
1378 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def, const bool subst )
1380 return ProcessEvent( new TGetStrSettingEvent( section, name, def, subst ) );
1384 \fn QColor SalomePyQt::colorSetting( const QString& section,
1385 const QString& name,
1387 \brief Get color setting from the application preferences.
1388 \param section resources file section name
1389 \param name setting name
1390 \param def default value which is returned if the setting is not found
1391 \return setting value
1394 class TGetColorSettingEvent: public SALOME_Event
1397 typedef QColor TResult;
1402 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1403 : mySection( section ), myName( name ), myDefault( def ) {}
1404 virtual void Execute()
1406 if ( SUIT_Session::session() ) {
1407 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1408 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1412 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1414 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1418 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1419 const QString& name,
1420 const QByteArray def );
1421 \brief Get byte array setting from the application preferences.
1422 \param section resources file section name
1423 \param name setting name
1424 \param def default value which is returned if the setting is not found
1425 \return setting value
1428 class TGetByteArraySettingEvent: public SALOME_Event
1431 typedef QByteArray TResult;
1436 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1437 : mySection( section ), myName( name ), myDefault( def ) {}
1438 virtual void Execute()
1440 if ( SUIT_Session::session() ) {
1441 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1442 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1446 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1448 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1452 \brief Remove setting from the application preferences.
1453 \param section resources file section name
1454 \param name setting name
1456 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1458 class TEvent: public SALOME_Event
1463 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1464 virtual void Execute()
1466 if ( SUIT_Session::session() ) {
1467 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1468 if ( !mySection.isEmpty() && !myName.isEmpty() )
1469 resMgr->remove( mySection, myName );
1473 ProcessVoidEvent( new TEvent( section, name ) );
1477 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1478 \brief Check setting existence in the application preferences.
1479 \param section resources file section name
1480 \param name setting name
1481 \return \c true if setting exists
1484 class THasSettingEvent: public SALOME_Event
1487 typedef bool TResult;
1491 THasSettingEvent( const QString& section, const QString& name )
1492 : mySection( section ), myName( name ) {}
1493 virtual void Execute()
1495 if ( SUIT_Session::session() ) {
1496 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1497 myResult = resMgr->hasValue( mySection, myName );
1501 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1503 return ProcessEvent( new THasSettingEvent( section, name ) );
1507 \fn QStringList SalomePyQt::parameters( const QString& section );
1508 \brief Get names of preference items stored within the given section.
1509 \param section resources file section's name
1510 \return \c list of preferences items
1514 \fn QStringList SalomePyQt::parameters( const QStringList& section );
1515 \brief Get names of preference items stored within the given section.
1516 \param section resources file section's name
1517 \return \c list of preferences items
1520 class TParametersEvent: public SALOME_Event
1523 typedef QStringList TResult;
1525 QStringList mySection;
1526 TParametersEvent( const QString& section )
1528 mySection << section;
1530 TParametersEvent( const QStringList& section )
1531 : mySection( section )
1533 virtual void Execute()
1535 if ( SUIT_Session::session() ) {
1536 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1537 myResult = resMgr->parameters( mySection );
1541 QStringList SalomePyQt::parameters( const QString& section )
1543 return ProcessEvent( new TParametersEvent( section ) );
1545 QStringList SalomePyQt::parameters( const QStringList& section )
1547 return ProcessEvent( new TParametersEvent( section ) );
1551 \fn QString SalomePyQt::getFileName( QWidget* parent,
1552 const QString& initial,
1553 const QStringList& filters,
1554 const QString& caption,
1556 \brief Show 'Open/Save file' dialog box for file selection
1557 and return a user's choice (selected file name).
1558 \param parent parent widget
1559 \param initial initial directory the dialog box to be opened in
1560 \param filters list of files filters (wildcards)
1561 \param caption dialog box title
1562 \param open if \c true, "Open File" dialog box is shown;
1563 otherwise "Save File" dialog box is shown
1564 \return selected file name (null string if user cancels operation)
1567 class TGetFileNameEvent: public SALOME_Event
1570 typedef QString TResult;
1574 QStringList myFilters;
1577 TGetFileNameEvent( QWidget* parent,
1578 const QString& initial,
1579 const QStringList& filters,
1580 const QString& caption,
1582 : myParent ( parent ),
1583 myInitial( initial ),
1584 myFilters( filters ),
1585 myCaption( caption ),
1587 virtual void Execute()
1589 if ( LightApp_Application* anApp = getApplication() ) {
1590 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1591 myCaption, myParent );
1595 QString SalomePyQt::getFileName( QWidget* parent,
1596 const QString& initial,
1597 const QStringList& filters,
1598 const QString& caption,
1601 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1605 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1606 const QString& initial,
1607 const QStringList& filters,
1608 const QString& caption );
1609 \brief Show 'Open files' dialog box for multiple files selection
1610 and return a user's choice (selected file names list).
1611 \param parent parent widget
1612 \param initial initial directory the dialog box to be opened in
1613 \param filters list of files filters (wildcards)
1614 \param caption dialog box title
1615 \return selected file names list (empty list if user cancels operation)
1618 class TGetOpenFileNamesEvent: public SALOME_Event
1621 typedef QStringList TResult;
1625 QStringList myFilters;
1627 TGetOpenFileNamesEvent( QWidget* parent,
1628 const QString& initial,
1629 const QStringList& filters,
1630 const QString& caption )
1631 : myParent ( parent ),
1632 myInitial( initial ),
1633 myFilters( filters ),
1634 myCaption( caption ) {}
1635 virtual void Execute()
1637 if ( LightApp_Application* anApp = getApplication() ) {
1638 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1642 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1643 const QString& initial,
1644 const QStringList& filters,
1645 const QString& caption )
1647 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1651 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1652 const QString& initial,
1653 const QString& caption );
1654 \brief Show 'Get Directory' dialog box for the directory selection
1655 and return a user's choice (selected directory name).
1656 \param parent parent widget
1657 \param initial initial directory the dialog box to be opened in
1658 \param caption dialog box title
1659 \return selected directory name (null string if user cancels operation)
1662 class TGetExistingDirectoryEvent: public SALOME_Event
1665 typedef QString TResult;
1670 TGetExistingDirectoryEvent( QWidget* parent,
1671 const QString& initial,
1672 const QString& caption )
1673 : myParent ( parent ),
1674 myInitial( initial ),
1675 myCaption( caption ) {}
1676 virtual void Execute()
1678 if ( LightApp_Application* anApp = getApplication() ) {
1679 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1683 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1684 const QString& initial,
1685 const QString& caption )
1687 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1691 \fn QString SalomePyQt::loadIcon( const QString& filename );
1692 \brief Load an icon from the module resources by the specified file name.
1693 \param fileName icon file name
1697 class TLoadIconEvent: public SALOME_Event
1700 typedef QIcon TResult;
1704 TLoadIconEvent( const QString& module, const QString& filename )
1705 : myModule( module ),
1706 myFileName ( filename ) {}
1707 virtual void Execute()
1709 myResult = loadIconInternal( myModule, myFileName );
1712 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1714 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1718 \brief Open external browser to display context help information.
1721 Current implementation does nothing.
1723 \param source documentation (HTML) file name
1724 \param context context (for example, HTML ancor name)
1726 void SalomePyQt::helpContext( const QString& source, const QString& context )
1728 class TEvent: public SALOME_Event
1733 TEvent( const QString& source, const QString& context )
1734 : mySource( source ), myContext( context ) {}
1735 virtual void Execute()
1737 if ( LightApp_Application* anApp = getApplication() ) {
1738 anApp->onHelpContextModule( "", mySource, myContext );
1742 ProcessVoidEvent( new TEvent( source, context ) );
1746 \fn int SalomePyQt::defaultMenuGroup();
1747 \brief Get detault menu group identifier which can be used when
1748 creating menus (insert custom menu commands).
1749 \return default menu group ID
1752 class TDefMenuGroupEvent: public SALOME_Event
1755 typedef int TResult;
1757 TDefMenuGroupEvent() : myResult( -1 ) {}
1758 virtual void Execute()
1760 myResult = PyModuleHelper::defaultMenuGroup();
1763 int SalomePyQt::defaultMenuGroup()
1765 return ProcessEvent( new TDefMenuGroupEvent() );
1771 CrTool( const QString& tBar, const QString& nBar )
1772 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1773 CrTool( const int id, const int tBar, const int idx )
1774 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1775 CrTool( const int id, const QString& tBar, const int idx )
1776 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1777 CrTool( QAction* action, const int tbId, const int id, const int idx )
1778 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1779 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1780 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1782 int execute( LightApp_Module* module ) const
1787 return module->createTool( myTbTitle, myTbName );
1789 return module->createTool( myId, myTbId, myIndex );
1791 return module->createTool( myId, myTbTitle, myIndex );
1793 return module->createTool( myAction, myTbId, myId, myIndex );
1795 return module->createTool( myAction, myTbTitle, myId, myIndex );
1810 class TCreateToolEvent: public SALOME_Event
1813 typedef int TResult;
1815 const CrTool& myCrTool;
1816 TCreateToolEvent( const CrTool& crTool )
1817 : myResult( -1 ), myCrTool( crTool ) {}
1818 virtual void Execute()
1820 LightApp_Module* module = getActiveModule();
1822 myResult = myCrTool.execute( module );
1827 \brief Create toolbar with specified name.
1828 \param tBar toolbar title (language-dependent)
1829 \param nBar toolbar name (language-independent) [optional]
1830 \return toolbar ID or -1 if toolbar creation is failed
1832 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1834 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1838 \brief Insert action with specified \a id to the toolbar.
1840 \param tBar toolbar ID
1841 \param idx required index in the toolbar
1842 \return action ID or -1 if action could not be added
1844 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1846 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1850 \brief Insert action with specified \a id to the toolbar.
1852 \param tBar toolbar name
1853 \param idx required index in the toolbar
1854 \return action ID or -1 if action could not be added
1856 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1858 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1862 \brief Insert action to the toolbar.
1864 \param tBar toolbar ID
1865 \param id required action ID
1866 \param idx required index in the toolbar
1867 \return action ID or -1 if action could not be added
1869 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1871 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1875 \brief Insert action to the toolbar.
1877 \param tBar toolbar name
1878 \param id required action ID
1879 \param idx required index in the toolbar
1880 \return action ID or -1 if action could not be added
1882 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1884 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1890 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1891 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1892 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1893 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1894 CrMenu( const int id, const int menu, const int group, const int idx )
1895 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1896 CrMenu( const int id, const QString& menu, const int group, const int idx )
1897 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1898 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1899 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1900 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1901 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1903 int execute( LightApp_Module* module ) const
1908 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1910 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1912 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1914 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1916 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1918 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1927 QString mySubMenuName;
1934 class TCreateMenuEvent: public SALOME_Event
1937 typedef int TResult;
1939 const CrMenu& myCrMenu;
1940 TCreateMenuEvent( const CrMenu& crMenu )
1941 : myResult( -1 ), myCrMenu( crMenu ) {}
1942 virtual void Execute()
1944 LightApp_Module* module = getActiveModule();
1946 myResult = myCrMenu.execute( module );
1951 \brief Create main menu.
1952 \param subMenu menu name
1953 \param menu parent menu ID
1954 \param id required menu ID
1955 \param group menu group ID
1956 \param idx required index in the menu
1957 \return menu ID or -1 if menu could not be added
1959 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1961 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1965 \brief Create main menu.
1966 \param subMenu menu name
1967 \param menu parent menu name (list of menu names separated by "|")
1968 \param id required menu ID
1969 \param group menu group ID
1970 \param idx required index in the menu
1971 \return menu ID or -1 if menu could not be added
1973 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1975 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1979 \brief Insert action to the main menu.
1981 \param menu parent menu ID
1982 \param group menu group ID
1983 \param idx required index in the menu
1984 \return action ID or -1 if action could not be added
1986 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1988 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1992 \brief Insert action to the main menu.
1994 \param menu parent menu name (list of menu names separated by "|")
1995 \param group menu group ID
1996 \param idx required index in the menu
1997 \return action ID or -1 if action could not be added
1999 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
2001 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
2005 \brief Insert action to the main menu.
2007 \param menu parent menu ID
2008 \param group menu group ID
2009 \param idx required index in the menu
2010 \return action ID or -1 if action could not be added
2012 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
2014 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2018 \brief Insert action to the main menu.
2020 \param menu parent menu name (list of menu names separated by "|")
2021 \param group menu group ID
2022 \param idx required index in the menu
2023 \return action ID or -1 if action could not be added
2025 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
2027 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
2031 \fn QAction* SalomePyQt::createSeparator();
2032 \brief Create separator action which can be used in the menu or toolbar.
2033 \return new separator action
2036 class TCreateSepEvent: public SALOME_Event
2039 typedef QAction* TResult;
2043 virtual void Execute()
2045 LightApp_Module* module = getActiveModule();
2047 myResult = (QAction*)module->separator();
2050 QAction* SalomePyQt::createSeparator()
2052 return ProcessEvent( new TCreateSepEvent() );
2056 \fn QAction* SalomePyQt::createAction( const int id,
2057 const QString& menuText,
2058 const QString& tipText,
2059 const QString& statusText,
2060 const QString& icon,
2062 const bool toggle );
2063 \brief Create an action which can be then used in the menu or toolbar.
2064 \param id the unique id action to be registered to
2065 \param menuText action text which should appear in menu
2066 \param tipText text which should appear in the tooltip
2067 \param statusText text which should appear in the status bar when action is activated
2068 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
2069 \param key the key accelrator for the action
2070 \param toggle if \c true the action is checkable
2073 class TCreateActionEvent: public SALOME_Event
2076 typedef QAction* TResult;
2081 QString myStatusText;
2085 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
2086 const QString& statusText, const QString& icon, const int key, const bool toggle )
2087 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
2088 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
2089 virtual void Execute()
2091 LightApp_Module* module = getActiveModule();
2093 QIcon icon = loadIconInternal( module->name(), myIcon );
2094 myResult = (QAction*)module->action( myId );
2096 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
2097 myResult->setToolTip( myTipText );
2098 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
2099 myResult->setText( myMenuText );
2100 if ( myResult->icon().isNull() && !icon.isNull() )
2101 myResult->setIcon( icon );
2102 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
2103 myResult->setStatusTip( myStatusText );
2104 if ( myResult->shortcut().isEmpty() && myKey )
2105 myResult->setShortcut( myKey );
2106 if ( myResult->isCheckable() != myToggle )
2107 myResult->setCheckable( myToggle );
2110 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2112 // for Python module, automatically connect action to callback slot
2113 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2114 if ( helper ) helper->connectAction( myResult );
2118 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2119 const QString& tipText, const QString& statusText,
2120 const QString& icon, const int key, const bool toggle )
2122 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2126 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2127 \brief Create an action group which can be then used in the menu or toolbar
2128 \param id : the unique id action group to be registered to
2129 \param exclusive : if \c true the action group does exclusive toggling
2132 struct TCreateActionGroupEvent: public SALOME_Event
2134 typedef QtxActionGroup* TResult;
2138 TCreateActionGroupEvent( const int id, const bool exclusive )
2139 : myId( id ), myExclusive( exclusive ) {}
2140 virtual void Execute()
2142 LightApp_Module* module = getActiveModule();
2144 myResult = module->createActionGroup( myId, myExclusive );
2147 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2149 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2153 \fn QAction* SalomePyQt::action( const int id );
2154 \brief Get action by specified identifier.
2155 \return action or 0 if action is not registered
2158 class TActionEvent: public SALOME_Event
2161 typedef QAction* TResult;
2164 TActionEvent( const int id )
2165 : myResult( 0 ), myId( id ) {}
2166 virtual void Execute()
2168 LightApp_Module* module = getActiveModule();
2170 myResult = (QAction*)module->action( myId );
2173 QAction* SalomePyQt::action( const int id )
2175 return ProcessEvent( new TActionEvent( id ) );
2179 \fn int SalomePyQt::actionId( const QAction* a );
2180 \brief Get an action identifier.
2181 \return action ID or -1 if action is not registered
2184 class TActionIdEvent: public SALOME_Event
2187 typedef int TResult;
2189 const QAction* myAction;
2190 TActionIdEvent( const QAction* action )
2191 : myResult( -1 ), myAction( action ) {}
2192 virtual void Execute()
2194 LightApp_Module* module = getActiveModule();
2196 myResult = module->actionId( myAction );
2199 int SalomePyQt::actionId( const QAction* a )
2201 return ProcessEvent( new TActionIdEvent( a ) );
2205 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2206 \brief Add global (not module-related) preferences group.
2207 \param label global preferences group name
2208 \return preferences group identifier
2211 class TAddGlobalPrefEvent: public SALOME_Event
2214 typedef int TResult;
2217 TAddGlobalPrefEvent( const QString& label )
2218 : myResult( -1 ), myLabel( label ) {}
2219 virtual void Execute()
2221 LightApp_Module* module = getActiveModule();
2223 LightApp_Preferences* pref = module->getApp()->preferences();
2225 myResult = pref->addPreference( myLabel, -1 );
2229 int SalomePyQt::addGlobalPreference( const QString& label )
2231 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2235 \fn int SalomePyQt::addPreference( const QString& label );
2236 \brief Add module-related preferences group.
2237 \param label preferences group name
2238 \return preferences group identifier
2241 class TAddPrefEvent: public SALOME_Event
2244 typedef int TResult;
2247 TAddPrefEvent( const QString& label )
2248 : myResult( -1 ), myLabel( label ) {}
2249 virtual void Execute()
2251 LightApp_Module* module = getActiveModule();
2253 LightApp_Preferences* pref = module->getApp()->preferences();
2255 int cId = pref->addPreference( module->moduleName(), -1 );
2257 myResult = pref->addPreference( myLabel, cId );
2262 int SalomePyQt::addPreference( const QString& label )
2264 return ProcessEvent( new TAddPrefEvent( label ) );
2268 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2269 const QString& section, const QString& param );
2270 \brief Add module-related preferences.
2271 \param label preferences group name
2272 \param pId parent preferences group id
2273 \param type preferences type
2274 \param section resources file section name
2275 \param param resources file setting name
2276 \return preferences identifier
2279 class TAddPrefParamEvent: public SALOME_Event
2282 typedef int TResult;
2289 TAddPrefParamEvent( const QString& label,
2290 const int pId, const int type,
2291 const QString& section,
2292 const QString& param )
2294 myLabel( label ), myPId( pId ), myType( type ),
2295 mySection( section ), myParam ( param ) {}
2296 virtual void Execute()
2298 LightApp_Module* module = getActiveModule();
2300 LightApp_Preferences* pref = module->getApp()->preferences();
2302 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2306 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2307 const QString& section, const QString& param )
2309 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2313 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2314 \brief Get the preferences property.
2315 \param id preferences identifier
2316 \param prop preferences property name
2317 \return preferences property value or null QVariant if property is not set
2320 class TPrefPropEvent: public SALOME_Event
2323 typedef QVariant TResult;
2327 TPrefPropEvent( const int id, const QString& prop )
2328 : myId( id ), myProp( prop ) {}
2329 virtual void Execute()
2331 LightApp_Module* module = getActiveModule();
2333 LightApp_Preferences* pref = module->getApp()->preferences();
2335 myResult = pref->itemProperty( myProp, myId );
2339 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2341 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2345 \brief Set the preferences property.
2346 \param id preferences identifier
2347 \param prop preferences property name
2348 \param var preferences property value
2350 void SalomePyQt::setPreferenceProperty( const int id,
2351 const QString& prop,
2352 const QVariant& var )
2354 class TEvent: public SALOME_Event
2360 TEvent( const int id, const QString& prop, const QVariant& var )
2361 : myId( id ), myProp( prop ), myVar( var ) {}
2362 virtual void Execute()
2364 LightApp_Module* module = getActiveModule();
2366 LightApp_Preferences* pref = module->getApp()->preferences();
2368 pref->setItemProperty( myProp, myVar, myId );
2372 ProcessVoidEvent( new TEvent( id, prop, var) );
2376 \brief Add the property value to the list of values.
2378 This method allows creating properties which are QList<QVariant>
2379 - there is no way to pass such values directly to QVariant parameter with PyQt.
2381 \param id preferences identifier
2382 \param prop preferences property name
2383 \param idx preferences property index
2384 \param var preferences property value for the index \a idx
2386 void SalomePyQt::addPreferenceProperty( const int id,
2387 const QString& prop,
2389 const QVariant& var )
2391 class TEvent: public SALOME_Event
2398 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2399 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2400 virtual void Execute()
2402 LightApp_Module* module = getActiveModule();
2404 LightApp_Preferences* pref = module->getApp()->preferences();
2406 QVariant var = pref->itemProperty( myProp, myId );
2407 if ( var.isValid() ) {
2408 if ( var.type() == QVariant::StringList ) {
2409 QStringList sl = var.toStringList();
2410 if ( myIdx >= 0 && myIdx < sl.count() )
2411 sl[myIdx] = myVar.toString();
2413 sl.append( myVar.toString() );
2414 pref->setItemProperty( myProp, sl, myId );
2416 else if ( var.type() == QVariant::List ) {
2417 QList<QVariant> vl = var.toList();
2418 if ( myIdx >= 0 && myIdx < vl.count() )
2422 pref->setItemProperty( myProp, vl, myId );
2428 pref->setItemProperty( myProp, vl, myId );
2434 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2438 \brief Put the message to the Log messages output window
2439 \param msg message text (it can be of simple rich text format)
2440 \param addSeparator boolean flag which specifies if it is necessary
2441 to separate the message with predefined separator
2443 void SalomePyQt::message( const QString& msg, bool addSeparator )
2445 class TEvent: public SALOME_Event
2450 TEvent( const QString& msg, bool addSeparator )
2451 : myMsg( msg ), myAddSep( addSeparator ) {}
2452 virtual void Execute()
2454 if ( LightApp_Application* anApp = getApplication() ) {
2455 LogWindow* lw = anApp->logWindow();
2457 lw->putMessage( myMsg, myAddSep );
2461 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2465 \brief Remove all the messages from the Log messages output window.
2467 void SalomePyQt::clearMessages()
2469 class TEvent: public SALOME_Event
2473 virtual void Execute()
2475 if ( LightApp_Application* anApp = getApplication() ) {
2476 LogWindow* lw = anApp->logWindow();
2482 ProcessVoidEvent( new TEvent() );
2486 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2487 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2488 to the image file in the specified format.
2490 For the current moment JPEG, PNG and BMP images formats are supported.
2491 The image format is defined automatically by the file name extension.
2492 By default, BMP format is used.
2494 \param filename image file name
2495 \return operation status (\c true on success)
2498 class TDumpViewEvent: public SALOME_Event
2501 typedef bool TResult;
2505 TDumpViewEvent( const QString& filename, const int id )
2506 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2507 virtual void Execute()
2509 SUIT_ViewWindow* wnd = 0;
2511 if ( LightApp_Application* anApp = getApplication() ) {
2512 SUIT_ViewManager* vm = anApp->activeViewManager();
2514 wnd = vm->getActiveView();
2516 myWndId = wnd->getId();
2519 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2522 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2523 #ifndef DISABLE_PLOT2DVIEWER
2524 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2526 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2527 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2528 qApp->processEvents();
2529 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2530 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2534 #endif // DISABLE_PLOT2DVIEWER
2535 QImage im = wnd->dumpView();
2536 if ( !im.isNull() && !myFileName.isEmpty() ) {
2537 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2538 if ( fmt == "JPG" ) fmt = "JPEG";
2539 myResult = im.save( myFileName, fmt.toLatin1() );
2544 bool SalomePyQt::dumpView( const QString& filename, const int id )
2546 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2550 \fn QList<int> SalomePyQt::getViews();
2551 \brief Get list of integer identifiers of all the currently opened views
2552 \return list of integer identifiers of all the currently opened views
2555 class TGetViews: public SALOME_Event
2558 typedef QList<int> TResult;
2561 virtual void Execute()
2564 LightApp_Application* app = getApplication();
2566 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2568 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2569 SUIT_ViewWindow* wnd;
2570 foreach ( wnd, wndlist )
2571 myResult.append( wnd->getId() );
2576 QList<int> SalomePyQt::getViews()
2578 return ProcessEvent( new TGetViews() );
2582 \fn int SalomePyQt::getActiveView();
2583 \brief Get integer identifier of the currently active view
2584 \return integer identifier of the currently active view
2587 class TGetActiveView: public SALOME_Event
2590 typedef int TResult;
2594 virtual void Execute()
2596 LightApp_Application* app = getApplication();
2598 SUIT_ViewManager* viewMgr = app->activeViewManager();
2600 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2602 myResult = wnd->getId();
2607 int SalomePyQt::getActiveView()
2609 return ProcessEvent( new TGetActiveView() );
2613 \fn QString SalomePyQt::getViewType( const int id );
2614 \brief Get type of the specified view, e.g. "OCCViewer"
2615 \param id window identifier
2619 class TGetViewType: public SALOME_Event
2622 typedef QString TResult;
2625 TGetViewType( const int id )
2627 virtual void Execute()
2629 SUIT_ViewWindow* wnd = getWnd( myWndId );
2631 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2633 myResult = viewMgr->getType();
2637 QString SalomePyQt::getViewType( const int id )
2639 return ProcessEvent( new TGetViewType( id ) );
2643 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2644 \brief Change view caption
2645 \param id window identifier
2646 \param title new window title
2647 \return \c true if operation is completed successfully and \c false otherwise
2650 class TSetViewTitle: public SALOME_Event
2653 typedef bool TResult;
2657 TSetViewTitle( const int id, const QString& title )
2658 : myResult( false ),
2661 virtual void Execute()
2663 SUIT_ViewWindow* wnd = getWnd( myWndId );
2665 wnd->setWindowTitle( myTitle );
2670 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2672 return ProcessEvent( new TSetViewTitle( id, title ) );
2676 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2677 \brief Set view size
2678 \param w window width
2679 \param h window height
2680 \param id window identifier
2681 \return \c true if operation is completed successfully and \c false otherwise
2684 class TSetViewSize: public SALOME_Event
2687 typedef bool TResult;
2692 TSetViewSize( const int w, const int h, const int id )
2693 : myResult( false ),
2697 virtual void Execute()
2699 SUIT_ViewWindow* wnd = 0;
2701 if ( LightApp_Application* anApp = getApplication() ) {
2702 SUIT_ViewManager* vm = anApp->activeViewManager();
2704 wnd = vm->getActiveView();
2708 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2711 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2713 QString type = viewMgr->getType();
2714 if ( type == "OCCViewer") {
2715 #ifndef DISABLE_OCCVIEWER
2716 // specific processing for OCC viewer:
2717 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2718 // - if there is only one sub-view active; it will be resized;
2719 // - if there are several sub-views, each of them will be resized.
2720 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2721 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2722 if ( occView && occView->getView( i ) ) {
2723 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2727 #endif // DISABLE_OCCVIEWER
2729 else if ( type == "ParaView") {
2730 #ifndef DISABLE_PVVIEWER
2731 // specific processing for ParaView viewer:
2732 // hierarchy of ParaView viewer is much complex than for usual view;
2733 // we look for sub-widget named "Viewport"
2734 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2735 if ( !lst.isEmpty() ) {
2736 lst[0]->resize( myWndWidth, myWndHeight );
2739 #endif // DISABLE_PVVIEWER
2742 if ( wnd->centralWidget() ) {
2743 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2751 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2753 return ProcessEvent( new TSetViewSize( w, h, id ) );
2757 \fn QString SalomePyQt::getViewTitle( const int id );
2758 \brief Get view caption
2759 \param id window identifier
2760 \return view caption
2763 class TGetViewTitle: public SALOME_Event
2766 typedef QString TResult;
2769 TGetViewTitle( const int id )
2771 virtual void Execute()
2773 SUIT_ViewWindow* wnd = getWnd( myWndId );
2775 myResult = wnd->windowTitle();
2778 QString SalomePyQt::getViewTitle( const int id )
2780 return ProcessEvent( new TGetViewTitle( id ) );
2784 \fn QList<int> SalomePyQt::findViews( const QString& type );
2785 \brief Get list of integer identifiers of all the
2786 currently opened views of the specified type
2787 \param type viewer type
2788 \return list of integer identifiers
2791 class TFindViews: public SALOME_Event
2794 typedef QList<int> TResult;
2797 TFindViews( const QString& type )
2799 virtual void Execute()
2802 LightApp_Application* app = getApplication();
2804 ViewManagerList vmList;
2805 app->viewManagers( myType, vmList );
2806 SUIT_ViewManager* viewMgr;
2807 foreach ( viewMgr, vmList ) {
2808 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2809 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2810 SUIT_ViewWindow* wnd = vec[ i ];
2812 myResult.append( wnd->getId() );
2818 QList<int> SalomePyQt::findViews( const QString& type )
2820 return ProcessEvent( new TFindViews( type ) );
2824 \fn bool SalomePyQt::activateView( const int id );
2825 \brief Activate view
2826 \param id window identifier
2827 \return \c true if operation is completed successfully and \c false otherwise
2830 class TActivateView: public SALOME_Event
2833 typedef bool TResult;
2836 TActivateView( const int id )
2837 : myResult( false ),
2839 virtual void Execute()
2841 SUIT_ViewWindow* wnd = getWnd( myWndId );
2848 bool SalomePyQt::activateView( const int id )
2850 return ProcessEvent( new TActivateView( id ) );
2854 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2855 \brief Create new view and activate it
2856 \param type viewer type
2860 \return integer identifier of created view (or -1 if view could not be created)
2863 class TCreateView: public SALOME_Event
2866 typedef int TResult;
2872 TCreateView( const QString& theType, bool visible, const int width, const int height )
2878 virtual void Execute()
2880 LightApp_Application* app = getApplication();
2882 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2884 QWidget* wnd = viewMgr->getActiveView();
2885 myResult = viewMgr->getActiveView()->getId();
2888 wnd->setVisible(false);
2889 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2893 if (myWidth > 0 && myHeight > 0) {
2894 #ifndef DISABLE_PLOT2DVIEWER
2895 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2896 if ( wnd2D ) wnd = wnd2D->getViewFrame();
2897 #endif // DISABLE_PLOT2DVIEWER
2898 wnd->setGeometry( 0, 0, myWidth, myHeight );
2905 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2907 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2908 QCoreApplication::processEvents();
2913 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2914 \brief Create new view with custom widget embedded and activate it
2915 \param type viewer type
2916 \param w custom widget
2917 \return integer identifier of created view (or -1 if view could not be created)
2920 class TCreateViewWg: public SALOME_Event
2923 typedef int TResult;
2927 TCreateViewWg( const QString& theType, QWidget* w )
2931 virtual void Execute()
2933 LightApp_Application* app = getApplication();
2935 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2937 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2939 myResult = wnd->getId();
2944 int SalomePyQt::createView( const QString& type, QWidget* w )
2946 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2947 QCoreApplication::processEvents();
2952 \fn bool SalomePyQt::closeView( const int id );
2954 \param id window identifier
2955 \return \c true if operation is completed successfully and \c false otherwise
2958 class TCloseView: public SALOME_Event
2961 typedef bool TResult;
2964 TCloseView( const int id )
2965 : myResult( false ),
2967 virtual void Execute()
2969 SUIT_ViewWindow* wnd = getWnd( myWndId );
2971 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2979 bool SalomePyQt::closeView( const int id )
2981 return ProcessEvent( new TCloseView( id ) );
2985 \fn int SalomePyQt::cloneView( const int id );
2986 \brief Clone view (if this operation is supported for specified view type)
2987 \param id window identifier
2988 \return integer identifier of the cloned view or -1 or operation could not be performed
2991 class TCloneView: public SALOME_Event
2994 typedef int TResult;
2997 TCloneView( const int id )
3000 virtual void Execute()
3002 SUIT_ViewWindow* wnd = getWnd( myWndId );
3004 SUIT_ViewManager* viewMgr = wnd->getViewManager();
3006 #ifndef DISABLE_OCCVIEWER
3007 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
3008 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
3009 occView->onCloneView();
3010 wnd = viewMgr->getActiveView();
3012 myResult = wnd->getId();
3014 #endif // DISABLE_OCCVIEWER
3015 #ifndef DISABLE_PLOT2DVIEWER
3016 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
3017 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
3018 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3019 if ( viewMgr2d && srcWnd2d ) {
3020 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
3021 myResult = resWnd->getId();
3024 #endif // DISABLE_OCCVIEWER
3029 int SalomePyQt::cloneView( const int id )
3031 return ProcessEvent( new TCloneView( id ) );
3035 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
3036 \brief Set view visibility.
3037 \param id window identifier
3038 \param visible new visiblity
3041 void SalomePyQt::setViewVisible( const int id, const bool visible )
3043 class TEvent: public SALOME_Event
3048 TEvent( const int id, const bool visible )
3049 : myWndId( id ), myVisible( visible ) {}
3050 virtual void Execute()
3052 SUIT_ViewWindow* wnd = getWnd( myWndId );
3053 if ( wnd ) wnd->setVisible( myVisible );
3056 ProcessVoidEvent( new TEvent( id, visible ) );
3060 \fn bool SalomePyQt::isViewVisible( const int id );
3061 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
3062 \param id window identifier
3063 \return \c true if view is visible and \c false otherwise
3066 class TIsViewVisible: public SALOME_Event
3069 typedef bool TResult;
3072 TIsViewVisible( const int id )
3073 : myResult( false ),
3075 virtual void Execute()
3077 SUIT_ViewWindow* wnd = getWnd( myWndId );
3080 QWidget* p = wnd->parentWidget();
3081 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
3085 bool SalomePyQt::isViewVisible( const int id )
3087 return ProcessEvent( new TIsViewVisible( id ) );
3091 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
3092 \brief Set / clear view's "closable" option. By default any view is closable
3093 (i.e. can be closed by the user).
3094 \param id window identifier
3095 \param on new "closable" option's value
3098 void SalomePyQt::setViewClosable( const int id, const bool on )
3100 class TEvent: public SALOME_Event
3105 TEvent( const int id, const bool on )
3106 : myWndId( id ), myOn( on ) {}
3107 virtual void Execute()
3109 SUIT_ViewWindow* wnd = getWnd( myWndId );
3110 if ( wnd ) wnd->setClosable( myOn );
3113 ProcessVoidEvent( new TEvent( id, on ) );
3117 \fn bool SalomePyQt::isViewClosable( const int id );
3118 \brief Check whether view is closable (i.e. can be closed by the user)
3119 \param id window identifier
3120 \return \c true if view is closable or \c false otherwise
3123 class TIsViewClosable: public SALOME_Event
3126 typedef bool TResult;
3129 TIsViewClosable( const int id )
3132 virtual void Execute()
3134 SUIT_ViewWindow* wnd = getWnd( myWndId );
3136 myResult = wnd->closable();
3140 bool SalomePyQt::isViewClosable( const int id )
3142 return ProcessEvent( new TIsViewClosable( id ) );
3146 \fn bool SalomePyQt::groupAllViews();
3147 \brief Group all views to the single tab area
3148 \return \c true if operation is completed successfully and \c false otherwise
3151 class TGroupAllViews: public SALOME_Event
3154 typedef bool TResult;
3157 : myResult( false ) {}
3158 virtual void Execute()
3160 LightApp_Application* app = getApplication();
3162 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3164 QtxWorkstack* wStack = tabDesk->workstack();
3173 bool SalomePyQt::groupAllViews()
3175 return ProcessEvent( new TGroupAllViews() );
3179 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3180 \brief Split tab area to which view with identifier belongs to
3181 \param id window identifier
3182 \param ori orientation of split operation
3183 \param action action to be performed
3184 \return \c true if operation is completed successfully \c false otherwise
3187 class TSplitView: public SALOME_Event
3190 typedef bool TResult;
3195 TSplitView( const int id,
3196 const Orientation ori,
3197 const Action action )
3198 : myResult( false ),
3201 myAction( action ) {}
3202 virtual void Execute()
3204 SUIT_ViewWindow* wnd = getWnd( myWndId );
3207 // wnd->setFocus(); ???
3210 if ( getApplication() ) {
3211 STD_TabDesktop* desk =
3212 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3214 QtxWorkstack* wStack = desk->workstack();
3216 Qt::Orientation qtOri =
3217 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3219 QtxWorkstack::SplitType sType;
3220 if ( myAction == MoveWidget )
3221 sType = QtxWorkstack::SplitMove;
3222 else if ( myAction == LeaveWidget )
3223 sType = QtxWorkstack::SplitStay;
3225 sType = QtxWorkstack::SplitAt;
3227 wStack->Split( wnd, qtOri, sType );
3235 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3237 return ProcessEvent( new TSplitView( id, ori, action ) );
3241 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3242 \brief Move view with the first identifier to the same area which
3243 another view with the second identifier belongs to
3244 \param id source window identifier
3245 \param id_to destination window identifier
3246 param before specifies whether the first viewt has to be moved before or after
3248 \return \c true if operation is completed successfully and \c false otherwise
3251 class TMoveView: public SALOME_Event
3254 typedef bool TResult;
3259 TMoveView( const int id, const int id_to, const bool before )
3260 : myResult( false ),
3263 myIsBefore( before ) {}
3264 virtual void Execute()
3266 SUIT_ViewWindow* wnd = getWnd( myWndId );
3267 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3268 if ( wnd && wnd_to ) {
3269 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3270 getApplication()->desktop() )->workstack();
3272 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3276 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3278 return ProcessEvent( new TMoveView( id, id_to, before ) );
3282 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3283 \brief Get list of views identifiers that belongs to the same area as
3284 specified view (excluding it)
3285 \param id window identifier
3286 \return list of views identifiers
3289 class TNeighbourViews: public SALOME_Event
3292 typedef QList<int> TResult;
3295 TNeighbourViews( const int id )
3297 virtual void Execute()
3300 SUIT_ViewWindow* wnd = getWnd( myWndId );
3302 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3303 getApplication()->desktop() )->workstack();
3305 QWidgetList wgList = wStack->windowList( wnd );
3307 foreach ( wg, wgList ) {
3308 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3309 if ( tmpWnd && tmpWnd != wnd )
3310 myResult.append( tmpWnd->getId() );
3316 QList<int> SalomePyQt::neighbourViews( const int id )
3318 return ProcessEvent( new TNeighbourViews( id ) );
3323 \fn void SalomePyQt::createRoot();
3324 \brief Initialize root data object.
3326 Does nothing if root is already initialized.
3329 void SalomePyQt::createRoot()
3331 class TEvent: public SALOME_Event
3335 virtual void Execute()
3337 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3339 SALOME_PYQT_DataModelLight* dm =
3340 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
3345 if ( verbose() ) printf( "SalomePyQt.createRoot() function is not supported for the current module.\n" );
3349 ProcessVoidEvent( new TEvent() );
3353 \fn QString SalomePyQt::createObject( const QString& parent );
3354 \brief Create empty data object
3355 \param parent entry of parent data object
3356 \return entry of created data object
3359 class TCreateEmptyObjectEvent: public SALOME_Event
3362 typedef QString TResult;
3365 TCreateEmptyObjectEvent( const QString& parent )
3366 : myParent( parent ) {}
3367 virtual void Execute()
3369 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3371 myResult = module->createObject( myParent );
3374 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3378 QString SalomePyQt::createObject( const QString& parent )
3380 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3384 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3385 const QString& tooltip,const QString& parent );
3386 \brief Create new data object with specified name, icon and tooltip
3387 \param name data object name
3388 \param icon data object icon
3389 \param toolTip data object tooltip
3390 \param parent entry of parent data object
3391 \return entry of created data object
3394 class TCreateObjectEvent: public SALOME_Event
3397 typedef QString TResult;
3403 TCreateObjectEvent( const QString& name,
3404 const QString& icon,
3405 const QString& tooltip,
3406 const QString& parent )
3409 myToolTip( tooltip ),
3410 myParent( parent ) {}
3411 virtual void Execute()
3413 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3415 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3418 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3422 QString SalomePyQt::createObject( const QString& name,
3423 const QString& icon,
3424 const QString& toolTip,
3425 const QString& parent )
3427 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3432 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3433 \brief Set data object name
3434 \param entry data object entry
3435 \param name data object name
3437 class TSetNameEvent: public SALOME_Event
3442 TSetNameEvent( const QString& entry,
3443 const QString& name )
3446 virtual void Execute()
3448 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3450 module->setName( myEntry, myName );
3453 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3457 void SalomePyQt::setName( const QString& entry, const QString& name )
3459 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3463 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3464 \brief Set data object icon
3465 \param entry data object entry
3466 \param icon data object icon file name (icon is loaded from module resources)
3469 class TSetIconEvent: public SALOME_Event
3474 TSetIconEvent( const QString& entry,
3475 const QString& icon )
3478 virtual void Execute()
3480 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3482 module->setIcon( myEntry, myIcon );
3485 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3490 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3492 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3496 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3497 \brief Set data object tooltip
3498 \param entry data object entry
3499 \param toolTip data object tooltip
3502 class TSetToolTipEvent: public SALOME_Event
3507 TSetToolTipEvent( const QString& entry,
3508 const QString& toolTip )
3510 myToolTip( toolTip ) {}
3511 virtual void Execute()
3513 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3515 module->setToolTip( myEntry, myToolTip );
3518 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3522 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3524 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3528 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3529 \brief Set reference to another data object
3530 \param entry data object entry
3531 \param refEntry referenced data object entry
3534 class TSetRefEvent: public SALOME_Event
3539 TSetRefEvent( const QString& entry,
3540 const QString& refEntry )
3542 myRefEntry( refEntry ) {}
3543 virtual void Execute()
3545 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3547 module->setReference( myEntry, myRefEntry );
3550 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3554 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3556 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3560 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3561 \brief Set data object color
3562 \param entry data object entry
3563 \param color data object color
3566 class TSetColorEvent: public SALOME_Event
3571 TSetColorEvent( const QString& entry,
3572 const QColor& color )
3575 virtual void Execute()
3577 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3579 module->setColor( myEntry, myColor );
3582 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3586 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3588 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3592 \fn QString SalomePyQt::getName( const QString& entry );
3593 \brief Get data object name
3594 \param entry data object entry
3595 \return data object name
3598 class TGetNameEvent: public SALOME_Event
3601 typedef QString TResult;
3604 TGetNameEvent( const QString& entry )
3605 : myEntry( entry ) {}
3606 virtual void Execute()
3608 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3610 myResult = module->getName( myEntry );
3613 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3617 QString SalomePyQt::getName( const QString& entry )
3619 return ProcessEvent( new TGetNameEvent( entry ) );
3623 \fn QString SalomePyQt::getToolTip( const QString& entry );
3624 \brief Get data object tooltip
3625 \param entry data object entry
3626 \return data object tooltip
3629 class TGetToolTipEvent: public SALOME_Event
3632 typedef QString TResult;
3635 TGetToolTipEvent( const QString& entry )
3636 : myEntry( entry ) {}
3637 virtual void Execute()
3639 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3641 myResult = module->getToolTip( myEntry );
3644 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3648 QString SalomePyQt::getToolTip( const QString& entry )
3650 return ProcessEvent( new TGetToolTipEvent( entry ) );
3654 \fn QString SalomePyQt::getReference( const QString& entry );
3655 \brief Get entry of the referenced object (if there's any)
3656 \param entry data object entry
3657 \return referenced data object entry
3660 class TGetRefEvent: public SALOME_Event
3663 typedef QString TResult;
3666 TGetRefEvent( const QString& entry )
3667 : myEntry( entry ) {}
3668 virtual void Execute()
3670 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3672 myResult = module->getReference( myEntry );
3675 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3679 QString SalomePyQt::getReference( const QString& entry )
3681 return ProcessEvent( new TGetRefEvent( entry ) );
3685 \fn QColor SalomePyQt::getColor( const QString& entry );
3686 \brief Get data object color
3687 \param entry data object entry
3688 \return data object color
3691 class TGetColorEvent: public SALOME_Event
3694 typedef QColor TResult;
3697 TGetColorEvent( const QString& entry )
3698 : myEntry( entry ) {}
3699 virtual void Execute()
3701 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3703 myResult = module->getColor( myEntry );
3706 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3710 QColor SalomePyQt::getColor( const QString& entry )
3712 return ProcessEvent( new TGetColorEvent( entry ) );
3716 \fn void SalomePyQt::removeChildren( const QString& entry );
3717 \brief Remove all child data objects from specified data object
3718 \param entry data object entry
3721 class TRemoveChildEvent: public SALOME_Event
3725 TRemoveChildEvent( const QString& entry )
3726 : myEntry( entry ) {}
3727 virtual void Execute()
3729 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3731 module->removeChildren( myEntry );
3734 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3738 void SalomePyQt::removeChildren( const QString& entry )
3740 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3742 void SalomePyQt::removeChild( const QString& entry )
3744 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3745 removeChildren( entry );
3749 \fn void SalomePyQt::removeObject( const QString& entry );
3750 \brief Remove object by entry
3751 \param entry data object entry
3754 class TRemoveObjectEvent: public SALOME_Event
3759 TRemoveObjectEvent( const QString& entry )
3760 : myEntry( entry ) {}
3761 virtual void Execute()
3763 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3765 module->removeObject( myEntry );
3768 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3772 void SalomePyQt::removeObject( const QString& entry )
3774 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3778 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3779 \brief Get entries of all child data objects of specified data object
3780 \param entry data object entry
3781 \param recursive \c true for recursive processing
3784 class TGetChildrenEvent: public SALOME_Event
3787 typedef QStringList TResult;
3791 TGetChildrenEvent( const QString& entry, const bool recursive )
3793 myRecursive( recursive ) {}
3794 virtual void Execute()
3796 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3798 myResult = module->getChildren( myEntry, myRecursive );
3801 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3805 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3807 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3810 #ifndef DISABLE_PLOT2DVIEWER
3811 // Next set of methods relates to the Plot2d viewer functionality
3814 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3815 \brief Display theCurve in view
3816 \param id window identifier
3817 \param theCurve curve to display
3820 class TDisplayCurve: public SALOME_Event
3824 Plot2d_Curve* myCurve;
3825 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3826 virtual void Execute() {
3827 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3829 wnd->getViewFrame()->displayCurve( myCurve );
3832 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3834 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
3838 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3839 \brief Erase theCurve in view
3840 \param id window identifier
3841 \param theCurve curve to erase
3844 class TEraseCurve: public SALOME_Event
3848 Plot2d_Curve* myCurve;
3849 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3850 virtual void Execute() {
3851 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3852 wnd->getViewFrame()->eraseCurve( myCurve );
3855 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3857 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
3861 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3862 \brief Delete theCurve from all views
3863 \param theCurve curve to delete
3866 class TDeleteCurve: public SALOME_Event
3869 Plot2d_Curve* myCurve;
3870 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3871 virtual void Execute() {
3872 LightApp_Application* app = getApplication();
3874 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3876 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3877 SUIT_ViewWindow* wnd;
3878 foreach ( wnd, wndlist ) {
3879 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3881 aP2d->getViewFrame()->eraseObject( myCurve );
3887 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3889 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3893 \brief updateCurves (repaint) curves in view window.
3895 void SalomePyQt::updateCurves( const int id )
3897 class TEvent: public SALOME_Event
3901 TEvent( const int id ) : myWndId( id ) {}
3902 virtual void Execute()
3904 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3906 wnd->getViewFrame()->DisplayAll();
3909 ProcessVoidEvent( new TEvent( id ) );
3913 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3914 \brief Get title of corresponding type
3915 \param id window identifier
3916 \param type is type of title
3917 \return title of corresponding type
3920 class TGetPlot2dTitle: public SALOME_Event
3923 typedef QString TResult;
3927 TGetPlot2dTitle(const int id, ObjectType type) :
3930 virtual void Execute() {
3931 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3933 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
3936 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
3938 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
3943 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3944 \brief Set title of corresponding type
3945 \param id window identifier
3947 \param type is type of title
3951 class TSetPlot2dTitle: public SALOME_Event
3955 Plot2d_Curve* myCurve;
3959 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
3964 virtual void Execute() {
3965 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3966 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
3969 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
3971 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
3975 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3976 \brief Get list of Plot2d view ranges
3977 \param id window identifier
3978 \return list of view ranges (XMin, XMax, YMin, YMax)
3981 class TFitRangeByCurves: public SALOME_Event
3984 typedef QList<double> TResult;
3987 TFitRangeByCurves( const int id )
3989 virtual void Execute()
3992 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3994 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3995 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3996 myResult.append( XMin );
3997 myResult.append( XMax );
3998 myResult.append( YMin );
3999 myResult.append( YMax );
4003 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
4005 return ProcessEvent( new TFitRangeByCurves( id ) );
4009 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4010 \brief Get list of current Plot2d view ranges
4011 \param id window identifier
4012 \return list of view ranges (XMin, XMax, YMin, YMax)
4015 class TFitRangeCurrent: public SALOME_Event
4018 typedef QList<double> TResult;
4021 TFitRangeCurrent( const int id )
4023 virtual void Execute()
4026 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4028 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
4029 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
4030 myResult.append( XMin );
4031 myResult.append( XMax );
4032 myResult.append( YMin );
4033 myResult.append( YMax );
4037 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
4039 return ProcessEvent( new TFitRangeCurrent( id ) );
4043 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4044 \brief Set range of Plot2d view
4045 \param id window identifier
4052 class TPlot2dFitRange: public SALOME_Event
4060 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
4066 virtual void Execute() {
4067 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
4069 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
4072 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
4074 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
4077 // End of methods related to the Plot2d viewer functionality
4078 #endif // DISABLE_PLOT2DVIEWER
4081 \brief Process Qt event loop
4083 void SalomePyQt::processEvents()
4085 QCoreApplication::processEvents();
4089 \brief Set visibility state for given object
4090 \param theEntry study ID of the object
4091 \param theState visibility state
4093 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
4095 class TEvent: public SALOME_Event
4100 TEvent( const QString& theEntry, int theState ):
4101 myEntry( theEntry ), myState( theState ) {}
4102 virtual void Execute()
4104 LightApp_Study* aStudy = getActiveStudy();
4107 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
4110 ProcessVoidEvent( new TEvent( theEntry, theState ) );
4114 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4115 \brief Get visibility state for given object
4116 \param theEntry study ID of the object
4117 \return visibility state
4120 class TGetVisibilityStateEvent: public SALOME_Event
4123 typedef int TResult;
4126 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4127 virtual void Execute()
4129 LightApp_Study* aStudy = getActiveStudy();
4131 myResult = aStudy->visibilityState( myEntry );
4134 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
4136 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4140 \brief Set position of given object in the tree
4141 \param theEntry study ID of the object
4142 \param thePos position
4144 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4146 class TEvent: public SALOME_Event
4151 TEvent( const QString& theEntry, int thePos ):
4152 myEntry( theEntry ), myPos( thePos ) {}
4153 virtual void Execute()
4155 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4157 module->setObjectPosition( myEntry, myPos );
4160 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4164 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4165 \brief Get position of given object in the tree
4166 \param theEntry study ID of the object
4170 class TGetObjectPositionEvent: public SALOME_Event
4173 typedef int TResult;
4176 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4177 virtual void Execute()
4179 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4181 myResult = module->getObjectPosition( myEntry );
4184 int SalomePyQt::getObjectPosition( const QString& theEntry )
4186 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4190 \brief Start recordind a log of Python commands from embedded console
4191 \param theFileName output lof file name
4193 void SalomePyQt::startPyLog( const QString& theFileName )
4195 class TEvent: public SALOME_Event
4199 TEvent( const QString& theFileName ):
4200 myFileName( theFileName ) {}
4201 virtual void Execute()
4203 if ( getApplication() ) {
4204 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4205 if ( pyConsole ) pyConsole->startLog( myFileName );
4209 ProcessVoidEvent( new TEvent( theFileName ) );
4213 \brief Stop recordind a log of Python commands from embedded console
4215 void SalomePyQt::stopPyLog()
4217 class TEvent: public SALOME_Event
4221 virtual void Execute()
4223 if ( getApplication() ) {
4224 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4225 if ( pyConsole ) pyConsole->stopLog();
4229 ProcessVoidEvent( new TEvent() );