mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-22 05:39:37 +08:00
D6: Moved file loading code
This commit is contained in:
parent
26fe0ddbb5
commit
3605403314
@ -1031,4 +1031,68 @@ class CuraApplication(QtApplication):
|
|||||||
def log(self, msg):
|
def log(self, msg):
|
||||||
Logger.log("d", msg)
|
Logger.log("d", msg)
|
||||||
|
|
||||||
|
_loading_files = []
|
||||||
|
_non_sliceable_extensions = [".gcode", ".g"]
|
||||||
|
|
||||||
|
@pyqtSlot(QUrl)
|
||||||
|
def readLocalFile(self, file):
|
||||||
|
if not file.isValid():
|
||||||
|
return
|
||||||
|
|
||||||
|
scene = self.getController().getScene()
|
||||||
|
|
||||||
|
for node in DepthFirstIterator(scene.getRoot()):
|
||||||
|
if node.callDecoration("shouldBlockSlicing"):
|
||||||
|
self.deleteAll()
|
||||||
|
break
|
||||||
|
|
||||||
|
f = file.toLocalFile()
|
||||||
|
extension = os.path.splitext(f)[1]
|
||||||
|
filename = os.path.basename(f)
|
||||||
|
if len(self._loading_files) > 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(
|
||||||
|
self._i18n_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._loading_files[0])[1]
|
||||||
|
if extension.lower() in self._non_sliceable_extensions:
|
||||||
|
message = Message(
|
||||||
|
self._i18n_catalog.i18nc("@info:status",
|
||||||
|
"Can't open any other file if G-code is loading. Skipped importing {0}",
|
||||||
|
filename))
|
||||||
|
message.show()
|
||||||
|
return
|
||||||
|
|
||||||
|
self._loading_files.append(f)
|
||||||
|
if extension in self._non_sliceable_extensions:
|
||||||
|
self.deleteAll()
|
||||||
|
|
||||||
|
job = ReadMeshJob(f)
|
||||||
|
job.finished.connect(self._readMeshFinished)
|
||||||
|
job.start()
|
||||||
|
|
||||||
|
def _readMeshFinished(self, job):
|
||||||
|
node = job.getResult()
|
||||||
|
filename = job.getFileName()
|
||||||
|
self._loading_files.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()
|
||||||
|
|
||||||
|
scene = self.getController().getScene()
|
||||||
|
|
||||||
|
op = AddSceneNodeOperation(node, scene.getRoot())
|
||||||
|
op.push()
|
||||||
|
|
||||||
|
scene.sceneChanged.emit(node)
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ class CuraEngineBackend(Backend):
|
|||||||
def pauseSlicing(self):
|
def pauseSlicing(self):
|
||||||
self.close()
|
self.close()
|
||||||
self._pause_slicing = True
|
self._pause_slicing = True
|
||||||
self.backendStateChange.emit(BackendState.SlicingDisabled)
|
self.backendStateChange.emit(BackendState.Disabled)
|
||||||
|
|
||||||
def continueSlicing(self):
|
def continueSlicing(self):
|
||||||
if self._pause_slicing:
|
if self._pause_slicing:
|
||||||
|
@ -223,7 +223,7 @@ class GCodeReader(MeshReader):
|
|||||||
|
|
||||||
for line in file:
|
for line in file:
|
||||||
if self._cancelled:
|
if self._cancelled:
|
||||||
Logger.log("i", "Parsing %s cancelled" % file_name)
|
Logger.log("d", "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:
|
||||||
|
@ -275,7 +275,7 @@ UM.MainWindow
|
|||||||
// There is no endsWith in this version of JS...
|
// 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")) {
|
if ((drop.urls[i].length <= 12) || (drop.urls[i].substring(drop.urls[i].length-12) !== ".curaprofile")) {
|
||||||
// Drop an object
|
// Drop an object
|
||||||
UM.MeshFileHandler.readLocalFile(drop.urls[i]);
|
Printer.readLocalFile(drop.urls[i]);
|
||||||
if (imported_model == -1)
|
if (imported_model == -1)
|
||||||
{
|
{
|
||||||
imported_model = i;
|
imported_model = i;
|
||||||
@ -737,7 +737,7 @@ UM.MainWindow
|
|||||||
|
|
||||||
for(var i in fileUrls)
|
for(var i in fileUrls)
|
||||||
{
|
{
|
||||||
UM.MeshFileHandler.readLocalFile(fileUrls[i])
|
Printer.readLocalFile(fileUrls[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())
|
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())
|
||||||
|
@ -26,7 +26,7 @@ Menu
|
|||||||
return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
|
return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
|
||||||
}
|
}
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
UM.MeshFileHandler.readLocalFile(modelData);
|
Printer.readLocalFile(modelData);
|
||||||
var meshName = backgroundItem.getMeshName(modelData.toString())
|
var meshName = backgroundItem.getMeshName(modelData.toString())
|
||||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user