diff --git a/Navigator/src/Navigator/Application.h b/Navigator/src/Navigator/Application.h index 441c295..93c7e02 100644 --- a/Navigator/src/Navigator/Application.h +++ b/Navigator/src/Navigator/Application.h @@ -22,6 +22,7 @@ namespace Navigator { virtual ~Application(); void Run(); + inline void Close() { m_runFlag = false; } void OnEvent(Event& event); void PushLayer(Layer* layer); diff --git a/Navigator/src/Navigator/CutMap.h b/Navigator/src/Navigator/CutMap.h index 6734739..a9677bc 100644 --- a/Navigator/src/Navigator/CutMap.h +++ b/Navigator/src/Navigator/CutMap.h @@ -97,6 +97,10 @@ namespace Navigator { { 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); bool IsInsideCut(const std::string& name, double xval, double yval = 0); diff --git a/Navigator/src/Navigator/Editor/EditorLayer.cpp b/Navigator/src/Navigator/Editor/EditorLayer.cpp index 0a60739..d5d39a8 100644 --- a/Navigator/src/Navigator/Editor/EditorLayer.cpp +++ b/Navigator/src/Navigator/Editor/EditorLayer.cpp @@ -8,7 +8,7 @@ namespace Navigator { EditorLayer::EditorLayer() : - Layer("EditorLayer"), m_spectrumPanel() + Layer("EditorLayer"), m_removeHistogram(false), m_removeCut(false) { } @@ -85,13 +85,14 @@ namespace Navigator { { m_fileDialog.SetOpenFileDialog(true); } - if(ImGui::MenuItem("Exit")) - { - } if(ImGui::MenuItem("Save")) { m_fileDialog.SetSaveFileDialog(true); } + if (ImGui::MenuItem("Exit")) + { + Application::Get().Close(); + } ImGui::EndMenu(); } if (ImGui::BeginMenu("Data Source")) @@ -119,9 +120,11 @@ namespace Navigator { { if (ImGui::MenuItem("Spectrum")) { + m_removeHistogram = true; } if (ImGui::MenuItem("Cut")) { + m_removeCut = true; } ImGui::EndMenu(); } @@ -147,6 +150,10 @@ namespace Navigator { m_sourceDialog.ImGuiRenderSourceDialog(); + RemoveHistogramDialog(); + + RemoveCutDialog(); + m_spectrumPanel.OnImGuiRender(); if (ImGui::Begin("Spectra")) @@ -199,4 +206,74 @@ namespace Navigator { 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(); + } + } } diff --git a/Navigator/src/Navigator/Editor/EditorLayer.h b/Navigator/src/Navigator/Editor/EditorLayer.h index ac0f567..bad3790 100644 --- a/Navigator/src/Navigator/Editor/EditorLayer.h +++ b/Navigator/src/Navigator/Editor/EditorLayer.h @@ -31,6 +31,9 @@ namespace Navigator { private: + void RemoveCutDialog(); + void RemoveHistogramDialog(); + EventCallbackFunc m_callbackFunc; SpectrumPanel m_spectrumPanel; @@ -45,7 +48,8 @@ namespace Navigator { ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; - + bool m_removeHistogram; + bool m_removeCut; }; } diff --git a/Navigator/src/Navigator/Histogram.h b/Navigator/src/Navigator/Histogram.h index 9be8821..fe3b360 100644 --- a/Navigator/src/Navigator/Histogram.h +++ b/Navigator/src/Navigator/Histogram.h @@ -50,7 +50,7 @@ namespace Navigator { virtual void ClearData() {} inline virtual bool Is1D() 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& GetYParam() const { return m_params.y_par; }; inline const std::string& GetName() const { return m_params.name; } diff --git a/Navigator/src/Navigator/HistogramMap.cpp b/Navigator/src/Navigator/HistogramMap.cpp index f1ac066..16774aa 100644 --- a/Navigator/src/Navigator/HistogramMap.cpp +++ b/Navigator/src/Navigator/HistogramMap.cpp @@ -21,20 +21,47 @@ namespace Navigator { 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); if(iter != m_map.end()) 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); if(iter != m_map.end()) 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() { std::string xpar, ypar; diff --git a/Navigator/src/Navigator/HistogramMap.h b/Navigator/src/Navigator/HistogramMap.h index 6a0d2b1..daa390f 100644 --- a/Navigator/src/Navigator/HistogramMap.h +++ b/Navigator/src/Navigator/HistogramMap.h @@ -15,15 +15,20 @@ namespace Navigator { ~HistogramMap(); void AddHistogram(const HistogramParameters& params); + + void RemoveHistogram(const std::string& name); + void AddCutToHistogramDraw(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 DrawHistograms(); 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; }