Search in sources :

Example 21 with Component

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);
        }
    }
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 22 with Component

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);
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 23 with Component

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();
    }
}
Also used : Pin(com.cburch.logisim.std.wiring.Pin) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Component(com.cburch.logisim.comp.Component)

Example 24 with Component

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();
    }
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 25 with Component

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);
}
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

Component (com.cburch.logisim.comp.Component)97 Location (com.cburch.logisim.data.Location)26 ArrayList (java.util.ArrayList)20 Circuit (com.cburch.logisim.circuit.Circuit)19 AttributeSet (com.cburch.logisim.data.AttributeSet)13 Wire (com.cburch.logisim.circuit.Wire)12 Bounds (com.cburch.logisim.data.Bounds)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 EndData (com.cburch.logisim.comp.EndData)8 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)8 Project (com.cburch.logisim.proj.Project)7 Pin (com.cburch.logisim.std.wiring.Pin)7 Graphics (java.awt.Graphics)7 CircuitState (com.cburch.logisim.circuit.CircuitState)6 Splitter (com.cburch.logisim.circuit.Splitter)6 Selection (com.cburch.logisim.gui.main.Selection)6 InstanceState (com.cburch.logisim.instance.InstanceState)5