Commit 1d08218e authored by Francesco Carraro's avatar Francesco Carraro
Browse files

working on xml files reading (segments fit)

parent 6c64521e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -285,8 +285,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Converters
            {
                string userControlName = (string)parameter;

                var rightPanelsTabsHelper = Ioc.Default.GetRequiredService<UserControlsHelper>();
                return rightPanelsTabsHelper.RequiredUserControlName.Equals(userControlName);
                var userControlsHelper = Ioc.Default.GetRequiredService<UserControlsHelper>();
                return userControlsHelper.RequiredUserControlName.Equals(userControlName);
            }
            catch (Exception)
            {
+16 −42
Original line number Diff line number Diff line
@@ -2,18 +2,14 @@
using INAF.Apps.Uwp.SLabDataManager.Models.Chart;
using INAF.Apps.Uwp.SLabDataManager.Models.Chart.Fit;
using INAF.Apps.Uwp.SLabDataManager.Models.Containers;
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;
using INAF.Libraries.Uwp.Converters;
using INAF.Libraries.Uwp.Logging;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Telerik.UI.Xaml.Controls.Chart;
using Windows.UI;
using Windows.UI.Xaml;
@@ -57,54 +53,32 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
            }
        }

        public async Task addNewSegmentsAsync(RadCartesianChart chart)
        {
            try
            {
                /* recover points on chart and order them for creating segments */
                var orderedPoints = chart.Annotations
                                            .OfType<CartesianCustomAnnotation>()
                                            .OrderBy(x => x.HorizontalValue);
                //foreach (var point in orderedPoints)
                //    System.Diagnostics.Debug.WriteLine($"orderedPoint - x,y: {point.HorizontalValue},{point.VerticalValue}");

                /* clear existing segments before creating new ones */
                var userControlsViewModelFactory = serviceProvider.GetRequiredService<UserControlsViewModelFactory>();
                var segmentsFitViewModel = userControlsViewModelFactory.createSegmentsFitViewModel();

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

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

                var newSegments = segmentsFitViewModel.SegmentsFitModels.Where(x => !x.IsShown);
                if (newSegments?.Count() > 0)
        public List<PointModel> getOrderedPoints(RadCartesianChart chart)
        {
                    int newSegmentsNum = newSegments.Count();
                    for (int i = 0; i < newSegmentsNum; i++)
            List<PointModel> orderedPoints = null;

            try
            {
                        System.Diagnostics.Debug.WriteLine($"fit segment - i: {i}, (x1,x2): {newSegments.ElementAt(i).P1.X}-{newSegments.ElementAt(i).P2.X}");
                        await viewModel.fitSelectedSegmentAsync(newSegments.ElementAt(i));
                    }
                }
                /* recover points on chart and order them for creating segments */
                orderedPoints = chart.Annotations
                                            .OfType<CartesianCustomAnnotation>()
                                            .OrderBy(x => x.HorizontalValue)
                                            .Select(x => x.ToPointModel())
                                            .ToList();
            }
            catch (Exception ex)
            {
                logger.Write<ChartAnnotationsHelper>($"{nameof(addNewSegmentsAsync)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error);
            }
                logger.Write<ChartAnnotationsHelper>($"{nameof(getOrderedPoints)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error);
            }

        public void addPointOnChart(PointModel newPoint,
                                    RadCartesianChart chart,
                                    DataTemplate tappedPointTemplate)
        {
            chart.Annotations.Add(getCustomAnnotation(newPoint.X, newPoint.Y, tappedPointTemplate));
            return orderedPoints;
        }

        public int getPointsNum(RadCartesianChart chart)
+6 −0
Original line number Diff line number Diff line
@@ -134,6 +134,12 @@
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
      <Version>6.2.14</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.UI">
      <Version>7.1.2</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
      <Version>7.1.2</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
      <Version>7.1.2</Version>
    </PackageReference>
+15 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ using INAF.Libraries.NetStandard.Extensions;
using INAF.Libraries.NetStandard.Math.Models;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart.Fit
{
@@ -27,6 +28,20 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart.Fit
                selectedFitMethod = FitMethods[0];
        }

        public SegmentFitModel(PointModel p1,
                               PointModel p2,
                               string fitMethodName,
                               double paramValue,
                               List<FitMethodModel> fitMethods) : this(p1, p2, fitMethods)
        {
            if (FitMethods?.Count > 0)
            {
                SelectedFitMethod = FitMethods.FirstOrDefault(x => x.MethodName.Equals(fitMethodName));
                if (SelectedFitMethod != null)
                    SelectedFitMethod.ParameterConstraintValue.Value = paramValue;
            }
        }

        #region proeprties
        public int Id { get; set; }

+10 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Telerik.UI.Xaml.Controls.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
@@ -628,10 +629,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        {
            var spectrumOfTypeAligned = processedSpectraContainer.get<ChartSpectrumOfTypeAlignedModel>();
            if (spectrumOfTypeAligned != null)
            {
                initAlignmentViewModel();

                WorkingItems.SpectraContainer.SelectedRefBand.setBoundaries(spectrumOfTypeAligned.AlignmentSettings.AlignmentSegmentBoundaries.Min,
                                                                            spectrumOfTypeAligned.AlignmentSettings.AlignmentSegmentBoundaries.Max,
                                                                            isSaveEnabled: false); // avoid saving alignment segment for next spectra alignments
            }
        }

        private void manageSpectrumOfTypeContinuumRemoved(ProcessedSpectraContainer processedSpectraContainer)
        {
@@ -641,11 +646,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                /* init segments-fit viewmodel for allowing management of points and segments used for fitting spectrum and removing continuum */
                initSegmentsFitViewModel();

                /* add segments used for fitting continuum and their boundary points */
                foreach (var segment in spectrumOfTypeContinuumRemoved.ContinuumRemovalSettings.Segments)
                {
                    SegmentsFitViewModel.addOrInsertPoint(segment.XStart, spectrumOfTypeContinuumRemoved.getY(segment.XStart));
                }
                /* set fit settings */
                SegmentsFitViewModel.setFitSettings(spectrumOfTypeContinuumRemoved.ContinuumRemovalSettings.Segments.ToList());

                /* raise event for adding points and segments on chart */
                SegmentsFitViewModel.raiseAreFitSettingsReady();
            }
        }
        #endregion
Loading