diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index 67ca07e5ec9722378eeaf498fbc76bf0ddb106ff..f0dfb076c41c0fc3f433c4ca6a58e8cff183509b 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -493,6 +493,34 @@ export class ParamDefinition implements INamedIterableValues, IObservable { return this.paramValues.valuesIterator.count(); } + /** + * Copies values of p into the current parameter, whatever the valueMode is; if + * p has linked values, the target values will be copied and the links won't be kept + * @param p a reference ParamDefinition or ParamValues to copy values from + */ + public copyValuesFrom(p: ParamDefinition | ParamValues) { + this.valueMode = p.valueMode; + switch (p.valueMode) { + case ParamValueMode.MINMAX: + this.min = p.min; + this.max = p.max; + this.step = p.step; + break; + case ParamValueMode.LISTE: + this.valueList = p.valueList; + break; + case ParamValueMode.LINK: + if (p instanceof ParamDefinition) { + this.copyValuesFrom(p.referencedValue.getParamValues()); + } + break; + case ParamValueMode.CALCUL: + case ParamValueMode.SINGLE: + default: + this.singleValue = p.singleValue; + } + } + // for INumberiterator interface public get currentValue(): number { // magically follows links