use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class SubcircuitFactory method configureLabel.
private void configureLabel(Instance instance) {
Bounds bds = instance.getBounds();
Direction loc = instance.getAttributeValue(CircuitAttributes.LABEL_LOCATION_ATTR);
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int ha = GraphicsUtil.H_CENTER;
int va = GraphicsUtil.V_CENTER;
if (loc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
ha = GraphicsUtil.H_LEFT;
} else if (loc == Direction.WEST) {
x = bds.getX() - 2;
ha = GraphicsUtil.H_RIGHT;
} else if (loc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
va = GraphicsUtil.V_TOP;
} else {
y = bds.getY() - 2;
va = GraphicsUtil.V_BASELINE;
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, ha, va);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class SubcircuitFactory method contains.
/**
* Code taken from Cornell's version of Logisim:
* http://www.cs.cornell.edu/courses/cs3410/2015sp/
*/
@Override
public boolean contains(Location loc, AttributeSet attrs) {
if (super.contains(loc, attrs)) {
Direction facing = attrs.getValue(StdAttr.FACING);
Direction defaultFacing = source.getAppearance().getFacing();
Location query;
if (facing.equals(defaultFacing)) {
query = loc;
} else {
query = loc.rotate(facing, defaultFacing, 0, 0);
}
return source.getAppearance().contains(query);
} else {
return false;
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class SubcircuitFactory method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
Direction defaultFacing = source.getAppearance().getFacing();
Bounds bds = source.getAppearance().getOffsetBounds();
return bds.rotate(defaultFacing, facing, 0, 0);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class PortManager method computeDefaultLocation.
private static Location computeDefaultLocation(CircuitAppearance appear, Instance pin, Map<Instance, AppearancePort> others) {
// Determine which locations are being used in canvas, and look for
// which instances facing the same way in layout
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;
// (preferably previous in map)
Instance neighbor = null;
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;
}
// round coordinates up to ensure they're on grid
x = (x + 9) / 10 * 10;
y = (y + 9) / 10 * 10;
Location loc = Location.create(x, y);
while (usedLocs.contains(loc)) {
loc = loc.translate(dx, dy);
}
return loc;
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Splitter method contains.
@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;
}
}
Aggregations