1 // Copyright (C) 2007-2016 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 ? module->findChild<PyModuleHelper*>( "python_module_helper" ) : 0;
128 \brief Get SALOME verbose level
130 \return \c true if SALOME debug output is allowed or \c false otherwise
134 bool isVerbose = false;
135 if ( getenv( "SALOME_VERBOSE" ) ) {
136 QString envVar = getenv( "SALOME_VERBOSE" );
138 int value = envVar.toInt( &ok );
139 isVerbose = ok && value != 0;
145 \brief Get menu item title
147 \param menuId menu identifier
148 \return menu title (localized)
150 QString getMenuName( const QString& menuId )
152 QStringList contexts;
153 contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
154 "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
155 QString menuName = menuId;
156 for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
157 menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
162 \brief Load module icon
164 \param module module name
165 \param fileName path to the icon file
168 QIcon loadIconInternal( const QString& module, const QString& fileName )
172 LightApp_Application* app = getApplication();
174 if ( app && !fileName.isEmpty() ) {
175 QPixmap pixmap = app->resourceMgr()->loadPixmap( module,
176 QApplication::translate( module.toLatin1().data(),
177 fileName.toLatin1().data() ) );
178 if ( !pixmap.isNull() )
179 icon = QIcon( pixmap );
185 \brief Gets window with specified identifier
187 \param id window identifier
188 \return pointer on the window
190 SUIT_ViewWindow* getWnd( const int id )
192 SUIT_ViewWindow* resWnd = 0;
194 LightApp_Application* app = getApplication();
196 ViewManagerList vmlist = app->viewManagers();
197 foreach( SUIT_ViewManager* vm, vmlist ) {
198 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
199 foreach ( SUIT_ViewWindow* vw, vwlist ) {
200 if ( id == vw->getId() ) {
211 \brief Map of created selection objects.
214 QMap<LightApp_Application*, SALOME_Selection*> SelMap;
217 \brief Default resource file section name.
220 const char* DEFAULT_SECTION = "SalomePyQt";
224 \class SALOME_Selection
225 \brief The class represents selection which can be used in Python.
229 \brief Get the selection object for the specified application.
231 Finds or creates the selection object (one per study).
233 \param app application object
234 \return selection object or 0 if \a app is invalid
236 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
238 SALOME_Selection* sel = 0;
239 if ( app && SelMap.find( app ) != SelMap.end() )
242 sel = SelMap[ app ] = new SALOME_Selection( app );
248 \param p parent object
250 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
252 LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
254 mySelMgr = app->selectionMgr();
255 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
256 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
263 SALOME_Selection::~SALOME_Selection()
265 LightApp_Application* app = 0;
266 QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
267 for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
268 if ( it.value() == this ) app = it.key();
270 if ( app ) SelMap.remove( app );
274 \brief Called when selection manager is destroyed (usually
275 when the study is closed).
277 void SALOME_Selection::onSelMgrDestroyed()
283 \brief Clear the selection.
285 void SALOME_Selection::Clear()
287 class TEvent: public SALOME_Event
289 LightApp_SelectionMgr* mySelMgr;
291 TEvent( LightApp_SelectionMgr* selMgr )
292 : mySelMgr( selMgr ) {}
293 virtual void Execute()
296 mySelMgr->clearSelected();
299 ProcessVoidEvent( new TEvent( mySelMgr ) );
303 \brief Clear the selection.
305 void SALOME_Selection::ClearIObjects()
311 Removes all selection filters.
313 void SALOME_Selection::ClearFilters()
315 class TEvent: public SALOME_Event
317 LightApp_SelectionMgr* mySelMgr;
319 TEvent( LightApp_SelectionMgr* selMgr )
320 : mySelMgr( selMgr ) {}
321 virtual void Execute()
324 mySelMgr->clearFilters();
327 ProcessVoidEvent( new TEvent( mySelMgr ) );
332 \brief The class provides utility functions which can be used in the Python
333 to operate with the SALOME GUI.
335 All the functionality of this class is implemented as static methods, so they
336 can be called with the class name prefixed or via creation of the class instance.
337 For example, next both ways of SalomePyQt class usage are legal:
339 from SalomePyQt import *
341 # using SalomePyQt class instance
342 desktop = sg.getDesktop()
343 # using SalomePyQt class directly
344 menubar = SalomePyQt.getMainMenuBar()
349 \fn QWidget* SalomePyQt::getDesktop();
350 \brief Get the active application's desktop window.
351 \return desktop window or 0 if there is no any
354 class TGetDesktopEvent: public SALOME_Event
357 typedef QWidget* TResult;
359 TGetDesktopEvent() : myResult( 0 ) {}
360 virtual void Execute()
362 if ( getApplication() )
363 myResult = (QWidget*)( getApplication()->desktop() );
366 QWidget* SalomePyQt::getDesktop()
368 return ProcessEvent( new TGetDesktopEvent() );
372 \fn QWidget* SalomePyQt::getMainFrame();
373 \brief Get current application's main frame widget [obsolete].
375 Main frame widget is an internal widget of the application
376 desktop window (workspace).
378 \return workspace widget (0 on any error)
381 class TGetMainFrameEvent: public SALOME_Event
384 typedef QWidget* TResult;
386 TGetMainFrameEvent() : myResult( 0 ) {}
387 virtual void Execute()
389 if ( getApplication() ) {
390 SUIT_Desktop* aDesktop = getApplication()->desktop();
391 myResult = (QWidget*)( aDesktop->centralWidget() );
395 QWidget* SalomePyQt::getMainFrame()
397 return ProcessEvent( new TGetMainFrameEvent() );
401 \fn QMenuBar* SalomePyQt::getMainMenuBar();
402 \brief Get current application desktop's main menu.
403 \return main menu object (0 on any error)
406 class TGetMainMenuBarEvent: public SALOME_Event
409 typedef QMenuBar* TResult;
411 TGetMainMenuBarEvent() : myResult( 0 ) {}
412 virtual void Execute()
414 if ( LightApp_Application* anApp = getApplication() ) {
415 myResult = anApp->desktop()->menuBar();
419 QMenuBar* SalomePyQt::getMainMenuBar()
421 return ProcessEvent( new TGetMainMenuBarEvent() );
425 \fn QMenu* SalomePyQt::getPopupMenu( const MenuName menu );
426 \brief Get main menu's child popup submenu by its identifier.
428 This function is obsolete.
429 Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead.
431 \param menu menu identifier
432 \return popup submenu object or 0 if it does not exist
436 \fn QMenu* SalomePyQt::getPopupMenu( const QString& menu );
437 \brief Get main menu's child popup submenu by its name.
439 The function creates menu if it does not exist.
441 \param menu menu name
442 \return popup submenu object (0 on any error)
445 class TGetPopupMenuEvent: public SALOME_Event
448 typedef QMenu* TResult;
451 TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
452 virtual void Execute()
454 LightApp_Application* anApp = getApplication();
455 if ( anApp && !myMenuName.isEmpty() ) {
456 QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
457 myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
462 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
467 menuName = getMenuName( "MEN_DESK_FILE" ); break;
469 menuName = getMenuName( "MEN_DESK_VIEW" ); break;
471 menuName = getMenuName( "MEN_DESK_EDIT" ); break;
473 menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
475 menuName = getMenuName( "MEN_DESK_TOOLS" ); break;
477 menuName = getMenuName( "MEN_DESK_WINDOW" ); break;
479 menuName = getMenuName( "MEN_DESK_HELP" ); break;
481 return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
483 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
485 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
489 \fn QTreeView* SalomePyQt::getObjectBrowser();
490 \brief Get object browser
491 \return object browser for the active study or 0 in case of error
494 class TGetObjectBrowserEvent: public SALOME_Event
497 typedef QTreeView* TResult;
499 TGetObjectBrowserEvent() : myResult( 0 ) {}
500 virtual void Execute()
502 LightApp_Application* anApp = getApplication();
503 if ( anApp && anApp->objectBrowser() ) {
504 myResult = anApp->objectBrowser()->treeView();
508 QTreeView* SalomePyQt::getObjectBrowser()
510 return ProcessEvent( new TGetObjectBrowserEvent() );
514 \fn int SalomePyQt::getStudyId();
515 \brief Get active study's identifier.
516 \return active study ID or 0 if there is no active study
519 class TGetStudyIdEvent: public SALOME_Event
524 TGetStudyIdEvent() : myResult( 0 ) {}
525 virtual void Execute()
527 if ( LightApp_Study* aStudy = getActiveStudy() ) {
528 myResult = aStudy->id();
532 int SalomePyQt::getStudyId()
534 return ProcessEvent( new TGetStudyIdEvent() );
538 \fn SALOME_Selection* SalomePyQt::getSelection();
539 \brief Get the selection object for the current study.
541 Creates a Selection object if it has not been created yet.
543 \return selection object (0 on error)
546 class TGetSelectionEvent: public SALOME_Event
549 typedef SALOME_Selection* TResult;
551 TGetSelectionEvent() : myResult( 0 ) {}
552 virtual void Execute()
554 myResult = SALOME_Selection::GetSelection( getApplication() );
557 SALOME_Selection* SalomePyQt::getSelection()
559 return ProcessEvent( new TGetSelectionEvent() );
563 \fn void SalomePyQt::putInfo( const QString& msg, const int sec );
564 \brief Put an information message to the current application's
567 Optional second delay parameter (\a sec) can be used to specify
568 time of the message diplaying in seconds. If this parameter is less
569 or equal to zero, the constant message will be put.
571 \param msg message text
572 \param sec message displaying time in seconds
575 class TPutInfoEvent: public SALOME_Event
580 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
581 virtual void Execute()
583 if ( LightApp_Application* anApp = getApplication() ) {
584 anApp->putInfo( myMsg, mySecs * 1000 );
588 void SalomePyQt::putInfo( const QString& msg, const int sec )
590 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
594 \fn const QString SalomePyQt::getActiveComponent();
595 \brief Get the currently active module name (for the current study).
596 \return active module name or empty string if there is no active module
599 class TGetActiveComponentEvent: public SALOME_Event
602 typedef QString TResult;
604 TGetActiveComponentEvent() {}
605 virtual void Execute()
607 if ( LightApp_Application* anApp = getApplication() ) {
608 if ( CAM_Module* mod = anApp->activeModule() ) {
609 myResult = mod->name();
614 const QString SalomePyQt::getActiveComponent()
616 return ProcessEvent( new TGetActiveComponentEvent() );
620 \fn PyObject* SalomePyQt::getActivePythonModule();
621 \brief Access to Python module object currently loaded into SALOME_PYQT_ModuleLight container.
622 \return Python module object currently loaded into SALOME_PYQT_ModuleLight container
625 class TGetActivePyModuleEvent: public SALOME_Event
628 typedef PyObject* TResult;
630 TGetActivePyModuleEvent() : myResult( Py_None ) {}
631 virtual void Execute()
633 PyModuleHelper* helper = getPythonHelper();
635 myResult = (PyObject*)helper->pythonModule();
638 PyObject* SalomePyQt::getActivePythonModule()
640 return ProcessEvent( new TGetActivePyModuleEvent() );
644 \fn bool SalomePyQt::activateModule( const QString& modName );
645 \brief Activates SALOME module with the given name
646 \return True if the module has been activated and False otherwise.
649 class TActivateModuleEvent: public SALOME_Event
652 typedef bool TResult;
654 QString myModuleName;
655 TActivateModuleEvent( const QString& modName )
656 : myResult( false ), myModuleName( modName ) {}
657 virtual void Execute()
659 if ( LightApp_Application* anApp = getApplication() ) {
660 myResult = anApp->activateModule( myModuleName );
664 bool SalomePyQt::activateModule( const QString& modName )
666 return ProcessEvent( new TActivateModuleEvent( modName ) );
670 \brief Update an Object Browser of the specified (by identifier) study.
672 If \a studyId <= 0 the active study's object browser is updated.
673 The \a updateSelection parameter is obsolete and currently is not used.
674 This parameter will be removed in future, so try to avoid its usage in
677 \brief studyId study identifier
678 \brief updateSelection update selection flag (not used)
681 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
683 class TEvent: public SALOME_Event
686 bool myUpdateSelection;
688 TEvent( const int studyId, bool updateSelection )
689 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
690 virtual void Execute()
692 if ( SUIT_Session::session() ) {
693 if ( getActiveStudy() && myStudyId <= 0 )
694 myStudyId = getActiveStudy()->id();
695 if ( myStudyId > 0 ) {
696 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
697 QList<SUIT_Application*>::Iterator it;
698 for( it = apps.begin(); it != apps.end(); ++it ) {
699 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
700 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
701 anApp->updateObjectBrowser();
709 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
714 SalomePyQt::isModified()
715 \return The modification status of the data model
716 for the currently active Python module
717 \note This function is supported for "light" Python-based SALOME modules only.
720 class TIsModifiedEvent: public SALOME_Event
723 typedef bool TResult;
725 TIsModifiedEvent() : myResult( false ) {}
726 virtual void Execute()
728 LightApp_Module* module = getActiveModule();
732 SALOME_PYQT_DataModelLight* aModel =
733 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
735 myResult = aModel->isModified();
738 if ( verbose() ) printf( "SalomePyQt.isModified() function is not supported for the current module.\n" );
742 bool SalomePyQt::isModified()
744 return ProcessEvent(new TIsModifiedEvent());
748 SalomePyQt::setModified()
750 Sets the modification status of the data model for
751 the currently active Python module. This method should be used
752 by the Python code in order to enable/disable "Save" operation
753 depending on the module's data state.
755 \note This function is supported for "light" Python-based SALOME modules only.
757 \param New modification status of the data model
761 void SalomePyQt::setModified( bool flag )
763 class TEvent: public SALOME_Event
769 virtual void Execute()
771 LightApp_Module* module = getActiveModule();
775 SALOME_PYQT_DataModelLight* model =
776 dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
778 LightApp_Application* app = module->getApp();
780 if ( model && app ) {
781 model->setModified( myFlag );
782 app->updateActions();
785 if ( verbose() ) printf( "SalomePyQt.setModified() function is not supported for the current module.\n" );
789 ProcessVoidEvent( new TEvent( flag ) );
793 \brief Add string setting to the application preferences.
795 The parameter \a autoValue is obsolete parameter and currently is not used.
796 This parameter will be removed in future, so try to avoid its usage in
799 This function is obsolete. Use one of addSetting() instead.
801 \param name setting name (it should be of kind <section:setting> where
802 \c section is resources section name and \c setting is setting name)
803 \param value new setting value
804 \param autoValue (not used)
806 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
808 class TEvent: public SALOME_Event
814 TEvent( const QString& name, const QString& value, bool autoValue )
815 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
816 virtual void Execute()
818 if ( SUIT_Session::session() ) {
819 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
820 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
821 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
822 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
823 if ( !_sec.isEmpty() && !_nam.isEmpty() )
824 resMgr->setValue( _sec, _nam, myValue );
828 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
832 \brief Add integer setting to the application preferences.
834 The parameter \a autoValue is obsolete parameter and currently is not used.
835 This parameter will be removed in future, so try to avoid its usage in
838 This function is obsolete. Use one of addSetting() instead.
840 \param name setting name (it should be of kind <section:setting> where
841 \c section is resources section name and \c setting is setting name)
842 \param value new setting value
843 \param autoValue (not used)
845 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
847 class TEvent: public SALOME_Event
853 TEvent( const QString& name, const int value, bool autoValue )
854 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
855 virtual void Execute()
857 if ( SUIT_Session::session() ) {
858 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
859 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
860 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
861 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
862 if ( !_sec.isEmpty() && !_nam.isEmpty() )
863 resMgr->setValue( _sec, _nam, myValue );
867 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
871 \brief Add double setting to the application preferences.
873 The parameter \a autoValue is obsolete parameter and currently is not used.
874 This parameter will be removed in future, so try to avoid its usage in
877 This function is obsolete. Use one of addSetting() instead.
879 \param name setting name (it should be of kind <section:setting> where
880 \c section is resources section name and \c setting is setting name)
881 \param value new setting value
882 \param autoValue (not used)
884 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
886 class TEvent: public SALOME_Event
892 TEvent( const QString& name, const double value, bool autoValue )
893 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
894 virtual void Execute()
896 if ( SUIT_Session::session() ) {
897 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
898 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
899 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
900 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
901 if ( !_sec.isEmpty() && !_nam.isEmpty() )
902 resMgr->setValue( _sec, _nam, myValue );
906 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
910 \brief Add boolean setting to the application preferences.
912 The parameter \a autoValue is obsolete parameter and currently is not used.
913 This parameter will be removed in future, so try to avoid its usage in
916 This function is obsolete. Use one of addSetting() instead.
918 \param name setting name (it should be of kind <section:setting> where
919 \c section is resources section name and \c setting is setting name)
920 \param value new setting value
921 \param autoValue (not used)
923 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
925 class TEvent: public SALOME_Event
931 TEvent( const QString& name, const bool value, bool autoValue )
932 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
933 virtual void Execute()
935 if ( SUIT_Session::session() ) {
936 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
937 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
938 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
939 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
940 if ( !_sec.isEmpty() && !_nam.isEmpty() )
941 resMgr->setValue( _sec, _nam, myValue );
945 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
949 \brief Remove setting from the application preferences.
951 This function is obsolete. Use removeSetting() instead.
953 \param name setting name (it should be of kind <section:setting> where
954 \c section is resources section name and \c setting is setting name)
956 void SalomePyQt::removeSettings( const QString& name )
958 class TEvent: public SALOME_Event
962 TEvent( const QString& name ) : myName( name ) {}
963 virtual void Execute()
965 if ( SUIT_Session::session() ) {
966 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
967 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
968 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
969 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
970 if ( !_sec.isEmpty() && !_nam.isEmpty() )
971 resMgr->remove( _sec, _nam );
975 ProcessVoidEvent( new TEvent( name ) );
979 \fn QString SalomePyQt::getSetting( const QString& name );
980 \brief Get application setting value (as string represenation).
982 This function is obsolete. Use stringSetting(), integerSetting(),
983 boolSetting(), stringSetting() or colorSetting() instead.
985 \param name setting name (it should be of kind <section:setting> where
986 \c section is resources section name and \c setting is setting name)
987 \return setting name (empty string if setting name is invalid)
990 class TGetSettingEvent: public SALOME_Event
993 typedef QString TResult;
996 TGetSettingEvent( const QString& name ) : myName( name ) {}
997 virtual void Execute()
999 if ( SUIT_Session::session() ) {
1000 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1001 QStringList sl = myName.split( ":", QString::SkipEmptyParts );
1002 QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
1003 QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
1004 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
1008 QString SalomePyQt::getSetting( const QString& name )
1010 return ProcessEvent( new TGetSettingEvent( name ) );
1014 \brief Add double setting to the application preferences.
1015 \param section resources file section name
1016 \param name setting name
1017 \param value new setting value
1019 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
1021 class TEvent: public SALOME_Event
1027 TEvent( const QString& section, const QString& name, double value )
1028 : mySection( section ), myName( name ), myValue( value ) {}
1029 virtual void Execute()
1031 if ( SUIT_Session::session() ) {
1032 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1033 if ( !mySection.isEmpty() && !myName.isEmpty() )
1034 resMgr->setValue( mySection, myName, myValue );
1038 ProcessVoidEvent( new TEvent( section, name, value ) );
1042 \brief Add integer setting to the application preferences.
1043 \param section resources file section name
1044 \param name setting name
1045 \param value new setting value
1047 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
1049 class TEvent: public SALOME_Event
1055 TEvent( const QString& section, const QString& name, int value )
1056 : mySection( section ), myName( name ), myValue( value ) {}
1057 virtual void Execute()
1059 if ( SUIT_Session::session() ) {
1060 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1061 if ( !mySection.isEmpty() && !myName.isEmpty() )
1062 resMgr->setValue( mySection, myName, myValue );
1066 ProcessVoidEvent( new TEvent( section, name, value ) );
1070 \brief Add boolean setting to the application preferences.
1071 \param section resources file section name
1072 \param name setting name
1073 \param value new setting value
1074 \param dumb this parameter is used in order to avoid sip compilation error
1075 because of conflicting int and bool types
1077 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
1079 class TEvent: public SALOME_Event
1085 TEvent( const QString& section, const QString& name, bool value )
1086 : mySection( section ), myName( name ), myValue( value ) {}
1087 virtual void Execute()
1089 if ( SUIT_Session::session() ) {
1090 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1091 if ( !mySection.isEmpty() && !myName.isEmpty() )
1092 resMgr->setValue( mySection, myName, myValue );
1096 ProcessVoidEvent( new TEvent( section, name, value ) );
1100 \brief Add string setting to the application preferences.
1101 \param section resources file section name
1102 \param name setting name
1103 \param value new setting value
1105 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
1107 class TEvent: public SALOME_Event
1113 TEvent( const QString& section, const QString& name, const QString& value )
1114 : mySection( section ), myName( name ), myValue( value ) {}
1115 virtual void Execute()
1117 if ( SUIT_Session::session() ) {
1118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1119 if ( !mySection.isEmpty() && !myName.isEmpty() )
1120 resMgr->setValue( mySection, myName, myValue );
1124 ProcessVoidEvent( new TEvent( section, name, value ) );
1128 \brief Add color setting to the application preferences.
1129 \param section resources file section name
1130 \param name setting name
1131 \param value new setting value
1133 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
1135 class TEvent: public SALOME_Event
1141 TEvent( const QString& section, const QString& name, const QColor& value )
1142 : mySection( section ), myName( name ), myValue( value ) {}
1143 virtual void Execute()
1145 if ( SUIT_Session::session() ) {
1146 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1147 if ( !mySection.isEmpty() && !myName.isEmpty() )
1148 resMgr->setValue( mySection, myName, myValue );
1152 ProcessVoidEvent( new TEvent( section, name, value ) );
1156 \brief Add byte array setting to the application preferences.
1157 \param section resources file section name
1158 \param name setting name
1159 \param value new setting value
1161 void SalomePyQt::addSetting( const QString& section, const QString& name, const QByteArray& value )
1163 class TEvent: public SALOME_Event
1169 TEvent( const QString& section, const QString& name, const QByteArray& value )
1170 : mySection( section ), myName( name ), myValue( value ) {}
1171 virtual void Execute()
1173 if ( SUIT_Session::session() ) {
1174 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1175 if ( !mySection.isEmpty() && !myName.isEmpty() )
1176 resMgr->setValue( mySection, myName, myValue );
1180 ProcessVoidEvent( new TEvent( section, name, value ) );
1184 \fn int SalomePyQt::integerSetting( const QString& section,
1185 const QString& name,
1187 \brief Get integer setting from the application preferences.
1188 \param section resources file section name
1189 \param name setting name
1190 \param def default value which is returned if the setting is not found
1191 \return setting value
1194 class TGetIntSettingEvent: public SALOME_Event
1197 typedef int TResult;
1202 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
1203 : mySection( section ), myName( name ), myDefault( def ) {}
1204 virtual void Execute()
1206 if ( SUIT_Session::session() ) {
1207 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1208 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
1212 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
1214 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
1218 \fn double SalomePyQt::doubleSetting( const QString& section,
1219 const QString& name,
1221 \brief Get double setting from the application preferences.
1222 \param section resources file section name
1223 \param name setting name
1224 \param def default value which is returned if the setting is not found
1225 \return setting value
1228 class TGetDblSettingEvent: public SALOME_Event
1231 typedef double TResult;
1236 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
1237 : mySection( section ), myName( name ), myDefault( def ) {}
1238 virtual void Execute()
1240 if ( SUIT_Session::session() ) {
1241 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1242 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
1246 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
1248 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
1252 \fn bool SalomePyQt::boolSetting( const QString& section,
1253 const QString& name,
1255 \brief Get boolean setting from the application preferences.
1256 \param section resources file section name
1257 \param name setting name
1258 \param def default value which is returned if the setting is not found
1259 \return setting value
1262 class TGetBoolSettingEvent: public SALOME_Event
1265 typedef bool TResult;
1270 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
1271 : mySection( section ), myName( name ), myDefault( def ) {}
1272 virtual void Execute()
1274 if ( SUIT_Session::session() ) {
1275 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1276 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
1280 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
1282 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
1286 \fn QString SalomePyQt::stringSetting( const QString& section,
1287 const QString& name,
1288 const QString& def );
1289 \brief Get string setting from the application preferences.
1290 \param section resources file section name
1291 \param name setting name
1292 \param def default value which is returned if the setting is not found
1293 \return setting value
1296 class TGetStrSettingEvent: public SALOME_Event
1299 typedef QString TResult;
1304 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
1305 : mySection( section ), myName( name ), myDefault( def ) {}
1306 virtual void Execute()
1308 if ( SUIT_Session::session() ) {
1309 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1310 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
1314 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
1316 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
1320 \fn QColor SalomePyQt::colorSetting( const QString& section,
1321 const QString& name,
1323 \brief Get color setting from the application preferences.
1324 \param section resources file section name
1325 \param name setting name
1326 \param def default value which is returned if the setting is not found
1327 \return setting value
1330 class TGetColorSettingEvent: public SALOME_Event
1333 typedef QColor TResult;
1338 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
1339 : mySection( section ), myName( name ), myDefault( def ) {}
1340 virtual void Execute()
1342 if ( SUIT_Session::session() ) {
1343 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1344 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
1348 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
1350 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
1354 \fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
1355 const QString& name,
1356 const QByteArray def );
1357 \brief Get byte array setting from the application preferences.
1358 \param section resources file section name
1359 \param name setting name
1360 \param def default value which is returned if the setting is not found
1361 \return setting value
1364 class TGetByteArraySettingEvent: public SALOME_Event
1367 typedef QByteArray TResult;
1372 TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& def )
1373 : mySection( section ), myName( name ), myDefault( def ) {}
1374 virtual void Execute()
1376 if ( SUIT_Session::session() ) {
1377 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1378 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->byteArrayValue( mySection, myName, myDefault ) : myDefault;
1382 QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def )
1384 return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
1388 \brief Remove setting from the application preferences.
1389 \param section resources file section name
1390 \param name setting name
1392 void SalomePyQt::removeSetting( const QString& section, const QString& name )
1394 class TEvent: public SALOME_Event
1399 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
1400 virtual void Execute()
1402 if ( SUIT_Session::session() ) {
1403 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1404 if ( !mySection.isEmpty() && !myName.isEmpty() )
1405 resMgr->remove( mySection, myName );
1409 ProcessVoidEvent( new TEvent( section, name ) );
1413 \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name );
1414 \brief Check setting existence in the application preferences.
1415 \param section resources file section name
1416 \param name setting name
1417 \return \c true if setting exists
1420 class THasSettingEvent: public SALOME_Event
1423 typedef bool TResult;
1427 THasSettingEvent( const QString& section, const QString& name )
1428 : mySection( section ), myName( name ) {}
1429 virtual void Execute()
1431 if ( SUIT_Session::session() ) {
1432 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1433 myResult = resMgr->hasValue( mySection, myName );
1437 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
1439 return ProcessEvent( new THasSettingEvent( section, name ) );
1443 \fn QString SalomePyQt::getFileName( QWidget* parent,
1444 const QString& initial,
1445 const QStringList& filters,
1446 const QString& caption,
1448 \brief Show 'Open/Save file' dialog box for file selection
1449 and return a user's choice (selected file name).
1450 \param parent parent widget
1451 \param initial initial directory the dialog box to be opened in
1452 \param filters list of files filters (wildcards)
1453 \param caption dialog box title
1454 \param open if \c true, "Open File" dialog box is shown;
1455 otherwise "Save File" dialog box is shown
1456 \return selected file name (null string if user cancels operation)
1459 class TGetFileNameEvent: public SALOME_Event
1462 typedef QString TResult;
1466 QStringList myFilters;
1469 TGetFileNameEvent( QWidget* parent,
1470 const QString& initial,
1471 const QStringList& filters,
1472 const QString& caption,
1474 : myParent ( parent ),
1475 myInitial( initial ),
1476 myFilters( filters ),
1477 myCaption( caption ),
1479 virtual void Execute()
1481 if ( LightApp_Application* anApp = getApplication() ) {
1482 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"),
1483 myCaption, myParent );
1487 QString SalomePyQt::getFileName( QWidget* parent,
1488 const QString& initial,
1489 const QStringList& filters,
1490 const QString& caption,
1493 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
1497 \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1498 const QString& initial,
1499 const QStringList& filters,
1500 const QString& caption );
1501 \brief Show 'Open files' dialog box for multiple files selection
1502 and return a user's choice (selected file names list).
1503 \param parent parent widget
1504 \param initial initial directory the dialog box to be opened in
1505 \param filters list of files filters (wildcards)
1506 \param caption dialog box title
1507 \return selected file names list (empty list if user cancels operation)
1510 class TGetOpenFileNamesEvent: public SALOME_Event
1513 typedef QStringList TResult;
1517 QStringList myFilters;
1519 TGetOpenFileNamesEvent( QWidget* parent,
1520 const QString& initial,
1521 const QStringList& filters,
1522 const QString& caption )
1523 : myParent ( parent ),
1524 myInitial( initial ),
1525 myFilters( filters ),
1526 myCaption( caption ) {}
1527 virtual void Execute()
1529 if ( LightApp_Application* anApp = getApplication() ) {
1530 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
1534 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
1535 const QString& initial,
1536 const QStringList& filters,
1537 const QString& caption )
1539 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
1543 \fn QString SalomePyQt::getExistingDirectory( QWidget* parent,
1544 const QString& initial,
1545 const QString& caption );
1546 \brief Show 'Get Directory' dialog box for the directory selection
1547 and return a user's choice (selected directory name).
1548 \param parent parent widget
1549 \param initial initial directory the dialog box to be opened in
1550 \param caption dialog box title
1551 \return selected directory name (null string if user cancels operation)
1554 class TGetExistingDirectoryEvent: public SALOME_Event
1557 typedef QString TResult;
1562 TGetExistingDirectoryEvent( QWidget* parent,
1563 const QString& initial,
1564 const QString& caption )
1565 : myParent ( parent ),
1566 myInitial( initial ),
1567 myCaption( caption ) {}
1568 virtual void Execute()
1570 if ( LightApp_Application* anApp = getApplication() ) {
1571 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1575 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1576 const QString& initial,
1577 const QString& caption )
1579 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1583 \fn QString SalomePyQt::loadIcon( const QString& filename );
1584 \brief Load an icon from the module resources by the specified file name.
1585 \param fileName icon file name
1589 class TLoadIconEvent: public SALOME_Event
1592 typedef QIcon TResult;
1596 TLoadIconEvent( const QString& module, const QString& filename )
1597 : myModule( module ),
1598 myFileName ( filename ) {}
1599 virtual void Execute()
1601 myResult = loadIconInternal( myModule, myFileName );
1604 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
1606 return ProcessEvent( new TLoadIconEvent( module, filename ) );
1610 \brief Open external browser to display context help information.
1613 Current implementation does nothing.
1615 \param source documentation (HTML) file name
1616 \param context context (for example, HTML ancor name)
1618 void SalomePyQt::helpContext( const QString& source, const QString& context )
1620 class TEvent: public SALOME_Event
1625 TEvent( const QString& source, const QString& context )
1626 : mySource( source ), myContext( context ) {}
1627 virtual void Execute()
1629 if ( LightApp_Application* anApp = getApplication() ) {
1630 anApp->onHelpContextModule( "", mySource, myContext );
1634 ProcessVoidEvent( new TEvent( source, context ) );
1638 \fn int SalomePyQt::defaultMenuGroup();
1639 \brief Get detault menu group identifier which can be used when
1640 creating menus (insert custom menu commands).
1641 \return default menu group ID
1644 class TDefMenuGroupEvent: public SALOME_Event
1647 typedef int TResult;
1649 TDefMenuGroupEvent() : myResult( -1 ) {}
1650 virtual void Execute()
1652 myResult = PyModuleHelper::defaultMenuGroup();
1655 int SalomePyQt::defaultMenuGroup()
1657 return ProcessEvent( new TDefMenuGroupEvent() );
1663 CrTool( const QString& tBar, const QString& nBar )
1664 : myCase( 0 ), myTbTitle( tBar ), myTbName( nBar) {}
1665 CrTool( const int id, const int tBar, const int idx )
1666 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1667 CrTool( const int id, const QString& tBar, const int idx )
1668 : myCase( 2 ), myId( id ), myTbTitle( tBar ), myIndex( idx ) {}
1669 CrTool( QAction* action, const int tbId, const int id, const int idx )
1670 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1671 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
1672 : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
1674 int execute( LightApp_Module* module ) const
1679 return module->createTool( myTbTitle, myTbName );
1681 return module->createTool( myId, myTbId, myIndex );
1683 return module->createTool( myId, myTbTitle, myIndex );
1685 return module->createTool( myAction, myTbId, myId, myIndex );
1687 return module->createTool( myAction, myTbTitle, myId, myIndex );
1702 class TCreateToolEvent: public SALOME_Event
1705 typedef int TResult;
1707 const CrTool& myCrTool;
1708 TCreateToolEvent( const CrTool& crTool )
1709 : myResult( -1 ), myCrTool( crTool ) {}
1710 virtual void Execute()
1712 LightApp_Module* module = getActiveModule();
1714 myResult = myCrTool.execute( module );
1719 \brief Create toolbar with specified name.
1720 \param tBar toolbar title (language-dependent)
1721 \param nBar toolbar name (language-independent) [optional]
1722 \return toolbar ID or -1 if toolbar creation is failed
1724 int SalomePyQt::createTool( const QString& tBar, const QString& nBar )
1726 return ProcessEvent( new TCreateToolEvent( CrTool( tBar, nBar ) ) );
1730 \brief Insert action with specified \a id to the toolbar.
1732 \param tBar toolbar ID
1733 \param idx required index in the toolbar
1734 \return action ID or -1 if action could not be added
1736 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1738 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1742 \brief Insert action with specified \a id to the toolbar.
1744 \param tBar toolbar name
1745 \param idx required index in the toolbar
1746 \return action ID or -1 if action could not be added
1748 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1750 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1754 \brief Insert action to the toolbar.
1756 \param tBar toolbar ID
1757 \param id required action ID
1758 \param idx required index in the toolbar
1759 \return action ID or -1 if action could not be added
1761 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
1763 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1767 \brief Insert action to the toolbar.
1769 \param tBar toolbar name
1770 \param id required action ID
1771 \param idx required index in the toolbar
1772 \return action ID or -1 if action could not be added
1774 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
1776 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1782 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1783 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1784 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1785 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1786 CrMenu( const int id, const int menu, const int group, const int idx )
1787 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1788 CrMenu( const int id, const QString& menu, const int group, const int idx )
1789 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1790 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1791 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1792 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1793 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1795 int execute( LightApp_Module* module ) const
1800 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1802 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1804 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1806 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1808 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1810 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1819 QString mySubMenuName;
1826 class TCreateMenuEvent: public SALOME_Event
1829 typedef int TResult;
1831 const CrMenu& myCrMenu;
1832 TCreateMenuEvent( const CrMenu& crMenu )
1833 : myResult( -1 ), myCrMenu( crMenu ) {}
1834 virtual void Execute()
1836 LightApp_Module* module = getActiveModule();
1838 myResult = myCrMenu.execute( module );
1843 \brief Create main menu.
1844 \param subMenu menu name
1845 \param menu parent menu ID
1846 \param id required menu ID
1847 \param group menu group ID
1848 \param idx required index in the menu
1849 \return menu ID or -1 if menu could not be added
1851 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1853 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1857 \brief Create main menu.
1858 \param subMenu menu name
1859 \param menu parent menu name (list of menu names separated by "|")
1860 \param id required menu ID
1861 \param group menu group ID
1862 \param idx required index in the menu
1863 \return menu ID or -1 if menu could not be added
1865 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1867 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1871 \brief Insert action to the main menu.
1873 \param menu parent menu ID
1874 \param group menu group ID
1875 \param idx required index in the menu
1876 \return action ID or -1 if action could not be added
1878 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1880 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1884 \brief Insert action to the main menu.
1886 \param menu parent menu name (list of menu names separated by "|")
1887 \param group menu group ID
1888 \param idx required index in the menu
1889 \return action ID or -1 if action could not be added
1891 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1893 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1897 \brief Insert action to the main menu.
1899 \param menu parent menu ID
1900 \param group menu group ID
1901 \param idx required index in the menu
1902 \return action ID or -1 if action could not be added
1904 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1906 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1910 \brief Insert action to the main menu.
1912 \param menu parent menu name (list of menu names separated by "|")
1913 \param group menu group ID
1914 \param idx required index in the menu
1915 \return action ID or -1 if action could not be added
1917 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1919 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1923 \fn QAction* SalomePyQt::createSeparator();
1924 \brief Create separator action which can be used in the menu or toolbar.
1925 \return new separator action
1928 class TCreateSepEvent: public SALOME_Event
1931 typedef QAction* TResult;
1935 virtual void Execute()
1937 LightApp_Module* module = getActiveModule();
1939 myResult = (QAction*)module->separator();
1942 QAction* SalomePyQt::createSeparator()
1944 return ProcessEvent( new TCreateSepEvent() );
1948 \fn QAction* SalomePyQt::createAction( const int id,
1949 const QString& menuText,
1950 const QString& tipText,
1951 const QString& statusText,
1952 const QString& icon,
1954 const bool toggle );
1955 \brief Create an action which can be then used in the menu or toolbar.
1956 \param id the unique id action to be registered to
1957 \param menuText action text which should appear in menu
1958 \param tipText text which should appear in the tooltip
1959 \param statusText text which should appear in the status bar when action is activated
1960 \param icon the name of the icon file (the actual icon file name can be coded in the translation files)
1961 \param key the key accelrator for the action
1962 \param toggle if \c true the action is checkable
1965 class TCreateActionEvent: public SALOME_Event
1968 typedef QAction* TResult;
1973 QString myStatusText;
1977 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1978 const QString& statusText, const QString& icon, const int key, const bool toggle )
1979 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1980 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1981 virtual void Execute()
1983 LightApp_Module* module = getActiveModule();
1985 QIcon icon = loadIconInternal( module->name(), myIcon );
1986 myResult = (QAction*)module->action( myId );
1988 if ( myResult->toolTip().isEmpty() && !myTipText.isEmpty() )
1989 myResult->setToolTip( myTipText );
1990 if ( myResult->text().isEmpty() && !myMenuText.isEmpty() )
1991 myResult->setText( myMenuText );
1992 if ( myResult->icon().isNull() && !icon.isNull() )
1993 myResult->setIcon( icon );
1994 if ( myResult->statusTip().isEmpty() && !myStatusText.isEmpty() )
1995 myResult->setStatusTip( myStatusText );
1996 if ( myResult->shortcut().isEmpty() && myKey )
1997 myResult->setShortcut( myKey );
1998 if ( myResult->isCheckable() != myToggle )
1999 myResult->setCheckable( myToggle );
2002 myResult = (QAction*)module->createAction( myId, myTipText, icon, myMenuText, myStatusText, myKey, module, myToggle );
2004 // for Python module, automatically connect action to callback slot
2005 PyModuleHelper* helper = module->findChild<PyModuleHelper*>( "python_module_helper" );
2006 if ( helper ) helper->connectAction( myResult );
2010 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
2011 const QString& tipText, const QString& statusText,
2012 const QString& icon, const int key, const bool toggle )
2014 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
2018 \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive );
2019 \brief Create an action group which can be then used in the menu or toolbar
2020 \param id : the unique id action group to be registered to
2021 \param exclusive : if \c true the action group does exclusive toggling
2024 struct TCreateActionGroupEvent: public SALOME_Event
2026 typedef QtxActionGroup* TResult;
2030 TCreateActionGroupEvent( const int id, const bool exclusive )
2031 : myId( id ), myExclusive( exclusive ) {}
2032 virtual void Execute()
2034 LightApp_Module* module = getActiveModule();
2036 myResult = module->createActionGroup( myId, myExclusive );
2039 QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive )
2041 return ProcessEvent( new TCreateActionGroupEvent( id, exclusive ) );
2045 \fn QAction* SalomePyQt::action( const int id );
2046 \brief Get action by specified identifier.
2047 \return action or 0 if action is not registered
2050 class TActionEvent: public SALOME_Event
2053 typedef QAction* TResult;
2056 TActionEvent( const int id )
2057 : myResult( 0 ), myId( id ) {}
2058 virtual void Execute()
2060 LightApp_Module* module = getActiveModule();
2062 myResult = (QAction*)module->action( myId );
2065 QAction* SalomePyQt::action( const int id )
2067 return ProcessEvent( new TActionEvent( id ) );
2071 \fn int SalomePyQt::actionId( const QAction* a );
2072 \brief Get an action identifier.
2073 \return action ID or -1 if action is not registered
2076 class TActionIdEvent: public SALOME_Event
2079 typedef int TResult;
2081 const QAction* myAction;
2082 TActionIdEvent( const QAction* action )
2083 : myResult( -1 ), myAction( action ) {}
2084 virtual void Execute()
2086 LightApp_Module* module = getActiveModule();
2088 myResult = module->actionId( myAction );
2091 int SalomePyQt::actionId( const QAction* a )
2093 return ProcessEvent( new TActionIdEvent( a ) );
2097 \fn int SalomePyQt::addGlobalPreference( const QString& label );
2098 \brief Add global (not module-related) preferences group.
2099 \param label global preferences group name
2100 \return preferences group identifier
2103 class TAddGlobalPrefEvent: public SALOME_Event
2106 typedef int TResult;
2109 TAddGlobalPrefEvent( const QString& label )
2110 : myResult( -1 ), myLabel( label ) {}
2111 virtual void Execute()
2113 LightApp_Module* module = getActiveModule();
2115 LightApp_Preferences* pref = module->getApp()->preferences();
2117 myResult = pref->addPreference( myLabel, -1 );
2121 int SalomePyQt::addGlobalPreference( const QString& label )
2123 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
2127 \fn int SalomePyQt::addPreference( const QString& label );
2128 \brief Add module-related preferences group.
2129 \param label preferences group name
2130 \return preferences group identifier
2133 class TAddPrefEvent: public SALOME_Event
2136 typedef int TResult;
2139 TAddPrefEvent( const QString& label )
2140 : myResult( -1 ), myLabel( label ) {}
2141 virtual void Execute()
2143 LightApp_Module* module = getActiveModule();
2145 LightApp_Preferences* pref = module->getApp()->preferences();
2147 int cId = pref->addPreference( module->moduleName(), -1 );
2149 myResult = pref->addPreference( myLabel, cId );
2154 int SalomePyQt::addPreference( const QString& label )
2156 return ProcessEvent( new TAddPrefEvent( label ) );
2160 \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2161 const QString& section, const QString& param );
2162 \brief Add module-related preferences.
2163 \param label preferences group name
2164 \param pId parent preferences group id
2165 \param type preferences type
2166 \param section resources file section name
2167 \param param resources file setting name
2168 \return preferences identifier
2171 class TAddPrefParamEvent: public SALOME_Event
2174 typedef int TResult;
2181 TAddPrefParamEvent( const QString& label,
2182 const int pId, const int type,
2183 const QString& section,
2184 const QString& param )
2186 myLabel( label ), myPId( pId ), myType( type ),
2187 mySection( section ), myParam ( param ) {}
2188 virtual void Execute()
2190 LightApp_Module* module = getActiveModule();
2192 LightApp_Preferences* pref = module->getApp()->preferences();
2194 myResult = pref->addPreference( module->moduleName(), myLabel, myPId, myType, mySection, myParam );
2198 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
2199 const QString& section, const QString& param )
2201 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
2205 \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop );
2206 \brief Get the preferences property.
2207 \param id preferences identifier
2208 \param prop preferences property name
2209 \return preferences property value or null QVariant if property is not set
2212 class TPrefPropEvent: public SALOME_Event
2215 typedef QVariant TResult;
2219 TPrefPropEvent( const int id, const QString& prop )
2220 : myId( id ), myProp( prop ) {}
2221 virtual void Execute()
2223 LightApp_Module* module = getActiveModule();
2225 LightApp_Preferences* pref = module->getApp()->preferences();
2227 myResult = pref->itemProperty( myProp, myId );
2231 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
2233 return ProcessEvent( new TPrefPropEvent( id, prop ) );
2237 \brief Set the preferences property.
2238 \param id preferences identifier
2239 \param prop preferences property name
2240 \param var preferences property value
2242 void SalomePyQt::setPreferenceProperty( const int id,
2243 const QString& prop,
2244 const QVariant& var )
2246 class TEvent: public SALOME_Event
2252 TEvent( const int id, const QString& prop, const QVariant& var )
2253 : myId( id ), myProp( prop ), myVar( var ) {}
2254 virtual void Execute()
2256 LightApp_Module* module = getActiveModule();
2258 LightApp_Preferences* pref = module->getApp()->preferences();
2260 pref->setItemProperty( myProp, myVar, myId );
2264 ProcessVoidEvent( new TEvent( id, prop, var) );
2268 \brief Add the property value to the list of values.
2270 This method allows creating properties which are QList<QVariant>
2271 - there is no way to pass such values directly to QVariant parameter with PyQt.
2273 \param id preferences identifier
2274 \param prop preferences property name
2275 \param idx preferences property index
2276 \param var preferences property value for the index \a idx
2278 void SalomePyQt::addPreferenceProperty( const int id,
2279 const QString& prop,
2281 const QVariant& var )
2283 class TEvent: public SALOME_Event
2290 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
2291 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
2292 virtual void Execute()
2294 LightApp_Module* module = getActiveModule();
2296 LightApp_Preferences* pref = module->getApp()->preferences();
2298 QVariant var = pref->itemProperty( myProp, myId );
2299 if ( var.isValid() ) {
2300 if ( var.type() == QVariant::StringList ) {
2301 QStringList sl = var.toStringList();
2302 if ( myIdx >= 0 && myIdx < sl.count() )
2303 sl[myIdx] = myVar.toString();
2305 sl.append( myVar.toString() );
2306 pref->setItemProperty( myProp, sl, myId );
2308 else if ( var.type() == QVariant::List ) {
2309 QList<QVariant> vl = var.toList();
2310 if ( myIdx >= 0 && myIdx < vl.count() )
2314 pref->setItemProperty( myProp, vl, myId );
2320 pref->setItemProperty( myProp, vl, myId );
2326 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
2330 \brief Put the message to the Log messages output window
2331 \param msg message text (it can be of simple rich text format)
2332 \param addSeparator boolean flag which specifies if it is necessary
2333 to separate the message with predefined separator
2335 void SalomePyQt::message( const QString& msg, bool addSeparator )
2337 class TEvent: public SALOME_Event
2342 TEvent( const QString& msg, bool addSeparator )
2343 : myMsg( msg ), myAddSep( addSeparator ) {}
2344 virtual void Execute()
2346 if ( LightApp_Application* anApp = getApplication() ) {
2347 LogWindow* lw = anApp->logWindow();
2349 lw->putMessage( myMsg, myAddSep );
2353 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
2357 \brief Remove all the messages from the Log messages output window.
2359 void SalomePyQt::clearMessages()
2361 class TEvent: public SALOME_Event
2365 virtual void Execute()
2367 if ( LightApp_Application* anApp = getApplication() ) {
2368 LogWindow* lw = anApp->logWindow();
2374 ProcessVoidEvent( new TEvent() );
2378 \fn bool SalomePyQt::dumpView( const QString& filename, const int id = 0 );
2379 \brief Dump the contents of the id view window. If id is 0 then current active view is processed.
2380 to the image file in the specified format.
2382 For the current moment JPEG, PNG and BMP images formats are supported.
2383 The image format is defined automatically by the file name extension.
2384 By default, BMP format is used.
2386 \param filename image file name
2387 \return operation status (\c true on success)
2390 class TDumpViewEvent: public SALOME_Event
2393 typedef bool TResult;
2397 TDumpViewEvent( const QString& filename, const int id )
2398 : myResult ( false ), myFileName( filename ), myWndId( id ) {}
2399 virtual void Execute()
2401 SUIT_ViewWindow* wnd = 0;
2403 if ( LightApp_Application* anApp = getApplication() ) {
2404 SUIT_ViewManager* vm = anApp->activeViewManager();
2406 wnd = vm->getActiveView();
2408 myWndId = wnd->getId();
2411 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2414 QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
2415 #ifndef DISABLE_PLOT2DVIEWER
2416 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2418 qApp->postEvent( wnd2D->getViewFrame(), new QPaintEvent( QRect( 0, 0, wnd2D->getViewFrame()->width(), wnd2D->getViewFrame()->height() ) ) );
2419 qApp->postEvent( wnd2D, new QPaintEvent( QRect( 0, 0, wnd2D->width(), wnd2D->height() ) ) );
2420 qApp->processEvents();
2421 if ( fmt == "PS" || fmt == "EPS" || fmt == "PDF" ) {
2422 myResult = wnd2D->getViewFrame()->print( myFileName, fmt );
2426 #endif // DISABLE_PLOT2DVIEWER
2427 QImage im = wnd->dumpView();
2428 if ( !im.isNull() && !myFileName.isEmpty() ) {
2429 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
2430 if ( fmt == "JPG" ) fmt = "JPEG";
2431 myResult = im.save( myFileName, fmt.toLatin1() );
2436 bool SalomePyQt::dumpView( const QString& filename, const int id )
2438 return ProcessEvent( new TDumpViewEvent( filename, id ) );
2442 \fn QList<int> SalomePyQt::getViews();
2443 \brief Get list of integer identifiers of all the currently opened views
2444 \return list of integer identifiers of all the currently opened views
2447 class TGetViews: public SALOME_Event
2450 typedef QList<int> TResult;
2453 virtual void Execute()
2456 LightApp_Application* app = getApplication();
2458 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
2460 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
2461 SUIT_ViewWindow* wnd;
2462 foreach ( wnd, wndlist )
2463 myResult.append( wnd->getId() );
2468 QList<int> SalomePyQt::getViews()
2470 return ProcessEvent( new TGetViews() );
2474 \fn int SalomePyQt::getActiveView();
2475 \brief Get integer identifier of the currently active view
2476 \return integer identifier of the currently active view
2479 class TGetActiveView: public SALOME_Event
2482 typedef int TResult;
2486 virtual void Execute()
2488 LightApp_Application* app = getApplication();
2490 SUIT_ViewManager* viewMgr = app->activeViewManager();
2492 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2494 myResult = wnd->getId();
2499 int SalomePyQt::getActiveView()
2501 return ProcessEvent( new TGetActiveView() );
2505 \fn QString SalomePyQt::getViewType( const int id );
2506 \brief Get type of the specified view, e.g. "OCCViewer"
2507 \param id window identifier
2511 class TGetViewType: public SALOME_Event
2514 typedef QString TResult;
2517 TGetViewType( const int id )
2519 virtual void Execute()
2521 SUIT_ViewWindow* wnd = getWnd( myWndId );
2523 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2525 myResult = viewMgr->getType();
2529 QString SalomePyQt::getViewType( const int id )
2531 return ProcessEvent( new TGetViewType( id ) );
2535 \fn bool SalomePyQt::setViewTitle( const int id, const QString& title );
2536 \brief Change view caption
2537 \param id window identifier
2538 \param title new window title
2539 \return \c true if operation is completed successfully and \c false otherwise
2542 class TSetViewTitle: public SALOME_Event
2545 typedef bool TResult;
2549 TSetViewTitle( const int id, const QString& title )
2550 : myResult( false ),
2553 virtual void Execute()
2555 SUIT_ViewWindow* wnd = getWnd( myWndId );
2557 wnd->setWindowTitle( myTitle );
2562 bool SalomePyQt::setViewTitle( const int id, const QString& title )
2564 return ProcessEvent( new TSetViewTitle( id, title ) );
2568 \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id );
2569 \brief Set view size
2570 \param w window width
2571 \param h window height
2572 \param id window identifier
2573 \return \c true if operation is completed successfully and \c false otherwise
2576 class TSetViewSize: public SALOME_Event
2579 typedef bool TResult;
2584 TSetViewSize( const int w, const int h, const int id )
2585 : myResult( false ),
2589 virtual void Execute()
2591 SUIT_ViewWindow* wnd = 0;
2593 if ( LightApp_Application* anApp = getApplication() ) {
2594 SUIT_ViewManager* vm = anApp->activeViewManager();
2596 wnd = vm->getActiveView();
2600 wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
2603 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2605 QString type = viewMgr->getType();
2606 if ( type == "OCCViewer") {
2607 #ifndef DISABLE_OCCVIEWER
2608 // specific processing for OCC viewer:
2609 // OCC view can embed up to 4 sub-views, split according to the specified layout;
2610 // - if there is only one sub-view active; it will be resized;
2611 // - if there are several sub-views, each of them will be resized.
2612 OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
2613 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
2614 if ( occView && occView->getView( i ) ) {
2615 occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight );
2619 #endif // DISABLE_OCCVIEWER
2621 else if ( type == "ParaView") {
2622 #ifndef DISABLE_PVVIEWER
2623 // specific processing for ParaView viewer:
2624 // hierarchy of ParaView viewer is much complex than for usual view;
2625 // we look for sub-widget named "Viewport"
2626 QList<QWidget*> lst = wnd->findChildren<QWidget*>( "Viewport" );
2627 if ( !lst.isEmpty() ) {
2628 lst[0]->resize( myWndWidth, myWndHeight );
2631 #endif // DISABLE_PVVIEWER
2634 if ( wnd->centralWidget() ) {
2635 wnd->centralWidget()->resize( myWndWidth, myWndHeight );
2643 bool SalomePyQt::setViewSize( const int w, const int h, const int id )
2645 return ProcessEvent( new TSetViewSize( w, h, id ) );
2649 \fn QString SalomePyQt::getViewTitle( const int id );
2650 \brief Get view caption
2651 \param id window identifier
2652 \return view caption
2655 class TGetViewTitle: public SALOME_Event
2658 typedef QString TResult;
2661 TGetViewTitle( const int id )
2663 virtual void Execute()
2665 SUIT_ViewWindow* wnd = getWnd( myWndId );
2667 myResult = wnd->windowTitle();
2670 QString SalomePyQt::getViewTitle( const int id )
2672 return ProcessEvent( new TGetViewTitle( id ) );
2676 \fn QList<int> SalomePyQt::findViews( const QString& type );
2677 \brief Get list of integer identifiers of all the
2678 currently opened views of the specified type
2679 \param type viewer type
2680 \return list of integer identifiers
2683 class TFindViews: public SALOME_Event
2686 typedef QList<int> TResult;
2689 TFindViews( const QString& type )
2691 virtual void Execute()
2694 LightApp_Application* app = getApplication();
2696 ViewManagerList vmList;
2697 app->viewManagers( myType, vmList );
2698 SUIT_ViewManager* viewMgr;
2699 foreach ( viewMgr, vmList ) {
2700 QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
2701 for ( int i = 0, n = vec.size(); i < n; i++ ) {
2702 SUIT_ViewWindow* wnd = vec[ i ];
2704 myResult.append( wnd->getId() );
2710 QList<int> SalomePyQt::findViews( const QString& type )
2712 return ProcessEvent( new TFindViews( type ) );
2716 \fn bool SalomePyQt::activateView( const int id );
2717 \brief Activate view
2718 \param id window identifier
2719 \return \c true if operation is completed successfully and \c false otherwise
2722 class TActivateView: public SALOME_Event
2725 typedef bool TResult;
2728 TActivateView( const int id )
2729 : myResult( false ),
2731 virtual void Execute()
2733 SUIT_ViewWindow* wnd = getWnd( myWndId );
2740 bool SalomePyQt::activateView( const int id )
2742 return ProcessEvent( new TActivateView( id ) );
2746 \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
2747 \brief Create new view and activate it
2748 \param type viewer type
2752 \return integer identifier of created view (or -1 if view could not be created)
2755 class TCreateView: public SALOME_Event
2758 typedef int TResult;
2764 TCreateView( const QString& theType, bool visible, const int width, const int height )
2770 virtual void Execute()
2772 LightApp_Application* app = getApplication();
2774 SUIT_ViewManager* viewMgr = app->createViewManager( myType );
2776 QWidget* wnd = viewMgr->getActiveView();
2777 myResult = viewMgr->getActiveView()->getId();
2780 wnd->setVisible(false);
2781 if ( !myVisible && myWidth == 0 && myHeight == 0 ) {
2785 if (myWidth > 0 && myHeight > 0) {
2786 #ifndef DISABLE_PLOT2DVIEWER
2787 Plot2d_ViewWindow* wnd2D = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2788 if ( wnd2D ) wnd = wnd2D->getViewFrame();
2789 #endif // DISABLE_PLOT2DVIEWER
2790 wnd->setGeometry( 0, 0, myWidth, myHeight );
2797 int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
2799 int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
2800 QCoreApplication::processEvents();
2805 \fn int SalomePyQt::createView( const QString& type, QWidget* w );
2806 \brief Create new view with custom widget embedded and activate it
2807 \param type viewer type
2808 \param w custom widget
2809 \return integer identifier of created view (or -1 if view could not be created)
2812 class TCreateViewWg: public SALOME_Event
2815 typedef int TResult;
2819 TCreateViewWg( const QString& theType, QWidget* w )
2823 virtual void Execute()
2825 LightApp_Application* app = getApplication();
2827 SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
2829 SUIT_ViewWindow* wnd = viewMgr->getActiveView();
2831 myResult = wnd->getId();
2836 int SalomePyQt::createView( const QString& type, QWidget* w )
2838 int ret = ProcessEvent( new TCreateViewWg( type, w ) );
2839 QCoreApplication::processEvents();
2844 \fn bool SalomePyQt::closeView( const int id );
2846 \param id window identifier
2847 \return \c true if operation is completed successfully and \c false otherwise
2850 class TCloseView: public SALOME_Event
2853 typedef bool TResult;
2856 TCloseView( const int id )
2857 : myResult( false ),
2859 virtual void Execute()
2861 SUIT_ViewWindow* wnd = getWnd( myWndId );
2863 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2871 bool SalomePyQt::closeView( const int id )
2873 return ProcessEvent( new TCloseView( id ) );
2877 \fn int SalomePyQt::cloneView( const int id );
2878 \brief Clone view (if this operation is supported for specified view type)
2879 \param id window identifier
2880 \return integer identifier of the cloned view or -1 or operation could not be performed
2883 class TCloneView: public SALOME_Event
2886 typedef int TResult;
2889 TCloneView( const int id )
2892 virtual void Execute()
2894 SUIT_ViewWindow* wnd = getWnd( myWndId );
2896 SUIT_ViewManager* viewMgr = wnd->getViewManager();
2898 #ifndef DISABLE_OCCVIEWER
2899 if ( wnd->inherits( "OCCViewer_ViewWindow" ) ) {
2900 OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
2901 occView->onCloneView();
2902 wnd = viewMgr->getActiveView();
2904 myResult = wnd->getId();
2906 #endif // DISABLE_OCCVIEWER
2907 #ifndef DISABLE_PLOT2DVIEWER
2908 if ( wnd->inherits( "Plot2d_ViewWindow" ) ) {
2909 Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
2910 Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
2911 if ( viewMgr2d && srcWnd2d ) {
2912 Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
2913 myResult = resWnd->getId();
2916 #endif // DISABLE_OCCVIEWER
2921 int SalomePyQt::cloneView( const int id )
2923 return ProcessEvent( new TCloneView( id ) );
2927 \fn bool SalomePyQt::setViewVisible( const int id, const bool visible )
2928 \brief Set view visibility.
2929 \param id window identifier
2930 \param visible new visiblity
2933 void SalomePyQt::setViewVisible( const int id, const bool visible )
2935 class TEvent: public SALOME_Event
2940 TEvent( const int id, const bool visible )
2941 : myWndId( id ), myVisible( visible ) {}
2942 virtual void Execute()
2944 SUIT_ViewWindow* wnd = getWnd( myWndId );
2945 if ( wnd ) wnd->setVisible( myVisible );
2948 ProcessVoidEvent( new TEvent( id, visible ) );
2952 \fn bool SalomePyQt::isViewVisible( const int id );
2953 \brief Check whether view is visible ( i.e. it is on the top of the views stack)
2954 \param id window identifier
2955 \return \c true if view is visible and \c false otherwise
2958 class TIsViewVisible: public SALOME_Event
2961 typedef bool TResult;
2964 TIsViewVisible( const int id )
2965 : myResult( false ),
2967 virtual void Execute()
2969 SUIT_ViewWindow* wnd = getWnd( myWndId );
2972 QWidget* p = wnd->parentWidget();
2973 myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
2977 bool SalomePyQt::isViewVisible( const int id )
2979 return ProcessEvent( new TIsViewVisible( id ) );
2983 \fn bool SalomePyQt::setViewClosable( const int id, const bool on );
2984 \brief Set / clear view's "closable" option. By default any view is closable
2985 (i.e. can be closed by the user).
2986 \param id window identifier
2987 \param on new "closable" option's value
2990 void SalomePyQt::setViewClosable( const int id, const bool on )
2992 class TEvent: public SALOME_Event
2997 TEvent( const int id, const bool on )
2998 : myWndId( id ), myOn( on ) {}
2999 virtual void Execute()
3001 SUIT_ViewWindow* wnd = getWnd( myWndId );
3002 if ( wnd ) wnd->setClosable( myOn );
3005 ProcessVoidEvent( new TEvent( id, on ) );
3009 \fn bool SalomePyQt::isViewClosable( const int id );
3010 \brief Check whether view is closable (i.e. can be closed by the user)
3011 \param id window identifier
3012 \return \c true if view is closable or \c false otherwise
3015 class TIsViewClosable: public SALOME_Event
3018 typedef bool TResult;
3021 TIsViewClosable( const int id )
3024 virtual void Execute()
3026 SUIT_ViewWindow* wnd = getWnd( myWndId );
3028 myResult = wnd->closable();
3032 bool SalomePyQt::isViewClosable( const int id )
3034 return ProcessEvent( new TIsViewClosable( id ) );
3038 \fn bool SalomePyQt::groupAllViews();
3039 \brief Group all views to the single tab area
3040 \return \c true if operation is completed successfully and \c false otherwise
3043 class TGroupAllViews: public SALOME_Event
3046 typedef bool TResult;
3049 : myResult( false ) {}
3050 virtual void Execute()
3052 LightApp_Application* app = getApplication();
3054 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3056 QtxWorkstack* wStack = tabDesk->workstack();
3065 bool SalomePyQt::groupAllViews()
3067 return ProcessEvent( new TGroupAllViews() );
3071 \fn bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action );
3072 \brief Split tab area to which view with identifier belongs to
3073 \param id window identifier
3074 \param ori orientation of split operation
3075 \param action action to be performed
3076 \return \c true if operation is completed successfully \c false otherwise
3079 class TSplitView: public SALOME_Event
3082 typedef bool TResult;
3087 TSplitView( const int id,
3088 const Orientation ori,
3089 const Action action )
3090 : myResult( false ),
3093 myAction( action ) {}
3094 virtual void Execute()
3096 SUIT_ViewWindow* wnd = getWnd( myWndId );
3099 // wnd->setFocus(); ???
3102 if ( getApplication() ) {
3103 STD_TabDesktop* desk =
3104 dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
3106 QtxWorkstack* wStack = desk->workstack();
3108 Qt::Orientation qtOri =
3109 ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
3111 QtxWorkstack::SplitType sType;
3112 if ( myAction == MoveWidget )
3113 sType = QtxWorkstack::SplitMove;
3114 else if ( myAction == LeaveWidget )
3115 sType = QtxWorkstack::SplitStay;
3117 sType = QtxWorkstack::SplitAt;
3119 wStack->Split( wnd, qtOri, sType );
3127 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
3129 return ProcessEvent( new TSplitView( id, ori, action ) );
3133 \fn bool SalomePyQt::moveView( const int id, const int id_to, const bool before );
3134 \brief Move view with the first identifier to the same area which
3135 another view with the second identifier belongs to
3136 \param id source window identifier
3137 \param id_to destination window identifier
3138 param before specifies whether the first viewt has to be moved before or after
3140 \return \c true if operation is completed successfully and \c false otherwise
3143 class TMoveView: public SALOME_Event
3146 typedef bool TResult;
3151 TMoveView( const int id, const int id_to, const bool before )
3152 : myResult( false ),
3155 myIsBefore( before ) {}
3156 virtual void Execute()
3158 SUIT_ViewWindow* wnd = getWnd( myWndId );
3159 SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
3160 if ( wnd && wnd_to ) {
3161 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3162 getApplication()->desktop() )->workstack();
3164 myResult = wStack->move( wnd, wnd_to, myIsBefore );
3168 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
3170 return ProcessEvent( new TMoveView( id, id_to, before ) );
3174 \fn QList<int> SalomePyQt::neighbourViews( const int id );
3175 \brief Get list of views identifiers that belongs to the same area as
3176 specified view (excluding it)
3177 \param id window identifier
3178 \return list of views identifiers
3181 class TNeighbourViews: public SALOME_Event
3184 typedef QList<int> TResult;
3187 TNeighbourViews( const int id )
3189 virtual void Execute()
3192 SUIT_ViewWindow* wnd = getWnd( myWndId );
3194 QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>(
3195 getApplication()->desktop() )->workstack();
3197 QWidgetList wgList = wStack->windowList( wnd );
3199 foreach ( wg, wgList ) {
3200 SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
3201 if ( tmpWnd && tmpWnd != wnd )
3202 myResult.append( tmpWnd->getId() );
3208 QList<int> SalomePyQt::neighbourViews( const int id )
3210 return ProcessEvent( new TNeighbourViews( id ) );
3215 \fn QString SalomePyQt::createObject( const QString& parent );
3216 \brief Create empty data object
3217 \param parent entry of parent data object
3218 \return entry of created data object
3221 class TCreateEmptyObjectEvent: public SALOME_Event
3224 typedef QString TResult;
3227 TCreateEmptyObjectEvent( const QString& parent )
3228 : myParent( parent ) {}
3229 virtual void Execute()
3231 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3233 myResult = module->createObject( myParent );
3236 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3240 QString SalomePyQt::createObject( const QString& parent )
3242 return ProcessEvent( new TCreateEmptyObjectEvent( parent ) );
3246 \fn QString SalomePyQt::createObject( const QString& name, const QString& icon,
3247 const QString& tooltip,const QString& parent );
3248 \brief Create new data object with specified name, icon and tooltip
3249 \param name data object name
3250 \param icon data object icon
3251 \param toolTip data object tooltip
3252 \param parent entry of parent data object
3253 \return entry of created data object
3256 class TCreateObjectEvent: public SALOME_Event
3259 typedef QString TResult;
3265 TCreateObjectEvent( const QString& name,
3266 const QString& icon,
3267 const QString& tooltip,
3268 const QString& parent )
3271 myToolTip( tooltip ),
3272 myParent( parent ) {}
3273 virtual void Execute()
3275 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3277 myResult = module->createObject( myName, myIcon, myToolTip, myParent );
3280 if ( verbose() ) printf( "SalomePyQt.createObject() function is not supported for the current module.\n" );
3284 QString SalomePyQt::createObject( const QString& name,
3285 const QString& icon,
3286 const QString& toolTip,
3287 const QString& parent )
3289 return ProcessEvent( new TCreateObjectEvent( name, icon, toolTip, parent ) );
3294 \fn void SalomePyQt::setName( const QString& entry, const QString& name );
3295 \brief Set data object name
3296 \param entry data object entry
3297 \param name data object name
3299 class TSetNameEvent: public SALOME_Event
3304 TSetNameEvent( const QString& entry,
3305 const QString& name )
3308 virtual void Execute()
3310 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3312 module->setName( myEntry, myName );
3315 if ( verbose() ) printf( "SalomePyQt.setName() function is not supported for the current module.\n" );
3319 void SalomePyQt::setName( const QString& entry, const QString& name )
3321 ProcessVoidEvent( new TSetNameEvent( entry, name ) );
3325 \fn void SalomePyQt::setIcon( const QString& entry, const QString& icon );
3326 \brief Set data object icon
3327 \param entry data object entry
3328 \param icon data object icon file name (icon is loaded from module resources)
3331 class TSetIconEvent: public SALOME_Event
3336 TSetIconEvent( const QString& entry,
3337 const QString& icon )
3340 virtual void Execute()
3342 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3344 module->setIcon( myEntry, myIcon );
3347 if ( verbose() ) printf( "SalomePyQt.setIcon() function is not supported for the current module.\n" );
3352 void SalomePyQt::setIcon( const QString& entry, const QString& icon )
3354 ProcessVoidEvent( new TSetIconEvent( entry, icon ) );
3358 \fn void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip );
3359 \brief Set data object tooltip
3360 \param entry data object entry
3361 \param toolTip data object tooltip
3364 class TSetToolTipEvent: public SALOME_Event
3369 TSetToolTipEvent( const QString& entry,
3370 const QString& toolTip )
3372 myToolTip( toolTip ) {}
3373 virtual void Execute()
3375 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3377 module->setToolTip( myEntry, myToolTip );
3380 if ( verbose() ) printf( "SalomePyQt.setToolTip() function is not supported for the current module.\n" );
3384 void SalomePyQt::setToolTip( const QString& entry, const QString& toolTip )
3386 ProcessVoidEvent( new TSetToolTipEvent( entry, toolTip ) );
3390 \fn void SalomePyQt::setReference( const QString& entry, const QString& refEntry );
3391 \brief Set reference to another data object
3392 \param entry data object entry
3393 \param refEntry referenced data object entry
3396 class TSetRefEvent: public SALOME_Event
3401 TSetRefEvent( const QString& entry,
3402 const QString& refEntry )
3404 myRefEntry( refEntry ) {}
3405 virtual void Execute()
3407 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3409 module->setReference( myEntry, myRefEntry );
3412 if ( verbose() ) printf( "SalomePyQt.setReference() function is not supported for the current module.\n" );
3416 void SalomePyQt::setReference( const QString& entry, const QString& refEntry )
3418 ProcessVoidEvent( new TSetRefEvent( entry, refEntry ) );
3422 \fn void SalomePyQt::setColor( const QString& entry, const QColor& color );
3423 \brief Set data object color
3424 \param entry data object entry
3425 \param color data object color
3428 class TSetColorEvent: public SALOME_Event
3433 TSetColorEvent( const QString& entry,
3434 const QColor& color )
3437 virtual void Execute()
3439 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3441 module->setColor( myEntry, myColor );
3444 if ( verbose() ) printf( "SalomePyQt.setColor() function is not supported for the current module.\n" );
3448 void SalomePyQt::setColor( const QString& entry, const QColor& color )
3450 ProcessVoidEvent( new TSetColorEvent( entry, color ) );
3454 \fn QString SalomePyQt::getName( const QString& entry );
3455 \brief Get data object name
3456 \param entry data object entry
3457 \return data object name
3460 class TGetNameEvent: public SALOME_Event
3463 typedef QString TResult;
3466 TGetNameEvent( const QString& entry )
3467 : myEntry( entry ) {}
3468 virtual void Execute()
3470 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3472 myResult = module->getName( myEntry );
3475 if ( verbose() ) printf( "SalomePyQt.getName() function is not supported for the current module.\n" );
3479 QString SalomePyQt::getName( const QString& entry )
3481 return ProcessEvent( new TGetNameEvent( entry ) );
3485 \fn QString SalomePyQt::getToolTip( const QString& entry );
3486 \brief Get data object tooltip
3487 \param entry data object entry
3488 \return data object tooltip
3491 class TGetToolTipEvent: public SALOME_Event
3494 typedef QString TResult;
3497 TGetToolTipEvent( const QString& entry )
3498 : myEntry( entry ) {}
3499 virtual void Execute()
3501 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3503 myResult = module->getToolTip( myEntry );
3506 if ( verbose() ) printf( "SalomePyQt.getToolTip() function is not supported for the current module.\n" );
3510 QString SalomePyQt::getToolTip( const QString& entry )
3512 return ProcessEvent( new TGetToolTipEvent( entry ) );
3516 \fn QString SalomePyQt::getReference( const QString& entry );
3517 \brief Get entry of the referenced object (if there's any)
3518 \param entry data object entry
3519 \return referenced data object entry
3522 class TGetRefEvent: public SALOME_Event
3525 typedef QString TResult;
3528 TGetRefEvent( const QString& entry )
3529 : myEntry( entry ) {}
3530 virtual void Execute()
3532 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3534 myResult = module->getReference( myEntry );
3537 if ( verbose() ) printf( "SalomePyQt.getReference() function is not supported for the current module.\n" );
3541 QString SalomePyQt::getReference( const QString& entry )
3543 return ProcessEvent( new TGetRefEvent( entry ) );
3547 \fn QColor SalomePyQt::getColor( const QString& entry );
3548 \brief Get data object color
3549 \param entry data object entry
3550 \return data object color
3553 class TGetColorEvent: public SALOME_Event
3556 typedef QColor TResult;
3559 TGetColorEvent( const QString& entry )
3560 : myEntry( entry ) {}
3561 virtual void Execute()
3563 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3565 myResult = module->getColor( myEntry );
3568 if ( verbose() ) printf( "SalomePyQt.getColor() function is not supported for the current module.\n" );
3572 QColor SalomePyQt::getColor( const QString& entry )
3574 return ProcessEvent( new TGetColorEvent( entry ) );
3578 \fn void SalomePyQt::removeChildren( const QString& entry );
3579 \brief Remove all child data objects from specified data object
3580 \param entry data object entry
3583 class TRemoveChildEvent: public SALOME_Event
3587 TRemoveChildEvent( const QString& entry )
3588 : myEntry( entry ) {}
3589 virtual void Execute()
3591 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3593 module->removeChildren( myEntry );
3596 if ( verbose() ) printf( "SalomePyQt.removeChildren() function is not supported for the current module.\n" );
3600 void SalomePyQt::removeChildren( const QString& entry )
3602 ProcessVoidEvent( new TRemoveChildEvent( entry ) );
3604 void SalomePyQt::removeChild( const QString& entry )
3606 if ( verbose() ) printf( "SalomePyQt.removeChild() function is obsolete. Use SalomePyQt.removeChildren() instead." );
3607 removeChildren( entry );
3611 \fn void SalomePyQt::removeObject( const QString& entry );
3612 \brief Remove object by entry
3613 \param entry data object entry
3616 class TRemoveObjectEvent: public SALOME_Event
3621 TRemoveObjectEvent( const QString& entry )
3622 : myEntry( entry ) {}
3623 virtual void Execute()
3625 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3627 module->removeObject( myEntry );
3630 if ( verbose() ) printf( "SalomePyQt.removeObject() function is not supported for the current module.\n" );
3634 void SalomePyQt::removeObject( const QString& entry )
3636 ProcessVoidEvent( new TRemoveObjectEvent( entry ) );
3640 \fn QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive );
3641 \brief Get entries of all child data objects of specified data object
3642 \param entry data object entry
3643 \param recursive \c true for recursive processing
3646 class TGetChildrenEvent: public SALOME_Event
3649 typedef QStringList TResult;
3653 TGetChildrenEvent( const QString& entry, const bool recursive )
3655 myRecursive( recursive ) {}
3656 virtual void Execute()
3658 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
3660 myResult = module->getChildren( myEntry, myRecursive );
3663 if ( verbose() ) printf( "SalomePyQt.getChildren() function is not supported for the current module.\n" );
3667 QStringList SalomePyQt::getChildren( const QString& entry, const bool recursive )
3669 return ProcessEvent( new TGetChildrenEvent( entry, recursive ) );
3672 #ifndef DISABLE_PLOT2DVIEWER
3673 // Next set of methods relates to the Plot2d viewer functionality
3676 \fn void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3677 \brief Display theCurve in view
3678 \param id window identifier
3679 \param theCurve curve to display
3682 class TDisplayCurve: public SALOME_Event
3686 Plot2d_Curve* myCurve;
3687 TDisplayCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3688 virtual void Execute() {
3689 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3691 wnd->getViewFrame()->displayCurve( myCurve );
3694 void SalomePyQt::displayCurve( const int id, Plot2d_Curve* theCurve )
3696 ProcessVoidEvent( new TDisplayCurve( id, theCurve ) );
3700 \fn void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3701 \brief Erase theCurve in view
3702 \param id window identifier
3703 \param theCurve curve to erase
3706 class TEraseCurve: public SALOME_Event
3710 Plot2d_Curve* myCurve;
3711 TEraseCurve( const int id, Plot2d_Curve* theCurve ) : myWndId( id ), myCurve( theCurve ) {}
3712 virtual void Execute() {
3713 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3714 wnd->getViewFrame()->eraseCurve( myCurve );
3717 void SalomePyQt::eraseCurve( const int id, Plot2d_Curve* theCurve )
3719 ProcessVoidEvent( new TEraseCurve( id, theCurve ) );
3723 \fn void SalomePyQt::deleteCurve( Plot2d_Curve* theCurve )
3724 \brief Delete theCurve from all views
3725 \param theCurve curve to delete
3728 class TDeleteCurve: public SALOME_Event
3731 Plot2d_Curve* myCurve;
3732 TDeleteCurve( Plot2d_Curve* theCurve ) : myCurve( theCurve ) {}
3733 virtual void Execute() {
3734 LightApp_Application* app = getApplication();
3736 STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
3738 QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
3739 SUIT_ViewWindow* wnd;
3740 foreach ( wnd, wndlist ) {
3741 Plot2d_ViewWindow* aP2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
3743 aP2d->getViewFrame()->eraseObject( myCurve );
3749 void SalomePyQt::eraseCurve( Plot2d_Curve* theCurve )
3751 ProcessVoidEvent( new TDeleteCurve( theCurve ) );
3755 \brief updateCurves (repaint) curves in view window.
3757 void SalomePyQt::updateCurves( const int id )
3759 class TEvent: public SALOME_Event
3763 TEvent( const int id ) : myWndId( id ) {}
3764 virtual void Execute()
3766 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3768 wnd->getViewFrame()->DisplayAll();
3771 ProcessVoidEvent( new TEvent( id ) );
3775 \fn QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type = MainTitle )
3776 \brief Get title of corresponding type
3777 \param id window identifier
3778 \param type is type of title
3779 \return title of corresponding type
3782 class TGetPlot2dTitle: public SALOME_Event
3785 typedef QString TResult;
3789 TGetPlot2dTitle(const int id, ObjectType type) :
3792 virtual void Execute() {
3793 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3795 myResult = wnd->getViewFrame()->getTitle( (Plot2d_ViewFrame::ObjectType)myType );
3798 QString SalomePyQt::getPlot2dTitle( const int id, ObjectType type )
3800 return ProcessEvent( new TGetPlot2dTitle( id, type ) );
3805 \fn void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type = MainTitle, bool show = true )
3806 \brief Set title of corresponding type
3807 \param id window identifier
3809 \param type is type of title
3813 class TSetPlot2dTitle: public SALOME_Event
3817 Plot2d_Curve* myCurve;
3821 TSetPlot2dTitle( const int id, const QString& title, ObjectType type, bool show ) :
3826 virtual void Execute() {
3827 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3828 wnd->getViewFrame()->setTitle( myShow, myTitle, (Plot2d_ViewFrame::ObjectType)myType, false );
3831 void SalomePyQt::setPlot2dTitle( const int id, const QString& title, ObjectType type, bool show )
3833 ProcessVoidEvent( new TSetPlot2dTitle( id, title, type, show ) );
3837 \fn QList<int> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3838 \brief Get list of Plot2d view ranges
3839 \param id window identifier
3840 \return list of view ranges (XMin, XMax, YMin, YMax)
3843 class TFitRangeByCurves: public SALOME_Event
3846 typedef QList<double> TResult;
3849 TFitRangeByCurves( const int id )
3851 virtual void Execute()
3854 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3856 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3857 wnd->getViewFrame()->getFitRangeByCurves( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3858 myResult.append( XMin );
3859 myResult.append( XMax );
3860 myResult.append( YMin );
3861 myResult.append( YMax );
3865 QList<double> SalomePyQt::getPlot2dFitRangeByCurves( const int id )
3867 return ProcessEvent( new TFitRangeByCurves( id ) );
3871 \fn QList<int> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3872 \brief Get list of current Plot2d view ranges
3873 \param id window identifier
3874 \return list of view ranges (XMin, XMax, YMin, YMax)
3877 class TFitRangeCurrent: public SALOME_Event
3880 typedef QList<double> TResult;
3883 TFitRangeCurrent( const int id )
3885 virtual void Execute()
3888 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3890 double XMin, XMax, YMin, YMax, Y2Min, Y2Max;
3891 wnd->getViewFrame()->getFitRanges( XMin, XMax, YMin, YMax, Y2Min, Y2Max );
3892 myResult.append( XMin );
3893 myResult.append( XMax );
3894 myResult.append( YMin );
3895 myResult.append( YMax );
3899 QList<double> SalomePyQt::getPlot2dFitRangeCurrent( const int id )
3901 return ProcessEvent( new TFitRangeCurrent( id ) );
3905 \fn void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3906 \brief Set range of Plot2d view
3907 \param id window identifier
3914 class TPlot2dFitRange: public SALOME_Event
3922 TPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax ) :
3928 virtual void Execute() {
3929 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( getWnd( myWndId ) );
3931 wnd->getViewFrame()->fitData( 0, myXMin, myXMax, myYMin, myYMax );
3934 void SalomePyQt::setPlot2dFitRange( const int id, const double XMin, const double XMax, const double YMin, const double YMax )
3936 ProcessVoidEvent( new TPlot2dFitRange( id, XMin, XMax, YMin, YMax ) );
3939 // End of methods related to the Plot2d viewer functionality
3940 #endif // DISABLE_PLOT2DVIEWER
3943 \brief Process Qt event loop
3945 void SalomePyQt::processEvents()
3947 QCoreApplication::processEvents();
3951 \brief Set visibility state for given object
3952 \param theEntry study ID of the object
3953 \param theState visibility state
3955 void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState )
3957 class TEvent: public SALOME_Event
3962 TEvent( const QString& theEntry, int theState ):
3963 myEntry( theEntry ), myState( theState ) {}
3964 virtual void Execute()
3966 LightApp_Study* aStudy = getActiveStudy();
3969 aStudy->setVisibilityState( myEntry, (Qtx::VisibilityState)myState );
3972 ProcessVoidEvent( new TEvent( theEntry, theState ) );
3976 \fn VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3977 \brief Get visibility state for given object
3978 \param theEntry study ID of the object
3979 \return visibility state
3982 class TGetVisibilityStateEvent: public SALOME_Event
3985 typedef int TResult;
3988 TGetVisibilityStateEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
3989 virtual void Execute()
3991 LightApp_Study* aStudy = getActiveStudy();
3993 myResult = aStudy->visibilityState( myEntry );
3996 VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry )
3998 return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent( theEntry ) );
4002 \brief Set position of given object in the tree
4003 \param theEntry study ID of the object
4004 \param thePos position
4006 void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos )
4008 class TEvent: public SALOME_Event
4013 TEvent( const QString& theEntry, int thePos ):
4014 myEntry( theEntry ), myPos( thePos ) {}
4015 virtual void Execute()
4017 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4019 module->setObjectPosition( myEntry, myPos );
4022 ProcessVoidEvent( new TEvent( theEntry, thePos ) );
4026 \fn int SalomePyQt::getObjectPosition( const QString& theEntry )
4027 \brief Get position of given object in the tree
4028 \param theEntry study ID of the object
4032 class TGetObjectPositionEvent: public SALOME_Event
4035 typedef int TResult;
4038 TGetObjectPositionEvent( const QString& theEntry ) : myResult( 0 ), myEntry( theEntry ) {}
4039 virtual void Execute()
4041 SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
4043 myResult = module->getObjectPosition( myEntry );
4046 int SalomePyQt::getObjectPosition( const QString& theEntry )
4048 return ProcessEvent( new TGetObjectPositionEvent( theEntry ) );
4052 \brief Start recordind a log of Python commands from embedded console
4053 \param theFileName output lof file name
4055 void SalomePyQt::startPyLog( const QString& theFileName )
4057 class TEvent: public SALOME_Event
4061 TEvent( const QString& theFileName ):
4062 myFileName( theFileName ) {}
4063 virtual void Execute()
4065 if ( getApplication() ) {
4066 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4067 if ( pyConsole ) pyConsole->startLog( myFileName );
4071 ProcessVoidEvent( new TEvent( theFileName ) );
4075 \brief Stop recordind a log of Python commands from embedded console
4077 void SalomePyQt::stopPyLog()
4079 class TEvent: public SALOME_Event
4083 virtual void Execute()
4085 if ( getApplication() ) {
4086 PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
4087 if ( pyConsole ) pyConsole->stopLog();
4091 ProcessVoidEvent( new TEvent() );