1 package org.simantics.sysdyn.modelImport.model.element;
\r
3 import java.util.List;
\r
5 import org.simantics.databoard.Bindings;
\r
6 import org.simantics.db.Resource;
\r
7 import org.simantics.db.WriteGraph;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.layer0.Layer0;
\r
10 import org.simantics.layer0.utils.direct.GraphUtils;
\r
11 import org.simantics.modeling.ModelingResources;
\r
12 import org.simantics.sysdyn.SysdynResource;
\r
13 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
14 import org.simantics.sysdyn.modelImport.model.expression.IExpression;
\r
15 import org.simantics.sysdyn.modelImport.model.support.Enumeration;
\r
16 import org.simantics.sysdyn.modelImport.model.support.Range;
\r
17 import org.simantics.sysdyn.modelImport.model.support.Variable;
\r
19 public abstract class ModelVariable extends Element {
\r
21 protected String name;
\r
22 protected IExpression expression;
\r
23 protected Range range;
\r
24 protected String unit;
\r
25 protected String description;
\r
27 protected List<Enumeration> enumerations;
\r
29 public ModelVariable(double x, double y, double w, double h, String name, IExpression expression, Range range, String unit, String description) {
\r
32 this.expression = expression;
\r
35 this.description = description;
\r
38 public ModelVariable(double x, double y, double w, double h, Variable variable) {
\r
40 this.name = variable.getName();
\r
41 this.expression = variable.getExpression();
\r
42 this.range = variable.getRange();
\r
43 this.unit = variable.getUnit();
\r
44 this.description = variable.getDescription();
\r
47 public String getName() {
\r
51 public Resource createVariable(WriteGraph graph, Resource type, Resource parent, WriteContext context)
\r
52 throws DatabaseException {
\r
53 Layer0 l0 = Layer0.getInstance(graph);
\r
54 ModelingResources mr = ModelingResources.getInstance(graph);
\r
55 SysdynResource sr = SysdynResource.getInstance(graph);
\r
57 Resource variable = GraphUtils.create2(graph, type,
\r
60 graph.claim(variable, mr.Mapped, variable);
\r
62 expression.write(graph, variable, context);
\r
64 // TODO: write references to enumerations here?
\r
66 if (range != null) {
\r
67 range.write(graph, variable, context);
\r
69 if (unit != null && !unit.isEmpty()) {
\r
70 graph.claimLiteral(variable, sr.Variable_unit, unit, Bindings.STRING);
\r
72 if (description != null && !description.isEmpty()) {
\r
73 graph.claimLiteral(variable, l0.HasDescription, description, Bindings.STRING);
\r