Initial prototype for revised validation reporting

This commit is contained in:
John Lewin 2019-01-18 18:16:21 -08:00
parent 70b61e840f
commit ce948c105f
6 changed files with 115 additions and 52 deletions

View file

@ -0,0 +1,75 @@
/*
Copyright (c) 2019, 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.Collections.Generic;
using MatterHackers.Agg.Image;
namespace MatterHackers.MatterControl
{
public class NamedAction
{
public string Title { get; set; }
public string Shortcut { get; set; }
public Action Action { get; set; }
public ImageBuffer Icon { get; set; }
public Func<bool> IsEnabled { get; set; }
public string ID { get; set; }
}
public class ActionSeparator : NamedAction
{
}
public class NamedBoolAction : NamedAction
{
public Func<bool> GetIsActive { get; set; }
public Action<bool> SetIsActive { get; set; }
}
public abstract class LocalizedAction
{
public Func<string> TitleResolver { get; set; }
public string Title => this.TitleResolver?.Invoke();
public ImageBuffer Icon { get; set; }
}
public static class NamedActionExtensions
{
public static void Add(this List<NamedAction> list, string title, Action action)
{
list.Add(new NamedAction()
{
Title = title,
Action = action
});
}
}
}

View file

@ -44,5 +44,6 @@ namespace MatterHackers.MatterControl
public string Details { get; set; }
public ValidationErrorLevel ErrorLevel { get; set; } = ValidationErrorLevel.Error;
public NamedAction FixAction { get; set; }
}
}

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.SlicerConfiguration;
@ -44,6 +45,25 @@ namespace MatterHackers.MatterControl
var errors = new List<ValidationError>();
var printerIsConnected = printer.Connection.CommunicationState != PrinterCommunication.CommunicationStates.Disconnected;
if (!printerIsConnected)
{
errors.Add(new ValidationError()
{
Error = "Printer Disconnected".Localize(),
Details = "Connect to your printer to continue".Localize()
});
}
if (ApplicationController.PrinterNeedsToRunSetup(printer))
{
errors.Add(new ValidationError()
{
Error = "Setup Required".Localize(),
Details = "Setup needs to be run before printing".Localize()
});
}
// last let's check if there is any support in the scene and if it looks like it is needed
if (GenerateSupportPanel.RequiresSupport(printer.Bed.Scene))
{
@ -51,7 +71,16 @@ namespace MatterHackers.MatterControl
{
Error = "Support Recommended".Localize(),
Details = "Some of the parts appear to require support. Consider canceling this print then adding support to get the best results possible.".Localize(),
ErrorLevel = ValidationErrorLevel.Warning
ErrorLevel = ValidationErrorLevel.Warning,
FixAction = new NamedAction()
{
Title = "Add Supports".Localize(),
Action = () =>
{
// Do something like popup the supports panel or directly show the popup
System.Diagnostics.Debugger.Break();
}
}
});
}

View file

@ -36,33 +36,6 @@ using MatterHackers.MatterControl;
namespace MatterHackers.Agg.UI
{
public class NamedAction
{
public string Title { get; set; }
public string Shortcut { get; set; }
public Action Action { get; set; }
public ImageBuffer Icon { get; set; }
public Func<bool> IsEnabled { get; set; }
public string ID { get; internal set; }
}
public class ActionSeparator : NamedAction
{
}
public class NamedBoolAction : NamedAction
{
public Func<bool> GetIsActive { get; set; }
public Action<bool> SetIsActive { get; set; }
}
public abstract class LocalizedAction
{
public Func<string> TitleResolver { get; set; }
public string Title => this.TitleResolver?.Invoke();
public ImageBuffer Icon { get; set; }
}
public class SceneSelectionOperation : LocalizedAction
{
public Action<BedConfig> Action { get; set; }

View file

@ -195,6 +195,8 @@ namespace MatterHackers.MatterControl.Library.Export
// TODO: Prior code bypassed GCodeOverridePath mechanisms in EditContext. Consolidating into a single pathway
string gcodePath = printer.Bed.EditContext.GCodeFilePath(printer);
List<ValidationError> errors = new List<ValidationError>();
if (ApplicationSettings.ValidFileExtensions.IndexOf(sourceExtension, StringComparison.OrdinalIgnoreCase) >= 0
|| string.Equals(sourceExtension, ".mcx", StringComparison.OrdinalIgnoreCase))
{
@ -218,7 +220,7 @@ namespace MatterHackers.MatterControl.Library.Export
printer.Settings.SetValue(SettingsKey.spiral_vase, "1");
}
var errors = printer.ValidateSettings();
errors = printer.ValidateSettings();
if(errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error))
{
@ -257,7 +259,7 @@ namespace MatterHackers.MatterControl.Library.Export
});
}
return null;
return errors;
}
}
catch

View file

@ -154,39 +154,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
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 = "";
var errors = printer.ValidateSettings();
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 printEnabled = !errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error);
var startPrintButton = new TextButton("Start Print".Localize(), menuTheme)
{
Name = "Start Print Button",
Enabled = printerIsConnected && !printerNeedsToRunSetup
Enabled = printEnabled
};
startPrintButton.Click += (s, e) =>
@ -217,6 +198,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
column.AddChild(setupRow);
var printerNeedsToRunSetup = ApplicationController.PrinterNeedsToRunSetup(printer);
if (!printerNeedsToRunSetup)
{
theme.ApplyPrimaryActionStyle(startPrintButton);