Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:27:00

0001 // Created on: 2014-04-24
0002 // Created by: Kirill Gavrilov
0003 // Copyright (c) 2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _AIS_ColoredShape_HeaderFile
0017 #define _AIS_ColoredShape_HeaderFile
0018 
0019 #include <AIS_ColoredDrawer.hxx>
0020 #include <NCollection_DataMap.hxx>
0021 #include <TopTools_ShapeMapHasher.hxx>
0022 #include <AIS_Shape.hxx>
0023 #include <NCollection_IndexedDataMap.hxx>
0024 #include <TopoDS_Compound.hxx>
0025 #include <TopoDS_Shape.hxx>
0026 #include <NCollection_Map.hxx>
0027 
0028 class StdSelect_BRepOwner;
0029 
0030 //! Presentation of the shape with customizable sub-shapes properties.
0031 class AIS_ColoredShape : public AIS_Shape
0032 {
0033 public:
0034   //! Default constructor
0035   Standard_EXPORT AIS_ColoredShape(const TopoDS_Shape& theShape);
0036 
0037   //! Copy constructor
0038   Standard_EXPORT AIS_ColoredShape(const occ::handle<AIS_Shape>& theShape);
0039 
0040 public: //! @name sub-shape aspects
0041   //! Customize properties of specified sub-shape.
0042   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
0043   //! This method can be used to mark sub-shapes with customizable properties.
0044   Standard_EXPORT virtual occ::handle<AIS_ColoredDrawer> CustomAspects(
0045     const TopoDS_Shape& theShape);
0046 
0047   //! Reset the map of custom sub-shape aspects.
0048   Standard_EXPORT virtual void ClearCustomAspects();
0049 
0050   //! Reset custom properties of specified sub-shape.
0051   //! @param theToUnregister unregister or not sub-shape from the map
0052   Standard_EXPORT void UnsetCustomAspects(const TopoDS_Shape& theShape,
0053                                           const bool          theToUnregister = false);
0054 
0055   //! Customize color of specified sub-shape
0056   Standard_EXPORT void SetCustomColor(const TopoDS_Shape& theShape, const Quantity_Color& theColor);
0057 
0058   //! Customize transparency of specified sub-shape
0059   Standard_EXPORT void SetCustomTransparency(const TopoDS_Shape& theShape, double theTransparency);
0060 
0061   //! Customize line width of specified sub-shape
0062   Standard_EXPORT void SetCustomWidth(const TopoDS_Shape& theShape, const double theLineWidth);
0063 
0064   //! Return the map of custom aspects.
0065   const NCollection_DataMap<TopoDS_Shape, occ::handle<AIS_ColoredDrawer>, TopTools_ShapeMapHasher>&
0066     CustomAspectsMap() const
0067   {
0068     return myShapeColors;
0069   }
0070 
0071   //! Return the map of custom aspects.
0072   NCollection_DataMap<TopoDS_Shape, occ::handle<AIS_ColoredDrawer>, TopTools_ShapeMapHasher>&
0073     ChangeCustomAspectsMap()
0074   {
0075     return myShapeColors;
0076   }
0077 
0078 public: //! @name global aspects
0079   //! Setup color of entire shape.
0080   Standard_EXPORT void SetColor(const Quantity_Color& theColor) override;
0081 
0082   //! Setup line width of entire shape.
0083   Standard_EXPORT void SetWidth(const double theLineWidth) override;
0084 
0085   //! Sets transparency value.
0086   Standard_EXPORT void SetTransparency(const double theValue) override;
0087 
0088   //! Sets the material aspect.
0089   Standard_EXPORT void SetMaterial(const Graphic3d_MaterialAspect& theAspect) override;
0090 
0091 public:
0092   //! Removes the setting for transparency in the reconstructed compound shape.
0093   Standard_EXPORT void UnsetTransparency() override;
0094 
0095   //! Setup line width of entire shape.
0096   Standard_EXPORT void UnsetWidth() override;
0097 
0098 protected: //! @name override presentation computation
0099   //! Compute presentation considering sub-shape color map.
0100   Standard_EXPORT void Compute(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0101                                const occ::handle<Prs3d_Presentation>&         thePrs,
0102                                const int                                      theMode) override;
0103 
0104   //! Compute selection considering sub-shape hidden state.
0105   Standard_EXPORT void ComputeSelection(const occ::handle<SelectMgr_Selection>& theSelection,
0106                                         const int                               theMode) override;
0107 
0108 protected:
0109   typedef NCollection_IndexedDataMap<occ::handle<AIS_ColoredDrawer>, TopoDS_Compound>
0110     DataMapOfDrawerCompd;
0111 
0112 protected:
0113   //! Recursive function to map shapes.
0114   //! @param theParentDrawer   the drawer to be used for undetailed shapes (default colors)
0115   //! @param theShapeToParse   the subshape to be recursively parsed
0116   //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
0117   //! @param theParentType     the parent subshape type
0118   //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
0119   //! @param theDrawerOpenedShapePerType the array of shape types to fill
0120   //! @param theDrawerClosedFaces        the map for closed faces
0121   Standard_EXPORT static bool dispatchColors(
0122     const occ::handle<AIS_ColoredDrawer>&               theParentDrawer,
0123     const TopoDS_Shape&                                 theShapeToParse,
0124     const NCollection_DataMap<TopoDS_Shape,
0125                               occ::handle<AIS_ColoredDrawer>,
0126                               TopTools_ShapeMapHasher>& theShapeDrawerMap,
0127     const TopAbs_ShapeEnum                              theParentType,
0128     const bool                                          theIsParentClosed,
0129     DataMapOfDrawerCompd*                               theDrawerOpenedShapePerType,
0130     DataMapOfDrawerCompd&                               theDrawerClosedFaces);
0131 
0132 protected:
0133   //! Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
0134   //! This needed when colored shape is not part of BaseShape (but subshapes are) and actually
0135   //! container for subshapes.
0136   Standard_EXPORT void fillSubshapeDrawerMap(
0137     NCollection_DataMap<TopoDS_Shape, occ::handle<AIS_ColoredDrawer>, TopTools_ShapeMapHasher>&
0138       theSubshapeDrawerMap) const;
0139 
0140   //! Add shape to presentation
0141   //! @param thePrs the presentation
0142   //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
0143   //! @param theDrawerClosedFaces the map of attributes for closed faces
0144   //! @param theMode display mode
0145   Standard_EXPORT void addShapesWithCustomProps(
0146     const occ::handle<Prs3d_Presentation>& thePrs,
0147     const DataMapOfDrawerCompd*            theDrawerOpenedShapePerType,
0148     const DataMapOfDrawerCompd&            theDrawerClosedFaces,
0149     const int                              theMode);
0150 
0151   //! Check all shapes from myShapeColorsfor visibility
0152   Standard_EXPORT bool isShapeEntirelyVisible() const;
0153 
0154   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
0155   //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
0156   //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape ->
0157   //! theOriginKeyShape
0158   //! @param theKeyShape       a shape to be resolved (parse) into smaller (in topological sense)
0159   //!                          subshapes for new bind cycle
0160   //! @param theDrawer         assigned drawer
0161   Standard_EXPORT void bindSubShapes(
0162     NCollection_DataMap<TopoDS_Shape, occ::handle<AIS_ColoredDrawer>, TopTools_ShapeMapHasher>&
0163                                           theShapeDrawerMap,
0164     const TopoDS_Shape&                   theKeyShape,
0165     const occ::handle<AIS_ColoredDrawer>& theDrawer) const;
0166 
0167   //! Add sub-shape to selection considering hidden state (recursively).
0168   //! @param theParentDrawer   drawer of parent shape
0169   //! @param theShapeDrawerMap shapes map
0170   //! @param theShape          shape to compute sensitive entities
0171   //! @param theOwner          selectable owner object
0172   //! @param theSelection      selection to append new sensitive entities
0173   //! @param theTypOfSel       type of selection
0174   //! @param theDeflection     linear deflection
0175   //! @param theDeflAngle      angular deflection
0176   Standard_EXPORT void computeSubshapeSelection(
0177     const occ::handle<AIS_ColoredDrawer>&               theParentDrawer,
0178     const NCollection_DataMap<TopoDS_Shape,
0179                               occ::handle<AIS_ColoredDrawer>,
0180                               TopTools_ShapeMapHasher>& theShapeDrawerMap,
0181     const TopoDS_Shape&                                 theShape,
0182     const occ::handle<StdSelect_BRepOwner>&             theOwner,
0183     const occ::handle<SelectMgr_Selection>&             theSelection,
0184     const TopAbs_ShapeEnum                              theTypOfSel,
0185     const int                                           thePriority,
0186     const double                                        theDeflection,
0187     const double                                        theDeflAngle);
0188 
0189 protected:
0190   NCollection_DataMap<TopoDS_Shape, occ::handle<AIS_ColoredDrawer>, TopTools_ShapeMapHasher>
0191     myShapeColors;
0192 
0193 public:
0194   DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape, AIS_Shape)
0195 };
0196 
0197 #endif // _AIS_ColoredShape_HeaderFile