From 36d095f6f6dfae871fca7e84fcf99ad2000c342a Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 8 Mar 2011 10:36:46 +0000 Subject: [PATCH] git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19958 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/modelica/ModelicaWriter.java | 7 +++ .../sysdyn/representation/Enumeration.java | 50 ++++++++++++------- .../sysdyn/representation/Redeclaration.java | 6 ++- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java index d12f7b40..9bfc195d 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -34,6 +34,13 @@ public class ModelicaWriter { public void write(Configuration conf) { + if(!functionsWritten) { + b.append("partial class Enumeration_class\n"); + b.append(" parameter Integer size;\n"); + b.append(" parameter Integer elements[:];\n"); + b.append("end Enumeration_class;\n\n"); + } + writeConfiguration(conf); if(!functionsWritten) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java index 6a4a4807..98acfbb4 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java @@ -57,28 +57,44 @@ public class Enumeration extends Variable { } public String getEnumerationClassDefinition() { - StringBuilder sb = new StringBuilder(); + + // Build indexes (one = 1, two = 2, etc..) and elements {1,2,3,..,size} ArrayList indexes = getEnumerationIndexes(); - sb.append(" class "); - sb.append(this.name); - sb.append("_class\n parameter Integer size = "); - sb.append(indexes.size()); - sb.append(";\n"); - StringBuilder arrayBuilder = new StringBuilder(); - arrayBuilder.append("{"); + StringBuilder elementsBuilder = new StringBuilder(); + elementsBuilder.append("{"); + StringBuilder indexesBuilder = new StringBuilder(); for(int i = 1; i <= indexes.size(); i++) { - sb.append(" constant Integer "); - sb.append(indexes.get(i - 1).getName()); - sb.append(" = " + i + ";\n"); + indexesBuilder.append(" constant Integer "); + indexesBuilder.append(indexes.get(i - 1).getName()); + indexesBuilder.append(" = " + i + ";\n"); - arrayBuilder.append(i); + elementsBuilder.append(i); if(i < indexes.size()) - arrayBuilder.append(","); + elementsBuilder.append(","); } - arrayBuilder.append("}"); - sb.append(" constant Integer[" + indexes.size() + "] elements = "); - sb.append(arrayBuilder); - sb.append(";\n end "); + elementsBuilder.append("}"); + + /* + * class E_class + * extends Enumeration_class(size = n, elements = {1,2,3,..n}); + * constant Integer index1 = 1; + * constant Integer index2 = 2; + * .... + * constant Integer indexn = n; + * end E_class; + */ + + StringBuilder sb = new StringBuilder(); + sb.append(" class "); + sb.append(this.name); + sb.append("_class\n"); + sb.append(" extends Enumeration_class(size="); + sb.append(indexes.size()); + sb.append(", elements="); + sb.append(elementsBuilder); + sb.append(");\n"); + sb.append(indexesBuilder); + sb.append(" end "); sb.append(this.name); sb.append("_class;\n"); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java index 672713f4..b048bbdb 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java @@ -31,7 +31,11 @@ public class Redeclaration { sb.append(replacedEnumeration.getName()); sb.append(".size = "); sb.append(replacingEnumeration.getName()); - sb.append(".size"); + sb.append(".size, "); + sb.append(replacedEnumeration.getName()); + sb.append(".elements = "); + sb.append(replacingEnumeration.getName()); + sb.append(".elements"); return sb.toString(); } -- 2.47.1