47a6d3118a0ab9d47334cb34f3a0a344a541d726
[occt.git] / src / XCAFPrs / XCAFPrs_Style.hxx
1 // Created on: 2000-08-11
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-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 _XCAFPrs_Style_HeaderFile
17 #define _XCAFPrs_Style_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
22 #include <Quantity_ColorRGBAHasher.hxx>
23
24 //! Represents a set of styling settings applicable to a (sub)shape
25 class XCAFPrs_Style 
26 {
27 public:
28
29   DEFINE_STANDARD_ALLOC
30
31   //! Empty constructor - colors are unset, visibility is TRUE.
32   Standard_EXPORT XCAFPrs_Style();
33
34   //! Return TRUE if surface color has been defined.
35   Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
36
37   //! Return surface color.
38   const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
39
40   //! Set surface color.
41   void SetColorSurf (const Quantity_Color& theColor) { SetColorSurf  (Quantity_ColorRGBA (theColor)); }
42
43   //! Return surface color.
44   const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
45
46   //! Set surface color.
47   Standard_EXPORT void SetColorSurf  (const Quantity_ColorRGBA& theColor);
48
49   //! Manage surface color setting
50   Standard_EXPORT void UnSetColorSurf();
51   
52   //! Return TRUE if curve color has been defined.
53   Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
54
55   //! Return curve color.
56   const Quantity_Color& GetColorCurv() const { return myColorCurv; }
57
58   //! Set curve color.
59   Standard_EXPORT void SetColorCurv (const Quantity_Color& col);
60   
61   //! Manage curve color setting
62   Standard_EXPORT void UnSetColorCurv();
63
64   //! Assign visibility.
65   void SetVisibility (const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
66
67   //! Manage visibility.
68   Standard_Boolean IsVisible() const { return myIsVisible; }
69
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
73   {
74     if (myIsVisible != theOther.myIsVisible)
75     {
76       return false;
77     }
78     else if (!myIsVisible)
79     {
80       return true;
81     }
82
83     return myHasColorSurf == theOther.myHasColorSurf
84         && myHasColorCurv == theOther.myHasColorCurv
85         && (!myHasColorSurf || myColorSurf == theOther.myColorSurf)
86         && (!myHasColorCurv || myColorCurv == theOther.myColorCurv);
87   }
88
89   //! Returns True if styles are the same.
90   Standard_Boolean operator== (const XCAFPrs_Style& theOther) const
91   {
92     return IsEqual (theOther);
93   }
94
95   //! Returns a HasCode value.
96   static Standard_Integer HashCode (const XCAFPrs_Style& theStyle,
97                                     const Standard_Integer theUpper)
98   {
99     if (!theStyle.myIsVisible)
100     {
101       return 1;
102     }
103
104     int aHashCode = 0;
105     if (theStyle.myHasColorSurf)
106     {
107       aHashCode = aHashCode ^ Quantity_ColorRGBAHasher::HashCode (theStyle.myColorSurf, theUpper);
108     }
109     if (theStyle.myHasColorCurv)
110     {
111       aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorCurv, theUpper);
112     }
113     return ((aHashCode & 0x7fffffff) % theUpper) + 1;
114   }
115
116   //! Returns True when the two keys are the same.
117   static Standard_Boolean IsEqual (const XCAFPrs_Style& theS1, const XCAFPrs_Style& theS2)
118   {
119     return theS1.IsEqual (theS2);
120   }
121
122 protected:
123
124   Quantity_ColorRGBA myColorSurf;
125   Quantity_Color     myColorCurv;
126   Standard_Boolean   myHasColorSurf;
127   Standard_Boolean   myHasColorCurv;
128   Standard_Boolean   myIsVisible;
129
130 };
131
132 #endif // _XCAFPrs_Style_HeaderFile