Skip to content

Commit ec6fd4c

Browse files
authored
Merge pull request #8083 from LucasYuki/gui_timing_widget_filter_clock
Gui: Add clock filter in the Timing Report
2 parents 8d69146 + 33dd5ff commit ec6fd4c

File tree

9 files changed

+254
-18
lines changed

9 files changed

+254
-18
lines changed

src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if (Qt5_FOUND AND BUILD_GUI)
6969
src/bufferTreeDescriptor.cpp
7070
src/chartsWidget.cpp
7171
src/GUIProgress.cpp
72+
src/dropdownCheckboxes.cpp
7273
resources/resource.qrc
7374
)
7475

src/gui/src/dropdownCheckboxes.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2021-2025, The OpenROAD Authors
3+
4+
#include "dropdownCheckboxes.h"
5+
6+
#include <qnamespace.h>
7+
8+
namespace gui {
9+
10+
DropdownCheckboxes::DropdownCheckboxes(const std::string& name,
11+
const std::string& all_text,
12+
QWidget* parent)
13+
: QComboBox(parent),
14+
name_item_(new QStandardItem(QString::fromStdString(name))),
15+
all_item_(new QStandardItem(QString::fromStdString(all_text))),
16+
model_(new QStandardItemModel(this)),
17+
updating_check_boxes_(false)
18+
{
19+
setup();
20+
}
21+
22+
DropdownCheckboxes::DropdownCheckboxes(const QString& name,
23+
const QString& all_text,
24+
QWidget* parent)
25+
: QComboBox(parent),
26+
name_item_(new QStandardItem(name)),
27+
all_item_(new QStandardItem(all_text)),
28+
model_(new QStandardItemModel(this)),
29+
updating_check_boxes_(false)
30+
{
31+
setup();
32+
}
33+
34+
void DropdownCheckboxes::setup()
35+
{
36+
name_item_->setFlags(Qt::NoItemFlags);
37+
all_item_->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled
38+
| Qt::ItemIsAutoTristate);
39+
all_item_->setData(Qt::Checked, Qt::CheckStateRole);
40+
model_->appendRow(name_item_);
41+
model_->appendRow(all_item_);
42+
43+
setModel(model_);
44+
setCurrentIndex(0);
45+
46+
connect(model_,
47+
&QStandardItemModel::itemChanged,
48+
this,
49+
&DropdownCheckboxes::itemChanged);
50+
}
51+
52+
void DropdownCheckboxes::clear()
53+
{
54+
model_->removeRows(2, model_->rowCount() - 2);
55+
}
56+
57+
void DropdownCheckboxes::itemChanged(QStandardItem* item)
58+
{
59+
if (updating_check_boxes_) {
60+
return;
61+
}
62+
63+
updating_check_boxes_ = true;
64+
if (item == all_item_) { // set all check boxes to all_item_ state
65+
Qt::CheckState state = all_item_->checkState();
66+
if (state == Qt::PartiallyChecked) {
67+
return;
68+
}
69+
for (auto row = 2; row < model_->rowCount(); row++) {
70+
QStandardItem* item_iter = model_->item(row);
71+
if (item_iter->checkState() != state) {
72+
item_iter->setCheckState(state);
73+
}
74+
}
75+
} else { // updates all_item_ state
76+
bool all_checked = true;
77+
bool all_unchecked = true;
78+
for (auto row = 2; row < model_->rowCount(); row++) {
79+
QStandardItem* item_iter = model_->item(row);
80+
if (item_iter->checkState() == Qt::Unchecked) {
81+
all_checked = false;
82+
} else {
83+
all_unchecked = false;
84+
}
85+
}
86+
if (all_checked) {
87+
all_item_->setCheckState(Qt::Checked);
88+
} else if (all_unchecked) {
89+
all_item_->setCheckState(Qt::Unchecked);
90+
} else {
91+
all_item_->setCheckState(Qt::PartiallyChecked);
92+
}
93+
}
94+
updating_check_boxes_ = false;
95+
}
96+
97+
std::vector<QString> DropdownCheckboxes::selectedItems()
98+
{
99+
std::vector<QString> selected;
100+
for (auto row = 2; row < model_->rowCount(); row++) {
101+
QStandardItem* item_iter = model_->item(row);
102+
if (item_iter->checkState() == Qt::Checked) {
103+
selected.push_back(item_iter->text());
104+
}
105+
}
106+
return selected;
107+
}
108+
109+
} // namespace gui

src/gui/src/dropdownCheckboxes.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2021-2025, The OpenROAD Authors
3+
4+
#pragma once
5+
6+
#include <qchar.h>
7+
#include <qobjectdefs.h>
8+
9+
#include <QComboBox>
10+
#include <QStandardItem>
11+
#include <QStandardItemModel>
12+
13+
namespace sta {
14+
class dbSta;
15+
class Clock;
16+
} // namespace sta
17+
18+
namespace gui {
19+
class DropdownCheckboxes : public QComboBox
20+
{
21+
Q_OBJECT
22+
public:
23+
DropdownCheckboxes(const std::string& name,
24+
const std::string& all_text = "All",
25+
QWidget* parent = nullptr);
26+
DropdownCheckboxes(const QString& name,
27+
const QString& all_text = "All",
28+
QWidget* parent = nullptr);
29+
void clear();
30+
31+
void setName(const std::string& name)
32+
{
33+
name_item_->setText(QString::fromStdString(name));
34+
};
35+
void setName(const QString& name) { name_item_->setText(name); };
36+
QString getName() { return name_item_->text(); };
37+
QStandardItem* getNameItem() { return name_item_; };
38+
39+
void setAllText(const std::string& text)
40+
{
41+
all_item_->setText(QString::fromStdString(text));
42+
};
43+
void setAllText(const QString& text) { all_item_->setText(text); };
44+
QString getAllText() { return all_item_->text(); };
45+
QStandardItem* getAllItem() { return all_item_; };
46+
47+
QStandardItemModel* model() { return model_; };
48+
std::vector<QString> selectedItems();
49+
50+
public slots:
51+
void itemChanged(QStandardItem* item);
52+
53+
private:
54+
QStandardItem* name_item_;
55+
QStandardItem* all_item_;
56+
QStandardItemModel* model_;
57+
bool updating_check_boxes_;
58+
59+
void setup();
60+
void updateName();
61+
};
62+
63+
} // namespace gui

src/gui/src/staGui.cpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#include "staGui.h"
55

6+
#include <qchar.h>
7+
#include <qglobal.h>
8+
69
#include <QAbstractItemView>
710
#include <QAction>
811
#include <QApplication>
@@ -15,7 +18,6 @@
1518
#include <cstddef>
1619
#include <fstream>
1720
#include <functional>
18-
#include <iostream>
1921
#include <iterator>
2022
#include <limits>
2123
#include <map>
@@ -30,10 +32,12 @@
3032
#include "dbDescriptors.h"
3133
#include "db_sta/dbNetwork.hh"
3234
#include "db_sta/dbSta.hh"
35+
#include "gui/gui.h"
3336
#include "odb/db.h"
3437
#include "odb/dbObject.h"
3538
#include "odb/dbShape.h"
3639
#include "odb/geom.h"
40+
#include "sta/Clock.hh"
3741
#include "sta/Corner.hh"
3842
#include "sta/PatternMatch.hh"
3943
#include "sta/Units.hh"
@@ -266,26 +270,28 @@ void TimingPathsModel::populateModel(
266270
const std::set<const sta::Pin*>& from,
267271
const std::vector<std::set<const sta::Pin*>>& thru,
268272
const std::set<const sta::Pin*>& to,
269-
const std::string& path_group_name)
273+
const std::string& path_group_name,
274+
sta::ClockSet* clks)
270275
{
271276
beginResetModel();
272277
timing_paths_.clear();
273-
populatePaths(from, thru, to, path_group_name);
278+
populatePaths(from, thru, to, path_group_name, clks);
274279
endResetModel();
275280
}
276281

277282
bool TimingPathsModel::populatePaths(
278283
const std::set<const sta::Pin*>& from,
279284
const std::vector<std::set<const sta::Pin*>>& thru,
280285
const std::set<const sta::Pin*>& to,
281-
const std::string& path_group_name)
286+
const std::string& path_group_name,
287+
sta::ClockSet* clks)
282288
{
283289
// On lines of DataBaseHandler
284290
QApplication::setOverrideCursor(Qt::WaitCursor);
285291

286292
const bool sta_max = sta_->isUseMax();
287293
sta_->setUseMax(is_setup_);
288-
timing_paths_ = sta_->getTimingPaths(from, thru, to, path_group_name);
294+
timing_paths_ = sta_->getTimingPaths(from, thru, to, path_group_name, clks);
289295
sta_->setUseMax(sta_max);
290296

291297
QApplication::restoreOverrideCursor();
@@ -1117,6 +1123,9 @@ TimingControlsDialog::TimingControlsDialog(QWidget* parent)
11171123
layout_(new QFormLayout),
11181124
path_count_spin_box_(new QSpinBox(this)),
11191125
corner_box_(new QComboBox(this)),
1126+
clock_box_(new DropdownCheckboxes(QString("Select Clocks"),
1127+
QString("All Clocks"),
1128+
this)),
11201129
unconstrained_(new QCheckBox(this)),
11211130
one_path_per_endpoint_(new QCheckBox(this)),
11221131
expand_clk_(new QCheckBox(this)),
@@ -1132,6 +1141,7 @@ TimingControlsDialog::TimingControlsDialog(QWidget* parent)
11321141
layout_->addRow("Paths:", path_count_spin_box_);
11331142
layout_->addRow("Expand clock:", expand_clk_);
11341143
layout_->addRow("Corner:", corner_box_);
1144+
layout_->addRow("Clock filter:", clock_box_);
11351145

11361146
setupPinRow("From:", from_);
11371147
setThruPin({});
@@ -1250,6 +1260,20 @@ void TimingControlsDialog::populate()
12501260
}
12511261

12521262
corner_box_->setCurrentIndex(selection);
1263+
1264+
for (auto clk : *sta_->getClocks()) {
1265+
QString clk_name = clk->name();
1266+
1267+
if (qstring_to_clk_.count(clk_name) != 1) {
1268+
qstring_to_clk_[clk_name] = clk;
1269+
QStandardItem* item = new QStandardItem(clk_name);
1270+
1271+
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
1272+
item->setData(Qt::Checked, Qt::CheckStateRole);
1273+
1274+
clock_box_->model()->appendRow(item);
1275+
}
1276+
}
12531277
}
12541278

12551279
void TimingControlsDialog::setPinSelections()
@@ -1332,4 +1356,12 @@ std::vector<std::set<const sta::Pin*>> TimingControlsDialog::getThruPins() const
13321356
}
13331357
return pins;
13341358
}
1335-
} // namespace gui
1359+
1360+
void TimingControlsDialog::getClocks(sta::ClockSet* clock_set) const
1361+
{
1362+
for (const auto& clk_name : clock_box_->selectedItems()) {
1363+
clock_set->insert(qstring_to_clk_[clk_name]);
1364+
}
1365+
}
1366+
1367+
} // namespace gui

src/gui/src/staGui.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33

44
#pragma once
55

6+
#include <qchar.h>
7+
68
#include <QAbstractTableModel>
79
#include <QCheckBox>
810
#include <QColor>
911
#include <QComboBox>
1012
#include <QDialog>
1113
#include <QFormLayout>
1214
#include <QHBoxLayout>
15+
#include <QHash>
1316
#include <QListWidget>
1417
#include <QSpinBox>
1518
#include <map>
@@ -19,6 +22,7 @@
1922
#include <string>
2023
#include <vector>
2124

25+
#include "dropdownCheckboxes.h"
2226
#include "gui/gui.h"
2327
#include "odb/db.h"
2428
#include "odb/dbBlockCallBackObj.h"
@@ -30,6 +34,7 @@
3034
namespace sta {
3135
class dbSta;
3236
class Pin;
37+
class Clock;
3338
} // namespace sta
3439
namespace gui {
3540
class TimingPathsModel;
@@ -92,7 +97,8 @@ class TimingPathsModel : public QAbstractTableModel
9297
void populateModel(const std::set<const sta::Pin*>& from,
9398
const std::vector<std::set<const sta::Pin*>>& thru,
9499
const std::set<const sta::Pin*>& to,
95-
const std::string& path_group_name);
100+
const std::string& path_group_name,
101+
sta::ClockSet* clks);
96102

97103
public slots:
98104
void sort(int col_index, Qt::SortOrder sort_order) override;
@@ -101,7 +107,8 @@ class TimingPathsModel : public QAbstractTableModel
101107
bool populatePaths(const std::set<const sta::Pin*>& from,
102108
const std::vector<std::set<const sta::Pin*>>& thru,
103109
const std::set<const sta::Pin*>& to,
104-
const std::string& path_group_name);
110+
const std::string& path_group_name,
111+
sta::ClockSet* clks);
105112

106113
STAGuiInterface* sta_;
107114
bool is_setup_;
@@ -399,6 +406,7 @@ class TimingControlsDialog : public QDialog
399406
std::set<const sta::Pin*> getFromPins() const { return from_->getPins(); }
400407
std::vector<std::set<const sta::Pin*>> getThruPins() const;
401408
std::set<const sta::Pin*> getToPins() const { return to_->getPins(); }
409+
void getClocks(sta::ClockSet* clock_set) const;
402410

403411
const sta::Pin* convertTerm(Gui::Term term) const;
404412

@@ -422,6 +430,7 @@ class TimingControlsDialog : public QDialog
422430

423431
QSpinBox* path_count_spin_box_;
424432
QComboBox* corner_box_;
433+
DropdownCheckboxes* clock_box_;
425434

426435
QCheckBox* unconstrained_;
427436
QCheckBox* one_path_per_endpoint_;
@@ -430,8 +439,9 @@ class TimingControlsDialog : public QDialog
430439
PinSetWidget* from_;
431440
std::vector<PinSetWidget*> thru_;
432441
PinSetWidget* to_;
442+
QHash<QString, sta::Clock*> qstring_to_clk_;
433443

434-
static constexpr int kThruStartRow = 3;
444+
static constexpr int kThruStartRow = 4;
435445

436446
void setPinSelections();
437447

0 commit comments

Comments
 (0)