0031701: Visualization, SelectMgr_ViewerSelector - make depth tolerance configurable
[occt.git] / src / SelectMgr / SelectMgr_SortCriterion.hxx
index a95383c..29fc12b 100644 (file)
@@ -37,7 +37,6 @@ public:
   Standard_Integer   Priority;        //!< selection priority
   Standard_Integer   ZLayerPosition;  //!< ZLayer rendering order index, stronger than a depth
   Standard_Integer   NbOwnerMatches;  //!< overall number of entities collected for the same owner
-  Standard_Boolean   ToPreferClosest; //!< whether closest object is preferred even if has less priority
 
 public:
   DEFINE_STANDARD_ALLOC
@@ -48,18 +47,11 @@ public:
     MinDist  (0.0),
     Tolerance(0.0),
     Priority (0),
-    ZLayerPosition  (0),
-    NbOwnerMatches  (0),
-    ToPreferClosest (Standard_True) {}
+    ZLayerPosition (0),
+    NbOwnerMatches (0) {}
 
-  //! Comparison operator.
-  bool operator> (const SelectMgr_SortCriterion& theOther) const { return IsGreater (theOther); }
-
-  //! Comparison operator.
-  bool operator< (const SelectMgr_SortCriterion& theOther) const { return IsLower   (theOther); }
-
-  //! Compare with another item.
-  bool IsGreater (const SelectMgr_SortCriterion& theOther) const
+  //! Compare with another item by depth, priority and minDist.
+  bool IsCloserDepth (const SelectMgr_SortCriterion& theOther) const
   {
     // the object within different ZLayer groups can not be compared by depth
     if (ZLayerPosition != theOther.ZLayerPosition)
@@ -67,88 +59,48 @@ public:
       return ZLayerPosition > theOther.ZLayerPosition;
     }
 
-    if (ToPreferClosest)
+    // closest object is selected unless difference is within tolerance
+    if (Abs (Depth - theOther.Depth) > (Tolerance + theOther.Tolerance))
     {
-      // closest object is selected unless difference is within tolerance
-      if (Abs (Depth - theOther.Depth) > (Tolerance + theOther.Tolerance))
-      {
-        return Depth < theOther.Depth;
-      }
-
-      // if two objects have similar depth, select the one with higher priority
-      if (Priority > theOther.Priority)
-      {
-        return true;
-      }
-
-      // if priorities are equal, one closest to the mouse
-      return Priority == theOther.Priority
-          && MinDist  <  theOther.MinDist;
+      return Depth < theOther.Depth;
     }
 
-    // old logic (OCCT version <= 6.3.1)
+    // if two objects have similar depth, select the one with higher priority
     if (Priority > theOther.Priority)
     {
       return true;
     }
-    else if (Priority != theOther.Priority)
-    {
-      return false;
-    }
-
-    if (Abs (Depth - theOther.Depth) <= Precision::Confusion())
-    {
-      return MinDist < theOther.MinDist;
-    }
 
-    return Depth < theOther.Depth;
+    // if priorities are equal, one closest to the mouse
+    return Priority == theOther.Priority
+        && MinDist  <  theOther.MinDist;
   }
 
-  //! Compare with another item.
-  bool IsLower (const SelectMgr_SortCriterion& theOther) const
+  //! Compare with another item using old logic (OCCT version <= 6.3.1) with priority considered preceding depth.
+  bool IsHigherPriority (const SelectMgr_SortCriterion& theOther) const
   {
     // the object within different ZLayer groups can not be compared by depth
     if (ZLayerPosition != theOther.ZLayerPosition)
     {
-      return ZLayerPosition < theOther.ZLayerPosition;
-    }
-
-    if (ToPreferClosest)
-    {
-      // closest object is selected unless difference is within tolerance
-      if (ToPreferClosest
-       && Abs (Depth - theOther.Depth) > (Tolerance + theOther.Tolerance))
-      {
-        return Depth > theOther.Depth;
-      }
-
-      // if two objects have similar depth, select the one with higher priority
-      if (Priority < theOther.Priority)
-      {
-        return true;
-      }
-
-      // if priorities are equal, one closest to the mouse
-      return Priority == theOther.Priority
-          && MinDist  >  theOther.MinDist;
+      return ZLayerPosition > theOther.ZLayerPosition;
     }
 
-    // old logic (OCCT version <= 6.3.1)
     if (Priority > theOther.Priority)
     {
-      return false;
+      return true;
     }
     else if (Priority != theOther.Priority)
     {
-      return true;
+      return false;
     }
 
+    //if (Abs (Depth - theOther.Depth) <= (Tolerance + theOther.Tolerance))
     if (Abs (Depth - theOther.Depth) <= Precision::Confusion())
     {
-      return MinDist > theOther.MinDist;
+      return MinDist < theOther.MinDist;
     }
 
-    return Depth > theOther.Depth;
+    return Depth < theOther.Depth;
   }
 
 };