work on hydraulic structures

setup.py
Theophile Terraz 2023-12-11 16:53:53 +01:00
parent f302e18d71
commit 7db65f127e
7 changed files with 56 additions and 17 deletions

View File

@ -185,3 +185,6 @@ class BasicHS(SQLSubModel):
@property @property
def lst(self): def lst(self):
return self._data.copy() return self._data.copy()
def convert(self, new_type):
return new_type(id=self.id, name=self.name, status=self._status)

View File

@ -41,6 +41,23 @@ class NotDefined(BasicHS):
] ]
class Dummy(BasicHS):
def __init__(self, id: int = -1, name: str = "",
status=None):
super(Dummy, self).__init__(
id=id, name=name,
status=status
)
self._type = "DU"
self._data = [
BHSValue("foo", float, 0.0),
BHSValue("bar", float, 42.0),
BHSValue("baz", int, 13),
]
BHS_types = { BHS_types = {
"ND": NotDefined, "ND": NotDefined,
"DU": Dummy,
} }

View File

@ -256,7 +256,7 @@ class HydraulicStructure(SQLSubModel):
lambda e: e[1], lambda e: e[1],
filter( filter(
lambda e: e[0] not in indexes, lambda e: e[0] not in indexes,
enumerate(self.data) enumerate(self._data)
) )
) )
) )
@ -266,7 +266,7 @@ class HydraulicStructure(SQLSubModel):
self._data = list( self._data = list(
filter( filter(
lambda e: e not in els, lambda e: e not in els,
self.data self._data
) )
) )
self._status.modified() self._status.modified()

View File

@ -97,8 +97,13 @@ class ComboBoxDelegate(QItemDelegate):
class TableModel(PamhyrTableModel): class TableModel(PamhyrTableModel):
def _setup_lst(self): def __init__(self, trad=None, **kwargs):
self._lst = self._data.basic_structures self._trad = trad
self._long_types = {}
if self._trad is not None:
self._long_types = self._trad.get_dict("long_types")
super(TableModel, self).__init__(trad=trad, **kwargs)
def rowCount(self, parent): def rowCount(self, parent):
return len(self._lst) return len(self._lst)
@ -111,9 +116,9 @@ class TableModel(PamhyrTableModel):
column = index.column() column = index.column()
if self._headers[column] == "name": if self._headers[column] == "name":
return self._lst[row].name return self._data.basic_structure(row).name
elif self._headers[column] == "type": elif self._headers[column] == "type":
n = self._lst[row].type return self._long_types[self._data.basic_structure(row).type]
return QVariant() return QVariant()
@ -132,9 +137,11 @@ 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 v == value)
self._undo.push( self._undo.push(
SetTypeCommand( SetTypeCommand(
self._data, row, type self._data, row, BHS_types[key]
) )
) )
except Exception as e: except Exception as e:

View File

@ -29,6 +29,7 @@ class BasicHydraulicStructuresTranslate(PamhyrTranslate):
self._sub_dict["long_types"] = { self._sub_dict["long_types"] = {
"ND": _translate("BasicHydraulicStructures", "Not defined"), "ND": _translate("BasicHydraulicStructures", "Not defined"),
"DU": _translate("BasicHydraulicStructures", "Dummy"),
} }
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {

View File

@ -41,21 +41,23 @@ class SetNameCommand(QUndoCommand):
class SetTypeCommand(QUndoCommand): class SetTypeCommand(QUndoCommand):
def __init__(self, hs, index, reach): def __init__(self, hs, index, new_type):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._hs = hs self._hs = hs
self._index = index self._index = index
self._type = _type self._type = new_type
self._old = self._hs.basic_structure(self._index) self._old = self._hs.basic_structure(self._index)
self._new = self._hs.basic_structure(self._index)\ self._new = self._hs.basic_structure(self._index)\
.convert(self._type) .convert(self._type)
def undo(self): def undo(self):
self._hs.basic_structure(self._index).convert(self._old) self._hs.delete_i([self._index])
self._hs.insert(self._index, self._old)
def redo(self): def redo(self):
self._hs.basic_structure(self._index).convert(self._new) self._hs.delete_i([self._index])
self._hs.insert(self._index, self._new)
class AddCommand(QUndoCommand): class AddCommand(QUndoCommand):
@ -94,7 +96,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):
@ -108,9 +110,7 @@ class PasteCommand(QUndoCommand):
self._bhs.reverse() self._bhs.reverse()
def undo(self): def undo(self):
self._hs.delete_i( self._hs.delete_i(range(self._row, self._row + len(self._bhs))
self._tab,
range(self._row, self._row + len(self._bhs))
) )
def redo(self): def redo(self):

View File

@ -122,11 +122,22 @@ class BasicHydraulicStructuresWindow(PamhyrWindow):
self.plot_layout.addWidget(self.toolbar) self.plot_layout.addWidget(self.toolbar)
self.plot_layout.addWidget(self.canvas) self.plot_layout.addWidget(self.canvas)
reach = self._hs.input_reach
profile_kp = self._hs.input_kp
if profile_kp is not None:
profiles = reach.reach.get_profiles_from_kp(float(profile_kp))
else:
profiles = None
if profiles is not None:
profile = profiles[0]
else:
profile = None
self.plot_ac = PlotAC( self.plot_ac = PlotAC(
canvas=self.canvas, canvas=self.canvas,
river=self._study.river, river=self._study.river,
reach=None, reach=self._hs.input_reach,
profile=None, profile=profile,
toolbar=self.toolbar toolbar=self.toolbar
) )
self.plot_ac.draw() self.plot_ac.draw()