| 1 | // Created on: 2014-04-24 |
| 2 | // Created by: Kirill Gavrilov |
| 3 | // Copyright (c) 2014 OPEN CASCADE SAS |
| 4 | // |
| 5 | // This file is part of Open CASCADE Technology software library. |
| 6 | // |
| 7 | // This library is free software; you can redistribute it and/or modify it under |
| 8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 9 | // by the Free Software Foundation, with special exception defined in the file |
| 10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 11 | // distribution for complete text of the license and disclaimer of any warranty. |
| 12 | // |
| 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 14 | // commercial license or contractual agreement. |
| 15 | |
| 16 | #ifndef _AIS_ColoredShape_HeaderFile |
| 17 | #define _AIS_ColoredShape_HeaderFile |
| 18 | |
| 19 | #include <AIS_Drawer.hxx> |
| 20 | #include <AIS_Shape.hxx> |
| 21 | |
| 22 | #include <NCollection_DataMap.hxx> |
| 23 | #include <NCollection_IndexedDataMap.hxx> |
| 24 | #include <TopTools_ShapeMapHasher.hxx> |
| 25 | #include <TopoDS_Compound.hxx> |
| 26 | #include <StdPrs_Volume.hxx> |
| 27 | |
| 28 | //! Customizable properties. |
| 29 | class AIS_ColoredDrawer : public AIS_Drawer |
| 30 | { |
| 31 | public: |
| 32 | |
| 33 | AIS_ColoredDrawer (const Handle(AIS_Drawer)& theLink) |
| 34 | : myIsHidden (Standard_False), |
| 35 | myHasOwnColor (Standard_False), |
| 36 | myHasOwnWidth (Standard_False) |
| 37 | { |
| 38 | Link (theLink); |
| 39 | } |
| 40 | |
| 41 | Standard_Boolean IsHidden() const { return myIsHidden; } |
| 42 | void SetHidden (const Standard_Boolean theToHide) { myIsHidden = theToHide; } |
| 43 | Standard_Boolean HasOwnColor() const { return myHasOwnColor; } |
| 44 | void UnsetOwnColor() { myHasOwnColor = Standard_False; } |
| 45 | void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True; } |
| 46 | Standard_Boolean HasOwnWidth() const { return myHasOwnWidth; } |
| 47 | void UnsetOwnWidth() { myHasOwnWidth = Standard_False; } |
| 48 | void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = Standard_True; } |
| 49 | |
| 50 | public: //! @name list of overridden properties |
| 51 | |
| 52 | Standard_Boolean myIsHidden; |
| 53 | Standard_Boolean myHasOwnColor; |
| 54 | Standard_Boolean myHasOwnWidth; |
| 55 | |
| 56 | public: |
| 57 | DEFINE_STANDARD_RTTI(AIS_ColoredDrawer); |
| 58 | |
| 59 | }; |
| 60 | |
| 61 | DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, AIS_Drawer) |
| 62 | |
| 63 | //! Presentation of the shape with customizable sub-shapes properties. |
| 64 | class AIS_ColoredShape : public AIS_Shape |
| 65 | { |
| 66 | public: |
| 67 | |
| 68 | //! Default constructor |
| 69 | Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape); |
| 70 | |
| 71 | //! Copy constructor |
| 72 | Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape); |
| 73 | |
| 74 | public: //! @name sub-shape aspects |
| 75 | |
| 76 | //! Customize properties of specified sub-shape. |
| 77 | //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape! |
| 78 | //! This method can be used to mark sub-shapes with customizable properties. |
| 79 | Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape); |
| 80 | |
| 81 | //! Reset the map of custom sub-shape aspects. |
| 82 | Standard_EXPORT void ClearCustomAspects(); |
| 83 | |
| 84 | //! Reset custom properties of specified sub-shape. |
| 85 | //! @param theToUnregister unregister or not sub-shape from the map |
| 86 | Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape, |
| 87 | const Standard_Boolean theToUnregister = Standard_False); |
| 88 | |
| 89 | //! Customize color of specified sub-shape |
| 90 | Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape, |
| 91 | const Quantity_Color& theColor); |
| 92 | |
| 93 | //! Customize line width of specified sub-shape |
| 94 | Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape, |
| 95 | const Standard_Real theLineWidth); |
| 96 | |
| 97 | public: //! @name global aspects |
| 98 | |
| 99 | //! Setup color of entire shape. |
| 100 | Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE; |
| 101 | |
| 102 | //! Setup line width of entire shape. |
| 103 | Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE; |
| 104 | |
| 105 | //! Sets transparency value. |
| 106 | Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE; |
| 107 | |
| 108 | //! Sets the material aspect. |
| 109 | Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE; |
| 110 | |
| 111 | protected: //! @name override presentation computation |
| 112 | |
| 113 | Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
| 114 | const Handle(Prs3d_Presentation)& thePrs, |
| 115 | const Standard_Integer theMode) Standard_OVERRIDE; |
| 116 | |
| 117 | protected: |
| 118 | |
| 119 | typedef NCollection_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor; |
| 120 | typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> DataMapOfShapeShape; |
| 121 | typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd; |
| 122 | |
| 123 | protected: |
| 124 | |
| 125 | //! Recursive function to map shapes. |
| 126 | //! @param theBaseKey the key to be used for undetailed shapes (default colors) |
| 127 | //! @param theSubshapeToParse the subshape to be parsed |
| 128 | //! @param theSubshapeKeyshapeMap shapes map Subshape (in the base shape) -> Keyshape (detailed shape) |
| 129 | //! @param theParentType the parent subshape type |
| 130 | //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill |
| 131 | Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape& theBaseKey, |
| 132 | const TopoDS_Shape& theSubshapeToParse, |
| 133 | const DataMapOfShapeShape& theSubshapeKeyshapeMap, |
| 134 | const TopAbs_ShapeEnum theParentType, |
| 135 | DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray); |
| 136 | |
| 137 | Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape, |
| 138 | const DataMapOfShapeColor& theKeyshapeColorMap, |
| 139 | DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray); |
| 140 | |
| 141 | protected: |
| 142 | |
| 143 | //! Add shape to presentation |
| 144 | //! @param thePrs the presentation |
| 145 | //! @param theDispatched the shapes map with unique attributes |
| 146 | //! @param theMode display mode |
| 147 | //! @param theVolume how to interpret theDispatched shapes - as Closed volumes, as Open volumes |
| 148 | //! or to perform Autodetection |
| 149 | Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs, |
| 150 | DataMapOfShapeCompd* theDispatched, |
| 151 | const Standard_Integer theMode, |
| 152 | const StdPrs_Volume theVolume); |
| 153 | |
| 154 | //! Check all shapes from myShapeColorsfor visibility |
| 155 | Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const; |
| 156 | |
| 157 | //! Check a shape with unique attributes for visibility of all 2d subshape |
| 158 | Standard_EXPORT Standard_Boolean isShapeEntirelyVisible (DataMapOfShapeCompd* theDispatched) const; |
| 159 | |
| 160 | //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape, |
| 161 | //! bind all resolved subshapes with theOriginKeyShape and store all binds in theSubshapeKeyshapeMap |
| 162 | //! @param theSubshapeKeyshapeMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape |
| 163 | //! @param theBaseShape a shape to be sought |
| 164 | //! @param theBaseKey a shape to be resolved (parse) into smaller (in topological sense) |
| 165 | //! subshapes for new bind cycle |
| 166 | //! @param theOriginKeyShape the key to be used for undetailed shapes (default colors) |
| 167 | Standard_EXPORT static void bindSubShapes (DataMapOfShapeShape& theSubshapeKeyshapeMap, |
| 168 | const TopoDS_Shape& theBaseShape, |
| 169 | const TopoDS_Shape& theKeyShape, |
| 170 | const TopoDS_Shape& theOriginKeyShape); |
| 171 | |
| 172 | protected: |
| 173 | |
| 174 | DataMapOfShapeColor myShapeColors; |
| 175 | |
| 176 | public: |
| 177 | |
| 178 | DEFINE_STANDARD_RTTI(AIS_ColoredShape); |
| 179 | |
| 180 | }; |
| 181 | |
| 182 | DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape) |
| 183 | |
| 184 | #endif // _AIS_ColoredShape_HeaderFile |