Files
Tiago Conceição 8e4995a6a5 v3.8.3
- **UVtoolsCmd:**
  - **print-properties:**
    - (Change) `-b`, `--base` option to `-a`, `-all` to indicate all properties and sub-properties, now defaults to only show base properties
    - (Add) `-r`, `--range` option to prints only the matching layer(s) index(es) in a range
    - (Add) `-i`, `--indexes` option to prints only the matching layer(s) index(es)
  - (Add) Command: `set-properties <input-file> <property=value> Set properties in a file or to it layers with new values`
  - (Add) Command: `print-issues <input-file> Detect and print issues in a file`
  - (Add) New option to the `run` command: `-p, --property <property=value>  Set a property with a new value (Compatible with operations only)`
  - (Remove) Command: `print-layers` as it has been moved to `print-properties`, use `-r :` to obtain same result as default on `print-layers`
- **Issues:**
  - (Fix) Issues groups with only one issue was displaying the wrong area value
  - (Fix) Volume incorrectly calculated, resulting in a high value for group of issues
  - (Fix) Incorrect calculation of the bounding rectangle for a group of issues
- **Repair layers:**
  - (Add) Switch to opt between "Re-detect the selected issues before repair" and "Use and repair the previous detected issues" (Default)
  - (Improvement) Do not allow to run the tool if there are no detected issues when the option "Use and repair the previous detected issues" is selected
- (Improvement) Linux: Recompile libcvextern.so on a older system to be able to run on both older and newest system (#603)
- (Upgrade) .NET from 6.0.10 to 6.0.11
2022-11-10 04:09:00 +00:00

178 lines
4.8 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using UVtools.Core;
using UVtools.Core.Extensions;
using UVtools.Core.Suggestions;
namespace UVtools.WPF.Structures;
public class SuggestionManager
{
#region Properties
/// <summary>
/// Default filepath for store
/// </summary>
public static string FilePath => Path.Combine(CoreSettings.DefaultSettingsFolderAndEnsureCreation, "suggestions.xml");
public SuggestionBottomLayerCount BottomLayerCount { get; set; } = new();
public SuggestionTransitionLayerCount TransitionLayerCount { get; set; } = new();
public SuggestionWaitTimeBeforeCure WaitTimeBeforeCure { get; set; } = new();
public SuggestionWaitTimeAfterCure WaitTimeAfterCure { get; set; } = new();
public SuggestionLayerHeight LayerHeight { get; set; } = new();
public SuggestionModelPosition ModelPosition { get; set; } = new();
/// <summary>
/// Gets all suggestions
/// </summary>
[XmlIgnore]
public Suggestion[] Suggestions
{
get
{
return new Suggestion[]
{
BottomLayerCount,
TransitionLayerCount,
WaitTimeBeforeCure,
WaitTimeAfterCure,
LayerHeight,
ModelPosition,
};
}
set
{
foreach (var suggestion in value)
{
Set(suggestion);
}
Save();
}
}
public void Set(Suggestion suggestion)
{
switch (suggestion)
{
case SuggestionBottomLayerCount bottomLayerCount:
BottomLayerCount = bottomLayerCount;
break;
case SuggestionTransitionLayerCount transitionLayerCount:
TransitionLayerCount = transitionLayerCount;
break;
case SuggestionWaitTimeBeforeCure waitTimeBeforeCure:
WaitTimeBeforeCure = waitTimeBeforeCure;
break;
case SuggestionWaitTimeAfterCure waitTimeAfterCure:
WaitTimeAfterCure = waitTimeAfterCure;
break;
case SuggestionLayerHeight layerHeight:
LayerHeight = layerHeight;
break;
case SuggestionModelPosition modelPosition:
ModelPosition = modelPosition;
break;
default: throw new ArgumentOutOfRangeException(nameof(suggestion));
}
}
public Suggestion? Get(Type type)
{
return Suggestions.FirstOrDefault(suggestion => suggestion.GetType() == type);
}
#endregion
#region Singleton
private static Lazy<SuggestionManager> _instanceHolder =
new(() => new SuggestionManager());
/// <summary>
/// Instance (singleton)
/// </summary>
public static SuggestionManager Instance => _instanceHolder.Value;
//public static List<Operation> Operations => _instance.Operations;
#endregion
#region Constructor
private SuggestionManager()
{ }
#endregion
#region Static Methods
public static void SetSuggestion(Suggestion suggestion, bool save = false)
{
Instance.Set(suggestion);
if(save) Save();
}
public static Suggestion? GetSuggestion(Type type)
{
return Instance.Get(type);
}
/// <summary>
/// Reset to defaults
/// </summary>
/// <param name="save">True to save settings on file, otherwise false</param>
public static void Reset(bool save = true)
{
_instanceHolder = new Lazy<SuggestionManager>(() => new SuggestionManager());
if (save) Save();
}
/// <summary>
/// Load settings from file
/// </summary>
public static void Load()
{
if (!File.Exists(FilePath))
{
return;
}
try
{
var instance = XmlExtensions.DeserializeFromFile<SuggestionManager>(FilePath);
_instanceHolder = new Lazy<SuggestionManager>(() => instance);
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
/// <summary>
/// Save settings to file
/// </summary>
public static void Save()
{
try
{
XmlExtensions.SerializeToFile(Instance, FilePath, XmlExtensions.SettingsIndent);
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
#endregion
}