From af6a72a76e05dff46fb39f00cd7c9a6f913a166a Mon Sep 17 00:00:00 2001 From: David Vierra Date: Tue, 20 Oct 2015 11:30:10 -1000 Subject: [PATCH] Move tool and coord widget now support relative offsets --- src/mcedit2/editortools/move.py | 3 ++ src/mcedit2/ui/coord_widget.ui | 72 +++++++++++++---------------- src/mcedit2/widgets/coord_widget.py | 63 +++++++++++++++++++------ 3 files changed, 85 insertions(+), 53 deletions(-) diff --git a/src/mcedit2/editortools/move.py b/src/mcedit2/editortools/move.py index 819166f..07ad10f 100644 --- a/src/mcedit2/editortools/move.py +++ b/src/mcedit2/editortools/move.py @@ -146,6 +146,7 @@ class MoveTool(EditorTool): if newPoint != oldPoint: command = MoveOffsetCommand(oldPoint, newPoint, self.currentImport) self.editorSession.pushCommand(command) + self.pointInput.point = newPoint @property def currentImport(self): @@ -168,6 +169,8 @@ class MoveTool(EditorTool): self._currentImportNode = node self.overlayNode.addChild(node) self.rotationInput.rotation = pendingImport.rotation + self.pointInput.point = pendingImport.basePosition + self.pointInput.origin = pendingImport.selection.origin @property def currentImportNode(self): diff --git a/src/mcedit2/ui/coord_widget.ui b/src/mcedit2/ui/coord_widget.ui index 4e31660..562d321 100644 --- a/src/mcedit2/ui/coord_widget.ui +++ b/src/mcedit2/ui/coord_widget.ui @@ -6,8 +6,8 @@ 0 0 - 293 - 92 + 121 + 115 @@ -23,6 +23,20 @@ + + + Relative + + + + + + + X: + + + + -2000000000 @@ -32,31 +46,14 @@ - - - - X: - - - - + - Z: + Y: - - - -2000000000 - - - 2000000000 - - - - -2000000000 @@ -66,33 +63,28 @@ - - + + - Y: + Z: + + + + + + + -2000000000 + + + 2000000000 - xInput - xMaxInput - label - label_2 - yInput - yMaxInput - zMaxInput - zInput - label_3 - stackedWidget - zMaxInput - yMaxInput - xMaxInput - widthLabel - heightLabel - lengthLabel + relativeCheckBox diff --git a/src/mcedit2/widgets/coord_widget.py b/src/mcedit2/widgets/coord_widget.py index 655ad6f..a440b2e 100644 --- a/src/mcedit2/widgets/coord_widget.py +++ b/src/mcedit2/widgets/coord_widget.py @@ -20,9 +20,38 @@ class CoordinateWidget(QtGui.QWidget): self.yInput.valueChanged.connect(self.setY) self.zInput.valueChanged.connect(self.setZ) + self.relativeCheckBox.toggled.connect(self.relativeToggled) + pointChanged = QtCore.Signal(BoundingBox) _point = Vector(0, 0, 0) + _origin = Vector(0, 0, 0) + _relative = False + + def relativeToggled(self, enabled): + self._relative = enabled + self.updateInputs() + + def updateInputs(self): + if self._relative: + displayed = self._point - self._origin + else: + displayed = self._point + + x, y, z = displayed + self.xInput.setValue(x) + self.yInput.setValue(y) + self.zInput.setValue(z) + + @property + def origin(self): + return self._origin + + @origin.setter + def origin(self, value): + value = Vector(*value) + if value != self._origin: + self._origin = value @property def point(self): @@ -31,23 +60,31 @@ class CoordinateWidget(QtGui.QWidget): @point.setter def point(self, point): self.setEnabled(point is not None) - self._point = point - if point is not None: - x, y, z = point - self.xInput.setValue(x) - self.yInput.setValue(y) - self.zInput.setValue(z) + point = Vector(*point) + if self._point != point: + self._point = point + if point is not None: + self.updateInputs() - self.pointChanged.emit(point) + self.pointChanged.emit(point) def setX(self, value): - x, y, z = self.point - self.point = Vector(value, y, z) + self.setCoord(value, 0) def setY(self, value): - x, y, z = self.point - self.point = Vector(x, value, z) + self.setCoord(value, 1) def setZ(self, value): - x, y, z = self.point - self.point = Vector(x, y, value) \ No newline at end of file + self.setCoord(value, 2) + + def setCoord(self, value, index): + old = self.point + if self._relative: + old = old - self._origin + new = list(old) + new[index] = value + new = Vector(*new) + if self._relative: + new = new + self._origin + + self.point = new