Merge master into material marketplace

This commit is contained in:
Lipu Fei 2018-05-01 11:56:34 +02:00
commit 9a5fb47a6e
228 changed files with 125261 additions and 4020 deletions

View file

@ -1,4 +1,4 @@
# Copyright (c) 2017 Ultimaker B.V.
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os.path
@ -22,12 +22,10 @@ from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Settings.InstanceContainer import InstanceContainer
from UM.MimeTypeDatabase import MimeTypeNotFoundError
from UM.Settings.ContainerFormatError import ContainerFormatError
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.i18n import i18nCatalog
from cura.Settings.ExtruderManager import ExtruderManager
from cura.Settings.ExtruderStack import ExtruderStack
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
@ -289,7 +287,9 @@ class ContainerManager(QObject):
with open(file_url, "rt", encoding = "utf-8") as f:
container.deserialize(f.read())
except PermissionError:
return {"status": "error", "message": "Permission denied when trying to read the file"}
return {"status": "error", "message": "Permission denied when trying to read the file."}
except ContainerFormatError:
return {"status": "error", "Message": "The material file appears to be corrupt."}
except Exception as ex:
return {"status": "error", "message": str(ex)}

View file

@ -1,4 +1,4 @@
# Copyright (c) 2017 Ultimaker B.V.
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os
@ -10,6 +10,7 @@ from typing import Optional
from PyQt5.QtWidgets import QMessageBox
from UM.Decorators import override
from UM.Settings.ContainerFormatError import ContainerFormatError
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.ContainerStack import ContainerStack
from UM.Settings.InstanceContainer import InstanceContainer
@ -189,7 +190,7 @@ class CuraContainerRegistry(ContainerRegistry):
return { "status": "ok", "message": catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "No custom profile to import in file <filename>{0}</filename>", file_name)}
except Exception as e:
# Note that this will fail quickly. That is, if any profile reader throws an exception, it will stop reading. It will only continue reading if the reader returned None.
Logger.log("e", "Failed to import profile from %s: %s while using profile reader. Got exception %s", file_name,profile_reader.getPluginId(), str(e))
Logger.log("e", "Failed to import profile from %s: %s while using profile reader. Got exception %s", file_name, profile_reader.getPluginId(), str(e))
return { "status": "error", "message": catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Failed to import profile from <filename>{0}</filename>: <message>{1}</message>", file_name, "\n" + str(e))}
if profile_or_list:
@ -418,7 +419,6 @@ class CuraContainerRegistry(ContainerRegistry):
Logger.log("d", "Converting ContainerStack {stack} to {type}", stack = container.getId(), type = container_type)
new_stack = None
if container_type == "extruder_train":
new_stack = ExtruderStack.ExtruderStack(container.getId())
else:
@ -704,7 +704,11 @@ class CuraContainerRegistry(ContainerRegistry):
instance_container = InstanceContainer(container_id)
with open(file_path, "r", encoding = "utf-8") as f:
serialized = f.read()
instance_container.deserialize(serialized, file_path)
try:
instance_container.deserialize(serialized, file_path)
except ContainerFormatError:
Logger.logException("e", "Unable to deserialize InstanceContainer %s", file_path)
continue
self.addContainer(instance_container)
break

View file

@ -283,6 +283,13 @@ class CuraContainerStack(ContainerStack):
self._containers = new_containers
# CURA-5281
# Some stacks can have empty definition_changes containers which will cause problems.
# Make sure that all stacks here have non-empty definition_changes containers.
if isinstance(new_containers[_ContainerIndexes.DefinitionChanges], type(self._empty_instance_container)):
from cura.Settings.CuraStackBuilder import CuraStackBuilder
CuraStackBuilder.createDefinitionChangesContainer(self, self.getId() + "_settings")
## protected:
# Helper to make sure we emit a PyQt signal on container changes.

View file

@ -74,6 +74,7 @@ class MachineManager(QObject):
self._stacks_have_errors = None # type:Optional[bool]
self._empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
self._empty_definition_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_definition_changes")[0]
self._empty_variant_container = ContainerRegistry.getInstance().findContainers(id = "empty_variant")[0]
self._empty_material_container = ContainerRegistry.getInstance().findContainers(id = "empty_material")[0]
@ -310,19 +311,40 @@ class MachineManager(QObject):
global_quality_changes = global_stack.qualityChanges
global_quality_changes_name = global_quality_changes.getName()
# Try to set the same quality/quality_changes as the machine specified.
# If the quality/quality_changes is not available, switch to the default or the first quality that's available.
same_quality_found = False
quality_groups = self._application.getQualityManager().getQualityGroups(global_stack)
if global_quality_changes.getId() != "empty_quality_changes":
quality_changes_groups = self._application._quality_manager.getQualityChangesGroups(global_stack)
if global_quality_changes_name in quality_changes_groups:
new_quality_changes_group = quality_changes_groups[global_quality_changes_name]
quality_changes_groups = self._application.getQualityManager().getQualityChangesGroups(global_stack)
new_quality_changes_group = quality_changes_groups.get(global_quality_changes_name)
if new_quality_changes_group is not None:
self._setQualityChangesGroup(new_quality_changes_group)
same_quality_found = True
Logger.log("i", "Machine '%s' quality changes set to '%s'",
global_stack.getName(), new_quality_changes_group.name)
else:
quality_groups = self._application._quality_manager.getQualityGroups(global_stack)
if quality_type not in quality_groups:
Logger.log("w", "Quality type [%s] not found in available qualities [%s]", quality_type, ", ".join(quality_groups.keys()))
self._setEmptyQuality()
return
new_quality_group = quality_groups[quality_type]
self._setQualityGroup(new_quality_group, empty_quality_changes = True)
new_quality_group = quality_groups.get(quality_type)
if new_quality_group is not None:
self._setQualityGroup(new_quality_group, empty_quality_changes = True)
same_quality_found = True
Logger.log("i", "Machine '%s' quality set to '%s'",
global_stack.getName(), new_quality_group.quality_type)
# Could not find the specified quality/quality_changes, switch to the preferred quality if available,
# otherwise the first quality that's available, otherwise empty (not supported).
if not same_quality_found:
Logger.log("i", "Machine '%s' could not find quality_type '%s' and quality_changes '%s'. "
"Available quality types are [%s]. Switching to default quality.",
global_stack.getName(), quality_type, global_quality_changes_name,
", ".join(quality_groups.keys()))
preferred_quality_type = global_stack.getMetaDataEntry("preferred_quality_type")
quality_group = quality_groups.get(preferred_quality_type)
if quality_group is None:
if quality_groups:
quality_group = list(quality_groups.values())[0]
self._setQualityGroup(quality_group, empty_quality_changes = True)
@pyqtSlot(str)
def setActiveMachine(self, stack_id: str) -> None:
@ -1012,6 +1034,10 @@ class MachineManager(QObject):
if empty_quality_changes:
self._current_quality_changes_group = None
if quality_group is None:
self._setEmptyQuality()
return
# Set quality and quality_changes for the GlobalStack
self._global_container_stack.quality = quality_group.node_for_global.getContainer()
if empty_quality_changes:
@ -1123,13 +1149,15 @@ class MachineManager(QObject):
Logger.log("d", "Current quality type = [%s]", current_quality_type)
if not self.activeMaterialsCompatible():
Logger.log("i", "Active materials are not compatible, setting all qualities to empty (Not Supported).")
self._setEmptyQuality()
if current_quality_type is not None:
Logger.log("i", "Active materials are not compatible, setting all qualities to empty (Not Supported).")
self._setEmptyQuality()
return
if not available_quality_types:
Logger.log("i", "No available quality types found, setting all qualities to empty (Not Supported).")
self._setEmptyQuality()
if self._current_quality_changes_group is None:
Logger.log("i", "No available quality types found, setting all qualities to empty (Not Supported).")
self._setEmptyQuality()
return
if current_quality_type in available_quality_types:

View file

@ -82,8 +82,9 @@ class SettingInheritanceManager(QObject):
def _onActiveExtruderChanged(self):
new_active_stack = ExtruderManager.getInstance().getActiveExtruderStack()
# if not new_active_stack:
# new_active_stack = self._global_container_stack
if not new_active_stack:
self._active_container_stack = None
return
if new_active_stack != self._active_container_stack: # Check if changed
if self._active_container_stack: # Disconnect signal from old container (if any)
@ -154,6 +155,8 @@ class SettingInheritanceManager(QObject):
has_setting_function = False
if not stack:
stack = self._active_container_stack
if not stack: #No active container stack yet!
return False
containers = []
## Check if the setting has a user state. If not, it is never overwritten.