diff --git a/spec/pab/pab.spec.ts b/spec/pab/pab.spec.ts index 08a5aa183c504f920044bd9be11d484382bdabcf..d238f8a3feaf8375e002fdc97ab2cf4d853274bb 100644 --- a/spec/pab/pab.spec.ts +++ b/spec/pab/pab.spec.ts @@ -1,4 +1,3 @@ -import { ParamValueMode, Session } from "../../src/index"; import { CloisonAval } from "../../src/pab/cloison_aval"; import { CloisonsAvalParams } from "../../src/pab/cloison_aval_params"; import { Cloisons } from "../../src/pab/cloisons"; @@ -11,6 +10,8 @@ import { StructureVanLevVillemonte } from "../../src/structure/structure_vanlev_ import { StructureWeirSubmergedLarinier } from "../../src/structure/structure_weir_submerged_larinier"; import { StructureWeirVillemonte } from "../../src/structure/structure_weir_villemonte"; import { MessageCode } from "../../src/util/message"; +import { ParamValueMode } from "../../src/param/param-value-mode"; +import { Session } from "../../src/session"; const dbg: boolean = false; @@ -282,4 +283,29 @@ describe("Class Pab: ", () => { }); }); + describe("linking QA", () => { + + it("when there are more than 1 Cloison, QA should be linkable to its siblings", () => { + Session.getInstance().clear(); + Session.getInstance().registerNub(pab); + const lv = Session.getInstance().getLinkableValues(pab.children[0].prms.QA); + expect(lv.length).toBe(13); // example PAB has 14 walls + }); + + it("when there are more than 1 Pab, QA should be linkable to other Pab's QAs", () => { + const pab2 = createPabTest(); + Session.getInstance().clear(); + // keep only one wall + for (let i=0; i < 13; i++) { + pab.deleteChild(13 - i); + pab2.deleteChild(13 - i); + } + expect(pab.children.length).toBe(1); + expect(pab2.children.length).toBe(1); + Session.getInstance().registerNub(pab); + Session.getInstance().registerNub(pab2); + const lv = Session.getInstance().getLinkableValues(pab.children[0].prms.QA); + expect(lv.length).toBe(1); // the only wall of the 2nd PAB + }); + }); }); diff --git a/src/nub.ts b/src/nub.ts index 5e4011f4e8e7c6456c620d0b3bdbf11f8952980b..5c32e1c498704d580d18319ef86f9df7b4a8183c 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -789,7 +789,17 @@ export abstract class Nub extends ComputeNode implements IObservable { } // 3. children Nubs, except for PAB and MRC and PreBarrage - if (!(this instanceof Pab || this instanceof MacrorugoCompound || this._calcType === CalculatorType.PreBarrage)) { + if ( + ! (this instanceof MacrorugoCompound) + && ( // meta-except, if source param in a PAB's Cloison (should only apply to QA) + ! (this instanceof Pab) + || ( + src.originNub instanceof Pab + && src.symbol === "QA" + ) + ) + && this._calcType !== CalculatorType.PreBarrage + ) { for (const cn of this.getChildren()) { res = res.concat(cn.getLinkableValues(src)); } diff --git a/src/pab/pab.ts b/src/pab/pab.ts index 597d82631b0cac5d4f05d10bd8bd2fb1ff4549bf..716d7c818b7f28df4d9cf82a9f943cec6176ba24 100644 --- a/src/pab/pab.ts +++ b/src/pab/pab.ts @@ -1,5 +1,5 @@ import { CalculatorType } from "../compute-node"; -import { Session } from "../index"; +import { Session, JalhydObject } from "../index"; import { ParamValueMode } from "../index"; import { Nub } from "../nub"; import { ParamCalculability, ParamDefinition } from "../param/param-definition"; @@ -76,6 +76,7 @@ export class Pab extends FishPass { for (let i = 0; i < n; i++) { const cl: Cloisons = Session.getInstance().unserialiseSingleNub(serialisedCloisonModel, false).nub as Cloisons; + cl.setUid(JalhydObject.nextUID); // prevent all Cloisons having the same UID const p = cl.prms; // Copy calculated param to the new Cloison #130 cl.calculatedParam.singleValue = cloisonModel.calculatedParam.V;