mattercontrol/PrinterControls/ControlWidgets/MovementControls.cs

260 lines
10 KiB
C#
Raw Normal View History

2014-10-15 16:57:26 -07:00
/*
Copyright (c) 2014, Kevin Pope
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-10-15 16:57:26 -07: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-10-15 16:57:26 -07: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-10-15 16:57:26 -07: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-10-15 16:57:26 -07:00
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
2015-04-08 15:20:10 -07:00
using MatterHackers.VectorMath;
using System;
using System.Collections.Generic;
2014-10-15 16:57:26 -07:00
namespace MatterHackers.MatterControl.PrinterControls
{
2015-04-08 15:20:10 -07:00
public class MovementControls : ControlWidgetBase
{
2015-11-23 10:49:08 -08:00
public bool hotKeysEnabled = false;
public FlowLayoutWidget manualControlsLayout;
private double borderWidth = 2;
2015-04-08 15:20:10 -07:00
private Button disableMotors;
2015-11-23 10:49:08 -08:00
private EditManualMovementSpeedsWindow editManualMovementSettingsWindow;
2015-04-08 15:20:10 -07:00
private Button homeAllButton;
private Button homeXButton;
private Button homeYButton;
private Button homeZButton;
private TextImageButtonFactory hotKeyButtonFactory = new TextImageButtonFactory();
2015-11-23 10:49:08 -08:00
private JogControls jogControls;
private AltGroupBox movementControlsGroupBox;
public static double XSpeed { get { return GetMovementSpeeds()["x"]; } }
2015-11-23 10:49:08 -08:00
public static double YSpeed { get { return GetMovementSpeeds()["y"]; } }
public static double ZSpeed { get { return GetMovementSpeeds()["z"]; } }
public static double EFeedRate(int extruderIndex)
{
if (GetMovementSpeeds().ContainsKey("e" + extruderIndex.ToString()))
{
return GetMovementSpeeds()["e" + extruderIndex.ToString()];
}
return GetMovementSpeeds()["e0"];
}
2015-04-08 15:20:10 -07:00
protected override void AddChildElements()
{
Button editButton;
movementControlsGroupBox = new AltGroupBox(textImageButtonFactory.GenerateGroupBoxLabelWithEdit(new TextWidget("Movement Controls".Localize(), pointSize: 18, textColor: ActiveTheme.Instance.SecondaryAccentColor), out editButton));
2015-04-08 15:20:10 -07:00
editButton.Click += (sender, e) =>
{
if (editManualMovementSettingsWindow == null)
{
editManualMovementSettingsWindow = new EditManualMovementSpeedsWindow("Movement Speeds".Localize(), GetMovementSpeedsString(), SetMovementSpeeds);
editManualMovementSettingsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { editManualMovementSettingsWindow = null; };
}
else
{
editManualMovementSettingsWindow.BringToFront();
}
};
movementControlsGroupBox.Margin = new BorderDouble(0);
movementControlsGroupBox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
movementControlsGroupBox.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;
movementControlsGroupBox.VAnchor = Agg.UI.VAnchor.FitToChildren;
jogControls = new JogControls(new XYZColors());
jogControls.Margin = new BorderDouble(0);
2015-04-08 15:20:10 -07:00
{
manualControlsLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
2015-04-08 15:20:10 -07:00
manualControlsLayout.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
manualControlsLayout.VAnchor = Agg.UI.VAnchor.FitToChildren;
manualControlsLayout.Padding = new BorderDouble(3, 5, 3, 0) * TextWidget.GlobalPointSizeScaleRatio;
{
FlowLayoutWidget leftToRightContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
2015-04-08 15:20:10 -07:00
manualControlsLayout.AddChild(GetHomeButtonBar());
manualControlsLayout.AddChild(CreateSeparatorLine());
manualControlsLayout.AddChild(jogControls);
//manualControlsLayout.AddChild(leftToRightContainer);
2015-04-08 15:20:10 -07:00
manualControlsLayout.AddChild(CreateSeparatorLine());
2015-11-23 10:49:08 -08:00
2015-04-08 15:20:10 -07:00
//manualControlsLayout.AddChild(GetManualMoveBar());
}
2015-11-23 10:49:08 -08:00
2015-04-08 15:20:10 -07:00
movementControlsGroupBox.AddChild(manualControlsLayout);
}
2015-11-23 10:49:08 -08:00
2015-04-08 15:20:10 -07:00
this.AddChild(movementControlsGroupBox);
}
2015-11-23 10:49:08 -08:00
private static Dictionary<string, double> GetMovementSpeeds()
{
Dictionary<string, double> speeds = new Dictionary<string, double>();
string movementSpeedsString = GetMovementSpeedsString();
string[] allSpeeds = movementSpeedsString.Split(',');
for (int i = 0; i < allSpeeds.Length / 2; i++)
{
speeds.Add(allSpeeds[i * 2 + 0], double.Parse(allSpeeds[i * 2 + 1]));
}
return speeds;
}
private static string GetMovementSpeedsString()
{
string presets = "x,3000,y,3000,z,315,e0,150"; // stored x,value,y,value,z,value,e1,value,e2,value,e3,value,...
if (PrinterConnectionAndCommunication.Instance != null && ActivePrinterProfile.Instance.ActivePrinter != null)
{
string savedSettings = ActivePrinterProfile.Instance.ActivePrinter.ManualMovementSpeeds;
if (savedSettings != null && savedSettings != "")
{
presets = savedSettings;
}
}
return presets;
}
private static void SetMovementSpeeds(object seder, EventArgs e)
{
StringEventArgs stringEvent = e as StringEventArgs;
if (stringEvent != null && stringEvent.Data != null)
{
ActivePrinterProfile.Instance.ActivePrinter.ManualMovementSpeeds = stringEvent.Data;
ActivePrinterProfile.Instance.ActivePrinter.Commit();
ApplicationController.Instance.ReloadAdvancedControlsPanel();
}
}
private void disableMotors_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.ReleaseMotors();
}
2015-04-08 15:20:10 -07:00
private FlowLayoutWidget GetHomeButtonBar()
{
FlowLayoutWidget homeButtonBar = new FlowLayoutWidget();
homeButtonBar.HAnchor = HAnchor.ParentLeftRight;
homeButtonBar.Margin = new BorderDouble(3, 0, 3, 6) * TextWidget.GlobalPointSizeScaleRatio;
homeButtonBar.Padding = new BorderDouble(0);
textImageButtonFactory.borderWidth = 1;
textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
textImageButtonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
ImageBuffer helpIconImage = StaticData.Instance.LoadIcon("icon_home_white_24x24.png");
ImageWidget homeIconImageWidget = new ImageWidget(helpIconImage);
homeIconImageWidget.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
homeIconImageWidget.OriginRelativeParent += new Vector2(0, 2) * TextWidget.GlobalPointSizeScaleRatio;
RGBA_Bytes oldColor = this.textImageButtonFactory.normalFillColor;
textImageButtonFactory.normalFillColor = new RGBA_Bytes(180, 180, 180);
homeAllButton = textImageButtonFactory.Generate(LocalizedString.Get("ALL"));
this.textImageButtonFactory.normalFillColor = oldColor;
homeAllButton.ToolTipText = "Home X, Y and Z";
2015-04-08 15:20:10 -07:00
homeAllButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
homeAllButton.Click += new EventHandler(homeAll_Click);
2014-10-15 16:57:26 -07:00
textImageButtonFactory.FixedWidth = (int)homeAllButton.Width * TextWidget.GlobalPointSizeScaleRatio;
2015-04-08 15:20:10 -07:00
homeXButton = textImageButtonFactory.Generate("X", centerText: true);
homeXButton.ToolTipText = "Home X";
2015-04-08 15:20:10 -07:00
homeXButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
homeXButton.Click += new EventHandler(homeXButton_Click);
homeYButton = textImageButtonFactory.Generate("Y", centerText: true);
homeYButton.ToolTipText = "Home Y";
2015-04-08 15:20:10 -07:00
homeYButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
homeYButton.Click += new EventHandler(homeYButton_Click);
homeZButton = textImageButtonFactory.Generate("Z", centerText: true);
homeZButton.ToolTipText = "Home Z";
2015-04-08 15:20:10 -07:00
homeZButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
homeZButton.Click += new EventHandler(homeZButton_Click);
textImageButtonFactory.normalFillColor = RGBA_Bytes.White;
textImageButtonFactory.FixedWidth = 0;
GuiWidget spacer = new GuiWidget();
spacer.HAnchor = HAnchor.ParentLeftRight;
disableMotors = textImageButtonFactory.Generate("Release".Localize().ToUpper());
disableMotors.Margin = new BorderDouble(0);
disableMotors.Click += new EventHandler(disableMotors_Click);
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
2015-04-08 15:20:10 -07:00
GuiWidget spacerReleaseShow = new GuiWidget(10 * TextWidget.GlobalPointSizeScaleRatio, 0);
homeButtonBar.AddChild(homeIconImageWidget);
homeButtonBar.AddChild(homeAllButton);
homeButtonBar.AddChild(homeXButton);
homeButtonBar.AddChild(homeYButton);
homeButtonBar.AddChild(homeZButton);
homeButtonBar.AddChild(spacer);
homeButtonBar.AddChild(disableMotors);
homeButtonBar.AddChild(spacerReleaseShow);
return homeButtonBar;
}
2015-11-23 10:49:08 -08:00
private void homeAll_Click(object sender, EventArgs mouseEvent)
2015-04-08 15:20:10 -07:00
{
2015-11-23 10:49:08 -08:00
PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.XYZ);
2015-04-08 15:20:10 -07:00
}
private void homeXButton_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.X);
}
private void homeYButton_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Y);
}
private void homeZButton_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Z);
}
2015-11-23 10:49:08 -08:00
}
2015-04-08 15:20:10 -07:00
2015-11-23 10:49:08 -08:00
public class XYZColors
{
public static RGBA_Bytes eColor = new RGBA_Bytes(180, 180, 180);
public static RGBA_Bytes xColor = new RGBA_Bytes(180, 180, 180);
public static RGBA_Bytes yColor = new RGBA_Bytes(255, 255, 255);
public static RGBA_Bytes zColor = new RGBA_Bytes(255, 255, 255);
public XYZColors()
2015-04-08 15:20:10 -07:00
{
}
}
}