Search in sources :

Example 66 with Location

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

the class ControlledBuffer method configurePorts.

private void configurePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Bounds bds = getOffsetBounds(instance.getAttributeSet());
    int d = Math.max(bds.getWidth(), bds.getHeight()) - 20;
    Location loc0 = Location.create(0, 0);
    Location loc1 = loc0.translate(facing.reverse(), 20 + d);
    Location loc2;
    if (instance.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
        loc2 = loc0.translate(facing.reverse(), 10 + d, 10);
    } else {
        loc2 = loc0.translate(facing.reverse(), 10 + d, -10);
    }
    Port[] ports = new Port[3];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    ports[1] = new Port(loc1.getX(), loc1.getY(), Port.INPUT, StdAttr.WIDTH);
    ports[2] = new Port(loc2.getX(), loc2.getY(), Port.INPUT, 1);
    instance.setPorts(ports);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 67 with Location

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

the class ControlledBuffer method paintShape.

private void paintShape(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    double rotate = 0.0;
    Graphics g = painter.getGraphics();
    g.translate(x, y);
    if (facing != Direction.EAST && g instanceof Graphics2D) {
        rotate = -facing.toRadians();
        ((Graphics2D) g).rotate(rotate);
    }
    if (isInverter) {
        PainterShaped.paintNot(painter);
    } else {
        GraphicsUtil.switchToWidth(g, 2);
        int d = isInverter ? 10 : 0;
        int[] xp = new int[] { -d, -19 - d, -19 - d, -d };
        int[] yp = new int[] { 0, -7, 7, 0 };
        g.drawPolyline(xp, yp, 4);
    // if (isInverter) g.drawOval(-9, -4, 9, 9);
    }
    if (rotate != 0.0) {
        ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-x, -y);
}
Also used : Graphics(java.awt.Graphics) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location) Graphics2D(java.awt.Graphics2D)

Example 68 with Location

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

the class PortHDLGeneratorFactory method findEndConnection.

private Location findEndConnection(Location start, Circuit circ) {
    Location newLoc = start;
    Collection<Wire> wiresCol = circ.getWires(newLoc);
    Iterator<Wire> wires = wiresCol.iterator();
    if (wiresCol.size() != 1) {
        return null;
    }
    Wire net = null;
    Wire oldNet = null;
    while (wires.hasNext()) {
        net = wires.next();
        if (net != oldNet) {
            newLoc = net.getEnd0().equals(newLoc) ? net.getEnd1() : net.getEnd0();
            wiresCol = circ.getWires(newLoc);
            wires = wiresCol.iterator();
            oldNet = net;
        }
    }
    return newLoc;
}
Also used : Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 69 with Location

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

the class AbstractFlipFlop method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    painter.drawLabel();
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    GraphicsUtil.switchToWidth(g, 2);
    g.drawRect(x, y, 40, 60);
    if (painter.getShowState()) {
        StateData myState = (StateData) painter.getData();
        if (myState != null) {
            g.setColor(myState.curValue.getColor());
            g.fillOval(x + 13, y + 23, 14, 14);
            g.setColor(Color.WHITE);
            GraphicsUtil.drawCenteredText(g, myState.curValue.toDisplayString(), x + 21, y + 29);
            g.setColor(Color.BLACK);
        }
    }
    int n = getPorts().size() - STD_PORTS;
    g.setColor(Color.GRAY);
    painter.drawPort(n + 3, "R", Direction.SOUTH);
    painter.drawPort(n + 4, "S", Direction.NORTH);
    g.setColor(Color.BLACK);
    for (int i = 0; i < n; i++) {
        g.fillRect(x - 10, y + 9 + i * 20, 10, 3);
        painter.drawPort(i);
        GraphicsUtil.drawCenteredText(g, getInputName(i), x + 8, y + 10 + i * 20);
    }
    Object Trigger = painter.getAttributeValue(triggerAttribute);
    if (Trigger.equals(StdAttr.TRIG_RISING) || Trigger.equals(StdAttr.TRIG_FALLING)) {
        painter.drawClockSymbol(x, y + 50);
    } else {
        GraphicsUtil.drawCenteredText(g, "E", x + 8, y + 50);
    }
    if (Trigger.equals(StdAttr.TRIG_RISING) || Trigger.equals(StdAttr.TRIG_HIGH)) {
        g.fillRect(x - 10, y + 49, 10, 3);
    } else {
        GraphicsUtil.switchToWidth(g, 2);
        g.drawOval(x - 10, y + 45, 10, 10);
        GraphicsUtil.switchToWidth(g, 1);
    }
    painter.drawPort(n);
    g.fillRect(x + 40, y + 9, 10, 3);
    GraphicsUtil.drawCenteredText(g, "Q", x + 31, y + 10);
    painter.drawPort(n + 1);
    GraphicsUtil.switchToWidth(g, 2);
    g.drawOval(x + 40, y + 45, 10, 10);
    GraphicsUtil.switchToWidth(g, 1);
    painter.drawPort(n + 2);
}
Also used : Graphics(java.awt.Graphics) Location(com.cburch.logisim.data.Location)

Example 70 with Location

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

the class Button method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    int x = bds.getX();
    int y = bds.getY();
    int w = bds.getWidth();
    int h = bds.getHeight();
    Value val;
    if (painter.getShowState()) {
        InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
        val = data == null ? Value.FALSE : (Value) data.getValue();
    } else {
        val = Value.FALSE;
    }
    Color color = painter.getAttributeValue(Io.ATTR_COLOR);
    if (!painter.shouldDrawColor()) {
        int hue = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
        color = new Color(hue, hue, hue);
    }
    Graphics g = painter.getGraphics();
    int depress;
    if (val == Value.TRUE) {
        x += DEPTH;
        y += DEPTH;
        Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC);
        if (labelLoc == Io.LABEL_CENTER || labelLoc == Direction.NORTH || labelLoc == Direction.WEST) {
            depress = DEPTH;
        } else {
            depress = 0;
        }
        Object facing = painter.getAttributeValue(StdAttr.FACING);
        if (facing == Direction.NORTH || facing == Direction.WEST) {
            Location p = painter.getLocation();
            int px = p.getX();
            int py = p.getY();
            GraphicsUtil.switchToWidth(g, Wire.WIDTH);
            g.setColor(Value.TRUE_COLOR);
            if (facing == Direction.NORTH)
                g.drawLine(px, py, px, py + 10);
            else
                g.drawLine(px, py, px + 10, py);
            GraphicsUtil.switchToWidth(g, 1);
        }
        g.setColor(color);
        g.fillRect(x, y, w - DEPTH, h - DEPTH);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, w - DEPTH, h - DEPTH);
    } else {
        depress = 0;
        int[] xp = new int[] { x, x + w - DEPTH, x + w, x + w, x + DEPTH, x };
        int[] yp = new int[] { y, y, y + DEPTH, y + h, y + h, y + h - DEPTH };
        g.setColor(color.darker());
        g.fillPolygon(xp, yp, xp.length);
        g.setColor(color);
        g.fillRect(x, y, w - DEPTH, h - DEPTH);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, w - DEPTH, h - DEPTH);
        g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
        g.drawPolygon(xp, yp, xp.length);
    }
    g.translate(depress, depress);
    painter.drawLabel();
    g.translate(-depress, -depress);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton) 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