0026859: Export of GDT from XCAF to STEP
[occt.git] / src / XCAFDoc / XCAFDoc_GeomTolerance.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_GeomTolerance.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 <TDataStd_Integer.hxx>
21#include <TDataStd_IntegerArray.hxx>
1c9d3225 22#include <TDataStd_RealArray.hxx>
9ebaae37 23#include <TDataStd_Real.hxx>
24#include <XCAFDimTolObjects_GeomToleranceObject.hxx>
25
26enum ChildLab
27{
28 ChildLab_Type = 1,
29 ChildLab_TypeOfValue,
30 ChildLab_Value,
31 ChildLab_MatReqModif,
32 ChildLab_ZoneModif,
33 ChildLab_ValueOfZoneModif,
34 ChildLab_Modifiers,
1c9d3225 35 ChildLab_aMaxValueModif,
36 ChildLab_AxisLoc,
37 ChildLab_AxisN,
38 ChildLab_AxisRef
9ebaae37 39};
40
41//=======================================================================
42//function : XCAFDoc_GeomTolerance
43//purpose :
44//=======================================================================
45
46XCAFDoc_GeomTolerance::XCAFDoc_GeomTolerance()
47{
48}
49
50
51//=======================================================================
52//function : GetID
53//purpose :
54//=======================================================================
55
56const Standard_GUID& XCAFDoc_GeomTolerance::GetID()
57{
58 static Standard_GUID DGTID ("58ed092f-44de-11d8-8776-001083004c77");
59 //static Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b");
60 return DGTID;
61 //return ID;
62}
63
64//=======================================================================
65//function :
66//purpose :
67//=======================================================================
68
69Handle(XCAFDoc_GeomTolerance) XCAFDoc_GeomTolerance::Set (const TDF_Label& theLabel)
70{
71 Handle(XCAFDoc_GeomTolerance) A;
72 if (!theLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), A)) {
73 A = new XCAFDoc_GeomTolerance();
74 theLabel.AddAttribute(A);
75 }
76 return A;
77}
78
79//=======================================================================
80//function : SetObject
81//purpose :
82//=======================================================================
83
84void XCAFDoc_GeomTolerance::SetObject (const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject)
85{
86 Backup();
87
1c9d3225 88 //Label().ForForgetAllAttributes();
89 TDF_ChildIterator anIter(Label());
90 for(;anIter.More(); anIter.Next())
9ebaae37 91 {
1c9d3225 92 anIter.Value().ForgetAllAttributes();
9ebaae37 93 }
1c9d3225 94
95 Handle(TDataStd_Integer) aType = new TDataStd_Integer();
9ebaae37 96 aType->Set(theObject->GetType());
1c9d3225 97 Label().FindChild(ChildLab_Type).AddAttribute(aType);
9ebaae37 98
1c9d3225 99 if(theObject->GetTypeOfValue() != XCAFDimTolObjects_GeomToleranceTypeValue_None)
9ebaae37 100 {
1c9d3225 101 Handle(TDataStd_Integer) aTypeOfValue = new TDataStd_Integer();
102 aTypeOfValue->Set(theObject->GetTypeOfValue());
9ebaae37 103 Label().FindChild(ChildLab_TypeOfValue).AddAttribute(aTypeOfValue);
104 }
9ebaae37 105
1c9d3225 106 Handle(TDataStd_Real) aValue = new TDataStd_Real();
9ebaae37 107 aValue->Set(theObject->GetValue());
1c9d3225 108 Label().FindChild(ChildLab_Value).AddAttribute(aValue);
9ebaae37 109
110 Handle(TDataStd_Integer) aMatReqModif;
1c9d3225 111 if(theObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
9ebaae37 112 {
1c9d3225 113 Label().FindChild(ChildLab_MatReqModif).FindAttribute(TDataStd_Integer::GetID(), aMatReqModif);
9ebaae37 114 aMatReqModif = new TDataStd_Integer();
115 Label().FindChild(ChildLab_MatReqModif).AddAttribute(aMatReqModif);
1c9d3225 116 aMatReqModif->Set(theObject->GetMaterialRequirementModifier());
9ebaae37 117 }
9ebaae37 118
1c9d3225 119 if(theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_None)
9ebaae37 120 {
1c9d3225 121 Handle(TDataStd_Integer) aZoneModif = new TDataStd_Integer();
122 aZoneModif->Set(theObject->GetZoneModifier());
9ebaae37 123 Label().FindChild(ChildLab_ZoneModif).AddAttribute(aZoneModif);
124 }
1c9d3225 125
126 if(theObject->GetValueOfZoneModifier() > 0)
9ebaae37 127 {
1c9d3225 128 Handle(TDataStd_Real) aValueOfZoneModif = new TDataStd_Real();
129 aValueOfZoneModif->Set(theObject->GetValueOfZoneModifier());
9ebaae37 130 Label().FindChild(ChildLab_ValueOfZoneModif).AddAttribute(aValueOfZoneModif);
131 }
9ebaae37 132
1c9d3225 133 if(theObject->GetModifiers().Length() > 0)
9ebaae37 134 {
1c9d3225 135 Handle(TDataStd_IntegerArray) aModifiers = new TDataStd_IntegerArray();
9ebaae37 136 Handle(TColStd_HArray1OfInteger) anArr = new TColStd_HArray1OfInteger(1,theObject->GetModifiers().Length());
137 for(Standard_Integer i = 1; i <= theObject->GetModifiers().Length(); i++)
138 anArr->SetValue(i,theObject->GetModifiers().Value(i));
139 aModifiers->ChangeArray(anArr);
1c9d3225 140 Label().FindChild(ChildLab_Modifiers).AddAttribute(aModifiers);
9ebaae37 141 }
142
1c9d3225 143 if(theObject->GetMaxValueModifier() > 0)
9ebaae37 144 {
1c9d3225 145 Handle(TDataStd_Real) aMaxValueModif = new TDataStd_Real();
146 aMaxValueModif->Set(theObject->GetMaxValueModifier());
9ebaae37 147 Label().FindChild(ChildLab_aMaxValueModif).AddAttribute(aMaxValueModif);
148 }
1c9d3225 149
150 if(theObject->HasAxis())
151 {
152 Handle(TDataStd_RealArray) aLoc = new TDataStd_RealArray();
153 Handle(TDataStd_RealArray) aN = new TDataStd_RealArray();
154 Handle(TDataStd_RealArray) aR = new TDataStd_RealArray();
155 gp_Ax2 anAx = theObject->GetAxis();
1c9d3225 156
6595eee7 157 Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3);
158 for (Standard_Integer i = 1; i <= 3; i++)
159 aLocArr->SetValue(i, anAx.Location().Coord(i));
160 aLoc->ChangeArray(aLocArr);
1c9d3225 161
6595eee7 162 Handle(TColStd_HArray1OfReal) aNArr = new TColStd_HArray1OfReal(1, 3);
163 for (Standard_Integer i = 1; i <= 3; i++)
164 aNArr->SetValue(i, anAx.Direction().Coord(i));
165 aN->ChangeArray(aNArr);
166
167 Handle(TColStd_HArray1OfReal) aRArr = new TColStd_HArray1OfReal(1, 3);
168 for (Standard_Integer i = 1; i <= 3; i++)
169 aRArr->SetValue(i, anAx.XDirection().Coord(i));
170 aR->ChangeArray(aRArr);
1c9d3225 171
172 Label().FindChild(ChildLab_AxisLoc).AddAttribute(aLoc);
173 Label().FindChild(ChildLab_AxisN).AddAttribute(aN);
174 Label().FindChild(ChildLab_AxisRef).AddAttribute(aR);
175 }
9ebaae37 176}
177
178//=======================================================================
179//function :GetObject
180//purpose :
181//=======================================================================
182
183Handle(XCAFDimTolObjects_GeomToleranceObject) XCAFDoc_GeomTolerance::GetObject() const
184{
185 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = new XCAFDimTolObjects_GeomToleranceObject();
186
187 Handle(TDataStd_Integer) aType;
188 if(Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
189 {
190 anObj->SetType((XCAFDimTolObjects_GeomToleranceType)aType->Get());
191 }
192
193 Handle(TDataStd_Integer) aTypeOfValue;
194 if(Label().FindChild(ChildLab_TypeOfValue).FindAttribute(TDataStd_Integer::GetID(), aTypeOfValue))
195 {
196 anObj->SetTypeOfValue((XCAFDimTolObjects_GeomToleranceTypeValue)aTypeOfValue->Get());
197 }
198
199 Handle(TDataStd_Real) aValue;
200 if(Label().FindChild(ChildLab_Value).FindAttribute(TDataStd_Real::GetID(), aValue))
201 {
202 anObj->SetValue(aValue->Get());
203 }
204
205 Handle(TDataStd_Integer) aMatReqModif;
206 if(Label().FindChild(ChildLab_MatReqModif).FindAttribute(TDataStd_Integer::GetID(), aMatReqModif))
207 {
208 anObj->SetMaterialRequirementModifier((XCAFDimTolObjects_GeomToleranceMatReqModif)aMatReqModif->Get());
209 }
210
211 Handle(TDataStd_Integer) aZoneModif;
212 if(Label().FindChild(ChildLab_ZoneModif).FindAttribute(TDataStd_Integer::GetID(), aZoneModif))
213 {
214 anObj->SetZoneModifier((XCAFDimTolObjects_GeomToleranceZoneModif)aZoneModif->Get());
215 }
216
217 Handle(TDataStd_Real) aValueOfZoneModif;
218 if(Label().FindChild(ChildLab_ValueOfZoneModif).FindAttribute(TDataStd_Real::GetID(), aValueOfZoneModif))
219 {
220 anObj->SetValueOfZoneModifier(aValueOfZoneModif->Get());
221 }
222
223 Handle(TDataStd_IntegerArray) anArr;
224 if(Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), anArr)
225 && !anArr->Array().IsNull())
226 {
227 XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers;
228 for(Standard_Integer i = 1; i <= anArr->Length(); i++)
229 aModifiers.Append((XCAFDimTolObjects_GeomToleranceModif)anArr->Value(i));
230 anObj->SetModifiers(aModifiers);
231 }
232
233 Handle(TDataStd_Real) aMaxValueModif;
234 if(Label().FindChild(ChildLab_aMaxValueModif).FindAttribute(TDataStd_Real::GetID(), aMaxValueModif))
235 {
236 anObj->SetMaxValueModifier(aMaxValueModif->Get());
237 }
1c9d3225 238
239 Handle(TDataStd_RealArray) aLoc;
240 Handle(TDataStd_RealArray) aN;
241 Handle(TDataStd_RealArray) aR;
242 if(Label().FindChild(ChildLab_AxisLoc).FindAttribute(TDataStd_RealArray::GetID(), aLoc) && aLoc->Length() == 3 &&
243 Label().FindChild(ChildLab_AxisN).FindAttribute(TDataStd_RealArray::GetID(), aN) && aN->Length() == 3 &&
244 Label().FindChild(ChildLab_AxisRef).FindAttribute(TDataStd_RealArray::GetID(), aR) && aR->Length() == 3 )
245 {
6595eee7 246 gp_Pnt aL(aLoc->Value(aLoc->Lower()), aLoc->Value(aLoc->Lower()+1), aLoc->Value(aLoc->Lower()+2));
247 gp_Dir aD(aN->Value(aN->Lower()), aN->Value(aN->Lower()+1), aN->Value(aN->Lower()+2));
248 gp_Dir aDR(aR->Value(aR->Lower()), aR->Value(aR->Lower()+1), aR->Value(aR->Lower()+2));
1c9d3225 249 gp_Ax2 anAx(aL, aD, aDR);
250 anObj->SetAxis(anAx);
251 }
9ebaae37 252 return anObj;
253}
254
255//=======================================================================
256//function : ID
257//purpose :
258//=======================================================================
259
260const Standard_GUID& XCAFDoc_GeomTolerance::ID() const
261{
262 return GetID();
263}
264
265//=======================================================================
266//function : Restore
267//purpose :
268//=======================================================================
269
270void XCAFDoc_GeomTolerance::Restore(const Handle(TDF_Attribute)& /*With*/)
271{
272}
273
274
275//=======================================================================
276//function : NewEmpty
277//purpose :
278//=======================================================================
279
280Handle(TDF_Attribute) XCAFDoc_GeomTolerance::NewEmpty() const
281{
282 return new XCAFDoc_GeomTolerance();
283}
284
285
286//=======================================================================
287//function : Paste
288//purpose :
289//=======================================================================
290
291void XCAFDoc_GeomTolerance::Paste(const Handle(TDF_Attribute)& /*Into*/,
292 const Handle(TDF_RelocationTable)& /*RT*/) const
293{
294}