diff options
author | Remco Burema <r.burema@ultimaker.com> | 2019-09-02 01:17:14 +0300 |
---|---|---|
committer | Remco Burema <r.burema@ultimaker.com> | 2019-09-02 01:17:14 +0300 |
commit | b97015a35407e77c7d66c5f7aad8ca486e05e54e (patch) | |
tree | 1c5c1daa18db5193a7596c941afeef169afc979b /cura/CuraActions.py | |
parent | 243d51eb237c963e43bc9411f9f4c3ea71c55d24 (diff) |
Added 'align selected face with buildplate' feature.
Alt-click to select a face. See the (identically named) 'feature_bottom_face' branch in Uranium for more indepth information.
Diffstat (limited to 'cura/CuraActions.py')
-rw-r--r-- | cura/CuraActions.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cura/CuraActions.py b/cura/CuraActions.py index 20c44c7916..0f2878023d 100644 --- a/cura/CuraActions.py +++ b/cura/CuraActions.py @@ -7,11 +7,13 @@ from typing import List, cast from UM.Event import CallFunctionEvent from UM.FlameProfiler import pyqtSlot +from UM.Math.Quaternion import Quaternion from UM.Math.Vector import Vector from UM.Scene.Selection import Selection from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator from UM.Operations.GroupedOperation import GroupedOperation from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation +from UM.Operations.RotateOperation import RotateOperation from UM.Operations.TranslateOperation import TranslateOperation import cura.CuraApplication @@ -73,6 +75,36 @@ class CuraActions(QObject): operation.addOperation(center_operation) operation.push() + # Rotate the selection, so that the face that the mouse-pointer is on, faces the build-plate. + @pyqtSlot() + def bottomFaceSelection(self) -> None: + selected_face = Selection.getSelectedFace() + if not selected_face: + Logger.log("e", "Bottom face operation shouldn't have been called without a selected face.") + return + + original_node, face_id = selected_face + meshdata = original_node.getMeshDataTransformed() + if not meshdata or face_id < 0 or face_id > 0x10001: + return + + rotation_point, face_normal = meshdata.getFacePlane(face_id) + rotation_point_vector = Vector(rotation_point[0], rotation_point[1], rotation_point[2]) + face_normal_vector = Vector(face_normal[0], face_normal[1], face_normal[2]) + rotation_quaternion = Quaternion.rotationTo(face_normal_vector.normalized(), Vector(0.0, -1.0, 0.0)) + + operation = GroupedOperation() + for node in Selection.getAllSelectedObjects(): + current_node = node + parent_node = current_node.getParent() + while parent_node and parent_node.callDecoration("isGroup"): + current_node = parent_node + parent_node = current_node.getParent() + + rotate_operation = RotateOperation(current_node, rotation_quaternion, rotation_point_vector) + operation.addOperation(rotate_operation) + operation.push() + ## Multiply all objects in the selection # # \param count The number of times to multiply the selection. |