1 // Created on: 2000-08-11
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _XCAFPrs_Style_HeaderFile
17 #define _XCAFPrs_Style_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
22 #include <Quantity_ColorRGBAHasher.hxx>
23 #include <XCAFDoc_VisMaterial.hxx>
25 //! Represents a set of styling settings applicable to a (sub)shape
32 //! Empty constructor - colors are unset, visibility is TRUE.
33 Standard_EXPORT XCAFPrs_Style();
35 //! Return TRUE if style is empty - does not override any properties.
36 Standard_Boolean IsEmpty() const
38 return !myHasColorSurf
40 && myMaterial.IsNull()
45 const Handle(XCAFDoc_VisMaterial)& Material() const { return myMaterial; }
48 void SetMaterial (const Handle(XCAFDoc_VisMaterial)& theMaterial) { myMaterial = theMaterial; }
50 //! Return TRUE if surface color has been defined.
51 Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
53 //! Return surface color.
54 const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
56 //! Set surface color.
57 void SetColorSurf (const Quantity_Color& theColor) { SetColorSurf (Quantity_ColorRGBA (theColor)); }
59 //! Return surface color.
60 const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
62 //! Set surface color.
63 Standard_EXPORT void SetColorSurf (const Quantity_ColorRGBA& theColor);
65 //! Manage surface color setting
66 Standard_EXPORT void UnSetColorSurf();
68 //! Return TRUE if curve color has been defined.
69 Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
71 //! Return curve color.
72 const Quantity_Color& GetColorCurv() const { return myColorCurv; }
75 Standard_EXPORT void SetColorCurv (const Quantity_Color& col);
77 //! Manage curve color setting
78 Standard_EXPORT void UnSetColorCurv();
80 //! Assign visibility.
81 void SetVisibility (const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
83 //! Manage visibility.
84 Standard_Boolean IsVisible() const { return myIsVisible; }
86 //! Returns True if styles are the same
87 //! Methods for using Style as key in maps
88 Standard_Boolean IsEqual (const XCAFPrs_Style& theOther) const
90 if (myIsVisible != theOther.myIsVisible)
94 else if (!myIsVisible)
99 return myHasColorSurf == theOther.myHasColorSurf
100 && myHasColorCurv == theOther.myHasColorCurv
101 && myMaterial == theOther.myMaterial
102 && (!myHasColorSurf || myColorSurf == theOther.myColorSurf)
103 && (!myHasColorCurv || myColorCurv == theOther.myColorCurv);
106 //! Returns True if styles are the same.
107 Standard_Boolean operator== (const XCAFPrs_Style& theOther) const
109 return IsEqual (theOther);
112 //! Computes a hash code for the given set of styling settings, in the range [1, theUpperBound]
113 //! @param theStyle the set of styling settings which hash code is to be computed
114 //! @param theUpperBound the upper bound of the range a computing hash code must be within
115 //! @return a computed hash code, in the range [1, theUpperBound]
116 static Standard_Integer HashCode (const XCAFPrs_Style& theStyle, const Standard_Integer theUpperBound)
118 if (!theStyle.myIsVisible)
123 Standard_Integer aHashCode = 0;
124 if (theStyle.myHasColorSurf)
126 aHashCode = aHashCode ^ Quantity_ColorRGBAHasher::HashCode (theStyle.myColorSurf, theUpperBound);
128 if (theStyle.myHasColorCurv)
130 aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorCurv, theUpperBound);
132 if (!theStyle.myMaterial.IsNull())
134 aHashCode = aHashCode ^ ::HashCode (theStyle.myMaterial, theUpperBound);
136 return ::HashCode (aHashCode, theUpperBound);
139 //! Returns True when the two keys are the same.
140 static Standard_Boolean IsEqual (const XCAFPrs_Style& theS1, const XCAFPrs_Style& theS2)
142 return theS1.IsEqual (theS2);
145 //! Dumps the content of me into the stream
146 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
150 Handle(XCAFDoc_VisMaterial) myMaterial;
151 Quantity_ColorRGBA myColorSurf;
152 Quantity_Color myColorCurv;
153 Standard_Boolean myHasColorSurf;
154 Standard_Boolean myHasColorCurv;
155 Standard_Boolean myIsVisible;
159 #endif // _XCAFPrs_Style_HeaderFile