LCS Complete

adists_num
Youcef AOUAD 2024-06-20 11:59:57 +02:00
parent 510bee115b
commit 02c597d109
11 changed files with 157 additions and 261 deletions

View File

@ -49,7 +49,7 @@ class LateralContributionAdisTS(SQLSubModel):
self._begin_kp = 0.0 self._begin_kp = 0.0
self._end_kp = 0.0 self._end_kp = 0.0
self._data = [] self._data = []
self._header = [] self._header = ["time", "rate"]
self._types = [float, float] self._types = [float, float]
LateralContributionAdisTS._id_cnt = max( LateralContributionAdisTS._id_cnt = max(

View File

@ -45,13 +45,13 @@ class SetDataCommand(QUndoCommand):
if self._column == 0: if self._column == 0:
self._data._data[self._index] = (self._old,self._data._data[self._index][1]) self._data._data[self._index] = (self._old,self._data._data[self._index][1])
else: else:
self._data._data[self._index] = (self._data._data[self._index][1], self._old) self._data._data[self._index] = (self._data._data[self._index][0], self._old)
def redo(self): def redo(self):
if self._column == 0: if self._column == 0:
self._data._data[self._index] = (self._new,self._data._data[self._index][1]) self._data._data[self._index] = (self._new,self._data._data[self._index][1])
else: else:
self._data._data[self._index] = (self._data._data[self._index][1], self._new) self._data._data[self._index] = (self._data._data[self._index][0], self._new)
class AddCommand(QUndoCommand): class AddCommand(QUndoCommand):
def __init__(self, data, index): def __init__(self, data, index):
@ -84,7 +84,7 @@ class DelCommand(QUndoCommand):
def undo(self): def undo(self):
for row, el in self._bc: for row, el in self._bc:
self._data.insert(row, el) self._data._data.insert(row, el)
def redo(self): def redo(self):
for row in self._rows: for row in self._rows:

View File

@ -31,7 +31,6 @@ _translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
class Plot(PamhyrPlot): class Plot(PamhyrPlot):
def __init__(self, mode="time", data=None, def __init__(self, mode="time", data=None,
trad=None, canvas=None, toolbar=None, trad=None, canvas=None, toolbar=None,

View File

@ -39,16 +39,11 @@ from PyQt5.QtWidgets import (
QTimeEdit, QDateTimeEdit, QItemDelegate, QTimeEdit, QDateTimeEdit, QItemDelegate,
) )
from Model.LateralContribution.LateralContributionTypes import (
NotDefined, LateralContrib, Rain, Evaporation,
)
from View.LateralContribution.Edit.UndoCommand import ( from View.LateralContributionsAdisTS.Edit.UndoCommand import (
SetDataCommand, AddCommand, DelCommand, SetDataCommand, AddCommand, DelCommand,
SortCommand, MoveCommand, PasteCommand,
DuplicateCommand,
) )
from View.LateralContribution.Edit.translate import * from View.LateralContributionsAdisTS.Edit.translate import *
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
@ -69,8 +64,8 @@ class TableModel(PamhyrTableModel):
value = QVariant() value = QVariant()
if 0 <= column < 2: if 0 <= column < 2:
v = self._data.get_i(row)[column] v = self._data._data[row][column]
if self._data.get_type_column(column) == float: if self._data._types[column] == float:
value = f"{v:.4f}" value = f"{v:.4f}"
elif self._data.header[column] == "time": elif self._data.header[column] == "time":
if self._opt_data == "time": if self._opt_data == "time":
@ -125,69 +120,3 @@ class TableModel(PamhyrTableModel):
self.endRemoveRows() self.endRemoveRows()
def sort(self, _reverse, parent=QModelIndex()):
self.layoutAboutToBeChanged.emit()
self._undo.push(
SortCommand(
self._data, _reverse
)
)
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()
def move_up(self, row, parent=QModelIndex()):
if row <= 0:
return
target = row + 2
self.beginMoveRows(parent, row - 1, row - 1, parent, target)
self._undo_stack.push(
MoveCommand(
self._data, "up", row
)
)
self.endMoveRows()
self.layoutChanged.emit()
def move_down(self, index, parent=QModelIndex()):
if row > len(self._data):
return
target = row
self.beginMoveRows(parent, row + 1, row + 1, parent, target)
self._undo_stack.push(
MoveCommand(
self._data, "down", row
)
)
self.endMoveRows()
self.layoutChanged.emit()
def paste(self, row, header, data):
if len(data) == 0:
return
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
)
)
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()

View File

@ -23,7 +23,7 @@ from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack, QMessageBox, QUndoCommand, QUndoStack,
) )
from Model.LateralContribution.LateralContribution import LateralContribution from Model.LateralContributionsAdisTS.LateralContributionAdisTS import LateralContributionAdisTS
class SetDataCommand(QUndoCommand): class SetDataCommand(QUndoCommand):
@ -33,15 +33,21 @@ 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.get_i(self._index)[self._column] self._old = self._data._data[self._index][self._column]
_type = self._data.get_type_column(self._column) _type = self._data._types[self._column]
self._new = _type(new_value) self._new = _type(new_value)
def undo(self): def undo(self):
self._data._set_i_c_v(self._index, self._column, self._old) if self._column == 0:
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):
self._data._set_i_c_v(self._index, self._column, self._new) if self._column == 0:
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):
@ -53,14 +59,13 @@ class AddCommand(QUndoCommand):
self._new = None self._new = None
def undo(self): def undo(self):
self._data.delete_i([self._index]) del self._data._data[self._index]
def redo(self): def redo(self):
if self._new is None: if self._new is None:
self._new = self._data.add(self._index) self._new = self._data._data.insert(self._index, (self._data._types[0](0), self._data._types[1](0.0)))
else: else:
self._data.insert(self._index, self._new) self._data._data.insert(self._index, self._new)
class DelCommand(QUndoCommand): class DelCommand(QUndoCommand):
def __init__(self, data, rows): def __init__(self, data, rows):
@ -71,98 +76,13 @@ class DelCommand(QUndoCommand):
self._lc = [] self._lc = []
for row in rows: for row in rows:
self._lc.append((row, self._data.get_i(row))) self._lc.append((row, self._data._data[row]))
self._lc.sort() self._lc.sort()
def undo(self): def undo(self):
for row, el in self._lc: for row, el in self._lc:
self._data.insert(row, el) self._data._data.insert(row, el)
def redo(self): def redo(self):
self._data.delete_i(self._rows) for row in self._rows:
del self._data._data[row]
class SortCommand(QUndoCommand):
def __init__(self, data, _reverse):
QUndoCommand.__init__(self)
self._data = data
self._reverse = _reverse
self._old = self._data.data
self._indexes = None
def undo(self):
ll = self._data.data
self._data.sort(
key=lambda x: self._indexes[ll.index(x)]
)
def redo(self):
self._data.sort(
_reverse=self._reverse,
key=lambda x: x[0]
)
if self._indexes is None:
self._indexes = list(
map(
lambda p: self._old.index(p),
self._data.data
)
)
self._old = None
class MoveCommand(QUndoCommand):
def __init__(self, data, up, i):
QUndoCommand.__init__(self)
self._data = data
self._up = up == "up"
self._i = i
def undo(self):
if self._up:
self._data.move_up(self._i)
else:
self._data.move_down(self._i)
def redo(self):
if self._up:
self._data.move_up(self._i)
else:
self._data.move_down(self._i)
class PasteCommand(QUndoCommand):
def __init__(self, data, row, lcs):
QUndoCommand.__init__(self)
self._data = data
self._row = row
self._lcs = lcs
self._lcs.reverse()
def undo(self):
self._data.delete(self._lcs)
def redo(self):
for bc in self._lcs:
self._data.insert(self._row, bc)
class DuplicateCommand(QUndoCommand):
def __init__(self, data, rows, bc):
QUndoCommand.__init__(self)
self._data = data
self._rows = rows
self._lc = deepcopy(bc)
self._lc.reverse()
def undo(self):
self._data.delete(self._lc)
def redo(self):
for bc in self._lcs:
self._data.insert(self._rows[0], bc)

View File

@ -39,16 +39,16 @@ from PyQt5.QtWidgets import (
from View.Tools.Plot.PamhyrCanvas import MplCanvas from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
from View.LateralContribution.Edit.translate import LCETranslate from View.LateralContributionsAdisTS.Edit.translate import LCETranslate
from View.LateralContribution.Edit.Table import TableModel from View.LateralContributionsAdisTS.Edit.Table import TableModel
from View.LateralContribution.Edit.Plot import Plot from View.LateralContributionsAdisTS.Edit.Plot import Plot
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class EditLateralContributionWindow(PamhyrWindow): class EditLateralContributionAdisTSWindow(PamhyrWindow):
_pamhyr_ui = "EditLateralContribution" _pamhyr_ui = "EditLateralContributionAdisTS"
_pamhyr_name = "Edit lateral contribution" _pamhyr_name = "Edit lateral contribution AdisTS"
def __init__(self, data=None, def __init__(self, data=None,
study=None, config=None, study=None, config=None,
@ -57,17 +57,8 @@ class EditLateralContributionWindow(PamhyrWindow):
trad = LCETranslate() trad = LCETranslate()
name = trad[self._pamhyr_name] name = trad[self._pamhyr_name]
if self._data is not None:
edge_name = (self._data.edge.name if self._data.edge is not None
else trad['not_associated'])
name += (
f" - {study.name} " +
f" - {self._data.name} ({self._data.id}) " +
f"({trad.get_dict('long_types')[self._data.lctype]} - " +
f"{edge_name})"
)
super(EditLateralContributionWindow, self).__init__( super(EditLateralContributionAdisTSWindow, self).__init__(
title=name, title=name,
study=study, study=study,
config=config, config=config,
@ -75,6 +66,17 @@ class EditLateralContributionWindow(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()
@ -134,7 +136,6 @@ class EditLateralContributionWindow(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_del").triggered.connect(self.delete) self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_sort").triggered.connect(self.sort)
self._table.dataChanged.connect(self.update) self._table.dataChanged.connect(self.update)
@ -176,46 +177,6 @@ class EditLateralContributionWindow(PamhyrWindow):
self._table.delete(rows) self._table.delete(rows)
self.plot.update() self.plot.update()
def sort(self):
self._table.sort(False)
self.plot.update()
def move_up(self):
row = self.index_selected_row()
self._table.move_up(row)
self.plot.update()
def move_down(self):
row = self.index_selected_row()
self._table.move_down(row)
self.plot.update()
def _copy(self):
rows = self.index_selected_rows()
table = []
table.append(self._data.header)
data = self._data.data
for row in rows:
table.append(list(data[row]))
self.copyTableIntoClipboard(table)
def _paste(self):
header, data = self.parseClipboardTable()
if len(data) == 0:
return
row = 0
rows = self.index_selected_rows()
if len(rows) != 0:
row = rows[0]
self._table.paste(row, header, data)
self.plot.update()
def _undo(self): def _undo(self):
self._table.undo() self._table.undo()
self.plot.update() self.plot.update()

View File

@ -19,7 +19,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Translate import MainTranslate from View.Translate import MainTranslate
from View.LateralContribution.translate import LCTranslate from View.LateralContributionsAdisTS.translate import LCTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
@ -27,15 +27,12 @@ _translate = QCoreApplication.translate
class LCETranslate(LCTranslate): class LCETranslate(LCTranslate):
def __init__(self): def __init__(self):
super(LCETranslate, self).__init__() super(LCETranslate, self).__init__()
self._dict["Edit lateral contribution"] = _translate( self._dict["Edit lateral contribution AdisTS"] = _translate(
"LateralContribution", "Edit lateral contribution" "LateralContributionAdisTS", "Edit lateral contribution AdisTS"
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"x": _translate("LateralContribution", "X"),
"y": _translate("LateralContribution", "Y"),
"time": self._dict["time"], "time": self._dict["time"],
"date": self._dict["date"], "date": self._dict["date"],
"discharge": self._dict["unit_discharge"], "rate": _translate("LateralContributionAdisTS", "Mass Flow"),
"z": self._dict["unit_elevation"],
} }

View File

@ -48,7 +48,7 @@ from View.Geometry.PlotXY import PlotXY
from View.LateralContributionsAdisTS.translate import ( from View.LateralContributionsAdisTS.translate import (
LCTranslate, LCTranslate,
) )
from View.LateralContributionsAdisTS.Edit.Window import EditLateralContributionWindow from View.LateralContributionsAdisTS.Edit.Window import EditLateralContributionAdisTSWindow
logger = logging.getLogger() logger = logging.getLogger()
@ -136,7 +136,6 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete) self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_edit").triggered.connect(self.edit) self.find(QAction, "action_edit").triggered.connect(self.edit)
self.find(QAction, "action_sort").triggered.connect(self.sort)
table = self.find(QTableView, f"tableView") table = self.find(QTableView, f"tableView")
table.selectionModel()\ table.selectionModel()\
@ -233,18 +232,17 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
self._set_current_reach() self._set_current_reach()
def edit(self): def edit(self):
tab = self.current_tab()
rows = self.index_selected_rows() rows = self.index_selected_rows()
for row in rows: for row in rows:
data = self._lcs.get(tab, row) data = self._lcs.lst[row]
if self.sub_window_exists( if self.sub_window_exists(
EditLateralContributionWindow, EditLateralContributionAdisTSWindow,
data=[self._study, None, data] data=[self._study, None, data]
): ):
continue continue
win = EditLateralContributionWindow( win = EditLateralContributionAdisTSWindow(
data=data, data=data,
study=self._study, study=self._study,
parent=self parent=self

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>450</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="locale">
<locale language="English" country="Europe"/>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTableView" name="tableView"/>
<widget class="QWidget" name="verticalLayoutWidget">
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_add"/>
<addaction name="action_del"/>
</widget>
<action name="action_add">
<property name="checkable">
<bool>false</bool>
</property>
<property name="icon">
<iconset>
<normaloff>ressources/add.png</normaloff>ressources/add.png</iconset>
</property>
<property name="text">
<string>Add</string>
</property>
<property name="toolTip">
<string>Add a new point in boundary condition or lateral contribution</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="action_del">
<property name="icon">
<iconset>
<normaloff>ressources/del.png</normaloff>ressources/del.png</iconset>
</property>
<property name="text">
<string>Delete</string>
</property>
<property name="toolTip">
<string>Delete current selected rows</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -69,7 +69,6 @@
<addaction name="action_add"/> <addaction name="action_add"/>
<addaction name="action_del"/> <addaction name="action_del"/>
<addaction name="action_edit"/> <addaction name="action_edit"/>
<addaction name="action_sort"/>
</widget> </widget>
<action name="action_add"> <action name="action_add">
<property name="checkable"> <property name="checkable">
@ -119,18 +118,6 @@
<string>Ctrl+E</string> <string>Ctrl+E</string>
</property> </property>
</action> </action>
<action name="action_sort">
<property name="icon">
<iconset>
<normaloff>ressources/sort_A-Z.png</normaloff>ressources/sort_A-Z.png</iconset>
</property>
<property name="text">
<string>Sort</string>
</property>
<property name="toolTip">
<string>Sort boundary condition by name</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>