--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+ <classpathentry kind="src" path="src"/>\r
+ <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
--- /dev/null
+syntax: regexp\r
+^bin/\r
+\r
+syntax: glob\r
+*.svn/*
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+ <name>org.simantics.sysdyn</name>\r
+ <comment></comment>\r
+ <projects>\r
+ </projects>\r
+ <buildSpec>\r
+ <buildCommand>\r
+ <name>org.eclipse.jdt.core.javabuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ <buildCommand>\r
+ <name>org.eclipse.pde.ManifestBuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ <buildCommand>\r
+ <name>org.eclipse.pde.SchemaBuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ </buildSpec>\r
+ <natures>\r
+ <nature>org.eclipse.pde.PluginNature</nature>\r
+ <nature>org.eclipse.jdt.core.javanature</nature>\r
+ </natures>\r
+</projectDescription>\r
--- /dev/null
+#Mon Nov 16 15:37:44 EET 2009\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.6\r
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Sysdyn
+Bundle-SymbolicName: org.simantics.sysdyn
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
+ org.simantics.db;bundle-version="0.6.2"
+Export-Package: org.simantics.sysdyn,
+ org.simantics.sysdyn.modelica,
+ org.simantics.sysdyn.representation,
+ org.simantics.sysdyn.representation.visitors
--- /dev/null
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+ .\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn;\r
+\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class SysdynResource {\r
+ \r
+ public final Resource Auxiliary;\r
+ public final Resource Cloud;\r
+ public final Resource Configuration;\r
+ public final Resource Dependency;\r
+ public final Resource Flow;\r
+ public final Resource HasAngle;\r
+ public final Resource HasHead;\r
+ public final Resource HasTail;\r
+ public final Resource HasValue;\r
+ public final Resource HasX;\r
+ public final Resource HasY;\r
+ public final Resource IndependentVariable;\r
+ public final Resource IsHeadOf;\r
+ public final Resource IsTailOf;\r
+ public final Resource Stock;\r
+ public final Resource SysdynProject;\r
+ public final Resource Valve;\r
+ public final Resource Variable;\r
+ \r
+ public static class URIs {\r
+ public static final String Auxiliary = "http://www.simantics.org/Sysdyn#Auxiliary";\r
+ public static final String Cloud = "http://www.simantics.org/Sysdyn#Cloud";\r
+ public static final String Configuration = "http://www.simantics.org/Sysdyn#Configuration";\r
+ public static final String Dependency = "http://www.simantics.org/Sysdyn#Dependency";\r
+ public static final String Flow = "http://www.simantics.org/Sysdyn#Flow";\r
+ public static final String HasAngle = "http://www.simantics.org/Sysdyn#HasAngle";\r
+ public static final String HasHead = "http://www.simantics.org/Sysdyn#HasHead";\r
+ public static final String HasTail = "http://www.simantics.org/Sysdyn#HasTail";\r
+ public static final String HasValue = "http://www.simantics.org/Sysdyn#HasValue";\r
+ public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
+ public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
+ public static final String IndependentVariable = "http://www.simantics.org/Sysdyn#IndependentVariable";\r
+ public static final String IsHeadOf = "http://www.simantics.org/Sysdyn#IsHeadOf";\r
+ public static final String IsTailOf = "http://www.simantics.org/Sysdyn#IsTailOf";\r
+ public static final String Stock = "http://www.simantics.org/Sysdyn#Stock";\r
+ public static final String SysdynProject = "http://www.simantics.org/Sysdyn#SysdynProject";\r
+ public static final String Valve = "http://www.simantics.org/Sysdyn#Valve";\r
+ public static final String Variable = "http://www.simantics.org/Sysdyn#Variable";\r
+ }\r
+ \r
+ public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
+ try {\r
+ return graph.getResourceByURI(uri);\r
+ } catch(DatabaseException e) {\r
+ System.err.println(e.getMessage());\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ public SysdynResource(ReadGraph graph) {\r
+ Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
+ Cloud = getResourceOrNull(graph, URIs.Cloud);\r
+ Configuration = getResourceOrNull(graph, URIs.Configuration);\r
+ Dependency = getResourceOrNull(graph, URIs.Dependency);\r
+ Flow = getResourceOrNull(graph, URIs.Flow);\r
+ HasAngle = getResourceOrNull(graph, URIs.HasAngle);\r
+ HasHead = getResourceOrNull(graph, URIs.HasHead);\r
+ HasTail = getResourceOrNull(graph, URIs.HasTail);\r
+ HasValue = getResourceOrNull(graph, URIs.HasValue);\r
+ HasX = getResourceOrNull(graph, URIs.HasX);\r
+ HasY = getResourceOrNull(graph, URIs.HasY);\r
+ IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
+ IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf);\r
+ IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
+ Stock = getResourceOrNull(graph, URIs.Stock);\r
+ SysdynProject = getResourceOrNull(graph, URIs.SysdynProject);\r
+ Valve = getResourceOrNull(graph, URIs.Valve);\r
+ Variable = getResourceOrNull(graph, URIs.Variable);\r
+ }\r
+ \r
+ public static SysdynResource getInstance(ReadGraph graph) {\r
+ Session session = graph.getSession();\r
+ SysdynResource ret = session.getService(SysdynResource.class);\r
+ if(ret == null) {\r
+ ret = new SysdynResource(graph);\r
+ session.registerService(SysdynResource.class, ret);\r
+ }\r
+ return ret;\r
+ }\r
+ \r
+}\r
+\r
--- /dev/null
+package org.simantics.sysdyn.modelica;\r
+\r
+import org.simantics.sysdyn.representation.Auxiliary;\r
+import org.simantics.sysdyn.representation.Configuration;\r
+import org.simantics.sysdyn.representation.IElement;\r
+import org.simantics.sysdyn.representation.Stock;\r
+import org.simantics.sysdyn.representation.Valve;\r
+import org.simantics.sysdyn.representation.visitors.ElementVisitorVoidAdapter;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+public class ModelicaWriter {\r
+\r
+ StringBuilder b;\r
+ \r
+ IElementVisitorVoid componentWriter = new ElementVisitorVoidAdapter() {\r
+ public void visit(Auxiliary auxiliary) {\r
+ b.append(" Real ").append(escape(auxiliary.name)).append(";\n");\r
+ }\r
+ public void visit(Stock stock) {\r
+ b.append(" Real ").append(escape(stock.name)).append(";\n");\r
+ } \r
+ public void visit(Valve valve) {\r
+ // TODO\r
+ }\r
+ };\r
+ \r
+ IElementVisitorVoid equationWriter = new ElementVisitorVoidAdapter() {\r
+ public void visit(Auxiliary auxiliary) {\r
+ b.append(" ").append(escape(auxiliary.name))\r
+ .append(" = ").append(auxiliary.value).append(";\n");\r
+ }\r
+ public void visit(Stock stock) {\r
+ } \r
+ public void visit(Valve valve) {\r
+ }\r
+ };\r
+ \r
+ public void write(Configuration conf) {\r
+ conf.update();\r
+ b.append("model ").append(conf.name).append('\n');\r
+ for(IElement element : conf.elements)\r
+ element.accept(componentWriter);\r
+ b.append("equation\n");\r
+ for(IElement element : conf.elements)\r
+ element.accept(equationWriter);\r
+ b.append("end ").append(conf.name).append(";\n");\r
+ }\r
+ \r
+ public String escape(String name) {\r
+ return name;\r
+ }\r
+ \r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Auxiliary")\r
+public class Auxiliary extends Variable {\r
+ // TODO\r
+ public String value;\r
+\r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Cloud")\r
+public class Cloud implements IElement {\r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.representation.visitors.ElementVisitorVoidAdapter;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Configuration")\r
+public class Configuration {\r
+ @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasName")\r
+ public String name = "Unnamed";\r
+ \r
+ @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#ConsistsOf")\r
+ public ArrayList<IElement> elements = new ArrayList<IElement>();\r
+ \r
+ IElementVisitorVoid clearVisitor = new ElementVisitorVoidAdapter() {\r
+ public void visit(Stock stock) {\r
+ stock.incomingFlows.clear();\r
+ stock.outgoingFlows.clear();\r
+ }\r
+ };\r
+ \r
+ IElementVisitorVoid updateVisitor = new ElementVisitorVoidAdapter() {\r
+ public void visit(Flow flow) {\r
+ if(flow.head instanceof Stock) {\r
+ ((Stock)flow.head).incomingFlows.add((Variable)flow.tail);\r
+ }\r
+ else if(flow.tail instanceof Stock) {\r
+ ((Stock)flow.tail).outgoingFlows.add((Variable)flow.head);\r
+ }\r
+ }\r
+ };\r
+ \r
+ public void update() {\r
+ for(IElement element : elements)\r
+ element.accept(clearVisitor);\r
+ for(IElement element : elements)\r
+ element.accept(updateVisitor);\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Cloud")\r
+public class Dependency implements IElement {\r
+ @RelatedElement("http://www.simantics.org/Sysdyn#HasTail")\r
+ public IElement tail;\r
+ @RelatedElement("http://www.simantics.org/Sysdyn#HasHead")\r
+ public IElement head;\r
+ \r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Cloud")\r
+public class Flow implements IElement {\r
+ @RelatedElement("http://www.simantics.org/Sysdyn#HasTail")\r
+ public IElement tail;\r
+ @RelatedElement("http://www.simantics.org/Sysdyn#HasHead")\r
+ public IElement head;\r
+ \r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+public interface IElement {\r
+ void accept(IElementVisitorVoid v);\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Stock")\r
+public class Stock extends Variable {\r
+ public ArrayList<Variable> incomingFlows = new ArrayList<Variable>(2);\r
+ public ArrayList<Variable> outgoingFlows = new ArrayList<Variable>(2);\r
+ \r
+ public Stock() {\r
+ name = "Valve" + hashCode(); // FIXME\r
+ }\r
+ \r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+}\r
+\r
+\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Valve")\r
+public class Valve implements IElement {\r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+\r
+public abstract class Variable implements IElement {\r
+ @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasName")\r
+ public String name;\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation.visitors;\r
+\r
+import org.simantics.sysdyn.representation.Auxiliary;\r
+import org.simantics.sysdyn.representation.Cloud;\r
+import org.simantics.sysdyn.representation.Dependency;\r
+import org.simantics.sysdyn.representation.Flow;\r
+import org.simantics.sysdyn.representation.Stock;\r
+import org.simantics.sysdyn.representation.Valve;\r
+\r
+public class ElementVisitorVoidAdapter implements IElementVisitorVoid {\r
+\r
+ @Override\r
+ public void visit(Auxiliary auxiliary) {\r
+ }\r
+\r
+ @Override\r
+ public void visit(Stock stock) {\r
+ }\r
+\r
+ @Override\r
+ public void visit(Valve valve) {\r
+ }\r
+\r
+ @Override\r
+ public void visit(Cloud cloud) {\r
+ }\r
+\r
+ @Override\r
+ public void visit(Dependency dependency) {\r
+ }\r
+\r
+ @Override\r
+ public void visit(Flow flow) {\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation.visitors;\r
+\r
+import org.simantics.sysdyn.representation.Auxiliary;\r
+import org.simantics.sysdyn.representation.Cloud;\r
+import org.simantics.sysdyn.representation.Dependency;\r
+import org.simantics.sysdyn.representation.Flow;\r
+import org.simantics.sysdyn.representation.Stock;\r
+import org.simantics.sysdyn.representation.Valve;\r
+\r
+public interface IElementVisitorVoid {\r
+\r
+ void visit(Auxiliary auxiliary);\r
+ void visit(Stock stock);\r
+ void visit(Valve valve);\r
+ void visit(Cloud cloud);\r
+ void visit(Dependency dependency);\r
+ void visit(Flow flow); \r
+ \r
+}\r