1 // Created on: 2000-08-16
2 // Created by: data exchange team
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 #include <XCAFDoc_Color.hxx>
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>
27 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Color,TDF_Attribute)
29 //=======================================================================
30 //function : Constructor
32 //=======================================================================
33 XCAFDoc_Color::XCAFDoc_Color()
37 //=======================================================================
40 //=======================================================================
42 const Standard_GUID& XCAFDoc_Color::GetID()
44 static Standard_GUID ColorID ("efd212f0-6dfd-11d4-b9c8-0060b0ee281b");
48 //=======================================================================
51 //=======================================================================
53 Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
54 const Quantity_Color& C)
56 Handle(XCAFDoc_Color) A;
57 if (!L.FindAttribute (XCAFDoc_Color::GetID(), A)) {
58 A = new XCAFDoc_Color ();
65 //=======================================================================
68 //=======================================================================
70 Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
71 const Quantity_ColorRGBA& C)
73 Handle(XCAFDoc_Color) A;
74 if (!L.FindAttribute(XCAFDoc_Color::GetID(), A)) {
75 A = new XCAFDoc_Color();
82 //=======================================================================
85 //=======================================================================
87 Handle(XCAFDoc_Color) XCAFDoc_Color::Set(const TDF_Label& L,
88 const Quantity_NameOfColor C)
90 Handle(XCAFDoc_Color) A;
91 if (!L.FindAttribute (XCAFDoc_Color::GetID(), A)) {
92 A = new XCAFDoc_Color ();
99 //=======================================================================
102 //=======================================================================
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)
110 Handle(XCAFDoc_Color) A;
111 if (!L.FindAttribute (XCAFDoc_Color::GetID(), A)) {
112 A = new XCAFDoc_Color ();
115 A->Set (R,G,B, alpha);
119 //=======================================================================
122 //=======================================================================
124 void XCAFDoc_Color::Set(const Quantity_Color& C)
130 //=======================================================================
133 //=======================================================================
135 void XCAFDoc_Color::Set(const Quantity_ColorRGBA& C)
141 //=======================================================================
144 //=======================================================================
146 void XCAFDoc_Color::Set(const Quantity_NameOfColor C)
152 //=======================================================================
155 //=======================================================================
157 void XCAFDoc_Color::Set(const Standard_Real R,
158 const Standard_Real G,
159 const Standard_Real B,
160 const Standard_Real alpha)
163 Quantity_Color aColor;
164 aColor.SetValues(R, G, B, Quantity_TOC_RGB);
165 myColor.SetRGB(aColor);
166 myColor.SetAlpha((Standard_ShortReal)alpha);
169 //=======================================================================
170 //function : GetColor
172 //=======================================================================
174 const Quantity_Color& XCAFDoc_Color::GetColor() const
176 return myColor.GetRGB();
179 //=======================================================================
180 //function : GetColorRGBA
182 //=======================================================================
184 const Quantity_ColorRGBA& XCAFDoc_Color::GetColorRGBA() const
189 //=======================================================================
192 //=======================================================================
194 Quantity_NameOfColor XCAFDoc_Color::GetNOC() const
196 return myColor.GetRGB().Name();
199 //=======================================================================
202 //=======================================================================
204 void XCAFDoc_Color::GetRGB(Standard_Real& R,
206 Standard_Real& B) const
208 myColor.GetRGB().Values(R,G,B, Quantity_TOC_RGB);
211 //=======================================================================
214 //=======================================================================
216 Standard_ShortReal XCAFDoc_Color::GetAlpha() const
218 return myColor.Alpha();
220 //=======================================================================
223 //=======================================================================
225 const Standard_GUID& XCAFDoc_Color::ID() const
230 //=======================================================================
233 //=======================================================================
235 void XCAFDoc_Color::Restore(const Handle(TDF_Attribute)& With)
237 myColor = Handle(XCAFDoc_Color)::DownCast(With)->GetColorRGBA();
240 //=======================================================================
241 //function : NewEmpty
243 //=======================================================================
245 Handle(TDF_Attribute) XCAFDoc_Color::NewEmpty() const
247 return new XCAFDoc_Color();
250 //=======================================================================
253 //=======================================================================
255 void XCAFDoc_Color::Paste(const Handle(TDF_Attribute)& Into,
256 const Handle(TDF_RelocationTable)& /* RT */) const
258 Handle(XCAFDoc_Color)::DownCast(Into)->Set(myColor);
261 //=======================================================================
262 //function : DumpJson
264 //=======================================================================
265 void XCAFDoc_Color::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
267 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
269 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
271 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myColor)