0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_ColoredShape.hxx
index 5fb4a3e..d23560b 100644 (file)
 #ifndef _AIS_ColoredShape_HeaderFile
 #define _AIS_ColoredShape_HeaderFile
 
-#include <Prs3d_Drawer.hxx>
+#include <AIS_DataMapOfShapeDrawer.hxx>
 #include <AIS_Shape.hxx>
-
-#include <NCollection_DataMap.hxx>
 #include <NCollection_IndexedDataMap.hxx>
-#include <TopTools_ShapeMapHasher.hxx>
-#include <TopoDS_Compound.hxx>
 #include <StdPrs_Volume.hxx>
+#include <TopoDS_Compound.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TColStd_MapTransientHasher.hxx>
 
-//! Customizable properties.
-class AIS_ColoredDrawer : public Prs3d_Drawer
-{
-public:
-
-  AIS_ColoredDrawer (const Handle(Prs3d_Drawer)& theLink)
-  : myIsHidden    (Standard_False),
-    myHasOwnColor (Standard_False),
-    myHasOwnWidth (Standard_False)
-  {
-    Link (theLink);
-  }
-
-  Standard_Boolean IsHidden()    const                              { return myIsHidden; }
-  void             SetHidden (const Standard_Boolean theToHide)     { myIsHidden = theToHide;  }
-  Standard_Boolean HasOwnColor() const                              { return myHasOwnColor; }
-  void             UnsetOwnColor()                                  { myHasOwnColor = Standard_False; }
-  void             SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True;  }
-  Standard_Boolean HasOwnWidth() const                              { return myHasOwnWidth; }
-  void             UnsetOwnWidth()                                  { myHasOwnWidth = Standard_False; }
-  void             SetOwnWidth (const Standard_Real /*theWidth*/)   { myHasOwnWidth = Standard_True;  }
-
-public:  //! @name list of overridden properties
-
-  Standard_Boolean myIsHidden;
-  Standard_Boolean myHasOwnColor;
-  Standard_Boolean myHasOwnWidth;
-
-public:
-  DEFINE_STANDARD_RTTI(AIS_ColoredDrawer);
-
-};
-
-DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, Prs3d_Drawer)
+class StdSelect_BRepOwner;
 
 //! Presentation of the shape with customizable sub-shapes properties.
 class AIS_ColoredShape : public AIS_Shape
@@ -76,10 +42,10 @@ public: //! @name sub-shape aspects
   //! Customize properties of specified sub-shape.
   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
   //! This method can be used to mark sub-shapes with customizable properties.
-  Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
+  Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
 
   //! Reset the map of custom sub-shape aspects.
-  Standard_EXPORT void ClearCustomAspects();
+  Standard_EXPORT virtual void ClearCustomAspects();
 
   //! Reset custom properties of specified sub-shape.
   //! @param theToUnregister unregister or not sub-shape from the map
@@ -90,10 +56,20 @@ public: //! @name sub-shape aspects
   Standard_EXPORT void SetCustomColor (const TopoDS_Shape&   theShape,
                                        const Quantity_Color& theColor);
 
+  //! Customize transparency of specified sub-shape
+  Standard_EXPORT void SetCustomTransparency (const TopoDS_Shape& theShape,
+                                              Standard_Real theTransparency);
+
   //! Customize line width of specified sub-shape
   Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
                                        const Standard_Real theLineWidth);
 
+  //! Return the map of custom aspects.
+  const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
+
+  //! Return the map of custom aspects.
+  AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
+
 public: //! @name global aspects
 
   //! Setup color of entire shape.
@@ -108,74 +84,101 @@ public: //! @name global aspects
   //! Sets the material aspect.
   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
 
+public:
+
+  //! Removes the setting for transparency in the reconstructed compound shape.
+  Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
+
+  //! Setup line width of entire shape.
+  Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
+
 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_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor;
-  typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape,              TopTools_ShapeMapHasher> DataMapOfShapeShape;
-  typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound,    TopTools_ShapeMapHasher> DataMapOfShapeCompd;
+  typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
 
 protected:
 
   //! Recursive function to map shapes.
-  //! @param theBaseKey                    the key to be used for undetailed shapes (default colors)
-  //! @param theSubshapeToParse            the subshape to be parsed
-  //! @param theSubshapeKeyshapeMap        shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
-  //! @param theParentType                 the parent subshape type
-  //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
-  Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape&        theBaseKey,
-                                                          const TopoDS_Shape&        theSubshapeToParse,
-                                                          const DataMapOfShapeShape& theSubshapeKeyshapeMap,
-                                                          const TopAbs_ShapeEnum     theParentType,
-                                                          DataMapOfShapeCompd*       theTypeKeyshapeDrawshapeArray);
-
-  Standard_EXPORT static void dispatchColors (const TopoDS_Shape&        theBaseShape,
-                                              const DataMapOfShapeColor& theKeyshapeColorMap,
-                                              DataMapOfShapeCompd*       theTypeKeyshapeDrawshapeArray);
-
+  //! @param theParentDrawer   the drawer to be used for undetailed shapes (default colors)
+  //! @param theShapeToParse   the subshape to be recursively parsed
+  //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
+  //! @param theParentType     the parent subshape type
+  //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
+  //! @param theDrawerOpenedShapePerType the array of shape types to fill
+  //! @param theDrawerClosedFaces        the map for closed faces
+  Standard_EXPORT static Standard_Boolean dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
+                                                          const TopoDS_Shape& theShapeToParse,
+                                                          const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
+                                                          const TopAbs_ShapeEnum theParentType,
+                                                          const Standard_Boolean theIsParentClosed,
+                                                          DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
+                                                          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 theDispatched  the shapes map with unique attributes
-  //! @param theMode        display mode
-  //! @param theVolume      how to interpret theDispatched shapes - as Closed volumes, as Open volumes
-  //!                       or to perform Autodetection
+  //! @param thePrs the presentation
+  //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
+  //! @param theDrawerClosedFaces the map of attributes for closed faces
+  //! @param theMode display mode
   Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
-                                                 DataMapOfShapeCompd*              theDispatched,
-                                                 const Standard_Integer            theMode,
-                                                 const StdPrs_Volume               theVolume);
+                                                 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
+                                                 const DataMapOfDrawerCompd& theDrawerClosedFaces,
+                                                 const Standard_Integer theMode);
 
   //! Check all shapes from myShapeColorsfor visibility
   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
 
-  //! Check a shape with unique attributes for visibility of all 2d subshape
-  Standard_EXPORT Standard_Boolean isShapeEntirelyVisible (DataMapOfShapeCompd* theDispatched) const;
-
   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
-  //! bind all resolved subshapes with theOriginKeyShape and store all binds in theSubshapeKeyshapeMap
-  //! @param theSubshapeKeyshapeMap        shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape 
-  //! @param theBaseShape                  a shape to be sought
-  //! @param theBaseKey                    a shape to be resolved (parse) into smaller (in topological sense)
-  //!                                      subshapes for new bind cycle
-  //! @param theOriginKeyShape             the key to be used for undetailed shapes (default colors)
-  Standard_EXPORT static void bindSubShapes (DataMapOfShapeShape& theSubshapeKeyshapeMap,
-                                             const TopoDS_Shape&  theBaseShape,
-                                             const TopoDS_Shape&  theKeyShape,
-                                             const TopoDS_Shape&  theOriginKeyShape);
+  //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
+  //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
+  //! @param theKeyShape       a shape to be resolved (parse) into smaller (in topological sense)
+  //!                          subshapes for new bind cycle
+  //! @param theDrawer         assigned drawer
+  Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
+                                      const TopoDS_Shape& theKeyShape,
+                                      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:
 
-  DataMapOfShapeColor myShapeColors;
+  AIS_DataMapOfShapeDrawer myShapeColors;
 
 public:
 
-  DEFINE_STANDARD_RTTI(AIS_ColoredShape);
+  DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
 
 };