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 | |
16 | #include <XCAFDoc_DocumentTool.ixx> | |
17 | #include <TDataStd_Name.hxx> | |
18 | #include <TDF_Data.hxx> | |
19 | #include <TDF_Tool.hxx> | |
388fc344 | 20 | #include <TDataStd_TreeNode.hxx> |
7fd59977 | 21 | |
22 | //======================================================================= | |
23 | //function : GetID | |
24 | //purpose : | |
25 | //======================================================================= | |
26 | ||
27 | const Standard_GUID& XCAFDoc_DocumentTool::GetID() | |
28 | { | |
29 | static Standard_GUID DocumentToolID ("efd212ec-6dfd-11d4-b9c8-0060b0ee281b"); | |
30 | return DocumentToolID; | |
31 | } | |
32 | ||
388fc344 RL |
33 | namespace { |
34 | //======================================================================= | |
35 | //function : GetRefID | |
36 | //purpose : Returns a reference id to find a tree node attribute at the root | |
37 | // label | |
38 | //======================================================================= | |
39 | ||
40 | static const Standard_GUID& GetDocumentToolRefID() | |
41 | { | |
42 | static Standard_GUID DocumentToolRefID ("efd212eb-6dfd-11d4-b9c8-0060b0ee281b"); | |
43 | return DocumentToolRefID; | |
44 | } | |
45 | } | |
46 | ||
7fd59977 | 47 | |
48 | //======================================================================= | |
49 | //function : Set | |
50 | //purpose : | |
51 | //======================================================================= | |
52 | ||
53 | Handle(XCAFDoc_DocumentTool) XCAFDoc_DocumentTool::Set(const TDF_Label& L, | |
54 | const Standard_Boolean IsAcces) | |
55 | { | |
56 | Handle(XCAFDoc_DocumentTool) A; | |
388fc344 RL |
57 | TDF_Label aL = DocLabel (L); |
58 | if (!aL.FindAttribute (XCAFDoc_DocumentTool::GetID(), A)) { | |
59 | if (!IsAcces) | |
60 | aL = L; | |
61 | ||
7fd59977 | 62 | A = new XCAFDoc_DocumentTool; |
388fc344 RL |
63 | aL.AddAttribute(A); |
64 | A->Init(); | |
7fd59977 | 65 | // set ShapeTool, ColorTool and LayerTool attributes |
66 | XCAFDoc_ShapeTool::Set(ShapesLabel(L)); | |
67 | XCAFDoc_ColorTool::Set(ColorsLabel(L)); | |
68 | XCAFDoc_LayerTool::Set(LayersLabel(L)); | |
69 | XCAFDoc_DimTolTool::Set(DGTsLabel(L)); | |
70 | XCAFDoc_MaterialTool::Set(MaterialsLabel(L)); | |
71 | } | |
72 | return A; | |
73 | } | |
74 | ||
75 | ||
76 | //======================================================================= | |
77 | //function : DocLabel | |
78 | //purpose : | |
79 | //======================================================================= | |
80 | ||
81 | TDF_Label XCAFDoc_DocumentTool::DocLabel(const TDF_Label& acces) | |
82 | { | |
83 | TDF_Label DocL, RootL = acces.Root(); | |
388fc344 RL |
84 | const Standard_GUID& aRefGuid = GetDocumentToolRefID(); |
85 | Handle(TDataStd_TreeNode) aRootNode, aLabNode; | |
86 | ||
87 | if (RootL.FindAttribute (aRefGuid, aRootNode)) { | |
88 | aLabNode = aRootNode->First(); | |
89 | DocL = aLabNode->Label(); | |
90 | return DocL; | |
91 | } | |
92 | ||
7fd59977 | 93 | DocL = RootL.FindChild(1); |
7fd59977 | 94 | return DocL; |
95 | } | |
96 | ||
97 | ||
98 | //======================================================================= | |
99 | //function : Constructor | |
100 | //purpose : | |
101 | //======================================================================= | |
102 | ||
103 | XCAFDoc_DocumentTool::XCAFDoc_DocumentTool() | |
104 | { | |
105 | } | |
106 | ||
107 | ||
108 | //======================================================================= | |
109 | //function : ShapesLabel | |
110 | //purpose : | |
111 | //======================================================================= | |
112 | ||
113 | TDF_Label XCAFDoc_DocumentTool::ShapesLabel(const TDF_Label& acces) | |
114 | { | |
115 | TDF_Label L = DocLabel(acces).FindChild(1,Standard_True); | |
116 | TDataStd_Name::Set(L, "Shapes"); | |
117 | return L; | |
118 | } | |
119 | ||
120 | ||
121 | //======================================================================= | |
122 | //function : ColorsLabel | |
123 | //purpose : | |
124 | //======================================================================= | |
125 | ||
126 | TDF_Label XCAFDoc_DocumentTool::ColorsLabel(const TDF_Label& acces) | |
127 | { | |
128 | TDF_Label L = DocLabel(acces).FindChild(2,Standard_True); | |
129 | TDataStd_Name::Set(L, "Colors"); | |
130 | return L; | |
131 | } | |
132 | ||
133 | ||
134 | //======================================================================= | |
135 | //function : LayersLabel | |
136 | //purpose : | |
137 | //======================================================================= | |
138 | ||
139 | TDF_Label XCAFDoc_DocumentTool::LayersLabel(const TDF_Label& acces) | |
140 | { | |
141 | TDF_Label L = DocLabel(acces).FindChild(3,Standard_True); | |
142 | TDataStd_Name::Set(L, "Layers"); | |
143 | return L; | |
144 | } | |
145 | ||
146 | ||
147 | //======================================================================= | |
148 | //function : DGTsLabel | |
149 | //purpose : | |
150 | //======================================================================= | |
151 | ||
152 | TDF_Label XCAFDoc_DocumentTool::DGTsLabel(const TDF_Label& acces) | |
153 | { | |
154 | TDF_Label L = DocLabel(acces).FindChild(4,Standard_True); | |
155 | TDataStd_Name::Set(L, "D>s"); | |
156 | return L; | |
157 | } | |
158 | ||
159 | ||
160 | //======================================================================= | |
161 | //function : MaterialsLabel | |
162 | //purpose : | |
163 | //======================================================================= | |
164 | ||
165 | TDF_Label XCAFDoc_DocumentTool::MaterialsLabel(const TDF_Label& acces) | |
166 | { | |
167 | TDF_Label L = DocLabel(acces).FindChild(5,Standard_True); | |
168 | TDataStd_Name::Set(L, "Materials"); | |
169 | return L; | |
170 | } | |
171 | ||
172 | ||
173 | //======================================================================= | |
174 | //function : ShapeTool | |
175 | //purpose : | |
176 | //======================================================================= | |
177 | ||
178 | Handle(XCAFDoc_ShapeTool) XCAFDoc_DocumentTool::ShapeTool(const TDF_Label& acces) | |
179 | { | |
180 | return XCAFDoc_ShapeTool::Set(ShapesLabel(acces)); | |
181 | } | |
182 | ||
183 | ||
184 | //======================================================================= | |
185 | //function : ColorTool | |
186 | //purpose : | |
187 | //======================================================================= | |
188 | ||
189 | Handle(XCAFDoc_ColorTool) XCAFDoc_DocumentTool::ColorTool (const TDF_Label& acces) | |
190 | { | |
191 | return XCAFDoc_ColorTool::Set(ColorsLabel(acces)); | |
192 | } | |
193 | ||
194 | ||
195 | //======================================================================= | |
196 | //function : LayerTool | |
197 | //purpose : | |
198 | //======================================================================= | |
199 | ||
200 | Handle(XCAFDoc_LayerTool) XCAFDoc_DocumentTool::LayerTool (const TDF_Label& acces) | |
201 | { | |
202 | return XCAFDoc_LayerTool::Set(LayersLabel(acces)); | |
203 | } | |
204 | ||
205 | ||
206 | //======================================================================= | |
207 | //function : DimTolTool | |
208 | //purpose : | |
209 | //======================================================================= | |
210 | ||
211 | Handle(XCAFDoc_DimTolTool) XCAFDoc_DocumentTool::DimTolTool(const TDF_Label& acces) | |
212 | { | |
213 | return XCAFDoc_DimTolTool::Set(DGTsLabel(acces)); | |
214 | } | |
215 | ||
216 | ||
217 | //======================================================================= | |
218 | //function : MaterialTool | |
219 | //purpose : | |
220 | //======================================================================= | |
221 | ||
222 | Handle(XCAFDoc_MaterialTool) XCAFDoc_DocumentTool::MaterialTool(const TDF_Label& acces) | |
223 | { | |
224 | return XCAFDoc_MaterialTool::Set(MaterialsLabel(acces)); | |
225 | } | |
226 | ||
227 | ||
228 | //======================================================================= | |
229 | //function : ID | |
230 | //purpose : | |
231 | //======================================================================= | |
232 | ||
233 | const Standard_GUID& XCAFDoc_DocumentTool::ID() const | |
234 | { | |
235 | return GetID(); | |
236 | } | |
237 | ||
238 | ||
239 | //======================================================================= | |
240 | //function : Restore | |
241 | //purpose : | |
242 | //======================================================================= | |
243 | ||
244 | void XCAFDoc_DocumentTool::Restore(const Handle(TDF_Attribute)& /* with */) | |
245 | { | |
246 | } | |
247 | ||
248 | ||
249 | //======================================================================= | |
250 | //function : NewEmpty | |
251 | //purpose : | |
252 | //======================================================================= | |
253 | ||
254 | Handle(TDF_Attribute) XCAFDoc_DocumentTool::NewEmpty() const | |
255 | { | |
256 | return new XCAFDoc_DocumentTool; | |
257 | } | |
258 | ||
259 | ||
260 | //======================================================================= | |
261 | //function : Paste | |
262 | //purpose : | |
263 | //======================================================================= | |
264 | ||
265 | void XCAFDoc_DocumentTool::Paste (const Handle(TDF_Attribute)& /* into */, | |
266 | const Handle(TDF_RelocationTable)& /* RT */) const | |
267 | { | |
268 | } | |
269 | ||
270 | ||
271 | //======================================================================= | |
272 | //function : Init | |
273 | //purpose : | |
274 | //======================================================================= | |
275 | ||
276 | void XCAFDoc_DocumentTool::Init() const | |
277 | { | |
278 | TDF_Label DocL = Label(), RootL = DocL.Root(); | |
388fc344 RL |
279 | const Standard_GUID& aRefGuid = GetDocumentToolRefID(); |
280 | Handle(TDataStd_TreeNode) aRootNode, aLabNode; | |
281 | ||
282 | if (!RootL.FindAttribute (aRefGuid, aRootNode)) { | |
283 | Handle(TDataStd_TreeNode) aRootNode = TDataStd_TreeNode::Set (RootL, aRefGuid); | |
284 | Handle(TDataStd_TreeNode) aLNode = TDataStd_TreeNode::Set (DocL, aRefGuid); | |
285 | aLNode->SetFather (aRootNode); | |
286 | aRootNode->SetFirst (aLNode); | |
287 | } | |
7fd59977 | 288 | } |
289 | ||
290 | ||
291 | //======================================================================= | |
292 | //function : IsXCAFDocument | |
293 | //purpose : | |
294 | //======================================================================= | |
295 | ||
296 | Standard_Boolean XCAFDoc_DocumentTool::IsXCAFDocument(const Handle(TDocStd_Document)& D) | |
297 | { | |
388fc344 RL |
298 | TDF_Label RootL = D->Main().Root(); |
299 | const Standard_GUID& aRefGuid = GetDocumentToolRefID(); | |
300 | Handle(TDataStd_TreeNode) aRootNode; | |
301 | return RootL.FindAttribute (aRefGuid, aRootNode); | |
7fd59977 | 302 | } |
f898928a RL |
303 | |
304 | ||
305 | //======================================================================= | |
306 | //function : Destroy | |
388fc344 | 307 | //purpose : No longer required. Kept for binary compatibility only. |
f898928a RL |
308 | //======================================================================= |
309 | ||
310 | void XCAFDoc_DocumentTool::Destroy() | |
311 | { | |
f898928a | 312 | } |