mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
36 Commits
cea4dcd9cb
...
cb4dfab482
| Author | SHA1 | Date |
|---|---|---|
|
|
cb4dfab482 | |
|
|
377c508038 | |
|
|
30e34b6847 | |
|
|
102702e1df | |
|
|
c014f0ef34 | |
|
|
e615a6b9d4 | |
|
|
f1dca727c6 | |
|
|
2db1f4c7f7 | |
|
|
b3d631943c | |
|
|
b6895ae99c | |
|
|
9f26a7323c | |
|
|
2a7e322ee5 | |
|
|
13a44264ac | |
|
|
6165719829 | |
|
|
51dd6d27c5 | |
|
|
7a91969f41 | |
|
|
e755459004 | |
|
|
a8f95e2386 | |
|
|
55b200a48e | |
|
|
6b8d7c2df2 | |
|
|
eb7c4895ca | |
|
|
a060dbd461 | |
|
|
9379f7a27d | |
|
|
a4026d6386 | |
|
|
d6f7755d12 | |
|
|
b58d3e005d | |
|
|
870bb41ff7 | |
|
|
0701531d37 | |
|
|
43eb486700 | |
|
|
82eeb9a478 | |
|
|
432c263cdf | |
|
|
c2d28b0110 | |
|
|
23361d142e | |
|
|
63836527c7 | |
|
|
4f6e8249e0 | |
|
|
ab2f775b95 |
|
|
@ -329,7 +329,8 @@ class BoundaryCondition(SQLSubModel):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, name, type, node, d50, sigma, scenario " +
|
"SELECT pamhyr_id, deleted, name, type, node, d50, sigma, " +
|
||||||
|
"scenario " +
|
||||||
"FROM boundary_condition " +
|
"FROM boundary_condition " +
|
||||||
f"WHERE tab = '{tab}' " +
|
f"WHERE tab = '{tab}' " +
|
||||||
f"AND scenario = {scenario.id} " +
|
f"AND scenario = {scenario.id} " +
|
||||||
|
|
@ -355,11 +356,14 @@ class BoundaryCondition(SQLSubModel):
|
||||||
status=data['status'],
|
status=data['status'],
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
|
|
||||||
if deleted:
|
if deleted:
|
||||||
bc.set_as_deleted()
|
bc.set_as_deleted()
|
||||||
if t=="SL":
|
|
||||||
|
if t == "SL":
|
||||||
bc.d50 = d50
|
bc.d50 = d50
|
||||||
bc.sigma = sigma
|
bc.sigma = sigma
|
||||||
|
|
||||||
bc.node = None
|
bc.node = None
|
||||||
if node != -1:
|
if node != -1:
|
||||||
bc.node = next(filter(lambda n: n.id == node, nodes), None)
|
bc.node = next(filter(lambda n: n.id == node, nodes), None)
|
||||||
|
|
@ -510,6 +514,42 @@ class BoundaryCondition(SQLSubModel):
|
||||||
self._sigma = float(value)
|
self._sigma = float(value)
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def d50(self):
|
||||||
|
return self._d50
|
||||||
|
|
||||||
|
@d50.setter
|
||||||
|
def d50(self, value):
|
||||||
|
self._d50 = float(value)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sigma(self):
|
||||||
|
return self._sigma
|
||||||
|
|
||||||
|
@sigma.setter
|
||||||
|
def sigma(self, value):
|
||||||
|
self._sigma = float(value)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def d50(self):
|
||||||
|
return self._d50
|
||||||
|
|
||||||
|
@d50.setter
|
||||||
|
def d50(self, value):
|
||||||
|
self._d50 = float(value)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sigma(self):
|
||||||
|
return self._sigma
|
||||||
|
|
||||||
|
@sigma.setter
|
||||||
|
def sigma(self, value):
|
||||||
|
self._sigma = float(value)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
return self._header.copy()
|
return self._header.copy()
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ class Data(SQLSubModel):
|
||||||
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
||||||
"boundary_condition_data_adists " +
|
"boundary_condition_data_adists " +
|
||||||
f"WHERE bca = {bca.id} " +
|
f"WHERE bca = {bca.id} " +
|
||||||
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
f"AND scenario = {scenario.id}"
|
f"AND scenario = {scenario.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -300,6 +301,12 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
if pol_id == -1:
|
if pol_id == -1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if pol_id not in pid_pol:
|
||||||
|
# ⚠️ cas important : probablement déjà migré
|
||||||
|
print(f"[WARN] pol_id {pol_id} not in pid_pol " +
|
||||||
|
f"→ probably already migrated")
|
||||||
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE boundary_condition_adists " +
|
f"UPDATE boundary_condition_adists " +
|
||||||
f"SET pollutant = {pid_pol[pol_id]} " +
|
f"SET pollutant = {pid_pol[pol_id]} " +
|
||||||
|
|
|
||||||
|
|
@ -132,11 +132,13 @@ class Data(SQLSubModel):
|
||||||
if scenario is None:
|
if scenario is None:
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
lca = data["lca"]
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, data0, data1 " +
|
"SELECT pamhyr_id, deleted, data0, data1, scenario " +
|
||||||
"FROM lateral_contribution_data_adists " +
|
"FROM lateral_contribution_data_adists " +
|
||||||
f"WHERE scenario = {scenario.id} " +
|
f"WHERE scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
f"AND lca = '{lca.id}'"
|
f"AND lca = '{lca.id}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -150,16 +152,16 @@ class Data(SQLSubModel):
|
||||||
data1 = next(it)
|
data1 = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
data = cls(
|
lc = cls(
|
||||||
data0, data1,
|
data0, data1,
|
||||||
id=pid, status=status,
|
id=pid, status=status,
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
data.set_as_deleted()
|
lc.set_as_deleted()
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(data)
|
new.append(lc)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
|
|
@ -175,7 +177,7 @@ class Data(SQLSubModel):
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_adists(pamhyr_id, deleted," +
|
"lateral_contribution_data_adists(pamhyr_id, deleted," +
|
||||||
"data0, data1, lca, scenario) " +
|
"data0, data1, lca, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
|
|
@ -372,16 +374,18 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_adists(pamhyr_id, deleted," +
|
"lateral_contribution_adists(pamhyr_id, deleted, " +
|
||||||
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"{self._pollutant}, {self.reach}, " +
|
f"{self._pollutant}, {self.reach}, " +
|
||||||
f"{self._begin_rk}, {self._end_rk}" +
|
f"{self._begin_rk}, {self._end_rk}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data["lca"] = self
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
|
|
@ -471,3 +475,57 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
def end_rk(self, end_rk):
|
def end_rk(self, end_rk):
|
||||||
self._end_rk = end_rk
|
self._end_rk = end_rk
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_0(self):
|
||||||
|
return self._types[0](0)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_1(self):
|
||||||
|
return self._types[1](0.0)
|
||||||
|
|
||||||
|
def add(self, index: int):
|
||||||
|
value = Data(self._default_0, self._default_1, status=self._status)
|
||||||
|
self._data.insert(index, value)
|
||||||
|
self.modified()
|
||||||
|
return value
|
||||||
|
|
||||||
|
def insert(self, index: int, data: Data):
|
||||||
|
self._data.insert(index, data)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def delete_i(self, indexes):
|
||||||
|
self._data = list(
|
||||||
|
map(
|
||||||
|
lambda e: e[1],
|
||||||
|
filter(
|
||||||
|
lambda e: e[0] not in indexes,
|
||||||
|
enumerate(self.data)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def index(self, bc):
|
||||||
|
self._data.index(bc)
|
||||||
|
|
||||||
|
def get_i(self, index: int):
|
||||||
|
return self._data[index]
|
||||||
|
|
||||||
|
def get_range(self, _range):
|
||||||
|
lst = []
|
||||||
|
for r in _range:
|
||||||
|
lst.append(r)
|
||||||
|
return lst
|
||||||
|
|
||||||
|
def _set_i_c_v(self, index: int, column: int, value):
|
||||||
|
v = self._data[index]
|
||||||
|
v[column] = self._types[column](value)
|
||||||
|
self._data[index] = v
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def set_i_0(self, index: int, value):
|
||||||
|
self._set_i_c_v(index, 0, value)
|
||||||
|
|
||||||
|
def set_i_1(self, index: int, value):
|
||||||
|
self._set_i_c_v(index, 1, value)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,9 @@ from tools import (
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
from Model.Scenario import Scenario
|
from Model.Scenario import Scenario
|
||||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
|
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import (
|
||||||
|
BoundaryConditionAdisTS,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
@ -427,6 +429,13 @@ class Pollutants(SQLSubModel):
|
||||||
execute, data=data
|
execute, data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
new_pollutant._boundary_conditions_adists = (
|
||||||
|
BoundaryConditionAdisTS._db_load(
|
||||||
|
execute,
|
||||||
|
data=data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(new_pollutant)
|
new.append(new_pollutant)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -311,6 +311,12 @@ class SQLSubModel(PamhyrID):
|
||||||
if node_id == -1:
|
if node_id == -1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if node_id not in nodes:
|
||||||
|
# ⚠️ cas important : probablement déjà migré
|
||||||
|
print(f"[WARN] node_id {node_id} not in nodes " +
|
||||||
|
f"→ probably already migrated")
|
||||||
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE {table} " +
|
f"UPDATE {table} " +
|
||||||
f"SET node = {nodes[node_id]} " +
|
f"SET node = {nodes[node_id]} " +
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,16 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||||
|
|
||||||
name = trad[self._pamhyr_name]
|
name = trad[self._pamhyr_name]
|
||||||
|
|
||||||
|
if self._data is not None:
|
||||||
|
n = self._data.node
|
||||||
|
node_name = next(filter(
|
||||||
|
lambda x: x.id == n, study.river._nodes
|
||||||
|
)).name
|
||||||
|
name += (
|
||||||
|
f" - {study.name} " +
|
||||||
|
f"({node_name})"
|
||||||
|
)
|
||||||
|
|
||||||
super(EditBoundaryConditionWindow, self).__init__(
|
super(EditBoundaryConditionWindow, self).__init__(
|
||||||
title=name,
|
title=name,
|
||||||
study=study,
|
study=study,
|
||||||
|
|
@ -71,16 +81,6 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||||
parent=parent
|
parent=parent
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._data is not None:
|
|
||||||
n = self._data.node
|
|
||||||
node_name = next(filter(
|
|
||||||
lambda x: x.id == n, self._study.river._nodes
|
|
||||||
)).name
|
|
||||||
name += (
|
|
||||||
f" - {study.name} " +
|
|
||||||
f"({node_name})"
|
|
||||||
)
|
|
||||||
|
|
||||||
self._hash_data.append(data)
|
self._hash_data.append(data)
|
||||||
|
|
||||||
self.setup_table()
|
self.setup_table()
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,8 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
|
|
||||||
|
|
||||||
class TableModel(PamhyrTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
def __init__(self, bc_list=None, pollutant_bc_list=None, trad=None, **kwargs):
|
def __init__(self, bc_list=None, pollutant_bc_list=None,
|
||||||
|
trad=None, **kwargs):
|
||||||
self._trad = trad
|
self._trad = trad
|
||||||
self._bc_list = bc_list
|
self._bc_list = bc_list
|
||||||
self._pollutant = pollutant_bc_list.id
|
self._pollutant = pollutant_bc_list.id
|
||||||
|
|
@ -214,9 +215,14 @@ class TableModel(PamhyrTableModel):
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
global_rows = list(
|
row_by_bc = {
|
||||||
map(self._global_row, rows)
|
id(bc): row for row, bc in enumerate(self._bc_list._lst)
|
||||||
)
|
}
|
||||||
|
global_rows = [
|
||||||
|
row_by_bc[id(self._lst[row])]
|
||||||
|
for row in rows
|
||||||
|
if 0 <= row < len(self._lst)
|
||||||
|
]
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._bc_list, global_rows
|
self._bc_list, global_rows
|
||||||
|
|
|
||||||
|
|
@ -58,17 +58,18 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
||||||
_pamhyr_name = "Boundary conditions AdisTS"
|
_pamhyr_name = "Boundary conditions AdisTS"
|
||||||
|
|
||||||
def __init__(self, data=None, pollutant_id=None, study=None, config=None, parent=None):
|
def __init__(self, data=None, pollutant_id=None, study=None,
|
||||||
|
config=None, parent=None):
|
||||||
self._data = data
|
self._data = data
|
||||||
self._pollutant_id = pollutant_id
|
self._pollutant_id = pollutant_id
|
||||||
|
trad = BCAdisTSTranslate()
|
||||||
|
|
||||||
_pollutants_lst = study._river._Pollutants.Pollutants_List
|
|
||||||
self._pollutant_name = next(
|
self._pollutant_name = next(
|
||||||
(x.name for x in _pollutants_lst if x.id == self._pollutant_id),
|
(x.name for x in study._river._Pollutants.Pollutants_List
|
||||||
|
if x.id == self._pollutant_id),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
trad = BCAdisTSTranslate()
|
|
||||||
name = (
|
name = (
|
||||||
trad[self._pamhyr_name] +
|
trad[self._pamhyr_name] +
|
||||||
" - " + study.name +
|
" - " + study.name +
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class D90TableModel(PamhyrTableModel):
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = list(
|
self._lst = list(
|
||||||
filter(
|
filter(
|
||||||
lambda d90: d90._deleted == False,
|
lambda d90: d90._deleted is False,
|
||||||
self._data._data
|
self._data._data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@
|
||||||
from View.Tools.PamhyrWindow import PamhyrDialog
|
from View.Tools.PamhyrWindow import PamhyrDialog
|
||||||
from PyQt5.QtWidgets import QDoubleSpinBox
|
from PyQt5.QtWidgets import QDoubleSpinBox
|
||||||
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
|
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
|
||||||
|
from PyQt5.QtWidgets import QDoubleSpinBox
|
||||||
|
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
|
||||||
|
|
||||||
|
|
||||||
class ShiftDialog(PamhyrDialog):
|
class ShiftDialog(PamhyrDialog):
|
||||||
_pamhyr_ui = "GeometryReachShift"
|
_pamhyr_ui = "GeometryReachShift"
|
||||||
|
|
|
||||||
|
|
@ -91,3 +91,9 @@ class GeometryTranslate(MainTranslate):
|
||||||
self._dict["Shift"] = _translate(
|
self._dict["Shift"] = _translate(
|
||||||
"Geometry", "Shift"
|
"Geometry", "Shift"
|
||||||
)
|
)
|
||||||
|
self._dict["warning"] = _translate(
|
||||||
|
"Geometry", "Warning"
|
||||||
|
)
|
||||||
|
self._dict["format_not_exportable"] = _translate(
|
||||||
|
"Geometry", "The format of the file is not exportable."
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -691,7 +691,13 @@ class GeometryWindow(PamhyrWindow):
|
||||||
if suffix == ".st" or suffix == ".ST":
|
if suffix == ".st" or suffix == ".ST":
|
||||||
self._export_to_file_st(filename[:-3])
|
self._export_to_file_st(filename[:-3])
|
||||||
else:
|
else:
|
||||||
# TODO : prévenir l'utilisateur que le format n'est pas exportable
|
# Warning popup when the format is not exportable
|
||||||
|
win = QtWidgets.QMessageBox()
|
||||||
|
win.setIcon(QtWidgets.QMessageBox.Warning)
|
||||||
|
win.setWindowTitle(self._trad["warning"])
|
||||||
|
win.setText(self._trad["format_not_exportable"])
|
||||||
|
win.exec()
|
||||||
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._export_to_file_st(filename)
|
self._export_to_file_st(filename)
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = list(
|
self._lst = list(
|
||||||
filter(
|
filter(
|
||||||
lambda ica: ica._deleted == False,
|
lambda ica: ica._deleted is False,
|
||||||
self._data._data
|
self._data._data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -68,15 +68,22 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "InitialConditionsAdisTS"
|
_pamhyr_ui = "InitialConditionsAdisTS"
|
||||||
_pamhyr_name = "Initial condition AdisTS"
|
_pamhyr_name = "Initial condition AdisTS"
|
||||||
|
|
||||||
def __init__(self, data=None, study=None, config=None, parent=None):
|
def __init__(self, data=None, pollutant_id=None, study=None,
|
||||||
|
config=None, parent=None):
|
||||||
self._data = []
|
self._data = []
|
||||||
self._data.append(data)
|
self._data.append(data)
|
||||||
|
self._pollutant_id = pollutant_id
|
||||||
trad = IcAdisTSTranslate()
|
trad = IcAdisTSTranslate()
|
||||||
|
|
||||||
|
self._pollutant_name = next(
|
||||||
|
(x.name for x in study._river._Pollutants.Pollutants_List
|
||||||
|
if x.id == self._pollutant_id),
|
||||||
|
None
|
||||||
|
)
|
||||||
name = (
|
name = (
|
||||||
trad[self._pamhyr_name] +
|
trad[self._pamhyr_name] +
|
||||||
" - " + study.name +
|
" - " + study.name +
|
||||||
" - " + self._data[0].name
|
" - " + self._pollutant_name
|
||||||
)
|
)
|
||||||
|
|
||||||
super(InitialConditionsAdisTSWindow, self).__init__(
|
super(InitialConditionsAdisTSWindow, self).__init__(
|
||||||
|
|
|
||||||
|
|
@ -34,29 +34,14 @@ class SetDataCommand(QUndoCommand):
|
||||||
self._data = data
|
self._data = data
|
||||||
self._index = index
|
self._index = index
|
||||||
self._column = column
|
self._column = column
|
||||||
self._old = self._data._data[self._index][self._column]
|
self._old = self._data.get_i(self._index)[self._column]
|
||||||
_type = self._data._types[self._column]
|
self._new = new_value
|
||||||
self._new = _type(new_value)
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
if self._column == 0:
|
self._data._set_i_c_v(self._index, self._column, self._old)
|
||||||
self._data._data[self._index] = (
|
|
||||||
self._old, self._data._data[self._index][1]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._data._data[self._index] = (
|
|
||||||
self._data._data[self._index][0], self._old
|
|
||||||
)
|
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._column == 0:
|
self._data._set_i_c_v(self._index, self._column, self._new)
|
||||||
self._data._data[self._index] = (
|
|
||||||
self._new, self._data._data[self._index][1]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._data._data[self._index] = (
|
|
||||||
self._data._data[self._index][0], self._new
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AddCommand(QUndoCommand):
|
class AddCommand(QUndoCommand):
|
||||||
|
|
@ -72,11 +57,7 @@ class AddCommand(QUndoCommand):
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._data._data.insert(
|
self._new = self._data.add(self._index)
|
||||||
self._index, (
|
|
||||||
self._data._types[0](0), self._data._types[1](0.0)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self._data._data.insert(self._index, self._new)
|
self._data._data.insert(self._index, self._new)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,38 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "EditLateralContributionAdisTS"
|
_pamhyr_ui = "EditLateralContributionAdisTS"
|
||||||
_pamhyr_name = "Edit lateral contribution AdisTS"
|
_pamhyr_name = "Edit lateral contribution AdisTS"
|
||||||
|
|
||||||
def __init__(self, data=None,
|
def __init__(self, data=None, study=None, config=None, parent=None):
|
||||||
study=None, config=None,
|
|
||||||
parent=None):
|
|
||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
trad = LCETranslate()
|
trad = LCETranslate()
|
||||||
|
|
||||||
name = trad[self._pamhyr_name]
|
name = trad[self._pamhyr_name]
|
||||||
|
|
||||||
|
if self._data is not None:
|
||||||
|
if self._data.reach is not None:
|
||||||
|
reach_name = next(filter(
|
||||||
|
lambda reach: reach.id == self._data.reach,
|
||||||
|
study.river.reachs()
|
||||||
|
)).name
|
||||||
|
else:
|
||||||
|
reach_name = trad['not_associated']
|
||||||
|
|
||||||
|
if self._data.begin_rk is not None:
|
||||||
|
begin_rk = self._data.begin_rk
|
||||||
|
else:
|
||||||
|
begin_rk = trad['not_associated']
|
||||||
|
|
||||||
|
if self._data.end_rk is not None:
|
||||||
|
end_rk = self._data.end_rk
|
||||||
|
else:
|
||||||
|
end_rk = trad['not_associated']
|
||||||
|
|
||||||
|
name += (
|
||||||
|
f" - {study.name} - " +
|
||||||
|
f"{reach_name} - " +
|
||||||
|
f"({begin_rk} - " +
|
||||||
|
f"{end_rk})"
|
||||||
|
)
|
||||||
|
|
||||||
super(EditLateralContributionAdisTSWindow, self).__init__(
|
super(EditLateralContributionAdisTSWindow, self).__init__(
|
||||||
title=name,
|
title=name,
|
||||||
study=study,
|
study=study,
|
||||||
|
|
@ -66,20 +90,6 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
parent=parent
|
parent=parent
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._data is not None:
|
|
||||||
if self._data.edge is not None:
|
|
||||||
edge_name = next(filter(
|
|
||||||
lambda edge: edge.id == self._data.edge,
|
|
||||||
self._study.river.edges()
|
|
||||||
)).name
|
|
||||||
else:
|
|
||||||
edge_name = trad['not_associated']
|
|
||||||
|
|
||||||
name += (
|
|
||||||
f"{study.name} - " +
|
|
||||||
f"{edge_name})"
|
|
||||||
)
|
|
||||||
|
|
||||||
self._hash_data.append(data)
|
self._hash_data.append(data)
|
||||||
|
|
||||||
self.setup_table()
|
self.setup_table()
|
||||||
|
|
|
||||||
|
|
@ -116,10 +116,22 @@ class TableModel(PamhyrTableModel):
|
||||||
self._pollutant = pollutant
|
self._pollutant = pollutant
|
||||||
|
|
||||||
super(TableModel, self).__init__(trad=trad, **kwargs)
|
super(TableModel, self).__init__(trad=trad, **kwargs)
|
||||||
|
self._setup_lst()
|
||||||
|
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = self._data.lateral_contributions_adists.lst
|
if self._lcs_list is not None:
|
||||||
self._tab = self._opt_data
|
self._lcs_pol_list = [
|
||||||
|
lcs for lcs in self._lcs_list._lst
|
||||||
|
if lcs.pollutant == self._pollutant
|
||||||
|
]
|
||||||
|
|
||||||
|
self._lst = list(
|
||||||
|
filter(
|
||||||
|
lambda x: x._deleted is False,
|
||||||
|
self._lcs_pol_list
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# self._tab = self._opt_data
|
||||||
self._long_types = self._trad.get_dict("long_types")
|
self._long_types = self._trad.get_dict("long_types")
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
|
|
@ -190,17 +202,37 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._setup_lst()
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
|
row_by_lc = {
|
||||||
|
id(lc): row for row, lc in enumerate(self._lcs_list._lst)
|
||||||
|
}
|
||||||
|
global_rows = [
|
||||||
|
row_by_lc[id(self._lst[row])]
|
||||||
|
for row in rows
|
||||||
|
if 0 <= row < len(self._lst)
|
||||||
|
]
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._lst, rows
|
self._lcs_list, global_rows
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._setup_lst()
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self._undo.undo()
|
||||||
|
self._setup_lst()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
self._undo.redo()
|
||||||
|
self._setup_lst()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,13 @@ class AddCommand(QUndoCommand):
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
del self._lcs[self._index]
|
self._lcs.delete_i(self._index)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._lcs.new(self._index, self._pollutant)
|
self._new = self._lcs.new(self._index, self._pollutant)
|
||||||
else:
|
else:
|
||||||
self._lcs_lst.insert(self._index, self._new)
|
self._lcs.insert(self._index, self._new)
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
|
|
@ -107,15 +107,14 @@ class DelCommand(QUndoCommand):
|
||||||
self._lcs = lcs
|
self._lcs = lcs
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
|
|
||||||
self._bc = []
|
self._lc = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._bc.append((row, self._lcs[row]))
|
self._lc.append((row, self._lcs._lst[row]))
|
||||||
self._bc.sort()
|
self._lc.sort()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for row, el in self._bc:
|
for row, el in self._lc:
|
||||||
self._lcs.insert(row, el)
|
self._lcs.insert(row, el)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for row in self._rows:
|
self._lcs.delete_i(self._rows)
|
||||||
del self._lcs[row]
|
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,24 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "LateralContributionsAdisTS"
|
_pamhyr_ui = "LateralContributionsAdisTS"
|
||||||
_pamhyr_name = "Lateral contribution AdisTS"
|
_pamhyr_name = "Lateral contribution AdisTS"
|
||||||
|
|
||||||
def __init__(self, study=None, pollutant=None, config=None, parent=None):
|
def __init__(self, data=None, study=None, pollutant_id=None,
|
||||||
|
config=None, parent=None):
|
||||||
|
self._pollutant = pollutant_id
|
||||||
|
self._study = study
|
||||||
|
self._data = data
|
||||||
trad = LCTranslate()
|
trad = LCTranslate()
|
||||||
name = trad[self._pamhyr_name] + " - " + study.name
|
|
||||||
|
|
||||||
self._pollutant = pollutant
|
self._pollutant_name = next(
|
||||||
|
(x.name for x in study._river._Pollutants.Pollutants_List
|
||||||
|
if x.id == self._pollutant),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
name = (
|
||||||
|
trad[self._pamhyr_name] +
|
||||||
|
" - " + study.name +
|
||||||
|
" - " + self._pollutant_name
|
||||||
|
)
|
||||||
|
|
||||||
super(LateralContributionAdisTSWindow, self).__init__(
|
super(LateralContributionAdisTSWindow, self).__init__(
|
||||||
title=name,
|
title=name,
|
||||||
|
|
@ -110,7 +123,7 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
opt_data="liquid",
|
# opt_data="liquid",
|
||||||
pollutant=self._pollutant,
|
pollutant=self._pollutant,
|
||||||
lcs_list=self._lcs,
|
lcs_list=self._lcs,
|
||||||
)
|
)
|
||||||
|
|
@ -237,6 +250,9 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
|
|
||||||
def edit(self):
|
def edit(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
|
if not rows:
|
||||||
|
return
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
data = self._lcs.lst[row]
|
data = self._lcs.lst[row]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,8 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
initial = InitialConditionsAdisTSWindow(
|
initial = InitialConditionsAdisTSWindow(
|
||||||
study=self._study,
|
study=self._study,
|
||||||
parent=self,
|
parent=self,
|
||||||
data=ics_adists
|
data=ics_adists,
|
||||||
|
pollutant_id=pollutant_id
|
||||||
)
|
)
|
||||||
initial.show()
|
initial.show()
|
||||||
|
|
||||||
|
|
@ -229,7 +230,8 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
for row in rows:
|
for row in rows:
|
||||||
pollutant_id = self._pollutants_lst.get(row).id
|
pollutant_id = self._pollutants_lst.get(row).id
|
||||||
|
|
||||||
bclist = self._study.river.boundary_conditions_adists.BCs_AdisTS_List
|
river = self._study.river
|
||||||
|
bclist = river.boundary_conditions_adists.BCs_AdisTS_List
|
||||||
bcs_adists = [
|
bcs_adists = [
|
||||||
x for x in bclist
|
x for x in bclist
|
||||||
if x.pollutant == pollutant_id
|
if x.pollutant == pollutant_id
|
||||||
|
|
@ -256,6 +258,9 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
|
|
||||||
pollutant_id = self._pollutants_lst.get(rows[0]).id
|
pollutant_id = self._pollutants_lst.get(rows[0]).id
|
||||||
|
|
||||||
|
lclist = self._study.river.lateral_contributions_adists.Lat_Cont_List
|
||||||
|
lcs_adists = [x for x in lclist if x.pollutant == pollutant_id]
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
LateralContributionAdisTSWindow,
|
LateralContributionAdisTSWindow,
|
||||||
data=[self._study, pollutant_id, None]
|
data=[self._study, pollutant_id, None]
|
||||||
|
|
@ -264,8 +269,9 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
|
|
||||||
lateral = LateralContributionAdisTSWindow(
|
lateral = LateralContributionAdisTSWindow(
|
||||||
study=self._study,
|
study=self._study,
|
||||||
pollutant=pollutant_id,
|
parent=self,
|
||||||
parent=self
|
data=lcs_adists,
|
||||||
|
pollutant_id=pollutant_id,
|
||||||
)
|
)
|
||||||
lateral.show()
|
lateral.show()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ from PyQt5.QtWidgets import QDoubleSpinBox
|
||||||
|
|
||||||
|
|
||||||
class FlexibleDoubleSpinBox(QDoubleSpinBox):
|
class FlexibleDoubleSpinBox(QDoubleSpinBox):
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
if event.text() == ".":
|
if event.text() == ".":
|
||||||
# Simule une virgule à la place du point
|
# Simule une virgule à la place du point
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue