summaryrefslogtreecommitdiff
path: root/src/SelectMgr/SelectMgr_SortCriterion.cxx
blob: 92aa3e563ff29adbf6ffd30d52ea9bc26c9a21da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// File:        SelectMgr_SortCriterion.cxx
// Created:     Thu Mar 26 17:32:47 1998
// Author:      Robert COUBLANC
//              <rob@robox.paris1.matra-dtv.fr>


#include <SelectMgr_SortCriterion.ixx>
#include <Precision.hxx>

//=======================================================================
//function : SelectMgr_SortCriterion
//purpose  : Empty constructor
//=======================================================================

SelectMgr_SortCriterion::SelectMgr_SortCriterion()
     : myPrior  (0),
       myDepth  (0.0),
       myDist   (0.0),
       myTol    (0.0),
       myPreferClosest(Standard_True)
{}

//=======================================================================
//function : SelectMgr_SortCriterion
//purpose  : Constructor
//=======================================================================

SelectMgr_SortCriterion::SelectMgr_SortCriterion(const Standard_Integer Prior,
                                                 const Standard_Real Depth,
                                                 const Standard_Real Dist,
                                                 const Standard_Real Tol,
                                                 const Standard_Boolean PreferClosest)
     : myPrior  (Prior),
       myDepth  (Depth),
       myDist   (Dist),
       myTol    (Tol),
       myPreferClosest(PreferClosest)
{}

//=======================================================================
//function : IsGreater
//purpose  :  priorite d'abor, puis profondeur + distance...
//=======================================================================
Standard_Boolean SelectMgr_SortCriterion::IsGreater
                                (const SelectMgr_SortCriterion& SC) const
{
  if ( myPreferClosest )
  {
    // closest object is selected unless difference is within tolerance
    if ( Abs (myDepth - SC.Depth()) > myTol + SC.Tol() )
      return myDepth < SC.Depth();

    // if two objects have similar depth, select the one with higher 
    // priority or, if priorities are equal, one closest to the mouse
    return myPrior > SC.Priority() ? Standard_True :
           myPrior < SC.Priority() ? Standard_False :
           myDist < SC.MinDist();
  }

  // old logic (OCCT version <= 6.3.1)
  if(myPrior>SC.Priority()) return Standard_True;
  if(myPrior<SC.Priority()) return Standard_False;
  if(Abs(myDepth-SC.Depth())<=Precision::Confusion())
    return myDist < SC.MinDist();
  return (myDepth < SC.Depth() );
}

//=======================================================================
//function : IsLower
//purpose  : On n'utilise que les criteres de profondeur et de priorite...
//=======================================================================
Standard_Boolean SelectMgr_SortCriterion::IsLower
                                (const SelectMgr_SortCriterion& SC) const
{
  if ( myPreferClosest )
  {
    // closest object is selected unless difference is within tolerance
    if ( myPreferClosest && Abs (myDepth - SC.Depth()) > myTol + SC.Tol() )
      return myDepth > SC.Depth();

    // if two objects have similar depth, select the one with higher 
    // priority or, if priorities are equal, one closest to the mouse
    return myPrior < SC.Priority() ? Standard_True :
           myPrior > SC.Priority() ? Standard_False :
           myDist > SC.MinDist();
  }

  // old logic (OCCT version <= 6.3.1)
  if(myPrior>SC.Priority()) return Standard_False;
  if(myPrior<SC.Priority()) return Standard_True;
  if(Abs(myDepth-SC.Depth())<=Precision::Confusion())
    return myDist > SC.MinDist();
  return (myDepth > SC.Depth() );
}