From 9a6f835e5f91d29d7fe5009bff6a60add48ea41a Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Wed, 31 Jul 2019 15:25:27 +0200
Subject: [PATCH] Move Nub.V method to getter ParamDefinition.V

---
 src/macrorugo/macrorugo.ts    |  4 ++--
 src/nub.ts                    | 16 +---------------
 src/param/param-definition.ts | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/macrorugo/macrorugo.ts b/src/macrorugo/macrorugo.ts
index 6cb7c29b..2a652cc4 100644
--- a/src/macrorugo/macrorugo.ts
+++ b/src/macrorugo/macrorugo.ts
@@ -70,7 +70,7 @@ export class MacroRugo extends Nub {
         // Cote de fond aval
         r.extraResults.ZF2 = this.prms.ZF1.v - this.prms.If.v * this.prms.L.v;
         // Vitesse débitante
-        r.extraResults.Vdeb = this.V(this.prms.Q) / this.prms.B.v / this.prms.Y.v;
+        r.extraResults.Vdeb = this.prms.Q.V / this.prms.B.v / this.prms.Y.v;
         // Froude
         const vg: number = r.extraResults.Vdeb / (1 - Math.sqrt(MacroRugo.fracAxAy * this.prms.C.v));
         r.extraResults.Fr = vg / Math.sqrt(MacroRugo.g * this.prms.Y.v);
@@ -81,7 +81,7 @@ export class MacroRugo extends Nub {
             Math.pow(r.extraResults.Fr, -2 / 3)
         );
         // Puissance dissipée
-        r.extraResults.PV = 1000 * MacroRugo.g * this.V(this.prms.Q) / this.prms.B.v * this.prms.If.v;
+        r.extraResults.PV = 1000 * MacroRugo.g * this.prms.Q.V / this.prms.B.v * this.prms.If.v;
         // Type d'écoulement
         if (this.prms.Y.v / this.prms.PBH.v < 1) {
             r.extraResults.ENUM_MacroRugoFlowType = MacroRugoFlowType.EMERGENT;
diff --git a/src/nub.ts b/src/nub.ts
index e2669f2b..d42cdba0 100644
--- a/src/nub.ts
+++ b/src/nub.ts
@@ -466,21 +466,6 @@ export abstract class Nub extends ComputeNode implements IObservable {
         return this._result;
     }
 
-    /**
-     * Renvoie la valeur actuelle d'un paramètre (valeur utilisateur ou résultat)
-     * @param p Paramètre
-     */
-    public V(p: ParamDefinition): number {
-        if (p.valueMode === ParamValueMode.CALCUL) {
-            if (this.result !== undefined) {
-                if (this.result.resultElement.ok) {
-                    return this.result.vCalc;
-                }
-            }
-        }
-        return p.currentValue;
-    }
-
     public addChild(child: Nub, after?: number) {
         if (after !== undefined) {
             this._children.splice(after + 1, 0, child);
@@ -931,6 +916,7 @@ export abstract class Nub extends ComputeNode implements IObservable {
                         ret.hasErrors = true;
                     }
                 } else {
+                    // tslint:disable-next-line:no-console
                     console.error(`session file : cannot find parameter ${p.symbol} in target Nub`);
                     ret.hasErrors = true;
                 }
diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts
index d6d2b2ba..3602bd98 100644
--- a/src/param/param-definition.ts
+++ b/src/param/param-definition.ts
@@ -1057,6 +1057,20 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
         return this.calculability === ParamCalculability.EQUATION;
     }
 
+    /**
+     * Renvoie la valeur actuelle du paramètre (valeur courante ou résultat si calculé)
+     */
+    get V(): number {
+        if (this.valueMode === ParamValueMode.CALCUL) {
+            if (this.parentNub.result !== undefined) {
+                if (this.parentNub.result.resultElement.ok) {
+                    return this.parentNub.result.vCalc;
+                }
+            }
+        }
+        return this.currentValue;
+    }
+
     public clone(): ParamDefinition {
         const res = new ParamDefinition(this._parent, this._symbol,
             this.domain.clone(), this._unit, this.singleValue, this._family, this.visible);
-- 
GitLab