Integration of OCCT 6.5.0 from SVN
[occt.git] / src / SelectMgr / SelectMgr_SortCriterion.cxx
CommitLineData
7fd59977 1// File: SelectMgr_SortCriterion.cxx
2// Created: Thu Mar 26 17:32:47 1998
3// Author: Robert COUBLANC
4// <rob@robox.paris1.matra-dtv.fr>
5
6
7#include <SelectMgr_SortCriterion.ixx>
8#include <Precision.hxx>
9
10//=======================================================================
11//function : SelectMgr_SortCriterion
12//purpose : Empty constructor
13//=======================================================================
14
15SelectMgr_SortCriterion::SelectMgr_SortCriterion()
16 : myPrior (0),
17 myDepth (0.0),
18 myDist (0.0),
19 myTol (0.0),
20 myPreferClosest(Standard_True)
21{}
22
23//=======================================================================
24//function : SelectMgr_SortCriterion
25//purpose : Constructor
26//=======================================================================
27
28SelectMgr_SortCriterion::SelectMgr_SortCriterion(const Standard_Integer Prior,
29 const Standard_Real Depth,
30 const Standard_Real Dist,
31 const Standard_Real Tol,
32 const Standard_Boolean PreferClosest)
33 : myPrior (Prior),
34 myDepth (Depth),
35 myDist (Dist),
36 myTol (Tol),
37 myPreferClosest(PreferClosest)
38{}
39
40//=======================================================================
41//function : IsGreater
42//purpose : priorite d'abor, puis profondeur + distance...
43//=======================================================================
44Standard_Boolean SelectMgr_SortCriterion::IsGreater
45 (const SelectMgr_SortCriterion& SC) const
46{
47 if ( myPreferClosest )
48 {
49 // closest object is selected unless difference is within tolerance
50 if ( Abs (myDepth - SC.Depth()) > myTol + SC.Tol() )
51 return myDepth < SC.Depth();
52
53 // if two objects have similar depth, select the one with higher
54 // priority or, if priorities are equal, one closest to the mouse
55 return myPrior > SC.Priority() ? Standard_True :
56 myPrior < SC.Priority() ? Standard_False :
57 myDist < SC.MinDist();
58 }
59
60 // old logic (OCCT version <= 6.3.1)
61 if(myPrior>SC.Priority()) return Standard_True;
62 if(myPrior<SC.Priority()) return Standard_False;
63 if(Abs(myDepth-SC.Depth())<=Precision::Confusion())
64 return myDist < SC.MinDist();
65 return (myDepth < SC.Depth() );
66}
67
68//=======================================================================
69//function : IsLower
70//purpose : On n'utilise que les criteres de profondeur et de priorite...
71//=======================================================================
72Standard_Boolean SelectMgr_SortCriterion::IsLower
73 (const SelectMgr_SortCriterion& SC) const
74{
75 if ( myPreferClosest )
76 {
77 // closest object is selected unless difference is within tolerance
78 if ( myPreferClosest && Abs (myDepth - SC.Depth()) > myTol + SC.Tol() )
79 return myDepth > SC.Depth();
80
81 // if two objects have similar depth, select the one with higher
82 // priority or, if priorities are equal, one closest to the mouse
83 return myPrior < SC.Priority() ? Standard_True :
84 myPrior > SC.Priority() ? Standard_False :
85 myDist > SC.MinDist();
86 }
87
88 // old logic (OCCT version <= 6.3.1)
89 if(myPrior>SC.Priority()) return Standard_False;
90 if(myPrior<SC.Priority()) return Standard_True;
91 if(Abs(myDepth-SC.Depth())<=Precision::Confusion())
92 return myDist > SC.MinDist();
93 return (myDepth > SC.Depth() );
94}