42cf5bc1 |
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> |
650efe05 |
22 | #include <Quantity_ColorHasher.hxx> |
42cf5bc1 |
23 | |
650efe05 |
24 | //! Represents a set of styling settings applicable to a (sub)shape |
42cf5bc1 |
25 | class XCAFPrs_Style |
26 | { |
27 | public: |
28 | |
29 | DEFINE_STANDARD_ALLOC |
30 | |
650efe05 |
31 | //! Empty constructor - colors are unset, visibility is TRUE. |
42cf5bc1 |
32 | Standard_EXPORT XCAFPrs_Style(); |
650efe05 |
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; } |
39 | |
40 | //! Set surface color. |
42cf5bc1 |
41 | Standard_EXPORT void SetColorSurf (const Quantity_Color& col); |
42 | |
43 | //! Manage surface color setting |
44 | Standard_EXPORT void UnSetColorSurf(); |
45 | |
650efe05 |
46 | //! Return TRUE if curve color has been defined. |
47 | Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; } |
48 | |
49 | //! Return curve color. |
50 | const Quantity_Color& GetColorCurv() const { return myColorCurv; } |
51 | |
52 | //! Set curve color. |
42cf5bc1 |
53 | Standard_EXPORT void SetColorCurv (const Quantity_Color& col); |
54 | |
55 | //! Manage curve color setting |
56 | Standard_EXPORT void UnSetColorCurv(); |
42cf5bc1 |
57 | |
650efe05 |
58 | //! Assign visibility. |
59 | void SetVisibility (const Standard_Boolean theVisibility) { myIsVisible = theVisibility; } |
42cf5bc1 |
60 | |
650efe05 |
61 | //! Manage visibility. |
62 | Standard_Boolean IsVisible() const { return myIsVisible; } |
42cf5bc1 |
63 | |
650efe05 |
64 | //! Returns True if styles are the same |
65 | //! Methods for using Style as key in maps |
66 | Standard_Boolean IsEqual (const XCAFPrs_Style& theOther) const |
67 | { |
68 | if (myIsVisible != theOther.myIsVisible) |
69 | { |
70 | return false; |
71 | } |
72 | else if (!myIsVisible) |
73 | { |
74 | return true; |
75 | } |
76 | |
77 | return myHasColorSurf == theOther.myHasColorSurf |
78 | && myHasColorCurv == theOther.myHasColorCurv |
79 | && (!myHasColorSurf || myColorSurf == theOther.myColorSurf) |
80 | && (!myHasColorCurv || myColorCurv == theOther.myColorCurv); |
81 | } |
82 | |
83 | //! Returns True if styles are the same. |
84 | Standard_Boolean operator== (const XCAFPrs_Style& theOther) const |
85 | { |
86 | return IsEqual (theOther); |
87 | } |
88 | |
89 | //! Returns a HasCode value. |
90 | static Standard_Integer HashCode (const XCAFPrs_Style& theStyle, |
91 | const Standard_Integer theUpper) |
92 | { |
93 | if (!theStyle.myIsVisible) |
94 | { |
95 | return 1; |
96 | } |
97 | |
98 | int aHashCode = 0; |
99 | if (theStyle.myHasColorSurf) |
100 | { |
101 | aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorSurf, theUpper); |
102 | } |
103 | if (theStyle.myHasColorCurv) |
104 | { |
105 | aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorCurv, theUpper); |
106 | } |
107 | return ((aHashCode & 0x7fffffff) % theUpper) + 1; |
108 | } |
109 | |
110 | //! Returns True when the two keys are the same. |
111 | static Standard_Boolean IsEqual (const XCAFPrs_Style& theS1, const XCAFPrs_Style& theS2) |
112 | { |
113 | return theS1.IsEqual (theS2); |
114 | } |
42cf5bc1 |
115 | |
116 | protected: |
117 | |
650efe05 |
118 | Quantity_Color myColorSurf; |
119 | Quantity_Color myColorCurv; |
120 | Standard_Boolean myHasColorSurf; |
121 | Standard_Boolean myHasColorCurv; |
122 | Standard_Boolean myIsVisible; |
42cf5bc1 |
123 | |
124 | }; |
125 | |
42cf5bc1 |
126 | #endif // _XCAFPrs_Style_HeaderFile |