mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 16:27:51 -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.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 types import MethodType
|
||||||
|
|
||||||
|
from UM.Qt.Bindings.MeshFileHandlerProxy import MeshFileHandlerProxy
|
||||||
|
|
||||||
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
||||||
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
|
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
|
||||||
|
@ -535,6 +538,54 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
|
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):
|
def onSelectionChanged(self):
|
||||||
if Selection.hasSelection():
|
if Selection.hasSelection():
|
||||||
if self.getController().getActiveTool():
|
if self.getController().getActiveTool():
|
||||||
|
|
|
@ -14,11 +14,13 @@ from UM.Math.AxisAlignedBox import AxisAlignedBox
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Preferences import Preferences
|
from UM.Preferences import Preferences
|
||||||
|
|
||||||
|
|
||||||
from cura import LayerDataBuilder
|
from cura import LayerDataBuilder
|
||||||
from cura import LayerDataDecorator
|
from cura import LayerDataDecorator
|
||||||
from cura import LayerPolygon
|
from cura import LayerPolygon
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
from types import MethodType
|
||||||
|
|
||||||
|
|
||||||
from UM.Job import Job
|
from UM.Job import Job
|
||||||
|
|
|
@ -269,16 +269,16 @@ UM.MainWindow
|
||||||
if(drop.urls.length > 0)
|
if(drop.urls.length > 0)
|
||||||
{
|
{
|
||||||
// Import models
|
// Import models
|
||||||
|
var imported_model = -1;
|
||||||
for(var i in drop.urls)
|
for(var i in drop.urls)
|
||||||
{
|
{
|
||||||
// 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.loadFile(drop.urls[i]);
|
||||||
if (i == drop.urls.length - 1)
|
if (imported_model == -1)
|
||||||
{
|
{
|
||||||
var meshName = backgroundItem.getMeshName(drop.urls[i].toString());
|
imported_model = i;
|
||||||
backgroundItem.hasMesh(decodeURIComponent(meshName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,6 +297,11 @@ UM.MainWindow
|
||||||
}
|
}
|
||||||
messageDialog.open()
|
messageDialog.open()
|
||||||
}
|
}
|
||||||
|
if (imported_model != -1)
|
||||||
|
{
|
||||||
|
var meshName = backgroundItem.getMeshName(drop.urls[imported_model].toString())
|
||||||
|
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -732,16 +737,13 @@ UM.MainWindow
|
||||||
|
|
||||||
for(var i in fileUrls)
|
for(var i in fileUrls)
|
||||||
{
|
{
|
||||||
UM.MeshFileHandler.readLocalFile(fileUrls[i])
|
Printer.loadFile(fileUrls[i])
|
||||||
|
}
|
||||||
|
|
||||||
if (i == fileUrls.length - 1)
|
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())
|
||||||
{
|
|
||||||
var meshName = backgroundItem.getMeshName(fileUrls.toString())
|
|
||||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
|
|
|
@ -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.loadFile(modelData);
|
||||||
var meshName = backgroundItem.getMeshName(modelData.toString())
|
var meshName = backgroundItem.getMeshName(modelData.toString())
|
||||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue