{
super(model, "dff12", name, "D flip flop\n12 bits");
setSize(40, 20);
- addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 20), Position.TOP);
- addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 10), Position.RIGHT);
- addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 20, 20), Position.TOP);
+ addPin(new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 10), Position.RIGHT);
+ addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
}
@Override
{
super(model, "dff4_finewe", name, "D flip flop\n4 bits");
setSize(35, 90);
- addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
- addPin(new Pin(this, "_WE1", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
- addPin(new Pin(this, "_WE2", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
- addPin(new Pin(this, "_WE3", 1, PinUsage.INPUT, 0, 35), Position.RIGHT);
- addPin(new Pin(this, "_WE4", 1, PinUsage.INPUT, 0, 45), Position.RIGHT);
- addPin(new Pin(this, "D1", 1, PinUsage.INPUT, 0, 55), Position.RIGHT);
- addPin(new Pin(this, "D2", 1, PinUsage.INPUT, 0, 65), Position.RIGHT);
- addPin(new Pin(this, "D3", 1, PinUsage.INPUT, 0, 75), Position.RIGHT);
- addPin(new Pin(this, "D4", 1, PinUsage.INPUT, 0, 85), Position.RIGHT);
- addPin(new Pin(this, "Q1", 1, PinUsage.OUTPUT, 35, 5), Position.LEFT);
- addPin(new Pin(this, "Q2", 1, PinUsage.OUTPUT, 35, 15), Position.LEFT);
- addPin(new Pin(this, "Q3", 1, PinUsage.OUTPUT, 35, 25), Position.LEFT);
- addPin(new Pin(this, "Q4", 1, PinUsage.OUTPUT, 35, 35), Position.LEFT);
+ addPin(new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
+ addPin(new Pin(model, this, "_WE1", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
+ addPin(new Pin(model, this, "_WE2", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
+ addPin(new Pin(model, this, "_WE3", 1, PinUsage.INPUT, 0, 35), Position.RIGHT);
+ addPin(new Pin(model, this, "_WE4", 1, PinUsage.INPUT, 0, 45), Position.RIGHT);
+ addPin(new Pin(model, this, "D1", 1, PinUsage.INPUT, 0, 55), Position.RIGHT);
+ addPin(new Pin(model, this, "D2", 1, PinUsage.INPUT, 0, 65), Position.RIGHT);
+ addPin(new Pin(model, this, "D3", 1, PinUsage.INPUT, 0, 75), Position.RIGHT);
+ addPin(new Pin(model, this, "D4", 1, PinUsage.INPUT, 0, 85), Position.RIGHT);
+ addPin(new Pin(model, this, "Q1", 1, PinUsage.OUTPUT, 35, 5), Position.LEFT);
+ addPin(new Pin(model, this, "Q2", 1, PinUsage.OUTPUT, 35, 15), Position.LEFT);
+ addPin(new Pin(model, this, "Q3", 1, PinUsage.OUTPUT, 35, 25), Position.LEFT);
+ addPin(new Pin(model, this, "Q4", 1, PinUsage.OUTPUT, 35, 35), Position.LEFT);
}
@Override
{
super(model, "inc12", name, "Incrementer");
setSize(40, 20);
- addPin(new Pin(this, "A", 12, PinUsage.INPUT, 20, 20), Position.TOP);
- addPin(new Pin(this, "CI", 1, PinUsage.INPUT, 40, 10), Position.LEFT);
- addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "A", 12, PinUsage.INPUT, 20, 20), Position.TOP);
+ addPin(new Pin(model, this, "CI", 1, PinUsage.INPUT, 40, 10), Position.LEFT);
+ addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
}
@Override
{
super(model, "nor12", name, "=0");
setSize(35, 20);
- addPin(new Pin(this, "D", 12, PinUsage.INPUT, 0, 10), Position.RIGHT);
- addPin(new Pin(this, "Y", 1, PinUsage.OUTPUT, 35, 10), Position.LEFT);
+ addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 0, 10), Position.RIGHT);
+ addPin(new Pin(model, this, "Y", 1, PinUsage.OUTPUT, 35, 10), Position.LEFT);
}
@Override
{
super(model, "ram5_12", name, "RAM\n5 x 12 Bit");
setSize(40, 40);
- addPin(new Pin(this, "A", 3, PinUsage.INPUT, 10, 0), Position.BOTTOM);
- addPin(new Pin(this, "B", 3, PinUsage.INPUT, 30, 0), Position.BOTTOM);
- addPin(new Pin(this, "WE", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
- addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
- addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 0, 30), Position.RIGHT);
- addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 40), Position.TOP);
+ addPin(new Pin(model, this, "A", 3, PinUsage.INPUT, 10, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "B", 3, PinUsage.INPUT, 30, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "WE", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
+ addPin(new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
+ addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 0, 30), Position.RIGHT);
+ addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 20, 40), Position.TOP);
}
@Override
{
super(model, "sel4_12", name, "4-way SEL\n12 bit");
setSize(80, 40);
- addPin(new Pin(this, "SA", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
- addPin(new Pin(this, "SB", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
- addPin(new Pin(this, "SC", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
- addPin(new Pin(this, "SD", 1, PinUsage.INPUT, 0, 35), Position.RIGHT);
- addPin(new Pin(this, "A", 12, PinUsage.INPUT, 10, 0), Position.BOTTOM);
- addPin(new Pin(this, "B", 12, PinUsage.INPUT, 30, 0), Position.BOTTOM);
- addPin(new Pin(this, "C", 12, PinUsage.INPUT, 50, 0), Position.BOTTOM);
- addPin(new Pin(this, "D", 12, PinUsage.INPUT, 70, 0), Position.BOTTOM);
- addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 40, 40), Position.TOP);
+ addPin(new Pin(model, this, "SA", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
+ addPin(new Pin(model, this, "SB", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
+ addPin(new Pin(model, this, "SC", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
+ addPin(new Pin(model, this, "SD", 1, PinUsage.INPUT, 0, 35), Position.RIGHT);
+ addPin(new Pin(model, this, "A", 12, PinUsage.INPUT, 10, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "B", 12, PinUsage.INPUT, 30, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "C", 12, PinUsage.INPUT, 50, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 70, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 40, 40), Position.TOP);
}
@Override
{
super(model, "Am2904RegCTInstrDecode", name, "Instruction\ndecode");
setSize(80, 80);
- addPin(new Pin(this, "I12-11", 2, PinUsage.INPUT, 0, 30), Position.RIGHT);
- addPin(new Pin(this, "I5-0", 6, PinUsage.INPUT, 0, 50), Position.RIGHT);
+ addPin(new Pin(model, this, "I12-11", 2, PinUsage.INPUT, 0, 30), Position.RIGHT);
+ addPin(new Pin(model, this, "I5-0", 6, PinUsage.INPUT, 0, 50), Position.RIGHT);
// muSR MUX:
// 00: 0
// 01: 1
// 10: M
// 11: I
- addPin(new Pin(this, "muSR_MUX", 2, PinUsage.OUTPUT, 80, 10), Position.LEFT);
- addPin(new Pin(this, "muSR_OVRRET", 1, PinUsage.OUTPUT, 80, 20), Position.LEFT);
- addPin(new Pin(this, "muSR_CINV", 1, PinUsage.OUTPUT, 80, 30), Position.LEFT);
- addPin(new Pin(this, "muSR_WEZ", 1, PinUsage.OUTPUT, 80, 40), Position.LEFT);
- addPin(new Pin(this, "muSR_WEC", 1, PinUsage.OUTPUT, 80, 50), Position.LEFT);
- addPin(new Pin(this, "muSR_WEN", 1, PinUsage.OUTPUT, 80, 60), Position.LEFT);
- addPin(new Pin(this, "muSR_WEOVR", 1, PinUsage.OUTPUT, 80, 70), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_MUX", 2, PinUsage.OUTPUT, 80, 10), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_OVRRET", 1, PinUsage.OUTPUT, 80, 20), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_CINV", 1, PinUsage.OUTPUT, 80, 30), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_WEZ", 1, PinUsage.OUTPUT, 80, 40), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_WEC", 1, PinUsage.OUTPUT, 80, 50), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_WEN", 1, PinUsage.OUTPUT, 80, 60), Position.LEFT);
+ addPin(new Pin(model, this, "muSR_WEOVR", 1, PinUsage.OUTPUT, 80, 70), Position.LEFT);
// MSR MUX:
// 000: 0
// 001: 1
// 101: I, invert C
// 110: Swap OVR and C
// 111: _M
- addPin(new Pin(this, "MSR_MUX", 3, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
- addPin(new Pin(this, "OEN", 1, PinUsage.OUTPUT, 60, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "MSR_MUX", 3, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "OEN", 1, PinUsage.OUTPUT, 60, 0), Position.BOTTOM);
// Y MUX:
// 00: mu
// 01: mu
// 10: M
// 11: I
- addPin(new Pin(this, "Y_MUX", 2, PinUsage.OUTPUT, 10, 80), Position.TOP);
+ addPin(new Pin(model, this, "Y_MUX", 2, PinUsage.OUTPUT, 10, 80), Position.TOP);
// CT MUX:
// see Am2900 Family Data Book, Am2904, Table 4 (CT_MUX2-0 = I3-1)
- addPin(new Pin(this, "CT_MUX", 3, PinUsage.OUTPUT, 30, 80), Position.TOP);
- addPin(new Pin(this, "CT_INV", 1, PinUsage.OUTPUT, 40, 80), Position.TOP);
- addPin(new Pin(this, "CT_EXP", 1, PinUsage.OUTPUT, 50, 80), Position.TOP);
+ addPin(new Pin(model, this, "CT_MUX", 3, PinUsage.OUTPUT, 30, 80), Position.TOP);
+ addPin(new Pin(model, this, "CT_INV", 1, PinUsage.OUTPUT, 40, 80), Position.TOP);
+ addPin(new Pin(model, this, "CT_EXP", 1, PinUsage.OUTPUT, 50, 80), Position.TOP);
// C0 MUX:
// 00xx: 0
// 01xx: 1
// 1101: _muC
// 1110: MC
// 1111: _MC
- addPin(new Pin(this, "C0_MUX", 4, PinUsage.OUTPUT, 70, 80), Position.TOP);
+ addPin(new Pin(model, this, "C0_MUX", 4, PinUsage.OUTPUT, 70, 80), Position.TOP);
}
@Override
{
super(model, "Am2904ShiftInstrDecode", name, "Shift \ninstruction\ndecode");
setSize(60, 80);
- addPin(new Pin(this, "I", 5, PinUsage.INPUT, 0, 25), Position.RIGHT);
- addPin(new Pin(this, "_SE", 1, PinUsage.INPUT, 0, 55), Position.RIGHT);
+ addPin(new Pin(model, this, "I", 5, PinUsage.INPUT, 0, 25), Position.RIGHT);
+ addPin(new Pin(model, this, "_SE", 1, PinUsage.INPUT, 0, 55), Position.RIGHT);
// SIO0 MUX:
// 000: 0
// 001: 1
// 01x: SIOn
// 10x: QIOn
// 11x: MC
- addPin(new Pin(this, "SIO0_MUX", 3, PinUsage.OUTPUT, 60, 5), Position.LEFT);
+ addPin(new Pin(model, this, "SIO0_MUX", 3, PinUsage.OUTPUT, 60, 5), Position.LEFT);
// SIOn MUX:
// 000: 0
// 001: 1
// 101: MN
// 110: IC
// 111: IN xor IVOR
- addPin(new Pin(this, "SIOn_MUX", 3, PinUsage.OUTPUT, 60, 15), Position.LEFT);
+ addPin(new Pin(model, this, "SIOn_MUX", 3, PinUsage.OUTPUT, 60, 15), Position.LEFT);
// QIO0 MUX:
// 000: 0
// 001: 1
// 01x: SIOn
// 10x: QIOn
// 11x: MC
- addPin(new Pin(this, "QIO0_MUX", 3, PinUsage.OUTPUT, 60, 25), Position.LEFT);
+ addPin(new Pin(model, this, "QIO0_MUX", 3, PinUsage.OUTPUT, 60, 25), Position.LEFT);
// QIOn MUX:
// 000: 0
// 001: 1
// 01x: SIO0
// 10x: QIO0
// 11x: MN
- addPin(new Pin(this, "QIOn_MUX", 3, PinUsage.OUTPUT, 60, 35), Position.LEFT);
- addPin(new Pin(this, "OEn", 1, PinUsage.OUTPUT, 60, 45), Position.LEFT);
- addPin(new Pin(this, "OE0", 1, PinUsage.OUTPUT, 60, 55), Position.LEFT);
+ addPin(new Pin(model, this, "QIOn_MUX", 3, PinUsage.OUTPUT, 60, 35), Position.LEFT);
+ addPin(new Pin(model, this, "OEn", 1, PinUsage.OUTPUT, 60, 45), Position.LEFT);
+ addPin(new Pin(model, this, "OE0", 1, PinUsage.OUTPUT, 60, 55), Position.LEFT);
// 00: SIO0
// 01: QIO0
// 1x: SIOn
- addPin(new Pin(this, "MC_MUX", 2, PinUsage.OUTPUT, 60, 65), Position.LEFT);
- addPin(new Pin(this, "MC_EN", 1, PinUsage.OUTPUT, 60, 75), Position.LEFT);
+ addPin(new Pin(model, this, "MC_MUX", 2, PinUsage.OUTPUT, 60, 65), Position.LEFT);
+ addPin(new Pin(model, this, "MC_EN", 1, PinUsage.OUTPUT, 60, 75), Position.LEFT);
}
@Override
{
super(model, "Am2910InstrPLA", name, "Instr.\nPLA");
setSize(30, 85);
- addPin(new Pin(this, "PASS", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
- addPin(new Pin(this, "I", 4, PinUsage.INPUT, 0, 20), Position.RIGHT);
- addPin(new Pin(this, "R=0", 1, PinUsage.INPUT, 15, 0), Position.BOTTOM);
- addPin(new Pin(this, "_PL", 1, PinUsage.OUTPUT, 5, 85), Position.TOP);
- addPin(new Pin(this, "_MAP", 1, PinUsage.OUTPUT, 15, 85), Position.TOP);
- addPin(new Pin(this, "_VECT", 1, PinUsage.OUTPUT, 25, 85), Position.TOP);
- addPin(new Pin(this, "RWE", 1, PinUsage.OUTPUT, 30, 5), Position.LEFT);
- addPin(new Pin(this, "RDEC", 1, PinUsage.OUTPUT, 30, 15), Position.LEFT);
- addPin(new Pin(this, "YD", 1, PinUsage.OUTPUT, 30, 25), Position.LEFT);
- addPin(new Pin(this, "YR", 1, PinUsage.OUTPUT, 30, 35), Position.LEFT);
- addPin(new Pin(this, "YF", 1, PinUsage.OUTPUT, 30, 45), Position.LEFT);
- addPin(new Pin(this, "YmuPC", 1, PinUsage.OUTPUT, 30, 55), Position.LEFT);
- addPin(new Pin(this, "STKI0", 1, PinUsage.OUTPUT, 30, 65), Position.LEFT);
- addPin(new Pin(this, "STKI1", 1, PinUsage.OUTPUT, 30, 75), Position.LEFT);
+ addPin(new Pin(model, this, "PASS", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
+ addPin(new Pin(model, this, "I", 4, PinUsage.INPUT, 0, 20), Position.RIGHT);
+ addPin(new Pin(model, this, "R=0", 1, PinUsage.INPUT, 15, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "_PL", 1, PinUsage.OUTPUT, 5, 85), Position.TOP);
+ addPin(new Pin(model, this, "_MAP", 1, PinUsage.OUTPUT, 15, 85), Position.TOP);
+ addPin(new Pin(model, this, "_VECT", 1, PinUsage.OUTPUT, 25, 85), Position.TOP);
+ addPin(new Pin(model, this, "RWE", 1, PinUsage.OUTPUT, 30, 5), Position.LEFT);
+ addPin(new Pin(model, this, "RDEC", 1, PinUsage.OUTPUT, 30, 15), Position.LEFT);
+ addPin(new Pin(model, this, "YD", 1, PinUsage.OUTPUT, 30, 25), Position.LEFT);
+ addPin(new Pin(model, this, "YR", 1, PinUsage.OUTPUT, 30, 35), Position.LEFT);
+ addPin(new Pin(model, this, "YF", 1, PinUsage.OUTPUT, 30, 45), Position.LEFT);
+ addPin(new Pin(model, this, "YmuPC", 1, PinUsage.OUTPUT, 30, 55), Position.LEFT);
+ addPin(new Pin(model, this, "STKI0", 1, PinUsage.OUTPUT, 30, 65), Position.LEFT);
+ addPin(new Pin(model, this, "STKI1", 1, PinUsage.OUTPUT, 30, 75), Position.LEFT);
}
@Override
{
super(model, "Am2910RegCntr", name, "Register/\nCounter");
setSize(40, 40);
- addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 0), Position.BOTTOM);
- addPin(new Pin(this, "_RLD", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
- addPin(new Pin(this, "WE", 1, PinUsage.INPUT, 0, 20), Position.RIGHT);
- addPin(new Pin(this, "DEC", 1, PinUsage.INPUT, 0, 30), Position.RIGHT);
- addPin(new Pin(this, "C", 1, PinUsage.INPUT, 40, 20), Position.LEFT);
- addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 20, 40), Position.TOP);
+ addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 20, 0), Position.BOTTOM);
+ addPin(new Pin(model, this, "_RLD", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
+ addPin(new Pin(model, this, "WE", 1, PinUsage.INPUT, 0, 20), Position.RIGHT);
+ addPin(new Pin(model, this, "DEC", 1, PinUsage.INPUT, 0, 30), Position.RIGHT);
+ addPin(new Pin(model, this, "C", 1, PinUsage.INPUT, 40, 20), Position.LEFT);
+ addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 20, 40), Position.TOP);
}
@Override
{
super(model, "Am2910SP", name, "Stack\npointer");
setSize(40, 30);
- addPin(new Pin(this, "STKI0", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
- addPin(new Pin(this, "STKI1", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
- addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
- addPin(new Pin(this, "A", 3, PinUsage.OUTPUT, 10, 30), Position.TOP);
- addPin(new Pin(this, "B", 3, PinUsage.OUTPUT, 30, 30), Position.TOP);
- addPin(new Pin(this, "_FULL", 1, PinUsage.OUTPUT, 40, 15), Position.LEFT);
+ addPin(new Pin(model, this, "STKI0", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
+ addPin(new Pin(model, this, "STKI1", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
+ addPin(new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
+ addPin(new Pin(model, this, "A", 3, PinUsage.OUTPUT, 10, 30), Position.TOP);
+ addPin(new Pin(model, this, "B", 3, PinUsage.OUTPUT, 30, 30), Position.TOP);
+ addPin(new Pin(model, this, "_FULL", 1, PinUsage.OUTPUT, 40, 15), Position.LEFT);
}
@Override
{
Set<ModelWire> wiresConnectedToPin = comp.submodel.getWiresByName().values().stream()
.filter(w -> w.getPin1() == interfacePin || w.getPin2() == interfacePin).collect(Collectors.toSet());
- wiresConnectedToPin.forEach(comp.getSubmodelModifiable()::destroyWire);
- comp.removeSubmodelInterface(interfacePin.name);
- comp.addSubmodelInterface(
- new MovablePin(comp, interfacePin.name, interfacePin.logicWidth, usage, interfacePin.getRelX(), interfacePin.getRelY()));
LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
+ wiresConnectedToPin.forEach(submodelModifiable::destroyWire);
+ comp.removeSubmodelInterface(interfacePin.name);
+ comp.addSubmodelInterface(new MovablePin(submodelModifiable, comp, interfacePin.name, interfacePin.logicWidth, usage,
+ interfacePin.getRelX(), interfacePin.getRelY()));
wiresConnectedToPin.forEach(w -> new ModelWire(submodelModifiable, w.getPin1(), w.getPin2()));
}
}
\ No newline at end of file
{
try
{
- Pin p = editor.toBeEdited.addSubmodelInterface(new MovablePin(editor.toBeEdited, result[0], Integer.parseInt(result[1]),
- PinUsage.valueOf(result[2]), clicked.x, clicked.y));
+ Pin p = editor.toBeEdited.addSubmodelInterface(new MovablePin(editor.getSubmodel(), editor.toBeEdited, result[0],
+ Integer.parseInt(result[1]), PinUsage.valueOf(result[2]), clicked.x, clicked.y));
editor.handleManager.getInterfacePinHandle(p).reqMove(clicked.x, clicked.y);
}
catch (NumberFormatException e)
}
/**
- * Adds the given wire to the list of wires and calls all wireAddedListeners.
+ * Adds the given wire to the list of wires and calls all wireAddedListeners. Don't call this method from application code as it is
+ * automatically called in {@link ModelWire}'s constructor.
*
* @author Daniel Kirschten
*/
*/
protected void destroyed()
{
- pinsByName.values().forEach(p -> pinRemovedListeners.forEach(l -> l.accept(p)));
+ pinsByName.values().forEach(this::removePinWithoutRedraw);
}
// pins
*/
protected void removePin(String name)
{
- Pin pin = pinsByName.remove(name);
- callPinRemovedListeners(pin);
+ removePinWithoutRedraw(pinsByName.remove(name));
model.requestRedraw();
}
+ private void removePinWithoutRedraw(Pin pin)
+ {
+ pin.destroyed();
+ callPinRemovedListeners(pin);
+ }
+
/**
* Returns a collection of pins of this component.
*
logicObs = (i) -> model.requestRedraw();
setSize(width, height);
- addPin(this.inputPin = new Pin(this, "", logicWidth, PinUsage.INPUT, 0, height / 2));
+ addPin(this.inputPin = new Pin(model, this, "", logicWidth, PinUsage.INPUT, 0, height / 2));
}
@Override
oc = new OrientationCalculator(params.orientation, width, height);
setSize(oc.width(), oc.height());
- this.outputPin = new Pin(this, "", 1, PinUsage.OUTPUT, oc.newX(width, height / 2), oc.newY(width, height / 2));
+ this.outputPin = new Pin(model, this, "", 1, PinUsage.OUTPUT, oc.newX(width, height / 2), oc.newY(width, height / 2));
addPin(outputPin);
}
super(model, name);
this.bits = bits;
setSize(width, height);
- addPin(new Pin(this, "out", bits.length(), PinUsage.OUTPUT, width, height / 2));
+ addPin(new Pin(model, this, "out", bits.length(), PinUsage.OUTPUT, width, height / 2));
}
@Override
logicObs = (i) -> model.requestRedraw();
setSize(width, height);
- addPin(this.outputPin = new Pin(this, "", logicWidth, PinUsage.OUTPUT, width, height / 2));
+ addPin(this.outputPin = new Pin(model, this, "", logicWidth, PinUsage.OUTPUT, width, height / 2));
}
@Override
setSize(width, (logicWidth - 1) * heightPerPin);
double inputHeight = (logicWidth - 1) * heightPerPin;
for (int i = 0; i < logicWidth; i++, inputHeight -= 10)
- addPin(new Pin(this, "I" + i, 1, PinUsage.TRISTATE, 0, inputHeight));
- addPin(this.outputPin = new Pin(this, "O", logicWidth, PinUsage.TRISTATE, width, (logicWidth - 1) * heightPerPin / 2));
+ addPin(new Pin(model, this, "I" + i, 1, PinUsage.TRISTATE, 0, inputHeight));
+ addPin(this.outputPin = new Pin(model, this, "O", logicWidth, PinUsage.TRISTATE, width, (logicWidth - 1) * heightPerPin / 2));
inputEnds = new ReadEnd[logicWidth];
}
super(model, name);
this.logicWidth = logicWidth;
setSize(width, (logicWidth - 1) * heightPerPin);
- addPin(this.inputPin = new Pin(this, "I", logicWidth, PinUsage.TRISTATE, 0, (logicWidth - 1) * heightPerPin / 2));
+ addPin(this.inputPin = new Pin(model, this, "I", logicWidth, PinUsage.TRISTATE, 0, (logicWidth - 1) * heightPerPin / 2));
double outputHeight = (logicWidth - 1) * heightPerPin;
for (int i = 0; i < logicWidth; i++, outputHeight -= 10)
- addPin(new Pin(this, "O" + i, 1, PinUsage.TRISTATE, width, outputHeight));
+ addPin(new Pin(model, this, "O" + i, 1, PinUsage.TRISTATE, width, outputHeight));
outputEnds = new ReadEnd[logicWidth];
}
double hHalf = height / 2;
double hQuar = height / 4;
- this.input = new Pin(this, "IN", params.logicWidth, PinUsage.INPUT, oc.newX(0, hHalf), oc.newY(0, hHalf));
- this.output = new Pin(this, "OUT", params.logicWidth, PinUsage.OUTPUT, oc.newX(width, hHalf), oc.newY(width, hHalf));
- this.enable = new Pin(this, "EN", 1, PinUsage.INPUT, oc.newX(wHalf, hQuar), oc.newY(wHalf, hQuar));
+ this.input = new Pin(model, this, "IN", params.logicWidth, PinUsage.INPUT, oc.newX(0, hHalf), oc.newY(0, hHalf));
+ this.output = new Pin(model, this, "OUT", params.logicWidth, PinUsage.OUTPUT, oc.newX(width, hHalf), oc.newY(width, hHalf));
+ this.enable = new Pin(model, this, "EN", 1, PinUsage.INPUT, oc.newX(wHalf, hQuar), oc.newY(wHalf, hQuar));
this.path = new double[] { oc.newX(0, 0), oc.newY(0, 0), oc.newX(width, hHalf), oc.newY(width, hHalf), oc.newX(0, height),
oc.newY(0, height) };
private MovablePin outputPin;
private final List<Pin> inputPins;
- protected SimpleRectangularModelGate(LogicModelModifiable model, String id, String label, boolean isInverted, int logicWidth, String name)
+ protected SimpleRectangularModelGate(LogicModelModifiable model, String id, String label, boolean isInverted, int logicWidth,
+ String name)
{
super(model, name);
this.id = id;
this.logicWidth = logicWidth;
this.isInverted = isInverted;
this.rectWidth = width - (isInverted ? invertedCircleDiam : 0);
- this.outputPin = new MovablePin(this, "Y", logicWidth, PinUsage.OUTPUT, width, 0);
+ this.outputPin = new MovablePin(model, this, "Y", logicWidth, PinUsage.OUTPUT, width, 0);
addPin(outputPin);
this.inputPins = new ArrayList<>();
setInputCount(1);
for (int i = oldInputCount; i < inputCount; i++)
{
// TODO what for more than 24 input pins?
- Pin pin = new Pin(this, String.valueOf((char) ('A' + i)), logicWidth, PinUsage.INPUT, 0, pinDistance / 2 + i * pinDistance);
+ Pin pin = new Pin(model, this, String.valueOf((char) ('A' + i)), logicWidth, PinUsage.INPUT, 0,
+ pinDistance / 2 + i * pinDistance);
inputPins.add(pin);
addPin(pin);
}
String pinName = newPinNames[i];
int oldPinIndex = pinNamesListThisSide.indexOf(pinName);
if (oldPinIndex == -1)
- super.addSubmodelInterface(new MovablePin(this, pinName, logicWidth, usage, relX, pinDistance / 2 + i * pinDistance));
+ super.addSubmodelInterface(
+ new MovablePin(model, this, pinName, logicWidth, usage, relX, pinDistance / 2 + i * pinDistance));
else
getSupermodelMovablePin(pinName).setRelPos(relX, pinDistance / 2 + i * pinDistance);
}
default:
throw new IllegalArgumentException("Unknown enum constant: " + supermodelPin.usage);
}
- MovablePin submodelPin = new MovablePin(submodelInterface, name, supermodelPin.logicWidth, submodelPinUsage,
+ MovablePin submodelPin = new MovablePin(model, submodelInterface, name, supermodelPin.logicWidth, submodelPinUsage,
supermodelPin.getRelX() / submodelScale, supermodelPin.getRelY() / submodelScale);
submodelPin.addPinMovedListener(p ->
logicObs = (i) -> model.requestRedraw();
setSize(CIRCLE_DIAM, CIRCLE_DIAM);
- addPin(this.pin = new Pin(this, "", logicWidth, PinUsage.TRISTATE, CIRCLE_RADIUS, CIRCLE_RADIUS));
+ addPin(this.pin = new Pin(model, this, "", logicWidth, PinUsage.TRISTATE, CIRCLE_RADIUS, CIRCLE_RADIUS));
}
// pins
package net.mograsim.logic.model.model.wires;
+import net.mograsim.logic.model.model.LogicModelModifiable;
import net.mograsim.logic.model.model.components.ModelComponent;
/**
*/
public class MovablePin extends Pin
{
- public MovablePin(ModelComponent component, String name, int logicWidth, PinUsage usage, double relX, double relY)
+ public MovablePin(LogicModelModifiable model, ModelComponent component, String name, int logicWidth, PinUsage usage, double relX,
+ double relY)
{
- super(component, name, logicWidth, usage, relX, relY);
+ super(model, component, name, logicWidth, usage, relX, relY);
}
@Override
package net.mograsim.logic.model.model.wires;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Consumer;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.mograsim.logic.model.model.LogicModelModifiable;
import net.mograsim.logic.model.model.components.ModelComponent;
/**
*/
public class Pin
{
+ /**
+ * The {@link LogicModel} the component this pin belongs to is a part of.
+ */
+ private final LogicModelModifiable model;
/**
* The {@link ModelComponent} this pin belongs to.
*/
*
* @author Daniel Kirschten
*/
- public Pin(ModelComponent component, String name, int logicWidth, PinUsage usage, double relX, double relY)
+ public Pin(LogicModelModifiable model, ModelComponent component, String name, int logicWidth, PinUsage usage, double relX, double relY)
{
+ this.model = model;
this.component = component;
this.name = name;
this.logicWidth = logicWidth;
component.addComponentMovedListener(c -> callPinMovedListeners());
}
+ /**
+ * Destroys this pin by removing all wires connected to it from the model the component is a part of.<br>
+ * Don't call this method from application code as it is automatically called in {@link ModelComponent#removePin(String)}.
+ */
+ public void destroyed()
+ {
+ Set<ModelWire> connectedWires = new HashSet<>();
+ for (ModelWire w : model.getWiresByName().values())
+ if (w.getPin1() == this || w.getPin2() == this)
+ connectedWires.add(w);
+ connectedWires.forEach(model::destroyWire);
+ }
+
// "graphical" operations
/**
comp.setSize(params.width, params.height);
for (LegacyInterfacePinParams iPinParams : params.interfacePins)
// TRISTATE because we don't have a better choice
- comp.addSubmodelInterface(new MovablePin(comp, iPinParams.name, iPinParams.logicWidth, PinUsage.TRISTATE, iPinParams.location.x,
- iPinParams.location.y));
+ comp.addSubmodelInterface(new MovablePin(model, comp, iPinParams.name, iPinParams.logicWidth, PinUsage.TRISTATE,
+ iPinParams.location.x, iPinParams.location.y));
LegacySubmodelParameters submodelParams = params.submodel;
LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
Map<String, ModelComponent> componentsByName = submodelModifiable.getComponentsByName();
comp.setSize(params.width, params.height);
for (InterfacePinParams iPinParams : params.interfacePins)
// TRISTATE because we don't have a better choice
- comp.addSubmodelInterface(new MovablePin(comp, iPinParams.name, iPinParams.logicWidth,
+ comp.addSubmodelInterface(new MovablePin(model, comp, iPinParams.name, iPinParams.logicWidth,
hasUsageSerialized ? iPinParams.usage : PinUsage.TRISTATE, iPinParams.location.x, iPinParams.location.y));
LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
LogicModelSerializer.deserialize(comp.getSubmodelModifiable(), params.submodel);
setSize(width, height);
//TODO check the usages
- addPin(addrPin = new Pin(this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10));
- addPin(dataPin = new Pin(this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30));
- addPin(rWPin = new Pin(this, "RW", 1, PinUsage.INPUT, 0, 50));
+ addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10));
+ addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30));
+ addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, 0, 50));
}
public Pin getAddressPin()