]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Allow setSelection from other components 19/3419/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 29 Oct 2019 12:04:06 +0000 (14:04 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 29 Oct 2019 12:04:06 +0000 (14:04 +0200)
Additionally, allow other components to utilize node highlight method

gitlab #29

Change-Id: Ifcee2c1691456f389c8460b50cf1235c3750ac42

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/NodeSelectionProvider2.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/SelectionHighlighter.java

index 5de69f354b03b38142772ccb227bd339589f95c6..d5b8d70953db52e3dac044cbd224613537b24fa4 100644 (file)
@@ -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<DBObject,JavaObject> implements ISelectionPr
        
        @Override
        public void setSelection(ISelection selection) {
+           Collection<IG3DNode> nodes = AdaptionUtils.adaptToCollection(selection, IG3DNode.class);
+           Collection<Resource> resources= AdaptionUtils.adaptToCollection(selection, Resource.class);
+           if (nodes.size() > 0) {
+               processSelection(selection);
+               fireSelectionChanged(this);
+           } else if (resources.size() > 0) {
+               nodes = new ArrayList<IG3DNode>();
+               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);
+           }
                
        }
        
index 789cfb1883c7218fde90b5d4e54b1ac740f3c091..9998f5bf4520482ab38e10d641b6aaa52cac2f60 100644 (file)
@@ -171,7 +171,7 @@ public class SelectionHighlighter<E extends INode> 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;