mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
geometry: Profile: Update qtable and add undo commands.
This commit is contained in:
1 parent
a9c57a9512
commit
a2e1208d42
6 files changed
+404
-326
No files matched your search
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from Model.Geometry.Point import Point
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
class Profile(object):
|
||||
@@ -20,6 +21,14 @@ class Profile(object):
|
||||
|
||||
self._profile_type = _type
|
||||
|
||||
@property
|
||||
def number_points(self):
|
||||
return len(self._points)
|
||||
|
||||
@property
|
||||
def points(self):
|
||||
return self._points.copy()
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
@@ -100,6 +109,11 @@ class Profile(object):
|
||||
def profile_type(self, value: str):
|
||||
self._profile_type = value
|
||||
|
||||
def point(self, i:int):
|
||||
if i < len(self._points):
|
||||
return self._points[i]
|
||||
|
||||
return None
|
||||
|
||||
def named_points(self):
|
||||
"""List of named point
|
||||
@@ -110,6 +124,81 @@ class Profile(object):
|
||||
return [point for point in self._points
|
||||
if point.point_is_named()]
|
||||
|
||||
|
||||
def insert_point(self, index: int, point:Point):
|
||||
"""Insert point at index.
|
||||
|
||||
Args:
|
||||
index: The index of new profile.
|
||||
point: The point.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
self._points.insert(index, point)
|
||||
|
||||
|
||||
def delete(self, index: int):
|
||||
"""Delete the point at index
|
||||
|
||||
Args:
|
||||
index: Index of point.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
try:
|
||||
self._points.pop(index)
|
||||
except IndexError:
|
||||
raise IndexError(f"Invalid point index: {index}")
|
||||
|
||||
# Move
|
||||
|
||||
def move_up_point(self, index: int):
|
||||
if index < len(self._points):
|
||||
next = index - 1
|
||||
|
||||
p = self._points
|
||||
p[index], p[next] = p[next], p[index]
|
||||
|
||||
def move_down_point(self, index: int):
|
||||
if index >= 0:
|
||||
prev = index + 1
|
||||
|
||||
p = self._points
|
||||
p[index], p[prev] = p[prev], p[index]
|
||||
|
||||
# Sort
|
||||
|
||||
@timer
|
||||
def sort(self, column, is_reversed: bool = False):
|
||||
predicate = lambda p: p.x
|
||||
if column == 'y':
|
||||
predicate = lambda p: p.y
|
||||
elif column == 'z':
|
||||
predicate = lambda p: p.z
|
||||
|
||||
self._profiles = sorted(
|
||||
self._points,
|
||||
key=predicate,
|
||||
reverse=is_reversed
|
||||
)
|
||||
|
||||
@timer
|
||||
def sort_with_indexes(self, indexes: list):
|
||||
if len(self._points) != len(indexes):
|
||||
print("TODO: CRITICAL ERROR!")
|
||||
|
||||
self._points = list(
|
||||
map(
|
||||
lambda x: x[1],
|
||||
sorted(
|
||||
enumerate(self.points),
|
||||
key=lambda x: indexes[x[0]]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# Abstract method, must be implemented for in non abstract class
|
||||
def get_station(self):
|
||||
raise NotImplementedMethodeError(self, self.get_station)
|
||||
Reference in new issue
Block a user