From 92dad569ada8b8d69c74deb5e9d57fce097d1520 Mon Sep 17 00:00:00 2001 From: Jorge Ferreira Date: Thu, 22 Oct 2026 16:42:09 +0000 Subject: [PATCH 1/5] gui: give every build the gui:: commands 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 --- src/gui/BUILD | 13 ++- src/gui/CMakeLists.txt | 51 +++++---- src/gui/src/gui.cpp | 99 +++++++---------- src/gui/src/gui.i | 10 +- src/gui/src/makeGui.cpp | 144 ++++++++++++++++++------- src/gui/test/BUILD | 4 + src/gui/test/CMakeLists.txt | 28 ++--- src/gui/test/dump_heatmap_headless.tcl | 5 - src/gui/test/no_window.tcl | 60 +++++++++++ src/web/README.md | 3 +- src/web/include/web/core.h | 13 ++- src/web/src/guiDispatch.cpp | 57 ++++++++++ src/web/src/web.tcl | 7 +- 13 files changed, 335 insertions(+), 159 deletions(-) create mode 100644 src/gui/test/no_window.tcl diff --git a/src/gui/BUILD b/src/gui/BUILD index b66ccf8bde2..f7895dadd3b 100644 --- a/src/gui/BUILD +++ b/src/gui/BUILD @@ -17,14 +17,17 @@ package( features = ["layering_check"], ) -# The gui as a binary with no Qt has it: the Qt-free core, plus the entry -# points answering that there is no gui to open. A Qt build links :gui_qt -# instead, which carries Qt's own versions of those, so nothing reachable -# from :openroad-qt depends on this target. +# The gui as a binary with no Qt has it: the Qt-free core, the same gui:: +# Tcl commands as a Qt build, and the entry points answering that there is +# no gui to open. A Qt build links :gui_qt instead, which carries Qt's own +# versions of those, so nothing reachable from :openroad-qt depends on this +# target. cc_library( name = "gui", srcs = [ "src/makeGui.cpp", + ":gui_swig", + ":tcl", ], hdrs = [ "include/gui/MakeGui.h", @@ -35,10 +38,12 @@ cc_library( "src", ], deps = [ + "//:ord", "//src/dbSta", "//src/odb/src/db", "//src/utl", "//src/web:core", + "@boost.stacktrace", "@tcl_lang//:tcl", ], ) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 3bee73b0e9c..6e91b55252a 100755 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -14,20 +14,34 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) if (Qt5_FOUND AND BUILD_GUI) message(STATUS "GUI is enabled") + set(GUI_WITH_QT ON) + # Set before swig_lib creates the target, which picks these up. set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC_SEARCH_PATHS ui) +else() + set(GUI_WITH_QT OFF) + if(BUILD_GUI) + message(STATUS "QT5 not found. GUI is disabled") + set(BUILD_GUI OFF CACHE BOOL "Build the GUI" FORCE) + else() + message(STATUS "GUI is not enabled") + endif() +endif() - set(GUI_WRAP ${CMAKE_CURRENT_BINARY_DIR}/gui_wrap.cc) +# Both builds have the gui:: Tcl commands; without Qt, makeGui.cpp answers +# the ones that need a window. +set(GUI_WRAP ${CMAKE_CURRENT_BINARY_DIR}/gui_wrap.cc) - swig_lib(NAME gui - NAMESPACE gui - I_FILE src/gui.i - SCRIPTS src/gui.tcl - RUNTIME_HEADER tclSwig.h - ) +swig_lib(NAME gui + NAMESPACE gui + I_FILE src/gui.i + SCRIPTS src/gui.tcl + RUNTIME_HEADER tclSwig.h +) +if (GUI_WITH_QT) set_property(SOURCE ${GUI_WRAP} PROPERTY SKIP_AUTOMOC ON) target_sources(gui @@ -93,19 +107,9 @@ if (Qt5_FOUND AND BUILD_GUI) ) target_compile_options(gui PRIVATE "-fno-lto") target_link_options(gui PRIVATE "-fno-lto") - -messages( - TARGET gui -) - else() - if(BUILD_GUI) - message(STATUS "QT5 not found. GUI is disabled") - set(BUILD_GUI OFF CACHE BOOL "Build the GUI" FORCE) - else() - message(STATUS "GUI is not enabled") - endif() - add_library(gui + target_sources(gui + PRIVATE src/makeGui.cpp ) target_link_libraries(gui @@ -115,14 +119,15 @@ else() gui_core dbSta utl_lib + Boost::boost OpenSTA ) - target_include_directories(gui - PRIVATE - ${OPENROAD_HOME} - ) endif() +messages( + TARGET gui +) + target_include_directories(gui PUBLIC include diff --git a/src/gui/src/gui.cpp b/src/gui/src/gui.cpp index d3631dffeff..c5e67f3ee32 100644 --- a/src/gui/src/gui.cpp +++ b/src/gui/src/gui.cpp @@ -53,7 +53,6 @@ #include "utl/decode.h" #include "utl/exception.h" #include "web/descriptor_registry.h" -#include "web/heatMap.h" extern int cmd_argc; extern char** cmd_argv; @@ -503,6 +502,42 @@ class QtGuiBackend : public GuiBackend main_window->timingPathsThrough(terms); } + void showWorstTimingPath(bool setup) override + { + main_window->getTimingWidget()->showWorstTimingPath(setup); + } + + void clearTimingPath() override + { + main_window->getTimingWidget()->clearSelection(); + } + + void selectMarkers(odb::dbMarkerCategory* markers) override + { + main_window->getDRCViewer()->selectCategory(markers); + } + + void selectClockviewerClock(const std::string& clock_name, + std::optional depth) override + { + main_window->getClockViewer()->selectClock(clock_name, depth); + } + + void showWidget(const std::string& name, bool show) override + { + auto* widget = findWidget(name); + if (widget == nullptr) { + return; + } + + if (show) { + widget->show(); + widget->raise(); + } else { + widget->hide(); + } + } + void triggerAction(const std::string& name) override { // name is widget.action: up to the last dot picks the widget, the rest @@ -614,54 +649,6 @@ std::string Gui::requestUserInput(const std::string& title, QString::fromStdString(question)); } -void Gui::selectMarkers(odb::dbMarkerCategory* markers) -{ - if (!hasUI()) { - return; - } - main_window->getDRCViewer()->selectCategory(markers); -} - -void Gui::showWorstTimingPath(bool setup) -{ - if (!hasUI()) { - return; - } - main_window->getTimingWidget()->showWorstTimingPath(setup); -} - -void Gui::clearTimingPath() -{ - if (!hasUI()) { - return; - } - main_window->getTimingWidget()->clearSelection(); -} - -void Gui::selectClockviewerClock(const std::string& clock_name, - std::optional depth) -{ - if (!hasUI()) { - return; - } - main_window->getClockViewer()->selectClock(clock_name, depth); -} - -void Gui::showWidget(const std::string& name, bool show) -{ - auto* widget = findWidget(name); - if (widget == nullptr) { - return; - } - - if (show) { - widget->show(); - widget->raise(); - } else { - widget->hide(); - } -} - void Gui::setMainWindowTitle(const std::string& title) { main_window_title_ = title; @@ -741,20 +728,6 @@ void Gui::init(odb::dbDatabase* db, sta::dbSta* sta, utl::Logger* logger) static gui::QtDialogs dialogs; setDialogs(&dialogs); setLauncher(&qt_launcher); - - for (const auto& source : getRegisteredHeatMapSources()) { - const bool already_registered = std::ranges::any_of( - heat_maps_, [&source](HeatMapDataSource* heatmap) { - return heatmap->getShortName() == source->getShortName(); - }); - if (already_registered) { - continue; - } - auto instance = source->createInstance(); - instance->setChip(db->getChip()); - registerHeatMap(instance.get()); - owned_heat_maps_.push_back(std::move(instance)); - } } void Gui::selectHelp(const std::string& item) diff --git a/src/gui/src/gui.i b/src/gui/src/gui.i index 75cb89d55f5..93421828063 100644 --- a/src/gui/src/gui.i +++ b/src/gui/src/gui.i @@ -79,8 +79,7 @@ bool enabled() } // True only while the Qt main window is running. Tcl commands that a -// non-Qt viewer also implements dispatch on this, so makeGui.cpp defines it -// too and it is always callable. +// non-Qt viewer also implements dispatch on this. bool has_ui() { return web::Gui::hasUI(); @@ -306,6 +305,10 @@ void fit() void save_image(const char* filename, double xlo, double ylo, double xhi, double yhi, int width_px = 0, double dbu_per_pixel = 0, const std::map& display_settings = {}) { auto gui = web::Gui::get(); + if (!web::Gui::hasUI() && gui->getLauncher() == nullptr) { + auto logger = ord::OpenRoad::openRoad()->getLogger(); + logger->error(GUI, 113, "Command gui::save_image is not available as OpenROAD was not compiled with QT support."); + } gui->saveImage(filename, make_rect(xlo, ylo, xhi, yhi), width_px, dbu_per_pixel, display_settings); } @@ -789,9 +792,10 @@ void trigger_action(const std::string& name) gui->triggerAction(name); } +// Whether this build has the Qt gui: only gui.cpp installs a launcher. bool supported() { - return true; + return web::Gui::get()->getLauncher() != nullptr; } void minimize() diff --git a/src/gui/src/makeGui.cpp b/src/gui/src/makeGui.cpp index eb15217c502..d440e1774b1 100644 --- a/src/gui/src/makeGui.cpp +++ b/src/gui/src/makeGui.cpp @@ -1,21 +1,30 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2020-2025, The OpenROAD Authors -// The two entry points OpenRoad calls into gui with, for a build that has no -// Qt. A Qt build compiles gui.cpp's versions of them instead and never sees -// this file, so between them every binary has exactly one of each. +// gui's entry points for a build with no Qt. A Qt build compiles gui.cpp's +// versions instead, so every binary has exactly one of each. + +#include "gui/MakeGui.h" -#include #include #include #include "gui/gui.h" #include "odb/db.h" #include "tcl.h" -#include "web/heatMap.h" +#include "utl/Logger.h" +#include "utl/decode.h" +#include "web/core.h" namespace gui { +// Tcl files encoded into strings. +extern const char* gui_tcl_inits[]; + +extern "C" { +extern int Gui_Init(Tcl_Interp* interp); +} + // using namespace odb; int startGui(int& argc, char* argv[], @@ -37,41 +46,98 @@ void initGui(Tcl_Interp* interp, sta::dbSta* sta, utl::Logger* logger) { - // Brings up the descriptor registry and the heat map sources for the web - // viewer and other non-Qt consumers, and gives web::Gui the database and - // logger its own dispatch reports through. - web::Gui::get()->initCommon(db, sta, logger); + // The same gui:: commands as a Qt build, so a script runs on either; with + // no window they answer as a Qt build does before its window opens. + Gui_Init(interp); + utl::evalTclInit(interp, gui::gui_tcl_inits); - // Tcl requires this to be a writable string - std::string cmd_save_image( - "proc save_image { args } {" - " utl::error GUI 4 \"Command save_image is not available as OpenROAD " - "was not compiled with QT support.\"" - "}"); - Tcl_Eval(interp, cmd_save_image.c_str()); - std::string cmd_supported( - "namespace eval gui {" - " proc supported {} {" - " return 0" - " }" - "}"); - Tcl_Eval(interp, cmd_supported.c_str()); - std::string enabled_supported( - "namespace eval gui {" - " proc enabled {} {" - " return 0" - " }" - "}"); - Tcl_Eval(interp, enabled_supported.c_str()); - // Counterpart of gui.i's has_ui: commands shared with a non-Qt viewer - // dispatch on it, so it has to answer in a build with no Qt at all. - std::string cmd_has_ui( - "namespace eval gui {" - " proc has_ui {} {" - " return 0" - " }" - "}"); - Tcl_Eval(interp, cmd_has_ui.c_str()); + web::Gui::get()->initCommon(db, sta, logger); } } // namespace gui + +namespace web { + +// Gui methods only the Qt main window has; gui.i's check_gui() keeps all but +// gui::show and set_title from them. The NOLINTs: gui.cpp's signatures. + +// NOLINTNEXTLINE(modernize-use-string-view) +std::string Gui::addToolbarButton(const std::string& /* name */, + const std::string& /* text */, + const std::string& /* script */, + bool /* echo */) +{ + return {}; +} + +void Gui::removeToolbarButton(const std::string& /* name */) +{ +} + +// NOLINTNEXTLINE(modernize-use-string-view) +std::string Gui::addMenuItem(const std::string& /* name */, + const std::string& /* path */, + const std::string& /* text */, + const std::string& /* script */, + const std::string& /* shortcut */, + bool /* echo */) +{ + return {}; +} + +void Gui::removeMenuItem(const std::string& /* name */) +{ +} + +// NOLINTNEXTLINE(modernize-use-string-view) +std::string Gui::requestUserInput(const std::string& /* title */, + const std::string& /* question */) +{ + return {}; +} + +void Gui::hideGui() +{ +} + +void Gui::minimize() +{ +} + +void Gui::unminimize() +{ +} + +void Gui::selectHelp(const std::string& /* item */) +{ +} + +void Gui::selectChart(const std::string& /* name */) +{ +} + +void Gui::updateTimingReport() +{ +} + +void Gui::showGui(const std::string& /* cmds */, + bool /* interactive */, + bool /* load_settings */) +{ + logger_->error(utl::GUI, + 112, + "Command gui::show is not available as OpenROAD was not " + "compiled with QT support."); +} + +void Gui::setMainWindowTitle(const std::string& title) +{ + main_window_title_ = title; +} + +std::string Gui::getMainWindowTitle() +{ + return main_window_title_; +} + +} // namespace web diff --git a/src/gui/test/BUILD b/src/gui/test/BUILD index 9e49d0d14c3..6858addcca1 100644 --- a/src/gui/test/BUILD +++ b/src/gui/test/BUILD @@ -10,6 +10,8 @@ package(features = ["layering_check"]) ALL_TESTS = [ "supported", "clocktree_virtual_clock", + "dump_heatmap_headless", + "no_window", "save_animated_gif_headless", "save_image_headless", "select_name_patterns", @@ -18,6 +20,8 @@ ALL_TESTS = [ # From CMakeLists.txt or_integration_tests(PASSFAIL_TESTS PASSFAIL_TESTS = [ "clocktree_virtual_clock", + "dump_heatmap_headless", + "no_window", "save_animated_gif_headless", "save_image_headless", "select_name_patterns", diff --git a/src/gui/test/CMakeLists.txt b/src/gui/test/CMakeLists.txt index 49bd379c85e..f22fcd15bc6 100644 --- a/src/gui/test/CMakeLists.txt +++ b/src/gui/test/CMakeLists.txt @@ -1,26 +1,20 @@ set(GUI_TESTS supported) -set(GUI_PASSFAIL_TESTS) +set(GUI_PASSFAIL_TESTS + dump_heatmap_headless + no_window +) if (Qt5_FOUND AND BUILD_GUI) - list(APPEND GUI_PASSFAIL_TESTS dump_heatmap_headless) list(APPEND GUI_PASSFAIL_TESTS clocktree_virtual_clock) list(APPEND GUI_PASSFAIL_TESTS save_animated_gif_headless) list(APPEND GUI_PASSFAIL_TESTS save_image_headless) list(APPEND GUI_PASSFAIL_TESTS select_name_patterns) endif() -if (GUI_PASSFAIL_TESTS) - or_integration_tests( - "gui" - TESTS - ${GUI_TESTS} - PASSFAIL_TESTS - ${GUI_PASSFAIL_TESTS} - ) -else() - or_integration_tests( - "gui" - TESTS - ${GUI_TESTS} - ) -endif() +or_integration_tests( + "gui" + TESTS + ${GUI_TESTS} + PASSFAIL_TESTS + ${GUI_PASSFAIL_TESTS} +) diff --git a/src/gui/test/dump_heatmap_headless.tcl b/src/gui/test/dump_heatmap_headless.tcl index b79a83aaed9..cc7368ac4ce 100644 --- a/src/gui/test/dump_heatmap_headless.tcl +++ b/src/gui/test/dump_heatmap_headless.tcl @@ -3,11 +3,6 @@ set openroad_test_dir [file normalize [file join $script_dir .. .. .. test]] source [file join $openroad_test_dir helpers.tcl] -if { ![gui::supported] } { - puts "fail" - exit 1 -} - suppress_message ODB 128 suppress_message ODB 130 suppress_message ODB 131 diff --git a/src/gui/test/no_window.tcl b/src/gui/test/no_window.tcl new file mode 100644 index 00000000000..b1d756abcbc --- /dev/null +++ b/src/gui/test/no_window.tcl @@ -0,0 +1,60 @@ +# With no Qt window, in a build with or without Qt, the gui:: commands exist, +# and the ones that need a window log GUI-0001 rather than fail. + +set script_dir [file dirname [info script]] +set openroad_test_dir [file normalize [file join $script_dir .. .. .. test]] + +source [file join $openroad_test_dir helpers.tcl] + +proc fail { msg } { + puts "fail: $msg" + exit 0 +} + +suppress_message ODB 127 +suppress_message ODB 128 +suppress_message ODB 130 +suppress_message ODB 131 +suppress_message ODB 132 +suppress_message ODB 133 +suppress_message ODB 134 +suppress_message ODB 227 + +read_lef [file join $openroad_test_dir Nangate45 Nangate45.lef] +read_def [file join $openroad_test_dir gcd_nangate45.def] + +foreach cmd { + gui::fit gui::clear_selections gui::clear_highlights + gui::set_display_controls gui::save_display_controls + gui::restore_display_controls gui::select_marker_category + gui::show_widget gui::hide_widget gui::select_clockviewer_clock + gui::show_worst_path gui::set_heatmap select save_clocktree_image +} { + if { [info commands $cmd] == "" } { + fail "$cmd is not defined" + } +} + +if { [gui::has_ui] || [gui::enabled] } { + fail "a viewer is up before any was opened" +} + +gui::save_display_controls +gui::clear_highlights -1 +gui::clear_selections +gui::fit +gui::set_display_controls "*" visible false +gui::show_widget "Clock Tree Viewer" +gui::hide_widget "Clock Tree Viewer" +gui::restore_display_controls + +if { ![gui::supported] } { + # Without Qt, save_image renders with the web viewer. + set image [make_result_file no_window.png] + save_image -width 256 $image + if { ![file exists $image] || [file size $image] == 0 } { + fail "save_image wrote nothing" + } +} + +puts "pass" diff --git a/src/web/README.md b/src/web/README.md index 93260c3e971..dd2f0547fc4 100644 --- a/src/web/README.md +++ b/src/web/README.md @@ -65,6 +65,7 @@ openroad -web -web_port 8080 -web_bind 0.0.0.0 Save the layout to a PNG file. By default, the command uses the GUI (Qt) renderer. Pass `-web` to use the web tile renderer instead, which runs entirely server-side without a display and is suitable for headless CI. +OpenROAD built without Qt always uses the web tile renderer. ```tcl save_image @@ -80,7 +81,7 @@ save_image | Switch Name | Description | | -------------- | ---------------------------------------------- | -| `-web` | Use the web tile renderer instead of the GUI renderer. Does not require a display or a running web server. | +| `-web` | Use the web tile renderer instead of the GUI renderer. Does not require a display or a running web server. Implied when OpenROAD is built without Qt. | | `-area` | Bounding box in microns `{x0 y0 x1 y1}`. Default: the whole design -- the die area unioned with the block bounding box -- plus a 5% margin. | | `-width` | Output image width in pixels. Cannot be used with `-resolution`. | | `-resolution` | Resolution in microns per pixel. Minimum: 1 DBU per pixel. Cannot be used with `-width`. | diff --git a/src/web/include/web/core.h b/src/web/include/web/core.h index 81556f0437f..aa7fc799f98 100644 --- a/src/web/include/web/core.h +++ b/src/web/include/web/core.h @@ -1079,11 +1079,22 @@ class GuiBackend virtual void registerHeatMap(HeatMapDataSource* /* heatmap */) {} virtual void unregisterHeatMap(HeatMapDataSource* /* heatmap */) {} - // Drive the timing views. A backend with no timing widgets ignores both. + // Drive the timing views. A backend with no timing widgets ignores these. virtual void timingCone(Term /* term */, bool /* fanin */, bool /* fanout */) { } virtual void timingPathsThrough(const std::set& /* terms */) {} + virtual void showWorstTimingPath(bool /* setup */) {} + virtual void clearTimingPath() {} + + // The DRC viewer's marker category, the clock tree viewer's clock, and + // widgets by name. A backend with no such widgets ignores these. + virtual void selectMarkers(odb::dbMarkerCategory* /* markers */) {} + virtual void selectClockviewerClock(const std::string& /* clock_name */, + std::optional /* depth */) + { + } + virtual void showWidget(const std::string& /* name */, bool /* show */) {} // Activate a named control -- a menu action or a button -- by its widget // path. Scripted UI driving, so a backend with no widgets does nothing. diff --git a/src/web/src/guiDispatch.cpp b/src/web/src/guiDispatch.cpp index 819c78a6399..840146fcf27 100644 --- a/src/web/src/guiDispatch.cpp +++ b/src/web/src/guiDispatch.cpp @@ -1174,6 +1174,47 @@ void Gui::timingPathsThrough(const std::set& terms) activeBackend()->timingPathsThrough(terms); } +void Gui::showWorstTimingPath(bool setup) +{ + if (!hasUI()) { + return; + } + activeBackend()->showWorstTimingPath(setup); +} + +void Gui::clearTimingPath() +{ + if (!hasUI()) { + return; + } + activeBackend()->clearTimingPath(); +} + +void Gui::selectMarkers(odb::dbMarkerCategory* markers) +{ + if (!hasUI()) { + return; + } + activeBackend()->selectMarkers(markers); +} + +void Gui::selectClockviewerClock(const std::string& clock_name, + std::optional depth) +{ + if (!hasUI()) { + return; + } + activeBackend()->selectClockviewerClock(clock_name, depth); +} + +void Gui::showWidget(const std::string& name, bool show) +{ + if (!hasUI()) { + return; + } + activeBackend()->showWidget(name, show); +} + void Gui::triggerAction(const std::string& name) { if (!hasUI()) { @@ -1192,6 +1233,22 @@ void Gui::initCommon(odb::dbDatabase* db, sta::dbSta* sta, utl::Logger* logger) registry->initDescriptors(db, sta); registerBuiltinHeatMapSources(sta, logger); + + // One instance per source registered so far, so gui::set_heatmap and + // gui::dump_heatmap work in every build, not only with Qt. + for (const auto& source : getRegisteredHeatMapSources()) { + const bool already_registered = std::ranges::any_of( + heat_maps_, [&source](HeatMapDataSource* heatmap) { + return heatmap->getShortName() == source->getShortName(); + }); + if (already_registered) { + continue; + } + auto instance = source->createInstance(); + instance->setChip(db->getChip()); + registerHeatMap(instance.get()); + owned_heat_maps_.push_back(std::move(instance)); + } } } // namespace web diff --git a/src/web/src/web.tcl b/src/web/src/web.tcl index cc6d581a497..983eaf8fc77 100644 --- a/src/web/src/web.tcl +++ b/src/web/src/web.tcl @@ -52,7 +52,8 @@ proc save_image { args } { sta::parse_key_args "save_image" args \ keys {-area -width -resolution} flags {-web} - set use_web [info exists flags(-web)] + # Without Qt the web renderer is the only one there is. + set use_web [expr { [info exists flags(-web)] || ![gui::supported] }] set resolution 0 if { [info exists keys(-resolution)] } { @@ -195,8 +196,8 @@ proc web_load_chiplet_heatmap { args } { # is why a Qt build launched without -gui lands on the web viewer rather than # on the GUI command's "not usable in non-GUI mode". # -# gui::has_ui is the predicate: gui.i exports it in a Qt build and stub.cpp -# defines it in a build without Qt, so it always answers. +# gui::has_ui is the predicate: gui.i exports it in every build, so it always +# answers. namespace eval web { # Options the web viewer adds that the Qt path cannot honour: its toolbar From 86dfa64051edbc7a10b4a95b75ee08f328adff40 Mon Sep 17 00:00:00 2001 From: Jorge Ferreira Date: Thu, 22 Oct 2026 16:42:09 +0000 Subject: [PATCH 2/5] web: a script view for gui:: commands with no Qt window 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 --- src/gpl/src/graphicsImpl.cpp | 6 +- src/gui/src/displayControls.cpp | 12 + src/gui/src/displayControls.h | 2 + src/gui/src/gui.cpp | 5 + src/gui/src/gui.i | 35 ++- src/gui/test/BUILD | 12 + src/gui/test/CMakeLists.txt | 1 + src/gui/test/clocktree_virtual_clock.tcl | 4 +- src/gui/test/display_controls_parity.tcl | 73 +++++ src/gui/test/no_window.tcl | 18 +- src/gui/test/save_animated_gif_headless.tcl | 4 +- src/gui/test/save_image_headless.tcl | 4 +- src/web/BUILD | 6 + src/web/CMakeLists.txt | 3 + src/web/README.md | 10 + src/web/include/web/core.h | 36 +++ src/web/include/web/heatMap.h | 3 + src/web/include/web/web.h | 4 + src/web/src/display_control_tree.cpp | 290 +++++++++++++++++++ src/web/src/display_control_tree.h | 55 ++++ src/web/src/guiDispatch.cpp | 74 +++-- src/web/src/heatMapCore.cpp | 2 +- src/web/src/renderer.cpp | 4 +- src/web/src/renderer_controls.cpp | 58 ++++ src/web/src/renderer_controls.h | 53 ++++ src/web/src/script_view.cpp | 283 ++++++++++++++++++ src/web/src/script_view.h | 103 +++++++ src/web/src/tile_generator.cpp | 140 ++++++--- src/web/src/tile_generator.h | 16 + src/web/src/web.cpp | 51 +++- src/web/src/web_serve.cpp | 8 + src/web/src/web_viewer_hook.cpp | 21 +- src/web/src/web_viewer_hook.h | 46 +-- src/web/test/BUILD | 17 ++ src/web/test/cpp/CMakeLists.txt | 1 + src/web/test/cpp/TestDebugGraphics.cpp | 15 +- src/web/test/cpp/TestHeatMap.cpp | 31 ++ src/web/test/cpp/TestSaveDisplayControls.cpp | 11 +- src/web/test/cpp/TestScriptView.cpp | 258 +++++++++++++++++ src/web/test/cpp/TestTileGenerator.cpp | 12 + test/regression.bzl | 4 +- 41 files changed, 1635 insertions(+), 156 deletions(-) create mode 100644 src/gui/test/display_controls_parity.tcl create mode 100644 src/web/src/display_control_tree.cpp create mode 100644 src/web/src/display_control_tree.h create mode 100644 src/web/src/renderer_controls.cpp create mode 100644 src/web/src/renderer_controls.h create mode 100644 src/web/src/script_view.cpp create mode 100644 src/web/src/script_view.h create mode 100644 src/web/test/cpp/TestScriptView.cpp diff --git a/src/gpl/src/graphicsImpl.cpp b/src/gpl/src/graphicsImpl.cpp index 6d19a296733..fbe045d5b05 100644 --- a/src/gpl/src/graphicsImpl.cpp +++ b/src/gpl/src/graphicsImpl.cpp @@ -1079,7 +1079,7 @@ void GraphicsImpl::saveLabeledImageImpl(std::string_view path, odb::Rect bbox = pbc_->db()->getChip()->getBlock()->getBBox()->getBox(); if (!heatmap_control.empty()) { - gui->setDisplayControlsVisible(std::string(heatmap_control), true); + gui->setRendererControl(std::string(heatmap_control), true); } static int label_id = 0; @@ -1090,7 +1090,7 @@ void GraphicsImpl::saveLabeledImageImpl(std::string_view path, gui->deleteLabel(label_name); if (!heatmap_control.empty()) { - gui->setDisplayControlsVisible(std::string(heatmap_control), false); + gui->setRendererControl(std::string(heatmap_control), false); } gui->clearSelections(); @@ -1122,7 +1122,7 @@ void GraphicsImpl::gifEnd(int key) void GraphicsImpl::setDisplayControl(std::string_view name, bool value) { - web::Gui::get()->setDisplayControlsVisible(std::string(name), value); + web::Gui::get()->setRendererControl(std::string(name), value); } } // namespace gpl diff --git a/src/gui/src/displayControls.cpp b/src/gui/src/displayControls.cpp index 208d71b3537..7ec2a9c3df8 100644 --- a/src/gui/src/displayControls.cpp +++ b/src/gui/src/displayControls.cpp @@ -1221,6 +1221,18 @@ bool DisplayControls::checkControlByPath(const std::string& path, return false; } +std::vector DisplayControls::controlPaths() +{ + std::map controls; + collectControls(model_->invisibleRootItem(), kVisible, controls); + std::vector paths; + paths.reserve(controls.size()); + for (const auto& [path, item] : controls) { + paths.push_back(path); + } + return paths; +} + void DisplayControls::collectControls( const QStandardItem* parent, Column column, diff --git a/src/gui/src/displayControls.h b/src/gui/src/displayControls.h index 9429937e431..483820ed5b7 100644 --- a/src/gui/src/displayControls.h +++ b/src/gui/src/displayControls.h @@ -176,6 +176,8 @@ class DisplayControls : public QDockWidget, Qt::CheckState value); void setControlByPath(const std::string& path, const QColor& color); bool checkControlByPath(const std::string& path, bool is_visible); + // The paths of the controls with a visible box, sorted. + std::vector controlPaths(); void registerRenderer(web::Renderer* renderer); void unregisterRenderer(web::Renderer* renderer); diff --git a/src/gui/src/gui.cpp b/src/gui/src/gui.cpp index c5e67f3ee32..24ff3a6a5fc 100644 --- a/src/gui/src/gui.cpp +++ b/src/gui/src/gui.cpp @@ -365,6 +365,11 @@ class QtGuiBackend : public GuiBackend main_window->getControls()->restore(); } + std::vector displayControlPaths() override + { + return main_window->getControls()->controlPaths(); + } + void addFocusNet(odb::dbNet* net) override { main_window->getLayoutTabs()->addFocusNet(net); diff --git a/src/gui/src/gui.i b/src/gui/src/gui.i index 93421828063..3156ff2e5d2 100644 --- a/src/gui/src/gui.i +++ b/src/gui/src/gui.i @@ -3,6 +3,8 @@ %{ #include +#include +#include #include "ord/OpenRoad.hh" #include "utl/Logger.h" @@ -10,10 +12,12 @@ using utl::GUI; -bool check_gui(const char* command) +// With any_viewer, the script view serves the command when no Qt window is +// up; otherwise it needs the window. +bool check_gui(const char* command, bool any_viewer = false) { auto logger = ord::OpenRoad::openRoad()->getLogger(); - if (!web::Gui::hasUI()) { + if (!(any_viewer ? web::Gui::hasViewer() : web::Gui::hasUI())) { logger->info(GUI, 1, "Command {} is not usable in non-GUI mode", command); return false; } @@ -71,6 +75,14 @@ namespace std { %rename(pause) gui_pause; +%typemap(out) std::vector { + Tcl_Obj* list = Tcl_NewListObj(0, nullptr); + for (const std::string& item : *(&$1)) { + Tcl_ListObjAppendElement(interp, list, Tcl_NewStringObj(item.c_str(), item.size())); + } + Tcl_SetObjResult(interp, list); +} + %inline %{ bool enabled() @@ -295,7 +307,7 @@ void design_created() void fit() { - if (!check_gui("fit")) { + if (!check_gui("fit", true)) { return; } auto gui = web::Gui::get(); @@ -390,7 +402,7 @@ void clear_highlights(int highlight_group = 0) void set_display_controls(const char* name, const char* display_type, const char* value) { - if (!check_gui("set_display_controls")) { + if (!check_gui("set_display_controls", true)) { return; } auto gui = web::Gui::get(); @@ -421,7 +433,7 @@ void set_display_controls(const char* name, const char* display_type, const char bool check_display_controls(const char* name, const char* display_type) { - if (!check_gui("check_display_controls")) { + if (!check_gui("check_display_controls", true)) { return false; } auto gui = web::Gui::get(); @@ -446,7 +458,7 @@ bool check_display_controls(const char* name, const char* display_type) void save_display_controls() { - if (!check_gui("set_display_controls")) { + if (!check_gui("save_display_controls", true)) { return; } auto gui = web::Gui::get(); @@ -455,13 +467,22 @@ void save_display_controls() void restore_display_controls() { - if (!check_gui("restore_display_controls")) { + if (!check_gui("restore_display_controls", true)) { return; } auto gui = web::Gui::get(); gui->restoreDisplayControls(); } +// The paths set_display_controls can name, as a Tcl list. +std::vector display_control_paths() +{ + if (!check_gui("display_control_paths", true)) { + return {}; + } + return web::Gui::get()->displayControlPaths(); +} + const std::string create_toolbar_button(const char* name, const char* text, const char* script, bool echo) { if (!check_gui("create_toolbar_button")) { diff --git a/src/gui/test/BUILD b/src/gui/test/BUILD index 6858addcca1..3805ff8c871 100644 --- a/src/gui/test/BUILD +++ b/src/gui/test/BUILD @@ -10,6 +10,7 @@ package(features = ["layering_check"]) ALL_TESTS = [ "supported", "clocktree_virtual_clock", + "display_controls_parity", "dump_heatmap_headless", "no_window", "save_animated_gif_headless", @@ -17,9 +18,19 @@ ALL_TESTS = [ "select_name_patterns", ] +# Exercise the Qt gui, so they need it built in. +QT_TESTS = [ + "clocktree_virtual_clock", + "display_controls_parity", + "save_animated_gif_headless", + "save_image_headless", + "select_name_patterns", +] + # From CMakeLists.txt or_integration_tests(PASSFAIL_TESTS PASSFAIL_TESTS = [ "clocktree_virtual_clock", + "display_controls_parity", "dump_heatmap_headless", "no_window", "save_animated_gif_headless", @@ -51,6 +62,7 @@ filegroup( check_log = False if test_name in PASSFAIL_TESTS else True, check_passfail = True if test_name in PASSFAIL_TESTS else False, data = [":test_resources"], + openroad = "//:openroad-qt" if test_name in QT_TESTS else "//:openroad", visibility = ["//visibility:public"], ) for test_name in ALL_TESTS diff --git a/src/gui/test/CMakeLists.txt b/src/gui/test/CMakeLists.txt index f22fcd15bc6..09b34bac95d 100644 --- a/src/gui/test/CMakeLists.txt +++ b/src/gui/test/CMakeLists.txt @@ -6,6 +6,7 @@ set(GUI_PASSFAIL_TESTS if (Qt5_FOUND AND BUILD_GUI) list(APPEND GUI_PASSFAIL_TESTS clocktree_virtual_clock) + list(APPEND GUI_PASSFAIL_TESTS display_controls_parity) list(APPEND GUI_PASSFAIL_TESTS save_animated_gif_headless) list(APPEND GUI_PASSFAIL_TESTS save_image_headless) list(APPEND GUI_PASSFAIL_TESTS select_name_patterns) diff --git a/src/gui/test/clocktree_virtual_clock.tcl b/src/gui/test/clocktree_virtual_clock.tcl index dc7aafeb318..a515ac3e5bb 100644 --- a/src/gui/test/clocktree_virtual_clock.tcl +++ b/src/gui/test/clocktree_virtual_clock.tcl @@ -11,8 +11,8 @@ set openroad_test_dir [file normalize [file join $script_dir .. .. .. test]] source [file join $openroad_test_dir helpers.tcl] if { ![gui::supported] } { - # Built without the GUI; nothing to exercise. - puts "pass" + # Registered only where the Qt gui is built in. + puts "fail: OpenROAD was built without the Qt gui" } else { if { ![info exists ::env(QT_QPA_PLATFORM)] } { set ::env(QT_QPA_PLATFORM) offscreen diff --git a/src/gui/test/display_controls_parity.tcl b/src/gui/test/display_controls_parity.tcl new file mode 100644 index 00000000000..f371bbbccdf --- /dev/null +++ b/src/gui/test/display_controls_parity.tcl @@ -0,0 +1,73 @@ +# With no Qt window, gui::set_display_controls acts on the web viewer's +# script view, which keeps its own copy of the Qt display-control tree. This +# checks that copy against the real one: the same paths, and the same +# defaults. + +set script_dir [file dirname [info script]] +set openroad_test_dir [file normalize [file join $script_dir .. .. .. test]] + +source [file join $openroad_test_dir helpers.tcl] + +proc fail { msg } { + puts "fail: $msg" + exit 0 +} + +# Path -> default visibility for every control the current viewer has. +proc control_defaults { } { + set defaults [dict create] + foreach path [gui::display_control_paths] { + dict set defaults $path [gui::check_display_controls $path visible] + } + return $defaults +} + +if { ![gui::supported] } { + # Registered only where the Qt gui is built in, so no tree to compare with + # is a failure. + fail "OpenROAD was built without the Qt gui" +} else { + if { ![info exists ::env(QT_QPA_PLATFORM)] } { + set ::env(QT_QPA_PLATFORM) offscreen + } + + suppress_message ODB 127 + suppress_message ODB 128 + suppress_message ODB 130 + suppress_message ODB 131 + suppress_message ODB 132 + suppress_message ODB 133 + suppress_message ODB 134 + suppress_message ODB 227 + + read_lef [file join $openroad_test_dir Nangate45 Nangate45.lef] + read_def [file join $openroad_test_dir gcd_nangate45.def] + + set web [control_defaults] + # Without the saved settings, so the window starts from its defaults. + set ::qt {} + gui::show { + set ::qt [control_defaults] + gui::hide + } false false + + if { [dict size $::qt] == 0 } { + fail "the Qt gui reported no controls" + } + foreach path [dict keys $::qt] { + if { ![dict exists $web $path] } { + fail "missing without a window: $path" + } + if { [dict get $web $path] != [dict get $::qt $path] } { + fail "$path defaults to [dict get $web $path] without a window, \ + [dict get $::qt $path] in Qt" + } + } + foreach path [dict keys $web] { + if { ![dict exists $::qt $path] } { + fail "not in the Qt gui: $path" + } + } + + puts "pass" +} diff --git a/src/gui/test/no_window.tcl b/src/gui/test/no_window.tcl index b1d756abcbc..45945b390ee 100644 --- a/src/gui/test/no_window.tcl +++ b/src/gui/test/no_window.tcl @@ -1,5 +1,6 @@ -# With no Qt window, in a build with or without Qt, the gui:: commands exist, -# and the ones that need a window log GUI-0001 rather than fail. +# With no Qt window, in a build with or without Qt, the gui:: commands exist +# and answer: the display controls act on the web viewer's script view, and +# the commands that need a window log GUI-0001 rather than fail. set script_dir [file dirname [info script]] set openroad_test_dir [file normalize [file join $script_dir .. .. .. test]] @@ -44,9 +45,22 @@ gui::clear_highlights -1 gui::clear_selections gui::fit gui::set_display_controls "*" visible false +if { [gui::check_display_controls "Nets/Power" visible] } { + fail "Nets/Power is still visible after hiding everything" +} +gui::set_display_controls "Nets/*" visible true +if { ![gui::check_display_controls "Nets/Power" visible] } { + fail "Nets/* did not reach Nets/Power" +} gui::show_widget "Clock Tree Viewer" gui::hide_widget "Clock Tree Viewer" gui::restore_display_controls +if { ![gui::check_display_controls "Layers/metal1" visible] } { + fail "restore did not bring Layers/metal1 back" +} +if { [catch { gui::set_display_controls "Bogus/*" visible true }] == 0 } { + fail "an unknown control was accepted" +} if { ![gui::supported] } { # Without Qt, save_image renders with the web viewer. diff --git a/src/gui/test/save_animated_gif_headless.tcl b/src/gui/test/save_animated_gif_headless.tcl index dd7a7187892..08c0cc19f55 100644 --- a/src/gui/test/save_animated_gif_headless.tcl +++ b/src/gui/test/save_animated_gif_headless.tcl @@ -33,8 +33,8 @@ proc gif_header { path } { } if { ![gui::supported] } { - # Built without the GUI; nothing to exercise. - puts "pass" + # Registered only where the Qt gui is built in. + puts "fail: OpenROAD was built without the Qt gui" } else { if { ![info exists ::env(QT_QPA_PLATFORM)] } { set ::env(QT_QPA_PLATFORM) offscreen diff --git a/src/gui/test/save_image_headless.tcl b/src/gui/test/save_image_headless.tcl index 6fbcafea8ae..5e41fca3fc2 100644 --- a/src/gui/test/save_image_headless.tcl +++ b/src/gui/test/save_image_headless.tcl @@ -45,8 +45,8 @@ proc png_size { path } { } if { ![gui::supported] } { - # Built without the GUI; nothing to exercise. - puts "pass" + # Registered only where the Qt gui is built in. + puts "fail: OpenROAD was built without the Qt gui" } else { if { ![info exists ::env(QT_QPA_PLATFORM)] } { set ::env(QT_QPA_PLATFORM) offscreen diff --git a/src/web/BUILD b/src/web/BUILD index bcaa5a2cd12..f9efaa21bcf 100644 --- a/src/web/BUILD +++ b/src/web/BUILD @@ -203,15 +203,18 @@ cc_library( srcs = [ "src/asset_gzip.cpp", "src/clock_tree_report.cpp", + "src/display_control_tree.cpp", "src/font_atlas.h", "src/font_data.cpp", "src/font_data.h", "src/glyph_cache.cpp", "src/hierarchy_report.cpp", "src/module_color_palette.h", + "src/renderer_controls.cpp", "src/report_html.cpp", "src/request_dispatcher.h", "src/request_handler.cpp", + "src/script_view.cpp", "src/search.cpp", "src/search.h", "src/tile_generator.cpp", @@ -233,7 +236,10 @@ cc_library( # If these are meant to be used in tests with specific dependencies, # these should be put (together with their *.cpp files) into separate # libraries, with visibility for the //src/web/test path (see :color). + "src/display_control_tree.h", "src/glyph_cache.h", + "src/renderer_controls.h", + "src/script_view.h", "src/tile_generator.h", "src/timing_report.h", "src/web_chart.h", diff --git a/src/web/CMakeLists.txt b/src/web/CMakeLists.txt index fa3f2b35b23..10c52d759e9 100644 --- a/src/web/CMakeLists.txt +++ b/src/web/CMakeLists.txt @@ -97,9 +97,12 @@ target_sources(web PRIVATE src/clock_tree_report.cpp src/color.cpp + src/display_control_tree.cpp src/hierarchy_report.cpp + src/renderer_controls.cpp src/report_html.cpp src/request_handler.cpp + src/script_view.cpp src/search.cpp src/font_data.cpp src/glyph_cache.cpp diff --git a/src/web/README.md b/src/web/README.md index dd2f0547fc4..6bdc97fb3f4 100644 --- a/src/web/README.md +++ b/src/web/README.md @@ -101,6 +101,8 @@ field and the value is `true` or `false`. | Key | Default | Description | | --- | ------- | ----------- | | `stdcells` | true | Standard cells | +| `std_physical` | `stdcells` | Liberty cells with no ports, such as decaps | +| `std_other` | `stdcells` | Cells with no Liberty cell that are not core masters | | `macros` | true | Macros | | `routing` | true | Signal routing | | `special_nets` | true | Power/ground straps | @@ -326,6 +328,14 @@ whichever one synced last. Because Tcl commands typed into the browser console run on the server, this is normally invoked from the viewer's own console after arranging the panel. +This command is not `gui::save_display_controls`. With no Qt window open, +`gui::set_display_controls`, `gui::check_display_controls`, +`gui::save_display_controls`, `gui::restore_display_controls` and `gui::fit` +act on a copy of the Qt display-control tree kept on the server, with the +same paths and defaults. That copy works in a build without Qt and needs no +running server, but it is separate from what a browser shows. Of the colors, +only `Misc/Background` is kept there. + ### Restore Display Controls Apply a previously saved display-controls file to every connected viewer. diff --git a/src/web/include/web/core.h b/src/web/include/web/core.h index aa7fc799f98..fa68b373130 100644 --- a/src/web/include/web/core.h +++ b/src/web/include/web/core.h @@ -1135,6 +1135,18 @@ class GuiBackend bool /* value */) { } + // Every control with a visible box, by the path the calls above take. + virtual std::vector displayControlPaths() { return {}; } + // A renderer's own control, asked from the render threads. The script view + // and the web viewer draw a path they do not know rather than err. + virtual bool checkRendererControl(const std::string& path) + { + return checkDisplayControlVisible(path); + } + virtual void setRendererControl(const std::string& path, bool value) + { + setDisplayControlVisible(path, value); + } }; // This is the API for the rest of the program to interact with the @@ -1273,10 +1285,15 @@ class Gui // panel. bool checkDisplayControlsVisible(const std::string& name); bool checkDisplayControlsSelectable(const std::string& name); + // A renderer's control, from the Qt window or else the script view, whose + // store the web viewer shares. + bool checkRendererControl(const std::string& path); + void setRendererControl(const std::string& path, bool value); // Used to save and restore the display controls, useful for batch operations void saveDisplayControls(); void restoreDisplayControls(); + std::vector displayControlPaths(); // Used to add and remove focus nets from layout void addFocusNet(odb::dbNet* net); @@ -1423,6 +1440,8 @@ class Gui void registerHeatMap(HeatMapDataSource* heatmap); void unregisterHeatMap(HeatMapDataSource* heatmap); + // Whether `renderer` is the one registerHeatMap made for a heat map. + bool isHeatMapRenderer(const Renderer* renderer) const; const std::set& getHeatMaps(); HeatMapDataSource* getHeatMap(const std::string& name); @@ -1444,6 +1463,10 @@ class Gui // should gate on this rather than enabled(). static bool hasUI(); + // True when there is a Qt window or a script view for the view commands + // (display controls, fit) to act on. + static bool hasViewer(); + // Install / inspect the Qt gui's backend. MainWindow sets it when it // opens and clears it when it closes. void setBackend(GuiBackend* backend) { backend_ = backend; } @@ -1454,6 +1477,11 @@ class Gui void setHeadlessViewer(GuiBackend* viewer); GuiBackend* getHeadlessViewer() const { return headless_viewer_; } + // Install / inspect what the view commands act on while no Qt window is up + // (the web viewer's ScriptView). Never a backend, so enabled() ignores it. + void setScriptView(GuiBackend* view) { script_view_ = view; } + GuiBackend* getScriptView() const { return script_view_; } + // Factory for web::Chart instances when the Qt GUI is not running. // The web viewer installs a factory that returns WebChart*. When the // Qt GUI is running, the main window's ChartsWidget is used instead @@ -1510,6 +1538,13 @@ class Gui return backend_ != nullptr ? backend_ : headless_viewer_; } + // Where the view commands go: the Qt window when one is open, otherwise the + // script view. + GuiBackend* viewTarget() const + { + return hasUI() ? activeBackend() : script_view_; + } + bool filterSelectionProperties(const Descriptor::Properties& properties, const std::string& attribute, const std::any& value, @@ -1543,6 +1578,7 @@ class Gui GuiBackend* backend_ = nullptr; // Used when the Qt gui is not active. Installed by the web viewer. GuiBackend* headless_viewer_ = nullptr; + GuiBackend* script_view_ = nullptr; ChartFactory chart_factory_; Dialogs* dialogs_ = nullptr; GuiLauncher* launcher_ = nullptr; diff --git a/src/web/include/web/heatMap.h b/src/web/include/web/heatMap.h index ba8d74dc8bd..1aafa1e0544 100644 --- a/src/web/include/web/heatMap.h +++ b/src/web/include/web/heatMap.h @@ -38,6 +38,9 @@ class Logger; } // namespace utl namespace web { + +// The display-control group of every heat map's renderer. +inline constexpr const char* kHeatMapGroup = "Heat Maps"; class HeatMapSourceRegistration; class HeatMapDataSource diff --git a/src/web/include/web/web.h b/src/web/include/web/web.h index 75d7f97d135..e80fc96e827 100644 --- a/src/web/include/web/web.h +++ b/src/web/include/web/web.h @@ -40,6 +40,7 @@ struct Color; class Search; class ClockTreeReport; +class ScriptView; class TileGenerator; struct TclEvaluator; class TimingReport; @@ -292,6 +293,9 @@ class WebServer std::shared_ptr generator_; std::unique_ptr viewer_hook_; + // What the gui:: commands act on with no Qt window; there whether or not + // the server runs. + std::unique_ptr script_view_; // Open animated-GIF streams, indexed by the key returned from gifStart. // Kept as a vector (like gui's gifs_) so multiple GIFs can record at once; diff --git a/src/web/src/display_control_tree.cpp b/src/web/src/display_control_tree.cpp new file mode 100644 index 00000000000..ad65508a000 --- /dev/null +++ b/src/web/src/display_control_tree.cpp @@ -0,0 +1,290 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#include "display_control_tree.h" + +#include + +#include +#include + +#include "odb/db.h" +#include "odb/dbTypes.h" +#include "tile_generator.h" + +namespace web { + +namespace { + +constexpr const char* kLayers = "Layers/"; +constexpr const char* kImplantLayers = "Layers/Implant"; +constexpr const char* kOtherLayers = "Layers/Other"; +constexpr const char* kRows = "Rows"; + +using Flag = bool TileVisibility::*; + +// A leaf of DisplayControls' constructor, in its order, and the tile fields it +// drives. A `selectable` row's box starts as `visible`, as in makeLeafItem. +struct LeafSpec +{ + const char* path; + bool visible; + bool selectable; + Flag vis_field; + Flag sel_field; +}; + +using TV = TileVisibility; + +// clang-format off +// NOLINTBEGIN(modernize-use-designated-initializers,readability-trailing-comma) +const LeafSpec kLeafSpecs[] = { + {"Layers/Implant", true, true, nullptr, nullptr}, + {"Layers/Other", false, true, nullptr, nullptr}, + + {"Nets/Signal", true, true, &TV::net_signal, &TV::net_signal_selectable}, + {"Nets/Power", true, true, &TV::net_power, &TV::net_power_selectable}, + {"Nets/Ground", true, true, &TV::net_ground, &TV::net_ground_selectable}, + {"Nets/Clock", true, true, &TV::net_clock, &TV::net_clock_selectable}, + {"Nets/Reset", true, true, &TV::net_reset, &TV::net_reset_selectable}, + {"Nets/Tie off", true, true, &TV::net_tieoff, &TV::net_tieoff_selectable}, + {"Nets/Scan", true, true, &TV::net_scan, &TV::net_scan_selectable}, + {"Nets/Analog", true, true, &TV::net_analog, &TV::net_analog_selectable}, + + {"Instances/StdCells/Buffers/Inverters/Timing opt.", true, true, + &TV::std_bufinv_timing, &TV::std_bufinv_timing_selectable}, + {"Instances/StdCells/Buffers/Inverters/Netlist", true, true, + &TV::std_bufinv, &TV::std_bufinv_selectable}, + {"Instances/StdCells/Combinational", true, true, + &TV::std_combinational, &TV::std_combinational_selectable}, + {"Instances/StdCells/Sequential", true, true, + &TV::std_sequential, &TV::std_sequential_selectable}, + {"Instances/StdCells/Clock tree/Buffer/Inverter", true, true, + &TV::std_clock_bufinv, &TV::std_clock_bufinv_selectable}, + {"Instances/StdCells/Clock tree/Clock gate", true, true, + &TV::std_clock_gate, &TV::std_clock_gate_selectable}, + {"Instances/StdCells/Level shifter", true, true, + &TV::std_level_shift, &TV::std_level_shift_selectable}, + {"Instances/Macro", true, true, &TV::macros, &TV::macros_selectable}, + {"Instances/Pads/Input", true, true, &TV::pad_input, &TV::pad_input_selectable}, + {"Instances/Pads/Output", true, true, &TV::pad_output, &TV::pad_output_selectable}, + {"Instances/Pads/Inout", true, true, &TV::pad_inout, &TV::pad_inout_selectable}, + {"Instances/Pads/Power", true, true, &TV::pad_power, &TV::pad_power_selectable}, + {"Instances/Pads/Spacer", true, true, &TV::pad_spacer, &TV::pad_spacer_selectable}, + {"Instances/Pads/Area IO", true, true, &TV::pad_areaio, &TV::pad_areaio_selectable}, + {"Instances/Pads/Other", true, true, &TV::pad_other, &TV::pad_other_selectable}, + {"Instances/Physical/Fill cell", true, true, &TV::phys_fill, &TV::phys_fill_selectable}, + {"Instances/Physical/Endcap", true, true, &TV::phys_endcap, &TV::phys_endcap_selectable}, + {"Instances/Physical/Welltap", true, true, &TV::phys_welltap, &TV::phys_welltap_selectable}, + {"Instances/Physical/Tie high/low", true, true, &TV::phys_tie, &TV::phys_tie_selectable}, + {"Instances/Physical/Antenna", true, true, &TV::phys_antenna, &TV::phys_antenna_selectable}, + {"Instances/Physical/Cover", true, true, &TV::phys_cover, &TV::phys_cover_selectable}, + {"Instances/Physical/Bump", true, true, &TV::phys_bump, &TV::phys_bump_selectable}, + {"Instances/Physical/Other", true, true, &TV::phys_other, &TV::phys_other_selectable}, + + {"Blockages/Placement", true, true, + &TV::placement_blockages, &TV::placement_blockages_selectable}, + {"Blockages/Routing", true, true, + &TV::routing_obstructions, &TV::routing_obstructions_selectable}, + + {"Rulers", true, true, nullptr, nullptr}, + {kRows, false, true, nullptr, nullptr}, + + {"Tracks/Pref", false, false, &TV::tracks_pref, nullptr}, + {"Tracks/Non Pref", false, false, &TV::tracks_non_pref, nullptr}, + + {"Shape Types/Routing/Segments", true, false, &TV::routing_segments, nullptr}, + {"Shape Types/Routing/Vias", true, false, &TV::routing_vias, nullptr}, + {"Shape Types/Special Routing/Segments", true, false, &TV::srouting_segments, nullptr}, + {"Shape Types/Special Routing/Vias", true, false, &TV::srouting_vias, nullptr}, + {"Shape Types/Pins", true, true, &TV::pins, &TV::pins_selectable}, + {"Shape Types/Pin Names", true, false, &TV::pin_names, nullptr}, + {"Shape Types/Fills", false, false, &TV::fills, nullptr}, + + {"Misc/Instances/Names", true, false, &TV::inst_names, nullptr}, + {"Misc/Instances/Pins", true, true, &TV::inst_pins, &TV::inst_pins_selectable}, + {"Misc/Instances/Pin Names", false, false, &TV::inst_pin_names, nullptr}, + {"Misc/Instances/Blockages", true, false, &TV::blockages, nullptr}, + {"Misc/Scale bar", true, false, nullptr, nullptr}, + {"Misc/Access points", false, false, &TV::access_points, nullptr}, + {"Misc/Regions", true, true, &TV::regions, nullptr}, + {"Misc/Detailed view", false, false, &TV::detailed, nullptr}, + {"Misc/Highlight selected", true, false, nullptr, nullptr}, + {"Misc/Module view", false, false, nullptr, nullptr}, + {"Misc/Manufacturing grid", false, false, &TV::mfg_grid, nullptr}, + {"Misc/GCell grid", false, false, &TV::gcell_grid, nullptr}, + {"Misc/Flywires only", false, false, nullptr, nullptr}, + {"Misc/Focused nets guides", false, false, nullptr, nullptr}, + {"Misc/Labels", true, true, &TV::labels, nullptr}, +}; +// NOLINTEND(modernize-use-designated-initializers,readability-trailing-comma) +// clang-format on + +} // namespace + +DisplayControlTree::DisplayControlTree() +{ + for (const LeafSpec& spec : kLeafSpecs) { + Leaf leaf{.visible = spec.visible, .selectable = std::nullopt}; + if (spec.selectable) { + leaf.selectable = spec.visible; + } + leaves_[spec.path] = leaf; + } + // No checkbox: the panel only sets its colour. + leaves_["Misc/Background"] = Leaf{}; +} + +void DisplayControlTree::addLeaf(const std::string& path, const Leaf& leaf) +{ + leaves_.insert({path, leaf}); +} + +DisplayControlTree::Leaf* DisplayControlTree::find(const std::string& path) +{ + const auto it = leaves_.find(path); + return it == leaves_.end() ? nullptr : &it->second; +} + +void DisplayControlTree::addDesignRows(odb::dbDatabase* db) +{ + if (db == nullptr) { + return; + } + + // DisplayControls::addTech: routing and cut layers directly under Layers, + // implant under Implant, and the rest under Other, which starts off. + for (odb::dbTech* tech : db->getTechs()) { + for (odb::dbTechLayer* layer : tech->getLayers()) { + std::string parent; + bool on = true; + switch (layer->getType()) { + case odb::dbTechLayerType::ROUTING: + case odb::dbTechLayerType::CUT: + parent = kLayers; + break; + case odb::dbTechLayerType::IMPLANT: + parent = std::string(kImplantLayers) + "/"; + leaves_.erase(kImplantLayers); + break; + default: + parent = std::string(kOtherLayers) + "/"; + leaves_.erase(kOtherLayers); + on = false; + break; + } + addLeaf(parent + layer->getName(), {.visible = on, .selectable = on}); + } + } + + // 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}); + } + } +} + +bool DisplayControlTree::matches(const std::string& pattern, + const std::string& path) +{ + // No FNM_PATHNAME, so '*' crosses '/' as in Qt. + return fnmatch(pattern.c_str(), path.c_str(), FNM_CASEFOLD) == 0; +} + +bool DisplayControlTree::visible(const std::string& path) const +{ + const auto it = leaves_.find(path); + return it != leaves_.end() && it->second.visible.value_or(false); +} + +bool DisplayControlTree::selectable(const std::string& path) const +{ + const auto it = leaves_.find(path); + return it != leaves_.end() && it->second.selectable.value_or(false); +} + +void DisplayControlTree::apply(TileVisibility& vis) const +{ + for (const LeafSpec& spec : kLeafSpecs) { + if (spec.vis_field != nullptr) { + vis.*spec.vis_field = visible(spec.path); + } + if (spec.sel_field != nullptr) { + vis.*spec.sel_field = selectable(spec.path); + } + } + + // Qt draws by a parent row's state, which is on while any leaf under it is. + // dbSta's STD_PHYSICAL and STD_OTHER go by Instances/Physical and Instances. + vis.stdcells = false; + vis.stdcells_selectable = false; + vis.std_physical = false; + vis.std_physical_selectable = false; + vis.std_other = false; + vis.std_other_selectable = false; + for (const auto& [path, leaf] : leaves_) { + if (!path.starts_with("Instances/")) { + continue; + } + const bool on = leaf.visible.value_or(false); + const bool selectable_on = leaf.selectable.value_or(false); + if (path.starts_with("Instances/StdCells/")) { + vis.stdcells = vis.stdcells || on; + vis.stdcells_selectable = vis.stdcells_selectable || selectable_on; + } + if (path.starts_with("Instances/Physical/")) { + vis.std_physical = vis.std_physical || on; + vis.std_physical_selectable + = vis.std_physical_selectable || selectable_on; + } + vis.std_other = vis.std_other || on; + vis.std_other_selectable = vis.std_other_selectable || selectable_on; + } + vis.routing = vis.routing_segments || vis.routing_vias; + vis.special_nets = vis.srouting_segments || vis.srouting_vias; + vis.pin_markers = vis.pins; + + vis.rows = visible(kRows); + vis.sites.clear(); + vis.site_selectable.clear(); + vis.visible_layers.clear(); + vis.selectable_layers.clear(); + const std::string rows_prefix = std::string(kRows) + "/"; + for (const auto& [path, leaf] : leaves_) { + if (path.starts_with(rows_prefix)) { + const std::string site = path.substr(rows_prefix.size()); + vis.sites[site] = leaf.visible.value_or(false); + vis.site_selectable[site] = leaf.selectable.value_or(false); + vis.rows = vis.rows || leaf.visible.value_or(false); + } else if (path.starts_with(kLayers) && path != kImplantLayers + && path != kOtherLayers) { + const std::string layer = path.substr(path.rfind('/') + 1); + if (leaf.visible.value_or(false)) { + vis.visible_layers.insert(layer); + } + if (leaf.selectable.value_or(false)) { + vis.selectable_layers.insert(layer); + } + } + } + vis.has_visible_layers = true; + vis.has_selectable_layers = true; +} + +} // namespace web diff --git a/src/web/src/display_control_tree.h b/src/web/src/display_control_tree.h new file mode 100644 index 00000000000..fe8a37cc81f --- /dev/null +++ b/src/web/src/display_control_tree.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#pragma once + +#include +#include +#include + +namespace odb { +class dbDatabase; +} + +namespace web { + +struct TileVisibility; + +// The Qt display-control panel's leaves, by gui::set_display_controls paths +// and with Qt's defaults. As in Qt, a parent is a leaf while it has no rows. +class DisplayControlTree +{ + public: + struct Leaf + { + std::optional visible; // unset for a row with no checkbox + std::optional selectable; // unset for a row Qt cannot select by + }; + using Leaves = std::map; + + DisplayControlTree(); + + // Adds the leaves the design defines, one per tech layer and one per lib + // site, keeping the state of those already there, as Qt does. + void addDesignRows(odb::dbDatabase* db); + // Adds `path` unless it is already a leaf. + void addLeaf(const std::string& path, const Leaf& leaf); + + const Leaves& leaves() const { return leaves_; } + Leaf* find(const std::string& path); + + // Whether `path` matches `pattern` as Qt matches them: wildcards, case + // insensitive, with '*' crossing '/'. + static bool matches(const std::string& pattern, const std::string& path); + + // Sets the fields the tile renderer draws by from the leaves. + void apply(TileVisibility& vis) const; + + private: + bool visible(const std::string& path) const; + bool selectable(const std::string& path) const; + + Leaves leaves_; +}; + +} // namespace web diff --git a/src/web/src/guiDispatch.cpp b/src/web/src/guiDispatch.cpp index 840146fcf27..3ebd23622d2 100644 --- a/src/web/src/guiDispatch.cpp +++ b/src/web/src/guiDispatch.cpp @@ -69,6 +69,11 @@ bool Gui::hasUI() return backend != nullptr && backend->hasWindow(); } +bool Gui::hasViewer() +{ + return Gui::get()->viewTarget() != nullptr; +} + void Gui::setHeadlessViewer(GuiBackend* viewer) { headless_viewer_ = viewer; @@ -479,10 +484,9 @@ void Gui::setResolution(double pixels_per_dbu) void Gui::fit() { - if (!hasUI()) { - return; + if (auto* target = viewTarget()) { + target->fit(); } - activeBackend()->fit(); } std::string Gui::addLabel(int x, @@ -545,36 +549,49 @@ void Gui::clearRulers() activeBackend()->clearRulers(); } -// The display-control queries are the one group that always had a headless -// path: they answered from the web viewer when no window was up. Dispatching -// through the backend is that same fallback, without the special case -- the -// defaults here are the ones Gui used with nothing installed at all. +// With no Qt window the controls are the script view's, with Qt's names and +// defaults; the defaults here are Gui's with nothing installed. void Gui::setDisplayControlsVisible(const std::string& name, bool value) { - if (auto* backend = activeBackend()) { - backend->setDisplayControlVisible(name, value); + if (auto* target = viewTarget()) { + target->setDisplayControlVisible(name, value); } } bool Gui::checkDisplayControlsVisible(const std::string& name) { - if (auto* backend = activeBackend()) { - return backend->checkDisplayControlVisible(name); + if (auto* target = viewTarget()) { + return target->checkDisplayControlVisible(name); } return true; } +bool Gui::checkRendererControl(const std::string& path) +{ + if (auto* target = viewTarget()) { + return target->checkRendererControl(path); + } + return true; +} + +void Gui::setRendererControl(const std::string& path, const bool value) +{ + if (auto* target = viewTarget()) { + target->setRendererControl(path, value); + } +} + void Gui::setDisplayControlsSelectable(const std::string& name, bool value) { - if (auto* backend = activeBackend()) { - backend->setDisplayControlSelectable(name, value); + if (auto* target = viewTarget()) { + target->setDisplayControlSelectable(name, value); } } bool Gui::checkDisplayControlsSelectable(const std::string& name) { - if (auto* backend = activeBackend()) { - return backend->checkDisplayControlSelectable(name); + if (auto* target = viewTarget()) { + return target->checkDisplayControlSelectable(name); } return false; } @@ -582,25 +599,33 @@ bool Gui::checkDisplayControlsSelectable(const std::string& name) void Gui::setDisplayControlsColor(const std::string& name, const Painter::Color& color) { - if (auto* backend = activeBackend()) { - backend->setDisplayControlColor(name, color); + if (auto* target = viewTarget()) { + target->setDisplayControlColor(name, color); } } void Gui::saveDisplayControls() { - if (auto* backend = activeBackend()) { - backend->saveDisplayControls(); + if (auto* target = viewTarget()) { + target->saveDisplayControls(); } } void Gui::restoreDisplayControls() { - if (auto* backend = activeBackend()) { - backend->restoreDisplayControls(); + if (auto* target = viewTarget()) { + target->restoreDisplayControls(); } } +std::vector Gui::displayControlPaths() +{ + if (auto* target = viewTarget()) { + return target->displayControlPaths(); + } + return {}; +} + void Gui::addFocusNet(odb::dbNet* net) { if (!hasUI()) { @@ -1139,6 +1164,13 @@ void Gui::unregisterHeatMap(HeatMapDataSource* heatmap) heat_maps_.erase(heatmap); } +bool Gui::isHeatMapRenderer(const Renderer* renderer) const +{ + return std::ranges::any_of( + heat_map_renderers_, + [renderer](const auto& entry) { return entry.second.get() == renderer; }); +} + void Gui::setChartFactory(ChartFactory factory) { chart_factory_ = std::move(factory); diff --git a/src/web/src/heatMapCore.cpp b/src/web/src/heatMapCore.cpp index 8a022270419..998df253ea2 100644 --- a/src/web/src/heatMapCore.cpp +++ b/src/web/src/heatMapCore.cpp @@ -1438,7 +1438,7 @@ class HeatMapRenderer : public Renderer {""}); } - const char* getDisplayControlGroupName() override { return "Heat Maps"; } + const char* getDisplayControlGroupName() override { return kHeatMapGroup; } void drawObjects(Painter& painter) override { diff --git a/src/web/src/renderer.cpp b/src/web/src/renderer.cpp index 3e629502f2d..770e98289c7 100644 --- a/src/web/src/renderer.cpp +++ b/src/web/src/renderer.cpp @@ -32,12 +32,12 @@ void Renderer::redraw() bool Renderer::checkDisplayControl(const std::string& name) { - return Gui::get()->checkDisplayControlsVisible(displayControlPath(name)); + return Gui::get()->checkRendererControl(displayControlPath(name)); } void Renderer::setDisplayControl(const std::string& name, bool value) { - Gui::get()->setDisplayControlsVisible(displayControlPath(name), value); + Gui::get()->setRendererControl(displayControlPath(name), value); } void Renderer::addDisplayControl( diff --git a/src/web/src/renderer_controls.cpp b/src/web/src/renderer_controls.cpp new file mode 100644 index 00000000000..ec7644de240 --- /dev/null +++ b/src/web/src/renderer_controls.cpp @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#include "renderer_controls.h" + +#include +#include + +namespace web { + +bool RendererControls::check(const std::string& path) const +{ + const std::scoped_lock lock(mutex_); + const auto it = visible_.find(path); + return it == visible_.end() ? true : it->second; +} + +bool RendererControls::contains(const std::string& path) const +{ + const std::scoped_lock lock(mutex_); + return visible_.contains(path); +} + +void RendererControls::set(const std::string& path, const bool value) +{ + const std::scoped_lock lock(mutex_); + visible_[path] = value; +} + +void RendererControls::seed(const std::string& path, const bool value) +{ + const std::scoped_lock lock(mutex_); + visible_.insert({path, value}); +} + +bool RendererControls::markSeeded(const void* renderer) +{ + const std::scoped_lock lock(mutex_); + return seeded_.insert(renderer).second; +} + +RendererControls::Values RendererControls::values() const +{ + const std::scoped_lock lock(mutex_); + return visible_; +} + +void RendererControls::restore(const Values& values) +{ + const std::scoped_lock lock(mutex_); + for (const auto& [path, value] : values) { + if (auto it = visible_.find(path); it != visible_.end()) { + it->second = value; + } + } +} + +} // namespace web diff --git a/src/web/src/renderer_controls.h b/src/web/src/renderer_controls.h new file mode 100644 index 00000000000..85a008fab34 --- /dev/null +++ b/src/web/src/renderer_controls.h @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#pragma once + +#include +#include +#include +#include + +namespace web { + +// Each Renderer display control's visibility, by its "Group/Name" path. +// Read from the render threads, so every access is locked. +class RendererControls +{ + public: + using Values = std::map; + + // A path nobody set or seeded reads as visible. + bool check(const std::string& path) const; + bool contains(const std::string& path) const; + void set(const std::string& path, bool value); + // Sets `path` unless it already has a value, so a renderer registering + // again keeps what the user chose. + void seed(const std::string& path, bool value); + // True the first time `renderer` is offered for seeding. + bool markSeeded(const void* renderer); + + Values values() const; + // Puts back the paths in `values` that still have a value here. + void restore(const Values& values); + + private: + mutable std::mutex mutex_; + Values visible_; + std::set seeded_; +}; + +// Installs each registered renderer's own control defaults, once per +// renderer. Defined in web.cpp, which may reach web::Gui. +void seedRendererControls(RendererControls& controls); + +// Turning on the control at `path` turns off the siblings it is mutually +// exclusive with, as DisplayControls::itemChanged does. Defined in web.cpp. +void applyRendererControlExclusivity(RendererControls& controls, + const std::string& path); +// Sets the control at `path`, with the exclusivity above when turned on. +void setRendererControl(RendererControls& controls, + const std::string& path, + bool value); + +} // namespace web diff --git a/src/web/src/script_view.cpp b/src/web/src/script_view.cpp new file mode 100644 index 00000000000..9c43a558cc8 --- /dev/null +++ b/src/web/src/script_view.cpp @@ -0,0 +1,283 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#include "script_view.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "display_control_tree.h" +#include "odb/db.h" +#include "renderer_controls.h" +#include "tile_generator.h" +#include "utl/Logger.h" +#include "web/core.h" + +namespace web { + +namespace { + +// TimingPathRenderer's controls (staGui.cpp), which the Qt gui lists whether +// or not its timing widget is open. +constexpr const char* kTimingPathRows[] = { + "Timing Path/Data path", + "Timing Path/Launch clock", + "Timing Path/Capture clock", + "Timing Path/Legend", +}; + +constexpr const char* kBackground = "Misc/Background"; + +const char* columnName(const bool selectable) +{ + return selectable ? "select" : "visible"; +} + +} // namespace + +ScriptView::ScriptView(odb::dbDatabase* db, utl::Logger* logger) + : db_(db), logger_(logger) +{ + for (const char* path : kTimingPathRows) { + tree_.addLeaf(path, {.visible = true, .selectable = std::nullopt}); + } +} + +void ScriptView::refreshLocked() +{ + tree_.addDesignRows(db_); + seedRendererControls(renderer_controls_); +} + +std::vector ScriptView::matchLocked( + DisplayControlTree& tree, + const std::string& pattern, + const bool selectable) +{ + std::vector matches; + for (const auto& [path, leaf] : tree.leaves()) { + const bool has_box + = selectable ? leaf.selectable.has_value() : leaf.visible.has_value(); + if (has_box && DisplayControlTree::matches(pattern, path)) { + matches.push_back({.path = path, .leaf = tree.find(path)}); + } + } + if (selectable) { + // Qt gives a renderer's controls no selectable box. + return matches; + } + + std::set renderer_paths; + for (Renderer* renderer : Gui::get()->renderers()) { + for (const auto& [name, control] : renderer->getDisplayControls()) { + const std::string path = renderer->displayControlPath(name); + if (tree.find(path) == nullptr + && DisplayControlTree::matches(pattern, path)) { + renderer_paths.insert(path); + } + } + } + for (const std::string& path : renderer_paths) { + matches.push_back({.path = path, .leaf = nullptr}); + } + return matches; +} + +bool ScriptView::check(const std::string& name, const bool selectable) +{ + const std::scoped_lock lock(mutex_); + refreshLocked(); + const std::vector matches = matchLocked(tree_, name, selectable); + if (matches.empty()) { + logger_->warn(utl::WEB, + 127, + "Unable to find {} display control at {}.", + columnName(selectable), + name); + return false; + } + if (matches.size() > 1) { + logger_->warn(utl::WEB, + 128, + "Found {} controls matching {} at {}.", + matches.size(), + name, + columnName(selectable)); + return false; + } + const Match& match = matches.front(); + if (match.leaf == nullptr) { + return renderer_controls_.check(match.path); + } + const auto& value = selectable ? match.leaf->selectable : match.leaf->visible; + return value.value_or(false); +} + +void ScriptView::set(const std::string& name, + const bool selectable, + const bool value) +{ + const std::scoped_lock lock(mutex_); + refreshLocked(); + const std::vector matches = matchLocked(tree_, name, selectable); + if (matches.empty()) { + logger_->error(utl::WEB, + 126, + "Unable to find {} display control at {}.", + columnName(selectable), + name); + } + for (const Match& match : matches) { + if (match.leaf != nullptr) { + (selectable ? match.leaf->selectable : match.leaf->visible) = value; + } else { + web::setRendererControl(renderer_controls_, match.path, value); + } + } +} + +bool ScriptView::checkDisplayControlVisible(const std::string& name) +{ + return check(name, /*selectable=*/false); +} + +bool ScriptView::checkDisplayControlSelectable(const std::string& name) +{ + return check(name, /*selectable=*/true); +} + +void ScriptView::setDisplayControlVisible(const std::string& name, + const bool value) +{ + set(name, /*selectable=*/false, value); +} + +void ScriptView::setDisplayControlSelectable(const std::string& name, + const bool value) +{ + set(name, /*selectable=*/true, value); +} + +void ScriptView::setDisplayControlColor(const std::string& name, + const Painter::Color& color) +{ + const std::scoped_lock lock(mutex_); + refreshLocked(); + 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; + } + } + if (!found) { + logger_->error(utl::WEB, 130, "Unable to find {} display control", name); + } + if (ignored) { + logger_->warn(utl::WEB, + 129, + "Without the Qt GUI only the {} color is used; ignoring it " + "for {}.", + kBackground, + name); + } +} + +void ScriptView::saveDisplayControls() +{ + const std::scoped_lock lock(mutex_); + refreshLocked(); + saved_ = Saved{ + .leaves = tree_.leaves(), + .renderer_controls = renderer_controls_.values(), + }; +} + +void ScriptView::restoreDisplayControls() +{ + const std::scoped_lock lock(mutex_); + if (!saved_) { + return; + } + // Only the controls that still exist, as DisplayControls::restore does. + for (const auto& [path, leaf] : saved_->leaves) { + if (DisplayControlTree::Leaf* current = tree_.find(path)) { + *current = leaf; + } + } + renderer_controls_.restore(saved_->renderer_controls); +} + +bool ScriptView::checkRendererControl(const std::string& path) +{ + seedRendererControls(renderer_controls_); + return renderer_controls_.check(path); +} + +void ScriptView::setRendererControl(const std::string& path, const bool value) +{ + seedRendererControls(renderer_controls_); + web::setRendererControl(renderer_controls_, path, value); +} + +std::vector ScriptView::displayControlPaths() +{ + const std::scoped_lock lock(mutex_); + refreshLocked(); + std::vector paths; + for (const Match& match : matchLocked(tree_, "*", /*selectable=*/false)) { + paths.push_back(match.path); + } + std::ranges::sort(paths); + return paths; +} + +ScriptView::Frame ScriptView::frame( + const std::map& overrides) +{ + const std::scoped_lock lock(mutex_); + refreshLocked(); + + // The patterns go on a copy, so an image's options do not stick. + DisplayControlTree tree = tree_; + std::map flags; + for (const auto& [key, value] : overrides) { + if (TileVisibility::isFlag(key)) { + flags.emplace(key, value); + continue; + } + const std::vector matches + = matchLocked(tree, key, /*selectable=*/false); + if (matches.empty()) { + logger_->error(utl::WEB, + 131, + "{} is neither a display control nor a display option.", + key); + } + for (const Match& match : matches) { + if (match.leaf != nullptr) { + match.leaf->visible = value; + } + } + } + + Frame frame; + tree.apply(frame.vis); + frame.vis.setFlags(flags); + frame.background = background_; + return frame; +} + +} // namespace web diff --git a/src/web/src/script_view.h b/src/web/src/script_view.h new file mode 100644 index 00000000000..39b3db6d98c --- /dev/null +++ b/src/web/src/script_view.h @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#pragma once + +#include +#include +#include +#include +#include + +#include "display_control_tree.h" +#include "renderer_controls.h" +#include "tile_generator.h" +#include "web/core.h" + +namespace odb { +class dbDatabase; +} // namespace odb + +namespace utl { +class Logger; +} + +namespace web { + +// What gui:: commands act on with no Qt window: Qt-named controls that +// save_image -web draws by. Not a backend, so Gui::enabled() stays false. +class ScriptView : public GuiBackend +{ + public: + ScriptView(odb::dbDatabase* db, utl::Logger* logger); + + void redraw() override {} + void pause(int /* timeout_ms */) override {} + bool isPaused() const override { return false; } + // A saved image with no -area frames the whole design already. + void fit() override {} + + bool checkDisplayControlVisible(const std::string& name) override; + bool checkDisplayControlSelectable(const std::string& name) override; + void setDisplayControlVisible(const std::string& name, bool value) override; + void setDisplayControlSelectable(const std::string& name, + bool value) override; + void setDisplayControlColor(const std::string& name, + const Painter::Color& color) override; + void saveDisplayControls() override; + void restoreDisplayControls() override; + std::vector displayControlPaths() override; + // From the renderers, possibly on the render threads: only the shared + // RendererControls, under its own lock. + bool checkRendererControl(const std::string& path) override; + void setRendererControl(const std::string& path, bool value) override; + + // Shared with the web viewer, so the browser's renderer toggles and Tcl's + // agree. + RendererControls& rendererControls() { return renderer_controls_; } + + // What a saved image is drawn by. + struct Frame + { + TileVisibility vis; + // Set only once a script has chosen Misc/Background's color. + std::optional background; + }; + // The current controls with `overrides` (TileVisibility JSON keys or + // display-control patterns) on top, leaving the controls as they were. + Frame frame(const std::map& overrides = {}); + + private: + // A control a pattern can name: a leaf of the tree, or a registered + // renderer's control, whose state lives in renderer_controls_. + struct Match + { + std::string path; + DisplayControlTree::Leaf* leaf; + }; + + // Brings the design's layers and sites, and the renderers' controls, in. + void refreshLocked(); + std::vector matchLocked(DisplayControlTree& tree, + const std::string& pattern, + bool selectable); + bool check(const std::string& name, bool selectable); + void set(const std::string& name, bool selectable, bool value); + + odb::dbDatabase* db_; + utl::Logger* logger_; + + std::mutex mutex_; + DisplayControlTree tree_; + RendererControls renderer_controls_; + std::optional background_; + + struct Saved + { + DisplayControlTree::Leaves leaves; + RendererControls::Values renderer_controls; + }; + std::optional saved_; +}; + +} // namespace web diff --git a/src/web/src/tile_generator.cpp b/src/web/src/tile_generator.cpp index e01656b83b3..823ff557f27 100644 --- a/src/web/src/tile_generator.cpp +++ b/src/web/src/tile_generator.cpp @@ -1101,6 +1101,8 @@ const BoolField kBoolFields[] = { {"std_level_shift", &TileVisibility::std_level_shift, true}, {"std_sequential", &TileVisibility::std_sequential, true}, {"std_combinational", &TileVisibility::std_combinational, true}, + {"std_physical", &TileVisibility::std_physical, true}, + {"std_other", &TileVisibility::std_other, true}, {"net_signal", &TileVisibility::net_signal, true}, {"net_power", &TileVisibility::net_power, true}, {"net_ground", &TileVisibility::net_ground, true}, @@ -1154,6 +1156,41 @@ std::optional TileVisibility::flag(const std::string_view key) const return std::nullopt; } +bool TileVisibility::isFlag(const std::string_view key) +{ + return std::ranges::any_of( + kBoolFields, [key](const BoolField& f) { return key == f.key; }); +} + +bool TileVisibility::setFlag(const std::string_view key, const bool value) +{ + // As parseFromJson does with no keys of their own, the two follow stdcells. + if (key == "stdcells") { + std_physical = value; + std_other = value; + } + for (const BoolField& f : kBoolFields) { + if (key == f.key) { + this->*f.field = value; + return true; + } + } + return false; +} + +void TileVisibility::setFlags(const std::map& flags) +{ + // stdcells first, so std_physical or std_other given with it wins. + if (const auto it = flags.find("stdcells"); it != flags.end()) { + setFlag(it->first, it->second); + } + for (const auto& [key, value] : flags) { + if (key != "stdcells") { + setFlag(key, value); + } + } +} + void TileVisibility::parseFromJson(const boost::json::object& json) { // Visibility flags are nominally always sent by the web frontend, but @@ -1162,6 +1199,8 @@ void TileVisibility::parseFromJson(const boost::json::object& json) for (const auto& f : kBoolFields) { this->*(f.field) = jsonOr(json, f.key, f.default_val); } + std_physical = jsonOr(json, "std_physical", stdcells); + std_other = jsonOr(json, "std_other", stdcells); // Bound the visibility-filter sizes so a malformed/oversized payload // can't make us allocate unbounded memory or thrash later contains() @@ -1248,6 +1287,9 @@ void TileVisibility::parseFromJson(const boost::json::object& json) for (const auto& f : kSelectableFields) { this->*(f.field) = jsonOr(json, f.key, f.default_val); } + std_physical_selectable + = jsonOr(json, "s_std_physical", stdcells_selectable); + std_other_selectable = jsonOr(json, "s_std_other", stdcells_selectable); selectable_layers.clear(); has_selectable_layers = false; @@ -1400,9 +1442,11 @@ InstCategory classifyInstance(odb::dbInst* inst, sta::dbSta* sta) return InstCategory::kStdSequential; case IT::STD_COMBINATIONAL: return InstCategory::kStdCombinational; - case IT::STD_CELL: case IT::STD_PHYSICAL: + return InstCategory::kStdPhysical; case IT::STD_OTHER: + return InstCategory::kStdOther; + case IT::STD_CELL: default: return InstCategory::kStdCells; } @@ -1518,6 +1562,10 @@ bool TileVisibility::isCategoryVisible(InstCategory cat) const return std_sequential; case InstCategory::kStdCombinational: return std_combinational; + case InstCategory::kStdPhysical: + return std_physical; + case InstCategory::kStdOther: + return std_other; } return stdcells; } @@ -1573,6 +1621,10 @@ bool TileVisibility::isInstSelectable(odb::dbInst* inst, sta::dbSta* sta) const return std_sequential_selectable; case InstCategory::kStdCombinational: return std_combinational_selectable; + case InstCategory::kStdPhysical: + return std_physical_selectable; + case InstCategory::kStdOther: + return std_other_selectable; } return stdcells_selectable; } @@ -6561,6 +6613,52 @@ void TileGenerator::saveImage(const std::string& filename, utl::WEB, 24, "Saved {}x{} image to {}", final_w, final_h, filename); } +TileVisibility overlayOnlyVisibility() +{ + TileVisibility vis; + vis.stdcells = false; + vis.macros = false; + vis.pad_input = false; + vis.pad_output = false; + vis.pad_inout = false; + vis.pad_power = false; + vis.pad_spacer = false; + vis.pad_areaio = false; + vis.pad_other = false; + vis.phys_fill = false; + vis.phys_endcap = false; + vis.phys_welltap = false; + vis.phys_tie = false; + vis.phys_antenna = false; + vis.phys_cover = false; + vis.phys_bump = false; + vis.phys_other = false; + vis.std_bufinv = false; + vis.std_bufinv_timing = false; + vis.std_clock_bufinv = false; + vis.std_clock_gate = false; + vis.std_level_shift = false; + vis.std_sequential = false; + vis.std_combinational = false; + vis.std_physical = false; + vis.std_other = false; + vis.routing = false; + vis.routing_segments = false; + vis.routing_vias = false; + vis.special_nets = false; + vis.srouting_segments = false; + vis.srouting_vias = false; + vis.pins = false; + vis.pin_names = false; + vis.inst_names = false; + vis.inst_pins = false; + vis.inst_pin_names = false; + vis.blockages = false; + vis.placement_blockages = false; + vis.routing_obstructions = false; + return vis; +} + std::vector TileGenerator::renderOverlayPng( int width_px, const std::vector& rects, @@ -6611,45 +6709,7 @@ std::vector TileGenerator::renderOverlayPng( std::vector output(4UL * tile_span_w * tile_span_h, 0); // Render on _instances layer with all visibility off so only overlays draw. - TileVisibility vis; - vis.stdcells = false; - vis.macros = false; - vis.pad_input = false; - vis.pad_output = false; - vis.pad_inout = false; - vis.pad_power = false; - vis.pad_spacer = false; - vis.pad_areaio = false; - vis.pad_other = false; - vis.phys_fill = false; - vis.phys_endcap = false; - vis.phys_welltap = false; - vis.phys_tie = false; - vis.phys_antenna = false; - vis.phys_cover = false; - vis.phys_bump = false; - vis.phys_other = false; - vis.std_bufinv = false; - vis.std_bufinv_timing = false; - vis.std_clock_bufinv = false; - vis.std_clock_gate = false; - vis.std_level_shift = false; - vis.std_sequential = false; - vis.std_combinational = false; - vis.routing = false; - vis.routing_segments = false; - vis.routing_vias = false; - vis.special_nets = false; - vis.srouting_segments = false; - vis.srouting_vias = false; - vis.pins = false; - vis.pin_names = false; - vis.inst_names = false; - vis.inst_pins = false; - vis.inst_pin_names = false; - vis.blockages = false; - vis.placement_blockages = false; - vis.routing_obstructions = false; + const TileVisibility vis = overlayOnlyVisibility(); for (int ty = 0; ty <= ty_max; ++ty) { for (int tx = 0; tx <= tx_max; ++tx) { diff --git a/src/web/src/tile_generator.h b/src/web/src/tile_generator.h index fd9644783ee..a7307dffa24 100644 --- a/src/web/src/tile_generator.h +++ b/src/web/src/tile_generator.h @@ -257,6 +257,8 @@ enum class InstCategory kStdLevelShift, kStdSequential, kStdCombinational, + kStdPhysical, // a liberty cell with no ports (decap, ...) + kStdOther, // no liberty cell, and not a core master }; InstCategory classifyInstance(odb::dbInst* inst, sta::dbSta* sta); @@ -296,6 +298,10 @@ struct TileVisibility bool std_level_shift = true; bool std_sequential = true; bool std_combinational = true; + // Qt draws these by Instances/Physical and Instances; a payload without + // their keys gives them stdcells' value. + bool std_physical = true; + bool std_other = true; // Net sub-types (by dbSigType) bool net_signal = true; @@ -440,6 +446,8 @@ struct TileVisibility bool std_level_shift_selectable = true; bool std_sequential_selectable = true; bool std_combinational_selectable = true; + bool std_physical_selectable = true; + bool std_other_selectable = true; bool net_signal_selectable = true; bool net_power_selectable = true; @@ -473,6 +481,11 @@ struct TileVisibility bool pinNamesShown() const { return inst_pins && inst_pin_names; } // The boolean field a JSON key sets, or none for a key it does not know. std::optional flag(std::string_view key) const; + static bool isFlag(std::string_view key); + // Sets the field a JSON key names; false for a key it does not know. + bool setFlag(std::string_view key, bool value); + // setFlag for each, with stdcells before the std_physical/std_other it sets. + void setFlags(const std::map& flags); // Visibility for an already-classified instance. Lets callers that already // computed the category (e.g. the tile render loop) avoid reclassifying. bool isCategoryVisible(InstCategory cat) const; @@ -483,6 +496,9 @@ struct TileVisibility bool isLayerSelectable(const std::string& layer_name) const; }; +// Nothing of the design: an image of only what is drawn over it. +TileVisibility overlayOnlyVisibility(); + class TileGenerator { public: diff --git a/src/web/src/web.cpp b/src/web/src/web.cpp index 1d02b2185c4..bb4058bcfc3 100644 --- a/src/web/src/web.cpp +++ b/src/web/src/web.cpp @@ -48,9 +48,11 @@ #include "odb/db.h" #include "odb/dbBlockCallBackObj.h" #include "odb/dbChipCallBackObj.h" +#include "renderer_controls.h" #include "report_html.h" #include "request_dispatcher.h" #include "request_handler.h" +#include "script_view.h" #include "tcl.h" #include "tile_generator.h" #include "timing_report.h" @@ -516,25 +518,29 @@ bool isRegisteredHeatMapName(const std::string& name) return false; } -void seedRendererControls(WebViewerHook* hook) +void seedRendererControls(RendererControls& controls) { - if (hook == nullptr) { - return; - } for (web::Renderer* renderer : web::Gui::get()->renderers()) { // The controls a renderer declares are fixed once it has registered, so // one pass per renderer is enough — the render path calls this on every // tile and must not pay for the walk each time. - if (!hook->markRendererSeeded(renderer)) { + if (!controls.markSeeded(renderer)) { continue; } for (const auto& [name, control] : renderer->getDisplayControls()) { - hook->seedDisplayControlVisible(renderer->displayControlPath(name), - control.visibility); + controls.seed(renderer->displayControlPath(name), control.visibility); } } } +void seedRendererControls(WebViewerHook* hook) +{ + if (hook == nullptr) { + return; + } + seedRendererControls(hook->rendererControls()); +} + // Serializes the per-renderer display controls for the `renderer_controls` // request: {"type":"renderer_controls","controls":[...]}. Flat list; the // client groups by `group` the way registerRenderer merges renderers that @@ -560,7 +566,6 @@ std::string rendererControlsJson(WebViewerHook* hook) // Matching the name alone would silently drop an unrelated renderer's // control that happened to be called "Pin Density"; matching the group // alone would drop a real renderer that picked the same group name. - static constexpr const char* kHeatMapGroup = "Heat Maps"; boost::json::array controls; for (web::Renderer* renderer : web::Gui::get()->renderers()) { @@ -595,12 +600,22 @@ std::string rendererControlsJson(WebViewerHook* hook) return boost::json::serialize(root); } +void setRendererControl(RendererControls& controls, + const std::string& path, + const bool value) +{ + controls.set(path, value); + if (value) { + applyRendererControlExclusivity(controls, path); + } +} + // The per-renderer control just switched on at `path` turns off the siblings // it declares mutually exclusive with, mirroring // DisplayControls::itemChanged: exclusivity is scoped to the parent group, an // empty name means "every sibling", and renderers that share a group name // share the parent, so a sibling can belong to another renderer. -void applyRendererControlExclusivity(WebViewerHook* hook, +void applyRendererControlExclusivity(RendererControls& controls, const std::string& path) { std::string group; @@ -638,7 +653,7 @@ void applyRendererControlExclusivity(WebViewerHook* hook, if (control_path == path) { continue; } - hook->setDisplayControlVisible(control_path, false); + controls.set(control_path, false); } } } @@ -858,10 +873,7 @@ WebSocketSession::WebSocketSession( try { const std::string path = std::string(req.json.at("path").as_string()); const bool value = req.json.at("value").as_bool(); - viewer_hook_->setDisplayControlVisible(path, value); - if (value) { - applyRendererControlExclusivity(viewer_hook_, path); - } + setRendererControl(viewer_hook_->rendererControls(), path, value); // Every client shows the same server-side state, so tell them all; // the renderers redraw from the new values on the next tile. viewer_hook_->sessions().broadcast( @@ -1680,8 +1692,10 @@ WebServer::WebServer(odb::dbDatabase* db, logger_(logger), interp_(interp), num_threads_(1), - tcl_eval_(std::make_shared(interp, logger)) + tcl_eval_(std::make_shared(interp, logger)), + script_view_(std::make_unique(db, logger)) { + web::Gui::get()->setScriptView(script_view_.get()); } void WebServer::setThreadCount(int num_threads) @@ -1762,6 +1776,13 @@ WebServer::~WebServer() logger_->removeSink(log_sink_); log_sink_.reset(); } + // The script view goes with us, so nothing may reach it afterwards. + if (web::Gui::get()->getScriptView() == script_view_.get()) { + web::Gui::get()->setScriptView(nullptr); + } + if (viewer_hook_) { + viewer_hook_->setRendererControls(nullptr); + } // Also leak viewer_hook_ — it may be referenced by Gui's // headless_viewer_ pointer which outlives us (static singleton). (void) viewer_hook_.release(); // NOLINT(bugprone-unused-return-value) diff --git a/src/web/src/web_serve.cpp b/src/web/src/web_serve.cpp index abde7263c20..26f64dd3728 100644 --- a/src/web/src/web_serve.cpp +++ b/src/web/src/web_serve.cpp @@ -40,6 +40,7 @@ #include "clock_tree_report.h" #include "odb/geom.h" #include "request_handler.h" +#include "script_view.h" #include "spdlog/sinks/base_sink.h" #include "tcl.h" #include "tile_generator.h" @@ -146,6 +147,8 @@ void WebServer::initLogger() // chart factory are installed in serve() instead. if (!viewer_hook_) { viewer_hook_ = std::make_unique(); + // One set of renderer controls for the browser and the gui:: commands. + viewer_hook_->setRendererControls(&script_view_->rendererControls()); } auto log_sink = std::make_shared(viewer_hook_.get()); @@ -338,6 +341,11 @@ void WebServer::serve(int port, const std::string& bind_address) } seedRendererControls(hook); for (web::Renderer* renderer : web::Gui::get()->renderers()) { + // Heat maps have a tile layer of their own here, and their own pass + // in save_image -web. + if (web::Gui::get()->isHeatMapRenderer(renderer)) { + continue; + } // A Renderer sees the tile as a whole-DBU window (Painter's API is // integer DBU); only the rasterization below needs the exact // origin, which it takes from the frame. diff --git a/src/web/src/web_viewer_hook.cpp b/src/web/src/web_viewer_hook.cpp index cdb864479c0..d8ff1b8fa48 100644 --- a/src/web/src/web_viewer_hook.cpp +++ b/src/web/src/web_viewer_hook.cpp @@ -317,31 +317,18 @@ bool WebViewerHook::takeRenderersChanged() bool WebViewerHook::checkDisplayControlVisible(const std::string& name) { - const std::lock_guard lock(renderer_controls_mutex_); - const auto it = renderer_control_visible_.find(name); - return it == renderer_control_visible_.end() ? true : it->second; + return renderer_controls_->check(name); } void WebViewerHook::setDisplayControlVisible(const std::string& name, const bool value) { - const std::lock_guard lock(renderer_controls_mutex_); - renderer_control_visible_[name] = value; + renderer_controls_->set(name, value); } -void WebViewerHook::seedDisplayControlVisible(const std::string& name, - const bool value) +void WebViewerHook::setRendererControls(RendererControls* controls) { - const std::lock_guard lock(renderer_controls_mutex_); - // insert(), not operator[]: a renderer re-registering (a second placement - // run) must not reset a control the user turned on. - renderer_control_visible_.insert({name, value}); -} - -bool WebViewerHook::markRendererSeeded(const void* renderer) -{ - const std::lock_guard lock(renderer_controls_mutex_); - return seeded_renderers_.insert(renderer).second; + renderer_controls_ = controls != nullptr ? controls : &own_renderer_controls_; } void WebViewerHook::drainLogs() diff --git a/src/web/src/web_viewer_hook.h b/src/web/src/web_viewer_hook.h index 1304ba5d682..6fc5c4701af 100644 --- a/src/web/src/web_viewer_hook.h +++ b/src/web/src/web_viewer_hook.h @@ -8,14 +8,13 @@ #include #include #include -#include #include #include -#include #include #include #include +#include "renderer_controls.h" #include "web/core.h" namespace utl { @@ -113,27 +112,23 @@ class WebViewerHook : public web::GuiBackend // Per-renderer display controls (issue #10619, the Qt DisplayControls rows // built by registerRenderer from Renderer::getDisplayControls()). // - // web::Renderer::checkDisplayControl composes the path "Group/Name" and - // routes it here through Gui::checkDisplayControlsVisible when there is no - // Qt window. The base class answers "everything visible", which made every - // sub-control read as on: FlexDRGraphics registers ten of them, six - // defaulting to off, and the web drew them all. Backing them with a real - // map is what gives the web the same filtering Qt has. + // web::Renderer::checkDisplayControl composes the path "Group/Name"; with no + // Qt window Gui::checkRendererControl answers it from the script view, whose + // store this hook shares (setRendererControls). The base class answers + // "everything visible", which made every sub-control read as on: + // FlexDRGraphics registers ten of them, six defaulting to off, and the web + // drew them all. Backing them with a real map is what gives the web the + // same filtering Qt has. // - // Renderers query these from the render threads, so the map is mutex - // guarded. A path that was never set falls back to `default_value`, which - // the registry seeds from each control's own initial visibility. + // Renderers query these from the render threads; the RendererControls store + // is mutex guarded, and seeded from each control's initial visibility. bool checkDisplayControlVisible(const std::string& name) override; void setDisplayControlVisible(const std::string& name, bool value) override; - // Seed a control's value the first time its renderer is seen, without - // clobbering a value the user has since chosen. - void seedDisplayControlVisible(const std::string& name, bool value); - - // True the first time this renderer is offered for seeding. Lets the - // render path skip the whole walk on every tile after the first: the - // controls a renderer declares are fixed once it has registered. - bool markRendererSeeded(const void* renderer); + // Where the controls above live: the hook's own by default, or a store + // shared with the script view, so Tcl and the browser see one set. + void setRendererControls(RendererControls* controls); + RendererControls& rendererControls() { return *renderer_controls_; } // Release any blocked placer thread. Called by the DEBUG_CONTINUE // request handler. @@ -304,9 +299,8 @@ class WebViewerHook : public web::GuiBackend // Per-renderer display controls, keyed by the "Group/Name" path // web::Renderer::checkDisplayControl builds. Read from render threads. - mutable std::mutex renderer_controls_mutex_; - std::map renderer_control_visible_; - std::set seeded_renderers_; + RendererControls own_renderer_controls_; + RendererControls* renderer_controls_ = &own_renderer_controls_; // Set by (un)registerRenderer, taken once the change has settled. std::atomic renderers_changed_{false}; }; @@ -320,12 +314,4 @@ void seedRendererControls(WebViewerHook* hook); // heat maps are not. Seeds each control's default into `hook` on the way. std::string rendererControlsJson(WebViewerHook* hook); -// Applies Qt's mutual-exclusivity rule after a per-renderer control is -// switched on: the siblings it names, within its own group, go off ("" names -// every sibling), as DisplayControls::itemChanged does. Defined in web.cpp, -// which may reach web::Gui — this header must not, so that the targets which -// link only the hook stay free of it. -void applyRendererControlExclusivity(WebViewerHook* hook, - const std::string& path); - } // namespace web diff --git a/src/web/test/BUILD b/src/web/test/BUILD index 94951de955d..c898436a0d7 100644 --- a/src/web/test/BUILD +++ b/src/web/test/BUILD @@ -74,6 +74,7 @@ test_suite( ":heat_map_test", ":request_handler_test", ":save_display_controls_test", + ":script_view_test", ":tile_generator_test", ":web_assets_test", ], @@ -499,6 +500,22 @@ cc_test( ], ) +cc_test( + name = "script_view_test", + srcs = ["cpp/TestScriptView.cpp"], + data = [ + "//test:nangate45_data", + ], + deps = [ + "//src/odb/src/db", + "//src/tst:nangate45_fixture", + "//src/web", + "//src/web:core", + "@googletest//:gtest", + "@googletest//:gtest_main", + ], +) + cc_test( name = "snap_test", srcs = ["cpp/TestSnap.cpp"], diff --git a/src/web/test/cpp/CMakeLists.txt b/src/web/test/cpp/CMakeLists.txt index 84cf593be1c..bcdc76071f3 100644 --- a/src/web/test/cpp/CMakeLists.txt +++ b/src/web/test/cpp/CMakeLists.txt @@ -29,6 +29,7 @@ set(WEB_TESTS TestCharts TestLabels TestSaveDisplayControls + TestScriptView TestGif TestWebAssets TestHeatMap diff --git a/src/web/test/cpp/TestDebugGraphics.cpp b/src/web/test/cpp/TestDebugGraphics.cpp index 74b606464c7..384a1724680 100644 --- a/src/web/test/cpp/TestDebugGraphics.cpp +++ b/src/web/test/cpp/TestDebugGraphics.cpp @@ -16,6 +16,7 @@ #include "gtest/gtest.h" #include "odb/db.h" #include "odb/geom.h" +#include "renderer_controls.h" #include "tile_generator.h" #include "web/core.h" #include "web_chart.h" @@ -468,8 +469,8 @@ TEST(WebViewerHookTest, DisplayControlVisibilityRoundTrips) TEST(WebViewerHookTest, SeedInstallsTheRenderersOwnDefault) { WebViewerHook hook; - hook.seedDisplayControlVisible("Detailed Router/Graph edges", false); - hook.seedDisplayControlVisible("Detailed Router/Route guides", true); + hook.rendererControls().seed("Detailed Router/Graph edges", false); + hook.rendererControls().seed("Detailed Router/Route guides", true); EXPECT_FALSE(hook.checkDisplayControlVisible("Detailed Router/Graph edges")); EXPECT_TRUE(hook.checkDisplayControlVisible("Detailed Router/Route guides")); } @@ -482,19 +483,19 @@ TEST(WebViewerHookTest, ARendererIsOfferedForSeedingOnlyOnce) { WebViewerHook hook; int marker = 0; - EXPECT_TRUE(hook.markRendererSeeded(&marker)); - EXPECT_FALSE(hook.markRendererSeeded(&marker)); + EXPECT_TRUE(hook.rendererControls().markSeeded(&marker)); + EXPECT_FALSE(hook.rendererControls().markSeeded(&marker)); int other = 0; - EXPECT_TRUE(hook.markRendererSeeded(&other)) + EXPECT_TRUE(hook.rendererControls().markSeeded(&other)) << "a second renderer is still seeded"; } TEST(WebViewerHookTest, SeedDoesNotClobberAUserChoice) { WebViewerHook hook; - hook.seedDisplayControlVisible("PDN/Vias", false); + hook.rendererControls().seed("PDN/Vias", false); hook.setDisplayControlVisible("PDN/Vias", true); - hook.seedDisplayControlVisible("PDN/Vias", false); + hook.rendererControls().seed("PDN/Vias", false); EXPECT_TRUE(hook.checkDisplayControlVisible("PDN/Vias")) << "the second seed must not reset the control"; } diff --git a/src/web/test/cpp/TestHeatMap.cpp b/src/web/test/cpp/TestHeatMap.cpp index baf539cce9b..73d0e9eb311 100644 --- a/src/web/test/cpp/TestHeatMap.cpp +++ b/src/web/test/cpp/TestHeatMap.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2026, The OpenROAD Authors +#include #include #include "db_sta/dbNetwork.hh" @@ -11,6 +12,7 @@ #include "sta/PowerClass.hh" #include "tst/nangate45_fixture.h" #include "utl/Logger.h" +#include "web/core.h" #include "web/heatMap.h" namespace web { @@ -44,6 +46,35 @@ class UniformHeatMap : public HeatMapDataSource } }; +// A renderer that only exists to carry a display control. +class ControlsOnlyRenderer : public Renderer +{ + public: + const char* getDisplayControlGroupName() override { return kHeatMapGroup; } +}; + +// The web viewer leaves these out of its renderer pass: it draws heat maps +// its own way. +TEST(HeatMapRendererTest, OnlyTheRegisteredOnesAreHeatMapRenderers) +{ + utl::Logger logger; + UniformHeatMap heat_map(&logger); + Gui* gui = Gui::get(); + const std::set before = gui->renderers(); + gui->registerHeatMap(&heat_map); + int added = 0; + for (Renderer* renderer : gui->renderers()) { + if (!before.contains(renderer)) { + ++added; + EXPECT_TRUE(gui->isHeatMapRenderer(renderer)); + } + } + EXPECT_EQ(added, 1); + ControlsOnlyRenderer other; + EXPECT_FALSE(gui->isHeatMapRenderer(&other)) << "a group name is not enough"; + gui->unregisterHeatMap(&heat_map); +} + class HeatMapTest : public tst::Nangate45Fixture { protected: diff --git a/src/web/test/cpp/TestSaveDisplayControls.cpp b/src/web/test/cpp/TestSaveDisplayControls.cpp index 5c313b74a3d..1f497b2df43 100644 --- a/src/web/test/cpp/TestSaveDisplayControls.cpp +++ b/src/web/test/cpp/TestSaveDisplayControls.cpp @@ -11,6 +11,7 @@ #include "boost/json.hpp" #include "gtest/gtest.h" +#include "renderer_controls.h" #include "tst/nangate45_fixture.h" #include "web/core.h" #include "web/heatMap.h" @@ -246,7 +247,8 @@ TEST(RendererControlExclusivity, TurningOneOnTurnsOffTheNamedSiblings) for (const char* name : {"Maze search", "Graph edges", "Route guides"}) { hook.setDisplayControlVisible(std::string("Detailed Router/") + name, true); } - applyRendererControlExclusivity(&hook, "Detailed Router/Maze search"); + applyRendererControlExclusivity(hook.rendererControls(), + "Detailed Router/Maze search"); EXPECT_TRUE(hook.checkDisplayControlVisible("Detailed Router/Maze search")) << "the control that was switched on stays on"; @@ -270,7 +272,7 @@ TEST(RendererControlExclusivity, EmptyNameExcludesEverySibling) for (const char* name : {"Shapes", "Nodes", "Sources"}) { hook.setDisplayControlVisible(std::string("IR Drop/") + name, true); } - applyRendererControlExclusivity(&hook, "IR Drop/Shapes"); + applyRendererControlExclusivity(hook.rendererControls(), "IR Drop/Shapes"); EXPECT_TRUE(hook.checkDisplayControlVisible("IR Drop/Shapes")); EXPECT_FALSE(hook.checkDisplayControlVisible("IR Drop/Nodes")); @@ -291,7 +293,8 @@ TEST(RendererControlExclusivity, DoesNotReachIntoAnotherGroup) WebViewerHook hook; hook.setDisplayControlVisible("Detailed Router/Maze search", true); hook.setDisplayControlVisible("PDN/Vias", true); - applyRendererControlExclusivity(&hook, "Detailed Router/Maze search"); + applyRendererControlExclusivity(hook.rendererControls(), + "Detailed Router/Maze search"); EXPECT_TRUE(hook.checkDisplayControlVisible("PDN/Vias")) << "exclusivity is scoped to the parent group"; @@ -311,7 +314,7 @@ TEST(RendererControlExclusivity, NoExclusivityIsANoOp) WebViewerHook hook; hook.setDisplayControlVisible("PDN/Vias", true); hook.setDisplayControlVisible("PDN/Straps", true); - applyRendererControlExclusivity(&hook, "PDN/Vias"); + applyRendererControlExclusivity(hook.rendererControls(), "PDN/Vias"); EXPECT_TRUE(hook.checkDisplayControlVisible("PDN/Straps")); diff --git a/src/web/test/cpp/TestScriptView.cpp b/src/web/test/cpp/TestScriptView.cpp new file mode 100644 index 00000000000..8133fb8ab6c --- /dev/null +++ b/src/web/test/cpp/TestScriptView.cpp @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2026, The OpenROAD Authors + +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "odb/db.h" +#include "script_view.h" +#include "tile_generator.h" +#include "tst/nangate45_fixture.h" +#include "web/core.h" +#include "web/descriptor_registry.h" +#include "web_viewer_hook.h" + +namespace web { +namespace { + +constexpr const char* kSite = "Rows/FreePDK45_38x28_10R_NP_162NW_34O"; + +class ScriptViewTest : public tst::Nangate45Fixture +{ + protected: + ScriptView view_{getDb(), getLogger()}; +}; + +// A renderer that only exists to carry display controls. +class ControlsOnlyRenderer : public Renderer +{ + public: + const char* getDisplayControlGroupName() override { return "Test Group"; } + using Renderer::addDisplayControl; +}; + +// The defaults DisplayControls' constructor and addTech give the same rows. +TEST_F(ScriptViewTest, DefaultsAreTheQtOnes) +{ + EXPECT_TRUE(view_.checkDisplayControlVisible("Nets/Power")); + EXPECT_TRUE(view_.checkDisplayControlSelectable("Nets/Power")); + EXPECT_TRUE(view_.checkDisplayControlVisible("Instances/Physical/Fill cell")); + EXPECT_TRUE(view_.checkDisplayControlVisible("Misc/Scale bar")); + EXPECT_TRUE(view_.checkDisplayControlVisible("Misc/Highlight selected")); + EXPECT_TRUE(view_.checkDisplayControlVisible("Timing Path/Data path")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Tracks/Pref")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Shape Types/Fills")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Misc/Instances/Pin Names")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Misc/Detailed view")); + + // Routing and cut layers are on; masterslice and overlap go under Other, + // which starts off; the lib's site starts as Rows does, off. + EXPECT_TRUE(view_.checkDisplayControlVisible("Layers/metal1")); + EXPECT_TRUE(view_.checkDisplayControlVisible("Layers/via1")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Layers/Other/poly")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Layers/Other/OVERLAP")); + EXPECT_FALSE(view_.checkDisplayControlVisible(kSite)); +} + +// Even before anything else asks, a parent with rows under it is not one. +TEST_F(ScriptViewTest, TheFirstCheckOfAParentWarns) +{ + getLogger()->redirectStringBegin(); + EXPECT_FALSE(view_.checkDisplayControlVisible("Rows")); + EXPECT_NE(getLogger()->redirectStringEnd().find("WEB-0127"), + std::string::npos); +} + +// Only leaves are controls: a parent with rows under it is not one. +TEST_F(ScriptViewTest, ParentsWithRowsAreNotControls) +{ + const std::vector paths = view_.displayControlPaths(); + auto has = [&](const std::string& path) { + return std::ranges::find(paths, path) != paths.end(); + }; + EXPECT_TRUE(has("Layers/Implant")) << "no implant layers, so still a leaf"; + EXPECT_FALSE(has("Layers/Other")); + EXPECT_FALSE(has("Rows")); + EXPECT_FALSE(has("Nets")); + EXPECT_FALSE(has("Misc/Background")) << "it has no visible box"; + EXPECT_TRUE(std::ranges::is_sorted(paths)); + + EXPECT_THROW(view_.setDisplayControlVisible("Nets", false), + std::runtime_error); +} + +TEST_F(ScriptViewTest, WildcardsMatchAsInQt) +{ + view_.setDisplayControlVisible("*", false); + EXPECT_FALSE(view_.checkDisplayControlVisible("Nets/Signal")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Layers/metal1")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Timing Path/Legend")); + + // Case does not matter, and '*' crosses '/'. + view_.setDisplayControlVisible("nets/power", true); + EXPECT_TRUE(view_.checkDisplayControlVisible("Nets/Power")); + view_.setDisplayControlVisible("Instances/*", true); + EXPECT_TRUE(view_.checkDisplayControlVisible( + "Instances/StdCells/Clock tree/Clock gate")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Nets/Ground")); + + EXPECT_THROW(view_.setDisplayControlVisible("Bogus/*", true), + std::runtime_error); +} + +TEST_F(ScriptViewTest, CheckingSeveralControlsAtOnceIsFalse) +{ + EXPECT_FALSE(view_.checkDisplayControlVisible("Nets/*")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Bogus")); +} + +// With nothing changed, the tile renderer draws as it does by default, except +// that the layers Qt hides start hidden. +TEST_F(ScriptViewTest, DefaultsDrawLikeTheTileRendererDefaults) +{ + const TileVisibility vis = view_.frame().vis; + const TileVisibility defaults; + for (const char* key : { + "stdcells", "macros", "pad_input", "phys_fill", + "std_bufinv", "std_sequential", "net_signal", "net_power", + "routing", "routing_vias", "special_nets", "pins", + "pin_markers", "pin_names", "access_points", "regions", + "mfg_grid", "gcell_grid", "inst_names", "inst_pins", + "inst_pin_names", "blockages", "fills", "rows", + "tracks_pref", "detailed", "labels", + }) { + EXPECT_EQ(vis.flag(key), defaults.flag(key)) << key; + } + + EXPECT_TRUE(vis.has_visible_layers); + EXPECT_TRUE(vis.visible_layers.contains("metal1")); + EXPECT_TRUE(vis.visible_layers.contains("via9")); + EXPECT_FALSE(vis.visible_layers.contains("poly")); + EXPECT_FALSE(vis.visible_layers.contains("OVERLAP")); +} + +TEST_F(ScriptViewTest, ControlsMapOntoTheTileRenderer) +{ + view_.setDisplayControlVisible("Nets/Power", false); + view_.setDisplayControlVisible("Instances/StdCells/Sequential", false); + view_.setDisplayControlVisible("Shape Types/Pins", false); + view_.setDisplayControlVisible("Layers/metal2", false); + view_.setDisplayControlVisible("Rows/*", true); + TileVisibility vis = view_.frame().vis; + EXPECT_FALSE(vis.net_power); + EXPECT_TRUE(vis.net_ground); + EXPECT_FALSE(vis.std_sequential); + EXPECT_TRUE(vis.stdcells) << "the other std cell rows are still on"; + EXPECT_FALSE(vis.pins); + EXPECT_FALSE(vis.pin_markers); + EXPECT_FALSE(vis.visible_layers.contains("metal2")); + EXPECT_TRUE(vis.rows); + EXPECT_TRUE(vis.isSiteVisible("FreePDK45_38x28_10R_NP_162NW_34O")); + + view_.setDisplayControlVisible("Instances/StdCells/*", false); + view_.setDisplayControlVisible("Shape Types/Routing/*", false); + vis = view_.frame().vis; + EXPECT_FALSE(vis.stdcells); + EXPECT_FALSE(vis.routing); + EXPECT_TRUE(vis.special_nets); +} + +TEST_F(ScriptViewTest, RestoreBringsBackWhatWasSaved) +{ + view_.saveDisplayControls(); + view_.setDisplayControlVisible("*", false); + view_.setDisplayControlVisible("Tracks/Pref", true); + view_.restoreDisplayControls(); + EXPECT_TRUE(view_.checkDisplayControlVisible("Nets/Power")); + EXPECT_TRUE(view_.checkDisplayControlVisible("Layers/metal1")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Tracks/Pref")); +} + +TEST_F(ScriptViewTest, OnlyTheBackgroundColorIsKept) +{ + constexpr Painter::Color kWhite{255, 255, 255}; + view_.setDisplayControlColor("Misc/Background", kWhite); + EXPECT_EQ(view_.frame().background, kWhite); + EXPECT_NO_THROW(view_.setDisplayControlColor("Nets/Power", kWhite)); + EXPECT_THROW(view_.setDisplayControlColor("Bogus", kWhite), + std::runtime_error); +} + +// A renderer's controls are rows too, with its own defaults and exclusivity, +// and the web viewer's hook reads the same values. +TEST_F(ScriptViewTest, RendererControlsAreSharedWithTheHook) +{ + ControlsOnlyRenderer renderer; + renderer.addDisplayControl("A", true, {}, {"B"}); + renderer.addDisplayControl("B", false); + Gui::get()->registerRenderer(&renderer); + + EXPECT_TRUE(view_.checkDisplayControlVisible("Test Group/A")); + EXPECT_FALSE(view_.checkDisplayControlVisible("Test Group/B")); + const std::vector paths = view_.displayControlPaths(); + EXPECT_NE(std::ranges::find(paths, "Test Group/B"), paths.end()); + + view_.setDisplayControlVisible("Test Group/B", true); + view_.setDisplayControlVisible("Test Group/A", true); + EXPECT_FALSE(view_.checkDisplayControlVisible("Test Group/B")) + << "turning A on turns off what it excludes"; + + WebViewerHook hook; + hook.setRendererControls(&view_.rendererControls()); + hook.setDisplayControlVisible("Test Group/A", false); + EXPECT_FALSE(view_.checkDisplayControlVisible("Test Group/A")); + + Gui::get()->unregisterRenderer(&renderer); +} + +// With no Qt window the Gui's display-control calls land here, and a script +// view is not a backend: Gui::enabled() stays false. +TEST_F(ScriptViewTest, GuiRoutesToTheScriptView) +{ + Gui* gui = Gui::get(); + GuiBackend* previous = gui->getScriptView(); + gui->setScriptView(&view_); + + gui->setDisplayControlsVisible("Nets/Power", false); + EXPECT_FALSE(view_.checkDisplayControlVisible("Nets/Power")); + EXPECT_FALSE(gui->checkDisplayControlsVisible("Nets/Power")); + EXPECT_TRUE(Gui::hasViewer()); + EXPECT_FALSE(Gui::enabled()); + + gui->setScriptView(previous); +} + +// Renderers ask from the render threads: a path nobody registered draws, and +// setting one is no error. The display-control commands stay strict. +TEST_F(ScriptViewTest, RendererControlsAreLenient) +{ + Gui* gui = Gui::get(); + GuiBackend* previous = gui->getScriptView(); + gui->setScriptView(&view_); + + EXPECT_TRUE(gui->checkRendererControl("Nobody/Registered")); + EXPECT_NO_THROW(gui->setRendererControl("Nobody/Registered", false)); + EXPECT_FALSE(gui->checkRendererControl("Nobody/Registered")); + EXPECT_THROW(gui->setDisplayControlsVisible("Bogus/Control", true), + std::runtime_error); + + gui->setScriptView(previous); +} + +// As the browser's payload with no keys of their own: std_physical and +// std_other follow a stdcells option, unless given too. +TEST_F(ScriptViewTest, StdcellsTakesThePhysicalAndOtherCells) +{ + TileVisibility vis = view_.frame({{"stdcells", false}}).vis; + EXPECT_FALSE(vis.std_physical); + EXPECT_FALSE(vis.std_other); + vis = view_.frame({{"stdcells", false}, {"std_physical", true}}).vis; + EXPECT_TRUE(vis.std_physical); + EXPECT_FALSE(vis.std_other); +} + +} // namespace +} // namespace web diff --git a/src/web/test/cpp/TestTileGenerator.cpp b/src/web/test/cpp/TestTileGenerator.cpp index acf6e51322d..274137f4cd4 100644 --- a/src/web/test/cpp/TestTileGenerator.cpp +++ b/src/web/test/cpp/TestTileGenerator.cpp @@ -922,6 +922,18 @@ class TileGeneratorTest : public tst::Nangate45Fixture std::unique_ptr heatmap_; }; +// The overlay PNG goes over the browser's tiles, so no kind of cell may show +// through it. +TEST(OverlayVisibilityTest, HidesEveryInstanceCategory) +{ + const TileVisibility vis = overlayOnlyVisibility(); + for (int cat = static_cast(InstCategory::kStdCells); + cat <= static_cast(InstCategory::kStdOther); + ++cat) { + EXPECT_FALSE(vis.isCategoryVisible(static_cast(cat))) << cat; + } +} + TEST_F(TileGeneratorTest, HasStaFalseWhenNull) { makeTileGen(); diff --git a/test/regression.bzl b/test/regression.bzl index db33e106c88..f29a860500f 100644 --- a/test/regression.bzl +++ b/test/regression.bzl @@ -352,6 +352,7 @@ def regression_test( Args: name: The base name of the test (without extension). **kwargs: Additional keyword arguments to pass to the regression_rule_test. + `openroad` picks the binary to run, //:openroad by default. """ # TODO: we should _not_ have the magic to figure out if tcl or py exists @@ -370,6 +371,7 @@ def regression_test( size = _pop(kwargs, "size", "small") test_type = _pop(kwargs, "test_type", "") tags = _pop(kwargs, "tags", []) + openroad = _pop(kwargs, "openroad", "//:openroad") # Default every regression test to the GPU_ENV_OFF pin: on a GPU build # (--config=gpu) the runtime gate defaults on, and any test that runs @@ -398,7 +400,7 @@ def regression_test( test_type = effective_test_type, data = test_data, bazel_test_sh = "//test:bazel_test.sh", - openroad = "//:openroad", + openroad = openroad, regression_test = "//test:regression_test.sh", # top showed me 50-400mByte of usage, so "enormous" for # long running tests, but the OpenROAD tests are generally From d8630d6ddb4735eaffe35e5f69b26b733c36336e Mon Sep 17 00:00:00 2001 From: Jorge Ferreira Date: Thu, 22 Oct 2026 20:26:02 +0000 Subject: [PATCH 3/5] web: script view fixes from review 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 --- src/web/src/display_control_tree.cpp | 29 +++++++++++++++++----------- src/web/src/renderer_controls.cpp | 11 +++-------- src/web/src/renderer_controls.h | 5 ++--- src/web/src/script_view.cpp | 8 ++++++-- src/web/test/cpp/TestScriptView.cpp | 13 +++++++++++++ 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/web/src/display_control_tree.cpp b/src/web/src/display_control_tree.cpp index ad65508a000..7091f4d32df 100644 --- a/src/web/src/display_control_tree.cpp +++ b/src/web/src/display_control_tree.cpp @@ -177,24 +177,31 @@ void DisplayControlTree::addDesignRows(odb::dbDatabase* db) } } - // DisplayControls::libInit: a site starts as Rows is when it is added. + // DisplayControls::libInit: a site starts as Rows is when it is added, the + // same for every site added now. + auto rows_on = [this] { + if (const Leaf* rows = find(kRows)) { + return rows->visible.value_or(false); + } + bool on = true; + for (const auto& [path, leaf] : leaves_) { + if (path.starts_with(std::string(kRows) + "/")) { + on = on && leaf.visible.value_or(false); + } + } + return on; + }; + std::optional on; 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); - } - } + if (!on) { + on = rows_on(); + leaves_.erase(kRows); } - leaves_.erase(kRows); addLeaf(path, {.visible = on, .selectable = on}); } } diff --git a/src/web/src/renderer_controls.cpp b/src/web/src/renderer_controls.cpp index ec7644de240..e12279735b7 100644 --- a/src/web/src/renderer_controls.cpp +++ b/src/web/src/renderer_controls.cpp @@ -8,17 +8,12 @@ namespace web { -bool RendererControls::check(const std::string& path) const +bool RendererControls::check(const std::string& path, + const bool default_val) const { const std::scoped_lock lock(mutex_); const auto it = visible_.find(path); - return it == visible_.end() ? true : it->second; -} - -bool RendererControls::contains(const std::string& path) const -{ - const std::scoped_lock lock(mutex_); - return visible_.contains(path); + return it == visible_.end() ? default_val : it->second; } void RendererControls::set(const std::string& path, const bool value) diff --git a/src/web/src/renderer_controls.h b/src/web/src/renderer_controls.h index 85a008fab34..de71421e7c4 100644 --- a/src/web/src/renderer_controls.h +++ b/src/web/src/renderer_controls.h @@ -17,9 +17,8 @@ class RendererControls public: using Values = std::map; - // A path nobody set or seeded reads as visible. - bool check(const std::string& path) const; - bool contains(const std::string& path) const; + // A path nobody set or seeded reads as `default_val`. + bool check(const std::string& path, bool default_val = true) const; void set(const std::string& path, bool value); // Sets `path` unless it already has a value, so a renderer registering // again keeps what the user chose. diff --git a/src/web/src/script_view.cpp b/src/web/src/script_view.cpp index 9c43a558cc8..ee25a9fccfd 100644 --- a/src/web/src/script_view.cpp +++ b/src/web/src/script_view.cpp @@ -169,8 +169,12 @@ void ScriptView::setDisplayControlColor(const std::string& name, { const std::scoped_lock lock(mutex_); refreshLocked(); - bool found = !matchLocked(tree_, name, /*selectable=*/false).empty(); - bool ignored = false; + const std::vector matches + = matchLocked(tree_, name, /*selectable=*/false); + bool found = !matches.empty(); + // A renderer's control has no color here. + bool ignored = std::ranges::any_of( + matches, [](const Match& match) { return match.leaf == nullptr; }); for (const auto& [path, leaf] : tree_.leaves()) { if (!DisplayControlTree::matches(name, path)) { continue; diff --git a/src/web/test/cpp/TestScriptView.cpp b/src/web/test/cpp/TestScriptView.cpp index 8133fb8ab6c..31adb57e956 100644 --- a/src/web/test/cpp/TestScriptView.cpp +++ b/src/web/test/cpp/TestScriptView.cpp @@ -208,6 +208,19 @@ TEST_F(ScriptViewTest, RendererControlsAreSharedWithTheHook) Gui::get()->unregisterRenderer(&renderer); } +// Only Misc/Background has a color here; a renderer's control has none either. +TEST_F(ScriptViewTest, ARendererControlsColorIsIgnored) +{ + ControlsOnlyRenderer renderer; + renderer.addDisplayControl("A", true); + Gui::get()->registerRenderer(&renderer); + getLogger()->redirectStringBegin(); + view_.setDisplayControlColor("Test Group/A", Painter::kRed); + EXPECT_NE(getLogger()->redirectStringEnd().find("WEB-0129"), + std::string::npos); + Gui::get()->unregisterRenderer(&renderer); +} + // With no Qt window the Gui's display-control calls land here, and a script // view is not a backend: Gui::enabled() stays false. TEST_F(ScriptViewTest, GuiRoutesToTheScriptView) From bebb867eb4d94aec20e61a7e817056fa1c042d5d Mon Sep 17 00:00:00 2001 From: Jorge Ferreira Date: Wed, 4 Nov 2026 18:59:08 +0000 Subject: [PATCH 4/5] web: move two script view messages off master's WEB-126/127 The web server's fixes took those IDs on master. Signed-off-by: Jorge Ferreira --- src/web/src/script_view.cpp | 4 ++-- src/web/test/cpp/TestScriptView.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/web/src/script_view.cpp b/src/web/src/script_view.cpp index ee25a9fccfd..20b04dd654d 100644 --- a/src/web/src/script_view.cpp +++ b/src/web/src/script_view.cpp @@ -96,7 +96,7 @@ bool ScriptView::check(const std::string& name, const bool selectable) const std::vector matches = matchLocked(tree_, name, selectable); if (matches.empty()) { logger_->warn(utl::WEB, - 127, + 137, "Unable to find {} display control at {}.", columnName(selectable), name); @@ -128,7 +128,7 @@ void ScriptView::set(const std::string& name, const std::vector matches = matchLocked(tree_, name, selectable); if (matches.empty()) { logger_->error(utl::WEB, - 126, + 136, "Unable to find {} display control at {}.", columnName(selectable), name); diff --git a/src/web/test/cpp/TestScriptView.cpp b/src/web/test/cpp/TestScriptView.cpp index 31adb57e956..ad2eed204c1 100644 --- a/src/web/test/cpp/TestScriptView.cpp +++ b/src/web/test/cpp/TestScriptView.cpp @@ -62,7 +62,7 @@ TEST_F(ScriptViewTest, TheFirstCheckOfAParentWarns) { getLogger()->redirectStringBegin(); EXPECT_FALSE(view_.checkDisplayControlVisible("Rows")); - EXPECT_NE(getLogger()->redirectStringEnd().find("WEB-0127"), + EXPECT_NE(getLogger()->redirectStringEnd().find("WEB-0137"), std::string::npos); } From 33c418f4e9134f05ac4ee092a3ec30bfe7fd286f Mon Sep 17 00:00:00 2001 From: Jorge Ferreira Date: Tue, 17 Nov 2026 21:49:00 +0000 Subject: [PATCH 5/5] web: move four script view messages off master's WEB-128..131 Master took those IDs while this was in review. Signed-off-by: Jorge Ferreira --- openroad/web/src/script_view.cpp | 8 ++++---- openroad/web/test/cpp/TestScriptView.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/openroad/web/src/script_view.cpp b/openroad/web/src/script_view.cpp index 20b04dd654d..d1c3c908379 100644 --- a/openroad/web/src/script_view.cpp +++ b/openroad/web/src/script_view.cpp @@ -104,7 +104,7 @@ bool ScriptView::check(const std::string& name, const bool selectable) } if (matches.size() > 1) { logger_->warn(utl::WEB, - 128, + 140, "Found {} controls matching {} at {}.", matches.size(), name, @@ -187,11 +187,11 @@ void ScriptView::setDisplayControlColor(const std::string& name, } } if (!found) { - logger_->error(utl::WEB, 130, "Unable to find {} display control", name); + logger_->error(utl::WEB, 142, "Unable to find {} display control", name); } if (ignored) { logger_->warn(utl::WEB, - 129, + 141, "Without the Qt GUI only the {} color is used; ignoring it " "for {}.", kBackground, @@ -266,7 +266,7 @@ ScriptView::Frame ScriptView::frame( = matchLocked(tree, key, /*selectable=*/false); if (matches.empty()) { logger_->error(utl::WEB, - 131, + 143, "{} is neither a display control nor a display option.", key); } diff --git a/openroad/web/test/cpp/TestScriptView.cpp b/openroad/web/test/cpp/TestScriptView.cpp index ad2eed204c1..901adddb961 100644 --- a/openroad/web/test/cpp/TestScriptView.cpp +++ b/openroad/web/test/cpp/TestScriptView.cpp @@ -216,7 +216,7 @@ TEST_F(ScriptViewTest, ARendererControlsColorIsIgnored) Gui::get()->registerRenderer(&renderer); getLogger()->redirectStringBegin(); view_.setDisplayControlColor("Test Group/A", Painter::kRed); - EXPECT_NE(getLogger()->redirectStringEnd().find("WEB-0129"), + EXPECT_NE(getLogger()->redirectStringEnd().find("WEB-0141"), std::string::npos); Gui::get()->unregisterRenderer(&renderer); }