0029938: Visualization - SelectMgr_ViewerSelector::PickedPoint() should return point...
[occt.git] / src / SelectMgr / SelectMgr_ToleranceMap.hxx
1 // Copyright (c) 2016 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 #ifndef _SelectMgr_ToleranceMap_HeaderFile
15 #define _SelectMgr_ToleranceMap_HeaderFile
16
17 #include <NCollection_DataMap.hxx>
18 #include <Precision.hxx>
19
20 //! An internal class for calculation of current largest tolerance value which will be applied for creation of selecting frustum by default.
21 //! Each time the selection set is deactivated, maximum tolerance value will be recalculated.
22 //! If a user enables custom precision using StdSelect_ViewerSelector3d::SetPixelTolerance, it will be applied to all sensitive entities without any checks.
23 class SelectMgr_ToleranceMap
24 {
25 public:
26
27   //! Sets tolerance values to -1.0
28   Standard_EXPORT SelectMgr_ToleranceMap();
29
30   Standard_EXPORT ~SelectMgr_ToleranceMap();
31
32   //! Adds the value given to map, checks if the current tolerance value
33   //! should be replaced by theTolerance
34   Standard_EXPORT void Add (const Standard_Integer& theTolerance);
35
36   //! Decrements a counter of the tolerance given, checks if the current tolerance value
37   //! should be recalculated
38   Standard_EXPORT void Decrement (const Standard_Integer& theTolerance);
39
40   //! Returns a current tolerance that must be applied
41   Standard_Integer Tolerance() const
42   {
43     if (myLargestKey < Precision::Confusion())
44     {
45       return 2; // default tolerance value
46     }
47     return myCustomTolerance < 0
48          ? myLargestKey
49          : myLargestKey + myCustomTolerance;
50   }
51
52   //! Sets tolerance to the given one and disables adaptive checks
53   void SetCustomTolerance (const Standard_Integer theTolerance) { myCustomTolerance = theTolerance; }
54
55   //! Unsets a custom tolerance and enables adaptive checks
56   void ResetDefaults() { myCustomTolerance = -1; }
57
58   //! Returns the value of custom tolerance regardless of it validity
59   Standard_Integer CustomTolerance() const { return myCustomTolerance; }
60
61   //! Returns true if custom tolerance value is greater than zero
62   Standard_Boolean IsCustomTolSet() const { return myCustomTolerance > 0; }
63
64 private:
65   NCollection_DataMap<Standard_Integer, Standard_Integer> myTolerances;
66   Standard_Integer                                        myLargestKey;
67   Standard_Integer                                        myCustomTolerance;
68 };
69
70 #endif // _SelectMgr_ToleranceMap_HeaderFile