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 return ProcessEvent( new TCreateViewWg( type, w ) );
2705 \fn bool SalomePyQt::closeView( const int id );
2707 \param id window identifier
2708 \return \c true if operation is completed successfully and \c false otherwise
2711 class TCloseView: public SALOME_Event
2714 typedef bool TResult;
2717 TCloseView( const int id )
2718 : myResult( false ),
2720 virtual void Execute()
2722 SUIT_ViewWindow* wnd = getWnd( myWndId );
2725 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2734 bool SalomePyQt::closeView( const int id )
2736 return ProcessEvent( new TCloseView( id ) );
2740 \fn int SalomePyQt::cloneView( const int id );
2741 \brief Clone view (if this operation is supported for specified view type)
2742 \param id window identifier
2743 \return integer identifier of the cloned view or -1 or operation could not be performed
2746 class TCloneView: public SALOME_Event
2749 typedef int TResult;
2752 TCloneView( const int id )
2755 virtual void Execute()
2757 SUIT_ViewWindow* wnd = getWnd( myWndId );
2760 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2763 if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
2765 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2766 occView->onCloneView();
2768 wnd = viewMgr->getActiveView();
2770 myResult = wnd->getId();
2772 else if ( wnd->inherits( "Plot2d_ViewWindow" ) )
2774 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2775 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2776 if ( viewMgr2d && srcWnd2d )
2778 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2779 myResult = resWnd->getId();
2786 int SalomePyQt::cloneView( const int id )
2788 return ProcessEvent( new TCloneView( id ) );
2792 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2793 \brief Set view visibility.
2794 \param id window identifier
2795 \param visible new visiblity
2798 void SalomePyQt::setViewVisible( const int id, const bool visible )
2800 class TEvent: public SALOME_Event
2805 TEvent( const int id, const bool visible )
2806 : myWndId( id ), myVisible( visible ) {}
2807 virtual void Execute()
2809 SUIT_ViewWindow* wnd = getWnd( myWndId );
2810 if ( wnd ) wnd->setVisible( myVisible );
2813 ProcessVoidEvent( new TEvent( id, visible ) );
2817 \fn bool SalomePyQt::isViewVisible( const int id );
2818 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2819 \param id window identifier
2820 \return \c true if view is visible and \c false otherwise
2823 class TIsViewVisible: public SALOME_Event
2826 typedef bool TResult;
2829 TIsViewVisible( const int id )
2830 : myResult( false ),
2832 virtual void Execute()
2834 SUIT_ViewWindow* wnd = getWnd( myWndId );
2837 QWidget* p = wnd->parentWidget();
2838 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2842 bool SalomePyQt::isViewVisible( const int id )
2844 return ProcessEvent( new TIsViewVisible( id ) );
2848 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2849 \brief Set / clear view's "closable" option. By default any view is closable
2850 (i.e. can be closed by the user).
2851 \param id window identifier
2852 \param on new "closable" option's value
2855 void SalomePyQt::setViewClosable( const int id, const bool on )
2857 class TEvent: public SALOME_Event
2862 TEvent( const int id, const bool on )
2863 : myWndId( id ), myOn( on ) {}
2864 virtual void Execute()
2866 SUIT_ViewWindow* wnd = getWnd( myWndId );
2867 if ( wnd ) wnd->setClosable( myOn );
2870 ProcessVoidEvent( new TEvent( id, on ) );
2874 \fn bool SalomePyQt::isViewClosable( const int id );
2875 \brief Check whether view is closable (i.e. can be closed by the user)
2876 \param id window identifier
2877 \return \c true if view is closable or \c false otherwise
2880 class TIsViewClosable: public SALOME_Event
2883 typedef bool TResult;
2886 TIsViewClosable( const int id )
2889 virtual void Execute()
2891 SUIT_ViewWindow* wnd = getWnd( myWndId );
2893 myResult = wnd->closable();
2897 bool SalomePyQt::isViewClosable( const int id )
2899 return ProcessEvent( new TIsViewClosable( id ) );
2903 \fn bool SalomePyQt::groupAllViews();
2904 \brief Group all views to the single tab area
2905 \return \c true if operation is completed successfully and \c false otherwise
2908 class TGroupAllViews: public SALOME_Event
2911 typedef bool TResult;
2914 : myResult( false ) {}
2915 virtual void Execute()
2917 LightApp_Application* app = getApplication();
2920 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2923 QtxWorkstack* wStack = tabDesk->workstack();
2933 bool SalomePyQt::groupAllViews()
2935 return ProcessEvent( new TGroupAllViews() );
2939 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
2940 \brief Split tab area to which view with identifier belongs to
2941 \param id window identifier
2942 \param ori orientation of split operation
2943 \param action action to be performed
2944 \return \c true if operation is completed successfully \c false otherwise
2947 class TSplitView: public SALOME_Event
2950 typedef bool TResult;
2955 TSplitView( const int id,
2956 const Orientation ori,
2957 const Action action )
2958 : myResult( false ),
2961 myAction( action ) {}
2962 virtual void Execute()
2964 SUIT_ViewWindow* wnd = getWnd( myWndId );
2968 // wnd->setFocus(); ???
2971 if ( getApplication() )
2973 STD_TabDesktop* desk =
2974 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
2977 QtxWorkstack* wStack = desk->workstack();
2980 Qt::Orientation qtOri =
2981 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
2983 QtxWorkstack::SplitType sType;
2984 if ( myAction == MoveWidget )
2985 sType = QtxWorkstack::SplitMove;
2986 else if ( myAction == LeaveWidget )
2987 sType = QtxWorkstack::SplitStay;
2989 sType = QtxWorkstack::SplitAt;
2991 wStack->Split( wnd, qtOri, sType );
2999 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3001 return ProcessEvent( new TSplitView( id, ori, action ) );
3005 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3006 \brief Move view with the first identifier to the same area which
3007 another view with the second identifier belongs to
3008 \param id source window identifier
3009 \param id_to destination window identifier
3010 param before specifies whether the first viewt has to be moved before or after
3012 \return \c true if operation is completed successfully and \c false otherwise
3015 class TMoveView: public SALOME_Event
3018 typedef bool TResult;
3023 TMoveView( const int id, const int id_to, const bool before )
3024 : myResult( false ),
3027 myIsBefore( before ) {}
3028 virtual void Execute()
3030 SUIT_ViewWindow* wnd = getWnd( myWndId );
3031 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3032 if ( wnd && wnd_to )
3034 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3035 getApplication()->desktop() )->workstack();
3037 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3041 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3043 return ProcessEvent( new TMoveView( id, id_to, before ) );
3047 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3048 \brief Get list of views identifiers that belongs to the same area as
3049 specified view (excluding it)
3050 \param id window identifier
3051 \return list of views identifiers
3054 class TNeighbourViews: public SALOME_Event
3057 typedef QList<int> TResult;
3060 TNeighbourViews( const int id )
3062 virtual void Execute()
3065 SUIT_ViewWindow* wnd = getWnd( myWndId );
3068 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3069 getApplication()->desktop() )->workstack();
3072 QWidgetList wgList = wStack->windowList( wnd );
3074 foreach ( wg, wgList )
3076 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3077 if ( tmpWnd && tmpWnd != wnd )
3078 myResult.append( tmpWnd->getId() );
3084 QList<int> SalomePyQt::neighbourViews( const int id )
3086 return ProcessEvent( new TNeighbourViews( id ) );
3091 \fn QString SalomePyQt::createObject( const QString& parent );
3092 \brief Create empty data object
3093 \param parent entry of parent data object
3094 \return entry of created data object
3097 class TCreateEmptyObjectEvent: public SALOME_Event
3100 typedef QString TResult;
3103 TCreateEmptyObjectEvent( const QString& parent )
3104 : myParent( parent ) {}
3105 virtual void Execute()
3107 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3109 myResult = module->createObject( myParent );
3112 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3116 QString SalomePyQt::createObject( const QString& parent )
3118 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3122 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3123 const QString& tooltip,const QString& parent );
3124 \brief Create new data object with specified name, icon and tooltip
3125 \param name data object name
3126 \param icon data object icon
3127 \param toolTip data object tooltip
3128 \param parent entry of parent data object
3129 \return entry of created data object
3132 class TCreateObjectEvent: public SALOME_Event
3135 typedef QString TResult;
3141 TCreateObjectEvent( const QString& name,
3142 const QString& icon,
3143 const QString& tooltip,
3144 const QString& parent )
3147 myToolTip( tooltip ),
3148 myParent( parent ) {}
3149 virtual void Execute()
3151 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3153 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3156 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3160 QString SalomePyQt::createObject( const QString& name,
3161 const QString& icon,
3162 const QString& toolTip,
3163 const QString& parent )
3165 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3170 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3171 \brief Set data object name
3172 \param entry data object entry
3173 \param name data object name
3175 class TSetNameEvent: public SALOME_Event
3180 TSetNameEvent( const QString& entry,
3181 const QString& name )
3184 virtual void Execute()
3186 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3188 module->setName( myEntry, myName );
3191 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3195 void SalomePyQt::setName( const QString& entry, const QString& name )
3197 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3201 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3202 \brief Set data object icon
3203 \param entry data object entry
3204 \param icon data object icon file name (icon is loaded from module resources)
3207 class TSetIconEvent: public SALOME_Event
3212 TSetIconEvent( const QString& entry,
3213 const QString& icon )
3216 virtual void Execute()
3218 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3220 module->setIcon( myEntry, myIcon );
3223 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3228 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3230 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3234 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3235 \brief Set data object tooltip
3236 \param entry data object entry
3237 \param toolTip data object tooltip
3240 class TSetToolTipEvent: public SALOME_Event
3245 TSetToolTipEvent( const QString& entry,
3246 const QString& toolTip )
3248 myToolTip( toolTip ) {}
3249 virtual void Execute()
3251 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3253 module->setToolTip( myEntry, myToolTip );
3256 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3260 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3262 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3266 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3267 \brief Set reference to another data object
3268 \param entry data object entry
3269 \param refEntry referenced data object entry
3272 class TSetRefEvent: public SALOME_Event
3277 TSetRefEvent( const QString& entry,
3278 const QString& refEntry )
3280 myRefEntry( refEntry ) {}
3281 virtual void Execute()
3283 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3285 module->setReference( myEntry, myRefEntry );
3288 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3292 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3294 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3298 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3299 \brief Set data object color
3300 \param entry data object entry
3301 \param color data object color
3304 class TSetColorEvent: public SALOME_Event
3309 TSetColorEvent( const QString& entry,
3310 const QColor& color )
3313 virtual void Execute()
3315 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3317 module->setColor( myEntry, myColor );
3320 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3324 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3326 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3330 \fn QString SalomePyQt::getName( const QString& entry );
3331 \brief Get data object name
3332 \param entry data object entry
3333 \return data object name
3336 class TGetNameEvent: public SALOME_Event
3339 typedef QString TResult;
3342 TGetNameEvent( const QString& entry )
3343 : myEntry( entry ) {}
3344 virtual void Execute()
3346 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3348 myResult = module->getName( myEntry );
3351 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3355 QString SalomePyQt::getName( const QString& entry )
3357 return ProcessEvent( new TGetNameEvent( entry ) );
3361 \fn QString SalomePyQt::getToolTip( const QString& entry );
3362 \brief Get data object tooltip
3363 \param entry data object entry
3364 \return data object tooltip
3367 class TGetToolTipEvent: public SALOME_Event
3370 typedef QString TResult;
3373 TGetToolTipEvent( const QString& entry )
3374 : myEntry( entry ) {}
3375 virtual void Execute()
3377 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3379 myResult = module->getToolTip( myEntry );
3382 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3386 QString SalomePyQt::getToolTip( const QString& entry )
3388 return ProcessEvent( new TGetToolTipEvent( entry ) );
3392 \fn QString SalomePyQt::getReference( const QString& entry );
3393 \brief Get entry of the referenced object (if there's any)
3394 \param entry data object entry
3395 \return referenced data object entry
3398 class TGetRefEvent: public SALOME_Event
3401 typedef QString TResult;
3404 TGetRefEvent( const QString& entry )
3405 : myEntry( entry ) {}
3406 virtual void Execute()
3408 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3410 myResult = module->getReference( myEntry );
3413 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3417 QString SalomePyQt::getReference( const QString& entry )
3419 return ProcessEvent( new TGetRefEvent( entry ) );
3423 \fn QColor SalomePyQt::getColor( const QString& entry );
3424 \brief Get data object color
3425 \param entry data object entry
3426 \return data object color
3429 class TGetColorEvent: public SALOME_Event
3432 typedef QColor TResult;
3435 TGetColorEvent( const QString& entry )
3436 : myEntry( entry ) {}
3437 virtual void Execute()
3439 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3441 myResult = module->getColor( myEntry );
3444 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3448 QColor SalomePyQt::getColor( const QString& entry )
3450 return ProcessEvent( new TGetColorEvent( entry ) );
3454 \fn void SalomePyQt::removeChildren( const QString& entry );
3455 \brief Remove all child data objects from specified data object
3456 \param entry data object entry
3459 class TRemoveChildEvent: public SALOME_Event
3463 TRemoveChildEvent( const QString& entry )
3464 : myEntry( entry ) {}
3465 virtual void Execute()
3467 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3469 module->removeChildren( myEntry );
3472 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3476 void SalomePyQt::removeChildren( const QString& entry )
3478 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3480 void SalomePyQt::removeChild( const QString& entry )
3482 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3483 removeChildren( entry );
3487 \fn void SalomePyQt::removeObject( const QString& entry );
3488 \brief Remove object by entry
3489 \param entry data object entry
3492 class TRemoveObjectEvent: public SALOME_Event
3497 TRemoveObjectEvent( const QString& entry )
3498 : myEntry( entry ) {}
3499 virtual void Execute()
3501 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3503 module->removeObject( myEntry );
3506 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3510 void SalomePyQt::removeObject( const QString& entry )
3512 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3516 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3517 \brief Get entries of all child data objects of specified data object
3518 \param entry data object entry
3519 \param recursive \c true for recursive processing
3522 class TGetChildrenEvent: public SALOME_Event
3525 typedef QStringList TResult;
3529 TGetChildrenEvent( const QString& entry, const bool recursive )
3531 myRecursive( recursive ) {}
3532 virtual void Execute()
3534 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3536 myResult = module->getChildren( myEntry, myRecursive );
3539 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3543 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3545 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3550 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3551 \brief Display theCurve in view
3552 \param id window identifier
3553 \param theCurve curve to display
3556 class TDisplayCurve: public SALOME_Event
3560 Plot2d_Curve* myCurve;
3561 TDisplayCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3562 virtual void Execute() {
3563 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3566 wnd->getViewFrame()->displayCurve(myCurve);
3570 void SalomePyQt::displayCurve(const int id, Plot2d_Curve* theCurve)
3572 ProcessVoidEvent( new TDisplayCurve(id, theCurve) );
3576 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3577 \brief Erase theCurve in view
3578 \param id window identifier
3579 \param theCurve curve to erase
3582 class TEraseCurve: public SALOME_Event
3586 Plot2d_Curve* myCurve;
3587 TEraseCurve(const int id, Plot2d_Curve* theCurve) : myWndId(id), myCurve(theCurve) {}
3588 virtual void Execute() {
3589 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3592 wnd->getViewFrame()->eraseCurve(myCurve);
3596 void SalomePyQt::eraseCurve(const int id, Plot2d_Curve* theCurve)
3598 ProcessVoidEvent( new TEraseCurve(id, theCurve) );
3602 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3603 \brief Delete theCurve from all views
3604 \param theCurve curve to delete
3607 class TDeleteCurve: public SALOME_Event
3610 Plot2d_Curve* myCurve;
3611 TDeleteCurve(Plot2d_Curve* theCurve) : myCurve(theCurve) {}
3612 virtual void Execute() {
3613 LightApp_Application* app = getApplication();
3616 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3619 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3620 SUIT_ViewWindow* wnd;
3621 foreach ( wnd, wndlist )
3623 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>(wnd);
3626 aP2d->getViewFrame()->eraseObject(myCurve);
3633 void SalomePyQt::eraseCurve(Plot2d_Curve * theCurve)
3635 ProcessVoidEvent( new TDeleteCurve(theCurve) );
3639 \brief updateCurves (repaint) curves in view window.
3641 void SalomePyQt::updateCurves(const int id)
3643 class TEvent: public SALOME_Event
3647 TEvent( const int id ) : myWndId( id ) {}
3648 virtual void Execute()
3650 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3653 wnd->getViewFrame()->DisplayAll();
3657 ProcessVoidEvent( new TEvent(id) );
3661 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3662 \brief Get title of corresponding type
3663 \param id window identifier
3664 \param type is type of title
3665 \return title of corresponding type
3668 class TGetPlot2dTitle: public SALOME_Event
3671 typedef QString TResult;
3675 TGetPlot2dTitle(const int id, ObjectType type) :
3678 virtual void Execute() {
3679 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3682 myResult = wnd->getViewFrame()->getTitle((Plot2d_ViewFrame::ObjectType)myType);
3686 QString SalomePyQt::getPlot2dTitle(const int id, ObjectType type)
3688 return ProcessEvent( new TGetPlot2dTitle(id, type) );
3693 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3694 \brief Set title of corresponding type
3695 \param id window identifier
3697 \param type is type of title
3701 class TSetPlot2dTitle: public SALOME_Event
3705 Plot2d_Curve* myCurve;
3709 TSetPlot2dTitle(const int id, const QString& title, ObjectType type, bool show) :
3714 virtual void Execute() {
3715 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3718 wnd->getViewFrame()->setTitle(myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false);
3722 void SalomePyQt::setPlot2dTitle(const int id, const QString& title, ObjectType type, bool show)
3724 ProcessVoidEvent( new TSetPlot2dTitle(id, title, type, show) );
3728 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3729 \brief Get list of Plot2d view ranges
3730 \param id window identifier
3731 \return list of view ranges (XMin, XMax, YMin, YMax)
3734 class TFitRangeByCurves: public SALOME_Event
3737 typedef QList<double> TResult;
3740 TFitRangeByCurves( const int id )
3742 virtual void Execute()
3745 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3748 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3749 wnd->getViewFrame()->getFitRangeByCurves(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3750 myResult.append(XMin);
3751 myResult.append(XMax);
3752 myResult.append(YMin);
3753 myResult.append(YMax);
3757 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3759 return ProcessEvent( new TFitRangeByCurves( id ) );
3763 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3764 \brief Get list of current Plot2d view ranges
3765 \param id window identifier
3766 \return list of view ranges (XMin, XMax, YMin, YMax)
3769 class TFitRangeCurrent: public SALOME_Event
3772 typedef QList<double> TResult;
3775 TFitRangeCurrent( const int id )
3777 virtual void Execute()
3780 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3783 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3784 wnd->getViewFrame()->getFitRanges(XMin, XMax, YMin, YMax, Y2Min, Y2Max);
3785 myResult.append(XMin);
3786 myResult.append(XMax);
3787 myResult.append(YMin);
3788 myResult.append(YMax);
3792 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3794 return ProcessEvent( new TFitRangeCurrent( id ) );
3798 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3799 \brief Set range of Plot2d view
3800 \param id window identifier
3807 class TPlot2dFitRange: public SALOME_Event
3815 TPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax) :
3821 virtual void Execute() {
3822 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>(getWnd( myWndId ));
3825 wnd->getViewFrame()->fitData(0, myXMin, myXMax, myYMin, myYMax);
3829 void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double XMax, const double YMin, const double YMax)
3831 ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) );
3834 //class TInitParaview: public SALOME_Event
3837 // TInitParaview() {}
3838 // virtual void Execute() {
3839 // LightApp_Application* anApp = getApplication();
3840 // // Create PVViewer_ViewManager, which will initialize ParaView stuff
3841 // PVViewer_ViewManager* viewMgr =
3842 // dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), true ) );
3845 //void SalomePyQt::initializeParaViewGUI()
3847 // ProcessVoidEvent( new TInitParaview() );
3850 void SalomePyQt::processEvents()
3852 QCoreApplication::processEvents();
3855 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState)
3857 class TEvent: public SALOME_Event
3862 TEvent( const QString& theEntry, int theState):
3863 myEntry(theEntry), myState(theState) {}
3864 virtual void Execute()
3866 LightApp_Study* aStudy = getActiveStudy();
3869 aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState);
3872 ProcessVoidEvent( new TEvent(theEntry, theState ) );
3875 class TGetVisibilityStateEvent: public SALOME_Event
3878 typedef int TResult;
3881 TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3882 virtual void Execute()
3884 LightApp_Study* aStudy = getActiveStudy();
3886 myResult = aStudy->visibilityState(myEntry);
3890 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3892 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) );
3896 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3898 class TEvent: public SALOME_Event
3903 TEvent( const QString& theEntry, int thePos):
3904 myEntry(theEntry), myPos(thePos) {}
3905 virtual void Execute()
3907 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3909 module->setObjectPosition(myEntry, myPos );
3912 ProcessVoidEvent( new TEvent(theEntry, thePos ) );
3917 class TGetObjectPositionEvent: public SALOME_Event
3920 typedef int TResult;
3923 TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {}
3924 virtual void Execute()
3926 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3928 myResult = module->getObjectPosition(myEntry);
3932 int SalomePyQt::getObjectPosition( const QString& theEntry )
3934 return ProcessEvent( new TGetObjectPositionEvent(theEntry) );
3937 void SalomePyQt::startPyLog(const QString& theFileName)
3939 class TEvent: public SALOME_Event
3943 TEvent( const QString& theFileName ):
3944 myFileName( theFileName ) {}
3945 virtual void Execute()
3947 if ( getApplication() ) {
3948 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3949 if ( pyConsole ) pyConsole->startLog( myFileName );
3953 ProcessVoidEvent( new TEvent( theFileName ) );
3956 void SalomePyQt::stopPyLog()
3958 class TEvent: public SALOME_Event
3962 virtual void Execute()
3964 if ( getApplication() ) {
3965 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
3966 if ( pyConsole ) pyConsole->stopLog();
3970 ProcessVoidEvent( new TEvent() );