Exemplo n.º 1
0
 public void UpdateOpticalProperties_Executed()
 {
     //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated
     if (SolutionDomainTypeOptionVM != null)
     {
         UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
     }
     if (UseSpectralPanelData && WindowViewModel.Current != null &&
         WindowViewModel.Current.SpectralMappingVM != null)
     {
         if (IsMultiRegion && MultiRegionTissueVM != null)
         {
             MultiRegionTissueVM.RegionsVM.ForEach(region =>
                                                   ((dynamic)region).OpticalPropertyVM.SetOpticalProperties(
                                                       WindowViewModel.Current.SpectralMappingVM.OpticalProperties));
         }
         else if (OpticalPropertyVM != null)
         {
             OpticalPropertyVM.SetOpticalProperties(WindowViewModel.Current.SpectralMappingVM.OpticalProperties);
         }
     }
 }
Exemplo n.º 2
0
        public ForwardSolverViewModel()
        {
            _showOpticalProperties = true;
            _useSpectralPanelData  = false;


            _allRangeVMs = new[] { new RangeViewModel {
                                       Title = StringLookup.GetLocalizedString("IndependentVariableAxis_Rho")
                                   } };

#if WHITELIST
            ForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>("Forward Model", false, WhiteList.ForwardSolverTypes);
#else
            ForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>("Forward Model", false);
#endif
            SolutionDomainTypeOptionVM = new SolutionDomainOptionViewModel("Solution Domain", SolutionDomainType.ROfRho);

            ForwardAnalysisTypeOptionVM = new OptionViewModel <ForwardAnalysisType>(StringLookup.GetLocalizedString("Heading_ModelAnalysisOutput"), true);

            ForwardSolverTypeOptionVM.PropertyChanged += (sender, args) =>
            {
                OnPropertyChanged("IsGaussianForwardModel");
                OnPropertyChanged("IsMultiRegion");
                OnPropertyChanged("IsSemiInfinite");
                TissueInputVM = GetTissueInputVM(IsMultiRegion ? "MultiLayer" : "SemiInfinite");
                UpdateAvailableOptions();
            };
            ForwardSolverTypeOptionVM.SelectedValue = ForwardSolverType.PointSourceSDA; // force the model choice here?

            Action <double> updateSolutionDomainWithWavelength = wv =>
            {
                var wvAxis =
                    SolutionDomainTypeOptionVM.ConstantAxesVMs.FirstOrDefault(
                        axis => axis.AxisType == IndependentVariableAxis.Wavelength);
                if (wvAxis != null)
                {
                    wvAxis.AxisValue = wv;
                }
            };

            SolutionDomainTypeOptionVM.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "UseSpectralInputs")
                {
                    UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
                }
                if (args.PropertyName == "IndependentAxesVMs")
                {
                    var useSpectralPanelDataAndNotNull = SolutionDomainTypeOptionVM.UseSpectralInputs &&
                                                         WindowViewModel.Current != null &&
                                                         WindowViewModel.Current.SpectralMappingVM != null;

                    AllRangeVMs =
                        (from i in
                         Enumerable.Range(0,
                                          SolutionDomainTypeOptionVM.IndependentVariableAxisOptionVM.SelectedValues.Length)
                         orderby i descending
                         // descending so that wavelength takes highest priority, then time/time frequency, then space/spatial frequency
                         select
                         useSpectralPanelDataAndNotNull&&
                         SolutionDomainTypeOptionVM.IndependentVariableAxisOptionVM.SelectedValues[i] ==
                         IndependentVariableAxis.Wavelength
                                    ? WindowViewModel.Current.SpectralMappingVM.WavelengthRangeVM
                         // bind to same instance, not a copy
                                    : SolutionDomainTypeOptionVM.IndependentAxesVMs[i].AxisRangeVM).ToArray();

                    // if the independent axis is wavelength, then hide optical properties (because they come from spectral panel)
                    ShowOpticalProperties =
                        _allRangeVMs.All(value => value.AxisType != IndependentVariableAxis.Wavelength);

                    // update solution domain wavelength constant if applicable
                    if (useSpectralPanelDataAndNotNull &&
                        SolutionDomainTypeOptionVM.ConstantAxesVMs.Any(
                            axis => axis.AxisType == IndependentVariableAxis.Wavelength))
                    {
                        updateSolutionDomainWithWavelength(WindowViewModel.Current.SpectralMappingVM.Wavelength);
                    }
                }
            };

            ExecuteForwardSolverCommand = new RelayCommand(() => ExecuteForwardSolver_Executed(null, null));

            OpticalPropertyVM.PropertyChanged += (sender, args) =>
            {
                //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated
                if (SolutionDomainTypeOptionVM != null)
                {
                    UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
                }
                if (UseSpectralPanelData && WindowViewModel.Current != null &&
                    WindowViewModel.Current.SpectralMappingVM != null)
                {
                    updateSolutionDomainWithWavelength(WindowViewModel.Current.SpectralMappingVM.Wavelength);
                }
            };

            if (WindowViewModel.Current.SpectralMappingVM != null)
            {
                WindowViewModel.Current.SpectralMappingVM.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == "Wavelength")
                    {
                        //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated
                        if (SolutionDomainTypeOptionVM != null)
                        {
                            UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
                        }
                        if (UseSpectralPanelData && WindowViewModel.Current != null &&
                            WindowViewModel.Current.SpectralMappingVM != null)
                        {
                            updateSolutionDomainWithWavelength(WindowViewModel.Current.SpectralMappingVM.Wavelength);
                        }
                    }

                    if (args.PropertyName == "OpticalProperties")
                    {
                        //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated
                        if (SolutionDomainTypeOptionVM != null)
                        {
                            UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
                        }
                        if (UseSpectralPanelData && WindowViewModel.Current != null &&
                            WindowViewModel.Current.SpectralMappingVM != null)
                        {
                            if (IsMultiRegion && MultiRegionTissueVM != null)
                            {
                                MultiRegionTissueVM.RegionsVM.ForEach(region =>
                                                                      ((dynamic)region).OpticalPropertyVM.SetOpticalProperties(
                                                                          WindowViewModel.Current.SpectralMappingVM.OpticalProperties));
                            }
                            else if (OpticalPropertyVM != null)
                            {
                                OpticalPropertyVM.SetOpticalProperties(
                                    WindowViewModel.Current.SpectralMappingVM.OpticalProperties);
                            }
                        }
                    }
                };
            }
        }