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;
32 //=======================================================================
35 //=======================================================================
37 XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObj)
39 myType = theObj->myType;
40 myVal = theObj->myVal;
41 myQualifier = theObj->myQualifier;
42 myIsHole = theObj->myIsHole;
43 myFormVariance = theObj->myFormVariance;
44 myGrade = theObj->myGrade;
47 myModifiers = theObj->myModifiers;
48 myPath = theObj->myPath;
49 myDir = theObj->myDir;
50 myPnts = theObj->myPnts;
51 myPntText= theObj->myPntText;
52 myHasPlane = theObj->myHasPlane;
53 myPlane = theObj->myPlane;
54 myHasPntText = theObj->myHasPntText;
57 //=======================================================================
58 //function : SetQualifier
60 //=======================================================================
61 void XCAFDimTolObjects_DimensionObject::SetQualifier (const XCAFDimTolObjects_DimensionQualifier theQualifier)
63 myQualifier = theQualifier;
66 //=======================================================================
67 //function : GetQualifier
69 //=======================================================================
70 XCAFDimTolObjects_DimensionQualifier XCAFDimTolObjects_DimensionObject::GetQualifier() const
75 //=======================================================================
76 //function : HasQualifier
78 //=======================================================================
79 Standard_Boolean XCAFDimTolObjects_DimensionObject::HasQualifier() const
81 return (myQualifier != XCAFDimTolObjects_DimensionQualifier_None);
84 //=======================================================================
87 //=======================================================================
88 void XCAFDimTolObjects_DimensionObject::SetType (const XCAFDimTolObjects_DimensionType theType)
93 //=======================================================================
96 //=======================================================================
97 XCAFDimTolObjects_DimensionType XCAFDimTolObjects_DimensionObject::GetType() const
102 //=======================================================================
103 //function : GetValue
105 //=======================================================================
106 Standard_Real XCAFDimTolObjects_DimensionObject::GetValue () const
111 // Simple value or value with Plus_Minus_Tolerance
112 if (myVal->Length() == 1 || myVal->Length() == 3) {
113 return myVal->Value(1);
116 if (myVal->Length() == 2) {
117 return (myVal->Value(1) + myVal->Value(2)) / 2;
122 //=======================================================================
123 //function : GetValues
125 //=======================================================================
126 Handle(TColStd_HArray1OfReal) XCAFDimTolObjects_DimensionObject::GetValues () const
131 //=======================================================================
132 //function : SetValue
134 //=======================================================================
135 void XCAFDimTolObjects_DimensionObject::SetValue (const Standard_Real theValue)
137 myVal = new TColStd_HArray1OfReal(1, 1);
138 myVal->SetValue(1,theValue);
141 //=======================================================================
142 //function : SetValues
144 //=======================================================================
145 void XCAFDimTolObjects_DimensionObject::SetValues (const Handle(TColStd_HArray1OfReal)& theValue)
150 //=======================================================================
151 //function : IsDimWithRange
153 //=======================================================================
154 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithRange() const
156 if (!myVal.IsNull() && myVal->Length() == 2)
157 return Standard_True;
158 return Standard_False;
161 //=======================================================================
162 //function : SetUpperBound
164 //=======================================================================
165 void XCAFDimTolObjects_DimensionObject::SetUpperBound (const Standard_Real theUpperBound)
167 if(!myVal.IsNull() && myVal->Length() > 1)
168 myVal->SetValue(2, theUpperBound);
171 myVal = new TColStd_HArray1OfReal(1, 2);
172 myVal->SetValue(1, theUpperBound);
173 myVal->SetValue(2, theUpperBound);
177 //=======================================================================
178 //function : SetLowerBound
180 //=======================================================================
181 void XCAFDimTolObjects_DimensionObject::SetLowerBound (const Standard_Real theLowerBound)
183 if(!myVal.IsNull() && myVal->Length() > 1)
184 myVal->SetValue(1, theLowerBound);
187 myVal = new TColStd_HArray1OfReal(1, 2);
188 myVal->SetValue(2, theLowerBound);
189 myVal->SetValue(1, theLowerBound);
193 //=======================================================================
194 //function : GetUpperBound
196 //=======================================================================
197 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperBound () const
199 if(!myVal.IsNull() && myVal->Length() == 2)
201 return myVal->Value(2);
206 //=======================================================================
207 //function : GetLowerBound
209 //=======================================================================
210 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerBound () const
212 if(!myVal.IsNull() && myVal->Length() == 2)
214 return myVal->Value(1);
219 //=======================================================================
220 //function : IsDimWithPlusMinusTolerance
222 //=======================================================================
223 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithPlusMinusTolerance() const
225 return (!myVal.IsNull() && myVal->Length() == 3);
228 //=======================================================================
229 //function : SetUpperTolValue
231 //=======================================================================
232 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetUpperTolValue (const Standard_Real theUperTolValue)
234 if(!myVal.IsNull() && myVal->Length() == 3)
236 myVal->SetValue(3, theUperTolValue);
237 return Standard_True;
239 else if(!myVal.IsNull() && myVal->Length() == 1)
241 Standard_Real v = myVal->Value(1);
242 myVal = new TColStd_HArray1OfReal(1, 3);
243 myVal->SetValue(1, v);
244 myVal->SetValue(2, theUperTolValue);
245 myVal->SetValue(3, theUperTolValue);
246 return Standard_True;
248 return Standard_False;
251 //=======================================================================
252 //function : SetLowerTolValue
254 //=======================================================================
255 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetLowerTolValue (const Standard_Real theLowerTolValue)
257 if(!myVal.IsNull() && myVal->Length() == 3)
259 myVal->SetValue(2, theLowerTolValue);
260 return Standard_True;
262 else if(!myVal.IsNull() && myVal->Length() == 1)
264 Standard_Real v = myVal->Value(1);
265 myVal = new TColStd_HArray1OfReal(1, 3);
266 myVal->SetValue(1, v);
267 myVal->SetValue(2, theLowerTolValue);
268 myVal->SetValue(3, theLowerTolValue);
269 return Standard_True;
271 return Standard_False;
274 //=======================================================================
275 //function : GetUpperTolValue
277 //=======================================================================
278 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperTolValue () const
280 if(!myVal.IsNull() && myVal->Length() == 3)
282 return myVal->Value(3);
287 //=======================================================================
288 //function : GetLowerTolValue
290 //=======================================================================
291 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerTolValue () const
293 if(!myVal.IsNull() && myVal->Length() == 3)
295 return myVal->Value(2);
300 //=======================================================================
301 //function : IsDimWithClassOfTolerance
303 //=======================================================================
304 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithClassOfTolerance() const
306 return (myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None);
309 //=======================================================================
310 //function : SetClassOfTolerance
312 //=======================================================================
313 void XCAFDimTolObjects_DimensionObject::SetClassOfTolerance (const Standard_Boolean theHole,
314 const XCAFDimTolObjects_DimensionFormVariance theFormVariance,
315 const XCAFDimTolObjects_DimensionGrade theGrade)
318 myFormVariance = theFormVariance;
322 //=======================================================================
323 //function : GetClassOfTolerance
325 //=======================================================================
326 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetClassOfTolerance (Standard_Boolean& theHole,
327 XCAFDimTolObjects_DimensionFormVariance& theFormVariance,
328 XCAFDimTolObjects_DimensionGrade& theGrade) const
330 theFormVariance = myFormVariance;
331 if(myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None)
335 return Standard_True;
337 return Standard_False;
340 //=======================================================================
341 //function : SetNbOfDecimalPlaces
343 //=======================================================================
344 void XCAFDimTolObjects_DimensionObject::SetNbOfDecimalPlaces (const Standard_Integer theL, const Standard_Integer theR)
350 //=======================================================================
351 //function : GetNbOfDecimalPlaces
353 //=======================================================================
354 void XCAFDimTolObjects_DimensionObject::GetNbOfDecimalPlaces (Standard_Integer& theL, Standard_Integer& theR) const
360 //=======================================================================
361 //function : GetModifiers
363 //=======================================================================
364 XCAFDimTolObjects_DimensionModifiersSequence XCAFDimTolObjects_DimensionObject::GetModifiers () const
369 //=======================================================================
370 //function : SetModifiers
372 //=======================================================================
373 void XCAFDimTolObjects_DimensionObject::SetModifiers (const XCAFDimTolObjects_DimensionModifiersSequence& theModifiers)
375 myModifiers = theModifiers;
378 //=======================================================================
379 //function : AddModifier
381 //=======================================================================
382 void XCAFDimTolObjects_DimensionObject::AddModifier (const XCAFDimTolObjects_DimensionModif theModifier)
384 myModifiers.Append(theModifier);
387 //=======================================================================
390 //=======================================================================
391 TopoDS_Edge XCAFDimTolObjects_DimensionObject::GetPath () const
396 //=======================================================================
399 //=======================================================================
400 void XCAFDimTolObjects_DimensionObject::SetPath (const TopoDS_Edge& thePath)
402 if(!thePath.IsNull())
408 //=======================================================================
409 //function : GetDirection
411 //=======================================================================
412 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetDirection (gp_Dir& theDir) const
415 return Standard_True;
418 //=======================================================================
419 //function : SetDirection
421 //=======================================================================
422 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetDirection (const gp_Dir& theDir)
425 return Standard_True;
428 //=======================================================================
429 //function : GetPoints
431 //=======================================================================
432 Handle(TColgp_HArray1OfPnt) XCAFDimTolObjects_DimensionObject::GetPoints () const
437 //=======================================================================
438 //function : SetPoints
440 //=======================================================================
441 void XCAFDimTolObjects_DimensionObject::SetPoints (const Handle(TColgp_HArray1OfPnt)& thePnts)
446 //=======================================================================
447 //function : RemoveDescription
449 //=======================================================================
450 void XCAFDimTolObjects_DimensionObject::RemoveDescription(const Standard_Integer theNumber)
452 if (theNumber < myDescriptions.Lower() || theNumber > myDescriptions.Upper())
454 NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptions;
455 NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptionNames;
456 for (Standard_Integer i = aDescriptions.Lower(); i < theNumber; i++) {
457 aDescriptions.Append(myDescriptions.Value(i));
458 aDescriptionNames.Append(myDescriptionNames.Value(i));
460 for (Standard_Integer i = theNumber + 1; i <= aDescriptions.Upper(); i++) {
461 aDescriptions.Append(myDescriptions.Value(i));
462 aDescriptionNames.Append(myDescriptionNames.Value(i));
464 myDescriptions = aDescriptions;
465 myDescriptionNames = aDescriptionNames;