Unified the android and desktop setup wizard classes

This commit is contained in:
Lars Brubaker 2016-06-01 18:17:11 -07:00
parent 6acbe7f2d3
commit b54e6a14ad
25 changed files with 1850 additions and 227 deletions

View file

@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl
{
this.AddChild(new ActionBar.PrinterActionRow());
}
this.AddChild(new PrintStatusRow(queueDataView));
this.AddChild(PrintStatusRow.Create(queueDataView));
this.Padding = new BorderDouble(bottom: 6);
// Add Handlers

View file

@ -437,7 +437,7 @@ namespace MatterHackers.MatterControl.ActionBar
if (ActiveSliceSettings.Instance == null)
{
#if __ANDROID__
SetupWizardWindow.Show();
WizardWindow.Show();
#else
PrinterActionRow.OpenConnectionWindow(true);
#endif

View file

@ -32,61 +32,22 @@ using MatterHackers.Agg.Image;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.GuiAutomation;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
namespace MatterHackers.MatterControl.ActionBar
{
public class PrintStatusRow : FlowLayoutWidget
{
private static FlowLayoutWidget iconContainer;
private TextWidget activePrintInfo;
private TextWidget activePrintLabel;
private TextWidget activePrintName;
private PartThumbnailWidget activePrintPreviewImage;
private TextWidget activePrintStatus;
private TemperatureWidgetBase bedTemperatureWidget;
private TemperatureWidgetBase extruderTemperatureWidget;
private QueueDataView queueDataView;
private TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
public PrintStatusRow(QueueDataView queueDataView)
{
Initialize();
this.HAnchor = HAnchor.ParentLeftRight;
this.queueDataView = queueDataView;
AddChildElements();
AddHandlers();
onActivePrintItemChanged(null, null);
if (privateAddIconToPrintStatusRow != null)
{
privateAddIconToPrintStatusRow(iconContainer);
}
}
protected static event Action<GuiWidget> privateAddIconToPrintStatusRow;
protected static FlowLayoutWidget iconContainer;
public static event Action<GuiWidget> AddIconToPrintStatusRow
{
add
@ -102,9 +63,58 @@ namespace MatterHackers.MatterControl.ActionBar
}
}
private static event Action<GuiWidget> privateAddIconToPrintStatusRow;
public static GuiWidget Create(QueueDataView queueDataView)
{
if (ActiveTheme.Instance.IsTouchScreen)
{
return new TouchScreenPrintStatusRow(queueDataView);
}
else
{
return new DesktopPrintStatusRow(queueDataView);
}
}
protected PrintStatusRow()
{
}
protected void DoAddIconToPrintStatusRow()
{
privateAddIconToPrintStatusRow?.Invoke(iconContainer);
}
}
public class DesktopPrintStatusRow : PrintStatusRow
{
private TextWidget activePrintInfo;
private TextWidget activePrintLabel;
private TextWidget activePrintName;
private PartThumbnailWidget activePrintPreviewImage;
private TextWidget activePrintStatus;
private TemperatureWidgetBase bedTemperatureWidget;
private TemperatureWidgetBase extruderTemperatureWidget;
private QueueDataView queueDataView;
private TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
public DesktopPrintStatusRow(QueueDataView queueDataView)
{
Initialize();
this.HAnchor = HAnchor.ParentLeftRight;
this.queueDataView = queueDataView;
AddChildElements();
AddHandlers();
onActivePrintItemChanged(null, null);
DoAddIconToPrintStatusRow();
}
private event EventHandler unregisterEvents;
private string ActivePrintStatusText
{
set
@ -242,7 +252,7 @@ namespace MatterHackers.MatterControl.ActionBar
autoLevelButton.Margin = new Agg.BorderDouble(top: 3);
autoLevelButton.ToolTipText = "Print leveling is enabled.".Localize();
autoLevelButton.Cursor = Cursors.Hand;
autoLevelButton.Click += (s, e) =>
autoLevelButton.Click += (s, e) =>
{
UiNavigation.GoToPrintLevelSettings();
};
@ -345,6 +355,7 @@ namespace MatterHackers.MatterControl.ActionBar
StringEventArgs message = e as StringEventArgs;
ActivePrintStatusText = message.Data;
}
private void SetVisibleStatus()
{
if (ActiveSliceSettings.Instance != null)
@ -359,6 +370,7 @@ namespace MatterHackers.MatterControl.ActionBar
}
}
}
private void UpdatePrintItemName()
{
if (PrinterConnectionAndCommunication.Instance.ActivePrintItem != null)
@ -475,4 +487,448 @@ namespace MatterHackers.MatterControl.ActionBar
}
}
}
public class TouchScreenPrintStatusRow : PrintStatusRow
{
private TextWidget activePrintInfo;
private TextWidget activePrintLabel;
private TextWidget activePrintName;
private PartThumbnailWidget activePrintPreviewImage;
private TextWidget activePrintStatus;
private TemperatureWidgetBase bedTemperatureWidget;
private TemperatureWidgetBase extruderTemperatureWidget;
private QueueDataView queueDataView;
private Button setupButton;
private TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
private Stopwatch timeSinceLastDrawTime = new Stopwatch();
public TouchScreenPrintStatusRow(QueueDataView queueDataView)
{
Initialize();
this.HAnchor = HAnchor.ParentLeftRight;
this.queueDataView = queueDataView;
AddChildElements();
AddHandlers();
onActivePrintItemChanged(null, null);
}
public delegate void AddIconToPrintStatusRowDelegate(GuiWidget iconContainer);
private event EventHandler unregisterEvents;
private string ActivePrintStatusText
{
set
{
if (activePrintStatus.Text != value)
{
activePrintStatus.Text = value;
}
}
}
public override void OnClosed(EventArgs e)
{
unregisterEvents?.Invoke(this, null);
base.OnClosed(e);
}
public override void OnDraw(Graphics2D graphics2D)
{
timeSinceLastDrawTime.Restart();
base.OnDraw(graphics2D);
}
public override void OnMouseUp(MouseEventArgs mouseEvent)
{
int boxSize = 20;
// Handle errors in the touch panel that push touch event positions to the screen edge by
// proxying all clicks in the target region back into the desired control
RectangleDouble topRightHitbox = new RectangleDouble(this.Width - boxSize, this.Height - boxSize, this.Width, this.Height);
if (topRightHitbox.Contains(mouseEvent.Position) && this.MouseCaptured)
{
setupButton.ClickButton(null);
return;
}
base.OnMouseUp(mouseEvent);
}
protected void AddHandlers()
{
PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(onPrintItemChanged, ref unregisterEvents);
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onStateChanged, ref unregisterEvents);
PrinterConnectionAndCommunication.Instance.WroteLine.RegisterEvent((s, e) => UpdatePrintStatus(), ref unregisterEvents);
PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(onActivePrintItemChanged, ref unregisterEvents);
}
protected void Initialize()
{
UiThread.RunOnIdle(OnIdle);
this.Margin = new BorderDouble(6, 3, 0, 0);
// Use top and right padding rather than margin to position controls but still
// ensure corner click events can be caught in this control
this.Padding = new BorderDouble(0, 0, 6, 6);
}
protected void onPrintItemChanged(object sender, EventArgs e)
{
UpdatePrintItemName();
UpdatePrintStatus();
}
private void AddChildElements()
{
FlowLayoutWidget tempWidgets = new FlowLayoutWidget();
tempWidgets.VAnchor = VAnchor.ParentBottomTop;
tempWidgets.Width = 120;
extruderTemperatureWidget = new TemperatureWidgetExtruder();
//extruderTemperatureWidget.Margin = new BorderDouble(right: 6);
extruderTemperatureWidget.VAnchor = VAnchor.ParentTop;
bedTemperatureWidget = new TemperatureWidgetBed();
bedTemperatureWidget.VAnchor = VAnchor.ParentTop;
tempWidgets.AddChild(extruderTemperatureWidget);
tempWidgets.AddChild(new GuiWidget(6, 6));
if (ActiveSliceSettings.Instance.HasHeatedBed())
{
tempWidgets.AddChild(bedTemperatureWidget);
}
tempWidgets.AddChild(new GuiWidget(6, 6));
FlowLayoutWidget printStatusContainer = CreateActivePrinterInfoWidget();
PrintActionRow printActionRow = new PrintActionRow(queueDataView);
printActionRow.VAnchor = VAnchor.ParentTop;
ImageButtonFactory factory = new ImageButtonFactory();
factory.InvertImageColor = false;
setupButton = factory.Generate(StaticData.Instance.LoadIcon("icon_gear_dot.png").InvertLightness(), null);
setupButton.Margin = new BorderDouble(left: 6);
setupButton.VAnchor = VAnchor.ParentCenter;
setupButton.Click += (sender, e) =>
{
WizardWindow.Show(true);
};
this.AddChild(printStatusContainer);
this.AddChild(printActionRow);
this.AddChild(tempWidgets);
this.AddChild(setupButton);
this.Height = 80;
UpdatePrintStatus();
UpdatePrintItemName();
}
private FlowLayoutWidget CreateActivePrinterInfoWidget()
{
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
container.Margin = new BorderDouble(6, 0, 6, 0);
container.HAnchor = HAnchor.ParentLeftRight;
container.VAnchor = VAnchor.ParentCenter;
container.Height = 80;
FlowLayoutWidget topRow = new FlowLayoutWidget();
topRow.Name = "PrintStatusRow.ActivePrinterInfo.TopRow";
topRow.HAnchor = HAnchor.ParentLeftRight;
string nextPrintLabel = LocalizedString.Get("Next Print");
string nextPrintLabelFull = string.Format("{0}:", nextPrintLabel);
activePrintLabel = getPrintStatusLabel(nextPrintLabelFull, pointSize: 11);
activePrintLabel.VAnchor = VAnchor.ParentTop;
topRow.AddChild(activePrintLabel);
FlowLayoutWidget bottomRow = new FlowLayoutWidget();
activePrintPreviewImage = new PartThumbnailWidget(null, "part_icon_transparent_100x100.png", "building_thumbnail_100x100.png", PartThumbnailWidget.ImageSizes.Size50x50);
activePrintPreviewImage.VAnchor = VAnchor.ParentTop;
activePrintPreviewImage.Padding = new BorderDouble(0);
activePrintPreviewImage.HoverBackgroundColor = new RGBA_Bytes();
activePrintPreviewImage.BorderWidth = 3;
FlowLayoutWidget labelContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
labelContainer.VAnchor |= VAnchor.ParentTop;
labelContainer.Margin = new BorderDouble(8, 0, 0, 4);
{
activePrintName = getPrintStatusLabel("this is the biggest name we will allow", pointSize: 14);
activePrintName.AutoExpandBoundsToText = false;
activePrintStatus = getPrintStatusLabel("this is the biggest label we will allow - bigger", pointSize: 11);
activePrintStatus.AutoExpandBoundsToText = false;
activePrintStatus.Text = "";
activePrintStatus.Margin = new BorderDouble(top: 3);
activePrintInfo = getPrintStatusLabel("", pointSize: 11);
activePrintInfo.AutoExpandBoundsToText = true;
labelContainer.AddChild(activePrintName);
labelContainer.AddChild(activePrintStatus);
}
bottomRow.AddChild(activePrintPreviewImage);
bottomRow.AddChild(labelContainer);
//PrintActionRow printActionRow = new PrintActionRow(queueDataView);
container.AddChild(topRow);
container.AddChild(bottomRow);
//container.AddChild(activePrintInfo);
//container.AddChild(printActionRow);
//container.AddChild(new VerticalSpacer());
//container.AddChild(new MessageActionRow());
return container;
}
private Button GetAutoLevelIndicator()
{
ImageButtonFactory imageButtonFactory = new ImageButtonFactory();
imageButtonFactory.InvertImageColor = false;
string notifyIconPath = Path.Combine("PrintStatusControls", "leveling-16x16.png");
string notifyHoverIconPath = Path.Combine("PrintStatusControls", "leveling-16x16.png");
Button autoLevelButton = imageButtonFactory.Generate(notifyIconPath, notifyHoverIconPath);
autoLevelButton.Cursor = Cursors.Hand;
autoLevelButton.Margin = new Agg.BorderDouble(top: 3);
autoLevelButton.ToolTipText = "Print leveling is enabled.".Localize();
autoLevelButton.Visible = ActiveSliceSettings.Instance.DoPrintLeveling();
ActiveSliceSettings.ActivePrinterChanged.RegisterEvent((sender, e) =>
{
autoLevelButton.Visible = ActiveSliceSettings.Instance.DoPrintLeveling();
}, ref unregisterEvents);
ActiveSliceSettings.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) =>
{
autoLevelButton.Visible = ActiveSliceSettings.Instance.DoPrintLeveling();
}, ref unregisterEvents);
return autoLevelButton;
}
private string getConnectionMessage()
{
if (ActiveSliceSettings.Instance == null)
{
return "Press 'Connect' to select a printer.".Localize();
}
else
{
switch (PrinterConnectionAndCommunication.Instance.CommunicationState)
{
case PrinterConnectionAndCommunication.CommunicationStates.Disconnected:
return "Not connected. Press 'Connect' to enable printing.".Localize();
case PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect:
return "Attempting to Connect".Localize() + "...";
case PrinterConnectionAndCommunication.CommunicationStates.ConnectionLost:
case PrinterConnectionAndCommunication.CommunicationStates.FailedToConnect:
return "Unable to communicate with printer.".Localize();
default:
return "";
}
}
}
private TextWidget getPrintStatusLabel(string text, int pointSize)
{
TextWidget widget = new TextWidget(text, pointSize: pointSize);
widget.TextColor = RGBA_Bytes.White;
widget.AutoExpandBoundsToText = true;
widget.MinimumSize = new Vector2(widget.Width, widget.Height);
return widget;
}
private void onActivePrintItemChanged(object sender, EventArgs e)
{
// first we have to remove any link to an old part (the part currently in the view)
if (activePrintPreviewImage.ItemWrapper != null)
{
activePrintPreviewImage.ItemWrapper.SlicingOutputMessage -= PrintItem_SlicingOutputMessage;
}
activePrintPreviewImage.ItemWrapper = PrinterConnectionAndCommunication.Instance.ActivePrintItem;
// then hook up our new part
if (activePrintPreviewImage.ItemWrapper != null)
{
activePrintPreviewImage.ItemWrapper.SlicingOutputMessage += PrintItem_SlicingOutputMessage;
}
activePrintPreviewImage.Invalidate();
}
private void OnIdle()
{
if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
{
if (!timeSinceLastDrawTime.IsRunning)
{
timeSinceLastDrawTime.Start();
}
else if (timeSinceLastDrawTime.ElapsedMilliseconds > 999)
{
UpdatePrintStatus();
timeSinceLastDrawTime.Restart();
}
}
if (!HasBeenClosed)
{
UiThread.RunOnIdle(OnIdle);
}
}
private void onStateChanged(object sender, EventArgs e)
{
UpdatePrintStatus();
}
private void PrintItem_SlicingOutputMessage(object sender, EventArgs e)
{
StringEventArgs message = e as StringEventArgs;
ActivePrintStatusText = message.Data;
}
private void SetVisibleStatus()
{
if (ActiveSliceSettings.Instance != null)
{
if (ActiveSliceSettings.Instance.HasHeatedBed())
{
bedTemperatureWidget.Visible = true;
}
else
{
bedTemperatureWidget.Visible = false;
}
}
}
private void UpdatePrintItemName()
{
if (PrinterConnectionAndCommunication.Instance.ActivePrintItem != null)
{
string labelName = textInfo.ToTitleCase(PrinterConnectionAndCommunication.Instance.ActivePrintItem.Name);
labelName = labelName.Replace('_', ' ');
this.activePrintName.Text = labelName;
}
else
{
this.activePrintName.Text = LocalizedString.Get("No items in the print queue");
}
}
private void UpdatePrintStatus()
{
if (PrinterConnectionAndCommunication.Instance.ActivePrintItem != null)
{
int totalSecondsInPrint = PrinterConnectionAndCommunication.Instance.TotalSecondsInPrint;
int totalHoursInPrint = (int)(totalSecondsInPrint / (60 * 60));
int totalMinutesInPrint = (int)(totalSecondsInPrint / 60 - totalHoursInPrint * 60);
totalSecondsInPrint = totalSecondsInPrint % 60;
string totalTimeLabel = LocalizedString.Get("Est. Print Time");
string calculatingLabel = LocalizedString.Get("Calculating...");
string totalPrintTimeText;
if (totalSecondsInPrint > 0)
{
if (totalHoursInPrint > 0)
{
totalPrintTimeText = string.Format("{3} {0}h {1:00}m {2:00}s",
totalHoursInPrint,
totalMinutesInPrint,
totalSecondsInPrint,
totalTimeLabel);
}
else
{
totalPrintTimeText = string.Format("{2} {0}m {1:00}s",
totalMinutesInPrint,
totalSecondsInPrint,
totalTimeLabel);
}
}
else
{
if (totalSecondsInPrint < 0)
{
totalPrintTimeText = string.Format("{0}", LocalizedString.Get("Streaming GCode..."));
}
else
{
totalPrintTimeText = string.Format("{0}: {1}", totalTimeLabel, calculatingLabel);
}
}
//GC.WaitForFullGCComplete();
string printPercentRemainingText;
string printPercentCompleteText = LocalizedString.Get("complete");
printPercentRemainingText = string.Format("{0:0.0}% {1}", PrinterConnectionAndCommunication.Instance.PercentComplete, printPercentCompleteText);
switch (PrinterConnectionAndCommunication.Instance.CommunicationState)
{
case PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint:
string preparingPrintLabel = LocalizedString.Get("Preparing To Print");
string preparingPrintLabelFull = string.Format("{0}:", preparingPrintLabel);
activePrintLabel.Text = preparingPrintLabelFull;
//ActivePrintStatusText = ""; // set by slicer
activePrintInfo.Text = "";
break;
case PrinterConnectionAndCommunication.CommunicationStates.Printing:
{
activePrintLabel.Text = PrinterConnectionAndCommunication.Instance.PrintingStateString;
ActivePrintStatusText = totalPrintTimeText;
}
break;
case PrinterConnectionAndCommunication.CommunicationStates.Paused:
{
string activePrintLabelText = LocalizedString.Get("Printing Paused");
string activePrintLabelTextFull = string.Format("{0}:", activePrintLabelText);
activePrintLabel.Text = activePrintLabelTextFull;
ActivePrintStatusText = totalPrintTimeText;
}
break;
case PrinterConnectionAndCommunication.CommunicationStates.FinishedPrint:
string donePrintingText = LocalizedString.Get("Done Printing");
string donePrintingTextFull = string.Format("{0}:", donePrintingText);
activePrintLabel.Text = donePrintingTextFull;
ActivePrintStatusText = totalPrintTimeText;
break;
default:
string nextPrintLabelActive = LocalizedString.Get("Next Print");
string nextPrintLabelActiveFull = string.Format("{0}: ", nextPrintLabelActive);
activePrintLabel.Text = nextPrintLabelActiveFull;
ActivePrintStatusText = getConnectionMessage();
break;
}
}
else
{
string nextPrintLabel = LocalizedString.Get("Next Print");
string nextPrintLabelFull = string.Format("{0}:", nextPrintLabel);
activePrintLabel.Text = nextPrintLabelFull;
ActivePrintStatusText = string.Format(LocalizedString.Get("Press 'Add' to choose an item to print"));
}
}
}
}

View file

@ -41,7 +41,6 @@ namespace MatterHackers.MatterControl.ActionBar
{
public class PrinterActionRow : ActionRowBase
{
static private ConnectionWizard connectionWindow;
private TextImageButtonFactory actionBarButtonFactory = new TextImageButtonFactory();
private Button connectPrinterButton;
private string disconnectAndCancelMessage = "Disconnect and cancel the current print?".Localize();
@ -60,19 +59,7 @@ namespace MatterHackers.MatterControl.ActionBar
ActiveSliceSettings.ActivePrinterChanged.RegisterEvent(ConnectToActivePrinter, ref staticUnregisterEvents);
}
if (connectionWindow == null)
{
connectionWindow = new ConnectionWizard();
connectionWindow.Closed += new EventHandler(ConnectionWindow_Closed);
}
else
{
if (connectionWindow != null)
{
connectionWindow.BringToFront();
}
}
WizardWindow.Show();
}
public override void OnClosed(EventArgs e)
@ -126,7 +113,7 @@ namespace MatterHackers.MatterControl.ActionBar
selectActivePrinterButton = new PrinterSelector();
selectActivePrinterButton.HAnchor = HAnchor.ParentLeftRight;
selectActivePrinterButton.Cursor = Cursors.Hand;
selectActivePrinterButton.AddPrinter += (s, e) => ConnectionWizard.Show();
selectActivePrinterButton.AddPrinter += (s, e) => WizardWindow.Show();
if (ApplicationController.Instance.WidescreenMode)
{
selectActivePrinterButton.Margin = new BorderDouble(0, 6, 0, 3);
@ -214,10 +201,6 @@ namespace MatterHackers.MatterControl.ActionBar
actionBarButtonFactory.borderWidth = 0;
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
}
static private void ConnectionWindow_Closed(object sender, EventArgs e)
{
connectionWindow = null;
}
static public void ConnectToActivePrinter(object sender, EventArgs e)
{

View file

@ -34,7 +34,7 @@ namespace MatterHackers.MatterControl
{
return new List<MenuItemAction>
{
new MenuItemAction("Add Printer".Localize(), () => ConnectionWizard.Show()),
new MenuItemAction("Add Printer".Localize(), () => WizardWindow.Show()),
new MenuItemAction("Add File To Queue".Localize(), importFile_Click),
new MenuItemAction("Redeem Design Code".Localize(), () => RedeemDesignCode?.Invoke(this, null)),
new MenuItemAction("Enter Share Code".Localize(), () => EnterShareCode?.Invoke(this, null)),

View file

@ -245,6 +245,12 @@
<Compile Include="Library\Provider\LibraryProvider.cs" />
<Compile Include="Queue\OptionsMenu\ExportGcodePlugin.cs" />
<Compile Include="Queue\OptionsMenu\MergeQueueItems.cs" />
<Compile Include="SetupWizard\SetupWizardConnect.cs" />
<Compile Include="SetupWizard\WizardPanel.cs" />
<Compile Include="SetupWizard\SetupWizardHome.cs" />
<Compile Include="SetupWizard\SetupWizardTroubleshooting.cs" />
<Compile Include="SetupWizard\SetupWizardWifi.cs" />
<Compile Include="SetupWizard\WizardWindow.cs" />
<Compile Include="SlicerConfiguration\SliceSettingsDetailControl.cs" />
<Compile Include="SlicerConfiguration\Settings\SettingsProfile.cs" />
<Compile Include="SlicerConfiguration\Settings\ActiveSliceSettings.cs" />
@ -329,7 +335,6 @@
<Compile Include="PrinterControls\PrinterConnections\SetupStepMakeModelName.cs" />
<Compile Include="PrinterControls\PrinterConnections\SetupStepBaudRate.cs" />
<Compile Include="PrinterControls\PrinterConnections\SetupStepInstallDriver.cs" />
<Compile Include="PrinterControls\PrinterConnections\ConnectionWindow.cs" />
<Compile Include="PrinterControls\ManualPrinterControls.cs" />
<Compile Include="PrinterControls\PrinterConnections\BaseConnectionWidget.cs" />
<Compile Include="PrinterControls\PrinterConnections\PrinterChooser.cs" />

View file

@ -72,6 +72,11 @@ namespace MatterHackers.MatterControl
private DataViewGraph msGraph;
private string savePartsSheetExitAnywayMessage = "You are currently saving a parts sheet, are you sure you want to exit?".Localize();
private bool ShowMemoryUsed = false;
public void ConfigureWifi()
{
}
private Stopwatch totalDrawTime = new Stopwatch();
#if true//!DEBUG
@ -798,5 +803,10 @@ namespace MatterHackers.MatterControl
MatterHackers.MeshVisualizer.MeshViewerWidget.AssertDebugNotDefined();
MatterHackers.RenderOpenGl.GLMeshTrianglePlugin.AssertDebugNotDefined();
}
public bool IsNetworkConnected()
{
return true;
}
}
}

View file

@ -37,17 +37,6 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
}
}
public class BaudRateRadioButton : RadioButton
{
public int BaudRate;
public BaudRateRadioButton(string label)
: base(label)
{
BaudRate = int.Parse(label);
}
}
public class PrinterSelectRadioButton : RadioButton
{
public PrinterInfo printer;
@ -242,7 +231,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
}
}
public class ConnectionWidgetBase : GuiWidget
public class ConnectionWidgetBase : WizardPanel
{
private static Regex linuxDefaultUIFilter = new Regex("/dev/ttyS*\\d+", RegexOptions.CultureInvariant | RegexOptions.Compiled);
protected List<SerialPortIndexRadioButton> SerialPortButtonsList = new List<SerialPortIndexRadioButton>();
@ -273,11 +262,9 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
}
}
protected ConnectionWizard connectionWizard;
public ConnectionWidgetBase(ConnectionWizard wizard)
public ConnectionWidgetBase(WizardWindow wizard)
: base(wizard)
{
this.connectionWizard = wizard;
ActiveTheme.Instance.ThemeChanged.RegisterEvent((s,e) => this.Invalidate(), ref unregisterEvents);
}

View file

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

View file

@ -20,7 +20,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
protected LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
public SetupConnectionWidgetBase(ConnectionWizard wizard) : base(wizard)
public SetupConnectionWidgetBase(WizardWindow wizard) : base(wizard)
{
SetDisplayAttributes();
@ -75,7 +75,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
settings.SetName(ActivePrinter.Name);
});
UiThread.RunOnIdle(connectionWizard.Close);
UiThread.RunOnIdle(wizardWindow.Close);
}
private void SetDisplayAttributes()
@ -97,7 +97,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private void CancelButton_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
UiThread.RunOnIdle(connectionWizard.Close);
UiThread.RunOnIdle(wizardWindow.Close);
}
}
}

View file

@ -9,7 +9,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
public class SetupStepBaudRate : SetupConnectionWidgetBase
{
private List<BaudRateRadioButton> BaudRateButtonsList = new List<BaudRateRadioButton>();
private List<RadioButton> BaudRateButtonsList = new List<RadioButton>();
private FlowLayoutWidget printerBaudRateContainer;
private TextWidget printerBaudRateError;
private GuiWidget baudRateWidget;
@ -19,7 +19,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private Button printerBaudRateHelpLink;
private TextWidget printerBaudRateHelpMessage;
public SetupStepBaudRate(ConnectionWizard connectionWizard) : base(connectionWizard)
public SetupStepBaudRate(WizardWindow connectionWizard) : base(connectionWizard)
{
linkButtonFactory.fontSize = 8;
@ -100,7 +100,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
foreach (string baudRate in baudRates)
{
BaudRateRadioButton baudOption = new BaudRateRadioButton(baudRate);
RadioButton baudOption = new RadioButton(baudRate);
BaudRateButtonsList.Add(baudOption);
baudOption.Margin = baudRateMargin;
baudOption.TextColor = ActiveTheme.Instance.PrimaryTextColor;
@ -140,7 +140,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private void BindBaudRateHandlers()
{
otherBaudRateRadioButton.CheckedStateChanged += BindBaudRate_Select;
foreach (BaudRateRadioButton button in BaudRateButtonsList)
foreach (RadioButton button in BaudRateButtonsList)
{
button.CheckedStateChanged += BindBaudRate_Select;
}
@ -161,7 +161,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private void MoveToNextWidget()
{
connectionWizard.ChangeToInstallDriverOrComPortOne();
wizardWindow.ChangeToInstallDriverOrComPortOne();
}
private void NextButton_Click(object sender, EventArgs mouseEvent)
@ -211,11 +211,11 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private string GetSelectedBaudRate()
{
foreach (BaudRateRadioButton button in BaudRateButtonsList)
foreach (RadioButton button in BaudRateButtonsList)
{
if (button.Checked)
{
return button.BaudRate.ToString();
return button.Text;
}
}
if (otherBaudRateRadioButton.Checked)

View file

@ -20,7 +20,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private event EventHandler unregisterEvents;
public SetupStepComPortManual(ConnectionWizard connectionWizard) : base(connectionWizard)
public SetupStepComPortManual(WizardWindow connectionWizard) : base(connectionWizard)
{
linkButtonFactory.fontSize = 8;
@ -125,7 +125,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private void MoveToNextWidget(object state)
{
connectionWizard.ChangeToInstallDriverOrComPortOne();
wizardWindow.ChangeToInstallDriverOrComPortOne();
}
private void ConnectButton_Click(object sender, EventArgs mouseEvent)

View file

@ -11,7 +11,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
private Button nextButton;
public SetupStepComPortOne(ConnectionWizard connectionWizard) : base(connectionWizard)
public SetupStepComPortOne(WizardWindow connectionWizard) : base(connectionWizard)
{
contentRow.AddChild(createPrinterConnectionMessageContainer());
{
@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
Button manualLink = linkButtonFactory.Generate(LocalizedString.Get("Manually Configure Connection"));
manualLink.Margin = new BorderDouble(0, 5);
manualLink.Click += (s, e) => connectionWizard.ChangeToSetupComPortManual();
manualLink.Click += (s, e) => wizardWindow.ChangeToSetupComPortManual();
string printerMessageFourText = LocalizedString.Get("or");
TextWidget printerMessageFour = new TextWidget(printerMessageFourText, 0, 0, 10);

View file

@ -20,7 +20,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private event EventHandler unregisterEvents;
public SetupStepComPortTwo(ConnectionWizard windowController) : base(windowController)
public SetupStepComPortTwo(WizardWindow windowController) : base(windowController)
{
startingPortNames = FrostedSerialPort.GetPortNames();
contentRow.AddChild(createPrinterConnectionMessageContainer());
@ -97,7 +97,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
Button manualLink = linkButtonFactory.Generate("Manual Configuration".Localize());
manualLink.Margin = new BorderDouble(0, 5);
manualLink.Click += (s, e) => connectionWizard.ChangeToSetupComPortManual();
manualLink.Click += (s, e) => wizardWindow.ChangeToSetupComPortManual();
printerErrorMessage = new TextWidget("", 0, 0, 10);
printerErrorMessage.AutoExpandBoundsToText = true;

View file

@ -36,7 +36,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
public class SetupStepConfigureConnection : SetupConnectionWidgetBase
{
public SetupStepConfigureConnection(ConnectionWizard connectionWizard) : base(connectionWizard)
public SetupStepConfigureConnection(WizardWindow connectionWizard) : base(connectionWizard)
{
BorderDouble elementMargin = new BorderDouble(top: 5);
@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
//Construct buttons
var nextButton = textImageButtonFactory.Generate("Connect");
nextButton.Click += (s, e) => base.connectionWizard.ChangeToSetupBaudOrComPortOne();
nextButton.Click += (s, e) => wizardWindow.ChangeToSetupBaudOrComPortOne();
var skipButton = textImageButtonFactory.Generate("Skip");
skipButton.Click += (s, e) => SaveAndExit();

View file

@ -19,7 +19,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private Button installButton;
private Button skipButton;
public SetupStepInstallDriver(ConnectionWizard windowController)
public SetupStepInstallDriver(WizardWindow windowController)
: base(windowController)
{
headerLabel.Text = string.Format(LocalizedString.Get("Install Communication Driver"));
@ -35,13 +35,13 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
bool canContinue = this.InstallDriver();
if (canContinue)
{
connectionWizard.ChangeToSetupBaudOrComPortOne();
wizardWindow.ChangeToSetupBaudOrComPortOne();
}
});
};
skipButton = textImageButtonFactory.Generate(LocalizedString.Get("Skip"));
skipButton.Click += (s, e) => connectionWizard.ChangeToSetupBaudOrComPortOne();
skipButton.Click += (s, e) => wizardWindow.ChangeToSetupBaudOrComPortOne();
//Add buttons to buttonContainer
footerRow.AddChild(installButton);

View file

@ -32,7 +32,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private BoundDropList printerManufacturerSelector;
private BoundDropList printerModelSelector;
public SetupStepMakeModelName(ConnectionWizard windowController) : base(windowController)
public SetupStepMakeModelName(WizardWindow windowController) : base(windowController)
{
var allManufacturers = StaticData.Instance.GetDirectories("PrinterSettings").Select(p => Path.GetFileName(p.TrimEnd(new[] { '/', '\\' })));
@ -86,7 +86,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
bool canContinue = this.OnSave();
if (canContinue)
{
UiThread.RunOnIdle(connectionWizard.Close);
wizardWindow.ChangeToSetupBaudRate();
//UiThread.RunOnIdle(connectionWizard.Close);
}
};

View file

@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.SerialPortCommunication.FrostedSerial;
namespace MatterHackers.MatterControl
{
//Normally step one of the setup process
public class SetupWizardConnect : WizardPanel
{
event EventHandler unregisterEvents;
TextWidget generalError;
Button connectButton;
Button skipButton;
Button nextButton;
Button retryButton;
Button troubleshootButton;
TextWidget skipMessage;
FlowLayoutWidget retryButtonContainer;
FlowLayoutWidget connectButtonContainer;
public SetupWizardConnect(WizardWindow windowController)
: base(windowController)
{
string printerNameLabelTxt = LocalizedString.Get("Connect Your Device");
string printerNameLabelTxtFull = string.Format ("{0}:", printerNameLabelTxt);
TextWidget printerNameLabel = new TextWidget(printerNameLabelTxtFull, 0, 0, labelFontSize);
printerNameLabel.TextColor = this.defaultTextColor;
printerNameLabel.Margin = new BorderDouble(bottom: 10);
contentRow.AddChild(printerNameLabel);
contentRow.AddChild(new TextWidget(LocalizedString.Get("Instructions:"), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor));
contentRow.AddChild(new TextWidget(LocalizedString.Get("1. Power on your 3D Printer."), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor));
contentRow.AddChild(new TextWidget(LocalizedString.Get("2. Attach your 3D Printer via USB."), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor));
contentRow.AddChild(new TextWidget(LocalizedString.Get("3. Press 'Connect'."), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor));
//Add inputs to main container
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(communicationStateChanged, ref unregisterEvents);
connectButtonContainer = new FlowLayoutWidget();
connectButtonContainer.HAnchor = HAnchor.ParentLeftRight;
connectButtonContainer.Margin = new BorderDouble(0, 6);
//Construct buttons
connectButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Connect"),centerText:true);
connectButton.Margin = new BorderDouble(0,0,10,0);
connectButton.Click += new EventHandler(ConnectButton_Click);
//Construct buttons
skipButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Skip"), centerText:true);
skipButton.Click += new EventHandler(NextButton_Click);
connectButtonContainer.AddChild(connectButton);
connectButtonContainer.AddChild(skipButton);
connectButtonContainer.AddChild(new HorizontalSpacer());
contentRow.AddChild(connectButtonContainer);
skipMessage = new TextWidget(LocalizedString.Get("(Press 'Skip' to setup connection later)"), 0, 0, 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
contentRow.AddChild(skipMessage);
generalError = new TextWidget("", 0, 0, errorFontSize);
generalError.TextColor = ActiveTheme.Instance.SecondaryAccentColor;
generalError.HAnchor = HAnchor.ParentLeftRight;
generalError.Visible = false;
generalError.Margin = new BorderDouble(top: 20);
contentRow.AddChild(generalError);
//Construct buttons
retryButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Retry"), centerText:true);
retryButton.Click += new EventHandler(ConnectButton_Click);
retryButton.Margin = new BorderDouble(0,0,10,0);
//Construct buttons
troubleshootButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Troubleshoot"), centerText:true);
troubleshootButton.Click += new EventHandler(TroubleshootButton_Click);
retryButtonContainer = new FlowLayoutWidget();
retryButtonContainer.HAnchor = HAnchor.ParentLeftRight;
retryButtonContainer.Margin = new BorderDouble(0, 6);
retryButtonContainer.AddChild(retryButton);
retryButtonContainer.AddChild(troubleshootButton);
retryButtonContainer.AddChild(new HorizontalSpacer());
retryButtonContainer.Visible = false;
contentRow.AddChild(retryButtonContainer);
//Construct buttons
nextButton = textImageButtonFactory.Generate(LocalizedString.Get("Continue"));
nextButton.Click += new EventHandler(NextButton_Click);
nextButton.Visible = false;
GuiWidget hSpacer = new GuiWidget();
hSpacer.HAnchor = HAnchor.ParentLeftRight;
//Add buttons to buttonContainer
footerRow.AddChild(nextButton);
footerRow.AddChild(hSpacer);
footerRow.AddChild(cancelButton);
updateControls(true);
}
void ConnectButton_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter();
}
void TroubleshootButton_Click(object sender, EventArgs mouseEvent)
{
wizardWindow.ChangeToTroubleshooting();
}
void NextButton_Click(object sender, EventArgs mouseEvent)
{
this.generalError.Text = "Please wait...";
this.generalError.Visible = true;
nextButton.Visible = false;
UiThread.RunOnIdle(this.wizardWindow.Close);
}
private void communicationStateChanged(object sender, EventArgs args)
{
UiThread.RunOnIdle(() => updateControls(false));
}
private void updateControls(bool firstLoad)
{
connectButton.Visible = false;
skipMessage.Visible = false;
generalError.Visible = false;
nextButton.Visible = false;
connectButtonContainer.Visible = false;
retryButtonContainer.Visible = false;
if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected)
{
generalError.Text = "{0}!".FormatWith ("Connection succeeded".Localize ());
generalError.Visible = true;
nextButton.Visible = true;
}
else if (firstLoad || PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Disconnected)
{
generalError.Text = "";
connectButton.Visible = true;
connectButtonContainer.Visible = true;
}
else if (PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect)
{
generalError.Text = "{0}...".FormatWith("Attempting to connect".Localize());
generalError.Visible = true;
}
else
{
generalError.Text = "Uh-oh! Could not connect to printer.".Localize();
generalError.Visible = true;
nextButton.Visible = false;
retryButtonContainer.Visible = true;
}
this.Invalidate();
}
}
}

View file

@ -0,0 +1,298 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.ComponentModel;
using MatterHackers.Agg;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl
{
//Normally step one of the setup process
public class SetupWizardHome : WizardPanel
{
TextImageButtonFactory setupButtonFactory = new TextImageButtonFactory();
Button addProfileButton;
Button editProfilesButton;
Button setupWifiButton;
Button troubleshootButton;
Button accountButton;
public SetupWizardHome(WizardWindow windowController)
: base(windowController, unlocalizedTextForCancelButton: "Done")
{
headerLabel.Text = "Setup Options".Localize();
SetButtonAttributes();
contentRow.AddChild(new SetupPrinterView(this.wizardWindow));
contentRow.AddChild(new SetupAccountView(this.wizardWindow));
contentRow.AddChild(new EnterCodesView(this.wizardWindow));
GuiWidget hSpacer = new GuiWidget();
hSpacer.HAnchor = HAnchor.ParentLeftRight;
//Add buttons to buttonContainer
footerRow.AddChild(hSpacer);
footerRow.AddChild(cancelButton);
cancelButton.Text = "Back".Localize();
}
private void SetButtonAttributes()
{
setupButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.normalFillColor = ActiveTheme.Instance.PrimaryBackgroundColor;
setupButtonFactory.fontSize = 16;
setupButtonFactory.FixedWidth = 420;
setupButtonFactory.ImageSpacing = 20;
}
}
public class EnterCodesView : SetupViewBase
{
public static EventHandler RedeemDesignCode;
public static EventHandler EnterShareCode;
public EnterCodesView(WizardWindow windowController)
: base("", windowController)
{
FlowLayoutWidget buttonContainer = new FlowLayoutWidget();
buttonContainer.HAnchor = HAnchor.ParentLeftRight;
buttonContainer.Margin = new BorderDouble(0, 14);
mainContainer.AddChild(buttonContainer);
if (ActiveTheme.Instance.IsTouchScreen)
{
// the redeem design code button
{
Button redeemPurchaseButton = textImageButtonFactory.Generate("Redeem Purchase".Localize());
redeemPurchaseButton.Enabled = true; // The library selector (the first library selected) is protected so we can't add to it.
redeemPurchaseButton.Name = "Redeem Code Button";
buttonContainer.AddChild(redeemPurchaseButton);
redeemPurchaseButton.Margin = new BorderDouble(0, 0, 10, 0);
redeemPurchaseButton.Click += (sender, e) =>
{
if (RedeemDesignCode != null)
{
RedeemDesignCode(this, null);
}
};
}
// the redeem a share code button
{
Button redeemShareButton = textImageButtonFactory.Generate("Enter Share Code".Localize());
redeemShareButton.Enabled = true; // The library selector (the first library selected) is protected so we can't add to it.
redeemShareButton.Name = "Enter Share Code";
buttonContainer.AddChild(redeemShareButton);
redeemShareButton.Margin = new BorderDouble(0, 0, 3, 0);
redeemShareButton.Click += (sender, e) =>
{
if (EnterShareCode != null)
{
EnterShareCode(this, null);
}
};
}
}
}
}
public class SetupPrinterView : SetupViewBase
{
Button disconnectButton;
TextWidget connectionStatus;
event EventHandler unregisterEvents;
public SetupPrinterView(WizardWindow windowController)
: base("Printer Profile", windowController)
{
var buttonContainer = new FlowLayoutWidget()
{
HAnchor = HAnchor.ParentLeftRight,
Margin = new BorderDouble (0, 14)
};
var printerSelector = new PrinterSelector();
printerSelector.AddPrinter += (s, e) => this.windowController.ChangeToSetupPrinterForm();
buttonContainer.AddChild(printerSelector);
disconnectButton = textImageButtonFactory.Generate("Disconnect");
disconnectButton.Margin = new BorderDouble(left: 12);
disconnectButton.VAnchor = VAnchor.ParentCenter;
disconnectButton.Click += (sender, e) =>
{
PrinterConnectionAndCommunication.Instance.Disable();
windowController.ChangeToHome();
};
buttonContainer.AddChild(disconnectButton);
mainContainer.AddChild(buttonContainer);
connectionStatus = new TextWidget("Status:", pointSize: 12, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
HAnchor = HAnchor.ParentLeftRight
};
mainContainer.AddChild(connectionStatus);
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(updateConnectedState, ref unregisterEvents);
updateConnectedState(null, null);
}
private void updateConnectedState(object sender, EventArgs e)
{
if (disconnectButton != null)
{
disconnectButton.Visible = PrinterConnectionAndCommunication.Instance.PrinterIsConnected;
}
if (connectionStatus != null)
{
connectionStatus.Text = string.Format ("{0}: {1}", "Status".Localize().ToUpper(), PrinterConnectionAndCommunication.Instance.PrinterConnectionStatusVerbose);
}
this.Invalidate();
}
}
public class SetupAccountView : SetupViewBase
{
Button signInButton;
Button signOutButton;
event EventHandler unregisterEvents;
TextWidget statusMessage;
public SetupAccountView(WizardWindow windowController)
: base("My Account", windowController)
{
bool signedIn = true;
string username = ApplicationController.Instance.GetSessionUsername();
if (username == null)
{
signedIn = false;
username = "Not Signed In";
}
mainContainer.AddChild(new TextWidget(username, pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor));
//mainContainer.AddChild(new TextWidget(statusDescription, pointSize: 12, textColor: ActiveTheme.Instance.PrimaryTextColor));
FlowLayoutWidget buttonContainer = new FlowLayoutWidget();
buttonContainer.HAnchor = HAnchor.ParentLeftRight;
buttonContainer.Margin = new BorderDouble(0, 14);
signInButton = textImageButtonFactory.Generate("Sign In");
signInButton.Margin = new BorderDouble(left: 0);
signInButton.VAnchor = VAnchor.ParentCenter;
signInButton.Click += new EventHandler(signInButton_Click);
signInButton.Visible = !signedIn;
buttonContainer.AddChild(signInButton);
signOutButton = textImageButtonFactory.Generate("Sign Out");
signOutButton.Margin = new BorderDouble(left: 0);
signOutButton.VAnchor = VAnchor.ParentCenter;
signOutButton.Click += new EventHandler(signOutButton_Click);
signOutButton.Visible = signedIn;
buttonContainer.AddChild(signOutButton);
statusMessage = new TextWidget("Please wait...", pointSize: 12, textColor: ActiveTheme.Instance.SecondaryAccentColor);
statusMessage.Visible = false;
buttonContainer.AddChild(statusMessage);
mainContainer.AddChild(buttonContainer);
ApplicationController.Instance.DoneReloadingAll.RegisterEvent(onDoneReloading, ref unregisterEvents);
}
void onDoneReloading(object sender, EventArgs e)
{
this.windowController.ChangeToHome();
}
void signInButton_Click(object sender, EventArgs e)
{
UiThread.RunOnIdle(() =>
{
signInButton.Visible = false;
signOutButton.Visible = false;
statusMessage.Visible = true;
ApplicationController.Instance.StartLogin();
});
}
void signOutButton_Click(object sender, EventArgs e)
{
UiThread.RunOnIdle(() =>
{
signInButton.Visible = false;
signOutButton.Visible = false;
statusMessage.Visible = true;
ApplicationController.Instance.StartLogout();
});
}
}
public class SetupViewBase : AltGroupBox
{
protected readonly int TallButtonHeight = 28;
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
protected LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
protected RGBA_Bytes separatorLineColor;
protected FlowLayoutWidget mainContainer;
protected WizardWindow windowController;
public SetupViewBase(string title,WizardWindow windowController)
: base(title != "" ? new TextWidget(title, pointSize: 18, textColor: ActiveTheme.Instance.SecondaryAccentColor) : null)
{
this.windowController = windowController;
SetDisplayAttributes();
mainContainer = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom);
mainContainer.HAnchor = HAnchor.ParentLeftRight;
mainContainer.Margin = new BorderDouble(6,0,0,6);
AddChild(mainContainer);
}
private void SetDisplayAttributes()
{
//this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.separatorLineColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 100);
this.Margin = new BorderDouble(2, 10, 2, 0);
this.textImageButtonFactory.normalFillColor = RGBA_Bytes.Transparent;
this.textImageButtonFactory.disabledFillColor = RGBA_Bytes.White;
this.textImageButtonFactory.FixedHeight = TallButtonHeight;
this.textImageButtonFactory.fontSize = 16;
this.textImageButtonFactory.borderWidth = 1;
this.textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
this.textImageButtonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
this.textImageButtonFactory.disabledTextColor = RGBA_Bytes.DarkGray;
this.textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
this.textImageButtonFactory.normalTextColor = ActiveTheme.Instance.SecondaryTextColor;
this.textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
this.linkButtonFactory.fontSize = 11;
}
}
}

View file

@ -0,0 +1,308 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.SerialPortCommunication.FrostedSerial;
#if __ANDROID__
using Com.Hoho.Android.Usbserial.Driver;
using Android.Hardware.Usb;
using Android.Content;
#endif
namespace MatterHackers.MatterControl
{
public class SetupWizardTroubleshooting : WizardPanel
{
private Button nextButton;
private event EventHandler unregisterEvents;
private CriteriaRow connectToPrinterRow;
#if __ANDROID__
private static UsbManager usbManager
{
get { return (UsbManager) Android.App.Application.Context.ApplicationContext.GetSystemService(Context.UsbService); }
}
#endif
public SetupWizardTroubleshooting(WizardWindow windowController)
: base(windowController)
{
RefreshStatus();
//Construct buttons
cancelButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Cancel"), centerText:true);
cancelButton.Click += (sender, e) =>
{
this.wizardWindow.ChangeToPanel(new SetupWizardConnect(windowController));
};
//Construct buttons
nextButton = textImageButtonFactory.Generate(LocalizedString.Get("Continue"));
nextButton.Click += (sender, e) => UiThread.RunOnIdle(this.wizardWindow.Close);
nextButton.Visible = false;
//Add buttons to buttonContainer
footerRow.AddChild(nextButton);
footerRow.AddChild(new GuiWidget() { HAnchor = HAnchor.ParentLeftRight });
footerRow.AddChild(cancelButton);
// Register for connection notifications
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(ConnectionStatusChanged, ref unregisterEvents);
}
public void ConnectionStatusChanged(object test, EventArgs args)
{
if(PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Connected && connectToPrinterRow != null)
{
connectToPrinterRow.SetSuccessful();
nextButton.Visible = true;
}
}
public override void OnClosed(EventArgs e)
{
if (unregisterEvents != null)
{
unregisterEvents(this, null);
}
if(checkForPermissionTimer != null)
{
checkForPermissionTimer.Dispose();
}
base.OnClosed(e);
}
System.Threading.Timer checkForPermissionTimer;
private void RefreshStatus()
{
CriteriaRow.ResetAll();
// Clear the main container
contentRow.CloseAllChildren();
// Regen and refresh the troubleshooting criteria
TextWidget printerNameLabel = new TextWidget(string.Format ("{0}:", "Connection Troubleshooting".Localize()), 0, 0, labelFontSize);
printerNameLabel.TextColor = this.defaultTextColor;
printerNameLabel.Margin = new BorderDouble(bottom: 10);
#if __ANDROID__
IUsbSerialPort serialPort = FrostedSerialPort.LoadSerialDriver();
#if ANDROID7
// Filter out the built-in 002 device and select the first item from the list
// On the T7 Android device, there is a non-printer device always registered at usb/002/002 that must be ignored
UsbDevice usbPrintDevice = usbManager.DeviceList.Values.Where(d => d.DeviceName != "/dev/bus/usb/002/002").FirstOrDefault();
#else
UsbDevice usbPrintDevice = usbManager.DeviceList.Values.FirstOrDefault();
#endif
UsbStatus usbStatus = new UsbStatus () {
IsDriverLoadable = (serialPort != null),
HasUsbDevice = true,
HasUsbPermission = false,
AnyUsbDeviceExists = usbPrintDevice != null
};
if (!usbStatus.IsDriverLoadable)
{
usbStatus.HasUsbDevice = usbPrintDevice != null;
if (usbStatus.HasUsbDevice) {
// TODO: Testing specifically for UsbClass.Comm seems fragile but no better alternative exists without more research
usbStatus.UsbDetails = new UsbDeviceDetails () {
ProductID = usbPrintDevice.ProductId,
VendorID = usbPrintDevice.VendorId,
DriverClass = usbManager.DeviceList.Values.First ().DeviceClass == Android.Hardware.Usb.UsbClass.Comm ? "cdcDriverType" : "ftdiDriverType"
};
usbStatus.Summary = string.Format ("No USB device definition found. Click the 'Fix' button to add an override for your device ", usbStatus.UsbDetails.VendorID, usbStatus.UsbDetails.ProductID);
}
}
usbStatus.HasUsbPermission = usbStatus.IsDriverLoadable && FrostedSerialPort.HasPermissionToDevice(serialPort);
contentRow.AddChild(printerNameLabel);
contentRow.AddChild(new CriteriaRow(
"USB Connection",
"Retry",
"No USB device found. Check and reseat cables and try again",
usbStatus.AnyUsbDeviceExists,
() => UiThread.RunOnIdle(RefreshStatus)));
contentRow.AddChild(new CriteriaRow(
"USB Driver",
"Fix",
usbStatus.Summary,
usbStatus.IsDriverLoadable,
() => {
string overridePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "usboverride.local");
UsbDeviceDetails usbDetails = usbStatus.UsbDetails;
File.AppendAllText(overridePath, string.Format("{0},{1},{2}\r\n", usbDetails.VendorID, usbDetails.ProductID, usbDetails.DriverClass));
UiThread.RunOnIdle(() => RefreshStatus());
}));
contentRow.AddChild(new CriteriaRow(
"USB Permission",
"Request Permission",
"Click the 'Request Permission' button to gain Android access rights",
usbStatus.HasUsbPermission ,
() => {
if(checkForPermissionTimer == null)
{
checkForPermissionTimer = new System.Threading.Timer((state) => {
if(FrostedSerialPort.HasPermissionToDevice(serialPort))
{
UiThread.RunOnIdle(this.RefreshStatus);
checkForPermissionTimer.Dispose();
}
}, null, 200, 200);
}
FrostedSerialPort.RequestPermissionToDevice(serialPort);
}));
#endif
connectToPrinterRow = new CriteriaRow(
"Connect to Printer",
"Connect",
"Click the 'Connect' button to retry the original connection attempt",
false,
() => PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter());
contentRow.AddChild(connectToPrinterRow);
if (CriteriaRow.ActiveErrorItem != null) {
FlowLayoutWidget errorText = new FlowLayoutWidget () {
Padding = new BorderDouble (0, 15)
};
errorText.AddChild(new TextWidget(CriteriaRow.ActiveErrorItem.ErrorText) {
TextColor = ActiveTheme.Instance.PrimaryAccentColor
});
contentRow.AddChild(errorText);
}
}
private class CriteriaRow : FlowLayoutWidget
{
public static CriteriaRow ActiveErrorItem { get; private set; }
public string ErrorText { get; private set; }
private static bool stillSuccessful = true;
private static int criteriaCount = 0;
private static RGBA_Bytes disabledTextColor = new RGBA_Bytes(0.35, 0.35, 0.35);
private static RGBA_Bytes disabledBackColor = new RGBA_Bytes(0.22, 0.22, 0.22);
private static RGBA_Bytes toggleColor = new RGBA_Bytes(RGBA_Bytes.Gray.red + 2, RGBA_Bytes.Gray.green + 2, RGBA_Bytes.Gray.blue + 2);
public CriteriaRow (string itemText, string fixitText, string errorText, bool succeeded, Action fixAction) :base(FlowDirection.LeftToRight, HAnchor.ParentLeftRight, VAnchor.AbsolutePosition)
{
TextImageButtonFactory buttonFactory = new TextImageButtonFactory();
ErrorText = errorText;
base.Height = 40;
base.AddChild(new TextWidget (string.Format(" {0}. {1}", criteriaCount + 1, itemText)){
TextColor = stillSuccessful ? RGBA_Bytes.White : disabledTextColor,
VAnchor = VAnchor.ParentCenter
});
if(stillSuccessful && !succeeded)
{
ActiveErrorItem = this;
}
base.AddChild(new HorizontalSpacer());
if(stillSuccessful) {
if(succeeded)
{
// Add checkmark image
AddSuccessIcon();
} else {
// Add Fix button
Button button = buttonFactory.Generate(LocalizedString.Get(fixitText),centerText:true);
button.VAnchor = VAnchor.ParentCenter;
button.Padding = new BorderDouble(3, 8);
button.Click += (sender, e) => fixAction();
base.AddChild(button);
}
}
if(stillSuccessful)
{
this.BackgroundColor = (criteriaCount % 2 == 0) ? RGBA_Bytes.Gray : toggleColor;
}
else
{
this.BackgroundColor = disabledBackColor;
}
stillSuccessful &= succeeded;
criteriaCount++;
}
public void SetSuccessful()
{
this.RemoveChild (this.Children.Last ());
ActiveErrorItem = null;
AddSuccessIcon();
}
public static void ResetAll()
{
criteriaCount = 0;
stillSuccessful = true;
ActiveErrorItem = null;
}
private void AddSuccessIcon()
{
base.AddChild (new ImageWidget (StaticData.Instance.LoadImage (Path.Combine ("Icons", "426.png"))) {
VAnchor = VAnchor.ParentCenter
});
}
}
private class UsbStatus
{
public bool HasUsbDevice { get; set; }
public bool IsDriverLoadable { get; set; }
public string Summary { get; set; }
public bool HasUsbPermission { get; set; }
public bool AnyUsbDeviceExists { get ; set; }
public UsbDeviceDetails UsbDetails { get; set; }
}
private class UsbDeviceDetails
{
public int VendorID { get; set; }
public int ProductID { get; set; }
public string DriverClass { get; set; }
}
}
}

View file

@ -0,0 +1,88 @@
/*
Copyright (c) 2016, Kevin Pope, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
namespace MatterHackers.MatterControl
{
//Normally step one of the setup process
public class SetupWizardWifi : WizardPanel
{
public SetupWizardWifi(WizardWindow windowController)
: base(windowController)
{
contentRow.AddChild(new TextWidget("Wifi Setup".Localize() + ":", 0, 0, labelFontSize)
{
TextColor = this.defaultTextColor,
Margin = new BorderDouble(bottom: 10)
});
contentRow.AddChild(new TextWidget("Some features may require an internet connection.".Localize(), 0, 0, 12, textColor: ActiveTheme.Instance.PrimaryTextColor));
contentRow.AddChild(new TextWidget("Would you like to setup Wifi?".Localize(), 0, 0, 12, textColor: ActiveTheme.Instance.PrimaryTextColor));
var connectButtonContainer = new FlowLayoutWidget()
{
HAnchor = HAnchor.ParentLeftRight,
Margin = new BorderDouble(0, 6)
};
//Construct buttons
Button skipButton = whiteImageButtonFactory.Generate("Skip".Localize(), centerText: true);
skipButton.Click += (s, e) => this.wizardWindow.ChangeToSetupPrinterForm();
Button nextButton = textImageButtonFactory.Generate("Continue".Localize());
nextButton.Click += (s, e) => this.wizardWindow.ChangeToSetupPrinterForm();
nextButton.Visible = false;
Button configureButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Configure"), centerText: true);
configureButton.Margin = new BorderDouble(0, 0, 10, 0);
configureButton.Click += (s, e) =>
{
nextButton.Visible = true;
skipButton.Visible = false;
configureButton.Visible = false;
MatterControlApplication.Instance.ConfigureWifi();
};
connectButtonContainer.AddChild(configureButton);
connectButtonContainer.AddChild(skipButton);
connectButtonContainer.AddChild(new HorizontalSpacer());
contentRow.AddChild(connectButtonContainer);
//Add buttons to buttonContainer
footerRow.AddChild(nextButton);
footerRow.AddChild(new HorizontalSpacer());
footerRow.AddChild(cancelButton);
}
}
}

170
SetupWizard/WizardPanel.cs Normal file
View file

@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl
{
public class WizardPanel : GuiWidget
{
protected FlowLayoutWidget headerRow;
protected FlowLayoutWidget contentRow;
protected FlowLayoutWidget footerRow;
protected TextWidget headerLabel;
protected Button cancelButton;
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
protected TextImageButtonFactory whiteImageButtonFactory = new TextImageButtonFactory();
protected LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
protected GuiWidget containerWindowToClose;
protected RGBA_Bytes defaultTextColor = ActiveTheme.Instance.PrimaryTextColor;
protected RGBA_Bytes defaultBackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
protected RGBA_Bytes subContainerTextColor = ActiveTheme.Instance.PrimaryTextColor;
protected RGBA_Bytes labelBackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
protected RGBA_Bytes linkTextColor = ActiveTheme.Instance.SecondaryAccentColor;
protected double labelFontSize = 12 * GuiWidget.DeviceScale;
protected double errorFontSize = 10 * GuiWidget.DeviceScale;
protected WizardWindow wizardWindow;
event EventHandler unregisterEvents;
public void ThemeChanged(object sender, EventArgs e)
{
this.linkTextColor = ActiveTheme.Instance.PrimaryAccentColor;
this.Invalidate();
}
public override void OnClosed(EventArgs e)
{
unregisterEvents?.Invoke(this, null);
base.OnClosed(e);
}
PrinterInfo activePrinter;
public PrinterInfo ActivePrinter
{
get
{
if (activePrinter == null)
{
var settings = ActiveSliceSettings.Instance;
activePrinter = new PrinterInfo
{
AutoConnect = settings.DoAutoConnect(),
BaudRate = settings.BaudRate(),
ComPort = settings.ComPort(),
DriverType = settings.DriverType(),
Id = settings.ID,
Name = settings.Name()
};
}
return activePrinter;
}
}
public WizardPanel(WizardWindow windowController, string unlocalizedTextForCancelButton = "Cancel")
: base()
{
this.wizardWindow = windowController;
this.textImageButtonFactory.fontSize = 16;
SetWhiteButtonAttributes();
this.AnchorAll();
ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);
cancelButton = textImageButtonFactory.Generate(unlocalizedTextForCancelButton.Localize());
cancelButton.Name = unlocalizedTextForCancelButton;
cancelButton.Click += new EventHandler(CancelButton_Click);
//Create the main container
GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
mainContainer.AnchorAll();
mainContainer.Padding = new BorderDouble(12, 12, 12, 0);
mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
//Create the header row for the widget
headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
headerRow.Margin = new BorderDouble(0, 3, 0, 0);
headerRow.Padding = new BorderDouble(0, 12);
headerRow.HAnchor = HAnchor.ParentLeftRight;
{
string defaultHeaderTitle = "Setup Wizard".Localize();
headerLabel = new TextWidget(defaultHeaderTitle, pointSize: 24, textColor: ActiveTheme.Instance.SecondaryAccentColor);
headerLabel.AutoExpandBoundsToText = true;
headerRow.AddChild(headerLabel);
}
//Create the main control container
contentRow = new FlowLayoutWidget(FlowDirection.TopToBottom);
contentRow.Padding = new BorderDouble(10);
contentRow.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
contentRow.HAnchor = HAnchor.ParentLeftRight;
contentRow.VAnchor = VAnchor.ParentBottomTop;
//Create the footer (button) container
footerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
footerRow.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
footerRow.Margin = new BorderDouble(0, 6);
mainContainer.AddChild(headerRow);
mainContainer.AddChild(contentRow);
mainContainer.AddChild(footerRow);
this.AddChild(mainContainer);
}
protected void SaveAndExit()
{
throw new NotImplementedException();
/*
this.ActivePrinter.Commit();
ActivePrinterProfile.Instance.ActivePrinter = this.ActivePrinter;
this.containerWindowToClose.Close(); */
}
void SetWhiteButtonAttributes()
{
whiteImageButtonFactory.normalFillColor = RGBA_Bytes.White;
whiteImageButtonFactory.disabledFillColor = RGBA_Bytes.White;
whiteImageButtonFactory.fontSize = 16;
whiteImageButtonFactory.borderWidth = 1;
whiteImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
whiteImageButtonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
whiteImageButtonFactory.disabledTextColor = RGBA_Bytes.DarkGray;
whiteImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
whiteImageButtonFactory.normalTextColor = RGBA_Bytes.Black;
whiteImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
whiteImageButtonFactory.FixedWidth = 200;
}
void CloseWindow(object o, EventArgs e)
{
PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
this.wizardWindow.Close();
}
void CancelButton_Click(object sender, EventArgs mouseEvent)
{
UiThread.RunOnIdle(() =>
{
if (Parent != null)
{
Parent.Close();
}
});
}
}
}

226
SetupWizard/WizardWindow.cs Normal file
View file

@ -0,0 +1,226 @@
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl
{
public class WizardWindow : SystemWindow
{
private bool editMode = false;
protected PrinterInfo activePrinter;
public WizardWindow(bool openToHome = false)
: base(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale)
{
AlwaysOnTopOfMain = true;
this.Title = "Setup Wizard".Localize();
if (openToHome)
{
ChangeToHome();
}
else
{
//Todo - detect wifi connectivity
bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected();
if (!WifiDetected)
{
ChangeToWifiForm();
}
else if (GetPrinterRecordCount() > 0)
{
ChangeToSetupPrinterForm();
}
else
{
ChangeToSetupPrinterForm();
}
}
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.Padding = new BorderDouble(8);
this.ShowAsSystemWindow();
MinimumSize = new Vector2(350 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale);
}
private static WizardWindow setupWizardWindow = null;
private static bool connectionWindowIsOpen = false;
public static void Show(bool openToHome = false)
{
if (connectionWindowIsOpen == false)
{
setupWizardWindow = new WizardWindow(openToHome);
connectionWindowIsOpen = true;
setupWizardWindow.Closed += (parentSender, e) =>
{
connectionWindowIsOpen = false;
setupWizardWindow = null;
};
}
else
{
if (setupWizardWindow != null)
{
setupWizardWindow.BringToFront();
}
}
}
public override void OnMouseUp(MouseEventArgs mouseEvent)
{
base.OnMouseUp(mouseEvent);
}
private void DoNotChangeWindow()
{
//Empty function used as default callback for changeToWindowCallback
}
public void ChangeToSetupPrinterForm()
{
UiThread.RunOnIdle(DoChangeToSetupPrinterForm);
}
private void DoChangeToSetupPrinterForm()
{
this.ChangeToAddPrinter();
}
public void ChangeToConnectForm(bool editMode = false)
{
this.editMode = editMode;
UiThread.RunOnIdle(DoChangeToConnectForm);
}
public void DoChangeToConnectForm()
{
GuiWidget chooseConnectionWidget = new SetupWizardConnect(this);
this.RemoveAllChildren();
this.AddChild(chooseConnectionWidget);
this.Invalidate();
}
public void ChangeToTroubleshooting()
{
UiThread.RunOnIdle(() =>
{
GuiWidget wizardForm = new SetupWizardTroubleshooting(this);
this.RemoveAllChildren();
this.AddChild(wizardForm);
this.Invalidate();
});
}
public void ChangeToWifiForm(bool editMode = false)
{
this.editMode = editMode;
UiThread.RunOnIdle(DoChangeToWifiForm, null);
}
public void ChangeToPanel(WizardPanel panelToChangeTo)
{
this.RemoveAllChildren();
this.AddChild(panelToChangeTo);
this.Invalidate();
}
public void DoChangeToWifiForm(object state)
{
GuiWidget chooseConnectionWidget = new SetupWizardWifi(this);
this.RemoveAllChildren();
this.AddChild(chooseConnectionWidget);
this.Invalidate();
}
public void ChangeToHome()
{
UiThread.RunOnIdle(DoChangeToHome, null);
}
public void DoChangeToHome(object state)
{
GuiWidget homeWidget = new SetupWizardHome(this);
this.RemoveAllChildren();
this.AddChild(homeWidget);
this.Invalidate();
}
private int GetPrinterRecordCount()
{
return Datastore.Instance.RecordCount("Printer");
}
internal void ChangeToAddPrinter()
{
this.activePrinter = null;
ChangeToStep(new SetupStepMakeModelName(this));
}
private void ChangeToStep(GuiWidget nextStep)
{
UiThread.RunOnIdle(() =>
{
this.RemoveAllChildren();
this.AddChild(nextStep);
this.Invalidate();
});
}
internal void ChangeToSetupBaudRate()
{
ChangeToStep(new SetupStepBaudRate(this));
}
internal void ChangeToInstallDriver()
{
ChangeToStep(new SetupStepInstallDriver(this));
}
internal void ChangeToSetupComPortOne()
{
ChangeToStep(new SetupStepComPortOne(this));
}
internal void ChangeToSetupCompPortTwo()
{
ChangeToStep(new SetupStepComPortTwo(this));
}
internal void ChangeToSetupComPortManual()
{
ChangeToStep(new SetupStepComPortManual(this));
}
internal void ChangeToInstallDriverOrComPortOne()
{
if (ActiveSliceSettings.Instance.PrinterDrivers().Count > 0)
{
ChangeToInstallDriver();
}
else
{
ChangeToSetupComPortOne();
}
}
internal void ChangeToSetupBaudOrComPortOne()
{
if (string.IsNullOrEmpty(activePrinter.BaudRate))
{
ChangeToSetupBaudRate();
}
else
{
ChangeToSetupComPortOne();
}
}
}
}

View file

@ -4879,3 +4879,33 @@ Translated:The COM port to use while connecting to this printer.
English:COM Port
Translated:COM Port
English:Setup Wizard
Translated:Setup Wizard
English:Setup Options
Translated:Setup Options
English:Please wait. Generating printer profile
Translated:Please wait. Generating printer profile
English:Connect Your Device
Translated:Connect Your Device
English:Instructions:
Translated:Instructions:
English:1. Power on your 3D Printer.
Translated:1. Power on your 3D Printer.
English:2. Attach your 3D Printer via USB.
Translated:2. Attach your 3D Printer via USB.
English:3. Press 'Connect'.
Translated:3. Press 'Connect'.
English:(Press 'Skip' to setup connection later)
Translated:(Press 'Skip' to setup connection later)
English:Troubleshoot
Translated:Troubleshoot

@ -1 +1 @@
Subproject commit e8c232b5ee5763e4168a527c05ad9ec9b4df2c86
Subproject commit 935cac90bbc3c426e4ddcdcb693c193284bca1de