From 9520206f9063eff6e3e5800a9f43818a2df29c66 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Thu, 26 Apr 2018 10:05:03 +0200
Subject: [PATCH] =?UTF-8?q?=20#47=20NubFactory=20:=20ajout=20de=20la=20m?=
 =?UTF-8?q?=C3=A9thode=20deleteSessionNub()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/nub_factory.ts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/nub_factory.ts b/src/nub_factory.ts
index 56a6a128..52907eb4 100644
--- a/src/nub_factory.ts
+++ b/src/nub_factory.ts
@@ -86,6 +86,24 @@ export class NubFactory {
         }
     }
 
+    private deleteStructureNub(n: Nub) {
+        if (n instanceof Structure) {
+            for (const sn of this._session)
+                if (sn.nub instanceof ParallelStructure) {
+                    const psn = sn.nub as ParallelStructure;
+                    let i = 0;
+                    for (const st of psn.structures) {
+                        if (st.uid == n.uid) {
+                            psn.deleteStructure(i);
+                            return;
+                        }
+                        i++;
+                    }
+                }
+            throw new Error(`NubFactory.deleteStructureNub() : la structure (uid ${n.uid}) à supprimer n'a pas été trouvée`);
+        }
+    }
+
     /**
      * remplace un SessionNub par un nouveau
      * @param sn SessionNub à remplacer
@@ -205,6 +223,19 @@ export class NubFactory {
         }
     }
 
+    public deleteSessionNub(sn: SessionNub) {
+        let i = 0;
+        for (const n of this._session) {
+            if (n.uid == sn.uid) {
+                this._session.splice(i, 1);
+                this.deleteStructureNub(sn.nub);
+                return;
+            }
+            i++;
+        }
+        throw new Error(`NubFactory.deleteSessionNub() : le SessionNub (uid ${sn.uid}) à supprimer n'a pas été trouvé`);
+    }
+
     private createSection(nt: ComputeNodeType): acSection {
         switch (nt) {
             case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle section convient
-- 
GitLab