package net.mograsim.logic.ui.am2900;
+import java.util.ArrayList;
+import java.util.List;
+
import net.mograsim.logic.ui.SimpleLogicUIStandalone;
import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.model.components.GUIComponent;
import net.mograsim.logic.ui.model.components.atomic.GUIManualSwitch;
import net.mograsim.logic.ui.model.components.atomic.GUINotGate;
import net.mograsim.logic.ui.model.components.atomic.TextComponent;
-import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdff;
-import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901;
-import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent;
import net.mograsim.logic.ui.model.wires.Pin;
import net.mograsim.logic.ui.model.wires.WireCrossPoint;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
import net.mograsim.logic.ui.util.ModellingTool;
public class Am2901Testbench
public static void createTestbench(ViewModelModifiable model)
{
- SimpleRectangularSubmodelComponent comp = new GUIAm2901(model);
+ GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901");
ModellingTool tool = ModellingTool.createFor(model);
comp.moveTo(240, 0);
and.moveTo(135, -30);
Pin last = and.getPin("Y");
- for (int i = 0; i < comp.getInputPinNames().size(); i++)
+ // 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
+ List<String> inputPinNames = new ArrayList<>();
+ List<String> outputPinNames = new ArrayList<>();
+ for (Pin p : comp.getPins().values())
+ if (p.getRelX() == 0)
+ inputPinNames.add(p.name);
+ else
+ outputPinNames.add(p.name);
+
+ for (int i = 0; i < inputPinNames.size(); i++)
{
double x = 55 + 70 * (i % 2);
double y = 10 * i;
WireCrossPoint wcp = new WireCrossPoint(model, 1);
- GUIComponent d_ff = new GUIdff(model);
+ GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff");
GUIManualSwitch sw = new GUIManualSwitch(model);
tool.connect(last, wcp);
tool.connect(wcp, d_ff, "C");
tool.connect(sw, d_ff, "", "D");
- tool.connect(d_ff, comp, "Q", comp.getInputPinNames().get(i));
+ tool.connect(d_ff, comp, "Q", inputPinNames.get(i));
last = wcp.getPin();
- TextComponent label = new TextComponent(model, comp.getInputPinNames().get(i));
+ TextComponent label = new TextComponent(model, inputPinNames.get(i));
sw.moveTo(x, y + 7.5);
wcp.moveTo(160, y);
label.moveTo(x - 25, y + 15);
}
- for (int i = 0; i < comp.getOutputPinNames().size(); i++)
+ for (int i = 0; i < outputPinNames.size(); i++)
{
double x = 300 + 75 * (i % 2);
double y = 10 * i - 2.5;
GUIBitDisplay bd = new GUIBitDisplay(model);
bd.moveTo(x, y);
- tool.connect(bd.getInputPin(), comp, comp.getOutputPinNames().get(i));
+ tool.connect(bd.getInputPin(), comp, outputPinNames.get(i));
- TextComponent label = new TextComponent(model, comp.getOutputPinNames().get(i));
+ TextComponent label = new TextComponent(model, outputPinNames.get(i));
label.moveTo(x + 50, y + 8);
}
}
import static org.junit.jupiter.api.Assertions.fail;\r
\r
import java.lang.reflect.Field;\r
+import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.LinkedList;\r
+import java.util.List;\r
import java.util.Objects;\r
import java.util.Queue;\r
import java.util.Set;\r
import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901;\r
import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent;\r
import net.mograsim.logic.ui.model.wires.GUIWire;\r
+import net.mograsim.logic.ui.model.wires.Pin;\r
import net.mograsim.logic.ui.modeladapter.LogicModelParameters;\r
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;\r
\r
public class TestableAm2901Impl implements TestableAm2901\r
{\r
- private GUIAm2901 am2901;\r
+ private GUIComponent am2901;\r
private Timeline timeline;\r
private ManualSwitch I8, I7, I6, I5, I4, I3, I2, I1, I0;\r
private ManualSwitch C;\r
{\r
// Create view model\r
ViewModelModifiable viewModel = new ViewModelModifiable();\r
+ // TODO replace with deserialized version as soon as high level states work for deserialized components\r
am2901 = new GUIAm2901(viewModel);\r
+// am2901 = IndirectGUIComponentCreator.createComponent(viewModel, "GUIAm2901");\r
+ // guess which pins are outputs and which are inputs\r
+ // TODO this code exists three times... but it seems too "hacky" to put it in a helper class\r
+ List<String> inputPinNames = new ArrayList<>();\r
+ List<String> outputPinNames = new ArrayList<>();\r
+ for (Pin p : am2901.getPins().values())\r
+ if (p.getRelX() == 0)\r
+ inputPinNames.add(p.name);\r
+ else\r
+ outputPinNames.add(p.name);\r
// Get switches\r
HashMap<String, GUIManualSwitch> idSwitchMap = new HashMap<>();\r
- for (String id : am2901.getInputPinNames())\r
+ for (String id : inputPinNames)\r
{\r
GUIManualSwitch sw = new GUIManualSwitch(viewModel);\r
new GUIWire(viewModel, am2901.getPin(id), sw.getOutputPin());\r
}\r
// Get displays\r
HashMap<String, GUIBitDisplay> idDisplayMap = new HashMap<>();\r
- for (String id : am2901.getOutputPinNames())\r
+ for (String id : outputPinNames)\r
{\r
GUIBitDisplay bd = new GUIBitDisplay(viewModel);\r
// bd.addRedrawListener(() -> System.out.println(id + " " + bd.getBitDisplay().getDisplayedValue()));\r