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

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

30 files changed:
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java
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/IMdlObject.java [deleted file]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/Lookup.java
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/Variable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Auxiliary.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Auxiliary.java with 89% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Cloud.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Cloud.java with 87% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Comment.java with 87% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Connection.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Connection.java with 90% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Dependency.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Dependency.java with 91% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Flow.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Flow.java with 87% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Model.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/ModelVariable.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/ModelVariable.java with 92% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Shadow.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Shadow.java with 89% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Stock.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Stock.java with 89% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Symbol.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Symbol.java with 88% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Valve.java [moved from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Valve.java with 91% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/WriteContext.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/support/Function.java

index ae11a1fadde44179eca15b0c82cbfeb79c1b0315..8d35a4ea6ecc76fe547f9fd88bd276446a2fc5cc 100644 (file)
@@ -68,7 +68,7 @@ public class ImportMdlHandler extends AbstractHandler {
                // Convert Vensim model to Simantics SysDyn format using MdlParser\r
                final Model model;\r
                try {\r
-               model = MdlParser.parse(file);\r
+                       model = MdlParser.parse(file);\r
                }\r
                catch (Exception e) {\r
                        e.printStackTrace();\r
@@ -76,7 +76,6 @@ public class ImportMdlHandler extends AbstractHandler {
                }\r
                \r
                SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                       \r
                        @Override\r
                        public void perform(WriteGraph graph) throws DatabaseException {\r
                                model.write(graph, project, new WriteContext());\r
index 94bf2f7d30f2581c1799c2eccc994d9dba64a183..93766ed45e7c21e676f993d1a0240696deb080d7 100644 (file)
@@ -179,10 +179,18 @@ public class WizardMdlImportPage extends WizardPage{
                \r
                File file = new File(selected);\r
                \r
-               final Model model = MdlParser.parse(file);\r
+               // TODO: is this wizard actually used anywhere?\r
+               final Model model;\r
+               \r
+               try {\r
+                       model = MdlParser.parse(file);\r
+               }\r
+               catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       return false;\r
+               }\r
                \r
                SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                       \r
                        @Override\r
                        public void perform(WriteGraph graph) throws DatabaseException {\r
                                model.write(graph, project, new WriteContext());\r
index b60deac540107ee70ca4f98b549511e2eeed820c..f580493a22614a25902866444c6a3ecdb8d4d38b 100644 (file)
@@ -15,6 +15,7 @@ import java.io.BufferedReader;
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.InputStreamReader;\r
+import java.util.regex.Pattern;\r
 \r
 import org.simantics.sysdyn.modelImport.mdl.Declaration;\r
 import org.simantics.sysdyn.modelImport.mdl.Lookup;\r
@@ -28,44 +29,44 @@ import org.simantics.sysdyn.modelImport.mdl.SketchVariable;
 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.model.Connection;\r
 import org.simantics.sysdyn.modelImport.model.Model;\r
-import org.simantics.sysdyn.modelImport.model.element.Connection;\r
-import org.simantics.sysdyn.modelImport.model.element.ModelVariable;\r
-import org.simantics.sysdyn.modelImport.model.element.Symbol;\r
-import org.simantics.sysdyn.modelImport.model.element.Shadow;\r
-import org.simantics.sysdyn.modelImport.model.element.Valve;\r
+import org.simantics.sysdyn.modelImport.model.ModelVariable;\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
 \r
 public class MdlParser {\r
+       \r
+       private static final String UTF_8 = "{UTF-8}";\r
+       private static final String SKETCH_VERSION = "V300";\r
+       private static final String SKETCH_START = "\\\\\\---///";\r
+       private static final String SKETCH_END = "///---\\\\\\";\r
+       \r
+       private static final String PARAMETER_START = "INITIAL TIME";\r
+       private static final String PARAMETER_STOP = "FINAL TIME";\r
+       private static final String PARAMETER_STEP = "TIME STEP";\r
 \r
-       public static Model parse(File file) {\r
+       public static Model parse(File file) throws Exception {\r
                // generate a mdl model based on the contents of the file\r
-               MdlModel mdl;\r
-               try {\r
-                       mdl = parseFile(file);\r
-               }\r
-               catch (Exception e) {\r
-                       e.printStackTrace();\r
-                       return null;\r
-               }\r
-               \r
-               System.err.println("model parsed");\r
+               MdlModel mdl = parseFile(file);\r
                \r
                // generate a sysdyn model from the mdl model\r
-               \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
                }\r
                \r
+               // add lookup functions\r
                for (Lookup lookup : mdl.getAllLookups()) {\r
                        model.addFunction(lookup.getFunction());\r
                }\r
                \r
-               try {\r
                // add sketch labels and independent elements\r
                for (Sketch sketch : mdl.getSketches()) {\r
                        \r
@@ -100,17 +101,10 @@ public class MdlParser {
                        offset += 200;\r
                }\r
                \r
-               }\r
-               catch (NullPointerException e) {\r
-                       e.printStackTrace();\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
-                               if (original == null)\r
-                                       System.err.println("original variable not found for "+variable.getName());\r
                                Symbol symbol = original != null ? new Shadow(variable.getDimensions(sketch), original) : variable.getSymbol(mdl, sketch);\r
                                if (symbol != null) {\r
                                        variable.setModelObject(symbol);\r
@@ -128,20 +122,24 @@ public class MdlParser {
                }\r
                \r
                // Set simulation parameters\r
+               Variable 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
+               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
+                       model.setStep(Double.parseDouble(step.getExpressionString()));\r
+               \r
+               // TODO: unit and result step thingamajig\r
                \r
-               System.err.println("DONE");\r
-\r
                return model;\r
        }\r
        \r
-       private static final String UTF_8 = "{UTF-8}";\r
-       private static final String SKETCH_VERSION = "V300";\r
-       private static final String SKETCH_START = "\\\\\\---///";\r
-       private static final String SKETCH_END = "///---\\\\\\";\r
-       \r
-       private static MdlModel parseFile(File file) \r
-                       throws Exception {\r
-               \r
+       private static MdlModel parseFile(File file) throws Exception {\r
                // strip the file suffix from file name\r
                String name = file.getName();\r
                if (file.getName().contains(".")) {\r
@@ -181,8 +179,13 @@ public class MdlParser {
                        // combine the (possible) variable declaration into one line    \r
                        StringBuilder buffer = new StringBuilder();\r
                        do {\r
+                               // strip leading whitespace if present\r
+                               line = line.replaceFirst("^\\s*", "");\r
                                // strip trailing '\' if present\r
-                               buffer.append(line.endsWith("\\") ? line.substring(0, line.length()-1) : line);\r
+                               line = line.replaceFirst("\\\\$", "");\r
+                               \r
+                               buffer.append(line);\r
+                               \r
                                // each variable declaration ends with '|'\r
                                if (line.endsWith("|"))\r
                                        break;\r
@@ -190,25 +193,23 @@ public class MdlParser {
                        String str = buffer.toString();\r
 \r
                        String cat;\r
-                       Variable var;\r
-                       Lookup lookup;\r
-                       Subscript subscript;\r
+                       Declaration decl;\r
                        \r
                        // parse the (possible) variable declaration\r
                        if ((cat = Declaration.parseCategory(str)) != null) {\r
                                category = cat;\r
                        }\r
-                       else if ((var = Variable.getPossible(str)) != null) {\r
-                               mdl.addVariable(var, category);\r
+                       else if ((decl = Variable.getPossible(str)) != null) {\r
+                               mdl.addVariable((Variable)decl, category);\r
                        }\r
-                       else if ((var = SubscriptVariable.getPossible(str)) != null) {\r
-                               mdl.addSubscriptVariable((SubscriptVariable)var, category);\r
+                       else if ((decl = SubscriptVariable.getPossible(str)) != null) {\r
+                               mdl.addSubscriptVariable((SubscriptVariable)decl, category);\r
                        }\r
-                       else if ((lookup = Lookup.getPossible(str)) != null) {\r
-                               mdl.addLookup(lookup);\r
+                       else if ((decl = Lookup.getPossible(str)) != null) {\r
+                               mdl.addLookup((Lookup)decl);\r
                        }\r
-                       else if ((subscript = Subscript.getPossible(str)) != null) {\r
-                               mdl.addSubscript(subscript);\r
+                       else if ((decl = Subscript.getPossible(str)) != null) {\r
+                               mdl.addSubscript((Subscript)decl);\r
                        }\r
                        else {\r
                                // if we got this far, the variable could not be parsed\r
index b3546407c80ecc934675d8846b1168820eb30c5d..819988aee2e515fcee4ad60f23408434b8dfcb4f 100644 (file)
@@ -9,16 +9,16 @@ import org.simantics.sysdyn.modelImport.mdl.Lookup;
 import org.simantics.sysdyn.modelImport.mdl.MdlModel;\r
 \r
 public class MdlUtil {\r
-       \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
-       \r
+\r
        // some regular expressions that are used commonly in the parser\r
-       public static final String DBL = "-?\\d+(?:\\.\\d+)?";\r
+       public static final String DBL = "[+-]?(?:NaN|Infinity|\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)";\r
        public static final String DBL_G = "("+DBL+")";\r
-       public static final String INT = "-?\\d+";\r
+       public static final String INT = "[+-]?\\d+";\r
        public static final String INT_G = "("+INT+")";\r
-       \r
+\r
        // matches a basic vensim name (starts with a letter, may contain any word \r
        // characters and white space)\r
        public static final String BASIC_NAME =\r
@@ -27,10 +27,10 @@ public class MdlUtil {
        // may contain escaped special characters)\r
        public static final String SPECIAL_NAME =\r
                        "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"";\r
-       \r
+\r
        // matches a vensim variable (either basic name or special name)\r
        public static final String VARIABLE =\r
-                               "("+BASIC_NAME+"|"+SPECIAL_NAME+")";\r
+                       "("+BASIC_NAME+"|"+SPECIAL_NAME+")";\r
        // matches a vensim variable inside an expression (basic name not followed \r
        // by an open parenthesis or a special name)\r
        public static final String VARIABLE_EXPRESSION =\r
@@ -41,7 +41,7 @@ public class MdlUtil {
        // matches a vensim function (basic name followed by an open parenthesis)\r
        public static final String FUNCTION =\r
                        "("+BASIC_NAME+")\\s*\\(";\r
-       \r
+\r
        public static String normalize(String str) {\r
                // start by removing all tabs from the string, not really necessary \r
                // but does make the equation cleaner\r
@@ -51,14 +51,14 @@ public class MdlUtil {
                str = normalizeFunctions(str);\r
                // normalize variables\r
                str = normalizeVariables(str);\r
-               \r
+\r
                // replace inline operations\r
                str = str.replaceAll(":AND:", " and ");\r
                str = str.replaceAll(":OR:", " or ");\r
 \r
                return str;\r
        }\r
-       \r
+\r
        private static String normalizeVariables(String expression) {\r
                StringBuilder result = new StringBuilder();\r
                int offset = 0;\r
@@ -68,7 +68,7 @@ public class MdlUtil {
                        result.append(expression.substring(offset, matcher.start()));\r
 \r
                        String variable = matcher.group(1);\r
-                       \r
+\r
                        if (variable.equalsIgnoreCase("time")) {\r
                                result.append("time");\r
                        }\r
@@ -90,16 +90,16 @@ public class MdlUtil {
                                        result.append(parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1));\r
                                }\r
                        }\r
-                       \r
+\r
                        offset = matcher.end();\r
                }\r
                if (offset < expression.length()) {\r
                        result.append(expression.substring(offset));\r
                }\r
-               \r
+\r
                return result.toString();\r
        }\r
-       \r
+\r
        private static String normalizeFunctions(String expression) {\r
                StringBuilder result = new StringBuilder();\r
                int offset = 0;\r
@@ -109,7 +109,7 @@ public class MdlUtil {
                        result.append(expression.substring(offset, matcher.start()));\r
 \r
                        String function = matcher.group(1);\r
-                       \r
+\r
                        if (function.equalsIgnoreCase("sum")) {\r
                                // vensim "sum" is similar to modelica "sum" if operations \r
                                // are replaced with dot-operations (e.g. * with .*) inside\r
@@ -134,17 +134,17 @@ public class MdlUtil {
                if (offset < expression.length()) {\r
                        result.append(expression.substring(offset));\r
                }\r
-               \r
+\r
                return result.toString();\r
        }\r
-       \r
+\r
        public static String finalize(String expression, MdlModel mdl) {\r
                expression = expandIterations(expression, mdl);\r
                expression = renameLookups(expression, mdl);\r
-               \r
+\r
                return expression;\r
        }\r
-       \r
+\r
        private static String expandIterations(String expression, MdlModel mdl) {\r
                StringBuilder result = new StringBuilder();\r
                int offset = 0;\r
@@ -152,17 +152,17 @@ public class MdlUtil {
                Matcher matcher = Pattern.compile(SUBSCRIPT).matcher(expression);\r
                while (matcher.find()) {\r
                        result.append(expression.substring(offset, matcher.start()));\r
-                       \r
+\r
                        String name = matcher.group(1);\r
                        String[] indices = matcher.group(2).split(",");\r
-                       \r
+\r
                        result.append(name);\r
-                       \r
+\r
                        result.append('[');\r
                        for (int i = 0; i < indices.length; i++) {\r
                                if (i > 0)\r
                                        result.append(',');\r
-                               \r
+\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
@@ -179,16 +179,16 @@ public class MdlUtil {
                                }\r
                        }\r
                        result.append(']');\r
-                       \r
+\r
                        offset = matcher.end();\r
                }\r
                if (offset < expression.length()) {\r
                        result.append(expression.substring(offset));\r
                }\r
-               \r
+\r
                return result.toString();\r
        }\r
-       \r
+\r
        private static String renameLookups(String expression, MdlModel mdl) {\r
                StringBuilder result = new StringBuilder();\r
                int offset = 0;\r
@@ -198,42 +198,41 @@ public class MdlUtil {
                        result.append(expression.substring(offset, matcher.start()));\r
 \r
                        String name = matcher.group(1);\r
-                       \r
+\r
                        Lookup potential = mdl.getLookup(name);\r
-                       \r
+\r
                        if (potential != null) {\r
-                               System.err.println("found lookup "+name);\r
                                name = name.replaceAll("\\s+", "");\r
                        }\r
-                       \r
+\r
                        result.append(name+"(");\r
                        offset = matcher.end();\r
                }\r
                if (offset < expression.length()) {\r
                        result.append(expression.substring(offset));\r
                }\r
-               \r
+\r
                return result.toString();\r
        }\r
-       \r
+\r
        public static String replaceSubscripts(String expression, String subscript, String replacement) {\r
                StringBuilder result = new StringBuilder();\r
                int offset = 0;\r
-               \r
+\r
                Matcher matcher = Pattern.compile(SUBSCRIPT).matcher(expression);\r
                while (matcher.find()) {\r
                        result.append(expression.substring(offset, matcher.start()));\r
-                       \r
+\r
                        String name = matcher.group(1);\r
                        String[] indices = matcher.group(2).split(",");\r
-                       \r
+\r
                        result.append(name);\r
-                       \r
+\r
                        result.append('[');\r
                        for (int i = 0; i < indices.length; i++) {\r
                                if (i > 0)\r
                                        result.append(',');\r
-                               \r
+\r
                                if (indices[i].equals(subscript)) {\r
                                        result.append(replacement);\r
                                }\r
@@ -242,16 +241,16 @@ public class MdlUtil {
                                }\r
                        }\r
                        result.append(']');\r
-                       \r
+\r
                        offset = matcher.end();\r
                }\r
                if (offset < expression.length()) {\r
                        result.append(expression.substring(offset));\r
                }\r
-               \r
+\r
                return result.toString();\r
        }\r
-       \r
+\r
        public static String[] splitFunctionParameters(String str) {\r
                ArrayList<String> list = new ArrayList<String>();\r
 \r
@@ -260,7 +259,7 @@ public class MdlUtil {
                int level = 0;\r
                boolean comment = false;\r
                boolean brackets = false;\r
-               \r
+\r
                for (i = 0; i < str.length(); i++) {\r
                        char current = str.charAt(i);\r
                        if (current == '"')\r
@@ -282,7 +281,7 @@ public class MdlUtil {
                if (last < i) {\r
                        list.add(str.substring(last, i).trim());\r
                }\r
-               \r
+\r
                return list.toArray(new String[list.size()]);\r
        }\r
 }\r
index 4c3a1e1e1542fc4c46ae224336469fce8571afc9..45d1bb41c9212672641c83ab5c8d2ef2006e373e 100644 (file)
@@ -5,7 +5,7 @@ import java.util.regex.Pattern;
 \r
 public abstract class Declaration {\r
 \r
-       private static final String CATEGORY = "\\*{56}\\s*\\.(\\S+)\\s*\\*{56}.*";\r
+       private static final String CATEGORY = "\\*{56}\\s*\\.(.+)\\s*\\*{56}.*";\r
        \r
        protected static final String DECL_DELIM = "\\s*~\\s*";\r
        protected static final String DECL_END = "\\s*\\|";\r
@@ -52,7 +52,7 @@ public abstract class Declaration {
 \r
        public static String parseCategory(String line) {\r
                Matcher matcher = Pattern.compile(CATEGORY).matcher(line);\r
-               return matcher.matches() ? matcher.group(1) : null;\r
+               return matcher.matches() ? matcher.group(1).trim() : null;\r
        }\r
 \r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/IMdlObject.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/IMdlObject.java
deleted file mode 100644 (file)
index cfa4129..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.simantics.sysdyn.modelImport.mdl;\r
-\r
-public interface IMdlObject {\r
-       \r
-}\r
index b166a32d816a1e723bc7039104a97d4b6b537dec..d6528be117455f15a64298907b9d48911df70508 100644 (file)
@@ -4,7 +4,6 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;\r
 \r
 import org.simantics.sysdyn.modelImport.MdlUtil;\r
-import org.simantics.sysdyn.modelImport.model.expression.LookupExpression;\r
 import org.simantics.sysdyn.modelImport.model.support.Function;\r
 \r
 public class Lookup extends Declaration {\r
@@ -17,7 +16,7 @@ public class Lookup extends Declaration {
                        "("+MdlUtil.BASIC_NAME+")\\s*\\(\\s*"+LOOKUP_RANGE+","+LOOKUP_POINTS+"\\s*\\)";\r
        \r
        private static final String LOOKUP_DECL = \r
-                       LOOKUP+"("+DECL_SUFFIX+")";     \r
+                       LOOKUP+"("+DECL_SUFFIX+")";\r
        private static final int lookupName = 1;\r
        private static final int lookupRangeXMin = 2;\r
        private static final int lookupRangeYMin = 3;\r
@@ -34,8 +33,6 @@ public class Lookup extends Declaration {
        \r
        private Function function;\r
        \r
-       // TODO: generate functions from lookup variables\r
-\r
        protected Lookup(String name, double xMin, double yMin, double xMax, double yMax, double[] points) {\r
                super(name);\r
                this.xMin = xMin;\r
index 865f8da2692e7710c5226c07cc7ffb10a07fd0c4..cba3e0c907bca1d0fa87132922ddcd8d26818891 100644 (file)
@@ -5,7 +5,7 @@ import java.util.HashMap;
 import java.util.Iterator;\r
 import java.util.List;\r
 \r
-import org.simantics.sysdyn.modelImport.model.element.Symbol;\r
+import org.simantics.sysdyn.modelImport.model.Symbol;\r
 \r
 public class Sketch {\r
        \r
index 8cae21d9c1af4121c49c565c67445dbd97f5af86..e0d0eb13f6249c540b8aacc0ea448e9f72729ea6 100644 (file)
@@ -3,9 +3,9 @@ package org.simantics.sysdyn.modelImport.mdl;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-import org.simantics.sysdyn.modelImport.model.element.Cloud;\r
-import org.simantics.sysdyn.modelImport.model.element.Comment;\r
-import org.simantics.sysdyn.modelImport.model.element.Symbol;\r
+import org.simantics.sysdyn.modelImport.model.Cloud;\r
+import org.simantics.sysdyn.modelImport.model.Comment;\r
+import org.simantics.sysdyn.modelImport.model.Symbol;\r
 \r
 public class SketchComment extends SketchElement {\r
        \r
index 74cb1bf70a912f8e0041f1d1cb3b145c6719416f..cd20a7b0aca35b5770141ddd18f37ef06fd77d09 100644 (file)
@@ -3,11 +3,10 @@ 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.element.Connection;\r
-import org.simantics.sysdyn.modelImport.model.element.Dependency;\r
-import org.simantics.sysdyn.modelImport.model.element.Symbol;\r
-import org.simantics.sysdyn.modelImport.model.element.Flow;\r
+import org.simantics.sysdyn.modelImport.model.Connection;\r
+import org.simantics.sysdyn.modelImport.model.Dependency;\r
+import org.simantics.sysdyn.modelImport.model.Flow;\r
+import org.simantics.sysdyn.modelImport.model.Symbol;\r
 \r
 public class SketchConnection extends SketchObject {\r
        \r
@@ -15,11 +14,6 @@ public class SketchConnection extends SketchObject {
                ARROW, LINE_ARROW, LINE_SEGMENT, OTHER\r
        }\r
        \r
-       // some shorthands\r
-       private static final String KEEP_I = MdlUtil.INT_G+",";\r
-       private static final String SKIP_I = MdlUtil.INT+",";\r
-       private static final String SKIP_ANY = "[^,]*,";\r
-       \r
        private static final String POINTS = "(\\d+\\|(?:\\(-?\\d+,-?\\d+\\)\\|)+)";\r
        \r
        // each sketch connection is declared with a string:\r
@@ -132,7 +126,7 @@ public class SketchConnection extends SketchObject {
                }\r
        }\r
 \r
-       public double getAngle(Sketch sketch) {\r
+       private double getAngle(Sketch sketch) {\r
                if (points == null || points.length < 2) {\r
                        return 0;\r
                }\r
index b041864691df9983b04ca6b2eb5b4c68c78b3a8c..3507db92c57b364d49d846871fd6b6d382e12a85 100644 (file)
@@ -3,15 +3,13 @@ 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.element.Symbol;\r
-import org.simantics.sysdyn.modelImport.model.element.Valve.TextPosition;\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
-       // some shorthands\r
-       protected static final String KEEP_I = MdlUtil.INT_G+",";\r
-       protected static final String SKIP_I = MdlUtil.INT+",";\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
@@ -24,13 +22,13 @@ public abstract class SketchElement extends SketchObject {
        protected static final String ELEMENT_SUFFIX =\r
                        KEEP_I+KEEP_I+KEEP_I+KEEP_I+KEEP_I+KEEP_I+SKIP_I+SKIP_I+KEEP_I+".*";\r
        // corresponding group indices\r
-       protected static final int elementX = 1;\r
-       protected static final int elementY = 2;\r
-       protected static final int elementWidth = 3;\r
-       protected static final int elementHeight = 4;\r
-       protected static final int elementShape = 5;\r
-       protected static final int elementBits = 6;\r
-       protected static final int elementTextPos = 7;\r
+       private static final int elementX = 1;\r
+       private static final int elementY = 2;\r
+       private static final int elementWidth = 3;\r
+       private static final int elementHeight = 4;\r
+       private static final int elementShape = 5;\r
+       private static final int elementBits = 6;\r
+       private static final int elementTextPos = 7;\r
 \r
        private int x;\r
        private int y;\r
@@ -119,8 +117,6 @@ public abstract class SketchElement extends SketchObject {
 \r
        public abstract Symbol getSymbol(MdlModel mdl, Sketch sketch);\r
        \r
-       private static final double SCALE_MULTIPLIER = 0.4;\r
-       \r
        public double[] getDimensions(Sketch sketch) {\r
                double[] dimensions = getDimensions();\r
                dimensions[0] = dimensions[0] + sketch.getHorizontalOffset();\r
@@ -128,7 +124,7 @@ public abstract class SketchElement extends SketchObject {
                return dimensions;\r
        }\r
        \r
-       // get element dimensions, [x, y, width, height]\r
+       // get element dimensions [x, y, width, height]\r
        public double[] getDimensions() {\r
                double[] dimensions = new double[4];\r
                dimensions[0] = (getX() - getWidth()) * SCALE_MULTIPLIER;\r
index 8bf5105509c5ef1cd19839536d984dbda1b9a177..2ddb1e4c3fb6f2933d2f48be06c5d5c2ed17799e 100644 (file)
@@ -1,8 +1,14 @@
 package org.simantics.sysdyn.modelImport.mdl;\r
 \r
+import org.simantics.sysdyn.modelImport.MdlUtil;\r
 import org.simantics.sysdyn.modelImport.model.IWriteableObject;\r
 \r
 public abstract class SketchObject {\r
+       \r
+       // some shorthands\r
+       protected static final String KEEP_I = MdlUtil.INT_G+",";\r
+       protected static final String SKIP_I = MdlUtil.INT+",";\r
+       protected static final String SKIP_ANY = "[^,]*,";\r
 \r
        private int id;\r
        private IWriteableObject modelObject;\r
index 2d0c88cedc486f4eb0be7581483c6dcf8e53e803..f9d5bd381b40aae8c56765646e77097866e8400f 100644 (file)
@@ -3,8 +3,8 @@ package org.simantics.sysdyn.modelImport.mdl;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-import org.simantics.sysdyn.modelImport.model.element.Valve;\r
-import org.simantics.sysdyn.modelImport.model.element.Valve.Orientation;\r
+import org.simantics.sysdyn.modelImport.model.Valve;\r
+import org.simantics.sysdyn.modelImport.model.Valve.Orientation;\r
 \r
 public class SketchValve extends SketchElement {\r
        \r
index 5137203e2bf9d58a467452d1d1a0267f9a71a661..f6f3a1f059ea29193f4300d983604cd929a85dad 100644 (file)
@@ -4,10 +4,10 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;\r
 \r
 import org.simantics.sysdyn.modelImport.MdlUtil;\r
-import org.simantics.sysdyn.modelImport.model.element.Auxiliary;\r
-import org.simantics.sysdyn.modelImport.model.element.ModelVariable;\r
-import org.simantics.sysdyn.modelImport.model.element.Symbol;\r
-import org.simantics.sysdyn.modelImport.model.element.Stock;\r
+import org.simantics.sysdyn.modelImport.model.Auxiliary;\r
+import org.simantics.sysdyn.modelImport.model.ModelVariable;\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
index 7dceeaef9dae2457889103cd7ff6b95f6ace4f3a..25f21fa227ce36e60e82c91a78246a2f99d97ce2 100644 (file)
@@ -5,7 +5,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;\r
 \r
 import org.simantics.sysdyn.modelImport.MdlUtil;\r
-import org.simantics.sysdyn.modelImport.model.element.ModelVariable;\r
+import org.simantics.sysdyn.modelImport.model.ModelVariable;\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
similarity index 89%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Auxiliary.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Auxiliary.java
index e30545b6f9db6f57afb5e16ee059424a167f2f0a..871d2106271756cf8f23d148fb94776ee4bff45f 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
similarity index 87%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Cloud.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Cloud.java
index 9687c53314f5d09d6b03d9a4932573f61f575c26..c93d003fb0877d06eb65226b1b26e447599eda32 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -8,7 +8,6 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public class Cloud extends Symbol {\r
        \r
similarity index 87%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Comment.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java
index b632ca1df3e3e2a08918b3d6bdb8cee69af8b6cf..06c651c9f66cda0c48b874ce0c64a2d04d61b2ce 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
@@ -7,7 +7,6 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public class Comment extends Symbol {\r
        \r
similarity index 90%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Connection.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Connection.java
index dda8b59ad6cd639b84ba6398e08f2666d233e7bb..acd124c5b8c7a6355084b1034c00c3d191fff768 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -11,8 +11,6 @@ import org.simantics.layer0.utils.direct.GraphUtils;
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.IWriteableObject;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public abstract class Connection implements IWriteableObject {\r
 \r
similarity index 91%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Dependency.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Dependency.java
index a2c486bbb9781668083bc0effd1b1832e30a1156..a09c3e821b6ca130cd0975d6dca165f4877df836 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
@@ -7,7 +7,6 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public class Dependency extends Connection {\r
        \r
similarity index 87%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Flow.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Flow.java
index 9e3b28d5493291f15007b2641a432db65794545e..6fb0d8d0884961440cfcd063713f11b9ff07865f 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
@@ -7,7 +7,6 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public class Flow extends Connection {\r
        \r
index 0b56e6e6e890548b8ce7ce7ab5001bc8119bcfa9..65cc051dd18449136895deb9ba5b23adf710f216 100644 (file)
@@ -14,7 +14,6 @@ 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
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
@@ -24,10 +23,7 @@ import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.sysdyn.modelImport.model.element.Connection;\r
-import org.simantics.sysdyn.modelImport.model.element.Symbol;\r
-import org.simantics.sysdyn.modelImport.model.element.ModelVariable;\r
-import org.simantics.sysdyn.modelImport.model.element.Shadow;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.modelImport.model.support.Enumeration;\r
 import org.simantics.sysdyn.modelImport.model.support.Function;\r
 import org.simantics.sysdyn.utils.ModelUtils;\r
@@ -37,6 +33,7 @@ public class Model implements IWriteableObject {
        private String name;\r
        // necessary simulation parameters\r
        private double start, stop, step;\r
+       private String unit;\r
        \r
        // the structure of the model\r
        private HashMap<String, ModelVariable> variables;\r
@@ -59,6 +56,15 @@ public class Model implements IWriteableObject {
                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
@@ -92,6 +98,7 @@ public class Model implements IWriteableObject {
                \r
                variables.put(variable.getName(), variable);\r
                \r
+               \r
                symbols.add(variable);\r
        }\r
        \r
@@ -152,11 +159,17 @@ public class Model implements IWriteableObject {
                Layer0 l0 = Layer0.getInstance(graph);\r
                ModelingResources mr = ModelingResources.getInstance(graph);\r
                SimulationResource sim = SimulationResource.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
                \r
                model = ModelUtils.createModel(graph);\r
                graph.claimLiteral(model, l0.HasLabel, name, Bindings.STRING);\r
                \r
-               // TODO: set simulation parameters\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
                \r
                Resource configuration = graph.getSingleObject(model, sim.HasConfiguration);\r
                \r
similarity index 92%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/ModelVariable.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/ModelVariable.java
index d5e96f0094a96688d35989e6b262b82586e308b0..5e64585da13bbe545197da49e7685dc51c6357d7 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
@@ -9,7 +9,6 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
similarity index 89%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Shadow.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Shadow.java
index 716c2aa726b4c4321023d6149953a12d9e7dce32..2e7d2689cb6e4c05e08aa201fc90d8a3096e8db6 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -8,7 +8,6 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public class Shadow extends Symbol {\r
 \r
similarity index 89%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Stock.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Stock.java
index 9c4b11c26e5a324f194b18cdb8e181bd7447d2c8..76842a2d4817d0abf5c2abfe0f7372d39b1667e6 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
similarity index 88%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Symbol.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Symbol.java
index e4f23be675269417a688016f24495c4080db10e2..18e76cf78537293f7a30d088f6791eade0f83c64 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
@@ -11,8 +11,6 @@ import org.simantics.diagram.stubs.G2DResource;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
-import org.simantics.sysdyn.modelImport.model.IWriteableObject;\r
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 \r
 public abstract class Symbol implements IWriteableObject {\r
        \r
similarity index 91%
rename from org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/element/Valve.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Valve.java
index f9451118ca1a8f8f3ad5fe6354fb35cea17222ee..9a84e09491d5f34fdc8597a67f189635eb0ebcf4 100644 (file)
@@ -1,11 +1,10 @@
-package org.simantics.sysdyn.modelImport.model.element;\r
+package org.simantics.sysdyn.modelImport.model;\r
 \r
 import org.simantics.db.ReadGraph;\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
-import org.simantics.sysdyn.modelImport.model.WriteContext;\r
 import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 import org.simantics.sysdyn.modelImport.model.support.Range;\r
 \r
index 1cc4f3d27c1c5ba384547f2319fc252f2adfd974..4a00b01ab09f2d707373048dbc083b372e359aff 100644 (file)
@@ -1,14 +1,5 @@
 package org.simantics.sysdyn.modelImport.model;\r
 \r
-import java.util.Arrays;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.sysdyn.modelImport.model.support.Enumeration;\r
-\r
 public class WriteContext {\r
        \r
        private long objectCount;\r
@@ -18,9 +9,6 @@ public class WriteContext {
        private long dependencyCount;\r
        private long flowCount;\r
        \r
-       private HashMap<String, Enumeration> enumerations;\r
-       private HashMap<String, Set<Enumeration>> enumerationValues;\r
-       \r
        public WriteContext() {\r
                objectCount = 0;\r
                \r
@@ -28,9 +16,6 @@ public class WriteContext {
                shadowCount = 0;\r
                dependencyCount = 0;\r
                flowCount = 0;\r
-               \r
-               enumerations = new HashMap<String, Enumeration>();\r
-               enumerationValues = new HashMap<String, Set<Enumeration>>();\r
        }\r
        \r
        public String getNextObject() {\r
@@ -56,50 +41,5 @@ public class WriteContext {
        public String getNextFlow() {\r
                return "Flow" + flowCount++;\r
        }\r
-       \r
-       public void registerEnumeration(Enumeration enumeration, boolean copy) {\r
-               enumerations.put(enumeration.getName(), enumeration);\r
-               if (enumerationValues.get(enumeration.getName()) == null) {\r
-                       enumerationValues.put(enumeration.getName(), new HashSet<Enumeration>());\r
-               }\r
-               enumerationValues.get(enumeration.getName()).add(enumeration);\r
-               if (!copy) {\r
-                       for (String value : enumeration.getValues()) {\r
-                               if (enumerationValues.get(value) == null) {\r
-                                       enumerationValues.put(value, new HashSet<Enumeration>());\r
-                               }\r
-                               enumerationValues.get(value).add(enumeration);\r
-                       }\r
-               }\r
-       }\r
-               \r
-       public Enumeration getEnumeration(Set<String> indices) {\r
-               System.err.println("size is "+indices.size());\r
-               if (indices.size() == 1) {\r
-                       Enumeration enumeration = enumerations.get(indices.iterator().next());\r
-                       if (enumeration != null) {\r
-                               return enumeration;\r
-                       }\r
-               }\r
-               \r
-               // the set of potential matches is the intersection of all sets of\r
-               // enumerations that contain any of the given indices as elements\r
-               Set<Enumeration> potential = new HashSet<Enumeration>(enumerations.values());\r
-               for (String index : indices) {\r
-                       potential.retainAll(enumerationValues.get(index));\r
-               }\r
-               \r
-               // if there is more than one potential match, the enumerations are not\r
-               // well defined (there are multiple enumerations with similar indices)\r
-               if (potential.size() == 1) {\r
-                       return potential.iterator().next();\r
-               }\r
-               else {\r
-                       System.err.println("enumeration could not be resolved "+potential.size());\r
-                       for (String index : indices)\r
-                               System.err.println("  "+index);\r
-                       return null;\r
-               }\r
-       }\r
 \r
 }\r
index 00d99797934ab3273afbb29060e3c694c42884c1..c3246adc35343cca9c0090d8bcf4c34dc07c5499 100644 (file)
@@ -1,9 +1,7 @@
 package org.simantics.sysdyn.modelImport.model.expression;\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.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
@@ -26,19 +24,9 @@ public class EnumerationExpression extends Expression {
        }\r
        \r
        public void addExpression(Expression expression, String...indices) {\r
-//             for (int i = 0; i < indices.length; i++) {\r
-//                     if (!enumerations.get(i).getValues().contains(indices)) {\r
-//                             System.err.println("tried adding an enumeration expression with incorrect indices");\r
-//                             return;\r
-//                     }\r
-//             }\r
                subExpressions.add(new EnumerationSubExpression(expression, indices));\r
        }\r
        \r
-       public List<EnumerationSubExpression> getExpressions() {\r
-               return subExpressions;\r
-       }\r
-       \r
        @Override\r
        public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {\r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
@@ -70,6 +58,16 @@ public class EnumerationExpression extends Expression {
                \r
                return getResource();\r
        }\r
+\r
+       @Override\r
+       public Resource getExpressionType(ReadGraph graph) {\r
+               return subExpressions.get(0).expression.getExpressionType(graph);\r
+       }\r
+       \r
+       @Override\r
+       public Resource getResource() {\r
+               return subExpressions.get(0).expression.getResource();\r
+       }\r
        \r
        private class EnumerationSubExpression {\r
                \r
@@ -81,14 +79,4 @@ public class EnumerationExpression extends Expression {
                        this.indices = indices;\r
                }\r
        }\r
-\r
-       @Override\r
-       public Resource getExpressionType(ReadGraph graph) {\r
-               return subExpressions.get(0).expression.getExpressionType(graph);\r
-       }\r
-       \r
-       @Override\r
-       public Resource getResource() {\r
-               return subExpressions.get(0).expression.getResource();\r
-       }\r
 }\r
index faa5f5a6445093eeb75558c8c884b28de179c02c..8aa761f17a3ce00417f99b62d6f7a0a187a8f10a 100644 (file)
@@ -41,8 +41,6 @@ public class Function implements IWriteableObject {
        @Override\r
        public Resource write(WriteGraph graph, Resource parent, WriteContext context) \r
                        throws DatabaseException {\r
-               System.err.println("write function");\r
-               \r
                Layer0 l0 = Layer0.getInstance(graph);\r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
                \r