Skip to content

Commit

Permalink
modified the "c" hotkey to work better in micro step mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hneemann committed Apr 30, 2022
1 parent 8b07681 commit c107474
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/main/java/de/neemann/digital/core/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,22 @@ public <A extends Runnable> A modify(A run) {
return run;
}

/**
* Modifies the model without performing a step calculation.
* Usage makes only sense in micro step simulation mode!
*
* @param run the modification to apply
* @param <A> the type of the modification
* @return the applied modification
*/
public <A extends Runnable> A modifyWithoutDoStep(A run) {
synchronized (this) {
run.run();
}
fireEvent(ModelEvent.MICROSTEP); // record the external modification as a micro step!
return run;
}

/**
* Creates a {@link SyncAccess} instance to access the model.
* If microStep is true, there is no foll step performed, in case of a user interaction.
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/de/neemann/digital/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,26 @@ private void enableClockShortcut() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (model != null && !realTimeClockRunning) {
ArrayList<Clock> cl = model.getClocks();
if (cl.size() == 1) {
model.modify(() -> {
ObservableValue clkVal = cl.get(0).getClockOutput();
clkVal.setBool(!clkVal.getBool());
});
if (stateManager.isActive(runModelMicroState)) {
if (doMicroStep.isEnabled()) {
model.doMicroStep(false);
} else {
ArrayList<Clock> cl = model.getClocks();
if (cl.size() == 1) {
model.modifyWithoutDoStep(() -> {
ObservableValue clkVal = cl.get(0).getClockOutput();
clkVal.setBool(!clkVal.getBool());
});
}
}
} else {
ArrayList<Clock> cl = model.getClocks();
if (cl.size() == 1) {
model.modify(() -> {
ObservableValue clkVal = cl.get(0).getClockOutput();
clkVal.setBool(!clkVal.getBool());
});
}
}
}
}
Expand Down

0 comments on commit c107474

Please sign in to comment.