1 package org.simantics.sysdyn.modelImport.model.expression;
\r
3 import org.simantics.databoard.Bindings;
\r
4 import org.simantics.db.ReadGraph;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.WriteGraph;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.sysdyn.SysdynResource;
\r
9 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
11 public class LookupExpression extends Expression {
\r
13 private String expression;
\r
14 private double xMin;
\r
15 private double yMin;
\r
16 private double xMax;
\r
17 private double yMax;
\r
18 private double[] points;
\r
20 public LookupExpression(String expression, double xMin, double yMin, double xMax, double yMax, double[] points) {
\r
21 this.expression = expression;
\r
26 this.points = points;
\r
30 public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {
\r
31 SysdynResource sr = SysdynResource.getInstance(graph);
\r
33 StringBuilder lookup = new StringBuilder();
\r
35 for (int i = 0; i < points.length / 2; i++) {
\r
38 lookup.append('{').append(points[2*i]).append(',').append(points[2*i+1]).append('}');
\r
42 Resource expr = super.write(graph, parent, context);
\r
45 graph.claimLiteral(expr, sr.WithLookupExpression_expression, expression, Bindings.STRING);
\r
46 graph.claimLiteral(expr, sr.WithLookupExpression_lookup, lookup.toString(), Bindings.STRING);
\r
47 graph.claimLiteral(expr, sr.WithLookupExpression_minX, xMin, Bindings.DOUBLE);
\r
48 graph.claimLiteral(expr, sr.WithLookupExpression_minY, yMin, Bindings.DOUBLE);
\r
49 graph.claimLiteral(expr, sr.WithLookupExpression_maxX, xMax, Bindings.DOUBLE);
\r
50 graph.claimLiteral(expr, sr.WithLookupExpression_maxY, yMax, Bindings.DOUBLE);
\r
56 public Resource getExpressionType(ReadGraph graph) {
\r
57 return SysdynResource.getInstance(graph).WithLookupExpression;
\r