mattercontrol/PrinterControls/PrinterConnections/ConnectionWindow.cs

120 lines
2.7 KiB
C#
Raw Normal View History

2016-04-18 11:31:31 -07:00
using System;
using MatterHackers.Agg.UI;
2014-01-29 19:09:30 -08:00
using MatterHackers.Localizations;
2015-04-08 15:20:10 -07:00
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.VectorMath;
2016-04-18 11:31:31 -07:00
using System.Collections.Generic;
using MatterHackers.Agg.PlatformAbstract;
using System.IO;
using MatterHackers.MatterControl.SlicerConfiguration;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
2016-04-18 11:31:31 -07:00
public class ConnectionWizard : SystemWindow
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
protected PrinterInfo activePrinter;
2015-04-08 15:20:10 -07:00
private bool editMode = false;
2016-04-18 11:31:31 -07:00
public ConnectionWizard()
: base(350 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale)
2015-04-08 15:20:10 -07:00
{
AlwaysOnTopOfMain = true;
string connectToPrinterTitle = LocalizedString.Get("MatterControl");
string connectToPrinterTitleEnd = LocalizedString.Get("Connect to Printer");
Title = string.Format("{0} - {1}", connectToPrinterTitle, connectToPrinterTitleEnd);
2016-03-04 14:36:49 -08:00
Name = "Printer Connection Window";
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
ChangeToAddPrinter();
2015-04-08 15:20:10 -07:00
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.ShowAsSystemWindow();
MinimumSize = new Vector2(350 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale);
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
private static ConnectionWizard connectionWindow = null;
2015-04-08 15:20:10 -07:00
public static void Show()
{
2016-04-18 11:31:31 -07:00
if (connectionWindow != null)
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
connectionWindow.BringToFront();
2015-04-08 15:20:10 -07:00
}
else
2016-04-18 11:31:31 -07:00
{
connectionWindow = new ConnectionWizard();
connectionWindow.Closed += (s, e) => connectionWindow = null;
2015-04-08 15:20:10 -07:00
}
}
2016-04-18 11:31:31 -07:00
internal void ChangeToAddPrinter()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
this.activePrinter = null;
ChangeToStep(new SetupStepMakeModelName(this));
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
private void ChangeToStep(GuiWidget nextStep)
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
UiThread.RunOnIdle(() =>
{
this.RemoveAllChildren();
this.AddChild(nextStep);
this.Invalidate();
});
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
private int GetPrinterRecordCount()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
return Datastore.Instance.RecordCount("Printer");
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2016-04-18 11:31:31 -07:00
internal void ChangeToSetupBaudRate()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
ChangeToStep(new SetupStepBaudRate(this));
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
internal void ChangeToInstallDriver()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
ChangeToStep(new SetupStepInstallDriver(this));
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
internal void ChangeToSetupComPortOne()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
ChangeToStep(new SetupStepComPortOne(this));
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
internal void ChangeToSetupCompPortTwo()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
ChangeToStep(new SetupStepComPortTwo(this));
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2016-04-18 11:31:31 -07:00
internal void ChangeToSetupComPortManual()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
ChangeToStep(new SetupStepComPortManual(this));
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
internal void ChangeToInstallDriverOrComPortOne()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if (ActiveSliceSettings.Instance.PrinterDrivers().Count > 0)
{
ChangeToInstallDriver();
}
else
{
ChangeToSetupComPortOne();
}
}
internal void ChangeToSetupBaudOrComPortOne()
{
if (string.IsNullOrEmpty(activePrinter.BaudRate))
{
ChangeToSetupBaudRate();
}
else
{
ChangeToSetupComPortOne();
}
2015-04-08 15:20:10 -07:00
}
}
}