mirror of https://gitlab.com/pamhyr/pamhyr2
IC: Add growing constant draft generator.
parent
240367fed1
commit
a836b78c22
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
from functools import reduce
|
||||
|
||||
class Data(object):
|
||||
def __init__(self, reach = None, status = None):
|
||||
|
|
@ -117,6 +118,10 @@ class InitialConditions(object):
|
|||
def data(self):
|
||||
return self._data.copy()
|
||||
|
||||
@data.setter
|
||||
def data(self, data):
|
||||
self._data = data
|
||||
|
||||
def get(self, index):
|
||||
return self._data[index]
|
||||
|
||||
|
|
@ -175,3 +180,40 @@ class InitialConditions(object):
|
|||
|
||||
def get_flow(self):
|
||||
return self._data_get("flow")
|
||||
|
||||
def _sort_by_z_and_kp(self, profiles):
|
||||
profiles.sort(
|
||||
reverse = False,
|
||||
key = lambda p: p.kp
|
||||
)
|
||||
|
||||
first_z = profiles[0].z()
|
||||
last_z = profiles[-1].z()
|
||||
|
||||
if first_z > last_z:
|
||||
profiles.sort(
|
||||
reverse = True,
|
||||
key = lambda p: p.kp
|
||||
)
|
||||
|
||||
def generate_growing_constante_draft(self, draft:int):
|
||||
self._data = []
|
||||
|
||||
profiles = self._reach.reach.profiles
|
||||
self._sort_by_z_and_kp(profiles)
|
||||
|
||||
prev = None
|
||||
for profile in profiles:
|
||||
new = Data(reach = self._reach, status = self._status)
|
||||
new["kp"] = profile.kp
|
||||
|
||||
if prev is None:
|
||||
new["elevation"] = profile.z_min() + draft
|
||||
else:
|
||||
new["elevation"] = max(
|
||||
profile.z_min() + draft,
|
||||
prev["elevation"]
|
||||
)
|
||||
|
||||
self._data.append(new)
|
||||
prev = new
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@ class PlotDKP(APlot):
|
|||
if self.data is None:
|
||||
return
|
||||
|
||||
if len(self.data) == 0:
|
||||
return
|
||||
|
||||
self.canvas.axes.set_ylabel(
|
||||
_translate("MainWindow_reach", "Draft (m)"),
|
||||
color='green', fontsize=11
|
||||
|
|
@ -49,13 +46,14 @@ class PlotDKP(APlot):
|
|||
color='grey', lw=1.
|
||||
)
|
||||
|
||||
kp = self.data.get_kp()
|
||||
elevation = self.data.get_elevation()
|
||||
if len(self.data) != 0:
|
||||
kp = self.data.get_kp()
|
||||
elevation = self.data.get_elevation()
|
||||
|
||||
self.line_kp_elevation = self.canvas.axes.plot(
|
||||
kp, elevation,
|
||||
color='b', marker='+', lw=1.
|
||||
)
|
||||
self.line_kp_elevation = self.canvas.axes.plot(
|
||||
kp, elevation,
|
||||
color='b', marker='+', lw=1.
|
||||
)
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@ class PlotFlow(APlot):
|
|||
if self.data is None:
|
||||
return
|
||||
|
||||
if len(self.data) == 0:
|
||||
return
|
||||
|
||||
self.canvas.axes.set_ylabel(
|
||||
_translate("MainWindow_reach", "Flow (m^3/s)"),
|
||||
color='green', fontsize=11
|
||||
|
|
@ -43,13 +40,14 @@ class PlotFlow(APlot):
|
|||
left = min(kp), right = max(kp)
|
||||
)
|
||||
|
||||
kp = self.data.get_kp()
|
||||
flow = self.data.get_flow()
|
||||
if len(self.data) != 0:
|
||||
kp = self.data.get_kp()
|
||||
flow = self.data.get_flow()
|
||||
|
||||
self.line_kp_zmin = self.canvas.axes.plot(
|
||||
kp, flow,
|
||||
color='r', lw=1.
|
||||
)
|
||||
self.line_kp_zmin = self.canvas.axes.plot(
|
||||
kp, flow,
|
||||
color='r', lw=1.
|
||||
)
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from PyQt5.QtWidgets import (
|
|||
from View.InitialConditions.UndoCommand import (
|
||||
SetCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, PasteCommand,
|
||||
DuplicateCommand,
|
||||
DuplicateCommand, GenerateCommand,
|
||||
)
|
||||
|
||||
from View.InitialConditions.translate import *
|
||||
|
|
@ -173,7 +173,7 @@ class TableModel(QAbstractTableModel):
|
|||
|
||||
self.beginMoveRows(parent, row - 1, row - 1, parent, target)
|
||||
|
||||
self._undo_stack.push(
|
||||
self._undo.push(
|
||||
MoveCommand(
|
||||
self._ics, "up", row
|
||||
)
|
||||
|
|
@ -190,7 +190,7 @@ class TableModel(QAbstractTableModel):
|
|||
|
||||
self.beginMoveRows(parent, row + 1, row + 1, parent, target)
|
||||
|
||||
self._undo_stack.push(
|
||||
self._undo.push(
|
||||
MoveCommand(
|
||||
self._ics, "down", row
|
||||
)
|
||||
|
|
@ -206,3 +206,11 @@ class TableModel(QAbstractTableModel):
|
|||
def redo(self):
|
||||
self._undo.redo()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def generate(self, generator, param):
|
||||
self._undo.push(
|
||||
GenerateCommand(
|
||||
self._ics, generator, param
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
|
|
@ -146,3 +146,19 @@ class DuplicateCommand(QUndoCommand):
|
|||
def redo(self):
|
||||
for ic in self._ics:
|
||||
self._ics.insert(self._rows[0], ic)
|
||||
|
||||
class GenerateCommand(QUndoCommand):
|
||||
def __init__(self, ics, generator, param):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._param = param
|
||||
self._copy = self._ics.data
|
||||
self._generator = generator
|
||||
|
||||
def undo(self):
|
||||
self._ics.data = self._copy
|
||||
|
||||
def redo(self):
|
||||
#if self._generator == "growing":
|
||||
self._ics.generate_growing_constante_draft(self._param)
|
||||
|
|
|
|||
|
|
@ -126,6 +126,10 @@ class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
|
|||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
||||
|
||||
self.find(QPushButton, "pushButton_generate_1").clicked.connect(
|
||||
self.generate_growing_constante_draft
|
||||
)
|
||||
|
||||
self.undo_sc.activated.connect(self.undo)
|
||||
self.redo_sc.activated.connect(self.redo)
|
||||
self.copy_sc.activated.connect(self.copy)
|
||||
|
|
@ -201,3 +205,7 @@ class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
|
|||
def redo(self):
|
||||
self._table.redo()
|
||||
self._update_plot()
|
||||
|
||||
def generate_growing_constante_draft(self):
|
||||
self._table.generate("growing", 1)
|
||||
self._update_plot()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@ from matplotlib.figure import Figure
|
|||
|
||||
class MplCanvas(FigureCanvasQTAgg):
|
||||
def __init__(self, width=5, height=4, dpi=100):
|
||||
fig = Figure(figsize=(width, height), dpi=dpi)
|
||||
fig = Figure(
|
||||
figsize=(width, height),
|
||||
dpi=dpi,
|
||||
layout='tight',
|
||||
)
|
||||
super(MplCanvas, self).__init__(fig)
|
||||
|
||||
self.axes = fig.add_subplot(111)
|
||||
|
|
|
|||
Loading…
Reference in New Issue