use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class CircuitMutatorImpl method replace.
public void replace(Circuit circuit, ReplacementMap repl) {
if (!repl.isEmpty()) {
modified.add(circuit);
log.add(CircuitChange.replace(circuit, repl));
repl.freeze();
getMap(circuit).append(repl);
for (Component c : repl.getRemovals()) {
circuit.mutatorRemove(c);
}
for (Component c : repl.getAdditions()) {
circuit.mutatorAdd(c);
}
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class CircuitPoints method find.
private Collection<? extends Component> find(Location loc, boolean isWire) {
LocationData locData = map.get(loc);
if (locData == null)
return Collections.emptySet();
// first see how many elements we have; we can handle some simple
// cases without creating any new lists
ArrayList<Component> list = locData.components;
int retSize = 0;
Component retValue = null;
for (Component o : list) {
if ((o instanceof Wire) == isWire) {
retValue = o;
retSize++;
}
}
if (retSize == list.size())
return list;
if (retSize == 0)
return Collections.emptySet();
if (retSize == 1)
return Collections.singleton(retValue);
// otherwise we have to create our own list
Component[] ret = new Component[retSize];
int retPos = 0;
for (Component o : list) {
if ((o instanceof Wire) == isWire) {
ret[retPos] = o;
retPos++;
}
}
return Arrays.asList(ret);
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class CircuitState method processDirtyComponents.
void processDirtyComponents() {
if (!dirtyComponents.isEmpty()) {
// This seeming wasted copy is to avoid ConcurrentModifications
// if we used an iterator instead.
Object[] toProcess;
RuntimeException firstException = null;
for (int tries = 4; true; tries--) {
try {
toProcess = dirtyComponents.toArray();
break;
} catch (RuntimeException e) {
if (firstException == null)
firstException = e;
if (tries == 0) {
toProcess = new Object[0];
dirtyComponents = new CopyOnWriteArraySet<Component>();
throw firstException;
}
}
}
dirtyComponents.clear();
for (Object compObj : toProcess) {
if (compObj instanceof Component) {
Component comp = (Component) compObj;
comp.propagate(this);
if (comp.getFactory() instanceof Pin && parentState != null) {
// should be propagated in superstate
parentComp.propagate(parentState);
}
}
}
}
CircuitState[] subs = new CircuitState[substates.size()];
for (CircuitState substate : substates.toArray(subs)) {
substate.processDirtyComponents();
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class CircuitState method reset.
void reset() {
wireData = null;
for (Iterator<Component> it = componentData.keySet().iterator(); it.hasNext(); ) {
Component comp = it.next();
if (!(comp.getFactory() instanceof SubcircuitFactory))
it.remove();
}
values.clear();
dirtyComponents.clear();
dirtyPoints.clear();
causes.clear();
markAllComponentsDirty();
for (CircuitState sub : substates) {
sub.reset();
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class CircuitState method copyFrom.
private void copyFrom(CircuitState src, Propagator base) {
this.base = base;
this.parentComp = src.parentComp;
this.parentState = src.parentState;
HashMap<CircuitState, CircuitState> substateData = new HashMap<CircuitState, CircuitState>();
this.substates = new HashSet<CircuitState>();
for (CircuitState oldSub : src.substates) {
CircuitState newSub = new CircuitState(src.proj, oldSub.circuit);
newSub.copyFrom(oldSub, base);
newSub.parentState = this;
this.substates.add(newSub);
substateData.put(oldSub, newSub);
}
for (Component key : src.componentData.keySet()) {
Object oldValue = src.componentData.get(key);
if (oldValue instanceof CircuitState) {
Object newValue = substateData.get(oldValue);
if (newValue != null)
this.componentData.put(key, newValue);
else
this.componentData.remove(key);
} else {
Object newValue;
if (oldValue instanceof ComponentState) {
newValue = ((ComponentState) oldValue).clone();
} else {
newValue = oldValue;
}
this.componentData.put(key, newValue);
}
}
for (Location key : src.causes.keySet()) {
Propagator.SetData oldValue = src.causes.get(key);
Propagator.SetData newValue = oldValue.cloneFor(this);
this.causes.put(key, newValue);
}
if (src.wireData != null) {
this.wireData = (CircuitWires.State) src.wireData.clone();
}
this.values.putAll(src.values);
this.dirtyComponents.addAll(src.dirtyComponents);
this.dirtyPoints.addAll(src.dirtyPoints);
}
Aggregations