EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
echomap::ChannelMappingPanel Class Referencefinal

Provides a panel for defining mappings between Signal and Sensor objects. More...

#include <ChannelMappingPanel.hpp>

Inheritance diagram for echomap::ChannelMappingPanel:
[legend]

Classes

struct  AddChannelMappingRowCache

Public Member Functions

 ChannelMappingPanel (EchoMap *app, const Project *initial_project=nullptr)
 Create a new ChannelMappingPanel to describe and configure Signal-Sensor mappings.
const char * get_imgui_name () const noexcept override
 Retrieves the name of the IPanel for Dear ImGui API functions.
void draw () noexcept override
 Draw the panel to the active rendering context.
void change_active_project (const Project *new_project) override
 Updates the active Project being described by the IPanel.
Public Member Functions inherited from echomap::IPanel
virtual void update_gpu (const wgpu::CommandEncoder &command_encoder)
 Delegate work to the GPU via the WebGPU platform.

Static Public Member Functions

static const char * get_imgui_stable_name () noexcept

Private Member Functions

void draw_new_channel_mapping () noexcept
void draw_existing_channel_mapping () const noexcept

Private Attributes

std::string panel_name
struct echomap::ChannelMappingPanel::AddChannelMappingRowCache new_entry_cache
EchoMapapp
const Projectactive_project = nullptr
std::vector< sigc::scoped_connection > connections

Additional Inherited Members

Static Protected Attributes inherited from echomap::IPanel
static constexpr ImVec2 button_size {80.0f, 20.0f}
static constexpr auto table_flags

Detailed Description

Provides a panel for defining mappings between Signal and Sensor objects.

Definition at line 25 of file ChannelMappingPanel.hpp.

Constructor & Destructor Documentation

◆ ChannelMappingPanel()

echomap::ChannelMappingPanel::ChannelMappingPanel ( EchoMap * app,
const Project * initial_project = nullptr )
explicit

Create a new ChannelMappingPanel to describe and configure Signal-Sensor mappings.

Parameters
appThe parent application instance.
initial_projectAn optional initial Project for the IPanel to display.

Definition at line 16 of file ChannelMappingPanel.cpp.

19 :
20 panel_name(std::string("Channel Mapping") + get_imgui_stable_name()),
21 app(app),
22 active_project(initial_project)
23{
24}

Member Function Documentation

◆ change_active_project()

void echomap::ChannelMappingPanel::change_active_project ( const Project * new_project)
overridevirtual

Updates the active Project being described by the IPanel.

Parameters
new_projectAn observing pointer to the new active Project.

Implements echomap::IProjectPanel.

Definition at line 60 of file ChannelMappingPanel.cpp.

63{
64 active_project = new_project;
65}

◆ draw()

void echomap::ChannelMappingPanel::draw ( )
overridevirtualnoexcept

Draw the panel to the active rendering context.

Implements echomap::IPanel.

Definition at line 31 of file ChannelMappingPanel.cpp.

32{
33 if (ImGui::Begin(panel_name.c_str())) {
34 if (active_project == nullptr)
35 ImGui::Text("No project is loaded.");
36 else {
37 ImGui::SeparatorText("Create Channel Mapping");
38 draw_new_channel_mapping();
39
40 // If a new mapping has been fully described, add it and prompt for another.
41 if (new_entry_cache.signal != nullptr && new_entry_cache.sensor != nullptr) {
42 app->notify(AddChannelMappingNotification(
43 active_project->get_id(),
44 new_entry_cache.signal->get_id(),
45 new_entry_cache.sensor->get_id()
46 ));
47
48 new_entry_cache.signal = nullptr;
49 new_entry_cache.sensor = nullptr;
50 }
51
52 ImGui::SeparatorText("Existing Channel Mapping");
53 draw_existing_channel_mapping();
54 }
55 }
56
57 ImGui::End();
58}

◆ draw_existing_channel_mapping()

void echomap::ChannelMappingPanel::draw_existing_channel_mapping ( ) const
privatenoexcept

Definition at line 138 of file ChannelMappingPanel.cpp.

139{
140 if (ImGui::BeginTable("##ExistingChannelMapping", 2, table_flags)) {
141 ImGui::TableSetupColumn("Signal", ImGuiTableColumnFlags_WidthStretch);
142 ImGui::TableSetupColumn("Sensor", ImGuiTableColumnFlags_WidthStretch);
143 ImGui::TableHeadersRow();
144
145 // Display existing associations.
146 for (const auto& [signal, sensor] : active_project->observe_associations()) {
147 ImGui::TableNextRow();
148 ImGui::TableNextColumn();
149 ImGui::SetNextItemWidth(-std::numeric_limits<float>::min());
150 ImGui::TextUnformatted(signal.get_imgui_name());
151 ImGui::TableNextColumn();
152 ImGui::SetNextItemWidth(-std::numeric_limits<float>::min());
153 ImGui::TextUnformatted(sensor.get_imgui_name());
154 }
155
156 ImGui::EndTable();
157 }
158}
T min(T... args)
T signal(T... args)

◆ draw_new_channel_mapping()

void echomap::ChannelMappingPanel::draw_new_channel_mapping ( )
privatenoexcept

Definition at line 72 of file ChannelMappingPanel.cpp.

73{
74 // TODO refactor monster.
75
76 if (ImGui::BeginTable("##NewChannelMapping", 2, table_flags)) {
77 ImGui::TableSetupColumn("Signal", ImGuiTableColumnFlags_WidthStretch);
78 ImGui::TableSetupColumn("Sensor", ImGuiTableColumnFlags_WidthStretch);
79 ImGui::TableHeadersRow();
80 ImGui::TableNextRow();
81 ImGui::TableNextColumn();
82
83 bool need_to_force = false;
84
85 // Prompt for the associated signal.
86 ImGui::SetNextItemWidth(-std::numeric_limits<float>::min());
87 if (ImGui::BeginCombo(
88 "##NewAssociationSignal",
89 new_entry_cache.signal == nullptr ? "Select signal..." : new_entry_cache.signal->get_imgui_name(),
90 0
91 )) {
92 for (const auto& signal : active_project->observe_signals()) {
93 const bool is_selected = new_entry_cache.signal == nullptr ? false : signal == *new_entry_cache.signal;
94
95 // Checks if something has changed (thus current value needs updating).
96 if (ImGui::Selectable(signal.get_imgui_name(), is_selected))
97 new_entry_cache.signal = &signal;
98
99 // Checks if the current item is selected.
100 if (is_selected)
101 ImGui::SetItemDefaultFocus();
102 }
103
104 ImGui::EndCombo();
105 need_to_force = true;
106 }
107
108 ImGui::TableNextColumn();
109
110 // Prompt for the associated sensor.
111 ImGui::SetNextItemWidth(-std::numeric_limits<float>::min());
112 if (ImGui::BeginCombo(
113 "##NewAssociationSensor",
114 new_entry_cache.sensor == nullptr ? "Select sensor..." : new_entry_cache.sensor->get_imgui_name(),
115 0
116 )) {
117 for (const auto& sensor : active_project->observe_sensors()) {
118 const bool is_selected = new_entry_cache.sensor == nullptr ? false : sensor == *new_entry_cache.sensor;
119
120 if (ImGui::Selectable(sensor.get_imgui_name(), is_selected))
121 new_entry_cache.sensor = &sensor;
122
123 if (is_selected)
124 ImGui::SetItemDefaultFocus();
125 }
126
127 ImGui::EndCombo();
128 need_to_force = true;
129 }
130
131 ImGui::EndTable();
132
133 if (need_to_force)
134 app->increment_forced_frames();
135 }
136}

◆ get_imgui_name()

const char * echomap::ChannelMappingPanel::get_imgui_name ( ) const
nodiscardoverridevirtualnoexcept

Retrieves the name of the IPanel for Dear ImGui API functions.

Returns
The human-readable name of the window as a NULL-terminated C string.

Implements echomap::IPanel.

Definition at line 26 of file ChannelMappingPanel.cpp.

27{
28 return panel_name.c_str();
29}

◆ get_imgui_stable_name()

const char * echomap::ChannelMappingPanel::get_imgui_stable_name ( )
staticnoexcept

Definition at line 67 of file ChannelMappingPanel.cpp.

68{
69 return "###ChannelMappingPanel";
70}

Member Data Documentation

◆ active_project

const Project* echomap::ChannelMappingPanel::active_project = nullptr
private

Definition at line 60 of file ChannelMappingPanel.hpp.

◆ app

EchoMap* echomap::ChannelMappingPanel::app
private

Definition at line 59 of file ChannelMappingPanel.hpp.

◆ connections

std::vector<sigc::scoped_connection> echomap::ChannelMappingPanel::connections
private

Definition at line 61 of file ChannelMappingPanel.hpp.

◆ panel_name

std::string echomap::ChannelMappingPanel::panel_name
private

Definition at line 51 of file ChannelMappingPanel.hpp.


The documentation for this class was generated from the following files: