From 194ebd7e4e9b71ef40703682157eb0280fe57a14 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Wed, 29 Jul 2020 15:27:23 +0200
Subject: [PATCH] Espece: load predefined species criteria #248

---
 src/verification/espece.ts | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/verification/espece.ts b/src/verification/espece.ts
index bb4d70a8..12c78dd7 100644
--- a/src/verification/espece.ts
+++ b/src/verification/espece.ts
@@ -953,6 +953,33 @@ export class Espece extends Nub implements Observer {
             }
         }
     }
+
+    /**
+     * Load ICE tables values into parameters, for a given species
+     * (used in GUI for loading predefined species)
+     */
+    public loadPredefinedSpecies(sp: FishSpecies) {
+        let found: boolean;
+        // for each param
+        for (const p of this.prms) {
+            if (p.symbol !== "OK") {
+                // reset current value
+                p.singleValue = undefined;
+                // whatever the pass type (criteria are supposed to apply to 1 pass type only)
+                found = false;
+                for (const pt of Object.keys(this.presets)) {
+                    const preset = this.presets[pt];
+                    if (! found && preset !== undefined && preset[sp] !== undefined && preset[sp][p.symbol] !== undefined) {
+                        found = true;
+                        // if (preset[sp][p.symbol] !== undefined) console.log(`-> setting ${p.symbol} to ${preset[sp][p.symbol]}`);
+                        // apply preset
+                        p.singleValue = preset[sp][p.symbol];
+                    }
+                }
+            }
+        }
+    }
+
     /** Parameters other than OK are just settings here, nothing can vary or be calculated */
     protected setParametersCalculability(): void {
         for (const p of this._prms) {
-- 
GitLab