mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-12 22:36:02 -04:00
switch behaves like an input, see #319
This commit is contained in:
parent
2db2b7d8a5
commit
34fdf0b3a9
@ -815,4 +815,9 @@ public final class Keys {
|
||||
new Key<>("wireToolTips", false);
|
||||
|
||||
|
||||
/**
|
||||
* The switch acts as input
|
||||
*/
|
||||
public static final Key<Boolean> SWITCH_ACTS_AS_INPUT =
|
||||
new Key<>("switchActsAsInput", false).setSecondary();
|
||||
}
|
||||
|
@ -25,10 +25,14 @@ public class Switch implements Element, NodeInterface, Countable {
|
||||
.addAttribute(Keys.BITS)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.POLES)
|
||||
.addAttribute(Keys.CLOSED);
|
||||
.addAttribute(Keys.CLOSED)
|
||||
.addAttribute(Keys.SWITCH_ACTS_AS_INPUT);
|
||||
|
||||
private final PlainSwitch[] poles;
|
||||
private final String label;
|
||||
private final boolean switchActsAsInput;
|
||||
private boolean closed;
|
||||
private ObservableValue value;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
@ -52,6 +56,8 @@ public class Switch implements Element, NodeInterface, Countable {
|
||||
poles = new PlainSwitch[poleCount];
|
||||
for (int i = 0; i < poleCount; i++)
|
||||
poles[i] = new PlainSwitch(bits, closed, "A" + (i + 1), "B" + (i + 1));
|
||||
label = attr.getLabel();
|
||||
switchActsAsInput = attr.get(Keys.SWITCH_ACTS_AS_INPUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,6 +85,21 @@ public class Switch implements Element, NodeInterface, Countable {
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
if (switchActsAsInput && !label.isEmpty()) {
|
||||
value = new ObservableValue(label, 1);
|
||||
value.addObserver(new NodeInterface() {
|
||||
@Override
|
||||
public ObservableValues getOutputs() {
|
||||
return value.asList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasChanged() {
|
||||
setClosed(value.getBool());
|
||||
}
|
||||
});
|
||||
model.addInput(new Signal(label, value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -93,9 +114,13 @@ public class Switch implements Element, NodeInterface, Countable {
|
||||
* @param closed true if closed
|
||||
*/
|
||||
public void setClosed(boolean closed) {
|
||||
this.closed = closed;
|
||||
for (PlainSwitch p : poles)
|
||||
p.setClosed(closed);
|
||||
if (this.closed != closed) {
|
||||
if (value != null)
|
||||
value.setBool(closed);
|
||||
this.closed = closed;
|
||||
for (PlainSwitch p : poles)
|
||||
p.setClosed(closed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1361,6 +1361,10 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="key_showTutorial">Tutorial beim Start anzeigen</string>
|
||||
<string name="key_showTutorial_tt">Aktiviert das Tutorial.</string>
|
||||
|
||||
<string name="key_switchActsAsInput">Schalter verhält sich wie ein Eingang</string>
|
||||
<string name="key_switchActsAsInput_tt">Wird das Model analysiert, verhält sich der Schalter wie ein Eingang, wobei
|
||||
"offen" einer '0' und "geschlossen" einer '1' entspricht.</string>
|
||||
|
||||
<string name="menu_exportSVGSettings">SVG Exporteinstellungen</string>
|
||||
<string name="key_SVG_LaTeX">Text im LaTeX-Format</string>
|
||||
<string name="key_SVG_LaTeX_tt">Text wird in LaTeX-Notation eingefügt. Inkscape ist für die Weiterverabeitung erforderlich.</string>
|
||||
|
@ -1347,6 +1347,9 @@
|
||||
<string name="key_showTutorial">Show Tutorial at Startup</string>
|
||||
<string name="key_showTutorial_tt">Enables the tutorial.</string>
|
||||
|
||||
<string name="key_switchActsAsInput">Switch behaves like an input</string>
|
||||
<string name="key_switchActsAsInput_tt">If the model is analyzed, the switch behaves like an input, where "open" corresponds to '0' and "closed" to '1'.</string>
|
||||
|
||||
<string name="menu_exportSVGSettings">SVG Export Settings</string>
|
||||
<string name="key_SVG_LaTeX">Text in LaTeX notation</string>
|
||||
<string name="key_SVG_LaTeX_tt">Text is inserted in LaTeX notation. Inkscape is required for further processing.</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user