Exemple #1
0
        public void EditRegister(object parameter)
        {
            MainWindow           window = App.Current.MainWindow as MainWindow;
            NewRegisterInputVM   vm     = new NewRegisterInputVM();
            NewRegisterInput     input  = new NewRegisterInput(vm);
            ICustomContentDialog dialog = window.DialogManager.CreateCustomContentDialog(input, DialogMode.OkCancel);

            dialog.Ok = () =>
            {
                // to update bindings:
                input.normalize.Focus();
                if (!Validation.GetHasError(input.widthBox) &&
                    !Validation.GetHasError(input.statesGrid))
                {
                    int width = (int)vm.Width;
                    Dictionary <ulong, Complex> initStates = vm.GetInitStates();
                    if (width > 0 && initStates.Count > 0)
                    {
                        int toAdd = width - _model.Registers[_registerIndex].Qubits.Count;
                        if (toAdd > 0)
                        {
                            for (int i = 0; i < toAdd; i++)
                            {
                                _model.InsertQubitAbove(_registerIndex, _model.Registers[_registerIndex].Qubits.Count - 1);
                            }
                        }
                        else if (toAdd < 0)
                        {
                            for (int i = 0; i < -toAdd; i++)
                            {
                                _model.DeleteQubit(_registerIndex, _model.Registers[_registerIndex].Qubits.Count - 1);
                            }
                        }
                        _model.Registers[_registerIndex].InitStates = initStates;
                    }
                }
            };
            dialog.Show();
        }