Browse Source

Merge branch 'fieldOfView-fix_create_material'

Ghostkeeper 7 years ago
parent
commit
bf432dee34
1 changed files with 15 additions and 4 deletions
  1. 15 4
      cura/Settings/ContainerManager.py

+ 15 - 4
cura/Settings/ContainerManager.py

@@ -700,7 +700,7 @@ class ContainerManager(QObject):
         self._container_registry.addContainer(duplicated_container)
         return self._getMaterialContainerIdForActiveMachine(new_id)
 
-    ##  Create a new material by cloning Generic PLA and setting the GUID to something unqiue
+    ##  Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
     #
     #   \return \type{str} the id of the newly created container.
     @pyqtSlot(result = str)
@@ -708,14 +708,25 @@ class ContainerManager(QObject):
         # Ensure all settings are saved.
         Application.getInstance().saveSettings()
 
-        containers = self._container_registry.findInstanceContainers(id="generic_pla")
+        global_stack = Application.getInstance().getGlobalContainerStack()
+        if not global_stack:
+            return ""
+
+        approximate_diameter = round(global_stack.getProperty("material_diameter", "value"))
+        containers = self._container_registry.findInstanceContainers(id = "generic_pla*", approximate_diameter = approximate_diameter)
         if not containers:
-            Logger.log("d", "Unable to create a new material by cloning generic_pla, because it doesn't exist.")
+            Logger.log("d", "Unable to create a new material by cloning Generic PLA, because it cannot be found for the material diameter for this machine.")
+            return ""
+
+        base_file = containers[0].getMetaDataEntry("base_file")
+        containers = self._container_registry.findInstanceContainers(id = base_file)
+        if not containers:
+            Logger.log("d", "Unable to create a new material by cloning Generic PLA, because the base file for Generic PLA for this machine can not be found.")
             return ""
 
         # Create a new ID & container to hold the data.
         new_id = self._container_registry.uniqueName("custom_material")
-        container_type = type(containers[0])  # Could be either a XMLMaterialProfile or a InstanceContainer
+        container_type = type(containers[0])  # Always XMLMaterialProfile, since we specifically clone the base_file
         duplicated_container = container_type(new_id)
 
         # Instead of duplicating we load the data from the basefile again.