diff --git a/src/util/result.ts b/src/util/result.ts index 356b1c8ccaf0005099a9814ecf69e7f714e13aff..1525085765f826998830e3647c01ef0cecdcd6b8 100644 --- a/src/util/result.ts +++ b/src/util/result.ts @@ -100,9 +100,6 @@ export class Result extends JalhydObject implements INamedIterableValues { return this.resultElement.vCalc; } - /** - * @return le résultat de calcul du 1er ResultElement - */ set vCalc(r: number) { this.resultElement.vCalc = r; } @@ -176,6 +173,7 @@ export class Result extends JalhydObject implements INamedIterableValues { return Object.keys(r).length; } + // WTF public getExtraResult(name: string): any { const res = []; for (const r of this._resultElements) { @@ -195,11 +193,35 @@ export class Result extends JalhydObject implements INamedIterableValues { default: throw new Error( "Result.getExtraResult() : il existe plusieurs ResultElement avec" + - " un extratresult dont le nom est '" + name + "'", + " un extraResult dont le nom est '" + name + "'", ); } } + /** + * Returns the list of calculated values for the parameter in CALC mode; + * if no parameter is variated, the list will contain only 1 value + */ + public getCalculatedValues(): number[] { + return this.resultElements.map((re) => { + return re.vCalc; + }); + } + + /** + * Returns the list of extra results values for the given symbol; + * if no parameter is variated, the list will contain only 1 value + */ + public getExtraResults(symbol: string): number[] { + const extraRes: number[] = []; + const ier = this.getIterableExtraResults(symbol); + ier.initValuesIterator(false); + for (const er of ier) { + extraRes.push(er); + } + return extraRes; + } + /** * ajoute un message au journal */ @@ -292,11 +314,9 @@ export class Result extends JalhydObject implements INamedIterableValues { res.addValue(er); } } - if (found) { return res; } - return undefined; } diff --git a/src/value_ref/object_ref.ts b/src/value_ref/object_ref.ts index 3db161ae793733f22b87c737f869f5c26fd00c13..42c1ef9b75e2dcc54731dbecb2d672d14bf155eb 100644 --- a/src/value_ref/object_ref.ts +++ b/src/value_ref/object_ref.ts @@ -86,16 +86,38 @@ export class LinkedValue { /** * Returs the ParamValues for the linked Parameter if any, or a - * pseudo ParamValues object if the targetted element is a Result + * fake ParamValues object if the targetted element is a Result * or ExtraResults */ public getParamValues(): ParamValues { + let ret: ParamValues; + if (this.isParameter()) { - return (this.element as ParamDefinition).paramValues; + // simple proxy + ret = (this.element as ParamDefinition).paramValues; + + } else if (this.isExtraResult()) { + // already computed ? + if (this.nub.result) { + // handmade fake param values + ret = new ParamValues(); // @TODO extend class ? + // console.log("setting fake PV for linked ER", this.symbol, + // this.nub.result, this.nub.result.extraResults); + if (this.nub.resultHasMultipleValues()) { + const multipleExtraRes = this.nub.result.getExtraResults(this.symbol); + ret.setValues(multipleExtraRes); + } else { + const singleExtraRes = this.nub.result.getExtraResult(this.symbol); + ret.setSingleValue(singleExtraRes); + } + } else { + // not computed yet @TODO return undefined instead of throwing error ? + throw new Error("LinkedValue.getParamValues() - result not yet available"); + } } else { - // @TODO implement - throw new Error("not implemented - get pseudo ParamValues for ExtraResults"); + throw new Error("LinkedValue.getParamValues() - cannot determine nature of target"); } + return ret; } /** @@ -111,6 +133,19 @@ export class LinkedValue { return this.getParamValues().currentValue; } + /** + * Returns the current values array of this.paramValues; throws an error if + * this.paramValues is not defined + */ + public getValues(): number[] { + if (! this.getParamValues().isDefined) { + const e = new Message(MessageCode.ERROR_PARAMDEF_LINKED_VALUE_UNDEFINED); + e.extraVar.symbol = this.symbol; + throw e; + } + return this.getParamValues().valueList; + } + /** * Returns true if * - a parameter is targetted and it has multiple values