From 41b389a152c045bd2e3087fe90a2416bfeae410b Mon Sep 17 00:00:00 2001 From: age Date: Mon, 7 Dec 2020 11:53:17 +0300 Subject: [PATCH] 0030737: Visualization - implementing new selection schemes in context Cherry picked a new highlighting logic from 75cf82505b83f6c85f43b1327e13bd5b88355ff5 --- src/AIS/AIS_InteractiveContext_1.cxx | 75 ++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index e0b3d93fe5..9bbb6eb962 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -202,6 +202,7 @@ void AIS_InteractiveContext::unhighlightOwners (const AIS_NListOfEntityOwner& th { (*aStatusPtr)->SetHilightStatus (Standard_False); } + (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)()); } for (NCollection_IndexedMap::Iterator anIter (anObjToClear); anIter.More(); anIter.Next()) { @@ -507,10 +508,10 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectRectangle (const Graphic3d_Vec2i& if (myMainSel->NbPicked() > 0) { aPickedOwners.Resize (1, myMainSel->NbPicked(), Standard_False); - } - for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) - { - aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter); + for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) + { + aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter); + } } return Select (aPickedOwners, theSelScheme); @@ -536,10 +537,10 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectPolygon (const TColgp_Array1OfPnt if (myMainSel->NbPicked() > 0) { aPickedOwners.Resize (1, myMainSel->NbPicked(), Standard_False); - } - for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) - { - aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter); + for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) + { + aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter); + } } return Select (aPickedOwners, theSelScheme); @@ -565,10 +566,10 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectPoint (const Graphic3d_Vec2i& if (myMainSel->NbPicked() > 0) { aPickedOwners.Resize (1, myMainSel->NbPicked(), Standard_False); - } - for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) - { - aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter); + for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) + { + aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter); + } } return Select (aPickedOwners, theSelScheme); @@ -709,19 +710,61 @@ AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NArray1OfEntityOwner& theOwners, const AIS_SelectionScheme theSelScheme) { - // all objects detected by the selector are taken, previous current objects are emptied, - // new objects are put... + NCollection_IndexedMap aSelOwnerMap (myAutoHilight ? mySelection->Objects().Size() : 0); if (myAutoHilight) { clearDynamicHighlight(); - UnhilightSelected (Standard_False); + + // collect currently selected owners + for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next()) + { + aSelOwnerMap.Add (anOwnerIter.Value()); + } } mySelection->SelectOwners (theOwners, theSelScheme, myFilters); if (myAutoHilight) { - HilightSelected (Standard_False); + // collect lists of owners to unhighlight (unselected) and to highlight (selected) + AIS_NListOfEntityOwner anOwnersToUnhighlight, anOwnersToHighlight; + for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next()) + { + // add newly selected owners + const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value(); + if (!aSelOwnerMap.RemoveKey (anOwner)) + { + // newly selected owner + anOwnersToHighlight.Append (anOwner); + } + else + { + // already selected owner + if (!anOwner->IsAutoHilight() + && theSelScheme != AIS_SelectionScheme_XOR + && theSelScheme != AIS_SelectionScheme_Add) + { + // hack to perform AIS_InteractiveObject::ClearSelected() before highlighting + anOwnersToUnhighlight.Append (anOwner); + anOwnersToHighlight.Append (anOwner); + } + else if (anOwner->IsForcedHilight() + || !anOwner->IsAutoHilight()) + { + anOwnersToHighlight.Append (anOwner); + } + } + } + + for (NCollection_IndexedMap::Iterator anOwnerIter (aSelOwnerMap); anOwnerIter.More(); anOwnerIter.Next()) + { + // owners removed from selection + const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value(); + anOwnersToUnhighlight.Append (anOwner); + } + + unhighlightOwners (anOwnersToUnhighlight); + highlightOwners (anOwnersToHighlight, Standard_True); } Standard_Integer aSelNum = NbSelected(); -- 2.39.5