From d8caff675dd6bbc1461c222595023e8515f9e406 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 13 Dec 2017 11:07:34 +0300 Subject: [PATCH] Issue #2309 Possibility to hide faces: using COMPOUND instead of SHELL of faces inside the presentation. --- src/ModuleBase/ModuleBase_ResultPrs.cpp | 76 ++++++++++++++++++------- src/ModuleBase/ModuleBase_ResultPrs.h | 13 +++++ 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index ad9ca2feb..33708cb51 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -146,16 +147,15 @@ bool ModuleBase_ResultPrs::hasSubShapeVisible(const TopoDS_Shape& theShape) if (!myHiddenSubShapes.Contains(theShape)) aNbOfHiddenSubShapes++; // the shape to be hidden later - TopExp_Explorer anExp(myOriginalShape, TopAbs_FACE); - bool aHasVisibleShape = false; - for(TopExp_Explorer anExp(myOriginalShape, TopAbs_FACE); anExp.More() && !aHasVisibleShape; - anExp.Next()) - { - aNbOfHiddenSubShapes--; - if (aNbOfHiddenSubShapes < 0) - aHasVisibleShape = true; - } - return aHasVisibleShape; + //const TopoDS_Shape aCurrentShape = Shape(); + NCollection_List aHiddenSubShapes = myHiddenSubShapes; + aHiddenSubShapes.Append(theShape); + + TopoDS_Compound aCompound; + BRep_Builder aBuilder; + aBuilder.MakeCompound (aCompound); + collectSubShapes(aBuilder, aCompound, myOriginalShape, aHiddenSubShapes); + return !BOPTools_AlgoTools3D::IsEmptyShape(aCompound); } //******************************************************************** @@ -184,17 +184,12 @@ void ModuleBase_ResultPrs::Compute( Set(myOriginalShape); } else { // convert shape into SHELL - TopoDS_Shell aShell; - BRep_Builder aShellBuilder; - aShellBuilder.MakeShell(aShell); - bool isEmptyShape = true; - for(TopExp_Explorer anExp(myOriginalShape, TopAbs_FACE); anExp.More(); anExp.Next()) { - if (myHiddenSubShapes.Contains(anExp.Current())) - continue; - aShellBuilder.Add(aShell, anExp.Current()); - isEmptyShape = false; - } - Set(aShell); + TopoDS_Compound aCompound; + BRep_Builder aBuilder; + aBuilder.MakeCompound (aCompound); + collectSubShapes(aBuilder, aCompound, myOriginalShape, myHiddenSubShapes); + bool isEmptyShape = BOPTools_AlgoTools3D::IsEmptyShape(aCompound); + Set(aCompound); if (isEmptyShape) aReadyToDisplay = false; } @@ -218,6 +213,45 @@ void ModuleBase_ResultPrs::Compute( } } +//******************************************************************** +void ModuleBase_ResultPrs::collectSubShapes(BRep_Builder& theBuilder, + TopoDS_Shape& theCompound, const TopoDS_Shape& theShape, + const NCollection_List& theHiddenSubShapes) +{ + switch (theShape.ShapeType()) { + case TopAbs_COMPOUND: { + for (TopoDS_Iterator aChildIter (theShape); aChildIter.More(); aChildIter.Next()) + collectSubShapes(theBuilder, theCompound, aChildIter.Value(), theHiddenSubShapes); + } + break; + case TopAbs_SOLID: + case TopAbs_SHELL: { + for (TopExp_Explorer anExp (theShape, TopAbs_FACE); anExp.More(); anExp.Next()) { + collectSubShapes(theBuilder, theCompound, anExp.Current(), theHiddenSubShapes); + } + } + break; + case TopAbs_WIRE: { + for (TopExp_Explorer anExp (theShape, TopAbs_EDGE); anExp.More(); anExp.Next()) { + collectSubShapes(theBuilder, theCompound, anExp.Current(), theHiddenSubShapes); + } + } + break; + case TopAbs_FACE: { + if (theHiddenSubShapes.Contains(theShape)) + return; // remove hidden shape + theBuilder.Add(theCompound, theShape); + } + break; + case TopAbs_EDGE: + case TopAbs_VERTEX: { + theBuilder.Add(theCompound, theShape); + } + default: + break; + } +} + //******************************************************************** void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer theMode) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index 642beb8fb..3fb1e1906 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -124,6 +125,18 @@ private: bool appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer theMode); + /// Creates compound of vertices, edges and faces. + /// If the shape is COMPOUND, iterate by sub-shapes. + /// If the shape is SOLID/SHEL, explore shape by FACES, + /// If the shape is WIRE, explore shape by EDGES + /// \param theBuilder result compound builder + /// \param theCompound the result shape + /// \param theShape the processed shape + /// \param theHiddenSubShapes container of shapes to be skipped (faces) + void collectSubShapes(BRep_Builder& theBuilder, TopoDS_Shape& theCompound, + const TopoDS_Shape& theShape, const NCollection_List& theHiddenSubShapes); + +private: /// Reference to result object ResultPtr myResult; -- 2.30.2