diff --git a/Navigator/src/Navigator/Application.cpp b/Navigator/src/Navigator/Application.cpp index ceffc7c..841cb8b 100644 --- a/Navigator/src/Navigator/Application.cpp +++ b/Navigator/src/Navigator/Application.cpp @@ -20,7 +20,9 @@ namespace Navigator { m_physicsLayer = new PhysicsLayer(); PushLayer(m_physicsLayer); - PushLayer(new EditorLayer()); + EditorLayer* editor = new EditorLayer(); //memory handled by layer stack + editor->SetEventCallbackFunc(BIND_EVENT_FUNCTION(Application::OnEvent)); + PushLayer(editor); m_imgui_layer = new ImGuiLayer(); PushOverlay(m_imgui_layer); } diff --git a/Navigator/src/Navigator/Editor/EditorLayer.cpp b/Navigator/src/Navigator/Editor/EditorLayer.cpp index c729373..0a60739 100644 --- a/Navigator/src/Navigator/Editor/EditorLayer.cpp +++ b/Navigator/src/Navigator/Editor/EditorLayer.cpp @@ -98,9 +98,12 @@ namespace Navigator { { if (ImGui::MenuItem("Attach Source")) { + m_sourceDialog.OpenSourceDialog(); } if (ImGui::MenuItem("Detach Source")) { + PhysicsStopEvent event; + m_callbackFunc(event); } ImGui::EndMenu(); } @@ -142,6 +145,8 @@ namespace Navigator { m_spectrumDialog.ImGuiRenderSpectrumDialog(); + m_sourceDialog.ImGuiRenderSourceDialog(); + m_spectrumPanel.OnImGuiRender(); if (ImGui::Begin("Spectra")) diff --git a/Navigator/src/Navigator/Editor/EditorLayer.h b/Navigator/src/Navigator/Editor/EditorLayer.h index ab848cc..ac0f567 100644 --- a/Navigator/src/Navigator/Editor/EditorLayer.h +++ b/Navigator/src/Navigator/Editor/EditorLayer.h @@ -9,15 +9,20 @@ #include "SpectrumPanel.h" #include "FileDialog.h" #include "SpectrumDialog.h" +#include "SourceDialog.h" namespace Navigator { class EditorLayer : public Layer { public: + using EventCallbackFunc = std::function; + EditorLayer(); ~EditorLayer(); + void SetEventCallbackFunc(const EventCallbackFunc& f) { m_callbackFunc = f; } + virtual void OnAttach() override; virtual void OnDetach() override; virtual void OnImGuiRender() override; @@ -26,9 +31,12 @@ namespace Navigator { private: + EventCallbackFunc m_callbackFunc; + SpectrumPanel m_spectrumPanel; FileDialog m_fileDialog; SpectrumDialog m_spectrumDialog; + SourceDialog m_sourceDialog; //ImGui Settings bool dockspaceOpen = true; diff --git a/Navigator/src/Navigator/Editor/SourceDialog.cpp b/Navigator/src/Navigator/Editor/SourceDialog.cpp new file mode 100644 index 0000000..a17fd8c --- /dev/null +++ b/Navigator/src/Navigator/Editor/SourceDialog.cpp @@ -0,0 +1,82 @@ +#include "SourceDialog.h" +#include "Navigator/Events/PhysicsEvent.h" +#include "Navigator/Events/Event.h" +#include "Navigator/Application.h" + +#include "imgui.h" +#include "misc/cpp/imgui_stdlib.h" + +namespace Navigator { + + SourceDialog::SourceDialog() : + m_openFlag(false), m_chosenWindow(2000000) + { + } + + SourceDialog::~SourceDialog() + { + } + + void SourceDialog::ImGuiRenderSourceDialog() + { + static bool onlineFlag = false; + static bool offlineFlag = false; + static std::vector availTypes = { DataSource::SourceType::CompassOnline, DataSource::SourceType::CompassOffline }; + + if (m_openFlag) + { + onlineFlag = false; + offlineFlag = false; + m_openFlag = false; + m_chosenType = DataSource::SourceType::None; + m_chosenLocation = ""; + m_chosenWindow = 2000000; + ImGui::OpenPopup("Attach Source"); + } + if (ImGui::BeginPopupModal("Attach Source")) + { + if (ImGui::BeginCombo("Source Type", ConvertDataSourceTypeToString(m_chosenType).c_str())) + { + for (auto& type : availTypes) + { + if (ImGui::Selectable(ConvertDataSourceTypeToString(type).c_str(), type == m_chosenType, ImGuiSelectableFlags_DontClosePopups)) + { + m_chosenType = type; + } + } + ImGui::EndCombo(); + } + + if (m_chosenType == DataSource::SourceType::CompassOnline) + { + ImGui::InputText("Hostname", &m_chosenLocation); + } + else if (m_chosenType == DataSource::SourceType::CompassOffline) + { + ImGui::InputText("Run Directory", &m_chosenLocation); + if (ImGui::Button("Choose Location")) + { + m_fileDialog.SetOpenDirDialog(true); + } + auto& temp = m_fileDialog.ImGuiRenderOpenDir(); + if (temp != "") + m_chosenLocation = temp; + } + ImGui::InputInt("Coincidence Window (ps)", &m_chosenWindow); + + + if (ImGui::Button("Ok")) + { + PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow); + Application::Get().OnEvent(event); + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Cancel")) + { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + } + +} \ No newline at end of file diff --git a/Navigator/src/Navigator/Editor/SourceDialog.h b/Navigator/src/Navigator/Editor/SourceDialog.h new file mode 100644 index 0000000..c8da5d7 --- /dev/null +++ b/Navigator/src/Navigator/Editor/SourceDialog.h @@ -0,0 +1,28 @@ +#ifndef SOURCE_DIALOG_H +#define SOURCE_DIALOG_H + +#include "FileDialog.h" +#include "Navigator/Physics/DataSource.h" + +namespace Navigator { + + class NAV_API SourceDialog + { + public: + SourceDialog(); + ~SourceDialog(); + + void ImGuiRenderSourceDialog(); + + inline void OpenSourceDialog() { m_openFlag = true; } + private: + bool m_openFlag; + DataSource::SourceType m_chosenType; + std::string m_chosenLocation; + FileDialog m_fileDialog; + int m_chosenWindow; + }; + +} + +#endif \ No newline at end of file