]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
f2f84ebab2c002fffc112b7ff98e77c8622d7be1
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.modelImport.model.expression;\r
2 \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
10 \r
11 public class LookupExpression extends Expression {\r
12         \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
19         \r
20         public LookupExpression(String expression, double xMin, double yMin, double xMax, double yMax, double[] points) {\r
21                 this.expression = expression;\r
22                 this.xMin = xMin;\r
23                 this.yMin = yMin;\r
24                 this.xMax = xMax;\r
25                 this.yMax = yMax;\r
26                 this.points = points;\r
27         }\r
28 \r
29         @Override\r
30         public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {\r
31                 SysdynResource sr = SysdynResource.getInstance(graph);\r
32                 \r
33                 StringBuilder lookup = new StringBuilder();\r
34                 lookup.append('{');\r
35                 for (int i = 0; i < points.length / 2; i++) {\r
36                         if (i > 0)\r
37                                 lookup.append(',');\r
38                         lookup.append('{').append(points[2*i]).append(',').append(points[2*i+1]).append('}');\r
39                 }\r
40                 lookup.append('}');\r
41                 \r
42                 Resource expr = super.write(graph, parent, context);\r
43                 \r
44                 // TODO: fix this\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
51                 \r
52                 return expr;\r
53         }\r
54         \r
55         @Override\r
56         public Resource getExpressionType(ReadGraph graph) {\r
57                 return SysdynResource.getInstance(graph).WithLookupExpression;\r
58         }\r
59 \r
60 }\r