Search in sources :

Example 21 with Direction

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

the class AppearanceSvgReader method createShape.

public static AbstractCanvasObject createShape(Element elt, Map<Location, Instance> pins) {
    String name = elt.getTagName();
    if (name.equals("circ-anchor") || name.equals("circ-origin")) {
        Location loc = getLocation(elt);
        AbstractCanvasObject ret = new AppearanceAnchor(loc);
        if (elt.hasAttribute("facing")) {
            Direction facing = Direction.parse(elt.getAttribute("facing"));
            ret.setValue(AppearanceAnchor.FACING, facing);
        }
        return ret;
    } else if (name.equals("circ-port")) {
        Location loc = getLocation(elt);
        String[] pinStr = elt.getAttribute("pin").split(",");
        Location pinLoc = Location.create(Integer.parseInt(pinStr[0].trim()), Integer.parseInt(pinStr[1].trim()));
        Instance pin = pins.get(pinLoc);
        if (pin == null) {
            return null;
        } else {
            return new AppearancePort(loc, pin);
        }
    } else {
        return SvgReader.createShape(elt);
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 22 with Direction

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

the class SplitterAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    if (attr == StdAttr.FACING) {
        Direction NewFacing = (Direction) value;
        if (facing.equals(NewFacing))
            return;
        facing = (Direction) value;
        configureOptions();
        parameters = null;
    } else if (attr == ATTR_FANOUT) {
        int newValue = ((Integer) value).intValue();
        byte[] bits = bit_end;
        for (int i = 0; i < bits.length; i++) {
            if (bits[i] >= newValue)
                bits[i] = (byte) (newValue - 1);
        }
        if (fanout == (byte) newValue)
            return;
        fanout = (byte) newValue;
        configureOptions();
        configureDefaults();
        parameters = null;
    } else if (attr == ATTR_WIDTH) {
        BitWidth width = (BitWidth) value;
        if (bit_end.length == width.getWidth())
            return;
        bit_end = new byte[width.getWidth()];
        configureOptions();
        configureDefaults();
    } else if (attr == ATTR_APPEARANCE) {
        AttributeOption appearance = (AttributeOption) value;
        if (appear.equals(appearance))
            return;
        appear = appearance;
        parameters = null;
    } else if (attr instanceof BitOutAttribute) {
        BitOutAttribute bitOutAttr = (BitOutAttribute) attr;
        int val;
        if (value instanceof Integer) {
            val = ((Integer) value).intValue();
        } else {
            val = ((BitOutOption) value).value + 1;
        }
        if (val >= 0 && val <= fanout) {
            if (bit_end[bitOutAttr.which] == (byte) val)
                return;
            bit_end[bitOutAttr.which] = (byte) val;
        } else
            return;
    } else {
        throw new IllegalArgumentException("unknown attribute " + attr);
    }
    fireAttributeValueChanged(attr, value, null);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction) AttributeOption(com.cburch.logisim.data.AttributeOption)

Example 23 with Direction

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

the class BitSelector method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Plexers.drawTrapezoid(g, painter.getBounds(), facing, 9);
    Bounds bds = painter.getBounds();
    g.setColor(Color.BLACK);
    GraphicsUtil.drawCenteredText(g, "Sel", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 24 with Direction

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

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

the class BitSelector method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    Bounds base = Bounds.create(-30, -15, 30, 30);
    return base.rotate(Direction.EAST, facing, 0, 0);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

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