From c1ff99797ceac24ddbf5a70296b3c5b6578c4f24 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Tue, 22 Aug 2023 11:39:08 +0200
Subject: [PATCH] Resutls: Read and display sediment results only if available.

---
 src/Solver/Mage.py         |  4 +--
 src/View/Results/Window.py | 63 ++++++++++++++++++++++----------------
 2 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py
index a9273176..aa68802f 100644
--- a/src/Solver/Mage.py
+++ b/src/Solver/Mage.py
@@ -677,8 +677,8 @@ class Mage8(Mage):
 
     @timer
     def read_gra(self, study, repertory, results, qlog = None):
-        # if not study.river.has_sediment():
-        #     return
+        if not study.river.has_sediment():
+            return
 
         logger.info(f"read_gra: Start ...")
 
diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py
index 6ca6fc56..3882a7ba 100644
--- a/src/View/Results/Window.py
+++ b/src/View/Results/Window.py
@@ -182,36 +182,37 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
         )
         self.plot_h.draw()
 
-
         self.canvas_5 = MplCanvas(width=5, height=4, dpi=100)
         self.canvas_5.setObjectName("canvas_5")
         self.plot_layout_5 = self.find(QVBoxLayout, "verticalLayout_sed_reach")
         self.plot_layout_5.addWidget(self.canvas_5)
 
-        self.plot_sed_reach = PlotSedReach(
-            canvas = self.canvas_5,
-            results = self._results,
-            study = self._study,
-            reach_id = 0,
-            profile_id = 0,
-            toolbar = None
-        )
-        self.plot_sed_reach.draw()
+        if self._study.river.has_sediment():
+            self.plot_sed_reach = PlotSedReach(
+                canvas = self.canvas_5,
+                results = self._results,
+                study = self._study,
+                reach_id = 0,
+                profile_id = 0,
+                toolbar = None
+            )
+            self.plot_sed_reach.draw()
 
         self.canvas_6 = MplCanvas(width=5, height=4, dpi=100)
         self.canvas_6.setObjectName("canvas_6")
         self.plot_layout_6 = self.find(QVBoxLayout, "verticalLayout_sed_profile")
         self.plot_layout_6.addWidget(self.canvas_6)
 
-        self.plot_sed_profile = PlotSedProfile(
-            canvas = self.canvas_6,
-            results = self._results,
-            study = self._study,
-            reach_id = 0,
-            profile_id = 0,
-            toolbar = None
-        )
-        self.plot_sed_profile.draw()
+        if self._study.river.has_sediment():
+            self.plot_sed_profile = PlotSedProfile(
+                canvas = self.canvas_6,
+                results = self._results,
+                study = self._study,
+                reach_id = 0,
+                profile_id = 0,
+                toolbar = None
+            )
+            self.plot_sed_profile.draw()
 
     def setup_connections(self):
         self.undo_sc.activated.connect(self.undo)
@@ -243,29 +244,37 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
             self.plot_ac.set_reach(reach_id)
             self.plot_kpc.set_reach(reach_id)
             self.plot_h.set_reach(reach_id)
-            self.plot_sed_reach.set_reach(reach_id)
-            self.plot_sed_profile.set_reach(reach_id)
+
+            if self._study.river.has_sediment():
+                self.plot_sed_reach.set_reach(reach_id)
+                self.plot_sed_profile.set_reach(reach_id)
         if profile_id is not None:
             self.plot_xy.set_profile(profile_id)
             self.plot_ac.set_profile(profile_id)
             self.plot_kpc.set_profile(profile_id)
             self.plot_h.set_profile(profile_id)
-            self.plot_sed_reach.set_profile(profile_id)
-            self.plot_sed_profile.set_profile(profile_id)
+
+            if self._study.river.has_sediment():
+                self.plot_sed_reach.set_profile(profile_id)
+                self.plot_sed_profile.set_profile(profile_id)
         if timestamp is not None:
             self.plot_xy.set_timestamp(timestamp)
             self.plot_ac.set_timestamp(timestamp)
             self.plot_kpc.set_timestamp(timestamp)
             self.plot_h.set_timestamp(timestamp)
-            self.plot_sed_reach.set_timestamp(timestamp)
-            self.plot_sed_profile.set_timestamp(timestamp)
+
+            if self._study.river.has_sediment():
+                self.plot_sed_reach.set_timestamp(timestamp)
+                self.plot_sed_profile.set_timestamp(timestamp)
 
         self.plot_xy.draw()
         self.plot_ac.draw()
         self.plot_kpc.draw()
         self.plot_h.draw()
-        self.plot_sed_reach.draw()
-        self.plot_sed_profile.draw()
+
+        if self._study.river.has_sediment():
+            self.plot_sed_reach.draw()
+            self.plot_sed_profile.draw()
 
 
     def _set_current_reach(self):
-- 
GitLab