D5: Moved loading files code

This commit is contained in:
Victor Larchenko 2016-11-23 11:32:18 +06:00 committed by Youness Alaoui
parent cd7979e301
commit c18b3149da
5 changed files with 24 additions and 79 deletions

View file

@ -539,9 +539,6 @@ class CuraApplication(QtApplication):
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
loadingFiles = []
non_sliceable_extensions = [".gcode", ".g"]
changeLayerViewSignal = pyqtSignal()
def changeToLayerView(self):
@ -551,63 +548,6 @@ class CuraApplication(QtApplication):
view.setLayer(999999)
view.calculateMaxLayers()
@pyqtSlot(QUrl)
def loadFile(self, file):
scene = self.getController().getScene()
if not file.isValid():
return
for node in DepthFirstIterator(scene.getRoot()):
if hasattr(node, "gcode") and getattr(node, "gcode") is True:
self.deleteAll()
break
f = file.toLocalFile()
extension = os.path.splitext(f)[1]
filename = os.path.basename(f)
if len(self.loadingFiles) > 0:
# If a non-slicable file is already being loaded, we prevent loading of any further non-slicable files
if extension.lower() in self.non_sliceable_extensions:
message = Message(
catalog.i18nc("@info:status", "Only one G-code file can be loaded at a time. Skipped importing {0}",
filename))
message.show()
return
# If file being loaded is non-slicable file, then prevent loading of any other files
extension = os.path.splitext(self.loadingFiles[0])[1]
if extension.lower() in self.non_sliceable_extensions:
message = Message(
catalog.i18nc("@info:status",
"Can't open any other file if G-code is loading. Skipped importing {0}",
filename))
message.show()
return
self.loadingFiles.append(f)
job = ReadMeshJob(f)
job.finished.connect(self._readMeshFinished)
job.start()
def _readMeshFinished(self, job):
node = job.getResult()
filename = job.getFileName()
self.loadingFiles.remove(filename)
if node != None:
node.setSelectable(True)
node.setName(os.path.basename(filename))
extension = os.path.splitext(filename)[1]
if extension.lower() in self.non_sliceable_extensions:
self.changeLayerViewSignal.emit()
op = AddSceneNodeOperation(node, self.getController().getScene().getRoot())
op.push()
self.getController().getScene().sceneChanged.emit(node)
def onSelectionChanged(self):
if Selection.hasSelection():
if self.getController().getActiveTool():

View file

@ -188,6 +188,13 @@ class CuraEngineBackend(Backend):
self._start_slice_job.start()
self._start_slice_job.finished.connect(self._onStartSliceCompleted)
def pauseSlicing(self):
self.close()
self.backendStateChange.emit(BackendState.SlicingDisabled)
def continueSlicing(self):
self.backendStateChange.emit(BackendState.NotStarted)
def _onBackendStateChanged(self, state):
if state == BackendState.SlicingDisabled:
self._pause_slicing = True

View file

@ -22,6 +22,7 @@ from cura.LayerPolygon import LayerPolygon
import numpy
import math
import re
class GCodeReader(MeshReader):
@ -39,7 +40,9 @@ class GCodeReader(MeshReader):
n = line.find(code) + len(code)
if n < 1:
return None
m = line.find(' ', n)
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:]
@ -66,23 +69,18 @@ class GCodeReader(MeshReader):
self._cancelled = True
def _onParentChanged(self, node):
backend = Application.getInstance().getBackend()
if self._scene_node is not None and self._scene_node.getParent() is None:
self._scene_node = None
backend.backendStateChange.emit(BackendState.NotStarted)
Application.getInstance().getBackend().continueSlicing()
Application.getInstance().setHideSettings(False)
Application.getInstance().getPrintInformation().setPreSliced(False)
# else:
# backend.backendStateChange.emit(BackendState.SlicingDisabled)
# Application.getInstance().getPrintInformation().setPreSliced(True)
# Application.getInstance().setHideSettings(True)
@staticmethod
def _getNullBoundingBox():
return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10))
@staticmethod
def _createPolygon(layer_data, path, layer_id, extruder):
def _createPolygon(layer_data, path, layer_id, extruder, thickness):
countvalid = 0
for point in path:
if point[3] > 0:
@ -92,7 +90,7 @@ class GCodeReader(MeshReader):
try:
layer_data.addLayer(layer_id)
layer_data.setLayerHeight(layer_id, path[0][1])
layer_data.setLayerThickness(layer_id, 0.25)
layer_data.setLayerThickness(layer_id, thickness)
this_layer = layer_data.getLayer(layer_id)
except ValueError:
return False
@ -128,9 +126,7 @@ class GCodeReader(MeshReader):
self._scene_node.gcode = True
self._scene_node.parentChanged.connect(self._onParentChanged)
backend = Application.getInstance().getBackend()
backend.close()
backend.backendStateChange.emit(BackendState.SlicingDisabled)
Application.getInstance().getBackend().pauseSlicing()
glist = []
Application.getInstance().getController().getScene().gcode_list = glist
@ -155,6 +151,7 @@ class GCodeReader(MeshReader):
current_z = 0
current_e = 0
current_layer = 0
prev_z = 0
self._message = Message(catalog.i18nc("@info:status", "Parsing GCODE"), lifetime=0)
self._message.setProgress(0)
@ -188,6 +185,7 @@ class GCodeReader(MeshReader):
if z is not None:
if not current_z == z:
z_changed = True
prev_z = current_z
current_z = z
if e is not None:
if e > current_e:
@ -196,10 +194,10 @@ class GCodeReader(MeshReader):
current_path.append([current_x, current_y, current_z, LayerPolygon.MoveRetractionType]) # retraction
current_e = e
else:
current_path.append([current_x, current_y, current_z, LayerPolygon.NoneType])
current_path.append([current_x, current_y, current_z, LayerPolygon.MoveCombingType])
if z_changed:
if len(current_path) > 1 and current_z > 0:
if self._createPolygon(layer_data_builder, current_path, current_layer, current_extruder):
if self._createPolygon(layer_data_builder, current_path, current_layer, current_extruder, math.fabs(current_z - prev_z)):
current_layer += 1
current_path.clear()
else:
@ -231,14 +229,14 @@ class GCodeReader(MeshReader):
if T is not None:
current_extruder = T
if len(current_path) > 1 and current_z > 0:
if self._createPolygon(layer_data_builder, current_path, current_layer, current_extruder):
if self._createPolygon(layer_data_builder, current_path, current_layer, current_extruder, math.fabs(current_z - prev_z)):
current_layer += 1
current_path.clear()
else:
current_path.clear()
if len(current_path) > 1 and current_z > 0:
if self._createPolygon(layer_data_builder, current_path, current_layer, current_extruder):
if self._createPolygon(layer_data_builder, current_path, current_layer, current_extruder, math.fabs(current_z - prev_z)):
current_layer += 1
current_path.clear()

View file

@ -275,7 +275,7 @@ UM.MainWindow
// There is no endsWith in this version of JS...
if ((drop.urls[i].length <= 12) || (drop.urls[i].substring(drop.urls[i].length-12) !== ".curaprofile")) {
// Drop an object
Printer.loadFile(drop.urls[i]);
UM.MeshFileHandler.readLocalFile(drop.urls[i]);
if (imported_model == -1)
{
imported_model = i;
@ -737,7 +737,7 @@ UM.MainWindow
for(var i in fileUrls)
{
Printer.loadFile(fileUrls[i])
UM.MeshFileHandler.readLocalFile(fileUrls[i])
}
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())

View file

@ -26,7 +26,7 @@ Menu
return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
}
onTriggered: {
Printer.loadFile(modelData);
UM.MeshFileHandler.readLocalFile(modelData);
var meshName = backgroundItem.getMeshName(modelData.toString())
backgroundItem.hasMesh(decodeURIComponent(meshName))
}