Search in sources :

Example 21 with Wire

use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.

the class WiringTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
    if (!exists)
        return;
    Canvas.snapToGrid(e);
    int curX = e.getX();
    int curY = e.getY();
    if (computeMove(curX, curY)) {
        cur = Location.create(curX, curY);
    }
    if (hasDragged) {
        exists = false;
        super.mouseReleased(canvas, g, e);
        ArrayList<Wire> ws = new ArrayList<Wire>(2);
        if (cur.getY() == start.getY() || cur.getX() == start.getX()) {
            Wire w = Wire.create(cur, start);
            w = checkForRepairs(canvas, w, w.getEnd0());
            w = checkForRepairs(canvas, w, w.getEnd1());
            if (performShortening(canvas, start, cur)) {
                return;
            }
            if (w.getLength() > 0)
                ws.add(w);
        } else {
            Location m;
            if (direction == HORIZONTAL) {
                m = Location.create(cur.getX(), start.getY());
            } else {
                m = Location.create(start.getX(), cur.getY());
            }
            Wire w0 = Wire.create(start, m);
            Wire w1 = Wire.create(m, cur);
            w0 = checkForRepairs(canvas, w0, start);
            w1 = checkForRepairs(canvas, w1, cur);
            if (w0.getLength() > 0)
                ws.add(w0);
            if (w1.getLength() > 0)
                ws.add(w1);
        }
        if (ws.size() > 0) {
            CircuitMutation mutation = new CircuitMutation(canvas.getCircuit());
            mutation.addAll(ws);
            StringGetter desc;
            if (ws.size() == 1)
                desc = Strings.getter("addWireAction");
            else
                desc = Strings.getter("addWiresAction");
            Action act = mutation.toAction(desc);
            canvas.getProject().doAction(act);
            lastAction = act;
        }
    }
}
Also used : Action(com.cburch.logisim.proj.Action) ArrayList(java.util.ArrayList) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Wire(com.cburch.logisim.circuit.Wire) StringGetter(com.cburch.logisim.util.StringGetter) Location(com.cburch.logisim.data.Location)

Example 22 with Wire

use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.

the class WiringTool method draw.

@Override
public void draw(Canvas canvas, ComponentDrawContext context) {
    Graphics g = context.getGraphics();
    if (exists) {
        Location e0 = start;
        Location e1 = cur;
        Wire shortenBefore = willShorten(start, cur);
        if (shortenBefore != null) {
            Wire shorten = getShortenResult(shortenBefore, start, cur);
            if (shorten == null) {
                return;
            } else {
                e0 = shorten.getEnd0();
                e1 = shorten.getEnd1();
            }
        }
        int x0 = e0.getX();
        int y0 = e0.getY();
        int x1 = e1.getX();
        int y1 = e1.getY();
        g.setColor(Color.BLACK);
        GraphicsUtil.switchToWidth(g, 3);
        if (direction == HORIZONTAL) {
            if (x0 != x1)
                g.drawLine(x0, y0, x1, y0);
            if (y0 != y1)
                g.drawLine(x1, y0, x1, y1);
        } else if (direction == VERTICAL) {
            if (y0 != y1)
                g.drawLine(x0, y0, x0, y1);
            if (x0 != x1)
                g.drawLine(x0, y1, x1, y1);
        }
    } else if (AppPreferences.ADD_SHOW_GHOSTS.getBoolean() && inCanvas) {
        g.setColor(Color.GRAY);
        g.fillOval(cur.getX() - 2, cur.getY() - 2, 5, 5);
    }
}
Also used : Graphics(java.awt.Graphics) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 23 with Wire

use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.

the class MoveGesture method computeConnections.

private static Set<ConnectionData> computeConnections(Circuit circuit, Set<Component> selected) {
    if (selected == null || selected.isEmpty())
        return Collections.emptySet();
    // first identify locations that might be connected
    Set<Location> locs = new HashSet<Location>();
    for (Component comp : selected) {
        for (EndData end : comp.getEnds()) {
            locs.add(end.getLocation());
        }
    }
    // now see which of them require connection
    Set<ConnectionData> conns = new HashSet<ConnectionData>();
    for (Location loc : locs) {
        boolean found = false;
        for (Component comp : circuit.getComponents(loc)) {
            if (!selected.contains(comp)) {
                found = true;
                break;
            }
        }
        if (found) {
            List<Wire> wirePath;
            Location wirePathStart;
            Wire lastOnPath = findWire(circuit, loc, selected, null);
            if (lastOnPath == null) {
                wirePath = Collections.emptyList();
                wirePathStart = loc;
            } else {
                wirePath = new ArrayList<Wire>();
                Location cur = loc;
                for (Wire w = lastOnPath; w != null; w = findWire(circuit, cur, selected, w)) {
                    wirePath.add(w);
                    cur = w.getOtherEnd(cur);
                }
                Collections.reverse(wirePath);
                wirePathStart = cur;
            }
            Direction dir = null;
            if (lastOnPath != null) {
                Location other = lastOnPath.getOtherEnd(loc);
                int dx = loc.getX() - other.getX();
                int dy = loc.getY() - other.getY();
                if (Math.abs(dx) > Math.abs(dy)) {
                    dir = dx > 0 ? Direction.EAST : Direction.WEST;
                } else {
                    dir = dy > 0 ? Direction.SOUTH : Direction.NORTH;
                }
            }
            conns.add(new ConnectionData(loc, dir, wirePath, wirePathStart));
        }
    }
    return conns;
}
Also used : EndData(com.cburch.logisim.comp.EndData) Wire(com.cburch.logisim.circuit.Wire) Direction(com.cburch.logisim.data.Direction) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location) HashSet(java.util.HashSet)

Example 24 with Wire

use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.

the class SimpleDRCContainer method ClearMarks.

public void ClearMarks() {
    if (!DRCInfoPresent())
        return;
    for (Object obj : DRCComponents) {
        if (obj instanceof Wire) {
            Wire wire = (Wire) obj;
            if ((MarkType & MARK_WIRE) != 0) {
                wire.SetMarked(false);
            }
        } else if (obj instanceof Splitter) {
            Splitter split = (Splitter) obj;
            if ((MarkType & MARK_INSTANCE) != 0) {
                split.SetMarked(false);
            }
        } else if (obj instanceof InstanceComponent) {
            InstanceComponent comp = (InstanceComponent) obj;
            comp.clearMarks();
        }
    }
}
Also used : Splitter(com.cburch.logisim.circuit.Splitter) Wire(com.cburch.logisim.circuit.Wire) InstanceComponent(com.cburch.logisim.instance.InstanceComponent)

Aggregations

Wire (com.cburch.logisim.circuit.Wire)24 Location (com.cburch.logisim.data.Location)13 Component (com.cburch.logisim.comp.Component)12 Circuit (com.cburch.logisim.circuit.Circuit)8 ArrayList (java.util.ArrayList)7 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)4 HashSet (java.util.HashSet)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Direction (com.cburch.logisim.data.Direction)3 EndData (com.cburch.logisim.comp.EndData)2 Bounds (com.cburch.logisim.data.Bounds)2 Selection (com.cburch.logisim.gui.main.Selection)2 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)2 Action (com.cburch.logisim.proj.Action)2 Project (com.cburch.logisim.proj.Project)2 Pin (com.cburch.logisim.std.wiring.Pin)2 StringGetter (com.cburch.logisim.util.StringGetter)2 Graphics (java.awt.Graphics)2