From: Daniel Kirschten Date: Wed, 17 Jul 2019 12:22:37 +0000 (+0200) Subject: Further duplication of bad code guessing input/output pins X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=ca786d4adb85001128a2440154d028632a22e3b8;p=Mograsim.git Further duplication of bad code guessing input/output pins --- diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java index 2ab42305..27e3d166 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java @@ -26,7 +26,7 @@ public class SubmodelComponentTestbench GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901", "Am2901"); // guess which pins are outputs and which are inputs - // TODO this code exists three times... but it seems too "hacky" to put it in a helper class + // TODO this code exists four times... but it seems too "hacky" to put it in a helper class List inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>(); for (Pin p : comp.getPins().values()) diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java index 7939eaec..a5b6b8a7 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java @@ -52,7 +52,7 @@ public class Am2901Testbench Pin last = and.getPin("Y"); // guess which pins are outputs and which are inputs - // TODO this code exists three times... but it seems too "hacky" to put it in a helper class + // TODO this code exists four times... but it seems too "hacky" to put it in a helper class List inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>(); for (Pin p : comp.getPins().values()) diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java index 1448333a..3d5ce860 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java @@ -105,7 +105,7 @@ public class TestableAm2901Impl implements TestableAm2901 ViewModelModifiable viewModel = new ViewModelModifiable(); am2901 = IndirectGUIComponentCreator.createComponent(viewModel, "GUIAm2901"); // guess which pins are outputs and which are inputs - // TODO this code exists three times... but it seems too "hacky" to put it in a helper class + // TODO this code exists four times... but it seems too "hacky" to put it in a helper class List inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>(); for (Pin p : am2901.getPins().values()) diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java index 33fb7253..26d95cf7 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java @@ -1,5 +1,9 @@ package net.mograsim.plugin.views; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + import javax.inject.Inject; import org.eclipse.e4.ui.model.application.ui.basic.MPart; @@ -13,13 +17,14 @@ import net.mograsim.logic.core.timeline.Timeline; import net.mograsim.logic.model.LogicExecuter; import net.mograsim.logic.model.LogicUICanvas; import net.mograsim.logic.model.model.ViewModelModifiable; +import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay; import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch; -import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901; -import net.mograsim.logic.model.model.components.submodels.SimpleRectangularSubmodelComponent; import net.mograsim.logic.model.model.wires.GUIWire; +import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.modeladapter.LogicModelParameters; import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter; +import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; import net.mograsim.plugin.ThemePreferences; import net.mograsim.preferences.Preferences; @@ -78,20 +83,32 @@ public class LogicUIPart extends ViewPart @SuppressWarnings("unused") // for GUIWires being created public static void createTestbench(ViewModelModifiable model) { - SimpleRectangularSubmodelComponent comp = new GUIAm2901(model); + GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901"); + + // TODO this code exists four times... but it seems too "hacky" to put it in a helper class + List inputPinNames = new ArrayList<>(); + List outputPinNames = new ArrayList<>(); + for (Pin p : comp.getPins().values()) + if (p.getRelX() == 0) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); + + inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); + outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); comp.moveTo(100, 0); - for (int i = 0; i < comp.getInputPinNames().size(); i++) + for (int i = 0; i < inputPinNames.size(); i++) { GUIManualSwitch sw = new GUIManualSwitch(model); sw.moveTo(0, 20 * i); - new GUIWire(model, comp.getPin(comp.getInputPinNames().get(i)), sw.getOutputPin()); + new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin()); } - for (int i = 0; i < comp.getOutputPinNames().size(); i++) + for (int i = 0; i < outputPinNames.size(); i++) { GUIBitDisplay bd = new GUIBitDisplay(model); bd.moveTo(200, 20 * i); - new GUIWire(model, comp.getPin(comp.getOutputPinNames().get(i)), bd.getInputPin()); + new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin()); } } } \ No newline at end of file