Commit b1792c04 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

fixed xml reading for continuum-removed; added xml reading for smoothed; added...

fixed xml reading for continuum-removed; added xml reading for smoothed; added warning for missing parent file
parent c32ec4cb
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -604,9 +604,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions
                                               segment.SelectedFitMethod.ParameterConstraintValue?.Value);
        }

        public static SmoothingSegmentModel ToSmoothingSegmentModel(this SmoothingSegment segment)
        public static SmoothingSegment ToSmoothingSegment(this SegmentSmoothingSettingsModel segmentSettings)
        {
            return new SmoothingSegmentModel(segment.Id,
            return new SmoothingSegment(segmentSettings.Id,
                                        (double)segmentSettings.XStart,
                                        (double)segmentSettings.XEnd,
                                        segmentSettings.WindowSize,
                                        segmentSettings.PolynomialOrder);
        }

        public static SegmentSmoothingSettingsModel ToSegmentSmoothingSettings(this SmoothingSegment segment)
        {
            return new SegmentSmoothingSettingsModel(segment.Id,
                                                     (double)segment.LowerBoundary,
                                                     (double)segment.HigherBoundary,
                                                     segment.WindowSize,
@@ -617,10 +626,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions
        {
            hexstring = hexstring.Replace("#", string.Empty);
            // from #RRGGBB string
            var a = (byte)System.Convert.ToUInt32(hexstring.Substring(0, 2), 16);
            var r = (byte)System.Convert.ToUInt32(hexstring.Substring(2, 2), 16);
            var g = (byte)System.Convert.ToUInt32(hexstring.Substring(4, 2), 16);
            var b = (byte)System.Convert.ToUInt32(hexstring.Substring(6, 2), 16);
            var a = (byte)Convert.ToUInt32(hexstring.Substring(0, 2), 16);
            var r = (byte)Convert.ToUInt32(hexstring.Substring(2, 2), 16);
            var g = (byte)Convert.ToUInt32(hexstring.Substring(4, 2), 16);
            var b = (byte)Convert.ToUInt32(hexstring.Substring(6, 2), 16);
            //get the color
            Color color = Color.FromArgb(a, r, g, b);
            // create the solidColorbrush
+22 −5
Original line number Diff line number Diff line
@@ -23,10 +23,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart.Fit

            IsShown = false;

            /* this deny the creation of numericbox for parmeterValue when combobox is created.
             * This because the default selected fit method, linear, doesn't need this elements */
            /* this denies the creation of numericbox for parmeterValue when combobox is created 
             * at SegmentsFitUserControl loading (event 'comboboxFitMethods_SelectionChanged').
             * This because the default selected fit method (linear) does NOT require this element */
            IsSelectedFitMethodChangedEventAllowed = false;

            /* execution of command for fitting segment is allowed */
            IsCommandExecutionAllowed = true;

            if (FitMethods?.Count > 0)
                selectedFitMethod = FitMethods[0];
        }
@@ -44,16 +48,24 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart.Fit
                if (SelectedFitMethod != null && SelectedFitMethod.ParameterConstraintValue != null)
                    SelectedFitMethod.ParameterConstraintValue.Value = paramValue;

                /* this overwrite of variable value, allows creation of numericbox, because we're loading values from
                 * processed filex and the selected fit method is different from the linear one, and this element is required */
                /* this overwrite of variable value allows creation of numericbox  when combobox is created 
                 * at SegmentsFitUserControl loading (event 'comboboxFitMethods_SelectionChanged'), because we're loading values from
                 * processed file: if the selected fit method is different from the linear one, this element is required */
                IsSelectedFitMethodChangedEventAllowed = true;

                /* execution of command for fitting segment needs to be disabled in this case, causes recursive call that blocks app */
                IsCommandExecutionAllowed = false;
            }
        }

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

        public bool IsSelectedFitMethodChangedEventAllowed { get; set; }
        /* determine whether execution of command for fitting segment is allowed or not when 'comboboxFitMethods_SelectionChanged' event is fired */
        public bool IsCommandExecutionAllowed { get; private set; }

        /* determine whether creation of numericbox is allowed or not */
        public bool IsSelectedFitMethodChangedEventAllowed { get; private set; }

        public bool IsShown { get; set; }

@@ -93,6 +105,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart.Fit
        }
        #endregion

        public void allowIsSelectedFitMethodChangedEventAllowed()
        {
            IsSelectedFitMethodChangedEventAllowed = true;
        }

        public void raiseSelectedFitMethod()
        {
            OnPropertyChanged(nameof(SelectedFitMethod));
+15 −2
Original line number Diff line number Diff line
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;

namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
{
    public sealed class SmoothingSegment : ObservableObject
    {
        [JsonConstructor]
        public SmoothingSegment(double lowerBoundary,
                                double higherBoundary,
                                bool isAddButtonAllowed)
@@ -16,6 +18,17 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            WindowSize = 0;
        }

        public SmoothingSegment(int id,
                                double lowerBoundary,
                                double higherBoundary,
                                int windowSize,
                                int polynomialOrder) : this(lowerBoundary, higherBoundary, true)
        {
            Id = id;
            WindowSize = windowSize;
            PolynomialOrder = polynomialOrder;
        }

        #region properties
        private double higherBoundary;
        public double HigherBoundary
+14 −7
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing

        public void buildSegments()
        {
            if (!tryReadBoundariesItemsSettings())
            if (!tryReadSmoothingSegments())
            {
                /* re-order items for building well-ordered boundaries */
                boundaryValues = boundaryValues.OrderBy(x => x).ToList();
@@ -95,7 +95,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            Segments.Remove(item);

            /* force saving of boundaries settings */
            saveBoundariesItemsSettings();
            saveSmoothingSegments();

            /* add/reset event-listener for boundaries */
            addPropertyChangedListenerForBoundaries();
@@ -107,7 +107,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            Segments = new ObservableCollection<SmoothingSegment>();
        }

        public void insertBoundariesItem(SmoothingSegment item)
        public void insertSmoothingSegment(SmoothingSegment item)
        {
            var nextItem = Segments.FirstOrDefault(x => x.LowerBoundary > item.HigherBoundary);

@@ -148,13 +148,20 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            addPropertyChangedListenerForBoundaries();
        }

        private void saveBoundariesItemsSettings()
        private void saveSmoothingSegments()
        {
            settingsHelper.remove(nameof(Segments));
            settingsHelper.save<List<SmoothingSegment>>(nameof(Segments), Segments.ToList());
        }

        private bool tryReadBoundariesItemsSettings()
        public void setSmoothingSegments(IEnumerable<SmoothingSegment> smoothingSegments)
        {
            Segments.Clear();
            foreach (var segment in smoothingSegments)
                Segments.Add(segment);
        }

        private bool tryReadSmoothingSegments()
        {
            if (!settingsHelper.contains(nameof(Segments)))
                return false;
@@ -167,7 +174,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing

        private void Segment_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            saveBoundariesItemsSettings();
            saveSmoothingSegments();
        }

        #region commands
@@ -175,7 +182,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
        public RelayCommand<SmoothingSegment> CommandDeleteSegment => commandDeleteSegment ?? (commandDeleteSegment = new RelayCommand<SmoothingSegment>((item) => deleteSegment(item)));

        private RelayCommand<SmoothingSegment> commandInsertSegment;
        public RelayCommand<SmoothingSegment> CommandInsertSegment => commandInsertSegment ?? (commandInsertSegment = new RelayCommand<SmoothingSegment>((item) => insertBoundariesItem(item)));
        public RelayCommand<SmoothingSegment> CommandInsertSegment => commandInsertSegment ?? (commandInsertSegment = new RelayCommand<SmoothingSegment>((item) => insertSmoothingSegment(item)));
        #endregion
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -164,10 +164,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart
            else
                chartSpectrumOfTypeSmoothed = new ChartSpectrumOfTypeSmoothedModel(serviceProvider, spectrumType, spectrum.Info.RawFilename, spectrum.Info.Filepath);

            List<SmoothingSegmentModel> segments = new List<SmoothingSegmentModel>();
            List<SegmentSmoothingSettingsModel> segments = new List<SegmentSmoothingSettingsModel>();
            foreach (var segment in spectrum.SmoothingSettings.Segments.Segment)
            {
                segments.Add(new SmoothingSegmentModel()
                segments.Add(new SegmentSmoothingSettingsModel()
                {
                    XStart = segment.SegmentStart.ToIntInvariant(),
                    XEnd = segment.SegmentEnd.ToIntInvariant(),
Loading