mirror of https://gitlab.com/pamhyr/pamhyr2
Merge branch 'hydraulics-structure' of gitlab-ssh.irstea.fr:theophile.terraz/pamhyr into hydraulics-structure
commit
4c5281ea30
|
|
@ -16,10 +16,13 @@
|
||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
class Friction(SQLSubModel):
|
class Friction(SQLSubModel):
|
||||||
def __init__(self, name: str = "", status=None):
|
def __init__(self, name: str = "", status=None):
|
||||||
|
|
@ -60,7 +63,10 @@ class Friction(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
reach = data["parent"] # Reach object
|
|
||||||
|
logger.info(data)
|
||||||
|
|
||||||
|
reach = data["reach"]
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
stricklers = data["stricklers"].stricklers
|
stricklers = data["stricklers"].stricklers
|
||||||
|
|
||||||
|
|
@ -69,9 +75,6 @@ class Friction(SQLSubModel):
|
||||||
f"FROM friction WHERE reach = {reach.id}"
|
f"FROM friction WHERE reach = {reach.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for _ in table:
|
|
||||||
new.append(None)
|
|
||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
ind = row[0]
|
ind = row[0]
|
||||||
# Get stricklers
|
# Get stricklers
|
||||||
|
|
@ -86,7 +89,11 @@ class Friction(SQLSubModel):
|
||||||
sec.begin_strickler = bs
|
sec.begin_strickler = bs
|
||||||
sec.end_strickler = es
|
sec.end_strickler = es
|
||||||
|
|
||||||
yield ind, sec
|
new.append((ind, sec))
|
||||||
|
|
||||||
|
logger.info(new)
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
@ -116,6 +123,10 @@ class Friction(SQLSubModel):
|
||||||
def edge(self):
|
def edge(self):
|
||||||
return self._edge
|
return self._edge
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reach(self):
|
||||||
|
return self._edge
|
||||||
|
|
||||||
@edge.setter
|
@edge.setter
|
||||||
def edge(self, edge):
|
def edge(self, edge):
|
||||||
self._edge = edge
|
self._edge = edge
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,12 @@ class FrictionList(PamhyrModelList):
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(status=data['status'])
|
new = cls(status=data['status'])
|
||||||
|
|
||||||
new._lst = Friction._db_load(
|
ilst = Friction._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
new._lst = list(map(lambda x: x[1], sorted(ilst)))
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
sl = self._sl.id if self._sl is not None else -1
|
sl = self._sl.id if self._sl is not None else -1
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT INTO " +
|
||||||
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) " +
|
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, '{self._db_format(self._name)}', " +
|
f"{ind}, '{self._db_format(self._name)}', " +
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
f"WHERE reach = {reach.id}"
|
f"WHERE reach = {reach.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for _ in table:
|
|
||||||
profiles.append(None)
|
|
||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
id = row[0]
|
id = row[0]
|
||||||
ind = row[1]
|
ind = row[1]
|
||||||
|
|
@ -132,7 +129,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
id=id, num=num,
|
id=id, num=num,
|
||||||
name=name, kp=kp,
|
name=name, kp=kp,
|
||||||
code1=code1, code2=code2,
|
code1=code1, code2=code2,
|
||||||
reach=data["parent"],
|
reach=reach,
|
||||||
status=status
|
status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -151,10 +148,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
|
|
||||||
yield ind, new
|
yield ind, new
|
||||||
|
|
||||||
# profiles[ind] = new
|
|
||||||
|
|
||||||
# return profiles
|
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
ok = True
|
ok = True
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class Reach(SQLSubModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
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(
|
new._profiles = ProfileXYZ._db_load(
|
||||||
execute,
|
execute,
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ class HydraulicStructure(SQLSubModel):
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
enabled BOOLEAN NOT NULL,
|
enabled BOOLEAN NOT NULL,
|
||||||
input_kp INTEGER,
|
input_kp REAL NOT NULL,
|
||||||
output_kp INTEGER,
|
output_kp REAL NOT NULL,
|
||||||
input_reach INTEGER,
|
input_reach INTEGER,
|
||||||
output_reach INTEGER,
|
output_reach INTEGER,
|
||||||
FOREIGN KEY(input_reach) REFERENCES river_reach(id),
|
FOREIGN KEY(input_reach) REFERENCES river_reach(id),
|
||||||
|
|
@ -140,6 +140,14 @@ class HydraulicStructure(SQLSubModel):
|
||||||
if self._output_reach is not None:
|
if self._output_reach is not None:
|
||||||
output_reach_id = self._output_reach.id
|
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 = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"hydraulic_structures(" +
|
"hydraulic_structures(" +
|
||||||
|
|
@ -149,7 +157,7 @@ class HydraulicStructure(SQLSubModel):
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"{self._db_format(self.enabled)}, " +
|
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}" +
|
f"{input_reach_id}, {output_reach_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,9 @@ class RiverReach(Edge, SQLSubModel):
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, name, enable, node1, node2 FROM river_reach")
|
"SELECT id, name, enable, node1, node2 FROM river_reach"
|
||||||
|
)
|
||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
# Update id counter
|
# Update id counter
|
||||||
cls._id_cnt = max(cls._id_cnt, row[0])
|
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 = cls(id, name, node1, node2, status=data["status"])
|
||||||
new.enable(enable=enable)
|
new.enable(enable=enable)
|
||||||
|
|
||||||
data["reach"] = id
|
data["reach"] = new
|
||||||
data["parent"] = new
|
|
||||||
new._reach = Reach._db_load(execute, data)
|
|
||||||
|
|
||||||
|
new._reach = Reach._db_load(execute, data)
|
||||||
new._frictions = FrictionList._db_load(execute, data)
|
new._frictions = FrictionList._db_load(execute, data)
|
||||||
|
|
||||||
reachs.append(new)
|
reachs.append(new)
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class LateralContributionWindow(PamhyrWindow):
|
||||||
self._table[t] = TableModel(
|
self._table[t] = TableModel(
|
||||||
table_view=table,
|
table_view=table,
|
||||||
table_headers=self._trad.get_dict("table_headers"),
|
table_headers=self._trad.get_dict("table_headers"),
|
||||||
editable_headers=True,
|
editable_headers=self._trad.get_dict("table_headers"),
|
||||||
delegates={
|
delegates={
|
||||||
"type": self._delegate_type,
|
"type": self._delegate_type,
|
||||||
"edge": self._delegate_edge,
|
"edge": self._delegate_edge,
|
||||||
|
|
|
||||||
|
|
@ -101,4 +101,5 @@ class NewStudyWindow(PamhyrDialog):
|
||||||
self._study.use_date(date)
|
self._study.use_date(date)
|
||||||
else:
|
else:
|
||||||
self._study.use_time()
|
self._study.use_time()
|
||||||
|
|
||||||
self.done(True)
|
self.done(True)
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,12 @@ class ListedSubWindow(object):
|
||||||
logger.info(f"Close window: ({h}) {self.sub_win_cnt}")
|
logger.info(f"Close window: ({h}) {self.sub_win_cnt}")
|
||||||
|
|
||||||
def _sub_win_exists(self, h):
|
def _sub_win_exists(self, h):
|
||||||
return reduce(
|
res = reduce(
|
||||||
lambda acc, el: (acc or (h == (el[1].hash()))),
|
lambda acc, el: (acc or (h == (el[1].hash()))),
|
||||||
self.sub_win_list,
|
self.sub_win_list,
|
||||||
False
|
False
|
||||||
)
|
)
|
||||||
|
return res
|
||||||
|
|
||||||
def sub_win_exists(self, h):
|
def sub_win_exists(self, h):
|
||||||
return self._sub_win_exists(h)
|
return self._sub_win_exists(h)
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
|
|
||||||
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
||||||
|
|
||||||
if (self._editable_headers or
|
if self._headers[column] in self._editable_headers:
|
||||||
self._headers[column] in self._editable_headers):
|
|
||||||
options |= Qt.ItemIsEditable
|
options |= Qt.ItemIsEditable
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
|
||||||
|
|
@ -186,3 +186,8 @@ class PamhyrDialog(ASubWindow, ListedSubWindow, PamhyrWindowTools):
|
||||||
self._hash_data.append(self._config)
|
self._hash_data.append(self._config)
|
||||||
|
|
||||||
self._set_title()
|
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)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>868</width>
|
<width>1280</width>
|
||||||
<height>720</height>
|
<height>720</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -101,7 +101,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>868</width>
|
<width>1280</width>
|
||||||
<height>22</height>
|
<height>22</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue