diff --git a/MatterControlLib/ApplicationView/SettingsValidation.cs b/MatterControlLib/ApplicationView/SettingsValidation.cs index b88259b7d..dc700e0dd 100644 --- a/MatterControlLib/ApplicationView/SettingsValidation.cs +++ b/MatterControlLib/ApplicationView/SettingsValidation.cs @@ -42,48 +42,17 @@ namespace MatterHackers.MatterControl { public static class SettingsValidation { + /// + /// Validates the printer settings satisfy all requirements + /// + /// The printer to validate + /// A list of all warnings and errors public static List ValidateSettings(this PrinterConfig printer) { var settings = printer.Settings; var errors = new List(); - 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() - }); - } - - // TODO: Consider splitting out each individual requirement in PrinterNeedsToRunSetup and reporting validation in a more granular fashion - if (ApplicationController.PrinterNeedsToRunSetup(printer)) - { - errors.Add(new ValidationError() - { - Error = "Printer Setup Required".Localize(), - Details = "Printer Setup must be run before printing".Localize(), - FixAction = new NamedAction() - { - ID = "SetupPrinter", - Title = "Setup".Localize() + "...", - Action = () => - { - UiThread.RunOnIdle(async () => - { - await ApplicationController.Instance.PrintPart( - printer.Bed.EditContext, - printer, - null, - CancellationToken.None); - }); - } - } - }); - } - // last let's check if there is any support in the scene and if it looks like it is needed var supportGenerator = new SupportGenerator(printer.Bed.Scene); if (supportGenerator.RequiresSupport()) @@ -373,6 +342,57 @@ namespace MatterHackers.MatterControl return errors; } + /// + /// Validates printer satisfies all requirements + /// + /// The printer to validate + /// A list of all warnings and errors + public static List Validate(this PrinterConfig printer) + { + var errors = new List(); + + 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() + }); + } + + // TODO: Consider splitting out each individual requirement in PrinterNeedsToRunSetup and reporting validation in a more granular fashion + if (ApplicationController.PrinterNeedsToRunSetup(printer)) + { + errors.Add(new ValidationError() + { + Error = "Printer Setup Required".Localize(), + Details = "Printer Setup must be run before printing".Localize(), + FixAction = new NamedAction() + { + ID = "SetupPrinter", + Title = "Setup".Localize() + "...", + Action = () => + { + UiThread.RunOnIdle(async () => + { + await ApplicationController.Instance.PrintPart( + printer.Bed.EditContext, + printer, + null, + CancellationToken.None); + }); + } + } + }); + } + + // Concat printer and settings errors + errors.AddRange(printer.ValidateSettings()); + + return errors; + } + private static string GetSettingsName(string settingsKey) { var settingData = PrinterSettings.SettingsData[settingsKey]; diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index b4612622b..476ae6c21 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -195,7 +195,7 @@ 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 errors = new List(); + var errors = new List(); if (ApplicationSettings.ValidFileExtensions.IndexOf(sourceExtension, StringComparison.OrdinalIgnoreCase) >= 0 || string.Equals(sourceExtension, ".mcx", StringComparison.OrdinalIgnoreCase)) diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs index 5350a0f1c..1e9fa8ead 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs @@ -160,7 +160,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }; // Perform validation before popup - var errors = printer.ValidateSettings(); + var errors = printer.Validate(); // Enable print option when no validation Errors exists var printEnabled = !errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error);