From 2bf1a3a2c26cf2a1ff4cd5b56971ef6a0ff10015 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Mon, 28 Jan 2019 10:39:27 +0200 Subject: [PATCH] Support selection of experiment run for scene graph provider Change-Id: I1507d0088942c9d2d05d0ba66d7854458302a89a --- .../diagram/elements/DiagramNodeUtil.java | 13 +++++++++- .../runtime/RuntimeDiagramManager.java | 2 +- .../ICanvasSceneGraphProvider2.java | 25 ++++++++++++++++++ .../ui/sg/DiagramSceneGraphProvider.java | 26 +++++++++++++++---- 4 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 bundles/org.simantics.g2d/src/org/simantics/g2d/scenegraph/ICanvasSceneGraphProvider2.java diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java index 467e4e349..671c317ec 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java @@ -13,6 +13,7 @@ import org.simantics.db.common.request.Queries; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; import org.simantics.db.request.Read; import org.simantics.db.service.TransactionSupport; import org.simantics.db.service.VirtualGraphSupport; @@ -26,6 +27,7 @@ import org.simantics.g2d.diagram.handler.DataElementMap; import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.IElement; import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider; +import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider2; import org.simantics.modeling.ModelingResources; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.adapters.ISceneGraphProvider; @@ -180,10 +182,19 @@ public class DiagramNodeUtil { } public static ICanvasSceneGraphProvider loadSceneGraphProviderForDiagram(ICanvasContext context, Resource model, Resource diagram, String diagramRVI) throws DatabaseException, InterruptedException { + return loadSceneGraphProviderForDiagram(context, model, diagram, diagramRVI, null); + } + + public static ICanvasSceneGraphProvider loadSceneGraphProviderForDiagram(ICanvasContext context, Resource model, Resource diagram, String diagramRVI, Variable run) throws DatabaseException, InterruptedException { String modelURI = Simantics.getSession().syncRequest(Queries.uri(model)); ISceneGraphProvider provider = Simantics.getSession().syncRequest( Queries.adapt( diagram, ISceneGraphProvider.class ) ); ICanvasSceneGraphProvider cp = (ICanvasSceneGraphProvider) provider; - cp.initializeSceneGraph(context, modelURI, diagramRVI); + if(cp instanceof ICanvasSceneGraphProvider2) { + ((ICanvasSceneGraphProvider2)cp).initializeSceneGraph(context, modelURI, diagramRVI, run); + + } else { + cp.initializeSceneGraph(context, modelURI, diagramRVI); + } NodeUtil.waitPending(cp.getCanvasContext().getThreadAccess(), context.getSceneGraph()); Simantics.getSession().getService(TransactionSupport.class).waitCompletion(); return cp; diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java index 04e30f70d..b0ba03c58 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java @@ -314,7 +314,7 @@ public class RuntimeDiagramManager { }); } - private Resource createRuntimeDiagram(WriteGraph graph, Resource diagram, RuntimeDiagramDesc desc) throws DatabaseException { + protected Resource createRuntimeDiagram(WriteGraph graph, Resource diagram, RuntimeDiagramDesc desc) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); final DiagramResource DIA = DiagramResource.getInstance(graph); diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/scenegraph/ICanvasSceneGraphProvider2.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/scenegraph/ICanvasSceneGraphProvider2.java new file mode 100644 index 000000000..c0af2f890 --- /dev/null +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/scenegraph/ICanvasSceneGraphProvider2.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.scenegraph; + +import org.simantics.db.layer0.variable.Variable; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.scenegraph.g2d.G2DSceneGraph; + +/** + * @author Antti Villberg + */ +public interface ICanvasSceneGraphProvider2 extends ICanvasSceneGraphProvider { + + public G2DSceneGraph initializeSceneGraph(ICanvasContext context, String modelURI, String RVI, Variable experiment); + +} diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java index 5c8f36791..8d3088667 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java @@ -19,12 +19,14 @@ import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.Session; import org.simantics.db.common.ResourceArray; import org.simantics.db.common.primitiverequest.PossibleAdapter; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.exception.ServiceException; +import org.simantics.db.layer0.variable.Variable; import org.simantics.db.management.ISessionContext; import org.simantics.db.request.Read; import org.simantics.diagram.adapter.DefaultConnectionClassFactory; @@ -76,6 +78,7 @@ import org.simantics.g2d.participant.TimeParticipant; import org.simantics.g2d.participant.TransformUtil; import org.simantics.g2d.participant.ZoomToAreaHandler; import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider; +import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider2; import org.simantics.modeling.ModelingResources; import org.simantics.modeling.mapping.ComponentCopyAdvisor; import org.simantics.modeling.mapping.ElementCopyAdvisor; @@ -107,7 +110,7 @@ import org.simantics.utils.ui.ErrorLogger; * @author J-P Laine * */ -public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDiagramUpdateSupport { +public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider2, IDiagramUpdateSupport { protected boolean isSymbol = false; protected Resource resource; @@ -318,8 +321,17 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi @Override public G2DSceneGraph initializeSceneGraph(ICanvasContext context, String modelURI, String RVI) { G2DSceneGraph sg = context.getSceneGraph(); - return initializeSceneGraph(context, sg, modelURI, RVI, ""); + return initializeSceneGraph(context, sg, modelURI, RVI, "", null); } + + + @Override + public G2DSceneGraph initializeSceneGraph(ICanvasContext context, String modelURI, String RVI, + Variable experiment) { + G2DSceneGraph sg = context.getSceneGraph(); + return initializeSceneGraph(context, sg, modelURI, RVI, "", experiment); + } + /** * @param sg @@ -330,7 +342,7 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi private G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg, String modelURI, String RVI, String view) { IThreadWorkQueue thread = AWTThread.getThreadAccess(); ctx = new CanvasContext(thread, sg); // By giving the scene graph instance as parameter, we can use external serializer - return initializeSceneGraph(ctx, sg, modelURI, RVI, view); + return initializeSceneGraph(ctx, sg, modelURI, RVI, view, null); } protected GraphToDiagramSynchronizer createSynchronizer(ReadGraph graph) throws DatabaseException { @@ -342,6 +354,10 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi ) ); } + + protected RuntimeDiagramManager createRuntimeDiagramManager(Session session, Resource resource, String modelURI, String RVI, Variable experiment) throws DatabaseException { + return RuntimeDiagramManager.create(session, resource, modelURI, RVI); + } /** * @param sg @@ -349,7 +365,7 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi * @param initialHints * @return */ - private G2DSceneGraph initializeSceneGraph(ICanvasContext context, G2DSceneGraph sg, String modelURI, String RVI, String view) { + private G2DSceneGraph initializeSceneGraph(ICanvasContext context, G2DSceneGraph sg, String modelURI, String RVI, String view, Variable run) { this.ctx = (CanvasContext) context; this.view = view; if(view != null) { @@ -366,7 +382,7 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi initialHints.setHint(SynchronizationHints.COPY_ADVISOR, getCopyAdvisor()); - final RuntimeDiagramManager runtimeDiagramManager = RuntimeDiagramManager.create(Simantics.getSession(), resource, modelURI, RVI); + final RuntimeDiagramManager runtimeDiagramManager = createRuntimeDiagramManager(Simantics.getSession(), resource, modelURI, RVI, run); synchronizer = Simantics.getSession().syncRequest(new Read() { @Override -- 2.47.1