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>
24 //! Represents a set of styling settings applicable to a (sub)shape
31 //! Empty constructor - colors are unset, visibility is TRUE.
32 Standard_EXPORT XCAFPrs_Style();
34 //! Return TRUE if surface color has been defined.
35 Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
37 //! Return surface color.
38 const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
40 //! Set surface color.
41 void SetColorSurf (const Quantity_Color& theColor) { SetColorSurf (Quantity_ColorRGBA (theColor)); }
43 //! Return surface color.
44 const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
46 //! Set surface color.
47 Standard_EXPORT void SetColorSurf (const Quantity_ColorRGBA& theColor);
49 //! Manage surface color setting
50 Standard_EXPORT void UnSetColorSurf();
52 //! Return TRUE if curve color has been defined.
53 Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
55 //! Return curve color.
56 const Quantity_Color& GetColorCurv() const { return myColorCurv; }
59 Standard_EXPORT void SetColorCurv (const Quantity_Color& col);
61 //! Manage curve color setting
62 Standard_EXPORT void UnSetColorCurv();
64 //! Assign visibility.
65 void SetVisibility (const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
67 //! Manage visibility.
68 Standard_Boolean IsVisible() const { return myIsVisible; }
70 //! Returns True if styles are the same
71 //! Methods for using Style as key in maps
72 Standard_Boolean IsEqual (const XCAFPrs_Style& theOther) const
74 if (myIsVisible != theOther.myIsVisible)
78 else if (!myIsVisible)
83 return myHasColorSurf == theOther.myHasColorSurf
84 && myHasColorCurv == theOther.myHasColorCurv
85 && (!myHasColorSurf || myColorSurf == theOther.myColorSurf)
86 && (!myHasColorCurv || myColorCurv == theOther.myColorCurv);
89 //! Returns True if styles are the same.
90 Standard_Boolean operator== (const XCAFPrs_Style& theOther) const
92 return IsEqual (theOther);
95 //! Computes a hash code for the given set of styling settings, in the range [1, theUpperBound]
96 //! @param theStyle the set of styling settings which hash code is to be computed
97 //! @param theUpperBound the upper bound of the range a computing hash code must be within
98 //! @return a computed hash code, in the range [1, theUpperBound]
99 static Standard_Integer HashCode (const XCAFPrs_Style& theStyle, const Standard_Integer theUpperBound)
101 if (!theStyle.myIsVisible)
106 Standard_Integer aHashCode = 0;
107 if (theStyle.myHasColorSurf)
109 aHashCode = aHashCode ^ Quantity_ColorRGBAHasher::HashCode (theStyle.myColorSurf, theUpperBound);
111 if (theStyle.myHasColorCurv)
113 aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorCurv, theUpperBound);
115 return ::HashCode (aHashCode, theUpperBound);
118 //! Returns True when the two keys are the same.
119 static Standard_Boolean IsEqual (const XCAFPrs_Style& theS1, const XCAFPrs_Style& theS2)
121 return theS1.IsEqual (theS2);
124 //! Dumps the content of me into the stream
125 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const;
129 Quantity_ColorRGBA myColorSurf;
130 Quantity_Color myColorCurv;
131 Standard_Boolean myHasColorSurf;
132 Standard_Boolean myHasColorCurv;
133 Standard_Boolean myIsVisible;
137 #endif // _XCAFPrs_Style_HeaderFile