Refined "finish micro steps" action. See #284

This commit is contained in:
hneemann 2019-07-18 09:48:44 +02:00
parent dbd3a99924
commit cd7ddd364b
4 changed files with 40 additions and 45 deletions

View File

@ -335,25 +335,27 @@ public class Model implements Iterable<Node>, SyncAccess {
}
}
/**
* Completes the actual micro step session to a full step.
*
* @param noise true if noise should be enabled
* @throws NodeException NodeException
*/
public void finishMicroSteps(boolean noise) throws NodeException {
public void runToBreakMicro() throws NodeException {
ArrayList<BreakDetector> brVal = new ArrayList<>();
for (Break b : breaks)
brVal.add(new BreakDetector(b));
stepWithCondition(noise, () -> {
boolean wasBreak = false;
for (BreakDetector bd : brVal)
if (bd.detected()) {
fireEvent(ModelEvent.BREAK);
wasBreak = true;
}
return needsUpdate() && !wasBreak;
});
ObservableValue clkVal = clocks.get(0).getClockOutput();
fireEvent(ModelEvent.FASTRUN);
final boolean[] wasBreak = {false};
while (!wasBreak[0]) {
if (!needsUpdate())
clkVal.setBool(!clkVal.getBool());
stepWithCondition(false, () -> {
for (BreakDetector bd : brVal)
if (bd.detected()) {
fireEvent(ModelEvent.BREAK);
wasBreak[0] = true;
}
return needsUpdate() && !wasBreak[0];
});
}
}
/**

View File

@ -132,7 +132,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
private final boolean keepPrefMainFile;
private ToolTipAction doStep;
private ToolTipAction finishStep;
private ToolTipAction runToBreakMicroAction;
private ToolTipAction runToBreakAction;
private ToolTipAction showMeasurementDialog;
private ToolTipAction showMeasurementGraph;
@ -954,28 +954,26 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
circuitComponent.graphicHasChanged();
final boolean needsUpdate = model.needsUpdate();
doStep.setEnabled(needsUpdate);
finishStep.setEnabled(needsUpdate);
} catch (Exception e1) {
showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1);
}
}
}.setToolTip(Lang.get("menu_step_tt"));
finishStep = new ToolTipAction(Lang.get("menu_stepFinish"), ICON_STEP_FINISH) {
runToBreakMicroAction = new ToolTipAction(Lang.get("menu_runToBreakMicro"), ICON_STEP_FINISH) {
@Override
public void actionPerformed(ActionEvent e) {
try {
model.finishMicroSteps(false);
model.runToBreakMicro();
circuitComponent.removeHighLighted();
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
circuitComponent.graphicHasChanged();
final boolean needsUpdate = model.needsUpdate();
doStep.setEnabled(needsUpdate);
finishStep.setEnabled(needsUpdate);
} catch (Exception e1) {
showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1);
}
}
}.setToolTip(Lang.get("menu_stepFinish_tt"));
}.setToolTip(Lang.get("menu_runToBreakMicro_tt")).setEnabledChain(false);
ToolTipAction runModelAction = runModelState.createToolTipAction(Lang.get("menu_run"), ICON_RUN)
.setToolTip(Lang.get("menu_run_tt"));
@ -1098,7 +1096,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
run.addSeparator();
run.add(runModelMicroAction.createJMenuItem());
run.add(doStep.createJMenuItem());
run.add(finishStep.createJMenuItem());
run.add(runToBreakMicroAction.createJMenuItem());
run.addSeparator();
run.add(runTests.createJMenuItem());
run.add(runAllTests.createJMenuItem());
@ -1106,7 +1104,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
run.add(speedTest.createJMenuItem());
run.add(stats.createJMenuItem());
doStep.setEnabled(false);
finishStep.setEnabled(false);
toolBar.add(runModelState.setIndicator(runModelAction.createJButtonNoText()));
toolBar.add(runToBreakAction.createJButtonNoText());
@ -1114,7 +1111,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
toolBar.addSeparator();
toolBar.add(runModelMicroState.setIndicator(runModelMicroAction.createJButtonNoText()));
toolBar.add(doStep.createJButtonNoText());
toolBar.add(finishStep.createJButtonNoText());
toolBar.add(runToBreakMicroAction.createJButtonNoText());
toolBar.addSeparator();
toolBar.add(runTests.createJButtonNoText());
}
@ -1251,11 +1248,11 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
clearModelDescription();
circuitComponent.setModeAndReset(false, SyncAccess.NOSYNC);
doStep.setEnabled(false);
finishStep.setEnabled(false);
stoppedState.getAction().setEnabled(false);
showMeasurementDialog.setEnabled(false);
showMeasurementGraph.setEnabled(false);
runToBreakAction.setEnabled(false);
runToBreakMicroAction.setEnabled(false);
runTests.setEnabled(true);
// keep errors
if (circuitComponent.getHighLightStyle() != Style.ERROR)
@ -1369,8 +1366,12 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
handleKeyboardComponent(updateEvent);
doStep.setEnabled(false);
finishStep.setEnabled(false);
runToBreakAction.setEnabled(!realTimeClockRunning && model.isRunToBreakAllowed());
if (!realTimeClockRunning && model.isRunToBreakAllowed()) {
if (updateEvent == ModelEvent.MICROSTEP)
runToBreakMicroAction.setEnabled(true);
else
runToBreakAction.setEnabled(true);
}
ElementAttributes settings = circuitComponent.getCircuit().getAttributes();
if (settings.get(Keys.SHOW_DATA_TABLE) || windowPosManager.isVisible("probe"))
@ -1390,11 +1391,8 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
model.init();
if (updateEvent == ModelEvent.MICROSTEP) {
final boolean needsUpdate = model.needsUpdate();
doStep.setEnabled(needsUpdate);
finishStep.setEnabled(needsUpdate);
}
if (updateEvent == ModelEvent.MICROSTEP)
doStep.setEnabled(model.needsUpdate());
return true;
} catch (NodeException | PinException | RuntimeException | ElementNotFoundException e) {
@ -1415,9 +1413,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
keyboard.hasChanged();
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
model.fireManualChangeEvent();
final boolean needsUpdate = model.needsUpdate();
doStep.setEnabled(needsUpdate);
finishStep.setEnabled(needsUpdate);
doStep.setEnabled(model.needsUpdate());
circuitComponent.graphicHasChanged();
};
else
@ -1650,11 +1646,8 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
model.fireManualChangeEvent();
circuitComponent.graphicHasChanged();
if (!realTimeClockRunning) {
final boolean needsUpdate = model.needsUpdate();
doStep.setEnabled(needsUpdate);
finishStep.setEnabled(needsUpdate);
}
if (!realTimeClockRunning)
doStep.setEnabled(model.needsUpdate());
}
}

View File

@ -1448,8 +1448,8 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="menu_speedTest_tt">Führt einen Geschwindigkeitstest durch. Es wird die maximal mögliche Taktfrequenz ermittelt</string>
<string name="menu_step">Gatterschritt</string>
<string name="menu_step_tt">Führt einen Einzelgatterschritt aus</string>
<string name="menu_stepFinish">Gatterschritte beenden</string>
<string name="menu_stepFinish_tt">Führt alle Einzelgatterschritte aus, bis die Schaltung sich stabilisiert hat oder eine steigende Flanke an einem Break-Element erkannt wird.</string>
<string name="menu_runToBreakMicro">Run To Break im Gatterschrittmodus</string>
<string name="menu_runToBreakMicro_tt">Führt alle Einzelgatterschritte aus, bis eine steigende Flanke an einem Break-Element erkannt wird.</string>
<string name="menu_synthesise">Synthese</string>
<string name="menu_synthesise_tt">Erzeugt minimale boolsche Ausdrücke, welche durch eine Wahrheitstabelle beschrieben werden.</string>
<string name="menu_table_N_variables">{0} Variablen</string>

View File

@ -1433,8 +1433,8 @@
<string name="menu_speedTest_tt">Performs a speed test by calculating the max. clock frequency.</string>
<string name="menu_step">Gate Step</string>
<string name="menu_step_tt">Calculates a single gate step</string>
<string name="menu_stepFinish">Finish Gate Step</string>
<string name="menu_stepFinish_tt">Executes all single gate steps until the circuit has stabilized or a rising edge is detected on a break component.</string>
<string name="menu_runToBreakMicro">Run To Break in Single Gate Mode</string>
<string name="menu_runToBreakMicro_tt">Executes all single gate steps until a rising edge is detected on a break component.</string>
<string name="menu_synthesise">Synthesise</string>
<string name="menu_synthesise_tt">Generates the minimal bool expressions described by a truth table.</string>
<string name="menu_table_N_variables">{0} variables</string>