1 // Created on: 2000-08-30
2 // Created by: data exchange team
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.
17 #include <Standard_GUID.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDataStd_Name.hxx>
20 #include <TDataStd_TreeNode.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_Data.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_RelocationTable.hxx>
25 #include <TDF_Tool.hxx>
26 #include <TDocStd_Document.hxx>
27 #include <XCAFDoc_ColorTool.hxx>
28 #include <XCAFDoc_DimTolTool.hxx>
29 #include <XCAFDoc_DocumentTool.hxx>
30 #include <XCAFDoc_LayerTool.hxx>
31 #include <XCAFDoc_MaterialTool.hxx>
32 #include <XCAFDoc_ShapeTool.hxx>
33 #include <XCAFDoc_ViewTool.hxx>
35 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DocumentTool,TDF_Attribute)
37 //=======================================================================
40 //=======================================================================
41 const Standard_GUID& XCAFDoc_DocumentTool::GetID()
43 static Standard_GUID DocumentToolID ("efd212ec-6dfd-11d4-b9c8-0060b0ee281b");
44 return DocumentToolID;
48 //=======================================================================
50 //purpose : Returns a reference id to find a tree node attribute at the root
52 //=======================================================================
54 static const Standard_GUID& GetDocumentToolRefID()
56 static Standard_GUID DocumentToolRefID ("efd212eb-6dfd-11d4-b9c8-0060b0ee281b");
57 return DocumentToolRefID;
62 //=======================================================================
65 //=======================================================================
67 Handle(XCAFDoc_DocumentTool) XCAFDoc_DocumentTool::Set(const TDF_Label& L,
68 const Standard_Boolean IsAcces)
70 Handle(XCAFDoc_DocumentTool) A;
71 TDF_Label aL = DocLabel (L);
72 if (!aL.FindAttribute (XCAFDoc_DocumentTool::GetID(), A)) {
76 A = new XCAFDoc_DocumentTool;
79 // set ShapeTool, ColorTool and LayerTool attributes
80 XCAFDoc_ShapeTool::Set(ShapesLabel(L));
81 XCAFDoc_ColorTool::Set(ColorsLabel(L));
82 XCAFDoc_LayerTool::Set(LayersLabel(L));
83 XCAFDoc_DimTolTool::Set(DGTsLabel(L));
84 XCAFDoc_MaterialTool::Set(MaterialsLabel(L));
85 XCAFDoc_ViewTool::Set(ViewsLabel(L));
91 //=======================================================================
94 //=======================================================================
96 TDF_Label XCAFDoc_DocumentTool::DocLabel(const TDF_Label& acces)
98 TDF_Label DocL, RootL = acces.Root();
99 const Standard_GUID& aRefGuid = GetDocumentToolRefID();
100 Handle(TDataStd_TreeNode) aRootNode, aLabNode;
102 if (RootL.FindAttribute (aRefGuid, aRootNode)) {
103 aLabNode = aRootNode->First();
104 DocL = aLabNode->Label();
108 DocL = RootL.FindChild(1);
113 //=======================================================================
114 //function : Constructor
116 //=======================================================================
118 XCAFDoc_DocumentTool::XCAFDoc_DocumentTool()
123 //=======================================================================
124 //function : ShapesLabel
126 //=======================================================================
128 TDF_Label XCAFDoc_DocumentTool::ShapesLabel(const TDF_Label& acces)
130 TDF_Label L = DocLabel(acces).FindChild(1,Standard_True);
131 TDataStd_Name::Set(L, "Shapes");
136 //=======================================================================
137 //function : ColorsLabel
139 //=======================================================================
141 TDF_Label XCAFDoc_DocumentTool::ColorsLabel(const TDF_Label& acces)
143 TDF_Label L = DocLabel(acces).FindChild(2,Standard_True);
144 TDataStd_Name::Set(L, "Colors");
149 //=======================================================================
150 //function : LayersLabel
152 //=======================================================================
154 TDF_Label XCAFDoc_DocumentTool::LayersLabel(const TDF_Label& acces)
156 TDF_Label L = DocLabel(acces).FindChild(3,Standard_True);
157 TDataStd_Name::Set(L, "Layers");
162 //=======================================================================
163 //function : DGTsLabel
165 //=======================================================================
167 TDF_Label XCAFDoc_DocumentTool::DGTsLabel(const TDF_Label& acces)
169 TDF_Label L = DocLabel(acces).FindChild(4,Standard_True);
170 TDataStd_Name::Set(L, "D>s");
175 //=======================================================================
176 //function : MaterialsLabel
178 //=======================================================================
180 TDF_Label XCAFDoc_DocumentTool::MaterialsLabel(const TDF_Label& acces)
182 TDF_Label L = DocLabel(acces).FindChild(5,Standard_True);
183 TDataStd_Name::Set(L, "Materials");
188 //=======================================================================
189 //function : ViewsLabel
191 //=======================================================================
193 TDF_Label XCAFDoc_DocumentTool::ViewsLabel(const TDF_Label& acces)
195 TDF_Label L = DocLabel(acces).FindChild(7, Standard_True);
196 TDataStd_Name::Set(L, "Views");
201 //=======================================================================
202 //function : ShapeTool
204 //=======================================================================
206 Handle(XCAFDoc_ShapeTool) XCAFDoc_DocumentTool::ShapeTool(const TDF_Label& acces)
208 return XCAFDoc_ShapeTool::Set(ShapesLabel(acces));
212 //=======================================================================
213 //function : ColorTool
215 //=======================================================================
217 Handle(XCAFDoc_ColorTool) XCAFDoc_DocumentTool::ColorTool (const TDF_Label& acces)
219 return XCAFDoc_ColorTool::Set(ColorsLabel(acces));
223 //=======================================================================
224 //function : LayerTool
226 //=======================================================================
228 Handle(XCAFDoc_LayerTool) XCAFDoc_DocumentTool::LayerTool (const TDF_Label& acces)
230 return XCAFDoc_LayerTool::Set(LayersLabel(acces));
234 //=======================================================================
235 //function : DimTolTool
237 //=======================================================================
239 Handle(XCAFDoc_DimTolTool) XCAFDoc_DocumentTool::DimTolTool(const TDF_Label& acces)
241 return XCAFDoc_DimTolTool::Set(DGTsLabel(acces));
245 //=======================================================================
246 //function : MaterialTool
248 //=======================================================================
250 Handle(XCAFDoc_MaterialTool) XCAFDoc_DocumentTool::MaterialTool(const TDF_Label& acces)
252 return XCAFDoc_MaterialTool::Set(MaterialsLabel(acces));
255 //=======================================================================
256 //function : ViewTool
258 //=======================================================================
260 Handle(XCAFDoc_ViewTool) XCAFDoc_DocumentTool::ViewTool(const TDF_Label& acces)
262 return XCAFDoc_ViewTool::Set(ViewsLabel(acces));
266 //=======================================================================
269 //=======================================================================
271 const Standard_GUID& XCAFDoc_DocumentTool::ID() const
277 //=======================================================================
280 //=======================================================================
282 void XCAFDoc_DocumentTool::Restore(const Handle(TDF_Attribute)& /* with */)
287 //=======================================================================
288 //function : NewEmpty
290 //=======================================================================
292 Handle(TDF_Attribute) XCAFDoc_DocumentTool::NewEmpty() const
294 return new XCAFDoc_DocumentTool;
298 //=======================================================================
301 //=======================================================================
303 void XCAFDoc_DocumentTool::Paste (const Handle(TDF_Attribute)& /* into */,
304 const Handle(TDF_RelocationTable)& /* RT */) const
309 //=======================================================================
312 //=======================================================================
314 void XCAFDoc_DocumentTool::Init() const
316 TDF_Label DocL = Label(), RootL = DocL.Root();
317 const Standard_GUID& aRefGuid = GetDocumentToolRefID();
318 Handle(TDataStd_TreeNode) aRootNode, aLabNode;
320 if (!RootL.FindAttribute (aRefGuid, aRootNode)) {
321 Handle(TDataStd_TreeNode) aRootNodeNew = TDataStd_TreeNode::Set (RootL, aRefGuid);
322 Handle(TDataStd_TreeNode) aLNode = TDataStd_TreeNode::Set (DocL, aRefGuid);
323 aLNode->SetFather (aRootNodeNew);
324 aRootNodeNew->SetFirst (aLNode);
329 //=======================================================================
330 //function : IsXCAFDocument
332 //=======================================================================
334 Standard_Boolean XCAFDoc_DocumentTool::IsXCAFDocument(const Handle(TDocStd_Document)& D)
336 TDF_Label RootL = D->Main().Root();
337 const Standard_GUID& aRefGuid = GetDocumentToolRefID();
338 Handle(TDataStd_TreeNode) aRootNode;
339 return RootL.FindAttribute (aRefGuid, aRootNode);