Merge branch 'master' into feature-backup-manager

This commit is contained in:
ChrisTerBeke 2018-05-08 12:50:31 +02:00
commit 62c4a88168
10 changed files with 73 additions and 27 deletions

View File

@ -16,6 +16,7 @@ from UM.Qt.Duration import Duration
from UM.Preferences import Preferences from UM.Preferences import Preferences
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from UM.MimeTypeDatabase import MimeTypeDatabase
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
@ -322,7 +323,7 @@ class PrintInformation(QObject):
# when a file is opened using the terminal; the filename comes from _onFileLoaded and still contains its # when a file is opened using the terminal; the filename comes from _onFileLoaded and still contains its
# extension. This cuts the extension off if necessary. # extension. This cuts the extension off if necessary.
name = os.path.splitext(name)[0] check_name = os.path.splitext(name)[0]
filename_parts = os.path.basename(base_name).split(".") filename_parts = os.path.basename(base_name).split(".")
# If it's a gcode, also always update the job name # If it's a gcode, also always update the job name
@ -333,25 +334,21 @@ class PrintInformation(QObject):
# if this is a profile file, always update the job name # if this is a profile file, always update the job name
# name is "" when I first had some meshes and afterwards I deleted them so the naming should start again # name is "" when I first had some meshes and afterwards I deleted them so the naming should start again
is_empty = name == "" is_empty = check_name == ""
if is_gcode or is_project_file or (is_empty or (self._base_name == "" and self._base_name != name)): if is_gcode or is_project_file or (is_empty or (self._base_name == "" and self._base_name != check_name)):
# Only take the file name part, Note : file name might have 'dot' in name as well # Only take the file name part, Note : file name might have 'dot' in name as well
if is_project_file:
# This is for .curaproject, loaded as project
self._base_name = ".".join(filename_parts)
elif len(filename_parts) > 1:
if "gcode" in filename_parts:
gcode_index = filename_parts.index('gcode')
self._base_name = ".".join(filename_parts[0:gcode_index])
elif "curaproject" in filename_parts:
#load a project and import only models
curaproject_index = filename_parts.index('curaproject')
self._base_name = ".".join(filename_parts[0:curaproject_index])
else:
self._base_name = name
else:
self._base_name = name
data = ''
try:
mime_type = MimeTypeDatabase.getMimeTypeForFile(name)
data = mime_type.stripExtension(name)
except:
Logger.log("w", "Unsupported Mime Type Database file extension")
if data is not None:
self._base_name = data
else:
self._base_name = ''
self._updateJobName() self._updateJobName()

View File

@ -402,7 +402,8 @@ class ExtruderManager(QObject):
# Register the extruder trains by position # Register the extruder trains by position
for extruder_train in extruder_trains: for extruder_train in extruder_trains:
self._extruder_trains[global_stack_id][extruder_train.getMetaDataEntry("position")] = extruder_train extruder_position = extruder_train.getMetaDataEntry("position")
self._extruder_trains[global_stack_id][extruder_position] = extruder_train
# regardless of what the next stack is, we have to set it again, because of signal routing. ??? # regardless of what the next stack is, we have to set it again, because of signal routing. ???
extruder_train.setParent(global_stack) extruder_train.setParent(global_stack)

View File

@ -38,7 +38,7 @@ class ExtruderStack(CuraContainerStack):
# #
# This will set the next stack and ensure that we register this stack as an extruder. # This will set the next stack and ensure that we register this stack as an extruder.
@override(ContainerStack) @override(ContainerStack)
def setNextStack(self, stack: CuraContainerStack) -> None: def setNextStack(self, stack: CuraContainerStack, connect_signals: bool = True) -> None:
super().setNextStack(stack) super().setNextStack(stack)
stack.addExtruder(self) stack.addExtruder(self)
self.addMetaDataEntry("machine", stack.id) self.addMetaDataEntry("machine", stack.id)

View File

@ -125,7 +125,7 @@ class GlobalStack(CuraContainerStack):
# #
# This will simply raise an exception since the Global stack cannot have a next stack. # This will simply raise an exception since the Global stack cannot have a next stack.
@override(ContainerStack) @override(ContainerStack)
def setNextStack(self, next_stack: ContainerStack) -> None: def setNextStack(self, stack: CuraContainerStack, connect_signals: bool = True) -> None:
raise Exceptions.InvalidOperationError("Global stack cannot have a next stack!") raise Exceptions.InvalidOperationError("Global stack cannot have a next stack!")
# protected: # protected:
@ -153,6 +153,23 @@ class GlobalStack(CuraContainerStack):
return True return True
## Perform some sanity checks on the global stack
# Sanity check for extruders; they must have positions 0 and up to machine_extruder_count - 1
def isValid(self):
container_registry = ContainerRegistry.getInstance()
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = self.getId())
machine_extruder_count = self.getProperty("machine_extruder_count", "value")
extruder_check_position = set()
for extruder_train in extruder_trains:
extruder_position = extruder_train.getMetaDataEntry("position")
extruder_check_position.add(extruder_position)
for check_position in range(machine_extruder_count):
if str(check_position) not in extruder_check_position:
return False
return True
## private: ## private:
global_stack_mime = MimeType( global_stack_mime = MimeType(

View File

@ -6,6 +6,7 @@ import time
#Type hinting. #Type hinting.
from typing import List, Dict, TYPE_CHECKING, Optional from typing import List, Dict, TYPE_CHECKING, Optional
from UM.ConfigurationErrorMessage import ConfigurationErrorMessage
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.InstanceContainer import InstanceContainer
from UM.Settings.Interfaces import ContainerInterface from UM.Settings.Interfaces import ContainerInterface
@ -167,8 +168,6 @@ class MachineManager(QObject):
if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id): if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id):
# An active machine was saved, so restore it. # An active machine was saved, so restore it.
self.setActiveMachine(active_machine_id) self.setActiveMachine(active_machine_id)
# Make sure _active_container_stack is properly initiated
ExtruderManager.getInstance().setActiveExtruderIndex(0)
def _onOutputDevicesChanged(self) -> None: def _onOutputDevicesChanged(self) -> None:
self._printer_output_devices = [] self._printer_output_devices = []
@ -359,6 +358,10 @@ class MachineManager(QObject):
return return
global_stack = containers[0] global_stack = containers[0]
if not global_stack.isValid():
# Mark global stack as invalid
ConfigurationErrorMessage.getInstance().addFaultyContainers(global_stack.getId())
return # We're done here
ExtruderManager.getInstance().setActiveExtruderIndex(0) # Switch to first extruder ExtruderManager.getInstance().setActiveExtruderIndex(0) # Switch to first extruder
self._global_container_stack = global_stack self._global_container_stack = global_stack
Application.getInstance().setGlobalContainerStack(global_stack) Application.getInstance().setGlobalContainerStack(global_stack)

View File

@ -15,6 +15,7 @@ from UM.Math.Vector import Vector
from UM.Mesh.MeshBuilder import MeshBuilder from UM.Mesh.MeshBuilder import MeshBuilder
from UM.Mesh.MeshReader import MeshReader from UM.Mesh.MeshReader import MeshReader
from UM.Scene.GroupDecorator import GroupDecorator from UM.Scene.GroupDecorator import GroupDecorator
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
from cura.Settings.ExtruderManager import ExtruderManager from cura.Settings.ExtruderManager import ExtruderManager
from cura.Scene.CuraSceneNode import CuraSceneNode from cura.Scene.CuraSceneNode import CuraSceneNode
@ -25,6 +26,15 @@ from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
MYPY = False MYPY = False
MimeTypeDatabase.addMimeType(
MimeType(
name = "application/x-cura-project-file",
comment = "Cura Project File",
suffixes = ["curaproject.3mf"]
)
)
try: try:
if not MYPY: if not MYPY:
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET

View File

@ -5,10 +5,20 @@ from UM.FileHandler.FileReader import FileReader
from UM.Mesh.MeshReader import MeshReader from UM.Mesh.MeshReader import MeshReader
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from UM.Preferences import Preferences from UM.Preferences import Preferences
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
from . import MarlinFlavorParser, RepRapFlavorParser from . import MarlinFlavorParser, RepRapFlavorParser
MimeTypeDatabase.addMimeType(
MimeType(
name = "application/x-cura-gcode-file",
comment = "Cura GCode File",
suffixes = ["gcode", "gcode.gz"]
)
)
# Class for loading and parsing G-code files # Class for loading and parsing G-code files
class GCodeReader(MeshReader): class GCodeReader(MeshReader):

View File

@ -66,9 +66,9 @@ class GCodeWriter(MeshWriter):
active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
scene = Application.getInstance().getController().getScene() scene = Application.getInstance().getController().getScene()
gcode_dict = getattr(scene, "gcode_dict") if not hasattr(scene, "gcode_dict"):
if not gcode_dict:
return False return False
gcode_dict = getattr(scene, "gcode_dict")
gcode_list = gcode_dict.get(active_build_plate, None) gcode_list = gcode_dict.get(active_build_plate, None)
if gcode_list is not None: if gcode_list is not None:
has_settings = False has_settings = False

View File

@ -56,8 +56,6 @@ class MachineSettingsAction(MachineAction):
if self._isEmptyDefinitionChanges(definition_changes_id): if self._isEmptyDefinitionChanges(definition_changes_id):
return return
self._container_registry.removeContainer(definition_changes_id)
def _reset(self): def _reset(self):
if not self._global_container_stack: if not self._global_container_stack:
return return

View File

@ -11,6 +11,16 @@ except ImportError:
from UM.i18n import i18nCatalog #To translate the file format description. from UM.i18n import i18nCatalog #To translate the file format description.
from UM.Mesh.MeshWriter import MeshWriter #For the binary mode flag. from UM.Mesh.MeshWriter import MeshWriter #For the binary mode flag.
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
MimeTypeDatabase.addMimeType(
MimeType(
name = "application/x-cura-stl-file",
comment = "Cura UFP File",
suffixes = ["ufp"]
)
)
i18n_catalog = i18nCatalog("cura") i18n_catalog = i18nCatalog("cura")