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 double xMin;
\r
14 private double yMin;
\r
15 private double xMax;
\r
16 private double yMax;
\r
17 private double[] points;
\r
19 public LookupExpression(double xMin, double yMin, double xMax, double yMax, double[] points) {
\r
24 this.points = points;
\r
28 public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {
\r
29 SysdynResource sr = SysdynResource.getInstance(graph);
\r
31 StringBuilder lookup = new StringBuilder();
\r
33 for (int i = 0; i < points.length / 2; i++) {
\r
36 lookup.append('{').append(points[2*i]).append(',').append(points[2*i+1]).append('}');
\r
40 Resource expr = super.write(graph, parent, context);
\r
43 graph.claimLiteral(expr, sr.WithLookupExpression_expression, "", Bindings.STRING);
\r
44 graph.claimLiteral(expr, sr.WithLookupExpression_lookup, lookup.toString(), Bindings.STRING);
\r
45 graph.claimLiteral(expr, sr.WithLookupExpression_minX, xMin, Bindings.DOUBLE);
\r
46 graph.claimLiteral(expr, sr.WithLookupExpression_minY, yMin, Bindings.DOUBLE);
\r
47 graph.claimLiteral(expr, sr.WithLookupExpression_maxX, xMax, Bindings.DOUBLE);
\r
48 graph.claimLiteral(expr, sr.WithLookupExpression_maxY, yMax, Bindings.DOUBLE);
\r
54 public Resource getExpressionType(ReadGraph graph) {
\r
55 return SysdynResource.getInstance(graph).WithLookupExpression;
\r