internal OutputsViewModel( IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState, SamplingDesigns samplingDesigns ) { _appState = appState; _appSettings = appSettings; _moduleState = moduleState; _simulation = appState.Target.AssertSome(); _outputsSelectedSampleViewModel = new OutputsSelectedSampleViewModel(appState, appService, moduleState); _outputsFilteredSamplesViewModel = new OutputsFilteredSamplesViewModel(appState, appService, moduleState, samplingDesigns); _outputsEvidenceViewModel = new OutputsEvidenceViewModel(appState, appService, moduleState); var output = _simulation.SimConfig.SimOutput; _outputNames = output.DependentVariables .Map(e => e.Name) .OrderBy(n => n.ToUpperInvariant()) .ToArr(); _moduleState.OutputsState.SelectedOutputName ??= _outputNames.Head(); _selectedOutputName = _outputNames.IndexOf( _moduleState.OutputsState.SelectedOutputName ); PlotController = new(); PlotController.Bind( new OxyMouseDownGesture(OxyMouseButton.Left), new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown) ); PlotController.Bind( new OxyMouseDownGesture(OxyMouseButton.Left, OxyModifierKeys.Control), new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown) ); Outputs = new(); var horizontalAxis = new LinearAxis { Position = AxisPosition.Bottom, Title = output.IndependentVariable.Name, Unit = output.IndependentVariable.Unit }; Outputs.Axes.Add(horizontalAxis); var verticalAxis = new LinearAxis { Position = AxisPosition.Left }; Outputs.Axes.Add(verticalAxis); Outputs.ApplyThemeToPlotModelAndAxes(); PopulateAll(); ToggleSeriesType = ReactiveCommand.Create(HandleToggleSeriesType); ResetAxes = ReactiveCommand.Create(HandleResetAxes); _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( appSettings .GetWhenPropertyChanged() .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <string?>( ObserveAppSettingsPropertyChange ) ), moduleState.OutputsState .ObservableForProperty(os => os.SelectedOutputName) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveOutputsStateSelectedOutputName ) ), moduleState.OutputsState .ObservableForProperty(os => os.ObservationsReferences) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveOutputsStateObservationsReferences ) ), moduleState .ObservableForProperty(ms => ms.FilterConfig) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateFilterConfig ) ), moduleState .ObservableForProperty(ms => ms.Outputs) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateOutputs ) ), moduleState .ObservableForProperty(ms => ms.OutputFilters) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateOutputFilters ) ), this .ObservableForProperty(vm => vm.SelectedOutputName) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveSelectedOutputName ) ) ); }
internal DesignViewModel( IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState, SamplingDesigns samplingDesigns ) { _appService = appService; _appSettings = appSettings; _moduleState = moduleState; _samplingDesigns = samplingDesigns; _simulation = appState.Target.AssertSome(); _simData = appState.SimData; CreateDesign = ReactiveCommand.Create( HandleCreateDesign, this.WhenAny(vm => vm.CanCreateDesign, _ => CanCreateDesign) ); UnloadDesign = ReactiveCommand.Create( HandleUnloadDesign, this.WhenAny(vm => vm.CanUnloadDesign, _ => CanUnloadDesign) ); AcquireOutputs = ReactiveCommand.Create( HandleAcquireOutputs, this.WhenAny(vm => vm.CanAcquireOutputs, _ => CanAcquireOutputs) ); CancelAcquireOutputs = ReactiveCommand.Create( HandleCancelAcquireOutputs, this.WhenAny(vm => vm.CanCancelAcquireOutputs, _ => CanCancelAcquireOutputs) ); _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( moduleState .ObservableForProperty(vm => vm.Samples) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateSamples ) ), moduleState .ObservableForProperty(vm => vm.SamplingDesign) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateSamplingDesign ) ) ); using (_reactiveSafeInvoke.SuspendedReactivity) { Populate(); if (_moduleState.SamplingDesign != default) { ConfigureOutputsAcquisition(); } UpdateEnable(); } }
internal OutputsFilteredSamplesViewModel( IAppState appState, IAppService appService, ModuleState moduleState, SamplingDesigns samplingDesigns ) { _moduleState = moduleState; _samplingDesigns = samplingDesigns; _simulation = appState.Target.AssertSome(); _toggleEnable = ReactiveCommand.Create <OutputsFilterViewModel>(HandleToggleEnable); _delete = ReactiveCommand.Create <OutputsFilterViewModel>(HandleDelete); var independentVariable = _simulation.SimConfig.SimOutput.IndependentVariable; IndependentVariableName = independentVariable.Name; IndependentVariableUnit = independentVariable.Unit; _outputName = moduleState.OutputsState.SelectedOutputName; AddNewFilter = ReactiveCommand.Create( HandleAddNewFilter, this.WhenAny( vm => vm.FromN, vm => vm.ToN, (_, _) => FromN.HasValue && ToN.HasValue ) ); IsUnion = moduleState.SamplingDesign is null ? moduleState.FilteredSamplesState.IsUnion : _moduleState.FilterConfig.IsUnion; IsEnabled = moduleState.SamplingDesign is null ? moduleState.FilteredSamplesState.IsEnabled : moduleState.FilterConfig.IsEnabled; PopulateOutputFilters(); _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( moduleState .ObservableForProperty(ms => ms.Outputs) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateOutputs ) ), moduleState .ObservableForProperty(ms => ms.FilterConfig) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateFilterConfig ) ), moduleState .ObservableForProperty(ms => ms.OutputFilters) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateOutputFilters ) ), moduleState.OutputsState .ObservableForProperty(os => os.SelectedOutputName) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveOutputsStateSelectedOutputName ) ), this .ObservableForProperty(vm => vm.FromT) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveFromT ) ), this .ObservableForProperty(vm => vm.ToT) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveToT ) ), this .ObservableForProperty(vm => vm.IsEnabled) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveIsEnabled ) ), this .ObservableForProperty(vm => vm.IsUnion) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveIsUnion ) ) ); }
internal ViewModel(IAppState appState, IAppService appService, IAppSettings appSettings) { _appState = appState; _appService = appService; _sharedState = appState.SimSharedState; _simulation = appState.Target.AssertSome(); _evidence = appState.SimEvidence; var pathToSamplingDesignsDirectory = _simulation.GetPrivateDirectory(nameof(Sampling), nameof(SamplingDesigns)); _samplingDesigns = new SamplingDesigns(pathToSamplingDesignsDirectory); _moduleState = ModuleState.LoadOrCreate(_simulation, _samplingDesigns); _parametersViewModel = new ParametersViewModel(appState, appService, appSettings, _moduleState); _samplesViewModel = new SamplesViewModel(appState, appService, appSettings, _moduleState); _designViewModel = new DesignViewModel(appState, appService, appSettings, _moduleState, _samplingDesigns); _outputsViewModel = new OutputsViewModel(appState, appService, appSettings, _moduleState, _samplingDesigns); _designDigestsViewModel = new DesignDigestsViewModel(appService, _moduleState, _samplingDesigns); _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( _moduleState.ParameterStateChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>( ObserveParameterStateChange ) ), _sharedState.ParameterSharedStateChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimParameterSharedState>, ObservableQualifier)>( ObserveSharedStateParameterChange ) ), _sharedState.ObservationsSharedStateChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimObservationsSharedState>, ObservableQualifier)>( ObserveSharedStateObservationsChange ) ), _designDigestsViewModel .ObservableForProperty(vm => vm.TargetSamplingDesign).Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveTargetSamplingDesign ) ), _moduleState .ObservableForProperty(ms => ms.SamplingDesign) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateSamplingDesign ) ), _moduleState.OutputsState .ObservableForProperty(os => os.ObservationsReferences) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveOutputsStateObservationsReferences ) ), _evidence.ObservationsChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimObservations>, ObservableQualifier)>( ObserveEvidenceObservationsChange ) ), _samplingDesigns.SamplingDesignChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>( ObserveSamplingDesignChange ) ) ); SetActivities(); if (_moduleState.SamplingDesign != default) { _designViewModel.IsSelected = true; } }
internal DesignDigestsViewModel( IAppService appService, ModuleState moduleState, SamplingDesigns samplingDesigns ) { _moduleState = moduleState; _samplingDesigns = samplingDesigns; LoadSamplingDesign = ReactiveCommand.Create( HandleLoadSamplingDesign, this.WhenAny( vm => vm.SelectedDesignDigestViewModel, _ => SelectedDesignDigestViewModel != default ) ); DeleteSamplingDesign = ReactiveCommand.Create( HandleDeleteSamplingDesign, this.WhenAny( vm => vm.SelectedDesignDigestViewModel, _ => SelectedDesignDigestViewModel != default ) ); FollowKeyboardInDesignDigests = ReactiveCommand.Create <(Key Key, bool Control, bool Shift)>( HandleFollowKeyboardInDesignDigests ); DesignDigestViewModels = new ObservableCollection <IDesignDigestViewModel>( samplingDesigns.DesignDigests.Map( dd => new DesignDigestViewModel(dd.CreatedOn, dd.Description) )); if (_moduleState.SamplingDesign != default) { TargetSamplingDesign = Some((_moduleState.SamplingDesign.CreatedOn, DateTime.Now)); SelectedDesignDigestViewModel = DesignDigestViewModels .Find(vm => vm.CreatedOn == _moduleState.SamplingDesign.CreatedOn) .Match <IDesignDigestViewModel?>(vm => vm, () => default); } _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( moduleState .ObservableForProperty(ms => ms.SamplingDesign) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateSamplingDesign ) ), samplingDesigns.SamplingDesignChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>( ObserveSamplingDesignChange ) ) ); }