use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CircuitWires method connectTunnels.
private void connectTunnels(BundleMap ret) {
// determine the sets of tunnels
HashMap<String, ArrayList<Location>> tunnelSets = new HashMap<String, ArrayList<Location>>();
for (Component comp : tunnels) {
String label = comp.getAttributeSet().getValue(StdAttr.LABEL);
label = label.trim();
if (!label.equals("")) {
ArrayList<Location> tunnelSet = tunnelSets.get(label);
if (tunnelSet == null) {
tunnelSet = new ArrayList<Location>(3);
tunnelSets.put(label, tunnelSet);
}
tunnelSet.add(comp.getLocation());
}
}
// now connect the bundles that are tunnelled together
for (ArrayList<Location> tunnelSet : tunnelSets.values()) {
WireBundle foundBundle = null;
Location foundLocation = null;
for (Location loc : tunnelSet) {
WireBundle b = ret.getBundleAt(loc);
if (b != null) {
foundBundle = b;
foundLocation = loc;
break;
}
}
if (foundBundle == null) {
foundLocation = tunnelSet.get(0);
foundBundle = ret.createBundleAt(foundLocation);
}
for (Location loc : tunnelSet) {
if (loc != foundLocation) {
WireBundle b = ret.getBundleAt(loc);
if (b == null) {
foundBundle.points.add(loc);
ret.setBundleAt(loc, foundBundle);
} else {
b.unite(foundBundle);
}
}
}
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CircuitWires method connectPullResistors.
private void connectPullResistors(BundleMap ret) {
for (Component comp : pulls) {
Location loc = comp.getEnd(0).getLocation();
WireBundle b = ret.getBundleAt(loc);
if (b == null) {
b = ret.createBundleAt(loc);
b.points.add(loc);
ret.setBundleAt(loc, b);
}
Instance instance = Instance.getInstanceFor(comp);
b.addPullValue(PullResistor.getPullValue(instance));
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CircuitWires method getThreadValue.
private Value getThreadValue(CircuitState state, WireThread t) {
Value ret = Value.UNKNOWN;
Value pull = Value.UNKNOWN;
for (ThreadBundle tb : t.getBundles()) {
for (Location p : tb.b.points) {
Value val = state.getComponentOutputAt(p);
if (val != null && val != Value.NIL) {
ret = ret.combine(val.get(tb.loc));
}
}
Value pullHere = tb.b.getPullValue();
if (pullHere != Value.UNKNOWN)
pull = pull.combine(pullHere);
}
if (pull != Value.UNKNOWN) {
ret = pullValue(ret, pull);
}
return ret;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CircuitWires method draw.
void draw(ComponentDrawContext context, Collection<Component> hidden) {
boolean showState = context.getShowState();
CircuitState state = context.getCircuitState();
Graphics g = context.getGraphics();
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
WireSet highlighted = context.getHighlightedWires();
BundleMap bmap = getBundleMap();
boolean isValid = bmap.isValid();
if (hidden == null || hidden.size() == 0) {
for (Wire w : wires) {
Location s = w.e0;
Location t = w.e1;
WireBundle wb = bmap.getBundleAt(s);
int width = 5;
if (!wb.isValid()) {
g.setColor(Value.WIDTH_ERROR_COLOR);
} else if (showState) {
if (!isValid)
g.setColor(Value.NIL_COLOR);
else
g.setColor(state.getValue(s).getColor());
} else {
g.setColor(Color.BLACK);
}
if (highlighted.containsWire(w)) {
if (wb.isBus())
width = Wire.HIGHLIGHTED_WIDTH_BUS;
else
width = Wire.HIGHLIGHTED_WIDTH;
GraphicsUtil.switchToWidth(g, width);
g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
} else {
if (wb.isBus())
width = Wire.WIDTH_BUS;
else
width = Wire.WIDTH;
GraphicsUtil.switchToWidth(g, width);
g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
}
if (w.IsSetAsMarked()) {
width += 2;
g.setColor(w.GetMarkColor());
GraphicsUtil.switchToWidth(g, 2);
if (w.isVertical()) {
g.drawLine(s.getX() - width, s.getY(), t.getX() - width, t.getY());
g.drawLine(s.getX() + width, s.getY(), t.getX() + width, t.getY());
} else {
g.drawLine(s.getX(), s.getY() - width, t.getX(), t.getY() - width);
g.drawLine(s.getX(), s.getY() + width, t.getX(), t.getY() + width);
}
}
}
for (Location loc : points.getSplitLocations()) {
if (points.getComponentCount(loc) > 2) {
WireBundle wb = bmap.getBundleAt(loc);
if (wb != null) {
if (!wb.isValid()) {
g.setColor(Value.WIDTH_ERROR_COLOR);
} else if (showState) {
if (!isValid)
g.setColor(Value.NIL_COLOR);
else
g.setColor(state.getValue(loc).getColor());
} else {
g.setColor(Color.BLACK);
}
int radius;
if (highlighted.containsLocation(loc)) {
radius = wb.isBus() ? (int) (Wire.HIGHLIGHTED_WIDTH_BUS * Wire.DOT_MULTIPLY_FACTOR) : (int) (Wire.HIGHLIGHTED_WIDTH * Wire.DOT_MULTIPLY_FACTOR);
} else {
radius = wb.isBus() ? (int) (Wire.WIDTH_BUS * Wire.DOT_MULTIPLY_FACTOR) : (int) (Wire.WIDTH * Wire.DOT_MULTIPLY_FACTOR);
}
g.fillOval(loc.getX() - radius, loc.getY() - radius, radius * 2, radius * 2);
}
}
}
} else {
for (Wire w : wires) {
if (!hidden.contains(w)) {
Location s = w.e0;
Location t = w.e1;
WireBundle wb = bmap.getBundleAt(s);
if (!wb.isValid()) {
g.setColor(Value.WIDTH_ERROR_COLOR);
} else if (showState) {
if (!isValid)
g.setColor(Value.NIL_COLOR);
else
g.setColor(state.getValue(s).getColor());
} else {
g.setColor(Color.BLACK);
}
if (highlighted.containsWire(w)) {
GraphicsUtil.switchToWidth(g, Wire.WIDTH + 2);
g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
} else {
if (wb.isBus())
GraphicsUtil.switchToWidth(g, Wire.WIDTH_BUS);
else
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
}
}
}
// while at a time anway.
for (Location loc : points.getSplitLocations()) {
if (points.getComponentCount(loc) > 2) {
int icount = 0;
for (Component comp : points.getComponents(loc)) {
if (!hidden.contains(comp))
++icount;
}
if (icount > 2) {
WireBundle wb = bmap.getBundleAt(loc);
if (wb != null) {
if (!wb.isValid()) {
g.setColor(Value.WIDTH_ERROR_COLOR);
} else if (showState) {
if (!isValid)
g.setColor(Value.NIL_COLOR);
else
g.setColor(state.getValue(loc).getColor());
} else {
g.setColor(Color.BLACK);
}
int radius;
if (highlighted.containsLocation(loc)) {
radius = wb.isBus() ? Wire.HIGHLIGHTED_WIDTH_BUS : Wire.HIGHLIGHTED_WIDTH;
} else {
radius = wb.isBus() ? Wire.WIDTH_BUS : Wire.WIDTH;
}
g.fillOval(loc.getX() - radius, loc.getY() - radius, radius * 2, radius * 2);
}
}
}
}
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CircuitWires method computeBundleMap.
// To be called by getBundleMap only
private void computeBundleMap(BundleMap ret) {
// create bundles corresponding to wires and tunnels
connectWires(ret);
connectTunnels(ret);
connectPullResistors(ret);
// merge any WireBundle objects united by previous steps
for (Iterator<WireBundle> it = ret.getBundles().iterator(); it.hasNext(); ) {
WireBundle b = it.next();
WireBundle bpar = b.find();
if (bpar != b) {
// b isn't group's representative
for (Location pt : b.points) {
ret.setBundleAt(pt, bpar);
bpar.points.add(pt);
}
bpar.addPullValue(b.getPullValue());
it.remove();
}
}
// make a WireBundle object for each end of a splitter
for (Splitter spl : splitters) {
List<EndData> ends = new ArrayList<EndData>(spl.getEnds());
for (EndData end : ends) {
Location p = end.getLocation();
WireBundle pb = ret.createBundleAt(p);
pb.setWidth(end.getWidth(), p);
}
}
// based on components
for (Location p : ret.getBundlePoints()) {
WireBundle pb = ret.getBundleAt(p);
BitWidth width = points.getWidth(p);
if (width != BitWidth.UNKNOWN) {
pb.setWidth(width, p);
}
}
// determine the bundles at the end of each splitter
for (Splitter spl : splitters) {
List<EndData> ends = new ArrayList<EndData>(spl.getEnds());
int index = -1;
for (EndData end : ends) {
index++;
Location p = end.getLocation();
WireBundle pb = ret.getBundleAt(p);
if (pb != null) {
pb.setWidth(end.getWidth(), p);
spl.wire_data.end_bundle[index] = pb;
}
}
}
// unite threads going through splitters
for (Splitter spl : splitters) {
synchronized (spl) {
SplitterAttributes spl_attrs = (SplitterAttributes) spl.getAttributeSet();
byte[] bit_end = spl_attrs.bit_end;
SplitterData spl_data = spl.wire_data;
WireBundle from_bundle = spl_data.end_bundle[0];
if (from_bundle == null || !from_bundle.isValid())
continue;
for (int i = 0; i < bit_end.length; i++) {
int j = bit_end[i];
if (j > 0) {
int thr = spl.bit_thread[i];
WireBundle to_bundle = spl_data.end_bundle[j];
WireThread[] to_threads = to_bundle.threads;
if (to_threads != null && to_bundle.isValid()) {
WireThread[] from_threads = from_bundle.threads;
if (i >= from_threads.length) {
throw new ArrayIndexOutOfBoundsException("from " + i + " of " + from_threads.length);
}
if (thr >= to_threads.length) {
throw new ArrayIndexOutOfBoundsException("to " + thr + " of " + to_threads.length);
}
from_threads[i].unite(to_threads[thr]);
}
}
}
}
}
// merge any threads united by previous step
for (WireBundle b : ret.getBundles()) {
if (b.isValid() && b.threads != null) {
for (int i = 0; i < b.threads.length; i++) {
WireThread thr = b.threads[i].find();
b.threads[i] = thr;
thr.getBundles().add(new ThreadBundle(i, b));
}
}
}
// All threads are sewn together! Compute the exception set before
// leaving
Collection<WidthIncompatibilityData> exceptions = points.getWidthIncompatibilityData();
if (exceptions != null && exceptions.size() > 0) {
for (WidthIncompatibilityData wid : exceptions) {
ret.addWidthIncompatibilityData(wid);
}
}
for (WireBundle b : ret.getBundles()) {
WidthIncompatibilityData e = b.getWidthIncompatibilityData();
if (e != null)
ret.addWidthIncompatibilityData(e);
}
}
Aggregations