mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-10 15:25:09 -06:00
Merge branch 'master' into CURA-6793_performance
This commit is contained in:
commit
c12817170c
31 changed files with 537 additions and 94 deletions
|
@ -46,6 +46,8 @@ class IntentCategoryModel(ListModel):
|
|||
self.addRoleName(self.WeightRole, "weight")
|
||||
self.addRoleName(self.QualitiesRole, "qualities")
|
||||
|
||||
application = cura.CuraApplication.CuraApplication.getInstance()
|
||||
|
||||
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerChange)
|
||||
ContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChange)
|
||||
machine_manager = cura.CuraApplication.CuraApplication.getInstance().getMachineManager()
|
||||
|
@ -53,6 +55,9 @@ class IntentCategoryModel(ListModel):
|
|||
machine_manager.activeVariantChanged.connect(self.update)
|
||||
machine_manager.extruderChanged.connect(self.update)
|
||||
|
||||
extruder_manager = application.getExtruderManager()
|
||||
extruder_manager.extrudersChanged.connect(self.update)
|
||||
|
||||
self.update()
|
||||
|
||||
## Updates the list of intents if an intent profile was added or removed.
|
||||
|
|
|
@ -8,6 +8,7 @@ import uuid # To generate new GUIDs for new materials.
|
|||
|
||||
from UM.i18n import i18nCatalog
|
||||
from UM.Logger import Logger
|
||||
from UM.Signal import postponeSignals, CompressTechnique
|
||||
|
||||
import cura.CuraApplication # Imported like this to prevent circular imports.
|
||||
from cura.Machines.ContainerTree import ContainerTree
|
||||
|
@ -73,8 +74,20 @@ class MaterialManagementModel(QObject):
|
|||
def removeMaterial(self, material_node: "MaterialNode") -> None:
|
||||
container_registry = CuraContainerRegistry.getInstance()
|
||||
materials_this_base_file = container_registry.findContainersMetadata(base_file = material_node.base_file)
|
||||
for material_metadata in materials_this_base_file:
|
||||
container_registry.removeContainer(material_metadata["id"])
|
||||
|
||||
# The material containers belonging to the same material file are supposed to work together. This postponeSignals()
|
||||
# does two things:
|
||||
# - optimizing the signal emitting.
|
||||
# - making sure that the signals will only be emitted after all the material containers have been removed.
|
||||
with postponeSignals(container_registry.containerRemoved, compress = CompressTechnique.CompressPerParameterValue):
|
||||
# CURA-6886: Some containers may not have been loaded. If remove one material container, its material file
|
||||
# will be removed. If later we remove a sub-material container which hasn't been loaded previously, it will
|
||||
# crash because removeContainer() requires to load the container first, but the material file was already
|
||||
# gone.
|
||||
for material_metadata in materials_this_base_file:
|
||||
container_registry.findInstanceContainers(id = material_metadata["id"])
|
||||
for material_metadata in materials_this_base_file:
|
||||
container_registry.removeContainer(material_metadata["id"])
|
||||
|
||||
## Creates a duplicate of a material with the same GUID and base_file
|
||||
# metadata.
|
||||
|
@ -128,15 +141,33 @@ class MaterialManagementModel(QObject):
|
|||
new_container.getMetaData().update(new_metadata)
|
||||
new_containers.append(new_container)
|
||||
|
||||
for container_to_add in new_containers:
|
||||
container_to_add.setDirty(True)
|
||||
container_registry.addContainer(container_to_add)
|
||||
# CURA-6863: Nodes in ContainerTree will be updated upon ContainerAdded signals, one at a time. It will use the
|
||||
# best fit material container at the time it sees one. For example, if you duplicate and get generic_pva #2,
|
||||
# if the node update function sees the containers in the following order:
|
||||
#
|
||||
# - generic_pva #2
|
||||
# - generic_pva #2_um3_aa04
|
||||
#
|
||||
# It will first use "generic_pva #2" because that's the best fit it has ever seen, and later "generic_pva #2_um3_aa04"
|
||||
# once it sees that. Because things run in the Qt event loop, they don't happen at the same time. This means if
|
||||
# between those two events, the ContainerTree will have nodes that contain invalid data.
|
||||
#
|
||||
# This sort fixes the problem by emitting the most specific containers first.
|
||||
new_containers = sorted(new_containers, key = lambda x: x.getId(), reverse = True)
|
||||
|
||||
# If the duplicated material was favorite then the new material should also be added to the favorites.
|
||||
favorites_set = set(application.getPreferences().getValue("cura/favorite_materials").split(";"))
|
||||
if base_file in favorites_set:
|
||||
favorites_set.add(new_base_id)
|
||||
application.getPreferences().setValue("cura/favorite_materials", ";".join(favorites_set))
|
||||
# Optimization. Serving the same purpose as the postponeSignals() in removeMaterial()
|
||||
# postpone the signals emitted when duplicating materials. This is easier on the event loop; changes the
|
||||
# behavior to be like a transaction. Prevents concurrency issues.
|
||||
with postponeSignals(container_registry.containerAdded, compress=CompressTechnique.CompressPerParameterValue):
|
||||
for container_to_add in new_containers:
|
||||
container_to_add.setDirty(True)
|
||||
container_registry.addContainer(container_to_add)
|
||||
|
||||
# If the duplicated material was favorite then the new material should also be added to the favorites.
|
||||
favorites_set = set(application.getPreferences().getValue("cura/favorite_materials").split(";"))
|
||||
if base_file in favorites_set:
|
||||
favorites_set.add(new_base_id)
|
||||
application.getPreferences().setValue("cura/favorite_materials", ";".join(favorites_set))
|
||||
|
||||
return new_base_id
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from typing import Any, cast, Dict, Optional, TYPE_CHECKING
|
||||
from PyQt5.QtCore import pyqtSlot, QObject, Qt
|
||||
from PyQt5.QtCore import pyqtSlot, QObject, Qt, QTimer
|
||||
|
||||
from UM.Logger import Logger
|
||||
from UM.Qt.ListModel import ListModel
|
||||
|
@ -51,14 +51,27 @@ class QualityManagementModel(ListModel):
|
|||
application = cura.CuraApplication.CuraApplication.getInstance()
|
||||
container_registry = application.getContainerRegistry()
|
||||
self._machine_manager = application.getMachineManager()
|
||||
self._extruder_manager = application.getExtruderManager()
|
||||
self._machine_manager.activeQualityGroupChanged.connect(self._onChange)
|
||||
self._machine_manager.activeStackChanged.connect(self._onChange)
|
||||
self._machine_manager.extruderChanged.connect(self._onChange)
|
||||
self._machine_manager.globalContainerChanged.connect(self._onChange)
|
||||
|
||||
self._extruder_manager = application.getExtruderManager()
|
||||
self._extruder_manager.extrudersChanged.connect(self._onChange)
|
||||
|
||||
self._machine_manager.globalContainerChanged.connect(self._update)
|
||||
container_registry.containerAdded.connect(self._qualityChangesListChanged)
|
||||
container_registry.containerRemoved.connect(self._qualityChangesListChanged)
|
||||
container_registry.containerMetaDataChanged.connect(self._qualityChangesListChanged)
|
||||
|
||||
self._update()
|
||||
self._update_timer = QTimer()
|
||||
self._update_timer.setInterval(100)
|
||||
self._update_timer.setSingleShot(True)
|
||||
self._update_timer.timeout.connect(self._update)
|
||||
|
||||
self._onChange()
|
||||
|
||||
def _onChange(self) -> None:
|
||||
self._update_timer.start()
|
||||
|
||||
## Deletes a custom profile. It will be gone forever.
|
||||
# \param quality_changes_group The quality changes group representing the
|
||||
|
|
|
@ -44,6 +44,9 @@ class QualityProfilesDropDownMenuModel(ListModel):
|
|||
machine_manager.activeVariantChanged.connect(self._onChange)
|
||||
machine_manager.extruderChanged.connect(self._onChange)
|
||||
|
||||
extruder_manager = application.getExtruderManager()
|
||||
extruder_manager.extrudersChanged.connect(self._onChange)
|
||||
|
||||
self._layer_height_unit = "" # This is cached
|
||||
|
||||
self._update_timer = QTimer() # type: QTimer
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from UM.Logger import Logger
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
from UM.Signal import Signal
|
||||
|
||||
from cura.Settings.cura_empty_instance_containers import empty_variant_container
|
||||
from cura.Machines.ContainerNode import ContainerNode
|
||||
from cura.Machines.MaterialNode import MaterialNode
|
||||
|
||||
import UM.FlameProfiler
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Dict
|
||||
from cura.Machines.MachineNode import MachineNode
|
||||
|
@ -101,6 +104,14 @@ class VariantNode(ContainerNode):
|
|||
def _materialAdded(self, container: ContainerInterface) -> None:
|
||||
if container.getMetaDataEntry("type") != "material":
|
||||
return # Not interested.
|
||||
if not ContainerRegistry.getInstance().findContainersMetadata(id = container.getId()):
|
||||
# CURA-6889
|
||||
# containerAdded and removed signals may be triggered in the next event cycle. If a container gets added
|
||||
# and removed in the same event cycle, in the next cycle, the connections should just ignore the signals.
|
||||
# The check here makes sure that the container in the signal still exists.
|
||||
Logger.log("d", "Got container added signal for container [%s] but it no longer exists, do nothing.",
|
||||
container.getId())
|
||||
return
|
||||
if not self.machine.has_materials:
|
||||
return # We won't add any materials.
|
||||
material_definition = container.getMetaDataEntry("definition")
|
||||
|
@ -111,18 +122,18 @@ class VariantNode(ContainerNode):
|
|||
if base_file not in self.materials: # Completely new base file. Always better than not having a file as long as it matches our set-up.
|
||||
if material_definition != "fdmprinter" and material_definition != self.machine.container_id:
|
||||
return
|
||||
material_variant = container.getMetaDataEntry("variant_name", "empty")
|
||||
if material_variant != "empty" and material_variant != self.variant_name:
|
||||
material_variant = container.getMetaDataEntry("variant_name", empty_variant_container.getName())
|
||||
if material_variant != self.variant_name:
|
||||
return
|
||||
else: # We already have this base profile. Replace the base profile if the new one is more specific.
|
||||
new_definition = container.getMetaDataEntry("definition")
|
||||
if new_definition == "fdmprinter":
|
||||
return # Just as unspecific or worse.
|
||||
if new_definition != self.machine.container_id:
|
||||
material_variant = container.getMetaDataEntry("variant_name")
|
||||
if new_definition != self.machine.container_id or material_variant != self.variant_name:
|
||||
return # Doesn't match this set-up.
|
||||
original_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = self.materials[base_file].container_id)[0]
|
||||
original_variant = original_metadata.get("variant_name", "empty")
|
||||
if original_variant != "empty" or container.getMetaDataEntry("variant_name", "empty") == "empty":
|
||||
if "variant_name" in original_metadata or material_variant is None:
|
||||
return # Original was already specific or just as unspecific as the new one.
|
||||
|
||||
if "empty_material" in self.materials:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue