From 9c24a2565d7c79d152607ba06170ce7bd2e3eda8 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 9 Aug 2018 18:43:28 +0300 Subject: [PATCH] Task 2.2.5: Highlight all results if a shape of a one result is preselected --- src/XGUI/XGUI_Selection.cpp | 1 - src/XGUI/XGUI_ViewerProxy.cpp | 64 +++++++++++++++++++++++++++++++++++ src/XGUI/XGUI_ViewerProxy.h | 7 ++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index b3815aa53..3073bf450 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -143,7 +143,6 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs, const Handle(SelectMgr_EntityOwner)& theOwner) const { thePrs->setOwner(theOwner); - Handle(SelectMgr_SelectableObject) aSelectable = theOwner->Selectable(); Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); thePrs->setInteractive(anIO); diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 788a0d906..d763573e3 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -31,6 +31,9 @@ #endif #include +#include + +#include #include @@ -283,8 +286,69 @@ void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouse emit mouseDoubleClick(theWnd, theEvent); } +void XGUI_ViewerProxy::displayHighlight() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + std::list aResults = myFeature->results(); + std::list::const_iterator aIt; + ResultPtr aRes; + Handle(AIS_Shape) aAis; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { + aRes = (*aIt); + TopoDS_Shape aTShape = aRes->shape()->impl(); + aAis = new AIS_Shape(aTShape); + aAis->SetColor(Quantity_NOC_CYAN3); + aAis->SetZLayer(Graphic3d_ZLayerId_Topmost); + myHighlights.Append(aAis); + aContext->Display(aAis, false); + aContext->Deactivate(aAis); + } +} + +void XGUI_ViewerProxy::eraseHighlight() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + Handle(AIS_InteractiveObject) anAISIO; + AIS_ListIteratorOfListOfInteractive aLIt; + for (aLIt.Initialize(myHighlights); aLIt.More(); aLIt.Next()) { + anAISIO = aLIt.Value(); + aContext->Remove(anAISIO, false); + } + myHighlights.Clear(); +} + void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent) { + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Handle(SelectMgr_EntityOwner) aOwner; + Handle(AIS_InteractiveObject) anIO; + ObjectPtr aObj; + bool isDisplayed = false; + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { + aOwner = aContext->DetectedOwner(); + anIO = Handle(AIS_InteractiveObject)::DownCast(aOwner->Selectable()); + aObj = aDisplayer->getObject(anIO); + if (aObj.get()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature.get()) { + if (aFeature != myFeature) { + eraseHighlight(); + myFeature = aFeature; + displayHighlight(); + aContext->UpdateCurrentViewer(); + } + isDisplayed = true; + } + } + } + if (!isDisplayed) { + eraseHighlight(); + aContext->UpdateCurrentViewer(); + myFeature = FeaturePtr(); + } + } emit mouseMove(theWnd, theEvent); } diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index 93e76332b..9c4755f82 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -23,8 +23,10 @@ #include "XGUI.h" #include +#include #include +#include #ifndef HAVE_SALOME #include @@ -152,7 +154,12 @@ private slots: #endif private: + void displayHighlight(); + void eraseHighlight(); + XGUI_Workshop* myWorkshop; + FeaturePtr myFeature; + AIS_ListOfInteractive myHighlights; }; #endif -- 2.30.2