From a3cc4c8f9634a6f6626df2fa9b9a8598d8bfb76f Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 4 Jan 2019 17:49:58 -0800 Subject: [PATCH] Remove additional presentation data from validation errors - Add location property - Have caller concatenate Location with Details --- .../ApplicationView/ApplicationController.cs | 12 +- .../ApplicationView/SettingsValidation.cs | 118 +++++++----------- .../ApplicationView/ValidationError.cs | 2 + .../CustomWidgets/ExportPrintItemPage.cs | 10 +- .../PartPreviewWindow/PrinterTabPage.cs | 10 +- .../View3D/PrinterBar/SliceButton.cs | 10 +- 6 files changed, 81 insertions(+), 81 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 535607a16..54b635865 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -2254,14 +2254,20 @@ namespace MatterHackers.MatterControl var errors = SettingsValidation.SettingsValid(printer); if(errors.Count > 0) { - // Project to newline separated Error/Details string - var formattedErrors = errors.Select(err => $"{err.Error}\n\n{err.Details}").ToArray(); + // Project to newline separated Error/Details/Location string + var formattedErrors = errors.Select(err => + { + // Conditionally combine Error/Details/Location when not empty + return err.Error + + ((string.IsNullOrWhiteSpace(err.Details)) ? "" : $"\n\n{err.Details}") + + ((string.IsNullOrWhiteSpace(err.Location)) ? "" : $"\n\n{err.Location}"); + }).ToArray(); StyledMessageBox.ShowMessageBox( string.Join("\n__________________\n\n", formattedErrors), "Export Error".Localize()); } - else // there are no erros continue printing + else // there are no errors continue printing { // 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)) diff --git a/MatterControlLib/ApplicationView/SettingsValidation.cs b/MatterControlLib/ApplicationView/SettingsValidation.cs index 5ca69e718..07aadf18a 100644 --- a/MatterControlLib/ApplicationView/SettingsValidation.cs +++ b/MatterControlLib/ApplicationView/SettingsValidation.cs @@ -59,7 +59,8 @@ namespace MatterHackers.MatterControl { Error = "{0} must be less than or equal to the {1}.".Localize().FormatWith( GetSettingsName(SettingsKey.layer_height), GetSettingsName(SettingsKey.nozzle_diameter)), - Details = $"{details}\n\n{GetSettingsLocation(SettingsKey.layer_height)}" + Details = details, + Location = GetSettingsLocation(SettingsKey.layer_height) }); } else if (settings.GetValue(SettingsKey.layer_height) <= 0) @@ -68,7 +69,7 @@ namespace MatterHackers.MatterControl new ValidationError() { Error = "{0} must be greater than 0.".Localize().FormatWith(GetSettingsName(SettingsKey.layer_height)), - Details = GetSettingsLocation(SettingsKey.layer_height) + Location = GetSettingsLocation(SettingsKey.layer_height) }); } else if (settings.GetValue(SettingsKey.first_layer_height) > settings.GetValue(SettingsKey.nozzle_diameter)) @@ -79,15 +80,14 @@ namespace MatterHackers.MatterControl GetSettingsName(SettingsKey.nozzle_diameter), settings.GetValue(SettingsKey.nozzle_diameter)); - var location = GetSettingsLocation(SettingsKey.first_layer_height); - errors.Add( new ValidationError() { Error = "{0} must be less than or equal to the {1}.".Localize().FormatWith( GetSettingsName(SettingsKey.layer_height), GetSettingsName(SettingsKey.nozzle_diameter)), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = details, + Location = GetSettingsLocation(SettingsKey.first_layer_height) }); } } @@ -99,29 +99,25 @@ namespace MatterHackers.MatterControl { foreach (string startGCodeLine in startGCode) { - var location = GetSettingsLocation(SettingsKey.start_gcode); - if (startGCodeLine.StartsWith("G29")) { - var details = "Your Start G-Code should not contain a G29 if you are planning on using Print Recovery. Change your start G-Code or turn off Print Recovery.".Localize(); - errors.Add( new ValidationError() { Error = "Start G-Code cannot contain G29 if Print Recovery is enabled.".Localize(), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "Your Start G-Code should not contain a G29 if you are planning on using Print Recovery. Change your start G-Code or turn off Print Recovery.".Localize(), + Location = GetSettingsLocation(SettingsKey.start_gcode) }); } if (startGCodeLine.StartsWith("G30")) { - var details = "Your Start G-Code should not contain a G30 if you are planning on using Print Recovery. Change your start G-Code or turn off Print Recovery.".Localize(); - errors.Add( new ValidationError() { Error = "Start G-Code cannot contain G30 if Print Leveling is enabled.".Localize(), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "Your Start G-Code should not contain a G30 if you are planning on using Print Recovery. Change your start G-Code or turn off Print Recovery.".Localize(), + Location = GetSettingsLocation(SettingsKey.start_gcode) }); } } @@ -134,27 +130,23 @@ namespace MatterHackers.MatterControl { if (startGCodeLine.StartsWith("G29")) { - var location = GetSettingsLocation(SettingsKey.start_gcode); - var details = "Your Start G-Code should not contain a G29 if you are planning on using print leveling. Change your start G-Code or turn off print leveling.".Localize(); - errors.Add( new ValidationError() { Error = "Start G-Code cannot contain G29 if Print Leveling is enabled.".Localize(), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "Your Start G-Code should not contain a G29 if you are planning on using print leveling. Change your start G-Code or turn off print leveling.".Localize(), + Location = GetSettingsLocation(SettingsKey.start_gcode) }); } if (startGCodeLine.StartsWith("G30")) { - var location = GetSettingsLocation(SettingsKey.start_gcode); - var details = "Your Start G-Code should not contain a G30 if you are planning on using print leveling. Change your start G-Code or turn off print leveling.".Localize(); - errors.Add( new ValidationError() { Error = "Start G-Code cannot contain G30 if Print Leveling is enabled.".Localize(), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "Your Start G-Code should not contain a G30 if you are planning on using print leveling. Change your start G-Code or turn off print leveling.".Localize(), + Location = GetSettingsLocation(SettingsKey.start_gcode) }); } } @@ -163,6 +155,7 @@ namespace MatterHackers.MatterControl // If we have print leveling turned on then make sure we don't have any leveling commands in the start gcode. if (Math.Abs(settings.GetValue(SettingsKey.baby_step_z_offset)) > 2) { + // TODO: is this different than GetSettingsLocation? var location = "Location".Localize() + ":"; location += "\n" + "Controls".Localize(); location += "\n • " + "Movement".Localize(); @@ -174,7 +167,8 @@ namespace MatterHackers.MatterControl new ValidationError() { Error = "Z Offset is too large.".Localize(), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = details, + Location = location }); } @@ -186,31 +180,28 @@ namespace MatterHackers.MatterControl GetSettingsName(SettingsKey.nozzle_diameter), settings.GetValue(SettingsKey.nozzle_diameter)); - string location = GetSettingsLocation(SettingsKey.first_layer_extrusion_width); - errors.Add( new ValidationError() { Error = "{0} must be less than or equal to the {1} * 4.".Localize().FormatWith( GetSettingsName(SettingsKey.first_layer_extrusion_width), GetSettingsName(SettingsKey.nozzle_diameter)), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = details, + Location = GetSettingsLocation(SettingsKey.first_layer_extrusion_width) }); } if (settings.GetValue(SettingsKey.first_layer_extrusion_width) <= 0) { - var details = "{0} = {1}".FormatWith( - GetSettingsName(SettingsKey.first_layer_extrusion_width), - settings.GetValue(SettingsKey.first_layer_extrusion_width)); - string location = GetSettingsLocation(SettingsKey.first_layer_extrusion_width); - errors.Add( new ValidationError() { Error = "{0} must be greater than 0.".Localize().FormatWith( GetSettingsName(SettingsKey.first_layer_extrusion_width)), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "{0} = {1}".FormatWith( + GetSettingsName(SettingsKey.first_layer_extrusion_width), + settings.GetValue(SettingsKey.first_layer_extrusion_width)), + Location = GetSettingsLocation(SettingsKey.first_layer_extrusion_width) }); } @@ -221,7 +212,6 @@ namespace MatterHackers.MatterControl settings.GetValue(SettingsKey.external_perimeter_extrusion_width), GetSettingsName(SettingsKey.nozzle_diameter), settings.GetValue(SettingsKey.nozzle_diameter)); - string location = GetSettingsLocation(SettingsKey.external_perimeter_extrusion_width); errors.Add( new ValidationError() @@ -229,87 +219,75 @@ namespace MatterHackers.MatterControl Error = "{0} must be less than or equal to the {1} * 4.".Localize().FormatWith( GetSettingsName(SettingsKey.external_perimeter_extrusion_width), GetSettingsName(SettingsKey.nozzle_diameter)), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = details, + Location = GetSettingsLocation(SettingsKey.external_perimeter_extrusion_width) }); } if (settings.GetValue(SettingsKey.external_perimeter_extrusion_width) <= 0) { - var details = "{0} = {1}".FormatWith( - GetSettingsName(SettingsKey.external_perimeter_extrusion_width), - settings.GetValue(SettingsKey.external_perimeter_extrusion_width)); - var location = GetSettingsLocation(SettingsKey.external_perimeter_extrusion_width); errors.Add( new ValidationError() { Error = "{0} must be greater than 0.".Localize().FormatWith( GetSettingsName(SettingsKey.external_perimeter_extrusion_width)), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "{0} = {1}".FormatWith( + GetSettingsName(SettingsKey.external_perimeter_extrusion_width), + settings.GetValue(SettingsKey.external_perimeter_extrusion_width)), + Location = GetSettingsLocation(SettingsKey.external_perimeter_extrusion_width) }); } if (settings.GetValue(SettingsKey.min_fan_speed) > 100) { - var details = "It is currently set to {0}.".Localize().FormatWith( - settings.GetValue(SettingsKey.min_fan_speed)); - - var location = GetSettingsLocation(SettingsKey.min_fan_speed); - errors.Add( new ValidationError() { Error = "The {0} can only go as high as 100%.".Localize().FormatWith( GetSettingsName(SettingsKey.min_fan_speed)), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "It is currently set to {0}.".Localize().FormatWith( + settings.GetValue(SettingsKey.min_fan_speed)), + Location = GetSettingsLocation(SettingsKey.min_fan_speed) }); } if (settings.GetValue(SettingsKey.max_fan_speed) > 100) { - var details = "It is currently set to {0}.".Localize().FormatWith( - settings.GetValue(SettingsKey.max_fan_speed)); - var location = GetSettingsLocation(SettingsKey.max_fan_speed); - errors.Add( new ValidationError() { Error = "The {0} can only go as high as 100%.".Localize().FormatWith( GetSettingsName(SettingsKey.max_fan_speed)), - Details = "{0}\n\n{1".FormatWith(details, location) + Details = "It is currently set to {0}.".Localize().FormatWith( + settings.GetValue(SettingsKey.max_fan_speed)), + Location = GetSettingsLocation(SettingsKey.max_fan_speed) }); } if (settings.GetValue(SettingsKey.extruder_count) < 1) { - var details = "It is currently set to {0}.".Localize().FormatWith( - settings.GetValue(SettingsKey.extruder_count)); - - var location = GetSettingsLocation(SettingsKey.extruder_count); - errors.Add( new ValidationError() { Error = "The {0} must be at least 1.".Localize().FormatWith( GetSettingsName(SettingsKey.extruder_count)), - Details= "{0}\n\n{1}".FormatWith(details, location) + Details= "It is currently set to {0}.".Localize().FormatWith( + settings.GetValue(SettingsKey.extruder_count)), + Location = GetSettingsLocation(SettingsKey.extruder_count) }); } if (settings.GetValue(SettingsKey.fill_density) < 0 || settings.GetValue(SettingsKey.fill_density) > 1) { - var error = "The {0} must be between 0 and 1.".Localize().FormatWith( - GetSettingsName(SettingsKey.fill_density)); - var details = "It is currently set to {0}.".Localize().FormatWith( - settings.GetValue(SettingsKey.fill_density)); - var location = GetSettingsLocation(SettingsKey.filament_density); - - errors.Add( new ValidationError() { - Error = error, - Details = "{0}\n\n{1}".FormatWith(details, location) + Error = "The {0} must be between 0 and 1.".Localize().FormatWith( + GetSettingsName(SettingsKey.fill_density)), + Details = "It is currently set to {0}.".Localize().FormatWith( + settings.GetValue(SettingsKey.fill_density)), + Location = GetSettingsLocation(SettingsKey.filament_density) }); } @@ -392,14 +370,13 @@ namespace MatterHackers.MatterControl SliceSettingData data = SettingsOrganizer.Instance.GetSettingsData(gCodeSetting); if (data != null) { - var location = GetSettingsLocation(gCodeSetting); - var details = "Found a line that is {0} characters long.\n{1}...".Localize().FormatWith(length, trimedLine.Substring(0, 20)); errors.Add( new ValidationError() { Error = "All G-Code lines mush be shorter than 100 characters (excluding comments).".Localize().FormatWith(data.PresentationName), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = details, + Location = GetSettingsLocation(gCodeSetting) }); } @@ -433,15 +410,12 @@ namespace MatterHackers.MatterControl SliceSettingData data = SettingsOrganizer.Instance.GetSettingsData(speedSetting); if (data != null) { - var location = GetSettingsLocation(speedSetting); - - var details = "It is currently set to {0}.".Localize().FormatWith(actualSpeedValueString); - errors.Add( new ValidationError() { Error = "The {0} must be greater than 0.".Localize().FormatWith(data.PresentationName), - Details = "{0}\n\n{1}".FormatWith(details, location) + Details = "It is currently set to {0}.".Localize().FormatWith(actualSpeedValueString), + Location = GetSettingsLocation(speedSetting) }); } } diff --git a/MatterControlLib/ApplicationView/ValidationError.cs b/MatterControlLib/ApplicationView/ValidationError.cs index 4f61da6b6..fbf80be1b 100644 --- a/MatterControlLib/ApplicationView/ValidationError.cs +++ b/MatterControlLib/ApplicationView/ValidationError.cs @@ -38,5 +38,7 @@ namespace MatterHackers.MatterControl public string Source { get; set; } public string SourceName { get; set; } + + public string Location { get; set; } } } \ No newline at end of file diff --git a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs index 286a068a5..13ea0e021 100644 --- a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs +++ b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs @@ -245,8 +245,14 @@ namespace MatterHackers.MatterControl { UiThread.RunOnIdle(() => { - // Project to newline separated Error/Details string - var formattedErrors = exportErrors.Select(err => $"{err.Error}\n\n{err.Details}").ToArray(); + // Project to newline separated Error/Details/Location string + var formattedErrors = exportErrors.Select(err => + { + // Conditionally combine Error/Details/Location when not empty + return err.Error + + ((string.IsNullOrWhiteSpace(err.Details)) ? "" : $"\n\n{err.Details}") + + ((string.IsNullOrWhiteSpace(err.Location)) ? "" : $"\n\n{err.Location}"); + }).ToArray(); StyledMessageBox.ShowMessageBox( string.Join("\n__________________\n\n", formattedErrors), diff --git a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs index 86fe552da..91a51635d 100644 --- a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs +++ b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs @@ -548,8 +548,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { doSlicing = false; - // Project to newline separated Error/Details string - var formattedErrors = errors.Select(err => $"{err.Error}\n\n{err.Details}").ToArray(); + // Project to newline separated Error/Details/Location string + var formattedErrors = errors.Select(err => + { + // Conditionally combine Error/Details/Location when not empty + return err.Error + + ((string.IsNullOrWhiteSpace(err.Details)) ? "" : $"\n\n{err.Details}") + + ((string.IsNullOrWhiteSpace(err.Location)) ? "" : $"\n\n{err.Location}"); + }).ToArray(); StyledMessageBox.ShowMessageBox( string.Join("\n__________________\n\n", formattedErrors), diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs index 2e750833b..4779c946a 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs @@ -107,8 +107,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { doSlicing = false; - // Project to newline separated Error/Details string - var formattedErrors = errors.Select(err => $"{err.Error}\n\n{err.Details}").ToArray(); + // Project to newline separated Error/Details/Location string + var formattedErrors = errors.Select(err => + { + // Conditionally combine Error/Details/Location when not empty + return err.Error + + ((string.IsNullOrWhiteSpace(err.Details)) ? "" : $"\n\n{err.Details}") + + ((string.IsNullOrWhiteSpace(err.Location)) ? "" : $"\n\n{err.Location}"); + }).ToArray(); StyledMessageBox.ShowMessageBox( string.Join("\n__________________\n\n", formattedErrors),