From 45bd3ed1b7da1b8e0d9c7b8d736117d4cc9caa9f Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 28 Mar 2022 11:49:29 -0700 Subject: [PATCH] Don't show some warning if there are errors --- .../ApplicationView/ApplicationController.cs | 3 +- .../ApplicationView/SettingsValidation.cs | 66 +++++++++---------- .../CustomWidgets/ExportPrintItemPage.cs | 3 +- .../Library/Export/GCodeExport.cs | 2 +- .../PartPreviewWindow/PrinterTabPage.cs | 4 +- .../View3D/PrinterBar/SliceButton.cs | 4 +- .../SliceSettingsWidget.cs | 3 +- .../SlicerConfiguration/UIFields/UIField.cs | 3 +- 8 files changed, 48 insertions(+), 40 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index e11627e8f..14f7af2cd 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -1943,7 +1943,8 @@ namespace MatterHackers.MatterControl printer.Connection.PrintingItemName = printItemName; - var errors = printer.ValidateSettings(validatePrintBed: !printer.Bed.EditContext.IsGGCodeSource); + var errors = new List(); + printer.ValidateSettings(errors, validatePrintBed: !printer.Bed.EditContext.IsGGCodeSource); if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error)) { this.ShowValidationErrors("Validation Error".Localize(), errors); diff --git a/MatterControlLib/ApplicationView/SettingsValidation.cs b/MatterControlLib/ApplicationView/SettingsValidation.cs index 535e4c263..e7c6bcd64 100644 --- a/MatterControlLib/ApplicationView/SettingsValidation.cs +++ b/MatterControlLib/ApplicationView/SettingsValidation.cs @@ -48,7 +48,7 @@ namespace MatterHackers.MatterControl /// /// The printer to validate. /// A list of all warnings and errors. - public static List ValidateSettings(this PrinterConfig printer, SettingsContext settingsContext = null, bool validatePrintBed = true) + public static List ValidateSettings(this PrinterConfig printer, List 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(); - var extruderCount = settingsContext.GetValue(SettingsKey.extruder_count); - // Check to see if supports are required - if (!settingsContext.GetValue(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().FirstOrDefault(w => w.Name == "View3DContainerParent"); - if (sharedParent != null) - { - var supportsPopup = sharedParent.FindDescendant("Support SplitButton"); - supportsPopup.InvokeClick(); - } - } - } - }); - } - } - if (!settingsContext.GetValue(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(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().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; } diff --git a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs index 21dedbd05..53f65337b 100644 --- a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs +++ b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs @@ -128,7 +128,8 @@ namespace MatterHackers.MatterControl if (gcodeExportButton.Checked) { - var errors = printer.ValidateSettings(validatePrintBed: false); + var errors = new List(); + printer.ValidateSettings(errors, validatePrintBed: false); exportButton.Enabled = !errors.Any(item => item.ErrorLevel == ValidationErrorLevel.Error); diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index a328c5f73..6319012c8 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -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)) { diff --git a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs index 024af4f9f..8be749bb0 100644 --- a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs +++ b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs @@ -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(); + printer.ValidateSettings(errors); if (errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error)) { doSlicing = false; diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs index 81071bec5..963502eb5 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs @@ -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(); + printer.ValidateSettings(errors); if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error)) { doSlicing = false; diff --git a/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs b/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs index 142684f93..bef07cdf2 100644 --- a/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs +++ b/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs @@ -237,7 +237,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration this.settingsRows = new List<(GuiWidget, SliceSettingData)>(); - var errors = printer.ValidateSettings(settingsContext); + var errors = new List(); + printer.ValidateSettings(errors, settingsContext); // Loop over categories creating a tab for each foreach (var category in settingsSection.Categories) diff --git a/MatterControlLib/SlicerConfiguration/UIFields/UIField.cs b/MatterControlLib/SlicerConfiguration/UIFields/UIField.cs index f8afb5d5e..647161e63 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/UIField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/UIField.cs @@ -113,7 +113,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration userInitiated: false); } - var errors2 = printer.ValidateSettings(settingsContext); + var errors2 = new List(); + printer.ValidateSettings(errors2, settingsContext); if (errors != null) {