1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-18 14:27:39 +03:00

0027797: Visualization - consider ZLayer properties while sorting list of picked entities

OpenGl_GraphicDriver::ZLayers() / V3d_Viewer::GetAllZLayers() now return
the layers sequence following rendering order (taking into account IsImmediate flag).

StdSelect_ViewerSelector3d::Pick() now sort result taking into account ZLayers flags.
This commit is contained in:
kgv
2016-08-23 17:26:22 +03:00
committed by bugmaster
parent 94afca11a0
commit 1593b4eeab
11 changed files with 252 additions and 222 deletions

View File

@@ -17,14 +17,14 @@
#ifndef _SelectMgr_SortCriterion_HeaderFile
#define _SelectMgr_SortCriterion_HeaderFile
#include <Graphic3d_ZLayerId.hxx>
#include <Precision.hxx>
#include <Standard.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
//! This class provides data and criterion for sorting candidate
//! entities in the process of interactive selection by mouse click
@@ -32,75 +32,124 @@ class SelectMgr_SortCriterion
{
public:
Standard_Real Depth; //!< distance from the view plane to the entity
Standard_Real MinDist; //!< distance from the clicked point to the entity on the view plane
Standard_Real Tolerance; //!< tolerance used for selecting candidates
Standard_Integer Priority; //!< selection priority
Standard_Integer ZLayerPosition; //!< ZLayer rendering order index, stronger than a depth
Standard_Boolean ToPreferClosest; //!< whether closest object is preferred even if has less priority
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT SelectMgr_SortCriterion();
//! Defines parameters of selection criterion:
//! - Priority: selection priority
//! - Depth: distance from the view plane to the entity
//! - MinDist: distance from the clicked point to the entity on the view plane
//! - Tol: tolerance used for selecting candidates
//! - PreferClosest: specify whether closest object is preferred even if
//! if has less priority
Standard_EXPORT SelectMgr_SortCriterion(const Standard_Integer thePriority, const Standard_Real theDepth, const Standard_Real theMinDist, const Standard_Real theTol, const Standard_Boolean PreferClosest);
void SetPriority (const Standard_Integer P);
void SetDepth (const Standard_Real D);
void SetMinDist (const Standard_Real D);
void SetTol (const Standard_Real T);
Standard_Integer Priority() const;
Standard_Real Depth() const;
Standard_Real MinDist() const;
Standard_Real Tol() const;
Standard_EXPORT Standard_Boolean IsGreater (const SelectMgr_SortCriterion& anOtherCriterion) const;
Standard_Boolean operator > (const SelectMgr_SortCriterion& anOtherCriterion) const
{
return IsGreater(anOtherCriterion);
}
Standard_EXPORT Standard_Boolean IsLower (const SelectMgr_SortCriterion& anOtherCriterion) const;
Standard_Boolean operator < (const SelectMgr_SortCriterion& anOtherCriterion) const
{
return IsLower(anOtherCriterion);
}
//! Empty constructor.
SelectMgr_SortCriterion()
: Depth (0.0),
MinDist (0.0),
Tolerance(0.0),
Priority (0),
ZLayerPosition (0),
ToPreferClosest (Standard_True) {}
//! 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
{
// the object within different ZLayer groups can not be compared by depth
if (ZLayerPosition != theOther.ZLayerPosition)
{
return ZLayerPosition > theOther.ZLayerPosition;
}
protected:
if (ToPreferClosest)
{
// 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;
}
// old logic (OCCT version <= 6.3.1)
if (Priority > theOther.Priority)
{
return true;
}
else if (Priority != theOther.Priority)
{
return false;
}
if (Abs (Depth - theOther.Depth) <= Precision::Confusion())
{
return MinDist < theOther.MinDist;
}
private:
return Depth < theOther.Depth;
}
//! Compare with another item.
bool IsLower (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;
}
Standard_Integer myPrior;
Standard_Real myDepth;
Standard_Real myDist;
Standard_Real myTol;
Standard_Boolean myPreferClosest;
// 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;
}
// old logic (OCCT version <= 6.3.1)
if (Priority > theOther.Priority)
{
return false;
}
else if (Priority != theOther.Priority)
{
return true;
}
if (Abs (Depth - theOther.Depth) <= Precision::Confusion())
{
return MinDist > theOther.MinDist;
}
return Depth > theOther.Depth;
}
};
#include <SelectMgr_SortCriterion.lxx>
#endif // _SelectMgr_SortCriterion_HeaderFile