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>
19 IMPLEMENT_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject,Standard_Transient)
21 //=======================================================================
22 //function : XCAFDimTolObjects_DimensionObject
24 //=======================================================================
26 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject()
28 myHasPlane = Standard_False;
29 myHasPntText = Standard_False;
30 myHasPoint1 = Standard_False;
31 myHasPoint2 = Standard_False;
34 //=======================================================================
37 //=======================================================================
39 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObj)
41 myType = theObj->myType;
42 myVal = theObj->myVal;
43 myQualifier = theObj->myQualifier;
44 myIsHole = theObj->myIsHole;
45 myFormVariance = theObj->myFormVariance;
46 myGrade = theObj->myGrade;
49 myModifiers = theObj->myModifiers;
50 myPath = theObj->myPath;
51 myDir = theObj->myDir;
52 myHasPoint1 = theObj->myHasPoint1;
53 myPnt1 = theObj->myPnt1;
54 myHasPoint2 = theObj->myHasPoint2;
55 myPnt2 = theObj->myPnt2;
56 myPntText= theObj->myPntText;
57 myHasPlane = theObj->myHasPlane;
58 myPlane = theObj->myPlane;
59 myHasPntText = theObj->myHasPntText;
62 //=======================================================================
63 //function : SetQualifier
65 //=======================================================================
66 void XCAFDimTolObjects_DimensionObject::SetQualifier (const XCAFDimTolObjects_DimensionQualifier theQualifier)
68 myQualifier = theQualifier;
71 //=======================================================================
72 //function : GetQualifier
74 //=======================================================================
75 XCAFDimTolObjects_DimensionQualifier XCAFDimTolObjects_DimensionObject::GetQualifier() const
80 //=======================================================================
81 //function : HasQualifier
83 //=======================================================================
84 Standard_Boolean XCAFDimTolObjects_DimensionObject::HasQualifier() const
86 return (myQualifier != XCAFDimTolObjects_DimensionQualifier_None);
89 //=======================================================================
92 //=======================================================================
93 void XCAFDimTolObjects_DimensionObject::SetType (const XCAFDimTolObjects_DimensionType theType)
98 //=======================================================================
101 //=======================================================================
102 XCAFDimTolObjects_DimensionType XCAFDimTolObjects_DimensionObject::GetType() const
107 //=======================================================================
108 //function : GetValue
110 //=======================================================================
111 Standard_Real XCAFDimTolObjects_DimensionObject::GetValue () const
116 // Simple value or value with Plus_Minus_Tolerance
117 if (myVal->Length() == 1 || myVal->Length() == 3) {
118 return myVal->Value(1);
121 if (myVal->Length() == 2) {
122 return (myVal->Value(1) + myVal->Value(2)) / 2;
127 //=======================================================================
128 //function : GetValues
130 //=======================================================================
131 Handle(TColStd_HArray1OfReal) XCAFDimTolObjects_DimensionObject::GetValues () const
136 //=======================================================================
137 //function : SetValue
139 //=======================================================================
140 void XCAFDimTolObjects_DimensionObject::SetValue (const Standard_Real theValue)
142 myVal = new TColStd_HArray1OfReal(1, 1);
143 myVal->SetValue(1,theValue);
146 //=======================================================================
147 //function : SetValues
149 //=======================================================================
150 void XCAFDimTolObjects_DimensionObject::SetValues (const Handle(TColStd_HArray1OfReal)& theValue)
155 //=======================================================================
156 //function : IsDimWithRange
158 //=======================================================================
159 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithRange() const
161 if (!myVal.IsNull() && myVal->Length() == 2)
162 return Standard_True;
163 return Standard_False;
166 //=======================================================================
167 //function : SetUpperBound
169 //=======================================================================
170 void XCAFDimTolObjects_DimensionObject::SetUpperBound (const Standard_Real theUpperBound)
172 if(!myVal.IsNull() && myVal->Length() > 1)
173 myVal->SetValue(2, theUpperBound);
176 myVal = new TColStd_HArray1OfReal(1, 2);
177 myVal->SetValue(1, theUpperBound);
178 myVal->SetValue(2, theUpperBound);
182 //=======================================================================
183 //function : SetLowerBound
185 //=======================================================================
186 void XCAFDimTolObjects_DimensionObject::SetLowerBound (const Standard_Real theLowerBound)
188 if(!myVal.IsNull() && myVal->Length() > 1)
189 myVal->SetValue(1, theLowerBound);
192 myVal = new TColStd_HArray1OfReal(1, 2);
193 myVal->SetValue(2, theLowerBound);
194 myVal->SetValue(1, theLowerBound);
198 //=======================================================================
199 //function : GetUpperBound
201 //=======================================================================
202 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperBound () const
204 if(!myVal.IsNull() && myVal->Length() == 2)
206 return myVal->Value(2);
211 //=======================================================================
212 //function : GetLowerBound
214 //=======================================================================
215 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerBound () const
217 if(!myVal.IsNull() && myVal->Length() == 2)
219 return myVal->Value(1);
224 //=======================================================================
225 //function : IsDimWithPlusMinusTolerance
227 //=======================================================================
228 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithPlusMinusTolerance() const
230 return (!myVal.IsNull() && myVal->Length() == 3);
233 //=======================================================================
234 //function : SetUpperTolValue
236 //=======================================================================
237 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetUpperTolValue (const Standard_Real theUperTolValue)
239 if(!myVal.IsNull() && myVal->Length() == 3)
241 myVal->SetValue(3, theUperTolValue);
242 return Standard_True;
244 else if(!myVal.IsNull() && myVal->Length() == 1)
246 Standard_Real v = myVal->Value(1);
247 myVal = new TColStd_HArray1OfReal(1, 3);
248 myVal->SetValue(1, v);
249 myVal->SetValue(2, theUperTolValue);
250 myVal->SetValue(3, theUperTolValue);
251 return Standard_True;
253 return Standard_False;
256 //=======================================================================
257 //function : SetLowerTolValue
259 //=======================================================================
260 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetLowerTolValue (const Standard_Real theLowerTolValue)
262 if(!myVal.IsNull() && myVal->Length() == 3)
264 myVal->SetValue(2, theLowerTolValue);
265 return Standard_True;
267 else if(!myVal.IsNull() && myVal->Length() == 1)
269 Standard_Real v = myVal->Value(1);
270 myVal = new TColStd_HArray1OfReal(1, 3);
271 myVal->SetValue(1, v);
272 myVal->SetValue(2, theLowerTolValue);
273 myVal->SetValue(3, theLowerTolValue);
274 return Standard_True;
276 return Standard_False;
279 //=======================================================================
280 //function : GetUpperTolValue
282 //=======================================================================
283 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperTolValue () const
285 if(!myVal.IsNull() && myVal->Length() == 3)
287 return myVal->Value(3);
292 //=======================================================================
293 //function : GetLowerTolValue
295 //=======================================================================
296 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerTolValue () const
298 if(!myVal.IsNull() && myVal->Length() == 3)
300 return myVal->Value(2);
305 //=======================================================================
306 //function : IsDimWithClassOfTolerance
308 //=======================================================================
309 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithClassOfTolerance() const
311 return (myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None);
314 //=======================================================================
315 //function : SetClassOfTolerance
317 //=======================================================================
318 void XCAFDimTolObjects_DimensionObject::SetClassOfTolerance (const Standard_Boolean theHole,
319 const XCAFDimTolObjects_DimensionFormVariance theFormVariance,
320 const XCAFDimTolObjects_DimensionGrade theGrade)
323 myFormVariance = theFormVariance;
327 //=======================================================================
328 //function : GetClassOfTolerance
330 //=======================================================================
331 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetClassOfTolerance (Standard_Boolean& theHole,
332 XCAFDimTolObjects_DimensionFormVariance& theFormVariance,
333 XCAFDimTolObjects_DimensionGrade& theGrade) const
335 theFormVariance = myFormVariance;
336 if(myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None)
340 return Standard_True;
342 return Standard_False;
345 //=======================================================================
346 //function : SetNbOfDecimalPlaces
348 //=======================================================================
349 void XCAFDimTolObjects_DimensionObject::SetNbOfDecimalPlaces (const Standard_Integer theL, const Standard_Integer theR)
355 //=======================================================================
356 //function : GetNbOfDecimalPlaces
358 //=======================================================================
359 void XCAFDimTolObjects_DimensionObject::GetNbOfDecimalPlaces (Standard_Integer& theL, Standard_Integer& theR) const
365 //=======================================================================
366 //function : GetModifiers
368 //=======================================================================
369 XCAFDimTolObjects_DimensionModifiersSequence XCAFDimTolObjects_DimensionObject::GetModifiers () const
374 //=======================================================================
375 //function : SetModifiers
377 //=======================================================================
378 void XCAFDimTolObjects_DimensionObject::SetModifiers (const XCAFDimTolObjects_DimensionModifiersSequence& theModifiers)
380 myModifiers = theModifiers;
383 //=======================================================================
384 //function : AddModifier
386 //=======================================================================
387 void XCAFDimTolObjects_DimensionObject::AddModifier (const XCAFDimTolObjects_DimensionModif theModifier)
389 myModifiers.Append(theModifier);
392 //=======================================================================
395 //=======================================================================
396 TopoDS_Edge XCAFDimTolObjects_DimensionObject::GetPath () const
401 //=======================================================================
404 //=======================================================================
405 void XCAFDimTolObjects_DimensionObject::SetPath (const TopoDS_Edge& thePath)
407 if(!thePath.IsNull())
413 //=======================================================================
414 //function : GetDirection
416 //=======================================================================
417 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetDirection (gp_Dir& theDir) const
420 return Standard_True;
423 //=======================================================================
424 //function : SetDirection
426 //=======================================================================
427 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetDirection (const gp_Dir& theDir)
430 return Standard_True;
433 //=======================================================================
434 //function : RemoveDescription
436 //=======================================================================
437 void XCAFDimTolObjects_DimensionObject::RemoveDescription(const Standard_Integer theNumber)
439 if (theNumber < myDescriptions.Lower() || theNumber > myDescriptions.Upper())
441 NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptions;
442 NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptionNames;
443 for (Standard_Integer i = aDescriptions.Lower(); i < theNumber; i++) {
444 aDescriptions.Append(myDescriptions.Value(i));
445 aDescriptionNames.Append(myDescriptionNames.Value(i));
447 for (Standard_Integer i = theNumber + 1; i <= aDescriptions.Upper(); i++) {
448 aDescriptions.Append(myDescriptions.Value(i));
449 aDescriptionNames.Append(myDescriptionNames.Value(i));
451 myDescriptions = aDescriptions;
452 myDescriptionNames = aDescriptionNames;