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
IMPLEMENT_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject,Standard_Transient)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
XCAFDimTolObjects_DimensionObject(const Handle (XCAFDimTolObjects_DimensionObject)& theObj)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 mySemanticName = theObj->mySemanticName;
61 myPresentation = theObj->myPresentation;
62 myPresentationName = theObj->myPresentationName;
63 for (int i = 0; i < theObj->myDescriptions.Length(); i++)
64 {
65 myDescriptions.Append(theObj->myDescriptions(i));
66 }
67 for (int i = 0; i < theObj->myDescriptionNames.Length(); i++)
68 {
69 myDescriptionNames.Append(theObj->myDescriptionNames(i));
70 }
71 }
72
73 //=======================================================================
74 //function :
75 //purpose :
76 //=======================================================================
77
Handle(TCollection_HAsciiString)78 Handle(TCollection_HAsciiString) XCAFDimTolObjects_DimensionObject::GetSemanticName() const
79 {
80 return mySemanticName;
81 }
82
83 //=======================================================================
84 //function :
85 //purpose :
86 //=======================================================================
87
SetSemanticName(const Handle (TCollection_HAsciiString)& theName)88 void XCAFDimTolObjects_DimensionObject::SetSemanticName(const Handle(TCollection_HAsciiString)& theName)
89 {
90 mySemanticName = theName;
91 }
92
93 //=======================================================================
94 //function : SetQualifier
95 //purpose :
96 //=======================================================================
SetQualifier(const XCAFDimTolObjects_DimensionQualifier theQualifier)97 void XCAFDimTolObjects_DimensionObject::SetQualifier (const XCAFDimTolObjects_DimensionQualifier theQualifier)
98 {
99 myQualifier = theQualifier;
100 }
101
102 //=======================================================================
103 //function : GetQualifier
104 //purpose :
105 //=======================================================================
GetQualifier() const106 XCAFDimTolObjects_DimensionQualifier XCAFDimTolObjects_DimensionObject::GetQualifier() const
107 {
108 return myQualifier;
109 }
110
111 //=======================================================================
112 //function : HasQualifier
113 //purpose :
114 //=======================================================================
HasQualifier() const115 Standard_Boolean XCAFDimTolObjects_DimensionObject::HasQualifier() const
116 {
117 return (myQualifier != XCAFDimTolObjects_DimensionQualifier_None);
118 }
119
120 //=======================================================================
121 //function : SetType
122 //purpose :
123 //=======================================================================
SetType(const XCAFDimTolObjects_DimensionType theType)124 void XCAFDimTolObjects_DimensionObject::SetType (const XCAFDimTolObjects_DimensionType theType)
125 {
126 myType = theType;
127 }
128
129 //=======================================================================
130 //function : GetType
131 //purpose :
132 //=======================================================================
GetType() const133 XCAFDimTolObjects_DimensionType XCAFDimTolObjects_DimensionObject::GetType() const
134 {
135 return myType;
136 }
137
138 //=======================================================================
139 //function : GetValue
140 //purpose :
141 //=======================================================================
GetValue() const142 Standard_Real XCAFDimTolObjects_DimensionObject::GetValue () const
143 {
144 if (myVal.IsNull())
145 return 0;
146
147 // Simple value or value with Plus_Minus_Tolerance
148 if (myVal->Length() == 1 || myVal->Length() == 3) {
149 return myVal->Value(1);
150 }
151 // Range
152 if (myVal->Length() == 2) {
153 return (myVal->Value(1) + myVal->Value(2)) / 2;
154 }
155 return 0;
156 }
157
158 //=======================================================================
159 //function : GetValues
160 //purpose :
161 //=======================================================================
Handle(TColStd_HArray1OfReal)162 Handle(TColStd_HArray1OfReal) XCAFDimTolObjects_DimensionObject::GetValues () const
163 {
164 return myVal;
165 }
166
167 //=======================================================================
168 //function : SetValue
169 //purpose :
170 //=======================================================================
SetValue(const Standard_Real theValue)171 void XCAFDimTolObjects_DimensionObject::SetValue (const Standard_Real theValue)
172 {
173 myVal = new TColStd_HArray1OfReal(1, 1);
174 myVal->SetValue(1,theValue);
175 }
176
177 //=======================================================================
178 //function : SetValues
179 //purpose :
180 //=======================================================================
SetValues(const Handle (TColStd_HArray1OfReal)& theValue)181 void XCAFDimTolObjects_DimensionObject::SetValues (const Handle(TColStd_HArray1OfReal)& theValue)
182 {
183 myVal = theValue;
184 }
185
186 //=======================================================================
187 //function : IsDimWithRange
188 //purpose :
189 //=======================================================================
IsDimWithRange() const190 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithRange() const
191 {
192 if (!myVal.IsNull() && myVal->Length() == 2)
193 return Standard_True;
194 return Standard_False;
195 }
196
197 //=======================================================================
198 //function : SetUpperBound
199 //purpose :
200 //=======================================================================
SetUpperBound(const Standard_Real theUpperBound)201 void XCAFDimTolObjects_DimensionObject::SetUpperBound (const Standard_Real theUpperBound)
202 {
203 if(!myVal.IsNull() && myVal->Length() > 1)
204 myVal->SetValue(2, theUpperBound);
205 else
206 {
207 myVal = new TColStd_HArray1OfReal(1, 2);
208 myVal->SetValue(1, theUpperBound);
209 myVal->SetValue(2, theUpperBound);
210 }
211 }
212
213 //=======================================================================
214 //function : SetLowerBound
215 //purpose :
216 //=======================================================================
SetLowerBound(const Standard_Real theLowerBound)217 void XCAFDimTolObjects_DimensionObject::SetLowerBound (const Standard_Real theLowerBound)
218 {
219 if(!myVal.IsNull() && myVal->Length() > 1)
220 myVal->SetValue(1, theLowerBound);
221 else
222 {
223 myVal = new TColStd_HArray1OfReal(1, 2);
224 myVal->SetValue(2, theLowerBound);
225 myVal->SetValue(1, theLowerBound);
226 }
227 }
228
229 //=======================================================================
230 //function : GetUpperBound
231 //purpose :
232 //=======================================================================
GetUpperBound() const233 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperBound () const
234 {
235 if(!myVal.IsNull() && myVal->Length() == 2)
236 {
237 return myVal->Value(2);
238 }
239 return 0;
240 }
241
242 //=======================================================================
243 //function : GetLowerBound
244 //purpose :
245 //=======================================================================
GetLowerBound() const246 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerBound () const
247 {
248 if(!myVal.IsNull() && myVal->Length() == 2)
249 {
250 return myVal->Value(1);
251 }
252 return 0;
253 }
254
255 //=======================================================================
256 //function : IsDimWithPlusMinusTolerance
257 //purpose :
258 //=======================================================================
IsDimWithPlusMinusTolerance() const259 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithPlusMinusTolerance() const
260 {
261 return (!myVal.IsNull() && myVal->Length() == 3);
262 }
263
264 //=======================================================================
265 //function : SetUpperTolValue
266 //purpose :
267 //=======================================================================
SetUpperTolValue(const Standard_Real theUperTolValue)268 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetUpperTolValue (const Standard_Real theUperTolValue)
269 {
270 if(!myVal.IsNull() && myVal->Length() == 3)
271 {
272 myVal->SetValue(3, theUperTolValue);
273 return Standard_True;
274 }
275 else if(!myVal.IsNull() && myVal->Length() == 1)
276 {
277 Standard_Real v = myVal->Value(1);
278 myVal = new TColStd_HArray1OfReal(1, 3);
279 myVal->SetValue(1, v);
280 myVal->SetValue(2, theUperTolValue);
281 myVal->SetValue(3, theUperTolValue);
282 return Standard_True;
283 }
284 return Standard_False;
285 }
286
287 //=======================================================================
288 //function : SetLowerTolValue
289 //purpose :
290 //=======================================================================
SetLowerTolValue(const Standard_Real theLowerTolValue)291 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetLowerTolValue (const Standard_Real theLowerTolValue)
292 {
293 if(!myVal.IsNull() && myVal->Length() == 3)
294 {
295 myVal->SetValue(2, theLowerTolValue);
296 return Standard_True;
297 }
298 else if(!myVal.IsNull() && myVal->Length() == 1)
299 {
300 Standard_Real v = myVal->Value(1);
301 myVal = new TColStd_HArray1OfReal(1, 3);
302 myVal->SetValue(1, v);
303 myVal->SetValue(2, theLowerTolValue);
304 myVal->SetValue(3, theLowerTolValue);
305 return Standard_True;
306 }
307 return Standard_False;
308 }
309
310 //=======================================================================
311 //function : GetUpperTolValue
312 //purpose :
313 //=======================================================================
GetUpperTolValue() const314 Standard_Real XCAFDimTolObjects_DimensionObject::GetUpperTolValue () const
315 {
316 if(!myVal.IsNull() && myVal->Length() == 3)
317 {
318 return myVal->Value(3);
319 }
320 return 0;
321 }
322
323 //=======================================================================
324 //function : GetLowerTolValue
325 //purpose :
326 //=======================================================================
GetLowerTolValue() const327 Standard_Real XCAFDimTolObjects_DimensionObject::GetLowerTolValue () const
328 {
329 if(!myVal.IsNull() && myVal->Length() == 3)
330 {
331 return myVal->Value(2);
332 }
333 return 0;
334 }
335
336 //=======================================================================
337 //function : IsDimWithClassOfTolerance
338 //purpose :
339 //=======================================================================
IsDimWithClassOfTolerance() const340 Standard_Boolean XCAFDimTolObjects_DimensionObject::IsDimWithClassOfTolerance() const
341 {
342 return (myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None);
343 }
344
345 //=======================================================================
346 //function : SetClassOfTolerance
347 //purpose :
348 //=======================================================================
SetClassOfTolerance(const Standard_Boolean theHole,const XCAFDimTolObjects_DimensionFormVariance theFormVariance,const XCAFDimTolObjects_DimensionGrade theGrade)349 void XCAFDimTolObjects_DimensionObject::SetClassOfTolerance (const Standard_Boolean theHole,
350 const XCAFDimTolObjects_DimensionFormVariance theFormVariance,
351 const XCAFDimTolObjects_DimensionGrade theGrade)
352 {
353 myIsHole = theHole;
354 myFormVariance = theFormVariance;
355 myGrade = theGrade;
356 }
357
358 //=======================================================================
359 //function : GetClassOfTolerance
360 //purpose :
361 //=======================================================================
GetClassOfTolerance(Standard_Boolean & theHole,XCAFDimTolObjects_DimensionFormVariance & theFormVariance,XCAFDimTolObjects_DimensionGrade & theGrade) const362 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetClassOfTolerance (Standard_Boolean& theHole,
363 XCAFDimTolObjects_DimensionFormVariance& theFormVariance,
364 XCAFDimTolObjects_DimensionGrade& theGrade) const
365 {
366 theFormVariance = myFormVariance;
367 if(myFormVariance != XCAFDimTolObjects_DimensionFormVariance_None)
368 {
369 theHole = myIsHole;
370 theGrade = myGrade;
371 return Standard_True;
372 }
373 return Standard_False;
374 }
375
376 //=======================================================================
377 //function : SetNbOfDecimalPlaces
378 //purpose :
379 //=======================================================================
SetNbOfDecimalPlaces(const Standard_Integer theL,const Standard_Integer theR)380 void XCAFDimTolObjects_DimensionObject::SetNbOfDecimalPlaces (const Standard_Integer theL, const Standard_Integer theR)
381 {
382 myL = theL;
383 myR = theR;
384 }
385
386 //=======================================================================
387 //function : GetNbOfDecimalPlaces
388 //purpose :
389 //=======================================================================
GetNbOfDecimalPlaces(Standard_Integer & theL,Standard_Integer & theR) const390 void XCAFDimTolObjects_DimensionObject::GetNbOfDecimalPlaces (Standard_Integer& theL, Standard_Integer& theR) const
391 {
392 theL = myL;
393 theR = myR;
394 }
395
396 //=======================================================================
397 //function : GetModifiers
398 //purpose :
399 //=======================================================================
GetModifiers() const400 XCAFDimTolObjects_DimensionModifiersSequence XCAFDimTolObjects_DimensionObject::GetModifiers () const
401 {
402 return myModifiers;
403 }
404
405 //=======================================================================
406 //function : SetModifiers
407 //purpose :
408 //=======================================================================
SetModifiers(const XCAFDimTolObjects_DimensionModifiersSequence & theModifiers)409 void XCAFDimTolObjects_DimensionObject::SetModifiers (const XCAFDimTolObjects_DimensionModifiersSequence& theModifiers)
410 {
411 myModifiers = theModifiers;
412 }
413
414 //=======================================================================
415 //function : AddModifier
416 //purpose :
417 //=======================================================================
AddModifier(const XCAFDimTolObjects_DimensionModif theModifier)418 void XCAFDimTolObjects_DimensionObject::AddModifier (const XCAFDimTolObjects_DimensionModif theModifier)
419 {
420 myModifiers.Append(theModifier);
421 }
422
423 //=======================================================================
424 //function : GetPath
425 //purpose :
426 //=======================================================================
GetPath() const427 TopoDS_Edge XCAFDimTolObjects_DimensionObject::GetPath () const
428 {
429 return myPath;
430 }
431
432 //=======================================================================
433 //function : SetPath
434 //purpose :
435 //=======================================================================
SetPath(const TopoDS_Edge & thePath)436 void XCAFDimTolObjects_DimensionObject::SetPath (const TopoDS_Edge& thePath)
437 {
438 if(!thePath.IsNull())
439 {
440 myPath = thePath;
441 }
442 }
443
444 //=======================================================================
445 //function : GetDirection
446 //purpose :
447 //=======================================================================
GetDirection(gp_Dir & theDir) const448 Standard_Boolean XCAFDimTolObjects_DimensionObject::GetDirection (gp_Dir& theDir) const
449 {
450 theDir = myDir;
451 return Standard_True;
452 }
453
454 //=======================================================================
455 //function : SetDirection
456 //purpose :
457 //=======================================================================
SetDirection(const gp_Dir & theDir)458 Standard_Boolean XCAFDimTolObjects_DimensionObject::SetDirection (const gp_Dir& theDir)
459 {
460 myDir = theDir;
461 return Standard_True;
462 }
463
464 //=======================================================================
465 //function : RemoveDescription
466 //purpose :
467 //=======================================================================
RemoveDescription(const Standard_Integer theNumber)468 void XCAFDimTolObjects_DimensionObject::RemoveDescription(const Standard_Integer theNumber)
469 {
470 if (theNumber < myDescriptions.Lower() || theNumber > myDescriptions.Upper())
471 return;
472 NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptions;
473 NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptionNames;
474 for (Standard_Integer i = aDescriptions.Lower(); i < theNumber; i++) {
475 aDescriptions.Append(myDescriptions.Value(i));
476 aDescriptionNames.Append(myDescriptionNames.Value(i));
477 }
478 for (Standard_Integer i = theNumber + 1; i <= aDescriptions.Upper(); i++) {
479 aDescriptions.Append(myDescriptions.Value(i));
480 aDescriptionNames.Append(myDescriptionNames.Value(i));
481 }
482 myDescriptions = aDescriptions;
483 myDescriptionNames = aDescriptionNames;
484 }
485
486 //=======================================================================
487 //function : DumpJson
488 //purpose :
489 //=======================================================================
DumpJson(Standard_OStream & theOStream,Standard_Integer theDepth) const490 void XCAFDimTolObjects_DimensionObject::DumpJson (Standard_OStream& theOStream,
491 Standard_Integer theDepth) const
492 {
493 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
494
495 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myType)
496
497 if (!myVal.IsNull())
498 {
499 for (Standard_Integer anId = myVal->Lower(); anId <= myVal->Upper(); anId++)
500 {
501 Standard_Real aValue = myVal->Value (anId);
502 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aValue)
503 }
504 }
505
506 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myQualifier)
507 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsHole)
508 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myFormVariance)
509
510 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGrade)
511 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myL)
512 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myR)
513
514 if (!myPath.IsNull())
515 {
516 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPath)
517 }
518
519 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDir)
520 if (myHasPoint1)
521 {
522 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPnt1)
523 }
524
525 if (myHasPoint2)
526 {
527 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPnt2)
528 }
529
530 if (myHasPlane)
531 {
532 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPlane)
533 }
534
535 if (myHasPntText)
536 {
537 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPntText)
538 }
539
540 if (!myPresentation.IsNull())
541 {
542 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPresentation)
543 }
544
545 if (!mySemanticName.IsNull())
546 {
547 Standard_CString aSemanticName = mySemanticName->ToCString();
548 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aSemanticName)
549 }
550 if (!myPresentationName.IsNull())
551 {
552 Standard_CString aPresentationName = myPresentationName->ToCString();
553 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aPresentationName)
554 }
555
556 for (NCollection_Vector<Handle(TCollection_HAsciiString)>::Iterator aDescIt (myDescriptions); aDescIt.More(); aDescIt.Next())
557 {
558 if (aDescIt.Value().IsNull())
559 continue;
560 Standard_CString aDescription = aDescIt.Value()->ToCString();
561 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDescription)
562 }
563
564 for (NCollection_Vector<Handle(TCollection_HAsciiString)>::Iterator aDescNameIt (myDescriptionNames); aDescNameIt.More(); aDescNameIt.Next())
565 {
566 if (aDescNameIt.Value().IsNull())
567 continue;
568 Standard_CString aDescriptionName = aDescNameIt.Value()->ToCString();
569 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDescriptionName)
570 }
571
572 for (XCAFDimTolObjects_DimensionModifiersSequence::Iterator aModifIt (myModifiers); aModifIt.More(); aModifIt.Next())
573 {
574 XCAFDimTolObjects_DimensionModif aModifier = aModifIt.Value();
575 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aModifier)
576 }
577 }
578