From d3edf9e5c314d9d7ab7ab08bdff0924417d7c86c Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 24 Jul 2023 17:16:37 +0200 Subject: [PATCH] Geometry: Propagate profile information into point. --- src/Model/Geometry/Point.py | 3 ++- src/Model/Geometry/PointXYZ.py | 11 ++++++----- src/Model/Geometry/ProfileXYZ.py | 14 +++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Model/Geometry/Point.py b/src/Model/Geometry/Point.py index 041603df..cdebd17e 100644 --- a/src/Model/Geometry/Point.py +++ b/src/Model/Geometry/Point.py @@ -3,12 +3,13 @@ from Model.Except import NotImplementedMethodeError class Point(object): - def __init__(self, name:str = "", status = None): + def __init__(self, name:str = "", profile=None, status = None): super(Point, self).__init__() self._status = status self._name = name + self._profile = profile self._sl = None diff --git a/src/Model/Geometry/PointXYZ.py b/src/Model/Geometry/PointXYZ.py index 0fecd1ea..4e55c7b8 100644 --- a/src/Model/Geometry/PointXYZ.py +++ b/src/Model/Geometry/PointXYZ.py @@ -10,8 +10,8 @@ class PointXYZ(Point, SQLSubModel): _sub_classes = [] def __init__(self, x:float = 0.0, y:float = 0.0, z:float = 0.0, - name:str = "", status = None): - super(PointXYZ, self).__init__(name=name, status=status) + name:str = "", profile = None, status = None): + super(PointXYZ, self).__init__(name=name, profile=profile, status=status) self._x = float(x) self._y = float(y) @@ -49,7 +49,7 @@ class PointXYZ(Point, SQLSubModel): table = execute( "SELECT ind, name, x, y, z " + "FROM geometry_pointXYZ " + - f"WHERE profile = {profile}" + f"WHERE profile = {profile.id}" ) # Create points list @@ -67,6 +67,7 @@ class PointXYZ(Point, SQLSubModel): new = cls( name = name, x = x, y = y, z = z, + profile = profile, status = status ) @@ -84,7 +85,7 @@ class PointXYZ(Point, SQLSubModel): "VALUES (" + f"{ind}, '{self._sql_format(self._name)}', " + f"{self.x}, {self.y}, {self.z}, " + - f"{profile}" + + f"{profile.id}" + ")" ) execute(sql) @@ -101,7 +102,7 @@ class PointXYZ(Point, SQLSubModel): *data ) else: - valid_header = {'name', 'x', 'y', 'z'} + valid_header = {'name', 'x', 'y', 'z', 'profile'} d = {} for i, v in enumerate(data): h = header[i].strip().lower().split(' ')[0] diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index d368b981..af310769 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -102,7 +102,7 @@ class ProfileXYZ(Profile, SQLSubModel): status = status ) - data["profile"] = id + data["profile"] = new new._points = PointXYZ._sql_load(execute, data) profiles[ind] = new @@ -124,7 +124,7 @@ class ProfileXYZ(Profile, SQLSubModel): ) execute(sql) - data["profile"] = self.id + data["profile"] = self execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}") ind = 0 @@ -162,11 +162,11 @@ class ProfileXYZ(Profile, SQLSubModel): try: if len(header) == 0: point = PointXYZ( - *data, status=self._status + *data, profile=self, status=self._status ) else: valid_header = {'name', 'x', 'y', 'z'} - d = {"status": self._status} + d = {"status": self._status, "profile": self} for i, v in enumerate(data): h = header[i].strip().lower().split(' ')[0] if h in valid_header: @@ -219,7 +219,7 @@ class ProfileXYZ(Profile, SQLSubModel): Nothing. """ for point in list_points: - pt = PointXYZ(*point, status=self._status) + pt = PointXYZ(*point, profile=self, status=self._status) self._points.append(pt) self._status.modified() @@ -243,7 +243,7 @@ class ProfileXYZ(Profile, SQLSubModel): Returns: Nothing. """ - point_xyz = PointXYZ(0., 0., 0., status=self._status) + point_xyz = PointXYZ(0., 0., 0., profile=self, status=self._status) self._points.append(point_xyz) self._status.modified() @@ -256,7 +256,7 @@ class ProfileXYZ(Profile, SQLSubModel): Returns: The new point. """ - point = PointXYZ(0., 0., 0., status=self._status) + point = PointXYZ(0., 0., 0., profile=self, status=self._status) self._points.insert(index, point) self._status.modified() return point -- GitLab