Skip to content

Commit

Permalink
Improve position of reset and scan ports
Browse files Browse the repository at this point in the history
Position ports at the bottom of circuit schematic.
Align new ports with existing ports.
Make use of proxy contacts to reduce clutter.
  • Loading branch information
danilovesky committed Oct 18, 2024
1 parent efc1c1f commit 01982d1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public static boolean insertReset(VisualCircuit circuit, boolean isActiveLow) {
for (VisualFunctionComponent component : resetComponents) {
insertReset(circuit, component, resetPort, isActiveLow);
}
SpaceUtils.positionPort(circuit, resetPort, false);
CircuitUtils.detachJoint(circuit, resetPort, 0.5);
SpaceUtils.positionPortAtBottom(circuit, resetPort, false);
setInitialisationProtocol(circuit, resetPort, isActiveLow);
return true;
}
Expand All @@ -227,6 +226,7 @@ private static boolean insertReset(VisualCircuit circuit, VisualFunctionComponen
appendResetToComponent(circuit, component, resetPort, isActiveLow);
} else {
CircuitUtils.connectIfPossible(circuit, resetPort, resetInputPin);
ConversionUtils.replicateDriverContact(circuit, resetInputPin);
}
return true;
}
Expand Down Expand Up @@ -389,6 +389,7 @@ private static Collection<VisualFunctionComponent> resetByReplacingGate(VisualCi
if (!forcedInitOutputs.isEmpty()) {
VisualFunctionContact initContact = getOrCreateResetPin(circuit, component, initGatePinPair.getSecond());
CircuitUtils.connectIfPossible(circuit, resetPort, initContact);
ConversionUtils.replicateDriverContact(circuit, initContact);
for (VisualFunctionContact contact : forcedInitOutputs) {
insertResetFunction(contact, initContact, isActiveLow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.workcraft.dom.Node;
import org.workcraft.dom.references.Identifier;
import org.workcraft.dom.visual.connections.VisualConnection;
import org.workcraft.formula.*;
import org.workcraft.plugins.circuit.*;
import org.workcraft.plugins.circuit.genlib.GateInterface;
Expand Down Expand Up @@ -234,9 +233,9 @@ private static void connectCommonInputPort(VisualCircuit circuit, List<VisualFun
for (VisualFunctionComponent component : components) {
VisualContact pin = getContactWithPathbreakerPinNameOrWithPortName(circuit, portName, component, pinName);
CircuitUtils.connectIfPossible(circuit, port, pin);
ConversionUtils.replicateDriverContact(circuit, pin);
}
SpaceUtils.positionPort(circuit, port, false);
CircuitUtils.detachJoint(circuit, port, 0.5);
SpaceUtils.positionPortAtBottom(circuit, port, false);
}
}

Expand Down Expand Up @@ -309,14 +308,13 @@ private static int connectIndividualScanPathbreaker(VisualCircuit circuit, Visua
return 0;
}

VisualConnection scaninConnection = connectFromIndividualInputPort(
circuit, scanData.scaninPortPrefix, index, scaninPin, false);

if ((scaninConnection != null) && needScaninInversion) {
connectFromIndividualInputPort(circuit, scanData.scaninPortPrefix, index, scaninPin, false);
if (needScaninInversion) {
VisualFunctionComponent inverterGate = GateUtils.createInverterGate(circuit);
String invInstancePrefix = CircuitSettings.getInitialisationInverterInstancePrefix();
circuit.setMathName(inverterGate, invInstancePrefix + index);
GateUtils.insertGateWithin(circuit, inverterGate, scaninConnection);
SpaceUtils.makeSpaceAroundContact(circuit, scaninPin, 2.0);
GateUtils.insertGateBefore(circuit, inverterGate, scaninPin, -1.5 * scanenPin.getDirection().getGradientX());
GateUtils.propagateInitialState(circuit, inverterGate);
}

Expand Down Expand Up @@ -370,31 +368,31 @@ private static int connectIndividualScanHierarchy(VisualCircuit circuit, VisualF
return count;
}

private static VisualConnection connectFromIndividualInputPort(VisualCircuit circuit, String portPrefix,
private static void connectFromIndividualInputPort(VisualCircuit circuit, String portPrefix,
int index, VisualContact pin, boolean initToOne) {

String portName = MatchingUtils.getSignalWithBusSuffix(portPrefix, index);
VisualContact port = getOrCreateNeverRiseForcedInitInputPort(circuit, portName,
VisualContact.Direction.WEST, initToOne);

CircuitUtils.disconnectContact(circuit, pin);
VisualConnection connection = CircuitUtils.connectIfPossible(circuit, port, pin);
SpaceUtils.positionPort(circuit, port, false);
return connection;
CircuitUtils.connectIfPossible(circuit, port, pin);
SpaceUtils.positionPortAtBottom(circuit, port, false);
ConversionUtils.replicateDriverContact(circuit, pin);
}

private static VisualConnection connectToIndividualOutputPort(VisualCircuit circuit, VisualContact pin,
private static void connectToIndividualOutputPort(VisualCircuit circuit, VisualContact pin,
String portPrefix, int index) {

String portName = MatchingUtils.getSignalWithBusSuffix(portPrefix, index);
VisualContact port = CircuitUtils.getOrCreatePort(circuit, portName,
Contact.IOType.OUTPUT, VisualContact.Direction.EAST);

CircuitUtils.disconnectContact(circuit, port);
VisualConnection connection = CircuitUtils.connectIfPossible(circuit, pin, port);
CircuitUtils.connectIfPossible(circuit, pin, port);
port.setInitToOne(pin.getInitToOne());
SpaceUtils.positionPort(circuit, port, true);
return connection;
SpaceUtils.positionPortAtBottom(circuit, port, true);
ConversionUtils.replicateDriverContact(circuit, port);
}

private static VisualContact getOrCreateContact(VisualCircuit circuit, VisualFunctionComponent component,
Expand Down Expand Up @@ -454,7 +452,7 @@ private static void stitchScanComponents(VisualCircuit circuit, List<VisualFunct
} else {
connectExistingScanChain(circuit, contact, oldScaninContacts);
}
SpaceUtils.positionPort(circuit, scaninPort, true);
SpaceUtils.alignPortWithPin(circuit, scaninPort, scaninPort.getDirection().getGradientX());
}

private static VisualContact stitchScanComponent(VisualCircuit circuit, VisualFunctionComponent component,
Expand All @@ -480,7 +478,8 @@ private static void connectScanoutPort(VisualCircuit circuit, VisualContact cont
contact = addBuffering(circuit, contact);
}
CircuitUtils.connectIfPossible(circuit, contact, scanoutPort);
SpaceUtils.positionPort(circuit, scanoutPort, true);
SpaceUtils.positionPortAtBottom(circuit, scanoutPort, true);
ConversionUtils.replicateDriverContact(circuit, scanoutPort);
}

private static boolean needsBuffering(VisualCircuit circuit, VisualContact contact) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.workcraft.dom.visual.*;
import org.workcraft.dom.visual.connections.ConnectionUtils;
import org.workcraft.dom.visual.connections.VisualConnection;
import org.workcraft.plugins.circuit.*;
import org.workcraft.plugins.circuit.VisualCircuit;
import org.workcraft.plugins.circuit.VisualContact;
import org.workcraft.plugins.circuit.VisualFunctionComponent;
import org.workcraft.utils.Hierarchy;

import java.awt.geom.Point2D;
Expand Down Expand Up @@ -104,44 +106,33 @@ public static Point2D getOffsetContactPosition(VisualContact contact, double spa
return new Point2D.Double(x, y);
}

public static void positionPort(VisualCircuit circuit, VisualContact port, boolean alignToRight) {
Collection<Touchable> nodes = new HashSet<>(Hierarchy.getChildrenOfType(circuit.getRoot(), VisualConnection.class));
for (VisualConnection connection : circuit.getConnections(port)) {
nodes.remove(connection);
}
nodes.addAll(Hierarchy.getChildrenOfType(circuit.getRoot(), VisualCircuitComponent.class));
nodes.addAll(Hierarchy.getChildrenOfType(circuit.getRoot(), VisualJoint.class));

Rectangle2D modelBox = BoundingBoxHelper.mergeBoundingBoxes(nodes);
double x = TransformHelper.snapP5(alignToRight ? modelBox.getMaxX() : modelBox.getMinX());
double y = modelBox.getCenterY();
if (port.isOutput()) {
VisualContact driver = CircuitUtils.findDriver(circuit, port, false);
if (driver != null) {
y = driver.getRootSpaceY();
}
} else {
Collection<VisualContact> driven = CircuitUtils.findDriven(circuit, port, false);
if (driven.size() == 1) {
y = driven.iterator().next().getRootSpaceY();
} else if (!driven.isEmpty()) {
Point2D p = MixUtils.middleRootspacePosition(driven);
if (p != null) {
y = TransformHelper.snapP5(p.getY());
}
}
}
boolean done = false;
while (!done) {
done = true;
for (VisualContact otherPort : circuit.getVisualPorts()) {
if ((port != otherPort) && (otherPort.getRootSpacePosition().distance(x, y) < 0.1)) {
y = TransformHelper.snapP5(y + 0.5);
done = false;
public static void positionPortAtBottom(VisualCircuit circuit, VisualContact port, boolean alignToRight) {
Rectangle2D modelBox = circuit.getBoundingBox();
double x = (modelBox == null) ? 0.0 : (alignToRight ? modelBox.getMaxX() : modelBox.getMinX());
double y = (modelBox == null) ? 0.0 : modelBox.getCenterY();
boolean foundOtherPortForAlignment = false;
double centerX = (modelBox == null) ? 0.0 : modelBox.getCenterX();
for (VisualContact otherPort : circuit.getVisualPorts()) {
if (port != otherPort) {
double otherX = otherPort.getRootSpaceX();
if (alignToRight == (otherX > centerX)) {
double otherY = otherPort.getRootSpaceY();
if (!foundOtherPortForAlignment) {
x = otherX;
y = otherY;
foundOtherPortForAlignment = true;
} else {
if (alignToRight == (x < otherX)) {
x = otherX;
}
if (y < otherY) {
y = otherY;
}
}
}
}
}
port.setRootSpacePosition(new Point2D.Double(x, y));
port.setRootSpacePosition(new Point2D.Double(TransformHelper.snapP5(x), TransformHelper.snapP5(y + 1.0)));
}

public static void alignPortWithPin(VisualContact port, VisualContact pin, double dx) {
Expand Down
2 changes: 1 addition & 1 deletion workcraft/WorkcraftCore/src/org/workcraft/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Info {
private static final String SUBTITLE_3 = "Return of the Hazard";
private static final String SUBTITLE_4 = "Revenge of the Timing Assumption";

private static final Version VERSION = new Version(3, 5, 2, Status.ALPHA);
private static final Version VERSION = new Version(3, 5, 2, Status.BETA);

private static final int START_YEAR = 2006;
private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);
Expand Down

0 comments on commit 01982d1

Please sign in to comment.