diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 9e7c60f55d..355a3ba10c 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -1039,6 +1039,7 @@ public: //! Unhighlights previously selected owners and marks them as not selected. //! Marks owner given as selected and highlights it. + //! Performs selection filters check. Standard_EXPORT void SetSelected (const Handle(SelectMgr_EntityOwner)& theOwners, const Standard_Boolean theToUpdateViewer = Standard_True); @@ -1048,6 +1049,7 @@ public: //! Standard_False, the presentation of the Interactive //! Object activates the selection mode; the object is //! displayed but no viewer will be updated. + //! Performs selection filters check. Standard_EXPORT void SetSelected (const Handle(AIS_InteractiveObject)& theObject, const Standard_Boolean theToUpdateViewer = Standard_True); @@ -1610,6 +1612,12 @@ private: void highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner, const Quantity_NameOfColor theSelColor); + //! Helper function that unhighlights all owners that are stored in current AIS_Selection. + //! The function updates global status and selection state of owner and interactive object. + //! If the parameter is set to true, interactive objects with sub-intensity + //! switched on in AIS_GlobalStatus will be highlighted with context's sub-intensity color. + void unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity = Standard_False); + AIS_DataMapOfIOStatus myObjects; Handle(SelectMgr_SelectionManager) mgrSelector; Handle(PrsMgr_PresentationManager3d) myMainPM; diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 2cb6e921c0..901448c382 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -108,6 +108,56 @@ void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwn } } +//======================================================================= +//function : unhighlightSelected +//purpose : +//======================================================================= +void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity) +{ + AIS_Selection::SetCurrentSelection (myCurrentName.ToCString()); + Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString()); + NCollection_IndexedMap anObjToClear; + for (aCurSel->Init(); aCurSel->More(); aCurSel->Next()) + { + const Handle(SelectMgr_EntityOwner) anOwner = + Handle(SelectMgr_EntityOwner)::DownCast (aCurSel->Value()); + if (anOwner.IsNull() || !anOwner->HasSelectable()) + continue; + + const Handle(AIS_InteractiveObject) anInteractive = + Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); + if (anOwner->IsAutoHilight()) + { + const Standard_Integer aHiMode = anInteractive->HasHilightMode() ? anInteractive->HilightMode() : 0; + anOwner->Unhilight (myMainPM, aHiMode); + if (theIsToHilightSubIntensity) + { + if (myObjects.IsBound (anInteractive) && myObjects (anInteractive)->IsSubIntensityOn()) + { + anOwner->HilightWithColor (myMainPM, mySubIntensity, aHiMode); + } + } + } + else + { + if (!anObjToClear.Contains (anInteractive)) + anObjToClear.Add (anInteractive); + } + anOwner->State (0); + if (anOwner == anInteractive->GlobalSelOwner()) + { + myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False); + } + } + for (NCollection_IndexedMap::Iterator anIter (anObjToClear); anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObj = anIter.Value(); + const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0; + myMainPM->Unhighlight (anObj, aHiMode); + anObj->ClearSelected(); + } +} + //======================================================================= //function : MoveTo //purpose : @@ -391,47 +441,7 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdate } else { - AIS_Selection::SetCurrentSelection (myCurrentName.ToCString()); - Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection(); - NCollection_IndexedMap anObjToClear; - for (aSelection->Init(); aSelection->More(); aSelection->Next()) - { - const Handle(SelectMgr_EntityOwner) anOwner - = Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()); - - if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) - continue; - - const Handle(AIS_InteractiveObject) anObject = - Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - anOwner->State (0); - if (anOwner == anObject->GlobalSelOwner()) - { - myObjects.ChangeFind (anObject)->SetHilightStatus (Standard_False); - } - if (!anOwner->IsAutoHilight()) - { - if (!anObjToClear.Contains (anObject)) - anObjToClear.Add (anObject); - } - else - { - const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0; - anOwner->Unhilight (myMainPM, aHiMode); - if (myObjects.IsBound (anObject) && myObjects(anObject)->IsSubIntensityOn()) - { - anOwner->HilightWithColor (myMainPM, mySubIntensity, aHiMode); - } - } - } - while (!anObjToClear.IsEmpty()) - { - const Handle(AIS_InteractiveObject)& anObj = anObjToClear.FindKey (anObjToClear.Size()); - const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0; - myMainPM->Unhighlight (anObj, aHiMode); - anObj->ClearSelected(); - anObjToClear.RemoveLast(); - } + unhighlightSelected (Standard_True); AIS_Selection::Select(); if (toUpdateViewer && myWasLastMain) @@ -843,40 +853,7 @@ void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateVi if (NbSelected() == 0) return; - AIS_Selection::SetCurrentSelection (myCurrentName.ToCString()); - Handle(AIS_Selection) aSel = AIS_Selection::CurrentSelection(); - NCollection_IndexedMap anObjToClear; - for (aSel->Init(); aSel->More(); aSel->Next()) - { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value()); - if (!anOwner.IsNull() && anOwner->HasSelectable()) - { - const Handle(AIS_InteractiveObject) anObj = - Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - if (anOwner == anObj->GlobalSelOwner()) - { - myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); - } - anOwner->State (0); - if (!anOwner->IsAutoHilight()) - { - if (!anObjToClear.Contains (anObj)) - anObjToClear.Add (anObj); - } - else - { - const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0; - anOwner->Unhilight (myMainPM, aHiMode); - } - } - } - - while (!anObjToClear.IsEmpty()) - { - anObjToClear.FindKey (anObjToClear.Size())->ClearSelected(); - anObjToClear.RemoveLast(); - } + unhighlightSelected(); AIS_Selection::Select(); myMainPM->ClearImmediateDraw(); @@ -938,7 +915,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t { const Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSel->Value()); - if (anOwner.IsNull() || !anOwner->HasSelectable()) + if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) continue; Handle(AIS_InteractiveObject) aSelectable = @@ -991,7 +968,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Boolean theToUpdateViewer) { - if (theOwner.IsNull() || !theOwner->HasSelectable()) + if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner)) return; const Handle(AIS_InteractiveObject) anObject = @@ -1015,38 +992,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& t if (!myObjects.IsBound (anObject)) Display (anObject, Standard_False); - AIS_Selection::SetCurrentSelection (myCurrentName.ToCString()); - Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString()); - NCollection_IndexedMap anObjToClear; - for (aCurSel->Init(); aCurSel->More(); aCurSel->Next()) - { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (aCurSel->Value()); - if (!anOwner->HasSelectable()) - continue; - const Handle(AIS_InteractiveObject) anInteractive = - Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - if (anOwner->IsAutoHilight()) - { - const Standard_Integer aHiMode = anInteractive->HasHilightMode() ? anInteractive->HilightMode() : 0; - anOwner->Unhilight (myMainPM, aHiMode); - } - else - { - if (!anObjToClear.Contains (anInteractive)) - anObjToClear.Add (anInteractive); - } - anOwner->State (0); - if (theOwner == anObject->GlobalSelOwner()) - { - myObjects.ChangeFind (anObject)->SetHilightStatus (Standard_False); - } - } - while (!anObjToClear.IsEmpty()) - { - anObjToClear.FindKey (anObjToClear.Size())->ClearSelected(); - anObjToClear.RemoveLast(); - } + unhighlightSelected(); AIS_Selection::ClearAndSelect (theOwner); theOwner->State (1); diff --git a/tests/bugs/vis/bug26721 b/tests/bugs/vis/bug26721 new file mode 100644 index 0000000000..7e9e7f9708 --- /dev/null +++ b/tests/bugs/vis/bug26721 @@ -0,0 +1,34 @@ +puts "============" +puts "CR26721" +puts "============" +puts "" + +########################################################################################## +puts "Visualization - selection highlight of selected face is broken" +########################################################################################## + +pload VISUALIZATION MODELING + +box b 1 1 1 +vinit +vdisplay b +vfit + +# select box in 0 selection mode +vselect 200 200 + +vselmode 4 1 +# select box's face +vselect 200 300 + +# check if highlight is correct: +# 1. check if other edges of the box are not highlighted +if {[vreadpixel 292 356 name] != "YELLOW 1"} { + puts "ERROR: the box is drawn with the color that isn't equal to default!" +} +# 2. check if previously selected face is highlighted with selection color +if {[vreadpixel 204 301 name] != "GRAY80 1"} { + puts "ERROR: the face selected is not highlighted with selection color!" +} + +set only_screen 1