From 145968a5e74eae1cc8ed1857e939d41bd35191f5 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 8 Oct 2019 16:27:32 +0200 Subject: [PATCH] Bief: add buttons to generate up/downstream SectionParametree --- .../calculator.component.html | 9 ++ .../calculator.component.scss | 9 ++ .../calculator.component.ts | 92 ++++++++++++++----- src/locale/messages.en.json | 2 + src/locale/messages.fr.json | 2 + 5 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html index 2cde586a4..b8d29a5a3 100644 --- a/src/app/components/generic-calculator/calculator.component.html +++ b/src/app/components/generic-calculator/calculator.component.html @@ -104,6 +104,15 @@ {{ uitextGeneratePAB }} </button> + <div *ngIf="isBief" class="multi-buttons-container"> + <button mat-raised-button color="accent" id="generate-sp-amont" (click)="generateSPAmont()"> + {{ uitextGenerateSPAmont }} + </button> + <button mat-raised-button color="accent" id="generate-sp-aval" (click)="generateSPAval()"> + {{ uitextGenerateSPAval }} + </button> + </div> + <mat-card-content> <calc-results id="resultsComp" (afterViewChecked)="onCalcResultsViewChecked()"></calc-results> </mat-card-content> diff --git a/src/app/components/generic-calculator/calculator.component.scss b/src/app/components/generic-calculator/calculator.component.scss index b520db9c9..e48960ad0 100644 --- a/src/app/components/generic-calculator/calculator.component.scss +++ b/src/app/components/generic-calculator/calculator.component.scss @@ -66,6 +66,15 @@ mat-card { height: min-content; } } + + .multi-buttons-container { + button:nth-of-type(even) { + margin-top: .5em; + } + button:nth-of-type(odd) { + margin-right: .5em; + } + } } ::ng-deep .mat-card-header-text { diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 4bdf8c675..f655bd60f 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit, DoCheck, OnDestroy, ViewChild, ViewChildren, QueryList, AfterViewChecked, ElementRef, Inject, forwardRef } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; -import { Observer, Session, Cloisons, Pab, ParamValueMode, CalculatorType } from "jalhyd"; +import { Observer, Session, Cloisons, Pab, ParamValueMode, CalculatorType, Bief, SectionParametree, acSection, round, SessionSettings } from "jalhyd"; import { AppComponent } from "../../app.component"; import { FormulaireService } from "../../services/formulaire.service"; @@ -195,6 +195,14 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe return this.intlService.localizeText("INFO_CALCULATOR_RESULTS_GENERATE_PAB"); } + public get uitextGenerateSPAmont() { + return this.intlService.localizeText("INFO_CALCULATOR_RESULTS_GENERATE_SP_AMONT"); + } + + public get uitextGenerateSPAval() { + return this.intlService.localizeText("INFO_CALCULATOR_RESULTS_GENERATE_SP_AVAL"); + } + public get uitextOpenHelp() { return this.intlService.localizeText("INFO_CALCULATOR_OPEN_HELP"); } @@ -497,6 +505,15 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe return this._formulaire && this._formulaire.helpLink; } + /** return true if current Nub type is ct */ + public is(ct: CalculatorType): boolean { + return ( + this._formulaire + && this._formulaire.currentNub + && this._formulaire.currentNub.calcType === ct + ); + } + // for "one wide column" layout public get isWide() { return (this.isPAB || this.isMRC); @@ -504,38 +521,27 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe // true if current Nub is PAB public get isPAB() { - return ( - this._formulaire - && this._formulaire.currentNub - && this._formulaire.currentNub.calcType === CalculatorType.Pab - ); + return this.is(CalculatorType.Pab); } // true if current Nub is MacroRugoCompound public get isMRC() { - return ( - this._formulaire - && this._formulaire.currentNub - && this._formulaire.currentNub.calcType === CalculatorType.MacroRugoCompound - ); + return this.is(CalculatorType.MacroRugoCompound); } // true if current Nub is Jet public get isJet() { - return ( - this._formulaire - && this._formulaire.currentNub - && this._formulaire.currentNub.calcType === CalculatorType.Jet - ); + return this.is(CalculatorType.Jet); } // for "generate PAB" button public get isPABCloisons() { - return ( - this._formulaire - && this._formulaire.currentNub - && this._formulaire.currentNub.calcType === CalculatorType.Cloisons - ); + return this.is(CalculatorType.Cloisons); + } + + // true if current Nub is Bief + public get isBief() { + return this.is(CalculatorType.Bief); } /** @@ -611,6 +617,50 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe }); } + /** + * Génère une SectionParametree à partir des cotes amont du module Bief en cours + */ + public generateSPAmont() { + const bief = (this._formulaire.currentNub as Bief); + this.generateSP(round(bief.prms.Z1.singleValue - bief.prms.ZF1.singleValue, 3)); + } + + /** + * Génère une SectionParametree à partir des cotes aval du module Bief en cours + */ + public generateSPAval() { + const bief = (this._formulaire.currentNub as Bief); + this.generateSP(round(bief.prms.Z2.singleValue - bief.prms.ZF2.singleValue, 3)); + } + + /** + * Génère une SectionParametree à partir du module Bief en cours + * @param Y tirant d'eau + */ + private generateSP(Y: number) { + const bief = (this._formulaire.currentNub as Bief); + const pente = round( + (bief.prms.ZF1.singleValue - bief.prms.ZF2.singleValue) / bief.prms.Long.singleValue, + 5 // ça ou autre chose… + ); + const serialisedSection = bief.section.serialise(); + const sectionCopy = Session.getInstance().unserialiseSingleNub(serialisedSection, false).nub; + const secParam = new SectionParametree(sectionCopy as acSection); + Session.getInstance().registerNub(secParam); + + this.formulaireService.createFormulaire(CalculatorType.SectionParametree, secParam) + .then((f: FormulaireDefinition) => { + const sp = (f.currentNub as SectionParametree); + sp.section.prms.Y.singleValue = Y; + sp.section.prms.If.singleValue = pente; + // calculate + f.doCompute(); + // go to new SP + this.router.navigate(["/calculator", f.uid]).then(); + } + ); + } + public saveCalculator() { this.formulaireService.saveForm(this._formulaire); } diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 75e200113..d46b196a0 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -61,6 +61,8 @@ "INFO_CALCULATOR_OPEN_HELP": "Help", "INFO_CALCULATOR_PARAMFIXES": "Fixed parameters", "INFO_CALCULATOR_RESULTS_GENERATE_PAB": "Generate a fish ladder", + "INFO_CALCULATOR_RESULTS_GENERATE_SP_AMONT": "Hydraulic details of upstream section", + "INFO_CALCULATOR_RESULTS_GENERATE_SP_AVAL": "Hydraulic details of downstream section", "INFO_CALCULATOR_RESULTS_TITLE": "Results", "INFO_CALCULATOR_SAVE": "Save", "INFO_CALCULATOR_USED_BY": "Used by", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index b53cb3494..92a77bf9c 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -61,6 +61,8 @@ "INFO_CALCULATOR_OPEN_HELP": "Aide", "INFO_CALCULATOR_PARAMFIXES": "Paramètres fixés", "INFO_CALCULATOR_RESULTS_GENERATE_PAB": "Générer une passe à bassins", + "INFO_CALCULATOR_RESULTS_GENERATE_SP_AMONT": "Détails hydrauliques de la section amont", + "INFO_CALCULATOR_RESULTS_GENERATE_SP_AVAL": "Détails hydrauliques de la section aval", "INFO_CALCULATOR_RESULTS_TITLE": "Résultats", "INFO_CALCULATOR_SAVE": "Enregistrer", "INFO_CALCULATOR_USED_BY": "Utilisé par", -- GitLab