From 1f645882d229fc3d4081e4c5060559d75dc2cc24 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Thu, 5 Sep 2019 20:33:46 +0200 Subject: [PATCH] Wires connected to a component now get deleted with the component --- .../model/am2900/components/Modeldff12.java | 6 ++-- .../am2900/components/Modeldff4_finewe.java | 26 +++++++-------- .../model/am2900/components/Modelinc12.java | 6 ++-- .../model/am2900/components/Modelnor12.java | 4 +-- .../model/am2900/components/Modelram5_12.java | 12 +++---- .../model/am2900/components/Modelsel4_12.java | 18 +++++------ .../am2904/ModelAm2904RegCTInstrDecode.java | 32 +++++++++---------- .../am2904/ModelAm2904ShiftInstrDecode.java | 20 ++++++------ .../am2910/ModelAm2910InstrPLA.java | 28 ++++++++-------- .../components/am2910/ModelAm2910RegCntr.java | 12 +++---- .../components/am2910/ModelAm2910SP.java | 12 +++---- .../ReserializeJSONsSettingUsages.java | 8 ++--- .../model/editor/states/SelectionState.java | 4 +-- .../logic/model/model/LogicModel.java | 3 +- .../model/components/ModelComponent.java | 11 +++++-- .../components/atomic/ModelBitDisplay.java | 2 +- .../model/components/atomic/ModelClock.java | 2 +- .../components/atomic/ModelFixedOutput.java | 2 +- .../components/atomic/ModelManualSwitch.java | 2 +- .../model/components/atomic/ModelMerger.java | 4 +-- .../components/atomic/ModelSplitter.java | 4 +-- .../atomic/ModelTriStateBuffer.java | 6 ++-- .../atomic/SimpleRectangularModelGate.java | 8 +++-- .../SimpleRectangularSubmodelComponent.java | 3 +- .../submodels/SubmodelComponent.java | 2 +- .../model/wires/ModelWireCrossPoint.java | 2 +- .../logic/model/model/wires/MovablePin.java | 6 ++-- .../mograsim/logic/model/model/wires/Pin.java | 23 ++++++++++++- .../LegacySubmodelComponentSerializer.java | 4 +-- .../SubmodelComponentSerializer.java | 2 +- .../standard/memory/ModelMemoryWA.java | 6 ++-- 31 files changed, 156 insertions(+), 124 deletions(-) diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff12.java index a3ec2f5f..59aaf84b 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff12.java @@ -24,9 +24,9 @@ public class Modeldff12 extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff4_finewe.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff4_finewe.java index 5b565ad2..fcb355f8 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff4_finewe.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff4_finewe.java @@ -26,19 +26,19 @@ public class Modeldff4_finewe extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java index 7979ae3c..2f4483ad 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java @@ -24,9 +24,9 @@ public class Modelinc12 extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelnor12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelnor12.java index 6ca7b14e..758c17e0 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelnor12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelnor12.java @@ -24,8 +24,8 @@ public class Modelnor12 extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelram5_12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelram5_12.java index 5be6303e..a381b0c8 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelram5_12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelram5_12.java @@ -28,12 +28,12 @@ public class Modelram5_12 extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelsel4_12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelsel4_12.java index b13a4d02..3aa416d2 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelsel4_12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelsel4_12.java @@ -25,15 +25,15 @@ public class Modelsel4_12 extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904RegCTInstrDecode.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904RegCTInstrDecode.java index 999f8bf6..e5cc1ea8 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904RegCTInstrDecode.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904RegCTInstrDecode.java @@ -24,20 +24,20 @@ public class ModelAm2904RegCTInstrDecode extends SimpleRectangularHardcodedModel { 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 @@ -47,19 +47,19 @@ public class ModelAm2904RegCTInstrDecode extends SimpleRectangularHardcodedModel // 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 @@ -68,7 +68,7 @@ public class ModelAm2904RegCTInstrDecode extends SimpleRectangularHardcodedModel // 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904ShiftInstrDecode.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904ShiftInstrDecode.java index 74cdd440..ef7b2c13 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904ShiftInstrDecode.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/ModelAm2904ShiftInstrDecode.java @@ -25,15 +25,15 @@ public class ModelAm2904ShiftInstrDecode extends SimpleRectangularHardcodedModel { 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 @@ -43,28 +43,28 @@ public class ModelAm2904ShiftInstrDecode extends SimpleRectangularHardcodedModel // 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910InstrPLA.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910InstrPLA.java index 414c0a50..928578f8 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910InstrPLA.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910InstrPLA.java @@ -23,20 +23,20 @@ public class ModelAm2910InstrPLA extends SimpleRectangularHardcodedModelComponen { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java index 193b58bc..f300e6f1 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java @@ -24,12 +24,12 @@ public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java index a4491d20..dbcfa06e 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java @@ -24,12 +24,12 @@ public class ModelAm2910SP extends SimpleRectangularHardcodedModelComponent { 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 diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONsSettingUsages.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONsSettingUsages.java index a102f764..bd4d4588 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONsSettingUsages.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONsSettingUsages.java @@ -77,11 +77,11 @@ public class ReserializeJSONsSettingUsages { Set 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 diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/states/SelectionState.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/states/SelectionState.java index 4a02db4c..baa2eff9 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/states/SelectionState.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/states/SelectionState.java @@ -104,8 +104,8 @@ public class SelectionState extends EditorState { 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) diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java index eb6f7ee4..227d9b1a 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java @@ -75,7 +75,8 @@ public class LogicModel } /** - * 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 */ diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java index d2ead744..40ab62fc 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java @@ -79,7 +79,7 @@ public abstract class ModelComponent implements JSONSerializable */ protected void destroyed() { - pinsByName.values().forEach(p -> pinRemovedListeners.forEach(l -> l.accept(p))); + pinsByName.values().forEach(this::removePinWithoutRedraw); } // pins @@ -112,11 +112,16 @@ public abstract class ModelComponent implements JSONSerializable */ 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. * diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java index 9573b3d9..6e65cb8d 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java @@ -43,7 +43,7 @@ public class ModelBitDisplay extends ModelComponent 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 diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java index 6bf2ecb7..96a9d486 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java @@ -50,7 +50,7 @@ public class ModelClock extends ModelComponent 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); } diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelFixedOutput.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelFixedOutput.java index 2ff06f20..b889fada 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelFixedOutput.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelFixedOutput.java @@ -34,7 +34,7 @@ public class ModelFixedOutput extends ModelComponent 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 diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java index 25d3a69e..ff991e09 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java @@ -46,7 +46,7 @@ public class ModelManualSwitch extends ModelComponent 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 diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelMerger.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelMerger.java index fbea650b..ec98d789 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelMerger.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelMerger.java @@ -41,8 +41,8 @@ public class ModelMerger extends ModelComponent 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]; } diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelSplitter.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelSplitter.java index 24d65784..805831fa 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelSplitter.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelSplitter.java @@ -39,10 +39,10 @@ public class ModelSplitter extends ModelComponent 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]; } diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelTriStateBuffer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelTriStateBuffer.java index 45e653cb..6791aff8 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelTriStateBuffer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelTriStateBuffer.java @@ -48,9 +48,9 @@ public class ModelTriStateBuffer extends ModelComponent 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) }; diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularModelGate.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularModelGate.java index ea16e4c5..f455b3ca 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularModelGate.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularModelGate.java @@ -36,7 +36,8 @@ public class SimpleRectangularModelGate extends ModelComponent private MovablePin outputPin; private final List 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; @@ -44,7 +45,7 @@ public class SimpleRectangularModelGate extends ModelComponent 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); @@ -61,7 +62,8 @@ public class SimpleRectangularModelGate extends ModelComponent 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); } diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java index 5e01fe04..90c6fa5d 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java @@ -81,7 +81,8 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent 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); } diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java index a08c0934..4a2f46c1 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java @@ -159,7 +159,7 @@ public abstract class SubmodelComponent extends ModelComponent 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 -> diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWireCrossPoint.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWireCrossPoint.java index 75b619d9..0a634992 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWireCrossPoint.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWireCrossPoint.java @@ -58,7 +58,7 @@ public class ModelWireCrossPoint extends ModelComponent 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 diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/MovablePin.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/MovablePin.java index 4ec62c7a..c2291f81 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/MovablePin.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/MovablePin.java @@ -1,5 +1,6 @@ package net.mograsim.logic.model.model.wires; +import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.logic.model.model.components.ModelComponent; /** @@ -9,9 +10,10 @@ 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 diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java index eb8df887..11a69082 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java @@ -1,11 +1,14 @@ 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; /** @@ -18,6 +21,10 @@ 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. */ @@ -56,8 +63,9 @@ public class Pin * * @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; @@ -71,6 +79,19 @@ public class Pin component.addComponentMovedListener(c -> callPinMovedListeners()); } + /** + * Destroys this pin by removing all wires connected to it from the model the component is a part of.
+ * Don't call this method from application code as it is automatically called in {@link ModelComponent#removePin(String)}. + */ + public void destroyed() + { + Set 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 /** diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java index 37b05a90..531913f1 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java @@ -173,8 +173,8 @@ public final class LegacySubmodelComponentSerializer 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 componentsByName = submodelModifiable.getComponentsByName(); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java index ce770ac8..b4b2ff9c 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java @@ -172,7 +172,7 @@ public final class SubmodelComponentSerializer 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); diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java index 78bd16f4..f874e467 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java @@ -39,9 +39,9 @@ public class ModelMemoryWA extends ModelComponent 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() -- 2.17.1