mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-12 11:32:33 +02:00
6d6be66ced
- (Upgrade) AvaloniaUI from 0.10 to 0.10.2 - (Remove) Unused assemblies - **Issues** - Improve the performance when loading big lists of issues into the DataGrid - Auto refresh issues on the vertical highlight tracker once cath a modification on the Issues list - **Layer preview - Difference:** - Layer difference will now only check the pixels inside the union of previous, current and next layer bounding rectangle, increasing the performance and speed - Previous and next layer pixels if both exists was not showing with the configured color and using the next layer color instead - Respect Anti-Aliasing pixels and fade colors accordingly - Unlock the possiblity of using the layer difference on first and last layer - Add a option to show similar pixels instead of the difference - Change previous default color from (255, 0, 255) to (81, 131, 82) for better depth preception - Change next default color from (0, 255, 255) to (81, 249, 252) for better depth preception - Change previous & next default color from (255, 0, 0) to (246, 240, 216) for better depth preception - **(Fix) Pixel editor:** - Modification was append instead of prepend on the list - Modification was not updating the index number on the list - (Fix) PrusaSlicer printer: Bene4 Mono screen, bed and height size
281 lines
7.9 KiB
C#
281 lines
7.9 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.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Xml.Serialization;
|
|
using UVtools.Core.Objects;
|
|
|
|
namespace UVtools.Core.Managers
|
|
{
|
|
public class MaterialManager : BindableBase, IList<Material>
|
|
{
|
|
#region Settings
|
|
|
|
public static string FilePath;
|
|
#endregion
|
|
|
|
#region Singleton
|
|
|
|
private static Lazy<MaterialManager> _instanceHolder =
|
|
new(() => new MaterialManager());
|
|
|
|
/// <summary>
|
|
/// Instance of <see cref="UserSettings"/> (singleton)
|
|
/// </summary>
|
|
public static MaterialManager Instance => _instanceHolder.Value;
|
|
|
|
//public static List<Operation> Operations => _instance.Operations;
|
|
#endregion
|
|
|
|
#region Members
|
|
|
|
private RangeObservableCollection<Material> _materials = new();
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public RangeObservableCollection<Material> Materials
|
|
{
|
|
get => _materials;
|
|
set => RaiseAndSetIfChanged(ref _materials, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the total number of bottles in stock
|
|
/// </summary>
|
|
public int BottlesInStock => this.Sum(material => material.BottlesInStock);
|
|
|
|
/// <summary>
|
|
/// Gets the total number of bottles ever owned
|
|
/// </summary>
|
|
public int OwnedBottles => this.Sum(material => material.OwnedBottles);
|
|
|
|
/// <summary>
|
|
/// Gets the total of consumed volume in milliliters
|
|
/// </summary>
|
|
public decimal ConsumedVolume => this.Sum(material => material.ConsumedVolume);
|
|
|
|
/// <summary>
|
|
/// Gets the total of consumed volume in liters
|
|
/// </summary>
|
|
public decimal ConsumedVolumeLiters => this.Sum(material => material.ConsumedVolumeLiters);
|
|
|
|
/// <summary>
|
|
/// Gets the total volume in stock in milliliters
|
|
/// </summary>
|
|
public decimal VolumeInStock => this.Sum(material => material.VolumeInStock);
|
|
|
|
/// <summary>
|
|
/// Gets the total volume in stock in liters
|
|
/// </summary>
|
|
public decimal VolumeInStockLiters => VolumeInStock / 1000;
|
|
|
|
/// <summary>
|
|
/// Gets the total costs
|
|
/// </summary>
|
|
public decimal TotalCost => this.Sum(material => material.TotalCost);
|
|
|
|
/// <summary>
|
|
/// Gets the total print time in hours
|
|
/// </summary>
|
|
public double PrintTime => this.Sum(material => material.PrintTime);
|
|
|
|
/// <summary>
|
|
/// Gets the total print time
|
|
/// </summary>
|
|
public TimeSpan PrintTimeSpan => TimeSpan.FromHours(PrintTime);
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
private MaterialManager()
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
#region Methods
|
|
public Material this[int index]
|
|
{
|
|
get => _materials[index];
|
|
set => _materials[index] = value;
|
|
}
|
|
|
|
public Material this[uint index]
|
|
{
|
|
get => _materials[(int) index];
|
|
set => _materials[(int) index] = value;
|
|
}
|
|
|
|
public Material this[Material material]
|
|
{
|
|
get
|
|
{
|
|
var index = IndexOf(material);
|
|
return index < 0 ? this[index] : null;
|
|
}
|
|
set
|
|
{
|
|
var index = IndexOf(material);
|
|
if(index >= 0) this[index] = value;
|
|
}
|
|
}
|
|
|
|
public IEnumerator<Material> GetEnumerator() => _materials.GetEnumerator();
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
public void Add(Material item)
|
|
{
|
|
_materials.Add(item);
|
|
RaisePropertiesChanged();
|
|
}
|
|
|
|
public void Add(Material item, bool save)
|
|
{
|
|
Add(item);
|
|
if (save) Save();
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_materials.Clear();
|
|
RaisePropertiesChanged();
|
|
}
|
|
|
|
public void Clear(bool save)
|
|
{
|
|
Clear();
|
|
if(save) Save();
|
|
}
|
|
|
|
|
|
public bool Contains(Material item) => _materials.Contains(item);
|
|
|
|
public void CopyTo(Material[] array, int arrayIndex)
|
|
{
|
|
_materials.CopyTo(array, arrayIndex);
|
|
RaisePropertiesChanged();
|
|
}
|
|
|
|
public bool Remove(Material item)
|
|
{
|
|
if (_materials.Remove(item))
|
|
{
|
|
RaisePropertiesChanged();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void Remove(Material item, bool save)
|
|
{
|
|
Remove(item);
|
|
if (save) Save();
|
|
}
|
|
|
|
public void RemoveRange(IEnumerable<Material> collection)
|
|
{
|
|
_materials.RemoveRange(collection);
|
|
}
|
|
|
|
public int Count => _materials.Count;
|
|
public bool IsReadOnly => false;
|
|
public int IndexOf(Material item) => _materials.IndexOf(item);
|
|
|
|
public void Insert(int index, Material item)
|
|
{
|
|
_materials.Insert(index, item);
|
|
RaisePropertiesChanged();
|
|
}
|
|
|
|
public void Insert(int index, Material item, bool save)
|
|
{
|
|
Insert(index, item);
|
|
if (save) Save();
|
|
}
|
|
|
|
public void RemoveAt(int index)
|
|
{
|
|
_materials.RemoveAt(index);
|
|
RaisePropertiesChanged();
|
|
}
|
|
|
|
public void RemoveAt(int index, bool save)
|
|
{
|
|
RemoveAt(index);
|
|
if (save) Save();
|
|
}
|
|
|
|
public void RaisePropertiesChanged()
|
|
{
|
|
RaisePropertyChanged(nameof(BottlesInStock));
|
|
RaisePropertyChanged(nameof(OwnedBottles));
|
|
RaisePropertyChanged(nameof(ConsumedVolume));
|
|
RaisePropertyChanged(nameof(ConsumedVolumeLiters));
|
|
RaisePropertyChanged(nameof(VolumeInStock));
|
|
RaisePropertyChanged(nameof(VolumeInStockLiters));
|
|
RaisePropertyChanged(nameof(TotalCost));
|
|
RaisePropertyChanged(nameof(PrintTime));
|
|
RaisePropertyChanged(nameof(PrintTimeSpan));
|
|
RaisePropertyChanged(nameof(Count));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load settings from file
|
|
/// </summary>
|
|
public static void Load()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(FilePath) || !File.Exists(FilePath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var serializer = new XmlSerializer(Instance.GetType());
|
|
try
|
|
{
|
|
using var myXmlReader = new StreamReader(FilePath);
|
|
var instance = (MaterialManager)serializer.Deserialize(myXmlReader);
|
|
_instanceHolder = new Lazy<MaterialManager>(() => instance);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.WriteLine(e.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save settings to file
|
|
/// </summary>
|
|
public static void Save()
|
|
{
|
|
var serializer = new XmlSerializer(Instance.GetType());
|
|
try
|
|
{
|
|
using var myXmlWriter = new StreamWriter(FilePath);
|
|
serializer.Serialize(myXmlWriter, Instance);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.WriteLine(e.ToString());
|
|
}
|
|
}
|
|
|
|
public void SortByName()
|
|
{
|
|
_materials.Sort((material, material1) => string.Compare(material.Name, material1.Name, StringComparison.Ordinal));
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |