GeoTIFF: Add red rectangle at GeoTIFF selected.

scenario-dev-pa
Pierre-Antoine 2025-11-17 15:01:00 +01:00
parent 624ae826eb
commit f8a41fce08
2 changed files with 53 additions and 5 deletions

View File

@ -116,13 +116,13 @@ class GeoTIFF(SQLSubModel):
self.read_file(value)
elif key == "coordinates":
self.coordinates = value
elif key == "coordinates_bottom":
elif key == "coordinates_bottom" or key == "bottom":
self.coordinates["bottom"] = value
elif key == "coordinates_top":
elif key == "coordinates_top" or key == "top":
self.coordinates["top"] = value
elif key == "coordinates_left":
elif key == "coordinates_left" or key == "left":
self.coordinates["left"] = value
elif key == "coordinates_right":
elif key == "coordinates_right" or key == "right":
self.coordinates["right"] = value
self.modified()

View File

@ -22,6 +22,8 @@ from PyQt5.QtWidgets import (
QAction, QListView, QVBoxLayout,
)
from matplotlib.patches import Rectangle
from Modules import Modules
from View.Tools.PamhyrWindow import PamhyrWindow
@ -30,6 +32,7 @@ from View.GeoTIFF.List import ListModel
from View.GeoTIFF.Translate import GeoTIFFTranslate
from View.GeoTIFF.Edit.Window import EditGeoTIFFWindow
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.PlotXY import PlotXY
@ -71,7 +74,7 @@ class GeoTIFFListWindow(PamhyrWindow):
self.setup_connections()
def setup_list(self):
lst = self.find(QListView, f"listView")
lst = self.find(QListView, "listView")
self._list = ListModel(
list_view=lst,
data=self._study.river.geotiff,
@ -83,6 +86,11 @@ class GeoTIFFListWindow(PamhyrWindow):
self.canvas = MplCanvas(width=5, height=4, dpi=100)
self.canvas.setObjectName("canvas")
self._plot_layout = self.find(QVBoxLayout, "verticalLayout")
self._toolbar = PamhyrPlotToolbar(
self.canvas, self,
items=["home", "zoom", "save", "iso", "back/forward", "move"]
)
self._plot_layout.addWidget(self._toolbar)
self._plot_layout.addWidget(self.canvas)
self._plot = PlotXY(
@ -93,6 +101,7 @@ class GeoTIFFListWindow(PamhyrWindow):
toolbar=None,
parent=self
)
self._plot_rect = []
self._plot.update()
@ -103,6 +112,11 @@ class GeoTIFFListWindow(PamhyrWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit)
self.find(QListView, "listView")\
.selectionModel()\
.selectionChanged\
.connect(self._update_rectangle)
def _propagated_update(self, key=Modules(0)):
if Modules.GEOMETRY not in key and Modules.GEOTIFF not in key:
return
@ -113,6 +127,40 @@ class GeoTIFFListWindow(PamhyrWindow):
self._list.update()
self._plot.update()
self._update_rectangle()
def _update_rectangle(self):
for rect in self._plot_rect:
rect.remove()
self._plot_rect = []
rows = self.selected_rows()
if len(rows) <= 0:
return
for row in rows:
geotiff = self._study.river.geotiff.files[row]
coord = geotiff.coordinates
xy = (coord["bottom"], coord["left"])
width = abs(coord["top"] - coord["bottom"])
height = abs(coord["right"] - coord["left"])
rect = Rectangle(
xy, width, height,
edgecolor='red', facecolor='none',
lw=2
)
self._plot_rect.append(rect)
self.canvas.axes.add_patch(
rect
)
self._plot.idle()
def selected_rows(self):
lst = self.find(QListView, f"listView")
return list(map(lambda i: i.row(), lst.selectedIndexes()))