0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / XCAFDoc / XCAFDoc_Color.cxx
1 // Created on: 2000-08-16
2 // Created by: data exchange team
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 #include <XCAFDoc_Color.hxx>
17
18 #include <Quantity_Color.hxx>
19 #include <Quantity_ColorRGBA.hxx>
20 #include <Standard_Dump.hxx>
21 #include <Standard_GUID.hxx>
22 #include <Standard_Type.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_RelocationTable.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Color,TDF_Attribute)
28
29 //=======================================================================
30 //function : Constructor
31 //purpose  : 
32 //=======================================================================
33 XCAFDoc_Color::XCAFDoc_Color()
34 {
35 }
36
37 //=======================================================================
38 //function : GetID
39 //purpose  : 
40 //=======================================================================
41
42 const Standard_GUID& XCAFDoc_Color::GetID() 
43 {
44   static Standard_GUID ColorID ("efd212f0-6dfd-11d4-b9c8-0060b0ee281b");
45   return ColorID; 
46 }
47
48 //=======================================================================
49 //function : Set
50 //purpose  : 
51 //=======================================================================
52
53  Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
54                                           const Quantity_Color& C) 
55 {
56   Handle(XCAFDoc_Color) A;
57   if (!L.FindAttribute (XCAFDoc_Color::GetID(), A)) {
58     A = new XCAFDoc_Color ();
59     L.AddAttribute(A);
60   }
61   A->Set (C); 
62   return A;
63 }
64
65  //=======================================================================
66  //function : Set
67  //purpose  : 
68  //=======================================================================
69
70  Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
71    const Quantity_ColorRGBA& C)
72  {
73    Handle(XCAFDoc_Color) A;
74    if (!L.FindAttribute(XCAFDoc_Color::GetID(), A)) {
75      A = new XCAFDoc_Color();
76      L.AddAttribute(A);
77    }
78    A->Set(C);
79    return A;
80  }
81
82 //=======================================================================
83 //function : Set
84 //purpose  : 
85 //=======================================================================
86
87  Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
88                                           const Quantity_NameOfColor C) 
89 {
90   Handle(XCAFDoc_Color) A;
91   if (!L.FindAttribute (XCAFDoc_Color::GetID(), A)) {
92     A = new XCAFDoc_Color ();
93     L.AddAttribute(A);
94   }
95   A->Set (C); 
96   return A;
97 }
98
99 //=======================================================================
100 //function : Set
101 //purpose  : 
102 //=======================================================================
103
104 Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
105                                          const Standard_Real R,
106                                          const Standard_Real G,
107                                          const Standard_Real B,
108                                          const Standard_Real alpha) 
109 {
110   Handle(XCAFDoc_Color) A;
111   if (!L.FindAttribute (XCAFDoc_Color::GetID(), A)) {
112     A = new XCAFDoc_Color ();
113     L.AddAttribute(A);
114   }
115   A->Set (R,G,B, alpha); 
116   return A;
117 }
118
119 //=======================================================================
120 //function : Set
121 //purpose  : 
122 //=======================================================================
123
124 void XCAFDoc_Color::Set(const Quantity_Color& C) 
125 {
126   Backup();
127   myColor.SetRGB(C);
128 }
129
130 //=======================================================================
131 //function : Set
132 //purpose  : 
133 //=======================================================================
134
135 void XCAFDoc_Color::Set(const Quantity_ColorRGBA& C)
136 {
137   Backup();
138   myColor = C;
139 }
140
141 //=======================================================================
142 //function : Set
143 //purpose  : 
144 //=======================================================================
145
146  void XCAFDoc_Color::Set(const Quantity_NameOfColor C) 
147 {
148   Backup();
149   myColor.SetRGB(C);
150 }
151
152 //=======================================================================
153 //function : Set
154 //purpose  : 
155 //=======================================================================
156
157  void XCAFDoc_Color::Set(const Standard_Real R,
158                          const Standard_Real G,
159                          const Standard_Real B,
160                          const Standard_Real alpha) 
161 {
162   Backup();
163   Quantity_Color aColor;
164   aColor.SetValues(R, G, B, Quantity_TOC_RGB);
165   myColor.SetRGB(aColor);
166   myColor.SetAlpha((Standard_ShortReal)alpha);
167 }
168
169 //=======================================================================
170 //function : GetColor
171 //purpose  : 
172 //=======================================================================
173
174 const Quantity_Color& XCAFDoc_Color::GetColor() const
175 {
176   return myColor.GetRGB();
177 }
178
179 //=======================================================================
180 //function : GetColorRGBA
181 //purpose  : 
182 //=======================================================================
183
184 const Quantity_ColorRGBA& XCAFDoc_Color::GetColorRGBA() const
185 {
186   return myColor;
187 }
188
189 //=======================================================================
190 //function : GetNOC
191 //purpose  : 
192 //=======================================================================
193
194  Quantity_NameOfColor XCAFDoc_Color::GetNOC() const
195 {
196   return myColor.GetRGB().Name();
197 }
198
199 //=======================================================================
200 //function : GetRGB
201 //purpose  : 
202 //=======================================================================
203
204  void XCAFDoc_Color::GetRGB(Standard_Real& R,
205                                   Standard_Real& G,
206                                   Standard_Real& B) const
207 {
208   myColor.GetRGB().Values(R,G,B, Quantity_TOC_RGB);
209 }
210
211  //=======================================================================
212  //function : GetRGBA
213  //purpose  : 
214  //=======================================================================
215
216  Standard_ShortReal XCAFDoc_Color::GetAlpha() const
217  {
218    return myColor.Alpha();
219  }
220 //=======================================================================
221 //function : ID
222 //purpose  : 
223 //=======================================================================
224
225 const Standard_GUID& XCAFDoc_Color::ID() const
226 {
227   return GetID();
228 }
229
230 //=======================================================================
231 //function : Restore
232 //purpose  : 
233 //=======================================================================
234
235  void XCAFDoc_Color::Restore(const Handle(TDF_Attribute)& With) 
236 {
237   myColor = Handle(XCAFDoc_Color)::DownCast(With)->GetColorRGBA();
238 }
239
240 //=======================================================================
241 //function : NewEmpty
242 //purpose  : 
243 //=======================================================================
244
245  Handle(TDF_Attribute) XCAFDoc_Color::NewEmpty() const
246 {
247   return new XCAFDoc_Color();
248 }
249
250 //=======================================================================
251 //function : Paste
252 //purpose  : 
253 //=======================================================================
254
255  void XCAFDoc_Color::Paste(const Handle(TDF_Attribute)& Into,
256                                  const Handle(TDF_RelocationTable)& /* RT */) const
257 {
258   Handle(XCAFDoc_Color)::DownCast(Into)->Set(myColor);
259 }
260
261 //=======================================================================
262 //function : DumpJson
263 //purpose  : 
264 //=======================================================================
265 void XCAFDoc_Color::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
266 {
267   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
268
269   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
270
271   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myColor)
272 }