Compare commits

...

3 Commits

10 changed files with 181 additions and 68 deletions

View File

@ -232,6 +232,8 @@ class BoundaryCondition(SQLSubModel):
type TEXT NOT NULL, type TEXT NOT NULL,
tab TEXT NOT NULL, tab TEXT NOT NULL,
node INTEGER, node INTEGER,
d50 REAL DEFAULT 0.002,
sigma REAL DEFAULT 1,
{Scenario.create_db_add_scenario()}, {Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()}, {Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id), FOREIGN KEY(node) REFERENCES river_node(pamhyr_id),
@ -258,6 +260,17 @@ class BoundaryCondition(SQLSubModel):
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE" "ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
) )
if major == "0" and int(minor) <= 2:
if int(release) < 4:
execute(
"ALTER TABLE boundary_condition " +
"ADD COLUMN d50 REAL DEFAULT 0.002"
)
execute(
"ALTER TABLE boundary_condition " +
"ADD COLUMN sigma REAL DEFAULT 1"
)
return cls._update_submodel(execute, version, data) return cls._update_submodel(execute, version, data)
@classmethod @classmethod
@ -316,7 +329,7 @@ class BoundaryCondition(SQLSubModel):
return new return new
table = execute( table = execute(
"SELECT pamhyr_id, deleted, name, type, node, scenario " + "SELECT pamhyr_id, deleted, name, type, node, d50, sigma, scenario " +
"FROM boundary_condition " + "FROM boundary_condition " +
f"WHERE tab = '{tab}' " + f"WHERE tab = '{tab}' " +
f"AND scenario = {scenario.id} " + f"AND scenario = {scenario.id} " +
@ -331,6 +344,8 @@ class BoundaryCondition(SQLSubModel):
name = next(it) name = next(it)
t = next(it) t = next(it)
node = next(it) node = next(it)
d50 = next(it)
sigma = next(it)
owner_scenario = next(it) owner_scenario = next(it)
ctor = cls._get_ctor_from_type(t) ctor = cls._get_ctor_from_type(t)
@ -342,7 +357,9 @@ class BoundaryCondition(SQLSubModel):
) )
if deleted: if deleted:
bc.set_as_deleted() bc.set_as_deleted()
if t=="SL":
bc.d50 = d50
bc.sigma = sigma
bc.node = None bc.node = None
if node != -1: if node != -1:
bc.node = next(filter(lambda n: n.id == node, nodes), None) bc.node = next(filter(lambda n: n.id == node, nodes), None)
@ -375,15 +392,22 @@ class BoundaryCondition(SQLSubModel):
if self._node is not None: if self._node is not None:
node = self._node.id node = self._node.id
d50 = 0.002
sigma = 1
if self._type == "SL":
d50 = self._d50
sigma = self._sigma
execute( execute(
"INSERT INTO " + "INSERT INTO " +
"boundary_condition(" + "boundary_condition(" +
"pamhyr_id, deleted, name, type, tab, node, scenario" + "pamhyr_id, deleted, name, type, tab, node, d50, sigma, scenario" +
") " + ") " +
"VALUES (" + "VALUES (" +
f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " + f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " +
f"'{self._db_format(self._name)}', " + f"'{self._db_format(self._name)}', " +
f"'{self._db_format(self._type)}', '{tab}', {node}, " + f"'{self._db_format(self._type)}', '{tab}', {node}, " +
f"{d50}, {sigma}, " +
f"{self._status.scenario_id}" + f"{self._status.scenario_id}" +
")" ")"
) )
@ -468,6 +492,24 @@ class BoundaryCondition(SQLSubModel):
def has_node(self): def has_node(self):
return self._node is not None return self._node is not None
@property
def d50(self):
return self._d50
@d50.setter
def d50(self, value):
self._d50 = float(value)
self.modified()
@property
def sigma(self):
return self._sigma
@sigma.setter
def sigma(self, value):
self._sigma = float(value)
self.modified()
@property @property
def header(self): def header(self):
return self._header.copy() return self._header.copy()

View File

@ -312,6 +312,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
status = data['status'] status = data['status']
nodes = data['nodes'] nodes = data['nodes']
scenario = data["scenario"] scenario = data["scenario"]
pollutant = data["pollutant"]
loaded = data['loaded_pid'] loaded = data['loaded_pid']
if scenario is None: if scenario is None:
@ -321,7 +322,8 @@ class BoundaryConditionAdisTS(SQLSubModel):
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario " + "SELECT pamhyr_id, deleted, pollutant, type, node, scenario " +
"FROM boundary_condition_adists " + "FROM boundary_condition_adists " +
f"WHERE scenario = {scenario.id} " + f"WHERE scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
f"AND pollutant = {pollutant.id} "
) )
if table is not None: if table is not None:

View File

@ -28,6 +28,7 @@ from tools import (
from Model.Tools.PamhyrDB import SQLSubModel from Model.Tools.PamhyrDB import SQLSubModel
from Model.Except import NotImplementedMethodeError from Model.Except import NotImplementedMethodeError
from Model.Scenario import Scenario from Model.Scenario import Scenario
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
logger = logging.getLogger() logger = logging.getLogger()
@ -275,7 +276,8 @@ class PollutantCharacteristics(SQLSubModel):
class Pollutants(SQLSubModel): class Pollutants(SQLSubModel):
_sub_classes = [PollutantCharacteristics] _sub_classes = [PollutantCharacteristics,
BoundaryConditionAdisTS]
def __init__(self, id: int = -1, name: str = "", def __init__(self, id: int = -1, name: str = "",
status=None, owner_scenario=-1): status=None, owner_scenario=-1):
@ -293,6 +295,11 @@ class Pollutants(SQLSubModel):
self._enabled = True self._enabled = True
self._data = [] self._data = []
self._boundary_conditions_adists = []
@property
def boundary_conditions_adists(self):
return self._boundary_conditions_adists
@property @property
def name(self): def name(self):
@ -416,6 +423,10 @@ class Pollutants(SQLSubModel):
execute, data=data execute, data=data
) )
new_pollutant._boundary_conditions_adists = BoundaryConditionAdisTS._db_load(
execute, data=data
)
loaded.add(pid) loaded.add(pid)
new.append(new_pollutant) new.append(new_pollutant)
@ -455,6 +466,9 @@ class Pollutants(SQLSubModel):
for d in self._data: for d in self._data:
ok &= d._db_save(execute, data) ok &= d._db_save(execute, data)
for bc in self._boundary_conditions_adists:
ok &= bc._db_save(execute, data)
return ok return ok
def _data_traversal(self, def _data_traversal(self,

View File

@ -37,7 +37,7 @@ logger = logging.getLogger()
class Study(SQLModel): class Study(SQLModel):
_version = "0.2.3" _version = "0.2.4"
_sub_classes = [ _sub_classes = [
Scenario, Scenario,

View File

@ -112,18 +112,21 @@ class ComboBoxDelegate(QItemDelegate):
class TableModel(PamhyrTableModel): class TableModel(PamhyrTableModel):
def __init__(self, pollutant=None, bc_list=None, trad=None, **kwargs): def __init__(self, bc_list=None, pollutant_bc_list=None, trad=None, **kwargs):
self._trad = trad self._trad = trad
self._bc_list = bc_list self._bc_list = bc_list
self._pollutant = pollutant self._pollutant = pollutant_bc_list.id
self._pollutant_bc_list = pollutant_bc_list
super(TableModel, self).__init__(trad=trad, **kwargs) super(TableModel, self).__init__(trad=trad, **kwargs)
def _setup_lst(self):
self._lst = self._pollutant_bc_list.boundary_conditions_adists
def rowCount(self, parent): def rowCount(self, parent):
return len(self._bc_list) return len(self._lst)
def data(self, index, role): def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole: if role != Qt.ItemDataRole.DisplayRole:
return QVariant() return QVariant()
@ -131,12 +134,12 @@ class TableModel(PamhyrTableModel):
column = index.column() column = index.column()
if self._headers[column] == "type": if self._headers[column] == "type":
n = self._bc_list.get(row).type n = self._lst[row].type
if n is None or n == "": if n is None or n == "":
return self._trad["not_associated"] return self._trad["not_associated"]
return n return n
elif self._headers[column] == "node": elif self._headers[column] == "node":
n = self._bc_list.get(row).node n = self._lst[row].node
if n is None: if n is None:
return self._trad["not_associated"] return self._trad["not_associated"]
tmp = next(filter(lambda x: x.id == n, self._data._nodes), None) tmp = next(filter(lambda x: x.id == n, self._data._nodes), None)
@ -144,18 +147,6 @@ class TableModel(PamhyrTableModel):
return tmp.name return tmp.name
else: else:
return self._trad["not_associated"] return self._trad["not_associated"]
elif self._headers[column] == "pol":
n = self._bc_list.get(row).pollutant
if n is None or n == "not_associated" or n == "":
return self._trad["not_associated"]
tmp = next(filter(lambda x: x.id == n,
self._data._Pollutants.Pollutants_List
),
None)
if tmp is not None:
return tmp.name
else:
return self._trad["not_associated"]
return QVariant() return QVariant()
@ -179,22 +170,7 @@ class TableModel(PamhyrTableModel):
self._bc_list, row, self._data.node(value) self._bc_list, row, self._data.node(value)
) )
) )
elif self._headers[column] == "pol":
if value == self._trad["not_associated"]:
self._undo.push(
SetPolCommand(
self._bc_list, row, None
)
)
else:
pol = next(filter(lambda x: x.name == value,
self._data._Pollutants.Pollutants_List)
)
self._undo.push(
SetPolCommand(
self._bc_list, row, pol.id
)
)
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())

View File

@ -58,11 +58,21 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
_pamhyr_ui = "BoundaryConditionsAdisTS" _pamhyr_ui = "BoundaryConditionsAdisTS"
_pamhyr_name = "Boundary conditions AdisTS" _pamhyr_name = "Boundary conditions AdisTS"
def __init__(self, study=None, config=None, parent=None): def __init__(self, data=None, pollutant_id=None, study=None, config=None, parent=None):
self._data = data
self._pollutant_id = pollutant_id
_pollutants_lst = study._river._Pollutants.Pollutants_List
self._pollutant_name = next(
(x.name for x in _pollutants_lst if x.id == self._pollutant_id),
None
)
trad = BCAdisTSTranslate() trad = BCAdisTSTranslate()
name = ( name = (
trad[self._pamhyr_name] + trad[self._pamhyr_name] +
" - " + study.name " - " + study.name +
" - " + self._pollutant_name
) )
super(BoundaryConditionAdisTSWindow, self).__init__( super(BoundaryConditionAdisTSWindow, self).__init__(
@ -73,7 +83,6 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
parent=parent parent=parent
) )
self._pollutants_lst = self._study._river._Pollutants
self._bcs = self._study.river.boundary_conditions_adists self._bcs = self._study.river.boundary_conditions_adists
self.setup_graph() self.setup_graph()
@ -95,12 +104,6 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
mode="node", mode="node",
parent=self parent=self
) )
self._delegate_pol = ComboBoxDelegate(
trad=self._trad,
data=self._study.river,
mode="pol",
parent=self
)
table = self.find(QTableView, f"tableView") table = self.find(QTableView, f"tableView")
self._table = TableModel( self._table = TableModel(
@ -110,10 +113,10 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
delegates={ delegates={
"type": self._delegate_type, "type": self._delegate_type,
"node": self._delegate_node, "node": self._delegate_node,
"pol": self._delegate_pol,
}, },
trad=self._trad, trad=self._trad,
bc_list=self._study.river.boundary_conditions_adists, bc_list=self._study.river.boundary_conditions_adists,
pollutant_bc_list=self._data,
undo=self._undo_stack, undo=self._undo_stack,
data=self._study.river data=self._study.river
) )
@ -156,7 +159,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
) )
def add(self): def add(self):
self._table.add(len(self._bcs)) self._table.add(len(self._data.boundary_conditions_adists))
def delete(self): def delete(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()

View File

@ -34,5 +34,4 @@ class BCAdisTSTranslate(MainTranslate):
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"type": self._dict["type"], "type": self._dict["type"],
"node": _translate("BoundaryCondition", "Node"), "node": _translate("BoundaryCondition", "Node"),
"pol": _translate("BoundaryCondition", "Pollutant")
} }

View File

@ -17,7 +17,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from View.Tools.PamhyrWindow import PamhyrDialog from View.Tools.PamhyrWindow import PamhyrDialog
from PyQt5.QtWidgets import QDoubleSpinBox
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
class ShiftDialog(PamhyrDialog): class ShiftDialog(PamhyrDialog):
_pamhyr_ui = "GeometryReachShift" _pamhyr_ui = "GeometryReachShift"
@ -31,8 +32,36 @@ class ShiftDialog(PamhyrDialog):
parent=parent parent=parent
) )
self._replace_spinboxes()
self._init_default_values() self._init_default_values()
def _replace_spinboxes(self):
for name in ["doubleSpinBox_X", "doubleSpinBox_Y", "doubleSpinBox_Z"]:
old = self.find(QDoubleSpinBox, name)
if old is None:
continue
new = FlexibleDoubleSpinBox(old.parent())
new.setObjectName(old.objectName())
# Copier propriétés utiles
new.setDecimals(old.decimals())
new.setMinimum(old.minimum())
new.setMaximum(old.maximum())
new.setSingleStep(old.singleStep())
new.setValue(old.value())
new.setGeometry(old.geometry())
# Remplacement dans layout si présent
layout = old.parent().layout()
if layout is not None:
layout.replaceWidget(old, new)
old.hide()
old.setParent(None)
old.deleteLater()
def _init_default_values(self): def _init_default_values(self):
self._dx = 0.0 self._dx = 0.0
self._dy = 0.0 self._dy = 0.0

View File

@ -222,19 +222,30 @@ class PollutantsWindow(PamhyrWindow):
initial.show() initial.show()
def boundary_conditions(self): def boundary_conditions(self):
rows = self.index_selected_rows()
if len(rows) == 0:
return
for row in rows:
pollutant_id = self._pollutants_lst.get(row).id
bclist = self._study.river.boundary_conditions_adists.BCs_AdisTS_List
bcs_adists = [
x for x in bclist
if x.pollutant == pollutant_id
]
self._data = self._study.river.Pollutants.get(row)
if self.sub_window_exists( if self.sub_window_exists(
BoundaryConditionAdisTSWindow, BoundaryConditionAdisTSWindow,
data=[self._study, None] data=[self._study, None, bcs_adists]
): ):
bound = self.get_sub_window(
BoundaryConditionAdisTSWindow,
data=[self._study, None]
)
return return
bound = BoundaryConditionAdisTSWindow( bound = BoundaryConditionAdisTSWindow(
study=self._study, parent=self study=self._study,
parent=self,
data=self._data,
pollutant_id=pollutant_id
) )
bound.show() bound.show()

View File

@ -0,0 +1,37 @@
# PamhyrWindow.py -- Pamhyr
# Copyright (C) 2023-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 os
import logging
from PyQt5.QtWidgets import QDoubleSpinBox
class FlexibleDoubleSpinBox(QDoubleSpinBox):
def keyPressEvent(self, event):
if event.text() == ".":
# Simule une virgule à la place du point
event = type(event)(
event.type(),
event.key(),
event.modifiers(),
","
)
super().keyPressEvent(event)