diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 40217b619a7b18f79624bd14496f2433fe7ca2a1..e1e74c9e6fcf715c1a11c1da7dbf121960ea5801 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -5,7 +5,7 @@ import * as screenfull from "screenfull"; import { Screenfull } from "screenfull"; // @see https://github.com/sindresorhus/screenfull.js/issues/126#issuecomment-488796645 import { - PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable + PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable, ParamDefinition, ParamValueMode } from "jalhyd"; import * as mermaid from "mermaid"; @@ -20,6 +20,7 @@ import { FormulairePrebarrage } from "../../formulaire/definition/form-prebarrag import { AppComponent } from "../../app.component"; import { fv } from "app/util"; +import { FormulaireNode } from "app/formulaire/elements/formulaire-node"; /** * The interactive schema for calculator type "PreBarrage" (component) @@ -491,10 +492,35 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni return this.i18nService.localizeText("INFO_FIELDSET_COPY"); } + /** + * Set value of all single parameters to undefined, except for the given parameter ids + */ + private emptyFields(basin: PbBassin, except: string[] = FormulaireNode.NeverEmptyFields) { + // save current calculated param, as setting value on a CALC param will + // change its mode and choose another calculated param by default + let calcP: ParamDefinition; + for (const p of basin.parameterIterator) { + if ( + [ParamValueMode.SINGLE, ParamValueMode.CALCUL].includes(p.valueMode) + && !except.includes(p.symbol) + ) { + if (p.valueMode === ParamValueMode.CALCUL) { + calcP = p; + } + p.setValue(undefined); + } + } + // restore original calculated param + if (calcP !== undefined) { + calcP.setCalculated(); + } + } + /** Adds a new lone basin */ public onAddBasinClick() { const newBasin = new PbBassin(new PbBassinParams(20, 99)); this.model.addChild(newBasin); + this.emptyFields(newBasin); this.clearResults(); this.refreshWithSelection(newBasin.uid); this.calculatorComponent.showPBInputData = true; diff --git a/src/app/formulaire/elements/formulaire-node.ts b/src/app/formulaire/elements/formulaire-node.ts index b0e214f5ebd3f41a30c9918b2aea7ae5b4b3056c..4d48607af879a7bbfe7aadd459e61737db0787b6 100644 --- a/src/app/formulaire/elements/formulaire-node.ts +++ b/src/app/formulaire/elements/formulaire-node.ts @@ -12,7 +12,7 @@ export abstract class FormulaireNode implements IObservable { /** * fields in fieldset that must not be empty due to enableEmptyFieldsOnFormInit option */ - protected static NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL"]; + public static readonly NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL"]; /** aide en ligne */ protected _helpLink: string;