Beispiel #1
0
        /// <summary>
        /// Applies a transaction without pushing it to the undo stack.
        /// This method can cause inconsistencies in the undo system and should be used with care.
        /// </summary>
        public void DoTransactionNoPush(Transaction.Transaction transaction)
        {
            switch (transaction)
            {
            case WireTransaction wt:
                Wires.ApplyTransaction(wt);
                break;

            case GateTransaction gt:
                Gates.ApplyTransaction(gt);
                break;

            case BundledTransaction bt:
            {
                foreach (var bundled in bt.BundledTransactions)
                {
                    DoTransactionNoPush(bundled);
                }
                break;
            }

            default:
                throw new Exception($"Unknown transaction type! {transaction.GetType()}");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Applies a transaction without pushing it to the undo stack.
        /// This method can cause inconsistencies in the undo system and should be used with care.
        /// </summary>
        public void DoTransactionNoPush(Transaction.Transaction transaction)
        {
            switch (transaction)
            {
            case WireTransaction wt:
                Wires.ApplyTransaction(wt);
                // Update the subnets
                UpdateSubnets(wt.Created, wt.Deleted);
                break;

            case GateTransaction gt:
                Gates.ApplyTransaction(gt);
                if (gt.ConnectionPointWireEdits != null)
                {
                    Wires.ApplyTransaction(gt.ConnectionPointWireEdits);
                }
                // FIXME: Clean this up, this is just so that we can get something simulating
                if (gt.RemoveComponent)
                {
                    this.RemoveComponent(gt.Gate);
                }
                else
                {
                    this.AddComponent(gt.Gate);
                }
                // Update the subnets
                UpdateSubnets(
                    gt.ConnectionPointWireEdits?.CreatedWires ?? new List <Wire>(),
                    gt.ConnectionPointWireEdits?.DeletedWires ?? new List <Wire>());
                break;

            case BundledTransaction bt:
            {
                foreach (var bundled in bt.BundledTransactions)
                {
                    DoTransactionNoPush(bundled);
                }
                break;
            }

            default:
                throw new Exception($"Unknown transaction type! {transaction.GetType()}");
            }
        }
Beispiel #3
0
        private void DrawingArea_KeyPressEvent(object o, KeyPressEventArgs args)
        {
            var @event = args.Event;

            // Check that control is the only modifier pressed.
            if ((@event.State ^ ModifierType.ControlMask) == 0)
            {
                if (@event.Key == Gdk.Key.z)
                {
                    // This is ctrl-z, i.e. undo
                    if (Transactions.TryUndo(out var transaction))
                    {
                        switch (transaction)
                        {
                        case WireTransaction wt:
                            Wires.RevertTransaction(wt);
                            break;

                        case GateTransaction gt:
                            Gates.RevertGateTransaction(gt);
                            break;

                        default:
                            throw new Exception($"Unknown transaction type! {transaction.GetType()}");
                        }
                        Console.WriteLine($"Undid transaction: {transaction}");
                        DrawingArea.QueueDraw();
                    }
                }
                else if (@event.Key == Gdk.Key.y)
                {
                    // This is ctrl-y, i.e. redo
                    if (Transactions.TryRedo(out var transaction))
                    {
                        switch (transaction)
                        {
                        case WireTransaction wt:
                            Wires.ApplyTransaction(wt);
                            break;

                        case GateTransaction gt:
                            Gates.ApplyTransaction(gt);
                            break;

                        default:
                            throw new Exception($"Unknown transaction type! {transaction.GetType()}");
                        }
                        Console.WriteLine($"Redid transaction: {transaction}");
                        DrawingArea.QueueDraw();
                    }
                }
            }

            if ((@event.State ^ (ModifierType.ControlMask | ModifierType.ShiftMask)) == 0)
            {
                if (@event.Key == Gdk.Key.Z)
                {
                    // This is ctrl-shift-z, i.e. redo
                    if (Transactions.TryRedo(out var transaction))
                    {
                        switch (transaction)
                        {
                        case WireTransaction wt:
                            Wires.ApplyTransaction(wt);
                            break;

                        case GateTransaction gt:
                            Gates.ApplyTransaction(gt);
                            break;

                        default:
                            throw new Exception($"Unknown transaction type! {transaction.GetType()}");
                        }
                        Console.WriteLine($"Redid transaction: {transaction}");
                        DrawingArea.QueueDraw();
                    }
                }
            }
        }