From: miettinen Date: Wed, 20 Aug 2014 12:15:36 +0000 (+0000) Subject: Allow whitespace in Sysdyn modules and module types (refs #4882). X-Git-Tag: v1.29.0~229 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8d447fda61fe4893045b010ec8fa190935c0df06;p=simantics%2Fsysdyn.git Allow whitespace in Sysdyn modules and module types (refs #4882). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30101 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/NameValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/NameValidator.java index 25d7090b..ff352c72 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/NameValidator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/NameValidator.java @@ -113,8 +113,8 @@ public abstract class NameValidator { // Function, FunctionLibrary, and SharedFunctionLibrary are not // allowed to have whitespace. if (graph.isInstanceOf(resource, sr.Variable) -// || graph.isInstanceOf(resource, sr.Module) -// || graph.isInstanceOf(resource, sr.ModuleType) + || graph.isInstanceOf(resource, sr.Module) + || graph.isInheritedFrom(resource, sr.ModuleSymbol) || graph.isInstanceOf(resource, sr.Enumeration) || graph.isInstanceOf(resource, sr.EnumerationIndex) || graph.isInstanceOf(resource, sheet.Spreadsheet) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index ab040550..0d4a811a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Association for Decentralized Information Management in + * Copyright (c) 2010, 2013, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -66,7 +66,7 @@ import org.simantics.sysdyn.solver.SolverSettings.SolverType; /** * Maintains a Java representation of system dynamic model. - * @author Hannu Niemistö, Teemu Lempinen + * @author Hannu Niemistö, Teemu Lempinen, Tuomas Miettinen */ public class SysdynModel implements IModel, IMappingListener, VariableSubscriptionManager { @@ -493,7 +493,7 @@ public class SysdynModel implements IModel, IMappingListener, VariableSubscripti if (element instanceof Module) { Module module = (Module) element; Configuration conf = module.getType().getConfiguration(); - String prfx = prefix + module.getName() + "."; + String prfx = prefix + module.getModelicaName() + "."; inits.putAll(getInits(conf, prfx)); for(ParameterOverride po : module.getParameterOverrides()) { inits.put(prfx + po.getVariable().getName(), po.getExpression()); 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 f2c0a1b7..29b806a3 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Copyright (c) 2007, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -212,11 +212,11 @@ public class ModelicaWriter { // Module Module m = (Module)element; modules.add(m); - moduleInputs.put(m.getName(), new ArrayList()); + moduleInputs.put(m.getModelicaName(), new ArrayList()); for(IElement e : m.getType().getConfiguration().getElements()) // Inputs inside the module if(e instanceof Input && !((Input)e).isHeadOfDependency()) { - moduleInputs.get(m.getName()).add((Input)e); + moduleInputs.get(m.getModelicaName()).add((Input)e); } } else if (element instanceof Input) { // Input variables @@ -245,7 +245,7 @@ public class ModelicaWriter { ModuleType mt = configuration.getModuleType(); // className == null, if this is a model configuration. model configuration start and end are written in ModelicaWriter.write - String className = mt != null ? (mt.getName().replace(" ", "")) : null; + String className = mt != null ? (mt.getModelicaName()) : null; if(className != null) b.append("class "+className+"\n"); @@ -335,8 +335,8 @@ public class ModelicaWriter { Module module = (Module)dependency.getHead(); Input reference = (Input)dependency.refersTo(); if(reference != null && reference.getName() != null && (reference.getVariability() == null || reference.getVariability().isEmpty())) { - b.append(" " + module.getName() + "." + reference.getModelicaName() + " = " + variable.getModelicaName() + ";\n"); - moduleInputs.get(module.getName()).remove(reference); + b.append(" " + module.getModelicaName() + "." + reference.getModelicaName() + " = " + variable.getModelicaName() + ";\n"); + moduleInputs.get(module.getModelicaName()).remove(reference); } } @@ -352,7 +352,7 @@ public class ModelicaWriter { if(configuration.isGameConfiguration() && !modules.isEmpty()) { b.append("// Time values for module\n"); for(Module m : modules) { - b.append(" " + m.getName() + ".time = time;\n"); + b.append(" " + m.getModelicaName() + ".time = time;\n"); } } } @@ -391,7 +391,7 @@ public class ModelicaWriter { String expression; // If reference exists, use reference name. Otherwise, use default value. if(reference != null && reference.getName() != null) - expression = module.getName() + "." + reference.getModelicaName() + ";\n"; + expression = module.getModelicaName() + "." + reference.getModelicaName() + ";\n"; else expression = input.getDefaultInputValue() + ";\n"; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java index 3938f200..e8908c9b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -58,6 +58,17 @@ public class Module implements IElement { public String getName() { return name; } + + /** + * Get Modelica compliant name + * @return The name of this variable with spaces (' ') replaced with + * underscore characters ('_') + */ + public String getModelicaName() { + if (this.name == null) + return null; + return this.name.replace(' ', '_'); + } public ModuleType getType() { return type; @@ -114,9 +125,9 @@ public class Module implements IElement { } sb.append(" "); - sb.append(getType().getName()); + sb.append(getType().getModelicaName()); sb.append(" "); - sb.append(getName()); + sb.append(getModelicaName()); sb.append(redeclarations.toString()); // possible redeclarations sb.append(";\n"); return sb.toString(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java index bf7b84a9..1dbabb0c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -22,6 +22,7 @@ import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; * Representation of a module type * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ @GraphType(StructuralResource2.URIs.ComponentType) @@ -35,7 +36,18 @@ public class ModuleType implements IElement { @RelatedElement(Layer0.URIs.PartOf) protected Object parent; - + + /** + * Get Modelica compliant name + * @return The name of this variable with spaces (' ') replaced with + * underscore characters ('_') + */ + public String getModelicaName() { + if (this.name == null) + return null; + return this.name.replace(' ', '_'); + } + public String getName() { return name; }