import org.simantics.sysdyn.modelImport.MdlParser;\r
import org.simantics.sysdyn.modelImport.MdlParser2;\r
import org.simantics.sysdyn.modelImport.model.Model;\r
+import org.simantics.sysdyn.modelImport.model.Model2;\r
import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.ui.SimanticsUI;\r
\r
\r
// Convert Vensim model to Simantics SysDyn format using MdlParser\r
MdlParser2 parser = new MdlParser2();\r
- parser.parse(file);\r
+ final Model2 model = parser.parse(file);\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
- //model.write(graph, project);\r
+ model.write(graph, project);\r
}\r
});\r
\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
+import org.simantics.sysdyn.modelImport.MdlUtils.CommentIcon;\r
+import org.simantics.sysdyn.modelImport.model.Auxiliary2;\r
+import org.simantics.sysdyn.modelImport.model.Cloud2;\r
+import org.simantics.sysdyn.modelImport.model.Comment2;\r
import org.simantics.sysdyn.modelImport.model.Connection2;\r
import org.simantics.sysdyn.modelImport.model.Element2;\r
-import org.simantics.sysdyn.modelImport.model.Model;\r
+import org.simantics.sysdyn.modelImport.model.IntegralExpression;\r
import org.simantics.sysdyn.modelImport.model.Model2;\r
+import org.simantics.sysdyn.modelImport.model.Shadow2;\r
import org.simantics.sysdyn.modelImport.model.Sketch2;\r
import org.simantics.sysdyn.modelImport.model.SketchComment;\r
import org.simantics.sysdyn.modelImport.model.SketchConnection;\r
import org.simantics.sysdyn.modelImport.model.SketchElement;\r
import org.simantics.sysdyn.modelImport.model.SketchValve;\r
import org.simantics.sysdyn.modelImport.model.SketchVariable;\r
+import org.simantics.sysdyn.modelImport.model.Stock2;\r
+import org.simantics.sysdyn.modelImport.model.Valve2;\r
import org.simantics.sysdyn.modelImport.model.Variable2;\r
\r
/*\r
public class MdlParser2 {\r
\r
private static final String UTF_8 = "{UTF-8}";\r
- private static final String CONTROL_STR = ".Control";\r
private static final String SKETCH_VERSION = "V300";\r
\r
+ private static final String CATEGORY_CONTROL = "Control";\r
+ \r
// each .mdl is divided into three sections, these are the the delimiter\r
// strings used to identify where each section starts\r
private static final String SKETCH_START = "\\\\\\---///";\r
private static final String SKETCH_END = "///---\\\\\\";\r
+ \r
+ private static final double H_SPACE = 10;\r
+ private static final double V_SPACE = 0;\r
\r
private HashMap<String, Variable2> variables;\r
private HashMap<String, Variable2> controls;\r
sketches = new ArrayList<Sketch2>();\r
}\r
\r
- public Model parse(File file) {\r
+ public Model2 parse(File file) {\r
try {\r
// peek at the first line to see if we need to use UTF-8\r
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));\r
\r
Model2 model = new Model2(file.getName());\r
\r
- int offset = 0;\r
+ double hOffset = 0;\r
+ double vOffset = V_SPACE;\r
+ \r
+ // do this in several passes\r
\r
- for (Sketch2 sketch : sketches) {\r
- // must keep track of which elements in the sketch correspond to \r
- // which elements in the model so connections can be constructed \r
- // accurately\r
- HashMap<SketchElement, Element2> elementMap = new HashMap<SketchElement, Element2>();\r
+ HashMap<Variable2, Element2> allVariables = new HashMap<Variable2, Element2>();\r
+ \r
+ // add sketch labels and independent elements\r
+ for (int i = 0; i < sketches.size(); i++) {\r
+ Sketch2 sketch = sketches.get(i);\r
+ \r
+ sketch.hOffset = hOffset;\r
+ sketch.vOffset = vOffset;\r
\r
- for (SketchElement element : sketch.getElements()) {\r
- Element2 e = element.getWriteableElement(0, 0);\r
- //model.addElement(e);\r
- //elementMap.put(element, e);\r
+ model.addElement(new Comment2(sketch.getWidth() / 2 + sketch.hOffset, 0, sketch.getName()));\r
+ \r
+ for (SketchComment comment : sketch.getComments()) {\r
+ if (comment.isInputOutput()) {\r
+ // input / output objects are not supported yet\r
+ System.err.println("input / output objects are not supported yet");\r
+ continue;\r
+ }\r
+ \r
+ Element2 modelElement = comment.getModelElement(sketch.hOffset, sketch.vOffset);\r
+ model.addElement(modelElement);\r
+ sketch.elements.put(comment.getId(), modelElement);\r
}\r
\r
- for (SketchConnection connection : sketch.getConnections()) {\r
- Connection2 c = connection.getWriteableConnection();\r
- //model.addConnection(c);\r
+ for (SketchValve valve : sketch.getValves()) {\r
+ Element2 modelElement = valve.getModelElement(sketch.hOffset, sketch.vOffset);\r
+ model.addElement(modelElement);\r
+ sketch.elements.put(valve.getId(), modelElement);\r
+ sketch.elements.put(valve.getAttachedVariable().getId(), modelElement);\r
+ allVariables.put(valve.getAttachedVariable().getVariable(), modelElement);\r
+ }\r
+ \r
+ for (SketchVariable variable : sketch.getVariables()) {\r
+ if (!variable.allowsIn()) {\r
+ // the variable is a shadow variable, skip these for now\r
+ continue;\r
+ }\r
+ \r
+ if (variable.isAttached()) {\r
+ // the variable is attached to a valve, already handled\r
+ continue;\r
+ }\r
+ \r
+ Element2 modelElement = variable.getModelElement(sketch.hOffset, sketch.vOffset);\r
+ model.addElement(modelElement);\r
+ sketch.elements.put(variable.getId(), modelElement);\r
+ allVariables.put(variable.getVariable(), modelElement);\r
+ }\r
+ \r
+ hOffset += sketch.getWidth() + H_SPACE;\r
+ }\r
+ \r
+ // add dependent elements\r
+ for (int i = 0; i < sketches.size(); i++) {\r
+ Sketch2 sketch = sketches.get(i);\r
+ \r
+ for (SketchVariable variable : sketch.getVariables()) {\r
+ if (!variable.allowsIn()) {\r
+ // the variable is a shadow variable\r
+ Element2 original = allVariables.get(variable.getVariable());\r
+ if (original == null) {\r
+ System.err.println("original not found");\r
+ continue;\r
+ }\r
+ Shadow2 modelElement = new Shadow2(variable.getX(sketch.hOffset), variable.getY(sketch.vOffset), allVariables.get(variable.getVariable()));\r
+ model.addShadow(modelElement);\r
+ sketch.elements.put(variable.getId(), modelElement);\r
+ }\r
}\r
\r
- offset += sketch.getWidth() + 100;\r
+ for (SketchConnection connection : sketch.getConnections()) {\r
+ Element2 head = sketch.elements.get(connection.getTo());\r
+ Element2 tail = sketch.elements.get(connection.getFrom());\r
+ Connection2 c = connection.getWriteableConnection(head, tail);\r
+ if (c != null) {\r
+ model.addConnection(c);\r
+ }\r
+ }\r
}\r
\r
- return null;\r
+ return model;\r
}\r
\r
private String readVariables(BufferedReader reader, String line) \r
\r
StringBuilder buffer = new StringBuilder(line);\r
\r
- while ((line = reader.readLine()) != null) {\r
+ do {\r
if (line.endsWith("\\"))\r
buffer.append(line.substring(0, line.length()-1));\r
else\r
\r
if (line.endsWith("|"))\r
break;\r
- }\r
+ } while ((line = reader.readLine()) != null);\r
\r
String str = buffer.toString();\r
- \r
- // TODO: must handle categories other than .Control\r
+\r
+ // handle category declarations\r
+ String cat = MdlUtils.getPossibleCategory(str);\r
+ if (cat != null) {\r
+ category = cat;\r
+ continue;\r
+ }\r
\r
Variable2 var = MdlUtils.getPossibleVariable(str, category);\r
if (var != null) {\r
- variables.put(var.getName(), var);\r
+ if (CATEGORY_CONTROL.equals(category)) {\r
+ controls.put(var.getName(), var);\r
+ }\r
+ else {\r
+ variables.put(var.getName(), var);\r
+ }\r
continue;\r
}\r
\r
\r
SketchConnection connection = MdlUtils.getPossibleSketchConnection(line);\r
if (connection != null) {\r
- sketch.addSketchObject(connection);\r
+ sketch.addConnection(connection);\r
continue;\r
}\r
\r
SketchVariable variable = MdlUtils.getPossibleSketchVariable(line, variables);\r
if (variable != null) {\r
- sketch.addSketchObject(variable);\r
+ sketch.addVariable(variable);\r
continue;\r
}\r
\r
continue;\r
}\r
valve.setAttachedVariable(attached);\r
- sketch.addSketchObject(valve);\r
- sketch.addSketchObject(attached);\r
+ sketch.addValve(valve);\r
+ sketch.addVariable(attached);\r
continue;\r
}\r
\r
SketchComment comment = MdlUtils.getPossibleSketchComment(line);\r
if (comment != null) {\r
- if (comment.hasTextNextLine()) {\r
+ if (comment.hasTextLine()) {\r
comment.setText(reader.readLine());\r
}\r
- \r
- if (comment.isIOElement()) {\r
- System.err.println("IO elements are not currently supported");\r
- continue;\r
- }\r
- \r
- sketch.addSketchObject(comment);\r
+ sketch.addComment(comment);\r
continue;\r
}\r
\r
import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
\r
+import org.simantics.sysdyn.modelImport.model.IExpression;\r
+import org.simantics.sysdyn.modelImport.model.IntegralExpression;\r
+import org.simantics.sysdyn.modelImport.model.NormalExpression;\r
+import org.simantics.sysdyn.modelImport.model.Range;\r
import org.simantics.sysdyn.modelImport.model.SketchComment;\r
import org.simantics.sysdyn.modelImport.model.SketchConnection;\r
import org.simantics.sysdyn.modelImport.model.SketchElement;\r
import org.simantics.sysdyn.modelImport.model.SketchVariable;\r
import org.simantics.sysdyn.modelImport.model.Variable2;\r
import org.simantics.sysdyn.modelImport.model.Valve2.TextPosition;\r
-import org.simantics.utils.datastructures.Pair;\r
\r
public class MdlUtils {\r
\r
}\r
\r
String name = matcher.group(variableName);\r
- String equation = matcher.group(variableEquation);\r
+ IExpression expression = parseEquation(matcher.group(variableEquation));\r
+ \r
String unit = matcher.group(variableUnit);\r
+ Range range = parseRange(unit);\r
+ if (range != null) {\r
+ unit = unit.substring(0, unit.indexOf(range.originalString())).trim();\r
+ }\r
String description = matcher.group(variableDesc);\r
\r
- return new Variable2(name, equation, unit, description);\r
+ return new Variable2(name, expression, unit, range, description);\r
}\r
\r
- public static Pair<String, String> getPossibleIntegral(String equation) {\r
- \r
+ private static IExpression parseEquation(String equation) {\r
Matcher matcher = Pattern.compile("INTEG\\s*\\((.*),(.*)\\)").matcher(equation);\r
if (matcher.matches()) {\r
- return new Pair<String, String>(matcher.group(1), matcher.group(2));\r
+ return new IntegralExpression(matcher.group(1), matcher.group(2));\r
+ }\r
+ else {\r
+ return new NormalExpression("");\r
+ }\r
+ }\r
+ \r
+ private static Range parseRange(String unit) {\r
+ Matcher matcher = Pattern.compile("\\[(-?\\d+|\\?),(-?\\d+|\\?)\\]").matcher(unit);\r
+ if (matcher.find()) {\r
+ String start = matcher.group(1);\r
+ String end = matcher.group(2);\r
+ // TODO: and step is?\r
+ return new Range(\r
+ start.equals("?") ? null : Double.parseDouble(start), \r
+ end.equals("?") ? null : Double.parseDouble(end), \r
+ null, \r
+ matcher.group());\r
+ }\r
+ else {\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ private static final String categoryPattern = "\\*{56}\\s+\\.(\\S+)\\s+\\*{56}.*";\r
+ \r
+ public static String getPossibleCategory(String line) {\r
+ Matcher matcher = Pattern.compile(categoryPattern).matcher(line);\r
+ \r
+ if (!matcher.matches()) {\r
+ return null;\r
}\r
\r
- return null;\r
+ return matcher.group(1);\r
}\r
\r
// sketch object data is defined similarly\r
\r
int id = Integer.parseInt(matcher.group(elementId));\r
Variable2 var = variables.get(matcher.group(elementName));\r
- boolean attached = elementIsAttached(matcher);\r
- boolean in = elementAllowsInBound(matcher);\r
- boolean out = elementAllowsOutBound(matcher);\r
\r
- SketchVariable variable = new SketchVariable(id, var, attached, in, out);\r
+ SketchVariable variable = new SketchVariable(id, var);\r
\r
initializeElement(variable, matcher);\r
\r
\r
int id = Integer.parseInt(matcher.group(elementId));\r
CommentIcon icon = getCommentIcon(matcher);\r
- boolean nextLine = elementHasCommentLine(matcher);\r
- boolean isIO = elementIsIO(matcher);\r
\r
- SketchComment comment = new SketchComment(id, icon, nextLine, isIO);\r
+ SketchComment comment = new SketchComment(id, icon);\r
\r
initializeElement(comment, matcher);\r
\r
int y = Integer.parseInt(matcher.group(elementY));\r
int w = Integer.parseInt(matcher.group(elementWidth));\r
int h = Integer.parseInt(matcher.group(elementHeight));\r
+ boolean attached = elementIsAttached(matcher);\r
+ boolean in = elementAllowsInBound(matcher);\r
+ boolean out = elementAllowsOutBound(matcher);\r
+ boolean inputOutput = elementIsInputOutput(matcher);\r
+ boolean textLine = elementhasTextLine(matcher);\r
\r
- element.setLocationAndSize(x, y, w, h);\r
+ element.init(x, y, w, h, attached, in, out, inputOutput, textLine);\r
}\r
\r
public static ConnectionType getConnectionType(Matcher matcher) {\r
switch(Integer.parseInt(matcher.group(connectionShape))) {\r
- case 0: return ConnectionType.ARROW;\r
+ case 0: \r
+ case 1: return ConnectionType.ARROW;\r
case 4: return ConnectionType.LINE_ARROW;\r
case 100: return ConnectionType.LINE_SEGMENT;\r
- default: return ConnectionType.OTHER;\r
+ default: System.err.println("connection type "+Integer.parseInt(matcher.group(connectionShape))); return ConnectionType.OTHER;\r
}\r
}\r
\r
return (Integer.parseInt(matcher.group(elementBits)) & 1<<1) != 0;\r
}\r
\r
- public static boolean elementHasCommentLine(Matcher matcher) {\r
+ public static boolean elementhasTextLine(Matcher matcher) {\r
return (Integer.parseInt(matcher.group(elementBits)) & 1<<2) != 0;\r
}\r
\r
- public static boolean elementIsIO(Matcher matcher) {\r
+ public static boolean elementIsInputOutput(Matcher matcher) {\r
return (Integer.parseInt(matcher.group(elementBits)) & 1<<3) != 0;\r
}\r
\r
package org.simantics.sysdyn.modelImport.model;\r
\r
-import java.util.Arrays;\r
-\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
public class Auxiliary2 extends ModelVariable {\r
\r
- protected String equation;\r
-\r
public Auxiliary2(double x, double y, \r
- String name, String unit, Range range, String description, \r
- String equation) {\r
- this.equation = equation;\r
+ String name, IExpression expression, Range range, String unit, String description) {\r
+ super(x, y, name, expression, range, unit, description);\r
}\r
\r
- public Auxiliary2(double x, double y, Variable2 variable, String equation) {\r
- this.equation = equation;\r
+ public Auxiliary2(double x, double y, Variable2 variable) {\r
+ super(x, y, variable);\r
}\r
\r
@Override\r
public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
Resource variable = createVariable(graph, sr.Auxiliary, parent);\r
-\r
- Resource expression = GraphUtils.create2(graph, sr.NormalExpression,\r
- sr.Expression_equation, equation,\r
- l0.PartOf, variable);\r
- // TODO: why is the expressoin stored in two places?\r
- graph.claim(variable, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expression)));\r
-\r
createSymbol(graph, sr.AuxiliarySymbol, variable, parent);\r
-\r
+ \r
setResource(variable);\r
}\r
\r
+ @Override\r
+ public boolean supportsDependencies() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsFlows() {\r
+ return false;\r
+ }\r
+\r
}\r
sr.Cloud);\r
\r
graph.claim(parent, l0.ConsistsOf, cloud);\r
-\r
\r
\r
Resource symbol = GraphUtils.create2(graph, \r
package org.simantics.sysdyn.modelImport.model;\r
\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
public class Cloud2 extends Element2 {\r
\r
- public Cloud2() {\r
+ public Cloud2(double x, double y) {\r
+ super(x, y);\r
+ }\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ Resource cloud = GraphUtils.create2(graph, sr.Cloud, \r
+ l0.PartOf, parent);\r
+ \r
+ createSymbol(graph, sr.CloudSymbol, cloud, parent);\r
\r
+ setResource(cloud);\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsDependencies() {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsFlows() {\r
+ return true;\r
}\r
\r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
public class Comment2 extends Element2 {\r
+ \r
+ private String text;\r
+ \r
+ public Comment2(double x, double y, String text) {\r
+ super(x, y);\r
+ this.text = text;\r
+ }\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
+ DiagramResource dr = DiagramResource.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph); \r
+ \r
+ Resource comment = createSymbol(graph, sr.AdditionalSymbols_MultilineText, null, parent);\r
+ \r
+ graph.claimLiteral(comment, dr.HasText, text, Bindings.STRING);\r
+ \r
+ setResource(comment);\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsDependencies() {\r
+ return false;\r
+ }\r
\r
+ @Override\r
+ public boolean supportsFlows() {\r
+ return false;\r
+ }\r
+ \r
}\r
\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
\r
public abstract class Connection2 implements IWriteableObject {\r
- \r
+\r
protected Element2 head;\r
protected Element2 tail;\r
\r
- @Override\r
- public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
- System.err.println("Writing connection");\r
- }\r
- \r
- protected void writeConnection() {\r
- \r
- }\r
- \r
- public void setHead(Element2 head) {\r
+ public Connection2(Element2 head, Element2 tail) {\r
this.head = head;\r
- }\r
- \r
- public void setTail(Element2 tail) {\r
this.tail = tail;\r
}\r
- \r
+\r
+ protected Resource createConnection(WriteGraph graph, Resource type, Resource symbol, Resource parent) \r
+ throws DatabaseException {\r
+ // TODO: remove this\r
+ if (head == null || tail == null) {\r
+ return null;\r
+ }\r
+ \r
+ // create connection\r
+ Layer0 l0 = Layer0.getInstance(graph); \r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+ Resource connection = GraphUtils.create2(graph, type,\r
+ sr.Variable_HasHead, head.getResource(),\r
+ sr.Variable_HasTail, tail.getResource(),\r
+ l0.PartOf, parent);\r
+ graph.claim(connection, mr.Mapped, connection);\r
+\r
+ // create symbol\r
+ DiagramResource dr = DiagramResource.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ \r
+ Resource diagramTail = graph.getPossibleObject(tail.getResource(), mr.ComponentToElement);\r
+ Resource tailConnector = GraphUtils.create2(graph, dr.Connector,\r
+ sr.HasTailTerminal, diagramTail);\r
+\r
+ Resource diagramHead = graph.getPossibleObject(head.getResource(), mr.ComponentToElement);\r
+ Resource headConnector = GraphUtils.create2(graph, dr.Connector,\r
+ sr.HasHeadTerminal, diagramHead,\r
+ dr.AreConnected, tailConnector);\r
+\r
+ Resource diagramConnection = GraphUtils.create2(graph, symbol,\r
+ sr2.HasConnectionType, sr.SysdynConnectionType,\r
+ mr.DiagramConnectionToConnection, connection,\r
+ dr.HasArrowConnector, headConnector,\r
+ dr.HasPlainConnector, tailConnector);\r
+\r
+ Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram);\r
+ OrderedSetUtils.add(graph, diagram, diagramConnection);\r
+\r
+ return connection;\r
+ }\r
+\r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
public class Dependency2 extends Connection2 {\r
\r
private boolean showArrow;\r
private boolean showDelay;\r
\r
- public Dependency2(boolean showArrow, boolean showDelay) {\r
+ public Dependency2(Element2 head, Element2 tail, boolean showArrow, boolean showDelay) {\r
+ super(head, tail);\r
this.showArrow = showArrow;\r
this.showDelay = showDelay;\r
}\r
\r
@Override\r
- public void setHead(Element2 head) {\r
- // TODO: make sure head is of the right type\r
- super.setHead(head);\r
- }\r
-\r
- @Override\r
- public void setTail(Element2 Tail) {\r
- // TODO: make sure tail is of the right type\r
- super.setTail(tail);\r
+ public void write(WriteGraph graph, Resource parent)\r
+ throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ Resource dependency = createConnection(graph, sr.Dependency, sr.DependencyConnection, parent);\r
}\r
\r
}\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.ModelingResources;\r
\r
-public class Element2 implements IWriteableObject {\r
+public abstract class Element2 implements IWriteableObject {\r
+ \r
+ private static final double SCALE = 1.0 / 3.0;\r
\r
- private int x;\r
- private int y;\r
+ private double x;\r
+ private double y;\r
\r
private Resource resource;\r
\r
- public Element2() {\r
-\r
+ public Element2(double x, double y) {\r
+ this.x = x * SCALE;\r
+ this.y = y * SCALE;\r
}\r
\r
- // public Element2(int x, int y, int width, int height) {\r
- // this.x = x;\r
- // this.y = y;\r
- // this.width = width;\r
- // this.height = height;\r
- // \r
- // this.resource = null;\r
- // }\r
-\r
- @Override\r
- public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
- System.err.println("Writing element");\r
- }\r
-\r
- // TODO: is this the right place for this?\r
-\r
public Resource getResource() {\r
return resource;\r
}\r
G2DResource g2d = G2DResource.getInstance(graph);\r
ModelingResources mr = ModelingResources.getInstance(graph);\r
\r
- Resource symbol = GraphUtils.create2(graph, type, \r
- mr.ElementToComponent, variable);\r
+ Resource symbol = GraphUtils.create2(graph, type);\r
+ \r
+ if (variable != null) {\r
+ graph.claim(symbol, mr.ElementToComponent, variable);\r
+ }\r
\r
double[] transform = { 1.0, 0.0, 0.0, 1.0, x, y };\r
graph.claimLiteral(symbol, dr.HasTransform, g2d.Transform, transform, Bindings.DOUBLE_ARRAY);\r
\r
return symbol;\r
}\r
+ \r
+ public abstract boolean supportsDependencies();\r
+ public abstract boolean supportsFlows();\r
\r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
public class Flow2 extends Connection2 {\r
\r
- public Flow2() {\r
- \r
- }\r
-\r
- @Override\r
- public void setHead(Element2 head) {\r
- // TODO: make sure head is of the right type\r
- super.setHead(head);\r
+ public Flow2(Element2 head, Element2 tail) {\r
+ super(head, tail);\r
}\r
\r
@Override\r
- public void setTail(Element2 tail) {\r
- // TODO: make sure tail is of the right type\r
- super.setTail(tail);\r
+ public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ Resource flow = createConnection(graph, sr.Flow, sr.FlowConnection, parent);\r
}\r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.modelImport.model;\r
+\r
+public interface IExpression extends IWriteableObject {\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.modelImport.model;\r
+\r
+import java.util.Arrays;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class IntegralExpression implements IExpression {\r
+ \r
+ private String integral;\r
+ private String initial;\r
+ \r
+ public IntegralExpression(String integral, String initial) {\r
+ this.integral = integral;\r
+ this.initial = initial;\r
+ }\r
+ \r
+ @Override\r
+ public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ Resource expression = GraphUtils.create2(graph, sr.StockExpression,\r
+ sr.StockExpression_integralEquation, integral,\r
+ sr.StockExpression_initialEquation, initial,\r
+ l0.PartOf, parent);\r
+ // TODO: why is the expression stored in two places?\r
+ graph.claim(parent, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expression)));\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.modelImport.model;\r
+\r
+public class MdlModel {\r
+\r
+}\r
\r
// the structure of the model\r
private ArrayList<Element2> elements;\r
+ private ArrayList<Shadow2> shadows;\r
private ArrayList<Connection2> connections;\r
\r
public Model2(String name) {\r
this.name = name;\r
\r
elements = new ArrayList<Element2>();\r
+ shadows = new ArrayList<Shadow2>();\r
connections = new ArrayList<Connection2>();\r
}\r
\r
elements.add(element);\r
}\r
\r
+ public void addShadow(Shadow2 shadow) {\r
+ shadows.add(shadow);\r
+ }\r
+ \r
public void addConnection(Connection2 connection) {\r
connections.add(connection);\r
}\r
Resource model = ModelUtils.createModel(graph);\r
graph.claimLiteral(model, l0.HasLabel, name, Bindings.STRING);\r
\r
- // TODO: set simulatin parameters\r
+ // TODO: set simulation parameters\r
\r
Resource configuration = graph.getSingleObject(model, sim.HasConfiguration);\r
\r
e.write(graph, configuration);\r
}\r
\r
+ for (Shadow2 s : shadows) {\r
+ s.write(graph, configuration);\r
+ }\r
+ \r
for (Connection2 c : connections) {\r
c.write(graph, configuration);\r
}\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
-public class ModelVariable extends Element2 {\r
+public abstract class ModelVariable extends Element2 {\r
\r
protected String name;\r
+ protected IExpression expression;\r
protected Range range;\r
protected String unit;\r
protected String description;\r
\r
- public ModelVariable() {\r
-\r
+ public ModelVariable(double x, double y, String name, IExpression expression, Range range, String unit, String description) {\r
+ super(x, y);\r
+ this.name = name;\r
+ this.expression = expression;\r
+ this.range = range;\r
+ this.unit = unit;\r
+ this.description = description;\r
+ }\r
+ \r
+ public ModelVariable(double x, double y, Variable2 variable) {\r
+ super(x, y);\r
+ this.name = variable.getName();\r
+ this.expression = variable.getExpression();\r
+ this.range = variable.getRange();\r
+ this.unit = variable.getUnit();\r
+ this.description = variable.getDescription();\r
}\r
\r
- public Resource createVariable(WriteGraph graph, Resource type, Resource parent) throws DatabaseException {\r
+ public Resource createVariable(WriteGraph graph, Resource type, Resource parent) \r
+ throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
ModelingResources mr = ModelingResources.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
l0.PartOf, parent);\r
graph.claim(variable, mr.Mapped, variable);\r
\r
+ expression.write(graph, variable);\r
+ \r
+ if (range != null) {\r
+ range.write(graph, variable);\r
+ }\r
if (unit != null && !unit.isEmpty()) {\r
graph.claimLiteral(variable, sr.Variable_unit, unit, Bindings.STRING);\r
}\r
if (description != null && !description.isEmpty()) {\r
graph.claimLiteral(variable, l0.HasDescription, description, Bindings.STRING);\r
}\r
- if (range != null) {\r
- //graph.claimLiteral(variable, sr.HasRangeStart, rangeStart);\r
- //graph.claimLiteral(variable, sr.HasRangeEnd, rangeEnd);\r
- //graph.claimLiteral(variable, sr.HasRangeStep, rangeStep);\r
- }\r
\r
return variable;\r
}\r
--- /dev/null
+package org.simantics.sysdyn.modelImport.model;\r
+\r
+import java.util.Arrays;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class NormalExpression implements IExpression {\r
+\r
+ private String equation;\r
+ \r
+ public NormalExpression(String equation) {\r
+ this.equation = equation;\r
+ }\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource variable) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+ Resource expression = GraphUtils.create2(graph, sr.NormalExpression,\r
+ sr.Expression_equation, equation,\r
+ l0.PartOf, variable);\r
+ // TODO: why is the expression stored in two places?\r
+ graph.claim(variable, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expression)));\r
+ }\r
+}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
-public class Range {\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class Range implements IWriteableObject {\r
\r
- private double start;\r
- private double end;\r
- private double step;\r
+ private Double start;\r
+ private Double end;\r
+ private Double step;\r
+ private String original;\r
\r
- public Range(double start, double end, double step) {\r
+ public Range(Double start, Double end, Double step, String original) {\r
this.start = start;\r
this.end = end;\r
this.step = step;\r
+ this.original = original;\r
+ }\r
+ \r
+ public Double getStart() {\r
+ return start;\r
+ }\r
+\r
+ public Double getEnd() {\r
+ return end;\r
+ }\r
+\r
+ public Double getStep() {\r
+ return step;\r
+ }\r
+\r
+ public String originalString() {\r
+ return original;\r
+ }\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource variable) throws DatabaseException {\r
+ // TODO: implementation\r
}\r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.modelImport.model;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class Shadow2 extends Element2 {\r
+\r
+ private Element2 original;\r
+ \r
+ public Shadow2(double x, double y, Element2 original) {\r
+ super(x, y);\r
+ this.original = original;\r
+ }\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ Resource shadow = GraphUtils.create2(graph, sr.Shadow, \r
+ l0.PartOf, parent);\r
+ \r
+ graph.claim(shadow, sr.Shadow_original, original.getResource());\r
+ \r
+ createSymbol(graph, sr.ShadowSymbol, shadow, parent);\r
+ \r
+ setResource(shadow);\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsDependencies() {\r
+ return original.supportsDependencies();\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsFlows() {\r
+ return original.supportsFlows();\r
+ }\r
+\r
+}\r
\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
-import java.util.Iterator;\r
import java.util.List;\r
\r
public class Sketch2 {\r
\r
private String name;\r
\r
- private HashMap<Integer, SketchObject> objectMap;\r
- private ArrayList<SketchConnection> unfinished;\r
+ private ArrayList<SketchComment> comments;\r
+ private ArrayList<SketchConnection> connections;\r
+ private ArrayList<SketchValve> valves;\r
+ private ArrayList<SketchVariable> variables;\r
\r
public Sketch2() {\r
- objectMap = new HashMap<Integer, SketchObject>();\r
- unfinished = new ArrayList<SketchConnection>();\r
+ comments = new ArrayList<SketchComment>();\r
+ connections = new ArrayList<SketchConnection>();\r
+ valves = new ArrayList<SketchValve>();\r
+ variables = new ArrayList<SketchVariable>();\r
}\r
\r
public String getName() {\r
this.name = name;\r
}\r
\r
- public SketchObject getSketchObject(int index) {\r
- return objectMap.get(index);\r
- }\r
-\r
- public void addSketchObject(SketchConnection object) {\r
- unfinished.add(object);\r
- \r
- addSketchObject((SketchObject)object);\r
+ public void addComment(SketchComment comment) {\r
+ comments.add(comment);\r
}\r
\r
- public void addSketchObject(SketchObject object) {\r
- if (objectMap.get(object.getId()) != null) {\r
- System.err.println("duplicate object with id "+object.getId());\r
- return;\r
- }\r
- objectMap.put(object.getId(), object);\r
- \r
- // NOTE: could just do another pass to update connections at the end \r
- // or just use a priority queue or something but the number of \r
- // unfinished connections at any given time should be relatively \r
- // small in practice so it does not matter that this is inefficient\r
- Iterator<SketchConnection> i = unfinished.iterator();\r
- while (i.hasNext()) {\r
- SketchConnection connection = i.next();\r
- \r
- SketchObject from = objectMap.get(connection.getFromId());\r
- SketchObject to = objectMap.get(connection.getToId());\r
- \r
- if (from != null && to != null) {\r
- // connections can only connect elements so if this is not the \r
- // case something has gone wrong with the indexing\r
- assert from instanceof SketchElement;\r
- assert to instanceof SketchElement;\r
- \r
- connection.setFrom((SketchElement)from);\r
- connection.setTo((SketchElement)to);\r
- \r
- i.remove();\r
- }\r
- }\r
+ public List<SketchComment> getComments() {\r
+ return comments;\r
}\r
-\r
- // TODO: ugly and inefficient\r
\r
- public List<SketchElement> getElements() {\r
- ArrayList<SketchElement> list = new ArrayList<SketchElement>();\r
- for (SketchObject o : objectMap.values()) {\r
- if (o instanceof SketchElement) {\r
- list.add((SketchElement)o);\r
- }\r
- }\r
- return list;\r
+ public void addConnection(SketchConnection connection) {\r
+ connections.add(connection);\r
}\r
\r
public List<SketchConnection> getConnections() {\r
- ArrayList<SketchConnection> list = new ArrayList<SketchConnection>();\r
- for (SketchObject o : objectMap.values()) {\r
- if (o instanceof SketchConnection) {\r
- list.add((SketchConnection)o);\r
- }\r
- }\r
+ return connections;\r
+ }\r
+ \r
+ public void addValve(SketchValve valve) {\r
+ valves.add(valve);\r
+ }\r
+ \r
+ public List<SketchValve> getValves() {\r
+ return valves;\r
+ }\r
+ \r
+ public void addVariable(SketchVariable variable) {\r
+ variables.add(variable);\r
+ }\r
+ \r
+ public List<SketchVariable> getVariables() {\r
+ return variables;\r
+ }\r
+ \r
+ public List<SketchElement> getAllElements() {\r
+ ArrayList<SketchElement> list = new ArrayList<SketchElement>();\r
+ list.addAll(getComments());\r
+ list.addAll(getValves());\r
+ list.addAll(getVariables());\r
return list;\r
}\r
\r
public int getWidth() {\r
int width = 0;\r
- for (SketchElement e : getElements()) {\r
+ for (SketchElement e : getAllElements()) {\r
width = Math.max(width, e.getX()+e.getWidth());\r
}\r
return width;\r
\r
public int getHeight() {\r
int height = 0;\r
- for (SketchElement e : getElements()) {\r
+ for (SketchElement e : getAllElements()) {\r
height = Math.max(height, e.getY()+e.getHeight());\r
}\r
return height;\r
}\r
+ \r
+ // relevant for sysdyn model creation, this is not the cleanest place to\r
+ // store this information but it works\r
+ \r
+ public double hOffset = 0;\r
+ public double vOffset = 0;\r
+ \r
+ public HashMap<Integer, Element2> elements = new HashMap<Integer, Element2>();\r
\r
}\r
\r
private String text;\r
private CommentIcon icon;\r
- private boolean nextLine;\r
- private boolean isIO;\r
\r
- public SketchComment(int id, CommentIcon icon, boolean nextLine, boolean isIO) {\r
+ public SketchComment(int id, CommentIcon icon) {\r
super(id);\r
this.icon = icon;\r
- this.nextLine = nextLine;\r
- this.isIO = isIO;\r
}\r
\r
public String getText() {\r
}\r
\r
public CommentIcon getIcon() {\r
- return this.icon;\r
+ return icon;\r
}\r
\r
- public boolean isCloud() {\r
- return this.icon.equals(CommentIcon.CLOUD);\r
- }\r
- \r
- public boolean hasTextNextLine() {\r
- return nextLine;\r
- }\r
- \r
- public boolean isIOElement() {\r
- return this.isIO;\r
- }\r
- \r
- public Comment2 getWriteableElement(int xOffset, int yOffset) {\r
- return null;\r
- }\r
- \r
- @Override\r
- public String toString() {\r
- return text != null ? "\""+text+"\"" : "(empty comment)";\r
+ public Element2 getModelElement(double xOffset, double yOffset) {\r
+ if (icon.equals(CommentIcon.CLOUD)) {\r
+ return new Cloud2(getX(xOffset), getY(yOffset));\r
+ }\r
+ else {\r
+ return new Comment2(getX(xOffset), getY(yOffset), text);\r
+ }\r
}\r
\r
}\r
\r
public class SketchConnection extends SketchObject {\r
\r
- private int fromId;\r
- private SketchElement from;\r
- private int toId;\r
- private SketchElement to;\r
+ private int from;\r
+ private int to;\r
private ConnectionType type;\r
\r
- public SketchConnection(int id, int fromId, int toId, ConnectionType type) {\r
+ public SketchConnection(int id, int from, int to, ConnectionType type) {\r
super(id);\r
- this.fromId = fromId;\r
- this.toId = toId;\r
+ this.from = from;\r
+ this.to = to;\r
this.type = type;\r
}\r
\r
- public int getFromId() {\r
- return fromId;\r
- }\r
- \r
- public int getToId() {\r
- return toId;\r
- }\r
-\r
- public SketchElement getFrom() {\r
- if (from == null) {\r
- System.err.println("endpoint "+fromId+" for connection "+getId()+" is unset");\r
- }\r
+ public int getFrom() {\r
return from;\r
}\r
-\r
- public void setFrom(SketchElement from) {\r
- this.from = from;\r
- }\r
-\r
- public SketchElement getTo() {\r
- if (to == null) {\r
- System.err.println("endpoint "+toId+" for connection "+getId()+" is unset");\r
- }\r
+ \r
+ public int getTo() {\r
return to;\r
}\r
-\r
- public void setTo(SketchElement to) {\r
- this.to = to;\r
- }\r
\r
public ConnectionType getType() {\r
return type;\r
}\r
\r
- public Connection2 getWriteableConnection() {\r
- // return dependency or flow\r
+ public Connection2 getWriteableConnection(Element2 head, Element2 tail) {\r
+ if (type.equals(ConnectionType.ARROW)) {\r
+ return new Dependency2(head, tail, false, false);\r
+ }\r
+ else if (type.equals(ConnectionType.LINE_ARROW)) {\r
+ return new Flow2(head, tail);\r
+ }\r
+ else if (type.equals(ConnectionType.LINE_SEGMENT)) {\r
+ // TODO: what is this I don't even...\r
+ return new Flow2(tail, head);\r
+ }\r
return null;\r
}\r
\r
- @Override\r
- public String toString() {\r
- return from.toString() + " --> " + to.toString();\r
- }\r
- \r
}\r
private int y;\r
private int width;\r
private int height;\r
+ private boolean attached;\r
+ private boolean allowsIn;\r
+ private boolean allowsOut;\r
+ private boolean inputOutput;\r
+ private boolean textLine;\r
\r
public SketchElement(int id) {\r
super(id);\r
}\r
\r
- public void setLocationAndSize(int x, int y, int width, int height) {\r
+ public void init(int x, int y, int width, int height, \r
+ boolean attached, boolean allowsIn, boolean allowsOut, \r
+ boolean inputOutput, boolean textLine) {\r
this.x = x;\r
this.y = y;\r
this.width = width;\r
this.height = height;\r
+ this.attached = attached;\r
+ this.allowsIn = allowsIn;\r
+ this.allowsOut = allowsOut;\r
+ this.inputOutput = inputOutput;\r
+ this.textLine = textLine;\r
}\r
\r
public int getX() {\r
return x;\r
}\r
+ \r
+ public double getX(double offset) {\r
+ return x + offset;\r
+ }\r
\r
public int getY() {\r
return y;\r
}\r
+ \r
+ public double getY(double offset) {\r
+ return y + offset;\r
+ }\r
\r
public int getWidth() {\r
return width;\r
return height;\r
}\r
\r
- public abstract Element2 getWriteableElement(int xOffset, int yOffset);\r
+ public boolean isAttached() {\r
+ return attached;\r
+ }\r
+\r
+ public boolean allowsIn() {\r
+ return allowsIn;\r
+ }\r
+\r
+ public boolean allowsOut() {\r
+ return allowsOut;\r
+ }\r
+\r
+ public boolean isInputOutput() {\r
+ return inputOutput;\r
+ }\r
+\r
+ public boolean hasTextLine() {\r
+ return textLine;\r
+ }\r
+\r
+ public abstract Element2 getModelElement(double xOffset, double yOffset);\r
\r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
public abstract class SketchObject {\r
- \r
- // TODO: some type stuff here maybe?\r
- \r
+\r
private int id;\r
\r
SketchObject(int id) {\r
}\r
\r
@Override\r
- public Valve2 getWriteableElement(int xOffset, int yOffset) {\r
- return null;\r
- }\r
- \r
- @Override\r
- public String toString() {\r
- return "X("+variable.toString()+")";\r
+ public Element2 getModelElement(double xOffset, double yOffset) {\r
+ return new Valve2(getX(xOffset), getY(yOffset), variable.getVariable());\r
}\r
\r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
-import org.simantics.sysdyn.modelImport.MdlUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
public class SketchVariable extends SketchElement {\r
\r
private Variable2 variable;\r
- boolean isAttached;\r
- boolean allowsInBound;\r
- boolean allowsOutBound;\r
\r
- public SketchVariable(int id, Variable2 variable, boolean isAttached, boolean in, boolean out) {\r
+ public SketchVariable(int id, Variable2 variable) {\r
super(id);\r
this.variable = variable;\r
- this.isAttached = isAttached;\r
- this.allowsInBound = in;\r
- this.allowsOutBound = out;\r
}\r
\r
public Variable2 getVariable() {\r
- return this.variable;\r
- }\r
- \r
- public boolean isAttached() {\r
- return isAttached;\r
- }\r
- \r
- public boolean allowsInBound() {\r
- return allowsInBound;\r
- }\r
- \r
- public boolean allowsOutBound() {\r
- return allowsOutBound;\r
+ return variable;\r
}\r
\r
@Override\r
- public Element2 getWriteableElement(int xOffset, int yOffset) {\r
- Pair<String, String> integral = MdlUtils.getPossibleIntegral(variable.getEquation());\r
- if (integral != null) {\r
- return new Stock2(getX(), getY(), variable, integral);\r
+ public Element2 getModelElement(double xOffset, double yOffset) {\r
+ if (variable.getExpression() instanceof IntegralExpression) {\r
+ return new Stock2(getX(xOffset), getY(yOffset), variable);\r
}\r
else {\r
- return new Auxiliary2(getX(), getY(), variable, variable.getEquation());\r
+ return new Auxiliary2(getX(xOffset), getY(yOffset), variable);\r
}\r
}\r
\r
- @Override\r
- public String toString() {\r
- return (allowsInBound?"":"<")+variable.getName()+(allowsInBound?"":">");\r
- }\r
- \r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
-import java.util.Arrays;\r
-\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.utils.datastructures.Pair;\r
\r
public class Stock2 extends ModelVariable {\r
\r
- protected String integral;\r
- protected String initial;\r
-\r
public Stock2(double x, double y, \r
- String name, String unit, Range range, String description, \r
- String integral, String initial) {\r
- this.integral = integral;\r
- this.initial = initial;\r
+ String name, IntegralExpression expression, Range range, String unit, String description) {\r
+ super(x, y, name, expression, range, unit, description);\r
}\r
\r
- public Stock2(double x, double y, Variable2 variable, Pair<String, String> equation) {\r
- this.integral = equation.first;\r
- this.initial = equation.second;\r
+ public Stock2(double x, double y, Variable2 variable) {\r
+ super(x, y, variable);\r
}\r
\r
public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
Resource stock = createVariable(graph, sr.Stock, parent);\r
-\r
- Resource expression = GraphUtils.create2(graph, sr.StockExpression,\r
- sr.StockExpression_integralEquation, integral,\r
- sr.StockExpression_initialEquation, initial,\r
- l0.PartOf, stock);\r
- // TODO: why is the expressoin stored in two places?\r
- graph.claim(stock, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expression)));\r
-\r
createSymbol(graph, sr.StockSymbol, stock, parent);\r
\r
setResource(stock);\r
}\r
+\r
+ @Override\r
+ public boolean supportsDependencies() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsFlows() {\r
+ return true;\r
+ }\r
\r
}\r
package org.simantics.sysdyn.modelImport.model;\r
\r
-public class Valve2 extends Element2 {\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class Valve2 extends ModelVariable {\r
\r
public enum Orientation {\r
HORIZONTAL, VERTICAL\r
INSIDE, BELOW, LEFT, ABOVE, RIGHT, UNSET\r
}\r
\r
- public Valve2(String equation, Orientation orientation, TextPosition position, String unit, Range range, String description) {\r
- \r
+ public Valve2(double x, double y, \r
+ String name, IExpression expression, Range range, String unit, String description) {\r
+ super(x, y, name, expression, range, unit, description);\r
+ }\r
+ \r
+ public Valve2(double x, double y, Variable2 variable) {\r
+ super(x, y, variable);\r
+ }\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource parent) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+ Resource valve = createVariable(graph, sr.Valve, parent);\r
+ createSymbol(graph, sr.ValveSymbol, valve, parent);\r
+\r
+ setResource(valve);\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsDependencies() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsFlows() {\r
+ return true;\r
}\r
\r
}\r
public class Variable2 {\r
\r
private String name;\r
- private String equation;\r
+ private IExpression expression;\r
private String unit;\r
+ private Range range;\r
private String description;\r
\r
- public Variable2(String name, String equation, String unit, String description) {\r
+ public Variable2(String name, IExpression expression, String unit, Range range, String description) {\r
this.name = name;\r
- this.equation = equation;\r
+ this.expression = expression;\r
this.unit = unit;\r
+ this.range = range;\r
this.description = description;\r
}\r
\r
return name;\r
}\r
\r
- public void setName(String name) {\r
- this.name = name;\r
+ public IExpression getExpression() {\r
+ return expression;\r
}\r
\r
- public String getEquation() {\r
- return equation;\r
- }\r
-\r
- public void setEquation(String equation) {\r
- this.equation = equation;\r
+ public Range getRange() {\r
+ return range;\r
}\r
\r
public String getUnit() {\r
return unit;\r
}\r
\r
- public void setUnit(String unit) {\r
- this.unit = unit;\r
- }\r
-\r
public String getDescription() {\r
return description;\r
}\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
+ \r
}\r