diff --git a/Navigator/src/Navigator/CutMap.h b/Navigator/src/Navigator/CutMap.h index 0964370..62d2fee 100644 --- a/Navigator/src/Navigator/CutMap.h +++ b/Navigator/src/Navigator/CutMap.h @@ -76,7 +76,7 @@ namespace Navigator { class NAV_API CutMap { public: - using Iter = std::unordered_map>::iterator; + using Iter = std::unordered_map>::iterator; CutMap(); ~CutMap(); @@ -100,7 +100,7 @@ namespace Navigator { inline Iter end() { return m_map.end(); } private: - std::unordered_map> m_map; + std::unordered_map> m_map; static CutMap* s_instance; }; diff --git a/Navigator/src/Navigator/Editor/SpectrumPanel.cpp b/Navigator/src/Navigator/Editor/SpectrumPanel.cpp index 73d55bb..aa3d6d8 100644 --- a/Navigator/src/Navigator/Editor/SpectrumPanel.cpp +++ b/Navigator/src/Navigator/Editor/SpectrumPanel.cpp @@ -1,10 +1,11 @@ #include "SpectrumPanel.h" #include "implot.h" +#include "misc/cpp/imgui_stdlib.h" namespace Navigator { SpectrumPanel::SpectrumPanel() : - m_zoomedFlag(false), m_cutModeFlag("false"), m_zoomedGram(""), m_totalSlots(1) + m_zoomedFlag(false), m_cutModeFlag(false), m_zoomedGram(""), m_totalSlots(1) { m_tableSizes[0] = 1; m_tableSizes[1] = 1; } @@ -16,6 +17,7 @@ namespace Navigator { HistogramMap& histMap = HistogramMap::GetInstance(); ParameterMap& paramMap = ParameterMap::GetInstance(); CutMap& cutMap = CutMap::GetInstance(); + static bool acceptCutFlag = false; if (ImGui::Begin("Active View")) { if (histMap.size() > 0) @@ -24,12 +26,22 @@ namespace Navigator { { if(ImGui::Button("Draw Cut")) { + m_newCutParams = CutParams(); + m_newCutX.resize(0); + m_newCutY.resize(0); ImGui::OpenPopup("New Cut Dialog"); } if(ImGui::BeginPopupModal("New Cut Dialog")) { - if(ImGui::Button("Accept")) + auto& zoomed_params = histMap.GetHistogramParams(m_zoomedGram); + m_newCutParams.x_par = zoomed_params.x_par; + m_newCutParams.y_par = zoomed_params.y_par; + ImGui::InputText("Cut Name", &m_newCutParams.name); + ImGui::BulletText("X Parameter: %s", m_newCutParams.x_par.c_str()); + ImGui::BulletText("Y Parameter: %s", m_newCutParams.y_par.c_str()); + if(ImGui::Button("Accept & Draw")) { + m_cutModeFlag = true; ImGui::CloseCurrentPopup(); } if(ImGui::Button("Cancel")) @@ -42,14 +54,72 @@ namespace Navigator { if (ImPlot::BeginPlot(m_zoomedGram.c_str(), ImVec2(-1, -1))) { histMap.DrawHistogram(m_zoomedGram); - if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + if (!m_cutModeFlag && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { NAV_INFO("We lost 'em, de-zoom and enhance!"); m_zoomedFlag = false; m_zoomedGram = ""; } + else if (m_cutModeFlag && m_newCutParams.y_par == "None") + { + if (m_newCutX.size() == 2) + { + acceptCutFlag = true; + } + else if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) + { + m_newCutX.push_back(ImPlot::GetPlotMousePos().x); + } + ImPlot::PlotVLines(m_newCutParams.name.c_str(), m_newCutX.data(), m_newCutX.size()); + + } + else if(m_cutModeFlag) + { + if (m_newCutX.size() >= 2 && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + acceptCutFlag = true; + m_newCutX.push_back(m_newCutX[0]); + m_newCutY.push_back(m_newCutY[0]); + } + else if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) + { + auto point = ImPlot::GetPlotMousePos(); + m_newCutX.push_back(point.x); + m_newCutY.push_back(point.y); + } + ImPlot::PlotLine(m_newCutParams.name.c_str(), m_newCutX.data(), m_newCutY.data(), m_newCutX.size()); + } ImPlot::EndPlot(); } + if (acceptCutFlag) + { + acceptCutFlag = false; + m_cutModeFlag = false; + ImGui::OpenPopup("Accept Cut"); + } + if (ImGui::BeginPopupModal("Accept Cut")) + { + ImGui::Text("Save this Cut?"); + if (ImGui::Button("Yes")) + { + if (m_newCutParams.y_par == "None") + { + std::sort(m_newCutX.begin(), m_newCutX.end()); + cutMap.AddCut(m_newCutParams, m_newCutX[0], m_newCutX[1]); + } + else + { + cutMap.AddCut(m_newCutParams, m_newCutX, m_newCutY); + } + histMap.AddCutToHistogramDraw(m_newCutParams.name, m_zoomedGram); + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("No")) + { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } } else { diff --git a/Navigator/src/Navigator/Editor/SpectrumPanel.h b/Navigator/src/Navigator/Editor/SpectrumPanel.h index 7eda1c4..d060fd0 100644 --- a/Navigator/src/Navigator/Editor/SpectrumPanel.h +++ b/Navigator/src/Navigator/Editor/SpectrumPanel.h @@ -25,6 +25,9 @@ namespace Navigator { std::string m_zoomedGram; int m_tableSizes[2]; int m_totalSlots; + CutParams m_newCutParams; + std::vector m_newCutX; + std::vector m_newCutY; }; } diff --git a/Navigator/src/Navigator/HistogramMap.cpp b/Navigator/src/Navigator/HistogramMap.cpp index cb6d2c5..f1ac066 100644 --- a/Navigator/src/Navigator/HistogramMap.cpp +++ b/Navigator/src/Navigator/HistogramMap.cpp @@ -74,13 +74,16 @@ namespace Navigator { } } - std::vector HistogramMap::GetListOfHistogramParams() + const HistogramParameters& HistogramMap::GetHistogramParams(const std::string& name) { - std::vector params; - params.reserve(m_map.size()); - for (auto& pair : m_map) - params.push_back(pair.second->GetParameters()); - return params; + + auto iter = m_map.find(name); + if (iter != m_map.end()) + return iter->second->GetParameters(); + else + { + return HistogramParameters(); + } } //Only to be used within ImGui context!! diff --git a/Navigator/src/Navigator/HistogramMap.h b/Navigator/src/Navigator/HistogramMap.h index 360f690..6a0d2b1 100644 --- a/Navigator/src/Navigator/HistogramMap.h +++ b/Navigator/src/Navigator/HistogramMap.h @@ -23,7 +23,7 @@ namespace Navigator { void DrawHistograms(); void DrawHistogram(const std::string& name); - std::vector GetListOfHistogramParams(); //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); //thread safe access for GUI to the underlying parameters. Only needs to be called when a gram is added/removed static HistogramMap& GetInstance() { return *s_instance; }