Skip to content

Commit 9c4f2c8

Browse files
committed
Add zoom to fit when selecting a new cell.
Signed-off-by: Chris Lavin <[email protected]>
1 parent 80db61c commit 9c4f2c8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/com/xilinx/rapidwright/gui/NetlistBrowser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,14 @@ private void init() {
116116
addDockWidget(DockWidgetArea.RightDockWidgetArea, schematicWidget);
117117

118118
schematicScene.objectSelected.connect(this, "selectFromSchematic(String)");
119+
schematicScene.cellDrawn.connect(schematicView, "zoomToFit()");
119120
}
120121

121122
public void selectNetlistItem(QModelIndex index) {
122123
QTreeWidgetItem item = treeWidget.getItemFromIndex(index);
123124
if (item instanceof HierCellInstTreeWidgetItem) {
124125
EDIFHierCellInst cellInst = ((HierCellInstTreeWidgetItem) item).getInst();
125-
schematicScene.drawCell(cellInst);
126+
schematicScene.drawCell(cellInst, true);
126127
} else if (item.data(0, 0) instanceof EDIFPort) {
127128
EDIFPort port = (EDIFPort) item.data(0, 0);
128129
schematicScene.selectObject(item.data(1, 0).toString(), true);

src/com/xilinx/rapidwright/gui/SchematicScene.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class SchematicScene extends QGraphicsScene {
9696
private Set<String> selectedObjects = new HashSet<>();
9797

9898
public Signal1<String> objectSelected = new Signal1<>();
99+
public Signal0 cellDrawn = new Signal0();
99100

100101
private static QFont FONT = new QFont("Arial", 8);
101102
private static QFont BUTTON_TEXT_FONT = new QFont("Arial", 10, QFont.Weight.Bold.value());
@@ -168,7 +169,7 @@ private void applyElkNodeProperties(ElkNode root) {
168169
root.setProperty(CoreOptions.SPACING_EDGE_NODE, EDGE_TO_NODE_SPACING);
169170
}
170171

171-
public void drawCell(EDIFHierCellInst cellInst) {
172+
public void drawCell(EDIFHierCellInst cellInst, boolean zoomFit) {
172173
clear();
173174
portInstMap.clear();
174175
elkNodeTopPortMap.clear();
@@ -185,6 +186,9 @@ public void drawCell(EDIFHierCellInst cellInst) {
185186
engine.layout(elkRoot, monitor);
186187

187188
renderSchematic();
189+
if (zoomFit) {
190+
cellDrawn.emit();
191+
}
188192
}
189193

190194
public void renderSchematic() {
@@ -700,7 +704,8 @@ private void toggleCellInstExpansion(String cellInstName) {
700704
} else {
701705
expandedCellInsts.add(cellInstName);
702706
}
703-
drawCell(currCellInst);
707+
boolean zoomFit = false;
708+
drawCell(currCellInst, zoomFit);
704709
}
705710

706711
private void toggleSelection(String lookup, boolean multipleSelection) {

src/com/xilinx/rapidwright/gui/SchematicView.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
import com.trolltech.qt.core.QPoint;
2626
import com.trolltech.qt.core.QPointF;
27+
import com.trolltech.qt.core.QRectF;
2728
import com.trolltech.qt.core.Qt;
29+
import com.trolltech.qt.core.Qt.AspectRatioMode;
2830
import com.trolltech.qt.core.Qt.CursorShape;
2931
import com.trolltech.qt.core.Qt.Key;
3032
import com.trolltech.qt.gui.QCursor;
@@ -159,4 +161,21 @@ public void zoomOut() {
159161
if (this.matrix().m11() > zoomMin)
160162
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
161163
}
164+
165+
public void zoomToFit() {
166+
QRectF sceneRect = scene().sceneRect();
167+
if (sceneRect != null) {
168+
fitInView(sceneRect, AspectRatioMode.KeepAspectRatio);
169+
double zoom = this.matrix().m11();
170+
if (zoom > zoomMax) {
171+
resetMatrix();
172+
scale(zoomMax, zoomMax);
173+
fitInView(sceneRect, AspectRatioMode.KeepAspectRatio);
174+
} else if (zoom < zoomMin) {
175+
resetMatrix();
176+
scale(zoomMin, zoomMin);
177+
fitInView(sceneRect, AspectRatioMode.KeepAspectRatio);
178+
}
179+
}
180+
}
162181
}

0 commit comments

Comments
 (0)