mirror of https://gitlab.com/pamhyr/pamhyr2
Geometry: Point: Add scenario support.
parent
05ee0e86b1
commit
02c6430ed2
|
|
@ -21,10 +21,12 @@ from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
class Point(object):
|
class Point(object):
|
||||||
def __init__(self, id: int = -1, name: str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
profile=None, status=None):
|
profile=None, status=None,
|
||||||
super(Point, self).__init__()
|
owner_scenario=-1):
|
||||||
|
super(Point, self).__init__(
|
||||||
self._status = status
|
status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._profile = profile
|
self._profile = profile
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,11 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
|
|
||||||
def __init__(self, id: int = -1,
|
def __init__(self, id: int = -1,
|
||||||
x: float = 0.0, y: float = 0.0, z: float = 0.0,
|
x: float = 0.0, y: float = 0.0, z: float = 0.0,
|
||||||
name: str = "", profile=None, status=None):
|
name: str = "", profile=None,
|
||||||
|
status=None, owner_scenario=-1):
|
||||||
super(PointXYZ, self).__init__(
|
super(PointXYZ, self).__init__(
|
||||||
id=id, name=name, profile=profile, status=status
|
id=id, name=name, profile=profile, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
|
|
||||||
self._x = float(x)
|
self._x = float(x)
|
||||||
|
|
@ -47,6 +49,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE geometry_pointXYZ{ext} (
|
CREATE TABLE geometry_pointXYZ{ext} (
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
ind INTEGER NOT NULL,
|
ind INTEGER NOT NULL,
|
||||||
name TEXT,
|
name TEXT,
|
||||||
x INTEGER NOT NULL,
|
x INTEGER NOT NULL,
|
||||||
|
|
@ -80,6 +83,13 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
|
|
||||||
cls._db_update_to_0_1_0(execute, data)
|
cls._db_update_to_0_1_0(execute, data)
|
||||||
|
|
||||||
|
if major == "0" and minor == "1":
|
||||||
|
if int(release) < 2:
|
||||||
|
execute(
|
||||||
|
"ALTER TABLE geometry_pointXYZ " +
|
||||||
|
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||||
|
)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -156,11 +166,19 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
|
scenario = data["scenario"]
|
||||||
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
|
if scenario is None:
|
||||||
|
return
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, name, x, y, z, sl " +
|
"SELECT pamhyr_id, deleted, " +
|
||||||
|
"name, x, y, z, sl, scenario " +
|
||||||
"FROM geometry_pointXYZ " +
|
"FROM geometry_pointXYZ " +
|
||||||
f"WHERE profile = {profile.pamhyr_id} " +
|
f"WHERE profile = {profile.pamhyr_id} " +
|
||||||
|
f"AND scenario = {scenario.id} " +
|
||||||
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
"ORDER BY ind ASC"
|
"ORDER BY ind ASC"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -168,19 +186,24 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
it = iter(row)
|
it = iter(row)
|
||||||
|
|
||||||
pid = next(it)
|
pid = next(it)
|
||||||
|
deleted = (next(it) == 1)
|
||||||
name = next(it)
|
name = next(it)
|
||||||
x = next(it)
|
x = next(it)
|
||||||
y = next(it)
|
y = next(it)
|
||||||
z = next(it)
|
z = next(it)
|
||||||
sl = next(it)
|
sl = next(it)
|
||||||
|
owner_scenario = next(it)
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
id=pid,
|
id=pid,
|
||||||
name=name,
|
name=name,
|
||||||
x=x, y=y, z=z,
|
x=x, y=y, z=z,
|
||||||
profile=profile,
|
profile=profile,
|
||||||
status=status
|
status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
|
if deleted:
|
||||||
|
nd.set_as_deleted()
|
||||||
|
|
||||||
if sl == -1 or sl is None:
|
if sl == -1 or sl is None:
|
||||||
new._sl = None
|
new._sl = None
|
||||||
|
|
@ -192,9 +215,17 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
loaded.add(pid)
|
||||||
yield new
|
yield new
|
||||||
|
|
||||||
|
data["scenario"] = scenario.parent
|
||||||
|
yield from cls._db_load(execute, data)
|
||||||
|
data["scenario"] = scenario
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
|
if not self.must_be_saved():
|
||||||
|
return True
|
||||||
|
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
|
|
@ -202,13 +233,14 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"geometry_pointXYZ(pamhyr_id, ind, name, " +
|
"geometry_pointXYZ(pamhyr_id, deleted, ind, name, " +
|
||||||
"x, y, z, profile, sl) " +
|
"x, y, z, profile, sl, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.pamhyr_id}, " +
|
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"{ind}, '{self._db_format(self._name)}', " +
|
f"{ind}, '{self._db_format(self._name)}', " +
|
||||||
f"{self.x}, {self.y}, {self.z}, " +
|
f"{self.x}, {self.y}, {self.z}, " +
|
||||||
f"{profile.pamhyr_id}, {sl}" +
|
f"{profile.pamhyr_id}, {sl}, " +
|
||||||
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -246,7 +278,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
@x.setter
|
@x.setter
|
||||||
def x(self, value):
|
def x(self, value):
|
||||||
self._x = float(value)
|
self._x = float(value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def y(self):
|
def y(self):
|
||||||
|
|
@ -255,7 +287,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
@y.setter
|
@y.setter
|
||||||
def y(self, value):
|
def y(self, value):
|
||||||
self._y = float(value)
|
self._y = float(value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def z(self):
|
def z(self):
|
||||||
|
|
@ -264,7 +296,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
@z.setter
|
@z.setter
|
||||||
def z(self, value):
|
def z(self, value):
|
||||||
self._z = float(value)
|
self._z = float(value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def is_nan(self):
|
def is_nan(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue