Commit 0d956753 authored by Grand Francois's avatar Grand Francois
Browse files

#44 enum ParamValueMode : ajout de la valeur CALCUL pour les paramètres "à calculer"

- classe ParamValues : _singleValue number->DefinedNumber, mode "à calculer" par défaut, ajout de contrôles de cohérence mode/valeur(s)
Showing with 78 additions and 10 deletions
+78 -10
import { Pair } from "../util/pair" import { Pair } from "../util/pair"
import { DefinedNumber } from "../util/definedvalue";
/** /**
* mode de génération des valeurs * mode de génération des valeurs
...@@ -17,7 +18,12 @@ export enum ParamValueMode { ...@@ -17,7 +18,12 @@ export enum ParamValueMode {
/** /**
* liste de valeurs discrètes * liste de valeurs discrètes
*/ */
LISTE LISTE,
/**
* la valeur du paramètre est non définie et à calculer
*/
CALCUL
} }
/** /**
...@@ -149,12 +155,12 @@ export class ParamValues { ...@@ -149,12 +155,12 @@ export class ParamValues {
/** /**
* mode de génération des valeurs : min/max, liste, ... * mode de génération des valeurs : min/max, liste, ...
*/ */
private _valueMode: ParamValueMode = ParamValueMode.MINMAX; private _valueMode: ParamValueMode;
/** /**
* valeur dans le cas ParamValueMode.SINGLE * valeur numérique (éventuellement non définie) dans le mode "valeur unique" (ParamValueMode.SINGLE)
*/ */
private _singleValue: number; private _singleValue: DefinedNumber;
/** /**
* valeur min dans le cas ParamValueMode.MINMAX * valeur min dans le cas ParamValueMode.MINMAX
...@@ -176,20 +182,27 @@ export class ParamValues { ...@@ -176,20 +182,27 @@ export class ParamValues {
*/ */
private _valueList: number[]; private _valueList: number[];
constructor() {
this._singleValue = new DefinedNumber();
this.valueMode = ParamValueMode.CALCUL;
}
public setValues(o: number | any, max?: number, step?: number) { public setValues(o: number | any, max?: number, step?: number) {
if (typeof (o) === "number") { if (typeof (o) === "number") {
if (max == undefined) { if (max == undefined) {
this._valueMode = ParamValueMode.SINGLE; this.valueMode = ParamValueMode.SINGLE;
this._singleValue = o as number; this._singleValue.value = o as number;
} else { } else {
this._valueMode = ParamValueMode.MINMAX; this.valueMode = ParamValueMode.MINMAX;
this._minValue = o as number; this._minValue = o as number;
this._maxValue = max; this._maxValue = max;
this._stepValue = step; this._stepValue = step;
} }
} }
else if (Array.isArray(o)) else if (Array.isArray(o)) {
this.valueMode = ParamValueMode.LISTE;
this._valueList = o; this._valueList = o;
}
else else
throw new Error(`ParamValues.setValues() : appel invalide`); throw new Error(`ParamValues.setValues() : appel invalide`);
} }
...@@ -200,50 +213,104 @@ export class ParamValues { ...@@ -200,50 +213,104 @@ export class ParamValues {
public set valueMode(m: ParamValueMode) { public set valueMode(m: ParamValueMode) {
this._valueMode = m; this._valueMode = m;
switch (m) {
case ParamValueMode.SINGLE:
this._minValue = undefined;
this._maxValue = undefined;
this._stepValue = undefined;
this._valueList = undefined;
break;
case ParamValueMode.LISTE:
this._singleValue.undefine();
this._minValue = undefined;
this._maxValue = undefined;
this._stepValue = undefined;
break;
case ParamValueMode.MINMAX:
this._singleValue.undefine();
this._valueList = undefined;
break;
case ParamValueMode.CALCUL:
this._singleValue.undefine();
this._minValue = undefined;
this._maxValue = undefined;
this._stepValue = undefined;
this._valueList = undefined;
break;
}
}
private checkValueMode(expected: ParamValueMode) {
if (this._valueMode != expected)
throw new Error(`ParamValues : mode de valeurs ${ParamValueMode[expected]} incorrect`);
} }
public get singleValue() { public get singleValue() {
return this._singleValue; this.checkValueMode(ParamValueMode.SINGLE);
return this._singleValue.value;
}
public get uncheckedValue() {
this.checkValueMode(ParamValueMode.SINGLE);
return this._singleValue.uncheckedValue;
} }
public set singleValue(v: number) { public set singleValue(v: number) {
this._singleValue = v; this._singleValue.value = v;
this.valueMode = ParamValueMode.SINGLE;
}
public get isDefined() {
this.checkValueMode(ParamValueMode.SINGLE);
return this._singleValue.isDefined;
} }
public get min() { public get min() {
this.checkValueMode(ParamValueMode.MINMAX);
return this._minValue; return this._minValue;
} }
public set min(v: number) { public set min(v: number) {
this._minValue = v; this._minValue = v;
this.valueMode = ParamValueMode.MINMAX;
} }
public get max() { public get max() {
this.checkValueMode(ParamValueMode.MINMAX);
return this._maxValue; return this._maxValue;
} }
public set max(v: number) { public set max(v: number) {
this._maxValue = v; this._maxValue = v;
this.valueMode = ParamValueMode.MINMAX;
} }
public get stepRefValue(): Pair { public get stepRefValue(): Pair {
this.checkValueMode(ParamValueMode.MINMAX);
return new Pair(1e-9, this._maxValue - this._minValue); return new Pair(1e-9, this._maxValue - this._minValue);
} }
public get step() { public get step() {
this.checkValueMode(ParamValueMode.MINMAX);
return this._stepValue; return this._stepValue;
} }
public set step(v: number) { public set step(v: number) {
this._stepValue = v; this._stepValue = v;
this.valueMode = ParamValueMode.MINMAX;
} }
public get valueList() { public get valueList() {
this.checkValueMode(ParamValueMode.LISTE);
return this._valueList; return this._valueList;
} }
public set valueList(l: number[]) { public set valueList(l: number[]) {
this._valueList = l; this._valueList = l;
this.valueMode = ParamValueMode.LISTE;
} }
public getValuesIterator(reverse: boolean = false): ParamValueIterator { public getValuesIterator(reverse: boolean = false): ParamValueIterator {
...@@ -255,6 +322,7 @@ export class ParamValues { ...@@ -255,6 +322,7 @@ export class ParamValues {
*/ */
public copyMembers(n: ParamValues) { public copyMembers(n: ParamValues) {
n._valueMode = this.valueMode; n._valueMode = this.valueMode;
n._singleValue = new DefinedNumber(this._singleValue.value);
n._minValue = this._minValue; n._minValue = this._minValue;
n._maxValue = this._maxValue; n._maxValue = this._maxValue;
n._stepValue = this._stepValue; n._stepValue = this._stepValue;
......
Supports Markdown
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