Skip to content

Commit

Permalink
Merge pull request #4918 from gadfort/gui-rtree
Browse files Browse the repository at this point in the history
gui: use boost geom for shapes
  • Loading branch information
maliberty authored Apr 8, 2024
2 parents c8b2480 + 198d075 commit 8a3ea52
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 157 deletions.
47 changes: 20 additions & 27 deletions src/gui/src/layoutViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void LayoutViewer::searchNearestViaEdge(
search_line.yMax(),
shape_limit);
std::vector<odb::dbShape> shapes;
for (auto& [box, sbox, net] : via_shapes) {
for (const auto& [sbox, net] : via_shapes) {
if (isNetVisible(net)) {
sbox->getViaLayerBoxes(search_layer, shapes);
for (auto& shape : shapes) {
Expand Down Expand Up @@ -560,15 +560,6 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
}
};

auto convert_box_to_rect = [](const Search::Box& box) -> odb::Rect {
const auto min_corner = box.min_corner();
const auto max_corner = box.max_corner();
const odb::Point ll(min_corner.x(), min_corner.y());
const odb::Point ur(max_corner.x(), max_corner.y());

return odb::Rect(ll, ur);
};

// get die bounding box
Rect bbox = block_->getDieArea();
check_rect(bbox);
Expand Down Expand Up @@ -611,13 +602,13 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
// Cache the search results as we will iterate over the instances
// for each layer.
std::vector<dbInst*> insts;
for (auto& [box, inst] : inst_range) {
for (auto* inst : inst_range) {
if (options_->isInstanceVisible(inst)) {
if (inst_internals_visible) {
// only add inst if it can be used for pin or obs search
insts.push_back(inst);
}
check_rect(convert_box_to_rect(box));
check_rect(inst->getBBox()->getBox());
}
}

Expand Down Expand Up @@ -665,15 +656,15 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
search_line.xMax(),
search_line.yMax(),
shape_limit);
for (auto& [box, is_via, net] : box_shapes) {
for (const auto& [box, is_via, net] : box_shapes) {
if (!routing_visible && !is_via) {
continue;
}
if (!vias_visible && is_via) {
continue;
}
if (isNetVisible(net)) {
check_rect(convert_box_to_rect(box));
check_rect(box);
}
}
}
Expand Down Expand Up @@ -702,9 +693,9 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
search_line.xMax(),
search_line.yMax(),
shape_limit);
for (auto& [box, poly, net] : polygon_shapes) {
for (const auto& [box, poly, net] : polygon_shapes) {
if (isNetVisible(net)) {
check_rect(convert_box_to_rect(box));
check_rect(box->getBox());
}
}
}
Expand All @@ -717,8 +708,10 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
search_line.xMax(),
search_line.yMax(),
shape_limit);
for (auto& [box, fill] : fills) {
check_rect(convert_box_to_rect(box));
for (auto* fill : fills) {
odb::Rect box;
fill->getRect(box);
check_rect(box);
}
}

Expand All @@ -730,8 +723,8 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
search_line.xMax(),
search_line.yMax(),
shape_limit);
for (auto& [box, ob] : obs) {
check_rect(convert_box_to_rect(box));
for (auto* ob : obs) {
check_rect(ob->getBBox()->getBox());
}
}
}
Expand All @@ -743,8 +736,8 @@ std::pair<LayoutViewer::Edge, bool> LayoutViewer::searchNearestEdge(
search_line.xMax(),
search_line.yMax(),
shape_limit);
for (auto& [box, blck] : blcks) {
check_rect(convert_box_to_rect(box));
for (auto* blck : blcks) {
check_rect(blck->getBBox()->getBox());
}
}

Expand Down Expand Up @@ -805,7 +798,7 @@ void LayoutViewer::selectViaShapesAt(dbTechLayer* cut_layer,
shape_limit);

std::vector<odb::dbShape> shapes;
for (auto& [box, sbox, net] : via_shapes) {
for (const auto& [sbox, net] : via_shapes) {
if (isNetVisible(net) && options_->isNetSelectable(net)) {
sbox->getViaLayerBoxes(select_layer, shapes);
for (auto& shape : shapes) {
Expand Down Expand Up @@ -836,7 +829,7 @@ void LayoutViewer::selectAt(odb::Rect region, std::vector<Selected>& selections)
region.xMax(),
region.yMax(),
shape_limit);
for (auto& [box, blockage] : blockages) {
for (auto* blockage : blockages) {
selections.push_back(gui_->makeSelected(blockage));
}
}
Expand Down Expand Up @@ -868,8 +861,8 @@ void LayoutViewer::selectAt(odb::Rect region, std::vector<Selected>& selections)
region.xMax(),
region.yMax(),
shape_limit);
for (auto& [box, obs] : obs) {
selections.push_back(gui_->makeSelected(obs));
for (auto* ob : obs) {
selections.push_back(gui_->makeSelected(ob));
}
}

Expand Down Expand Up @@ -942,7 +935,7 @@ void LayoutViewer::selectAt(odb::Rect region, std::vector<Selected>& selections)
region.yMax(),
instanceSizeLimit());

for (auto& [box, inst] : insts) {
for (auto* inst : insts) {
if (options_->isInstanceVisible(inst)) {
if (options_->isInstanceSelectable(inst)) {
selections.push_back(gui_->makeSelected(inst));
Expand Down
36 changes: 16 additions & 20 deletions src/gui/src/renderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void RenderThread::drawInstanceShapes(dbTechLayer* layer,
instance_limit);
child_insts.clear();
child_insts.reserve(10000);
for (auto& [box, inst] : inst_range) {
for (auto* inst : inst_range) {
if (viewer_->options_->isInstanceVisible(inst)) {
child_insts.push_back(inst);
}
Expand Down Expand Up @@ -788,7 +788,7 @@ void RenderThread::drawBlockages(QPainter* painter,
bounds.yMax(),
viewer_->shapeSizeLimit());

for (auto& [box, blockage] : blockage_range) {
for (auto* blockage : blockage_range) {
if (restart_) {
break;
}
Expand Down Expand Up @@ -821,7 +821,7 @@ void RenderThread::drawObstructions(odb::dbBlock* block,
bounds.yMax(),
viewer_->shapeSizeLimit());

for (auto& [box, obs] : obstructions_range) {
for (auto* obs : obstructions_range) {
if (restart_) {
break;
}
Expand All @@ -846,7 +846,7 @@ void RenderThread::drawViaShapes(QPainter* painter,
shape_limit);

std::vector<odb::dbShape> via_shapes;
for (auto& [box, sbox, net] : via_sbox_iter) {
for (const auto& [sbox, net] : via_sbox_iter) {
if (restart_) {
break;
}
Expand Down Expand Up @@ -923,10 +923,8 @@ void RenderThread::drawLayer(QPainter* painter,
if (!viewer_->isNetVisible(net)) {
continue;
}
const auto& ll = box.min_corner();
const auto& ur = box.max_corner();
painter->drawRect(
QRect(ll.x(), ll.y(), ur.x() - ll.x(), ur.y() - ll.y()));
const auto& ll = box.ll();
painter->drawRect(QRect(ll.x(), ll.y(), box.dx(), box.dy()));
}
}

Expand Down Expand Up @@ -990,14 +988,14 @@ void RenderThread::drawLayer(QPainter* painter,
bounds.yMax(),
shape_limit);

for (auto& i : iter) {
for (auto* fill : iter) {
if (restart_) {
break;
}
const auto& ll = std::get<0>(i).min_corner();
const auto& ur = std::get<0>(i).max_corner();
painter->drawRect(
QRect(ll.x(), ll.y(), ur.x() - ll.x(), ur.y() - ll.y()));
odb::Rect box;
fill->getRect(box);
const auto& ll = box.ll();
painter->drawRect(QRect(ll.x(), ll.y(), box.dx(), box.dy()));
}
}
}
Expand Down Expand Up @@ -1083,7 +1081,7 @@ void RenderThread::drawBlock(QPainter* painter,
// for each layer.
std::vector<dbInst*> insts;
insts.reserve(10000);
for (auto& [box, inst] : inst_range) {
for (auto* inst : inst_range) {
if (restart_) {
break;
}
Expand Down Expand Up @@ -1546,10 +1544,10 @@ void RenderThread::drawIOPins(Painter& painter,

// RTree used to search for overlapping shapes and decide if rotation of
// text is needed.
bgi::rtree<Search::Box, bgi::quadratic<16>> pin_text_spec_shapes;
bgi::rtree<odb::Rect, bgi::quadratic<16>> pin_text_spec_shapes;
struct PinText
{
Search::Box rect;
odb::Rect rect;
bool can_rotate;
std::string text;
odb::Point pt;
Expand Down Expand Up @@ -1652,12 +1650,10 @@ void RenderThread::drawIOPins(Painter& painter,
pin_specs.anchor,
pin_specs.text);
text_rect.bloat(text_margin, text_rect);
pin_specs.rect
= Search::Box(Search::Point(text_rect.xMin(), text_rect.yMin()),
Search::Point(text_rect.xMax(), text_rect.yMax()));
pin_specs.rect = text_rect;
pin_text_spec_shapes.insert(pin_specs.rect);
} else {
pin_specs.rect = Search::Box();
pin_specs.rect = odb::Rect();
}
pin_text_spec.push_back(pin_specs);
}
Expand Down
Loading

0 comments on commit 8a3ea52

Please sign in to comment.