Added a small switch symbol to the transmission gate.

This commit is contained in:
hneemann 2017-05-29 10:16:56 +02:00
parent 243e58fd88
commit 7f359f6ccc
3 changed files with 26 additions and 6 deletions

View File

@ -75,4 +75,10 @@ public class TransGate extends Node implements Element {
}); });
} }
/**
* @return the state of the transmission gate
*/
public boolean isClosed() {
return closed;
}
} }

View File

@ -80,13 +80,22 @@ public abstract class FETShape implements Shape {
* @param graphic the instance to draw to * @param graphic the instance to draw to
*/ */
private void drawSwitch(Graphic graphic) { 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) { if (closed) {
graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE), Style.SHAPE_PIN); graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE), Style.SHAPE_PIN);
} else { } else {
graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE2 / 2), Style.SHAPE_PIN); graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE2 / 2), Style.SHAPE_PIN);
graphic.drawPolygon(new Polygon(false) 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 - SIZE2 / 2)
.add(SIZE + SIZE2, SIZE), Style.SHAPE_PIN); .add(SIZE + SIZE2, SIZE), Style.SHAPE_PIN);
} }

View File

@ -3,13 +3,11 @@ package de.neemann.digital.draw.shapes;
import de.neemann.digital.core.Observer; import de.neemann.digital.core.Observer;
import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.PinDescriptions; 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.IOState;
import de.neemann.digital.draw.elements.Pin; import de.neemann.digital.draw.elements.Pin;
import de.neemann.digital.draw.elements.Pins; import de.neemann.digital.draw.elements.Pins;
import de.neemann.digital.draw.graphics.Graphic; import de.neemann.digital.draw.graphics.*;
import de.neemann.digital.draw.graphics.Polygon;
import de.neemann.digital.draw.graphics.Style;
import de.neemann.digital.draw.graphics.Vector;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE; import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; import static de.neemann.digital.draw.shapes.GenericShape.SIZE2;
@ -34,8 +32,11 @@ public class TransGateShape implements Shape {
.add(SIZE * 2, SIZE) .add(SIZE * 2, SIZE)
.add(0, 0); .add(0, 0);
private static final Transform TRANS_SWITCH = new TransformRotate(new Vector(SIZE2, SIZE + SIZE2), 1);
private final PinDescriptions input; private final PinDescriptions input;
private final PinDescriptions output; private final PinDescriptions output;
private TransGate transGate;
/** /**
* Creates a trantmission gate * Creates a trantmission gate
@ -60,6 +61,7 @@ public class TransGateShape implements Shape {
@Override @Override
public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) { public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) {
transGate = (TransGate) ioState.getElement();
return null; return null;
} }
@ -69,6 +71,9 @@ public class TransGateShape implements Shape {
graphic.drawPolygon(BOTTOM, Style.NORMAL); graphic.drawPolygon(BOTTOM, Style.NORMAL);
graphic.drawLine(new Vector(SIZE, -SIZE), new Vector(SIZE, -SIZE2), 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); 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());
} }
} }