diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index 81739569920d674c5bd24b56f315d04a48aee681..d7baf4b471828ed650ed7bb51980d4908cee5d97 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -6,6 +6,7 @@ from typing import List from Model.Geometry.Profile import Profile from Model.Geometry.PointXYZ import PointXYZ +from Model.Geometry.Vector_1d import Vector1d class ProfileXYZ(Profile): def __init__(self, num: int = 0, @@ -61,22 +62,22 @@ class ProfileXYZ(Profile): return [point.name for point in self._points] def x_max(self): - return max(self.filter_isnan(self.x)) + return max(self.filter_isnan(self.x())) def x_min(self): - return min(self.filter_isnan(self.x)) + return min(self.filter_isnan(self.x())) def y_max(self): - return max(self.filter_isnan(self.y)) + return max(self.filter_isnan(self.y())) def y_min(self): - return min(self.filter_isnan(self.y)) + return min(self.filter_isnan(self.y())) def z_max(self): - return max(self.filter_isnan(self.z)) + return max(self.filter_isnan(self.z())) def z_min(self): - return min(self.filter_isnan(self.z)) + return min(self.filter_isnan(self.z())) def import_points(self, list_points: list): """Import a list of points to profile @@ -195,7 +196,7 @@ class ProfileXYZ(Profile): first_point_not_nan = self._first_point_not_nan() last_point_not_nan = self._last_point_not_nan() - for index, point in enumerate(self.points): + for index, point in enumerate(self._points): if point.point_is_named(): index_first_named_point = index first_named_point = point @@ -209,8 +210,8 @@ class ProfileXYZ(Profile): station = [] constant = 0.0 - if ((first_named_point is not None) and - (last_named_point is not None)): + if (first_named_point is not None and + last_named_point is not None): if (first_named_point != last_named_point and first_named_point.x != last_named_point.x): vector = Vector1d(first_named_point, last_named_point) @@ -227,9 +228,9 @@ class ProfileXYZ(Profile): normalized_direction_vec[1] * yi) station.append(station_i) - station = np.array(station) + ret = np.array(station) - constant = station[index_first_named_point] + constant = ret[index_first_named_point] elif first_named_point is None: vector = Vector1d(first_point_not_nan, last_point_not_nan) @@ -242,23 +243,23 @@ class ProfileXYZ(Profile): normalized_direction_vec[1] * yi) station.append(station_i) - station = np.array(station) + ret = np.array(station) index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0] - constant = station[index_profile_z_min] + constant = ret[index_profile_z_min] - return (station - constant) + return (ret - constant) else: return np.array(np.nan) def _first_point_not_nan(self): first_point = self._points[0] - for point in self.points: + for point in self._points: if not point.is_nan(): first_point = point break - return first_point_not_nan + return first_point def _last_point_not_nan(self): last_point = self._points[-1] diff --git a/src/Model/Geometry/Reach.py b/src/Model/Geometry/Reach.py index d2c6b4f0dfdcd6ea8642f73c9519faaac0f466e9..f81416fefce64fc224b69630341cc63721a133f1 100644 --- a/src/Model/Geometry/Reach.py +++ b/src/Model/Geometry/Reach.py @@ -145,7 +145,7 @@ class Reach: Returns: List of z min for each profile """ - return [profile.z_min() for profile in self._data.profiles] + return [profile.z_min() for profile in self.profiles] def get_z_max(self): """List of z max for each profile @@ -153,7 +153,7 @@ class Reach: Returns: List of z max for each profile """ - return [profile.z_max() for profile in self._data.profiles] + return [profile.z_max() for profile in self.profiles] def get_kp(self): """List of profiles kp @@ -161,11 +161,10 @@ class Reach: Returns: List of profiles kp """ - return [profile.kp for profile in self._data.profiles] + return [profile.kp for profile in self.profiles] - ############## - # GUIDELINES # - ############## + + # Guidelines def _compute_guidelines_cache(self, guide_set, named_points): # Reset guide lines cache @@ -247,6 +246,7 @@ class Reach: def get_guidelines_z(self): return self._map_guidelines_points(lambda p: p.z) + # Sort def sort_ascending(self): @@ -265,6 +265,9 @@ class Reach: """ self._sort(is_reversed=True) + + # Copy/Paste + def copy(self, index_list: List[int]): self.__list_copied_profiles.clear() index_list = list(set(index_list)) # delete duplicate index @@ -280,6 +283,9 @@ class Reach: for profile in self.__list_copied_profiles: self._profiles.append(profile) + + # Import/Export + def import_geometry(self, file_path_name: str): """Import a geometry from file (.ST or .st) diff --git a/src/Model/Geometry/vector_1d.py b/src/Model/Geometry/Vector_1d.py similarity index 99% rename from src/Model/Geometry/vector_1d.py rename to src/Model/Geometry/Vector_1d.py index b82b86b03d5d353b5f165ff66308a53161fa0337..51fef7f2c45cb2c339950402b24c867fc1297513 100644 --- a/src/Model/Geometry/vector_1d.py +++ b/src/Model/Geometry/Vector_1d.py @@ -3,7 +3,6 @@ import numpy as np from Model.Geometry.PointXYZ import PointXYZ - class Vector1d: def __init__(self, a: PointXYZ, b: PointXYZ): self.A = a diff --git a/src/Model/Geometry/projection_pointXYZ.py b/src/Model/Geometry/projection_pointXYZ.py deleted file mode 100644 index 579ae63c09c7e228c4b50fe272e67337bed322db..0000000000000000000000000000000000000000 --- a/src/Model/Geometry/projection_pointXYZ.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -import copy - -import numpy as np -import pandas as pd -from time import time - -from Model.Geometry import PointXYZ -from Model.Geometry.ProfileXYZ import ProfileXYZ -from Model.Geometry.vector_1d import Vector1d - - -def update_station(list_header, list_point_xyz): - profile = ProfileXYZ(list_header, list_point_xyz) - if profile.nb_points >= 3: - return get_station(profile) - else: - pass - - -def get_station(profile: ProfileXYZ) -> np.ndarray: - """Projection of the points of the profile on a plane. - - Args: - profile: The profile - - Returns: - Projection of the points of the profile on a plane. - """ - if profile.nb_points >= 3: - first_named_point = None - index_first_named_point = None - last_named_point = None - - for index, point in enumerate(profile.points): - if point.point_is_named(): - index_first_named_point = index - first_named_point = point - break - - for point in profile.points[::-1]: - if point.point_is_named(): - last_named_point = point - break - - station = [] - constant = 0.0 - - if ((first_named_point is not None) and - (last_named_point is not None)): - if (first_named_point != last_named_point and - first_named_point.x != last_named_point.x): - vector = Vector1d(first_named_point, last_named_point) - normalized_direction_vec = vector.normalized_direction_vector() - else: - vector = Vector1d(_first_point_not_nan(profile), - _last_point_not_nan(profile)) - normalized_direction_vec = vector.normalized_direction_vector() - - for point in profile.points: - xi = point.x - first_named_point.x - yi = point.y - first_named_point.y - station_i = (normalized_direction_vec[0] * xi + - normalized_direction_vec[1] * yi) - station.append(station_i) - - station = np.array(station) - - constant = station[index_first_named_point] - elif first_named_point is None: - vector = Vector1d(_first_point_not_nan(profile), - _last_point_not_nan(profile)) - normalized_direction_vec = vector.normalized_direction_vector() - - for point in profile.points: - xi = point.x - _first_point_not_nan(profile).x - yi = point.y - _first_point_not_nan(profile).y - station_i = (normalized_direction_vec[0] * xi + - normalized_direction_vec[1] * yi) - station.append(station_i) - - station = np.array(station) - index_profile_z_min = np.where(np.array(profile.z) == profile.z_min)[0][0] - constant = station[index_profile_z_min] - - return (station - constant) - else: - return np.array(np.nan) - -def _first_point_not_nan(profile: ProfileXYZ): - first_point_not_nan = profile.points[0] - - for point in profile.points: - if not point.is_nan(): - first_point_not_nan = point - break - - return first_point_not_nan - -def _last_point_not_nan(profile: ProfileXYZ): - last_point = profile.points[-1] - - for point in profile.points[::-1]: - if not point.is_nan(): - last_point = point - break - - return last_point diff --git a/src/View/Geometry/GeometryWindow.py b/src/View/Geometry/GeometryWindow.py index b3b19502241c2324c22cf2938be4e5a58a9d3f5e..9908831c3f9fa609e8c645773c83bab234bf4090 100644 --- a/src/View/Geometry/GeometryWindow.py +++ b/src/View/Geometry/GeometryWindow.py @@ -389,8 +389,8 @@ class GeometryWindow(QMainWindow, WindowToolKit): self.tableView.model().blockSignals(True) selected_profile = 0 - station = self._reach.get_station(selected_profile) # L'abscisse en travers - station_plus_1 = self._reach.get_station(selected_profile + 1) + station = self._reach.profile(selected_profile).get_station() + station_plus_1 = self._reach.profile(selected_profile + 1).get_station() elevation = self._reach.profile(selected_profile).z elevation_i_plus_1 = self._reach.profile(selected_profile + 1).z ld = self._reach.profile(selected_profile).name @@ -495,8 +495,8 @@ class GeometryWindow(QMainWindow, WindowToolKit): self.annotation_3[:] = [] - x = self.get_station(ind) - y = self.get_elevation(ind) + x = self.profile(ind).get_station() + y = self._reach.profile(ind).z() ld = self._reach.profile(ind).name get_complete_list_ld = self._reach.get_complete_list_ld() get_incomplete_list_ld = self._reach.get_incomplete_list_ld() @@ -552,10 +552,10 @@ class GeometryWindow(QMainWindow, WindowToolKit): return colors def get_station(self, ind: int): - return self._reach.get_station(ind) + return self._reach.profile(ind).get_station() def get_elevation(self, ind: int): - return self._reach.profile(ind).z + return self._reach.profile(ind).z() def update_graphic_3(self, ind: int): self.tableView.model().blockSignals(True) diff --git a/src/View/Geometry/qtableview_profile.py b/src/View/Geometry/qtableview_profile.py index 292b11f456a19a2f4b28daf566fa4919b224b87f..b94f59ac89c0b3d1e3598528c98aabe27a994b5d 100644 --- a/src/View/Geometry/qtableview_profile.py +++ b/src/View/Geometry/qtableview_profile.py @@ -7,7 +7,6 @@ from PyQt5 import QtWidgets, QtGui from PyQt5.QtCore import QModelIndex, Qt, QAbstractTableModel, QVariant, QCoreApplication from Model.Geometry.ProfileXYZ import ProfileXYZ -from Model.Geometry.projection_pointXYZ import * _translate = QCoreApplication.translate