Commit 76e6c6c3 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

geometry: Put graphic 3 into PlotAC class.

Showing with 336 additions and 208 deletions
+336 -208
......@@ -19,6 +19,8 @@ from PyQt5.QtWidgets import (
from View.Geometry.PlotXY import PlotXY
from View.Geometry.PlotKPC import PlotKPC
from View.Geometry.PlotAC import PlotAC
from View.Geometry.mainwindow_ui_reach import Ui_MainWindow
from View.Geometry import qtableview_reach
from View.Geometry import window_profileXYZ
......@@ -233,6 +235,11 @@ class GeometryWindow(QMainWindow, WindowToolKit):
self.tableView.model().blockSignals(False)
def update_graphic_1(self):
self.tableView.model().blockSignals(True)
self.plot_xy.update()
self.tableView.model().blockSignals(False)
def graphic_2(self):
self.tableView.model().blockSignals(True)
......@@ -247,186 +254,26 @@ class GeometryWindow(QMainWindow, WindowToolKit):
def update_graphic_2(self):
self.tableView.model().blockSignals(True)
self.plot_kpc.update()
self.tableView.model().blockSignals(False)
def update_graphic_1(self):
self.tableView.model().blockSignals(True)
self.plot_xy.update()
self.tableView.model().blockSignals(False)
@timer
def graphic_3(self):
self.tableView.model().blockSignals(True)
selected_profile = 0
station = self._reach.profile(selected_profile).get_station()
station_plus_1 = self._reach.profile(selected_profile + 1).get_station()
elevation = self._reach.profile(selected_profile).z()
elevation_i_plus_1 = self._reach.profile(selected_profile + 1).z()
gl = self._reach.profile(selected_profile).names()
self.ui.canvas_3.axes.cla()
self.ui.canvas_3.axes.grid(color='grey', linestyle='--', linewidth=0.5)
self.ui.canvas_3.axes.set_xlabel(
_translate("MainWindow_reach", "Abscisse en travers (m)"),
color='green', fontsize=12
)
self.ui.canvas_3.axes.set_ylabel(
_translate("MainWindow_reach", "Cote (m)"),
color='green', fontsize=12
)
self.ui.canvas_3.figure.tight_layout()
label_profile_i_minus_1 = _translate("MainWindow_reach", "Profil précédent")
label_profile_i = _translate("MainWindow_reach", "Profil sélectionné")
label_profile_i_plus_1 = _translate("MainWindow_reach", "Profil suivant")
color_profile_i_minus_1 = "k" # 'grey'
color_profile_i = 'b'
color_profile_i_plus_1 = 'm'
self.profile_i_minus_1, = self.ui.canvas_3.axes.plot(
[], [], label=label_profile_i_minus_1, lw=1.8,
linestyle='--', color=color_profile_i_minus_1
)
self.profile_i, = self.ui.canvas_3.axes.plot(
station, elevation, label=label_profile_i,
color=color_profile_i, lw=1.8
)
self.profile_i_plus_1, = self.ui.canvas_3.axes.plot(
station_plus_1, elevation_i_plus_1,
label=label_profile_i_plus_1,
color=color_profile_i_plus_1, lw=1.6, linestyle='--'
self.plot_ac = PlotAC(
canvas = self.ui.canvas_3,
data = self._reach,
toolbar = self.ui.toolbar_3,
plot_xy = self.plot_xy
)
self.annotation_3 = []
self.complete_gl, self.incomplete_gl = self._reach.compute_guidelines()
lcomplete = list(self.complete_gl)
lincomplete = list(self.incomplete_gl)
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"]
x_gl_complete = []
y_gl_complete = []
color_scat_complete_gl = []
x_gl_incomplete = []
y_gl_incomplete = []
color_scat_incomplete_gl = []
for i, txt in enumerate(gl):
if txt.strip() in self.complete_gl:
annotation_3 = self.ui.canvas_3.axes.annotate(
txt, (station[i], elevation[i]),
horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_complete_gl[
lcomplete.index(txt)
]
)
annotation_3.set_position((station[i] + 0., elevation[i] + 0.))
self.annotation_3.append(annotation_3)
x_gl_complete.append(station[i])
y_gl_complete.append(elevation[i])
color_scat_complete_gl.append(self.color_complete_gl[lcomplete.index(txt)])
elif txt.strip() in self.incomplete_gl:
annotate = self.ui.canvas_3.axes.annotate(
txt, (station[i], elevation[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True, fontsize=11,
color=self.color_incomplete_gl[
lincomplete.index(txt)
],
)
self.annotation_3.append(annotate)
x_gl_incomplete.append(station[i])
y_gl_incomplete.append(elevation[i])
color_scat_incomplete_gl.append(
self.color_incomplete_gl[lincomplete.index(txt)]
)
self.plot_ac.draw()
self.tableView.model().blockSignals(False)
self.ui.canvas_3.axes.legend(fancybox=True, shadow=True, fontsize=8)
self.ui.canvas_3.figure.tight_layout()
self.ui.canvas_3.figure.canvas.draw_idle()
self.ui.toolbar_3.update()
@timer
def update_annotate_3(self, ind: int):
def update_graphic_3(self, ind: int):
self.tableView.model().blockSignals(True)
for a in self.annotation_3:
a.remove()
self.annotation_3[:] = []
x = self._reach.profile(ind).get_station()
y = self._reach.profile(ind).z()
gl = self._reach.profile(ind).names()
complete, incomplete = self._reach.compute_guidelines()
lcomplete = list(complete)
lincomplete = list(incomplete)
self.x_complete = []
color_scat_complete = []
self.x_incomplete = []
color_scat_incomplete = []
try:
for i, txt in enumerate(gl):
if txt in complete:
annotate = self.ui.canvas_3.axes.annotate(
txt, (x[i], y[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_complete_gl[
lcomplete.index(txt)
],
)
self.annotation_3.append(annotate)
self.x_complete.append([x[i], y[i]])
color_scat_complete.append(
self.color_complete_gl[lcomplete.index(txt)]
)
elif txt in incomplete:
annotate = self.ui.canvas_3.axes.annotate(
txt, (x[i], y[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_incomplete_gl[
lincomplete.index(txt)
],
)
self.annotation_3.append(annotate)
self.x_incomplete.append([x[i], y[i]])
color_scat_incomplete.append(
self.color_incomplete_gl[lincomplete.index(txt)]
)
except Exception as e:
print(f"{e}")
self.plot_ac.update(ind=ind)
self.tableView.model().blockSignals(False)
self.ui.canvas_3.figure.canvas.draw_idle()
def get_line_gl_colors(self, line_2d):
colors = []
for line in line_2d:
colors.append(line[0].get_color())
return colors
def get_station(self, ind: int):
return self._reach.profile(ind).get_station()
......@@ -434,54 +281,14 @@ class GeometryWindow(QMainWindow, WindowToolKit):
def get_elevation(self, ind: int):
return self._reach.profile(ind).z()
@timer
def update_graphic_3(self, ind: int):
self.tableView.model().blockSignals(True)
# ind - 1
if ind != 0:
self.profile_i_minus_1.set_data(
self.get_station(ind - 1),
self.get_elevation(ind - 1)
)
else:
self.profile_i_minus_1.set_data([], [])
# ind
self.profile_i.set_data(
self.get_station(ind),
self.get_elevation(ind)
)
# ind + 1
if ind != self._tablemodel.rowCount() - 1:
self.profile_i_plus_1.set_data(
self.get_station(ind + 1),
self.get_elevation(ind + 1)
)
else:
self.profile_i_plus_1.set_data([], [])
self.tableView.model().blockSignals(False)
# Update graphic 3
self.update_annotate_3(ind)
self.ui.canvas_3.axes.relim()
self.ui.canvas_3.axes.autoscale_view()
self.ui.canvas_3.figure.canvas.draw_idle()
def select_plot_graphic_1(self, ind: int):
self.tableView.model().blockSignals(True)
self.plot_xy.update(ind=ind)
self.tableView.model().blockSignals(False)
def select_plot_graphic_2(self, ind: int):
self.tableView.model().blockSignals(True)
self.plot_kpc.update(ind=ind)
self.tableView.model().blockSignals(False)
......
# -*- coding: utf-8 -*-
from tools import timer
from View.Plot.APlot import APlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotAC(APlot):
def __init__(self, canvas=None, data=None, toolbar=None, plot_xy=None):
super(PlotAC, self).__init__(
canvas=canvas,
data=data,
toolbar=toolbar
)
self.plot_xy = plot_xy
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
def get_line_gl_colors(self, line_2d):
colors = []
for line in line_2d:
colors.append(line[0].get_color())
return colors
@timer
def draw(self):
selected_profile = 0
station = self.data.profile(selected_profile).get_station()
station_plus_1 = self.data.profile(selected_profile + 1).get_station()
elevation = self.data.profile(selected_profile).z()
elevation_i_plus_1 = self.data.profile(selected_profile + 1).z()
gl = self.data.profile(selected_profile).names()
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "Abscisse en travers (m)"),
color='green', fontsize=12
)
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Cote (m)"),
color='green', fontsize=12
)
self.canvas.figure.tight_layout()
label_before_plot_selected = _translate("MainWindow_reach", "Profil précédent")
label_plot_selected = _translate("MainWindow_reach", "Profil sélectionné")
label_after_plot_selected = _translate("MainWindow_reach", "Profil suivant")
color_before_plot_selected = "k" # 'grey'
color_plot_selected = 'b'
color_after_plot_selected = 'm'
self.before_plot_selected, = self.canvas.axes.plot(
[], [], label=label_before_plot_selected, lw=1.8,
linestyle='--', color=color_before_plot_selected
)
self.plot_selected, = self.canvas.axes.plot(
station, elevation, label=label_plot_selected,
color=color_plot_selected, lw=1.8
)
self.after_plot_selected, = self.canvas.axes.plot(
station_plus_1, elevation_i_plus_1,
label=label_after_plot_selected,
color=color_after_plot_selected, lw=1.6, linestyle='--'
)
self.annotation = []
self.complete_gl, self.incomplete_gl = self.data.compute_guidelines()
lcomplete = list(self.complete_gl)
lincomplete = list(self.incomplete_gl)
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"]
x_gl_complete = []
y_gl_complete = []
color_scat_complete_gl = []
x_gl_incomplete = []
y_gl_incomplete = []
color_scat_incomplete_gl = []
for i, txt in enumerate(gl):
if txt.strip() in self.complete_gl:
annotation = self.canvas.axes.annotate(
txt, (station[i], elevation[i]),
horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_complete_gl[
lcomplete.index(txt)
]
)
annotation.set_position((station[i] + 0., elevation[i] + 0.))
self.annotation.append(annotation)
x_gl_complete.append(station[i])
y_gl_complete.append(elevation[i])
color_scat_complete_gl.append(self.color_complete_gl[lcomplete.index(txt)])
elif txt.strip() in self.incomplete_gl:
annotate = self.canvas.axes.annotate(
txt, (station[i], elevation[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True, fontsize=11,
color=self.color_incomplete_gl[
lincomplete.index(txt)
],
)
self.annotation.append(annotate)
x_gl_incomplete.append(station[i])
y_gl_incomplete.append(elevation[i])
color_scat_incomplete_gl.append(
self.color_incomplete_gl[lincomplete.index(txt)]
)
self.canvas.axes.legend(fancybox=True, shadow=True, fontsize=8)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
self.toolbar.update()
def update_full(self):
selected_profile = 0
station = self.data.profile(selected_profile).get_station()
station_plus_1 = self.data.profile(selected_profile + 1).get_station()
elevation = self.data.profile(selected_profile).z()
elevation_i_plus_1 = self.data.profile(selected_profile + 1).z()
gl = self.data.profile(selected_profile).names()
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "Abscisse en travers (m)"),
color='green', fontsize=12
)
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Cote (m)"),
color='green', fontsize=12
)
self.canvas.figure.tight_layout()
label_before_plot_selected = _translate("MainWindow_reach", "Profil précédent")
label_plot_selected = _translate("MainWindow_reach", "Profil sélectionné")
label_after_plot_selected = _translate("MainWindow_reach", "Profil suivant")
color_before_plot_selected = "k" # 'grey'
color_plot_selected = 'b'
color_after_plot_selected = 'm'
self.before_plot_selected, = self.canvas.axes.plot(
[], [], label=label_before_plot_selected, lw=1.8,
linestyle='--', color=color_before_plot_selected
)
self.plot_selected, = self.canvas.axes.plot(
station, elevation, label=label_plot_selected,
color=color_plot_selected, lw=1.8
)
self.after_plot_selected, = self.canvas.axes.plot(
station_plus_1, elevation_i_plus_1,
label=label_after_plot_selected,
color=color_after_plot_selected, lw=1.6, linestyle='--'
)
self.annotation = []
self.complete_gl, self.incomplete_gl = self.data.compute_guidelines()
lcomplete = list(self.complete_gl)
lincomplete = list(self.incomplete_gl)
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"]
x_gl_complete = []
y_gl_complete = []
color_scat_complete_gl = []
x_gl_incomplete = []
y_gl_incomplete = []
color_scat_incomplete_gl = []
for i, txt in enumerate(gl):
if txt.strip() in self.complete_gl:
annotation = self.canvas.axes.annotate(
txt, (station[i], elevation[i]),
horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_complete_gl[
lcomplete.index(txt)
]
)
annotation.set_position((station[i] + 0., elevation[i] + 0.))
self.annotation.append(annotation)
x_gl_complete.append(station[i])
y_gl_complete.append(elevation[i])
color_scat_complete_gl.append(self.color_complete_gl[lcomplete.index(txt)])
elif txt.strip() in self.incomplete_gl:
annotate = self.canvas.axes.annotate(
txt, (station[i], elevation[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True, fontsize=11,
color=self.color_incomplete_gl[
lincomplete.index(txt)
],
)
self.annotation.append(annotate)
x_gl_incomplete.append(station[i])
y_gl_incomplete.append(elevation[i])
color_scat_incomplete_gl.append(
self.color_incomplete_gl[lincomplete.index(txt)]
)
self.canvas.axes.legend(fancybox=True, shadow=True, fontsize=8)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
self.toolbar.update()
def update_annotate_full(self, ind):
for a in self.annotation:
a.remove()
self.annotation[:] = []
x = self.data.profile(ind).get_station()
y = self.data.profile(ind).z()
gl = self.data.profile(ind).names()
complete, incomplete = self.data.compute_guidelines()
lcomplete = list(complete)
lincomplete = list(incomplete)
self.x_complete = []
color_scat_complete = []
self.x_incomplete = []
color_scat_incomplete = []
try:
for i, txt in enumerate(gl):
if txt in complete:
annotate = self.canvas.axes.annotate(
txt, (x[i], y[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_complete_gl[
lcomplete.index(txt)
],
)
self.annotation.append(annotate)
self.x_complete.append([x[i], y[i]])
color_scat_complete.append(
self.color_complete_gl[lcomplete.index(txt)]
)
elif txt in incomplete:
annotate = self.canvas.axes.annotate(
txt, (x[i], y[i]), horizontalalignment='left',
verticalalignment='top', annotation_clip=True,
fontsize=11,
color=self.color_incomplete_gl[
lincomplete.index(txt)
],
)
self.annotation.append(annotate)
self.x_incomplete.append([x[i], y[i]])
color_scat_incomplete.append(
self.color_incomplete_gl[lincomplete.index(txt)]
)
except Exception as e:
print(f"{e}")
self.canvas.figure.canvas.draw_idle()
@timer
def update(self, ind=None):
if ind:
before = ind - 1
after = ind + 1
self.before_plot_selected.set_data([], [])
self.plot_selected.set_data([], [])
self.after_plot_selected.set_data([], [])
if 0 <= before < self.data.number_profiles:
self.before_plot_selected.set_data(
self.data.profile(before).get_station(),
self.data.profile(before).z()
)
if 0 <= ind < self.data.number_profiles:
self.plot_selected.set_data(
self.data.profile(ind).get_station(),
self.data.profile(ind).z()
)
if 0 <= after < self.data.number_profiles:
self.after_plot_selected.set_data(
self.data.profile(after).get_station(),
self.data.profile(after).z()
)
self.update_annotate_full(ind)
else:
self.update_full()
self.update_annotate_full(0)
self.canvas.axes.relim()
self.canvas.axes.autoscale_view()
self.canvas.figure.canvas.draw_idle()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment