From 6dd5b348d85e1b5d9dffa9422a01388701b061eb Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 29 Oct 2019 14:04:06 +0200 Subject: [PATCH] Allow setSelection from other components Additionally, allow other components to utilize node highlight method gitlab #29 Change-Id: Ifcee2c1691456f389c8460b50cf1235c3750ac42 --- .../g3d/vtk/common/NodeSelectionProvider2.java | 17 +++++++++++++++++ .../g3d/vtk/common/SelectionHighlighter.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/NodeSelectionProvider2.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/NodeSelectionProvider2.java index 5de69f35..d5b8d709 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/NodeSelectionProvider2.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/NodeSelectionProvider2.java @@ -29,6 +29,7 @@ import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.tools.AdaptationUtils; import org.simantics.objmap.graph.IMapping; import org.simantics.objmap.structural.StructuralResource; +import org.simantics.utils.ui.AdaptionUtils; import vtk.vtkProp; @@ -69,6 +70,22 @@ public class NodeSelectionProvider2 implements ISelectionPr @Override public void setSelection(ISelection selection) { + Collection nodes = AdaptionUtils.adaptToCollection(selection, IG3DNode.class); + Collection resources= AdaptionUtils.adaptToCollection(selection, Resource.class); + if (nodes.size() > 0) { + processSelection(selection); + fireSelectionChanged(this); + } else if (resources.size() > 0) { + nodes = new ArrayList(); + for (Resource r : resources) { + JavaObject n = mapping.get((DBObject)r); + if (n instanceof IG3DNode) { + nodes.add((IG3DNode)n); + } + } + processSelection(new StructuredSelection(nodes.toArray())); + fireSelectionChanged(this); + } } diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/SelectionHighlighter.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/SelectionHighlighter.java index 789cfb18..9998f5bf 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/SelectionHighlighter.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/SelectionHighlighter.java @@ -171,7 +171,7 @@ public class SelectionHighlighter implements ISelectionChangedL } - protected void setColor(E node, boolean edge, double color[]) { + public void setColor(E node, boolean edge, double color[]) { for (vtkProp prop : nodeMap.getRenderObjects(node)) { if (prop instanceof vtkActor) { vtkActor act = (vtkActor)prop; -- 2.47.1