add shift button in geometry window

This commit is contained in:
Theophile Terraz committed 2024-08-05 15:50:22 +02:00
1 parent a698d46144
commit 12cca24d8b
10 files changed
+281 -5

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
# ShiftDialog.py -- Pamhyr
# Copyright (C) 2023-2024 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from View.Tools.PamhyrWindow import PamhyrDialog
class ShiftDialog(PamhyrDialog):
_pamhyr_ui = "GeometryReachShift"
_pamhyr_name = "Shift"
def __init__(self, trad=None, parent=None):
super(ShiftDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
options=[],
parent=parent
)
self._init_default_values()
def _init_default_values(self):
self._dx = 0.0
self._dy = 0.0
self._dz = 0.0
@property
def dx(self):
return self._dx
@property
def dy(self):
return self._dy
@property
def dz(self):
return self._dz
def accept(self):
self._dx = self.get_double_spin_box("doubleSpinBox_X")
self._dy = self.get_double_spin_box("doubleSpinBox_Y")
self._dz = self.get_double_spin_box("doubleSpinBox_Z")
super().accept()
def reject(self):
self.close()
+9
View File
@@ -267,3 +267,12 @@ class GeometryReachTableModel(PamhyrTableModel):
)
)
self.layoutChanged.emit()
def shift(self, rows, dx, dy, dz):
self._undo.push(
ShiftCommand(
self._data, rows, dx, dy, dz
)
)
self.layoutChanged.emit()
+9
View File
@@ -82,3 +82,12 @@ class GeometryTranslate(MainTranslate):
self._dict["Meshing"] = _translate(
"Geometry", "Meshing"
)
self._dict["UpdateRK"] = _translate(
"Geometry", "UpdateRK"
)
self._dict["Purge"] = _translate(
"Geometry", "Purge"
)
self._dict["Shift"] = _translate(
"Geometry", "Shift"
)
+29
View File
@@ -281,3 +281,32 @@ class PurgeCommand(QUndoCommand):
def redo(self):
for profile in self._reach._profiles:
profile.purge(self._np_purge)
class ShiftCommand(QUndoCommand):
def __init__(self, reach, rows, dx, dy, dz):
QUndoCommand.__init__(self)
self._reach = reach
self._rows = rows
self._dx = dx
self._dy = dy
self._dz = dz
self._old = []
for profile in self._reach.profiles:
self._old.append(profile.points.copy())
def undo(self):
for i in self._rows:
profile = self._reach.profiles[i]
self._reach.profiles[i].shift(-self._dx,
-self._dy,
-self._dz)
def redo(self):
for i in self._rows:
profile = self._reach.profiles[i]
self._reach.profiles[i].shift(self._dx,
self._dy,
self._dz)
+24 -4
View File
@@ -58,6 +58,7 @@ from View.Geometry.PlotRKZ import PlotRKZ
from View.Geometry.MeshingDialog import MeshingDialog
from View.Geometry.UpdateRKDialog import UpdateRKDialog
from View.Geometry.PurgeDialog import PurgeDialog
from View.Geometry.ShiftDialog import ShiftDialog
from View.Geometry.Translate import GeometryTranslate
from View.Geometry.Profile.Window import ProfileWindow
@@ -194,6 +195,7 @@ class GeometryWindow(PamhyrWindow):
"action_meshing": self.edit_meshing,
"action_update_rk": self.update_rk,
"action_purge": self.purge,
"action_shift": self.shift,
}
for action in actions:
@@ -499,10 +501,6 @@ class GeometryWindow(PamhyrWindow):
self._table.move_down(row)
self.select_current_profile()
def purge(self):
self._table.purge()
self.update_redraw()
def purge(self):
try:
dlg = PurgeDialog(
@@ -515,6 +513,28 @@ class GeometryWindow(PamhyrWindow):
logger_exception(e)
return
def shift(self):
rows = sorted(
list(
set(
[index.row() for index in self.tableView.selectedIndexes()]
)
)
)
try:
dlg = ShiftDialog(
trad=self._trad,
parent=self
)
if dlg.exec():
self._table.shift(rows,
dlg.dx,
dlg.dy,
dlg.dz)
except Exception as e:
logger_exception(e)
return
def duplicate(self):
rows = [
row.row() for row in