1 // Copyright (C) 2007-2015 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 #include "OCCViewer_ViewWindow.h"
42 #include "OCCViewer_ViewFrame.h"
43 #include "Plot2d_ViewManager.h"
44 #include "Plot2d_ViewWindow.h"
45 #include "PVViewer_ViewManager.h"
46 #include "PVViewer_ViewModel.h"
47 #include "QtxActionMenuMgr.h"
48 #include "QtxWorkstack.h"
49 #include "QtxTreeView.h"
50 #include "SALOME_Event.h"
51 #include "STD_TabDesktop.h"
52 #include "SUIT_DataBrowser.h"
53 #include "SUIT_ResourceMgr.h"
54 #include "SUIT_Session.h"
55 #include "SUIT_Tools.h"
56 #include "PyConsole_Console.h"
59 #include <QApplication>
60 #include <QPaintEvent>
61 #include <QCoreApplication>
64 \brief Get the currently active application.
66 \return active application object or 0 if there is no any
68 static LightApp_Application* getApplication()
70 if ( SUIT_Session::session() )
71 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
76 \brief Get the currently active study.
78 \return active study or 0 if there is no study opened
80 static LightApp_Study* getActiveStudy()
82 if ( getApplication() )
83 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
88 \brief Get the currently active module.
90 This function returns correct result only if Python-based
91 module is currently active. Otherwize, 0 is returned.
93 static LightApp_Module* getActiveModule()
95 LightApp_Module* module = 0;
96 if ( LightApp_Application* anApp = getApplication() ) {
97 module = PyModuleHelper::getInitModule();
99 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
105 \brief Get the currently active Python module's helper.
107 This function returns correct result only if Python-based
108 module is currently active. Otherwize, 0 is returned.
110 static PyModuleHelper* getPythonHelper()
112 LightApp_Module* module = getActiveModule();
113 PyModuleHelper* helper = module ? qFindChild<PyModuleHelper*>( module, "python_module_helper" ) : 0;
118 \brief Get SALOME verbose level
120 \return \c true if SALOME debug output is allowed or \c false otherwise
122 static bool verbose()
124 bool isVerbose = false;
125 if ( getenv( "SALOME_VERBOSE" ) ) {
126 QString envVar = getenv( "SALOME_VERBOSE" );
128 int value = envVar.toInt( &ok );
129 isVerbose = ok && value != 0;
135 \class SALOME_Selection
136 \brief The class represents selection which can be used in Python.
140 \brief Map of created selection objects.
143 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
146 \brief Get the selection object for the specified application.
148 Finds or creates the selection object (one per study).
150 \param app application object
151 \return selection object or 0 if \a app is invalid
153 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
155 SALOME_Selection* sel = 0;
156 if ( app && SelMap.find( app ) != SelMap.end() )
159 sel = SelMap[ app ] = new SALOME_Selection( app );
165 \param p parent object
167 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
169 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
171 mySelMgr = app->selectionMgr();
172 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
173 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
180 SALOME_Selection::~SALOME_Selection()
182 LightApp_Application* app = 0;
183 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
184 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
185 if ( it.value() == this ) app = it.key();
187 if ( app ) SelMap.remove( app );
191 \brief Called when selection manager is destroyed (usually
192 when the study is closed).
194 void SALOME_Selection::onSelMgrDestroyed()
200 \brief Clear the selection.
202 void SALOME_Selection::Clear()
204 class TEvent: public SALOME_Event
206 LightApp_SelectionMgr* mySelMgr;
208 TEvent( LightApp_SelectionMgr* selMgr )
209 : mySelMgr( selMgr ) {}
210 virtual void Execute()
213 mySelMgr->clearSelected();
216 ProcessVoidEvent( new TEvent( mySelMgr ) );
220 \brief Clear the selection.
222 void SALOME_Selection::ClearIObjects()
228 Removes all selection filters.
230 void SALOME_Selection::ClearFilters()
232 class TEvent: public SALOME_Event
234 LightApp_SelectionMgr* mySelMgr;
236 TEvent( LightApp_SelectionMgr* selMgr )
237 : mySelMgr( selMgr ) {}
238 virtual void Execute()
241 mySelMgr->clearFilters();
244 ProcessVoidEvent( new TEvent( mySelMgr ) );
249 \brief The class provides utility functions which can be used in the Python
250 to operate with the SALOME GUI.
252 All the functionality of this class is implemented as static methods, so they
253 can be called with the class name prefixed or via creation of the class instance.
254 For example, next both ways of SalomePyQt class usage are legal:
256 from SalomePyQt import *
258 # using SalomePyQt class instance
259 desktop = sg.getDesktop()
260 # using SalomePyQt class directly
261 menubar = SalomePyQt.getMainMenuBar()
266 \fn QWidget* SalomePyQt::getDesktop();
267 \brief Get the active application's desktop window.
268 \return desktop window or 0 if there is no any
271 class TGetDesktopEvent: public SALOME_Event
274 typedef QWidget* TResult;
276 TGetDesktopEvent() : myResult( 0 ) {}
277 virtual void Execute()
279 if ( getApplication() )
280 myResult = (QWidget*)( getApplication()->desktop() );
283 QWidget* SalomePyQt::getDesktop()
285 return ProcessEvent( new TGetDesktopEvent() );
289 \fn QWidget* SalomePyQt::getMainFrame();
290 \brief Get current application's main frame widget [obsolete].
292 Main frame widget is an internal widget of the application
293 desktop window (workspace).
295 \return workspace widget (0 on any error)
298 class TGetMainFrameEvent: public SALOME_Event
301 typedef QWidget* TResult;
303 TGetMainFrameEvent() : myResult( 0 ) {}
304 virtual void Execute()
306 if ( getApplication() ) {
307 SUIT_Desktop* aDesktop = getApplication()->desktop();
308 myResult = (QWidget*)( aDesktop->centralWidget() );
312 QWidget* SalomePyQt::getMainFrame()
314 return ProcessEvent( new TGetMainFrameEvent() );
318 \fn QMenuBar* SalomePyQt::getMainMenuBar();
319 \brief Get current application desktop's main menu.
320 \return main menu object (0 on any error)
323 class TGetMainMenuBarEvent: public SALOME_Event
326 typedef QMenuBar* TResult;
328 TGetMainMenuBarEvent() : myResult( 0 ) {}
329 virtual void Execute()
331 if ( LightApp_Application* anApp = getApplication() ) {
332 myResult = anApp->desktop()->menuBar();
336 QMenuBar* SalomePyQt::getMainMenuBar()
338 return ProcessEvent( new TGetMainMenuBarEvent() );
342 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
343 \brief Get main menu's child popup submenu by its identifier.
345 This function is obsolete.
346 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
348 \param menu menu identifier
349 \return popup submenu object or 0 if it does not exist
353 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
354 \brief Get main menu's child popup submenu by its name.
356 The function creates menu if it does not exist.
358 \param menu menu name
359 \return popup submenu object (0 on any error)
362 class TGetPopupMenuEvent: public SALOME_Event
365 typedef QMenu* TResult;
368 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
369 virtual void Execute()
371 LightApp_Application* anApp = getApplication();
372 if ( anApp && !myMenuName.isEmpty() ) {
373 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
374 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
380 \brief Get menu item title
382 \param menuId menu identifier
383 \return menu title (localized)
385 static QString getMenuName( const QString& menuId )
387 QStringList contexts;
388 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
389 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
390 QString menuName = menuId;
391 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
392 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
396 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
401 menuName = getMenuName( "MEN_DESK_FILE" ); break;
403 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
405 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
407 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
409 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
411 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
413 menuName = getMenuName( "MEN_DESK_HELP" ); break;
415 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
417 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
419 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
423 \fn QTreeView* SalomePyQt::getObjectBrowser();
424 \brief Get object browser
425 \return object browser for the active study or 0 in case of error
428 class TGetObjectBrowserEvent: public SALOME_Event
431 typedef QTreeView* TResult;
433 TGetObjectBrowserEvent() : myResult( 0 ) {}
434 virtual void Execute()
436 LightApp_Application* anApp = getApplication();
438 myResult = anApp->objectBrowser()->treeView();
442 QTreeView* SalomePyQt::getObjectBrowser()
444 return ProcessEvent( new TGetObjectBrowserEvent() );
448 \fn int SalomePyQt::getStudyId();
449 \brief Get active study's identifier.
450 \return active study ID or 0 if there is no active study
453 class TGetStudyIdEvent: public SALOME_Event
458 TGetStudyIdEvent() : myResult( 0 ) {}
459 virtual void Execute()
461 if ( LightApp_Study* aStudy = getActiveStudy() ) {
462 myResult = aStudy->id();
466 int SalomePyQt::getStudyId()
468 return ProcessEvent( new TGetStudyIdEvent() );
472 \fn SALOME_Selection* SalomePyQt::getSelection();
473 \brief Get the selection object for the current study.
475 Creates a Selection object if it has not been created yet.
477 \return selection object (0 on error)
480 class TGetSelectionEvent: public SALOME_Event
483 typedef SALOME_Selection* TResult;
485 TGetSelectionEvent() : myResult( 0 ) {}
486 virtual void Execute()
488 myResult = SALOME_Selection::GetSelection( getApplication() );
491 SALOME_Selection* SalomePyQt::getSelection()
493 return ProcessEvent( new TGetSelectionEvent() );
497 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
498 \brief Put an information message to the current application's
501 Optional second delay parameter (\a sec) can be used to specify
502 time of the message diplaying in seconds. If this parameter is less
503 or equal to zero, the constant message will be put.
505 \param msg message text
506 \param sec message displaying time in seconds
509 class TPutInfoEvent: public SALOME_Event
514 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
515 virtual void Execute()
517 if ( LightApp_Application* anApp = getApplication() ) {
518 anApp->putInfo( myMsg, mySecs * 1000 );
522 void SalomePyQt::putInfo( const QString& msg, const int sec )
524 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
528 \fn const QString SalomePyQt::getActiveComponent();
529 \brief Get the currently active module name (for the current study).
530 \return active module name or empty string if there is no active module
533 class TGetActiveComponentEvent: public SALOME_Event
536 typedef QString TResult;
538 TGetActiveComponentEvent() {}
539 virtual void Execute()
541 if ( LightApp_Application* anApp = getApplication() ) {
542 if ( CAM_Module* mod = anApp->activeModule() ) {
543 myResult = mod->name();
548 const QString SalomePyQt::getActiveComponent()
550 return ProcessEvent( new TGetActiveComponentEvent() );
554 \fn PyObject* SalomePyQt::getActivePythonModule();
555 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
556 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
559 class TGetActivePyModuleEvent: public SALOME_Event
562 typedef PyObject* TResult;
564 TGetActivePyModuleEvent() : myResult( Py_None ) {}
565 virtual void Execute()
567 PyModuleHelper* helper = getPythonHelper();
569 myResult = (PyObject*)helper->pythonModule();
572 PyObject* SalomePyQt::getActivePythonModule()
574 return ProcessEvent( new TGetActivePyModuleEvent() );
578 \fn bool SalomePyQt::activateModule( const QString& modName );
579 \brief Activates SALOME module with the given name
580 \return True if the module has been activated and False otherwise.
583 class TActivateModuleEvent: public SALOME_Event
586 typedef bool TResult;
588 QString myModuleName;
589 TActivateModuleEvent( const QString& modName )
590 : myResult( false ), myModuleName( modName ) {}
591 virtual void Execute()
593 if ( LightApp_Application* anApp = getApplication() ) {
594 myResult = anApp->activateModule( myModuleName );
598 bool SalomePyQt::activateModule( const QString& modName )
600 return ProcessEvent( new TActivateModuleEvent( modName ) );
604 \brief Update an Object Browser of the specified (by identifier) study.
606 If \a studyId <= 0 the active study's object browser is updated.
607 The \a updateSelection parameter is obsolete and currently is not used.
608 This parameter will be removed in future, so try to avoid its usage in
611 \brief studyId study identifier
612 \brief updateSelection update selection flag (not used)
615 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
617 class TEvent: public SALOME_Event
620 bool myUpdateSelection;
622 TEvent( const int studyId, bool updateSelection )
623 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
624 virtual void Execute()
626 if ( SUIT_Session::session() ) {
627 if ( getActiveStudy() && myStudyId <= 0 )
628 myStudyId = getActiveStudy()->id();
629 if ( myStudyId > 0 ) {
630 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
631 QList<SUIT_Application*>::Iterator it;
632 for( it = apps.begin(); it != apps.end(); ++it ) {
633 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
634 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
635 anApp->updateObjectBrowser();
643 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
648 SalomePyQt::isModified()
649 \return The modification status of the data model
650 for the currently active Python module
651 \note This function is supported for "light" Python-based SALOME modules only.
654 class TIsModifiedEvent: public SALOME_Event
657 typedef bool TResult;
659 TIsModifiedEvent() : myResult( false ) {}
660 virtual void Execute()
662 LightApp_Module* module = getActiveModule();
666 SALOME_PYQT_DataModelLight* aModel =
667 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
669 myResult = aModel->isModified();
672 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
676 bool SalomePyQt::isModified()
678 return ProcessEvent(new TIsModifiedEvent());
682 SalomePyQt::setModified()
684 Sets the modification status of the data model for
685 the currently active Python module. This method should be used
686 by the Python code in order to enable/disable "Save" operation
687 depending on the module's data state.
689 \note This function is supported for "light" Python-based SALOME modules only.
691 \param New modification status of the data model
695 void SalomePyQt::setModified( bool flag )
697 class TEvent: public SALOME_Event
703 virtual void Execute()
705 LightApp_Module* module = getActiveModule();
709 SALOME_PYQT_DataModelLight* model =
710 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
712 LightApp_Application* app = module->getApp();
714 if ( model && app ) {
715 model->setModified( myFlag );
716 app->updateActions();
719 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
723 ProcessVoidEvent( new TEvent( flag ) );
727 \brief Default resource file section name.
730 static const char* DEFAULT_SECTION = "SalomePyQt";
733 \brief Add string setting to the application preferences.
735 The parameter \a autoValue is obsolete parameter and currently is not used.
736 This parameter will be removed in future, so try to avoid its usage in
739 This function is obsolete. Use one of addSetting() instead.
741 \param name setting name (it should be of kind <section:setting> where
742 \c section is resources section name and \c setting is setting name)
743 \param value new setting value
744 \param autoValue (not used)
746 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
748 class TEvent: public SALOME_Event
754 TEvent( const QString& name, const QString& value, bool autoValue )
755 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
756 virtual void Execute()
758 if ( SUIT_Session::session() ) {
759 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
760 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
761 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
762 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
763 if ( !_sec.isEmpty() && !_nam.isEmpty() )
764 resMgr->setValue( _sec, _nam, myValue );
768 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
772 \brief Add integer setting to the application preferences.
774 The parameter \a autoValue is obsolete parameter and currently is not used.
775 This parameter will be removed in future, so try to avoid its usage in
778 This function is obsolete. Use one of addSetting() instead.
780 \param name setting name (it should be of kind <section:setting> where
781 \c section is resources section name and \c setting is setting name)
782 \param value new setting value
783 \param autoValue (not used)
785 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
787 class TEvent: public SALOME_Event
793 TEvent( const QString& name, const int value, bool autoValue )
794 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
795 virtual void Execute()
797 if ( SUIT_Session::session() ) {
798 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
799 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
800 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
801 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
802 if ( !_sec.isEmpty() && !_nam.isEmpty() )
803 resMgr->setValue( _sec, _nam, myValue );
807 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
811 \brief Add double setting to the application preferences.
813 The parameter \a autoValue is obsolete parameter and currently is not used.
814 This parameter will be removed in future, so try to avoid its usage in
817 This function is obsolete. Use one of addSetting() instead.
819 \param name setting name (it should be of kind <section:setting> where
820 \c section is resources section name and \c setting is setting name)
821 \param value new setting value
822 \param autoValue (not used)
824 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
826 class TEvent: public SALOME_Event
832 TEvent( const QString& name, const double value, bool autoValue )
833 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
834 virtual void Execute()
836 if ( SUIT_Session::session() ) {
837 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
838 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
839 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
840 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
841 if ( !_sec.isEmpty() && !_nam.isEmpty() )
842 resMgr->setValue( _sec, _nam, myValue );
846 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
850 \brief Add boolean setting to the application preferences.
852 The parameter \a autoValue is obsolete parameter and currently is not used.
853 This parameter will be removed in future, so try to avoid its usage in
856 This function is obsolete. Use one of addSetting() instead.
858 \param name setting name (it should be of kind <section:setting> where
859 \c section is resources section name and \c setting is setting name)
860 \param value new setting value
861 \param autoValue (not used)
863 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
865 class TEvent: public SALOME_Event
871 TEvent( const QString& name, const bool value, bool autoValue )
872 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
873 virtual void Execute()
875 if ( SUIT_Session::session() ) {
876 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
877 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
878 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
879 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
880 if ( !_sec.isEmpty() && !_nam.isEmpty() )
881 resMgr->setValue( _sec, _nam, myValue );
885 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
889 \brief Remove setting from the application preferences.
891 This function is obsolete. Use removeSetting() instead.
893 \param name setting name (it should be of kind <section:setting> where
894 \c section is resources section name and \c setting is setting name)
896 void SalomePyQt::removeSettings( const QString& name )
898 class TEvent: public SALOME_Event
902 TEvent( const QString& name ) : myName( name ) {}
903 virtual void Execute()
905 if ( SUIT_Session::session() ) {
906 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
907 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
908 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
909 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
910 if ( !_sec.isEmpty() && !_nam.isEmpty() )
911 resMgr->remove( _sec, _nam );
915 ProcessVoidEvent( new TEvent( name ) );
919 \fn QString SalomePyQt::getSetting( const QString& name );
920 \brief Get application setting value (as string represenation).
922 This function is obsolete. Use stringSetting(), integerSetting(),
923 boolSetting(), stringSetting() or colorSetting() instead.
925 \param name setting name (it should be of kind <section:setting> where
926 \c section is resources section name and \c setting is setting name)
927 \return setting name (empty string if setting name is invalid)
930 class TGetSettingEvent: public SALOME_Event
933 typedef QString TResult;
936 TGetSettingEvent( const QString& name ) : myName( name ) {}
937 virtual void Execute()
939 if ( SUIT_Session::session() ) {
940 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
941 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
942 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
943 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
944 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
948 QString SalomePyQt::getSetting( const QString& name )
950 return ProcessEvent( new TGetSettingEvent( name ) );
954 \brief Add double setting to the application preferences.
955 \param section resources file section name
956 \param name setting name
957 \param value new setting value
959 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
961 class TEvent: public SALOME_Event
967 TEvent( const QString& section, const QString& name, double value )
968 : mySection( section ), myName( name ), myValue( value ) {}
969 virtual void Execute()
971 if ( SUIT_Session::session() ) {
972 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
973 if ( !mySection.isEmpty() && !myName.isEmpty() )
974 resMgr->setValue( mySection, myName, myValue );
978 ProcessVoidEvent( new TEvent( section, name, value ) );
982 \brief Add integer setting to the application preferences.
983 \param section resources file section name
984 \param name setting name
985 \param value new setting value
987 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
989 class TEvent: public SALOME_Event
995 TEvent( const QString& section, const QString& name, int value )
996 : mySection( section ), myName( name ), myValue( value ) {}
997 virtual void Execute()
999 if ( SUIT_Session::session() ) {
1000 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1001 if ( !mySection.isEmpty() && !myName.isEmpty() )
1002 resMgr->setValue( mySection, myName, myValue );
1006 ProcessVoidEvent( new TEvent( section, name, value ) );
1010 \brief Add boolean setting to the application preferences.
1011 \param section resources file section name
1012 \param name setting name
1013 \param value new setting value
1014 \param dumb this parameter is used in order to avoid sip compilation error
1015 because of conflicting int and bool types
1017 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1019 class TEvent: public SALOME_Event
1025 TEvent( const QString& section, const QString& name, bool value )
1026 : mySection( section ), myName( name ), myValue( value ) {}
1027 virtual void Execute()
1029 if ( SUIT_Session::session() ) {
1030 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1031 if ( !mySection.isEmpty() && !myName.isEmpty() )
1032 resMgr->setValue( mySection, myName, myValue );
1036 ProcessVoidEvent( new TEvent( section, name, value ) );
1040 \brief Add string setting to the application preferences.
1041 \param section resources file section name
1042 \param name setting name
1043 \param value new setting value
1045 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1047 class TEvent: public SALOME_Event
1053 TEvent( const QString& section, const QString& name, const QString& value )
1054 : mySection( section ), myName( name ), myValue( value ) {}
1055 virtual void Execute()
1057 if ( SUIT_Session::session() ) {
1058 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1059 if ( !mySection.isEmpty() && !myName.isEmpty() )
1060 resMgr->setValue( mySection, myName, myValue );
1064 ProcessVoidEvent( new TEvent( section, name, value ) );
1068 \brief Add color setting to the application preferences.
1069 \param section resources file section name
1070 \param name setting name
1071 \param value new setting value
1073 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1075 class TEvent: public SALOME_Event
1081 TEvent( const QString& section, const QString& name, const QColor& value )
1082 : mySection( section ), myName( name ), myValue( value ) {}
1083 virtual void Execute()
1085 if ( SUIT_Session::session() ) {
1086 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1087 if ( !mySection.isEmpty() && !myName.isEmpty() )
1088 resMgr->setValue( mySection, myName, myValue );
1092 ProcessVoidEvent( new TEvent( section, name, value ) );
1096 \fn int SalomePyQt::integerSetting( const QString& section,
1097 const QString& name,
1099 \brief Get integer setting from the application preferences.
1100 \param section resources file section name
1101 \param name setting name
1102 \param def default value which is returned if the setting is not found
1103 \return setting value
1106 class TGetIntSettingEvent: public SALOME_Event
1109 typedef int TResult;
1114 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1115 : mySection( section ), myName( name ), myDefault( def ) {}
1116 virtual void Execute()
1118 if ( SUIT_Session::session() ) {
1119 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1120 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1124 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1126 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1130 \fn double SalomePyQt::doubleSetting( const QString& section,
1131 const QString& name,
1133 \brief Get double setting from the application preferences.
1134 \param section resources file section name
1135 \param name setting name
1136 \param def default value which is returned if the setting is not found
1137 \return setting value
1140 class TGetDblSettingEvent: public SALOME_Event
1143 typedef double TResult;
1148 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1149 : mySection( section ), myName( name ), myDefault( def ) {}
1150 virtual void Execute()
1152 if ( SUIT_Session::session() ) {
1153 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1154 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1158 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1160 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1164 \fn bool SalomePyQt::boolSetting( const QString& section,
1165 const QString& name,
1167 \brief Get boolean setting from the application preferences.
1168 \param section resources file section name
1169 \param name setting name
1170 \param def default value which is returned if the setting is not found
1171 \return setting value
1174 class TGetBoolSettingEvent: public SALOME_Event
1177 typedef bool TResult;
1182 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1183 : mySection( section ), myName( name ), myDefault( def ) {}
1184 virtual void Execute()
1186 if ( SUIT_Session::session() ) {
1187 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1188 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1192 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1194 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1198 \fn QString SalomePyQt::stringSetting( const QString& section,
1199 const QString& name,
1200 const QString& def );
1201 \brief Get string setting from the application preferences.
1202 \param section resources file section name
1203 \param name setting name
1204 \param def default value which is returned if the setting is not found
1205 \return setting value
1208 class TGetStrSettingEvent: public SALOME_Event
1211 typedef QString TResult;
1216 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1217 : mySection( section ), myName( name ), myDefault( def ) {}
1218 virtual void Execute()
1220 if ( SUIT_Session::session() ) {
1221 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1222 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1226 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1228 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1232 \fn QColor SalomePyQt::colorSetting( const QString& section,
1233 const QString& name,
1235 \brief Get color setting from the application preferences.
1236 \param section resources file section name
1237 \param name setting name
1238 \param def default value which is returned if the setting is not found
1239 \return setting value
1242 class TGetColorSettingEvent: public SALOME_Event
1245 typedef QColor TResult;
1250 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1251 : mySection( section ), myName( name ), myDefault( def ) {}
1252 virtual void Execute()
1254 if ( SUIT_Session::session() ) {
1255 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1256 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1260 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1262 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1266 \brief Remove setting from the application preferences.
1267 \param section resources file section name
1268 \param name setting name
1270 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1272 class TEvent: public SALOME_Event
1277 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1278 virtual void Execute()
1280 if ( SUIT_Session::session() ) {
1281 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1282 if ( !mySection.isEmpty() && !myName.isEmpty() )
1283 resMgr->remove( mySection, myName );
1287 ProcessVoidEvent( new TEvent( section, name ) );
1291 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1292 \brief Check setting existence in the application preferences.
1293 \param section resources file section name
1294 \param name setting name
1295 \return \c true if setting exists
1298 class THasColorSettingEvent: public SALOME_Event
1301 typedef bool TResult;
1305 THasColorSettingEvent( const QString& section, const QString& name )
1306 : mySection( section ), myName( name ) {}
1307 virtual void Execute()
1309 if ( SUIT_Session::session() ) {
1310 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1311 myResult = resMgr->hasValue( mySection, myName );
1315 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1317 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1321 \fn QString SalomePyQt::getFileName( QWidget* parent,
1322 const QString& initial,
1323 const QStringList& filters,
1324 const QString& caption,
1326 \brief Show 'Open/Save file' dialog box for file selection
1327 and return a user's choice (selected file name).
1328 \param parent parent widget
1329 \param initial initial directory the dialog box to be opened in
1330 \param filters list of files filters (wildcards)
1331 \param caption dialog box title
1332 \param open if \c true, "Open File" dialog box is shown;
1333 otherwise "Save File" dialog box is shown
1334 \return selected file name (null string if user cancels operation)
1337 class TGetFileNameEvent: public SALOME_Event
1340 typedef QString TResult;
1344 QStringList myFilters;
1347 TGetFileNameEvent( QWidget* parent,
1348 const QString& initial,
1349 const QStringList& filters,
1350 const QString& caption,
1352 : myParent ( parent ),
1353 myInitial( initial ),
1354 myFilters( filters ),
1355 myCaption( caption ),
1357 virtual void Execute()
1359 if ( LightApp_Application* anApp = getApplication() ) {
1360 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1361 myCaption, myParent );
1365 QString SalomePyQt::getFileName( QWidget* parent,
1366 const QString& initial,
1367 const QStringList& filters,
1368 const QString& caption,
1371 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1375 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1376 const QString& initial,
1377 const QStringList& filters,
1378 const QString& caption );
1379 \brief Show 'Open files' dialog box for multiple files selection
1380 and return a user's choice (selected file names list).
1381 \param parent parent widget
1382 \param initial initial directory the dialog box to be opened in
1383 \param filters list of files filters (wildcards)
1384 \param caption dialog box title
1385 \return selected file names list (empty list if user cancels operation)
1388 class TGetOpenFileNamesEvent: public SALOME_Event
1391 typedef QStringList TResult;
1395 QStringList myFilters;
1397 TGetOpenFileNamesEvent( QWidget* parent,
1398 const QString& initial,
1399 const QStringList& filters,
1400 const QString& caption )
1401 : myParent ( parent ),
1402 myInitial( initial ),
1403 myFilters( filters ),
1404 myCaption( caption ) {}
1405 virtual void Execute()
1407 if ( LightApp_Application* anApp = getApplication() ) {
1408 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1412 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1413 const QString& initial,
1414 const QStringList& filters,
1415 const QString& caption )
1417 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1421 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1422 const QString& initial,
1423 const QString& caption );
1424 \brief Show 'Get Directory' dialog box for the directory selection
1425 and return a user's choice (selected directory name).
1426 \param parent parent widget
1427 \param initial initial directory the dialog box to be opened in
1428 \param caption dialog box title
1429 \return selected directory name (null string if user cancels operation)
1432 class TGetExistingDirectoryEvent: public SALOME_Event
1435 typedef QString TResult;
1440 TGetExistingDirectoryEvent( QWidget* parent,
1441 const QString& initial,
1442 const QString& caption )
1443 : myParent ( parent ),
1444 myInitial( initial ),
1445 myCaption( caption ) {}
1446 virtual void Execute()
1448 if ( LightApp_Application* anApp = getApplication() ) {
1449 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1453 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1454 const QString& initial,
1455 const QString& caption )
1457 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1461 \fn QString SalomePyQt::loadIcon( const QString& filename );
1462 \brief Load an icon from the module resources by the specified file name.
1463 \param fileName icon file name
1467 static QIcon loadIconInternal( const QString& module, const QString& fileName )
1471 LightApp_Application* app = getApplication();
1473 if ( app && !fileName.isEmpty() ) {
1474 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
1475 QApplication::translate( module.toLatin1().data(),
1476 fileName.toLatin1().data() ) );
1477 if ( !pixmap.isNull() )
1478 icon = QIcon( pixmap );
1483 class TLoadIconEvent: public SALOME_Event
1486 typedef QIcon TResult;
1490 TLoadIconEvent( const QString& module, const QString& filename )
1491 : myModule( module ),
1492 myFileName ( filename ) {}
1493 virtual void Execute()
1495 myResult = loadIconInternal( myModule, myFileName );
1498 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1500 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1504 \brief Open external browser to display context help information.
1507 Current implementation does nothing.
1509 \param source documentation (HTML) file name
1510 \param context context (for example, HTML ancor name)
1512 void SalomePyQt::helpContext( const QString& source, const QString& context )
1514 class TEvent: public SALOME_Event
1519 TEvent( const QString& source, const QString& context )
1520 : mySource( source ), myContext( context ) {}
1521 virtual void Execute()
1523 if ( LightApp_Application* anApp = getApplication() ) {
1524 anApp->onHelpContextModule( "", mySource, myContext );
1528 ProcessVoidEvent( new TEvent( source, context ) );
1532 \fn int SalomePyQt::defaultMenuGroup();
1533 \brief Get detault menu group identifier which can be used when
1534 creating menus (insert custom menu commands).
1535 \return default menu group ID
1538 class TDefMenuGroupEvent: public SALOME_Event
1541 typedef int TResult;
1543 TDefMenuGroupEvent() : myResult( -1 ) {}
1544 virtual void Execute()
1546 myResult = PyModuleHelper::defaultMenuGroup();
1549 int SalomePyQt::defaultMenuGroup()
1551 return ProcessEvent( new TDefMenuGroupEvent() );
1557 CrTool( const QString& tBar, const QString& nBar )
1558 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1559 CrTool( const int id, const int tBar, const int idx )
1560 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1561 CrTool( const int id, const QString& tBar, const int idx )
1562 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1563 CrTool( QAction* action, const int tbId, const int id, const int idx )
1564 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1565 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1566 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1568 int execute( LightApp_Module* module ) const
1573 return module->createTool( myTbTitle, myTbName );
1575 return module->createTool( myId, myTbId, myIndex );
1577 return module->createTool( myId, myTbTitle, myIndex );
1579 return module->createTool( myAction, myTbId, myId, myIndex );
1581 return module->createTool( myAction, myTbTitle, myId, myIndex );
1596 class TCreateToolEvent: public SALOME_Event
1599 typedef int TResult;
1601 const CrTool& myCrTool;
1602 TCreateToolEvent( const CrTool& crTool )
1603 : myResult( -1 ), myCrTool( crTool ) {}
1604 virtual void Execute()
1606 LightApp_Module* module = getActiveModule();
1608 myResult = myCrTool.execute( module );
1613 \brief Create toolbar with specified name.
1614 \param tBar toolbar title (language-dependent)
1615 \param nBar toolbar name (language-independent) [optional]
1616 \return toolbar ID or -1 if toolbar creation is failed
1618 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1620 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1624 \brief Insert action with specified \a id to the toolbar.
1626 \param tBar toolbar ID
1627 \param idx required index in the toolbar
1628 \return action ID or -1 if action could not be added
1630 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1632 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1636 \brief Insert action with specified \a id to the toolbar.
1638 \param tBar toolbar name
1639 \param idx required index in the toolbar
1640 \return action ID or -1 if action could not be added
1642 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1644 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1648 \brief Insert action to the toolbar.
1650 \param tBar toolbar ID
1651 \param id required action ID
1652 \param idx required index in the toolbar
1653 \return action ID or -1 if action could not be added
1655 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1657 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1661 \brief Insert action to the toolbar.
1663 \param tBar toolbar name
1664 \param id required action ID
1665 \param idx required index in the toolbar
1666 \return action ID or -1 if action could not be added
1668 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1670 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1676 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1677 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1678 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1679 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1680 CrMenu( const int id, const int menu, const int group, const int idx )
1681 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1682 CrMenu( const int id, const QString& menu, const int group, const int idx )
1683 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1684 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1685 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1686 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1687 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1689 int execute( LightApp_Module* module ) const
1694 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1696 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1698 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1700 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1702 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1704 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1713 QString mySubMenuName;
1720 class TCreateMenuEvent: public SALOME_Event
1723 typedef int TResult;
1725 const CrMenu& myCrMenu;
1726 TCreateMenuEvent( const CrMenu& crMenu )
1727 : myResult( -1 ), myCrMenu( crMenu ) {}
1728 virtual void Execute()
1730 LightApp_Module* module = getActiveModule();
1732 myResult = myCrMenu.execute( module );
1737 \brief Create main menu.
1738 \param subMenu menu name
1739 \param menu parent menu ID
1740 \param id required menu ID
1741 \param group menu group ID
1742 \param idx required index in the menu
1743 \return menu ID or -1 if menu could not be added
1745 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1747 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1751 \brief Create main menu.
1752 \param subMenu menu name
1753 \param menu parent menu name (list of menu names separated by "|")
1754 \param id required menu ID
1755 \param group menu group ID
1756 \param idx required index in the menu
1757 \return menu ID or -1 if menu could not be added
1759 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1761 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1765 \brief Insert action to the main menu.
1767 \param menu parent menu ID
1768 \param group menu group ID
1769 \param idx required index in the menu
1770 \return action ID or -1 if action could not be added
1772 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1774 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1778 \brief Insert action to the main menu.
1780 \param menu parent menu name (list of menu names separated by "|")
1781 \param group menu group ID
1782 \param idx required index in the menu
1783 \return action ID or -1 if action could not be added
1785 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1787 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1791 \brief Insert action to the main menu.
1793 \param menu parent menu ID
1794 \param group menu group ID
1795 \param idx required index in the menu
1796 \return action ID or -1 if action could not be added
1798 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1800 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1804 \brief Insert action to the main menu.
1806 \param menu parent menu name (list of menu names separated by "|")
1807 \param group menu group ID
1808 \param idx required index in the menu
1809 \return action ID or -1 if action could not be added
1811 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1813 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1817 \fn QAction* SalomePyQt::createSeparator();
1818 \brief Create separator action which can be used in the menu or toolbar.
1819 \return new separator action
1822 class TCreateSepEvent: public SALOME_Event
1825 typedef QAction* TResult;
1829 virtual void Execute()
1831 LightApp_Module* module = getActiveModule();
1833 myResult = (QAction*)module->separator();
1836 QAction* SalomePyQt::createSeparator()
1838 return ProcessEvent( new TCreateSepEvent() );
1842 \fn QAction* SalomePyQt::createAction( const int id,
1843 const QString& menuText,
1844 const QString& tipText,
1845 const QString& statusText,
1846 const QString& icon,
1848 const bool toggle );
1849 \brief Create an action which can be then used in the menu or toolbar.
1850 \param id the unique id action to be registered to
1851 \param menuText action text which should appear in menu
1852 \param tipText text which should appear in the tooltip
1853 \param statusText text which should appear in the status bar when action is activated
1854 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1855 \param key the key accelrator for the action
1856 \param toggle if \c true the action is checkable
1859 class TCreateActionEvent: public SALOME_Event
1862 typedef QAction* TResult;
1867 QString myStatusText;
1871 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1872 const QString& statusText, const QString& icon, const int key, const bool toggle )
1873 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1874 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1875 virtual void Execute()
1877 LightApp_Module* module = getActiveModule();
1879 QIcon icon = loadIconInternal( module->name(), myIcon );
1880 myResult = (QAction*)module->action( myId );
1882 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1883 myResult->setToolTip( myTipText );
1884 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1885 myResult->setText( myMenuText );
1886 if ( myResult->icon().isNull() && !icon.isNull() )
1887 myResult->setIcon( icon );
1888 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1889 myResult->setStatusTip( myStatusText );
1890 if ( myResult->shortcut().isEmpty() && myKey )
1891 myResult->setShortcut( myKey );
1892 if ( myResult->isCheckable() != myToggle )
1893 myResult->setCheckable( myToggle );
1896 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1898 // for Python module, automatically connect action to callback slot
1899 PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1900 if ( helper ) helper->connectAction( myResult );
1904 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1905 const QString& tipText, const QString& statusText,
1906 const QString& icon, const int key, const bool toggle )
1908 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1912 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1913 \brief Create an action group which can be then used in the menu or toolbar
1914 \param id : the unique id action group to be registered to
1915 \param exclusive : if \c true the action group does exclusive toggling
1918 struct TCreateActionGroupEvent: public SALOME_Event
1920 typedef QtxActionGroup* TResult;
1924 TCreateActionGroupEvent( const int id, const bool exclusive )
1925 : myId( id ), myExclusive( exclusive ) {}
1926 virtual void Execute()
1928 LightApp_Module* module = getActiveModule();
1930 myResult = module->createActionGroup( myId, myExclusive );
1933 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1935 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1939 \fn QAction* SalomePyQt::action( const int id );
1940 \brief Get action by specified identifier.
1941 \return action or 0 if action is not registered
1944 class TActionEvent: public SALOME_Event
1947 typedef QAction* TResult;
1950 TActionEvent( const int id )
1951 : myResult( 0 ), myId( id ) {}
1952 virtual void Execute()
1954 LightApp_Module* module = getActiveModule();
1956 myResult = (QAction*)module->action( myId );
1959 QAction* SalomePyQt::action( const int id )
1961 return ProcessEvent( new TActionEvent( id ) );
1965 \fn int SalomePyQt::actionId( const QAction* a );
1966 \brief Get an action identifier.
1967 \return action ID or -1 if action is not registered
1970 class TActionIdEvent: public SALOME_Event
1973 typedef int TResult;
1975 const QAction* myAction;
1976 TActionIdEvent( const QAction* action )
1977 : myResult( -1 ), myAction( action ) {}
1978 virtual void Execute()
1980 LightApp_Module* module = getActiveModule();
1982 myResult = module->actionId( myAction );
1985 int SalomePyQt::actionId( const QAction* a )
1987 return ProcessEvent( new TActionIdEvent( a ) );
1991 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1992 \brief Add global (not module-related) preferences group.
1993 \param label global preferences group name
1994 \return preferences group identifier
1997 class TAddGlobalPrefEvent: public SALOME_Event
2000 typedef int TResult;
2003 TAddGlobalPrefEvent( const QString& label )
2004 : myResult( -1 ), myLabel( label ) {}
2005 virtual void Execute()
2007 LightApp_Module* module = getActiveModule();
2009 LightApp_Preferences* pref = module->getApp()->preferences();
2011 myResult = pref->addPreference( myLabel, -1 );
2015 int SalomePyQt::addGlobalPreference( const QString& label )
2017 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2021 \fn int SalomePyQt::addPreference( const QString& label );
2022 \brief Add module-related preferences group.
2023 \param label preferences group name
2024 \return preferences group identifier
2027 class TAddPrefEvent: public SALOME_Event
2030 typedef int TResult;
2033 TAddPrefEvent( const QString& label )
2034 : myResult( -1 ), myLabel( label ) {}
2035 virtual void Execute()
2037 LightApp_Module* module = getActiveModule();
2039 LightApp_Preferences* pref = module->getApp()->preferences();
2041 int cId = pref->addPreference( module->moduleName(), -1 );
2043 myResult = pref->addPreference( myLabel, cId );
2048 int SalomePyQt::addPreference( const QString& label )
2050 return ProcessEvent( new TAddPrefEvent( label ) );
2054 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2055 const QString& section, const QString& param );
2056 \brief Add module-related preferences.
2057 \param label preferences group name
2058 \param pId parent preferences group id
2059 \param type preferences type
2060 \param section resources file section name
2061 \param param resources file setting name
2062 \return preferences identifier
2065 class TAddPrefParamEvent: public SALOME_Event
2068 typedef int TResult;
2075 TAddPrefParamEvent( const QString& label,
2076 const int pId, const int type,
2077 const QString& section,
2078 const QString& param )
2080 myLabel( label ), myPId( pId ), myType( type ),
2081 mySection( section ), myParam ( param ) {}
2082 virtual void Execute()
2084 LightApp_Module* module = getActiveModule();
2086 LightApp_Preferences* pref = module->getApp()->preferences();
2088 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2092 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2093 const QString& section, const QString& param )
2095 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2099 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2100 \brief Get the preferences property.
2101 \param id preferences identifier
2102 \param prop preferences property name
2103 \return preferences property value or null QVariant if property is not set
2106 class TPrefPropEvent: public SALOME_Event
2109 typedef QVariant TResult;
2113 TPrefPropEvent( const int id, const QString& prop )
2114 : myId( id ), myProp( prop ) {}
2115 virtual void Execute()
2117 LightApp_Module* module = getActiveModule();
2119 LightApp_Preferences* pref = module->getApp()->preferences();
2121 myResult = pref->itemProperty( myProp, myId );
2125 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2127 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2131 \brief Set the preferences property.
2132 \param id preferences identifier
2133 \param prop preferences property name
2134 \param var preferences property value
2136 void SalomePyQt::setPreferenceProperty( const int id,
2137 const QString& prop,
2138 const QVariant& var )
2140 class TEvent: public SALOME_Event
2146 TEvent( const int id, const QString& prop, const QVariant& var )
2147 : myId( id ), myProp( prop ), myVar( var ) {}
2148 virtual void Execute()
2150 LightApp_Module* module = getActiveModule();
2152 LightApp_Preferences* pref = module->getApp()->preferences();
2154 pref->setItemProperty( myProp, myVar, myId );
2158 ProcessVoidEvent( new TEvent( id, prop, var) );
2162 \brief Add the property value to the list of values.
2164 This method allows creating properties which are QList<QVariant>
2165 - there is no way to pass such values directly to QVariant parameter with PyQt.
2167 \param id preferences identifier
2168 \param prop preferences property name
2169 \param idx preferences property index
2170 \param var preferences property value for the index \a idx
2172 void SalomePyQt::addPreferenceProperty( const int id,
2173 const QString& prop,
2175 const QVariant& var )
2177 class TEvent: public SALOME_Event
2184 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2185 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2186 virtual void Execute()
2188 LightApp_Module* module = getActiveModule();
2190 LightApp_Preferences* pref = module->getApp()->preferences();
2192 QVariant var = pref->itemProperty( myProp, myId );
2193 if ( var.isValid() ) {
2194 if ( var.type() == QVariant::StringList ) {
2195 QStringList sl = var.toStringList();
2196 if ( myIdx >= 0 && myIdx < sl.count() )
2197 sl[myIdx] = myVar.toString();
2199 sl.append( myVar.toString() );
2200 pref->setItemProperty( myProp, sl, myId );
2202 else if ( var.type() == QVariant::List ) {
2203 QList<QVariant> vl = var.toList();
2204 if ( myIdx >= 0 && myIdx < vl.count() )
2208 pref->setItemProperty( myProp, vl, myId );
2214 pref->setItemProperty( myProp, vl, myId );
2220 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2224 \brief Put the message to the Log messages output window
2225 \param msg message text (it can be of simple rich text format)
2226 \param addSeparator boolean flag which specifies if it is necessary
2227 to separate the message with predefined separator
2229 void SalomePyQt::message( const QString& msg, bool addSeparator )
2231 class TEvent: public SALOME_Event
2236 TEvent( const QString& msg, bool addSeparator )
2237 : myMsg( msg ), myAddSep( addSeparator ) {}
2238 virtual void Execute()
2240 if ( LightApp_Application* anApp = getApplication() ) {
2241 LogWindow* lw = anApp->logWindow();
2243 lw->putMessage( myMsg, myAddSep );
2247 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2251 \brief Remove all the messages from the Log messages output window.
2253 void SalomePyQt::clearMessages()
2255 class TEvent: public SALOME_Event
2259 virtual void Execute()
2261 if ( LightApp_Application* anApp = getApplication() ) {
2262 LogWindow* lw = anApp->logWindow();
2268 ProcessVoidEvent( new TEvent() );
2272 \brief Gets window with specified identifier
2274 \param id window identifier
2275 \return pointer on the window
2277 static SUIT_ViewWindow* getWnd( const int id )
2279 SUIT_ViewWindow* resWnd = 0;
2281 LightApp_Application* app = getApplication();
2284 ViewManagerList vmlist = app->viewManagers();
2285 foreach( SUIT_ViewManager* vm, vmlist )
2287 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2288 foreach ( SUIT_ViewWindow* vw, vwlist )
2290 if ( id == vw->getId() )
2303 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2304 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2305 to the image file in the specified format.
2307 For the current moment JPEG, PNG and BMP images formats are supported.
2308 The image format is defined automatically by the file name extension.
2309 By default, BMP format is used.
2311 \param filename image file name
2312 \return operation status (\c true on success)
2315 class TDumpViewEvent: public SALOME_Event
2318 typedef bool TResult;
2322 TDumpViewEvent( const QString& filename, const int id )
2323 : myResult ( false ), myFileName( filename ), myWndId(id) {}
2324 virtual void Execute()
2326 SUIT_ViewWindow* wnd = NULL;
2329 if ( LightApp_Application* anApp = getApplication() ) {
2330 SUIT_ViewManager* vm = anApp->activeViewManager();
2332 wnd = vm->getActiveView();
2334 myWndId = wnd->getId();
2338 wnd = dynamic_cast<SUIT_ViewWindow*>(getWnd( myWndId ));
2341 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2342 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2343 if(fmt == "PS" || fmt == "EPS" || fmt == "PDF") {
2345 myResult = wnd2D->getViewFrame()->print(myFileName, fmt);
2351 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2352 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2353 qApp->processEvents();
2355 QImage im = wnd->dumpView();
2356 if ( !im.isNull() && !myFileName.isEmpty() ) {
2357 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2358 if ( fmt == "JPG" ) fmt = "JPEG";
2359 myResult = im.save( myFileName, fmt.toLatin1() );
2365 bool SalomePyQt::dumpView( const QString& filename, const int id )
2367 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2372 \fn QList<int> SalomePyQt::getViews();
2373 \brief Get list of integer identifiers of all the currently opened views
2374 \return list of integer identifiers of all the currently opened views
2377 class TGetViews: public SALOME_Event
2380 typedef QList<int> TResult;
2383 virtual void Execute()
2386 LightApp_Application* app = getApplication();
2389 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2392 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2393 SUIT_ViewWindow* wnd;
2394 foreach ( wnd, wndlist )
2395 myResult.append( wnd->getId() );
2400 QList<int> SalomePyQt::getViews()
2402 return ProcessEvent( new TGetViews() );
2406 \fn int SalomePyQt::getActiveView();
2407 \brief Get integer identifier of the currently active view
2408 \return integer identifier of the currently active view
2411 class TGetActiveView: public SALOME_Event
2414 typedef int TResult;
2418 virtual void Execute()
2420 LightApp_Application* app = getApplication();
2423 SUIT_ViewManager* viewMgr = app->activeViewManager();
2426 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2428 myResult = wnd->getId();
2433 int SalomePyQt::getActiveView()
2435 return ProcessEvent( new TGetActiveView() );
2439 \fn QString SalomePyQt::getViewType( const int id );
2440 \brief Get type of the specified view, e.g. "OCCViewer"
2441 \param id window identifier
2445 class TGetViewType: public SALOME_Event
2448 typedef QString TResult;
2451 TGetViewType( const int id )
2453 virtual void Execute()
2455 SUIT_ViewWindow* wnd = getWnd( myWndId );
2458 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2460 myResult = viewMgr->getType();
2464 QString SalomePyQt::getViewType( const int id )
2466 return ProcessEvent( new TGetViewType( id ) );
2470 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2471 \brief Change view caption
2472 \param id window identifier
2473 \param title new window title
2474 \return \c true if operation is completed successfully and \c false otherwise
2477 class TSetViewTitle: public SALOME_Event
2480 typedef bool TResult;
2484 TSetViewTitle( const int id, const QString& title )
2485 : myResult( false ),
2488 virtual void Execute()
2490 SUIT_ViewWindow* wnd = getWnd( myWndId );
2493 wnd->setWindowTitle( myTitle );
2498 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2500 return ProcessEvent( new TSetViewTitle( id, title ) );
2504 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2505 \brief Set view size
2506 \param w window width
2507 \param h window height
2508 \param id window identifier
2509 \return \c true if operation is completed successfully and \c false otherwise
2512 class TSetViewSize: public SALOME_Event
2515 typedef bool TResult;
2520 TSetViewSize( const int w, const int h, const int id )
2521 : myResult( false ),
2525 virtual void Execute()
2527 SUIT_ViewWindow* wnd = 0;
2529 if ( LightApp_Application* anApp = getApplication() ) {
2530 SUIT_ViewManager* vm = anApp->activeViewManager();
2532 wnd = vm->getActiveView();
2536 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2539 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2541 QString type = viewMgr->getType();
2542 if ( type == "OCCViewer") {
2543 // specific processing for OCC viewer:
2544 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2545 // - if there is only one sub-view active; it will be resized;
2546 // - if there are several sub-views, each of them will be resized.
2547 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2548 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2549 if ( occView && occView->getView( i ) ) {
2550 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2555 else if ( type == "ParaView") {
2556 // specific processing for ParaView viewer:
2557 // hierarchy of ParaView viewer is much complex than for usual view;
2558 // we look for sub-widget named "Viewport"
2559 QList<QWidget*> lst = qFindChildren<QWidget*>( wnd, "Viewport" );
2560 if ( !lst.isEmpty() ) {
2561 lst[0]->resize( myWndWidth, myWndHeight );
2566 if ( wnd->centralWidget() ) {
2567 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2575 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2577 return ProcessEvent( new TSetViewSize( w, h, id ) );
2581 \fn QString SalomePyQt::getViewTitle( const int id );
2582 \brief Get view caption
2583 \param id window identifier
2584 \return view caption
2587 class TGetViewTitle: public SALOME_Event
2590 typedef QString TResult;
2593 TGetViewTitle( const int id )
2595 virtual void Execute()
2597 SUIT_ViewWindow* wnd = getWnd( myWndId );
2599 myResult = wnd->windowTitle();
2602 QString SalomePyQt::getViewTitle( const int id )
2604 return ProcessEvent( new TGetViewTitle( id ) );
2608 \fn QList<int> SalomePyQt::findViews( const QString& type );
2609 \brief Get list of integer identifiers of all the
2610 currently opened views of the specified type
2611 \param type viewer type
2612 \return list of integer identifiers
2615 class TFindViews: public SALOME_Event
2618 typedef QList<int> TResult;
2621 TFindViews( const QString& type )
2623 virtual void Execute()
2626 LightApp_Application* app = getApplication();
2629 ViewManagerList vmList;
2630 app->viewManagers( myType, vmList );
2631 SUIT_ViewManager* viewMgr;
2632 foreach ( viewMgr, vmList )
2634 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2635 for ( int i = 0, n = vec.size(); i < n; i++ )
2637 SUIT_ViewWindow* wnd = vec[ i ];
2639 myResult.append( wnd->getId() );
2645 QList<int> SalomePyQt::findViews( const QString& type )
2647 return ProcessEvent( new TFindViews( type ) );
2651 \fn bool SalomePyQt::activateView( const int id );
2652 \brief Activate view
2653 \param id window identifier
2654 \return \c true if operation is completed successfully and \c false otherwise
2657 class TActivateView: public SALOME_Event
2660 typedef bool TResult;
2663 TActivateView( const int id )
2664 : myResult( false ),
2666 virtual void Execute()
2668 SUIT_ViewWindow* wnd = getWnd( myWndId );
2676 bool SalomePyQt::activateView( const int id )
2678 return ProcessEvent( new TActivateView( id ) );
2682 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2683 \brief Create new view and activate it
2684 \param type viewer type
2688 \return integer identifier of created view (or -1 if view could not be created)
2691 class TCreateView: public SALOME_Event
2694 typedef int TResult;
2700 TCreateView( const QString& theType, bool visible, const int width, const int height )
2706 virtual void Execute()
2708 LightApp_Application* app = getApplication();
2711 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2714 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2716 wnd->setShown(myVisible);
2717 if(!myVisible && myWidth == 0 && myHeight == 0) {
2721 if(myWidth > 0 && myHeight > 0) {
2722 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2724 wnd2D->getViewFrame()->setGeometry(0,0,myWidth,myHeight);
2726 wnd->setGeometry(0,0,myWidth,myHeight);
2729 myResult = wnd->getId();
2735 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2737 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2738 QCoreApplication::processEvents();
2743 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2744 \brief Create new view with custom widget embedded and activate it
2745 \param type viewer type
2746 \param w custom widget
2747 \return integer identifier of created view (or -1 if view could not be created)
2750 class TCreateViewWg: public SALOME_Event
2753 typedef int TResult;
2757 TCreateViewWg( const QString& theType, QWidget* w )
2761 virtual void Execute()
2763 LightApp_Application* app = getApplication();
2766 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2769 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2771 myResult = wnd->getId();
2776 int SalomePyQt::createView( const QString& type, QWidget* w )
2778 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2779 QCoreApplication::processEvents();
2784 \fn bool SalomePyQt::closeView( const int id );
2786 \param id window identifier
2787 \return \c true if operation is completed successfully and \c false otherwise
2790 class TCloseView: public SALOME_Event
2793 typedef bool TResult;
2796 TCloseView( const int id )
2797 : myResult( false ),
2799 virtual void Execute()
2801 SUIT_ViewWindow* wnd = getWnd( myWndId );
2804 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2813 bool SalomePyQt::closeView( const int id )
2815 return ProcessEvent( new TCloseView( id ) );
2819 \fn int SalomePyQt::cloneView( const int id );
2820 \brief Clone view (if this operation is supported for specified view type)
2821 \param id window identifier
2822 \return integer identifier of the cloned view or -1 or operation could not be performed
2825 class TCloneView: public SALOME_Event
2828 typedef int TResult;
2831 TCloneView( const int id )
2834 virtual void Execute()
2836 SUIT_ViewWindow* wnd = getWnd( myWndId );
2839 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2842 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2844 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2845 occView->onCloneView();
2847 wnd = viewMgr->getActiveView();
2849 myResult = wnd->getId();
2851 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2853 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2854 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2855 if ( viewMgr2d && srcWnd2d )
2857 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2858 myResult = resWnd->getId();
2865 int SalomePyQt::cloneView( const int id )
2867 return ProcessEvent( new TCloneView( id ) );
2871 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2872 \brief Set view visibility.
2873 \param id window identifier
2874 \param visible new visiblity
2877 void SalomePyQt::setViewVisible( const int id, const bool visible )
2879 class TEvent: public SALOME_Event
2884 TEvent( const int id, const bool visible )
2885 : myWndId( id ), myVisible( visible ) {}
2886 virtual void Execute()
2888 SUIT_ViewWindow* wnd = getWnd( myWndId );
2889 if ( wnd ) wnd->setVisible( myVisible );
2892 ProcessVoidEvent( new TEvent( id, visible ) );
2896 \fn bool SalomePyQt::isViewVisible( const int id );
2897 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2898 \param id window identifier
2899 \return \c true if view is visible and \c false otherwise
2902 class TIsViewVisible: public SALOME_Event
2905 typedef bool TResult;
2908 TIsViewVisible( const int id )
2909 : myResult( false ),
2911 virtual void Execute()
2913 SUIT_ViewWindow* wnd = getWnd( myWndId );
2916 QWidget* p = wnd->parentWidget();
2917 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2921 bool SalomePyQt::isViewVisible( const int id )
2923 return ProcessEvent( new TIsViewVisible( id ) );
2927 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2928 \brief Set / clear view's "closable" option. By default any view is closable
2929 (i.e. can be closed by the user).
2930 \param id window identifier
2931 \param on new "closable" option's value
2934 void SalomePyQt::setViewClosable( const int id, const bool on )
2936 class TEvent: public SALOME_Event
2941 TEvent( const int id, const bool on )
2942 : myWndId( id ), myOn( on ) {}
2943 virtual void Execute()
2945 SUIT_ViewWindow* wnd = getWnd( myWndId );
2946 if ( wnd ) wnd->setClosable( myOn );
2949 ProcessVoidEvent( new TEvent( id, on ) );
2953 \fn bool SalomePyQt::isViewClosable( const int id );
2954 \brief Check whether view is closable (i.e. can be closed by the user)
2955 \param id window identifier
2956 \return \c true if view is closable or \c false otherwise
2959 class TIsViewClosable: public SALOME_Event
2962 typedef bool TResult;
2965 TIsViewClosable( const int id )
2968 virtual void Execute()
2970 SUIT_ViewWindow* wnd = getWnd( myWndId );
2972 myResult = wnd->closable();
2976 bool SalomePyQt::isViewClosable( const int id )
2978 return ProcessEvent( new TIsViewClosable( id ) );
2982 \fn bool SalomePyQt::groupAllViews();
2983 \brief Group all views to the single tab area
2984 \return \c true if operation is completed successfully and \c false otherwise
2987 class TGroupAllViews: public SALOME_Event
2990 typedef bool TResult;
2993 : myResult( false ) {}
2994 virtual void Execute()
2996 LightApp_Application* app = getApplication();
2999 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3002 QtxWorkstack* wStack = tabDesk->workstack();
3012 bool SalomePyQt::groupAllViews()
3014 return ProcessEvent( new TGroupAllViews() );
3018 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3019 \brief Split tab area to which view with identifier belongs to
3020 \param id window identifier
3021 \param ori orientation of split operation
3022 \param action action to be performed
3023 \return \c true if operation is completed successfully \c false otherwise
3026 class TSplitView: public SALOME_Event
3029 typedef bool TResult;
3034 TSplitView( const int id,
3035 const Orientation ori,
3036 const Action action )
3037 : myResult( false ),
3040 myAction( action ) {}
3041 virtual void Execute()
3043 SUIT_ViewWindow* wnd = getWnd( myWndId );
3047 // wnd->setFocus(); ???
3050 if ( getApplication() )
3052 STD_TabDesktop* desk =
3053 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3056 QtxWorkstack* wStack = desk->workstack();
3059 Qt::Orientation qtOri =
3060 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3062 QtxWorkstack::SplitType sType;
3063 if ( myAction == MoveWidget )
3064 sType = QtxWorkstack::SplitMove;
3065 else if ( myAction == LeaveWidget )
3066 sType = QtxWorkstack::SplitStay;
3068 sType = QtxWorkstack::SplitAt;
3070 wStack->Split( wnd, qtOri, sType );
3078 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3080 return ProcessEvent( new TSplitView( id, ori, action ) );
3084 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3085 \brief Move view with the first identifier to the same area which
3086 another view with the second identifier belongs to
3087 \param id source window identifier
3088 \param id_to destination window identifier
3089 param before specifies whether the first viewt has to be moved before or after
3091 \return \c true if operation is completed successfully and \c false otherwise
3094 class TMoveView: public SALOME_Event
3097 typedef bool TResult;
3102 TMoveView( const int id, const int id_to, const bool before )
3103 : myResult( false ),
3106 myIsBefore( before ) {}
3107 virtual void Execute()
3109 SUIT_ViewWindow* wnd = getWnd( myWndId );
3110 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3111 if ( wnd && wnd_to )
3113 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3114 getApplication()->desktop() )->workstack();
3116 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3120 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3122 return ProcessEvent( new TMoveView( id, id_to, before ) );
3126 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3127 \brief Get list of views identifiers that belongs to the same area as
3128 specified view (excluding it)
3129 \param id window identifier
3130 \return list of views identifiers
3133 class TNeighbourViews: public SALOME_Event
3136 typedef QList<int> TResult;
3139 TNeighbourViews( const int id )
3141 virtual void Execute()
3144 SUIT_ViewWindow* wnd = getWnd( myWndId );
3147 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3148 getApplication()->desktop() )->workstack();
3151 QWidgetList wgList = wStack->windowList( wnd );
3153 foreach ( wg, wgList )
3155 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3156 if ( tmpWnd && tmpWnd != wnd )
3157 myResult.append( tmpWnd->getId() );
3163 QList<int> SalomePyQt::neighbourViews( const int id )
3165 return ProcessEvent( new TNeighbourViews( id ) );
3170 \fn QString SalomePyQt::createObject( const QString& parent );
3171 \brief Create empty data object
3172 \param parent entry of parent data object
3173 \return entry of created data object
3176 class TCreateEmptyObjectEvent: public SALOME_Event
3179 typedef QString TResult;
3182 TCreateEmptyObjectEvent( const QString& parent )
3183 : myParent( parent ) {}
3184 virtual void Execute()
3186 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3188 myResult = module->createObject( myParent );
3191 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3195 QString SalomePyQt::createObject( const QString& parent )
3197 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3201 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3202 const QString& tooltip,const QString& parent );
3203 \brief Create new data object with specified name, icon and tooltip
3204 \param name data object name
3205 \param icon data object icon
3206 \param toolTip data object tooltip
3207 \param parent entry of parent data object
3208 \return entry of created data object
3211 class TCreateObjectEvent: public SALOME_Event
3214 typedef QString TResult;
3220 TCreateObjectEvent( const QString& name,
3221 const QString& icon,
3222 const QString& tooltip,
3223 const QString& parent )
3226 myToolTip( tooltip ),
3227 myParent( parent ) {}
3228 virtual void Execute()
3230 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3232 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3235 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3239 QString SalomePyQt::createObject( const QString& name,
3240 const QString& icon,
3241 const QString& toolTip,
3242 const QString& parent )
3244 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3249 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3250 \brief Set data object name
3251 \param entry data object entry
3252 \param name data object name
3254 class TSetNameEvent: public SALOME_Event
3259 TSetNameEvent( const QString& entry,
3260 const QString& name )
3263 virtual void Execute()
3265 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3267 module->setName( myEntry, myName );
3270 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3274 void SalomePyQt::setName( const QString& entry, const QString& name )
3276 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3280 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3281 \brief Set data object icon
3282 \param entry data object entry
3283 \param icon data object icon file name (icon is loaded from module resources)
3286 class TSetIconEvent: public SALOME_Event
3291 TSetIconEvent( const QString& entry,
3292 const QString& icon )
3295 virtual void Execute()
3297 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3299 module->setIcon( myEntry, myIcon );
3302 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3307 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3309 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3313 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3314 \brief Set data object tooltip
3315 \param entry data object entry
3316 \param toolTip data object tooltip
3319 class TSetToolTipEvent: public SALOME_Event
3324 TSetToolTipEvent( const QString& entry,
3325 const QString& toolTip )
3327 myToolTip( toolTip ) {}
3328 virtual void Execute()
3330 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3332 module->setToolTip( myEntry, myToolTip );
3335 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3339 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3341 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3345 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3346 \brief Set reference to another data object
3347 \param entry data object entry
3348 \param refEntry referenced data object entry
3351 class TSetRefEvent: public SALOME_Event
3356 TSetRefEvent( const QString& entry,
3357 const QString& refEntry )
3359 myRefEntry( refEntry ) {}
3360 virtual void Execute()
3362 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3364 module->setReference( myEntry, myRefEntry );
3367 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3371 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3373 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3377 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3378 \brief Set data object color
3379 \param entry data object entry
3380 \param color data object color
3383 class TSetColorEvent: public SALOME_Event
3388 TSetColorEvent( const QString& entry,
3389 const QColor& color )
3392 virtual void Execute()
3394 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3396 module->setColor( myEntry, myColor );
3399 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3403 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3405 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3409 \fn QString SalomePyQt::getName( const QString& entry );
3410 \brief Get data object name
3411 \param entry data object entry
3412 \return data object name
3415 class TGetNameEvent: public SALOME_Event
3418 typedef QString TResult;
3421 TGetNameEvent( const QString& entry )
3422 : myEntry( entry ) {}
3423 virtual void Execute()
3425 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3427 myResult = module->getName( myEntry );
3430 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3434 QString SalomePyQt::getName( const QString& entry )
3436 return ProcessEvent( new TGetNameEvent( entry ) );
3440 \fn QString SalomePyQt::getToolTip( const QString& entry );
3441 \brief Get data object tooltip
3442 \param entry data object entry
3443 \return data object tooltip
3446 class TGetToolTipEvent: public SALOME_Event
3449 typedef QString TResult;
3452 TGetToolTipEvent( const QString& entry )
3453 : myEntry( entry ) {}
3454 virtual void Execute()
3456 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3458 myResult = module->getToolTip( myEntry );
3461 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3465 QString SalomePyQt::getToolTip( const QString& entry )
3467 return ProcessEvent( new TGetToolTipEvent( entry ) );
3471 \fn QString SalomePyQt::getReference( const QString& entry );
3472 \brief Get entry of the referenced object (if there's any)
3473 \param entry data object entry
3474 \return referenced data object entry
3477 class TGetRefEvent: public SALOME_Event
3480 typedef QString TResult;
3483 TGetRefEvent( const QString& entry )
3484 : myEntry( entry ) {}
3485 virtual void Execute()
3487 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3489 myResult = module->getReference( myEntry );
3492 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3496 QString SalomePyQt::getReference( const QString& entry )
3498 return ProcessEvent( new TGetRefEvent( entry ) );
3502 \fn QColor SalomePyQt::getColor( const QString& entry );
3503 \brief Get data object color
3504 \param entry data object entry
3505 \return data object color
3508 class TGetColorEvent: public SALOME_Event
3511 typedef QColor TResult;
3514 TGetColorEvent( const QString& entry )
3515 : myEntry( entry ) {}
3516 virtual void Execute()
3518 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3520 myResult = module->getColor( myEntry );
3523 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3527 QColor SalomePyQt::getColor( const QString& entry )
3529 return ProcessEvent( new TGetColorEvent( entry ) );
3533 \fn void SalomePyQt::removeChildren( const QString& entry );
3534 \brief Remove all child data objects from specified data object
3535 \param entry data object entry
3538 class TRemoveChildEvent: public SALOME_Event
3542 TRemoveChildEvent( const QString& entry )
3543 : myEntry( entry ) {}
3544 virtual void Execute()
3546 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3548 module->removeChildren( myEntry );
3551 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3555 void SalomePyQt::removeChildren( const QString& entry )
3557 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3559 void SalomePyQt::removeChild( const QString& entry )
3561 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3562 removeChildren( entry );
3566 \fn void SalomePyQt::removeObject( const QString& entry );
3567 \brief Remove object by entry
3568 \param entry data object entry
3571 class TRemoveObjectEvent: public SALOME_Event
3576 TRemoveObjectEvent( const QString& entry )
3577 : myEntry( entry ) {}
3578 virtual void Execute()
3580 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3582 module->removeObject( myEntry );
3585 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3589 void SalomePyQt::removeObject( const QString& entry )
3591 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3595 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3596 \brief Get entries of all child data objects of specified data object
3597 \param entry data object entry
3598 \param recursive \c true for recursive processing
3601 class TGetChildrenEvent: public SALOME_Event
3604 typedef QStringList TResult;
3608 TGetChildrenEvent( const QString& entry, const bool recursive )
3610 myRecursive( recursive ) {}
3611 virtual void Execute()
3613 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3615 myResult = module->getChildren( myEntry, myRecursive );
3618 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3622 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3624 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3629 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3630 \brief Display theCurve in view
3631 \param id window identifier
3632 \param theCurve curve to display
3635 class TDisplayCurve: public SALOME_Event
3639 Plot2d_Curve* myCurve;
3640 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3641 virtual void Execute() {
3642 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3645 wnd->getViewFrame()->displayCurve(myCurve);
3649 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3651 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3655 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3656 \brief Erase theCurve in view
3657 \param id window identifier
3658 \param theCurve curve to erase
3661 class TEraseCurve: public SALOME_Event
3665 Plot2d_Curve* myCurve;
3666 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3667 virtual void Execute() {
3668 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3671 wnd->getViewFrame()->eraseCurve(myCurve);
3675 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3677 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3681 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3682 \brief Delete theCurve from all views
3683 \param theCurve curve to delete
3686 class TDeleteCurve: public SALOME_Event
3689 Plot2d_Curve* myCurve;
3690 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3691 virtual void Execute() {
3692 LightApp_Application* app = getApplication();
3695 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3698 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3699 SUIT_ViewWindow* wnd;
3700 foreach ( wnd, wndlist )
3702 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3705 aP2d->getViewFrame()->eraseObject(myCurve);
3712 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3714 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3718 \brief updateCurves (repaint) curves in view window.
3720 void SalomePyQt::updateCurves(const int id)
3722 class TEvent: public SALOME_Event
3726 TEvent( const int id ) : myWndId( id ) {}
3727 virtual void Execute()
3729 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3732 wnd->getViewFrame()->DisplayAll();
3736 ProcessVoidEvent( new TEvent(id) );
3740 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3741 \brief Get title of corresponding type
3742 \param id window identifier
3743 \param type is type of title
3744 \return title of corresponding type
3747 class TGetPlot2dTitle: public SALOME_Event
3750 typedef QString TResult;
3754 TGetPlot2dTitle(const int id, ObjectType type) :
3757 virtual void Execute() {
3758 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3761 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3765 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3767 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3772 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3773 \brief Set title of corresponding type
3774 \param id window identifier
3776 \param type is type of title
3780 class TSetPlot2dTitle: public SALOME_Event
3784 Plot2d_Curve* myCurve;
3788 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3793 virtual void Execute() {
3794 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3797 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3801 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3803 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3807 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3808 \brief Get list of Plot2d view ranges
3809 \param id window identifier
3810 \return list of view ranges (XMin, XMax, YMin, YMax)
3813 class TFitRangeByCurves: public SALOME_Event
3816 typedef QList<double> TResult;
3819 TFitRangeByCurves( const int id )
3821 virtual void Execute()
3824 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3827 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3828 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3829 myResult.append(XMin);
3830 myResult.append(XMax);
3831 myResult.append(YMin);
3832 myResult.append(YMax);
3836 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3838 return ProcessEvent( new TFitRangeByCurves( id ) );
3842 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3843 \brief Get list of current Plot2d view ranges
3844 \param id window identifier
3845 \return list of view ranges (XMin, XMax, YMin, YMax)
3848 class TFitRangeCurrent: public SALOME_Event
3851 typedef QList<double> TResult;
3854 TFitRangeCurrent( const int id )
3856 virtual void Execute()
3859 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3862 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3863 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3864 myResult.append(XMin);
3865 myResult.append(XMax);
3866 myResult.append(YMin);
3867 myResult.append(YMax);
3871 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3873 return ProcessEvent( new TFitRangeCurrent( id ) );
3877 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3878 \brief Set range of Plot2d view
3879 \param id window identifier
3886 class TPlot2dFitRange: public SALOME_Event
3894 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3900 virtual void Execute() {
3901 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3904 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3908 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3910 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3913 //class TInitParaview: public SALOME_Event
3916 // TInitParaview() {}
3917 // virtual void Execute() {
3918 // LightApp_Application* anApp = getApplication();
3919 // // Create PVViewer_ViewManager, which will initialize ParaView stuff
3920 // PVViewer_ViewManager* viewMgr =
3921 // dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), true ) );
3924 //void SalomePyQt::initializeParaViewGUI()
3926 // ProcessVoidEvent( new TInitParaview() );
3929 void SalomePyQt::processEvents()
3931 QCoreApplication::processEvents();
3934 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3936 class TEvent: public SALOME_Event
3941 TEvent( const QString& theEntry, int theState):
3942 myEntry(theEntry), myState(theState) {}
3943 virtual void Execute()
3945 LightApp_Study* aStudy = getActiveStudy();
3948 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3951 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3954 class TGetVisibilityStateEvent: public SALOME_Event
3957 typedef int TResult;
3960 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3961 virtual void Execute()
3963 LightApp_Study* aStudy = getActiveStudy();
3965 myResult = aStudy->visibilityState(myEntry);
3969 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3971 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3975 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3977 class TEvent: public SALOME_Event
3982 TEvent( const QString& theEntry, int thePos):
3983 myEntry(theEntry), myPos(thePos) {}
3984 virtual void Execute()
3986 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3988 module->setObjectPosition(myEntry, myPos );
3991 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3996 class TGetObjectPositionEvent: public SALOME_Event
3999 typedef int TResult;
4002 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
4003 virtual void Execute()
4005 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4007 myResult = module->getObjectPosition(myEntry);
4011 int SalomePyQt::getObjectPosition( const QString& theEntry )
4013 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );
4016 void SalomePyQt::startPyLog(const QString& theFileName)
4018 class TEvent: public SALOME_Event
4022 TEvent( const QString& theFileName ):
4023 myFileName( theFileName ) {}
4024 virtual void Execute()
4026 if ( getApplication() ) {
4027 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4028 if ( pyConsole ) pyConsole->startLog( myFileName );
4032 ProcessVoidEvent( new TEvent( theFileName ) );
4035 void SalomePyQt::stopPyLog()
4037 class TEvent: public SALOME_Event
4041 virtual void Execute()
4043 if ( getApplication() ) {
4044 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4045 if ( pyConsole ) pyConsole->stopLog();
4049 ProcessVoidEvent( new TEvent() );