From 63d385cab896365899347153dab3a36f16ef3626 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 1 Feb 2023 09:53:18 +0100
Subject: [PATCH] fix: pressure loss form: create child law nub when opening
 calculator

refs #592
---
 .../formulaire/definition/form-pressureloss.ts    | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/app/formulaire/definition/form-pressureloss.ts b/src/app/formulaire/definition/form-pressureloss.ts
index 60c98da99..4b1e7ceb4 100644
--- a/src/app/formulaire/definition/form-pressureloss.ts
+++ b/src/app/formulaire/definition/form-pressureloss.ts
@@ -1,4 +1,4 @@
-import { PressureLoss, Props, PressureLossType } from "jalhyd";
+import { PressureLoss, Props, PressureLossType, Session, PressureLossLaw, CalculatorType } from "jalhyd";
 import { FormulaireFixedVar } from "./form-fixedvar";
 
 /**
@@ -17,8 +17,19 @@ export class FormulairePressureLoss extends FormulaireFixedVar {
         if (props === undefined) {
             props = new Props();
         }
+
+        // create pressure loss parent nub
+        const pll = this.defaultProperties["pressureLossType"];
         props.setPropValue("calcType", this.calculatorType);
-        props.setPropValue("pressureLossType", this.defaultProperties["pressureLossType"]);
+        props.setPropValue("pressureLossType", pll);
         super.initNub(props);
+
+        // create pressure loss law child nub
+        const propsLaw: Props = new Props();
+        const pressureLossCalc: CalculatorType = PressureLossLaw.calcTypeFromPressureLossLaw[pll];
+        propsLaw.setPropValue("calcType", pressureLossCalc);
+        const law = Session.getInstance().createNub(propsLaw) as PressureLossLaw;
+        const pl: PressureLoss = this.currentNub as PressureLoss;
+        pl.setLaw(law);
     }
 }
-- 
GitLab