mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "1ed5d69bf4f9336faf52ee70823d4d4f6002032a" and "a308af41e00fa872315b3613b844b63158b8c8b0" have entirely different histories.
1ed5d69bf4
...
a308af41e0
|
|
@ -35,8 +35,6 @@ try:
|
|||
import rasterio.sample
|
||||
import rasterio.vrt
|
||||
import rasterio._features
|
||||
|
||||
from rasterio.io import MemoryFile
|
||||
_rasterio_loaded = True
|
||||
except Exception as e:
|
||||
print(f"Module 'rasterio' is not available: {e}")
|
||||
|
|
@ -155,7 +153,7 @@ class GeoTIFF(SQLSubModel):
|
|||
if self._file_bytes == b'':
|
||||
return None
|
||||
|
||||
if self._memfile is None:
|
||||
if self._memfile == None:
|
||||
self._memfile = MemoryFile()
|
||||
self._memfile.write(self._file_bytes)
|
||||
|
||||
|
|
@ -204,12 +202,9 @@ class GeoTIFF(SQLSubModel):
|
|||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) == 2:
|
||||
if major == "0" and int(minor) <= 2:
|
||||
if int(release) < 3:
|
||||
cls._db_create(execute)
|
||||
cls._create_submodel(execute)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -233,7 +228,6 @@ class GeoTIFF(SQLSubModel):
|
|||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
|
|
@ -293,7 +287,7 @@ class GeoTIFF(SQLSubModel):
|
|||
self.name,
|
||||
self.description,
|
||||
self.file_name,
|
||||
self.file_bytes,
|
||||
self.file_bytes
|
||||
self.coordinates['bottom'],
|
||||
self.coordinates['top'],
|
||||
self.coordinates['left'],
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from tools import trace, timer
|
|||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.GeoTIFF.GeoTIFF import GeoTIFF
|
||||
from Model.AdditionalFile.GeoTIFF import GeoTIFF
|
||||
|
||||
|
||||
class GeoTIFFList(PamhyrModelList):
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList \
|
|||
import LateralContributionsAdisTSList
|
||||
from Model.D90AdisTS.D90AdisTSList import D90AdisTSList
|
||||
from Model.DIFAdisTS.DIFAdisTSList import DIFAdisTSList
|
||||
from Model.GeoTIFF.GeoTIFFList import GeoTIFFList
|
||||
from Model.Results.Results import Results
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
@ -469,7 +468,6 @@ class River(Graph):
|
|||
LateralContributionsAdisTSList,
|
||||
D90AdisTSList,
|
||||
DIFAdisTSList,
|
||||
GeoTIFFList,
|
||||
Results
|
||||
]
|
||||
|
||||
|
|
@ -507,8 +505,6 @@ class River(Graph):
|
|||
self._D90AdisTS = D90AdisTSList(status=self._status)
|
||||
self._DIFAdisTS = DIFAdisTSList(status=self._status)
|
||||
|
||||
self._geo_tiff = GeoTIFFList(status=self._status)
|
||||
|
||||
self._results = {}
|
||||
|
||||
@classmethod
|
||||
|
|
@ -621,8 +617,6 @@ class River(Graph):
|
|||
|
||||
new._DIFAdisTS = DIFAdisTSList._db_load(execute, data)
|
||||
|
||||
new._geo_tiff = GeoTIFFList._db_load(execute, data)
|
||||
|
||||
return new
|
||||
|
||||
def _db_load_results(self, execute, data=None):
|
||||
|
|
@ -732,7 +726,6 @@ class River(Graph):
|
|||
self._BoundaryConditionsAdisTS,
|
||||
self._LateralContributionsAdisTS,
|
||||
self._D90AdisTS, self._DIFAdisTS,
|
||||
self._geo_tiff,
|
||||
]
|
||||
|
||||
for solver in self._parameters:
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ logger = logging.getLogger()
|
|||
|
||||
|
||||
class Study(SQLModel):
|
||||
_version = "0.2.3"
|
||||
_version = "0.2.2"
|
||||
|
||||
_sub_classes = [
|
||||
Scenario,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class Modules(IterableFlag):
|
|||
SEDIMENT_LAYER = auto()
|
||||
ADDITIONAL_FILES = auto()
|
||||
OUTPUT_RK = auto()
|
||||
GEOTIFF = auto()
|
||||
|
||||
# Results
|
||||
RESULTS = auto()
|
||||
|
|
@ -82,7 +81,6 @@ class Modules(IterableFlag):
|
|||
cls.RESULTS,
|
||||
cls.WINDOW_LIST,
|
||||
cls.OUTPUT_RK,
|
||||
cls.GEOTIFF
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
|
@ -101,7 +99,6 @@ class Modules(IterableFlag):
|
|||
| cls.HYDRAULIC_STRUCTURES
|
||||
| cls.RESERVOIR
|
||||
| cls.SEDIMENT_LAYER
|
||||
| cls.GEOTIFF
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -117,7 +114,6 @@ class Modules(IterableFlag):
|
|||
cls.HYDRAULIC_STRUCTURES,
|
||||
cls.RESERVOIR,
|
||||
cls.SEDIMENT_LAYER,
|
||||
cls.GEOTIFF,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
|
@ -133,7 +129,6 @@ class Modules(IterableFlag):
|
|||
cls.HYDRAULIC_STRUCTURES: "Hydraulic structures",
|
||||
cls.RESERVOIR: "Reservoir",
|
||||
cls.SEDIMENT_LAYER: "Sediment layer",
|
||||
cls.GEOTIFF: "GeoTIFF",
|
||||
}
|
||||
|
||||
def impact(self):
|
||||
|
|
@ -173,5 +168,4 @@ _impact = {
|
|||
Modules.HYDRAULIC_STRUCTURES: [],
|
||||
Modules.RESERVOIR: [],
|
||||
Modules.SEDIMENT_LAYER: [],
|
||||
Modules.GEOTIFF: [],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,102 +0,0 @@
|
|||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from Modules import Modules
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QLabel, QPlainTextEdit, QPushButton,
|
||||
QCheckBox,
|
||||
)
|
||||
|
||||
from View.GeoTIFF.Translate import GeoTIFFTranslate
|
||||
from View.GeoTIFF.UndoCommand import (
|
||||
SetCommand
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class EditGeoTIFFWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "EditGeoTIFF"
|
||||
_pamhyr_name = "Edit GeoTIFF"
|
||||
|
||||
def __init__(self, study=None, config=None, add_file=None,
|
||||
trad=None, undo=None, parent=None):
|
||||
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
super(EditGeoTIFFWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._geotiff = geotiff
|
||||
self._hash_data.append(self._geotiff)
|
||||
|
||||
self._undo = undo
|
||||
|
||||
self.setup_values()
|
||||
self.setup_connection()
|
||||
|
||||
def setup_values(self):
|
||||
self.set_check_box("checkBox", self._geotiff.enabled)
|
||||
self.set_line_edit_text("lineEdit_name", self._geotiff.name)
|
||||
self.set_line_edit_text("lineEdit_path", self._geotiff.description)
|
||||
self.set_plaintext_edit_text("plainTextEdit", self._geotiff.text)
|
||||
|
||||
if self._study.is_read_only():
|
||||
self.set_check_box_enable("checkBox", False)
|
||||
self.set_line_edit_enable("lineEdit_name", False)
|
||||
self.set_line_edit_enable("lineEdit_path", False)
|
||||
self.set_plaintext_edit_enable("plainTextEdit", False)
|
||||
|
||||
def setup_connection(self):
|
||||
self.find(QPushButton, "pushButton_cancel")\
|
||||
.clicked.connect(self.close)
|
||||
self.find(QPushButton, "pushButton_ok")\
|
||||
.clicked.connect(self.accept)
|
||||
|
||||
def accept(self):
|
||||
if self._study.is_editable():
|
||||
is_enabled = self.get_check_box("checkBox")
|
||||
name = self.get_line_edit_text("lineEdit_name")
|
||||
path = self.get_line_edit_text("lineEdit_path")
|
||||
coord_bottom = self.get_plaintext_edit_text("plainTextEdit")
|
||||
coord_top = self.get_plaintext_edit_text("plainTextEdit")
|
||||
coord_left = self.get_plaintext_edit_text("plainTextEdit")
|
||||
coord_right = self.get_plaintext_edit_text("plainTextEdit")
|
||||
|
||||
self._undo.push(
|
||||
SetCommand(
|
||||
self._geotiff, enabled=is_enabled,
|
||||
name=name, description=description,
|
||||
coordinates_bottom=coord_bottom,
|
||||
coordinates_top=coord_top,
|
||||
coordinates_left=coord_left,
|
||||
coordinates_right=coord_right,
|
||||
)
|
||||
)
|
||||
|
||||
self._propagate_update(key=Modules.GEOTIFF)
|
||||
|
||||
self.close()
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
# List.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from functools import reduce
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant,
|
||||
)
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QColor, QBrush,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrList import PamhyrListModel
|
||||
from View.GeoTIFF.UndoCommand import (
|
||||
AddCommand, DelCommand
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class ListModel(PamhyrListModel):
|
||||
def get_true_data_row(self, row):
|
||||
el = self._data.get(row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == el,
|
||||
enumerate(self._data._lst)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
file = self._data.files[row]
|
||||
|
||||
if role == Qt.ForegroundRole:
|
||||
color = Qt.gray
|
||||
|
||||
if file.is_enabled():
|
||||
color = QColor("black")
|
||||
else:
|
||||
color = QColor("grey")
|
||||
|
||||
return QBrush(color)
|
||||
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
text = f"{file.name}: '{file.path}'"
|
||||
|
||||
if not file.is_enabled():
|
||||
text += " (disabled)"
|
||||
|
||||
return text
|
||||
|
||||
return QVariant()
|
||||
|
||||
def add(self, row):
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._data, row
|
||||
)
|
||||
)
|
||||
self.update()
|
||||
|
||||
def delete(self, row):
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, self._data.files[row]
|
||||
)
|
||||
)
|
||||
self.update()
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
# Translate.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 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 PyQt5.QtCore import QCoreApplication
|
||||
from View.Translate import MainTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class GeoTIFFTranslate(MainTranslate):
|
||||
def __init__(self):
|
||||
super(AddFileTranslate, self).__init__()
|
||||
|
||||
self._dict["GeoTIFF files"] = _translate(
|
||||
"GeoTIFF", "GeoTIFF files"
|
||||
)
|
||||
|
||||
self._dict["Edit additional file"] = _translate(
|
||||
"GeoTIFF", "Edit GeoTIFF file"
|
||||
)
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
# UndoCommand.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 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 trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
|
||||
class SetCommand(QUndoCommand):
|
||||
def __init__(self, geotiff, **kwargs):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._geotiff = geotiff
|
||||
self._new = kwargs
|
||||
self._old = None
|
||||
|
||||
def undo(self):
|
||||
f = self._geotiff
|
||||
|
||||
for key in self._old:
|
||||
f[key] = self._old[key]
|
||||
|
||||
def redo(self):
|
||||
f = self._geotiff
|
||||
|
||||
if self._old is None:
|
||||
self._old = {}
|
||||
for key in self._new:
|
||||
self._old[key] = f[key]
|
||||
|
||||
for key in self._new:
|
||||
f[key] = self._new[key]
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, files, row):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._files = files
|
||||
self._row = row
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._new.set_as_deleted()
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._files.new(self._row)
|
||||
else:
|
||||
self._new.set_as_not_deleted()
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, files, line):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._files = files
|
||||
self._line = line
|
||||
|
||||
def undo(self):
|
||||
self._line.set_as_not_deleted()
|
||||
|
||||
def redo(self):
|
||||
self._line.set_as_deleted()
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 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 trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QAction, QListView,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from View.GeoTIFF.List import ListModel
|
||||
from View.GeoTIFF.Translate import GeoTIFFTranslate
|
||||
from View.GeoTIFF.Edit.Window import EditGeoTIFFWindow
|
||||
|
||||
|
||||
class GeoTIFFListWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "GeoTIFFList"
|
||||
_pamhyr_name = "GeoTIFF files"
|
||||
|
||||
def __init__(self, study=None, config=None,
|
||||
parent=None):
|
||||
trad = GeoTIFFTranslate()
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
|
||||
super(GeoTIFFListWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self.setup_list()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_list(self):
|
||||
lst = self.find(QListView, f"listView")
|
||||
self._list = ListModel(
|
||||
list_view=lst,
|
||||
data=self._study.river.geotiff,
|
||||
undo=self._undo_stack,
|
||||
trad=self._trad,
|
||||
)
|
||||
|
||||
def setup_connections(self):
|
||||
if self._study.is_editable():
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
||||
|
||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
|
||||
def update(self):
|
||||
self._list.update()
|
||||
|
||||
def selected_rows(self):
|
||||
lst = self.find(QListView, f"listView")
|
||||
return list(map(lambda i: i.row(), lst.selectedIndexes()))
|
||||
|
||||
def add(self):
|
||||
rows = self.selected_rows()
|
||||
if len(rows) > 0:
|
||||
row = rows[0]
|
||||
else:
|
||||
row = 0
|
||||
|
||||
self._list.add(row)
|
||||
|
||||
def delete(self):
|
||||
rows = self.selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._list.delete(rows[0])
|
||||
|
||||
def edit(self):
|
||||
rows = self.selected_rows()
|
||||
|
||||
for row in rows:
|
||||
add_file = self._study.river.geotiff.files[row]
|
||||
|
||||
if self.sub_window_exists(
|
||||
EditGeoTIFFWindow,
|
||||
data=[self._study, self._config, add_file]
|
||||
):
|
||||
continue
|
||||
|
||||
win = EditGeoTIFFWindow(
|
||||
study=self._study,
|
||||
config=self._config,
|
||||
add_file=add_file,
|
||||
trad=self._trad,
|
||||
undo=self._undo_stack,
|
||||
parent=self,
|
||||
)
|
||||
win.show()
|
||||
|
||||
def _undo(self):
|
||||
self._undo_stack.undo()
|
||||
self.update()
|
||||
|
||||
def _redo(self):
|
||||
self._undo_stack.redo()
|
||||
self.update()
|
||||
Loading…
Reference in New Issue