diff --git a/spec/verificateur/verificateur.spec.ts b/spec/verificateur/verificateur.spec.ts index 82969208cac93c1974a60882ba11dcb76edd2306..bc4d21b435187fc2da52d6760dc05625ad414cff 100644 --- a/spec/verificateur/verificateur.spec.ts +++ b/spec/verificateur/verificateur.spec.ts @@ -28,7 +28,7 @@ function createPab(): Pab { const cl = Session.getInstance().createNub( new Props({ calcType: CalculatorType.Cloisons }) ) as Cloisons; - cl.parent = pab; + cl.setParent(pab); pab.children.push(cl); pab.children[0].structures[0] = CreateStructure(LoiDebit.WeirSubmergedLarinier, cl); const dw = Session.getInstance().createNub( @@ -237,7 +237,7 @@ describe("vérificateur de franchissement −", () => { pab.children[4].structures[0] = new StructureWeirVillemonte( // Échancrure (Villemonte 1957) pab.children[4].structures[0].prms as RectangularStructureParams ); - pab.children[4].structures[0].parent = pab.children[4]; + pab.children[4].structures[0].setParent(pab.children[4]); pab.children[4].structures[0].getParameter("L").singleValue = 0.35; pab.prms.Z2.singleValue = 30.4; // évite une chute trop importante à la cloison 5 // vérificateur diff --git a/src/nub.ts b/src/nub.ts index 73d7590ed73dae8aed6fcae6e94c422e62bbb28e..91c1c24270235a07a2e284a85d858f8d7b88758b 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -76,7 +76,15 @@ export abstract class Nub extends ComputeNode implements IObservable { public dichoStartIntervalMaxSteps: number = 100; /** pointer to parent Nub */ - public parent: Nub; + private _parent: Nub; + + public get parent(): Nub { + return this._parent; + } + + public setParent(p: Nub) { + this._parent = p; + } /** * Used by GUI for translation of the nub type in ngHyd (snackbar, ...). @@ -727,7 +735,7 @@ export abstract class Nub extends ComputeNode implements IObservable { this._children.push(child); } // add reference to parent collection (this) - child.parent = this; + child.setParent(this); // postprocessing this.adjustChildParameters(child); } @@ -1457,7 +1465,7 @@ export abstract class Nub extends ComputeNode implements IObservable { this.resetDefaultCalculatedParam(); } // add reference to parent collection (this) - child.parent = this; + child.setParent(this); } /** diff --git a/src/pab/pab.ts b/src/pab/pab.ts index 5ef89546c0e31e74c9d492c4e80b32b92903b4da..811081b426884e212e9182ee86c65362adc75a73 100644 --- a/src/pab/pab.ts +++ b/src/pab/pab.ts @@ -65,7 +65,7 @@ export class Pab extends FishPass { public set downWall(dw: CloisonAval) { this._downWall = dw; if (dw) { // might be undefined - dw.parent = this; // important + dw.setParent(this); // important // postprocessing this.adjustDownwallParameters(this.downWall); } diff --git a/src/prebarrage/pb_bassin.ts b/src/prebarrage/pb_bassin.ts index cac1c3cbe264ae4f28b8eebde9dbb58be0b7f28f..05022067bf926834847cdd151948edf8c4e792ea 100644 --- a/src/prebarrage/pb_bassin.ts +++ b/src/prebarrage/pb_bassin.ts @@ -20,8 +20,6 @@ export class PbBassin extends Nub { /** Liste des cloisons aval */ public cloisonsAval: PbCloison[]; - public parent: PreBarrage; - /** Débit transitant dans le bassin en m³/s */ public Q: number; @@ -86,6 +84,10 @@ export class PbBassin extends Nub { this.prms.ZF.calculability = ParamCalculability.FREE; } + public get parent(): PreBarrage { + return super.parent as PreBarrage; + } + public CalcQ(): number { this.Q = 0; for(const c of this.cloisonsAmont) { @@ -117,4 +119,4 @@ export class PbBassin extends Nub { order: String(this.order) }); } -} \ No newline at end of file +} diff --git a/src/prebarrage/pb_cloison.ts b/src/prebarrage/pb_cloison.ts index c4f19d285c570cef70136cb5ea53434bbb882452..07b39d44c2c5abe3d5c7a234c59d7c05e2c0bec1 100644 --- a/src/prebarrage/pb_cloison.ts +++ b/src/prebarrage/pb_cloison.ts @@ -9,9 +9,6 @@ import { Message, MessageCode } from "../util/message"; export class PbCloison extends ParallelStructure { - /** pointer to parent Nub */ - public parent: PreBarrage; - constructor(bassinAmont: PbBassin, bassinAval: PbBassin, dbg: boolean = false, nullParams: boolean = false) { super(new ParallelStructureParams(0, 0, 0, nullParams), dbg); // prevent multiple CALC params in session file @@ -24,6 +21,11 @@ export class PbCloison extends ParallelStructure { this._intlType = "Cloison"; } + /** pointer to parent Nub */ + public get parent(): PreBarrage { + return super.parent as PreBarrage; + } + /** Bassin à l'amont de la cloison ou undefined pour condition limite amont */ public get bassinAmont(): PbBassin { let basin: PbBassin; diff --git a/src/structure/factory_structure.ts b/src/structure/factory_structure.ts index f3bb70f810dbc631d318ced19f52458e8a799f86..f7e229685cf10d9214d9b5ff2101613873190e17 100755 --- a/src/structure/factory_structure.ts +++ b/src/structure/factory_structure.ts @@ -223,7 +223,7 @@ export function CreateStructure(loiDebit: LoiDebit, parentNub?: ParallelStructur // set reference to parent if (parentNub) { - ret.parent = parentNub; + ret.setParent(parentNub); // Set Structure Type ret.properties.setPropValue("structureType", StructureProperties.findCompatibleStructure(loiDebit, parentNub)); } diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts index 1ab776cf6d5d87fb5f1dcc0d06bd5924b137ad51..e8037fc96411821218809969b9aa0421cea2da7d 100644 --- a/src/structure/parallel_structure.ts +++ b/src/structure/parallel_structure.ts @@ -29,7 +29,7 @@ export class ParallelStructure extends Nub { public set structures(structures: Structure[]) { this._children = structures; this._children.forEach((s) => { - s.parent = this; + s.setParent(this); }); } diff --git a/src/structure/structure.ts b/src/structure/structure.ts index b9d3a0c99d481f95b6c9bbf90465df85f1bcb1f4..8ed8981aa0a33424e094a6695b00333a381c3b55 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -8,6 +8,7 @@ import { StructureParams } from "./structure_params"; import { LoiDebit, StructureProperties } from "./structure_props"; import { ParallelStructure } from "./parallel_structure"; import { round } from "../base"; +import { Nub } from "../nub"; /** * Flow mode: weir or orifice flow @@ -139,6 +140,15 @@ export abstract class Structure extends ChildNub { // completes props with structureType and loiDebit this._loiDebit = ld; this._props.setPropValue("loiDebit", this._loiDebit); + this.updateStructureType(); + } + + public setParent(p: Nub): void { + super.setParent(p); + this.updateStructureType(); + } + + private updateStructureType() { this._props.setPropValue("structureType", StructureProperties.findCompatibleStructure(this._loiDebit, this.parent as ParallelStructure)); }