diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index cbe75cc548..cf2ce25ff7 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -69,6 +69,8 @@ class SimulationPass(RenderPass): self._layer_shader.setUniformValue("u_min_feedrate", self._layer_view.getMinFeedrate()) self._layer_shader.setUniformValue("u_max_thickness", self._layer_view.getMaxThickness()) self._layer_shader.setUniformValue("u_min_thickness", self._layer_view.getMinThickness()) + self._layer_shader.setUniformValue("u_max_line_width", self._layer_view.getMaxLineWidth()) + self._layer_shader.setUniformValue("u_min_line_width", self._layer_view.getMinLineWidth()) self._layer_shader.setUniformValue("u_layer_view_type", self._layer_view.getSimulationViewType()) self._layer_shader.setUniformValue("u_extruder_opacity", self._layer_view.getExtruderOpacities()) self._layer_shader.setUniformValue("u_show_travel_moves", self._layer_view.getShowTravelMoves()) @@ -82,6 +84,8 @@ class SimulationPass(RenderPass): self._layer_shader.setUniformValue("u_min_feedrate", 0) self._layer_shader.setUniformValue("u_max_thickness", 1) self._layer_shader.setUniformValue("u_min_thickness", 0) + self._layer_shader.setUniformValue("u_max_line_width", 1) + self._layer_shader.setUniformValue("u_min_line_width", 0) self._layer_shader.setUniformValue("u_layer_view_type", 1) self._layer_shader.setUniformValue("u_extruder_opacity", [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) self._layer_shader.setUniformValue("u_show_travel_moves", 0) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 1324d793fb..9494e42a5e 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -91,6 +91,8 @@ class SimulationView(CuraView): self._min_feedrate = sys.float_info.max self._max_thickness = sys.float_info.min self._min_thickness = sys.float_info.max + self._max_line_width = sys.float_info.min + self._min_line_width = sys.float_info.max self._global_container_stack = None # type: Optional[ContainerStack] self._proxy = None @@ -220,6 +222,8 @@ class SimulationView(CuraView): self._min_feedrate = sys.float_info.max self._max_thickness = sys.float_info.min self._min_thickness = sys.float_info.max + self._max_line_width = sys.float_info.min + self._min_line_width = sys.float_info.max def beginRendering(self) -> None: scene = self.getController().getScene() @@ -386,6 +390,14 @@ class SimulationView(CuraView): def getMaxThickness(self) -> float: return self._max_thickness + def getMaxLineWidth(self) -> float: + return self._max_line_width + + def getMinLineWidth(self) -> float: + if abs(self._min_line_width - sys.float_info.max) < 10: # Some lenience due to floating point rounding. + return 0.0 # If it's still max-float, there are no measurements. Use 0 then. + return self._min_line_width + def calculateMaxLayers(self) -> None: scene = self.getController().getScene() @@ -410,6 +422,8 @@ class SimulationView(CuraView): for p in layer_data.getLayer(layer_id).polygons: self._max_feedrate = max(float(p.lineFeedrates.max()), self._max_feedrate) self._min_feedrate = min(float(p.lineFeedrates.min()), self._min_feedrate) + self._max_line_width = max(float(p.lineWidths.max()), self._max_line_width) + self._min_line_width = min(float(p.lineWidths.min()), self._min_line_width) self._max_thickness = max(float(p.lineThicknesses.max()), self._max_thickness) try: self._min_thickness = min(float(p.lineThicknesses[numpy.nonzero(p.lineThicknesses)].min()), self._min_thickness) diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index d29d4051a4..7611e0d558 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -89,6 +89,7 @@ Cura.ExpandableComponent property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3 property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2 property bool show_thickness_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 3 + property bool show_line_width_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 4 property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers") property int top_layer_count: UM.Preferences.getValue("view/top_layer_count") @@ -117,9 +118,13 @@ Cura.ExpandableComponent type_id: 2 }) layerViewTypes.append({ - text: catalog.i18nc("@label:listbox", "Layer thickness"), + text: catalog.i18nc("@label:listbox", "Layer Thickness"), type_id: 3 // these ids match the switching in the shader }) + layerViewTypes.append({ + text: catalog.i18nc("@label:listbox", "Line Width"), + type_id: 4 + }) } ComboBox @@ -145,9 +150,10 @@ Cura.ExpandableComponent { // Update the visibility of the legends. viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1); - viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3); + viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3 || type_id == 4); viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2); viewSettings.show_thickness_gradient = viewSettings.show_gradient && (type_id == 3); + viewSettings.show_line_width_gradient = viewSettings.show_gradient && (type_id == 4); } } @@ -390,6 +396,11 @@ Cura.ExpandableComponent { return parseFloat(UM.SimulationView.getMinThickness()).toFixed(2) } + //Line width selected + if(UM.Preferences.getValue("layerview/layer_view_type") == 4) + { + return parseFloat(UM.SimulationView.getMinLineWidth()).toFixed(2); + } } return catalog.i18nc("@label","min") } @@ -415,6 +426,11 @@ Cura.ExpandableComponent { return "mm" } + //Line width selected + if(UM.Preferences.getValue("layerview/layer_view_type") == 4) + { + return "mm" + } } return "" } @@ -439,6 +455,11 @@ Cura.ExpandableComponent { return parseFloat(UM.SimulationView.getMaxThickness()).toFixed(2) } + //Line width selected + if(UM.Preferences.getValue("layerview/layer_view_type") == 4) + { + return parseFloat(UM.SimulationView.getMaxLineWidth()).toFixed(2); + } } return catalog.i18nc("@label","max") } @@ -453,7 +474,7 @@ Cura.ExpandableComponent Rectangle { id: feedrateGradient - visible: viewSettings.show_feedrate_gradient + visible: viewSettings.show_feedrate_gradient || viewSettings.show_line_width_gradient anchors.left: parent.left anchors.right: parent.right height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index ce2c336257..12947f6464 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -117,6 +117,14 @@ class SimulationViewProxy(QObject): def getMaxThickness(self): return self._simulation_view.getMaxThickness() + @pyqtSlot(result=float) + def getMaxLineWidth(self): + return self._simulation_view.getMaxLineWidth() + + @pyqtSlot(result=float) + def getMinLineWidth(self): + return self._simulation_view.getMinLineWidth() + # Opacity 0..1 @pyqtSlot(int, float) def setExtruderOpacity(self, extruder_nr, opacity): diff --git a/plugins/SimulationView/layers3d.shader b/plugins/SimulationView/layers3d.shader index 0a5cc23ce7..a0c93e146a 100644 --- a/plugins/SimulationView/layers3d.shader +++ b/plugins/SimulationView/layers3d.shader @@ -10,6 +10,8 @@ vertex41core = uniform lowp float u_min_feedrate; uniform lowp float u_max_thickness; uniform lowp float u_min_thickness; + uniform lowp float u_max_line_width; + uniform lowp float u_min_line_width; uniform lowp int u_layer_view_type; uniform lowp mat4 u_extruder_opacity; // currently only for max 16 extruders, others always visible @@ -66,6 +68,19 @@ vertex41core = return vec4(red, green, blue, 1.0); } + vec4 lineWidthGradientColor(float abs_value, float min_value, float max_value) + { + float value = (abs_value - min_value) / (max_value - min_value); + float red = value; + float green = 1 - abs(1 - 4 * value); + if(value > 0.375) + { + green = 0.5; + } + float blue = max(1 - 4 * value, 0); + return vec4(red, green, blue, 1.0); + } + void main() { vec4 v1_vertex = a_vertex; @@ -88,6 +103,9 @@ vertex41core = case 3: // "Layer thickness" v_color = layerThicknessGradientColor(a_line_dim.y, u_min_thickness, u_max_thickness); break; + case 4: // "Line width" + v_color = lineWidthGradientColor(a_line_dim.x, u_min_line_width, u_max_line_width); + break; } v_vertex = world_space_vert.xyz;