Commit 27347745 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Nub.replaceChild() : copy values only for parameters present in both current child and new child

parent 16434765
......@@ -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);
});
});
......@@ -1138,9 +1138,13 @@ export abstract class Nub extends ComputeNode implements IObservable {
// store old parameters state
if (keepParametersState && hasOldChild) {
for (const p of this._children[index].parameterIterator) {
// 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([]);
}
}
}
// replace child
this._children[index] = child;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment