Browse Source

Merge branch 'master' into feature_sync_button

Diego Prado Gesto 7 years ago
parent
commit
2bf6d071d1

+ 26 - 31
cura/BuildVolume.py

@@ -111,6 +111,9 @@ class BuildVolume(SceneNode):
         # but it does not update the disallowed areas after material change
         Application.getInstance().getMachineManager().activeStackChanged.connect(self._onStackChanged)
 
+        # Enable and disable extruder
+        Application.getInstance().getMachineManager().extruderChanged.connect(self.updateNodeBoundaryCheck)
+
         # list of settings which were updated
         self._changed_settings_since_last_rebuild = []
 
@@ -217,30 +220,26 @@ class BuildVolume(SceneNode):
                 group_nodes.append(node)  # Keep list of affected group_nodes
 
             if node.callDecoration("isSliceable") or node.callDecoration("isGroup"):
-                node._outside_buildarea = False
-                bbox = node.getBoundingBox()
+                if node.collidesWithBbox(build_volume_bounding_box):
+                    node.setOutsideBuildArea(True)
+                    continue
+
+                if node.collidesWithArea(self.getDisallowedAreas()):
+                    node.setOutsideBuildArea(True)
+                    continue
 
-                # Mark the node as outside the build volume if the bounding box test fails.
-                if build_volume_bounding_box.intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection:
-                    node._outside_buildarea = True
+                # Mark the node as outside build volume if the set extruder is disabled
+                extruder_position = node.callDecoration("getActiveExtruderPosition")
+                if not self._global_container_stack.extruders[extruder_position].isEnabled:
+                    node.setOutsideBuildArea(True)
                     continue
 
-                convex_hull = node.callDecoration("getConvexHull")
-                if convex_hull:
-                    if not convex_hull.isValid():
-                        return
-                    # Check for collisions between disallowed areas and the object
-                    for area in self.getDisallowedAreas():
-                        overlap = convex_hull.intersectsPolygon(area)
-                        if overlap is None:
-                            continue
-                        node._outside_buildarea = True
-                        continue
+                node.setOutsideBuildArea(False)
 
         # Group nodes should override the _outside_buildarea property of their children.
         for group_node in group_nodes:
             for child_node in group_node.getAllChildren():
-                child_node._outside_buildarea = group_node._outside_buildarea
+                child_node.setOutsideBuildArea(group_node.isOutsideBuildArea)
 
     ##  Update the outsideBuildArea of a single node, given bounds or current build volume
     def checkBoundsAndUpdate(self, node: CuraSceneNode, bounds: Optional[AxisAlignedBox] = None):
@@ -260,24 +259,20 @@ class BuildVolume(SceneNode):
             build_volume_bounding_box = bounds
 
         if node.callDecoration("isSliceable") or node.callDecoration("isGroup"):
-            bbox = node.getBoundingBox()
+            if node.collidesWithBbox(build_volume_bounding_box):
+                node.setOutsideBuildArea(True)
+                return
 
-            # Mark the node as outside the build volume if the bounding box test fails.
-            if build_volume_bounding_box.intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection:
+            if node.collidesWithArea(self.getDisallowedAreas()):
+                node.setOutsideBuildArea(True)
+                return
+
+            # Mark the node as outside build volume if the set extruder is disabled
+            extruder_position = node.callDecoration("getActiveExtruderPosition")
+            if not self._global_container_stack.extruders[extruder_position].isEnabled:
                 node.setOutsideBuildArea(True)
                 return
 
-            convex_hull = self.callDecoration("getConvexHull")
-            if convex_hull:
-                if not convex_hull.isValid():
-                    return
-                # Check for collisions between disallowed areas and the object
-                for area in self.getDisallowedAreas():
-                    overlap = convex_hull.intersectsPolygon(area)
-                    if overlap is None:
-                        continue
-                    node.setOutsideBuildArea(True)
-                    return
             node.setOutsideBuildArea(False)
 
     ##  Recalculates the build volume & disallowed areas.

+ 4 - 0
cura/CuraApplication.py

@@ -1605,6 +1605,8 @@ class CuraApplication(QtApplication):
                 fixed_nodes.append(node_)
         arranger = Arrange.create(fixed_nodes = fixed_nodes)
         min_offset = 8
+        default_extruder_position = self.getMachineManager().defaultExtruderPosition
+        default_extruder_id = self._global_container_stack.extruders[default_extruder_position].getId()
 
         for original_node in nodes:
 
@@ -1670,6 +1672,8 @@ class CuraApplication(QtApplication):
 
             op = AddSceneNodeOperation(node, scene.getRoot())
             op.push()
+
+            node.callDecoration("setActiveExtruder", default_extruder_id)
             scene.sceneChanged.emit(node)
 
         self.fileCompleted.emit(filename)

+ 6 - 5
cura/Machines/MaterialGroup.py

@@ -1,9 +1,10 @@
 # Copyright (c) 2018 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
+from typing import List
+from cura.Machines.MaterialNode import MaterialNode #For type checking.
 
-#
-# A MaterialGroup represents a group of material InstanceContainers that are derived from a single material profile.
+## A MaterialGroup represents a group of material InstanceContainers that are derived from a single material profile.
 # The main InstanceContainer which has the ID of the material profile file name is called the "root_material". For
 # example: "generic_abs" is the root material (ID) of "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4",
 # and "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4" are derived materials of "generic_abs".
@@ -17,11 +18,11 @@
 class MaterialGroup:
     __slots__ = ("name", "is_read_only", "root_material_node", "derived_material_node_list")
 
-    def __init__(self, name: str):
+    def __init__(self, name: str, root_material_node: MaterialNode):
         self.name = name
         self.is_read_only = False
-        self.root_material_node = None
-        self.derived_material_node_list = []
+        self.root_material_node = root_material_node
+        self.derived_material_node_list = [] #type: List[MaterialNode]
 
     def __str__(self) -> str:
         return "%s[%s]" % (self.__class__.__name__, self.name)

+ 7 - 9
cura/Machines/MaterialManager.py

@@ -72,30 +72,28 @@ class MaterialManager(QObject):
 
     def initialize(self):
         # Find all materials and put them in a matrix for quick search.
-        material_metadata_list = self._container_registry.findContainersMetadata(type = "material")
+        material_metadatas = {metadata["id"]: metadata for metadata in self._container_registry.findContainersMetadata(type = "material")}
 
         self._material_group_map = dict()
 
         # Map #1
         #    root_material_id -> MaterialGroup
-        for material_metadata in material_metadata_list:
-            material_id = material_metadata["id"]
+        for material_id, material_metadata in material_metadatas.items():
             # We don't store empty material in the lookup tables
             if material_id == "empty_material":
                 continue
 
             root_material_id = material_metadata.get("base_file")
             if root_material_id not in self._material_group_map:
-                self._material_group_map[root_material_id] = MaterialGroup(root_material_id)
+                self._material_group_map[root_material_id] = MaterialGroup(root_material_id, MaterialNode(material_metadatas[root_material_id]))
                 self._material_group_map[root_material_id].is_read_only = self._container_registry.isReadOnly(root_material_id)
             group = self._material_group_map[root_material_id]
 
-            # We only add root materials here
-            if material_id == root_material_id:
-                group.root_material_node = MaterialNode(material_metadata)
-            else:
+            #Store this material in the group of the appropriate root material.
+            if material_id != root_material_id:
                 new_node = MaterialNode(material_metadata)
                 group.derived_material_node_list.append(new_node)
+
         # Order this map alphabetically so it's easier to navigate in a debugger
         self._material_group_map = OrderedDict(sorted(self._material_group_map.items(), key = lambda x: x[0]))
 
@@ -180,7 +178,7 @@ class MaterialManager(QObject):
         #    "machine" -> "variant_name" -> "root material ID" -> specific material InstanceContainer
         # Construct the "machine" -> "variant" -> "root material ID" -> specific material InstanceContainer
         self._diameter_machine_variant_material_map = dict()
-        for material_metadata in material_metadata_list:
+        for material_metadata in material_metadatas.values():
             # We don't store empty material in the lookup tables
             if material_metadata["id"] == "empty_material":
                 continue

+ 3 - 4
cura/Machines/Models/BrandMaterialsModel.py

@@ -4,8 +4,8 @@
 from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
 
 from UM.Qt.ListModel import ListModel
-
-from .BaseMaterialsModel import BaseMaterialsModel
+from UM.Logger import Logger
+from cura.Machines.Models.BaseMaterialsModel import BaseMaterialsModel
 
 
 #
@@ -54,9 +54,7 @@ class BrandMaterialsModel(ListModel):
         self._material_manager = CuraApplication.getInstance().getMaterialManager()
 
         self._machine_manager.globalContainerChanged.connect(self._update)
-        self._extruder_manager.activeExtruderChanged.connect(self._update)
         self._material_manager.materialsUpdated.connect(self._update)
-
         self._update()
 
     def setExtruderPosition(self, position: int):
@@ -69,6 +67,7 @@ class BrandMaterialsModel(ListModel):
         return self._extruder_position
 
     def _update(self):
+        Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
         global_stack = self._machine_manager.activeMachine
         if global_stack is None:
             self.setItems([])

+ 2 - 0
cura/Machines/Models/BuildPlateModel.py

@@ -4,6 +4,7 @@
 from PyQt5.QtCore import Qt
 
 from UM.Application import Application
+from UM.Logger import Logger
 from UM.Qt.ListModel import ListModel
 from UM.Util import parseBool
 
@@ -29,6 +30,7 @@ class BuildPlateModel(ListModel):
         self._update()
 
     def _update(self):
+        Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
         global_stack = self._machine_manager._global_container_stack
         if not global_stack:
             self.setItems([])

+ 1 - 1
cura/Machines/Models/CustomQualityProfilesDropDownMenuModel.py

@@ -12,7 +12,7 @@ from cura.Machines.Models.QualityProfilesDropDownMenuModel import QualityProfile
 class CustomQualityProfilesDropDownMenuModel(QualityProfilesDropDownMenuModel):
 
     def _update(self):
-        Logger.log("d", "Updating %s ...", self.__class__.__name__)
+        Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
 
         active_global_stack = self._machine_manager.activeMachine
         if active_global_stack is None:

+ 4 - 3
cura/Machines/Models/GenericMaterialsModel.py

@@ -1,7 +1,8 @@
 # Copyright (c) 2018 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
-from .BaseMaterialsModel import BaseMaterialsModel
+from UM.Logger import Logger
+from cura.Machines.Models.BaseMaterialsModel import BaseMaterialsModel
 
 
 class GenericMaterialsModel(BaseMaterialsModel):
@@ -15,12 +16,12 @@ class GenericMaterialsModel(BaseMaterialsModel):
         self._material_manager = CuraApplication.getInstance().getMaterialManager()
 
         self._machine_manager.globalContainerChanged.connect(self._update)
-        self._extruder_manager.activeExtruderChanged.connect(self._update)
         self._material_manager.materialsUpdated.connect(self._update)
-
         self._update()
 
     def _update(self):
+        Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
+
         global_stack = self._machine_manager.activeMachine
         if global_stack is None:
             self.setItems([])

+ 4 - 1
cura/Machines/Models/MaterialManagementModel.py

@@ -1,8 +1,9 @@
 # Copyright (c) 2018 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
-from PyQt5.QtCore import Qt, pyqtProperty
+from PyQt5.QtCore import Qt
 
+from UM.Logger import Logger
 from UM.Qt.ListModel import ListModel
 
 
@@ -60,6 +61,8 @@ class MaterialManagementModel(ListModel):
         self._update()
 
     def _update(self):
+        Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
+
         global_stack = self._machine_manager.activeMachine
         if global_stack is None:
             self.setItems([])

+ 14 - 9
cura/Machines/Models/NozzleModel.py

@@ -4,6 +4,7 @@
 from PyQt5.QtCore import Qt
 
 from UM.Application import Application
+from UM.Logger import Logger
 from UM.Qt.ListModel import ListModel
 from UM.Util import parseBool
 
@@ -20,26 +21,30 @@ class NozzleModel(ListModel):
         self.addRoleName(self.HotendNameRole, "hotend_name")
         self.addRoleName(self.ContainerNodeRole, "container_node")
 
-        Application.getInstance().globalContainerStackChanged.connect(self._update)
-        Application.getInstance().getMachineManager().activeVariantChanged.connect(self._update)
-        Application.getInstance().getMachineManager().activeStackChanged.connect(self._update)
-        Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update)
+        self._application = Application.getInstance()
+        self._machine_manager = self._application.getMachineManager()
+        self._variant_manager = self._application.getVariantManager()
+
+        self._machine_manager.globalContainerChanged.connect(self._update)
+        self._update()
 
     def _update(self):
+        Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
+
         self.items.clear()
 
-        variant_manager = Application.getInstance()._variant_manager
-        active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
-        if active_global_stack is None:
+        global_stack = self._machine_manager.activeMachine
+        if global_stack is None:
             self.setItems([])
             return
 
-        has_variants = parseBool(active_global_stack.getMetaDataEntry("has_variants", False))
+        has_variants = parseBool(global_stack.getMetaDataEntry("has_variants", False))
         if not has_variants:
             self.setItems([])
             return
 
-        variant_node_dict = variant_manager.getVariantNodes(active_global_stack)
+        from cura.Machines.VariantManager import VariantType
+        variant_node_dict = self._variant_manager.getVariantNodes(global_stack, VariantType.NOZZLE)
         if not variant_node_dict:
             self.setItems([])
             return

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