From 3f52eaab1f7fec5d736cccb187f0668c2f99147a Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 19 Nov 2019 11:40:26 +0100 Subject: [PATCH] getDependingNubs() : add option to consider Solveur dependencies --- src/nub.ts | 18 ++++++++++++++---- src/session.ts | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/nub.ts b/src/nub.ts index 18deb103..63355434 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -1,7 +1,7 @@ import { CalculatorType, ComputeNode } from "./compute-node"; import { Dichotomie } from "./dichotomie"; import { acSection, MacrorugoCompound, Pab, ParamDefinition, ParamsEquation, - Session, Structure } from "./index"; + Session, Solveur, Structure } from "./index"; import { LinkedValue } from "./linked-value"; import { ParamCalculability, ParamFamily } from "./param/param-definition"; import { ParamValueMode } from "./param/param-value-mode"; @@ -875,12 +875,15 @@ export abstract class Nub extends ComputeNode implements IObservable { * if current Nub targets this symbol, it will be considered dependent * @param includeValuesLinks if true, even if this Nub targets only non-calculated non-modified * parameters, it will be considered dependent @see jalhyd#98 + * @param includeSolveurDependencies if true and this Nub is a Solveur, also return + * true if ${uid} is either the X or the Ytarget's parent Nub of this Solveur */ public resultDependsOnNub( uid: string, visited: string[] = [], symbol?: string, - includeValuesLinks: boolean = false + includeValuesLinks: boolean = false, + includeSolveurDependencies: boolean = false ): boolean { if (uid !== this.uid && ! visited.includes(this.uid)) { visited.push(this.uid); @@ -896,16 +899,23 @@ export abstract class Nub extends ComputeNode implements IObservable { // does any of our parent's parameters depend on the target Nub ? const parent = this.getParent(); if (parent) { - if (parent.resultDependsOnNub(uid, visited, symbol, includeValuesLinks)) { + if (parent.resultDependsOnNub(uid, visited, symbol, includeValuesLinks, includeSolveurDependencies)) { return true; } } // does any of our children' parameters depend on the target Nub ? for (const c of this.getChildren()) { - if (c.resultDependsOnNub(uid, visited, symbol, includeValuesLinks)) { + if (c.resultDependsOnNub(uid, visited, symbol, includeValuesLinks, includeSolveurDependencies)) { return true; } } + // is this a Solveur + if (includeSolveurDependencies && (this instanceof Solveur)) { + return ( + (this.searchedParameter !== undefined && this.searchedParameter.nubUid === uid) + || (this.nubToCalculate !== undefined && this.nubToCalculate.uid === uid) + ); + } } return false; } diff --git a/src/session.ts b/src/session.ts index 413b07a1..2f2d5d81 100644 --- a/src/session.ts +++ b/src/session.ts @@ -634,11 +634,21 @@ export class Session { * Nubs targetting this symbol will be considered dependent * @param includeValuesLinks if true, even Nubs targetting non-calculated non-modified parameters * will be considered dependent @see jalhyd#98 + * @param includeSolveurDependencies if true, Solveur Nubs having given Nub either as X or as Ytarget's + * parent Nub, will be considered dependent */ - public getDependingNubs(uid: string, symbol?: string, includeValuesLinks: boolean = false): Nub[] { + public getDependingNubs( + uid: string, + symbol?: string, + includeValuesLinks: boolean = false, + includeSolveurDependencies: boolean = false + ): Nub[] { const dependingNubs: Nub[] = []; for (const n of this._nubs) { - if (n.uid !== uid && n.resultDependsOnNub(uid, [], symbol, includeValuesLinks)) { + if ( + n.uid !== uid + && n.resultDependsOnNub(uid, [], symbol, includeValuesLinks, includeSolveurDependencies) + ) { dependingNubs.push(n); } } -- GitLab