Search in sources :

Example 46 with Direction

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

the class Button method computeTextField.

private void computeTextField(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
    Bounds bds = instance.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y = bds.getY() + bds.getHeight() / 2;
    int halign = GraphicsUtil.H_CENTER;
    int valign = GraphicsUtil.V_CENTER;
    if (labelLoc == Io.LABEL_CENTER) {
        x = bds.getX() + (bds.getWidth() - DEPTH) / 2;
        y = bds.getY() + (bds.getHeight() - DEPTH) / 2;
    } else if (labelLoc == Direction.NORTH) {
        y = bds.getY() - 2;
        valign = GraphicsUtil.V_BOTTOM;
    } else if (labelLoc == Direction.SOUTH) {
        y = bds.getY() + bds.getHeight() + 2;
        valign = GraphicsUtil.V_TOP;
    } else if (labelLoc == Direction.EAST) {
        x = bds.getX() + bds.getWidth() + 2;
        halign = GraphicsUtil.H_LEFT;
    } else if (labelLoc == Direction.WEST) {
        x = bds.getX() - 2;
        halign = GraphicsUtil.H_RIGHT;
    }
    if (labelLoc == facing) {
        if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
            x += 2;
            halign = GraphicsUtil.H_LEFT;
        } else {
            y -= 2;
            valign = GraphicsUtil.V_BOTTOM;
        }
    }
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 47 with Direction

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

the class DipSwitch method computeTextField.

private void computeTextField(Instance instance) {
    Direction facing = Direction.NORTH;
    Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
    Bounds bds = instance.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y = bds.getY() + bds.getHeight() / 2;
    int halign = GraphicsUtil.H_CENTER;
    int valign = GraphicsUtil.V_CENTER;
    if (labelLoc == Direction.NORTH) {
        y = bds.getY() - 2;
        valign = GraphicsUtil.V_BOTTOM;
    } else if (labelLoc == Direction.SOUTH) {
        y = bds.getY() + bds.getHeight() + 2;
        valign = GraphicsUtil.V_TOP;
    } else if (labelLoc == Direction.EAST) {
        x = bds.getX() + bds.getWidth() + 2;
        halign = GraphicsUtil.H_LEFT;
    } else if (labelLoc == Direction.WEST) {
        x = bds.getX() - 2;
        halign = GraphicsUtil.H_RIGHT;
    }
    if (labelLoc == facing) {
        if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
            x += 2;
            halign = GraphicsUtil.H_LEFT;
        } else {
            y -= 2;
            valign = GraphicsUtil.V_BOTTOM;
        }
    }
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 48 with Direction

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

the class NotGate method configurePorts.

private void configurePorts(Instance instance) {
    Object size = instance.getAttributeValue(ATTR_SIZE);
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    int dx = size == SIZE_NARROW ? -20 : -30;
    Port[] ports = new Port[2];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    Location out = Location.create(0, 0).translate(facing, dx);
    ports[1] = new Port(out.getX(), out.getY(), Port.INPUT, StdAttr.WIDTH);
    instance.setPorts(ports);
}
Also used : Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 49 with Direction

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

the class PainterShaped method getInputLineLengths.

private static int[] getInputLineLengths(GateAttributes attrs, AbstractGate factory) {
    int inputs = attrs.inputs;
    int mainHeight = ((Integer) attrs.size.getValue()).intValue();
    Integer key = Integer.valueOf(inputs * 31 + mainHeight);
    Object ret = INPUT_LENGTHS.get(key);
    if (ret != null) {
        return (int[]) ret;
    }
    Direction facing = attrs.facing;
    if (facing != Direction.EAST) {
        attrs = (GateAttributes) attrs.clone();
        attrs.facing = Direction.EAST;
    }
    int[] lengths = new int[inputs];
    INPUT_LENGTHS.put(key, lengths);
    int width = mainHeight;
    Location loc0 = OrGate.FACTORY.getInputOffset(attrs, 0);
    Location locn = OrGate.FACTORY.getInputOffset(attrs, inputs - 1);
    int totalHeight = 10 + loc0.manhattanDistanceTo(locn);
    if (totalHeight < width)
        totalHeight = width;
    GeneralPath path = computeShield(width, totalHeight);
    for (int i = 0; i < inputs; i++) {
        Location loci = OrGate.FACTORY.getInputOffset(attrs, i);
        Point2D p = new Point2D.Float(loci.getX() + 1, loci.getY());
        int iters = 0;
        while (path.contains(p) && iters < 15) {
            iters++;
            p.setLocation(p.getX() + 1, p.getY());
        }
        if (iters >= 15)
            iters = 0;
        lengths[i] = iters;
    }
    /*
		 * used prior to 2.5.1, when moved to GeneralPath int wingHeight =
		 * (totalHeight - mainHeight) / 2; double wingCenterX = wingHeight *
		 * Math.sqrt(3) / 2; double mainCenterX = mainHeight * Math.sqrt(3) / 2;
		 * 
		 * for (int i = 0; i < inputs; i++) { Location loci =
		 * factory.getInputOffset(attrs, i); int disti = 5 +
		 * loc0.manhattanDistanceTo(loci); if (disti > totalHeight - disti) { //
		 * ensure on top half disti = totalHeight - disti; } double dx; if
		 * (disti < wingHeight) { // point is on wing int dy = wingHeight / 2 -
		 * disti; dx = Math.sqrt(wingHeight * wingHeight - dy * dy) -
		 * wingCenterX; } else { // point is on main shield int dy = totalHeight
		 * / 2 - disti; dx = Math.sqrt(mainHeight * mainHeight - dy * dy) -
		 * mainCenterX; } lengths[i] = (int) (dx - 0.5); }
		 */
    return lengths;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 50 with Direction

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

the class SubcircuitFactory method computePorts.

void computePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Map<Location, Instance> portLocs = source.getAppearance().getPortOffsets(facing);
    Port[] ports = new Port[portLocs.size()];
    Instance[] pins = new Instance[portLocs.size()];
    int i = -1;
    for (Map.Entry<Location, Instance> portLoc : portLocs.entrySet()) {
        i++;
        Location loc = portLoc.getKey();
        Instance pin = portLoc.getValue();
        String type = Pin.FACTORY.isInputPin(pin) ? Port.INPUT : Port.OUTPUT;
        BitWidth width = pin.getAttributeValue(StdAttr.WIDTH);
        ports[i] = new Port(loc.getX(), loc.getY(), type, width);
        pins[i] = pin;
        String label = pin.getAttributeValue(StdAttr.LABEL);
        if (label != null && label.length() > 0) {
            ports[i].setToolTip(StringUtil.constantGetter(label));
        }
    }
    CircuitAttributes attrs = (CircuitAttributes) instance.getAttributeSet();
    attrs.setPinInstances(pins);
    instance.setPorts(ports);
    instance.recomputeBounds();
    // since this affects the circuit's bounds
    configureLabel(instance);
}
Also used : Instance(com.cburch.logisim.instance.Instance) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) BitWidth(com.cburch.logisim.data.BitWidth) HashMap(java.util.HashMap) Map(java.util.Map) 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