diff --git a/ApplicationView/MenuRow/ApplicationMenuRow.cs b/ApplicationView/MenuRow/ApplicationMenuRow.cs index 4eeab1ff6..9eb6ce9fc 100644 --- a/ApplicationView/MenuRow/ApplicationMenuRow.cs +++ b/ApplicationView/MenuRow/ApplicationMenuRow.cs @@ -33,6 +33,8 @@ using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.AboutPage; using System; using MatterHackers.Localizations; +using MatterHackers.MatterControl.SlicerConfiguration; +using System.Linq; namespace MatterHackers.MatterControl { @@ -67,7 +69,10 @@ namespace MatterHackers.MatterControl this.AddChild(new MenuOptionSettings()); // put in the help menu - this.AddChild(new MenuOptionMacros()); + if (ActiveSliceSettings.Instance.ActionMacros().Any()) + { + this.AddChild(new MenuOptionAction()); + } // put in the help menu this.AddChild(new MenuOptionHelp()); diff --git a/ApplicationView/MenuRow/MenuOptionMacros.cs b/ApplicationView/MenuRow/MenuOptionAction.cs similarity index 57% rename from ApplicationView/MenuRow/MenuOptionMacros.cs rename to ApplicationView/MenuRow/MenuOptionAction.cs index 9cc25710d..f7ee931cc 100644 --- a/ApplicationView/MenuRow/MenuOptionMacros.cs +++ b/ApplicationView/MenuRow/MenuOptionAction.cs @@ -9,15 +9,16 @@ using System.Collections.Generic; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.MatterControl.PrinterControls; using MatterHackers.MatterControl.PrinterCommunication; +using System.Linq; namespace MatterHackers.MatterControl { - public class MenuOptionMacros : MenuBase + public class MenuOptionAction : MenuBase { private event EventHandler unregisterEvents; - public MenuOptionMacros() : base("Macros".Localize()) + public MenuOptionAction() : base("Actions".Localize()) { - Name = "Macro Menu"; + Name = "Actions Menu"; ActiveSliceSettings.ActivePrinterChanged.RegisterEvent((s, e) => SetEnabledState(), ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((s,e) => SetEnabledState(), ref unregisterEvents); @@ -37,48 +38,26 @@ namespace MatterHackers.MatterControl private void SetEnabledState() { - for(int i=0; i GetMenuActions() { var list = new List(); - if (ActiveSliceSettings.Instance.Macros.Count > 0) + if (ActiveSliceSettings.Instance.ActionMacros().Any()) { - foreach (GCodeMacro macro in ActiveSliceSettings.Instance.Macros) + foreach (GCodeMacro macro in ActiveSliceSettings.Instance.ActionMacros()) { - list.Add(new MenuItemAction(MacroControls.FixMacroName(macro.Name), macro.Run)); + list.Add(new MenuItemAction(GCodeMacro.FixMacroName(macro.Name), macro.Run)); } } - list.Add(new MenuItemAction( - //StaticData.Instance.LoadIcon("icon_plus.png", 32, 32), - "Edit Macros...", - () => - { - if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) - { - UiThread.RunOnIdle(() => - StyledMessageBox.ShowMessageBox(null, "Please wait until the print has finished and try again.".Localize(), "Can't edit macros while printing".Localize()) - ); - } - else - { - UiThread.RunOnIdle(() => EditMacrosWindow.Show()); - } - - })); - - return list; } } diff --git a/Library/PrintLibraryWidget.cs b/Library/PrintLibraryWidget.cs index 211fa1e1d..b348dd57a 100644 --- a/Library/PrintLibraryWidget.cs +++ b/Library/PrintLibraryWidget.cs @@ -236,7 +236,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private GuiWidget CreateActionsMenu() { - var actionMenu = new DropDownMenu("Action".Localize() + "... "); + var actionMenu = new DropDownMenu("Actions".Localize() + "... "); actionMenu.AlignToRightEdge = true; actionMenu.NormalColor = new RGBA_Bytes(); actionMenu.BorderWidth = 1; diff --git a/MatterControl.csproj b/MatterControl.csproj index a71c9072b..0eef41b07 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -134,7 +134,7 @@ - + diff --git a/PrinterControls/ControlWidgets/MacroControls.cs b/PrinterControls/ControlWidgets/MacroControls.cs index a9efa0d8e..82290cf52 100644 --- a/PrinterControls/ControlWidgets/MacroControls.cs +++ b/PrinterControls/ControlWidgets/MacroControls.cs @@ -43,21 +43,6 @@ namespace MatterHackers.MatterControl.PrinterControls { public class MacroControls : ControlWidgetBase { - static internal string FixMacroName(string input) - { - int lengthLimit = 24; - - string result = Regex.Replace(input, @"\r\n?|\n", " "); - - if (result.Length > lengthLimit) - { - result = result.Substring(0, lengthLimit) + "..."; - } - - return result; - } - - public MacroControls() { this.AddChild(new MacroControlsWidget()); @@ -120,17 +105,114 @@ namespace MatterHackers.MatterControl.PrinterControls macroButtonContainer.Margin = new BorderDouble(3, 0); macroButtonContainer.Padding = new BorderDouble(3); - if (ActiveSliceSettings.Instance?.Macros == null) + if (ActiveSliceSettings.Instance?.UserMacros().Any() == false) { return macroButtonContainer; } int buttonCount = 0; - foreach (GCodeMacro macro in ActiveSliceSettings.Instance.Macros) + foreach (GCodeMacro macro in ActiveSliceSettings.Instance.UserMacros()) { buttonCount++; - Button macroButton = textImageButtonFactory.Generate(MacroControls.FixMacroName(macro.Name)); + Button macroButton = textImageButtonFactory.Generate(GCodeMacro.FixMacroName(macro.Name)); + macroButton.Margin = new BorderDouble(right: 5); + macroButton.Click += (s, e) => macro.Run(); + + macroButtonContainer.AddChild(macroButton); + } + + if (buttonCount == 0) + { + TextWidget noMacrosFound = new TextWidget(LocalizedString.Get("No macros are currently set up for this printer."), pointSize: 10); + noMacrosFound.TextColor = ActiveTheme.Instance.PrimaryTextColor; + macroButtonContainer.AddChild(noMacrosFound); + } + + return macroButtonContainer; + } + } + + + public class ActionControls : ControlWidgetBase + { + public ActionControls() + { + if (!ActiveSliceSettings.Instance.ActionMacros().Any()) + { + Margin = new BorderDouble(); + return; + } + this.AddChild(new ActionControlsWidget()); + } + } + + public class ActionControlsWidget : FlowLayoutWidget + { + protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); + protected FlowLayoutWidget presetButtonsContainer; + + protected string label; + protected string editWindowLabel; + + public ActionControlsWidget() + : base(FlowDirection.TopToBottom) + { + this.textImageButtonFactory.normalFillColor = RGBA_Bytes.White; + this.textImageButtonFactory.FixedHeight = 24 * GuiWidget.DeviceScale; + this.textImageButtonFactory.fontSize = 12; + this.textImageButtonFactory.borderWidth = 1; + this.textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200); + this.textImageButtonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200); + + this.textImageButtonFactory.disabledTextColor = RGBA_Bytes.Gray; + this.textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor; + this.textImageButtonFactory.normalTextColor = RGBA_Bytes.Black; + this.textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor; + + this.HAnchor = HAnchor.ParentLeftRight; + + // add the widgets to this window + FlowLayoutWidget groupBox = new FlowLayoutWidget() + { + Padding = new BorderDouble(5), + HAnchor = HAnchor.ParentLeftRight, + BackgroundColor = ActiveTheme.Instance.TertiaryBackgroundColor, + }; + + groupBox.HAnchor |= Agg.UI.HAnchor.ParentLeftRight; + // make sure the client area will get smaller when the contents get smaller + groupBox.VAnchor = Agg.UI.VAnchor.FitToChildren; + + FlowLayoutWidget controlRow = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom); + controlRow.Margin = new BorderDouble(top: 5); + controlRow.HAnchor |= HAnchor.ParentLeftRight; + { + this.presetButtonsContainer = GetMacroButtonContainer(); + controlRow.AddChild(this.presetButtonsContainer); + } + + groupBox.AddChild(controlRow); + this.AddChild(groupBox); + } + + 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() == false) + { + return macroButtonContainer; + } + + int buttonCount = 0; + foreach (GCodeMacro macro in ActiveSliceSettings.Instance.ActionMacros()) + { + buttonCount++; + + Button macroButton = textImageButtonFactory.Generate(GCodeMacro.FixMacroName(macro.Name)); macroButton.Margin = new BorderDouble(right: 5); macroButton.Click += (s, e) => macro.Run(); diff --git a/PrinterControls/EditMacrosWindow.cs b/PrinterControls/EditMacrosWindow.cs index a769a0f37..a4f8a56d0 100644 --- a/PrinterControls/EditMacrosWindow.cs +++ b/PrinterControls/EditMacrosWindow.cs @@ -110,6 +110,7 @@ namespace MatterHackers.MatterControl private MHTextEditWidget macroCommandInput; private TextWidget macroNameError; private MHTextEditWidget macroNameInput; + private CheckBox showInActionMenu; private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); private EditMacrosWindow windowController; @@ -150,8 +151,9 @@ namespace MatterHackers.MatterControl topToBottom.AddChild(presetsFormContainer); - presetsFormContainer.AddChild(createMacroNameContainer()); + presetsFormContainer.AddChild(CreateMacroNameContainer()); presetsFormContainer.AddChild(CreateMacroCommandContainer()); + presetsFormContainer.AddChild(CreateMacroActionEdit()); Button addMacroButton = textImageButtonFactory.Generate(LocalizedString.Get("Save")); addMacroButton.Click += new EventHandler(SaveMacro_Click); @@ -215,20 +217,19 @@ namespace MatterHackers.MatterControl return container; } - private FlowLayoutWidget createMacroNameContainer() + private FlowLayoutWidget CreateMacroNameContainer() { FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom); container.Margin = new BorderDouble(0, 5); BorderDouble elementMargin = new BorderDouble(top: 3); - string macroNameLabelTxt = LocalizedString.Get("Macro Name"); - string macroNameLabelTxtFull = string.Format("{0}:", macroNameLabelTxt); + 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(MacroControls.FixMacroName(windowController.ActiveMacro.Name)); + macroNameInput = new MHTextEditWidget(GCodeMacro.FixMacroName(windowController.ActiveMacro.Name)); macroNameInput.HAnchor = HAnchor.ParentLeftRight; string giveMacroANameLabel = LocalizedString.Get("Give the macro a name"); @@ -245,10 +246,30 @@ namespace MatterHackers.MatterControl return container; } + FlowLayoutWidget CreateMacroActionEdit() + { + FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom); + container.Margin = new BorderDouble(0, 5); + BorderDouble elementMargin = new BorderDouble(top: 3); + + showInActionMenu = new CheckBox("Show In Action Menu".Localize()) + { + TextColor = ActiveTheme.Instance.PrimaryTextColor, + HAnchor = HAnchor.ParentLeftRight, + Margin = new BorderDouble(0, 0, 0, 1), + Checked = windowController.ActiveMacro.ActionGroup, + }; + + container.AddChild(showInActionMenu); + container.HAnchor = HAnchor.ParentLeftRight; + return container; + } + private void SaveActiveMacro() { windowController.ActiveMacro.Name = macroNameInput.Text; windowController.ActiveMacro.GCode = macroCommandInput.Text; + windowController.ActiveMacro.ActionGroup = showInActionMenu.Checked; if (!ActiveSliceSettings.Instance.Macros.Contains(windowController.ActiveMacro)) { @@ -346,7 +367,7 @@ namespace MatterHackers.MatterControl macroRow.Padding = new BorderDouble(3); macroRow.BackgroundColor = RGBA_Bytes.White; - TextWidget buttonLabel = new TextWidget(MacroControls.FixMacroName(macro.Name)); + TextWidget buttonLabel = new TextWidget(GCodeMacro.FixMacroName(macro.Name)); macroRow.AddChild(buttonLabel); macroRow.AddChild(new HorizontalSpacer()); diff --git a/PrinterControls/ManualPrinterControls.cs b/PrinterControls/ManualPrinterControls.cs index 1a52b3150..a43850922 100644 --- a/PrinterControls/ManualPrinterControls.cs +++ b/PrinterControls/ManualPrinterControls.cs @@ -34,6 +34,7 @@ using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.PrinterControls; using MatterHackers.MatterControl.SlicerConfiguration; using System; +using System.Linq; namespace MatterHackers.MatterControl { @@ -46,6 +47,7 @@ namespace MatterHackers.MatterControl private DisableableWidget fanControlsContainer; private DisableableWidget macroControlsContainer; + private DisableableWidget actionControlsContainer; private MovementControls movementControlsContainer; @@ -69,11 +71,13 @@ namespace MatterHackers.MatterControl controlsTopToBottomLayout.Name = "ManualPrinterControls.ControlsContainer"; controlsTopToBottomLayout.Margin = new BorderDouble(0); - AddMacroControls(controlsTopToBottomLayout); + AddActionControls(controlsTopToBottomLayout); AddTemperatureControls(controlsTopToBottomLayout); AddMovementControls(controlsTopToBottomLayout); + AddMacroControls(controlsTopToBottomLayout); + FlowLayoutWidget linearPanel = new FlowLayoutWidget(); linearPanel.HAnchor = Agg.UI.HAnchor.ParentLeftRight; controlsTopToBottomLayout.AddChild(linearPanel); @@ -133,6 +137,12 @@ namespace MatterHackers.MatterControl PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); } + private void AddActionControls(FlowLayoutWidget controlsTopToBottomLayout) + { + actionControlsContainer = new ActionControls(); + controlsTopToBottomLayout.AddChild(actionControlsContainer); + } + private void AddMacroControls(FlowLayoutWidget controlsTopToBottomLayout) { macroControlsContainer = new MacroControls(); @@ -180,6 +190,7 @@ namespace MatterHackers.MatterControl movementControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); fanControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); macroControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + actionControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); tuningAdjustmentControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); } else // we at least have a printer selected @@ -199,6 +210,7 @@ namespace MatterHackers.MatterControl movementControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.ConfigOnly); fanControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); macroControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.ConfigOnly); + actionControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); tuningAdjustmentControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); foreach (var widget in movementControlsContainer.DisableableWidgets) @@ -220,6 +232,7 @@ namespace MatterHackers.MatterControl movementControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); fanControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); macroControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + actionControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); tuningAdjustmentControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); foreach (var widget in movementControlsContainer.DisableableWidgets) @@ -239,6 +252,7 @@ namespace MatterHackers.MatterControl movementControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.ConfigOnly); fanControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); macroControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.ConfigOnly); + actionControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); tuningAdjustmentControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); break; @@ -258,6 +272,7 @@ namespace MatterHackers.MatterControl //movementControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.ConfigOnly); fanControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); macroControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.ConfigOnly); + actionControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); tuningAdjustmentControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); foreach(var widget in movementControlsContainer.DisableableWidgets) @@ -283,6 +298,7 @@ namespace MatterHackers.MatterControl movementControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); fanControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); macroControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + actionControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); tuningAdjustmentControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); foreach (var widget in movementControlsContainer.DisableableWidgets) diff --git a/SlicerConfiguration/Settings/GCodeMacro.cs b/SlicerConfiguration/Settings/GCodeMacro.cs index 1cdc01c0a..b903a99b4 100644 --- a/SlicerConfiguration/Settings/GCodeMacro.cs +++ b/SlicerConfiguration/Settings/GCodeMacro.cs @@ -37,6 +37,7 @@ using Newtonsoft.Json.Linq; using System.Text; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.PrinterCommunication.Io; +using System.Text.RegularExpressions; namespace MatterHackers.MatterControl.SlicerConfiguration { @@ -44,8 +45,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { public string Name { get; set; } public string GCode { get; set; } + public bool ActionGroup { get; set; } public DateTime LastModified { get; set; } + public static string FixMacroName(string input) + { + int lengthLimit = 24; + + string result = Regex.Replace(input, @"\r\n?|\n", " "); + + if (result.Length > lengthLimit) + { + result = result.Substring(0, lengthLimit) + "..."; + } + + return result; + } + public void Run() { if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected) diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index 17fb4031c..b99fe0d60 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -81,7 +81,27 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } public List Macros { get; set; } = new List(); - + public IEnumerable UserMacros() + { + foreach (var macro in Macros) + { + if (!macro.ActionGroup) + { + yield return macro; + } + } + } + public IEnumerable ActionMacros() + { + foreach (var macro in Macros) + { + if (macro.ActionGroup) + { + yield return macro; + } + } + } + [OnDeserialized] internal void OnDeserializedMethod(StreamingContext context) { diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index ee0f63918..1b0929dc9 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -440,34 +440,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration //If the active printer has no theme we set it to the current theme color printerSettings.UserLayer[SettingsKey.active_theme_name] = ActiveTheme.Instance.Name; - // Import named macros as defined in the following printers: (Airwolf Axiom, HD, HD-R, HD2x, HDL, HDx, Me3D Me2, Robo R1[+]) - var classicDefaultMacros = printerSettings.GetValue("default_macros"); - if (!string.IsNullOrEmpty(classicDefaultMacros)) - { - var namedMacros = new Dictionary(); - namedMacros["Lights On"] = "M42 P6 S255"; - namedMacros["Lights Off"] = "M42 P6 S0"; - namedMacros["Offset 0.8"] = "M565 Z0.8;\nM500"; - namedMacros["Offset 0.9"] = "M565 Z0.9;\nM500"; - namedMacros["Offset 1"] = "M565 Z1;\nM500"; - namedMacros["Offset 1.1"] = "M565 Z1.1;\nM500"; - namedMacros["Offset 1.2"] = "M565 Z1.2;\nM500"; - namedMacros["Z Offset"] = "G1 Z10;\nG28;\nG29;\nG1 Z10;\nG1 X5 Y5 F4000;\nM117;"; - - foreach (string namedMacro in classicDefaultMacros.Split(',')) - { - string gcode; - if (namedMacros.TryGetValue(namedMacro.Trim(), out gcode)) - { - printerSettings.Macros.Add(new GCodeMacro() - { - Name = namedMacro.Trim(), - GCode = gcode - }); - } - } - } - // Add to Profiles - fires ProfileManager.Save due to ObservableCollection event listener Instance.Profiles.Add(new PrinterInfo { diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 2d617508c..63f91f2ae 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -5644,3 +5644,9 @@ Translated:Note: Be sure the tip of the extruder is clean. English:- none - Translated:- none - +English:Actions +Translated:Actions + +English:Show In Action Menu +Translated:Show In Action Menu +