myToPreferClosest (Standard_True),
myCameraScale (1.0),
myToPrebuildBVH (Standard_False),
+ myIsSorted (Standard_False),
myIsLeftChildQueuedFirst (Standard_False)
{
myEntitySetBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 4> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth, Standard_True);
}
}
-//==================================================
-// Function: Clear
-// Purpose :
-//==================================================
-void SelectMgr_ViewerSelector::Clear()
-{
- mystored.Clear();
-}
-
//=======================================================================
// function: isToScaleFrustum
// purpose : Checks if the entity given requires to scale current selecting frustum
SelectMgr_BVHThreadPool::Sentry aSentry (myBVHThreadPool);
mystored.Clear();
+ myIsSorted = false;
Graphic3d_Vec2i aWinSize;
mySelectingVolumeMgr.WindowSize (aWinSize.x(), aWinSize.y());
void SelectMgr_ViewerSelector::ClearPicked()
{
mystored.Clear();
+ myIsSorted = true;
+}
+
+//==================================================
+// Function: RemovePicked
+// Purpose :
+//==================================================
+bool SelectMgr_ViewerSelector::RemovePicked (const Handle(SelectMgr_SelectableObject)& theObject)
+{
+ if (mystored.IsEmpty()
+ || !mySelectableObjects.Contains (theObject))
+ {
+ return false;
+ }
+
+ bool isRemoved = false;
+ for (Standard_Integer aPickIter = 1; aPickIter <= mystored.Extent(); ++aPickIter)
+ {
+ const Handle(SelectMgr_EntityOwner)& aStoredOwner = mystored.FindKey (aPickIter);
+ if (!aStoredOwner.IsNull()
+ && aStoredOwner->IsSameSelectable (theObject))
+ {
+ mystored.RemoveFromIndex (aPickIter);
+ --aPickIter;
+ isRemoved = true;
+ }
+ }
+ if (isRemoved)
+ {
+ myIsSorted = false;
+ }
+ return isRemoved;
}
//=======================================================================
return Handle(SelectMgr_EntityOwner)();
}
- const Standard_Integer anOwnerIdx = myIndexes->Value (theRank);
+ if (!myIsSorted)
+ {
+ SortResult();
+ }
+
+ const Standard_Integer anOwnerIdx = myIndexes.Value (theRank);
const Handle(SelectMgr_EntityOwner)& aStoredOwner = mystored.FindKey (anOwnerIdx);
return aStoredOwner;
}
const SelectMgr_SortCriterion& SelectMgr_ViewerSelector::PickedData(const Standard_Integer theRank) const
{
Standard_OutOfRange_Raise_if (theRank < 1 || theRank > NbPicked(), "SelectMgr_ViewerSelector::PickedData() out of range index");
- const Standard_Integer anOwnerIdx = myIndexes->Value (theRank);
+ if (!myIsSorted)
+ {
+ SortResult();
+ }
+
+ const Standard_Integer anOwnerIdx = myIndexes.Value (theRank);
return mystored.FindFromIndex (anOwnerIdx);
}
//function : SortResult
//purpose :
//=======================================================================
-void SelectMgr_ViewerSelector::SortResult()
+void SelectMgr_ViewerSelector::SortResult() const
{
if (mystored.IsEmpty())
{
+ myIsSorted = true;
return;
}
const Standard_Integer anExtent = mystored.Extent();
- if (myIndexes.IsNull() || anExtent != myIndexes->Length())
+ if (anExtent != myIndexes.Length())
{
- myIndexes = new TColStd_HArray1OfInteger (1, anExtent);
+ myIndexes.Resize (1, anExtent, false);
}
- TColStd_Array1OfInteger& anIndexArray = myIndexes->ChangeArray1();
for (Standard_Integer anIndexIter = 1; anIndexIter <= anExtent; ++anIndexIter)
{
- anIndexArray.SetValue (anIndexIter, anIndexIter);
+ myIndexes.SetValue (anIndexIter, anIndexIter);
}
- std::sort (anIndexArray.begin(), anIndexArray.end(), CompareResults (mystored, myToPreferClosest));
+ std::sort (myIndexes.begin(), myIndexes.end(), CompareResults (mystored, myToPreferClosest));
+ myIsSorted = true;
}
//=======================================================================
Handle(SelectMgr_SelectableObject) anObj = theObject;
if (myMapOfObjectSensitives.UnBind (theObject))
{
+ RemovePicked (theObject);
mySelectableObjects.Remove (theObject);
}
}
OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCameraDir)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCameraScale)
- if (!myIndexes.IsNull())
- OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIndexes->Size())
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIndexes.Size())
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsLeftChildQueuedFirst)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMapOfObjectSensitives.Extent())
friend class SelectMgr_SelectionManager;
public:
- //! Empties all the tables, removes all selections...
- Standard_EXPORT void Clear();
-
//! Returns custom pixel tolerance value.
Standard_Integer CustomPixelTolerance() const { return myTolerances.CustomTolerance(); }
//! Returns the largest pixel tolerance.
Standard_Integer PixelTolerance() const { return myTolerances.Tolerance(); }
- //! Sorts the detected entites by priority and distance.
- Standard_EXPORT virtual void SortResult();
+ //! Sorts the detected entities by priority and distance.
+ Standard_EXPORT virtual void SortResult() const;
//! Returns the picked element with the highest priority,
//! and which is the closest to the last successful mouse position.
//! Clears picking results.
Standard_EXPORT void ClearPicked();
+ //! Empties all the tables, removes all selections...
+ void Clear() { ClearPicked(); }
+
//! Returns the entity Owner for the object picked at specified position.
//! @param theRank rank of detected object within range 1...NbPicked()
Standard_EXPORT Handle(SelectMgr_EntityOwner) Picked (const Standard_Integer theRank) const;
//! @param theRank rank of detected object within range 1...NbPicked()
gp_Pnt PickedPoint (const Standard_Integer theRank) const { return PickedData (theRank).Point; }
+ //! Remove picked entities associated with specified object.
+ Standard_EXPORT Standard_Boolean RemovePicked (const Handle(SelectMgr_SelectableObject)& theObject);
+
Standard_EXPORT Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const;
//! Returns the default builder used to construct BVH of entity set.
Standard_Boolean myToPrebuildBVH;
Handle(SelectMgr_BVHThreadPool) myBVHThreadPool;
- Handle(TColStd_HArray1OfInteger) myIndexes;
+ mutable TColStd_Array1OfInteger myIndexes;
+ mutable Standard_Boolean myIsSorted;
Standard_Boolean myIsLeftChildQueuedFirst;
SelectMgr_MapOfObjectSensitives myMapOfObjectSensitives;