Loading INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +4 −4 Original line number Diff line number Diff line Loading @@ -154,19 +154,19 @@ namespace INAF.Apps.Uwp.SLabDataManager /* transient */ .AddTransient<AnimationsHelper>() .AddTransient<AuthenticationManager>() .AddTransient<XmlAssetConfigReader>() .AddTransient<XmlAssetFitFunctionsReader>() .AddTransient<LabSpectrumFileReader>() .AddTransient<LinearFitHelper>() .AddTransient<LinearProcessingHelper>() .AddTransient<SplineProcessingHelper>() .AddTransient<RemoteOperationsManager>() .AddTransient<RemoteOperationsXmlReader>() .AddTransient<SavitzkyGolayHelper>() .AddTransient<XmlAssetSmoothingDefaultBoundariesReader>() .AddTransient<SpectraFactory>() .AddTransient<SplineFitHelper>() .AddTransient<SplineProcessingHelper>() .AddTransient<ZoomHelper>() .AddTransient<XmlAssetConfigReader>() .AddTransient<XmlAssetFitFunctionsReader>() .AddTransient<XmlAssetSmoothingDefaultBoundariesReader>() .AddTransient<XmlHelper>() .AddTransient<XmlSpectrumFileReader>() /* usercontrols viewmodels */ Loading INAF.Apps.Uwp.SLabDataManager/Constants/Constants.cs +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ public static readonly string RED = "FFBB1717"; public static readonly string YELLOW = "FFD1AB43"; public static readonly double POINT_RADIUS = 24; // double of point-radius in tappedPointTemplate public static readonly string X_AXIS_MAJOR_STEP = "xaxismajorstep"; public static readonly string WAVELENGTH_MEASURE_UNITS = "wavelengthmeasureunits"; public static readonly string MAJOR_LINES_VISIBILITY = "majorlinesvisibility"; Loading INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ChartAnnotationsHelper.cs +41 −84 Original line number Diff line number Diff line Loading @@ -57,77 +57,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart } } public async Task addOrRemoveTappedPointForContinuumAsync(RadCartesianChart chart, PointModel point, DataTemplate tappedPointTemplate) { try { var segmentsFitViewModel = serviceProvider.GetRequiredService<SegmentsFitViewModel>(); /* find closest points on spectrum to mouse position */ (PointModel lowBoundary, PointModel highBoundary) boundaries = getSegmentBoundaries(spectraContainer.getAlignedSpectrum(), point.X); var lowerBoundaryPoint = boundaries.lowBoundary; var higherBoundaryPoint = boundaries.highBoundary; if (lowerBoundaryPoint == null || higherBoundaryPoint == null) return; /* if a point in selected position already exists, then remove it... */ var existantItem = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= (point.X - 12d)) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (point.X + 12d))); if (existantItem != null) { /* if already existant, then remove point from chart */ chart.Annotations.Remove(existantItem); /* also remove segments having current point as boundary point */ segmentsFitViewModel.removeOldSegmentsAndAddNewOne(((CartesianCustomAnnotation)existantItem).ToPointModel()); } else { /* calculate y on spectrum */ double yOnSpectrum = (double)point.Y; if (lowerBoundaryPoint.X != higherBoundaryPoint.X) { var line = new StraightLineModel(lowerBoundaryPoint, higherBoundaryPoint); yOnSpectrum = line.calculateY(point.X); } else yOnSpectrum = lowerBoundaryPoint.Y; /* add the new point on chart */ PointModel pointModel = addPoint(point, yOnSpectrum, chart, tappedPointTemplate, segmentsFitViewModel); System.Diagnostics.Debug.WriteLine($"new point: {point.X},{yOnSpectrum}"); /* save point */ segmentsFitViewModel.addPoint(pointModel); } /* if only a point is added, then avoid trying create segments */ var pointsNum = chart.Annotations.Count(x => x is CartesianCustomAnnotation); if (pointsNum > 1) { /* try to create lines connecting selected points */ await addNewSegmentsAsync(chart); /* update UI */ SeriesHelper.UpdateUI(chart); } } catch (Exception ex) { logger.Write<ChartAnnotationsHelper>($"{nameof(addOrRemoveTappedPointForContinuumAsync)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } } private async Task addNewSegmentsAsync(RadCartesianChart chart) public async Task addNewSegmentsAsync(RadCartesianChart chart) { try { Loading @@ -139,7 +69,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart // System.Diagnostics.Debug.WriteLine($"orderedPoint - x,y: {point.HorizontalValue},{point.VerticalValue}"); /* clear existing segments before creating new ones */ var segmentsFitViewModel = serviceProvider.GetRequiredService<SegmentsFitViewModel>(); var userControlsViewModelFactory = serviceProvider.GetRequiredService<UserControlsViewModelFactory>(); var segmentsFitViewModel = userControlsViewModelFactory.createSegmentsFitViewModel(); /* create segments starting from ordered points */ var pointsNum = chart.Annotations.Count(x => x is CartesianCustomAnnotation); Loading Loading @@ -169,23 +100,49 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart } } private PointModel addPoint(PointModel point, double yOnSpectrum, public void addPointOnChart(PointModel newPoint, RadCartesianChart chart, DataTemplate tappedPointTemplate, SegmentsFitViewModel segmentsFitViewModel) DataTemplate tappedPointTemplate) { chart.Annotations.Add(getCustomAnnotation(newPoint.X, newPoint.Y, tappedPointTemplate)); } public int getPointsNum(RadCartesianChart chart) { return chart.Annotations.Count(x => x is CartesianCustomAnnotation); } public (bool isAnyExistingPoint, PointModel existingPoint) isAlreadyExistingPointOnChart(RadCartesianChart chart, PointModel point) { /* create new point to be used for new segment(s) */ var pointModel = new PointModel(point.X, yOnSpectrum); (bool isAnyExistingPoint, PointModel existingPoint) result = (false, null); /* if new point belongs to an existant segment, then it is removed and 2 new segments are created */ if (segmentsFitViewModel.isPointContainedInExistingSegment(pointModel)) segmentsFitViewModel.removeOldSegmentAndAddNewOnes(pointModel); /* if a point in selected position already exists, then remove it... * check within x-interval of +/- 12 derives from point template, which define a point with a radius of 12 pixel */ var existingPoint = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= (point.X - Constants.Constants.POINT_RADIUS)) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (point.X + Constants.Constants.POINT_RADIUS))); /* ...otherwise add a new point */ chart.Annotations.Add(getCustomAnnotation(point.X, yOnSpectrum, tappedPointTemplate)); if (existingPoint != null) { result.isAnyExistingPoint = true; result.existingPoint = ((CartesianCustomAnnotation)existingPoint).ToPointModel(); } return result; } public void removeExistingPointOnChart(RadCartesianChart chart, PointModel point) { /* if a point in selected position already exists, then remove it... * check within x-interval of +/- 12 derives from point template, which define a point with a radius of 12 pixel */ var existingItem = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= (point.X - Constants.Constants.POINT_RADIUS)) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (point.X + Constants.Constants.POINT_RADIUS))); return pointModel; if (existingItem != null) chart.Annotations.Remove(existingItem); } public void removePointsForContinuum(RadCartesianChart chart) Loading INAF.Apps.Uwp.SLabDataManager/Models/Chart/SelectedRefBand.cs +5 −5 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ using INAF.Libraries.NetStandard.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.Uwp.Settings; using Microsoft.Extensions.DependencyInjection; using System; using static INAF.Libraries.NetStandard.ScienceModels.Enums.Enums; namespace INAF.Apps.Uwp.SLabDataManager.Models.Charts Loading @@ -10,15 +12,13 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Charts public sealed class SelectedRefBand : BaseValueModel { private readonly SettingsHelper settingsHelper; private readonly SpectrumChartOptionsModel spectrumChartOptions; public SelectedRefBand(SettingsHelper settingsHelper, SpectrumChartOptionsModel spectrumChartOptions) public SelectedRefBand(IServiceProvider serviceProvider, SettingsHelper settingsHelper) { this.settingsHelper = settingsHelper; this.spectrumChartOptions = spectrumChartOptions; MeasureUnit = spectrumChartOptions.SelectedWavelengthMeasureUnit; MeasureUnit = serviceProvider.GetRequiredService<SpectrumChartOptionsModel>().SelectedWavelengthMeasureUnit; initBoundaries(); Loading INAF.Apps.Uwp.SLabDataManager/Models/Containers/ProcessedSpectraContainer.cs +1 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Containers IsAnySpectrum = true; } public bool any() public bool isAny() { return ChartSpectraModels.Any(); } Loading Loading
INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +4 −4 Original line number Diff line number Diff line Loading @@ -154,19 +154,19 @@ namespace INAF.Apps.Uwp.SLabDataManager /* transient */ .AddTransient<AnimationsHelper>() .AddTransient<AuthenticationManager>() .AddTransient<XmlAssetConfigReader>() .AddTransient<XmlAssetFitFunctionsReader>() .AddTransient<LabSpectrumFileReader>() .AddTransient<LinearFitHelper>() .AddTransient<LinearProcessingHelper>() .AddTransient<SplineProcessingHelper>() .AddTransient<RemoteOperationsManager>() .AddTransient<RemoteOperationsXmlReader>() .AddTransient<SavitzkyGolayHelper>() .AddTransient<XmlAssetSmoothingDefaultBoundariesReader>() .AddTransient<SpectraFactory>() .AddTransient<SplineFitHelper>() .AddTransient<SplineProcessingHelper>() .AddTransient<ZoomHelper>() .AddTransient<XmlAssetConfigReader>() .AddTransient<XmlAssetFitFunctionsReader>() .AddTransient<XmlAssetSmoothingDefaultBoundariesReader>() .AddTransient<XmlHelper>() .AddTransient<XmlSpectrumFileReader>() /* usercontrols viewmodels */ Loading
INAF.Apps.Uwp.SLabDataManager/Constants/Constants.cs +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ public static readonly string RED = "FFBB1717"; public static readonly string YELLOW = "FFD1AB43"; public static readonly double POINT_RADIUS = 24; // double of point-radius in tappedPointTemplate public static readonly string X_AXIS_MAJOR_STEP = "xaxismajorstep"; public static readonly string WAVELENGTH_MEASURE_UNITS = "wavelengthmeasureunits"; public static readonly string MAJOR_LINES_VISIBILITY = "majorlinesvisibility"; Loading
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ChartAnnotationsHelper.cs +41 −84 Original line number Diff line number Diff line Loading @@ -57,77 +57,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart } } public async Task addOrRemoveTappedPointForContinuumAsync(RadCartesianChart chart, PointModel point, DataTemplate tappedPointTemplate) { try { var segmentsFitViewModel = serviceProvider.GetRequiredService<SegmentsFitViewModel>(); /* find closest points on spectrum to mouse position */ (PointModel lowBoundary, PointModel highBoundary) boundaries = getSegmentBoundaries(spectraContainer.getAlignedSpectrum(), point.X); var lowerBoundaryPoint = boundaries.lowBoundary; var higherBoundaryPoint = boundaries.highBoundary; if (lowerBoundaryPoint == null || higherBoundaryPoint == null) return; /* if a point in selected position already exists, then remove it... */ var existantItem = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= (point.X - 12d)) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (point.X + 12d))); if (existantItem != null) { /* if already existant, then remove point from chart */ chart.Annotations.Remove(existantItem); /* also remove segments having current point as boundary point */ segmentsFitViewModel.removeOldSegmentsAndAddNewOne(((CartesianCustomAnnotation)existantItem).ToPointModel()); } else { /* calculate y on spectrum */ double yOnSpectrum = (double)point.Y; if (lowerBoundaryPoint.X != higherBoundaryPoint.X) { var line = new StraightLineModel(lowerBoundaryPoint, higherBoundaryPoint); yOnSpectrum = line.calculateY(point.X); } else yOnSpectrum = lowerBoundaryPoint.Y; /* add the new point on chart */ PointModel pointModel = addPoint(point, yOnSpectrum, chart, tappedPointTemplate, segmentsFitViewModel); System.Diagnostics.Debug.WriteLine($"new point: {point.X},{yOnSpectrum}"); /* save point */ segmentsFitViewModel.addPoint(pointModel); } /* if only a point is added, then avoid trying create segments */ var pointsNum = chart.Annotations.Count(x => x is CartesianCustomAnnotation); if (pointsNum > 1) { /* try to create lines connecting selected points */ await addNewSegmentsAsync(chart); /* update UI */ SeriesHelper.UpdateUI(chart); } } catch (Exception ex) { logger.Write<ChartAnnotationsHelper>($"{nameof(addOrRemoveTappedPointForContinuumAsync)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } } private async Task addNewSegmentsAsync(RadCartesianChart chart) public async Task addNewSegmentsAsync(RadCartesianChart chart) { try { Loading @@ -139,7 +69,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart // System.Diagnostics.Debug.WriteLine($"orderedPoint - x,y: {point.HorizontalValue},{point.VerticalValue}"); /* clear existing segments before creating new ones */ var segmentsFitViewModel = serviceProvider.GetRequiredService<SegmentsFitViewModel>(); var userControlsViewModelFactory = serviceProvider.GetRequiredService<UserControlsViewModelFactory>(); var segmentsFitViewModel = userControlsViewModelFactory.createSegmentsFitViewModel(); /* create segments starting from ordered points */ var pointsNum = chart.Annotations.Count(x => x is CartesianCustomAnnotation); Loading Loading @@ -169,23 +100,49 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart } } private PointModel addPoint(PointModel point, double yOnSpectrum, public void addPointOnChart(PointModel newPoint, RadCartesianChart chart, DataTemplate tappedPointTemplate, SegmentsFitViewModel segmentsFitViewModel) DataTemplate tappedPointTemplate) { chart.Annotations.Add(getCustomAnnotation(newPoint.X, newPoint.Y, tappedPointTemplate)); } public int getPointsNum(RadCartesianChart chart) { return chart.Annotations.Count(x => x is CartesianCustomAnnotation); } public (bool isAnyExistingPoint, PointModel existingPoint) isAlreadyExistingPointOnChart(RadCartesianChart chart, PointModel point) { /* create new point to be used for new segment(s) */ var pointModel = new PointModel(point.X, yOnSpectrum); (bool isAnyExistingPoint, PointModel existingPoint) result = (false, null); /* if new point belongs to an existant segment, then it is removed and 2 new segments are created */ if (segmentsFitViewModel.isPointContainedInExistingSegment(pointModel)) segmentsFitViewModel.removeOldSegmentAndAddNewOnes(pointModel); /* if a point in selected position already exists, then remove it... * check within x-interval of +/- 12 derives from point template, which define a point with a radius of 12 pixel */ var existingPoint = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= (point.X - Constants.Constants.POINT_RADIUS)) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (point.X + Constants.Constants.POINT_RADIUS))); /* ...otherwise add a new point */ chart.Annotations.Add(getCustomAnnotation(point.X, yOnSpectrum, tappedPointTemplate)); if (existingPoint != null) { result.isAnyExistingPoint = true; result.existingPoint = ((CartesianCustomAnnotation)existingPoint).ToPointModel(); } return result; } public void removeExistingPointOnChart(RadCartesianChart chart, PointModel point) { /* if a point in selected position already exists, then remove it... * check within x-interval of +/- 12 derives from point template, which define a point with a radius of 12 pixel */ var existingItem = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= (point.X - Constants.Constants.POINT_RADIUS)) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (point.X + Constants.Constants.POINT_RADIUS))); return pointModel; if (existingItem != null) chart.Annotations.Remove(existingItem); } public void removePointsForContinuum(RadCartesianChart chart) Loading
INAF.Apps.Uwp.SLabDataManager/Models/Chart/SelectedRefBand.cs +5 −5 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ using INAF.Libraries.NetStandard.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.Uwp.Settings; using Microsoft.Extensions.DependencyInjection; using System; using static INAF.Libraries.NetStandard.ScienceModels.Enums.Enums; namespace INAF.Apps.Uwp.SLabDataManager.Models.Charts Loading @@ -10,15 +12,13 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Charts public sealed class SelectedRefBand : BaseValueModel { private readonly SettingsHelper settingsHelper; private readonly SpectrumChartOptionsModel spectrumChartOptions; public SelectedRefBand(SettingsHelper settingsHelper, SpectrumChartOptionsModel spectrumChartOptions) public SelectedRefBand(IServiceProvider serviceProvider, SettingsHelper settingsHelper) { this.settingsHelper = settingsHelper; this.spectrumChartOptions = spectrumChartOptions; MeasureUnit = spectrumChartOptions.SelectedWavelengthMeasureUnit; MeasureUnit = serviceProvider.GetRequiredService<SpectrumChartOptionsModel>().SelectedWavelengthMeasureUnit; initBoundaries(); Loading
INAF.Apps.Uwp.SLabDataManager/Models/Containers/ProcessedSpectraContainer.cs +1 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Containers IsAnySpectrum = true; } public bool any() public bool isAny() { return ChartSpectraModels.Any(); } Loading