From c36d652fa0ed635d116396be7fac9e7025bfe5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Sat, 28 May 2022 19:31:14 +0200 Subject: [PATCH] fix: fields not empty on pre-dams calculator creation with "empty fields" option refs #546 --- .../pb-schema/pb-schema.component.ts | 11 +++++---- .../formulaire/definition/form-pb-cloison.ts | 6 +++-- src/app/services/formulaire.service.ts | 23 ++++++++++--------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index b2f00304c..c37219926 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -453,13 +453,14 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni // never let an unconnected basin ! (not done in model to prevent unwanted // automatic child addition when clearing children) if (this._selectedItem instanceof PbCloison) { + const emptyFields: boolean = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // if no downstream connections remain, connect to river downstream if (this._selectedItem.bassinAmont?.cloisonsAval.length === 0) { - this.model.addChild(new PbCloison(this._selectedItem.bassinAmont, undefined)); + this.model.addChild(new PbCloison(this._selectedItem.bassinAmont, undefined, undefined, emptyFields)); } // if no upstream connections remain, connect to river upstream if (this._selectedItem.bassinAval?.cloisonsAmont.length === 0) { - this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval)); + this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval, undefined, emptyFields)); } } this.clearResults(); @@ -486,7 +487,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni /** Copies a wall */ public onCopyClick() { const wall = this._selectedItem as PbCloison; - const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval); + const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval, undefined, ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit); wallCopy.loadObjectRepresentation(wall.objectRepresentation()); this.model.addChild(wallCopy); this.clearResults(); @@ -532,7 +533,9 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni if (result.up !== undefined && result.down !== undefined) { const wall = new PbCloison( result.up === 0 ? undefined : this.model.bassins[result.up - 1], - result.down === 0 ? undefined : this.model.bassins[result.down - 1] + result.down === 0 ? undefined : this.model.bassins[result.down - 1], + undefined, + ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit ); this.model.addChild(wall); this.clearResults(); diff --git a/src/app/formulaire/definition/form-pb-cloison.ts b/src/app/formulaire/definition/form-pb-cloison.ts index f7680be3a..02934c401 100644 --- a/src/app/formulaire/definition/form-pb-cloison.ts +++ b/src/app/formulaire/definition/form-pb-cloison.ts @@ -6,6 +6,7 @@ import { FormulaireNode } from "../elements/formulaire-node"; import { FieldsetContainer } from "../elements/fieldset-container"; import { FormulairePrebarrage } from "./form-prebarrage"; import { SelectFieldCustom } from "../elements/select-field-custom"; +import { ServiceFactory } from "app/services/service-factory"; export class FormulairePbCloison extends FormulaireParallelStructure { @@ -43,6 +44,7 @@ export class FormulairePbCloison extends FormulaireParallelStructure { if (sender instanceof SelectFieldCustom) { const nub = this._currentNub as PbCloison; const pb = nub.parent; + const emptyFields: boolean = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // empty "" data.value.value should return undefined, which is good for amont/aval const newBasin = pb.findChild(data.value?.value) as PbBassin; if (sender.id === "select_upstream_basin") { @@ -52,7 +54,7 @@ export class FormulairePbCloison extends FormulaireParallelStructure { const uid = nub.uid; const oldDownstreamBasin = nub.bassinAval; pb.deleteChild(pb.findChildPosition(nub.uid)); - const newWall = new PbCloison(newBasin, oldDownstreamBasin); + const newWall = new PbCloison(newBasin, oldDownstreamBasin, undefined, emptyFields); newWall.setUid(uid); // copy structures for (const s of nub.structures) { @@ -69,7 +71,7 @@ export class FormulairePbCloison extends FormulaireParallelStructure { const uid = nub.uid; const oldUpstreamBasin = nub.bassinAmont; pb.deleteChild(pb.findChildPosition(nub.uid)); - const newWall = new PbCloison(oldUpstreamBasin, newBasin); + const newWall = new PbCloison(oldUpstreamBasin, newBasin, undefined, emptyFields); newWall.setUid(uid); // copy structures for (const s of nub.structures) { diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index 1bfdbe14f..bf650c62b 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -453,21 +453,22 @@ export class FormulaireService extends Observable { && f.currentNub instanceof PreBarrage && f.currentNub.children.length === 0 ) { + const emptyFields: boolean = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // 1 basin - f.currentNub.addChild(new PbBassin(new PbBassinParams(13.80, 95))); + f.currentNub.addChild(new PbBassin(new PbBassinParams(13.80, 95, emptyFields))); // 1st wall - f.currentNub.addChild(new PbCloison(undefined, f.currentNub.children[0] as PbBassin)); - const s1: Structure = CreateStructure(LoiDebit.WeirCunge80); - s1.prms.ZDV.singleValue = 95.30; - s1.getParameter("L").singleValue = 0.4; - s1.getParameter("CdGR").singleValue = 1.04; + f.currentNub.addChild(new PbCloison(undefined, f.currentNub.children[0] as PbBassin, undefined, emptyFields)); + const s1: Structure = CreateStructure(LoiDebit.WeirCunge80, undefined, undefined, emptyFields); + // s1.prms.ZDV.singleValue = 95.30; + // s1.getParameter("L").singleValue = 0.4; + // s1.getParameter("CdGR").singleValue = 1.04; f.currentNub.children[1].addChild(s1); // 2nd wall - f.currentNub.addChild(new PbCloison(f.currentNub.children[0] as PbBassin, undefined)); - const s2: Structure = CreateStructure(LoiDebit.WeirCunge80); - s2.prms.ZDV.singleValue = 95.30; - s2.getParameter("L").singleValue = 0.4; - s2.getParameter("CdGR").singleValue = 1.04; + f.currentNub.addChild(new PbCloison(f.currentNub.children[0] as PbBassin, undefined, undefined, emptyFields)); + const s2: Structure = CreateStructure(LoiDebit.WeirCunge80, undefined, undefined, emptyFields); + // s2.prms.ZDV.singleValue = 95.30; + // s2.getParameter("L").singleValue = 0.4; + // s2.getParameter("CdGR").singleValue = 1.04; f.currentNub.children[2].addChild(s2); } -- GitLab