1 // Copyright (C) 2007-2014 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 "Plot2d_ViewManager.h"
43 #include "Plot2d_ViewWindow.h"
44 #include "QtxActionMenuMgr.h"
45 #include "QtxWorkstack.h"
46 #include "QtxTreeView.h"
47 #include "SALOME_Event.h"
48 #include "STD_TabDesktop.h"
49 #include "SUIT_DataBrowser.h"
50 #include "SUIT_ResourceMgr.h"
51 #include "SUIT_Session.h"
52 #include "SUIT_Tools.h"
53 #include "PyConsole_Console.h"
56 #include <QApplication>
57 #include <QPaintEvent>
60 \brief Get the currently active application.
62 \return active application object or 0 if there is no any
64 static LightApp_Application* getApplication()
66 if ( SUIT_Session::session() )
67 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
72 \brief Get the currently active study.
74 \return active study or 0 if there is no study opened
76 static LightApp_Study* getActiveStudy()
78 if ( getApplication() )
79 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
84 \brief Get the currently active module.
86 This function returns correct result only if Python-based
87 module is currently active. Otherwize, 0 is returned.
89 static LightApp_Module* getActiveModule()
91 LightApp_Module* module = 0;
92 if ( LightApp_Application* anApp = getApplication() ) {
93 module = PyModuleHelper::getInitModule();
95 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
101 \brief Get the currently active Python module's helper.
103 This function returns correct result only if Python-based
104 module is currently active. Otherwize, 0 is returned.
106 static PyModuleHelper* getPythonHelper()
108 LightApp_Module* module = getActiveModule();
109 PyModuleHelper* helper = module ? qFindChild<PyModuleHelper*>( module, "python_module_helper" ) : 0;
114 \brief Get SALOME verbose level
116 \return \c true if SALOME debug output is allowed or \c false otherwise
118 static bool verbose()
120 bool isVerbose = false;
121 if ( getenv( "SALOME_VERBOSE" ) ) {
122 QString envVar = getenv( "SALOME_VERBOSE" );
124 int value = envVar.toInt( &ok );
125 isVerbose = ok && value != 0;
131 \class SALOME_Selection
132 \brief The class represents selection which can be used in Python.
136 \brief Map of created selection objects.
139 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
142 \brief Get the selection object for the specified application.
144 Finds or creates the selection object (one per study).
146 \param app application object
147 \return selection object or 0 if \a app is invalid
149 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
151 SALOME_Selection* sel = 0;
152 if ( app && SelMap.find( app ) != SelMap.end() )
155 sel = SelMap[ app ] = new SALOME_Selection( app );
161 \param p parent object
163 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
165 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
167 mySelMgr = app->selectionMgr();
168 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
169 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
176 SALOME_Selection::~SALOME_Selection()
178 LightApp_Application* app = 0;
179 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
180 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
181 if ( it.value() == this ) app = it.key();
183 if ( app ) SelMap.remove( app );
187 \brief Called when selection manager is destroyed (usually
188 when the study is closed).
190 void SALOME_Selection::onSelMgrDestroyed()
196 \brief Clear the selection.
198 void SALOME_Selection::Clear()
200 class TEvent: public SALOME_Event
202 LightApp_SelectionMgr* mySelMgr;
204 TEvent( LightApp_SelectionMgr* selMgr )
205 : mySelMgr( selMgr ) {}
206 virtual void Execute()
209 mySelMgr->clearSelected();
212 ProcessVoidEvent( new TEvent( mySelMgr ) );
216 \brief Clear the selection.
218 void SALOME_Selection::ClearIObjects()
224 Removes all selection filters.
226 void SALOME_Selection::ClearFilters()
228 class TEvent: public SALOME_Event
230 LightApp_SelectionMgr* mySelMgr;
232 TEvent( LightApp_SelectionMgr* selMgr )
233 : mySelMgr( selMgr ) {}
234 virtual void Execute()
237 mySelMgr->clearFilters();
240 ProcessVoidEvent( new TEvent( mySelMgr ) );
245 \brief The class provides utility functions which can be used in the Python
246 to operate with the SALOME GUI.
248 All the functionality of this class is implemented as static methods, so they
249 can be called with the class name prefixed or via creation of the class instance.
250 For example, next both ways of SalomePyQt class usage are legal:
252 from SalomePyQt import *
254 # using SalomePyQt class instance
255 desktop = sg.getDesktop()
256 # using SalomePyQt class directly
257 menubar = SalomePyQt.getMainMenuBar()
262 \fn QWidget* SalomePyQt::getDesktop();
263 \brief Get the active application's desktop window.
264 \return desktop window or 0 if there is no any
267 class TGetDesktopEvent: public SALOME_Event
270 typedef QWidget* TResult;
272 TGetDesktopEvent() : myResult( 0 ) {}
273 virtual void Execute()
275 if ( getApplication() )
276 myResult = (QWidget*)( getApplication()->desktop() );
279 QWidget* SalomePyQt::getDesktop()
281 return ProcessEvent( new TGetDesktopEvent() );
285 \fn QWidget* SalomePyQt::getMainFrame();
286 \brief Get current application's main frame widget [obsolete].
288 Main frame widget is an internal widget of the application
289 desktop window (workspace).
291 \return workspace widget (0 on any error)
294 class TGetMainFrameEvent: public SALOME_Event
297 typedef QWidget* TResult;
299 TGetMainFrameEvent() : myResult( 0 ) {}
300 virtual void Execute()
302 if ( getApplication() ) {
303 SUIT_Desktop* aDesktop = getApplication()->desktop();
304 myResult = (QWidget*)( aDesktop->centralWidget() );
308 QWidget* SalomePyQt::getMainFrame()
310 return ProcessEvent( new TGetMainFrameEvent() );
314 \fn QMenuBar* SalomePyQt::getMainMenuBar();
315 \brief Get current application desktop's main menu.
316 \return main menu object (0 on any error)
319 class TGetMainMenuBarEvent: public SALOME_Event
322 typedef QMenuBar* TResult;
324 TGetMainMenuBarEvent() : myResult( 0 ) {}
325 virtual void Execute()
327 if ( LightApp_Application* anApp = getApplication() ) {
328 myResult = anApp->desktop()->menuBar();
332 QMenuBar* SalomePyQt::getMainMenuBar()
334 return ProcessEvent( new TGetMainMenuBarEvent() );
338 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
339 \brief Get main menu's child popup submenu by its identifier.
341 This function is obsolete.
342 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
344 \param menu menu identifier
345 \return popup submenu object or 0 if it does not exist
349 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
350 \brief Get main menu's child popup submenu by its name.
352 The function creates menu if it does not exist.
354 \param menu menu name
355 \return popup submenu object (0 on any error)
358 class TGetPopupMenuEvent: public SALOME_Event
361 typedef QMenu* TResult;
364 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
365 virtual void Execute()
367 LightApp_Application* anApp = getApplication();
368 if ( anApp && !myMenuName.isEmpty() ) {
369 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
370 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
376 \brief Get menu item title
378 \param menuId menu identifier
379 \return menu title (localized)
381 static QString getMenuName( const QString& menuId )
383 QStringList contexts;
384 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
385 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
386 QString menuName = menuId;
387 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
388 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
392 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
397 menuName = getMenuName( "MEN_DESK_FILE" ); break;
399 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
401 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
403 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
405 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
407 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
409 menuName = getMenuName( "MEN_DESK_HELP" ); break;
411 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
413 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
415 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
419 \fn QTreeView* SalomePyQt::getObjectBrowser();
420 \brief Get object browser
421 \return object browser for the active study or 0 in case of error
424 class TGetObjectBrowserEvent: public SALOME_Event
427 typedef QTreeView* TResult;
429 TGetObjectBrowserEvent() : myResult( 0 ) {}
430 virtual void Execute()
432 LightApp_Application* anApp = getApplication();
434 myResult = anApp->objectBrowser()->treeView();
438 QTreeView* SalomePyQt::getObjectBrowser()
440 return ProcessEvent( new TGetObjectBrowserEvent() );
444 \fn int SalomePyQt::getStudyId();
445 \brief Get active study's identifier.
446 \return active study ID or 0 if there is no active study
449 class TGetStudyIdEvent: public SALOME_Event
454 TGetStudyIdEvent() : myResult( 0 ) {}
455 virtual void Execute()
457 if ( LightApp_Study* aStudy = getActiveStudy() ) {
458 myResult = aStudy->id();
462 int SalomePyQt::getStudyId()
464 return ProcessEvent( new TGetStudyIdEvent() );
468 \fn SALOME_Selection* SalomePyQt::getSelection();
469 \brief Get the selection object for the current study.
471 Creates a Selection object if it has not been created yet.
473 \return selection object (0 on error)
476 class TGetSelectionEvent: public SALOME_Event
479 typedef SALOME_Selection* TResult;
481 TGetSelectionEvent() : myResult( 0 ) {}
482 virtual void Execute()
484 myResult = SALOME_Selection::GetSelection( getApplication() );
487 SALOME_Selection* SalomePyQt::getSelection()
489 return ProcessEvent( new TGetSelectionEvent() );
493 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
494 \brief Put an information message to the current application's
497 Optional second delay parameter (\a sec) can be used to specify
498 time of the message diplaying in seconds. If this parameter is less
499 or equal to zero, the constant message will be put.
501 \param msg message text
502 \param sec message displaying time in seconds
505 class TPutInfoEvent: public SALOME_Event
510 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
511 virtual void Execute()
513 if ( LightApp_Application* anApp = getApplication() ) {
514 anApp->putInfo( myMsg, mySecs * 1000 );
518 void SalomePyQt::putInfo( const QString& msg, const int sec )
520 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
524 \fn const QString SalomePyQt::getActiveComponent();
525 \brief Get the currently active module name (for the current study).
526 \return active module name or empty string if there is no active module
529 class TGetActiveComponentEvent: public SALOME_Event
532 typedef QString TResult;
534 TGetActiveComponentEvent() {}
535 virtual void Execute()
537 if ( LightApp_Application* anApp = getApplication() ) {
538 if ( CAM_Module* mod = anApp->activeModule() ) {
539 myResult = mod->name();
544 const QString SalomePyQt::getActiveComponent()
546 return ProcessEvent( new TGetActiveComponentEvent() );
550 \fn PyObject* SalomePyQt::getActivePythonModule();
551 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
552 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
555 class TGetActivePyModuleEvent: public SALOME_Event
558 typedef PyObject* TResult;
560 TGetActivePyModuleEvent() : myResult( Py_None ) {}
561 virtual void Execute()
563 PyModuleHelper* helper = getPythonHelper();
565 myResult = (PyObject*)helper->pythonModule();
568 PyObject* SalomePyQt::getActivePythonModule()
570 return ProcessEvent( new TGetActivePyModuleEvent() );
574 \fn bool SalomePyQt::activateModule( const QString& modName );
575 \brief Activates SALOME module with the given name
576 \return True if the module has been activated and False otherwise.
579 class TActivateModuleEvent: public SALOME_Event
582 typedef bool TResult;
584 QString myModuleName;
585 TActivateModuleEvent( const QString& modName )
586 : myResult( false ), myModuleName( modName ) {}
587 virtual void Execute()
589 if ( LightApp_Application* anApp = getApplication() ) {
590 myResult = anApp->activateModule( myModuleName );
594 bool SalomePyQt::activateModule( const QString& modName )
596 return ProcessEvent( new TActivateModuleEvent( modName ) );
600 \brief Update an Object Browser of the specified (by identifier) study.
602 If \a studyId <= 0 the active study's object browser is updated.
603 The \a updateSelection parameter is obsolete and currently is not used.
604 This parameter will be removed in future, so try to avoid its usage in
607 \brief studyId study identifier
608 \brief updateSelection update selection flag (not used)
611 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
613 class TEvent: public SALOME_Event
616 bool myUpdateSelection;
618 TEvent( const int studyId, bool updateSelection )
619 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
620 virtual void Execute()
622 if ( SUIT_Session::session() ) {
623 if ( getActiveStudy() && myStudyId <= 0 )
624 myStudyId = getActiveStudy()->id();
625 if ( myStudyId > 0 ) {
626 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
627 QList<SUIT_Application*>::Iterator it;
628 for( it = apps.begin(); it != apps.end(); ++it ) {
629 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
630 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
631 anApp->updateObjectBrowser();
639 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
644 SalomePyQt::isModified()
645 \return The modification status of the data model
646 for the currently active Python module
647 \note This function is supported for "light" Python-based SALOME modules only.
650 class TIsModifiedEvent: public SALOME_Event
653 typedef bool TResult;
655 TIsModifiedEvent() : myResult( false ) {}
656 virtual void Execute()
658 LightApp_Module* module = getActiveModule();
662 SALOME_PYQT_DataModelLight* aModel =
663 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
665 myResult = aModel->isModified();
668 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
672 bool SalomePyQt::isModified()
674 return ProcessEvent(new TIsModifiedEvent());
678 SalomePyQt::setModified()
680 Sets the modification status of the data model for
681 the currently active Python module. This method should be used
682 by the Python code in order to enable/disable "Save" operation
683 depending on the module's data state.
685 \note This function is supported for "light" Python-based SALOME modules only.
687 \param New modification status of the data model
691 void SalomePyQt::setModified( bool flag )
693 class TEvent: public SALOME_Event
699 virtual void Execute()
701 LightApp_Module* module = getActiveModule();
705 SALOME_PYQT_DataModelLight* model =
706 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
708 LightApp_Application* app = module->getApp();
710 if ( model && app ) {
711 model->setModified( myFlag );
712 app->updateActions();
715 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
719 ProcessVoidEvent( new TEvent( flag ) );
723 \brief Default resource file section name.
726 static const char* DEFAULT_SECTION = "SalomePyQt";
729 \brief Add string setting to the application preferences.
731 The parameter \a autoValue is obsolete parameter and currently is not used.
732 This parameter will be removed in future, so try to avoid its usage in
735 This function is obsolete. Use one of addSetting() instead.
737 \param name setting name (it should be of kind <section:setting> where
738 \c section is resources section name and \c setting is setting name)
739 \param value new setting value
740 \param autoValue (not used)
742 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
744 class TEvent: public SALOME_Event
750 TEvent( const QString& name, const QString& value, bool autoValue )
751 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
752 virtual void Execute()
754 if ( SUIT_Session::session() ) {
755 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
756 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
757 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
758 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
759 if ( !_sec.isEmpty() && !_nam.isEmpty() )
760 resMgr->setValue( _sec, _nam, myValue );
764 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
768 \brief Add integer setting to the application preferences.
770 The parameter \a autoValue is obsolete parameter and currently is not used.
771 This parameter will be removed in future, so try to avoid its usage in
774 This function is obsolete. Use one of addSetting() instead.
776 \param name setting name (it should be of kind <section:setting> where
777 \c section is resources section name and \c setting is setting name)
778 \param value new setting value
779 \param autoValue (not used)
781 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
783 class TEvent: public SALOME_Event
789 TEvent( const QString& name, const int value, bool autoValue )
790 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
791 virtual void Execute()
793 if ( SUIT_Session::session() ) {
794 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
795 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
796 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
797 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
798 if ( !_sec.isEmpty() && !_nam.isEmpty() )
799 resMgr->setValue( _sec, _nam, myValue );
803 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
807 \brief Add double setting to the application preferences.
809 The parameter \a autoValue is obsolete parameter and currently is not used.
810 This parameter will be removed in future, so try to avoid its usage in
813 This function is obsolete. Use one of addSetting() instead.
815 \param name setting name (it should be of kind <section:setting> where
816 \c section is resources section name and \c setting is setting name)
817 \param value new setting value
818 \param autoValue (not used)
820 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
822 class TEvent: public SALOME_Event
828 TEvent( const QString& name, const double value, bool autoValue )
829 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
830 virtual void Execute()
832 if ( SUIT_Session::session() ) {
833 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
834 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
835 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
836 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
837 if ( !_sec.isEmpty() && !_nam.isEmpty() )
838 resMgr->setValue( _sec, _nam, myValue );
842 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
846 \brief Add boolean setting to the application preferences.
848 The parameter \a autoValue is obsolete parameter and currently is not used.
849 This parameter will be removed in future, so try to avoid its usage in
852 This function is obsolete. Use one of addSetting() instead.
854 \param name setting name (it should be of kind <section:setting> where
855 \c section is resources section name and \c setting is setting name)
856 \param value new setting value
857 \param autoValue (not used)
859 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
861 class TEvent: public SALOME_Event
867 TEvent( const QString& name, const bool value, bool autoValue )
868 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
869 virtual void Execute()
871 if ( SUIT_Session::session() ) {
872 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
873 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
874 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
875 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
876 if ( !_sec.isEmpty() && !_nam.isEmpty() )
877 resMgr->setValue( _sec, _nam, myValue );
881 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
885 \brief Remove setting from the application preferences.
887 This function is obsolete. Use removeSetting() instead.
889 \param name setting name (it should be of kind <section:setting> where
890 \c section is resources section name and \c setting is setting name)
892 void SalomePyQt::removeSettings( const QString& name )
894 class TEvent: public SALOME_Event
898 TEvent( const QString& name ) : myName( name ) {}
899 virtual void Execute()
901 if ( SUIT_Session::session() ) {
902 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
903 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
904 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
905 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
906 if ( !_sec.isEmpty() && !_nam.isEmpty() )
907 resMgr->remove( _sec, _nam );
911 ProcessVoidEvent( new TEvent( name ) );
915 \fn QString SalomePyQt::getSetting( const QString& name );
916 \brief Get application setting value (as string represenation).
918 This function is obsolete. Use stringSetting(), integerSetting(),
919 boolSetting(), stringSetting() or colorSetting() instead.
921 \param name setting name (it should be of kind <section:setting> where
922 \c section is resources section name and \c setting is setting name)
923 \return setting name (empty string if setting name is invalid)
926 class TGetSettingEvent: public SALOME_Event
929 typedef QString TResult;
932 TGetSettingEvent( const QString& name ) : myName( name ) {}
933 virtual void Execute()
935 if ( SUIT_Session::session() ) {
936 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
937 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
938 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
939 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
940 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
944 QString SalomePyQt::getSetting( const QString& name )
946 return ProcessEvent( new TGetSettingEvent( name ) );
950 \brief Add double setting to the application preferences.
951 \param section resources file section name
952 \param name setting name
953 \param value new setting value
955 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
957 class TEvent: public SALOME_Event
963 TEvent( const QString& section, const QString& name, double value )
964 : mySection( section ), myName( name ), myValue( value ) {}
965 virtual void Execute()
967 if ( SUIT_Session::session() ) {
968 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
969 if ( !mySection.isEmpty() && !myName.isEmpty() )
970 resMgr->setValue( mySection, myName, myValue );
974 ProcessVoidEvent( new TEvent( section, name, value ) );
978 \brief Add integer setting to the application preferences.
979 \param section resources file section name
980 \param name setting name
981 \param value new setting value
983 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
985 class TEvent: public SALOME_Event
991 TEvent( const QString& section, const QString& name, int value )
992 : mySection( section ), myName( name ), myValue( value ) {}
993 virtual void Execute()
995 if ( SUIT_Session::session() ) {
996 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
997 if ( !mySection.isEmpty() && !myName.isEmpty() )
998 resMgr->setValue( mySection, myName, myValue );
1002 ProcessVoidEvent( new TEvent( section, name, value ) );
1006 \brief Add boolean setting to the application preferences.
1007 \param section resources file section name
1008 \param name setting name
1009 \param value new setting value
1010 \param dumb this parameter is used in order to avoid sip compilation error
1011 because of conflicting int and bool types
1013 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1015 class TEvent: public SALOME_Event
1021 TEvent( const QString& section, const QString& name, bool value )
1022 : mySection( section ), myName( name ), myValue( value ) {}
1023 virtual void Execute()
1025 if ( SUIT_Session::session() ) {
1026 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1027 if ( !mySection.isEmpty() && !myName.isEmpty() )
1028 resMgr->setValue( mySection, myName, myValue );
1032 ProcessVoidEvent( new TEvent( section, name, value ) );
1036 \brief Add string setting to the application preferences.
1037 \param section resources file section name
1038 \param name setting name
1039 \param value new setting value
1041 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1043 class TEvent: public SALOME_Event
1049 TEvent( const QString& section, const QString& name, const QString& value )
1050 : mySection( section ), myName( name ), myValue( value ) {}
1051 virtual void Execute()
1053 if ( SUIT_Session::session() ) {
1054 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1055 if ( !mySection.isEmpty() && !myName.isEmpty() )
1056 resMgr->setValue( mySection, myName, myValue );
1060 ProcessVoidEvent( new TEvent( section, name, value ) );
1064 \brief Add color setting to the application preferences.
1065 \param section resources file section name
1066 \param name setting name
1067 \param value new setting value
1069 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1071 class TEvent: public SALOME_Event
1077 TEvent( const QString& section, const QString& name, const QColor& value )
1078 : mySection( section ), myName( name ), myValue( value ) {}
1079 virtual void Execute()
1081 if ( SUIT_Session::session() ) {
1082 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1083 if ( !mySection.isEmpty() && !myName.isEmpty() )
1084 resMgr->setValue( mySection, myName, myValue );
1088 ProcessVoidEvent( new TEvent( section, name, value ) );
1092 \fn int SalomePyQt::integerSetting( const QString& section,
1093 const QString& name,
1095 \brief Get integer setting from the application preferences.
1096 \param section resources file section name
1097 \param name setting name
1098 \param def default value which is returned if the setting is not found
1099 \return setting value
1102 class TGetIntSettingEvent: public SALOME_Event
1105 typedef int TResult;
1110 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1111 : mySection( section ), myName( name ), myDefault( def ) {}
1112 virtual void Execute()
1114 if ( SUIT_Session::session() ) {
1115 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1116 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1120 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1122 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1126 \fn double SalomePyQt::doubleSetting( const QString& section,
1127 const QString& name,
1129 \brief Get double setting from the application preferences.
1130 \param section resources file section name
1131 \param name setting name
1132 \param def default value which is returned if the setting is not found
1133 \return setting value
1136 class TGetDblSettingEvent: public SALOME_Event
1139 typedef double TResult;
1144 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1145 : mySection( section ), myName( name ), myDefault( def ) {}
1146 virtual void Execute()
1148 if ( SUIT_Session::session() ) {
1149 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1150 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1154 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1156 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1160 \fn bool SalomePyQt::boolSetting( const QString& section,
1161 const QString& name,
1163 \brief Get boolean setting from the application preferences.
1164 \param section resources file section name
1165 \param name setting name
1166 \param def default value which is returned if the setting is not found
1167 \return setting value
1170 class TGetBoolSettingEvent: public SALOME_Event
1173 typedef bool TResult;
1178 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1179 : mySection( section ), myName( name ), myDefault( def ) {}
1180 virtual void Execute()
1182 if ( SUIT_Session::session() ) {
1183 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1184 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1188 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1190 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1194 \fn QString SalomePyQt::stringSetting( const QString& section,
1195 const QString& name,
1196 const QString& def );
1197 \brief Get string setting from the application preferences.
1198 \param section resources file section name
1199 \param name setting name
1200 \param def default value which is returned if the setting is not found
1201 \return setting value
1204 class TGetStrSettingEvent: public SALOME_Event
1207 typedef QString TResult;
1212 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1213 : mySection( section ), myName( name ), myDefault( def ) {}
1214 virtual void Execute()
1216 if ( SUIT_Session::session() ) {
1217 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1218 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1222 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1224 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1228 \fn QColor SalomePyQt::colorSetting( const QString& section,
1229 const QString& name,
1231 \brief Get color setting from the application preferences.
1232 \param section resources file section name
1233 \param name setting name
1234 \param def default value which is returned if the setting is not found
1235 \return setting value
1238 class TGetColorSettingEvent: public SALOME_Event
1241 typedef QColor TResult;
1246 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1247 : mySection( section ), myName( name ), myDefault( def ) {}
1248 virtual void Execute()
1250 if ( SUIT_Session::session() ) {
1251 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1252 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1256 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1258 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1262 \brief Remove setting from the application preferences.
1263 \param section resources file section name
1264 \param name setting name
1266 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1268 class TEvent: public SALOME_Event
1273 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1274 virtual void Execute()
1276 if ( SUIT_Session::session() ) {
1277 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1278 if ( !mySection.isEmpty() && !myName.isEmpty() )
1279 resMgr->remove( mySection, myName );
1283 ProcessVoidEvent( new TEvent( section, name ) );
1287 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1288 \brief Check setting existence in the application preferences.
1289 \param section resources file section name
1290 \param name setting name
1291 \return \c true if setting exists
1294 class THasColorSettingEvent: public SALOME_Event
1297 typedef bool TResult;
1301 THasColorSettingEvent( const QString& section, const QString& name )
1302 : mySection( section ), myName( name ) {}
1303 virtual void Execute()
1305 if ( SUIT_Session::session() ) {
1306 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1307 myResult = resMgr->hasValue( mySection, myName );
1311 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1313 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1317 \fn QString SalomePyQt::getFileName( QWidget* parent,
1318 const QString& initial,
1319 const QStringList& filters,
1320 const QString& caption,
1322 \brief Show 'Open/Save file' dialog box for file selection
1323 and return a user's choice (selected file name).
1324 \param parent parent widget
1325 \param initial initial directory the dialog box to be opened in
1326 \param filters list of files filters (wildcards)
1327 \param caption dialog box title
1328 \param open if \c true, "Open File" dialog box is shown;
1329 otherwise "Save File" dialog box is shown
1330 \return selected file name (null string if user cancels operation)
1333 class TGetFileNameEvent: public SALOME_Event
1336 typedef QString TResult;
1340 QStringList myFilters;
1343 TGetFileNameEvent( QWidget* parent,
1344 const QString& initial,
1345 const QStringList& filters,
1346 const QString& caption,
1348 : myParent ( parent ),
1349 myInitial( initial ),
1350 myFilters( filters ),
1351 myCaption( caption ),
1353 virtual void Execute()
1355 if ( LightApp_Application* anApp = getApplication() ) {
1356 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1357 myCaption, myParent );
1361 QString SalomePyQt::getFileName( QWidget* parent,
1362 const QString& initial,
1363 const QStringList& filters,
1364 const QString& caption,
1367 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1371 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1372 const QString& initial,
1373 const QStringList& filters,
1374 const QString& caption );
1375 \brief Show 'Open files' dialog box for multiple files selection
1376 and return a user's choice (selected file names list).
1377 \param parent parent widget
1378 \param initial initial directory the dialog box to be opened in
1379 \param filters list of files filters (wildcards)
1380 \param caption dialog box title
1381 \return selected file names list (empty list if user cancels operation)
1384 class TGetOpenFileNamesEvent: public SALOME_Event
1387 typedef QStringList TResult;
1391 QStringList myFilters;
1393 TGetOpenFileNamesEvent( QWidget* parent,
1394 const QString& initial,
1395 const QStringList& filters,
1396 const QString& caption )
1397 : myParent ( parent ),
1398 myInitial( initial ),
1399 myFilters( filters ),
1400 myCaption( caption ) {}
1401 virtual void Execute()
1403 if ( LightApp_Application* anApp = getApplication() ) {
1404 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1408 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1409 const QString& initial,
1410 const QStringList& filters,
1411 const QString& caption )
1413 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1417 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1418 const QString& initial,
1419 const QString& caption );
1420 \brief Show 'Get Directory' dialog box for the directory selection
1421 and return a user's choice (selected directory name).
1422 \param parent parent widget
1423 \param initial initial directory the dialog box to be opened in
1424 \param caption dialog box title
1425 \return selected directory name (null string if user cancels operation)
1428 class TGetExistingDirectoryEvent: public SALOME_Event
1431 typedef QString TResult;
1436 TGetExistingDirectoryEvent( QWidget* parent,
1437 const QString& initial,
1438 const QString& caption )
1439 : myParent ( parent ),
1440 myInitial( initial ),
1441 myCaption( caption ) {}
1442 virtual void Execute()
1444 if ( LightApp_Application* anApp = getApplication() ) {
1445 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1449 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1450 const QString& initial,
1451 const QString& caption )
1453 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1457 \fn QString SalomePyQt::loadIcon( const QString& filename );
1458 \brief Load an icon from the module resources by the specified file name.
1459 \param fileName icon file name
1463 static QIcon loadIconInternal( const QString& module, const QString& fileName )
1467 LightApp_Application* app = getApplication();
1469 if ( app && !fileName.isEmpty() ) {
1470 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
1471 QApplication::translate( module.toLatin1().data(),
1472 fileName.toLatin1().data() ) );
1473 if ( !pixmap.isNull() )
1474 icon = QIcon( pixmap );
1479 class TLoadIconEvent: public SALOME_Event
1482 typedef QIcon TResult;
1486 TLoadIconEvent( const QString& module, const QString& filename )
1487 : myModule( module ),
1488 myFileName ( filename ) {}
1489 virtual void Execute()
1491 myResult = loadIconInternal( myModule, myFileName );
1494 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1496 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1500 \brief Open external browser to display context help information.
1503 Current implementation does nothing.
1505 \param source documentation (HTML) file name
1506 \param context context (for example, HTML ancor name)
1508 void SalomePyQt::helpContext( const QString& source, const QString& context )
1510 class TEvent: public SALOME_Event
1515 TEvent( const QString& source, const QString& context )
1516 : mySource( source ), myContext( context ) {}
1517 virtual void Execute()
1519 if ( LightApp_Application* anApp = getApplication() ) {
1520 anApp->onHelpContextModule( "", mySource, myContext );
1524 ProcessVoidEvent( new TEvent( source, context ) );
1528 \fn int SalomePyQt::defaultMenuGroup();
1529 \brief Get detault menu group identifier which can be used when
1530 creating menus (insert custom menu commands).
1531 \return default menu group ID
1534 class TDefMenuGroupEvent: public SALOME_Event
1537 typedef int TResult;
1539 TDefMenuGroupEvent() : myResult( -1 ) {}
1540 virtual void Execute()
1542 myResult = PyModuleHelper::defaultMenuGroup();
1545 int SalomePyQt::defaultMenuGroup()
1547 return ProcessEvent( new TDefMenuGroupEvent() );
1553 CrTool( const QString& tBar, const QString& nBar )
1554 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1555 CrTool( const int id, const int tBar, const int idx )
1556 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1557 CrTool( const int id, const QString& tBar, const int idx )
1558 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1559 CrTool( QAction* action, const int tbId, const int id, const int idx )
1560 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1561 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1562 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1564 int execute( LightApp_Module* module ) const
1569 return module->createTool( myTbTitle, myTbName );
1571 return module->createTool( myId, myTbId, myIndex );
1573 return module->createTool( myId, myTbTitle, myIndex );
1575 return module->createTool( myAction, myTbId, myId, myIndex );
1577 return module->createTool( myAction, myTbTitle, myId, myIndex );
1592 class TCreateToolEvent: public SALOME_Event
1595 typedef int TResult;
1597 const CrTool& myCrTool;
1598 TCreateToolEvent( const CrTool& crTool )
1599 : myResult( -1 ), myCrTool( crTool ) {}
1600 virtual void Execute()
1602 LightApp_Module* module = getActiveModule();
1604 myResult = myCrTool.execute( module );
1609 \brief Create toolbar with specified name.
1610 \param tBar toolbar title (language-dependent)
1611 \param nBar toolbar name (language-independent) [optional]
1612 \return toolbar ID or -1 if toolbar creation is failed
1614 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1616 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1620 \brief Insert action with specified \a id to the toolbar.
1622 \param tBar toolbar ID
1623 \param idx required index in the toolbar
1624 \return action ID or -1 if action could not be added
1626 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1628 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1632 \brief Insert action with specified \a id to the toolbar.
1634 \param tBar toolbar name
1635 \param idx required index in the toolbar
1636 \return action ID or -1 if action could not be added
1638 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1640 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1644 \brief Insert action to the toolbar.
1646 \param tBar toolbar ID
1647 \param id required action ID
1648 \param idx required index in the toolbar
1649 \return action ID or -1 if action could not be added
1651 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1653 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1657 \brief Insert action to the toolbar.
1659 \param tBar toolbar name
1660 \param id required action ID
1661 \param idx required index in the toolbar
1662 \return action ID or -1 if action could not be added
1664 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1666 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1672 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1673 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1674 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1675 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1676 CrMenu( const int id, const int menu, const int group, const int idx )
1677 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1678 CrMenu( const int id, const QString& menu, const int group, const int idx )
1679 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1680 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1681 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1682 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1683 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1685 int execute( LightApp_Module* module ) const
1690 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1692 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1694 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1696 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1698 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1700 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1709 QString mySubMenuName;
1716 class TCreateMenuEvent: public SALOME_Event
1719 typedef int TResult;
1721 const CrMenu& myCrMenu;
1722 TCreateMenuEvent( const CrMenu& crMenu )
1723 : myResult( -1 ), myCrMenu( crMenu ) {}
1724 virtual void Execute()
1726 LightApp_Module* module = getActiveModule();
1728 myResult = myCrMenu.execute( module );
1733 \brief Create main menu.
1734 \param subMenu menu name
1735 \param menu parent menu ID
1736 \param id required menu ID
1737 \param group menu group ID
1738 \param idx required index in the menu
1739 \return menu ID or -1 if menu could not be added
1741 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1743 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1747 \brief Create main menu.
1748 \param subMenu menu name
1749 \param menu parent menu name (list of menu names separated by "|")
1750 \param id required menu ID
1751 \param group menu group ID
1752 \param idx required index in the menu
1753 \return menu ID or -1 if menu could not be added
1755 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1757 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1761 \brief Insert action to the main menu.
1763 \param menu parent menu ID
1764 \param group menu group ID
1765 \param idx required index in the menu
1766 \return action ID or -1 if action could not be added
1768 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1770 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1774 \brief Insert action to the main menu.
1776 \param menu parent menu name (list of menu names separated by "|")
1777 \param group menu group ID
1778 \param idx required index in the menu
1779 \return action ID or -1 if action could not be added
1781 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1783 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1787 \brief Insert action to the main menu.
1789 \param menu parent menu ID
1790 \param group menu group ID
1791 \param idx required index in the menu
1792 \return action ID or -1 if action could not be added
1794 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1796 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1800 \brief Insert action to the main menu.
1802 \param menu parent menu name (list of menu names separated by "|")
1803 \param group menu group ID
1804 \param idx required index in the menu
1805 \return action ID or -1 if action could not be added
1807 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1809 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1813 \fn QAction* SalomePyQt::createSeparator();
1814 \brief Create separator action which can be used in the menu or toolbar.
1815 \return new separator action
1818 class TCreateSepEvent: public SALOME_Event
1821 typedef QAction* TResult;
1825 virtual void Execute()
1827 LightApp_Module* module = getActiveModule();
1829 myResult = (QAction*)module->separator();
1832 QAction* SalomePyQt::createSeparator()
1834 return ProcessEvent( new TCreateSepEvent() );
1838 \fn QAction* SalomePyQt::createAction( const int id,
1839 const QString& menuText,
1840 const QString& tipText,
1841 const QString& statusText,
1842 const QString& icon,
1844 const bool toggle );
1845 \brief Create an action which can be then used in the menu or toolbar.
1846 \param id the unique id action to be registered to
1847 \param menuText action text which should appear in menu
1848 \param tipText text which should appear in the tooltip
1849 \param statusText text which should appear in the status bar when action is activated
1850 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1851 \param key the key accelrator for the action
1852 \param toggle if \c true the action is checkable
1855 class TCreateActionEvent: public SALOME_Event
1858 typedef QAction* TResult;
1863 QString myStatusText;
1867 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1868 const QString& statusText, const QString& icon, const int key, const bool toggle )
1869 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1870 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1871 virtual void Execute()
1873 LightApp_Module* module = getActiveModule();
1875 QIcon icon = loadIconInternal( module->name(), myIcon );
1876 myResult = (QAction*)module->action( myId );
1878 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1879 myResult->setToolTip( myTipText );
1880 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1881 myResult->setText( myMenuText );
1882 if ( myResult->icon().isNull() && !icon.isNull() )
1883 myResult->setIcon( icon );
1884 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1885 myResult->setStatusTip( myStatusText );
1886 if ( myResult->shortcut().isEmpty() && myKey )
1887 myResult->setShortcut( myKey );
1888 if ( myResult->isCheckable() != myToggle )
1889 myResult->setCheckable( myToggle );
1892 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1894 // for Python module, automatically connect action to callback slot
1895 PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1896 if ( helper ) helper->connectAction( myResult );
1900 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1901 const QString& tipText, const QString& statusText,
1902 const QString& icon, const int key, const bool toggle )
1904 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1908 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1909 \brief Create an action group which can be then used in the menu or toolbar
1910 \param id : the unique id action group to be registered to
1911 \param exclusive : if \c true the action group does exclusive toggling
1914 struct TCreateActionGroupEvent: public SALOME_Event
1916 typedef QtxActionGroup* TResult;
1920 TCreateActionGroupEvent( const int id, const bool exclusive )
1921 : myId( id ), myExclusive( exclusive ) {}
1922 virtual void Execute()
1924 LightApp_Module* module = getActiveModule();
1926 myResult = module->createActionGroup( myId, myExclusive );
1929 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1931 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1935 \fn QAction* SalomePyQt::action( const int id );
1936 \brief Get action by specified identifier.
1937 \return action or 0 if action is not registered
1940 class TActionEvent: public SALOME_Event
1943 typedef QAction* TResult;
1946 TActionEvent( const int id )
1947 : myResult( 0 ), myId( id ) {}
1948 virtual void Execute()
1950 LightApp_Module* module = getActiveModule();
1952 myResult = (QAction*)module->action( myId );
1955 QAction* SalomePyQt::action( const int id )
1957 return ProcessEvent( new TActionEvent( id ) );
1961 \fn int SalomePyQt::actionId( const QAction* a );
1962 \brief Get an action identifier.
1963 \return action ID or -1 if action is not registered
1966 class TActionIdEvent: public SALOME_Event
1969 typedef int TResult;
1971 const QAction* myAction;
1972 TActionIdEvent( const QAction* action )
1973 : myResult( -1 ), myAction( action ) {}
1974 virtual void Execute()
1976 LightApp_Module* module = getActiveModule();
1978 myResult = module->actionId( myAction );
1981 int SalomePyQt::actionId( const QAction* a )
1983 return ProcessEvent( new TActionIdEvent( a ) );
1987 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1988 \brief Add global (not module-related) preferences group.
1989 \param label global preferences group name
1990 \return preferences group identifier
1993 class TAddGlobalPrefEvent: public SALOME_Event
1996 typedef int TResult;
1999 TAddGlobalPrefEvent( const QString& label )
2000 : myResult( -1 ), myLabel( label ) {}
2001 virtual void Execute()
2003 LightApp_Module* module = getActiveModule();
2005 LightApp_Preferences* pref = module->getApp()->preferences();
2007 myResult = pref->addPreference( myLabel, -1 );
2011 int SalomePyQt::addGlobalPreference( const QString& label )
2013 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2017 \fn int SalomePyQt::addPreference( const QString& label );
2018 \brief Add module-related preferences group.
2019 \param label preferences group name
2020 \return preferences group identifier
2023 class TAddPrefEvent: public SALOME_Event
2026 typedef int TResult;
2029 TAddPrefEvent( const QString& label )
2030 : myResult( -1 ), myLabel( label ) {}
2031 virtual void Execute()
2033 LightApp_Module* module = getActiveModule();
2035 LightApp_Preferences* pref = module->getApp()->preferences();
2037 int cId = pref->addPreference( module->moduleName(), -1 );
2039 myResult = pref->addPreference( myLabel, cId );
2044 int SalomePyQt::addPreference( const QString& label )
2046 return ProcessEvent( new TAddPrefEvent( label ) );
2050 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2051 const QString& section, const QString& param );
2052 \brief Add module-related preferences.
2053 \param label preferences group name
2054 \param pId parent preferences group id
2055 \param type preferences type
2056 \param section resources file section name
2057 \param param resources file setting name
2058 \return preferences identifier
2061 class TAddPrefParamEvent: public SALOME_Event
2064 typedef int TResult;
2071 TAddPrefParamEvent( const QString& label,
2072 const int pId, const int type,
2073 const QString& section,
2074 const QString& param )
2076 myLabel( label ), myPId( pId ), myType( type ),
2077 mySection( section ), myParam ( param ) {}
2078 virtual void Execute()
2080 LightApp_Module* module = getActiveModule();
2082 LightApp_Preferences* pref = module->getApp()->preferences();
2084 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2088 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2089 const QString& section, const QString& param )
2091 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2095 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2096 \brief Get the preferences property.
2097 \param id preferences identifier
2098 \param prop preferences property name
2099 \return preferences property value or null QVariant if property is not set
2102 class TPrefPropEvent: public SALOME_Event
2105 typedef QVariant TResult;
2109 TPrefPropEvent( const int id, const QString& prop )
2110 : myId( id ), myProp( prop ) {}
2111 virtual void Execute()
2113 LightApp_Module* module = getActiveModule();
2115 LightApp_Preferences* pref = module->getApp()->preferences();
2117 myResult = pref->itemProperty( myProp, myId );
2121 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2123 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2127 \brief Set the preferences property.
2128 \param id preferences identifier
2129 \param prop preferences property name
2130 \param var preferences property value
2132 void SalomePyQt::setPreferenceProperty( const int id,
2133 const QString& prop,
2134 const QVariant& var )
2136 class TEvent: public SALOME_Event
2142 TEvent( const int id, const QString& prop, const QVariant& var )
2143 : myId( id ), myProp( prop ), myVar( var ) {}
2144 virtual void Execute()
2146 LightApp_Module* module = getActiveModule();
2148 LightApp_Preferences* pref = module->getApp()->preferences();
2150 pref->setItemProperty( myProp, myVar, myId );
2154 ProcessVoidEvent( new TEvent( id, prop, var) );
2158 \brief Add the property value to the list of values.
2160 This method allows creating properties which are QList<QVariant>
2161 - there is no way to pass such values directly to QVariant parameter with PyQt.
2163 \param id preferences identifier
2164 \param prop preferences property name
2165 \param idx preferences property index
2166 \param var preferences property value for the index \a idx
2168 void SalomePyQt::addPreferenceProperty( const int id,
2169 const QString& prop,
2171 const QVariant& var )
2173 class TEvent: public SALOME_Event
2180 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2181 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2182 virtual void Execute()
2184 LightApp_Module* module = getActiveModule();
2186 LightApp_Preferences* pref = module->getApp()->preferences();
2188 QVariant var = pref->itemProperty( myProp, myId );
2189 if ( var.isValid() ) {
2190 if ( var.type() == QVariant::StringList ) {
2191 QStringList sl = var.toStringList();
2192 if ( myIdx >= 0 && myIdx < sl.count() )
2193 sl[myIdx] = myVar.toString();
2195 sl.append( myVar.toString() );
2196 pref->setItemProperty( myProp, sl, myId );
2198 else if ( var.type() == QVariant::List ) {
2199 QList<QVariant> vl = var.toList();
2200 if ( myIdx >= 0 && myIdx < vl.count() )
2204 pref->setItemProperty( myProp, vl, myId );
2210 pref->setItemProperty( myProp, vl, myId );
2216 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2220 \brief Put the message to the Log messages output window
2221 \param msg message text (it can be of simple rich text format)
2222 \param addSeparator boolean flag which specifies if it is necessary
2223 to separate the message with predefined separator
2225 void SalomePyQt::message( const QString& msg, bool addSeparator )
2227 class TEvent: public SALOME_Event
2232 TEvent( const QString& msg, bool addSeparator )
2233 : myMsg( msg ), myAddSep( addSeparator ) {}
2234 virtual void Execute()
2236 if ( LightApp_Application* anApp = getApplication() ) {
2237 LogWindow* lw = anApp->logWindow();
2239 lw->putMessage( myMsg, myAddSep );
2243 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2247 \brief Remove all the messages from the Log messages output window.
2249 void SalomePyQt::clearMessages()
2251 class TEvent: public SALOME_Event
2255 virtual void Execute()
2257 if ( LightApp_Application* anApp = getApplication() ) {
2258 LogWindow* lw = anApp->logWindow();
2264 ProcessVoidEvent( new TEvent() );
2268 \brief Gets window with specified identifier
2270 \param id window identifier
2271 \return pointer on the window
2273 static SUIT_ViewWindow* getWnd( const int id )
2275 SUIT_ViewWindow* resWnd = 0;
2277 LightApp_Application* app = getApplication();
2280 ViewManagerList vmlist = app->viewManagers();
2281 foreach( SUIT_ViewManager* vm, vmlist )
2283 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2284 foreach ( SUIT_ViewWindow* vw, vwlist )
2286 if ( id == vw->getId() )
2299 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2300 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2301 to the image file in the specified format.
2303 For the current moment JPEG, PNG and BMP images formats are supported.
2304 The image format is defined automatically by the file name extension.
2305 By default, BMP format is used.
2307 \param filename image file name
2308 \return operation status (\c true on success)
2311 class TDumpViewEvent: public SALOME_Event
2314 typedef bool TResult;
2318 TDumpViewEvent( const QString& filename, const int id )
2319 : myResult ( false ), myFileName( filename ), myWndId(id) {}
2320 virtual void Execute()
2322 SUIT_ViewWindow* wnd = NULL;
2325 if ( LightApp_Application* anApp = getApplication() ) {
2326 SUIT_ViewManager* vm = anApp->activeViewManager();
2328 wnd = vm->getActiveView();
2330 myWndId = wnd->getId();
2334 wnd = dynamic_cast<SUIT_ViewWindow*>(getWnd( myWndId ));
2337 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2338 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2339 if(fmt == "PS" || fmt == "EPS" || fmt == "PDF") {
2341 myResult = wnd2D->getViewFrame()->print(myFileName, fmt);
2347 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2348 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2349 qApp->processEvents();
2351 QImage im = wnd->dumpView();
2352 if ( !im.isNull() && !myFileName.isEmpty() ) {
2353 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2354 if ( fmt == "JPG" ) fmt = "JPEG";
2355 myResult = im.save( myFileName, fmt.toLatin1() );
2361 bool SalomePyQt::dumpView( const QString& filename, const int id )
2363 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2368 \fn QList<int> SalomePyQt::getViews();
2369 \brief Get list of integer identifiers of all the currently opened views
2370 \return list of integer identifiers of all the currently opened views
2373 class TGetViews: public SALOME_Event
2376 typedef QList<int> TResult;
2379 virtual void Execute()
2382 LightApp_Application* app = getApplication();
2385 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2388 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2389 SUIT_ViewWindow* wnd;
2390 foreach ( wnd, wndlist )
2391 myResult.append( wnd->getId() );
2396 QList<int> SalomePyQt::getViews()
2398 return ProcessEvent( new TGetViews() );
2402 \fn int SalomePyQt::getActiveView();
2403 \brief Get integer identifier of the currently active view
2404 \return integer identifier of the currently active view
2407 class TGetActiveView: public SALOME_Event
2410 typedef int TResult;
2414 virtual void Execute()
2416 LightApp_Application* app = getApplication();
2419 SUIT_ViewManager* viewMgr = app->activeViewManager();
2422 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2424 myResult = wnd->getId();
2429 int SalomePyQt::getActiveView()
2431 return ProcessEvent( new TGetActiveView() );
2435 \fn QString SalomePyQt::getViewType( const int id );
2436 \brief Get type of the specified view, e.g. "OCCViewer"
2437 \param id window identifier
2441 class TGetViewType: public SALOME_Event
2444 typedef QString TResult;
2447 TGetViewType( const int id )
2449 virtual void Execute()
2451 SUIT_ViewWindow* wnd = getWnd( myWndId );
2454 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2456 myResult = viewMgr->getType();
2460 QString SalomePyQt::getViewType( const int id )
2462 return ProcessEvent( new TGetViewType( id ) );
2466 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2467 \brief Change view caption
2468 \param id window identifier
2469 \param title new window title
2470 \return \c true if operation is completed successfully and \c false otherwise
2473 class TSetViewTitle: public SALOME_Event
2476 typedef bool TResult;
2480 TSetViewTitle( const int id, const QString& title )
2481 : myResult( false ),
2484 virtual void Execute()
2486 SUIT_ViewWindow* wnd = getWnd( myWndId );
2489 wnd->setWindowTitle( myTitle );
2494 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2496 return ProcessEvent( new TSetViewTitle( id, title ) );
2501 \fn QString SalomePyQt::getViewTitle( const int id );
2502 \brief Get view caption
2503 \param id window identifier
2504 \return view caption
2507 class TGetViewTitle: public SALOME_Event
2510 typedef QString TResult;
2513 TGetViewTitle( const int id )
2515 virtual void Execute()
2517 SUIT_ViewWindow* wnd = getWnd( myWndId );
2519 myResult = wnd->windowTitle();
2522 QString SalomePyQt::getViewTitle( const int id )
2524 return ProcessEvent( new TGetViewTitle( id ) );
2528 \fn QList<int> SalomePyQt::findViews( const QString& type );
2529 \brief Get list of integer identifiers of all the
2530 currently opened views of the specified type
2531 \param type viewer type
2532 \return list of integer identifiers
2535 class TFindViews: public SALOME_Event
2538 typedef QList<int> TResult;
2541 TFindViews( const QString& type )
2543 virtual void Execute()
2546 LightApp_Application* app = getApplication();
2549 ViewManagerList vmList;
2550 app->viewManagers( myType, vmList );
2551 SUIT_ViewManager* viewMgr;
2552 foreach ( viewMgr, vmList )
2554 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2555 for ( int i = 0, n = vec.size(); i < n; i++ )
2557 SUIT_ViewWindow* wnd = vec[ i ];
2559 myResult.append( wnd->getId() );
2565 QList<int> SalomePyQt::findViews( const QString& type )
2567 return ProcessEvent( new TFindViews( type ) );
2571 \fn bool SalomePyQt::activateView( const int id );
2572 \brief Activate view
2573 \param id window identifier
2574 \return \c true if operation is completed successfully and \c false otherwise
2577 class TActivateView: public SALOME_Event
2580 typedef bool TResult;
2583 TActivateView( const int id )
2584 : myResult( false ),
2586 virtual void Execute()
2588 SUIT_ViewWindow* wnd = getWnd( myWndId );
2596 bool SalomePyQt::activateView( const int id )
2598 return ProcessEvent( new TActivateView( id ) );
2602 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2603 \brief Create new view and activate it
2604 \param type viewer type
2608 \return integer identifier of created view (or -1 if view could not be created)
2611 class TCreateView: public SALOME_Event
2614 typedef int TResult;
2620 TCreateView( const QString& theType, bool visible, const int width, const int height )
2626 virtual void Execute()
2628 LightApp_Application* app = getApplication();
2631 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2634 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2636 wnd->setShown(myVisible);
2637 if(!myVisible && myWidth == 0 && myHeight == 0) {
2641 if(myWidth > 0 && myHeight > 0) {
2642 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2644 wnd2D->getViewFrame()->setGeometry(0,0,myWidth,myHeight);
2646 wnd->setGeometry(0,0,myWidth,myHeight);
2649 myResult = wnd->getId();
2655 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2657 return ProcessEvent( new TCreateView( type, visible, width, height ) );
2661 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2662 \brief Create new view with custom widget embedded and activate it
2663 \param type viewer type
2664 \param w custom widget
2665 \return integer identifier of created view (or -1 if view could not be created)
2668 class TCreateViewWg: public SALOME_Event
2671 typedef int TResult;
2675 TCreateViewWg( const QString& theType, QWidget* w )
2679 virtual void Execute()
2681 LightApp_Application* app = getApplication();
2684 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2687 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2689 myResult = wnd->getId();
2694 int SalomePyQt::createView( const QString& type, QWidget* w )
2696 return ProcessEvent( new TCreateViewWg( type, w ) );
2700 \fn bool SalomePyQt::closeView( const int id );
2702 \param id window identifier
2703 \return \c true if operation is completed successfully and \c false otherwise
2706 class TCloseView: public SALOME_Event
2709 typedef bool TResult;
2712 TCloseView( const int id )
2713 : myResult( false ),
2715 virtual void Execute()
2717 SUIT_ViewWindow* wnd = getWnd( myWndId );
2720 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2729 bool SalomePyQt::closeView( const int id )
2731 return ProcessEvent( new TCloseView( id ) );
2735 \fn int SalomePyQt::cloneView( const int id );
2736 \brief Clone view (if this operation is supported for specified view type)
2737 \param id window identifier
2738 \return integer identifier of the cloned view or -1 or operation could not be performed
2741 class TCloneView: public SALOME_Event
2744 typedef int TResult;
2747 TCloneView( const int id )
2750 virtual void Execute()
2752 SUIT_ViewWindow* wnd = getWnd( myWndId );
2755 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2758 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2760 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2761 occView->onCloneView();
2763 wnd = viewMgr->getActiveView();
2765 myResult = wnd->getId();
2767 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2769 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2770 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2771 if ( viewMgr2d && srcWnd2d )
2773 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2774 myResult = resWnd->getId();
2781 int SalomePyQt::cloneView( const int id )
2783 return ProcessEvent( new TCloneView( id ) );
2787 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2788 \brief Set view visibility.
2789 \param id window identifier
2790 \param visible new visiblity
2793 void SalomePyQt::setViewVisible( const int id, const bool visible )
2795 class TEvent: public SALOME_Event
2800 TEvent( const int id, const bool visible )
2801 : myWndId( id ), myVisible( visible ) {}
2802 virtual void Execute()
2804 SUIT_ViewWindow* wnd = getWnd( myWndId );
2805 if ( wnd ) wnd->setVisible( myVisible );
2808 ProcessVoidEvent( new TEvent( id, visible ) );
2812 \fn bool SalomePyQt::isViewVisible( const int id );
2813 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2814 \param id window identifier
2815 \return \c true if view is visible and \c false otherwise
2818 class TIsViewVisible: public SALOME_Event
2821 typedef bool TResult;
2824 TIsViewVisible( const int id )
2825 : myResult( false ),
2827 virtual void Execute()
2829 SUIT_ViewWindow* wnd = getWnd( myWndId );
2832 QWidget* p = wnd->parentWidget();
2833 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2837 bool SalomePyQt::isViewVisible( const int id )
2839 return ProcessEvent( new TIsViewVisible( id ) );
2843 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2844 \brief Set / clear view's "closable" option. By default any view is closable
2845 (i.e. can be closed by the user).
2846 \param id window identifier
2847 \param on new "closable" option's value
2850 void SalomePyQt::setViewClosable( const int id, const bool on )
2852 class TEvent: public SALOME_Event
2857 TEvent( const int id, const bool on )
2858 : myWndId( id ), myOn( on ) {}
2859 virtual void Execute()
2861 SUIT_ViewWindow* wnd = getWnd( myWndId );
2862 if ( wnd ) wnd->setClosable( myOn );
2865 ProcessVoidEvent( new TEvent( id, on ) );
2869 \fn bool SalomePyQt::isViewClosable( const int id );
2870 \brief Check whether view is closable (i.e. can be closed by the user)
2871 \param id window identifier
2872 \return \c true if view is closable or \c false otherwise
2875 class TIsViewClosable: public SALOME_Event
2878 typedef bool TResult;
2881 TIsViewClosable( const int id )
2884 virtual void Execute()
2886 SUIT_ViewWindow* wnd = getWnd( myWndId );
2888 myResult = wnd->closable();
2892 bool SalomePyQt::isViewClosable( const int id )
2894 return ProcessEvent( new TIsViewClosable( id ) );
2898 \fn bool SalomePyQt::groupAllViews();
2899 \brief Group all views to the single tab area
2900 \return \c true if operation is completed successfully and \c false otherwise
2903 class TGroupAllViews: public SALOME_Event
2906 typedef bool TResult;
2909 : myResult( false ) {}
2910 virtual void Execute()
2912 LightApp_Application* app = getApplication();
2915 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2918 QtxWorkstack* wStack = tabDesk->workstack();
2928 bool SalomePyQt::groupAllViews()
2930 return ProcessEvent( new TGroupAllViews() );
2934 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2935 \brief Split tab area to which view with identifier belongs to
2936 \param id window identifier
2937 \param ori orientation of split operation
2938 \param action action to be performed
2939 \return \c true if operation is completed successfully \c false otherwise
2942 class TSplitView: public SALOME_Event
2945 typedef bool TResult;
2950 TSplitView( const int id,
2951 const Orientation ori,
2952 const Action action )
2953 : myResult( false ),
2956 myAction( action ) {}
2957 virtual void Execute()
2959 SUIT_ViewWindow* wnd = getWnd( myWndId );
2963 // wnd->setFocus(); ???
2966 if ( getApplication() )
2968 STD_TabDesktop* desk =
2969 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2972 QtxWorkstack* wStack = desk->workstack();
2975 Qt::Orientation qtOri =
2976 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2978 QtxWorkstack::SplitType sType;
2979 if ( myAction == MoveWidget )
2980 sType = QtxWorkstack::SplitMove;
2981 else if ( myAction == LeaveWidget )
2982 sType = QtxWorkstack::SplitStay;
2984 sType = QtxWorkstack::SplitAt;
2986 wStack->Split( wnd, qtOri, sType );
2994 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2996 return ProcessEvent( new TSplitView( id, ori, action ) );
3000 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3001 \brief Move view with the first identifier to the same area which
3002 another view with the second identifier belongs to
3003 \param id source window identifier
3004 \param id_to destination window identifier
3005 param before specifies whether the first viewt has to be moved before or after
3007 \return \c true if operation is completed successfully and \c false otherwise
3010 class TMoveView: public SALOME_Event
3013 typedef bool TResult;
3018 TMoveView( const int id, const int id_to, const bool before )
3019 : myResult( false ),
3022 myIsBefore( before ) {}
3023 virtual void Execute()
3025 SUIT_ViewWindow* wnd = getWnd( myWndId );
3026 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3027 if ( wnd && wnd_to )
3029 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3030 getApplication()->desktop() )->workstack();
3032 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3036 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3038 return ProcessEvent( new TMoveView( id, id_to, before ) );
3042 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3043 \brief Get list of views identifiers that belongs to the same area as
3044 specified view (excluding it)
3045 \param id window identifier
3046 \return list of views identifiers
3049 class TNeighbourViews: public SALOME_Event
3052 typedef QList<int> TResult;
3055 TNeighbourViews( const int id )
3057 virtual void Execute()
3060 SUIT_ViewWindow* wnd = getWnd( myWndId );
3063 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3064 getApplication()->desktop() )->workstack();
3067 QWidgetList wgList = wStack->windowList( wnd );
3069 foreach ( wg, wgList )
3071 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3072 if ( tmpWnd && tmpWnd != wnd )
3073 myResult.append( tmpWnd->getId() );
3079 QList<int> SalomePyQt::neighbourViews( const int id )
3081 return ProcessEvent( new TNeighbourViews( id ) );
3086 \fn QString SalomePyQt::createObject( const QString& parent );
3087 \brief Create empty data object
3088 \param parent entry of parent data object
3089 \return entry of created data object
3092 class TCreateEmptyObjectEvent: public SALOME_Event
3095 typedef QString TResult;
3098 TCreateEmptyObjectEvent( const QString& parent )
3099 : myParent( parent ) {}
3100 virtual void Execute()
3102 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3104 myResult = module->createObject( myParent );
3107 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3111 QString SalomePyQt::createObject( const QString& parent )
3113 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3117 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3118 const QString& tooltip,const QString& parent );
3119 \brief Create new data object with specified name, icon and tooltip
3120 \param name data object name
3121 \param icon data object icon
3122 \param toolTip data object tooltip
3123 \param parent entry of parent data object
3124 \return entry of created data object
3127 class TCreateObjectEvent: public SALOME_Event
3130 typedef QString TResult;
3136 TCreateObjectEvent( const QString& name,
3137 const QString& icon,
3138 const QString& tooltip,
3139 const QString& parent )
3142 myToolTip( tooltip ),
3143 myParent( parent ) {}
3144 virtual void Execute()
3146 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3148 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3151 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3155 QString SalomePyQt::createObject( const QString& name,
3156 const QString& icon,
3157 const QString& toolTip,
3158 const QString& parent )
3160 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3165 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3166 \brief Set data object name
3167 \param entry data object entry
3168 \param name data object name
3170 class TSetNameEvent: public SALOME_Event
3175 TSetNameEvent( const QString& entry,
3176 const QString& name )
3179 virtual void Execute()
3181 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3183 module->setName( myEntry, myName );
3186 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3190 void SalomePyQt::setName( const QString& entry, const QString& name )
3192 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3196 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3197 \brief Set data object icon
3198 \param entry data object entry
3199 \param icon data object icon file name (icon is loaded from module resources)
3202 class TSetIconEvent: public SALOME_Event
3207 TSetIconEvent( const QString& entry,
3208 const QString& icon )
3211 virtual void Execute()
3213 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3215 module->setIcon( myEntry, myIcon );
3218 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3223 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3225 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3229 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3230 \brief Set data object tooltip
3231 \param entry data object entry
3232 \param toolTip data object tooltip
3235 class TSetToolTipEvent: public SALOME_Event
3240 TSetToolTipEvent( const QString& entry,
3241 const QString& toolTip )
3243 myToolTip( toolTip ) {}
3244 virtual void Execute()
3246 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3248 module->setToolTip( myEntry, myToolTip );
3251 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3255 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3257 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3261 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3262 \brief Set reference to another data object
3263 \param entry data object entry
3264 \param refEntry referenced data object entry
3267 class TSetRefEvent: public SALOME_Event
3272 TSetRefEvent( const QString& entry,
3273 const QString& refEntry )
3275 myRefEntry( refEntry ) {}
3276 virtual void Execute()
3278 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3280 module->setReference( myEntry, myRefEntry );
3283 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3287 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3289 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3293 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3294 \brief Set data object color
3295 \param entry data object entry
3296 \param color data object color
3299 class TSetColorEvent: public SALOME_Event
3304 TSetColorEvent( const QString& entry,
3305 const QColor& color )
3308 virtual void Execute()
3310 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3312 module->setColor( myEntry, myColor );
3315 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3319 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3321 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3325 \fn QString SalomePyQt::getName( const QString& entry );
3326 \brief Get data object name
3327 \param entry data object entry
3328 \return data object name
3331 class TGetNameEvent: public SALOME_Event
3334 typedef QString TResult;
3337 TGetNameEvent( const QString& entry )
3338 : myEntry( entry ) {}
3339 virtual void Execute()
3341 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3343 myResult = module->getName( myEntry );
3346 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3350 QString SalomePyQt::getName( const QString& entry )
3352 return ProcessEvent( new TGetNameEvent( entry ) );
3356 \fn QString SalomePyQt::getToolTip( const QString& entry );
3357 \brief Get data object tooltip
3358 \param entry data object entry
3359 \return data object tooltip
3362 class TGetToolTipEvent: public SALOME_Event
3365 typedef QString TResult;
3368 TGetToolTipEvent( const QString& entry )
3369 : myEntry( entry ) {}
3370 virtual void Execute()
3372 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3374 myResult = module->getToolTip( myEntry );
3377 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3381 QString SalomePyQt::getToolTip( const QString& entry )
3383 return ProcessEvent( new TGetToolTipEvent( entry ) );
3387 \fn QString SalomePyQt::getReference( const QString& entry );
3388 \brief Get entry of the referenced object (if there's any)
3389 \param entry data object entry
3390 \return referenced data object entry
3393 class TGetRefEvent: public SALOME_Event
3396 typedef QString TResult;
3399 TGetRefEvent( const QString& entry )
3400 : myEntry( entry ) {}
3401 virtual void Execute()
3403 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3405 myResult = module->getReference( myEntry );
3408 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3412 QString SalomePyQt::getReference( const QString& entry )
3414 return ProcessEvent( new TGetRefEvent( entry ) );
3418 \fn QColor SalomePyQt::getColor( const QString& entry );
3419 \brief Get data object color
3420 \param entry data object entry
3421 \return data object color
3424 class TGetColorEvent: public SALOME_Event
3427 typedef QColor TResult;
3430 TGetColorEvent( const QString& entry )
3431 : myEntry( entry ) {}
3432 virtual void Execute()
3434 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3436 myResult = module->getColor( myEntry );
3439 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3443 QColor SalomePyQt::getColor( const QString& entry )
3445 return ProcessEvent( new TGetColorEvent( entry ) );
3449 \fn void SalomePyQt::removeChildren( const QString& entry );
3450 \brief Remove all child data objects from specified data object
3451 \param entry data object entry
3454 class TRemoveChildEvent: public SALOME_Event
3458 TRemoveChildEvent( const QString& entry )
3459 : myEntry( entry ) {}
3460 virtual void Execute()
3462 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3464 module->removeChildren( myEntry );
3467 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3471 void SalomePyQt::removeChildren( const QString& entry )
3473 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3475 void SalomePyQt::removeChild( const QString& entry )
3477 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3478 removeChildren( entry );
3482 \fn void SalomePyQt::removeObject( const QString& entry );
3483 \brief Remove object by entry
3484 \param entry data object entry
3487 class TRemoveObjectEvent: public SALOME_Event
3492 TRemoveObjectEvent( const QString& entry )
3493 : myEntry( entry ) {}
3494 virtual void Execute()
3496 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3498 module->removeObject( myEntry );
3501 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3505 void SalomePyQt::removeObject( const QString& entry )
3507 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3511 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3512 \brief Get entries of all child data objects of specified data object
3513 \param entry data object entry
3514 \param recursive \c true for recursive processing
3517 class TGetChildrenEvent: public SALOME_Event
3520 typedef QStringList TResult;
3524 TGetChildrenEvent( const QString& entry, const bool recursive )
3526 myRecursive( recursive ) {}
3527 virtual void Execute()
3529 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3531 myResult = module->getChildren( myEntry, myRecursive );
3534 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3538 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3540 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3545 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3546 \brief Display theCurve in view
3547 \param id window identifier
3548 \param theCurve curve to display
3551 class TDisplayCurve: public SALOME_Event
3555 Plot2d_Curve* myCurve;
3556 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3557 virtual void Execute() {
3558 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3561 wnd->getViewFrame()->displayCurve(myCurve);
3565 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3567 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3571 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3572 \brief Erase theCurve in view
3573 \param id window identifier
3574 \param theCurve curve to erase
3577 class TEraseCurve: public SALOME_Event
3581 Plot2d_Curve* myCurve;
3582 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3583 virtual void Execute() {
3584 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3587 wnd->getViewFrame()->eraseCurve(myCurve);
3591 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3593 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3597 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3598 \brief Delete theCurve from all views
3599 \param theCurve curve to delete
3602 class TDeleteCurve: public SALOME_Event
3605 Plot2d_Curve* myCurve;
3606 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3607 virtual void Execute() {
3608 LightApp_Application* app = getApplication();
3611 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3614 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3615 SUIT_ViewWindow* wnd;
3616 foreach ( wnd, wndlist )
3618 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3621 aP2d->getViewFrame()->eraseObject(myCurve);
3628 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3630 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3634 \brief updateCurves (repaint) curves in view window.
3636 void SalomePyQt::updateCurves(const int id)
3638 class TEvent: public SALOME_Event
3642 TEvent( const int id ) : myWndId( id ) {}
3643 virtual void Execute()
3645 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3648 wnd->getViewFrame()->DisplayAll();
3652 ProcessVoidEvent( new TEvent(id) );
3656 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3657 \brief Get title of corresponding type
3658 \param id window identifier
3659 \param type is type of title
3660 \return title of corresponding type
3663 class TGetPlot2dTitle: public SALOME_Event
3666 typedef QString TResult;
3670 TGetPlot2dTitle(const int id, ObjectType type) :
3673 virtual void Execute() {
3674 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3677 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3681 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3683 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3688 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3689 \brief Set title of corresponding type
3690 \param id window identifier
3692 \param type is type of title
3696 class TSetPlot2dTitle: public SALOME_Event
3700 Plot2d_Curve* myCurve;
3704 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3709 virtual void Execute() {
3710 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3713 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3717 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3719 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3723 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3724 \brief Get list of Plot2d view ranges
3725 \param id window identifier
3726 \return list of view ranges (XMin, XMax, YMin, YMax)
3729 class TFitRangeByCurves: public SALOME_Event
3732 typedef QList<double> TResult;
3735 TFitRangeByCurves( const int id )
3737 virtual void Execute()
3740 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3743 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3744 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3745 myResult.append(XMin);
3746 myResult.append(XMax);
3747 myResult.append(YMin);
3748 myResult.append(YMax);
3752 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3754 return ProcessEvent( new TFitRangeByCurves( id ) );
3758 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3759 \brief Get list of current Plot2d view ranges
3760 \param id window identifier
3761 \return list of view ranges (XMin, XMax, YMin, YMax)
3764 class TFitRangeCurrent: public SALOME_Event
3767 typedef QList<double> TResult;
3770 TFitRangeCurrent( const int id )
3772 virtual void Execute()
3775 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3778 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3779 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3780 myResult.append(XMin);
3781 myResult.append(XMax);
3782 myResult.append(YMin);
3783 myResult.append(YMax);
3787 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3789 return ProcessEvent( new TFitRangeCurrent( id ) );
3793 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3794 \brief Set range of Plot2d view
3795 \param id window identifier
3802 class TPlot2dFitRange: public SALOME_Event
3810 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3816 virtual void Execute() {
3817 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3820 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3824 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3826 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3830 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3832 class TEvent: public SALOME_Event
3837 TEvent( const QString& theEntry, int theState):
3838 myEntry(theEntry), myState(theState) {}
3839 virtual void Execute()
3841 LightApp_Study* aStudy = getActiveStudy();
3844 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3847 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3850 class TGetVisibilityStateEvent: public SALOME_Event
3853 typedef int TResult;
3856 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3857 virtual void Execute()
3859 LightApp_Study* aStudy = getActiveStudy();
3861 myResult = aStudy->visibilityState(myEntry);
3865 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3867 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3871 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3873 class TEvent: public SALOME_Event
3878 TEvent( const QString& theEntry, int thePos):
3879 myEntry(theEntry), myPos(thePos) {}
3880 virtual void Execute()
3882 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3884 module->setObjectPosition(myEntry, myPos );
3887 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3892 class TGetObjectPositionEvent: public SALOME_Event
3895 typedef int TResult;
3898 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3899 virtual void Execute()
3901 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3903 myResult = module->getObjectPosition(myEntry);
3907 int SalomePyQt::getObjectPosition( const QString& theEntry )
3909 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );
3912 void SalomePyQt::startPyLog(const QString& theFileName)
3914 class TEvent: public SALOME_Event
3918 TEvent( const QString& theFileName ):
3919 myFileName( theFileName ) {}
3920 virtual void Execute()
3922 if ( getApplication() ) {
3923 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3924 if ( pyConsole ) pyConsole->startLog( myFileName );
3928 ProcessVoidEvent( new TEvent( theFileName ) );
3931 void SalomePyQt::stopPyLog()
3933 class TEvent: public SALOME_Event
3937 virtual void Execute()
3939 if ( getApplication() ) {
3940 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3941 if ( pyConsole ) pyConsole->stopLog();
3945 ProcessVoidEvent( new TEvent() );