Search in sources :

Example 31 with Location

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

the class PropagationPoints method draw.

void draw(ComponentDrawContext context) {
    if (data.isEmpty())
        return;
    CircuitState state = context.getCircuitState();
    HashMap<CircuitState, CircuitState> stateMap = new HashMap<CircuitState, CircuitState>();
    for (CircuitState s : state.getSubstates()) {
        addSubstates(stateMap, s, s);
    }
    Graphics g = context.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    for (Entry e : data) {
        if (e.state == state) {
            Location p = e.loc;
            g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
        } else if (stateMap.containsKey(e.state)) {
            CircuitState substate = stateMap.get(e.state);
            Component subcirc = substate.getSubcircuit();
            Bounds b = subcirc.getBounds();
            g.drawRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
        }
    }
    GraphicsUtil.switchToWidth(g, 1);
}
Also used : Graphics(java.awt.Graphics) HashMap(java.util.HashMap) Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 32 with Location

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

the class SubcircuitFactory method paintBase.

private void paintBase(InstancePainter painter, Graphics g) {
    CircuitAttributes attrs = (CircuitAttributes) painter.getAttributeSet();
    Direction facing = attrs.getFacing();
    Direction defaultFacing = source.getAppearance().getFacing();
    Location loc = painter.getLocation();
    g.translate(loc.getX(), loc.getY());
    source.getAppearance().paintSubcircuit(g, facing);
    drawCircuitLabel(painter, getOffsetBounds(attrs), facing, defaultFacing);
    g.translate(-loc.getX(), -loc.getY());
    painter.drawLabel();
}
Also used : Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 33 with Location

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

the class WireIterator method next.

public Location next() {
    Location ret = Location.create(curX, curY);
    destReturned |= curX == destX && curY == destY;
    curX += deltaX;
    curY += deltaY;
    return ret;
}
Also used : Location(com.cburch.logisim.data.Location)

Example 34 with Location

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

the class WireRepair method doSplits.

private void doSplits(CircuitMutator mutator) {
    Set<Location> splitLocs = circuit.wires.points.getSplitLocations();
    ReplacementMap repl = new ReplacementMap();
    for (Wire w : circuit.getWires()) {
        Location w0 = w.getEnd0();
        Location w1 = w.getEnd1();
        ArrayList<Location> splits = null;
        for (Location loc : splitLocs) {
            if (w.contains(loc) && !loc.equals(w0) && !loc.equals(w1)) {
                if (splits == null)
                    splits = new ArrayList<Location>();
                splits.add(loc);
            }
        }
        if (splits != null) {
            splits.add(w1);
            Collections.sort(splits);
            Location e0 = w0;
            ArrayList<Wire> subs = new ArrayList<Wire>(splits.size());
            for (Location e1 : splits) {
                subs.add(Wire.create(e0, e1));
                e0 = e1;
            }
            repl.put(w, subs);
        }
    }
    mutator.replace(circuit, repl);
}
Also used : ArrayList(java.util.ArrayList) Location(com.cburch.logisim.data.Location)

Example 35 with Location

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

the class DefaultAppearance method old_build.

private static List<CanvasObject> old_build(Collection<Instance> pins) {
    Map<Direction, List<Instance>> edge;
    edge = new HashMap<Direction, List<Instance>>();
    edge.put(Direction.NORTH, new ArrayList<Instance>());
    edge.put(Direction.SOUTH, new ArrayList<Instance>());
    edge.put(Direction.EAST, new ArrayList<Instance>());
    edge.put(Direction.WEST, new ArrayList<Instance>());
    for (Instance pin : pins) {
        Direction pinFacing = pin.getAttributeValue(StdAttr.FACING);
        Direction pinEdge = pinFacing.reverse();
        List<Instance> e = edge.get(pinEdge);
        e.add(pin);
    }
    for (Map.Entry<Direction, List<Instance>> entry : edge.entrySet()) {
        sortPinList(entry.getValue(), entry.getKey());
    }
    int numNorth = edge.get(Direction.NORTH).size();
    int numSouth = edge.get(Direction.SOUTH).size();
    int numEast = edge.get(Direction.EAST).size();
    int numWest = edge.get(Direction.WEST).size();
    int maxVert = Math.max(numNorth, numSouth);
    int maxHorz = Math.max(numEast, numWest);
    int offsNorth = computeOffset(numNorth, numSouth, maxHorz);
    int offsSouth = computeOffset(numSouth, numNorth, maxHorz);
    int offsEast = computeOffset(numEast, numWest, maxVert);
    int offsWest = computeOffset(numWest, numEast, maxVert);
    int width = computeDimension(maxVert, maxHorz);
    int height = computeDimension(maxHorz, maxVert);
    // compute position of anchor relative to top left corner of box
    int ax;
    int ay;
    if (numEast > 0) {
        // anchor is on east side
        ax = width;
        ay = offsEast;
    } else if (numNorth > 0) {
        // anchor is on north side
        ax = offsNorth;
        ay = 0;
    } else if (numWest > 0) {
        // anchor is on west side
        ax = 0;
        ay = offsWest;
    } else if (numSouth > 0) {
        // anchor is on south side
        ax = offsSouth;
        ay = height;
    } else {
        // anchor is top left corner
        ax = 0;
        ay = 0;
    }
    // place rectangle so anchor is on the grid
    int rx = OFFS + (9 - (ax + 9) % 10);
    int ry = OFFS + (9 - (ay + 9) % 10);
    Location e0 = Location.create(rx + (width - 8) / 2, ry + 1);
    Location e1 = Location.create(rx + (width + 8) / 2, ry + 1);
    Location ct = Location.create(rx + width / 2, ry + 11);
    Curve notch = new Curve(e0, e1, ct);
    notch.setValue(DrawAttr.STROKE_WIDTH, Integer.valueOf(2));
    notch.setValue(DrawAttr.STROKE_COLOR, Color.GRAY);
    Rectangle rect = new Rectangle(rx, ry, width, height);
    rect.setValue(DrawAttr.STROKE_WIDTH, Integer.valueOf(2));
    List<CanvasObject> ret = new ArrayList<CanvasObject>();
    ret.add(notch);
    ret.add(rect);
    placePins(ret, edge.get(Direction.WEST), rx, ry + offsWest, 0, 10);
    placePins(ret, edge.get(Direction.EAST), rx + width, ry + offsEast, 0, 10);
    placePins(ret, edge.get(Direction.NORTH), rx + offsNorth, ry, 10, 0);
    placePins(ret, edge.get(Direction.SOUTH), rx + offsSouth, ry + height, 10, 0);
    ret.add(new AppearanceAnchor(Location.create(rx + ax, ry + ay)));
    return ret;
}
Also used : Instance(com.cburch.logisim.instance.Instance) Curve(com.cburch.draw.shapes.Curve) Rectangle(com.cburch.draw.shapes.Rectangle) ArrayList(java.util.ArrayList) Direction(com.cburch.logisim.data.Direction) CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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