Merge branch 'master' of gitlab.com:pamhyr/pamhyr2

This commit is contained in:
parouby committed 2025-10-21 15:42:01 +02:00
commit 97ebf9324a
38 files changed
+1152 -305

No files matched your search

+23
View File
@@ -211,3 +211,26 @@ class TableModel(PamhyrTableModel):
)
self.layoutAboutToBeChanged.emit()
self.update()
def read_from_file(self, file_name, bctype):
logger.debug(f"Import boundary conditions from {file_name}")
data0 = []
data1 = []
if bctype == "ZD":
mult = 1
else:
mult = 60
with open(file_name, encoding="utf-8") as bc_file:
for line in bc_file:
if not (line.startswith("#") or
line.startswith("*") or
line.startswith("$")):
line = line.split()
if bctype == "ZD":
data0.append(float(line[0]))
else:
data0.append(old_pamhyr_date_to_timestamp(line[0]))
data1.append(line[1])
self.replace_data(data0, data1)
+29 -2
View File
@@ -30,10 +30,10 @@ from PyQt5.QtGui import (
QKeySequence,
)
from PyQt5 import QtCore
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel, QCoreApplication,
pyqtSlot, pyqtSignal,
pyqtSlot, pyqtSignal, QSettings,
)
from PyQt5.QtWidgets import (
@@ -198,6 +198,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_sort").triggered.connect(self.sort)
self.find(QAction, "action_import").triggered\
.connect(self.import_from_file)
self.find(QAction, "action_generate_uniform").triggered.connect(
self.generate_uniform
)
@@ -293,6 +295,31 @@ class EditBoundaryConditionWindow(PamhyrWindow):
self._table.sort(False)
self.plot.update()
def import_from_file(self):
options = QFileDialog.Options()
settings = QSettings(QSettings.IniFormat,
QSettings.UserScope, 'MyOrg', )
options |= QFileDialog.DontUseNativeDialog
if self._data.bctype == "TD":
file_types = [self._trad["file_hyd"]]
if self._data.bctype == "TZ":
file_types = [self._trad["file_lim"]]
if self._data.bctype == "ZD":
file_types = [self._trad["file_ava"]]
file_types.append(self._trad["file_all"])
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
self,
self._trad["open_file"],
"",
";; ".join(file_types),
options=options
)
if file_name != "":
self._table.read_from_file(file_name, self._data.bctype)
def move_up(self):
row = self.index_selected_row()
self._table.move_up(row)
@@ -35,6 +35,17 @@ class BCETranslate(BCTranslate):
self._dict["Boundary Condition Options"] = _translate(
"BoundaryCondition", "Boundary Condition Options")
self._dict["open_file"] = _translate(
"BoundaryCondition", "Open a file")
self._dict["file_hyd"] = _translate(
"BoundaryCondition", "Mage hydrograph file (*.HYD)")
self._dict["file_lim"] = _translate(
"BoundaryCondition", "Mage limnigraph file (*.LIM)")
self._dict["file_ava"] = _translate(
"BoundaryCondition", "Mage rating curve file (*.AVA)")
self._dict["file_all"] = _translate(
"BoundaryCondition", "All files (*)")
self._sub_dict["table_headers"] = {
"x": _translate("BoundaryCondition", "X"),
"y": _translate("BoundaryCondition", "Y"),
+43 -2
View File
@@ -38,7 +38,7 @@ from View.Frictions.UndoCommand import (
SetNameCommand, SetBeginCommand, SetEndCommand,
SetBeginStricklerCommand, SetEndStricklerCommand,
AddCommand, DelCommand, SortCommand,
MoveCommand, PasteCommand, DuplicateCommand,
MoveCommand, PasteCommand, DuplicateCommand, ReplaceDataCommand,
)
from View.Tools.PamhyrTable import PamhyrTableModel
@@ -99,7 +99,7 @@ class ComboBoxDelegate(QItemDelegate):
self.commitData.emit(self.sender())
class TableModel(PamhyrTableModel):
class FrictionTableModel(PamhyrTableModel):
def _setup_lst(self):
self._lst = self._data.frictions
self._study = self._opt_data
@@ -199,6 +199,18 @@ class TableModel(PamhyrTableModel):
self.endRemoveRows()
self.layoutChanged.emit()
def replace_data(self, new_data):
self.layoutAboutToBeChanged.emit()
self._undo.push(
ReplaceDataCommand(
self._lst, new_data
)
)
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()
def sort(self, _reverse, parent=QModelIndex()):
self.layoutAboutToBeChanged.emit()
@@ -252,3 +264,32 @@ class TableModel(PamhyrTableModel):
def redo(self):
self._undo.redo()
self.layoutChanged.emit()
def read_from_file(self, file_name):
reach_id = self._study.river.enable_edges().index(self._data) + 1
logger.debug(f"Import frictions from {file_name}")
data = []
with open(file_name, encoding="utf-8") as rug_file:
for line in rug_file:
if line.upper().startswith("K"):
if int(line[1:4]) == reach_id:
data.append(line[4:].split())
new_data = []
for d in data:
new = None
minor = float(d[2])
medium = float(d[3])
for s in self._study.river.stricklers.stricklers:
if s.minor == minor and s.medium == medium:
new = s
break
if new is None:
new = self._study.river.stricklers.new(len(
self._study.river.stricklers))
new.minor = minor
new.medium = medium
new_data.append([self._data, float(d[0]), float(d[1]), new, new])
self.replace_data(new_data)
+36
View File
@@ -143,6 +143,42 @@ class AddCommand(QUndoCommand):
self._frictions.insert(self._index, self._new)
class ReplaceDataCommand(QUndoCommand):
def __init__(self, frictions, new_data):
QUndoCommand.__init__(self)
self._frictions = frictions
self._new_data = new_data
self._old_rows = list(range(len(frictions)))
self._new_rows = list(range(len(new_data)))
self._new = []
self._old_friction = []
for row in self._old_rows:
self._old_friction.append((row, self._frictions.lst[row]))
def undo(self):
self._frictions.delete_i(self._new_rows)
for row, el in self._old_friction:
self._frictions.insert(row, el)
def redo(self):
if len(self._new) == 0:
self._frictions.delete_i(self._old_rows)
for row in self._new_rows:
new = self._frictions.new(row)
d = self._new_data[row]
new.edge = d[0]
new.begin_rk = d[1]
new.end_rk = d[2]
new.begin_strickler = d[3]
new.end_strickler = d[4]
self._new.append((row, new))
else:
for row, el in self._new:
self._frictions.insert(row, el)
class DelCommand(QUndoCommand):
def __init__(self, frictions, rows):
QUndoCommand.__init__(self)
+25 -3
View File
@@ -26,10 +26,11 @@ from PyQt5.QtGui import (
QKeySequence,
)
from PyQt5 import QtWidgets
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QRect,
QRect, QSettings,
)
from PyQt5.QtWidgets import (
@@ -46,7 +47,7 @@ from View.Frictions.UndoCommand import (
)
from View.Frictions.Table import (
TableModel, ComboBoxDelegate
FrictionTableModel, ComboBoxDelegate
)
from View.Tools.Plot.PamhyrCanvas import MplCanvas
@@ -106,7 +107,7 @@ class FrictionsWindow(PamhyrWindow):
)
table = self.find(QTableView, f"tableView")
self._table = TableModel(
self._table = FrictionTableModel(
table_view=table,
table_headers=self._trad.get_dict("table_headers"),
editable_headers=[
@@ -157,6 +158,8 @@ class FrictionsWindow(PamhyrWindow):
self.plot_2.draw()
def setup_connections(self):
self.find(QAction, "action_import").triggered\
.connect(self.import_from_file)
self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_sort").triggered.connect(self.sort)
@@ -265,3 +268,22 @@ class FrictionsWindow(PamhyrWindow):
parent=self
)
strick.show()
def import_from_file(self):
options = QFileDialog.Options()
settings = QSettings(QSettings.IniFormat,
QSettings.UserScope, 'MyOrg', )
options |= QFileDialog.DontUseNativeDialog
file_types = [self._trad["file_rug"], self._trad["file_all"]]
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
self,
self._trad["open_file"],
"",
";; ".join(file_types),
options=options
)
if file_name != "":
self._table.read_from_file(file_name)
+4
View File
@@ -38,6 +38,10 @@ class FrictionsTranslate(MainTranslate):
self._dict["Edit frictions"] = _translate(
"Frictions", "Edit frictions"
)
self._dict["file_rug"] = _translate(
"Frictions", "Mage initial frictions file (*.RUG *.rug)")
self._dict["file_all"] = _translate(
"Frictions", "All files (*)")
self._sub_dict["table_headers"] = {
# "name": self._dict["name"],
+18 -8
View File
@@ -23,12 +23,12 @@ from PyQt5.QtGui import (
)
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
Qt, QVariant, QAbstractTableModel, QItemSelectionModel,
)
from PyQt5.QtWidgets import (
QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
QDoubleSpinBox,
QDoubleSpinBox, QRadioButton,
)
@@ -55,7 +55,7 @@ class MeshingDialog(PamhyrDialog):
self._space_step = 50.0
self._lplan = False
self._lm = "3"
self._linear = False
self._linear = True
self._begin_cs = -1
self._end_cs = -1
self._begin_dir = "un"
@@ -71,7 +71,7 @@ class MeshingDialog(PamhyrDialog):
self._origin = self._reach.profile(0)
self._init_default_values_profiles()
self._init_default_values_guidelines()
# self._init_default_values_guidelines()
self.set_double_spin_box(
"doubleSpinBox_space_step",
@@ -83,14 +83,24 @@ class MeshingDialog(PamhyrDialog):
else:
self.set_radio_button("radioButton_spline", True)
self.find(QRadioButton, "radioButton_spline").setEnabled(False)
self.find(QRadioButton, "radioButton_linear").setEnabled(False)
def _init_default_values_profiles(self):
profiles = self.profiles
self.combobox_add_items("comboBox_begin_rk", profiles)
self.combobox_add_items("comboBox_end_rk", profiles)
self.set_combobox_text("comboBox_begin_rk", profiles[0])
self.set_combobox_text("comboBox_end_rk", profiles[-1])
r = self.parent.tableView\
.selectionModel()\
.selectedRows()
if len(r) <= 1:
self.set_combobox_text("comboBox_begin_rk", profiles[0])
self.set_combobox_text("comboBox_end_rk", profiles[-1])
else:
self.set_combobox_text("comboBox_begin_rk", profiles[r[0].row()])
self.set_combobox_text("comboBox_end_rk", profiles[r[-1].row()])
@property
def profiles(self):
@@ -167,8 +177,8 @@ class MeshingDialog(PamhyrDialog):
self._begin_cs = self.profiles.index(p1)
self._end_cs = self.profiles.index(p2)
self._begin_dir = self.get_combobox_text("comboBox_begin_gl")
self._end_dir = self.get_combobox_text("comboBox_end_gl")
# self._begin_dir = self.get_combobox_text("comboBox_begin_gl")
# self._end_dir = self.get_combobox_text("comboBox_end_gl")
super().accept()
+2 -4
View File
@@ -28,8 +28,6 @@ from PyQt5.QtWidgets import (
from Model.Geometry import Reach
from Model.Except import exception_message_box
from Meshing.Mage import MeshingWithMage
logger = logging.getLogger()
@@ -240,7 +238,7 @@ class MeshingCommand(QUndoCommand):
self._mesher = mesher
self._command = command
self._profiles = reach.profiles.copy()
self._profiles = [p.copy() for p in reach.profiles]
self._profiles.reverse()
self._new_profiles = None
@@ -264,7 +262,7 @@ class MeshingCommand(QUndoCommand):
**self._data
)
self._new_profiles = self._reach.profiles.copy()
self._new_profiles = [p.copy() for p in self._reach.profiles]
self._new_profiles.reverse()
else:
self._reach.purge()
+27 -12
View File
@@ -32,6 +32,7 @@ from PyQt5.QtGui import (
from PyQt5.QtCore import (
QModelIndex, Qt, QSettings, pyqtSlot,
QItemSelectionModel, QCoreApplication, QSize,
QItemSelection, QItemSelectionRange,
)
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QFileDialog, QCheckBox,
@@ -49,9 +50,7 @@ from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.SelectReach.Window import SelectReachWindow
from Meshing.Mage import (
MeshingWithMage, MeshingWithMageMailleurTT
)
from Meshing.Internal import InternalMeshing
from View.Geometry.Table import GeometryReachTableModel
from View.Geometry.PlotXY import PlotXY
@@ -288,6 +287,13 @@ class GeometryWindow(PamhyrWindow):
self.tableView.model().blockSignals(False)
def edit_meshing(self):
rows = list(
set(
(i.row() for i in self.tableView.selectedIndexes())
)
)
selected_rk = [self._reach.profile(r).rk for r in rows]
try:
dlg = MeshingDialog(
reach=self._reach,
@@ -298,8 +304,6 @@ class GeometryWindow(PamhyrWindow):
data = {
"step": dlg.space_step,
"limites": [dlg.begin_cs, dlg.end_cs],
"directrices": [dlg.begin_dir, dlg.end_dir],
"lplan": dlg.lplan,
"linear": dlg.linear,
}
self._edit_meshing(data)
@@ -307,18 +311,29 @@ class GeometryWindow(PamhyrWindow):
logger_exception(e)
return
ind = []
for i in range(self._reach.number_profiles):
if self._reach.profile(i).rk in selected_rk:
ind.append(i)
self.tableView.setFocus()
selection = self.tableView.selectionModel()
index = QItemSelection()
if len(ind) > 0:
for i in ind:
index.append(QItemSelectionRange(self.tableView.model().index(i, 0)))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
def _edit_meshing(self, data):
try:
mesher = MeshingWithMageMailleurTT()
mesher = InternalMeshing()
self._table.meshing(mesher, data)
except Exception as e:
logger_exception(e)
raise ExternFileMissingError(
module="mage",
filename="MailleurTT",
path=MeshingWithMageMailleurTT._path(),
src_except=e
)
def update_rk(self):
try:
+28 -1
View File
@@ -244,7 +244,7 @@ class InitialConditionTableModel(PamhyrTableModel):
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()
def import_from_results(self, index, results):
def import_from_results(self, results):
if results is None:
logger.error("No results data")
return
@@ -281,6 +281,33 @@ class InitialConditionTableModel(PamhyrTableModel):
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()
def read_from_ini(self, file_name):
reach_id = self._data.river.enable_edges().index(self._reach) + 1
logger.debug(f"Import initial conditions from {file_name}")
data = []
with open(file_name, encoding="utf-8") as ini_file:
for line in ini_file:
if not (line.startswith("#") or
line.startswith("*") or
line.startswith("$")):
line = line.split()
if int(line[0]) == reach_id:
data.append([line[4], line[2], line[3]])
self._undo.push(
ReplaceDataCommand(
self._lst,
list(
map(
lambda d: self._lst.new_from_data(*d),
data
)
)
)
)
def undo(self):
self._undo.undo()
self.layoutChanged.emit()
+20 -9
View File
@@ -265,20 +265,29 @@ class InitialConditionsWindow(PamhyrWindow):
settings = QSettings(QSettings.IniFormat,
QSettings.UserScope, 'MyOrg', )
options |= QFileDialog.DontUseNativeDialog
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
file_types = [
self._trad["file_bin"],
self._trad["file_ini"],
self._trad["file_all"],
]
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
self,
self._trad["open_file"],
"",
";; ".join(["Mage (*.BIN)"]),
";; ".join(file_types),
options=options
)
if filename != "":
size = os.stat(filename).st_size
# self._table.import_geometry(0, filename)
self._import_from_file(filename)
if file_name != "":
size = os.stat(file_name).st_size
# self._table.import_geometry(0, file_name)
if file_name[-4:] == ".BIN":
self._import_from_bin_file(file_name)
elif file_name[-4:].upper() == ".INI":
self._import_from_ini_file(file_name)
def _import_from_file(self, file_name):
def _import_from_bin_file(self, file_name):
solver = Mage8("dummy")
name = os.path.basename(file_name)\
.replace(".BIN", "")
@@ -305,9 +314,11 @@ class InitialConditionsWindow(PamhyrWindow):
def _import_from_results(self, results):
logger.debug(f"import from results: {results}")
row = self.index_selected_row()
self._table.import_from_results(results)
self._table.import_from_results(row, results)
def _import_from_ini_file(self, file_name):
logger.debug(f"import from INI file: {file_name}")
self._table.read_from_ini(file_name)
def move_up(self):
row = self.index_selected_row()
+9
View File
@@ -34,6 +34,15 @@ class ICTranslate(MainTranslate):
self._dict["discharge"] = self._dict["unit_discharge"]
self._dict["rk"] = self._dict["unit_rk"]
self._dict["open_file"] = _translate(
"InitialCondition", "Open a file")
self._dict["file_bin"] = _translate(
"InitialCondition", "Mage results file (*.BIN)")
self._dict["file_ini"] = _translate(
"InitialCondition", "Mage initial conditions file (*.INI *.ini)")
self._dict["file_all"] = _translate(
"InitialCondition", "All files (*)")
self._sub_dict["table_headers"] = {
# "name": _translate("InitialCondition", "Name"),
"rk": self._dict["unit_rk"],
+56 -12
View File
@@ -19,7 +19,7 @@
import logging
import traceback
from tools import trace, timer
from tools import trace, timer, old_pamhyr_date_to_timestamp
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
@@ -38,7 +38,7 @@ from View.LateralContribution.UndoCommand import (
SetNameCommand, SetEdgeCommand, SetTypeCommand,
SetBeginCommand, SetEndCommand,
AddCommand, DelCommand, SortCommand,
MoveCommand, PasteCommand, DuplicateCommand,
MoveCommand, PasteCommand, DuplicateCommand, ImportCommand,
)
from Model.LateralContribution.LateralContributionTypes import (
@@ -116,17 +116,20 @@ class ComboBoxDelegate(QItemDelegate):
def setModelData(self, editor, model, index):
text = str(editor.currentText())
if self._mode == "rk":
profiles = list(
filter(
lambda p: p.display_name() == text,
self._data.reach.profiles
)
)
value = profiles[0].rk if len(profiles) > 0 else None
else:
if self._data is None:
value = text
else:
if self._mode == "rk" and self._data.reach is not None:
profiles = list(
filter(
lambda p: p.display_name() == text,
self._data.reach.profiles
)
)
value = profiles[0].rk if len(profiles) > 0 else None
else:
value = text
model.setData(index, value)
editor.close()
@@ -293,3 +296,44 @@ class TableModel(PamhyrTableModel):
self.endMoveRows()
self.layoutChanged.emit()
def read_from_lat(self, file_name):
logger.debug(f"Import lateral contributions from {file_name}")
data = []
current_reach = -1
with open(file_name, encoding="utf-8") as lat_file:
for line in lat_file:
if not (line.startswith("#") or
line.startswith("*") or
len(line) < 1):
line = line.split()
if line[0] == "$":
current_reach = int(line[1]) - 1
if (current_reach <= len(self._data.enable_edges()) and
current_reach >= 0):
data.append(
[self._data.enable_edges()[current_reach],
float(line[2]),
float(line[3])
]
)
else:
if (current_reach <= len(self._data.enable_edges()) and
current_reach >= 0):
data[-1].append(
[
old_pamhyr_date_to_timestamp(line[0]),
float(line[1])
]
)
self.layoutAboutToBeChanged.emit()
self._undo.push(
ImportCommand(
self._lst, self._tab, data
)
)
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()
+57 -16
View File
@@ -28,6 +28,10 @@ from Model.LateralContribution.LateralContributionList import (
LateralContributionList
)
from Model.LateralContribution.LateralContributionTypes import (
NotDefined, LateralContrib,
)
class SetNameCommand(QUndoCommand):
def __init__(self, lcs, tab, index, new_value):
@@ -143,13 +147,13 @@ class DelCommand(QUndoCommand):
self._tab = tab
self._rows = rows
self._bc = []
self._lc = []
for row in rows:
self._bc.append((row, self._lcs.get(self._tab, row)))
self._bc.sort()
self._lc.append((row, self._lcs.get(self._tab, row)))
self._lc.sort()
def undo(self):
for row, el in self._bc:
for row, el in self._lc:
self._lcs.insert(self._tab, row, el)
def redo(self):
@@ -213,36 +217,73 @@ class MoveCommand(QUndoCommand):
class PasteCommand(QUndoCommand):
def __init__(self, lcs, tab, row, bc):
def __init__(self, lcs, tab, row, lc):
QUndoCommand.__init__(self)
self._lcs = lcs
self._tab = tab
self._row = row
self._bc = deepcopy(bc)
self._bc.reverse()
self._lc = deepcopy(lc)
self._lc.reverse()
def undo(self):
self._lcs.delete(self._tab, self._bc)
self._lcs.delete(self._tab, self._lc)
def redo(self):
for bc in self._bc:
self._lcs.insert(self._tab, self._row, bc)
for lc in self._lc:
self._lcs.insert(self._tab, self._row, lc)
class ImportCommand(QUndoCommand):
def __init__(self, lcs, tab, data):
QUndoCommand.__init__(self)
self._tab = tab
self._lcs = lcs
self._data = data
self._old_rows = list(range(len(self._lcs.get_tab(self._tab))))
self._new_rows = list(range(len(self._data)))
self._new_lc = None
self._old_lc = []
for row in self._old_rows:
self._old_lc.append((row, self._lcs.get(self._tab, row)))
def undo(self):
self._lcs.delete_i(self._tab, self._new_rows)
for row, el in self._old_lc:
self._lcs.insert(self._tab, row, el)
def redo(self):
self._lcs.delete_i(self._tab, self._old_rows)
if self._new_lc is None:
self._new_lc = []
for row, data in enumerate(self._data):
new = LateralContrib(status=self._lcs._status)
new.edge = data[0]
new.begin_rk = data[1]
new.end_rk = data[2]
for i, val in enumerate(data[3:]):
new.insert(i, val)
self._new_lc.append(new)
for row, el in enumerate(self._new_lc):
self._lcs.insert(self._tab, row, el)
class DuplicateCommand(QUndoCommand):
def __init__(self, lcs, tab, rows, bc):
def __init__(self, lcs, tab, rows, lc):
QUndoCommand.__init__(self)
self._lcs = lcs
self._tab = tab
self._rows = rows
self._bc = deepcopy(bc)
self._bc.reverse()
self._lc = deepcopy(lc)
self._lc.reverse()
def undo(self):
self._lcs.delete(self._tab, self._bc)
self._lcs.delete(self._tab, self._lc)
def redo(self):
for bc in self._lcs:
self._lcs.insert(self._tab, self._rows[0], bc)
for lc in self._lcs:
self._lcs.insert(self._tab, self._rows[0], lc)
+27 -1
View File
@@ -22,6 +22,7 @@ from tools import trace, timer
from View.Tools.PamhyrWindow import PamhyrWindow
from PyQt5 import QtWidgets
from PyQt5.QtGui import (
QKeySequence,
)
@@ -29,7 +30,7 @@ from PyQt5.QtGui import (
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QRect,
QRect, QSettings,
)
from PyQt5.QtWidgets import (
@@ -153,6 +154,8 @@ class LateralContributionWindow(PamhyrWindow):
)
def setup_connections(self):
self.find(QAction, "action_import").triggered.connect(
self.import_from_file)
self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_edit").triggered.connect(self.edit)
@@ -297,3 +300,26 @@ class LateralContributionWindow(PamhyrWindow):
parent=self
)
win.show()
def import_from_file(self):
options = QFileDialog.Options()
settings = QSettings(QSettings.IniFormat,
QSettings.UserScope, 'MyOrg', )
options |= QFileDialog.DontUseNativeDialog
file_types = [
self._trad["file_lat"],
self._trad["file_all"],
]
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
self,
self._trad["open_file"],
"",
";; ".join(file_types),
options=options
)
if filename != "":
tab = self.current_tab()
self._table[tab].read_from_lat(filename)
@@ -52,6 +52,10 @@ class LCTranslate(MainTranslate):
self._dict["x"] = _translate("Geometry", "X (m)")
self._dict["y"] = _translate("Geometry", "Y (m)")
self._dict["z"] = _translate("Geometry", "Z (m)")
self._dict["file_lat"] = _translate(
"LateralContribution", "Shapefile (*.LAT *.lat)")
self._dict["file_all"] = _translate(
"LateralContribution", "All files (*)")
self._sub_dict["table_headers"] = {
"name": self._dict["name"],
+8
View File
@@ -23,6 +23,8 @@ from numpy import sqrt
from tools import timer, trace
from itertools import compress
from PyQt5.QtGui import (
QKeySequence, QColor
)
@@ -51,8 +53,12 @@ class TableModel(PamhyrTableModel):
self._lst = _river.reachs
elif self._opt_data == "profile":
self._lst = _river.reach(0).profiles
# self._lst = list(filter(lambda x: x.name[0:8] != 'interpol',
# _river.reach(0).profiles))
elif self._opt_data == "raw_data":
self._lst = _river.reach(0).profiles
# self._lst = list(filter(lambda x: x.name[0:8] != 'interpol',
# _river.reach(0).profiles))
elif self._opt_data == "solver":
self._lst = self._parent._solvers
@@ -151,6 +157,8 @@ class TableModel(PamhyrTableModel):
self._lst = _river.reachs
elif self._opt_data == "profile" or self._opt_data == "raw_data":
self._lst = _river.reach(reach).profiles
# self._lst = list(compress(_river.reach(reach).profiles,
# _river.reach(reach).profile_mask))
elif self._opt_data == "solver":
self._lst = self._parent._solvers
+49 -46
View File
@@ -19,7 +19,7 @@
import os
import csv
import logging
import rasterio
# import rasterio
from numpy import sqrt
@@ -338,6 +338,8 @@ class ResultsWindow(PamhyrWindow):
# "action_export": self.export_current,
"action_Geo_tiff": self.import_geotiff
}
self.find(QAction, "action_Geo_tiff").setEnabled(False)
self.find(QAction, "action_Geo_tiff").setVisible(False)
if len(self._results) > 1:
self.find(QAction, "action_reload").setEnabled(False)
@@ -494,7 +496,7 @@ class ResultsWindow(PamhyrWindow):
table = self.find(QTableView, f"tableView_profile")
indexes = table.selectedIndexes()
if len(indexes) == 0:
return 0
return []
return [i.row() for i in indexes]
@@ -1166,47 +1168,48 @@ class ResultsWindow(PamhyrWindow):
self.update_table_selection_profile(profile_id)
def import_geotiff(self):
options = QFileDialog.Options()
settings = QSettings(QSettings.IniFormat,
QSettings.UserScope, 'MyOrg', )
options |= QFileDialog.DontUseNativeDialog
file_types = [
self._trad["file_geotiff"],
self._trad["file_all"],
]
filename, _ = QFileDialog.getOpenFileName(
self,
self._trad["open_file"],
"",
";; ".join(file_types),
options=options
)
if filename != "":
with rasterio.open(filename) as data:
img = data.read()
b = data.bounds[:]
# b[0] left
# b[1] bottom
# b[2] right
# b[3] top
xlim = self.canvas.axes.get_xlim()
ylim = self.canvas.axes.get_ylim()
if b[2] > b[0] and b[1] < b[3]:
self.canvas.axes.imshow(img.transpose((1, 2, 0)),
extent=[b[0], b[2], b[1], b[3]])
else:
dlg = CoordinatesDialog(
xlim,
ylim,
trad=self._trad,
parent=self
)
if dlg.exec():
self.canvas.axes.imshow(img.transpose((1, 2, 0)),
extent=dlg.values)
self.plot_xy.idle()
self.canvas.axes.set_xlim(xlim)
self.canvas.axes.set_ylim(ylim)
# options = QFileDialog.Options()
# settings = QSettings(QSettings.IniFormat,
# QSettings.UserScope, 'MyOrg', )
# options |= QFileDialog.DontUseNativeDialog
#
# file_types = [
# self._trad["file_geotiff"],
# self._trad["file_all"],
# ]
#
# filename, _ = QFileDialog.getOpenFileName(
# self,
# self._trad["open_file"],
# "",
# ";; ".join(file_types),
# options=options
# )
#
# if filename != "":
# with rasterio.open(filename) as data:
# img = data.read()
# b = data.bounds[:]
# # b[0] left
# # b[1] bottom
# # b[2] right
# # b[3] top
# xlim = self.canvas.axes.get_xlim()
# ylim = self.canvas.axes.get_ylim()
# if b[2] > b[0] and b[1] < b[3]:
# self.canvas.axes.imshow(img.transpose((1, 2, 0)),
# extent=[b[0], b[2], b[1], b[3]])
# else:
# dlg = CoordinatesDialog(
# xlim,
# ylim,
# trad=self._trad,
# parent=self
# )
# if dlg.exec():
# self.canvas.axes.imshow(img.transpose((1, 2, 0)),
# extent=dlg.values)
# self.plot_xy.idle()
# self.canvas.axes.set_xlim(xlim)
# self.canvas.axes.set_ylim(ylim)
return
+13
View File
@@ -70,6 +70,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_import"/>
<addaction name="action_add"/>
<addaction name="action_del"/>
<addaction name="action_sort"/>
@@ -149,6 +150,18 @@
<string>Remove points to make the curve increasing</string>
</property>
</action>
<action name="action_import">
<property name="icon">
<iconset>
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip">
<string>Import from file</string>
</property>
</action>
</widget>
<resources/>
<connections/>
+12
View File
@@ -112,6 +112,18 @@
<string>Sort points</string>
</property>
</action>
<action name="action_import">
<property name="icon">
<iconset>
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip">
<string>Import from file</string>
</property>
</action>
</widget>
<resources/>
<connections/>
+13
View File
@@ -60,6 +60,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_import"/>
<addaction name="action_add"/>
<addaction name="action_del"/>
<addaction name="action_sort"/>
@@ -107,6 +108,18 @@
<string>Ctrl+E</string>
</property>
</action>
<action name="action_import">
<property name="icon">
<iconset>
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip">
<string>Import from file</string>
</property>
</action>
</widget>
<resources/>
<connections/>
+13
View File
@@ -97,6 +97,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_import"/>
<addaction name="action_add"/>
<addaction name="action_del"/>
<addaction name="action_edit"/>
@@ -162,6 +163,18 @@
<string>Sort by names</string>
</property>
</action>
<action name="action_import">
<property name="icon">
<iconset>
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip">
<string>Import from file</string>
</property>
</action>
</widget>
<resources/>
<connections/>
+13 -53
View File
@@ -7,24 +7,14 @@
<x>0</x>
<y>0</y>
<width>520</width>
<height>341</height>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Parameters</string>
@@ -79,7 +69,7 @@
<string>Spline</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@@ -88,6 +78,9 @@
<property name="text">
<string>Linear</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@@ -108,47 +101,14 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Guideline used for distance computation</string>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Second guideline</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>First guideline</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_end_gl">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_begin_gl">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">