Created GUINandGate
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / modeladapter / componentadapters / NandGateAdapter.java
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/modeladapter/componentadapters/NandGateAdapter.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/modeladapter/componentadapters/NandGateAdapter.java
new file mode 100644 (file)
index 0000000..761689a
--- /dev/null
@@ -0,0 +1,34 @@
+package net.mograsim.logic.ui.modeladapter.componentadapters;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.components.gates.AndGate;
+import net.mograsim.logic.core.components.gates.NotGate;
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.wires.Wire;
+import net.mograsim.logic.ui.model.components.GUINandGate;
+import net.mograsim.logic.ui.model.wires.Pin;
+import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
+
+public class NandGateAdapter implements ComponentAdapter<GUINandGate>
+{
+       @Override
+       public Class<GUINandGate> getSupportedClass()
+       {
+               return GUINandGate.class;
+       }
+
+       @Override
+       @SuppressWarnings("unused") // AndGate and NotGate
+       public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, GUINandGate guiComponent,
+                       Map<Pin, Wire> logicWiresPerPin)
+       {
+               Wire i0 = logicWiresPerPin.get(guiComponent.getInputPins().get(0));
+               Wire i1 = logicWiresPerPin.get(guiComponent.getInputPins().get(1));
+               Wire o = logicWiresPerPin.get(guiComponent.getOutputPin());
+               Wire w = new Wire(timeline, guiComponent.getOutputPin().logicWidth, 1);
+
+               new AndGate(timeline, 1, w.createReadWriteEnd(), i0.createReadOnlyEnd(), i1.createReadOnlyEnd());
+               new NotGate(timeline, Math.max(1, params.gateProcessTime - 2), w.createReadOnlyEnd(), o.createReadWriteEnd());
+       }
+}
\ No newline at end of file