mirror of https://gitlab.com/pamhyr/pamhyr2
SL: Edit: Add Plot.
parent
043d8d839a
commit
181776f33f
|
|
@ -143,6 +143,15 @@ class SedimentLayer(SQLSubModel):
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._layers)
|
return len(self._layers)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def layers(self):
|
||||||
|
return self._layers.copy()
|
||||||
|
|
||||||
|
def height(self):
|
||||||
|
return list(
|
||||||
|
map(lambda l: l.height, self._layers)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
@ -151,6 +160,11 @@ class SedimentLayer(SQLSubModel):
|
||||||
def name(self, name):
|
def name(self, name):
|
||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
|
def names(self):
|
||||||
|
return list(
|
||||||
|
map(lambda l: l.name, self._layers)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def comment(self):
|
def comment(self):
|
||||||
return self._comment
|
return self._comment
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
from tools import timer
|
||||||
|
from View.Plot.APlot import APlot
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QCoreApplication
|
||||||
|
)
|
||||||
|
|
||||||
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class Plot(APlot):
|
||||||
|
def __init__(self, canvas=None, data=None, toolbar=None,
|
||||||
|
display_current=True):
|
||||||
|
super(Plot, self).__init__(
|
||||||
|
canvas=canvas,
|
||||||
|
data=data,
|
||||||
|
toolbar=toolbar
|
||||||
|
)
|
||||||
|
|
||||||
|
self._display_current = display_current
|
||||||
|
|
||||||
|
self.line_kp_zmin = None
|
||||||
|
self.line_kp_sl = []
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def draw(self):
|
||||||
|
self.canvas.axes.cla()
|
||||||
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlabel(
|
||||||
|
_translate("MainWindow_reach", "X (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
self.canvas.axes.set_ylabel(
|
||||||
|
_translate("MainWindow_reach", "Height (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
|
||||||
|
x = [0,1]
|
||||||
|
z = [0,0]
|
||||||
|
sl = self.data.height()
|
||||||
|
names = ["fond"] + self.data.names()
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlim(
|
||||||
|
left = min(x), right = max(x)
|
||||||
|
)
|
||||||
|
|
||||||
|
lsl = []
|
||||||
|
for i in range(len(sl)):
|
||||||
|
cur = []
|
||||||
|
for _ in x:
|
||||||
|
cur.append(sl[i])
|
||||||
|
lsl.append(cur)
|
||||||
|
|
||||||
|
# Compute sediment layer in function to point z
|
||||||
|
z_sl = reduce(
|
||||||
|
lambda acc, v: acc + [
|
||||||
|
list(
|
||||||
|
map(lambda x, y: y - x, v, acc[-1])
|
||||||
|
)
|
||||||
|
],
|
||||||
|
lsl,
|
||||||
|
[z]
|
||||||
|
)
|
||||||
|
|
||||||
|
for i, zsl in enumerate(z_sl):
|
||||||
|
self.line_kp_sl.append(None)
|
||||||
|
self.line_kp_sl[i], = self.canvas.axes.plot(
|
||||||
|
x, zsl,
|
||||||
|
label=names[i],
|
||||||
|
linestyle="solid" if i == 0 else "--",
|
||||||
|
lw=1.8,
|
||||||
|
color='grey' if i == 0 else None
|
||||||
|
)
|
||||||
|
self.canvas.axes.text(x[0] + 0.01, zsl[0] + 0.01, f'{names[i]}')
|
||||||
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
if self.toolbar is not None:
|
||||||
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = True
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
|
if ind is None:
|
||||||
|
logger.info("TODO: Update")
|
||||||
|
|
||||||
|
self.canvas.axes.autoscale_view(True, True, True)
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
@ -28,6 +28,7 @@ from View.Plot.MplCanvas import MplCanvas
|
||||||
|
|
||||||
from View.SedimentLayers.Edit.UndoCommand import *
|
from View.SedimentLayers.Edit.UndoCommand import *
|
||||||
from View.SedimentLayers.Edit.Table import *
|
from View.SedimentLayers.Edit.Table import *
|
||||||
|
from View.SedimentLayers.Edit.Plot import Plot
|
||||||
from View.SedimentLayers.Edit.translate import *
|
from View.SedimentLayers.Edit.translate import *
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
@ -91,13 +92,13 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
|
self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
|
||||||
self.plot_layout.addWidget(self.canvas)
|
self.plot_layout.addWidget(self.canvas)
|
||||||
|
|
||||||
# self.plot = PlotKPC(
|
self.plot = Plot(
|
||||||
# canvas = self.canvas,
|
canvas = self.canvas,
|
||||||
# data = self._reach.reach,
|
data = self._sl,
|
||||||
# toolbar = None,
|
toolbar = None,
|
||||||
# display_current = False
|
display_current = False
|
||||||
# )
|
)
|
||||||
# self.plot.draw()
|
self.plot.draw()
|
||||||
|
|
||||||
|
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue