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

@ -27,27 +27,20 @@ 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 System;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class PopupButton : GuiWidget, IIgnoredPopupChild, IMenuCreator
{
public Color HoverColor { get; set; } = new Color(0, 0, 0, 40);
public Color OpenColor { get; set; } = new Color(0, 0, 0, 40);
public event EventHandler PopupWindowClosed;
public event EventHandler BeforePopup;
public event EventHandler<GuiWidget> ConfigurePopup;
protected GuiWidget buttonView;
private bool menuVisibileAtMouseDown = false;
protected bool menuVisible = false;
private bool menuVisibileAtMouseDown = false;
private PopupWidget popupWidget;
private bool overridePopupHAnchor = false;
private bool overridePopupVAnchor = false;
public PopupButton()
{
@ -63,14 +56,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.AddChild(buttonView);
}
public bool AlignToRightEdge { get; set; }
public virtual Func<GuiWidget> DynamicPopupContent { get; set; }
public IPopupLayoutEngine PopupLayoutEngine { get; set; }
public Direction PopDirection { get; set; } = Direction.Down;
public bool MakeScrollable { get; set; } = true;
public virtual GuiWidget PopupContent { get; set; }
public event EventHandler BeforePopup;
public Color PopupBorderColor { get; set; } = Color.Transparent;
public event EventHandler PopupWindowClosed;
public bool AlignToRightEdge { get; set; }
public bool AlwaysKeepOpen { get; set; }
public override Color BackgroundColor
{
@ -78,12 +69,38 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
set => base.BackgroundColor = value;
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
public virtual Func<GuiWidget> DynamicPopupContent { get; set; }
public Color HoverColor { get; set; } = new Color(0, 0, 0, 40);
public bool KeepMenuOpen => menuVisible || this.AlwaysKeepOpen;
public bool MakeScrollable { get; set; } = true;
public Color OpenColor { get; set; } = new Color(0, 0, 0, 40);
public Direction PopDirection { get; set; } = Direction.Down;
public Color PopupBorderColor { get; set; } = Color.Transparent;
public virtual GuiWidget PopupContent { get; set; }
private HAnchor _popupHAnchor;
public HAnchor PopupHAnchor
{
// Store the menu state at the time of mousedown
menuVisibileAtMouseDown = menuVisible;
base.OnMouseDown(mouseEvent);
get => _popupHAnchor;
set
{
overridePopupHAnchor = true;
_popupHAnchor = value;
}
}
public IPopupLayoutEngine PopupLayoutEngine { get; set; }
private VAnchor _popupVAnchor;
public VAnchor PopupVAnchor
{
get => _popupVAnchor;
set
{
overridePopupVAnchor = true;
_popupVAnchor = value;
}
}
public void CloseMenu() => popupWidget?.CloseMenu();
public override void OnClick(MouseEventArgs mouseEvent)
{
@ -101,6 +118,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnClosed(e);
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
// Store the menu state at the time of mousedown
menuVisibileAtMouseDown = menuVisible;
base.OnMouseDown(mouseEvent);
}
public void ShowPopup()
{
if (PopupLayoutEngine == null)
@ -139,20 +163,21 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.PopupWindowClosed?.Invoke(this, null);
};
ConfigurePopup?.Invoke(this, popupWidget);
if (overridePopupHAnchor)
{
popupWidget.HAnchor = PopupHAnchor;
}
if (overridePopupVAnchor)
{
popupWidget.VAnchor = PopupVAnchor;
}
popupWidget.Focus();
}
public void CloseMenu() => popupWidget?.CloseMenu();
protected virtual void OnBeforePopup()
{
this.BeforePopup?.Invoke(this, null);
}
public bool AlwaysKeepOpen { get; set; }
public bool KeepMenuOpen => menuVisible || this.AlwaysKeepOpen;
}
}

View file

@ -138,7 +138,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
cancellationToken.ThrowIfCancellationRequested();
progressStatus.Status = status;
progressStatus.Progress0To1 = percentCompleted + amountPerOperation * progress0To1;
progressStatus.Progress0To1 = percentCompleted + (amountPerOperation * progress0To1);
reporter.Report(progressStatus);
}, cancellationToken);
@ -149,7 +149,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
cancellationToken.ThrowIfCancellationRequested();
progressStatus.Status = status;
progressStatus.Progress0To1 = percentCompleted + amountPerOperation * progress0To1;
progressStatus.Progress0To1 = percentCompleted + (amountPerOperation * progress0To1);
reporter?.Report(progressStatus);
}, cancellationToken);
@ -160,7 +160,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
cancellationToken.ThrowIfCancellationRequested();
progressStatus.Status = status;
progressStatus.Progress0To1 = percentCompleted + amountPerOperation * progress0To1;
progressStatus.Progress0To1 = percentCompleted + (amountPerOperation * progress0To1);
reporter.Report(progressStatus);
}, cancellationToken);
}
@ -180,9 +180,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
positionIndex.Add(key, i);
var position = Vector3.Transform(vertex.Position, matrix);
va[i * 3 + 0] = position.X;
va[i * 3 + 1] = position.Y;
va[i * 3 + 2] = position.Z;
va[(i * 3) + 0] = position.X;
va[(i * 3) + 1] = position.Y;
va[(i * 3) + 2] = position.Z;
i++;
}
}

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)
{

View file

@ -652,11 +652,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Margin = theme.ButtonSpacing,
};
libraryPopup.ConfigurePopup += (s, e) =>
{
e.HAnchor = HAnchor.Fit;
e.VAnchor = VAnchor.Fit;
};
libraryPopup.PopupHAnchor = HAnchor.Fit;
libraryPopup.PopupVAnchor = VAnchor.Fit;
return libraryPopup;
}

@ -1 +1 @@
Subproject commit 471501d30de9b18ce59951aba08819e5bef88e66
Subproject commit b0855708309d04c1c2c0373cba8382b4c82f84b4