diff --git a/src/main/java/de/neemann/digital/core/switching/TransGate.java b/src/main/java/de/neemann/digital/core/switching/TransGate.java index c5e0b7e02..b40e96f4e 100644 --- a/src/main/java/de/neemann/digital/core/switching/TransGate.java +++ b/src/main/java/de/neemann/digital/core/switching/TransGate.java @@ -75,4 +75,10 @@ public class TransGate extends Node implements Element { }); } + /** + * @return the state of the transmission gate + */ + public boolean isClosed() { + return closed; + } } diff --git a/src/main/java/de/neemann/digital/draw/shapes/FETShape.java b/src/main/java/de/neemann/digital/draw/shapes/FETShape.java index c22709de8..9a14c9471 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/FETShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/FETShape.java @@ -80,13 +80,22 @@ public abstract class FETShape implements Shape { * @param graphic the instance to draw to */ private void drawSwitch(Graphic graphic) { - boolean closed = fet.isClosed(); + drawSwitch(graphic, fet.isClosed()); + } + + /** + * draws the switch + * + * @param graphic the graphics instance to draw to + * @param closed state of the switch + */ + public static void drawSwitch(Graphic graphic, boolean closed) { if (closed) { graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE), Style.SHAPE_PIN); } else { graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE2 / 2), Style.SHAPE_PIN); graphic.drawPolygon(new Polygon(false) - .add(SIZE + SIZE2 / 2, SIZE2 / 2) + .add(SIZE + SIZE2 / 2, SIZE2 / 2 + 2) .add(SIZE + SIZE2, SIZE - SIZE2 / 2) .add(SIZE + SIZE2, SIZE), Style.SHAPE_PIN); } diff --git a/src/main/java/de/neemann/digital/draw/shapes/TransGateShape.java b/src/main/java/de/neemann/digital/draw/shapes/TransGateShape.java index 0e20520fc..d83fc4ae9 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/TransGateShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/TransGateShape.java @@ -3,13 +3,11 @@ package de.neemann.digital.draw.shapes; import de.neemann.digital.core.Observer; import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.PinDescriptions; +import de.neemann.digital.core.switching.TransGate; import de.neemann.digital.draw.elements.IOState; import de.neemann.digital.draw.elements.Pin; import de.neemann.digital.draw.elements.Pins; -import de.neemann.digital.draw.graphics.Graphic; -import de.neemann.digital.draw.graphics.Polygon; -import de.neemann.digital.draw.graphics.Style; -import de.neemann.digital.draw.graphics.Vector; +import de.neemann.digital.draw.graphics.*; import static de.neemann.digital.draw.shapes.GenericShape.SIZE; import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; @@ -34,8 +32,11 @@ public class TransGateShape implements Shape { .add(SIZE * 2, SIZE) .add(0, 0); + private static final Transform TRANS_SWITCH = new TransformRotate(new Vector(SIZE2, SIZE + SIZE2), 1); + private final PinDescriptions input; private final PinDescriptions output; + private TransGate transGate; /** * Creates a trantmission gate @@ -60,6 +61,7 @@ public class TransGateShape implements Shape { @Override public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) { + transGate = (TransGate) ioState.getElement(); return null; } @@ -69,6 +71,9 @@ public class TransGateShape implements Shape { graphic.drawPolygon(BOTTOM, Style.NORMAL); graphic.drawLine(new Vector(SIZE, -SIZE), new Vector(SIZE, -SIZE2), Style.NORMAL); graphic.drawCircle(new Vector(SIZE - RAD, P - RAD), new Vector(SIZE + RAD, P + RAD), Style.NORMAL); + + if (transGate != null) + FETShape.drawSwitch(new GraphicTransform(graphic, TRANS_SWITCH), transGate.isClosed()); } }