Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gui/include/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ class Gui

// Zoom to the given rectangle
void zoomTo(const odb::Rect& rect_dbu);
// zoom to the specified point
void zoomTo(const odb::Point& focus, int diameter);
void zoomIn();
void zoomIn(const odb::Point& focus_dbu);
void zoomOut();
Expand Down
42 changes: 20 additions & 22 deletions src/gui/src/gotoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GotoLocationDialog::GotoLocationDialog(QWidget* parent, LayoutTabs* viewers)
: QDialog(parent), viewers_(viewers)
{
setupUi(this);
connect(gotoBtn, &QPushButton::clicked, this, &GotoLocationDialog::goTo);
}

void GotoLocationDialog::updateUnits(int dbu_per_micron, bool use_dbu)
Expand All @@ -32,32 +33,28 @@ void GotoLocationDialog::updateUnits(int dbu_per_micron, bool use_dbu)
}

// NOLINTNEXTLINE(readability-non-const-parameter)
void GotoLocationDialog::updateLocation(QLineEdit* x_edit, QLineEdit* y_edit)
void GotoLocationDialog::updateLocation()
{
auto viewer = viewers_->getCurrent();
x_edit->setText(QString::fromStdString(Descriptor::Property::convert_dbu(
if (!viewer) {
return;
}
xEdit->setText(QString::fromStdString(Descriptor::Property::convert_dbu(
viewer->getVisibleCenter().x(), false)));
y_edit->setText(QString::fromStdString(Descriptor::Property::convert_dbu(
yEdit->setText(QString::fromStdString(Descriptor::Property::convert_dbu(
viewer->getVisibleCenter().y(), false)));
int box_size = viewer->getVisibleDiameter();
sEdit->setText(QString::fromStdString(
Descriptor::Property::convert_dbu(box_size, false)));
}

void GotoLocationDialog::show_init()
void GotoLocationDialog::showInit()
{
auto viewer = viewers_->getCurrent();
GotoLocationDialog::updateLocation(xEdit, yEdit);
int box_size = sqrt(pow((viewer->getVisibleBounds().lr().x()
- viewer->getVisibleBounds().ll().x()),
2)
+ pow((viewer->getVisibleBounds().ul().y()
- viewer->getVisibleBounds().ll().y()),
2))
/ 2;
sEdit->setText(QString::fromStdString(
Descriptor::Property::convert_dbu(box_size, false)));
updateLocation();
show();
}

void GotoLocationDialog::accept()
void GotoLocationDialog::goTo()
{
auto gui = gui::Gui::get();
bool convert_x_ok;
Expand All @@ -67,14 +64,15 @@ void GotoLocationDialog::accept()
xEdit->text().toStdString(), &convert_x_ok);
int y_coord = Descriptor::Property::convert_string(
yEdit->text().toStdString(), &convert_y_ok);
int box_size = Descriptor::Property::convert_string(
int diameter = Descriptor::Property::convert_string(
sEdit->text().toStdString(), &convert_s_ok);
if (convert_x_ok && convert_y_ok && convert_s_ok) {
gui->zoomTo(odb::Rect(x_coord - box_size,
y_coord - box_size,
x_coord + box_size,
y_coord + box_size));
gui->zoomTo(odb::Point(x_coord, y_coord), diameter);
}
GotoLocationDialog::updateLocation(xEdit, yEdit);
updateLocation();
}

void GotoLocationDialog::accept()
{
}
} // namespace gui
5 changes: 3 additions & 2 deletions src/gui/src/gotoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class GotoLocationDialog : public QDialog, public Ui::GotoLocDialog
public:
GotoLocationDialog(QWidget* parent = nullptr, LayoutTabs* viewers = nullptr);
public slots:
void updateLocation(QLineEdit* x_edit, QLineEdit* y_edit);
void updateLocation();
void updateUnits(int dbu_per_micron, bool use_dbu);
void show_init();
void showInit();
void goTo();
void accept() override;
};
} // namespace gui
5 changes: 5 additions & 0 deletions src/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@ void Gui::zoomTo(const odb::Rect& rect_dbu)
main_window->zoomTo(rect_dbu);
}

void Gui::zoomTo(const odb::Point& focus, int diameter)
{
main_window->zoomTo(focus, diameter);
}

void Gui::zoomIn()
{
main_window->getLayoutViewer()->zoomIn();
Expand Down
8 changes: 8 additions & 0 deletions src/gui/src/layoutTabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void LayoutTabs::chipLoaded(odb::dbChip* chip)
&LayoutViewer::focusNetsChanged,
this,
&LayoutTabs::focusNetsChanged);
connect(viewer, &LayoutViewer::viewUpdated, this, &LayoutTabs::viewUpdated);

emit newViewer(viewer);
}
Expand Down Expand Up @@ -177,6 +178,13 @@ void LayoutTabs::zoomTo(const odb::Rect& rect_dbu)
}
}

void LayoutTabs::zoomTo(const odb::Point& focus, int diameter)
{
if (current_viewer_) {
current_viewer_->zoomTo(focus, diameter);
}
}

void LayoutTabs::fit()
{
if (current_viewer_) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/src/layoutTabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class LayoutTabs : public QTabWidget
void focusNetsChanged();
void routeGuidesChanged();
void netTracksChanged();
void viewUpdated();

public slots:
void tabChange(int index);
Expand All @@ -95,6 +96,7 @@ class LayoutTabs : public QTabWidget
void zoomIn();
void zoomOut();
void zoomTo(const odb::Rect& rect_dbu);
void zoomTo(const odb::Point& focus, int diameter);
void chipLoaded(odb::dbChip* chip);
void fit();
void fullRepaint();
Expand Down
61 changes: 44 additions & 17 deletions src/gui/src/layoutViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,39 +251,35 @@ qreal LayoutViewer::computePixelsPerDBU(const QSize& size, const Rect& dbu_rect)
size.height() / (double) dbu_rect.dy());
}

void LayoutViewer::setPixelsPerDBU(qreal pixels_per_dbu)
void LayoutViewer::setPixelsPerDBU(qreal target_pixels_per_dbu)
{
if (!hasDesign()) {
return;
}

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

if (!scroll_bars_visible && zoomed_out) {
return;
}

const Rect current_viewer(0,
0,
this->size().width() / pixels_per_dbu_,
this->size().height() / pixels_per_dbu_);
qreal current_viewer_x = this->size().width() / pixels_per_dbu_;
qreal current_viewer_y = this->size().height() / pixels_per_dbu_;

// ensure max size is not exceeded
qreal maximum_pixels_per_dbu
= 0.98
* computePixelsPerDBU(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX),
current_viewer);
qreal target_pixels_per_dbu
= std::min(pixels_per_dbu, maximum_pixels_per_dbu);
Rect(0, 0, current_viewer_x, current_viewer_y));

if (target_pixels_per_dbu == maximum_pixels_per_dbu) {
if (target_pixels_per_dbu >= maximum_pixels_per_dbu) {
return;
}

const QSize new_size(ceil(current_viewer.dx() * target_pixels_per_dbu),
ceil(current_viewer.dy() * target_pixels_per_dbu));
const QSize new_size(ceil(current_viewer_x * target_pixels_per_dbu),
ceil(current_viewer_y * target_pixels_per_dbu));

resize(new_size);
}
Expand Down Expand Up @@ -421,17 +417,46 @@ void LayoutViewer::zoom(const odb::Point& focus,

void LayoutViewer::zoomTo(const Rect& rect_dbu)
{
const Rect padded_rect = getPaddedRect(rect_dbu);

// set resolution required to view the whole padded rect
setPixelsPerDBU(
computePixelsPerDBU(scroller_->maximumViewportSize(), padded_rect));
qreal pixels_per_DBU
= computePixelsPerDBU(scroller_->maximumViewportSize(), rect_dbu);
qreal pixels_per_DBU_with_margins
= pixels_per_DBU / (1 + 2 * defaultZoomMargin);
setPixelsPerDBU(pixels_per_DBU_with_margins);

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

void LayoutViewer::zoomTo(const odb::Point& focus, int diameter)
{
odb::Point ref
= odb::Point(focus.x() - (diameter / 2), focus.y() - (diameter / 2));
zoomTo(odb::Rect(ref.x(), ref.y(), ref.x() + diameter, ref.y() + diameter));
}

int LayoutViewer::getVisibleDiameter()
{
odb::Rect bounds = getVisibleBounds();
// scrollbar
int scrollBarWidth
= std::ceil((qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent))
/ pixels_per_dbu_);
if (scroller_->verticalScrollBar()->isVisible()) {
bounds.set_xhi(bounds.xMax() + scrollBarWidth);
}
if (scroller_->horizontalScrollBar()->isVisible()) {
bounds.set_yhi(bounds.yMax() + scrollBarWidth);
}

// undo the margin
const int smaller_side = std::min(bounds.dx(), bounds.dy());
const int margin = std::ceil(smaller_side * 2 * defaultZoomMargin
/ (1 + 2 * defaultZoomMargin));

return std::min(bounds.dx(), bounds.dy()) - margin;
}

int LayoutViewer::edgeToPointDistance(const odb::Point& pt,
const Edge& edge) const
{
Expand Down Expand Up @@ -1986,6 +2011,8 @@ void LayoutViewer::fullRepaint()
setLoadingState();
viewer_thread_.render(rect, selected_, highlighted_, rulers_, labels_);
}

emit(viewUpdated());
}

void LayoutViewer::fit()
Expand Down
12 changes: 11 additions & 1 deletion src/gui/src/layoutViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class LayoutViewer : public QWidget
bool isCursorInsideViewport();
void updateCursorCoordinates();

// gets the size of the diameter of the biggest circle that fits the view
int getVisibleDiameter();

signals:
// indicates the current location of the mouse
void location(int x, int y);
Expand All @@ -183,6 +186,8 @@ class LayoutViewer : public QWidget

void focusNetsChanged();

void viewUpdated();

public slots:
// zoom in the layout, keeping the current center_
void zoomIn();
Expand All @@ -205,6 +210,9 @@ class LayoutViewer : public QWidget
// zoom to the specified rect
void zoomTo(const odb::Rect& rect_dbu);

// zoom to the specified point
void zoomTo(const odb::Point& focus, int diameter);

// indicates a chip has been loaded
void chipLoaded(odb::dbChip* chip);

Expand Down Expand Up @@ -291,7 +299,8 @@ class LayoutViewer : public QWidget

qreal computePixelsPerDBU(const QSize& size, const odb::Rect& dbu_rect);
odb::Rect getBounds() const;
odb::Rect getPaddedRect(const odb::Rect& rect, double factor = 0.05);
odb::Rect getPaddedRect(const odb::Rect& rect,
double factor = defaultZoomMargin);

bool hasDesign() const;
int getDbuPerMicron() const;
Expand Down Expand Up @@ -435,6 +444,7 @@ class LayoutViewer : public QWidget
std::string loading_indicator_;

static constexpr qreal kZoomScaleFactor = 1.2;
static constexpr double defaultZoomMargin = 0.05;

// parameters used to animate the selection of objects
static constexpr int kAnimationRepeats = 6;
Expand Down
11 changes: 10 additions & 1 deletion src/gui/src/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
&MainWindow::displayUnitsChanged,
goto_dialog_,
&GotoLocationDialog::updateUnits);
connect(viewers_,
&LayoutTabs::viewUpdated,
goto_dialog_,
&GotoLocationDialog::updateLocation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "gui::GotoLocationDialog" is directly included [misc-include-cleaner]

src/gui/src/mainWindow.cpp:20:

- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ #include "src/gotoDialog.h"
+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

connect(selection_timer_.get(), &QTimer::timeout, [this]() {
emit selectionChanged();
});
Expand Down Expand Up @@ -1431,6 +1435,11 @@ void MainWindow::zoomTo(const odb::Rect& rect_dbu)
viewers_->zoomTo(rect_dbu);
}

void MainWindow::zoomTo(const odb::Point& focus, int diameter)
{
viewers_->zoomTo(focus, diameter);
}

void MainWindow::zoomInToItems(const QList<const Selected*>& items)
{
if (items.empty()) {
Expand Down Expand Up @@ -1471,7 +1480,7 @@ void MainWindow::showGotoDialog()
return;
}

goto_dialog_->show_init();
goto_dialog_->showInit();
}

void MainWindow::showHelp()
Expand Down
3 changes: 3 additions & 0 deletions src/gui/src/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class MainWindow : public QMainWindow, public odb::dbDatabaseObserver
// Zoom to the given rectangle
void zoomTo(const odb::Rect& rect_dbu);

// zoom to the specified point
void zoomTo(const odb::Point& focus, int diameter);

// Zoom In To Items such that its bbox is in visible Area
void zoomInToItems(const QList<const Selected*>& items);

Expand Down
17 changes: 14 additions & 3 deletions src/gui/ui/gotoDlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<x>0</x>
<y>0</y>
<width>150</width>
<height>100</height>
<height>120</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -69,7 +69,7 @@
<number>3</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,1,1">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,1,1,0">
<property name="spacing">
<number>3</number>
</property>
Expand Down Expand Up @@ -240,12 +240,23 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="sEdit"/>
<widget class="QLineEdit" name="sEdit">
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="gotoBtn">
<property name="text">
<string>Go to</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down