Exemplo n.º 1
0
        private FlowLayoutWidget GetMacroButtonContainer()
        {
            FLowLeftRightWithWrapping macroContainer = new FLowLeftRightWithWrapping();

            TextWidget noMacrosFound = new TextWidget("No macros are currently set up for this printer.".Localize(), pointSize: 10);

            noMacrosFound.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            macroContainer.AddChild(noMacrosFound);
            noMacrosFound.Visible = false;

            if (ActiveSliceSettings.Instance?.UserMacros().Any() != true)
            {
                noMacrosFound.Visible = true;
                return(macroContainer);
            }

            foreach (GCodeMacro macro in ActiveSliceSettings.Instance.UserMacros())
            {
                Button macroButton = textImageButtonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
                macroButton.Margin = new BorderDouble(right: 5);
                macroButton.Click += (s, e) => macro.Run();

                macroContainer.AddChild(macroButton);
            }

            macroContainer.Children.CollectionChanged += (s, e) =>
            {
                if (!this.HasBeenClosed)
                {
                    noMacrosFound.Visible = macroContainer.Children.Count == 0;
                }
            };

            return(macroContainer);
        }
Exemplo n.º 2
0
        private void Rebuild()
        {
            addedChildren.Clear();

            if (!printer.Settings.Macros.Any())
            {
                var noMacrosFound = new TextWidget("No macros are currently set up for this printer.".Localize(), pointSize: 10, textColor: theme.TextColor);
                this.AddChild(noMacrosFound);
            }
            else
            {
                foreach (GCodeMacro macro in printer.Settings.Macros)
                {
                    var macroButton = new TextButton(GCodeMacro.FixMacroName(macro.Name), theme)
                    {
                        BackgroundColor = theme.MinimalShade,
                        Margin          = new BorderDouble(right: 5)
                    };
                    macroButton.Click += (s, e) => macro.Run(printer.Connection);

                    addedChildren.Add(macroButton);
                }
            }

            DoWrappingLayout();
        }
Exemplo n.º 3
0
        private FlowLayoutWidget CreateMacroNameContainer()
        {
            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.Margin = new BorderDouble(0, 5);
            BorderDouble elementMargin = new BorderDouble(top: 3);

            string     macroNameLabelTxtFull = string.Format("{0}:", "Macro Name".Localize());
            TextWidget macroNameLabel        = new TextWidget(macroNameLabelTxtFull, 0, 0, 12);

            macroNameLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            macroNameLabel.HAnchor   = HAnchor.ParentLeftRight;
            macroNameLabel.Margin    = new BorderDouble(0, 0, 0, 1);

            macroNameInput         = new MHTextEditWidget(GCodeMacro.FixMacroName(windowController.ActiveMacro.Name));
            macroNameInput.HAnchor = HAnchor.ParentLeftRight;

            string giveMacroANameLabel     = "Give the macro a name".Localize();
            string giveMacroANameLabelFull = string.Format("{0}.", giveMacroANameLabel);

            macroNameError           = new TextWidget(giveMacroANameLabelFull, 0, 0, 10);
            macroNameError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            macroNameError.HAnchor   = HAnchor.ParentLeftRight;
            macroNameError.Margin    = elementMargin;

            container.AddChild(macroNameLabel);
            container.AddChild(macroNameInput);
            container.AddChild(macroNameError);
            container.HAnchor = HAnchor.ParentLeftRight;
            return(container);
        }
Exemplo n.º 4
0
 public void ChangeToMacroDetail(GCodeMacro macro)
 {
     this.ActiveMacro = macro;
     UiThread.RunOnIdle(() =>
     {
         this.RemoveAllChildren();
         this.AddChild(new MacroDetailWidget(this));
         this.Invalidate();
     });
 }
Exemplo n.º 5
0
        private void RebuildList(PrinterSettings printerSettings)
        {
            this.contentRow.CloseAllChildren();

            if (printerSettings?.Macros != null)
            {
                foreach (GCodeMacro macro in printerSettings.Macros)
                {
                    var macroRow = new FlowLayoutWidget
                    {
                        Margin  = new BorderDouble(3, 0, 3, 3),
                        HAnchor = HAnchor.Stretch,
                        Padding = new BorderDouble(3),
                    };

                    macroRow.AddChild(new TextWidget(GCodeMacro.FixMacroName(macro.Name), textColor: theme.TextColor));

                    macroRow.AddChild(new HorizontalSpacer());

                    // You can't use the foreach variable inside the lambda functions directly or it will always be the last item.
                    // We make a local variable to create a closure around it to ensure we get the correct instance
                    var localMacroReference = macro;

                    var editLink = new LinkLabel("edit".Localize(), theme)
                    {
                        Margin    = new BorderDouble(right: 5),
                        TextColor = theme.TextColor
                    };
                    editLink.Click += (s, e) =>
                    {
                        this.DialogWindow.ChangeToPage(
                            new MacroDetailPage(localMacroReference, printerSettings));
                    };
                    macroRow.AddChild(editLink);

                    var removeLink = new LinkLabel("remove".Localize(), theme)
                    {
                        TextColor = theme.TextColor
                    };
                    removeLink.Click += (sender, e) =>
                    {
                        printerSettings.Macros.Remove(localMacroReference);
                        printerSettings.Save();
                        printerSettings.NotifyMacrosChanged();
                        this.RebuildList(printerSettings);
                    };
                    macroRow.AddChild(removeLink);

                    contentRow.AddChild(macroRow);
                }
            }
        }
Exemplo n.º 6
0
        protected override IEnumerable <MenuItemAction> GetMenuActions()
        {
            var list = new List <MenuItemAction>();

            if (ActiveSliceSettings.Instance.ActionMacros().Any())
            {
                foreach (GCodeMacro macro in ActiveSliceSettings.Instance.ActionMacros())
                {
                    list.Add(new MenuItemAction(GCodeMacro.FixMacroName(macro.Name), macro.Run));
                }
            }

            return(list);
        }
Exemplo n.º 7
0
        private void RebuildList(PrinterSettings printerSettings, LinkButtonFactory linkButtonFactory)
        {
            this.contentRow.CloseAllChildren();

            if (printerSettings?.Macros != null)
            {
                foreach (GCodeMacro macro in printerSettings.Macros)
                {
                    var macroRow = new FlowLayoutWidget
                    {
                        Margin          = new BorderDouble(3, 0, 3, 3),
                        HAnchor         = HAnchor.Stretch,
                        Padding         = new BorderDouble(3),
                        BackgroundColor = Color.White
                    };

                    macroRow.AddChild(new TextWidget(GCodeMacro.FixMacroName(macro.Name)));

                    macroRow.AddChild(new HorizontalSpacer());

                    // You can't use the foreach variable inside the lambda functions directly or it will always be the last item.
                    // We make a local variable to create a closure around it to ensure we get the correct instance
                    var localMacroReference = macro;

                    var oldColor = linkButtonFactory.textColor;
                    linkButtonFactory.textColor = Color.Black;
                    Button editLink = linkButtonFactory.Generate("edit".Localize());
                    editLink.Margin = new BorderDouble(right: 5);
                    editLink.Click += (s, e) =>
                    {
                        this.DialogWindow.ChangeToPage(
                            new MacroDetailPage(localMacroReference, printerSettings));
                    };
                    macroRow.AddChild(editLink);

                    Button removeLink = linkButtonFactory.Generate("remove".Localize());
                    removeLink.Click += (sender, e) =>
                    {
                        printerSettings.Macros.Remove(localMacroReference);
                        printerSettings.Save();
                        this.RebuildList(printerSettings, linkButtonFactory);
                    };
                    macroRow.AddChild(removeLink);
                    linkButtonFactory.textColor = oldColor;

                    contentRow.AddChild(macroRow);
                }
            }
        }
Exemplo n.º 8
0
        private FlowLayoutWidget GetMacroButtonContainer()
        {
            FlowLayoutWidget macroButtonContainer = new FlowLayoutWidget();

            macroButtonContainer.Margin  = new BorderDouble(0, 0, 3, 0);
            macroButtonContainer.Padding = new BorderDouble(0, 3, 3, 3);

            if (ActiveSliceSettings.Instance?.ActionMacros().Any() != true)
            {
                return(macroButtonContainer);
            }

            foreach (GCodeMacro macro in ActiveSliceSettings.Instance.ActionMacros())
            {
                Button macroButton = textImageButtonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
                macroButton.Margin = new BorderDouble(right: 5);
                macroButton.Click += (s, e) => macro.Run();

                macroButtonContainer.AddChild(macroButton);
            }

            return(macroButtonContainer);
        }
Exemplo n.º 9
0
        internal ControlContentExtruder(PrinterConfig printer, int extruderIndex, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor = HAnchor.Stretch;
            this.printer = printer;

            GuiWidget macroButtons = null;

            // We do not yet support loading filament into extruders other than 0, fix it when time.
            if (extruderIndex == 0)
            {
                // add in load and unload buttons
                macroButtons = new FlowLayoutWidget()
                {
                    Padding = theme.ToolbarPadding,
                };

                var loadFilament = new GCodeMacro()
                {
                    GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "load_filament.txt"))
                };

                var loadButton = new TextButton("Load".Localize(), theme)
                {
                    BackgroundColor = theme.SlightShade,
                    Margin          = theme.ButtonSpacing,
                    ToolTipText     = "Load filament".Localize()
                };
                loadButton.Name   = "Load Filament Button";
                loadButton.Click += (s, e) => loadFilament.Run(printer.Connection);
                macroButtons.AddChild(loadButton);

                var unloadFilament = new GCodeMacro()
                {
                    GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "unload_filament.txt"))
                };

                var unloadButton = new TextButton("Unload".Localize(), theme)
                {
                    BackgroundColor = theme.SlightShade,
                    Margin          = theme.ButtonSpacing,
                    ToolTipText     = "Unload filament".Localize()
                };
                unloadButton.Click += (s, e) => unloadFilament.Run(printer.Connection);
                macroButtons.AddChild(unloadButton);

                this.AddChild(new SettingsItem("Filament".Localize(), macroButtons, theme, enforceGutter: false));
            }

            // Add the Extrude buttons
            var buttonContainer = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Padding = theme.ToolbarPadding,
            };

            var retractButton = new TextButton("Retract".Localize(), theme)
            {
                BackgroundColor = theme.SlightShade,
                Margin          = theme.ButtonSpacing,
                ToolTipText     = "Retract filament".Localize()
            };

            retractButton.Click += (s, e) =>
            {
                printer.Connection.MoveExtruderRelative(moveAmount * -1, printer.Settings.EFeedRate(extruderIndex), extruderIndex);
            };
            buttonContainer.AddChild(retractButton);

            int extruderButtonTopMargin = macroButtons == null ? 8 : 0;

            var extrudeButton = new TextButton("Extrude".Localize(), theme)
            {
                BackgroundColor = theme.SlightShade,
                Margin          = theme.ButtonSpacing,
                Name            = "Extrude Button",
                ToolTipText     = "Extrude filament".Localize()
            };

            extrudeButton.Click += (s, e) =>
            {
                printer.Connection.MoveExtruderRelative(moveAmount, printer.Settings.EFeedRate(extruderIndex), extruderIndex);
            };
            buttonContainer.AddChild(extrudeButton);

            this.AddChild(new SettingsItem(
                              macroButtons == null ? "Filament".Localize() : "",   // Don't put the name if we put in a macro button (it has the name)
                              buttonContainer,
                              theme,
                              enforceGutter: false));

            var moveButtonsContainer = new FlowLayoutWidget()
            {
                VAnchor = VAnchor.Fit | VAnchor.Center,
                HAnchor = HAnchor.Fit,
                Padding = theme.ToolbarPadding,
            };

            var oneButton = theme.CreateMicroRadioButton("1");

            oneButton.CheckedStateChanged += (s, e) =>
            {
                if (oneButton.Checked)
                {
                    moveAmount = 1;
                }
            };
            moveButtonsContainer.AddChild(oneButton);

            var tenButton = theme.CreateMicroRadioButton("10");

            tenButton.CheckedStateChanged += (s, e) =>
            {
                if (tenButton.Checked)
                {
                    moveAmount = 10;
                }
            };
            moveButtonsContainer.AddChild(tenButton);

            var oneHundredButton = theme.CreateMicroRadioButton("100");

            oneHundredButton.CheckedStateChanged += (s, e) =>
            {
                if (oneHundredButton.Checked)
                {
                    moveAmount = 100;
                }
            };
            moveButtonsContainer.AddChild(oneHundredButton);

            switch (moveAmount)
            {
            case 1:
                oneButton.Checked = true;
                break;

            case 10:
                tenButton.Checked = true;
                break;

            case 100:
                oneHundredButton.Checked = true;
                break;
            }

            moveButtonsContainer.AddChild(new TextWidget("mm", textColor: theme.Colors.PrimaryTextColor, pointSize: 8)
            {
                VAnchor = VAnchor.Center,
                Margin  = new BorderDouble(3, 0)
            });

            this.AddChild(new SettingsItem("Distance".Localize(), moveButtonsContainer, theme, enforceGutter: false));
        }
Exemplo n.º 10
0
        public MacroDetailPage(GCodeMacro gcodeMacro, PrinterSettings printerSettings)
        {
            // Form validation fields
            MHTextEditWidget macroNameInput;
            MHTextEditWidget macroCommandInput;
            TextWidget       macroCommandError;
            TextWidget       macroNameError;

            this.HeaderText      = "Edit Macro".Localize();
            this.printerSettings = printerSettings;

            var elementMargin = new BorderDouble(top: 3);

            contentRow.Padding += 3;

            contentRow.AddChild(new TextWidget("Macro Name".Localize() + ":", 0, 0, 12)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = new BorderDouble(0, 0, 0, 1)
            });

            contentRow.AddChild(macroNameInput = new MHTextEditWidget(GCodeMacro.FixMacroName(gcodeMacro.Name))
            {
                HAnchor = HAnchor.Stretch
            });

            contentRow.AddChild(macroNameError = new TextWidget("Give the macro a name".Localize() + ".", 0, 0, 10)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            });

            contentRow.AddChild(new TextWidget("Macro Commands".Localize() + ":", 0, 0, 12)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = new BorderDouble(0, 0, 0, 1)
            });

            macroCommandInput = new MHTextEditWidget(gcodeMacro.GCode, pixelHeight: 120, multiLine: true, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };
            macroCommandInput.ActualTextEditWidget.VAnchor = VAnchor.Stretch;
            macroCommandInput.DrawFromHintedCache();
            contentRow.AddChild(macroCommandInput);

            contentRow.AddChild(macroCommandError = new TextWidget("This should be in 'G-Code'".Localize() + ".", 0, 0, 10)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            });

            var container = new FlowLayoutWidget
            {
                Margin  = new BorderDouble(0, 5),
                HAnchor = HAnchor.Stretch
            };

            contentRow.AddChild(container);

            var addMacroButton = theme.CreateDialogButton("Save".Localize());

            addMacroButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    if (ValidateMacroForm())
                    {
                        // SaveActiveMacro
                        gcodeMacro.Name  = macroNameInput.Text;
                        gcodeMacro.GCode = macroCommandInput.Text;

                        if (!printerSettings.Macros.Contains(gcodeMacro))
                        {
                            printerSettings.Macros.Add(gcodeMacro);
                            printerSettings.Save();
                        }

                        this.DialogWindow.ChangeToPage(new MacroListPage(printerSettings));
                    }
                });
            };

            this.AddPageAction(addMacroButton);

            // Define field validation
            var validationMethods        = new ValidationMethods();
            var stringValidationHandlers = new FormField.ValidationHandler[] { validationMethods.StringIsNotEmpty };

            formFields = new List <FormField>
            {
                new FormField(macroNameInput, macroNameError, stringValidationHandlers),
                new FormField(macroCommandInput, macroCommandError, stringValidationHandlers)
            };
        }
Exemplo n.º 11
0
 public void ChangeToMacroList()
 {
     this.ActiveMacro = null;
     UiThread.RunOnIdle(DoChangeToMacroList);
 }
Exemplo n.º 12
0
        public MacroListWidget(EditMacrosWindow windowController)
        {
            this.windowController = windowController;

            linkButtonFactory.fontSize = 10;
            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottom.AnchorAll();
            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);

            {
                string     macroPresetsLabel     = "Macro Presets".Localize();
                string     macroPresetsLabelFull = string.Format("{0}:", macroPresetsLabel);
                TextWidget elementHeader         = new TextWidget(macroPresetsLabelFull, pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor   = HAnchor.ParentLeftRight;
                elementHeader.VAnchor   = Agg.UI.VAnchor.ParentBottom;
                headerRow.AddChild(elementHeader);
            }

            topToBottom.AddChild(headerRow);

            FlowLayoutWidget presetsFormContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            {
                presetsFormContainer.HAnchor         = HAnchor.ParentLeftRight;
                presetsFormContainer.VAnchor         = VAnchor.ParentBottomTop;
                presetsFormContainer.Padding         = new BorderDouble(3);
                presetsFormContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            topToBottom.AddChild(presetsFormContainer);

            if (ActiveSliceSettings.Instance?.Macros != null)
            {
                foreach (GCodeMacro macro in ActiveSliceSettings.Instance.Macros)
                {
                    FlowLayoutWidget macroRow = new FlowLayoutWidget();
                    macroRow.Margin          = new BorderDouble(3, 0, 3, 3);
                    macroRow.HAnchor         = Agg.UI.HAnchor.ParentLeftRight;
                    macroRow.Padding         = new BorderDouble(3);
                    macroRow.BackgroundColor = RGBA_Bytes.White;

                    TextWidget buttonLabel = new TextWidget(GCodeMacro.FixMacroName(macro.Name));
                    macroRow.AddChild(buttonLabel);

                    macroRow.AddChild(new HorizontalSpacer());

                    // You can't use the foreach variable inside the lambda functions directly or it will always be the last item.
                    // We make a local variable to create a closure around it to ensure we get the correct instance
                    var localMacroReference = macro;

                    Button editLink = linkButtonFactory.Generate("edit".Localize());
                    editLink.Margin = new BorderDouble(right: 5);
                    editLink.Click += (sender, e) =>
                    {
                        windowController.ChangeToMacroDetail(localMacroReference);
                    };
                    macroRow.AddChild(editLink);

                    Button removeLink = linkButtonFactory.Generate("remove".Localize());
                    removeLink.Click += (sender, e) =>
                    {
                        ActiveSliceSettings.Instance.Macros.Remove(localMacroReference);

                        windowController.RefreshMacros();
                        windowController.ChangeToMacroList();
                    };
                    macroRow.AddChild(removeLink);

                    presetsFormContainer.AddChild(macroRow);
                }
            }

            Button addMacroButton = textImageButtonFactory.Generate("Add".Localize(), "icon_circle_plus.png");

            addMacroButton.ToolTipText = "Add a new Macro".Localize();
            addMacroButton.Click      += (s, e) =>
            {
                windowController.ChangeToMacroDetail(new GCodeMacro()
                {
                    Name  = "Home All",
                    GCode = "G28 ; Home All Axes"
                });
            };

            Button cancelPresetsButton = textImageButtonFactory.Generate("Close".Localize());

            cancelPresetsButton.Click += (sender, e) =>
            {
                UiThread.RunOnIdle(() => this.windowController.Close());
            };

            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Padding = new BorderDouble(0, 3);

            GuiWidget hButtonSpacer = new GuiWidget();

            hButtonSpacer.HAnchor = HAnchor.ParentLeftRight;

            buttonRow.AddChild(addMacroButton);
            buttonRow.AddChild(hButtonSpacer);
            buttonRow.AddChild(cancelPresetsButton);

            topToBottom.AddChild(buttonRow);
            AddChild(topToBottom);
            this.AnchorAll();
        }