2014-01-29 19:09:30 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
2014-02-04 13:30:42 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2014-06-11 14:52:58 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2014-07-28 13:48:28 -07:00
|
|
|
|
using MatterHackers.SerialPortCommunication.FrostedSerial;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SetupStepComPortTwo : SetupConnectionWidgetBase
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] startingPortNames;
|
|
|
|
|
|
string[] currentPortNames;
|
|
|
|
|
|
Button nextButton;
|
|
|
|
|
|
Button connectButton;
|
|
|
|
|
|
TextWidget printerErrorMessage;
|
|
|
|
|
|
event EventHandler unregisterEvents;
|
|
|
|
|
|
|
|
|
|
|
|
public SetupStepComPortTwo(ConnectionWindow windowController, GuiWidget containerWindowToClose, PrinterSetupStatus setupPrinterStatus)
|
|
|
|
|
|
: base(windowController, containerWindowToClose, setupPrinterStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2015-03-09 11:35:29 -07:00
|
|
|
|
startingPortNames = FrostedSerialPortFactory.Instance.GetPortNames();
|
2014-01-29 19:09:30 -08:00
|
|
|
|
contentRow.AddChild(createPrinterConnectionMessageContainer());
|
|
|
|
|
|
{
|
|
|
|
|
|
//Construct buttons
|
2014-03-11 15:24:47 -07:00
|
|
|
|
nextButton = textImageButtonFactory.Generate(LocalizedString.Get("Done"));
|
2014-10-24 13:41:13 -07:00
|
|
|
|
nextButton.Click += new EventHandler(NextButton_Click);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
nextButton.Visible = false;
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
connectButton = textImageButtonFactory.Generate(LocalizedString.Get("Connect"));
|
2014-10-24 13:41:13 -07:00
|
|
|
|
connectButton.Click += new EventHandler(ConnectButton_Click);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-06-11 14:52:58 -07:00
|
|
|
|
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
GuiWidget hSpacer = new GuiWidget();
|
|
|
|
|
|
hSpacer.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
|
|
|
|
|
|
//Add buttons to buttonContainer
|
|
|
|
|
|
footerRow.AddChild(nextButton);
|
|
|
|
|
|
footerRow.AddChild(connectButton);
|
|
|
|
|
|
footerRow.AddChild(hSpacer);
|
|
|
|
|
|
|
|
|
|
|
|
footerRow.AddChild(cancelButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnClosed(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (unregisterEvents != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
unregisterEvents(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
string printerMessageOneText = LocalizedString.Get ("MatterControl will now attempt to auto-detect printer.");
|
2014-02-04 13:30:42 -08:00
|
|
|
|
TextWidget printerMessageOne = new TextWidget(printerMessageOneText, 0, 0, 10);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
printerMessageOne.Margin = new BorderDouble(0, 10, 0, 5);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageOne.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
printerMessageOne.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageOne.Margin = elementMargin;
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
string printerMessageTwoTxtBeg = LocalizedString.Get ("Disconnect printer");
|
|
|
|
|
|
string printerMessageTwoTxtEnd = LocalizedString.Get ("if currently connected");
|
2014-02-04 13:30:42 -08:00
|
|
|
|
string printerMessageTwoTxtFull = string.Format ("1.) {0} ({1}).", printerMessageTwoTxtBeg, printerMessageTwoTxtEnd);
|
|
|
|
|
|
TextWidget printerMessageTwo = new TextWidget(printerMessageTwoTxtFull, 0, 0, 12);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageTwo.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
printerMessageTwo.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageTwo.Margin = elementMargin;
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
string printerMessageThreeTxtBeg = LocalizedString.Get ("Press");
|
|
|
|
|
|
string printerMessageThreeTxtEnd = LocalizedString.Get ("Continue");
|
2014-02-04 13:30:42 -08:00
|
|
|
|
string printerMessageThreeTxtFull = string.Format ("2.) {0} '{1}'.", printerMessageThreeTxtBeg, printerMessageThreeTxtEnd);
|
|
|
|
|
|
TextWidget printerMessageThree = new TextWidget(printerMessageThreeTxtFull, 0, 0, 12);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageThree.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
printerMessageThree.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageThree.Margin = elementMargin;
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
string printerMessageFourBeg = LocalizedString.Get ("Power on and connect printer");
|
2014-02-04 13:30:42 -08:00
|
|
|
|
string printerMessageFourFull = string.Format ("3.) {0}.", printerMessageFourBeg);
|
|
|
|
|
|
TextWidget printerMessageFour = new TextWidget(printerMessageFourFull, 0, 0, 12);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageFour.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
printerMessageFour.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageFour.Margin = elementMargin;
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
string printerMessageFiveTxtBeg = LocalizedString.Get ("Press");
|
|
|
|
|
|
string printerMessageFiveTxtEnd = LocalizedString.Get ("Connect");
|
2014-02-04 13:30:42 -08:00
|
|
|
|
string printerMessageFiveTxtFull = string.Format ("4.) {0} '{1}'.", printerMessageFiveTxtBeg, printerMessageFiveTxtEnd);
|
|
|
|
|
|
TextWidget printerMessageFive = new TextWidget(printerMessageFiveTxtFull, 0, 0, 12);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMessageFive.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
printerMessageFive.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMessageFive.Margin = elementMargin;
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget vSpacer = new GuiWidget();
|
|
|
|
|
|
vSpacer.VAnchor = VAnchor.ParentBottomTop;
|
|
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
Button manualLink = linkButtonFactory.Generate(LocalizedString.Get("Manual Configuration"));
|
2014-01-29 19:09:30 -08:00
|
|
|
|
manualLink.Margin = new BorderDouble(0, 5);
|
2014-10-24 13:41:13 -07:00
|
|
|
|
manualLink.Click += new EventHandler(ManualLink_Click);
|
2014-01-29 19:09:30 -08: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(printerMessageTwo);
|
|
|
|
|
|
container.AddChild(printerMessageThree);
|
|
|
|
|
|
container.AddChild(printerMessageFour);
|
|
|
|
|
|
container.AddChild(printerMessageFive);
|
|
|
|
|
|
container.AddChild(printerErrorMessage);
|
|
|
|
|
|
container.AddChild(vSpacer);
|
|
|
|
|
|
container.AddChild(manualLink);
|
|
|
|
|
|
|
|
|
|
|
|
container.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-24 13:41:13 -07:00
|
|
|
|
void ManualLink_Click(object sender, EventArgs mouseEvent)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(MoveToManualConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MoveToManualConfiguration(object state)
|
|
|
|
|
|
{
|
2015-01-05 10:27:24 -08:00
|
|
|
|
Parent.AddChild(new SetupStepComPortManual((ConnectionWindow)Parent, Parent, this.currentPrinterSetupStatus));
|
2014-01-29 19:09:30 -08:00
|
|
|
|
Parent.RemoveChild(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-24 13:41:13 -07:00
|
|
|
|
void ConnectButton_Click(object sender, EventArgs mouseEvent)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
2015-02-04 19:51:36 -08:00
|
|
|
|
// Select the first port that's in GetPortNames() but not in startingPortNames
|
2015-03-09 11:35:29 -07:00
|
|
|
|
string candidatePort = FrostedSerialPortFactory.Instance.GetPortNames().Except(startingPortNames).FirstOrDefault();
|
2014-01-29 19:09:30 -08:00
|
|
|
|
if (candidatePort == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
printerErrorMessage.TextColor = RGBA_Bytes.Red;
|
2014-04-15 10:11:56 -07:00
|
|
|
|
string printerErrorMessageLabelFull = LocalizedString.Get ("Oops! Printer could not be detected ");
|
|
|
|
|
|
printerErrorMessage.Text = printerErrorMessageLabelFull;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ActivePrinter.ComPort = candidatePort;
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-04-15 10:11:56 -07:00
|
|
|
|
string printerErrorMessageLabelTwo = LocalizedString.Get ("Attempting to connect");
|
|
|
|
|
|
string printerErrorMessageLabelTwoFull = string.Format("{0}...",printerErrorMessageLabelTwo);
|
|
|
|
|
|
printerErrorMessage.Text = printerErrorMessageLabelTwoFull;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
this.ActivePrinter.Commit();
|
2014-02-14 12:06:44 -08:00
|
|
|
|
ActivePrinterProfile.Instance.ActivePrinter = this.ActivePrinter;
|
2014-06-11 14:52:58 -07:00
|
|
|
|
PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter();
|
2014-01-29 19:09:30 -08:00
|
|
|
|
connectButton.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onPrinterStatusChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2014-06-11 14:52:58 -07:00
|
|
|
|
if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
|
|
|
|
|
onConnectionSuccess();
|
|
|
|
|
|
}
|
2014-06-11 14:52:58 -07:00
|
|
|
|
else if (PrinterConnectionAndCommunication.Instance.CommunicationState != PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
|
|
|
|
|
onConnectionFailed();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onConnectionFailed()
|
|
|
|
|
|
{
|
|
|
|
|
|
printerErrorMessage.TextColor = RGBA_Bytes.Red;
|
2014-03-11 15:24:47 -07:00
|
|
|
|
printerErrorMessage.Text = LocalizedString.Get("Uh-oh! Could not connect to printer.");
|
2014-01-29 19:09:30 -08:00
|
|
|
|
connectButton.Visible = true;
|
|
|
|
|
|
nextButton.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onConnectionSuccess()
|
|
|
|
|
|
{
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2014-04-15 10:11:56 -07:00
|
|
|
|
string printerErrorMessageLabelThree = LocalizedString.Get ("Connection succeeded");
|
|
|
|
|
|
string printerErrorMessageLabelThreeFull = string.Format ("{0}!", printerErrorMessageLabelThree);
|
|
|
|
|
|
printerErrorMessage.Text = printerErrorMessageLabelThreeFull;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
nextButton.Visible = true;
|
|
|
|
|
|
connectButton.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-24 13:41:13 -07:00
|
|
|
|
void NextButton_Click(object sender, EventArgs mouseEvent)
|
2014-02-17 16:35:24 -08:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(DoNextButton_Click);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DoNextButton_Click(object state)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
|
|
|
|
|
Parent.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|