From 318073c3d1f7c0701cf327cbbde59eb7ce8dd7bd Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Fri, 24 May 2019 16:43:19 +0200
Subject: [PATCH] When looking for a calculable param, variable params are now
 eligible too

---
 src/nub.ts                 | 32 ++++----------------------------
 src/structure/structure.ts |  4 ++--
 2 files changed, 6 insertions(+), 30 deletions(-)

diff --git a/src/nub.ts b/src/nub.ts
index 125609f1..43970a54 100644
--- a/src/nub.ts
+++ b/src/nub.ts
@@ -180,11 +180,7 @@ export abstract class Nub extends ComputeNode implements IObservable {
                 )
             ) {
                 // first SINGLE calculable parameter if any
-                let newCalculatedParam = this.findFirstSingleParameter(requirer);
-                if (! newCalculatedParam) {
-                    // first MIMAX/LISTE calculable parameter if any
-                    newCalculatedParam = this.findFirstVariableParameter(requirer);
-                }
+                const newCalculatedParam = this.findFirstCalculableParameter(requirer);
                 if (newCalculatedParam) {
                     this.calculatedParam = newCalculatedParam;
                 } else {
@@ -202,30 +198,10 @@ export abstract class Nub extends ComputeNode implements IObservable {
 
     /**
      * Returns the first visible calculable parameter other than "Pr",
-     * and other than otherThan, that is set to SINGLE mode
-     * (there might be none)
-     */
-    public findFirstSingleParameter(otherThan?: ParamDefinition) {
-        for (const p of this.parameterIterator) {
-            if (
-                [ ParamCalculability.EQUATION, ParamCalculability.DICHO ].includes(p.calculability)
-                && p.symbol !== "Pr"
-                && p.visible
-                && p !== otherThan
-                && p.valueMode === ParamValueMode.SINGLE
-            ) {
-                return p;
-            }
-        }
-        return undefined;
-    }
-
-    /**
-     * Returns the first visible calculable parameter other than "Pr",
-     * and other than otherThan, that is set to MINMAX or LISTE mode
-     * (there might be none)
+     * and other than otherThan, that is set to SINGLE, MINMAX or LISTE
+     * mode (there might be none)
      */
-    public findFirstVariableParameter(otherThan?: ParamDefinition) {
+    public findFirstCalculableParameter(otherThan?: ParamDefinition) {
         for (const p of this.parameterIterator) {
             if (
                 [ ParamCalculability.EQUATION, ParamCalculability.DICHO ].includes(p.calculability)
diff --git a/src/structure/structure.ts b/src/structure/structure.ts
index 68eb9930..123d0490 100644
--- a/src/structure/structure.ts
+++ b/src/structure/structure.ts
@@ -137,9 +137,9 @@ export abstract class Structure extends Nub {
      * Forwards to parent, that has vsibility over
      * all the parameters, including the Structure ones
      */
-    public findFirstSingleParameter(otherThan?: ParamDefinition) {
+    public findFirstCalculableParameter(otherThan?: ParamDefinition) {
         if (this.parent) {
-            return this.parent.findFirstSingleParameter(otherThan);
+            return this.parent.findFirstCalculableParameter(otherThan);
         }
         return undefined;
     }
-- 
GitLab