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