Search in sources :

Example 46 with Location

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

the class BitSelector method updatePorts.

private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    BitWidth group = instance.getAttributeValue(GROUP_ATTR);
    int groups = (data.getWidth() + group.getWidth() - 1) / group.getWidth() - 1;
    int selectBits = 1;
    if (groups > 0) {
        while (groups != 1) {
            groups >>= 1;
            selectBits++;
        }
    }
    BitWidth select = BitWidth.create(selectBits);
    Location inPt;
    Location selPt;
    if (facing == Direction.WEST) {
        inPt = Location.create(30, 0);
        selPt = Location.create(10, 10);
    } else if (facing == Direction.NORTH) {
        inPt = Location.create(0, 30);
        selPt = Location.create(-10, 10);
    } else if (facing == Direction.SOUTH) {
        inPt = Location.create(0, -30);
        selPt = Location.create(-10, -10);
    } else {
        inPt = Location.create(-30, 0);
        selPt = Location.create(-10, 10);
    }
    Port[] ps = new Port[3];
    ps[0] = new Port(0, 0, Port.OUTPUT, group.getWidth());
    ps[1] = new Port(inPt.getX(), inPt.getY(), Port.INPUT, data.getWidth());
    ps[2] = new Port(selPt.getX(), selPt.getY(), Port.INPUT, select.getWidth());
    ps[0].setToolTip(Strings.getter("bitSelectorOutputTip"));
    ps[1].setToolTip(Strings.getter("bitSelectorDataTip"));
    ps[2].setToolTip(Strings.getter("bitSelectorSelectTip"));
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 47 with Location

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

the class Decoder method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
    int outputs = 1 << select.getWidth();
    // draw stubs for select and enable ports
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) {
        // draw select wire
        if (painter.getShowState()) {
            g.setColor(painter.getPortValue(outputs).getColor());
        }
        Location pt = painter.getInstance().getPortLocation(outputs);
        g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
    }
    if (enable) {
        Location en = painter.getInstance().getPortLocation(outputs + 1);
        int len = outputs == 2 ? 6 : 4;
        if (painter.getShowState()) {
            g.setColor(painter.getPortValue(outputs + 1).getColor());
        }
        g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
    // draw "0"
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
        x0 = 3;
        y0 = 15 + (outputs == 2 ? 5 : 0);
        halign = GraphicsUtil.H_LEFT;
    } else if (facing == Direction.NORTH) {
        x0 = 10 + (outputs == 2 ? 5 : 0);
        y0 = 15;
        halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
        x0 = 10 + (outputs == 2 ? 5 : 0);
        y0 = bds.getHeight() - 3;
        halign = GraphicsUtil.H_CENTER;
    } else {
        x0 = bds.getWidth() - 3;
        y0 = 15 + (outputs == 2 ? 5 : 0);
        halign = GraphicsUtil.H_RIGHT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0, halign, GraphicsUtil.V_BASELINE);
    // draw trapezoid, "Decd", and ports
    g.setColor(Color.BLACK);
    if (outputs == 2) {
        if (facing == Direction.EAST || facing == Direction.WEST) {
            Plexers.drawTrapezoid(g, Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing.reverse(), 10);
        } else {
            Plexers.drawTrapezoid(g, Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing.reverse(), 10);
        }
    } else {
        Plexers.drawTrapezoid(g, bds, facing.reverse(), 20);
    }
    GraphicsUtil.drawCenteredText(g, "Decd", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 48 with Location

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

the class Pin method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    boolean output = attrs.isOutput();
    if (output) {
        BitWidth width = attrs.getValue(StdAttr.WIDTH);
        if (width == BitWidth.ONE) {
            g.drawOval(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
        } else {
            g.drawRoundRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1, 6, 6);
        }
    } else {
        g.drawRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
    }
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Example 49 with Location

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

the class Demultiplexer method updatePorts.

private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Port[] ps = new Port[outputs + (enable ? 3 : 2)];
    Location sel;
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    if (outputs == 2) {
        Location end0;
        Location end1;
        if (facing == Direction.WEST) {
            end0 = Location.create(-30, -10);
            end1 = Location.create(-30, 10);
            sel = Location.create(-20, selMult * 20);
        } else if (facing == Direction.NORTH) {
            end0 = Location.create(-10, -30);
            end1 = Location.create(10, -30);
            sel = Location.create(selMult * -20, -20);
        } else if (facing == Direction.SOUTH) {
            end0 = Location.create(-10, 30);
            end1 = Location.create(10, 30);
            sel = Location.create(selMult * -20, 20);
        } else {
            end0 = Location.create(30, -10);
            end1 = Location.create(30, 10);
            sel = Location.create(20, selMult * 20);
        }
        ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, data.getWidth());
        ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, data.getWidth());
    } else {
        int dx = -(outputs / 2) * 10;
        int ddx = 10;
        int dy = dx;
        int ddy = 10;
        if (facing == Direction.WEST) {
            dx = -40;
            ddx = 0;
            sel = Location.create(-20, selMult * (dy + 10 * outputs));
        } else if (facing == Direction.NORTH) {
            dy = -40;
            ddy = 0;
            sel = Location.create(selMult * dx, -20);
        } else if (facing == Direction.SOUTH) {
            dy = 40;
            ddy = 0;
            sel = Location.create(selMult * dx, 20);
        } else {
            dx = 40;
            ddx = 0;
            sel = Location.create(20, selMult * (dy + 10 * outputs));
        }
        for (int i = 0; i < outputs; i++) {
            ps[i] = new Port(dx, dy, Port.OUTPUT, data.getWidth());
            dx += ddx;
            dy += ddy;
        }
    }
    Location en = sel.translate(facing, -10);
    ps[outputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
    if (enable) {
        ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    ps[ps.length - 1] = new Port(0, 0, Port.INPUT, data.getWidth());
    for (int i = 0; i < outputs; i++) {
        ps[i].setToolTip(Strings.getter("demultiplexerOutTip", "" + i));
    }
    ps[outputs].setToolTip(Strings.getter("demultiplexerSelectTip"));
    if (enable) {
        ps[outputs + 1].setToolTip(Strings.getter("demultiplexerEnableTip"));
    }
    ps[ps.length - 1].setToolTip(Strings.getter("demultiplexerInTip"));
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 50 with Location

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

the class CurveTool method updateMouse.

private Curve updateMouse(Canvas canvas, int mx, int my, int mods) {
    lastMouseX = mx;
    lastMouseY = my;
    boolean shiftDown = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
    boolean ctrlDown = (mods & MouseEvent.CTRL_DOWN_MASK) != 0;
    boolean altDown = (mods & MouseEvent.ALT_DOWN_MASK) != 0;
    Curve ret = null;
    switch(state) {
        case ENDPOINT_DRAG:
            if (mouseDown) {
                if (shiftDown) {
                    Location p = LineUtil.snapTo8Cardinals(end0, mx, my);
                    mx = p.getX();
                    my = p.getY();
                }
                if (ctrlDown) {
                    mx = canvas.snapX(mx);
                    my = canvas.snapY(my);
                }
                end1 = Location.create(mx, my);
            }
            break;
        case CONTROL_DRAG:
            if (mouseDown) {
                int cx = mx;
                int cy = my;
                if (ctrlDown) {
                    cx = canvas.snapX(cx);
                    cy = canvas.snapY(cy);
                }
                if (shiftDown) {
                    double x0 = end0.getX();
                    double y0 = end0.getY();
                    double x1 = end1.getX();
                    double y1 = end1.getY();
                    double midx = (x0 + x1) / 2;
                    double midy = (y0 + y1) / 2;
                    double dx = x1 - x0;
                    double dy = y1 - y0;
                    double[] p = LineUtil.nearestPointInfinite(cx, cy, midx, midy, midx - dy, midy + dx);
                    cx = (int) Math.round(p[0]);
                    cy = (int) Math.round(p[1]);
                }
                if (altDown) {
                    double[] e0 = { end0.getX(), end0.getY() };
                    double[] e1 = { end1.getX(), end1.getY() };
                    double[] mid = { cx, cy };
                    double[] ct = CurveUtil.interpolate(e0, e1, mid);
                    cx = (int) Math.round(ct[0]);
                    cy = (int) Math.round(ct[1]);
                }
                ret = new Curve(end0, end1, Location.create(cx, cy));
                curCurve = ret;
            }
            break;
        default:
            break;
    }
    return ret;
}
Also used : Curve(com.cburch.draw.shapes.Curve) 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