Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:54

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_DataMapOfShapeDrawer.hxx>
0020 #include <AIS_Shape.hxx>
0021 #include <NCollection_IndexedDataMap.hxx>
0022 #include <TopoDS_Compound.hxx>
0023 #include <TopTools_MapOfShape.hxx>
0024 
0025 class StdSelect_BRepOwner;
0026 
0027 //! Presentation of the shape with customizable sub-shapes properties.
0028 class AIS_ColoredShape : public AIS_Shape
0029 {
0030 public:
0031 
0032   //! Default constructor
0033   Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
0034 
0035   //! Copy constructor
0036   Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
0037 
0038 public: //! @name sub-shape aspects
0039 
0040   //! Customize properties of specified sub-shape.
0041   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
0042   //! This method can be used to mark sub-shapes with customizable properties.
0043   Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
0044 
0045   //! Reset the map of custom sub-shape aspects.
0046   Standard_EXPORT virtual void ClearCustomAspects();
0047 
0048   //! Reset custom properties of specified sub-shape.
0049   //! @param theToUnregister unregister or not sub-shape from the map
0050   Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape&    theShape,
0051                                            const Standard_Boolean theToUnregister = Standard_False);
0052 
0053   //! Customize color of specified sub-shape
0054   Standard_EXPORT void SetCustomColor (const TopoDS_Shape&   theShape,
0055                                        const Quantity_Color& theColor);
0056 
0057   //! Customize transparency of specified sub-shape
0058   Standard_EXPORT void SetCustomTransparency (const TopoDS_Shape& theShape,
0059                                               Standard_Real theTransparency);
0060 
0061   //! Customize line width of specified sub-shape
0062   Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
0063                                        const Standard_Real theLineWidth);
0064 
0065   //! Return the map of custom aspects.
0066   const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
0067 
0068   //! Return the map of custom aspects.
0069   AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
0070 
0071 public: //! @name global aspects
0072 
0073   //! Setup color of entire shape.
0074   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
0075 
0076   //! Setup line width of entire shape.
0077   Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
0078 
0079   //! Sets transparency value.
0080   Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
0081 
0082   //! Sets the material aspect.
0083   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
0084 
0085 public:
0086 
0087   //! Removes the setting for transparency in the reconstructed compound shape.
0088   Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
0089 
0090   //! Setup line width of entire shape.
0091   Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
0092 
0093 protected: //! @name override presentation computation
0094 
0095   //! Compute presentation considering sub-shape color map.
0096   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0097                                         const Handle(Prs3d_Presentation)& thePrs,
0098                                         const Standard_Integer theMode) Standard_OVERRIDE;
0099 
0100   //! Compute selection considering sub-shape hidden state.
0101   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
0102                                                  const Standard_Integer theMode) Standard_OVERRIDE;
0103 
0104 protected:
0105 
0106   typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound> DataMapOfDrawerCompd;
0107 
0108 protected:
0109 
0110   //! Recursive function to map shapes.
0111   //! @param theParentDrawer   the drawer to be used for undetailed shapes (default colors)
0112   //! @param theShapeToParse   the subshape to be recursively parsed
0113   //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
0114   //! @param theParentType     the parent subshape type
0115   //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
0116   //! @param theDrawerOpenedShapePerType the array of shape types to fill
0117   //! @param theDrawerClosedFaces        the map for closed faces
0118   Standard_EXPORT static Standard_Boolean dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
0119                                                           const TopoDS_Shape& theShapeToParse,
0120                                                           const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
0121                                                           const TopAbs_ShapeEnum theParentType,
0122                                                           const Standard_Boolean theIsParentClosed,
0123                                                           DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
0124                                                           DataMapOfDrawerCompd& theDrawerClosedFaces);
0125 protected:
0126 
0127   //! Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
0128   //! This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
0129   Standard_EXPORT void fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const;
0130 
0131   //! Add shape to presentation
0132   //! @param thePrs the presentation
0133   //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
0134   //! @param theDrawerClosedFaces the map of attributes for closed faces
0135   //! @param theMode display mode
0136   Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
0137                                                  const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
0138                                                  const DataMapOfDrawerCompd& theDrawerClosedFaces,
0139                                                  const Standard_Integer theMode);
0140 
0141   //! Check all shapes from myShapeColorsfor visibility
0142   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
0143 
0144   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
0145   //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
0146   //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
0147   //! @param theKeyShape       a shape to be resolved (parse) into smaller (in topological sense)
0148   //!                          subshapes for new bind cycle
0149   //! @param theDrawer         assigned drawer
0150   Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
0151                                       const TopoDS_Shape& theKeyShape,
0152                                       const Handle(AIS_ColoredDrawer)& theDrawer) const;
0153 
0154   //! Add sub-shape to selection considering hidden state (recursively).
0155   //! @param theParentDrawer   drawer of parent shape
0156   //! @param theShapeDrawerMap shapes map
0157   //! @param theShape          shape to compute sensitive entities
0158   //! @param theOwner          selectable owner object
0159   //! @param theSelection      selection to append new sensitive entities
0160   //! @param theTypOfSel       type of selection
0161   //! @param theDeflection     linear deflection
0162   //! @param theDeflAngle      angular deflection
0163   Standard_EXPORT void computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
0164                                                  const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
0165                                                  const TopoDS_Shape& theShape,
0166                                                  const Handle(StdSelect_BRepOwner)& theOwner,
0167                                                  const Handle(SelectMgr_Selection)& theSelection,
0168                                                  const TopAbs_ShapeEnum theTypOfSel,
0169                                                  const Standard_Integer thePriority,
0170                                                  const Standard_Real theDeflection,
0171                                                  const Standard_Real theDeflAngle);
0172 
0173 protected:
0174 
0175   AIS_DataMapOfShapeDrawer myShapeColors;
0176 
0177 public:
0178 
0179   DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
0180 
0181 };
0182 
0183 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
0184 
0185 #endif // _AIS_ColoredShape_HeaderFile