mirror of https://gitlab.com/pamhyr/pamhyr2
merge
commit
79b31e8d08
|
|
@ -80,11 +80,15 @@ class BasicHS(SQLSubModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_ctor_from_type(cls, t):
|
def _get_ctor_from_type(cls, t):
|
||||||
from Model.HydraulicStructure.Basic.Types import (
|
from Model.HydraulicStructures.Basic.Types import (
|
||||||
NotDefined,
|
NotDefined, Dummy,
|
||||||
)
|
)
|
||||||
|
|
||||||
res = NotDefined
|
res = NotDefined
|
||||||
|
|
||||||
|
if t == "DU":
|
||||||
|
res = Dummy
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -93,7 +97,8 @@ class BasicHS(SQLSubModel):
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, name, type, enabled, hs " +
|
"SELECT id, name, type, enabled, hs " +
|
||||||
"FROM hydraulic_structures "
|
"FROM hydraulic_structures_basic " +
|
||||||
|
f"WHERE hs = {data['hs_id']} "
|
||||||
)
|
)
|
||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
|
|
@ -113,7 +118,7 @@ class BasicHS(SQLSubModel):
|
||||||
bhs.enabled = enabled
|
bhs.enabled = enabled
|
||||||
|
|
||||||
data['bhs_id'] = bhs_id
|
data['bhs_id'] = bhs_id
|
||||||
bhs._data = BasicHSValue._db_load(
|
bhs._data = BHSValue._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -144,7 +149,7 @@ class BasicHS(SQLSubModel):
|
||||||
data['bhs_id'] = self.id
|
data['bhs_id'] = self.id
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM hydraulic_structures_basic_value " +
|
"DELETE FROM hydraulic_structures_basic_value " +
|
||||||
f"WHERE bhs = {bhs_id}"
|
f"WHERE bhs = {self.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for values in self._data:
|
for values in self._data:
|
||||||
|
|
@ -183,8 +188,8 @@ class BasicHS(SQLSubModel):
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def lst(self):
|
def parameters(self):
|
||||||
return self._data.copy()
|
return self._data
|
||||||
|
|
||||||
def convert(self, new_type):
|
def convert(self, new_type):
|
||||||
return new_type(id=self.id, name=self.name, status=self._status)
|
return new_type(id=self.id, name=self.name, status=self._status)
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,9 @@ class NotDefined(BasicHS):
|
||||||
|
|
||||||
self._type = "ND"
|
self._type = "ND"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("foo", float, 0.0),
|
BHSValue("foo", float, 0.0, status=status),
|
||||||
BHSValue("bar", float, 42.0),
|
BHSValue("bar", float, 42.0, status=status),
|
||||||
BHSValue("baz", int, 13),
|
BHSValue("baz", int, 13, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||||
|
|
||||||
|
|
@ -117,15 +118,15 @@ class HydraulicStructure(SQLSubModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
hs.enabled = enabled
|
hs.enabled = enabled
|
||||||
hs.input_kp = input_kp
|
hs.input_kp = input_kp if input_kp != -1 else None
|
||||||
hs.output_kp = output_kp
|
hs.output_kp = output_kp if output_kp != -1 else None
|
||||||
|
|
||||||
hs.input_reach, hs.output_reach = reduce(
|
hs.input_reach, hs.output_reach = reduce(
|
||||||
lambda acc, n: (
|
lambda acc, n: (
|
||||||
n if n.id == input_reach_id else acc[0],
|
n if n.id == input_reach_id else acc[0],
|
||||||
n if n.id == output_reach_id else acc[1]
|
n if n.id == output_reach_id else acc[1]
|
||||||
),
|
),
|
||||||
data["reachs"],
|
data["edges"],
|
||||||
[None, None]
|
[None, None]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class Study(SQLModel):
|
||||||
def is_saved(self):
|
def is_saved(self):
|
||||||
return self.status.is_saved()
|
return self.status.is_saved()
|
||||||
|
|
||||||
def save(self):
|
def save(self, progress=None):
|
||||||
# Save a copy of database
|
# Save a copy of database
|
||||||
fdir, fname = os.path.split(self.filename)
|
fdir, fname = os.path.split(self.filename)
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ class Study(SQLModel):
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
self.last_save_date = datetime.now()
|
self.last_save_date = datetime.now()
|
||||||
self._save()
|
self._save(progress=progress)
|
||||||
self.status.save()
|
self.status.save()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -266,38 +266,54 @@ class Study(SQLModel):
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _save(self):
|
def _save(self, progress=None):
|
||||||
|
progress = progress if progress is not None else lambda: None
|
||||||
|
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE info SET " +
|
f"UPDATE info SET " +
|
||||||
f"value='{self._db_format(self.name)}' WHERE key='name'"
|
f"value='{self._db_format(self.name)}' WHERE key='name'"
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE info SET " +
|
f"UPDATE info SET " +
|
||||||
f"value='{self._db_format(self.description)}' " +
|
f"value='{self._db_format(self.description)}' " +
|
||||||
"WHERE key='description'"
|
"WHERE key='description'"
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE info SET " +
|
f"UPDATE info SET " +
|
||||||
f"value='{self._time_system}' WHERE key='time_system'"
|
f"value='{self._time_system}' WHERE key='time_system'"
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE info SET " +
|
f"UPDATE info SET " +
|
||||||
f"value='{timestamp(self._date)}' WHERE key='date'"
|
f"value='{timestamp(self._date)}' WHERE key='date'"
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE info SET " +
|
f"UPDATE info SET " +
|
||||||
f"value='{timestamp(self.creation_date)}' " +
|
f"value='{timestamp(self.creation_date)}' " +
|
||||||
"WHERE key='creation_date'"
|
"WHERE key='creation_date'"
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE info SET " +
|
f"UPDATE info SET " +
|
||||||
f"value='{timestamp(self.last_save_date)}' " +
|
f"value='{timestamp(self.last_save_date)}' " +
|
||||||
"WHERE key='last_save_date'"
|
"WHERE key='last_save_date'"
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
|
|
||||||
self._save_submodel([self._river])
|
self._save_submodel([self._river], data=progress)
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
|
def sql_save_request_count(self):
|
||||||
|
return self._count()
|
||||||
|
|
||||||
|
def _count(self):
|
||||||
|
cnt = self._save_count([self._river])
|
||||||
|
logger.debug(cnt)
|
||||||
|
return cnt + 6
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close db connection
|
"""Close db connection
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import sqlite3
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
from tools import SQL
|
from tools import SQL
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
@ -87,11 +88,16 @@ class SQLModel(SQL):
|
||||||
raise NotImplementedMethodeError(self, self._update)
|
raise NotImplementedMethodeError(self, self._update)
|
||||||
|
|
||||||
def _save_submodel(self, objs, data=None):
|
def _save_submodel(self, objs, data=None):
|
||||||
def fn(sql): return self.execute(
|
progress = data if data is not None else lambda: None
|
||||||
|
|
||||||
|
def fn(sql):
|
||||||
|
res = self.execute(
|
||||||
sql,
|
sql,
|
||||||
fetch_one=False,
|
fetch_one=False,
|
||||||
commit=False
|
commit=False
|
||||||
)
|
)
|
||||||
|
progress()
|
||||||
|
return res
|
||||||
|
|
||||||
ok = True
|
ok = True
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
|
|
@ -100,9 +106,43 @@ class SQLModel(SQL):
|
||||||
self.commit()
|
self.commit()
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
def _save(self):
|
def _save(self, progress=None):
|
||||||
raise NotImplementedMethodeError(self, self._save)
|
raise NotImplementedMethodeError(self, self._save)
|
||||||
|
|
||||||
|
def _count(self):
|
||||||
|
raise NotImplementedMethodeError(self, self._count)
|
||||||
|
|
||||||
|
def _save_count(self, objs, data=None):
|
||||||
|
counter = {
|
||||||
|
"insert": 0,
|
||||||
|
"update": 0,
|
||||||
|
"delete": 0,
|
||||||
|
"other": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
def fn(sql):
|
||||||
|
if "insert" in sql.lower():
|
||||||
|
counter["insert"] = counter["insert"] + 1
|
||||||
|
elif "update" in sql.lower():
|
||||||
|
counter["update"] = counter["update"] + 1
|
||||||
|
elif "delete" in sql.lower():
|
||||||
|
counter["delete"] = counter["delete"] + 1
|
||||||
|
else:
|
||||||
|
counter["other"] = counter["other"] + 1
|
||||||
|
return []
|
||||||
|
|
||||||
|
ok = True
|
||||||
|
for obj in objs:
|
||||||
|
ok &= obj._db_save(fn)
|
||||||
|
|
||||||
|
logger.debug(counter)
|
||||||
|
|
||||||
|
return reduce(
|
||||||
|
lambda acc, k: acc + counter[k],
|
||||||
|
counter,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load(cls, filename=None):
|
def _load(cls, filename=None):
|
||||||
raise NotImplementedMethodeError(cls, cls._load)
|
raise NotImplementedMethodeError(cls, cls._load)
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,15 @@ from PyQt5.QtWidgets import (
|
||||||
QDialogButtonBox, QPushButton, QLineEdit,
|
QDialogButtonBox, QPushButton, QLineEdit,
|
||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||||
QComboBox,
|
QComboBox, QMessageBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
||||||
from View.HydraulicStructures.BasicHydraulicStructures.UndoCommand import (
|
from View.HydraulicStructures.BasicHydraulicStructures.UndoCommand import (
|
||||||
SetNameCommand, SetTypeCommand,
|
SetNameCommand, SetTypeCommand,
|
||||||
AddCommand, DelCommand,
|
SetEnabledCommand, AddCommand, DelCommand,
|
||||||
|
SetValueCommand,
|
||||||
)
|
)
|
||||||
from Model.HydraulicStructures.Basic.Types import BHS_types
|
from Model.HydraulicStructures.Basic.Types import BHS_types
|
||||||
|
|
||||||
|
|
@ -61,15 +62,13 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
self.editor = QComboBox(parent)
|
self.editor = QComboBox(parent)
|
||||||
|
|
||||||
|
|
||||||
lst = list(
|
lst = list(
|
||||||
map(
|
map(
|
||||||
lambda k: self._long_types[k], BHS_types.keys()
|
lambda k: self._long_types[k],
|
||||||
|
BHS_types.keys()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.editor.addItems(
|
self.editor.addItems(lst)
|
||||||
lst
|
|
||||||
)
|
|
||||||
|
|
||||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||||
return self.editor
|
return self.editor
|
||||||
|
|
@ -137,20 +136,35 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "type":
|
elif self._headers[column] == "type":
|
||||||
key = next(k for k, v in self._long_types.items()
|
if self._question_set_type():
|
||||||
if v == value)
|
key = next(
|
||||||
|
k for k, v in self._long_types.items()
|
||||||
|
if v == value
|
||||||
|
)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetTypeCommand(
|
SetTypeCommand(
|
||||||
self._data, row, BHS_types[key]
|
self._data, row, BHS_types[key]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.error(e)
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
|
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _question_set_type(self):
|
||||||
|
question = QMessageBox(self._parent)
|
||||||
|
|
||||||
|
question.setWindowTitle(self._trad['msg_type_change_title'])
|
||||||
|
question.setText(self._trad['msg_type_change_text'])
|
||||||
|
question.setStandardButtons(QMessageBox.Cancel | QMessageBox.Ok)
|
||||||
|
question.setIcon(QMessageBox.Question)
|
||||||
|
|
||||||
|
res = question.exec()
|
||||||
|
return res == QMessageBox.Ok
|
||||||
|
|
||||||
def add(self, row, parent=QModelIndex()):
|
def add(self, row, parent=QModelIndex()):
|
||||||
self.beginInsertRows(parent, row, row - 1)
|
self.beginInsertRows(parent, row, row - 1)
|
||||||
|
|
||||||
|
|
@ -175,6 +189,14 @@ class TableModel(PamhyrTableModel):
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||||
|
self._undo.push(
|
||||||
|
SetEnabledCommand(
|
||||||
|
self._lst, row, enabled
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._undo.undo()
|
self._undo.undo()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
@ -182,3 +204,72 @@ class TableModel(PamhyrTableModel):
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._undo.redo()
|
self._undo.redo()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
|
||||||
|
class ParametersTableModel(PamhyrTableModel):
|
||||||
|
def __init__(self, trad=None, **kwargs):
|
||||||
|
self._trad = trad
|
||||||
|
self._long_types = {}
|
||||||
|
|
||||||
|
if self._trad is not None:
|
||||||
|
self._long_types = self._trad.get_dict("long_types")
|
||||||
|
|
||||||
|
self._hs_index = None
|
||||||
|
|
||||||
|
super(ParametersTableModel, self).__init__(trad=trad, **kwargs)
|
||||||
|
|
||||||
|
def rowCount(self, parent):
|
||||||
|
if self._hs_index is None:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return len(
|
||||||
|
self._data.basic_structure(self._hs_index)
|
||||||
|
)
|
||||||
|
|
||||||
|
def data(self, index, role):
|
||||||
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
if self._hs_index is None:
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
row = index.row()
|
||||||
|
column = index.column()
|
||||||
|
|
||||||
|
hs = self._data.basic_structure(self._hs_index)
|
||||||
|
|
||||||
|
if self._headers[column] == "name":
|
||||||
|
return hs.parameters[row].name
|
||||||
|
elif self._headers[column] == "value":
|
||||||
|
return str(hs.parameters[row].value)
|
||||||
|
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
def setData(self, index, value, role=Qt.EditRole):
|
||||||
|
if not index.isValid() or role != Qt.EditRole:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self._hs_index is None:
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
row = index.row()
|
||||||
|
column = index.column()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if self._headers[column] == "value":
|
||||||
|
self._undo.push(
|
||||||
|
SetValueCommand(
|
||||||
|
self._data.basic_structure(self._hs_index),
|
||||||
|
row, value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
logger.debug(traceback.format_exc())
|
||||||
|
|
||||||
|
self.dataChanged.emit(index, index)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def update_hs_index(self, index):
|
||||||
|
self._hs_index = index
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,17 @@ class BasicHydraulicStructuresTranslate(PamhyrTranslate):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(BasicHydraulicStructuresTranslate, self).__init__()
|
super(BasicHydraulicStructuresTranslate, self).__init__()
|
||||||
|
|
||||||
|
self._dict['msg_type_change_title'] = _translate(
|
||||||
|
"BasicHydraulicStructures",
|
||||||
|
"Change hydraulic structure type"
|
||||||
|
)
|
||||||
|
|
||||||
|
self._dict['msg_type_change_text'] = _translate(
|
||||||
|
"BasicHydraulicStructures",
|
||||||
|
"Do you want to change the hydraulic structure type and reset \
|
||||||
|
hydraulic structure values?"
|
||||||
|
)
|
||||||
|
|
||||||
self._sub_dict["long_types"] = {
|
self._sub_dict["long_types"] = {
|
||||||
"ND": _translate("BasicHydraulicStructures", "Not defined"),
|
"ND": _translate("BasicHydraulicStructures", "Not defined"),
|
||||||
"S1": _translate("BasicHydraulicStructures", "Seuil déversoir"),
|
"S1": _translate("BasicHydraulicStructures", "Seuil déversoir"),
|
||||||
|
|
@ -45,3 +56,8 @@ class BasicHydraulicStructuresTranslate(PamhyrTranslate):
|
||||||
"name": _translate("BasicHydraulicStructures", "Name"),
|
"name": _translate("BasicHydraulicStructures", "Name"),
|
||||||
"type": _translate("BasicHydraulicStructures", "Type"),
|
"type": _translate("BasicHydraulicStructures", "Type"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._sub_dict["table_headers_parameters"] = {
|
||||||
|
"name": _translate("BasicHydraulicStructures", "Name"),
|
||||||
|
"value": _translate("BasicHydraulicStructures", "Value"),
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,22 @@ class SetTypeCommand(QUndoCommand):
|
||||||
self._hs.insert(self._index, self._new)
|
self._hs.insert(self._index, self._new)
|
||||||
|
|
||||||
|
|
||||||
|
class SetEnabledCommand(QUndoCommand):
|
||||||
|
def __init__(self, hs, index, enabled):
|
||||||
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
|
self._hs = hs
|
||||||
|
self._index = index
|
||||||
|
self._old = not enabled
|
||||||
|
self._new = enabled
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self._hs.basic_structure(self._index).enabled = self._old
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
self._hs.basic_structure(self._index).enabled = self._new
|
||||||
|
|
||||||
|
|
||||||
class AddCommand(QUndoCommand):
|
class AddCommand(QUndoCommand):
|
||||||
def __init__(self, hs, index):
|
def __init__(self, hs, index):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
@ -96,7 +112,7 @@ class DelCommand(QUndoCommand):
|
||||||
self._hs.insert(row, el)
|
self._hs.insert(row, el)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._hs.delete_i([self._rows])
|
self._hs.delete_i(self._rows)
|
||||||
|
|
||||||
|
|
||||||
class PasteCommand(QUndoCommand):
|
class PasteCommand(QUndoCommand):
|
||||||
|
|
@ -110,9 +126,28 @@ class PasteCommand(QUndoCommand):
|
||||||
self._bhs.reverse()
|
self._bhs.reverse()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._hs.delete_i(range(self._row, self._row + len(self._bhs))
|
self._hs.delete_i(range(self._row, self._row + len(self._bhs)))
|
||||||
)
|
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for r in self._bhs:
|
for r in self._bhs:
|
||||||
self._hs.insert(self._row, r)
|
self._hs.insert(self._row, r)
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# Basic hydraulic structure values #
|
||||||
|
####################################
|
||||||
|
|
||||||
|
|
||||||
|
class SetValueCommand(QUndoCommand):
|
||||||
|
def __init__(self, bhs, index, value):
|
||||||
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
|
self._bhs = bhs
|
||||||
|
self._index = index
|
||||||
|
self._old = self._bhs.parameters[self._index].value
|
||||||
|
self._new = self._bhs.parameters[self._index].type(value)
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self._bhs.parameters[self._index].value = self._old
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
self._bhs.parameters[self._index].value = self._new
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,13 @@ from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||||
from View.HydraulicStructures.PlotAC import PlotAC
|
from View.HydraulicStructures.PlotAC import PlotAC
|
||||||
|
|
||||||
from View.HydraulicStructures.BasicHydraulicStructures.Table import (
|
from View.HydraulicStructures.BasicHydraulicStructures.Table import (
|
||||||
TableModel, ComboBoxDelegate
|
ComboBoxDelegate, TableModel, ParametersTableModel,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.Network.GraphWidget import GraphWidget
|
from View.Network.GraphWidget import GraphWidget
|
||||||
from View.HydraulicStructures.BasicHydraulicStructures.Translate import BasicHydraulicStructuresTranslate
|
from View.HydraulicStructures.BasicHydraulicStructures.Translate import (
|
||||||
|
BasicHydraulicStructuresTranslate
|
||||||
|
)
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
@ -77,6 +79,10 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
self.setup_connections()
|
self.setup_connections()
|
||||||
|
|
||||||
def setup_table(self):
|
def setup_table(self):
|
||||||
|
self.setup_table_bhs()
|
||||||
|
self.setup_table_bhs_parameters()
|
||||||
|
|
||||||
|
def setup_table_bhs(self):
|
||||||
self._table = None
|
self._table = None
|
||||||
|
|
||||||
self._delegate_type = ComboBoxDelegate(
|
self._delegate_type = ComboBoxDelegate(
|
||||||
|
|
@ -95,6 +101,7 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
data=self._hs,
|
data=self._hs,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
|
parent=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
selectionModel = table.selectionModel()
|
selectionModel = table.selectionModel()
|
||||||
|
|
@ -108,6 +115,21 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
)
|
)
|
||||||
table.scrollTo(index)
|
table.scrollTo(index)
|
||||||
|
|
||||||
|
def setup_table_bhs_parameters(self):
|
||||||
|
self._table_parameters = None
|
||||||
|
|
||||||
|
table = self.find(QTableView, f"tableView_2")
|
||||||
|
self._table_parameters = ParametersTableModel(
|
||||||
|
table_view=table,
|
||||||
|
table_headers=self._trad.get_dict("table_headers_parameters"),
|
||||||
|
editable_headers=["value"],
|
||||||
|
delegates={},
|
||||||
|
trad=self._trad,
|
||||||
|
data=self._hs,
|
||||||
|
undo=self._undo_stack,
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
|
||||||
def setup_checkbox(self):
|
def setup_checkbox(self):
|
||||||
self._checkbox = self.find(QCheckBox, f"checkBox")
|
self._checkbox = self.find(QCheckBox, f"checkBox")
|
||||||
self._set_checkbox_state()
|
self._set_checkbox_state()
|
||||||
|
|
@ -145,17 +167,19 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||||
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
||||||
self._checkbox.stateChanged.connect(self._set_basic_structure_state)
|
self._checkbox.clicked.connect(self._set_basic_structure_state)
|
||||||
|
|
||||||
table = self.find(QTableView, "tableView")
|
table = self.find(QTableView, "tableView")
|
||||||
table.selectionModel()\
|
table.selectionModel()\
|
||||||
.selectionChanged\
|
.selectionChanged\
|
||||||
.connect(self.update)
|
.connect(self.update)
|
||||||
|
|
||||||
|
self._table.layoutChanged.connect(self.update)
|
||||||
|
|
||||||
def index_selected(self):
|
def index_selected(self):
|
||||||
table = self.find(QTableView, "tableView")
|
table = self.find(QTableView, "tableView")
|
||||||
r = table.selectionModel()\
|
r = table.selectionModel().selectedRows()
|
||||||
.selectedRows()
|
|
||||||
if len(r) > 0:
|
if len(r) > 0:
|
||||||
return r[0]
|
return r[0]
|
||||||
else:
|
else:
|
||||||
|
|
@ -163,8 +187,8 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
|
|
||||||
def index_selected_row(self):
|
def index_selected_row(self):
|
||||||
table = self.find(QTableView, "tableView")
|
table = self.find(QTableView, "tableView")
|
||||||
r = table.selectionModel()\
|
r = table.selectionModel().selectedRows()
|
||||||
.selectedRows()
|
|
||||||
if len(r) > 0:
|
if len(r) > 0:
|
||||||
return r[0].row()
|
return r[0].row()
|
||||||
else:
|
else:
|
||||||
|
|
@ -184,6 +208,7 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
|
|
||||||
if len(self._hs) == 0 or len(rows) == 0:
|
if len(self._hs) == 0 or len(rows) == 0:
|
||||||
self._table.add(0)
|
self._table.add(0)
|
||||||
else:
|
else:
|
||||||
|
|
@ -191,6 +216,7 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
|
|
||||||
if len(rows) == 0:
|
if len(rows) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -210,6 +236,7 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
|
|
||||||
def _set_checkbox_state(self):
|
def _set_checkbox_state(self):
|
||||||
row = self.index_selected_row()
|
row = self.index_selected_row()
|
||||||
|
|
||||||
if row is None:
|
if row is None:
|
||||||
self._checkbox.setEnabled(False)
|
self._checkbox.setEnabled(False)
|
||||||
self._checkbox.setChecked(True)
|
self._checkbox.setChecked(True)
|
||||||
|
|
@ -219,14 +246,17 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
|
||||||
|
|
||||||
def _set_basic_structure_state(self):
|
def _set_basic_structure_state(self):
|
||||||
row = self.index_selected_row()
|
row = self.index_selected_row()
|
||||||
if row is None:
|
|
||||||
self._checkbox.setEnabled(False)
|
if row is not None:
|
||||||
else:
|
self._table.enabled(
|
||||||
self._hs.basic_structure(row).enabled = self._checkbox.isChecked()
|
row,
|
||||||
|
self._checkbox.isChecked()
|
||||||
|
)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self._set_checkbox_state()
|
self._set_checkbox_state()
|
||||||
self._update_clear_plot()
|
self._update_parameters_table()
|
||||||
|
|
||||||
def _update_clear_plot(self):
|
def _update_parameters_table(self):
|
||||||
rows = self.index_selected_rows()
|
row = self.index_selected_row()
|
||||||
|
self._table_parameters.update_hs_index(row)
|
||||||
|
|
|
||||||
|
|
@ -106,13 +106,13 @@ class PlotAC(PamhyrPlot):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
||||||
if self.line_kp is None:
|
if self.line_kp is None:
|
||||||
self.draw()
|
self.draw()
|
||||||
else:
|
else:
|
||||||
if self._current_reach is None or self._current_profile is None:
|
if self._current_reach is None or self._current_profile is None:
|
||||||
self.clear()
|
self.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
profile = self._current_profile
|
profile = self._current_profile
|
||||||
x = profile.get_station()
|
x = profile.get_station()
|
||||||
z = profile.z()
|
z = profile.z()
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
val
|
val
|
||||||
)
|
)
|
||||||
|
|
||||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
||||||
return self.editor
|
return self.editor
|
||||||
|
|
||||||
def setEditorData(self, editor, index):
|
def setEditorData(self, editor, index):
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,9 @@ class SetEnabledCommand(QUndoCommand):
|
||||||
self._new = enabled
|
self._new = enabled
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
logger.info(f"Undo {self._new} -> {self._old}")
|
|
||||||
self._h_s_lst.get(self._index).enabled = self._old
|
self._h_s_lst.get(self._index).enabled = self._old
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
logger.info(f"Undo {self._old} -> {self._new}")
|
|
||||||
self._h_s_lst.get(self._index).enabled = self._new
|
self._h_s_lst.get(self._index).enabled = self._new
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,9 @@ from View.HydraulicStructures.Table import (
|
||||||
from View.Network.GraphWidget import GraphWidget
|
from View.Network.GraphWidget import GraphWidget
|
||||||
from View.HydraulicStructures.Translate import HydraulicStructuresTranslate
|
from View.HydraulicStructures.Translate import HydraulicStructuresTranslate
|
||||||
|
|
||||||
from View.HydraulicStructures.BasicHydraulicStructures.Window import BasicHydraulicStructuresWindow
|
from View.HydraulicStructures.BasicHydraulicStructures.Window import (
|
||||||
|
BasicHydraulicStructuresWindow
|
||||||
|
)
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ from PyQt5.QtGui import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
QTranslator, QEvent, QUrl,
|
Qt, QTranslator, QEvent, QUrl,
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QMainWindow, QApplication, QAction,
|
QMainWindow, QApplication, QAction,
|
||||||
QFileDialog, QShortcut, QMenu, QToolBar,
|
QFileDialog, QShortcut, QMenu, QToolBar,
|
||||||
QMessageBox,
|
QMessageBox, QProgressDialog,
|
||||||
)
|
)
|
||||||
from PyQt5.uic import loadUi
|
from PyQt5.uic import loadUi
|
||||||
|
|
||||||
|
|
@ -406,8 +406,20 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
if self._study.is_saved:
|
if self._study.is_saved:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
sql_request_count = self._study.sql_save_request_count()
|
||||||
|
progress = QProgressDialog(
|
||||||
|
"Saving...", None,
|
||||||
|
0, sql_request_count,
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
|
progress.setWindowModality(Qt.WindowModal)
|
||||||
|
progress.setValue(0)
|
||||||
|
|
||||||
logger.info("Save...")
|
logger.info("Save...")
|
||||||
self._study.save()
|
self._study.save(
|
||||||
|
progress=lambda: progress.setValue(progress.value() + 1)
|
||||||
|
)
|
||||||
|
logger.info("Done")
|
||||||
|
|
||||||
def save_as_study(self):
|
def save_as_study(self):
|
||||||
"""Save current study as new file
|
"""Save current study as new file
|
||||||
|
|
@ -428,7 +440,20 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
else:
|
else:
|
||||||
self._study.filename = file_name + ".pamhyr"
|
self._study.filename = file_name + ".pamhyr"
|
||||||
|
|
||||||
self._study.save()
|
sql_request_count = self._study.sql_save_request_count()
|
||||||
|
progress = QProgressDialog(
|
||||||
|
"Saving...", None,
|
||||||
|
0, sql_request_count,
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
|
progress.setWindowModality(Qt.WindowModal)
|
||||||
|
progress.setValue(0)
|
||||||
|
|
||||||
|
logger.info("Save...")
|
||||||
|
self._study.save(
|
||||||
|
progress=lambda: progress.setValue(progress.value() + 1)
|
||||||
|
)
|
||||||
|
logger.info("Done")
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# MSG AND DIALOG #
|
# MSG AND DIALOG #
|
||||||
|
|
|
||||||
|
|
@ -178,12 +178,15 @@ class EdgeItem(QGraphicsItem):
|
||||||
if self.graph.selected_item() == self:
|
if self.graph.selected_item() == self:
|
||||||
color = Qt.red
|
color = Qt.red
|
||||||
elif self.graph.current_edge() == self:
|
elif self.graph.current_edge() == self:
|
||||||
color = Qt.black
|
color = Qt.blue
|
||||||
elif not self.graph.graph.is_enable_edge(self.edge):
|
elif not self.graph.graph.is_enable_edge(self.edge):
|
||||||
color = Qt.darkGray
|
color = Qt.darkGray
|
||||||
|
|
||||||
painter.setPen(QPen(color, 2, Qt.SolidLine, Qt.RoundCap,
|
painter.setPen(
|
||||||
Qt.RoundJoin))
|
QPen(
|
||||||
|
color, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin
|
||||||
|
)
|
||||||
|
)
|
||||||
# Draw the line
|
# Draw the line
|
||||||
painter.drawLine(line)
|
painter.drawLine(line)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,8 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
trad=None,
|
trad=None,
|
||||||
data=None,
|
data=None,
|
||||||
undo=None,
|
undo=None,
|
||||||
opt_data=None):
|
opt_data=None,
|
||||||
|
parent=None):
|
||||||
super(PamhyrTableModel, self).__init__()
|
super(PamhyrTableModel, self).__init__()
|
||||||
|
|
||||||
self._table_view = table_view
|
self._table_view = table_view
|
||||||
|
|
@ -93,6 +94,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
self._editable_headers = editable_headers
|
self._editable_headers = editable_headers
|
||||||
self._delegates = delegates
|
self._delegates = delegates
|
||||||
self._trad = trad
|
self._trad = trad
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._opt_data = opt_data
|
self._opt_data = opt_data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue