Skip to content

Commit c57e620

Browse files
authored
Merge pull request #9177 from LucasYuki/gui_goto
Gui goto
2 parents ed76164 + 14ac404 commit c57e620

File tree

11 files changed

+137
-78
lines changed

11 files changed

+137
-78
lines changed

src/gui/include/gui/gui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ class Gui
761761

762762
// Zoom to the given rectangle
763763
void zoomTo(const odb::Rect& rect_dbu);
764+
// zoom to the specified point
765+
void zoomTo(const odb::Point& focus, int diameter);
764766
void zoomIn();
765767
void zoomIn(const odb::Point& focus_dbu);
766768
void zoomOut();

src/gui/src/gotoDialog.cpp

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,50 @@ GotoLocationDialog::GotoLocationDialog(QWidget* parent, LayoutTabs* viewers)
1616
: QDialog(parent), viewers_(viewers)
1717
{
1818
setupUi(this);
19-
}
20-
21-
void GotoLocationDialog::updateUnits(int dbu_per_micron, bool use_dbu)
22-
{
23-
if (use_dbu) {
24-
xEdit->setText(QString::number(xEdit->text().toDouble() * dbu_per_micron));
25-
yEdit->setText(QString::number(yEdit->text().toDouble() * dbu_per_micron));
26-
sEdit->setText(QString::number(sEdit->text().toDouble() * dbu_per_micron));
27-
} else {
28-
xEdit->setText(QString::number(xEdit->text().toDouble() / dbu_per_micron));
29-
yEdit->setText(QString::number(yEdit->text().toDouble() / dbu_per_micron));
30-
sEdit->setText(QString::number(sEdit->text().toDouble() / dbu_per_micron));
31-
}
19+
connect(gotoBtn, &QPushButton::clicked, this, &GotoLocationDialog::goTo);
3220
}
3321

3422
// NOLINTNEXTLINE(readability-non-const-parameter)
35-
void GotoLocationDialog::updateLocation(QLineEdit* x_edit, QLineEdit* y_edit)
23+
void GotoLocationDialog::updateLocation()
3624
{
3725
auto viewer = viewers_->getCurrent();
26+
if (!viewer) {
27+
return;
28+
}
3829
x_edit->setText(QString::fromStdString(Descriptor::Property::convert_dbu(
3930
viewer->getVisibleCenter().x(), false)));
4031
y_edit->setText(QString::fromStdString(Descriptor::Property::convert_dbu(
4132
viewer->getVisibleCenter().y(), false)));
33+
int box_size = viewer->getVisibleDiameter();
34+
s_edit->setText(QString::fromStdString(
35+
Descriptor::Property::convert_dbu(box_size, false)));
4236
}
4337

44-
void GotoLocationDialog::show_init()
38+
void GotoLocationDialog::showInit()
4539
{
46-
auto viewer = viewers_->getCurrent();
47-
GotoLocationDialog::updateLocation(xEdit, yEdit);
48-
int box_size = sqrt(pow((viewer->getVisibleBounds().lr().x()
49-
- viewer->getVisibleBounds().ll().x()),
50-
2)
51-
+ pow((viewer->getVisibleBounds().ul().y()
52-
- viewer->getVisibleBounds().ll().y()),
53-
2))
54-
/ 2;
55-
sEdit->setText(QString::fromStdString(
56-
Descriptor::Property::convert_dbu(box_size, false)));
40+
updateLocation();
5741
show();
5842
}
5943

60-
void GotoLocationDialog::accept()
44+
void GotoLocationDialog::goTo()
6145
{
6246
auto gui = gui::Gui::get();
6347
bool convert_x_ok;
6448
bool convert_y_ok;
6549
bool convert_s_ok;
6650
int x_coord = Descriptor::Property::convert_string(
67-
xEdit->text().toStdString(), &convert_x_ok);
51+
x_edit->text().toStdString(), &convert_x_ok);
6852
int y_coord = Descriptor::Property::convert_string(
69-
yEdit->text().toStdString(), &convert_y_ok);
70-
int box_size = Descriptor::Property::convert_string(
71-
sEdit->text().toStdString(), &convert_s_ok);
53+
y_edit->text().toStdString(), &convert_y_ok);
54+
int diameter = Descriptor::Property::convert_string(
55+
s_edit->text().toStdString(), &convert_s_ok);
7256
if (convert_x_ok && convert_y_ok && convert_s_ok) {
73-
gui->zoomTo(odb::Rect(x_coord - box_size,
74-
y_coord - box_size,
75-
x_coord + box_size,
76-
y_coord + box_size));
57+
gui->zoomTo(odb::Point(x_coord, y_coord), diameter);
7758
}
78-
GotoLocationDialog::updateLocation(xEdit, yEdit);
59+
updateLocation();
60+
}
61+
62+
void GotoLocationDialog::accept()
63+
{
7964
}
8065
} // namespace gui

src/gui/src/gotoDialog.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class GotoLocationDialog : public QDialog, public Ui::GotoLocDialog
1919
public:
2020
GotoLocationDialog(QWidget* parent = nullptr, LayoutTabs* viewers = nullptr);
2121
public slots:
22-
void updateLocation(QLineEdit* x_edit, QLineEdit* y_edit);
23-
void updateUnits(int dbu_per_micron, bool use_dbu);
24-
void show_init();
22+
void updateLocation();
23+
void showInit();
24+
void goTo();
2525
void accept() override;
2626
};
2727
} // namespace gui

src/gui/src/gui.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ void Gui::zoomTo(const odb::Rect& rect_dbu)
707707
main_window->zoomTo(rect_dbu);
708708
}
709709

710+
void Gui::zoomTo(const odb::Point& focus, int diameter)
711+
{
712+
main_window->zoomTo(focus, diameter);
713+
}
714+
710715
void Gui::zoomIn()
711716
{
712717
main_window->getLayoutViewer()->zoomIn();

src/gui/src/layoutTabs.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ void LayoutTabs::chipLoaded(odb::dbChip* chip)
124124
&LayoutViewer::focusNetsChanged,
125125
this,
126126
&LayoutTabs::focusNetsChanged);
127+
connect(viewer, &LayoutViewer::viewUpdated, this, &LayoutTabs::viewUpdated);
127128

128129
emit newViewer(viewer);
129130
}
@@ -177,6 +178,13 @@ void LayoutTabs::zoomTo(const odb::Rect& rect_dbu)
177178
}
178179
}
179180

181+
void LayoutTabs::zoomTo(const odb::Point& focus, int diameter)
182+
{
183+
if (current_viewer_) {
184+
current_viewer_->zoomTo(focus, diameter);
185+
}
186+
}
187+
180188
void LayoutTabs::fit()
181189
{
182190
if (current_viewer_) {

src/gui/src/layoutTabs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class LayoutTabs : public QTabWidget
8585
void focusNetsChanged();
8686
void routeGuidesChanged();
8787
void netTracksChanged();
88+
void viewUpdated();
8889

8990
public slots:
9091
void tabChange(int index);
@@ -95,6 +96,7 @@ class LayoutTabs : public QTabWidget
9596
void zoomIn();
9697
void zoomOut();
9798
void zoomTo(const odb::Rect& rect_dbu);
99+
void zoomTo(const odb::Point& focus, int diameter);
98100
void chipLoaded(odb::dbChip* chip);
99101
void fit();
100102
void fullRepaint();

src/gui/src/layoutViewer.cpp

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,39 +251,35 @@ qreal LayoutViewer::computePixelsPerDBU(const QSize& size, const Rect& dbu_rect)
251251
size.height() / (double) dbu_rect.dy());
252252
}
253253

254-
void LayoutViewer::setPixelsPerDBU(qreal pixels_per_dbu)
254+
void LayoutViewer::setPixelsPerDBU(qreal target_pixels_per_dbu)
255255
{
256256
if (!hasDesign()) {
257257
return;
258258
}
259259

260260
bool scroll_bars_visible = scroller_->horizontalScrollBar()->isVisible()
261261
|| scroller_->verticalScrollBar()->isVisible();
262-
bool zoomed_out = pixels_per_dbu_ /*old*/ > pixels_per_dbu /*new*/;
262+
bool zoomed_out = pixels_per_dbu_ /*old*/ > target_pixels_per_dbu /*new*/;
263263

264264
if (!scroll_bars_visible && zoomed_out) {
265265
return;
266266
}
267267

268-
const Rect current_viewer(0,
269-
0,
270-
this->size().width() / pixels_per_dbu_,
271-
this->size().height() / pixels_per_dbu_);
268+
qreal current_viewer_x = this->size().width() / pixels_per_dbu_;
269+
qreal current_viewer_y = this->size().height() / pixels_per_dbu_;
272270

273271
// ensure max size is not exceeded
274272
qreal maximum_pixels_per_dbu
275273
= 0.98
276274
* computePixelsPerDBU(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX),
277-
current_viewer);
278-
qreal target_pixels_per_dbu
279-
= std::min(pixels_per_dbu, maximum_pixels_per_dbu);
275+
Rect(0, 0, current_viewer_x, current_viewer_y));
280276

281-
if (target_pixels_per_dbu == maximum_pixels_per_dbu) {
277+
if (target_pixels_per_dbu >= maximum_pixels_per_dbu) {
282278
return;
283279
}
284280

285-
const QSize new_size(ceil(current_viewer.dx() * target_pixels_per_dbu),
286-
ceil(current_viewer.dy() * target_pixels_per_dbu));
281+
const QSize new_size(ceil(current_viewer_x * target_pixels_per_dbu),
282+
ceil(current_viewer_y * target_pixels_per_dbu));
287283

288284
resize(new_size);
289285
}
@@ -421,17 +417,46 @@ void LayoutViewer::zoom(const odb::Point& focus,
421417

422418
void LayoutViewer::zoomTo(const Rect& rect_dbu)
423419
{
424-
const Rect padded_rect = getPaddedRect(rect_dbu);
425-
426-
// set resolution required to view the whole padded rect
427-
setPixelsPerDBU(
428-
computePixelsPerDBU(scroller_->maximumViewportSize(), padded_rect));
420+
qreal pixels_per_DBU
421+
= computePixelsPerDBU(scroller_->maximumViewportSize(), rect_dbu);
422+
qreal pixels_per_DBU_with_margins
423+
= pixels_per_DBU / (1 + 2 * defaultZoomMargin);
424+
setPixelsPerDBU(pixels_per_DBU_with_margins);
429425

430426
// center the layout at the middle of the rect
431427
centerAt(Point(rect_dbu.xMin() + rect_dbu.dx() / 2,
432428
rect_dbu.yMin() + rect_dbu.dy() / 2));
433429
}
434430

431+
void LayoutViewer::zoomTo(const odb::Point& focus, int diameter)
432+
{
433+
odb::Point ref
434+
= odb::Point(focus.x() - (diameter / 2), focus.y() - (diameter / 2));
435+
zoomTo(odb::Rect(ref.x(), ref.y(), ref.x() + diameter, ref.y() + diameter));
436+
}
437+
438+
int LayoutViewer::getVisibleDiameter()
439+
{
440+
odb::Rect bounds = getVisibleBounds();
441+
// scrollbar
442+
int scrollBarWidth
443+
= std::ceil((qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent))
444+
/ pixels_per_dbu_);
445+
if (scroller_->verticalScrollBar()->isVisible()) {
446+
bounds.set_xhi(bounds.xMax() + scrollBarWidth);
447+
}
448+
if (scroller_->horizontalScrollBar()->isVisible()) {
449+
bounds.set_yhi(bounds.yMax() + scrollBarWidth);
450+
}
451+
452+
// undo the margin
453+
const int smaller_side = std::min(bounds.dx(), bounds.dy());
454+
const int margin = std::ceil(smaller_side * 2 * defaultZoomMargin
455+
/ (1 + 2 * defaultZoomMargin));
456+
457+
return std::min(bounds.dx(), bounds.dy()) - margin;
458+
}
459+
435460
int LayoutViewer::edgeToPointDistance(const odb::Point& pt,
436461
const Edge& edge) const
437462
{
@@ -1986,6 +2011,8 @@ void LayoutViewer::fullRepaint()
19862011
setLoadingState();
19872012
viewer_thread_.render(rect, selected_, highlighted_, rulers_, labels_);
19882013
}
2014+
2015+
emit(viewUpdated());
19892016
}
19902017

19912018
void LayoutViewer::fit()

src/gui/src/layoutViewer.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class LayoutViewer : public QWidget
167167
bool isCursorInsideViewport();
168168
void updateCursorCoordinates();
169169

170+
// gets the size of the diameter of the biggest circle that fits the view
171+
int getVisibleDiameter();
172+
170173
signals:
171174
// indicates the current location of the mouse
172175
void location(int x, int y);
@@ -183,6 +186,8 @@ class LayoutViewer : public QWidget
183186

184187
void focusNetsChanged();
185188

189+
void viewUpdated();
190+
186191
public slots:
187192
// zoom in the layout, keeping the current center_
188193
void zoomIn();
@@ -205,6 +210,9 @@ class LayoutViewer : public QWidget
205210
// zoom to the specified rect
206211
void zoomTo(const odb::Rect& rect_dbu);
207212

213+
// zoom to the specified point
214+
void zoomTo(const odb::Point& focus, int diameter);
215+
208216
// indicates a chip has been loaded
209217
void chipLoaded(odb::dbChip* chip);
210218

@@ -291,7 +299,8 @@ class LayoutViewer : public QWidget
291299

292300
qreal computePixelsPerDBU(const QSize& size, const odb::Rect& dbu_rect);
293301
odb::Rect getBounds() const;
294-
odb::Rect getPaddedRect(const odb::Rect& rect, double factor = 0.05);
302+
odb::Rect getPaddedRect(const odb::Rect& rect,
303+
double factor = defaultZoomMargin);
295304

296305
bool hasDesign() const;
297306
int getDbuPerMicron() const;
@@ -435,6 +444,7 @@ class LayoutViewer : public QWidget
435444
std::string loading_indicator_;
436445

437446
static constexpr qreal kZoomScaleFactor = 1.2;
447+
static constexpr double defaultZoomMargin = 0.05;
438448

439449
// parameters used to animate the selection of objects
440450
static constexpr int kAnimationRepeats = 6;

src/gui/src/mainWindow.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "displayControls.h"
4646
#include "drcWidget.h"
4747
#include "globalConnectDialog.h"
48+
#include "gotoDialog.h"
4849
#include "gui/gui.h"
4950
#include "gui/heatMap.h"
5051
#include "helpWidget.h"
@@ -395,10 +396,10 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
395396
drc_viewer_->updateSelection(*selected_.begin());
396397
}
397398
});
398-
connect(this,
399-
&MainWindow::displayUnitsChanged,
399+
connect(viewers_,
400+
&LayoutTabs::viewUpdated,
400401
goto_dialog_,
401-
&GotoLocationDialog::updateUnits);
402+
&GotoLocationDialog::updateLocation);
402403
connect(selection_timer_.get(), &QTimer::timeout, [this]() {
403404
emit selectionChanged();
404405
});
@@ -1431,6 +1432,11 @@ void MainWindow::zoomTo(const odb::Rect& rect_dbu)
14311432
viewers_->zoomTo(rect_dbu);
14321433
}
14331434

1435+
void MainWindow::zoomTo(const odb::Point& focus, int diameter)
1436+
{
1437+
viewers_->zoomTo(focus, diameter);
1438+
}
1439+
14341440
void MainWindow::zoomInToItems(const QList<const Selected*>& items)
14351441
{
14361442
if (items.empty()) {
@@ -1471,7 +1477,7 @@ void MainWindow::showGotoDialog()
14711477
return;
14721478
}
14731479

1474-
goto_dialog_->show_init();
1480+
goto_dialog_->showInit();
14751481
}
14761482

14771483
void MainWindow::showHelp()

src/gui/src/mainWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ class MainWindow : public QMainWindow, public odb::dbDatabaseObserver
227227
// Zoom to the given rectangle
228228
void zoomTo(const odb::Rect& rect_dbu);
229229

230+
// zoom to the specified point
231+
void zoomTo(const odb::Point& focus, int diameter);
232+
230233
// Zoom In To Items such that its bbox is in visible Area
231234
void zoomInToItems(const QList<const Selected*>& items);
232235

0 commit comments

Comments
 (0)