diff --git a/MatterControl.csproj b/MatterControl.csproj index 3f800d91b..8f0614b65 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -246,7 +246,7 @@ - + @@ -328,7 +328,6 @@ - diff --git a/PrinterControls/PrinterConnections/SetupStepConfigureConnection.cs b/PrinterControls/PrinterConnections/SetupStepConfigureConnection.cs deleted file mode 100644 index fe233a099..000000000 --- a/PrinterControls/PrinterConnections/SetupStepConfigureConnection.cs +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright (c) 2014, Kevin Pope -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.MatterControl.CustomWidgets; -using System; - -namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections -{ - public class SetupStepConfigureConnection : ConnectionWizardPanel - { - public SetupStepConfigureConnection() - { - BorderDouble elementMargin = new BorderDouble(top: 5); - - var continueMessage = new TextWidget("Would you like to connect to this printer now?", 0, 0, 12); - continueMessage.AutoExpandBoundsToText = true; - continueMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; - continueMessage.HAnchor = HAnchor.ParentLeftRight; - continueMessage.Margin = elementMargin; - - var continueMessageTwo = new TextWidget("You can always configure this later.", 0, 0, 10); - continueMessageTwo.AutoExpandBoundsToText = true; - continueMessageTwo.TextColor = ActiveTheme.Instance.PrimaryTextColor; - continueMessageTwo.HAnchor = HAnchor.ParentLeftRight; - continueMessageTwo.Margin = elementMargin; - - var printerErrorMessage = new TextWidget("", 0, 0, 10); - printerErrorMessage.AutoExpandBoundsToText = true; - printerErrorMessage.TextColor = RGBA_Bytes.Red; - printerErrorMessage.HAnchor = HAnchor.ParentLeftRight; - printerErrorMessage.Margin = elementMargin; - - var container = new FlowLayoutWidget(FlowDirection.TopToBottom); - container.Margin = new BorderDouble(5); - container.AddChild(continueMessage); - container.AddChild(continueMessageTwo); - container.AddChild(printerErrorMessage); - container.HAnchor = HAnchor.ParentLeftRight; - - //Construct buttons - var nextButton = textImageButtonFactory.Generate("Connect"); - nextButton.Click += (s, e) => WizardWindow.ChangeToSetupBaudOrComPortOne(); - - var skipButton = textImageButtonFactory.Generate("Skip"); - skipButton.Click += (s, e) => SaveAndExit(); - - //Add buttons to buttonContainer - footerRow.AddChild(nextButton); - footerRow.AddChild(skipButton); - footerRow.AddChild(new HorizontalSpacer()); - footerRow.AddChild(cancelButton); - } - } -} \ No newline at end of file diff --git a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index 197c83295..f1db4353d 100644 --- a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -84,7 +84,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections if (canContinue) { #if __ANDROID__ - WizardWindow.ChangeToPanel(); + WizardWindow.ChangeToPanel(); #else WizardWindow.ChangeToPanel(); #endif diff --git a/SetupWizard/AndroidConnectDevicePanel.cs b/SetupWizard/AndroidConnectDevicePanel.cs new file mode 100644 index 000000000..d7e493649 --- /dev/null +++ b/SetupWizard/AndroidConnectDevicePanel.cs @@ -0,0 +1,204 @@ +/* +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 System; + +using MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.PrinterCommunication; + +namespace MatterHackers.MatterControl +{ + public class AndroidConnectDevicePanel : WizardPanel + { + private event EventHandler unregisterEvents; + + private TextWidget generalError; + + private Button connectButton; + private Button skipButton; + private Button nextButton; + private Button retryButton; + private Button troubleshootButton; + + private TextWidget skipMessage; + + private FlowLayoutWidget retryButtonContainer; + private FlowLayoutWidget connectButtonContainer; + + public AndroidConnectDevicePanel() + { + TextWidget printerNameLabel = new TextWidget("Connect Your Device".Localize() + ":", 0, 0, labelFontSize) + { + TextColor = ActiveTheme.Instance.PrimaryTextColor, + Margin = new BorderDouble(bottom: 10) + }; + contentRow.AddChild(printerNameLabel); + + contentRow.AddChild(new TextWidget("Instructions:".Localize(), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor)); + contentRow.AddChild(new TextWidget("1. Power on your 3D Printer.".Localize(), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor)); + contentRow.AddChild(new TextWidget("2. Attach your 3D Printer via USB.".Localize(), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor)); + contentRow.AddChild(new TextWidget("3. Press 'Connect'.".Localize(), 0, 0, 12,textColor:ActiveTheme.Instance.PrimaryTextColor)); + + //Add inputs to main container + PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(communicationStateChanged, ref unregisterEvents); + + connectButtonContainer = new FlowLayoutWidget() + { + HAnchor = HAnchor.ParentLeftRight, + Margin = new BorderDouble(0, 6) + }; + + //Construct buttons + connectButton = whiteImageButtonFactory.Generate("Connect".Localize(),centerText:true); + connectButton.Margin = new BorderDouble(0,0,10,0); + connectButton.Click += new EventHandler(ConnectButton_Click); + + skipButton = whiteImageButtonFactory.Generate("Skip".Localize(), centerText:true); + skipButton.Click += new EventHandler(NextButton_Click); + + connectButtonContainer.AddChild(connectButton); + connectButtonContainer.AddChild(skipButton); + connectButtonContainer.AddChild(new HorizontalSpacer()); + contentRow.AddChild(connectButtonContainer); + + skipMessage = new TextWidget("(Press 'Skip' to setup connection later)".Localize(), 0, 0, 10, textColor: ActiveTheme.Instance.PrimaryTextColor); + contentRow.AddChild(skipMessage); + + generalError = new TextWidget("", 0, 0, errorFontSize) + { + TextColor = ActiveTheme.Instance.SecondaryAccentColor, + HAnchor = HAnchor.ParentLeftRight, + Visible = false, + Margin = new BorderDouble(top: 20), + }; + contentRow.AddChild(generalError); + + //Construct buttons + retryButton = whiteImageButtonFactory.Generate("Retry".Localize(), centerText:true); + retryButton.Click += ConnectButton_Click; + retryButton.Margin = new BorderDouble(0,0,10,0); + + //Construct buttons + troubleshootButton = whiteImageButtonFactory.Generate("Troubleshoot".Localize(), centerText:true); + troubleshootButton.Click += (s, e) => WizardWindow.ChangeToPanel(); + + retryButtonContainer = new FlowLayoutWidget() + { + HAnchor = HAnchor.ParentLeftRight, + Margin = new BorderDouble(0, 6), + Visible = false + }; + + retryButtonContainer.AddChild(retryButton); + retryButtonContainer.AddChild(troubleshootButton); + retryButtonContainer.AddChild(new HorizontalSpacer()); + + contentRow.AddChild(retryButtonContainer); + + //Construct buttons + nextButton = textImageButtonFactory.Generate("Continue".Localize()); + nextButton.Click += 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 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(); + } + + public override void OnClosed(EventArgs e) + { + unregisterEvents?.Invoke(this, null); + base.OnClosed(e); + } + } +} diff --git a/SetupWizard/SetupWizardConnect.cs b/SetupWizard/SetupWizardConnect.cs deleted file mode 100644 index 38f4640c4..000000000 --- a/SetupWizard/SetupWizardConnect.cs +++ /dev/null @@ -1,180 +0,0 @@ -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() - { - string printerNameLabelTxt = LocalizedString.Get("Connect Your Device"); - string printerNameLabelTxtFull = string.Format ("{0}:", printerNameLabelTxt); - TextWidget printerNameLabel = new TextWidget(printerNameLabelTxtFull, 0, 0, labelFontSize); - printerNameLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; - 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.ChangeToPanel(); - } - - 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(); - } - } -} diff --git a/SetupWizard/SetupWizardTroubleshooting.cs b/SetupWizard/SetupWizardTroubleshooting.cs index 0c292b3a9..60906f8b8 100644 --- a/SetupWizard/SetupWizardTroubleshooting.cs +++ b/SetupWizard/SetupWizardTroubleshooting.cs @@ -44,7 +44,7 @@ namespace MatterHackers.MatterControl //Construct buttons cancelButton = whiteImageButtonFactory.Generate("Cancel".Localize(), centerText:true); - cancelButton.Click += (s, e) => this.WizardWindow.ChangeToPanel(); + cancelButton.Click += (s, e) => this.WizardWindow.ChangeToPanel(); //Construct buttons nextButton = textImageButtonFactory.Generate("Continue".Localize());