improved the LayoutShape

This commit is contained in:
hneemann 2018-07-29 20:11:22 +02:00
parent 35fc866e32
commit a9ab5870c8
5 changed files with 38 additions and 22 deletions

View File

@ -289,6 +289,21 @@ public final class Keys {
= new Key.KeyInteger("Width", 3)
.setMin(2);
/**
* defines the shape type of the custom circuit
*/
public static final Key<CustomCircuitShapeType> SHAPE_TYPE
= new Key.KeyEnum<>("shapeType", CustomCircuitShapeType.DEFAULT, CustomCircuitShapeType.values()).setSecondary();
/**
* the width of an element if it is included as nested element
*/
public static final Key<Integer> HEIGHT
= new Key.KeyInteger("Height", 3)
.setMin(2)
.setSecondary()
.setDependsOn(SHAPE_TYPE, cst -> cst.equals(CustomCircuitShapeType.LAYOUT));
/**
* width of the terminal
*/
@ -528,12 +543,6 @@ public final class Keys {
public static final Key<String> PINNUMBER =
new Key<>("pinNumber", "").setSecondary();
/**
* defines the shape type of the custom circuit
*/
public static final Key<CustomCircuitShapeType> SHAPE_TYPE
= new Key.KeyEnum<>("shapeType", CustomCircuitShapeType.DEFAULT, CustomCircuitShapeType.values()).setSecondary();
/**
* the pin count
*/

View File

@ -21,7 +21,6 @@ import de.neemann.digital.lang.Lang;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -34,12 +33,11 @@ import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
*/
public class LayoutShape implements Shape {
private final int width;
private final int height;
private int width;
private int height;
private final Pins pins;
private final Color color;
private final String name;
private final String label;
private final PinList left;
private final PinList right;
private final PinList top;
@ -94,16 +92,14 @@ public class LayoutShape implements Shape {
}
}
height = Math.max(right.size(), left.size()) + 1;
final int w = Math.max(top.size(), bottom.size()) + 1;
width = Math.max(w, custom.getAttributes().get(Keys.WIDTH));
height = Math.max(Math.max(right.size(), left.size()) + 1, custom.getAttributes().get(Keys.HEIGHT));
width = Math.max(Math.max(top.size(), bottom.size()) + 1, custom.getAttributes().get(Keys.WIDTH));
HashMap<String, PinPos> map = new HashMap<>();
top.createPosition(map, new Vector(((width - top.size()) / 2 + 1) * SIZE, 0));
bottom.createPosition(map, new Vector(((width - bottom.size()) / 2 + 1) * SIZE, SIZE * height));
left.createPosition(map, new Vector(0, SIZE));
right.createPosition(map, new Vector(SIZE * width, SIZE));
left.createPosition(map, new Vector(0, ((height - left.size()) / 2 + 1) * SIZE));
right.createPosition(map, new Vector(SIZE * width, ((height - right.size()) / 2 + 1) * SIZE));
pins = new Pins();
for (PinDescription p : custom.getInputDescription(elementAttributes))
@ -112,8 +108,12 @@ public class LayoutShape implements Shape {
pins.add(createPin(map, p));
color = custom.getCircuit().getAttributes().get(Keys.BACKGROUND_COLOR);
label = elementAttributes.getCleanLabel();
name = custom.getShortName();
String l = elementAttributes.getCleanLabel();
if (l != null && l.length() > 0)
name = l;
else
name = custom.getShortName();
}
private Pin createPin(HashMap<String, PinPos> map, PinDescription p) throws PinException {
@ -144,9 +144,12 @@ public class LayoutShape implements Shape {
graphic.drawPolygon(poly, Style.NORMAL.deriveFillStyle(color));
graphic.drawPolygon(poly, Style.NORMAL);
Vector center = new Vector(width * SIZE / 2, height * SIZE / 2);
Graphic.drawText(graphic, center.add(0, -2), name, Orientation.CENTERBOTTOM, Style.SHAPE_PIN);
Graphic.drawText(graphic, center.add(0, 2), label, Orientation.CENTERTOP, Style.SHAPE_PIN);
if (top.size() == 0)
Graphic.drawText(graphic, new Vector(width * SIZE / 2, -4), name, Orientation.CENTERBOTTOM, Style.SHAPE_PIN);
else if (bottom.size() == 0)
Graphic.drawText(graphic, new Vector(width * SIZE / 2, height * SIZE + 4), name, Orientation.CENTERTOP, Style.SHAPE_PIN);
else
Graphic.drawText(graphic, new Vector(width * SIZE / 2, height * SIZE /2), name, Orientation.CENTERCENTER, Style.SHAPE_PIN);
for (PinPos p : left)
Graphic.drawText(graphic, p.pos.add(4, 0), p.label, Orientation.LEFTCENTER, Style.SHAPE_PIN);
@ -196,7 +199,6 @@ public class LayoutShape implements Shape {
}
private void createPosition(HashMap<String, PinPos> map, Vector pos) {
Collections.sort(pins);
for (PinPos pp : pins) {
map.put(pp.label, pp);
pp.pos = pos;

View File

@ -67,6 +67,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
ATTR_LIST.add(Keys.SHAPE_TYPE);
if (Main.isExperimentalMode())
ATTR_LIST.add(Keys.CUSTOM_SHAPE);
ATTR_LIST.add(Keys.HEIGHT);
ATTR_LIST.add(Keys.PINCOUNT);
ATTR_LIST.add(Keys.BACKGROUND_COLOR);
ATTR_LIST.add(Keys.DESCRIPTION);

View File

@ -1000,6 +1000,8 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_Value_tt">Der Wert der Konstanten.</string>
<string name="key_Width">Breite</string>
<string name="key_Width_tt">Breite des Symbols, wenn diese Schaltung in eine andere eingefügt wird.</string>
<string name="key_Height">Höhe</string>
<string name="key_Height_tt">Höhe des Symbols, wenn diese Schaltung in eine andere eingefügt wird.</string>
<string name="key_autoReload">Bei jedem Start automatisch neu laden.</string><!-- ROM -->
<string name="key_autoReload_tt">Lädt das HEX-File bei jedem Modelstart neu.</string>
<string name="key_flipSelPos">Tausche Selektorposition</string><!-- Driver, DriverInvSel, Multiplexer, Demultiplexer, Decoder -->

View File

@ -992,6 +992,8 @@
<string name="key_Value_tt">The value of the constant.</string>
<string name="key_Width">Width</string>
<string name="key_Width_tt">With of symbol if this circuit is used as an component in an other circuit.</string>
<string name="key_Height">Height</string>
<string name="key_Height_tt">Height of symbol if this circuit is used as an component in an other circuit.</string>
<string name="key_autoReload">Reload at model start</string><!-- ROM -->
<string name="key_autoReload_tt">Reloads the hex file every time the model is started.</string>
<string name="key_flipSelPos">Flip selector position</string><!-- Driver, DriverInvSel, Multiplexer, Demultiplexer, Decoder -->