1111#include < set>
1212#include < string>
1313#include < typeinfo>
14+ #include < utility>
1415#include < vector>
1516
1617#include " bufferTreeDescriptor.h"
@@ -46,20 +47,34 @@ Gui* gui::Gui::get()
4647}
4748
4849bool gui::Gui::enabled ()
50+ {
51+ return Gui::get ()->getHeadlessViewer () != nullptr ;
52+ }
53+
54+ bool gui::Gui::hasUI ()
4955{
5056 return false ;
5157}
5258
53- void gui::Gui::registerRenderer (gui::Renderer*)
59+ void gui::Gui::registerRenderer (gui::Renderer* renderer )
5460{
61+ renderers_.insert (renderer);
62+ redraw ();
5563}
5664
5765void HeatMapDataSource::registerHeatMap ()
5866{
67+ // gpl / other modules call this to expose their heatmap to the GUI.
68+ // In headless mode the web viewer enumerates heatmaps via
69+ // gui::getRegisteredHeatMapSources() (factory-backed sources) so this
70+ // one-off pathway does nothing here for now. Left intentionally as
71+ // a no-op until heatmap plumbing for ad-hoc sources lands.
5972}
6073
61- void gui::Gui::unregisterRenderer (gui::Renderer*)
74+ void gui::Gui::unregisterRenderer (gui::Renderer* renderer )
6275{
76+ renderers_.erase (renderer);
77+ redraw ();
6378}
6479
6580void gui::Gui::zoomTo (const odb::Rect& rect_dbu)
@@ -68,10 +83,26 @@ void gui::Gui::zoomTo(const odb::Rect& rect_dbu)
6883
6984void gui::Gui::redraw ()
7085{
86+ if (headless_viewer_ != nullptr ) {
87+ headless_viewer_->redraw ();
88+ }
7189}
7290
7391void gui::Gui::pause (int timeout)
7492{
93+ if (headless_viewer_ != nullptr ) {
94+ headless_viewer_->pause (timeout);
95+ }
96+ }
97+
98+ void gui::Gui::setHeadlessViewer (HeadlessViewer* viewer)
99+ {
100+ headless_viewer_ = viewer;
101+ }
102+
103+ void gui::Gui::setChartFactory (ChartFactory factory)
104+ {
105+ chart_factory_ = std::move (factory);
75106}
76107
77108void Gui::status (const std::string& /* message */ )
@@ -84,9 +115,13 @@ void Gui::triggerAction(const std::string& /* action */)
84115
85116void Renderer::redraw ()
86117{
118+ Gui::get ()->redraw ();
87119}
88120
89- Renderer::~Renderer () = default ;
121+ Renderer::~Renderer ()
122+ {
123+ Gui::get ()->unregisterRenderer (this );
124+ }
90125
91126void DiscreteLegend::addLegendKey (const Painter::Color& color,
92127 const std::string& text)
@@ -97,17 +132,27 @@ void DiscreteLegend::draw(Painter& painter) const
97132{
98133}
99134
100- bool Renderer::checkDisplayControl (const std::string& /* name */ )
135+ bool Renderer::checkDisplayControl (const std::string& name)
101136{
137+ auto it = controls_.find (name);
138+ if (it != controls_.end ()) {
139+ return it->second .visibility ;
140+ }
102141 return false ;
103142}
104143
105144void Renderer::addDisplayControl (
106- const std::string& /* name */ ,
107- bool /* initial_visible */ ,
108- const DisplayControlCallback& /* setup */ ,
109- const std::vector<std::string>& /* mutual_exclusivity */ )
145+ const std::string& name,
146+ bool initial_visible,
147+ const DisplayControlCallback& setup,
148+ const std::vector<std::string>& mutual_exclusivity)
110149{
150+ DisplayControl control;
151+ control.visibility = initial_visible;
152+ control.interactive_setup = setup;
153+ control.mutual_exclusivity .insert (mutual_exclusivity.begin (),
154+ mutual_exclusivity.end ());
155+ controls_[name] = std::move (control);
111156}
112157
113158Renderer::Settings Renderer::getSettings ()
@@ -241,6 +286,9 @@ Chart* Gui::addChart(const std::string& name,
241286 const std::string& x_label,
242287 const std::vector<std::string>& y_labels)
243288{
289+ if (chart_factory_) {
290+ return chart_factory_ (name, x_label, y_labels);
291+ }
244292 return nullptr ;
245293}
246294
0 commit comments