Salome HOME
Task 2.2.5: Highlight all results if a shape of a one result is preselected
authorvsv <vsv@opencascade.com>
Thu, 9 Aug 2018 15:43:28 +0000 (18:43 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Fri, 10 Aug 2018 07:37:22 +0000 (10:37 +0300)
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h

index b3815aa530de635f45f26b1e7d8c8aab99d5abe1..3073bf450d83146ead97e6151fff677a75850fc2 100644 (file)
@@ -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);
index 788a0d906ec07a474aaa51c330f69b53264117e3..d763573e353fb6cccda447eec738675b03c3ffdf 100644 (file)
@@ -31,6 +31,9 @@
 #endif
 
 #include <ModuleBase_IViewWindow.h>
+#include <GeomAPI_Shape.h>
+
+#include <AIS_Shape.hxx>
 
 #include <QEvent>
 
@@ -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<ResultPtr> aResults = myFeature->results();
+  std::list<ResultPtr>::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<TopoDS_Shape>();
+    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);
 }
 
index 93e76332bcf84ce48894e4095c4842ecf5a078e6..9c4755f827084bfe5cb14c5a7b12a089fb84964a 100644 (file)
 
 #include "XGUI.h"
 #include <ModuleBase_IViewer.h>
+#include <ModelAPI_Feature.h>
 
 #include <AIS_Trihedron.hxx>
+#include <AIS_ListOfInteractive.hxx>
 
 #ifndef HAVE_SALOME
   #include <AppElements_ViewWindow.h>
@@ -152,7 +154,12 @@ private slots:
 #endif
 
  private:
+   void displayHighlight();
+   void eraseHighlight();
+
   XGUI_Workshop* myWorkshop;
+  FeaturePtr myFeature;
+  AIS_ListOfInteractive myHighlights;
 };
 
 #endif