From c0349c853020bfbe45aebac03584584781fa936f Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 27 Jan 2014 09:01:41 +0000 Subject: [PATCH] PPGP patch --- .../SALOME_PYQT_GUILight/CMakeLists.txt | 1 + .../SALOME_PYQT_ModuleLight.cxx | 24 +++++- .../SALOME_PYQT_ModuleLight.h | 3 + .../SALOME_PYQT_PyModule.cxx | 68 ++++++++++++++- .../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 ++++ src/SUIT/SUIT_DataObject.cxx | 29 +++++++ src/SUIT/SUIT_DataObject.h | 2 + src/SalomeApp/SalomeApp_Application.cxx | 2 +- 11 files changed, 239 insertions(+), 5 deletions(-) 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..0e0df09d2 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -165,15 +165,15 @@ public: FuncMsg( const QString& funcName ) { myName = funcName; - MESSAGE( qPrintable( myName ) << " [ begin ]" ); + //MESSAGE( qPrintable( myName ) << " [ begin ]" ); } ~FuncMsg() { - MESSAGE( qPrintable( myName ) << " [ end ]" ); + //MESSAGE( qPrintable( myName ) << " [ end ]" ); } void message( const QString& msg ) { - MESSAGE( qPrintable( myName ) << " : " << qPrintable( msg ) ); + //MESSAGE( qPrintable( myName ) << " : " << qPrintable( msg ) ); } private: QString myName; @@ -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/ ; diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index dd7c09e83..182f5eb49 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -138,6 +138,25 @@ int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const return myChildren.indexOf( (SUIT_DataObject*)obj ); } +/*! + \brief Moves the child position from current to new one. + \param theObj child object + \param theNewPos child objectnew position in the children list + +*/ +void SUIT_DataObject::moveChildPos( SUIT_DataObject* theObj, int theNewPos) +{ + if (myChildren.size() <= 1) return; + + int aNewPos = theNewPos; + if (aNewPos < 0) aNewPos = 0; + if (aNewPos > (myChildren.size() - 1)) aNewPos = myChildren.size() - 1; + + if (myChildren.removeOne(theObj)) + myChildren.insert(aNewPos, theObj); +} + + /*! \brief Get child object by the specified index. \param idx child object index @@ -180,6 +199,16 @@ int SUIT_DataObject::position() const return myParent ? myParent->childPos( this ) : 0; } +/*! + \brief Sets new position of the object in parent's list +*/ +void SUIT_DataObject::setPosition(int theNewPos) +{ + if (theNewPos == position()) return; + if (!myParent) return; + myParent->moveChildPos(this, theNewPos); +} + /*! \brief Get the next sibling data object in the children list. \return child object or 0 if there is no next sibling diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index ab44bbdbe..b5f62d986 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -76,9 +76,11 @@ public: int childCount() const; int childPos( const SUIT_DataObject* ) const; + void moveChildPos( SUIT_DataObject*, int ); SUIT_DataObject* childObject( const int ) const; int level() const; int position() const; + void setPosition(int); SUIT_DataObject* nextBrother() const; SUIT_DataObject* prevBrother() const; diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index c7b16a8ae..5d9b14d17 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1864,8 +1864,8 @@ void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, else anObjState = Qtx::HiddenState; } + aStudy->setVisibilityState( obj->entry(), anObjState ); // Do not change modules without displayer } - aStudy->setVisibilityState( obj->entry(), anObjState ); } } } -- 2.39.2