use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class TransmissionGate method drawInstance.
private void drawInstance(InstancePainter painter, boolean isGhost) {
Bounds bds = painter.getBounds();
Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
Direction facing = painter.getAttributeValue(StdAttr.FACING);
boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
if (flip)
degrees += 180;
double radians = Math.toRadians((degrees + 360) % 360);
Graphics2D g = (Graphics2D) painter.getGraphics().create();
g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
g.translate(bds.getX(), bds.getY());
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
Color gate0 = g.getColor();
Color gate1 = gate0;
Color input = gate0;
Color output = gate0;
Color platform = gate0;
if (!isGhost && painter.getShowState()) {
gate0 = painter.getPortValue(GATE0).getColor();
gate1 = painter.getPortValue(GATE0).getColor();
input = painter.getPortValue(INPUT).getColor();
output = painter.getPortValue(OUTPUT).getColor();
platform = computeOutput(painter).getColor();
}
g.setColor(flip ? input : output);
g.drawLine(0, 20, 11, 20);
g.drawLine(11, 13, 11, 27);
g.setColor(flip ? output : input);
g.drawLine(29, 20, 40, 20);
g.drawLine(29, 13, 29, 27);
g.setColor(gate0);
g.drawLine(20, 35, 20, 40);
GraphicsUtil.switchToWidth(g, 1);
g.drawOval(18, 30, 4, 4);
g.drawLine(10, 30, 30, 30);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.setColor(gate1);
g.drawLine(20, 9, 20, 0);
GraphicsUtil.switchToWidth(g, 1);
g.drawLine(10, 10, 30, 10);
g.setColor(platform);
g.drawLine(9, 12, 31, 12);
g.drawLine(9, 28, 31, 28);
if (flip) {
// arrow
g.drawLine(18, 17, 21, 20);
g.drawLine(18, 23, 21, 20);
} else {
g.drawLine(22, 17, 19, 20);
g.drawLine(22, 23, 19, 20);
}
g.dispose();
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class MoveGesture method computeConnections.
private static Set<ConnectionData> computeConnections(Circuit circuit, Set<Component> selected) {
if (selected == null || selected.isEmpty())
return Collections.emptySet();
// first identify locations that might be connected
Set<Location> locs = new HashSet<Location>();
for (Component comp : selected) {
for (EndData end : comp.getEnds()) {
locs.add(end.getLocation());
}
}
// now see which of them require connection
Set<ConnectionData> conns = new HashSet<ConnectionData>();
for (Location loc : locs) {
boolean found = false;
for (Component comp : circuit.getComponents(loc)) {
if (!selected.contains(comp)) {
found = true;
break;
}
}
if (found) {
List<Wire> wirePath;
Location wirePathStart;
Wire lastOnPath = findWire(circuit, loc, selected, null);
if (lastOnPath == null) {
wirePath = Collections.emptyList();
wirePathStart = loc;
} else {
wirePath = new ArrayList<Wire>();
Location cur = loc;
for (Wire w = lastOnPath; w != null; w = findWire(circuit, cur, selected, w)) {
wirePath.add(w);
cur = w.getOtherEnd(cur);
}
Collections.reverse(wirePath);
wirePathStart = cur;
}
Direction dir = null;
if (lastOnPath != null) {
Location other = lastOnPath.getOtherEnd(loc);
int dx = loc.getX() - other.getX();
int dy = loc.getY() - other.getY();
if (Math.abs(dx) > Math.abs(dy)) {
dir = dx > 0 ? Direction.EAST : Direction.WEST;
} else {
dir = dy > 0 ? Direction.SOUTH : Direction.NORTH;
}
}
conns.add(new ConnectionData(loc, dir, wirePath, wirePathStart));
}
}
return conns;
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Led method computeTextField.
private void computeTextField(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 2;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 2;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Decoder method updatePorts.
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
Port[] ps = new Port[outputs + (enable ? 2 : 1)];
if (outputs == 2) {
Location end0;
Location end1;
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
int y = facing == Direction.NORTH ? -10 : 10;
if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
end0 = Location.create(-30, y);
end1 = Location.create(-10, y);
} else {
end0 = Location.create(10, y);
end1 = Location.create(30, y);
}
} else {
int x = facing == Direction.WEST ? -10 : 10;
if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
end0 = Location.create(x, 10);
end1 = Location.create(x, 30);
} else {
end0 = Location.create(x, -30);
end1 = Location.create(x, -10);
}
}
ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, 1);
ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, 1);
} else {
int dx;
int ddx;
int dy;
int ddy;
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
dy = facing == Direction.NORTH ? -20 : 20;
ddy = 0;
dx = selectLoc == Plexers.SELECT_TOP_RIGHT ? -10 * outputs : 0;
ddx = 10;
} else {
dx = facing == Direction.WEST ? -20 : 20;
ddx = 0;
dy = selectLoc == Plexers.SELECT_TOP_RIGHT ? 0 : -10 * outputs;
ddy = 10;
}
for (int i = 0; i < outputs; i++) {
ps[i] = new Port(dx, dy, Port.OUTPUT, 1);
dx += ddx;
dy += ddy;
}
}
Location en = Location.create(0, 0).translate(facing, -10);
ps[outputs] = new Port(0, 0, Port.INPUT, select.getWidth());
if (enable) {
ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
}
for (int i = 0; i < outputs; i++) {
ps[i].setToolTip(Strings.getter("decoderOutTip", "" + i));
}
ps[outputs].setToolTip(Strings.getter("decoderSelectTip"));
if (enable) {
ps[outputs + 1].setToolTip(Strings.getter("decoderEnableTip"));
}
instance.setPorts(ps);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Decoder method paintGhost.
@Override
public void paintGhost(InstancePainter painter) {
Direction facing = painter.getAttributeValue(StdAttr.FACING);
BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
Bounds bds = painter.getBounds();
if (select.getWidth() == 1) {
if (facing == Direction.EAST || facing == Direction.WEST) {
Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing.reverse(), 10);
} else {
Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing.reverse(), 10);
}
} else {
Plexers.drawTrapezoid(painter.getGraphics(), bds, facing.reverse(), 20);
}
}
Aggregations