Scenario: Fix profile saving and loading for scenario.

scenarios
Pierre-Antoine 2025-08-15 10:08:26 +02:00
parent 739eb56006
commit 216239bfce
4 changed files with 41 additions and 26 deletions

View File

@ -24,7 +24,7 @@ class Point(object):
profile=None, status=None,
owner_scenario=-1):
super(Point, self).__init__(
status=status,
id=id, status=status,
owner_scenario=owner_scenario
)

View File

@ -164,13 +164,15 @@ class PointXYZ(Point, SQLSubModel):
@classmethod
def _db_load(cls, execute, data=None):
new = []
status = data["status"]
profile = data["profile"]
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return
return new
table = execute(
"SELECT pamhyr_id, deleted, " +
@ -194,7 +196,7 @@ class PointXYZ(Point, SQLSubModel):
sl = next(it)
owner_scenario = next(it)
new = cls(
point = cls(
id=pid,
name=name,
x=x, y=y, z=z,
@ -203,12 +205,12 @@ class PointXYZ(Point, SQLSubModel):
owner_scenario=owner_scenario
)
if deleted:
new.set_as_deleted()
point.set_as_deleted()
if sl == -1 or sl is None:
new._sl = None
point._sl = None
else:
new._sl = next(
point._sl = next(
filter(
lambda s: s.pamhyr_id == sl,
data["sediment_layers_list"].sediment_layers
@ -216,12 +218,14 @@ class PointXYZ(Point, SQLSubModel):
)
loaded.add(pid)
yield new
new.append(point)
data["scenario"] = scenario.parent
yield from cls._db_load(execute, data)
new += cls._db_load(execute, data)
data["scenario"] = scenario
return new
def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True

View File

@ -49,6 +49,7 @@ class ProfileXYZ(Profile, SQLSubModel):
def __init__(self,
id: int = -1,
ind: int = -1,
name: str = "",
rk: float = 0.,
reach=None,
@ -70,9 +71,8 @@ class ProfileXYZ(Profile, SQLSubModel):
"""
super(ProfileXYZ, self).__init__(
id=id,
num=num,
name=name,
rk=rk,
num=num, rk=rk,
code1=code1, code2=code2,
_type="XYZ",
reach=reach,
@ -80,6 +80,7 @@ class ProfileXYZ(Profile, SQLSubModel):
owner_scenario=owner_scenario
)
self._db_ind = ind
self.tab = Tabulation([], [], [])
self.tab_up_to_date = False
self.time_z = 0.0
@ -219,16 +220,18 @@ class ProfileXYZ(Profile, SQLSubModel):
@classmethod
def _db_load(cls, execute, data=None):
new = []
status = data["status"]
scenario = data["scenario"]
loaded = data['loaded_pid']
reach = data["reach"]
if scenario is None:
return
return new
table = execute(
"SELECT pamhyr_id, deleted, name, rk, num, " +
"SELECT pamhyr_id, ind, deleted, name, rk, num, " +
"code1, code2, sl, scenario " +
"FROM geometry_profileXYZ " +
f"WHERE reach = {reach.id} " +
@ -241,6 +244,7 @@ class ProfileXYZ(Profile, SQLSubModel):
it = iter(row)
pid = next(it)
ind = next(it)
deleted = (next(it) == 1)
name = next(it)
rk = next(it)
@ -250,8 +254,8 @@ class ProfileXYZ(Profile, SQLSubModel):
sl = next(it)
owner_scenario = next(it)
new = cls(
id=pid, num=num,
profile = cls(
id=pid, ind=ind, num=num,
name=name, rk=rk,
code1=code1, code2=code2,
reach=reach,
@ -259,27 +263,31 @@ class ProfileXYZ(Profile, SQLSubModel):
owner_scenario=owner_scenario
)
if deleted:
new.set_as_deleted()
profile.set_as_deleted()
if sl == -1 or sl is None:
new._sl = None
profile._sl = None
else:
new._sl = next(
profile._sl = next(
filter(
lambda s: s.id == sl,
data["sediment_layers_list"].sediment_layers
), None)
),
None
)
data["profile"] = new
new._points = PointXYZ._db_load(execute, data.copy())
data["profile"] = profile
profile._points = PointXYZ._db_load(execute, data.copy())
loaded.add(pid)
yield new
new.append(profile)
data["scenario"] = scenario.parent
yield from cls._db_load(execute, data)
new += cls._db_load(execute, data)
data["scenario"] = scenario
return new
def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True
@ -991,7 +999,7 @@ class ProfileXYZ(Profile, SQLSubModel):
self.modified()
def shift(self, x, y, z):
for p in self.points:
for p in self._points:
p.x = p.x + x
p.y = p.y + y
p.z = p.z + z

View File

@ -72,9 +72,12 @@ class Reach(SQLSubModel):
def _db_load(cls, execute, data=None):
new = cls(status=data["status"], parent=data["reach"])
new._profiles = ProfileXYZ._db_load(
execute,
data=data.copy()
new._profiles = sorted(
ProfileXYZ._db_load(
execute,
data=data.copy()
),
key=lambda p: p._db_ind
)
return new