From: Christophe Bourcier Date: Tue, 11 Jul 2017 12:09:52 +0000 (+0200) Subject: Fix #2198 ExportToGeom's shape stream not being dump by GEOM RestoreShape X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=49ddf5381f07758876d1b965383dec3c2729b875;p=modules%2Fshaper.git Fix #2198 ExportToGeom's shape stream not being dump by GEOM RestoreShape --- diff --git a/src/ConnectorPlugin/CMakeLists.txt b/src/ConnectorPlugin/CMakeLists.txt index 20012fb1e..77063b06d 100644 --- a/src/ConnectorPlugin/CMakeLists.txt +++ b/src/ConnectorPlugin/CMakeLists.txt @@ -3,6 +3,7 @@ INCLUDE(Common) SET(PYTHON_FILES ConnectorPlugin.py ConnectorPlugin_ExportFeature.py + ShapeUtilities.py ) SET(XML_RESOURCES diff --git a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py index 7902a8ddd..8bf882cb7 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py @@ -1,3 +1,4 @@ + ## @package Plugins # ExportFeature class definition # Copyright (C) 2014-20xx CEA/DEN, EDF R&D @@ -6,6 +7,7 @@ import EventsAPI import ModelAPI import GeomAPI import GeomAlgoAPI +import ShapeUtilities import salome from salome.geom import geomBuilder @@ -51,36 +53,20 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): ## Exports all bodies def exportBodies(self): - global ShapeIndex - kResultBodyType = "Bodies" - aPartSize = self.Part.size(kResultBodyType) - if aPartSize == 0: - EventsAPI.Events_InfoMessage("ExportFeature","No results in the active document").send() - return - - anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)] - aShapesList = GeomAlgoAPI.ShapeList() - aName = "" - for idx, anObject in enumerate(anObjList): - aResult = ModelAPI.modelAPI_Result(anObject) - aBodyResult = ModelAPI.modelAPI_ResultBody(aResult) - if not aBodyResult: - continue - aShape = aBodyResult.shape() - if aShape is not None and not aShape.isNull(): - aShapesList.append(aShape) - if len(aShapesList) == 1: - aName = aBodyResult.data().name() - - # issue 1045: create compound if there are more than one shape - if len(aShapesList) > 1: - self.shape = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.compound(aShapesList) - aName = "ShaperResults" - elif len(aShapesList) == 1: - self.shape = aShapesList[0] - - # so, only one shape is always in the result + self.shape = ShapeUtilities.makeShape(self.Part) + + aName = self.shape.name + + # only one shape is always in the result aDump = self.shape.getShapeStream() + + # guess the name of the dumped part objet + partName = "Part_%i"%self.Part.id() + + # add the information that the stream comes from Shaper to make specific dump in GEOM + firstLine = "FromShaperExportToGeom;" + partName + aDump = firstLine + aDump + # Load shape to SALOME Geom aBrep = self.geompy.RestoreShape(aDump) diff --git a/src/ConnectorPlugin/ShapeUtilities.py b/src/ConnectorPlugin/ShapeUtilities.py new file mode 100644 index 000000000..1f478d216 --- /dev/null +++ b/src/ConnectorPlugin/ShapeUtilities.py @@ -0,0 +1,37 @@ +import EventsAPI +import ModelAPI +import GeomAlgoAPI + +## Make the shape from the part +# Utility function used in Shaper's ExportToGeom and Geom's RestoreShape +def makeShape(aPart): + kResultBodyType = "Bodies" + aPartSize = aPart.size(kResultBodyType) + if aPartSize == 0: + EventsAPI.Events_InfoMessage("ExportFeature","No results in the active document").send() + return + + anObjList = [aPart.object(kResultBodyType, idx) for idx in xrange(aPartSize)] + aShapesList = GeomAlgoAPI.ShapeList() + aName = "" + for idx, anObject in enumerate(anObjList): + aResult = ModelAPI.modelAPI_Result(anObject) + aBodyResult = ModelAPI.modelAPI_ResultBody(aResult) + if not aBodyResult: + continue + aShape = aBodyResult.shape() + if aShape is not None and not aShape.isNull(): + aShapesList.append(aShape) + if len(aShapesList) == 1: + aName = aBodyResult.data().name() + + # issue 1045: create compound if there are more than one shape + if len(aShapesList) > 1: + aShape = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.compound(aShapesList) + aName = "ShaperResults" + elif len(aShapesList) == 1: + aShape = aShapesList[0] + + aShape.name = aName + + return aShape \ No newline at end of file diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 29364c692..fd2acaf19 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -25,3 +25,6 @@ from partset import * from primitives import * from gdml import * from tests import * + +# Other utilities +from ShapeUtilities import makeShape \ No newline at end of file