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 )
1553 : myCase( 0 ), myTbName( tBar ) {}
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 ), myTbName( 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 ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1563 int execute( LightApp_Module* module ) const
1568 return module->createTool( myTbName );
1570 return module->createTool( myId, myTbId, myIndex );
1572 return module->createTool( myId, myTbName, myIndex );
1574 return module->createTool( myAction, myTbId, myId, myIndex );
1576 return module->createTool( myAction, myTbName, myId, myIndex );
1590 class TCreateToolEvent: public SALOME_Event
1593 typedef int TResult;
1595 const CrTool& myCrTool;
1596 TCreateToolEvent( const CrTool& crTool )
1597 : myResult( -1 ), myCrTool( crTool ) {}
1598 virtual void Execute()
1600 LightApp_Module* module = getActiveModule();
1602 myResult = myCrTool.execute( module );
1607 \brief Create toolbar with specified name.
1608 \param tBar toolbar name
1609 \return toolbar ID or -1 if toolbar creation is failed
1611 int SalomePyQt::createTool( const QString& tBar )
1613 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1617 \brief Insert action with specified \a id to the toolbar.
1619 \param tBar toolbar ID
1620 \param idx required index in the toolbar
1621 \return action ID or -1 if action could not be added
1623 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1625 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1629 \brief Insert action with specified \a id to the toolbar.
1631 \param tBar toolbar name
1632 \param idx required index in the toolbar
1633 \return action ID or -1 if action could not be added
1635 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1637 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1641 \brief Insert action to the toolbar.
1643 \param tBar toolbar ID
1644 \param id required action ID
1645 \param idx required index in the toolbar
1646 \return action ID or -1 if action could not be added
1648 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1650 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1654 \brief Insert action to the toolbar.
1656 \param tBar toolbar name
1657 \param id required action ID
1658 \param idx required index in the toolbar
1659 \return action ID or -1 if action could not be added
1661 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1663 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1669 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1670 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1671 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1672 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1673 CrMenu( const int id, const int menu, const int group, const int idx )
1674 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1675 CrMenu( const int id, const QString& menu, const int group, const int idx )
1676 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1677 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1678 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1679 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1680 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1682 int execute( LightApp_Module* module ) const
1687 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1689 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1691 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1693 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1695 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1697 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1706 QString mySubMenuName;
1713 class TCreateMenuEvent: public SALOME_Event
1716 typedef int TResult;
1718 const CrMenu& myCrMenu;
1719 TCreateMenuEvent( const CrMenu& crMenu )
1720 : myResult( -1 ), myCrMenu( crMenu ) {}
1721 virtual void Execute()
1723 LightApp_Module* module = getActiveModule();
1725 myResult = myCrMenu.execute( module );
1730 \brief Create main menu.
1731 \param subMenu menu name
1732 \param menu parent menu ID
1733 \param id required menu ID
1734 \param group menu group ID
1735 \param idx required index in the menu
1736 \return menu ID or -1 if menu could not be added
1738 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1740 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1744 \brief Create main menu.
1745 \param subMenu menu name
1746 \param menu parent menu name (list of menu names separated by "|")
1747 \param id required menu ID
1748 \param group menu group ID
1749 \param idx required index in the menu
1750 \return menu ID or -1 if menu could not be added
1752 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1754 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1758 \brief Insert action to the main menu.
1760 \param menu parent menu ID
1761 \param group menu group ID
1762 \param idx required index in the menu
1763 \return action ID or -1 if action could not be added
1765 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1767 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1771 \brief Insert action to the main menu.
1773 \param menu parent menu name (list of menu names separated by "|")
1774 \param group menu group ID
1775 \param idx required index in the menu
1776 \return action ID or -1 if action could not be added
1778 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1780 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1784 \brief Insert action to the main menu.
1786 \param menu parent menu ID
1787 \param group menu group ID
1788 \param idx required index in the menu
1789 \return action ID or -1 if action could not be added
1791 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1793 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1797 \brief Insert action to the main menu.
1799 \param menu parent menu name (list of menu names separated by "|")
1800 \param group menu group ID
1801 \param idx required index in the menu
1802 \return action ID or -1 if action could not be added
1804 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1806 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1810 \fn QAction* SalomePyQt::createSeparator();
1811 \brief Create separator action which can be used in the menu or toolbar.
1812 \return new separator action
1815 class TCreateSepEvent: public SALOME_Event
1818 typedef QAction* TResult;
1822 virtual void Execute()
1824 LightApp_Module* module = getActiveModule();
1826 myResult = (QAction*)module->separator();
1829 QAction* SalomePyQt::createSeparator()
1831 return ProcessEvent( new TCreateSepEvent() );
1835 \fn QAction* SalomePyQt::createAction( const int id,
1836 const QString& menuText,
1837 const QString& tipText,
1838 const QString& statusText,
1839 const QString& icon,
1841 const bool toggle );
1842 \brief Create an action which can be then used in the menu or toolbar.
1843 \param id the unique id action to be registered to
1844 \param menuText action text which should appear in menu
1845 \param tipText text which should appear in the tooltip
1846 \param statusText text which should appear in the status bar when action is activated
1847 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1848 \param key the key accelrator for the action
1849 \param toggle if \c true the action is checkable
1852 class TCreateActionEvent: public SALOME_Event
1855 typedef QAction* TResult;
1860 QString myStatusText;
1864 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1865 const QString& statusText, const QString& icon, const int key, const bool toggle )
1866 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1867 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1868 virtual void Execute()
1870 LightApp_Module* module = getActiveModule();
1872 QIcon icon = loadIconInternal( module->name(), myIcon );
1873 myResult = (QAction*)module->action( myId );
1875 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1876 myResult->setToolTip( myTipText );
1877 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1878 myResult->setText( myMenuText );
1879 if ( myResult->icon().isNull() && !icon.isNull() )
1880 myResult->setIcon( icon );
1881 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1882 myResult->setStatusTip( myStatusText );
1883 if ( myResult->shortcut().isEmpty() && myKey )
1884 myResult->setShortcut( myKey );
1885 if ( myResult->isCheckable() != myToggle )
1886 myResult->setCheckable( myToggle );
1889 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1891 // for Python module, automatically connect action to callback slot
1892 PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1893 if ( helper ) helper->connectAction( myResult );
1897 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1898 const QString& tipText, const QString& statusText,
1899 const QString& icon, const int key, const bool toggle )
1901 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1905 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1906 \brief Create an action group which can be then used in the menu or toolbar
1907 \param id : the unique id action group to be registered to
1908 \param exclusive : if \c true the action group does exclusive toggling
1911 struct TCreateActionGroupEvent: public SALOME_Event
1913 typedef QtxActionGroup* TResult;
1917 TCreateActionGroupEvent( const int id, const bool exclusive )
1918 : myId( id ), myExclusive( exclusive ) {}
1919 virtual void Execute()
1921 LightApp_Module* module = getActiveModule();
1923 myResult = module->createActionGroup( myId, myExclusive );
1926 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1928 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1932 \fn QAction* SalomePyQt::action( const int id );
1933 \brief Get action by specified identifier.
1934 \return action or 0 if action is not registered
1937 class TActionEvent: public SALOME_Event
1940 typedef QAction* TResult;
1943 TActionEvent( const int id )
1944 : myResult( 0 ), myId( id ) {}
1945 virtual void Execute()
1947 LightApp_Module* module = getActiveModule();
1949 myResult = (QAction*)module->action( myId );
1952 QAction* SalomePyQt::action( const int id )
1954 return ProcessEvent( new TActionEvent( id ) );
1958 \fn int SalomePyQt::actionId( const QAction* a );
1959 \brief Get an action identifier.
1960 \return action ID or -1 if action is not registered
1963 class TActionIdEvent: public SALOME_Event
1966 typedef int TResult;
1968 const QAction* myAction;
1969 TActionIdEvent( const QAction* action )
1970 : myResult( -1 ), myAction( action ) {}
1971 virtual void Execute()
1973 LightApp_Module* module = getActiveModule();
1975 myResult = module->actionId( myAction );
1978 int SalomePyQt::actionId( const QAction* a )
1980 return ProcessEvent( new TActionIdEvent( a ) );
1984 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1985 \brief Add global (not module-related) preferences group.
1986 \param label global preferences group name
1987 \return preferences group identifier
1990 class TAddGlobalPrefEvent: public SALOME_Event
1993 typedef int TResult;
1996 TAddGlobalPrefEvent( const QString& label )
1997 : myResult( -1 ), myLabel( label ) {}
1998 virtual void Execute()
2000 LightApp_Module* module = getActiveModule();
2002 LightApp_Preferences* pref = module->getApp()->preferences();
2004 myResult = pref->addPreference( myLabel, -1 );
2008 int SalomePyQt::addGlobalPreference( const QString& label )
2010 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2014 \fn int SalomePyQt::addPreference( const QString& label );
2015 \brief Add module-related preferences group.
2016 \param label preferences group name
2017 \return preferences group identifier
2020 class TAddPrefEvent: public SALOME_Event
2023 typedef int TResult;
2026 TAddPrefEvent( const QString& label )
2027 : myResult( -1 ), myLabel( label ) {}
2028 virtual void Execute()
2030 LightApp_Module* module = getActiveModule();
2032 LightApp_Preferences* pref = module->getApp()->preferences();
2034 int cId = pref->addPreference( module->moduleName(), -1 );
2036 myResult = pref->addPreference( myLabel, cId );
2041 int SalomePyQt::addPreference( const QString& label )
2043 return ProcessEvent( new TAddPrefEvent( label ) );
2047 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2048 const QString& section, const QString& param );
2049 \brief Add module-related preferences.
2050 \param label preferences group name
2051 \param pId parent preferences group id
2052 \param type preferences type
2053 \param section resources file section name
2054 \param param resources file setting name
2055 \return preferences identifier
2058 class TAddPrefParamEvent: public SALOME_Event
2061 typedef int TResult;
2068 TAddPrefParamEvent( const QString& label,
2069 const int pId, const int type,
2070 const QString& section,
2071 const QString& param )
2073 myLabel( label ), myPId( pId ), myType( type ),
2074 mySection( section ), myParam ( param ) {}
2075 virtual void Execute()
2077 LightApp_Module* module = getActiveModule();
2079 LightApp_Preferences* pref = module->getApp()->preferences();
2081 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2085 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2086 const QString& section, const QString& param )
2088 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2092 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2093 \brief Get the preferences property.
2094 \param id preferences identifier
2095 \param prop preferences property name
2096 \return preferences property value or null QVariant if property is not set
2099 class TPrefPropEvent: public SALOME_Event
2102 typedef QVariant TResult;
2106 TPrefPropEvent( const int id, const QString& prop )
2107 : myId( id ), myProp( prop ) {}
2108 virtual void Execute()
2110 LightApp_Module* module = getActiveModule();
2112 LightApp_Preferences* pref = module->getApp()->preferences();
2114 myResult = pref->itemProperty( myProp, myId );
2118 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2120 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2124 \brief Set the preferences property.
2125 \param id preferences identifier
2126 \param prop preferences property name
2127 \param var preferences property value
2129 void SalomePyQt::setPreferenceProperty( const int id,
2130 const QString& prop,
2131 const QVariant& var )
2133 class TEvent: public SALOME_Event
2139 TEvent( const int id, const QString& prop, const QVariant& var )
2140 : myId( id ), myProp( prop ), myVar( var ) {}
2141 virtual void Execute()
2143 LightApp_Module* module = getActiveModule();
2145 LightApp_Preferences* pref = module->getApp()->preferences();
2147 pref->setItemProperty( myProp, myVar, myId );
2151 ProcessVoidEvent( new TEvent( id, prop, var) );
2155 \brief Add the property value to the list of values.
2157 This method allows creating properties which are QList<QVariant>
2158 - there is no way to pass such values directly to QVariant parameter with PyQt.
2160 \param id preferences identifier
2161 \param prop preferences property name
2162 \param idx preferences property index
2163 \param var preferences property value for the index \a idx
2165 void SalomePyQt::addPreferenceProperty( const int id,
2166 const QString& prop,
2168 const QVariant& var )
2170 class TEvent: public SALOME_Event
2177 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2178 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2179 virtual void Execute()
2181 LightApp_Module* module = getActiveModule();
2183 LightApp_Preferences* pref = module->getApp()->preferences();
2185 QVariant var = pref->itemProperty( myProp, myId );
2186 if ( var.isValid() ) {
2187 if ( var.type() == QVariant::StringList ) {
2188 QStringList sl = var.toStringList();
2189 if ( myIdx >= 0 && myIdx < sl.count() )
2190 sl[myIdx] = myVar.toString();
2192 sl.append( myVar.toString() );
2193 pref->setItemProperty( myProp, sl, myId );
2195 else if ( var.type() == QVariant::List ) {
2196 QList<QVariant> vl = var.toList();
2197 if ( myIdx >= 0 && myIdx < vl.count() )
2201 pref->setItemProperty( myProp, vl, myId );
2207 pref->setItemProperty( myProp, vl, myId );
2213 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2217 \brief Put the message to the Log messages output window
2218 \param msg message text (it can be of simple rich text format)
2219 \param addSeparator boolean flag which specifies if it is necessary
2220 to separate the message with predefined separator
2222 void SalomePyQt::message( const QString& msg, bool addSeparator )
2224 class TEvent: public SALOME_Event
2229 TEvent( const QString& msg, bool addSeparator )
2230 : myMsg( msg ), myAddSep( addSeparator ) {}
2231 virtual void Execute()
2233 if ( LightApp_Application* anApp = getApplication() ) {
2234 LogWindow* lw = anApp->logWindow();
2236 lw->putMessage( myMsg, myAddSep );
2240 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2244 \brief Remove all the messages from the Log messages output window.
2246 void SalomePyQt::clearMessages()
2248 class TEvent: public SALOME_Event
2252 virtual void Execute()
2254 if ( LightApp_Application* anApp = getApplication() ) {
2255 LogWindow* lw = anApp->logWindow();
2261 ProcessVoidEvent( new TEvent() );
2265 \brief Gets window with specified identifier
2267 \param id window identifier
2268 \return pointer on the window
2270 static SUIT_ViewWindow* getWnd( const int id )
2272 SUIT_ViewWindow* resWnd = 0;
2274 LightApp_Application* app = getApplication();
2277 ViewManagerList vmlist = app->viewManagers();
2278 foreach( SUIT_ViewManager* vm, vmlist )
2280 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2281 foreach ( SUIT_ViewWindow* vw, vwlist )
2283 if ( id == vw->getId() )
2296 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2297 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2298 to the image file in the specified format.
2300 For the current moment JPEG, PNG and BMP images formats are supported.
2301 The image format is defined automatically by the file name extension.
2302 By default, BMP format is used.
2304 \param filename image file name
2305 \return operation status (\c true on success)
2308 class TDumpViewEvent: public SALOME_Event
2311 typedef bool TResult;
2315 TDumpViewEvent( const QString& filename, const int id )
2316 : myResult ( false ), myFileName( filename ), myWndId(id) {}
2317 virtual void Execute()
2319 SUIT_ViewWindow* wnd = NULL;
2322 if ( LightApp_Application* anApp = getApplication() ) {
2323 SUIT_ViewManager* vm = anApp->activeViewManager();
2325 wnd = vm->getActiveView();
2327 myWndId = wnd->getId();
2331 wnd = dynamic_cast<SUIT_ViewWindow*>(getWnd( myWndId ));
2334 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2335 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2336 if(fmt == "PS" || fmt == "EPS" || fmt == "PDF") {
2338 myResult = wnd2D->getViewFrame()->print(myFileName, fmt);
2344 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2345 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2346 qApp->processEvents();
2348 QImage im = wnd->dumpView();
2349 if ( !im.isNull() && !myFileName.isEmpty() ) {
2350 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2351 if ( fmt == "JPG" ) fmt = "JPEG";
2352 myResult = im.save( myFileName, fmt.toLatin1() );
2358 bool SalomePyQt::dumpView( const QString& filename, const int id )
2360 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2365 \fn QList<int> SalomePyQt::getViews();
2366 \brief Get list of integer identifiers of all the currently opened views
2367 \return list of integer identifiers of all the currently opened views
2370 class TGetViews: public SALOME_Event
2373 typedef QList<int> TResult;
2376 virtual void Execute()
2379 LightApp_Application* app = getApplication();
2382 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2385 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2386 SUIT_ViewWindow* wnd;
2387 foreach ( wnd, wndlist )
2388 myResult.append( wnd->getId() );
2393 QList<int> SalomePyQt::getViews()
2395 return ProcessEvent( new TGetViews() );
2399 \fn int SalomePyQt::getActiveView();
2400 \brief Get integer identifier of the currently active view
2401 \return integer identifier of the currently active view
2404 class TGetActiveView: public SALOME_Event
2407 typedef int TResult;
2411 virtual void Execute()
2413 LightApp_Application* app = getApplication();
2416 SUIT_ViewManager* viewMgr = app->activeViewManager();
2419 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2421 myResult = wnd->getId();
2426 int SalomePyQt::getActiveView()
2428 return ProcessEvent( new TGetActiveView() );
2432 \fn QString SalomePyQt::getViewType( const int id );
2433 \brief Get type of the specified view, e.g. "OCCViewer"
2434 \param id window identifier
2438 class TGetViewType: public SALOME_Event
2441 typedef QString TResult;
2444 TGetViewType( const int id )
2446 virtual void Execute()
2448 SUIT_ViewWindow* wnd = getWnd( myWndId );
2451 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2453 myResult = viewMgr->getType();
2457 QString SalomePyQt::getViewType( const int id )
2459 return ProcessEvent( new TGetViewType( id ) );
2463 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2464 \brief Change view caption
2465 \param id window identifier
2466 \param title new window title
2467 \return \c true if operation is completed successfully and \c false otherwise
2470 class TSetViewTitle: public SALOME_Event
2473 typedef bool TResult;
2477 TSetViewTitle( const int id, const QString& title )
2478 : myResult( false ),
2481 virtual void Execute()
2483 SUIT_ViewWindow* wnd = getWnd( myWndId );
2486 wnd->setWindowTitle( myTitle );
2491 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2493 return ProcessEvent( new TSetViewTitle( id, title ) );
2498 \fn QString SalomePyQt::getViewTitle( const int id );
2499 \brief Get view caption
2500 \param id window identifier
2501 \return view caption
2504 class TGetViewTitle: public SALOME_Event
2507 typedef QString TResult;
2510 TGetViewTitle( const int id )
2512 virtual void Execute()
2514 SUIT_ViewWindow* wnd = getWnd( myWndId );
2516 myResult = wnd->windowTitle();
2519 QString SalomePyQt::getViewTitle( const int id )
2521 return ProcessEvent( new TGetViewTitle( id ) );
2525 \fn QList<int> SalomePyQt::findViews( const QString& type );
2526 \brief Get list of integer identifiers of all the
2527 currently opened views of the specified type
2528 \param type viewer type
2529 \return list of integer identifiers
2532 class TFindViews: public SALOME_Event
2535 typedef QList<int> TResult;
2538 TFindViews( const QString& type )
2540 virtual void Execute()
2543 LightApp_Application* app = getApplication();
2546 ViewManagerList vmList;
2547 app->viewManagers( myType, vmList );
2548 SUIT_ViewManager* viewMgr;
2549 foreach ( viewMgr, vmList )
2551 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2552 for ( int i = 0, n = vec.size(); i < n; i++ )
2554 SUIT_ViewWindow* wnd = vec[ i ];
2556 myResult.append( wnd->getId() );
2562 QList<int> SalomePyQt::findViews( const QString& type )
2564 return ProcessEvent( new TFindViews( type ) );
2568 \fn bool SalomePyQt::activateView( const int id );
2569 \brief Activate view
2570 \param id window identifier
2571 \return \c true if operation is completed successfully and \c false otherwise
2574 class TActivateView: public SALOME_Event
2577 typedef bool TResult;
2580 TActivateView( const int id )
2581 : myResult( false ),
2583 virtual void Execute()
2585 SUIT_ViewWindow* wnd = getWnd( myWndId );
2593 bool SalomePyQt::activateView( const int id )
2595 return ProcessEvent( new TActivateView( id ) );
2599 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2600 \brief Create new view and activate it
2601 \param type viewer type
2605 \return integer identifier of created view (or -1 if view could not be created)
2608 class TCreateView: public SALOME_Event
2611 typedef int TResult;
2617 TCreateView( const QString& theType, bool visible, const int width, const int height )
2623 virtual void Execute()
2625 LightApp_Application* app = getApplication();
2628 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2631 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2633 wnd->setShown(myVisible);
2634 if(!myVisible && myWidth == 0 && myHeight == 0) {
2638 if(myWidth > 0 && myHeight > 0) {
2639 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2641 wnd2D->getViewFrame()->setGeometry(0,0,myWidth,myHeight);
2643 wnd->setGeometry(0,0,myWidth,myHeight);
2646 myResult = wnd->getId();
2652 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2654 return ProcessEvent( new TCreateView( type, visible, width, height ) );
2658 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2659 \brief Create new view with custom widget embedded and activate it
2660 \param type viewer type
2661 \param w custom widget
2662 \return integer identifier of created view (or -1 if view could not be created)
2665 class TCreateViewWg: public SALOME_Event
2668 typedef int TResult;
2672 TCreateViewWg( const QString& theType, QWidget* w )
2676 virtual void Execute()
2678 LightApp_Application* app = getApplication();
2681 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2684 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2686 myResult = wnd->getId();
2691 int SalomePyQt::createView( const QString& type, QWidget* w )
2693 return ProcessEvent( new TCreateViewWg( type, w ) );
2697 \fn bool SalomePyQt::closeView( const int id );
2699 \param id window identifier
2700 \return \c true if operation is completed successfully and \c false otherwise
2703 class TCloseView: public SALOME_Event
2706 typedef bool TResult;
2709 TCloseView( const int id )
2710 : myResult( false ),
2712 virtual void Execute()
2714 SUIT_ViewWindow* wnd = getWnd( myWndId );
2717 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2726 bool SalomePyQt::closeView( const int id )
2728 return ProcessEvent( new TCloseView( id ) );
2732 \fn int SalomePyQt::cloneView( const int id );
2733 \brief Clone view (if this operation is supported for specified view type)
2734 \param id window identifier
2735 \return integer identifier of the cloned view or -1 or operation could not be performed
2738 class TCloneView: public SALOME_Event
2741 typedef int TResult;
2744 TCloneView( const int id )
2747 virtual void Execute()
2749 SUIT_ViewWindow* wnd = getWnd( myWndId );
2752 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2755 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2757 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2758 occView->onCloneView();
2760 wnd = viewMgr->getActiveView();
2762 myResult = wnd->getId();
2764 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2766 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2767 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2768 if ( viewMgr2d && srcWnd2d )
2770 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2771 myResult = resWnd->getId();
2778 int SalomePyQt::cloneView( const int id )
2780 return ProcessEvent( new TCloneView( id ) );
2784 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2785 \brief Set view visibility.
2786 \param id window identifier
2787 \param visible new visiblity
2790 void SalomePyQt::setViewVisible( const int id, const bool visible )
2792 class TEvent: public SALOME_Event
2797 TEvent( const int id, const bool visible )
2798 : myWndId( id ), myVisible( visible ) {}
2799 virtual void Execute()
2801 SUIT_ViewWindow* wnd = getWnd( myWndId );
2802 if ( wnd ) wnd->setVisible( myVisible );
2805 ProcessVoidEvent( new TEvent( id, visible ) );
2809 \fn bool SalomePyQt::isViewVisible( const int id );
2810 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2811 \param id window identifier
2812 \return \c true if view is visible and \c false otherwise
2815 class TIsViewVisible: public SALOME_Event
2818 typedef bool TResult;
2821 TIsViewVisible( const int id )
2822 : myResult( false ),
2824 virtual void Execute()
2826 SUIT_ViewWindow* wnd = getWnd( myWndId );
2829 QWidget* p = wnd->parentWidget();
2830 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2834 bool SalomePyQt::isViewVisible( const int id )
2836 return ProcessEvent( new TIsViewVisible( id ) );
2840 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2841 \brief Set / clear view's "closable" option. By default any view is closable
2842 (i.e. can be closed by the user).
2843 \param id window identifier
2844 \param on new "closable" option's value
2847 void SalomePyQt::setViewClosable( const int id, const bool on )
2849 class TEvent: public SALOME_Event
2854 TEvent( const int id, const bool on )
2855 : myWndId( id ), myOn( on ) {}
2856 virtual void Execute()
2858 SUIT_ViewWindow* wnd = getWnd( myWndId );
2859 if ( wnd ) wnd->setClosable( myOn );
2862 ProcessVoidEvent( new TEvent( id, on ) );
2866 \fn bool SalomePyQt::isViewClosable( const int id );
2867 \brief Check whether view is closable (i.e. can be closed by the user)
2868 \param id window identifier
2869 \return \c true if view is closable or \c false otherwise
2872 class TIsViewClosable: public SALOME_Event
2875 typedef bool TResult;
2878 TIsViewClosable( const int id )
2881 virtual void Execute()
2883 SUIT_ViewWindow* wnd = getWnd( myWndId );
2885 myResult = wnd->closable();
2889 bool SalomePyQt::isViewClosable( const int id )
2891 return ProcessEvent( new TIsViewClosable( id ) );
2895 \fn bool SalomePyQt::groupAllViews();
2896 \brief Group all views to the single tab area
2897 \return \c true if operation is completed successfully and \c false otherwise
2900 class TGroupAllViews: public SALOME_Event
2903 typedef bool TResult;
2906 : myResult( false ) {}
2907 virtual void Execute()
2909 LightApp_Application* app = getApplication();
2912 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2915 QtxWorkstack* wStack = tabDesk->workstack();
2925 bool SalomePyQt::groupAllViews()
2927 return ProcessEvent( new TGroupAllViews() );
2931 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2932 \brief Split tab area to which view with identifier belongs to
2933 \param id window identifier
2934 \param ori orientation of split operation
2935 \param action action to be performed
2936 \return \c true if operation is completed successfully \c false otherwise
2939 class TSplitView: public SALOME_Event
2942 typedef bool TResult;
2947 TSplitView( const int id,
2948 const Orientation ori,
2949 const Action action )
2950 : myResult( false ),
2953 myAction( action ) {}
2954 virtual void Execute()
2956 SUIT_ViewWindow* wnd = getWnd( myWndId );
2960 // wnd->setFocus(); ???
2963 if ( getApplication() )
2965 STD_TabDesktop* desk =
2966 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2969 QtxWorkstack* wStack = desk->workstack();
2972 Qt::Orientation qtOri =
2973 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2975 QtxWorkstack::SplitType sType;
2976 if ( myAction == MoveWidget )
2977 sType = QtxWorkstack::SplitMove;
2978 else if ( myAction == LeaveWidget )
2979 sType = QtxWorkstack::SplitStay;
2981 sType = QtxWorkstack::SplitAt;
2983 wStack->Split( wnd, qtOri, sType );
2991 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2993 return ProcessEvent( new TSplitView( id, ori, action ) );
2997 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
2998 \brief Move view with the first identifier to the same area which
2999 another view with the second identifier belongs to
3000 \param id source window identifier
3001 \param id_to destination window identifier
3002 param before specifies whether the first viewt has to be moved before or after
3004 \return \c true if operation is completed successfully and \c false otherwise
3007 class TMoveView: public SALOME_Event
3010 typedef bool TResult;
3015 TMoveView( const int id, const int id_to, const bool before )
3016 : myResult( false ),
3019 myIsBefore( before ) {}
3020 virtual void Execute()
3022 SUIT_ViewWindow* wnd = getWnd( myWndId );
3023 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3024 if ( wnd && wnd_to )
3026 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3027 getApplication()->desktop() )->workstack();
3029 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3033 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3035 return ProcessEvent( new TMoveView( id, id_to, before ) );
3039 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3040 \brief Get list of views identifiers that belongs to the same area as
3041 specified view (excluding it)
3042 \param id window identifier
3043 \return list of views identifiers
3046 class TNeighbourViews: public SALOME_Event
3049 typedef QList<int> TResult;
3052 TNeighbourViews( const int id )
3054 virtual void Execute()
3057 SUIT_ViewWindow* wnd = getWnd( myWndId );
3060 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3061 getApplication()->desktop() )->workstack();
3064 QWidgetList wgList = wStack->windowList( wnd );
3066 foreach ( wg, wgList )
3068 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3069 if ( tmpWnd && tmpWnd != wnd )
3070 myResult.append( tmpWnd->getId() );
3076 QList<int> SalomePyQt::neighbourViews( const int id )
3078 return ProcessEvent( new TNeighbourViews( id ) );
3083 \fn QString SalomePyQt::createObject( const QString& parent );
3084 \brief Create empty data object
3085 \param parent entry of parent data object
3086 \return entry of created data object
3089 class TCreateEmptyObjectEvent: public SALOME_Event
3092 typedef QString TResult;
3095 TCreateEmptyObjectEvent( const QString& parent )
3096 : myParent( parent ) {}
3097 virtual void Execute()
3099 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3101 myResult = module->createObject( myParent );
3104 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3108 QString SalomePyQt::createObject( const QString& parent )
3110 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3114 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3115 const QString& tooltip,const QString& parent );
3116 \brief Create new data object with specified name, icon and tooltip
3117 \param name data object name
3118 \param icon data object icon
3119 \param toolTip data object tooltip
3120 \param parent entry of parent data object
3121 \return entry of created data object
3124 class TCreateObjectEvent: public SALOME_Event
3127 typedef QString TResult;
3133 TCreateObjectEvent( const QString& name,
3134 const QString& icon,
3135 const QString& tooltip,
3136 const QString& parent )
3139 myToolTip( tooltip ),
3140 myParent( parent ) {}
3141 virtual void Execute()
3143 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3145 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3148 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3152 QString SalomePyQt::createObject( const QString& name,
3153 const QString& icon,
3154 const QString& toolTip,
3155 const QString& parent )
3157 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3162 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3163 \brief Set data object name
3164 \param entry data object entry
3165 \param name data object name
3167 class TSetNameEvent: public SALOME_Event
3172 TSetNameEvent( const QString& entry,
3173 const QString& name )
3176 virtual void Execute()
3178 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3180 module->setName( myEntry, myName );
3183 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3187 void SalomePyQt::setName( const QString& entry, const QString& name )
3189 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3193 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3194 \brief Set data object icon
3195 \param entry data object entry
3196 \param icon data object icon file name (icon is loaded from module resources)
3199 class TSetIconEvent: public SALOME_Event
3204 TSetIconEvent( const QString& entry,
3205 const QString& icon )
3208 virtual void Execute()
3210 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3212 module->setIcon( myEntry, myIcon );
3215 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3220 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3222 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3226 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3227 \brief Set data object tooltip
3228 \param entry data object entry
3229 \param toolTip data object tooltip
3232 class TSetToolTipEvent: public SALOME_Event
3237 TSetToolTipEvent( const QString& entry,
3238 const QString& toolTip )
3240 myToolTip( toolTip ) {}
3241 virtual void Execute()
3243 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3245 module->setToolTip( myEntry, myToolTip );
3248 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3252 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3254 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3258 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3259 \brief Set reference to another data object
3260 \param entry data object entry
3261 \param refEntry referenced data object entry
3264 class TSetRefEvent: public SALOME_Event
3269 TSetRefEvent( const QString& entry,
3270 const QString& refEntry )
3272 myRefEntry( refEntry ) {}
3273 virtual void Execute()
3275 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3277 module->setReference( myEntry, myRefEntry );
3280 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3284 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3286 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3290 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3291 \brief Set data object color
3292 \param entry data object entry
3293 \param color data object color
3296 class TSetColorEvent: public SALOME_Event
3301 TSetColorEvent( const QString& entry,
3302 const QColor& color )
3305 virtual void Execute()
3307 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3309 module->setColor( myEntry, myColor );
3312 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3316 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3318 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3322 \fn QString SalomePyQt::getName( const QString& entry );
3323 \brief Get data object name
3324 \param entry data object entry
3325 \return data object name
3328 class TGetNameEvent: public SALOME_Event
3331 typedef QString TResult;
3334 TGetNameEvent( const QString& entry )
3335 : myEntry( entry ) {}
3336 virtual void Execute()
3338 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3340 myResult = module->getName( myEntry );
3343 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3347 QString SalomePyQt::getName( const QString& entry )
3349 return ProcessEvent( new TGetNameEvent( entry ) );
3353 \fn QString SalomePyQt::getToolTip( const QString& entry );
3354 \brief Get data object tooltip
3355 \param entry data object entry
3356 \return data object tooltip
3359 class TGetToolTipEvent: public SALOME_Event
3362 typedef QString TResult;
3365 TGetToolTipEvent( const QString& entry )
3366 : myEntry( entry ) {}
3367 virtual void Execute()
3369 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3371 myResult = module->getToolTip( myEntry );
3374 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3378 QString SalomePyQt::getToolTip( const QString& entry )
3380 return ProcessEvent( new TGetToolTipEvent( entry ) );
3384 \fn QString SalomePyQt::getReference( const QString& entry );
3385 \brief Get entry of the referenced object (if there's any)
3386 \param entry data object entry
3387 \return referenced data object entry
3390 class TGetRefEvent: public SALOME_Event
3393 typedef QString TResult;
3396 TGetRefEvent( const QString& entry )
3397 : myEntry( entry ) {}
3398 virtual void Execute()
3400 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3402 myResult = module->getReference( myEntry );
3405 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3409 QString SalomePyQt::getReference( const QString& entry )
3411 return ProcessEvent( new TGetRefEvent( entry ) );
3415 \fn QColor SalomePyQt::getColor( const QString& entry );
3416 \brief Get data object color
3417 \param entry data object entry
3418 \return data object color
3421 class TGetColorEvent: public SALOME_Event
3424 typedef QColor TResult;
3427 TGetColorEvent( const QString& entry )
3428 : myEntry( entry ) {}
3429 virtual void Execute()
3431 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3433 myResult = module->getColor( myEntry );
3436 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3440 QColor SalomePyQt::getColor( const QString& entry )
3442 return ProcessEvent( new TGetColorEvent( entry ) );
3446 \fn void SalomePyQt::removeChildren( const QString& entry );
3447 \brief Remove all child data objects from specified data object
3448 \param entry data object entry
3451 class TRemoveChildEvent: public SALOME_Event
3455 TRemoveChildEvent( const QString& entry )
3456 : myEntry( entry ) {}
3457 virtual void Execute()
3459 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3461 module->removeChildren( myEntry );
3464 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3468 void SalomePyQt::removeChildren( const QString& entry )
3470 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3472 void SalomePyQt::removeChild( const QString& entry )
3474 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3475 removeChildren( entry );
3479 \fn void SalomePyQt::removeObject( const QString& entry );
3480 \brief Remove object by entry
3481 \param entry data object entry
3484 class TRemoveObjectEvent: public SALOME_Event
3489 TRemoveObjectEvent( const QString& entry )
3490 : myEntry( entry ) {}
3491 virtual void Execute()
3493 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3495 module->removeObject( myEntry );
3498 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3502 void SalomePyQt::removeObject( const QString& entry )
3504 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3508 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3509 \brief Get entries of all child data objects of specified data object
3510 \param entry data object entry
3511 \param recursive \c true for recursive processing
3514 class TGetChildrenEvent: public SALOME_Event
3517 typedef QStringList TResult;
3521 TGetChildrenEvent( const QString& entry, const bool recursive )
3523 myRecursive( recursive ) {}
3524 virtual void Execute()
3526 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3528 myResult = module->getChildren( myEntry, myRecursive );
3531 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3535 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3537 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3542 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3543 \brief Display theCurve in view
3544 \param id window identifier
3545 \param theCurve curve to display
3548 class TDisplayCurve: public SALOME_Event
3552 Plot2d_Curve* myCurve;
3553 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3554 virtual void Execute() {
3555 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3558 wnd->getViewFrame()->displayCurve(myCurve);
3562 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3564 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3568 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3569 \brief Erase theCurve in view
3570 \param id window identifier
3571 \param theCurve curve to erase
3574 class TEraseCurve: public SALOME_Event
3578 Plot2d_Curve* myCurve;
3579 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3580 virtual void Execute() {
3581 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3584 wnd->getViewFrame()->eraseCurve(myCurve);
3588 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3590 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3594 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3595 \brief Delete theCurve from all views
3596 \param theCurve curve to delete
3599 class TDeleteCurve: public SALOME_Event
3602 Plot2d_Curve* myCurve;
3603 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3604 virtual void Execute() {
3605 LightApp_Application* app = getApplication();
3608 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3611 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3612 SUIT_ViewWindow* wnd;
3613 foreach ( wnd, wndlist )
3615 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3618 aP2d->getViewFrame()->eraseObject(myCurve);
3625 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3627 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3631 \brief updateCurves (repaint) curves in view window.
3633 void SalomePyQt::updateCurves(const int id)
3635 class TEvent: public SALOME_Event
3639 TEvent( const int id ) : myWndId( id ) {}
3640 virtual void Execute()
3642 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3645 wnd->getViewFrame()->DisplayAll();
3649 ProcessVoidEvent( new TEvent(id) );
3653 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3654 \brief Get title of corresponding type
3655 \param id window identifier
3656 \param type is type of title
3657 \return title of corresponding type
3660 class TGetPlot2dTitle: public SALOME_Event
3663 typedef QString TResult;
3667 TGetPlot2dTitle(const int id, ObjectType type) :
3670 virtual void Execute() {
3671 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3674 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3678 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3680 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3685 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3686 \brief Set title of corresponding type
3687 \param id window identifier
3689 \param type is type of title
3693 class TSetPlot2dTitle: public SALOME_Event
3697 Plot2d_Curve* myCurve;
3701 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3706 virtual void Execute() {
3707 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3710 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3714 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3716 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3720 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3721 \brief Get list of Plot2d view ranges
3722 \param id window identifier
3723 \return list of view ranges (XMin, XMax, YMin, YMax)
3726 class TFitRangeByCurves: public SALOME_Event
3729 typedef QList<double> TResult;
3732 TFitRangeByCurves( const int id )
3734 virtual void Execute()
3737 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3740 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3741 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3742 myResult.append(XMin);
3743 myResult.append(XMax);
3744 myResult.append(YMin);
3745 myResult.append(YMax);
3749 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3751 return ProcessEvent( new TFitRangeByCurves( id ) );
3755 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3756 \brief Get list of current Plot2d view ranges
3757 \param id window identifier
3758 \return list of view ranges (XMin, XMax, YMin, YMax)
3761 class TFitRangeCurrent: public SALOME_Event
3764 typedef QList<double> TResult;
3767 TFitRangeCurrent( const int id )
3769 virtual void Execute()
3772 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3775 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3776 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3777 myResult.append(XMin);
3778 myResult.append(XMax);
3779 myResult.append(YMin);
3780 myResult.append(YMax);
3784 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3786 return ProcessEvent( new TFitRangeCurrent( id ) );
3790 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3791 \brief Set range of Plot2d view
3792 \param id window identifier
3799 class TPlot2dFitRange: public SALOME_Event
3807 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3813 virtual void Execute() {
3814 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3817 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3821 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3823 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3827 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3829 class TEvent: public SALOME_Event
3834 TEvent( const QString& theEntry, int theState):
3835 myEntry(theEntry), myState(theState) {}
3836 virtual void Execute()
3838 LightApp_Study* aStudy = getActiveStudy();
3841 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3844 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3847 class TGetVisibilityStateEvent: public SALOME_Event
3850 typedef int TResult;
3853 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3854 virtual void Execute()
3856 LightApp_Study* aStudy = getActiveStudy();
3858 myResult = aStudy->visibilityState(myEntry);
3862 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3864 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3868 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3870 class TEvent: public SALOME_Event
3875 TEvent( const QString& theEntry, int thePos):
3876 myEntry(theEntry), myPos(thePos) {}
3877 virtual void Execute()
3879 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3881 module->setObjectPosition(myEntry, myPos );
3884 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3889 class TGetObjectPositionEvent: public SALOME_Event
3892 typedef int TResult;
3895 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3896 virtual void Execute()
3898 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3900 myResult = module->getObjectPosition(myEntry);
3904 int SalomePyQt::getObjectPosition( const QString& theEntry )
3906 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );