Esempio n. 1
0
        public TraceViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            Arr <ParameterViewModel> parameterViewModels,
            ModuleState moduleState,
            OutputGroupStore outputGroupStore
            )
        {
            RequireNotNull(SynchronizationContext.Current);

            _appState            = appState;
            _appService          = appService;
            _parameterViewModels = parameterViewModels;
            _moduleState         = moduleState;
            _outputGroupStore    = outputGroupStore;

            _simulation = appState.Target.AssertSome("No simulation");

            TraceDataPlotViewModels = Range(1, ModuleState.N_TRACES)
                                      .Map(i =>
                                           new TraceDataPlotViewModel(
                                               appState,
                                               appService,
                                               appSettings,
                                               moduleState.TraceDataPlotStates[i - 1]
                                               )
                                           )
                                      .ToArr <ITraceDataPlotViewModel>();

            var nTracesVisible = _moduleState.TraceDataPlotStates.Count(s => s.IsVisible);

            ChartGridLayout = nTracesVisible - 1;

            WorkingSet = new ObservableCollection <IParameterViewModel>(
                parameterViewModels.Filter(vm => vm.IsSelected)
                );

            UndoWorkingChange = ReactiveCommand.Create(
                HandleUndoWorkingChange,
                this.WhenAny(vm => vm.SessionEdits, _ => SessionEdits.Count > 1)
                );

            PlotWorkingChanges = ReactiveCommand.Create(
                HandlePlotWorkingChanges,
                this.WhenAny(vm => vm.HasPendingWorkingChanges, _ => HasPendingWorkingChanges)
                );

            _isWorkingSetPanelOpen = _moduleState.TraceState.IsWorkingSetPanelOpen
        ? 0
        : -1;

            var(ms, _) = _appState.SimData
                         .GetExecutionInterval(_simulation)
                         .IfNone((304, default));
Esempio n. 2
0
        public static void Save(ModuleState instance, Simulation simulation)
        {
            var dto = new _ModuleStateDTO
            {
                TraceDataPlotStates = instance.TraceDataPlotStates
                                      .Map(tdps => new _TraceDataPlotStateDTO
                {
                    IsVisible         = tdps.IsVisible,
                    DepVarConfigState = new _DepVarConfigStateDTO
                    {
                        SelectedElementName               = tdps.DepVarConfigState.SelectedElementName,
                        MRUElementNames                   = tdps.DepVarConfigState.MRUElementNames.ToArray(),
                        SelectedInsetElementName          = tdps.DepVarConfigState.SelectedInsetElementName,
                        SupplementaryElementNames         = tdps.DepVarConfigState.SupplementaryElementNames.ToArray(),
                        InactiveSupplementaryElementNames = tdps.DepVarConfigState.InactiveSupplementaryElementNames
                                                            .ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToArray()),
                        ObservationsReferences = tdps.DepVarConfigState.ObservationsReferences.ToArray(),
                        IsScaleLogarithmic     = tdps.DepVarConfigState.IsScaleLogarithmic
                    },
                    ViewHeight                   = tdps.ViewHeight,
                    IsSeriesTypeLine             = tdps.IsSeriesTypeLine,
                    IsAxesOriginLockedToZeroZero = tdps.IsAxesOriginLockedToZeroZero,
                    XMinimum = tdps.XMinimum,
                    XMaximum = tdps.XMaximum,
                    YMinimum = tdps.YMinimum,
                    YMaximum = tdps.YMaximum
                })
                                      .ToArray(),
                ParameterEditStates              = instance.ParameterEditStates.ToArray(),
                TraceState                       = instance.TraceState,
                AutoApplyParameterSharedState    = instance.AutoApplyParameterSharedState,
                AutoShareParameterSharedState    = instance.AutoShareParameterSharedState,
                AutoApplyElementSharedState      = instance.AutoApplyElementSharedState,
                AutoShareElementSharedState      = instance.AutoShareElementSharedState,
                AutoApplyObservationsSharedState = instance.AutoApplyObservationsSharedState,
                AutoShareObservationsSharedState = instance.AutoShareObservationsSharedState
            };

            simulation.SavePrivateData(
                dto,
                nameof(Plot),
                nameof(ViewModel),
                nameof(ModuleState)
                );
        }
Esempio n. 3
0
        internal ViewModel(IAppState appState, IAppService appService, IAppSettings appSettings)
        {
            _appState    = appState;
            _sharedState = appState.SimSharedState;
            _simulation  = appState.Target.AssertSome("No simulation");
            _evidence    = appState.SimEvidence;

            _moduleState = ModuleState.LoadOrCreate(_simulation);

            _outputGroupStore = new OutputGroupStore(_simulation);

            _parameters = new Parameters(_simulation, appService, _moduleState);

            _traceViewModel      = new TraceViewModel(appState, appService, appSettings, _parameters.ViewModels, _moduleState, _outputGroupStore);
            _parametersViewModel = new ParametersViewModel(_parameters.ViewModels);
            _outputsViewModel    = new OutputsViewModel(appState, _outputGroupStore);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(SubscribeToObservables());

            TraceViewModel.IsSelected = true;
        }
Esempio n. 4
0
        internal Parameters(Simulation simulation, IAppService appService, ModuleState moduleState)
        {
            _simulation  = simulation;
            _appService  = appService;
            _moduleState = moduleState;

            _toggleSelect    = ReactiveCommand.Create <IParameterViewModel>(HandleToggleSelect);
            _resetValue      = ReactiveCommand.Create <IParameterViewModel>(HandleResetValue);
            _increaseMinimum = ReactiveCommand.Create <IParameterViewModel>(HandleIncreaseMinimum);
            _decreaseMinimum = ReactiveCommand.Create <IParameterViewModel>(HandleDecreaseMinimum);
            _increaseMaximum = ReactiveCommand.Create <IParameterViewModel>(HandleIncreaseMaximum);
            _decreaseMaximum = ReactiveCommand.Create <IParameterViewModel>(HandleDecreaseMaximum);

            var parameters = simulation.SimConfig.SimInput.SimParameters;

            ViewModels = _moduleState.ParameterEditStates.Map(
                pes =>
            {
                var parameter = parameters.GetParameter(
                    pes.Name.AssertNotNull("Invalid module state")
                    );

                return(new ParameterViewModel(
                           _toggleSelect,
                           _resetValue,
                           _increaseMinimum,
                           _decreaseMinimum,
                           _increaseMaximum,
                           _decreaseMaximum,
                           parameter.Name,
                           parameter.Value,
                           parameter.Unit,
                           parameter.Description,
                           appService
                           )
                {
                    IsSelected = pes.IsSelected,
                    TValue = pes.Value,
                    Minimum = pes.Minimum,
                    Maximum = pes.Maximum
                });
            });

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            var disposables = moduleState.ParameterEditStates
                              .Map(pes => pes
                                   .GetWhenPropertyChanged()
                                   .Subscribe(
                                       _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                                           s => ObserveParameterEditStateProperty(pes, s)
                                           )
                                       )
                                   );

            disposables += ViewModels.Map(
                p => p
                .GetWhenPropertyChanged()
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <string?>(s => ObserveParameterViewModelProperty(p, s))
                    )
                );

            _subscriptions = new CompositeDisposable(disposables);
        }