Salome HOME
Correct work with shapes and SObjects
authormpv <mpv@opencascade.com>
Tue, 17 Dec 2019 11:38:15 +0000 (14:38 +0300)
committermpv <mpv@opencascade.com>
Tue, 17 Dec 2019 11:38:33 +0000 (14:38 +0300)
src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h

index 45a1aed6c23eaab732c6d9f54742f90a43a23a89..a21dca2c6c317288a7f89acb3f9db173052bb1e4 100644 (file)
@@ -84,6 +84,7 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
             print("Found a result to publish ", aRes.data().name())
             aResFeatureId = aPartDoc.feature(aRes).data().featureId()
             aSSEntry = str(aPartFeatureId) + ":" + str(aResFeatureId)
-            aSShape = anEngine.CreateShape(aSSEntry)
-            aSShape.SetShapeByStream(aRes.shape().getShapeStream())
-            anEngine.AddInStudy(aSShape, aRes.data().name(), None)
+            aSShape = anEngine.FindOrCreateShape(aSSEntry)
+            aSShape.SetShapeByStream(aRes.shape().getShapeStream(False))
+            if not aSShape.GetSO(): # publish in case it is a new shape
+              anEngine.AddInStudy(aSShape, aRes.data().name(), None)
index a0c9061d78a4f1a7cf0eea160ce47db96f211fbc..60ca800a3d03c75c06a90a647fa4cfb8a0c9df71 100644 (file)
@@ -32,6 +32,7 @@
 #include <BRepAlgoAPI_Section.hxx>
 #include <BRepBndLib.hxx>
 #include <BRepBuilderAPI_FindPlane.hxx>
+#include <BRepBuilderAPI_Copy.hxx>
 #include <BRepExtrema_DistShapeShape.hxx>
 #include <BRepTools.hxx>
 #include <Bnd_Box.hxx>
@@ -638,11 +639,17 @@ GeomPointPtr GeomAPI_Shape::middlePoint() const
 }
 
 // LCOV_EXCL_START
-std::string GeomAPI_Shape::getShapeStream() const
+std::string GeomAPI_Shape::getShapeStream(const bool theWithTriangulation) const
 {
   std::ostringstream aStream;
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
-  BRepTools::Write(aShape, aStream);
+  if (!theWithTriangulation) { // make a copy of shape without triangulation
+    BRepBuilderAPI_Copy aCopy(aShape, Standard_False, Standard_False);
+    const TopoDS_Shape& aCopyShape = aCopy.Shape();
+    BRepTools::Write(aCopyShape, aStream);
+  } else {
+    BRepTools::Write(aShape, aStream);
+  }
   return aStream.str();
 }
 // LCOV_EXCL_STOP
index 7c3a2a6cc513ca93e36928b5067f86f6042ac2c8..34887d85f3aaa3b85b14d641b4a3b8e844ba9e61 100644 (file)
@@ -192,7 +192,7 @@ public:
 
   /// Returns the shape as BRep stream
   GEOMAPI_EXPORT
-  std::string getShapeStream() const;
+  std::string getShapeStream(const bool theWithTriangulation = true) const;
 
   /// Returns intersection of shapes
   GEOMAPI_EXPORT