mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
D6: Refactoring
This commit is contained in:
parent
60eb83d920
commit
ba372f69a7
3 changed files with 41 additions and 45 deletions
|
@ -20,6 +20,7 @@ from UM.Scene.Selection import Selection
|
||||||
from UM.Scene.GroupDecorator import GroupDecorator
|
from UM.Scene.GroupDecorator import GroupDecorator
|
||||||
from UM.Settings.Validator import Validator
|
from UM.Settings.Validator import Validator
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
|
||||||
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
||||||
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
|
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
|
||||||
|
@ -32,9 +33,6 @@ from UM.Settings.SettingDefinition import SettingDefinition, DefinitionPropertyT
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from UM.Settings.SettingFunction import SettingFunction
|
from UM.Settings.SettingFunction import SettingFunction
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
|
||||||
catalog = i18nCatalog("cura")
|
|
||||||
|
|
||||||
from . import PlatformPhysics
|
from . import PlatformPhysics
|
||||||
from . import BuildVolume
|
from . import BuildVolume
|
||||||
from . import CameraAnimation
|
from . import CameraAnimation
|
||||||
|
@ -608,15 +606,16 @@ class CuraApplication(QtApplication):
|
||||||
if other_bb is not None:
|
if other_bb is not None:
|
||||||
scene_bounding_box = scene_bounding_box + node.getBoundingBox()
|
scene_bounding_box = scene_bounding_box + node.getBoundingBox()
|
||||||
|
|
||||||
if not should_pause:
|
print_information = self.getPrintInformation()
|
||||||
self.getBackend().continueSlicing()
|
if should_pause:
|
||||||
self.setHideSettings(False)
|
|
||||||
if self.getPrintInformation():
|
|
||||||
self.getPrintInformation().setPreSliced(False)
|
|
||||||
else:
|
|
||||||
self.getBackend().pauseSlicing()
|
self.getBackend().pauseSlicing()
|
||||||
self.setHideSettings(True)
|
self.setHideSettings(True)
|
||||||
self.getPrintInformation().setPreSliced(True)
|
print_information.setPreSliced(True)
|
||||||
|
else:
|
||||||
|
self.getBackend().continueSlicing()
|
||||||
|
self.setHideSettings(False)
|
||||||
|
if print_information:
|
||||||
|
print_information.setPreSliced(False)
|
||||||
|
|
||||||
if not scene_bounding_box:
|
if not scene_bounding_box:
|
||||||
scene_bounding_box = AxisAlignedBox.Null
|
scene_bounding_box = AxisAlignedBox.Null
|
||||||
|
|
|
@ -116,7 +116,6 @@ class CuraEngineBackend(Backend):
|
||||||
|
|
||||||
self.backendQuit.connect(self._onBackendQuit)
|
self.backendQuit.connect(self._onBackendQuit)
|
||||||
self.backendConnected.connect(self._onBackendConnected)
|
self.backendConnected.connect(self._onBackendConnected)
|
||||||
self.backendStateChange.connect(self._onBackendStateChanged)
|
|
||||||
|
|
||||||
# When a tool operation is in progress, don't slice. So we need to listen for tool operations.
|
# When a tool operation is in progress, don't slice. So we need to listen for tool operations.
|
||||||
Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
|
Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
|
||||||
|
@ -188,22 +187,16 @@ class CuraEngineBackend(Backend):
|
||||||
self._start_slice_job.start()
|
self._start_slice_job.start()
|
||||||
self._start_slice_job.finished.connect(self._onStartSliceCompleted)
|
self._start_slice_job.finished.connect(self._onStartSliceCompleted)
|
||||||
|
|
||||||
_last_state = BackendState.NotStarted
|
|
||||||
|
|
||||||
def pauseSlicing(self):
|
def pauseSlicing(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
self._pause_slicing = True
|
||||||
self.backendStateChange.emit(BackendState.SlicingDisabled)
|
self.backendStateChange.emit(BackendState.SlicingDisabled)
|
||||||
|
|
||||||
def continueSlicing(self):
|
def continueSlicing(self):
|
||||||
if self._last_state == BackendState.SlicingDisabled:
|
if self._pause_slicing:
|
||||||
self.backendStateChange.emit(BackendState.NotStarted)
|
|
||||||
|
|
||||||
def _onBackendStateChanged(self, state):
|
|
||||||
self._last_state = state
|
|
||||||
if state == BackendState.SlicingDisabled:
|
|
||||||
self._pause_slicing = True
|
|
||||||
else:
|
|
||||||
self._pause_slicing = False
|
self._pause_slicing = False
|
||||||
|
self.backendStateChange.emit(BackendState.NotStarted)
|
||||||
|
|
||||||
## Terminate the engine process.
|
## Terminate the engine process.
|
||||||
def _terminate(self):
|
def _terminate(self):
|
||||||
|
|
|
@ -47,12 +47,13 @@ class GCodeReader(MeshReader):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _getValue(line, code):
|
def _getValue(line, code):
|
||||||
n = line.find(code) + len(code)
|
n = line.find(code)
|
||||||
if n < 1:
|
if n < 0:
|
||||||
return None
|
return None
|
||||||
|
n += len(code)
|
||||||
pattern = re.compile("[;\s]")
|
pattern = re.compile("[;\s]")
|
||||||
match = pattern.search(line, n)
|
match = pattern.search(line, n)
|
||||||
m = match.start() if math is not None else -1
|
m = match.start() if match is not None else -1
|
||||||
try:
|
try:
|
||||||
if m < 0:
|
if m < 0:
|
||||||
return line[n:]
|
return line[n:]
|
||||||
|
@ -91,7 +92,7 @@ class GCodeReader(MeshReader):
|
||||||
return False
|
return False
|
||||||
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][1])
|
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._prev_z))
|
||||||
this_layer = self._layer_data_builder.getLayer(self._layer)
|
this_layer = self._layer_data_builder.getLayer(self._layer)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -120,7 +121,8 @@ 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
|
xp, yp, zp, ep = params
|
||||||
x, y = xp if xp is not None else x, yp if yp is not None else y
|
x = xp if xp is not None else x
|
||||||
|
y = yp if yp is not None else y
|
||||||
z_changed = False
|
z_changed = False
|
||||||
if zp is not None:
|
if zp is not None:
|
||||||
if z != zp:
|
if z != zp:
|
||||||
|
@ -142,39 +144,37 @@ class GCodeReader(MeshReader):
|
||||||
path.clear()
|
path.clear()
|
||||||
else:
|
else:
|
||||||
path.clear()
|
path.clear()
|
||||||
return x, y, z, e
|
return (x, y, z, e)
|
||||||
|
|
||||||
def _gCode28(self, position, params, path):
|
def _gCode28(self, position, params, path):
|
||||||
x, y, z, e = position
|
x, y, z, e = position
|
||||||
xp, yp, zp, ep = params
|
xp, yp, zp, ep = params
|
||||||
return xp if xp is not None else x,\
|
return (xp if xp is not None else x,
|
||||||
yp if yp is not None else y,\
|
yp if yp is not None else y,
|
||||||
0,\
|
0,
|
||||||
e
|
e)
|
||||||
|
|
||||||
def _gCode92(self, position, params, path):
|
def _gCode92(self, position, params, path):
|
||||||
x, y, z, e = position
|
x, y, z, e = position
|
||||||
xp, yp, zp, ep = params
|
xp, yp, zp, ep = params
|
||||||
return xp if xp is not None else x,\
|
return (xp if xp is not None else x,
|
||||||
yp if yp is not None else y,\
|
yp if yp is not None else y,
|
||||||
zp if zp is not None else z,\
|
zp if zp is not None else z,
|
||||||
ep if ep is not None else e
|
ep if ep is not None else e)
|
||||||
|
|
||||||
_g_code_map = {0: _gCode0, 1: _gCode0, 28: _gCode28, 92: _gCode92}
|
_gCode1 = _gCode0
|
||||||
|
|
||||||
def _processGCode(self, G, line, position, path):
|
def _processGCode(self, G, line, position, path):
|
||||||
func = self._g_code_map.get(G, None)
|
func = getattr(self, "_gCode%s" % G, None)
|
||||||
x = self._getFloat(line, "X")
|
x = self._getFloat(line, "X")
|
||||||
y = self._getFloat(line, "Y")
|
y = self._getFloat(line, "Y")
|
||||||
z = self._getFloat(line, "Z")
|
z = self._getFloat(line, "Z")
|
||||||
e = self._getFloat(line, "E")
|
e = self._getFloat(line, "E")
|
||||||
if x is not None and x < 0:
|
|
||||||
self._center_is_zero = True
|
|
||||||
if y is not None and y < 0:
|
|
||||||
self._center_is_zero = True
|
|
||||||
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):
|
||||||
|
self._center_is_zero = True
|
||||||
params = (x, y, z, e)
|
params = (x, y, z, e)
|
||||||
return func(self, position, params, path)
|
return func(position, params, path)
|
||||||
return position
|
return position
|
||||||
|
|
||||||
def _processTCode(self, T, line, position, path):
|
def _processTCode(self, T, line, position, path):
|
||||||
|
@ -186,6 +186,8 @@ class GCodeReader(MeshReader):
|
||||||
else:
|
else:
|
||||||
path.clear()
|
path.clear()
|
||||||
|
|
||||||
|
_type_keyword = ";TYPE:"
|
||||||
|
|
||||||
def read(self, file_name):
|
def read(self, file_name):
|
||||||
Logger.log("d", "Preparing to load %s" % file_name)
|
Logger.log("d", "Preparing to load %s" % file_name)
|
||||||
self._cancelled = False
|
self._cancelled = False
|
||||||
|
@ -194,7 +196,7 @@ class GCodeReader(MeshReader):
|
||||||
scene_node.getBoundingBox = self._getNullBoundingBox # Manually set bounding box, because mesh doesn't have mesh data
|
scene_node.getBoundingBox = self._getNullBoundingBox # Manually set bounding box, because mesh doesn't have mesh data
|
||||||
|
|
||||||
glist = []
|
glist = []
|
||||||
Application.getInstance().getController().getScene().gcode_list = glist
|
|
||||||
|
|
||||||
Logger.log("d", "Opening file %s" % file_name)
|
Logger.log("d", "Opening file %s" % file_name)
|
||||||
|
|
||||||
|
@ -209,7 +211,7 @@ class GCodeReader(MeshReader):
|
||||||
|
|
||||||
self._clearValues()
|
self._clearValues()
|
||||||
|
|
||||||
self._message = Message(catalog.i18nc("@info:status", "Parsing GCODE"), lifetime=0)
|
self._message = Message(catalog.i18nc("@info:status", "Parsing G-code"), lifetime=0)
|
||||||
self._message.setProgress(0)
|
self._message.setProgress(0)
|
||||||
self._message.show()
|
self._message.show()
|
||||||
|
|
||||||
|
@ -227,8 +229,8 @@ class GCodeReader(MeshReader):
|
||||||
self._message.setProgress(math.floor(current_line / file_lines * 100))
|
self._message.setProgress(math.floor(current_line / file_lines * 100))
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
continue
|
continue
|
||||||
if line.find(";TYPE:") == 0:
|
if line.find(self._type_keyword) == 0:
|
||||||
type = line[6:].strip()
|
type = line[len(self._type_keyword):].strip()
|
||||||
if type == "WALL-INNER":
|
if type == "WALL-INNER":
|
||||||
self._layer_type = LayerPolygon.InsetXType
|
self._layer_type = LayerPolygon.InsetXType
|
||||||
elif type == "WALL-OUTER":
|
elif type == "WALL-OUTER":
|
||||||
|
@ -266,6 +268,8 @@ class GCodeReader(MeshReader):
|
||||||
sliceable_decorator.setSliceable(False)
|
sliceable_decorator.setSliceable(False)
|
||||||
scene_node.addDecorator(sliceable_decorator)
|
scene_node.addDecorator(sliceable_decorator)
|
||||||
|
|
||||||
|
Application.getInstance().getController().getScene().gcode_list = glist
|
||||||
|
|
||||||
Logger.log("d", "Finished parsing %s" % file_name)
|
Logger.log("d", "Finished parsing %s" % file_name)
|
||||||
self._message.hide()
|
self._message.hide()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue