diff --git a/src/Model/River.py b/src/Model/River.py index 8c29fef3..eecdb4b8 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -963,6 +963,12 @@ Last export at: @date.""" self._results[solv_type] = results def _split_reach(self, reach, profile): + profiles = reach.reach.profiles + if not profiles or profile not in profiles[1:-1]: + raise ValueError( + "A reach cannot be split at its first or last profile" + ) + node1 = reach.node1 node2 = reach.node2 diff --git a/src/View/Network/GraphWidget.py b/src/View/Network/GraphWidget.py index 114053a4..ba7e40c6 100644 --- a/src/View/Network/GraphWidget.py +++ b/src/View/Network/GraphWidget.py @@ -32,6 +32,7 @@ from PyQt5.QtGui import ( from PyQt5.QtWidgets import ( QApplication, QGraphicsScene, QGraphicsView, QGraphicsItem, QGraphicsTextItem, QMenu, + QMessageBox, ) from Model.Network.Node import Node @@ -724,6 +725,16 @@ class GraphWidget(QGraphicsView): def split_edge(self, item): edge = item.edge + if len(edge.reach.profiles) < 3: + QMessageBox.information( + self, + self._trad["menu_split_edge"], + _translate( + "Network", + "No profile is available to split this reach." + ) + ) + return dlg = SelectProfileDialog( study=self.parent._study, diff --git a/src/View/Network/ProfileDialog.py b/src/View/Network/ProfileDialog.py index 28caa99d..66abccaf 100644 --- a/src/View/Network/ProfileDialog.py +++ b/src/View/Network/ProfileDialog.py @@ -73,7 +73,10 @@ class SelectProfileDialog(PamhyrDialog): list( map( lambda p: p.display_name(), - self._reach.reach.profiles))) + self._reach.reach.profiles[1:-1] + ) + ) + ) def accept(self): profile = self.get_combobox_text("comboBox") @@ -81,7 +84,7 @@ class SelectProfileDialog(PamhyrDialog): self._profile = next( filter( lambda p: p.display_name() == profile, - self._reach.reach.profiles + self._reach.reach.profiles[1:-1] ) )