use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Transistor method contains.
@Override
public boolean contains(Location loc, AttributeSet attrs) {
if (super.contains(loc, attrs)) {
Direction facing = attrs.getValue(StdAttr.FACING);
Location center = Location.create(0, 0).translate(facing, -20);
return center.manhattanDistanceTo(loc) < 24;
} else {
return false;
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Transistor method drawInstance.
private void drawInstance(InstancePainter painter, boolean isGhost) {
Object type = painter.getAttributeValue(ATTR_TYPE);
Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
Direction from = painter.getAttributeValue(StdAttr.FACING);
Direction facing = painter.getAttributeValue(StdAttr.FACING);
boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
int degrees = Direction.EAST.toDegrees() - from.toDegrees();
double radians = Math.toRadians((degrees + 360) % 360);
int m = flip ? 1 : -1;
Graphics2D g = (Graphics2D) painter.getGraphics();
Location loc = painter.getLocation();
g.translate(loc.getX(), loc.getY());
g.rotate(radians);
Color gate;
Color input;
Color output;
Color platform;
if (!isGhost && painter.getShowState()) {
gate = painter.getPortValue(GATE).getColor();
input = painter.getPortValue(INPUT).getColor();
output = painter.getPortValue(OUTPUT).getColor();
Value out = computeOutput(painter);
platform = out.isUnknown() ? Value.UNKNOWN.getColor() : out.getColor();
} else {
Color base = g.getColor();
gate = base;
input = base;
output = base;
platform = base;
}
// input and output lines
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.setColor(output);
g.drawLine(0, 0, -11, 0);
g.drawLine(-11, m * 7, -11, 0);
g.setColor(input);
g.drawLine(-40, 0, -29, 0);
g.drawLine(-29, m * 7, -29, 0);
// gate line
g.setColor(gate);
if (type == TYPE_P) {
g.drawLine(-20, m * 20, -20, m * 15);
GraphicsUtil.switchToWidth(g, 1);
g.drawOval(-22, m * 12 - 2, 4, 4);
} else {
g.drawLine(-20, m * 20, -20, m * 11);
GraphicsUtil.switchToWidth(g, 1);
}
// draw platforms
// gate platform
g.drawLine(-10, m * 10, -30, m * 10);
g.setColor(platform);
// input/output platform
g.drawLine(-9, m * 8, -31, m * 8);
// arrow (same color as platform)
g.drawLine(-21, m * 6, -18, m * 3);
g.drawLine(-21, 0, -18, m * 3);
g.rotate(-radians);
g.translate(-loc.getX(), -loc.getY());
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Tunnel method configureLabel.
//
// private methods
//
private void configureLabel(Instance instance) {
TunnelAttributes attrs = (TunnelAttributes) instance.getAttributeSet();
Location loc = instance.getLocation();
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, loc.getX() + attrs.getLabelX(), loc.getY() + attrs.getLabelY(), attrs.getLabelHAlign(), attrs.getLabelVAlign());
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Tunnel method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
Graphics g = painter.getGraphics();
g.translate(x, y);
g.setColor(Color.BLACK);
paintGhost(painter);
g.translate(-x, -y);
painter.drawPorts();
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Connector method processPath.
private static void processPath(ArrayList<Location> path, ConnectionData conn, AvoidanceMap avoid, ReplacementMap repl, Set<Location> unmarkable) {
Iterator<Location> pathIt = path.iterator();
Location loc0 = pathIt.next();
if (!loc0.equals(conn.getLocation())) {
Location pathLoc = conn.getWirePathStart();
boolean found = loc0.equals(pathLoc);
for (Wire w : conn.getWirePath()) {
Location nextLoc = w.getOtherEnd(pathLoc);
if (found) {
// existing wire will be removed
repl.remove(w);
avoid.unmarkWire(w, nextLoc, unmarkable);
} else if (w.contains(loc0)) {
// wires after this will be
// removed
found = true;
if (!loc0.equals(nextLoc)) {
avoid.unmarkWire(w, nextLoc, unmarkable);
Wire shortenedWire = Wire.create(pathLoc, loc0);
repl.replace(w, shortenedWire);
avoid.markWire(shortenedWire, 0, 0);
}
}
pathLoc = nextLoc;
}
}
while (pathIt.hasNext()) {
Location loc1 = pathIt.next();
Wire newWire = Wire.create(loc0, loc1);
repl.add(newWire);
avoid.markWire(newWire, 0, 0);
loc0 = loc1;
}
}
Aggregations