diff --git a/src/Model/Friction/Friction.py b/src/Model/Friction/Friction.py index db1a60db772c318dd57fdfdf3fe8ab8b5c9ecaac..2e6ec259bf4b3c09e218d30aa987a9cdfeac18c0 100644 --- a/src/Model/Friction/Friction.py +++ b/src/Model/Friction/Friction.py @@ -16,10 +16,13 @@ # -*- coding: utf-8 -*- +import logging + from tools import trace, timer from Model.Tools.PamhyrDB import SQLSubModel +logger = logging.getLogger() class Friction(SQLSubModel): def __init__(self, name: str = "", status=None): @@ -60,7 +63,10 @@ class Friction(SQLSubModel): @classmethod def _db_load(cls, execute, data=None): new = [] - reach = data["parent"] # Reach object + + logger.info(data) + + reach = data["reach"] status = data["status"] stricklers = data["stricklers"].stricklers @@ -69,9 +75,6 @@ class Friction(SQLSubModel): f"FROM friction WHERE reach = {reach.id}" ) - for _ in table: - new.append(None) - for row in table: ind = row[0] # Get stricklers @@ -86,7 +89,11 @@ class Friction(SQLSubModel): sec.begin_strickler = bs sec.end_strickler = es - yield ind, sec + new.append((ind, sec)) + + logger.info(new) + + return new def _db_save(self, execute, data=None): ind = data["ind"] @@ -116,6 +123,10 @@ class Friction(SQLSubModel): def edge(self): return self._edge + @property + def reach(self): + return self._edge + @edge.setter def edge(self, edge): self._edge = edge diff --git a/src/Model/Friction/FrictionList.py b/src/Model/Friction/FrictionList.py index 20c3319764400f516972ad33f4349ebb578b1040..6a5a6c091b63cce40896c52987b9d8f21c1a7c6c 100644 --- a/src/Model/Friction/FrictionList.py +++ b/src/Model/Friction/FrictionList.py @@ -50,10 +50,12 @@ class FrictionList(PamhyrModelList): def _db_load(cls, execute, data=None): new = cls(status=data['status']) - new._lst = Friction._db_load( + ilst = Friction._db_load( execute, data ) + new._lst = list(map(lambda x: x[1], sorted(ilst))) + return new def _db_save(self, execute, data=None): diff --git a/src/Model/Geometry/PointXYZ.py b/src/Model/Geometry/PointXYZ.py index 06a6ccf61ecd97e8f888363e5514282c432a3c7f..57c13a373d66dfd29a5a110a91de162e4f9a5b0d 100644 --- a/src/Model/Geometry/PointXYZ.py +++ b/src/Model/Geometry/PointXYZ.py @@ -116,7 +116,7 @@ class PointXYZ(Point, SQLSubModel): sl = self._sl.id if self._sl is not None else -1 sql = ( - "INSERT OR REPLACE INTO " + + "INSERT INTO " + "geometry_pointXYZ(ind, name, x, y, z, profile, sl) " + "VALUES (" + f"{ind}, '{self._db_format(self._name)}', " + diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index ad3ebb5ea61e9a23b8c8b2c75efe3bdc52f12599..495fbac10c737209f33138ee7f2a05b8acd359be 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -115,9 +115,6 @@ class ProfileXYZ(Profile, SQLSubModel): f"WHERE reach = {reach.id}" ) - for _ in table: - profiles.append(None) - for row in table: id = row[0] ind = row[1] @@ -132,7 +129,7 @@ class ProfileXYZ(Profile, SQLSubModel): id=id, num=num, name=name, kp=kp, code1=code1, code2=code2, - reach=data["parent"], + reach=reach, status=status ) @@ -151,10 +148,6 @@ class ProfileXYZ(Profile, SQLSubModel): yield ind, new - # profiles[ind] = new - - # return profiles - def _db_save(self, execute, data=None): ok = True ind = data["ind"] diff --git a/src/Model/Geometry/Reach.py b/src/Model/Geometry/Reach.py index 5351a9cbbabeb1dd7cf9a62012ccb8542b779168..3c02f16a68541a78b4fd79dfdd09d2c5aeb3f63b 100644 --- a/src/Model/Geometry/Reach.py +++ b/src/Model/Geometry/Reach.py @@ -61,7 +61,7 @@ class Reach(SQLSubModel): @classmethod def _db_load(cls, execute, data=None): - new = cls(status=data["status"], parent=data["parent"]) + new = cls(status=data["status"], parent=data["reach"]) new._profiles = ProfileXYZ._db_load( execute, diff --git a/src/Model/HydraulicStructures/HydraulicStructures.py b/src/Model/HydraulicStructures/HydraulicStructures.py index ca55e05c349ebea06abd4866ec21af6c7d0a8ea5..99dc2dc718e8a13efbeae856f4b26018fadd373b 100644 --- a/src/Model/HydraulicStructures/HydraulicStructures.py +++ b/src/Model/HydraulicStructures/HydraulicStructures.py @@ -61,8 +61,8 @@ class HydraulicStructure(SQLSubModel): id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL, enabled BOOLEAN NOT NULL, - input_kp INTEGER, - output_kp INTEGER, + input_kp REAL NOT NULL, + output_kp REAL NOT NULL, input_reach INTEGER, output_reach INTEGER, FOREIGN KEY(input_reach) REFERENCES river_reach(id), @@ -140,6 +140,14 @@ class HydraulicStructure(SQLSubModel): if self._output_reach is not None: output_reach_id = self._output_reach.id + input_kp = -1 + if self.input_kp is not None: + input_kp = self.input_kp + + output_kp = -1 + if self.output_kp is not None: + output_kp = self.output_kp + sql = ( "INSERT INTO " + "hydraulic_structures(" + @@ -149,7 +157,7 @@ class HydraulicStructure(SQLSubModel): "VALUES (" + f"{self.id}, '{self._db_format(self._name)}', " + f"{self._db_format(self.enabled)}, " + - f"{self.input_kp}, {self.input_kp}, " + + f"{input_kp}, {output_kp}, " + f"{input_reach_id}, {output_reach_id}" + ")" ) diff --git a/src/Model/River.py b/src/Model/River.py index d995d2c389b6133be698e826608acd800b9ffc5c..2ba5a54f4105813ee8f92eeebd08064de915ad41 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -157,7 +157,9 @@ class RiverReach(Edge, SQLSubModel): data = {} table = execute( - "SELECT id, name, enable, node1, node2 FROM river_reach") + "SELECT id, name, enable, node1, node2 FROM river_reach" + ) + for row in table: # Update id counter cls._id_cnt = max(cls._id_cnt, row[0]) @@ -172,10 +174,9 @@ class RiverReach(Edge, SQLSubModel): new = cls(id, name, node1, node2, status=data["status"]) new.enable(enable=enable) - data["reach"] = id - data["parent"] = new - new._reach = Reach._db_load(execute, data) + data["reach"] = new + new._reach = Reach._db_load(execute, data) new._frictions = FrictionList._db_load(execute, data) reachs.append(new) diff --git a/src/View/LateralContribution/Window.py b/src/View/LateralContribution/Window.py index 8a9a2e8e740c48a37e08d9662c9a49defd77142b..a6f04af5a494680de1dba05b0a73761459f45691 100644 --- a/src/View/LateralContribution/Window.py +++ b/src/View/LateralContribution/Window.py @@ -107,7 +107,7 @@ class LateralContributionWindow(PamhyrWindow): self._table[t] = TableModel( table_view=table, table_headers=self._trad.get_dict("table_headers"), - editable_headers=True, + editable_headers=self._trad.get_dict("table_headers"), delegates={ "type": self._delegate_type, "edge": self._delegate_edge, diff --git a/src/View/Study/Window.py b/src/View/Study/Window.py index e8b9c7f83791ae14e05671d78958a78771669461..bfb615d1ecb99fe853ffbc9f5565c04d38e9a55e 100644 --- a/src/View/Study/Window.py +++ b/src/View/Study/Window.py @@ -101,4 +101,5 @@ class NewStudyWindow(PamhyrDialog): self._study.use_date(date) else: self._study.use_time() + self.done(True) diff --git a/src/View/Tools/ListedSubWindow.py b/src/View/Tools/ListedSubWindow.py index 7fe21bb7bfab7cf0b1a40d3b5fac61ca8fff8792..d0b833b8efa46a7179f86e746b66c6bcc0c1f98b 100644 --- a/src/View/Tools/ListedSubWindow.py +++ b/src/View/Tools/ListedSubWindow.py @@ -55,11 +55,12 @@ class ListedSubWindow(object): logger.info(f"Close window: ({h}) {self.sub_win_cnt}") def _sub_win_exists(self, h): - return reduce( + res = reduce( lambda acc, el: (acc or (h == (el[1].hash()))), self.sub_win_list, False ) + return res def sub_win_exists(self, h): return self._sub_win_exists(h) diff --git a/src/View/Tools/PamhyrTable.py b/src/View/Tools/PamhyrTable.py index b77e26b9ceab0afe487e1b83caaf28fd1a5af4dd..6ce66a428a1345a5d18dae51287dc31df36d65b8 100644 --- a/src/View/Tools/PamhyrTable.py +++ b/src/View/Tools/PamhyrTable.py @@ -119,8 +119,7 @@ class PamhyrTableModel(QAbstractTableModel): options = Qt.ItemIsEnabled | Qt.ItemIsSelectable - if (self._editable_headers or - self._headers[column] in self._editable_headers): + if self._headers[column] in self._editable_headers: options |= Qt.ItemIsEditable return options diff --git a/src/View/Tools/PamhyrWindow.py b/src/View/Tools/PamhyrWindow.py index 74756167b65b01ebefb02a9f996095d28ced6923..87829b8dad058c0933a2285c5f2a273d950bf5e7 100644 --- a/src/View/Tools/PamhyrWindow.py +++ b/src/View/Tools/PamhyrWindow.py @@ -186,3 +186,8 @@ class PamhyrDialog(ASubWindow, ListedSubWindow, PamhyrWindowTools): self._hash_data.append(self._config) self._set_title() + + def done(self, result): + if self.parent is not None: + self.parent.sub_win_del(self.hash()) + super(PamhyrDialog, self).done(result) diff --git a/src/View/ui/GeometryReach.ui b/src/View/ui/GeometryReach.ui index a11a2279caabc72fba0a586e430b2d86a9a60899..d18d0e14e34cb335b9b9f5ae31a99e023241bcb8 100644 --- a/src/View/ui/GeometryReach.ui +++ b/src/View/ui/GeometryReach.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>868</width> + <width>1280</width> <height>720</height> </rect> </property> @@ -101,7 +101,7 @@ <rect> <x>0</x> <y>0</y> - <width>868</width> + <width>1280</width> <height>22</height> </rect> </property>