Search in sources :

Example 11 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class Transistor method contains.

@Override
public boolean contains(Location loc, AttributeSet attrs) {
    if (super.contains(loc, attrs)) {
        Direction facing = attrs.getValue(StdAttr.FACING);
        Location center = Location.create(0, 0).translate(facing, -20);
        return center.manhattanDistanceTo(loc) < 24;
    } else {
        return false;
    }
}
Also used : Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 12 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class Transistor method drawInstance.

private void drawInstance(InstancePainter painter, boolean isGhost) {
    Object type = painter.getAttributeValue(ATTR_TYPE);
    Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
    Direction from = painter.getAttributeValue(StdAttr.FACING);
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
    int degrees = Direction.EAST.toDegrees() - from.toDegrees();
    double radians = Math.toRadians((degrees + 360) % 360);
    int m = flip ? 1 : -1;
    Graphics2D g = (Graphics2D) painter.getGraphics();
    Location loc = painter.getLocation();
    g.translate(loc.getX(), loc.getY());
    g.rotate(radians);
    Color gate;
    Color input;
    Color output;
    Color platform;
    if (!isGhost && painter.getShowState()) {
        gate = painter.getPortValue(GATE).getColor();
        input = painter.getPortValue(INPUT).getColor();
        output = painter.getPortValue(OUTPUT).getColor();
        Value out = computeOutput(painter);
        platform = out.isUnknown() ? Value.UNKNOWN.getColor() : out.getColor();
    } else {
        Color base = g.getColor();
        gate = base;
        input = base;
        output = base;
        platform = base;
    }
    // input and output lines
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
    g.setColor(output);
    g.drawLine(0, 0, -11, 0);
    g.drawLine(-11, m * 7, -11, 0);
    g.setColor(input);
    g.drawLine(-40, 0, -29, 0);
    g.drawLine(-29, m * 7, -29, 0);
    // gate line
    g.setColor(gate);
    if (type == TYPE_P) {
        g.drawLine(-20, m * 20, -20, m * 15);
        GraphicsUtil.switchToWidth(g, 1);
        g.drawOval(-22, m * 12 - 2, 4, 4);
    } else {
        g.drawLine(-20, m * 20, -20, m * 11);
        GraphicsUtil.switchToWidth(g, 1);
    }
    // draw platforms
    // gate platform
    g.drawLine(-10, m * 10, -30, m * 10);
    g.setColor(platform);
    // input/output platform
    g.drawLine(-9, m * 8, -31, m * 8);
    // arrow (same color as platform)
    g.drawLine(-21, m * 6, -18, m * 3);
    g.drawLine(-21, 0, -18, m * 3);
    g.rotate(-radians);
    g.translate(-loc.getX(), -loc.getY());
}
Also used : Color(java.awt.Color) Value(com.cburch.logisim.data.Value) Direction(com.cburch.logisim.data.Direction) Graphics2D(java.awt.Graphics2D) Location(com.cburch.logisim.data.Location)

Example 13 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class Tunnel method configureLabel.

// 
// private methods
// 
private void configureLabel(Instance instance) {
    TunnelAttributes attrs = (TunnelAttributes) instance.getAttributeSet();
    Location loc = instance.getLocation();
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, loc.getX() + attrs.getLabelX(), loc.getY() + attrs.getLabelY(), attrs.getLabelHAlign(), attrs.getLabelVAlign());
}
Also used : Location(com.cburch.logisim.data.Location)

Example 14 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class Tunnel method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    g.translate(x, y);
    g.setColor(Color.BLACK);
    paintGhost(painter);
    g.translate(-x, -y);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Location(com.cburch.logisim.data.Location)

Example 15 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class Connector method processPath.

private static void processPath(ArrayList<Location> path, ConnectionData conn, AvoidanceMap avoid, ReplacementMap repl, Set<Location> unmarkable) {
    Iterator<Location> pathIt = path.iterator();
    Location loc0 = pathIt.next();
    if (!loc0.equals(conn.getLocation())) {
        Location pathLoc = conn.getWirePathStart();
        boolean found = loc0.equals(pathLoc);
        for (Wire w : conn.getWirePath()) {
            Location nextLoc = w.getOtherEnd(pathLoc);
            if (found) {
                // existing wire will be removed
                repl.remove(w);
                avoid.unmarkWire(w, nextLoc, unmarkable);
            } else if (w.contains(loc0)) {
                // wires after this will be
                // removed
                found = true;
                if (!loc0.equals(nextLoc)) {
                    avoid.unmarkWire(w, nextLoc, unmarkable);
                    Wire shortenedWire = Wire.create(pathLoc, loc0);
                    repl.replace(w, shortenedWire);
                    avoid.markWire(shortenedWire, 0, 0);
                }
            }
            pathLoc = nextLoc;
        }
    }
    while (pathIt.hasNext()) {
        Location loc1 = pathIt.next();
        Wire newWire = Wire.create(loc0, loc1);
        repl.add(newWire);
        avoid.markWire(newWire, 0, 0);
        loc0 = loc1;
    }
}
Also used : Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Aggregations

Location (com.cburch.logisim.data.Location)169 Direction (com.cburch.logisim.data.Direction)39 Graphics (java.awt.Graphics)35 Component (com.cburch.logisim.comp.Component)26 Bounds (com.cburch.logisim.data.Bounds)24 ArrayList (java.util.ArrayList)23 CanvasObject (com.cburch.draw.model.CanvasObject)17 BitWidth (com.cburch.logisim.data.BitWidth)16 Wire (com.cburch.logisim.circuit.Wire)13 HashMap (java.util.HashMap)10 Handle (com.cburch.draw.model.Handle)9 AttributeSet (com.cburch.logisim.data.AttributeSet)9 Value (com.cburch.logisim.data.Value)9 Instance (com.cburch.logisim.instance.Instance)9 Port (com.cburch.logisim.instance.Port)9 Color (java.awt.Color)9 Graphics2D (java.awt.Graphics2D)9 HashSet (java.util.HashSet)9 Circuit (com.cburch.logisim.circuit.Circuit)8 EndData (com.cburch.logisim.comp.EndData)7