1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-23 02:38:52 -05:00

Added removal dialogs for both spectra and cuts. Lightly tested.

This commit is contained in:
Gordon McCann 2022-01-23 20:45:31 -05:00
parent 37e10eae1f
commit 343424ead7
7 changed files with 127 additions and 9 deletions

View File

@ -22,6 +22,7 @@ namespace Navigator {
virtual ~Application(); virtual ~Application();
void Run(); void Run();
inline void Close() { m_runFlag = false; }
void OnEvent(Event& event); void OnEvent(Event& event);
void PushLayer(Layer* layer); void PushLayer(Layer* layer);

View File

@ -97,6 +97,10 @@ namespace Navigator {
{ {
m_map[params.name].reset(new Cut2D(params, xpoints, ypoints)); m_map[params.name].reset(new Cut2D(params, xpoints, ypoints));
} }
inline void RemoveCut(const std::string& name)
{
m_map.erase(name);
}
void DrawCut(const std::string& name); void DrawCut(const std::string& name);
bool IsInsideCut(const std::string& name, double xval, double yval = 0); bool IsInsideCut(const std::string& name, double xval, double yval = 0);

View File

@ -8,7 +8,7 @@
namespace Navigator { namespace Navigator {
EditorLayer::EditorLayer() : EditorLayer::EditorLayer() :
Layer("EditorLayer"), m_spectrumPanel() Layer("EditorLayer"), m_removeHistogram(false), m_removeCut(false)
{ {
} }
@ -85,13 +85,14 @@ namespace Navigator {
{ {
m_fileDialog.SetOpenFileDialog(true); m_fileDialog.SetOpenFileDialog(true);
} }
if(ImGui::MenuItem("Exit"))
{
}
if(ImGui::MenuItem("Save")) if(ImGui::MenuItem("Save"))
{ {
m_fileDialog.SetSaveFileDialog(true); m_fileDialog.SetSaveFileDialog(true);
} }
if (ImGui::MenuItem("Exit"))
{
Application::Get().Close();
}
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Data Source")) if (ImGui::BeginMenu("Data Source"))
@ -119,9 +120,11 @@ namespace Navigator {
{ {
if (ImGui::MenuItem("Spectrum")) if (ImGui::MenuItem("Spectrum"))
{ {
m_removeHistogram = true;
} }
if (ImGui::MenuItem("Cut")) if (ImGui::MenuItem("Cut"))
{ {
m_removeCut = true;
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -147,6 +150,10 @@ namespace Navigator {
m_sourceDialog.ImGuiRenderSourceDialog(); m_sourceDialog.ImGuiRenderSourceDialog();
RemoveHistogramDialog();
RemoveCutDialog();
m_spectrumPanel.OnImGuiRender(); m_spectrumPanel.OnImGuiRender();
if (ImGui::Begin("Spectra")) if (ImGui::Begin("Spectra"))
@ -199,4 +206,74 @@ namespace Navigator {
ImGui::End(); ImGui::End();
} }
void EditorLayer::RemoveHistogramDialog()
{
HistogramMap& histMap = HistogramMap::GetInstance();
static std::string selectedGram = "";
if (m_removeHistogram)
{
selectedGram = "";
m_removeHistogram = false;
ImGui::OpenPopup("Remove Histogram");
}
if (ImGui::BeginPopupModal("Remove Histogram"))
{
if (ImGui::BeginCombo("Histogram", selectedGram.c_str()))
{
for (auto& gram : histMap)
{
if (ImGui::Selectable(gram.second->GetName().c_str(), gram.second->GetName() == selectedGram, ImGuiSelectableFlags_DontClosePopups))
selectedGram = gram.second->GetName();
}
ImGui::EndPopup();
}
if (ImGui::Button("Ok"))
{
histMap.RemoveHistogram(selectedGram);
ImGui::CloseCurrentPopup();
}
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
void EditorLayer::RemoveCutDialog()
{
HistogramMap& histMap = HistogramMap::GetInstance();
CutMap& cutMap = CutMap::GetInstance();
static std::string selectedCut = "";
if (m_removeCut)
{
selectedCut = "";
m_removeCut = false;
ImGui::OpenPopup("Remove Cut");
}
if (ImGui::BeginPopupModal("Remove Cut"))
{
if (ImGui::BeginCombo("Cut", selectedCut.c_str()))
{
for (auto& cut : cutMap)
{
if (ImGui::Selectable(cut.second->GetName().c_str(), cut.second->GetName() == selectedCut, ImGuiSelectableFlags_DontClosePopups))
selectedCut = cut.second->GetName();
}
ImGui::EndCombo();
}
if (ImGui::Button("Ok"))
{
histMap.RemoveCutFromHistograms(selectedCut);
cutMap.RemoveCut(selectedCut);
ImGui::CloseCurrentPopup();
}
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
} }

View File

@ -31,6 +31,9 @@ namespace Navigator {
private: private:
void RemoveCutDialog();
void RemoveHistogramDialog();
EventCallbackFunc m_callbackFunc; EventCallbackFunc m_callbackFunc;
SpectrumPanel m_spectrumPanel; SpectrumPanel m_spectrumPanel;
@ -45,7 +48,8 @@ namespace Navigator {
ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
bool m_removeHistogram;
bool m_removeCut;
}; };
} }

View File

@ -50,7 +50,7 @@ namespace Navigator {
virtual void ClearData() {} virtual void ClearData() {}
inline virtual bool Is1D() const { return false; } inline virtual bool Is1D() const { return false; }
inline virtual bool Is2D() const { return false; } inline virtual bool Is2D() const { return false; }
inline const HistogramParameters& GetParameters() const { return m_params; } inline HistogramParameters& GetParameters() { return m_params; }
inline const std::string& GetXParam() const { return m_params.x_par; }; inline const std::string& GetXParam() const { return m_params.x_par; };
inline const std::string& GetYParam() const { return m_params.y_par; }; inline const std::string& GetYParam() const { return m_params.y_par; };
inline const std::string& GetName() const { return m_params.name; } inline const std::string& GetName() const { return m_params.name; }

View File

@ -21,20 +21,47 @@ namespace Navigator {
m_map[params.name].reset(new Histogram2D(params)); m_map[params.name].reset(new Histogram2D(params));
} }
void HistogramMap::AddCutToHistogramDraw(const std::string &cutname, const std::string &histoname) void HistogramMap::RemoveHistogram(const std::string& name)
{
m_map.erase(name);
}
void HistogramMap::AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname)
{ {
auto iter = m_map.find(histoname); auto iter = m_map.find(histoname);
if(iter != m_map.end()) if(iter != m_map.end())
iter->second->AddCutToBeDrawn(cutname); iter->second->AddCutToBeDrawn(cutname);
} }
void HistogramMap::AddCutToHistogramApplied(const std::string &cutname, const std::string &histoname) void HistogramMap::AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname)
{ {
auto iter = m_map.find(histoname); auto iter = m_map.find(histoname);
if(iter != m_map.end()) if(iter != m_map.end())
iter->second->AddCutToBeApplied(cutname); iter->second->AddCutToBeApplied(cutname);
} }
void HistogramMap::RemoveCutFromHistograms(const std::string& cutname)
{
for (auto& gram : m_map)
{
auto& params = gram.second->GetParameters();
for (size_t i = 0; i < params.cutsDrawnUpon.size(); ++i)
{
if (params.cutsDrawnUpon[i] == cutname)
{
params.cutsDrawnUpon.erase(params.cutsDrawnUpon.begin() + i);
}
}
for (size_t i = 0; i < params.cutsAppliedTo.size(); ++i)
{
if (params.cutsAppliedTo[i] == cutname)
{
params.cutsAppliedTo.erase(params.cutsAppliedTo.begin() + i);
}
}
}
}
void HistogramMap::UpdateHistograms() void HistogramMap::UpdateHistograms()
{ {
std::string xpar, ypar; std::string xpar, ypar;

View File

@ -16,14 +16,19 @@ namespace Navigator {
void AddHistogram(const HistogramParameters& params); void AddHistogram(const HistogramParameters& params);
void RemoveHistogram(const std::string& name);
void AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname); void AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname);
void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname); void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname);
void RemoveCutFromHistograms(const std::string& cutname);
void UpdateHistograms(); void UpdateHistograms();
void DrawHistograms(); void DrawHistograms();
void DrawHistogram(const std::string& name); void DrawHistogram(const std::string& name);
const HistogramParameters& GetHistogramParams(const std::string& name); //thread safe access for GUI to the underlying parameters. Only needs to be called when a gram is added/removed const HistogramParameters& GetHistogramParams(const std::string& name);
static HistogramMap& GetInstance() { return *s_instance; } static HistogramMap& GetInstance() { return *s_instance; }