public static void SlideToNewState(this RadioIconButton widget, RadioIconButton newActiveButton, OverflowBar parent, Action animationComplete, ThemeConfig theme)
        {
            double displayTime = 600;
            double elapsedMs   = 0;

            var box = new GuiWidget()
            {
                HAnchor                = HAnchor.Absolute,
                VAnchor                = VAnchor.Absolute,
                Position               = widget.Position + new VectorMath.Vector2(widget.Margin.Width, widget.Margin.Height),
                Size                   = widget.Size,
                BackgroundColor        = theme.AccentMimimalOverlay,
                BackgroundRadius       = theme.ButtonRadius,
                BackgroundOutlineWidth = 1,
                BorderColor            = theme.PrimaryAccentColor
            };

            parent.AddChildDirect(box);

            var startX    = box.Position.X;
            var startY    = box.Position.Y;
            var xdistance = (newActiveButton.Position.X + newActiveButton.Margin.Width) - startX;
            var direction = xdistance > 0 ? 1 : -1;
            var startedMS = UiThread.CurrentTimerMs;

            var animation = new Animation()
            {
                DrawTarget      = widget,
                FramesPerSecond = 20,
            };

            animation.Update += (s1, updateEvent) =>
            {
                elapsedMs = UiThread.CurrentTimerMs - startedMS;
                if (elapsedMs < (displayTime + 300))
                {
                    var    ratio = Math.Min(1, elapsedMs / displayTime);
                    double blend = Easing.Cubic.In(ratio);
                    box.Position = new VectorMath.Vector2(startX + (xdistance * blend), startY);

                    // Console.WriteLine("Ms: {0}, Ratio: {1}, Easing: {2}, Position: {3}", elapsedMs, ratio, blend, box.Position);
                    box.Invalidate();
                }
                else
                {
                    animation.Stop();

                    animationComplete?.Invoke();

                    UiThread.RunOnIdle(box.Close, .3);
                }
            };

            animation.Start();
        }
Exemple #2
0
        public GCodeOptionsPanel(BedConfig sceneContext, PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            gcodeOptions = sceneContext.RendererOptions;

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

            var buttonGroup = new ObservableCollection <GuiWidget>();

            speedsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("speeds.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Speeds Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Speeds",
                ToolTipText = "Show Speeds".Localize(),
                Margin      = theme.ButtonSpacing
            };
            speedsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(speedsButton);

            buttonPanel.AddChild(speedsButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("materials.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Materials Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Materials",
                ToolTipText = "Show Materials".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Color Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "None",
                ToolTipText = "No Color".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Color View".Localize(),
                    theme,
                    optionalControls: buttonPanel,
                    enforceGutter: false));

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

            // Reset to new button group
            buttonGroup = new ObservableCollection <GuiWidget>();

            solidButton = new RadioIconButton(AggContext.StaticData.LoadIcon("solid.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Solid Button",
                Checked     = gcodeOptions.GCodeModelView == "Semi-Transparent",
                ToolTipText = "Show Semi-Transparent Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            solidButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(solidButton);

            buttonPanel.AddChild(solidButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("wireframe.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Wireframe Button",
                Checked     = gcodeOptions.GCodeModelView == "Wireframe",
                ToolTipText = "Show Wireframe Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Model Button",
                Checked     = gcodeOptions.GCodeModelView == "None",
                ToolTipText = "No Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Model View".Localize(),
                    buttonPanel,
                    theme,
                    enforceGutter: false));

            gcodeOptions = sceneContext.RendererOptions;

            var viewOptions = sceneContext.GetBaseViewOptions();

            viewOptions.AddRange(new[]
            {
                new BoolOption(
                    "Moves".Localize(),
                    () => gcodeOptions.RenderMoves,
                    (value) => gcodeOptions.RenderMoves = value),
                new BoolOption(
                    "Retractions".Localize(),
                    () => gcodeOptions.RenderRetractions,
                    (value) => gcodeOptions.RenderRetractions = value),
                new BoolOption(
                    "Extrusion".Localize(),
                    () => gcodeOptions.SimulateExtrusion,
                    (value) => gcodeOptions.SimulateExtrusion = value),
                new BoolOption(
                    "Transparent".Localize(),
                    () => gcodeOptions.TransparentExtrusion,
                    (value) => gcodeOptions.TransparentExtrusion = value),
                new BoolOption(
                    "Hide Offsets".Localize(),
                    () => gcodeOptions.HideExtruderOffsets,
                    (value) => gcodeOptions.HideExtruderOffsets = value,
                    () => printer.Settings.GetValue <int>(SettingsKey.extruder_count) > 1),
                new BoolOption(
                    "Sync To Print".Localize(),
                    () => gcodeOptions.SyncToPrint,
                    (value) =>
                {
                    gcodeOptions.SyncToPrint = value;
                    if (!gcodeOptions.SyncToPrint)
                    {
                        // If we are turning off sync to print, set the slider to full.
                        //layerRenderRatioSlider.SecondValue = 1;
                    }
                })
            });

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

            this.AddChild(optionsContainer);

            void BuildMenu()
            {
                foreach (var option in viewOptions.Where(option => option.IsVisible()))
                {
                    var settingsItem = new SettingsItem(
                        option.Title,
                        theme,
                        new SettingsItem.ToggleSwitchConfig()
                    {
                        Name         = option.Title + " Toggle",
                        Checked      = option.IsChecked(),
                        ToggleAction = option.SetValue
                    },
                        enforceGutter: false);

                    settingsItem.Padding = settingsItem.Padding.Clone(right: 8);

                    optionsContainer.AddChild(settingsItem);
                }
            }

            BuildMenu();

            PropertyChangedEventHandler syncProperties = (s, e) =>
            {
                if (e.PropertyName == nameof(gcodeOptions.RenderBed) ||
                    e.PropertyName == nameof(gcodeOptions.RenderBuildVolume))
                {
                    optionsContainer.CloseAllChildren();
                    BuildMenu();
                }
            };

            gcodeOptions.PropertyChanged += syncProperties;

            optionsContainer.Closed += (s, e) =>
            {
                gcodeOptions.PropertyChanged -= syncProperties;
            };
        }
Exemple #3
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);
            }
        }
        public ViewControls3D(PartWorkspace workspace, ThemeConfig theme, UndoBuffer undoBuffer, bool isPrinterType, bool showPrintButton)
            : base(theme)
        {
            this.theme             = theme;
            this.undoBuffer        = undoBuffer;
            this.ActionArea.Click += (s, e) =>
            {
                view3DWidget.Object3DControlLayer.Focus();
            };

            this.OverflowButton.ToolTipText = "Tool Bar Overflow".Localize();

            this.OverflowButton.DynamicPopupContent = () =>
            {
                bool IncludeInMenu(SceneOperation operation)
                {
                    foreach (var widget in this.ActionArea.Children.Where(c => !c.Visible && !ignoredInMenuTypes.Contains(c.GetType())))
                    {
                        if (operationButtons.TryGetValue(widget, out SceneOperation buttonOperation) &&
                            buttonOperation == operation)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }

                return(SceneOperations.GetToolbarOverflowMenu(AppContext.MenuTheme, sceneContext, IncludeInMenu));
            };

            this.IsPrinterMode = isPrinterType;
            this.sceneContext  = workspace.SceneContext;
            this.workspace     = workspace;

            string iconPath;

            this.AddChild(CreateAddButton(sceneContext, theme));

            this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));

            bedMenuButton = new PopupMenuButton(StaticData.Instance.LoadIcon("bed.png", 16, 16, theme.InvertIcons), theme)
            {
                Name        = "Bed Options Menu",
                ToolTipText = "Bed",
                Enabled     = true,
                Margin      = theme.ButtonSpacing,
                VAnchor     = VAnchor.Center,
                DrawArrow   = true
            };

            this.AddChild(bedMenuButton);

            this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));

            this.AddChild(CreateOpenButton(theme));

            this.AddChild(CreateSaveButton(theme));

            this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));

            undoButton = new IconButton(StaticData.Instance.LoadIcon("Undo_grey_16x.png", 16, 16, theme.InvertIcons), theme)
            {
                Name        = "3D View Undo",
                ToolTipText = "Undo".Localize(),
                Enabled     = false,
                Margin      = theme.ButtonSpacing,
                VAnchor     = VAnchor.Center
            };
            undoButton.Click += (sender, e) =>
            {
                sceneContext.Scene.Undo();
                view3DWidget.Object3DControlLayer.Focus();
            };
            this.AddChild(undoButton);

            redoButton = new IconButton(StaticData.Instance.LoadIcon("Redo_grey_16x.png", 16, 16, theme.InvertIcons), theme)
            {
                Name        = "3D View Redo",
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Redo".Localize(),
                Enabled     = false,
                VAnchor     = VAnchor.Center
            };
            redoButton.Click += (sender, e) =>
            {
                sceneContext.Scene.Redo();
                view3DWidget.Object3DControlLayer.Focus();
            };
            this.AddChild(redoButton);

            if (showPrintButton)
            {
                var printButton = new TextButton("Print", theme)
                {
                    Name            = "Print Button",
                    BackgroundColor = theme.AccentMimimalOverlay
                };
                printButton.Click += (s, e) =>
                {
                    view3DWidget.PushToPrinterAndPrint();
                };
                this.AddChild(printButton);
            }

            this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));

            undoButton.Enabled = undoBuffer.UndoCount > 0;
            redoButton.Enabled = undoBuffer.RedoCount > 0;

            var buttonGroupA = new ObservableCollection <GuiWidget>();

            if (UserSettings.Instance.IsTouchScreen)
            {
                iconPath     = Path.Combine("ViewTransformControls", "rotate.png");
                rotateButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Rotate (Alt + Left Mouse)".Localize(),
                    Margin = theme.ButtonSpacing
                };
                rotateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Rotate;
                buttonGroupA.Add(rotateButton);
                AddChild(rotateButton);

                iconPath        = Path.Combine("ViewTransformControls", "translate.png");
                translateButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Move (Shift + Left Mouse)".Localize(),
                    Margin = theme.ButtonSpacing
                };
                translateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Translate;
                buttonGroupA.Add(translateButton);
                AddChild(translateButton);

                iconPath    = Path.Combine("ViewTransformControls", "scale.png");
                scaleButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Zoom (Ctrl + Left Mouse)".Localize(),
                    Margin = theme.ButtonSpacing
                };
                scaleButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Scale;
                buttonGroupA.Add(scaleButton);
                AddChild(scaleButton);

                rotateButton.Checked = true;

                // Add vertical separator
                this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));

                iconPath         = Path.Combine("ViewTransformControls", "partSelect.png");
                partSelectButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Select Part".Localize(),
                    Margin = theme.ButtonSpacing
                };
                partSelectButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.PartSelect;
                buttonGroupA.Add(partSelectButton);
                AddChild(partSelectButton);
            }

            operationButtons = new Dictionary <GuiWidget, SceneOperation>();

            // Add Selected IObject3D -> Operations to toolbar
            foreach (var namedAction in SceneOperations.All)
            {
                if (namedAction is SceneSelectionSeparator)
                {
                    this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));
                    continue;
                }

                // add the create support before the align
                if (namedAction is OperationGroup group &&
                    group.Id == "Transform")
                {
                    this.AddChild(CreateSupportButton(theme));
                    this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));
                }

                GuiWidget button = null;

                if (namedAction is OperationGroup operationGroup)
                {
                    if (operationGroup.Collapse)
                    {
                        var defaultOperation = operationGroup.GetDefaultOperation();

                        PopupMenuButton groupButton = null;

                        groupButton = theme.CreateSplitButton(
                            new SplitButtonParams()
                        {
                            Icon          = defaultOperation.Icon(theme.InvertIcons),
                            DefaultAction = (menuButton) =>
                            {
                                defaultOperation.Action.Invoke(sceneContext);
                            },
                            DefaultActionTooltip = defaultOperation.HelpText ?? defaultOperation.Title,
                            ButtonName           = defaultOperation.Title,
                            ExtendPopupMenu      = (PopupMenu popupMenu) =>
                            {
                                foreach (var operation in operationGroup.Operations)
                                {
                                    var operationMenu = popupMenu.CreateMenuItem(operation.Title, operation.Icon?.Invoke(theme.InvertIcons));

                                    operationMenu.Enabled     = operation.IsEnabled(sceneContext);
                                    operationMenu.ToolTipText = operation.Title;

                                    if (!operationMenu.Enabled &&
                                        !string.IsNullOrEmpty(operation.HelpText))
                                    {
                                        operationMenu.ToolTipText += "\n\n" + operation.HelpText;
                                    }

                                    operationMenu.Click += (s, e) => UiThread.RunOnIdle(() =>
                                    {
                                        if (defaultOperation != operation)
                                        {
                                            // Update button
                                            var iconButton = groupButton.Children.OfType <IconButton>().First();
                                            iconButton.SetIcon(operation.Icon(theme.InvertIcons));
                                            iconButton.ToolTipText = operation.HelpText ?? operation.Title;

                                            UserSettings.Instance.set(operationGroup.GroupRecordId, operationGroup.Operations.IndexOf(operation).ToString());

                                            defaultOperation = operation;

                                            iconButton.Invalidate();
                                        }

                                        operation.Action?.Invoke(sceneContext);
                                    });
                                }
                            }
                        },
                            operationGroup);

                        button = groupButton;
                    }
                    else
                    {
                        if (!(this.ActionArea.Children.LastOrDefault() is ToolbarSeparator))
                        {
                            this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));
                        }

                        foreach (var operation in operationGroup.Operations)
                        {
                            var operationButton = new OperationIconButton(operation, sceneContext, theme);
                            operationButtons.Add(operationButton, operation);

                            this.AddChild(operationButton);
                        }

                        this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));
                    }
                }
                else if (namedAction.Icon != null)
                {
                    button = new IconButton(namedAction.Icon(theme.InvertIcons), theme)
                    {
                        Name            = namedAction.Title + " Button",
                        ToolTipText     = namedAction.Title,
                        Margin          = theme.ButtonSpacing,
                        BackgroundColor = theme.ToolbarButtonBackground,
                        HoverColor      = theme.ToolbarButtonHover,
                        MouseDownColor  = theme.ToolbarButtonDown,
                    };
                }
                else
                {
                    button = new TextButton(namedAction.Title, theme)
                    {
                        Name            = namedAction.Title + " Button",
                        Margin          = theme.ButtonSpacing,
                        BackgroundColor = theme.ToolbarButtonBackground,
                        HoverColor      = theme.ToolbarButtonHover,
                        MouseDownColor  = theme.ToolbarButtonDown,
                    };
                }

                if (button != null)
                {
                    operationButtons.Add(button, namedAction);

                    // Only bind Click event if not a SplitButton
                    if (!(button is PopupMenuButton))
                    {
                        button.Click += (s, e) => UiThread.RunOnIdle(() =>
                        {
                            namedAction.Action.Invoke(sceneContext);
                            var partTab = button.Parents <PartTabPage>().FirstOrDefault();
                            var view3D  = partTab.Descendants <View3DWidget>().FirstOrDefault();
                            view3D.Object3DControlLayer.Focus();
                        });
                    }

                    this.AddChild(button);
                }
            }

            // Register listeners
            undoBuffer.Changed += UndoBuffer_Changed;
            sceneContext.Scene.SelectionChanged += UpdateToolbarButtons;
            sceneContext.Scene.ItemsModified    += UpdateToolbarButtons;

            // Run on load
            UpdateToolbarButtons(null, null);
        }
Exemple #5
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);
        }
Exemple #6
0
        public override void Initialize(int tabIndex)
        {
            // Enum keyed on name to friendly name
            var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
            {
                return(new
                {
                    Key = enumName,
                    Value = enumName.Replace('_', ' ')
                });
            });

            var iconsRow = new FlowLayoutWidget();

            int index           = 0;
            var radioButtonSize = new Vector2(iconsAttribute.Width, iconsAttribute.Height);

            foreach (var enumItem in enumItems)
            {
                var         localIndex = index;
                ImageBuffer iconImage  = null;
                var         iconPath   = iconsAttribute.IconPaths[localIndex];
                if (!string.IsNullOrWhiteSpace(iconPath))
                {
                    if (iconsAttribute.Width > 0)
                    {
                        iconImage = AggContext.StaticData.LoadIcon(iconPath, iconsAttribute.Width, iconsAttribute.Height);
                    }
                    else
                    {
                        iconImage = AggContext.StaticData.LoadIcon(iconPath);
                    }

                    var radioButton = new RadioIconButton(iconImage, theme)
                    {
                        ToolTipText = enumItem.Key
                    };

                    radioButtonSize = new Vector2(radioButton.Width, radioButton.Height);

                    // set it if checked
                    if (enumItem.Value == this.InitialValue)
                    {
                        radioButton.Checked = true;
                    }

                    iconsRow.AddChild(radioButton);

                    var localItem = enumItem;
                    radioButton.CheckedStateChanged += (s, e) =>
                    {
                        if (radioButton.Checked)
                        {
                            this.SetValue(localItem.Key, true);
                        }
                    };
                }
                else if (iconsAttribute.Width > 0)
                {
                    // hold the space of the empty icon
                    iconsRow.AddChild(new GuiWidget(radioButtonSize.X, radioButtonSize.Y));
                }

                index++;
            }

            this.Content = iconsRow;
        }
        public ModelOptionsPanel(BedConfig sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            var buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            var buttonGroup = new ObservableCollection <GuiWidget>();

            var shadedViewButton = new RadioIconButton(AggContext.StaticData.LoadIcon("view_shaded.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Shaded Button",
                Checked     = sceneContext.ViewState.RenderType == RenderTypes.Shaded,
                ToolTipText = "Shaded".Localize(),
                Margin      = theme.ButtonSpacing
            };

            shadedViewButton.Click += (s, e) => sceneContext.ViewState.RenderType = RenderTypes.Shaded;
            buttonGroup.Add(shadedViewButton);

            buttonPanel.AddChild(shadedViewButton);


            var outlinesViewButton = new RadioIconButton(AggContext.StaticData.LoadIcon("view_outlines.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Outlines Button",
                Checked     = sceneContext.ViewState.RenderType == RenderTypes.Outlines,
                ToolTipText = "Outlines".Localize(),
                Margin      = theme.ButtonSpacing
            };

            outlinesViewButton.Click += (s, e) => sceneContext.ViewState.RenderType = RenderTypes.Outlines;
            buttonGroup.Add(outlinesViewButton);

            buttonPanel.AddChild(outlinesViewButton);

            var polygonsViewButton = new RadioIconButton(AggContext.StaticData.LoadIcon("view_polygons.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Polygons Button",
                Checked     = sceneContext.ViewState.RenderType == RenderTypes.Polygons,
                ToolTipText = "Polygons".Localize(),
                Margin      = theme.ButtonSpacing
            };

            polygonsViewButton.Click += (s, e) => sceneContext.ViewState.RenderType = RenderTypes.Polygons;
            buttonGroup.Add(polygonsViewButton);

            buttonPanel.AddChild(polygonsViewButton);

            var materialsViewButton = new RadioIconButton(AggContext.StaticData.LoadIcon("view_materials.png"), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Materials Button",
                Checked     = sceneContext.ViewState.RenderType == RenderTypes.Materials,
                ToolTipText = "Materials".Localize(),
                Margin      = theme.ButtonSpacing
            };

            materialsViewButton.Click += (s, e) => sceneContext.ViewState.RenderType = RenderTypes.Materials;
            buttonGroup.Add(materialsViewButton);

            buttonPanel.AddChild(materialsViewButton);

            var overhangViewButton = new RadioIconButton(AggContext.StaticData.LoadIcon("view_overhang.png"), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Overhang Button",
                Checked     = sceneContext.ViewState.RenderType == RenderTypes.Overhang,
                ToolTipText = "Overhang".Localize(),
                Margin      = theme.ButtonSpacing
            };

            overhangViewButton.Click += (s, e) => sceneContext.ViewState.RenderType = RenderTypes.Overhang;
            buttonGroup.Add(overhangViewButton);

            buttonPanel.AddChild(overhangViewButton);

            this.AddChild(
                new SettingsItem(
                    "View Style".Localize(),
                    buttonPanel,
                    theme,
                    enforceGutter: false)
            {
                Border = 0
            });

            foreach (var option in sceneContext.GetBaseViewOptions())
            {
                if (option.IsVisible())
                {
                    this.AddChild(
                        new SettingsItem(
                            option.Title,
                            theme,
                            new SettingsItem.ToggleSwitchConfig()
                    {
                        Name         = option.Title + " Toggle",
                        Checked      = option.IsChecked(),
                        ToggleAction = option.SetValue
                    },
                            enforceGutter: false)
                        );
                }
            }
        }