diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 144d7c9d32..01acaecf31 100644 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -2,7 +2,109 @@ # Cura is released under the terms of the AGPLv3 or higher. from UM.Mesh.MeshReader import MeshReader +from UM.Application import Application +from UM.Scene.SceneNode import SceneNode +from UM.Mesh.MeshData import MeshData + +from cura.LayerData import LayerData +from cura.LayerDataDecorator import LayerDataDecorator + +import os +import numpy class GCodeReader(MeshReader): + def __init__(self): + super().__init__() + self._supported_extension = ".gcode" + self._scene = Application.getInstance().getController().getScene() + def read(self, file_name): - pass \ No newline at end of file + extension = os.path.splitext(file_name)[1] + if extension.lower() == self._supported_extension: + layer_data = LayerData() + with open (file_name,"rt") as f: + layer = "" + current_path_type = "" + + current_layer_nr = 0 + poly_list = [] + old_position = [0,0,0] + current_z = 0 + for line in f: + if line.startswith(';TYPE:'): + current_path_type = line[6:].strip() + #layer_data.addPolygon(current_layer_nr,3 ,None ,5 ) + elif line.startswith(';LAYER:'): + current_layer_nr = int(line[7:].strip()) + layer_data.addLayer(int(line[7:].strip())) + elif line.startswith(';'): + pass # Ignore comments + else: + command_type = self.getCodeInt(line, 'G') + if command_type == 0 or command_type == 1: #Move command + x = self.getCodeFloat(line, 'X') + y = self.getCodeFloat(line, 'Y') + z = self.getCodeFloat(line, 'Z') + if z: + current_z = z + if x and y: + polygon_data = numpy.zeros((4,3)) #Square :) + polygon_data[0,:] = old_position + polygon_data[1,:] = old_position + polygon_data[2,:] = [x,current_z,y] + polygon_data[3,:] = [x,current_z,y] + old_position = [x,current_z,y] + if current_path_type == "SKIRT": + layer_data.addPolygon(current_layer_nr,5 ,polygon_data ,5 ) + elif current_path_type == "WALL-INNER": + layer_data.addPolygon(current_layer_nr,3 ,polygon_data ,5 ) + elif current_path_type == "WALL-OUTER": + layer_data.addPolygon(current_layer_nr,1 ,polygon_data ,5 ) + else: + layer_data.addPolygon(current_layer_nr,2 ,polygon_data ,5 ) + #e = self.getCodeFloat(line, 'E') + #print(x , " ", y , " ", z, " " , e) + pass + layer_data.build() + decorator = LayerDataDecorator() + decorator.setLayerData(layer_data) + new_node = SceneNode() + new_node.setMeshData(MeshData()) + new_node.addDecorator(decorator) + new_node.setParent(self._scene.getRoot()) + + + ## Gets the value after the 'code' as int + # example: line = "G50" and code is "G" this function will return 50 + # \param line string containing g-code. + # \param code string Letter to look for. + # \sa getCodeFloat + # \returns int + def getCodeInt(self, line, code): + n = line.find(code) + 1 + if n < 1: + return None + m = line.find(' ', n) + try: + if m < 0: + return int(line[n:]) + return int(line[n:m]) + except: + return None + ## Gets the value after the 'code' as float + # example: line = "G50" and code is "G" this function will return 50 + # \param line string containing g-code. + # \param code string Letter to look for. + # \sa getCodeInt + # \returns float + def getCodeFloat(self, line, code): + n = line.find(code) + 1 + if n < 1: + return None + m = line.find(' ', n) + try: + if m < 0: + return float(line[n:]) + return float(line[n:m]) + except: + return None \ No newline at end of file diff --git a/resources/machines/fdmprinter.json b/resources/machines/fdmprinter.json index 8952ebebb9..b2b6e92280 100644 --- a/resources/machines/fdmprinter.json +++ b/resources/machines/fdmprinter.json @@ -146,20 +146,27 @@ } }, "categories": { - "resolution": { - "label": "Quality", + "machine": { + "label": "Machine", "visible": true, "icon": "category_layer_height", "settings": { "machine_nozzle_size": { "label": "Nozzle Diameter", - "description": "The inner diameter of the hole in the nozzle.", + "description": "The inner diameter of the nozzle.", "unit": "mm", "type": "float", "default": 0.4, "min_value": "0.001", "visible": false - }, + } + } + }, + "resolution": { + "label": "Quality", + "visible": true, + "icon": "category_layer_height", + "settings": { "layer_height": { "label": "Layer Height", "description": "The height of each layer, in mm. Normal quality prints are 0.1mm, high quality is 0.06mm. You can go up to 0.25mm with an Ultimaker for very fast prints at low quality. For most purposes, layer heights between 0.1 and 0.2mm give a good tradeoff of speed and surface finish.", diff --git a/resources/machines/ultimaker2.json b/resources/machines/ultimaker2.json index f4bbf5011a..582212fd08 100644 --- a/resources/machines/ultimaker2.json +++ b/resources/machines/ultimaker2.json @@ -63,7 +63,7 @@ ] }, "machine_center_is_zero": { "default": false }, - "machine_nozzle_size": { "default": 0.4, "description": "The inner diameter of the hole in the nozzle. If you are using an Olsson Block with a non-standard nozzle then set this field to the nozzle size you are using." }, + "machine_nozzle_size": { "default": 0.4, "min_value": "0.001", "description": "The inner diameter of the nozzle. If you are using an Olsson Block with a non-standard nozzle diameter, set this field to the diameter you are using." }, "machine_nozzle_heat_up_speed": { "default": 2.0 }, "machine_nozzle_cool_down_speed": { "default": 2.0 }, "gantry_height": { "default": 55 }, diff --git a/resources/qml/ViewPage.qml b/resources/qml/ViewPage.qml index 7b33345a9a..6204b47ee6 100644 --- a/resources/qml/ViewPage.qml +++ b/resources/qml/ViewPage.qml @@ -30,7 +30,7 @@ UM.PreferencesPage width: childrenRect.width; height: childrenRect.height; - text: catalog.i18nc("@info:tooltip","Highlight unsupported areas of the model in red. Without support these areas will nog print properly.") + text: catalog.i18nc("@info:tooltip","Highlight unsupported areas of the model in red. Without support these areas will not print properly.") CheckBox {