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