Exemplo n.º 1
0
    public override void Execute(Editor arg)
    {
        Edge <WireNode> onEdge = Util.GetEdgeFromPos(arg.Simulator, this.endPos, out Wire wire);

        this.sourcePos = onEdge.Source.GetPosition();
        this.targetPos = onEdge.Target.GetPosition();

        WireNode newJunc = wire.CreateJunctionWireNode(this.endPos);

        wire.InsertNodeBetween(onEdge.Source, onEdge.Target, newJunc);

        IOWireNode ioNode = wire.CreateIOWireNode(this.startIO);

        if (IsCornerNeeded())
        {
            // INCLUDE CORNER
            JunctionWireNode cornerNode = wire.CreateJunctionWireNode(this.corner);
            wire.ConnectNodes(newJunc, wire, cornerNode);
            wire.ConnectNodes(cornerNode, wire, ioNode);
        }
        else
        {
            // NO CORNER
            wire.ConnectNodes(newJunc, wire, ioNode);
        }
    }
    public override void Undo(Editor arg)
    {
        WireNode junctionNode = Util.GetWireNodeFromPos(arg.Simulator, this.junctionPosition, out Wire wire);

        if (this.IsCornerNeeded())
        {
            // CORNER IS INCLUDED
            WireNode corner = Util.GetWireNodeFromPos(arg.Simulator, this.corner, out Wire cornerWire);
            cornerWire.RemoveNode(corner);
        }

        // REMOVE START NODE IOWIRENODE
        IOWireNode startNode = Util.GetIOWireNodeFromPos(arg.Simulator, this.startIO.GetPosition(), out Wire startWire);

        startWire.RemoveNode(startNode);
    }