diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index 9c528251ab..f3396308d0 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -384,55 +386,10 @@ 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; - { - // 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)) - { - continue; - } - - for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next()) - { - const TopoDS_Shape& aShape = aChildIter.Value(); - if (!myShapeColors.IsBound (aShape)) - { - bindSubShapes (aSubshapeDrawerMap, aShape, aKeyShapeIter.Value()); - } - } - } - - // 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))) - { - continue; - } - - bindSubShapes (aSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value()); - } - } + fillSubshapeDrawerMap (aSubshapeDrawerMap); Handle(AIS_ColoredDrawer) aBaseDrawer; myShapeColors.Find (myshape, aBaseDrawer); @@ -446,6 +403,156 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& , 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) + { + 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)) + { + continue; + } + + for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next()) + { + const TopoDS_Shape& aShape = aChildIter.Value(); + if (!myShapeColors.IsBound (aShape)) + { + bindSubShapes (theSubshapeDrawerMap, aShape, aKeyShapeIter.Value()); + } + } + } + + // 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))) + { + 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); + + 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); + } +} + //======================================================================= //function : addShapesWithCustomProps //purpose : @@ -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) diff --git a/src/AIS/AIS_ColoredShape.hxx b/src/AIS/AIS_ColoredShape.hxx index ccd1679988..c713ce1d12 100644 --- a/src/AIS/AIS_ColoredShape.hxx +++ b/src/AIS/AIS_ColoredShape.hxx @@ -24,6 +24,8 @@ #include #include +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 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: diff --git a/tests/bugs/xde/bug25381 b/tests/bugs/xde/bug25381 index 84cf769a3b..f292fe40d7 100644 --- a/tests/bugs/xde/bug25381 +++ b/tests/bugs/xde/bug25381 @@ -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