Merge branch 'master' of github.com:Ultimaker/Cura

This commit is contained in:
Ghostkeeper 2018-03-09 15:00:25 +01:00
commit 65591e7c26
No known key found for this signature in database
GPG Key ID: 5252B696FB5E7C7A
7 changed files with 35 additions and 37 deletions

View File

@ -357,10 +357,10 @@ class MaterialManager(QObject):
else: else:
return None return None
def getDefaultMaterial(self, global_stack: "GlobalStack", extruder_variant_name: str) -> Optional["MaterialNode"]: def getDefaultMaterial(self, global_stack: "GlobalStack", extruder_variant_name: Optional[str]) -> Optional["MaterialNode"]:
node = None node = None
machine_definition = global_stack.definition machine_definition = global_stack.definition
if parseBool(machine_definition.getMetaDataEntry("has_materials", False)): if parseBool(global_stack.getMetaDataEntry("has_materials", False)):
material_diameter = machine_definition.getProperty("material_diameter", "value") material_diameter = machine_definition.getProperty("material_diameter", "value")
if isinstance(material_diameter, SettingFunction): if isinstance(material_diameter, SettingFunction):
material_diameter = material_diameter(global_stack) material_diameter = material_diameter(global_stack)

View File

@ -905,11 +905,13 @@ class MachineManager(QObject):
def _setMaterial(self, position, container_node = None): def _setMaterial(self, position, container_node = None):
if container_node: if container_node:
self._global_container_stack.extruders[position].material = container_node.getContainer() self._global_container_stack.extruders[position].material = container_node.getContainer()
else:
self._global_container_stack.extruders[position].material = self._empty_material_container
# The _current_root_material_id is used in the MaterialMenu to see which material is selected
root_material_id = container_node.metadata["base_file"] root_material_id = container_node.metadata["base_file"]
root_material_name = container_node.getContainer().getName() root_material_name = container_node.getContainer().getName()
else:
self._global_container_stack.extruders[position].material = self._empty_material_container
root_material_id = None
root_material_name = None
# The _current_root_material_id is used in the MaterialMenu to see which material is selected
if root_material_id != self._current_root_material_id[position]: if root_material_id != self._current_root_material_id[position]:
self._current_root_material_id[position] = root_material_id self._current_root_material_id[position] = root_material_id
self._current_root_material_name[position] = root_material_name self._current_root_material_name[position] = root_material_name

View File

@ -709,7 +709,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
# function is running on the main thread (Qt thread), although those "changed" signals have been emitted, but # function is running on the main thread (Qt thread), although those "changed" signals have been emitted, but
# they won't take effect until this function is done. # they won't take effect until this function is done.
# To solve this, we schedule _updateActiveMachine() for later so it will have the latest data. # To solve this, we schedule _updateActiveMachine() for later so it will have the latest data.
Application.getInstance().setGlobalContainerStack(global_stack)
self._updateActiveMachine(global_stack) self._updateActiveMachine(global_stack)
# Load all the nodes / meshdata of the workspace # Load all the nodes / meshdata of the workspace

View File

@ -2,20 +2,16 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, pyqtSignal from PyQt5.QtCore import pyqtProperty, pyqtSignal
import UM.i18n
from UM.FlameProfiler import pyqtSlot from UM.FlameProfiler import pyqtSlot
from cura.MachineAction import MachineAction
from UM.Application import Application from UM.Application import Application
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.DefinitionContainer import DefinitionContainer from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Logger import Logger
from cura.Settings.ExtruderManager import ExtruderManager from cura.MachineAction import MachineAction
from cura.Settings.CuraStackBuilder import CuraStackBuilder from cura.Settings.CuraStackBuilder import CuraStackBuilder
import UM.i18n
catalog = UM.i18n.i18nCatalog("cura") catalog = UM.i18n.i18nCatalog("cura")
@ -26,6 +22,8 @@ class MachineSettingsAction(MachineAction):
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings")) super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
self._qml_url = "MachineSettingsAction.qml" self._qml_url = "MachineSettingsAction.qml"
self._application = Application.getInstance()
self._global_container_stack = None self._global_container_stack = None
from cura.Settings.CuraContainerStack import _ContainerIndexes from cura.Settings.CuraContainerStack import _ContainerIndexes
@ -34,16 +32,16 @@ class MachineSettingsAction(MachineAction):
self._container_registry = ContainerRegistry.getInstance() self._container_registry = ContainerRegistry.getInstance()
self._container_registry.containerAdded.connect(self._onContainerAdded) self._container_registry.containerAdded.connect(self._onContainerAdded)
self._container_registry.containerRemoved.connect(self._onContainerRemoved) self._container_registry.containerRemoved.connect(self._onContainerRemoved)
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged) self._application.globalContainerStackChanged.connect(self._onGlobalContainerChanged)
self._empty_container = self._container_registry.getEmptyInstanceContainer() self._empty_container = self._container_registry.getEmptyInstanceContainer()
self._backend = Application.getInstance().getBackend() self._backend = self._application.getBackend()
def _onContainerAdded(self, container): 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 isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine": if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey()) self._application.getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
def _onContainerRemoved(self, container): def _onContainerRemoved(self, container):
# Remove definition_changes containers when a stack is removed # Remove definition_changes containers when a stack is removed
@ -61,11 +59,11 @@ class MachineSettingsAction(MachineAction):
# Make sure there is a definition_changes container to store the machine settings # Make sure there is a definition_changes container to store the machine settings
definition_changes_container = self._global_container_stack.definitionChanges definition_changes_container = self._global_container_stack.definitionChanges
if definition_changes_container == self._empty_container: if definition_changes_container == self._empty_container:
definition_changes_container = CuraStackBuilder.createDefinitionChangesContainer( CuraStackBuilder.createDefinitionChangesContainer(self._global_container_stack,
self._global_container_stack, self._global_container_stack.getName() + "_settings") self._global_container_stack.getName() + "_settings")
# Notify the UI in which container to store the machine settings data # Notify the UI in which container to store the machine settings data
from cura.Settings.CuraContainerStack import CuraContainerStack, _ContainerIndexes from cura.Settings.CuraContainerStack import _ContainerIndexes
container_index = _ContainerIndexes.DefinitionChanges container_index = _ContainerIndexes.DefinitionChanges
if container_index != self._container_index: if container_index != self._container_index:
@ -107,13 +105,13 @@ class MachineSettingsAction(MachineAction):
def setMachineExtruderCount(self, extruder_count): def setMachineExtruderCount(self, extruder_count):
# Note: this method was in this class before, but since it's quite generic and other plugins also need it # Note: this method was in this class before, but since it's quite generic and other plugins also need it
# it was moved to the machine manager instead. Now this method just calls the machine manager. # it was moved to the machine manager instead. Now this method just calls the machine manager.
Application.getInstance().getMachineManager().setActiveMachineExtruderCount(extruder_count) self._application.getMachineManager().setActiveMachineExtruderCount(extruder_count)
@pyqtSlot() @pyqtSlot()
def forceUpdate(self): def forceUpdate(self):
# Force rebuilding the build volume by reloading the global container stack. # Force rebuilding the build volume by reloading the global container stack.
# This is a bit of a hack, but it seems quick enough. # This is a bit of a hack, but it seems quick enough.
Application.getInstance().globalContainerStackChanged.emit() self._application.globalContainerStackChanged.emit()
@pyqtSlot() @pyqtSlot()
def updateHasMaterialsMetadata(self): def updateHasMaterialsMetadata(self):
@ -126,9 +124,11 @@ class MachineSettingsAction(MachineAction):
# In other words: only continue for the UM2 (extended), but not for the UM2+ # In other words: only continue for the UM2 (extended), but not for the UM2+
return return
stacks = ExtruderManager.getInstance().getExtruderStacks() machine_manager = self._application.getMachineManager()
extruder_positions = list(self._global_container_stack.extruders.keys())
has_materials = self._global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode" has_materials = self._global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
material_node = None
if has_materials: if has_materials:
if "has_materials" in self._global_container_stack.getMetaData(): if "has_materials" in self._global_container_stack.getMetaData():
self._global_container_stack.setMetaDataEntry("has_materials", True) self._global_container_stack.setMetaDataEntry("has_materials", True)
@ -136,26 +136,22 @@ class MachineSettingsAction(MachineAction):
self._global_container_stack.addMetaDataEntry("has_materials", True) self._global_container_stack.addMetaDataEntry("has_materials", True)
# Set the material container for each extruder to a sane default # Set the material container for each extruder to a sane default
for stack in stacks: material_manager = self._application.getMaterialManager()
material_container = stack.material material_node = material_manager.getDefaultMaterial(self._global_container_stack, None)
if material_container == self._empty_container:
machine_approximate_diameter = str(round(self._global_container_stack.getProperty("material_diameter", "value")))
search_criteria = { "type": "material", "definition": "fdmprinter", "id": self._global_container_stack.getMetaDataEntry("preferred_material"), "approximate_diameter": machine_approximate_diameter}
materials = self._container_registry.findInstanceContainers(**search_criteria)
if materials:
stack.material = materials[0]
else: else:
# The metadata entry is stored in an ini, and ini files are parsed as strings only. # The metadata entry is stored in an ini, and ini files are parsed as strings only.
# Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False. # Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
if "has_materials" in self._global_container_stack.getMetaData(): if "has_materials" in self._global_container_stack.getMetaData():
self._global_container_stack.removeMetaDataEntry("has_materials") self._global_container_stack.removeMetaDataEntry("has_materials")
for stack in stacks: # set materials
stack.material = ContainerRegistry.getInstance().getEmptyInstanceContainer() for position in extruder_positions:
machine_manager.setMaterial(position, material_node)
Application.getInstance().globalContainerStackChanged.emit() self._application.globalContainerStackChanged.emit()
@pyqtSlot(int) @pyqtSlot(int)
def updateMaterialForDiameter(self, extruder_position: int): def updateMaterialForDiameter(self, extruder_position: int):
# Updates the material container to a material that matches the material diameter set for the printer # Updates the material container to a material that matches the material diameter set for the printer
Application.getInstance().getExtruderManager().updateMaterialForDiameter(extruder_position) self._application.getExtruderManager().updateMaterialForDiameter(extruder_position)

View File

@ -103,6 +103,7 @@ material_print_temperature_layer_0
material_initial_print_temperature material_initial_print_temperature
material_final_print_temperature material_final_print_temperature
material_extrusion_cool_down_speed material_extrusion_cool_down_speed
default_material_bed_temperature
material_bed_temperature material_bed_temperature
material_bed_temperature_layer_0 material_bed_temperature_layer_0
material_diameter material_diameter

View File

@ -122,7 +122,7 @@ Column
{ {
label: catalog.i18nc("@label", "Printing Time") label: catalog.i18nc("@label", "Printing Time")
value: activePrintJob != null ? getPrettyTime(activePrintJob.timeTotal) : "" value: activePrintJob != null ? getPrettyTime(activePrintJob.timeTotal) : ""
width:base.width width: base.width
visible: activePrinter != null visible: activePrinter != null
} }

View File

@ -64,11 +64,11 @@ Rectangle
function getPrettyTime(time) function getPrettyTime(time)
{ {
var hours = Math.round(time / 3600) var hours = Math.floor(time / 3600)
time -= hours * 3600 time -= hours * 3600
var minutes = Math.round(time / 60); var minutes = Math.floor(time / 60);
time -= minutes * 60 time -= minutes * 60
var seconds = Math.round(time); var seconds = Math.floor(time);
var finalTime = strPadLeft(hours, "0", 2) + ':' + strPadLeft(minutes,'0',2)+ ':' + strPadLeft(seconds,'0',2); var finalTime = strPadLeft(hours, "0", 2) + ':' + strPadLeft(minutes,'0',2)+ ':' + strPadLeft(seconds,'0',2);
return finalTime; return finalTime;