Commit 9d9b75a5 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

refactored viewmodels for usercontrols; added check is already saved on cloud...

refactored viewmodels for usercontrols; added check is already saved on cloud for derived spectra types
parent 8afd8479
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ namespace INAF.Apps.Uwp.SLabDataManager
                .AddSingleton<RemoteOperationsRepository>()
                .AddSingleton<SecondaryWindowHelper>()
                .AddSingleton<SegmentFitModelsFactory>()
                .AddSingleton<SegmentsFitModelHelper>()
                .AddSingleton<SegmentsFitViewModel>()
                .AddSingleton<SelectedRefBand>()
                .AddSingleton<SettingsHelper>()
                .AddSingleton<SmoothingBoundariesContainer>()
+2 −1
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@
		<operation type="SaveAsCopySpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveAsCopySpectrumOfTypeContinuumRemoved</operation>
		<operation type="SaveSpectrumOfTypeRaw">AppSpectraFilesActions/SaveSpectrumOfTypeRaw</operation>
		<operation type="SaveSpectrumSampleData">AppSpectraFilesActions/SaveSpectrumSampleData</operation>
		<operation type="IsSavedOnCloud">AppSpectraFilesActions/IsSpectrumSavedOnCloud</operation>
		<operation type="IsAnySpectrumTypeSavedOnCloud">AppSpectraFilesActions/IsAnySpectrumTypeSavedOnCloud</operation>
		<operation type="IsSpectrumTypeSavedOnCloud">AppSpectraFilesActions/IsSpectrumTypeSavedOnCloud</operation>
		<operation type="GetSampleDataValues">AppSpectraFilesActions/GetSampleDataValues</operation>
		<operation type="DeleteSpectrum">AppSpectraFilesActions/DeleteSpectrum</operation>
	</operationUrls>
+1 −5
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers
                switchXAxisMeasureUnit(spectrumChartOptions.SelectedWavelengthMeasureUnit);

                await Task.Delay(TimeSpan.FromMilliseconds(300));
                AlignmentViewModel.switchToMeasureUnit(spectrumChartOptions.SelectedWavelengthMeasureUnit);
                //AlignmentViewModel.switchToMeasureUnit(spectrumChartOptions.SelectedWavelengthMeasureUnit);
                SelectedRefBand.switchToMeasureUnit(spectrumChartOptions.SelectedWavelengthMeasureUnit);

                IsWorkInProgress = false;
@@ -42,8 +42,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers

        public SelectedRefBand SelectedRefBand { get; protected set; }

        public AlignmentViewModel AlignmentViewModel { get; protected set; }

        public SpectrumType SelectedSpectrumType { get; protected set; }

        #region spectra
@@ -170,8 +168,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers
        {
            base.init();

            AlignmentViewModel = serviceProvider.GetRequiredService<AlignmentViewModel>();

            SelectedRefBand = serviceProvider.GetRequiredService<SelectedRefBand>();

            Spectra = new ObservableCollection<SpectrumModel>();
+7 −2
Original line number Diff line number Diff line
@@ -56,9 +56,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations
            return await getAsync(RemoteOperationType.IsTokenValid);
        }

        public async Task<GenericIdResponseModel> isSavedOnCloudAsync(IsFileSavedOnCloudRequestModel model)
        public async Task<GenericIdResponseModel> isAnySpectrumTypeSavedOnCloudAsync(IsAnySpectrumTypeSavedOnCloudRequestModel model)
        {
            return await postAsync<GenericIdResponseModel>(model, RemoteOperationType.IsSavedOnCloud);
            return await postAsync<GenericIdResponseModel>(model, RemoteOperationType.IsAnySpectrumTypeSavedOnCloud);
        }

        public async Task<GenericIdResponseModel> isSpectrumTypeSavedOnCloudAsync(IsSpectrumTypeSavedOnCloudRequestModel model)
        {
            return await postAsync<GenericIdResponseModel>(model, RemoteOperationType.IsSpectrumTypeSavedOnCloud);
        }

        public async Task<GenericIdResponseModel> saveSpectrumOfTypeAlignedAsync(SaveSpectrumOfTypeAlignedRequestModel saveSpectrumRequest)
+35 −15
Original line number Diff line number Diff line
using INAF.Apps.Uwp.SLabDataManager.Extensions;
using INAF.Apps.Uwp.SLabDataManager.Charts.Containers;
using INAF.Apps.Uwp.SLabDataManager.Extensions;
using INAF.Apps.Uwp.SLabDataManager.Models;
using INAF.Apps.Uwp.SLabDataManager.Models.Fit;
using INAF.Apps.Uwp.SLabDataManager.ViewModels;
using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels;
using INAF.Libraries.NetStandard.Math.Fit.Linear.Models;
using INAF.Libraries.NetStandard.Math.Models;
using INAF.Libraries.NetStandard.ScienceModels.Spectra;
@@ -25,15 +27,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
    public sealed class ChartAnnotationsHelper
    {
        private readonly IServiceProvider serviceProvider;
        private readonly WorkingItemsModel workingItems;
        private readonly SpectraContainer spectraContainer;
        private readonly AlignmentViewModel alignmentViewModel;
        private readonly Logger logger;

        public ChartAnnotationsHelper(IServiceProvider serviceProvider,
                                      WorkingItemsModel workingItems,
                                      SpectraContainer spectraContainer,
                                      AlignmentViewModel alignmentViewModel,
                                      Logger logger)
        {
            this.serviceProvider = serviceProvider;
            this.workingItems = workingItems;
            this.spectraContainer = spectraContainer;
            this.alignmentViewModel = alignmentViewModel;
            this.logger = logger;
        }

@@ -43,10 +48,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
        {
            try
            {
                var segmentsFitModelContainer = serviceProvider.GetRequiredService<SegmentsFitModelHelper>();
                var segmentsFitViewModel = serviceProvider.GetRequiredService<SegmentsFitViewModel>();

                /*  find closest points on spectrum to mouse position */
                (PointModel lowBoundary, PointModel highBoundary) boundaries = getSegmentBoundaries(workingItems.SpectraContainer.getAlignedSpectrum(),
                (PointModel lowBoundary, PointModel highBoundary) boundaries = getSegmentBoundaries(spectraContainer.getAlignedSpectrum(),
                                                                                                    (double)point.Item1,
                                                                                                    (double)point.Item2);

@@ -65,7 +70,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
                    /* if already existant, then remove point from chart */
                    chart.Annotations.Remove(existantItem);
                    /* also remove segments having current point as boundary point */
                    segmentsFitModelContainer.removeOldSegmentsAndAddNewOne(((CartesianCustomAnnotation)existantItem).ToPointModel());
                    segmentsFitViewModel.removeOldSegmentsAndAddNewOne(((CartesianCustomAnnotation)existantItem).ToPointModel());
                }
                else
                {
@@ -81,8 +86,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
                    var pointModel = new PointModel((double)point.Item1, yOnSpectrum);

                    /* if new point belongs to an existant segment, then it is removed and 2 new segments are created */
                    if (segmentsFitModelContainer.isPointContainedInExistingSegment(pointModel))
                        segmentsFitModelContainer.removeOldSegmentAndAddNewOnes(pointModel);
                    if (segmentsFitViewModel.isPointContainedInExistingSegment(pointModel))
                        segmentsFitViewModel.removeOldSegmentAndAddNewOnes(pointModel);

                    /* ...otherwise add a new point */
                    chart.Annotations.Add(getCustomAnnotation((double)point.Item1, yOnSpectrum, tappedPointTemplate));
@@ -119,20 +124,20 @@ 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 segmentsFitModelContainer = serviceProvider.GetRequiredService<SegmentsFitModelHelper>();
            var segmentsFitViewModel = serviceProvider.GetRequiredService<SegmentsFitViewModel>();

            /* create segments starting from ordered points */
            var pointsNum = chart.Annotations.Count(x => x is CartesianCustomAnnotation);
            for (int i = 0; i < pointsNum - 1; i++)
            {
                /* try adding new segment, only the new segment is returned, if segment is already existant, then method returns null */
                segmentsFitModelContainer.tryAddOrInsertSegment(orderedPoints.ElementAt(i).ToPointModel(), orderedPoints.ElementAt(i + 1).ToPointModel());
                segmentsFitViewModel.tryAddOrInsertSegment(orderedPoints.ElementAt(i).ToPointModel(), orderedPoints.ElementAt(i + 1).ToPointModel());
            }

            /* fit new segment(s) */
            var viewModel = serviceProvider.GetRequiredService<ChartViewModel>();

            var newSegments = segmentsFitModelContainer.SegmentsFitModels.Where(x => !x.IsShown);
            var newSegments = segmentsFitViewModel.SegmentsFitModels.Where(x => !x.IsShown);
            if (newSegments?.Count() > 0)
            {
                int newSegmentsNum = newSegments.Count();
@@ -159,8 +164,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
        public void createCartesianGridLineAnnotations(RadCartesianChart chart,
                                                       bool areSeparatorsVisible)
        {
            foreach (var separator in workingItems.SpectraContainer.AlignmentViewModel.WavelengthSeparators)
            foreach (var separator in alignmentViewModel.WavelengthSeparators)
            {
                chart.Annotations.Add(getAnnotation(chart, separator, areSeparatorsVisible));
            }

            chart.UpdateLayout();
        }
@@ -178,9 +185,22 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
            };
            annotation.SetBinding(CartesianGridLineAnnotation.ValueProperty, new Binding() { Path = new PropertyPath("CurrentValue"), Source = separator, Mode = BindingMode.OneWay });
            annotation.SetBinding(CartesianGridLineAnnotation.LabelProperty, new Binding() { Path = new PropertyPath("CurrentValue"), Source = separator, Mode = BindingMode.OneWay });
            annotation.SetBinding(CartesianGridLineAnnotation.VisibilityProperty, new Binding() { Path = new PropertyPath("AreSeparatorsVisible"), Source = workingItems.SpectraContainer.AlignmentViewModel, Converter = new BoolToVisibilityConverter(), Mode = BindingMode.OneWay });
            annotation.SetBinding(CartesianGridLineAnnotation.VisibilityProperty, new Binding() { Path = new PropertyPath("AreSeparatorsVisible"), Source = alignmentViewModel, Converter = new BoolToVisibilityConverter(), Mode = BindingMode.OneWay });
            return annotation;
        }

        public void removeCartesianGridLineAnnotations(RadCartesianChart chart)
        {
            var annotations = chart.Annotations.OfType<CartesianGridLineAnnotation>();
            if (annotations?.Count() > 0)
            {
                int annotationsNum = annotations.Count();
                for (int i = annotationsNum - 1; i >= 0; i--)
                {
                    chart.Annotations.Remove(annotations.ElementAt(i));
                }
            }
        }
        #endregion

        #region highlight/lowlight
@@ -223,7 +243,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
        public IEnumerable<ElementModel> getSegmentSpectrumElements(SegmentFitModel segmentFit,
                                                                    SpectrumType spectrumType)
        {
            var spectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(spectrumType);
            var spectrum = spectraContainer.tryGetSpectrumOfType(spectrumType);

            return spectrum.Elements.Where(x => x.X >= segmentFit.P1.X &&
                                                x.X <= segmentFit.P2.X);
Loading