Beispiel #1
0
        public static void AddSettingsRow(GuiWidget contentRow, PrinterConfig printer, string warning, string key, ThemeConfig theme, ref int tabIndex)
        {
            var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            contentRow.AddChild(
                new TextWidget(
                    "Recommended Settings Changes".Localize() + ":",
                    textColor: theme.TextColor,
                    pointSize: theme.DefaultFontSize)
            {
                Margin = new BorderDouble(10, 0, 0, 20)
            });

            contentRow.AddChild(
                new WrappedTextWidget(
                    warning,
                    textColor: theme.TextColor,
                    pointSize: theme.DefaultFontSize)
            {
                Margin = new BorderDouble(0, 10, 0, 20)
            });

            var settingsData = PrinterSettings.SettingsData[key];
            var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex);

            if (row is SliceSettingsRow settingsRow)
            {
                settingsRow.ArrowDirection = ArrowDirection.Left;
            }

            contentRow.AddChild(row);
        }
Beispiel #2
0
        private GuiWidget GetPopupContent(ThemeConfig menuTheme)
        {
            var widget = new IgnoredPopupWidget()
            {
                Width           = 300,
                HAnchor         = HAnchor.Absolute,
                VAnchor         = VAnchor.Fit,
                Padding         = new BorderDouble(12, 0),
                BackgroundColor = menuTheme.BackgroundColor
            };

            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Top,
            };

            widget.AddChild(container);

            GuiWidget hotendRow;

            container.AddChild(hotendRow = new SettingsItem(
                                   "Heated Bed".Localize(),
                                   menuTheme,
                                   new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = false,
                ToggleAction = (itemChecked) =>
                {
                    var goalTemp = itemChecked ? printer.Settings.GetValue <double>(SettingsKey.bed_temperature) : 0;

                    if (itemChecked)
                    {
                        SetTargetTemperature(goalTemp);
                    }
                    else
                    {
                        SetTargetTemperature(0);
                    }
                }
            },
                                   enforceGutter: false));

            var toggleWidget = hotendRow.Children.Where(o => o is ICheckbox).FirstOrDefault();

            toggleWidget.Name = "Toggle Heater";

            heatToggle = toggleWidget as ICheckbox;

            int tabIndex        = 0;
            var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            var settingsData   = PrinterSettings.SettingsData[SettingsKey.bed_temperature];
            var temperatureRow = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

            container.AddChild(temperatureRow);

            // Add the temperature row to the always enabled list ensuring the field can be set when disconnected
            alwaysEnabled.Add(temperatureRow);

            // add in the temp graph
            var graph = new DataViewGraph()
            {
                DynamicallyScaleRange = false,
                MinValue  = 0,
                ShowGoal  = true,
                GoalColor = menuTheme.PrimaryAccentColor,
                GoalValue = printer.Settings.GetValue <double>(SettingsKey.bed_temperature),
                MaxValue  = 150,             // could come from some profile value in the future
                Width     = widget.Width - 20,
                Height    = 35,              // this works better if it is a common multiple of the Width
                Margin    = new BorderDouble(0, 5, 0, 0),
            };

            runningInterval = UiThread.SetInterval(() =>
            {
                graph.AddData(this.ActualTemperature);
            }, 1);

            var settingsRow = temperatureRow.DescendantsAndSelf <SliceSettingsRow>().FirstOrDefault();

            void Printer_SettingChanged(object s, StringEventArgs stringEvent)
            {
                if (stringEvent != null)
                {
                    string settingsKey = stringEvent.Data;
                    if (this.allUiFields.TryGetValue(settingsKey, out UIField uifield))
                    {
                        string currentValue = settingsContext.GetValue(settingsKey);
                        if (uifield.Value != currentValue)
                        {
                            uifield.SetValue(
                                currentValue,
                                userInitiated: false);
                        }
                    }

                    if (stringEvent.Data == SettingsKey.bed_temperature)
                    {
                        var temp = printer.Settings.GetValue <double>(SettingsKey.bed_temperature);
                        graph.GoalValue = temp;

                        // TODO: Why is this only when enabled? How does it get set to
                        if (heatToggle.Checked)
                        {
                            // TODO: Why is a UI widget who is listening to model events driving this behavior? What when it's not loaded?
                            SetTargetTemperature(temp);
                        }

                        settingsRow.UpdateStyle();
                    }
                }
            }

            printer.Settings.SettingChanged += Printer_SettingChanged;
            printer.Disposed += (s, e) => printer.Settings.SettingChanged -= Printer_SettingChanged;

            container.AddChild(graph);

            return(widget);
        }
        public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme)
            : base(theme)
        {
            this.printer         = printer;
            this.DrawArrow       = true;
            this.BackgroundColor = theme.ToolbarButtonBackground;
            this.HoverColor      = theme.ToolbarButtonHover;
            this.MouseDownColor  = theme.ToolbarButtonDown;
            this.Name            = "PrintPopupMenu";
            this.HAnchor         = HAnchor.Fit;
            this.VAnchor         = VAnchor.Fit;

            settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            this.PopupHAnchor   = HAnchor.Fit;
            this.PopupVAnchor   = VAnchor.Fit;
            this.MakeScrollable = false;

            this.DynamicPopupContent = () =>
            {
                var menuTheme = ApplicationController.Instance.MenuTheme;

                int tabIndex = 0;

                allUiFields.Clear();

                var printPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Padding         = theme.DefaultContainerPadding,
                    BackgroundColor = menuTheme.BackgroundColor
                };

                printPanel.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.TextColor, pointSize: theme.DefaultFontSize)
                {
                    HAnchor = HAnchor.Left
                });

                var optionsPanel = new IgnoredFlowLayout()
                {
                    Name        = "PrintPopupMenu Panel",
                    HAnchor     = HAnchor.Fit | HAnchor.Left,
                    VAnchor     = VAnchor.Fit,
                    Padding     = 5,
                    MinimumSize = new Vector2(400, 65),
                };
                printPanel.AddChild(optionsPanel);

                foreach (var key in new[] { SettingsKey.layer_height, SettingsKey.fill_density, SettingsKey.create_raft })
                {
                    var settingsData = PrinterSettings.SettingsData[key];
                    var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

                    if (row is SliceSettingsRow settingsRow)
                    {
                        settingsRow.ArrowDirection = ArrowDirection.Left;
                    }

                    optionsPanel.AddChild(row);
                }

                var subPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Margin = new BorderDouble(2, 0)
                };

                bool anySettingOverridden = false;
                anySettingOverridden |= printer.Settings.GetValue <bool>(SettingsKey.spiral_vase);
                anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause));

                var sectionWidget = new SectionWidget("Advanced".Localize(), subPanel, menuTheme, expanded: anySettingOverridden)
                {
                    Name    = "Advanced Section",
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit,
                    Margin  = 0
                };
                printPanel.AddChild(sectionWidget);

                foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause })
                {
                    var advancedRow = SliceSettingsTabView.CreateItemRow(
                        PrinterSettings.SettingsData[key],
                        settingsContext,
                        printer,
                        menuTheme,
                        ref tabIndex,
                        allUiFields);

                    if (advancedRow is SliceSettingsRow settingsRow)
                    {
                        settingsRow.ArrowDirection = ArrowDirection.Left;
                    }

                    subPanel.AddChild(advancedRow);
                }

                menuTheme.ApplyBoxStyle(sectionWidget);

                sectionWidget.Margin = new BorderDouble(0, 10);
                sectionWidget.ContentPanel.Children <SettingsRow>().First().Border = new BorderDouble(0, 1);
                sectionWidget.ContentPanel.Children <SettingsRow>().Last().Border  = 0;

                var printerReadyToTakeCommands = printer.Connection.CommunicationState == PrinterCommunication.CommunicationStates.FinishedPrint ||
                                                 printer.Connection.CommunicationState == PrinterCommunication.CommunicationStates.Connected;

                // add the start print button
                var setupRow = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.Stretch
                };

                // Perform validation before popup
                var errors = printer.Validate();

                // Enable print option when no validation Errors exists
                var printEnabled = !errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error);

                var startPrintButton = new TextButton("Start Print".Localize(), menuTheme)
                {
                    Name    = "Start Print Button",
                    Enabled = printEnabled
                };

                startPrintButton.Click += (s, e) =>
                {
                    // Exit if the bed is not GCode and the bed has no printable items
                    if (!printer.Bed.EditContext.IsGGCodeSource &&
                        !printer.PrintableItems(printer.Bed.Scene).Any())
                    {
                        return;
                    }

                    UiThread.RunOnIdle(async() =>
                    {
                        // Save any pending changes before starting print operation
                        await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer, printer.Bed.SaveChanges);

                        await ApplicationController.Instance.PrintPart(
                            printer.Bed.EditContext,
                            printer,
                            null,
                            CancellationToken.None);
                    });

                    this.CloseMenu();
                };

                var hasErrors   = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error);
                var hasWarnings = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Warning &&
                                             UserSettings.Instance.get($"Ignore_{e.ID}") != "true");

                var hasErrorsOrWarnings = hasErrors || hasWarnings;
                if (hasErrorsOrWarnings)
                {
                    string label = hasErrors ? "Action Required".Localize() : "Action Recommended".Localize();

                    setupRow.AddChild(new TextWidget(label, textColor: hasErrors ? Color.Red : theme.PrimaryAccentColor, pointSize: theme.DefaultFontSize)
                    {
                        VAnchor = VAnchor.Bottom,
                        AutoExpandBoundsToText = true,
                    });
                }

                setupRow.AddChild(new HorizontalSpacer());

                // Export button {{
                bool isSailfish       = printer.Settings.GetValue <bool>("enable_sailfish_communication");
                var  exportPlugins    = PluginFinder.CreateInstancesOf <IExportPlugin>();
                var  targetPluginType = isSailfish ? typeof(X3GExport) : typeof(GCodeExport);

                // Find the first export plugin with the target type
                if (exportPlugins.FirstOrDefault(p => p.GetType() == targetPluginType) is IExportPlugin exportPlugin)
                {
                    string exportType = isSailfish ? "Export X3G".Localize() : "Export G-Code".Localize();

                    exportPlugin.Initialize(printer);

                    var exportGCodeButton = menuTheme.CreateDialogButton("Export".Localize());
                    exportGCodeButton.Name        = "Export Gcode Button";
                    exportGCodeButton.Enabled     = exportPlugin.Enabled;
                    exportGCodeButton.ToolTipText = exportPlugin.Enabled ? exportType : exportPlugin.DisabledReason;

                    exportGCodeButton.Click += (s, e) =>
                    {
                        ExportPrintItemPage.DoExport(
                            new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
                            printer,
                            exportPlugin);
                    };

                    setupRow.AddChild(exportGCodeButton);
                }

                // Export button }}

                setupRow.AddChild(startPrintButton);

                printPanel.AddChild(setupRow);

                if (printEnabled)
                {
                    theme.ApplyPrimaryActionStyle(startPrintButton);
                }
                else
                {
                    startPrintButton.BackgroundColor = theme.MinimalShade;
                }

                if (hasErrorsOrWarnings)
                {
                    var errorsPanel = new ValidationErrorsPanel(errors, menuTheme);

                    // Conditional layout for right or bottom errors panel alignment
                    var layoutStyle = FlowDirection.TopToBottom;

                    if (layoutStyle == FlowDirection.LeftToRight)
                    {
                        errorsPanel.HAnchor         = HAnchor.Absolute;
                        errorsPanel.VAnchor         = VAnchor.Fit | VAnchor.Top;
                        errorsPanel.BackgroundColor = theme.ResolveColor(menuTheme.BackgroundColor, theme.PrimaryAccentColor.WithAlpha(30));
                        errorsPanel.Width           = 350;

                        errorsPanel.Load += (s, e) =>
                        {
                            errorsPanel.Parent.BackgroundColor = Color.Transparent;
                        };
                    }
                    else
                    {
                        errorsPanel.HAnchor = HAnchor.Stretch;
                        errorsPanel.VAnchor = VAnchor.Fit;
                        errorsPanel.Margin  = 3;
                    }

                    // Instead of the typical case where the print panel is returned, wrap and append validation errors panel
                    var errorsContainer = new FlowLayoutWidget(layoutStyle)
                    {
                        HAnchor         = HAnchor.Fit,
                        VAnchor         = VAnchor.Fit,
                        BackgroundColor = layoutStyle == FlowDirection.TopToBottom ? printPanel.BackgroundColor : Color.Transparent
                    };

                    // Clear bottom padding
                    printPanel.Padding = printPanel.Padding.Clone(bottom: 2);

                    errorsContainer.AddChild(printPanel);
                    errorsContainer.AddChild(errorsPanel);

                    return(errorsContainer);
                }

                return(printPanel);
            };

            this.AddChild(new TextButton("Print".Localize(), theme)
            {
                Selectable = false,
                Padding    = theme.TextButtonPadding.Clone(right: 5)
            });

            // Register listeners
            printer.Settings.SettingChanged += Printer_SettingChanged;
        }
        private FlowLayoutWidget CreateComPortContainer()
        {
            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Margin  = new BorderDouble(0),
                VAnchor = VAnchor.Stretch
            };

            BorderDouble elementMargin = new BorderDouble(top: 3);

            var comPortLabel = new TextWidget("Serial Port".Localize() + ":", 0, 0, 12)
            {
                TextColor = theme.TextColor,
                Margin    = new BorderDouble(0, 0, 0, 10),
                HAnchor   = HAnchor.Stretch
            };

            var serialPortContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch
            };

            var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
            var menuTheme       = ApplicationController.Instance.MenuTheme;
            var tabIndex        = 0;
            var settingsToAdd   = new[]
            {
                SettingsKey.com_port,
                SettingsKey.baud_rate,
            };

            // turn off the port wizard button in this context
            ComPortField.ShowPortWizardButton = false;
            foreach (var key in settingsToAdd)
            {
                var settingsRow = SliceSettingsTabView.CreateItemRow(
                    PrinterSettings.SettingsData[key],
                    settingsContext,
                    printer,
                    menuTheme,
                    ref tabIndex);

                serialPortContainer.AddChild(settingsRow);
            }
            ComPortField.ShowPortWizardButton = false;

            var comPortMessageContainer = new FlowLayoutWidget
            {
                Margin  = elementMargin,
                HAnchor = HAnchor.Stretch
            };

            printerComPortError = new TextWidget("Currently available serial ports.".Localize(), 0, 0, 10)
            {
                TextColor = theme.TextColor,
                AutoExpandBoundsToText = true
            };

            printerComPortHelpLink = new LinkLabel("What's this?".Localize(), theme)
            {
                Margin  = new BorderDouble(left: 5),
                VAnchor = VAnchor.Bottom
            };
            printerComPortHelpLink.Click += (s, e) => printerComPortHelpMessage.Visible = !printerComPortHelpMessage.Visible;

            printerComPortHelpMessage = new TextWidget("The 'Serial Port' section lists all available serial\nports on your device. Changing which USB port the printer\nis connected to may change the associated serial port.\n\nTip: If you are uncertain, unplug/plug in your printer\nand hit refresh. The new port that appears should be\nyour printer.".Localize(), 0, 0, 10)
            {
                TextColor = theme.TextColor,
                Margin    = new BorderDouble(top: 10),
                Visible   = false
            };

            comPortMessageContainer.AddChild(printerComPortError);
            comPortMessageContainer.AddChild(printerComPortHelpLink);

            container.AddChild(comPortLabel);
            container.AddChild(serialPortContainer);
            container.AddChild(comPortMessageContainer);
            container.AddChild(printerComPortHelpMessage);

            container.HAnchor = HAnchor.Stretch;

            return(container);
        }
Beispiel #5
0
        public SetupCustomPrinter(PrinterConfig printer)
            : base("Done".Localize())
        {
            var scrollable = new ScrollableWidget(autoScroll: true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            scrollable.ScrollArea.HAnchor = HAnchor.Stretch;
            contentRow.AddChild(scrollable);

            var settingsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch
            };

            scrollable.AddChild(settingsContainer);

            var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
            var menuTheme       = ApplicationController.Instance.MenuTheme;
            var tabIndex        = 0;

            void AddSettingsRow(string key)
            {
                var settingsRow = SliceSettingsTabView.CreateItemRow(
                    PrinterSettings.SettingsData[key],
                    settingsContext,
                    printer,
                    menuTheme,
                    ref tabIndex);

                settingsContainer.AddChild(settingsRow);
            }

            void AddSettingsRows(string[] keys)
            {
                foreach (var key in keys)
                {
                    AddSettingsRow(key);
                }
            }

            settingsContainer.AddChild(
                new WrappedTextWidget(
                    "Set the information below to configure your printer. After completing this step, you can customize additional settings under the 'Settings' and 'Printer' options for this printer.".Localize(),
                    pointSize: theme.DefaultFontSize,
                    textColor: theme.TextColor)
            {
                Margin = new BorderDouble(5, 5, 5, 15)
            });


            // turn off the port wizard button in this context
            AddSettingsRow(SettingsKey.printer_name);

            settingsContainer.AddChild(new WrappedTextWidget("Bed Settings".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                Margin = new BorderDouble(5, 5, 5, 15)
            });

            AddSettingsRows(new[] { SettingsKey.bed_shape, SettingsKey.bed_size, SettingsKey.print_center, SettingsKey.build_height, SettingsKey.has_heated_bed });
            settingsContainer.AddChild(new WrappedTextWidget("Filament Settings".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                Margin = new BorderDouble(5, 5, 5, 15)
            });
            AddSettingsRows(new[] { SettingsKey.nozzle_diameter, SettingsKey.filament_diameter });
        }
        public XyCalibrationSelectPage(XyCalibrationWizard calibrationWizard)
            : base(calibrationWizard)
        {
            this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize();
            this.HeaderText  = "Calibration Print".Localize();

            preCalibrationPrintViewMode = printer.ViewState.ViewMode;

            contentRow.Padding = theme.DefaultContainerPadding;

            // default to normal offset
            calibrationWizard.Offset = printer.Settings.GetValue <double>(SettingsKey.nozzle_diameter) / 3.0;

            contentRow.AddChild(
                new TextWidget(
                    "This wizard will close to print a calibration part and resume after the print completes.".Localize(),
                    textColor: theme.TextColor,
                    pointSize: theme.DefaultFontSize)
            {
                Margin = new BorderDouble(bottom: theme.DefaultContainerPadding)
            });

            contentRow.AddChild(
                new TextWidget(
                    "Calibration Mode".Localize(),
                    textColor: theme.TextColor,
                    pointSize: theme.DefaultFontSize)
            {
                Margin = new BorderDouble(0, theme.DefaultContainerPadding)
            });


            var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Margin  = new BorderDouble(left: theme.DefaultContainerPadding),
                HAnchor = HAnchor.Stretch,
            };

            contentRow.AddChild(column);

            var coarseText = calibrationWizard.Quality == QualityType.Coarse ? "Initial (Recommended)".Localize() : "Coarse".Localize();

            column.AddChild(coarseCalibration = new RadioButton(coarseText, textColor: theme.TextColor, fontSize: theme.DefaultFontSize)
            {
                Checked = calibrationWizard.Quality == QualityType.Coarse
            });
            coarseCalibration.CheckedStateChanged += (s, e) =>
            {
                calibrationWizard.Quality = QualityType.Coarse;
                calibrationWizard.Offset  = printer.Settings.GetValue <double>(SettingsKey.nozzle_diameter);
            };

            var normalText = calibrationWizard.Quality == QualityType.Normal ? "Normal (Recommended)".Localize() : "Normal".Localize();

            column.AddChild(normalCalibration = new RadioButton(normalText, textColor: theme.TextColor, fontSize: theme.DefaultFontSize)
            {
                Checked = calibrationWizard.Quality == QualityType.Normal
            });
            normalCalibration.CheckedStateChanged += (s, e) =>
            {
                calibrationWizard.Quality = QualityType.Normal;
                calibrationWizard.Offset  = printer.Settings.GetValue <double>(SettingsKey.nozzle_diameter) / 3.0;
            };

            column.AddChild(fineCalibration = new RadioButton("Fine".Localize(), textColor: theme.TextColor, fontSize: theme.DefaultFontSize)
            {
                Checked = calibrationWizard.Quality == QualityType.Fine
            });
            fineCalibration.CheckedStateChanged += (s, e) =>
            {
                calibrationWizard.Quality = QualityType.Fine;
                calibrationWizard.Offset  = printer.Settings.GetValue <double>(SettingsKey.nozzle_diameter) / 9.0;
            };

            var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
            int tabIndex        = 0;
            var allUiFields     = new Dictionary <string, UIField>();
            var settingAdded    = false;

            void AddSettingsRow(string warning, string key)
            {
                if (!settingAdded)
                {
                    contentRow.AddChild(
                        new TextWidget(
                            "Recommended Settings Changes".Localize() + ":",
                            textColor: theme.TextColor,
                            pointSize: theme.DefaultFontSize)
                    {
                        Margin = new BorderDouble(10, 0, 0, 20)
                    });

                    settingAdded = true;
                }

                contentRow.AddChild(
                    new WrappedTextWidget(
                        warning,
                        textColor: theme.TextColor,
                        pointSize: theme.DefaultFontSize)
                {
                    Margin = new BorderDouble(0, 10, 0, 20)
                });

                var settingsData = PrinterSettings.SettingsData[key];
                var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex, allUiFields);

                if (row is SliceSettingsRow settingsRow)
                {
                    settingsRow.ArrowDirection = ArrowDirection.Left;
                }

                contentRow.AddChild(row);
            }

            if (printer.Settings.GetValue <double>(SettingsKey.layer_height) < printer.Settings.GetValue <double>(SettingsKey.nozzle_diameter) / 2)
            {
                // The layer height is very small and it will be hard to see features. Show a warning.
                AddSettingsRow("The calibration object will printer better if the layer hight is set to a larger value. It is recommended that your increase it.".Localize(), SettingsKey.layer_height);
            }

            if (printer.Settings.GetValue <bool>(SettingsKey.create_raft))
            {
                // The layer height is very small and it will be hard to see features. Show a warning.
                AddSettingsRow("A raft is not needed for the calibration object. It is recommended that you turn it off.".Localize(), SettingsKey.create_raft);
            }

            this.NextButton.Visible = false;

            // add in the option to tell the system the printer is already calibrated
            var alreadyCalibratedButton = theme.CreateDialogButton("Already Calibrated".Localize());

            alreadyCalibratedButton.Name   = "Already Calibrated Button";
            alreadyCalibratedButton.Click += (s, e) =>
            {
                printer.Settings.SetValue(SettingsKey.xy_offsets_have_been_calibrated, "1");
                this.FinishWizard();
            };

            this.AddPageAction(alreadyCalibratedButton);

            var startCalibrationPrint = theme.CreateDialogButton("Start Print".Localize());

            startCalibrationPrint.Name   = "Start Calibration Print";
            startCalibrationPrint.Click += async(s, e) =>
            {
                await PrintCalibrationPart(calibrationWizard);
            };

            this.AcceptButton = startCalibrationPrint;

            this.AddPageAction(startCalibrationPrint);
        }
Beispiel #7
0
        public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme)
            : base(theme)
        {
            this.printer         = printer;
            this.DrawArrow       = true;
            this.BackgroundColor = theme.ToolbarButtonBackground;
            this.HoverColor      = theme.ToolbarButtonHover;
            this.MouseDownColor  = theme.ToolbarButtonDown;
            this.Name            = "PrintPopupMenu";
            this.HAnchor         = HAnchor.Fit;
            this.VAnchor         = VAnchor.Fit;

            settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            this.DynamicPopupContent = () =>
            {
                var menuTheme = ApplicationController.Instance.MenuTheme;

                int tabIndex = 0;

                allUiFields.Clear();

                var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Padding         = 10,
                    BackgroundColor = menuTheme.Colors.PrimaryBackgroundColor
                };

                column.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.Colors.PrimaryTextColor)
                {
                    HAnchor = HAnchor.Left
                });

                var optionsPanel = new IgnoredFlowLayout()
                {
                    Name        = "PrintPopupMenu Panel",
                    HAnchor     = HAnchor.Fit | HAnchor.Left,
                    VAnchor     = VAnchor.Fit,
                    Padding     = 5,
                    MinimumSize = new Vector2(400, 65),
                    Margin      = new BorderDouble(top: 10),
                };
                column.AddChild(optionsPanel);

                foreach (var key in new[] { "layer_height", "fill_density", "support_material", "create_raft" })
                {
                    var settingsData = SettingsOrganizer.Instance.GetSettingsData(key);
                    var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

                    SliceSettingsRow.AddBordersToEditFields(row);

                    optionsPanel.AddChild(row);
                }

                var subPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);

                var sectionWidget = new SectionWidget("Advanced", subPanel, menuTheme, expanded: true)
                {
                    Name    = "Advanced Section",
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit,
                    Margin  = 0
                };
                column.AddChild(sectionWidget);

                bool anySettingOverridden = false;
                anySettingOverridden |= printer.Settings.GetValue <bool>(SettingsKey.spiral_vase);
                anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause));

                sectionWidget.Load += (s, e) =>
                {
                    sectionWidget.Checkbox.Checked = anySettingOverridden;
                };

                foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause })
                {
                    var settingsData = SettingsOrganizer.Instance.GetSettingsData(key);
                    var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

                    SliceSettingsRow.AddBordersToEditFields(row);

                    subPanel.AddChild(row);
                }

                theme.ApplyBoxStyle(sectionWidget);

                sectionWidget.Margin = new BorderDouble(0, 10);
                sectionWidget.ContentPanel.Children <SettingsRow>().First().Border = new BorderDouble(0, 1);
                sectionWidget.ContentPanel.Children <SettingsRow>().Last().Border  = 0;

                var button = new TextButton("Start Print".Localize(), menuTheme)
                {
                    Name    = "Start Print Button",
                    HAnchor = HAnchor.Right,
                    VAnchor = VAnchor.Absolute,
                };
                button.Click += (s, e) =>
                {
                    // Exit if the bed is not GCode and the bed has no printable items
                    if ((printer.Bed.EditContext.SourceItem as ILibraryAsset)?.ContentType != "gcode" &&
                        !printer.PrintableItems(printer.Bed.EditContext.Content).Any())
                    {
                        return;
                    }

                    UiThread.RunOnIdle(async() =>
                    {
                        // Save any pending changes before starting print operation
                        await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges);

                        await ApplicationController.Instance.PrintPart(
                            printer.Bed.EditContext,
                            printer,
                            null,
                            CancellationToken.None);
                    });
                };
                column.AddChild(button);

                theme.ApplyPrimaryActionStyle(button);

                return(column);
            };

            this.AddChild(new TextButton("Print".Localize(), theme)
            {
                Selectable = false,
                Padding    = theme.TextButtonPadding.Clone(right: 5)
            });

            PrinterSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                if (e is StringEventArgs stringEvent)
                {
                    string settingsKey = stringEvent.Data;
                    if (allUiFields.TryGetValue(settingsKey, out UIField uifield))
                    {
                        string currentValue = settingsContext.GetValue(settingsKey);
                        if (uifield.Value != currentValue ||
                            settingsKey == "com_port")
                        {
                            uifield.SetValue(
                                currentValue,
                                userInitiated: false);
                        }
                    }
                }
            },
                                                         ref unregisterEvents);
        }
Beispiel #8
0
        private GuiWidget GetPopupContent(ThemeConfig theme)
        {
            var widget = new IgnoredPopupWidget()
            {
                Width           = 300,
                HAnchor         = HAnchor.Absolute,
                VAnchor         = VAnchor.Fit,
                BackgroundColor = theme.Colors.PrimaryBackgroundColor,
                Padding         = new BorderDouble(12, 0)
            };

            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Top,
            };

            widget.AddChild(container);

            GuiWidget hotendRow;

            container.AddChild(hotendRow = new SettingsItem(
                                   "Heated Bed".Localize(),
                                   theme,
                                   new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = false,
                ToggleAction = (itemChecked) =>
                {
                    var goalTemp = itemChecked ? printer.Settings.GetValue <double>(SettingsKey.bed_temperature) : 0;

                    if (itemChecked)
                    {
                        SetTargetTemperature(goalTemp);
                    }
                    else
                    {
                        SetTargetTemperature(0);
                    }
                }
            },
                                   enforceGutter: false));

            var toggleWidget = hotendRow.Children.Where(o => o is ICheckbox).FirstOrDefault();

            toggleWidget.Name = "Toggle Heater";

            heatToggle = toggleWidget as ICheckbox;

            int tabIndex        = 0;
            var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            var settingsData   = SettingsOrganizer.Instance.GetSettingsData(SettingsKey.bed_temperature);
            var temperatureRow = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex);

            SliceSettingsRow.AddBordersToEditFields(temperatureRow);
            container.AddChild(temperatureRow);

            alwaysEnabled.Add(hotendRow);

            // add in the temp graph
            var graph = new DataViewGraph()
            {
                DynamiclyScaleRange = false,
                MinValue            = 0,
                ShowGoal            = true,
                GoalColor           = ActiveTheme.Instance.PrimaryAccentColor,
                GoalValue           = printer.Settings.GetValue <double>(SettingsKey.bed_temperature),
                MaxValue            = 150,   // could come from some profile value in the future
                Width  = widget.Width - 20,
                Height = 35,                 // this works better if it is a common multiple of the Width
                Margin = new BorderDouble(0, 5, 0, 0),
            };

            var runningInterval = UiThread.SetInterval(() =>
            {
                graph.AddData(this.ActualTemperature);
            }, 1);

            this.Closed += (s, e) => runningInterval.Continue = false;

            var valueField  = temperatureRow.Descendants <MHNumberEdit>().FirstOrDefault();
            var settingsRow = temperatureRow.DescendantsAndSelf <SliceSettingsRow>().FirstOrDefault();

            ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                if (e is StringEventArgs stringEvent)
                {
                    var temp         = printer.Settings.GetValue <double>(SettingsKey.bed_temperature);
                    valueField.Value = temp;
                    graph.GoalValue  = temp;
                    settingsRow.UpdateStyle();
                    if (stringEvent.Data == SettingsKey.bed_temperature &&
                        heatToggle.Checked)
                    {
                        SetTargetTemperature(temp);
                    }
                }
                ;
            }, ref unregisterEvents);

            container.AddChild(graph);

            return(widget);
        }
        private async void AddUpgradeInfoPannel(GuiWidget generalPanel)
        {
            var make    = printer.Settings.GetValue(SettingsKey.make);
            var model   = printer.Settings.GetValue(SettingsKey.model);
            var message = $"The default settings for the {make} {model} have been updated.";

            message += "\nBelow you can find a list of each setting that has changed.".Localize();
            message += "\nUpdating a default setting will not change any override that you have applied.".Localize();
            generalPanel.AddChild(new WrappedTextWidget(message, pointSize: 11)
            {
                Margin    = new BorderDouble(5, 15),
                TextColor = theme.TextColor
            });

            int tabIndex = 0;

            var serverOemSettings = await ProfileManager.LoadOemSettingsAsync(OemSettings.Instance.OemProfiles[make][model],
                                                                              make,
                                                                              model);

            var oemPrinter = new PrinterConfig(serverOemSettings);

            foreach (var setting in ProfileManager.GetOemSettingsNeedingUpdate(printer))
            {
                void AddSetting(PrinterConfig printer, string description, string key, Color overlay)
                {
                    generalPanel.AddChild(new TextWidget(description, pointSize: 11)
                    {
                        // HAnchor = HAnchor.Center,
                        Margin    = new BorderDouble(5),
                        TextColor = theme.TextColor
                    });

                    var under = new GuiWidget()
                    {
                        HAnchor = HAnchor.Stretch,
                        VAnchor = VAnchor.Fit
                    };
                    var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
                    {
                        HAnchor = HAnchor.Stretch
                    };

                    var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.OEMSettings);

                    topToBottom.AddChild(SliceSettingsTabView.CreateItemRow(
                                             PrinterSettings.SettingsData[key],
                                             settingsContext,
                                             printer,
                                             theme,
                                             ref tabIndex));
                    var cover = new GuiWidget()
                    {
                        BackgroundColor = overlay,
                        HAnchor         = HAnchor.Stretch,
                        VAnchor         = VAnchor.Stretch
                    };

                    generalPanel.AddChild(under).AddChild(topToBottom);
                    under.AddChild(cover);
                }

                var currentText = "Current Default".Localize();
                var settingData = PrinterSettings.SettingsData[setting.key];
                var group       = settingData.OrganizerGroup;
                var category    = group.Category;

                currentText += ": " + category.Name + " > " + group.Name + " > " + settingData.PresentationName;

                AddSetting(printer, currentText, setting.key, theme.SlightShade);
                AddSetting(oemPrinter, "Will be updated to:".Localize(), setting.key, Color.Transparent);

                var buttonContainer = new FlowLayoutWidget(FlowDirection.RightToLeft)
                {
                    HAnchor     = HAnchor.Stretch,
                    Margin      = new BorderDouble(0, 25, 0, 3),
                    Border      = new BorderDouble(0, 1, 0, 0),
                    BorderColor = theme.MinimalShade,
                };

                generalPanel.AddChild(buttonContainer);
                var updateButton = new TextButton("Update Setting".Localize(), theme)
                {
                    Margin = new BorderDouble(0, 3, 20, 0),
                    Name   = setting.key + " Update",
                };

                theme.ApplyPrimaryActionStyle(updateButton);

                buttonContainer.AddChild(updateButton);

                updateButton.Click += (s, e) =>
                {
                    var scrollAmount = this.contentRow.Descendants <ScrollableWidget>().First().ScrollPositionFromTop;
                    printer.Settings.SetValue(setting.key, setting.newValue, printer.Settings.OemLayer);
                    AddAllContent();
                    UiThread.RunOnIdle(() =>
                    {
                        this.contentRow.Descendants <ScrollableWidget>().First().ScrollPositionFromTop = scrollAmount;
                    });
                };
            }
        }
        public ExportSlaPopupMenu(PrinterConfig printer, ThemeConfig theme)
            : base(theme)
        {
            this.printer         = printer;
            this.DrawArrow       = true;
            this.BackgroundColor = theme.ToolbarButtonBackground;
            this.HoverColor      = theme.ToolbarButtonHover;
            this.MouseDownColor  = theme.ToolbarButtonDown;
            this.Name            = "ExportSlaPopupMenu";
            this.HAnchor         = HAnchor.Fit;
            this.VAnchor         = VAnchor.Fit;

            settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            this.PopupHAnchor   = HAnchor.Fit;
            this.PopupVAnchor   = VAnchor.Fit;
            this.MakeScrollable = false;

            this.DynamicPopupContent = () =>
            {
                var menuTheme = ApplicationController.Instance.MenuTheme;

                int tabIndex = 0;

                allUiFields.Clear();

                var exportPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Padding         = theme.DefaultContainerPadding,
                    BackgroundColor = menuTheme.BackgroundColor
                };

                exportPanel.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.TextColor, pointSize: theme.DefaultFontSize)
                {
                    HAnchor = HAnchor.Left
                });

                var optionsPanel = new IgnoredFlowLayout()
                {
                    Name        = "ExportSlaPopupMenu Panel",
                    HAnchor     = HAnchor.Fit | HAnchor.Left,
                    VAnchor     = VAnchor.Fit,
                    Padding     = 5,
                    MinimumSize = new Vector2(400 * GuiWidget.DeviceScale, 65 * GuiWidget.DeviceScale),
                };
                exportPanel.AddChild(optionsPanel);

                var settingsToAdd = new[]
                {
                    SettingsKey.sla_layer_height,
                    SettingsKey.sla_create_raft,
                    SettingsKey.sla_auto_support
                };

                foreach (var key in settingsToAdd)
                {
                    var settingsData = PrinterSettings.SettingsData[key];
                    var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

                    if (row is SliceSettingsRow settingsRow)
                    {
                        settingsRow.ArrowDirection = ArrowDirection.Left;
                    }

                    optionsPanel.AddChild(row);
                }

                // add the export print button
                var setupRow = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.Stretch
                };

                // Perform validation before popup
                var errors = printer.Validate();

                var hasErrors   = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error);
                var hasWarnings = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Warning &&
                                             UserSettings.Instance.get($"Ignore_{e.ID}") != "true");

                var hasErrorsOrWarnings = hasErrors || hasWarnings;
                if (hasErrorsOrWarnings)
                {
                    string label = hasErrors ? "Action Required".Localize() : "Action Recommended".Localize();

                    setupRow.AddChild(new TextWidget(label, textColor: hasErrors ? Color.Red : theme.PrimaryAccentColor, pointSize: theme.DefaultFontSize)
                    {
                        VAnchor = VAnchor.Bottom,
                        AutoExpandBoundsToText = true,
                    });
                }

                setupRow.AddChild(new HorizontalSpacer());

                // Export button {{
                var exportPlugins = PluginFinder.CreateInstancesOf <IExportPlugin>();
                // set target as SLA export
                var targetPluginType = typeof(GCodeExport);

                // Find the first export plugin with the target type
                if (exportPlugins.FirstOrDefault(p => p.GetType() == targetPluginType) is IExportPlugin exportPlugin)
                {
                    string exportType = "Export Photon File".Localize();

                    exportPlugin.Initialize(printer);

                    var exportButton = menuTheme.CreateDialogButton("Export".Localize());
                    theme.ApplyPrimaryActionStyle(exportButton);

                    exportButton.Name        = "Export SLA Button";
                    exportButton.Enabled     = exportPlugin.Enabled;
                    exportButton.ToolTipText = exportPlugin.Enabled ? exportType : exportPlugin.DisabledReason;

                    exportButton.Click += (s, e) =>
                    {
                        this.CloseMenu();
                        ExportPrintItemPage.DoExport(
                            new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
                            printer,
                            exportPlugin);
                    };

                    setupRow.AddChild(exportButton);
                }

                // Export button

                exportPanel.AddChild(setupRow);

                if (hasErrorsOrWarnings)
                {
                    var errorsPanel = new ValidationErrorsPanel(errors, menuTheme);

                    // Conditional layout for right or bottom errors panel alignment
                    var layoutStyle = FlowDirection.TopToBottom;

                    if (layoutStyle == FlowDirection.LeftToRight)
                    {
                        errorsPanel.HAnchor         = HAnchor.Absolute;
                        errorsPanel.VAnchor         = VAnchor.Fit | VAnchor.Top;
                        errorsPanel.BackgroundColor = theme.ResolveColor(menuTheme.BackgroundColor, theme.PrimaryAccentColor.WithAlpha(30));
                        errorsPanel.Width           = 350;

                        errorsPanel.Load += (s, e) =>
                        {
                            errorsPanel.Parent.BackgroundColor = Color.Transparent;
                        };
                    }
                    else
                    {
                        errorsPanel.HAnchor = HAnchor.Stretch;
                        errorsPanel.VAnchor = VAnchor.Fit;
                        errorsPanel.Margin  = 3;
                    }

                    // Instead of the typical case where the print panel is returned, wrap and append validation errors panel
                    var errorsContainer = new FlowLayoutWidget(layoutStyle)
                    {
                        HAnchor         = HAnchor.Fit,
                        VAnchor         = VAnchor.Fit,
                        BackgroundColor = layoutStyle == FlowDirection.TopToBottom ? exportPanel.BackgroundColor : Color.Transparent
                    };

                    // Clear bottom padding
                    exportPanel.Padding = exportPanel.Padding.Clone(bottom: 2);

                    errorsContainer.AddChild(exportPanel);
                    errorsContainer.AddChild(errorsPanel);

                    return(errorsContainer);
                }

                return(exportPanel);
            };

            this.AddChild(new TextButton("Export".Localize(), theme)
            {
                Selectable = false,
                Padding    = theme.TextButtonPadding.Clone(right: 5)
            });
        }