use of com.cburch.logisim.comp.Component 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.comp.Component 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.comp.Component 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.comp.Component in project logisim-evolution by reds-heig.
the class PropagationPoints method draw.
void draw(ComponentDrawContext context) {
if (data.isEmpty())
return;
CircuitState state = context.getCircuitState();
HashMap<CircuitState, CircuitState> stateMap = new HashMap<CircuitState, CircuitState>();
for (CircuitState s : state.getSubstates()) {
addSubstates(stateMap, s, s);
}
Graphics g = context.getGraphics();
GraphicsUtil.switchToWidth(g, 2);
for (Entry e : data) {
if (e.state == state) {
Location p = e.loc;
g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
} else if (stateMap.containsKey(e.state)) {
CircuitState substate = stateMap.get(e.state);
Component subcirc = substate.getSubcircuit();
Bounds b = subcirc.getBounds();
g.drawRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
}
}
GraphicsUtil.switchToWidth(g, 1);
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class LoadedLibrary method replaceAll.
private static void replaceAll(Circuit circuit, Map<ComponentFactory, ComponentFactory> compMap) {
ArrayList<Component> toReplace = null;
for (Component comp : circuit.getNonWires()) {
if (compMap.containsKey(comp.getFactory())) {
if (toReplace == null)
toReplace = new ArrayList<Component>();
toReplace.add(comp);
}
}
if (toReplace != null) {
CircuitMutation xn = new CircuitMutation(circuit);
for (Component comp : toReplace) {
xn.remove(comp);
ComponentFactory factory = compMap.get(comp.getFactory());
if (factory != null) {
AttributeSet newAttrs = createAttributes(factory, comp.getAttributeSet());
xn.add(factory.createComponent(comp.getLocation(), newAttrs));
}
}
xn.execute();
}
}
Aggregations