2016-06-01 18:17:11 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2016-07-28 12:04:43 -07:00
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
2016-06-01 18:17:11 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2016-06-07 14:27:37 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2016-06-01 18:17:11 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2016-05-31 16:58:06 -07:00
|
|
|
|
using System;
|
2016-06-08 16:52:56 -07:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-01 18:17:11 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public class WizardWindow : SystemWindow
|
|
|
|
|
|
{
|
2016-12-09 10:40:01 -08:00
|
|
|
|
private event EventHandler unregisterEvents;
|
2016-06-07 15:45:50 -07:00
|
|
|
|
public static Func<bool> ShouldShowAuthPanel { get; set; }
|
|
|
|
|
|
public static Action ShowAuthDialog;
|
2016-07-14 11:29:46 -07:00
|
|
|
|
public static Action ChangeToAccountCreate;
|
2016-06-07 15:45:50 -07:00
|
|
|
|
|
2016-06-08 16:52:56 -07:00
|
|
|
|
private static Dictionary<string, WizardWindow> allWindows = new Dictionary<string, WizardWindow>();
|
|
|
|
|
|
|
|
|
|
|
|
private WizardWindow()
|
|
|
|
|
|
: base(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale)
|
|
|
|
|
|
{
|
2016-06-10 15:26:25 -07:00
|
|
|
|
this.AlwaysOnTopOfMain = true;
|
|
|
|
|
|
|
2016-06-08 16:52:56 -07:00
|
|
|
|
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
|
|
|
|
this.Padding = new BorderDouble(8);
|
|
|
|
|
|
this.MinimumSize = new Vector2(350 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale);
|
2016-06-01 18:17:11 -07:00
|
|
|
|
|
|
|
|
|
|
this.ShowAsSystemWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-08 18:26:08 -07:00
|
|
|
|
public static void Close(string uri)
|
|
|
|
|
|
{
|
|
|
|
|
|
WizardWindow existingWindow;
|
|
|
|
|
|
|
|
|
|
|
|
if (allWindows.TryGetValue(uri, out existingWindow))
|
|
|
|
|
|
{
|
|
|
|
|
|
existingWindow.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-08 16:52:56 -07:00
|
|
|
|
public static void Show<PanelType>(string uri, string title) where PanelType : WizardPage, new()
|
|
|
|
|
|
{
|
2016-07-13 17:12:45 -07:00
|
|
|
|
WizardWindow wizardWindow = GetWindow(uri);
|
|
|
|
|
|
wizardWindow.Title = title;
|
|
|
|
|
|
wizardWindow.ChangeToPage<PanelType>();
|
|
|
|
|
|
}
|
2016-06-08 16:52:56 -07:00
|
|
|
|
|
2016-07-13 17:12:45 -07:00
|
|
|
|
public static void Show(string uri, string title, WizardPage wizardPage)
|
|
|
|
|
|
{
|
|
|
|
|
|
WizardWindow wizardWindow = GetWindow(uri);
|
|
|
|
|
|
wizardWindow.Title = title;
|
|
|
|
|
|
wizardWindow.ChangeToPage(wizardPage);
|
2016-06-08 16:52:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-01 17:21:31 -07:00
|
|
|
|
public static void ShowPrinterSetup(bool userRequestedNewPrinter = false)
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2016-07-21 13:49:22 -07:00
|
|
|
|
WizardWindow wizardWindow = GetWindow("PrinterSetup");
|
|
|
|
|
|
wizardWindow.Title = "Setup Wizard".Localize();
|
|
|
|
|
|
|
|
|
|
|
|
// Do the printer setup logic
|
|
|
|
|
|
// Todo - detect wifi connectivity
|
|
|
|
|
|
bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected();
|
|
|
|
|
|
if (!WifiDetected)
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2016-07-21 13:49:22 -07:00
|
|
|
|
wizardWindow.ChangeToPage<SetupWizardWifi>();
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-08-01 17:21:31 -07:00
|
|
|
|
wizardWindow.ChangeToSetupPrinterForm(userRequestedNewPrinter);
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-21 13:49:22 -07:00
|
|
|
|
public static void ShowComPortSetup()
|
|
|
|
|
|
{
|
|
|
|
|
|
WizardWindow wizardWindow = GetWindow("PrinterSetup");
|
|
|
|
|
|
wizardWindow.Title = "Setup Wizard".Localize();
|
|
|
|
|
|
|
2016-07-28 11:53:10 -07:00
|
|
|
|
wizardWindow.ChangeToPage<SetupStepComPortOne>();
|
2016-07-21 13:49:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool IsOpen(string uri)
|
|
|
|
|
|
{
|
|
|
|
|
|
WizardWindow wizardWindow;
|
|
|
|
|
|
|
|
|
|
|
|
if (allWindows.TryGetValue(uri, out wizardWindow))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-13 17:12:45 -07:00
|
|
|
|
private static WizardWindow GetWindow(string uri)
|
|
|
|
|
|
{
|
|
|
|
|
|
WizardWindow wizardWindow;
|
|
|
|
|
|
|
|
|
|
|
|
if (allWindows.TryGetValue(uri, out wizardWindow))
|
|
|
|
|
|
{
|
|
|
|
|
|
wizardWindow.BringToFront();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
wizardWindow = new WizardWindow();
|
|
|
|
|
|
wizardWindow.Closed += (s, e) => allWindows.Remove(uri);
|
|
|
|
|
|
allWindows[uri] = wizardWindow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return wizardWindow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-08 16:52:56 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
|
|
|
|
|
{
|
2016-12-09 10:40:01 -08:00
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
2016-06-08 16:52:56 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-01 17:21:31 -07:00
|
|
|
|
public void ChangeToSetupPrinterForm(bool userRequestedNewPrinter = false)
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2016-05-31 16:58:06 -07:00
|
|
|
|
bool showAuthPanel = ShouldShowAuthPanel?.Invoke() ?? false;
|
2016-08-01 17:21:31 -07:00
|
|
|
|
if (showAuthPanel
|
|
|
|
|
|
&& !userRequestedNewPrinter)
|
2016-05-31 16:58:06 -07:00
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
ChangeToPage<ShowAuthPanel>();
|
2016-05-31 16:58:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
ChangeToPage<SetupStepMakeModelName>();
|
2016-05-31 16:58:06 -07:00
|
|
|
|
}
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void ChangeToInstallDriverOrComPortOne()
|
|
|
|
|
|
{
|
2016-07-28 12:04:43 -07:00
|
|
|
|
if (SetupStepInstallDriver.PrinterDrivers().Count > 0
|
|
|
|
|
|
&& OsInformation.OperatingSystem == OSType.Windows)
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
ChangeToPage<SetupStepInstallDriver>();
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
ChangeToPage<SetupStepComPortOne>();
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void ChangeToSetupBaudOrComPortOne()
|
|
|
|
|
|
{
|
2016-07-12 17:46:48 -07:00
|
|
|
|
if (string.IsNullOrEmpty(PrinterConnectionAndCommunication.Instance?.ActivePrinter?.GetValue(SettingsKey.baud_rate)))
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
ChangeToPage<SetupStepBaudRate>();
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-06-08 09:31:26 -07:00
|
|
|
|
ChangeToPage<SetupStepComPortOne>();
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-07 17:23:41 -07:00
|
|
|
|
|
2016-06-15 11:49:57 -07:00
|
|
|
|
internal void ChangeToPage(WizardPage pageToChangeTo)
|
|
|
|
|
|
{
|
|
|
|
|
|
pageToChangeTo.WizardWindow = this;
|
2016-12-09 12:09:28 -08:00
|
|
|
|
this.CloseAllChildren();
|
|
|
|
|
|
this.AddChild(pageToChangeTo);
|
|
|
|
|
|
this.Invalidate();
|
2016-06-15 11:49:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-08 09:31:26 -07:00
|
|
|
|
internal void ChangeToPage<PanelType>() where PanelType : WizardPage, new()
|
2016-06-07 17:23:41 -07:00
|
|
|
|
{
|
2016-12-09 10:40:01 -08:00
|
|
|
|
PanelType panel = new PanelType();
|
|
|
|
|
|
ChangeToPage(panel);
|
|
|
|
|
|
|
|
|
|
|
|
// in the event of a reload all make sure we rebuild the contents correctly
|
|
|
|
|
|
ApplicationController.Instance.DoneReloadingAll.RegisterEvent((s,e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// fix the main window background color if needed
|
|
|
|
|
|
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
|
|
|
|
|
|
|
|
|
|
// find out where the contents we put in last time are
|
|
|
|
|
|
int thisIndex = GetChildIndex(panel);
|
2016-12-09 12:09:28 -08:00
|
|
|
|
RemoveAllChildren();
|
2016-12-09 10:40:01 -08:00
|
|
|
|
// make new content with the possibly changed theme
|
|
|
|
|
|
PanelType newPanel = new PanelType();
|
2016-12-09 12:09:28 -08:00
|
|
|
|
newPanel.WizardWindow = this;
|
2016-12-09 10:40:01 -08:00
|
|
|
|
AddChild(newPanel, thisIndex);
|
|
|
|
|
|
panel.CloseOnIdle();
|
|
|
|
|
|
// remember the new content
|
|
|
|
|
|
panel = newPanel;
|
|
|
|
|
|
}, ref unregisterEvents);
|
2016-06-07 17:23:41 -07:00
|
|
|
|
}
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|