mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-09 21:05:46 -04:00
added debugging rectangles to circuit
This commit is contained in:
parent
ab5e853814
commit
6e738b960d
@ -243,7 +243,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
||||
|
||||
private void addFragmentToCircuit(Fragment fr, Circuit circuit) {
|
||||
fr.setPos(new Vector(0, 0));
|
||||
de.neemann.digital.builder.circuit.Box b = fr.doLayout();
|
||||
Box b = fr.doLayout();
|
||||
|
||||
fr.addToCircuit(new Vector(0, pos), circuit);
|
||||
pos += b.getHeight() + SIZE * 2;
|
||||
|
@ -4,6 +4,8 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.core.element.PinDescription;
|
||||
import de.neemann.digital.core.flipflops.FlipflopD;
|
||||
import de.neemann.digital.core.flipflops.FlipflopJK;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.Pin;
|
||||
import de.neemann.digital.draw.elements.Pins;
|
||||
@ -15,6 +17,8 @@ import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
|
||||
/**
|
||||
* A fragment describing a VisualElement
|
||||
*
|
||||
@ -91,7 +95,11 @@ public class FragmentVisualElement implements Fragment {
|
||||
for (Vector p : outputs)
|
||||
mm.check(p);
|
||||
Vector delta = mm.getMax().sub(mm.getMin());
|
||||
return new Box(delta.x, delta.y);
|
||||
if (visualElement.equalsDescription(FlipflopJK.DESCRIPTION)
|
||||
|| visualElement.equalsDescription(FlipflopD.DESCRIPTION))
|
||||
return new Box(delta.x, delta.y + SIZE); // Space for label
|
||||
else
|
||||
return new Box(delta.x, delta.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,6 +13,8 @@ import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.memory.DataField;
|
||||
import de.neemann.digital.core.wiring.Clock;
|
||||
import de.neemann.digital.draw.graphics.Graphic;
|
||||
import de.neemann.digital.draw.graphics.Polygon;
|
||||
import de.neemann.digital.draw.graphics.Style;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.draw.shapes.Drawable;
|
||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
@ -48,6 +50,7 @@ public class Circuit {
|
||||
private List<String> measurementOrdering;
|
||||
private transient boolean dotsPresent = false;
|
||||
private transient boolean modified = false;
|
||||
private transient ArrayList<CircRect> recs;
|
||||
|
||||
/**
|
||||
* Creates a proper configurated XStream instance
|
||||
@ -183,6 +186,11 @@ public class Circuit {
|
||||
p.drawTo(graphic, highLighted.contains(p));
|
||||
graphic.closeGroup();
|
||||
}
|
||||
|
||||
// plot debugging rectangles
|
||||
if (recs != null)
|
||||
for (CircRect r : recs)
|
||||
r.drawTo(graphic);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -545,4 +553,37 @@ public class Circuit {
|
||||
this.measurementOrdering = measurementOrdering;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a rectangle to the circuit.
|
||||
* Only used to debug the {@link de.neemann.digital.builder.circuit.CircuitBuilder}.
|
||||
*
|
||||
* @param pos pos of rectangle
|
||||
* @param size size of rectangle
|
||||
*/
|
||||
public void addRect(Vector pos, Vector size) {
|
||||
if (recs == null)
|
||||
recs = new ArrayList<>();
|
||||
recs.add(new CircRect(pos, size));
|
||||
}
|
||||
|
||||
private static final class CircRect {
|
||||
private final Vector pos;
|
||||
private final Vector size;
|
||||
|
||||
private CircRect(Vector pos, Vector size) {
|
||||
this.pos = pos;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
private void drawTo(Graphic graphic) {
|
||||
|
||||
Polygon p = new Polygon(true)
|
||||
.add(pos)
|
||||
.add(pos.add(size.x, 0))
|
||||
.add(pos.add(size))
|
||||
.add(pos.add(0, size.y));
|
||||
|
||||
graphic.drawPolygon(p, Style.DASH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,31 @@
|
||||
package de.neemann.digital.builder.circuit;
|
||||
|
||||
import de.neemann.digital.core.flipflops.FlipflopJK;
|
||||
import de.neemann.digital.draw.elements.Tunnel;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
|
||||
/**
|
||||
* @author hneemann
|
||||
*/
|
||||
public class FragmentExpressionTest extends TestCase {
|
||||
|
||||
public void testCalcBackOffset1() throws Exception {
|
||||
public void testBox() throws Exception {
|
||||
ShapeFactory shapeFactory = new ShapeFactory(new ElementLibrary());
|
||||
FragmentVisualElement ve = new FragmentVisualElement(FlipflopJK.DESCRIPTION,shapeFactory);
|
||||
FragmentExpression fe = new FragmentExpression(ve, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory));
|
||||
|
||||
fe.setPos(new Vector(0,0));
|
||||
Box box = fe.doLayout();
|
||||
assertEquals(SIZE*3, box.getHeight());
|
||||
assertEquals(SIZE*4, box.getWidth());
|
||||
}
|
||||
|
||||
public void testCalcBackOffset() throws Exception {
|
||||
assertEquals(0, FragmentExpression.calcBackOffset(1, 0));
|
||||
|
||||
assertEquals(1, FragmentExpression.calcBackOffset(2, 0));
|
||||
|
@ -0,0 +1,24 @@
|
||||
package de.neemann.digital.builder.circuit;
|
||||
|
||||
import de.neemann.digital.core.flipflops.FlipflopJK;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
|
||||
/**
|
||||
* @author hneemann
|
||||
*/
|
||||
public class FragmentVisualElementTest extends TestCase {
|
||||
|
||||
public void testBox() throws Exception {
|
||||
ShapeFactory shapeFactory = new ShapeFactory(new ElementLibrary());
|
||||
FragmentVisualElement ve = new FragmentVisualElement(FlipflopJK.DESCRIPTION,shapeFactory);
|
||||
ve.setPos(new Vector(0,0));
|
||||
Box box = ve.doLayout();
|
||||
assertEquals(SIZE*3, box.getHeight());
|
||||
assertEquals(SIZE*3, box.getWidth());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user