Search in sources :

Example 41 with Location

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

the class AppearancePort method toSvgElement.

@Override
public Element toSvgElement(Document doc) {
    Location loc = getLocation();
    Location pinLoc = pin.getLocation();
    Element ret = doc.createElement("circ-port");
    int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
    ret.setAttribute("x", "" + (loc.getX() - r));
    ret.setAttribute("y", "" + (loc.getY() - r));
    ret.setAttribute("width", "" + 2 * r);
    ret.setAttribute("height", "" + 2 * r);
    ret.setAttribute("pin", "" + pinLoc.getX() + "," + pinLoc.getY());
    return ret;
}
Also used : Element(org.w3c.dom.Element) Location(com.cburch.logisim.data.Location)

Example 42 with Location

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

the class AppearancePort method getHandles.

@Override
public List<Handle> getHandles(HandleGesture gesture) {
    Location loc = getLocation();
    int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
    return UnmodifiableList.create(new Handle[] { new Handle(this, loc.translate(-r, -r)), new Handle(this, loc.translate(r, -r)), new Handle(this, loc.translate(r, r)), new Handle(this, loc.translate(-r, r)) });
}
Also used : Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 43 with Location

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

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

the class CircuitAppearance method getBounds.

private Bounds getBounds(boolean relativeToAnchor) {
    Bounds ret = null;
    Location offset = null;
    for (CanvasObject o : getObjectsFromBottom()) {
        if (o instanceof AppearanceElement) {
            Location loc = ((AppearanceElement) o).getLocation();
            if (o instanceof AppearanceAnchor) {
                offset = loc;
            }
            if (ret == null) {
                ret = Bounds.create(loc);
            } else {
                ret = ret.add(loc);
            }
        } else {
            if (ret == null) {
                ret = o.getBounds();
            } else {
                ret = ret.add(o.getBounds());
            }
        }
    }
    if (ret == null) {
        return Bounds.EMPTY_BOUNDS;
    } else if (relativeToAnchor && offset != null) {
        return ret.translate(-offset.getX(), -offset.getY());
    } else {
        return ret;
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Example 45 with Location

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

the class Splitter method configureComponent.

private synchronized void configureComponent() {
    SplitterAttributes attrs = (SplitterAttributes) getAttributeSet();
    SplitterParameters parms = attrs.getParameters();
    int fanout = attrs.fanout;
    byte[] bit_end = attrs.bit_end;
    // compute width of each end
    bit_thread = new byte[bit_end.length];
    byte[] end_width = new byte[fanout + 1];
    end_width[0] = (byte) bit_end.length;
    for (int i = 0; i < bit_end.length; i++) {
        byte thr = bit_end[i];
        if (thr > 0) {
            bit_thread[i] = end_width[thr];
            end_width[thr]++;
        } else {
            bit_thread[i] = -1;
        }
    }
    // compute end positions
    Location origin = getLocation();
    int x = origin.getX() + parms.getEnd0X();
    int y = origin.getY() + parms.getEnd0Y();
    int dx = parms.getEndToEndDeltaX();
    int dy = parms.getEndToEndDeltaY();
    EndData[] ends = new EndData[fanout + 1];
    ends[0] = new EndData(origin, BitWidth.create(bit_end.length), EndData.INPUT_OUTPUT);
    for (int i = 0; i < fanout; i++) {
        ends[i + 1] = new EndData(Location.create(x, y), BitWidth.create(end_width[i + 1]), EndData.INPUT_OUTPUT);
        x += dx;
        y += dy;
    }
    wire_data = new CircuitWires.SplitterData(fanout);
    setEnds(ends);
    recomputeBounds();
    fireComponentInvalidated(new ComponentEvent(this));
}
Also used : EndData(com.cburch.logisim.comp.EndData) ComponentEvent(com.cburch.logisim.comp.ComponentEvent) 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