Browse Source

Merge branch 'master' into CURA-6793_performance

Ghostkeeper 5 years ago
parent
commit
c12817170c

+ 5 - 0
cura/Machines/Models/IntentCategoryModel.py

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

+ 42 - 11
cura/Machines/Models/MaterialManagementModel.py

@@ -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)
-
-        # 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))
+        # 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)
+
+        # 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
 

+ 16 - 3
cura/Machines/Models/QualityManagementModel.py

@@ -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._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

+ 3 - 0
cura/Machines/Models/QualityProfilesDropDownMenuModel.py

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

+ 17 - 6
cura/Machines/VariantNode.py

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

+ 4 - 3
cura/PrinterOutput/Models/ExtruderConfigurationModel.py

@@ -25,9 +25,10 @@ class ExtruderConfigurationModel(QObject):
         return self._position
 
     def setMaterial(self, material: Optional[MaterialOutputModel]) -> None:
-        if self._material != material:
-            self._material = material
-            self.extruderConfigurationChanged.emit()
+        if material is None or self._material == material:
+            return
+        self._material = material
+        self.extruderConfigurationChanged.emit()
 
     @pyqtProperty(QObject, fset = setMaterial, notify = extruderConfigurationChanged)
     def activeMaterial(self) -> Optional[MaterialOutputModel]:

+ 4 - 0
cura/Settings/IntentManager.py

@@ -78,6 +78,8 @@ class IntentManager(QObject):
         final_intent_ids = set()  # type: Set[str]
         current_definition_id = global_stack.definition.getId()
         for extruder_stack in global_stack.extruderList:
+            if not extruder_stack.isEnabled:
+                continue
             nozzle_name = extruder_stack.variant.getMetaDataEntry("name")
             material_id = extruder_stack.material.getMetaDataEntry("base_file")
             final_intent_ids |= {metadata["id"] for metadata in self.intentMetadatas(current_definition_id, nozzle_name, material_id) if metadata.get("quality_type") in available_quality_types}
@@ -104,6 +106,8 @@ class IntentManager(QObject):
         current_definition_id = global_stack.definition.getId()
         final_intent_categories = set()  # type: Set[str]
         for extruder_stack in global_stack.extruderList:
+            if not extruder_stack.isEnabled:
+                continue
             nozzle_name = extruder_stack.variant.getMetaDataEntry("name")
             material_id = extruder_stack.material.getMetaDataEntry("base_file")
             final_intent_categories.update(self.intentCategories(current_definition_id, nozzle_name, material_id))

+ 5 - 5
cura/Settings/MachineManager.py

@@ -1322,7 +1322,8 @@ class MachineManager(QObject):
     #   changed.
     #   \param position The extruder stack to update. If provided with None, all
     #   extruder stacks will be updated.
-    def updateMaterialWithVariant(self, position: Optional[str]) -> None:
+    @pyqtSlot()
+    def updateMaterialWithVariant(self, position: Optional[str] = None) -> None:
         if self._global_container_stack is None:
             return
         if position is None:
@@ -1353,10 +1354,9 @@ class MachineManager(QObject):
                 self._setMaterial(position_item, new_material)
             else:
                 # The current material is not available, find the preferred one.
-                if position is not None:
-                    approximate_material_diameter = int(self._global_container_stack.extruderList[int(position_item)].getApproximateMaterialDiameter())
-                    material_node = nozzle_node.preferredMaterial(approximate_material_diameter)
-                    self._setMaterial(position_item, material_node)
+                approximate_material_diameter = int(self._global_container_stack.extruderList[int(position_item)].getApproximateMaterialDiameter())
+                material_node = nozzle_node.preferredMaterial(approximate_material_diameter)
+                self._setMaterial(position_item, material_node)
 
     ##  Given a printer definition name, select the right machine instance. In case it doesn't exist, create a new
     #   instance with the same network key.

+ 4 - 2
plugins/PostProcessingPlugin/scripts/PauseAtHeight.py

@@ -162,6 +162,8 @@ class PauseAtHeight(Script):
         # use offset to calculate the current height: <current_height> = <current_z> - <layer_0_z>
         layer_0_z = 0
         current_z = 0
+        current_height = 0
+        current_layer = 0
         current_extrusion_f = 0
         got_first_g_cmd_on_layer_0 = False
         current_t = 0 #Tracks the current extruder for tracking the target temperature.
@@ -263,8 +265,8 @@ class PauseAtHeight(Script):
                         # the nozzle)
                         x, y = self.getNextXY(layer)
                         prev_lines = prev_layer.split("\n")
-                        for line in prev_lines:
-                            new_e = self.getValue(line, 'E', current_e)
+                        for lin in prev_lines:
+                            new_e = self.getValue(lin, "E", current_e)
                             if new_e != current_e:
                                 current_e = new_e
                                 break

+ 1 - 1
plugins/Toolbox/resources/qml/ToolboxLicenseDialog.qml

@@ -30,7 +30,7 @@ UM.Dialog
             anchors.top: parent.top
             anchors.left: parent.left
             anchors.right: parent.right
-            text: licenseDialog.pluginName + catalog.i18nc("@label", "This plugin contains a license.\nYou need to accept this license to install this plugin.\nDo you agree with the terms below?")
+            text: licenseDialog.pluginName + ": " + catalog.i18nc("@label", "This plugin contains a license.\nYou need to accept this license to install this plugin.\nDo you agree with the terms below?")
             wrapMode: Text.Wrap
             renderType: Text.NativeRendering
         }

Some files were not shown because too many files changed in this diff