Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#1407 from The-OpenROAD-Projec…
Browse files Browse the repository at this point in the history
…t-staging/gui-displaycontrol-menus

gui: right click in display controls
  • Loading branch information
gadfort authored Dec 9, 2021
2 parents c1b3451 + f97e34e commit 9522701
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
124 changes: 124 additions & 0 deletions src/gui/src/displayControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,16 @@ DisplayControls::DisplayControls(QWidget* parent)
: QDockWidget("Display Control", parent),
view_(new QTreeView(this)),
model_(new DisplayControlModel(user_data_item_idx_, this)),
layers_menu_(new QMenu(this)),
layers_menu_layer_(nullptr),
ignore_callback_(false),
db_(nullptr),
logger_(nullptr),
tech_inited_(false)
{
setObjectName("layers"); // for settings
view_->setModel(model_);
view_->setContextMenuPolicy(Qt::CustomContextMenu);

QHeaderView* header = view_->header();
header->setSectionResizeMode(Name, QHeaderView::Stretch);
Expand All @@ -258,6 +261,8 @@ DisplayControls::DisplayControls(QWidget* parent)
// QTreeView defaults stretchLastSection to true, overriding setSectionResizeMode
header->setStretchLastSection(false);

createLayerMenu();

auto layers = makeParentItem(
layers_group_,
"Layers",
Expand Down Expand Up @@ -368,6 +373,11 @@ DisplayControls::DisplayControls(QWidget* parent)
this,
SLOT(displayItemDblClicked(const QModelIndex&)));

connect(view_,
SIGNAL(customContextMenuRequested(const QPoint &)),
this,
SLOT(itemContextMenu(const QPoint &)));

// register renderers
if (gui::Gui::get() != nullptr) {
for (auto renderer : gui::Gui::get()->renderers()) {
Expand All @@ -381,6 +391,48 @@ DisplayControls::~DisplayControls()
custom_controls_.clear();
}

void DisplayControls::createLayerMenu()
{
connect(layers_menu_->addAction("Show only selected"),
&QAction::triggered,
[this]() {
layerShowOnlySelectedNeighbors(0, 0);
});


const QString show_range = "Show layer range ";
const QString updown_arrow = "\u2195";
const QString down_arrow = "\u2193";
const QString up_arrow = "\u2191";
auto add_range_action = [&](int up, int down) {
QString arrows;
for (int n = 1; n < down; n++) {
arrows += up_arrow;
}
if (up > 0 && down > 0) {
arrows += updown_arrow;
} else if (down > 0) {
arrows += up_arrow;
} else if (up > 0) {
arrows += down_arrow;
}
for (int n = 1; n < up; n++) {
arrows += down_arrow;
}

connect(layers_menu_->addAction(show_range + arrows),
&QAction::triggered,
[this, up, down]() {
layerShowOnlySelectedNeighbors(down, up);
});
};

add_range_action(1, 1); // 1 layer above / below
add_range_action(2, 2); // 2 layers above / below
add_range_action(0, 1); // 1 layer below
add_range_action(1, 0); // 1 layer above
}

void DisplayControls::writeSettingsForRow(QSettings* settings, const ModelRow& row)
{
auto asBool
Expand Down Expand Up @@ -1524,4 +1576,76 @@ void DisplayControls::buildRestoreTclCommands(std::vector<std::string>& cmds, co
}
}

void DisplayControls::itemContextMenu(const QPoint &point)
{
const QModelIndex index = view_->indexAt(point);

if (!index.isValid()) {
return;
}

// check if index is a layer
const QModelIndex parent = index.parent();
if (!parent.isValid()) {
return;
}

auto* parent_item = model_->itemFromIndex(parent);
if (parent_item != layers_group_.name) {
// not a member of the layers
return;
}

const QModelIndex name_index = model_->index(index.row(), Name, parent);
auto* name_item = model_->itemFromIndex(name_index);
layers_menu_layer_ = name_item->data(user_data_item_idx_).value<odb::dbTechLayer*>();

layers_menu_->popup(view_->viewport()->mapToGlobal(point));
}

void DisplayControls::layerShowOnlySelectedNeighbors(int lower, int upper)
{
if (layers_menu_layer_ == nullptr) {
return;
}

std::set<const odb::dbTechLayer*> layers;
collectNeighboringLayers(layers_menu_layer_, lower, upper, layers);
setOnlyVisibleLayers(layers);

layers_menu_layer_ = nullptr;
}

void DisplayControls::collectNeighboringLayers(odb::dbTechLayer* layer,
int lower,
int upper,
std::set<const odb::dbTechLayer*>& layers)
{
if (layer == nullptr) {
return;
}

layers.insert(layer);
if (lower > 0) {
collectNeighboringLayers(layer->getLowerLayer(), lower - 1, 0, layers);
}

if (upper > 0) {
collectNeighboringLayers(layer->getUpperLayer(), 0, upper - 1, layers);
}
}

void DisplayControls::setOnlyVisibleLayers(const std::set<const odb::dbTechLayer*> layers)
{
for (auto& [layer, row] : layer_controls_) {
row.visible->setCheckState(Qt::Unchecked);
}

for (auto* layer : layers) {
if (layer_controls_.count(layer) != 0) {
layer_controls_[layer].visible->setCheckState(Qt::Checked);
}
}
}

} // namespace gui
12 changes: 12 additions & 0 deletions src/gui/src/displayControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QGridLayout>
#include <QGroupBox>
#include <QLineEdit>
#include <QMenu>
#include <QModelIndex>
#include <QRadioButton>
#include <QSettings>
Expand All @@ -48,6 +49,7 @@
#include <QVBoxLayout>
#include <functional>
#include <map>
#include <set>
#include <vector>

#include "options.h"
Expand Down Expand Up @@ -227,6 +229,9 @@ class DisplayControls : public QDockWidget, public Options
void displayItemSelected(const QItemSelection& selected);
void displayItemDblClicked(const QModelIndex& index);

private slots:
void itemContextMenu(const QPoint &point);

private:
// The columns in the tree view
enum Column
Expand Down Expand Up @@ -328,8 +333,15 @@ class DisplayControls : public QDockWidget, public Options
void setNameItemDoubleClickAction(ModelRow& row, const std::function<void(void)>& callback);
void setItemExclusivity(ModelRow& row, const std::set<std::string>& exclusivity);

void createLayerMenu();
void layerShowOnlySelectedNeighbors(int lower, int upper);
void collectNeighboringLayers(odb::dbTechLayer* layer, int lower, int upper, std::set<const odb::dbTechLayer*>& layers);
void setOnlyVisibleLayers(const std::set<const odb::dbTechLayer*> layers);

QTreeView* view_;
DisplayControlModel* model_;
QMenu* layers_menu_;
odb::dbTechLayer* layers_menu_layer_;

bool ignore_callback_;

Expand Down

0 comments on commit 9522701

Please sign in to comment.