0029528: Visualization, TKOpenGl - allow defining sRGB textures
[occt.git] / src / XCAFDoc / XCAFDoc_ColorTool.hxx
CommitLineData
42cf5bc1 1// Created on: 2000-05-11
2// Created by: Edward AGAPOV
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 _XCAFDoc_ColorTool_HeaderFile
17#define _XCAFDoc_ColorTool_HeaderFile
18
19#include <Standard.hxx>
20#include <Standard_Type.hxx>
21
22#include <TDF_Attribute.hxx>
23#include <Standard_Boolean.hxx>
24#include <TDF_LabelSequence.hxx>
25#include <XCAFDoc_ColorType.hxx>
26class XCAFDoc_ShapeTool;
27class TDF_Label;
28class Standard_GUID;
29class Quantity_Color;
973d410e 30class Quantity_ColorRGBA;
42cf5bc1 31class TopoDS_Shape;
32class TDF_Attribute;
33class TDF_RelocationTable;
34
35
36class XCAFDoc_ColorTool;
37DEFINE_STANDARD_HANDLE(XCAFDoc_ColorTool, TDF_Attribute)
38
39//! Provides tools to store and retrieve attributes (colors)
40//! of TopoDS_Shape in and from TDocStd_Document
41//! A Document is intended to hold different
42//! attributes of ONE shape and it's sub-shapes
43//! Provide tools for management of Colors section of document.
44class XCAFDoc_ColorTool : public TDF_Attribute
45{
46
47public:
48
49
50 Standard_EXPORT XCAFDoc_ColorTool();
51
52 //! Creates (if not exist) ColorTool.
53 Standard_EXPORT static Handle(XCAFDoc_ColorTool) Set (const TDF_Label& L);
54
55 Standard_EXPORT static const Standard_GUID& GetID();
56
57 //! returns the label under which colors are stored
58 Standard_EXPORT TDF_Label BaseLabel() const;
59
60 //! Returns internal XCAFDoc_ShapeTool tool
61 Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
62
63 //! Returns True if label belongs to a colortable and
64 //! is a color definition
65 Standard_EXPORT Standard_Boolean IsColor (const TDF_Label& lab) const;
66
67 //! Returns color defined by label lab
68 //! Returns False if the label is not in colortable
69 //! or does not define a color
70 Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col) const;
973d410e 71
72 //! Returns color defined by label lab
73 //! Returns False if the label is not in colortable
74 //! or does not define a color
75 Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col) const;
42cf5bc1 76
77 //! Finds a color definition in a colortable and returns
78 //! its label if found
79 //! Returns False if color is not found in colortable
80 Standard_EXPORT Standard_Boolean FindColor (const Quantity_Color& col, TDF_Label& lab) const;
973d410e 81
82 //! Finds a color definition in a colortable and returns
83 //! its label if found
84 //! Returns False if color is not found in colortable
85 Standard_EXPORT Standard_Boolean FindColor(const Quantity_ColorRGBA& col, TDF_Label& lab) const;
42cf5bc1 86
87 //! Finds a color definition in a colortable and returns
88 //! its label if found (or Null label else)
89 Standard_EXPORT TDF_Label FindColor (const Quantity_Color& col) const;
973d410e 90
91 //! Finds a color definition in a colortable and returns
92 //! its label if found (or Null label else)
93 Standard_EXPORT TDF_Label FindColor(const Quantity_ColorRGBA& col) const;
42cf5bc1 94
95 //! Adds a color definition to a colortable and returns
96 //! its label (returns existing label if the same color
97 //! is already defined)
98 Standard_EXPORT TDF_Label AddColor (const Quantity_Color& col) const;
973d410e 99
100 //! Adds a color definition to a colortable and returns
101 //! its label (returns existing label if the same color
102 //! is already defined)
103 Standard_EXPORT TDF_Label AddColor(const Quantity_ColorRGBA& col) const;
42cf5bc1 104
105 //! Removes color from the colortable
106 Standard_EXPORT void RemoveColor (const TDF_Label& lab) const;
107
108 //! Returns a sequence of colors currently stored
109 //! in the colortable
110 Standard_EXPORT void GetColors (TDF_LabelSequence& Labels) const;
111
112 //! Sets a link with GUID defined by <type> (see
113 //! XCAFDoc::ColorRefGUID()) from label <L> to color
114 //! defined by <colorL>. Color of shape is defined following way
115 //! in dependance with type of color.
116 //! If type of color is XCAFDoc_ColorGen - then this color
117 //! defines default color for surfaces and curves.
118 //! If for shape color with types XCAFDoc_ColorSurf or XCAFDoc_ColorCurv is specified
119 //! then such color overrides generic color.
120 Standard_EXPORT void SetColor (const TDF_Label& L, const TDF_Label& colorL, const XCAFDoc_ColorType type) const;
121
122 //! Sets a link with GUID defined by <type> (see
123 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
124 //! in the colortable
125 //! Adds a color as necessary
126 Standard_EXPORT void SetColor (const TDF_Label& L, const Quantity_Color& Color, const XCAFDoc_ColorType type) const;
973d410e 127
128 //! Sets a link with GUID defined by <type> (see
129 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
130 //! in the colortable
131 //! Adds a color as necessary
132 Standard_EXPORT void SetColor(const TDF_Label& L, const Quantity_ColorRGBA& Color, const XCAFDoc_ColorType type) const;
42cf5bc1 133
134 //! Removes a link with GUID defined by <type> (see
135 //! XCAFDoc::ColorRefGUID()) from label <L> to color
136 Standard_EXPORT void UnSetColor (const TDF_Label& L, const XCAFDoc_ColorType type) const;
137
138 //! Returns True if label <L> has a color assignment
139 //! of the type <type>
140 Standard_EXPORT Standard_Boolean IsSet (const TDF_Label& L, const XCAFDoc_ColorType type) const;
141
142 //! Returns label with color assigned to <L> as <type>
143 //! Returns False if no such color is assigned
144 Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, TDF_Label& colorL);
145
146 //! Returns color assigned to <L> as <type>
147 //! Returns False if no such color is assigned
148 Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color);
973d410e 149
150 //! Returns color assigned to <L> as <type>
151 //! Returns False if no such color is assigned
152 Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
42cf5bc1 153
154 //! Sets a link with GUID defined by <type> (see
155 //! XCAFDoc::ColorRefGUID()) from label <L> to color
156 //! defined by <colorL>
157 //! Returns False if cannot find a label for shape S
158 Standard_EXPORT Standard_Boolean SetColor (const TopoDS_Shape& S, const TDF_Label& colorL, const XCAFDoc_ColorType type);
159
160 //! Sets a link with GUID defined by <type> (see
161 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
162 //! in the colortable
163 //! Adds a color as necessary
164 //! Returns False if cannot find a label for shape S
165 Standard_EXPORT Standard_Boolean SetColor (const TopoDS_Shape& S, const Quantity_Color& Color, const XCAFDoc_ColorType type);
973d410e 166
167 //! Sets a link with GUID defined by <type> (see
168 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
169 //! in the colortable
170 //! Adds a color as necessary
171 //! Returns False if cannot find a label for shape S
172 Standard_EXPORT Standard_Boolean SetColor(const TopoDS_Shape& S, const Quantity_ColorRGBA& Color, const XCAFDoc_ColorType type);
42cf5bc1 173
174 //! Removes a link with GUID defined by <type> (see
175 //! XCAFDoc::ColorRefGUID()) from label <L> to color
176 //! Returns True if such link existed
177 Standard_EXPORT Standard_Boolean UnSetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type);
178
179 //! Returns True if label <L> has a color assignment
180 //! of the type <type>
181 Standard_EXPORT Standard_Boolean IsSet (const TopoDS_Shape& S, const XCAFDoc_ColorType type);
182
183 //! Returns label with color assigned to <L> as <type>
184 //! Returns False if no such color is assigned
185 Standard_EXPORT Standard_Boolean GetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type, TDF_Label& colorL);
186
187 //! Returns color assigned to <L> as <type>
188 //! Returns False if no such color is assigned
189 Standard_EXPORT Standard_Boolean GetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_Color& color);
973d410e 190
191 //! Returns color assigned to <L> as <type>
192 //! Returns False if no such color is assigned
193 Standard_EXPORT Standard_Boolean GetColor(const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
42cf5bc1 194
195 //! Return TRUE if object on this label is visible, FALSE if invisible.
196 Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& L) const;
197
198 //! Set the visibility of object on label. Do nothing if there no any object.
199 //! Set UAttribute with corresponding GUID.
200 Standard_EXPORT void SetVisibility (const TDF_Label& shapeLabel, const Standard_Boolean isvisible = Standard_True);
08b183fe 201
202 //! Return TRUE if object color defined by its Layer, FALSE if not.
203 Standard_EXPORT Standard_Boolean IsColorByLayer (const TDF_Label& L) const;
204
205 //! Set the Color defined by Layer flag on label. Do nothing if there no any object.
206 //! Set UAttribute with corresponding GUID.
207 Standard_EXPORT void SetColorByLayer (const TDF_Label& shapeLabel, const Standard_Boolean isColorByLayer = Standard_False);
208
42cf5bc1 209 //! Sets the color of component that styled with SHUO structure
210 //! Returns FALSE if no sush component found
211 //! NOTE: create SHUO structeure if it is necessary and if <isCreateSHUO>
212 Standard_EXPORT Standard_Boolean SetInstanceColor (const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, const Quantity_Color& color, const Standard_Boolean isCreateSHUO = Standard_True);
213
973d410e 214 //! Sets the color of component that styled with SHUO structure
215 //! Returns FALSE if no sush component found
216 //! NOTE: create SHUO structeure if it is necessary and if <isCreateSHUO>
217 Standard_EXPORT Standard_Boolean SetInstanceColor(const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, const Quantity_ColorRGBA& color, const Standard_Boolean isCreateSHUO = Standard_True);
218
42cf5bc1 219 //! Gets the color of component that styled with SHUO structure
220 //! Returns FALSE if no sush component or color type
221 Standard_EXPORT Standard_Boolean GetInstanceColor (const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, Quantity_Color& color);
973d410e 222
223 //! Gets the color of component that styled with SHUO structure
224 //! Returns FALSE if no sush component or color type
225 Standard_EXPORT Standard_Boolean GetInstanceColor(const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
42cf5bc1 226
227 //! Gets the visibility status of component that styled with SHUO structure
228 //! Returns FALSE if no sush component
229 Standard_EXPORT Standard_Boolean IsInstanceVisible (const TopoDS_Shape& theShape);
230
231 //! Reverses order in chains of TreeNodes (from Last to First) under
232 //! each Color Label since we became to use function ::Prepend()
233 //! instead of ::Append() in method SetColor() for acceleration
234 Standard_EXPORT Standard_Boolean ReverseChainsOfTreeNodes();
235
79104795 236 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
42cf5bc1 237
79104795 238 Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
42cf5bc1 239
79104795 240 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
42cf5bc1 241
79104795 242 Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
42cf5bc1 243
244
245
246
92efcf78 247 DEFINE_STANDARD_RTTIEXT(XCAFDoc_ColorTool,TDF_Attribute)
42cf5bc1 248
249protected:
250
251
252
253
254private:
255
256
257 Handle(XCAFDoc_ShapeTool) myShapeTool;
258
259
260};
261
262
263
264
265
266
267
268#endif // _XCAFDoc_ColorTool_HeaderFile