From bcf994ac79dbdb1e11e66b127690427544a2269a Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 23 Dec 2013 09:51:26 +0000 Subject: [PATCH] Modification for bugs 22451: MoveUp/MoveDown items of ObjectBrowser 22450: 'eye' icon management --- .../SALOME_PYQT_GUILight/CMakeLists.txt | 1 + .../SALOME_PYQT_ModuleLight.cxx | 24 +++++- .../SALOME_PYQT_ModuleLight.h | 3 + .../SALOME_PYQT_PyModule.cxx | 62 ++++++++++++++ .../SALOME_PYQT_PyModule.h | 3 + src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 83 +++++++++++++++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 15 ++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 14 ++++ 8 files changed, 204 insertions(+), 1 deletion(-) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt b/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt index 9e62e7428..3247ef9bf 100755 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt @@ -41,6 +41,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/STD ${PROJECT_SOURCE_DIR}/src/SUIT ${PROJECT_SOURCE_DIR}/src/SUITApp + ${PROJECT_SOURCE_DIR}/src/ObjBrowser ) # additional preprocessor / compiler flags diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index 886022377..80f2e6a71 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -27,7 +27,8 @@ #include "CAM_Application.h" #include "SUITApp_init_python.hxx" #include "SUIT_DataObjectIterator.h" - +#include "LightApp_Application.h" +#include "SUIT_DataBrowser.h" #include "sipAPISalomePyQtGUILight.h" #ifndef GUI_DISABLE_CORBA @@ -141,6 +142,11 @@ void SALOME_PYQT_ModuleLight::initialize( CAM_Application* app ) // ... then call helper myHelper->initialize( app ); + SUIT_DataBrowser* ob = getApp()->objectBrowser(); + if (ob && ob->model()) { + connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), + myHelper, SLOT( onObjectBrowserClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection ); + } } /*! @@ -467,6 +473,22 @@ QColor SALOME_PYQT_ModuleLight::getColor( const QString& entry ) const return color; } +void SALOME_PYQT_ModuleLight::setObjectPosition( const QString& theEntry, int thePos ) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject( theEntry ); + if ( dataObj ) + dataObj->setPosition(thePos); +} + +int SALOME_PYQT_ModuleLight::getObjectPosition( const QString& theEntry ) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject( theEntry ); + if ( dataObj ) + return dataObj->position(); + return -1; +} + + /*! \brief Set reference to another data object \param entry data object entry diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h index dff9b5963..a3aada321 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -92,6 +92,9 @@ public: void removeObject( const QString& ); void removeChildren( const QString& ); + void setObjectPosition( const QString&, int ); + int getObjectPosition( const QString& ); + QStringList getChildren( const QString&, const bool = false ) const; protected: diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index b4eba060a..a7b79f9b0 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -2708,3 +2708,65 @@ void PyModuleHelper::connectView( SUIT_ViewWindow* view ) Qt::UniqueConnection ); } } + + + +void PyModuleHelper::internalOBClickedPython( const QString& theObj, int theColumn) +{ + FuncMsg fmsg( "--- PyModuleHelper::internalOBClickedPython()" ); + + // Python interpreter should be initialized and Python module should be + // import first + if ( !myInterp || !myPyModule ) + return; // Error + + if ( PyObject_HasAttrString( myPyModule, (char*)"onObjectBrowserClicked" ) ) { + PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"onObjectBrowserClicked", (char*)"si", theObj.toLatin1().constData(), theColumn ) ); + if( !res ) { + PyErr_Print(); + } + } +} + + + +void PyModuleHelper::onObjectBrowserClicked(SUIT_DataObject* theObj, int theColumn) +{ + FuncMsg fmsg( "PyModuleHelper::onObjectBrowserClicked()" ); + + // temporary set myInitModule because dumpPython() method + // might be called by the framework when this module is inactive, + // but still it should be possible to access this module's data + // from Python + InitLocker lock( myModule ); + + class PythonReq: public PyInterp_LockRequest + { + public: + PythonReq( PyInterp_Interp* _py_interp, + PyModuleHelper* _helper, + const QString& _entry, + int _column ) + : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) + myHelper( _helper ) , + myEntry( _entry ), + myColumn( _column ) + {} + protected: + virtual void execute() + { + myHelper->internalOBClickedPython( myEntry, myColumn ); + } + private: + PyModuleHelper* myHelper; + int myColumn; + QString myEntry; + }; + + // Posting the request only if dispatcher is not busy! + // Executing the request synchronously + const LightApp_DataObject* data_object = dynamic_cast( theObj ); + if ( (!PyInterp_Dispatcher::Get()->IsBusy()) && data_object ) + PyInterp_Dispatcher::Get()->Exec( new PythonReq( myInterp, this, data_object->entry(), theColumn ) ); +} + diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h index 49c429632..35d388726 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h @@ -106,6 +106,8 @@ public slots: const int, Qt::DropAction ); QString engineIOR() const; + void onObjectBrowserClicked(SUIT_DataObject*, int); + private: void initInterp( int ); void importModule(); @@ -133,6 +135,7 @@ private: void internalDropObjects( const DataObjectList&, SUIT_DataObject*, const int, Qt::DropAction ); QString internalEngineIOR() const; + void internalOBClickedPython( const QString&, int ); void connectView( SUIT_ViewWindow* ); }; diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 6866f472a..286ad4cd6 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -3822,3 +3822,86 @@ void SalomePyQt::setPlot2dFitRange(const int id, const double XMin, const double { ProcessVoidEvent( new TPlot2dFitRange(id, XMin, XMax, YMin, YMax) ); } + + +void SalomePyQt::setVisibilityState( const QString& theEntry, VisibilityState theState) +{ + class TEvent: public SALOME_Event + { + QString myEntry; + int myState; + public: + TEvent( const QString& theEntry, int theState): + myEntry(theEntry), myState(theState) {} + virtual void Execute() + { + LightApp_Study* aStudy = getActiveStudy(); + if ( !aStudy ) + return; + aStudy->setVisibilityState(myEntry, (Qtx::VisibilityState)myState); + } + }; + ProcessVoidEvent( new TEvent(theEntry, theState ) ); +} + +class TGetVisibilityStateEvent: public SALOME_Event +{ +public: + typedef int TResult; + TResult myResult; + QString myEntry; + TGetVisibilityStateEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {} + virtual void Execute() + { + LightApp_Study* aStudy = getActiveStudy(); + if ( aStudy ) + myResult = aStudy->visibilityState(myEntry); + } +}; + +VisibilityState SalomePyQt::getVisibilityState( const QString& theEntry ) +{ + return (VisibilityState) ProcessEvent( new TGetVisibilityStateEvent(theEntry) ); +} + + +void SalomePyQt::setObjectPosition( const QString& theEntry, int thePos ) +{ + class TEvent: public SALOME_Event + { + QString myEntry; + int myPos; + public: + TEvent( const QString& theEntry, int thePos): + myEntry(theEntry), myPos(thePos) {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = dynamic_cast( getActiveModule() ); + if ( module ) + module->setObjectPosition(myEntry, myPos ); + } + }; + ProcessVoidEvent( new TEvent(theEntry, thePos ) ); +} + + + +class TGetObjectPositionEvent: public SALOME_Event +{ +public: + typedef int TResult; + TResult myResult; + QString myEntry; + TGetObjectPositionEvent(const QString& theEntry) : myResult( 0 ), myEntry(theEntry) {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = dynamic_cast( getActiveModule() ); + if ( module ) + myResult = module->getObjectPosition(myEntry); + } +}; + +int SalomePyQt::getObjectPosition( const QString& theEntry ) +{ + return ProcessEvent( new TGetObjectPositionEvent(theEntry) ); +} diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 9f7247fb0..9df13706c 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -129,6 +129,14 @@ enum ObjectType Y2Axis = Plot2d_ViewFrame::Y2Axis }; +enum VisibilityState +{ + ShownState, //!< Object is shown in viewer + HiddenState, //!< Object is hidden in viewer + UnpresentableState //!< Unpresentable object +}; + + class SalomePyQt { public: @@ -165,6 +173,13 @@ public: static QString getName( const QString& ); static QString getToolTip( const QString& ); + static void setVisibilityState( const QString&, VisibilityState ); + static VisibilityState getVisibilityState( const QString& ); + + static void setObjectPosition( const QString&, int ); + static int getObjectPosition( const QString& ); + + static void setColor( const QString&, const QColor& ); static QColor getColor( const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 431dad6e9..136881846 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -251,6 +251,14 @@ public: void clearAllPoints(); }; +enum VisibilityState +{ + ShownState, + HiddenState, + UnpresentableState +}; + + class SalomePyQt { %TypeHeaderCode @@ -291,6 +299,12 @@ public: static QString getName(const QString& ) /ReleaseGIL/ ; static QString getToolTip(const QString& ) /ReleaseGIL/ ; + static void setVisibilityState( const QString&, VisibilityState ); + static VisibilityState getVisibilityState( const QString& ); + + static void setObjectPosition( const QString&, int ); + static int getObjectPosition( const QString& ); + static void setColor( const QString&, const QColor& ) /ReleaseGIL/ ; static QColor getColor( const QString& ) /ReleaseGIL/ ; -- 2.39.2