<commit_before>from . import SceneNode

from UM.View.Renderer import Renderer
from UM.Mesh.MeshData import MeshData
from UM.Resources import Resources
from UM.Application import Application
from UM.Math.Color import Color
from UM.Math.Vector import Vector

class ToolHandle(SceneNode.SceneNode):
    NoAxis = 1
    XAxis = 2
    YAxis = 3
    ZAxis = 4
    AllAxis = 5

    DisabledColor = Color(0.5, 0.5, 0.5, 1.0)
    XAxisColor = Color(1.0, 0.0, 0.0, 1.0)
    YAxisColor = Color(0.0, 0.0, 1.0, 1.0)
    ZAxisColor = Color(0.0, 1.0, 0.0, 1.0)
    AllAxisColor = Color(1.0, 1.0, 1.0, 1.0)

    def __init__(self, parent = None):
        super().__init__(parent)

        self._scene = Application.getInstance().getController().getScene()

        self._solid_mesh = None
        self._line_mesh = None
        self._material = None

        self._previous_dist = None

    def getLineMesh(self):
        return self._line_mesh

    def setLineMesh(self, mesh):
        self._line_mesh = mesh

    def getSolidMesh(self):
        return self._solid_mesh

    def setSolidMesh(self, mesh):
        self._solid_mesh = mesh

    def getMaterial(self):
        return self._material

    def render(self, renderer):
        if not self._material:
            self._material = renderer.createMaterial(
                Resources.getPath(Resources.ShadersLocation, 'toolhandle.vert'),
                Resources.getPath(Resources.ShadersLocation, 'toolhandle.frag')
            )
            self._material.setUniformValue('u_disabledColor', self.DisabledColor)
            self._material.setUniformValue('u_activeColor', self.DisabledColor)

        camera_position = self._scene.getActiveCamera().getGlobalPosition()
        dist = (camera_position - self.getGlobalPosition()).length()

        scale = dist / 200
        self.setScale(Vector(scale, scale, scale))

        if self._line_mesh:
            renderer.queueNode(self, mesh = self._line_mesh, mode = Renderer.RenderLines, overlay = True, material = self._material)
        if self._solid_mesh:
            renderer.queueNode(self, mesh = self._solid_mesh, mode = Renderer.RenderTriangles, overlay = True, material = self._material)
        return True

    def getSelectionMap(self):
        return {
            self.XAxisColor: self.XAxis,
            self.YAxisColor: self.YAxis,
            self.ZAxisColor: self.ZAxis,
            self.AllAxisColor: self.AllAxis
        }

    def setActiveAxis(self, axis):
        if axis:
            self._material.setUniformValue('u_activeColor', self._axisColorMap[axis])
        else:
            self._material.setUniformValue('u_activeColor', self.DisabledColor)

        self._scene.sceneChanged.emit(self)

    @classmethod
    def isAxis(cls, value):
        return value in cls._axisColorMap

    _axisColorMap = {
        NoAxis: DisabledColor,
        XAxis: XAxisColor,
        YAxis: YAxisColor,
        ZAxis: ZAxisColor,
        AllAxis: AllAxisColor
    }<commit_msg>Do not emit a signal when the active axis for a tool is set to the already active axis.<commit_after>from . import SceneNode

from UM.View.Renderer import Renderer
from UM.Mesh.MeshData import MeshData
from UM.Resources import Resources
from UM.Application import Application
from UM.Math.Color import Color
from UM.Math.Vector import Vector

class ToolHandle(SceneNode.SceneNode):
    NoAxis = 1
    XAxis = 2
    YAxis = 3
    ZAxis = 4
    AllAxis = 5

    DisabledColor = Color(0.5, 0.5, 0.5, 1.0)
    XAxisColor = Color(1.0, 0.0, 0.0, 1.0)
    YAxisColor = Color(0.0, 0.0, 1.0, 1.0)
    ZAxisColor = Color(0.0, 1.0, 0.0, 1.0)
    AllAxisColor = Color(1.0, 1.0, 1.0, 1.0)

    def __init__(self, parent = None):
        super().__init__(parent)

        self._scene = Application.getInstance().getController().getScene()

        self._solid_mesh = None
        self._line_mesh = None
        self._material = None

        self._previous_dist = None
        self._active_axis = None

    def getLineMesh(self):
        return self._line_mesh

    def setLineMesh(self, mesh):
        self._line_mesh = mesh

    def getSolidMesh(self):
        return self._solid_mesh

    def setSolidMesh(self, mesh):
        self._solid_mesh = mesh

    def getMaterial(self):
        return self._material

    def render(self, renderer):
        if not self._material:
            self._material = renderer.createMaterial(
                Resources.getPath(Resources.ShadersLocation, 'toolhandle.vert'),
                Resources.getPath(Resources.ShadersLocation, 'toolhandle.frag')
            )
            self._material.setUniformValue('u_disabledColor', self.DisabledColor)
            self._material.setUniformValue('u_activeColor', self.DisabledColor)

        camera_position = self._scene.getActiveCamera().getGlobalPosition()
        dist = (camera_position - self.getGlobalPosition()).length()

        scale = dist / 200
        self.setScale(Vector(scale, scale, scale))

        if self._line_mesh:
            renderer.queueNode(self, mesh = self._line_mesh, mode = Renderer.RenderLines, overlay = True, material = self._material)
        if self._solid_mesh:
            renderer.queueNode(self, mesh = self._solid_mesh, mode = Renderer.RenderTriangles, overlay = True, material = self._material)
        return True

    def getSelectionMap(self):
        return {
            self.XAxisColor: self.XAxis,
            self.YAxisColor: self.YAxis,
            self.ZAxisColor: self.ZAxis,
            self.AllAxisColor: self.AllAxis
        }

    def setActiveAxis(self, axis):
        if axis == self._active_axis:
            return
        if axis:
            self._material.setUniformValue('u_activeColor', self._axisColorMap[axis])
        else:
            self._material.setUniformValue('u_activeColor', self.DisabledColor)
        self._active_axis = axis
        self._scene.sceneChanged.emit(self)

    @classmethod
    def isAxis(cls, value):
        return value in cls._axisColorMap

    _axisColorMap = {
        NoAxis: DisabledColor,
        XAxis: XAxisColor,
        YAxis: YAxisColor,
        ZAxis: ZAxisColor,
        AllAxis: AllAxisColor
    }
{'fraction_non_alphanumeric': 0.09756493506493506, 'fraction_numerical': 0.015584415584415584, 'mean_word_length': 2.4554122265844085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5733852', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1799, 'n_words': 412}