Пример #1
0
 public FloatCoord getPinLocation(PlacedItem i, Pin p) {
   Coord itemLoc = i.loc;
   Coord pinLoc = p.getLocation();
   ItemType type = i.i.getType();
   return new FloatCoord(
       spacing.getX(itemLoc.x) - type.getOffsetX() + pinLoc.x,
       spacing.getY(itemLoc.y) - type.getOffsetY() + pinLoc.y);
 }
Пример #2
0
  public void act(int dt) {
    z = new float[(int) spacing.getTotalWidth()][(int) spacing.getTotalHeight()];
    List<RenderedWire> newWires = new ArrayList<>();
    List<RenderedWire> oldWires = new ArrayList<>();

    List<PlacedItem> itemSet = new ArrayList<>();
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        if (items[x][y] != null) {
          PlacedItem newItem = new PlacedItem(items[x][y], new Coord(x, y));
          if (!itemSet.contains(newItem)) {
            itemSet.add(newItem);
          }
        }
      }
    }
    List<PlacedPin> pinSet = new ArrayList<>();
    for (PlacedItem i : itemSet) {
      for (Pin p : i.i.getPins()) {
        if (p.getAttatched() != null) {
          pinSet.add(new PlacedPin(p, i));
        }
      }
    }
    while (pinSet.size() > 0) {
      PlacedPin p0 = pinSet.remove(0);
      if (p0.p.getAttatched() != null) {
        boolean flag = true;
        if (p0.p.getAttatched().isAttatchedOnBothSides()) {
          flag = false;
          Pin other = p0.p.getAttatched().getOtherEnd(p0.p);
          PlacedPin p1 =
              pinSet.stream().filter(placedPin -> placedPin.p == other).findAny().orElse(null);
          if (p1 != null) {
            pinSet.remove(p1);
            RenderedWire testWire = new RenderedWire(p0, p1);
            if (wires.contains(testWire)) {
              oldWires.add(testWire);
            } else {
              newWires.add(testWire);
            }
          } else {
            flag = true;
          }
        }
        if (flag) // p0.p is not attached on both sides, or it is attached to something not in the
        // grid.
        {
          RenderedWire testWire = new RenderedWire(p0, null);
          if (wires.contains(testWire)) {
            oldWires.add(testWire);
          } else {
            newWires.add(testWire);
          }
        }
      }
    }
    for (RenderedWire w : wires) {
      if (oldWires.contains(w)) {
        addDepthInfo(w.path);
      } else {
        removeWire(w.path);
      }
    }
    for (RenderedWire w : newWires) {
      if (w.end != null) {
        w.setWirePath(addWire(w.start, w.end));
      } else {
        w.setWirePath(addUnfinishedWire(w.start));
      }
    }

    wires.retainAll(oldWires);
    wires.addAll(newWires);

    super.act(dt);
  }