0028985: XCAF data structures for generic text annotations linked to GD&T annotations...
[occt.git] / src / XCAFDoc / XCAFDoc_DocumentTool.cxx
CommitLineData
b311480e 1// Created on: 2000-08-30
2// Created by: data exchange team
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
42cf5bc1 16
17#include <Standard_GUID.hxx>
18#include <Standard_Type.hxx>
7fd59977 19#include <TDataStd_Name.hxx>
42cf5bc1 20#include <TDataStd_TreeNode.hxx>
21#include <TDF_Attribute.hxx>
7fd59977 22#include <TDF_Data.hxx>
42cf5bc1 23#include <TDF_Label.hxx>
24#include <TDF_RelocationTable.hxx>
7fd59977 25#include <TDF_Tool.hxx>
42cf5bc1 26#include <TDocStd_Document.hxx>
27#include <XCAFDoc_ColorTool.hxx>
0c63f2f8 28#include <XCAFDoc_ClippingPlaneTool.hxx>
42cf5bc1 29#include <XCAFDoc_DimTolTool.hxx>
30#include <XCAFDoc_DocumentTool.hxx>
31#include <XCAFDoc_LayerTool.hxx>
32#include <XCAFDoc_MaterialTool.hxx>
024d6f77 33#include <XCAFDoc_NotesTool.hxx>
42cf5bc1 34#include <XCAFDoc_ShapeTool.hxx>
2df785d7 35#include <XCAFDoc_ViewTool.hxx>
7fd59977 36
92efcf78 37IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DocumentTool,TDF_Attribute)
38
7fd59977 39//=======================================================================
40//function : GetID
41//purpose :
42//=======================================================================
7fd59977 43const Standard_GUID& XCAFDoc_DocumentTool::GetID()
44{
45 static Standard_GUID DocumentToolID ("efd212ec-6dfd-11d4-b9c8-0060b0ee281b");
46 return DocumentToolID;
47}
48
388fc344
RL
49namespace {
50//=======================================================================
51//function : GetRefID
52//purpose : Returns a reference id to find a tree node attribute at the root
53// label
54//=======================================================================
55
56static const Standard_GUID& GetDocumentToolRefID()
57{
58 static Standard_GUID DocumentToolRefID ("efd212eb-6dfd-11d4-b9c8-0060b0ee281b");
59 return DocumentToolRefID;
60}
61}
62
7fd59977 63
64//=======================================================================
65//function : Set
66//purpose :
67//=======================================================================
68
69Handle(XCAFDoc_DocumentTool) XCAFDoc_DocumentTool::Set(const TDF_Label& L,
70 const Standard_Boolean IsAcces)
71{
72 Handle(XCAFDoc_DocumentTool) A;
388fc344
RL
73 TDF_Label aL = DocLabel (L);
74 if (!aL.FindAttribute (XCAFDoc_DocumentTool::GetID(), A)) {
75 if (!IsAcces)
76 aL = L;
77
7fd59977 78 A = new XCAFDoc_DocumentTool;
388fc344
RL
79 aL.AddAttribute(A);
80 A->Init();
7fd59977 81 // set ShapeTool, ColorTool and LayerTool attributes
82 XCAFDoc_ShapeTool::Set(ShapesLabel(L));
83 XCAFDoc_ColorTool::Set(ColorsLabel(L));
84 XCAFDoc_LayerTool::Set(LayersLabel(L));
85 XCAFDoc_DimTolTool::Set(DGTsLabel(L));
86 XCAFDoc_MaterialTool::Set(MaterialsLabel(L));
024d6f77 87 XCAFDoc_NotesTool::Set(NotesLabel(L));
2df785d7 88 XCAFDoc_ViewTool::Set(ViewsLabel(L));
0c63f2f8 89 XCAFDoc_ClippingPlaneTool::Set(ClippingPlanesLabel(L));
7fd59977 90 }
91 return A;
92}
93
94
95//=======================================================================
96//function : DocLabel
97//purpose :
98//=======================================================================
99
100TDF_Label XCAFDoc_DocumentTool::DocLabel(const TDF_Label& acces)
101{
102 TDF_Label DocL, RootL = acces.Root();
388fc344
RL
103 const Standard_GUID& aRefGuid = GetDocumentToolRefID();
104 Handle(TDataStd_TreeNode) aRootNode, aLabNode;
105
106 if (RootL.FindAttribute (aRefGuid, aRootNode)) {
107 aLabNode = aRootNode->First();
108 DocL = aLabNode->Label();
109 return DocL;
110 }
111
7fd59977 112 DocL = RootL.FindChild(1);
7fd59977 113 return DocL;
114}
115
116
117//=======================================================================
118//function : Constructor
119//purpose :
120//=======================================================================
121
122XCAFDoc_DocumentTool::XCAFDoc_DocumentTool()
123{
124}
125
126
127//=======================================================================
128//function : ShapesLabel
129//purpose :
130//=======================================================================
131
132TDF_Label XCAFDoc_DocumentTool::ShapesLabel(const TDF_Label& acces)
133{
134 TDF_Label L = DocLabel(acces).FindChild(1,Standard_True);
135 TDataStd_Name::Set(L, "Shapes");
136 return L;
137}
138
139
140//=======================================================================
141//function : ColorsLabel
142//purpose :
143//=======================================================================
144
145TDF_Label XCAFDoc_DocumentTool::ColorsLabel(const TDF_Label& acces)
146{
147 TDF_Label L = DocLabel(acces).FindChild(2,Standard_True);
148 TDataStd_Name::Set(L, "Colors");
149 return L;
150}
151
152
153//=======================================================================
154//function : LayersLabel
155//purpose :
156//=======================================================================
157
158TDF_Label XCAFDoc_DocumentTool::LayersLabel(const TDF_Label& acces)
159{
160 TDF_Label L = DocLabel(acces).FindChild(3,Standard_True);
161 TDataStd_Name::Set(L, "Layers");
162 return L;
163}
164
165
166//=======================================================================
167//function : DGTsLabel
168//purpose :
169//=======================================================================
170
171TDF_Label XCAFDoc_DocumentTool::DGTsLabel(const TDF_Label& acces)
172{
173 TDF_Label L = DocLabel(acces).FindChild(4,Standard_True);
174 TDataStd_Name::Set(L, "D&GTs");
175 return L;
176}
177
178
179//=======================================================================
180//function : MaterialsLabel
181//purpose :
182//=======================================================================
183
184TDF_Label XCAFDoc_DocumentTool::MaterialsLabel(const TDF_Label& acces)
185{
186 TDF_Label L = DocLabel(acces).FindChild(5,Standard_True);
187 TDataStd_Name::Set(L, "Materials");
188 return L;
189}
190
191
2df785d7 192//=======================================================================
193//function : ViewsLabel
194//purpose :
195//=======================================================================
196
197TDF_Label XCAFDoc_DocumentTool::ViewsLabel(const TDF_Label& acces)
198{
199 TDF_Label L = DocLabel(acces).FindChild(7, Standard_True);
200 TDataStd_Name::Set(L, "Views");
201 return L;
202}
203
0c63f2f8 204//=======================================================================
205//function : ClippingPlanesLabel
206//purpose :
207//=======================================================================
208
209TDF_Label XCAFDoc_DocumentTool::ClippingPlanesLabel(const TDF_Label& acces)
210{
211 TDF_Label L = DocLabel(acces).FindChild(8, Standard_True);
212 TDataStd_Name::Set(L, "Clipping Planes");
213 return L;
214}
2df785d7 215
024d6f77 216//=======================================================================
217//function : NotesLabel
218//purpose :
219//=======================================================================
220
221TDF_Label XCAFDoc_DocumentTool::NotesLabel(const TDF_Label& acces)
222{
223 TDF_Label L = DocLabel(acces).FindChild(9, Standard_True);
224 TDataStd_Name::Set(L, "Notes");
225 return L;
226}
227
7fd59977 228//=======================================================================
229//function : ShapeTool
230//purpose :
231//=======================================================================
232
233 Handle(XCAFDoc_ShapeTool) XCAFDoc_DocumentTool::ShapeTool(const TDF_Label& acces)
234{
235 return XCAFDoc_ShapeTool::Set(ShapesLabel(acces));
236}
237
238
239//=======================================================================
240//function : ColorTool
241//purpose :
242//=======================================================================
243
244Handle(XCAFDoc_ColorTool) XCAFDoc_DocumentTool::ColorTool (const TDF_Label& acces)
245{
246 return XCAFDoc_ColorTool::Set(ColorsLabel(acces));
247}
248
249
250//=======================================================================
251//function : LayerTool
252//purpose :
253//=======================================================================
254
255Handle(XCAFDoc_LayerTool) XCAFDoc_DocumentTool::LayerTool (const TDF_Label& acces)
256{
257 return XCAFDoc_LayerTool::Set(LayersLabel(acces));
258}
259
260
261//=======================================================================
262//function : DimTolTool
263//purpose :
264//=======================================================================
265
266Handle(XCAFDoc_DimTolTool) XCAFDoc_DocumentTool::DimTolTool(const TDF_Label& acces)
267{
268 return XCAFDoc_DimTolTool::Set(DGTsLabel(acces));
269}
270
271
272//=======================================================================
273//function : MaterialTool
274//purpose :
275//=======================================================================
276
277Handle(XCAFDoc_MaterialTool) XCAFDoc_DocumentTool::MaterialTool(const TDF_Label& acces)
278{
279 return XCAFDoc_MaterialTool::Set(MaterialsLabel(acces));
280}
281
2df785d7 282//=======================================================================
283//function : ViewTool
284//purpose :
285//=======================================================================
286
287Handle(XCAFDoc_ViewTool) XCAFDoc_DocumentTool::ViewTool(const TDF_Label& acces)
288{
289 return XCAFDoc_ViewTool::Set(ViewsLabel(acces));
290}
291
0c63f2f8 292//=======================================================================
293//function : ClippingPlaneTool
294//purpose :
295//=======================================================================
296
297Handle(XCAFDoc_ClippingPlaneTool) XCAFDoc_DocumentTool::ClippingPlaneTool(const TDF_Label& acces)
298{
299 return XCAFDoc_ClippingPlaneTool::Set(ClippingPlanesLabel(acces));
300}
7fd59977 301
024d6f77 302//=======================================================================
303//function : ClippingPlaneTool
304//purpose :
305//=======================================================================
306
307Handle(XCAFDoc_NotesTool) XCAFDoc_DocumentTool::NotesTool(const TDF_Label& acces)
308{
309 return XCAFDoc_NotesTool::Set(NotesLabel(acces));
310}
311
7fd59977 312//=======================================================================
313//function : ID
314//purpose :
315//=======================================================================
316
317const Standard_GUID& XCAFDoc_DocumentTool::ID() const
318{
319 return GetID();
320}
321
322
323//=======================================================================
324//function : Restore
325//purpose :
326//=======================================================================
327
328void XCAFDoc_DocumentTool::Restore(const Handle(TDF_Attribute)& /* with */)
329{
330}
331
332
333//=======================================================================
334//function : NewEmpty
335//purpose :
336//=======================================================================
337
338Handle(TDF_Attribute) XCAFDoc_DocumentTool::NewEmpty() const
339{
340 return new XCAFDoc_DocumentTool;
341}
342
343
344//=======================================================================
345//function : Paste
346//purpose :
347//=======================================================================
348
349void XCAFDoc_DocumentTool::Paste (const Handle(TDF_Attribute)& /* into */,
350 const Handle(TDF_RelocationTable)& /* RT */) const
351{
352}
353
354
355//=======================================================================
356//function : Init
357//purpose :
358//=======================================================================
359
360void XCAFDoc_DocumentTool::Init() const
361{
362 TDF_Label DocL = Label(), RootL = DocL.Root();
388fc344
RL
363 const Standard_GUID& aRefGuid = GetDocumentToolRefID();
364 Handle(TDataStd_TreeNode) aRootNode, aLabNode;
365
366 if (!RootL.FindAttribute (aRefGuid, aRootNode)) {
51740958 367 Handle(TDataStd_TreeNode) aRootNodeNew = TDataStd_TreeNode::Set (RootL, aRefGuid);
388fc344 368 Handle(TDataStd_TreeNode) aLNode = TDataStd_TreeNode::Set (DocL, aRefGuid);
51740958 369 aLNode->SetFather (aRootNodeNew);
370 aRootNodeNew->SetFirst (aLNode);
388fc344 371 }
7fd59977 372}
373
374
375//=======================================================================
376//function : IsXCAFDocument
377//purpose :
378//=======================================================================
379
380Standard_Boolean XCAFDoc_DocumentTool::IsXCAFDocument(const Handle(TDocStd_Document)& D)
381{
388fc344
RL
382 TDF_Label RootL = D->Main().Root();
383 const Standard_GUID& aRefGuid = GetDocumentToolRefID();
384 Handle(TDataStd_TreeNode) aRootNode;
385 return RootL.FindAttribute (aRefGuid, aRootNode);
7fd59977 386}