Compare commits

..

No commits in common. "cea4dcd9cb8be0f7baa6a9b6f961331509bfb2b9" and "260efc17a92a61fc7265b65871008aebd3595056" have entirely different histories.

49 changed files with 2544 additions and 2739 deletions

View File

@ -232,8 +232,6 @@ 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),
@ -260,17 +258,6 @@ 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
@ -329,7 +316,7 @@ class BoundaryCondition(SQLSubModel):
return new return new
table = execute( table = execute(
"SELECT pamhyr_id, deleted, name, type, node, d50, sigma, scenario " + "SELECT pamhyr_id, deleted, name, type, node, 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} " +
@ -344,8 +331,6 @@ 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)
@ -357,9 +342,7 @@ 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)
@ -391,23 +374,16 @@ class BoundaryCondition(SQLSubModel):
node = -1 node = -1
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, d50, sigma, scenario" + "pamhyr_id, deleted, name, type, tab, node, 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}" +
")" ")"
) )
@ -491,24 +467,6 @@ 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):

View File

@ -312,21 +312,17 @@ class BoundaryConditionAdisTS(SQLSubModel):
status = data['status'] status = data['status']
nodes = data['nodes'] nodes = data['nodes']
scenario = data["scenario"] scenario = data["scenario"]
pollutant = data.get("pollutant")
loaded = data['loaded_pid'] loaded = data['loaded_pid']
if scenario is None: if scenario is None:
return new return new
sql = ( table = execute(
"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))}) "
) )
if pollutant is not None:
sql += f"AND pollutant = {pollutant.id} "
table = execute(sql)
if table is not None: if table is not None:
for row in table: for row in table:
@ -351,7 +347,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
bc.type = bc_type bc.type = bc_type
bc.node = None bc.node = None
if node != -1: if row[3] != -1:
tmp = next( tmp = next(
filter( filter(
lambda n: n.id == node, nodes lambda n: n.id == node, nodes
@ -455,7 +451,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
@node.setter @node.setter
def node(self, node): def node(self, node):
self._node = node self._node = node
self.modified() self._status.modified()
@property @property
def header(self): def header(self):
@ -464,7 +460,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
@header.setter @header.setter
def header(self, header): def header(self, header):
self._header = header self._header = header
self.modified() self._status.modified()
@property @property
def pollutant(self): def pollutant(self):
@ -473,7 +469,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
@pollutant.setter @pollutant.setter
def pollutant(self, pollutant): def pollutant(self, pollutant):
self._pollutant = pollutant self._pollutant = pollutant
self.modified() self._status.modified()
@property @property
def type(self): def type(self):
@ -482,7 +478,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
@type.setter @type.setter
def type(self, type): def type(self, type):
self._type = type self._type = type
self.modified() self._status.modified()
@property @property
def data(self): def data(self):
@ -515,17 +511,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
return (new_0, new_1) return (new_0, new_1)
def add(self, index: int): def add(self, index: int):
value = Data( value = (self._default_0, self._default_1)
self._default_0, self._default_1,
status=self._status
)
self._data.insert(index, value) self._data.insert(index, value)
self.modified() self._status.modified()
return value return value
def insert(self, index: int, value): def insert(self, index: int, value):
self._data.insert(index, value) self._data.insert(index, value)
self.modified() self._status.modified()
def delete_i(self, indexes): def delete_i(self, indexes):
self._data = list( self._data = list(
@ -537,14 +530,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
) )
) )
) )
self.modified() self._status.modified()
def sort(self, _reverse=False, key=None): def sort(self, _reverse=False, key=None):
if key is None: if key is None:
self._data.sort(reverse=_reverse) self._data.sort(reverse=_reverse)
else: else:
self._data.sort(reverse=_reverse, key=key) self._data.sort(reverse=_reverse, key=key)
self.modified() self._status.modified()
def index(self, bc): def index(self, bc):
self._data.index(bc) self._data.index(bc)
@ -559,10 +552,10 @@ class BoundaryConditionAdisTS(SQLSubModel):
return lst return lst
def _set_i_c_v(self, index, column, value): def _set_i_c_v(self, index, column, value):
v = self._data[index] v = list(self._data[index])
v[column] = self._types[column](value) v[column] = self._types[column](value)
self._data[index] = v self._data[index] = tuple(v)
self.modified() self._status.modified()
def set_i_0(self, index: int, value): def set_i_0(self, index: int, value):
self._set_i_c_v(index, 0, value) self._set_i_c_v(index, 0, value)

View File

@ -38,13 +38,9 @@ class BoundaryConditionsAdisTSList(PamhyrModelList):
if data is None: if data is None:
data = {} data = {}
previous_pollutant = data.get("pollutant") new._lst = BoundaryConditionAdisTS._db_load(
data.pop("pollutant", None) execute, data
)
new._lst = BoundaryConditionAdisTS._db_load(execute, data)
if previous_pollutant is not None:
data["pollutant"] = previous_pollutant
return new return new

View File

@ -167,7 +167,7 @@ class D90AdisTSSpec(SQLSubModel):
owner_scenario=owner_scenario owner_scenario=owner_scenario
) )
if deleted: if deleted:
new_spec.set_as_deleted() new_spec.is_deleted()
new_spec.reach = reach new_spec.reach = reach
new_spec.start_rk = start_rk new_spec.start_rk = start_rk
@ -196,12 +196,12 @@ class D90AdisTSSpec(SQLSubModel):
"d90_default, name, reach, " + "d90_default, name, reach, " +
"start_rk, end_rk, d90, enabled, scenario) " + "start_rk, end_rk, d90, enabled, scenario) " +
"VALUES (" + "VALUES (" +
f"{self.id}, {self._db_format(self.is_deleted())}, " + f"{self.id}, {self._db_format(self.is_deleted())}" +
f"{d90_default}, " + f"{d90_default}, " +
f"'{self._db_format(self._name_section)}', " + f"'{self._db_format(self._name_section)}', " +
f"{self._reach}, " + f"{self._reach}, " +
f"{self._start_rk}, {self._end_rk}, " + f"{self._start_rk}, {self._end_rk}, " +
f"{self._d90}, {self._enabled}, " + f"{self._d90}, {self._enabled}" +
f"{self._status.scenario_id}" + f"{self._status.scenario_id}" +
")" ")"
) )

View File

@ -267,7 +267,7 @@ class InitialConditionsAdisTS(SQLSubModel):
@name.setter @name.setter
def name(self, name): def name(self, name):
self._name = name self._name = name
self.modified() self._status.modified()
@property @property
def pollutant(self): def pollutant(self):
@ -276,7 +276,7 @@ class InitialConditionsAdisTS(SQLSubModel):
@pollutant.setter @pollutant.setter
def pollutant(self, pollutant): def pollutant(self, pollutant):
self._pollutant = pollutant self._pollutant = pollutant
self.modified() self._status.modified()
@property @property
def concentration(self): def concentration(self):
@ -285,7 +285,7 @@ class InitialConditionsAdisTS(SQLSubModel):
@concentration.setter @concentration.setter
def concentration(self, concentration): def concentration(self, concentration):
self._concentration = concentration self._concentration = concentration
self.modified() self._status.modified()
@property @property
def eg(self): def eg(self):
@ -294,7 +294,7 @@ class InitialConditionsAdisTS(SQLSubModel):
@eg.setter @eg.setter
def eg(self, eg): def eg(self, eg):
self._eg = eg self._eg = eg
self.modified() self._status.modified()
@property @property
def em(self): def em(self):
@ -303,7 +303,7 @@ class InitialConditionsAdisTS(SQLSubModel):
@em.setter @em.setter
def em(self, em): def em(self, em):
self._em = em self._em = em
self.modified() self._status.modified()
@property @property
def ed(self): def ed(self):
@ -312,7 +312,7 @@ class InitialConditionsAdisTS(SQLSubModel):
@ed.setter @ed.setter
def ed(self, ed): def ed(self, ed):
self._ed = ed self._ed = ed
self.modified() self._status.modified()
@property @property
def enabled(self): def enabled(self):
@ -321,45 +321,28 @@ class InitialConditionsAdisTS(SQLSubModel):
@enabled.setter @enabled.setter
def enabled(self, enabled): def enabled(self, enabled):
self._enabled = enabled self._enabled = enabled
self.modified() self._status.modified()
def new(self, index): def new(self, index):
n = ICAdisTSSpec(status=self._status) n = ICAdisTSSpec(status=self._status)
self._data.insert(index, n) self._data.insert(index, n)
self.modified() self._status.modified()
return n return n
def delete(self, data): def delete(self, data):
list( self._data = list(
map( filter(
lambda x: x.set_as_deleted(), lambda x: x not in data,
data self._data
) )
) )
self.modified() self._status.modified()
def delete_i(self, indexes): def delete_i(self, indexes):
list( for ind in indexes:
map( del self._data[ind]
lambda e: e[1].set_as_deleted(), self._status.modified()
filter(
lambda e: e[0] in indexes,
enumerate(self._data)
)
)
)
self.modified()
def insert(self, index, data): def insert(self, index, data):
if data in self._data: self._data.insert(index, data)
self.undelete([data]) self._status.modified()
else:
self._data.insert(index, data)
self.modified()
def undelete(self, lst):
for x in lst:
x.set_as_not_deleted()
self.modified()

View File

@ -31,7 +31,7 @@ class ICAdisTSSpec(SQLSubModel):
_sub_classes = [] _sub_classes = []
def __init__(self, id: int = -1, name: str = "", def __init__(self, id: int = -1, name: str = "",
status=None, owner_scenario=None): status=None):
super(ICAdisTSSpec, self).__init__() super(ICAdisTSSpec, self).__init__()
self._status = status self._status = status
@ -194,7 +194,7 @@ class ICAdisTSSpec(SQLSubModel):
new_spec.rate = rate new_spec.rate = rate
new_spec.enabled = enabled new_spec.enabled = enabled
# loaded.add(pid) loaded.add(pid)
new.append(new_spec) new.append(new_spec)
data["scenario"] = scenario.parent data["scenario"] = scenario.parent
@ -211,7 +211,7 @@ class ICAdisTSSpec(SQLSubModel):
sql = ( sql = (
"INSERT INTO " + "INSERT INTO " +
"initial_conditions_adists_spec(pamhyr_id, deleted, " + "initial_conditions_adists_spec(id, deleted, " +
"ic_default, name, reach, " + "ic_default, name, reach, " +
"start_rk, end_rk, concentration, eg, em, ed, rate, " + "start_rk, end_rk, concentration, eg, em, ed, rate, " +
"enabled, scenario) " + "enabled, scenario) " +

View File

@ -372,7 +372,7 @@ class LateralContributionAdisTS(SQLSubModel):
execute( execute(
"INSERT INTO " + "INSERT INTO " +
"lateral_contribution_adists(pamhyr_id, deleted," + "lateral_contribution_adists(id, deleted," +
"pollutant, reach, begin_rk, end_rk, scenario) " + "pollutant, reach, begin_rk, end_rk, scenario) " +
"VALUES (" + "VALUES (" +
f"{self.id}, {self._db_format(self.is_deleted())}, " + f"{self.id}, {self._db_format(self.is_deleted())}, " +

View File

@ -28,7 +28,6 @@ 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()
@ -276,8 +275,7 @@ 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):
@ -295,11 +293,6 @@ 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):
@ -422,10 +415,6 @@ class Pollutants(SQLSubModel):
new_pollutant._data = PollutantCharacteristics._db_load( new_pollutant._data = PollutantCharacteristics._db_load(
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)
@ -466,9 +455,6 @@ 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.4" _version = "0.2.3"
_sub_classes = [ _sub_classes = [
Scenario, Scenario,

View File

@ -326,7 +326,7 @@ class Mage(CommandLineSolver):
v0 = d[0] v0 = d[0]
v1 = d[1] v1 = d[1]
if t in ["HYD", "LIM"]: if t in ["HYD", "QSO", "LIM"]:
v0 /= 60 # Convert first column to minute v0 /= 60 # Convert first column to minute
f.write(f"{v0:9} {v1:9} \n") f.write(f"{v0:9} {v1:9} \n")
@ -989,7 +989,7 @@ class Mage8(Mage):
# Data # Data
for d in bound.data: for d in bound.data:
f.write(f"{d[0]/60:10.3f}{d[1]:10.3f}\n") f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n")
return files return files

View File

@ -55,7 +55,7 @@ class AboutWindow(PamhyrDialog):
label = self.get_label_text("label_version") label = self.get_label_text("label_version")
label = label.replace("@version", version) label = label.replace("@version", version)
label = label.replace("@codename", "") label = label.replace("@codename", "(Adis-TS)")
self.set_label_text("label_version", label) self.set_label_text("label_version", label)
# Authors # Authors

View File

@ -54,7 +54,7 @@ class Plot(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
def custom_ticks(self): def custom_ticks(self):
if self.data.header[0] != "time": if self.data.header[0] != "time":

View File

@ -55,7 +55,7 @@ class Plot(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
def custom_ticks(self): def custom_ticks(self):
if self.data.header[0] != "time": if self.data.header[0] != "time":

View File

@ -61,7 +61,9 @@ class AddCommand(QUndoCommand):
def redo(self): def redo(self):
if self._new is None: if self._new is None:
self._new = self._data.add(self._index) self._new = self._data.insert(self._index, (
self._data._types[0](0), self._data._types[1](0.0)
))
else: else:
self._data.insert(self._index, self._new) self._data.insert(self._index, self._new)

View File

@ -112,36 +112,18 @@ class ComboBoxDelegate(QItemDelegate):
class TableModel(PamhyrTableModel): 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._trad = trad
self._bc_list = bc_list self._bc_list = bc_list
self._pollutant = pollutant_bc_list.id self._pollutant = pollutant
super(TableModel, self).__init__(trad=trad, **kwargs) super(TableModel, self).__init__(trad=trad, **kwargs)
def _setup_lst(self): def rowCount(self, parent):
self._lst = list( return len(self._bc_list)
filter(
lambda bc: bc.pollutant == self._pollutant,
self._bc_list.lst
)
)
def get(self, row):
if row < 0 or row >= len(self._lst):
return None
return self._lst[row]
def _global_row(self, row):
bc = self.get(row)
if bc is None:
return None
return self._bc_list.index(bc)
def rowCount(self, parent=QModelIndex()):
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()
@ -149,12 +131,12 @@ class TableModel(PamhyrTableModel):
column = index.column() column = index.column()
if self._headers[column] == "type": if self._headers[column] == "type":
n = self._lst[row].type n = self._bc_list.get(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._lst[row].node n = self._bc_list.get(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)
@ -162,6 +144,18 @@ 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()
@ -174,24 +168,33 @@ class TableModel(PamhyrTableModel):
try: try:
if self._headers[column] == "type": if self._headers[column] == "type":
global_row = self._global_row(row)
self._undo.push( self._undo.push(
SetTypeCommand( SetTypeCommand(
self._bc_list, global_row, value self._bc_list, row, value
) )
) )
elif self._headers[column] == "node": elif self._headers[column] == "node":
global_row = self._global_row(row)
node = next(
filter(lambda n: n.name == value, self._data.nodes()),
None
)
self._undo.push( self._undo.push(
SetNodeCommand( SetNodeCommand(
self._bc_list, global_row, node 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())
@ -200,39 +203,33 @@ class TableModel(PamhyrTableModel):
return True return True
def add(self, row, parent=QModelIndex()): def add(self, row, parent=QModelIndex()):
row = len(self._lst) self.beginInsertRows(parent, row, row - 1)
self.beginInsertRows(parent, row, row)
self._undo.push( self._undo.push(
AddCommand( AddCommand(
self._pollutant, self._bc_list, len(self._bc_list) self._pollutant, self._bc_list, row
) )
) )
self._setup_lst()
self.endInsertRows() self.endInsertRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def delete(self, rows, parent=QModelIndex()): def delete(self, rows, parent=QModelIndex()):
self.beginRemoveRows(parent, rows[0], rows[-1]) self.beginRemoveRows(parent, rows[0], rows[-1])
global_rows = list(
map(self._global_row, rows)
)
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._bc_list, global_rows self._bc_list, rows
) )
) )
self._setup_lst()
self.endRemoveRows() self.endRemoveRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def undo(self): def undo(self):
self._undo.undo() self._undo.undo()
self._setup_lst()
self.layoutChanged.emit() self.layoutChanged.emit()
def redo(self): def redo(self):
self._undo.redo() self._undo.redo()
self._setup_lst()
self.layoutChanged.emit() self.layoutChanged.emit()

View File

@ -36,7 +36,7 @@ class SetNodeCommand(QUndoCommand):
self._bcs = bcs self._bcs = bcs
self._index = index self._index = index
self._old = self._bcs.get(self._index).node self._old = self._bcs.get(self._index).node
self._new = node.id if node is not None else None self._new = node.id
def undo(self): def undo(self):
self._bcs.get(self._index).node = self._old self._bcs.get(self._index).node = self._old

View File

@ -58,21 +58,11 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
_pamhyr_ui = "BoundaryConditionsAdisTS" _pamhyr_ui = "BoundaryConditionsAdisTS"
_pamhyr_name = "Boundary conditions AdisTS" _pamhyr_name = "Boundary conditions AdisTS"
def __init__(self, data=None, pollutant_id=None, study=None, config=None, parent=None): def __init__(self, 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__(
@ -83,6 +73,7 @@ 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()
@ -104,6 +95,12 @@ 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(
@ -113,10 +110,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
) )
@ -159,7 +156,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
) )
def add(self): def add(self):
self._table.add(self._table.rowCount()) self._table.add(len(self._bcs))
def delete(self): def delete(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
@ -183,7 +180,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
def edit(self): def edit(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
for row in rows: for row in rows:
data = self._table.get(row) data = self._bcs.get(row)
if data.node is None: if data.node is None:
continue continue

View File

@ -34,4 +34,5 @@ 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

@ -46,21 +46,21 @@ _translate = QCoreApplication.translate
class ComboBoxDelegate(QItemDelegate): class ComboBoxDelegate(QItemDelegate):
def __init__(self, data=None, d90_spec_lst=None, def __init__(self, data=None, ic_spec_lst=None,
trad=None, parent=None, mode="reaches"): trad=None, parent=None, mode="reaches"):
super(ComboBoxDelegate, self).__init__(parent) super(ComboBoxDelegate, self).__init__(parent)
self._data = data self._data = data
self._mode = mode self._mode = mode
self._trad = trad self._trad = trad
self._d90_spec_lst = d90_spec_lst self._ic_spec_lst = ic_spec_lst
def createEditor(self, parent, option, index): def createEditor(self, parent, option, index):
self.editor = QComboBox(parent) self.editor = QComboBox(parent)
val = [] val = []
if self._mode == "rk": if self._mode == "rk":
reach_id = self._d90_spec_lst[index.row()].reach reach_id = self._ic_spec_lst[index.row()].reach
reach = next(filter( reach = next(filter(
lambda edge: edge.id == reach_id, self._data.edges() lambda edge: edge.id == reach_id, self._data.edges()
@ -118,12 +118,7 @@ class D90TableModel(PamhyrTableModel):
self._data = data self._data = data
def _setup_lst(self): def _setup_lst(self):
self._lst = list( self._lst = self._data._data
filter(
lambda d90: d90._deleted == False,
self._data._data
)
)
def rowCount(self, parent): def rowCount(self, parent):
return len(self._lst) return len(self._lst)
@ -202,25 +197,18 @@ class D90TableModel(PamhyrTableModel):
) )
) )
self._setup_lst()
self.endInsertRows() self.endInsertRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def delete(self, rows, parent=QModelIndex()): def delete(self, rows, parent=QModelIndex()):
self.beginRemoveRows(parent, rows[0], rows[-1]) self.beginRemoveRows(parent, rows[0], rows[-1])
data_rows = {
id(d90): i for i, d90 in enumerate(self._data._data)
}
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._data, self._data, self._lst, rows
self._data._data,
[data_rows[id(self._lst[row])] for row in rows]
) )
) )
self._setup_lst()
self.endRemoveRows() self.endRemoveRows()
self.layoutChanged.emit() self.layoutChanged.emit()

View File

@ -112,11 +112,11 @@ class SetCommandSpec(QUndoCommand):
class AddCommand(QUndoCommand): class AddCommand(QUndoCommand):
def __init__(self, data, d90_spec, index): def __init__(self, data, ics_spec, index):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._data = data self._data = data
self._d90_spec = d90_spec self._ics_spec = ics_spec
self._index = index self._index = index
self._new = None self._new = None
@ -131,20 +131,21 @@ class AddCommand(QUndoCommand):
class DelCommand(QUndoCommand): class DelCommand(QUndoCommand):
def __init__(self, data, d90_spec, rows): def __init__(self, data, ics_spec, rows):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._data = data self._data = data
self._d90_spec = d90_spec self._ics_spec = ics_spec
self._rows = rows self._rows = rows
# self._data = data
self._d90 = [] self._ic = []
for row in rows: for row in rows:
self._d90.append((row, self._d90_spec[row])) self._ic.append((row, self._ics_spec[row]))
self._d90.sort() self._ic.sort()
def undo(self): def undo(self):
for row, el in self._d90: for row, el in self._ic:
self._data.insert(row, el) self._data.insert(row, el)
def redo(self): def redo(self):

View File

@ -138,14 +138,14 @@ class D90AdisTSWindow(PamhyrWindow):
self._delegate_reach = ComboBoxDelegate( self._delegate_reach = ComboBoxDelegate(
trad=self._trad, trad=self._trad,
data=self._study.river, data=self._study.river,
d90_spec_lst=self._data[0]._data, ic_spec_lst=self._data[0]._data,
parent=self, parent=self,
mode="reaches" mode="reaches"
) )
self._delegate_rk = ComboBoxDelegate( self._delegate_rk = ComboBoxDelegate(
trad=self._trad, trad=self._trad,
data=self._study.river, data=self._study.river,
d90_spec_lst=self._data[0]._data, ic_spec_lst=self._data[0]._data,
parent=self, parent=self,
mode="rk" mode="rk"
) )
@ -227,15 +227,15 @@ class D90AdisTSWindow(PamhyrWindow):
table = list( table = list(
map( map(
lambda ed90: list( lambda eic: list(
map( map(
lambda k: ed90[1][k], lambda k: eic[1][k],
["rk", "discharge", "elevation"] ["rk", "discharge", "elevation"]
) )
), ),
filter( filter(
lambda ed90: ed90[0] in rows, lambda eic: eic[0] in rows,
enumerate(self._d90.lst()) enumerate(self._ics.lst())
) )
) )
) )

View File

@ -43,7 +43,7 @@ class PlotRKZ(PlotRKC):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
self.parent = parent self.parent = parent
def onpick(self, event): def onpick(self, event):

View File

@ -50,7 +50,7 @@ class PlotStricklers(PamhyrPlot):
self._auto_relim = False self._auto_relim = False
self._auto_relim_update = False self._auto_relim_update = False
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):

View File

@ -38,7 +38,7 @@ class PlotAC(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
self.label_x = self._trad["transverse_abscissa"] self.label_x = self._trad["transverse_abscissa"]
self.label_y = self._trad["unit_elevation"] self.label_y = self._trad["unit_elevation"]

View File

@ -17,8 +17,7 @@
# -*- 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,37 +30,9 @@ class ShiftDialog(PamhyrDialog):
options=[], options=[],
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

@ -20,7 +20,6 @@ import os
import sys import sys
import time import time
import pathlib import pathlib
from pathlib import Path
import logging import logging
from copy import deepcopy from copy import deepcopy
@ -686,18 +685,10 @@ class GeometryWindow(PamhyrWindow):
) )
if filename != '' and filename is not None: if filename != '' and filename is not None:
suffix = Path(filename).suffix self._export_to_file_st(filename)
if suffix != "":
if suffix == ".st" or suffix == ".ST":
self._export_to_file_st(filename[:-3])
else:
# TODO : prévenir l'utilisateur que le format n'est pas exportable
pass
else:
self._export_to_file_st(filename)
def _export_to_file_st(self, filename): def _export_to_file_st(self, filename):
with open(filename+".st", "w+") as f: with open(filename, "w+") as f:
f.write("# Exported from Pamhyr2\n") f.write("# Exported from Pamhyr2\n")
self._export_to_file_st_reach(f, self._reach) self._export_to_file_st_reach(f, self._reach)

View File

@ -42,7 +42,7 @@ class PlotAC(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@property @property
def river(self): def river(self):

View File

@ -50,7 +50,7 @@ class PlotRKC(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
self.parent = parent self.parent = parent
self.anotate_lst = [] self.anotate_lst = []

View File

@ -47,7 +47,7 @@ class PlotDRK(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):

View File

@ -37,7 +37,7 @@ class PlotDischarge(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self): def draw(self):

View File

@ -117,12 +117,7 @@ class InitialConditionTableModel(PamhyrTableModel):
self._data = data self._data = data
def _setup_lst(self): def _setup_lst(self):
self._lst = list( self._lst = self._data._data
filter(
lambda ica: ica._deleted == False,
self._data._data
)
)
def rowCount(self, parent): def rowCount(self, parent):
return len(self._lst) return len(self._lst)
@ -221,25 +216,18 @@ class InitialConditionTableModel(PamhyrTableModel):
) )
) )
self._setup_lst()
self.endInsertRows() self.endInsertRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def delete(self, rows, parent=QModelIndex()): def delete(self, rows, parent=QModelIndex()):
self.beginRemoveRows(parent, rows[0], rows[-1]) self.beginRemoveRows(parent, rows[0], rows[-1])
data_rows = {
id(ica): i for i, ica in enumerate(self._data._data)
}
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._data, self._data, self._lst, rows
self._data._data,
[data_rows[id(self._lst[row])] for row in rows]
) )
) )
self._setup_lst()
self.endRemoveRows() self.endRemoveRows()
self.layoutChanged.emit() self.layoutChanged.emit()

View File

@ -181,6 +181,7 @@ class DelCommand(QUndoCommand):
self._data = data self._data = data
self._ics_spec = ics_spec self._ics_spec = ics_spec
self._rows = rows self._rows = rows
# self._data = data
self._ic = [] self._ic = []
for row in rows: for row in rows:

View File

@ -54,7 +54,7 @@ class Plot(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
def custom_ticks(self): def custom_ticks(self):
if self.data.header[0] != "time": if self.data.header[0] != "time":

View File

@ -54,7 +54,7 @@ class Plot(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
def custom_ticks(self): def custom_ticks(self):
if self.data.header[0] != "time": if self.data.header[0] != "time":

View File

@ -901,18 +901,7 @@ class GraphWidget(QGraphicsView):
painter.drawRect(sceneRect) painter.drawRect(sceneRect)
def wheelEvent(self, event): def wheelEvent(self, event):
factor = math.pow(2.0, event.angleDelta().y() / 240.0) self.scaleView(math.pow(2.0, -event.angleDelta().y() / 240.0))
old_pos = self.mapToScene(event.pos())
self.scaleView(factor)
new_pos = self.mapToScene(event.pos())
delta = old_pos - new_pos
# Compensation pour garder le point sous la souris fixe
self.translate(delta.x(), delta.y())
def scaleView(self, scaleFactor): def scaleView(self, scaleFactor):
factor = self.transform().scale( factor = self.transform().scale(
@ -925,9 +914,6 @@ class GraphWidget(QGraphicsView):
self.scale(scaleFactor, scaleFactor) self.scale(scaleFactor, scaleFactor)
def mousePressEvent(self, event): def mousePressEvent(self, event):
if self._only_display or self.graph._status.is_read_only():
return
pos = self.mapToScene(event.pos()) pos = self.mapToScene(event.pos())
self.clicked = True self.clicked = True

View File

@ -68,7 +68,7 @@ class PlotXY(PamhyrPlot):
self._isometric_axis = True self._isometric_axis = True
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self): def draw(self):

View File

@ -222,32 +222,21 @@ class PollutantsWindow(PamhyrWindow):
initial.show() initial.show()
def boundary_conditions(self): 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 return
for row in rows: bound = BoundaryConditionAdisTSWindow(
pollutant_id = self._pollutants_lst.get(row).id study=self._study, parent=self
)
bclist = self._study.river.boundary_conditions_adists.BCs_AdisTS_List bound.show()
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()
def lateral_contrib(self): def lateral_contrib(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()

View File

@ -55,7 +55,7 @@ class Plot(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self): def draw(self):

View File

@ -56,7 +56,7 @@ class PlotAC(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@property @property
def results(self): def results(self):

View File

@ -59,7 +59,7 @@ class PlotRKC(PamhyrPlot):
self._isometric_axis = False self._isometric_axis = False
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = False self._autoscale_update = True
@property @property
def results(self): def results(self):

View File

@ -701,8 +701,7 @@ class ResultsWindow(PamhyrWindow):
logger.info("TODO: paste") logger.info("TODO: paste")
def _undo(self): def _undo(self):
logger.info("TODO: undo") self._table.undo()
# self._table.undo()
def _redo(self): def _redo(self):
self._table.redo() self._table.redo()

View File

@ -312,18 +312,7 @@ class GraphWidget(QGraphicsView):
painter.drawRect(sceneRect) painter.drawRect(sceneRect)
def wheelEvent(self, event): def wheelEvent(self, event):
factor = math.pow(2.0, event.angleDelta().y() / 240.0) self.scaleView(math.pow(2.0, -event.angleDelta().y() / 240.0))
old_pos = self.mapToScene(event.pos())
self.scaleView(factor)
new_pos = self.mapToScene(event.pos())
delta = old_pos - new_pos
# Compensation pour garder le point sous la souris fixe
self.translate(delta.x(), delta.y())
def keyPressEvent(self, event): def keyPressEvent(self, event):
key = event.key() key = event.key()

View File

@ -49,7 +49,7 @@ class Plot(PamhyrPlot):
self._auto_relim = False self._auto_relim = False
self._auto_relim_update = False self._auto_relim_update = False
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self): def draw(self):

View File

@ -53,7 +53,7 @@ class Plot(PamhyrPlot):
self._auto_relim = False self._auto_relim = False
self._auto_relim_update = False self._auto_relim_update = False
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self): def draw(self):

View File

@ -53,7 +53,7 @@ class Plot(PamhyrPlot):
self._auto_relim = False self._auto_relim = False
self._auto_relim_update = False self._auto_relim_update = False
self._autoscale_update = False self._autoscale_update = True
@timer @timer
def draw(self): def draw(self):

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)

View File

@ -222,11 +222,10 @@ class PamhyrPlotToolbar(NavigationToolbar2QT):
filters.append(new) filters.append(new)
filters = ';;'.join(filters) filters = ';;'.join(filters)
file_name, _ = QtWidgets.QFileDialog.getSaveFileName( file_name, _ = qt_compat._getSaveFileName(
self.canvas.parent(), self.canvas.parent(),
_translate("MainWindow_reach", "Select destination file"), _translate("MainWindow_reach", "Select destination file"),
start, start, filters,
filters,
selected_filter selected_filter
) )

View File

@ -225,7 +225,7 @@
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>&lt;a href=&quot;https://gitlab.com/pamhyr/pamhyr2&quot;&gt;Source code&lt;/a&gt;</string> <string>&lt;a href=&quot;https://gitlab.irstea.fr/theophile.terraz/pamhyr&quot;&gt;Source code&lt;/a&gt;</string>
</property> </property>
<property name="textFormat"> <property name="textFormat">
<enum>Qt::RichText</enum> <enum>Qt::RichText</enum>

File diff suppressed because it is too large Load Diff