mirror of https://gitlab.com/pamhyr/pamhyr2
add XY geom view in main window
parent
a19ab7aa79
commit
77baba0893
|
|
@ -20,8 +20,13 @@ import logging
|
|||
|
||||
from tools import timer, trace
|
||||
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.PlotXY import PlotXY
|
||||
from View.Tools.PamhyrWidget import PamhyrWidget
|
||||
|
||||
from PyQt5.QtWidgets import QVBoxLayout
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
|
|
@ -38,7 +43,9 @@ class WidgetInfo(PamhyrWidget):
|
|||
parent=parent
|
||||
)
|
||||
|
||||
self.parent = parent
|
||||
self.set_initial_values()
|
||||
self.setup_graph()
|
||||
|
||||
@property
|
||||
def study(self):
|
||||
|
|
@ -64,6 +71,25 @@ class WidgetInfo(PamhyrWidget):
|
|||
self.set_label_text("label_lc", "-")
|
||||
self.set_label_text("label_hs", "-")
|
||||
|
||||
def setup_graph(self):
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.plot_layout_xy = self.find(QVBoxLayout, "verticalLayout")
|
||||
self._toolbar_xy = PamhyrPlotToolbar(
|
||||
self.canvas, self,
|
||||
items=["home", "zoom", "save", "iso", "back/forward", "move"]
|
||||
)
|
||||
self.plot_layout_xy.addWidget(self._toolbar_xy)
|
||||
self.plot_layout_xy.addWidget(self.canvas)
|
||||
|
||||
self.plot = PlotXY(
|
||||
canvas=self.canvas,
|
||||
data=None,
|
||||
trad=self.parent._trad,
|
||||
toolbar=self._toolbar_xy,
|
||||
parent=self
|
||||
)
|
||||
|
||||
def update(self):
|
||||
if self._study is None:
|
||||
self.set_initial_values()
|
||||
|
|
@ -75,6 +101,15 @@ class WidgetInfo(PamhyrWidget):
|
|||
self.set_network_values()
|
||||
self.set_geometry_values()
|
||||
|
||||
self.plot = PlotXY(
|
||||
canvas=self.canvas,
|
||||
data=self._study.river.enable_edges(),
|
||||
trad=self.parent._trad,
|
||||
toolbar=self._toolbar_xy,
|
||||
parent=self
|
||||
)
|
||||
self.plot.update()
|
||||
|
||||
def set_network_values(self):
|
||||
river = self._study.river
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
# PlotXY.py -- Pamhyr
|
||||
# Copyright (C) 2023-2024 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import timer, trace
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
from matplotlib import collections
|
||||
import numpy as np
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication, Qt, QItemSelectionModel,
|
||||
QItemSelection, QItemSelectionRange,
|
||||
)
|
||||
from PyQt5.QtWidgets import QApplication, QTableView
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class PlotXY(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, data=None, toolbar=None,
|
||||
table=None, parent=None):
|
||||
super(PlotXY, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
data=data,
|
||||
toolbar=toolbar,
|
||||
table=table,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._data = data
|
||||
self.label_x = self._trad["x"]
|
||||
self.label_y = self._trad["y"]
|
||||
self.parent = parent
|
||||
|
||||
self._isometric_axis = True
|
||||
|
||||
self._auto_relim_update = True
|
||||
self._autoscale_update = True
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.init_axes()
|
||||
|
||||
if self._data is None:
|
||||
self.idle()
|
||||
return
|
||||
|
||||
if len(self._data) < 1:
|
||||
self.idle()
|
||||
return
|
||||
|
||||
self.line_lr = []
|
||||
for data in self._data:
|
||||
if data.reach.number_profiles != 0:
|
||||
self.draw_xy(data.reach)
|
||||
self.draw_lr(data.reach)
|
||||
self.idle()
|
||||
return
|
||||
|
||||
def draw_xy(self, reach):
|
||||
line_xy = []
|
||||
for xy in zip(reach.get_x(), reach.get_y()):
|
||||
line_xy.append(np.column_stack(xy))
|
||||
|
||||
line_xy_collection = collections.LineCollection(
|
||||
line_xy,
|
||||
colors=self.color_plot_river_bottom
|
||||
)
|
||||
self.canvas.axes.add_collection(line_xy_collection)
|
||||
|
||||
def draw_lr(self, reach):
|
||||
lx = []
|
||||
ly = []
|
||||
rx = []
|
||||
ry = []
|
||||
|
||||
for x, y in zip(reach.get_x(),
|
||||
reach.get_y()):
|
||||
lx.append(x[0])
|
||||
ly.append(y[0])
|
||||
|
||||
rx.append(x[-1])
|
||||
ry.append(y[-1])
|
||||
|
||||
line = self.canvas.axes.plot(
|
||||
lx, ly,
|
||||
color=self.color_plot_river_bottom,
|
||||
linestyle="dotted",
|
||||
lw=1.,
|
||||
)
|
||||
self.line_lr.append(line)
|
||||
|
||||
line = self.canvas.axes.plot(
|
||||
rx, ry,
|
||||
color=self.color_plot_river_bottom,
|
||||
linestyle="dotted",
|
||||
lw=1.,
|
||||
)
|
||||
self.line_lr.append(line)
|
||||
|
||||
@timer
|
||||
def update(self):
|
||||
self.draw()
|
||||
self.update_idle()
|
||||
|
|
@ -73,8 +73,7 @@ class UnitTranslate(CommonWordTranslate):
|
|||
|
||||
self._dict["unit_date_s"] = _translate("Unit", "Date (sec)")
|
||||
self._dict["unit_date_iso"] = _translate("Unit", "Date (ISO format)")
|
||||
|
||||
self._dict["unit_wet_area"] = _translate("Unit", "Wet Area (m^2)")
|
||||
self._dict["unit_wet_area"] = _translate("Unit", "Wet Area (m²)")
|
||||
self._dict["unit_wet_perimeter"] = _translate(
|
||||
"Unit", "Wet Perimeter (m)"
|
||||
)
|
||||
|
|
@ -133,3 +132,5 @@ class MainTranslate(UnitTranslate):
|
|||
"MainWindow",
|
||||
"Do you want to save current study before closing it?"
|
||||
)
|
||||
self._dict["x"] = _translate("MainWindow", "X (m)")
|
||||
self._dict["y"] = _translate("MainWindow", "Y (m)")
|
||||
|
|
|
|||
Loading…
Reference in New Issue