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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue