Skip to content

Commit

Permalink
[HandPlacer] Cleanup snapping code in hand placer (#1091)
Browse files Browse the repository at this point in the history
* Cleanup snapping code in hand placer

Signed-off-by: Chris Lavin <[email protected]>

* Fix PolynomialGenerator example line connection visualization

Signed-off-by: Chris Lavin <[email protected]>

---------

Signed-off-by: Chris Lavin <[email protected]>
  • Loading branch information
clavin-xlnx authored Nov 1, 2024
1 parent b0487b0 commit afed028
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
7 changes: 5 additions & 2 deletions src/com/xilinx/rapidwright/examples/PolynomialGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.xilinx.rapidwright.edif.EDIFCell;
import com.xilinx.rapidwright.edif.EDIFCellInst;
import com.xilinx.rapidwright.edif.EDIFDirection;
import com.xilinx.rapidwright.edif.EDIFLibrary;
import com.xilinx.rapidwright.edif.EDIFNet;
import com.xilinx.rapidwright.edif.EDIFNetlist;
import com.xilinx.rapidwright.edif.EDIFPort;
Expand Down Expand Up @@ -138,7 +137,7 @@ public static void buildOperatorTree(String[] tokens, Design d, EDIFPortInst[] r


buildOperatorTree(left,d,inputA);
buildOperatorTree(right,d,inputB);
buildOperatorTree(right, d, inputB);
}

private static void ensureCellTypesSet(Module module) {
Expand Down Expand Up @@ -379,6 +378,10 @@ public static Design generatePolynomial(String polynomial, String name, int widt

buildOperatorTree(p, d, results);

// This is redundant if the design will be routed later, but is necessary
// for correct visualization in the Hand Placer tool
RWRoute.preprocess(d);

releaseOperators();

d.addXDCConstraint(ConstraintGroup.LATE, "create_clock -name "+CLK_NAME+" -period 1.291 [get_ports "+CLK_NAME+"]");
Expand Down
34 changes: 10 additions & 24 deletions src/com/xilinx/rapidwright/gui/GUIModuleInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class GUIModuleInst extends QGraphicsPolygonItem {
private ArrayList<Integer> occupiedTilesY;
private ArrayList<GUIMultiNetLine> myLines;

public static int SNAPPING_DISTANCE = 100;

public GUIModuleInst(ModuleInst modInst, TileScene scene, boolean movable) {
this.moduleInst = modInst;
this.scene = scene;
Expand Down Expand Up @@ -438,32 +440,22 @@ public void mouseDoubleClickEvent(QGraphicsSceneMouseEvent event) {
public Object itemChange(GraphicsItemChange change, Object value) {
if (change == GraphicsItemChange.ItemSelectedHasChanged) {
selected.emit(QVariant.toBoolean(value));
} else if (change == GraphicsItemChange.ItemPositionHasChanged
&& scene() != null) {
} else if (change == GraphicsItemChange.ItemPositionHasChanged && scene() != null) {
moved.emit();
} else if (change == GraphicsItemChange.ItemPositionChange
&& scene() != null) {
} else if (change == GraphicsItemChange.ItemPositionChange && scene() != null) {
// value is the new position.

return makeValidPosition((QPointF) value);
}
return super.itemChange(change, value);
}

private Tile toTile(QPointF newPos) {

//newPos = newPos.subtract(grabOffset);



QRectF rect = scene().sceneRect();
double width = this.boundingRect().width();
width = Math.floor(width / scene.tileSize);
double height = this.boundingRect().height();
height = Math.floor(height / scene.tileSize);
QPointF p = rect.bottomRight();
//p.setX((fpScene.device.getColumns() - width) * fpScene.tileSize);
//p.setY((fpScene.device.getRows() - height) * fpScene.tileSize);

p.setX((scene.cols - width) * scene.tileSize);
p.setY((scene.rows - height) * scene.tileSize);
Expand All @@ -479,30 +471,24 @@ private Tile toTile(QPointF newPos) {
}

private QPointF makeValidPosition(QPointF newPos) {

final Tile target = toTile(newPos);
Tile result = null;
float bestDistance = Float.POSITIVE_INFINITY;
float closestValidPlacement = Float.POSITIVE_INFINITY;

for (Site placement : moduleInst.getModule().getAllValidPlacements()) {
float xDiff = placement.getTile().getColumn() - target.getColumn();
float yDiff = placement.getTile().getRow() - target.getRow();
float dist = xDiff * xDiff + yDiff * yDiff;

if (dist < bestDistance) {
bestDistance = dist;
if (dist < closestValidPlacement) {
closestValidPlacement = dist;
result = placement.getTile();
}
}

//Only snap to valid placement if it is close
if (bestDistance > 200) {
result = target;
}

return new QPointF(scene.getDrawnTileX(result)*scene.tileSize, scene.getDrawnTileY(result)*scene.tileSize)
.subtract(getAnchorOffset());

// Only snap to valid placement if it is close
return closestValidPlacement > SNAPPING_DISTANCE ? scene.getTilePoint(target)
: scene.getTilePoint(result).subtract(getAnchorOffset());
}

public boolean isGrabbed() {
Expand Down
3 changes: 3 additions & 0 deletions src/com/xilinx/rapidwright/gui/TileScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ public int getDrawnTileY(Tile tile) {
return tmp;
}

public QPointF getTilePoint(Tile tile) {
return new QPointF(getDrawnTileX(tile) * tileSize, getDrawnTileY(tile) * tileSize);
}

public Design getDesign() {
return design;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class HandPlacer extends QMainWindow {
Device device;
private QComboBox netViewCombo;

private static String title = "Hand HMPlacer";
private static String title = "Hand Placer";

private String currOpenFileName = null;

Expand Down

0 comments on commit afed028

Please sign in to comment.