Commit e7099bfb authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Profile: Fix profile id issues and profile index in reach.

Showing with 30 additions and 15 deletions
+30 -15
......@@ -19,10 +19,11 @@ class Profile(object):
if id == -1:
self.id = Profile._id_cnt
Profile._id_cnt += 1
else:
self.id = id
Profile._id_cnt = max(self.id, Profile._id_cnt+1)
self._num = int(num)
self._code1 = int(code1)
self._code2 = int(code2)
......
......@@ -53,6 +53,7 @@ class ProfileXYZ(Profile, SQLSubModel):
execute("""
CREATE TABLE geometry_profileXYZ(
id INTEGER NOT NULL PRIMARY KEY,
ind INTEGER NOT NULL,
name TEXT,
reach INTEGER NOT NULL,
kp REAL NOT NULL,
......@@ -76,18 +77,22 @@ class ProfileXYZ(Profile, SQLSubModel):
reach = data["reach"]
table = execute(
"SELECT id, name, kp, num, code1, code2 " +
"SELECT id, ind, name, kp, num, code1, code2 " +
"FROM geometry_profileXYZ " +
f"WHERE reach = {reach}"
)
for _ in table:
profiles.append(None)
for row in table:
id = row[0]
name = row[1]
kp = row[2]
num = row[3]
code1 = row[4]
code2 = row[5]
ind = row[1]
name = row[2]
kp = row[3]
num = row[5]
code1 = row[5]
code2 = row[6]
new = cls(
id=id, num = num,
......@@ -100,28 +105,26 @@ class ProfileXYZ(Profile, SQLSubModel):
data["profile"] = id
new._points = PointXYZ._sql_load(execute, data)
profiles.append(new)
profiles[ind] = new
return profiles
def _sql_save(self, execute, data = None):
ok = True
ind = data["ind"]
sql = (
"INSERT OR REPLACE INTO " +
"geometry_profileXYZ(id, name, reach, kp, num, code1, code2) "+
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2) "+
"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.code1}, {self.code1}" +
")"
)
execute(sql)
if data is None:
data = {}
data["profile"] = self.id
execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}")
ind = 0
......
......@@ -51,9 +51,20 @@ class Reach(SQLSubModel):
return new
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):
"""Returns profile at index i
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment