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 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2661 QCoreApplication::processEvents();
2666 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2667 \brief Create new view with custom widget embedded and activate it
2668 \param type viewer type
2669 \param w custom widget
2670 \return integer identifier of created view (or -1 if view could not be created)
2673 class TCreateViewWg: public SALOME_Event
2676 typedef int TResult;
2680 TCreateViewWg( const QString& theType, QWidget* w )
2684 virtual void Execute()
2686 LightApp_Application* app = getApplication();
2689 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2692 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2694 myResult = wnd->getId();
2699 int SalomePyQt::createView( const QString& type, QWidget* w )
2701 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2702 QCoreApplication::processEvents();
2707 \fn bool SalomePyQt::closeView( const int id );
2709 \param id window identifier
2710 \return \c true if operation is completed successfully and \c false otherwise
2713 class TCloseView: public SALOME_Event
2716 typedef bool TResult;
2719 TCloseView( const int id )
2720 : myResult( false ),
2722 virtual void Execute()
2724 SUIT_ViewWindow* wnd = getWnd( myWndId );
2727 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2736 bool SalomePyQt::closeView( const int id )
2738 return ProcessEvent( new TCloseView( id ) );
2742 \fn int SalomePyQt::cloneView( const int id );
2743 \brief Clone view (if this operation is supported for specified view type)
2744 \param id window identifier
2745 \return integer identifier of the cloned view or -1 or operation could not be performed
2748 class TCloneView: public SALOME_Event
2751 typedef int TResult;
2754 TCloneView( const int id )
2757 virtual void Execute()
2759 SUIT_ViewWindow* wnd = getWnd( myWndId );
2762 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2765 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2767 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2768 occView->onCloneView();
2770 wnd = viewMgr->getActiveView();
2772 myResult = wnd->getId();
2774 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2776 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2777 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2778 if ( viewMgr2d && srcWnd2d )
2780 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2781 myResult = resWnd->getId();
2788 int SalomePyQt::cloneView( const int id )
2790 return ProcessEvent( new TCloneView( id ) );
2794 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2795 \brief Set view visibility.
2796 \param id window identifier
2797 \param visible new visiblity
2800 void SalomePyQt::setViewVisible( const int id, const bool visible )
2802 class TEvent: public SALOME_Event
2807 TEvent( const int id, const bool visible )
2808 : myWndId( id ), myVisible( visible ) {}
2809 virtual void Execute()
2811 SUIT_ViewWindow* wnd = getWnd( myWndId );
2812 if ( wnd ) wnd->setVisible( myVisible );
2815 ProcessVoidEvent( new TEvent( id, visible ) );
2819 \fn bool SalomePyQt::isViewVisible( const int id );
2820 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2821 \param id window identifier
2822 \return \c true if view is visible and \c false otherwise
2825 class TIsViewVisible: public SALOME_Event
2828 typedef bool TResult;
2831 TIsViewVisible( const int id )
2832 : myResult( false ),
2834 virtual void Execute()
2836 SUIT_ViewWindow* wnd = getWnd( myWndId );
2839 QWidget* p = wnd->parentWidget();
2840 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2844 bool SalomePyQt::isViewVisible( const int id )
2846 return ProcessEvent( new TIsViewVisible( id ) );
2850 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2851 \brief Set / clear view's "closable" option. By default any view is closable
2852 (i.e. can be closed by the user).
2853 \param id window identifier
2854 \param on new "closable" option's value
2857 void SalomePyQt::setViewClosable( const int id, const bool on )
2859 class TEvent: public SALOME_Event
2864 TEvent( const int id, const bool on )
2865 : myWndId( id ), myOn( on ) {}
2866 virtual void Execute()
2868 SUIT_ViewWindow* wnd = getWnd( myWndId );
2869 if ( wnd ) wnd->setClosable( myOn );
2872 ProcessVoidEvent( new TEvent( id, on ) );
2876 \fn bool SalomePyQt::isViewClosable( const int id );
2877 \brief Check whether view is closable (i.e. can be closed by the user)
2878 \param id window identifier
2879 \return \c true if view is closable or \c false otherwise
2882 class TIsViewClosable: public SALOME_Event
2885 typedef bool TResult;
2888 TIsViewClosable( const int id )
2891 virtual void Execute()
2893 SUIT_ViewWindow* wnd = getWnd( myWndId );
2895 myResult = wnd->closable();
2899 bool SalomePyQt::isViewClosable( const int id )
2901 return ProcessEvent( new TIsViewClosable( id ) );
2905 \fn bool SalomePyQt::groupAllViews();
2906 \brief Group all views to the single tab area
2907 \return \c true if operation is completed successfully and \c false otherwise
2910 class TGroupAllViews: public SALOME_Event
2913 typedef bool TResult;
2916 : myResult( false ) {}
2917 virtual void Execute()
2919 LightApp_Application* app = getApplication();
2922 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2925 QtxWorkstack* wStack = tabDesk->workstack();
2935 bool SalomePyQt::groupAllViews()
2937 return ProcessEvent( new TGroupAllViews() );
2941 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2942 \brief Split tab area to which view with identifier belongs to
2943 \param id window identifier
2944 \param ori orientation of split operation
2945 \param action action to be performed
2946 \return \c true if operation is completed successfully \c false otherwise
2949 class TSplitView: public SALOME_Event
2952 typedef bool TResult;
2957 TSplitView( const int id,
2958 const Orientation ori,
2959 const Action action )
2960 : myResult( false ),
2963 myAction( action ) {}
2964 virtual void Execute()
2966 SUIT_ViewWindow* wnd = getWnd( myWndId );
2970 // wnd->setFocus(); ???
2973 if ( getApplication() )
2975 STD_TabDesktop* desk =
2976 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2979 QtxWorkstack* wStack = desk->workstack();
2982 Qt::Orientation qtOri =
2983 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2985 QtxWorkstack::SplitType sType;
2986 if ( myAction == MoveWidget )
2987 sType = QtxWorkstack::SplitMove;
2988 else if ( myAction == LeaveWidget )
2989 sType = QtxWorkstack::SplitStay;
2991 sType = QtxWorkstack::SplitAt;
2993 wStack->Split( wnd, qtOri, sType );
3001 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3003 return ProcessEvent( new TSplitView( id, ori, action ) );
3007 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3008 \brief Move view with the first identifier to the same area which
3009 another view with the second identifier belongs to
3010 \param id source window identifier
3011 \param id_to destination window identifier
3012 param before specifies whether the first viewt has to be moved before or after
3014 \return \c true if operation is completed successfully and \c false otherwise
3017 class TMoveView: public SALOME_Event
3020 typedef bool TResult;
3025 TMoveView( const int id, const int id_to, const bool before )
3026 : myResult( false ),
3029 myIsBefore( before ) {}
3030 virtual void Execute()
3032 SUIT_ViewWindow* wnd = getWnd( myWndId );
3033 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3034 if ( wnd && wnd_to )
3036 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3037 getApplication()->desktop() )->workstack();
3039 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3043 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3045 return ProcessEvent( new TMoveView( id, id_to, before ) );
3049 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3050 \brief Get list of views identifiers that belongs to the same area as
3051 specified view (excluding it)
3052 \param id window identifier
3053 \return list of views identifiers
3056 class TNeighbourViews: public SALOME_Event
3059 typedef QList<int> TResult;
3062 TNeighbourViews( const int id )
3064 virtual void Execute()
3067 SUIT_ViewWindow* wnd = getWnd( myWndId );
3070 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3071 getApplication()->desktop() )->workstack();
3074 QWidgetList wgList = wStack->windowList( wnd );
3076 foreach ( wg, wgList )
3078 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3079 if ( tmpWnd && tmpWnd != wnd )
3080 myResult.append( tmpWnd->getId() );
3086 QList<int> SalomePyQt::neighbourViews( const int id )
3088 return ProcessEvent( new TNeighbourViews( id ) );
3093 \fn QString SalomePyQt::createObject( const QString& parent );
3094 \brief Create empty data object
3095 \param parent entry of parent data object
3096 \return entry of created data object
3099 class TCreateEmptyObjectEvent: public SALOME_Event
3102 typedef QString TResult;
3105 TCreateEmptyObjectEvent( const QString& parent )
3106 : myParent( parent ) {}
3107 virtual void Execute()
3109 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3111 myResult = module->createObject( myParent );
3114 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3118 QString SalomePyQt::createObject( const QString& parent )
3120 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3124 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3125 const QString& tooltip,const QString& parent );
3126 \brief Create new data object with specified name, icon and tooltip
3127 \param name data object name
3128 \param icon data object icon
3129 \param toolTip data object tooltip
3130 \param parent entry of parent data object
3131 \return entry of created data object
3134 class TCreateObjectEvent: public SALOME_Event
3137 typedef QString TResult;
3143 TCreateObjectEvent( const QString& name,
3144 const QString& icon,
3145 const QString& tooltip,
3146 const QString& parent )
3149 myToolTip( tooltip ),
3150 myParent( parent ) {}
3151 virtual void Execute()
3153 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3155 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3158 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3162 QString SalomePyQt::createObject( const QString& name,
3163 const QString& icon,
3164 const QString& toolTip,
3165 const QString& parent )
3167 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3172 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3173 \brief Set data object name
3174 \param entry data object entry
3175 \param name data object name
3177 class TSetNameEvent: public SALOME_Event
3182 TSetNameEvent( const QString& entry,
3183 const QString& name )
3186 virtual void Execute()
3188 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3190 module->setName( myEntry, myName );
3193 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3197 void SalomePyQt::setName( const QString& entry, const QString& name )
3199 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3203 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3204 \brief Set data object icon
3205 \param entry data object entry
3206 \param icon data object icon file name (icon is loaded from module resources)
3209 class TSetIconEvent: public SALOME_Event
3214 TSetIconEvent( const QString& entry,
3215 const QString& icon )
3218 virtual void Execute()
3220 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3222 module->setIcon( myEntry, myIcon );
3225 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3230 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3232 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3236 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3237 \brief Set data object tooltip
3238 \param entry data object entry
3239 \param toolTip data object tooltip
3242 class TSetToolTipEvent: public SALOME_Event
3247 TSetToolTipEvent( const QString& entry,
3248 const QString& toolTip )
3250 myToolTip( toolTip ) {}
3251 virtual void Execute()
3253 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3255 module->setToolTip( myEntry, myToolTip );
3258 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3262 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3264 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3268 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3269 \brief Set reference to another data object
3270 \param entry data object entry
3271 \param refEntry referenced data object entry
3274 class TSetRefEvent: public SALOME_Event
3279 TSetRefEvent( const QString& entry,
3280 const QString& refEntry )
3282 myRefEntry( refEntry ) {}
3283 virtual void Execute()
3285 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3287 module->setReference( myEntry, myRefEntry );
3290 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3294 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3296 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3300 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3301 \brief Set data object color
3302 \param entry data object entry
3303 \param color data object color
3306 class TSetColorEvent: public SALOME_Event
3311 TSetColorEvent( const QString& entry,
3312 const QColor& color )
3315 virtual void Execute()
3317 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3319 module->setColor( myEntry, myColor );
3322 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3326 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3328 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3332 \fn QString SalomePyQt::getName( const QString& entry );
3333 \brief Get data object name
3334 \param entry data object entry
3335 \return data object name
3338 class TGetNameEvent: public SALOME_Event
3341 typedef QString TResult;
3344 TGetNameEvent( const QString& entry )
3345 : myEntry( entry ) {}
3346 virtual void Execute()
3348 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3350 myResult = module->getName( myEntry );
3353 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3357 QString SalomePyQt::getName( const QString& entry )
3359 return ProcessEvent( new TGetNameEvent( entry ) );
3363 \fn QString SalomePyQt::getToolTip( const QString& entry );
3364 \brief Get data object tooltip
3365 \param entry data object entry
3366 \return data object tooltip
3369 class TGetToolTipEvent: public SALOME_Event
3372 typedef QString TResult;
3375 TGetToolTipEvent( const QString& entry )
3376 : myEntry( entry ) {}
3377 virtual void Execute()
3379 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3381 myResult = module->getToolTip( myEntry );
3384 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3388 QString SalomePyQt::getToolTip( const QString& entry )
3390 return ProcessEvent( new TGetToolTipEvent( entry ) );
3394 \fn QString SalomePyQt::getReference( const QString& entry );
3395 \brief Get entry of the referenced object (if there's any)
3396 \param entry data object entry
3397 \return referenced data object entry
3400 class TGetRefEvent: public SALOME_Event
3403 typedef QString TResult;
3406 TGetRefEvent( const QString& entry )
3407 : myEntry( entry ) {}
3408 virtual void Execute()
3410 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3412 myResult = module->getReference( myEntry );
3415 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3419 QString SalomePyQt::getReference( const QString& entry )
3421 return ProcessEvent( new TGetRefEvent( entry ) );
3425 \fn QColor SalomePyQt::getColor( const QString& entry );
3426 \brief Get data object color
3427 \param entry data object entry
3428 \return data object color
3431 class TGetColorEvent: public SALOME_Event
3434 typedef QColor TResult;
3437 TGetColorEvent( const QString& entry )
3438 : myEntry( entry ) {}
3439 virtual void Execute()
3441 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3443 myResult = module->getColor( myEntry );
3446 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3450 QColor SalomePyQt::getColor( const QString& entry )
3452 return ProcessEvent( new TGetColorEvent( entry ) );
3456 \fn void SalomePyQt::removeChildren( const QString& entry );
3457 \brief Remove all child data objects from specified data object
3458 \param entry data object entry
3461 class TRemoveChildEvent: public SALOME_Event
3465 TRemoveChildEvent( const QString& entry )
3466 : myEntry( entry ) {}
3467 virtual void Execute()
3469 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3471 module->removeChildren( myEntry );
3474 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3478 void SalomePyQt::removeChildren( const QString& entry )
3480 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3482 void SalomePyQt::removeChild( const QString& entry )
3484 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3485 removeChildren( entry );
3489 \fn void SalomePyQt::removeObject( const QString& entry );
3490 \brief Remove object by entry
3491 \param entry data object entry
3494 class TRemoveObjectEvent: public SALOME_Event
3499 TRemoveObjectEvent( const QString& entry )
3500 : myEntry( entry ) {}
3501 virtual void Execute()
3503 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3505 module->removeObject( myEntry );
3508 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3512 void SalomePyQt::removeObject( const QString& entry )
3514 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3518 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3519 \brief Get entries of all child data objects of specified data object
3520 \param entry data object entry
3521 \param recursive \c true for recursive processing
3524 class TGetChildrenEvent: public SALOME_Event
3527 typedef QStringList TResult;
3531 TGetChildrenEvent( const QString& entry, const bool recursive )
3533 myRecursive( recursive ) {}
3534 virtual void Execute()
3536 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3538 myResult = module->getChildren( myEntry, myRecursive );
3541 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3545 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3547 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3552 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3553 \brief Display theCurve in view
3554 \param id window identifier
3555 \param theCurve curve to display
3558 class TDisplayCurve: public SALOME_Event
3562 Plot2d_Curve* myCurve;
3563 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3564 virtual void Execute() {
3565 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3568 wnd->getViewFrame()->displayCurve(myCurve);
3572 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3574 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3578 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3579 \brief Erase theCurve in view
3580 \param id window identifier
3581 \param theCurve curve to erase
3584 class TEraseCurve: public SALOME_Event
3588 Plot2d_Curve* myCurve;
3589 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3590 virtual void Execute() {
3591 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3594 wnd->getViewFrame()->eraseCurve(myCurve);
3598 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3600 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3604 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3605 \brief Delete theCurve from all views
3606 \param theCurve curve to delete
3609 class TDeleteCurve: public SALOME_Event
3612 Plot2d_Curve* myCurve;
3613 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3614 virtual void Execute() {
3615 LightApp_Application* app = getApplication();
3618 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3621 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3622 SUIT_ViewWindow* wnd;
3623 foreach ( wnd, wndlist )
3625 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3628 aP2d->getViewFrame()->eraseObject(myCurve);
3635 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3637 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3641 \brief updateCurves (repaint) curves in view window.
3643 void SalomePyQt::updateCurves(const int id)
3645 class TEvent: public SALOME_Event
3649 TEvent( const int id ) : myWndId( id ) {}
3650 virtual void Execute()
3652 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3655 wnd->getViewFrame()->DisplayAll();
3659 ProcessVoidEvent( new TEvent(id) );
3663 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3664 \brief Get title of corresponding type
3665 \param id window identifier
3666 \param type is type of title
3667 \return title of corresponding type
3670 class TGetPlot2dTitle: public SALOME_Event
3673 typedef QString TResult;
3677 TGetPlot2dTitle(const int id, ObjectType type) :
3680 virtual void Execute() {
3681 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3684 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3688 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3690 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3695 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3696 \brief Set title of corresponding type
3697 \param id window identifier
3699 \param type is type of title
3703 class TSetPlot2dTitle: public SALOME_Event
3707 Plot2d_Curve* myCurve;
3711 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3716 virtual void Execute() {
3717 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3720 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3724 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3726 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3730 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3731 \brief Get list of Plot2d view ranges
3732 \param id window identifier
3733 \return list of view ranges (XMin, XMax, YMin, YMax)
3736 class TFitRangeByCurves: public SALOME_Event
3739 typedef QList<double> TResult;
3742 TFitRangeByCurves( const int id )
3744 virtual void Execute()
3747 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3750 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3751 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3752 myResult.append(XMin);
3753 myResult.append(XMax);
3754 myResult.append(YMin);
3755 myResult.append(YMax);
3759 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3761 return ProcessEvent( new TFitRangeByCurves( id ) );
3765 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3766 \brief Get list of current Plot2d view ranges
3767 \param id window identifier
3768 \return list of view ranges (XMin, XMax, YMin, YMax)
3771 class TFitRangeCurrent: public SALOME_Event
3774 typedef QList<double> TResult;
3777 TFitRangeCurrent( const int id )
3779 virtual void Execute()
3782 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3785 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3786 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3787 myResult.append(XMin);
3788 myResult.append(XMax);
3789 myResult.append(YMin);
3790 myResult.append(YMax);
3794 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3796 return ProcessEvent( new TFitRangeCurrent( id ) );
3800 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3801 \brief Set range of Plot2d view
3802 \param id window identifier
3809 class TPlot2dFitRange: public SALOME_Event
3817 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3823 virtual void Execute() {
3824 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3827 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3831 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3833 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3836 //class TInitParaview: public SALOME_Event
3839 // TInitParaview() {}
3840 // virtual void Execute() {
3841 // LightApp_Application* anApp = getApplication();
3842 // // Create PVViewer_ViewManager, which will initialize ParaView stuff
3843 // PVViewer_ViewManager* viewMgr =
3844 // dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), true ) );
3847 //void SalomePyQt::initializeParaViewGUI()
3849 // ProcessVoidEvent( new TInitParaview() );
3852 void SalomePyQt::processEvents()
3854 QCoreApplication::processEvents();
3857 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3859 class TEvent: public SALOME_Event
3864 TEvent( const QString& theEntry, int theState):
3865 myEntry(theEntry), myState(theState) {}
3866 virtual void Execute()
3868 LightApp_Study* aStudy = getActiveStudy();
3871 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3874 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3877 class TGetVisibilityStateEvent: public SALOME_Event
3880 typedef int TResult;
3883 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3884 virtual void Execute()
3886 LightApp_Study* aStudy = getActiveStudy();
3888 myResult = aStudy->visibilityState(myEntry);
3892 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3894 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3898 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3900 class TEvent: public SALOME_Event
3905 TEvent( const QString& theEntry, int thePos):
3906 myEntry(theEntry), myPos(thePos) {}
3907 virtual void Execute()
3909 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3911 module->setObjectPosition(myEntry, myPos );
3914 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3919 class TGetObjectPositionEvent: public SALOME_Event
3922 typedef int TResult;
3925 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3926 virtual void Execute()
3928 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3930 myResult = module->getObjectPosition(myEntry);
3934 int SalomePyQt::getObjectPosition( const QString& theEntry )
3936 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );
3939 void SalomePyQt::startPyLog(const QString& theFileName)
3941 class TEvent: public SALOME_Event
3945 TEvent( const QString& theFileName ):
3946 myFileName( theFileName ) {}
3947 virtual void Execute()
3949 if ( getApplication() ) {
3950 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3951 if ( pyConsole ) pyConsole->startLog( myFileName );
3955 ProcessVoidEvent( new TEvent( theFileName ) );
3958 void SalomePyQt::stopPyLog()
3960 class TEvent: public SALOME_Event
3964 virtual void Execute()
3966 if ( getApplication() ) {
3967 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3968 if ( pyConsole ) pyConsole->stopLog();
3972 ProcessVoidEvent( new TEvent() );