From beef7bb17d18a9b3e8510d58bba8dbf6064242c2 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 17 Dec 2019 14:37:44 +0300 Subject: [PATCH] Correct work with shapes and SObjects --- idl/SHAPERSTUDY_Gen.idl | 13 +++++++++++-- src/PY/SHAPERSTUDY.py | 18 ++++++++++++++++-- src/PY/SHAPERSTUDY_Object.py | 30 ++++++++++++++++++++++++------ src/StudyData/StudyData_Object.cpp | 20 ++++++++++++++++++++ src/StudyData/StudyData_Object.h | 10 +++++++++- 5 files changed, 80 insertions(+), 11 deletions(-) diff --git a/idl/SHAPERSTUDY_Gen.idl b/idl/SHAPERSTUDY_Gen.idl index 7705f39..9e7824d 100644 --- a/idl/SHAPERSTUDY_Gen.idl +++ b/idl/SHAPERSTUDY_Gen.idl @@ -40,14 +40,23 @@ interface SHAPER_Object : GEOM::GEOM_Object * \brief Sets the internal entry of the object, common for all objects in SHAPER-STUDY */ void SetEntry( in string theInternalEntry ); + /*! + * \brief Sets SObject of this object (when it is published) + */ + void SetSO( in SALOMEDS::SObject theInternalEntry ); + /*! + * \brief Returns SObject of this object + */ + SALOMEDS::SObject GetSO(); + }; interface Gen : GEOM::GEOM_Gen { /*! - * \brief Creates a SHAPERSTUDY_Object to interact with SHAPER + * \brief Searches existing or creates a new SHAPERSTUDY_Object to interact with SHAPER */ - SHAPER_Object CreateShape(in string theInternalEntry); + SHAPER_Object FindOrCreateShape(in string theInternalEntry); }; interface IShapesOperations : GEOM::GEOM_IShapesOperations diff --git a/src/PY/SHAPERSTUDY.py b/src/PY/SHAPERSTUDY.py index 32c9732..74fddcf 100644 --- a/src/PY/SHAPERSTUDY.py +++ b/src/PY/SHAPERSTUDY.py @@ -21,6 +21,7 @@ # import SHAPERSTUDY_ORB__POA +import SHAPERSTUDY_ORB import SALOME_ComponentPy import SALOME_DriverPy import SALOMEDS @@ -53,10 +54,22 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen, # pass - def CreateShape( self, theInternalEntry ): + def FindOrCreateShape( self, theInternalEntry ): """ - Creates a SHAPERSTUDY_Object to interact with SHAPER + Searches existing or creates a new SHAPERSTUDY_Object to interact with SHAPER """ + # Searching in the study tree + aComponent = findOrCreateComponent() + aSOIter = getStudy().NewChildIterator(aComponent) + while aSOIter.More(): + aSO = aSOIter.Value() + anIOR = aSO.GetIOR() + anObj = salome.orb.string_to_object(anIOR) + if isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object): + if anObj.GetEntry() == theInternalEntry: + return anObj + aSOIter.Next() + aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object() aShapeObj.SetEntry(theInternalEntry) return aShapeObj._this() @@ -76,6 +89,7 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen, if theObject: anIOR = salome.orb.object_to_string(theObject) aResultSO.SetAttrString("AttributeIOR", anIOR) + theObject.SetSO(aResultSO) return aResultSO diff --git a/src/PY/SHAPERSTUDY_Object.py b/src/PY/SHAPERSTUDY_Object.py index 43c5ca3..968151d 100644 --- a/src/PY/SHAPERSTUDY_Object.py +++ b/src/PY/SHAPERSTUDY_Object.py @@ -31,6 +31,8 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): Construct an instance of SHAPERSTUDY Object. """ def __init__ ( self, *args): + self.SO = None + self.data = None pass def GetShapeType( self ): @@ -80,7 +82,10 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): """ Sets geometric shape content of the object as a byte stream in BRep format """ - self.data = StudyData_Swig.StudyData_Object(theStream) + if self.data: + self.data.updateShape(theStream) + else: + self.data = StudyData_Swig.StudyData_Object(theStream) """ Methods from BaseObject @@ -89,7 +94,7 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): """ Get name of the object associated with this object. """ - return "" + return self.SO.GetName() def SetEntry( self, theInternalEntry ): """ @@ -111,18 +116,19 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): # 1 corresponds to the Import feature (GEOMImpl_Types.hxx ) return 1 - # TODO: version number of the shape def GetTick( self ): """ Get value of a modification counter of the object """ - return 1 + if self.data: + return self.data.getTick() + return 0 def GetStudyEntry( self ): """ Get a Study entry where this object was published. """ - return '0:0:0:1' + return self.SO.GetID() def IsShape( self ): """ @@ -135,7 +141,7 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): """ Return true if passed object is identical to this object """ - return False + return self.GetType() == other.GetType() and self.GetEntry() == other.GetEntry() def GetGen( self ): """ @@ -143,4 +149,16 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): """ return getEngine() + def SetSO( self, theSO ): + """ + Sets SObject of this object (when it is published) + """ + self.SO = theSO + + def GetSO( self ): + """ + Returns SObject of this object + """ + return self.SO + pass diff --git a/src/StudyData/StudyData_Object.cpp b/src/StudyData/StudyData_Object.cpp index 87c7e80..4455da4 100644 --- a/src/StudyData/StudyData_Object.cpp +++ b/src/StudyData/StudyData_Object.cpp @@ -24,12 +24,15 @@ #include #include +#include StudyData_Object::StudyData_Object(const std::string theFile) { std::istringstream streamBrep(theFile.c_str()); BRep_Builder aBuilder; BRepTools::Read(myShape, streamBrep, aBuilder); + myTick = 1; + myStream = theFile; } @@ -71,3 +74,20 @@ CORBA::LongLong StudyData_Object::shape() const return ((CORBA::LongLong)(&myShape)); } +void StudyData_Object::updateShape(const std::string theFile) +{ + if (myStream == theFile) { // absolutely identical shapes, no need to store + return; + } + // update the current shape + std::istringstream streamBrep(theFile.c_str()); + BRep_Builder aBuilder; + BRepTools::Read(myShape, streamBrep, aBuilder); + myTick++; + myStream = theFile; +} + +int StudyData_Object::getTick() +{ + return myTick; +} diff --git a/src/StudyData/StudyData_Object.h b/src/StudyData/StudyData_Object.h index 22bc293..fa711dc 100644 --- a/src/StudyData/StudyData_Object.h +++ b/src/StudyData/StudyData_Object.h @@ -40,8 +40,16 @@ public: CORBA::LongLong shape() const; + // updates the current shape if needed + void updateShape(const std::string theFile); + + // returns the version number of the shape starting from 1 + int getTick(); + private: - TopoDS_Shape myShape; + std::string myStream; // the current stream of a shape + TopoDS_Shape myShape; // latest shape of this object + int myTick; // version index of the shape }; #endif // !StudyData_Object_H -- 2.39.2