1 // Copyright (C) 2007-2015 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 #ifndef DISABLE_OCCVIEWER
42 #include "OCCViewer_ViewWindow.h"
43 #include "OCCViewer_ViewFrame.h"
44 #endif // DISABLE_OCCVIEWER
45 #ifndef DISABLE_PLOT2DVIEWER
46 #include "Plot2d_ViewManager.h"
47 #include "Plot2d_ViewWindow.h"
48 #endif // DISABLE_PLOT2DVIEWER
49 #ifndef DISABLE_PVVIEWER
50 #include "PVViewer_ViewManager.h"
51 #include "PVViewer_ViewModel.h"
52 #endif // DISABLE_PVVIEWER
53 #include "QtxActionMenuMgr.h"
54 #include "QtxWorkstack.h"
55 #include "QtxTreeView.h"
56 #include "SALOME_Event.h"
57 #include "STD_TabDesktop.h"
58 #include "SUIT_DataBrowser.h"
59 #include "SUIT_ResourceMgr.h"
60 #include "SUIT_Session.h"
61 #include "SUIT_Tools.h"
62 #include "SUIT_ViewManager.h"
63 #include "SUIT_ViewWindow.h"
64 #include "SalomePyConsole_Console.h"
67 #include <QApplication>
68 #include <QPaintEvent>
69 #include <QCoreApplication>
74 \brief Get the currently active application.
76 \return active application object or 0 if there is no any
78 LightApp_Application* getApplication()
80 if ( SUIT_Session::session() )
81 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
86 \brief Get the currently active study.
88 \return active study or 0 if there is no study opened
90 LightApp_Study* getActiveStudy()
92 if ( getApplication() )
93 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
98 \brief Get the currently active module.
100 This function returns correct result only if Python-based
101 module is currently active. Otherwize, 0 is returned.
103 LightApp_Module* getActiveModule()
105 LightApp_Module* module = 0;
106 if ( LightApp_Application* anApp = getApplication() ) {
107 module = PyModuleHelper::getInitModule();
109 module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
115 \brief Get the currently active Python module's helper.
117 This function returns correct result only if Python-based
118 module is currently active. Otherwize, 0 is returned.
120 PyModuleHelper* getPythonHelper()
122 LightApp_Module* module = getActiveModule();
123 PyModuleHelper* helper = module ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
128 \brief Get SALOME verbose level
130 \return \c true if SALOME debug output is allowed or \c false otherwise
134 bool isVerbose = false;
135 if ( getenv( "SALOME_VERBOSE" ) ) {
136 QString envVar = getenv( "SALOME_VERBOSE" );
138 int value = envVar.toInt( &ok );
139 isVerbose = ok && value != 0;
145 \brief Get menu item title
147 \param menuId menu identifier
148 \return menu title (localized)
150 QString getMenuName( const QString& menuId )
152 QStringList contexts;
153 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
154 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
155 QString menuName = menuId;
156 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
157 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
162 \brief Load module icon
164 \param module module name
165 \param fileName path to the icon file
168 QIcon loadIconInternal( const QString& module, const QString& fileName )
172 LightApp_Application* app = getApplication();
174 if ( app && !fileName.isEmpty() ) {
175 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
176 QApplication::translate( module.toLatin1().data(),
177 fileName.toLatin1().data() ) );
178 if ( !pixmap.isNull() )
179 icon = QIcon( pixmap );
185 \brief Gets window with specified identifier
187 \param id window identifier
188 \return pointer on the window
190 SUIT_ViewWindow* getWnd( const int id )
192 SUIT_ViewWindow* resWnd = 0;
194 LightApp_Application* app = getApplication();
196 ViewManagerList vmlist = app->viewManagers();
197 foreach( SUIT_ViewManager* vm, vmlist ) {
198 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
199 foreach ( SUIT_ViewWindow* vw, vwlist ) {
200 if ( id == vw->getId() ) {
211 \brief Map of created selection objects.
214 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
217 \brief Default resource file section name.
220 const char* DEFAULT_SECTION = "SalomePyQt";
224 \class SALOME_Selection
225 \brief The class represents selection which can be used in Python.
229 \brief Get the selection object for the specified application.
231 Finds or creates the selection object (one per study).
233 \param app application object
234 \return selection object or 0 if \a app is invalid
236 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
238 SALOME_Selection* sel = 0;
239 if ( app && SelMap.find( app ) != SelMap.end() )
242 sel = SelMap[ app ] = new SALOME_Selection( app );
248 \param p parent object
250 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
252 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
254 mySelMgr = app->selectionMgr();
255 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
256 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
263 SALOME_Selection::~SALOME_Selection()
265 LightApp_Application* app = 0;
266 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
267 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
268 if ( it.value() == this ) app = it.key();
270 if ( app ) SelMap.remove( app );
274 \brief Called when selection manager is destroyed (usually
275 when the study is closed).
277 void SALOME_Selection::onSelMgrDestroyed()
283 \brief Clear the selection.
285 void SALOME_Selection::Clear()
287 class TEvent: public SALOME_Event
289 LightApp_SelectionMgr* mySelMgr;
291 TEvent( LightApp_SelectionMgr* selMgr )
292 : mySelMgr( selMgr ) {}
293 virtual void Execute()
296 mySelMgr->clearSelected();
299 ProcessVoidEvent( new TEvent( mySelMgr ) );
303 \brief Clear the selection.
305 void SALOME_Selection::ClearIObjects()
311 Removes all selection filters.
313 void SALOME_Selection::ClearFilters()
315 class TEvent: public SALOME_Event
317 LightApp_SelectionMgr* mySelMgr;
319 TEvent( LightApp_SelectionMgr* selMgr )
320 : mySelMgr( selMgr ) {}
321 virtual void Execute()
324 mySelMgr->clearFilters();
327 ProcessVoidEvent( new TEvent( mySelMgr ) );
332 \brief The class provides utility functions which can be used in the Python
333 to operate with the SALOME GUI.
335 All the functionality of this class is implemented as static methods, so they
336 can be called with the class name prefixed or via creation of the class instance.
337 For example, next both ways of SalomePyQt class usage are legal:
339 from SalomePyQt import *
341 # using SalomePyQt class instance
342 desktop = sg.getDesktop()
343 # using SalomePyQt class directly
344 menubar = SalomePyQt.getMainMenuBar()
349 \fn QWidget* SalomePyQt::getDesktop();
350 \brief Get the active application's desktop window.
351 \return desktop window or 0 if there is no any
354 class TGetDesktopEvent: public SALOME_Event
357 typedef QWidget* TResult;
359 TGetDesktopEvent() : myResult( 0 ) {}
360 virtual void Execute()
362 if ( getApplication() )
363 myResult = (QWidget*)( getApplication()->desktop() );
366 QWidget* SalomePyQt::getDesktop()
368 return ProcessEvent( new TGetDesktopEvent() );
372 \fn QWidget* SalomePyQt::getMainFrame();
373 \brief Get current application's main frame widget [obsolete].
375 Main frame widget is an internal widget of the application
376 desktop window (workspace).
378 \return workspace widget (0 on any error)
381 class TGetMainFrameEvent: public SALOME_Event
384 typedef QWidget* TResult;
386 TGetMainFrameEvent() : myResult( 0 ) {}
387 virtual void Execute()
389 if ( getApplication() ) {
390 SUIT_Desktop* aDesktop = getApplication()->desktop();
391 myResult = (QWidget*)( aDesktop->centralWidget() );
395 QWidget* SalomePyQt::getMainFrame()
397 return ProcessEvent( new TGetMainFrameEvent() );
401 \fn QMenuBar* SalomePyQt::getMainMenuBar();
402 \brief Get current application desktop's main menu.
403 \return main menu object (0 on any error)
406 class TGetMainMenuBarEvent: public SALOME_Event
409 typedef QMenuBar* TResult;
411 TGetMainMenuBarEvent() : myResult( 0 ) {}
412 virtual void Execute()
414 if ( LightApp_Application* anApp = getApplication() ) {
415 myResult = anApp->desktop()->menuBar();
419 QMenuBar* SalomePyQt::getMainMenuBar()
421 return ProcessEvent( new TGetMainMenuBarEvent() );
425 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
426 \brief Get main menu's child popup submenu by its identifier.
428 This function is obsolete.
429 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
431 \param menu menu identifier
432 \return popup submenu object or 0 if it does not exist
436 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
437 \brief Get main menu's child popup submenu by its name.
439 The function creates menu if it does not exist.
441 \param menu menu name
442 \return popup submenu object (0 on any error)
445 class TGetPopupMenuEvent: public SALOME_Event
448 typedef QMenu* TResult;
451 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
452 virtual void Execute()
454 LightApp_Application* anApp = getApplication();
455 if ( anApp && !myMenuName.isEmpty() ) {
456 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
457 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
462 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
467 menuName = getMenuName( "MEN_DESK_FILE" ); break;
469 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
471 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
473 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
475 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
477 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
479 menuName = getMenuName( "MEN_DESK_HELP" ); break;
481 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
483 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
485 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
489 \fn QTreeView* SalomePyQt::getObjectBrowser();
490 \brief Get object browser
491 \return object browser for the active study or 0 in case of error
494 class TGetObjectBrowserEvent: public SALOME_Event
497 typedef QTreeView* TResult;
499 TGetObjectBrowserEvent() : myResult( 0 ) {}
500 virtual void Execute()
502 LightApp_Application* anApp = getApplication();
503 if ( anApp && anApp->objectBrowser() ) {
504 myResult = anApp->objectBrowser()->treeView();
508 QTreeView* SalomePyQt::getObjectBrowser()
510 return ProcessEvent( new TGetObjectBrowserEvent() );
514 \fn int SalomePyQt::getStudyId();
515 \brief Get active study's identifier.
516 \return active study ID or 0 if there is no active study
519 class TGetStudyIdEvent: public SALOME_Event
524 TGetStudyIdEvent() : myResult( 0 ) {}
525 virtual void Execute()
527 if ( LightApp_Study* aStudy = getActiveStudy() ) {
528 myResult = aStudy->id();
532 int SalomePyQt::getStudyId()
534 return ProcessEvent( new TGetStudyIdEvent() );
538 \fn SALOME_Selection* SalomePyQt::getSelection();
539 \brief Get the selection object for the current study.
541 Creates a Selection object if it has not been created yet.
543 \return selection object (0 on error)
546 class TGetSelectionEvent: public SALOME_Event
549 typedef SALOME_Selection* TResult;
551 TGetSelectionEvent() : myResult( 0 ) {}
552 virtual void Execute()
554 myResult = SALOME_Selection::GetSelection( getApplication() );
557 SALOME_Selection* SalomePyQt::getSelection()
559 return ProcessEvent( new TGetSelectionEvent() );
563 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
564 \brief Put an information message to the current application's
567 Optional second delay parameter (\a sec) can be used to specify
568 time of the message diplaying in seconds. If this parameter is less
569 or equal to zero, the constant message will be put.
571 \param msg message text
572 \param sec message displaying time in seconds
575 class TPutInfoEvent: public SALOME_Event
580 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
581 virtual void Execute()
583 if ( LightApp_Application* anApp = getApplication() ) {
584 anApp->putInfo( myMsg, mySecs * 1000 );
588 void SalomePyQt::putInfo( const QString& msg, const int sec )
590 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
594 \fn const QString SalomePyQt::getActiveComponent();
595 \brief Get the currently active module name (for the current study).
596 \return active module name or empty string if there is no active module
599 class TGetActiveComponentEvent: public SALOME_Event
602 typedef QString TResult;
604 TGetActiveComponentEvent() {}
605 virtual void Execute()
607 if ( LightApp_Application* anApp = getApplication() ) {
608 if ( CAM_Module* mod = anApp->activeModule() ) {
609 myResult = mod->name();
614 const QString SalomePyQt::getActiveComponent()
616 return ProcessEvent( new TGetActiveComponentEvent() );
620 \fn PyObject* SalomePyQt::getActivePythonModule();
621 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
622 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
625 class TGetActivePyModuleEvent: public SALOME_Event
628 typedef PyObject* TResult;
630 TGetActivePyModuleEvent() : myResult( Py_None ) {}
631 virtual void Execute()
633 PyModuleHelper* helper = getPythonHelper();
635 myResult = (PyObject*)helper->pythonModule();
638 PyObject* SalomePyQt::getActivePythonModule()
640 return ProcessEvent( new TGetActivePyModuleEvent() );
644 \fn bool SalomePyQt::activateModule( const QString& modName );
645 \brief Activates SALOME module with the given name
646 \return True if the module has been activated and False otherwise.
649 class TActivateModuleEvent: public SALOME_Event
652 typedef bool TResult;
654 QString myModuleName;
655 TActivateModuleEvent( const QString& modName )
656 : myResult( false ), myModuleName( modName ) {}
657 virtual void Execute()
659 if ( LightApp_Application* anApp = getApplication() ) {
660 myResult = anApp->activateModule( myModuleName );
664 bool SalomePyQt::activateModule( const QString& modName )
666 return ProcessEvent( new TActivateModuleEvent( modName ) );
670 \brief Update an Object Browser of the specified (by identifier) study.
672 If \a studyId <= 0 the active study's object browser is updated.
673 The \a updateSelection parameter is obsolete and currently is not used.
674 This parameter will be removed in future, so try to avoid its usage in
677 \brief studyId study identifier
678 \brief updateSelection update selection flag (not used)
681 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
683 class TEvent: public SALOME_Event
686 bool myUpdateSelection;
688 TEvent( const int studyId, bool updateSelection )
689 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
690 virtual void Execute()
692 if ( SUIT_Session::session() ) {
693 if ( getActiveStudy() && myStudyId <= 0 )
694 myStudyId = getActiveStudy()->id();
695 if ( myStudyId > 0 ) {
696 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
697 QList<SUIT_Application*>::Iterator it;
698 for( it = apps.begin(); it != apps.end(); ++it ) {
699 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
700 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
701 anApp->updateObjectBrowser();
709 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
714 SalomePyQt::isModified()
715 \return The modification status of the data model
716 for the currently active Python module
717 \note This function is supported for "light" Python-based SALOME modules only.
720 class TIsModifiedEvent: public SALOME_Event
723 typedef bool TResult;
725 TIsModifiedEvent() : myResult( false ) {}
726 virtual void Execute()
728 LightApp_Module* module = getActiveModule();
732 SALOME_PYQT_DataModelLight* aModel =
733 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
735 myResult = aModel->isModified();
738 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
742 bool SalomePyQt::isModified()
744 return ProcessEvent(new TIsModifiedEvent());
748 SalomePyQt::setModified()
750 Sets the modification status of the data model for
751 the currently active Python module. This method should be used
752 by the Python code in order to enable/disable "Save" operation
753 depending on the module's data state.
755 \note This function is supported for "light" Python-based SALOME modules only.
757 \param New modification status of the data model
761 void SalomePyQt::setModified( bool flag )
763 class TEvent: public SALOME_Event
769 virtual void Execute()
771 LightApp_Module* module = getActiveModule();
775 SALOME_PYQT_DataModelLight* model =
776 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
778 LightApp_Application* app = module->getApp();
780 if ( model && app ) {
781 model->setModified( myFlag );
782 app->updateActions();
785 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
789 ProcessVoidEvent( new TEvent( flag ) );
793 \brief Add string setting to the application preferences.
795 The parameter \a autoValue is obsolete parameter and currently is not used.
796 This parameter will be removed in future, so try to avoid its usage in
799 This function is obsolete. Use one of addSetting() instead.
801 \param name setting name (it should be of kind <section:setting> where
802 \c section is resources section name and \c setting is setting name)
803 \param value new setting value
804 \param autoValue (not used)
806 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
808 class TEvent: public SALOME_Event
814 TEvent( const QString& name, const QString& value, bool autoValue )
815 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
816 virtual void Execute()
818 if ( SUIT_Session::session() ) {
819 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
820 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
821 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
822 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
823 if ( !_sec.isEmpty() && !_nam.isEmpty() )
824 resMgr->setValue( _sec, _nam, myValue );
828 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
832 \brief Add integer setting to the application preferences.
834 The parameter \a autoValue is obsolete parameter and currently is not used.
835 This parameter will be removed in future, so try to avoid its usage in
838 This function is obsolete. Use one of addSetting() instead.
840 \param name setting name (it should be of kind <section:setting> where
841 \c section is resources section name and \c setting is setting name)
842 \param value new setting value
843 \param autoValue (not used)
845 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
847 class TEvent: public SALOME_Event
853 TEvent( const QString& name, const int value, bool autoValue )
854 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
855 virtual void Execute()
857 if ( SUIT_Session::session() ) {
858 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
859 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
860 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
861 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
862 if ( !_sec.isEmpty() && !_nam.isEmpty() )
863 resMgr->setValue( _sec, _nam, myValue );
867 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
871 \brief Add double setting to the application preferences.
873 The parameter \a autoValue is obsolete parameter and currently is not used.
874 This parameter will be removed in future, so try to avoid its usage in
877 This function is obsolete. Use one of addSetting() instead.
879 \param name setting name (it should be of kind <section:setting> where
880 \c section is resources section name and \c setting is setting name)
881 \param value new setting value
882 \param autoValue (not used)
884 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
886 class TEvent: public SALOME_Event
892 TEvent( const QString& name, const double value, bool autoValue )
893 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
894 virtual void Execute()
896 if ( SUIT_Session::session() ) {
897 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
898 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
899 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
900 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
901 if ( !_sec.isEmpty() && !_nam.isEmpty() )
902 resMgr->setValue( _sec, _nam, myValue );
906 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
910 \brief Add boolean setting to the application preferences.
912 The parameter \a autoValue is obsolete parameter and currently is not used.
913 This parameter will be removed in future, so try to avoid its usage in
916 This function is obsolete. Use one of addSetting() instead.
918 \param name setting name (it should be of kind <section:setting> where
919 \c section is resources section name and \c setting is setting name)
920 \param value new setting value
921 \param autoValue (not used)
923 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
925 class TEvent: public SALOME_Event
931 TEvent( const QString& name, const bool value, bool autoValue )
932 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
933 virtual void Execute()
935 if ( SUIT_Session::session() ) {
936 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
937 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
938 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
939 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
940 if ( !_sec.isEmpty() && !_nam.isEmpty() )
941 resMgr->setValue( _sec, _nam, myValue );
945 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
949 \brief Remove setting from the application preferences.
951 This function is obsolete. Use removeSetting() instead.
953 \param name setting name (it should be of kind <section:setting> where
954 \c section is resources section name and \c setting is setting name)
956 void SalomePyQt::removeSettings( const QString& name )
958 class TEvent: public SALOME_Event
962 TEvent( const QString& name ) : myName( name ) {}
963 virtual void Execute()
965 if ( SUIT_Session::session() ) {
966 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
967 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
968 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
969 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
970 if ( !_sec.isEmpty() && !_nam.isEmpty() )
971 resMgr->remove( _sec, _nam );
975 ProcessVoidEvent( new TEvent( name ) );
979 \fn QString SalomePyQt::getSetting( const QString& name );
980 \brief Get application setting value (as string represenation).
982 This function is obsolete. Use stringSetting(), integerSetting(),
983 boolSetting(), stringSetting() or colorSetting() instead.
985 \param name setting name (it should be of kind <section:setting> where
986 \c section is resources section name and \c setting is setting name)
987 \return setting name (empty string if setting name is invalid)
990 class TGetSettingEvent: public SALOME_Event
993 typedef QString TResult;
996 TGetSettingEvent( const QString& name ) : myName( name ) {}
997 virtual void Execute()
999 if ( SUIT_Session::session() ) {
1000 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1001 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1002 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1003 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1004 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1008 QString SalomePyQt::getSetting( const QString& name )
1010 return ProcessEvent( new TGetSettingEvent( name ) );
1014 \brief Add double setting to the application preferences.
1015 \param section resources file section name
1016 \param name setting name
1017 \param value new setting value
1019 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1021 class TEvent: public SALOME_Event
1027 TEvent( const QString& section, const QString& name, double value )
1028 : mySection( section ), myName( name ), myValue( value ) {}
1029 virtual void Execute()
1031 if ( SUIT_Session::session() ) {
1032 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1033 if ( !mySection.isEmpty() && !myName.isEmpty() )
1034 resMgr->setValue( mySection, myName, myValue );
1038 ProcessVoidEvent( new TEvent( section, name, value ) );
1042 \brief Add integer setting to the application preferences.
1043 \param section resources file section name
1044 \param name setting name
1045 \param value new setting value
1047 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1049 class TEvent: public SALOME_Event
1055 TEvent( const QString& section, const QString& name, int value )
1056 : mySection( section ), myName( name ), myValue( value ) {}
1057 virtual void Execute()
1059 if ( SUIT_Session::session() ) {
1060 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1061 if ( !mySection.isEmpty() && !myName.isEmpty() )
1062 resMgr->setValue( mySection, myName, myValue );
1066 ProcessVoidEvent( new TEvent( section, name, value ) );
1070 \brief Add boolean setting to the application preferences.
1071 \param section resources file section name
1072 \param name setting name
1073 \param value new setting value
1074 \param dumb this parameter is used in order to avoid sip compilation error
1075 because of conflicting int and bool types
1077 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1079 class TEvent: public SALOME_Event
1085 TEvent( const QString& section, const QString& name, bool value )
1086 : mySection( section ), myName( name ), myValue( value ) {}
1087 virtual void Execute()
1089 if ( SUIT_Session::session() ) {
1090 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1091 if ( !mySection.isEmpty() && !myName.isEmpty() )
1092 resMgr->setValue( mySection, myName, myValue );
1096 ProcessVoidEvent( new TEvent( section, name, value ) );
1100 \brief Add string setting to the application preferences.
1101 \param section resources file section name
1102 \param name setting name
1103 \param value new setting value
1105 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1107 class TEvent: public SALOME_Event
1113 TEvent( const QString& section, const QString& name, const QString& value )
1114 : mySection( section ), myName( name ), myValue( value ) {}
1115 virtual void Execute()
1117 if ( SUIT_Session::session() ) {
1118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1119 if ( !mySection.isEmpty() && !myName.isEmpty() )
1120 resMgr->setValue( mySection, myName, myValue );
1124 ProcessVoidEvent( new TEvent( section, name, value ) );
1128 \brief Add color setting to the application preferences.
1129 \param section resources file section name
1130 \param name setting name
1131 \param value new setting value
1133 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1135 class TEvent: public SALOME_Event
1141 TEvent( const QString& section, const QString& name, const QColor& value )
1142 : mySection( section ), myName( name ), myValue( value ) {}
1143 virtual void Execute()
1145 if ( SUIT_Session::session() ) {
1146 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1147 if ( !mySection.isEmpty() && !myName.isEmpty() )
1148 resMgr->setValue( mySection, myName, myValue );
1152 ProcessVoidEvent( new TEvent( section, name, value ) );
1156 \fn int SalomePyQt::integerSetting( const QString& section,
1157 const QString& name,
1159 \brief Get integer setting from the application preferences.
1160 \param section resources file section name
1161 \param name setting name
1162 \param def default value which is returned if the setting is not found
1163 \return setting value
1166 class TGetIntSettingEvent: public SALOME_Event
1169 typedef int TResult;
1174 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1175 : mySection( section ), myName( name ), myDefault( def ) {}
1176 virtual void Execute()
1178 if ( SUIT_Session::session() ) {
1179 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1180 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1184 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1186 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1190 \fn double SalomePyQt::doubleSetting( const QString& section,
1191 const QString& name,
1193 \brief Get double setting from the application preferences.
1194 \param section resources file section name
1195 \param name setting name
1196 \param def default value which is returned if the setting is not found
1197 \return setting value
1200 class TGetDblSettingEvent: public SALOME_Event
1203 typedef double TResult;
1208 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1209 : mySection( section ), myName( name ), myDefault( def ) {}
1210 virtual void Execute()
1212 if ( SUIT_Session::session() ) {
1213 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1214 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1218 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1220 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1224 \fn bool SalomePyQt::boolSetting( const QString& section,
1225 const QString& name,
1227 \brief Get boolean setting from the application preferences.
1228 \param section resources file section name
1229 \param name setting name
1230 \param def default value which is returned if the setting is not found
1231 \return setting value
1234 class TGetBoolSettingEvent: public SALOME_Event
1237 typedef bool TResult;
1242 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1243 : mySection( section ), myName( name ), myDefault( def ) {}
1244 virtual void Execute()
1246 if ( SUIT_Session::session() ) {
1247 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1248 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1252 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1254 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1258 \fn QString SalomePyQt::stringSetting( const QString& section,
1259 const QString& name,
1260 const QString& def );
1261 \brief Get string setting from the application preferences.
1262 \param section resources file section name
1263 \param name setting name
1264 \param def default value which is returned if the setting is not found
1265 \return setting value
1268 class TGetStrSettingEvent: public SALOME_Event
1271 typedef QString TResult;
1276 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1277 : mySection( section ), myName( name ), myDefault( def ) {}
1278 virtual void Execute()
1280 if ( SUIT_Session::session() ) {
1281 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1282 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1286 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1288 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1292 \fn QColor SalomePyQt::colorSetting( const QString& section,
1293 const QString& name,
1295 \brief Get color setting from the application preferences.
1296 \param section resources file section name
1297 \param name setting name
1298 \param def default value which is returned if the setting is not found
1299 \return setting value
1302 class TGetColorSettingEvent: public SALOME_Event
1305 typedef QColor TResult;
1310 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1311 : mySection( section ), myName( name ), myDefault( def ) {}
1312 virtual void Execute()
1314 if ( SUIT_Session::session() ) {
1315 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1316 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1320 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1322 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1326 \brief Remove setting from the application preferences.
1327 \param section resources file section name
1328 \param name setting name
1330 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1332 class TEvent: public SALOME_Event
1337 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1338 virtual void Execute()
1340 if ( SUIT_Session::session() ) {
1341 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1342 if ( !mySection.isEmpty() && !myName.isEmpty() )
1343 resMgr->remove( mySection, myName );
1347 ProcessVoidEvent( new TEvent( section, name ) );
1351 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1352 \brief Check setting existence in the application preferences.
1353 \param section resources file section name
1354 \param name setting name
1355 \return \c true if setting exists
1358 class THasColorSettingEvent: public SALOME_Event
1361 typedef bool TResult;
1365 THasColorSettingEvent( const QString& section, const QString& name )
1366 : mySection( section ), myName( name ) {}
1367 virtual void Execute()
1369 if ( SUIT_Session::session() ) {
1370 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1371 myResult = resMgr->hasValue( mySection, myName );
1375 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1377 return ProcessEvent( new THasColorSettingEvent( section, name ) );
1381 \fn QString SalomePyQt::getFileName( QWidget* parent,
1382 const QString& initial,
1383 const QStringList& filters,
1384 const QString& caption,
1386 \brief Show 'Open/Save file' dialog box for file selection
1387 and return a user's choice (selected file name).
1388 \param parent parent widget
1389 \param initial initial directory the dialog box to be opened in
1390 \param filters list of files filters (wildcards)
1391 \param caption dialog box title
1392 \param open if \c true, "Open File" dialog box is shown;
1393 otherwise "Save File" dialog box is shown
1394 \return selected file name (null string if user cancels operation)
1397 class TGetFileNameEvent: public SALOME_Event
1400 typedef QString TResult;
1404 QStringList myFilters;
1407 TGetFileNameEvent( QWidget* parent,
1408 const QString& initial,
1409 const QStringList& filters,
1410 const QString& caption,
1412 : myParent ( parent ),
1413 myInitial( initial ),
1414 myFilters( filters ),
1415 myCaption( caption ),
1417 virtual void Execute()
1419 if ( LightApp_Application* anApp = getApplication() ) {
1420 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1421 myCaption, myParent );
1425 QString SalomePyQt::getFileName( QWidget* parent,
1426 const QString& initial,
1427 const QStringList& filters,
1428 const QString& caption,
1431 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1435 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1436 const QString& initial,
1437 const QStringList& filters,
1438 const QString& caption );
1439 \brief Show 'Open files' dialog box for multiple files selection
1440 and return a user's choice (selected file names list).
1441 \param parent parent widget
1442 \param initial initial directory the dialog box to be opened in
1443 \param filters list of files filters (wildcards)
1444 \param caption dialog box title
1445 \return selected file names list (empty list if user cancels operation)
1448 class TGetOpenFileNamesEvent: public SALOME_Event
1451 typedef QStringList TResult;
1455 QStringList myFilters;
1457 TGetOpenFileNamesEvent( QWidget* parent,
1458 const QString& initial,
1459 const QStringList& filters,
1460 const QString& caption )
1461 : myParent ( parent ),
1462 myInitial( initial ),
1463 myFilters( filters ),
1464 myCaption( caption ) {}
1465 virtual void Execute()
1467 if ( LightApp_Application* anApp = getApplication() ) {
1468 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1472 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1473 const QString& initial,
1474 const QStringList& filters,
1475 const QString& caption )
1477 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1481 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1482 const QString& initial,
1483 const QString& caption );
1484 \brief Show 'Get Directory' dialog box for the directory selection
1485 and return a user's choice (selected directory name).
1486 \param parent parent widget
1487 \param initial initial directory the dialog box to be opened in
1488 \param caption dialog box title
1489 \return selected directory name (null string if user cancels operation)
1492 class TGetExistingDirectoryEvent: public SALOME_Event
1495 typedef QString TResult;
1500 TGetExistingDirectoryEvent( QWidget* parent,
1501 const QString& initial,
1502 const QString& caption )
1503 : myParent ( parent ),
1504 myInitial( initial ),
1505 myCaption( caption ) {}
1506 virtual void Execute()
1508 if ( LightApp_Application* anApp = getApplication() ) {
1509 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1513 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1514 const QString& initial,
1515 const QString& caption )
1517 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1521 \fn QString SalomePyQt::loadIcon( const QString& filename );
1522 \brief Load an icon from the module resources by the specified file name.
1523 \param fileName icon file name
1527 class TLoadIconEvent: public SALOME_Event
1530 typedef QIcon TResult;
1534 TLoadIconEvent( const QString& module, const QString& filename )
1535 : myModule( module ),
1536 myFileName ( filename ) {}
1537 virtual void Execute()
1539 myResult = loadIconInternal( myModule, myFileName );
1542 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1544 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1548 \brief Open external browser to display context help information.
1551 Current implementation does nothing.
1553 \param source documentation (HTML) file name
1554 \param context context (for example, HTML ancor name)
1556 void SalomePyQt::helpContext( const QString& source, const QString& context )
1558 class TEvent: public SALOME_Event
1563 TEvent( const QString& source, const QString& context )
1564 : mySource( source ), myContext( context ) {}
1565 virtual void Execute()
1567 if ( LightApp_Application* anApp = getApplication() ) {
1568 anApp->onHelpContextModule( "", mySource, myContext );
1572 ProcessVoidEvent( new TEvent( source, context ) );
1576 \fn int SalomePyQt::defaultMenuGroup();
1577 \brief Get detault menu group identifier which can be used when
1578 creating menus (insert custom menu commands).
1579 \return default menu group ID
1582 class TDefMenuGroupEvent: public SALOME_Event
1585 typedef int TResult;
1587 TDefMenuGroupEvent() : myResult( -1 ) {}
1588 virtual void Execute()
1590 myResult = PyModuleHelper::defaultMenuGroup();
1593 int SalomePyQt::defaultMenuGroup()
1595 return ProcessEvent( new TDefMenuGroupEvent() );
1601 CrTool( const QString& tBar, const QString& nBar )
1602 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1603 CrTool( const int id, const int tBar, const int idx )
1604 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1605 CrTool( const int id, const QString& tBar, const int idx )
1606 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1607 CrTool( QAction* action, const int tbId, const int id, const int idx )
1608 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1609 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1610 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1612 int execute( LightApp_Module* module ) const
1617 return module->createTool( myTbTitle, myTbName );
1619 return module->createTool( myId, myTbId, myIndex );
1621 return module->createTool( myId, myTbTitle, myIndex );
1623 return module->createTool( myAction, myTbId, myId, myIndex );
1625 return module->createTool( myAction, myTbTitle, myId, myIndex );
1640 class TCreateToolEvent: public SALOME_Event
1643 typedef int TResult;
1645 const CrTool& myCrTool;
1646 TCreateToolEvent( const CrTool& crTool )
1647 : myResult( -1 ), myCrTool( crTool ) {}
1648 virtual void Execute()
1650 LightApp_Module* module = getActiveModule();
1652 myResult = myCrTool.execute( module );
1657 \brief Create toolbar with specified name.
1658 \param tBar toolbar title (language-dependent)
1659 \param nBar toolbar name (language-independent) [optional]
1660 \return toolbar ID or -1 if toolbar creation is failed
1662 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1664 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1668 \brief Insert action with specified \a id to the toolbar.
1670 \param tBar toolbar ID
1671 \param idx required index in the toolbar
1672 \return action ID or -1 if action could not be added
1674 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1676 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1680 \brief Insert action with specified \a id to the toolbar.
1682 \param tBar toolbar name
1683 \param idx required index in the toolbar
1684 \return action ID or -1 if action could not be added
1686 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1688 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1692 \brief Insert action to the toolbar.
1694 \param tBar toolbar ID
1695 \param id required action ID
1696 \param idx required index in the toolbar
1697 \return action ID or -1 if action could not be added
1699 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1701 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1705 \brief Insert action to the toolbar.
1707 \param tBar toolbar name
1708 \param id required action ID
1709 \param idx required index in the toolbar
1710 \return action ID or -1 if action could not be added
1712 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1714 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1720 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1721 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1722 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1723 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1724 CrMenu( const int id, const int menu, const int group, const int idx )
1725 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1726 CrMenu( const int id, const QString& menu, const int group, const int idx )
1727 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1728 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1729 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1730 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1731 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1733 int execute( LightApp_Module* module ) const
1738 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1740 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1742 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1744 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1746 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1748 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1757 QString mySubMenuName;
1764 class TCreateMenuEvent: public SALOME_Event
1767 typedef int TResult;
1769 const CrMenu& myCrMenu;
1770 TCreateMenuEvent( const CrMenu& crMenu )
1771 : myResult( -1 ), myCrMenu( crMenu ) {}
1772 virtual void Execute()
1774 LightApp_Module* module = getActiveModule();
1776 myResult = myCrMenu.execute( module );
1781 \brief Create main menu.
1782 \param subMenu menu name
1783 \param menu parent menu ID
1784 \param id required menu ID
1785 \param group menu group ID
1786 \param idx required index in the menu
1787 \return menu ID or -1 if menu could not be added
1789 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1791 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1795 \brief Create main menu.
1796 \param subMenu menu name
1797 \param menu parent menu name (list of menu names separated by "|")
1798 \param id required menu ID
1799 \param group menu group ID
1800 \param idx required index in the menu
1801 \return menu ID or -1 if menu could not be added
1803 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1805 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1809 \brief Insert action to the main menu.
1811 \param menu parent menu ID
1812 \param group menu group ID
1813 \param idx required index in the menu
1814 \return action ID or -1 if action could not be added
1816 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1818 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1822 \brief Insert action to the main menu.
1824 \param menu parent menu name (list of menu names separated by "|")
1825 \param group menu group ID
1826 \param idx required index in the menu
1827 \return action ID or -1 if action could not be added
1829 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1831 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1835 \brief Insert action to the main menu.
1837 \param menu parent menu ID
1838 \param group menu group ID
1839 \param idx required index in the menu
1840 \return action ID or -1 if action could not be added
1842 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1844 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1848 \brief Insert action to the main menu.
1850 \param menu parent menu name (list of menu names separated by "|")
1851 \param group menu group ID
1852 \param idx required index in the menu
1853 \return action ID or -1 if action could not be added
1855 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1857 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1861 \fn QAction* SalomePyQt::createSeparator();
1862 \brief Create separator action which can be used in the menu or toolbar.
1863 \return new separator action
1866 class TCreateSepEvent: public SALOME_Event
1869 typedef QAction* TResult;
1873 virtual void Execute()
1875 LightApp_Module* module = getActiveModule();
1877 myResult = (QAction*)module->separator();
1880 QAction* SalomePyQt::createSeparator()
1882 return ProcessEvent( new TCreateSepEvent() );
1886 \fn QAction* SalomePyQt::createAction( const int id,
1887 const QString& menuText,
1888 const QString& tipText,
1889 const QString& statusText,
1890 const QString& icon,
1892 const bool toggle );
1893 \brief Create an action which can be then used in the menu or toolbar.
1894 \param id the unique id action to be registered to
1895 \param menuText action text which should appear in menu
1896 \param tipText text which should appear in the tooltip
1897 \param statusText text which should appear in the status bar when action is activated
1898 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1899 \param key the key accelrator for the action
1900 \param toggle if \c true the action is checkable
1903 class TCreateActionEvent: public SALOME_Event
1906 typedef QAction* TResult;
1911 QString myStatusText;
1915 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1916 const QString& statusText, const QString& icon, const int key, const bool toggle )
1917 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1918 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1919 virtual void Execute()
1921 LightApp_Module* module = getActiveModule();
1923 QIcon icon = loadIconInternal( module->name(), myIcon );
1924 myResult = (QAction*)module->action( myId );
1926 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1927 myResult->setToolTip( myTipText );
1928 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1929 myResult->setText( myMenuText );
1930 if ( myResult->icon().isNull() && !icon.isNull() )
1931 myResult->setIcon( icon );
1932 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1933 myResult->setStatusTip( myStatusText );
1934 if ( myResult->shortcut().isEmpty() && myKey )
1935 myResult->setShortcut( myKey );
1936 if ( myResult->isCheckable() != myToggle )
1937 myResult->setCheckable( myToggle );
1940 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
1942 // for Python module, automatically connect action to callback slot
1943 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
1944 if ( helper ) helper->connectAction( myResult );
1948 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1949 const QString& tipText, const QString& statusText,
1950 const QString& icon, const int key, const bool toggle )
1952 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1956 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
1957 \brief Create an action group which can be then used in the menu or toolbar
1958 \param id : the unique id action group to be registered to
1959 \param exclusive : if \c true the action group does exclusive toggling
1962 struct TCreateActionGroupEvent: public SALOME_Event
1964 typedef QtxActionGroup* TResult;
1968 TCreateActionGroupEvent( const int id, const bool exclusive )
1969 : myId( id ), myExclusive( exclusive ) {}
1970 virtual void Execute()
1972 LightApp_Module* module = getActiveModule();
1974 myResult = module->createActionGroup( myId, myExclusive );
1977 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
1979 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
1983 \fn QAction* SalomePyQt::action( const int id );
1984 \brief Get action by specified identifier.
1985 \return action or 0 if action is not registered
1988 class TActionEvent: public SALOME_Event
1991 typedef QAction* TResult;
1994 TActionEvent( const int id )
1995 : myResult( 0 ), myId( id ) {}
1996 virtual void Execute()
1998 LightApp_Module* module = getActiveModule();
2000 myResult = (QAction*)module->action( myId );
2003 QAction* SalomePyQt::action( const int id )
2005 return ProcessEvent( new TActionEvent( id ) );
2009 \fn int SalomePyQt::actionId( const QAction* a );
2010 \brief Get an action identifier.
2011 \return action ID or -1 if action is not registered
2014 class TActionIdEvent: public SALOME_Event
2017 typedef int TResult;
2019 const QAction* myAction;
2020 TActionIdEvent( const QAction* action )
2021 : myResult( -1 ), myAction( action ) {}
2022 virtual void Execute()
2024 LightApp_Module* module = getActiveModule();
2026 myResult = module->actionId( myAction );
2029 int SalomePyQt::actionId( const QAction* a )
2031 return ProcessEvent( new TActionIdEvent( a ) );
2035 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2036 \brief Add global (not module-related) preferences group.
2037 \param label global preferences group name
2038 \return preferences group identifier
2041 class TAddGlobalPrefEvent: public SALOME_Event
2044 typedef int TResult;
2047 TAddGlobalPrefEvent( const QString& label )
2048 : myResult( -1 ), myLabel( label ) {}
2049 virtual void Execute()
2051 LightApp_Module* module = getActiveModule();
2053 LightApp_Preferences* pref = module->getApp()->preferences();
2055 myResult = pref->addPreference( myLabel, -1 );
2059 int SalomePyQt::addGlobalPreference( const QString& label )
2061 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2065 \fn int SalomePyQt::addPreference( const QString& label );
2066 \brief Add module-related preferences group.
2067 \param label preferences group name
2068 \return preferences group identifier
2071 class TAddPrefEvent: public SALOME_Event
2074 typedef int TResult;
2077 TAddPrefEvent( const QString& label )
2078 : myResult( -1 ), myLabel( label ) {}
2079 virtual void Execute()
2081 LightApp_Module* module = getActiveModule();
2083 LightApp_Preferences* pref = module->getApp()->preferences();
2085 int cId = pref->addPreference( module->moduleName(), -1 );
2087 myResult = pref->addPreference( myLabel, cId );
2092 int SalomePyQt::addPreference( const QString& label )
2094 return ProcessEvent( new TAddPrefEvent( label ) );
2098 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2099 const QString& section, const QString& param );
2100 \brief Add module-related preferences.
2101 \param label preferences group name
2102 \param pId parent preferences group id
2103 \param type preferences type
2104 \param section resources file section name
2105 \param param resources file setting name
2106 \return preferences identifier
2109 class TAddPrefParamEvent: public SALOME_Event
2112 typedef int TResult;
2119 TAddPrefParamEvent( const QString& label,
2120 const int pId, const int type,
2121 const QString& section,
2122 const QString& param )
2124 myLabel( label ), myPId( pId ), myType( type ),
2125 mySection( section ), myParam ( param ) {}
2126 virtual void Execute()
2128 LightApp_Module* module = getActiveModule();
2130 LightApp_Preferences* pref = module->getApp()->preferences();
2132 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2136 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2137 const QString& section, const QString& param )
2139 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2143 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2144 \brief Get the preferences property.
2145 \param id preferences identifier
2146 \param prop preferences property name
2147 \return preferences property value or null QVariant if property is not set
2150 class TPrefPropEvent: public SALOME_Event
2153 typedef QVariant TResult;
2157 TPrefPropEvent( const int id, const QString& prop )
2158 : myId( id ), myProp( prop ) {}
2159 virtual void Execute()
2161 LightApp_Module* module = getActiveModule();
2163 LightApp_Preferences* pref = module->getApp()->preferences();
2165 myResult = pref->itemProperty( myProp, myId );
2169 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2171 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2175 \brief Set the preferences property.
2176 \param id preferences identifier
2177 \param prop preferences property name
2178 \param var preferences property value
2180 void SalomePyQt::setPreferenceProperty( const int id,
2181 const QString& prop,
2182 const QVariant& var )
2184 class TEvent: public SALOME_Event
2190 TEvent( const int id, const QString& prop, const QVariant& var )
2191 : myId( id ), myProp( prop ), myVar( var ) {}
2192 virtual void Execute()
2194 LightApp_Module* module = getActiveModule();
2196 LightApp_Preferences* pref = module->getApp()->preferences();
2198 pref->setItemProperty( myProp, myVar, myId );
2202 ProcessVoidEvent( new TEvent( id, prop, var) );
2206 \brief Add the property value to the list of values.
2208 This method allows creating properties which are QList<QVariant>
2209 - there is no way to pass such values directly to QVariant parameter with PyQt.
2211 \param id preferences identifier
2212 \param prop preferences property name
2213 \param idx preferences property index
2214 \param var preferences property value for the index \a idx
2216 void SalomePyQt::addPreferenceProperty( const int id,
2217 const QString& prop,
2219 const QVariant& var )
2221 class TEvent: public SALOME_Event
2228 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2229 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2230 virtual void Execute()
2232 LightApp_Module* module = getActiveModule();
2234 LightApp_Preferences* pref = module->getApp()->preferences();
2236 QVariant var = pref->itemProperty( myProp, myId );
2237 if ( var.isValid() ) {
2238 if ( var.type() == QVariant::StringList ) {
2239 QStringList sl = var.toStringList();
2240 if ( myIdx >= 0 && myIdx < sl.count() )
2241 sl[myIdx] = myVar.toString();
2243 sl.append( myVar.toString() );
2244 pref->setItemProperty( myProp, sl, myId );
2246 else if ( var.type() == QVariant::List ) {
2247 QList<QVariant> vl = var.toList();
2248 if ( myIdx >= 0 && myIdx < vl.count() )
2252 pref->setItemProperty( myProp, vl, myId );
2258 pref->setItemProperty( myProp, vl, myId );
2264 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2268 \brief Put the message to the Log messages output window
2269 \param msg message text (it can be of simple rich text format)
2270 \param addSeparator boolean flag which specifies if it is necessary
2271 to separate the message with predefined separator
2273 void SalomePyQt::message( const QString& msg, bool addSeparator )
2275 class TEvent: public SALOME_Event
2280 TEvent( const QString& msg, bool addSeparator )
2281 : myMsg( msg ), myAddSep( addSeparator ) {}
2282 virtual void Execute()
2284 if ( LightApp_Application* anApp = getApplication() ) {
2285 LogWindow* lw = anApp->logWindow();
2287 lw->putMessage( myMsg, myAddSep );
2291 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2295 \brief Remove all the messages from the Log messages output window.
2297 void SalomePyQt::clearMessages()
2299 class TEvent: public SALOME_Event
2303 virtual void Execute()
2305 if ( LightApp_Application* anApp = getApplication() ) {
2306 LogWindow* lw = anApp->logWindow();
2312 ProcessVoidEvent( new TEvent() );
2316 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2317 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2318 to the image file in the specified format.
2320 For the current moment JPEG, PNG and BMP images formats are supported.
2321 The image format is defined automatically by the file name extension.
2322 By default, BMP format is used.
2324 \param filename image file name
2325 \return operation status (\c true on success)
2328 class TDumpViewEvent: public SALOME_Event
2331 typedef bool TResult;
2335 TDumpViewEvent( const QString& filename, const int id )
2336 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2337 virtual void Execute()
2339 SUIT_ViewWindow* wnd = 0;
2341 if ( LightApp_Application* anApp = getApplication() ) {
2342 SUIT_ViewManager* vm = anApp->activeViewManager();
2344 wnd = vm->getActiveView();
2346 myWndId = wnd->getId();
2349 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2352 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2353 #ifndef DISABLE_PLOT2DVIEWER
2354 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2356 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2357 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2358 qApp->processEvents();
2359 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2360 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2364 #endif // DISABLE_PLOT2DVIEWER
2365 QImage im = wnd->dumpView();
2366 if ( !im.isNull() && !myFileName.isEmpty() ) {
2367 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2368 if ( fmt == "JPG" ) fmt = "JPEG";
2369 myResult = im.save( myFileName, fmt.toLatin1() );
2374 bool SalomePyQt::dumpView( const QString& filename, const int id )
2376 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2380 \fn QList<int> SalomePyQt::getViews();
2381 \brief Get list of integer identifiers of all the currently opened views
2382 \return list of integer identifiers of all the currently opened views
2385 class TGetViews: public SALOME_Event
2388 typedef QList<int> TResult;
2391 virtual void Execute()
2394 LightApp_Application* app = getApplication();
2396 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2398 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2399 SUIT_ViewWindow* wnd;
2400 foreach ( wnd, wndlist )
2401 myResult.append( wnd->getId() );
2406 QList<int> SalomePyQt::getViews()
2408 return ProcessEvent( new TGetViews() );
2412 \fn int SalomePyQt::getActiveView();
2413 \brief Get integer identifier of the currently active view
2414 \return integer identifier of the currently active view
2417 class TGetActiveView: public SALOME_Event
2420 typedef int TResult;
2424 virtual void Execute()
2426 LightApp_Application* app = getApplication();
2428 SUIT_ViewManager* viewMgr = app->activeViewManager();
2430 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2432 myResult = wnd->getId();
2437 int SalomePyQt::getActiveView()
2439 return ProcessEvent( new TGetActiveView() );
2443 \fn QString SalomePyQt::getViewType( const int id );
2444 \brief Get type of the specified view, e.g. "OCCViewer"
2445 \param id window identifier
2449 class TGetViewType: public SALOME_Event
2452 typedef QString TResult;
2455 TGetViewType( const int id )
2457 virtual void Execute()
2459 SUIT_ViewWindow* wnd = getWnd( myWndId );
2461 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2463 myResult = viewMgr->getType();
2467 QString SalomePyQt::getViewType( const int id )
2469 return ProcessEvent( new TGetViewType( id ) );
2473 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2474 \brief Change view caption
2475 \param id window identifier
2476 \param title new window title
2477 \return \c true if operation is completed successfully and \c false otherwise
2480 class TSetViewTitle: public SALOME_Event
2483 typedef bool TResult;
2487 TSetViewTitle( const int id, const QString& title )
2488 : myResult( false ),
2491 virtual void Execute()
2493 SUIT_ViewWindow* wnd = getWnd( myWndId );
2495 wnd->setWindowTitle( myTitle );
2500 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2502 return ProcessEvent( new TSetViewTitle( id, title ) );
2506 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2507 \brief Set view size
2508 \param w window width
2509 \param h window height
2510 \param id window identifier
2511 \return \c true if operation is completed successfully and \c false otherwise
2514 class TSetViewSize: public SALOME_Event
2517 typedef bool TResult;
2522 TSetViewSize( const int w, const int h, const int id )
2523 : myResult( false ),
2527 virtual void Execute()
2529 SUIT_ViewWindow* wnd = 0;
2531 if ( LightApp_Application* anApp = getApplication() ) {
2532 SUIT_ViewManager* vm = anApp->activeViewManager();
2534 wnd = vm->getActiveView();
2538 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2541 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2543 QString type = viewMgr->getType();
2544 if ( type == "OCCViewer") {
2545 #ifndef DISABLE_OCCVIEWER
2546 // specific processing for OCC viewer:
2547 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2548 // - if there is only one sub-view active; it will be resized;
2549 // - if there are several sub-views, each of them will be resized.
2550 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2551 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2552 if ( occView && occView->getView( i ) ) {
2553 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2557 #endif // DISABLE_OCCVIEWER
2559 else if ( type == "ParaView") {
2560 #ifndef DISABLE_PVVIEWER
2561 // specific processing for ParaView viewer:
2562 // hierarchy of ParaView viewer is much complex than for usual view;
2563 // we look for sub-widget named "Viewport"
2564 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2565 if ( !lst.isEmpty() ) {
2566 lst[0]->resize( myWndWidth, myWndHeight );
2569 #endif // DISABLE_PVVIEWER
2572 if ( wnd->centralWidget() ) {
2573 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2581 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2583 return ProcessEvent( new TSetViewSize( w, h, id ) );
2587 \fn QString SalomePyQt::getViewTitle( const int id );
2588 \brief Get view caption
2589 \param id window identifier
2590 \return view caption
2593 class TGetViewTitle: public SALOME_Event
2596 typedef QString TResult;
2599 TGetViewTitle( const int id )
2601 virtual void Execute()
2603 SUIT_ViewWindow* wnd = getWnd( myWndId );
2605 myResult = wnd->windowTitle();
2608 QString SalomePyQt::getViewTitle( const int id )
2610 return ProcessEvent( new TGetViewTitle( id ) );
2614 \fn QList<int> SalomePyQt::findViews( const QString& type );
2615 \brief Get list of integer identifiers of all the
2616 currently opened views of the specified type
2617 \param type viewer type
2618 \return list of integer identifiers
2621 class TFindViews: public SALOME_Event
2624 typedef QList<int> TResult;
2627 TFindViews( const QString& type )
2629 virtual void Execute()
2632 LightApp_Application* app = getApplication();
2634 ViewManagerList vmList;
2635 app->viewManagers( myType, vmList );
2636 SUIT_ViewManager* viewMgr;
2637 foreach ( viewMgr, vmList ) {
2638 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2639 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2640 SUIT_ViewWindow* wnd = vec[ i ];
2642 myResult.append( wnd->getId() );
2648 QList<int> SalomePyQt::findViews( const QString& type )
2650 return ProcessEvent( new TFindViews( type ) );
2654 \fn bool SalomePyQt::activateView( const int id );
2655 \brief Activate view
2656 \param id window identifier
2657 \return \c true if operation is completed successfully and \c false otherwise
2660 class TActivateView: public SALOME_Event
2663 typedef bool TResult;
2666 TActivateView( const int id )
2667 : myResult( false ),
2669 virtual void Execute()
2671 SUIT_ViewWindow* wnd = getWnd( myWndId );
2678 bool SalomePyQt::activateView( const int id )
2680 return ProcessEvent( new TActivateView( id ) );
2684 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2685 \brief Create new view and activate it
2686 \param type viewer type
2690 \return integer identifier of created view (or -1 if view could not be created)
2693 class TCreateView: public SALOME_Event
2696 typedef int TResult;
2702 TCreateView( const QString& theType, bool visible, const int width, const int height )
2708 virtual void Execute()
2710 LightApp_Application* app = getApplication();
2712 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2714 QWidget* wnd = viewMgr->getActiveView();
2715 myResult = viewMgr->getActiveView()->getId();
2718 wnd->setVisible(false);
2719 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2723 if (myWidth > 0 && myHeight > 0) {
2724 #ifndef DISABLE_PLOT2DVIEWER
2725 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2726 if ( wnd2D ) wnd = wnd2D->getViewFrame();
2727 #endif // DISABLE_PLOT2DVIEWER
2728 wnd->setGeometry( 0, 0, myWidth, myHeight );
2735 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2737 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2738 QCoreApplication::processEvents();
2743 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2744 \brief Create new view with custom widget embedded and activate it
2745 \param type viewer type
2746 \param w custom widget
2747 \return integer identifier of created view (or -1 if view could not be created)
2750 class TCreateViewWg: public SALOME_Event
2753 typedef int TResult;
2757 TCreateViewWg( const QString& theType, QWidget* w )
2761 virtual void Execute()
2763 LightApp_Application* app = getApplication();
2765 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2767 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2769 myResult = wnd->getId();
2774 int SalomePyQt::createView( const QString& type, QWidget* w )
2776 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2777 QCoreApplication::processEvents();
2782 \fn bool SalomePyQt::closeView( const int id );
2784 \param id window identifier
2785 \return \c true if operation is completed successfully and \c false otherwise
2788 class TCloseView: public SALOME_Event
2791 typedef bool TResult;
2794 TCloseView( const int id )
2795 : myResult( false ),
2797 virtual void Execute()
2799 SUIT_ViewWindow* wnd = getWnd( myWndId );
2801 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2809 bool SalomePyQt::closeView( const int id )
2811 return ProcessEvent( new TCloseView( id ) );
2815 \fn int SalomePyQt::cloneView( const int id );
2816 \brief Clone view (if this operation is supported for specified view type)
2817 \param id window identifier
2818 \return integer identifier of the cloned view or -1 or operation could not be performed
2821 class TCloneView: public SALOME_Event
2824 typedef int TResult;
2827 TCloneView( const int id )
2830 virtual void Execute()
2832 SUIT_ViewWindow* wnd = getWnd( myWndId );
2834 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2836 #ifndef DISABLE_OCCVIEWER
2837 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
2838 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2839 occView->onCloneView();
2840 wnd = viewMgr->getActiveView();
2842 myResult = wnd->getId();
2844 #endif // DISABLE_OCCVIEWER
2845 #ifndef DISABLE_PLOT2DVIEWER
2846 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
2847 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2848 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2849 if ( viewMgr2d && srcWnd2d ) {
2850 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2851 myResult = resWnd->getId();
2854 #endif // DISABLE_OCCVIEWER
2859 int SalomePyQt::cloneView( const int id )
2861 return ProcessEvent( new TCloneView( id ) );
2865 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2866 \brief Set view visibility.
2867 \param id window identifier
2868 \param visible new visiblity
2871 void SalomePyQt::setViewVisible( const int id, const bool visible )
2873 class TEvent: public SALOME_Event
2878 TEvent( const int id, const bool visible )
2879 : myWndId( id ), myVisible( visible ) {}
2880 virtual void Execute()
2882 SUIT_ViewWindow* wnd = getWnd( myWndId );
2883 if ( wnd ) wnd->setVisible( myVisible );
2886 ProcessVoidEvent( new TEvent( id, visible ) );
2890 \fn bool SalomePyQt::isViewVisible( const int id );
2891 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2892 \param id window identifier
2893 \return \c true if view is visible and \c false otherwise
2896 class TIsViewVisible: public SALOME_Event
2899 typedef bool TResult;
2902 TIsViewVisible( const int id )
2903 : myResult( false ),
2905 virtual void Execute()
2907 SUIT_ViewWindow* wnd = getWnd( myWndId );
2910 QWidget* p = wnd->parentWidget();
2911 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2915 bool SalomePyQt::isViewVisible( const int id )
2917 return ProcessEvent( new TIsViewVisible( id ) );
2921 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2922 \brief Set / clear view's "closable" option. By default any view is closable
2923 (i.e. can be closed by the user).
2924 \param id window identifier
2925 \param on new "closable" option's value
2928 void SalomePyQt::setViewClosable( const int id, const bool on )
2930 class TEvent: public SALOME_Event
2935 TEvent( const int id, const bool on )
2936 : myWndId( id ), myOn( on ) {}
2937 virtual void Execute()
2939 SUIT_ViewWindow* wnd = getWnd( myWndId );
2940 if ( wnd ) wnd->setClosable( myOn );
2943 ProcessVoidEvent( new TEvent( id, on ) );
2947 \fn bool SalomePyQt::isViewClosable( const int id );
2948 \brief Check whether view is closable (i.e. can be closed by the user)
2949 \param id window identifier
2950 \return \c true if view is closable or \c false otherwise
2953 class TIsViewClosable: public SALOME_Event
2956 typedef bool TResult;
2959 TIsViewClosable( const int id )
2962 virtual void Execute()
2964 SUIT_ViewWindow* wnd = getWnd( myWndId );
2966 myResult = wnd->closable();
2970 bool SalomePyQt::isViewClosable( const int id )
2972 return ProcessEvent( new TIsViewClosable( id ) );
2976 \fn bool SalomePyQt::groupAllViews();
2977 \brief Group all views to the single tab area
2978 \return \c true if operation is completed successfully and \c false otherwise
2981 class TGroupAllViews: public SALOME_Event
2984 typedef bool TResult;
2987 : myResult( false ) {}
2988 virtual void Execute()
2990 LightApp_Application* app = getApplication();
2992 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2994 QtxWorkstack* wStack = tabDesk->workstack();
3003 bool SalomePyQt::groupAllViews()
3005 return ProcessEvent( new TGroupAllViews() );
3009 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3010 \brief Split tab area to which view with identifier belongs to
3011 \param id window identifier
3012 \param ori orientation of split operation
3013 \param action action to be performed
3014 \return \c true if operation is completed successfully \c false otherwise
3017 class TSplitView: public SALOME_Event
3020 typedef bool TResult;
3025 TSplitView( const int id,
3026 const Orientation ori,
3027 const Action action )
3028 : myResult( false ),
3031 myAction( action ) {}
3032 virtual void Execute()
3034 SUIT_ViewWindow* wnd = getWnd( myWndId );
3037 // wnd->setFocus(); ???
3040 if ( getApplication() ) {
3041 STD_TabDesktop* desk =
3042 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3044 QtxWorkstack* wStack = desk->workstack();
3046 Qt::Orientation qtOri =
3047 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3049 QtxWorkstack::SplitType sType;
3050 if ( myAction == MoveWidget )
3051 sType = QtxWorkstack::SplitMove;
3052 else if ( myAction == LeaveWidget )
3053 sType = QtxWorkstack::SplitStay;
3055 sType = QtxWorkstack::SplitAt;
3057 wStack->Split( wnd, qtOri, sType );
3065 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3067 return ProcessEvent( new TSplitView( id, ori, action ) );
3071 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3072 \brief Move view with the first identifier to the same area which
3073 another view with the second identifier belongs to
3074 \param id source window identifier
3075 \param id_to destination window identifier
3076 param before specifies whether the first viewt has to be moved before or after
3078 \return \c true if operation is completed successfully and \c false otherwise
3081 class TMoveView: public SALOME_Event
3084 typedef bool TResult;
3089 TMoveView( const int id, const int id_to, const bool before )
3090 : myResult( false ),
3093 myIsBefore( before ) {}
3094 virtual void Execute()
3096 SUIT_ViewWindow* wnd = getWnd( myWndId );
3097 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3098 if ( wnd && wnd_to ) {
3099 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3100 getApplication()->desktop() )->workstack();
3102 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3106 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3108 return ProcessEvent( new TMoveView( id, id_to, before ) );
3112 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3113 \brief Get list of views identifiers that belongs to the same area as
3114 specified view (excluding it)
3115 \param id window identifier
3116 \return list of views identifiers
3119 class TNeighbourViews: public SALOME_Event
3122 typedef QList<int> TResult;
3125 TNeighbourViews( const int id )
3127 virtual void Execute()
3130 SUIT_ViewWindow* wnd = getWnd( myWndId );
3132 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3133 getApplication()->desktop() )->workstack();
3135 QWidgetList wgList = wStack->windowList( wnd );
3137 foreach ( wg, wgList ) {
3138 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3139 if ( tmpWnd && tmpWnd != wnd )
3140 myResult.append( tmpWnd->getId() );
3146 QList<int> SalomePyQt::neighbourViews( const int id )
3148 return ProcessEvent( new TNeighbourViews( id ) );
3153 \fn QString SalomePyQt::createObject( const QString& parent );
3154 \brief Create empty data object
3155 \param parent entry of parent data object
3156 \return entry of created data object
3159 class TCreateEmptyObjectEvent: public SALOME_Event
3162 typedef QString TResult;
3165 TCreateEmptyObjectEvent( const QString& parent )
3166 : myParent( parent ) {}
3167 virtual void Execute()
3169 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3171 myResult = module->createObject( myParent );
3174 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3178 QString SalomePyQt::createObject( const QString& parent )
3180 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3184 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3185 const QString& tooltip,const QString& parent );
3186 \brief Create new data object with specified name, icon and tooltip
3187 \param name data object name
3188 \param icon data object icon
3189 \param toolTip data object tooltip
3190 \param parent entry of parent data object
3191 \return entry of created data object
3194 class TCreateObjectEvent: public SALOME_Event
3197 typedef QString TResult;
3203 TCreateObjectEvent( const QString& name,
3204 const QString& icon,
3205 const QString& tooltip,
3206 const QString& parent )
3209 myToolTip( tooltip ),
3210 myParent( parent ) {}
3211 virtual void Execute()
3213 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3215 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3218 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3222 QString SalomePyQt::createObject( const QString& name,
3223 const QString& icon,
3224 const QString& toolTip,
3225 const QString& parent )
3227 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3232 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3233 \brief Set data object name
3234 \param entry data object entry
3235 \param name data object name
3237 class TSetNameEvent: public SALOME_Event
3242 TSetNameEvent( const QString& entry,
3243 const QString& name )
3246 virtual void Execute()
3248 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3250 module->setName( myEntry, myName );
3253 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3257 void SalomePyQt::setName( const QString& entry, const QString& name )
3259 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3263 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3264 \brief Set data object icon
3265 \param entry data object entry
3266 \param icon data object icon file name (icon is loaded from module resources)
3269 class TSetIconEvent: public SALOME_Event
3274 TSetIconEvent( const QString& entry,
3275 const QString& icon )
3278 virtual void Execute()
3280 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3282 module->setIcon( myEntry, myIcon );
3285 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3290 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3292 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3296 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3297 \brief Set data object tooltip
3298 \param entry data object entry
3299 \param toolTip data object tooltip
3302 class TSetToolTipEvent: public SALOME_Event
3307 TSetToolTipEvent( const QString& entry,
3308 const QString& toolTip )
3310 myToolTip( toolTip ) {}
3311 virtual void Execute()
3313 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3315 module->setToolTip( myEntry, myToolTip );
3318 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3322 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3324 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3328 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3329 \brief Set reference to another data object
3330 \param entry data object entry
3331 \param refEntry referenced data object entry
3334 class TSetRefEvent: public SALOME_Event
3339 TSetRefEvent( const QString& entry,
3340 const QString& refEntry )
3342 myRefEntry( refEntry ) {}
3343 virtual void Execute()
3345 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3347 module->setReference( myEntry, myRefEntry );
3350 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3354 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3356 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3360 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3361 \brief Set data object color
3362 \param entry data object entry
3363 \param color data object color
3366 class TSetColorEvent: public SALOME_Event
3371 TSetColorEvent( const QString& entry,
3372 const QColor& color )
3375 virtual void Execute()
3377 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3379 module->setColor( myEntry, myColor );
3382 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3386 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3388 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3392 \fn QString SalomePyQt::getName( const QString& entry );
3393 \brief Get data object name
3394 \param entry data object entry
3395 \return data object name
3398 class TGetNameEvent: public SALOME_Event
3401 typedef QString TResult;
3404 TGetNameEvent( const QString& entry )
3405 : myEntry( entry ) {}
3406 virtual void Execute()
3408 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3410 myResult = module->getName( myEntry );
3413 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3417 QString SalomePyQt::getName( const QString& entry )
3419 return ProcessEvent( new TGetNameEvent( entry ) );
3423 \fn QString SalomePyQt::getToolTip( const QString& entry );
3424 \brief Get data object tooltip
3425 \param entry data object entry
3426 \return data object tooltip
3429 class TGetToolTipEvent: public SALOME_Event
3432 typedef QString TResult;
3435 TGetToolTipEvent( const QString& entry )
3436 : myEntry( entry ) {}
3437 virtual void Execute()
3439 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3441 myResult = module->getToolTip( myEntry );
3444 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3448 QString SalomePyQt::getToolTip( const QString& entry )
3450 return ProcessEvent( new TGetToolTipEvent( entry ) );
3454 \fn QString SalomePyQt::getReference( const QString& entry );
3455 \brief Get entry of the referenced object (if there's any)
3456 \param entry data object entry
3457 \return referenced data object entry
3460 class TGetRefEvent: public SALOME_Event
3463 typedef QString TResult;
3466 TGetRefEvent( const QString& entry )
3467 : myEntry( entry ) {}
3468 virtual void Execute()
3470 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3472 myResult = module->getReference( myEntry );
3475 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3479 QString SalomePyQt::getReference( const QString& entry )
3481 return ProcessEvent( new TGetRefEvent( entry ) );
3485 \fn QColor SalomePyQt::getColor( const QString& entry );
3486 \brief Get data object color
3487 \param entry data object entry
3488 \return data object color
3491 class TGetColorEvent: public SALOME_Event
3494 typedef QColor TResult;
3497 TGetColorEvent( const QString& entry )
3498 : myEntry( entry ) {}
3499 virtual void Execute()
3501 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3503 myResult = module->getColor( myEntry );
3506 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3510 QColor SalomePyQt::getColor( const QString& entry )
3512 return ProcessEvent( new TGetColorEvent( entry ) );
3516 \fn void SalomePyQt::removeChildren( const QString& entry );
3517 \brief Remove all child data objects from specified data object
3518 \param entry data object entry
3521 class TRemoveChildEvent: public SALOME_Event
3525 TRemoveChildEvent( const QString& entry )
3526 : myEntry( entry ) {}
3527 virtual void Execute()
3529 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3531 module->removeChildren( myEntry );
3534 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3538 void SalomePyQt::removeChildren( const QString& entry )
3540 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3542 void SalomePyQt::removeChild( const QString& entry )
3544 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3545 removeChildren( entry );
3549 \fn void SalomePyQt::removeObject( const QString& entry );
3550 \brief Remove object by entry
3551 \param entry data object entry
3554 class TRemoveObjectEvent: public SALOME_Event
3559 TRemoveObjectEvent( const QString& entry )
3560 : myEntry( entry ) {}
3561 virtual void Execute()
3563 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3565 module->removeObject( myEntry );
3568 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3572 void SalomePyQt::removeObject( const QString& entry )
3574 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3578 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3579 \brief Get entries of all child data objects of specified data object
3580 \param entry data object entry
3581 \param recursive \c true for recursive processing
3584 class TGetChildrenEvent: public SALOME_Event
3587 typedef QStringList TResult;
3591 TGetChildrenEvent( const QString& entry, const bool recursive )
3593 myRecursive( recursive ) {}
3594 virtual void Execute()
3596 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3598 myResult = module->getChildren( myEntry, myRecursive );
3601 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3605 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3607 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3610 #ifndef DISABLE_PLOT2DVIEWER
3611 // Next set of methods relates to the Plot2d viewer functionality
3614 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3615 \brief Display theCurve in view
3616 \param id window identifier
3617 \param theCurve curve to display
3620 class TDisplayCurve: public SALOME_Event
3624 Plot2d_Curve* myCurve;
3625 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3626 virtual void Execute() {
3627 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3629 wnd->getViewFrame()->displayCurve( myCurve );
3632 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3634 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
3638 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3639 \brief Erase theCurve in view
3640 \param id window identifier
3641 \param theCurve curve to erase
3644 class TEraseCurve: public SALOME_Event
3648 Plot2d_Curve* myCurve;
3649 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3650 virtual void Execute() {
3651 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3652 wnd->getViewFrame()->eraseCurve( myCurve );
3655 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3657 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
3661 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3662 \brief Delete theCurve from all views
3663 \param theCurve curve to delete
3666 class TDeleteCurve: public SALOME_Event
3669 Plot2d_Curve* myCurve;
3670 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3671 virtual void Execute() {
3672 LightApp_Application* app = getApplication();
3674 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3676 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3677 SUIT_ViewWindow* wnd;
3678 foreach ( wnd, wndlist ) {
3679 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3681 aP2d->getViewFrame()->eraseObject( myCurve );
3687 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3689 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3693 \brief updateCurves (repaint) curves in view window.
3695 void SalomePyQt::updateCurves( const int id )
3697 class TEvent: public SALOME_Event
3701 TEvent( const int id ) : myWndId( id ) {}
3702 virtual void Execute()
3704 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3706 wnd->getViewFrame()->DisplayAll();
3709 ProcessVoidEvent( new TEvent( id ) );
3713 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3714 \brief Get title of corresponding type
3715 \param id window identifier
3716 \param type is type of title
3717 \return title of corresponding type
3720 class TGetPlot2dTitle: public SALOME_Event
3723 typedef QString TResult;
3727 TGetPlot2dTitle(const int id, ObjectType type) :
3730 virtual void Execute() {
3731 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3733 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
3736 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
3738 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
3743 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3744 \brief Set title of corresponding type
3745 \param id window identifier
3747 \param type is type of title
3751 class TSetPlot2dTitle: public SALOME_Event
3755 Plot2d_Curve* myCurve;
3759 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
3764 virtual void Execute() {
3765 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3766 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
3769 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
3771 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
3775 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3776 \brief Get list of Plot2d view ranges
3777 \param id window identifier
3778 \return list of view ranges (XMin, XMax, YMin, YMax)
3781 class TFitRangeByCurves: public SALOME_Event
3784 typedef QList<double> TResult;
3787 TFitRangeByCurves( const int id )
3789 virtual void Execute()
3792 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3794 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3795 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3796 myResult.append( XMin );
3797 myResult.append( XMax );
3798 myResult.append( YMin );
3799 myResult.append( YMax );
3803 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3805 return ProcessEvent( new TFitRangeByCurves( id ) );
3809 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3810 \brief Get list of current Plot2d view ranges
3811 \param id window identifier
3812 \return list of view ranges (XMin, XMax, YMin, YMax)
3815 class TFitRangeCurrent: public SALOME_Event
3818 typedef QList<double> TResult;
3821 TFitRangeCurrent( const int id )
3823 virtual void Execute()
3826 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3828 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3829 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3830 myResult.append( XMin );
3831 myResult.append( XMax );
3832 myResult.append( YMin );
3833 myResult.append( YMax );
3837 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3839 return ProcessEvent( new TFitRangeCurrent( id ) );
3843 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3844 \brief Set range of Plot2d view
3845 \param id window identifier
3852 class TPlot2dFitRange: public SALOME_Event
3860 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
3866 virtual void Execute() {
3867 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3869 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
3872 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3874 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
3877 // End of methods related to the Plot2d viewer functionality
3878 #endif // DISABLE_PLOT2DVIEWER
3881 \brief Process Qt event loop
3883 void SalomePyQt::processEvents()
3885 QCoreApplication::processEvents();
3889 \brief Set visibility state for given object
3890 \param theEntry study ID of the object
3891 \param theState visibility state
3893 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
3895 class TEvent: public SALOME_Event
3900 TEvent( const QString& theEntry, int theState ):
3901 myEntry( theEntry ), myState( theState ) {}
3902 virtual void Execute()
3904 LightApp_Study* aStudy = getActiveStudy();
3907 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
3910 ProcessVoidEvent( new TEvent( theEntry, theState ) );
3914 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3915 \brief Get visibility state for given object
3916 \param theEntry study ID of the object
3917 \return visibility state
3920 class TGetVisibilityStateEvent: public SALOME_Event
3923 typedef int TResult;
3926 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
3927 virtual void Execute()
3929 LightApp_Study* aStudy = getActiveStudy();
3931 myResult = aStudy->visibilityState( myEntry );
3934 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3936 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
3940 \brief Set position of given object in the tree
3941 \param theEntry study ID of the object
3942 \param thePos position
3944 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3946 class TEvent: public SALOME_Event
3951 TEvent( const QString& theEntry, int thePos ):
3952 myEntry( theEntry ), myPos( thePos ) {}
3953 virtual void Execute()
3955 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3957 module->setObjectPosition( myEntry, myPos );
3960 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
3964 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
3965 \brief Get position of given object in the tree
3966 \param theEntry study ID of the object
3970 class TGetObjectPositionEvent: public SALOME_Event
3973 typedef int TResult;
3976 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
3977 virtual void Execute()
3979 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3981 myResult = module->getObjectPosition( myEntry );
3984 int SalomePyQt::getObjectPosition( const QString& theEntry )
3986 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
3990 \brief Start recordind a log of Python commands from embedded console
3991 \param theFileName output lof file name
3993 void SalomePyQt::startPyLog( const QString& theFileName )
3995 class TEvent: public SALOME_Event
3999 TEvent( const QString& theFileName ):
4000 myFileName( theFileName ) {}
4001 virtual void Execute()
4003 if ( getApplication() ) {
4004 SalomePyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4005 if ( pyConsole ) pyConsole->startLog( myFileName );
4009 ProcessVoidEvent( new TEvent( theFileName ) );
4013 \brief Stop recordind a log of Python commands from embedded console
4015 void SalomePyQt::stopPyLog()
4017 class TEvent: public SALOME_Event
4021 virtual void Execute()
4023 if ( getApplication() ) {
4024 SalomePyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4025 if ( pyConsole ) pyConsole->stopLog();
4029 ProcessVoidEvent( new TEvent() );