From 95eff5263ff0df3396af7aed1543740fa005bb34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Tue, 8 Nov 2022 14:58:05 +0100
Subject: [PATCH] fix: backwater curve: wrong Y value passed to generated
 parametric section, remove button in select entries

refs #496
---
 src/app/app.module.ts                         |  2 -
 .../section-details-entry.component.html      |  6 --
 .../section-details-entry.component.scss      |  0
 .../section-details-entry.component.ts        | 55 -------------------
 .../select-section-details.component.html     |  6 +-
 .../select-section-details.component.ts       | 24 ++++++++
 src/app/results/remous-results.ts             | 41 +++++++++++---
 7 files changed, 60 insertions(+), 74 deletions(-)
 delete mode 100644 src/app/components/section-details-entry/section-details-entry.component.html
 delete mode 100644 src/app/components/section-details-entry/section-details-entry.component.scss
 delete mode 100644 src/app/components/section-details-entry/section-details-entry.component.ts

diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 702dabc0e..43b3b0b91 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -123,7 +123,6 @@ import { DialogConfirmLoadSessionURLComponent } from "./components/dialog-confir
 import { StructureFieldsetContainerComponent } from "./components/structure-fieldset-container/structure-fieldset-container.component";
 import { BasinFieldsetContainerComponent } from "./components/basin-fieldset-container/basin-fieldset-container.component";
 import { PrebarrageService } from "./services/prebarrage.service";
-import { SectionDetailsEntryComponent } from "./components/section-details-entry/section-details-entry.component";
 import { SelectSectionDetailsComponent } from "./components/select-section-details/select-section-details.component";
 
 const appRoutes: Routes = [
@@ -260,7 +259,6 @@ const appRoutes: Routes = [
         SessionPropertiesComponent,
         VarResultsComponent,
         VerificateurResultsComponent,
-        SectionDetailsEntryComponent,
         SelectSectionDetailsComponent
     ],
     providers: [ // services
diff --git a/src/app/components/section-details-entry/section-details-entry.component.html b/src/app/components/section-details-entry/section-details-entry.component.html
deleted file mode 100644
index 7ce439984..000000000
--- a/src/app/components/section-details-entry/section-details-entry.component.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<div fxLayout="row wrap" fxLayoutGap="10px">
-    <p>{{label}}</p>
-    <button mat-raised-button color="accent" id="generate-cr-sp" (click)="generateCrSp()">
-        {{ uitextGenerateRuSp }}
-    </button>
-</div>
diff --git a/src/app/components/section-details-entry/section-details-entry.component.scss b/src/app/components/section-details-entry/section-details-entry.component.scss
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/app/components/section-details-entry/section-details-entry.component.ts b/src/app/components/section-details-entry/section-details-entry.component.ts
deleted file mode 100644
index 477c7486f..000000000
--- a/src/app/components/section-details-entry/section-details-entry.component.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import { Component, Input } from '@angular/core';
-import { Router } from '@angular/router';
-import { FormulaireDefinition } from 'app/formulaire/definition/form-definition';
-import { FormulaireService } from 'app/services/formulaire.service';
-import { I18nService } from 'app/services/internationalisation.service';
-import { fv } from 'app/util';
-import { formattedValue } from 'jalhyd';
-
-/**
- * Bouton d'ouverture des détails de section hydraulique pour chaque point du graphe de "courbes de remous".
- * Utilisé comme entrées d'un select.
- */
-@Component({
-  selector: 'section-details-entry',
-  templateUrl: './section-details-entry.component.html',
-  styleUrls: ['./section-details-entry.component.scss']
-})
-export class SectionDetailsEntryComponent {
-  private _point: any;
-
-  @Input()
-  private set point(p: any) {
-    this._point = p;
-  }
-
-  constructor(
-    private intlService: I18nService,
-    private formulaireService: FormulaireService,
-    private router: Router
-  ) { }
-
-  public get label(): string {
-    if (this._point === undefined) {
-      return undefined;
-    }
-    return "x : " + formattedValue(this._point.x, 1) + " y : " + fv(this._point.y);
-  }
-
-  public get uitextGenerateRuSp() {
-    return this.intlService.localizeText("INFO_CALCULATOR_RESULTS_GENERATE_RU_SP");
-  }
-
-  /**
-   * Génère une SectionParametree à partir du module en cours
-   */
-  public async generateCrSp() {
-    const f: FormulaireDefinition = await this.formulaireService.generateParametricSectionForm(this._point.y);
-
-    // calculate form
-    f.doCompute();
-
-    // go to new form
-    this.router.navigate(["/calculator", f.uid]);
-  }
-}
diff --git a/src/app/components/select-section-details/select-section-details.component.html b/src/app/components/select-section-details/select-section-details.component.html
index bbb74ee25..4b3a06f5c 100644
--- a/src/app/components/select-section-details/select-section-details.component.html
+++ b/src/app/components/select-section-details/select-section-details.component.html
@@ -1,5 +1,5 @@
-<mat-select [placeholder]="uitextPlaceholder">
-    <mat-option *ngFor="let p of points">
-        <section-details-entry [point]=p></section-details-entry>
+<mat-select [placeholder]="uitextPlaceholder" (selectionChange)="generateCrSp($event.value)">
+    <mat-option *ngFor="let p of points" [value]="p">
+        {{ pointLabel(p) }}
     </mat-option>
 </mat-select>
\ No newline at end of file
diff --git a/src/app/components/select-section-details/select-section-details.component.ts b/src/app/components/select-section-details/select-section-details.component.ts
index 811e73291..58516fc2d 100644
--- a/src/app/components/select-section-details/select-section-details.component.ts
+++ b/src/app/components/select-section-details/select-section-details.component.ts
@@ -1,4 +1,9 @@
 import { Component, Input } from '@angular/core';
+import { Router } from '@angular/router';
+import { FormulaireDefinition } from 'app/formulaire/definition/form-definition';
+import { FormulaireService } from 'app/services/formulaire.service';
+import { fv } from 'app/util';
+import { formattedValue } from 'jalhyd';
 
 /**
  * liste déroulante de boutons de génération de formulaire "section paramétrée"
@@ -25,8 +30,27 @@ export class SelectSectionDetailsComponent {
   }
 
   constructor(
+    private formulaireService: FormulaireService,
+    private router: Router
   ) { }
 
+  public pointLabel(p: any): string {
+    return "x : " + formattedValue(p.x, 1) + " y : " + fv(p.z);
+  }
+
+  /**
+   * Génère une SectionParametree à partir du module en cours
+   */
+  public async generateCrSp(p: any) {
+    const f: FormulaireDefinition = await this.formulaireService.generateParametricSectionForm(p.y);
+
+    // calculate form
+    f.doCompute();
+
+    // go to new form
+    this.router.navigate(["/calculator", f.uid]);
+  }
+
   public get uitextPlaceholder() {
     return "Générer une section paramétrée pour...";
   }
diff --git a/src/app/results/remous-results.ts b/src/app/results/remous-results.ts
index 6b64caaf8..20f412f13 100644
--- a/src/app/results/remous-results.ts
+++ b/src/app/results/remous-results.ts
@@ -15,6 +15,12 @@ export class RemousResults extends CalculatorResults {
     /** pas de discrétisation */
     private _Dx: number;
 
+    /** cote de fond amont */
+    private _ZF1: number;
+
+    /** cote de fond aval */
+    private _ZF2: number;
+
     /** longueur du bief */
     private _Long: number;
 
@@ -80,17 +86,19 @@ export class RemousResults extends CalculatorResults {
     }
 
     public set parameters(p: CourbeRemousParams) {
+        const nub = p.parent as Nub;
+
         // pente du fond
-        this._penteFond = (p.parent as Nub).getParameter("If").singleValue;
+        this._penteFond = nub.getParameter("If").singleValue;
 
         // hauteur de berge
-        this._hautBerge = (p.parent as Nub).getParameter("YB").singleValue;
+        this._hautBerge = nub.getParameter("YB").singleValue;
 
         // longueur du bief
-        this._Long = (p.parent as Nub).getParameter("Long").singleValue;
+        this._Long = nub.getParameter("Long").singleValue;
 
         // pas d'espace
-        this._Dx = (p.parent as Nub).getParameter("Dx").singleValue;
+        this._Dx = nub.getParameter("Dx").singleValue;
 
         // série de valeurs de X
         this._xValues = new ParamDefinition(
@@ -98,6 +106,12 @@ export class RemousResults extends CalculatorResults {
             "ABSCISSE",
             ParamDomainValue.POS_NULL
         );
+
+        // cote de fond amont
+        this._ZF1 = nub.getParameter("ZF1").singleValue;
+
+        // cote de fond aval
+        this._ZF2 = nub.getParameter("ZF2").singleValue;
     }
 
     public get log(): cLog {
@@ -125,10 +139,21 @@ export class RemousResults extends CalculatorResults {
 
     private updatePoints() {
         this._points = this._result.resultElements.map((re) => {
-            let Y = re.getValue("flu");
-            if (Y === undefined)
-                Y = re.getValue("tor");
-            return { x: re.getValue("X"), y: Y };
+            const X = re.getValue("X");
+
+            // cote de fond
+            const k = X / this._Long;
+            const Zf = (this._ZF2 - this._ZF1) * k + this._ZF1;
+
+            // cote de l'eau
+            let Z = re.getValue("flu");
+            if (Z === undefined)
+                Z = re.getValue("tor");
+
+            // tirant d'eau
+            const Y = Z - Zf;
+
+            return { x: X, y: Y, z: Z };
         });
     }
 
-- 
GitLab