]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Trying to make MDL import work 15/4515/1 master release/1.45.0
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 30 Sep 2020 08:52:40 +0000 (11:52 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Wed, 30 Sep 2020 08:52:40 +0000 (11:52 +0300)
gitlab #84

Change-Id: I7d9c36e4190f020033ebeefb6d008ebc34ffb478

bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java
bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchComment.java
bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java

index 6fd3cf65829de5c16ac508388a02448da63defec..4248fb9611ac2b4857eadc6f5f2feb03f4b053d5 100644 (file)
@@ -21,6 +21,9 @@ public class MdlUtil {
        public static final String INT = "[+-]?\\d+";\r
        public static final String INT_G = "("+INT+")";\r
 \r
+       // matches a basic character allowed in variable name\r
+       public static final String FORBIDDEN_VARIABLE_CHAR = "\\W";\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
@@ -94,8 +97,7 @@ public class MdlUtil {
 //                             result.append(variable.substring(1, variable.length() - 1));\r
 //                             result.append('\'');\r
                                // try this: replace quoted variable names with normalized versions\r
-                               String foobar = variable.replace('"', ' ');\r
-                               foobar = foobar.replace('-', ' ');\r
+                               variable = variable.replaceAll(FORBIDDEN_VARIABLE_CHAR, "_");\r
                                result.append(variable);\r
                        }\r
                        else {\r
@@ -104,7 +106,7 @@ public class MdlUtil {
                                // this would be to simply quote problematic variable names \r
                                // but quoted variable names are currently broken in sysdyn so \r
                                // that is not an option)\r
-                               \r
+                               variable = variable.replaceAll(FORBIDDEN_VARIABLE_CHAR, "_");\r
                                // capitalize each part of the variable name to prevent \r
                                // collisions with reserved keywords (e.g. "public")\r
                                String[] parts = variable.split("\\s+");\r
@@ -120,7 +122,9 @@ public class MdlUtil {
                        offset = matcher.end();\r
                }\r
                if (offset < expression.length()) {\r
-                       result.append(expression.substring(offset));\r
+                       String stuff = expression.substring(offset);\r
+                       stuff = stuff.replaceAll("=", "==");\r
+                       result.append(stuff);\r
                }\r
 \r
                return result.toString();\r
index 3c4b23845fc6d9e0858dd41c8ff8a29db81be804..2f26fb52b6adfb40d73dff345f686b9715d8e014 100644 (file)
@@ -19,7 +19,7 @@ public class SketchComment extends SketchElement {
                CLOUD, OTHER\r
        }\r
        \r
-       private String text;\r
+       private String text = "empty comment";\r
        private CommentIcon icon;\r
 \r
        protected SketchComment(int id, Sketch sketch, CommentIcon icon) {\r
index 06c651c9f66cda0c48b874ce0c64a2d04d61b2ce..884d433aa5080e15c760f2e88326ff4075c522be 100644 (file)
@@ -13,7 +13,7 @@ public class Comment extends Symbol {
        private String text;\r
        \r
        public Comment() {\r
-               \r
+               this.text = "Comment";\r
        }\r
        \r
        public Comment(String text) {\r