Browse Source

Merge branch 'feature_local_container_server' of github.com:Ultimaker/Cura into feature_local_container_server

Jack Ha 7 years ago
parent
commit
20500b5c51
3 changed files with 39 additions and 3 deletions
  1. 1 1
      cura/CuraApplication.py
  2. 2 1
      cura/Settings/ContainerManager.py
  3. 36 1
      cura/Settings/UserProfilesModel.py

+ 1 - 1
cura/CuraApplication.py

@@ -725,7 +725,7 @@ class CuraApplication(QtApplication):
 
             self.exec_()
 
-    def getMachineManager(self, *args):
+    def getMachineManager(self, *args) -> MachineManager:
         if self._machine_manager is None:
             self._machine_manager = MachineManager.createMachineManager()
         return self._machine_manager

+ 2 - 1
cura/Settings/ContainerManager.py

@@ -789,7 +789,8 @@ class ContainerManager(QObject):
             if container_to_copy.getMetaDataEntry("definition") != "fdmprinter":
                 new_id += "_" + container_to_copy.getMetaDataEntry("definition")
                 if container_to_copy.getMetaDataEntry("variant"):
-                    new_id += "_" + container_to_copy.getMetaDataEntry("variant")
+                    variant = self._container_registry.findContainers(id = container_to_copy.getMetaDataEntry("variant"))[0]
+                    new_id += "_" + variant.getName().replace(" ", "_")
             if current_id == material_id:
                 clone_of_original = new_id
 

+ 36 - 1
cura/Settings/UserProfilesModel.py

@@ -1,7 +1,7 @@
 # Copyright (c) 2017 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
-from UM.Application import Application
 
+from UM.Application import Application
 from cura.QualityManager import QualityManager
 from cura.Settings.ProfilesModel import ProfilesModel
 from cura.Settings.ExtruderManager import ExtruderManager
@@ -12,6 +12,16 @@ class UserProfilesModel(ProfilesModel):
     def __init__(self, parent = None):
         super().__init__(parent)
 
+        #Need to connect to the metaDataChanged signal of the active materials.
+        self.__current_extruders = []
+        self.__current_materials = []
+
+        Application.getInstance().getExtruderManager().extrudersChanged.connect(self.__onExtrudersChanged)
+        self.__onExtrudersChanged()
+        self.__current_materials = [extruder.material for extruder in self.__current_extruders]
+        for material in self.__current_materials:
+            material.metaDataChanged.connect(self._onContainerChanged)
+
     ##  Fetch the list of containers to display.
     #
     #   See UM.Settings.Models.InstanceContainersModel._fetchInstanceContainers().
@@ -43,3 +53,28 @@ class UserProfilesModel(ProfilesModel):
                                      qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())}
 
         return filtered_quality_changes, {}
+
+    ##  Called when a container changed on an extruder stack.
+    #
+    #   If it's the material we need to connect to the metaDataChanged signal of
+    #   that.
+    def __onContainerChanged(self, new_container):
+        #Careful not to update when a quality or quality changes profile changed!
+        #If you then update you're going to have an infinite recursion because the update may change the container.
+        if new_container.getMetaDataEntry("type") == "material":
+            for material in self.__current_materials:
+                material.metaDataChanged.disconnect(self._onContainerChanged)
+            self.__current_materials = [extruder.material for extruder in self.__current_extruders]
+            for material in self.__current_materials:
+                material.metaDataChanged.connect(self._onContainerChanged)
+
+    ##  Called when the current set of extruders change.
+    #
+    #   This makes sure that we are listening to the signal for when the
+    #   materials change.
+    def __onExtrudersChanged(self):
+        for extruder in self.__current_extruders:
+            extruder.containersChanged.disconnect(self.__onContainerChanged)
+        self.__current_extruders = Application.getInstance().getExtruderManager().getExtruderStacks()
+        for extruder in self.__current_extruders:
+            extruder.containersChanged.connect(self.__onContainerChanged)