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.PinDescriptions;
10 import de.neemann.digital.draw.elements.IOState;
11 import de.neemann.digital.draw.elements.Pin;
12 import de.neemann.digital.draw.elements.Pins;
13 import de.neemann.digital.draw.graphics.Graphic;
14 import de.neemann.digital.draw.graphics.Orientation;
15 import de.neemann.digital.draw.graphics.Style;
16 import de.neemann.digital.draw.graphics.Vector;
17 
18 import static de.neemann.digital.draw.shapes.GenericShape.SIZE2;
19 
20 /**
21  * The ground shape
22  */
23 public class GroundShape implements Shape {
24 
25     private final PinDescriptions outputs;
26     private final String label;
27 
28     /**
29      * Creates a new instance
30      *
31      * @param attr    the attributes
32      * @param inputs  the inputs
33      * @param outputs the outputs
34      */
GroundShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs)35     public GroundShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
36         this.outputs = outputs;
37         label = attr.getLabel();
38     }
39 
40     @Override
getPins()41     public Pins getPins() {
42         return new Pins().add(new Pin(new Vector(0, 0), outputs.get(0)));
43     }
44 
45     @Override
applyStateMonitor(IOState ioState)46     public Interactor applyStateMonitor(IOState ioState) {
47         return null;
48     }
49 
50     @Override
drawTo(Graphic graphic, Style heighLight)51     public void drawTo(Graphic graphic, Style heighLight) {
52         graphic.drawLine(new Vector(-SIZE2, 0), new Vector(SIZE2, 0), Style.THICK);
53         if (!label.isEmpty())
54             graphic.drawText(new Vector(0, SIZE2), label, Orientation.CENTERTOP, Style.SHAPE_PIN);
55     }
56 }
57