Exemplo n.º 1
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            SelectionSize = editor.RoundDistToGrid(endOffset);
            Selecting     = false;

            // FIXME: Do the selecting

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 2
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            SelectionSize = editor.RoundDistToGrid(endOffset);
            Selecting     = false;

            // Make sure we don't have a negitive size

            if (SelectionSize.X < 0)
            {
                SelectionSize.X   = -SelectionSize.X;
                SelectionStart.X -= SelectionSize.X;
            }

            if (SelectionSize.Y < 0)
            {
                SelectionSize.Y   = -SelectionSize.Y;
                SelectionStart.Y -= SelectionSize.Y;
            }

            // FIXME: Do the selecting
            var wires = editor.Scene.Wires;

            ClearSelection(editor);

            // If the size is zero we want to check if we clicked a wire or gate
            if (SelectionSize == Vector2i.Zero)
            {
                foreach (var wire in wires.WiresList)
                {
                    if (wire.IsPointOnWire(SelectionStart))
                    {
                        SelectedWires.Add(wire);
                        break;
                    }
                }
            }
            else
            {
                // Here we should loop through all wires and see if they are contained in the area
                Recti selectionRect = new Recti(SelectionStart, SelectionSize);

                foreach (var wire in wires.WiresList)
                {
                    if (selectionRect.Contains(wire.Pos) &&
                        selectionRect.Contains(wire.EndPos))
                    {
                        SelectedWires.Add(wire);
                        Console.WriteLine($"Selected wire: {wire}");
                    }
                }
            }

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 3
0
        public override void GestureUpdate(CircuitEditor editor, Vector2d offset)
        {
            var diff = editor.RoundDistToGrid(offset);

            if (Math.Abs(diff.X) > Math.Abs(diff.Y))
            {
                // Here we are drawing a horizontal line
                CurrentWire = new Wire(DragStartPos, diff.X, Circuit.Direction.Horizontal);
            }
            else
            {
                //This should be a vertical line
                CurrentWire = new Wire(DragStartPos, diff.Y, Circuit.Direction.Vertical);
            }

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 4
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            VisualPosition = StartPosition + editor.RoundDistToGrid(endOffset);
            StartPosition  = VisualPosition;

            var transaction = editor.Gates.CreateAddGateTransaction(
                InstanceData.Create(BaseComponent.Type, VisualPosition, CompOrientation)
                );

            editor.Gates.ApplyTransaction(transaction);
            editor.Transactions.PushTransaction(transaction);

            StartPosition     = VisualPosition;
            DraggingComponent = false;

            editor.DrawingArea.QueueDraw();
            // FIXME: Add the component!
        }
Exemplo n.º 5
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            VisualPosition = StartPosition + editor.RoundDistToGrid(endOffset);
            StartPosition  = VisualPosition;

            var transaction = editor.Scene.Gates.CreateAddGateTransaction(editor.Scene.Wires,
                                                                          InstanceData.Create(BaseComponent.Type, VisualPosition, CompOrientation)
                                                                          );

            editor.Scene.PushTransaction(transaction);

            Console.WriteLine($"Created gate transaction: \n{transaction}");

            StartPosition     = VisualPosition;
            DraggingComponent = false;

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 6
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            VisualPosition = StartPosition + editor.RoundDistToGrid(endOffset);
            StartPosition  = VisualPosition;

            var transaction = editor.Gates.CreateAddGateTrasaction(
                BaseComponent.Create(VisualPosition, CompOrientation)
                //new Circuit.AndGate(VisualPosition, CompOrientation)
                );

            editor.Gates.ApplyTransaction(transaction);
            editor.Transactions.PushTransaction(transaction);

            VisualPosition = StartPosition = Vector2i.Zero;

            editor.DrawingArea.QueueDraw();
            // FIXME: Add the component!
        }
Exemplo n.º 7
0
 public override void GestureUpdate(CircuitEditor editor, Vector2d offset)
 {
     SelectionSize = editor.RoundDistToGrid(offset);
     //Console.WriteLine($"Size: {SelectionSize}");
     editor.DrawingArea.QueueDraw();
 }
Exemplo n.º 8
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            // FIXME: Do l-shaped wire addition
            var diff = editor.RoundDistToGrid(endOffset);

            if (Math.Abs(diff.X) > Math.Abs(diff.Y))
            {
                // FIXME: We shouldn't rely on the constructor to flip negative diffs
                // because we are going to remove that so we should do it ourselves here.

                // Here we are drawing a horizontal line
                CurrentWire = new Wire(DragStartPos, diff.X, Circuit.Direction.Horizontal);
            }
            else
            {
                //This should be a vertical line
                CurrentWire = new Wire(DragStartPos, diff.Y, Circuit.Direction.Vertical);
            }

            DraggingWire = false;

            if (CurrentWire.Length != 0)
            {
                // Here we should figure out if we are modifying an existing wire.
                // Because adding wires handles merging wires that go in the same
                // direction, we only want to detect the case where we are shrinking
                // a wire. This is easy, because we only need to check that we grabbed
                // one end of the wire and the the other end is inside the wire we want
                // to shrink.
                Wire?modifying = null;
                bool movingEnd = false;
                foreach (var bWire in editor.Scene.Wires.WiresList)
                {
                    if (CurrentWire.Direction != bWire.Direction)
                    {
                        continue;
                    }

                    // We do 'IsPointInsideWire' because we don't want to detect the case
                    // where we are dragging a wire left from a junction to create a new wire.
                    // What would happen if we used 'IsPointOnWire' is that the start pos would
                    // be equal and at the same time 'CurrentWire.Pos' would be on the wire,
                    // making us think that we want to edit the wire while we don't want to.
                    if (DragStartPos == bWire.Pos && bWire.IsPointInsideWire(CurrentWire.EndPos))
                    {
                        modifying = bWire;
                        movingEnd = false;
                    }
                    else if (DragStartPos == bWire.EndPos && bWire.IsPointInsideWire(CurrentWire.Pos))
                    {
                        modifying = bWire;
                        movingEnd = true;
                    }
                    else if (CurrentWire == bWire)
                    {
                        // If they are the same wire we want to remove the bWire
                        modifying = bWire;
                    }
                }

                // If there there more than one endpoint at the start position
                // We don't want to modify a wire, we want to create a new one
                // If there was only one point we check that we actually want to
                // modify that wire (ie modifying is not null).
                if (modifying is Wire modify)
                {
                    // Here we are modifying an existing wire.
                    // So we should figure out how the wire should be modified.
                    // If the wire is deleted we need to check for places where we should merge
                    // other connecting wires. The creation of the remove transaction should
                    // probably be created in a Wires.CreateRemoveWireTransaction(...).

                    Wire modifiedWire = modify;
                    if (movingEnd == false)
                    {
                        // Here we are moving the start poistion of the wire.
                        diff                 = CurrentWire.EndPos - modify.Pos;
                        modifiedWire.Pos     = CurrentWire.EndPos;
                        modifiedWire.Length -= diff.ManhattanDistance;
                    }
                    else
                    {
                        // Here we only need to change the length of the wire.
                        diff = modify.EndPos - CurrentWire.Pos;
                        modifiedWire.Length -= diff.ManhattanDistance;
                    }

                    if (modifiedWire.Length > 0)
                    {
                        // FIMXE: Figure out if there are any edge-cases when modifying wires like this.
                        // One of the cases is where the modified wire should split another already
                        // existing wire.

                        WireTransaction?modifyTransaction = editor.Scene.Wires.CreateModifyWireTransaction(modify, modifiedWire);
                        if (modifyTransaction != null)
                        {
                            editor.Scene.PushTransaction(modifyTransaction);
                            //Console.WriteLine($"Modified existing wire! ({modify}) -> ({modifiedWire})\n{modifyTransaction}\n");
                        }
                    }
                    else
                    {
                        // Here we should remove the wire completely
                        var deleteTransaction = editor.Scene.Wires.CreateRemoveWireTransaction(modify);
                        editor.Scene.PushTransaction(deleteTransaction);
                        //Console.WriteLine($"Deleted wire! ({modify})\n{deleteTransaction}\n");
                    }
                }
                else
                {
                    var transaction = editor.Scene.Wires.CreateAddWireTransaction(CurrentWire);
                    if (transaction != null)
                    {
                        editor.Scene.PushTransaction(transaction);
                        //Console.WriteLine($"End wire!\n{transaction}\n");
                    }
                    else
                    {
                        //Console.WriteLine($"No wire created!\n");
                    }
                }
            }
            else
            {
                //Console.WriteLine($"Zero length wire!\n\n");
            }

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 9
0
        public override void GestureUpdate(CircuitEditor editor, Vector2d offset)
        {
            VisualPosition = StartPosition + editor.RoundDistToGrid(offset);

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 10
0
        public override void GestureEnd(CircuitEditor editor, Vector2d endOffset)
        {
            SelectionSize = editor.RoundDistToGrid(endOffset);
            Selecting     = false;

            // Make sure we don't have a negitive size

            if (SelectionSize.X < 0)
            {
                SelectionSize.X   = -SelectionSize.X;
                SelectionStart.X -= SelectionSize.X;
            }

            if (SelectionSize.Y < 0)
            {
                SelectionSize.Y   = -SelectionSize.Y;
                SelectionStart.Y -= SelectionSize.Y;
            }

            if (Poking)
            {
                Poking = false;
                LogikUI.Simulation.ReleaseComponent(SelectedGates[0].ID);
            }

            // FIXME: Do the selecting
            var wires = editor.Scene.Wires;

            // If the size is zero we want to check if we clicked a wire or gate
            if (SelectionSize == Vector2i.Zero)
            {
                ClearSelection(editor);

                bool foundGate = false;
                var  pos       = editor.FromGridToWorld(SelectionStart);
                foreach (var instance in editor.Scene.Gates.Instances)
                {
                    Rect r = editor.Scene.Gates.GetBounds(instance);
                    r = r.Rotate(instance.Position * CircuitEditor.DotSpacing, instance.Orientation);

                    if (r.Contains(pos))
                    {
                        SelectedGates.Add(instance);
                        break;
                    }
                }

                if (foundGate == false)
                {
                    foreach (var wire in wires.WiresList)
                    {
                        if (wire.IsPointOnWire(SelectionStart))
                        {
                            SelectedWires.Add(wire);
                            foundGate = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                ClearSelection(editor);

                // Here we should loop through all wires and see if they are contained in the area
                Recti selectionRect = new Recti(SelectionStart, SelectionSize);

                foreach (var wire in wires.WiresList)
                {
                    if (selectionRect.Contains(wire.Pos) &&
                        selectionRect.Contains(wire.EndPos))
                    {
                        SelectedWires.Add(wire);
                        Console.WriteLine($"Selected wire: {wire}");
                    }
                }

                Rect worldRect = editor.FromGridToWorld(selectionRect);
                foreach (var instance in editor.Scene.Gates.Instances)
                {
                    Rect r = editor.Scene.Gates.GetBounds(instance);
                    r = r.Rotate(instance.Position * CircuitEditor.DotSpacing, instance.Orientation);

                    if (worldRect.Contains(r))
                    {
                        SelectedGates.Add(instance);
                    }
                }
            }

            editor.DrawingArea.QueueDraw();
        }
Exemplo n.º 11
0
 public override void GestureUpdate(CircuitEditor editor, Vector2d offset)
 {
     SelectionSize = editor.RoundDistToGrid(offset);
     editor.DrawingArea.QueueDraw();
 }