Compare commits

..

No commits in common. "c2d28b011015757802e55d931b7b2eb071c2d1c8" and "4f6e8249e00be9d96ad460680e3aaa6f5f16db0e" have entirely different histories.

10 changed files with 68 additions and 181 deletions

View File

@ -232,8 +232,6 @@ class BoundaryCondition(SQLSubModel):
type TEXT NOT NULL,
tab TEXT NOT NULL,
node INTEGER,
d50 REAL DEFAULT 0.002,
sigma REAL DEFAULT 1,
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id),
@ -260,17 +258,6 @@ class BoundaryCondition(SQLSubModel):
"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)
@classmethod
@ -329,7 +316,7 @@ class BoundaryCondition(SQLSubModel):
return new
table = execute(
"SELECT pamhyr_id, deleted, name, type, node, d50, sigma, scenario " +
"SELECT pamhyr_id, deleted, name, type, node, scenario " +
"FROM boundary_condition " +
f"WHERE tab = '{tab}' " +
f"AND scenario = {scenario.id} " +
@ -344,8 +331,6 @@ class BoundaryCondition(SQLSubModel):
name = next(it)
t = next(it)
node = next(it)
d50 = next(it)
sigma = next(it)
owner_scenario = next(it)
ctor = cls._get_ctor_from_type(t)
@ -357,9 +342,7 @@ class BoundaryCondition(SQLSubModel):
)
if deleted:
bc.set_as_deleted()
if t=="SL":
bc.d50 = d50
bc.sigma = sigma
bc.node = None
if node != -1:
bc.node = next(filter(lambda n: n.id == node, nodes), None)
@ -391,23 +374,16 @@ class BoundaryCondition(SQLSubModel):
node = -1
if self._node is not None:
node = self._node.id
d50 = 0.002
sigma = 1
if self._type == "SL":
d50 = self._d50
sigma = self._sigma
execute(
"INSERT INTO " +
"boundary_condition(" +
"pamhyr_id, deleted, name, type, tab, node, d50, sigma, scenario" +
"pamhyr_id, deleted, name, type, tab, node, scenario" +
") " +
"VALUES (" +
f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " +
f"'{self._db_format(self._name)}', " +
f"'{self._db_format(self._type)}', '{tab}', {node}, " +
f"{d50}, {sigma}, " +
f"{self._status.scenario_id}" +
")"
)
@ -491,24 +467,6 @@ class BoundaryCondition(SQLSubModel):
def has_node(self):
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
def header(self):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,8 +17,7 @@
# -*- coding: utf-8 -*-
from View.Tools.PamhyrWindow import PamhyrDialog
from PyQt5.QtWidgets import QDoubleSpinBox
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
class ShiftDialog(PamhyrDialog):
_pamhyr_ui = "GeometryReachShift"
@ -31,37 +30,9 @@ class ShiftDialog(PamhyrDialog):
options=[],
parent=parent
)
self._replace_spinboxes()
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):
self._dx = 0.0
self._dy = 0.0

View File

@ -222,32 +222,21 @@ class PollutantsWindow(PamhyrWindow):
initial.show()
def boundary_conditions(self):
rows = self.index_selected_rows()
if len(rows) == 0:
if self.sub_window_exists(
BoundaryConditionAdisTSWindow,
data=[self._study, None]
):
bound = self.get_sub_window(
BoundaryConditionAdisTSWindow,
data=[self._study, None]
)
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(
BoundaryConditionAdisTSWindow,
data=[self._study, None, bcs_adists]
):
return
bound = BoundaryConditionAdisTSWindow(
study=self._study,
parent=self,
data=self._data,
pollutant_id=pollutant_id
)
bound.show()
bound = BoundaryConditionAdisTSWindow(
study=self._study, parent=self
)
bound.show()
def lateral_contrib(self):
rows = self.index_selected_rows()

View File

@ -1,37 +0,0 @@
# 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)