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