Remove specialized PrinterSetup helpers from WizardWindow

This commit is contained in:
John Lewin 2017-10-18 14:56:10 -07:00
parent b4b3dfea9d
commit 8ff0db18cd
14 changed files with 178 additions and 105 deletions

View file

@ -58,6 +58,7 @@ namespace MatterHackers.MatterControl
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.SimplePartScripting;
using MatterHackers.MeshVisualizer;
using MatterHackers.SerialPortCommunication;
@ -783,13 +784,13 @@ namespace MatterHackers.MatterControl
// Pushing this after load fixes that empty printer list
ApplicationController.Instance.UserChanged();
bool showAuthWindow = WizardWindow.ShouldShowAuthPanel?.Invoke() ?? false;
bool showAuthWindow = PrinterSetup.ShouldShowAuthPanel?.Invoke() ?? false;
if (showAuthWindow)
{
if (ApplicationSettings.Instance.get(ApplicationSettingsKey.SuppressAuthPanel) != "True")
{
//Launch window to prompt user to sign in
UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup());
UiThread.RunOnIdle(() => WizardWindow.Show(PrinterSetup.GetBestStartPage()));
}
}
else
@ -834,7 +835,7 @@ namespace MatterHackers.MatterControl
if (!ProfileManager.Instance.ActiveProfiles.Any())
{
// Start the setup wizard if no profiles exist
UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup());
UiThread.RunOnIdle(() => WizardWindow.Show(PrinterSetup.GetBestStartPage()));
}
}

View file

@ -159,6 +159,7 @@
<Compile Include="PartPreviewWindow\PopupButton.cs" />
<Compile Include="PartPreviewWindow\View3D\DifferenceObject3D.cs" />
<Compile Include="PartPreviewWindow\View3D\SlicePopupMenu.cs" />
<Compile Include="PrinterControls\PrinterConnections\PrinterSetup.cs" />
<Compile Include="Utilities\InspectForm.cs" Condition="'$(Configuration)' == 'Debug'">
<SubType>Form</SubType>
</Compile>

View file

@ -31,6 +31,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.SlicerConfiguration;
@ -76,7 +77,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
UiThread.RunOnIdle(() =>
{
WizardWindow.ShowPrinterSetup(true);
WizardWindow.Show(PrinterSetup.GetBestStartPage(PrinterSetup.StartPageOptions.ShowMakeModel));
});
}
};

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2014, Lars Brubaker, John Lewin
Copyright (c) 2017, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -29,21 +29,94 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
using System;
using System.IO;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class SelectedObjectPanel : FlowLayoutWidget
{
public SelectedObjectPanel() : base(FlowDirection.TopToBottom)
private IObject3D item = new Object3D();
private GuiWidget editorPanel;
private TextWidget itemName;
public SelectedObjectPanel(View3DWidget view3DWidget, ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
HAnchor |= HAnchor.Right;
VAnchor = VAnchor.Top | VAnchor.Fit;
this.HAnchor |= HAnchor.Right;
this.VAnchor = VAnchor.Top | VAnchor.Fit;
this.Padding = new BorderDouble(8, 10);
this.MinimumSize = new VectorMath.Vector2(180, 0);
this.AddChild(itemName = new TextWidget("", textColor: ActiveTheme.Instance.PrimaryTextColor)
{
AutoExpandBoundsToText = true,
EllipsisIfClipped = true,
Margin = new BorderDouble(bottom: 10)
});
var behavior3DTypeButtons = new FlowLayoutWidget();
this.AddChild(behavior3DTypeButtons);
var buttonMargin = new BorderDouble(2, 5);
// put in the button for making the behavior solid
var solidButtonView = theme.ButtonFactory.Generate("Color".Localize());
var solidBehaviorButton = new PopupButton(solidButtonView)
{
Name = "Solid Colors",
AlignToRightEdge = true,
PopupContent = new ColorSwatchSelector(item, view3DWidget)
{
HAnchor = HAnchor.Fit,
VAnchor = VAnchor.Fit,
BackgroundColor = RGBA_Bytes.White
},
Margin = buttonMargin
};
solidBehaviorButton.Click += (s, e) =>
{
item.OutputType = PrintOutputTypes.Solid;
};
behavior3DTypeButtons.AddChild(solidBehaviorButton);
var objectActionList = new DropDownList("Actions", maxHeight: 200)
{
HAnchor = HAnchor.Stretch
};
foreach (var namedAction in ApplicationController.Instance.RegisteredSceneOperations())
{
var menuItem = objectActionList.AddItem(namedAction.Title.Localize());
menuItem.Click += (s, e) =>
{
namedAction.Action.Invoke(ApplicationController.Instance.ActivePrinter.Bed.Scene);
};
}
this.AddChild(objectActionList);
this.AddChild(editorPanel = new GuiWidget()
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
Margin = new BorderDouble(top: 10)
});
}
public void SetActiveItem(IObject3D selectedItem, GuiWidget editorWidget)
{
this.itemName.Text = selectedItem.Name ?? selectedItem.GetType().Name;
this.item = selectedItem;
this.editorPanel.RemoveAllChildren();
this.editorPanel.AddChild(editorWidget);
this.Visible = true;
}
}
}

View file

@ -42,6 +42,7 @@ using MatterHackers.GCodeVisualizer;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication.Io;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication;
@ -1011,7 +1012,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
// Only pop up the com port helper if the USER actually CLICKED the connect button.
if (showHelpIfNoPort)
{
WizardWindow.ShowComPortSetup(printer);
WizardWindow.Show(new SetupStepComPortOne(printer));
}
#endif
}

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
public static class PrinterSetup
{
public static Func<bool> ShouldShowAuthPanel { get; set; }
public static Action ShowAuthDialog;
public static Action ChangeToAccountCreate;
public enum StartPageOptions { Default, SkipWifiSetup, ShowMakeModel }
public static WizardPage GetBestStartPage(StartPageOptions options = StartPageOptions.Default)
{
// Do the printer setup logic
bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected();
if (!WifiDetected
&& options != StartPageOptions.SkipWifiSetup)
{
return new SetupWizardWifi();
}
else if (ShouldShowAuthPanel?.Invoke() == true
&& options != StartPageOptions.ShowMakeModel)
{
return new ShowAuthPanel();
}
else
{
return new SetupStepMakeModelName();
}
}
}
}

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.SlicerConfiguration;
@ -64,7 +65,15 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
UiThread.RunOnIdle(() =>
{
WizardWindow.ChangeToInstallDriverOrComPortOne(printer);
if (SetupStepInstallDriver.PrinterDrivers(printer).Count > 0
&& AggContext.OperatingSystem == OSType.Windows)
{
this.WizardWindow.ChangeToPage(new SetupStepInstallDriver(printer));
}
else
{
this.WizardWindow.ChangeToPage(new SetupStepComPortOne(printer));
}
});
}
};

View file

@ -30,7 +30,6 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
@ -38,6 +37,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
public SetupStepComPortOne(PrinterConfig printer)
{
this.WindowTitle = "Setup Wizard".Localize();
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
VAnchor = VAnchor.Stretch,

View file

@ -90,18 +90,30 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
bool canContinue = this.InstallDriver();
if (canContinue)
{
WizardWindow.ChangeToSetupBaudOrComPortOne(printer);
this.ChangeToSetupBaudOrComPortOne();
}
});
};
skipButton = textImageButtonFactory.Generate("Skip".Localize());
skipButton.Click += (s, e) => WizardWindow.ChangeToSetupBaudOrComPortOne(printer);
skipButton.Click += (s, e) => this.ChangeToSetupBaudOrComPortOne();
this.AddPageAction(installButton);
this.AddPageAction(skipButton);
}
private void ChangeToSetupBaudOrComPortOne()
{
if (string.IsNullOrEmpty(printer.Settings.GetValue(SettingsKey.baud_rate)))
{
this.WizardWindow.ChangeToPage(new SetupStepBaudRate(printer));
}
else
{
this.WizardWindow.ChangeToPage(new SetupStepComPortOne(printer));
}
}
private void InstallDriver(string fileName)
{
switch (AggContext.OperatingSystem)

View file

@ -64,6 +64,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
public SetupStepMakeModelName()
{
this.WindowTitle = "Setup Wizard".Localize();
printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), maxHeight: 200)
{
HAnchor = HAnchor.Stretch,

View file

@ -41,6 +41,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
public ShowAuthPanel()
: base ("Skip")
{
this.WindowTitle = "Setup Wizard".Localize();
WrappedTextWidget userSignInPromptLabel = new WrappedTextWidget("Sign in to access your cloud printer profiles.\n\nOnce signed in you will be able to access:".Localize())
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
@ -76,7 +78,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
UiThread.RunOnIdle (() =>
{
WizardWindow.Close();
WizardWindow.ChangeToAccountCreate();
PrinterSetup.ChangeToAccountCreate();
});
};
@ -87,7 +89,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
UiThread.RunOnIdle (() =>
{
WizardWindow.Close();
WizardWindow.ShowAuthDialog?.Invoke();
PrinterSetup.ShowAuthDialog?.Invoke();
});
};

View file

@ -31,6 +31,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
namespace MatterHackers.MatterControl
{
@ -39,6 +40,8 @@ namespace MatterHackers.MatterControl
{
public SetupWizardWifi()
{
this.WindowTitle = "Setup Wizard".Localize();
contentRow.AddChild(new TextWidget("Wifi Setup".Localize() + ":", 0, 0, labelFontSize)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
@ -56,22 +59,10 @@ namespace MatterHackers.MatterControl
//Construct buttons
Button skipButton = whiteImageButtonFactory.Generate("Skip".Localize());
skipButton.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
this.WizardWindow.ChangeToSetupPrinterForm();
});
};
skipButton.Click += Continue_Click;
Button nextButton = textImageButtonFactory.Generate("Continue".Localize());
nextButton.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
this.WizardWindow.ChangeToSetupPrinterForm();
});
};
nextButton.Click += Continue_Click;
nextButton.Visible = false;
Button configureButton = whiteImageButtonFactory.Generate("Configure".Localize());
@ -95,5 +86,13 @@ namespace MatterHackers.MatterControl
this.AddPageAction(nextButton);
}
private void Continue_Click(object sender, MouseEventArgs e)
{
UiThread.RunOnIdle(() =>
{
this.WizardWindow.ChangeToPage(PrinterSetup.GetBestStartPage());
});
}
}
}

View file

@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
namespace MatterHackers.MatterControl.SetupWizard
{
@ -30,7 +31,10 @@ namespace MatterHackers.MatterControl.SetupWizard
if (!ProfileManager.Instance.ActiveProfiles.Any())
{
// Switch to setup wizard if no profiles exist
UiThread.RunOnIdle(() => WizardWindow.ChangeToSetupPrinterForm());
UiThread.RunOnIdle(() =>
{
WizardWindow.Show(PrinterSetup.GetBestStartPage());
});
}
else if (ProfileManager.Instance.ActiveProfiles.Count() == 1)
{

View file

@ -13,9 +13,6 @@ namespace MatterHackers.MatterControl
public class WizardWindow : SystemWindow
{
private EventHandler unregisterEvents;
public static Func<bool> ShouldShowAuthPanel { get; set; }
public static Action ShowAuthDialog;
public static Action ChangeToAccountCreate;
private static Dictionary<Type, WizardWindow> allWindows = new Dictionary<Type, WizardWindow>();
@ -26,8 +23,6 @@ namespace MatterHackers.MatterControl
this.MinimumSize = new Vector2(200, 200);
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.Padding = new BorderDouble(8);
this.ShowAsSystemWindow();
}
public static void Close(Type type)
@ -78,32 +73,6 @@ namespace MatterHackers.MatterControl
wizardWindow.ShowAsSystemWindow();
}
public static void ShowPrinterSetup(bool userRequestedNewPrinter = false)
{
WizardWindow wizardWindow = GetWindow(typeof(SetupStepComPortOne));
wizardWindow.Title = "Setup Wizard".Localize();
// Do the printer setup logic
// Todo - detect wifi connectivity
bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected();
if (!WifiDetected)
{
wizardWindow.ChangeToPage<SetupWizardWifi>();
}
else
{
wizardWindow.ChangeToSetupPrinterForm(userRequestedNewPrinter);
}
}
public static void ShowComPortSetup(PrinterConfig printer)
{
WizardWindow wizardWindow = GetWindow(typeof(SetupStepComPortOne));
wizardWindow.Title = "Setup Wizard".Localize();
wizardWindow.ChangeToPage(new SetupStepComPortOne(printer));
}
public static bool IsOpen(Type type)
{
WizardWindow wizardWindow;
@ -140,45 +109,6 @@ namespace MatterHackers.MatterControl
base.OnClosed(e);
}
public void ChangeToSetupPrinterForm(bool userRequestedNewPrinter = false)
{
bool showAuthPanel = ShouldShowAuthPanel?.Invoke() ?? false;
if (showAuthPanel
&& !userRequestedNewPrinter)
{
ChangeToPage<ShowAuthPanel>();
}
else
{
ChangeToPage<SetupStepMakeModelName>();
}
}
internal void ChangeToInstallDriverOrComPortOne(PrinterConfig printer)
{
if (SetupStepInstallDriver.PrinterDrivers(printer).Count > 0
&& AggContext.OperatingSystem == OSType.Windows)
{
ChangeToPage(new SetupStepInstallDriver(printer));
}
else
{
ChangeToPage(new SetupStepComPortOne(printer));
}
}
internal void ChangeToSetupBaudOrComPortOne(PrinterConfig printer)
{
if (string.IsNullOrEmpty(printer.Settings.GetValue(SettingsKey.baud_rate)))
{
ChangeToPage(new SetupStepBaudRate(printer));
}
else
{
ChangeToPage(new SetupStepComPortOne(printer));
}
}
public void ChangeToPage(WizardPage pageToChangeTo)
{
activePage = pageToChangeTo;