};
}
- public static ICanvasSceneGraphProvider loadSceneGraphProvider(Resource model, Resource diagram, String diagramRVI) throws DatabaseException, InterruptedException {
+ public static ICanvasSceneGraphProvider loadSceneGraphProvider(Resource model, Resource diagram, String diagramRVI) throws DatabaseException {
Resource composite = Simantics.getSession().syncRequest( diagramToComposite(diagram) );
return loadSceneGraphProviderForComposite(model, composite, diagramRVI);
}
return cp.getCanvasContext();
}
- public static ICanvasSceneGraphProvider loadSceneGraphProviderForComposite(Resource model, Resource composite, String diagramRVI) throws DatabaseException, InterruptedException {
+ public static ICanvasSceneGraphProvider loadSceneGraphProviderForComposite(Resource model, Resource composite, String diagramRVI) throws DatabaseException {
String modelURI = Simantics.getSession().syncRequest(Queries.uri(model));
ISceneGraphProvider provider = Simantics.getSession().syncRequest( Queries.adapt( composite, ISceneGraphProvider.class ) );
ICanvasSceneGraphProvider cp = (ICanvasSceneGraphProvider) provider;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.xml.transform.OutputKeys;
import org.simantics.datatypes.literal.GUID;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
+import org.simantics.db.common.request.IndexRoot;
+import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.layer0.variable.Variables;
import org.simantics.diagram.elements.DecorationSVGNode;
import org.simantics.diagram.elements.DiagramNodeUtil;
import org.simantics.diagram.elements.TextGridNode;
import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
import org.simantics.scenegraph.utils.NodeUtil;
import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple2;
import org.simantics.trend.impl.ItemNode;
import org.simantics.utils.threads.ThreadUtils;
import org.slf4j.Logger;
private static final String[] ALL_SECTIONS = { MAIN_SECTION, SELECTION_SECTION, SELECTION_MASK_SECTION };
-
+ @Deprecated
public static ICanvasSceneGraphProvider getICanvasSceneGraphProvider(Resource model, Resource diagram, String diagramRVI) throws DatabaseException, InterruptedException {
ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider(model, diagram, diagramRVI);
return provider;
}
+ @Deprecated
public static void disposeSceneGraphProvider(ICanvasSceneGraphProvider provider) {
provider.dispose();
}
-
+
+ public static <T> T doWithICanvasSceneGraphProvider(Resource diagram, Function1<ICanvasSceneGraphProvider, T> func) throws DatabaseException {
+ return doWithICanvasSceneGraphProvider(diagram, (Function<ICanvasSceneGraphProvider, T>) provider -> func.apply(provider));
+ }
+
+ public static <T> T doWithICanvasSceneGraphProvider(Resource diagram, Function<ICanvasSceneGraphProvider, T> func) throws DatabaseException {
+ Tuple2 result = Simantics.getSession().syncRequest(new ResourceRead<Tuple2>(diagram) {
+
+ @Override
+ public Tuple2 perform(ReadGraph graph) throws DatabaseException {
+ Resource indexRoot = graph.syncRequest(new IndexRoot(resource));
+ String diagramRVI = Variables.getRVI(graph, resource);
+ return new Tuple2(indexRoot, diagramRVI);
+ }
+ });
+ ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider((Resource) result.c0, diagram, (String) result.c1);
+ try {
+ return func.apply(provider);
+ } finally {
+ provider.dispose();
+ }
+ }
+
+ public static <T> T doWithCanvasContext(Resource diagram, Function1<ICanvasContext, T> func) throws DatabaseException {
+ return doWithCanvasContext(diagram, (Function<ICanvasContext, T>) canvasContext -> func.apply(canvasContext));
+ }
+
+ public static <T> T doWithCanvasContext(Resource diagram, Function<ICanvasContext, T> func) throws DatabaseException {
+ return doWithICanvasSceneGraphProvider(diagram, (Function<ICanvasSceneGraphProvider, T>) provider -> func.apply(provider.getCanvasContext()));
+ }
+
public static String getNodeTransform(ICanvasContext ctx, String name) {
Set<TextNode> texts = NodeUtil.collectNodes(ctx.getSceneGraph(), TextNode.class);