Skip to content
Snippets Groups Projects
form-macrorugo-remous.ts 2.83 KiB
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;
        mrr.syncSectionMacroRugo();
        
        // 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;

        // calcul
        this._remousResults.result = mrr.CalcSerie();

        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;
    }

}