1 /* 2 * Copyright (c) 2016 Helmut Neemann 3 * Use of this source code is governed by the GPL v3 license 4 * that can be found in the LICENSE file. 5 */ 6 package de.neemann.digital.draw.shapes; 7 8 import de.neemann.digital.core.element.ElementAttributes; 9 import de.neemann.digital.core.element.Keys; 10 import de.neemann.digital.core.element.PinDescriptions; 11 import de.neemann.digital.draw.elements.IOState; 12 import de.neemann.digital.draw.elements.Pin; 13 import de.neemann.digital.draw.elements.Pins; 14 import de.neemann.digital.draw.graphics.Graphic; 15 import de.neemann.digital.draw.graphics.Polygon; 16 import de.neemann.digital.draw.graphics.Style; 17 import de.neemann.digital.draw.graphics.Vector; 18 19 import static de.neemann.digital.draw.shapes.GenericShape.SIZE; 20 import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; 21 22 /** 23 * The diodes shape 24 */ 25 public class DiodeBackwardShape implements Shape { 26 27 private final PinDescriptions inputs; 28 private final PinDescriptions outputs; 29 private final boolean blown; 30 31 /** 32 * Creates a new instance 33 * 34 * @param attributes the attributes 35 * @param inputs the inputs 36 * @param outputs the outputs 37 */ DiodeBackwardShape(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs)38 public DiodeBackwardShape(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) { 39 this.inputs = inputs; 40 this.outputs = outputs; 41 blown = attributes.get(Keys.BLOWN); 42 } 43 44 @Override getPins()45 public Pins getPins() { 46 return new Pins() 47 .add(new Pin(new Vector(0, 0), inputs.get(0))) 48 .add(new Pin(new Vector(0, -SIZE), outputs.get(0))); 49 } 50 51 @Override applyStateMonitor(IOState ioState)52 public InteractorInterface applyStateMonitor(IOState ioState) { 53 return null; 54 } 55 56 @Override drawTo(Graphic graphic, Style highLight)57 public void drawTo(Graphic graphic, Style highLight) { 58 Style style = blown ? Style.DASH : Style.NORMAL; 59 60 graphic.drawPolygon( 61 new Polygon(true) 62 .add(-SIZE2, -SIZE + 1) 63 .add(SIZE2, -SIZE + 1) 64 .add(0, -1), 65 style 66 ); 67 graphic.drawLine(new Vector(-SIZE2, -1), new Vector(SIZE2, -1), style); 68 } 69 70 } 71