From bff05cfebae9bc453820c240ba0f189da14d33ba Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 14 Dec 2012 13:41:33 +0000 Subject: [PATCH] Build preparations (refs #3646) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26520 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.feature/feature.xml | 53 +++++++++++++++++-- org.simantics.sysdyn.ui/plugin.xml | 2 +- .../sysdyn/ui/browser/SysdynBrowser.java | 2 +- .../sysdyn/ui/utils/ArrayVariableUtils.java | 9 ++-- .../sysdyn/manager/SysdynGameExperiment.java | 8 ++- .../sysdyn/representation/Module.java | 13 +++-- .../sysdyn/representation/Sheet.java | 25 ++++----- .../representation/utils/IndexUtils.java | 23 ++++---- 8 files changed, 100 insertions(+), 35 deletions(-) diff --git a/org.simantics.sysdyn.feature/feature.xml b/org.simantics.sysdyn.feature/feature.xml index 23193a92..8399d120 100644 --- a/org.simantics.sysdyn.feature/feature.xml +++ b/org.simantics.sysdyn.feature/feature.xml @@ -53,9 +53,8 @@ version="0.0.0"/> + id="org.simantics.eclipsec.launcher" + version="0.0.0"/> + diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index d39c13f3..5c5f8544 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -743,7 +743,7 @@ - --> + --> selectionTransformation = new BinaryFunction() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java index ef49ba46..26079fca 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java @@ -85,7 +85,8 @@ public class ArrayVariableUtils { for(String r : rangeComponents) { r = r.trim(); boolean componentIsValid = false; - for(EnumerationIndex ei : enumerations.get(i).getEnumerationIndexes()) { + Enumeration enumeration = enumerations.get(i); + for(EnumerationIndex ei : enumeration.getEnumerationIndexes()) { if(ei.getName().equals(r)) { componentIsValid = true; break; @@ -96,8 +97,8 @@ public class ArrayVariableUtils { try { int index = Integer.parseInt(r); int min = 1; - int max = enumerations.get(i).getEnumerationIndexes().size(); - if(index >= min && index <= max) { + int max = enumeration.getEnumerationIndexes().size(); + if(index >= min && index <= max || enumeration.isReplaceable()) { componentIsValid = true; error = new SyntaxError(); error.setMessage("Using numbers as array indexes is not encouraged"); @@ -105,7 +106,7 @@ public class ArrayVariableUtils { result.put(i, error); } else { error = new SyntaxError(); - error.setMessage("Invalid array index " + index + ". Numbered index must be between " + min + " and " + max + " unless the enumeration is overridden. In that case, ignore this warning."); + error.setMessage("Invalid array index " + index + ". Numbered index must be between " + min + " and " + max); error.setType(ExpressionField.SYNTAX_ERROR); result.put(i, error); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index defa0977..ed136642 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -226,6 +226,7 @@ public class SysdynGameExperiment extends SysdynExperiment { private class simulateDurationJob extends Job { + private boolean canceled = false; private double duration; private final SysdynGameExperiment experiment; public simulateDurationJob(String name, SysdynGameExperiment experiment, double duration) { @@ -233,6 +234,11 @@ public class SysdynGameExperiment extends SysdynExperiment { this.duration = duration; this.experiment = experiment; } + + @Override + protected void canceling() { + canceled = true; + } @Override protected IStatus run(IProgressMonitor monitor) { @@ -263,7 +269,7 @@ public class SysdynGameExperiment extends SysdynExperiment { monitor.worked(1); int stepNumber = 1; - while(control.getTime() < (eTime - 1e-9)) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers + while(control.getTime() < (eTime - 1e-9) && !canceled) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers monitor.subTask("Simulate step (time = " + control.getTime() + ")"); control.simulateStep(); monitor.worked(1); 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 699085c6..d9b329ef 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -130,12 +130,19 @@ public class Module implements IElement { StringBuilder redeclarations = new StringBuilder(); if(!getRedeclarations().isEmpty()) { + boolean first = true; Iterator i = getRedeclarations().iterator(); while(i.hasNext()) { Redeclaration rd = i.next(); - redeclarations.append(rd.getRedeclaration()); - if(i.hasNext()) - redeclarations.append(","); + String redeclaration = rd.getRedeclaration(); + if(redeclaration != null && !redeclaration.isEmpty()) { + if(!first) { + redeclarations.append(","); + } else { + first = false; + } + redeclarations.append(redeclaration); + } } } return redeclarations.toString(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java index a2deef14..92226cc8 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java @@ -157,19 +157,20 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable { } private void addRange(String key, HashSet usedCells, StringBuilder clazz) { - usedCells.add(key); - Object value = cells.get(key); - if(value instanceof String || value instanceof MutableString) { - try { - Double d = Double.parseDouble(value.toString()); - value = d; - } catch (NumberFormatException e) { - } - } + if(usedCells.add(key)) { + Object value = cells.get(key); + if(value instanceof String || value instanceof MutableString) { + try { + Double d = Double.parseDouble(value.toString()); + value = d; + } catch (NumberFormatException e) { + } + } - if(value instanceof Double) { - Double d = (Double)value; - clazz.append(" parameter Real " + key + " = " + d + " /* Actual value read from init file */;\n"); + if(value instanceof Double) { + Double d = (Double)value; + clazz.append(" parameter Real " + key + " = " + d + " /* Actual value read from init file */;\n"); + } } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java index e2f5cf45..137b6690 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java @@ -53,18 +53,21 @@ public class IndexUtils { if(rangeToken.matches("[\\[\\]:]")) { sb.append(rangeToken); } else if (rangeToken.equals(",")) { - sb.append(rangeToken); - index++; - } else if(rangeToken.equals(enumerations.get(index).getName())) { - sb.append(":"); + sb.append(rangeToken); + index++; + } else if(index < enumerations.size()) { + if(rangeToken.equals(enumerations.get(index).getName())) { + sb.append(":"); + } else { + int i = indexOf(enumerations.get(index), rangeToken); + if(i >= 0) + sb.append(i); + else + sb.append(rangeToken); + } } else { - int i = indexOf(enumerations.get(index), rangeToken); - if(i >= 0) - sb.append(i); - else - sb.append(rangeToken); + sb.append(rangeToken); } - } return sb.toString(); } -- 2.47.1