0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / XCAFDoc / XCAFDoc_Dimension.cxx
CommitLineData
9ebaae37 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <XCAFDoc_Dimension.hxx>
15
16#include <TDF_RelocationTable.hxx>
1c9d3225 17#include <TDF_ChildIterator.hxx>
9ebaae37 18#include <XCAFDoc.hxx>
19#include <TDataStd_TreeNode.hxx>
20#include <Precision.hxx>
21#include <TColgp_HArray1OfPnt.hxx>
22#include <TDataStd_Integer.hxx>
23#include <TDataStd_IntegerArray.hxx>
7644c7f4 24#include <TDataStd_ExtStringArray.hxx>
9ebaae37 25#include <TDataStd_Real.hxx>
26#include <TDataStd_RealArray.hxx>
27#include <TNaming_Builder.hxx>
28#include <TNaming_NamedShape.hxx>
29#include <TColStd_HArray1OfReal.hxx>
30#include <TopoDS.hxx>
31#include <XCAFDimTolObjects_DimensionObject.hxx>
5df609e7 32#include <TNaming_Tool.hxx>
33#include <TDataStd_Name.hxx>
9ebaae37 34
92efcf78 35IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Dimension,TDF_Attribute)
36
9ebaae37 37enum ChildLab
38{
39 ChildLab_Type = 1,
40 ChildLab_Value,
41 ChildLab_Qualifier,
42 ChildLab_Class,
43 ChildLab_Dec,
44 ChildLab_Modifiers,
45 ChildLab_Path,
46 ChildLab_Dir,
b7b2f85a 47 ChildLab_Pnt1,
48 ChildLab_Pnt2,
5df609e7 49 ChildLab_PlaneLoc,
50 ChildLab_PlaneN,
51 ChildLab_PlaneRef,
52 ChildLab_PntText,
7644c7f4 53 ChildLab_Presentation,
54 ChildLab_Descriptions,
55 ChildLab_DescriptionNames
9ebaae37 56};
57
58//=======================================================================
59//function : XCAFDoc_Dimension
60//purpose :
61//=======================================================================
62
63XCAFDoc_Dimension::XCAFDoc_Dimension()
64{
65}
66
67
68//=======================================================================
69//function : GetID
70//purpose :
71//=======================================================================
72
73const Standard_GUID& XCAFDoc_Dimension::GetID()
74{
75 static Standard_GUID DGTID ("58ed092c-44de-11d8-8776-001083004c77");
76 //static Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b");
77 return DGTID;
78 //return ID;
79}
80
81//=======================================================================
82//function : Set
83//purpose :
84//=======================================================================
85Handle(XCAFDoc_Dimension) XCAFDoc_Dimension::Set(const TDF_Label& theLabel)
86{
87 Handle(XCAFDoc_Dimension) A;
88 if (!theLabel.FindAttribute(XCAFDoc_Dimension::GetID(), A)) {
89 A = new XCAFDoc_Dimension();
90 theLabel.AddAttribute(A);
91 }
92 return A;
93}
94
95//=======================================================================
96//function : SetObject
97//purpose :
98//=======================================================================
99void XCAFDoc_Dimension::SetObject (const Handle(XCAFDimTolObjects_DimensionObject)& theObject)
100{
101 Backup();
102
1c9d3225 103 //Label().ForForgetAllAttributes();
104 TDF_ChildIterator anIter(Label());
105 for(;anIter.More(); anIter.Next())
9ebaae37 106 {
1c9d3225 107 anIter.Value().ForgetAllAttributes();
9ebaae37 108 }
1c9d3225 109 Handle(TDataStd_Integer) aType = new TDataStd_Integer();
110 Label().FindChild(ChildLab_Type).AddAttribute(aType);
9ebaae37 111 aType->Set(theObject->GetType());
112
1c9d3225 113 if(!theObject->GetValues().IsNull())
9ebaae37 114 {
1c9d3225 115 Handle(TDataStd_RealArray) aVal = new TDataStd_RealArray();
116 Label().FindChild(ChildLab_Value).AddAttribute(aVal);
9ebaae37 117 aVal->ChangeArray(theObject->GetValues());
118 }
119
1c9d3225 120 Handle(TDataStd_Integer) aQualifier = new TDataStd_Integer();
121 Label().FindChild(ChildLab_Qualifier).AddAttribute(aQualifier);
9ebaae37 122 aQualifier->Set(theObject->GetQualifier());
123
124 Standard_Boolean aH;
125 XCAFDimTolObjects_DimensionFormVariance aF;
126 XCAFDimTolObjects_DimensionGrade aG;
127 theObject->GetClassOfTolerance(aH,aF,aG);
1c9d3225 128 Handle(TColStd_HArray1OfInteger) anArrI;
129 if(aF != XCAFDimTolObjects_DimensionFormVariance_None)
9ebaae37 130 {
1c9d3225 131 Handle(TDataStd_IntegerArray) aClass = new TDataStd_IntegerArray();
9ebaae37 132 Label().FindChild(ChildLab_Class).AddAttribute(aClass);
1c9d3225 133 anArrI = new TColStd_HArray1OfInteger(1,3);
134 anArrI->SetValue(1,aH);
135 anArrI->SetValue(2,aF);
136 anArrI->SetValue(3,aG);
137 aClass->ChangeArray(anArrI);
9ebaae37 138 }
9ebaae37 139
140 Standard_Integer aL, aR;
141 theObject->GetNbOfDecimalPlaces(aL, aR);
1c9d3225 142 if (aL > 0 || aR > 0)
9ebaae37 143 {
1c9d3225 144 Handle(TDataStd_IntegerArray) aDec = new TDataStd_IntegerArray();
9ebaae37 145 Label().FindChild(ChildLab_Dec).AddAttribute(aDec);
1c9d3225 146 anArrI = new TColStd_HArray1OfInteger(1,2);
147 anArrI->SetValue(1,aL);
148 anArrI->SetValue(2,aR);
149 aDec->ChangeArray(anArrI);
9ebaae37 150 }
1c9d3225 151
152 if(theObject->GetModifiers().Length() > 0)
9ebaae37 153 {
1c9d3225 154 Handle(TDataStd_IntegerArray) aModifiers = new TDataStd_IntegerArray();
155 Label().FindChild(ChildLab_Modifiers).AddAttribute(aModifiers);
9ebaae37 156 anArrI = new TColStd_HArray1OfInteger(1,theObject->GetModifiers().Length());
157 for(Standard_Integer i = 1; i <= theObject->GetModifiers().Length(); i++)
158 anArrI->SetValue(i,theObject->GetModifiers().Value(i));
159 aModifiers->ChangeArray(anArrI);
160 }
161
162 if(!theObject->GetPath().IsNull())
163 {
1c9d3225 164 TNaming_Builder tnBuild(Label().FindChild(ChildLab_Path));
165 tnBuild.Generated(theObject->GetPath());
9ebaae37 166 }
167
1c9d3225 168 Handle(TColStd_HArray1OfReal) anArrR;
169 if(theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
9ebaae37 170 {
1c9d3225 171 gp_Dir aD;
172 theObject->GetDirection(aD);
173 Handle(TDataStd_RealArray) aDir = new TDataStd_RealArray();
9ebaae37 174 Label().FindChild(ChildLab_Dir).AddAttribute(aDir);
1c9d3225 175 anArrR = new TColStd_HArray1OfReal(1,3);
176 anArrR->SetValue(1,aD.X());
177 anArrR->SetValue(2,aD.Y());
178 anArrR->SetValue(3,aD.Z());
179 aDir->ChangeArray(anArrR);
9ebaae37 180 }
1c9d3225 181
b7b2f85a 182 if (theObject->HasPoint())
9ebaae37 183 {
b7b2f85a 184 Handle(TDataStd_RealArray) aPnt = new TDataStd_RealArray();
185 gp_Pnt aPnt1 = theObject->GetPoint();
186
187 Handle(TColStd_HArray1OfReal) aPntArr = new TColStd_HArray1OfReal(1, 3);
188 for (Standard_Integer i = 1; i <= 3; i++)
189 aPntArr->SetValue(i, aPnt1.Coord(i));
190 aPnt->ChangeArray(aPntArr);
191
192 Label().FindChild(ChildLab_Pnt1).AddAttribute(aPnt);
193 }
194
195 if (theObject->HasPoint2())
196 {
197 Handle(TDataStd_RealArray) aPnt = new TDataStd_RealArray();
198 gp_Pnt aPnt2 = theObject->GetPoint2();
199
200 Handle(TColStd_HArray1OfReal) aPntArr = new TColStd_HArray1OfReal(1, 3);
201 for (Standard_Integer i = 1; i <= 3; i++)
202 aPntArr->SetValue(i, aPnt2.Coord(i));
203 aPnt->ChangeArray(aPntArr);
204
205 Label().FindChild(ChildLab_Pnt2).AddAttribute(aPnt);
9ebaae37 206 }
5df609e7 207
208 if (theObject->HasPlane())
209 {
210 Handle(TDataStd_RealArray) aLoc = new TDataStd_RealArray();
211 Handle(TDataStd_RealArray) aN = new TDataStd_RealArray();
212 Handle(TDataStd_RealArray) aRAtt = new TDataStd_RealArray();
213 gp_Ax2 anAx = theObject->GetPlane();
214
215 Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3);
216 for (Standard_Integer i = 1; i <= 3; i++)
217 aLocArr->SetValue(i, anAx.Location().Coord(i));
218 aLoc->ChangeArray(aLocArr);
219
220 Handle(TColStd_HArray1OfReal) aNArr = new TColStd_HArray1OfReal(1, 3);
221 for (Standard_Integer i = 1; i <= 3; i++)
222 aNArr->SetValue(i, anAx.Direction().Coord(i));
223 aN->ChangeArray(aNArr);
224
225 Handle(TColStd_HArray1OfReal) aRArr = new TColStd_HArray1OfReal(1, 3);
226 for (Standard_Integer i = 1; i <= 3; i++)
227 aRArr->SetValue(i, anAx.XDirection().Coord(i));
228 aRAtt->ChangeArray(aRArr);
229
230 Label().FindChild(ChildLab_PlaneLoc).AddAttribute(aLoc);
231 Label().FindChild(ChildLab_PlaneN).AddAttribute(aN);
232 Label().FindChild(ChildLab_PlaneRef).AddAttribute(aRAtt);
233 }
234
235 if (theObject->HasTextPoint())
236 {
237 Handle(TDataStd_RealArray) aLoc = new TDataStd_RealArray();
238 gp_Pnt aPntText = theObject->GetPointTextAttach();
239
240 Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3);
241 for (Standard_Integer i = 1; i <= 3; i++)
242 aLocArr->SetValue(i, aPntText.Coord(i));
243 aLoc->ChangeArray(aLocArr);
244
245 Label().FindChild(ChildLab_PntText).AddAttribute(aLoc);
246 }
247
248 TopoDS_Shape aPresentation = theObject->GetPresentation();
249 if( !aPresentation.IsNull())
250 {
251 TDF_Label aLPres = Label().FindChild( ChildLab_Presentation);
252 TNaming_Builder tnBuild(aLPres);
253 tnBuild.Generated(aPresentation);
254 Handle(TCollection_HAsciiString) aName = theObject->GetPresentationName();
255 if( !aName.IsNull() )
256 {
257 TCollection_ExtendedString str ( aName->String() );
258 TDataStd_Name::Set ( aLPres, str );
259 }
260 }
7644c7f4 261
262 if (theObject->HasDescriptions())
263 {
264 Handle(TDataStd_ExtStringArray) aDescriptions = new TDataStd_ExtStringArray();
265 Handle(TDataStd_ExtStringArray) aDescriptionNames = new TDataStd_ExtStringArray();
266 Handle(TColStd_HArray1OfExtendedString) aDescrArr = new TColStd_HArray1OfExtendedString(1, theObject->NbDescriptions());
267 Handle(TColStd_HArray1OfExtendedString) aDescrNameArr = new TColStd_HArray1OfExtendedString(1, theObject->NbDescriptions());
268 for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
269 TCollection_ExtendedString aDescr(theObject->GetDescription(i)->String());
270 aDescrArr->SetValue(i + 1, aDescr);
271 TCollection_ExtendedString aDescrName(theObject->GetDescriptionName(i)->String());
272 aDescrNameArr->SetValue(i + 1, aDescrName);
273 }
274 aDescriptions->ChangeArray(aDescrArr);
275 aDescriptionNames->ChangeArray(aDescrNameArr);
276 Label().FindChild(ChildLab_Descriptions).AddAttribute(aDescriptions);
277 Label().FindChild(ChildLab_DescriptionNames).AddAttribute(aDescriptionNames);
278 }
9ebaae37 279}
280
281//=======================================================================
282//function : GetObject
283//purpose :
284//=======================================================================
285Handle(XCAFDimTolObjects_DimensionObject) XCAFDoc_Dimension::GetObject() const
286{
287 Handle(XCAFDimTolObjects_DimensionObject) anObj = new XCAFDimTolObjects_DimensionObject();
288
289 Handle(TDataStd_Integer) aType;
290 if(Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
291 {
292 anObj->SetType((XCAFDimTolObjects_DimensionType)aType->Get());
293 }
294
295 Handle(TDataStd_RealArray) aVal;
296 if(Label().FindChild(ChildLab_Value).FindAttribute(TDataStd_RealArray::GetID(), aVal)
297 && !aVal->Array().IsNull())
298 {
299 anObj->SetValues(aVal->Array());
300 }
301
302 Handle(TDataStd_Integer) aQualifier;
303 if(Label().FindChild(ChildLab_Qualifier).FindAttribute(TDataStd_Integer::GetID(), aQualifier))
304 {
305 anObj->SetQualifier((XCAFDimTolObjects_DimensionQualifier)aQualifier->Get());
306 }
307
308 Handle(TDataStd_IntegerArray) aClass;
309 if(Label().FindChild(ChildLab_Class).FindAttribute(TDataStd_IntegerArray::GetID(), aClass)
310 && !aClass->Array().IsNull() && aClass->Array()->Length() > 0)
311 {
dde68833 312 anObj->SetClassOfTolerance(aClass->Array()->Value(1) != 0, (XCAFDimTolObjects_DimensionFormVariance)aClass->Array()->Value(2), (XCAFDimTolObjects_DimensionGrade)aClass->Array()->Value(3));
9ebaae37 313 }
314
315 Handle(TDataStd_IntegerArray) aDec;
316 if(Label().FindChild(ChildLab_Dec).FindAttribute(TDataStd_IntegerArray::GetID(), aDec)
317 && !aDec->Array().IsNull() && aDec->Array()->Length() > 0)
318 {
319 anObj->SetNbOfDecimalPlaces(aDec->Array()->Value(1), aDec->Array()->Value(2));
320 }
321
322 Handle(TDataStd_IntegerArray) aModifiers;
323 if(Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), aModifiers)
324 && !aModifiers->Array().IsNull())
325 {
326 XCAFDimTolObjects_DimensionModifiersSequence aM;
327 for(Standard_Integer i = 1; i <= aModifiers->Array()->Length(); i++)
328 aM.Append((XCAFDimTolObjects_DimensionModif)aModifiers->Array()->Value(i));
329 anObj->SetModifiers(aM);
330 }
331
332 Handle(TNaming_NamedShape) aShape;
333 if(Label().FindChild(ChildLab_Path).FindAttribute(TNaming_NamedShape::GetID(), aShape)
334 && !aShape.IsNull())
335 {
336 anObj->SetPath(TopoDS::Edge(aShape->Get()));
337 }
338
339
340 Handle(TDataStd_RealArray) aDir;
341 if(Label().FindChild(ChildLab_Dir).FindAttribute(TDataStd_RealArray::GetID(), aDir)
342 && !aDir->Array().IsNull() && aDir->Array()->Length() > 0)
343 {
344 gp_Dir aD(aDir->Array()->Value(1), aDir->Array()->Value(2), aDir->Array()->Value(3));
345 anObj->SetDirection(aD);
346 }
347
b7b2f85a 348 Handle(TDataStd_RealArray) aPnt1;
349 if(Label().FindChild(ChildLab_Pnt1).FindAttribute(TDataStd_RealArray::GetID(), aPnt1) && aPnt1->Length() == 3 )
9ebaae37 350 {
b7b2f85a 351 gp_Pnt aP(aPnt1->Value(aPnt1->Lower()), aPnt1->Value(aPnt1->Lower()+1), aPnt1->Value(aPnt1->Lower()+2));
352 anObj->SetPoint(aP);
353 }
354
355 Handle(TDataStd_RealArray) aPnt2;
356 if(Label().FindChild(ChildLab_Pnt2).FindAttribute(TDataStd_RealArray::GetID(), aPnt2) && aPnt2->Length() == 3 )
357 {
358 gp_Pnt aP(aPnt2->Value(aPnt2->Lower()), aPnt2->Value(aPnt2->Lower()+1), aPnt2->Value(aPnt2->Lower()+2));
359 anObj->SetPoint2(aP);
9ebaae37 360 }
361
5df609e7 362 Handle(TDataStd_RealArray) aLoc, aN, aR;
363 if(Label().FindChild(ChildLab_PlaneLoc).FindAttribute(TDataStd_RealArray::GetID(), aLoc) && aLoc->Length() == 3 &&
364 Label().FindChild(ChildLab_PlaneN).FindAttribute(TDataStd_RealArray::GetID(), aN) && aN->Length() == 3 &&
365 Label().FindChild(ChildLab_PlaneRef).FindAttribute(TDataStd_RealArray::GetID(), aR) && aR->Length() == 3 )
366 {
367 gp_Pnt aL(aLoc->Value(aLoc->Lower()), aLoc->Value(aLoc->Lower()+1), aLoc->Value(aLoc->Lower()+2));
368 gp_Dir aD(aN->Value(aN->Lower()), aN->Value(aN->Lower()+1), aN->Value(aN->Lower()+2));
369 gp_Dir aDR(aR->Value(aR->Lower()), aR->Value(aR->Lower()+1), aR->Value(aR->Lower()+2));
370 gp_Ax2 anAx(aL, aD, aDR);
371 anObj->SetPlane(anAx);
372 }
373
374 Handle(TDataStd_RealArray) aPntText;
375 if(Label().FindChild(ChildLab_PntText).FindAttribute(TDataStd_RealArray::GetID(), aPntText) && aPntText->Length() == 3 )
376 {
377 gp_Pnt aP(aPntText->Value(aPntText->Lower()), aPntText->Value(aPntText->Lower()+1), aPntText->Value(aPntText->Lower()+2));
378 anObj->SetPointTextAttach(aP);
379 }
380
381 Handle(TNaming_NamedShape) aNS;
382 TDF_Label aLPres = Label().FindChild( ChildLab_Presentation);
383 if ( aLPres.FindAttribute(TNaming_NamedShape::GetID(), aNS) )
384 {
385
386 TopoDS_Shape aPresentation = TNaming_Tool::GetShape(aNS);
387 if( !aPresentation.IsNull())
388 {
389
390 Handle(TDataStd_Name) aNameAtrr;
391 Handle(TCollection_HAsciiString) aPresentName;
392 if (aLPres.FindAttribute(TDataStd_Name::GetID(),aNameAtrr))
393 {
394 const TCollection_ExtendedString& aName = aNameAtrr->Get();
395
396 if( !aName.IsEmpty())
397 aPresentName = new TCollection_HAsciiString(aName);
398 }
399
400 anObj->SetPresentation(aPresentation, aPresentName);
401 }
402 }
7644c7f4 403
404 Handle(TDataStd_ExtStringArray) aDescriptions, aDescriptionNames;
405 if (Label().FindChild(ChildLab_Descriptions).FindAttribute(TDataStd_ExtStringArray::GetID(), aDescriptions) &&
406 Label().FindChild(ChildLab_DescriptionNames).FindAttribute(TDataStd_ExtStringArray::GetID(), aDescriptionNames)) {
407 for (Standard_Integer i = 1; i <= aDescriptions->Length(); i++) {
408 Handle(TCollection_HAsciiString) aDescription, aDescriptionName;
409 aDescription = new TCollection_HAsciiString(TCollection_AsciiString(aDescriptions->Value(i)));
410 aDescriptionName = new TCollection_HAsciiString(TCollection_AsciiString(aDescriptionNames->Value(i)));
411 anObj->AddDescription(aDescription, aDescriptionName);
412 }
413 }
9ebaae37 414 return anObj;
415}
416
417//=======================================================================
418//function : ID
419//purpose :
420//=======================================================================
421
422const Standard_GUID& XCAFDoc_Dimension::ID() const
423{
424 return GetID();
425}
426
427//=======================================================================
428//function : Restore
429//purpose :
430//=======================================================================
431
432void XCAFDoc_Dimension::Restore(const Handle(TDF_Attribute)& /*With*/)
433{
434}
435
436
437//=======================================================================
438//function : NewEmpty
439//purpose :
440//=======================================================================
441
442Handle(TDF_Attribute) XCAFDoc_Dimension::NewEmpty() const
443{
444 return new XCAFDoc_Dimension();
445}
446
447
448//=======================================================================
449//function : Paste
450//purpose :
451//=======================================================================
452
453void XCAFDoc_Dimension::Paste(const Handle(TDF_Attribute)& /*Into*/,
454 const Handle(TDF_RelocationTable)& /*RT*/) const
455{
456}