1 package org.simantics.sysdyn.modelImport.model.element;
\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.layer0.Layer0;
\r
9 import org.simantics.layer0.utils.direct.GraphUtils;
\r
10 import org.simantics.modeling.ModelingResources;
\r
11 import org.simantics.sysdyn.SysdynResource;
\r
12 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
13 import org.simantics.sysdyn.modelImport.model.expression.Expression;
\r
14 import org.simantics.sysdyn.modelImport.model.support.Range;
\r
15 import org.simantics.sysdyn.modelImport.model.support.Variable;
\r
17 public abstract class ModelVariable extends Symbol {
\r
19 private String name;
\r
20 private Expression expression;
\r
21 private Range range;
\r
22 private String unit;
\r
23 private String description;
\r
25 private Resource variable;
\r
27 public ModelVariable(double x, double y, double w, double h,
\r
28 String name, Expression expression, Range range, String unit, String description) {
\r
31 this.expression = expression;
\r
34 this.description = description;
\r
37 public ModelVariable(double[] dimensions, Variable variable) {
\r
39 this.name = variable.getName();
\r
40 this.expression = variable.getExpression();
\r
41 this.range = variable.getRange();
\r
42 this.unit = variable.getUnit();
\r
43 this.description = variable.getDescription();
\r
46 public ModelVariable(double x, double y, double w, double h, Variable variable) {
\r
48 this.name = variable.getName();
\r
49 this.expression = variable.getExpression();
\r
50 this.range = variable.getRange();
\r
51 this.unit = variable.getUnit();
\r
52 this.description = variable.getDescription();
\r
55 public String getName() {
\r
60 public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {
\r
61 Layer0 l0 = Layer0.getInstance(graph);
\r
62 ModelingResources mr = ModelingResources.getInstance(graph);
\r
63 SysdynResource sr = SysdynResource.getInstance(graph);
\r
65 variable = GraphUtils.create2(graph, getVariableType(graph),
\r
68 graph.claim(variable, mr.Mapped, variable);
\r
70 // TODO: write references to enumerations here?
\r
72 if (expression != null) {
\r
73 expression.write(graph, variable, context);
\r
75 if (range != null) {
\r
76 range.write(graph, variable, context);
\r
78 if (unit != null && !unit.isEmpty()) {
\r
79 graph.claimLiteral(variable, sr.Variable_unit, unit, Bindings.STRING);
\r
81 if (description != null && !description.isEmpty()) {
\r
82 graph.claimLiteral(variable, l0.HasDescription, description, Bindings.STRING);
\r
85 Resource symbol = super.write(graph, parent, context);
\r
86 graph.claim(symbol, mr.ElementToComponent, variable);
\r
91 public abstract Resource getVariableType(ReadGraph graph);
\r
94 public Resource getResource() {
\r