From: kgv Date: Thu, 7 Sep 2017 15:29:13 +0000 (+0300) Subject: 0022048: Visualization, AIS_InteractiveContext - single object selection should alway... X-Git-Tag: V7_3_0_beta~271 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=780ee4e25cc8de44daa10216e7e0d3bf963f3f29 0022048: Visualization, AIS_InteractiveContext - single object selection should always clear multiple selection AIS_InteractiveContext::Select() now clears multiple selection when selecting a single object. --- diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index a164344e82..1e7ac281e1 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -564,7 +564,9 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdate clearDynamicHighlight(); if (myWasLastMain && !myLastinMain.IsNull()) { - if (!myLastinMain->IsSelected() || myLastinMain->IsForcedHilight()) + if (!myLastinMain->IsSelected() + || myLastinMain->IsForcedHilight() + || NbSelected() > 1) { SetSelected (myLastinMain, Standard_False); if(toUpdateViewer) @@ -1431,13 +1433,11 @@ void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& t //======================================================================= Standard_Integer AIS_InteractiveContext::NbSelected() { - Standard_Integer aNbSelected = 0; - for (InitSelected(); MoreSelected(); NextSelected()) + if (HasOpenedContext()) { - aNbSelected++; + return myLocalContexts (myCurLocalIndex)->Selection()->Extent(); } - - return aNbSelected; + return mySelection->Extent(); } //======================================================================= diff --git a/src/AIS/AIS_LocalContext.hxx b/src/AIS/AIS_LocalContext.hxx index 445856e832..0a9af0b385 100644 --- a/src/AIS/AIS_LocalContext.hxx +++ b/src/AIS/AIS_LocalContext.hxx @@ -91,8 +91,8 @@ public: Standard_Boolean AcceptErase() const; Standard_EXPORT void SetContext (const Handle(AIS_InteractiveContext)& aCtx); - - const Handle(AIS_Selection) Selection() const; + + const Handle(AIS_Selection)& Selection() const { return mySelection; } Standard_EXPORT void Terminate (const Standard_Boolean updateviewer = Standard_True); diff --git a/src/AIS/AIS_LocalContext.lxx b/src/AIS/AIS_LocalContext.lxx index e09769e336..a217befe80 100644 --- a/src/AIS/AIS_LocalContext.lxx +++ b/src/AIS/AIS_LocalContext.lxx @@ -18,9 +18,6 @@ #include -inline const Handle(AIS_Selection) AIS_LocalContext::Selection() const -{return mySelection;} - inline void AIS_LocalContext::SetAutomaticHilight(const Standard_Boolean aStatus) {myAutoHilight = aStatus;} diff --git a/src/ViewerTest/ViewerTest_EventManager.cxx b/src/ViewerTest/ViewerTest_EventManager.cxx index 2197d60af1..661a078c18 100644 --- a/src/ViewerTest/ViewerTest_EventManager.cxx +++ b/src/ViewerTest/ViewerTest_EventManager.cxx @@ -14,12 +14,12 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include #include #include -#include IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient) @@ -88,40 +88,31 @@ void ViewerTest_EventManager::Select (const Standard_Integer theXPressed, const Standard_Integer theYMotion, const Standard_Boolean theIsAutoAllowOverlap) { - #define IS_FULL_INCLUSION Standard_True if (myView.IsNull() + || myCtx.IsNull() || Abs (theXPressed - theXMotion) < 2 || Abs (theYPressed - theYMotion) < 2) { return; } - else if (!myCtx.IsNull()) + + if (theIsAutoAllowOverlap) { - if (theIsAutoAllowOverlap) - { - if (theYPressed == Min (theYPressed, theYMotion)) - { - myCtx->MainSelector()->AllowOverlapDetection (Standard_False); - } - else - { - myCtx->MainSelector()->AllowOverlapDetection (Standard_True); - } - } - myCtx->Select (Min (theXPressed, theXMotion), - Min (theYPressed, theYMotion), - Max (theXPressed, theXMotion), - Max (theYPressed, theYMotion), - myView, - Standard_False); - - // to restore default state of viewer selector - if (theIsAutoAllowOverlap) - { - myCtx->MainSelector()->AllowOverlapDetection (Standard_False); - } + const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion); + myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap); + } + myCtx->Select (Min (theXPressed, theXMotion), + Min (theYPressed, theYMotion), + Max (theXPressed, theXMotion), + Max (theYPressed, theYMotion), + myView, + Standard_False); + + // to restore default state of viewer selector + if (theIsAutoAllowOverlap) + { + myCtx->MainSelector()->AllowOverlapDetection (Standard_False); } - myView->Redraw(); } @@ -137,36 +128,29 @@ void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPressed, const Standard_Boolean theIsAutoAllowOverlap) { if (myView.IsNull() + || myCtx.IsNull() || Abs (theXPressed - theXMotion) < 2 || Abs (theYPressed - theYMotion) < 2) { return; } - else if (!myCtx.IsNull()) + + if (theIsAutoAllowOverlap) { - if (theIsAutoAllowOverlap) - { - if (theYPressed == Min (theYPressed, theYMotion)) - { - myCtx->MainSelector()->AllowOverlapDetection (Standard_False); - } - else - { - myCtx->MainSelector()->AllowOverlapDetection (Standard_True); - } - } - myCtx->ShiftSelect (Min (theXPressed, theXMotion), - Min (theYPressed, theYMotion), - Max (theXPressed, theXMotion), - Max (theYPressed, theYMotion), - myView, - Standard_False); - - // to restore default state of viewer selector - if (theIsAutoAllowOverlap) - { - myCtx->MainSelector()->AllowOverlapDetection (Standard_False); - } + const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion); + myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap); + } + myCtx->ShiftSelect (Min (theXPressed, theXMotion), + Min (theYPressed, theYMotion), + Max (theXPressed, theXMotion), + Max (theYPressed, theYMotion), + myView, + Standard_False); + + // to restore default state of viewer selector + if (theIsAutoAllowOverlap) + { + myCtx->MainSelector()->AllowOverlapDetection (Standard_False); } myView->Redraw(); } @@ -178,15 +162,13 @@ void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPressed, void ViewerTest_EventManager::Select() { - if (myView.IsNull()) + if (myView.IsNull() + || myCtx.IsNull()) { return; } - else if (!myCtx.IsNull()) - { - myCtx->Select (Standard_False); - } + myCtx->Select (Standard_False); myView->Redraw(); } @@ -197,15 +179,13 @@ void ViewerTest_EventManager::Select() void ViewerTest_EventManager::ShiftSelect() { - if (myView.IsNull()) + if (myView.IsNull() + || myCtx.IsNull()) { return; } - else if (!myCtx.IsNull()) - { - myCtx->ShiftSelect (Standard_False); - } + myCtx->ShiftSelect (Standard_False); myView->Redraw(); } @@ -216,15 +196,13 @@ void ViewerTest_EventManager::ShiftSelect() void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline) { - if (myView.IsNull()) + if (myView.IsNull() + || myCtx.IsNull()) { return; } - else if (!myCtx.IsNull()) - { - myCtx->Select (thePolyline, myView, Standard_False); - } + myCtx->Select (thePolyline, myView, Standard_False); myView->Redraw(); } @@ -235,18 +213,20 @@ void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline) void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline) { - if (myView.IsNull()) + if (myView.IsNull() + || myCtx.IsNull()) { return; } - else if (!myCtx.IsNull()) - { - myCtx->ShiftSelect (thePolyline, myView, Standard_False); - } + myCtx->ShiftSelect (thePolyline, myView, Standard_False); myView->Redraw(); } +//======================================================================= +//function : GetCurrentPosition +//purpose : +//======================================================================= void ViewerTest_EventManager::GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const { theXPix = myX; diff --git a/tests/bugs/vis/bug22048 b/tests/bugs/vis/bug22048 new file mode 100644 index 0000000000..bce206b8e5 --- /dev/null +++ b/tests/bugs/vis/bug22048 @@ -0,0 +1,22 @@ +puts "========" +puts "0022048: Visualization, AIS_InteractiveContext - single object selection should always clear multiple selection" +puts "========" +puts "" + +pload MODELING VISUALIZATION +box b1 0 0 0 10 10 10 +box b2 20 20 20 30 30 30 +vclear +vinit View1 +vaxo +vdisplay -dispMode 1 b1 b2 +vfit +vselprops selHighlight -dispMode -1 +vselect 0 0 400 400 1 +if { [vreadpixel 50 300 rgb name] != "GRAY66" } { puts "Error: b1 should be selected."} +if { [vreadpixel 300 200 rgb name] != "GRAY66" } { puts "Error: b2 should be selected."} +vselect 200 200 +if { [vreadpixel 50 300 rgb name] != "DARKGOLDENROD3" } { puts "Error: b1 should not be selected."} +if { [vreadpixel 300 200 rgb name] != "GRAY66" } { puts "Error: b2 should be selected."} + +vdump $imagedir/${casename}.png