]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Use IMapping<Resource,INode> in node maps. 59/3459/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 6 Nov 2019 12:18:57 +0000 (14:18 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 6 Nov 2019 12:59:20 +0000 (14:59 +0200)
Change-Id: Ibb4441e5e4e358af9564610c58e00458ff0338de

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java
org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMap.java
org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.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/SchemaBuilder.java
org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java

index bb5493f6b7a76ee806d712d402691f5b862cdc8d..0866dde55e730b6acaa82fd71d9de56abe983e4a 100644 (file)
@@ -53,7 +53,7 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
        private static final boolean DEBUG = false;
        
        protected Session session;
-       protected IMapping<DBObject,E> mapping;
+       protected IMapping<DBObject, INode> mapping;
        protected VtkView view;
        
        private MapList<E, vtkProp> nodeToActor = new MapList<E, vtkProp>();
@@ -66,7 +66,7 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
        protected int redoOpCount = 0;
        protected boolean runUndo = false;
        protected boolean runRedo = false;
-       public AbstractVTKNodeMap(Session session, IMapping<DBObject,E> mapping, VtkView view, ParentNode<E> rootNode) {
+       public AbstractVTKNodeMap(Session session, IMapping<DBObject,INode> mapping, VtkView view, ParentNode<E> rootNode) {
                this.session = session;
                this.mapping = mapping;
                this.view = view;
@@ -359,7 +359,8 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                        synchronized (syncMutex) {
                                graphUpdates = true;
                                for (DBObject domainObject : mapping.getDomainModified()) {
-                                       E rangeObject = mapping.get(domainObject);
+                                       @SuppressWarnings("unchecked")
+                                       E rangeObject = (E) mapping.get(domainObject);
                                        if (rangeObject != null)
                                                graphModified.add(rangeObject);
                                }
@@ -682,7 +683,7 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                
        }
        
-       public IMapping<DBObject,E> getMapping() {
+       public IMapping<DBObject,INode> getMapping() {
                return mapping;
        }
        
index 8ce1baf721022db6ee11c7e70b916cf34f38361f..4e0681472e7056b8cc8e6e9058aa53850a3fe3ab 100644 (file)
@@ -20,7 +20,7 @@ import org.simantics.objmap.graph.IMapping;
 
 public interface NodeMap<DBObject,T,E extends INode> {
 
-       public Collection<T> getRenderObjects(E node);
+       public Collection<T> getRenderObjects(INode node);
        
        public void updateRenderObjectsFor(E node);
        
@@ -58,5 +58,5 @@ public interface NodeMap<DBObject,T,E extends INode> {
        
        public void removeListener(NodeListener listener);
        
-       public IMapping<DBObject, E> getMapping();
+       public IMapping<DBObject, INode> getMapping();
 }
index d532e1f0557adbf8b93099713bc56732a9e28a66..f9a245dcd541f0dd2b92b155a280a5c72ccb933f 100644 (file)
@@ -47,7 +47,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        private static final boolean DEBUG = false;
        
        protected Session session;
-       protected IMapping<DBObject,E> mapping;
+       protected IMapping<DBObject,INode> mapping;
        
        protected ParentNode<E> rootNode;
        
@@ -55,7 +55,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        
        private boolean dirty = false;
        
-       public ScriptNodeMap(Session session, IMapping<DBObject,E> mapping, ParentNode<E> rootNode) {
+       public ScriptNodeMap(Session session, IMapping<DBObject,INode> mapping, ParentNode<E> rootNode) {
                this.session = session;
                this.mapping = mapping;
                this.rootNode = rootNode;
@@ -91,14 +91,11 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                return Collections.EMPTY_LIST;
        }
        
-       @SuppressWarnings("unchecked")
        @Override
        public ParentNode<E> getRootNode() {
                return (ParentNode<E>)rootNode;
        }
        
-       
-       
        @Override
        public boolean isChangeTracking() {
                return changeTracking;
@@ -120,11 +117,9 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
 
        private boolean rangeModified = false;
        
-       @SuppressWarnings("unchecked")
        @Override
        public void updateRenderObjectsFor(E node) {
-               nodes.add((E)node);
-
+               nodes.add(node);
        }
        
        @SuppressWarnings("unchecked")
@@ -160,7 +155,6 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                repaint();
        }
        
-       @SuppressWarnings("unchecked")
        private void receiveUpdate(E node, String id, boolean db) {
                if (DEBUG) System.out.println("receiveUpdate " + debugString(node)  + " " + id + " " + db);
                synchronized (syncMutex) {
@@ -255,7 +249,8 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                synchronized (syncMutex) {
                        graphUpdates = true;
                        for (DBObject domainObject : mapping.getDomainModified()) {
-                               E rangeObject = mapping.get(domainObject);
+                               @SuppressWarnings("unchecked")
+                               E rangeObject = (E) mapping.get(domainObject);
                                if (rangeObject != null)
                                        graphModified.add(rangeObject);
                        }
@@ -290,7 +285,6 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                                doCommit();
                        }
                        session.syncRequest(new ReadRequest() { 
-                               @SuppressWarnings("unchecked")
                                @Override
                                public void run(ReadGraph graph) throws DatabaseException {
                                        update(graph);
@@ -319,6 +313,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
         * This code here synchronizes removed and added objects to collect deletable objects. (a deletable object is one which is removed but not added).  
         * 
         */
+       @SuppressWarnings("unused")
        protected void syncDeletes() {
                deleteUC.clear();
                for (Pair<E, String> n : removed) {
@@ -340,6 +335,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        /**
         * Clears deletable objects from mapping cache.
         */
+       @SuppressWarnings("unused")
        protected void clearDeletes() {
                if (DEBUG && delete.size() > 0) System.out.println("Delete");
                for (E n : delete) {
@@ -561,7 +557,8 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                
        }
        
-       public IMapping<DBObject,E> getMapping() {
+       @Override
+       public IMapping<DBObject,INode> getMapping() {
                return mapping;
        }
        
index 24a141e464141f27ba4ff41ed068dee654cea1a3..a4e8bafd14b3d777ebaaa0e69b790d1408c85d0f 100644 (file)
@@ -28,7 +28,7 @@ import org.simantics.plant3d.scenegraph.PipelineComponent;
 import org.simantics.plant3d.scenegraph.TurnComponent;
 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
 
-public class P3DContentOutlinePage extends VTKContentOutlinePage<Resource, Object>{
+public class P3DContentOutlinePage extends VTKContentOutlinePage<Resource, INode>{
        
        private static final boolean DEBUG = true;
        protected Menu contextMenu;
@@ -41,7 +41,7 @@ public class P3DContentOutlinePage extends VTKContentOutlinePage<Resource, Objec
        private Image elbowImage;
        private Image componentImage;
        
-       public  P3DContentOutlinePage(ParentNode<? extends INode> rootNode, NodeSelectionProvider2<Resource,Object> provider) {
+       public  P3DContentOutlinePage(ParentNode<? extends INode> rootNode, NodeSelectionProvider2<Resource,INode> provider) {
                super(rootNode,provider);
                
                nozzleImage = manager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Nozzle.png"));
index 8daee3a530e9286a725bf5b0a113f711fd507f86..a145b71ab2d542c6dae6b792122bb25ccd6f1555 100644 (file)
@@ -34,7 +34,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap<Resource,INode> {
        
        private static final boolean DEBUG = false;
 
-       public P3DNodeMap(Session session, IMapping mapping, VtkView panel, P3DRootNode rootNode) {
+       public P3DNodeMap(Session session, IMapping<Resource,INode> mapping, VtkView panel, P3DRootNode rootNode) {
                super(session, mapping, panel, rootNode);
                rootNode.setNodeMap(this);
        }
index e7db15d11e3b8adb47f68429c17202c2348f89cb..53a0ed2c78ed1298bca72e551986d2fe2f3cd8fc 100644 (file)
@@ -22,7 +22,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.g3d.scenegraph.IG3DNode;
 import org.simantics.g3d.scenegraph.NodeMap;
 import org.simantics.g3d.scenegraph.RenderListener;
 import org.simantics.g3d.scenegraph.base.INode;
@@ -95,9 +94,9 @@ public class Plant3DEditor extends ResourceEditorPart {
        private InteractiveVtkComposite panel;
        
        private P3DRootNode rootNode;
-       private IMapping<Resource,Object> mapping;
+       private IMapping<Resource,INode> mapping;
        
-       protected NodeSelectionProvider2<Resource,Object> selectionProvider;
+       protected NodeSelectionProvider2<Resource, INode> selectionProvider;
        
        
        protected vtkCameraAndSelectorAction cameraAction;
@@ -160,12 +159,11 @@ public class Plant3DEditor extends ResourceEditorPart {
                try {
                        getSession().syncRequest(new ReadRequest() {
                                
-                               @SuppressWarnings({ "rawtypes", "unchecked" })
                                @Override
                                public void run(ReadGraph graph) throws DatabaseException {
                                    System.out.println("START PLANT3D LOAD");
                                        PipingRules.setEnabled(false);
-                                       IMappingSchema<Resource, Object> schema = getSchema(graph);
+                                       IMappingSchema<Resource,INode> schema = getSchema(graph);
                                        mapping = Mappings.createWithListening(schema);
                                        rootNode = (P3DRootNode)mapping.map(graph, input);
                                        // update control points.
@@ -228,8 +226,8 @@ public class Plant3DEditor extends ResourceEditorPart {
            return new vtkCameraAndSelectorAction(panel); 
        }
        
-       protected NodeSelectionProvider2<Resource,Object> createSelectionProvider() {
-           return new NodeSelectionProvider2<Resource,Object>(this,mapping,nodeMap);
+       protected NodeSelectionProvider2<Resource,INode> createSelectionProvider() {
+           return new NodeSelectionProvider2<Resource,INode>(this,mapping,nodeMap);
        }
        
        protected HoverHighlighter createHoverHighlhighter() {
@@ -250,12 +248,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                translateInlineAction = new TranslateInlineAction(panel, nodeMap);
                translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode());
                rotateAction = new RotateAction(panel,nodeMap);
-               removeAction = new RemoveAction(nodeMap) {
-                       public void setNode(IG3DNode node) {
-                               super.setNode(node);
-                       }
-               };
-               
+               removeAction = new RemoveAction(nodeMap);
                removeSplitAction = new RemoveAndSplitAction(nodeMap);
                routePipeAction = new RoutePipeAction(panel,rootNode);
                addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri());
@@ -293,12 +286,12 @@ public class Plant3DEditor extends ResourceEditorPart {
                
        }
        
-       protected IMappingSchema<Resource, Object> getSchema(ReadGraph graph) throws DatabaseException {
-               IMappingSchema<Resource,Object> schema = SchemaBuilder.getSchema(graph);
+       protected IMappingSchema<Resource, INode> getSchema(ReadGraph graph) throws DatabaseException {
+               IMappingSchema<Resource,INode> schema = SchemaBuilder.getSchema(graph);
                return schema;
        }
        
-       protected P3DNodeMap createNodeMap(Session session, IMapping<Resource, Object> mapping, VtkView panel, P3DRootNode rootNode) {
+       protected P3DNodeMap createNodeMap(Session session, IMapping<Resource, INode> mapping, VtkView panel, P3DRootNode rootNode) {
                return new P3DNodeMap(session, mapping, panel,rootNode);
        }
        
@@ -539,7 +532,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                return rootNode;
        }
        
-       public IMapping<Resource, Object> getMapping() {
+       public IMapping<Resource, INode> getMapping() {
                return mapping;
        }
        
index 5b761a11a0ee0d3f7001ecd3dfe781bc0b1ff7cd..a57a07e76547b56e19ee9a040f7be86ee4fa46d1 100644 (file)
@@ -6,23 +6,25 @@ import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
 import org.simantics.g3d.scenegraph.GeometryProvider;
+import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.objmap.graph.schema.IMappingSchema;
 import org.simantics.objmap.graph.schema.MappingSchemas;
 import org.simantics.objmap.graph.schema.SimpleSchema;
 import org.simantics.plant3d.ontology.Plant3D;
 
 public class SchemaBuilder {
-       public static IMappingSchema<Resource,Object> getSchema() throws DatabaseException{
-               return Simantics.getSession().syncRequest(new Read<IMappingSchema<Resource,Object>>() {
+       public static IMappingSchema<Resource,INode> getSchema() throws DatabaseException{
+               return Simantics.getSession().syncRequest(new Read<IMappingSchema<Resource,INode>>() {
                        @Override
-                       public IMappingSchema<Resource,Object> perform(ReadGraph g)
+                       public IMappingSchema<Resource,INode> perform(ReadGraph g)
                                        throws DatabaseException {
                                return getSchema(g);
                        }
                });
        }
        
-       public static IMappingSchema<Resource,Object> getSchema(ReadGraph g) throws DatabaseException{
+       @SuppressWarnings("unchecked")
+       public static IMappingSchema<Resource,INode> getSchema(ReadGraph g) throws DatabaseException{
                try {
                        SimpleSchema schema = new SimpleSchema();
                        schema.addLinkType(MappingSchemas.fromAnnotations(g, Equipment.class));
@@ -34,7 +36,7 @@ public class SchemaBuilder {
                        schema.addLinkType(MappingSchemas.fromAnnotations(g, PipeRun.class));
                        
                        schema.addLinkType(MappingSchemas.fromAdaptable(g, Plant3D.URIs.GeometryProvider, GeometryProvider.class));
-                       return schema;
+                       return (IMappingSchema<Resource, INode>)(IMappingSchema<Resource, ?>)schema;
                } catch (IllegalAccessException e) {
                        throw new DatabaseException(e);
                } catch (InstantiationException e) {
index 4c4b6d5760a6f40b68533dba92a67b741585fc27..e892106d08bd891ba88fdd1e5146dc7f3abf880e 100644 (file)
@@ -5,6 +5,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
+import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.objmap.graph.IMapping;
 import org.simantics.objmap.graph.Mappings;
 import org.simantics.objmap.graph.schema.IMappingSchema;
@@ -19,11 +20,11 @@ import org.simantics.plant3d.utils.P3DUtil;
 public class SCLUtil {
 
        public static interface SchemaProvider {
-               IMappingSchema<Resource,Object> get(ReadGraph graph) throws DatabaseException;
+               IMappingSchema<Resource,INode> get(ReadGraph graph) throws DatabaseException;
        }
 
        public static interface NodeMapProvider {
-               P3DScriptNodeMap get(IMapping<Resource, Object> mapping, P3DRootNode rootNode);
+               P3DScriptNodeMap get(IMapping<Resource, INode> mapping, P3DRootNode rootNode);
        }
        
        public static P3DScriptNodeMap load(final Resource root) throws DatabaseException {
@@ -55,10 +56,10 @@ public class SCLUtil {
                        @Override
                        public NodeMap perform(ReadGraph graph) throws DatabaseException {
                                PipingRules.setEnabled(false);
-                               IMappingSchema<Resource, Object> schema = schemaProvider.get(graph);
-                               IMapping<Resource, Object> mapping = Mappings.createWithListening(schema);
+                               IMappingSchema<Resource, INode> schema = schemaProvider.get(graph);
+                               IMapping<Resource, INode> mapping = Mappings.createWithListening(schema);
                                P3DRootNode rootNode = (P3DRootNode) mapping.map(graph, root);
-                               rootNode.setMapping((IMapping)mapping);
+                               rootNode.setMapping(mapping);
                                try {
                                        P3DUtil.finalizeDBLoad(rootNode);
                                        // FIXME: Something needs to be done here...
@@ -80,11 +81,11 @@ public class SCLUtil {
                        @Override
                        public Root perform(ReadGraph graph) throws DatabaseException {
                                PipingRules.setEnabled(false);
-                               IMappingSchema<Resource, Object> schema = schemaProvider.get(graph);
-                               IMapping<Resource, Object> mapping = Mappings.createWithoutListening(schema);
+                               IMappingSchema<Resource, INode> schema = schemaProvider.get(graph);
+                               IMapping<Resource, INode> mapping = Mappings.createWithoutListening(schema);
                                @SuppressWarnings("unchecked")
                                Root rootNode = (Root) mapping.map(graph, root);
-                               rootNode.setMapping((IMapping)mapping);
+                               rootNode.setMapping(mapping);
                                try {
                                        P3DUtil.finalizeDBLoad(rootNode);
                                        P3DUtil.finalizeDBLoad2(rootNode);