973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
bc73b006 |
14 | #include <XCAFDoc_Datum.hxx> |
7fd59977 |
15 | |
42cf5bc1 |
16 | #include <Standard_Type.hxx> |
42cf5bc1 |
17 | #include <TDF_Attribute.hxx> |
18 | #include <TDF_Label.hxx> |
1c9d3225 |
19 | #include <TDF_ChildIterator.hxx> |
7fd59977 |
20 | #include <TDF_RelocationTable.hxx> |
9ebaae37 |
21 | #include <TDataStd_AsciiString.hxx> |
22 | #include <TDataStd_IntegerArray.hxx> |
1c9d3225 |
23 | #include <TDataStd_RealArray.hxx> |
9ebaae37 |
24 | #include <TDataStd_Integer.hxx> |
25 | #include <TDataStd_Real.hxx> |
9ebaae37 |
26 | #include <TNaming_Builder.hxx> |
5df609e7 |
27 | #include <TNaming_Tool.hxx> |
28 | #include <TDataStd_Name.hxx> |
9ebaae37 |
29 | |
30 | #include <XCAFDimTolObjects_DatumObject.hxx> |
31 | |
92efcf78 |
32 | IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Datum,TDF_Attribute) |
33 | |
9ebaae37 |
34 | enum ChildLab |
35 | { |
e01ce0cd |
36 | ChildLab_Begin = 1, |
37 | ChildLab_Name = ChildLab_Begin, |
6595eee7 |
38 | ChildLab_Position, |
9ebaae37 |
39 | ChildLab_Modifiers, |
40 | ChildLab_ModifierWithValue, |
1c9d3225 |
41 | ChildLab_IsDTarget, |
42 | ChildLab_DTargetType, |
fbcef69b |
43 | ChildLab_AxisLoc, |
44 | ChildLab_AxisN, |
45 | ChildLab_AxisRef, |
1c9d3225 |
46 | ChildLab_DTargetLength, |
47 | ChildLab_DTargetWidth, |
6595eee7 |
48 | ChildLab_DTargetNumber, |
1c9d3225 |
49 | ChildLab_DatumTarget, |
fbcef69b |
50 | ChildLab_PlaneLoc, |
51 | ChildLab_PlaneN, |
52 | ChildLab_PlaneRef, |
5df609e7 |
53 | ChildLab_Pnt, |
54 | ChildLab_PntText, |
e01ce0cd |
55 | ChildLab_Presentation, |
56 | ChildLab_End |
9ebaae37 |
57 | }; |
7fd59977 |
58 | |
59 | //======================================================================= |
60 | //function : XCAFDoc_Datum |
61 | //purpose : |
62 | //======================================================================= |
7fd59977 |
63 | XCAFDoc_Datum::XCAFDoc_Datum() |
64 | { |
65 | } |
66 | |
67 | |
68 | //======================================================================= |
69 | //function : GetID |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | const Standard_GUID& XCAFDoc_Datum::GetID() |
74 | { |
75 | static Standard_GUID DID("58ed092e-44de-11d8-8776-001083004c77"); |
76 | //static Standard_GUID ID("efd212e2-6dfd-11d4-b9c8-0060b0ee281b"); |
77 | return DID; |
78 | //return ID; |
79 | } |
80 | |
81 | |
82 | //======================================================================= |
83 | //function : Set |
84 | //purpose : |
85 | //======================================================================= |
86 | |
9ebaae37 |
87 | Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& theLabel, |
88 | const Handle(TCollection_HAsciiString)& theName, |
89 | const Handle(TCollection_HAsciiString)& theDescription, |
90 | const Handle(TCollection_HAsciiString)& theIdentification) |
91 | { |
92 | Handle(XCAFDoc_Datum) aDatum; |
93 | if (!theLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) { |
94 | aDatum = new XCAFDoc_Datum(); |
95 | theLabel.AddAttribute(aDatum); |
96 | } |
97 | aDatum->Set(theName,theDescription,theIdentification); |
98 | return aDatum; |
99 | } |
100 | |
101 | //======================================================================= |
102 | //function : Set |
103 | //purpose : |
104 | //======================================================================= |
105 | |
106 | Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& theLabel) |
7fd59977 |
107 | { |
9ebaae37 |
108 | Handle(XCAFDoc_Datum) aDatum; |
109 | if (!theLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) { |
110 | aDatum = new XCAFDoc_Datum(); |
111 | theLabel.AddAttribute(aDatum); |
7fd59977 |
112 | } |
9ebaae37 |
113 | return aDatum; |
7fd59977 |
114 | } |
115 | |
116 | |
117 | //======================================================================= |
118 | //function : Set |
119 | //purpose : |
120 | //======================================================================= |
121 | |
9ebaae37 |
122 | void XCAFDoc_Datum::Set(const Handle(TCollection_HAsciiString)& theName, |
123 | const Handle(TCollection_HAsciiString)& theDescription, |
124 | const Handle(TCollection_HAsciiString)& theIdentification) |
7fd59977 |
125 | { |
9ebaae37 |
126 | Backup(); |
127 | myName = theName; |
128 | myDescription = theDescription; |
129 | myIdentification = theIdentification; |
7fd59977 |
130 | } |
131 | |
132 | |
133 | //======================================================================= |
134 | //function : GetName |
135 | //purpose : |
136 | //======================================================================= |
137 | |
138 | Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetName() const |
139 | { |
9ebaae37 |
140 | if(myName.IsNull()) |
141 | return new TCollection_HAsciiString(); |
7fd59977 |
142 | return myName; |
143 | } |
144 | |
7fd59977 |
145 | //======================================================================= |
9ebaae37 |
146 | //function : GetDescriptio7n |
7fd59977 |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetDescription() const |
151 | { |
152 | return myDescription; |
153 | } |
154 | |
155 | |
156 | //======================================================================= |
157 | //function : GetIdentification |
158 | //purpose : |
159 | //======================================================================= |
160 | |
161 | Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetIdentification() const |
162 | { |
163 | return myIdentification; |
164 | } |
165 | |
9ebaae37 |
166 | //======================================================================= |
167 | //function : SetObject |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | void XCAFDoc_Datum::SetObject(const Handle(XCAFDimTolObjects_DatumObject)& theObject) |
172 | { |
173 | Backup(); |
eacdb38f |
174 | |
175 | if (theObject->GetSemanticName()) |
176 | { |
177 | TCollection_ExtendedString str(theObject->GetSemanticName()->String()); |
178 | TDataStd_Name::Set(Label(), str); |
179 | } |
180 | |
e01ce0cd |
181 | for (int aChild = ChildLab_Begin; aChild < ChildLab_End; aChild++) |
1c9d3225 |
182 | { |
e01ce0cd |
183 | Label().FindChild(aChild).ForgetAllAttributes(); |
1c9d3225 |
184 | } |
185 | if (!theObject->GetName().IsNull() && !theObject->GetName()->IsEmpty()) |
5a1271c8 |
186 | Handle(TDataStd_AsciiString) anAttName = TDataStd_AsciiString::Set(Label().FindChild(ChildLab_Name), |
187 | theObject->GetName()->String()); |
9ebaae37 |
188 | |
fa53efef |
189 | Handle(TDataStd_Integer) aPosition = TDataStd_Integer::Set(Label().FindChild(ChildLab_Position), |
5a1271c8 |
190 | theObject->GetPosition()); |
6595eee7 |
191 | |
1c9d3225 |
192 | if(theObject->GetModifiers().Length() > 0) |
5a1271c8 |
193 | { |
9ebaae37 |
194 | Handle(TColStd_HArray1OfInteger) anArr = new TColStd_HArray1OfInteger(1,theObject->GetModifiers().Length()); |
195 | for(Standard_Integer i = 1; i <= theObject->GetModifiers().Length(); i++) |
196 | anArr->SetValue(i,theObject->GetModifiers().Value(i)); |
5a1271c8 |
197 | Handle(TDataStd_IntegerArray) aModifiers = TDataStd_IntegerArray::Set(Label().FindChild(ChildLab_Modifiers), |
198 | 1, theObject->GetModifiers().Length()); |
199 | if(!aModifiers.IsNull()) |
200 | aModifiers->ChangeArray(anArr); |
9ebaae37 |
201 | } |
202 | |
203 | XCAFDimTolObjects_DatumModifWithValue aM; |
204 | Standard_Real aV; |
205 | theObject->GetModifierWithValue(aM, aV); |
206 | if(aM != XCAFDimTolObjects_DatumModifWithValue_None) |
207 | { |
fa53efef |
208 | Handle(TDataStd_Integer) aModifierWithValueM = |
5a1271c8 |
209 | TDataStd_Integer::Set(Label().FindChild(ChildLab_ModifierWithValue), aM); |
fa53efef |
210 | |
211 | Handle(TDataStd_Real) aModifierWithValueV = |
5a1271c8 |
212 | TDataStd_Real::Set(Label().FindChild(ChildLab_ModifierWithValue), aV); |
9ebaae37 |
213 | } |
9ebaae37 |
214 | |
fa53efef |
215 | Handle(TDataStd_Integer) aIsTarget = TDataStd_Integer::Set(Label().FindChild(ChildLab_IsDTarget), |
5a1271c8 |
216 | theObject->IsDatumTarget()); |
1c9d3225 |
217 | |
218 | if(theObject->IsDatumTarget()) |
9ebaae37 |
219 | { |
fa53efef |
220 | Handle(TDataStd_Integer) aType = TDataStd_Integer::Set(Label().FindChild(ChildLab_DTargetType), |
5a1271c8 |
221 | theObject->GetDatumTargetType()); |
1c9d3225 |
222 | |
223 | if(theObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area) |
224 | { |
225 | if(!theObject->GetDatumTarget().IsNull()) |
226 | { |
227 | TNaming_Builder tnBuild(Label().FindChild(ChildLab_DatumTarget)); |
228 | tnBuild.Generated(theObject->GetDatumTarget()); |
229 | } |
230 | } |
400af1bc |
231 | else if (theObject->HasDatumTargetParams()) |
1c9d3225 |
232 | { |
1c9d3225 |
233 | gp_Ax2 anAx = theObject->GetDatumTargetAxis(); |
fbcef69b |
234 | Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3); |
235 | for (Standard_Integer i = 1; i <= 3; i++) |
236 | aLocArr->SetValue(i, anAx.Location().Coord(i)); |
237 | Handle(TDataStd_RealArray) aLoc = TDataStd_RealArray::Set(Label().FindChild(ChildLab_AxisLoc), 1, 3); |
238 | if (!aLoc.IsNull()) |
239 | aLoc->ChangeArray(aLocArr); |
240 | |
241 | Handle(TColStd_HArray1OfReal) aNArr = new TColStd_HArray1OfReal(1, 3); |
242 | for (Standard_Integer i = 1; i <= 3; i++) |
243 | aNArr->SetValue(i, anAx.Direction().Coord(i)); |
244 | Handle(TDataStd_RealArray) aN = TDataStd_RealArray::Set(Label().FindChild(ChildLab_AxisN), 1, 3); |
245 | if (!aN.IsNull()) |
246 | aN->ChangeArray(aNArr); |
247 | |
248 | Handle(TColStd_HArray1OfReal) aRArr = new TColStd_HArray1OfReal(1, 3); |
249 | for (Standard_Integer i = 1; i <= 3; i++) |
250 | aRArr->SetValue(i, anAx.XDirection().Coord(i)); |
251 | Handle(TDataStd_RealArray) aR = TDataStd_RealArray::Set(Label().FindChild(ChildLab_AxisRef), 1, 3); |
252 | if (!aR.IsNull()) |
253 | aR->ChangeArray(aRArr); |
1c9d3225 |
254 | |
255 | if(theObject->GetDatumTargetType() != XCAFDimTolObjects_DatumTargetType_Point) |
256 | { |
fa53efef |
257 | Handle(TDataStd_Real) aLen = TDataStd_Real::Set(Label().FindChild(ChildLab_DTargetLength), |
5a1271c8 |
258 | theObject->GetDatumTargetLength()); |
1c9d3225 |
259 | if(theObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Rectangle) |
fa53efef |
260 | Handle(TDataStd_Real) aWidth = TDataStd_Real::Set(Label().FindChild(ChildLab_DTargetWidth), |
5a1271c8 |
261 | theObject->GetDatumTargetWidth()); |
1c9d3225 |
262 | } |
263 | } |
fa53efef |
264 | Handle(TDataStd_Integer) aNum = TDataStd_Integer::Set(Label().FindChild(ChildLab_DTargetNumber), |
5a1271c8 |
265 | theObject->GetDatumTargetNumber()); |
9ebaae37 |
266 | } |
5df609e7 |
267 | |
268 | if (theObject->HasPlane()) |
269 | { |
fbcef69b |
270 | gp_Ax2 anAx = theObject->GetPlane(); |
271 | |
272 | Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3); |
273 | for (Standard_Integer i = 1; i <= 3; i++) |
274 | aLocArr->SetValue(i, anAx.Location().Coord(i)); |
275 | Handle(TDataStd_RealArray) aLoc = TDataStd_RealArray::Set(Label().FindChild(ChildLab_PlaneLoc), 1, 3); |
276 | if (!aLoc.IsNull()) |
277 | aLoc->ChangeArray(aLocArr); |
278 | |
279 | Handle(TColStd_HArray1OfReal) aNArr = new TColStd_HArray1OfReal(1, 3); |
280 | for (Standard_Integer i = 1; i <= 3; i++) |
281 | aNArr->SetValue(i, anAx.Direction().Coord(i)); |
282 | Handle(TDataStd_RealArray) aN = TDataStd_RealArray::Set(Label().FindChild(ChildLab_PlaneN), 1, 3); |
283 | if (!aN.IsNull()) |
284 | aN->ChangeArray(aNArr); |
285 | |
286 | Handle(TColStd_HArray1OfReal) aRArr = new TColStd_HArray1OfReal(1, 3); |
287 | for (Standard_Integer i = 1; i <= 3; i++) |
288 | aRArr->SetValue(i, anAx.XDirection().Coord(i)); |
289 | Handle(TDataStd_RealArray) aR = TDataStd_RealArray::Set(Label().FindChild(ChildLab_PlaneRef), 1, 3); |
290 | if (!aR.IsNull()) |
291 | aR->ChangeArray(aRArr); |
5df609e7 |
292 | } |
293 | |
294 | if (theObject->HasPoint()) |
295 | { |
fbcef69b |
296 | gp_Pnt aPnt = theObject->GetPoint(); |
297 | |
298 | Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3); |
299 | for (Standard_Integer i = 1; i <= 3; i++) |
300 | aLocArr->SetValue(i, aPnt.Coord(i)); |
301 | Handle(TDataStd_RealArray) aLoc = TDataStd_RealArray::Set(Label().FindChild(ChildLab_Pnt), 1, 3); |
302 | if (!aLoc.IsNull()) |
303 | aLoc->ChangeArray(aLocArr); |
5df609e7 |
304 | } |
305 | |
306 | if (theObject->HasPointText()) |
307 | { |
fbcef69b |
308 | gp_Pnt aPntText = theObject->GetPointTextAttach(); |
309 | |
310 | Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3); |
311 | for (Standard_Integer i = 1; i <= 3; i++) |
312 | aLocArr->SetValue(i, aPntText.Coord(i)); |
313 | Handle(TDataStd_RealArray) aLoc = TDataStd_RealArray::Set(Label().FindChild(ChildLab_PntText), 1, 3); |
314 | if (!aLoc.IsNull()) |
315 | aLoc->ChangeArray(aLocArr); |
5df609e7 |
316 | } |
b8bf9595 |
317 | |
5df609e7 |
318 | TopoDS_Shape aPresentation = theObject->GetPresentation(); |
319 | if( !aPresentation.IsNull()) |
320 | { |
321 | TDF_Label aLPres = Label().FindChild( ChildLab_Presentation); |
322 | TNaming_Builder tnBuild(aLPres); |
323 | tnBuild.Generated(aPresentation); |
324 | Handle(TCollection_HAsciiString) aName = theObject->GetPresentationName(); |
325 | if( !aName.IsNull() ) |
326 | { |
327 | TCollection_ExtendedString str ( aName->String() ); |
328 | TDataStd_Name::Set ( aLPres, str ); |
329 | } |
330 | } |
331 | |
9ebaae37 |
332 | } |
333 | |
334 | //======================================================================= |
335 | //function : GetObject |
336 | //purpose : |
337 | //======================================================================= |
338 | |
339 | Handle(XCAFDimTolObjects_DatumObject) XCAFDoc_Datum::GetObject() const |
340 | { |
341 | Handle(XCAFDimTolObjects_DatumObject) anObj = new XCAFDimTolObjects_DatumObject(); |
342 | |
eacdb38f |
343 | Handle(TDataStd_Name) aSemanticNameAttr; |
344 | Handle(TCollection_HAsciiString) aSemanticName; |
345 | if (Label().FindAttribute(TDataStd_Name::GetID(), aSemanticNameAttr)) |
346 | { |
347 | const TCollection_ExtendedString& aName = aSemanticNameAttr->Get(); |
348 | if (!aName.IsEmpty()) |
349 | aSemanticName = new TCollection_HAsciiString(aName); |
350 | } |
351 | anObj->SetSemanticName(aSemanticName); |
352 | |
9ebaae37 |
353 | Handle(TDataStd_AsciiString) anAttName; |
354 | if(Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), anAttName)) |
355 | { |
356 | Handle(TCollection_HAsciiString) aStr = new TCollection_HAsciiString(anAttName->Get()); |
357 | anObj->SetName(aStr); |
358 | } |
359 | |
360 | Handle(TDataStd_IntegerArray) anArr; |
361 | if(Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), anArr) |
362 | && !anArr->Array().IsNull()) |
363 | { |
364 | XCAFDimTolObjects_DatumModifiersSequence aModifiers; |
365 | for(Standard_Integer i = 1; i <= anArr->Length(); i++) |
366 | aModifiers.Append((XCAFDimTolObjects_DatumSingleModif)anArr->Value(i)); |
367 | anObj->SetModifiers(aModifiers); |
368 | } |
369 | |
370 | Handle(TDataStd_Integer) aModifierWithValueM; |
371 | if(Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Integer::GetID(), aModifierWithValueM)) |
372 | { |
373 | Handle(TDataStd_Real) aModifierWithValueV; |
374 | if(Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Real::GetID(), aModifierWithValueV)) |
375 | { |
376 | anObj->SetModifierWithValue((XCAFDimTolObjects_DatumModifWithValue)aModifierWithValueM->Get(),aModifierWithValueV->Get()); |
377 | } |
378 | } |
379 | |
6595eee7 |
380 | Handle(TDataStd_Integer) aPosition; |
381 | if(Label().FindChild(ChildLab_Position).FindAttribute(TDataStd_Integer::GetID(), aPosition)) |
382 | { |
383 | anObj->SetPosition(aPosition->Get()); |
384 | } |
385 | |
fbcef69b |
386 | Handle(TDataStd_RealArray) aLoc, aN, aR; |
387 | if (Label().FindChild(ChildLab_PlaneLoc).FindAttribute(TDataStd_RealArray::GetID(), aLoc) && aLoc->Length() == 3 && |
388 | Label().FindChild(ChildLab_PlaneN).FindAttribute(TDataStd_RealArray::GetID(), aN) && aN->Length() == 3 && |
389 | Label().FindChild(ChildLab_PlaneRef).FindAttribute(TDataStd_RealArray::GetID(), aR) && aR->Length() == 3) |
5df609e7 |
390 | { |
fbcef69b |
391 | gp_Pnt aL(aLoc->Value(aLoc->Lower()), aLoc->Value(aLoc->Lower() + 1), aLoc->Value(aLoc->Lower() + 2)); |
392 | gp_Dir aD(aN->Value(aN->Lower()), aN->Value(aN->Lower() + 1), aN->Value(aN->Lower() + 2)); |
393 | gp_Dir aDR(aR->Value(aR->Lower()), aR->Value(aR->Lower() + 1), aR->Value(aR->Lower() + 2)); |
394 | gp_Ax2 anAx(aL, aD, aDR); |
5df609e7 |
395 | anObj->SetPlane(anAx); |
396 | } |
397 | |
fbcef69b |
398 | Handle(TDataStd_RealArray) aPnt; |
399 | if (Label().FindChild(ChildLab_Pnt).FindAttribute(TDataStd_RealArray::GetID(), aPnt) && aPnt->Length() == 3) |
5df609e7 |
400 | { |
fbcef69b |
401 | gp_Pnt aP(aLoc->Value(aPnt->Lower()), aPnt->Value(aPnt->Lower() + 1), aPnt->Value(aPnt->Lower() + 2)); |
402 | anObj->SetPoint(aP); |
5df609e7 |
403 | } |
404 | |
fbcef69b |
405 | Handle(TDataStd_RealArray) aPntText; |
406 | if (Label().FindChild(ChildLab_PntText).FindAttribute(TDataStd_RealArray::GetID(), aPntText) && aPntText->Length() == 3) |
5df609e7 |
407 | { |
fbcef69b |
408 | gp_Pnt aP(aPntText->Value(aPntText->Lower()), aPntText->Value(aPntText->Lower() + 1), aPntText->Value(aPntText->Lower() + 2)); |
409 | anObj->SetPointTextAttach(aP); |
5df609e7 |
410 | } |
411 | |
1c9d3225 |
412 | Handle(TDataStd_Integer) aIsDTarget; |
413 | if(Label().FindChild(ChildLab_IsDTarget).FindAttribute(TDataStd_Integer::GetID(), aIsDTarget)) |
414 | { |
415 | anObj->IsDatumTarget((aIsDTarget->Get() != 0)); |
416 | } |
417 | else |
418 | { |
419 | return anObj; |
420 | } |
421 | |
422 | if (aIsDTarget->Get() != 0) |
9ebaae37 |
423 | { |
1c9d3225 |
424 | Handle(TDataStd_Integer) aDTargetType; |
425 | if(Label().FindChild(ChildLab_DTargetType).FindAttribute(TDataStd_Integer::GetID(), aDTargetType)) |
426 | { |
427 | anObj->SetDatumTargetType((XCAFDimTolObjects_DatumTargetType)aDTargetType->Get()); |
428 | if(anObj->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area) |
429 | { |
430 | Handle(TNaming_NamedShape) aDatumTarget; |
431 | if(Label().FindChild(ChildLab_DatumTarget).FindAttribute(TNaming_NamedShape::GetID(), aDatumTarget)) |
432 | { |
433 | anObj->SetDatumTarget(aDatumTarget->Get()); |
434 | } |
435 | } |
436 | else |
437 | { |
fbcef69b |
438 | if (Label().FindChild(ChildLab_AxisLoc).FindAttribute(TDataStd_RealArray::GetID(), aLoc) && aLoc->Length() == 3 && |
439 | Label().FindChild(ChildLab_AxisN).FindAttribute(TDataStd_RealArray::GetID(), aN) && aN->Length() == 3 && |
440 | Label().FindChild(ChildLab_AxisRef).FindAttribute(TDataStd_RealArray::GetID(), aR) && aR->Length() == 3) |
1c9d3225 |
441 | { |
fbcef69b |
442 | gp_Pnt aL(aLoc->Value(aLoc->Lower()), aLoc->Value(aLoc->Lower() + 1), aLoc->Value(aLoc->Lower() + 2)); |
443 | gp_Dir aD(aN->Value(aN->Lower()), aN->Value(aN->Lower() + 1), aN->Value(aN->Lower() + 2)); |
444 | gp_Dir aDR(aR->Value(aR->Lower()), aR->Value(aR->Lower() + 1), aR->Value(aR->Lower() + 2)); |
445 | gp_Ax2 anAx(aL, aD, aDR); |
1c9d3225 |
446 | anObj->SetDatumTargetAxis(anAx); |
447 | } |
448 | |
449 | if(anObj->GetDatumTargetType() != XCAFDimTolObjects_DatumTargetType_Point) |
450 | { |
451 | Handle(TDataStd_Real) aLen; |
6595eee7 |
452 | if(Label().FindChild(ChildLab_DTargetLength).FindAttribute(TDataStd_Real::GetID(), aLen)) |
1c9d3225 |
453 | { |
454 | anObj->SetDatumTargetLength(aLen->Get()); |
455 | } |
456 | if(anObj->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Rectangle) |
457 | { |
458 | Handle(TDataStd_Real) aWidth; |
6595eee7 |
459 | if(Label().FindChild(ChildLab_DTargetWidth).FindAttribute(TDataStd_Real::GetID(), aWidth)) |
1c9d3225 |
460 | { |
461 | anObj->SetDatumTargetWidth(aWidth->Get()); |
462 | } |
463 | } |
464 | } |
465 | } |
466 | } |
6595eee7 |
467 | Handle(TDataStd_Integer) aNum; |
468 | if(Label().FindChild(ChildLab_DTargetNumber).FindAttribute(TDataStd_Integer::GetID(), aNum)) |
469 | { |
470 | anObj->SetDatumTargetNumber(aNum->Get()); |
471 | } |
472 | else |
473 | { |
474 | anObj->SetDatumTargetNumber(0); |
475 | } |
9ebaae37 |
476 | } |
477 | |
5df609e7 |
478 | Handle(TNaming_NamedShape) aNS; |
479 | TDF_Label aLPres = Label().FindChild( ChildLab_Presentation); |
480 | if ( aLPres.FindAttribute(TNaming_NamedShape::GetID(), aNS) ) |
481 | { |
482 | |
483 | TopoDS_Shape aPresentation = TNaming_Tool::GetShape(aNS); |
484 | if( !aPresentation.IsNull()) |
485 | { |
486 | Handle(TDataStd_Name) aNameAtrr; |
487 | Handle(TCollection_HAsciiString) aPresentName; |
488 | if (aLPres.FindAttribute(TDataStd_Name::GetID(),aNameAtrr)) |
489 | { |
490 | const TCollection_ExtendedString& aName = aNameAtrr->Get(); |
491 | |
492 | if( !aName.IsEmpty()) |
493 | aPresentName = new TCollection_HAsciiString(aName); |
494 | } |
495 | |
496 | anObj->SetPresentation(aPresentation, aPresentName); |
497 | } |
498 | } |
9ebaae37 |
499 | return anObj; |
500 | } |
7fd59977 |
501 | |
502 | //======================================================================= |
503 | //function : ID |
504 | //purpose : |
505 | //======================================================================= |
506 | |
507 | const Standard_GUID& XCAFDoc_Datum::ID() const |
508 | { |
509 | return GetID(); |
510 | } |
511 | |
512 | |
513 | //======================================================================= |
514 | //function : Restore |
515 | //purpose : |
516 | //======================================================================= |
517 | |
9ebaae37 |
518 | void XCAFDoc_Datum::Restore(const Handle(TDF_Attribute)& theWith) |
7fd59977 |
519 | { |
9ebaae37 |
520 | myName = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetName(); |
521 | myDescription = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetDescription(); |
522 | myIdentification = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetIdentification(); |
7fd59977 |
523 | } |
524 | |
525 | |
526 | //======================================================================= |
527 | //function : NewEmpty |
528 | //purpose : |
529 | //======================================================================= |
530 | |
531 | Handle(TDF_Attribute) XCAFDoc_Datum::NewEmpty() const |
532 | { |
533 | return new XCAFDoc_Datum(); |
534 | } |
535 | |
536 | |
537 | //======================================================================= |
538 | //function : Paste |
539 | //purpose : |
540 | //======================================================================= |
541 | |
9ebaae37 |
542 | void XCAFDoc_Datum::Paste(const Handle(TDF_Attribute)& theInto, |
7fd59977 |
543 | const Handle(TDF_RelocationTable)& /*RT*/) const |
544 | { |
9ebaae37 |
545 | Handle(XCAFDoc_Datum)::DownCast(theInto)->Set(myName,myDescription,myIdentification); |
7fd59977 |
546 | } |
547 | |
bc73b006 |
548 | //======================================================================= |
549 | //function : DumpJson |
550 | //purpose : |
551 | //======================================================================= |
552 | void XCAFDoc_Datum::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
553 | { |
554 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
555 | |
556 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) |
557 | |
558 | OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName.get()) |
559 | OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myDescription.get()) |
560 | OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myIdentification.get()) |
39b707a6 |
561 | |
562 | Handle(XCAFDimTolObjects_DatumObject) anObject = GetObject(); |
563 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anObject.get()) |
bc73b006 |
564 | } |