From 0d5fc5fbd09402508e32f5acb4d1707699096c56 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Mon, 12 Mar 2018 15:13:30 +0100
Subject: [PATCH] =?UTF-8?q?introduction=20de=20la=20classe=20JalhydObject?=
 =?UTF-8?q?=20destin=C3=A9e=20=C3=A0=20=C3=AAtre=20la=20base=20des=20param?=
 =?UTF-8?q?=C3=A8tres,=20r=C3=A9sultats,=20...?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/jalhyd_object.ts        | 25 +++++++++++++++++++++++++
 src/param.ts                | 27 +++++++++++++++++++++------
 src/section/section_type.ts |  2 +-
 3 files changed, 47 insertions(+), 7 deletions(-)
 create mode 100644 src/jalhyd_object.ts

diff --git a/src/jalhyd_object.ts b/src/jalhyd_object.ts
new file mode 100644
index 00000000..8c01127d
--- /dev/null
+++ b/src/jalhyd_object.ts
@@ -0,0 +1,25 @@
+export abstract class JalhydObject {
+    /**
+    * id numérique unique
+    */
+    private _uid: number;
+
+    /**
+     * générateur d'id
+     */
+    private static _uidSequence: number = 0;
+
+    constructor() {
+        this._uid = JalhydObject.nextUID;
+    }
+
+    public get uid(): number {
+        return this._uid;
+    }
+
+    public static get nextUID(): number {
+        let res = this._uidSequence;
+        this._uidSequence++;
+        return res;
+    }
+}
diff --git a/src/param.ts b/src/param.ts
index 98268a09..ed9b00ad 100644
--- a/src/param.ts
+++ b/src/param.ts
@@ -3,6 +3,7 @@ import { DefinedNumber } from "./util/definedvalue";
 import { Interval } from "./util/interval";
 import { Message, MessageCode } from "./util/message";
 import { MapIterator } from "./util/iterator";
+import { JalhydObject } from "./jalhyd_object";
 
 /**
  * domaine de définition du paramètre
@@ -168,7 +169,7 @@ export enum ParamCalculability {
  * paramètre avec symbole et domaine de définition
  */
 // tslint:disable-next-line:max-classes-per-file
-export class BaseParam extends DefinedNumber {
+export class BaseParam extends JalhydObject {
     /**
      * symbole
      */
@@ -179,9 +180,15 @@ export class BaseParam extends DefinedNumber {
      */
     private _domain: ParamDomain;
 
+    /**
+     * valeur numérique (éventuellement non définie)
+     */
+    private _value: DefinedNumber;
+
     constructor(symb: string, d: ParamDomain | ParamDomainValue, val?: number) {
-        super(val);
+        super();
         this._symbol = symb;
+        this._value = new DefinedNumber(val);
 
         if (d instanceof ParamDomain) {
             this._domain = d;
@@ -208,23 +215,31 @@ export class BaseParam extends DefinedNumber {
      * gestion de la valeur
      */
 
+    public get isDefined(): boolean {
+        return this._value.isDefined;
+    }
+
     public getValue(): number {
-        if (!this.isDefined) {
+        if (!this._value.isDefined) {
             const e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_UNDEFINED);
             e.extraVar.symbol = this.symbol;
             throw e;
         }
 
-        return super.getValue();
+        return this._value.value;
     }
 
     public setValue(val: number) {
         this.checkValue(val);
-        super.setValue(val);
+        this._value.value = val;
 
         //        console.log("setting param " + this._symbol + " id=" + this._id + " to " + val); // A VIRER
     }
 
+    public get uncheckedValue(): number {
+        return this._value.uncheckedValue;
+    }
+
     public checkValue(v: number) {
         const sDomain = ParamDomainValue[this._domain.domain];
 
@@ -281,7 +296,7 @@ export class BaseParam extends DefinedNumber {
 }
 
 /**
- * définition d'un paramètre d'un neud de calcul
+ * définition d'un paramètre d'un noeud de calcul
  */
 // tslint:disable-next-line:max-classes-per-file
 export class ParamDefinition extends BaseParam {
diff --git a/src/section/section_type.ts b/src/section/section_type.ts
index 99f98b1f..7cc0467d 100644
--- a/src/section/section_type.ts
+++ b/src/section/section_type.ts
@@ -262,7 +262,7 @@ export abstract class acSection extends ComputeNode {
                 this.debug("in calcFromY(" + sDonnee + ", rY=" + rY + ") old " + sDonnee + "=" + this.arCalc[sDonnee]);
                 this.debug("this.Y=" + this.prms.Y.toString());
 
-                if (rY != undefined && (!this.prms.Y.isDefined || rY != this.prms.Y.v)) {
+                if (rY != undefined && (!this.prms.Y.isDefined || (this.prms.Y.isDefined && rY != this.prms.Y.v))) {
                         this.prms.Y.v = rY;
                         // On efface toutes les données dépendantes de Y pour forcer le calcul
                         this.Reset(false);
-- 
GitLab