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 "PyConsole_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 ? qFindChild<PyModuleHelper*>( module, "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();
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 = qFindChild<PyModuleHelper*>( module, "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 = qFindChildren<QWidget*>( wnd, "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();
2717 wnd->setShown(myVisible);
2718 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2722 if (myWidth > 0 && myHeight > 0) {
2723 #ifndef DISABLE_PLOT2DVIEWER
2724 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2725 if ( wnd2D ) wnd = wnd2D->getViewFrame();
2726 #endif // DISABLE_PLOT2DVIEWER
2727 wnd->setGeometry( 0, 0, myWidth, myHeight );
2734 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2736 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2737 QCoreApplication::processEvents();
2742 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2743 \brief Create new view with custom widget embedded and activate it
2744 \param type viewer type
2745 \param w custom widget
2746 \return integer identifier of created view (or -1 if view could not be created)
2749 class TCreateViewWg: public SALOME_Event
2752 typedef int TResult;
2756 TCreateViewWg( const QString& theType, QWidget* w )
2760 virtual void Execute()
2762 LightApp_Application* app = getApplication();
2764 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2766 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2768 myResult = wnd->getId();
2773 int SalomePyQt::createView( const QString& type, QWidget* w )
2775 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2776 QCoreApplication::processEvents();
2781 \fn bool SalomePyQt::closeView( const int id );
2783 \param id window identifier
2784 \return \c true if operation is completed successfully and \c false otherwise
2787 class TCloseView: public SALOME_Event
2790 typedef bool TResult;
2793 TCloseView( const int id )
2794 : myResult( false ),
2796 virtual void Execute()
2798 SUIT_ViewWindow* wnd = getWnd( myWndId );
2800 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2808 bool SalomePyQt::closeView( const int id )
2810 return ProcessEvent( new TCloseView( id ) );
2814 \fn int SalomePyQt::cloneView( const int id );
2815 \brief Clone view (if this operation is supported for specified view type)
2816 \param id window identifier
2817 \return integer identifier of the cloned view or -1 or operation could not be performed
2820 class TCloneView: public SALOME_Event
2823 typedef int TResult;
2826 TCloneView( const int id )
2829 virtual void Execute()
2831 SUIT_ViewWindow* wnd = getWnd( myWndId );
2833 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2835 #ifndef DISABLE_OCCVIEWER
2836 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
2837 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2838 occView->onCloneView();
2839 wnd = viewMgr->getActiveView();
2841 myResult = wnd->getId();
2843 #endif // DISABLE_OCCVIEWER
2844 #ifndef DISABLE_PLOT2DVIEWER
2845 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
2846 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2847 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2848 if ( viewMgr2d && srcWnd2d ) {
2849 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2850 myResult = resWnd->getId();
2853 #endif // DISABLE_OCCVIEWER
2858 int SalomePyQt::cloneView( const int id )
2860 return ProcessEvent( new TCloneView( id ) );
2864 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2865 \brief Set view visibility.
2866 \param id window identifier
2867 \param visible new visiblity
2870 void SalomePyQt::setViewVisible( const int id, const bool visible )
2872 class TEvent: public SALOME_Event
2877 TEvent( const int id, const bool visible )
2878 : myWndId( id ), myVisible( visible ) {}
2879 virtual void Execute()
2881 SUIT_ViewWindow* wnd = getWnd( myWndId );
2882 if ( wnd ) wnd->setVisible( myVisible );
2885 ProcessVoidEvent( new TEvent( id, visible ) );
2889 \fn bool SalomePyQt::isViewVisible( const int id );
2890 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2891 \param id window identifier
2892 \return \c true if view is visible and \c false otherwise
2895 class TIsViewVisible: public SALOME_Event
2898 typedef bool TResult;
2901 TIsViewVisible( const int id )
2902 : myResult( false ),
2904 virtual void Execute()
2906 SUIT_ViewWindow* wnd = getWnd( myWndId );
2909 QWidget* p = wnd->parentWidget();
2910 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2914 bool SalomePyQt::isViewVisible( const int id )
2916 return ProcessEvent( new TIsViewVisible( id ) );
2920 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2921 \brief Set / clear view's "closable" option. By default any view is closable
2922 (i.e. can be closed by the user).
2923 \param id window identifier
2924 \param on new "closable" option's value
2927 void SalomePyQt::setViewClosable( const int id, const bool on )
2929 class TEvent: public SALOME_Event
2934 TEvent( const int id, const bool on )
2935 : myWndId( id ), myOn( on ) {}
2936 virtual void Execute()
2938 SUIT_ViewWindow* wnd = getWnd( myWndId );
2939 if ( wnd ) wnd->setClosable( myOn );
2942 ProcessVoidEvent( new TEvent( id, on ) );
2946 \fn bool SalomePyQt::isViewClosable( const int id );
2947 \brief Check whether view is closable (i.e. can be closed by the user)
2948 \param id window identifier
2949 \return \c true if view is closable or \c false otherwise
2952 class TIsViewClosable: public SALOME_Event
2955 typedef bool TResult;
2958 TIsViewClosable( const int id )
2961 virtual void Execute()
2963 SUIT_ViewWindow* wnd = getWnd( myWndId );
2965 myResult = wnd->closable();
2969 bool SalomePyQt::isViewClosable( const int id )
2971 return ProcessEvent( new TIsViewClosable( id ) );
2975 \fn bool SalomePyQt::groupAllViews();
2976 \brief Group all views to the single tab area
2977 \return \c true if operation is completed successfully and \c false otherwise
2980 class TGroupAllViews: public SALOME_Event
2983 typedef bool TResult;
2986 : myResult( false ) {}
2987 virtual void Execute()
2989 LightApp_Application* app = getApplication();
2991 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2993 QtxWorkstack* wStack = tabDesk->workstack();
3002 bool SalomePyQt::groupAllViews()
3004 return ProcessEvent( new TGroupAllViews() );
3008 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3009 \brief Split tab area to which view with identifier belongs to
3010 \param id window identifier
3011 \param ori orientation of split operation
3012 \param action action to be performed
3013 \return \c true if operation is completed successfully \c false otherwise
3016 class TSplitView: public SALOME_Event
3019 typedef bool TResult;
3024 TSplitView( const int id,
3025 const Orientation ori,
3026 const Action action )
3027 : myResult( false ),
3030 myAction( action ) {}
3031 virtual void Execute()
3033 SUIT_ViewWindow* wnd = getWnd( myWndId );
3036 // wnd->setFocus(); ???
3039 if ( getApplication() ) {
3040 STD_TabDesktop* desk =
3041 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3043 QtxWorkstack* wStack = desk->workstack();
3045 Qt::Orientation qtOri =
3046 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3048 QtxWorkstack::SplitType sType;
3049 if ( myAction == MoveWidget )
3050 sType = QtxWorkstack::SplitMove;
3051 else if ( myAction == LeaveWidget )
3052 sType = QtxWorkstack::SplitStay;
3054 sType = QtxWorkstack::SplitAt;
3056 wStack->Split( wnd, qtOri, sType );
3064 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3066 return ProcessEvent( new TSplitView( id, ori, action ) );
3070 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3071 \brief Move view with the first identifier to the same area which
3072 another view with the second identifier belongs to
3073 \param id source window identifier
3074 \param id_to destination window identifier
3075 param before specifies whether the first viewt has to be moved before or after
3077 \return \c true if operation is completed successfully and \c false otherwise
3080 class TMoveView: public SALOME_Event
3083 typedef bool TResult;
3088 TMoveView( const int id, const int id_to, const bool before )
3089 : myResult( false ),
3092 myIsBefore( before ) {}
3093 virtual void Execute()
3095 SUIT_ViewWindow* wnd = getWnd( myWndId );
3096 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3097 if ( wnd && wnd_to ) {
3098 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3099 getApplication()->desktop() )->workstack();
3101 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3105 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3107 return ProcessEvent( new TMoveView( id, id_to, before ) );
3111 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3112 \brief Get list of views identifiers that belongs to the same area as
3113 specified view (excluding it)
3114 \param id window identifier
3115 \return list of views identifiers
3118 class TNeighbourViews: public SALOME_Event
3121 typedef QList<int> TResult;
3124 TNeighbourViews( const int id )
3126 virtual void Execute()
3129 SUIT_ViewWindow* wnd = getWnd( myWndId );
3131 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3132 getApplication()->desktop() )->workstack();
3134 QWidgetList wgList = wStack->windowList( wnd );
3136 foreach ( wg, wgList ) {
3137 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3138 if ( tmpWnd && tmpWnd != wnd )
3139 myResult.append( tmpWnd->getId() );
3145 QList<int> SalomePyQt::neighbourViews( const int id )
3147 return ProcessEvent( new TNeighbourViews( id ) );
3152 \fn QString SalomePyQt::createObject( const QString& parent );
3153 \brief Create empty data object
3154 \param parent entry of parent data object
3155 \return entry of created data object
3158 class TCreateEmptyObjectEvent: public SALOME_Event
3161 typedef QString TResult;
3164 TCreateEmptyObjectEvent( const QString& parent )
3165 : myParent( parent ) {}
3166 virtual void Execute()
3168 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3170 myResult = module->createObject( myParent );
3173 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3177 QString SalomePyQt::createObject( const QString& parent )
3179 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3183 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3184 const QString& tooltip,const QString& parent );
3185 \brief Create new data object with specified name, icon and tooltip
3186 \param name data object name
3187 \param icon data object icon
3188 \param toolTip data object tooltip
3189 \param parent entry of parent data object
3190 \return entry of created data object
3193 class TCreateObjectEvent: public SALOME_Event
3196 typedef QString TResult;
3202 TCreateObjectEvent( const QString& name,
3203 const QString& icon,
3204 const QString& tooltip,
3205 const QString& parent )
3208 myToolTip( tooltip ),
3209 myParent( parent ) {}
3210 virtual void Execute()
3212 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3214 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3217 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3221 QString SalomePyQt::createObject( const QString& name,
3222 const QString& icon,
3223 const QString& toolTip,
3224 const QString& parent )
3226 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3231 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3232 \brief Set data object name
3233 \param entry data object entry
3234 \param name data object name
3236 class TSetNameEvent: public SALOME_Event
3241 TSetNameEvent( const QString& entry,
3242 const QString& name )
3245 virtual void Execute()
3247 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3249 module->setName( myEntry, myName );
3252 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3256 void SalomePyQt::setName( const QString& entry, const QString& name )
3258 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3262 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3263 \brief Set data object icon
3264 \param entry data object entry
3265 \param icon data object icon file name (icon is loaded from module resources)
3268 class TSetIconEvent: public SALOME_Event
3273 TSetIconEvent( const QString& entry,
3274 const QString& icon )
3277 virtual void Execute()
3279 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3281 module->setIcon( myEntry, myIcon );
3284 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3289 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3291 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3295 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3296 \brief Set data object tooltip
3297 \param entry data object entry
3298 \param toolTip data object tooltip
3301 class TSetToolTipEvent: public SALOME_Event
3306 TSetToolTipEvent( const QString& entry,
3307 const QString& toolTip )
3309 myToolTip( toolTip ) {}
3310 virtual void Execute()
3312 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3314 module->setToolTip( myEntry, myToolTip );
3317 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3321 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3323 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3327 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3328 \brief Set reference to another data object
3329 \param entry data object entry
3330 \param refEntry referenced data object entry
3333 class TSetRefEvent: public SALOME_Event
3338 TSetRefEvent( const QString& entry,
3339 const QString& refEntry )
3341 myRefEntry( refEntry ) {}
3342 virtual void Execute()
3344 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3346 module->setReference( myEntry, myRefEntry );
3349 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3353 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3355 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3359 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3360 \brief Set data object color
3361 \param entry data object entry
3362 \param color data object color
3365 class TSetColorEvent: public SALOME_Event
3370 TSetColorEvent( const QString& entry,
3371 const QColor& color )
3374 virtual void Execute()
3376 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3378 module->setColor( myEntry, myColor );
3381 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3385 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3387 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3391 \fn QString SalomePyQt::getName( const QString& entry );
3392 \brief Get data object name
3393 \param entry data object entry
3394 \return data object name
3397 class TGetNameEvent: public SALOME_Event
3400 typedef QString TResult;
3403 TGetNameEvent( const QString& entry )
3404 : myEntry( entry ) {}
3405 virtual void Execute()
3407 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3409 myResult = module->getName( myEntry );
3412 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3416 QString SalomePyQt::getName( const QString& entry )
3418 return ProcessEvent( new TGetNameEvent( entry ) );
3422 \fn QString SalomePyQt::getToolTip( const QString& entry );
3423 \brief Get data object tooltip
3424 \param entry data object entry
3425 \return data object tooltip
3428 class TGetToolTipEvent: public SALOME_Event
3431 typedef QString TResult;
3434 TGetToolTipEvent( const QString& entry )
3435 : myEntry( entry ) {}
3436 virtual void Execute()
3438 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3440 myResult = module->getToolTip( myEntry );
3443 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3447 QString SalomePyQt::getToolTip( const QString& entry )
3449 return ProcessEvent( new TGetToolTipEvent( entry ) );
3453 \fn QString SalomePyQt::getReference( const QString& entry );
3454 \brief Get entry of the referenced object (if there's any)
3455 \param entry data object entry
3456 \return referenced data object entry
3459 class TGetRefEvent: public SALOME_Event
3462 typedef QString TResult;
3465 TGetRefEvent( const QString& entry )
3466 : myEntry( entry ) {}
3467 virtual void Execute()
3469 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3471 myResult = module->getReference( myEntry );
3474 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3478 QString SalomePyQt::getReference( const QString& entry )
3480 return ProcessEvent( new TGetRefEvent( entry ) );
3484 \fn QColor SalomePyQt::getColor( const QString& entry );
3485 \brief Get data object color
3486 \param entry data object entry
3487 \return data object color
3490 class TGetColorEvent: public SALOME_Event
3493 typedef QColor TResult;
3496 TGetColorEvent( const QString& entry )
3497 : myEntry( entry ) {}
3498 virtual void Execute()
3500 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3502 myResult = module->getColor( myEntry );
3505 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3509 QColor SalomePyQt::getColor( const QString& entry )
3511 return ProcessEvent( new TGetColorEvent( entry ) );
3515 \fn void SalomePyQt::removeChildren( const QString& entry );
3516 \brief Remove all child data objects from specified data object
3517 \param entry data object entry
3520 class TRemoveChildEvent: public SALOME_Event
3524 TRemoveChildEvent( const QString& entry )
3525 : myEntry( entry ) {}
3526 virtual void Execute()
3528 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3530 module->removeChildren( myEntry );
3533 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3537 void SalomePyQt::removeChildren( const QString& entry )
3539 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3541 void SalomePyQt::removeChild( const QString& entry )
3543 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3544 removeChildren( entry );
3548 \fn void SalomePyQt::removeObject( const QString& entry );
3549 \brief Remove object by entry
3550 \param entry data object entry
3553 class TRemoveObjectEvent: public SALOME_Event
3558 TRemoveObjectEvent( const QString& entry )
3559 : myEntry( entry ) {}
3560 virtual void Execute()
3562 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3564 module->removeObject( myEntry );
3567 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3571 void SalomePyQt::removeObject( const QString& entry )
3573 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3577 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3578 \brief Get entries of all child data objects of specified data object
3579 \param entry data object entry
3580 \param recursive \c true for recursive processing
3583 class TGetChildrenEvent: public SALOME_Event
3586 typedef QStringList TResult;
3590 TGetChildrenEvent( const QString& entry, const bool recursive )
3592 myRecursive( recursive ) {}
3593 virtual void Execute()
3595 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3597 myResult = module->getChildren( myEntry, myRecursive );
3600 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3604 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3606 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3609 #ifndef DISABLE_PLOT2DVIEWER
3610 // Next set of methods relates to the Plot2d viewer functionality
3613 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3614 \brief Display theCurve in view
3615 \param id window identifier
3616 \param theCurve curve to display
3619 class TDisplayCurve: public SALOME_Event
3623 Plot2d_Curve* myCurve;
3624 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3625 virtual void Execute() {
3626 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3628 wnd->getViewFrame()->displayCurve( myCurve );
3631 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3633 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
3637 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3638 \brief Erase theCurve in view
3639 \param id window identifier
3640 \param theCurve curve to erase
3643 class TEraseCurve: public SALOME_Event
3647 Plot2d_Curve* myCurve;
3648 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3649 virtual void Execute() {
3650 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3651 wnd->getViewFrame()->eraseCurve( myCurve );
3654 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3656 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
3660 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3661 \brief Delete theCurve from all views
3662 \param theCurve curve to delete
3665 class TDeleteCurve: public SALOME_Event
3668 Plot2d_Curve* myCurve;
3669 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3670 virtual void Execute() {
3671 LightApp_Application* app = getApplication();
3673 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3675 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3676 SUIT_ViewWindow* wnd;
3677 foreach ( wnd, wndlist ) {
3678 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3680 aP2d->getViewFrame()->eraseObject( myCurve );
3686 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3688 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3692 \brief updateCurves (repaint) curves in view window.
3694 void SalomePyQt::updateCurves( const int id )
3696 class TEvent: public SALOME_Event
3700 TEvent( const int id ) : myWndId( id ) {}
3701 virtual void Execute()
3703 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3705 wnd->getViewFrame()->DisplayAll();
3708 ProcessVoidEvent( new TEvent( id ) );
3712 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3713 \brief Get title of corresponding type
3714 \param id window identifier
3715 \param type is type of title
3716 \return title of corresponding type
3719 class TGetPlot2dTitle: public SALOME_Event
3722 typedef QString TResult;
3726 TGetPlot2dTitle(const int id, ObjectType type) :
3729 virtual void Execute() {
3730 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3732 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
3735 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
3737 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
3742 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3743 \brief Set title of corresponding type
3744 \param id window identifier
3746 \param type is type of title
3750 class TSetPlot2dTitle: public SALOME_Event
3754 Plot2d_Curve* myCurve;
3758 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
3763 virtual void Execute() {
3764 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3765 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
3768 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
3770 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
3774 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3775 \brief Get list of Plot2d view ranges
3776 \param id window identifier
3777 \return list of view ranges (XMin, XMax, YMin, YMax)
3780 class TFitRangeByCurves: public SALOME_Event
3783 typedef QList<double> TResult;
3786 TFitRangeByCurves( const int id )
3788 virtual void Execute()
3791 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3793 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3794 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3795 myResult.append( XMin );
3796 myResult.append( XMax );
3797 myResult.append( YMin );
3798 myResult.append( YMax );
3802 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3804 return ProcessEvent( new TFitRangeByCurves( id ) );
3808 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3809 \brief Get list of current Plot2d view ranges
3810 \param id window identifier
3811 \return list of view ranges (XMin, XMax, YMin, YMax)
3814 class TFitRangeCurrent: public SALOME_Event
3817 typedef QList<double> TResult;
3820 TFitRangeCurrent( const int id )
3822 virtual void Execute()
3825 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3827 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3828 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3829 myResult.append( XMin );
3830 myResult.append( XMax );
3831 myResult.append( YMin );
3832 myResult.append( YMax );
3836 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3838 return ProcessEvent( new TFitRangeCurrent( id ) );
3842 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3843 \brief Set range of Plot2d view
3844 \param id window identifier
3851 class TPlot2dFitRange: public SALOME_Event
3859 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
3865 virtual void Execute() {
3866 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3868 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
3871 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3873 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
3876 // End of methods related to the Plot2d viewer functionality
3877 #endif // DISABLE_PLOT2DVIEWER
3880 \brief Process Qt event loop
3882 void SalomePyQt::processEvents()
3884 QCoreApplication::processEvents();
3888 \brief Set visibility state for given object
3889 \param theEntry study ID of the object
3890 \param theState visibility state
3892 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
3894 class TEvent: public SALOME_Event
3899 TEvent( const QString& theEntry, int theState ):
3900 myEntry( theEntry ), myState( theState ) {}
3901 virtual void Execute()
3903 LightApp_Study* aStudy = getActiveStudy();
3906 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
3909 ProcessVoidEvent( new TEvent( theEntry, theState ) );
3913 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3914 \brief Get visibility state for given object
3915 \param theEntry study ID of the object
3916 \return visibility state
3919 class TGetVisibilityStateEvent: public SALOME_Event
3922 typedef int TResult;
3925 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
3926 virtual void Execute()
3928 LightApp_Study* aStudy = getActiveStudy();
3930 myResult = aStudy->visibilityState( myEntry );
3933 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3935 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
3939 \brief Set position of given object in the tree
3940 \param theEntry study ID of the object
3941 \param thePos position
3943 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
3945 class TEvent: public SALOME_Event
3950 TEvent( const QString& theEntry, int thePos ):
3951 myEntry( theEntry ), myPos( thePos ) {}
3952 virtual void Execute()
3954 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3956 module->setObjectPosition( myEntry, myPos );
3959 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
3963 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
3964 \brief Get position of given object in the tree
3965 \param theEntry study ID of the object
3969 class TGetObjectPositionEvent: public SALOME_Event
3972 typedef int TResult;
3975 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
3976 virtual void Execute()
3978 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3980 myResult = module->getObjectPosition( myEntry );
3983 int SalomePyQt::getObjectPosition( const QString& theEntry )
3985 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
3989 \brief Start recordind a log of Python commands from embedded console
3990 \param theFileName output lof file name
3992 void SalomePyQt::startPyLog( const QString& theFileName )
3994 class TEvent: public SALOME_Event
3998 TEvent( const QString& theFileName ):
3999 myFileName( theFileName ) {}
4000 virtual void Execute()
4002 if ( getApplication() ) {
4003 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4004 if ( pyConsole ) pyConsole->startLog( myFileName );
4008 ProcessVoidEvent( new TEvent( theFileName ) );
4012 \brief Stop recordind a log of Python commands from embedded console
4014 void SalomePyQt::stopPyLog()
4016 class TEvent: public SALOME_Event
4020 virtual void Execute()
4022 if ( getApplication() ) {
4023 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4024 if ( pyConsole ) pyConsole->stopLog();
4028 ProcessVoidEvent( new TEvent() );