diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 901fa13436d5ae5e5bf4f864a65dafa7a1c0e1e0..fc57d1653a54b9b69f994bf6ead3090235525c77 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -965,25 +965,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe * Génère une SectionParametree à partir du module RegimeUniforme en cours */ public async generateRuSp() { - const ru = (this._formulaire.currentNub as RegimeUniforme); - // copy section - const serialisedSection = ru.section.serialise(); - const sectionCopy = Session.getInstance().unserialiseSingleNub(serialisedSection, false).nub; - const secParam = new SectionParametree(sectionCopy as acSection); - // copy value of calculated param - const cp = ru.calculatedParam; - const scp = secParam.section.getParameter(cp.symbol); - if (cp.hasMultipleValues) { - scp.setValues(ru.result.getCalculatedValues().map(v => round(v, this.appSetupService.displayPrecision))); - } else { - scp.singleValue = ru.result.vCalc; - } - Session.getInstance().registerNub(secParam); - - const f: FormulaireDefinition = await this.formulaireService.createFormulaire(CalculatorType.SectionParametree, secParam); + const f = await this.formulaireService.generateParametricSectionForm(); // calculate f.doCompute(); // go to new SP + this.router.navigate(["/calculator", f.uid]); } public get generatePARSimulationEnabled(): boolean { diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index 4c9e42baa9e5dc138d02427ff9d4d4ad1520bad8..90095e6df9d235bfb3585c3d206f93828fbb8d43 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -21,7 +21,13 @@ import { LoiDebit, PbCloison, CreateStructure, - Structure + Structure, + SectionNub, + SectionParametree, + acSection, + round, + RegimeUniforme, + CourbeRemous } from "jalhyd"; import { ApplicationSetupService } from "./app-setup.service"; @@ -851,4 +857,32 @@ export class FormulaireService extends Observable { } } } + + /** + * Génère un formulaire SectionParametree à partir du module courant + * s'il est du type régime uniforme ou courbe de remous + */ + public async generateParametricSectionForm(): Promise<FormulaireDefinition> { + if (this.currentForm.currentNub instanceof SectionNub) { + const sn: SectionNub = this.currentForm.currentNub; + if (sn instanceof RegimeUniforme || sn instanceof CourbeRemous) { + // copy section + const serialisedSection = sn.section.serialise(); + const sectionCopy = Session.getInstance().unserialiseSingleNub(serialisedSection, false).nub; + const secParam = new SectionParametree(sectionCopy as acSection); + // copy value of calculated param + const cp: ParamDefinition = sn.calculatedParam; + const scp: ParamDefinition = secParam.section.getParameter(cp.symbol); + if (cp.hasMultipleValues) { + scp.setValues(sn.result.getCalculatedValues().map(v => round(v, this.appSetupService.displayPrecision))); + } else { + scp.singleValue = sn.result.vCalc; + } + Session.getInstance().registerNub(secParam); + + return await this.createFormulaire(CalculatorType.SectionParametree, secParam); + } + } + return Promise.reject("cannot create parametric section from current form"); + } }