Skip to content

Commit

Permalink
Simplify approach
Browse files Browse the repository at this point in the history
Input is empty, the user types in the value, rotation is applied and the field clears
  • Loading branch information
HellAholic committed Dec 7, 2024
1 parent abf6c4b commit a23e5e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 121 deletions.
53 changes: 0 additions & 53 deletions plugins/Tools/RotateTool/RotateTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def __init__(self):
self._snap_angle = math.radians(15)

self._angle = None
self._x_angle = 0
self._y_angle = 0
self._z_angle = 0
self._rotation_axis = None
self._angle_update_time = None

self._shortcut_key = Qt.Key.Key_R
Expand Down Expand Up @@ -163,15 +159,12 @@ def event(self, event):
if self.getLockedAxis() == ToolHandle.XAxis:
direction = 1 if Vector.Unit_X.dot(drag_start.cross(drag_end)) > 0 else -1
rotation = Quaternion.fromAngleAxis(direction * angle, Vector.Unit_X)
self._rotation_axis = Vector.Unit_X
elif self.getLockedAxis() == ToolHandle.YAxis:
direction = 1 if Vector.Unit_Y.dot(drag_start.cross(drag_end)) > 0 else -1
rotation = Quaternion.fromAngleAxis(direction * angle, Vector.Unit_Y)
self._rotation_axis = Vector.Unit_Y
elif self.getLockedAxis() == ToolHandle.ZAxis:
direction = 1 if Vector.Unit_Z.dot(drag_start.cross(drag_end)) > 0 else -1
rotation = Quaternion.fromAngleAxis(direction * angle, Vector.Unit_Z)
self._rotation_axis = Vector.Unit_Z
else:
direction = -1

Expand All @@ -182,15 +175,6 @@ def event(self, event):
if not self._angle_update_time or new_time - self._angle_update_time > 0.1:
self._angle_update_time = new_time
self._angle += direction * angle
match self._rotation_axis:
case Vector.Unit_X:
self._x_angle = self._angle
case Vector.Unit_Y:
self._y_angle = self._angle
case Vector.Unit_Z:
self._z_angle = self._angle
case _:
pass
self.propertyChanged.emit()

# Rotate around the saved centeres of all selected nodes
Expand All @@ -217,13 +201,10 @@ def event(self, event):
axis += self._handle.XAxis
if axis == ToolHandle.XAxis:
rotation = Quaternion.fromAngleAxis(angle, Vector.Unit_X)
self._x_angle += angle
elif axis == ToolHandle.YAxis:
rotation = Quaternion.fromAngleAxis(angle, Vector.Unit_Y)
self._y_angle += angle
else:
rotation = Quaternion.fromAngleAxis(angle, Vector.Unit_Z)
self._z_angle += angle


# Rotate around the saved centeres of all selected nodes
Expand All @@ -250,50 +231,17 @@ def event(self, event):

def setRX(self, rx: str) -> None:
angle = float(rx)
_angle = math.radians(angle)
if self._x_angle == _angle:
return
elif self._x_angle:
angle = angle - float(math.degrees(self._x_angle))
self._rotateModel(angle, Vector.Unit_X)
self._x_angle = _angle
self.propertyChanged.emit()

def setRY(self, ry: str) -> None:
angle = float(ry)
_angle = math.radians(angle)
if self._y_angle == _angle:
return
elif self._y_angle:
angle = angle - float(math.degrees(self._y_angle))
self._rotateModel(angle, Vector.Unit_Y)
self._y_angle = _angle
self.propertyChanged.emit()

def setRZ(self, rz: str) -> None:
angle = float(rz)
_angle = math.radians(angle)
if self._z_angle == _angle:
return
elif self._z_angle:
angle = angle - float(math.degrees(self._z_angle))
self._rotateModel(angle, Vector.Unit_Z)
self._z_angle = _angle
self.propertyChanged.emit()

def getRX(self) -> float:
return math.degrees(self._x_angle)

def getRY(self) -> float:
return math.degrees(self._y_angle)

def getRZ(self) -> float:
return math.degrees(self._z_angle)

def _resetXYZRotation(self) -> None:
self._x_angle = 0
self._y_angle = 0
self._z_angle = 0
self.propertyChanged.emit()

def _onSelectedFaceChanged(self):
Expand Down Expand Up @@ -404,7 +352,6 @@ def setSelectFaceToLayFlatMode(self, select: bool) -> None:
def resetRotation(self):
"""Reset the orientation of the mesh(es) to their original orientation(s)"""

self._resetXYZRotation()
for node in self._getSelectedObjectsWithoutSelectedAncestors():
node.setMirror(Vector(1, 1, 1))

Expand Down
74 changes: 6 additions & 68 deletions plugins/Tools/RotateTool/RotateTool.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Item
height: childrenRect.height
UM.I18nCatalog { id: catalog; name: "uranium"}

property string xText
property string yText
property string zText
property string snapText

//Rounds a floating point number to 4 decimals. This prevents floating
Expand Down Expand Up @@ -212,27 +209,15 @@ Item
width: UM.Theme.getSize("setting_control").width
height: UM.Theme.getSize("setting_control").height
unit: "degrees"
text: xText
text: ""

validator: UM.FloatValidator
{
maxBeforeDecimal: 3
maxAfterDecimal: 2
}
onEditingFinished:
{
var modified_text = text.replace(",", ".") // User convenience. We use dots for decimal values
if(text !="")
{
UM.Controller.setProperty("RX", modified_text)
}
}
onActiveFocusChanged:
{
if(!activeFocus && text =="")
{
xText = 0.1; // Need to change it to something else so we can force it to getvalue
xText = UM.Controller.properties.getValue("RX")
text =""
}
}
}
Expand All @@ -243,29 +228,16 @@ Item
width: UM.Theme.getSize("setting_control").width
height: UM.Theme.getSize("setting_control").height
unit: "degrees"
text: yText
text: ""

validator: UM.FloatValidator
{
maxBeforeDecimal: 3
maxAfterDecimal: 2
}
onEditingFinished:
{
var modified_text = text.replace(",", ".") // User convenience. We use dots for decimal values
if(text !="")
{
// Yes this is intentional. Y & Z are flipped between model axes and build plate axes
UM.Controller.setProperty("RZ", modified_text)
}
}
onActiveFocusChanged:
{
if(!activeFocus && text =="")
{
yText = 0.1; // Need to change it to something else so we can force it to getvalue
// Yes this is intentional. Y & Z are flipped between model axes and build plate axes
yText = UM.Controller.properties.getValue("RZ")
text =""
}
}
}
Expand All @@ -276,29 +248,16 @@ Item
width: UM.Theme.getSize("setting_control").width
height: UM.Theme.getSize("setting_control").height
unit: "degrees"
text: zText
text: ""

validator: UM.FloatValidator
{
maxBeforeDecimal: 3
maxAfterDecimal: 2
}
onEditingFinished:
{
var modified_text = text.replace(",", ".") // User convenience. We use dots for decimal values
if(text !="")
{
// Yes this is intentional. Y & Z are flipped between model axes and build plate axes
UM.Controller.setProperty("RY", modified_text)
}
}
onActiveFocusChanged:
{
if(!activeFocus && text =="")
{
zText = 0.1; // Need to change it to something else so we can force it to getvalue
// Yes this is intentional. Y & Z are flipped between model axes and build plate axes
zText = UM.Controller.properties.getValue("RY")
text = ""
}
}
}
Expand All @@ -325,25 +284,4 @@ Item
property: "snapText"
value: base.roundFloat(UM.Controller.properties.getValue("RotationSnapAngle"), 2)
}

Binding
{
target: base
property: "xText"
value: base.roundFloat(UM.Controller.properties.getValue("RX"), 2)
}

Binding
{
target: base
property: "zText"
value: base.roundFloat(UM.Controller.properties.getValue("RY"), 2)
}

Binding
{
target: base
property: "yText"
value: base.roundFloat(UM.Controller.properties.getValue("RZ"), 2)
}
}

0 comments on commit a23e5e8

Please sign in to comment.