Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:33

0001 // Created on: 2000-05-11
0002 // Created by: Edward AGAPOV
0003 // Copyright (c) 2000-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _XCAFDoc_ColorTool_HeaderFile
0017 #define _XCAFDoc_ColorTool_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_Type.hxx>
0021 
0022 #include <TDataStd_GenericEmpty.hxx>
0023 #include <Standard_Boolean.hxx>
0024 #include <TDF_LabelSequence.hxx>
0025 #include <XCAFDoc_ColorType.hxx>
0026 class XCAFDoc_ShapeTool;
0027 class TDF_Label;
0028 class Standard_GUID;
0029 class Quantity_Color;
0030 class Quantity_ColorRGBA;
0031 class TopoDS_Shape;
0032 
0033 
0034 class XCAFDoc_ColorTool;
0035 DEFINE_STANDARD_HANDLE(XCAFDoc_ColorTool, TDataStd_GenericEmpty)
0036 
0037 //! Provides tools to store and retrieve attributes (colors)
0038 //! of TopoDS_Shape in and from TDocStd_Document
0039 //! A Document is intended to hold different
0040 //! attributes of ONE shape and it's sub-shapes
0041 //! Provide tools for management of Colors section of document.
0042 class XCAFDoc_ColorTool : public TDataStd_GenericEmpty
0043 {
0044 public:
0045   //! Returns current auto-naming mode; TRUE by default.
0046   //! If TRUE then for added colors the TDataStd_Name attribute will be automatically added.
0047   //! This setting is global.
0048   Standard_EXPORT static Standard_Boolean AutoNaming();
0049 
0050   //! See also AutoNaming().
0051   Standard_EXPORT static void SetAutoNaming (Standard_Boolean theIsAutoNaming);
0052 
0053 public:
0054 
0055   Standard_EXPORT XCAFDoc_ColorTool();
0056   
0057   //! Creates (if not exist) ColorTool.
0058   Standard_EXPORT static Handle(XCAFDoc_ColorTool) Set (const TDF_Label& L);
0059   
0060   Standard_EXPORT static const Standard_GUID& GetID();
0061   
0062   //! returns the label under which colors are stored
0063   Standard_EXPORT TDF_Label BaseLabel() const;
0064   
0065   //! Returns internal XCAFDoc_ShapeTool tool
0066   Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
0067   
0068   //! Returns True if label belongs to a colortable and
0069   //! is a color definition
0070   Standard_EXPORT Standard_Boolean IsColor (const TDF_Label& lab) const;
0071   
0072   //! Returns color defined by label lab
0073   //! Returns False if the label is not in colortable
0074   //! or does not define a color
0075   Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col);
0076 
0077   //! Returns color defined by label lab
0078   //! Returns False if the label is not in colortable
0079   //! or does not define a color
0080   Standard_EXPORT static Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col);
0081   
0082   //! Finds a color definition in a colortable and returns
0083   //! its label if found
0084   //! Returns False if color is not found in colortable
0085   Standard_EXPORT Standard_Boolean FindColor (const Quantity_Color& col, TDF_Label& lab) const;
0086 
0087   //! Finds a color definition in a colortable and returns
0088   //! its label if found
0089   //! Returns False if color is not found in colortable
0090   Standard_EXPORT Standard_Boolean FindColor(const Quantity_ColorRGBA& col, TDF_Label& lab) const;
0091   
0092   //! Finds a color definition in a colortable and returns
0093   //! its label if found (or Null label else)
0094   Standard_EXPORT TDF_Label FindColor (const Quantity_Color& col) const;
0095 
0096   //! Finds a color definition in a colortable and returns
0097   //! its label if found (or Null label else)
0098   Standard_EXPORT TDF_Label FindColor(const Quantity_ColorRGBA& col) const;
0099   
0100   //! Adds a color definition to a colortable and returns
0101   //! its label (returns existing label if the same color
0102   //! is already defined)
0103   Standard_EXPORT TDF_Label AddColor (const Quantity_Color& col) const;
0104 
0105   //! Adds a color definition to a colortable and returns
0106   //! its label (returns existing label if the same color
0107   //! is already defined)
0108   Standard_EXPORT TDF_Label AddColor(const Quantity_ColorRGBA& col) const;
0109   
0110   //! Removes color from the colortable
0111   Standard_EXPORT void RemoveColor (const TDF_Label& lab) const;
0112   
0113   //! Returns a sequence of colors currently stored
0114   //! in the colortable
0115   Standard_EXPORT void GetColors (TDF_LabelSequence& Labels) const;
0116   
0117   //! Sets a link with GUID defined by <type> (see
0118   //! XCAFDoc::ColorRefGUID()) from label <L> to color
0119   //! defined by <colorL>. Color of shape is defined following way
0120   //! in dependance with type of color.
0121   //! If type of color is XCAFDoc_ColorGen - then this color
0122   //! defines default color for surfaces and curves.
0123   //! If for shape color with types XCAFDoc_ColorSurf or XCAFDoc_ColorCurv is specified
0124   //! then such color overrides generic color.
0125   Standard_EXPORT void SetColor (const TDF_Label& L, const TDF_Label& colorL, const XCAFDoc_ColorType type) const;
0126   
0127   //! Sets a link with GUID defined by <type> (see
0128   //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
0129   //! in the colortable
0130   //! Adds a color as necessary
0131   Standard_EXPORT void SetColor (const TDF_Label& L, const Quantity_Color& Color, const XCAFDoc_ColorType type) const;
0132 
0133   //! Sets a link with GUID defined by <type> (see
0134   //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
0135   //! in the colortable
0136   //! Adds a color as necessary
0137   Standard_EXPORT void SetColor(const TDF_Label& L, const Quantity_ColorRGBA& Color, const XCAFDoc_ColorType type) const;
0138   
0139   //! Removes a link with GUID defined by <type> (see
0140   //! XCAFDoc::ColorRefGUID()) from label <L> to color
0141   Standard_EXPORT void UnSetColor (const TDF_Label& L, const XCAFDoc_ColorType type) const;
0142   
0143   //! Returns True if label <L> has a color assignment
0144   //! of the type <type>
0145   Standard_EXPORT Standard_Boolean IsSet (const TDF_Label& L, const XCAFDoc_ColorType type) const;
0146   
0147   //! Returns label with color assigned to <L> as <type>
0148   //! Returns False if no such color is assigned
0149   Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, TDF_Label& colorL);
0150   
0151   //! Returns color assigned to <L> as <type>
0152   //! Returns False if no such color is assigned
0153   Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color);
0154 
0155   //! Returns color assigned to <L> as <type>
0156   //! Returns False if no such color is assigned
0157   Standard_EXPORT static Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
0158   
0159   //! Sets a link with GUID defined by <type> (see
0160   //! XCAFDoc::ColorRefGUID()) from label <L> to color
0161   //! defined by <colorL>
0162   //! Returns False if cannot find a label for shape S
0163   Standard_EXPORT Standard_Boolean SetColor (const TopoDS_Shape& S, const TDF_Label& colorL, const XCAFDoc_ColorType type);
0164   
0165   //! Sets a link with GUID defined by <type> (see
0166   //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
0167   //! in the colortable
0168   //! Adds a color as necessary
0169   //! Returns False if cannot find a label for shape S
0170   Standard_EXPORT Standard_Boolean SetColor (const TopoDS_Shape& S, const Quantity_Color& Color, const XCAFDoc_ColorType type);
0171 
0172   //! Sets a link with GUID defined by <type> (see
0173   //! XCAFDoc::ColorRefGUID()) from label <L> to color <Color>
0174   //! in the colortable
0175   //! Adds a color as necessary
0176   //! Returns False if cannot find a label for shape S
0177   Standard_EXPORT Standard_Boolean SetColor(const TopoDS_Shape& S, const Quantity_ColorRGBA& Color, const XCAFDoc_ColorType type);
0178   
0179   //! Removes a link with GUID defined by <type> (see
0180   //! XCAFDoc::ColorRefGUID()) from label <L> to color
0181   //! Returns True if such link existed
0182   Standard_EXPORT Standard_Boolean UnSetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type);
0183   
0184   //! Returns True if label <L> has a color assignment
0185   //! of the type <type>
0186   Standard_EXPORT Standard_Boolean IsSet (const TopoDS_Shape& S, const XCAFDoc_ColorType type);
0187   
0188   //! Returns label with color assigned to <L> as <type>
0189   //! Returns False if no such color is assigned
0190   Standard_EXPORT Standard_Boolean GetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type, TDF_Label& colorL);
0191   
0192   //! Returns color assigned to <L> as <type>
0193   //! Returns False if no such color is assigned
0194   Standard_EXPORT Standard_Boolean GetColor (const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_Color& color);
0195 
0196   //! Returns color assigned to <L> as <type>
0197   //! Returns False if no such color is assigned
0198   Standard_EXPORT Standard_Boolean GetColor(const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
0199   
0200   //! Return TRUE if object on this label is visible, FALSE if invisible.
0201   Standard_EXPORT static Standard_Boolean IsVisible (const TDF_Label& L);
0202   
0203   //! Set the visibility of object on label. Do nothing if there no any object.
0204   //! Set UAttribute with corresponding GUID.
0205   Standard_EXPORT void SetVisibility (const TDF_Label& shapeLabel, const Standard_Boolean isvisible = Standard_True);
0206 
0207   //! Return TRUE if object color defined by its Layer, FALSE if not.
0208   Standard_EXPORT Standard_Boolean IsColorByLayer (const TDF_Label& L) const;
0209 
0210   //! Set the Color defined by Layer flag on label. Do nothing if there no any object.
0211   //! Set UAttribute with corresponding GUID.
0212   Standard_EXPORT void SetColorByLayer (const TDF_Label& shapeLabel, const Standard_Boolean isColorByLayer = Standard_False);
0213 
0214   //! Sets the color of component that styled with SHUO structure
0215   //! Returns FALSE if no sush component found
0216   //! NOTE: create SHUO structeure if it is necessary and if <isCreateSHUO>
0217   Standard_EXPORT Standard_Boolean SetInstanceColor (const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, const Quantity_Color& color, const Standard_Boolean isCreateSHUO = Standard_True);
0218   
0219   //! Sets the color of component that styled with SHUO structure
0220   //! Returns FALSE if no sush component found
0221   //! NOTE: create SHUO structeure if it is necessary and if <isCreateSHUO>
0222   Standard_EXPORT Standard_Boolean SetInstanceColor(const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, const Quantity_ColorRGBA& color, const Standard_Boolean isCreateSHUO = Standard_True);
0223 
0224   //! Gets the color of component that styled with SHUO structure
0225   //! Returns FALSE if no sush component or color type
0226   Standard_EXPORT Standard_Boolean GetInstanceColor (const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, Quantity_Color& color);
0227 
0228   //! Gets the color of component that styled with SHUO structure
0229   //! Returns FALSE if no sush component or color type
0230   Standard_EXPORT Standard_Boolean GetInstanceColor(const TopoDS_Shape& theShape, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
0231   
0232   //! Gets the visibility status of component that styled with SHUO structure
0233   //! Returns FALSE if no sush component
0234   Standard_EXPORT Standard_Boolean IsInstanceVisible (const TopoDS_Shape& theShape);
0235   
0236   //! Reverses order in chains of TreeNodes (from Last to First) under
0237   //! each Color Label since we became to use function ::Prepend()
0238   //! instead of ::Append() in method SetColor() for acceleration
0239   Standard_EXPORT Standard_Boolean ReverseChainsOfTreeNodes();
0240   
0241   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
0242   
0243   //! Dumps the content of me into the stream
0244   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0245 
0246 
0247   DEFINE_DERIVED_ATTRIBUTE(XCAFDoc_ColorTool,TDataStd_GenericEmpty)
0248 
0249 private:
0250 
0251 
0252   Handle(XCAFDoc_ShapeTool) myShapeTool;
0253 
0254 
0255 };
0256 
0257 
0258 
0259 
0260 
0261 
0262 
0263 #endif // _XCAFDoc_ColorTool_HeaderFile