Salome HOME
Issue #2309 Possibility to hide faces: using COMPOUND instead of SHELL of faces insid...
authornds <nds@opencascade.com>
Wed, 13 Dec 2017 08:07:34 +0000 (11:07 +0300)
committernds <nds@opencascade.com>
Wed, 13 Dec 2017 08:08:14 +0000 (11:08 +0300)
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h

index ad9ca2febdeae5b830ca78d4ee4c119f4215015a..33708cb51f16de8a56b586912d07040e9e63a297 100755 (executable)
@@ -36,6 +36,7 @@
 #include <AIS_ColoredDrawer.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Selection.hxx>
+#include <BOPTools_AlgoTools3D.hxx>
 #include <BRep_Builder.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <Prs3d_Drawer.hxx>
@@ -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<TopoDS_Shape> 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<TopoDS_Shape>& 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)
index 642beb8fbf090ca2b52899c05f614cf06de49cc1..3fb1e1906b2e3a8fde1645e035e1068caed99301 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <ModelAPI_Result.h>
 
+#include <BRep_Builder.hxx>
 #include <NCollection_List.hxx>
 #include <ViewerData_AISShape.hxx>
 #include <Standard_DefineHandle.hxx>
@@ -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<TopoDS_Shape>& theHiddenSubShapes);
+
+private:
   /// Reference to result object
   ResultPtr myResult;