diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index 2ba0047cd4..d864f4288b 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -51,6 +51,7 @@ class ConvexHullDecorator(SceneNodeDecorator): return None hull = self._compute2DConvexHull() + if self._global_stack and self._node: if self._global_stack.getProperty("print_sequence", "value") == "one_at_a_time" and not self._node.getParent().callDecoration("isGroup"): hull = hull.getMinkowskiHull(Polygon(numpy.array(self._global_stack.getProperty("machine_head_polygon", "value"), numpy.float32))) @@ -72,7 +73,9 @@ class ConvexHullDecorator(SceneNodeDecorator): if self._global_stack: if self._global_stack.getProperty("print_sequence", "value") == "one_at_a_time" and not self._node.getParent().callDecoration("isGroup"): - return self._compute2DConvexHeadMin() + head_with_fans = self._compute2DConvexHeadMin() + head_with_fans_with_adhesion_margin = self._add2DAdhesionMargin(head_with_fans) + return head_with_fans_with_adhesion_margin return None ## Get convex hull of the node @@ -84,6 +87,7 @@ class ConvexHullDecorator(SceneNodeDecorator): if self._global_stack: if self._global_stack.getProperty("print_sequence", "value") == "one_at_a_time" and not self._node.getParent().callDecoration("isGroup"): + # Printing one at a time and it's not an object in a group return self._compute2DConvexHull() return None @@ -99,11 +103,6 @@ class ConvexHullDecorator(SceneNodeDecorator): convex_hull = self.getConvexHull() if self._convex_hull_node: - # Check if convex hull has changed - if (self._convex_hull_node.getHull() == convex_hull and - self._convex_hull_node.getThickness() == self._raft_thickness): - - return self._convex_hull_node.setParent(None) hull_node = ConvexHullNode.ConvexHullNode(self._node, convex_hull, self._raft_thickness, root) self._convex_hull_node = hull_node @@ -219,6 +218,44 @@ class ConvexHullDecorator(SceneNodeDecorator): min_head_hull = self._compute2DConvexHull().getMinkowskiHull(head_and_fans) return min_head_hull + ## Compensate given 2D polygon with adhesion margin + # \return 2D polygon with added margin + def _add2DAdhesionMargin(self, poly): + # Compensate for raft/skirt/brim + # Add extra margin depending on adhesion type + adhesion_type = self._global_stack.getProperty("adhesion_type", "value") + extra_margin = 0 + machine_head_coords = numpy.array( + self._global_stack.getProperty("machine_head_with_fans_polygon", "value"), + numpy.float32) + head_y_size = abs(machine_head_coords).min() # safe margin to take off in all directions + + if adhesion_type == "raft": + extra_margin = max(0, self._global_stack.getProperty("raft_margin", "value") - head_y_size) + elif adhesion_type == "brim": + extra_margin = max(0, self._global_stack.getProperty("brim_width", "value") - head_y_size) + elif adhesion_type == "skirt": + extra_margin = max( + 0, self._global_stack.getProperty("skirt_gap", "value") + + self._global_stack.getProperty("skirt_line_count", "value") * self._global_stack.getProperty("skirt_brim_line_width", "value") - + head_y_size) + # adjust head_and_fans with extra margin + if extra_margin > 0: + # In Cura 2.2+, there is a function to create this circle-like polygon. + extra_margin_polygon = Polygon(numpy.array([ + [-extra_margin, 0], + [-extra_margin * 0.707, extra_margin * 0.707], + [0, extra_margin], + [extra_margin * 0.707, extra_margin * 0.707], + [extra_margin, 0], + [extra_margin * 0.707, -extra_margin * 0.707], + [0, -extra_margin], + [-extra_margin * 0.707, -extra_margin * 0.707] + ], numpy.float32)) + + poly = poly.getMinkowskiHull(extra_margin_polygon) + return poly + def _roundHull(self, convex_hull): return convex_hull.getMinkowskiHull(Polygon(numpy.array([[-0.5, -0.5], [-0.5, 0.5], [0.5, 0.5], [0.5, -0.5]], numpy.float32))) @@ -249,4 +286,5 @@ class ConvexHullDecorator(SceneNodeDecorator): _affected_settings = [ "adhesion_type", "raft_base_thickness", "raft_interface_thickness", "raft_surface_layers", - "raft_surface_thickness", "raft_airgap", "print_sequence"] + "raft_surface_thickness", "raft_airgap", "print_sequence", + "skirt_gap", "skirt_line_count", "skirt_brim_line_width", "skirt_distance"] diff --git a/cura/ConvexHullNode.py b/cura/ConvexHullNode.py index f73db2a597..703dfb0bed 100644 --- a/cura/ConvexHullNode.py +++ b/cura/ConvexHullNode.py @@ -28,15 +28,16 @@ class ConvexHullNode(SceneNode): # The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting. self._mesh_height = 0.1 + self._thickness = thickness + # The node this mesh is "watching" self._node = node + self._convex_hull_head_mesh = None + self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged) self._onNodeDecoratorsChanged(self._node) - self._convex_hull_head_mesh = None - self._hull = hull - self._thickness = thickness if self._hull: hull_mesh_builder = MeshBuilder() @@ -46,11 +47,6 @@ class ConvexHullNode(SceneNode): hull_mesh = hull_mesh_builder.build() self.setMeshData(hull_mesh) - convex_hull_head = self._node.callDecoration("getConvexHullHead") - if convex_hull_head: - convex_hull_head_builder = MeshBuilder() - convex_hull_head_builder.addConvexPolygon(convex_hull_head.getPoints(), self._mesh_height-thickness) - self._convex_hull_head_mesh = convex_hull_head_builder.build() def getHull(self): return self._hull @@ -78,6 +74,12 @@ class ConvexHullNode(SceneNode): def _onNodeDecoratorsChanged(self, node): self._color = Color(35, 35, 35, 0.5) + convex_hull_head = self._node.callDecoration("getConvexHullHead") + if convex_hull_head: + convex_hull_head_builder = MeshBuilder() + convex_hull_head_builder.addConvexPolygon(convex_hull_head.getPoints(), self._mesh_height-self._thickness) + self._convex_hull_head_mesh = convex_hull_head_builder.build() + if not node: return diff --git a/plugins/SolidView/SolidView.py b/plugins/SolidView/SolidView.py index 96f60fb7cf..2182a0748a 100644 --- a/plugins/SolidView/SolidView.py +++ b/plugins/SolidView/SolidView.py @@ -35,7 +35,7 @@ class SolidView(View): if not self._disabled_shader: self._disabled_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "striped.shader")) - self._disabled_shader.setUniformValue("u_diffuseColor1", [1.0, 0.28, 0.28, 1.0]) + self._disabled_shader.setUniformValue("u_diffuseColor1", [0.48, 0.48, 0.48, 1.0]) self._disabled_shader.setUniformValue("u_diffuseColor2", [0.68, 0.68, 0.68, 1.0]) self._disabled_shader.setUniformValue("u_width", 50.0)