]> OCCT Git - occt.git/commitdiff
0029067: Visualization, AIS_ColoredShape - visibility of sub-shapes is ignored by...
authorkgv <kgv@opencascade.com>
Mon, 28 Aug 2017 18:10:28 +0000 (21:10 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 30 Aug 2017 10:52:51 +0000 (13:52 +0300)
src/AIS/AIS_ColoredShape.cxx
src/AIS/AIS_ColoredShape.hxx
tests/bugs/xde/bug25381

index 9c528251ab36dca862df106acc0ba04f7cc5d67d..f3396308d0527e6b936b0741de89ca256c295582 100644 (file)
@@ -18,6 +18,7 @@
 #include <AIS_InteractiveContext.hxx>
 #include <BRep_Builder.hxx>
 #include <BRepTools.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
 #include <gp_Pnt2d.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_AspectLine3d.hxx>
@@ -35,6 +36,7 @@
 #include <Prs3d_Root.hxx>
 #include <PrsMgr_PresentationManager3d.hxx>
 #include <Standard_ErrorHandler.hxx>
+#include <StdSelect_BRepSelectionTool.hxx>
 #include <StdPrs_ShadedShape.hxx>
 #include <StdPrs_ToolTriangulatedShape.hxx>
 #include <StdPrs_WFShape.hxx>
@@ -384,66 +386,171 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
     Prs3d::GetDeflection (myshape, myDrawer);
   }
 
-  // Extract myShapeColors map (KeyshapeColored -> Color)
-  // to subshapes map (Subshape -> Color).
-  // This needed when colored shape is not part of BaseShape
-  // (but subshapes are) and actually container for subshapes.
+  // Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
+  // This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
   AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
+  fillSubshapeDrawerMap (aSubshapeDrawerMap);
+
+  Handle(AIS_ColoredDrawer) aBaseDrawer;
+  myShapeColors.Find (myshape, aBaseDrawer);
+
+  // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
+  DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
+  DataMapOfDrawerCompd aDispatchedClosed;
+  dispatchColors (aBaseDrawer, myshape,
+                  aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
+                  aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
+  addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
+}
+
+//=======================================================================
+//function : fillSubshapeDrawerMap
+//purpose  :
+//=======================================================================
+void AIS_ColoredShape::fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const
+{
+  // unroll compounds specified for grouping sub-shapes with the same style
+  // (e.g. the compounds that are not a part of the main shape)
+  TopTools_MapOfShape aMapOfOwnCompounds;
+  if (myshape.ShapeType() == TopAbs_COMPOUND)
   {
-    // unroll compounds specified for grouping sub-shapes with the same style
-    // (e.g. the compounds that are not a part of the main shape)
-    TopTools_MapOfShape aMapOfOwnCompounds;
-    if (myshape.ShapeType() == TopAbs_COMPOUND)
+    aMapOfOwnCompounds.Add (myshape);
+    collectSubCompounds (aMapOfOwnCompounds, myshape);
+  }
+  for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
+        aKeyShapeIter.More(); aKeyShapeIter.Next())
+  {
+    const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
+    if (aKeyShape.ShapeType() != TopAbs_COMPOUND
+     || aMapOfOwnCompounds.Contains (aKeyShape))
     {
-      aMapOfOwnCompounds.Add (myshape);
-      collectSubCompounds (aMapOfOwnCompounds, myshape);
+      continue;
     }
-    for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
-         aKeyShapeIter.More(); aKeyShapeIter.Next())
-    {
-      const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
-      if (aKeyShape.ShapeType() != TopAbs_COMPOUND
-       || aMapOfOwnCompounds.Contains (aKeyShape))
-      {
-        continue;
-      }
 
-      for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
+    for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
+    {
+      const TopoDS_Shape& aShape = aChildIter.Value();
+      if (!myShapeColors.IsBound (aShape))
       {
-        const TopoDS_Shape& aShape = aChildIter.Value();
-        if (!myShapeColors.IsBound (aShape))
-        {
-          bindSubShapes (aSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
-        }
+        bindSubShapes (theSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
       }
     }
+  }
 
-    // assign other sub-shapes with styles
-    for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
-         aKeyShapeIter.More(); aKeyShapeIter.Next())
+  // assign other sub-shapes with styles
+  for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
+        aKeyShapeIter.More(); aKeyShapeIter.Next())
+  {
+    const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
+    if (myshape == aKeyShape
+    || (aKeyShape.ShapeType() == TopAbs_COMPOUND
+    && !aMapOfOwnCompounds.Contains (aKeyShape)))
     {
-      const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
-      if (myshape == aKeyShape
-      || (aKeyShape.ShapeType() == TopAbs_COMPOUND
-      && !aMapOfOwnCompounds.Contains (aKeyShape)))
-      {
-        continue;
-      }
-
-      bindSubShapes (aSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
+      continue;
     }
+
+    bindSubShapes (theSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
+  }
+}
+
+//=======================================================================
+//function : ComputeSelection
+//purpose  :
+//=======================================================================
+void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                                         const Standard_Integer theMode)
+{
+  if (myshape.IsNull())
+  {
+    return;
+  }
+  else if (isShapeEntirelyVisible())
+  {
+    base_type::ComputeSelection (theSelection, theMode);
+    return;
+  }
+
+  const TopAbs_ShapeEnum aTypOfSel   = AIS_Shape::SelectionType (theMode);
+  const Standard_Real    aDeflection = Prs3d::GetDeflection (myshape, myDrawer);
+  const Standard_Real    aDeviationAngle = myDrawer->HLRAngle();
+  const Standard_Integer aPriority   = StdSelect_BRepSelectionTool::GetStandardPriority (myshape, aTypOfSel);
+  if (myDrawer->IsAutoTriangulation()
+  && !BRepTools::Triangulation (myshape, Precision::Infinite()))
+  {
+    BRepMesh_IncrementalMesh aMesher (myshape, aDeflection, Standard_False, aDeviationAngle);
+  }
+
+  AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
+  fillSubshapeDrawerMap (aSubshapeDrawerMap);
+
+  Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
+  if (aTypOfSel == TopAbs_SHAPE)
+  {
+    aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
   }
 
   Handle(AIS_ColoredDrawer) aBaseDrawer;
   myShapeColors.Find (myshape, aBaseDrawer);
+  computeSubshapeSelection (aBaseDrawer, aSubshapeDrawerMap, myshape, aBrepOwner, theSelection,
+                            aTypOfSel, aPriority, aDeflection, aDeviationAngle);
 
-  // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
-  DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
-  DataMapOfDrawerCompd aDispatchedClosed;
-  dispatchColors (aBaseDrawer, myshape,
-                  aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
-                  aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
-  addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
+  Handle(SelectMgr_SelectableObject) aThis (this);
+  for (theSelection->Init(); theSelection->More(); theSelection->Next())
+  {
+    Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (theSelection->Sensitive()->BaseSensitive()->OwnerId());
+    anOwner->Set (aThis);
+  }
+
+  StdSelect_BRepSelectionTool::PreBuildBVH (theSelection);
+}
+
+//=======================================================================
+//function : computeSubshapeSelection
+//purpose  :
+//=======================================================================
+void AIS_ColoredShape::computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
+                                                 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
+                                                 const TopoDS_Shape& theShape,
+                                                 const Handle(StdSelect_BRepOwner)& theOwner,
+                                                 const Handle(SelectMgr_Selection)& theSelection,
+                                                 const TopAbs_ShapeEnum theTypOfSel,
+                                                 const Standard_Integer thePriority,
+                                                 const Standard_Real theDeflection,
+                                                 const Standard_Real theDeflAngle)
+{
+  Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
+  theShapeDrawerMap.Find (theShape, aDrawer);
+  if (!aDrawer.IsNull()
+    && aDrawer->IsHidden())
+  {
+    return;
+  }
+
+  const Standard_Integer aNbPOnEdge = 9;
+  const Standard_Real    aMaximalParameter = 500.0;
+  if (theTypOfSel == TopAbs_SHAPE
+   && theShape.ShapeType() >= TopAbs_FACE)
+  {
+    StdSelect_BRepSelectionTool::ComputeSensitive (theShape, theOwner, theSelection,
+                                                   theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
+    return;
+  }
+  else if (theShape.ShapeType() == theTypOfSel)
+  {
+    const Standard_Boolean isComesFromDecomposition = !theShape.IsEqual (myshape);
+    Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (theShape, thePriority, isComesFromDecomposition);
+    StdSelect_BRepSelectionTool::ComputeSensitive (theShape, aBrepOwner, theSelection,
+                                                   theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
+    return;
+  }
+
+  for (TopoDS_Iterator aSubShapeIter (theShape); aSubShapeIter.More(); aSubShapeIter.Next())
+  {
+    const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
+    computeSubshapeSelection (aDrawer, theShapeDrawerMap, aSubShape,
+                              theOwner, theSelection, theTypOfSel, thePriority,
+                              theDeflection, theDeflAngle);
+  }
 }
 
 //=======================================================================
@@ -683,7 +790,7 @@ Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
 //=======================================================================
 void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
                                       const TopoDS_Shape& theKeyShape,
-                                      const Handle(AIS_ColoredDrawer)& theDrawer)
+                                      const Handle(AIS_ColoredDrawer)& theDrawer) const
 {
   TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
   if (aShapeWithColorType == TopAbs_COMPOUND)
index ccd1679988f5b27f4bf31c67d1a392409696447d..c713ce1d122ccb1d7d40682046f960b3b455cae6 100644 (file)
@@ -24,6 +24,8 @@
 #include <TopTools_MapOfShape.hxx>
 #include <TColStd_MapTransientHasher.hxx>
 
+class StdSelect_BRepOwner;
+
 //! Presentation of the shape with customizable sub-shapes properties.
 class AIS_ColoredShape : public AIS_Shape
 {
@@ -83,10 +85,15 @@ public: //! @name global aspects
 
 protected: //! @name override presentation computation
 
+  //! Compute presentation considering sub-shape color map.
   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
                                         const Handle(Prs3d_Presentation)&           thePrs,
                                         const Standard_Integer                      theMode) Standard_OVERRIDE;
 
+  //! Compute selection considering sub-shape hidden state.
+  Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                                                 const Standard_Integer theMode) Standard_OVERRIDE;
+
 protected:
 
   typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
@@ -110,6 +117,10 @@ protected:
                                                           DataMapOfDrawerCompd& theDrawerClosedFaces);
 protected:
 
+  //! Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
+  //! This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
+  Standard_EXPORT void fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const;
+
   //! Add shape to presentation
   //! @param thePrs the presentation
   //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
@@ -131,7 +142,26 @@ protected:
   //! @param theDrawer         assigned drawer
   Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
                                       const TopoDS_Shape& theKeyShape,
-                                      const Handle(AIS_ColoredDrawer)& theDrawer);
+                                      const Handle(AIS_ColoredDrawer)& theDrawer) const;
+
+  //! Add sub-shape to selection considering hidden state (recursively).
+  //! @param theParentDrawer   drawer of parent shape
+  //! @param theShapeDrawerMap shapes map
+  //! @param theShape          shape to compute sensitive entities
+  //! @param theOwner          selectable owner object
+  //! @param theSelection      selection to append new sensitive entities
+  //! @param theTypOfSel       type of selection
+  //! @param theDeflection     linear deflection
+  //! @param theDeflAngle      angular deflection
+  Standard_EXPORT void computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
+                                                 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
+                                                 const TopoDS_Shape& theShape,
+                                                 const Handle(StdSelect_BRepOwner)& theOwner,
+                                                 const Handle(SelectMgr_Selection)& theSelection,
+                                                 const TopAbs_ShapeEnum theTypOfSel,
+                                                 const Standard_Integer thePriority,
+                                                 const Standard_Real theDeflection,
+                                                 const Standard_Real theDeflAngle);
 
 protected:
 
index 84cf769a3b4ee90ea88037c8b41bcc9e16e432e7..f292fe40d7c63ddbd4cc16d995bcb6482030150e 100644 (file)
@@ -1,19 +1,20 @@
 puts "============"
-puts "CR25381"
+puts "0025381: Visualization - XCAFPrs_AISObject ignores visibility flag for sub-shapes"
 puts "============"
 puts ""
-######################################################
-# Visualization - XCAFPrs_AISObject ignores visibility flag for sub-shapes
-######################################################
 
+pload XDE OCAF VISUALIZATION
+catch { Close D }
 ReadStep D [locate_data_file bug25381_test_assembly_invisible.step]
 XShow D
+vaxo
 vfit
+vsetdispmode 1
+vselprops dynHighlight -dispMode -1
+vmoveto 300 200
+if { [vreadpixel 250 200 rgb name] != "DARKTURQUOISE" } { puts "Error: object is NOT picked" }
+vmoveto 200 250
+if { [vreadpixel 200 250 rgb name] != "BLACK"} { puts "Error: hidden part is displayed" }
+if { [vreadpixel 250 200 rgb name] != "RED4" } { puts "Error: object is picked by hidden part" }
 
-if { "[vreadpixel 198 172 rgb name]" != "WHITE" } {
-   puts "OK : XCAFPrs_AISObject get visibility flag for sub-shapes"
-} else {
-   puts "Error : XCAFPrs_AISObject ignores visibility flag for sub-shapes"
-}
-
-checkview -screenshot -3d -path ${imagedir}/${test_image}.png
+vdump ${imagedir}/${casename}.png