mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Added removal dialogs for both spectra and cuts. Lightly tested.
This commit is contained in:
parent
37e10eae1f
commit
343424ead7
|
@ -22,6 +22,7 @@ namespace Navigator {
|
|||
virtual ~Application();
|
||||
|
||||
void Run();
|
||||
inline void Close() { m_runFlag = false; }
|
||||
|
||||
void OnEvent(Event& event);
|
||||
void PushLayer(Layer* layer);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,14 +16,19 @@ namespace Navigator {
|
|||
|
||||
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; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user