]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Use generics type variable for mapping db object. 20/3420/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 29 Oct 2019 13:39:29 +0000 (15:39 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 29 Oct 2019 13:39:29 +0000 (15:39 +0200)
gitlab #41

Change-Id: I59d5e8bf979ed70808cba17d447c7288599b2c66

16 files changed:
org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGNodeMap.java
org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/SelectionHighlighter.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKNodeMap.java
org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java
org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMap.java
org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMapProvider.java
org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java
org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java
org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java
org.simantics.plant3d/src/org/simantics/plant3d/scl/P3DScriptNodeMap.java

index c2712b8ce7e5dee61c662cbce1f95cba002bbbb3..bcd28db4dd214fce84f9ac717c3171c18642715c 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
+import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
 import org.simantics.g3d.csg.scenegraph2.ICSGnode;
@@ -27,7 +28,7 @@ import org.simantics.objmap.graph.IMapping;
 import vtk.vtkProp;
 import vtk.vtkProp3D;
 
-public class CSGNodeMap extends AbstractVTKNodeMap<ICSGnode> {
+public class CSGNodeMap extends AbstractVTKNodeMap<Resource,ICSGnode> {
        
 
        
index d88b42ed66adbc77863f986c094c93315e3a7d6e..9ae55a1fe33458359f5105108362578d44c6e614 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Stack;
 import javax.vecmath.Quat4d;
 import javax.vecmath.Vector3d;
 
+import org.simantics.db.Resource;
 import org.simantics.g3d.csg.editor.CSGNodeMap;
 import org.simantics.g3d.csg.ontology.CSG;
 import org.simantics.g3d.math.MathTools;
@@ -36,7 +37,7 @@ import vtk.vtkProp;
 
 
 @GraphType(CSG.URIs.Model)
-public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<vtkProp, ICSGnode> {
+public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<Resource,vtkProp, ICSGnode> {
        
        
        private CSGNodeMap nodeMap;
@@ -46,7 +47,7 @@ public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeM
        }
        
        @Override
-       public NodeMap<vtkProp, ICSGnode> getNodeMap() {
+       public NodeMap<Resource,vtkProp, ICSGnode> getNodeMap() {
                return nodeMap;
        }
        
index efb4c07b151d95b4ee336984f861c8dc094de69c..953ef198b2d43cbbd18c7f7285596fffaf88935c 100644 (file)
@@ -48,12 +48,12 @@ import org.simantics.utils.ui.ExceptionUtils;
 
 import vtk.vtkProp;
 
-public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<E>, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{
+public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VTKNodeMap<DBObject,E>, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{
 
        private static final boolean DEBUG = false;
        
        protected Session session;
-       protected IMapping<Object,E> mapping;
+       protected IMapping<DBObject,E> mapping;
        protected VtkView view;
        
        protected MapList<E, vtkProp> nodeToActor = new MapList<E, vtkProp>();
@@ -66,7 +66,7 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
        protected int redoOpCount = 0;
        protected boolean runUndo = false;
        protected boolean runRedo = false;
-       public AbstractVTKNodeMap(Session session, IMapping<Object,E> mapping, VtkView view, ParentNode<E> rootNode) {
+       public AbstractVTKNodeMap(Session session, IMapping<DBObject,E> mapping, VtkView view, ParentNode<E> rootNode) {
                this.session = session;
                this.mapping = mapping;
                this.view = view;
@@ -321,10 +321,11 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
        
        protected void reset(ReadGraph graph) throws MappingException {
                if (DEBUG) System.out.println("Reset");
+               
                synchronized (syncMutex) {
                        graphUpdates = true;
                        mapping.getRangeModified().clear();
-                       for (Object o : mapping.getDomain())
+                       for (DBObject o : mapping.getDomain())
                                mapping.domainModified(o);
                        mapping.updateRange(graph);
                        graphModified.clear();
@@ -341,7 +342,7 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                } else {
                        synchronized (syncMutex) {
                                graphUpdates = true;
-                               for (Object domainObject : mapping.getDomainModified()) {
+                               for (DBObject domainObject : mapping.getDomainModified()) {
                                        E rangeObject = mapping.get(domainObject);
                                        if (rangeObject != null)
                                                graphModified.add(rangeObject);
@@ -664,7 +665,7 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                
        }
        
-       public IMapping<Object,E> getMapping() {
+       public IMapping<DBObject,E> getMapping() {
                return mapping;
        }
        
index 9998f5bf4520482ab38e10d641b6aaa52cac2f60..69ed83e2d2dea1857494b445e2635dc0e4ed127e 100644 (file)
@@ -35,19 +35,19 @@ import vtk.vtkMapper;
 import vtk.vtkProp;
 import vtk.vtkProperty;
 
-public class SelectionHighlighter<E extends INode> implements ISelectionChangedListener{
+public class SelectionHighlighter<DBObject, E extends INode> implements ISelectionChangedListener{
 
        
        
        protected VtkView panel;
-       protected VTKNodeMap<E> nodeMap;
+       protected VTKNodeMap<DBObject,E> nodeMap;
        
        protected List<IG3DNode> selectedNodes = new ArrayList<IG3DNode>();
        protected List<vtkActor> selectedActors = new ArrayList<vtkActor>();
        
        protected HighlightObjectType type = HighlightObjectType.Node;
        
-       public SelectionHighlighter(VtkView panel, VTKNodeMap<E> nodeMap) {
+       public SelectionHighlighter(VtkView panel, VTKNodeMap<DBObject,E> nodeMap) {
                this.panel = panel;
                this.nodeMap = nodeMap;
        }
index 09d380c7e4c5cc04e3aa8f7ea36b721135cbda9d..5de2b10dd056ba7310d806826c5e8fbafbcea6e3 100644 (file)
@@ -17,7 +17,7 @@ import org.simantics.g3d.scenegraph.base.INode;
 
 import vtk.vtkProp;
 
-public interface VTKNodeMap<E extends INode> extends NodeMap<vtkProp, E>{
+public interface VTKNodeMap<DBObject,E extends INode> extends NodeMap<DBObject,vtkProp, E>{
 
        
 
index e216e5e7ae558e672c47fade33c3dea82b920633..f0fe47ece8be37c8f0403842bb1423abfde4f2f9 100644 (file)
@@ -339,7 +339,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                private TableViewer viewer;
                
                private IG3DNode node;
-               private NodeMap<?,?> nodeMap;
+               private NodeMap<?,?,?> nodeMap;
                
                private List<TableViewerColumn> valueColumns = new ArrayList<TableViewerColumn>();
                
@@ -578,8 +578,8 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                        nodeMap = null;
                                        break;
                                }
-                               if (n instanceof NodeMapProvider<?,?>) {
-                                       nodeMap = ((NodeMapProvider<?,?>) n).getNodeMap();
+                               if (n instanceof NodeMapProvider<?,?,?>) {
+                                       nodeMap = ((NodeMapProvider<?,?,?>) n).getNodeMap();
                                        if (nodeMap != null)
                                                break;
                                }
@@ -733,11 +733,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
        private static class PropertyEditingSupport extends EditingSupport {
                AnnotatedPropertyTab tab;
                int index;
-               NodeMap<?,?> nodeMap;
+               NodeMap<?,?,?> nodeMap;
                TableViewer viewer;
                CellEditor editor;
 
-               public PropertyEditingSupport(AnnotatedPropertyTab tab, TableViewer viewer, int index, NodeMap<?,?> nodeMap) {
+               public PropertyEditingSupport(AnnotatedPropertyTab tab, TableViewer viewer, int index, NodeMap<?,?,?> nodeMap) {
                        super(viewer);
                        this.tab = tab;
                        this.index = index;
index 36ee73a3ff98603d76a92844071a0a5f751932ff..8ce1baf721022db6ee11c7e70b916cf34f38361f 100644 (file)
@@ -18,7 +18,7 @@ import org.simantics.g3d.scenegraph.base.NodeListener;
 import org.simantics.g3d.scenegraph.base.ParentNode;
 import org.simantics.objmap.graph.IMapping;
 
-public interface NodeMap<T,E extends INode> {
+public interface NodeMap<DBObject,T,E extends INode> {
 
        public Collection<T> getRenderObjects(E node);
        
@@ -58,5 +58,5 @@ public interface NodeMap<T,E extends INode> {
        
        public void removeListener(NodeListener listener);
        
-       public IMapping<Object, E> getMapping();
+       public IMapping<DBObject, E> getMapping();
 }
index e9b7d4b4147eb7bdfa8d2019e0d937ea99c9db5f..5de7cc379a1700c0e9804e53c84ddde5b468815b 100644 (file)
@@ -13,7 +13,7 @@ package org.simantics.g3d.scenegraph;
 
 import org.simantics.g3d.scenegraph.base.INode;
 
-public interface NodeMapProvider<T,E extends INode> {
+public interface NodeMapProvider<DBObject,T,E extends INode> {
 
-       public NodeMap<T,E> getNodeMap();
+       public NodeMap<DBObject,T,E> getNodeMap();
 }
index cd2447b3ae17e38855a8036e22077ba941a0b1d9..d532e1f0557adbf8b93099713bc56732a9e28a66 100644 (file)
@@ -42,12 +42,12 @@ import org.simantics.utils.datastructures.Pair;
  *
  * @param <E>
  */
-public abstract class ScriptNodeMap<E extends INode> implements NodeMap<Object,E>, IMappingListener, NodeListener {
+public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap<DBObject,Object,E>, IMappingListener, NodeListener {
 
        private static final boolean DEBUG = false;
        
        protected Session session;
-       protected IMapping<Object,E> mapping;
+       protected IMapping<DBObject,E> mapping;
        
        protected ParentNode<E> rootNode;
        
@@ -55,7 +55,7 @@ public abstract class ScriptNodeMap<E extends INode> implements NodeMap<Object,E
        
        private boolean dirty = false;
        
-       public ScriptNodeMap(Session session, IMapping<Object,E> mapping, ParentNode<E> rootNode) {
+       public ScriptNodeMap(Session session, IMapping<DBObject,E> mapping, ParentNode<E> rootNode) {
                this.session = session;
                this.mapping = mapping;
                this.rootNode = rootNode;
@@ -242,7 +242,7 @@ public abstract class ScriptNodeMap<E extends INode> implements NodeMap<Object,E
                synchronized (syncMutex) {
                        graphUpdates = true;
                        mapping.getRangeModified().clear();
-                       for (Object o : mapping.getDomain())
+                       for (DBObject o : mapping.getDomain())
                                mapping.domainModified(o);
                        mapping.updateRange(graph);
                        graphModified.clear();
@@ -254,7 +254,7 @@ public abstract class ScriptNodeMap<E extends INode> implements NodeMap<Object,E
                if (DEBUG) System.out.println("Graph update start");
                synchronized (syncMutex) {
                        graphUpdates = true;
-                       for (Object domainObject : mapping.getDomainModified()) {
+                       for (DBObject domainObject : mapping.getDomainModified()) {
                                E rangeObject = mapping.get(domainObject);
                                if (rangeObject != null)
                                        graphModified.add(rangeObject);
@@ -561,7 +561,7 @@ public abstract class ScriptNodeMap<E extends INode> implements NodeMap<Object,E
                
        }
        
-       public IMapping<Object,E> getMapping() {
+       public IMapping<DBObject,E> getMapping() {
                return mapping;
        }
        
index 41b1aa592bcf04baa42b987814ef432ed5a242ad..69603a5230019f76bb407d53cf7528c50ced2569 100644 (file)
@@ -42,6 +42,8 @@ public class Plant3D {
     public final Resource Builtin_VerticalTank;
     public final Resource Builtin_VerticalTankGeometryProvider;
     public final Resource CodeComponent;
+    public final Resource ComponentLibrary;
+    public final Resource ComponentLibrary_contains;
     public final Resource Connects;
     public final Resource DualConnectedComponent;
     public final Resource EndComponent;
@@ -155,6 +157,8 @@ public class Plant3D {
         public static final String Builtin_VerticalTank = "http://www.simantics.org/Plant3D-0.1/Builtin/VerticalTank";
         public static final String Builtin_VerticalTankGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/VerticalTankGeometryProvider";
         public static final String CodeComponent = "http://www.simantics.org/Plant3D-0.1/CodeComponent";
+        public static final String ComponentLibrary = "http://www.simantics.org/Plant3D-0.1/ComponentLibrary";
+        public static final String ComponentLibrary_contains = "http://www.simantics.org/Plant3D-0.1/ComponentLibrary/contains";
         public static final String Connects = "http://www.simantics.org/Plant3D-0.1/Connects";
         public static final String DualConnectedComponent = "http://www.simantics.org/Plant3D-0.1/DualConnectedComponent";
         public static final String EndComponent = "http://www.simantics.org/Plant3D-0.1/EndComponent";
@@ -278,6 +282,8 @@ public class Plant3D {
         Builtin_VerticalTank = getResourceOrNull(graph, URIs.Builtin_VerticalTank);
         Builtin_VerticalTankGeometryProvider = getResourceOrNull(graph, URIs.Builtin_VerticalTankGeometryProvider);
         CodeComponent = getResourceOrNull(graph, URIs.CodeComponent);
+        ComponentLibrary = getResourceOrNull(graph, URIs.ComponentLibrary);
+        ComponentLibrary_contains = getResourceOrNull(graph, URIs.ComponentLibrary_contains);
         Connects = getResourceOrNull(graph, URIs.Connects);
         DualConnectedComponent = getResourceOrNull(graph, URIs.DualConnectedComponent);
         EndComponent = getResourceOrNull(graph, URIs.EndComponent);
index ba6721043d20f7e38c8f63d227e310ddc7591621..d4cf03073d20214baafd5303d8ac06dfdb963a9f 100644 (file)
@@ -6,9 +6,8 @@ import java.awt.event.MouseWheelEvent;
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.vecmath.Vector3d;
-
 import org.eclipse.swt.widgets.Display;
+import org.simantics.db.Resource;
 import org.simantics.g3d.scenegraph.NodeMap;
 import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
@@ -19,16 +18,11 @@ import org.simantics.plant3d.gizmo.TerminalSelectionGizmo;
 import org.simantics.plant3d.scenegraph.InlineComponent;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
-import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
-import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
-import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction;
 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PositionType;
-import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 import org.simantics.plant3d.utils.ComponentUtils;
-import org.simantics.plant3d.utils.Item;
 import org.simantics.plant3d.utils.ComponentUtils.InsertInstruction;
-import org.simantics.plant3d.utils.Item.Type;
+import org.simantics.plant3d.utils.Item;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ExceptionUtils;
 
@@ -39,7 +33,7 @@ public class AddComponentAction extends vtkSwtAction {
 
        private P3DRootNode root;
        private PipelineComponent component;
-       private NodeMap<vtkProp,INode> nodeMap;
+       private NodeMap<Resource,vtkProp,INode> nodeMap;
        
        private TerminalSelectionGizmo gizmo;
        
index b40d7e0b7b469b1ecc507937850e5673ee69ea25..a4c04b3e321e0b11f0eddc51677f1e21baa3f673 100644 (file)
@@ -13,6 +13,7 @@ import javax.vecmath.Point3d;
 import javax.vecmath.Tuple3d;
 import javax.vecmath.Vector3d;
 
+import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.math.Ray;
 import org.simantics.g3d.scenegraph.NodeMap;
@@ -64,7 +65,7 @@ public class RoutePipeAction extends vtkSwtAction {
        private SplitPointSelectionGizmo splitPointSelectionGizmo;
        private ConstraintPointGizmo constraintPointGizmo;
        private TerminalSelectionGizmo terminalSelectionGizmo;
-       private NodeMap<vtkProp,INode> nodeMap;
+       private NodeMap<Resource,vtkProp,INode> nodeMap;
        
        private enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING};
        private ToolState state = ToolState.NOT_ACTIVE;
index 510956efaa45edc772a31280182c631446a57ab2..fce61be4abc5ef5e4146a341e4f7b3f9eea801ae 100644 (file)
@@ -30,7 +30,7 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 import vtk.vtkProp;
 import vtk.vtkProp3D;
 
-public class P3DNodeMap extends AbstractVTKNodeMap<INode> {
+public class P3DNodeMap extends AbstractVTKNodeMap<Resource,INode> {
        
        private static final boolean DEBUG = false;
 
index f80d3be8d63086c436116f8973e1cceea506697f..d3f3c5e47e11d199b838225ee16f7afa6a0fd4e0 100644 (file)
@@ -228,8 +228,8 @@ public class Plant3DEditor extends ResourceEditorPart {
            return new HoverHighlighter(panel,nodeMap);
        }
        
-       protected SelectionHighlighter<INode> createSelectionHighlighter() {
-           return new SelectionHighlighter<INode>(panel,nodeMap);
+       protected SelectionHighlighter<Resource,INode> createSelectionHighlighter() {
+           return new SelectionHighlighter<Resource,INode>(panel,nodeMap);
        }
        
        protected String getLibraryUri() {
index 4f00530e7203f2e0ca010bf8423d9e57366d3188..0fb7ed4f8d1fa9b990cb9ea54f14f5713d9038bc 100644 (file)
@@ -7,6 +7,7 @@ import java.util.Set;
 import javax.vecmath.Quat4d;
 import javax.vecmath.Vector3d;
 
+import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.scenegraph.IG3DNode;
 import org.simantics.g3d.scenegraph.NodeMap;
@@ -24,7 +25,7 @@ import org.simantics.plant3d.ontology.Plant3D;
 import vtk.vtkProp;
 
 @GraphType(Plant3D.URIs.Plant)
-public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapProvider<vtkProp , INode> {
+public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapProvider<Resource, vtkProp , INode> {
        
        
        @RelatedElementsAdd(Plant3D.URIs.children)
@@ -51,7 +52,7 @@ public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapP
        }
        
        @Override
-       public NodeMap<vtkProp, INode> getNodeMap() {
+       public NodeMap<Resource,vtkProp, INode> getNodeMap() {
                return nodeMap;
        }
        
index e5726d60eb605f47d58c28e51deead1888667735..4d1fb18c2720f37075c7b054ef7303d91ad05bce 100644 (file)
@@ -4,6 +4,7 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.g3d.ontology.G3D;
@@ -24,7 +25,7 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 
 import vtk.vtkProp3D;
 
-public class P3DScriptNodeMap extends ScriptNodeMap<INode>{
+public class P3DScriptNodeMap extends ScriptNodeMap<Resource,INode>{
        
        private static final boolean DEBUG = false;