mattercontrol/PrinterControls/JogControls.cs

749 lines
23 KiB
C#
Raw Normal View History

2014-01-29 19:09:30 -08:00
/*
2018-04-15 17:55:12 -07:00
Copyright (c) 2018, Lars Brubaker, John Lewin
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.
*/
2017-01-04 15:35:38 -08:00
using System;
using System.Collections.Generic;
2017-08-20 15:52:43 -07:00
using System.Linq;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
2015-04-08 15:20:10 -07:00
using MatterHackers.Agg.UI;
2014-01-29 19:09:30 -08:00
using MatterHackers.Localizations;
2017-01-04 15:35:38 -08:00
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
2014-10-15 16:57:26 -07:00
using MatterHackers.MatterControl.PrinterControls;
2015-04-08 15:20:10 -07:00
using MatterHackers.MatterControl.SlicerConfiguration;
2017-05-19 14:39:57 -07:00
using MatterHackers.VectorMath;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
public class JogControls : GuiWidget
{
public static double AxisMoveAmount = 0;
public static int EAxisMoveAmount = 0;
2015-04-08 15:20:10 -07:00
private MoveButton xPlusControl;
private MoveButton xMinusControl;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private MoveButton yPlusControl;
private MoveButton yMinusControl;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private MoveButton zPlusControl;
private MoveButton zMinusControl;
private ThemeConfig theme;
private PrinterConfig printer;
2014-01-29 19:09:30 -08:00
private List<ExtrudeButton> eMinusButtons = new List<ExtrudeButton>();
private List<ExtrudeButton> ePlusButtons = new List<ExtrudeButton>();
private RadioTextButton movePointZeroTwoMmButton;
private RadioTextButton moveOneMmButton;
private RadioTextButton oneHundredButton;
private RadioTextButton tenButton;
private GuiWidget disableableEButtons;
private GuiWidget keyboardFocusBorder;
private GuiWidget keyboardImage;
private EventHandler unregisterEvents;
private GuiWidget xyGrid = null;
public JogControls(PrinterConfig printer, XYZColors colors, ThemeConfig theme)
2015-04-08 15:20:10 -07:00
{
this.theme = theme;
this.printer = printer;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
double distanceBetweenControls = 12;
double buttonSeparationDistance = 10;
2014-01-29 19:09:30 -08:00
var allControlsTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch
};
2014-01-29 19:09:30 -08:00
var allControlsLeftToRight = new FlowLayoutWidget();
2014-01-29 19:09:30 -08:00
using (allControlsLeftToRight.LayoutLock())
2018-04-15 17:56:37 -07:00
{
var xYZWithDistance = new FlowLayoutWidget(FlowDirection.TopToBottom);
2015-04-08 15:20:10 -07:00
{
var xYZControls = new FlowLayoutWidget();
xYZControls.AddChild(this.CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance));
2014-01-29 19:09:30 -08:00
FlowLayoutWidget zButtons = JogControls.CreateZButtons(printer, buttonSeparationDistance, out zPlusControl, out zMinusControl, colors, theme);
zButtons.VAnchor = VAnchor.Bottom;
xYZControls.AddChild(zButtons);
xYZWithDistance.AddChild(xYZControls);
2014-01-29 19:09:30 -08:00
// add in some movement radio buttons
var setMoveDistanceControl = new FlowLayoutWidget
{
HAnchor = HAnchor.Left | HAnchor.Fit,
VAnchor = VAnchor.Fit
};
2015-04-08 15:20:10 -07:00
2018-04-15 17:56:37 -07:00
{
var moveRadioButtons = new FlowLayoutWidget();
var radioList = new List<GuiWidget>();
2018-04-15 17:56:37 -07:00
movePointZeroTwoMmButton = theme.CreateMicroRadioButton("0.02", radioList);
movePointZeroTwoMmButton.CheckedStateChanged += (s, e) =>
{
if (movePointZeroTwoMmButton.Checked)
{
SetXYZMoveAmount(.02);
}
};
moveRadioButtons.AddChild(movePointZeroTwoMmButton);
var pointOneButton = theme.CreateMicroRadioButton("0.1", radioList);
pointOneButton.CheckedStateChanged += (s, e) =>
{
if (pointOneButton.Checked)
{
SetXYZMoveAmount(.1);
}
};
moveRadioButtons.AddChild(pointOneButton);
moveOneMmButton = theme.CreateMicroRadioButton("1", radioList);
moveOneMmButton.CheckedStateChanged += (s, e) =>
{
if (moveOneMmButton.Checked)
{
SetXYZMoveAmount(1);
}
};
moveRadioButtons.AddChild(moveOneMmButton);
tenButton = theme.CreateMicroRadioButton("10", radioList);
tenButton.CheckedStateChanged += (s, e) =>
{
if (tenButton.Checked)
{
SetXYZMoveAmount(10);
}
};
moveRadioButtons.AddChild(tenButton);
oneHundredButton = theme.CreateMicroRadioButton("100", radioList);
oneHundredButton.CheckedStateChanged += (s, e) =>
2018-04-15 17:56:37 -07:00
{
if (oneHundredButton.Checked)
{
SetXYZMoveAmount(100);
}
};
moveRadioButtons.AddChild(oneHundredButton);
tenButton.Checked = true;
SetXYZMoveAmount(10);
moveRadioButtons.Margin = new BorderDouble(0, 3);
setMoveDistanceControl.AddChild(moveRadioButtons);
2015-04-08 15:20:10 -07:00
moveRadioButtons.AddChild(new TextWidget("mm", textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 8)
{
Margin = new BorderDouble(left: 10),
VAnchor = VAnchor.Center
});
}
xYZWithDistance.AddChild(setMoveDistanceControl);
}
2018-04-15 17:56:37 -07:00
allControlsLeftToRight.AddChild(xYZWithDistance);
2015-04-08 15:20:10 -07:00
#if !__ANDROID__
allControlsLeftToRight.AddChild(GetHotkeyControlContainer());
#endif
// Bar between Z And E
allControlsLeftToRight.AddChild(new GuiWidget(1, 1)
{
VAnchor = VAnchor.Stretch,
BackgroundColor = colors.ZColor,
Margin = new BorderDouble(distanceBetweenControls, 5)
});
// EButtons
disableableEButtons = CreateEButtons(buttonSeparationDistance, colors);
disableableEButtons.Name = "disableableEButtons";
disableableEButtons.HAnchor = HAnchor.Fit;
disableableEButtons.VAnchor = VAnchor.Fit | VAnchor.Top;
allControlsLeftToRight.AddChild(disableableEButtons);
allControlsTopToBottom.AddChild(allControlsLeftToRight);
}
allControlsLeftToRight.PerformLayout();
2015-04-08 15:20:10 -07:00
using (this.LayoutLock())
{
this.AddChild(allControlsTopToBottom);
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit;
Margin = new BorderDouble(3);
}
2015-04-08 15:20:10 -07:00
this.PerformLayout();
ActiveSliceSettings.SettingChanged.RegisterEvent(Printer_SettingChanged, ref unregisterEvents);
2015-04-08 15:20:10 -07:00
}
internal void SetEnabledLevels(bool enableBabysteppingMode, bool enableEControls)
{
if (enableBabysteppingMode)
{
2016-07-25 14:58:45 -07:00
if (zPlusControl.MoveAmount >= 1)
{
movePointZeroTwoMmButton.InvokeClick();
}
}
else
{
if (zPlusControl.MoveAmount < 1)
{
moveOneMmButton.InvokeClick();
}
}
tenButton.Enabled = !enableBabysteppingMode;
oneHundredButton.Enabled = !enableBabysteppingMode;
if (xyGrid != null)
{
xyGrid.Enabled = !enableBabysteppingMode;
}
disableableEButtons.Enabled = enableEControls;
}
2015-04-08 15:20:10 -07:00
private void SetEMoveAmount(int moveAmount)
{
foreach (ExtrudeButton extrudeButton in eMinusButtons)
{
extrudeButton.MoveAmount = -moveAmount;
EAxisMoveAmount = moveAmount;
2015-04-08 15:20:10 -07:00
}
foreach (ExtrudeButton extrudeButton in ePlusButtons)
{
extrudeButton.MoveAmount = moveAmount;
EAxisMoveAmount = moveAmount;
2015-04-08 15:20:10 -07:00
}
}
private void SetXYZMoveAmount(double moveAmount)
{
xPlusControl.MoveAmount = moveAmount;
xMinusControl.MoveAmount = -moveAmount;
yPlusControl.MoveAmount = moveAmount;
yMinusControl.MoveAmount = -moveAmount;
zPlusControl.MoveAmount = moveAmount;
zMinusControl.MoveAmount = -moveAmount;
AxisMoveAmount = moveAmount;
2015-04-08 15:20:10 -07:00
}
public override void OnClosed(ClosedEventArgs e)
{
unregisterEvents?.Invoke(this, null);
base.OnClosed(e);
}
2015-04-08 15:20:10 -07:00
private FlowLayoutWidget GetHotkeyControlContainer()
{
var keyFocusedContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Fit,
VAnchor = VAnchor.Stretch,
ToolTipText = "Use cursor keys for axis movements".Localize(),
Margin = new BorderDouble(left: 10)
};
2017-05-19 14:39:57 -07:00
keyboardImage = new IconButton(AggContext.StaticData.LoadIcon("hot_key_small_white.png", 19, 12, theme.InvertIcons), theme)
2017-05-19 14:39:57 -07:00
{
HAnchor = HAnchor.Center,
2017-05-19 14:39:57 -07:00
Margin = new BorderDouble(5),
Visible = !UserSettings.Instance.IsTouchScreen,
Enabled = false,
Selectable = false
2017-05-19 14:39:57 -07:00
};
keyboardFocusBorder = new GuiWidget(1, 1)
{
MinimumSize = new Vector2(keyboardImage.Width + 5, keyboardImage.Height + 5),
};
keyboardFocusBorder.AddChild(keyboardImage);
keyFocusedContainer.AddChild(keyboardFocusBorder);
return keyFocusedContainer;
}
// OnLoad overridden for keyboard and only applicable on non-Android builds
#if !__ANDROID__
public override void OnLoad(EventArgs args)
{
var parent = keyboardFocusBorder.Parents<SectionWidget>().First();
2017-05-19 14:39:57 -07:00
parent.KeyDown += JogControls_KeyDown;
2017-05-19 14:39:57 -07:00
parent.ContainsFocusChanged += (sender, e) =>
2017-01-04 15:35:38 -08:00
{
bool hasFocus = (sender as GuiWidget).ContainsFocus;
if (keyboardImage.Enabled != hasFocus)
{
keyboardImage.Enabled = hasFocus;
//keyboardImage.BackgroundColor = (hasFocus) ? theme.SlightShade : Color.Transparent;
}
};
2017-05-19 14:39:57 -07:00
base.OnLoad(args);
}
#endif
private void JogControls_KeyDown(object sender, KeyEventArgs e)
{
double moveAmountPositive = AxisMoveAmount;
double moveAmountNegative = -AxisMoveAmount;
int eMoveAmountPositive = EAxisMoveAmount;
int eMoveAmountNegative = -EAxisMoveAmount;
// if we are not printing and on mac or PC
if (printer.Connection.CommunicationState != CommunicationStates.Printing
&& (AggContext.OperatingSystem == OSType.Windows || AggContext.OperatingSystem == OSType.Mac))
2017-05-19 14:39:57 -07:00
{
if (e.KeyCode == Keys.Z)
{
printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.Y)
{
printer.Connection.HomeAxis(PrinterConnection.Axis.Y);
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.X)
{
printer.Connection.HomeAxis(PrinterConnection.Axis.X);
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
if (e.KeyCode == Keys.Home)
{
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.Left)
{
printer.Connection.MoveRelative(PrinterConnection.Axis.X, moveAmountNegative, printer.Settings.XSpeed());
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.Right)
{
printer.Connection.MoveRelative(PrinterConnection.Axis.X, moveAmountPositive, printer.Settings.XSpeed());
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.Up)
{
printer.Connection.MoveRelative(PrinterConnection.Axis.Y, moveAmountPositive, printer.Settings.YSpeed());
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.Down)
{
printer.Connection.MoveRelative(PrinterConnection.Axis.Y, moveAmountNegative, printer.Settings.YSpeed());
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.E)
{
printer.Connection.MoveRelative(PrinterConnection.Axis.E, eMoveAmountPositive, printer.Settings.EFeedRate(0));
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else if (e.KeyCode == Keys.R)
{
printer.Connection.MoveRelative(PrinterConnection.Axis.E, eMoveAmountNegative, printer.Settings.EFeedRate(0));
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
}
if ((AggContext.OperatingSystem == OSType.Windows && e.KeyCode == Keys.PageUp)
|| (AggContext.OperatingSystem == OSType.Mac && e.KeyCode == (Keys.Back | Keys.Cancel)))
2017-05-19 14:39:57 -07:00
{
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
2017-05-19 14:39:57 -07:00
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
2017-05-19 14:39:57 -07:00
currentZ += moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else
{
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, moveAmountPositive, printer.Settings.ZSpeed());
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
}
else if ((AggContext.OperatingSystem == OSType.Windows && e.KeyCode == Keys.PageDown)
|| (AggContext.OperatingSystem == OSType.Mac && e.KeyCode == Keys.Clear))
2017-05-19 14:39:57 -07:00
{
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
2017-05-19 14:39:57 -07:00
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
2017-05-19 14:39:57 -07:00
currentZ += moveAmountNegative;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
else
{
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, moveAmountNegative, printer.Settings.ZSpeed());
e.Handled = true;
2017-05-19 14:39:57 -07:00
}
}
}
private FlowLayoutWidget CreateEButtons(double buttonSeparationDistance, XYZColors colors)
2015-04-08 15:20:10 -07:00
{
int extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
2015-04-08 15:20:10 -07:00
FlowLayoutWidget eButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
{
FlowLayoutWidget eMinusButtonAndText = new FlowLayoutWidget();
BorderDouble extrusionMargin = new BorderDouble(4, 0, 4, 0);
if (extruderCount == 1)
{
ExtrudeButton eMinusControl = theme.CreateExtrudeButton(printer, "E-", printer.Settings.EFeedRate(0), 0);
2015-04-08 15:20:10 -07:00
eMinusControl.Margin = extrusionMargin;
eMinusControl.ToolTipText = "Retract filament".Localize();
2015-04-08 15:20:10 -07:00
eMinusButtonAndText.AddChild(eMinusControl);
eMinusButtons.Add(eMinusControl);
}
else
{
for (int i = 0; i < extruderCount; i++)
{
ExtrudeButton eMinusControl = theme.CreateExtrudeButton(printer, $"E{i + 1}-", printer.Settings.EFeedRate(0), i);
eMinusControl.ToolTipText = "Retract filament".Localize();
2015-04-08 15:20:10 -07:00
eMinusControl.Margin = extrusionMargin;
eMinusButtonAndText.AddChild(eMinusControl);
eMinusButtons.Add(eMinusControl);
}
}
TextWidget eMinusControlLabel = new TextWidget("Retract".Localize(), pointSize: 11)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
VAnchor = VAnchor.Center
};
2015-04-08 15:20:10 -07:00
eMinusButtonAndText.AddChild(eMinusControlLabel);
eButtons.AddChild(eMinusButtonAndText);
eMinusButtonAndText.HAnchor = HAnchor.Fit;
eMinusButtonAndText.VAnchor = VAnchor.Fit;
2015-04-08 15:20:10 -07:00
FlowLayoutWidget buttonSpacerContainer = new FlowLayoutWidget();
for (int i = 0; i < extruderCount; i++)
{
double buttonWidth = eMinusButtons[i].Width + 6;
var eSpacer = new GuiWidget(1, buttonSeparationDistance)
{
Margin = new BorderDouble((buttonWidth / 2), 0, ((buttonWidth) / 2), 0),
BackgroundColor = colors.EColor
};
2015-04-08 15:20:10 -07:00
buttonSpacerContainer.AddChild(eSpacer);
}
2015-04-08 15:20:10 -07:00
eButtons.AddChild(buttonSpacerContainer);
buttonSpacerContainer.HAnchor = HAnchor.Fit;
buttonSpacerContainer.VAnchor = VAnchor.Fit;
2015-04-08 15:20:10 -07:00
FlowLayoutWidget ePlusButtonAndText = new FlowLayoutWidget();
if (extruderCount == 1)
{
ExtrudeButton ePlusControl = theme.CreateExtrudeButton(printer, "E+", printer.Settings.EFeedRate(0), 0);
2015-04-08 15:20:10 -07:00
ePlusControl.Margin = extrusionMargin;
ePlusControl.ToolTipText = "Extrude filament".Localize();
2015-04-08 15:20:10 -07:00
ePlusButtonAndText.AddChild(ePlusControl);
ePlusButtons.Add(ePlusControl);
}
else
{
for (int i = 0; i < extruderCount; i++)
{
ExtrudeButton ePlusControl = theme.CreateExtrudeButton(printer, $"E{i + 1}+", printer.Settings.EFeedRate(0), i);
2015-04-08 15:20:10 -07:00
ePlusControl.Margin = extrusionMargin;
ePlusControl.ToolTipText = "Extrude filament".Localize();
2015-04-08 15:20:10 -07:00
ePlusButtonAndText.AddChild(ePlusControl);
ePlusButtons.Add(ePlusControl);
}
}
2017-01-04 07:23:30 -08:00
TextWidget ePlusControlLabel = new TextWidget("Extrude".Localize(), pointSize: 11);
2015-04-08 15:20:10 -07:00
ePlusControlLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
2018-01-12 14:36:47 -08:00
ePlusControlLabel.VAnchor = VAnchor.Center;
2015-04-08 15:20:10 -07:00
ePlusButtonAndText.AddChild(ePlusControlLabel);
eButtons.AddChild(ePlusButtonAndText);
ePlusButtonAndText.HAnchor = HAnchor.Fit;
ePlusButtonAndText.VAnchor = VAnchor.Fit;
2015-04-08 15:20:10 -07:00
}
eButtons.AddChild(new GuiWidget(10, 6));
// add in some movement radio buttons
var setMoveDistanceControl = new FlowLayoutWidget
{
HAnchor = HAnchor.Fit
};
2015-04-08 15:20:10 -07:00
{
var moveRadioButtons = new FlowLayoutWidget
{
Margin = new BorderDouble(0, 3)
};
2018-04-07 22:51:10 -07:00
var oneButton = theme.CreateMicroRadioButton("1");
oneButton.CheckedStateChanged += (s, e) =>
{
if (oneButton.Checked)
{
SetEMoveAmount(1);
}
};
2015-04-08 15:20:10 -07:00
moveRadioButtons.AddChild(oneButton);
var tenButton = theme.CreateMicroRadioButton("10");
tenButton.CheckedStateChanged += (s, e) =>
{
if (tenButton.Checked)
{
SetEMoveAmount(10);
}
};
2015-04-08 15:20:10 -07:00
moveRadioButtons.AddChild(tenButton);
var oneHundredButton = theme.CreateMicroRadioButton("100");
oneHundredButton.CheckedStateChanged += (s, e) =>
{
if (oneHundredButton.Checked)
{
SetEMoveAmount(100);
}
};
2015-04-08 15:20:10 -07:00
moveRadioButtons.AddChild(oneHundredButton);
2015-04-08 15:20:10 -07:00
tenButton.Checked = true;
setMoveDistanceControl.AddChild(moveRadioButtons);
}
setMoveDistanceControl.AddChild(
new TextWidget("mm", textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 8)
{
VAnchor = VAnchor.Center,
Margin = new BorderDouble(left: 10)
});
2015-04-08 15:20:10 -07:00
eButtons.AddChild(setMoveDistanceControl);
eButtons.HAnchor = HAnchor.Fit;
eButtons.VAnchor = VAnchor.Fit | VAnchor.Bottom;
2015-04-08 15:20:10 -07:00
return eButtons;
}
public static FlowLayoutWidget CreateZButtons(PrinterConfig printer, double buttonSeparationDistance, out MoveButton zPlusControl, out MoveButton zMinusControl, XYZColors colors, ThemeConfig theme, bool levelingButtons = false)
{
var zButtons = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
Margin = new BorderDouble(0, 5),
};
zPlusControl = theme.CreateMoveButton(printer, "Z+", PrinterConnection.Axis.Z, printer.Settings.ZSpeed(), levelingButtons);
zPlusControl.Name = "Move Z positive".Localize();
zPlusControl.ToolTipText = "Move Z positive".Localize();
zButtons.AddChild(zPlusControl);
// spacer
zButtons.AddChild(new GuiWidget(1, buttonSeparationDistance)
2015-04-08 15:20:10 -07:00
{
HAnchor = HAnchor.Center,
BackgroundColor = colors.ZColor
});
2015-04-08 15:20:10 -07:00
zMinusControl = theme.CreateMoveButton(printer, "Z-", PrinterConnection.Axis.Z, printer.Settings.ZSpeed(), levelingButtons);
zMinusControl.ToolTipText = "Move Z negative".Localize();
zButtons.AddChild(zMinusControl);
2015-04-08 15:20:10 -07:00
return zButtons;
}
private void Printer_SettingChanged(object sender, EventArgs e)
{
if (e is StringEventArgs stringEvent)
{
if (stringEvent.Data == SettingsKey.manual_movement_speeds)
{
xPlusControl.MovementFeedRate = printer.Settings.XSpeed();
xMinusControl.MovementFeedRate = printer.Settings.XSpeed();
yPlusControl.MovementFeedRate = printer.Settings.YSpeed();
yMinusControl.MovementFeedRate = printer.Settings.YSpeed();
zPlusControl.MovementFeedRate = printer.Settings.ZSpeed();
zMinusControl.MovementFeedRate = printer.Settings.ZSpeed();
foreach (ExtrudeButton extrudeButton in eMinusButtons)
{
extrudeButton.MovementFeedRate = printer.Settings.EFeedRate(0);
}
foreach (ExtrudeButton extrudeButton in ePlusButtons)
{
extrudeButton.MovementFeedRate = printer.Settings.EFeedRate(0);
}
}
}
}
2015-04-08 15:20:10 -07:00
private GuiWidget CreateXYGridControl(XYZColors colors, double distanceBetweenControls, double buttonSeparationDistance)
{
xyGrid = new GuiWidget
2015-04-08 15:20:10 -07:00
{
HAnchor = HAnchor.Fit,
VAnchor = VAnchor.Fit | VAnchor.Bottom,
Margin = new BorderDouble(0, 5, distanceBetweenControls, 5)
};
var xButtons = new FlowLayoutWidget();
xButtons.HAnchor = HAnchor.Fit | HAnchor.Center;
xButtons.VAnchor = VAnchor.Fit | VAnchor.Center;
xyGrid.AddChild(xButtons);
2015-04-08 15:20:10 -07:00
xMinusControl = theme.CreateMoveButton(printer, "X-", PrinterConnection.Axis.X, printer.Settings.XSpeed());
xMinusControl.ToolTipText = "Move X negative".Localize();
xButtons.AddChild(xMinusControl);
2015-04-08 15:20:10 -07:00
// spacer
xButtons.AddChild(new GuiWidget(xMinusControl.Width + buttonSeparationDistance * 2, 1)
{
VAnchor = VAnchor.Center,
BackgroundColor = colors.XColor
});
2015-04-08 15:20:10 -07:00
xPlusControl = theme.CreateMoveButton(printer, "X+", PrinterConnection.Axis.X, printer.Settings.XSpeed());
xPlusControl.ToolTipText = "Move X positive".Localize();
xButtons.AddChild(xPlusControl);
2015-04-08 15:20:10 -07:00
var yButtons = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Fit | HAnchor.Center,
VAnchor = VAnchor.Fit | VAnchor.Center
};
xyGrid.AddChild(yButtons);
2015-04-08 15:20:10 -07:00
yPlusControl = theme.CreateMoveButton(printer, "Y+", PrinterConnection.Axis.Y, printer.Settings.YSpeed());
yPlusControl.ToolTipText = "Move Y positive".Localize();
yButtons.AddChild(yPlusControl);
// spacer
yButtons.AddChild(new GuiWidget(1, buttonSeparationDistance)
{
HAnchor = HAnchor.Center,
BackgroundColor = colors.YColor
});
yMinusControl = theme.CreateMoveButton(printer, "Y-", PrinterConnection.Axis.Y, printer.Settings.YSpeed());
yMinusControl.ToolTipText = "Move Y negative".Localize();
yButtons.AddChild(yMinusControl);
2015-04-08 15:20:10 -07:00
return xyGrid;
}
public class MoveButton : TextButton
2015-04-08 15:20:10 -07:00
{
//Amounts in millimeters
2018-04-15 00:33:55 -07:00
public double MoveAmount { get; set; } = 10;
2015-04-08 15:20:10 -07:00
public double MovementFeedRate { get; set; }
private PrinterConfig printer;
2015-04-08 15:20:10 -07:00
2018-04-15 00:33:55 -07:00
private PrinterConnection.Axis moveAxis;
public MoveButton(string text, PrinterConfig printer, PrinterConnection.Axis axis, double movementFeedRate, ThemeConfig theme)
: base(text, theme)
2015-04-08 15:20:10 -07:00
{
this.printer = printer;
2015-04-08 15:20:10 -07:00
this.moveAxis = axis;
this.MovementFeedRate = movementFeedRate;
2018-04-15 00:33:55 -07:00
}
public override void OnClick(MouseEventArgs mouseEvent)
{
base.OnClick(mouseEvent);
2015-04-08 15:20:10 -07:00
2018-04-15 00:33:55 -07:00
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
2018-04-15 00:33:55 -07:00
if (moveAxis == PrinterConnection.Axis.Z) // only works on z
2017-01-04 15:35:38 -08:00
{
2018-04-15 00:33:55 -07:00
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += this.MoveAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
2017-01-04 15:35:38 -08:00
}
2018-04-15 00:33:55 -07:00
}
else
{
printer.Connection.MoveRelative(this.moveAxis, this.MoveAmount, MovementFeedRate);
}
2015-04-08 15:20:10 -07:00
}
}
public class ExtrudeButton : TextButton
2015-04-08 15:20:10 -07:00
{
//Amounts in millimeters
public double MoveAmount = 10;
public double MovementFeedRate { get; set; }
2015-04-08 15:20:10 -07:00
public int ExtruderNumber;
private PrinterConfig printer;
public ExtrudeButton(PrinterConfig printer, string text, double movementFeedRate, int extruderNumber, ThemeConfig theme)
: base(text, theme)
2015-04-08 15:20:10 -07:00
{
this.printer = printer;
2015-04-08 15:20:10 -07:00
this.ExtruderNumber = extruderNumber;
this.MovementFeedRate = movementFeedRate;
2015-04-08 15:20:10 -07:00
}
public override void OnClick(MouseEventArgs mouseEvent)
2015-04-08 15:20:10 -07:00
{
base.OnClick(mouseEvent);
2015-04-08 15:20:10 -07:00
//Add more fancy movement here
printer.Connection.MoveExtruderRelative(MoveAmount, MovementFeedRate, ExtruderNumber);
2015-04-08 15:20:10 -07:00
}
}
}
}