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