Browse Source

Merge remote-tracking branch 'origin/3.5'

Lipu Fei 6 years ago
parent
commit
3b62284276

+ 79 - 48
cura/Settings/CuraStackBuilder.py

@@ -15,6 +15,7 @@ from .ExtruderStack import ExtruderStack
 
 ##  Contains helper functions to create new machines.
 class CuraStackBuilder:
+
     ##  Create a new instance of a machine.
     #
     #   \param name The name of the new machine.
@@ -26,7 +27,6 @@ class CuraStackBuilder:
         from cura.CuraApplication import CuraApplication
         application = CuraApplication.getInstance()
         variant_manager = application.getVariantManager()
-        material_manager = application.getMaterialManager()
         quality_manager = application.getQualityManager()
         registry = application.getContainerRegistry()
 
@@ -46,16 +46,6 @@ class CuraStackBuilder:
         if not global_variant_container:
             global_variant_container = application.empty_variant_container
 
-        # get variant container for extruders
-        extruder_variant_container = application.empty_variant_container
-        extruder_variant_node = variant_manager.getDefaultVariantNode(machine_definition, VariantType.NOZZLE)
-        extruder_variant_name = None
-        if extruder_variant_node:
-            extruder_variant_container = extruder_variant_node.getContainer()
-            if not extruder_variant_container:
-                extruder_variant_container = application.empty_variant_container
-            extruder_variant_name = extruder_variant_container.getName()
-
         generated_name = registry.createUniqueName("machine", "", name, machine_definition.getName())
         # Make sure the new name does not collide with any definition or (quality) profile
         # createUniqueName() only looks at other stacks, but not at definitions or quality profiles
@@ -74,34 +64,8 @@ class CuraStackBuilder:
 
         # Create ExtruderStacks
         extruder_dict = machine_definition.getMetaDataEntry("machine_extruder_trains")
-
-        for position, extruder_definition_id in extruder_dict.items():
-            # Sanity check: make sure that the positions in the extruder definitions are same as in the machine
-            # definition
-            extruder_definition = registry.findDefinitionContainers(id = extruder_definition_id)[0]
-            position_in_extruder_def = extruder_definition.getMetaDataEntry("position")
-            if position_in_extruder_def != position:
-                ConfigurationErrorMessage.getInstance().addFaultyContainers(extruder_definition_id)
-                return None #Don't return any container stack then, not the rest of the extruders either.
-
-            # get material container for extruders
-            material_container = application.empty_material_container
-            material_node = material_manager.getDefaultMaterial(new_global_stack, position, extruder_variant_name, extruder_definition = extruder_definition)
-            if material_node and material_node.getContainer():
-                material_container = material_node.getContainer()
-
-            new_extruder_id = registry.uniqueName(extruder_definition_id)
-            new_extruder = cls.createExtruderStack(
-                new_extruder_id,
-                extruder_definition = extruder_definition,
-                machine_definition_id = definition_id,
-                position = position,
-                variant_container = extruder_variant_container,
-                material_container = material_container,
-                quality_container = application.empty_quality_container
-            )
-            new_extruder.setNextStack(new_global_stack)
-            new_global_stack.addExtruder(new_extruder)
+        for position in extruder_dict:
+            cls.createExtruderStackWithDefaultSetup(new_global_stack, position)
 
         for new_extruder in new_global_stack.extruders.values(): #Only register the extruders if we're sure that all of them are correct.
             registry.addContainer(new_extruder)
@@ -136,19 +100,73 @@ class CuraStackBuilder:
 
         return new_global_stack
 
+    ##  Create a default Extruder Stack
+    #
+    #   \param global_stack The global stack this extruder refers to.
+    #   \param extruder_position The position of the current extruder.
+    @classmethod
+    def createExtruderStackWithDefaultSetup(cls, global_stack: "GlobalStack", extruder_position: int) -> None:
+        from cura.CuraApplication import CuraApplication
+        application = CuraApplication.getInstance()
+        variant_manager = application.getVariantManager()
+        material_manager = application.getMaterialManager()
+        registry = application.getContainerRegistry()
+
+        # get variant container for extruders
+        extruder_variant_container = application.empty_variant_container
+        extruder_variant_node = variant_manager.getDefaultVariantNode(global_stack.definition, VariantType.NOZZLE)
+        extruder_variant_name = None
+        if extruder_variant_node:
+            extruder_variant_container = extruder_variant_node.getContainer()
+            if not extruder_variant_container:
+                extruder_variant_container = application.empty_variant_container
+            extruder_variant_name = extruder_variant_container.getName()
+
+        extruder_definition_dict = global_stack.getMetaDataEntry("machine_extruder_trains")
+        extruder_definition_id = extruder_definition_dict[str(extruder_position)]
+        extruder_definition = registry.findDefinitionContainers(id = extruder_definition_id)[0]
+
+        # get material container for extruders
+        material_container = application.empty_material_container
+        material_node = material_manager.getDefaultMaterial(global_stack, extruder_position, extruder_variant_name,
+                                                            extruder_definition = extruder_definition)
+        if material_node and material_node.getContainer():
+            material_container = material_node.getContainer()
+
+        new_extruder_id = registry.uniqueName(extruder_definition_id)
+        new_extruder = cls.createExtruderStack(
+            new_extruder_id,
+            extruder_definition = extruder_definition,
+            machine_definition_id = global_stack.definition.getId(),
+            position = extruder_position,
+            variant_container = extruder_variant_container,
+            material_container = material_container,
+            quality_container = application.empty_quality_container
+        )
+        new_extruder.setNextStack(global_stack)
+        global_stack.addExtruder(new_extruder)
+
+        registry.addContainer(new_extruder)
+
     ##  Create a new Extruder stack
     #
     #   \param new_stack_id The ID of the new stack.
-    #   \param definition The definition to base the new stack on.
-    #   \param machine_definition_id The ID of the machine definition to use for
-    #   the user container.
-    #   \param kwargs You can add keyword arguments to specify IDs of containers to use for a specific type, for example "variant": "0.4mm"
+    #   \param extruder_definition The definition to base the new stack on.
+    #   \param machine_definition_id The ID of the machine definition to use for the user container.
+    #   \param position The position the extruder occupies in the machine.
+    #   \param variant_container The variant selected for the current extruder.
+    #   \param material_container The material selected for the current extruder.
+    #   \param quality_container The quality selected for the current extruder.
     #
-    #   \return A new Global stack instance with the specified parameters.
+    #   \return A new Extruder stack instance with the specified parameters.
     @classmethod
-    def createExtruderStack(cls, new_stack_id: str, extruder_definition: DefinitionContainerInterface, machine_definition_id: str,
+    def createExtruderStack(cls, new_stack_id: str, extruder_definition: DefinitionContainerInterface,
+                            machine_definition_id: str,
                             position: int,
-                            variant_container, material_container, quality_container) -> ExtruderStack:
+                            variant_container: "InstanceContainer",
+                            material_container: "InstanceContainer",
+                            quality_container: "InstanceContainer") -> ExtruderStack:
+
         from cura.CuraApplication import CuraApplication
         application = CuraApplication.getInstance()
         registry = application.getContainerRegistry()
@@ -157,7 +175,7 @@ class CuraStackBuilder:
         stack.setName(extruder_definition.getName())
         stack.setDefinition(extruder_definition)
 
-        stack.setMetaDataEntry("position", position)
+        stack.setMetaDataEntry("position", str(position))
 
         user_container = cls.createUserChangesContainer(new_stack_id + "_user", machine_definition_id, new_stack_id,
                                                         is_global_stack = False)
@@ -183,9 +201,22 @@ class CuraStackBuilder:
     #   \param kwargs You can add keyword arguments to specify IDs of containers to use for a specific type, for example "variant": "0.4mm"
     #
     #   \return A new Global stack instance with the specified parameters.
+
+    ##  Create a new Global stack
+    #
+    #   \param new_stack_id The ID of the new stack.
+    #   \param definition The definition to base the new stack on.
+    #   \param variant_container The variant selected for the current stack.
+    #   \param material_container The material selected for the current stack.
+    #   \param quality_container The quality selected for the current stack.
+    #
+    #   \return A new Global stack instance with the specified parameters.
     @classmethod
     def createGlobalStack(cls, new_stack_id: str, definition: DefinitionContainerInterface,
-                          variant_container, material_container, quality_container) -> GlobalStack:
+                          variant_container: "InstanceContainer",
+                          material_container: "InstanceContainer",
+                          quality_container: "InstanceContainer") -> GlobalStack:
+
         from cura.CuraApplication import CuraApplication
         application = CuraApplication.getInstance()
         registry = application.getContainerRegistry()

+ 9 - 2
cura/Settings/ExtruderManager.py

@@ -361,8 +361,15 @@ class ExtruderManager(QObject):
     # "fdmextruder". We need to check a machine here so its extruder definition is correct according to this.
     def _fixSingleExtrusionMachineExtruderDefinition(self, global_stack: "GlobalStack") -> None:
         expected_extruder_definition_0_id = global_stack.getMetaDataEntry("machine_extruder_trains")["0"]
-        extruder_stack_0 = global_stack.extruders["0"]
-        if extruder_stack_0.definition.getId() != expected_extruder_definition_0_id:
+        extruder_stack_0 = global_stack.extruders.get("0")
+
+        if extruder_stack_0 is None:
+            Logger.log("i", "No extruder stack for global stack [%s], create one", global_stack.getId())
+            # Single extrusion machine without an ExtruderStack, create it
+            from cura.Settings.CuraStackBuilder import CuraStackBuilder
+            CuraStackBuilder.createExtruderStackWithDefaultSetup(global_stack, 0)
+
+        elif extruder_stack_0.definition.getId() != expected_extruder_definition_0_id:
             Logger.log("e", "Single extruder printer [{printer}] expected extruder [{expected}], but got [{got}]. I'm making it [{expected}].".format(
                 printer = global_stack.getId(), expected = expected_extruder_definition_0_id, got = extruder_stack_0.definition.getId()))
             container_registry = ContainerRegistry.getInstance()

+ 2 - 1
cura/Settings/MachineManager.py

@@ -367,6 +367,7 @@ class MachineManager(QObject):
             return
 
         global_stack = containers[0]
+        ExtruderManager.getInstance()._fixSingleExtrusionMachineExtruderDefinition(global_stack)
         if not global_stack.isValid():
             # Mark global stack as invalid
             ConfigurationErrorMessage.getInstance().addFaultyContainers(global_stack.getId())
@@ -375,7 +376,7 @@ class MachineManager(QObject):
         self._global_container_stack = global_stack
         self._application.setGlobalContainerStack(global_stack)
         ExtruderManager.getInstance()._globalContainerStackChanged()
-        self._initMachineState(containers[0])
+        self._initMachineState(global_stack)
         self._onGlobalContainerChanged()
 
         self.__emitChangedSignals()

+ 7 - 3
plugins/ChangeLogPlugin/ChangeLog.txt

@@ -35,6 +35,9 @@ Improved and updated Chinese translations. Contributed by MarmaladeForMeat.
 *Save project
 Saving the project no longer triggers the project to reslice.
 
+*File menu
+The Save option in the file menu now saves project files. The export option now saves other types of files, such as STL.
+
 *Improved processing of overhang walls
 Overhang walls are detected and printed with different speeds. It will not start a perimeter on an overhanging wall. The quality of overhanging walls may be improved by printing those at a different speed. Contributed by smartavionics.
 
@@ -47,7 +50,8 @@ The support infill lines can now be rotated to increase the supporting capabilit
 *Minimum polygon circumference
 Polygons in sliced layers that have a circumference smaller than the setting value will be filtered out. Lower values lead to higher resolution meshes at the cost of increased slicing time. This setting is ideal for very tiny prints with a lot of detail, or for SLA printers. Contributed by cubiq.
 
-*Initial layer support line distance. This setting enables the user to reduce or increase the density of the support initial layer in order to increase or reduce adhesion to the build plate and the overall strength.
+*Initial layer support line distance
+This setting enables the user to reduce or increase the density of the support initial layer in order to increase or reduce adhesion to the build plate and the overall strength.
 
 *Extra infill wall line count
 Adds extra walls around infill. Contributed by BagelOrb.
@@ -64,8 +68,8 @@ New setting to modify the fan speed of bridged areas. This setting can be found
 *Minimum wall flow
 New setting to define a minimum flow for thin printed walls. Contributed by smartavionics.
 
-*Custom support
-A tool similar to the support blocker that adds cubes of support to the model manually by clicking parts of it. Contributed by Lokster.
+*Custom support plugin
+A tool downloadable from the toolbox, similar to the support blocker, that adds cubes of support to the model manually by clicking parts of it. Contributed by Lokster.
 
 *Quickly toggle autoslicing
 Adds a pause/play button to the progress bar to quickly toggle autoslicing. Contributed by fieldOfview.

+ 2 - 2
plugins/Toolbox/src/Toolbox.py

@@ -306,8 +306,8 @@ class Toolbox(QObject, Extension):
         all_packages = self._package_manager.getAllInstalledPackagesInfo()
         if "plugin" in all_packages:
             # For old plugins, we only want to include the old custom plugin that were installed via the old toolbox.
-            # The bundled plugins will be included in the "bundled_packages.json", so the bundled plugins should be
-            # excluded from the old plugins list/dict.
+            # The bundled plugins will be included in JSON files in the "bundled_packages" folder, so the bundled
+            # plugins should be excluded from the old plugins list/dict.
             all_plugin_package_ids = set(package["package_id"] for package in all_packages["plugin"])
             self._old_plugin_ids = set(plugin_id for plugin_id in self._old_plugin_ids
                                     if plugin_id not in all_plugin_package_ids)

+ 1 - 0
plugins/USBPrinting/AutoDetectBaudJob.py

@@ -77,6 +77,7 @@ class AutoDetectBaudJob(Job):
                             self.setResult(baud_rate)
                             Logger.log("d", "Detected baud rate {baud_rate} on serial {serial} on retry {retry} with after {time_elapsed:0.2f} seconds.".format(
                                 serial = self._serial_port, baud_rate = baud_rate, retry = retry, time_elapsed = time() - start_timeout_time))
+                            serial.close() # close serial port so it can be opened by the USBPrinterOutputDevice
                             return
 
                     serial.write(b"M105\n")

+ 0 - 0
resources/bundled_packages.json → resources/bundled_packages/cura.json