]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix #2198 ExportToGeom's shape stream not being dump by GEOM RestoreShape cbr/fix_export_to_geom_dump
authorChristophe Bourcier <christophe.bourcier@cea.fr>
Tue, 11 Jul 2017 12:09:52 +0000 (14:09 +0200)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Tue, 11 Jul 2017 12:09:52 +0000 (14:09 +0200)
src/ConnectorPlugin/CMakeLists.txt
src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py
src/ConnectorPlugin/ShapeUtilities.py [new file with mode: 0644]
src/PythonAPI/model/__init__.py

index 20012fb1ee8a3ed97855016777bf27962980e293..77063b06d7c7c24a09f8f9e1870c8c9a8edc3abf 100644 (file)
@@ -3,6 +3,7 @@ INCLUDE(Common)
 SET(PYTHON_FILES
     ConnectorPlugin.py
     ConnectorPlugin_ExportFeature.py
+    ShapeUtilities.py
 )
 
 SET(XML_RESOURCES
index 7902a8dddcc86b6895a943d8d2c79abc3e0e4013..8bf882cb74c109f190f3f5898978f04b24513ade 100644 (file)
@@ -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 (file)
index 0000000..1f478d2
--- /dev/null
@@ -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
index 29364c692b38edf4074740ddaec6a2129bd1ce8b..fd2acaf1909cffb4cfea3778278954cf826b1194 100644 (file)
@@ -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