Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Location


    if (circuit == null) return false;
    for (Component comp : components) {
      if (!(comp instanceof Wire)) {
        for (EndData endData : comp.getEnds()) {
          if (endData != null && endData.isExclusive()) {
            Location endLoc = endData.getLocation().translate(dx, dy);
            Component conflict = circuit.getExclusive(endLoc);
            if (conflict != null) {
              if (selfConflicts || !components.contains(conflict)) return true;
            }
          }
        }
        Location newLoc = comp.getLocation().translate(dx, dy);
        Bounds newBounds = comp.getBounds().translate(dx, dy);
        for (Component comp2 : circuit.getAllContaining(newLoc)) {
          Bounds bds = comp2.getBounds();
          if (bds.equals(newBounds)) {
            if (selfConflicts || !components.contains(comp2)) return true;
View Full Code Here


 
  private HashMap<Component,Component> copyComponents(Collection<Component> components,
      int dx, int dy) {
    HashMap<Component,Component> ret = new HashMap<Component,Component>();
    for (Component comp : components) {
      Location oldLoc = comp.getLocation();
      AttributeSet attrs = (AttributeSet) comp.getAttributeSet().clone();
      int newX = oldLoc.getX() + dx;
      int newY = oldLoc.getY() + dy;
      Object snap = comp.getFactory().getFeature(ComponentFactory.SHOULD_SNAP, attrs);
      if (snap == null || ((Boolean) snap).booleanValue()) {
        newX = Canvas.snapXToGrid(newX);
        newY = Canvas.snapYToGrid(newY);
      }
      Location newLoc = Location.create(newX, newY);
     
      Component copy = comp.getFactory().createComponent(newLoc, attrs);
      ret.put(comp, copy);
    }
    return ret;
View Full Code Here

   
    // 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));
View Full Code Here

    CompareLocations(boolean byX) {
      this.byX = byX;
    }
   
    public int compare(Instance a, Instance b) {
      Location aloc = a.getLocation();
      Location bloc = b.getLocation();
      if (byX) {
        int ax = aloc.getX();
        int bx = bloc.getX();
        if (ax != bx) {
          return ax < bx ? -1 : 1;
        }
      } else {
        int ay = aloc.getY();
        int by = bloc.getY();
        if (ay != by) {
          return ay < by ? -1 : 1;
        }
      }
      return aloc.compareTo(bloc);
View Full Code Here

public class AppearanceSvgReader {
  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 {
View Full Code Here

    DefaultAppearance.sortPinList(addsCopy, Direction.EAST);
      // They're probably not really all facing east.
      // I'm just sorting them so it works predictably.
    for (Instance pin : addsCopy) {
      if (!oldObjects.containsKey(pin)) {
        Location loc = computeDefaultLocation(appearance, pin, oldObjects);
        AppearancePort o = new AppearancePort(loc, pin);
        portAdds.add(o);
        oldObjects.put(pin, o);
      }
    }
View Full Code Here

    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;
      Instance neighbor = null; // (preferably previous in map)
      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;
    }
    x = (x + 9) / 10 * 10; // round coordinates up to ensure they're on grid
    y = (y + 9) / 10 * 10;
    Location loc = Location.create(x, y);
    while (usedLocs.contains(loc)) {
      loc = loc.translate(dx, dy);
    }
    return loc;
  }
View Full Code Here

  @Override
  public void drawGhost(ComponentDrawContext context,
      Color color, int x, int y, AttributeSet attrsBase) {
    SplitterAttributes attrs = (SplitterAttributes) attrsBase;
    context.getGraphics().setColor(color);
    Location loc = Location.create(x, y);
    if (attrs.appear == SplitterAttributes.APPEAR_LEGACY) {
      SplitterPainter.drawLegacy(context, attrs, loc);
    } else {
      SplitterPainter.drawLines(context, attrs, loc);
    }
View Full Code Here

  }
 
  @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;
    }
View Full Code Here

        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);
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.