mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 22:41:59 -04:00
Added "restore all fuses" and "make actual state the default input state" to the
undo event sourcing system.
This commit is contained in:
parent
e0d89eadc2
commit
7d398024f7
@ -17,9 +17,7 @@ import de.neemann.digital.draw.graphics.Graphic;
|
|||||||
import de.neemann.digital.draw.graphics.Polygon;
|
import de.neemann.digital.draw.graphics.Polygon;
|
||||||
import de.neemann.digital.draw.graphics.Style;
|
import de.neemann.digital.draw.graphics.Style;
|
||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
import de.neemann.digital.draw.library.ElementLibrary;
|
|
||||||
import de.neemann.digital.draw.shapes.Drawable;
|
import de.neemann.digital.draw.shapes.Drawable;
|
||||||
import de.neemann.digital.draw.shapes.InputShape;
|
|
||||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||||
import de.neemann.digital.gui.components.AttributeDialog;
|
import de.neemann.digital.gui.components.AttributeDialog;
|
||||||
import de.neemann.digital.gui.sync.NoSync;
|
import de.neemann.digital.gui.sync.NoSync;
|
||||||
@ -615,34 +613,6 @@ public class Circuit {
|
|||||||
this.measurementOrdering = measurementOrdering;
|
this.measurementOrdering = measurementOrdering;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes actual input values to the default value
|
|
||||||
*/
|
|
||||||
public void actualToDefault() {
|
|
||||||
for (VisualElement ve : visualElements)
|
|
||||||
if (ve.equalsDescription(In.DESCRIPTION)) {
|
|
||||||
ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue();
|
|
||||||
if (ov != null) {
|
|
||||||
ve.getElementAttributes().set(Keys.DEFAULT, (int) ov.getValue());
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All fuses (diodes) are restored to "not programed" so that they are working again.
|
|
||||||
*
|
|
||||||
* @param library library to determine which elements are programmable
|
|
||||||
*/
|
|
||||||
public void restoreAllFuses(ElementLibrary library) {
|
|
||||||
for (VisualElement ve : visualElements)
|
|
||||||
if (library.isProgrammable(ve.getElementName())) {
|
|
||||||
ve.getElementAttributes().set(Keys.BLOWN, false);
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a rectangle to the circuit.
|
* Add a rectangle to the circuit.
|
||||||
* Only used to debug the {@link de.neemann.digital.builder.circuit.CircuitBuilder}.
|
* Only used to debug the {@link de.neemann.digital.builder.circuit.CircuitBuilder}.
|
||||||
|
@ -557,7 +557,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
ToolTipAction actualToDefault = new ToolTipAction(Lang.get("menu_actualToDefault")) {
|
ToolTipAction actualToDefault = new ToolTipAction(Lang.get("menu_actualToDefault")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
circuitComponent.getCircuit().actualToDefault();
|
circuitComponent.actualToDefault();
|
||||||
stoppedState.enter();
|
stoppedState.enter();
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_actualToDefault_tt"));
|
}.setToolTip(Lang.get("menu_actualToDefault_tt"));
|
||||||
@ -565,7 +565,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
ToolTipAction restoreAllFuses = new ToolTipAction(Lang.get("menu_restoreAllFuses")) {
|
ToolTipAction restoreAllFuses = new ToolTipAction(Lang.get("menu_restoreAllFuses")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
circuitComponent.getCircuit().restoreAllFuses(library);
|
circuitComponent.restoreAllFuses();
|
||||||
stoppedState.enter();
|
stoppedState.enter();
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_restoreAllFuses_tt"));
|
}.setToolTip(Lang.get("menu_restoreAllFuses_tt"));
|
||||||
|
@ -4,7 +4,9 @@ import de.neemann.digital.core.NodeException;
|
|||||||
import de.neemann.digital.core.ObservableValue;
|
import de.neemann.digital.core.ObservableValue;
|
||||||
import de.neemann.digital.core.Observer;
|
import de.neemann.digital.core.Observer;
|
||||||
import de.neemann.digital.core.element.*;
|
import de.neemann.digital.core.element.*;
|
||||||
|
import de.neemann.digital.core.io.In;
|
||||||
import de.neemann.digital.draw.elements.*;
|
import de.neemann.digital.draw.elements.*;
|
||||||
|
import de.neemann.digital.draw.shapes.InputShape;
|
||||||
import de.neemann.digital.gui.components.modification.*;
|
import de.neemann.digital.gui.components.modification.*;
|
||||||
import de.neemann.digital.draw.graphics.*;
|
import de.neemann.digital.draw.graphics.*;
|
||||||
import de.neemann.digital.draw.library.ElementLibrary;
|
import de.neemann.digital.draw.library.ElementLibrary;
|
||||||
@ -260,12 +262,11 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
return new ToolTipAction(Lang.get("menu_cut")) {
|
return new ToolTipAction(Lang.get("menu_cut")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ArrayList<Movable> elements = null;
|
|
||||||
if (activeMouseController instanceof MouseControllerSelect) {
|
if (activeMouseController instanceof MouseControllerSelect) {
|
||||||
MouseControllerSelect mcs = ((MouseControllerSelect) activeMouseController);
|
MouseControllerSelect mcs = ((MouseControllerSelect) activeMouseController);
|
||||||
Vector min = Vector.min(mcs.corner1, mcs.corner2);
|
Vector min = Vector.min(mcs.corner1, mcs.corner2);
|
||||||
Vector max = Vector.max(mcs.corner1, mcs.corner2);
|
Vector max = Vector.max(mcs.corner1, mcs.corner2);
|
||||||
elements = circuit.getElementsToCopy(min, max, shapeFactory);
|
ArrayList<Movable> elements = circuit.getElementsToCopy(min, max, shapeFactory);
|
||||||
if (elements != null) {
|
if (elements != null) {
|
||||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
clipboard.setContents(new CircuitTransferable(elements), null);
|
clipboard.setContents(new CircuitTransferable(elements), null);
|
||||||
@ -829,6 +830,39 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
return redoAction;
|
return redoAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes actual input values to the default value
|
||||||
|
*/
|
||||||
|
public void actualToDefault() {
|
||||||
|
Modifications.Builder builder = new Modifications.Builder();
|
||||||
|
for (VisualElement ve : circuit.getElements())
|
||||||
|
if (ve.equalsDescription(In.DESCRIPTION)) {
|
||||||
|
ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue();
|
||||||
|
if (ov != null) {
|
||||||
|
int newValue = (int) ov.getValue();
|
||||||
|
int oldValue = ve.getElementAttributes().get(Keys.DEFAULT);
|
||||||
|
if (newValue != oldValue)
|
||||||
|
builder.add(new ModifyAttribute<>(ve, Keys.DEFAULT, newValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modify(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All fuses (diodes) are restored to "not programed" so that they are working again.
|
||||||
|
*/
|
||||||
|
public void restoreAllFuses() {
|
||||||
|
Modifications.Builder builder = new Modifications.Builder();
|
||||||
|
for (VisualElement ve : circuit.getElements())
|
||||||
|
if (library.isProgrammable(ve.getElementName())) {
|
||||||
|
if (ve.getElementAttributes().get(Keys.BLOWN))
|
||||||
|
builder.add(new ModifyAttribute<>(ve, Keys.BLOWN, false));
|
||||||
|
}
|
||||||
|
modify(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private final class PlusMinusAction extends ToolTipAction {
|
private final class PlusMinusAction extends ToolTipAction {
|
||||||
private final int delta;
|
private final int delta;
|
||||||
|
|
||||||
@ -855,7 +889,6 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
} catch (ElementNotFoundException e1) {
|
} catch (ElementNotFoundException e1) {
|
||||||
// do nothing on error
|
// do nothing on error
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1288,7 +1321,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic gr) {
|
public void drawTo(Graphic gr) {
|
||||||
wire.drawTo(gr, false);
|
wire.drawTo(gr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1373,8 +1406,8 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic gr) {
|
public void drawTo(Graphic gr) {
|
||||||
wire1.drawTo(gr, false);
|
wire1.drawTo(gr, true);
|
||||||
wire2.drawTo(gr, false);
|
wire2.drawTo(gr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user