From 49ddf5381f07758876d1b965383dec3c2729b875 Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Tue, 11 Jul 2017 14:09:52 +0200 Subject: [PATCH] Fix #2198 ExportToGeom's shape stream not being dump by GEOM RestoreShape --- src/ConnectorPlugin/CMakeLists.txt | 1 + .../ConnectorPlugin_ExportFeature.py | 44 +++++++------------ src/ConnectorPlugin/ShapeUtilities.py | 37 ++++++++++++++++ src/PythonAPI/model/__init__.py | 3 ++ 4 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 src/ConnectorPlugin/ShapeUtilities.py 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 -- 2.39.2