1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0032482: Visualization - Object owner isn't removed from picked owner when object is removed

SelectMgr_ViewerSelector::RemoveSelectableObject() now removes object from picking results.
This commit is contained in:
kgv 2021-07-26 17:16:13 +03:00 committed by bugmaster
parent bec59435e0
commit 6054db8a29
4 changed files with 84 additions and 27 deletions

View File

@ -682,6 +682,8 @@ void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIOb
//======================================================================= //=======================================================================
void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer) void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
{ {
ClearDetected();
AIS_ListOfInteractive aList; AIS_ListOfInteractive aList;
ObjectsInside (aList); ObjectsInside (aList);
for (AIS_ListOfInteractive::Iterator aListIterator (aList); aListIterator.More(); aListIterator.Next()) for (AIS_ListOfInteractive::Iterator aListIterator (aList); aListIterator.More(); aListIterator.Next())
@ -1899,7 +1901,6 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
// Object removes from Detected sequence // Object removes from Detected sequence
Standard_DISABLE_DEPRECATION_WARNINGS
for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();) for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
{ {
Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter)); Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
@ -1927,7 +1928,6 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
aDetIter++; aDetIter++;
} }
} }
Standard_ENABLE_DEPRECATION_WARNINGS
// remove IO from the selection manager to avoid memory leaks // remove IO from the selection manager to avoid memory leaks
const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity

View File

@ -165,6 +165,7 @@ SelectMgr_ViewerSelector::SelectMgr_ViewerSelector()
myToPreferClosest (Standard_True), myToPreferClosest (Standard_True),
myCameraScale (1.0), myCameraScale (1.0),
myToPrebuildBVH (Standard_False), myToPrebuildBVH (Standard_False),
myIsSorted (Standard_False),
myIsLeftChildQueuedFirst (Standard_False) myIsLeftChildQueuedFirst (Standard_False)
{ {
myEntitySetBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 4> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth, Standard_True); myEntitySetBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 4> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth, Standard_True);
@ -228,15 +229,6 @@ void SelectMgr_ViewerSelector::Deactivate (const Handle(SelectMgr_Selection)& th
} }
} }
//==================================================
// Function: Clear
// Purpose :
//==================================================
void SelectMgr_ViewerSelector::Clear()
{
mystored.Clear();
}
//======================================================================= //=======================================================================
// function: isToScaleFrustum // function: isToScaleFrustum
// purpose : Checks if the entity given requires to scale current selecting frustum // purpose : Checks if the entity given requires to scale current selecting frustum
@ -612,6 +604,7 @@ void SelectMgr_ViewerSelector::TraverseSensitives()
SelectMgr_BVHThreadPool::Sentry aSentry (myBVHThreadPool); SelectMgr_BVHThreadPool::Sentry aSentry (myBVHThreadPool);
mystored.Clear(); mystored.Clear();
myIsSorted = false;
Graphic3d_Vec2i aWinSize; Graphic3d_Vec2i aWinSize;
mySelectingVolumeMgr.WindowSize (aWinSize.x(), aWinSize.y()); mySelectingVolumeMgr.WindowSize (aWinSize.x(), aWinSize.y());
@ -760,6 +753,38 @@ void SelectMgr_ViewerSelector::TraverseSensitives()
void SelectMgr_ViewerSelector::ClearPicked() void SelectMgr_ViewerSelector::ClearPicked()
{ {
mystored.Clear(); 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;
} }
//======================================================================= //=======================================================================
@ -773,7 +798,12 @@ Handle(SelectMgr_EntityOwner) SelectMgr_ViewerSelector::Picked (const Standard_I
return Handle(SelectMgr_EntityOwner)(); 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); const Handle(SelectMgr_EntityOwner)& aStoredOwner = mystored.FindKey (anOwnerIdx);
return aStoredOwner; return aStoredOwner;
} }
@ -785,7 +815,12 @@ Handle(SelectMgr_EntityOwner) SelectMgr_ViewerSelector::Picked (const Standard_I
const SelectMgr_SortCriterion& SelectMgr_ViewerSelector::PickedData(const Standard_Integer theRank) const 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"); 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); return mystored.FindFromIndex (anOwnerIdx);
} }
@ -911,25 +946,26 @@ TCollection_AsciiString SelectMgr_ViewerSelector::Status (const Handle(SelectMgr
//function : SortResult //function : SortResult
//purpose : //purpose :
//======================================================================= //=======================================================================
void SelectMgr_ViewerSelector::SortResult() void SelectMgr_ViewerSelector::SortResult() const
{ {
if (mystored.IsEmpty()) if (mystored.IsEmpty())
{ {
myIsSorted = true;
return; return;
} }
const Standard_Integer anExtent = mystored.Extent(); 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) 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;
} }
//======================================================================= //=======================================================================
@ -983,6 +1019,7 @@ void SelectMgr_ViewerSelector::RemoveSelectableObject (const Handle(SelectMgr_Se
Handle(SelectMgr_SelectableObject) anObj = theObject; Handle(SelectMgr_SelectableObject) anObj = theObject;
if (myMapOfObjectSensitives.UnBind (theObject)) if (myMapOfObjectSensitives.UnBind (theObject))
{ {
RemovePicked (theObject);
mySelectableObjects.Remove (theObject); mySelectableObjects.Remove (theObject);
} }
} }
@ -1118,8 +1155,7 @@ void SelectMgr_ViewerSelector::DumpJson (Standard_OStream& theOStream, Standard_
OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCameraDir) OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCameraDir)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCameraScale) 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, myIsLeftChildQueuedFirst)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMapOfObjectSensitives.Extent()) OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMapOfObjectSensitives.Extent())

View File

@ -84,9 +84,6 @@ class SelectMgr_ViewerSelector : public Standard_Transient
friend class SelectMgr_SelectionManager; friend class SelectMgr_SelectionManager;
public: public:
//! Empties all the tables, removes all selections...
Standard_EXPORT void Clear();
//! Returns custom pixel tolerance value. //! Returns custom pixel tolerance value.
Standard_Integer CustomPixelTolerance() const { return myTolerances.CustomTolerance(); } Standard_Integer CustomPixelTolerance() const { return myTolerances.CustomTolerance(); }
@ -99,8 +96,8 @@ public:
//! Returns the largest pixel tolerance. //! Returns the largest pixel tolerance.
Standard_Integer PixelTolerance() const { return myTolerances.Tolerance(); } Standard_Integer PixelTolerance() const { return myTolerances.Tolerance(); }
//! Sorts the detected entites by priority and distance. //! Sorts the detected entities by priority and distance.
Standard_EXPORT virtual void SortResult(); Standard_EXPORT virtual void SortResult() const;
//! Returns the picked element with the highest priority, //! Returns the picked element with the highest priority,
//! and which is the closest to the last successful mouse position. //! and which is the closest to the last successful mouse position.
@ -144,6 +141,9 @@ public:
//! Clears picking results. //! Clears picking results.
Standard_EXPORT void ClearPicked(); 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. //! Returns the entity Owner for the object picked at specified position.
//! @param theRank rank of detected object within range 1...NbPicked() //! @param theRank rank of detected object within range 1...NbPicked()
Standard_EXPORT Handle(SelectMgr_EntityOwner) Picked (const Standard_Integer theRank) const; Standard_EXPORT Handle(SelectMgr_EntityOwner) Picked (const Standard_Integer theRank) const;
@ -161,6 +161,9 @@ public:
//! @param theRank rank of detected object within range 1...NbPicked() //! @param theRank rank of detected object within range 1...NbPicked()
gp_Pnt PickedPoint (const Standard_Integer theRank) const { return PickedData (theRank).Point; } 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; Standard_EXPORT Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const;
//! Returns the default builder used to construct BVH of entity set. //! Returns the default builder used to construct BVH of entity set.
@ -341,7 +344,8 @@ protected:
Standard_Boolean myToPrebuildBVH; Standard_Boolean myToPrebuildBVH;
Handle(SelectMgr_BVHThreadPool) myBVHThreadPool; Handle(SelectMgr_BVHThreadPool) myBVHThreadPool;
Handle(TColStd_HArray1OfInteger) myIndexes; mutable TColStd_Array1OfInteger myIndexes;
mutable Standard_Boolean myIsSorted;
Standard_Boolean myIsLeftChildQueuedFirst; Standard_Boolean myIsLeftChildQueuedFirst;
SelectMgr_MapOfObjectSensitives myMapOfObjectSensitives; SelectMgr_MapOfObjectSensitives myMapOfObjectSensitives;

View File

@ -0,0 +1,17 @@
puts "========"
puts "0032482: Visualization - Object owner isn't removed from picked owner when object is removed"
puts "========"
puts ""
pload MODELING VISUALIZATION
box b1 1 2 3
box b2 -0.5 -0.5 -0.5 3 2 1
vinit View1
vdisplay -dispMode 1 b1 b2
vfit
vmoveto 200 200
vstate -entities
vremove b1
vstate -entities
vdump $imagedir/${casename}.png