2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2014-06-19 15:55:20 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
2015-11-02 17:54:26 -08:00
|
|
|
|
using MatterHackers.MatterControl.SettingsManagement;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System.Collections.Generic;
|
2015-04-17 20:14:20 -07:00
|
|
|
|
using System.Linq;
|
2016-04-25 13:35:36 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
//Normally step one of the setup process
|
|
|
|
|
|
public class SetupStepMakeModelName : SetupConnectionWidgetBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private FlowLayoutWidget printerModelContainer;
|
|
|
|
|
|
private FlowLayoutWidget printerMakeContainer;
|
|
|
|
|
|
private FlowLayoutWidget printerNameContainer;
|
|
|
|
|
|
|
|
|
|
|
|
private MHTextEditWidget printerNameInput;
|
|
|
|
|
|
|
|
|
|
|
|
private List<CustomCommands> printerCustomCommands;
|
|
|
|
|
|
|
|
|
|
|
|
private TextWidget printerNameError;
|
|
|
|
|
|
private TextWidget printerModelError;
|
|
|
|
|
|
private TextWidget printerMakeError;
|
|
|
|
|
|
|
|
|
|
|
|
private PrinterChooser printerManufacturerSelector;
|
|
|
|
|
|
|
|
|
|
|
|
private Button nextButton;
|
|
|
|
|
|
|
|
|
|
|
|
private bool usingDefaultName;
|
|
|
|
|
|
|
|
|
|
|
|
public SetupStepMakeModelName(ConnectionWindow windowController, GuiWidget containerWindowToClose, PrinterSetupStatus printerSetupStatus = null)
|
|
|
|
|
|
: base(windowController, containerWindowToClose, printerSetupStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Construct inputs
|
|
|
|
|
|
printerNameContainer = createPrinterNameContainer();
|
|
|
|
|
|
printerMakeContainer = createPrinterMakeContainer();
|
|
|
|
|
|
|
|
|
|
|
|
if (printerManufacturerSelector.CountOfMakes == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ActivePrinter.Make = printerManufacturerSelector.ManufacturerDropList.SelectedValue;
|
|
|
|
|
|
|
|
|
|
|
|
printerMakeContainer.Visible = false;
|
|
|
|
|
|
printerModelContainer = createPrinterModelContainer(printerManufacturerSelector.ManufacturerDropList.SelectedValue);
|
|
|
|
|
|
printerModelContainer.Visible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
printerModelContainer = createPrinterModelContainer();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Add inputs to main container
|
|
|
|
|
|
contentRow.AddChild(printerNameContainer);
|
|
|
|
|
|
contentRow.AddChild(printerMakeContainer);
|
|
|
|
|
|
contentRow.AddChild(printerModelContainer);
|
|
|
|
|
|
|
|
|
|
|
|
//Construct buttons
|
2014-03-11 15:24:47 -07:00
|
|
|
|
nextButton = textImageButtonFactory.Generate(LocalizedString.Get("Save & Continue"));
|
2015-12-31 12:57:00 -08:00
|
|
|
|
nextButton.Name = "Save & Continue Button";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
nextButton.Click += new EventHandler(NextButton_Click);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
//Add buttons to buttonContainer
|
|
|
|
|
|
footerRow.AddChild(nextButton);
|
2016-04-25 13:35:36 -07:00
|
|
|
|
footerRow.AddChild(new HorizontalSpacer());
|
2015-04-08 15:20:10 -07:00
|
|
|
|
footerRow.AddChild(cancelButton);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-10-31 09:36:30 -07:00
|
|
|
|
usingDefaultName = true;
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
SetElementState();
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private void SetElementState()
|
|
|
|
|
|
{
|
|
|
|
|
|
printerModelContainer.Visible = (this.ActivePrinter.Make != null);
|
|
|
|
|
|
nextButton.Visible = (this.ActivePrinter.Model != null && this.ActivePrinter.Make != null);
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private FlowLayoutWidget createPrinterNameContainer()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
container.Margin = new BorderDouble(0, 5);
|
|
|
|
|
|
BorderDouble elementMargin = new BorderDouble(top: 3);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-02-17 17:38:08 -08:00
|
|
|
|
string printerNameLabelTxt = LocalizedString.Get("Name");
|
2015-04-08 15:20:10 -07:00
|
|
|
|
string printerNameLabelTxtFull = string.Format("{0}:", printerNameLabelTxt);
|
2014-02-05 18:29:58 -08:00
|
|
|
|
TextWidget printerNameLabel = new TextWidget(printerNameLabelTxtFull, 0, 0, 12);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerNameLabel.TextColor = this.defaultTextColor;
|
|
|
|
|
|
printerNameLabel.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerNameLabel.Margin = new BorderDouble(0, 0, 0, 1);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerNameInput = new MHTextEditWidget(this.ActivePrinter.Name);
|
|
|
|
|
|
printerNameInput.HAnchor = HAnchor.ParentLeftRight;
|
2015-06-24 16:59:10 -07:00
|
|
|
|
printerNameInput.KeyPressed += PrinterNameInput_KeyPressed;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
printerNameError = new TextWidget(LocalizedString.Get("Give your printer a name."), 0, 0, 10);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerNameError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerNameError.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerNameError.Margin = elementMargin;
|
|
|
|
|
|
|
|
|
|
|
|
container.AddChild(printerNameLabel);
|
|
|
|
|
|
container.AddChild(printerNameInput);
|
|
|
|
|
|
container.AddChild(printerNameError);
|
|
|
|
|
|
container.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private FlowLayoutWidget createPrinterMakeContainer()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
container.Margin = new BorderDouble(0, 5);
|
|
|
|
|
|
BorderDouble elementMargin = new BorderDouble(top: 3);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-02-17 17:38:08 -08:00
|
|
|
|
string printerManufacturerLabelTxt = LocalizedString.Get("Make");
|
2014-02-05 18:29:58 -08:00
|
|
|
|
string printerManufacturerLabelTxtFull = string.Format("{0}:", printerManufacturerLabelTxt);
|
|
|
|
|
|
TextWidget printerManufacturerLabel = new TextWidget(printerManufacturerLabelTxtFull, 0, 0, 12);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerManufacturerLabel.TextColor = this.defaultTextColor;
|
|
|
|
|
|
printerManufacturerLabel.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerManufacturerLabel.Margin = elementMargin;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerManufacturerSelector = new PrinterChooser();
|
|
|
|
|
|
printerManufacturerSelector.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerManufacturerSelector.Margin = elementMargin;
|
|
|
|
|
|
printerManufacturerSelector.ManufacturerDropList.SelectionChanged += new EventHandler(ManufacturerDropList_SelectionChanged);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
printerMakeError = new TextWidget(LocalizedString.Get("Select the printer manufacturer"), 0, 0, 10);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerMakeError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerMakeError.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerMakeError.Margin = elementMargin;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
container.AddChild(printerManufacturerLabel);
|
|
|
|
|
|
container.AddChild(printerManufacturerSelector);
|
|
|
|
|
|
container.AddChild(printerMakeError);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
container.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
return container;
|
|
|
|
|
|
}
|
2014-12-15 18:16:35 -08:00
|
|
|
|
|
2014-01-29 19:09:30 -08:00
|
|
|
|
private FlowLayoutWidget createPrinterModelContainer(string make = "Other")
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
container.Margin = new BorderDouble(0, 5);
|
|
|
|
|
|
BorderDouble elementMargin = new BorderDouble(top: 3);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-02-17 17:38:08 -08:00
|
|
|
|
string printerModelLabelTxt = LocalizedString.Get("Model");
|
2015-04-08 15:20:10 -07:00
|
|
|
|
string printerModelLabelTxtFull = string.Format("{0}:", printerModelLabelTxt);
|
2014-02-05 18:29:58 -08:00
|
|
|
|
TextWidget printerModelLabel = new TextWidget(printerModelLabelTxtFull, 0, 0, 12);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerModelLabel.TextColor = this.defaultTextColor;
|
|
|
|
|
|
printerModelLabel.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerModelLabel.Margin = elementMargin;
|
|
|
|
|
|
|
|
|
|
|
|
ModelChooser printerModelSelector = new ModelChooser(make);
|
|
|
|
|
|
printerModelSelector.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerModelSelector.Margin = elementMargin;
|
|
|
|
|
|
printerModelSelector.ModelDropList.SelectionChanged += new EventHandler(ModelDropList_SelectionChanged);
|
2014-07-16 14:13:49 -07:00
|
|
|
|
printerModelSelector.SelectIfOnlyOneModel();
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-03-11 15:24:47 -07:00
|
|
|
|
printerModelError = new TextWidget(LocalizedString.Get("Select the printer model"), 0, 0, 10);
|
2014-03-24 14:44:43 -07:00
|
|
|
|
printerModelError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
printerModelError.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
printerModelError.Margin = elementMargin;
|
|
|
|
|
|
|
|
|
|
|
|
container.AddChild(printerModelLabel);
|
|
|
|
|
|
container.AddChild(printerModelSelector);
|
|
|
|
|
|
container.AddChild(printerModelError);
|
|
|
|
|
|
|
|
|
|
|
|
container.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ManufacturerDropList_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-02-04 12:13:56 -08:00
|
|
|
|
ActivePrinter.Make = ((DropDownList)sender).SelectedValue;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
ActivePrinter.Model = null;
|
|
|
|
|
|
ReconstructModelSelector();
|
|
|
|
|
|
SetElementState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ReconstructModelSelector()
|
|
|
|
|
|
{
|
|
|
|
|
|
//reconstruct model selector
|
|
|
|
|
|
int currentIndex = contentRow.GetChildIndex(printerModelContainer);
|
|
|
|
|
|
contentRow.RemoveChild(printerModelContainer);
|
2015-11-02 17:54:26 -08:00
|
|
|
|
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
printerModelContainer = createPrinterModelContainer(ActivePrinter.Make);
|
|
|
|
|
|
contentRow.AddChild(printerModelContainer, currentIndex);
|
|
|
|
|
|
contentRow.Invalidate();
|
|
|
|
|
|
|
|
|
|
|
|
printerMakeError.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ModelDropList_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2015-06-11 12:06:40 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
ActivePrinter.Model = ((DropDownList)sender).SelectedLabel;
|
|
|
|
|
|
currentPrinterSetupStatus.LoadSetupSettings(ActivePrinter.Make, ActivePrinter.Model);
|
|
|
|
|
|
printerModelError.Visible = false;
|
|
|
|
|
|
SetElementState();
|
|
|
|
|
|
if (usingDefaultName)
|
|
|
|
|
|
{
|
2016-02-04 12:13:56 -08:00
|
|
|
|
// Use ManufacturerDropList.SelectedLabel instead of ActivePrinter.Make to ensure the mapped Unicode values are picked up
|
|
|
|
|
|
string mappedMakeText = printerManufacturerSelector.ManufacturerDropList.SelectedLabel;
|
|
|
|
|
|
|
|
|
|
|
|
string printerInputName = String.Format("{0} {1}", mappedMakeText, this.ActivePrinter.Model);
|
2015-10-20 10:30:13 -07:00
|
|
|
|
string query = "SELECT Name FROM Printer WHERE Name LIKE @printerName;";
|
|
|
|
|
|
var names = Datastore.Instance.dbSQLite.Query<sqlName>(query, printerInputName + "%").Select(item => item.Name).ToList();
|
2015-04-17 20:14:20 -07:00
|
|
|
|
|
|
|
|
|
|
if (!names.Contains(printerInputName))
|
|
|
|
|
|
{
|
|
|
|
|
|
printerNameInput.Text = printerInputName;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
int printerModelCount = 0; //Used to keep track of how many of the printer models we run into before and empty one
|
|
|
|
|
|
string possiblePrinterName;
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
printerModelCount++;
|
2016-02-04 12:13:56 -08:00
|
|
|
|
possiblePrinterName = String.Format("{0} ({1})", printerInputName, printerModelCount);
|
2015-04-17 20:14:20 -07:00
|
|
|
|
} while (names.Contains(possiblePrinterName));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printerNameInput.Text = possiblePrinterName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-10-31 09:36:30 -07:00
|
|
|
|
private void PrinterNameInput_KeyPressed(object sender, KeyPressEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.usingDefaultName = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void MoveToNextWidget()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-05-30 12:48:45 -07:00
|
|
|
|
if (Parent != null) // if it hasn't been closed
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-05-30 12:48:45 -07:00
|
|
|
|
if (this.ActivePrinter.BaudRate == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Parent.AddChild(new SetupStepBaudRate((ConnectionWindow)Parent, Parent, this.currentPrinterSetupStatus));
|
|
|
|
|
|
Parent.RemoveChild(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.currentPrinterSetupStatus.DriversToInstall.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Parent.AddChild(new SetupStepInstallDriver((ConnectionWindow)Parent, Parent, this.currentPrinterSetupStatus));
|
|
|
|
|
|
Parent.RemoveChild(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Parent.AddChild(new SetupStepComPortOne((ConnectionWindow)Parent, Parent, this.currentPrinterSetupStatus));
|
|
|
|
|
|
Parent.RemoveChild(this);
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-06 18:47:35 -07:00
|
|
|
|
private void NextButton_Click(object sender, EventArgs mouseEvent)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
bool canContinue = this.OnSave();
|
|
|
|
|
|
if (canContinue)
|
|
|
|
|
|
{
|
2015-10-06 18:47:35 -07:00
|
|
|
|
this.currentPrinterSetupStatus.LoadCalibrationPrints();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
UiThread.RunOnIdle(MoveToNextWidget);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-10-29 17:46:05 -07:00
|
|
|
|
|
|
|
|
|
|
public int ExistingPrinterCount()
|
|
|
|
|
|
{
|
2016-02-23 11:15:03 -08:00
|
|
|
|
return Datastore.Instance.RecordCount("Printer");
|
2014-10-29 17:46:05 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-02-23 11:15:03 -08:00
|
|
|
|
private class sqlName
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
}
|
2015-04-17 20:14:20 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private bool OnSave()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (printerNameInput.Text != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ActivePrinter.Name = printerNameInput.Text;
|
|
|
|
|
|
if (this.ActivePrinter.Make == null || this.ActivePrinter.Model == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2015-09-29 17:21:55 -07:00
|
|
|
|
Datastore.Instance.dbSQLite.RunInTransaction(currentPrinterSetupStatus.Save);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this.printerNameError.TextColor = RGBA_Bytes.Red;
|
2014-02-05 18:29:58 -08:00
|
|
|
|
this.printerNameError.Text = "Printer name cannot be blank";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
this.printerNameError.Visible = true;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|