1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <XCAFDimTolObjects_DimensionObject.hxx>
16 #include <Precision.hxx>
17 #include <TColgp_HArray1OfPnt.hxx>
20 IMPLEMENT_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject,Standard_Transient)
22 //=======================================================================
23 //function : XCAFDimTolObjects_DimensionObject
25 //=======================================================================
27 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject()
31 //=======================================================================
34 //=======================================================================
36 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObj)
38 myType = theObj->myType;
39 myVal = theObj->myVal;
40 myQualifier = theObj->myQualifier;
41 myIsHole = theObj->myIsHole;
42 myFormVariance = theObj->myFormVariance;
43 myGrade = theObj->myGrade;
46 myModifiers = theObj->myModifiers;
47 myPath = theObj->myPath;
48 myDir = theObj->myDir;
49 myPnts = theObj->myPnts;
52 //=======================================================================
53 //function : SetQualifier
55 //=======================================================================
56 void XCAFDimTolObjects_DimensionObject::SetQualifier (const XCAFDimTolObjects_DimensionQualifier theQualifier)
58 myQualifier = theQualifier;
61 //=======================================================================
62 //function : GetQualifier
64 //=======================================================================
65 XCAFDimTolObjects_DimensionQualifier XCAFDimTolObjects_DimensionObject::GetQualifier() const
70 //=======================================================================
71 //function : HasQualifier
73 //=======================================================================
74 Standard_Boolean XCAFDimTolObjects_DimensionObject::HasQualifier() const
76 return (myQualifier != XCAFDimTolObjects_DimensionQualifier_None);
79 //=======================================================================
82 //=======================================================================
83 void XCAFDimTolObjects_DimensionObject::SetType (const XCAFDimTolObjects_DimensionType theType)
88 //=======================================================================
91 //=======================================================================
92 XCAFDimTolObjects_DimensionType XCAFDimTolObjects_DimensionObject::GetType() const
97 //=======================================================================
100 //=======================================================================
101 Standard_Real XCAFDimTolObjects_DimensionObject::GetValue () const
106 // Simple value or value with Plus_Minus_Tolerance
107 if (myVal->Length() == 1 || myVal->Length() == 3) {
108 return myVal->Value(1);
111 if (myVal->Length() == 2) {
112 return (myVal->Value(1) + myVal->Value(2)) / 2;
117 //=======================================================================
118 //function : GetValues
120 //=======================================================================
121 Handle(TColStd_HArray1OfReal) XCAFDimTolObjects_DimensionObject::GetValues () const
126 //=======================================================================
127 //function : SetValue
129 //=======================================================================
130 void XCAFDimTolObjects_DimensionObject::SetValue (const Standard_Real theValue)
132 myVal = new TColStd_HArray1OfReal(1, 1);
133 myVal->SetValue(1,theValue);
136 //=======================================================================
137 //function : SetValues
139 //=======================================================================
140 void XCAFDimTolObjects_DimensionObject::SetValues (const Handle(TColStd_HArray1OfReal)& theValue)
145 //=======================================================================
146 //function : IsDimWithRange
148 //=======================================================================
149 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithRange() const
151 if (!myVal.IsNull() && myVal->Length() == 2)
152 return Standard_True;
153 return Standard_False;
156 //=======================================================================
157 //function : SetUpperBound
159 //=======================================================================
160 void XCAFDimTolObjects_DimensionObject::SetUpperBound (const Standard_Real theUpperBound)
162 if(!myVal.IsNull() && myVal->Length() > 1)
163 myVal->SetValue(2, theUpperBound);
166 myVal = new TColStd_HArray1OfReal(1, 2);
167 myVal->SetValue(1, theUpperBound);
168 myVal->SetValue(2, theUpperBound);
172 //=======================================================================
173 //function : SetLowerBound
175 //=======================================================================
176 void XCAFDimTolObjects_DimensionObject::SetLowerBound (const Standard_Real theLowerBound)
178 if(!myVal.IsNull() && myVal->Length() > 1)
179 myVal->SetValue(1, theLowerBound);
182 myVal = new TColStd_HArray1OfReal(1, 2);
183 myVal->SetValue(2, theLowerBound);
184 myVal->SetValue(1, theLowerBound);
188 //=======================================================================
189 //function : GetUpperBound
191 //=======================================================================
192 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperBound () const
194 if(!myVal.IsNull() && myVal->Length() == 2)
196 return myVal->Value(2);
201 //=======================================================================
202 //function : GetLowerBound
204 //=======================================================================
205 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerBound () const
207 if(!myVal.IsNull() && myVal->Length() == 2)
209 return myVal->Value(1);
214 //=======================================================================
215 //function : IsDimWithPlusMinusTolerance
217 //=======================================================================
218 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithPlusMinusTolerance() const
220 return (!myVal.IsNull() && myVal->Length() == 3);
223 //=======================================================================
224 //function : SetUpperTolValue
226 //=======================================================================
227 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetUpperTolValue (const Standard_Real theUperTolValue)
229 if(!myVal.IsNull() && myVal->Length() == 3)
231 myVal->SetValue(3, theUperTolValue);
232 return Standard_True;
234 else if(!myVal.IsNull() && myVal->Length() == 1)
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;
243 return Standard_False;
246 //=======================================================================
247 //function : SetLowerTolValue
249 //=======================================================================
250 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetLowerTolValue (const Standard_Real theLowerTolValue)
252 if(!myVal.IsNull() && myVal->Length() == 3)
254 myVal->SetValue(2, theLowerTolValue);
255 return Standard_True;
257 else if(!myVal.IsNull() && myVal->Length() == 1)
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;
266 return Standard_False;
269 //=======================================================================
270 //function : GetUpperTolValue
272 //=======================================================================
273 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperTolValue () const
275 if(!myVal.IsNull() && myVal->Length() == 3)
277 return myVal->Value(3);
282 //=======================================================================
283 //function : GetLowerTolValue
285 //=======================================================================
286 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerTolValue () const
288 if(!myVal.IsNull() && myVal->Length() == 3)
290 return myVal->Value(2);
295 //=======================================================================
296 //function : IsDimWithClassOfTolerance
298 //=======================================================================
299 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithClassOfTolerance() const
301 return (myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None);
304 //=======================================================================
305 //function : SetClassOfTolerance
307 //=======================================================================
308 void XCAFDimTolObjects_DimensionObject::SetClassOfTolerance (const Standard_Boolean theHole,
309 const XCAFDimTolObjects_DimensionFormVariance theFormVariance,
310 const XCAFDimTolObjects_DimensionGrade theGrade)
313 myFormVariance = theFormVariance;
317 //=======================================================================
318 //function : GetClassOfTolerance
320 //=======================================================================
321 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetClassOfTolerance (Standard_Boolean& theHole,
322 XCAFDimTolObjects_DimensionFormVariance& theFormVariance,
323 XCAFDimTolObjects_DimensionGrade& theGrade) const
325 theFormVariance = myFormVariance;
326 if(myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None)
330 return Standard_True;
332 return Standard_False;
335 //=======================================================================
336 //function : SetNbOfDecimalPlaces
338 //=======================================================================
339 void XCAFDimTolObjects_DimensionObject::SetNbOfDecimalPlaces (const Standard_Integer theL, const Standard_Integer theR)
345 //=======================================================================
346 //function : GetNbOfDecimalPlaces
348 //=======================================================================
349 void XCAFDimTolObjects_DimensionObject::GetNbOfDecimalPlaces (Standard_Integer& theL, Standard_Integer& theR) const
355 //=======================================================================
356 //function : GetModifiers
358 //=======================================================================
359 XCAFDimTolObjects_DimensionModifiersSequence XCAFDimTolObjects_DimensionObject::GetModifiers () const
364 //=======================================================================
365 //function : SetModifiers
367 //=======================================================================
368 void XCAFDimTolObjects_DimensionObject::SetModifiers (const XCAFDimTolObjects_DimensionModifiersSequence& theModifiers)
370 myModifiers = theModifiers;
373 //=======================================================================
374 //function : AddModifier
376 //=======================================================================
377 void XCAFDimTolObjects_DimensionObject::AddModifier (const XCAFDimTolObjects_DimensionModif theModifier)
379 myModifiers.Append(theModifier);
382 //=======================================================================
385 //=======================================================================
386 TopoDS_Edge XCAFDimTolObjects_DimensionObject::GetPath () const
391 //=======================================================================
394 //=======================================================================
395 void XCAFDimTolObjects_DimensionObject::SetPath (const TopoDS_Edge& thePath)
397 if(!thePath.IsNull())
403 //=======================================================================
404 //function : GetDirection
406 //=======================================================================
407 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetDirection (gp_Dir& theDir) const
410 return Standard_True;
413 //=======================================================================
414 //function : SetDirection
416 //=======================================================================
417 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetDirection (const gp_Dir& theDir)
420 return Standard_True;
423 //=======================================================================
424 //function : GetPoints
426 //=======================================================================
427 Handle(TColgp_HArray1OfPnt) XCAFDimTolObjects_DimensionObject::GetPoints () const
432 //=======================================================================
433 //function : SetPoints
435 //=======================================================================
436 void XCAFDimTolObjects_DimensionObject::SetPoints (const Handle(TColgp_HArray1OfPnt)& thePnts)