Removed 'Setup...' button

Improved Print popup
Made print popup always available

issue: MatterHackers/MCCentral#4661
Unify 'Setup...' into 'Print'
This commit is contained in:
Lars Brubaker 2018-12-03 13:23:24 -08:00
parent 6edfd4b9f0
commit 3ef1abd065
7 changed files with 172 additions and 222 deletions

View file

@ -1,164 +0,0 @@
/*
Copyright (c) 2017, Lars Brubaker, 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 System.Threading;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class PrintButton : FlowLayoutWidget
{
private GuiWidget finishSetupButton;
private GuiWidget startPrintButton;
private PrinterConfig printer;
private ThemeConfig theme;
public PrintButton(PrinterConfig printer, ThemeConfig theme)
{
this.printer = printer;
this.theme = theme;
// add the finish setup button
finishSetupButton = new TextButton("Setup...".Localize(), theme)
{
Name = "Finish Setup Button",
ToolTipText = "Run setup configuration for printer.".Localize(),
Margin = theme.ButtonSpacing,
};
finishSetupButton.Click += (s, e) =>
{
UiThread.RunOnIdle(async () =>
{
await ApplicationController.Instance.PrintPart(
printer.Bed.EditContext,
printer,
null,
CancellationToken.None);
});
};
this.AddChild(finishSetupButton);
// add the start print button
this.AddChild(startPrintButton = new PrintPopupMenu(printer, theme)
{
Margin = theme.ButtonSpacing
});
// Register listeners
printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged;
printer.Settings.SettingChanged += Printer_SettingChanged;
SetButtonStates();
}
public override void OnClosed(EventArgs e)
{
// Unregister listeners
printer.Connection.CommunicationStateChanged -= Connection_CommunicationStateChanged;
printer.Settings.SettingChanged -= Printer_SettingChanged;
base.OnClosed(e);
}
protected void SetButtonStates()
{
// If we don't have leveling data and we need it
bool showSetupButton = ApplicationController.PrinterNeedsToRunSetup(printer);
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.FinishedPrint:
case CommunicationStates.Connected:
if(showSetupButton)
{
startPrintButton.Visible = false;
finishSetupButton.Visible = true;
finishSetupButton.Enabled = true;
theme.ApplyPrimaryActionStyle(finishSetupButton);
}
else
{
startPrintButton.Visible = true;
startPrintButton.Enabled = true;
finishSetupButton.Visible = false;
theme.ApplyPrimaryActionStyle(startPrintButton);
}
break;
case CommunicationStates.PrintingFromSd:
case CommunicationStates.Printing:
case CommunicationStates.Paused:
default:
if (showSetupButton)
{
startPrintButton.Visible = false;
finishSetupButton.Visible = true;
finishSetupButton.Enabled = false;
theme.RemovePrimaryActionStyle(finishSetupButton);
}
else
{
startPrintButton.Visible = true;
startPrintButton.Enabled = false;
finishSetupButton.Visible = false;
theme.RemovePrimaryActionStyle(startPrintButton);
}
break;
}
}
private void Connection_CommunicationStateChanged(object s, EventArgs e)
{
UiThread.RunOnIdle(SetButtonStates);
}
private void Printer_SettingChanged(object s, EventArgs e)
{
if (e is StringEventArgs stringEvent
&& (stringEvent.Data == SettingsKey.z_probe_z_offset
|| stringEvent.Data == SettingsKey.print_leveling_data
|| stringEvent.Data == SettingsKey.print_leveling_solution
|| stringEvent.Data == SettingsKey.bed_temperature
|| stringEvent.Data == SettingsKey.print_leveling_enabled
|| stringEvent.Data == SettingsKey.print_leveling_required_to_print
|| stringEvent.Data == SettingsKey.filament_has_been_loaded))
{
SetButtonStates();
}
}
}
}

View file

@ -62,6 +62,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
this.PopupHAnchor = HAnchor.Fit;
this.PopupVAnchor = VAnchor.Fit;
this.MakeScrollable = false;
this.DynamicPopupContent = () =>
{
var menuTheme = ApplicationController.Instance.MenuTheme;
@ -106,7 +110,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Margin = new BorderDouble(2, 0)
};
var sectionWidget = new SectionWidget("Advanced", subPanel, menuTheme, expanded: true)
bool anySettingOverridden = false;
anySettingOverridden |= printer.Settings.GetValue<bool>(SettingsKey.spiral_vase);
anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause));
var sectionWidget = new SectionWidget("Advanced", subPanel, menuTheme, expanded: anySettingOverridden)
{
Name = "Advanced Section",
HAnchor = HAnchor.Stretch,
@ -115,15 +123,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
column.AddChild(sectionWidget);
bool anySettingOverridden = false;
anySettingOverridden |= printer.Settings.GetValue<bool>(SettingsKey.spiral_vase);
anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause));
sectionWidget.Load += (s, e) =>
{
sectionWidget.Checkbox.Checked = anySettingOverridden;
};
foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause })
{
subPanel.AddChild(
@ -142,13 +141,45 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
sectionWidget.ContentPanel.Children<SettingsRow>().First().Border = new BorderDouble(0, 1);
sectionWidget.ContentPanel.Children<SettingsRow>().Last().Border = 0;
var button = new TextButton("Start Print".Localize(), menuTheme)
var printerReadyToTakeCommands = printer.Connection.CommunicationState == PrinterCommunication.CommunicationStates.FinishedPrint
|| printer.Connection.CommunicationState == PrinterCommunication.CommunicationStates.Connected;
var printerIsConnected = printer.Connection.CommunicationState != PrinterCommunication.CommunicationStates.Disconnected;
var printerNeedsToRunSetup = ApplicationController.PrinterNeedsToRunSetup(printer);
// add the start print button
var setupRow = new FlowLayoutWidget()
{
HAnchor = HAnchor.Stretch
};
var printingMessage = "";
if (!printerIsConnected)
{
printingMessage = "Need to connect before printing".Localize();
}
else if(printerNeedsToRunSetup)
{
printingMessage = "Setup needs to be run before printing".Localize();
}
if (!string.IsNullOrEmpty(printingMessage))
{
setupRow.AddChild(new TextWidget(printingMessage, textColor: menuTheme.TextColor)
{
VAnchor = VAnchor.Center,
AutoExpandBoundsToText = true,
});
}
var startPrintButton = new TextButton("Start Print".Localize(), menuTheme)
{
Name = "Start Print Button",
HAnchor = HAnchor.Right,
VAnchor = VAnchor.Absolute,
Enabled = printerIsConnected && !printerNeedsToRunSetup
};
button.Click += (s, e) =>
startPrintButton.Click += (s, e) =>
{
// Exit if the bed is not GCode and the bed has no printable items
if ((printer.Bed.EditContext.SourceItem as ILibraryAsset)?.ContentType != "gcode"
@ -169,9 +200,43 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
CancellationToken.None);
});
};
column.AddChild(button);
setupRow.AddChild(new HorizontalSpacer());
setupRow.AddChild(startPrintButton);
theme.ApplyPrimaryActionStyle(button);
column.AddChild(setupRow);
if (!printerNeedsToRunSetup)
{
theme.ApplyPrimaryActionStyle(startPrintButton);
}
// put in setup if needed
if (printerNeedsToRunSetup && printerIsConnected)
{
// add the finish setup button
var finishSetupButton = new TextButton("Setup...".Localize(), theme)
{
Name = "Finish Setup Button",
ToolTipText = "Run setup configuration for printer.".Localize(),
Margin = theme.ButtonSpacing,
Enabled = printerReadyToTakeCommands,
HAnchor = HAnchor.Right,
VAnchor = VAnchor.Absolute,
};
theme.ApplyPrimaryActionStyle(finishSetupButton);
finishSetupButton.Click += (s, e) =>
{
UiThread.RunOnIdle(async () =>
{
await ApplicationController.Instance.PrintPart(
printer.Bed.EditContext,
printer,
null,
CancellationToken.None);
});
};
column.AddChild(finishSetupButton);
}
return column;
};

View file

@ -92,7 +92,34 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
this.AddChild(new PrinterConnectButton(printer, theme));
this.AddChild(new PrintButton(printer, theme));
// add the start print button
GuiWidget startPrintButton;
this.AddChild(startPrintButton = new PrintPopupMenu(printer, theme)
{
Margin = theme.ButtonSpacing
});
void SetPrintButtonStyle(object s, EventArgs e)
{
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.FinishedPrint:
case CommunicationStates.Connected:
theme.ApplyPrimaryActionStyle(startPrintButton);
break;
default:
theme.RemovePrimaryActionStyle(startPrintButton);
break;
}
}
// make sure the buttons state is set correctly
printer.Connection.CommunicationStateChanged += SetPrintButtonStyle;
startPrintButton.Closed += (s, e) => printer.Connection.CommunicationStateChanged -= SetPrintButtonStyle;
// and set the style right now
SetPrintButtonStyle(this, null);
this.AddChild(new SliceButton(printer, printerTabPage, theme)
{