Introduced new adapter class for testing tristate pins easily
authorChristian Femers <femers@in.tum.de>
Mon, 2 Sep 2019 04:53:18 +0000 (06:53 +0200)
committerChristian Femers <femers@in.tum.de>
Mon, 2 Sep 2019 04:53:18 +0000 (06:53 +0200)
net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/SwitchWithDisplay.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestEnvironmentHelper.java

diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/SwitchWithDisplay.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/SwitchWithDisplay.java
new file mode 100644 (file)
index 0000000..c5c3ab7
--- /dev/null
@@ -0,0 +1,65 @@
+package net.mograsim.logic.model.am2900;
+
+import net.mograsim.logic.core.components.BitDisplay;
+import net.mograsim.logic.core.components.ManualSwitch;
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
+import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.WireCrossPoint;
+import net.mograsim.logic.model.util.ModellingTool;
+
+public class SwitchWithDisplay
+{
+       private final Pin pin;
+       private final GUIBitDisplay guiBitDisplay;
+       private final GUIManualSwitch guiManualSwitch;
+
+       public SwitchWithDisplay(ViewModelModifiable model, Pin target)
+       {
+               pin = target;
+               guiBitDisplay = new GUIBitDisplay(model, pin.logicWidth);
+               guiManualSwitch = new GUIManualSwitch(model, pin.logicWidth);
+
+               ModellingTool tool = ModellingTool.createFor(model);
+               WireCrossPoint crossPoint = new WireCrossPoint(model, pin.logicWidth);
+               tool.connect(guiBitDisplay.getInputPin(), crossPoint);
+               tool.connect(guiManualSwitch.getOutputPin(), crossPoint);
+       }
+
+       public final BitVector getDisplayedValue()
+       {
+               return guiBitDisplay.getBitDisplay().getDisplayedValue();
+       }
+
+       public final void setState(BitVector bits)
+       {
+               guiManualSwitch.getManualSwitch().setState(bits);
+       }
+
+       public final Pin getPin()
+       {
+               return pin;
+       }
+
+       public final BitDisplay getBitDisplay()
+       {
+               return guiBitDisplay.getBitDisplay();
+       }
+
+       public final ManualSwitch getManualSwitch()
+       {
+               return guiManualSwitch.getManualSwitch();
+       }
+
+       final GUIBitDisplay getGuiBitDisplay()
+       {
+               return guiBitDisplay;
+       }
+
+       final GUIManualSwitch getGuiManualSwitch()
+       {
+               return guiManualSwitch;
+       }
+}
index 0a4838f..9ac4030 100644 (file)
@@ -116,6 +116,10 @@ public class TestEnvironmentHelper
                                GUIBitDisplay gbd = new GUIBitDisplay(viewModel, p.logicWidth);
                                modellingTool.connect(p, gbd.getInputPin());
                                idDisplayMap.put(p.name, gbd);
+                       } else if (SwitchWithDisplay.class.isAssignableFrom(type))
+                       {
+                               SwitchWithDisplay swd = new SwitchWithDisplay(viewModel, p);
+                               setField(f, swd);
                        } else
                        {
                                fail("unkown field type " + type);