mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-19 01:44:44 -04:00
improved the LayoutShape
This commit is contained in:
parent
35fc866e32
commit
a9ab5870c8
@ -289,6 +289,21 @@ public final class Keys {
|
|||||||
= new Key.KeyInteger("Width", 3)
|
= new Key.KeyInteger("Width", 3)
|
||||||
.setMin(2);
|
.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
|
* width of the terminal
|
||||||
*/
|
*/
|
||||||
@ -528,12 +543,6 @@ public final class Keys {
|
|||||||
public static final Key<String> PINNUMBER =
|
public static final Key<String> PINNUMBER =
|
||||||
new Key<>("pinNumber", "").setSecondary();
|
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
|
* the pin count
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,6 @@ import de.neemann.digital.lang.Lang;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
@ -34,12 +33,11 @@ import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
|||||||
*/
|
*/
|
||||||
public class LayoutShape implements Shape {
|
public class LayoutShape implements Shape {
|
||||||
|
|
||||||
private final int width;
|
private int width;
|
||||||
private final int height;
|
private int height;
|
||||||
private final Pins pins;
|
private final Pins pins;
|
||||||
private final Color color;
|
private final Color color;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String label;
|
|
||||||
private final PinList left;
|
private final PinList left;
|
||||||
private final PinList right;
|
private final PinList right;
|
||||||
private final PinList top;
|
private final PinList top;
|
||||||
@ -94,16 +92,14 @@ public class LayoutShape implements Shape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
height = Math.max(right.size(), left.size()) + 1;
|
height = Math.max(Math.max(right.size(), left.size()) + 1, custom.getAttributes().get(Keys.HEIGHT));
|
||||||
final int w = Math.max(top.size(), bottom.size()) + 1;
|
width = Math.max(Math.max(top.size(), bottom.size()) + 1, custom.getAttributes().get(Keys.WIDTH));
|
||||||
width = Math.max(w, custom.getAttributes().get(Keys.WIDTH));
|
|
||||||
|
|
||||||
|
|
||||||
HashMap<String, PinPos> map = new HashMap<>();
|
HashMap<String, PinPos> map = new HashMap<>();
|
||||||
top.createPosition(map, new Vector(((width - top.size()) / 2 + 1) * SIZE, 0));
|
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));
|
bottom.createPosition(map, new Vector(((width - bottom.size()) / 2 + 1) * SIZE, SIZE * height));
|
||||||
left.createPosition(map, new Vector(0, SIZE));
|
left.createPosition(map, new Vector(0, ((height - left.size()) / 2 + 1) * SIZE));
|
||||||
right.createPosition(map, new Vector(SIZE * width, SIZE));
|
right.createPosition(map, new Vector(SIZE * width, ((height - right.size()) / 2 + 1) * SIZE));
|
||||||
|
|
||||||
pins = new Pins();
|
pins = new Pins();
|
||||||
for (PinDescription p : custom.getInputDescription(elementAttributes))
|
for (PinDescription p : custom.getInputDescription(elementAttributes))
|
||||||
@ -112,8 +108,12 @@ public class LayoutShape implements Shape {
|
|||||||
pins.add(createPin(map, p));
|
pins.add(createPin(map, p));
|
||||||
|
|
||||||
color = custom.getCircuit().getAttributes().get(Keys.BACKGROUND_COLOR);
|
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 {
|
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.deriveFillStyle(color));
|
||||||
graphic.drawPolygon(poly, Style.NORMAL);
|
graphic.drawPolygon(poly, Style.NORMAL);
|
||||||
|
|
||||||
Vector center = new Vector(width * SIZE / 2, height * SIZE / 2);
|
if (top.size() == 0)
|
||||||
Graphic.drawText(graphic, center.add(0, -2), name, Orientation.CENTERBOTTOM, Style.SHAPE_PIN);
|
Graphic.drawText(graphic, new Vector(width * SIZE / 2, -4), name, Orientation.CENTERBOTTOM, Style.SHAPE_PIN);
|
||||||
Graphic.drawText(graphic, center.add(0, 2), label, Orientation.CENTERTOP, 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)
|
for (PinPos p : left)
|
||||||
Graphic.drawText(graphic, p.pos.add(4, 0), p.label, Orientation.LEFTCENTER, Style.SHAPE_PIN);
|
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) {
|
private void createPosition(HashMap<String, PinPos> map, Vector pos) {
|
||||||
Collections.sort(pins);
|
|
||||||
for (PinPos pp : pins) {
|
for (PinPos pp : pins) {
|
||||||
map.put(pp.label, pp);
|
map.put(pp.label, pp);
|
||||||
pp.pos = pos;
|
pp.pos = pos;
|
||||||
|
@ -67,6 +67,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
ATTR_LIST.add(Keys.SHAPE_TYPE);
|
ATTR_LIST.add(Keys.SHAPE_TYPE);
|
||||||
if (Main.isExperimentalMode())
|
if (Main.isExperimentalMode())
|
||||||
ATTR_LIST.add(Keys.CUSTOM_SHAPE);
|
ATTR_LIST.add(Keys.CUSTOM_SHAPE);
|
||||||
|
ATTR_LIST.add(Keys.HEIGHT);
|
||||||
ATTR_LIST.add(Keys.PINCOUNT);
|
ATTR_LIST.add(Keys.PINCOUNT);
|
||||||
ATTR_LIST.add(Keys.BACKGROUND_COLOR);
|
ATTR_LIST.add(Keys.BACKGROUND_COLOR);
|
||||||
ATTR_LIST.add(Keys.DESCRIPTION);
|
ATTR_LIST.add(Keys.DESCRIPTION);
|
||||||
|
@ -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_Value_tt">Der Wert der Konstanten.</string>
|
||||||
<string name="key_Width">Breite</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_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">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_autoReload_tt">Lädt das HEX-File bei jedem Modelstart neu.</string>
|
||||||
<string name="key_flipSelPos">Tausche Selektorposition</string><!-- Driver, DriverInvSel, Multiplexer, Demultiplexer, Decoder -->
|
<string name="key_flipSelPos">Tausche Selektorposition</string><!-- Driver, DriverInvSel, Multiplexer, Demultiplexer, Decoder -->
|
||||||
|
@ -992,6 +992,8 @@
|
|||||||
<string name="key_Value_tt">The value of the constant.</string>
|
<string name="key_Value_tt">The value of the constant.</string>
|
||||||
<string name="key_Width">Width</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_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">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_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 -->
|
<string name="key_flipSelPos">Flip selector position</string><!-- Driver, DriverInvSel, Multiplexer, Demultiplexer, Decoder -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user