Example #1
0
        public GuiWidget AddPluginWidget(SectionWidget sectionWidget)
        {
            // Section not active due to constraints
            if (sectionWidget == null)
            {
                return(null);
            }

            theme.ApplyBoxStyle(sectionWidget);

            sectionWidget.ContentPanel.Padding = new BorderDouble(10, 10, 10, 0);

            column.AddChild(sectionWidget);

            // Disable borders on all SettingsRow children in control panels
            foreach (var settingsRow in sectionWidget.ContentPanel.Descendants <SettingsRow>())
            {
                settingsRow.BorderColor = Color.Transparent;
            }

            // Return the panel widget rather than the source sectionWidget
            return(sectionWidget.ContentPanel);
        }
        public PrinterCalibrationWizard(PrinterConfig printer, ThemeConfig theme)
        {
            var stages = new List <ISetupWizard>()
            {
                new ZCalibrationWizard(printer),
                new PrintLevelingWizard(printer),
                new LoadFilamentWizard(printer, extruderIndex: 0, showAlreadyLoadedButton: true),
                new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true),
                new XyCalibrationWizard(printer, 1)
            };

            this.Stages  = stages;
            this.printer = printer;

            this.HomePageGenerator = () =>
            {
                var homePage = new WizardSummaryPage()
                {
                    HeaderText = "Printer Setup & Calibration".Localize()
                };

                var contentRow = homePage.ContentRow;

                if (!this.ReturnedToHomePage)
                {
                    contentRow.AddChild(
                        new WrappedTextWidget(
                            @"Select the calibration task on the left to continue".Replace("\r\n", "\n"),
                            pointSize: theme.DefaultFontSize,
                            textColor: theme.TextColor));
                }

                contentRow.BackgroundColor = Color.Transparent;

                foreach (var stage in this.Stages.Where(s => s.Enabled && s.Visible))
                {
                    GuiWidget rightWidget = null;
                    var       widget      = new GuiWidget();

                    if (stage is ZCalibrationWizard probeWizard)
                    {
                        var column = CreateColumn(theme);
                        column.FlowDirection = FlowDirection.LeftToRight;

                        var offset = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset);

                        column.AddChild(
                            new ValueTag(
                                "Z Offset".Localize(),
                                offset.Z.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            Margin      = new BorderDouble(bottom: 4),
                            MinimumSize = new Vector2(125, 0)
                        });

                        widget = column;
                    }

                    if (stage is PrintLevelingWizard levelingWizard)
                    {
                        PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;

                        // Always show leveling option if printer does not have hardware leveling
                        if (!printer.Settings.GetValue <bool>(SettingsKey.has_hardware_leveling))
                        {
                            var positions = levelingData.SampledPositions;

                            var column = CreateColumn(theme);

                            column.AddChild(
                                new ValueTag(
                                    "Leveling Solution".Localize(),
                                    printer.Settings.GetValue(SettingsKey.print_leveling_solution),
                                    new BorderDouble(12, 5, 2, 5),
                                    5,
                                    11)
                            {
                                Margin      = new BorderDouble(bottom: 4),
                                MinimumSize = new Vector2(125, 0)
                            });

                            var row = new FlowLayoutWidget()
                            {
                                VAnchor = VAnchor.Fit,
                                HAnchor = HAnchor.Fit
                            };

                            // Only show Edit button if data initialized
                            if (levelingData?.SampledPositions.Count() > 0)
                            {
                                var editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, theme.InvertIcons), theme)
                                {
                                    Name        = "Edit Leveling Data Button",
                                    ToolTipText = "Edit Leveling Data".Localize(),
                                };

                                editButton.Click += (s, e) =>
                                {
                                    DialogWindow.Show(new EditLevelingSettingsPage(printer, theme));
                                };

                                row.AddChild(editButton);
                            }

                            // only show the switch if leveling can be turned off (it can't if it is required).
                            if (!printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print))
                            {
                                // put in the switch
                                printLevelingSwitch = new RoundedToggleSwitch(theme)
                                {
                                    VAnchor     = VAnchor.Center,
                                    Margin      = new BorderDouble(theme.DefaultContainerPadding, 0),
                                    Checked     = printer.Settings.GetValue <bool>(SettingsKey.print_leveling_enabled),
                                    ToolTipText = "Enable Software Leveling".Localize()
                                };
                                printLevelingSwitch.CheckedStateChanged += (sender, e) =>
                                {
                                    printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
                                };
                                printLevelingSwitch.Closed += (s, e) =>
                                {
                                    // Unregister listeners
                                    printer.Settings.PrintLevelingEnabledChanged -= this.Settings_PrintLevelingEnabledChanged;
                                };

                                // TODO: Why is this listener conditional? If the leveling changes somehow, shouldn't we be updated the UI to reflect that?
                                // Register listeners
                                printer.Settings.PrintLevelingEnabledChanged += this.Settings_PrintLevelingEnabledChanged;

                                row.AddChild(printLevelingSwitch);
                            }

                            rightWidget = row;

                            // Only visualize leveling data if initialized
                            if (levelingData?.SampledPositions.Count() > 0)
                            {
                                var probeWidget = new ProbePositionsWidget(printer, positions.Select(v => new Vector2(v)).ToList(), theme)
                                {
                                    HAnchor            = HAnchor.Absolute,
                                    VAnchor            = VAnchor.Absolute,
                                    Height             = 200,
                                    Width              = 200,
                                    RenderLevelingData = true,
                                    RenderProbePath    = false,
                                    SimplePoints       = true,
                                };
                                column.AddChild(probeWidget);
                            }

                            widget = column;
                        }
                    }

                    if (stage is XyCalibrationWizard xyWizard)
                    {
                        var column = CreateColumn(theme);
                        column.FlowDirection = FlowDirection.LeftToRight;

                        var hotendOffset = printer.Settings.Helpers.ExtruderOffset(1);

                        var tool2Column = new FlowLayoutWidget(FlowDirection.TopToBottom);
                        column.AddChild(tool2Column);

                        tool2Column.AddChild(
                            new TextWidget("Tool".Localize() + " 2", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
                        {
                            Margin = new BorderDouble(bottom: 4)
                        });

                        tool2Column.AddChild(
                            new ValueTag(
                                "X Offset".Localize(),
                                hotendOffset.X.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            Margin      = new BorderDouble(bottom: 4),
                            MinimumSize = new Vector2(125, 0)
                        });

                        tool2Column.AddChild(
                            new ValueTag(
                                "Y Offset".Localize(),
                                hotendOffset.Y.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            MinimumSize = new Vector2(125, 0)
                        });

                        widget = column;
                    }

                    if (stage.SetupRequired)
                    {
                        var column = CreateColumn(theme);
                        column.AddChild(new TextWidget("Setup Required".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor));

                        widget = column;
                    }
                    else if (stage is LoadFilamentWizard filamentWizard)
                    {
                        widget.Margin = new BorderDouble(left: theme.DefaultContainerPadding);
                    }

                    var section = new SectionWidget(stage.Title, widget, theme, rightAlignedContent: rightWidget, expandingContent: false);
                    theme.ApplyBoxStyle(section);

                    section.Margin            = section.Margin.Clone(left: 0);
                    section.ShowExpansionIcon = false;

                    if (stage.SetupRequired)
                    {
                        section.BackgroundColor = Color.Red.WithAlpha(30);
                    }

                    contentRow.AddChild(section);
                }

                return(homePage);
            };
        }
Example #3
0
        public PrinterCalibrationWizard(PrinterConfig printer, ThemeConfig theme)
        {
            var stages = new List <ISetupWizard>()
            {
                new ZCalibrationWizard(printer),
                new PrintLevelingWizard(printer),
                new LoadFilamentWizard(printer, extruderIndex: 0, showAlreadyLoadedButton: true),
                new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true),
                new XyCalibrationWizard(printer, 1)
            };

            this.Stages  = stages;
            this.printer = printer;

            this.HomePageGenerator = () =>
            {
                var homePage = new WizardSummaryPage()
                {
                    HeaderText = "Printer Setup & Calibration".Localize()
                };

                var contentRow = homePage.ContentRow;

                if (!ReturnedToHomePage)
                {
                    if (printer.Connection.IsConnected)
                    {
                        contentRow.AddChild(
                            new WrappedTextWidget(
                                @"Select the calibration task to continue".Replace("\r\n", "\n"),
                                pointSize: theme.DefaultFontSize,
                                textColor: theme.TextColor));
                    }
                    else
                    {
                        contentRow.AddChild(
                            new WrappedTextWidget(
                                @"Connect the printer to complete the calibration tasks.".Replace("\r\n", "\n"),
                                pointSize: theme.DefaultFontSize,
                                textColor: theme.TextColor));
                    }
                }

                contentRow.BackgroundColor = Color.Transparent;

                foreach (var stage in this.Stages.Where(s => s.Visible))
                {
                    GuiWidget rightWidget = null;
                    var       widget      = new GuiWidget();

                    if (stage is ZCalibrationWizard probeWizard)
                    {
                        var column = CreateColumn(theme);
                        column.FlowDirection = FlowDirection.LeftToRight;

                        var offset = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset);

                        column.AddChild(
                            new ValueTag(
                                "Z Offset".Localize(),
                                offset.Z.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            Margin      = new BorderDouble(bottom: 4),
                            MinimumSize = new Vector2(125, 0)
                        });

                        column.AddChild(new HorizontalSpacer());
                        AddRunStageButton("Run Z Calibration".Localize(), theme, stage, column);

                        widget = column;
                    }

                    if (stage is LoadFilamentWizard loadWizard)
                    {
                        var column = CreateColumn(theme);
                        column.FlowDirection = FlowDirection.LeftToRight;
                        var lastRow = new FlowLayoutWidget()
                        {
                            HAnchor = HAnchor.Stretch
                        };
                        column.AddChild(lastRow);
                        lastRow.AddChild(new HorizontalSpacer());
                        AddRunStageButton("Load Filament".Localize(), theme, stage, lastRow).Margin = new BorderDouble(10);
                        widget = column;
                    }

                    if (stage is PrintLevelingWizard levelingWizard)
                    {
                        PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;

                        var column = CreateColumn(theme);

                        var lastRow = new FlowLayoutWidget()
                        {
                            HAnchor = HAnchor.Stretch
                        };

                        if (levelingData != null &&
                            printer.Settings?.GetValue <bool>(SettingsKey.print_leveling_enabled) == true)
                        {
                            var positions = levelingData.SampledPositions;

                            var levelingSolution = printer.Settings.GetValue(SettingsKey.print_leveling_solution);

                            column.AddChild(
                                new ValueTag(
                                    "Leveling Solution".Localize(),
                                    levelingSolution,
                                    new BorderDouble(12, 5, 2, 5),
                                    5,
                                    11)
                            {
                                Margin      = new BorderDouble(bottom: 4),
                                MinimumSize = new Vector2(125, 0)
                            });

                            var editButton = new IconButton(StaticData.Instance.LoadIcon("icon_edit.png", 16, 16).SetToColor(theme.TextColor), theme)
                            {
                                Name        = "Edit Leveling Data Button",
                                ToolTipText = "Edit Leveling Data".Localize(),
                            };

                            editButton.Click += (s, e) =>
                            {
                                DialogWindow.Show(new EditLevelingSettingsPage(printer, theme));
                            };

                            var row = new FlowLayoutWidget()
                            {
                                VAnchor = VAnchor.Fit,
                                HAnchor = HAnchor.Fit
                            };
                            row.AddChild(editButton);

                            // only show the switch if leveling can be turned off (it can't if it is required).
                            if (!printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print))
                            {
                                // put in the switch
                                printLevelingSwitch = new RoundedToggleSwitch(theme)
                                {
                                    VAnchor     = VAnchor.Center,
                                    Margin      = new BorderDouble(theme.DefaultContainerPadding, 0),
                                    Checked     = printer.Settings.GetValue <bool>(SettingsKey.print_leveling_enabled),
                                    ToolTipText = "Enable Software Leveling".Localize()
                                };
                                printLevelingSwitch.CheckedStateChanged += (sender, e) =>
                                {
                                    printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
                                };
                                printLevelingSwitch.Closed += (s, e) =>
                                {
                                    // Unregister listeners
                                    printer.Settings.PrintLevelingEnabledChanged -= Settings_PrintLevelingEnabledChanged;
                                };

                                // TODO: Why is this listener conditional? If the leveling changes somehow, shouldn't we be updated the UI to reflect that?
                                // Register listeners
                                printer.Settings.PrintLevelingEnabledChanged += Settings_PrintLevelingEnabledChanged;

                                row.AddChild(printLevelingSwitch);
                            }

                            rightWidget = row;

                            column.AddChild(lastRow);

                            var probeWidget = new ProbePositionsWidget(printer, positions.Select(v => new Vector2(v)).ToList(), theme)
                            {
                                HAnchor            = HAnchor.Absolute,
                                VAnchor            = VAnchor.Absolute,
                                Height             = 200,
                                Width              = 200,
                                RenderLevelingData = true,
                                RenderProbePath    = false,
                                SimplePoints       = true,
                            };
                            lastRow.AddChild(probeWidget);
                        }
                        else
                        {
                            column.AddChild(lastRow);

                            if (!printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print))
                            {
                                lastRow.AddChild(new WrappedTextWidget(
                                                     @"Print Leveling is an optional feature for this printer that can help improve print quality. If the bed is uneven or cannot be mechanically leveled.".Localize(),
                                                     pointSize: theme.DefaultFontSize,
                                                     textColor: theme.TextColor));
                            }
                            else if (printer.Settings.GetValue <bool>(SettingsKey.validate_leveling))
                            {
                                lastRow.AddChild(new WrappedTextWidget(
                                                     @"Print Leveling will run automatically at the start of each print.".Localize(),
                                                     pointSize: theme.DefaultFontSize,
                                                     textColor: theme.TextColor));
                            }
                            else
                            {
                                lastRow.AddChild(new HorizontalSpacer());
                            }
                        }

                        lastRow.AddChild(new HorizontalSpacer());
                        AddRunStageButton("Run Print Leveling".Localize(), theme, stage, lastRow);

                        widget = column;
                    }

                    if (stage is XyCalibrationWizard xyWizard)
                    {
                        var row = CreateColumn(theme);
                        row.FlowDirection = FlowDirection.LeftToRight;

                        var hotendOffset = printer.Settings.Helpers.ExtruderOffset(1);

                        var tool2Column = new FlowLayoutWidget(FlowDirection.TopToBottom);
                        row.AddChild(tool2Column);

                        tool2Column.AddChild(
                            new TextWidget("Tool".Localize() + " 2", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
                        {
                            Margin = new BorderDouble(bottom: 4)
                        });

                        tool2Column.AddChild(
                            new ValueTag(
                                "X Offset".Localize(),
                                hotendOffset.X.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            Margin      = new BorderDouble(bottom: 4),
                            MinimumSize = new Vector2(125, 0)
                        });

                        tool2Column.AddChild(
                            new ValueTag(
                                "Y Offset".Localize(),
                                hotendOffset.Y.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            MinimumSize = new Vector2(125, 0)
                        });

                        row.AddChild(new HorizontalSpacer());
                        AddRunStageButton("Run Nozzle Alignment".Localize(), theme, stage, row);

                        widget = row;
                    }

                    if (stage is LoadFilamentWizard filamentWizard)
                    {
                        widget.Margin = new BorderDouble(left: theme.DefaultContainerPadding);
                    }

                    var sectionName = stage.Title;
                    if (stage.SetupRequired)
                    {
                        sectionName += " - " + "Required".Localize();
                    }
                    else if (stage.Completed)
                    {
                        sectionName += " - " + "Completed".Localize();
                    }
                    else
                    {
                        sectionName += " - " + "Optional".Localize();
                    }


                    var section = new SectionWidget(sectionName, widget, theme, rightAlignedContent: rightWidget, expandingContent: false);
                    theme.ApplyBoxStyle(section);

                    section.Margin            = section.Margin.Clone(left: 0);
                    section.ShowExpansionIcon = false;

                    if (stage.SetupRequired)
                    {
                        section.BackgroundColor = Color.Red.WithAlpha(30);
                    }

                    contentRow.AddChild(section);
                }

                return(homePage);
            };
        }