1 package org.simantics.scenegraph.loader.function;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.variable.Variable;
8 import org.simantics.db.layer0.variable.Variables;
9 import org.simantics.layer0.Layer0;
10 import org.simantics.scenegraph.loader.SceneGraphContext;
11 import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;
12 import org.simantics.scenegraph.ontology.ScenegraphResources;
13 import org.simantics.scl.reflection.annotations.SCLValue;
17 @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")
18 public static Variable defaultRuntimeVariable(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
20 SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context);
21 if(vc == null) return null;
23 ScenegraphResources SG = ScenegraphResources.getInstance(graph);
24 String uri = graph.getRelatedValue(vc.getRuntime(), SG.Runtime_HasVariable, Bindings.STRING);
25 return Variables.getVariable(graph, uri);
29 @SCLValue(type = "ReadGraph -> Resource -> Variable -> Resource")
30 public static Resource defaultRuntimeResource(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
32 SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context);
33 if(vc == null) return null;
35 ScenegraphResources SG = ScenegraphResources.getInstance(graph);
36 return graph.getSingleObject(vc.getRuntime(), SG.Runtime_HasResource);
41 private static Object walk(ReadGraph graph, Variable context, String name) throws DatabaseException {
43 Variable var = context.getPossibleProperty(graph, name);
44 if(var != null) return var.getValue(graph);
46 Variable parent = context.getParent(graph);
47 if(parent == null) return null;
49 return walk(graph, parent, name);
53 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
54 public static Object liftedProperty(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
56 ScenegraphResources SG = ScenegraphResources.getInstance(graph);
57 final Resource predicate = graph.getSingleObject(converter, SG.LiftedProperty_HasPredicate);
60 Layer0 L0 = Layer0.getInstance(graph);
61 Variable parent = context.getParent(graph);
62 String name = graph.getRelatedValue(predicate, L0.HasName, Bindings.STRING);
63 return walk(graph, parent, name);
64 } catch (DatabaseException e) {
71 @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")
72 public static Variable singleVariableSelection(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
73 return ScenegraphLoaderUtils.getVariableSelection(graph, context);