Search in sources :

Example 51 with Direction

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

the class SubcircuitFactory method configureLabel.

private void configureLabel(Instance instance) {
    Bounds bds = instance.getBounds();
    Direction loc = instance.getAttributeValue(CircuitAttributes.LABEL_LOCATION_ATTR);
    int x = bds.getX() + bds.getWidth() / 2;
    int y = bds.getY() + bds.getHeight() / 2;
    int ha = GraphicsUtil.H_CENTER;
    int va = GraphicsUtil.V_CENTER;
    if (loc == Direction.EAST) {
        x = bds.getX() + bds.getWidth() + 2;
        ha = GraphicsUtil.H_LEFT;
    } else if (loc == Direction.WEST) {
        x = bds.getX() - 2;
        ha = GraphicsUtil.H_RIGHT;
    } else if (loc == Direction.SOUTH) {
        y = bds.getY() + bds.getHeight() + 2;
        va = GraphicsUtil.V_TOP;
    } else {
        y = bds.getY() - 2;
        va = GraphicsUtil.V_BASELINE;
    }
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, ha, va);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 52 with Direction

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

the class SubcircuitFactory method contains.

/**
 * Code taken from Cornell's version of Logisim:
 * http://www.cs.cornell.edu/courses/cs3410/2015sp/
 */
@Override
public boolean contains(Location loc, AttributeSet attrs) {
    if (super.contains(loc, attrs)) {
        Direction facing = attrs.getValue(StdAttr.FACING);
        Direction defaultFacing = source.getAppearance().getFacing();
        Location query;
        if (facing.equals(defaultFacing)) {
            query = loc;
        } else {
            query = loc.rotate(facing, defaultFacing, 0, 0);
        }
        return source.getAppearance().contains(query);
    } else {
        return false;
    }
}
Also used : Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 53 with Direction

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

the class SubcircuitFactory method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    Direction defaultFacing = source.getAppearance().getFacing();
    Bounds bds = source.getAppearance().getOffsetBounds();
    return bds.rotate(defaultFacing, facing, 0, 0);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 54 with Direction

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

the class PortManager method computeDefaultLocation.

private static Location computeDefaultLocation(CircuitAppearance appear, Instance pin, Map<Instance, AppearancePort> others) {
    // Determine which locations are being used in canvas, and look for
    // which instances facing the same way in layout
    Set<Location> usedLocs = new HashSet<Location>();
    List<Instance> sameWay = new ArrayList<Instance>();
    Direction facing = pin.getAttributeValue(StdAttr.FACING);
    for (Map.Entry<Instance, AppearancePort> entry : others.entrySet()) {
        Instance pin2 = entry.getKey();
        Location loc = entry.getValue().getLocation();
        usedLocs.add(loc);
        if (pin2.getAttributeValue(StdAttr.FACING) == facing) {
            sameWay.add(pin2);
        }
    }
    // if at least one faces the same way, place pin relative to that
    if (sameWay.size() > 0) {
        sameWay.add(pin);
        DefaultAppearance.sortPinList(sameWay, facing);
        boolean isFirst = false;
        // (preferably previous in map)
        Instance neighbor = null;
        for (Instance p : sameWay) {
            if (p == pin) {
                break;
            } else {
                neighbor = p;
            }
        }
        if (neighbor == null) {
            // pin must have been first in list
            neighbor = sameWay.get(1);
        }
        int dx;
        int dy;
        if (facing == Direction.EAST || facing == Direction.WEST) {
            dx = 0;
            dy = isFirst ? -10 : 10;
        } else {
            dx = isFirst ? -10 : 10;
            dy = 0;
        }
        Location loc = others.get(neighbor).getLocation();
        do {
            loc = loc.translate(dx, dy);
        } while (usedLocs.contains(loc));
        if (loc.getX() >= 0 && loc.getY() >= 0) {
            return loc;
        }
        do {
            loc = loc.translate(-dx, -dy);
        } while (usedLocs.contains(loc));
        return loc;
    }
    // otherwise place it on the boundary of the bounding rectangle
    Bounds bds = appear.getAbsoluteBounds();
    int x;
    int y;
    int dx = 0;
    int dy = 0;
    if (facing == Direction.EAST) {
        // on west side by default
        x = bds.getX() - 7;
        y = bds.getY() + 5;
        dy = 10;
    } else if (facing == Direction.WEST) {
        // on east side by default
        x = bds.getX() + bds.getWidth() - 3;
        y = bds.getY() + 5;
        dy = 10;
    } else if (facing == Direction.SOUTH) {
        // on north side by default
        x = bds.getX() + 5;
        y = bds.getY() - 7;
        dx = 10;
    } else {
        // on south side by default
        x = bds.getX() + 5;
        y = bds.getY() + bds.getHeight() - 3;
        dx = 10;
    }
    // round coordinates up to ensure they're on grid
    x = (x + 9) / 10 * 10;
    y = (y + 9) / 10 * 10;
    Location loc = Location.create(x, y);
    while (usedLocs.contains(loc)) {
        loc = loc.translate(dx, dy);
    }
    return loc;
}
Also used : Instance(com.cburch.logisim.instance.Instance) Bounds(com.cburch.logisim.data.Bounds) ArrayList(java.util.ArrayList) Direction(com.cburch.logisim.data.Direction) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.cburch.logisim.data.Location) HashSet(java.util.HashSet)

Example 55 with Direction

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

the class Splitter method contains.

@Override
public boolean contains(Location loc) {
    if (super.contains(loc)) {
        Location myLoc = getLocation();
        Direction facing = getAttributeSet().getValue(StdAttr.FACING);
        if (facing == Direction.EAST || facing == Direction.WEST) {
            return Math.abs(loc.getX() - myLoc.getX()) > 5 || loc.manhattanDistanceTo(myLoc) <= 5;
        } else {
            return Math.abs(loc.getY() - myLoc.getY()) > 5 || loc.manhattanDistanceTo(myLoc) <= 5;
        }
    } else {
        return false;
    }
}
Also used : 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