From 0c6542ab30786dbfeef96c6af0f08adac8d3a49e Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Wed, 2 Oct 2019 14:52:09 +0200
Subject: [PATCH] Bief

---
 src/app/calculators/bief/bief.config.json     | 70 ++++++++++++++++++
 src/app/calculators/bief/bief.en.json         | 35 +++++++++
 src/app/calculators/bief/bief.fr.json         | 35 +++++++++
 src/app/config.json                           |  2 +-
 .../definition/concrete/form-bief.ts          | 71 +++++++++++++++++++
 src/app/formulaire/fieldset.ts                | 10 ++-
 src/app/formulaire/select-field.ts            | 18 ++++-
 src/app/services/formulaire.service.ts        |  6 ++
 src/locale/messages.en.json                   |  2 +
 src/locale/messages.fr.json                   |  2 +
 10 files changed, 248 insertions(+), 3 deletions(-)
 create mode 100644 src/app/calculators/bief/bief.config.json
 create mode 100644 src/app/calculators/bief/bief.en.json
 create mode 100644 src/app/calculators/bief/bief.fr.json
 create mode 100644 src/app/formulaire/definition/concrete/form-bief.ts

diff --git a/src/app/calculators/bief/bief.config.json b/src/app/calculators/bief/bief.config.json
new file mode 100644
index 000000000..58561811f
--- /dev/null
+++ b/src/app/calculators/bief/bief.config.json
@@ -0,0 +1,70 @@
+[
+    {
+        "id": "fs_water_line",
+        "type": "fieldset",
+        "fields": [
+            {
+                "id": "select_regime",
+                "type": "select",
+                "source": "bief_regime"
+            }
+        ]
+    },
+    {
+        "id": "fs_section",
+        "type": "fieldset",
+        "fields": [
+            {
+                "id": "select_section",
+                "type": "select",
+                "help": {
+                    "SectionRectangle": "hsl/types_sections.html#section-rectangulaire",
+                    "SectionCercle": "hsl/types_sections.html#section-circulaire",
+                    "SectionTrapeze": "hsl/types_sections.html#section-trapezoidale",
+                    "SectionPuissance": "hsl/types_sections.html#section-parabolique"
+                },
+                "source": "acsection_section"
+            },
+            "LargeurFond",
+            "Fruit",
+            "LargeurBerge",
+            "D",
+            "k"
+        ]
+    },
+    {
+        "id": "fs_bief",
+        "type": "fieldset",
+        "fields": [
+            "Ks",
+            "Long",
+            "YB",
+            "ZF1",
+            "ZF2"
+        ]
+    },
+    {
+        "id": "fs_condlim",
+        "type": "fieldset",
+        "fields": [
+            "Q",
+            "Z1",
+            "Z2"
+        ]
+    },
+    {
+        "id": "fs_param_calc",
+        "type": "fieldset",
+        "fields": [
+            "Dx"
+        ]
+    },
+    {
+        "type": "options",
+        "defaultNodeType": "SectionRectangle",
+        "defaultRegime": "Fluvial",
+        "sectionSourceId": "select_section",
+        "regimeSelectId": "select_regime",
+        "help": "hsl/bief.html"
+    }
+]
\ No newline at end of file
diff --git a/src/app/calculators/bief/bief.en.json b/src/app/calculators/bief/bief.en.json
new file mode 100644
index 000000000..056d28730
--- /dev/null
+++ b/src/app/calculators/bief/bief.en.json
@@ -0,0 +1,35 @@
+{
+    "fs_water_line": "Type of water line",
+    "select_regime": "Regime",
+
+    "select_regime_0": "Fluvial",
+    "select_regime_1": "Torrential",
+
+    "fs_section": "Type of section",
+    "select_section": "Choice of section type",
+
+    "select_section_SectionTrapeze": "Trapezoidal",
+    "select_section_SectionRectangle": "Rectangular",
+    "select_section_SectionCercle": "Circular",
+    "select_section_SectionPuissance": "Parabolic",
+
+    "LargeurFond": "Width at bottom",
+    "Fruit": "Bank slope",
+    "D": "Diameter",
+    "k": "Coefficient",
+    "LargeurBerge": "Width at embankment level",
+    "fs_bief": "Reach features",
+    "Ks": "Strickler coefficient",
+    "Hs": "Head",
+    "Long": "Length of reach",
+    "YB": "Embankment elevation",
+    "fs_condlim": "Boundary conditions",
+    "Q": "Upstream flow",
+    "S": "Wet surface",
+    "fs_param_calc": "Calculation parameters",
+    "Dx": "Discretisation step",
+    "Z1": "Upstream water elevation",
+    "Z2": "Downstream water elevation",
+    "ZF1": "Upstream bottom elevation",
+    "ZF2": "Downstream bottom elevation"
+}
\ No newline at end of file
diff --git a/src/app/calculators/bief/bief.fr.json b/src/app/calculators/bief/bief.fr.json
new file mode 100644
index 000000000..f22d1f024
--- /dev/null
+++ b/src/app/calculators/bief/bief.fr.json
@@ -0,0 +1,35 @@
+{
+    "fs_water_line": "Type de ligne d'eau",
+    "select_regime": "Régime",
+
+    "select_regime_0": "Fluvial",
+    "select_regime_1": "Torrentiel",
+
+    "fs_section": "Type de section",
+    "select_section": "Choix du type de section",
+
+    "select_section_SectionTrapeze": "Trapézoïdale",
+    "select_section_SectionRectangle": "Rectangulaire",
+    "select_section_SectionCercle": "Circulaire",
+    "select_section_SectionPuissance": "Parabolique",
+
+    "LargeurFond": "Largeur au fond",
+    "Fruit": "Fruit des berges",
+    "D": "Diamètre",
+    "k": "Coefficient",
+    "LargeurBerge": "Largeur de berge",
+    "fs_bief": "Caractéristiques du bief",
+    "Ks": "Coefficient de Strickler",
+    "Hs": "Charge",
+    "Long": "Longueur du bief",
+    "YB": "Hauteur de berge",
+    "fs_condlim": "Conditions aux limites",
+    "Q": "Débit amont",
+    "S": "Surface mouillée",
+    "Dx": "Pas de discrétisation",
+    "fs_param_calc": "Paramètres de calcul",
+    "Z1": "Cote de l'eau à l'amont",
+    "Z2": "Cote de l'eau à l'aval",
+    "ZF1": "Cote du fond à l'amont",
+    "ZF2": "Cote du fond à l'aval"
+}
\ No newline at end of file
diff --git a/src/app/config.json b/src/app/config.json
index d7fa13874..1b2da220f 100644
--- a/src/app/config.json
+++ b/src/app/config.json
@@ -38,7 +38,7 @@
                 "path": "surface-libre.jpg",
                 "credits": "David Dorchies / Irstea"
             },
-            "calculators": [ 2, 3, 4, 20 ]
+            "calculators": [ 2, 3, 4, 20, 21 ]
         },
         {
             "name": "HYDRAULIQUE_EN_CHARGE",
diff --git a/src/app/formulaire/definition/concrete/form-bief.ts b/src/app/formulaire/definition/concrete/form-bief.ts
new file mode 100644
index 000000000..7aa4a6950
--- /dev/null
+++ b/src/app/formulaire/definition/concrete/form-bief.ts
@@ -0,0 +1,71 @@
+import { IObservable, SectionNub, Session, BiefRegime } from "jalhyd";
+
+import { FormDefSection } from "../form-def-section";
+import { FieldSet } from "../../fieldset";
+import { FormulaireBase } from "./form-base";
+
+export class FormulaireBief extends FormulaireBase {
+
+    private _formSection: FormDefSection;
+
+    /** id du select configurant le régime */
+    private _regimeSelectId: string;
+
+    constructor() {
+        super();
+        this._formSection = new FormDefSection(this);
+        // default properties
+        this._props["regime"] = BiefRegime.Fluvial;
+    }
+
+    protected parseOptions(json: {}) {
+        super.parseOptions(json);
+        this._formSection.parseOptions(json);
+
+        // id du select configurant la méthode de résolution
+        this._regimeSelectId = this.getOption(json, "regimeSelectId");
+    }
+
+    public afterParseFieldset(fs: FieldSet) {
+        this._formSection.afterParseFieldset(fs);
+
+        // si le FieldSet contient le select de méthode de résolution
+        if (this._regimeSelectId) {
+            const sel = fs.getFormulaireNodeById(this._regimeSelectId);
+            if (sel) {
+                // on abonne le formulaire aux propriétés du FieldSet
+                fs.properties.addObserver(this);
+            }
+        }
+    }
+
+    // interface Observer
+
+    update(sender: IObservable, data: any) {
+
+        super.update(sender, data);
+
+        if (sender instanceof FieldSet && data.action === "propertyChange") {
+            switch (sender.id) {
+                case "fs_section":
+                    // replace underlying section without replacing whole Nub
+                    const newSect = Session.getInstance().createSection(data.value);
+                    (this._currentNub as SectionNub).setSection(newSect);
+                    // reflect changes in GUI
+                    for (const fs of this.allFieldsets) {
+                        // show / hide dependent fields
+                        fs.updateFields();
+                    }
+                    this.reset();
+                    break;
+
+                case "fs_water_line":
+                    console.log("reset water line");
+                    this.reset();
+                    // Either Z1 or Z2 is calculable, depending on Regime
+                    this.getFieldsetById("fs_condlim").updateFields();
+                    break;
+            }
+        }
+    }
+}
diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts
index 494e64140..b5d4978c5 100644
--- a/src/app/formulaire/fieldset.ts
+++ b/src/app/formulaire/fieldset.ts
@@ -1,6 +1,5 @@
 import {
     CalculatorType,
-    ComputeNodeType,
     ParamDefinition,
     LCMaterial,
     LoiDebit,
@@ -10,6 +9,7 @@ import {
     MethodeResolution,
     GrilleType,
     GrilleProfile,
+    BiefRegime,
 } from "jalhyd";
 
 import { FormulaireElement } from "./formulaire-element";
@@ -254,6 +254,10 @@ export class FieldSet extends FormulaireElement implements Observer {
             case "fs_grille": // Grille
                 this.setSelectValueFromProperty("select_grid_profile", "gridProfile");
                 break;
+
+            case "fs_water_line": // Bief
+                this.setSelectValueFromProperty("select_regime", "regime");
+                break;
         }
     }
 
@@ -315,6 +319,7 @@ export class FieldSet extends FormulaireElement implements Observer {
         this.setPropertyValueFromConfig(json, "defaultMaterial", "material", LCMaterial);
         this.setPropertyValueFromConfig(json, "defaultGridProfile", "gridProfile", GrilleProfile);
         this.setPropertyValueFromConfig(json, "defaultGridType", "gridType", GrilleType);
+        this.setPropertyValueFromConfig(json, "defaultRegime", "regime", BiefRegime);
         this.setPropertyValueFromConfig(json, "varCalc", "varCalc");
 
         this.updateFields();
@@ -404,6 +409,9 @@ export class FieldSet extends FormulaireElement implements Observer {
                         case "select_grid_profile": // Grille
                             this.setPropValue("gridProfile", data.value.value);
                             break;
+                        case "select_regime": // Bief
+                            this.setPropValue("regime", data.value.value);
+                            break;
                     }
                     break;
             }
diff --git a/src/app/formulaire/select-field.ts b/src/app/formulaire/select-field.ts
index ee83f1ae8..308b319b0 100644
--- a/src/app/formulaire/select-field.ts
+++ b/src/app/formulaire/select-field.ts
@@ -1,4 +1,15 @@
-import { LechaptCalmon, acSection, CourbeRemous, Nub, ParallelStructure, StructureType, LoiDebit, GrilleType, GrilleProfile } from "jalhyd";
+import {
+    BiefRegime,
+    LechaptCalmon,
+    acSection,
+    CourbeRemous,
+    Nub,
+    ParallelStructure,
+    StructureType,
+    LoiDebit,
+    GrilleType,
+    GrilleProfile
+ } from "jalhyd";
 
 import { Field } from "./field";
 import { SelectEntry } from "./select-entry";
@@ -172,6 +183,11 @@ export class SelectField extends Field {
                 this.addEntry(new SelectEntry(this._entriesBaseId + GrilleProfile.Rectangular, GrilleProfile.Rectangular));
                 this.addEntry(new SelectEntry(this._entriesBaseId + GrilleProfile.Hydrodynamic, GrilleProfile.Hydrodynamic));
                 break;
+
+            case "bief_regime": // Bief: type de régime
+                this.addEntry(new SelectEntry(this._entriesBaseId + BiefRegime.Fluvial, BiefRegime.Fluvial));
+                this.addEntry(new SelectEntry(this._entriesBaseId + BiefRegime.Torrentiel, BiefRegime.Torrentiel));
+                break;
         }
     }
 }
diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts
index 8741f40e1..65a60d25b 100644
--- a/src/app/services/formulaire.service.ts
+++ b/src/app/services/formulaire.service.ts
@@ -38,6 +38,7 @@ import { FormulairePab } from "../formulaire/definition/concrete/form-pab";
 import { FormulaireMacrorugoCompound } from "../formulaire/definition/concrete/form-macrorugo-compound";
 import { FormulaireLechaptCalmon } from "../formulaire/definition/concrete/form-lechapt-calmon";
 import { FormulaireGrille } from "../formulaire/definition/concrete/form-grille";
+import { FormulaireBief } from "../formulaire/definition/concrete/form-bief";
 
 @Injectable()
 export class FormulaireService extends Observable {
@@ -82,6 +83,7 @@ export class FormulaireService extends Observable {
         this.calculatorPaths[CalculatorType.Jet] = "jet";
         this.calculatorPaths[CalculatorType.Grille] = "grille";
         this.calculatorPaths[CalculatorType.Pente] = "pente";
+        this.calculatorPaths[CalculatorType.Bief] = "bief";
     }
 
     private get _intlService(): I18nService {
@@ -323,6 +325,10 @@ export class FormulaireService extends Observable {
                 f = new FormulaireGrille();
                 break;
 
+            case CalculatorType.Bief:
+                f = new FormulaireBief();
+                break;
+
             default:
                 f = new FormulaireBase();
         }
diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json
index e8cbdf1d3..4e2f733da 100644
--- a/src/locale/messages.en.json
+++ b/src/locale/messages.en.json
@@ -62,6 +62,8 @@
     "INFO_CALCULATOR_SAVE": "Save",
     "INFO_CALCULATOR_USED_BY": "Used by",
     "INFO_CALCULATOR_VALEURS": "Values",
+    "INFO_BIEF_TITRE_COURT": "Reach",
+    "INFO_BIEF_TITRE": "Up/downstream elevations of a reach",
     "INFO_CLOISONS_TITRE_COURT": "Cross walls",
     "INFO_CLOISONS_TITRE": "Fish ladder: Cross walls",
     "INFO_CLOSE_DIALOGUE_DEPENDING_MODULES": "The following modules depend on the one you are closing:",
diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json
index f2199ec48..39603c386 100644
--- a/src/locale/messages.fr.json
+++ b/src/locale/messages.fr.json
@@ -62,6 +62,8 @@
     "INFO_CALCULATOR_SAVE": "Enregistrer",
     "INFO_CALCULATOR_USED_BY": "Utilisé par",
     "INFO_CALCULATOR_VALEURS": "Valeurs",
+    "INFO_BIEF_TITRE_COURT": "Bief",
+    "INFO_BIEF_TITRE": "Cotes amont/aval d'un bief",
     "INFO_CLOISONS_TITRE_COURT": "Cloisons",
     "INFO_CLOISONS_TITRE": "Passe à bassins&nbsp;: Cloisons",
     "INFO_CLOSE_DIALOGUE_DEPENDING_MODULES": "Les modules suivants dépendent de celui que vous êtes en train de fermer :",
-- 
GitLab