From acac44d571c379b974e609ab8376ab3fb38f992e Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Tue, 5 Jul 2022 16:10:36 +0300 Subject: [PATCH] 0033053: Data Exchange, Step Export - Compound with vertex is ignored Fixed problem with deep compound including with vertex group. --- src/STEPControl/STEPControl_ActorWrite.cxx | 100 +++++++++++++++------ src/STEPControl/STEPControl_ActorWrite.hxx | 9 ++ tests/bugs/step/bug33053 | 23 +++++ 3 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 tests/bugs/step/bug33053 diff --git a/src/STEPControl/STEPControl_ActorWrite.cxx b/src/STEPControl/STEPControl_ActorWrite.cxx index 69dc9db8a3..6b0706c9fe 100644 --- a/src/STEPControl/STEPControl_ActorWrite.cxx +++ b/src/STEPControl/STEPControl_ActorWrite.cxx @@ -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); diff --git a/src/STEPControl/STEPControl_ActorWrite.hxx b/src/STEPControl/STEPControl_ActorWrite.hxx index accdf962b8..d9d09b20d2 100644 --- a/src/STEPControl/STEPControl_ActorWrite.hxx +++ b/src/STEPControl/STEPControl_ActorWrite.hxx @@ -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 index 0000000000..edf34e1257 --- /dev/null +++ b/tests/bugs/step/bug33053 @@ -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]