use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class LogisimFile method getUnloadLibraryMessage.
public String getUnloadLibraryMessage(Library lib) {
HashSet<ComponentFactory> factories = new HashSet<ComponentFactory>();
for (Tool tool : lib.getTools()) {
if (tool instanceof AddTool) {
factories.add(((AddTool) tool).getFactory());
}
}
for (Circuit circuit : getCircuits()) {
for (Component comp : circuit.getNonWires()) {
if (factories.contains(comp.getFactory())) {
return StringUtil.format(Strings.get("unloadUsedError"), circuit.getName());
}
}
}
ToolbarData tb = options.getToolbarData();
MouseMappings mm = options.getMouseMappings();
for (Tool t : lib.getTools()) {
if (tb.usesToolFromSource(t)) {
return Strings.get("unloadToolbarError");
}
if (mm.usesToolFromSource(t)) {
return Strings.get("unloadMappingError");
}
}
return null;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class CircuitPins method transactionCompleted.
public void transactionCompleted(ReplacementMap repl) {
// determine the changes
Set<Instance> adds = new HashSet<Instance>();
Set<Instance> removes = new HashSet<Instance>();
Map<Instance, Instance> replaces = new HashMap<Instance, Instance>();
for (Component comp : repl.getAdditions()) {
if (comp.getFactory() instanceof Pin) {
Instance in = Instance.getInstanceFor(comp);
boolean added = pins.add(in);
if (added) {
comp.addComponentListener(myComponentListener);
in.getAttributeSet().addAttributeListener(myComponentListener);
adds.add(in);
}
}
}
for (Component comp : repl.getRemovals()) {
if (comp.getFactory() instanceof Pin) {
Instance in = Instance.getInstanceFor(comp);
boolean removed = pins.remove(in);
if (removed) {
comp.removeComponentListener(myComponentListener);
in.getAttributeSet().removeAttributeListener(myComponentListener);
Collection<Component> rs = repl.getComponentsReplacing(comp);
if (rs.isEmpty()) {
removes.add(in);
} else {
Component r = rs.iterator().next();
Instance rin = Instance.getInstanceFor(r);
adds.remove(rin);
replaces.put(in, rin);
}
}
}
}
appearanceManager.updatePorts(adds, removes, replaces, getPins());
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class WireUtil method mergeExclusive.
// Merge all parallel endpoint-to-endpoint wires within the given set.
public static Collection<? extends Component> mergeExclusive(Collection<? extends Component> toMerge) {
if (toMerge.size() <= 1)
return toMerge;
HashSet<Component> ret = new HashSet<Component>(toMerge);
CircuitPoints points = computeCircuitPoints(toMerge);
HashSet<Wire> wires = new HashSet<Wire>();
for (Location loc : points.getSplitLocations()) {
Collection<? extends Component> at = points.getComponents(loc);
if (at.size() == 2) {
Iterator<? extends Component> atIt = at.iterator();
Component o0 = atIt.next();
Component o1 = atIt.next();
if (o0 instanceof Wire && o1 instanceof Wire) {
Wire w0 = (Wire) o0;
Wire w1 = (Wire) o1;
if (w0.is_x_equal == w1.is_x_equal) {
wires.add(w0);
wires.add(w1);
}
}
}
}
points = null;
ret.removeAll(wires);
while (!wires.isEmpty()) {
Iterator<Wire> it = wires.iterator();
Wire w = it.next();
Location e0 = w.e0;
Location e1 = w.e1;
it.remove();
boolean found;
do {
found = false;
for (it = wires.iterator(); it.hasNext(); ) {
Wire cand = it.next();
if (cand.e0.equals(e1)) {
e1 = cand.e1;
found = true;
it.remove();
} else if (cand.e1.equals(e0)) {
e0 = cand.e0;
found = true;
it.remove();
}
}
} while (found);
ret.add(Wire.create(e0, e1));
}
return ret;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class ReplacementMap method print.
public void print(PrintStream out) {
boolean found = false;
for (Component c : getRemovals()) {
if (!found)
out.println(" removals:");
found = true;
out.println(" " + c.toString());
}
if (!found)
out.println(" removals: none");
found = false;
for (Component c : getAdditions()) {
if (!found)
out.println(" additions:");
found = true;
out.println(" " + c.toString());
}
if (!found)
out.println(" additions: none");
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class Circuit method RemoveWrongLabels.
private void RemoveWrongLabels(String Label) {
boolean HaveAChange = false;
for (Component comp : comps) {
AttributeSet attrs = comp.getAttributeSet();
if (attrs.containsAttribute(StdAttr.LABEL)) {
String CompLabel = attrs.getValue(StdAttr.LABEL);
if (Label.toUpperCase().equals(CompLabel.toUpperCase())) {
attrs.setValue(StdAttr.LABEL, "");
HaveAChange = true;
}
}
}
/* we do not have to check the wires as (1) Wire is a reserved keyword, and (2) they cannot have a label */
if (HaveAChange)
JOptionPane.showMessageDialog(null, "\"" + Label + "\" : " + Strings.get("ComponentLabelCollisionError"));
}
Aggregations