]> OCCT Git - occt.git/commitdiff
0033053: Data Exchange, Step Export - Compound with vertex is ignored IR-2022-08-26
authordpasukhi <dpasukhi@opencascade.com>
Tue, 5 Jul 2022 13:10:36 +0000 (16:10 +0300)
committersmoskvin <smoskvin@opencascade.com>
Fri, 26 Aug 2022 14:39:36 +0000 (17:39 +0300)
Fixed problem with deep compound including with vertex group.

src/STEPControl/STEPControl_ActorWrite.cxx
src/STEPControl/STEPControl_ActorWrite.hxx
tests/bugs/step/bug33053 [new file with mode: 0644]

index 69dc9db8a3cd5e1469efdb4b4f9e425ca1e8a69f..6b0706c9fec6f42e5169e7c5434a9a2217315628 100644 (file)
@@ -341,6 +341,43 @@ void STEPControl_ActorWrite::mergeInfoForNM(const Handle(Transfer_FinderProcess)
   }
 }
 
+//=======================================================================
+//function : separateShapeToSoloVertex
+//purpose  : 
+//=======================================================================
+Standard_Boolean STEPControl_ActorWrite::separateShapeToSoloVertex(const TopoDS_Shape& theShape,
+                                                                   TopTools_SequenceOfShape& theVertices)
+{
+  if (theShape.IsNull())
+  {
+    return Standard_False;
+  }
+  switch (theShape.ShapeType())
+  {
+    case TopAbs_COMPOUND:
+    {
+      for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next())
+      {
+        if (!separateShapeToSoloVertex(anIter.Value(), theVertices))
+        {
+          return Standard_False;
+        }
+      }
+      break;
+    }
+    case TopAbs_VERTEX:
+    {
+      theVertices.Append(theShape);
+      break;
+    }
+    default:
+    {
+      theVertices.Clear();
+      return Standard_False;
+    }
+  }
+  return Standard_True;
+}
 
 //=======================================================================
 //function : SetMode
@@ -814,42 +851,49 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape
 
   // create a list of items to translate
   Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
-  
-  Standard_Boolean isSeparateVertices = 
+
+  Standard_Boolean isSeparateVertices =
     Interface_Static::IVal("write.step.vertex.mode") == 0;//bug 23950
   // PTV 16.09.2002 OCC725 separate shape from solo vertices.
   Standard_Boolean isOnlyVertices = Standard_False;
-  if (theShape.ShapeType() == TopAbs_COMPOUND) {
-    Standard_Integer countVrtx = 0;
-    Standard_Integer countSh = 0;
+  if (theShape.ShapeType() == TopAbs_COMPOUND && isSeparateVertices)
+  {
     TopoDS_Compound aNewShape, aCompOfVrtx;
-    BRep_Builder aB;
-    aB.MakeCompound(aNewShape);
-    aB.MakeCompound(aCompOfVrtx);
-    TopoDS_Iterator anCompIt(theShape);
-    if (isSeparateVertices) {
-      for (; anCompIt.More(); anCompIt.Next()) {
-        TopoDS_Shape aCurSh = anCompIt.Value();
-        if (aCurSh.ShapeType() != TopAbs_VERTEX) {
-          aB.Add(aNewShape, aCurSh);
-          countSh++;
+    BRep_Builder aBuilder;
+    aBuilder.MakeCompound(aNewShape);
+    aBuilder.MakeCompound(aCompOfVrtx);
+    TopTools_SequenceOfShape aVertices;
+    isOnlyVertices = separateShapeToSoloVertex(theShape, aVertices);
+    if (!isOnlyVertices)
+    {
+      for (TopoDS_Iterator anCompIt(theShape); anCompIt.More(); anCompIt.Next())
+      {
+        const TopoDS_Shape& aCurSh = anCompIt.Value();
+        TopTools_SequenceOfShape aVerticesOfSubSh;
+        if (separateShapeToSoloVertex(aCurSh, aVerticesOfSubSh))
+        {
+          aVertices.Append(aVerticesOfSubSh);
         }
-        else {
-          aB.Add(aCompOfVrtx, aCurSh);
-          countVrtx++;
+        else
+        {
+          aBuilder.Add(aNewShape, aCurSh);
         }
       }
-      // replace the shapes
-      if (countSh)
-        theShape = aNewShape;
-      if (countVrtx)
-        RepItemSeq->Append(aCompOfVrtx);
-      if (countSh == 0) 
-        isOnlyVertices = Standard_True;
+      theShape = aNewShape;
     }
-  } 
-  
-  if (theShape.ShapeType() == TopAbs_COMPOUND) {
+    for (TopTools_HSequenceOfShape::Iterator anIterV(aVertices);
+         anIterV.More(); anIterV.Next())
+    {
+      aBuilder.Add(aCompOfVrtx, anIterV.Value());
+    }
+    if (!aVertices.IsEmpty())
+    {
+      RepItemSeq->Append(aCompOfVrtx);
+    }
+  }
+
+  if (theShape.ShapeType() == TopAbs_COMPOUND)
+  {
     TopExp_Explorer SolidExp, ShellExp, FaceExp;
     if (mymode != STEPControl_GeometricCurveSet) {
       for (SolidExp.Init(theShape, TopAbs_SOLID);
index accdf962b8e94f1e77d73cd84653684cd59e0cc8..d9d09b20d2410eacff49635a9b4c77125838924e 100644 (file)
@@ -117,6 +117,15 @@ private:
   //! bind already written shared faces to STEP entity for non-manifold
   Standard_EXPORT void mergeInfoForNM(const Handle(Transfer_FinderProcess)& theFP, const Handle(Standard_Transient) &theInfo) const;
 
+  //! Gets sequence of vertices of all compounds level by recursive
+  //! @param[in] theShape shape to iterate, checked for compound type and sub shapes vertex type
+  //! @param[out] theVertices sequence of found vertices via recursively iterate of shape
+  //! @return TRUE if one or more vertex was found and all shapes were compound or vertex
+  Standard_Boolean separateShapeToSoloVertex(const TopoDS_Shape& theShape,
+                                             TopTools_SequenceOfShape& theVertices);
+
+
+
   Standard_Integer mygroup;
   Standard_Real mytoler;
   STEPConstruct_ContextTool myContext;
diff --git a/tests/bugs/step/bug33053 b/tests/bugs/step/bug33053
new file mode 100644 (file)
index 0000000..edf34e1
--- /dev/null
@@ -0,0 +1,23 @@
+puts "===================================="
+puts "0033053: Data Exchange, Step Export - Compound with vertex is ignored"
+puts "===================================="
+puts ""
+
+pload OCAF
+
+Close D_orig -silent
+Close D_comp -silent
+
+ReadStep D_orig [locate_data_file bug33053_shapes_2d.stp]
+
+WriteStep D_orig $imagedir/${casename}_D.stp
+
+ReadStep D_comp $imagedir/${casename}_D.stp
+
+file delete $imagedir/${casename}_D.stp
+
+XGetOneShape orig D_orig
+XGetOneShape comp D_comp
+
+checkshape comp
+checknbshapes orig -ref [nbshapes comp]