From 35d66cc881a6e3ee8fd2a16a3202f9a3cf251afd Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Fri, 28 Apr 2023 13:58:10 +0200
Subject: [PATCH] boundary conditions: Add model scheme and window scheme.

---
 .../BoundaryCondition/BoundaryCondition.py    |  38 +++++
 src/Model/River.py                            |   3 +
 .../BoundaryConditionWindow.py                |  29 ++++
 .../EditBoundaryConditionWindow.py            |  24 ++++
 src/View/MainWindow.py                        |   8 +-
 src/View/ui/BoundaryConditions.ui             | 134 ++++++++++++++++++
 src/View/ui/EditBoundaryConditions.ui         | 118 +++++++++++++++
 7 files changed, 353 insertions(+), 1 deletion(-)
 create mode 100644 src/Model/BoundaryCondition/BoundaryCondition.py
 create mode 100644 src/View/BoundaryCondition/BoundaryConditionWindow.py
 create mode 100644 src/View/BoundaryCondition/EditBoundaryConditionWindow.py
 create mode 100644 src/View/ui/BoundaryConditions.ui
 create mode 100644 src/View/ui/EditBoundaryConditions.ui

diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py
new file mode 100644
index 00000000..806bceeb
--- /dev/null
+++ b/src/Model/BoundaryCondition/BoundaryCondition.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+from Model.Except import NotImplementedMethodeError
+
+class BoundaryCondition(object):
+    def __init__(self, name:str = ""):
+        super(BoundaryCondition, self).__init__()
+
+        self._name = name
+        self._type = ""
+        self._node = None
+        self._data = None
+
+    @property
+    def name(self):
+        return self._name
+
+    @name.setter
+    def name(self, name):
+        self._name = name
+
+    @property
+    def bctype(self):
+        return self._type
+
+    @property
+    def node(self):
+        return self._node
+
+    @node.setter
+    def node(self, node):
+        self._node = node
+
+    def has_node(self):
+        return self._node is not None
+
+    def is_define(self):
+        return self._data is not None
diff --git a/src/Model/River.py b/src/Model/River.py
index a386cbae..daaf0afb 100644
--- a/src/Model/River.py
+++ b/src/Model/River.py
@@ -7,6 +7,8 @@ from Model.Network.Graph import Graph
 from Model.Geometry.Profile import Profile
 from Model.Geometry.Reach import Reach
 
+from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
+
 class RiverNode(Node):
     def __init__(self, id:str, name:str,
                  x:float, y:float):
@@ -51,6 +53,7 @@ class River(Graph):
         self._edge_ctor = RiverReach
 
         self._current_reach = None
+        self._boundary_condition = []
 
     def has_current_reach(self):
         return self._current_reach is not None
diff --git a/src/View/BoundaryCondition/BoundaryConditionWindow.py b/src/View/BoundaryCondition/BoundaryConditionWindow.py
new file mode 100644
index 00000000..13f3f288
--- /dev/null
+++ b/src/View/BoundaryCondition/BoundaryConditionWindow.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+
+from View.ASubWindow import ASubMainWindow
+from View.ListedSubWindow import ListedSubWindow
+
+from PyQt5.QtCore import (
+    Qt, QVariant, QAbstractTableModel,
+)
+
+from PyQt5.QtWidgets import (
+    QDialogButtonBox, QPushButton, QLineEdit,
+    QFileDialog, QTableView, QAbstractItemView,
+)
+
+from View.BoundaryCondition.EditBoundaryConditionWindow import EditBoundaryConditionWindow
+
+class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
+    def __init__(self, title="BoundaryConditions", study=None, parent=None):
+        super(BoundaryConditionWindow, self).__init__(
+            name=title, ui="BoundaryConditions", parent=parent
+        )
+
+        self._study = study
+
+        self.ui.setWindowTitle(title)
+
+    def edit(self):
+        win = EditBoundaryConditionWindow(data=None, parent=self)
+        win.show()
diff --git a/src/View/BoundaryCondition/EditBoundaryConditionWindow.py b/src/View/BoundaryCondition/EditBoundaryConditionWindow.py
new file mode 100644
index 00000000..c3943440
--- /dev/null
+++ b/src/View/BoundaryCondition/EditBoundaryConditionWindow.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+
+from View.ASubWindow import ASubMainWindow
+from View.ListedSubWindow import ListedSubWindow
+
+from PyQt5.QtCore import (
+    Qt, QVariant, QAbstractTableModel,
+)
+
+from PyQt5.QtWidgets import (
+    QDialogButtonBox, QPushButton, QLineEdit,
+    QFileDialog, QTableView, QAbstractItemView,
+)
+
+
+class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
+    def __init__(self, title="Edit BoundaryConditions", data=None, parent=None):
+        super(EditBoundaryConditionWindow, self).__init__(
+            name=title, ui="EditBoundaryConditions", parent=parent
+        )
+
+        self._data = data
+
+        self.ui.setWindowTitle(title)
diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index bf8f80d5..a37a6a9e 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -22,6 +22,7 @@ from View.Main.NewStudyWindow import NewStudyWindow
 from View.Main.AboutWindow import AboutWindow
 from View.Network.NetworkWindow import NetworkWindow
 from View.Geometry.GeometryWindow import GeometryWindow
+from View.BoundaryCondition.BoundaryConditionWindow import BoundaryConditionWindow
 
 from Model.Study import Study
 
@@ -114,7 +115,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
             "action_toolBar_geometry": self.open_geometry,
             "action_toolBar_mesh": lambda: self.open_dummy("Mesh"),
             "action_toolBar_run_meshing_tool": lambda: self.open_dummy("Lancement mailleur externe"),
-            "action_toolBar_boundary_cond": lambda: self.open_dummy("Condition Limites"),
+            "action_toolBar_boundary_cond": self.open_boundary_cond,
             "action_toolBar_lateral_contrib": lambda: self.open_dummy("Apport Lateraux"),
             "action_toolBar_spills": lambda: self.open_dummy("Deversement"),
             "action_toolBar_sections": lambda: self.open_dummy("Tronçons"),
@@ -315,6 +316,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
                              "Geometry edition need a reach selected "
                              "into river network window to work on it")
 
+    def open_boundary_cond(self):
+        self.bound = BoundaryConditionWindow(study = self.model, parent=self)
+        self.bound.show()
+
+
     # TODO: Delete me !
     ###############
     # DUMMY STUFF #
diff --git a/src/View/ui/BoundaryConditions.ui b/src/View/ui/BoundaryConditions.ui
new file mode 100644
index 00000000..8a0f8f96
--- /dev/null
+++ b/src/View/ui/BoundaryConditions.ui
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>450</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <property name="locale">
+   <locale language="English" country="Europe"/>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QSplitter" name="splitter">
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="orientation">
+       <enum>Qt::Horizontal</enum>
+      </property>
+      <widget class="QTableView" name="tableView"/>
+      <widget class="QWidget" name="verticalLayoutWidget">
+       <layout class="QVBoxLayout" name="verticalLayout"/>
+      </widget>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>22</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="toolBar">
+   <property name="windowTitle">
+    <string>toolBar</string>
+   </property>
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+   <addaction name="action_add"/>
+   <addaction name="action_del"/>
+   <addaction name="action_edit"/>
+   <addaction name="action_sort"/>
+  </widget>
+  <action name="action_add">
+   <property name="checkable">
+    <bool>false</bool>
+   </property>
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/gtk-add.png</normaloff>ressources/gtk-add.png</iconset>
+   </property>
+   <property name="text">
+    <string>Add</string>
+   </property>
+   <property name="toolTip">
+    <string>Add a new boundary condition or lateral contribution</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+N</string>
+   </property>
+  </action>
+  <action name="action_del">
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset>
+   </property>
+   <property name="text">
+    <string>Delete</string>
+   </property>
+   <property name="toolTip">
+    <string>Delete current selected rows</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+D</string>
+   </property>
+  </action>
+  <action name="action_edit">
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/edit.png</normaloff>ressources/edit.png</iconset>
+   </property>
+   <property name="text">
+    <string>Edit</string>
+   </property>
+   <property name="toolTip">
+    <string>Edit boundary condition or lateral contribution</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+E</string>
+   </property>
+  </action>
+  <action name="action_sort">
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/gtk-sort-ascending.png</normaloff>ressources/gtk-sort-ascending.png</iconset>
+   </property>
+   <property name="text">
+    <string>Sort</string>
+   </property>
+   <property name="toolTip">
+    <string>Sort boundary condition by name</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/View/ui/EditBoundaryConditions.ui b/src/View/ui/EditBoundaryConditions.ui
new file mode 100644
index 00000000..6a36a552
--- /dev/null
+++ b/src/View/ui/EditBoundaryConditions.ui
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>450</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <property name="locale">
+   <locale language="English" country="Europe"/>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QSplitter" name="splitter">
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="orientation">
+       <enum>Qt::Horizontal</enum>
+      </property>
+      <widget class="QTableView" name="tableView"/>
+      <widget class="QWidget" name="verticalLayoutWidget">
+       <layout class="QVBoxLayout" name="verticalLayout"/>
+      </widget>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>22</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="toolBar">
+   <property name="windowTitle">
+    <string>toolBar</string>
+   </property>
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+   <addaction name="action_add"/>
+   <addaction name="action_del"/>
+   <addaction name="action_sort"/>
+  </widget>
+  <action name="action_add">
+   <property name="checkable">
+    <bool>false</bool>
+   </property>
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/gtk-add.png</normaloff>ressources/gtk-add.png</iconset>
+   </property>
+   <property name="text">
+    <string>Add</string>
+   </property>
+   <property name="toolTip">
+    <string>Add a new point in boundary condition or lateral contribution</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+N</string>
+   </property>
+  </action>
+  <action name="action_del">
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset>
+   </property>
+   <property name="text">
+    <string>Delete</string>
+   </property>
+   <property name="toolTip">
+    <string>Delete current selected rows</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+D</string>
+   </property>
+  </action>
+  <action name="action_sort">
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/gtk-sort-ascending.png</normaloff>ressources/gtk-sort-ascending.png</iconset>
+   </property>
+   <property name="text">
+    <string>Sort</string>
+   </property>
+   <property name="toolTip">
+    <string>Sort boundary condition point</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
-- 
GitLab