Loading INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +5 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ using INAF.Apps.Uwp.Charts; using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Charts.Containers; using INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing; using INAF.Apps.Uwp.SLabDataManager.Helpers; using INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations; using INAF.Apps.Uwp.SLabDataManager.Helpers.UI; Loading @@ -13,6 +14,7 @@ using INAF.Apps.Uwp.SLabDataManager.Models.Fit; using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum; using INAF.Apps.Uwp.SLabDataManager.Services; using INAF.Apps.Uwp.SLabDataManager.ViewModels; using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels; using INAF.Libraries.NetStandard.Math.Fit.Linear; using INAF.Libraries.NetStandard.Math.Fit.Spline; using INAF.Libraries.Uwp.Logging; Loading Loading @@ -133,6 +135,7 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddSingleton<SegmentsFitModelHelper>() .AddSingleton<SelectedRefBand>() .AddSingleton<SettingsHelper>() .AddSingleton<SmoothingBoundariesContainer>() .AddSingleton<SpectraContainer>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() Loading @@ -153,6 +156,8 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddTransient<SplineProcessingHelper>() .AddTransient<RemoteOperationsManager>() .AddTransient<RemoteOperationsXmlReader>() .AddTransient<SmoothingDefaultBoundariesReader>() .AddTransient<SmoothingViewModel>() .AddTransient<SpectrumModelFactory>() .AddTransient<SpectrumProcessingHelper>() .AddTransient<SpectrumReader>() Loading INAF.Apps.Uwp.SLabDataManager/Assets/xml/remoteoperations.xml +2 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,8 @@ <operation type="IsTokenValid">Account/IsTokenValid</operation> <operation type="IsLoginValid">Account/IsLoginValid</operation> <operation type="SaveSpectrumOfTypeAligned">AppSpectraFilesActions/SaveSpectrumOfTypeAligned</operation> <operation type="SaveSpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveSpectrumOfTypeContinuumRemoved</operation> <operation type="UpsertSpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/UpsertSpectrumOfTypeContinuumRemoved</operation> <operation type="SaveAsCopySpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveAsCopySpectrumOfTypeContinuumRemoved</operation> <operation type="SaveSpectrumOfTypeRaw">AppSpectraFilesActions/SaveSpectrumOfTypeRaw</operation> <operation type="SaveSpectrumSampleData">AppSpectraFilesActions/SaveSpectrumSampleData</operation> <operation type="IsSavedOnCloud">AppSpectraFilesActions/IsSpectrumSavedOnCloud</operation> Loading INAF.Apps.Uwp.SLabDataManager/Assets/xml/smoothingdefaults.xml 0 → 100644 +7 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8" ?> <defaults> <boundary>350</boundary> <boundary>700</boundary> <boundary>1500</boundary> <boundary>2500</boundary> </defaults> No newline at end of file INAF.Apps.Uwp.SLabDataManager/Charts/Smoothing/BoundariesItem.cs 0 → 100644 +66 −0 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing { public sealed class BoundariesItem : ObservableObject { public BoundariesItem(double lowerBoundary, double higherBoundary, bool isAddButtonAllowed) { LowerBoundary = lowerBoundary; HigherBoundary = higherBoundary; IsAddButtonAllowed = isAddButtonAllowed; PolynomialOrder = 0; WindowSize = 0; } #region properties private double higherBoundary; public double HigherBoundary { get { return higherBoundary; } set { SetProperty(ref higherBoundary, value); } } private bool isAddButtonAllowed; public bool IsAddButtonAllowed { get { return isAddButtonAllowed; } set { SetProperty(ref isAddButtonAllowed, value); } } private double lowerBoundary; public double LowerBoundary { get { return lowerBoundary; } set { SetProperty(ref lowerBoundary, value); } } private int polynomialOrder; public int PolynomialOrder { get { return polynomialOrder; } set { SetProperty(ref polynomialOrder, value); } } private int windowSize; public int WindowSize { get { return windowSize; } set { SetProperty(ref windowSize, value); } } #endregion public void updateHigherBoundary(double newValue) { HigherBoundary = newValue; } public void updateLowerBoundary(double newValue) { LowerBoundary = newValue; } } } INAF.Apps.Uwp.SLabDataManager/Charts/Smoothing/SmoothingBoundariesContainer.cs 0 → 100644 +173 −0 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using INAF.Libraries.Uwp.Settings; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing { public sealed class SmoothingBoundariesContainer : ObservableObject { private readonly SettingsHelper settingsHelper; public SmoothingBoundariesContainer(SettingsHelper settingsHelper) { this.settingsHelper = settingsHelper; init(); } #region properties private ObservableCollection<BoundariesItem> boundaries; public ObservableCollection<BoundariesItem> Boundaries { get { return boundaries; } set { SetProperty(ref boundaries, value); } } private List<double> boundaryValues { get; set; } #endregion #region methods public void add(double value) { if (boundaryValues.Contains(value)) return; boundaryValues.Add(value); } private void addPropertyChangedListenerForBoundaries() { /* remove event-listener for each item, if existing */ Boundaries.All(x => { x.PropertyChanged -= X_PropertyChanged; return true; }); /* add event to each item, in order to save all changes for each item property */ Boundaries.All(x => { x.PropertyChanged += X_PropertyChanged; return true; }); } public void buildBoundaries() { /* re-order items for building well-ordered boundaries */ boundaryValues = boundaryValues.OrderBy(x => x).ToList(); /* build boundaries */ int boundaryValuesNum = boundaryValues.Count; for (int i = 0; i < boundaryValuesNum - 1; i++) { double lowerValue = boundaryValues[i]; if (i > 0) lowerValue = boundaryValues[i] + 1; bool isAddButtonAllowed = true; if (i == boundaryValuesNum - 2) isAddButtonAllowed = false; Boundaries.Add(new BoundariesItem(lowerValue, boundaryValues[i + 1], isAddButtonAllowed)); } addPropertyChangedListenerForBoundaries(); } private void X_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { saveBoundariesItemsSettings(); } private void deleteBoundariesItem(BoundariesItem item) { var previousItem = Boundaries.FirstOrDefault(x => x.LowerBoundary < item.LowerBoundary); if (previousItem == null) { /* if removing item is the 1st one, then extend range of 2nd item... */ var firstRemainingItem = Boundaries.ElementAt(1); firstRemainingItem.LowerBoundary = item.LowerBoundary; } else { /* ...otherwise, update previousItem boundary by extending its range */ previousItem.HigherBoundary = item.HigherBoundary; } /* remove selected item */ Boundaries.Remove(item); /* add/reset event-listener for boundaries */ addPropertyChangedListenerForBoundaries(); } public void init() { boundaryValues = new List<double>(); Boundaries = new ObservableCollection<BoundariesItem>(); } public void insertBoundariesItem(BoundariesItem item) { var nextItem = Boundaries.FirstOrDefault(x => x.LowerBoundary > item.HigherBoundary); if (nextItem == null) return; /* calculate the existing range between the selected item and the next one */ double range = nextItem.HigherBoundary - nextItem.LowerBoundary; /* calculate the range for the new boundariesItem by dividing the currente 'range' by 2 */ int newItemRange = (int)Math.Floor(range / 2d); /* insert a new boundaryItem */ double newHigherBoundary = nextItem.LowerBoundary + newItemRange; bool isAddButtonAllowed = true; if (!Boundaries.Any(x => x.HigherBoundary > newHigherBoundary)) isAddButtonAllowed = false; /* find position of selecteditem */ int index = 0; int boundariesNum = Boundaries.Count; for (int i = 0; i < boundariesNum; i++) { if (nextItem.LowerBoundary == Boundaries[i].HigherBoundary + 1) { index = i; break; } } Boundaries.Insert(index + 1, new BoundariesItem(nextItem.LowerBoundary, newHigherBoundary, isAddButtonAllowed)); /* calculate the new lower-boundary for nextItem and apply it */ double newLowerBoundary = newHigherBoundary + 1; nextItem.updateLowerBoundary(newLowerBoundary); /* add/reset event-listener for boundaries */ addPropertyChangedListenerForBoundaries(); } private void saveBoundariesItemsSettings() { settingsHelper.remove(nameof(Boundaries)); settingsHelper.save<List<BoundariesItem>>(nameof(Boundaries), Boundaries.ToList()); } private void tryReadBoundariesItemsSettings() { if (!settingsHelper.contains(nameof(Boundaries))) return; } #endregion #region commands private RelayCommand<BoundariesItem> commandDeleteBoundariesItem; public RelayCommand<BoundariesItem> CommandDeleteBoundariesItem => commandDeleteBoundariesItem ?? (commandDeleteBoundariesItem = new RelayCommand<BoundariesItem>((item) => deleteBoundariesItem(item))); private RelayCommand<BoundariesItem> commandInsertBoundariesItem; public RelayCommand<BoundariesItem> CommandInsertBoundariesItem => commandInsertBoundariesItem ?? (commandInsertBoundariesItem = new RelayCommand<BoundariesItem>((item) => insertBoundariesItem(item))); #endregion } } Loading
INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +5 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ using INAF.Apps.Uwp.Charts; using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Charts.Containers; using INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing; using INAF.Apps.Uwp.SLabDataManager.Helpers; using INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations; using INAF.Apps.Uwp.SLabDataManager.Helpers.UI; Loading @@ -13,6 +14,7 @@ using INAF.Apps.Uwp.SLabDataManager.Models.Fit; using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum; using INAF.Apps.Uwp.SLabDataManager.Services; using INAF.Apps.Uwp.SLabDataManager.ViewModels; using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels; using INAF.Libraries.NetStandard.Math.Fit.Linear; using INAF.Libraries.NetStandard.Math.Fit.Spline; using INAF.Libraries.Uwp.Logging; Loading Loading @@ -133,6 +135,7 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddSingleton<SegmentsFitModelHelper>() .AddSingleton<SelectedRefBand>() .AddSingleton<SettingsHelper>() .AddSingleton<SmoothingBoundariesContainer>() .AddSingleton<SpectraContainer>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() Loading @@ -153,6 +156,8 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddTransient<SplineProcessingHelper>() .AddTransient<RemoteOperationsManager>() .AddTransient<RemoteOperationsXmlReader>() .AddTransient<SmoothingDefaultBoundariesReader>() .AddTransient<SmoothingViewModel>() .AddTransient<SpectrumModelFactory>() .AddTransient<SpectrumProcessingHelper>() .AddTransient<SpectrumReader>() Loading
INAF.Apps.Uwp.SLabDataManager/Assets/xml/remoteoperations.xml +2 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,8 @@ <operation type="IsTokenValid">Account/IsTokenValid</operation> <operation type="IsLoginValid">Account/IsLoginValid</operation> <operation type="SaveSpectrumOfTypeAligned">AppSpectraFilesActions/SaveSpectrumOfTypeAligned</operation> <operation type="SaveSpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveSpectrumOfTypeContinuumRemoved</operation> <operation type="UpsertSpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/UpsertSpectrumOfTypeContinuumRemoved</operation> <operation type="SaveAsCopySpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveAsCopySpectrumOfTypeContinuumRemoved</operation> <operation type="SaveSpectrumOfTypeRaw">AppSpectraFilesActions/SaveSpectrumOfTypeRaw</operation> <operation type="SaveSpectrumSampleData">AppSpectraFilesActions/SaveSpectrumSampleData</operation> <operation type="IsSavedOnCloud">AppSpectraFilesActions/IsSpectrumSavedOnCloud</operation> Loading
INAF.Apps.Uwp.SLabDataManager/Assets/xml/smoothingdefaults.xml 0 → 100644 +7 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8" ?> <defaults> <boundary>350</boundary> <boundary>700</boundary> <boundary>1500</boundary> <boundary>2500</boundary> </defaults> No newline at end of file
INAF.Apps.Uwp.SLabDataManager/Charts/Smoothing/BoundariesItem.cs 0 → 100644 +66 −0 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing { public sealed class BoundariesItem : ObservableObject { public BoundariesItem(double lowerBoundary, double higherBoundary, bool isAddButtonAllowed) { LowerBoundary = lowerBoundary; HigherBoundary = higherBoundary; IsAddButtonAllowed = isAddButtonAllowed; PolynomialOrder = 0; WindowSize = 0; } #region properties private double higherBoundary; public double HigherBoundary { get { return higherBoundary; } set { SetProperty(ref higherBoundary, value); } } private bool isAddButtonAllowed; public bool IsAddButtonAllowed { get { return isAddButtonAllowed; } set { SetProperty(ref isAddButtonAllowed, value); } } private double lowerBoundary; public double LowerBoundary { get { return lowerBoundary; } set { SetProperty(ref lowerBoundary, value); } } private int polynomialOrder; public int PolynomialOrder { get { return polynomialOrder; } set { SetProperty(ref polynomialOrder, value); } } private int windowSize; public int WindowSize { get { return windowSize; } set { SetProperty(ref windowSize, value); } } #endregion public void updateHigherBoundary(double newValue) { HigherBoundary = newValue; } public void updateLowerBoundary(double newValue) { LowerBoundary = newValue; } } }
INAF.Apps.Uwp.SLabDataManager/Charts/Smoothing/SmoothingBoundariesContainer.cs 0 → 100644 +173 −0 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using INAF.Libraries.Uwp.Settings; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing { public sealed class SmoothingBoundariesContainer : ObservableObject { private readonly SettingsHelper settingsHelper; public SmoothingBoundariesContainer(SettingsHelper settingsHelper) { this.settingsHelper = settingsHelper; init(); } #region properties private ObservableCollection<BoundariesItem> boundaries; public ObservableCollection<BoundariesItem> Boundaries { get { return boundaries; } set { SetProperty(ref boundaries, value); } } private List<double> boundaryValues { get; set; } #endregion #region methods public void add(double value) { if (boundaryValues.Contains(value)) return; boundaryValues.Add(value); } private void addPropertyChangedListenerForBoundaries() { /* remove event-listener for each item, if existing */ Boundaries.All(x => { x.PropertyChanged -= X_PropertyChanged; return true; }); /* add event to each item, in order to save all changes for each item property */ Boundaries.All(x => { x.PropertyChanged += X_PropertyChanged; return true; }); } public void buildBoundaries() { /* re-order items for building well-ordered boundaries */ boundaryValues = boundaryValues.OrderBy(x => x).ToList(); /* build boundaries */ int boundaryValuesNum = boundaryValues.Count; for (int i = 0; i < boundaryValuesNum - 1; i++) { double lowerValue = boundaryValues[i]; if (i > 0) lowerValue = boundaryValues[i] + 1; bool isAddButtonAllowed = true; if (i == boundaryValuesNum - 2) isAddButtonAllowed = false; Boundaries.Add(new BoundariesItem(lowerValue, boundaryValues[i + 1], isAddButtonAllowed)); } addPropertyChangedListenerForBoundaries(); } private void X_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { saveBoundariesItemsSettings(); } private void deleteBoundariesItem(BoundariesItem item) { var previousItem = Boundaries.FirstOrDefault(x => x.LowerBoundary < item.LowerBoundary); if (previousItem == null) { /* if removing item is the 1st one, then extend range of 2nd item... */ var firstRemainingItem = Boundaries.ElementAt(1); firstRemainingItem.LowerBoundary = item.LowerBoundary; } else { /* ...otherwise, update previousItem boundary by extending its range */ previousItem.HigherBoundary = item.HigherBoundary; } /* remove selected item */ Boundaries.Remove(item); /* add/reset event-listener for boundaries */ addPropertyChangedListenerForBoundaries(); } public void init() { boundaryValues = new List<double>(); Boundaries = new ObservableCollection<BoundariesItem>(); } public void insertBoundariesItem(BoundariesItem item) { var nextItem = Boundaries.FirstOrDefault(x => x.LowerBoundary > item.HigherBoundary); if (nextItem == null) return; /* calculate the existing range between the selected item and the next one */ double range = nextItem.HigherBoundary - nextItem.LowerBoundary; /* calculate the range for the new boundariesItem by dividing the currente 'range' by 2 */ int newItemRange = (int)Math.Floor(range / 2d); /* insert a new boundaryItem */ double newHigherBoundary = nextItem.LowerBoundary + newItemRange; bool isAddButtonAllowed = true; if (!Boundaries.Any(x => x.HigherBoundary > newHigherBoundary)) isAddButtonAllowed = false; /* find position of selecteditem */ int index = 0; int boundariesNum = Boundaries.Count; for (int i = 0; i < boundariesNum; i++) { if (nextItem.LowerBoundary == Boundaries[i].HigherBoundary + 1) { index = i; break; } } Boundaries.Insert(index + 1, new BoundariesItem(nextItem.LowerBoundary, newHigherBoundary, isAddButtonAllowed)); /* calculate the new lower-boundary for nextItem and apply it */ double newLowerBoundary = newHigherBoundary + 1; nextItem.updateLowerBoundary(newLowerBoundary); /* add/reset event-listener for boundaries */ addPropertyChangedListenerForBoundaries(); } private void saveBoundariesItemsSettings() { settingsHelper.remove(nameof(Boundaries)); settingsHelper.save<List<BoundariesItem>>(nameof(Boundaries), Boundaries.ToList()); } private void tryReadBoundariesItemsSettings() { if (!settingsHelper.contains(nameof(Boundaries))) return; } #endregion #region commands private RelayCommand<BoundariesItem> commandDeleteBoundariesItem; public RelayCommand<BoundariesItem> CommandDeleteBoundariesItem => commandDeleteBoundariesItem ?? (commandDeleteBoundariesItem = new RelayCommand<BoundariesItem>((item) => deleteBoundariesItem(item))); private RelayCommand<BoundariesItem> commandInsertBoundariesItem; public RelayCommand<BoundariesItem> CommandInsertBoundariesItem => commandInsertBoundariesItem ?? (commandInsertBoundariesItem = new RelayCommand<BoundariesItem>((item) => insertBoundariesItem(item))); #endregion } }