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

adding removal of all spectra when RAW changes

parent 417f1125
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -210,6 +210,17 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions
            };
        }

        public static SpectrumFileModel ToSpectrumFileBaseInfo(this SpectrumModel model)
        {
            return new SpectrumFileModel()
            {
                Id = model.Id,
                Filename = model.Filename,
                ParentId = model.ParentId,
                Type = model.Type
            };
        }

        public static PointModel ToPointModel(this CartesianCustomAnnotation cartesianCustomAnnotation)
        {
            try
+67 −40
Original line number Diff line number Diff line
@@ -313,12 +313,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            IsSegmentsFitsUserControlAutoOpenRequired = true;
            isSegmentsFitsUserControlAutoOpenRequired = false; // DO NOT UNCOMMENT THIS!
        }

        //private void reaiseIsSegmentsFitsUserControlCloseRequired()
        //{
        //    IsSegmentsFitsUserControlCloseRequired = true;
        //    isSegmentsFitsUserControlCloseRequired = false;
        //}
        #endregion

        #region methods
@@ -333,13 +327,45 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels

        public async Task deleteDerivedSpectraAsync()
        {
            if (WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.Aligned))
                await deleteAlignedSpectrumAsync(showErrorMessages: false);
            foreach (SpectrumType spectrumType in Enum.GetValues(typeof(SpectrumType)))
            {
                if (spectrumType == SpectrumType.Ref || spectrumType == SpectrumType.RefWhite)
                    continue;

            if (WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.ContinuumRemoved))
                await deleteContinuumRemovedSpectrumAsync(showErrorMessages: false,
                                                          deleteOnCloudIfAvailable: false,
                                                          removeFitSettings: true);
                if (WorkingItems.SpectraContainer.isAnySpectrumOfType(spectrumType))
                    await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(spectrumType);

                /* specific actions for spectra types */
                switch (spectrumType)
                {
                    case SpectrumType.Aligned:
                        /* disable buttons for saving/deleting aligned spectrum + disable toggleSwitch for adding points for fitting continuum */
                        AreButtonsForAlignedSpectrumEnabled = false;
                        /* set toggleSwitch for adding points for fitting continuum to 'off' */
                        ContinuumRemovalHelper.IsAddingPointsForContinuumRemovalAllowed = false;
                        /* hide panel for creating continuum */
                        raiseUserControlClosing(nameof(AlignmentConfigUserControl).FirstCharToLowerCase());
                        break;

                    case SpectrumType.AlignedSmoothedBySegments:
                    case SpectrumType.AlignedSmoothed:
                    case SpectrumType.ContinuumRemovedSmoothedBySegments:
                    case SpectrumType.ContinuumRemovedSmoothed:
                        /* hide panel for creating continuum */
                        raiseUserControlClosing(nameof(SmoothingUserControl).FirstCharToLowerCase());
                        break;
                    case SpectrumType.Continuum:
                        break;
                    case SpectrumType.ContinuumRemoved:
                        /* remove all points and segments for creating continuum */
                        await clearSegmentsFitAndContinuumSpectraAsync();
                        /* hide panel for creating continuum */
                        raiseUserControlClosing(nameof(SegmentsFitUserControl).FirstCharToLowerCase());
                        break;
                    default:
                        break;
                }
            }
        }

        private async void initAsync()
@@ -437,7 +463,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels

        private void saveAreButtonsForAlignedSpectrumEnabled()
        {
            settingsHelper.save(nameof(AreButtonsForAlignedSpectrumEnabled), AreButtonsForAlignedSpectrumEnabled);
            settingsHelper.save(nameof(AreButtonsForAlignedSpectrumEnabled), AreButtonsForAlignedSpectrumEnabled.ToString());
        }

        private bool tryReadAreButtonsForAlignedSpectrumEnabled()
@@ -514,29 +540,29 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        #endregion
        #endregion

        #region aligned spectrum
        private async Task deleteAlignedSpectrumAsync(bool showErrorMessages = true)
        {
            raiseHideAlignmentFlyoutRequired();
        #region aligned
        //private async Task deleteAlignedSpectrumAsync(bool showErrorMessages = true)
        //{
        //    raiseHideAlignmentFlyoutRequired();

            if (!WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.Aligned) && showErrorMessages)
            {
                showDialogMessage("RawSpectrumAlignmentNoAlignedToBeRemovedErrorMessage".GetText());
                return;
            }
        //    if (!WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.Aligned) && showErrorMessages)
        //    {
        //        showDialogMessage("RawSpectrumAlignmentNoAlignedToBeRemovedErrorMessage".GetText());
        //        return;
        //    }

            if (!await WorkingItems.SpectraContainer.removeAlignedSpectrumAsync() && showErrorMessages)
            {
                showDialogMessage("TryRemoveSpectrumFailedMessage".GetText());
                return;
            }
        //    if (!await WorkingItems.SpectraContainer.removeAlignedSpectrumAsync() && showErrorMessages)
        //    {
        //        showDialogMessage("TryRemoveSpectrumFailedMessage".GetText());
        //        return;
        //    }

            /* disable buttons for saving/deleting aligned spectrum + disable toggleSwitch for adding points for fitting continuum */
            AreButtonsForAlignedSpectrumEnabled = false;
        //    /* disable buttons for saving/deleting aligned spectrum + disable toggleSwitch for adding points for fitting continuum */
        //    AreButtonsForAlignedSpectrumEnabled = false;

            /* set toggleSwitch for adding points for fitting continuum to 'off' */
            ContinuumRemovalHelper.IsAddingPointsForContinuumRemovalAllowed = false;
        }
        //    /* set toggleSwitch for adding points for fitting continuum to 'off' */
        //    ContinuumRemovalHelper.IsAddingPointsForContinuumRemovalAllowed = false;
        //}

        private async Task executeSpectrumAlignmentAsync()
        {
@@ -583,11 +609,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            }

            /* raise error message if aligned spectrum is already saved */
            if (WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Aligned).IsSavedOnCloud)
            {
                showDialogMessage("AlignedSpectrumAlreadySavedWarningMessage".GetText(), DialogMessageType.Warning);
                return;
            }
            //if (WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Aligned).IsSavedOnCloud)
            //{
            //    showDialogMessage("AlignedSpectrumAlreadySavedWarningMessage".GetText(), DialogMessageType.Warning);
            //    return;
            //}

            IsLoading = true;

@@ -696,7 +722,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                AlignmentSettings = new AlignmentSettingsModel()
                {
                    RawFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Raw).ToSpectrumFile(),
                    RefFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Ref).ToSpectrumFile(),
                    RefFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Ref).ToSpectrumFileBaseInfo(),
                    RefWhiteFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.RefWhite).ToSpectrumFileBaseInfo(),
                    NumOfPoints = WorkingItems.SpectraContainer.SpectrumAlignmentConfig.NumOfPointsForAlignment,
                    AlignmentSegmentBoundaries = new AlignmentSegmentBoundariesModel()
                    {
@@ -725,8 +752,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        }

        private async Task deleteContinuumRemovedSpectrumAsync(bool showErrorMessages = true,
                                                               bool deleteOnCloudIfAvailable = true,
                                                               bool removeFitSettings = false)
                                                               bool deleteOnCloudIfAvailable = false,
                                                               bool removeFitSettings = true)
        {
            bool isDeleted = false;
            bool isSavedOnCloud = false;
+30 −24
Original line number Diff line number Diff line
@@ -60,8 +60,11 @@
        </Flyout>
    </Page.Resources>

    <ScrollViewer VerticalScrollMode="Auto"
                  VerticalScrollBarVisibility="Auto"
                  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid x:Name="ContentArea"
          Margin="{StaticResource MediumLeftRightMargin}">
              Margin="8">
        <Grid Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
@@ -108,11 +111,6 @@
                        </Core:EventTriggerBehavior>
                    </Interactivity:Interaction.Behaviors>
                </Button>
                <TextBlock x:Name="textblockRawSpectrumFile"
                           Text="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFilepathConverter}, ConverterParameter='Raw', Mode=OneWay}"
                           Margin="8,16"
                           Grid.Row="1"
                           Grid.Column="1" />
                <Button x:Name="buttonRecentRawSpectrumFiles"
                        FontFamily="Segoe MDL2 Assets"
                        Content="&#xE70D;"
@@ -122,13 +120,20 @@
                        Margin="8"
                        Background="{ThemeResource SystemAccentColor}"
                        Grid.Row="1"
                        Grid.Column="2"
                        Grid.Column="1"
                        DataContext="{x:Bind ViewModel.RecentFilesRawContainer, Mode=OneWay}"
                        Flyout="{StaticResource RecentFilesFlyout}">
                    <ToolTipService.ToolTip>
                        <TextBlock x:Uid="RecentFilesLabel" />
                    </ToolTipService.ToolTip>
                </Button>
                <TextBlock x:Name="textblockRawSpectrumFile"
                           Text="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFilepathConverter}, ConverterParameter='Raw', Mode=OneWay}"
                           Margin="8,16"
                           TextTrimming="WordEllipsis"
                           Grid.Row="1"
                           Grid.Column="2" >
                </TextBlock>
                <!-- ROW 2-->
                <Image x:Name="textblockRawSpectrumStatusImage"
                       Source="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFileReadingStatusToImageConverter}, ConverterParameter='Raw', Mode=OneWay}"
@@ -148,7 +153,7 @@
                           Visibility="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFileReadingStatusToVisibilityConverter}, ConverterParameter='Raw', Mode=OneWay}"
                           Grid.Row="2"
                           Grid.Column="1"
                           Grid.ColumnSpan="3"/>
                           Grid.ColumnSpan="2"/>
                <!-- RAW SPECTRUM SUMMARY-->
                <usercontrols:SpectrumSummaryUserControl x:Name="rawSpectrumSummary"
                                                         SpectrumSummary="{x:Bind uihelpers:XamlHelpers.GetSpectrumSummaryOfType(ViewModel.WorkingItems.SpectraContainer, 'Raw'), Mode=OneWay}"
@@ -201,11 +206,6 @@
                        </Core:EventTriggerBehavior>
                    </Interactivity:Interaction.Behaviors>
                </Button>
                <TextBlock x:Name="textblockRefSpectrumFile"
                           Text="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFilepathConverter}, ConverterParameter='Ref', Mode=OneWay}"
                           Margin="8,16"
                           Grid.Row="1"
                           Grid.Column="1" />
                <Button x:Name="buttonRecentRefSpectrumFiles"
                        FontFamily="Segoe MDL2 Assets"
                        Content="&#xE70D;"
@@ -215,13 +215,18 @@
                        Margin="8"
                        Background="{ThemeResource SystemAccentColor}"
                        Grid.Row="1"
                        Grid.Column="2"
                        Grid.Column="1"
                        DataContext="{x:Bind ViewModel.RecentFilesRefContainer, Mode=OneWay}"
                        Flyout="{StaticResource RecentFilesFlyout}">
                    <ToolTipService.ToolTip>
                        <TextBlock x:Uid="RecentFilesLabel" />
                    </ToolTipService.ToolTip>
                </Button>
                <TextBlock x:Name="textblockRefSpectrumFile"
                           Text="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFilepathConverter}, ConverterParameter='Ref', Mode=OneWay}"
                           Margin="8,16"
                           Grid.Row="1"
                           Grid.Column="2" />
                <!-- ROW 2 -->
                <Image x:Name="textblockRefSpectrumStatusImage"
                       Source="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFileReadingStatusToImageConverter}, ConverterParameter='Ref', Mode=OneWay}"
@@ -293,11 +298,6 @@
                        </Core:EventTriggerBehavior>
                    </Interactivity:Interaction.Behaviors>
                </Button>
                <TextBlock x:Name="textblockRefWhiteFile"
                           Text="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFilepathConverter}, ConverterParameter='RefWhite', Mode=OneWay}"
                           Margin="8,16"
                           Grid.Row="1"
                           Grid.Column="1" />
                <Button x:Name="buttonRecentRefWhiteFiles"
                        FontFamily="Segoe MDL2 Assets"
                        Content="&#xE70D;"
@@ -307,13 +307,18 @@
                        Margin="8"
                        Background="{ThemeResource SystemAccentColor}"
                        Grid.Row="1"
                        Grid.Column="2"
                        Grid.Column="1"
                        DataContext="{x:Bind ViewModel.RecentFilesRefWhiteContainer, Mode=OneWay}"
                        Flyout="{StaticResource RecentFilesFlyout}">
                    <ToolTipService.ToolTip>
                        <TextBlock x:Uid="RecentFilesLabel" />
                    </ToolTipService.ToolTip>
                </Button>
                <TextBlock x:Name="textblockRefWhiteFile"
                           Text="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFilepathConverter}, ConverterParameter='RefWhite', Mode=OneWay}"
                           Margin="8,16"
                           Grid.Row="1"
                           Grid.Column="2" />
                <!-- ROW 2 -->
                <Image x:Name="textblockRefWhiteStatusImage"
                       Source="{x:Bind ViewModel.WorkingItems.SpectraContainer.IsAnySummaryUpdated, Converter={StaticResource SpectrumSummaryFileReadingStatusToImageConverter}, ConverterParameter='RefWhite', Mode=OneWay}"
@@ -374,4 +379,5 @@
            </controls:InAppNotification.ContentTemplate>
        </controls:InAppNotification>
        </Grid>
    </ScrollViewer>
</Page>