Don't show some warning if there are errors

This commit is contained in:
Lars Brubaker 2022-03-28 11:49:29 -07:00
parent dd95d15b28
commit 45bd3ed1b7
8 changed files with 48 additions and 40 deletions

View file

@ -1943,7 +1943,8 @@ namespace MatterHackers.MatterControl
printer.Connection.PrintingItemName = printItemName;
var errors = printer.ValidateSettings(validatePrintBed: !printer.Bed.EditContext.IsGGCodeSource);
var errors = new List<ValidationError>();
printer.ValidateSettings(errors, validatePrintBed: !printer.Bed.EditContext.IsGGCodeSource);
if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error))
{
this.ShowValidationErrors("Validation Error".Localize(), errors);

View file

@ -48,7 +48,7 @@ namespace MatterHackers.MatterControl
/// </summary>
/// <param name="printer">The printer to validate.</param>
/// <returns>A list of all warnings and errors.</returns>
public static List<ValidationError> ValidateSettings(this PrinterConfig printer, SettingsContext settingsContext = null, bool validatePrintBed = true)
public static List<ValidationError> ValidateSettings(this PrinterConfig printer, List<ValidationError> errors, SettingsContext settingsContext = null, bool validatePrintBed = true)
{
var fffPrinter = printer.Settings.Slicer.PrinterType == PrinterType.FFF;
@ -57,39 +57,8 @@ namespace MatterHackers.MatterControl
settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
}
var errors = new List<ValidationError>();
var extruderCount = settingsContext.GetValue<int>(SettingsKey.extruder_count);
// Check to see if supports are required
if (!settingsContext.GetValue<bool>(SettingsKey.create_per_layer_support))
{
var supportGenerator = new SupportGenerator(printer.Bed.Scene, .05);
if (supportGenerator.RequiresSupport())
{
errors.Add(new ValidationError(ValidationErrors.UnsupportedParts)
{
Error = "Possible Unsupported Parts Detected".Localize(),
Details = "Some parts may require support structures to print correctly".Localize(),
ErrorLevel = ValidationErrorLevel.Warning,
FixAction = new NamedAction()
{
Title = "Generate Supports".Localize(),
Action = () =>
{
// Find and InvokeClick on the Generate Supports toolbar button
var sharedParent = ApplicationController.Instance.DragDropData.View3DWidget.Parents<GuiWidget>().FirstOrDefault(w => w.Name == "View3DContainerParent");
if (sharedParent != null)
{
var supportsPopup = sharedParent.FindDescendant("Support SplitButton");
supportsPopup.InvokeClick();
}
}
}
});
}
}
if (!settingsContext.GetValue<bool>(SettingsKey.extruder_offset))
{
var t0Offset = printer.Settings.Helpers.ExtruderOffset(0);
@ -473,6 +442,7 @@ namespace MatterHackers.MatterControl
if (printer.Connection.IsConnected
&& printer.Settings?.Helpers.ComPort() == "Emulator"
&& errors.Count(e => e.ErrorLevel == ValidationErrorLevel.Error) == 0
&& fffPrinter)
{
errors.Add(
@ -579,6 +549,36 @@ namespace MatterHackers.MatterControl
ValidateGoodSpeedSettingGreaterThan0(SettingsKey.travel_speed, settingsContext, errors);
ValidateGoodSpeedSettingGreaterThan0(SettingsKey.retract_speed, settingsContext, errors);
// Check to see if supports are required
if (!settingsContext.GetValue<bool>(SettingsKey.create_per_layer_support)
&& errors.Count(e => e.ErrorLevel == ValidationErrorLevel.Error) == 0)
{
var supportGenerator = new SupportGenerator(printer.Bed.Scene, .05);
if (supportGenerator.RequiresSupport())
{
errors.Add(new ValidationError(ValidationErrors.UnsupportedParts)
{
Error = "Possible Unsupported Parts Detected".Localize(),
Details = "Some parts may require support structures to print correctly".Localize(),
ErrorLevel = ValidationErrorLevel.Warning,
FixAction = new NamedAction()
{
Title = "Generate Supports".Localize(),
Action = () =>
{
// Find and InvokeClick on the Generate Supports toolbar button
var sharedParent = ApplicationController.Instance.DragDropData.View3DWidget.Parents<GuiWidget>().FirstOrDefault(w => w.Name == "View3DContainerParent");
if (sharedParent != null)
{
var supportsPopup = sharedParent.FindDescendant("Support SplitButton");
supportsPopup.InvokeClick();
}
}
}
});
}
}
if (printer.Connection.IsConnected
&& !PrinterSetupRequired(printer)
&& validatePrintBed
@ -711,7 +711,7 @@ namespace MatterHackers.MatterControl
}
// Concatenate printer and settings errors
errors.AddRange(printer.ValidateSettings(validatePrintBed: !printer.Bed.EditContext.IsGGCodeSource));
printer.ValidateSettings(errors, validatePrintBed: !printer.Bed.EditContext.IsGGCodeSource);
return errors;
}

View file

@ -128,7 +128,8 @@ namespace MatterHackers.MatterControl
if (gcodeExportButton.Checked)
{
var errors = printer.ValidateSettings(validatePrintBed: false);
var errors = new List<ValidationError>();
printer.ValidateSettings(errors, validatePrintBed: false);
exportButton.Enabled = !errors.Any(item => item.ErrorLevel == ValidationErrorLevel.Error);

View file

@ -237,7 +237,7 @@ namespace MatterHackers.MatterControl.Library.Export
Printer.Settings.SetValue(SettingsKey.spiral_vase, spiralVaseOverride == SpiralVaseOptions.FORCE_ON ? "1" : "0");
}
errors = Printer.ValidateSettings(validatePrintBed: false);
Printer.ValidateSettings(errors, validatePrintBed: false);
if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error))
{

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
@ -782,7 +783,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
bool doSlicing = !activelySlicing && printer.Bed.EditContext.SourceItem != null;
if (doSlicing)
{
var errors = printer.ValidateSettings();
var errors = new List<ValidationError>();
printer.ValidateSettings(errors);
if (errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error))
{
doSlicing = false;

View file

@ -32,6 +32,7 @@ using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -102,7 +103,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
bool doSlicing = !activelySlicing && printer.Bed.EditContext.SourceItem != null;
if (doSlicing)
{
var errors = printer.ValidateSettings();
var errors = new List<ValidationError>();
printer.ValidateSettings(errors);
if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error))
{
doSlicing = false;

View file

@ -237,7 +237,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
this.settingsRows = new List<(GuiWidget, SliceSettingData)>();
var errors = printer.ValidateSettings(settingsContext);
var errors = new List<ValidationError>();
printer.ValidateSettings(errors, settingsContext);
// Loop over categories creating a tab for each
foreach (var category in settingsSection.Categories)

View file

@ -113,7 +113,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
userInitiated: false);
}
var errors2 = printer.ValidateSettings(settingsContext);
var errors2 = new List<ValidationError>();
printer.ValidateSettings(errors2, settingsContext);
if (errors != null)
{