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

minor fixes for SegmentsFitUserControl

parent b6a818b2
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ namespace INAF.Apps.Uwp.SLabDataManager

        public static Dictionary<string, object> AppDictionary;
        public static Dictionary<UIContext, AppWindow> AppWindows;
        public static bool IsFirstRawFileReading;

        private ActivationService ActivationService
        {
@@ -111,8 +110,6 @@ namespace INAF.Apps.Uwp.SLabDataManager

        private void initServices()
        {
            IsFirstRawFileReading = true;

            /* create app dictionary shared across all app */
            AppDictionary = new Dictionary<string, object>();

+0 −32
Original line number Diff line number Diff line
@@ -78,8 +78,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            if (!App.AppDictionary.TryAdd(Constants.Constants.LAST_PAGE, nameof(ChartPage)))
                App.AppDictionary[Constants.Constants.LAST_PAGE] = nameof(ChartPage);

            saveIsSegmentsFitUserControlAutoOpenEnabled();

            clear();

            await base.OnNavigatingFrom(e);
@@ -185,20 +183,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            set { SetProperty(ref isHideAlignmentFlyoutRequired, value); }
        }

        private bool isSegmentsFitsUserControlAutoOpenEnabled;
        public bool IsSegmentsFitsUserControlAutoOpenEnabled
        {
            get { return isSegmentsFitsUserControlAutoOpenEnabled; }
            set { SetProperty(ref isSegmentsFitsUserControlAutoOpenEnabled, value); }
        }

        private bool isSegmentsFitsUserControlAutoOpenRequired;
        public bool IsSegmentsFitsUserControlAutoOpenRequired
        {
            get { return isSegmentsFitsUserControlAutoOpenRequired; }
            set { SetProperty(ref isSegmentsFitsUserControlAutoOpenRequired, value); }
        }

        private SegmentFitModel selectedSegment;
        public SegmentFitModel SelectedSegment
        {
@@ -280,12 +264,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            IsDisableFitFocusRequired = true;
            isDisableFitFocusRequired = false;
        }

        private void raiseIsSegmentsFitsUserControlAutoOpenRequired()
        {
            IsSegmentsFitsUserControlAutoOpenRequired = true;
            isSegmentsFitsUserControlAutoOpenRequired = false; // DO NOT UNCOMMENT THIS!
        }
        #endregion

        #region methods
@@ -321,16 +299,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            IsDisableFitFocusRequired = false;
            IsFocusRequired = false;

            ///* segments fit */
            //if (!tryReadIsSegmentsFitsUserControlAvailable())
            //    IsSegmentsFitsUserControlAvailable = false;

            if (!tryReadIsSegmentsFitUserControlAutoOpenEnabled())
                IsSegmentsFitsUserControlAutoOpenEnabled = true;

            if (!tryReadIsSegmentsFitsUserControlAutoOpenRequired())
                IsSegmentsFitsUserControlAutoOpenRequired = false;

            /* dialogs */
            IsOperationDialogRequired = false;
            DialogMessage = string.Empty;
+1 −41
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            UserControlsHelper.RequiredUserControlName = nameof(SegmentsFitUserControl).FirstCharToLowerCase(); // this is used to select the right tab in ChartPage->tabViewPanels, if shown

            if (isRaiseEventAllowed)
                raiseIsSegmentsFitsUserControlAutoOpenRequired();
                SegmentsFitViewModel.raiseIsSegmentsFitsUserControlAutoOpenRequired();

            /* fit current segment with selected fit method */
            if (segmentFitModel.SelectedFitMethod == null)
@@ -366,46 +366,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        }
        #endregion

        #region segments-fit panel
        private void saveIsSegmentsFitUserControlAutoOpenEnabled()
        {
            settingsHelper.save(nameof(IsSegmentsFitsUserControlAutoOpenEnabled), IsSegmentsFitsUserControlAutoOpenEnabled.ToString());
        }

        private void saveIsSegmentsFitsUserControlAutoOpenRequired()
        {
            settingsHelper.save(nameof(IsSegmentsFitsUserControlAutoOpenRequired), IsSegmentsFitsUserControlAutoOpenRequired.ToString());
        }

        public bool tryReadIsSegmentsFitUserControlAutoOpenEnabled()
        {
            bool isFound = false;

            string value = settingsHelper.get(nameof(IsSegmentsFitsUserControlAutoOpenEnabled));
            if (!string.IsNullOrEmpty(value))
            {
                IsSegmentsFitsUserControlAutoOpenEnabled = value.ToBool();
                isFound = true;
            }

            return isFound;
        }

        public bool tryReadIsSegmentsFitsUserControlAutoOpenRequired()
        {
            bool isFound = false;

            string value = settingsHelper.get(nameof(IsSegmentsFitsUserControlAutoOpenRequired));
            if (!string.IsNullOrEmpty(value))
            {
                IsSegmentsFitsUserControlAutoOpenRequired = value.ToBool();
                isFound = true;
            }

            return isFound;
        }
        #endregion

        #region commands
        private RelayCommand commandAskClearFitSegments;
        public RelayCommand CommandAskClearFitSegments => commandAskClearFitSegments ?? (commandAskClearFitSegments = new RelayCommand(() => askClearFitSegments()));
+20 −13
Original line number Diff line number Diff line
@@ -203,10 +203,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        }

        #region recent files
        private async Task addToRecentFilesAsync(string filepath, string token, string key)
        private async Task addToRecentFilesAsync(string filepath, string token, string suffix)
        {
            await Task.Run(() => recentFilesHelper.save(new RecentFileModel(filepath, token, key), key));
            await tryReadRecentFilesProcedureAsync();
            await Task.Run(() => recentFilesHelper.save(new RecentFileModel(filepath, token, suffix), suffix));
            await tryReadRecentFilesProcedureAsync().ConfigureAwait(true);
        }

        private async Task<bool> tryReadUserPermissionsAsync()
@@ -291,6 +291,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                isHideRecentFilesFlyoutRequired = false; // reset variable for next notification

                await readLabFileAsync(file, spectrumType, isFromRecentFileSelection: true);
                recentFilesHelper.moveToTopOfList(file.Path, spectrumType.ToString());
            }
        }

@@ -305,6 +306,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                string token = storageItemsAccessHelper.save(file);
                addToRecentFilesAsync(file.Path, token, spectrumType.ToString());
            }
            else
            {
                /* move selected item on top of the list of recent files */
                recentFilesHelper.moveToTopOfList(file.Path, spectrumType.ToString());
                await tryReadRecentFilesProcedureAsync().ConfigureAwait(true);
            }

            /* remember access to file */
            storageItemsAccessHelper.save(spectrumType.ToString(), file);
@@ -312,17 +319,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            System.Diagnostics.Debug.WriteLine($"reading {spectrumType.ToString()} Spectrum type...");
            if (spectrumType == SpectrumType.Raw)
            {
                /* clearing chart page and processedspectracontainer is not required on 1st file loading */
                //if (!App.IsFirstRawFileReading)
                //{
                /* clear chart page, if any chart is available */
                await clearChartPageAsync();

                /* clear all retrieved processed spectra, if any is available */
                tryClearProcessedSpectra();
                //}

                //App.IsFirstRawFileReading = false;
            }

            /* try reading the file to make spectrum available */
@@ -498,17 +499,23 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        {
            IsLoading = true;

            string key = FileExt.Xml.ToString();
            string suffix = FileExt.Xml.ToString();

            /* add selected file to recent files list and save the list update */
            if (!isFromRecentFileSelection)
            {
                string token = storageItemsAccessHelper.save(file);
                addToRecentFilesAsync(file.Path, token, key).ConfigureAwait(true);
                addToRecentFilesAsync(file.Path, token, suffix).ConfigureAwait(true);
            }
            else
            {
                /* move selected item on top of the list of recent files */
                recentFilesHelper.moveToTopOfList(file.Path, suffix);
                await tryReadRecentFilesProcedureAsync().ConfigureAwait(true);
            }

            /* remember access to file */
            storageItemsAccessHelper.save(key, file);
            storageItemsAccessHelper.save(suffix, file);

            /* clear summaries in 'Lab files' tab, if any is present */
            WorkingItems.LabSpectraSummaries.resetSummaryOfType(SpectrumType.Raw);
@@ -521,7 +528,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            UserControlsHelper.initUserControlsToBeOpened();

            var xmlSpectrumFileReader = serviceProvider.GetRequiredService<XmlSpectrumFileReader>();
            (IChartSpectrumModel spectrum, string exMsg) result = await xmlSpectrumFileReader.readFileAsync(key).ConfigureAwait(true);
            (IChartSpectrumModel spectrum, string exMsg) result = await xmlSpectrumFileReader.readFileAsync(suffix).ConfigureAwait(true);

            if (!string.IsNullOrEmpty(result.exMsg))
            {
+59 −10
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels
            CheckSpectrumType = SpectrumType.ContinuumRemoved;

            init();

            tryReadIsAddingPointsForContinuumRemovalAllowed();
        }

        #region properties
@@ -102,6 +100,28 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels
            }
        }

        private bool isSegmentsFitUserControlAutoOpenEnabled;
        public bool IsSegmentsFitUserControlAutoOpenEnabled
        {
            get { return isSegmentsFitUserControlAutoOpenEnabled; }
            set
            {
                if (SetProperty(ref isSegmentsFitUserControlAutoOpenEnabled, value))
                    saveIsSegmentsFitUserControlAutoOpenEnabled();
            }
        }

        private bool isSegmentsFitsUserControlAutoOpenRequired;
        public bool IsSegmentsFitsUserControlAutoOpenRequired
        {
            get { return isSegmentsFitsUserControlAutoOpenRequired; }
            set
            {
                if (SetProperty(ref isSegmentsFitsUserControlAutoOpenRequired, value))
                    saveIsSegmentsFitsUserControlAutoOpenRequired();
            }
        }

        private bool isSegmentHighlightRequired;
        public bool IsSegmentHighlightRequired
        {
@@ -116,13 +136,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels
            set { SetProperty(ref isSegmentLowlightRequired, value); }
        }

        private bool isSegmentsFitPanelAutoOpenEnabled;
        public bool IsSegmentsFitPanelAutoOpenEnabled
        {
            get { return isSegmentsFitPanelAutoOpenEnabled; }
            set { SetProperty(ref isSegmentsFitPanelAutoOpenEnabled, value); }
        }

        public List<PointModel> MissingPoints { get; private set; }

        private PointModel newPoint;
@@ -185,6 +198,13 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels

        public void init()
        {
            if (!tryReadIsAddingPointsForContinuumRemovalAllowed())
                IsAddingPointsForContinuumRemovalAllowed = false;

            /* segments fit */
            if (!tryReadIsSegmentsFitUserControlAutoOpenEnabled())
                IsSegmentsFitUserControlAutoOpenEnabled = true;

            AreFitSettingsReady = false;

            IsContinuumRemovedSaved = false;
@@ -558,6 +578,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels
            isSegmentHighlightRequired = false;
        }

        public void raiseIsSegmentsFitsUserControlAutoOpenRequired()
        {
            IsSegmentsFitsUserControlAutoOpenRequired = true;
            isSegmentsFitsUserControlAutoOpenRequired = false; // DO NOT UNCOMMENT THIS!
        }

        public void raiseIsSegmentsLowlightRequired()
        {
            IsSegmentLowlightRequired = true;
@@ -577,14 +603,37 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels
            settingsHelper.save(nameof(IsAddingPointsForContinuumRemovalAllowed), IsAddingPointsForContinuumRemovalAllowed);
        }

        private void saveIsSegmentsFitUserControlAutoOpenEnabled()
        {
            settingsHelper.save(nameof(IsSegmentsFitUserControlAutoOpenEnabled), IsSegmentsFitUserControlAutoOpenEnabled);
        }

        private void saveIsSegmentsFitsUserControlAutoOpenRequired()
        {
            settingsHelper.save(nameof(IsSegmentsFitsUserControlAutoOpenRequired), IsSegmentsFitsUserControlAutoOpenRequired);
        }

        private void saveNumOfPointsForMissingPoints(int numOfPointsForMissingPoints)
        {
            settingsHelper.save(Constants.Constants.NUM_OF_POINTS_FOR_MISSING_POINTS, numOfPointsForMissingPoints);
        }

        public void tryReadIsAddingPointsForContinuumRemovalAllowed()
        public bool tryReadIsAddingPointsForContinuumRemovalAllowed()
        {
            if (!settingsHelper.contains(nameof(IsAddingPointsForContinuumRemovalAllowed)))
                return false;

            IsAddingPointsForContinuumRemovalAllowed = settingsHelper.getValue<bool>(nameof(IsAddingPointsForContinuumRemovalAllowed));
            return true;
        }

        private bool tryReadIsSegmentsFitUserControlAutoOpenEnabled()
        {
            if (!settingsHelper.contains(nameof(IsSegmentsFitUserControlAutoOpenEnabled)))
                return false;

            IsSegmentsFitUserControlAutoOpenEnabled = settingsHelper.getValue<bool>(nameof(IsSegmentsFitUserControlAutoOpenEnabled));
            return true;
        }

        public void tryReadNumOfPointsForMissingPoints(int numOfPointsForMissingPoints)
Loading