<commit_before>﻿/*
Copyright (c) 2012, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

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
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/

using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls;
using MatterHackers.MatterControl.SlicerConfiguration;
using System;
using System.Collections.Generic;

namespace MatterHackers.MatterControl
{
	public class JogControls : GuiWidget
	{
		public static double AxisMoveAmount = 0;
		public static int EAxisMoveAmount = 0;

		private MoveButton xPlusControl;
		private MoveButton xMinusControl;

		private MoveButton yPlusControl;
		private MoveButton yMinusControl;

		private MoveButton zPlusControl;
		private MoveButton zMinusControl;
		public bool hotKeysEnabled = false;
		TextImageButtonFactory hotKeyButtonFactory = new TextImageButtonFactory();

		private MoveButtonFactory moveButtonFactory = new MoveButtonFactory();

		public JogControls(XYZColors colors)
		{
			moveButtonFactory.normalTextColor = RGBA_Bytes.Black;

			double distanceBetweenControls = 12;
			double buttonSeparationDistance = 10;

			FlowLayoutWidget allControlsTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

			allControlsTopToBottom.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;

			{
				FlowLayoutWidget allControlsLeftToRight = new FlowLayoutWidget();

				FlowLayoutWidget xYZWithDistance = new FlowLayoutWidget(FlowDirection.TopToBottom);
				{
					FlowLayoutWidget xYZControls = new FlowLayoutWidget();
					{
						GuiWidget xyGrid = CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance);
						xYZControls.AddChild(xyGrid);

						FlowLayoutWidget zButtons = CreateZButtons(XYZColors.zColor, buttonSeparationDistance, out zPlusControl, out zMinusControl);
						zButtons.VAnchor = Agg.UI.VAnchor.ParentBottom;
						xYZControls.AddChild(zButtons);
						xYZWithDistance.AddChild(xYZControls);
					}

					this.KeyDown += (sender, e) =>
				{

					double moveAmountPositive = AxisMoveAmount;
					double moveAmountNegative = -AxisMoveAmount;
					int eMoveAmountPositive = EAxisMoveAmount;
					int eMoveAmountNegative = -EAxisMoveAmount;


					if (e.KeyCode == Keys.Home && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.XYZ);
					}
					else if (e.KeyCode == Keys.Z && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Z);
					}
					else if (e.KeyCode == Keys.Y && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Y);
					}
					else if (e.KeyCode == Keys.X && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.X);
					}
					else if (e.KeyCode == Keys.Left && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountNegative, MovementControls.XSpeed);
					}
					else if (e.KeyCode == Keys.Right && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountPositive, MovementControls.XSpeed);
					}
					else if (e.KeyCode == Keys.Up && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountPositive, MovementControls.YSpeed);
					}
					else if (e.KeyCode == Keys.Down && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountNegative, MovementControls.YSpeed);
					}
					else if (e.KeyCode == Keys.PageUp && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountPositive, MovementControls.ZSpeed);
					}
					else if (e.KeyCode == Keys.PageDown && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountNegative, MovementControls.ZSpeed);
					}
					else if (e.KeyCode == Keys.E && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountPositive, MovementControls.EFeedRate(0));

					}
					else if (e.KeyCode == Keys.R && hotKeysEnabled)
					{
						PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountNegative, MovementControls.EFeedRate(0));
					}
				};

					// add in some movement radio buttons
					FlowLayoutWidget setMoveDistanceControl = new FlowLayoutWidget();
					TextWidget buttonsLabel = new TextWidget("Distance:", textColor: RGBA_Bytes.White);
					buttonsLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
					//setMoveDistanceControl.AddChild(buttonsLabel);

					{
						TextImageButtonFactory buttonFactory = new TextImageButtonFactory();
						buttonFactory.FixedHeight = 20 * TextWidget.GlobalPointSizeScaleRatio;
						buttonFactory.FixedWidth = 30 * TextWidget.GlobalPointSizeScaleRatio;
						buttonFactory.fontSize = 8;
						buttonFactory.Margin = new BorderDouble(0);
						buttonFactory.checkedBorderColor = ActiveTheme.Instance.PrimaryTextColor;

						FlowLayoutWidget moveRadioButtons = new FlowLayoutWidget();

						RadioButton pointOneButton = buttonFactory.GenerateRadioButton("0.1");
						pointOneButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
						pointOneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked) SetXYZMoveAmount(.1); };
						moveRadioButtons.AddChild(pointOneButton);

						RadioButton oneButton = buttonFactory.GenerateRadioButton("1");
						oneButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
						oneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked) SetXYZMoveAmount(1); };
						moveRadioButtons.AddChild(oneButton);

						RadioButton tenButton = buttonFactory.GenerateRadioButton("10");
						tenButton.VAnchor = Agg.UI.VAnchor.ParentCenter;<commit_msg>Fixed HotKey Manual Controls on Mac Keyboards<commit_after>﻿/*
Copyright (c) 2012, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

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
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/

using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls;
using MatterHackers.MatterControl.SlicerConfiguration;
using System;
using System.Collections.Generic;
using MatterHackers.Agg.PlatformAbstract;

namespace MatterHackers.MatterControl
{
	public class JogControls : GuiWidget
	{
		public static double AxisMoveAmount = 0;
		public static int EAxisMoveAmount = 0;

		private MoveButton xPlusControl;
		private MoveButton xMinusControl;

		private MoveButton yPlusControl;
		private MoveButton yMinusControl;

		private MoveButton zPlusControl;
		private MoveButton zMinusControl;
		public bool hotKeysEnabled = false;
		TextImageButtonFactory hotKeyButtonFactory = new TextImageButtonFactory();

		private MoveButtonFactory moveButtonFactory = new MoveButtonFactory();

		public JogControls(XYZColors colors)
		{
			moveButtonFactory.normalTextColor = RGBA_Bytes.Black;

			double distanceBetweenControls = 12;
			double buttonSeparationDistance = 10;

			FlowLayoutWidget allControlsTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

			allControlsTopToBottom.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;

			{
				FlowLayoutWidget allControlsLeftToRight = new FlowLayoutWidget();

				FlowLayoutWidget xYZWithDistance = new FlowLayoutWidget(FlowDirection.TopToBottom);
				{
					FlowLayoutWidget xYZControls = new FlowLayoutWidget();
					{
						GuiWidget xyGrid = CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance);
						xYZControls.AddChild(xyGrid);

						FlowLayoutWidget zButtons = CreateZButtons(XYZColors.zColor, buttonSeparationDistance, out zPlusControl, out zMinusControl);
						zButtons.VAnchor = Agg.UI.VAnchor.ParentBottom;
						xYZControls.AddChild(zButtons);
						xYZWithDistance.AddChild(xYZControls);
					}

					this.KeyDown += (sender, e) =>
				{

					double moveAmountPositive = AxisMoveAmount;
					double moveAmountNegative = -AxisMoveAmount;
					int eMoveAmountPositive = EAxisMoveAmount;
					int eMoveAmountNegative = -EAxisMoveAmount;

					if (OsInformation.OperatingSystem == OSType.Windows)
					{
						if (e.KeyCode == Keys.Home && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.XYZ);
						}
						else if (e.KeyCode == Keys.Z && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Z);
						}
						else if (e.KeyCode == Keys.Y && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Y);
						}
						else if (e.KeyCode == Keys.X && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.X);
						}
						else if (e.KeyCode == Keys.Left && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountNegative, MovementControls.XSpeed);
						}
						else if (e.KeyCode == Keys.Right && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountPositive, MovementControls.XSpeed);
						}
						else if (e.KeyCode == Keys.Up && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountPositive, MovementControls.YSpeed);
						}
						else if (e.KeyCode == Keys.Down && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountNegative, MovementControls.YSpeed);
						}
						else if (e.KeyCode == Keys.PageUp && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountPositive, MovementControls.ZSpeed);
						}
						else if (e.KeyCode == Keys.PageDown && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountNegative, MovementControls.ZSpeed);
						}
						else if (e.KeyCode == Keys.E && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountPositive, MovementControls.EFeedRate(0));

						}
						else if (e.KeyCode == Keys.R && hotKeysEnabled)
						{
							PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountNegative, MovementControls.EFeedRate(0));
						}
					}
					else if(OsInformation.OperatingSystem == OSType.Mac) 
					{
							if (e.KeyCode == Keys.LButton && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.XYZ);
							}
							else if (e.KeyCode == Keys.Z && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Z);
							}
							else if (e.KeyCode == Keys.Y && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Y);
							}
							else if (e.KeyCode == Keys.X && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.X);
							}
							else if (e.KeyCode == Keys.Left && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountNegative, MovementControls.XSpeed);
							}
							else if (e.KeyCode == Keys.Right && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountPositive, MovementControls.XSpeed);
							}
							else if (e.KeyCode == Keys.Up && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountPositive, MovementControls.YSpeed);
							}
							else if (e.KeyCode == Keys.Down && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountNegative, MovementControls.YSpeed);
							}
							else if (e.KeyCode == (Keys.Back | Keys.Cancel) && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountPositive, MovementControls.ZSpeed);
							}
							else if (e.KeyCode == Keys.Clear && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountNegative, MovementControls.ZSpeed);
							}
							else if (e.KeyCode == Keys.E && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountPositive, MovementControls.EFeedRate(0));

							}
							else if (e.KeyCode == Keys.R && hotKeysEnabled)
							{
								PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountNegative, MovementControls.EFeedRate(0));
							}
					}
				
				};

					// add in some movement radio buttons
					FlowLayoutWidget setMoveDistanceControl = new FlowLayoutWidget();
					TextWidget buttonsLabel = new TextWidget("Distance:", textColor: RGBA_Bytes.White);
					buttonsLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
					//setMoveDistanceControl.AddChild(buttonsLabel);

					{
						TextImageButtonFactory buttonFactory = new TextImageButtonFactory();
						buttonFactory.FixedHeight = 20 * TextWidget.GlobalPointSizeScaleRatio;
						buttonFactory.FixedWidth = 30 * TextWidget.GlobalPointSizeScaleRatio;
						buttonFactory.fontSize = 8;
						buttonFactory.Margin = new BorderDouble(0);
						buttonFactory.checkedBorderColor = ActiveTheme.Instance.PrimaryTextColor;

						FlowLayoutWidget moveRadioButtons = new FlowLayoutWidget();

						RadioButton pointOneButton = buttonFactory.GenerateRadioButton("0.1");
						pointOneButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
						pointOneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked) SetXYZMoveAmount(.1); };
						moveRadioButtons.AddChild(pointOneButton);

						RadioButton oneButton = buttonFactory.GenerateRadioButton("1");
						oneButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
						oneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked) SetXYZMoveAmount(1); };
						moveRadioButtons.AddChild(oneButton);

						RadioButton tenButton = buttonFactory.GenerateRadioButton("10");
						tenButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
{'fraction_non_alphanumeric': 0.07764472159373104, 'fraction_numerical': 0.0030903371778599415, 'mean_word_length': 4.379044226773523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3496791', 'n_tokens_mistral': 6333, 'n_tokens_neox': 4798, 'n_words': 1117}