diff --git a/spec/structure/parallel_structure.spec.ts b/spec/structure/parallel_structure.spec.ts index f3135420907dfd17f19efa0fb2b9ddabdad2a6d1..140fb74a5db570ee1ad0c7b7505958083d0e1c57 100644 --- a/spec/structure/parallel_structure.spec.ts +++ b/spec/structure/parallel_structure.spec.ts @@ -5,6 +5,8 @@ import { SessionSettings } from "../../src/session_settings"; import { CreateStructure } from "../../src/structure/factory_structure"; import { ParallelStructure } from "../../src/structure/parallel_structure"; import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; +import { RectangularStructure } from "../../src/structure/rectangular_structure"; +import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureKivi } from "../../src/structure/structure_kivi"; import { StructureKiviParams } from "../../src/structure/structure_kivi_params"; import { LoiDebit } from "../../src/structure/structure_props"; @@ -218,3 +220,31 @@ describe("Class ParallelStructure: ", () => { }); }); }); + +describe("switching between LoiDebit should load a new default Cd", () => { + + it("test 1", () => { + const ps = new ParallelStructure(new ParallelStructureParams(1, 102, 100)); + const s = CreateStructure(LoiDebit.WeirSubmergedLarinier, ps); + expect((s.prms as RectangularStructureParams).CdWSL.singleValue).toBe(0.65); + ps.addChild(s); + expect((ps.getChildren()[0] as RectangularStructure).prms.CdWSL.singleValue).toBe(0.65); + const s2 = CreateStructure(LoiDebit.WeirSubmerged, ps); + expect((s2.prms as RectangularStructureParams).CdWS.singleValue).toBe(0.9); + ps.replaceChildInplace(s, s2); + expect((ps.getChildren()[0] as RectangularStructure).prms.CdWS.singleValue).toBe(0.9); + }); + + it("test 2", () => { + const ps = new ParallelStructure(new ParallelStructureParams(1, 102, 100)); + const s = CreateStructure(LoiDebit.WeirSubmerged, ps); + expect((s.prms as RectangularStructureParams).CdWS.singleValue).toBe(0.9); + ps.addChild(s); + expect((ps.getChildren()[0] as RectangularStructure).prms.CdWS.singleValue).toBe(0.9); + const s2 = CreateStructure(LoiDebit.WeirSubmergedLarinier, ps); + expect((s2.prms as RectangularStructureParams).CdWSL.singleValue).toBe(0.65); + ps.replaceChildInplace(s, s2); + expect((ps.getChildren()[0] as RectangularStructure).prms.CdWSL.singleValue).toBe(0.65); + }); + +}); diff --git a/src/nub.ts b/src/nub.ts index 7892c8ba6b8077d70275055fe64500662f3608c6..18deb103b40043420f3d7d2b0e92368d9170df83 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -1138,7 +1138,11 @@ export abstract class Nub extends ComputeNode implements IObservable { // store old parameters state if (keepParametersState && hasOldChild) { for (const p of this._children[index].parameterIterator) { - parametersState[p.symbol] = p.objectRepresentation([]); + // if p is also present and visible in new Nub + const cp = child.getParameter(p.symbol); + if (cp !== undefined && cp.visible && p.visible) { + parametersState[p.symbol] = p.objectRepresentation([]); + } } }