From 0d5880e11acb155cf2e7147b52ac825c10a1a345 Mon Sep 17 00:00:00 2001 From: vpa Date: Mon, 26 Sep 2016 20:34:26 +0300 Subject: [PATCH] 0027893: Visualization - AIS_InteractiveContext::SetSelected does not work - misprint in check of global selection existence in AIS_InteractiveContext::SetSelected was corrected; - remaining occurrencies of hard-coded 0 selection mode were corrected to use global selection mode; - test case for issue #27983 --- src/AIS/AIS_InteractiveContext_1.cxx | 18 ++++----------- src/AIS/AIS_LocalContext_1.cxx | 21 +++++------------ src/QABugs/QABugs_19.cxx | 24 ++++++++++++++++++++ src/SelectMgr/SelectMgr_SelectionManager.cxx | 5 ++-- tests/bugs/vis/bug27893 | 17 ++++++++++++++ 5 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 tests/bugs/vis/bug27893 diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index e526bcdffc..efbfd12da3 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -1029,7 +1029,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t return; if(!myObjects.IsBound (theObject)) Display (theObject, Standard_False); - if (theObject->HasSelection (0)) + if (!theObject->HasSelection (theObject->GlobalSelectionMode())) return; const Handle(Graphic3d_HighlightStyle)& anObjSelStyle = @@ -1067,20 +1067,11 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t } // added to avoid untimely viewer update... - const Handle(SelectMgr_Selection)& aSel = theObject->Selection (0); - if (aSel->IsEmpty()) + Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); + if (anOwner.IsNull()) return; - aSel->Init(); - Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId()); mySelection->ClearAndSelect (anOwner); - anOwner->State (1); - if (anOwner == theObject->GlobalSelOwner()) - { - Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (theObject); - aState->SetHilightStatus (Standard_True); - aState->SetHilightStyle (anObjSelStyle); - } + Handle(Graphic3d_HighlightStyle) aCustomStyle; if (HighlightStyle (theObject, aCustomStyle)) { @@ -1093,6 +1084,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t { HilightWithColor (theObject, anObjSelStyle, Standard_False); } + anOwner->State (1); if (theToUpdateViewer) UpdateCurrentViewer(); diff --git a/src/AIS/AIS_LocalContext_1.cxx b/src/AIS/AIS_LocalContext_1.cxx index 921d245198..6a2a0887c4 100644 --- a/src/AIS/AIS_LocalContext_1.cxx +++ b/src/AIS/AIS_LocalContext_1.cxx @@ -1031,14 +1031,10 @@ void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj, Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj); if(EO.IsNull()){ - //check if in selection number 0 there is an owner that can be triturated... - if(anIObj->HasSelection(0)){ - const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); - SIOBJ->Init(); - if(SIOBJ->More()){ - Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId(); - EO = Handle(SelectMgr_EntityOwner)::DownCast (BO); - } + //check if global selection there is an owner that can be triturated... + if (anIObj->HasSelection (anIObj->GlobalSelectionMode())) + { + EO = anIObj->GlobalSelOwner(); } if(EO.IsNull()) EO = new SelectMgr_EntityOwner((const Handle(SelectMgr_SelectableObject)&)anIObj); @@ -1069,14 +1065,9 @@ void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& if (EO.IsNull()) { - if(anIObj->HasSelection(0)) + if(anIObj->HasSelection (anIObj->GlobalSelectionMode())) { - const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); - SIOBJ->Init(); - if(SIOBJ->More()){ - Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId(); - EO = Handle(SelectMgr_EntityOwner)::DownCast (BO); - } + EO = anIObj->GlobalSelOwner(); } if(EO.IsNull()) { diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index e2d38288db..0acfbd04ab 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -5310,6 +5310,27 @@ static Standard_Integer OCC27818 (Draw_Interpretor& /*theDI*/, Standard_Integer return 0; } +//======================================================================== +//function : OCC27893 +//purpose : Creates a box and selects it via AIS_InteractiveContext API +//======================================================================== +static Standard_Integer OCC27893 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv) +{ + const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); + if (aCtx.IsNull()) + { + std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n"; + return 1; + } + + TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape(); + Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox); + aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False); + aCtx->SetSelected (aBoxObj, Standard_True); + + return 0; +} + //======================================================================== //function : Commands_19 //purpose : @@ -5443,5 +5464,8 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) { theCommands.Add ("OCC27818", "OCC27818: Creates three boxes and highlights one of them with own style", __FILE__, OCC27818, group); + theCommands.Add ("OCC27893", + "OCC27893: Creates a box and selects it via AIS_InteractiveContext API", + __FILE__, OCC27893, group); return; } diff --git a/src/SelectMgr/SelectMgr_SelectionManager.cxx b/src/SelectMgr/SelectMgr_SelectionManager.cxx index 20a10f80d1..3e6de7b357 100644 --- a/src/SelectMgr/SelectMgr_SelectionManager.cxx +++ b/src/SelectMgr/SelectMgr_SelectionManager.cxx @@ -370,9 +370,10 @@ void SelectMgr_SelectionManager::Activate (const Handle(SelectMgr_SelectableObje if (myGlobal.Contains (theObject)) { - if (theMode != 0 && theSelector->IsActive (theObject, 0)) + const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode(); + if (theMode != aGlobalSelMode && theSelector->IsActive (theObject, aGlobalSelMode)) { - theSelector->Deactivate (theObject->Selection (0)); + theSelector->Deactivate (theObject->Selection (aGlobalSelMode)); } theSelector->Activate (theObject->Selection (theMode)); } diff --git a/tests/bugs/vis/bug27893 b/tests/bugs/vis/bug27893 new file mode 100644 index 0000000000..3a129889b9 --- /dev/null +++ b/tests/bugs/vis/bug27893 @@ -0,0 +1,17 @@ +puts "===========" +puts "OCC27893" +puts "===========" +puts "" +########################################################################## +# Visualization - AIS_InteractiveContext::SetSelected does not work +########################################################################## + +pload VISUALIZATION QAcommands + +vinit +OCC27893 +vfit + +if {[vnbselected] != "1" || [vreadpixel 204 254 name] != "GRAY80 1"} { + puts "ERROR: The box is not selected, AIS_InteractiveContext::SetSelected works incorrect" +}