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;
}
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)) });
}
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);
}
}
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;
}
}
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));
}
Aggregations