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 | |
26 | enum 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 | |
46 | XCAFDoc_GeomTolerance::XCAFDoc_GeomTolerance() |
47 | { |
48 | } |
49 | |
50 | |
51 | //======================================================================= |
52 | //function : GetID |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | const 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 | |
69 | Handle(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 | |
84 | void 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(); |
156 | aLoc->SetValue(aLoc->Upper(),anAx.Location().X()); |
157 | aLoc->SetValue(aLoc->Upper()+1,anAx.Location().Y()); |
158 | aLoc->SetValue(aLoc->Upper()+2,anAx.Location().Z()); |
159 | |
160 | aN->SetValue(aN->Upper(),anAx.Axis().Direction().X()); |
161 | aN->SetValue(aN->Upper(),anAx.Axis().Direction().X()); |
162 | aN->SetValue(aN->Upper(),anAx.Axis().Direction().X()); |
163 | |
164 | aR->SetValue(aR->Upper(),anAx.Direction().X()); |
165 | aR->SetValue(aR->Upper(),anAx.Direction().X()); |
166 | aR->SetValue(aR->Upper(),anAx.Direction().X()); |
167 | |
168 | Label().FindChild(ChildLab_AxisLoc).AddAttribute(aLoc); |
169 | Label().FindChild(ChildLab_AxisN).AddAttribute(aN); |
170 | Label().FindChild(ChildLab_AxisRef).AddAttribute(aR); |
171 | } |
9ebaae37 |
172 | } |
173 | |
174 | //======================================================================= |
175 | //function :GetObject |
176 | //purpose : |
177 | //======================================================================= |
178 | |
179 | Handle(XCAFDimTolObjects_GeomToleranceObject) XCAFDoc_GeomTolerance::GetObject() const |
180 | { |
181 | Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = new XCAFDimTolObjects_GeomToleranceObject(); |
182 | |
183 | Handle(TDataStd_Integer) aType; |
184 | if(Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType)) |
185 | { |
186 | anObj->SetType((XCAFDimTolObjects_GeomToleranceType)aType->Get()); |
187 | } |
188 | |
189 | Handle(TDataStd_Integer) aTypeOfValue; |
190 | if(Label().FindChild(ChildLab_TypeOfValue).FindAttribute(TDataStd_Integer::GetID(), aTypeOfValue)) |
191 | { |
192 | anObj->SetTypeOfValue((XCAFDimTolObjects_GeomToleranceTypeValue)aTypeOfValue->Get()); |
193 | } |
194 | |
195 | Handle(TDataStd_Real) aValue; |
196 | if(Label().FindChild(ChildLab_Value).FindAttribute(TDataStd_Real::GetID(), aValue)) |
197 | { |
198 | anObj->SetValue(aValue->Get()); |
199 | } |
200 | |
201 | Handle(TDataStd_Integer) aMatReqModif; |
202 | if(Label().FindChild(ChildLab_MatReqModif).FindAttribute(TDataStd_Integer::GetID(), aMatReqModif)) |
203 | { |
204 | anObj->SetMaterialRequirementModifier((XCAFDimTolObjects_GeomToleranceMatReqModif)aMatReqModif->Get()); |
205 | } |
206 | |
207 | Handle(TDataStd_Integer) aZoneModif; |
208 | if(Label().FindChild(ChildLab_ZoneModif).FindAttribute(TDataStd_Integer::GetID(), aZoneModif)) |
209 | { |
210 | anObj->SetZoneModifier((XCAFDimTolObjects_GeomToleranceZoneModif)aZoneModif->Get()); |
211 | } |
212 | |
213 | Handle(TDataStd_Real) aValueOfZoneModif; |
214 | if(Label().FindChild(ChildLab_ValueOfZoneModif).FindAttribute(TDataStd_Real::GetID(), aValueOfZoneModif)) |
215 | { |
216 | anObj->SetValueOfZoneModifier(aValueOfZoneModif->Get()); |
217 | } |
218 | |
219 | Handle(TDataStd_IntegerArray) anArr; |
220 | if(Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), anArr) |
221 | && !anArr->Array().IsNull()) |
222 | { |
223 | XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers; |
224 | for(Standard_Integer i = 1; i <= anArr->Length(); i++) |
225 | aModifiers.Append((XCAFDimTolObjects_GeomToleranceModif)anArr->Value(i)); |
226 | anObj->SetModifiers(aModifiers); |
227 | } |
228 | |
229 | Handle(TDataStd_Real) aMaxValueModif; |
230 | if(Label().FindChild(ChildLab_aMaxValueModif).FindAttribute(TDataStd_Real::GetID(), aMaxValueModif)) |
231 | { |
232 | anObj->SetMaxValueModifier(aMaxValueModif->Get()); |
233 | } |
1c9d3225 |
234 | |
235 | Handle(TDataStd_RealArray) aLoc; |
236 | Handle(TDataStd_RealArray) aN; |
237 | Handle(TDataStd_RealArray) aR; |
238 | if(Label().FindChild(ChildLab_AxisLoc).FindAttribute(TDataStd_RealArray::GetID(), aLoc) && aLoc->Length() == 3 && |
239 | Label().FindChild(ChildLab_AxisN).FindAttribute(TDataStd_RealArray::GetID(), aN) && aN->Length() == 3 && |
240 | Label().FindChild(ChildLab_AxisRef).FindAttribute(TDataStd_RealArray::GetID(), aR) && aR->Length() == 3 ) |
241 | { |
242 | gp_Pnt aL(aLoc->Value(aLoc->Upper()), aLoc->Value(aLoc->Upper()+1), aLoc->Value(aLoc->Upper()+2)); |
243 | gp_Dir aD(aN->Value(aN->Upper()), aN->Value(aN->Upper()+1), aN->Value(aN->Upper()+2)); |
244 | gp_Dir aDR(aR->Value(aR->Upper()), aR->Value(aR->Upper()+1), aR->Value(aR->Upper()+2)); |
245 | gp_Ax2 anAx(aL, aD, aDR); |
246 | anObj->SetAxis(anAx); |
247 | } |
9ebaae37 |
248 | return anObj; |
249 | } |
250 | |
251 | //======================================================================= |
252 | //function : ID |
253 | //purpose : |
254 | //======================================================================= |
255 | |
256 | const Standard_GUID& XCAFDoc_GeomTolerance::ID() const |
257 | { |
258 | return GetID(); |
259 | } |
260 | |
261 | //======================================================================= |
262 | //function : Restore |
263 | //purpose : |
264 | //======================================================================= |
265 | |
266 | void XCAFDoc_GeomTolerance::Restore(const Handle(TDF_Attribute)& /*With*/) |
267 | { |
268 | } |
269 | |
270 | |
271 | //======================================================================= |
272 | //function : NewEmpty |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | Handle(TDF_Attribute) XCAFDoc_GeomTolerance::NewEmpty() const |
277 | { |
278 | return new XCAFDoc_GeomTolerance(); |
279 | } |
280 | |
281 | |
282 | //======================================================================= |
283 | //function : Paste |
284 | //purpose : |
285 | //======================================================================= |
286 | |
287 | void XCAFDoc_GeomTolerance::Paste(const Handle(TDF_Attribute)& /*Into*/, |
288 | const Handle(TDF_RelocationTable)& /*RT*/) const |
289 | { |
290 | } |