Merge branch 'master' into python_type_hinting

This commit is contained in:
Simon Edwards 2016-12-13 14:39:35 +01:00
commit d4619da358
132 changed files with 42584 additions and 952 deletions

View file

@ -83,20 +83,20 @@ class ThreeMFReader(MeshReader):
definition = QualityManager.getInstance().getParentMachineDefinition(global_container_stack.getBottom())
node.callDecoration("getStack").getTop().setDefinition(definition)
setting_container = node.callDecoration("getStack").getTop()
for setting in xml_settings:
setting_key = setting.get("key")
setting_value = setting.text
setting_container = node.callDecoration("getStack").getTop()
for setting in xml_settings:
setting_key = setting.get("key")
setting_value = setting.text
# Extruder_nr is a special case.
if setting_key == "extruder_nr":
extruder_stack = ExtruderManager.getInstance().getExtruderStack(int(setting_value))
if extruder_stack:
node.callDecoration("setActiveExtruder", extruder_stack.getId())
else:
Logger.log("w", "Unable to find extruder in position %s", setting_value)
continue
setting_container.setProperty(setting_key,"value", setting_value)
# Extruder_nr is a special case.
if setting_key == "extruder_nr":
extruder_stack = ExtruderManager.getInstance().getExtruderStack(int(setting_value))
if extruder_stack:
node.callDecoration("setActiveExtruder", extruder_stack.getId())
else:
Logger.log("w", "Unable to find extruder in position %s", setting_value)
continue
setting_container.setProperty(setting_key,"value", setting_value)
if len(node.getChildren()) > 0:
group_decorator = GroupDecorator()
@ -184,9 +184,22 @@ class ThreeMFReader(MeshReader):
continue
build_item_node = self._createNodeFromObject(object, self._base_name + "_" + str(id))
# compensate for original center position, if object(s) is/are not around its zero position
transform_matrix = Matrix()
mesh_data = build_item_node.getMeshData()
if mesh_data is not None:
extents = mesh_data.getExtents()
center_vector = Vector(extents.center.x, extents.center.y, extents.center.z)
transform_matrix.setByTranslation(center_vector)
# offset with transform from 3mf
transform = build_item.get("transform")
if transform is not None:
build_item_node.setTransformation(self._createMatrixFromTransformationString(transform))
transform_matrix.multiply(self._createMatrixFromTransformationString(transform))
build_item_node.setTransformation(transform_matrix)
global_container_stack = Application.getInstance().getGlobalContainerStack()
# Create a transformation Matrix to convert from 3mf worldspace into ours.

View file

@ -0,0 +1,474 @@
from UM.Workspace.WorkspaceReader import WorkspaceReader
from UM.Application import Application
from UM.Logger import Logger
from UM.i18n import i18nCatalog
from UM.Settings.ContainerStack import ContainerStack
from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Settings.InstanceContainer import InstanceContainer
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.MimeTypeDatabase import MimeTypeDatabase
from UM.Job import Job
from UM.Preferences import Preferences
from .WorkspaceDialog import WorkspaceDialog
import xml.etree.ElementTree as ET
from cura.Settings.ExtruderManager import ExtruderManager
import zipfile
import io
import configparser
i18n_catalog = i18nCatalog("cura")
## Base implementation for reading 3MF workspace files.
class ThreeMFWorkspaceReader(WorkspaceReader):
def __init__(self):
super().__init__()
self._supported_extensions = [".3mf"]
self._dialog = WorkspaceDialog()
self._3mf_mesh_reader = None
self._container_registry = ContainerRegistry.getInstance()
self._definition_container_suffix = ContainerRegistry.getMimeTypeForContainer(DefinitionContainer).preferredSuffix
self._material_container_suffix = None # We have to wait until all other plugins are loaded before we can set it
self._instance_container_suffix = ContainerRegistry.getMimeTypeForContainer(InstanceContainer).preferredSuffix
self._container_stack_suffix = ContainerRegistry.getMimeTypeForContainer(ContainerStack).preferredSuffix
self._resolve_strategies = {}
self._id_mapping = {}
## Get a unique name based on the old_id. This is different from directly calling the registry in that it caches results.
# This has nothing to do with speed, but with getting consistent new naming for instances & objects.
def getNewId(self, old_id):
if old_id not in self._id_mapping:
self._id_mapping[old_id] = self._container_registry.uniqueName(old_id)
return self._id_mapping[old_id]
def preRead(self, file_name):
self._3mf_mesh_reader = Application.getInstance().getMeshFileHandler().getReaderForFile(file_name)
if self._3mf_mesh_reader and self._3mf_mesh_reader.preRead(file_name) == WorkspaceReader.PreReadResult.accepted:
pass
else:
Logger.log("w", "Could not find reader that was able to read the scene data for 3MF workspace")
return WorkspaceReader.PreReadResult.failed
machine_name = ""
# Check if there are any conflicts, so we can ask the user.
archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
container_stack_files = [name for name in cura_file_names if name.endswith(self._container_stack_suffix)]
self._resolve_strategies = {"machine": None, "quality_changes": None, "material": None}
machine_conflict = False
quality_changes_conflict = False
for container_stack_file in container_stack_files:
container_id = self._stripFileToId(container_stack_file)
serialized = archive.open(container_stack_file).read().decode("utf-8")
if machine_name == "":
machine_name = self._getMachineNameFromSerializedStack(serialized)
stacks = self._container_registry.findContainerStacks(id=container_id)
if stacks:
# Check if there are any changes at all in any of the container stacks.
id_list = self._getContainerIdListFromSerialized(serialized)
for index, container_id in enumerate(id_list):
if stacks[0].getContainer(index).getId() != container_id:
machine_conflict = True
Job.yieldThread()
material_labels = []
material_conflict = False
xml_material_profile = self._getXmlProfileClass()
if self._material_container_suffix is None:
self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).preferredSuffix
if xml_material_profile:
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
for material_container_file in material_container_files:
container_id = self._stripFileToId(material_container_file)
materials = self._container_registry.findInstanceContainers(id=container_id)
material_labels.append(self._getMaterialLabelFromSerialized(archive.open(material_container_file).read().decode("utf-8")))
if materials and not materials[0].isReadOnly(): # Only non readonly materials can be in conflict
material_conflict = True
Job.yieldThread()
# Check if any quality_changes instance container is in conflict.
instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)]
quality_name = ""
quality_type = ""
num_settings_overriden_by_quality_changes = 0 # How many settings are changed by the quality changes
for instance_container_file in instance_container_files:
container_id = self._stripFileToId(instance_container_file)
instance_container = InstanceContainer(container_id)
# Deserialize InstanceContainer by converting read data from bytes to string
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
container_type = instance_container.getMetaDataEntry("type")
if container_type == "quality_changes":
quality_name = instance_container.getName()
num_settings_overriden_by_quality_changes += len(instance_container._instances)
# Check if quality changes already exists.
quality_changes = self._container_registry.findInstanceContainers(id = container_id)
if quality_changes:
# Check if there really is a conflict by comparing the values
if quality_changes[0] != instance_container:
quality_changes_conflict = True
elif container_type == "quality":
# If the quality name is not set (either by quality or changes, set it now)
# Quality changes should always override this (as they are "on top")
if quality_name == "":
quality_name = instance_container.getName()
quality_type = instance_container.getName()
Job.yieldThread()
num_visible_settings = 0
try:
temp_preferences = Preferences()
temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
visible_settings_string = temp_preferences.getValue("general/visible_settings")
if visible_settings_string is not None:
num_visible_settings = len(visible_settings_string.split(";"))
active_mode = temp_preferences.getValue("cura/active_mode")
if not active_mode:
active_mode = Preferences.getInstance().getValue("cura/active_mode")
except KeyError:
# If there is no preferences file, it's not a workspace, so notify user of failure.
Logger.log("w", "File %s is not a valid workspace.", file_name)
return WorkspaceReader.PreReadResult.failed
# Show the dialog, informing the user what is about to happen.
self._dialog.setMachineConflict(machine_conflict)
self._dialog.setQualityChangesConflict(quality_changes_conflict)
self._dialog.setMaterialConflict(material_conflict)
self._dialog.setNumVisibleSettings(num_visible_settings)
self._dialog.setQualityName(quality_name)
self._dialog.setQualityType(quality_type)
self._dialog.setNumSettingsOverridenByQualityChanges(num_settings_overriden_by_quality_changes)
self._dialog.setActiveMode(active_mode)
self._dialog.setMachineName(machine_name)
self._dialog.setMaterialLabels(material_labels)
self._dialog.setHasObjectsOnPlate(Application.getInstance().getPlatformActivity)
self._dialog.show()
# Block until the dialog is closed.
self._dialog.waitForClose()
if self._dialog.getResult() == {}:
return WorkspaceReader.PreReadResult.cancelled
self._resolve_strategies = self._dialog.getResult()
return WorkspaceReader.PreReadResult.accepted
def read(self, file_name):
archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
# Create a shadow copy of the preferences (we don't want all of the preferences, but we do want to re-use its
# parsing code.
temp_preferences = Preferences()
temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
# Copy a number of settings from the temp preferences to the global
global_preferences = Preferences.getInstance()
visible_settings = temp_preferences.getValue("general/visible_settings")
if visible_settings is None:
Logger.log("w", "Workspace did not contain visible settings. Leaving visibility unchanged")
else:
global_preferences.setValue("general/visible_settings", visible_settings)
categories_expanded = temp_preferences.getValue("cura/categories_expanded")
if categories_expanded is None:
Logger.log("w", "Workspace did not contain expanded categories. Leaving them unchanged")
else:
global_preferences.setValue("cura/categories_expanded", categories_expanded)
Application.getInstance().expandedCategoriesChanged.emit() # Notify the GUI of the change
self._id_mapping = {}
# We don't add containers right away, but wait right until right before the stack serialization.
# We do this so that if something goes wrong, it's easier to clean up.
containers_to_add = []
# TODO: For the moment we use pretty naive existence checking. If the ID is the same, we assume in quite a few
# TODO: cases that the container loaded is the same (most notable in materials & definitions).
# TODO: It might be possible that we need to add smarter checking in the future.
Logger.log("d", "Workspace loading is checking definitions...")
# Get all the definition files & check if they exist. If not, add them.
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
for definition_container_file in definition_container_files:
container_id = self._stripFileToId(definition_container_file)
definitions = self._container_registry.findDefinitionContainers(id=container_id)
if not definitions:
definition_container = DefinitionContainer(container_id)
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
self._container_registry.addContainer(definition_container)
Job.yieldThread()
Logger.log("d", "Workspace loading is checking materials...")
material_containers = []
# Get all the material files and check if they exist. If not, add them.
xml_material_profile = self._getXmlProfileClass()
if self._material_container_suffix is None:
self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).suffixes[0]
if xml_material_profile:
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
for material_container_file in material_container_files:
container_id = self._stripFileToId(material_container_file)
materials = self._container_registry.findInstanceContainers(id=container_id)
if not materials:
material_container = xml_material_profile(container_id)
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
else:
if not materials[0].isReadOnly(): # Only create new materials if they are not read only.
if self._resolve_strategies["material"] == "override":
materials[0].deserialize(archive.open(material_container_file).read().decode("utf-8"))
elif self._resolve_strategies["material"] == "new":
# Note that we *must* deserialize it with a new ID, as multiple containers will be
# auto created & added.
material_container = xml_material_profile(self.getNewId(container_id))
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
material_containers.append(material_container)
Job.yieldThread()
Logger.log("d", "Workspace loading is checking instance containers...")
# Get quality_changes and user profiles saved in the workspace
instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)]
user_instance_containers = []
quality_changes_instance_containers = []
for instance_container_file in instance_container_files:
container_id = self._stripFileToId(instance_container_file)
instance_container = InstanceContainer(container_id)
# Deserialize InstanceContainer by converting read data from bytes to string
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
container_type = instance_container.getMetaDataEntry("type")
Job.yieldThread()
if container_type == "user":
# Check if quality changes already exists.
user_containers = self._container_registry.findInstanceContainers(id=container_id)
if not user_containers:
containers_to_add.append(instance_container)
else:
if self._resolve_strategies["machine"] == "override" or self._resolve_strategies["machine"] is None:
user_containers[0].deserialize(archive.open(instance_container_file).read().decode("utf-8"))
elif self._resolve_strategies["machine"] == "new":
# The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
extruder_id = instance_container.getMetaDataEntry("extruder", None)
if extruder_id:
new_id = self.getNewId(extruder_id) + "_current_settings"
instance_container._id = new_id
instance_container.setName(new_id)
instance_container.setMetaDataEntry("extruder", self.getNewId(extruder_id))
containers_to_add.append(instance_container)
machine_id = instance_container.getMetaDataEntry("machine", None)
if machine_id:
new_id = self.getNewId(machine_id) + "_current_settings"
instance_container._id = new_id
instance_container.setName(new_id)
instance_container.setMetaDataEntry("machine", self.getNewId(machine_id))
containers_to_add.append(instance_container)
user_instance_containers.append(instance_container)
elif container_type == "quality_changes":
# Check if quality changes already exists.
quality_changes = self._container_registry.findInstanceContainers(id = container_id)
if not quality_changes:
containers_to_add.append(instance_container)
else:
if self._resolve_strategies["quality_changes"] == "override":
quality_changes[0].deserialize(archive.open(instance_container_file).read().decode("utf-8"))
elif self._resolve_strategies["quality_changes"] is None:
# The ID already exists, but nothing in the values changed, so do nothing.
pass
quality_changes_instance_containers.append(instance_container)
else:
continue
# Add all the containers right before we try to add / serialize the stack
for container in containers_to_add:
self._container_registry.addContainer(container)
container.setDirty(True)
# Get the stack(s) saved in the workspace.
Logger.log("d", "Workspace loading is checking stacks containers...")
container_stack_files = [name for name in cura_file_names if name.endswith(self._container_stack_suffix)]
global_stack = None
extruder_stacks = []
container_stacks_added = []
try:
for container_stack_file in container_stack_files:
container_id = self._stripFileToId(container_stack_file)
# Check if a stack by this ID already exists;
container_stacks = self._container_registry.findContainerStacks(id=container_id)
if container_stacks:
stack = container_stacks[0]
if self._resolve_strategies["machine"] == "override":
# TODO: HACK
# There is a machine, check if it has authenticationd data. If so, keep that data.
network_authentication_id = container_stacks[0].getMetaDataEntry("network_authentication_id")
network_authentication_key = container_stacks[0].getMetaDataEntry("network_authentication_key")
container_stacks[0].deserialize(archive.open(container_stack_file).read().decode("utf-8"))
if network_authentication_id:
container_stacks[0].addMetaDataEntry("network_authentication_id", network_authentication_id)
if network_authentication_key:
container_stacks[0].addMetaDataEntry("network_authentication_key", network_authentication_key)
elif self._resolve_strategies["machine"] == "new":
new_id = self.getNewId(container_id)
stack = ContainerStack(new_id)
stack.deserialize(archive.open(container_stack_file).read().decode("utf-8"))
# Ensure a unique ID and name
stack._id = new_id
# Extruder stacks are "bound" to a machine. If we add the machine as a new one, the id of the
# bound machine also needs to change.
if stack.getMetaDataEntry("machine", None):
stack.setMetaDataEntry("machine", self.getNewId(stack.getMetaDataEntry("machine")))
if stack.getMetaDataEntry("type") != "extruder_train":
# Only machines need a new name, stacks may be non-unique
stack.setName(self._container_registry.uniqueName(stack.getName()))
container_stacks_added.append(stack)
self._container_registry.addContainer(stack)
else:
Logger.log("w", "Resolve strategy of %s for machine is not supported", self._resolve_strategies["machine"])
else:
stack = ContainerStack(container_id)
# Deserialize stack by converting read data from bytes to string
stack.deserialize(archive.open(container_stack_file).read().decode("utf-8"))
container_stacks_added.append(stack)
self._container_registry.addContainer(stack)
if stack.getMetaDataEntry("type") == "extruder_train":
extruder_stacks.append(stack)
else:
global_stack = stack
Job.yieldThread()
except:
Logger.logException("w", "We failed to serialize the stack. Trying to clean up.")
# Something went really wrong. Try to remove any data that we added.
for container in containers_to_add:
self._container_registry.getInstance().removeContainer(container.getId())
for container in container_stacks_added:
self._container_registry.getInstance().removeContainer(container.getId())
return None
if self._resolve_strategies["machine"] == "new":
# A new machine was made, but it was serialized with the wrong user container. Fix that now.
for container in user_instance_containers:
extruder_id = container.getMetaDataEntry("extruder", None)
if extruder_id:
for extruder in extruder_stacks:
if extruder.getId() == extruder_id:
extruder.replaceContainer(0, container)
continue
machine_id = container.getMetaDataEntry("machine", None)
if machine_id:
if global_stack.getId() == machine_id:
global_stack.replaceContainer(0, container)
continue
if self._resolve_strategies["quality_changes"] == "new":
# Quality changes needs to get a new ID, added to registry and to the right stacks
for container in quality_changes_instance_containers:
old_id = container.getId()
container.setName(self._container_registry.uniqueName(container.getName()))
# We're not really supposed to change the ID in normal cases, but this is an exception.
container._id = self.getNewId(container.getId())
# The container was not added yet, as it didn't have an unique ID. It does now, so add it.
self._container_registry.addContainer(container)
# Replace the quality changes container
old_container = global_stack.findContainer({"type": "quality_changes"})
if old_container.getId() == old_id:
quality_changes_index = global_stack.getContainerIndex(old_container)
global_stack.replaceContainer(quality_changes_index, container)
continue
for stack in extruder_stacks:
old_container = stack.findContainer({"type": "quality_changes"})
if old_container.getId() == old_id:
quality_changes_index = stack.getContainerIndex(old_container)
stack.replaceContainer(quality_changes_index, container)
if self._resolve_strategies["material"] == "new":
for material in material_containers:
old_material = global_stack.findContainer({"type": "material"})
if old_material.getId() in self._id_mapping:
material_index = global_stack.getContainerIndex(old_material)
global_stack.replaceContainer(material_index, material)
continue
for stack in extruder_stacks:
old_material = stack.findContainer({"type": "material"})
if old_material.getId() in self._id_mapping:
material_index = stack.getContainerIndex(old_material)
stack.replaceContainer(material_index, material)
continue
for stack in extruder_stacks:
ExtruderManager.getInstance().registerExtruder(stack, global_stack.getId())
else:
# Machine has no extruders, but it needs to be registered with the extruder manager.
ExtruderManager.getInstance().registerExtruder(None, global_stack.getId())
Logger.log("d", "Workspace loading is notifying rest of the code of changes...")
# Notify everything/one that is to notify about changes.
global_stack.containersChanged.emit(global_stack.getTop())
for stack in extruder_stacks:
stack.setNextStack(global_stack)
stack.containersChanged.emit(stack.getTop())
# Actually change the active machine.
Application.getInstance().setGlobalContainerStack(global_stack)
# Load all the nodes / meshdata of the workspace
nodes = self._3mf_mesh_reader.read(file_name)
if nodes is None:
nodes = []
return nodes
def _stripFileToId(self, file):
return file.replace("Cura/", "").split(".")[0]
def _getXmlProfileClass(self):
return self._container_registry.getContainerForMimeType(MimeTypeDatabase.getMimeType("application/x-ultimaker-material-profile"))
## Get the list of ID's of all containers in a container stack by partially parsing it's serialized data.
def _getContainerIdListFromSerialized(self, serialized):
parser = configparser.ConfigParser(interpolation=None, empty_lines_in_values=False)
parser.read_string(serialized)
container_ids = []
if "containers" in parser:
for index, container_id in parser.items("containers"):
container_ids.append(container_id)
elif parser.has_option("general", "containers"):
container_string = parser["general"].get("containers", "")
container_list = container_string.split(",")
container_ids = [container_id for container_id in container_list if container_id != ""]
return container_ids
def _getMachineNameFromSerializedStack(self, serialized):
parser = configparser.ConfigParser(interpolation=None, empty_lines_in_values=False)
parser.read_string(serialized)
return parser["general"].get("name", "")
def _getMaterialLabelFromSerialized(self, serialized):
data = ET.fromstring(serialized)
metadata = data.iterfind("./um:metadata/um:name/um:label", {"um": "http://www.ultimaker.com/material"})
for entry in metadata:
return entry.text
pass

View file

@ -0,0 +1,228 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import Qt, QUrl, pyqtSignal, pyqtSlot, QObject, pyqtProperty, QCoreApplication
from PyQt5.QtQml import QQmlComponent, QQmlContext
from UM.PluginRegistry import PluginRegistry
from UM.Application import Application
from UM.Logger import Logger
from UM.i18n import i18nCatalog
from UM.Settings.ContainerRegistry import ContainerRegistry
import os
import threading
import time
i18n_catalog = i18nCatalog("cura")
class WorkspaceDialog(QObject):
showDialogSignal = pyqtSignal()
def __init__(self, parent = None):
super().__init__(parent)
self._component = None
self._context = None
self._view = None
self._qml_url = "WorkspaceDialog.qml"
self._lock = threading.Lock()
self._default_strategy = "override"
self._result = {"machine": self._default_strategy,
"quality_changes": self._default_strategy,
"material": self._default_strategy}
self._visible = False
self.showDialogSignal.connect(self.__show)
self._has_quality_changes_conflict = False
self._has_machine_conflict = False
self._has_material_conflict = False
self._num_visible_settings = 0
self._active_mode = ""
self._quality_name = ""
self._num_settings_overriden_by_quality_changes = 0
self._quality_type = ""
self._machine_name = ""
self._material_labels = []
self._objects_on_plate = False
machineConflictChanged = pyqtSignal()
qualityChangesConflictChanged = pyqtSignal()
materialConflictChanged = pyqtSignal()
numVisibleSettingsChanged = pyqtSignal()
activeModeChanged = pyqtSignal()
qualityNameChanged = pyqtSignal()
numSettingsOverridenByQualityChangesChanged = pyqtSignal()
qualityTypeChanged = pyqtSignal()
machineNameChanged = pyqtSignal()
materialLabelsChanged = pyqtSignal()
objectsOnPlateChanged = pyqtSignal()
@pyqtProperty(bool, notify=objectsOnPlateChanged)
def hasObjectsOnPlate(self):
return self._objects_on_plate
def setHasObjectsOnPlate(self, objects_on_plate):
self._objects_on_plate = objects_on_plate
self.objectsOnPlateChanged.emit()
@pyqtProperty("QVariantList", notify = materialLabelsChanged)
def materialLabels(self):
return self._material_labels
def setMaterialLabels(self, material_labels):
self._material_labels = material_labels
self.materialLabelsChanged.emit()
@pyqtProperty(str, notify = machineNameChanged)
def machineName(self):
return self._machine_name
def setMachineName(self, machine_name):
self._machine_name = machine_name
self.machineNameChanged.emit()
@pyqtProperty(str, notify=qualityTypeChanged)
def qualityType(self):
return self._quality_type
def setQualityType(self, quality_type):
self._quality_type = quality_type
self.qualityTypeChanged.emit()
@pyqtProperty(int, notify=numSettingsOverridenByQualityChangesChanged)
def numSettingsOverridenByQualityChanges(self):
return self._num_settings_overriden_by_quality_changes
def setNumSettingsOverridenByQualityChanges(self, num_settings_overriden_by_quality_changes):
self._num_settings_overriden_by_quality_changes = num_settings_overriden_by_quality_changes
self.numSettingsOverridenByQualityChangesChanged.emit()
@pyqtProperty(str, notify=qualityNameChanged)
def qualityName(self):
return self._quality_name
def setQualityName(self, quality_name):
self._quality_name = quality_name
self.qualityNameChanged.emit()
@pyqtProperty(str, notify=activeModeChanged)
def activeMode(self):
return self._active_mode
def setActiveMode(self, active_mode):
if active_mode == 0:
self._active_mode = i18n_catalog.i18nc("@title:tab", "Recommended")
else:
self._active_mode = i18n_catalog.i18nc("@title:tab", "Custom")
self.activeModeChanged.emit()
@pyqtProperty(int, constant = True)
def totalNumberOfSettings(self):
return len(ContainerRegistry.getInstance().findDefinitionContainers(id="fdmprinter")[0].getAllKeys())
@pyqtProperty(int, notify = numVisibleSettingsChanged)
def numVisibleSettings(self):
return self._num_visible_settings
def setNumVisibleSettings(self, num_visible_settings):
self._num_visible_settings = num_visible_settings
self.numVisibleSettingsChanged.emit()
@pyqtProperty(bool, notify = machineConflictChanged)
def machineConflict(self):
return self._has_machine_conflict
@pyqtProperty(bool, notify=qualityChangesConflictChanged)
def qualityChangesConflict(self):
return self._has_quality_changes_conflict
@pyqtProperty(bool, notify=materialConflictChanged)
def materialConflict(self):
return self._has_material_conflict
@pyqtSlot(str, str)
def setResolveStrategy(self, key, strategy):
if key in self._result:
self._result[key] = strategy
def setMaterialConflict(self, material_conflict):
self._has_material_conflict = material_conflict
self.materialConflictChanged.emit()
def setMachineConflict(self, machine_conflict):
self._has_machine_conflict = machine_conflict
self.machineConflictChanged.emit()
def setQualityChangesConflict(self, quality_changes_conflict):
self._has_quality_changes_conflict = quality_changes_conflict
self.qualityChangesConflictChanged.emit()
def getResult(self):
if "machine" in self._result and not self._has_machine_conflict:
self._result["machine"] = None
if "quality_changes" in self._result and not self._has_quality_changes_conflict:
self._result["quality_changes"] = None
if "material" in self._result and not self._has_material_conflict:
self._result["material"] = None
return self._result
def _createViewFromQML(self):
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("3MFReader"), self._qml_url))
self._component = QQmlComponent(Application.getInstance()._engine, path)
self._context = QQmlContext(Application.getInstance()._engine.rootContext())
self._context.setContextProperty("manager", self)
self._view = self._component.create(self._context)
if self._view is None:
Logger.log("c", "QQmlComponent status %s", self._component.status())
Logger.log("c", "QQmlComponent error string %s", self._component.errorString())
def show(self):
# Emit signal so the right thread actually shows the view.
if threading.current_thread() != threading.main_thread():
self._lock.acquire()
# Reset the result
self._result = {"machine": self._default_strategy,
"quality_changes": self._default_strategy,
"material": self._default_strategy}
self._visible = True
self.showDialogSignal.emit()
@pyqtSlot()
## Used to notify the dialog so the lock can be released.
def notifyClosed(self):
self._result = {}
self._visible = False
self._lock.release()
def hide(self):
self._visible = False
self._lock.release()
self._view.hide()
@pyqtSlot()
def onOkButtonClicked(self):
self._view.hide()
self.hide()
@pyqtSlot()
def onCancelButtonClicked(self):
self._view.hide()
self.hide()
self._result = {}
## Block thread until the dialog is closed.
def waitForClose(self):
if self._visible:
if threading.current_thread() != threading.main_thread():
self._lock.acquire()
self._lock.release()
else:
# If this is not run from a separate thread, we need to ensure that the events are still processed.
while self._visible:
time.sleep(1 / 50)
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
def __show(self):
if self._view is None:
self._createViewFromQML()
if self._view:
self._view.show()

View file

@ -0,0 +1,319 @@
// Copyright (c) 2016 Ultimaker B.V.
// Cura is released under the terms of the AGPLv3 or higher.
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
import UM 1.1 as UM
UM.Dialog
{
title: catalog.i18nc("@title:window", "Open Project")
width: 550
minimumWidth: 550
maximumWidth: 550
height: 350
minimumHeight: 350
maximumHeight: 350
property int comboboxHeight: 15
property int spacerHeight: 10
onClosing: manager.notifyClosed()
onVisibleChanged:
{
if(visible)
{
machineResolveComboBox.currentIndex = 0
qualityChangesResolveComboBox.currentIndex = 0
materialConflictComboBox.currentIndex = 0
}
}
Item
{
anchors.fill: parent
UM.I18nCatalog
{
id: catalog;
name: "cura";
}
ListModel
{
id: resolveStrategiesModel
// Instead of directly adding the list elements, we add them afterwards.
// This is because it's impossible to use setting function results to be bound to listElement properties directly.
// See http://stackoverflow.com/questions/7659442/listelement-fields-as-properties
Component.onCompleted:
{
append({"key": "override", "label": catalog.i18nc("@action:ComboBox option", "Update existing")});
append({"key": "new", "label": catalog.i18nc("@action:ComboBox option", "Create new")});
}
}
Column
{
anchors.fill: parent
spacing: 2
Label
{
id: titleLabel
text: catalog.i18nc("@action:title", "Summary - Cura Project")
font.pixelSize: 22
}
Rectangle
{
id: separator
color: "black"
width: parent.width
height: 1
}
Item // Spacer
{
height: spacerHeight
width: height
}
Label
{
text: catalog.i18nc("@action:label", "Printer settings")
font.bold: true
}
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label", "Name")
width: parent.width / 3
}
Label
{
text: manager.machineName
width: parent.width / 3
}
UM.TooltipArea
{
id: machineResolveTooltip
width: parent.width / 3
height: visible ? comboboxHeight : 0
visible: manager.machineConflict
text: catalog.i18nc("@info:tooltip", "How should the conflict in the machine be resolved?")
ComboBox
{
model: resolveStrategiesModel
textRole: "label"
id: machineResolveComboBox
width: parent.width
onActivated:
{
manager.setResolveStrategy("machine", resolveStrategiesModel.get(index).key)
}
}
}
}
Item // Spacer
{
height: spacerHeight
width: height
}
Label
{
text: catalog.i18nc("@action:label", "Profile settings")
font.bold: true
}
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label", "Name")
width: parent.width / 3
}
Label
{
text: manager.qualityName
width: parent.width / 3
}
UM.TooltipArea
{
id: qualityChangesResolveTooltip
width: parent.width / 3
height: visible ? comboboxHeight : 0
visible: manager.qualityChangesConflict
text: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?")
ComboBox
{
model: resolveStrategiesModel
textRole: "label"
id: qualityChangesResolveComboBox
width: parent.width
onActivated:
{
manager.setResolveStrategy("quality_changes", resolveStrategiesModel.get(index).key)
}
}
}
}
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label", "Derivative from")
width: parent.width / 3
}
Label
{
text: catalog.i18nc("@action:label", "%1, %2 override(s)" ).arg(manager.qualityType).arg(manager.numSettingsOverridenByQualityChanges)
width: parent.width / 3
}
visible: manager.numSettingsOverridenByQualityChanges != 0
}
Item // Spacer
{
height: spacerHeight
width: height
}
Label
{
text: catalog.i18nc("@action:label", "Material settings")
font.bold: true
}
Repeater
{
model: manager.materialLabels
delegate: Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label", "Name")
width: parent.width / 3
}
Label
{
text: modelData
width: parent.width / 3
}
}
}
Row
{
width: parent.width
height: childrenRect.height
visible: manager.materialConflict
Item
{
width: parent.width / 3 * 2
height: comboboxHeight
}
UM.TooltipArea
{
id: materialResolveTooltip
width: parent.width / 3
height: visible ? comboboxHeight : 0
text: catalog.i18nc("@info:tooltip", "How should the conflict in the material be resolved?")
ComboBox
{
model: resolveStrategiesModel
textRole: "label"
id: materialResolveComboBox
width: parent.width
onActivated:
{
manager.setResolveStrategy("material", resolveStrategiesModel.get(index).key)
}
}
}
}
Item // Spacer
{
height: spacerHeight
width: height
}
Label
{
text: catalog.i18nc("@action:label", "Setting visibility")
font.bold: true
}
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label", "Mode")
width: parent.width / 3
}
Label
{
text: manager.activeMode
width: parent.width / 3
}
}
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label", "Visible settings:")
width: parent.width / 3
}
Label
{
text: catalog.i18nc("@action:label", "%1 out of %2" ).arg(manager.numVisibleSettings).arg(manager.totalNumberOfSettings)
width: parent.width / 3
}
}
Item // Spacer
{
height: spacerHeight
width: height
}
Label
{
text: catalog.i18nc("@action:warning", "Loading a project will clear all models on the buildplate")
visible: manager.hasObjectsOnPlate
color: "red"
width: parent.width
wrapMode: Text.Wrap
}
}
}
rightButtons: [
Button
{
id: ok_button
text: catalog.i18nc("@action:button","OK");
onClicked: { manager.onOkButtonClicked() }
enabled: true
},
Button
{
id: cancel_button
text: catalog.i18nc("@action:button","Cancel");
onClicked: { manager.onCancelButtonClicked() }
enabled: true
}
]
}

View file

@ -2,10 +2,11 @@
# Cura is released under the terms of the AGPLv3 or higher.
from . import ThreeMFReader
from . import ThreeMFWorkspaceReader
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
def getMetaData():
return {
"plugin": {
@ -20,8 +21,17 @@ def getMetaData():
"extension": "3mf",
"description": catalog.i18nc("@item:inlistbox", "3MF File")
}
],
"workspace_reader":
[
{
"extension": "curaproject.3mf",
"description": catalog.i18nc("@item:inlistbox", "3MF File")
}
]
}
def register(app):
return { "mesh_reader": ThreeMFReader.ThreeMFReader() }
return {"mesh_reader": ThreeMFReader.ThreeMFReader(),
"workspace_reader": ThreeMFWorkspaceReader.ThreeMFWorkspaceReader()}

View file

@ -0,0 +1,89 @@
from UM.Workspace.WorkspaceWriter import WorkspaceWriter
from UM.Application import Application
from UM.Preferences import Preferences
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.ContainerStack import ContainerStack
from cura.Settings.ExtruderManager import ExtruderManager
import zipfile
from io import StringIO
import copy
class ThreeMFWorkspaceWriter(WorkspaceWriter):
def __init__(self):
super().__init__()
def write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode):
mesh_writer = Application.getInstance().getMeshFileHandler().getWriter("3MFWriter")
if not mesh_writer: # We need to have the 3mf mesh writer, otherwise we can't save the entire workspace
return False
# Indicate that the 3mf mesh writer should not close the archive just yet (we still need to add stuff to it).
mesh_writer.setStoreArchive(True)
mesh_writer.write(stream, nodes, mode)
archive = mesh_writer.getArchive()
if archive is None: # This happens if there was no mesh data to write.
archive = zipfile.ZipFile(stream, "w", compression = zipfile.ZIP_DEFLATED)
global_container_stack = Application.getInstance().getGlobalContainerStack()
# Add global container stack data to the archive.
self._writeContainerToArchive(global_container_stack, archive)
# Also write all containers in the stack to the file
for container in global_container_stack.getContainers():
self._writeContainerToArchive(container, archive)
# Check if the machine has extruders and save all that data as well.
for extruder_stack in ExtruderManager.getInstance().getMachineExtruders(global_container_stack.getId()):
self._writeContainerToArchive(extruder_stack, archive)
for container in extruder_stack.getContainers():
self._writeContainerToArchive(container, archive)
# Write preferences to archive
preferences_file = zipfile.ZipInfo("Cura/preferences.cfg")
preferences_string = StringIO()
Preferences.getInstance().writeToFile(preferences_string)
archive.writestr(preferences_file, preferences_string.getvalue())
# Close the archive & reset states.
archive.close()
mesh_writer.setStoreArchive(False)
return True
## Helper function that writes ContainerStacks, InstanceContainers and DefinitionContainers to the archive.
# \param container That follows the \type{ContainerInterface} to archive.
# \param archive The archive to write to.
@staticmethod
def _writeContainerToArchive(container, archive):
if type(container) == type(ContainerRegistry.getInstance().getEmptyInstanceContainer()):
return # Empty file, do nothing.
file_suffix = ContainerRegistry.getMimeTypeForContainer(type(container)).preferredSuffix
# Some containers have a base file, which should then be the file to use.
if "base_file" in container.getMetaData():
base_file = container.getMetaDataEntry("base_file")
container = ContainerRegistry.getInstance().findContainers(id = base_file)[0]
file_name = "Cura/%s.%s" % (container.getId(), file_suffix)
if file_name in archive.namelist():
return # File was already saved, no need to do it again. Uranium guarantees unique ID's, so this should hold.
file_in_archive = zipfile.ZipInfo(file_name)
# For some reason we have to set the compress type of each file as well (it doesn't keep the type of the entire archive)
file_in_archive.compress_type = zipfile.ZIP_DEFLATED
if type(container) == ContainerStack and (container.getMetaDataEntry("network_authentication_id") or container.getMetaDataEntry("network_authentication_key")):
# TODO: Hack
# Create a shallow copy of the container, so we can filter out the network auth (if any)
container_copy = copy.deepcopy(container)
container_copy.removeMetaDataEntry("network_authentication_id")
container_copy.removeMetaDataEntry("network_authentication_key")
serialized_data = container_copy.serialize()
else:
serialized_data = container.serialize()
archive.writestr(file_in_archive, serialized_data)

View file

@ -0,0 +1,207 @@
# Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.
from UM.Mesh.MeshWriter import MeshWriter
from UM.Math.Vector import Vector
from UM.Logger import Logger
from UM.Math.Matrix import Matrix
from UM.Application import Application
try:
import xml.etree.cElementTree as ET
except ImportError:
Logger.log("w", "Unable to load cElementTree, switching to slower version")
import xml.etree.ElementTree as ET
import zipfile
import UM.Application
class ThreeMFWriter(MeshWriter):
def __init__(self):
super().__init__()
self._namespaces = {
"3mf": "http://schemas.microsoft.com/3dmanufacturing/core/2015/02",
"content-types": "http://schemas.openxmlformats.org/package/2006/content-types",
"relationships": "http://schemas.openxmlformats.org/package/2006/relationships",
"cura": "http://software.ultimaker.com/xml/cura/3mf/2015/10"
}
self._unit_matrix_string = self._convertMatrixToString(Matrix())
self._archive = None
self._store_archive = False
def _convertMatrixToString(self, matrix):
result = ""
result += str(matrix._data[0,0]) + " "
result += str(matrix._data[1,0]) + " "
result += str(matrix._data[2,0]) + " "
result += str(matrix._data[0,1]) + " "
result += str(matrix._data[1,1]) + " "
result += str(matrix._data[2,1]) + " "
result += str(matrix._data[0,2]) + " "
result += str(matrix._data[1,2]) + " "
result += str(matrix._data[2,2]) + " "
result += str(matrix._data[0,3]) + " "
result += str(matrix._data[1,3]) + " "
result += str(matrix._data[2,3]) + " "
return result
## Should we store the archive
# Note that if this is true, the archive will not be closed.
# The object that set this parameter is then responsible for closing it correctly!
def setStoreArchive(self, store_archive):
self._store_archive = store_archive
def getArchive(self):
return self._archive
def write(self, stream, nodes, mode = MeshWriter.OutputMode.BinaryMode):
self._archive = None # Reset archive
archive = zipfile.ZipFile(stream, "w", compression = zipfile.ZIP_DEFLATED)
try:
model_file = zipfile.ZipInfo("3D/3dmodel.model")
# Because zipfile is stupid and ignores archive-level compression settings when writing with ZipInfo.
model_file.compress_type = zipfile.ZIP_DEFLATED
# Create content types file
content_types_file = zipfile.ZipInfo("[Content_Types].xml")
content_types_file.compress_type = zipfile.ZIP_DEFLATED
content_types = ET.Element("Types", xmlns = self._namespaces["content-types"])
rels_type = ET.SubElement(content_types, "Default", Extension = "rels", ContentType = "application/vnd.openxmlformats-package.relationships+xml")
model_type = ET.SubElement(content_types, "Default", Extension = "model", ContentType = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml")
# Create _rels/.rels file
relations_file = zipfile.ZipInfo("_rels/.rels")
relations_file.compress_type = zipfile.ZIP_DEFLATED
relations_element = ET.Element("Relationships", xmlns = self._namespaces["relationships"])
model_relation_element = ET.SubElement(relations_element, "Relationship", Target = "/3D/3dmodel.model", Id = "rel0", Type = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel")
model = ET.Element("model", unit = "millimeter", xmlns = self._namespaces["3mf"])
# Add the version of Cura this was created with. As "CuraVersion" is not a recognised metadata name
# by 3mf itself, we place it in our own namespace.
version_metadata = ET.SubElement(model, "metadata", xmlns = self._namespaces["cura"], name = "CuraVersion")
version_metadata.text = Application.getInstance().getVersion()
resources = ET.SubElement(model, "resources")
build = ET.SubElement(model, "build")
added_nodes = []
index = 0 # Ensure index always exists (even if there are no nodes to write)
# Write all nodes with meshData to the file as objects inside the resource tag
for index, n in enumerate(MeshWriter._meshNodes(nodes)):
added_nodes.append(n) # Save the nodes that have mesh data
object = ET.SubElement(resources, "object", id = str(index+1), type = "model")
mesh = ET.SubElement(object, "mesh")
mesh_data = n.getMeshData()
vertices = ET.SubElement(mesh, "vertices")
verts = mesh_data.getVertices()
if verts is None:
Logger.log("d", "3mf writer can't write nodes without mesh data. Skipping this node.")
continue # No mesh data, nothing to do.
if mesh_data.hasIndices():
for face in mesh_data.getIndices():
v1 = verts[face[0]]
v2 = verts[face[1]]
v3 = verts[face[2]]
xml_vertex1 = ET.SubElement(vertices, "vertex", x = str(v1[0]), y = str(v1[1]), z = str(v1[2]))
xml_vertex2 = ET.SubElement(vertices, "vertex", x = str(v2[0]), y = str(v2[1]), z = str(v2[2]))
xml_vertex3 = ET.SubElement(vertices, "vertex", x = str(v3[0]), y = str(v3[1]), z = str(v3[2]))
triangles = ET.SubElement(mesh, "triangles")
for face in mesh_data.getIndices():
triangle = ET.SubElement(triangles, "triangle", v1 = str(face[0]) , v2 = str(face[1]), v3 = str(face[2]))
else:
triangles = ET.SubElement(mesh, "triangles")
for idx, vert in enumerate(verts):
xml_vertex = ET.SubElement(vertices, "vertex", x = str(vert[0]), y = str(vert[1]), z = str(vert[2]))
# If we have no faces defined, assume that every three subsequent vertices form a face.
if idx % 3 == 0:
triangle = ET.SubElement(triangles, "triangle", v1 = str(idx), v2 = str(idx + 1), v3 = str(idx + 2))
# Handle per object settings
stack = n.callDecoration("getStack")
if stack is not None:
changed_setting_keys = set(stack.getTop().getAllKeys())
# Ensure that we save the extruder used for this object.
if stack.getProperty("machine_extruder_count", "value") > 1:
changed_setting_keys.add("extruder_nr")
settings_xml = ET.SubElement(object, "settings", xmlns=self._namespaces["cura"])
# Get values for all changed settings & save them.
for key in changed_setting_keys:
setting_xml = ET.SubElement(settings_xml, "setting", key = key)
setting_xml.text = str(stack.getProperty(key, "value"))
# Add one to the index as we haven't incremented the last iteration.
index += 1
nodes_to_add = set()
for node in added_nodes:
# Check the parents of the nodes with mesh_data and ensure that they are also added.
parent_node = node.getParent()
while parent_node is not None:
if parent_node.callDecoration("isGroup"):
nodes_to_add.add(parent_node)
parent_node = parent_node.getParent()
else:
parent_node = None
# Sort all the nodes by depth (so nodes with the highest depth are done first)
sorted_nodes_to_add = sorted(nodes_to_add, key=lambda node: node.getDepth(), reverse = True)
# We have already saved the nodes with mesh data, but now we also want to save nodes required for the scene
for node in sorted_nodes_to_add:
object = ET.SubElement(resources, "object", id=str(index + 1), type="model")
components = ET.SubElement(object, "components")
for child in node.getChildren():
if child in added_nodes:
component = ET.SubElement(components, "component", objectid = str(added_nodes.index(child) + 1), transform = self._convertMatrixToString(child.getLocalTransformation()))
index += 1
added_nodes.append(node)
# Create a transformation Matrix to convert from our worldspace into 3MF.
# First step: flip the y and z axis.
transformation_matrix = Matrix()
transformation_matrix._data[1, 1] = 0
transformation_matrix._data[1, 2] = -1
transformation_matrix._data[2, 1] = 1
transformation_matrix._data[2, 2] = 0
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
# Second step: 3MF defines the left corner of the machine as center, whereas cura uses the center of the
# build volume.
if global_container_stack:
translation_vector = Vector(x=global_container_stack.getProperty("machine_width", "value") / 2,
y=global_container_stack.getProperty("machine_depth", "value") / 2,
z=0)
translation_matrix = Matrix()
translation_matrix.setByTranslation(translation_vector)
transformation_matrix.preMultiply(translation_matrix)
# Find out what the final build items are and add them.
for node in added_nodes:
if node.getParent().callDecoration("isGroup") is None:
node_matrix = node.getLocalTransformation()
ET.SubElement(build, "item", objectid = str(added_nodes.index(node) + 1), transform = self._convertMatrixToString(node_matrix.preMultiply(transformation_matrix)))
archive.writestr(model_file, b'<?xml version="1.0" encoding="UTF-8"?> \n' + ET.tostring(model))
archive.writestr(content_types_file, b'<?xml version="1.0" encoding="UTF-8"?> \n' + ET.tostring(content_types))
archive.writestr(relations_file, b'<?xml version="1.0" encoding="UTF-8"?> \n' + ET.tostring(relations_element))
except Exception as e:
Logger.logException("e", "Error writing zip file")
return False
finally:
if not self._store_archive:
archive.close()
else:
self._archive = archive
return True

View file

@ -0,0 +1,38 @@
# Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.
from UM.i18n import i18nCatalog
from . import ThreeMFWorkspaceWriter
from . import ThreeMFWriter
i18n_catalog = i18nCatalog("uranium")
def getMetaData():
return {
"plugin": {
"name": i18n_catalog.i18nc("@label", "3MF Writer"),
"author": "Ultimaker",
"version": "1.0",
"description": i18n_catalog.i18nc("@info:whatsthis", "Provides support for writing 3MF files."),
"api": 3
},
"mesh_writer": {
"output": [{
"extension": "3mf",
"description": i18n_catalog.i18nc("@item:inlistbox", "3MF file"),
"mime_type": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
"mode": ThreeMFWriter.ThreeMFWriter.OutputMode.BinaryMode
}]
},
"workspace_writer": {
"output": [{
"extension": "curaproject.3mf",
"description": i18n_catalog.i18nc("@item:inlistbox", "Cura Project 3MF file"),
"mime_type": "application/x-curaproject+xml",
"mode": ThreeMFWorkspaceWriter.ThreeMFWorkspaceWriter.OutputMode.BinaryMode
}]
}
}
def register(app):
return {"mesh_writer": ThreeMFWriter.ThreeMFWriter(), "workspace_writer": ThreeMFWorkspaceWriter.ThreeMFWorkspaceWriter()}

View file

@ -156,28 +156,29 @@ class StartSliceJob(Job):
if group[0].getParent().callDecoration("isGroup"):
self._handlePerObjectSettings(group[0].getParent(), group_message)
for object in group:
mesh_data = object.getMeshData().getTransformed(object.getWorldTransformation())
mesh_data = object.getMeshData()
rot_scale = object.getWorldTransformation().getTransposed().getData()[0:3, 0:3]
translate = object.getWorldTransformation().getData()[:3, 3]
obj = group_message.addRepeatedMessage("objects")
obj.id = id(object)
# This effectively performs a limited form of MeshData.getTransformed that ignores normals.
verts = mesh_data.getVertices()
indices = mesh_data.getIndices()
if indices is not None:
#TODO: This is a very slow way of doing it! It also locks up the GUI.
flat_vert_list = []
for face in indices:
for vert_index in face:
flat_vert_list.append(verts[vert_index])
Job.yieldThread()
verts = numpy.array(flat_vert_list)
else:
verts = numpy.array(verts)
verts = verts.dot(rot_scale)
verts += translate
# Convert from Y up axes to Z up axes. Equals a 90 degree rotation.
verts[:, [1, 2]] = verts[:, [2, 1]]
verts[:, 1] *= -1
obj.vertices = verts
obj = group_message.addRepeatedMessage("objects")
obj.id = id(object)
indices = mesh_data.getIndices()
if indices is not None:
flat_verts = numpy.take(verts, indices.flatten(), axis=0)
else:
flat_verts = numpy.array(verts)
obj.vertices = flat_verts
self._handlePerObjectSettings(object, obj)
@ -309,4 +310,4 @@ class StartSliceJob(Job):
continue
relations_set.add(relation.target.key)
self._addRelations(relations_set, relation.target.relations)
self._addRelations(relations_set, relation.target.relations)

View file

@ -3,6 +3,7 @@ from UM.Application import Application
import LayerView
class LayerViewProxy(QObject):
def __init__(self, parent = None):
super().__init__(parent)

View file

@ -1,17 +1,17 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import configparser #For reading the legacy profile INI files.
import json #For reading the Dictionary of Doom.
import math #For mathematical operations included in the Dictionary of Doom.
import os.path #For concatenating the path to the plugin and the relative path to the Dictionary of Doom.
import configparser # For reading the legacy profile INI files.
import json # For reading the Dictionary of Doom.
import math # For mathematical operations included in the Dictionary of Doom.
import os.path # For concatenating the path to the plugin and the relative path to the Dictionary of Doom.
from UM.Application import Application # To get the machine manager to create the new profile in.
from UM.Logger import Logger # Logging errors.
from UM.PluginRegistry import PluginRegistry # For getting the path to this plugin's directory.
from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make.
from cura.ProfileReader import ProfileReader # The plug-in type to implement.
from UM.Application import Application #To get the machine manager to create the new profile in.
from UM.Logger import Logger #Logging errors.
from UM.PluginRegistry import PluginRegistry #For getting the path to this plugin's directory.
from UM.Settings.DefinitionContainer import DefinitionContainer #For getting the current machine's defaults.
from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
from cura.ProfileReader import ProfileReader #The plug-in type to implement.
## A plugin that reads profile data from legacy Cura versions.
#
@ -33,7 +33,7 @@ class LegacyProfileReader(ProfileReader):
# \return A dictionary of the default values of the legacy Cura version.
def prepareDefaults(self, json):
defaults = {}
for key in json["defaults"]: #We have to copy over all defaults from the JSON handle to a normal dict.
for key in json["defaults"]: # We have to copy over all defaults from the JSON handle to a normal dict.
defaults[key] = json["defaults"][key]
return defaults
@ -52,7 +52,7 @@ class LegacyProfileReader(ProfileReader):
# \return A set of local variables, one for each setting in the legacy
# profile.
def prepareLocals(self, config_parser, config_section, defaults):
copied_locals = defaults.copy() #Don't edit the original!
copied_locals = defaults.copy() # Don't edit the original!
for option in config_parser.options(config_section):
copied_locals[option] = config_parser.get(config_section, option)
return copied_locals
@ -76,29 +76,29 @@ class LegacyProfileReader(ProfileReader):
raise Exception("Unable to import legacy profile. Multi extrusion is not supported")
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
profile = InstanceContainer("Imported Legacy Profile") # Create an empty profile.
profile = InstanceContainer("Imported Legacy Profile") # Create an empty profile.
parser = configparser.ConfigParser(interpolation = None)
try:
with open(file_name) as f:
parser.readfp(f) #Parse the INI file.
parser.readfp(f) # Parse the INI file.
except Exception as e:
Logger.log("e", "Unable to open legacy profile %s: %s", file_name, str(e))
return None
#Legacy Cura saved the profile under the section "profile_N" where N is the ID of a machine, except when you export in which case it saves it in the section "profile".
#Since importing multiple machine profiles is out of scope, just import the first section we find.
# Legacy Cura saved the profile under the section "profile_N" where N is the ID of a machine, except when you export in which case it saves it in the section "profile".
# Since importing multiple machine profiles is out of scope, just import the first section we find.
section = ""
for found_section in parser.sections():
if found_section.startswith("profile"):
section = found_section
break
if not section: #No section starting with "profile" was found. Probably not a proper INI file.
if not section: # No section starting with "profile" was found. Probably not a proper INI file.
return None
try:
with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", -1, "utf-8") as f:
dict_of_doom = json.load(f) #Parse the Dictionary of Doom.
dict_of_doom = json.load(f) # Parse the Dictionary of Doom.
except IOError as e:
Logger.log("e", "Could not open DictionaryOfDoom.json for reading: %s", str(e))
return None
@ -122,13 +122,13 @@ class LegacyProfileReader(ProfileReader):
return None
current_printer_definition = global_container_stack.getBottom()
profile.setDefinition(current_printer_definition)
for new_setting in dict_of_doom["translation"]: #Evaluate all new settings that would get a value from the translations.
for new_setting in dict_of_doom["translation"]: # Evaluate all new settings that would get a value from the translations.
old_setting_expression = dict_of_doom["translation"][new_setting]
compiled = compile(old_setting_expression, new_setting, "eval")
try:
new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation.
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
except Exception: #Probably some setting name that was missing or something else that went wrong in the ini file.
new_value = eval(compiled, {"math": math}, legacy_settings) # Pass the legacy settings as local variables to allow access to in the evaluation.
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
except Exception: # Probably some setting name that was missing or something else that went wrong in the ini file.
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
continue
definitions = current_printer_definition.findDefinitions(key = new_setting)

View file

@ -1,7 +1,7 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot
from cura.MachineAction import MachineAction
@ -16,40 +16,60 @@ from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
import UM.i18n
catalog = UM.i18n.i18nCatalog("cura")
## This action allows for certain settings that are "machine only") to be modified.
# It automatically detects machine definitions that it knows how to change and attaches itself to those.
class MachineSettingsAction(MachineAction):
def __init__(self, parent = None):
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
self._qml_url = "MachineSettingsAction.qml"
CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
self._container_index = 0
self._container_registry = ContainerRegistry.getInstance()
self._container_registry.containerAdded.connect(self._onContainerAdded)
def _reset(self):
global_container_stack = Application.Application.getInstance().getGlobalContainerStack()
if global_container_stack:
variant = global_container_stack.findContainer({"type": "variant"})
if variant and variant.getId() == "empty_variant":
variant_index = global_container_stack.getContainerIndex(variant)
self._createVariant(global_container_stack, variant_index)
global_container_stack = Application.getInstance().getGlobalContainerStack()
if not global_container_stack:
return
def _createVariant(self, global_container_stack, variant_index):
# Create and switch to a variant to store the settings in
new_variant = InstanceContainer(global_container_stack.getName() + "_variant")
new_variant.addMetaDataEntry("type", "variant")
new_variant.setDefinition(global_container_stack.getBottom())
ContainerRegistry.getInstance().addContainer(new_variant)
global_container_stack.replaceContainer(variant_index, new_variant)
# Make sure there is a definition_changes container to store the machine settings
definition_changes_container = global_container_stack.findContainer({"type": "definition_changes"})
if not definition_changes_container:
definition_changes_container = self._createDefinitionChangesContainer(global_container_stack)
# Notify the UI in which container to store the machine settings data
container_index = global_container_stack.getContainerIndex(definition_changes_container)
if container_index != self._container_index:
self._container_index = container_index
self.containerIndexChanged.emit()
def _createDefinitionChangesContainer(self, global_container_stack, container_index = None):
definition_changes_container = InstanceContainer(global_container_stack.getName() + "_settings")
definition = global_container_stack.getBottom()
definition_changes_container.setDefinition(definition)
definition_changes_container.addMetaDataEntry("type", "definition_changes")
self._container_registry.addContainer(definition_changes_container)
# Insert definition_changes between the definition and the variant
global_container_stack.insertContainer(-1, definition_changes_container)
return definition_changes_container
containerIndexChanged = pyqtSignal()
@pyqtProperty(int, notify = containerIndexChanged)
def containerIndex(self):
return self._container_index
def _onContainerAdded(self, container):
# Add this action as a supported action to all machine definitions
if isinstance(container, UM.Settings.DefinitionContainer.DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
if container.getProperty("machine_extruder_count", "value") > 1:
# Multiextruder printers are not currently supported
Logger.log("d", "Not attaching MachineSettingsAction to %s; Multi-extrusion printers are not supported", container.getId())
return
if container.getMetaDataEntry("has_variants", False):
# Machines that use variants are not currently supported
Logger.log("d", "Not attaching MachineSettingsAction to %s; Machines that use variants are not supported", container.getId())
return
Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
@ -62,7 +82,7 @@ class MachineSettingsAction(MachineAction):
@pyqtSlot()
def updateHasMaterialsMetadata(self):
# Updates the has_materials metadata flag after switching gcode flavor
global_container_stack = UM.Application.Application.getInstance().getGlobalContainerStack()
global_container_stack = Application.getInstance().getGlobalContainerStack()
if global_container_stack:
definition = global_container_stack.getBottom()
if definition.getProperty("machine_gcode_flavor", "value") == "UltiGCode" and not definition.getMetaDataEntry("has_materials", False):
@ -80,7 +100,7 @@ class MachineSettingsAction(MachineAction):
# Set the material container to a sane default
if material_container.getId() == "empty_material":
search_criteria = { "type": "material", "definition": "fdmprinter", "id": "*pla*" }
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
containers = self._container_registry.findInstanceContainers(**search_criteria)
if containers:
global_container_stack.replaceContainer(material_index, containers[0])
else:
@ -89,7 +109,7 @@ class MachineSettingsAction(MachineAction):
if "has_materials" in global_container_stack.getMetaData():
global_container_stack.removeMetaDataEntry("has_materials")
empty_material = ContainerRegistry.getInstance().findInstanceContainers(id = "empty_material")[0]
empty_material = self._container_registry.findInstanceContainers(id = "empty_material")[0]
global_container_stack.replaceContainer(material_index, empty_material)
Application.getInstance().globalContainerStackChanged.emit()
Application.getInstance().globalContainerStackChanged.emit()

View file

@ -120,19 +120,73 @@ Cura.MachineAction
Column
{
CheckBox
Row
{
id: heatedBedCheckBox
text: catalog.i18nc("@option:check", "Heated Bed")
checked: String(machineHeatedBedProvider.properties.value).toLowerCase() != 'false'
onClicked: machineHeatedBedProvider.setPropertyValue("value", checked)
spacing: UM.Theme.getSize("default_margin").width
Label
{
text: catalog.i18nc("@label", "Build Plate Shape")
}
ComboBox
{
id: shapeComboBox
model: ListModel
{
id: shapesModel
Component.onCompleted:
{
// Options come in as a string-representation of an OrderedDict
var options = machineShapeProvider.properties.options.match(/^OrderedDict\(\[\((.*)\)\]\)$/);
if(options)
{
options = options[1].split("), (")
for(var i = 0; i < options.length; i++)
{
var option = options[i].substring(1, options[i].length - 1).split("', '")
shapesModel.append({text: option[1], value: option[0]});
}
}
}
}
currentIndex:
{
var currentValue = machineShapeProvider.properties.value;
var index = 0;
for(var i = 0; i < shapesModel.count; i++)
{
if(shapesModel.get(i).value == currentValue) {
index = i;
break;
}
}
return index
}
onActivated:
{
machineShapeProvider.setPropertyValue("value", shapesModel.get(index).value);
manager.forceUpdate();
}
}
}
CheckBox
{
id: centerIsZeroCheckBox
text: catalog.i18nc("@option:check", "Machine Center is Zero")
checked: String(machineCenterIsZeroProvider.properties.value).toLowerCase() != 'false'
onClicked: machineCenterIsZeroProvider.setPropertyValue("value", checked)
onClicked:
{
machineCenterIsZeroProvider.setPropertyValue("value", checked);
manager.forceUpdate();
}
}
CheckBox
{
id: heatedBedCheckBox
text: catalog.i18nc("@option:check", "Heated Bed")
checked: String(machineHeatedBedProvider.properties.value).toLowerCase() != 'false'
onClicked: machineHeatedBedProvider.setPropertyValue("value", checked)
}
}
@ -147,19 +201,40 @@ Cura.MachineAction
ComboBox
{
model: ["RepRap (Marlin/Sprinter)", "UltiGCode", "Repetier"]
model: ListModel
{
id: flavorModel
Component.onCompleted:
{
// Options come in as a string-representation of an OrderedDict
var options = machineGCodeFlavorProvider.properties.options.match(/^OrderedDict\(\[\((.*)\)\]\)$/);
if(options)
{
options = options[1].split("), (")
for(var i = 0; i < options.length; i++)
{
var option = options[i].substring(1, options[i].length - 1).split("', '")
flavorModel.append({text: option[1], value: option[0]});
}
}
}
}
currentIndex:
{
var index = model.indexOf(machineGCodeFlavorProvider.properties.value);
if(index == -1)
var currentValue = machineGCodeFlavorProvider.properties.value;
var index = 0;
for(var i = 0; i < flavorModel.count; i++)
{
index = 0;
if(flavorModel.get(i).value == currentValue) {
index = i;
break;
}
}
return index
}
onActivated:
{
machineGCodeFlavorProvider.setPropertyValue("value", model[index]);
machineGCodeFlavorProvider.setPropertyValue("value", flavorModel.get(index).value);
manager.updateHasMaterialsMetadata();
}
}
@ -273,17 +348,20 @@ Cura.MachineAction
Label
{
text: catalog.i18nc("@label", "Nozzle size")
visible: !Cura.MachineManager.hasVariants
}
TextField
{
id: nozzleSizeField
text: machineNozzleSizeProvider.properties.value
visible: !Cura.MachineManager.hasVariants
validator: RegExpValidator { regExp: /[0-9\.]{0,6}/ }
onEditingFinished: { machineNozzleSizeProvider.setPropertyValue("value", text) }
}
Label
{
text: catalog.i18nc("@label", "mm")
visible: !Cura.MachineManager.hasVariants
}
}
}
@ -308,6 +386,8 @@ Cura.MachineAction
id: machineStartGcodeField
width: parent.width
height: parent.height - y
font: UM.Theme.getFont("fixed")
wrapMode: TextEdit.NoWrap
text: machineStartGcodeProvider.properties.value
onActiveFocusChanged:
{
@ -330,6 +410,8 @@ Cura.MachineAction
id: machineEndGcodeField
width: parent.width
height: parent.height - y
font: UM.Theme.getFont("fixed")
wrapMode: TextEdit.NoWrap
text: machineEndGcodeProvider.properties.value
onActiveFocusChanged:
{
@ -377,7 +459,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_width"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -387,7 +469,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_depth"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -397,7 +479,17 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_height"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
{
id: machineShapeProvider
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_shape"
watchedProperties: [ "value", "options" ]
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -407,7 +499,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_heated_bed"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -417,7 +509,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_center_is_zero"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -426,8 +518,8 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_gcode_flavor"
watchedProperties: [ "value" ]
storeIndex: 4
watchedProperties: [ "value", "options" ]
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -437,7 +529,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_nozzle_size"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -447,7 +539,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "gantry_height"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -457,7 +549,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_head_with_fans_polygon"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
@ -468,7 +560,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_start_gcode"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
UM.SettingPropertyProvider
@ -478,7 +570,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_end_gcode"
watchedProperties: [ "value" ]
storeIndex: 4
storeIndex: manager.containerIndex
}
}

View file

@ -351,7 +351,7 @@ Item {
{
if(text != "")
{
listview.model.filter = {"settable_per_mesh": true, "label": "*" + text}
listview.model.filter = {"settable_per_mesh": true, "i18n_label": "*" + text}
}
else
{

View file

@ -17,41 +17,60 @@ class OSXRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
drives = {}
p = subprocess.Popen(["system_profiler", "SPUSBDataType", "-xml"], stdout = subprocess.PIPE)
plist = plistlib.loads(p.communicate()[0])
p.wait()
for entry in plist:
if "_items" in entry:
for item in entry["_items"]:
for dev in item["_items"]:
if "removable_media" in dev and dev["removable_media"] == "yes" and "volumes" in dev and len(dev["volumes"]) > 0:
for vol in dev["volumes"]:
if "mount_point" in vol:
volume = vol["mount_point"]
drives[volume] = os.path.basename(volume)
result = self._recursiveSearch(plist, "removable_media")
p = subprocess.Popen(["system_profiler", "SPCardReaderDataType", "-xml"], stdout=subprocess.PIPE)
plist = plistlib.loads(p.communicate()[0])
p.wait()
for entry in plist:
if "_items" in entry:
for item in entry["_items"]:
for dev in item["_items"]:
if "removable_media" in dev and dev["removable_media"] == "yes" and "volumes" in dev and len(dev["volumes"]) > 0:
for vol in dev["volumes"]:
if "mount_point" in vol:
volume = vol["mount_point"]
drives[volume] = os.path.basename(volume)
result.extend(self._recursiveSearch(plist, "removable_media"))
for drive in result:
# Ignore everything not explicitly marked as removable
if drive["removable_media"] != "yes":
continue
# Ignore any removable device that does not have an actual volume
if "volumes" not in drive or not drive["volumes"]:
continue
for volume in drive["volumes"]:
if not "mount_point" in volume:
continue
mount_point = volume["mount_point"]
if "_name" in volume:
drive_name = volume["_name"]
else:
drive_name = os.path.basename(mount_point)
drives[mount_point] = drive_name
return drives
def performEjectDevice(self, device):
p = subprocess.Popen(["diskutil", "eject", device.getId()], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
output = p.communicate()
Logger.log("d", "umount returned: %s.", repr(output))
return_code = p.wait()
if return_code != 0:
return False
else:
return True
return True
# Recursively search for key in a plist parsed by plistlib
def _recursiveSearch(self, plist, key):
result = []
for entry in plist:
if key in entry:
result.append(entry)
continue
if "_items" in entry:
result.extend(self._recursiveSearch(entry["_items"], key))
if "Media" in entry:
result.extend(self._recursiveSearch(entry["Media"], key))
return result

View file

@ -6,7 +6,7 @@ import os.path
from UM.Application import Application
from UM.Logger import Logger
from UM.Message import Message
from UM.Mesh.WriteMeshJob import WriteMeshJob
from UM.FileHandler.WriteFileJob import WriteFileJob
from UM.Mesh.MeshWriter import MeshWriter
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.OutputDevice.OutputDevice import OutputDevice
@ -37,13 +37,17 @@ class RemovableDriveOutputDevice(OutputDevice):
# meshes.
# \param limit_mimetypes Should we limit the available MIME types to the
# MIME types available to the currently active machine?
def requestWrite(self, nodes, file_name = None, filter_by_machine = False):
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
filter_by_machine = True # This plugin is indended to be used by machine (regardless of what it was told to do)
if self._writing:
raise OutputDeviceError.DeviceBusyError()
# Formats supported by this application (File types that we can actually write)
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
if file_handler:
file_formats = file_handler.getSupportedFileTypesWrite()
else:
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
if filter_by_machine:
container = Application.getInstance().getGlobalContainerStack().findContainer({"file_formats": "*"})
@ -58,7 +62,11 @@ class RemovableDriveOutputDevice(OutputDevice):
raise OutputDeviceError.WriteRequestFailedError()
# Just take the first file format available.
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"])
if file_handler is not None:
writer = file_handler.getWriterByMimeType(file_formats[0]["mime_type"])
else:
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"])
extension = file_formats[0]["extension"]
if file_name is None:
@ -72,7 +80,7 @@ class RemovableDriveOutputDevice(OutputDevice):
Logger.log("d", "Writing to %s", file_name)
# Using buffering greatly reduces the write time for many lines of gcode
self._stream = open(file_name, "wt", buffering = 1, encoding = "utf-8")
job = WriteMeshJob(writer, self._stream, nodes, MeshWriter.OutputMode.TextMode)
job = WriteFileJob(writer, self._stream, nodes, MeshWriter.OutputMode.TextMode)
job.setFileName(file_name)
job.progress.connect(self._onProgress)
job.finished.connect(self._onFinished)

View file

@ -0,0 +1,148 @@
from cura.MachineAction import MachineAction
from UM.Application import Application
from UM.PluginRegistry import PluginRegistry
from UM.Logger import Logger
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QUrl, QObject
from PyQt5.QtQml import QQmlComponent, QQmlContext
import os.path
import time
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
class DiscoverUM3Action(MachineAction):
def __init__(self):
super().__init__("DiscoverUM3Action", catalog.i18nc("@action","Connect via Network"))
self._qml_url = "DiscoverUM3Action.qml"
self._network_plugin = None
self.__additional_components_context = None
self.__additional_component = None
self.__additional_components_view = None
Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView)
self._last_zeroconf_event_time = time.time()
self._zeroconf_change_grace_period = 0.25 # Time to wait after a zeroconf service change before allowing a zeroconf reset
printersChanged = pyqtSignal()
@pyqtSlot()
def startDiscovery(self):
if not self._network_plugin:
self._network_plugin = Application.getInstance().getOutputDeviceManager().getOutputDevicePlugin("UM3NetworkPrinting")
self._network_plugin.printerListChanged.connect(self._onPrinterDiscoveryChanged)
self.printersChanged.emit()
## Re-filters the list of printers.
@pyqtSlot()
def reset(self):
self.printersChanged.emit()
@pyqtSlot()
def restartDiscovery(self):
# Ensure that there is a bit of time after a printer has been discovered.
# This is a work around for an issue with Qt 5.5.1 up to Qt 5.7 which can segfault if we do this too often.
# It's most likely that the QML engine is still creating delegates, where the python side already deleted or
# garbage collected the data.
# Whatever the case, waiting a bit ensures that it doesn't crash.
if time.time() - self._last_zeroconf_event_time > self._zeroconf_change_grace_period:
if not self._network_plugin:
self.startDiscovery()
else:
self._network_plugin.startDiscovery()
@pyqtSlot(str, str)
def removeManualPrinter(self, key, address):
if not self._network_plugin:
return
self._network_plugin.removeManualPrinter(key, address)
@pyqtSlot(str, str)
def setManualPrinter(self, key, address):
if key != "":
# This manual printer replaces a current manual printer
self._network_plugin.removeManualPrinter(key)
if address != "":
self._network_plugin.addManualPrinter(address)
def _onPrinterDiscoveryChanged(self, *args):
self._last_zeroconf_event_time = time.time()
self.printersChanged.emit()
@pyqtProperty("QVariantList", notify = printersChanged)
def foundDevices(self):
if self._network_plugin:
if Application.getInstance().getGlobalContainerStack():
global_printer_type = Application.getInstance().getGlobalContainerStack().getBottom().getId()
else:
global_printer_type = "unknown"
printers = list(self._network_plugin.getPrinters().values())
# TODO; There are still some testing printers that don't have a correct printer type, so don't filter out unkown ones just yet.
printers = [printer for printer in printers if printer.printerType == global_printer_type or printer.printerType == "unknown"]
printers.sort(key = lambda k: k.name)
return printers
else:
return []
@pyqtSlot(str)
def setKey(self, key):
global_container_stack = Application.getInstance().getGlobalContainerStack()
if global_container_stack:
meta_data = global_container_stack.getMetaData()
if "um_network_key" in meta_data:
global_container_stack.setMetaDataEntry("um_network_key", key)
# Delete old authentication data.
global_container_stack.removeMetaDataEntry("network_authentication_id")
global_container_stack.removeMetaDataEntry("network_authentication_key")
else:
global_container_stack.addMetaDataEntry("um_network_key", key)
if self._network_plugin:
# Ensure that the connection states are refreshed.
self._network_plugin.reCheckConnections()
@pyqtSlot(result = str)
def getStoredKey(self):
global_container_stack = Application.getInstance().getGlobalContainerStack()
if global_container_stack:
meta_data = global_container_stack.getMetaData()
if "um_network_key" in meta_data:
return global_container_stack.getMetaDataEntry("um_network_key")
return ""
@pyqtSlot()
def loadConfigurationFromPrinter(self):
machine_manager = Application.getInstance().getMachineManager()
hotend_ids = machine_manager.printerOutputDevices[0].hotendIds
for index in range(len(hotend_ids)):
machine_manager.printerOutputDevices[0].hotendIdChanged.emit(index, hotend_ids[index])
material_ids = machine_manager.printerOutputDevices[0].materialIds
for index in range(len(material_ids)):
machine_manager.printerOutputDevices[0].materialIdChanged.emit(index, material_ids[index])
def _createAdditionalComponentsView(self):
Logger.log("d", "Creating additional ui components for UM3.")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.qml"))
self.__additional_component = QQmlComponent(Application.getInstance()._engine, path)
# We need access to engine (although technically we can't)
self.__additional_components_context = QQmlContext(Application.getInstance()._engine.rootContext())
self.__additional_components_context.setContextProperty("manager", self)
self.__additional_components_view = self.__additional_component.create(self.__additional_components_context)
if not self.__additional_components_view:
Logger.log("w", "Could not create ui components for UM3.")
return
Application.getInstance().addAdditionalComponent("monitorButtons", self.__additional_components_view.findChild(QObject, "networkPrinterConnectButton"))
Application.getInstance().addAdditionalComponent("machinesDetailPane", self.__additional_components_view.findChild(QObject, "networkPrinterConnectionInfo"))

View file

@ -0,0 +1,369 @@
import UM 1.2 as UM
import Cura 1.0 as Cura
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
Cura.MachineAction
{
id: base
anchors.fill: parent;
property var selectedPrinter: null
property bool completeProperties: true
property var connectingToPrinter: null
Connections
{
target: dialog ? dialog : null
ignoreUnknownSignals: true
onNextClicked:
{
// Connect to the printer if the MachineAction is currently shown
if(base.parent.wizard == dialog)
{
connectToPrinter();
}
}
}
function connectToPrinter()
{
if(base.selectedPrinter && base.completeProperties)
{
var printerKey = base.selectedPrinter.getKey()
if(connectingToPrinter != printerKey) {
// prevent an infinite loop
connectingToPrinter = printerKey;
manager.setKey(printerKey);
completed();
}
}
}
Column
{
anchors.fill: parent;
id: discoverUM3Action
spacing: UM.Theme.getSize("default_margin").height
SystemPalette { id: palette }
UM.I18nCatalog { id: catalog; name:"cura" }
Label
{
id: pageTitle
width: parent.width
text: catalog.i18nc("@title:window", "Connect to Networked Printer")
wrapMode: Text.WordWrap
font.pointSize: 18
}
Label
{
id: pageDescription
width: parent.width
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "To print directly to your printer over the network, please make sure your printer is connected to the network using a network cable or by connecting your printer to your WIFI network. If you don't connect Cura with your printer, you can still use a USB drive to transfer g-code files to your printer.\n\nSelect your printer from the list below:")
}
Row
{
spacing: UM.Theme.getSize("default_lining").width
Button
{
id: addButton
text: catalog.i18nc("@action:button", "Add");
onClicked:
{
manualPrinterDialog.showDialog("", "");
}
}
Button
{
id: editButton
text: catalog.i18nc("@action:button", "Edit")
enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
onClicked:
{
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
}
}
Button
{
id: removeButton
text: catalog.i18nc("@action:button", "Remove")
enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
}
Button
{
id: rediscoverButton
text: catalog.i18nc("@action:button", "Refresh")
onClicked: manager.restartDiscovery()
}
}
Row
{
id: contentRow
width: parent.width
spacing: UM.Theme.getSize("default_margin").width
Column
{
width: parent.width * 0.5
spacing: UM.Theme.getSize("default_margin").height
ScrollView
{
id: objectListContainer
frameVisible: true
width: parent.width
height: base.height - contentRow.y - discoveryTip.height
Rectangle
{
parent: viewport
anchors.fill: parent
color: palette.light
}
ListView
{
id: listview
model: manager.foundDevices
onModelChanged:
{
var selectedKey = manager.getStoredKey();
for(var i = 0; i < model.length; i++) {
if(model[i].getKey() == selectedKey)
{
currentIndex = i;
return
}
}
currentIndex = -1;
}
width: parent.width
currentIndex: -1
onCurrentIndexChanged:
{
base.selectedPrinter = listview.model[currentIndex];
// Only allow connecting if the printer has responded to API query since the last refresh
base.completeProperties = base.selectedPrinter != null && base.selectedPrinter.getProperty("incomplete") != "true";
}
Component.onCompleted: manager.startDiscovery()
delegate: Rectangle
{
height: childrenRect.height
color: ListView.isCurrentItem ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
width: parent.width
Label
{
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
anchors.right: parent.right
text: listview.model[index].name
color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text
elide: Text.ElideRight
}
MouseArea
{
anchors.fill: parent;
onClicked:
{
if(!parent.ListView.isCurrentItem)
{
parent.ListView.view.currentIndex = index;
}
}
}
}
}
}
Label
{
id: discoveryTip
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
//: Tips label
//TODO: get actual link from webteam
text: catalog.i18nc("@label", "If your printer is not listed, read the <a href='%1'>network-printing troubleshooting guide</a>").arg("https://ultimaker.com/en/troubleshooting");
onLinkActivated: Qt.openUrlExternally(link)
}
}
Column
{
width: parent.width * 0.5
visible: base.selectedPrinter ? true : false
spacing: UM.Theme.getSize("default_margin").height
Label
{
width: parent.width
wrapMode: Text.WordWrap
text: base.selectedPrinter ? base.selectedPrinter.name : ""
font: UM.Theme.getFont("large")
elide: Text.ElideRight
}
Grid
{
visible: base.completeProperties
width: parent.width
columns: 2
Label
{
width: parent.width * 0.5
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "Type")
}
Label
{
width: parent.width * 0.5
wrapMode: Text.WordWrap
text:
{
if(base.selectedPrinter)
{
if(base.selectedPrinter.printerType == "ultimaker3")
{
return catalog.i18nc("@label", "Ultimaker 3")
} else if(base.selectedPrinter.printerType == "ultimaker3_extended")
{
return catalog.i18nc("@label", "Ultimaker 3 Extended")
} else
{
return catalog.i18nc("@label", "Unknown") // We have no idea what type it is. Should not happen 'in the field'
}
}
else
{
return ""
}
}
}
Label
{
width: parent.width * 0.5
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "Firmware version")
}
Label
{
width: parent.width * 0.5
wrapMode: Text.WordWrap
text: base.selectedPrinter ? base.selectedPrinter.firmwareVersion : ""
}
Label
{
width: parent.width * 0.5
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "Address")
}
Label
{
width: parent.width * 0.5
wrapMode: Text.WordWrap
text: base.selectedPrinter ? base.selectedPrinter.ipAddress : ""
}
}
Label
{
width: parent.width
wrapMode: Text.WordWrap
visible: base.selectedPrinter != null && !base.completeProperties
text: catalog.i18nc("@label", "The printer at this address has not yet responded." )
}
Button
{
text: catalog.i18nc("@action:button", "Connect")
enabled: (base.selectedPrinter && base.completeProperties) ? true : false
onClicked: connectToPrinter()
}
}
}
}
UM.Dialog
{
id: manualPrinterDialog
property string printerKey
property alias addressText: addressField.text
title: catalog.i18nc("@title:window", "Printer Address")
minimumWidth: 400 * Screen.devicePixelRatio
minimumHeight: 120 * Screen.devicePixelRatio
width: minimumWidth
height: minimumHeight
signal showDialog(string key, string address)
onShowDialog:
{
printerKey = key;
addressText = address;
addressField.selectAll();
addressField.focus = true;
manualPrinterDialog.show();
}
onAccepted:
{
manager.setManualPrinter(printerKey, addressText)
}
Column {
anchors.fill: parent
spacing: UM.Theme.getSize("default_margin").height
Label
{
text: catalog.i18nc("@alabel","Enter the IP address or hostname of your printer on the network.")
width: parent.width
wrapMode: Text.WordWrap
}
TextField
{
id: addressField
width: parent.width
maximumLength: 40
validator: RegExpValidator
{
regExp: /[a-zA-Z0-9\.\-\_]*/
}
}
}
rightButtons: [
Button {
text: catalog.i18nc("@action:button","Cancel")
onClicked:
{
manualPrinterDialog.reject()
manualPrinterDialog.hide()
}
},
Button {
text: catalog.i18nc("@action:button", "Ok")
onClicked:
{
manualPrinterDialog.accept()
manualPrinterDialog.hide()
}
enabled: manualPrinterDialog.addressText.trim() != ""
isDefault: true
}
]
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,210 @@
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
from . import NetworkPrinterOutputDevice
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
from UM.Logger import Logger
from UM.Signal import Signal, signalemitter
from UM.Application import Application
from UM.Preferences import Preferences
from PyQt5.QtNetwork import QNetworkRequest, QNetworkAccessManager, QNetworkReply
from PyQt5.QtCore import QUrl
import time
import json
## This plugin handles the connection detection & creation of output device objects for the UM3 printer.
# Zero-Conf is used to detect printers, which are saved in a dict.
# If we discover a printer that has the same key as the active machine instance a connection is made.
@signalemitter
class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
def __init__(self):
super().__init__()
self._zero_conf = None
self._browser = None
self._printers = {}
self._api_version = "1"
self._api_prefix = "/api/v" + self._api_version + "/"
self._network_manager = QNetworkAccessManager()
self._network_manager.finished.connect(self._onNetworkRequestFinished)
# List of old printer names. This is used to ensure that a refresh of zeroconf does not needlessly forces
# authentication requests.
self._old_printers = []
# Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
self.addPrinterSignal.connect(self.addPrinter)
self.removePrinterSignal.connect(self.removePrinter)
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
# Get list of manual printers from preferences
self._preferences = Preferences.getInstance()
self._preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
self._manual_instances = self._preferences.getValue("um3networkprinting/manual_instances").split(",")
addPrinterSignal = Signal()
removePrinterSignal = Signal()
printerListChanged = Signal()
## Start looking for devices on network.
def start(self):
self.startDiscovery()
def startDiscovery(self):
self.stop()
if self._browser:
self._browser.cancel()
self._browser = None
self._old_printers = [printer_name for printer_name in self._printers]
self._printers = {}
self.printerListChanged.emit()
# After network switching, one must make a new instance of Zeroconf
# On windows, the instance creation is very fast (unnoticable). Other platforms?
self._zero_conf = Zeroconf()
self._browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.', [self._onServiceChanged])
# Look for manual instances from preference
for address in self._manual_instances:
if address:
self.addManualPrinter(address)
def addManualPrinter(self, address):
if address not in self._manual_instances:
self._manual_instances.append(address)
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
name = address
instance_name = "manual:%s" % address
properties = { b"name": name.encode("utf-8"), b"manual": b"true", b"incomplete": b"true" }
if instance_name not in self._printers:
# Add a preliminary printer instance
self.addPrinter(instance_name, address, properties)
self.checkManualPrinter(address)
def removeManualPrinter(self, key, address = None):
if key in self._printers:
if not address:
address = self._printers[key].ipAddress
self.removePrinter(key)
if address in self._manual_instances:
self._manual_instances.remove(address)
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
def checkManualPrinter(self, address):
# Check if a printer exists at this address
# If a printer responds, it will replace the preliminary printer created above
url = QUrl("http://" + address + self._api_prefix + "system")
name_request = QNetworkRequest(url)
self._network_manager.get(name_request)
## Handler for all requests that have finished.
def _onNetworkRequestFinished(self, reply):
reply_url = reply.url().toString()
status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
if reply.operation() == QNetworkAccessManager.GetOperation:
if "system" in reply_url: # Name returned from printer.
if status_code == 200:
system_info = json.loads(bytes(reply.readAll()).decode("utf-8"))
address = reply.url().host()
name = ("%s (%s)" % (system_info["name"], address))
instance_name = "manual:%s" % address
properties = { b"name": name.encode("utf-8"), b"firmware_version": system_info["firmware"].encode("utf-8"), b"manual": b"true" }
if instance_name in self._printers:
# Only replace the printer if it is still in the list of (manual) printers
self.removePrinter(instance_name)
self.addPrinter(instance_name, address, properties)
## Stop looking for devices on network.
def stop(self):
if self._zero_conf is not None:
Logger.log("d", "zeroconf close...")
self._zero_conf.close()
def getPrinters(self):
return self._printers
def reCheckConnections(self):
active_machine = Application.getInstance().getGlobalContainerStack()
if not active_machine:
return
for key in self._printers:
if key == active_machine.getMetaDataEntry("um_network_key"):
Logger.log("d", "Connecting [%s]..." % key)
self._printers[key].connect()
self._printers[key].connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
else:
if self._printers[key].isConnected():
Logger.log("d", "Closing connection [%s]..." % key)
self._printers[key].close()
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
def addPrinter(self, name, address, properties):
printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties, self._api_prefix)
self._printers[printer.getKey()] = printer
global_container_stack = Application.getInstance().getGlobalContainerStack()
if global_container_stack and printer.getKey() == global_container_stack.getMetaDataEntry("um_network_key"):
if printer.getKey() not in self._old_printers: # Was the printer already connected, but a re-scan forced?
Logger.log("d", "addPrinter, connecting [%s]..." % printer.getKey())
self._printers[printer.getKey()].connect()
printer.connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
self.printerListChanged.emit()
def removePrinter(self, name):
printer = self._printers.pop(name, None)
if printer:
if printer.isConnected():
printer.connectionStateChanged.disconnect(self._onPrinterConnectionStateChanged)
Logger.log("d", "removePrinter, disconnecting [%s]..." % name)
printer.disconnect()
self.printerListChanged.emit()
## Handler for when the connection state of one of the detected printers changes
def _onPrinterConnectionStateChanged(self, key):
if key not in self._printers:
return
if self._printers[key].isConnected():
self.getOutputDeviceManager().addOutputDevice(self._printers[key])
else:
self.getOutputDeviceManager().removeOutputDevice(key)
## Handler for zeroConf detection
def _onServiceChanged(self, zeroconf, service_type, name, state_change):
if state_change == ServiceStateChange.Added:
Logger.log("d", "Bonjour service added: %s" % name)
# First try getting info from zeroconf cache
info = ServiceInfo(service_type, name, properties = {})
for record in zeroconf.cache.entries_with_name(name.lower()):
info.update_record(zeroconf, time.time(), record)
for record in zeroconf.cache.entries_with_name(info.server):
info.update_record(zeroconf, time.time(), record)
if info.address:
break
# Request more data if info is not complete
if not info.address:
Logger.log("d", "Trying to get address of %s", name)
info = zeroconf.get_service_info(service_type, name)
if info:
type_of_device = info.properties.get(b"type", None).decode("utf-8")
if type_of_device == "printer":
address = '.'.join(map(lambda n: str(n), info.address))
self.addPrinterSignal.emit(str(name), address, info.properties)
else:
Logger.log("w", "The type of the found device is '%s', not 'printer'! Ignoring.." %type_of_device )
else:
Logger.log("w", "Could not get information about %s" % name)
elif state_change == ServiceStateChange.Removed:
Logger.log("d", "Bonjour service removed: %s" % name)
self.removePrinterSignal.emit(str(name))

View file

@ -0,0 +1,124 @@
import UM 1.2 as UM
import Cura 1.0 as Cura
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
Item
{
id: base
property bool isUM3: Cura.MachineManager.activeQualityDefinitionId == "ultimaker3"
property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
property bool authenticationRequested: printerConnected && Cura.MachineManager.printerOutputDevices[0].authenticationState == 2 // AuthState.AuthenticationRequested
Row
{
objectName: "networkPrinterConnectButton"
visible: isUM3
spacing: UM.Theme.getSize("default_margin").width
Button
{
height: UM.Theme.getSize("save_button_save_to_button").height
tooltip: catalog.i18nc("@info:tooltip", "Send access request to the printer")
text: catalog.i18nc("@action:button", "Request Access")
style: UM.Theme.styles.sidebar_action_button
onClicked: Cura.MachineManager.printerOutputDevices[0].requestAuthentication()
visible: printerConnected && !printerAcceptsCommands && !authenticationRequested
}
Button
{
height: UM.Theme.getSize("save_button_save_to_button").height
tooltip: catalog.i18nc("@info:tooltip", "Connect to a printer")
text: catalog.i18nc("@action:button", "Connect")
style: UM.Theme.styles.sidebar_action_button
onClicked: connectActionDialog.show()
visible: !printerConnected
}
}
UM.Dialog
{
id: connectActionDialog
Loader
{
anchors.fill: parent
source: "DiscoverUM3Action.qml"
}
rightButtons: Button
{
text: catalog.i18nc("@action:button", "Close")
iconName: "dialog-close"
onClicked: connectActionDialog.reject()
}
}
Column
{
objectName: "networkPrinterConnectionInfo"
visible: isUM3
spacing: UM.Theme.getSize("default_margin").width
anchors.fill: parent
Button
{
tooltip: catalog.i18nc("@info:tooltip", "Send access request to the printer")
text: catalog.i18nc("@action:button", "Request Access")
onClicked: Cura.MachineManager.printerOutputDevices[0].requestAuthentication()
visible: printerConnected && !printerAcceptsCommands && !authenticationRequested
}
Row
{
visible: printerConnected
spacing: UM.Theme.getSize("default_margin").width
anchors.left: parent.left
anchors.right: parent.right
height: childrenRect.height
Column
{
Repeater
{
model: Cura.ExtrudersModel { simpleNames: true }
Label { text: model.name }
}
}
Column
{
Repeater
{
id: nozzleColumn
model: printerConnected ? Cura.MachineManager.printerOutputDevices[0].hotendIds : null
Label { text: nozzleColumn.model[index] }
}
}
Column
{
Repeater
{
id: materialColumn
model: printerConnected ? Cura.MachineManager.printerOutputDevices[0].materialNames : null
Label { text: materialColumn.model[index] }
}
}
}
Button
{
tooltip: catalog.i18nc("@info:tooltip", "Load the configuration of the printer into Cura")
text: catalog.i18nc("@action:button", "Activate Configuration")
visible: printerConnected
onClicked: manager.loadConfigurationFromPrinter()
}
}
UM.I18nCatalog{id: catalog; name:"cura"}
}

View file

@ -0,0 +1,20 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from . import NetworkPrinterOutputDevicePlugin
from . import DiscoverUM3Action
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
def getMetaData():
return {
"plugin": {
"name": "UM3 Network Connection",
"author": "Ultimaker",
"description": catalog.i18nc("@info:whatsthis", "Manages network connections to Ultimaker 3 printers"),
"version": "1.0",
"api": 3
}
}
def register(app):
return { "output_device": NetworkPrinterOutputDevicePlugin.NetworkPrinterOutputDevicePlugin(), "machine_action": DiscoverUM3Action.DiscoverUM3Action()}

View file

@ -432,7 +432,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
# This is ignored.
# \param filter_by_machine Whether to filter MIME types by machine. This
# is ignored.
def requestWrite(self, nodes, file_name = None, filter_by_machine = False):
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
container_stack = Application.getInstance().getGlobalContainerStack()
if container_stack.getProperty("machine_gcode_flavor", "value") == "UltiGCode" or not container_stack.getMetaDataEntry("supports_usb_connection"):
self._error_message = Message(catalog.i18nc("@info:status",
"Unable to start a new job because the printer does not support usb printing."))
self._error_message.show()
return
Application.getInstance().showPrintMonitor.emit(True)
self.startPrint()

View file

@ -8,6 +8,8 @@ from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
## A simple action to handle manual bed leveling procedure for printers that don't have it on the firmware.
# This is currently only used by the Ultimaker Original+
class BedLevelMachineAction(MachineAction):
def __init__(self):
super().__init__("BedLevel", catalog.i18nc("@action", "Level build plate"))

View file

@ -8,6 +8,7 @@ from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
## Action to check up if the self-built UMO was done correctly.
class UMOCheckupMachineAction(MachineAction):
def __init__(self):
super().__init__("UMOCheckup", catalog.i18nc("@action", "Checkup"))
@ -27,7 +28,6 @@ class UMOCheckupMachineAction(MachineAction):
Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged)
onBedTestCompleted = pyqtSignal()
onHotendTestCompleted = pyqtSignal()

View file

@ -7,6 +7,11 @@ from UM.i18n import i18nCatalog
from UM.Application import Application
catalog = i18nCatalog("cura")
import UM.Settings.InstanceContainer
## The Ultimaker Original can have a few revisions & upgrades. This action helps with selecting them, so they are added
# as a variant.
class UMOUpgradeSelection(MachineAction):
def __init__(self):
super().__init__("UMOUpgradeSelection", catalog.i18nc("@action", "Select upgrades"))
@ -27,19 +32,23 @@ class UMOUpgradeSelection(MachineAction):
def setHeatedBed(self, heated_bed = True):
global_container_stack = Application.getInstance().getGlobalContainerStack()
if global_container_stack:
variant = global_container_stack.findContainer({"type": "variant"})
if variant:
if variant.getId() == "empty_variant":
variant_index = global_container_stack.getContainerIndex(variant)
variant = self._createVariant(global_container_stack, variant_index)
variant.setProperty("machine_heated_bed", "value", heated_bed)
self.heatedBedChanged.emit()
# Make sure there is a definition_changes container to store the machine settings
definition_changes_container = global_container_stack.findContainer({"type": "definition_changes"})
if not definition_changes_container:
definition_changes_container = self._createDefinitionChangesContainer(global_container_stack)
def _createVariant(self, global_container_stack, variant_index):
# Create and switch to a variant to store the settings in
new_variant = InstanceContainer(global_container_stack.getName() + "_variant")
new_variant.addMetaDataEntry("type", "variant")
new_variant.setDefinition(global_container_stack.getBottom())
ContainerRegistry.getInstance().addContainer(new_variant)
global_container_stack.replaceContainer(variant_index, new_variant)
return new_variant
definition_changes_container.setProperty("machine_heated_bed", "value", heated_bed)
self.heatedBedChanged.emit()
def _createDefinitionChangesContainer(self, global_container_stack):
# Create a definition_changes container to store the settings in and add it to the stack
definition_changes_container = UM.Settings.InstanceContainer(global_container_stack.getName() + "_settings")
definition = global_container_stack.getBottom()
definition_changes_container.setDefinition(definition)
definition_changes_container.addMetaDataEntry("type", "definition_changes")
UM.Settings.ContainerRegistry.getInstance().addContainer(definition_changes_container)
# Insert definition_changes between the definition and the variant
global_container_stack.insertContainer(-1, definition_changes_container)
return definition_changes_container

View file

@ -6,6 +6,7 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
catalog = i18nCatalog("cura")
## Upgrade the firmware of a machine by USB with this action.
class UpgradeFirmwareMachineAction(MachineAction):
def __init__(self):
super().__init__("UpgradeFirmware", catalog.i18nc("@action", "Upgrade Firmware"))
@ -13,6 +14,6 @@ class UpgradeFirmwareMachineAction(MachineAction):
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
def _onContainerAdded(self, container):
# Add this action as a supported action to all machine definitions
# Add this action as a supported action to all machine definitions if they support USB connection
if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine" and container.getMetaDataEntry("supports_usb_connection"):
Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())

View file

@ -0,0 +1,120 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import configparser #To get version numbers from config files.
import os
import os.path
import io
from UM import Resources
from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin.
class VersionUpgrade22to24(VersionUpgrade):
def upgradeMachineInstance(self, serialised, filename):
# All of this is needed to upgrade custom variant machines from old Cura to 2.4 where
# `definition_changes` instance container has been introduced. Variant files which
# look like the the handy work of the old machine settings plugin are converted directly
# on disk.
config = configparser.ConfigParser(interpolation = None)
config.read_string(serialised) # Read the input string as config file.
config.set("general", "version", "3")
container_list = []
if config.has_section("containers"):
for index, container_id in config.items("containers"):
container_list.append(container_id)
elif config.has_option("general", "containers"):
containers = config.get("general", "containers")
container_list = containers.split(",")
user_variants = self.__getUserVariants()
name_path_dict = {}
for variant in user_variants:
name_path_dict[variant.get("name")] = variant.get("path")
user_variant_names = set(container_list).intersection(name_path_dict.keys())
if len(user_variant_names):
# One of the user defined variants appears in the list of containers in the stack.
for variant_name in user_variant_names: # really there should just be one variant to convert.
config_name = self.__convertVariant(name_path_dict.get(variant_name))
# Change the name of variant and insert empty_variant into the stack.
new_container_list = []
for item in container_list:
if item == variant_name:
new_container_list.append(config_name)
new_container_list.append("empty_variant")
else:
new_container_list.append(item)
container_list = new_container_list
if not config.has_section("containers"):
config.add_section("containers")
config.remove_option("general", "containers")
for index in range(len(container_list)):
config.set("containers", index, container_list[index])
output = io.StringIO()
config.write(output)
return [filename], [output.getvalue()]
def __convertVariant(self, variant_path):
# Copy the variant to the machine_instances/*_settings.inst.cfg
variant_config = configparser.ConfigParser(interpolation=None)
with open(variant_path, "r") as fhandle:
variant_config.read_file(fhandle)
if variant_config.has_section("general") and variant_config.has_option("general", "name"):
config_name = variant_config.get("general", "name")
if config_name.endswith("_variant"):
config_name = config_name[:-len("_variant")] + "_settings"
variant_config.set("general", "name", config_name)
if not variant_config.has_section("metadata"):
variant_config.add_section("metadata")
variant_config.set("metadata", "type", "definition_changes")
resource_path = Resources.getDataStoragePath()
machine_instances_dir = os.path.join(resource_path, "machine_instances")
if variant_path.endswith("_variant.inst.cfg"):
variant_path = variant_path[:-len("_variant.inst.cfg")] + "_settings.inst.cfg"
with open(os.path.join(machine_instances_dir, os.path.basename(variant_path)), "w") as fp:
variant_config.write(fp)
return config_name
def __getUserVariants(self):
resource_path = Resources.getDataStoragePath()
variants_dir = os.path.join(resource_path, "variants")
result = []
for entry in os.scandir(variants_dir):
if entry.name.endswith('.inst.cfg') and entry.is_file():
config = configparser.ConfigParser(interpolation = None)
with open(entry.path, "r") as fhandle:
config.read_file(fhandle)
if config.has_section("general") and config.has_option("general", "name"):
result.append( { "path": entry.path, "name": config.get("general", "name") } )
return result
def upgradeExtruderTrain(self, serialised, filename):
config = configparser.ConfigParser(interpolation = None)
config.read_string(serialised) # Read the input string as config file.
config.set("general", "version", "3") # Just bump the version number. That is all we need for now.
output = io.StringIO()
config.write(output)
return [filename], [output.getvalue()]
def getCfgVersion(self, serialised):
parser = configparser.ConfigParser(interpolation = None)
parser.read_string(serialised)
return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.

View file

@ -0,0 +1,38 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from . import VersionUpgrade
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
upgrade = VersionUpgrade.VersionUpgrade22to24()
def getMetaData():
return {
"plugin": {
"name": catalog.i18nc("@label", "Version Upgrade 2.2 to 2.4"),
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Upgrades configurations from Cura 2.2 to Cura 2.4."),
"api": 3
},
"version_upgrade": {
# From To Upgrade function
("machine_instance", 2): ("machine_stack", 3, upgrade.upgradeMachineInstance),
("extruder_train", 2): ("extruder_train", 3, upgrade.upgradeExtruderTrain)
},
"sources": {
"machine_stack": {
"get_version": upgrade.getCfgVersion,
"location": {"./machine_instances"}
},
"extruder_train": {
"get_version": upgrade.getCfgVersion,
"location": {"./extruders"}
},
}
}
def register(app):
return { "version_upgrade": upgrade }

View file

@ -700,7 +700,11 @@ class X3DReader(MeshReader):
if not c is None:
pt = c.attrib.get("point")
if pt:
co = [float(x) for x in pt.split()]
# allow the list of float values in 'point' attribute to
# be separated by commas or whitespace as per spec of
# XML encoding of X3D
# Ref ISO/IEC 19776-1:2015 : Section 5.1.2
co = [float(x) for vec in pt.split(',') for x in vec.split()]
num_verts = len(co) // 3
self.verts = numpy.empty((4, num_verts), dtype=numpy.float32)
self.verts[3,:] = numpy.ones((num_verts), dtype=numpy.float32)

View file

@ -37,7 +37,7 @@ class XmlMaterialProfile(InstanceContainer):
if self.isReadOnly():
return
if self.getMetaDataEntry(key, None) == value:
# Prevent loop caused by for loop.
# Prevent recursion caused by for loop.
return
super().setMetaDataEntry(key, value)
@ -67,6 +67,17 @@ class XmlMaterialProfile(InstanceContainer):
for container in containers:
container.setName(new_name)
## Overridden from InstanceContainer, to set dirty to base file as well.
def setDirty(self, dirty):
super().setDirty(dirty)
base_file = self.getMetaDataEntry("base_file", None)
if base_file is not None and base_file != self._id:
containers = UM.Settings.ContainerRegistry.getInstance().findContainers(id=base_file)
if containers:
base_container = containers[0]
if not base_container.isReadOnly():
base_container.setDirty(dirty)
## Overridden from InstanceContainer
# def setProperty(self, key, property_name, property_value, container = None):
# if self.isReadOnly():
@ -348,10 +359,22 @@ class XmlMaterialProfile(InstanceContainer):
mapping[key] = element
first.append(element)
def clearData(self):
self._metadata = {}
self._name = ""
self._definition = None
self._instances = {}
self._read_only = False
self._dirty = False
self._path = ""
## Overridden from InstanceContainer
def deserialize(self, serialized):
data = ET.fromstring(serialized)
# Reset previous metadata
self.clearData() # Ensure any previous data is gone.
self.addMetaDataEntry("type", "material")
self.addMetaDataEntry("base_file", self.id)
@ -411,7 +434,7 @@ class XmlMaterialProfile(InstanceContainer):
for entry in settings:
key = entry.get("key")
if key in self.__material_property_setting_map:
self.setProperty(self.__material_property_setting_map[key], "value", entry.text, self._definition)
self.setProperty(self.__material_property_setting_map[key], "value", entry.text)
global_setting_values[self.__material_property_setting_map[key]] = entry.text
elif key in self.__unmapped_settings:
if key == "hardware compatible":
@ -453,7 +476,16 @@ class XmlMaterialProfile(InstanceContainer):
definition = definitions[0]
if machine_compatibility:
new_material = XmlMaterialProfile(self.id + "_" + machine_id)
new_material_id = self.id + "_" + machine_id
# It could be that we are overwriting, so check if the ID already exists.
materials = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=new_material_id)
if materials:
new_material = materials[0]
new_material.clearData()
else:
new_material = XmlMaterialProfile(new_material_id)
new_material.setName(self.getName())
new_material.setMetaData(copy.deepcopy(self.getMetaData()))
new_material.setDefinition(definition)
@ -461,15 +493,15 @@ class XmlMaterialProfile(InstanceContainer):
new_material.getMetaData()["compatible"] = machine_compatibility
for key, value in global_setting_values.items():
new_material.setProperty(key, "value", value, definition)
new_material.setProperty(key, "value", value)
for key, value in machine_setting_values.items():
new_material.setProperty(key, "value", value, definition)
new_material.setProperty(key, "value", value)
new_material._dirty = False
ContainerRegistry.getInstance().addContainer(new_material)
if not materials:
ContainerRegistry.getInstance().addContainer(new_material)
hotends = machine.iterfind("./um:hotend", self.__namespaces)
for hotend in hotends:
@ -499,7 +531,15 @@ class XmlMaterialProfile(InstanceContainer):
else:
Logger.log("d", "Unsupported material setting %s", key)
new_hotend_material = XmlMaterialProfile(self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_"))
# It could be that we are overwriting, so check if the ID already exists.
new_hotend_id = self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
materials = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=new_hotend_id)
if materials:
new_hotend_material = materials[0]
new_hotend_material.clearData()
else:
new_hotend_material = XmlMaterialProfile(new_hotend_id)
new_hotend_material.setName(self.getName())
new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
new_hotend_material.setDefinition(definition)
@ -508,16 +548,17 @@ class XmlMaterialProfile(InstanceContainer):
new_hotend_material.getMetaData()["compatible"] = hotend_compatibility
for key, value in global_setting_values.items():
new_hotend_material.setProperty(key, "value", value, definition)
new_hotend_material.setProperty(key, "value", value)
for key, value in machine_setting_values.items():
new_hotend_material.setProperty(key, "value", value, definition)
new_hotend_material.setProperty(key, "value", value)
for key, value in hotend_setting_values.items():
new_hotend_material.setProperty(key, "value", value, definition)
new_hotend_material.setProperty(key, "value", value)
new_hotend_material._dirty = False
ContainerRegistry.getInstance().addContainer(new_hotend_material)
if not materials: # It was not added yet, do so now.
ContainerRegistry.getInstance().addContainer(new_hotend_material)
def _addSettingElement(self, builder, instance):
try:
@ -537,7 +578,7 @@ class XmlMaterialProfile(InstanceContainer):
# Map XML file setting names to internal names
__material_property_setting_map = {
"print temperature": "material_print_temperature",
"print temperature": "default_material_print_temperature",
"heated bed temperature": "material_bed_temperature",
"standby temperature": "material_standby_temperature",
"processing temperature graph": "material_flow_temp_graph",