1 // Created on: 2000-09-26
2 // Created by: Pavel TELKOV.
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_LayerTool_HeaderFile
17 #define _XCAFDoc_LayerTool_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
22 #include <TDataStd_GenericEmpty.hxx>
23 #include <TDF_LabelSequence.hxx>
24 #include <TColStd_HSequenceOfExtendedString.hxx>
25 class XCAFDoc_ShapeTool;
28 class TCollection_ExtendedString;
32 class XCAFDoc_LayerTool;
33 DEFINE_STANDARD_HANDLE(XCAFDoc_LayerTool, TDataStd_GenericEmpty)
35 //! Provides tools to store and retrieve attributes (Layers)
36 //! of TopoDS_Shape in and from TDocStd_Document
37 //! A Document is intended to hold different
38 //! attributes of ONE shape and it's sub-shapes
39 //! Provide tools for management of Layers section of document.
40 class XCAFDoc_LayerTool : public TDataStd_GenericEmpty
46 Standard_EXPORT XCAFDoc_LayerTool();
48 //! Creates (if not exist) LayerTool.
49 Standard_EXPORT static Handle(XCAFDoc_LayerTool) Set (const TDF_Label& L);
51 Standard_EXPORT static const Standard_GUID& GetID();
53 //! returns the label under which Layers are stored
54 Standard_EXPORT TDF_Label BaseLabel() const;
56 //! Returns internal XCAFDoc_ShapeTool tool
57 Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
59 //! Returns True if label belongs to a Layertable and
60 //! is a Layer definition
61 Standard_EXPORT Standard_Boolean IsLayer (const TDF_Label& lab) const;
63 //! Returns Layer defined by label lab
64 //! Returns False if the label is not in Layertable
65 //! or does not define a Layer
66 Standard_EXPORT Standard_Boolean GetLayer (const TDF_Label& lab, TCollection_ExtendedString& aLayer) const;
68 //! Finds a Layer definition in a Layertable and returns
69 //! its label if found
70 //! Returns False if Layer is not found in Layertable
71 Standard_EXPORT Standard_Boolean FindLayer (const TCollection_ExtendedString& aLayer, TDF_Label& lab) const;
73 //! Finds a Layer definition in a Layertable by name
74 //! Returns first founded label with the same name if <theToFindWithProperty> is false
75 //! If <theToFindWithProperty> is true returns first label that
76 //! contains or not contains visible attr, according to the <theToFindVisible> parameter
77 Standard_EXPORT TDF_Label FindLayer (const TCollection_ExtendedString& aLayer, const Standard_Boolean theToFindWithProperty = Standard_False, const Standard_Boolean theToFindVisible = Standard_True) const;
79 //! Adds a Layer definition to a Layertable and returns
80 //! its label (returns existing label if the same Layer
81 //! is already defined)
82 Standard_EXPORT TDF_Label AddLayer (const TCollection_ExtendedString& theLayer) const;
84 //! Adds a Layer definition to a Layertable and returns its label
85 //! Returns existing label (if it is already defined)
86 //! of visible or invisible layer, according to <theToFindVisible> parameter
87 Standard_EXPORT TDF_Label AddLayer(const TCollection_ExtendedString& theLayer, const Standard_Boolean theToFindVisible) const;
89 //! Removes Layer from the Layertable
90 Standard_EXPORT void RemoveLayer (const TDF_Label& lab) const;
92 //! Returns a sequence of Layers currently stored
94 Standard_EXPORT void GetLayerLabels (TDF_LabelSequence& Labels) const;
96 //! Sets a link from label <L> to Layer
97 //! defined by <LayerL>
98 //! optional parameter <shapeInOneLayer> show could shape be
99 //! in number of layers or only in one.
100 Standard_EXPORT void SetLayer (const TDF_Label& L, const TDF_Label& LayerL, const Standard_Boolean shapeInOneLayer = Standard_False) const;
102 //! Sets a link from label <L> to Layer <aLayer>
103 //! in the Layertable
104 //! Adds a Layer as necessary
105 //! optional parameter <shapeInOneLayer> show could shape be
106 //! in number of layers or only in one.
107 Standard_EXPORT void SetLayer (const TDF_Label& L, const TCollection_ExtendedString& aLayer, const Standard_Boolean shapeInOneLayer = Standard_False) const;
109 //! Removes a link from label <L> to all layers
110 Standard_EXPORT void UnSetLayers (const TDF_Label& L) const;
112 //! Remove link from label <L> and Layer <aLayer>.
113 //! returns FALSE if no such layer.
114 Standard_EXPORT Standard_Boolean UnSetOneLayer (const TDF_Label& L, const TCollection_ExtendedString& aLayer) const;
116 //! Remove link from label <L> and Layer <aLayerL>.
117 //! returns FALSE if <aLayerL> is not a layer label.
118 Standard_EXPORT Standard_Boolean UnSetOneLayer (const TDF_Label& L, const TDF_Label& aLayerL) const;
120 //! Returns True if label <L> has a Layer associated
121 //! with the <aLayer>.
122 Standard_EXPORT Standard_Boolean IsSet (const TDF_Label& L, const TCollection_ExtendedString& aLayer) const;
124 //! Returns True if label <L> has a Layer associated
125 //! with the <aLayerL> label.
126 Standard_EXPORT Standard_Boolean IsSet (const TDF_Label& L, const TDF_Label& aLayerL) const;
128 //! Return sequence of strings <aLayerS> that associated with label <L>.
129 Standard_EXPORT Standard_Boolean GetLayers (const TDF_Label& L, Handle(TColStd_HSequenceOfExtendedString)& aLayerS);
131 //! Return sequence of labels <aLayerSL> that associated with label <L>.
132 Standard_EXPORT Standard_Boolean GetLayers (const TDF_Label& L, TDF_LabelSequence& aLayerLS);
134 //! Return sequence of strings that associated with label <L>.
135 Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetLayers (const TDF_Label& L);
137 //! Return sequanese of shape labels that assigned with layers to <ShLabels>.
138 Standard_EXPORT static void GetShapesOfLayer (const TDF_Label& theLayerL, TDF_LabelSequence& theShLabels);
140 //! Return TRUE if layer is visible, FALSE if invisible.
141 Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& layerL) const;
143 //! Set the visibility of layer. If layer is invisible when on it's layer
144 //! will set UAttribute with corresponding GUID.
145 Standard_EXPORT void SetVisibility (const TDF_Label& layerL, const Standard_Boolean isvisible = Standard_True) const;
147 //! Sets a link from label that containing shape <Sh>
148 //! with layer that situated at label <LayerL>.
149 //! optional parameter <shapeInOneLayer> show could shape be
150 //! in number of layers or only in one.
151 //! return FALSE if no such shape <Sh> or label <LayerL>
152 Standard_EXPORT Standard_Boolean SetLayer (const TopoDS_Shape& Sh, const TDF_Label& LayerL, const Standard_Boolean shapeInOneLayer = Standard_False);
154 //! Sets a link from label that containing shape <Sh>
155 //! with layer <aLayer>. Add <aLayer> to LayerTable if nessesery.
156 //! optional parameter <shapeInOneLayer> show could shape be
157 //! in number of layers or only in one.
158 //! return FALSE if no such shape <Sh>.
159 Standard_EXPORT Standard_Boolean SetLayer (const TopoDS_Shape& Sh, const TCollection_ExtendedString& aLayer, const Standard_Boolean shapeInOneLayer = Standard_False);
161 //! Remove link between shape <Sh> and all Layers at LayerTable.
162 //! return FALSE if no such shape <Sh> in XCAF Document.
163 Standard_EXPORT Standard_Boolean UnSetLayers (const TopoDS_Shape& Sh);
165 //! Remove link between shape <Sh> and layer <aLayer>.
166 //! returns FALSE if no such layer <aLayer> or shape <Sh>.
167 Standard_EXPORT Standard_Boolean UnSetOneLayer (const TopoDS_Shape& Sh, const TCollection_ExtendedString& aLayer);
169 //! Remove link between shape <Sh> and layer <aLayerL>.
170 //! returns FALSE if no such layer <aLayerL> or shape <Sh>.
171 Standard_EXPORT Standard_Boolean UnSetOneLayer (const TopoDS_Shape& Sh, const TDF_Label& aLayerL);
173 //! Returns True if shape <Sh> has a Layer associated
174 //! with the <aLayer>.
175 Standard_EXPORT Standard_Boolean IsSet (const TopoDS_Shape& Sh, const TCollection_ExtendedString& aLayer);
177 //! Returns True if shape <Sh> has a Layer associated
178 //! with the <aLayerL>.
179 Standard_EXPORT Standard_Boolean IsSet (const TopoDS_Shape& Sh, const TDF_Label& aLayerL);
181 //! Return sequence of strings <aLayerS> that associated with shape <Sh>.
182 Standard_EXPORT Standard_Boolean GetLayers (const TopoDS_Shape& Sh, Handle(TColStd_HSequenceOfExtendedString)& aLayerS);
184 //! Return sequence of labels <aLayerLS> that associated with shape <Sh>.
185 Standard_EXPORT Standard_Boolean GetLayers (const TopoDS_Shape& Sh, TDF_LabelSequence& aLayerLS);
187 //! Return sequence of strings that associated with shape <Sh>.
188 Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetLayers (const TopoDS_Shape& Sh);
190 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
192 //! Dumps the content of me into the stream
193 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
196 DEFINE_DERIVED_ATTRIBUTE(XCAFDoc_LayerTool,TDataStd_GenericEmpty)
202 Handle(XCAFDoc_ShapeTool) myShapeTool;
213 #endif // _XCAFDoc_LayerTool_HeaderFile