mirror of https://gitlab.com/pamhyr/pamhyr2
Scenario: Fix profile saving and loading for scenario.
parent
739eb56006
commit
216239bfce
|
|
@ -24,7 +24,7 @@ class Point(object):
|
||||||
profile=None, status=None,
|
profile=None, status=None,
|
||||||
owner_scenario=-1):
|
owner_scenario=-1):
|
||||||
super(Point, self).__init__(
|
super(Point, self).__init__(
|
||||||
status=status,
|
id=id, status=status,
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,13 +164,15 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
|
new = []
|
||||||
|
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
scenario = data["scenario"]
|
scenario = data["scenario"]
|
||||||
loaded = data['loaded_pid']
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
if scenario is None:
|
if scenario is None:
|
||||||
return
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, " +
|
"SELECT pamhyr_id, deleted, " +
|
||||||
|
|
@ -194,7 +196,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
sl = next(it)
|
sl = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
new = cls(
|
point = cls(
|
||||||
id=pid,
|
id=pid,
|
||||||
name=name,
|
name=name,
|
||||||
x=x, y=y, z=z,
|
x=x, y=y, z=z,
|
||||||
|
|
@ -203,12 +205,12 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
new.set_as_deleted()
|
point.set_as_deleted()
|
||||||
|
|
||||||
if sl == -1 or sl is None:
|
if sl == -1 or sl is None:
|
||||||
new._sl = None
|
point._sl = None
|
||||||
else:
|
else:
|
||||||
new._sl = next(
|
point._sl = next(
|
||||||
filter(
|
filter(
|
||||||
lambda s: s.pamhyr_id == sl,
|
lambda s: s.pamhyr_id == sl,
|
||||||
data["sediment_layers_list"].sediment_layers
|
data["sediment_layers_list"].sediment_layers
|
||||||
|
|
@ -216,12 +218,14 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
yield new
|
new.append(point)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
yield from cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
data["scenario"] = scenario
|
data["scenario"] = scenario
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
if not self.must_be_saved():
|
if not self.must_be_saved():
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
id: int = -1,
|
id: int = -1,
|
||||||
|
ind: int = -1,
|
||||||
name: str = "",
|
name: str = "",
|
||||||
rk: float = 0.,
|
rk: float = 0.,
|
||||||
reach=None,
|
reach=None,
|
||||||
|
|
@ -70,9 +71,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
"""
|
"""
|
||||||
super(ProfileXYZ, self).__init__(
|
super(ProfileXYZ, self).__init__(
|
||||||
id=id,
|
id=id,
|
||||||
num=num,
|
|
||||||
name=name,
|
name=name,
|
||||||
rk=rk,
|
num=num, rk=rk,
|
||||||
code1=code1, code2=code2,
|
code1=code1, code2=code2,
|
||||||
_type="XYZ",
|
_type="XYZ",
|
||||||
reach=reach,
|
reach=reach,
|
||||||
|
|
@ -80,6 +80,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._db_ind = ind
|
||||||
self.tab = Tabulation([], [], [])
|
self.tab = Tabulation([], [], [])
|
||||||
self.tab_up_to_date = False
|
self.tab_up_to_date = False
|
||||||
self.time_z = 0.0
|
self.time_z = 0.0
|
||||||
|
|
@ -219,16 +220,18 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
|
new = []
|
||||||
|
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
scenario = data["scenario"]
|
scenario = data["scenario"]
|
||||||
loaded = data['loaded_pid']
|
loaded = data['loaded_pid']
|
||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
|
|
||||||
if scenario is None:
|
if scenario is None:
|
||||||
return
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, name, rk, num, " +
|
"SELECT pamhyr_id, ind, deleted, name, rk, num, " +
|
||||||
"code1, code2, sl, scenario " +
|
"code1, code2, sl, scenario " +
|
||||||
"FROM geometry_profileXYZ " +
|
"FROM geometry_profileXYZ " +
|
||||||
f"WHERE reach = {reach.id} " +
|
f"WHERE reach = {reach.id} " +
|
||||||
|
|
@ -241,6 +244,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
it = iter(row)
|
it = iter(row)
|
||||||
|
|
||||||
pid = next(it)
|
pid = next(it)
|
||||||
|
ind = next(it)
|
||||||
deleted = (next(it) == 1)
|
deleted = (next(it) == 1)
|
||||||
name = next(it)
|
name = next(it)
|
||||||
rk = next(it)
|
rk = next(it)
|
||||||
|
|
@ -250,8 +254,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
sl = next(it)
|
sl = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
new = cls(
|
profile = cls(
|
||||||
id=pid, num=num,
|
id=pid, ind=ind, num=num,
|
||||||
name=name, rk=rk,
|
name=name, rk=rk,
|
||||||
code1=code1, code2=code2,
|
code1=code1, code2=code2,
|
||||||
reach=reach,
|
reach=reach,
|
||||||
|
|
@ -259,27 +263,31 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
new.set_as_deleted()
|
profile.set_as_deleted()
|
||||||
|
|
||||||
if sl == -1 or sl is None:
|
if sl == -1 or sl is None:
|
||||||
new._sl = None
|
profile._sl = None
|
||||||
else:
|
else:
|
||||||
new._sl = next(
|
profile._sl = next(
|
||||||
filter(
|
filter(
|
||||||
lambda s: s.id == sl,
|
lambda s: s.id == sl,
|
||||||
data["sediment_layers_list"].sediment_layers
|
data["sediment_layers_list"].sediment_layers
|
||||||
), None)
|
),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
data["profile"] = new
|
data["profile"] = profile
|
||||||
new._points = PointXYZ._db_load(execute, data.copy())
|
profile._points = PointXYZ._db_load(execute, data.copy())
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
yield new
|
new.append(profile)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
yield from cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
data["scenario"] = scenario
|
data["scenario"] = scenario
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
if not self.must_be_saved():
|
if not self.must_be_saved():
|
||||||
return True
|
return True
|
||||||
|
|
@ -991,7 +999,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
def shift(self, x, y, z):
|
def shift(self, x, y, z):
|
||||||
for p in self.points:
|
for p in self._points:
|
||||||
p.x = p.x + x
|
p.x = p.x + x
|
||||||
p.y = p.y + y
|
p.y = p.y + y
|
||||||
p.z = p.z + z
|
p.z = p.z + z
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,12 @@ class Reach(SQLSubModel):
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(status=data["status"], parent=data["reach"])
|
new = cls(status=data["status"], parent=data["reach"])
|
||||||
|
|
||||||
new._profiles = ProfileXYZ._db_load(
|
new._profiles = sorted(
|
||||||
execute,
|
ProfileXYZ._db_load(
|
||||||
data=data.copy()
|
execute,
|
||||||
|
data=data.copy()
|
||||||
|
),
|
||||||
|
key=lambda p: p._db_ind
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue