protected void SetButtonStates()
        {
            // If we don't have leveling data and we need it
            bool showSetupButton = PrintLevelingData.NeedsToBeRun(printer) ||
                                   ProbeCalibrationWizard.NeedsToBeRun(printer) ||
                                   LoadFilamentWizard.NeedsToBeRun(printer);

            switch (printer.Connection.CommunicationState)
            {
            case CommunicationStates.FinishedPrint:
            case CommunicationStates.Connected:
                if (showSetupButton)
                {
                    startPrintButton.Visible  = false;
                    finishSetupButton.Visible = true;
                    finishSetupButton.Enabled = true;
                    theme.ApplyPrimaryActionStyle(finishSetupButton);
                }
                else
                {
                    startPrintButton.Visible  = true;
                    startPrintButton.Enabled  = true;
                    finishSetupButton.Visible = false;
                    theme.ApplyPrimaryActionStyle(startPrintButton);
                }
                break;

            case CommunicationStates.PrintingFromSd:
            case CommunicationStates.Printing:
            case CommunicationStates.Paused:
            default:
                if (showSetupButton)
                {
                    startPrintButton.Visible  = false;
                    finishSetupButton.Visible = true;
                    finishSetupButton.Enabled = false;
                    theme.RemovePrimaryActionStyle(finishSetupButton);
                }
                else
                {
                    startPrintButton.Visible  = true;
                    startPrintButton.Enabled  = false;
                    finishSetupButton.Visible = false;
                    theme.RemovePrimaryActionStyle(startPrintButton);
                }
                break;
            }
        }
예제 #2
0
        public PrinterActionsBar(PrinterConfig printer, PrinterTabPage printerTabPage, ThemeConfig theme)
            : base(theme)
        {
            this.printer        = printer;
            this.printerTabPage = printerTabPage;

            this.HAnchor = HAnchor.Stretch;
            this.VAnchor = VAnchor.Fit;

            var defaultMargin = theme.ButtonSpacing;

            // add the reset button first (if there is one)
            if (printer.Settings.GetValue <bool>(SettingsKey.show_reset_connection))
            {
                var resetConnectionButton = new TextIconButton(
                    "Reset".Localize(),
                    AggContext.StaticData.LoadIcon("e_stop.png", 14, 14, theme.InvertIcons),
                    theme)
                {
                    ToolTipText = "Reboots the firmware on the controller".Localize(),
                    Margin      = defaultMargin
                };
                resetConnectionButton.Click += (s, e) =>
                {
                    UiThread.RunOnIdle(printer.Connection.RebootBoard);
                };
                this.AddChild(resetConnectionButton);
            }

            this.AddChild(new PrinterConnectButton(printer, theme));

            // add the start print button
            GuiWidget startPrintButton;

            this.AddChild(startPrintButton = new PrintPopupMenu(printer, theme)
            {
                Margin = theme.ButtonSpacing
            });

            void SetPrintButtonStyle(object s, EventArgs e)
            {
                switch (printer.Connection.CommunicationState)
                {
                case CommunicationStates.FinishedPrint:
                case CommunicationStates.Connected:
                    theme.ApplyPrimaryActionStyle(startPrintButton);
                    break;

                default:
                    theme.RemovePrimaryActionStyle(startPrintButton);
                    break;
                }
            }

            // make sure the buttons state is set correctly
            printer.Connection.CommunicationStateChanged += SetPrintButtonStyle;
            startPrintButton.Closed += (s, e) => printer.Connection.CommunicationStateChanged -= SetPrintButtonStyle;

            // and set the style right now
            SetPrintButtonStyle(this, null);

            this.AddChild(new SliceButton(printer, printerTabPage, theme)
            {
                Name   = "Generate Gcode Button",
                Margin = theme.ButtonSpacing,
            });

            // Add vertical separator
            this.AddChild(new ToolbarSeparator(theme)
            {
                VAnchor = VAnchor.Absolute,
                Height  = theme.ButtonHeight,
            });

            var buttonGroupB = new ObservableCollection <GuiWidget>();

            var iconPath = Path.Combine("ViewTransformControls", "model.png");

            modelViewButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 16, 16, theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroupB,
                Name        = "Model View Button",
                Checked     = printer?.ViewState.ViewMode == PartViewMode.Model || printer == null,
                ToolTipText = "Model View".Localize(),
                Margin      = theme.ButtonSpacing
            };
            modelViewButton.Click += SwitchModes_Click;
            buttonGroupB.Add(modelViewButton);
            AddChild(modelViewButton);

            viewModes.Add(PartViewMode.Model, modelViewButton);

            iconPath       = Path.Combine("ViewTransformControls", "gcode_3d.png");
            layers3DButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 16, 16, theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroupB,
                Name        = "Layers3D Button",
                Checked     = printer?.ViewState.ViewMode == PartViewMode.Layers3D,
                ToolTipText = "3D Layer View".Localize(),
                Margin      = theme.ButtonSpacing
            };
            layers3DButton.Click += SwitchModes_Click;
            buttonGroupB.Add(layers3DButton);

            viewModes.Add(PartViewMode.Layers3D, layers3DButton);

            if (!UserSettings.Instance.IsTouchScreen)
            {
                this.AddChild(layers3DButton);
            }

            iconPath       = Path.Combine("ViewTransformControls", "gcode_2d.png");
            layers2DButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 16, 16, theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroupB,
                Name        = "Layers2D Button",
                Checked     = printer?.ViewState.ViewMode == PartViewMode.Layers2D,
                ToolTipText = "2D Layer View".Localize(),
                Margin      = theme.ButtonSpacing,
            };
            layers2DButton.Click += SwitchModes_Click;
            buttonGroupB.Add(layers2DButton);
            this.AddChild(layers2DButton);

            viewModes.Add(PartViewMode.Layers2D, layers2DButton);

            this.AddChild(new HorizontalSpacer());

            int hotendCount = printer.Settings.Helpers.HotendCount();

            if (!printer.Settings.GetValue <bool>(SettingsKey.sla_printer))
            {
                for (int extruderIndex = 0; extruderIndex < hotendCount; extruderIndex++)
                {
                    this.AddChild(new TemperatureWidgetHotend(printer, extruderIndex, theme, hotendCount)
                    {
                        Margin = new BorderDouble(right: 10)
                    });
                }
            }

            if (printer.Settings.GetValue <bool>(SettingsKey.has_heated_bed))
            {
                this.AddChild(new TemperatureWidgetBed(printer, theme));
            }

            this.OverflowButton.Name = "Printer Overflow Menu";
            this.ExtendOverflowMenu  = (popupMenu) =>
            {
                this.GeneratePrinterOverflowMenu(popupMenu, ApplicationController.Instance.MenuTheme);
            };

            printer.ViewState.ViewModeChanged += (s, e) =>
            {
                if (viewModes[e.ViewMode] is RadioIconButton activeButton &&
                    viewModes[e.PreviousMode] is RadioIconButton previousButton &&
                    !buttonIsBeingClicked)
                {
                    // Show slide to animation from previous to current, on completion update view to current by setting active.Checked
                    previousButton.SlideToNewState(
                        activeButton,
                        this,
                        () =>
                    {
                        activeButton.Checked = true;
                    },
                        theme);
                }
            };

            // Register listeners
            printer.Connection.ConnectionSucceeded += CheckForPrintRecovery;

            // if we are already connected than check if there is a print recovery right now
            if (printer.Connection.CommunicationState == CommunicationStates.Connected)
            {
                CheckForPrintRecovery(null, null);
            }
        }