diff --git a/src/nub_factory.ts b/src/nub_factory.ts index c5df10bbe4da6a0345fb03aaa1a608c4943999a3..25923b665307f008c00e8e0456887af7f7869387 100644 --- a/src/nub_factory.ts +++ b/src/nub_factory.ts @@ -119,7 +119,6 @@ export class NubFactory { /** * déplace un SessionNub associé à un nub Structure d'une position vers la fin de la liste de structures * @param sn SessionNub à remplacer - * @param params propriété du nouveau SessionNub */ public moveStructureNubDown(sn: SessionNub) { const psn = this.findParallelStructureWithNub(sn.nub); diff --git a/src/structure/cloisons.ts b/src/structure/cloisons.ts index 6571566f3811c4e8bd621b17b1d537155527b935..1137494ce1b38b54298da6f5b1886fb5708b6db6 100644 --- a/src/structure/cloisons.ts +++ b/src/structure/cloisons.ts @@ -82,7 +82,7 @@ export class Cloisons extends ParallelStructure { } private updateKiviZRAM() { - for (const structure of this.structures) { + for (const structure of this._structures) { if (structure.prms instanceof StructureKiviParams) { structure.prms.ZRAM.v = this.prms.Z1.v - this.prms.PB.v; } diff --git a/src/structure/dever.ts b/src/structure/dever.ts index 51fba3774da8c764c46020016ed8dedf89c93c4b..df3b7d6a1fd0f2c0f517bc292bbe9484c7470b0f 100644 --- a/src/structure/dever.ts +++ b/src/structure/dever.ts @@ -60,7 +60,7 @@ export class Dever extends ParallelStructure { */ private calcA(): number { let A: number = 0; - for (const st of this.structures) { + for (const st of this._structures) { A += st.calcA(); } return A; diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts index 697c782fe37e54373872eed9f6e1d3e0c205ec2d..312b532d6ad9f5bbb2b82b3df7b5c2dda6887586 100644 --- a/src/structure/parallel_structure.ts +++ b/src/structure/parallel_structure.ts @@ -27,7 +27,12 @@ interface IStructureVarCalc { export class ParallelStructure extends Nub { /** Tableau des structures hydrauliques en parallèle */ - public structures: Structure[] = []; + protected _structures: Structure[] = []; + + /** getter only makes it kind of readonly */ + public get structures() { + return this._structures; + } /** * paramètres castés au bon type @@ -55,7 +60,7 @@ export class ParallelStructure extends Nub { public get parameterIterator(): IParamDefinitionIterator { const prms: ParamsEquation[] = []; prms.push(this._prms); - for (const st of this.structures) { + for (const st of this._structures) { prms.push(st.parameters); } return new ParamsEquationArrayIterator(prms); @@ -68,10 +73,12 @@ export class ParallelStructure extends Nub { */ public addStructure(structure: Structure, after?: number) { if (after !== undefined) { - this.structures.splice(after + 1, 0, structure); + this._structures.splice(after + 1, 0, structure); } else { - this.structures.push(structure); + this._structures.push(structure); } + // add reference to parent collection (this) + structure.parent = this; } /** @@ -80,18 +87,20 @@ export class ParallelStructure extends Nub { * @param structure nouvelle structure */ public replaceStructure(index: number, structure: Structure) { - if (index > -1 && index < this.structures.length) { - this.structures[index] = structure; + if (index > -1 && index < this._structures.length) { + this._structures[index] = structure; } else { throw new Error(`ParallelStructure.replaceStructure invalid index ${index}`); } + // add reference to parent collection (this) + structure.parent = this; } /** * @return true si la structure donnée est dans la liste */ public hasStructure(structure: Nub): boolean { - for (const s of this.structures) { + for (const s of this._structures) { if (s.uid === structure.uid) { return true; } @@ -104,11 +113,11 @@ export class ParallelStructure extends Nub { */ public moveStructureUp(structure: Structure) { let i = 0; - for (const s of this.structures) { + for (const s of this._structures) { if (s.uid === structure.uid && i > 0) { - const t = this.structures[i - 1]; - this.structures[i - 1] = this.structures[i]; - this.structures[i] = t; + const t = this._structures[i - 1]; + this._structures[i - 1] = this._structures[i]; + this._structures[i] = t; return; } i++; @@ -120,11 +129,11 @@ export class ParallelStructure extends Nub { */ public moveStructureDown(structure: Structure) { let i = 0; - for (const s of this.structures) { - if (s.uid === structure.uid && i < this.structures.length - 1) { - const t = this.structures[i]; - this.structures[i] = this.structures[i + 1]; - this.structures[i + 1] = t; + for (const s of this._structures) { + if (s.uid === structure.uid && i < this._structures.length - 1) { + const t = this._structures[i]; + this._structures[i] = this._structures[i + 1]; + this._structures[i + 1] = t; return; } i++; @@ -137,7 +146,11 @@ export class ParallelStructure extends Nub { */ public deleteStructure(index: number) { if (index > -1) { - this.structures.splice(index, 1); + const removedStructures = this._structures.splice(index, 1); + if (removedStructures && removedStructures.length === 1) { + // remove reference to parent collection (this) + removedStructures[0].parent = undefined; + } } else { throw new Error("ParallelStructure.deleteStructure invalid index=" + index); } @@ -159,17 +172,17 @@ export class ParallelStructure extends Nub { */ public CalcQ(iExcept?: number): Result { if (iExcept !== undefined) { - if (iExcept < 0 || iExcept >= this.structures.length) { + if (iExcept < 0 || iExcept >= this._structures.length) { throw new Error( - "ParallelStructure.CalcQ iExcept not in [0;" + (this.structures.length - 1) + "]", + "ParallelStructure.CalcQ iExcept not in [0;" + (this._structures.length - 1) + "]", ); } } const calcRes: Result = new Result(0); let qTot: number = 0; - for (let i = 0; i < this.structures.length; i++) { + for (let i = 0; i < this._structures.length; i++) { if (i !== iExcept) { - const res: Result = this.structures[i].Calc("Q"); + const res: Result = this._structures[i].Calc("Q"); calcRes.resultElement.AddResultElementToExtra(res.resultElement, `ouvrage[${i}].Q`); qTot += res.vCalc; } @@ -204,7 +217,7 @@ export class ParallelStructure extends Nub { // Suppression des extraResults : ils sont complétés plus bas pour chaque ouvrage res.resultElement.extraResults = {}; if (res.ok) { - this.structures[sVC.index].getParameter(sVC.prm).setValue(res.vCalc); + this._structures[sVC.index].getParameter(sVC.prm).setValue(res.vCalc); } } if (res.ok) { @@ -225,13 +238,13 @@ export class ParallelStructure extends Nub { try { // analyse n.X const i: IStructureVarCalc = this.getStructureVarCalc(desc); - return this.structures[i.index].getParameter(i.prm); + return this._structures[i.index].getParameter(i.prm); } catch (e) { // desc n'est pas de la forme n.X try { // analyse ouvrage[n].X const i: IStructureVarCalc = this.getStructureVarCalc2(desc); - const res = this.structures[i.index].result; + const res = this._structures[i.index].result; if (res === undefined) { return undefined; // pas de résultat calculé } @@ -276,7 +289,7 @@ export class ParallelStructure extends Nub { let res = super.getLinkableValues(src); let i = 0; - for (const s of this.structures) { + for (const s of this._structures) { // paramètres liables des Nub structures enfants const l = s.getLinkableValues(src, `${i}.`, true); @@ -303,7 +316,7 @@ export class ParallelStructure extends Nub { * Mise à jour de Z1, Z2, h1 et h2 pour tous les ouvrages */ protected updateStructuresH1H2() { - for (const structure of this.structures) { + for (const structure of this._structures) { structure.prms.Z1.v = this.prms.Z1.v; structure.prms.Z2.v = this.prms.Z2.v; structure.prms.update_h1h2(); @@ -351,10 +364,10 @@ export class ParallelStructure extends Nub { */ private CalcStructPrm(sVC: IStructureVarCalc, rInit?: number, rPrec: number = 0.001): Result { // Le débit restant sur la structure en calcul est : - this.structures[sVC.index].prms.Q.setValue(this.prms.Q.v - this.CalcQ(sVC.index).vCalc); + this._structures[sVC.index].prms.Q.setValue(this.prms.Q.v - this.CalcQ(sVC.index).vCalc); // Calcul du paramètre de la structure en calcul - return this.structures[sVC.index].Calc(sVC.prm, rInit, rPrec); + return this._structures[sVC.index].Calc(sVC.prm, rInit, rPrec); } } diff --git a/src/structure/structure.ts b/src/structure/structure.ts index c3dfca928a2c59a0a010776e3383ad0010f2bf33..75535e390aff1ab6380462b7847be37aa861f8ff 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -4,6 +4,7 @@ import { Message, MessageCode } from "../util/message"; import { Result } from "../util/result"; import { StructureParams } from "./structure_params"; +import { ParallelStructure } from "./parallel_structure"; export { StructureParams }; @@ -16,7 +17,7 @@ export enum StructureFlowMode { /** Orifice flow */ ORIFICE, /** Zéro flow */ - NULL, + NULL } /** @@ -30,7 +31,7 @@ export enum StructureFlowRegime { /** Submerged flow */ SUBMERGED, /** Zéro flow */ - NULL, + NULL } /** @@ -42,7 +43,7 @@ export enum StructureJetType { /** Plongeant */ PLONGEANT, /** De surface */ - SURFACE, + SURFACE } /** @@ -60,6 +61,9 @@ export abstract class Structure extends Nub { /** Constante utile : Racine de 2g */ protected static readonly R2G: number = Math.sqrt(2 * 9.81); + /** pointer to collection of structures */ + public parent: ParallelStructure; + /** Peut-on calculer ZDV ? */ protected _isZDVcalculable: boolean;