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