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

@ -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
}
}