Search in sources :

Example 1 with ComponentState

use of com.cburch.logisim.comp.ComponentState 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);
}
Also used : HashMap(java.util.HashMap) SetData(com.cburch.logisim.circuit.Propagator.SetData) Component(com.cburch.logisim.comp.Component) ComponentState(com.cburch.logisim.comp.ComponentState) Location(com.cburch.logisim.data.Location)

Aggregations

SetData (com.cburch.logisim.circuit.Propagator.SetData)1 Component (com.cburch.logisim.comp.Component)1 ComponentState (com.cburch.logisim.comp.ComponentState)1 Location (com.cburch.logisim.data.Location)1 HashMap (java.util.HashMap)1