Пример #1
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));
            this.AddChild(new PrintButton(printer, theme));

            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);

            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);

            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);

            this.AddChild(new HorizontalSpacer());

            bool shareTemp     = printer.Settings.GetValue <bool>(SettingsKey.extruders_share_temperature);
            int  extruderCount = shareTemp ? 1 : printer.Settings.GetValue <int>(SettingsKey.extruder_count);

            if (!printer.Settings.GetValue <bool>(SettingsKey.sla_printer))
            {
                for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
                {
                    this.AddChild(new TemperatureWidgetHotend(printer, extruderIndex, theme)
                    {
                        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) =>
            {
                RadioIconButton activeButton = null;
                if (e.ViewMode == PartViewMode.Layers2D)
                {
                    activeButton = layers2DButton;
                }
                else if (e.ViewMode == PartViewMode.Layers3D)
                {
                    activeButton = layers3DButton;
                }
                else
                {
                    activeButton = modelViewButton;
                }

                if (activeButton != null)
                {
                    activeButton.Checked = true;

                    if (!buttonIsBeingClicked)
                    {
                        activeButton.FlashBackground(theme.Colors.PrimaryAccentColor.WithContrast(theme.Colors.PrimaryTextColor, 6).ToColor());
                    }
                }
            };

            printer.Connection.ConnectionSucceeded.RegisterEvent((s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    PrintRecovery.CheckIfNeedToRecoverPrint(printer);
                });
            }, ref unregisterEvents);
        }