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
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();
52 //! See also AutoNaming().
53 Standard_EXPORT static void SetAutoNaming (Standard_Boolean theIsAutoNaming);
57 Standard_EXPORT XCAFDoc_ColorTool();
59 //! Creates (if not exist) ColorTool.
60 Standard_EXPORT static Handle(XCAFDoc_ColorTool) Set (const TDF_Label& L);
62 Standard_EXPORT static const Standard_GUID& GetID();
64 //! returns the label under which colors are stored
65 Standard_EXPORT TDF_Label BaseLabel() const;
67 //! Returns internal XCAFDoc_ShapeTool tool
68 Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
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;
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;
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;
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;
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;
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;
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;
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;
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;
112 //! Removes color from the colortable
113 Standard_EXPORT void RemoveColor (const TDF_Label& lab) const;
115 //! Returns a sequence of colors currently stored
116 //! in the colortable
117 Standard_EXPORT void GetColors (TDF_LabelSequence& Labels) const;
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;
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;
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;
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;
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;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
202 //! Return TRUE if object on this label is visible, FALSE if invisible.
203 Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& L) const;
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);
209 //! Return TRUE if object color defined by its Layer, FALSE if not.
210 Standard_EXPORT Standard_Boolean IsColorByLayer (const TDF_Label& L) const;
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);
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);
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);
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);
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);
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);
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();
243 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
245 Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
247 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
249 Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
251 //! Dumps the content of me into the stream
252 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
257 DEFINE_STANDARD_RTTIEXT(XCAFDoc_ColorTool,TDF_Attribute)
267 Handle(XCAFDoc_ShapeTool) myShapeTool;
278 #endif // _XCAFDoc_ColorTool_HeaderFile