1 // Created on: 2000-05-11
2 // Created by: Edward AGAPOV
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 #ifndef _XCAFDoc_ColorTool_HeaderFile
17 #define _XCAFDoc_ColorTool_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <TDF_LabelSequence.hxx>
25 #include <XCAFDoc_ColorType.hxx>
26 class XCAFDoc_ShapeTool;
30 class Quantity_ColorRGBA;
33 class TDF_RelocationTable;
36 class XCAFDoc_ColorTool;
37 DEFINE_STANDARD_HANDLE(XCAFDoc_ColorTool, TDF_Attribute)
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.
44 class XCAFDoc_ColorTool : public TDF_Attribute
50 Standard_EXPORT XCAFDoc_ColorTool();
52 //! Creates (if not exist) ColorTool.
53 Standard_EXPORT static Handle(XCAFDoc_ColorTool) Set (const TDF_Label& L);
55 Standard_EXPORT static const Standard_GUID& GetID();
57 //! returns the label under which colors are stored
58 Standard_EXPORT TDF_Label BaseLabel() const;
60 //! Returns internal XCAFDoc_ShapeTool tool
61 Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
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;
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;
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;
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;
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;
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;
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;
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;
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;
105 //! Removes color from the colortable
106 Standard_EXPORT void RemoveColor (const TDF_Label& lab) const;
108 //! Returns a sequence of colors currently stored
109 //! in the colortable
110 Standard_EXPORT void GetColors (TDF_LabelSequence& Labels) const;
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;
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;
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;
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;
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;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
195 //! Return TRUE if object on this label is visible, FALSE if invisible.
196 Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& L) const;
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);
202 //! Return TRUE if object color defined by its Layer, FALSE if not.
203 Standard_EXPORT Standard_Boolean IsColorByLayer (const TDF_Label& L) const;
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);
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);
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);
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);
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);
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);
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();
236 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
238 Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
240 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
242 Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
247 DEFINE_STANDARD_RTTIEXT(XCAFDoc_ColorTool,TDF_Attribute)
257 Handle(XCAFDoc_ShapeTool) myShapeTool;
268 #endif // _XCAFDoc_ColorTool_HeaderFile