Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit dd949d97 authored by Nico Mack's avatar Nico Mack

Proper handling of decimals property

Fixed an issue in EquationSystemBuilder causing output variables not
being properly assigned as equation parameters.
parent 58744a69
......@@ -44,11 +44,16 @@ public class VariableBootstrapper {
double maxValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.MAXIMUM_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Double.MAX_VALUE, context);
double scale = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.SCALE_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 1.0, context);
double numericValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.INITIAL_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 0.0, context);
int decimals = BootstrappingUtils.getContentAsInteger(variableNode, EquationSystemBundle.DECIMALS_ATTRIBUTE, BootstrappingUtils.OPTIONAL, -1, context);
NumericalVariable numerical = new NumericalVariable(name, unit, numericValue);
numerical.setMinValue(minValue);
numerical.setMaxValue(maxValue);
numerical.setScale(scale);
if (decimals >= 0) {
numerical.setNumberOfDecimals(decimals);
}
variable = numerical;
break;
......
......@@ -167,6 +167,18 @@ public class EquationSystemBuilder {
// ---------------------------------------------------------------------------
private String guessVariableType(String identifier) {
String type = EquationSystemBundle.NUMERIC_TYPE;
if (outputVariables.containsKey(identifier)) {
Variable<?> output = outputVariables.get(identifier);
type = output.getType();
}
return type;
}
// ---------------------------------------------------------------------------
@SuppressWarnings({"unchecked"})
private <T> Variable<T> instantiateVariable(String name, String type, String unit, String value) {
Variable<T> variable = null;
......@@ -261,7 +273,7 @@ public class EquationSystemBuilder {
attribute = this.getAttribute(element, EquationSystemBundle.TYPE_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = EquationSystemBundle.NUMERIC_TYPE;
attribute = guessVariableType(attributes.get(EquationSystemBundle.NAME_ATTRIBUTE));
attributes.put(EquationSystemBundle.TYPE_ATTRIBUTE, attribute);
attribute = this.getAttribute(element, EquationSystemBundle.UNIT_ATTRIBUTE);
......@@ -476,6 +488,7 @@ public class EquationSystemBuilder {
throw new EquationSystemException("For each output the name needs to be defined!"); //$NON-NLS-1$
}
outputVariables.put(identifier, this.createVariable(outputAttributes));
dependentVariables.put(identifier, this.createVariable(outputAttributes));
}
}
......@@ -870,7 +883,8 @@ public class EquationSystemBuilder {
// ---------------------------------------------------------------------------
public Map<String, Variable<?>> getOutputVariables() {
return outputVariables;
// return outputVariables;
return dependentVariables;
}
// ---------------------------------------------------------------------------
......
......@@ -442,6 +442,7 @@ public class NumericalVariable extends Variable<Double> {
// ---------------------------------------------------------------------------
public void setNumberOfDecimals(int decimals) {
this.format.setMinimumFractionDigits(decimals);
this.format.setMaximumFractionDigits(decimals);
this.roundingFactor = Math.pow(10, decimals);
}
......
......@@ -88,7 +88,11 @@ public class VariableHtmlBox extends HtmlBox implements VariableBased, InputChan
@Override
public List<Variable<?>> connectWithSystemVariables(Map<String, Variable<?>> systemVariables) {
return htmlTemplate.connectWithSystemVariables(systemVariables);
List<Variable<?>> connected = htmlTemplate.connectWithSystemVariables(systemVariables);
for (Variable<?> variable : connected) {
variable.addListener(this);
}
return connected;
}
// ---------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment