mirror of https://gitlab.com/pamhyr/pamhyr2
Profile: Fix profile id issues and profile index in reach.
parent
f394989a5c
commit
e7099bfb86
|
|
@ -19,10 +19,11 @@ class Profile(object):
|
||||||
|
|
||||||
if id == -1:
|
if id == -1:
|
||||||
self.id = Profile._id_cnt
|
self.id = Profile._id_cnt
|
||||||
Profile._id_cnt += 1
|
|
||||||
else:
|
else:
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
Profile._id_cnt = max(self.id, Profile._id_cnt+1)
|
||||||
|
|
||||||
self._num = int(num)
|
self._num = int(num)
|
||||||
self._code1 = int(code1)
|
self._code1 = int(code1)
|
||||||
self._code2 = int(code2)
|
self._code2 = int(code2)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE geometry_profileXYZ(
|
CREATE TABLE geometry_profileXYZ(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
ind INTEGER NOT NULL,
|
||||||
name TEXT,
|
name TEXT,
|
||||||
reach INTEGER NOT NULL,
|
reach INTEGER NOT NULL,
|
||||||
kp REAL NOT NULL,
|
kp REAL NOT NULL,
|
||||||
|
|
@ -76,18 +77,22 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, name, kp, num, code1, code2 " +
|
"SELECT id, ind, name, kp, num, code1, code2 " +
|
||||||
"FROM geometry_profileXYZ " +
|
"FROM geometry_profileXYZ " +
|
||||||
f"WHERE reach = {reach}"
|
f"WHERE reach = {reach}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for _ in table:
|
||||||
|
profiles.append(None)
|
||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
id = row[0]
|
id = row[0]
|
||||||
name = row[1]
|
ind = row[1]
|
||||||
kp = row[2]
|
name = row[2]
|
||||||
num = row[3]
|
kp = row[3]
|
||||||
code1 = row[4]
|
num = row[5]
|
||||||
code2 = row[5]
|
code1 = row[5]
|
||||||
|
code2 = row[6]
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
id=id, num = num,
|
id=id, num = num,
|
||||||
|
|
@ -100,28 +105,26 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
data["profile"] = id
|
data["profile"] = id
|
||||||
new._points = PointXYZ._sql_load(execute, data)
|
new._points = PointXYZ._sql_load(execute, data)
|
||||||
|
|
||||||
profiles.append(new)
|
profiles[ind] = new
|
||||||
|
|
||||||
return profiles
|
return profiles
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _sql_save(self, execute, data = None):
|
||||||
ok = True
|
ok = True
|
||||||
|
ind = data["ind"]
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"geometry_profileXYZ(id, name, reach, kp, num, code1, code2) "+
|
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2) "+
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
||||||
f"{self.reach.id}, {self.kp}, {self.num}, " +
|
f"{self.reach.id}, {self.kp}, {self.num}, " +
|
||||||
f"{self.code1}, {self.code1}" +
|
f"{self.code1}, {self.code1}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
||||||
if data is None:
|
|
||||||
data = {}
|
|
||||||
data["profile"] = self.id
|
data["profile"] = self.id
|
||||||
|
|
||||||
execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}")
|
execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}")
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,20 @@ class Reach(SQLSubModel):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _sql_save(self, execute, data = None):
|
||||||
objs = self._profiles
|
# Delete old data
|
||||||
|
execute(f"DELETE FROM geometry_profileXYZ")
|
||||||
|
execute(f"DELETE FROM geometry_pointXYZ")
|
||||||
|
|
||||||
return self._save_submodel(execute, objs, data)
|
if data is None:
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
ind = 0
|
||||||
|
for profile in self._profiles:
|
||||||
|
data["ind"] = ind
|
||||||
|
profile._sql_save(execute, data)
|
||||||
|
ind += 1
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def profile(self, i):
|
def profile(self, i):
|
||||||
"""Returns profile at index i
|
"""Returns profile at index i
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue