Commit 3f52eaab authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

getDependingNubs() : add option to consider Solveur dependencies

parent dcb8791d
import { CalculatorType, ComputeNode } from "./compute-node"; import { CalculatorType, ComputeNode } from "./compute-node";
import { Dichotomie } from "./dichotomie"; import { Dichotomie } from "./dichotomie";
import { acSection, MacrorugoCompound, Pab, ParamDefinition, ParamsEquation, import { acSection, MacrorugoCompound, Pab, ParamDefinition, ParamsEquation,
Session, Structure } from "./index"; Session, Solveur, Structure } from "./index";
import { LinkedValue } from "./linked-value"; import { LinkedValue } from "./linked-value";
import { ParamCalculability, ParamFamily } from "./param/param-definition"; import { ParamCalculability, ParamFamily } from "./param/param-definition";
import { ParamValueMode } from "./param/param-value-mode"; import { ParamValueMode } from "./param/param-value-mode";
...@@ -875,12 +875,15 @@ export abstract class Nub extends ComputeNode implements IObservable { ...@@ -875,12 +875,15 @@ export abstract class Nub extends ComputeNode implements IObservable {
* if current Nub targets this symbol, it will be considered dependent * 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 * @param includeValuesLinks if true, even if this Nub targets only non-calculated non-modified
* parameters, it will be considered dependent @see jalhyd#98 * 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( public resultDependsOnNub(
uid: string, uid: string,
visited: string[] = [], visited: string[] = [],
symbol?: string, symbol?: string,
includeValuesLinks: boolean = false includeValuesLinks: boolean = false,
includeSolveurDependencies: boolean = false
): boolean { ): boolean {
if (uid !== this.uid && ! visited.includes(this.uid)) { if (uid !== this.uid && ! visited.includes(this.uid)) {
visited.push(this.uid); visited.push(this.uid);
...@@ -896,16 +899,23 @@ export abstract class Nub extends ComputeNode implements IObservable { ...@@ -896,16 +899,23 @@ export abstract class Nub extends ComputeNode implements IObservable {
// does any of our parent's parameters depend on the target Nub ? // does any of our parent's parameters depend on the target Nub ?
const parent = this.getParent(); const parent = this.getParent();
if (parent) { if (parent) {
if (parent.resultDependsOnNub(uid, visited, symbol, includeValuesLinks)) { if (parent.resultDependsOnNub(uid, visited, symbol, includeValuesLinks, includeSolveurDependencies)) {
return true; return true;
} }
} }
// does any of our children' parameters depend on the target Nub ? // does any of our children' parameters depend on the target Nub ?
for (const c of this.getChildren()) { for (const c of this.getChildren()) {
if (c.resultDependsOnNub(uid, visited, symbol, includeValuesLinks)) { if (c.resultDependsOnNub(uid, visited, symbol, includeValuesLinks, includeSolveurDependencies)) {
return true; 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; return false;
} }
......
...@@ -634,11 +634,21 @@ export class Session { ...@@ -634,11 +634,21 @@ export class Session {
* Nubs targetting this symbol will be considered dependent * Nubs targetting this symbol will be considered dependent
* @param includeValuesLinks if true, even Nubs targetting non-calculated non-modified parameters * @param includeValuesLinks if true, even Nubs targetting non-calculated non-modified parameters
* will be considered dependent @see jalhyd#98 * 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[] = []; const dependingNubs: Nub[] = [];
for (const n of this._nubs) { 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); dependingNubs.push(n);
} }
} }
......
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