Exemple #1
0
        private void RefreshGCodeDetails(PrinterConfig printer)
        {
            loadedGCodeSection.CloseAllChildren();

            if (sceneContext.LoadedGCode?.LineCount > 0)
            {
                bool renderSpeeds = printer.Bed.RendererOptions.GCodeLineColorStyle == "Speeds";
                loadedGCodeSection.AddChild(
                    speedsWidget = new SectionWidget(
                        "Speeds".Localize(),
                        new SpeedsLegend(sceneContext.LoadedGCode, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Visible = renderSpeeds,
                    Padding = new BorderDouble(15, 4)
                },
                        theme)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                speedsWidget.Visible = renderSpeeds;

                // Single instance shared across widgets
                var gcodeDetails = new GCodeDetails(printer, printer.Bed.LoadedGCode);

                loadedGCodeSection.AddChild(
                    new SectionWidget(
                        "Details".Localize(),
                        new GCodeDetailsView(gcodeDetails, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                loadedGCodeSection.AddChild(
                    new SectionWidget(
                        "Layer".Localize(),
                        new GCodeLayerDetailsView(gcodeDetails, sceneContext, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });
            }

            // Enforce panel padding in sidebar
            this.EnsureSectionWidgetStyling(loadedGCodeSection.Children <SectionWidget>());

            this.Invalidate();
        }
Exemple #2
0
        private void RefreshGCodeDetails(PrinterConfig printer)
        {
            loadedGCodeSection.CloseAllChildren();

            if (sceneContext.LoadedGCode?.LineCount > 0)
            {
                bool renderSpeeds = printer.Bed.RendererOptions.GCodeLineColorStyle == "Speeds";
                loadedGCodeSection.AddChild(
                    speedsWidget = new SectionWidget(
                        "Speeds".Localize(),
                        new SpeedsLegend(sceneContext.LoadedGCode, theme, printer)
                {
                    HAnchor = HAnchor.Stretch,
                    Visible = renderSpeeds,
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_speeds",
                        expanded: true)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                speedsWidget.Visible = renderSpeeds;

                // Single instance shared across widgets
                loadedGCodeSection.AddChild(
                    new SectionWidget(
                        "Details".Localize(),
                        new GCodeDetailsView(printer.Bed.LoadedGCode, printer, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_details",
                        expanded: true)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                loadedGCodeSection.AddChild(
                    new SectionWidget(
                        "Layer".Localize(),
                        new GCodeLayerDetailsView(printer.Bed.LoadedGCode, sceneContext, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_layer_details",
                        expanded: true)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                SectionWidget lineInspectorWidget;

                loadedGCodeSection.AddChild(
                    lineInspectorWidget = new SectionWidget(
                        "Line Inspector".Localize(),
                        new GCodeDebugView(printerTabPage, printer.Bed.LoadedGCode, sceneContext, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_line_inspector",
                        expanded: false)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                lineInspectorWidget.ExpandedChanged += (s, sectionVisible) =>
                {
                    sceneContext.GCodeRenderer.GCodeInspector = sectionVisible;
                };

                sceneContext.GCodeRenderer.GCodeInspector = lineInspectorWidget.ContentPanel.Visible;
            }

            // Enforce panel padding in sidebar
            this.EnsureSectionWidgetStyling(loadedGCodeSection.Children <SectionWidget>());

            this.Invalidate();
        }
Exemple #3
0
        private void RefreshGCodeDetails(PrinterConfig printer)
        {
            loadedGCodeSection.CloseChildren();

            if (sceneContext.LoadedGCode?.LineCount > 0)
            {
                bool renderSpeeds = printer.Bed.RendererOptions.GCodeLineColorStyle == "Speeds";
                loadedGCodeSection.AddChild(
                    speedsWidget = new SectionWidget(
                        "Speeds".Localize(),
                        new SpeedsLegend(sceneContext.LoadedGCode, theme, printer)
                {
                    HAnchor = HAnchor.Stretch,
                    Visible = renderSpeeds,
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_speeds",
                        expanded: true)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                speedsWidget.Visible = renderSpeeds;

                // Single instance shared across widgets
                loadedGCodeSection.AddChild(
                    new SectionWidget(
                        "Details".Localize(),
                        new GCodeDetailsView(printer.Bed.LoadedGCode, printer, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_details",
                        expanded: true)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                var copyButton = new TextButton("copy".Localize(), theme, 8)
                {
                    Padding     = 5,
                    Margin      = new BorderDouble(0, 0, 15, 0),
                    VAnchor     = VAnchor.Center | VAnchor.Fit,
                    ToolTipText = "Copy extrusions data".Localize()
                };

                copyButton.Click += (s, e) =>
                {
                    var output = new StringBuilder();
                    // copy all the extrusions to the clipboard as paths
                    var extrusions = printer.Bed.LoadedGCode.GetExtrusionsForLayer(sceneContext.ActiveLayerIndex);
                    for (int i = 0; i < extrusions.Count; i++)
                    {
                        var extrusion = extrusions[i];
                        var count     = extrusion.Count;
                        for (var j = 0; j < count; j++)
                        {
                            var  position   = extrusion[j];
                            bool debugTurns = false;
                            if (debugTurns)
                            {
                                var prevPosition  = extrusion[(count + j - 1) % count];
                                var nextPosition  = extrusion[(count + j + 1) % count];
                                var angle         = position.GetTurnAmount(prevPosition, nextPosition);
                                var lengthToPoint = extrusion.LengthTo(j);

                                var leftPosition    = extrusion.GetPositionAt(lengthToPoint - 1.6);
                                var rightPosition   = extrusion.GetPositionAt(lengthToPoint + 1.6);
                                var nearAngle       = position.GetTurnAmount(leftPosition, rightPosition);
                                var directionNormal = (rightPosition - leftPosition).GetNormal().GetPerpendicularRight();
                                var delta           = Vector2.Dot(directionNormal, position - leftPosition);

                                output.AppendLine($"{lengthToPoint:0.##}, {angle:0.##}, {position.X:0.##}, {position.Y:0.##}, {delta:0.##}");
                            }
                            else
                            {
                                // output.AppendLine($"x:{position.X:0.##}, y:{position.Y:0.##}");
                                output.Append($"x:{position.X:0.##}, y:{position.Y:0.##},");
                            }
                        }

                        output.Append("|");
                    }

                    Clipboard.Instance.SetText(output.ToString());
                };

                loadedGCodeSection.AddChild(
                    new SectionWidget(
                        "Layer".Localize(),
                        new GCodeLayerDetailsView(printer.Bed.LoadedGCode, sceneContext, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_layer_details",
                        rightAlignedContent: copyButton,
                        expanded: true)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                SectionWidget lineInspectorWidget;

                loadedGCodeSection.AddChild(
                    lineInspectorWidget = new SectionWidget(
                        "Line Inspector".Localize(),
                        new GCodeDebugView(printerTabPage, printer.Bed.LoadedGCode, sceneContext, theme)
                {
                    HAnchor = HAnchor.Stretch,
                    Margin  = new BorderDouble(bottom: 3),
                    Padding = new BorderDouble(15, 4)
                },
                        theme,
                        serializationKey: "gcode_panel_line_inspector",
                        expanded: false)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit
                });

                lineInspectorWidget.ExpandedChanged += (s, sectionVisible) =>
                {
                    sceneContext.GCodeRenderer.GCodeInspector = sectionVisible;
                };

                sceneContext.GCodeRenderer.GCodeInspector = lineInspectorWidget.ContentPanel.Visible;
            }

            // Enforce panel padding in sidebar
            this.EnsureSectionWidgetStyling(loadedGCodeSection.Children <SectionWidget>());

            this.Invalidate();
        }
		public void ExtensionMethodsTests()
		{
			GuiWidget level0 = new GuiWidget() { Name = "level0" };
			GuiWidget level1 = new GuiWidget() { Name = "level1" };
			level0.AddChild(level1);
			GuiWidget level2 = new GuiWidget() { Name = "level2" };
			level1.AddChild(level2);
			GuiWidget level3 = new GuiWidget() { Name = "level3" };
			level2.AddChild(level3);
			List<GuiWidget> allWidgets = new List<GuiWidget>() { level0, level1, level2, level3 };

			foreach (var child in level0.Children<GuiWidget>())
			{
				Assert.IsTrue(child == allWidgets[1]);
			}
			foreach (var child in level1.Children<GuiWidget>())
			{
				Assert.IsTrue(child == allWidgets[2]);
			}
			foreach (var child in level2.Children<GuiWidget>())
			{
				Assert.IsTrue(child == allWidgets[3]);
			}
			foreach (var child in level3.Children<GuiWidget>())
			{
				Assert.IsTrue(false); // there are no children we should not get here
			}

			int index = allWidgets.Count-1;
			int parentCount = 0;
			foreach (var parent in level3.Parents<GuiWidget>())
			{
				parentCount++;
                Assert.IsTrue(parent == allWidgets[--index]);
			}
			Assert.IsTrue(parentCount == 3);
		}