From e9c25833c9fb3187d48e4cf58891cd65d88a02b0 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Tue, 1 Sep 2020 16:59:28 +0200
Subject: [PATCH] Fix #446 - bugs in Bief when generating sections

---
 .../calculator.component.ts                   | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index 8a328a71e..cca7416dd 100644
--- a/src/app/components/generic-calculator/calculator.component.ts
+++ b/src/app/components/generic-calculator/calculator.component.ts
@@ -712,7 +712,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
         if (bief.prms.Z1 === bief.calculatedParam) {
             return this.hasResults && ! bief.result.hasErrorMessages();
         } else {
-            return true;
+            // check that linked values are available, if any
+            return (
+                (bief.prms.Z1.valueMode !== ParamValueMode.LINK || bief.prms.Z1.referencedValue.isDefined())
+                && (bief.prms.ZF1.valueMode !== ParamValueMode.LINK || bief.prms.ZF1.referencedValue.isDefined())
+            );
         }
     }
 
@@ -721,7 +725,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
         if (bief.prms.Z2 === bief.calculatedParam) {
             return this.hasResults && ! bief.result.hasErrorMessages();
         } else {
-            return true;
+            // check that linked values are available, if any
+            return (
+                (bief.prms.Z2.valueMode !== ParamValueMode.LINK || bief.prms.Z2.referencedValue.isDefined())
+                && (bief.prms.ZF2.valueMode !== ParamValueMode.LINK || bief.prms.ZF2.referencedValue.isDefined())
+            );
         }
     }
 
@@ -812,7 +820,12 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
                 // do not link Y and If
                 && ! [ "If", "Y" ].includes(p.symbol)
             ) {
-                p.defineReference(bief.section, p.symbol);
+                const bP = bief.section.getParameter(p.symbol);
+                if (bP.valueMode === ParamValueMode.LINK) {
+                    p.defineReference(bP.referencedValue.nub, p.symbol);
+                } else {
+                    p.defineReference(bief.section, p.symbol);
+                }
             }
         }
 
-- 
GitLab