1 // Copyright (c) 2016 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _SelectMgr_ToleranceMap_HeaderFile
15 #define _SelectMgr_ToleranceMap_HeaderFile
17 #include <NCollection_DataMap.hxx>
18 #include <Precision.hxx>
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
27 //! Sets tolerance values to -1.0
28 Standard_EXPORT SelectMgr_ToleranceMap();
30 Standard_EXPORT ~SelectMgr_ToleranceMap();
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);
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);
40 //! Returns a current tolerance that must be applied
41 Standard_Integer Tolerance() const
43 if (myLargestKey < Precision::Confusion())
45 return 2; // default tolerance value
47 return myCustomTolerance < 0
49 : myLargestKey + myCustomTolerance;
52 //! Sets tolerance to the given one and disables adaptive checks
53 void SetCustomTolerance (const Standard_Integer theTolerance) { myCustomTolerance = theTolerance; }
55 //! Unsets a custom tolerance and enables adaptive checks
56 void ResetDefaults() { myCustomTolerance = -1; }
58 //! Returns the value of custom tolerance regardless of it validity
59 Standard_Integer CustomTolerance() const { return myCustomTolerance; }
61 //! Returns true if custom tolerance value is greater than zero
62 Standard_Boolean IsCustomTolSet() const { return myCustomTolerance > 0; }
65 NCollection_DataMap<Standard_Integer, Standard_Integer> myTolerances;
66 Standard_Integer myLargestKey;
67 Standard_Integer myCustomTolerance;
70 #endif // _SelectMgr_ToleranceMap_HeaderFile