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 "PVViewer_ViewManager.h"
45 #include "PVViewer_ViewModel.h"
46 #include "QtxActionMenuMgr.h"
47 #include "QtxWorkstack.h"
48 #include "QtxTreeView.h"
49 #include "SALOME_Event.h"
50 #include "STD_TabDesktop.h"
51 #include "SUIT_DataBrowser.h"
52 #include "SUIT_ResourceMgr.h"
53 #include "SUIT_Session.h"
54 #include "SUIT_Tools.h"
55 #include "PyConsole_Console.h"
58 #include <QApplication>
59 #include <QPaintEvent>
60 #include <QCoreApplication>
63 \brief Get the currently active application.
65 \return active application object or 0 if there is no any
67 static LightApp_Application* getApplication()
69 if ( SUIT_Session::session() )
70 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
75 \brief Get the currently active study.
77 \return active study or 0 if there is no study opened
79 static LightApp_Study* getActiveStudy()
81 if ( getApplication() )
82 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
87 \brief Get the currently active module.
89 This function returns correct result only if Python-based
90 module is currently active. Otherwize, 0 is returned.
92 static LightApp_Module* getActiveModule()
94 LightApp_Module* module = 0;
95 if ( LightApp_Application* anApp = getApplication() ) {
96 module = PyModuleHelper::getInitModule();
98 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
104 \brief Get the currently active Python module's helper.
106 This function returns correct result only if Python-based
107 module is currently active. Otherwize, 0 is returned.
109 static PyModuleHelper* getPythonHelper()
111 LightApp_Module* module = getActiveModule();
112 PyModuleHelper* helper = module ? qFindChild<PyModuleHelper*>( module, "python_module_helper" ) : 0;
117 \brief Get SALOME verbose level
119 \return \c true if SALOME debug output is allowed or \c false otherwise
121 static bool verbose()
123 bool isVerbose = false;
124 if ( getenv( "SALOME_VERBOSE" ) ) {
125 QString envVar = getenv( "SALOME_VERBOSE" );
127 int value = envVar.toInt( &ok );
128 isVerbose = ok && value != 0;
134 \class SALOME_Selection
135 \brief The class represents selection which can be used in Python.
139 \brief Map of created selection objects.
142 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
145 \brief Get the selection object for the specified application.
147 Finds or creates the selection object (one per study).
149 \param app application object
150 \return selection object or 0 if \a app is invalid
152 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
154 SALOME_Selection* sel = 0;
155 if ( app && SelMap.find( app ) != SelMap.end() )
158 sel = SelMap[ app ] = new SALOME_Selection( app );
164 \param p parent object
166 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
168 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
170 mySelMgr = app->selectionMgr();
171 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
172 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
179 SALOME_Selection::~SALOME_Selection()
181 LightApp_Application* app = 0;
182 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
183 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
184 if ( it.value() == this ) app = it.key();
186 if ( app ) SelMap.remove( app );
190 \brief Called when selection manager is destroyed (usually
191 when the study is closed).
193 void SALOME_Selection::onSelMgrDestroyed()
199 \brief Clear the selection.
201 void SALOME_Selection::Clear()
203 class TEvent: public SALOME_Event
205 LightApp_SelectionMgr* mySelMgr;
207 TEvent( LightApp_SelectionMgr* selMgr )
208 : mySelMgr( selMgr ) {}
209 virtual void Execute()
212 mySelMgr->clearSelected();
215 ProcessVoidEvent( new TEvent( mySelMgr ) );
219 \brief Clear the selection.
221 void SALOME_Selection::ClearIObjects()
227 Removes all selection filters.
229 void SALOME_Selection::ClearFilters()
231 class TEvent: public SALOME_Event
233 LightApp_SelectionMgr* mySelMgr;
235 TEvent( LightApp_SelectionMgr* selMgr )
236 : mySelMgr( selMgr ) {}
237 virtual void Execute()
240 mySelMgr->clearFilters();
243 ProcessVoidEvent( new TEvent( mySelMgr ) );
248 \brief The class provides utility functions which can be used in the Python
249 to operate with the SALOME GUI.
251 All the functionality of this class is implemented as static methods, so they
252 can be called with the class name prefixed or via creation of the class instance.
253 For example, next both ways of SalomePyQt class usage are legal:
255 from SalomePyQt import *
257 # using SalomePyQt class instance
258 desktop = sg.getDesktop()
259 # using SalomePyQt class directly
260 menubar = SalomePyQt.getMainMenuBar()
265 \fn QWidget* SalomePyQt::getDesktop();
266 \brief Get the active application's desktop window.
267 \return desktop window or 0 if there is no any
270 class TGetDesktopEvent: public SALOME_Event
273 typedef QWidget* TResult;
275 TGetDesktopEvent() : myResult( 0 ) {}
276 virtual void Execute()
278 if ( getApplication() )
279 myResult = (QWidget*)( getApplication()->desktop() );
282 QWidget* SalomePyQt::getDesktop()
284 return ProcessEvent( new TGetDesktopEvent() );
288 \fn QWidget* SalomePyQt::getMainFrame();
289 \brief Get current application's main frame widget [obsolete].
291 Main frame widget is an internal widget of the application
292 desktop window (workspace).
294 \return workspace widget (0 on any error)
297 class TGetMainFrameEvent: public SALOME_Event
300 typedef QWidget* TResult;
302 TGetMainFrameEvent() : myResult( 0 ) {}
303 virtual void Execute()
305 if ( getApplication() ) {
306 SUIT_Desktop* aDesktop = getApplication()->desktop();
307 myResult = (QWidget*)( aDesktop->centralWidget() );
311 QWidget* SalomePyQt::getMainFrame()
313 return ProcessEvent( new TGetMainFrameEvent() );
317 \fn QMenuBar* SalomePyQt::getMainMenuBar();
318 \brief Get current application desktop's main menu.
319 \return main menu object (0 on any error)
322 class TGetMainMenuBarEvent: public SALOME_Event
325 typedef QMenuBar* TResult;
327 TGetMainMenuBarEvent() : myResult( 0 ) {}
328 virtual void Execute()
330 if ( LightApp_Application* anApp = getApplication() ) {
331 myResult = anApp->desktop()->menuBar();
335 QMenuBar* SalomePyQt::getMainMenuBar()
337 return ProcessEvent( new TGetMainMenuBarEvent() );
341 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
342 \brief Get main menu's child popup submenu by its identifier.
344 This function is obsolete.
345 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
347 \param menu menu identifier
348 \return popup submenu object or 0 if it does not exist
352 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
353 \brief Get main menu's child popup submenu by its name.
355 The function creates menu if it does not exist.
357 \param menu menu name
358 \return popup submenu object (0 on any error)
361 class TGetPopupMenuEvent: public SALOME_Event
364 typedef QMenu* TResult;
367 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
368 virtual void Execute()
370 LightApp_Application* anApp = getApplication();
371 if ( anApp && !myMenuName.isEmpty() ) {
372 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
373 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
379 \brief Get menu item title
381 \param menuId menu identifier
382 \return menu title (localized)
384 static QString getMenuName( const QString& menuId )
386 QStringList contexts;
387 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
388 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
389 QString menuName = menuId;
390 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
391 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
395 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
400 menuName = getMenuName( "MEN_DESK_FILE" ); break;
402 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
404 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
406 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
408 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
410 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
412 menuName = getMenuName( "MEN_DESK_HELP" ); break;
414 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
416 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
418 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
422 \fn QTreeView* SalomePyQt::getObjectBrowser();
423 \brief Get object browser
424 \return object browser for the active study or 0 in case of error
427 class TGetObjectBrowserEvent: public SALOME_Event
430 typedef QTreeView* TResult;
432 TGetObjectBrowserEvent() : myResult( 0 ) {}
433 virtual void Execute()
435 LightApp_Application* anApp = getApplication();
437 myResult = anApp->objectBrowser()->treeView();
441 QTreeView* SalomePyQt::getObjectBrowser()
443 return ProcessEvent( new TGetObjectBrowserEvent() );
447 \fn int SalomePyQt::getStudyId();
448 \brief Get active study's identifier.
449 \return active study ID or 0 if there is no active study
452 class TGetStudyIdEvent: public SALOME_Event
457 TGetStudyIdEvent() : myResult( 0 ) {}
458 virtual void Execute()
460 if ( LightApp_Study* aStudy = getActiveStudy() ) {
461 myResult = aStudy->id();
465 int SalomePyQt::getStudyId()
467 return ProcessEvent( new TGetStudyIdEvent() );
471 \fn SALOME_Selection* SalomePyQt::getSelection();
472 \brief Get the selection object for the current study.
474 Creates a Selection object if it has not been created yet.
476 \return selection object (0 on error)
479 class TGetSelectionEvent: public SALOME_Event
482 typedef SALOME_Selection* TResult;
484 TGetSelectionEvent() : myResult( 0 ) {}
485 virtual void Execute()
487 myResult = SALOME_Selection::GetSelection( getApplication() );
490 SALOME_Selection* SalomePyQt::getSelection()
492 return ProcessEvent( new TGetSelectionEvent() );
496 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
497 \brief Put an information message to the current application's
500 Optional second delay parameter (\a sec) can be used to specify
501 time of the message diplaying in seconds. If this parameter is less
502 or equal to zero, the constant message will be put.
504 \param msg message text
505 \param sec message displaying time in seconds
508 class TPutInfoEvent: public SALOME_Event
513 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
514 virtual void Execute()
516 if ( LightApp_Application* anApp = getApplication() ) {
517 anApp->putInfo( myMsg, mySecs * 1000 );
521 void SalomePyQt::putInfo( const QString& msg, const int sec )
523 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
527 \fn const QString SalomePyQt::getActiveComponent();
528 \brief Get the currently active module name (for the current study).
529 \return active module name or empty string if there is no active module
532 class TGetActiveComponentEvent: public SALOME_Event
535 typedef QString TResult;
537 TGetActiveComponentEvent() {}
538 virtual void Execute()
540 if ( LightApp_Application* anApp = getApplication() ) {
541 if ( CAM_Module* mod = anApp->activeModule() ) {
542 myResult = mod->name();
547 const QString SalomePyQt::getActiveComponent()
549 return ProcessEvent( new TGetActiveComponentEvent() );
553 \fn PyObject* SalomePyQt::getActivePythonModule();
554 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
555 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
558 class TGetActivePyModuleEvent: public SALOME_Event
561 typedef PyObject* TResult;
563 TGetActivePyModuleEvent() : myResult( Py_None ) {}
564 virtual void Execute()
566 PyModuleHelper* helper = getPythonHelper();
568 myResult = (PyObject*)helper->pythonModule();
571 PyObject* SalomePyQt::getActivePythonModule()
573 return ProcessEvent( new TGetActivePyModuleEvent() );
577 \fn bool SalomePyQt::activateModule( const QString& modName );
578 \brief Activates SALOME module with the given name
579 \return True if the module has been activated and False otherwise.
582 class TActivateModuleEvent: public SALOME_Event
585 typedef bool TResult;
587 QString myModuleName;
588 TActivateModuleEvent( const QString& modName )
589 : myResult( false ), myModuleName( modName ) {}
590 virtual void Execute()
592 if ( LightApp_Application* anApp = getApplication() ) {
593 myResult = anApp->activateModule( myModuleName );
597 bool SalomePyQt::activateModule( const QString& modName )
599 return ProcessEvent( new TActivateModuleEvent( modName ) );
603 \brief Update an Object Browser of the specified (by identifier) study.
605 If \a studyId <= 0 the active study's object browser is updated.
606 The \a updateSelection parameter is obsolete and currently is not used.
607 This parameter will be removed in future, so try to avoid its usage in
610 \brief studyId study identifier
611 \brief updateSelection update selection flag (not used)
614 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
616 class TEvent: public SALOME_Event
619 bool myUpdateSelection;
621 TEvent( const int studyId, bool updateSelection )
622 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
623 virtual void Execute()
625 if ( SUIT_Session::session() ) {
626 if ( getActiveStudy() && myStudyId <= 0 )
627 myStudyId = getActiveStudy()->id();
628 if ( myStudyId > 0 ) {
629 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
630 QList<SUIT_Application*>::Iterator it;
631 for( it = apps.begin(); it != apps.end(); ++it ) {
632 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
633 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
634 anApp->updateObjectBrowser();
642 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
647 SalomePyQt::isModified()
648 \return The modification status of the data model
649 for the currently active Python module
650 \note This function is supported for "light" Python-based SALOME modules only.
653 class TIsModifiedEvent: public SALOME_Event
656 typedef bool TResult;
658 TIsModifiedEvent() : myResult( false ) {}
659 virtual void Execute()
661 LightApp_Module* module = getActiveModule();
665 SALOME_PYQT_DataModelLight* aModel =
666 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
668 myResult = aModel->isModified();
671 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
675 bool SalomePyQt::isModified()
677 return ProcessEvent(new TIsModifiedEvent());
681 SalomePyQt::setModified()
683 Sets the modification status of the data model for
684 the currently active Python module. This method should be used
685 by the Python code in order to enable/disable "Save" operation
686 depending on the module's data state.
688 \note This function is supported for "light" Python-based SALOME modules only.
690 \param New modification status of the data model
694 void SalomePyQt::setModified( bool flag )
696 class TEvent: public SALOME_Event
702 virtual void Execute()
704 LightApp_Module* module = getActiveModule();
708 SALOME_PYQT_DataModelLight* model =
709 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
711 LightApp_Application* app = module->getApp();
713 if ( model && app ) {
714 model->setModified( myFlag );
715 app->updateActions();
718 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
722 ProcessVoidEvent( new TEvent( flag ) );
726 \brief Default resource file section name.
729 static const char* DEFAULT_SECTION = "SalomePyQt";
732 \brief Add string setting to the application preferences.
734 The parameter \a autoValue is obsolete parameter and currently is not used.
735 This parameter will be removed in future, so try to avoid its usage in
738 This function is obsolete. Use one of addSetting() instead.
740 \param name setting name (it should be of kind <section:setting> where
741 \c section is resources section name and \c setting is setting name)
742 \param value new setting value
743 \param autoValue (not used)
745 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
747 class TEvent: public SALOME_Event
753 TEvent( const QString& name, const QString& value, bool autoValue )
754 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
755 virtual void Execute()
757 if ( SUIT_Session::session() ) {
758 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
759 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
760 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
761 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
762 if ( !_sec.isEmpty() && !_nam.isEmpty() )
763 resMgr->setValue( _sec, _nam, myValue );
767 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
771 \brief Add integer setting to the application preferences.
773 The parameter \a autoValue is obsolete parameter and currently is not used.
774 This parameter will be removed in future, so try to avoid its usage in
777 This function is obsolete. Use one of addSetting() instead.
779 \param name setting name (it should be of kind <section:setting> where
780 \c section is resources section name and \c setting is setting name)
781 \param value new setting value
782 \param autoValue (not used)
784 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
786 class TEvent: public SALOME_Event
792 TEvent( const QString& name, const int value, bool autoValue )
793 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
794 virtual void Execute()
796 if ( SUIT_Session::session() ) {
797 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
798 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
799 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
800 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
801 if ( !_sec.isEmpty() && !_nam.isEmpty() )
802 resMgr->setValue( _sec, _nam, myValue );
806 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
810 \brief Add double setting to the application preferences.
812 The parameter \a autoValue is obsolete parameter and currently is not used.
813 This parameter will be removed in future, so try to avoid its usage in
816 This function is obsolete. Use one of addSetting() instead.
818 \param name setting name (it should be of kind <section:setting> where
819 \c section is resources section name and \c setting is setting name)
820 \param value new setting value
821 \param autoValue (not used)
823 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
825 class TEvent: public SALOME_Event
831 TEvent( const QString& name, const double value, bool autoValue )
832 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
833 virtual void Execute()
835 if ( SUIT_Session::session() ) {
836 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
837 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
838 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
839 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
840 if ( !_sec.isEmpty() && !_nam.isEmpty() )
841 resMgr->setValue( _sec, _nam, myValue );
845 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
849 \brief Add boolean setting to the application preferences.
851 The parameter \a autoValue is obsolete parameter and currently is not used.
852 This parameter will be removed in future, so try to avoid its usage in
855 This function is obsolete. Use one of addSetting() instead.
857 \param name setting name (it should be of kind <section:setting> where
858 \c section is resources section name and \c setting is setting name)
859 \param value new setting value
860 \param autoValue (not used)
862 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
864 class TEvent: public SALOME_Event
870 TEvent( const QString& name, const bool value, bool autoValue )
871 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
872 virtual void Execute()
874 if ( SUIT_Session::session() ) {
875 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
876 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
877 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
878 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
879 if ( !_sec.isEmpty() && !_nam.isEmpty() )
880 resMgr->setValue( _sec, _nam, myValue );
884 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
888 \brief Remove setting from the application preferences.
890 This function is obsolete. Use removeSetting() instead.
892 \param name setting name (it should be of kind <section:setting> where
893 \c section is resources section name and \c setting is setting name)
895 void SalomePyQt::removeSettings( const QString& name )
897 class TEvent: public SALOME_Event
901 TEvent( const QString& name ) : myName( name ) {}
902 virtual void Execute()
904 if ( SUIT_Session::session() ) {
905 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
906 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
907 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
908 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
909 if ( !_sec.isEmpty() && !_nam.isEmpty() )
910 resMgr->remove( _sec, _nam );
914 ProcessVoidEvent( new TEvent( name ) );
918 \fn QString SalomePyQt::getSetting( const QString& name );
919 \brief Get application setting value (as string represenation).
921 This function is obsolete. Use stringSetting(), integerSetting(),
922 boolSetting(), stringSetting() or colorSetting() instead.
924 \param name setting name (it should be of kind <section:setting> where
925 \c section is resources section name and \c setting is setting name)
926 \return setting name (empty string if setting name is invalid)
929 class TGetSettingEvent: public SALOME_Event
932 typedef QString TResult;
935 TGetSettingEvent( const QString& name ) : myName( name ) {}
936 virtual void Execute()
938 if ( SUIT_Session::session() ) {
939 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
940 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
941 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
942 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
943 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
947 QString SalomePyQt::getSetting( const QString& name )
949 return ProcessEvent( new TGetSettingEvent( name ) );
953 \brief Add double setting to the application preferences.
954 \param section resources file section name
955 \param name setting name
956 \param value new setting value
958 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
960 class TEvent: public SALOME_Event
966 TEvent( const QString& section, const QString& name, double value )
967 : mySection( section ), myName( name ), myValue( value ) {}
968 virtual void Execute()
970 if ( SUIT_Session::session() ) {
971 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
972 if ( !mySection.isEmpty() && !myName.isEmpty() )
973 resMgr->setValue( mySection, myName, myValue );
977 ProcessVoidEvent( new TEvent( section, name, value ) );
981 \brief Add integer setting to the application preferences.
982 \param section resources file section name
983 \param name setting name
984 \param value new setting value
986 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
988 class TEvent: public SALOME_Event
994 TEvent( const QString& section, const QString& name, int value )
995 : mySection( section ), myName( name ), myValue( value ) {}
996 virtual void Execute()
998 if ( SUIT_Session::session() ) {
999 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1000 if ( !mySection.isEmpty() && !myName.isEmpty() )
1001 resMgr->setValue( mySection, myName, myValue );
1005 ProcessVoidEvent( new TEvent( section, name, value ) );
1009 \brief Add boolean setting to the application preferences.
1010 \param section resources file section name
1011 \param name setting name
1012 \param value new setting value
1013 \param dumb this parameter is used in order to avoid sip compilation error
1014 because of conflicting int and bool types
1016 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1018 class TEvent: public SALOME_Event
1024 TEvent( const QString& section, const QString& name, bool value )
1025 : mySection( section ), myName( name ), myValue( value ) {}
1026 virtual void Execute()
1028 if ( SUIT_Session::session() ) {
1029 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1030 if ( !mySection.isEmpty() && !myName.isEmpty() )
1031 resMgr->setValue( mySection, myName, myValue );
1035 ProcessVoidEvent( new TEvent( section, name, value ) );
1039 \brief Add string setting to the application preferences.
1040 \param section resources file section name
1041 \param name setting name
1042 \param value new setting value
1044 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1046 class TEvent: public SALOME_Event
1052 TEvent( const QString& section, const QString& name, const QString& value )
1053 : mySection( section ), myName( name ), myValue( value ) {}
1054 virtual void Execute()
1056 if ( SUIT_Session::session() ) {
1057 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1058 if ( !mySection.isEmpty() && !myName.isEmpty() )
1059 resMgr->setValue( mySection, myName, myValue );
1063 ProcessVoidEvent( new TEvent( section, name, value ) );
1067 \brief Add color setting to the application preferences.
1068 \param section resources file section name
1069 \param name setting name
1070 \param value new setting value
1072 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1074 class TEvent: public SALOME_Event
1080 TEvent( const QString& section, const QString& name, const QColor& value )
1081 : mySection( section ), myName( name ), myValue( value ) {}
1082 virtual void Execute()
1084 if ( SUIT_Session::session() ) {
1085 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1086 if ( !mySection.isEmpty() && !myName.isEmpty() )
1087 resMgr->setValue( mySection, myName, myValue );
1091 ProcessVoidEvent( new TEvent( section, name, value ) );
1095 \fn int SalomePyQt::integerSetting( const QString& section,
1096 const QString& name,
1098 \brief Get integer setting from the application preferences.
1099 \param section resources file section name
1100 \param name setting name
1101 \param def default value which is returned if the setting is not found
1102 \return setting value
1105 class TGetIntSettingEvent: public SALOME_Event
1108 typedef int TResult;
1113 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1114 : mySection( section ), myName( name ), myDefault( def ) {}
1115 virtual void Execute()
1117 if ( SUIT_Session::session() ) {
1118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1119 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1123 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1125 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1129 \fn double SalomePyQt::doubleSetting( const QString& section,
1130 const QString& name,
1132 \brief Get double setting from the application preferences.
1133 \param section resources file section name
1134 \param name setting name
1135 \param def default value which is returned if the setting is not found
1136 \return setting value
1139 class TGetDblSettingEvent: public SALOME_Event
1142 typedef double TResult;
1147 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1148 : mySection( section ), myName( name ), myDefault( def ) {}
1149 virtual void Execute()
1151 if ( SUIT_Session::session() ) {
1152 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1153 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1157 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1159 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1163 \fn bool SalomePyQt::boolSetting( const QString& section,
1164 const QString& name,
1166 \brief Get boolean setting from the application preferences.
1167 \param section resources file section name
1168 \param name setting name
1169 \param def default value which is returned if the setting is not found
1170 \return setting value
1173 class TGetBoolSettingEvent: public SALOME_Event
1176 typedef bool TResult;
1181 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1182 : mySection( section ), myName( name ), myDefault( def ) {}
1183 virtual void Execute()
1185 if ( SUIT_Session::session() ) {
1186 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1187 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1191 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1193 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1197 \fn QString SalomePyQt::stringSetting( const QString& section,
1198 const QString& name,
1199 const QString& def );
1200 \brief Get string setting from the application preferences.
1201 \param section resources file section name
1202 \param name setting name
1203 \param def default value which is returned if the setting is not found
1204 \return setting value
1207 class TGetStrSettingEvent: public SALOME_Event
1210 typedef QString TResult;
1215 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1216 : mySection( section ), myName( name ), myDefault( def ) {}
1217 virtual void Execute()
1219 if ( SUIT_Session::session() ) {
1220 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1221 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1225 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1227 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1231 \fn QColor SalomePyQt::colorSetting( const QString& section,
1232 const QString& name,
1234 \brief Get color setting from the application preferences.
1235 \param section resources file section name
1236 \param name setting name
1237 \param def default value which is returned if the setting is not found
1238 \return setting value
1241 class TGetColorSettingEvent: public SALOME_Event
1244 typedef QColor TResult;
1249 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1250 : mySection( section ), myName( name ), myDefault( def ) {}
1251 virtual void Execute()
1253 if ( SUIT_Session::session() ) {
1254 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1255 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1259 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1261 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1265 \brief Remove setting from the application preferences.
1266 \param section resources file section name
1267 \param name setting name
1269 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1271 class TEvent: public SALOME_Event
1276 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1277 virtual void Execute()
1279 if ( SUIT_Session::session() ) {
1280 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1281 if ( !mySection.isEmpty() && !myName.isEmpty() )
1282 resMgr->remove( mySection, myName );
1286 ProcessVoidEvent( new TEvent( section, name ) );
1290 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1291 \brief Check setting existence in the application preferences.
1292 \param section resources file section name
1293 \param name setting name
1294 \return \c true if setting exists
1297 class THasColorSettingEvent: public SALOME_Event
1300 typedef bool TResult;
1304 THasColorSettingEvent( const QString& section, const QString& name )
1305 : mySection( section ), myName( name ) {}
1306 virtual void Execute()
1308 if ( SUIT_Session::session() ) {
1309 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1310 myResult = resMgr->hasValue( mySection, myName );
1314 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1316 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1320 \fn QString SalomePyQt::getFileName( QWidget* parent,
1321 const QString& initial,
1322 const QStringList& filters,
1323 const QString& caption,
1325 \brief Show 'Open/Save file' dialog box for file selection
1326 and return a user's choice (selected file name).
1327 \param parent parent widget
1328 \param initial initial directory the dialog box to be opened in
1329 \param filters list of files filters (wildcards)
1330 \param caption dialog box title
1331 \param open if \c true, "Open File" dialog box is shown;
1332 otherwise "Save File" dialog box is shown
1333 \return selected file name (null string if user cancels operation)
1336 class TGetFileNameEvent: public SALOME_Event
1339 typedef QString TResult;
1343 QStringList myFilters;
1346 TGetFileNameEvent( QWidget* parent,
1347 const QString& initial,
1348 const QStringList& filters,
1349 const QString& caption,
1351 : myParent ( parent ),
1352 myInitial( initial ),
1353 myFilters( filters ),
1354 myCaption( caption ),
1356 virtual void Execute()
1358 if ( LightApp_Application* anApp = getApplication() ) {
1359 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1360 myCaption, myParent );
1364 QString SalomePyQt::getFileName( QWidget* parent,
1365 const QString& initial,
1366 const QStringList& filters,
1367 const QString& caption,
1370 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1374 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1375 const QString& initial,
1376 const QStringList& filters,
1377 const QString& caption );
1378 \brief Show 'Open files' dialog box for multiple files selection
1379 and return a user's choice (selected file names list).
1380 \param parent parent widget
1381 \param initial initial directory the dialog box to be opened in
1382 \param filters list of files filters (wildcards)
1383 \param caption dialog box title
1384 \return selected file names list (empty list if user cancels operation)
1387 class TGetOpenFileNamesEvent: public SALOME_Event
1390 typedef QStringList TResult;
1394 QStringList myFilters;
1396 TGetOpenFileNamesEvent( QWidget* parent,
1397 const QString& initial,
1398 const QStringList& filters,
1399 const QString& caption )
1400 : myParent ( parent ),
1401 myInitial( initial ),
1402 myFilters( filters ),
1403 myCaption( caption ) {}
1404 virtual void Execute()
1406 if ( LightApp_Application* anApp = getApplication() ) {
1407 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1411 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1412 const QString& initial,
1413 const QStringList& filters,
1414 const QString& caption )
1416 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1420 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1421 const QString& initial,
1422 const QString& caption );
1423 \brief Show 'Get Directory' dialog box for the directory selection
1424 and return a user's choice (selected directory name).
1425 \param parent parent widget
1426 \param initial initial directory the dialog box to be opened in
1427 \param caption dialog box title
1428 \return selected directory name (null string if user cancels operation)
1431 class TGetExistingDirectoryEvent: public SALOME_Event
1434 typedef QString TResult;
1439 TGetExistingDirectoryEvent( QWidget* parent,
1440 const QString& initial,
1441 const QString& caption )
1442 : myParent ( parent ),
1443 myInitial( initial ),
1444 myCaption( caption ) {}
1445 virtual void Execute()
1447 if ( LightApp_Application* anApp = getApplication() ) {
1448 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1452 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1453 const QString& initial,
1454 const QString& caption )
1456 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1460 \fn QString SalomePyQt::loadIcon( const QString& filename );
1461 \brief Load an icon from the module resources by the specified file name.
1462 \param fileName icon file name
1466 static QIcon loadIconInternal( const QString& module, const QString& fileName )
1470 LightApp_Application* app = getApplication();
1472 if ( app && !fileName.isEmpty() ) {
1473 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
1474 QApplication::translate( module.toLatin1().data(),
1475 fileName.toLatin1().data() ) );
1476 if ( !pixmap.isNull() )
1477 icon = QIcon( pixmap );
1482 class TLoadIconEvent: public SALOME_Event
1485 typedef QIcon TResult;
1489 TLoadIconEvent( const QString& module, const QString& filename )
1490 : myModule( module ),
1491 myFileName ( filename ) {}
1492 virtual void Execute()
1494 myResult = loadIconInternal( myModule, myFileName );
1497 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1499 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1503 \brief Open external browser to display context help information.
1506 Current implementation does nothing.
1508 \param source documentation (HTML) file name
1509 \param context context (for example, HTML ancor name)
1511 void SalomePyQt::helpContext( const QString& source, const QString& context )
1513 class TEvent: public SALOME_Event
1518 TEvent( const QString& source, const QString& context )
1519 : mySource( source ), myContext( context ) {}
1520 virtual void Execute()
1522 if ( LightApp_Application* anApp = getApplication() ) {
1523 anApp->onHelpContextModule( "", mySource, myContext );
1527 ProcessVoidEvent( new TEvent( source, context ) );
1531 \fn int SalomePyQt::defaultMenuGroup();
1532 \brief Get detault menu group identifier which can be used when
1533 creating menus (insert custom menu commands).
1534 \return default menu group ID
1537 class TDefMenuGroupEvent: public SALOME_Event
1540 typedef int TResult;
1542 TDefMenuGroupEvent() : myResult( -1 ) {}
1543 virtual void Execute()
1545 myResult = PyModuleHelper::defaultMenuGroup();
1548 int SalomePyQt::defaultMenuGroup()
1550 return ProcessEvent( new TDefMenuGroupEvent() );
1556 CrTool( const QString& tBar, const QString& nBar )
1557 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1558 CrTool( const int id, const int tBar, const int idx )
1559 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1560 CrTool( const int id, const QString& tBar, const int idx )
1561 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1562 CrTool( QAction* action, const int tbId, const int id, const int idx )
1563 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1564 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1565 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1567 int execute( LightApp_Module* module ) const
1572 return module->createTool( myTbTitle, myTbName );
1574 return module->createTool( myId, myTbId, myIndex );
1576 return module->createTool( myId, myTbTitle, myIndex );
1578 return module->createTool( myAction, myTbId, myId, myIndex );
1580 return module->createTool( myAction, myTbTitle, myId, myIndex );
1595 class TCreateToolEvent: public SALOME_Event
1598 typedef int TResult;
1600 const CrTool& myCrTool;
1601 TCreateToolEvent( const CrTool& crTool )
1602 : myResult( -1 ), myCrTool( crTool ) {}
1603 virtual void Execute()
1605 LightApp_Module* module = getActiveModule();
1607 myResult = myCrTool.execute( module );
1612 \brief Create toolbar with specified name.
1613 \param tBar toolbar title (language-dependent)
1614 \param nBar toolbar name (language-independent) [optional]
1615 \return toolbar ID or -1 if toolbar creation is failed
1617 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1619 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1623 \brief Insert action with specified \a id to the toolbar.
1625 \param tBar toolbar ID
1626 \param idx required index in the toolbar
1627 \return action ID or -1 if action could not be added
1629 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1631 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1635 \brief Insert action with specified \a id to the toolbar.
1637 \param tBar toolbar name
1638 \param idx required index in the toolbar
1639 \return action ID or -1 if action could not be added
1641 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1643 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1647 \brief Insert action to the toolbar.
1649 \param tBar toolbar ID
1650 \param id required action ID
1651 \param idx required index in the toolbar
1652 \return action ID or -1 if action could not be added
1654 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1656 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1660 \brief Insert action to the toolbar.
1662 \param tBar toolbar name
1663 \param id required action ID
1664 \param idx required index in the toolbar
1665 \return action ID or -1 if action could not be added
1667 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1669 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1675 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1676 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1677 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1678 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1679 CrMenu( const int id, const int menu, const int group, const int idx )
1680 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1681 CrMenu( const int id, const QString& menu, const int group, const int idx )
1682 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1683 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1684 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1685 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1686 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1688 int execute( LightApp_Module* module ) const
1693 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1695 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1697 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1699 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1701 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1703 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1712 QString mySubMenuName;
1719 class TCreateMenuEvent: public SALOME_Event
1722 typedef int TResult;
1724 const CrMenu& myCrMenu;
1725 TCreateMenuEvent( const CrMenu& crMenu )
1726 : myResult( -1 ), myCrMenu( crMenu ) {}
1727 virtual void Execute()
1729 LightApp_Module* module = getActiveModule();
1731 myResult = myCrMenu.execute( module );
1736 \brief Create main menu.
1737 \param subMenu menu name
1738 \param menu parent menu ID
1739 \param id required menu ID
1740 \param group menu group ID
1741 \param idx required index in the menu
1742 \return menu ID or -1 if menu could not be added
1744 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1746 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1750 \brief Create main menu.
1751 \param subMenu menu name
1752 \param menu parent menu name (list of menu names separated by "|")
1753 \param id required menu ID
1754 \param group menu group ID
1755 \param idx required index in the menu
1756 \return menu ID or -1 if menu could not be added
1758 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1760 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1764 \brief Insert action to the main menu.
1766 \param menu parent menu ID
1767 \param group menu group ID
1768 \param idx required index in the menu
1769 \return action ID or -1 if action could not be added
1771 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1773 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1777 \brief Insert action to the main menu.
1779 \param menu parent menu name (list of menu names separated by "|")
1780 \param group menu group ID
1781 \param idx required index in the menu
1782 \return action ID or -1 if action could not be added
1784 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1786 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1790 \brief Insert action to the main menu.
1792 \param menu parent menu ID
1793 \param group menu group ID
1794 \param idx required index in the menu
1795 \return action ID or -1 if action could not be added
1797 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1799 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1803 \brief Insert action to the main menu.
1805 \param menu parent menu name (list of menu names separated by "|")
1806 \param group menu group ID
1807 \param idx required index in the menu
1808 \return action ID or -1 if action could not be added
1810 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1812 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1816 \fn QAction* SalomePyQt::createSeparator();
1817 \brief Create separator action which can be used in the menu or toolbar.
1818 \return new separator action
1821 class TCreateSepEvent: public SALOME_Event
1824 typedef QAction* TResult;
1828 virtual void Execute()
1830 LightApp_Module* module = getActiveModule();
1832 myResult = (QAction*)module->separator();
1835 QAction* SalomePyQt::createSeparator()
1837 return ProcessEvent( new TCreateSepEvent() );
1841 \fn QAction* SalomePyQt::createAction( const int id,
1842 const QString& menuText,
1843 const QString& tipText,
1844 const QString& statusText,
1845 const QString& icon,
1847 const bool toggle );
1848 \brief Create an action which can be then used in the menu or toolbar.
1849 \param id the unique id action to be registered to
1850 \param menuText action text which should appear in menu
1851 \param tipText text which should appear in the tooltip
1852 \param statusText text which should appear in the status bar when action is activated
1853 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1854 \param key the key accelrator for the action
1855 \param toggle if \c true the action is checkable
1858 class TCreateActionEvent: public SALOME_Event
1861 typedef QAction* TResult;
1866 QString myStatusText;
1870 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1871 const QString& statusText, const QString& icon, const int key, const bool toggle )
1872 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1873 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1874 virtual void Execute()
1876 LightApp_Module* module = getActiveModule();
1878 QIcon icon = loadIconInternal( module->name(), myIcon );
1879 myResult = (QAction*)module->action( myId );
1881 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1882 myResult->setToolTip( myTipText );
1883 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1884 myResult->setText( myMenuText );
1885 if ( myResult->icon().isNull() && !icon.isNull() )
1886 myResult->setIcon( icon );
1887 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1888 myResult->setStatusTip( myStatusText );
1889 if ( myResult->shortcut().isEmpty() && myKey )
1890 myResult->setShortcut( myKey );
1891 if ( myResult->isCheckable() != myToggle )
1892 myResult->setCheckable( myToggle );
1895 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1897 // for Python module, automatically connect action to callback slot
1898 PyModuleHelper* helper = qFindChild<PyModuleHelper*>( module, "python_module_helper" );
1899 if ( helper ) helper->connectAction( myResult );
1903 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1904 const QString& tipText, const QString& statusText,
1905 const QString& icon, const int key, const bool toggle )
1907 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1911 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1912 \brief Create an action group which can be then used in the menu or toolbar
1913 \param id : the unique id action group to be registered to
1914 \param exclusive : if \c true the action group does exclusive toggling
1917 struct TCreateActionGroupEvent: public SALOME_Event
1919 typedef QtxActionGroup* TResult;
1923 TCreateActionGroupEvent( const int id, const bool exclusive )
1924 : myId( id ), myExclusive( exclusive ) {}
1925 virtual void Execute()
1927 LightApp_Module* module = getActiveModule();
1929 myResult = module->createActionGroup( myId, myExclusive );
1932 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1934 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1938 \fn QAction* SalomePyQt::action( const int id );
1939 \brief Get action by specified identifier.
1940 \return action or 0 if action is not registered
1943 class TActionEvent: public SALOME_Event
1946 typedef QAction* TResult;
1949 TActionEvent( const int id )
1950 : myResult( 0 ), myId( id ) {}
1951 virtual void Execute()
1953 LightApp_Module* module = getActiveModule();
1955 myResult = (QAction*)module->action( myId );
1958 QAction* SalomePyQt::action( const int id )
1960 return ProcessEvent( new TActionEvent( id ) );
1964 \fn int SalomePyQt::actionId( const QAction* a );
1965 \brief Get an action identifier.
1966 \return action ID or -1 if action is not registered
1969 class TActionIdEvent: public SALOME_Event
1972 typedef int TResult;
1974 const QAction* myAction;
1975 TActionIdEvent( const QAction* action )
1976 : myResult( -1 ), myAction( action ) {}
1977 virtual void Execute()
1979 LightApp_Module* module = getActiveModule();
1981 myResult = module->actionId( myAction );
1984 int SalomePyQt::actionId( const QAction* a )
1986 return ProcessEvent( new TActionIdEvent( a ) );
1990 \fn int SalomePyQt::addGlobalPreference( const QString& label );
1991 \brief Add global (not module-related) preferences group.
1992 \param label global preferences group name
1993 \return preferences group identifier
1996 class TAddGlobalPrefEvent: public SALOME_Event
1999 typedef int TResult;
2002 TAddGlobalPrefEvent( const QString& label )
2003 : myResult( -1 ), myLabel( label ) {}
2004 virtual void Execute()
2006 LightApp_Module* module = getActiveModule();
2008 LightApp_Preferences* pref = module->getApp()->preferences();
2010 myResult = pref->addPreference( myLabel, -1 );
2014 int SalomePyQt::addGlobalPreference( const QString& label )
2016 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2020 \fn int SalomePyQt::addPreference( const QString& label );
2021 \brief Add module-related preferences group.
2022 \param label preferences group name
2023 \return preferences group identifier
2026 class TAddPrefEvent: public SALOME_Event
2029 typedef int TResult;
2032 TAddPrefEvent( const QString& label )
2033 : myResult( -1 ), myLabel( label ) {}
2034 virtual void Execute()
2036 LightApp_Module* module = getActiveModule();
2038 LightApp_Preferences* pref = module->getApp()->preferences();
2040 int cId = pref->addPreference( module->moduleName(), -1 );
2042 myResult = pref->addPreference( myLabel, cId );
2047 int SalomePyQt::addPreference( const QString& label )
2049 return ProcessEvent( new TAddPrefEvent( label ) );
2053 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2054 const QString& section, const QString& param );
2055 \brief Add module-related preferences.
2056 \param label preferences group name
2057 \param pId parent preferences group id
2058 \param type preferences type
2059 \param section resources file section name
2060 \param param resources file setting name
2061 \return preferences identifier
2064 class TAddPrefParamEvent: public SALOME_Event
2067 typedef int TResult;
2074 TAddPrefParamEvent( const QString& label,
2075 const int pId, const int type,
2076 const QString& section,
2077 const QString& param )
2079 myLabel( label ), myPId( pId ), myType( type ),
2080 mySection( section ), myParam ( param ) {}
2081 virtual void Execute()
2083 LightApp_Module* module = getActiveModule();
2085 LightApp_Preferences* pref = module->getApp()->preferences();
2087 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2091 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2092 const QString& section, const QString& param )
2094 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2098 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2099 \brief Get the preferences property.
2100 \param id preferences identifier
2101 \param prop preferences property name
2102 \return preferences property value or null QVariant if property is not set
2105 class TPrefPropEvent: public SALOME_Event
2108 typedef QVariant TResult;
2112 TPrefPropEvent( const int id, const QString& prop )
2113 : myId( id ), myProp( prop ) {}
2114 virtual void Execute()
2116 LightApp_Module* module = getActiveModule();
2118 LightApp_Preferences* pref = module->getApp()->preferences();
2120 myResult = pref->itemProperty( myProp, myId );
2124 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2126 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2130 \brief Set the preferences property.
2131 \param id preferences identifier
2132 \param prop preferences property name
2133 \param var preferences property value
2135 void SalomePyQt::setPreferenceProperty( const int id,
2136 const QString& prop,
2137 const QVariant& var )
2139 class TEvent: public SALOME_Event
2145 TEvent( const int id, const QString& prop, const QVariant& var )
2146 : myId( id ), myProp( prop ), myVar( var ) {}
2147 virtual void Execute()
2149 LightApp_Module* module = getActiveModule();
2151 LightApp_Preferences* pref = module->getApp()->preferences();
2153 pref->setItemProperty( myProp, myVar, myId );
2157 ProcessVoidEvent( new TEvent( id, prop, var) );
2161 \brief Add the property value to the list of values.
2163 This method allows creating properties which are QList<QVariant>
2164 - there is no way to pass such values directly to QVariant parameter with PyQt.
2166 \param id preferences identifier
2167 \param prop preferences property name
2168 \param idx preferences property index
2169 \param var preferences property value for the index \a idx
2171 void SalomePyQt::addPreferenceProperty( const int id,
2172 const QString& prop,
2174 const QVariant& var )
2176 class TEvent: public SALOME_Event
2183 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2184 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2185 virtual void Execute()
2187 LightApp_Module* module = getActiveModule();
2189 LightApp_Preferences* pref = module->getApp()->preferences();
2191 QVariant var = pref->itemProperty( myProp, myId );
2192 if ( var.isValid() ) {
2193 if ( var.type() == QVariant::StringList ) {
2194 QStringList sl = var.toStringList();
2195 if ( myIdx >= 0 && myIdx < sl.count() )
2196 sl[myIdx] = myVar.toString();
2198 sl.append( myVar.toString() );
2199 pref->setItemProperty( myProp, sl, myId );
2201 else if ( var.type() == QVariant::List ) {
2202 QList<QVariant> vl = var.toList();
2203 if ( myIdx >= 0 && myIdx < vl.count() )
2207 pref->setItemProperty( myProp, vl, myId );
2213 pref->setItemProperty( myProp, vl, myId );
2219 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2223 \brief Put the message to the Log messages output window
2224 \param msg message text (it can be of simple rich text format)
2225 \param addSeparator boolean flag which specifies if it is necessary
2226 to separate the message with predefined separator
2228 void SalomePyQt::message( const QString& msg, bool addSeparator )
2230 class TEvent: public SALOME_Event
2235 TEvent( const QString& msg, bool addSeparator )
2236 : myMsg( msg ), myAddSep( addSeparator ) {}
2237 virtual void Execute()
2239 if ( LightApp_Application* anApp = getApplication() ) {
2240 LogWindow* lw = anApp->logWindow();
2242 lw->putMessage( myMsg, myAddSep );
2246 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2250 \brief Remove all the messages from the Log messages output window.
2252 void SalomePyQt::clearMessages()
2254 class TEvent: public SALOME_Event
2258 virtual void Execute()
2260 if ( LightApp_Application* anApp = getApplication() ) {
2261 LogWindow* lw = anApp->logWindow();
2267 ProcessVoidEvent( new TEvent() );
2271 \brief Gets window with specified identifier
2273 \param id window identifier
2274 \return pointer on the window
2276 static SUIT_ViewWindow* getWnd( const int id )
2278 SUIT_ViewWindow* resWnd = 0;
2280 LightApp_Application* app = getApplication();
2283 ViewManagerList vmlist = app->viewManagers();
2284 foreach( SUIT_ViewManager* vm, vmlist )
2286 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2287 foreach ( SUIT_ViewWindow* vw, vwlist )
2289 if ( id == vw->getId() )
2302 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2303 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2304 to the image file in the specified format.
2306 For the current moment JPEG, PNG and BMP images formats are supported.
2307 The image format is defined automatically by the file name extension.
2308 By default, BMP format is used.
2310 \param filename image file name
2311 \return operation status (\c true on success)
2314 class TDumpViewEvent: public SALOME_Event
2317 typedef bool TResult;
2321 TDumpViewEvent( const QString& filename, const int id )
2322 : myResult ( false ), myFileName( filename ), myWndId(id) {}
2323 virtual void Execute()
2325 SUIT_ViewWindow* wnd = NULL;
2328 if ( LightApp_Application* anApp = getApplication() ) {
2329 SUIT_ViewManager* vm = anApp->activeViewManager();
2331 wnd = vm->getActiveView();
2333 myWndId = wnd->getId();
2337 wnd = dynamic_cast<SUIT_ViewWindow*>(getWnd( myWndId ));
2340 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2341 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2342 if(fmt == "PS" || fmt == "EPS" || fmt == "PDF") {
2344 myResult = wnd2D->getViewFrame()->print(myFileName, fmt);
2350 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2351 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2352 qApp->processEvents();
2354 QImage im = wnd->dumpView();
2355 if ( !im.isNull() && !myFileName.isEmpty() ) {
2356 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2357 if ( fmt == "JPG" ) fmt = "JPEG";
2358 myResult = im.save( myFileName, fmt.toLatin1() );
2364 bool SalomePyQt::dumpView( const QString& filename, const int id )
2366 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2371 \fn QList<int> SalomePyQt::getViews();
2372 \brief Get list of integer identifiers of all the currently opened views
2373 \return list of integer identifiers of all the currently opened views
2376 class TGetViews: public SALOME_Event
2379 typedef QList<int> TResult;
2382 virtual void Execute()
2385 LightApp_Application* app = getApplication();
2388 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2391 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2392 SUIT_ViewWindow* wnd;
2393 foreach ( wnd, wndlist )
2394 myResult.append( wnd->getId() );
2399 QList<int> SalomePyQt::getViews()
2401 return ProcessEvent( new TGetViews() );
2405 \fn int SalomePyQt::getActiveView();
2406 \brief Get integer identifier of the currently active view
2407 \return integer identifier of the currently active view
2410 class TGetActiveView: public SALOME_Event
2413 typedef int TResult;
2417 virtual void Execute()
2419 LightApp_Application* app = getApplication();
2422 SUIT_ViewManager* viewMgr = app->activeViewManager();
2425 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2427 myResult = wnd->getId();
2432 int SalomePyQt::getActiveView()
2434 return ProcessEvent( new TGetActiveView() );
2438 \fn QString SalomePyQt::getViewType( const int id );
2439 \brief Get type of the specified view, e.g. "OCCViewer"
2440 \param id window identifier
2444 class TGetViewType: public SALOME_Event
2447 typedef QString TResult;
2450 TGetViewType( const int id )
2452 virtual void Execute()
2454 SUIT_ViewWindow* wnd = getWnd( myWndId );
2457 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2459 myResult = viewMgr->getType();
2463 QString SalomePyQt::getViewType( const int id )
2465 return ProcessEvent( new TGetViewType( id ) );
2469 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2470 \brief Change view caption
2471 \param id window identifier
2472 \param title new window title
2473 \return \c true if operation is completed successfully and \c false otherwise
2476 class TSetViewTitle: public SALOME_Event
2479 typedef bool TResult;
2483 TSetViewTitle( const int id, const QString& title )
2484 : myResult( false ),
2487 virtual void Execute()
2489 SUIT_ViewWindow* wnd = getWnd( myWndId );
2492 wnd->setWindowTitle( myTitle );
2497 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2499 return ProcessEvent( new TSetViewTitle( id, title ) );
2504 \fn QString SalomePyQt::getViewTitle( const int id );
2505 \brief Get view caption
2506 \param id window identifier
2507 \return view caption
2510 class TGetViewTitle: public SALOME_Event
2513 typedef QString TResult;
2516 TGetViewTitle( const int id )
2518 virtual void Execute()
2520 SUIT_ViewWindow* wnd = getWnd( myWndId );
2522 myResult = wnd->windowTitle();
2525 QString SalomePyQt::getViewTitle( const int id )
2527 return ProcessEvent( new TGetViewTitle( id ) );
2531 \fn QList<int> SalomePyQt::findViews( const QString& type );
2532 \brief Get list of integer identifiers of all the
2533 currently opened views of the specified type
2534 \param type viewer type
2535 \return list of integer identifiers
2538 class TFindViews: public SALOME_Event
2541 typedef QList<int> TResult;
2544 TFindViews( const QString& type )
2546 virtual void Execute()
2549 LightApp_Application* app = getApplication();
2552 ViewManagerList vmList;
2553 app->viewManagers( myType, vmList );
2554 SUIT_ViewManager* viewMgr;
2555 foreach ( viewMgr, vmList )
2557 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2558 for ( int i = 0, n = vec.size(); i < n; i++ )
2560 SUIT_ViewWindow* wnd = vec[ i ];
2562 myResult.append( wnd->getId() );
2568 QList<int> SalomePyQt::findViews( const QString& type )
2570 return ProcessEvent( new TFindViews( type ) );
2574 \fn bool SalomePyQt::activateView( const int id );
2575 \brief Activate view
2576 \param id window identifier
2577 \return \c true if operation is completed successfully and \c false otherwise
2580 class TActivateView: public SALOME_Event
2583 typedef bool TResult;
2586 TActivateView( const int id )
2587 : myResult( false ),
2589 virtual void Execute()
2591 SUIT_ViewWindow* wnd = getWnd( myWndId );
2599 bool SalomePyQt::activateView( const int id )
2601 return ProcessEvent( new TActivateView( id ) );
2605 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2606 \brief Create new view and activate it
2607 \param type viewer type
2611 \return integer identifier of created view (or -1 if view could not be created)
2614 class TCreateView: public SALOME_Event
2617 typedef int TResult;
2623 TCreateView( const QString& theType, bool visible, const int width, const int height )
2629 virtual void Execute()
2631 LightApp_Application* app = getApplication();
2634 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2637 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2639 wnd->setShown(myVisible);
2640 if(!myVisible && myWidth == 0 && myHeight == 0) {
2644 if(myWidth > 0 && myHeight > 0) {
2645 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>(wnd);
2647 wnd2D->getViewFrame()->setGeometry(0,0,myWidth,myHeight);
2649 wnd->setGeometry(0,0,myWidth,myHeight);
2652 myResult = wnd->getId();
2658 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2660 return ProcessEvent( new TCreateView( type, visible, width, height ) );
2664 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2665 \brief Create new view with custom widget embedded and activate it
2666 \param type viewer type
2667 \param w custom widget
2668 \return integer identifier of created view (or -1 if view could not be created)
2671 class TCreateViewWg: public SALOME_Event
2674 typedef int TResult;
2678 TCreateViewWg( const QString& theType, QWidget* w )
2682 virtual void Execute()
2684 LightApp_Application* app = getApplication();
2687 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2690 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2692 myResult = wnd->getId();
2697 int SalomePyQt::createView( const QString& type, QWidget* w )
2699 return ProcessEvent( new TCreateViewWg( type, w ) );
2703 \fn bool SalomePyQt::closeView( const int id );
2705 \param id window identifier
2706 \return \c true if operation is completed successfully and \c false otherwise
2709 class TCloseView: public SALOME_Event
2712 typedef bool TResult;
2715 TCloseView( const int id )
2716 : myResult( false ),
2718 virtual void Execute()
2720 SUIT_ViewWindow* wnd = getWnd( myWndId );
2723 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2732 bool SalomePyQt::closeView( const int id )
2734 return ProcessEvent( new TCloseView( id ) );
2738 \fn int SalomePyQt::cloneView( const int id );
2739 \brief Clone view (if this operation is supported for specified view type)
2740 \param id window identifier
2741 \return integer identifier of the cloned view or -1 or operation could not be performed
2744 class TCloneView: public SALOME_Event
2747 typedef int TResult;
2750 TCloneView( const int id )
2753 virtual void Execute()
2755 SUIT_ViewWindow* wnd = getWnd( myWndId );
2758 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2761 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2763 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2764 occView->onCloneView();
2766 wnd = viewMgr->getActiveView();
2768 myResult = wnd->getId();
2770 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2772 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2773 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2774 if ( viewMgr2d && srcWnd2d )
2776 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2777 myResult = resWnd->getId();
2784 int SalomePyQt::cloneView( const int id )
2786 return ProcessEvent( new TCloneView( id ) );
2790 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2791 \brief Set view visibility.
2792 \param id window identifier
2793 \param visible new visiblity
2796 void SalomePyQt::setViewVisible( const int id, const bool visible )
2798 class TEvent: public SALOME_Event
2803 TEvent( const int id, const bool visible )
2804 : myWndId( id ), myVisible( visible ) {}
2805 virtual void Execute()
2807 SUIT_ViewWindow* wnd = getWnd( myWndId );
2808 if ( wnd ) wnd->setVisible( myVisible );
2811 ProcessVoidEvent( new TEvent( id, visible ) );
2815 \fn bool SalomePyQt::isViewVisible( const int id );
2816 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2817 \param id window identifier
2818 \return \c true if view is visible and \c false otherwise
2821 class TIsViewVisible: public SALOME_Event
2824 typedef bool TResult;
2827 TIsViewVisible( const int id )
2828 : myResult( false ),
2830 virtual void Execute()
2832 SUIT_ViewWindow* wnd = getWnd( myWndId );
2835 QWidget* p = wnd->parentWidget();
2836 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2840 bool SalomePyQt::isViewVisible( const int id )
2842 return ProcessEvent( new TIsViewVisible( id ) );
2846 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2847 \brief Set / clear view's "closable" option. By default any view is closable
2848 (i.e. can be closed by the user).
2849 \param id window identifier
2850 \param on new "closable" option's value
2853 void SalomePyQt::setViewClosable( const int id, const bool on )
2855 class TEvent: public SALOME_Event
2860 TEvent( const int id, const bool on )
2861 : myWndId( id ), myOn( on ) {}
2862 virtual void Execute()
2864 SUIT_ViewWindow* wnd = getWnd( myWndId );
2865 if ( wnd ) wnd->setClosable( myOn );
2868 ProcessVoidEvent( new TEvent( id, on ) );
2872 \fn bool SalomePyQt::isViewClosable( const int id );
2873 \brief Check whether view is closable (i.e. can be closed by the user)
2874 \param id window identifier
2875 \return \c true if view is closable or \c false otherwise
2878 class TIsViewClosable: public SALOME_Event
2881 typedef bool TResult;
2884 TIsViewClosable( const int id )
2887 virtual void Execute()
2889 SUIT_ViewWindow* wnd = getWnd( myWndId );
2891 myResult = wnd->closable();
2895 bool SalomePyQt::isViewClosable( const int id )
2897 return ProcessEvent( new TIsViewClosable( id ) );
2901 \fn bool SalomePyQt::groupAllViews();
2902 \brief Group all views to the single tab area
2903 \return \c true if operation is completed successfully and \c false otherwise
2906 class TGroupAllViews: public SALOME_Event
2909 typedef bool TResult;
2912 : myResult( false ) {}
2913 virtual void Execute()
2915 LightApp_Application* app = getApplication();
2918 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2921 QtxWorkstack* wStack = tabDesk->workstack();
2931 bool SalomePyQt::groupAllViews()
2933 return ProcessEvent( new TGroupAllViews() );
2937 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2938 \brief Split tab area to which view with identifier belongs to
2939 \param id window identifier
2940 \param ori orientation of split operation
2941 \param action action to be performed
2942 \return \c true if operation is completed successfully \c false otherwise
2945 class TSplitView: public SALOME_Event
2948 typedef bool TResult;
2953 TSplitView( const int id,
2954 const Orientation ori,
2955 const Action action )
2956 : myResult( false ),
2959 myAction( action ) {}
2960 virtual void Execute()
2962 SUIT_ViewWindow* wnd = getWnd( myWndId );
2966 // wnd->setFocus(); ???
2969 if ( getApplication() )
2971 STD_TabDesktop* desk =
2972 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2975 QtxWorkstack* wStack = desk->workstack();
2978 Qt::Orientation qtOri =
2979 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2981 QtxWorkstack::SplitType sType;
2982 if ( myAction == MoveWidget )
2983 sType = QtxWorkstack::SplitMove;
2984 else if ( myAction == LeaveWidget )
2985 sType = QtxWorkstack::SplitStay;
2987 sType = QtxWorkstack::SplitAt;
2989 wStack->Split( wnd, qtOri, sType );
2997 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
2999 return ProcessEvent( new TSplitView( id, ori, action ) );
3003 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3004 \brief Move view with the first identifier to the same area which
3005 another view with the second identifier belongs to
3006 \param id source window identifier
3007 \param id_to destination window identifier
3008 param before specifies whether the first viewt has to be moved before or after
3010 \return \c true if operation is completed successfully and \c false otherwise
3013 class TMoveView: public SALOME_Event
3016 typedef bool TResult;
3021 TMoveView( const int id, const int id_to, const bool before )
3022 : myResult( false ),
3025 myIsBefore( before ) {}
3026 virtual void Execute()
3028 SUIT_ViewWindow* wnd = getWnd( myWndId );
3029 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3030 if ( wnd && wnd_to )
3032 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3033 getApplication()->desktop() )->workstack();
3035 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3039 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3041 return ProcessEvent( new TMoveView( id, id_to, before ) );
3045 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3046 \brief Get list of views identifiers that belongs to the same area as
3047 specified view (excluding it)
3048 \param id window identifier
3049 \return list of views identifiers
3052 class TNeighbourViews: public SALOME_Event
3055 typedef QList<int> TResult;
3058 TNeighbourViews( const int id )
3060 virtual void Execute()
3063 SUIT_ViewWindow* wnd = getWnd( myWndId );
3066 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3067 getApplication()->desktop() )->workstack();
3070 QWidgetList wgList = wStack->windowList( wnd );
3072 foreach ( wg, wgList )
3074 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3075 if ( tmpWnd && tmpWnd != wnd )
3076 myResult.append( tmpWnd->getId() );
3082 QList<int> SalomePyQt::neighbourViews( const int id )
3084 return ProcessEvent( new TNeighbourViews( id ) );
3089 \fn QString SalomePyQt::createObject( const QString& parent );
3090 \brief Create empty data object
3091 \param parent entry of parent data object
3092 \return entry of created data object
3095 class TCreateEmptyObjectEvent: public SALOME_Event
3098 typedef QString TResult;
3101 TCreateEmptyObjectEvent( const QString& parent )
3102 : myParent( parent ) {}
3103 virtual void Execute()
3105 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3107 myResult = module->createObject( myParent );
3110 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3114 QString SalomePyQt::createObject( const QString& parent )
3116 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3120 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3121 const QString& tooltip,const QString& parent );
3122 \brief Create new data object with specified name, icon and tooltip
3123 \param name data object name
3124 \param icon data object icon
3125 \param toolTip data object tooltip
3126 \param parent entry of parent data object
3127 \return entry of created data object
3130 class TCreateObjectEvent: public SALOME_Event
3133 typedef QString TResult;
3139 TCreateObjectEvent( const QString& name,
3140 const QString& icon,
3141 const QString& tooltip,
3142 const QString& parent )
3145 myToolTip( tooltip ),
3146 myParent( parent ) {}
3147 virtual void Execute()
3149 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3151 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3154 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3158 QString SalomePyQt::createObject( const QString& name,
3159 const QString& icon,
3160 const QString& toolTip,
3161 const QString& parent )
3163 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3168 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3169 \brief Set data object name
3170 \param entry data object entry
3171 \param name data object name
3173 class TSetNameEvent: public SALOME_Event
3178 TSetNameEvent( const QString& entry,
3179 const QString& name )
3182 virtual void Execute()
3184 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3186 module->setName( myEntry, myName );
3189 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3193 void SalomePyQt::setName( const QString& entry, const QString& name )
3195 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3199 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3200 \brief Set data object icon
3201 \param entry data object entry
3202 \param icon data object icon file name (icon is loaded from module resources)
3205 class TSetIconEvent: public SALOME_Event
3210 TSetIconEvent( const QString& entry,
3211 const QString& icon )
3214 virtual void Execute()
3216 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3218 module->setIcon( myEntry, myIcon );
3221 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3226 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3228 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3232 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3233 \brief Set data object tooltip
3234 \param entry data object entry
3235 \param toolTip data object tooltip
3238 class TSetToolTipEvent: public SALOME_Event
3243 TSetToolTipEvent( const QString& entry,
3244 const QString& toolTip )
3246 myToolTip( toolTip ) {}
3247 virtual void Execute()
3249 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3251 module->setToolTip( myEntry, myToolTip );
3254 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3258 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3260 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3264 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3265 \brief Set reference to another data object
3266 \param entry data object entry
3267 \param refEntry referenced data object entry
3270 class TSetRefEvent: public SALOME_Event
3275 TSetRefEvent( const QString& entry,
3276 const QString& refEntry )
3278 myRefEntry( refEntry ) {}
3279 virtual void Execute()
3281 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3283 module->setReference( myEntry, myRefEntry );
3286 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3290 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3292 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3296 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3297 \brief Set data object color
3298 \param entry data object entry
3299 \param color data object color
3302 class TSetColorEvent: public SALOME_Event
3307 TSetColorEvent( const QString& entry,
3308 const QColor& color )
3311 virtual void Execute()
3313 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3315 module->setColor( myEntry, myColor );
3318 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3322 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3324 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3328 \fn QString SalomePyQt::getName( const QString& entry );
3329 \brief Get data object name
3330 \param entry data object entry
3331 \return data object name
3334 class TGetNameEvent: public SALOME_Event
3337 typedef QString TResult;
3340 TGetNameEvent( const QString& entry )
3341 : myEntry( entry ) {}
3342 virtual void Execute()
3344 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3346 myResult = module->getName( myEntry );
3349 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3353 QString SalomePyQt::getName( const QString& entry )
3355 return ProcessEvent( new TGetNameEvent( entry ) );
3359 \fn QString SalomePyQt::getToolTip( const QString& entry );
3360 \brief Get data object tooltip
3361 \param entry data object entry
3362 \return data object tooltip
3365 class TGetToolTipEvent: public SALOME_Event
3368 typedef QString TResult;
3371 TGetToolTipEvent( const QString& entry )
3372 : myEntry( entry ) {}
3373 virtual void Execute()
3375 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3377 myResult = module->getToolTip( myEntry );
3380 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3384 QString SalomePyQt::getToolTip( const QString& entry )
3386 return ProcessEvent( new TGetToolTipEvent( entry ) );
3390 \fn QString SalomePyQt::getReference( const QString& entry );
3391 \brief Get entry of the referenced object (if there's any)
3392 \param entry data object entry
3393 \return referenced data object entry
3396 class TGetRefEvent: public SALOME_Event
3399 typedef QString TResult;
3402 TGetRefEvent( const QString& entry )
3403 : myEntry( entry ) {}
3404 virtual void Execute()
3406 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3408 myResult = module->getReference( myEntry );
3411 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3415 QString SalomePyQt::getReference( const QString& entry )
3417 return ProcessEvent( new TGetRefEvent( entry ) );
3421 \fn QColor SalomePyQt::getColor( const QString& entry );
3422 \brief Get data object color
3423 \param entry data object entry
3424 \return data object color
3427 class TGetColorEvent: public SALOME_Event
3430 typedef QColor TResult;
3433 TGetColorEvent( const QString& entry )
3434 : myEntry( entry ) {}
3435 virtual void Execute()
3437 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3439 myResult = module->getColor( myEntry );
3442 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3446 QColor SalomePyQt::getColor( const QString& entry )
3448 return ProcessEvent( new TGetColorEvent( entry ) );
3452 \fn void SalomePyQt::removeChildren( const QString& entry );
3453 \brief Remove all child data objects from specified data object
3454 \param entry data object entry
3457 class TRemoveChildEvent: public SALOME_Event
3461 TRemoveChildEvent( const QString& entry )
3462 : myEntry( entry ) {}
3463 virtual void Execute()
3465 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3467 module->removeChildren( myEntry );
3470 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3474 void SalomePyQt::removeChildren( const QString& entry )
3476 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3478 void SalomePyQt::removeChild( const QString& entry )
3480 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3481 removeChildren( entry );
3485 \fn void SalomePyQt::removeObject( const QString& entry );
3486 \brief Remove object by entry
3487 \param entry data object entry
3490 class TRemoveObjectEvent: public SALOME_Event
3495 TRemoveObjectEvent( const QString& entry )
3496 : myEntry( entry ) {}
3497 virtual void Execute()
3499 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3501 module->removeObject( myEntry );
3504 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3508 void SalomePyQt::removeObject( const QString& entry )
3510 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3514 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3515 \brief Get entries of all child data objects of specified data object
3516 \param entry data object entry
3517 \param recursive \c true for recursive processing
3520 class TGetChildrenEvent: public SALOME_Event
3523 typedef QStringList TResult;
3527 TGetChildrenEvent( const QString& entry, const bool recursive )
3529 myRecursive( recursive ) {}
3530 virtual void Execute()
3532 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3534 myResult = module->getChildren( myEntry, myRecursive );
3537 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3541 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3543 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3548 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3549 \brief Display theCurve in view
3550 \param id window identifier
3551 \param theCurve curve to display
3554 class TDisplayCurve: public SALOME_Event
3558 Plot2d_Curve* myCurve;
3559 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3560 virtual void Execute() {
3561 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3564 wnd->getViewFrame()->displayCurve(myCurve);
3568 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3570 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3574 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3575 \brief Erase theCurve in view
3576 \param id window identifier
3577 \param theCurve curve to erase
3580 class TEraseCurve: public SALOME_Event
3584 Plot2d_Curve* myCurve;
3585 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3586 virtual void Execute() {
3587 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3590 wnd->getViewFrame()->eraseCurve(myCurve);
3594 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3596 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3600 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3601 \brief Delete theCurve from all views
3602 \param theCurve curve to delete
3605 class TDeleteCurve: public SALOME_Event
3608 Plot2d_Curve* myCurve;
3609 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3610 virtual void Execute() {
3611 LightApp_Application* app = getApplication();
3614 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3617 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3618 SUIT_ViewWindow* wnd;
3619 foreach ( wnd, wndlist )
3621 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3624 aP2d->getViewFrame()->eraseObject(myCurve);
3631 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3633 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3637 \brief updateCurves (repaint) curves in view window.
3639 void SalomePyQt::updateCurves(const int id)
3641 class TEvent: public SALOME_Event
3645 TEvent( const int id ) : myWndId( id ) {}
3646 virtual void Execute()
3648 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3651 wnd->getViewFrame()->DisplayAll();
3655 ProcessVoidEvent( new TEvent(id) );
3659 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3660 \brief Get title of corresponding type
3661 \param id window identifier
3662 \param type is type of title
3663 \return title of corresponding type
3666 class TGetPlot2dTitle: public SALOME_Event
3669 typedef QString TResult;
3673 TGetPlot2dTitle(const int id, ObjectType type) :
3676 virtual void Execute() {
3677 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3680 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3684 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3686 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3691 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3692 \brief Set title of corresponding type
3693 \param id window identifier
3695 \param type is type of title
3699 class TSetPlot2dTitle: public SALOME_Event
3703 Plot2d_Curve* myCurve;
3707 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3712 virtual void Execute() {
3713 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3716 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3720 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3722 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3726 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3727 \brief Get list of Plot2d view ranges
3728 \param id window identifier
3729 \return list of view ranges (XMin, XMax, YMin, YMax)
3732 class TFitRangeByCurves: public SALOME_Event
3735 typedef QList<double> TResult;
3738 TFitRangeByCurves( const int id )
3740 virtual void Execute()
3743 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3746 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3747 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3748 myResult.append(XMin);
3749 myResult.append(XMax);
3750 myResult.append(YMin);
3751 myResult.append(YMax);
3755 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3757 return ProcessEvent( new TFitRangeByCurves( id ) );
3761 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3762 \brief Get list of current Plot2d view ranges
3763 \param id window identifier
3764 \return list of view ranges (XMin, XMax, YMin, YMax)
3767 class TFitRangeCurrent: public SALOME_Event
3770 typedef QList<double> TResult;
3773 TFitRangeCurrent( const int id )
3775 virtual void Execute()
3778 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3781 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3782 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3783 myResult.append(XMin);
3784 myResult.append(XMax);
3785 myResult.append(YMin);
3786 myResult.append(YMax);
3790 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3792 return ProcessEvent( new TFitRangeCurrent( id ) );
3796 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3797 \brief Set range of Plot2d view
3798 \param id window identifier
3805 class TPlot2dFitRange: public SALOME_Event
3813 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3819 virtual void Execute() {
3820 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3823 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3827 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3829 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3832 //class TInitParaview: public SALOME_Event
3835 // TInitParaview() {}
3836 // virtual void Execute() {
3837 // LightApp_Application* anApp = getApplication();
3838 // // Create PVViewer_ViewManager, which will initialize ParaView stuff
3839 // PVViewer_ViewManager* viewMgr =
3840 // dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), true ) );
3843 //void SalomePyQt::initializeParaViewGUI()
3845 // ProcessVoidEvent( new TInitParaview() );
3848 void SalomePyQt::processEvents()
3850 QCoreApplication::processEvents();
3853 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3855 class TEvent: public SALOME_Event
3860 TEvent( const QString& theEntry, int theState):
3861 myEntry(theEntry), myState(theState) {}
3862 virtual void Execute()
3864 LightApp_Study* aStudy = getActiveStudy();
3867 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3870 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3873 class TGetVisibilityStateEvent: public SALOME_Event
3876 typedef int TResult;
3879 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3880 virtual void Execute()
3882 LightApp_Study* aStudy = getActiveStudy();
3884 myResult = aStudy->visibilityState(myEntry);
3888 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3890 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3894 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3896 class TEvent: public SALOME_Event
3901 TEvent( const QString& theEntry, int thePos):
3902 myEntry(theEntry), myPos(thePos) {}
3903 virtual void Execute()
3905 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3907 module->setObjectPosition(myEntry, myPos );
3910 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3915 class TGetObjectPositionEvent: public SALOME_Event
3918 typedef int TResult;
3921 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3922 virtual void Execute()
3924 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3926 myResult = module->getObjectPosition(myEntry);
3930 int SalomePyQt::getObjectPosition( const QString& theEntry )
3932 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );
3935 void SalomePyQt::startPyLog(const QString& theFileName)
3937 class TEvent: public SALOME_Event
3941 TEvent( const QString& theFileName ):
3942 myFileName( theFileName ) {}
3943 virtual void Execute()
3945 if ( getApplication() ) {
3946 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3947 if ( pyConsole ) pyConsole->startLog( myFileName );
3951 ProcessVoidEvent( new TEvent( theFileName ) );
3954 void SalomePyQt::stopPyLog()
3956 class TEvent: public SALOME_Event
3960 virtual void Execute()
3962 if ( getApplication() ) {
3963 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3964 if ( pyConsole ) pyConsole->stopLog();
3968 ProcessVoidEvent( new TEvent() );