From 42cd80b32fe07e6eb881b6c30b592e134cff1fc6 Mon Sep 17 00:00:00 2001 From: LoneGit Date: Thu, 2 May 2024 23:35:59 +0300 Subject: [PATCH] Adjustments --- src/controller.py | 4 ++-- src/window.py | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/controller.py b/src/controller.py index def8d7c..5e9a049 100644 --- a/src/controller.py +++ b/src/controller.py @@ -126,10 +126,10 @@ def _connect_signals(self): self.view.move_button.clicked.connect(self.move_model) self.view.place_button.clicked.connect(self.place_model) self.view.cancel_action.clicked.connect( - partial(self.view.cancel_movement, True) + partial(self.view.shift_state, True) ) self.view.return_action.clicked.connect( - partial(self.view.cancel_movement, False) + partial(self.view.shift_state, False) ) self.view.load_model_button.clicked.connect(self.open_file) self.view.slice3a_button.clicked.connect(partial(self.slice_stl, "3axes")) diff --git a/src/window.py b/src/window.py index 1fdf622..252c3b5 100644 --- a/src/window.py +++ b/src/window.py @@ -699,10 +699,10 @@ def keyPressProcessing(self, event): if self.move_button.isChecked(): if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_Z: - self.cancel_movement() + self.shift_state() return True elif event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_Y: - self.cancel_movement(False) + self.shift_state(False) return True return False @@ -784,7 +784,9 @@ def save_current_movement(self): self.stlActor.movements_array = movements self.stlActor.current_movement_index = len(movements) - 1 - def cancel_movement(self, cancel=True): + # We move on to the nearest state of movement of the model. + # If cancel=True, go back. If cancel=False, move forward. + def shift_state(self, cancel=True): current_index = self.stlActor.current_movement_index movements = self.stlActor.movements_array @@ -793,20 +795,19 @@ def cancel_movement(self, cancel=True): else: current_index += 1 - if 0 <= current_index < len(movements): - transform = movements[current_index][1] + if (current_index > len(movements) - 1) or (current_index < 0): + return False - self.stlActor.SetUserTransform(transform) - if not self.boxWidget is None: - self.boxWidget.SetTransform(transform) + transform = movements[current_index][1] - self.updateTransform() - self.reload_scene() + self.stlActor.SetUserTransform(transform) + if not self.boxWidget is None: + self.boxWidget.SetTransform(transform) - self.stlActor.current_movement_index = current_index + self.updateTransform() + self.reload_scene() - else: - return False + self.stlActor.current_movement_index = current_index def updateTransform(self): tf = self.stlActor.GetUserTransform()