1ff4f502b908ac12e2745b1f9f6e9d8138a67f6a
[occt.git] / src / XCAFDimTolObjects / XCAFDimTolObjects_DimensionObject.cxx
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 <XCAFDimTolObjects_DimensionObject.hxx>
15
16 #include <Precision.hxx>
17 #include <TColgp_HArray1OfPnt.hxx>
18
19
20 IMPLEMENT_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject,Standard_Transient)
21
22 //=======================================================================
23 //function : XCAFDimTolObjects_DimensionObject
24 //purpose  : 
25 //=======================================================================
26
27 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject()
28 {
29 }
30
31 //=======================================================================
32 //function : 
33 //purpose  : 
34 //=======================================================================
35
36 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObj)
37 {
38   myType = theObj->myType;
39   myVal = theObj->myVal;
40   myQualifier = theObj->myQualifier;
41   myIsHole = theObj->myIsHole;
42   myFormVariance = theObj->myFormVariance;
43   myGrade = theObj->myGrade;
44   myL = theObj->myL;
45   myR = theObj->myR;
46   myModifiers = theObj->myModifiers;
47   myPath = theObj->myPath;
48   myDir = theObj->myDir;
49   myPnts = theObj->myPnts;
50 }
51
52 //=======================================================================
53 //function : SetQualifier
54 //purpose  : 
55 //=======================================================================
56 void XCAFDimTolObjects_DimensionObject::SetQualifier (const XCAFDimTolObjects_DimensionQualifier theQualifier)
57 {
58   myQualifier = theQualifier;
59 }
60
61 //=======================================================================
62 //function : GetQualifier
63 //purpose  : 
64 //=======================================================================
65 XCAFDimTolObjects_DimensionQualifier XCAFDimTolObjects_DimensionObject::GetQualifier()  const
66 {
67   return myQualifier;
68 }
69
70 //=======================================================================
71 //function : HasQualifier
72 //purpose  : 
73 //=======================================================================
74 Standard_Boolean XCAFDimTolObjects_DimensionObject::HasQualifier()  const
75 {
76   return (myQualifier != XCAFDimTolObjects_DimensionQualifier_None);
77 }
78
79 //=======================================================================
80 //function : SetType
81 //purpose  : 
82 //=======================================================================
83 void XCAFDimTolObjects_DimensionObject::SetType (const XCAFDimTolObjects_DimensionType theType)
84 {
85   myType = theType;
86 }
87
88 //=======================================================================
89 //function : GetType
90 //purpose  : 
91 //=======================================================================
92 XCAFDimTolObjects_DimensionType XCAFDimTolObjects_DimensionObject::GetType()  const
93 {
94   return myType;
95 }
96   
97 //=======================================================================
98 //function : GetValue
99 //purpose  : 
100 //=======================================================================
101 Standard_Real XCAFDimTolObjects_DimensionObject::GetValue ()  const
102 {
103   if (myVal.IsNull())
104     return 0;
105
106   // Simple value or value with Plus_Minus_Tolerance
107   if (myVal->Length() == 1 || myVal->Length() == 3) {
108     return myVal->Value(1);
109   }
110   // Range
111   if (myVal->Length() == 2) {
112     return (myVal->Value(1) + myVal->Value(2)) / 2;
113   }
114   return 0;
115 }
116
117 //=======================================================================
118 //function : GetValues
119 //purpose  : 
120 //=======================================================================
121 Handle(TColStd_HArray1OfReal) XCAFDimTolObjects_DimensionObject::GetValues ()  const
122 {
123   return myVal;
124 }
125
126 //=======================================================================
127 //function : SetValue
128 //purpose  : 
129 //=======================================================================
130 void XCAFDimTolObjects_DimensionObject::SetValue (const Standard_Real theValue)
131 {
132   myVal = new TColStd_HArray1OfReal(1, 1);
133   myVal->SetValue(1,theValue);
134 }
135
136 //=======================================================================
137 //function : SetValues
138 //purpose  : 
139 //=======================================================================
140 void XCAFDimTolObjects_DimensionObject::SetValues (const Handle(TColStd_HArray1OfReal)& theValue)
141 {
142   myVal = theValue;
143 }
144   
145 //=======================================================================
146 //function : IsDimWithRange
147 //purpose  : 
148 //=======================================================================
149 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithRange()  const
150 {
151   if (!myVal.IsNull() && myVal->Length() == 2)
152     return Standard_True;
153   return Standard_False;
154 }
155   
156 //=======================================================================
157 //function : SetUpperBound
158 //purpose  : 
159 //=======================================================================
160 void XCAFDimTolObjects_DimensionObject::SetUpperBound (const Standard_Real theUpperBound)
161 {
162   if(!myVal.IsNull() && myVal->Length() > 1)
163     myVal->SetValue(2, theUpperBound);
164   else
165   {
166     myVal = new TColStd_HArray1OfReal(1, 2);
167     myVal->SetValue(1, theUpperBound);
168     myVal->SetValue(2, theUpperBound);
169   }
170 }
171   
172 //=======================================================================
173 //function : SetLowerBound
174 //purpose  : 
175 //=======================================================================
176 void XCAFDimTolObjects_DimensionObject::SetLowerBound (const Standard_Real theLowerBound)
177 {
178   if(!myVal.IsNull() && myVal->Length() > 1)
179     myVal->SetValue(1, theLowerBound);
180   else
181   {
182     myVal = new TColStd_HArray1OfReal(1, 2);
183     myVal->SetValue(2, theLowerBound);
184     myVal->SetValue(1, theLowerBound);
185   }
186 }
187   
188 //=======================================================================
189 //function : GetUpperBound
190 //purpose  : 
191 //=======================================================================
192 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperBound ()  const
193 {
194   if(!myVal.IsNull() && myVal->Length() == 2)
195   {
196     return myVal->Value(2);
197   }
198   return 0;
199 }
200   
201 //=======================================================================
202 //function : GetLowerBound
203 //purpose  : 
204 //=======================================================================
205 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerBound ()  const
206 {
207   if(!myVal.IsNull() && myVal->Length() == 2)
208   {
209     return myVal->Value(1);
210   }
211   return 0;
212 }
213   
214 //=======================================================================
215 //function : IsDimWithPlusMinusTolerance
216 //purpose  : 
217 //=======================================================================
218 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithPlusMinusTolerance()  const
219 {
220   return (!myVal.IsNull() && myVal->Length() == 3);
221 }
222   
223 //=======================================================================
224 //function : SetUpperTolValue
225 //purpose  : 
226 //=======================================================================
227 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetUpperTolValue (const Standard_Real theUperTolValue)
228 {
229   if(!myVal.IsNull() && myVal->Length() == 3)
230   {
231     myVal->SetValue(3, theUperTolValue);
232     return Standard_True;
233   }
234   else if(!myVal.IsNull() && myVal->Length() == 1)
235   {
236     Standard_Real v = myVal->Value(1);
237     myVal = new TColStd_HArray1OfReal(1, 3);
238     myVal->SetValue(1, v);
239     myVal->SetValue(2, theUperTolValue);
240     myVal->SetValue(3, theUperTolValue);
241     return Standard_True;
242   }
243   return Standard_False;
244 }
245   
246 //=======================================================================
247 //function : SetLowerTolValue
248 //purpose  : 
249 //=======================================================================
250 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetLowerTolValue (const Standard_Real theLowerTolValue)
251 {
252   if(!myVal.IsNull() && myVal->Length() == 3)
253   {
254     myVal->SetValue(2, theLowerTolValue);
255     return Standard_True;
256   }
257   else if(!myVal.IsNull() && myVal->Length() == 1)
258   {
259     Standard_Real v = myVal->Value(1);
260     myVal = new TColStd_HArray1OfReal(1, 3);
261     myVal->SetValue(1, v);
262     myVal->SetValue(2, theLowerTolValue);
263     myVal->SetValue(3, theLowerTolValue);
264     return Standard_True;
265   }
266   return Standard_False;
267 }
268   
269 //=======================================================================
270 //function : GetUpperTolValue
271 //purpose  : 
272 //=======================================================================
273 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperTolValue ()  const
274 {
275   if(!myVal.IsNull() && myVal->Length() == 3)
276   {
277     return myVal->Value(3);
278   }
279   return 0;
280 }
281   
282 //=======================================================================
283 //function : GetLowerTolValue
284 //purpose  : 
285 //=======================================================================
286 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerTolValue ()  const
287 {
288   if(!myVal.IsNull() && myVal->Length() == 3)
289   {
290     return myVal->Value(2);
291   }
292   return 0;
293 }
294   
295 //=======================================================================
296 //function : IsDimWithClassOfTolerance
297 //purpose  : 
298 //=======================================================================
299 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithClassOfTolerance()  const
300 {
301   return (myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None);
302 }
303   
304 //=======================================================================
305 //function : SetClassOfTolerance
306 //purpose  : 
307 //=======================================================================
308 void XCAFDimTolObjects_DimensionObject::SetClassOfTolerance (const Standard_Boolean theHole,
309   const XCAFDimTolObjects_DimensionFormVariance theFormVariance,
310   const XCAFDimTolObjects_DimensionGrade theGrade)
311 {
312   myIsHole = theHole;
313   myFormVariance = theFormVariance;
314   myGrade = theGrade;
315 }
316   
317 //=======================================================================
318 //function : GetClassOfTolerance
319 //purpose  : 
320 //=======================================================================
321 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetClassOfTolerance (Standard_Boolean& theHole,
322   XCAFDimTolObjects_DimensionFormVariance& theFormVariance,
323   XCAFDimTolObjects_DimensionGrade& theGrade)  const
324 {
325   theFormVariance = myFormVariance;
326   if(myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None)
327   {
328     theHole = myIsHole;
329     theGrade = myGrade;
330     return Standard_True;
331   }
332   return Standard_False;
333 }
334   
335 //=======================================================================
336 //function : SetNbOfDecimalPlaces
337 //purpose  : 
338 //=======================================================================
339 void XCAFDimTolObjects_DimensionObject::SetNbOfDecimalPlaces (const Standard_Integer theL, const Standard_Integer theR)
340 {
341   myL = theL;
342   myR = theR;
343 }
344   
345 //=======================================================================
346 //function : GetNbOfDecimalPlaces
347 //purpose  : 
348 //=======================================================================
349 void XCAFDimTolObjects_DimensionObject::GetNbOfDecimalPlaces (Standard_Integer& theL, Standard_Integer& theR)  const
350 {
351   theL = myL;
352   theR = myR;
353 }
354   
355 //=======================================================================
356 //function : GetModifiers
357 //purpose  : 
358 //=======================================================================
359 XCAFDimTolObjects_DimensionModifiersSequence XCAFDimTolObjects_DimensionObject::GetModifiers ()  const
360 {
361   return myModifiers;
362 }
363   
364 //=======================================================================
365 //function : SetModifiers
366 //purpose  : 
367 //=======================================================================
368 void XCAFDimTolObjects_DimensionObject::SetModifiers (const XCAFDimTolObjects_DimensionModifiersSequence& theModifiers)
369 {
370   myModifiers = theModifiers;
371 }
372   
373 //=======================================================================
374 //function : AddModifier
375 //purpose  : 
376 //=======================================================================
377 void XCAFDimTolObjects_DimensionObject::AddModifier (const XCAFDimTolObjects_DimensionModif theModifier)
378 {
379   myModifiers.Append(theModifier);
380 }
381   
382 //=======================================================================
383 //function : GetPath
384 //purpose  : 
385 //=======================================================================
386 TopoDS_Edge XCAFDimTolObjects_DimensionObject::GetPath ()  const
387 {
388     return myPath;
389 }
390   
391 //=======================================================================
392 //function : SetPath
393 //purpose  : 
394 //=======================================================================
395 void XCAFDimTolObjects_DimensionObject::SetPath (const TopoDS_Edge& thePath)
396 {
397   if(!thePath.IsNull())
398   {
399     myPath = thePath;
400   }
401 }
402   
403 //=======================================================================
404 //function : GetDirection
405 //purpose  : 
406 //=======================================================================
407 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetDirection (gp_Dir& theDir)  const
408 {
409   theDir = myDir;
410   return Standard_True;
411 }
412   
413 //=======================================================================
414 //function : SetDirection
415 //purpose  : 
416 //=======================================================================
417 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetDirection (const gp_Dir& theDir)
418 {
419   myDir = theDir;
420   return Standard_True;
421 }
422
423 //=======================================================================
424 //function : GetPoints
425 //purpose  : 
426 //=======================================================================
427 Handle(TColgp_HArray1OfPnt) XCAFDimTolObjects_DimensionObject::GetPoints ()  const
428 {
429   return myPnts;
430 }
431   
432 //=======================================================================
433 //function : SetPoints
434 //purpose  : 
435 //=======================================================================
436 void XCAFDimTolObjects_DimensionObject::SetPoints (const Handle(TColgp_HArray1OfPnt)& thePnts)
437 {
438   myPnts = thePnts;
439 }