<commit_before># Copyright (c) 2016 <NAME>, Inc.
# Cura is released under the terms of the AGPLv3 or higher.

from UM.Mesh.MeshReader import MeshReader
import os
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Math.Vector import Vector
from UM.Math.AxisAlignedBox import AxisAlignedBox
from UM.Application import Application
from UM.Message import Message
from UM.Logger import Logger
from UM.Backend.Backend import BackendState

from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")


from cura import LayerDataBuilder
from cura import LayerDataDecorator
from cura.LayerPolygon import LayerPolygon

import numpy
import math
import re


# Class for loading and parsing G-code files
class GCodeReader(MeshReader):
    def __init__(self):
        super(GCodeReader, self).__init__()
        self._supported_extensions = [".gcode", ".g"]
        Application.getInstance().hideMessageSignal.connect(self._onHideMessage)
        self._cancelled = False
        self._message = None

        self._scene_node = None

    @staticmethod
    def _getValue(line, code):
        n = line.find(code) + len(code)
        if n < 1:
            return None
        pattern = re.compile("[;\s]")
        match = pattern.search(line, n)
        m = match.start() if math is not None else -1
        try:
            if m < 0:
                return line[n:]
            return line[n:m]
        except:
            return None

    def _getInt(self, line, code):
        value = self._getValue(line, code)
        try:
            return int(value)
        except:
            return None

    def _getFloat(self, line, code):
        value = self._getValue(line, code)
        try:
            return float(value)
        except:
            return None

    def _onHideMessage(self, message):
        if message == self._message:
            self._cancelled = True

    def _onParentChanged(self, node):
        if self._scene_node is not None and self._scene_node.getParent() is None:
            self._scene_node = None
            Application.getInstance().getBackend().continueSlicing()
            Application.getInstance().setHideSettings(False)
            Application.getInstance().getPrintInformation().setPreSliced(False)

    @staticmethod
    def _getNullBoundingBox():
        return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10))

    @staticmethod
    def _createPolygon(layer_data, path, layer_id, extruder, thickness):
        countvalid = 0
        for point in path:
            if point[3] > 0:
                countvalid += 1
        if countvalid < 2:
            return False
        try:
            layer_data.addLayer(layer_id)
            layer_data.setLayerHeight(layer_id, path[0][1])
            layer_data.setLayerThickness(layer_id, thickness)
            this_layer = layer_data.getLayer(layer_id)
        except ValueError:
            return False
        count = len(path)
        line_types = numpy.empty((count - 1, 1), numpy.int32)
        line_widths = numpy.empty((count - 1, 1), numpy.float32)
        # TODO: need to calculate actual line width based on E values
        line_widths[:, 0] = 0.5
        points = numpy.empty((count, 3), numpy.float32)
        i = 0
        for point in path:
            points[i, 0] = point[0]
            points[i, 1] = point[2]
            points[i, 2] = -point[1]
            if i > 0:
                if point[3] == LayerPolygon.Inset0Type:
                    line_types[i - 1] = extruder + 1
                else:
                    line_types[i - 1] = point[3]
            i += 1

        this_poly = LayerPolygon(layer_data, extruder, line_types, points, line_widths)
        this_poly.buildCache()
<commit_msg>D5: Fixed dual extrusion colors<commit_after># Copyright (c) 2016 <NAME>, Inc.
# Cura is released under the terms of the AGPLv3 or higher.

from UM.Mesh.MeshReader import MeshReader
import os
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Math.Vector import Vector
from UM.Math.AxisAlignedBox import AxisAlignedBox
from UM.Application import Application
from UM.Message import Message
from UM.Logger import Logger
from UM.Backend.Backend import BackendState

from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")


from cura import LayerDataBuilder
from cura import LayerDataDecorator
from cura.LayerPolygon import LayerPolygon

import numpy
import math
import re


# Class for loading and parsing G-code files
class GCodeReader(MeshReader):
    def __init__(self):
        super(GCodeReader, self).__init__()
        self._supported_extensions = [".gcode", ".g"]
        Application.getInstance().hideMessageSignal.connect(self._onHideMessage)
        self._cancelled = False
        self._message = None

        self._scene_node = None

    @staticmethod
    def _getValue(line, code):
        n = line.find(code) + len(code)
        if n < 1:
            return None
        pattern = re.compile("[;\s]")
        match = pattern.search(line, n)
        m = match.start() if math is not None else -1
        try:
            if m < 0:
                return line[n:]
            return line[n:m]
        except:
            return None

    def _getInt(self, line, code):
        value = self._getValue(line, code)
        try:
            return int(value)
        except:
            return None

    def _getFloat(self, line, code):
        value = self._getValue(line, code)
        try:
            return float(value)
        except:
            return None

    def _onHideMessage(self, message):
        if message == self._message:
            self._cancelled = True

    def _onParentChanged(self, node):
        if self._scene_node is not None and self._scene_node.getParent() is None:
            self._scene_node = None
            Application.getInstance().getBackend().continueSlicing()
            Application.getInstance().setHideSettings(False)
            Application.getInstance().getPrintInformation().setPreSliced(False)

    @staticmethod
    def _getNullBoundingBox():
        return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10))

    @staticmethod
    def _createPolygon(layer_data, path, layer_id, extruder, thickness):
        countvalid = 0
        for point in path:
            if point[3] > 0:
                countvalid += 1
        if countvalid < 2:
            return False
        try:
            layer_data.addLayer(layer_id)
            layer_data.setLayerHeight(layer_id, path[0][1])
            layer_data.setLayerThickness(layer_id, thickness)
            this_layer = layer_data.getLayer(layer_id)
        except ValueError:
            return False
        count = len(path)
        line_types = numpy.empty((count - 1, 1), numpy.int32)
        line_widths = numpy.empty((count - 1, 1), numpy.float32)
        # TODO: need to calculate actual line width based on E values
        line_widths[:, 0] = 0.5
        points = numpy.empty((count, 3), numpy.float32)
        i = 0
        for point in path:
            points[i, 0] = point[0]
            points[i, 1] = point[2]
            points[i, 2] = -point[1]
            if i > 0:
                line_types[i - 1] = point[3]
            i += 1

        this_poly = LayerPolygon(layer_data, extruder, line_types, points, line_widths)
        this_poly.buildCache()

{'fraction_non_alphanumeric': 0.09015182050248556, 'fraction_numerical': 0.015450759102512427, 'mean_word_length': 2.243572984749455, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5305578', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2124, 'n_words': 602}