diff --git a/src/nub.ts b/src/nub.ts index 720858153602971900c1235e1527bab1ff3ff561..c4cc38959b2f202b98c4d0ca764cb1f5d4192ac4 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -17,6 +17,22 @@ import { ResultElement } from "./util/resultelement"; */ export abstract class Nub extends ComputeNode implements IObservable { + protected static concatPrms(p1: ParamsEquation[], p2: ParamsEquation[]): ParamsEquation[] { + const p3: ParamsEquation[] = p1; + for (const p of p2) { + p3.push(p); + } + return p3; + } + + private static progressPercentageAccordedToChainCalculation = 50; + + /** paramétrage de la dichotomie */ + public dichoStartIntervalMaxSteps: number = 100; + + /** pointer to parent Nub */ + public parent: Nub; + /** type of children elements, used by GUI for translation */ protected _childrenType: string = ""; @@ -51,10 +67,16 @@ export abstract class Nub extends ComputeNode implements IObservable { public set properties(props: Props) { // copy observers const observers = this._props.getObservers(); - this._props = props.clone(); + // empty props + this._props.reset(); + // restore observers for (const obs of observers) { this._props.addObserver(obs); } + // set new props values + for (const p of Object.keys(props.props)) { + this._props.setPropValue(p, props.getPropValue(p)); + } } /** @@ -159,22 +181,6 @@ export abstract class Nub extends ComputeNode implements IObservable { } } - protected static concatPrms(p1: ParamsEquation[], p2: ParamsEquation[]): ParamsEquation[] { - const p3: ParamsEquation[] = p1; - for (const p of p2) { - p3.push(p); - } - return p3; - } - - private static progressPercentageAccordedToChainCalculation = 50; - - /** paramétrage de la dichotomie */ - public dichoStartIntervalMaxSteps: number = 100; - - /** pointer to parent Nub */ - public parent: Nub; - /** parameter that is to be computed by default - to be overloaded by child classes */ protected _defaultCalculatedParam: ParamDefinition; @@ -207,7 +213,7 @@ export abstract class Nub extends ComputeNode implements IObservable { public constructor(prms: ParamsEquation, dbg: boolean = false) { super(prms, dbg); - this._children = []; + this.deleteAllChildren(); this._observable = new Observable(); this._defaultCalculatedParam = this.getFirstAnalyticalParameter(); this.resetDefaultCalculatedParam(); @@ -1166,6 +1172,11 @@ export abstract class Nub extends ComputeNode implements IObservable { } } + /** Removes all children */ + public deleteAllChildren() { + this._children = []; + } + /** * Returns the position or the current structure (starting at 0) * in the parent Nub diff --git a/src/props.ts b/src/props.ts index 580a3e40e26a50338cf63c39f4e34d89514105e1..99f40d377583c8baea39f650cd095498d5e83602 100644 --- a/src/props.ts +++ b/src/props.ts @@ -59,6 +59,13 @@ export class Props implements IObservable { return this._observable.getObservers(); } + /** + * Remove all properties, does not notify of any change + */ + public reset() { + this._props = {}; + } + /** * Clones properties into a new Props object */