From a2ae95f7804b847430f483ecc45ff6fe12c08569 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Mon, 29 Apr 2019 12:26:25 +0200
Subject: [PATCH] Update PAB after rebase

---
 spec/pab/pab.spec.ts      |  4 ++--
 src/pab/pab.ts            | 27 +++++++--------------------
 src/pab/pab_cloisons.ts   | 19 ++++++++++++-------
 src/structure/cloisons.ts |  1 +
 4 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/spec/pab/pab.spec.ts b/spec/pab/pab.spec.ts
index e31c5783..c32052ee 100644
--- a/spec/pab/pab.spec.ts
+++ b/spec/pab/pab.spec.ts
@@ -12,7 +12,7 @@ import { Cloisons, CloisonsParams } from "../../src/structure/cloisons";
 import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params";
 import { StructureWeirSubmergedLarinier } from "../../src/structure/structure_weir_submerged_larinier";
 
-const dbg: boolean = true;
+const dbg: boolean = false;
 
 /**
  * Exemple formation Cassiopée 2018-09
@@ -41,7 +41,7 @@ const rectStructPrms = new RectangularStructureParams(
 );
 
 // Ajout d'ouvrage dans la cloison
-modelCloisons.addStructure(new StructureWeirSubmergedLarinier(rectStructPrms, dbg));
+modelCloisons.addChild(new StructureWeirSubmergedLarinier(rectStructPrms, dbg));
 
 // Création de la passe
 
diff --git a/src/pab/pab.ts b/src/pab/pab.ts
index 3b58e19e..1bef4aeb 100644
--- a/src/pab/pab.ts
+++ b/src/pab/pab.ts
@@ -15,8 +15,12 @@ export class Pab extends Nub {
         return this._prms as PabParams;
     }
 
-    /** Tableau des cloisons en série */
-    protected _pabCloisons: PabCloisons[] = [];
+    /**
+     * enfants castés au bon type
+     */
+    get children(): PabCloisons[] {
+        return this._children as PabCloisons[];
+    }
 
     /**
      * Calcul analytique
@@ -25,7 +29,7 @@ export class Pab extends Nub {
     public Equation(sVarCalc: string): Result {
         const r: Result = new Result(0, this);
         let Z: number = this.prms.Z2.v;
-        for (const cloison of this._pabCloisons) {
+        for (const cloison of this.children) {
             cloison.prms.Z2.v = Z;
             cloison.Calc("Z1");
             Z = cloison.prms.Z1.v;
@@ -34,23 +38,6 @@ export class Pab extends Nub {
         return r;
     }
 
-    /**
-     * Ajout d'une cloison en série
-     * @param structure La structure à rajouter
-     * @param after position après laquelle insérer la cloison, à la fin sinon
-     */
-    public addChild(pabCloisons: PabCloisons, after?: number) {
-        if (after !== undefined) {
-            this._pabCloisons.splice(after + 1, 0, pabCloisons);
-        } else {
-            this._pabCloisons.push(pabCloisons);
-        }
-        // add reference to parent collection (this)
-        pabCloisons.parent = this;
-        // propagate precision
-        pabCloisons.prms.Pr.setValue(this.prms.Pr.v); // does not write to .v to bypass calculability control
-    }
-
     /**
      * paramétrage de la calculabilité des paramètres
      */
diff --git a/src/pab/pab_cloisons.ts b/src/pab/pab_cloisons.ts
index 631fdd64..a80edbb8 100644
--- a/src/pab/pab_cloisons.ts
+++ b/src/pab/pab_cloisons.ts
@@ -6,7 +6,7 @@ import { Pab } from "./pab";
 
 class PabCloisonsParams extends CloisonsParams {
 
-   /** Débit entrant à l'amont de la passe (m3/s) */
+   /** Débit d'attrait d'un bassin (m3/s) */
    public QA: ParamDefinition;
 
     /**
@@ -27,6 +27,16 @@ class PabCloisonsParams extends CloisonsParams {
             modelCloisonsParams.PB.v,
             modelCloisonsParams.DH.v
         );
+        this.init(modelCloisonsParams);
+
+        // On garde Pr en propre sur cet objet (Pointage impossible car en lecture seule)
+        this.addParamDefinition(this.Pr, true);
+
+        this.QA = new ParamDefinition(this, "QA", ParamDomainValue.ANY, rQA, ParamFamily.FLOWS);
+        this.addParamDefinition(this.QA);
+    }
+
+    public init(modelCloisonsParams: CloisonsParams) {
         this.Q = modelCloisonsParams.Q;
         this.Z1 = modelCloisonsParams.Z1;
         this.LB = modelCloisonsParams.LB;
@@ -35,11 +45,6 @@ class PabCloisonsParams extends CloisonsParams {
         this.DH = modelCloisonsParams.DH;
         // Force la MAJ de la map avec les propriétés pointant vers celles de CloisonsParam
         this.addParamDefinitions(modelCloisonsParams);
-        // On garde Pr en propre sur cet objet (Pointage impossible car en lecture seule)
-        this.addParamDefinition(this.Pr, true);
-
-        this.QA = new ParamDefinition(this, "QA", ParamDomainValue.ANY, rQA, ParamFamily.FLOWS);
-        this.addParamDefinition(this.QA);
     }
 
 }
@@ -51,7 +56,7 @@ export class PabCloisons extends Cloisons {
 
     constructor(modelCloisons: Cloisons, rQA: number = 0, dbg: boolean = false) {
         super(new PabCloisonsParams(modelCloisons.prms, rQA), dbg);
-        this._structures = modelCloisons.structures;
+        this._children = modelCloisons.structures;
     }
 
     /**
diff --git a/src/structure/cloisons.ts b/src/structure/cloisons.ts
index 19eb0a07..056bf4f2 100644
--- a/src/structure/cloisons.ts
+++ b/src/structure/cloisons.ts
@@ -7,6 +7,7 @@ import { ParallelStructure } from "./parallel_structure";
 import { StructureKiviParams } from "./structure_kivi";
 import { loiAdmissiblesCloisons, LoiDebit } from "./structure_props";
 
+export { CloisonsParams };
 export class Cloisons extends ParallelStructure {
     constructor(prms: CloisonsParams, dbg: boolean = false) {
         super(prms, dbg);
-- 
GitLab