Search in sources :

Example 31 with Direction

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

the class Pin method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    BitWidth width = attrs.getValue(StdAttr.WIDTH);
    return Probe.getOffsetBounds(facing, width, attrs.getValue(RadixOption.ATTRIBUTE));
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction)

Example 32 with Direction

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

the class Pin method paintIconBase.

private void paintIconBase(InstancePainter painter) {
    PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
    Direction dir = attrs.facing;
    boolean output = attrs.isOutput();
    Graphics g = painter.getGraphics();
    if (output) {
        if (ICON_OUT != null) {
            Icons.paintRotated(g, 2, 2, dir, ICON_OUT, painter.getDestination());
            return;
        }
    } else {
        if (ICON_IN != null) {
            Icons.paintRotated(g, 2, 2, dir, ICON_IN, painter.getDestination());
            return;
        }
    }
    int pinx = 16;
    int piny = 9;
    if (dir == Direction.EAST) {
    // keep defaults
    } else if (dir == Direction.WEST) {
        pinx = 4;
    } else if (dir == Direction.NORTH) {
        pinx = 9;
        piny = 4;
    } else if (dir == Direction.SOUTH) {
        pinx = 9;
        piny = 16;
    }
    g.setColor(Color.black);
    if (output) {
        g.drawOval(4, 4, 13, 13);
    } else {
        g.drawRect(4, 4, 13, 13);
    }
    g.setColor(Value.TRUE.getColor());
    g.fillOval(7, 7, 8, 8);
    g.fillOval(pinx, piny, 3, 3);
}
Also used : Graphics(java.awt.Graphics) Direction(com.cburch.logisim.data.Direction)

Example 33 with Direction

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

the class PowerOnReset method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    java.awt.Graphics g = painter.getGraphics();
    Bounds bds = painter.getInstance().getBounds();
    int x = bds.getX();
    int y = bds.getY();
    GraphicsUtil.switchToWidth(g, 2);
    g.setColor(Color.ORANGE);
    g.fillRect(x, y, bds.getWidth(), bds.getHeight());
    g.setColor(Color.BLACK);
    g.drawRect(x, y, bds.getWidth(), bds.getHeight());
    Font old = g.getFont();
    g.setFont(old.deriveFont(18.0f).deriveFont(Font.BOLD));
    FontMetrics fm = g.getFontMetrics();
    String txt = "Power-On Reset";
    int wide = Math.max(bds.getWidth(), bds.getHeight());
    int offset = (wide - fm.stringWidth(txt)) / 2;
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    if (((facing == Direction.NORTH) || (facing == Direction.SOUTH)) && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D) g;
        int xpos = facing == Direction.NORTH ? x + 20 - fm.getDescent() : x + 20 + fm.getDescent();
        int ypos = facing == Direction.NORTH ? y + offset : y + bds.getHeight() - offset;
        g2.translate(xpos, ypos);
        g2.rotate(facing.toRadians());
        g.drawString(txt, 0, 0);
        g2.rotate(-facing.toRadians());
        g2.translate(-xpos, -ypos);
    } else {
        g.drawString(txt, x + offset, y + fm.getDescent() + 20);
    }
    painter.drawPorts();
}
Also used : FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 34 with Direction

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

the class ProbeAttributes method setValue.

@SuppressWarnings("unchecked")
@Override
public <V> void setValue(Attribute<V> attr, V value) {
    V Oldvalue = null;
    if (attr == StdAttr.FACING) {
        Direction newValue = (Direction) value;
        if (facing.equals(newValue))
            return;
        facing = (Direction) value;
    } else if (attr == StdAttr.LABEL) {
        String val = (String) value;
        // }
        if (label.equals(val))
            return;
        Oldvalue = (V) label;
        label = val;
    } else if (attr == Pin.ATTR_LABEL_LOC) {
        Direction newValue = (Direction) value;
        if (labelloc.equals(newValue))
            return;
        labelloc = newValue;
    } else if (attr == StdAttr.LABEL_FONT) {
        Font NewValue = (Font) value;
        if (labelfont.equals(NewValue))
            return;
        labelfont = NewValue;
    } else if (attr == RadixOption.ATTRIBUTE) {
        RadixOption NewValue = (RadixOption) value;
        if (radix.equals(NewValue))
            return;
        radix = NewValue;
    } else {
        throw new IllegalArgumentException("unknown attribute");
    }
    fireAttributeValueChanged(attr, value, Oldvalue);
}
Also used : Direction(com.cburch.logisim.data.Direction) Font(java.awt.Font) RadixOption(com.cburch.logisim.circuit.RadixOption)

Example 35 with Direction

use of com.cburch.logisim.data.Direction 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)

Aggregations

Direction (com.cburch.logisim.data.Direction)89 Location (com.cburch.logisim.data.Location)39 Bounds (com.cburch.logisim.data.Bounds)27 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics (java.awt.Graphics)20 Graphics2D (java.awt.Graphics2D)13 Port (com.cburch.logisim.instance.Port)10 Instance (com.cburch.logisim.instance.Instance)9 ArrayList (java.util.ArrayList)7 CanvasObject (com.cburch.draw.model.CanvasObject)5 Color (java.awt.Color)5 Font (java.awt.Font)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 AttributeSet (com.cburch.logisim.data.AttributeSet)4 FontMetrics (java.awt.FontMetrics)4 List (java.util.List)4 Wire (com.cburch.logisim.circuit.Wire)3 Attribute (com.cburch.logisim.data.Attribute)3 Value (com.cburch.logisim.data.Value)3