3333#include " mainwindow/rendering/lightpathspickinghandler.h"
3434#include " mainwindow/rendering/lightpathslayer.h"
3535#include " mainwindow/rendering/viewporttab.h"
36- #include " mainwindow/rendering/viewportwidget.h"
3736#include " utility/miscellaneous.h"
3837#include " utility/settingskeys.h"
3938
@@ -77,9 +76,11 @@ namespace studio {
7776
7877LightPathsViewportManager::LightPathsViewportManager (
7978 ViewportTab* viewport_tab,
80- Project& project,
79+ Project* project,
8180 ParamArray& settings)
8281 : m_enabled(false )
82+ , m_picking_enabled(true )
83+ , m_paths_display_active(false )
8384 , m_project(project)
8485 , m_settings(settings)
8586 , m_viewport_tab(viewport_tab)
@@ -94,15 +95,49 @@ LightPathsViewportManager::LightPathsViewportManager(
9495 recreate_handlers ();
9596}
9697
98+ void LightPathsViewportManager::reset (renderer::Project* project)
99+ {
100+ set_enabled (false );
101+ set_display_enabled (false );
102+ set_picking_enabled (true );
103+ m_project = project;
104+ }
105+
106+ void LightPathsViewportManager::slot_base_layer_changed (const ViewportWidget::BaseLayer layer)
107+ {
108+ if (layer == ViewportWidget::BaseLayer::FinalRender)
109+ set_picking_enabled (true );
110+ else
111+ set_picking_enabled (false );
112+ }
113+
97114void LightPathsViewportManager::set_enabled (const bool enabled)
98115{
99116 m_enabled = enabled;
100117 if (enabled)
118+ {
101119 m_toolbar->show ();
120+ }
102121 else
122+ {
123+ set_display_enabled (false );
103124 m_toolbar->hide ();
104-
125+ }
105126 m_toolbar->setDisabled (!enabled);
127+
128+ emit signal_should_display (m_enabled && m_paths_display_active);
129+ }
130+
131+ void LightPathsViewportManager::set_display_enabled (const bool enabled)
132+ {
133+ m_paths_display_active = enabled;
134+
135+ emit signal_should_display (m_enabled && m_paths_display_active);
136+ }
137+
138+ void LightPathsViewportManager::set_picking_enabled (const bool enabled)
139+ {
140+ m_picking_enabled = enabled;
106141 m_screen_space_paths_picking_handler->set_enabled (enabled);
107142}
108143
@@ -113,9 +148,11 @@ QToolBar* LightPathsViewportManager::toolbar() const
113148
114149void LightPathsViewportManager::slot_entity_picked (const ScenePicker::PickingResult& result)
115150{
116- if (!m_enabled) return ;
151+ if (!m_picking_enabled || ! m_enabled) return ;
117152
118- const CanvasProperties& props = m_project.get_frame ()->image ().properties ();
153+ set_display_enabled (true );
154+
155+ const CanvasProperties& props = m_project->get_frame ()->image ().properties ();
119156 m_screen_space_paths_picking_handler->pick (
120157 Vector2i (
121158 result.m_ndc [0 ] * static_cast <int >(props.m_canvas_width ),
@@ -129,8 +166,9 @@ void LightPathsViewportManager::slot_light_paths_display_toggled(const bool acti
129166
130167void LightPathsViewportManager::slot_rectangle_selection (const QRect& rect)
131168{
132- if (!m_enabled) return ;
169+ if (!m_picking_enabled || ! m_enabled) return ;
133170
171+ set_display_enabled (true );
134172 m_screen_space_paths_picking_handler->pick (
135173 AABB2i (
136174 Vector2i (rect.x (), rect.y ()),
@@ -139,15 +177,17 @@ void LightPathsViewportManager::slot_rectangle_selection(const QRect& rect)
139177
140178void LightPathsViewportManager::slot_light_path_selection_changed (
141179 const int selected_light_path_index,
142- const int total_light_paths) const
180+ const int total_light_paths)
143181{
144182 if (total_light_paths > 0 )
145183 {
184+ set_display_enabled (true );
146185 m_prev_path_button->setEnabled (selected_light_path_index > -1 );
147186 m_next_path_button->setEnabled (selected_light_path_index < total_light_paths - 1 );
148187 }
149188 else
150189 {
190+ set_display_enabled (false );
151191 m_prev_path_button->setEnabled (false );
152192 m_next_path_button->setEnabled (false );
153193 }
@@ -172,7 +212,7 @@ void LightPathsViewportManager::slot_save_light_paths()
172212 filepath = QDir::toNativeSeparators (filepath);
173213
174214 // Write light paths to disk.
175- m_project. get_light_path_recorder ().write (filepath.toUtf8 ().constData ());
215+ m_project-> get_light_path_recorder ().write (filepath.toUtf8 ().constData ());
176216}
177217
178218void LightPathsViewportManager::slot_camera_changed ()
@@ -192,7 +232,7 @@ void LightPathsViewportManager::create_toolbar()
192232 // Save Light Paths button.
193233 QToolButton* save_light_paths_button = new QToolButton ();
194234 save_light_paths_button->setIcon (load_icons (" lightpathstab_save_light_paths" ));
195- const auto light_path_count = m_project. get_light_path_recorder ().get_light_path_count ();
235+ const auto light_path_count = m_project-> get_light_path_recorder ().get_light_path_count ();
196236 save_light_paths_button->setToolTip (
197237 QString (" Save %1 Light Path%2..." )
198238 .arg (QString::fromStdString (pretty_uint (light_path_count)))
@@ -233,8 +273,8 @@ void LightPathsViewportManager::create_toolbar()
233273 backface_culling_button->setCheckable (true );
234274 backface_culling_button->setChecked (false );
235275 connect (
236- backface_culling_button, SIGNAL (toggled ()),
237- light_paths_layer, SLOT (slot_toggle_backface_culling ()));
276+ backface_culling_button, SIGNAL (toggled (bool )),
277+ light_paths_layer, SLOT (slot_toggle_backface_culling (bool )));
238278 m_toolbar->addWidget (backface_culling_button);
239279
240280 // Synchronize Camera button.
@@ -268,7 +308,7 @@ void LightPathsViewportManager::recreate_handlers()
268308 new LightPathsPickingHandler (
269309 m_viewport_tab->get_viewport_widget (),
270310 *m_mouse_tracker.get (),
271- m_project));
311+ * m_project));
272312 m_screen_space_paths_picking_handler->set_enabled (false );
273313
274314 // The world-space paths picking handler is used to pick paths in the light paths widget.
0 commit comments