2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2014-02-04 13:30:42 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2016-04-25 13:35:36 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2014-06-11 14:52:58 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2014-07-28 13:48:28 -07:00
|
|
|
|
using MatterHackers.SerialPortCommunication.FrostedSerial;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
|
|
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
public class SetupStepComPortTwo : ConnectionWizardPage
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
private string[] startingPortNames;
|
|
|
|
|
|
private string[] currentPortNames;
|
|
|
|
|
|
private Button nextButton;
|
|
|
|
|
|
private Button connectButton;
|
|
|
|
|
|
private TextWidget printerErrorMessage;
|
|
|
|
|
|
|
2016-12-29 06:55:12 -08:00
|
|
|
|
private EventHandler unregisterEvents;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-06-07 15:45:50 -07:00
|
|
|
|
public SetupStepComPortTwo()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-03-11 10:30:46 -07:00
|
|
|
|
startingPortNames = FrostedSerialPort.GetPortNames();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
contentRow.AddChild(createPrinterConnectionMessageContainer());
|
|
|
|
|
|
{
|
|
|
|
|
|
//Construct buttons
|
2016-04-18 11:31:31 -07:00
|
|
|
|
nextButton = textImageButtonFactory.Generate("Done".Localize());
|
|
|
|
|
|
nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
nextButton.Visible = false;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
connectButton = textImageButtonFactory.Generate("Connect".Localize());
|
|
|
|
|
|
connectButton.Click += ConnectButton_Click;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-06-13 17:22:49 -07:00
|
|
|
|
PrinterConnection.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
//Add buttons to buttonContainer
|
|
|
|
|
|
footerRow.AddChild(nextButton);
|
|
|
|
|
|
footerRow.AddChild(connectButton);
|
2016-04-25 13:35:36 -07:00
|
|
|
|
footerRow.AddChild(new HorizontalSpacer());
|
2016-11-30 13:31:19 -08:00
|
|
|
|
footerRow.AddChild(cancelButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-03 13:06:08 -08:00
|
|
|
|
public override void OnClosed(ClosedEventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public FlowLayoutWidget createPrinterConnectionMessageContainer()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
container.VAnchor = VAnchor.ParentBottomTop;
|
|
|
|
|
|
container.Margin = new BorderDouble(5);
|
|
|
|
|
|
BorderDouble elementMargin = new BorderDouble(top: 5);
|
|
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
string printerMessageOneText = "MatterControl will now attempt to auto-detect printer.".Localize();
|
2014-02-04 13:30:42 -08:00
|
|
|
|
TextWidget printerMessageOne = new TextWidget(printerMessageOneText, 0, 0, 10);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerMessageOne.Margin = new BorderDouble(0, 10, 0, 5);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageOne.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerMessageOne.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageOne.Margin = elementMargin;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-10-26 17:35:54 -07:00
|
|
|
|
string printerMessageFourBeg = "Connect printer and power on".Localize();
|
|
|
|
|
|
string printerMessageFourFull = string.Format("1.) {0}.", printerMessageFourBeg);
|
2014-02-04 13:30:42 -08:00
|
|
|
|
TextWidget printerMessageFour = new TextWidget(printerMessageFourFull, 0, 0, 12);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageFour.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerMessageFour.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageFour.Margin = elementMargin;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
string printerMessageFiveTxtBeg = "Press".Localize();
|
|
|
|
|
|
string printerMessageFiveTxtEnd = "Connect".Localize();
|
2016-10-26 17:35:54 -07:00
|
|
|
|
string printerMessageFiveTxtFull = string.Format("2.) {0} '{1}'.", printerMessageFiveTxtBeg, printerMessageFiveTxtEnd);
|
2014-02-04 13:30:42 -08:00
|
|
|
|
TextWidget printerMessageFive = new TextWidget(printerMessageFiveTxtFull, 0, 0, 12);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageFive.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerMessageFive.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageFive.Margin = elementMargin;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
GuiWidget vSpacer = new GuiWidget();
|
|
|
|
|
|
vSpacer.VAnchor = VAnchor.ParentBottomTop;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
Button manualLink = linkButtonFactory.Generate("Manual Configuration".Localize());
|
2015-04-08 15:20:10 -07:00
|
|
|
|
manualLink.Margin = new BorderDouble(0, 5);
|
2016-12-09 12:09:28 -08:00
|
|
|
|
manualLink.Click += (s, e) => UiThread.RunOnIdle(WizardWindow.ChangeToPage<SetupStepComPortManual>);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
printerErrorMessage = new TextWidget("", 0, 0, 10);
|
|
|
|
|
|
printerErrorMessage.AutoExpandBoundsToText = true;
|
|
|
|
|
|
printerErrorMessage.TextColor = RGBA_Bytes.Red;
|
|
|
|
|
|
printerErrorMessage.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerErrorMessage.Margin = elementMargin;
|
|
|
|
|
|
|
|
|
|
|
|
container.AddChild(printerMessageOne);
|
|
|
|
|
|
container.AddChild(printerMessageFour);
|
|
|
|
|
|
container.AddChild(printerErrorMessage);
|
|
|
|
|
|
container.AddChild(vSpacer);
|
|
|
|
|
|
container.AddChild(manualLink);
|
|
|
|
|
|
|
|
|
|
|
|
container.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ConnectButton_Click(object sender, EventArgs mouseEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Select the first port that's in GetPortNames() but not in startingPortNames
|
2015-03-11 10:30:46 -07:00
|
|
|
|
string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
if (candidatePort == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
printerErrorMessage.TextColor = RGBA_Bytes.Red;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
printerErrorMessage.Text = "Oops! Printer could not be detected ".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
printerErrorMessage.Text = "Attempting to connect".Localize() + "...";
|
|
|
|
|
|
|
2016-07-18 14:15:37 -07:00
|
|
|
|
ActiveSliceSettings.Instance.Helpers.SetComPort(candidatePort);
|
2017-06-13 17:22:49 -07:00
|
|
|
|
PrinterConnection.Instance.ConnectToActivePrinter();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
connectButton.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void onPrinterStatusChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-06-13 17:22:49 -07:00
|
|
|
|
if (PrinterConnection.Instance.PrinterIsConnected)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
|
|
|
|
|
printerErrorMessage.Text = "Connection succeeded".Localize() + "!";
|
|
|
|
|
|
nextButton.Visible = true;
|
|
|
|
|
|
connectButton.Visible = false;
|
2016-09-23 16:24:43 -07:00
|
|
|
|
UiThread.RunOnIdle(() => this?.Parent?.Close());
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2017-06-13 17:32:38 -07:00
|
|
|
|
else if (PrinterConnection.Instance.CommunicationState != CommunicationStates.AttemptingToConnect)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
printerErrorMessage.TextColor = RGBA_Bytes.Red;
|
|
|
|
|
|
printerErrorMessage.Text = "Uh-oh! Could not connect to printer.".Localize();
|
|
|
|
|
|
connectButton.Visible = true;
|
|
|
|
|
|
nextButton.Visible = false;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|