Add LayerGCodeHasExpectedValue test
- Immutable PrinterSettings.BaseLayer - Add PrinterSettings.AutoSave flag to support disabling autosave - Save to default path fails under test - Add PrinterSettings.Save(path) to support manual save - Migrate 'active_quality_key' to SettingsKey class
This commit is contained in:
parent
353df4331b
commit
e83c5e7388
5 changed files with 93 additions and 49 deletions
|
|
@ -57,8 +57,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public static RootedObjectEventHandler PrintLevelingEnabledChanged = new RootedObjectEventHandler();
|
||||
|
||||
private static PrinterSettingsLayer baseLayerCache;
|
||||
|
||||
public static PrinterSettings Empty { get; }
|
||||
|
||||
public int DocumentVersion { get; set; } = LatestVersion;
|
||||
|
|
@ -110,7 +108,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[OnDeserialized]
|
||||
internal void OnDeserializedMethod(StreamingContext context)
|
||||
{
|
||||
|
|
@ -132,7 +130,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
"layer_id",
|
||||
};
|
||||
|
||||
if(!setLayerName)
|
||||
if (!setLayerName)
|
||||
{
|
||||
skipKeys.Add(SettingsKey.layer_name);
|
||||
}
|
||||
|
|
@ -146,9 +144,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
var sourceFilter = rawSourceFilter.Where(layer => layer != null);
|
||||
|
||||
var baseLayer = settingsToImport.BaseLayer;
|
||||
settingsToImport.BaseLayer = new PrinterSettingsLayer();
|
||||
|
||||
foreach (var keyName in PrinterSettings.KnownSettings)
|
||||
{
|
||||
if (settingsToImport.Contains(keyName))
|
||||
|
|
@ -171,8 +166,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
destinationLayer[SettingsKey.layer_name] = settingsToImport.GetValue(SettingsKey.layer_name, sourceFilter);
|
||||
}
|
||||
|
||||
settingsToImport.BaseLayer = baseLayer;
|
||||
|
||||
this.Save();
|
||||
|
||||
ApplicationController.Instance.ReloadAdvancedControlsPanel();
|
||||
|
|
@ -197,11 +190,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
get
|
||||
{
|
||||
return GetValue("active_quality_key");
|
||||
return GetValue(SettingsKey.active_quality_key);
|
||||
}
|
||||
internal set
|
||||
{
|
||||
SetValue("active_quality_key", value);
|
||||
SetValue(SettingsKey.active_quality_key, value);
|
||||
QualityLayer = GetQualityLayer(value);
|
||||
Save();
|
||||
}
|
||||
|
|
@ -267,17 +260,25 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
return SHA1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string DocumentPath => ProfileManager.Instance.ProfilePath(this.ID);
|
||||
|
||||
[JsonIgnore]
|
||||
public bool AutoSave { get; set; } = true;
|
||||
|
||||
public void Save()
|
||||
{
|
||||
// Skip save operation if on the EmptyProfile
|
||||
if (!this.PrinterSelected)
|
||||
if (!this.PrinterSelected || !this.AutoSave)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save(DocumentPath);
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
{
|
||||
lock (writeLock)
|
||||
{
|
||||
string json = this.ToJson();
|
||||
|
|
@ -289,7 +290,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
ProfileManager.Instance.Save();
|
||||
}
|
||||
|
||||
File.WriteAllText(DocumentPath, json);
|
||||
File.WriteAllText(filePath, json);
|
||||
}
|
||||
|
||||
if (ActiveSliceSettings.Instance?.ID == this.ID)
|
||||
|
|
@ -510,23 +511,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public PrinterSettingsLayer BaseLayer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (baseLayerCache == null)
|
||||
{
|
||||
baseLayerCache = SliceSettingsOrganizer.Instance.GetDefaultSettings();
|
||||
}
|
||||
|
||||
return baseLayerCache;
|
||||
}
|
||||
|
||||
internal set
|
||||
{
|
||||
baseLayerCache = value;
|
||||
}
|
||||
}
|
||||
public PrinterSettingsLayer BaseLayer { get; set; } = SliceSettingsOrganizer.Instance.GetDefaultSettings();
|
||||
|
||||
private IEnumerable<PrinterSettingsLayer> defaultLayerCascade
|
||||
{
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
break;
|
||||
|
||||
case "MatterControl.ActiveQualityKey":
|
||||
layer.Add("active_quality_key", item.Value);
|
||||
layer.Add(SettingsKey.active_quality_key, item.Value);
|
||||
break;
|
||||
|
||||
case "MatterControl.ActiveMaterialKey":
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
public const string ip_address = nameof(ip_address);
|
||||
public const string ip_port = nameof(ip_port);
|
||||
public const string first_layer_speed = nameof(first_layer_speed);
|
||||
public const string active_quality_key = nameof(active_quality_key);
|
||||
}
|
||||
|
||||
public class SettingsHelpers
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using MatterHackers.Localizations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
/*
|
||||
Copyright (c) 2014, Kevin Pope
|
||||
/*
|
||||
Copyright (c) 2016, Kevin Pope, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -35,6 +30,10 @@ either expressed or implied, of the FreeBSD Project.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using MatterHackers.Localizations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
|
|
@ -210,6 +209,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public class SliceSettingsOrganizer
|
||||
{
|
||||
private static Dictionary<string, string> defaultSettings = null;
|
||||
|
||||
private Dictionary<string, OrganizerUserLevel> userLevels = new Dictionary<string, OrganizerUserLevel>();
|
||||
|
||||
public Dictionary<string, OrganizerUserLevel> UserLevels
|
||||
|
|
@ -351,14 +352,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public PrinterSettingsLayer GetDefaultSettings()
|
||||
{
|
||||
Dictionary<string, string> settingsDictionary = new Dictionary<string, string>();
|
||||
|
||||
foreach(SliceSettingData settingsData in this.SettingsData)
|
||||
if (defaultSettings == null)
|
||||
{
|
||||
settingsDictionary[settingsData.SlicerConfigName] = settingsData.DefaultValue;
|
||||
var settingsDictionary = new Dictionary<string, string>();
|
||||
foreach (var sliceSettingsData in this.SettingsData)
|
||||
{
|
||||
settingsDictionary[sliceSettingsData.SlicerConfigName] = sliceSettingsData.DefaultValue;
|
||||
}
|
||||
|
||||
defaultSettings = settingsDictionary;
|
||||
}
|
||||
|
||||
return new PrinterSettingsLayer(settingsDictionary);
|
||||
return new PrinterSettingsLayer(defaultSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,43 @@ namespace MatterControl.Tests.MatterControl
|
|||
}).ToList();
|
||||
}
|
||||
|
||||
[Test, RunInApplicationDomain]
|
||||
public void LayerGCodeHasExpectedValue()
|
||||
{
|
||||
// Verifies "layer_gcode" is expected value: "; LAYER:[layer_num]"
|
||||
ValidateOnAllPrinters((printer, settings) =>
|
||||
{
|
||||
if (settings.GetValue(SettingsKey.layer_gcode) != "; LAYER:[layer_num]")
|
||||
{
|
||||
printer.RuleViolated = true;
|
||||
|
||||
/* Fix existing invalid items...
|
||||
string layerValue;
|
||||
if (settings.OemLayer.TryGetValue(SettingsKey.layer_gcode, out layerValue) && layerValue == "")
|
||||
{
|
||||
settings.OemLayer.Remove(SettingsKey.layer_gcode);
|
||||
}
|
||||
|
||||
if (settings.QualityLayer?.TryGetValue(SettingsKey.layer_gcode, out layerValue) == true && layerValue == "")
|
||||
{
|
||||
settings.QualityLayer.Remove(SettingsKey.layer_gcode);
|
||||
}
|
||||
|
||||
if (settings.MaterialLayer?.TryGetValue(SettingsKey.layer_gcode, out layerValue) == true && layerValue == "")
|
||||
{
|
||||
settings.MaterialLayer.Remove(SettingsKey.layer_gcode);
|
||||
}
|
||||
|
||||
// Reset to default values
|
||||
settings.UserLayer.Remove(SettingsKey.active_quality_key);
|
||||
settings.MaterialSettingsKeys = new List<string>();
|
||||
settings.StagedUserSettings = new PrinterSettingsLayer();
|
||||
|
||||
settings.Save(printer.ConfigPath); */
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StartGCodeWithExtrudesMustFollowM109Heatup()
|
||||
{
|
||||
|
|
@ -412,7 +449,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the given delegate for each known printer, passing in a PrinterConfig object that has
|
||||
/// Calls the given delegate for each printer as well as each quality/material layer, passing in a PrinterConfig object that has
|
||||
/// printer settings loaded into a SettingsLayer as well as state about the printer
|
||||
/// </summary>
|
||||
/// <param name="action">The action to invoke for each printer</param>
|
||||
|
|
@ -424,20 +461,30 @@ namespace MatterControl.Tests.MatterControl
|
|||
{
|
||||
printer.RuleViolated = false;
|
||||
|
||||
PrinterSettingsLayer oemLayer = printer.PrinterSettings.OemLayer;
|
||||
var printerSettings = printer.PrinterSettings;
|
||||
printerSettings.AutoSave = false;
|
||||
|
||||
action(printer, new PrinterSettings() { OemLayer = oemLayer });
|
||||
// Disable active material/quality overrides
|
||||
printerSettings.SetMaterialPreset(0, "");
|
||||
printerSettings.ActiveQualityKey = "";
|
||||
|
||||
// Validate just the OemLayer
|
||||
action(printer, printerSettings);
|
||||
|
||||
if (printer.RuleViolated)
|
||||
{
|
||||
ruleViolations.Add(printer.RelativeFilePath);
|
||||
}
|
||||
|
||||
// Validate material layers
|
||||
foreach (var layer in printer.PrinterSettings.MaterialLayers)
|
||||
{
|
||||
printer.RuleViolated = false;
|
||||
|
||||
action(printer, new PrinterSettings() { BaseLayer = oemLayer, OemLayer = layer });
|
||||
printerSettings.SetMaterialPreset(0, layer.LayerID);
|
||||
|
||||
// Validate the settings with this material layer active
|
||||
action(printer, printerSettings);
|
||||
|
||||
if (printer.RuleViolated)
|
||||
{
|
||||
|
|
@ -445,11 +492,17 @@ namespace MatterControl.Tests.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
printerSettings.SetMaterialPreset(0, "");
|
||||
|
||||
// Validate quality layers
|
||||
foreach (var layer in printer.PrinterSettings.QualityLayers)
|
||||
{
|
||||
printer.RuleViolated = false;
|
||||
|
||||
action(printer, new PrinterSettings() { BaseLayer = oemLayer, OemLayer = layer });
|
||||
printerSettings.ActiveQualityKey = layer.LayerID;
|
||||
|
||||
// Validate the settings with this quality layer active
|
||||
action(printer, printerSettings);
|
||||
|
||||
if (printer.RuleViolated)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue