Skip to content

Commit

Permalink
Make tool handle direction Y be set by preference
Browse files Browse the repository at this point in the history
  • Loading branch information
nallath committed Nov 29, 2024
1 parent 1383cf2 commit f7e5334
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions plugins/Tools/TranslateTool/TranslateToolHandle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2019 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.

from UM.Application import Application
from UM.Math.Vector import Vector
from UM.Mesh.MeshBuilder import MeshBuilder
from UM.Scene.ToolHandle import ToolHandle
Expand All @@ -25,14 +25,17 @@ def __init__(self, parent = None):
self._active_handle_height = 9
self._active_handle_width = 7

Application.getInstance().getPreferences().addPreference("tool/flip_y_axis_tool_handle", False)

def setEnabledAxis(self, axis):
self._enabled_axis = axis
self.buildMesh()

def buildMesh(self):
mb = MeshBuilder()
flip_y_axis = Application.getInstance().getPreferences().getValue("tool/flip_y_axis_tool_handle")

#SOLIDMESH -> LINES
# SOLIDMESH -> LINES
if self.YAxis in self._enabled_axis:
mb.addCube(
width = self._line_width,
Expand All @@ -51,15 +54,16 @@ def buildMesh(self):
)

if self.ZAxis in self._enabled_axis:
center_z = -(self._handle_position / 2) if flip_y_axis else (self._handle_position / 2)
mb.addCube(
width = self._line_width,
height = self._line_width,
depth = self._line_length,
center = Vector(0, 0, -(self._handle_position / 2)),
center = Vector(0, 0, center_z),
color = self._z_axis_color
)

#SOLIDMESH -> HANDLES
# SOLIDMESH -> HANDLES
if self.YAxis in self._enabled_axis:
mb.addPyramid(
width = self._handle_width,
Expand All @@ -81,20 +85,22 @@ def buildMesh(self):
)

if self.ZAxis in self._enabled_axis:
center_z = self._handle_position if not flip_y_axis else -self._handle_position
angle = -90 if not flip_y_axis else 90
mb.addPyramid(
width = self._handle_width,
height = self._handle_height,
depth = self._handle_width,
center = Vector(0, 0, -(self._handle_position)),
color = self._z_axis_color,
axis = Vector.Unit_X,
angle = 90
width=self._handle_width,
height=self._handle_height,
depth=self._handle_width,
center=Vector(0, 0, center_z),
color=self._z_axis_color,
axis=Vector.Unit_X,
angle=angle
)

self.setSolidMesh(mb.build())

mb = MeshBuilder()
#SELECTIONMESH -> LINES
# SELECTIONMESH -> LINES
if self.YAxis in self._enabled_axis:
mb.addCube(
width = self._active_line_width,
Expand All @@ -113,12 +119,13 @@ def buildMesh(self):
)

if self.ZAxis in self._enabled_axis:
center_z = self._active_handle_position / 2 if not flip_y_axis else -(self._active_handle_position / 2)
mb.addCube(
width = self._active_line_width,
height = self._active_line_width,
depth = self._active_line_length,
center = Vector(0, 0, -(self._active_handle_position / 2)),
color = self._z_axis_color
width=self._active_line_width,
height=self._active_line_width,
depth=self._active_line_length,
center=Vector(0, 0, center_z),
color=self._z_axis_color
)

#SELECTIONMESH -> HANDLES
Expand All @@ -138,11 +145,13 @@ def buildMesh(self):
color = ToolHandle.XAxisSelectionColor
)

center_z = self._active_handle_position if not flip_y_axis else -self._active_handle_position

mb.addCube(
width = self._active_handle_width,
height = self._active_handle_width,
depth = self._active_handle_width,
center = Vector(0, 0, -(self._active_handle_position)),
color = ToolHandle.ZAxisSelectionColor
width=self._active_handle_width,
height=self._active_handle_width,
depth=self._active_handle_width,
center=Vector(0, 0, center_z),
color=ToolHandle.ZAxisSelectionColor
)
self.setSelectionMesh(mb.build())

0 comments on commit f7e5334

Please sign in to comment.