Skip to content

Commit

Permalink
fixes a bug if a generic circuit creates pins and is used with a Layo…
Browse files Browse the repository at this point in the history
…ut Shape, closes #625
  • Loading branch information
hneemann committed Jan 27, 2021
1 parent 6aaa353 commit 7fef9fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/main/dig/generic/modify/genAndTest.dig
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@
<visualElement>
<elementName>genAnd.dig</elementName>
<elementAttributes>
<entry>
<string>shapeType</string>
<shapeType>LAYOUT</shapeType>
</entry>
<entry>
<string>generic</string>
<string>inputs := 3;</string>
</entry>
</elementAttributes>
<pos x="760" y="520"/>
<pos x="760" y="500"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public Circuit getCircuit() {
return circuit;
}

/**
* Returns the resolved circuit if it is a generic circuit
*
* @param attributes the defining attributes
* @return the resolved circuit
* @throws NodeException NodeException
* @throws ElementNotFoundException ElementNotFoundException
*/
public Circuit getResolvedCircuit(ElementAttributes attributes) throws NodeException, ElementNotFoundException {
if (isGeneric())
return resolveGenerics.resolveCircuit(attributes).getCircuit();
else
return circuit;
}

/**
* Sets a custom description for this field
*
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/de/neemann/digital/draw/shapes/LayoutShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import de.neemann.digital.core.io.Out;
import de.neemann.digital.core.wiring.Clock;
import de.neemann.digital.draw.elements.*;
import de.neemann.digital.draw.graphics.*;
import de.neemann.digital.draw.graphics.Polygon;
import de.neemann.digital.draw.graphics.*;
import de.neemann.digital.draw.library.ElementNotFoundException;
import de.neemann.digital.draw.library.ElementTypeDescriptionCustom;
import de.neemann.digital.lang.Lang;

Expand All @@ -33,8 +34,8 @@
*/
public class LayoutShape implements Shape {

private int width;
private int height;
private final int width;
private final int height;
private final Pins pins;
private final Color color;
private final String name;
Expand All @@ -48,10 +49,11 @@ public class LayoutShape implements Shape {
*
* @param custom the type description
* @param elementAttributes the local attributes
* @throws NodeException NodeException
* @throws PinException PinException
* @throws NodeException NodeException
* @throws PinException PinException
* @throws ElementNotFoundException ElementNotFoundException
*/
public LayoutShape(ElementTypeDescriptionCustom custom, ElementAttributes elementAttributes) throws NodeException, PinException {
public LayoutShape(ElementTypeDescriptionCustom custom, ElementAttributes elementAttributes) throws NodeException, PinException, ElementNotFoundException {
String l = elementAttributes.getLabel();
if (l != null && l.length() > 0)
name = l;
Expand All @@ -63,7 +65,9 @@ public LayoutShape(ElementTypeDescriptionCustom custom, ElementAttributes elemen
top = new PinList(name, true);
bottom = new PinList(name, true);

for (VisualElement ve : custom.getCircuit().getElements()) {
Circuit circuit = custom.getResolvedCircuit(elementAttributes);

for (VisualElement ve : circuit.getElements()) {
if (ve.equalsDescription(In.DESCRIPTION) || ve.equalsDescription(Clock.DESCRIPTION)) {
switch (ve.getRotate()) {
case 0:
Expand Down Expand Up @@ -113,7 +117,7 @@ public LayoutShape(ElementTypeDescriptionCustom custom, ElementAttributes elemen
for (PinDescription p : custom.getOutputDescriptions(elementAttributes))
pins.add(createPin(map, p));

color = custom.getCircuit().getAttributes().get(Keys.BACKGROUND_COLOR);
color = circuit.getAttributes().get(Keys.BACKGROUND_COLOR);
}

private Pin createPin(HashMap<String, PinPos> map, PinDescription p) throws PinException {
Expand Down

0 comments on commit 7fef9fe

Please sign in to comment.