diff --git a/src/main/java/de/neemann/digital/draw/shapes/NFETShape.java b/src/main/java/de/neemann/digital/draw/shapes/FETShape.java similarity index 69% rename from src/main/java/de/neemann/digital/draw/shapes/NFETShape.java rename to src/main/java/de/neemann/digital/draw/shapes/FETShape.java index 2fe4ceede..375dd6d0a 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/NFETShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/FETShape.java @@ -3,25 +3,22 @@ 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.wiring.NFET; import de.neemann.digital.core.wiring.Relay; 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.*; import static de.neemann.digital.draw.shapes.GenericShape.SIZE; import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; /** - * The FETS shape + * FET shape. + * Created by hneemann on 25.02.17. */ -public class NFETShape implements Shape { - +public abstract class FETShape implements Shape { private final PinDescriptions inputs; private final PinDescriptions outputs; private final String label; - private NFET fet; + private Relay fet; /** * Creates a new instance @@ -30,25 +27,16 @@ public class NFETShape implements Shape { * @param inputs the inputs * @param outputs the outputs */ - public NFETShape(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) { + protected FETShape(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) { this.inputs = inputs; this.outputs = outputs; label = attributes.getCleanLabel(); } - @Override - public Pins getPins() { - return new Pins() - .add(new Pin(new Vector(0, SIZE * 2), inputs.get(0))) - .add(new Pin(new Vector(SIZE, 0), outputs.get(0))) - .add(new Pin(new Vector(SIZE, SIZE * 2), outputs.get(1))); - } - @Override public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) { - fet = (NFET) ioState.getElement(); + fet = (Relay) ioState.getElement(); ioState.getInput(0).addObserverToValue(guiObserver); - ioState.getInput(2).addObserverToValue(guiObserver); return null; } @@ -66,13 +54,6 @@ public class NFETShape implements Shape { .add(x1, SIZE * 2) .add(x1, SIZE * 2 - SIZE2 + g), Style.NORMAL); - graphic.drawLine(new Vector(SIZE2 + 3, SIZE), new Vector(SIZE, SIZE), Style.THIN); - - graphic.drawPolygon(new Polygon(true) - .add(x1 + 4, SIZE) - .add(SIZE - SIZE2 / 3, SIZE - SIZE2 / 4) - .add(SIZE - SIZE2 / 3, SIZE + SIZE2 / 4), Style.THIN_FILLED); - graphic.drawLine(new Vector(x1, SIZE2 + g), new Vector(x1, SIZE + SIZE2 - g), Style.NORMAL); graphic.drawLine(new Vector(1, 0), new Vector(1, SIZE * 2), Style.NORMAL); @@ -81,16 +62,15 @@ public class NFETShape implements Shape { graphic.drawText(new Vector(SIZE + SIZE2, SIZE * 2), new Vector(SIZE * 2, SIZE * 2), label, Orientation.LEFTBOTTOM, Style.SHAPE_PIN); if (fet != null) - drawSwitch(graphic, fet); + drawSwitch(graphic); } /** * Draws the small switch beside the fet * * @param graphic the instance to draw to - * @param fet the fet */ - public static void drawSwitch(Graphic graphic, Relay fet) { + private void drawSwitch(Graphic graphic) { boolean closed = fet.isClosed(); if (closed) { graphic.drawLine(new Vector(SIZE + SIZE2, 0), new Vector(SIZE + SIZE2, SIZE), Style.SHAPE_PIN); @@ -103,4 +83,17 @@ public class NFETShape implements Shape { } } + /** + * @return the inputs (gate) + */ + public PinDescriptions getInputs() { + return inputs; + } + + /** + * @return the outputs (source and drain) + */ + public PinDescriptions getOutputs() { + return outputs; + } } diff --git a/src/main/java/de/neemann/digital/draw/shapes/FETShapeN.java b/src/main/java/de/neemann/digital/draw/shapes/FETShapeN.java new file mode 100644 index 000000000..2a46c49e9 --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/shapes/FETShapeN.java @@ -0,0 +1,50 @@ +package de.neemann.digital.draw.shapes; + +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.PinDescriptions; +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 static de.neemann.digital.draw.shapes.GenericShape.SIZE; +import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; + +/** + * The n-chan FET shape + */ +public class FETShapeN extends FETShape { + + /** + * Creates a new instance + * + * @param attributes the attributes + * @param inputs the inputs + * @param outputs the outputs + */ + public FETShapeN(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) { + super(attributes, inputs, outputs); + } + + @Override + public Pins getPins() { + return new Pins() + .add(new Pin(new Vector(0, SIZE * 2), getInputs().get(0))) + .add(new Pin(new Vector(SIZE, 0), getOutputs().get(0))) + .add(new Pin(new Vector(SIZE, SIZE * 2), getOutputs().get(1))); + } + + @Override + public void drawTo(Graphic graphic, boolean highLight) { + super.drawTo(graphic, highLight); + + // the arrow + graphic.drawLine(new Vector(SIZE2 + 5, SIZE), new Vector(SIZE, SIZE), Style.THIN); + graphic.drawPolygon(new Polygon(true) + .add(SIZE2 + 2, SIZE) + .add(SIZE - SIZE2 / 3, SIZE - SIZE2 / 4) + .add(SIZE - SIZE2 / 3, SIZE + SIZE2 / 4), Style.THIN_FILLED); + } +} diff --git a/src/main/java/de/neemann/digital/draw/shapes/FETShapeP.java b/src/main/java/de/neemann/digital/draw/shapes/FETShapeP.java new file mode 100644 index 000000000..fc233074d --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/shapes/FETShapeP.java @@ -0,0 +1,52 @@ +package de.neemann.digital.draw.shapes; + +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.PinDescriptions; +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 static de.neemann.digital.draw.shapes.GenericShape.SIZE; +import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; + +/** + * The p-chan FET shape + */ +public class FETShapeP extends FETShape { + + /** + * Creates a new instance + * + * @param attributes the attributes + * @param inputs the inputs + * @param outputs the outputs + */ + public FETShapeP(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) { + super(attributes, inputs, outputs); + } + + @Override + public Pins getPins() { + return new Pins() + .add(new Pin(new Vector(0, 0), getInputs().get(0))) + .add(new Pin(new Vector(SIZE, 0), getOutputs().get(0))) + .add(new Pin(new Vector(SIZE, SIZE * 2), getOutputs().get(1))); + } + + + @Override + public void drawTo(Graphic graphic, boolean highLight) { + super.drawTo(graphic, highLight); + + // the arrow + graphic.drawLine(new Vector(SIZE2 - 2, SIZE), new Vector(SIZE2 + 4, SIZE), Style.THIN); + graphic.drawPolygon(new Polygon(true) + .add(SIZE - SIZE2 / 3 + 2, SIZE) + .add(SIZE2 + 4, SIZE - SIZE2 / 4) + .add(SIZE2 + 4, SIZE + SIZE2 / 4), Style.THIN_FILLED); + } + +} diff --git a/src/main/java/de/neemann/digital/draw/shapes/PFETShape.java b/src/main/java/de/neemann/digital/draw/shapes/PFETShape.java deleted file mode 100644 index c5102959e..000000000 --- a/src/main/java/de/neemann/digital/draw/shapes/PFETShape.java +++ /dev/null @@ -1,86 +0,0 @@ -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.wiring.PFET; -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.*; - -import static de.neemann.digital.draw.shapes.GenericShape.SIZE; -import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; - -/** - * The FETS shape - */ -public class PFETShape implements Shape { - - private final PinDescriptions inputs; - private final PinDescriptions outputs; - private final String label; - private PFET fet; - - /** - * Creates a new instance - * - * @param attributes the attributes - * @param inputs the inputs - * @param outputs the outputs - */ - public PFETShape(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) { - this.inputs = inputs; - this.outputs = outputs; - label = attributes.getCleanLabel(); - } - - @Override - public Pins getPins() { - return new Pins() - .add(new Pin(new Vector(0, 0), inputs.get(0))) - .add(new Pin(new Vector(SIZE, 0), outputs.get(0))) - .add(new Pin(new Vector(SIZE, SIZE * 2), outputs.get(1))); - } - - @Override - public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) { - fet = (PFET) ioState.getElement(); - ioState.getInput(0).addObserverToValue(guiObserver); - ioState.getInput(1).addObserverToValue(guiObserver); - return null; - } - - @Override - public void drawTo(Graphic graphic, boolean highLight) { - final int x1 = SIZE2 - 2; - final int g = SIZE2 / 2; - graphic.drawPolygon(new Polygon(false) - .add(SIZE, 0) - .add(x1, 0) - .add(x1, SIZE2 - g), Style.NORMAL); - - graphic.drawPolygon(new Polygon(false) - .add(SIZE, SIZE * 2) - .add(x1, SIZE * 2) - .add(x1, SIZE * 2 - SIZE2 + g), Style.NORMAL); - - graphic.drawLine(new Vector(x1, SIZE), new Vector(SIZE, SIZE), Style.THIN); - - graphic.drawPolygon(new Polygon(true) - .add(SIZE - SIZE2 / 3, SIZE) - .add(x1 + 4, SIZE - SIZE2 / 4) - .add(x1 + 4, SIZE + SIZE2 / 4), Style.THIN_FILLED); - - graphic.drawLine(new Vector(x1, SIZE2 + g), new Vector(x1, SIZE + SIZE2 - g), Style.NORMAL); - - graphic.drawLine(new Vector(1, 0), new Vector(1, SIZE * 2), Style.NORMAL); - - if (label != null && label.length() > 0) - graphic.drawText(new Vector(SIZE + SIZE2, SIZE * 2), new Vector(SIZE * 2, SIZE * 2), label, Orientation.LEFTBOTTOM, Style.SHAPE_PIN); - - if (fet != null) - NFETShape.drawSwitch(graphic, fet); - } - -} diff --git a/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java b/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java index c5fdedd9c..5b24ea9e6 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java +++ b/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java @@ -81,8 +81,8 @@ public final class ShapeFactory { map.put(VDD.DESCRIPTION.getName(), VDDShape::new); map.put(Switch.DESCRIPTION.getName(), SwitchShape::new); map.put(Relay.DESCRIPTION.getName(), RelayShape::new); - map.put(NFET.DESCRIPTION.getName(), NFETShape::new); - map.put(PFET.DESCRIPTION.getName(), PFETShape::new); + map.put(NFET.DESCRIPTION.getName(), FETShapeN::new); + map.put(PFET.DESCRIPTION.getName(), FETShapeP::new); map.put(Out.DESCRIPTION.getName(), OutputShape::new); map.put(Out.LEDDESCRIPTION.getName(), LEDShape::new); map.put(Button.DESCRIPTION.getName(), ButtonShape::new);