Repository navigation
web: draw overlays once per saved image, with selection and highlight groups - #11945
jorge-ferreira-pii wants to merge 8 commits into
Conversation
gui.i and gui.tcl now build without Qt too, so a script can call the gui:: commands in any build; with no window they still log GUI-0001. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
With no Qt window, the display controls act on a copy of the Qt display-control tree kept by the web viewer, with the same paths and defaults. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
save_image -web draws what the gui:: display controls chose, and a path that does not end in .png gets .png added. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
… groups Overlays and labels are drawn over the finished image at its own scale, and select and the highlight groups work with no window. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
|
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
There was a problem hiding this comment.
Code Review
This pull request introduces a headless, script-based view mechanism (ScriptView) and associated display control tree management (DisplayControlTree, RendererControls) for OpenROAD when compiled without Qt support. This allows GUI-like commands (such as save_image -web, select, and gui::set_display_controls) to function in headless mode by acting on a server-side copy of the display-control tree and selection state. Feedback on these changes highlights two performance and code quality improvement opportunities: first, in DisplayControlTree::addDesignRows, the default visibility value on should be precomputed outside of the nested loops to avoid O(N * M) complexity from repeatedly searching leaves_; second, in ScriptView::setDisplayControlColor, redundant matching can be eliminated by directly iterating over the matches returned by matchLocked instead of scanning tree_.leaves() again.
| // DisplayControls::libInit: a site starts as Rows is when it is added. | ||
| for (odb::dbLib* lib : db->getLibs()) { | ||
| for (odb::dbSite* site : lib->getSites()) { | ||
| const std::string path = std::string(kRows) + "/" + site->getName(); | ||
| if (leaves_.contains(path)) { | ||
| continue; | ||
| } | ||
| bool on = true; | ||
| if (const Leaf* rows = find(kRows)) { | ||
| on = rows->visible.value_or(false); | ||
| } else { | ||
| for (const auto& [other, leaf] : leaves_) { | ||
| if (other.starts_with(std::string(kRows) + "/")) { | ||
| on = on && leaf.visible.value_or(false); | ||
| } | ||
| } | ||
| } | ||
| leaves_.erase(kRows); | ||
| addLeaf(path, {.visible = on, .selectable = on}); | ||
| } | ||
| } |
There was a problem hiding this comment.
Computing the default visibility on inside the nested loops is inefficient. Since leaves_ can be large and there can be many sites, calling find(kRows) or scanning leaves_ in every iteration results in an on once before the loops, erase kRows if found, and then use that precomputed value for all new sites.
bool on = true;
if (const Leaf* rows = find(kRows)) {
on = rows->visible.value_or(false);
leaves_.erase(kRows);
} else {
for (const auto& [other, leaf] : leaves_) {
if (other.starts_with(std::string(kRows) + \"/\")) {
on = on && leaf.visible.value_or(false);
}
}
}
// DisplayControls::libInit: a site starts as Rows is when it is added.
for (odb::dbLib* lib : db->getLibs()) {
for (odb::dbSite* site : lib->getSites()) {
const std::string path = std::string(kRows) + \"/\" + site->getName();
if (leaves_.contains(path)) {
continue;
}
addLeaf(path, {.visible = on, .selectable = on});
}
}| bool found = !matchLocked(tree_, name, /*selectable=*/false).empty(); | ||
| bool ignored = false; | ||
| for (const auto& [path, leaf] : tree_.leaves()) { | ||
| if (!DisplayControlTree::matches(name, path)) { | ||
| continue; | ||
| } | ||
| found = true; | ||
| if (path == kBackground) { | ||
| background_ = color; | ||
| } else { | ||
| ignored = true; | ||
| } | ||
| } |
There was a problem hiding this comment.
In setDisplayControlColor, calling matchLocked and then manually iterating over tree_.leaves() to perform matching again is redundant. You can directly iterate over the matches returned by matchLocked to update the background color or mark as ignored.
const std::vector<Match> matches = matchLocked(tree_, name, /*selectable=*/false);
bool found = !matches.empty();
bool ignored = false;
for (const Match& match : matches) {
if (match.path == kBackground) {
background_ = color;
} else {
ignored = true;
}
}Rows' default for new sites is worked out once, a renderer control's color is reported as ignored, and RendererControls::check takes the default for a path it has no value for. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
…age-script-view Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
A renderer's control is shared with the browser, so save_image -display_option cannot set it for one image; say so instead of ignoring it. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
…save-image-overlays Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Part 4 of 9 for #11488. On top of PR #11944.
What is drawn on top of the layout is now drawn once over the finished image, at the image's own size, as Qt does. Labels keep the size asked for at any image width, and the overlays line up with the layout to the pixel.
select, gui::clear_selections, gui::highlight_inst, and the other selection commands now work without a window, and saved images show the selection in yellow and the highlight groups in Qt's colors. The selection is dropped when the selected objects are deleted.