From: Marko Luukkainen Date: Thu, 31 Oct 2019 15:15:52 +0000 (+0200) Subject: Use INode instead of IG3DNode in selections X-Git-Tag: v1.43.0~157 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=db7a5dfe7c90c6752e871f84de0f70a182dd527a;p=simantics%2F3d.git Use INode instead of IG3DNode in selections g3d.vtk plug-in upgraded to Java 1.8. gitlab #29 Change-Id: I2ef5f1da94b1c026b0af53029803765e68fd9b29 --- diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGEditor2.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGEditor2.java index 91b51419..3a85691b 100644 --- a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGEditor2.java +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGEditor2.java @@ -301,7 +301,7 @@ public class CSGEditor2 extends ResourceEditorPart { menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { final IMenuManager m = manager; - List selected = selectionProvider.getSelectedNodes(); + List 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 nodes = new ArrayList(); - 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)); diff --git a/org.simantics.g3d.vtk/.settings/org.eclipse.jdt.core.prefs b/org.simantics.g3d.vtk/.settings/org.eclipse.jdt.core.prefs index 2bbbf699..0c68a61d 100644 --- a/org.simantics.g3d.vtk/.settings/org.eclipse.jdt.core.prefs +++ b/org.simantics.g3d.vtk/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,7 @@ -#Thu Mar 29 15:34:08 EEST 2012 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +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 diff --git a/org.simantics.g3d.vtk/META-INF/MANIFEST.MF b/org.simantics.g3d.vtk/META-INF/MANIFEST.MF index 3a9a0aae..827e4638 100644 --- a/org.simantics.g3d.vtk/META-INF/MANIFEST.MF +++ b/org.simantics.g3d.vtk/META-INF/MANIFEST.MF @@ -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, diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/action/RemoveAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/action/RemoveAction.java index 8fcb9368..2ff89210 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/action/RemoveAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/action/RemoveAction.java @@ -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(); } } 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 d5b8d709..b9e3a0e8 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 @@ -37,7 +37,7 @@ public class NodeSelectionProvider2 implements ISelectionPr protected ISelection selection = new StructuredSelection(); protected List listeners = new ArrayList(); - protected List selectedNodes = new ArrayList(); // selection is ordered + protected List selectedNodes = new ArrayList<>(); // selection is ordered //List selectedResources = new ArrayList(); protected List> selectedItems = new ArrayList>(); @@ -85,6 +85,9 @@ public class NodeSelectionProvider2 implements ISelectionPr } processSelection(new StructuredSelection(nodes.toArray())); fireSelectionChanged(this); + } else { + processSelection(selection); + fireSelectionChanged(this); } } @@ -102,30 +105,33 @@ public class NodeSelectionProvider2 implements ISelectionPr protected void processSelection(ISelection s) { selectedNodes.clear(); selectedItems.clear(); - - Collection 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(a, node,r)); - } - } else { - Collection 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(null, (IG3DNode)node,r)); - } - } - - - selection = new StructuredSelection(selectedItems); + _processSelection(s); + } + + protected void _processSelection(ISelection s) { + Collection 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(a, node,r)); + } + } else { + Collection 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(null, (IG3DNode)node,r)); + } + } + + + selection = new StructuredSelection(selectedItems); } protected void fireSelectionChanged(Object source) { @@ -146,10 +152,14 @@ public class NodeSelectionProvider2 implements ISelectionPr } - public List getSelectedNodes() { + public List getSelectedNodes() { return selectedNodes; } + public List> getSelectedItems() { + return selectedItems; + } + @SuppressWarnings("unchecked") public List getSelectedResources() { diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java index 222da8b9..f332322f 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java @@ -22,10 +22,10 @@ import vtk.vtkProp; public class VTKSelectionItem 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 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; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java index d20a59c0..3dc6a4ae 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java @@ -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(); } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 2dc90bdd..5775035a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -89,7 +89,7 @@ public class Plant3DEditor extends ResourceEditorPart { private P3DRootNode rootNode; private IMapping mapping; - private NodeSelectionProvider2 selectionProvider; + protected NodeSelectionProvider2 selectionProvider; protected vtkCameraAndSelectorAction cameraAction; protected TranslateAction translateAction; @@ -357,7 +357,7 @@ public class Plant3DEditor extends ResourceEditorPart { } protected void createContextMenu(IMenuManager m) { - List selected = selectionProvider.getSelectedNodes(); + List selected = selectionProvider.getSelectedNodes(); try { if (selected.size() == 0) { for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {