diff --git a/openroad/gpl/src/graphicsImpl.cpp b/openroad/gpl/src/graphicsImpl.cpp index 6d19a296733..fbe045d5b05 100644 --- a/openroad/gpl/src/graphicsImpl.cpp +++ b/openroad/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/openroad/gui/src/displayControls.cpp b/openroad/gui/src/displayControls.cpp index 208d71b3537..7ec2a9c3df8 100644 --- a/openroad/gui/src/displayControls.cpp +++ b/openroad/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/openroad/gui/src/displayControls.h b/openroad/gui/src/displayControls.h index 9429937e431..483820ed5b7 100644 --- a/openroad/gui/src/displayControls.h +++ b/openroad/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/openroad/gui/src/gui.cpp b/openroad/gui/src/gui.cpp index c5e67f3ee32..24ff3a6a5fc 100644 --- a/openroad/gui/src/gui.cpp +++ b/openroad/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/openroad/gui/src/gui.i b/openroad/gui/src/gui.i index 93421828063..3156ff2e5d2 100644 --- a/openroad/gui/src/gui.i +++ b/openroad/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/openroad/gui/test/BUILD b/openroad/gui/test/BUILD index cd436a53804..dd9416e2eae 100644 --- a/openroad/gui/test/BUILD +++ b/openroad/gui/test/BUILD @@ -9,6 +9,7 @@ package(features = ["layering_check"]) ALL_TESTS = [ "supported", "clocktree_virtual_clock", + "display_controls_parity", "dump_heatmap_headless", "no_window", "save_animated_gif_headless", @@ -16,8 +17,18 @@ 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", +] + PASSFAIL_TESTS = [ "clocktree_virtual_clock", + "display_controls_parity", "dump_heatmap_headless", "no_window", "save_animated_gif_headless", @@ -49,6 +60,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/openroad/gui/test/clocktree_virtual_clock.tcl b/openroad/gui/test/clocktree_virtual_clock.tcl index dc7aafeb318..a515ac3e5bb 100644 --- a/openroad/gui/test/clocktree_virtual_clock.tcl +++ b/openroad/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/openroad/gui/test/display_controls_parity.tcl b/openroad/gui/test/display_controls_parity.tcl new file mode 100644 index 00000000000..f371bbbccdf --- /dev/null +++ b/openroad/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/openroad/gui/test/no_window.tcl b/openroad/gui/test/no_window.tcl index b1d756abcbc..45945b390ee 100644 --- a/openroad/gui/test/no_window.tcl +++ b/openroad/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/openroad/gui/test/save_animated_gif_headless.tcl b/openroad/gui/test/save_animated_gif_headless.tcl index dd7a7187892..08c0cc19f55 100644 --- a/openroad/gui/test/save_animated_gif_headless.tcl +++ b/openroad/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/openroad/gui/test/save_image_headless.tcl b/openroad/gui/test/save_image_headless.tcl index 6fbcafea8ae..5e41fca3fc2 100644 --- a/openroad/gui/test/save_image_headless.tcl +++ b/openroad/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/openroad/web/BUILD b/openroad/web/BUILD index a1db829866e..faa8e8ee121 100644 --- a/openroad/web/BUILD +++ b/openroad/web/BUILD @@ -202,6 +202,7 @@ 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", @@ -210,9 +211,11 @@ cc_library( "src/group_report.h", "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", @@ -234,7 +237,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 //openroad/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/openroad/web/README.md b/openroad/web/README.md index d0af992ea49..710f92049e6 100644 --- a/openroad/web/README.md +++ b/openroad/web/README.md @@ -208,6 +208,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 | @@ -467,6 +469,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/openroad/web/include/web/core.h b/openroad/web/include/web/core.h index a05883e252f..c9c2e40268a 100644 --- a/openroad/web/include/web/core.h +++ b/openroad/web/include/web/core.h @@ -1133,6 +1133,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 @@ -1271,10 +1283,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); @@ -1421,6 +1438,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); @@ -1442,6 +1461,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; } @@ -1452,6 +1475,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 @@ -1508,6 +1536,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, @@ -1541,6 +1576,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/openroad/web/include/web/heatMap.h b/openroad/web/include/web/heatMap.h index f54fbd9df46..a022f116fdf 100644 --- a/openroad/web/include/web/heatMap.h +++ b/openroad/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/openroad/web/include/web/web.h b/openroad/web/include/web/web.h index 6476d5a57e2..1dbb9c99d48 100644 --- a/openroad/web/include/web/web.h +++ b/openroad/web/include/web/web.h @@ -43,6 +43,7 @@ struct Color; class Search; class ClockTreeReport; +class ScriptView; class TileGenerator; struct TclEvaluator; class TimingReport; @@ -460,6 +461,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/openroad/web/src/display_control_tree.cpp b/openroad/web/src/display_control_tree.cpp new file mode 100644 index 00000000000..7091f4d32df --- /dev/null +++ b/openroad/web/src/display_control_tree.cpp @@ -0,0 +1,297 @@ +// 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, 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; + } + if (!on) { + on = rows_on(); + 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/openroad/web/src/display_control_tree.h b/openroad/web/src/display_control_tree.h new file mode 100644 index 00000000000..fe8a37cc81f --- /dev/null +++ b/openroad/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/openroad/web/src/guiDispatch.cpp b/openroad/web/src/guiDispatch.cpp index 840146fcf27..3ebd23622d2 100644 --- a/openroad/web/src/guiDispatch.cpp +++ b/openroad/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/openroad/web/src/heatMapCore.cpp b/openroad/web/src/heatMapCore.cpp index 8a022270419..998df253ea2 100644 --- a/openroad/web/src/heatMapCore.cpp +++ b/openroad/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/openroad/web/src/renderer.cpp b/openroad/web/src/renderer.cpp index 3e629502f2d..770e98289c7 100644 --- a/openroad/web/src/renderer.cpp +++ b/openroad/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/openroad/web/src/renderer_controls.cpp b/openroad/web/src/renderer_controls.cpp new file mode 100644 index 00000000000..e12279735b7 --- /dev/null +++ b/openroad/web/src/renderer_controls.cpp @@ -0,0 +1,53 @@ +// 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 bool default_val) const +{ + const std::scoped_lock lock(mutex_); + const auto it = visible_.find(path); + return it == visible_.end() ? default_val : it->second; +} + +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/openroad/web/src/renderer_controls.h b/openroad/web/src/renderer_controls.h new file mode 100644 index 00000000000..de71421e7c4 --- /dev/null +++ b/openroad/web/src/renderer_controls.h @@ -0,0 +1,52 @@ +// 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 `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. + 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/openroad/web/src/script_view.cpp b/openroad/web/src/script_view.cpp new file mode 100644 index 00000000000..d1c3c908379 --- /dev/null +++ b/openroad/web/src/script_view.cpp @@ -0,0 +1,287 @@ +// 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, + 137, + "Unable to find {} display control at {}.", + columnName(selectable), + name); + return false; + } + if (matches.size() > 1) { + logger_->warn(utl::WEB, + 140, + "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, + 136, + "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(); + 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; + } + found = true; + if (path == kBackground) { + background_ = color; + } else { + ignored = true; + } + } + if (!found) { + logger_->error(utl::WEB, 142, "Unable to find {} display control", name); + } + if (ignored) { + logger_->warn(utl::WEB, + 141, + "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, + 143, + "{} 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/openroad/web/src/script_view.h b/openroad/web/src/script_view.h new file mode 100644 index 00000000000..39b3db6d98c --- /dev/null +++ b/openroad/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/openroad/web/src/tile_generator.cpp b/openroad/web/src/tile_generator.cpp index e209a1a3cc4..58e2ccc2b3f 100644 --- a/openroad/web/src/tile_generator.cpp +++ b/openroad/web/src/tile_generator.cpp @@ -1103,6 +1103,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}, @@ -1159,6 +1161,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 @@ -1167,6 +1204,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() @@ -1286,6 +1325,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; @@ -1459,9 +1501,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; } @@ -1577,6 +1621,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; } @@ -1632,6 +1680,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; } @@ -6957,6 +7009,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, @@ -7007,45 +7105,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/openroad/web/src/tile_generator.h b/openroad/web/src/tile_generator.h index b737894e7f7..0747a456bbc 100644 --- a/openroad/web/src/tile_generator.h +++ b/openroad/web/src/tile_generator.h @@ -267,6 +267,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); @@ -306,6 +308,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; @@ -474,6 +480,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; @@ -510,6 +518,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; @@ -522,6 +535,9 @@ struct TileVisibility 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/openroad/web/src/web.cpp b/openroad/web/src/web.cpp index b3cc4383d6d..fdc4a31d9b1 100644 --- a/openroad/web/src/web.cpp +++ b/openroad/web/src/web.cpp @@ -49,9 +49,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" @@ -566,25 +568,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 @@ -610,7 +616,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()) { @@ -645,12 +650,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; @@ -688,7 +703,7 @@ void applyRendererControlExclusivity(WebViewerHook* hook, if (control_path == path) { continue; } - hook->setDisplayControlVisible(control_path, false); + controls.set(control_path, false); } } } @@ -908,10 +923,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( @@ -1764,8 +1776,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) @@ -1837,6 +1851,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/openroad/web/src/web_serve.cpp b/openroad/web/src/web_serve.cpp index 0fa160540ec..f0c49081c99 100644 --- a/openroad/web/src/web_serve.cpp +++ b/openroad/web/src/web_serve.cpp @@ -54,6 +54,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" @@ -303,6 +304,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()); @@ -514,6 +517,11 @@ void WebServer::serve(int port, } 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/openroad/web/src/web_viewer_hook.cpp b/openroad/web/src/web_viewer_hook.cpp index 5f852329ed5..c53c6b7b48a 100644 --- a/openroad/web/src/web_viewer_hook.cpp +++ b/openroad/web/src/web_viewer_hook.cpp @@ -321,31 +321,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/openroad/web/src/web_viewer_hook.h b/openroad/web/src/web_viewer_hook.h index 291a53247c3..d91b04ef58f 100644 --- a/openroad/web/src/web_viewer_hook.h +++ b/openroad/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 { @@ -115,27 +114,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. @@ -308,9 +303,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}; }; @@ -324,12 +318,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/openroad/web/test/BUILD b/openroad/web/test/BUILD index e1a938cc8f9..c8dd677ca77 100644 --- a/openroad/web/test/BUILD +++ b/openroad/web/test/BUILD @@ -80,6 +80,7 @@ test_suite( ":interconnect3d_test", ":request_handler_test", ":save_display_controls_test", + ":script_view_test", ":session_lifetime_test", ":tile_generator_test", ":web_assets_test", @@ -571,6 +572,22 @@ cc_test( ], ) +cc_test( + name = "script_view_test", + srcs = ["cpp/TestScriptView.cpp"], + data = [ + "//test:nangate45_data", + ], + deps = [ + "//openroad/odb/src/db", + "//openroad/tst:nangate45_fixture", + "//openroad/web", + "//openroad/web:core", + "@googletest//:gtest", + "@googletest//:gtest_main", + ], +) + cc_test( name = "snap_test", srcs = ["cpp/TestSnap.cpp"], diff --git a/openroad/web/test/cpp/TestDebugGraphics.cpp b/openroad/web/test/cpp/TestDebugGraphics.cpp index 7c8f4b7824d..001bd8ea4d4 100644 --- a/openroad/web/test/cpp/TestDebugGraphics.cpp +++ b/openroad/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" @@ -544,8 +545,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")); } @@ -558,19 +559,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/openroad/web/test/cpp/TestHeatMap.cpp b/openroad/web/test/cpp/TestHeatMap.cpp index baf539cce9b..73d0e9eb311 100644 --- a/openroad/web/test/cpp/TestHeatMap.cpp +++ b/openroad/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/openroad/web/test/cpp/TestSaveDisplayControls.cpp b/openroad/web/test/cpp/TestSaveDisplayControls.cpp index 5c313b74a3d..1f497b2df43 100644 --- a/openroad/web/test/cpp/TestSaveDisplayControls.cpp +++ b/openroad/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/openroad/web/test/cpp/TestScriptView.cpp b/openroad/web/test/cpp/TestScriptView.cpp new file mode 100644 index 00000000000..901adddb961 --- /dev/null +++ b/openroad/web/test/cpp/TestScriptView.cpp @@ -0,0 +1,271 @@ +// 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-0137"), + 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); +} + +// 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-0141"), + 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) +{ + 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/openroad/web/test/cpp/TestTileGenerator.cpp b/openroad/web/test/cpp/TestTileGenerator.cpp index c3995f443d0..645a6e10e58 100644 --- a/openroad/web/test/cpp/TestTileGenerator.cpp +++ b/openroad/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 3666cb5c508..17744b0efac 100644 --- a/test/regression.bzl +++ b/test/regression.bzl @@ -354,6 +354,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 @@ -372,6 +373,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 @@ -400,7 +402,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