Search in sources :

Example 6 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class ComponentDrawContext method drawPins.

public void drawPins(Component comp) {
    Color curColor = g.getColor();
    for (EndData e : comp.getEnds()) {
        Location pt = e.getLocation();
        if (getShowState()) {
            CircuitState state = getCircuitState();
            g.setColor(state.getValue(pt).getColor());
        } else {
            g.setColor(Color.BLACK);
        }
        g.fillOval(pt.getX() - PIN_OFFS, pt.getY() - PIN_OFFS, PIN_RAD, PIN_RAD);
    }
    g.setColor(curColor);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Color(java.awt.Color) Location(com.cburch.logisim.data.Location)

Example 7 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class Project method getCircuitState.

public CircuitState getCircuitState(Circuit circuit) {
    if (circuitState != null && circuitState.getCircuit() == circuit) {
        return circuitState;
    } else {
        CircuitState ret = stateMap.get(circuit);
        if (ret == null) {
            ret = new CircuitState(this, circuit);
            stateMap.put(circuit, ret);
        }
        return ret;
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState)

Example 8 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class Project method setCircuitState.

public void setCircuitState(CircuitState value) {
    if (value == null || circuitState == value)
        return;
    CircuitState old = circuitState;
    Circuit oldCircuit = old == null ? null : old.getCircuit();
    Circuit newCircuit = value.getCircuit();
    boolean circuitChanged = old == null || oldCircuit != newCircuit;
    if (circuitChanged) {
        Canvas canvas = frame == null ? null : frame.getCanvas();
        if (canvas != null) {
            if (tool != null)
                tool.deselect(canvas);
            Selection selection = canvas.getSelection();
            if (selection != null) {
                Action act = SelectionActions.dropAll(selection);
                if (act != null) {
                    doAction(act);
                }
            }
            if (tool != null)
                tool.select(canvas);
        }
        if (oldCircuit != null) {
            for (CircuitListener l : circuitListeners) {
                oldCircuit.removeCircuitListener(l);
            }
        }
    }
    circuitState = value;
    stateMap.put(circuitState.getCircuit(), circuitState);
    simulator.setCircuitState(circuitState);
    if (circuitChanged) {
        fireEvent(ProjectEvent.ACTION_SET_CURRENT, oldCircuit, newCircuit);
        if (newCircuit != null) {
            for (CircuitListener l : circuitListeners) {
                newCircuit.addCircuitListener(l);
            }
        }
    }
    fireEvent(ProjectEvent.ACTION_SET_STATE, old, circuitState);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) CircuitListener(com.cburch.logisim.circuit.CircuitListener) Selection(com.cburch.logisim.gui.main.Selection) Canvas(com.cburch.logisim.gui.main.Canvas) Circuit(com.cburch.logisim.circuit.Circuit)

Example 9 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class TtyInterface method loadRam.

private static boolean loadRam(CircuitState circState, File loadFile) throws IOException {
    if (loadFile == null)
        return false;
    boolean found = false;
    for (Component comp : circState.getCircuit().getNonWires()) {
        if (comp.getFactory() instanceof Ram) {
            Ram ramFactory = (Ram) comp.getFactory();
            InstanceState ramState = circState.getInstanceState(comp);
            ramFactory.loadImage(ramState, loadFile);
            found = true;
        }
    }
    for (CircuitState sub : circState.getSubstates()) {
        found |= loadRam(sub, loadFile);
    }
    return found;
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) InstanceState(com.cburch.logisim.instance.InstanceState) Component(com.cburch.logisim.comp.Component) Ram(com.cburch.logisim.std.memory.Ram)

Example 10 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class TtyInterface method prepareForTty.

private static boolean prepareForTty(CircuitState circState, ArrayList<InstanceState> keybStates) {
    boolean found = false;
    for (Component comp : circState.getCircuit().getNonWires()) {
        Object factory = comp.getFactory();
        if (factory instanceof Tty) {
            Tty ttyFactory = (Tty) factory;
            InstanceState ttyState = circState.getInstanceState(comp);
            ttyFactory.sendToStdout(ttyState);
            found = true;
        } else if (factory instanceof Keyboard) {
            keybStates.add(circState.getInstanceState(comp));
            found = true;
        }
    }
    for (CircuitState sub : circState.getSubstates()) {
        found |= prepareForTty(sub, keybStates);
    }
    return found;
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) InstanceState(com.cburch.logisim.instance.InstanceState) Keyboard(com.cburch.logisim.std.io.Keyboard) Tty(com.cburch.logisim.std.io.Tty) Component(com.cburch.logisim.comp.Component)

Aggregations

CircuitState (com.cburch.logisim.circuit.CircuitState)26 Component (com.cburch.logisim.comp.Component)6 Circuit (com.cburch.logisim.circuit.Circuit)5 ArrayList (java.util.ArrayList)4 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)3 Location (com.cburch.logisim.data.Location)3 Instance (com.cburch.logisim.instance.Instance)3 InstanceState (com.cburch.logisim.instance.InstanceState)3 Color (java.awt.Color)3 Dimension (java.awt.Dimension)3 Simulator (com.cburch.logisim.circuit.Simulator)2 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)2 Bounds (com.cburch.logisim.data.Bounds)2 Value (com.cburch.logisim.data.Value)2 LogisimFile (com.cburch.logisim.file.LogisimFile)2 Graphics (java.awt.Graphics)2 TreePath (javax.swing.tree.TreePath)2 CircuitListener (com.cburch.logisim.circuit.CircuitListener)1 SimulatorEvent (com.cburch.logisim.circuit.SimulatorEvent)1 AppearancePort (com.cburch.logisim.circuit.appear.AppearancePort)1