]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Finish cleanup of vensim import for release.
authorjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 30 May 2014 14:41:27 +0000 (14:41 +0000)
committerjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 30 May 2014 14:41:27 +0000 (14:41 +0000)
refs #2924

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29562 ac1ea38d-2e2b-0410-8846-a27921b304fc

26 files changed:
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlParser.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Declaration.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Lookup.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/MdlModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/MdlVariable.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Variable.java with 84% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Sketch.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchComment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchConnection.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchElement.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchObject.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchValve.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Subscript.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SubscriptVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Auxiliary.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Model.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Shadow.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Stock.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Valve.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Variable.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/ModelVariable.java with 86% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/support/Enumeration.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/support/Function.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/support/Range.java

index 58e73242ba7a3af3662f9e607732f9efc0672d29..e6c366275194717f3cb9b6985abb611483f57158 100644 (file)
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.importMdl"\r
-                  label="vensim import test"\r
+                  label="Vensim Model (.mdl)"\r
                   style="push">\r
             </command>\r
          </menu>\r
          </property>\r
          <property\r
                name="windowImages"\r
-               value="icons/simantics_sysdyn128.png">\r
+               value="icons/simantics_sysdyn16.png,icons/simantics_sysdyn32.png,icons/simantics_sysdyn48.png,icons/simantics_sysdyn64.png,icons/simantics_sysdyn128.png">\r
          </property>\r
          <property\r
                name="aboutText"\r
                value="%about.text">\r
          </property>\r
+         <property\r
+               name="aboutImage"\r
+               value="icons/simantics_sysdyn128.png">\r
+         </property>\r
       </product>\r
    </extension>\r
    <extension\r
index f580493a22614a25902866444c6a3ecdb8d4d38b..bd23088e94dc2cd93b858f4b282f319a657f47e0 100644 (file)
@@ -28,10 +28,11 @@ import org.simantics.sysdyn.modelImport.mdl.SketchValve;
 import org.simantics.sysdyn.modelImport.mdl.SketchVariable;\r
 import org.simantics.sysdyn.modelImport.mdl.Subscript;\r
 import org.simantics.sysdyn.modelImport.mdl.SubscriptVariable;\r
-import org.simantics.sysdyn.modelImport.mdl.Variable;\r
+import org.simantics.sysdyn.modelImport.mdl.MdlVariable;\r
+import org.simantics.sysdyn.modelImport.model.Comment;\r
 import org.simantics.sysdyn.modelImport.model.Connection;\r
 import org.simantics.sysdyn.modelImport.model.Model;\r
-import org.simantics.sysdyn.modelImport.model.ModelVariable;\r
+import org.simantics.sysdyn.modelImport.model.Variable;\r
 import org.simantics.sysdyn.modelImport.model.Shadow;\r
 import org.simantics.sysdyn.modelImport.model.Symbol;\r
 import org.simantics.sysdyn.modelImport.model.Valve;\r
@@ -54,12 +55,10 @@ public class MdlParser {
                // generate a sysdyn model from the mdl model\r
                Model model = new Model(mdl.getName());\r
 \r
-               double offset = 0;\r
-\r
                // add (necessary) enumerations\r
                for (Subscript subscript : mdl.getAllSubscripts()) {\r
                        if (!subscript.isEquivalent())\r
-                               model.addEnumeration(subscript.getEnumeration(mdl));\r
+                               model.addEnumeration(subscript.getEnumeration());\r
                }\r
                \r
                // add lookup functions\r
@@ -67,15 +66,19 @@ public class MdlParser {
                        model.addFunction(lookup.getFunction());\r
                }\r
                \r
+               int offset = 0;\r
+               \r
                // add sketch labels and independent elements\r
                for (Sketch sketch : mdl.getSketches()) {\r
                        \r
-                       sketch.setOffset(0, offset);\r
-\r
-                       //model.addSymbol(new Comment(0, offset, -1, -1, sketch.getName()));\r
+                       // add the sketch label to the diagram for the sake of clarity\r
+                       model.addSymbol(new Comment(\r
+                                       MdlUtil.getSysdynDimensions(offset, 0, -1, -1), \r
+                                       "========== VENSIM SKETCH: "+sketch.getName()+" =========="));\r
+                       sketch.setLocation(offset, 20);\r
                        \r
                        for (SketchComment comment : sketch.getComments()) {\r
-                               Symbol symbol = comment.getSymbol(mdl, sketch);\r
+                               Symbol symbol = comment.getSymbol();\r
                                if (symbol != null) {\r
                                        comment.setModelObject(symbol);\r
                                        model.addSymbol(symbol);\r
@@ -83,7 +86,7 @@ public class MdlParser {
                        }\r
                        \r
                        for (SketchValve valve : sketch.getValves()) {\r
-                               Valve symbol = valve.getSymbol(mdl, sketch);\r
+                               Valve symbol = valve.getSymbol();\r
                                if (symbol != null) {\r
                                        valve.setModelObject(symbol);\r
                                        model.addSymbol(symbol);\r
@@ -91,21 +94,21 @@ public class MdlParser {
                        }\r
                        \r
                        for (SketchVariable variable : sketch.getNonShadowVariables()) {\r
-                               ModelVariable symbol = variable.getSymbol(mdl, sketch);\r
+                               Variable symbol = variable.getSymbol();\r
                                if (symbol != null) {\r
                                        variable.setModelObject(symbol);\r
                                        model.addSymbol(symbol);\r
                                }\r
                        }\r
                        \r
-                       offset += 200;\r
+                       offset += sketch.getWidth();\r
                }\r
                \r
                // add dependent elements\r
                for (Sketch sketch : mdl.getSketches()) {\r
                        for (SketchVariable variable : sketch.getShadowVariables()) {\r
-                               ModelVariable original = model.getVariable(variable.getName());\r
-                               Symbol symbol = original != null ? new Shadow(variable.getDimensions(sketch), original) : variable.getSymbol(mdl, sketch);\r
+                               Variable original = model.getVariable(variable.getName());\r
+                               Symbol symbol = original != null ? new Shadow(variable.getDimensions(), original) : variable.getSymbol();\r
                                if (symbol != null) {\r
                                        variable.setModelObject(symbol);\r
                                        model.addSymbol(symbol);\r
@@ -113,7 +116,7 @@ public class MdlParser {
                        }\r
 \r
                        for (SketchConnection connection : sketch.getConnections()) {\r
-                               Connection conn = connection.getConnection(sketch);\r
+                               Connection conn = connection.getConnection();\r
                                if (conn != null) {\r
                                        connection.setModelObject(conn);\r
                                        model.addConnection(conn);\r
@@ -122,17 +125,26 @@ public class MdlParser {
                }\r
                \r
                // Set simulation parameters\r
-               Variable start = mdl.getVariable(PARAMETER_START);\r
+               MdlVariable start = mdl.getVariable(PARAMETER_START);\r
                if (start != null && Pattern.matches(MdlUtil.DBL, start.getExpressionString()))\r
                        model.setStart(Double.parseDouble(start.getExpressionString()));\r
                \r
-               Variable stop = mdl.getVariable(PARAMETER_STOP);\r
+               MdlVariable stop = mdl.getVariable(PARAMETER_STOP);\r
                if (stop != null && Pattern.matches(MdlUtil.DBL, stop.getExpressionString()))\r
                        model.setStop(Double.parseDouble(stop.getExpressionString()));\r
                \r
-               Variable step = mdl.getVariable(PARAMETER_STEP);\r
-               if (step != null && Pattern.matches(MdlUtil.DBL, step.getExpressionString()))\r
+               MdlVariable step = mdl.getVariable(PARAMETER_STEP);\r
+               if (step != null && Pattern.matches(MdlUtil.DBL, step.getExpressionString())) {\r
                        model.setStep(Double.parseDouble(step.getExpressionString()));\r
+                       // TODO: for some reason sysdyn only accepts certain time units\r
+                       // so this most definitely does not work in all cases\r
+                       String unit = step.getUnit();\r
+                       if (unit.contains("[")) {\r
+                               unit = unit.substring(0, unit.indexOf('[')).trim();\r
+                       }\r
+                       model.setUnit(unit.toLowerCase());\r
+               }\r
+               \r
                \r
                // TODO: unit and result step thingamajig\r
                \r
@@ -199,16 +211,16 @@ public class MdlParser {
                        if ((cat = Declaration.parseCategory(str)) != null) {\r
                                category = cat;\r
                        }\r
-                       else if ((decl = Variable.getPossible(str)) != null) {\r
-                               mdl.addVariable((Variable)decl, category);\r
+                       else if ((decl = MdlVariable.getPossible(str, mdl)) != null) {\r
+                               mdl.addVariable((MdlVariable)decl, category);\r
                        }\r
-                       else if ((decl = SubscriptVariable.getPossible(str)) != null) {\r
+                       else if ((decl = SubscriptVariable.getPossible(str, mdl)) != null) {\r
                                mdl.addSubscriptVariable((SubscriptVariable)decl, category);\r
                        }\r
-                       else if ((decl = Lookup.getPossible(str)) != null) {\r
+                       else if ((decl = Lookup.getPossible(str, mdl)) != null) {\r
                                mdl.addLookup((Lookup)decl);\r
                        }\r
-                       else if ((decl = Subscript.getPossible(str)) != null) {\r
+                       else if ((decl = Subscript.getPossible(str, mdl)) != null) {\r
                                mdl.addSubscript((Subscript)decl);\r
                        }\r
                        else {\r
@@ -237,7 +249,7 @@ public class MdlParser {
                        SketchObject so;\r
 \r
                        if (line.startsWith(SKETCH_START)) {\r
-                               sketch = new Sketch();\r
+                               sketch = new Sketch(mdl);\r
                                mdl.addSketch(sketch);\r
                        }\r
                        else if (line.startsWith(SKETCH_VERSION)) {\r
@@ -249,28 +261,30 @@ public class MdlParser {
                        else if (line.startsWith("$")) {\r
                                // font declaration, nothing to do here\r
                        }\r
-                       else if ((so = SketchConnection.getPossible(line)) != null) {\r
+                       else if ((so = SketchConnection.getPossible(line, sketch)) != null) {\r
                                sketch.addConnection((SketchConnection)so);\r
                        }\r
-                       else if ((so = SketchVariable.getPossible(line)) != null) {\r
+                       else if ((so = SketchVariable.getPossible(line, sketch)) != null) {\r
                                sketch.addVariable((SketchVariable)so);\r
                        }\r
-                       else if ((so = SketchValve.getPossible(line)) != null) {\r
+                       else if ((so = SketchValve.getPossible(line, sketch)) != null) {\r
                                SketchValve valve = (SketchValve)so;\r
                                // the next row after a valve should always the variable associated with the valve\r
-                               SketchVariable attached = SketchVariable.getPossible(reader.readLine());\r
+                               SketchVariable attached = SketchVariable.getPossible(reader.readLine(), sketch);\r
                                if (attached == null || !attached.isAttached()) {\r
                                        throw new Exception("attached variable not found for valve");\r
                                }\r
                                valve.setAttached(attached);\r
                                sketch.addValve(valve);\r
                        }\r
-                       else if ((so = SketchComment.getPossible(line)) != null) {\r
+                       else if ((so = SketchComment.getPossible(line, sketch)) != null) {\r
                                SketchComment comment = (SketchComment)so;\r
                                if (comment.hasTextLine()) {\r
                                        comment.setText(reader.readLine());\r
                                }\r
-                               sketch.addComment(comment);\r
+                               // do not add i/o objects to the sketch currently\r
+                               if (!comment.isInputOutput())\r
+                                       sketch.addComment(comment);\r
                        }\r
                        else {\r
                                // if we got this far, the element could not be parsed\r
index 819988aee2e515fcee4ad60f23408434b8dfcb4f..43babc2f5229ff6c9d2aca8b4a4c44d89e8b78da 100644 (file)
@@ -9,6 +9,9 @@ import org.simantics.sysdyn.modelImport.mdl.Lookup;
 import org.simantics.sysdyn.modelImport.mdl.MdlModel;\r
 \r
 public class MdlUtil {\r
+       \r
+       // multiplier for dimension conversion between vensim and sysdyn\r
+       private static final double SCALE_MULTIPLIER = 0.45;\r
 \r
        // most of this is based on the documentation of the .mdl file format \r
        // available in http://www.vensim.com/documentation/24305.htm\r
@@ -165,7 +168,7 @@ public class MdlUtil {
 \r
                                if (indices[i].endsWith("!")) {\r
                                        String subscript = indices[i].substring(0, indices[i].length() - 1);\r
-                                       List<String> values = mdl.getSubscript(subscript).getValues(mdl);\r
+                                       List<String> values = mdl.getSubscript(subscript).getValues();\r
                                        result.append('{');\r
                                        for (int j = 0; j < values.size(); j++) {\r
                                                if (j > 0)\r
@@ -284,4 +287,13 @@ public class MdlUtil {
 \r
                return list.toArray(new String[list.size()]);\r
        }\r
+       \r
+       public static double[] getSysdynDimensions(int x, int y, int width, int height) {\r
+               return new double[] {\r
+                               x * SCALE_MULTIPLIER,\r
+                               y * SCALE_MULTIPLIER,\r
+                               width * SCALE_MULTIPLIER,\r
+                               height * SCALE_MULTIPLIER\r
+               };\r
+       }\r
 }\r
index 45d1bb41c9212672641c83ab5c8d2ef2006e373e..4282a6dd0d50b7a0449fa2422bbfb0c39a18128c 100644 (file)
@@ -18,11 +18,14 @@ public abstract class Declaration {
        protected static final int declarationDescription = 2;\r
        \r
        private String name;\r
+       private MdlModel mdl;\r
+       \r
        private String unit;\r
        private String description;\r
        \r
-       protected Declaration(String name) {\r
+       protected Declaration(String name, MdlModel mdl) {\r
                this.name = name;\r
+               this.mdl = mdl;\r
        }\r
        \r
        protected void parseSuffix(String suffix) \r
@@ -42,6 +45,10 @@ public abstract class Declaration {
                return name;\r
        }\r
        \r
+       public MdlModel getMdl() {\r
+               return mdl;\r
+       }\r
+       \r
        public String getUnit() {\r
                return unit;\r
        }\r
index d6528be117455f15a64298907b9d48911df70508..cf0ff89458edad481e7926d0c83eed5be8facbc3 100644 (file)
@@ -33,8 +33,10 @@ public class Lookup extends Declaration {
        \r
        private Function function;\r
        \r
-       protected Lookup(String name, double xMin, double yMin, double xMax, double yMax, double[] points) {\r
-               super(name);\r
+       protected Lookup(String name, MdlModel mdl, \r
+                       double xMin, double yMin, double xMax, double yMax, \r
+                       double[] points) {\r
+               super(name, mdl);\r
                this.xMin = xMin;\r
                this.yMin = yMin;\r
                this.xMax = xMax;\r
@@ -42,7 +44,7 @@ public class Lookup extends Declaration {
                this.points = points;\r
        }\r
        \r
-       public static Lookup getPossible(String line) \r
+       public static Lookup getPossible(String line, MdlModel mdl\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(LOOKUP_DECL).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -56,7 +58,7 @@ public class Lookup extends Declaration {
                double yMax = Double.parseDouble(matcher.group(lookupRangeYMax));\r
                double[] points = parsePoints(matcher.group(lookupPoints));\r
                \r
-               Lookup lookup = new Lookup(name, xMin, yMin, xMax, yMax, points);\r
+               Lookup lookup = new Lookup(name, mdl, xMin, yMin, xMax, yMax, points);\r
                lookup.parseSuffix(matcher.group(lookupSuffix));\r
                return lookup;\r
        }\r
index 202dcad816bc355f1c415ba0e960ff3616502632..fba97c5ca36ca1cf930040b07321a7a1ee294ae5 100644 (file)
@@ -11,8 +11,8 @@ public class MdlModel {
        \r
        private String name;\r
        \r
-       private Map<String, Variable> variables;\r
-       private Map<String, ArrayList<Variable>> groups;\r
+       private Map<String, MdlVariable> variables;\r
+       private Map<String, ArrayList<MdlVariable>> groups;\r
        private Map<String, Lookup> lookups;\r
        private Map<String, Subscript> subscripts;\r
        private List<Sketch> sketches;\r
@@ -20,8 +20,8 @@ public class MdlModel {
        public MdlModel(String name) {\r
                this.name = name;\r
                \r
-               this.variables = new HashMap<String, Variable>();\r
-               this.groups = new HashMap<String, ArrayList<Variable>>();\r
+               this.variables = new HashMap<String, MdlVariable>();\r
+               this.groups = new HashMap<String, ArrayList<MdlVariable>>();\r
                this.lookups = new HashMap<String, Lookup>();\r
                this.subscripts = new HashMap<String, Subscript>();\r
                this.sketches = new ArrayList<Sketch>();\r
@@ -31,19 +31,25 @@ public class MdlModel {
                return name;\r
        }\r
        \r
-       public void addVariable(Variable variable, String group) \r
+       public void addVariable(MdlVariable variable, String group) \r
                        throws Exception {\r
                if (variables.get(variable.getName()) != null) {\r
                        throw new Exception("duplicate variable "+variable.getName());\r
                }\r
                \r
                variables.put(variable.getName(), variable);\r
-               addGroup(variable, group);\r
+               \r
+               if (group != null) {\r
+                       if (groups.get(group) == null) {\r
+                               groups.put(group, new ArrayList<MdlVariable>());\r
+                       }\r
+                       groups.get(group).add(variable);\r
+               }\r
        }\r
        \r
        public void addSubscriptVariable(SubscriptVariable variable, String group) \r
                        throws Exception {\r
-               Variable original = variables.get(variable.getName());\r
+               MdlVariable original = variables.get(variable.getName());\r
                if (original != null) {\r
                        if (!(original instanceof SubscriptVariable)) {\r
                                throw new Exception("incompatible type for variable "+variable.getName());\r
@@ -51,26 +57,16 @@ public class MdlModel {
                        ((SubscriptVariable)original).addSubscriptVariable(variable);\r
                }\r
                else {\r
-                       variables.put(variable.getName(), variable);\r
-                       addGroup(variable, group);\r
-               }\r
-       }\r
-       \r
-       private void addGroup(Variable variable, String group) {\r
-               if (group != null) {\r
-                       if (groups.get(group) == null) {\r
-                               groups.put(group, new ArrayList<Variable>());\r
-                       }\r
-                       groups.get(group).add(variable);\r
+                       addVariable(variable, group);\r
                }\r
        }\r
        \r
-       public Variable getVariable(String name) {\r
+       public MdlVariable getVariable(String name) {\r
                return variables.get(name);\r
        }\r
        \r
-       public Set<Variable> getAllVariables() {\r
-               return new HashSet<Variable>(variables.values());\r
+       public Set<MdlVariable> getAllVariables() {\r
+               return new HashSet<MdlVariable>(variables.values());\r
        }\r
        \r
        public void addLookup(Lookup lookup) \r
@@ -96,30 +92,24 @@ public class MdlModel {
                        throw new Exception("duplicate subscript "+subscript.getName());\r
                }\r
                \r
-               // TODO: check if a subscript with the same values already exists\r
-               \r
                subscripts.put(subscript.getName(), subscript);\r
        }\r
        \r
-       public Subscript getSubscript(String key) {\r
-               return subscripts.get(key);\r
+       public Subscript getSubscript(String name) {\r
+               return subscripts.get(name);\r
        }\r
        \r
        public Set<Subscript> getAllSubscripts() {\r
                return new HashSet<Subscript>(subscripts.values());\r
        }\r
        \r
-       public Subscript resolveSubscript(List<String> values) {\r
-               return resolveSubscript(new HashSet<String>(values));\r
-       }\r
-       \r
        public Subscript resolveSubscript(Set<String> values) {\r
-               // if one value is actually a subscript, expand it to its values\r
+               // if a value is actually a subscript, expand it to its values\r
                Set<String> all = new HashSet<String>();\r
                for (String value : values) {\r
                        Subscript potential = subscripts.get(value);\r
                        if (potential != null) {\r
-                               all.addAll(potential.getValues(this));\r
+                               all.addAll(potential.getValues());\r
                        }\r
                        else {\r
                                all.add(value);\r
@@ -129,7 +119,9 @@ public class MdlModel {
                // find the subscript that contains exactly the given set of values.\r
                // only consider original subscripts (ignore equivalent subscripts)\r
                for (Subscript subscript : getAllSubscripts()) {\r
-                       if (!subscript.isEquivalent() && subscript.getValues(this).containsAll(all) && all.containsAll(subscript.getValues(this))) {\r
+                       if (!subscript.isEquivalent() && \r
+                                       subscript.getValues().containsAll(all) && \r
+                                       all.containsAll(subscript.getValues())) {\r
                                return subscript;\r
                        }\r
                }\r
similarity index 84%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Variable.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/MdlVariable.java
index 25f21fa227ce36e60e82c91a78246a2f99d97ce2..6e45c926afb5eaafae9be634634c6a402b6a0824 100644 (file)
@@ -1,18 +1,17 @@
 package org.simantics.sysdyn.modelImport.mdl;\r
 \r
-import java.util.ArrayList;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
 import org.simantics.sysdyn.modelImport.MdlUtil;\r
-import org.simantics.sysdyn.modelImport.model.ModelVariable;\r
+import org.simantics.sysdyn.modelImport.model.Variable;\r
 import org.simantics.sysdyn.modelImport.model.expression.DelayExpression;\r
 import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 import org.simantics.sysdyn.modelImport.model.expression.IntegralExpression;\r
 import org.simantics.sysdyn.modelImport.model.expression.NormalExpression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
-public class Variable extends Declaration {\r
+public class MdlVariable extends Declaration {\r
        \r
        protected static final String EXPRESSION =\r
                        "(?:\\s*=\\s*([^~]*?(?:"+MdlUtil.SPECIAL_NAME+"[^~]*?)*))?";\r
@@ -25,12 +24,12 @@ public class Variable extends Declaration {
        \r
        private String expression;\r
        \r
-       protected Variable(String name, String expression) {\r
-               super(name);\r
+       protected MdlVariable(String name, MdlModel mdl, String expression) {\r
+               super(name, mdl);\r
                this.expression = expression;\r
        }\r
        \r
-       public static Variable getPossible(String line\r
+       public static MdlVariable getPossible(String line, MdlModel mdl\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(VARIABLE_DECL).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -42,7 +41,7 @@ public class Variable extends Declaration {
                if (expression != null)\r
                        expression = MdlUtil.normalize(expression);\r
                \r
-               Variable var = new Variable(name, expression);\r
+               MdlVariable var = new MdlVariable(name, mdl, expression);\r
                var.parseSuffix(matcher.group(variableSuffix));\r
                return var;\r
        }\r
@@ -51,11 +50,10 @@ public class Variable extends Declaration {
                return expression;\r
        }\r
        \r
-       public <T extends ModelVariable> T setUpModelVariable(T variable, \r
-                       double[] dimensions, MdlModel mdl) {\r
+       public <T extends Variable> T initVariable(T variable) {\r
                variable.setName(getName());\r
                if (expression != null)\r
-                       variable.setExpression(getExpression(mdl));\r
+                       variable.setExpression(getExpression());\r
                \r
                String unit = getUnit();\r
                Range range = parseRange(unit);\r
@@ -67,13 +65,11 @@ public class Variable extends Declaration {
                        variable.setRange(range);\r
                variable.setDescription(getDescription());\r
                \r
-               variable.setDimensions(dimensions);\r
-               \r
                return variable;\r
        }\r
        \r
-       public Expression getExpression(MdlModel mdl) {\r
-               return parseExpression(MdlUtil.finalize(expression, mdl));\r
+       public Expression getExpression() {\r
+               return parseExpression(MdlUtil.finalize(expression, getMdl()));\r
        }\r
        \r
        protected static Expression parseExpression(String expression) {\r
index cba3e0c907bca1d0fa87132922ddcd8d26818891..89f40f8786f266a149beb298c545d2c1c3bef1dc 100644 (file)
@@ -2,20 +2,21 @@ package org.simantics.sysdyn.modelImport.mdl;
 \r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
-import java.util.Iterator;\r
 import java.util.List;\r
 \r
-import org.simantics.sysdyn.modelImport.model.Symbol;\r
-\r
 public class Sketch {\r
        \r
+       private MdlModel mdl;\r
        private String name;\r
        \r
-       private boolean edgesOutOfDate;\r
-       public double topEdge = 0;\r
-       public double bottomEdge = 0;\r
-       public double leftEdge = 0;\r
-       public double rightEdge = 0;\r
+       private int xOffset = 0;\r
+       private int yOffset = 0;\r
+       \r
+       private boolean updateEdges;\r
+       private int topEdge = 0;\r
+       private int bottomEdge = 0;\r
+       private int leftEdge = 0;\r
+       private int rightEdge = 0;\r
 \r
        private List<SketchComment> comments;\r
        private List<SketchConnection> connections;\r
@@ -24,8 +25,10 @@ public class Sketch {
        \r
        private HashMap<Integer, SketchObject> objects;\r
        \r
-       public Sketch() {\r
-               edgesOutOfDate = true;\r
+       public Sketch(MdlModel mdl) {\r
+               this.mdl = mdl;\r
+               \r
+               updateEdges = true;\r
                \r
                comments = new ArrayList<SketchComment>();\r
                connections = new ArrayList<SketchConnection>();\r
@@ -35,6 +38,10 @@ public class Sketch {
                objects = new HashMap<Integer, SketchObject>();\r
        }\r
        \r
+       public MdlModel getMdl() {\r
+               return mdl;\r
+       }\r
+       \r
        public String getName() {\r
                return name;\r
        }\r
@@ -44,67 +51,49 @@ public class Sketch {
        }\r
        \r
        private void updateEdges() {\r
-//             if (edgesOutOfDate) {\r
-//                     boolean first = true;\r
-//                     for (SketchElement e : getAllElements()) {\r
-//                             topEdge    = first ? e.getSysdynTopEdge()    : Math.min(topEdge, e.getSysdynTopEdge());\r
-//                             bottomEdge = first ? e.getSysdynBottomEdge() : Math.max(bottomEdge, e.getSysdynBottomEdge());\r
-//                             leftEdge   = first ? e.getSysdynLeftEdge()   : Math.min(leftEdge, e.getSysdynLeftEdge());\r
-//                             rightEdge  = first ? e.getSysdynRightEdge()  : Math.max(rightEdge, e.getSysdynRightEdge());\r
-//                             first = false;\r
-//                     }\r
-//                     edgesOutOfDate = false;\r
-//             }\r
-       }\r
-       \r
-       public double getTopEdge() {\r
-               updateEdges();\r
-               return topEdge;\r
-       }\r
-       \r
-       public double getBottomEdge() {\r
-               updateEdges();\r
-               return bottomEdge;\r
-       }\r
-       \r
-       public double getLeftEdge() {\r
-               updateEdges();\r
-               return leftEdge;\r
-       }\r
-       \r
-       public double getRightEdge() {\r
-               updateEdges();\r
-               return rightEdge;\r
+               if (updateEdges) {\r
+                       boolean first = true;\r
+                       for (SketchElement e : getAllElements()) {\r
+                               topEdge    = first ? e.getTop()    : Math.min(topEdge, e.getTop() );\r
+                               bottomEdge = first ? e.getBottom() : Math.max(bottomEdge, e.getBottom());\r
+                               leftEdge   = first ? e.getLeft()   : Math.min(leftEdge, e.getLeft());\r
+                               rightEdge  = first ? e.getRight()  : Math.max(rightEdge, e.getRight());\r
+                               first = false;\r
+                       }\r
+                       updateEdges = false;\r
+               }\r
        }\r
        \r
-       public double getWidth() {\r
+       public int getWidth() {\r
                updateEdges();\r
                return rightEdge - leftEdge;\r
        }\r
        \r
-       public double getHeight() {\r
+       public int getHeight() {\r
                updateEdges();\r
                return bottomEdge - topEdge;\r
        }\r
        \r
-       public void setOffset(double horizontal, double vertical) {\r
-               hOffset = horizontal;\r
-               vOffset = vertical;\r
+       // sets the relative location of this sketch in the diagram \r
+       public void setLocation(int x, int y) {\r
+               xOffset = x;\r
+               yOffset = y;\r
        }\r
        \r
-       private double hOffset, vOffset;\r
-       \r
-       public double getHorizontalOffset() {\r
-               return hOffset;\r
+       public int getElementXOffset() {\r
+               updateEdges();\r
+               return -leftEdge + xOffset;\r
        }\r
        \r
-       public double getVerticalOffset() {\r
-               return vOffset;\r
+       public int getElementYOffset() {\r
+               updateEdges();\r
+               return -topEdge + yOffset;\r
        }\r
        \r
        public void addComment(SketchComment comment) {\r
                comments.add(comment);\r
                objects.put(comment.getId(), comment);\r
+               updateEdges = true;\r
        }\r
        \r
        public List<SketchComment> getComments() {\r
@@ -126,6 +115,7 @@ public class Sketch {
                // replace the attached variable with the valve in order to redirect \r
                // possible connections to the variable to the valve\r
                objects.put(valve.getAttached().getId(), valve);\r
+               updateEdges = true;\r
        }\r
        \r
        public List<SketchValve> getValves() {\r
@@ -135,6 +125,7 @@ public class Sketch {
        public void addVariable(SketchVariable variable) {\r
                variables.add(variable);\r
                objects.put(variable.getId(), variable);\r
+               updateEdges = true;\r
        }\r
        \r
        public List<SketchVariable> getVariables() {\r
index e0d0eb13f6249c540b8aacc0ea448e9f72729ea6..3c4b23845fc6d9e0858dd41c8ff8a29db81be804 100644 (file)
@@ -22,12 +22,12 @@ public class SketchComment extends SketchElement {
        private String text;\r
        private CommentIcon icon;\r
 \r
-       protected SketchComment(int id, CommentIcon icon) {\r
-               super(id);\r
+       protected SketchComment(int id, Sketch sketch, CommentIcon icon) {\r
+               super(id, sketch);\r
                this.icon = icon;\r
        }\r
        \r
-       public static SketchComment getPossible(String line) \r
+       public static SketchComment getPossible(String line, Sketch sketch\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(SKETCH_COMMENT).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -42,7 +42,7 @@ public class SketchComment extends SketchElement {
                default: icon = CommentIcon.OTHER; break;\r
                }\r
                \r
-               SketchComment element = new SketchComment(id, icon);\r
+               SketchComment element = new SketchComment(id, sketch, icon);\r
                element.parseSuffix(matcher.group(commentSuffix));\r
                return element;\r
        }\r
@@ -60,13 +60,13 @@ public class SketchComment extends SketchElement {
        }\r
        \r
        @Override\r
-       public Symbol getSymbol(MdlModel mdl, Sketch sketch) {\r
+       public Symbol getSymbol() {\r
                if (isInputOutput())\r
                        return new Comment(getDimensions(), "I/O objects are not supported");\r
                \r
                switch(icon) {\r
-               case CLOUD: return new Cloud(getDimensions(sketch));\r
-               case OTHER: return new Comment(getDimensions(sketch), text);\r
+               case CLOUD: return new Cloud(getDimensions());\r
+               case OTHER: return new Comment(getDimensions(), text);\r
                default: return null;\r
                }\r
        }\r
index cd20a7b0aca35b5770141ddd18f37ef06fd77d09..e1fe384a77b289e7865facf723805518ada57a0b 100644 (file)
@@ -42,15 +42,15 @@ public class SketchConnection extends SketchObject {
        private ConnectionType type;\r
        int[] points;\r
 \r
-       protected SketchConnection(int id, int from, int to, ConnectionType type, int[] points) {\r
-               super(id);\r
+       protected SketchConnection(int id, Sketch sketch, int from, int to, ConnectionType type, int[] points) {\r
+               super(id, sketch);\r
                this.from = from;\r
                this.to = to;\r
                this.type = type;\r
                this.points = points;\r
        }\r
        \r
-       public static SketchConnection getPossible(String line) \r
+       public static SketchConnection getPossible(String line, Sketch sketch\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(SKETCH_CONNECTION).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -75,7 +75,7 @@ public class SketchConnection extends SketchObject {
                \r
                int[] points = parsePoints(matcher.group(connectionPoints));\r
                \r
-               return new SketchConnection(id, from, to, type, points);\r
+               return new SketchConnection(id, sketch, from, to, type, points);\r
        }\r
        \r
        private static int[] parsePoints(String str) {\r
@@ -108,18 +108,18 @@ public class SketchConnection extends SketchObject {
                return points;\r
        }\r
 \r
-       public Connection getConnection(Sketch sketch) {\r
-               Symbol tail = (Symbol)sketch.getObject(from).getModelObject();\r
+       public Connection getConnection() {\r
+               Symbol tail = (Symbol)getSketch().getObject(from).getModelObject();\r
                if (tail == null) {\r
                        return null;\r
                }\r
-               Symbol head = (Symbol)sketch.getObject(to).getModelObject();\r
+               Symbol head = (Symbol)getSketch().getObject(to).getModelObject();\r
                if (head == null) {\r
                        return null;\r
                }\r
                \r
                switch (type) {\r
-               case ARROW:        return new Dependency(tail, head, true, false, getAngle(sketch));\r
+               case ARROW:        return new Dependency(tail, head, true, false, getAngle(getSketch()));\r
                case LINE_ARROW:   return new Flow(tail, head);\r
                case LINE_SEGMENT: return new Flow(head, tail);\r
                default: return null;\r
index 3507db92c57b364d49d846871fd6b6d382e12a85..ab4eae9e60830be949fcf0c80297ea439fb6c393 100644 (file)
@@ -3,14 +3,12 @@ package org.simantics.sysdyn.modelImport.mdl;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
+import org.simantics.sysdyn.modelImport.MdlUtil;\r
 import org.simantics.sysdyn.modelImport.model.Symbol;\r
 import org.simantics.sysdyn.modelImport.model.Valve.TextPosition;\r
 \r
 public abstract class SketchElement extends SketchObject {\r
        \r
-       // multiplier for dimension conversion between vensim and sysdyn\r
-       private static final double SCALE_MULTIPLIER = 0.4;\r
-       \r
        // each sketch element is declared with a string:\r
        // n,id,name,x,y,w,h,sh,bits,hid,hasf,tpos,bw,nav1,nav2(,box,fill,font)\r
        \r
@@ -41,8 +39,8 @@ public abstract class SketchElement extends SketchObject {
        private boolean textLine;\r
        private TextPosition textPosition;\r
 \r
-       protected SketchElement(int id) {\r
-               super(id);\r
+       protected SketchElement(int id, Sketch sketch) {\r
+               super(id, sketch);\r
        }\r
        \r
        protected void parseSuffix(String suffix) \r
@@ -91,6 +89,22 @@ public abstract class SketchElement extends SketchObject {
                return height;\r
        }\r
        \r
+       public int getTop() {\r
+               return getY() - getHeight();\r
+       }\r
+       \r
+       public int getBottom() {\r
+               return getY() + getHeight();\r
+       }\r
+       \r
+       public int getLeft() {\r
+               return getX() - getWidth();\r
+       }\r
+       \r
+       public int getRight() {\r
+               return getX() + getWidth();\r
+       }\r
+       \r
        public boolean isAttached() {\r
                return attached;\r
        }\r
@@ -115,23 +129,16 @@ public abstract class SketchElement extends SketchObject {
                return textPosition;\r
        }\r
 \r
-       public abstract Symbol getSymbol(MdlModel mdl, Sketch sketch);\r
-       \r
-       public double[] getDimensions(Sketch sketch) {\r
-               double[] dimensions = getDimensions();\r
-               dimensions[0] = dimensions[0] + sketch.getHorizontalOffset();\r
-               dimensions[1] = dimensions[1] + sketch.getVerticalOffset();\r
-               return dimensions;\r
-       }\r
+       public abstract Symbol getSymbol();\r
        \r
-       // get element dimensions [x, y, width, height]\r
+       // get sysdyn dimensions for element [x, y, width, height]\r
        public double[] getDimensions() {\r
-               double[] dimensions = new double[4];\r
-               dimensions[0] = (getX() - getWidth()) * SCALE_MULTIPLIER;\r
-               dimensions[1] = (getY() - getHeight()) * SCALE_MULTIPLIER;\r
-               dimensions[2] = getWidth() * 2 * SCALE_MULTIPLIER;\r
-               dimensions[3] = getHeight() * 2 * SCALE_MULTIPLIER;\r
-               return dimensions;\r
+               return MdlUtil.getSysdynDimensions(\r
+                               getLeft() + getSketch().getElementXOffset(),\r
+                               getTop() + getSketch().getElementYOffset(),\r
+                               getWidth() * 2,\r
+                               getHeight() * 2\r
+                               );\r
        }\r
        \r
 }\r
index 2ddb1e4c3fb6f2933d2f48be06c5d5c2ed17799e..a4c2ac472ea763889a6e62456955f55a8e95881e 100644 (file)
@@ -11,16 +11,23 @@ public abstract class SketchObject {
        protected static final String SKIP_ANY = "[^,]*,";\r
 \r
        private int id;\r
+       private Sketch sketch;\r
+       \r
        private IWriteableObject modelObject;\r
        \r
-       protected SketchObject(int id) {\r
+       protected SketchObject(int id, Sketch sketch) {\r
                this.id = id;\r
+               this.sketch = sketch;\r
        }\r
        \r
        public int getId() {\r
                return id;\r
        }\r
        \r
+       public Sketch getSketch() {\r
+               return sketch;\r
+       }\r
+       \r
        public void setModelObject(IWriteableObject modelObject) {\r
                this.modelObject = modelObject;\r
        }\r
index f9d5bd381b40aae8c56765646e77097866e8400f..7f3853142558f7319ec2eeb9bc61113c3e3cf4e0 100644 (file)
@@ -15,11 +15,11 @@ public class SketchValve extends SketchElement {
        \r
        private SketchVariable attached;\r
        \r
-       protected SketchValve(int id) {\r
-               super(id);\r
+       protected SketchValve(int id, Sketch sketch) {\r
+               super(id, sketch);\r
        }\r
        \r
-       public static SketchValve getPossible(String line) \r
+       public static SketchValve getPossible(String line, Sketch sketch\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(SKETCH_VALVE).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -28,7 +28,7 @@ public class SketchValve extends SketchElement {
                \r
                int id = Integer.parseInt(matcher.group(valveId));\r
                \r
-               SketchValve element = new SketchValve(id);\r
+               SketchValve element = new SketchValve(id, sketch);\r
                element.parseSuffix(matcher.group(valveSuffix));\r
                return element;\r
        }\r
@@ -42,15 +42,16 @@ public class SketchValve extends SketchElement {
        }\r
        \r
        @Override\r
-       public Valve getSymbol(MdlModel mdl, Sketch sketch) {\r
-               Variable variable = mdl.getVariable(attached.getName());\r
+       public Valve getSymbol() {\r
+               MdlVariable variable = getSketch().getMdl().getVariable(attached.getName());\r
                if (variable == null) {\r
                        return null;\r
                }\r
                \r
                Valve valve = new Valve(Orientation.HORIZONTAL, getTextPosition());\r
+               valve.setDimensions(getDimensions());\r
                \r
-               return variable.setUpModelVariable(valve, getDimensions(sketch), mdl);\r
+               return variable.initVariable(valve);\r
        }\r
 \r
 }\r
index f6f3a1f059ea29193f4300d983604cd929a85dad..9bcbeba810edfa90666476da5c014f00482c74c6 100644 (file)
@@ -5,10 +5,8 @@ import java.util.regex.Pattern;
 \r
 import org.simantics.sysdyn.modelImport.MdlUtil;\r
 import org.simantics.sysdyn.modelImport.model.Auxiliary;\r
-import org.simantics.sysdyn.modelImport.model.ModelVariable;\r
+import org.simantics.sysdyn.modelImport.model.Variable;\r
 import org.simantics.sysdyn.modelImport.model.Stock;\r
-import org.simantics.sysdyn.modelImport.model.Symbol;\r
-import org.simantics.sysdyn.modelImport.model.expression.IntegralExpression;\r
 \r
 public class SketchVariable extends SketchElement {\r
        \r
@@ -20,12 +18,12 @@ public class SketchVariable extends SketchElement {
        \r
        private String name;\r
 \r
-       protected SketchVariable(int id, String name) {\r
-               super(id);\r
+       protected SketchVariable(int id, Sketch sketch, String name) {\r
+               super(id, sketch);\r
                this.name = name;\r
        }\r
        \r
-       public static SketchVariable getPossible(String line) \r
+       public static SketchVariable getPossible(String line, Sketch sketch\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(SKETCH_VARIABLE).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -35,7 +33,7 @@ public class SketchVariable extends SketchElement {
                int id = Integer.parseInt(matcher.group(variableId));\r
                String name = MdlUtil.normalize(matcher.group(variableName));\r
                \r
-               SketchVariable element = new SketchVariable(id, name);\r
+               SketchVariable element = new SketchVariable(id, sketch, name);\r
                element.parseSuffix(matcher.group(variableSuffix));\r
                return element;\r
        }\r
@@ -45,20 +43,20 @@ public class SketchVariable extends SketchElement {
        }\r
        \r
        @Override\r
-       public ModelVariable getSymbol(MdlModel mdl, Sketch sketch) {\r
-               Variable variable = mdl.getVariable(name);\r
+       public Variable getSymbol() {\r
+               MdlVariable variable = getSketch().getMdl().getVariable(name);\r
                if (variable == null) {\r
                        return null;\r
                }\r
                \r
-               ModelVariable var;\r
-               \r
+               Variable var;\r
                if (variable.getExpressionString() != null && variable.getExpressionString().startsWith("INTEG"))\r
                        var = new Stock();\r
                else\r
                        var = new Auxiliary();\r
+               var.setDimensions(getDimensions());\r
                \r
-               return variable.setUpModelVariable(var, getDimensions(sketch), mdl);\r
+               return variable.initVariable(var);\r
        }\r
        \r
 }
\ No newline at end of file
index 820a608ffccd60f29c3d2eae66bd275b1f17e433..c6b4a940d24717380bed75b23217dcbd64adb7fc 100644 (file)
@@ -1,9 +1,7 @@
 package org.simantics.sysdyn.modelImport.mdl;\r
 \r
 import java.util.Arrays;\r
-import java.util.HashSet;\r
 import java.util.List;\r
-import java.util.Set;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
@@ -24,19 +22,19 @@ public class Subscript extends Declaration {
        \r
        private Enumeration enumeration;\r
        \r
-       protected Subscript(String name, List<String> values) {\r
-               super(name);\r
+       protected Subscript(String name, MdlModel mdl, List<String> values) {\r
+               super(name, mdl);\r
                this.original = null;\r
                this.values = values;\r
        }\r
        \r
-       protected Subscript(String name, String original) {\r
-               super(name);\r
+       protected Subscript(String name, MdlModel mdl, String original) {\r
+               super(name, mdl);\r
                this.original = original;\r
                this.values = null;\r
        }\r
        \r
-       public static Subscript getPossible(String line) \r
+       public static Subscript getPossible(String line, MdlModel mdl\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(SUBSCRIPT_DECL).matcher(line);                \r
                if (!matcher.matches())\r
@@ -48,9 +46,9 @@ public class Subscript extends Declaration {
                \r
                Subscript subscript;\r
                if (equivalent)\r
-                       subscript = new Subscript(name, expression);\r
+                       subscript = new Subscript(name, mdl, expression);\r
                else\r
-                       subscript = new Subscript(name, Arrays.asList(expression.split(",")));\r
+                       subscript = new Subscript(name, mdl, Arrays.asList(expression.split(",")));\r
                subscript.parseSuffix(matcher.group(subscriptSuffix));\r
                return subscript;\r
        }\r
@@ -59,20 +57,20 @@ public class Subscript extends Declaration {
                return original;\r
        }\r
        \r
-       public List<String> getValues(MdlModel mdl) {\r
+       public List<String> getValues() {\r
                if (values != null)\r
                        return values;\r
                else\r
-                       return mdl.getSubscript(original).getValues(mdl);\r
+                       return getMdl().getSubscript(original).getValues();\r
        }\r
        \r
        public boolean isEquivalent() {\r
                return original != null;\r
        }\r
        \r
-       public Enumeration getEnumeration(MdlModel mdl) {\r
+       public Enumeration getEnumeration() {\r
                if (enumeration == null) {\r
-                       enumeration = new Enumeration(getName(), getValues(mdl));\r
+                       enumeration = new Enumeration(getName(), getValues());\r
                }\r
                \r
                return enumeration;\r
index 23bf744e23df5de9704695ce9897a14887f7902c..2bbe092ba93eea1286c517447f7560fde9f21db1 100644 (file)
@@ -15,7 +15,7 @@ import org.simantics.sysdyn.modelImport.model.expression.EnumerationExpression;
 import org.simantics.sysdyn.modelImport.model.expression.NormalExpression;\r
 import org.simantics.sysdyn.modelImport.model.support.Enumeration;\r
 \r
-public class SubscriptVariable extends Variable {\r
+public class SubscriptVariable extends MdlVariable {\r
        \r
        // a subscript variable is a variable that has a different equation\r
        // depending on the value of the subscript it references\r
@@ -29,13 +29,13 @@ public class SubscriptVariable extends Variable {
        private String[] indices;\r
        private SubscriptVariable next;\r
        \r
-       protected SubscriptVariable(String name, String expression, String[] indices) {\r
-               super(name, expression);\r
+       protected SubscriptVariable(String name, MdlModel mdl, String expression, String[] indices) {\r
+               super(name, mdl, expression);\r
                this.indices = indices;\r
                this.next = null;\r
        }\r
        \r
-       public static SubscriptVariable getPossible(String line) \r
+       public static SubscriptVariable getPossible(String line, MdlModel mdl\r
                        throws Exception {\r
                Matcher matcher = Pattern.compile(SUBSCRIPT_VARIABLE_DECL).matcher(line);\r
                if (!matcher.matches()) {\r
@@ -48,7 +48,7 @@ public class SubscriptVariable extends Variable {
                if (expression != null)\r
                        expression = MdlUtil.normalize(expression);\r
                \r
-               SubscriptVariable subVar = new SubscriptVariable(name, expression, indices);\r
+               SubscriptVariable subVar = new SubscriptVariable(name, mdl, expression, indices);\r
                subVar.parseSuffix(matcher.group(subscriptVariableSuffix));\r
                return subVar;\r
        }\r
@@ -74,7 +74,7 @@ public class SubscriptVariable extends Variable {
        }\r
        \r
        @Override\r
-       public EnumerationExpression getExpression(MdlModel mdl) {\r
+       public EnumerationExpression getExpression() {\r
                SubscriptVariable var;\r
                \r
                // find out what subscripts the combined expression uses by collecting\r
@@ -101,7 +101,7 @@ public class SubscriptVariable extends Variable {
                \r
                List<Enumeration> enumerations = new ArrayList<Enumeration>();\r
                for (Set<String> values : subscripts) {\r
-                       Subscript potential = mdl.resolveSubscript(values);\r
+                       Subscript potential = getMdl().resolveSubscript(values);\r
                        if (potential == null) {\r
                                System.err.println("subscript indices could not be resolved ");\r
                                for (String value : values) {\r
@@ -109,42 +109,15 @@ public class SubscriptVariable extends Variable {
                                }\r
                                System.err.println();\r
                        }\r
-                       enumerations.add(potential.getEnumeration(mdl));\r
+                       enumerations.add(potential.getEnumeration());\r
                }\r
                \r
                EnumerationExpression expr = new EnumerationExpression(enumerations);\r
                \r
-               // populate the created expression (TODO: comment)\r
+               // populate the created expression\r
                \r
-               // TODO: is this check correct, also does not work correctly yet\r
+               // TODO: is this check correct?\r
                if (next == null && enumerations.size() == 2) {\r
-                       // option a:\r
-//                     StringBuilder buffer = new StringBuilder();\r
-//                     buffer.append('{');\r
-//                     for (int i = 0; i < values.length; i++) {\r
-//                             if (i > 0) {\r
-//                                     buffer.append(',');\r
-//                             }\r
-//                             buffer.append('{');\r
-//                             for (int j = 0; j < values[i].length; j++) {\r
-//                                     if (j > 0) {\r
-//                                             buffer.append(',');\r
-//                                     }\r
-//                                     buffer.append(values[i][j]);\r
-//                             }\r
-//                             buffer.append('}');\r
-//                     }\r
-//                     buffer.append('}');\r
-//\r
-//                     String[] exprindices = new String[enumerations.size()];\r
-//                     for (int i = 0; i < exprindices.length; i++) {\r
-//                             exprindices[i] = enumerations.get(i).getName();\r
-//                     }\r
-//\r
-//                     expr.addExpression(new NormalExpression(buffer.toString()), exprindices);\r
-//                     return expr;\r
-                       \r
-                       // option b: (probably more sensible)\r
                        double[][] values = getPossibleValueArray(getExpressionString());\r
                        if (values != null) {\r
                                for (int i = 0; i < values.length; i++) {\r
@@ -169,9 +142,9 @@ public class SubscriptVariable extends Variable {
                                int limit = workqueue.size();\r
                                for (int j = 0; j < limit; j++) {\r
                                        WorkExpression current = workqueue.pollFirst();\r
-                                       Subscript potential = mdl.getSubscript(current.indices[i]);\r
+                                       Subscript potential = getMdl().getSubscript(current.indices[i]);\r
                                        if (potential != null) {\r
-                                               for (String value : potential.getValues(mdl)) {\r
+                                               for (String value : potential.getValues()) {\r
                                                        String[] newindices = Arrays.copyOf(current.indices, current.indices.length);\r
                                                        newindices[i] = value;\r
                                                        String newexpression = current.expression;\r
@@ -186,8 +159,8 @@ public class SubscriptVariable extends Variable {
                        }\r
                        \r
                        for (WorkExpression we : workqueue) {\r
-                               // TODO: is this check correct\r
-                               String expression = MdlUtil.finalize(we.expression, mdl);\r
+                               String expression = MdlUtil.finalize(we.expression, getMdl());\r
+                               // TODO: is this check correct?\r
                                if (next == null) {\r
                                        expression = removeComparisons(expression, indices, we.indices);\r
                                }\r
index 871d2106271756cf8f23d148fb94776ee4bff45f..73d2e280ecec98f6cd0ff2abce94c6ab565f9ffb 100644 (file)
@@ -6,7 +6,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
-public class Auxiliary extends ModelVariable {\r
+public class Auxiliary extends Variable {\r
        \r
        public Auxiliary() {\r
                \r
index 65cc051dd18449136895deb9ba5b23adf710f216..7f1326a834e67900da7bd40ab6cbe1ca3f6c3b4f 100644 (file)
@@ -14,6 +14,8 @@ package org.simantics.sysdyn.modelImport.model;
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
@@ -32,39 +34,30 @@ public class Model implements IWriteableObject {
        \r
        private String name;\r
        // necessary simulation parameters\r
-       private double start, stop, step;\r
+       private Double start, stop, step;\r
        private String unit;\r
        \r
        // the structure of the model\r
-       private HashMap<String, ModelVariable> variables;\r
-       private HashMap<String, Enumeration> enumerations;\r
-       private HashMap<String, Function> functions;\r
+       private Map<String, Variable> variables;\r
+       private Map<String, Enumeration> enumerations;\r
+       private Map<String, Function> functions;\r
        \r
-       private ArrayList<Symbol> symbols;\r
-       private ArrayList<Shadow> shadows;\r
-       private ArrayList<Connection> connections;\r
+       private List<Symbol> symbols;\r
+       private List<Shadow> shadows;\r
+       private List<Connection> connections;\r
        \r
        private Resource model;\r
        \r
        public Model(String name) {\r
                this.name = name;\r
                \r
-               variables = new HashMap<String, ModelVariable>();\r
+               variables = new HashMap<String, Variable>();\r
                enumerations = new HashMap<String, Enumeration>();\r
                functions = new HashMap<String, Function>();\r
                \r
                symbols = new ArrayList<Symbol>();\r
                shadows = new ArrayList<Shadow>();\r
                connections = new ArrayList<Connection>();\r
-               \r
-               this.start = 0;\r
-               this.stop = 100;\r
-               this.step = 1;\r
-               this.unit = null;\r
-       }\r
-       \r
-       public void setParameters(double start, double stop, double step, String unit) {\r
-               \r
        }\r
 \r
        public double getStart() {\r
@@ -91,7 +84,15 @@ public class Model implements IWriteableObject {
                this.step = step;\r
        }\r
        \r
-       public void addSymbol(ModelVariable variable) {\r
+       public String getUnit() {\r
+               return unit;\r
+       }\r
+       \r
+       public void setUnit(String unit) {\r
+               this.unit = unit;\r
+       }\r
+       \r
+       public void addSymbol(Variable variable) {\r
                if (variables.get(variable.getName()) != null) {\r
                        System.err.println("variable "+variable.getName()+" already defined");\r
                }\r
@@ -102,11 +103,11 @@ public class Model implements IWriteableObject {
                symbols.add(variable);\r
        }\r
        \r
-       public ModelVariable getVariable(String name) {\r
+       public Variable getVariable(String name) {\r
                return variables.get(name);\r
        }\r
        \r
-       public Collection<ModelVariable> getVariables() {\r
+       public Collection<Variable> getVariables() {\r
                return variables.values();\r
        }\r
        \r
@@ -166,10 +167,14 @@ public class Model implements IWriteableObject {
                \r
                // TODO: this must be updated if/when simulation parameters are moved \r
                // from model to experiment\r
-               //graph.claimLiteral(model, sr.SysdynModel_startTime, start, Bindings.DOUBLE);\r
-               //graph.claimLiteral(model, sr.SysdynModel_stopTime, stop, Bindings.DOUBLE);\r
-               //graph.claimLiteral(model, sr.SysdynModel_simulationStepLength, step, Bindings.DOUBLE);\r
-               //graph.claimLiteral(model, sr.SysdynModel_timeUnit, unit, Bindings.STRING);\r
+               if (start != null)\r
+                       graph.claimLiteral(model, sr.SysdynModel_startTime, start, Bindings.DOUBLE);\r
+               if (stop != null)\r
+                       graph.claimLiteral(model, sr.SysdynModel_stopTime, stop, Bindings.DOUBLE);\r
+               if (step != null)\r
+                       graph.claimLiteral(model, sr.SysdynModel_simulationStepLength, step, Bindings.DOUBLE);\r
+               if (unit != null)\r
+                       graph.claimLiteral(model, sr.SysdynModel_timeUnit, unit, Bindings.STRING);\r
                \r
                Resource configuration = graph.getSingleObject(model, sim.HasConfiguration);\r
                \r
index 2e7d2689cb6e4c05e08aa201fc90d8a3096e8db6..228b5099dd32a4452d70efae694b3fa28ba86ab7 100644 (file)
@@ -11,7 +11,7 @@ import org.simantics.sysdyn.SysdynResource;
 \r
 public class Shadow extends Symbol {\r
 \r
-       private ModelVariable original;\r
+       private Variable original;\r
        \r
        private Resource shadow;\r
        \r
@@ -19,20 +19,20 @@ public class Shadow extends Symbol {
                \r
        }\r
        \r
-       public Shadow(ModelVariable original) {\r
+       public Shadow(Variable original) {\r
                this.original = original;\r
        }\r
        \r
-       public Shadow(double[] dim, ModelVariable original) {\r
+       public Shadow(double[] dim, Variable original) {\r
                super(dim);\r
                this.original = original;\r
        }\r
 \r
-       public ModelVariable getOriginal() {\r
+       public Variable getOriginal() {\r
                return original;\r
        }\r
 \r
-       public void setOriginal(ModelVariable original) {\r
+       public void setOriginal(Variable original) {\r
                this.original = original;\r
        }\r
 \r
index 76842a2d4817d0abf5c2abfe0f7372d39b1667e6..1e658ed8a3e5a8c70994925c11b47aa8b74eaa62 100644 (file)
@@ -6,7 +6,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.modelImport.model.expression.IntegralExpression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
-public class Stock extends ModelVariable {\r
+public class Stock extends Variable {\r
        \r
        public Stock() {\r
                \r
index 9a84e09491d5f34fdc8597a67f189635eb0ebcf4..011b3c1508fc3096269ba054a2d7a49094c713fd 100644 (file)
@@ -8,7 +8,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
-public class Valve extends ModelVariable {\r
+public class Valve extends Variable {\r
        \r
        public enum Orientation {\r
                HORIZONTAL, VERTICAL\r
similarity index 86%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/ModelVariable.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Variable.java
index 5e64585da13bbe545197da49e7685dc51c6357d7..c29b46bcf76d6d02909fba348914883c51d919f7 100644 (file)
@@ -12,7 +12,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
-public abstract class ModelVariable extends Symbol {\r
+public abstract class Variable extends Symbol {\r
 \r
        private String name;\r
        private Expression expression;\r
@@ -22,11 +22,11 @@ public abstract class ModelVariable extends Symbol {
        \r
        private Resource variable;\r
        \r
-       public ModelVariable() {\r
+       public Variable() {\r
                \r
        }\r
        \r
-       public ModelVariable(String name, Expression expression, Range range, String unit, String description) {\r
+       public Variable(String name, Expression expression, Range range, String unit, String description) {\r
                this.name = name;\r
                this.expression = expression;\r
                this.range = range;\r
@@ -34,7 +34,7 @@ public abstract class ModelVariable extends Symbol {
                this.description = description;\r
        }\r
 \r
-       public ModelVariable(double[] dim, String name, Expression expression, Range range, String unit, String description) {\r
+       public Variable(double[] dim, String name, Expression expression, Range range, String unit, String description) {\r
                super(dim);\r
                this.name = name;\r
                this.expression = expression;\r
index c3246adc35343cca9c0090d8bcf4c34dc07c5499..bfccc31fec928e7fd28341790158b8e70c881c37 100644 (file)
@@ -54,7 +54,7 @@ public class EnumerationExpression extends Expression {
                // write array index list\r
                graph.claim(parent, sr.Variable_arrayIndexesList, ListUtils.create(graph, indexlist));\r
                \r
-               // set active expression?\r
+               // TODO: set active expression?\r
                \r
                return getResource();\r
        }\r
index 5ea53010fe417aa578688f2604693e4a44698604..2a6e8e924a3d86bb759cac670ce33abac265b1fd 100644 (file)
@@ -1,9 +1,7 @@
 package org.simantics.sysdyn.modelImport.model.support;\r
 \r
 import java.util.ArrayList;\r
-import java.util.HashSet;\r
 import java.util.List;\r
-import java.util.Set;\r
 \r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
index 8aa761f17a3ce00417f99b62d6f7a0a187a8f10a..9f17087e42c06d2162e9c1333a89a88c522b4301 100644 (file)
@@ -1,7 +1,5 @@
 package org.simantics.sysdyn.modelImport.model.support;\r
 \r
-import java.util.List;\r
-\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
@@ -54,6 +52,8 @@ public class Function implements IWriteableObject {
                        graph.claimLiteral(function, l0.HasDescription, body, Bindings.STRING);\r
                }\r
                \r
+               // TODO: should alco handle inputs and outputs somehow\r
+               \r
                return function;\r
        }\r
 \r
index e28c6b68471908d4c238017774e82d19949acbab..bfcf236fb2a1d82cbd1ad1ce2bc86134225ae2d6 100644 (file)
@@ -34,6 +34,7 @@ public class Range implements IWriteableObject {
 \r
        @Override\r
        public Resource write(WriteGraph graph, Resource variable, WriteContext context) throws DatabaseException {\r
+               // TODO: implementation\r
                return null;\r
        }\r
        \r