D6: Refactoring

This commit is contained in:
Victor Larchenko 2016-12-09 14:47:13 +06:00 committed by Youness Alaoui
parent afc9b71279
commit 26fe0ddbb5
3 changed files with 29 additions and 45 deletions

View file

@ -609,11 +609,9 @@ class CuraApplication(QtApplication):
print_information = self.getPrintInformation() print_information = self.getPrintInformation()
if should_pause: if should_pause:
self.getBackend().pauseSlicing() self.getBackend().pauseSlicing()
self.setHideSettings(True)
print_information.setPreSliced(True) print_information.setPreSliced(True)
else: else:
self.getBackend().continueSlicing() self.getBackend().continueSlicing()
self.setHideSettings(False)
if print_information: if print_information:
print_information.setPreSliced(False) print_information.setPreSliced(False)
@ -1033,17 +1031,4 @@ class CuraApplication(QtApplication):
def log(self, msg): def log(self, msg):
Logger.log("d", msg) Logger.log("d", msg)
_hide_settings = False
hideSettingsChanged = pyqtSignal(bool)
@pyqtSlot(bool)
def setHideSettings(self, hide):
self._hide_settings = hide
self.hideSettingsChanged.emit(hide)
@pyqtProperty(bool, fset=setHideSettings, notify=hideSettingsChanged)
def hideSettings(self):
return self._hide_settings

View file

@ -24,6 +24,7 @@ from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator
import numpy import numpy
import math import math
import re import re
from collections import namedtuple
# Class for loading and parsing G-code files # Class for loading and parsing G-code files
@ -36,12 +37,13 @@ class GCodeReader(MeshReader):
self._message = None self._message = None
self._clearValues() self._clearValues()
self._scene_node = None self._scene_node = None
self._position = namedtuple('Position', ['x', 'y', 'z', 'e'])
def _clearValues(self): def _clearValues(self):
self._extruder = 0 self._extruder = 0
self._layer_type = LayerPolygon.Inset0Type self._layer_type = LayerPolygon.Inset0Type
self._layer = 0 self._layer = 0
self._prev_z = 0 self._previous_z = 0
self._layer_data_builder = LayerDataBuilder.LayerDataBuilder() self._layer_data_builder = LayerDataBuilder.LayerDataBuilder()
self._center_is_zero = False self._center_is_zero = False
@ -93,7 +95,7 @@ class GCodeReader(MeshReader):
try: try:
self._layer_data_builder.addLayer(self._layer) self._layer_data_builder.addLayer(self._layer)
self._layer_data_builder.setLayerHeight(self._layer, path[0][2]) self._layer_data_builder.setLayerHeight(self._layer, path[0][2])
self._layer_data_builder.setLayerThickness(self._layer, math.fabs(current_z - self._prev_z)) self._layer_data_builder.setLayerThickness(self._layer, math.fabs(current_z - self._previous_z))
this_layer = self._layer_data_builder.getLayer(self._layer) this_layer = self._layer_data_builder.getLayer(self._layer)
except ValueError: except ValueError:
return False return False
@ -120,21 +122,20 @@ class GCodeReader(MeshReader):
def _gCode0(self, position, params, path): def _gCode0(self, position, params, path):
x, y, z, e = position x, y, z, e = position
xp, yp, zp, ep = params x = params.x if params.x is not None else x
x = xp if xp is not None else x y = params.y if params.y is not None else y
y = yp if yp is not None else y
z_changed = False z_changed = False
if zp is not None: if params.z is not None:
if z != zp: if z != params.z:
z_changed = True z_changed = True
self._prev_z = z self._previous_z = z
z = zp z = params.z
if ep is not None: if params.e is not None:
if ep > e[self._extruder]: if params.e > e[self._extruder]:
path.append([x, y, z, self._layer_type]) # extrusion path.append([x, y, z, self._layer_type]) # extrusion
else: else:
path.append([x, y, z, LayerPolygon.MoveRetractionType]) # retraction path.append([x, y, z, LayerPolygon.MoveRetractionType]) # retraction
e[self._extruder] = ep e[self._extruder] = params.e
else: else:
path.append([x, y, z, LayerPolygon.MoveCombingType]) path.append([x, y, z, LayerPolygon.MoveCombingType])
if z_changed: if z_changed:
@ -144,25 +145,23 @@ class GCodeReader(MeshReader):
path.clear() path.clear()
else: else:
path.clear() path.clear()
return (x, y, z, e) return self._position(x, y, z, e)
def _gCode28(self, position, params, path): def _gCode28(self, position, params, path):
x, y, z, e = position return self._position(
xp, yp, zp, ep = params params.x if params.x is not None else position.x,
return (xp if xp is not None else x, params.y if params.y is not None else position.y,
yp if yp is not None else y,
0, 0,
e) position.e)
def _gCode92(self, position, params, path): def _gCode92(self, position, params, path):
x, y, z, e = position if params.e is not None:
xp, yp, zp, ep = params position.e[self._extruder] = params.e
if ep is not None: return self._position(
e[self._extruder] = ep params.x if params.x is not None else position.x,
return (xp if xp is not None else x, params.y if params.y is not None else position.y,
yp if yp is not None else y, params.z if params.z is not None else position.z,
zp if zp is not None else z, position.e)
e)
_gCode1 = _gCode0 _gCode1 = _gCode0
@ -175,7 +174,7 @@ class GCodeReader(MeshReader):
if func is not None: if func is not None:
if (x is not None and x < 0) or (y is not None and y < 0): if (x is not None and x < 0) or (y is not None and y < 0):
self._center_is_zero = True self._center_is_zero = True
params = (x, y, z, e) params = self._position(x, y, z, e)
return func(position, params, path) return func(position, params, path)
return position return position
@ -219,12 +218,12 @@ class GCodeReader(MeshReader):
Logger.log("d", "Parsing %s" % file_name) Logger.log("d", "Parsing %s" % file_name)
current_position = (0, 0, 0, [0, 0]) # x, y, z, e current_position = self._position(0, 0, 0, [0, 0])
current_path = [] current_path = []
for line in file: for line in file:
if self._cancelled: if self._cancelled:
Logger.log("w", "Parsing %s cancelled" % file_name) Logger.log("i", "Parsing %s cancelled" % file_name)
return None return None
current_line += 1 current_line += 1
if current_line % file_step == 0: if current_line % file_step == 0:

View file

@ -16,7 +16,7 @@ Rectangle
property int currentModeIndex; property int currentModeIndex;
property bool monitoringPrint: false property bool monitoringPrint: false
property bool hideSettings: Printer.hideSettings property bool hideSettings: PrintInformation.preSliced
Connections Connections
{ {
target: Printer target: Printer