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