Search in sources :

Example 1 with Simulator

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

the class SimulationExplorer method projectChanged.

// 
// ProjectListener methods
// 
public void projectChanged(ProjectEvent event) {
    int action = event.getAction();
    if (action == ProjectEvent.ACTION_SET_STATE) {
        Simulator sim = project.getSimulator();
        CircuitState root = sim.getCircuitState();
        if (model.getRootState() != root) {
            model = new SimulationTreeModel(root);
            tree.setModel(model);
        }
        model.setCurrentView(project.getCircuitState());
        TreePath path = model.mapToPath(project.getCircuitState());
        if (path != null) {
            tree.scrollPathToVisible(path);
        }
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) TreePath(javax.swing.tree.TreePath) Simulator(com.cburch.logisim.circuit.Simulator)

Example 2 with Simulator

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

the class MenuSimulate method setCurrentState.

public void setCurrentState(Simulator sim, CircuitState value) {
    if (currentState == value) {
        return;
    }
    Simulator oldSim = currentSim;
    CircuitState oldState = currentState;
    currentSim = sim;
    currentState = value;
    if (bottomState == null) {
        bottomState = currentState;
    } else if (currentState == null) {
        bottomState = null;
    } else {
        CircuitState cur = bottomState;
        while (cur != null && cur != currentState) {
            cur = cur.getParentState();
        }
        if (cur == null) {
            bottomState = currentState;
        }
    }
    boolean oldPresent = oldState != null;
    boolean present = currentState != null;
    if (oldPresent != present) {
        computeEnabled();
    }
    if (currentSim != oldSim) {
        double freq = currentSim == null ? 1.0 : currentSim.getTickFrequency();
        for (int i = 0; i < tickFreqs.length; i++) {
            tickFreqs[i].setSelected(Math.abs(tickFreqs[i].freq - freq) < 0.001);
        }
        if (oldSim != null) {
            oldSim.removeSimulatorListener(myListener);
        }
        if (currentSim != null) {
            currentSim.addSimulatorListener(myListener);
        }
        myListener.simulatorStateChanged(new SimulatorEvent(sim));
    }
    clearItems(downStateItems);
    CircuitState cur = bottomState;
    while (cur != null && cur != currentState) {
        downStateItems.add(new CircuitStateMenuItem(cur));
        cur = cur.getParentState();
    }
    if (cur != null) {
        cur = cur.getParentState();
    }
    clearItems(upStateItems);
    while (cur != null) {
        upStateItems.add(0, new CircuitStateMenuItem(cur));
        cur = cur.getParentState();
    }
    recreateStateMenus();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) SimulatorEvent(com.cburch.logisim.circuit.SimulatorEvent) Simulator(com.cburch.logisim.circuit.Simulator)

Example 3 with Simulator

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

the class MenuSimulate method computeEnabled.

@Override
void computeEnabled() {
    boolean present = currentState != null;
    Simulator sim = this.currentSim;
    boolean simRunning = sim != null && sim.isRunning();
    setEnabled(present);
    run.setEnabled(present);
    reset.setEnabled(present);
    step.setEnabled(present && !simRunning);
    simulate_vhdl_enable.setEnabled(present);
    vhdl_sim_files.setEnabled(present);
    upStateMenu.setEnabled(present);
    downStateMenu.setEnabled(present);
    tickOnce.setEnabled(present);
    tickOnceMain.setEnabled(present);
    ticksEnabled.setEnabled(present && simRunning);
    tickFreq.setEnabled(present);
    menubar.fireEnableChanged();
}
Also used : Simulator(com.cburch.logisim.circuit.Simulator)

Example 4 with Simulator

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

the class SimulationToolbarModel method stateChanged.

// 
// ChangeListener methods
// 
public void stateChanged(ChangeEvent e) {
    Simulator sim = project.getSimulator();
    boolean running = sim != null && sim.isRunning();
    boolean ticking = sim != null && sim.isTicking();
    simEnable.setIcon(running ? "simstop.png" : "simplay.png");
    simEnable.setToolTip(running ? Strings.getter("simulateDisableStepsTip") : Strings.getter("simulateEnableStepsTip"));
    tickEnable.setIcon(ticking ? "simtstop.png" : "simtplay.png");
    tickEnable.setToolTip(ticking ? Strings.getter("simulateDisableTicksTip") : Strings.getter("simulateEnableTicksTip"));
    fireToolbarAppearanceChanged();
}
Also used : Simulator(com.cburch.logisim.circuit.Simulator)

Example 5 with Simulator

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

the class TickCounter method tickCompleted.

public void tickCompleted(SimulatorEvent e) {
    Simulator sim = e.getSource();
    if (!sim.isTicking()) {
        queueSize = 0;
    } else {
        double freq = sim.getTickFrequency();
        if (freq != tickFrequency) {
            queueSize = 0;
            tickFrequency = freq;
        }
        int curSize = queueSize;
        int maxSize = queueTimes.length;
        int start = queueStart;
        int end;
        if (curSize < maxSize) {
            // new sample is added into queue
            end = start + curSize;
            if (end >= maxSize) {
                end -= maxSize;
            }
            curSize++;
            queueSize = curSize;
        } else {
            // new sample replaces oldest value in queue
            end = queueStart;
            if (end + 1 >= maxSize) {
                queueStart = 0;
            } else {
                queueStart = end + 1;
            }
        }
        long startTime = queueTimes[start];
        long endTime = System.currentTimeMillis();
        double rate;
        if (startTime == endTime || curSize <= 1) {
            rate = Double.MAX_VALUE;
        } else {
            rate = 1000.0 * (curSize - 1) / (endTime - startTime);
        }
        queueTimes[end] = endTime;
        queueRates[end] = rate;
    }
}
Also used : Simulator(com.cburch.logisim.circuit.Simulator)

Aggregations

Simulator (com.cburch.logisim.circuit.Simulator)5 CircuitState (com.cburch.logisim.circuit.CircuitState)2 SimulatorEvent (com.cburch.logisim.circuit.SimulatorEvent)1 TreePath (javax.swing.tree.TreePath)1