From: Reino Ruusu Date: Wed, 6 Nov 2019 12:18:57 +0000 (+0200) Subject: Use IMapping in node maps. X-Git-Tag: v1.43.0~140 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F59%2F3459%2F1;p=simantics%2F3d.git Use IMapping in node maps. Change-Id: Ibb4441e5e4e358af9564610c58e00458ff0338de --- diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java index bb5493f6..0866dde5 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java @@ -53,7 +53,7 @@ public abstract class AbstractVTKNodeMap implements VT private static final boolean DEBUG = false; protected Session session; - protected IMapping mapping; + protected IMapping mapping; protected VtkView view; private MapList nodeToActor = new MapList(); @@ -66,7 +66,7 @@ public abstract class AbstractVTKNodeMap implements VT protected int redoOpCount = 0; protected boolean runUndo = false; protected boolean runRedo = false; - public AbstractVTKNodeMap(Session session, IMapping mapping, VtkView view, ParentNode rootNode) { + public AbstractVTKNodeMap(Session session, IMapping mapping, VtkView view, ParentNode rootNode) { this.session = session; this.mapping = mapping; this.view = view; @@ -359,7 +359,8 @@ public abstract class AbstractVTKNodeMap 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 implements VT } - public IMapping getMapping() { + public IMapping getMapping() { return mapping; } diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMap.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMap.java index 8ce1baf7..4e068147 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMap.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/NodeMap.java @@ -20,7 +20,7 @@ import org.simantics.objmap.graph.IMapping; public interface NodeMap { - public Collection getRenderObjects(E node); + public Collection getRenderObjects(INode node); public void updateRenderObjectsFor(E node); @@ -58,5 +58,5 @@ public interface NodeMap { public void removeListener(NodeListener listener); - public IMapping getMapping(); + public IMapping getMapping(); } diff --git a/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java b/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java index d532e1f0..f9a245dc 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java @@ -47,7 +47,7 @@ public abstract class ScriptNodeMap implements NodeMap private static final boolean DEBUG = false; protected Session session; - protected IMapping mapping; + protected IMapping mapping; protected ParentNode rootNode; @@ -55,7 +55,7 @@ public abstract class ScriptNodeMap implements NodeMap private boolean dirty = false; - public ScriptNodeMap(Session session, IMapping mapping, ParentNode rootNode) { + public ScriptNodeMap(Session session, IMapping mapping, ParentNode rootNode) { this.session = session; this.mapping = mapping; this.rootNode = rootNode; @@ -91,14 +91,11 @@ public abstract class ScriptNodeMap implements NodeMap return Collections.EMPTY_LIST; } - @SuppressWarnings("unchecked") @Override public ParentNode getRootNode() { return (ParentNode)rootNode; } - - @Override public boolean isChangeTracking() { return changeTracking; @@ -120,11 +117,9 @@ public abstract class ScriptNodeMap 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 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 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 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 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 n : removed) { @@ -340,6 +335,7 @@ public abstract class ScriptNodeMap 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 implements NodeMap } - public IMapping getMapping() { + @Override + public IMapping getMapping() { return mapping; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java index 24a141e4..a4e8bafd 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java @@ -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{ +public class P3DContentOutlinePage extends VTKContentOutlinePage{ private static final boolean DEBUG = true; protected Menu contextMenu; @@ -41,7 +41,7 @@ public class P3DContentOutlinePage extends VTKContentOutlinePage rootNode, NodeSelectionProvider2 provider) { + public P3DContentOutlinePage(ParentNode rootNode, NodeSelectionProvider2 provider) { super(rootNode,provider); nozzleImage = manager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Nozzle.png")); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java index 8daee3a5..a145b71a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java @@ -34,7 +34,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap { private static final boolean DEBUG = false; - public P3DNodeMap(Session session, IMapping mapping, VtkView panel, P3DRootNode rootNode) { + public P3DNodeMap(Session session, IMapping mapping, VtkView panel, P3DRootNode rootNode) { super(session, mapping, panel, rootNode); rootNode.setNodeMap(this); } 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 e7db15d1..53a0ed2c 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -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 mapping; + private IMapping mapping; - protected NodeSelectionProvider2 selectionProvider; + protected NodeSelectionProvider2 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 schema = getSchema(graph); + IMappingSchema 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 createSelectionProvider() { - return new NodeSelectionProvider2(this,mapping,nodeMap); + protected NodeSelectionProvider2 createSelectionProvider() { + return new NodeSelectionProvider2(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 getSchema(ReadGraph graph) throws DatabaseException { - IMappingSchema schema = SchemaBuilder.getSchema(graph); + protected IMappingSchema getSchema(ReadGraph graph) throws DatabaseException { + IMappingSchema schema = SchemaBuilder.getSchema(graph); return schema; } - protected P3DNodeMap createNodeMap(Session session, IMapping mapping, VtkView panel, P3DRootNode rootNode) { + protected P3DNodeMap createNodeMap(Session session, IMapping 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 getMapping() { + public IMapping getMapping() { return mapping; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java index 5b761a11..a57a07e7 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java @@ -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 getSchema() throws DatabaseException{ - return Simantics.getSession().syncRequest(new Read>() { + public static IMappingSchema getSchema() throws DatabaseException{ + return Simantics.getSession().syncRequest(new Read>() { @Override - public IMappingSchema perform(ReadGraph g) + public IMappingSchema perform(ReadGraph g) throws DatabaseException { return getSchema(g); } }); } - public static IMappingSchema getSchema(ReadGraph g) throws DatabaseException{ + @SuppressWarnings("unchecked") + public static IMappingSchema 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)(IMappingSchema)schema; } catch (IllegalAccessException e) { throw new DatabaseException(e); } catch (InstantiationException e) { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java b/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java index 4c4b6d57..e892106d 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java @@ -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 get(ReadGraph graph) throws DatabaseException; + IMappingSchema get(ReadGraph graph) throws DatabaseException; } public static interface NodeMapProvider { - P3DScriptNodeMap get(IMapping mapping, P3DRootNode rootNode); + P3DScriptNodeMap get(IMapping 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 schema = schemaProvider.get(graph); - IMapping mapping = Mappings.createWithListening(schema); + IMappingSchema schema = schemaProvider.get(graph); + IMapping 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 schema = schemaProvider.get(graph); - IMapping mapping = Mappings.createWithoutListening(schema); + IMappingSchema schema = schemaProvider.get(graph); + IMapping 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);