This commit is contained in:
Theophile Terraz committed 2025-01-09 13:47:26 +01:00
commit 8d9a196059
123 files changed
+15495 -187

No files matched your search

+264 -6
View File
@@ -23,7 +23,12 @@ import logging
import subprocess
from queue import Queue
from functools import reduce
from time import process_time_ns
from numpy.core.multiarray import where
from platformdirs import user_cache_dir
from Solver.AdisTS import AdisTS
from tools import logger_exception
from PyQt5 import QtGui
@@ -39,6 +44,7 @@ from PyQt5.QtWidgets import (
QMainWindow, QApplication, QAction,
QFileDialog, QShortcut, QMenu, QToolBar,
QMessageBox, QProgressDialog, QTabWidget,
QDialog, QVBoxLayout, QLabel,
)
from PyQt5.uic import loadUi
@@ -75,10 +81,20 @@ from View.RunSolver.Window import (
SolverLogWindow,
CompareSolversWindow
)
from View.CheckList.Window import CheckListWindow
from View.Results.Window import ResultsWindow, CompareResultsWindow
from View.RunSolver.WindowAdisTS import (
SelectSolverWindowAdisTS,
SolverLogWindowAdisTS
)
from View.CheckList.Window import CheckListWindow
from View.CheckList.WindowAdisTS import CheckListWindowAdisTS
from View.Results.WindowAdisTS import ResultsWindowAdisTS
from View.Results.ReadingResultsDialog import ReadingResultsDialog
from View.Debug.Window import ReplWindow
from View.OutputRKAdisTS.Window import OutputRKAdisTSWindow
from View.Pollutants.Window import PollutantsWindow
from View.D90AdisTS.Window import D90AdisTSWindow
from View.DIFAdisTS.Window import DIFAdisTSWindow
from Solver.Solvers import GenericSolver
@@ -105,6 +121,7 @@ model_action = [
"action_menu_close", "action_menu_edit", "action_menu_save",
"action_menu_save_as", "action_toolBar_close", "action_toolBar_save",
"action_menu_numerical_parameter", "action_open_results_from_file",
"action_open_results_adists",
]
other_model_action = [
@@ -126,7 +143,9 @@ define_model_action = [
"action_menu_edit_hydraulic_structures", "action_menu_additional_file",
"action_menu_results_last", "action_open_results_from_file",
"action_compare_results", "action_menu_boundary_conditions_sediment",
"action_menu_rep_additional_lines",
"action_menu_rep_additional_lines", "action_menu_output_rk",
"action_menu_run_adists", "action_menu_pollutants",
"action_menu_d90", "action_menu_dif",
]
action = (
@@ -236,6 +255,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
"""
actions = {
# Menu action
"action_menu_dif": self.open_dif,
"action_menu_d90": self.open_d90,
"action_menu_pollutants": self.open_pollutants,
"action_menu_run_adists": self.select_run_solver_adists,
"action_menu_output_rk": self.open_output_rk_adists,
"action_menu_config": self.open_configure,
"action_menu_new": self.open_new_study,
"action_menu_edit": self.open_edit_study,
@@ -264,6 +288,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
"action_menu_results_last": self.open_last_results,
"action_open_results_from_file": self.open_results_from_file,
"action_compare_results": self.compare_results,
"action_open_results_adists": self.open_results_adists,
# Help
"action_menu_pamhyr_users_wiki": self.open_doc_user,
"action_menu_pamhyr_developers_pdf":
@@ -769,14 +794,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
dlg.setWindowTitle(self._trad["mb_last_open_title"])
dlg.setText(self._trad["mb_last_open_msg"])
opt = QMessageBox.Cancel | QMessageBox.Ok # | QMessageBox.Open
opt = QMessageBox.No | QMessageBox.Yes # | QMessageBox.Open
dlg.setStandardButtons(opt)
dlg.setIcon(QMessageBox.Question)
dlg.button(QMessageBox.Yes).setText(self._trad["Yes"])
dlg.button(QMessageBox.No).setText(self._trad["No"])
res = dlg.exec()
if res == QMessageBox.Ok:
if res == QMessageBox.Yes:
old = self.conf.last_study
file = self.dialog_reopen_study_select_backup(
self.conf.last_study
@@ -789,7 +816,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
elif res == QMessageBox.Open:
self.open_model()
return True
elif res == QMessageBox.Cancel:
elif res == QMessageBox.No:
return False
def dialog_reopen_study_select_backup(self, filename):
@@ -816,6 +843,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
dlg.setStandardButtons(opt)
dlg.setIcon(QMessageBox.Warning)
dlg.button(QMessageBox.Save).setText(self._trad["Save"])
dlg.button(QMessageBox.Close).setText(self._trad["Close"])
if cancel:
dlg.button(QMessageBox.Cancel).setText(self._trad["Cancel"])
res = dlg.exec()
@@ -890,6 +921,70 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
# SUB WINDOWS #
###############
def open_d90(self):
if len(self._study.river.d90_adists.lst) != 0:
d90_default = self._study.river.d90_adists.lst[0]
else:
d90_default = self._study.river.d90_adists.new(0)
if self.sub_window_exists(
D90AdisTSWindow,
data=[self._study, None, d90_default]
):
return
D90AdisTS = D90AdisTSWindow(
study=self._study,
parent=self,
data=d90_default
)
D90AdisTS.show()
def open_dif(self):
if len(self._study.river.dif_adists.lst) != 0:
dif_default = self._study.river.dif_adists.lst[0]
else:
dif_default = self._study.river.dif_adists.new(0)
if self.sub_window_exists(
DIFAdisTSWindow,
data=[self._study, None, dif_default]
):
return
DIFAdisTS = DIFAdisTSWindow(
study=self._study,
parent=self,
data=dif_default
)
DIFAdisTS.show()
def open_pollutants(self):
if self.sub_window_exists(
PollutantsWindow,
data=[self._study, None]
):
return
Pollutants = PollutantsWindow(
study=self._study,
parent=self
)
Pollutants.show()
def open_output_rk_adists(self):
if self.sub_window_exists(
OutputRKAdisTSWindow,
data=[self._study, None]
):
return
Output_RK_AdisTS = OutputRKAdisTSWindow(
study=self._study,
parent=self
)
Output_RK_AdisTS.show()
def open_configure(self):
"""Open configure window
@@ -1215,6 +1310,49 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if run.exec():
self.run_solver(run.solver)
def select_run_solver_adists(self):
if self._study is None:
return
# solver = next(filter(lambda x: x._type == "adistswc",
# self.conf.solvers))
# solver = next(filter(lambda x: x.name == "AdisTS-WC",
# self.conf.solvers))
# print(solver._type)
# self.run_solver(solver)
run = SelectSolverWindowAdisTS(
study=self._study,
config=self.conf,
parent=self
)
if run.exec():
self.run_solver_adists(run.solver, run.mage_rep)
def run_solver_adists(self, solver, mage_rep):
if self._study is None:
return
if self.sub_window_exists(
CheckListWindowAdisTS,
data=[
self._study,
self.conf,
solver,
mage_rep
]
):
return
check = CheckListWindowAdisTS(
study=self._study,
config=self.conf,
solver=solver,
parent=self,
mage_rep=mage_rep,
)
check.show()
def run_solver(self, solver):
if self._study is None:
return
@@ -1237,6 +1375,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
check.show()
def solver_log_adists(self, solver, mage_rep):
sol = SolverLogWindowAdisTS(
study=self._study,
config=self.conf,
solver=solver,
parent=self,
mage_rep=mage_rep,
)
sol.show()
def solver_log(self, solver):
sol = SolverLogWindow(
study=self._study,
@@ -1303,6 +1451,63 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
res.show()
def open_solver_results_adists(self, solver, results=None):
def reading_fn():
self._tmp_results = results
# If no specific results, get last results
if results is None:
def reading_fn():
self._tmp_results = self._last_results
if self._last_results is None:
def reading_fn():
self._tmp_results = solver.results(
self._study,
self._solver_workdir(solver),
)
# Open from file
if type(results) is str:
logger.info(f"Open results from {os.path.dirname(results)}")
name = os.path.basename(results).replace(".BIN", "")
def reading_fn():
self._tmp_results = solver.results(
self._study,
os.path.dirname(results),
name=name
)
dlg = ReadingResultsDialog(reading_fn=reading_fn, parent=self)
dlg.exec_()
results = self._tmp_results
# No results available
if results is None:
return
# Windows already opened
if self.sub_window_exists(
ResultsWindowAdisTS,
data=[
self._study,
None, # No config
solver,
results
]
):
return
res = ResultsWindowAdisTS(
study=self._study,
solver=solver,
results=results,
parent=self
)
res.show()
def _solver_workdir(self, solver):
workdir = os.path.join(
os.path.dirname(self._study.filename),
@@ -1317,7 +1522,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if self._last_solver is None:
return
self.open_solver_results(self._last_solver, self._last_results)
if self._last_solver._type == "mage8":
self.open_solver_results(self._last_solver,
self._last_results)
elif self._last_solver._type == "adistswc":
self.open_solver_results_adists(self._last_solver,
self._last_results)
def open_results_from_file(self):
if self._study is None:
@@ -1450,6 +1660,54 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
return result3
def open_results_adists(self):
if self._study is None:
return
if self._study.filename == "":
return
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
dialog = QFileDialog(self, options=options)
dialog.setFileMode(QFileDialog.DirectoryOnly)
# QFileDialog.FileMode.ExistingFile)
if self._last_solver is None:
dialog.setDirectory(
os.path.dirname(self._study.filename)
)
else:
dialog.setDirectory(
self._solver_workdir(self._last_solver)
)
if dialog.exec_():
dir_path = dialog.selectedFiles()[0]
dir_list = os.listdir(dir_path)
bin_list = list(filter(lambda s: "bin" in s, dir_list))
solver_name = dir_path.split("/")[-2]
solver_results = next(filter(lambda x: x.name == solver_name,
self.conf.solvers))
solver_results_adists = solver_results.results(
self._study,
repertory=dir_path[:-10], qlog=None) # self._output)
logger.info(f"Select results: {dir_path}")
if len(bin_list) >= 2 and ("total_sediment.bin" in bin_list):
self.open_solver_results_adists(
solver_results,
results=solver_results_adists,
)
else:
dlg = QDialog(self)
dlg.setWindowTitle("AdisTS Results")
layout = QVBoxLayout()
message = QLabel("AdisTS Results not found")
layout.addWidget(message)
dlg.setLayout(layout)
dlg.exec()
#################
# DOCUMENTATION #
#################