From 0753cb5ab5f31f03ec671975de920a81653f637b Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 10 Dec 2019 17:39:15 +0300 Subject: [PATCH] Initial support of publication of shapes --- idl/SHAPERSTUDY_Gen.idl | 14 ++++++--- src/PY/SHAPERSTUDY.py | 48 +++++++++++------------------- src/PY/SHAPERSTUDY_Object.py | 6 ++++ src/PY/SHAPERSTUDY_utils.py | 2 +- src/SWIG/StudyData_Swig.i | 2 ++ src/StudyData/StudyData_Object.cpp | 7 ++--- src/StudyData/StudyData_Object.h | 2 +- 7 files changed, 40 insertions(+), 41 deletions(-) diff --git a/idl/SHAPERSTUDY_Gen.idl b/idl/SHAPERSTUDY_Gen.idl index e5a3d56..de63919 100644 --- a/idl/SHAPERSTUDY_Gen.idl +++ b/idl/SHAPERSTUDY_Gen.idl @@ -29,8 +29,18 @@ module SHAPERSTUDY_ORB { + +interface SHAPER_Object : GEOM::GEOM_Object +{ + void SetShapeByStream(in string theStream); +}; + interface Gen : GEOM::GEOM_Gen { + /*! + * \brief Creates a SHAPERSTUDY_Object to interact with SHAPER + */ + SHAPER_Object CreateShape(); }; interface IShapesOperations : GEOM::GEOM_IShapesOperations @@ -53,10 +63,6 @@ interface BaseObject : GEOM::GEOM_BaseObject { }; -interface SHAPER_Object : GEOM::GEOM_Object -{ -}; - interface Field : GEOM::GEOM_Field { }; diff --git a/src/PY/SHAPERSTUDY.py b/src/PY/SHAPERSTUDY.py index 6730fb2..b01781a 100644 --- a/src/PY/SHAPERSTUDY.py +++ b/src/PY/SHAPERSTUDY.py @@ -25,6 +25,8 @@ import SALOME_ComponentPy import SALOME_DriverPy import SALOMEDS from SHAPERSTUDY_utils import findOrCreateComponent, moduleName, getStudy, getORB +import salome +import SHAPERSTUDY_Object __entry2IOR__ = {} @@ -51,11 +53,11 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen, # pass - def publish( self, theShaperObj ): + def CreateShape( self ): """ - Publish GEOM_Object corresponding to a given SHAPER object + Creates a SHAPERSTUDY_Object to interact with SHAPER """ - return SHAPERSTUDY_Object() + return SHAPERSTUDY_Object.SHAPERSTUDY_Object()._this() def AddInStudy( self, theObject, theName, theFather ): """ @@ -63,8 +65,17 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen, if theFather is not NULL the object is placed under theFather's SObject. Returns a SObject where theObject is placed """ - so = SALOMEDS.SALOMEDS_SObject() - return so + aStudy = getStudy() + aBuilder = aStudy.NewBuilder() + if not theFather: + theFather = findOrCreateComponent() + aResultSO = aBuilder.NewObject(theFather); + aResultSO.SetAttrString("AttributeName", theName) + if theObject: + anIOR = salome.orb.object_to_string(theObject) + aResultSO.SetAttrString("AttributeIOR", anIOR) + + return aResultSO def AddSubShape( theMainShape, theIndices ): """ @@ -124,7 +135,8 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen, Parameters: theStudyEntry is an entry of the Object in the study """ - return "" + print("My Test") + return "test" def Save( self, component, URL, isMultiFile ): @@ -265,27 +277,3 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen, Adds to the group all the given shapes. No errors, if some shapes are already included. """ return GetIGroupOperations().UnionList( theGroup, theSubShapes ) - - def addToStudy( self, aShape, aName ): - """ - Publish in study aShape with name aName - """ - try: - so = self.AddInStudy(aShape, aName, None ) - if so and aName: so.SetAttrString("AttributeName", aName) - except: - print("addToStudyInFather() failed") - return "" - return so.GetStudyEntry() - - def addToStudyInFather(self, aFather, aShape, aName): - """ - Publish in study aShape with name aName as sub-object of previously published aFather - """ - try: - so = self.AddInStudy(aShape, aName, aFather ) - if so and aName: so.SetAttrString("AttributeName", aName) - except: - print("addToStudyInFather() failed") - return "" - return so.GetStudyEntry() diff --git a/src/PY/SHAPERSTUDY_Object.py b/src/PY/SHAPERSTUDY_Object.py index 46eb7f1..4a8f400 100644 --- a/src/PY/SHAPERSTUDY_Object.py +++ b/src/PY/SHAPERSTUDY_Object.py @@ -129,4 +129,10 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object): """ return ; + def SetShapeByStream(self, theStream): + """ + Sets geometric shape content of the object as a byte stream in BRep format + """ + return ; + pass diff --git a/src/PY/SHAPERSTUDY_utils.py b/src/PY/SHAPERSTUDY_utils.py index 1ef1a03..0cf33c6 100644 --- a/src/PY/SHAPERSTUDY_utils.py +++ b/src/PY/SHAPERSTUDY_utils.py @@ -146,7 +146,7 @@ def getEngineIOR(): ### def findOrCreateComponent(): study = getStudy() - father =study.FindComponent( moduleName() ) + father = study.FindComponent( moduleName() ) if father is None: builder = study.NewBuilder() father = builder.NewComponent( moduleName() ) diff --git a/src/SWIG/StudyData_Swig.i b/src/SWIG/StudyData_Swig.i index f74d9d1..93ce542 100644 --- a/src/SWIG/StudyData_Swig.i +++ b/src/SWIG/StudyData_Swig.i @@ -5,3 +5,5 @@ %{ #include "StudyData_Object.h" %} + +%include "StudyData_Object.h" diff --git a/src/StudyData/StudyData_Object.cpp b/src/StudyData/StudyData_Object.cpp index 31e4668..13e22dd 100644 --- a/src/StudyData/StudyData_Object.cpp +++ b/src/StudyData/StudyData_Object.cpp @@ -25,12 +25,9 @@ #include #include -StudyData_Object::StudyData_Object(SALOMEDS::TMPFile_var theFile) +StudyData_Object::StudyData_Object(const std::string theFile) { - int sizebuf = theFile->length(); - char* aBuf; - aBuf = (char*)&theFile[0]; - std::istringstream streamBrep(aBuf); + std::istringstream streamBrep(theFile.c_str()); BRep_Builder aBuilder; BRepTools::Read(myShape, streamBrep, aBuilder); } diff --git a/src/StudyData/StudyData_Object.h b/src/StudyData/StudyData_Object.h index 55e7866..d04d350 100644 --- a/src/StudyData/StudyData_Object.h +++ b/src/StudyData/StudyData_Object.h @@ -30,7 +30,7 @@ class StudyData_Object { public: - StudyData_Object(SALOMEDS::TMPFile_var theFile); + Standard_EXPORT StudyData_Object(const std::string theFile); private: -- 2.30.2