mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
T466: Only one gcode file can be loaded at a time, and deleting previous gcode file when loading non-gcode file
Merge changes : Only call backgroundItem.hasMesh if/on an imported model (skips if only curaprofiles get loaded)
This commit is contained in:
parent
1f84ad7084
commit
b4a7173a61
4 changed files with 67 additions and 12 deletions
|
@ -19,6 +19,9 @@ from UM.SaveFile import SaveFile
|
|||
from UM.Scene.Selection import Selection
|
||||
from UM.Scene.GroupDecorator import GroupDecorator
|
||||
from UM.Settings.Validator import Validator
|
||||
from types import MethodType
|
||||
|
||||
from UM.Qt.Bindings.MeshFileHandlerProxy import MeshFileHandlerProxy
|
||||
|
||||
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
||||
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
|
||||
|
@ -535,6 +538,54 @@ class CuraApplication(QtApplication):
|
|||
|
||||
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
|
||||
|
||||
loadingFiles = []
|
||||
|
||||
@pyqtSlot(QUrl)
|
||||
def loadFile(self, file):
|
||||
scene = self.getController().getScene()
|
||||
|
||||
def findAny():
|
||||
for node1 in DepthFirstIterator(scene.getRoot()):
|
||||
if hasattr(node1, "gcode") and getattr(node1, "gcode") is True:
|
||||
return True
|
||||
return False
|
||||
if findAny():
|
||||
self.deleteAll()
|
||||
|
||||
if not file.isValid():
|
||||
return
|
||||
|
||||
supported_extensions = [".gcode", ".g"]
|
||||
|
||||
f = file.toLocalFile()
|
||||
|
||||
if len(self.loadingFiles) > 0:
|
||||
extension = os.path.splitext(f)[1]
|
||||
if extension.lower() in supported_extensions:
|
||||
return
|
||||
extension = os.path.splitext(self.loadingFiles[0])[1]
|
||||
if extension.lower() in supported_extensions:
|
||||
return
|
||||
|
||||
self.loadingFiles.append(f)
|
||||
|
||||
job = ReadMeshJob(f)
|
||||
job.finished.connect(self._readMeshFinished)
|
||||
job.start()
|
||||
|
||||
def _readMeshFinished(self, job):
|
||||
node = job.getResult()
|
||||
if node != None:
|
||||
filename = job.getFileName()
|
||||
node.setSelectable(True)
|
||||
node.setName(filename)
|
||||
self.loadingFiles.remove(filename)
|
||||
|
||||
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():
|
||||
|
|
|
@ -14,11 +14,13 @@ from UM.Math.AxisAlignedBox import AxisAlignedBox
|
|||
from UM.Application import Application
|
||||
from UM.Preferences import Preferences
|
||||
|
||||
|
||||
from cura import LayerDataBuilder
|
||||
from cura import LayerDataDecorator
|
||||
from cura import LayerPolygon
|
||||
|
||||
import numpy
|
||||
from types import MethodType
|
||||
|
||||
|
||||
from UM.Job import Job
|
||||
|
|
|
@ -269,16 +269,16 @@ UM.MainWindow
|
|||
if(drop.urls.length > 0)
|
||||
{
|
||||
// Import models
|
||||
var imported_model = -1;
|
||||
for(var i in drop.urls)
|
||||
{
|
||||
// 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
|
||||
UM.MeshFileHandler.readLocalFile(drop.urls[i]);
|
||||
if (i == drop.urls.length - 1)
|
||||
Printer.loadFile(drop.urls[i]);
|
||||
if (imported_model == -1)
|
||||
{
|
||||
var meshName = backgroundItem.getMeshName(drop.urls[i].toString());
|
||||
backgroundItem.hasMesh(decodeURIComponent(meshName));
|
||||
imported_model = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +297,11 @@ UM.MainWindow
|
|||
}
|
||||
messageDialog.open()
|
||||
}
|
||||
if (imported_model != -1)
|
||||
{
|
||||
var meshName = backgroundItem.getMeshName(drop.urls[imported_model].toString())
|
||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -732,14 +737,11 @@ UM.MainWindow
|
|||
|
||||
for(var i in fileUrls)
|
||||
{
|
||||
UM.MeshFileHandler.readLocalFile(fileUrls[i])
|
||||
|
||||
if (i == fileUrls.length - 1)
|
||||
{
|
||||
var meshName = backgroundItem.getMeshName(fileUrls.toString())
|
||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||
}
|
||||
Printer.loadFile(fileUrls[i])
|
||||
}
|
||||
|
||||
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())
|
||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ Menu
|
|||
return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
|
||||
}
|
||||
onTriggered: {
|
||||
UM.MeshFileHandler.readLocalFile(modelData);
|
||||
Printer.loadFile(modelData);
|
||||
var meshName = backgroundItem.getMeshName(modelData.toString())
|
||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue