An error occurred while loading the file. Please try again.
-
Olivier Kaufmann authoreda7eb21eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-
from tools import trace, timer
from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack,
)
from Model.Geometry.Profile import Profile
class SetDataCommand(QUndoCommand):
def __init__(self, profile, index, old_value, new_value):
QUndoCommand.__init__(self)
self._profile = profile
self._index = index
self._old = old_value
self._new = new_value
class SetXCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).x = self._old
def redo(self):
self._profile.point(self._index).x = self._new
class SetYCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).y = self._old
def redo(self):
self._profile.point(self._index).y = self._new
class SetZCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).z = self._old
def redo(self):
self._profile.point(self._index).z = self._new
class SetNameCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).name = self._old
def redo(self):
self._profile.point(self._index).name = self._new
class AddCommand(QUndoCommand):
def __init__(self, profile, index):
QUndoCommand.__init__(self)
self._profile = profile
self._index = index
self._point = None
def undo(self):
self._profile.delete([self._index])
def redo(self):
if self._point is None:
self._point = self._profile.insert(self._index)
else:
self._profile.insert_point(self._index, self._point)
class DelCommand(QUndoCommand):
def __init__(self, profile, rows):
QUndoCommand.__init__(self)
self._profile = profile
self._rows = rows
self._points = []
for row in rows:
self._points.append((row, self._profile.point(row)))
self._points.sort() # Sort by row index
def undo(self):
for row, point in self._points:
self._profile.insert_point(row, point)
def redo(self):
self._profile.delete(self._rows)
class SortCommand(QUndoCommand):
def __init__(self, profile, column, _reverse):
QUndoCommand.__init__(self)
self._profile = profile
self._column = column
self._reverse = _reverse
old = self._profile.points
self._profile.sort(self._column, self._reverse)
new = self._profile.points
self._indexes = list(
map(
lambda p: old.index(p),
new
)
)
def undo(self):
self._profile.sort_with_indexes(self._indexes)
def redo(self):
self._profile.sort(self._column, self._reverse)
class MoveCommand(QUndoCommand):
def __init__(self, profile, up, i):
QUndoCommand.__init__(self)
self._profile = profile
self._up = up == "up"
self._i = i
def undo(self):
if self._up:
self._profile.move_up_point(self._i)
else:
self._profile.move_down_point(self._i)
def redo(self):
if self._up:
self._profile.move_up_point(self._i)
else:
self._profile.move_down_point(self._i)
class PasteCommand(QUndoCommand):
def __init__(self, profile, row, points):
QUndoCommand.__init__(self)
self._profile = profile
self._row = row
self._points = points
self._points.reverse()
def undo(self):
for ind in range(len(self._points)):
self._profile.delete([self._row])
def redo(self):
for point in self._points:
self._profile.insert_point(self._row, point)