From c3dce056e05779f726dd043ae4f7eb1598fe517c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Tue, 28 Mar 2023 08:48:50 +0200 Subject: [PATCH] refactor: add specific form class for MacroRugoRemous refs #609 --- .../calculators/macrorugoremous/config.json | 3 +- .../definition/form-macrorugo-remous.ts | 86 +++++++++++++++++++ src/app/services/formulaire.service.ts | 5 ++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/app/formulaire/definition/form-macrorugo-remous.ts diff --git a/src/app/calculators/macrorugoremous/config.json b/src/app/calculators/macrorugoremous/config.json index d9d176908..5eb0dfb7b 100644 --- a/src/app/calculators/macrorugoremous/config.json +++ b/src/app/calculators/macrorugoremous/config.json @@ -13,7 +13,8 @@ "id": "fs_condlim", "type": "fieldset", "fields": [ - "Z2" + "Z2", + "Q" ] }, { diff --git a/src/app/formulaire/definition/form-macrorugo-remous.ts b/src/app/formulaire/definition/form-macrorugo-remous.ts new file mode 100644 index 000000000..fffac2f9a --- /dev/null +++ b/src/app/formulaire/definition/form-macrorugo-remous.ts @@ -0,0 +1,86 @@ +import { RemousResults } from "app/results/remous-results"; +import { acSection, CourbeRemous, CourbeRemousParams, MacroRugo, MacroRugoRemous, Props, Result, Session } from "jalhyd"; +import { MacroRugoRemousParams } from "jalhyd/build/internal_modules"; +import { FormulaireFixedVar } from "./form-fixedvar"; + +export class FormulaireMacroRugoRemous extends FormulaireFixedVar { + public initNub(props?: Props) { + // scan session, find first PAM + let pam: MacroRugo; + for (const n of Session.getInstance().getAllNubs()) { + if (n instanceof MacroRugo) { + pam = n; + break; + } + } + if (pam !== undefined) { + props.setPropValue(MacroRugoRemous.NubMacroRugoProp, pam.uid); + } + return super.initNub(props); + } + + + /** résultats de courbes de remous */ + private _remousResults: RemousResults; + + private resultYn: Result; + + private resultYc: Result; + + constructor() { + super(); + this._remousResults = new RemousResults(this); + this.updateCalcResults(); + this._props["varCalc"] = ""; // important + } + + protected compute() { + this.reaffectResultComponents(); + } + + protected reaffectResultComponents() { + const mrr = this.currentNub as MacroRugoRemous; + + // variable supplémentaire à calculer + this._remousResults.extraParamSymbol = mrr.getPropValue("varCalc"); + + // calcul + this._remousResults.result = mrr.CalcSerie(); + + const prmMRR = mrr.prms as MacroRugoRemousParams; + this._remousResults.parameters = prmMRR; + + const sect: acSection = mrr.Sn; + this.resultYn = sect.CalcSection("Yn"); // hauteur normale + this.resultYc = sect.CalcSection("Yc"); // hauteur critique + + // données du graphique + this._remousResults.hauteurNormale = this.resultYn.resultElement; + this._remousResults.hauteurCritique = this.resultYc.resultElement; + if (this._remousResults.extraParamSymbol) { + this._remousResults.extraChart = !["Hs", "Hsc", "Ycor", "Ycon"].includes(this._remousResults.extraParamSymbol); + } else { + this._remousResults.extraChart = false; + } + this.updateCalcResults(); + } + + protected updateCalcResults() { + this._calcResults = []; + if (this._remousResults) { + // ensure help links are propagated + this._remousResults.helpLinks = this.helpLinks; + this._calcResults.push(this._remousResults); + } + } + + public resetFormResults() { + this._remousResults.reset(); + this.updateCalcResults(); + } + + public get hasResults(): boolean { + return this._remousResults.hasResults; + } + +} diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index a32a1aec4..019244c56 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -59,6 +59,7 @@ import { FormulairePrebarrage } from "../formulaire/definition/form-prebarrage"; import { ServiceFactory } from "./service-factory"; import { FormulairePressureLoss } from "app/formulaire/definition/form-pressureloss"; import { getNubResultUnit } from "jalhyd"; +import { FormulaireMacroRugoRemous } from "app/formulaire/definition/form-macrorugo-remous"; @Injectable() export class FormulaireService extends Observable { @@ -344,6 +345,10 @@ export class FormulaireService extends Observable { f = new FormulairePressureLoss(); break; + case CalculatorType.MacroRugoRemous: + f = new FormulaireMacroRugoRemous(); + break; + default: f = new FormulaireFixedVar(); } -- GitLab