From: nds Date: Wed, 22 May 2019 14:33:02 +0000 (+0300) Subject: 0030728: Visualization - using one implementation of highlight/unhighlight in context X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=7fc133f086611b4f4e36b658f99c29012da921d1;p=occt-copy.git 0030728: Visualization - using one implementation of highlight/unhighlight in context (cherry picked from commit 36b87936acf5a89d573663b5e8d086a4a4a084d3) # Conflicts: # src/AIS/AIS_InteractiveContext_1.cxx --- diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index 572979090b..35e2032af3 100644 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -2018,10 +2018,10 @@ void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& t } //======================================================================= -//function : unhighlightOwners +//function : unselectOwners //purpose : //======================================================================= -void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject) +void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject) { SelectMgr_SequenceOfOwner aSeq; for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) @@ -2055,7 +2055,7 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t } Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj); - unhighlightOwners (theIObj); + unselectOwners (theIObj); myMainPM->Erase (theIObj, -1); theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 779af679bc..a3aed75b55 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -1201,7 +1201,7 @@ protected: //! @name internal methods const Standard_Boolean theToUpdateViewer); //! Helper function to unhighlight all entity owners currently highlighted with seleciton color. - Standard_EXPORT void unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject); + Standard_EXPORT void unselectOwners (const Handle(AIS_InteractiveObject)& theObject); //! Helper function that highlights the owner given with without //! performing AutoHighlight checks, e.g. is used for dynamic highlight. @@ -1212,12 +1212,17 @@ protected: //! @name internal methods //! for AutoHighlight, e.g. is used for selection. Standard_EXPORT void highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner); + //! Helper function that highlights the owners given with with check + //! for AutoHighlight, e.g. is used for selection. + Standard_EXPORT void highlightOwners (const AIS_NListOfEntityOwner& theOwners, + const Standard_Boolean& theToUseObjectDisplayMode); + //! Helper function that highlights global owner of the object given with with check //! for AutoHighlight, e.g. is used for selection. //! If global owner is null, it simply highlights the whole object Standard_EXPORT void highlightGlobal (const Handle(AIS_InteractiveObject)& theObj, const Handle(Prs3d_Drawer)& theStyle, - const Standard_Integer theDispMode) const; + const Standard_Integer theDispMode); //! 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. @@ -1225,9 +1230,14 @@ protected: //! @name internal methods //! switched on in AIS_GlobalStatus will be highlighted with context's sub-intensity color. Standard_EXPORT void unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity = Standard_False); + //! Helper function that highlights the owners given with with check + //! for AutoHighlight, e.g. is used for selection. + Standard_EXPORT void unhighlightOwners (const AIS_NListOfEntityOwner& theOwners, + const Standard_Boolean theIsToHilightSubIntensity = Standard_False); + //! Helper function that unhighlights global selection owner of given interactive. //! The function does not perform any updates of global or owner status - Standard_EXPORT void unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const; + Standard_EXPORT void unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj); //! Helper function that turns on sub-intensity in global status and highlights //! given objects with sub-intensity color diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 55b7c299e3..4f88964e1a 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -85,30 +85,9 @@ void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOw //======================================================================= void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner) { - const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); - if (anObj.IsNull()) - { - return; - } - - if (!theOwner->IsAutoHilight()) - { - SelectMgr_SequenceOfOwner aSeq; - for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) - { - if (aSelIter.Value()->IsSameSelectable (anObj)) - { - aSeq.Append (aSelIter.Value()); - } - } - anObj->HilightSelected (myMainPM, aSeq); - } - else - { - const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner); - const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1); - theOwner->HilightWithColor (myMainPM, aStyle, aHiMode); - } + AIS_NListOfEntityOwner anOwners; + anOwners.Append (theOwner); + highlightOwners (anOwners, Standard_False/*check if it is really important*/); } //======================================================================= @@ -117,14 +96,15 @@ void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwn //======================================================================= void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj, const Handle(Prs3d_Drawer)& theStyle, - const Standard_Integer theDispMode) const + const Standard_Integer /*theDispMode*/) { if (theObj.IsNull()) { return; } - const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode); + const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj); + const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, aStatus->DisplayMode()); const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner(); if (aGlobOwner.IsNull()) @@ -133,22 +113,9 @@ void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject return; } - if (!aGlobOwner->IsAutoHilight()) - { - SelectMgr_SequenceOfOwner aSeq; - for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) - { - if (aSelIter.Value()->IsSameSelectable (theObj)) - { - aSeq.Append (aSelIter.Value()); - } - } - theObj->HilightSelected (myMainPM, aSeq); - } - else - { - aGlobOwner->HilightWithColor (myMainPM, theStyle, aHiMode); - } + AIS_NListOfEntityOwner anOwners; + anOwners.Append (aGlobOwner); + highlightOwners (anOwners, Standard_True); } //======================================================================= @@ -156,24 +123,30 @@ void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject //purpose : //======================================================================= void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity) +{ + unhighlightOwners (mySelection->Objects(), theIsToHilightSubIntensity); +} + +//======================================================================= +//function : unhighlightOwners +//purpose : +//======================================================================= +void AIS_InteractiveContext::unhighlightOwners (const AIS_NListOfEntityOwner& theOwners, + const Standard_Boolean theIsToHilightSubIntensity) { NCollection_IndexedMap anObjToClear; - for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next()) { const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - Handle(AIS_GlobalStatus) aStatus; - if (!myObjects.Find (anInteractive, aStatus)) - { - continue; - } + Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anInteractive); if (anOwner->IsAutoHilight()) { anOwner->Unhilight (myMainPM); if (theIsToHilightSubIntensity) { - if (aStatus->IsSubIntensityOn()) + if (!aStatus.IsNull() && aStatus->IsSubIntensityOn()) { const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode()); highlightWithSubintensity (anOwner, aHiMode); @@ -184,9 +157,9 @@ void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsTo { anObjToClear.Add (anInteractive); } - if (anOwner == anInteractive->GlobalSelOwner()) + if (!aStatus.IsNull() && anOwner == anInteractive->GlobalSelOwner()) { - myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False); + aStatus->SetHilightStatus (Standard_False); } } for (NCollection_IndexedMap::Iterator anIter (anObjToClear); anIter.More(); anIter.Next()) @@ -201,7 +174,7 @@ void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsTo //function : unhighlightGlobal //purpose : //======================================================================= -void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const +void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) { if (theObj.IsNull()) { @@ -215,15 +188,9 @@ void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObje return; } - if (aGlobOwner->IsAutoHilight()) - { - aGlobOwner->Unhilight (myMainPM); - } - else - { - myMainPM->Unhighlight (theObj); - theObj->ClearSelected(); - } + AIS_NListOfEntityOwner anOwners; + anOwners.Append (aGlobOwner); + unhighlightOwners (anOwners); } //======================================================================= @@ -667,14 +634,31 @@ void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdate { // In case of selection without using local context clearDynamicHighlight(); + + highlightOwners (mySelection->Objects(), Standard_True); + + if (theToUpdateViewer) + UpdateCurrentViewer(); +} + +//======================================================================= +//function : highlightOwners +//purpose : +//======================================================================= +void AIS_InteractiveContext::highlightOwners (const AIS_NListOfEntityOwner& theOwners, + const Standard_Boolean& theToUseObjectDisplayMode) +{ AIS_MapOfObjSelectedOwners anObjOwnerMap; - for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next()) { const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); + if (anObj.IsNull()) + continue; + const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner); Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj); - if (anOwner == anObj->GlobalSelOwner()) + if (theToUseObjectDisplayMode && anOwner == anObj->GlobalSelOwner()) { aState->SetHilightStatus (Standard_True); aState->SetHilightStyle (anObjSelStyle); @@ -695,7 +679,7 @@ void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdate } else { - const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode()); + const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, theToUseObjectDisplayMode ? aState->DisplayMode() : -1); anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); } } @@ -708,9 +692,6 @@ void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdate } anObjOwnerMap.Clear(); } - - if (theToUpdateViewer) - UpdateCurrentViewer(); } //======================================================================= @@ -719,17 +700,7 @@ void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdate //======================================================================= void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer) { - for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) - { - const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); - const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - if (anOwner == anObj->GlobalSelOwner()) - { - myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); - } - - anOwner->Unhilight (myMainPM); - } + unhighlightSelected(); if (theToUpdateViewer) UpdateCurrentViewer(); @@ -884,13 +855,6 @@ void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& t } } - if (myAutoHilight && theOwner == anObject->GlobalSelOwner()) - { - Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject); - aState->SetHilightStatus (Standard_True); - aState->SetHilightStyle (anObjSelStyle); - } - if (theToUpdateViewer) UpdateCurrentViewer(); } @@ -937,30 +901,19 @@ void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityO if (myAutoHilight) { const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); - const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner; if (!myObjects.IsBound(anObj)) // e.g. AIS_ViewCubeFlat is not displayed return; Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj); if (theOwner->IsSelected()) { highlightSelected (theOwner); - if (isGlobal) - { - aStatus->SetHilightStatus (Standard_True); - aStatus->SetHilightStyle (getSelStyle (anObj, theOwner)); - } } else { - if (theOwner->IsAutoHilight()) - { - theOwner->Unhilight (myMainPM); - } - else - { - anObj->ClearSelected(); - } - aStatus->SetHilightStatus (Standard_False); + AIS_NListOfEntityOwner anOwners; + anOwners.Append (theOwner); + unhighlightOwners (anOwners); + aStatus->SetHilightStyle (Handle(Prs3d_Drawer)()); } }