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"
55 #include <QApplication>
56 #include <QPaintEvent>
59 \brief Get the currently active application.
61 \return active application object or 0 if there is no any
63 static LightApp_Application* getApplication()
65 if ( SUIT_Session::session() )
66 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
71 \brief Get the currently active study.
73 \return active study or 0 if there is no study opened
75 static LightApp_Study* getActiveStudy()
77 if ( getApplication() )
78 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
83 \brief Get the currently active module.
85 This function returns correct result only if Python-based
86 module is currently active. Otherwize, 0 is returned.
88 static LightApp_Module* getActiveModule()
90 LightApp_Module* module = 0;
91 if ( LightApp_Application* anApp = getApplication() ) {
92 module = PyModuleHelper::getInitModule();
94 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
100 \brief Get the currently active Python module's helper.
102 This function returns correct result only if Python-based
103 module is currently active. Otherwize, 0 is returned.
105 static PyModuleHelper* getPythonHelper()
107 LightApp_Module* module = getActiveModule();
108 PyModuleHelper* helper = module ? qFindChild<PyModuleHelper*>( module, "python_module_helper" ) : 0;
113 \brief Get SALOME verbose level
115 \return \c true if SALOME debug output is allowed or \c false otherwise
117 static bool verbose()
119 bool isVerbose = false;
120 if ( getenv( "SALOME_VERBOSE" ) ) {
121 QString envVar = getenv( "SALOME_VERBOSE" );
123 int value = envVar.toInt( &ok );
124 isVerbose = ok && value != 0;
130 \class SALOME_Selection
131 \brief The class represents selection which can be used in Python.
135 \brief Map of created selection objects.
138 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
141 \brief Get the selection object for the specified application.
143 Finds or creates the selection object (one per study).
145 \param app application object
146 \return selection object or 0 if \a app is invalid
148 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
150 SALOME_Selection* sel = 0;
151 if ( app && SelMap.find( app ) != SelMap.end() )
154 sel = SelMap[ app ] = new SALOME_Selection( app );
160 \param p parent object
162 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
164 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
166 mySelMgr = app->selectionMgr();
167 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
168 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
175 SALOME_Selection::~SALOME_Selection()
177 LightApp_Application* app = 0;
178 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
179 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
180 if ( it.value() == this ) app = it.key();
182 if ( app ) SelMap.remove( app );
186 \brief Called when selection manager is destroyed (usually
187 when the study is closed).
189 void SALOME_Selection::onSelMgrDestroyed()
195 \brief Clear the selection.
197 void SALOME_Selection::Clear()
199 class TEvent: public SALOME_Event
201 LightApp_SelectionMgr* mySelMgr;
203 TEvent( LightApp_SelectionMgr* selMgr )
204 : mySelMgr( selMgr ) {}
205 virtual void Execute()
208 mySelMgr->clearSelected();
211 ProcessVoidEvent( new TEvent( mySelMgr ) );
215 \brief Clear the selection.
217 void SALOME_Selection::ClearIObjects()
223 Removes all selection filters.
225 void SALOME_Selection::ClearFilters()
227 class TEvent: public SALOME_Event
229 LightApp_SelectionMgr* mySelMgr;
231 TEvent( LightApp_SelectionMgr* selMgr )
232 : mySelMgr( selMgr ) {}
233 virtual void Execute()
236 mySelMgr->clearFilters();
239 ProcessVoidEvent( new TEvent( mySelMgr ) );
244 \brief The class provides utility functions which can be used in the Python
245 to operate with the SALOME GUI.
247 All the functionality of this class is implemented as static methods, so they
248 can be called with the class name prefixed or via creation of the class instance.
249 For example, next both ways of SalomePyQt class usage are legal:
251 from SalomePyQt import *
253 # using SalomePyQt class instance
254 desktop = sg.getDesktop()
255 # using SalomePyQt class directly
256 menubar = SalomePyQt.getMainMenuBar()
261 \fn QWidget* SalomePyQt::getDesktop();
262 \brief Get the active application's desktop window.
263 \return desktop window or 0 if there is no any
266 class TGetDesktopEvent: public SALOME_Event
269 typedef QWidget* TResult;
271 TGetDesktopEvent() : myResult( 0 ) {}
272 virtual void Execute()
274 if ( getApplication() )
275 myResult = (QWidget*)( getApplication()->desktop() );
278 QWidget* SalomePyQt::getDesktop()
280 return ProcessEvent( new TGetDesktopEvent() );
284 \fn QWidget* SalomePyQt::getMainFrame();
285 \brief Get current application's main frame widget [obsolete].
287 Main frame widget is an internal widget of the application
288 desktop window (workspace).
290 \return workspace widget (0 on any error)
293 class TGetMainFrameEvent: public SALOME_Event
296 typedef QWidget* TResult;
298 TGetMainFrameEvent() : myResult( 0 ) {}
299 virtual void Execute()
301 if ( getApplication() ) {
302 SUIT_Desktop* aDesktop = getApplication()->desktop();
303 myResult = (QWidget*)( aDesktop->centralWidget() );
307 QWidget* SalomePyQt::getMainFrame()
309 return ProcessEvent( new TGetMainFrameEvent() );
313 \fn QMenuBar* SalomePyQt::getMainMenuBar();
314 \brief Get current application desktop's main menu.
315 \return main menu object (0 on any error)
318 class TGetMainMenuBarEvent: public SALOME_Event
321 typedef QMenuBar* TResult;
323 TGetMainMenuBarEvent() : myResult( 0 ) {}
324 virtual void Execute()
326 if ( LightApp_Application* anApp = getApplication() ) {
327 myResult = anApp->desktop()->menuBar();
331 QMenuBar* SalomePyQt::getMainMenuBar()
333 return ProcessEvent( new TGetMainMenuBarEvent() );
337 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
338 \brief Get main menu's child popup submenu by its identifier.
340 This function is obsolete.
341 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
343 \param menu menu identifier
344 \return popup submenu object or 0 if it does not exist
348 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
349 \brief Get main menu's child popup submenu by its name.
351 The function creates menu if it does not exist.
353 \param menu menu name
354 \return popup submenu object (0 on any error)
357 class TGetPopupMenuEvent: public SALOME_Event
360 typedef QMenu* TResult;
363 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
364 virtual void Execute()
366 LightApp_Application* anApp = getApplication();
367 if ( anApp && !myMenuName.isEmpty() ) {
368 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
369 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
375 \brief Get menu item title
377 \param menuId menu identifier
378 \return menu title (localized)
380 static QString getMenuName( const QString& menuId )
382 QStringList contexts;
383 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
384 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
385 QString menuName = menuId;
386 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
387 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
391 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
396 menuName = getMenuName( "MEN_DESK_FILE" ); break;
398 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
400 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
402 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
404 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
406 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
408 menuName = getMenuName( "MEN_DESK_HELP" ); break;
410 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
412 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
414 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
418 \fn QTreeView* SalomePyQt::getObjectBrowser();
419 \brief Get object browser
420 \return object browser for the active study or 0 in case of error
423 class TGetObjectBrowserEvent: public SALOME_Event
426 typedef QTreeView* TResult;
428 TGetObjectBrowserEvent() : myResult( 0 ) {}
429 virtual void Execute()
431 LightApp_Application* anApp = getApplication();
433 myResult = anApp->objectBrowser()->treeView();
437 QTreeView* SalomePyQt::getObjectBrowser()
439 return ProcessEvent( new TGetObjectBrowserEvent() );
443 \fn int SalomePyQt::getStudyId();
444 \brief Get active study's identifier.
445 \return active study ID or 0 if there is no active study
448 class TGetStudyIdEvent: public SALOME_Event
453 TGetStudyIdEvent() : myResult( 0 ) {}
454 virtual void Execute()
456 if ( LightApp_Study* aStudy = getActiveStudy() ) {
457 myResult = aStudy->id();
461 int SalomePyQt::getStudyId()
463 return ProcessEvent( new TGetStudyIdEvent() );
467 \fn SALOME_Selection* SalomePyQt::getSelection();
468 \brief Get the selection object for the current study.
470 Creates a Selection object if it has not been created yet.
472 \return selection object (0 on error)
475 class TGetSelectionEvent: public SALOME_Event
478 typedef SALOME_Selection* TResult;
480 TGetSelectionEvent() : myResult( 0 ) {}
481 virtual void Execute()
483 myResult = SALOME_Selection::GetSelection( getApplication() );
486 SALOME_Selection* SalomePyQt::getSelection()
488 return ProcessEvent( new TGetSelectionEvent() );
492 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
493 \brief Put an information message to the current application's
496 Optional second delay parameter (\a sec) can be used to specify
497 time of the message diplaying in seconds. If this parameter is less
498 or equal to zero, the constant message will be put.
500 \param msg message text
501 \param sec message displaying time in seconds
504 class TPutInfoEvent: public SALOME_Event
509 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
510 virtual void Execute()
512 if ( LightApp_Application* anApp = getApplication() ) {
513 anApp->putInfo( myMsg, mySecs * 1000 );
517 void SalomePyQt::putInfo( const QString& msg, const int sec )
519 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
523 \fn const QString SalomePyQt::getActiveComponent();
524 \brief Get the currently active module name (for the current study).
525 \return active module name or empty string if there is no active module
528 class TGetActiveComponentEvent: public SALOME_Event
531 typedef QString TResult;
533 TGetActiveComponentEvent() {}
534 virtual void Execute()
536 if ( LightApp_Application* anApp = getApplication() ) {
537 if ( CAM_Module* mod = anApp->activeModule() ) {
538 myResult = mod->name();
543 const QString SalomePyQt::getActiveComponent()
545 return ProcessEvent( new TGetActiveComponentEvent() );
549 \fn PyObject* SalomePyQt::getActivePythonModule();
550 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
551 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
554 class TGetActivePyModuleEvent: public SALOME_Event
557 typedef PyObject* TResult;
559 TGetActivePyModuleEvent() : myResult( Py_None ) {}
560 virtual void Execute()
562 PyModuleHelper* helper = getPythonHelper();
564 myResult = (PyObject*)helper->pythonModule();
567 PyObject* SalomePyQt::getActivePythonModule()
569 return ProcessEvent( new TGetActivePyModuleEvent() );
573 \fn bool SalomePyQt::activateModule( const QString& modName );
574 \brief Activates SALOME module with the given name
575 \return True if the module has been activated and False otherwise.
578 class TActivateModuleEvent: public SALOME_Event
581 typedef bool TResult;
583 QString myModuleName;
584 TActivateModuleEvent( const QString& modName )
585 : myResult( false ), myModuleName( modName ) {}
586 virtual void Execute()
588 if ( LightApp_Application* anApp = getApplication() ) {
589 myResult = anApp->activateModule( myModuleName );
593 bool SalomePyQt::activateModule( const QString& modName )
595 return ProcessEvent( new TActivateModuleEvent( modName ) );
599 \brief Update an Object Browser of the specified (by identifier) study.
601 If \a studyId <= 0 the active study's object browser is updated.
602 The \a updateSelection parameter is obsolete and currently is not used.
603 This parameter will be removed in future, so try to avoid its usage in
606 \brief studyId study identifier
607 \brief updateSelection update selection flag (not used)
610 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
612 class TEvent: public SALOME_Event
615 bool myUpdateSelection;
617 TEvent( const int studyId, bool updateSelection )
618 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
619 virtual void Execute()
621 if ( SUIT_Session::session() ) {
622 if ( getActiveStudy() && myStudyId <= 0 )
623 myStudyId = getActiveStudy()->id();
624 if ( myStudyId > 0 ) {
625 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
626 QList<SUIT_Application*>::Iterator it;
627 for( it = apps.begin(); it != apps.end(); ++it ) {
628 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
629 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
630 anApp->updateObjectBrowser();
638 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
643 SalomePyQt::isModified()
644 \return The modification status of the data model
645 for the currently active Python module
646 \note This function is supported for "light" Python-based SALOME modules only.
649 class TIsModifiedEvent: public SALOME_Event
652 typedef bool TResult;
654 TIsModifiedEvent() : myResult( false ) {}
655 virtual void Execute()
657 LightApp_Module* module = getActiveModule();
661 SALOME_PYQT_DataModelLight* aModel =
662 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
664 myResult = aModel->isModified();
667 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
671 bool SalomePyQt::isModified()
673 return ProcessEvent(new TIsModifiedEvent());
677 SalomePyQt::setModified()
679 Sets the modification status of the data model for
680 the currently active Python module. This method should be used
681 by the Python code in order to enable/disable "Save" operation
682 depending on the module's data state.
684 \note This function is supported for "light" Python-based SALOME modules only.
686 \param New modification status of the data model
690 void SalomePyQt::setModified( bool flag )
692 class TEvent: public SALOME_Event
698 virtual void Execute()
700 LightApp_Module* module = getActiveModule();
704 SALOME_PYQT_DataModelLight* model =
705 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
707 LightApp_Application* app = module->getApp();
709 if ( model && app ) {
710 model->setModified( myFlag );
711 app->updateActions();
714 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
718 ProcessVoidEvent( new TEvent( flag ) );
722 \brief Default resource file section name.
725 static const char* DEFAULT_SECTION = "SalomePyQt";
728 \brief Add string setting to the application preferences.
730 The parameter \a autoValue is obsolete parameter and currently is not used.
731 This parameter will be removed in future, so try to avoid its usage in
734 This function is obsolete. Use one of addSetting() instead.
736 \param name setting name (it should be of kind <section:setting> where
737 \c section is resources section name and \c setting is setting name)
738 \param value new setting value
739 \param autoValue (not used)
741 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
743 class TEvent: public SALOME_Event
749 TEvent( const QString& name, const QString& value, bool autoValue )
750 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
751 virtual void Execute()
753 if ( SUIT_Session::session() ) {
754 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
755 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
756 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
757 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
758 if ( !_sec.isEmpty() && !_nam.isEmpty() )
759 resMgr->setValue( _sec, _nam, myValue );
763 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
767 \brief Add integer setting to the application preferences.
769 The parameter \a autoValue is obsolete parameter and currently is not used.
770 This parameter will be removed in future, so try to avoid its usage in
773 This function is obsolete. Use one of addSetting() instead.
775 \param name setting name (it should be of kind <section:setting> where
776 \c section is resources section name and \c setting is setting name)
777 \param value new setting value
778 \param autoValue (not used)
780 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
782 class TEvent: public SALOME_Event
788 TEvent( const QString& name, const int value, bool autoValue )
789 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
790 virtual void Execute()
792 if ( SUIT_Session::session() ) {
793 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
794 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
795 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
796 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
797 if ( !_sec.isEmpty() && !_nam.isEmpty() )
798 resMgr->setValue( _sec, _nam, myValue );
802 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
806 \brief Add double setting to the application preferences.
808 The parameter \a autoValue is obsolete parameter and currently is not used.
809 This parameter will be removed in future, so try to avoid its usage in
812 This function is obsolete. Use one of addSetting() instead.
814 \param name setting name (it should be of kind <section:setting> where
815 \c section is resources section name and \c setting is setting name)
816 \param value new setting value
817 \param autoValue (not used)
819 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
821 class TEvent: public SALOME_Event
827 TEvent( const QString& name, const double value, bool autoValue )
828 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
829 virtual void Execute()
831 if ( SUIT_Session::session() ) {
832 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
833 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
834 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
835 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
836 if ( !_sec.isEmpty() && !_nam.isEmpty() )
837 resMgr->setValue( _sec, _nam, myValue );
841 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
845 \brief Add boolean setting to the application preferences.
847 The parameter \a autoValue is obsolete parameter and currently is not used.
848 This parameter will be removed in future, so try to avoid its usage in
851 This function is obsolete. Use one of addSetting() instead.
853 \param name setting name (it should be of kind <section:setting> where
854 \c section is resources section name and \c setting is setting name)
855 \param value new setting value
856 \param autoValue (not used)
858 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
860 class TEvent: public SALOME_Event
866 TEvent( const QString& name, const bool value, bool autoValue )
867 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
868 virtual void Execute()
870 if ( SUIT_Session::session() ) {
871 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
872 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
873 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
874 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
875 if ( !_sec.isEmpty() && !_nam.isEmpty() )
876 resMgr->setValue( _sec, _nam, myValue );
880 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
884 \brief Remove setting from the application preferences.
886 This function is obsolete. Use removeSetting() instead.
888 \param name setting name (it should be of kind <section:setting> where
889 \c section is resources section name and \c setting is setting name)
891 void SalomePyQt::removeSettings( const QString& name )
893 class TEvent: public SALOME_Event
897 TEvent( const QString& name ) : myName( name ) {}
898 virtual void Execute()
900 if ( SUIT_Session::session() ) {
901 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
902 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
903 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
904 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
905 if ( !_sec.isEmpty() && !_nam.isEmpty() )
906 resMgr->remove( _sec, _nam );
910 ProcessVoidEvent( new TEvent( name ) );
914 \fn QString SalomePyQt::getSetting( const QString& name );
915 \brief Get application setting value (as string represenation).
917 This function is obsolete. Use stringSetting(), integerSetting(),
918 boolSetting(), stringSetting() or colorSetting() instead.
920 \param name setting name (it should be of kind <section:setting> where
921 \c section is resources section name and \c setting is setting name)
922 \return setting name (empty string if setting name is invalid)
925 class TGetSettingEvent: public SALOME_Event
928 typedef QString TResult;
931 TGetSettingEvent( const QString& name ) : myName( name ) {}
932 virtual void Execute()
934 if ( SUIT_Session::session() ) {
935 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
936 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
937 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
938 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
939 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
943 QString SalomePyQt::getSetting( const QString& name )
945 return ProcessEvent( new TGetSettingEvent( name ) );
949 \brief Add double setting to the application preferences.
950 \param section resources file section name
951 \param name setting name
952 \param value new setting value
954 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
956 class TEvent: public SALOME_Event
962 TEvent( const QString& section, const QString& name, double value )
963 : mySection( section ), myName( name ), myValue( value ) {}
964 virtual void Execute()
966 if ( SUIT_Session::session() ) {
967 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
968 if ( !mySection.isEmpty() && !myName.isEmpty() )
969 resMgr->setValue( mySection, myName, myValue );
973 ProcessVoidEvent( new TEvent( section, name, value ) );
977 \brief Add integer setting to the application preferences.
978 \param section resources file section name
979 \param name setting name
980 \param value new setting value
982 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
984 class TEvent: public SALOME_Event
990 TEvent( const QString& section, const QString& name, int value )
991 : mySection( section ), myName( name ), myValue( value ) {}
992 virtual void Execute()
994 if ( SUIT_Session::session() ) {
995 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
996 if ( !mySection.isEmpty() && !myName.isEmpty() )
997 resMgr->setValue( mySection, myName, myValue );
1001 ProcessVoidEvent( new TEvent( section, name, value ) );
1005 \brief Add boolean setting to the application preferences.
1006 \param section resources file section name
1007 \param name setting name
1008 \param value new setting value
1009 \param dumb this parameter is used in order to avoid sip compilation error
1010 because of conflicting int and bool types
1012 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1014 class TEvent: public SALOME_Event
1020 TEvent( const QString& section, const QString& name, bool value )
1021 : mySection( section ), myName( name ), myValue( value ) {}
1022 virtual void Execute()
1024 if ( SUIT_Session::session() ) {
1025 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1026 if ( !mySection.isEmpty() && !myName.isEmpty() )
1027 resMgr->setValue( mySection, myName, myValue );
1031 ProcessVoidEvent( new TEvent( section, name, value ) );
1035 \brief Add string setting to the application preferences.
1036 \param section resources file section name
1037 \param name setting name
1038 \param value new setting value
1040 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1042 class TEvent: public SALOME_Event
1048 TEvent( const QString& section, const QString& name, const QString& value )
1049 : mySection( section ), myName( name ), myValue( value ) {}
1050 virtual void Execute()
1052 if ( SUIT_Session::session() ) {
1053 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1054 if ( !mySection.isEmpty() && !myName.isEmpty() )
1055 resMgr->setValue( mySection, myName, myValue );
1059 ProcessVoidEvent( new TEvent( section, name, value ) );
1063 \brief Add color setting to the application preferences.
1064 \param section resources file section name
1065 \param name setting name
1066 \param value new setting value
1068 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1070 class TEvent: public SALOME_Event
1076 TEvent( const QString& section, const QString& name, const QColor& value )
1077 : mySection( section ), myName( name ), myValue( value ) {}
1078 virtual void Execute()
1080 if ( SUIT_Session::session() ) {
1081 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1082 if ( !mySection.isEmpty() && !myName.isEmpty() )
1083 resMgr->setValue( mySection, myName, myValue );
1087 ProcessVoidEvent( new TEvent( section, name, value ) );
1091 \fn int SalomePyQt::integerSetting( const QString& section,
1092 const QString& name,
1094 \brief Get integer setting from the application preferences.
1095 \param section resources file section name
1096 \param name setting name
1097 \param def default value which is returned if the setting is not found
1098 \return setting value
1101 class TGetIntSettingEvent: public SALOME_Event
1104 typedef int TResult;
1109 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1110 : mySection( section ), myName( name ), myDefault( def ) {}
1111 virtual void Execute()
1113 if ( SUIT_Session::session() ) {
1114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1115 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1119 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1121 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1125 \fn double SalomePyQt::doubleSetting( const QString& section,
1126 const QString& name,
1128 \brief Get double setting from the application preferences.
1129 \param section resources file section name
1130 \param name setting name
1131 \param def default value which is returned if the setting is not found
1132 \return setting value
1135 class TGetDblSettingEvent: public SALOME_Event
1138 typedef double TResult;
1143 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1144 : mySection( section ), myName( name ), myDefault( def ) {}
1145 virtual void Execute()
1147 if ( SUIT_Session::session() ) {
1148 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1149 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1153 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1155 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1159 \fn bool SalomePyQt::boolSetting( const QString& section,
1160 const QString& name,
1162 \brief Get boolean setting from the application preferences.
1163 \param section resources file section name
1164 \param name setting name
1165 \param def default value which is returned if the setting is not found
1166 \return setting value
1169 class TGetBoolSettingEvent: public SALOME_Event
1172 typedef bool TResult;
1177 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1178 : mySection( section ), myName( name ), myDefault( def ) {}
1179 virtual void Execute()
1181 if ( SUIT_Session::session() ) {
1182 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1183 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1187 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1189 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1193 \fn QString SalomePyQt::stringSetting( const QString& section,
1194 const QString& name,
1195 const QString& def );
1196 \brief Get string setting from the application preferences.
1197 \param section resources file section name
1198 \param name setting name
1199 \param def default value which is returned if the setting is not found
1200 \return setting value
1203 class TGetStrSettingEvent: public SALOME_Event
1206 typedef QString TResult;
1211 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1212 : mySection( section ), myName( name ), myDefault( def ) {}
1213 virtual void Execute()
1215 if ( SUIT_Session::session() ) {
1216 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1217 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1221 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1223 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1227 \fn QColor SalomePyQt::colorSetting( const QString& section,
1228 const QString& name,
1230 \brief Get color setting from the application preferences.
1231 \param section resources file section name
1232 \param name setting name
1233 \param def default value which is returned if the setting is not found
1234 \return setting value
1237 class TGetColorSettingEvent: public SALOME_Event
1240 typedef QColor TResult;
1245 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1246 : mySection( section ), myName( name ), myDefault( def ) {}
1247 virtual void Execute()
1249 if ( SUIT_Session::session() ) {
1250 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1251 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1255 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1257 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1261 \brief Remove setting from the application preferences.
1262 \param section resources file section name
1263 \param name setting name
1265 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1267 class TEvent: public SALOME_Event
1272 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1273 virtual void Execute()
1275 if ( SUIT_Session::session() ) {
1276 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1277 if ( !mySection.isEmpty() && !myName.isEmpty() )
1278 resMgr->remove( mySection, myName );
1282 ProcessVoidEvent( new TEvent( section, name ) );
1286 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1287 \brief Check setting existence in the application preferences.
1288 \param section resources file section name
1289 \param name setting name
1290 \return \c true if setting exists
1293 class THasColorSettingEvent: public SALOME_Event
1296 typedef bool TResult;
1300 THasColorSettingEvent( const QString& section, const QString& name )
1301 : mySection( section ), myName( name ) {}
1302 virtual void Execute()
1304 if ( SUIT_Session::session() ) {
1305 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1306 myResult = resMgr->hasValue( mySection, myName );
1310 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1312 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1316 \fn QString SalomePyQt::getFileName( QWidget* parent,
1317 const QString& initial,
1318 const QStringList& filters,
1319 const QString& caption,
1321 \brief Show 'Open/Save file' dialog box for file selection
1322 and return a user's choice (selected file name).
1323 \param parent parent widget
1324 \param initial initial directory the dialog box to be opened in
1325 \param filters list of files filters (wildcards)
1326 \param caption dialog box title
1327 \param open if \c true, "Open File" dialog box is shown;
1328 otherwise "Save File" dialog box is shown
1329 \return selected file name (null string if user cancels operation)
1332 class TGetFileNameEvent: public SALOME_Event
1335 typedef QString TResult;
1339 QStringList myFilters;
1342 TGetFileNameEvent( QWidget* parent,
1343 const QString& initial,
1344 const QStringList& filters,
1345 const QString& caption,
1347 : myParent ( parent ),
1348 myInitial( initial ),
1349 myFilters( filters ),
1350 myCaption( caption ),
1352 virtual void Execute()
1354 if ( LightApp_Application* anApp = getApplication() ) {
1355 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1356 myCaption, myParent );
1360 QString SalomePyQt::getFileName( QWidget* parent,
1361 const QString& initial,
1362 const QStringList& filters,
1363 const QString& caption,
1366 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1370 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1371 const QString& initial,
1372 const QStringList& filters,
1373 const QString& caption );
1374 \brief Show 'Open files' dialog box for multiple files selection
1375 and return a user's choice (selected file names list).
1376 \param parent parent widget
1377 \param initial initial directory the dialog box to be opened in
1378 \param filters list of files filters (wildcards)
1379 \param caption dialog box title
1380 \return selected file names list (empty list if user cancels operation)
1383 class TGetOpenFileNamesEvent: public SALOME_Event
1386 typedef QStringList TResult;
1390 QStringList myFilters;
1392 TGetOpenFileNamesEvent( QWidget* parent,
1393 const QString& initial,
1394 const QStringList& filters,
1395 const QString& caption )
1396 : myParent ( parent ),
1397 myInitial( initial ),
1398 myFilters( filters ),
1399 myCaption( caption ) {}
1400 virtual void Execute()
1402 if ( LightApp_Application* anApp = getApplication() ) {
1403 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1407 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1408 const QString& initial,
1409 const QStringList& filters,
1410 const QString& caption )
1412 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1416 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1417 const QString& initial,
1418 const QString& caption );
1419 \brief Show 'Get Directory' dialog box for the directory selection
1420 and return a user's choice (selected directory name).
1421 \param parent parent widget
1422 \param initial initial directory the dialog box to be opened in
1423 \param caption dialog box title
1424 \return selected directory name (null string if user cancels operation)
1427 class TGetExistingDirectoryEvent: public SALOME_Event
1430 typedef QString TResult;
1435 TGetExistingDirectoryEvent( QWidget* parent,
1436 const QString& initial,
1437 const QString& caption )
1438 : myParent ( parent ),
1439 myInitial( initial ),
1440 myCaption( caption ) {}
1441 virtual void Execute()
1443 if ( LightApp_Application* anApp = getApplication() ) {
1444 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1448 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1449 const QString& initial,
1450 const QString& caption )
1452 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1456 \fn QString SalomePyQt::loadIcon( const QString& filename );
1457 \brief Load an icon from the module resources by the specified file name.
1458 \param fileName icon file name
1462 static QIcon loadIconInternal( const QString& module, const QString& fileName )
1466 LightApp_Application* app = getApplication();
1468 if ( app && !fileName.isEmpty() ) {
1469 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
1470 QApplication::translate( module.toLatin1().data(),
1471 fileName.toLatin1().data() ) );
1472 if ( !pixmap.isNull() )
1473 icon = QIcon( pixmap );
1478 class TLoadIconEvent: public SALOME_Event
1481 typedef QIcon TResult;
1485 TLoadIconEvent( const QString& module, const QString& filename )
1486 : myModule( module ),
1487 myFileName ( filename ) {}
1488 virtual void Execute()
1490 myResult = loadIconInternal( myModule, myFileName );
1493 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1495 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1499 \brief Open external browser to display context help information.
1502 Current implementation does nothing.
1504 \param source documentation (HTML) file name
1505 \param context context (for example, HTML ancor name)
1507 void SalomePyQt::helpContext( const QString& source, const QString& context )
1509 class TEvent: public SALOME_Event
1514 TEvent( const QString& source, const QString& context )
1515 : mySource( source ), myContext( context ) {}
1516 virtual void Execute()
1518 if ( LightApp_Application* anApp = getApplication() ) {
1519 anApp->onHelpContextModule( "", mySource, myContext );
1523 ProcessVoidEvent( new TEvent( source, context ) );
1527 \fn int SalomePyQt::defaultMenuGroup();
1528 \brief Get detault menu group identifier which can be used when
1529 creating menus (insert custom menu commands).
1530 \return default menu group ID
1533 class TDefMenuGroupEvent: public SALOME_Event
1536 typedef int TResult;
1538 TDefMenuGroupEvent() : myResult( -1 ) {}
1539 virtual void Execute()
1541 myResult = PyModuleHelper::defaultMenuGroup();
1544 int SalomePyQt::defaultMenuGroup()
1546 return ProcessEvent( new TDefMenuGroupEvent() );
1552 CrTool( const QString& tBar, const QString& nBar )
1553 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1554 CrTool( const int id, const int tBar, const int idx )
1555 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1556 CrTool( const int id, const QString& tBar, const int idx )
1557 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1558 CrTool( QAction* action, const int tbId, const int id, const int idx )
1559 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1560 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1561 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1563 int execute( LightApp_Module* module ) const
1568 return module->createTool( myTbTitle, myTbName );
1570 return module->createTool( myId, myTbId, myIndex );
1572 return module->createTool( myId, myTbTitle, myIndex );
1574 return module->createTool( myAction, myTbId, myId, myIndex );
1576 return module->createTool( myAction, myTbTitle, myId, myIndex );
1591 class TCreateToolEvent: public SALOME_Event
1594 typedef int TResult;
1596 const CrTool& myCrTool;
1597 TCreateToolEvent( const CrTool& crTool )
1598 : myResult( -1 ), myCrTool( crTool ) {}
1599 virtual void Execute()
1601 LightApp_Module* module = getActiveModule();
1603 myResult = myCrTool.execute( module );
1608 \brief Create toolbar with specified name.
1609 \param tBar toolbar title (language-dependent)
1610 \param nBar toolbar name (language-independent) [optional]
1611 \return toolbar ID or -1 if toolbar creation is failed
1613 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1615 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1619 \brief Insert action with specified \a id to the toolbar.
1621 \param tBar toolbar ID
1622 \param idx required index in the toolbar
1623 \return action ID or -1 if action could not be added
1625 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1627 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1631 \brief Insert action with specified \a id to the toolbar.
1633 \param tBar toolbar name
1634 \param idx required index in the toolbar
1635 \return action ID or -1 if action could not be added
1637 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1639 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1643 \brief Insert action to the toolbar.
1645 \param tBar toolbar ID
1646 \param id required action ID
1647 \param idx required index in the toolbar
1648 \return action ID or -1 if action could not be added
1650 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1652 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1656 \brief Insert action to the toolbar.
1658 \param tBar toolbar name
1659 \param id required action ID
1660 \param idx required index in the toolbar
1661 \return action ID or -1 if action could not be added
1663 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1665 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1671 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1672 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1673 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1674 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1675 CrMenu( const int id, const int menu, const int group, const int idx )
1676 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1677 CrMenu( const int id, const QString& menu, const int group, const int idx )
1678 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1679 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1680 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1681 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1682 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1684 int execute( LightApp_Module* module ) const
1689 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1691 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1693 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1695 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1697 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1699 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1708 QString mySubMenuName;
1715 class TCreateMenuEvent: public SALOME_Event
1718 typedef int TResult;
1720 const CrMenu& myCrMenu;
1721 TCreateMenuEvent( const CrMenu& crMenu )
1722 : myResult( -1 ), myCrMenu( crMenu ) {}
1723 virtual void Execute()
1725 LightApp_Module* module = getActiveModule();
1727 myResult = myCrMenu.execute( module );
1732 \brief Create main menu.
1733 \param subMenu menu name
1734 \param menu parent menu ID
1735 \param id required menu ID
1736 \param group menu group ID
1737 \param idx required index in the menu
1738 \return menu ID or -1 if menu could not be added
1740 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1742 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1746 \brief Create main menu.
1747 \param subMenu menu name
1748 \param menu parent menu name (list of menu names separated by "|")
1749 \param id required menu ID
1750 \param group menu group ID
1751 \param idx required index in the menu
1752 \return menu ID or -1 if menu could not be added
1754 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1756 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1760 \brief Insert action to the main menu.
1762 \param menu parent menu ID
1763 \param group menu group ID
1764 \param idx required index in the menu
1765 \return action ID or -1 if action could not be added
1767 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1769 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1773 \brief Insert action to the main menu.
1775 \param menu parent menu name (list of menu names separated by "|")
1776 \param group menu group ID
1777 \param idx required index in the menu
1778 \return action ID or -1 if action could not be added
1780 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1782 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1786 \brief Insert action to the main menu.
1788 \param menu parent menu ID
1789 \param group menu group ID
1790 \param idx required index in the menu
1791 \return action ID or -1 if action could not be added
1793 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1795 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1799 \brief Insert action to the main menu.
1801 \param menu parent menu name (list of menu names separated by "|")
1802 \param group menu group ID
1803 \param idx required index in the menu
1804 \return action ID or -1 if action could not be added
1806 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1808 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1812 \fn QAction* SalomePyQt::createSeparator();
1813 \brief Create separator action which can be used in the menu or toolbar.
1814 \return new separator action
1817 class TCreateSepEvent: public SALOME_Event
1820 typedef QAction* TResult;
1824 virtual void Execute()
1826 LightApp_Module* module = getActiveModule();
1828 myResult = (QAction*)module->separator();
1831 QAction* SalomePyQt::createSeparator()
1833 return ProcessEvent( new TCreateSepEvent() );
1837 \fn QAction* SalomePyQt::createAction( const int id,
1838 const QString& menuText,
1839 const QString& tipText,
1840 const QString& statusText,
1841 const QString& icon,
1843 const bool toggle );
1844 \brief Create an action which can be then used in the menu or toolbar.
1845 \param id the unique id action to be registered to
1846 \param menuText action text which should appear in menu
1847 \param tipText text which should appear in the tooltip
1848 \param statusText text which should appear in the status bar when action is activated
1849 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1850 \param key the key accelrator for the action
1851 \param toggle if \c true the action is checkable
1854 class TCreateActionEvent: public SALOME_Event
1857 typedef QAction* TResult;
1862 QString myStatusText;
1866 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1867 const QString& statusText, const QString& icon, const int key, const bool toggle )
1868 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1869 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1870 virtual void Execute()
1872 LightApp_Module* module = getActiveModule();
1874 QIcon icon = loadIconInternal( module->name(), myIcon );
1875 myResult = (QAction*)module->action( myId );
1877 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1878 myResult->setToolTip( myTipText );
1879 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1880 myResult->setText( myMenuText );
1881 if ( myResult->icon().isNull() && !icon.isNull() )
1882 myResult->setIcon( icon );
1883 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1884 myResult->setStatusTip( myStatusText );
1885 if ( myResult->shortcut().isEmpty() && myKey )
1886 myResult->setShortcut( myKey );
1887 if ( myResult->isCheckable() != myToggle )
1888 myResult->setCheckable( myToggle );
1891 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1893 // for Python module, automatically connect action to callback slot
1894 PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1895 if ( helper ) helper->connectAction( myResult );
1899 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1900 const QString& tipText, const QString& statusText,
1901 const QString& icon, const int key, const bool toggle )
1903 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1907 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1908 \brief Create an action group which can be then used in the menu or toolbar
1909 \param id : the unique id action group to be registered to
1910 \param exclusive : if \c true the action group does exclusive toggling
1913 struct TCreateActionGroupEvent: public SALOME_Event
1915 typedef QtxActionGroup* TResult;
1919 TCreateActionGroupEvent( const int id, const bool exclusive )
1920 : myId( id ), myExclusive( exclusive ) {}
1921 virtual void Execute()
1923 LightApp_Module* module = getActiveModule();
1925 myResult = module->createActionGroup( myId, myExclusive );
1928 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1930 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1934 \fn QAction* SalomePyQt::action( const int id );
1935 \brief Get action by specified identifier.
1936 \return action or 0 if action is not registered
1939 class TActionEvent: public SALOME_Event
1942 typedef QAction* TResult;
1945 TActionEvent( const int id )
1946 : myResult( 0 ), myId( id ) {}
1947 virtual void Execute()
1949 LightApp_Module* module = getActiveModule();
1951 myResult = (QAction*)module->action( myId );
1954 QAction* SalomePyQt::action( const int id )
1956 return ProcessEvent( new TActionEvent( id ) );
1960 \fn int SalomePyQt::actionId( const QAction* a );
1961 \brief Get an action identifier.
1962 \return action ID or -1 if action is not registered
1965 class TActionIdEvent: public SALOME_Event
1968 typedef int TResult;
1970 const QAction* myAction;
1971 TActionIdEvent( const QAction* action )
1972 : myResult( -1 ), myAction( action ) {}
1973 virtual void Execute()
1975 LightApp_Module* module = getActiveModule();
1977 myResult = module->actionId( myAction );
1980 int SalomePyQt::actionId( const QAction* a )
1982 return ProcessEvent( new TActionIdEvent( a ) );
1986 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1987 \brief Add global (not module-related) preferences group.
1988 \param label global preferences group name
1989 \return preferences group identifier
1992 class TAddGlobalPrefEvent: public SALOME_Event
1995 typedef int TResult;
1998 TAddGlobalPrefEvent( const QString& label )
1999 : myResult( -1 ), myLabel( label ) {}
2000 virtual void Execute()
2002 LightApp_Module* module = getActiveModule();
2004 LightApp_Preferences* pref = module->getApp()->preferences();
2006 myResult = pref->addPreference( myLabel, -1 );
2010 int SalomePyQt::addGlobalPreference( const QString& label )
2012 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2016 \fn int SalomePyQt::addPreference( const QString& label );
2017 \brief Add module-related preferences group.
2018 \param label preferences group name
2019 \return preferences group identifier
2022 class TAddPrefEvent: public SALOME_Event
2025 typedef int TResult;
2028 TAddPrefEvent( const QString& label )
2029 : myResult( -1 ), myLabel( label ) {}
2030 virtual void Execute()
2032 LightApp_Module* module = getActiveModule();
2034 LightApp_Preferences* pref = module->getApp()->preferences();
2036 int cId = pref->addPreference( module->moduleName(), -1 );
2038 myResult = pref->addPreference( myLabel, cId );
2043 int SalomePyQt::addPreference( const QString& label )
2045 return ProcessEvent( new TAddPrefEvent( label ) );
2049 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2050 const QString& section, const QString& param );
2051 \brief Add module-related preferences.
2052 \param label preferences group name
2053 \param pId parent preferences group id
2054 \param type preferences type
2055 \param section resources file section name
2056 \param param resources file setting name
2057 \return preferences identifier
2060 class TAddPrefParamEvent: public SALOME_Event
2063 typedef int TResult;
2070 TAddPrefParamEvent( const QString& label,
2071 const int pId, const int type,
2072 const QString& section,
2073 const QString& param )
2075 myLabel( label ), myPId( pId ), myType( type ),
2076 mySection( section ), myParam ( param ) {}
2077 virtual void Execute()
2079 LightApp_Module* module = getActiveModule();
2081 LightApp_Preferences* pref = module->getApp()->preferences();
2083 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2087 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2088 const QString& section, const QString& param )
2090 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2094 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2095 \brief Get the preferences property.
2096 \param id preferences identifier
2097 \param prop preferences property name
2098 \return preferences property value or null QVariant if property is not set
2101 class TPrefPropEvent: public SALOME_Event
2104 typedef QVariant TResult;
2108 TPrefPropEvent( const int id, const QString& prop )
2109 : myId( id ), myProp( prop ) {}
2110 virtual void Execute()
2112 LightApp_Module* module = getActiveModule();
2114 LightApp_Preferences* pref = module->getApp()->preferences();
2116 myResult = pref->itemProperty( myProp, myId );
2120 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2122 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2126 \brief Set the preferences property.
2127 \param id preferences identifier
2128 \param prop preferences property name
2129 \param var preferences property value
2131 void SalomePyQt::setPreferenceProperty( const int id,
2132 const QString& prop,
2133 const QVariant& var )
2135 class TEvent: public SALOME_Event
2141 TEvent( const int id, const QString& prop, const QVariant& var )
2142 : myId( id ), myProp( prop ), myVar( var ) {}
2143 virtual void Execute()
2145 LightApp_Module* module = getActiveModule();
2147 LightApp_Preferences* pref = module->getApp()->preferences();
2149 pref->setItemProperty( myProp, myVar, myId );
2153 ProcessVoidEvent( new TEvent( id, prop, var) );
2157 \brief Add the property value to the list of values.
2159 This method allows creating properties which are QList<QVariant>
2160 - there is no way to pass such values directly to QVariant parameter with PyQt.
2162 \param id preferences identifier
2163 \param prop preferences property name
2164 \param idx preferences property index
2165 \param var preferences property value for the index \a idx
2167 void SalomePyQt::addPreferenceProperty( const int id,
2168 const QString& prop,
2170 const QVariant& var )
2172 class TEvent: public SALOME_Event
2179 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2180 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2181 virtual void Execute()
2183 LightApp_Module* module = getActiveModule();
2185 LightApp_Preferences* pref = module->getApp()->preferences();
2187 QVariant var = pref->itemProperty( myProp, myId );
2188 if ( var.isValid() ) {
2189 if ( var.type() == QVariant::StringList ) {
2190 QStringList sl = var.toStringList();
2191 if ( myIdx >= 0 && myIdx < sl.count() )
2192 sl[myIdx] = myVar.toString();
2194 sl.append( myVar.toString() );
2195 pref->setItemProperty( myProp, sl, myId );
2197 else if ( var.type() == QVariant::List ) {
2198 QList<QVariant> vl = var.toList();
2199 if ( myIdx >= 0 && myIdx < vl.count() )
2203 pref->setItemProperty( myProp, vl, myId );
2209 pref->setItemProperty( myProp, vl, myId );
2215 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2219 \brief Put the message to the Log messages output window
2220 \param msg message text (it can be of simple rich text format)
2221 \param addSeparator boolean flag which specifies if it is necessary
2222 to separate the message with predefined separator
2224 void SalomePyQt::message( const QString& msg, bool addSeparator )
2226 class TEvent: public SALOME_Event
2231 TEvent( const QString& msg, bool addSeparator )
2232 : myMsg( msg ), myAddSep( addSeparator ) {}
2233 virtual void Execute()
2235 if ( LightApp_Application* anApp = getApplication() ) {
2236 LogWindow* lw = anApp->logWindow();
2238 lw->putMessage( myMsg, myAddSep );
2242 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2246 \brief Remove all the messages from the Log messages output window.
2248 void SalomePyQt::clearMessages()
2250 class TEvent: public SALOME_Event
2254 virtual void Execute()
2256 if ( LightApp_Application* anApp = getApplication() ) {
2257 LogWindow* lw = anApp->logWindow();
2263 ProcessVoidEvent( new TEvent() );
2267 \brief Gets window with specified identifier
2269 \param id window identifier
2270 \return pointer on the window
2272 static SUIT_ViewWindow* getWnd( const int id )
2274 SUIT_ViewWindow* resWnd = 0;
2276 LightApp_Application* app = getApplication();
2279 ViewManagerList vmlist = app->viewManagers();
2280 foreach( SUIT_ViewManager* vm, vmlist )
2282 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2283 foreach ( SUIT_ViewWindow* vw, vwlist )
2285 if ( id == vw->getId() )
2298 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2299 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2300 to the image file in the specified format.
2302 For the current moment JPEG, PNG and BMP images formats are supported.
2303 The image format is defined automatically by the file name extension.
2304 By default, BMP format is used.
2306 \param filename image file name
2307 \return operation status (\c true on success)
2310 class TDumpViewEvent: public SALOME_Event
2313 typedef bool TResult;
2317 TDumpViewEvent( const QString& filename, const int id )
2318 : myResult ( false ), myFileName( filename ), myWndId(id) {}
2319 virtual void Execute()
2321 SUIT_ViewWindow* wnd = NULL;
2324 if ( LightApp_Application* anApp = getApplication() ) {
2325 SUIT_ViewManager* vm = anApp->activeViewManager();
2327 wnd = vm->getActiveView();
2329 myWndId = wnd->getId();
2333 wnd = dynamic_cast<SUIT_ViewWindow*>(getWnd( myWndId ));
2336 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2337 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2338 if(fmt == "PS" || fmt == "EPS" || fmt == "PDF") {
2340 myResult = wnd2D->getViewFrame()->print(myFileName, fmt);
2346 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2347 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2348 qApp->processEvents();
2350 QImage im = wnd->dumpView();
2351 if ( !im.isNull() && !myFileName.isEmpty() ) {
2352 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2353 if ( fmt == "JPG" ) fmt = "JPEG";
2354 myResult = im.save( myFileName, fmt.toLatin1() );
2360 bool SalomePyQt::dumpView( const QString& filename, const int id )
2362 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2367 \fn QList<int> SalomePyQt::getViews();
2368 \brief Get list of integer identifiers of all the currently opened views
2369 \return list of integer identifiers of all the currently opened views
2372 class TGetViews: public SALOME_Event
2375 typedef QList<int> TResult;
2378 virtual void Execute()
2381 LightApp_Application* app = getApplication();
2384 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2387 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2388 SUIT_ViewWindow* wnd;
2389 foreach ( wnd, wndlist )
2390 myResult.append( wnd->getId() );
2395 QList<int> SalomePyQt::getViews()
2397 return ProcessEvent( new TGetViews() );
2401 \fn int SalomePyQt::getActiveView();
2402 \brief Get integer identifier of the currently active view
2403 \return integer identifier of the currently active view
2406 class TGetActiveView: public SALOME_Event
2409 typedef int TResult;
2413 virtual void Execute()
2415 LightApp_Application* app = getApplication();
2418 SUIT_ViewManager* viewMgr = app->activeViewManager();
2421 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2423 myResult = wnd->getId();
2428 int SalomePyQt::getActiveView()
2430 return ProcessEvent( new TGetActiveView() );
2434 \fn QString SalomePyQt::getViewType( const int id );
2435 \brief Get type of the specified view, e.g. "OCCViewer"
2436 \param id window identifier
2440 class TGetViewType: public SALOME_Event
2443 typedef QString TResult;
2446 TGetViewType( const int id )
2448 virtual void Execute()
2450 SUIT_ViewWindow* wnd = getWnd( myWndId );
2453 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2455 myResult = viewMgr->getType();
2459 QString SalomePyQt::getViewType( const int id )
2461 return ProcessEvent( new TGetViewType( id ) );
2465 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2466 \brief Change view caption
2467 \param id window identifier
2468 \param title new window title
2469 \return \c true if operation is completed successfully and \c false otherwise
2472 class TSetViewTitle: public SALOME_Event
2475 typedef bool TResult;
2479 TSetViewTitle( const int id, const QString& title )
2480 : myResult( false ),
2483 virtual void Execute()
2485 SUIT_ViewWindow* wnd = getWnd( myWndId );
2488 wnd->setWindowTitle( myTitle );
2493 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2495 return ProcessEvent( new TSetViewTitle( id, title ) );
2500 \fn QString SalomePyQt::getViewTitle( const int id );
2501 \brief Get view caption
2502 \param id window identifier
2503 \return view caption
2506 class TGetViewTitle: public SALOME_Event
2509 typedef QString TResult;
2512 TGetViewTitle( const int id )
2514 virtual void Execute()
2516 SUIT_ViewWindow* wnd = getWnd( myWndId );
2518 myResult = wnd->windowTitle();
2521 QString SalomePyQt::getViewTitle( const int id )
2523 return ProcessEvent( new TGetViewTitle( id ) );
2527 \fn QList<int> SalomePyQt::findViews( const QString& type );
2528 \brief Get list of integer identifiers of all the
2529 currently opened views of the specified type
2530 \param type viewer type
2531 \return list of integer identifiers
2534 class TFindViews: public SALOME_Event
2537 typedef QList<int> TResult;
2540 TFindViews( const QString& type )
2542 virtual void Execute()
2545 LightApp_Application* app = getApplication();
2548 ViewManagerList vmList;
2549 app->viewManagers( myType, vmList );
2550 SUIT_ViewManager* viewMgr;
2551 foreach ( viewMgr, vmList )
2553 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2554 for ( int i = 0, n = vec.size(); i < n; i++ )
2556 SUIT_ViewWindow* wnd = vec[ i ];
2558 myResult.append( wnd->getId() );
2564 QList<int> SalomePyQt::findViews( const QString& type )
2566 return ProcessEvent( new TFindViews( type ) );
2570 \fn bool SalomePyQt::activateView( const int id );
2571 \brief Activate view
2572 \param id window identifier
2573 \return \c true if operation is completed successfully and \c false otherwise
2576 class TActivateView: public SALOME_Event
2579 typedef bool TResult;
2582 TActivateView( const int id )
2583 : myResult( false ),
2585 virtual void Execute()
2587 SUIT_ViewWindow* wnd = getWnd( myWndId );
2595 bool SalomePyQt::activateView( const int id )
2597 return ProcessEvent( new TActivateView( id ) );
2601 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2602 \brief Create new view and activate it
2603 \param type viewer type
2607 \return integer identifier of created view (or -1 if view could not be created)
2610 class TCreateView: public SALOME_Event
2613 typedef int TResult;
2619 TCreateView( const QString& theType, bool visible, const int width, const int height )
2625 virtual void Execute()
2627 LightApp_Application* app = getApplication();
2630 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2633 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2635 wnd->setShown(myVisible);
2636 if(!myVisible && myWidth == 0 && myHeight == 0) {
2640 if(myWidth > 0 && myHeight > 0) {
2641 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2643 wnd2D->getViewFrame()->setGeometry(0,0,myWidth,myHeight);
2645 wnd->setGeometry(0,0,myWidth,myHeight);
2648 myResult = wnd->getId();
2654 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2656 return ProcessEvent( new TCreateView( type, visible, width, height ) );
2660 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2661 \brief Create new view with custom widget embedded and activate it
2662 \param type viewer type
2663 \param w custom widget
2664 \return integer identifier of created view (or -1 if view could not be created)
2667 class TCreateViewWg: public SALOME_Event
2670 typedef int TResult;
2674 TCreateViewWg( const QString& theType, QWidget* w )
2678 virtual void Execute()
2680 LightApp_Application* app = getApplication();
2683 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2686 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2688 myResult = wnd->getId();
2693 int SalomePyQt::createView( const QString& type, QWidget* w )
2695 return ProcessEvent( new TCreateViewWg( type, w ) );
2699 \fn bool SalomePyQt::closeView( const int id );
2701 \param id window identifier
2702 \return \c true if operation is completed successfully and \c false otherwise
2705 class TCloseView: public SALOME_Event
2708 typedef bool TResult;
2711 TCloseView( const int id )
2712 : myResult( false ),
2714 virtual void Execute()
2716 SUIT_ViewWindow* wnd = getWnd( myWndId );
2719 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2728 bool SalomePyQt::closeView( const int id )
2730 return ProcessEvent( new TCloseView( id ) );
2734 \fn int SalomePyQt::cloneView( const int id );
2735 \brief Clone view (if this operation is supported for specified view type)
2736 \param id window identifier
2737 \return integer identifier of the cloned view or -1 or operation could not be performed
2740 class TCloneView: public SALOME_Event
2743 typedef int TResult;
2746 TCloneView( const int id )
2749 virtual void Execute()
2751 SUIT_ViewWindow* wnd = getWnd( myWndId );
2754 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2757 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2759 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2760 occView->onCloneView();
2762 wnd = viewMgr->getActiveView();
2764 myResult = wnd->getId();
2766 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2768 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2769 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2770 if ( viewMgr2d && srcWnd2d )
2772 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2773 myResult = resWnd->getId();
2780 int SalomePyQt::cloneView( const int id )
2782 return ProcessEvent( new TCloneView( id ) );
2786 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2787 \brief Set view visibility.
2788 \param id window identifier
2789 \param visible new visiblity
2792 void SalomePyQt::setViewVisible( const int id, const bool visible )
2794 class TEvent: public SALOME_Event
2799 TEvent( const int id, const bool visible )
2800 : myWndId( id ), myVisible( visible ) {}
2801 virtual void Execute()
2803 SUIT_ViewWindow* wnd = getWnd( myWndId );
2804 if ( wnd ) wnd->setVisible( myVisible );
2807 ProcessVoidEvent( new TEvent( id, visible ) );
2811 \fn bool SalomePyQt::isViewVisible( const int id );
2812 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2813 \param id window identifier
2814 \return \c true if view is visible and \c false otherwise
2817 class TIsViewVisible: public SALOME_Event
2820 typedef bool TResult;
2823 TIsViewVisible( const int id )
2824 : myResult( false ),
2826 virtual void Execute()
2828 SUIT_ViewWindow* wnd = getWnd( myWndId );
2831 QWidget* p = wnd->parentWidget();
2832 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2836 bool SalomePyQt::isViewVisible( const int id )
2838 return ProcessEvent( new TIsViewVisible( id ) );
2842 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2843 \brief Set / clear view's "closable" option. By default any view is closable
2844 (i.e. can be closed by the user).
2845 \param id window identifier
2846 \param on new "closable" option's value
2849 void SalomePyQt::setViewClosable( const int id, const bool on )
2851 class TEvent: public SALOME_Event
2856 TEvent( const int id, const bool on )
2857 : myWndId( id ), myOn( on ) {}
2858 virtual void Execute()
2860 SUIT_ViewWindow* wnd = getWnd( myWndId );
2861 if ( wnd ) wnd->setClosable( myOn );
2864 ProcessVoidEvent( new TEvent( id, on ) );
2868 \fn bool SalomePyQt::isViewClosable( const int id );
2869 \brief Check whether view is closable (i.e. can be closed by the user)
2870 \param id window identifier
2871 \return \c true if view is closable or \c false otherwise
2874 class TIsViewClosable: public SALOME_Event
2877 typedef bool TResult;
2880 TIsViewClosable( const int id )
2883 virtual void Execute()
2885 SUIT_ViewWindow* wnd = getWnd( myWndId );
2887 myResult = wnd->closable();
2891 bool SalomePyQt::isViewClosable( const int id )
2893 return ProcessEvent( new TIsViewClosable( id ) );
2897 \fn bool SalomePyQt::groupAllViews();
2898 \brief Group all views to the single tab area
2899 \return \c true if operation is completed successfully and \c false otherwise
2902 class TGroupAllViews: public SALOME_Event
2905 typedef bool TResult;
2908 : myResult( false ) {}
2909 virtual void Execute()
2911 LightApp_Application* app = getApplication();
2914 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2917 QtxWorkstack* wStack = tabDesk->workstack();
2927 bool SalomePyQt::groupAllViews()
2929 return ProcessEvent( new TGroupAllViews() );
2933 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2934 \brief Split tab area to which view with identifier belongs to
2935 \param id window identifier
2936 \param ori orientation of split operation
2937 \param action action to be performed
2938 \return \c true if operation is completed successfully \c false otherwise
2941 class TSplitView: public SALOME_Event
2944 typedef bool TResult;
2949 TSplitView( const int id,
2950 const Orientation ori,
2951 const Action action )
2952 : myResult( false ),
2955 myAction( action ) {}
2956 virtual void Execute()
2958 SUIT_ViewWindow* wnd = getWnd( myWndId );
2962 // wnd->setFocus(); ???
2965 if ( getApplication() )
2967 STD_TabDesktop* desk =
2968 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2971 QtxWorkstack* wStack = desk->workstack();
2974 Qt::Orientation qtOri =
2975 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2977 QtxWorkstack::SplitType sType;
2978 if ( myAction == MoveWidget )
2979 sType = QtxWorkstack::SplitMove;
2980 else if ( myAction == LeaveWidget )
2981 sType = QtxWorkstack::SplitStay;
2983 sType = QtxWorkstack::SplitAt;
2985 wStack->Split( wnd, qtOri, sType );
2993 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2995 return ProcessEvent( new TSplitView( id, ori, action ) );
2999 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3000 \brief Move view with the first identifier to the same area which
3001 another view with the second identifier belongs to
3002 \param id source window identifier
3003 \param id_to destination window identifier
3004 param before specifies whether the first viewt has to be moved before or after
3006 \return \c true if operation is completed successfully and \c false otherwise
3009 class TMoveView: public SALOME_Event
3012 typedef bool TResult;
3017 TMoveView( const int id, const int id_to, const bool before )
3018 : myResult( false ),
3021 myIsBefore( before ) {}
3022 virtual void Execute()
3024 SUIT_ViewWindow* wnd = getWnd( myWndId );
3025 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3026 if ( wnd && wnd_to )
3028 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3029 getApplication()->desktop() )->workstack();
3031 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3035 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3037 return ProcessEvent( new TMoveView( id, id_to, before ) );
3041 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3042 \brief Get list of views identifiers that belongs to the same area as
3043 specified view (excluding it)
3044 \param id window identifier
3045 \return list of views identifiers
3048 class TNeighbourViews: public SALOME_Event
3051 typedef QList<int> TResult;
3054 TNeighbourViews( const int id )
3056 virtual void Execute()
3059 SUIT_ViewWindow* wnd = getWnd( myWndId );
3062 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3063 getApplication()->desktop() )->workstack();
3066 QWidgetList wgList = wStack->windowList( wnd );
3068 foreach ( wg, wgList )
3070 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3071 if ( tmpWnd && tmpWnd != wnd )
3072 myResult.append( tmpWnd->getId() );
3078 QList<int> SalomePyQt::neighbourViews( const int id )
3080 return ProcessEvent( new TNeighbourViews( id ) );
3085 \fn QString SalomePyQt::createObject( const QString& parent );
3086 \brief Create empty data object
3087 \param parent entry of parent data object
3088 \return entry of created data object
3091 class TCreateEmptyObjectEvent: public SALOME_Event
3094 typedef QString TResult;
3097 TCreateEmptyObjectEvent( const QString& parent )
3098 : myParent( parent ) {}
3099 virtual void Execute()
3101 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3103 myResult = module->createObject( myParent );
3106 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3110 QString SalomePyQt::createObject( const QString& parent )
3112 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3116 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3117 const QString& tooltip,const QString& parent );
3118 \brief Create new data object with specified name, icon and tooltip
3119 \param name data object name
3120 \param icon data object icon
3121 \param toolTip data object tooltip
3122 \param parent entry of parent data object
3123 \return entry of created data object
3126 class TCreateObjectEvent: public SALOME_Event
3129 typedef QString TResult;
3135 TCreateObjectEvent( const QString& name,
3136 const QString& icon,
3137 const QString& tooltip,
3138 const QString& parent )
3141 myToolTip( tooltip ),
3142 myParent( parent ) {}
3143 virtual void Execute()
3145 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3147 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3150 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3154 QString SalomePyQt::createObject( const QString& name,
3155 const QString& icon,
3156 const QString& toolTip,
3157 const QString& parent )
3159 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3164 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3165 \brief Set data object name
3166 \param entry data object entry
3167 \param name data object name
3169 class TSetNameEvent: public SALOME_Event
3174 TSetNameEvent( const QString& entry,
3175 const QString& name )
3178 virtual void Execute()
3180 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3182 module->setName( myEntry, myName );
3185 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3189 void SalomePyQt::setName( const QString& entry, const QString& name )
3191 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3195 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3196 \brief Set data object icon
3197 \param entry data object entry
3198 \param icon data object icon file name (icon is loaded from module resources)
3201 class TSetIconEvent: public SALOME_Event
3206 TSetIconEvent( const QString& entry,
3207 const QString& icon )
3210 virtual void Execute()
3212 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3214 module->setIcon( myEntry, myIcon );
3217 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3222 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3224 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3228 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3229 \brief Set data object tooltip
3230 \param entry data object entry
3231 \param toolTip data object tooltip
3234 class TSetToolTipEvent: public SALOME_Event
3239 TSetToolTipEvent( const QString& entry,
3240 const QString& toolTip )
3242 myToolTip( toolTip ) {}
3243 virtual void Execute()
3245 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3247 module->setToolTip( myEntry, myToolTip );
3250 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3254 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3256 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3260 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3261 \brief Set reference to another data object
3262 \param entry data object entry
3263 \param refEntry referenced data object entry
3266 class TSetRefEvent: public SALOME_Event
3271 TSetRefEvent( const QString& entry,
3272 const QString& refEntry )
3274 myRefEntry( refEntry ) {}
3275 virtual void Execute()
3277 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3279 module->setReference( myEntry, myRefEntry );
3282 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3286 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3288 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3292 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3293 \brief Set data object color
3294 \param entry data object entry
3295 \param color data object color
3298 class TSetColorEvent: public SALOME_Event
3303 TSetColorEvent( const QString& entry,
3304 const QColor& color )
3307 virtual void Execute()
3309 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3311 module->setColor( myEntry, myColor );
3314 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3318 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3320 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3324 \fn QString SalomePyQt::getName( const QString& entry );
3325 \brief Get data object name
3326 \param entry data object entry
3327 \return data object name
3330 class TGetNameEvent: public SALOME_Event
3333 typedef QString TResult;
3336 TGetNameEvent( const QString& entry )
3337 : myEntry( entry ) {}
3338 virtual void Execute()
3340 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3342 myResult = module->getName( myEntry );
3345 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3349 QString SalomePyQt::getName( const QString& entry )
3351 return ProcessEvent( new TGetNameEvent( entry ) );
3355 \fn QString SalomePyQt::getToolTip( const QString& entry );
3356 \brief Get data object tooltip
3357 \param entry data object entry
3358 \return data object tooltip
3361 class TGetToolTipEvent: public SALOME_Event
3364 typedef QString TResult;
3367 TGetToolTipEvent( const QString& entry )
3368 : myEntry( entry ) {}
3369 virtual void Execute()
3371 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3373 myResult = module->getToolTip( myEntry );
3376 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3380 QString SalomePyQt::getToolTip( const QString& entry )
3382 return ProcessEvent( new TGetToolTipEvent( entry ) );
3386 \fn QString SalomePyQt::getReference( const QString& entry );
3387 \brief Get entry of the referenced object (if there's any)
3388 \param entry data object entry
3389 \return referenced data object entry
3392 class TGetRefEvent: public SALOME_Event
3395 typedef QString TResult;
3398 TGetRefEvent( const QString& entry )
3399 : myEntry( entry ) {}
3400 virtual void Execute()
3402 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3404 myResult = module->getReference( myEntry );
3407 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3411 QString SalomePyQt::getReference( const QString& entry )
3413 return ProcessEvent( new TGetRefEvent( entry ) );
3417 \fn QColor SalomePyQt::getColor( const QString& entry );
3418 \brief Get data object color
3419 \param entry data object entry
3420 \return data object color
3423 class TGetColorEvent: public SALOME_Event
3426 typedef QColor TResult;
3429 TGetColorEvent( const QString& entry )
3430 : myEntry( entry ) {}
3431 virtual void Execute()
3433 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3435 myResult = module->getColor( myEntry );
3438 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3442 QColor SalomePyQt::getColor( const QString& entry )
3444 return ProcessEvent( new TGetColorEvent( entry ) );
3448 \fn void SalomePyQt::removeChildren( const QString& entry );
3449 \brief Remove all child data objects from specified data object
3450 \param entry data object entry
3453 class TRemoveChildEvent: public SALOME_Event
3457 TRemoveChildEvent( const QString& entry )
3458 : myEntry( entry ) {}
3459 virtual void Execute()
3461 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3463 module->removeChildren( myEntry );
3466 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3470 void SalomePyQt::removeChildren( const QString& entry )
3472 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3474 void SalomePyQt::removeChild( const QString& entry )
3476 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3477 removeChildren( entry );
3481 \fn void SalomePyQt::removeObject( const QString& entry );
3482 \brief Remove object by entry
3483 \param entry data object entry
3486 class TRemoveObjectEvent: public SALOME_Event
3491 TRemoveObjectEvent( const QString& entry )
3492 : myEntry( entry ) {}
3493 virtual void Execute()
3495 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3497 module->removeObject( myEntry );
3500 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3504 void SalomePyQt::removeObject( const QString& entry )
3506 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3510 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3511 \brief Get entries of all child data objects of specified data object
3512 \param entry data object entry
3513 \param recursive \c true for recursive processing
3516 class TGetChildrenEvent: public SALOME_Event
3519 typedef QStringList TResult;
3523 TGetChildrenEvent( const QString& entry, const bool recursive )
3525 myRecursive( recursive ) {}
3526 virtual void Execute()
3528 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3530 myResult = module->getChildren( myEntry, myRecursive );
3533 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3537 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3539 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3544 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3545 \brief Display theCurve in view
3546 \param id window identifier
3547 \param theCurve curve to display
3550 class TDisplayCurve: public SALOME_Event
3554 Plot2d_Curve* myCurve;
3555 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3556 virtual void Execute() {
3557 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3560 wnd->getViewFrame()->displayCurve(myCurve);
3564 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3566 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3570 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3571 \brief Erase theCurve in view
3572 \param id window identifier
3573 \param theCurve curve to erase
3576 class TEraseCurve: public SALOME_Event
3580 Plot2d_Curve* myCurve;
3581 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3582 virtual void Execute() {
3583 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3586 wnd->getViewFrame()->eraseCurve(myCurve);
3590 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3592 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3596 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3597 \brief Delete theCurve from all views
3598 \param theCurve curve to delete
3601 class TDeleteCurve: public SALOME_Event
3604 Plot2d_Curve* myCurve;
3605 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3606 virtual void Execute() {
3607 LightApp_Application* app = getApplication();
3610 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3613 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3614 SUIT_ViewWindow* wnd;
3615 foreach ( wnd, wndlist )
3617 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3620 aP2d->getViewFrame()->eraseObject(myCurve);
3627 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3629 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3633 \brief updateCurves (repaint) curves in view window.
3635 void SalomePyQt::updateCurves(const int id)
3637 class TEvent: public SALOME_Event
3641 TEvent( const int id ) : myWndId( id ) {}
3642 virtual void Execute()
3644 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3647 wnd->getViewFrame()->DisplayAll();
3651 ProcessVoidEvent( new TEvent(id) );
3655 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3656 \brief Get title of corresponding type
3657 \param id window identifier
3658 \param type is type of title
3659 \return title of corresponding type
3662 class TGetPlot2dTitle: public SALOME_Event
3665 typedef QString TResult;
3669 TGetPlot2dTitle(const int id, ObjectType type) :
3672 virtual void Execute() {
3673 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3676 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3680 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3682 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3687 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3688 \brief Set title of corresponding type
3689 \param id window identifier
3691 \param type is type of title
3695 class TSetPlot2dTitle: public SALOME_Event
3699 Plot2d_Curve* myCurve;
3703 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3708 virtual void Execute() {
3709 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3712 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3716 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3718 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3722 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3723 \brief Get list of Plot2d view ranges
3724 \param id window identifier
3725 \return list of view ranges (XMin, XMax, YMin, YMax)
3728 class TFitRangeByCurves: public SALOME_Event
3731 typedef QList<double> TResult;
3734 TFitRangeByCurves( const int id )
3736 virtual void Execute()
3739 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3742 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3743 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3744 myResult.append(XMin);
3745 myResult.append(XMax);
3746 myResult.append(YMin);
3747 myResult.append(YMax);
3751 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3753 return ProcessEvent( new TFitRangeByCurves( id ) );
3757 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3758 \brief Get list of current Plot2d view ranges
3759 \param id window identifier
3760 \return list of view ranges (XMin, XMax, YMin, YMax)
3763 class TFitRangeCurrent: public SALOME_Event
3766 typedef QList<double> TResult;
3769 TFitRangeCurrent( const int id )
3771 virtual void Execute()
3774 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3777 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3778 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3779 myResult.append(XMin);
3780 myResult.append(XMax);
3781 myResult.append(YMin);
3782 myResult.append(YMax);
3786 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3788 return ProcessEvent( new TFitRangeCurrent( id ) );
3792 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3793 \brief Set range of Plot2d view
3794 \param id window identifier
3801 class TPlot2dFitRange: public SALOME_Event
3809 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3815 virtual void Execute() {
3816 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3819 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3823 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3825 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3829 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3831 class TEvent: public SALOME_Event
3836 TEvent( const QString& theEntry, int theState):
3837 myEntry(theEntry), myState(theState) {}
3838 virtual void Execute()
3840 LightApp_Study* aStudy = getActiveStudy();
3843 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3846 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3849 class TGetVisibilityStateEvent: public SALOME_Event
3852 typedef int TResult;
3855 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3856 virtual void Execute()
3858 LightApp_Study* aStudy = getActiveStudy();
3860 myResult = aStudy->visibilityState(myEntry);
3864 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3866 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3870 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3872 class TEvent: public SALOME_Event
3877 TEvent( const QString& theEntry, int thePos):
3878 myEntry(theEntry), myPos(thePos) {}
3879 virtual void Execute()
3881 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3883 module->setObjectPosition(myEntry, myPos );
3886 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3891 class TGetObjectPositionEvent: public SALOME_Event
3894 typedef int TResult;
3897 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3898 virtual void Execute()
3900 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3902 myResult = module->getObjectPosition(myEntry);
3906 int SalomePyQt::getObjectPosition( const QString& theEntry )
3908 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );