mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Put graphic 1 into PlotXY classes.
parent
c235bbebda
commit
e7b6e66890
|
|
@ -17,12 +17,12 @@ from PyQt5.QtWidgets import (
|
|||
QApplication, QMainWindow, QFileDialog, QCheckBox
|
||||
)
|
||||
|
||||
from View.Geometry.reach_plot_xy import PlotXY
|
||||
from View.Geometry.mainwindow_ui_reach import Ui_MainWindow
|
||||
from View.Geometry import qtableview_reach
|
||||
from View.Geometry import window_profileXYZ
|
||||
from View.ASubWindow import WindowToolKit
|
||||
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class GeometryWindow(QMainWindow, WindowToolKit):
|
||||
|
|
@ -125,8 +125,6 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
self.graphic_2()
|
||||
self.graphic_3()
|
||||
|
||||
|
||||
|
||||
def messagebox_profile_editing(self):
|
||||
msg_box = QtWidgets.QMessageBox()
|
||||
msg_box.setIcon(QtWidgets.QMessageBox.Information)
|
||||
|
|
@ -222,70 +220,13 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
self.list_second_window = []
|
||||
self.list_row = []
|
||||
|
||||
@timer
|
||||
def graphic_1(self):
|
||||
self.ui.canvas_1.axes.cla()
|
||||
self.ui.canvas_1.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
|
||||
# Axes
|
||||
self.ui.canvas_1.axes.set_xlabel(
|
||||
_translate("MainWindow_reach", "X (m)"), color='green', fontsize=12
|
||||
self.plot_xy = PlotXY(
|
||||
canvas = self.ui.canvas_1,
|
||||
data = self._reach,
|
||||
toolbar = self.ui.toolbar_1
|
||||
)
|
||||
self.ui.canvas_1.axes.set_ylabel(
|
||||
_translate("MainWindow_reach", "Y (m)"), color='green', fontsize=12
|
||||
)
|
||||
|
||||
# Draw line for each profile
|
||||
self.line_xy = [
|
||||
self.ui.canvas_1.axes.plot(
|
||||
x, y,
|
||||
color='r', lw=1.,
|
||||
markersize=3, marker='+'
|
||||
)
|
||||
for x, y in zip(self._reach.get_x(), self._reach.get_y())
|
||||
]
|
||||
|
||||
# Guide lines
|
||||
self.x_complete = self._reach.get_guidelines_x()
|
||||
self.y_complete = self._reach.get_guidelines_y()
|
||||
|
||||
self.line_gl_1 = [
|
||||
self.ui.canvas_1.axes.plot(
|
||||
x, y,
|
||||
)
|
||||
for x, y in zip(self.x_complete, self.y_complete)
|
||||
]
|
||||
|
||||
# Current profile
|
||||
self.plot_selected_1, = self.ui.canvas_1.axes.plot(
|
||||
self._reach.profile(0).x(),
|
||||
self._reach.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="b"
|
||||
)
|
||||
self.plot_selected_1.set_visible(False)
|
||||
|
||||
# Previous profile
|
||||
self.before_plot_selected_1, = self.ui.canvas_1.axes.plot(
|
||||
self._reach.profile(0).x(),
|
||||
self._reach.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="k", linestyle="--"
|
||||
)
|
||||
self.before_plot_selected_1.set_visible(False)
|
||||
|
||||
# Next profile
|
||||
self.after_plot_selected_1, = self.ui.canvas_1.axes.plot(
|
||||
self._reach.profile(0).x(),
|
||||
self._reach.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="m", linestyle='--'
|
||||
)
|
||||
self.after_plot_selected_1.set_visible(False)
|
||||
|
||||
self.ui.canvas_1.figure.tight_layout()
|
||||
self.ui.canvas_1.figure.canvas.draw_idle()
|
||||
self.ui.toolbar_1.update()
|
||||
self.plot_xy.draw()
|
||||
|
||||
@timer
|
||||
def graphic_2(self):
|
||||
|
|
@ -356,27 +297,12 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
self.ui.canvas_2.figure.canvas.draw_idle()
|
||||
self.ui.toolbar_2.update()
|
||||
|
||||
@timer
|
||||
def update_graphic_1(self):
|
||||
self.tableView.model().blockSignals(True)
|
||||
|
||||
for ind in range(self._tablemodel.rowCount()):
|
||||
self.line_xy[ind][0].set_data(
|
||||
self._reach.profile(ind).x(),
|
||||
self._reach.profile(ind).y()
|
||||
)
|
||||
|
||||
self.x_complete = self._reach.get_guidelines_x()
|
||||
self.y_complete = self._reach.get_guidelines_y()
|
||||
|
||||
for i in range(len(self.line_gl_1)):
|
||||
self.line_gl_1[i].set_data(
|
||||
[x[i] for x in self.x_complete],
|
||||
[y[i] for y in self.y_complete]
|
||||
)
|
||||
self.plot_xy.update()
|
||||
|
||||
self.tableView.model().blockSignals(False)
|
||||
self.ui.canvas_1.figure.canvas.draw_idle()
|
||||
|
||||
@timer
|
||||
def update_graphic_2(self):
|
||||
|
|
@ -456,7 +382,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
lcomplete = list(self.complete_gl)
|
||||
lincomplete = list(self.incomplete_gl)
|
||||
|
||||
line_2d = [line_2D for line_2D in self.line_gl_1]
|
||||
line_2d = [line_2D for line_2D in self.plot_xy.line_gl]
|
||||
self.color_complete_gl = self.get_line_gl_colors(line_2d)
|
||||
self.color_incomplete_gl = 2 * ["#000000"]
|
||||
|
||||
|
|
@ -621,10 +547,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
def select_plot_graphic_1(self, ind: int):
|
||||
self.tableView.model().blockSignals(True)
|
||||
|
||||
if 0 <= ind < self._tablemodel.rowCount():
|
||||
self.plot_selected_1.set_data(self._reach.profile(ind).x(),
|
||||
self._reach.profile(ind).y())
|
||||
self.plot_selected_1.set_visible(True)
|
||||
self.plot_xy.update(ind=ind)
|
||||
|
||||
self.tableView.model().blockSignals(False)
|
||||
|
||||
|
|
@ -638,26 +561,6 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
(z_min_i, z_max_i))
|
||||
self.plot_selected_2.set_visible(True)
|
||||
|
||||
def select_before_plot_selected_1(self, ind: int):
|
||||
if 0 <= ind < self._tablemodel.rowCount():
|
||||
self.before_plot_selected_1.set_data(
|
||||
self._reach.profile(ind).x(),
|
||||
self._reach.profile(ind).y()
|
||||
)
|
||||
|
||||
self.before_plot_selected_1.set_visible(True)
|
||||
self.ui.canvas_1.figure.canvas.draw_idle()
|
||||
|
||||
def select_after_plot_selected_1(self, ind: int):
|
||||
if 0 <= ind < self._tablemodel.rowCount():
|
||||
self.after_plot_selected_1.set_data(
|
||||
self._reach.profile(ind).x(),
|
||||
self._reach.profile(ind).y()
|
||||
)
|
||||
|
||||
self.after_plot_selected_1.set_visible(True)
|
||||
self.ui.canvas_1.figure.canvas.draw_idle()
|
||||
|
||||
def select_before_plot_selected_2(self, ind: int):
|
||||
if 0 <= ind < self._tablemodel.rowCount():
|
||||
kp_i = self._reach.profile(ind).kp
|
||||
|
|
@ -710,25 +613,20 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
self.select_plot_graphic_1(row)
|
||||
self.select_plot_graphic_2(row)
|
||||
|
||||
self.plot_xy.update(ind = row)
|
||||
|
||||
if row == 0:
|
||||
self.before_plot_selected_1.set_visible(False)
|
||||
self.select_after_plot_selected_1(row + 1)
|
||||
self.before_plot_selected_2.set_visible(False)
|
||||
self.select_after_plot_selected_2(row + 1)
|
||||
elif 0 < row < self._tablemodel.rowCount() - 1:
|
||||
self.select_before_plot_selected_1(row - 1)
|
||||
self.select_after_plot_selected_1(row + 1)
|
||||
self.select_before_plot_selected_2(row - 1)
|
||||
self.select_after_plot_selected_2(row + 1)
|
||||
elif row == self._tablemodel.rowCount() - 1:
|
||||
self.after_plot_selected_1.set_visible(False)
|
||||
self.select_before_plot_selected_1(row - 1)
|
||||
self.after_plot_selected_2.set_visible(False)
|
||||
self.select_before_plot_selected_2(row - 1)
|
||||
|
||||
self.tableView.model().blockSignals(False)
|
||||
self.update_graphic_3(row)
|
||||
self.ui.canvas_1.figure.canvas.draw_idle()
|
||||
self.ui.canvas_2.figure.canvas.draw_idle()
|
||||
|
||||
def changed_slider_value(self):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,137 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import timer
|
||||
from View.Plot.APlot import APlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
)
|
||||
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class PlotXY(APlot):
|
||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
||||
super(PlotXY, self).__init__(
|
||||
canvas=canvas,
|
||||
data=data,
|
||||
toolbar=toolbar
|
||||
)
|
||||
|
||||
self.line_xy = []
|
||||
self.line_gl = []
|
||||
|
||||
self.before_plot_selected = None
|
||||
self.plot_selected = None
|
||||
self.after_plot_selected = None
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.canvas.axes.cla()
|
||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
|
||||
# Axes
|
||||
self.canvas.axes.set_xlabel(
|
||||
_translate("MainWindow_reach", "X (m)"),
|
||||
color='green', fontsize=12
|
||||
)
|
||||
self.canvas.axes.set_ylabel(
|
||||
_translate("MainWindow_reach", "Y (m)"),
|
||||
color='green', fontsize=12
|
||||
)
|
||||
|
||||
# Draw line for each profile
|
||||
self.line_xy = [
|
||||
self.canvas.axes.plot(
|
||||
x, y,
|
||||
color='r', lw=1.,
|
||||
markersize=3, marker='+'
|
||||
)
|
||||
for x, y in zip(self.data.get_x(), self.data.get_y())
|
||||
]
|
||||
|
||||
# Guide lines
|
||||
x_complete = self.data.get_guidelines_x()
|
||||
y_complete = self.data.get_guidelines_y()
|
||||
|
||||
self.line_gl = [
|
||||
self.canvas.axes.plot(
|
||||
x, y,
|
||||
)
|
||||
for x, y in zip(x_complete, y_complete)
|
||||
]
|
||||
|
||||
# Previous profile
|
||||
self.before_plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="k", linestyle="--"
|
||||
)
|
||||
self.before_plot_selected.set_visible(False)
|
||||
|
||||
# Current profile
|
||||
self.plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="b"
|
||||
)
|
||||
self.plot_selected.set_visible(False)
|
||||
|
||||
# Next profile
|
||||
self.after_plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="m", linestyle='--'
|
||||
)
|
||||
self.after_plot_selected.set_visible(False)
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
self.toolbar.update()
|
||||
|
||||
@timer
|
||||
def update(self, ind=None):
|
||||
if ind:
|
||||
before = ind - 1
|
||||
after = ind + 1
|
||||
|
||||
self.before_plot_selected.set_visible(False)
|
||||
self.plot_selected.set_visible(False)
|
||||
self.after_plot_selected.set_visible(False)
|
||||
|
||||
if 0 <= before < self.data.number_profiles:
|
||||
self.before_plot_selected.set_data(self.data.profile(before).x(),
|
||||
self.data.profile(before).y())
|
||||
self.before_plot_selected.set_visible(True)
|
||||
|
||||
if 0 <= ind < self.data.number_profiles:
|
||||
self.plot_selected.set_data(self.data.profile(ind).x(),
|
||||
self.data.profile(ind).y())
|
||||
self.plot_selected.set_visible(True)
|
||||
|
||||
if 0 <= after < self.data.number_profiles:
|
||||
self.after_plot_selected.set_data(self.data.profile(after).x(),
|
||||
self.data.profile(after).y())
|
||||
self.after_plot_selected.set_visible(True)
|
||||
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
else:
|
||||
for ind in range(self.data.number_profiles):
|
||||
self.line_xy[ind][0].set_data(
|
||||
self.data.profile(ind).x(),
|
||||
self.data.profile(ind).y()
|
||||
)
|
||||
|
||||
x_complete = self.data.get_guidelines_x()
|
||||
y_complete = self.data.get_guidelines_y()
|
||||
|
||||
for i in range(len(self.line_gl)):
|
||||
self.line_gl[i].set_data(
|
||||
[x[i] for x in x_complete],
|
||||
[y[i] for y in y_complete]
|
||||
)
|
||||
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
class APlot(object):
|
||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
||||
super(APlot, self).__init__()
|
||||
|
||||
self._canvas = canvas
|
||||
self._data = data
|
||||
self._toolbar = toolbar
|
||||
|
||||
@property
|
||||
def canvas(self):
|
||||
return self._canvas
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def toolbar(self):
|
||||
return self._toolbar
|
||||
|
||||
def draw(self):
|
||||
"""Draw plot
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
raise NotImplementedMethodeError(self, self.draw)
|
||||
|
||||
|
||||
def update(self, ind = None):
|
||||
"""Update plot
|
||||
|
||||
Update the plot, update for data index IND if define, else
|
||||
update all the plot
|
||||
|
||||
Args:
|
||||
ind: Data index to update
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
raise NotImplementedMethodeError(self, self.update)
|
||||
|
|
@ -30,7 +30,7 @@ def display_timers():
|
|||
lambda f: (f, _timers[f], _calls[f]),
|
||||
_timers
|
||||
),
|
||||
key=lambda f: f[1],
|
||||
key = lambda f: f[1],
|
||||
reverse = True
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue