From 94dacd7d3450464f8b2bb38fa837b129a42ac71d Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Fri, 10 May 2019 14:59:44 +0200
Subject: [PATCH] PAB: added mechanisms related to downWall

---
 src/pab/pab.ts | 19 +++++++++++++++++++
 src/session.ts | 22 +++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/pab/pab.ts b/src/pab/pab.ts
index 4833c18e..f56c5311 100644
--- a/src/pab/pab.ts
+++ b/src/pab/pab.ts
@@ -1,6 +1,7 @@
 import { CalculatorType } from "../compute-node";
 import { Nub } from "../nub";
 import { ParamCalculability } from "../param/param-definition";
+import { Session } from "../session";
 import { ParallelStructure } from "../structure/parallel_structure";
 import { Result } from "../util/result";
 import { PabCloisons } from "./pab_cloisons";
@@ -85,12 +86,26 @@ export class Pab extends Nub {
         return r;
     }
 
+    /**
+     * Finds the ParallelStructure targetted by modelUid and defines it as the current downWall
+     */
+    public setDownWall(modelUid: string) {
+        this.properties.setPropValue("modeleCloisonAval", modelUid);
+        const dw = (Session.getInstance().findNubByUid(modelUid) as ParallelStructure);
+        if (dw) {
+            this.downWall = dw;
+        } /* else {
+            console.error("Pab.setDownWall : cannot find target ParallelStructure");
+        } */
+    }
+
     /**
      * Once session is loaded, run a second pass on all PabCloisons to
      * reinit their target if needed
      */
     public fixPAB(obj: any) {
         if (obj.children && Array.isArray(obj.children)) {
+            // Cloisons models
             for (const c of obj.children) {
                 if (c.props.calcType === CalculatorType.PabCloisons) { // who knows ?
                     const childUid = c.uid;
@@ -102,6 +117,10 @@ export class Pab extends Nub {
                     } // else cannot find target
                 }
             }
+            // Downstream wall
+            if (obj.props.modeleCloisonAval) {
+                this.setDownWall(obj.props.modeleCloisonAval);
+            }
         }
     }
 
diff --git a/src/session.ts b/src/session.ts
index 0880b839..8e9b4042 100644
--- a/src/session.ts
+++ b/src/session.ts
@@ -372,12 +372,18 @@ export class Session {
             }
 
             case CalculatorType.Pab:
+                const modeleCloisonAval: string = params.getPropValue("modeleCloisonAval");
+                let downWall;
+                if (modeleCloisonAval) {
+                    downWall = (Session.getInstance().findNubByUid(modeleCloisonAval) as ParallelStructure);
+                    // si le module ParallelStructure ciblé n'existe pas, Session.fixPAB() est censé s'en occuper
+                }
                 nub = new Pab(
                     new PabParams(
                         1.5,    // Q
                         102,    // Z1
                         99      // Z2
-                    ), undefined, dbg
+                    ), downWall, dbg
                 );
                 break;
 
@@ -473,6 +479,20 @@ export class Session {
         return cloisonsNubs;
     }
 
+    /**
+     * Returns all Nubs of type ParallelStructure (no sub-types),
+     * to be used as downWall models in PAB
+     */
+    public getParallelStructureNubs() {
+        const psNubs: Nub[] = [];
+        for (const n of this._nubs) {
+            if (n.constructor === ParallelStructure) { // exact class checking
+                psNubs.push(n);
+            }
+        }
+        return psNubs;
+    }
+
     /**
      * Crée un Nub de type Section
      * @param nt ComputeNodeType
-- 
GitLab