2014-01-29 19:09:30 -08:00
|
|
|
|
/*
|
2014-02-15 18:06:03 -08:00
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
2014-01-29 19:09:30 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-01-29 19:09:30 -08:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-01-29 19:09:30 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-02-07 14:37:47 -08:00
|
|
|
|
using System;
|
2017-01-31 15:17:15 -08:00
|
|
|
|
using System.Linq;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2017-10-31 17:27:37 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2017-10-31 17:27:37 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2014-12-10 12:07:06 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-10-15 16:57:26 -07:00
|
|
|
|
namespace MatterHackers.MatterControl.PrinterControls
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
2018-01-10 18:22:13 -08:00
|
|
|
|
public class MacroControls : FlowLeftRightWithWrapping
|
2016-12-08 15:39:23 -08:00
|
|
|
|
{
|
2018-02-07 14:37:47 -08:00
|
|
|
|
private EventHandler unregisterEvents;
|
2018-09-05 07:43:28 -07:00
|
|
|
|
private PrinterConfig printer;
|
|
|
|
|
|
private ThemeConfig theme;
|
2018-02-07 14:37:47 -08:00
|
|
|
|
|
2018-01-10 18:22:13 -08:00
|
|
|
|
private MacroControls(PrinterConfig printer, ThemeConfig theme)
|
2016-12-08 15:39:23 -08:00
|
|
|
|
{
|
2018-02-07 14:37:47 -08:00
|
|
|
|
this.printer = printer;
|
|
|
|
|
|
this.theme = theme;
|
2018-09-05 07:43:28 -07:00
|
|
|
|
this.Rebuild();
|
|
|
|
|
|
|
2018-10-05 16:03:31 -07:00
|
|
|
|
printer.Settings.MacrosChanged += Settings_MacrosChanged;
|
2017-02-02 10:40:42 -08:00
|
|
|
|
|
2018-10-05 09:34:43 -07:00
|
|
|
|
ApplicationController.Instance.ActiveProfileModified.RegisterEvent((s, e) =>
|
2016-05-09 14:20:13 -07:00
|
|
|
|
{
|
2018-11-19 17:44:10 -08:00
|
|
|
|
if (s is PrinterSettings settings
|
|
|
|
|
|
&& settings.ID == this.printer.Settings.ID)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() => Rebuild());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 14:37:47 -08:00
|
|
|
|
}, ref unregisterEvents);
|
|
|
|
|
|
}
|
2016-05-09 14:20:13 -07:00
|
|
|
|
|
2018-10-05 16:03:31 -07:00
|
|
|
|
private void Settings_MacrosChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() => Rebuild());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2018-02-07 14:37:47 -08:00
|
|
|
|
{
|
|
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
2018-10-05 16:03:31 -07:00
|
|
|
|
printer.Settings.MacrosChanged -= Settings_MacrosChanged;
|
2018-02-07 14:37:47 -08:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
2016-05-08 14:13:16 -07:00
|
|
|
|
|
2018-09-05 07:43:28 -07:00
|
|
|
|
private void Rebuild()
|
2018-02-07 14:37:47 -08:00
|
|
|
|
{
|
|
|
|
|
|
addedChildren.Clear();
|
2016-02-24 07:57:15 -08:00
|
|
|
|
|
2018-02-07 14:37:47 -08:00
|
|
|
|
if (!printer.Settings.Macros.Any())
|
|
|
|
|
|
{
|
2018-11-03 09:13:07 -07:00
|
|
|
|
var noMacrosFound = new TextWidget("No macros are currently set up for this printer.".Localize(), pointSize: 10, textColor: theme.TextColor);
|
2018-02-07 14:37:47 -08:00
|
|
|
|
this.AddChild(noMacrosFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2017-01-31 15:17:15 -08:00
|
|
|
|
{
|
2018-02-07 14:37:47 -08:00
|
|
|
|
foreach (GCodeMacro macro in printer.Settings.Macros)
|
2017-02-01 10:06:35 -08:00
|
|
|
|
{
|
2022-07-16 07:46:44 -07:00
|
|
|
|
var macroButton = new ThemedTextButton(GCodeMacro.FixMacroName(macro.Name), theme)
|
2018-02-07 14:37:47 -08:00
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Margin = new BorderDouble(right: 5)
|
|
|
|
|
|
};
|
|
|
|
|
|
macroButton.Click += (s, e) => macro.Run(printer.Connection);
|
|
|
|
|
|
|
|
|
|
|
|
addedChildren.Add(macroButton);
|
2017-02-01 10:06:35 -08:00
|
|
|
|
}
|
2018-02-07 14:37:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DoWrappingLayout();
|
2018-01-10 18:22:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
var widget = new MacroControls(printer, theme);
|
|
|
|
|
|
|
2023-10-03 16:17:01 -07:00
|
|
|
|
var editButton = new ThemedIconButton(StaticData.Instance.LoadIcon("icon_edit.png", 16, 16).GrayToColor(theme.TextColor), theme);
|
2018-01-10 18:22:13 -08:00
|
|
|
|
editButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogWindow.Show(new MacroListPage(printer.Settings));
|
|
|
|
|
|
};
|
2018-01-10 15:00:59 -08:00
|
|
|
|
|
2018-01-10 18:22:13 -08:00
|
|
|
|
return new SectionWidget(
|
|
|
|
|
|
"Macros".Localize(),
|
|
|
|
|
|
widget,
|
|
|
|
|
|
theme,
|
|
|
|
|
|
editButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
}
|