0029902: Data Exchange, XCAF - provide extended Material definition for visualization...
[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{
a4815d55 46public:
47 //! Returns current auto-naming mode; TRUE by default.
48 //! If TRUE then for added colors the TDataStd_Name attribute will be automatically added.
49 //! This setting is global.
50 Standard_EXPORT static Standard_Boolean AutoNaming();
51
52 //! See also AutoNaming().
53 Standard_EXPORT static void SetAutoNaming (Standard_Boolean theIsAutoNaming);
42cf5bc1 54
55public:
56
42cf5bc1 57 Standard_EXPORT XCAFDoc_ColorTool();
58
59 //! Creates (if not exist) ColorTool.
60 Standard_EXPORT static Handle(XCAFDoc_ColorTool) Set (const TDF_Label& L);
61
62 Standard_EXPORT static const Standard_GUID& GetID();
63
64 //! returns the label under which colors are stored
65 Standard_EXPORT TDF_Label BaseLabel() const;
66
67 //! Returns internal XCAFDoc_ShapeTool tool
68 Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
69
70 //! Returns True if label belongs to a colortable and
71 //! is a color definition
72 Standard_EXPORT Standard_Boolean IsColor (const TDF_Label& lab) const;
73
74 //! Returns color defined by label lab
75 //! Returns False if the label is not in colortable
76 //! or does not define a color
77 Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col) const;
973d410e 78
79 //! Returns color defined by label lab
80 //! Returns False if the label is not in colortable
81 //! or does not define a color
82 Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col) const;
42cf5bc1 83
84 //! Finds a color definition in a colortable and returns
85 //! its label if found
86 //! Returns False if color is not found in colortable
87 Standard_EXPORT Standard_Boolean FindColor (const Quantity_Color& col, TDF_Label& lab) const;
973d410e 88
89 //! Finds a color definition in a colortable and returns
90 //! its label if found
91 //! Returns False if color is not found in colortable
92 Standard_EXPORT Standard_Boolean FindColor(const Quantity_ColorRGBA& col, TDF_Label& lab) const;
42cf5bc1 93
94 //! Finds a color definition in a colortable and returns
95 //! its label if found (or Null label else)
96 Standard_EXPORT TDF_Label FindColor (const Quantity_Color& col) const;
973d410e 97
98 //! Finds a color definition in a colortable and returns
99 //! its label if found (or Null label else)
100 Standard_EXPORT TDF_Label FindColor(const Quantity_ColorRGBA& col) const;
42cf5bc1 101
102 //! Adds a color definition to a colortable and returns
103 //! its label (returns existing label if the same color
104 //! is already defined)
105 Standard_EXPORT TDF_Label AddColor (const Quantity_Color& col) const;
973d410e 106
107 //! Adds a color definition to a colortable and returns
108 //! its label (returns existing label if the same color
109 //! is already defined)
110 Standard_EXPORT TDF_Label AddColor(const Quantity_ColorRGBA& col) const;
42cf5bc1 111
112 //! Removes color from the colortable
113 Standard_EXPORT void RemoveColor (const TDF_Label& lab) const;
114
115 //! Returns a sequence of colors currently stored
116 //! in the colortable
117 Standard_EXPORT void GetColors (TDF_LabelSequence& Labels) const;
118
119 //! Sets a link with GUID defined by <type> (see
120 //! XCAFDoc::ColorRefGUID()) from label <L> to color
121 //! defined by <colorL>. Color of shape is defined following way
122 //! in dependance with type of color.
123 //! If type of color is XCAFDoc_ColorGen - then this color
124 //! defines default color for surfaces and curves.
125 //! If for shape color with types XCAFDoc_ColorSurf or XCAFDoc_ColorCurv is specified
126 //! then such color overrides generic color.
127 Standard_EXPORT void SetColor (const TDF_Label& L, const TDF_Label& colorL, const XCAFDoc_ColorType type) const;
128
129 //! Sets a link with GUID defined by <type> (see
130 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
131 //! in the colortable
132 //! Adds a color as necessary
133 Standard_EXPORT void SetColor (const TDF_Label& L, const Quantity_Color& Color, const XCAFDoc_ColorType type) const;
973d410e 134
135 //! Sets a link with GUID defined by <type> (see
136 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
137 //! in the colortable
138 //! Adds a color as necessary
139 Standard_EXPORT void SetColor(const TDF_Label& L, const Quantity_ColorRGBA& Color, const XCAFDoc_ColorType type) const;
42cf5bc1 140
141 //! Removes a link with GUID defined by <type> (see
142 //! XCAFDoc::ColorRefGUID()) from label <L> to color
143 Standard_EXPORT void UnSetColor (const TDF_Label& L, const XCAFDoc_ColorType type) const;
144
145 //! Returns True if label <L> has a color assignment
146 //! of the type <type>
147 Standard_EXPORT Standard_Boolean IsSet (const TDF_Label& L, const XCAFDoc_ColorType type) const;
148
149 //! Returns label with color assigned to <L> as <type>
150 //! Returns False if no such color is assigned
151 Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, TDF_Label& colorL);
152
153 //! Returns color assigned to <L> as <type>
154 //! Returns False if no such color is assigned
155 Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color);
973d410e 156
157 //! Returns color assigned to <L> as <type>
158 //! Returns False if no such color is assigned
159 Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
42cf5bc1 160
161 //! Sets a link with GUID defined by <type> (see
162 //! XCAFDoc::ColorRefGUID()) from label <L> to color
163 //! defined by <colorL>
164 //! Returns False if cannot find a label for shape S
165 Standard_EXPORT Standard_Boolean SetColor (const TopoDS_Shape& S, const TDF_Label& colorL, const XCAFDoc_ColorType type);
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_Color& Color, const XCAFDoc_ColorType type);
973d410e 173
174 //! Sets a link with GUID defined by <type> (see
175 //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
176 //! in the colortable
177 //! Adds a color as necessary
178 //! Returns False if cannot find a label for shape S
179 Standard_EXPORT Standard_Boolean SetColor(const TopoDS_Shape& S, const Quantity_ColorRGBA& Color, const XCAFDoc_ColorType type);
42cf5bc1 180
181 //! Removes a link with GUID defined by <type> (see
182 //! XCAFDoc::ColorRefGUID()) from label <L> to color
183 //! Returns True if such link existed
184 Standard_EXPORT Standard_Boolean UnSetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type);
185
186 //! Returns True if label <L> has a color assignment
187 //! of the type <type>
188 Standard_EXPORT Standard_Boolean IsSet (const TopoDS_Shape& S, const XCAFDoc_ColorType type);
189
190 //! Returns label with color assigned to <L> as <type>
191 //! Returns False if no such color is assigned
192 Standard_EXPORT Standard_Boolean GetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type, TDF_Label& colorL);
193
194 //! Returns color assigned to <L> as <type>
195 //! Returns False if no such color is assigned
196 Standard_EXPORT Standard_Boolean GetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_Color& color);
973d410e 197
198 //! Returns color assigned to <L> as <type>
199 //! Returns False if no such color is assigned
200 Standard_EXPORT Standard_Boolean GetColor(const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
42cf5bc1 201
202 //! Return TRUE if object on this label is visible, FALSE if invisible.
203 Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& L) const;
204
205 //! Set the visibility of object on label. Do nothing if there no any object.
206 //! Set UAttribute with corresponding GUID.
207 Standard_EXPORT void SetVisibility (const TDF_Label& shapeLabel, const Standard_Boolean isvisible = Standard_True);
08b183fe 208
209 //! Return TRUE if object color defined by its Layer, FALSE if not.
210 Standard_EXPORT Standard_Boolean IsColorByLayer (const TDF_Label& L) const;
211
212 //! Set the Color defined by Layer flag on label. Do nothing if there no any object.
213 //! Set UAttribute with corresponding GUID.
214 Standard_EXPORT void SetColorByLayer (const TDF_Label& shapeLabel, const Standard_Boolean isColorByLayer = Standard_False);
215
42cf5bc1 216 //! Sets the color of component that styled with SHUO structure
217 //! Returns FALSE if no sush component found
218 //! NOTE: create SHUO structeure if it is necessary and if <isCreateSHUO>
219 Standard_EXPORT Standard_Boolean SetInstanceColor (const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, const Quantity_Color& color, const Standard_Boolean isCreateSHUO = Standard_True);
220
973d410e 221 //! Sets the color of component that styled with SHUO structure
222 //! Returns FALSE if no sush component found
223 //! NOTE: create SHUO structeure if it is necessary and if <isCreateSHUO>
224 Standard_EXPORT Standard_Boolean SetInstanceColor(const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, const Quantity_ColorRGBA& color, const Standard_Boolean isCreateSHUO = Standard_True);
225
42cf5bc1 226 //! Gets the color of component that styled with SHUO structure
227 //! Returns FALSE if no sush component or color type
228 Standard_EXPORT Standard_Boolean GetInstanceColor (const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, Quantity_Color& color);
973d410e 229
230 //! Gets the color of component that styled with SHUO structure
231 //! Returns FALSE if no sush component or color type
232 Standard_EXPORT Standard_Boolean GetInstanceColor(const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
42cf5bc1 233
234 //! Gets the visibility status of component that styled with SHUO structure
235 //! Returns FALSE if no sush component
236 Standard_EXPORT Standard_Boolean IsInstanceVisible (const TopoDS_Shape& theShape);
237
238 //! Reverses order in chains of TreeNodes (from Last to First) under
239 //! each Color Label since we became to use function ::Prepend()
240 //! instead of ::Append() in method SetColor() for acceleration
241 Standard_EXPORT Standard_Boolean ReverseChainsOfTreeNodes();
242
79104795 243 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
42cf5bc1 244
79104795 245 Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
42cf5bc1 246
79104795 247 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
42cf5bc1 248
79104795 249 Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
42cf5bc1 250
251
252
253
92efcf78 254 DEFINE_STANDARD_RTTIEXT(XCAFDoc_ColorTool,TDF_Attribute)
42cf5bc1 255
256protected:
257
258
259
260
261private:
262
263
264 Handle(XCAFDoc_ShapeTool) myShapeTool;
265
266
267};
268
269
270
271
272
273
274
275#endif // _XCAFDoc_ColorTool_HeaderFile