]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Use INode instead of IG3DNode in selections 36/3436/2
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 31 Oct 2019 15:15:52 +0000 (17:15 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 31 Oct 2019 15:20:23 +0000 (17:20 +0200)
g3d.vtk plug-in upgraded to Java 1.8.

gitlab #29

Change-Id: I2ef5f1da94b1c026b0af53029803765e68fd9b29

org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGEditor2.java
org.simantics.g3d.vtk/.settings/org.eclipse.jdt.core.prefs
org.simantics.g3d.vtk/META-INF/MANIFEST.MF
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/action/RemoveAction.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/NodeSelectionProvider2.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java
org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java

index 91b51419c0704a78b72d6cf25f9b5687adfe43c5..3a85691b07a400eb0bca0ff97a7772cc76b59260 100644 (file)
@@ -301,7 +301,7 @@ public class CSGEditor2  extends ResourceEditorPart {
                menuMgr.addMenuListener(new IMenuListener() {
                        public void menuAboutToShow(IMenuManager manager) {
                                final IMenuManager m = manager;
-                               List<IG3DNode> selected = selectionProvider.getSelectedNodes();
+                               List<INode> selected = selectionProvider.getSelectedNodes();
                                if (selected.size() == 0) {
                                        m.add(new AddPrimitiveAction2(rootNode, BarrelNode.class));
                                        m.add(new AddPrimitiveAction2(rootNode, BoxNode.class));
@@ -326,7 +326,7 @@ public class CSGEditor2  extends ResourceEditorPart {
                                } else if (selected.size() == 2) {
                                        if (selected.get(0).getParent().equals(rootNode) && selected.get(1).getParent().equals(rootNode)) {
                                                Collection<ICSGnode> nodes = new ArrayList<ICSGnode>();
-                                               for (IG3DNode n : selected)
+                                               for (INode n : selected)
                                                        nodes.add((ICSGnode)n);
                                                m.add(new AddBooleanOpAction2(rootNode, DifferenceNode.class, nodes));
                                                m.add(new AddBooleanOpAction2(rootNode, IntersectionNode.class, nodes));
index 2bbbf6990bc399e37fc141d3d0a779c48ea3ccf0..0c68a61dca867ceb49e79d2402935261ec3e3809 100644 (file)
@@ -1,8 +1,7 @@
-#Thu Mar 29 15:34:08 EEST 2012\r
-eclipse.preferences.version=1\r
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
-org.eclipse.jdt.core.compiler.compliance=1.6\r
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
-org.eclipse.jdt.core.compiler.source=1.6\r
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
index 3a9a0aaed986a890893a6896a347ced60b03c9da..827e4638162a173e595f76e3e591171b99b9d833 100644 (file)
@@ -20,7 +20,7 @@ Require-Bundle: org.eclipse.core.runtime,
  org.simantics.utils.ui;bundle-version="1.1.0",
  vtk.rendering;bundle-version="8.2.0",
  org.simantics.utils.thread.swt;bundle-version="1.1.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.g3d.vtk.action,
  org.simantics.g3d.vtk.awt,
index 8fcb93681bd3ea70d06e7997385220122b65b226..2ff89210f3657972e56a2ea5e855b4c617964738 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.g3d.vtk.action;
 
 import org.eclipse.jface.action.Action;
 import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.g3d.scenegraph.structural.IStructuralNode;
 import org.simantics.g3d.vtk.Activator;
 import org.simantics.g3d.vtk.common.VTKNodeMap;
@@ -20,7 +21,7 @@ import org.simantics.g3d.vtk.common.VTKNodeMap;
 public class RemoveAction extends Action {
 
        private VTKNodeMap nodeMap;
-       protected IG3DNode node;
+       protected INode node;
        
        public RemoveAction(VTKNodeMap nodeMap) {
                setText("Remove");
@@ -28,12 +29,12 @@ public class RemoveAction extends Action {
                this.nodeMap = nodeMap;
        }
        
-       public void setNode(IG3DNode node) {
+       public void setNode(INode node) {
                this.node = node;
                setEnabled(isRemovable(node));
        }
        
-       public boolean isRemovable(IG3DNode node) {
+       public boolean isRemovable(INode node) {
                if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot())
                        return false;
                return true;
@@ -47,7 +48,7 @@ public class RemoveAction extends Action {
                node = null;
        }
        
-       protected void doRemove(IG3DNode node) {
+       protected void doRemove(INode node) {
                node.remove();
        }
 }
index d5b8d70953db52e3dac044cbd224613537b24fa4..b9e3a0e8fc222f330e1e05e91156d945f7180ac3 100644 (file)
@@ -37,7 +37,7 @@ public class NodeSelectionProvider2<DBObject,JavaObject> implements ISelectionPr
     protected ISelection selection = new StructuredSelection();
        protected List<ISelectionChangedListener> listeners = new ArrayList<ISelectionChangedListener>();
        
-       protected List<IG3DNode> selectedNodes = new ArrayList<IG3DNode>(); // selection is ordered
+       protected List<INode> selectedNodes = new ArrayList<>(); // selection is ordered
        //List<Resource> selectedResources = new ArrayList<Resource>();
        protected List<VTKSelectionItem<DBObject>> selectedItems = new ArrayList<VTKSelectionItem<DBObject>>();
        
@@ -85,6 +85,9 @@ public class NodeSelectionProvider2<DBObject,JavaObject> implements ISelectionPr
                }
                processSelection(new StructuredSelection(nodes.toArray()));
                fireSelectionChanged(this);
+           } else {
+               processSelection(selection);
+            fireSelectionChanged(this);
            }
                
        }
@@ -102,30 +105,33 @@ public class NodeSelectionProvider2<DBObject,JavaObject> implements ISelectionPr
        protected void processSelection(ISelection s) {
                selectedNodes.clear();
                selectedItems.clear();
-               
-               Collection<vtkProp> selectedActors = AdaptationUtils.adaptToCollection(s, vtkProp.class);
-               if (selectedActors.size() > 0) {
-                       for (vtkProp a : selectedActors) {
-                               IG3DNode node = (IG3DNode)nodeMap.getNode((vtkProp)a);
-                               if (node == null)
-                                       continue;
-                               if (!selectedNodes.contains(node))
-                                       selectedNodes.add(node);
-                               DBObject r = mapping.inverseGet((JavaObject)node);
-                               selectedItems.add(new VTKSelectionItem<DBObject>(a, node,r));
-                       }
-               } else {
-                       Collection<IG3DNode> selectedNds = AdaptationUtils.adaptToCollection(s, IG3DNode.class);
-                       for (INode node : selectedNds) {
-                               if (!selectedNodes.contains(node))
-                                       selectedNodes.add((IG3DNode)node);
-                               DBObject r = mapping.inverseGet((JavaObject)node);
-                               selectedItems.add(new VTKSelectionItem<DBObject>(null, (IG3DNode)node,r));
-                       }
-               }
-               
-               
-               selection = new StructuredSelection(selectedItems);
+               _processSelection(s);
+       }
+       
+       protected void _processSelection(ISelection s) {
+           Collection<vtkProp> selectedActors = AdaptationUtils.adaptToCollection(s, vtkProp.class);
+        if (selectedActors.size() > 0) {
+            for (vtkProp a : selectedActors) {
+                IG3DNode node = (IG3DNode)nodeMap.getNode((vtkProp)a);
+                if (node == null)
+                    continue;
+                if (!selectedNodes.contains(node))
+                    selectedNodes.add(node);
+                DBObject r = mapping.inverseGet((JavaObject)node);
+                selectedItems.add(new VTKSelectionItem<DBObject>(a, node,r));
+            }
+        } else {
+            Collection<IG3DNode> selectedNds = AdaptationUtils.adaptToCollection(s, IG3DNode.class);
+            for (INode node : selectedNds) {
+                if (!selectedNodes.contains(node))
+                    selectedNodes.add((IG3DNode)node);
+                DBObject r = mapping.inverseGet((JavaObject)node);
+                selectedItems.add(new VTKSelectionItem<DBObject>(null, (IG3DNode)node,r));
+            }
+        }
+        
+        
+        selection = new StructuredSelection(selectedItems);
        }
        
        protected void fireSelectionChanged(Object source) {
@@ -146,10 +152,14 @@ public class NodeSelectionProvider2<DBObject,JavaObject> implements ISelectionPr
                
        }
        
-       public List<IG3DNode> getSelectedNodes() {
+       public List<INode> getSelectedNodes() {
                return selectedNodes;
        }
        
+       public List<VTKSelectionItem<DBObject>> getSelectedItems() {
+        return selectedItems;
+    }
+       
        @SuppressWarnings("unchecked")
        public List<DBObject> getSelectedResources() {
                
index 222da8b92012de4a404d0d3f862b84ed926768e3..f332322f27287d68b855669ffd46cc94796c2fe5 100644 (file)
@@ -22,10 +22,10 @@ import vtk.vtkProp;
 public class VTKSelectionItem<DBObject> implements IAdaptable{
 
        private vtkProp prop;
-       private IG3DNode node;
+       private INode node;
        private DBObject resource;
        
-       public VTKSelectionItem(vtkProp prop, IG3DNode node, DBObject res) {
+       public VTKSelectionItem(vtkProp prop, INode node, DBObject res) {
                this.prop = prop;
                this.node = node;
                this.resource = res;
@@ -46,7 +46,7 @@ public class VTKSelectionItem<DBObject> implements IAdaptable{
                                return null;
                if (adapter == vtkProp.class)
                        return prop;
-               if (adapter == IG3DNode.class)
+               if (adapter == IG3DNode.class && node instanceof IG3DNode)
                        return node;
                if (adapter == INode.class)
                        return node;
index d20a59c053179590d91833ff8a450c63dd264878..3dc6a4aee38ade811b3ea872752aef96fdc13071 100644 (file)
@@ -1,6 +1,6 @@
 package org.simantics.plant3d.actions;
 
-import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.g3d.vtk.action.RemoveAction;
 import org.simantics.g3d.vtk.common.VTKNodeMap;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
@@ -13,7 +13,7 @@ public class RemoveAndSplitAction extends RemoveAction {
     }
     
     @Override
-    public boolean isRemovable(IG3DNode node) {
+    public boolean isRemovable(INode node) {
         if (!super.isRemovable(node))
             return false;
         if (!(node instanceof PipelineComponent))
@@ -26,7 +26,7 @@ public class RemoveAndSplitAction extends RemoveAction {
     
     
     @Override
-    protected void doRemove(IG3DNode node) {
+    protected void doRemove(INode node) {
         PipelineComponent pc = (PipelineComponent)node;
         pc.removeAndSplit();
     }
index 2dc90bdd57466abf8f3bd2c4f4bc8d9002799fe4..5775035a1e48cb5cb6368d02ad20fdde686c1c4f 100644 (file)
@@ -89,7 +89,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        private P3DRootNode rootNode;
        private IMapping<Resource,Object> mapping;
        
-       private NodeSelectionProvider2<Resource,Object> selectionProvider;
+       protected NodeSelectionProvider2<Resource,Object> selectionProvider;
        
        protected vtkCameraAndSelectorAction cameraAction;
        protected TranslateAction translateAction;
@@ -357,7 +357,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        }
        
        protected void createContextMenu(IMenuManager m) {
-               List<IG3DNode> selected = selectionProvider.getSelectedNodes();
+               List<INode> selected = selectionProvider.getSelectedNodes();
                try {
                        if (selected.size() == 0) {
                                for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {