From 5bcae996626f920a29a333986e70cd24d7c86307 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Wed, 30 Sep 2020 11:52:40 +0300 Subject: [PATCH] Trying to make MDL import work gitlab #84 Change-Id: I7d9c36e4190f020033ebeefb6d008ebc34ffb478 --- .../org/simantics/sysdyn/modelImport/MdlUtil.java | 12 ++++++++---- .../sysdyn/modelImport/mdl/SketchComment.java | 2 +- .../simantics/sysdyn/modelImport/model/Comment.java | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java index 6fd3cf65..4248fb96 100644 --- a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java +++ b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java @@ -21,6 +21,9 @@ public class MdlUtil { public static final String INT = "[+-]?\\d+"; public static final String INT_G = "("+INT+")"; + // matches a basic character allowed in variable name + public static final String FORBIDDEN_VARIABLE_CHAR = "\\W"; + // matches a basic vensim name (starts with a letter, may contain any word // characters and white space) public static final String BASIC_NAME = @@ -94,8 +97,7 @@ public class MdlUtil { // result.append(variable.substring(1, variable.length() - 1)); // result.append('\''); // try this: replace quoted variable names with normalized versions - String foobar = variable.replace('"', ' '); - foobar = foobar.replace('-', ' '); + variable = variable.replaceAll(FORBIDDEN_VARIABLE_CHAR, "_"); result.append(variable); } else { @@ -104,7 +106,7 @@ public class MdlUtil { // this would be to simply quote problematic variable names // but quoted variable names are currently broken in sysdyn so // that is not an option) - + variable = variable.replaceAll(FORBIDDEN_VARIABLE_CHAR, "_"); // capitalize each part of the variable name to prevent // collisions with reserved keywords (e.g. "public") String[] parts = variable.split("\\s+"); @@ -120,7 +122,9 @@ public class MdlUtil { offset = matcher.end(); } if (offset < expression.length()) { - result.append(expression.substring(offset)); + String stuff = expression.substring(offset); + stuff = stuff.replaceAll("=", "=="); + result.append(stuff); } return result.toString(); diff --git a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchComment.java b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchComment.java index 3c4b2384..2f26fb52 100644 --- a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchComment.java +++ b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchComment.java @@ -19,7 +19,7 @@ public class SketchComment extends SketchElement { CLOUD, OTHER } - private String text; + private String text = "empty comment"; private CommentIcon icon; protected SketchComment(int id, Sketch sketch, CommentIcon icon) { diff --git a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java index 06c651c9..884d433a 100644 --- a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java +++ b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/Comment.java @@ -13,7 +13,7 @@ public class Comment extends Symbol { private String text; public Comment() { - + this.text = "Comment"; } public Comment(String text) { -- 2.47.1