65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Livia.Models.Data;
|
|
using Livia.Utility;
|
|
|
|
namespace Livia.ViewModels;
|
|
|
|
public enum RoiLocationDisplayMode
|
|
{
|
|
Volume = 0,
|
|
RoiPercentage = 1,
|
|
RegionPercentage = 2
|
|
}
|
|
|
|
public class RoiLocationDataControlViewModel : ObservableObject
|
|
{
|
|
public string Name { get; }
|
|
public int Weight { get; }
|
|
public float RegionPercentage => _locationData.RegionPercentage ?? 0;
|
|
public string DisplayString { get => _displayString; private set => SetProperty(ref _displayString, value); }
|
|
public bool IsExpanded { get => _isExpanded; set => SetProperty(ref _isExpanded, value); }
|
|
public List<RoiLocationDataControlViewModel> SubLocations { get; }
|
|
public bool ContainsSubLocation => SubLocations.Count > 0;
|
|
|
|
|
|
private string _displayString = string.Empty;
|
|
private bool _isExpanded;
|
|
private readonly string _roiPercentage;
|
|
private readonly string _regionPercentage;
|
|
private readonly string _volume;
|
|
private readonly LocationData _locationData;
|
|
|
|
public RoiLocationDataControlViewModel(LocationData data)
|
|
{
|
|
SubLocations = new List<RoiLocationDataControlViewModel>();
|
|
_locationData = data;
|
|
Name = LiviaUtility.ParseServerString(_locationData.Name);
|
|
Weight = _locationData.Weight ?? 0;
|
|
_roiPercentage = $"{_locationData.Percentage / 100:P2}";
|
|
_volume = $"{_locationData.Volume:N3}ml";
|
|
_regionPercentage = $"{(_locationData.RegionPercentage ?? 0) / 100:P2}";
|
|
UpdateDisplayString(RoiLocationDisplayMode.Volume);
|
|
if (_locationData.SubLocations == null)
|
|
return;
|
|
|
|
foreach (LocationData subLocation in _locationData.SubLocations)
|
|
{
|
|
SubLocations.Add(new RoiLocationDataControlViewModel(subLocation));
|
|
}
|
|
}
|
|
|
|
public void UpdateDisplayString(RoiLocationDisplayMode mode)
|
|
{
|
|
DisplayString = mode switch
|
|
{
|
|
RoiLocationDisplayMode.RoiPercentage => _roiPercentage,
|
|
RoiLocationDisplayMode.RegionPercentage => _regionPercentage,
|
|
_ => _volume
|
|
};
|
|
|
|
foreach (RoiLocationDataControlViewModel subLocation in SubLocations)
|
|
{
|
|
subLocation.UpdateDisplayString(mode);
|
|
}
|
|
}
|
|
} |