From 46cadc4df4837e546c303a4a063ec0ba6703584c Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 4 Jun 2024 17:27:29 +0200 Subject: [PATCH 01/41] [SofaGLFWBaseGUI] Handle Keyboard events --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 92 ++++++++++++++--------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 12 ++- 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 10ff31844b..bd7b3f7cf7 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -41,6 +41,8 @@ #include #include +#include +#include using namespace sofa; namespace sofaglfw @@ -313,6 +315,7 @@ void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* s glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_TRUE); glfwSetWindowMonitor(glfwWindow, nullptr, m_lastWindowPositionX, m_lastWindowPositionY, m_lastWindowWidth, m_lastWindowHeight, GLFW_DONT_CARE); } + std::cout<< "fkkkkkkk"; } else { @@ -489,23 +492,66 @@ void SofaGLFWBaseGUI::error_callback(int error, const char* description) SOFA_UNUSED(error); msg_error("SofaGLFWBaseGUI") << "Error: " << description << "."; } - + +int SofaGLFWBaseGUI::handleArrowKeys(int key) +{ + // Handling arrow keys with custom codes + switch (key) + { + case GLFW_KEY_UP: return 19; // Custom code for up + case GLFW_KEY_DOWN: return 21; // Custom code for down + case GLFW_KEY_LEFT: return 18; // Custom code for left + case GLFW_KEY_RIGHT: return 20; // Custom code for right + } + // Default case return the given value as GLFW handle it + return key; +} + void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - SOFA_UNUSED(scancode); + const char keyName = SofaGLFWBaseGUI::handleArrowKeys(key); + int state = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL); + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI == s_mapGUIs.end() || currentGUI->second == nullptr) + { + return; + } + + auto rootNode = currentGUI->second->getRootNode(); + if (!rootNode) + { + return; + } + if (state == GLFW_PRESS) + { + if (action == GLFW_PRESS) + { + if (key==GLFW_KEY_LEFT_CONTROL) + { + dmsg_info("SofaGLFWBaseGUI")<<"KeypressedEvent::keyPressEvent, CONTROL pressed"; + } + sofa::core::objectmodel::KeypressedEvent *keyPressedEvent = + new sofa::core::objectmodel::KeypressedEvent(keyName); + rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), keyPressedEvent); + delete keyPressedEvent; + } else if (action == GLFW_RELEASE) + { + sofa::core::objectmodel::KeyreleasedEvent *keyReleasedEvent = + new sofa::core::objectmodel::KeyreleasedEvent(keyName); + rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), keyReleasedEvent); + delete keyReleasedEvent; + } + } + // Handle specific keys for additional functionality switch (key) { case GLFW_KEY_F: if (action == GLFW_PRESS && (mods & GLFW_MOD_CONTROL)) { - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - currentGUI->second->switchFullScreen(window); - } + currentGUI->second->switchFullScreen(window); } - break; + break; case GLFW_KEY_ESCAPE: if (action == GLFW_PRESS) { @@ -515,35 +561,9 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in case GLFW_KEY_SPACE: if (action == GLFW_PRESS) { - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - currentGUI->second->setSimulationIsRunning(!currentGUI->second->simulationIsRunning()); - } - } - break; - case GLFW_KEY_LEFT_CONTROL: - case GLFW_KEY_RIGHT_CONTROL: - if (action == GLFW_PRESS) - { - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - currentGUI->second->m_isMouseInteractionEnabled = true; - msg_warning("SofaGLFWBaseGUI") << "Mouse interaction is not yet available"; - - } - } - else if (action == GLFW_RELEASE) - { - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - currentGUI->second->m_isMouseInteractionEnabled = false; - } + bool isRunning = currentGUI->second->simulationIsRunning(); + currentGUI->second->setSimulationIsRunning(!isRunning); } - break; - default: break; } } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 1e83f5b3c9..0ec923cbb6 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -64,6 +64,7 @@ class SOFAGLFW_API SofaGLFWBaseGUI void setWindowWidth(int width) { m_windowWidth = width; } int getWindowHeight() const { return m_windowHeight; } void setWindowHeight(int height) { m_windowHeight = height; } + bool isControlPressed() const{return m_isControlPressed;} void resizeWindow(int width, int height); @@ -104,24 +105,29 @@ class SOFAGLFW_API SofaGLFWBaseGUI static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); static void close_callback(GLFWwindow* window); - // empty (as in non-implemented) GLFW callbacks +// empty (as in non-implemented) GLFW callbacks static void window_focus_callback(GLFWwindow* window, int focused); static void cursor_enter_callback(GLFWwindow* window, int entered); static void monitor_callback(GLFWmonitor* monitor, int event); static void character_callback(GLFWwindow* window, unsigned int codepoint); + + static int handleArrowKeys(int key); + void makeCurrentContext(GLFWwindow* sofaWindow); void runStep(); - // static members + // static members inline static std::map< GLFWwindow*, SofaGLFWWindow*> s_mapWindows{}; inline static std::map< GLFWwindow*, SofaGLFWBaseGUI*> s_mapGUIs{}; //members bool m_bGlfwIsInitialized{ false }; bool m_bGlewIsInitialized{ false }; + bool m_isControlPressed{ false }; + - sofa::simulation::NodeSPtr m_groot; + sofa::simulation::NodeSPtr m_groot; std::string m_filename; sofa::gl::DrawToolGL* m_glDrawTool{ nullptr }; sofa::core::visual::VisualParams* m_vparams{ nullptr }; From ceed77d4e07a3f5b52c9e8e4237b53b58f63a3b7 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 4 Jun 2024 17:43:44 +0200 Subject: [PATCH 02/41] [SofaGLFWBaseGUI] Remove useless cout and include --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index bd7b3f7cf7..b67d8ce897 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -42,7 +42,6 @@ #include #include -#include using namespace sofa; namespace sofaglfw @@ -315,7 +314,6 @@ void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* s glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_TRUE); glfwSetWindowMonitor(glfwWindow, nullptr, m_lastWindowPositionX, m_lastWindowPositionY, m_lastWindowWidth, m_lastWindowHeight, GLFW_DONT_CARE); } - std::cout<< "fkkkkkkk"; } else { From bde7cfc12727371ce3521d5b5e43ae1c1ddc8dc9 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 4 Jun 2024 18:22:15 +0200 Subject: [PATCH 03/41] [SofaGLFWBaseGUI] Remove useless declarations --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 1 + SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index b67d8ce897..517e41a1e5 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -42,6 +42,7 @@ #include #include +#include using namespace sofa; namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 0ec923cbb6..7c6191bc49 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -64,8 +64,6 @@ class SOFAGLFW_API SofaGLFWBaseGUI void setWindowWidth(int width) { m_windowWidth = width; } int getWindowHeight() const { return m_windowHeight; } void setWindowHeight(int height) { m_windowHeight = height; } - bool isControlPressed() const{return m_isControlPressed;} - void resizeWindow(int width, int height); GLFWmonitor* getCurrentMonitor(GLFWwindow *window); @@ -124,10 +122,8 @@ class SOFAGLFW_API SofaGLFWBaseGUI //members bool m_bGlfwIsInitialized{ false }; bool m_bGlewIsInitialized{ false }; - bool m_isControlPressed{ false }; - - sofa::simulation::NodeSPtr m_groot; + sofa::simulation::NodeSPtr m_groot; std::string m_filename; sofa::gl::DrawToolGL* m_glDrawTool{ nullptr }; sofa::core::visual::VisualParams* m_vparams{ nullptr }; From 069c556b45c83867d1f049e9fe4623bae45a3945 Mon Sep 17 00:00:00 2001 From: MOHAMED SAID AIMEN LAMRI <89317946+lamriaimen@users.noreply.github.com> Date: Wed, 5 Jun 2024 09:49:16 +0200 Subject: [PATCH 04/41] Update SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h Co-authored-by: Alex Bilger --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 7c6191bc49..aa26f5ae3a 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -110,7 +110,7 @@ class SOFAGLFW_API SofaGLFWBaseGUI static void character_callback(GLFWwindow* window, unsigned int codepoint); - static int handleArrowKeys(int key); + static int handleArrowKeys(int key); void makeCurrentContext(GLFWwindow* sofaWindow); void runStep(); From 143572e1cc337bf45bec2d98c9a1bd5c255a0d9c Mon Sep 17 00:00:00 2001 From: MOHAMED SAID AIMEN LAMRI <89317946+lamriaimen@users.noreply.github.com> Date: Wed, 5 Jun 2024 09:49:24 +0200 Subject: [PATCH 05/41] Update SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp Co-authored-by: Alex Bilger --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 517e41a1e5..a96d262667 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -530,10 +530,8 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in { dmsg_info("SofaGLFWBaseGUI")<<"KeypressedEvent::keyPressEvent, CONTROL pressed"; } - sofa::core::objectmodel::KeypressedEvent *keyPressedEvent = - new sofa::core::objectmodel::KeypressedEvent(keyName); - rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), keyPressedEvent); - delete keyPressedEvent; + sofa::core::objectmodel::KeypressedEvent keyPressedEvent(keyName); + rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyPressedEvent); } else if (action == GLFW_RELEASE) { sofa::core::objectmodel::KeyreleasedEvent *keyReleasedEvent = From c23057fa757267b2baf2d7c25f05ec18076cace0 Mon Sep 17 00:00:00 2001 From: MOHAMED SAID AIMEN LAMRI <89317946+lamriaimen@users.noreply.github.com> Date: Wed, 5 Jun 2024 09:49:30 +0200 Subject: [PATCH 06/41] Update SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp Co-authored-by: Alex Bilger --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index a96d262667..9f5122d6b9 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -534,10 +534,8 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyPressedEvent); } else if (action == GLFW_RELEASE) { - sofa::core::objectmodel::KeyreleasedEvent *keyReleasedEvent = - new sofa::core::objectmodel::KeyreleasedEvent(keyName); - rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), keyReleasedEvent); - delete keyReleasedEvent; + sofa::core::objectmodel::KeyreleasedEvent keyReleasedEvent(keyName); + rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyReleasedEvent); } } // Handle specific keys for additional functionality From 2f5911923597c9b52415719af287a75d9f68a28c Mon Sep 17 00:00:00 2001 From: MOHAMED SAID AIMEN LAMRI <89317946+lamriaimen@users.noreply.github.com> Date: Wed, 5 Jun 2024 09:49:38 +0200 Subject: [PATCH 07/41] Update SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp Co-authored-by: Alex Bilger --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 9f5122d6b9..ea166f81ce 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -556,7 +556,7 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in case GLFW_KEY_SPACE: if (action == GLFW_PRESS) { - bool isRunning = currentGUI->second->simulationIsRunning(); + const bool isRunning = currentGUI->second->simulationIsRunning(); currentGUI->second->setSimulationIsRunning(!isRunning); } break; From f09f9d43e25efce79d8c3a5bc9b99c2393a25945 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 5 Jun 2024 14:46:55 +0200 Subject: [PATCH 08/41] cleaning --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index ea166f81ce..111acba2fa 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -509,7 +509,7 @@ int SofaGLFWBaseGUI::handleArrowKeys(int key) void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { const char keyName = SofaGLFWBaseGUI::handleArrowKeys(key); - int state = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL); + const bool isCtrlKeyPressed = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; auto currentGUI = s_mapGUIs.find(window); if (currentGUI == s_mapGUIs.end() || currentGUI->second == nullptr) @@ -522,22 +522,23 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in { return; } - if (state == GLFW_PRESS) + + if (isCtrlKeyPressed) { if (action == GLFW_PRESS) { - if (key==GLFW_KEY_LEFT_CONTROL) - { - dmsg_info("SofaGLFWBaseGUI")<<"KeypressedEvent::keyPressEvent, CONTROL pressed"; - } + dmsg_info_when(key == GLFW_KEY_LEFT_CONTROL, "SofaGLFWBaseGUI") << "KeyPressEvent, CONTROL pressed"; + sofa::core::objectmodel::KeypressedEvent keyPressedEvent(keyName); rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyPressedEvent); - } else if (action == GLFW_RELEASE) + } + else if (action == GLFW_RELEASE) { sofa::core::objectmodel::KeyreleasedEvent keyReleasedEvent(keyName); rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyReleasedEvent); } } + // Handle specific keys for additional functionality switch (key) { From 0a9aa6889ef6e5f72d94a3aaa25c0e6e336cb19e Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 5 Jun 2024 14:51:01 +0200 Subject: [PATCH 09/41] revert useless changes --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index aa26f5ae3a..24e3e1401f 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -103,7 +103,7 @@ class SOFAGLFW_API SofaGLFWBaseGUI static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); static void close_callback(GLFWwindow* window); -// empty (as in non-implemented) GLFW callbacks + // empty (as in non-implemented) GLFW callbacks static void window_focus_callback(GLFWwindow* window, int focused); static void cursor_enter_callback(GLFWwindow* window, int entered); static void monitor_callback(GLFWmonitor* monitor, int event); @@ -115,7 +115,7 @@ class SOFAGLFW_API SofaGLFWBaseGUI void makeCurrentContext(GLFWwindow* sofaWindow); void runStep(); - // static members + // static members inline static std::map< GLFWwindow*, SofaGLFWWindow*> s_mapWindows{}; inline static std::map< GLFWwindow*, SofaGLFWBaseGUI*> s_mapGUIs{}; From eaa8aa976df2b3c0e1181738ec2b013b378fee3a Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Mon, 24 Jun 2024 15:19:51 +0200 Subject: [PATCH 10/41] Resolve conflicts --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 1021 +++++++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 206 ++--- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 341 ++++--- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h | 56 +- 4 files changed, 898 insertions(+), 726 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 111acba2fa..3e10790ec5 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -43,641 +43,730 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + using namespace sofa; +using namespace sofa::gui::common; namespace sofaglfw { + std::unique_ptr SofaGLFWBaseGUI::attachOperation; + SofaGLFWBaseGUI::SofaGLFWBaseGUI():BaseViewer() + { + m_guiEngine = std::make_shared(); + } -SofaGLFWBaseGUI::SofaGLFWBaseGUI() -{ - m_guiEngine = std::make_shared(); -} - -SofaGLFWBaseGUI::~SofaGLFWBaseGUI() -{ - terminate(); -} + SofaGLFWBaseGUI::~SofaGLFWBaseGUI() + { + terminate(); + } -sofa::core::sptr SofaGLFWBaseGUI::getRootNode() const -{ - return m_groot; -} + sofa::core::sptr SofaGLFWBaseGUI::getRootNode() const + { + return m_groot; + } -bool SofaGLFWBaseGUI::init(int nbMSAASamples) -{ - if (m_bGlfwIsInitialized) - return true; + bool SofaGLFWBaseGUI::init(int nbMSAASamples) + { + if (m_bGlfwIsInitialized) + return true; - setErrorCallback(); + setErrorCallback(); - if (glfwInit() == GLFW_TRUE) - { - // defined samples for MSAA - // min = 0 (no MSAA Anti-aliasing) - // max = 32 (MSAA with 32 samples) - glfwWindowHint(GLFW_SAMPLES, std::clamp(nbMSAASamples, 0, 32) ); - - m_glDrawTool = new sofa::gl::DrawToolGL(); - m_bGlfwIsInitialized = true; - return true; + if (glfwInit() == GLFW_TRUE) + { + // defined samples for MSAA + // min = 0 (no MSAA Anti-aliasing) + // max = 32 (MSAA with 32 samples) + glfwWindowHint(GLFW_SAMPLES, std::clamp(nbMSAASamples, 0, 32) ); + + m_glDrawTool = new sofa::gl::DrawToolGL(); + m_bGlfwIsInitialized = true; + return true; + } + else + { + return false; + } } - else + + void SofaGLFWBaseGUI::setErrorCallback() const { - return false; + glfwSetErrorCallback(error_callback); } -} -void SofaGLFWBaseGUI::setErrorCallback() const -{ - glfwSetErrorCallback(error_callback); -} + void SofaGLFWBaseGUI::setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename) { + m_groot = groot; + m_filename = filename; -void SofaGLFWBaseGUI::setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename) -{ - m_groot = groot; - m_filename = filename; + sofa::core::visual::VisualParams::defaultInstance()->drawTool() = m_glDrawTool; - sofa::core::visual::VisualParams::defaultInstance()->drawTool() = m_glDrawTool; -} + if (m_groot) { + // Initialize the pick handler + pickHandler.init(m_groot.get()); + } + } -void SofaGLFWBaseGUI::setSimulationIsRunning(bool running) -{ - if (m_groot) + void SofaGLFWBaseGUI::setSimulationIsRunning(bool running) { - m_groot->setAnimate(running); + if (m_groot) + { + m_groot->setAnimate(running); + } } -} -bool SofaGLFWBaseGUI::simulationIsRunning() const -{ - if (m_groot) + bool SofaGLFWBaseGUI::simulationIsRunning() const { - return m_groot->getAnimate(); - } + if (m_groot) + { + return m_groot->getAnimate(); + } - return false; -} + return false; + } -sofa::component::visual::BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(sofa::simulation::NodeSPtr groot) -{ - sofa::component::visual::BaseCamera::SPtr camera; - groot->get(camera); - if (!camera) + sofa::component::visual::BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(sofa::simulation::NodeSPtr groot) { - camera = sofa::core::objectmodel::New(); - camera->setName(core::objectmodel::Base::shortName(camera.get())); - m_groot->addObject(camera); - camera->bwdInit(); - } + sofa::component::visual::BaseCamera::SPtr camera; + groot->get(camera); + if (!camera) + { + camera = sofa::core::objectmodel::New(); + camera->setName(core::objectmodel::Base::shortName(camera.get())); + m_groot->addObject(camera); + camera->bwdInit(); + } - camera->setBoundingBox(m_groot->f_bbox.getValue().minBBox(), m_groot->f_bbox.getValue().maxBBox()); + camera->setBoundingBox(m_groot->f_bbox.getValue().minBBox(), m_groot->f_bbox.getValue().maxBBox()); - return camera; -} + return camera; + } -void SofaGLFWBaseGUI::changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera) -{ - for (auto& w : s_mapWindows) - { - w.second->setCamera(newCamera); + + void SofaGLFWBaseGUI::setSizeW(int width) { + m_windowWidth = width; } -} -void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) -{ - //STBImage relies on DataRepository to find files: it must be extended with the resource files from this plugin - sofa::helper::system::DataRepository.addFirstPath(SOFAGLFW_RESOURCES_DIR); + void SofaGLFWBaseGUI::setSizeH(int height) { + m_windowHeight = height; + } - sofa::helper::io::STBImage img; - if (img.load("SOFA.png")) - { - GLFWimage images[1]; - images[0].height = img.getHeight(); - images[0].width = img.getWidth(); - images[0].pixels = img.getPixels(); - glfwSetWindowIcon(glfwWindow, 1, images); + int SofaGLFWBaseGUI::getWidth() { + return m_windowWidth; } - sofa::helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); -} -bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) -{ - m_guiEngine->init(); + int SofaGLFWBaseGUI::getHeight() { + return m_windowHeight; + } - if (m_groot == nullptr) + void SofaGLFWBaseGUI::changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera) { - msg_error("SofaGLFWBaseGUI") << "No simulation root has been defined. Quitting."; - return false; + for (auto& w : s_mapWindows) + { + w.second->setCamera(newCamera); + } } - GLFWwindow* glfwWindow = nullptr; - if (fullscreenAtStartup) + void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) { - GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor(); - const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor); + //STBImage relies on DataRepository to find files: it must be extended with the resource files from this plugin + sofa::helper::system::DataRepository.addFirstPath(SOFAGLFW_RESOURCES_DIR); - m_lastWindowWidth = width; - m_lastWindowHeight = height; - m_lastWindowPositionX = 100; - m_lastWindowPositionY = 100; - - glfwWindow = glfwCreateWindow(mode->width, mode->height, title, primaryMonitor, m_firstWindow); + sofa::helper::io::STBImage img; + if (img.load("SOFA.png")) + { + GLFWimage images[1]; + images[0].height = img.getHeight(); + images[0].width = img.getWidth(); + images[0].pixels = img.getPixels(); + glfwSetWindowIcon(glfwWindow, 1, images); + } + sofa::helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); } - else + + bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) { - glfwWindow = glfwCreateWindow(width > 0 ? width : 100, height > 0 ? height : 100, title, nullptr, m_firstWindow); - } + m_guiEngine->init(); - setWindowIcon(glfwWindow); + if (m_groot == nullptr) + { + msg_error("SofaGLFWBaseGUI") << "No simulation root has been defined. Quitting."; + return false; + } - if (!m_firstWindow) - m_firstWindow = glfwWindow; + GLFWwindow* glfwWindow = nullptr; + if (fullscreenAtStartup) + { + GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor); - if (glfwWindow) - { - glfwSetKeyCallback(glfwWindow, key_callback); - glfwSetCursorPosCallback(glfwWindow, cursor_position_callback); - glfwSetMouseButtonCallback(glfwWindow, mouse_button_callback); - glfwSetScrollCallback(glfwWindow, scroll_callback); - glfwSetWindowCloseCallback(glfwWindow, close_callback); + m_lastWindowWidth = width; + m_lastWindowHeight = height; + m_lastWindowPositionX = 100; + m_lastWindowPositionY = 100; - // this set empty callbacks - // solve a crash when glfw is quitting and tries to use nullptr callbacks - // could be potentially useful in the future anyway - glfwSetWindowFocusCallback(glfwWindow, window_focus_callback); - glfwSetCursorEnterCallback(glfwWindow, cursor_enter_callback); - glfwSetMonitorCallback(monitor_callback); - glfwSetCharCallback(glfwWindow, character_callback); + glfwWindow = glfwCreateWindow(mode->width, mode->height, title, primaryMonitor, m_firstWindow); + } + else + { + glfwWindow = glfwCreateWindow(width > 0 ? width : 100, height > 0 ? height : 100, title, nullptr, m_firstWindow); + } - makeCurrentContext(glfwWindow); + setWindowIcon(glfwWindow); - m_guiEngine->initBackend(glfwWindow); + if (!m_firstWindow) + m_firstWindow = glfwWindow; - auto camera = findCamera(m_groot); - - SofaGLFWWindow* sofaWindow = new SofaGLFWWindow(glfwWindow, camera); + if (glfwWindow) + { + glfwSetKeyCallback(glfwWindow, key_callback); + glfwSetCursorPosCallback(glfwWindow, cursor_position_callback); + glfwSetMouseButtonCallback(glfwWindow, mouse_button_callback); + glfwSetScrollCallback(glfwWindow, scroll_callback); + glfwSetWindowCloseCallback(glfwWindow, close_callback); + + // this set empty callbacks + // solve a crash when glfw is quitting and tries to use nullptr callbacks + // could be potentially useful in the future anyway + glfwSetWindowFocusCallback(glfwWindow, window_focus_callback); + glfwSetCursorEnterCallback(glfwWindow, cursor_enter_callback); + glfwSetMonitorCallback(monitor_callback); + glfwSetCharCallback(glfwWindow, character_callback); + + glfwSetWindowUserPointer(glfwWindow, this); + + makeCurrentContext(glfwWindow); - s_mapWindows[glfwWindow] = sofaWindow; - s_mapGUIs[glfwWindow] = this; + m_guiEngine->initBackend(glfwWindow); - return true; + auto camera = findCamera(m_groot); + + SofaGLFWWindow* sofaWindow = new SofaGLFWWindow(glfwWindow, camera); + + s_mapWindows[glfwWindow] = sofaWindow; + s_mapGUIs[glfwWindow] = this; + + return true; + } + else + { + return false; + } } - else + + void SofaGLFWBaseGUI::resizeWindow(int width, int height) { - return false; + if (hasWindow()) + { + glfwSetWindowSize(m_firstWindow, width, height); + } } -} -void SofaGLFWBaseGUI::resizeWindow(int width, int height) -{ - if (hasWindow()) + void SofaGLFWBaseGUI::destroyWindow() { - glfwSetWindowSize(m_firstWindow, width, height); } -} -void SofaGLFWBaseGUI::destroyWindow() -{ -} - -GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) -{ - int monitorsCount, i; - int windowsX, windowsY, windowsWidth, windowsHeight; - int monitorX, monitorY, monitorWidth, monitorHeight; - int overlap, bestOverlap; - GLFWmonitor *bestMonitor; - GLFWmonitor **monitors; - const GLFWvidmode *mode; + GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) + { + int monitorsCount, i; + int windowsX, windowsY, windowsWidth, windowsHeight; + int monitorX, monitorY, monitorWidth, monitorHeight; + int overlap, bestOverlap; + GLFWmonitor *bestMonitor; + GLFWmonitor **monitors; + const GLFWvidmode *mode; - bestOverlap = 0; - bestMonitor = nullptr; + bestOverlap = 0; + bestMonitor = nullptr; - glfwGetWindowPos(glfwWindow, &windowsX, &windowsY); - glfwGetWindowSize(glfwWindow, &windowsWidth, &windowsHeight); - monitors = glfwGetMonitors(&monitorsCount); + glfwGetWindowPos(glfwWindow, &windowsX, &windowsY); + glfwGetWindowSize(glfwWindow, &windowsWidth, &windowsHeight); + monitors = glfwGetMonitors(&monitorsCount); - for (i=0; iwidth; - monitorHeight = mode->height; + for (i=0; iwidth; + monitorHeight = mode->height; - overlap = std::max(0, std::min(windowsX + windowsWidth, monitorX + monitorWidth) - std::max(windowsX, monitorX)) * - std::max(0, std::min(windowsY + windowsHeight, monitorY + monitorHeight) - std::max(windowsY, monitorY)); + overlap = std::max(0, std::min(windowsX + windowsWidth, monitorX + monitorWidth) - std::max(windowsX, monitorX)) * + std::max(0, std::min(windowsY + windowsHeight, monitorY + monitorHeight) - std::max(windowsY, monitorY)); - if (bestOverlap < overlap) - { - bestOverlap = overlap; - bestMonitor = monitors[i]; + if (bestOverlap < overlap) + { + bestOverlap = overlap; + bestMonitor = monitors[i]; + } } - } - return bestMonitor; -} + return bestMonitor; + } -bool SofaGLFWBaseGUI::isFullScreen(GLFWwindow* glfwWindow) const -{ - if (hasWindow()) + bool SofaGLFWBaseGUI::isFullScreen(GLFWwindow* glfwWindow) const { - glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; - return glfwGetWindowMonitor(glfwWindow) != nullptr; + if (hasWindow()) + { + glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; + return glfwGetWindowMonitor(glfwWindow) != nullptr; + } + return false; } - return false; -} -void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* screenID */) -{ - if (hasWindow()) + void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* screenID */) { - // only manage the first window for now - // and the main screen - glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; + if (hasWindow()) + { + // only manage the first window for now + // and the main screen + glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; - bool isFullScreen = glfwGetWindowMonitor(glfwWindow) != nullptr; + bool isFullScreen = glfwGetWindowMonitor(glfwWindow) != nullptr; - if (!isFullScreen) - { - // backup window position and window size - glfwGetWindowPos(glfwWindow, &m_lastWindowPositionX, &m_lastWindowPositionY); - glfwGetWindowSize(glfwWindow, &m_lastWindowWidth, &m_lastWindowHeight); + if (!isFullScreen) + { + // backup window position and window size + glfwGetWindowPos(glfwWindow, &m_lastWindowPositionX, &m_lastWindowPositionY); + glfwGetWindowSize(glfwWindow, &m_lastWindowWidth, &m_lastWindowHeight); - GLFWmonitor* monitor = getCurrentMonitor(glfwWindow); - const GLFWvidmode* mode = glfwGetVideoMode(monitor); + GLFWmonitor* monitor = getCurrentMonitor(glfwWindow); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); - glfwSetWindowMonitor(glfwWindow, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); + glfwSetWindowMonitor(glfwWindow, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); + } + else + { + glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_TRUE); + glfwSetWindowMonitor(glfwWindow, nullptr, m_lastWindowPositionX, m_lastWindowPositionY, m_lastWindowWidth, m_lastWindowHeight, GLFW_DONT_CARE); + } } else { - glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_TRUE); - glfwSetWindowMonitor(glfwWindow, nullptr, m_lastWindowPositionX, m_lastWindowPositionY, m_lastWindowWidth, m_lastWindowHeight, GLFW_DONT_CARE); + msg_error("SofaGLFWBaseGUI") << "No window to set fullscreen"; // can happen with runSofa/BaseGUI } } - else - { - msg_error("SofaGLFWBaseGUI") << "No window to set fullscreen"; // can happen with runSofa/BaseGUI - } -} -void SofaGLFWBaseGUI::setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int /* windowID */) -{ - // only manage the first window for now - if (hasWindow()) - { - s_mapWindows[m_firstWindow]->setBackgroundColor(newColor); - } - else + void SofaGLFWBaseGUI::setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int /* windowID */) { - msg_error("SofaGLFWBaseGUI") << "No window to set the background in";// can happen with runSofa/BaseGUI + // only manage the first window for now + if (hasWindow()) + { + s_mapWindows[m_firstWindow]->setBackgroundColor(newColor); + } + else + { + msg_error("SofaGLFWBaseGUI") << "No window to set the background in";// can happen with runSofa/BaseGUI + } } -} - -void SofaGLFWBaseGUI::setBackgroundImage(const std::string& /* filename */, unsigned int /* windowID */) -{ - -} -void SofaGLFWBaseGUI::makeCurrentContext(GLFWwindow* glfwWindow) -{ - glfwMakeContextCurrent(glfwWindow); - glfwSwapInterval( 0 ); //request disabling vsync - if (!m_bGlewIsInitialized) + void SofaGLFWBaseGUI::setBackgroundImage(const std::string& /* filename */, unsigned int /* windowID */) { - glewInit(); - m_bGlewIsInitialized = true; + } -} -std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) -{ - if (!m_groot) + void SofaGLFWBaseGUI::makeCurrentContext(GLFWwindow* glfwWindow) { - msg_error("SofaGLFWBaseGUI") << "Cannot start main loop: root node is invalid"; - return 0; + glfwMakeContextCurrent(glfwWindow); + glfwSwapInterval( 0 ); //request disabling vsync + if (!m_bGlewIsInitialized) + { + glewInit(); + m_bGlewIsInitialized = true; + } } - m_vparams = sofa::core::visual::VisualParams::defaultInstance(); - - bool running = true; - std::size_t currentNbIterations = 0; - std::stringstream tmpStr; - while (!s_mapWindows.empty() && running) + std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) { - SIMULATION_LOOP_SCOPE - - // Keep running - runStep(); - - for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) + if (!m_groot) { - if (sofaGlfwWindow) - { - // while user did not request to close this window (i.e press escape), draw - if (!glfwWindowShouldClose(glfwWindow)) - { - makeCurrentContext(glfwWindow); + msg_error("SofaGLFWBaseGUI") << "Cannot start main loop: root node is invalid"; + return 0; + } - m_guiEngine->beforeDraw(glfwWindow); - sofaGlfwWindow->draw(m_groot, m_vparams); - m_guiEngine->afterDraw(); + m_vparams = sofa::core::visual::VisualParams::defaultInstance(); - m_guiEngine->startFrame(this); - m_guiEngine->endFrame(); + bool running = true; + std::size_t currentNbIterations = 0; + std::stringstream tmpStr; + while (!s_mapWindows.empty() && running) + { + SIMULATION_LOOP_SCOPE - glfwSwapBuffers(glfwWindow); + // Keep running + runStep(); - } - else + for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) + { + if (sofaGlfwWindow) { - // otherwise close this window - close_callback(glfwWindow); + // while user did not request to close this window (i.e press escape), draw + if (!glfwWindowShouldClose(glfwWindow)) + { + makeCurrentContext(glfwWindow); + + m_guiEngine->beforeDraw(glfwWindow); + sofaGlfwWindow->draw(m_groot, m_vparams); + m_guiEngine->afterDraw(); + + m_guiEngine->startFrame(this); + m_guiEngine->endFrame(); + + glfwSwapBuffers(glfwWindow); + + } + else + { + // otherwise close this window + close_callback(glfwWindow); + } } } - } - glfwPollEvents(); + glfwPollEvents(); + + currentNbIterations++; + running = (targetNbIterations > 0) ? currentNbIterations < targetNbIterations : true; + } - currentNbIterations++; - running = (targetNbIterations > 0) ? currentNbIterations < targetNbIterations : true; + return currentNbIterations; } - return currentNbIterations; -} + void SofaGLFWBaseGUI::initVisual() + { + sofa::simulation::node::initTextures(m_groot.get()); -void SofaGLFWBaseGUI::initVisual() -{ - sofa::simulation::node::initTextures(m_groot.get()); + component::visual::VisualStyle::SPtr visualStyle = nullptr; + m_groot->get(visualStyle); + if (!visualStyle) + { + visualStyle = sofa::core::objectmodel::New(); + visualStyle->setName(sofa::helper::NameDecoder::getShortName()); - component::visual::VisualStyle::SPtr visualStyle = nullptr; - m_groot->get(visualStyle); - if (!visualStyle) - { - visualStyle = sofa::core::objectmodel::New(); - visualStyle->setName(sofa::helper::NameDecoder::getShortName()); + core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit(); + displayFlags->setShowVisualModels(sofa::core::visual::tristate::true_value); + visualStyle->displayFlags.endEdit(); - core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit(); - displayFlags->setShowVisualModels(sofa::core::visual::tristate::true_value); - visualStyle->displayFlags.endEdit(); + m_groot->addObject(visualStyle); + visualStyle->init(); + } - m_groot->addObject(visualStyle); - visualStyle->init(); - } + //init gl states + glDepthFunc(GL_LEQUAL); + glClearDepth(1.0); + glEnable(GL_NORMALIZE); - //init gl states - glDepthFunc(GL_LEQUAL); - glClearDepth(1.0); - glEnable(GL_NORMALIZE); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + // Setup 'light 0' + float lightAmbient[4] = { 0.5f, 0.5f, 0.5f,1.0f }; + float lightDiffuse[4] = { 0.9f, 0.9f, 0.9f,1.0f }; + float lightSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; + float lightPosition[4] = { -0.7f, 0.3f, 0.0f,1.0f }; + glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular); + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - // Setup 'light 0' - float lightAmbient[4] = { 0.5f, 0.5f, 0.5f,1.0f }; - float lightDiffuse[4] = { 0.9f, 0.9f, 0.9f,1.0f }; - float lightSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; - float lightPosition[4] = { -0.7f, 0.3f, 0.0f,1.0f }; - glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular); - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - - // Enable color tracking - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + // Enable color tracking + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - // All materials hereafter have full specular reflectivity with a high shine - float materialSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; - glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); - glMateriali(GL_FRONT, GL_SHININESS, 128); + // All materials hereafter have full specular reflectivity with a high shine + float materialSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; + glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); + glMateriali(GL_FRONT, GL_SHININESS, 128); - glShadeModel(GL_SMOOTH); + glShadeModel(GL_SMOOTH); - glEnable(GL_LIGHT0); + glEnable(GL_LIGHT0); - m_vparams = sofa::core::visual::VisualParams::defaultInstance(); - for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) - { - sofaGlfwWindow->centerCamera(m_groot, m_vparams); + m_vparams = sofa::core::visual::VisualParams::defaultInstance(); + for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) + { + sofaGlfwWindow->centerCamera(m_groot, m_vparams); + } } -} -void SofaGLFWBaseGUI::runStep() -{ - if(simulationIsRunning()) + void SofaGLFWBaseGUI::runStep() { - sofa::helper::AdvancedTimer::begin("Animate"); + if(simulationIsRunning()) + { + sofa::helper::AdvancedTimer::begin("Animate"); - simulation::node::animate(m_groot.get(), m_groot->getDt()); - simulation::node::updateVisual(m_groot.get()); + simulation::node::animate(m_groot.get(), m_groot->getDt()); + simulation::node::updateVisual(m_groot.get()); - sofa::helper::AdvancedTimer::end("Animate"); + sofa::helper::AdvancedTimer::end("Animate"); + } } -} -void SofaGLFWBaseGUI::terminate() -{ - if (!m_bGlfwIsInitialized) - return; + void SofaGLFWBaseGUI::terminate() + { + if (!m_bGlfwIsInitialized) + return; - m_guiEngine->terminate(); + m_guiEngine->terminate(); - glfwTerminate(); -} + glfwTerminate(); + } -void SofaGLFWBaseGUI::error_callback(int error, const char* description) -{ - SOFA_UNUSED(error); - msg_error("SofaGLFWBaseGUI") << "Error: " << description << "."; -} + void SofaGLFWBaseGUI::error_callback(int error, const char* description) + { + SOFA_UNUSED(error); + msg_error("SofaGLFWBaseGUI") << "Error: " << description << "."; + } -int SofaGLFWBaseGUI::handleArrowKeys(int key) -{ - // Handling arrow keys with custom codes - switch (key) + int SofaGLFWBaseGUI::handleArrowKeys(int key) { + // Handling arrow keys with custom codes + switch (key) + { case GLFW_KEY_UP: return 19; // Custom code for up case GLFW_KEY_DOWN: return 21; // Custom code for down case GLFW_KEY_LEFT: return 18; // Custom code for left case GLFW_KEY_RIGHT: return 20; // Custom code for right + } + // Default case return the given value as GLFW handle it + return key; } - // Default case return the given value as GLFW handle it - return key; -} -void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ - const char keyName = SofaGLFWBaseGUI::handleArrowKeys(key); - const bool isCtrlKeyPressed = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; - - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI == s_mapGUIs.end() || currentGUI->second == nullptr) + void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - return; - } + const char keyName = SofaGLFWBaseGUI::handleArrowKeys(key); + const bool isCtrlKeyPressed = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; - auto rootNode = currentGUI->second->getRootNode(); - if (!rootNode) - { - return; - } + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI == s_mapGUIs.end() || currentGUI->second == nullptr) + { + return; + } - if (isCtrlKeyPressed) - { - if (action == GLFW_PRESS) + auto rootNode = currentGUI->second->getRootNode(); + if (!rootNode) + { + return; + } + + if (isCtrlKeyPressed) { - dmsg_info_when(key == GLFW_KEY_LEFT_CONTROL, "SofaGLFWBaseGUI") << "KeyPressEvent, CONTROL pressed"; + if (action == GLFW_PRESS) + { + dmsg_info_when(key == GLFW_KEY_LEFT_CONTROL, "SofaGLFWBaseGUI") << "KeyPressEvent, CONTROL pressed"; - sofa::core::objectmodel::KeypressedEvent keyPressedEvent(keyName); - rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyPressedEvent); + sofa::core::objectmodel::KeypressedEvent keyPressedEvent(keyName); + rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyPressedEvent); + } + else if (action == GLFW_RELEASE) + { + sofa::core::objectmodel::KeyreleasedEvent keyReleasedEvent(keyName); + rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyReleasedEvent); + } } - else if (action == GLFW_RELEASE) + + // Handle specific keys for additional functionality + switch (key) { - sofa::core::objectmodel::KeyreleasedEvent keyReleasedEvent(keyName); - rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyReleasedEvent); + case GLFW_KEY_F: + if (action == GLFW_PRESS && (mods & GLFW_MOD_CONTROL)) + { + currentGUI->second->switchFullScreen(window); + } + break; + case GLFW_KEY_ESCAPE: + if (action == GLFW_PRESS) + { + glfwSetWindowShouldClose(window, GLFW_TRUE); + } + break; + case GLFW_KEY_SPACE: + if (action == GLFW_PRESS) + { + const bool isRunning = currentGUI->second->simulationIsRunning(); + currentGUI->second->setSimulationIsRunning(!isRunning); + } + break; + case GLFW_KEY_LEFT_SHIFT: + if (action == GLFW_PRESS) + { + if (!currentGUI->second->getPickHandler()) std::cout<<"nooo pick"; + + const int viewport[4] = {}; + std::cout<<"key shft pressed\n"; + currentGUI->second->getPickHandler()->activateRay(viewport[2],viewport[3], rootNode.get()); + break; + } + } } - // Handle specific keys for additional functionality - switch (key) + + void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { - case GLFW_KEY_F: - if (action == GLFW_PRESS && (mods & GLFW_MOD_CONTROL)) + std::cout<<"callbackkkkkkkkkkk"; + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI == s_mapGUIs.end() || !currentGUI->second) + { + return; + } + + + auto rootNode = currentGUI->second->getRootNode(); + if (!rootNode) + { + return; + } + + bool shiftPressed = (mods & GLFW_MOD_SHIFT); + + if (shiftPressed) + { + std::cout << "Shift key pressed: " << shiftPressed << std::endl; + // Check if the animation is running + if (!currentGUI->second->simulationIsRunning()) { - currentGUI->second->switchFullScreen(window); + std::cout << "Animation is not running. Ignoring mouse interaction." << std::endl; + return; } - break; - case GLFW_KEY_ESCAPE: - if (action == GLFW_PRESS) + + + double xpos, ypos; + glfwGetCursorPos(window, &xpos, &ypos); + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { - glfwSetWindowShouldClose(window, GLFW_TRUE); + currentSofaWindow->second->mouseEvent(window, button, action, mods, xpos, ypos); } - break; - case GLFW_KEY_SPACE: - if (action == GLFW_PRESS) + } + else + { + if (currentGUI != s_mapGUIs.end() && currentGUI->second) + { + if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) + return; + } + + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { - const bool isRunning = currentGUI->second->simulationIsRunning(); - currentGUI->second->setSimulationIsRunning(!isRunning); + currentSofaWindow->second->mouseButtonEvent(button, action, mods); } - break; + } } -} -void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) -{ - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) + void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) { - if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) - return; - } + auto currentGUI = s_mapGUIs.find(window); - if (!currentGUI->second->m_isMouseInteractionEnabled) + if (currentGUI != s_mapGUIs.end() && currentGUI->second) + { + if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) + return; + } + + int width, height; + glfwGetFramebufferSize(window, &width, &height); + currentGUI->second->getPickHandler()->updateMouse2D({ static_cast(xpos), static_cast(ypos), width, height }); + + if (SofaGLFWBaseGUI::attachOperation) + { + SofaGLFWBaseGUI::attachOperation->execution(); + } + else + { + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + { + currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); + } + } + } + void SofaGLFWBaseGUI::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI != s_mapGUIs.end() && currentGUI->second) + { + if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) + return; + } + auto currentSofaWindow = s_mapWindows.find(window); if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { - currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos)); + currentSofaWindow->second->scrollEvent(xoffset, yoffset); } } -} -void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) -{ - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) - return; - } - - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + void SofaGLFWBaseGUI::close_callback(GLFWwindow* window) { - currentSofaWindow->second->mouseButtonEvent(button, action, mods); + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end()) + { + if (SofaGLFWWindow* glfwWindow = currentSofaWindow->second) + { + glfwWindow->close(); + delete glfwWindow; + } + s_mapWindows.erase(window); + } } -} -void SofaGLFWBaseGUI::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) -{ - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) + void SofaGLFWBaseGUI::window_focus_callback(GLFWwindow* window, int focused) { - if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) - return; + SOFA_UNUSED(window); + SOFA_UNUSED(focused); + //if (focused) + //{ + // // The window gained input focus + //} + //else + //{ + // // The window lost input focus + //} } - - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + void SofaGLFWBaseGUI::cursor_enter_callback(GLFWwindow* window, int entered) { - currentSofaWindow->second->scrollEvent(xoffset, yoffset); - } -} + SOFA_UNUSED(window); + SOFA_UNUSED(entered); -void SofaGLFWBaseGUI::close_callback(GLFWwindow* window) -{ - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end()) + //if (entered) + //{ + // // The cursor entered the content area of the window + //} + //else + //{ + // // The cursor left the content area of the window + //} + } + void SofaGLFWBaseGUI::monitor_callback(GLFWmonitor* monitor, int event) { - if (SofaGLFWWindow* glfwWindow = currentSofaWindow->second) - { - glfwWindow->close(); - delete glfwWindow; - } - s_mapWindows.erase(window); + SOFA_UNUSED(monitor); + SOFA_UNUSED(event); + + //if (event == GLFW_CONNECTED) + //{ + // // The monitor was connected + //} + //else if (event == GLFW_DISCONNECTED) + //{ + // // The monitor was disconnected + //} } -} -void SofaGLFWBaseGUI::window_focus_callback(GLFWwindow* window, int focused) -{ - SOFA_UNUSED(window); - SOFA_UNUSED(focused); - //if (focused) - //{ - // // The window gained input focus - //} - //else - //{ - // // The window lost input focus - //} -} -void SofaGLFWBaseGUI::cursor_enter_callback(GLFWwindow* window, int entered) -{ - SOFA_UNUSED(window); - SOFA_UNUSED(entered); - - //if (entered) - //{ - // // The cursor entered the content area of the window - //} - //else - //{ - // // The cursor left the content area of the window - //} -} -void SofaGLFWBaseGUI::monitor_callback(GLFWmonitor* monitor, int event) -{ - SOFA_UNUSED(monitor); - SOFA_UNUSED(event); - - //if (event == GLFW_CONNECTED) - //{ - // // The monitor was connected - //} - //else if (event == GLFW_DISCONNECTED) - //{ - // // The monitor was disconnected - //} -} - -void SofaGLFWBaseGUI::character_callback(GLFWwindow* window, unsigned int codepoint) -{ - SOFA_UNUSED(window); - SOFA_UNUSED(codepoint); + void SofaGLFWBaseGUI::character_callback(GLFWwindow* window, unsigned int codepoint) + { + SOFA_UNUSED(window); + SOFA_UNUSED(codepoint); - // The callback function receives Unicode code points for key events - // that would have led to regular text input and generally behaves as a standard text field on that platform. -} + // The callback function receives Unicode code points for key events + // that would have led to regular text input and generally behaves as a standard text field on that platform. + } } // namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 24e3e1401f..d988574abf 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -1,3 +1,4 @@ + /****************************************************************************** * SOFA, Simulation Open-Framework Architecture * * (c) 2006 INRIA, USTL, UJF, CNRS, MGH * @@ -29,116 +30,111 @@ #include #include - +#include #include +#include +#include + + struct GLFWwindow; struct GLFWmonitor; namespace sofaglfw { -class SofaGLFWWindow; - -class SOFAGLFW_API SofaGLFWBaseGUI -{ -public: - - SofaGLFWBaseGUI(); - - virtual ~SofaGLFWBaseGUI(); - - bool init(int nbMSAASamples = 0); - void setErrorCallback() const; - void setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename = std::string()); - void setSimulationIsRunning(bool running); - bool simulationIsRunning() const; - - bool createWindow(int width, int height, const char* title, bool fullscreenAtStartup = false); - void destroyWindow(); - void initVisual(); - std::size_t runLoop(std::size_t targetNbIterations = 0); - void terminate(); - - int getWindowWidth() const { return m_windowWidth; } - void setWindowWidth(int width) { m_windowWidth = width; } - int getWindowHeight() const { return m_windowHeight; } - void setWindowHeight(int height) { m_windowHeight = height; } - void resizeWindow(int width, int height); - - GLFWmonitor* getCurrentMonitor(GLFWwindow *window); - - bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; - void switchFullScreen(GLFWwindow* glfwWindow = nullptr, unsigned int /* screenID */ = 0); - void setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int /* windowID */ = 0); - void setBackgroundImage(const std::string& /* filename */, unsigned int /* windowID */ = 0); - - sofa::core::sptr getRootNode() const; - bool hasWindow() const { return m_firstWindow != nullptr; } - - [[nodiscard]] std::string getFilename() const - { - return m_filename; - } - - sofa::component::visual::BaseCamera::SPtr findCamera(sofa::simulation::NodeSPtr groot); - void changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera); - void setWindowIcon(GLFWwindow* glfwWindow); - - void setGUIEngine(std::shared_ptr guiEngine) - { - m_guiEngine = guiEngine; - } - - std::shared_ptr getGUIEngine() - { - return m_guiEngine; - } - -private: - // GLFW callbacks - static void error_callback(int error, const char* description); - static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); - static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos); - static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); - static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); - static void close_callback(GLFWwindow* window); - // empty (as in non-implemented) GLFW callbacks - static void window_focus_callback(GLFWwindow* window, int focused); - static void cursor_enter_callback(GLFWwindow* window, int entered); - static void monitor_callback(GLFWmonitor* monitor, int event); - static void character_callback(GLFWwindow* window, unsigned int codepoint); - - - static int handleArrowKeys(int key); - - void makeCurrentContext(GLFWwindow* sofaWindow); - void runStep(); - - // static members - inline static std::map< GLFWwindow*, SofaGLFWWindow*> s_mapWindows{}; - inline static std::map< GLFWwindow*, SofaGLFWBaseGUI*> s_mapGUIs{}; - - //members - bool m_bGlfwIsInitialized{ false }; - bool m_bGlewIsInitialized{ false }; - - sofa::simulation::NodeSPtr m_groot; - std::string m_filename; - sofa::gl::DrawToolGL* m_glDrawTool{ nullptr }; - sofa::core::visual::VisualParams* m_vparams{ nullptr }; - GLFWwindow* m_firstWindow{ nullptr }; - int m_windowWidth{ 0 }; - int m_windowHeight{ 0 }; - int m_lastWindowPositionX{ 0 }; - int m_lastWindowPositionY{ 0 }; - int m_lastWindowWidth{ 0 }; - int m_lastWindowHeight{ 0 }; - - bool m_isMouseInteractionEnabled { false }; - - std::shared_ptr m_guiEngine; - -}; - -} // namespace sofaglfw + class SofaGLFWWindow; + + class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { + public: + SofaGLFWBaseGUI(); + virtual ~SofaGLFWBaseGUI(); + bool init(int nbMSAASamples = 0); + void setErrorCallback() const; + void setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename = std::string()); + void setSimulationIsRunning(bool running); + bool simulationIsRunning() const; + bool createWindow(int width, int height, const char* title, bool fullscreenAtStartup = false); + void destroyWindow(); + void initVisual(); + std::size_t runLoop(std::size_t targetNbIterations = 0); + void terminate(); + + int getWindowWidth() const { return m_windowWidth; } + void setWindowWidth(int width) { m_windowWidth = width; } + int getWindowHeight() const { return m_windowHeight; } + void setWindowHeight(int height) { m_windowHeight = height; } + void resizeWindow(int width, int height); + + GLFWmonitor* getCurrentMonitor(GLFWwindow *window); + virtual void viewAll() override { std::cout << "viewAll() Called" << std::endl; } + virtual void saveView() override { std::cout << "saveView() Called" << std::endl; } + virtual void setSizeW(int width) override; + virtual void setSizeH(int height) override; + virtual int getWidth() override; + virtual int getHeight() override; + virtual void drawScene() override { std::cout << "drawScene() Called" << std::endl; } + virtual void redraw() override { std::cout << "redraw() Called" << std::endl; } + + bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; + void switchFullScreen(GLFWwindow* glfwWindow = nullptr, unsigned int screenID = 0); + void setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int windowID = 0); + virtual void setBackgroundImage(const std::string& imageFileName = "textures/SOFA_logo.bmp", unsigned int windowID = 0); + + sofa::core::sptr getRootNode() const; + bool hasWindow() const { return m_firstWindow != nullptr; } + + [[nodiscard]] std::string getFilename() const { return m_filename; } + + sofa::component::visual::BaseCamera::SPtr findCamera(sofa::simulation::NodeSPtr groot); + void changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera); + void setWindowIcon(GLFWwindow* glfwWindow); + + void setGUIEngine(std::shared_ptr guiEngine) { m_guiEngine = guiEngine; } + std::shared_ptr getGUIEngine() { return m_guiEngine; } + + private: + sofa::gui::common::PickHandler pickHandler; + static std::unique_ptr attachOperation; + + // GLFW callbacks + static void error_callback(int error, const char* description); + static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); + static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos); + static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); + static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); + static void close_callback(GLFWwindow* window); + static void window_focus_callback(GLFWwindow* window, int focused); + static void cursor_enter_callback(GLFWwindow* window, int entered); + static void monitor_callback(GLFWmonitor* monitor, int event); + static void character_callback(GLFWwindow* window, unsigned int codepoint); + + static int handleArrowKeys(int key); + + void makeCurrentContext(GLFWwindow* sofaWindow); + void runStep(); + + inline static std::map s_mapWindows{}; + inline static std::map s_mapGUIs{}; + + bool m_bGlfwIsInitialized{ false }; + bool m_bGlewIsInitialized{ false }; + + sofa::simulation::NodeSPtr m_groot; + std::string m_filename; + sofa::gl::DrawToolGL* m_glDrawTool{ nullptr }; + sofa::core::visual::VisualParams* m_vparams{ nullptr }; + GLFWwindow* m_firstWindow{ nullptr }; + int m_windowWidth{ 0 }; + int m_windowHeight{ 0 }; + int m_lastWindowPositionX{ 0 }; + int m_lastWindowPositionY{ 0 }; + int m_lastWindowWidth{ 0 }; + int m_lastWindowHeight{ 0 }; + + bool m_isMouseInteractionEnabled{ false }; + + std::shared_ptr m_guiEngine; + }; + +} // namespace sofaglfw \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index a838cea84d..8de0b75203 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -20,6 +20,10 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include +#include +#include +#include + #define GLFW_INCLUDE_NONE #include @@ -29,173 +33,254 @@ #include #include #include +#include +#include +#include +using namespace sofa; namespace sofaglfw { -SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) - : m_glfwWindow(glfwWindow) - , m_currentCamera(camera) -{ -} - -void SofaGLFWWindow::close() -{ - glfwDestroyWindow(m_glfwWindow); -} - - -void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams) -{ - glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); - glClearDepth(1.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glEnable(GL_LIGHTING); - glEnable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); - - // draw the scene - if (!m_currentCamera) + SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) + : m_glfwWindow(glfwWindow) + , m_currentCamera(camera) { - msg_error("SofaGLFWGUI") << "No camera defined."; - return; - } - if (groot->f_bbox.getValue().isValid()) - { - vparams->sceneBBox() = groot->f_bbox.getValue(); - m_currentCamera->setBoundingBox(vparams->sceneBBox().minBBox(), vparams->sceneBBox().maxBBox()); } - m_currentCamera->computeZ(); - m_currentCamera->p_widthViewport.setValue(vparams->viewport()[2]); - m_currentCamera->p_heightViewport.setValue(vparams->viewport()[3]); - - // matrices - double projectionMatrix[16]; - double mvMatrix[16]; - m_currentCamera->getOpenGLProjectionMatrix(projectionMatrix); - m_currentCamera->getOpenGLModelViewMatrix(mvMatrix); - glViewport(0, 0, vparams->viewport()[2], vparams->viewport()[3]); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMultMatrixd(projectionMatrix); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMultMatrixd(mvMatrix); - - // Update the visual params - vparams->zNear() = m_currentCamera->getZNear(); - vparams->zFar() = m_currentCamera->getZFar(); - vparams->setProjectionMatrix(projectionMatrix); - vparams->setModelViewMatrix(mvMatrix); + void SofaGLFWWindow::close() + { + glfwDestroyWindow(m_glfwWindow); + } - sofa::simulation::node::draw(vparams, groot.get()); -} + void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams) + { + glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); + glClearDepth(1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -void SofaGLFWWindow::setBackgroundColor(const sofa::type::RGBAColor& newColor) -{ - m_backgroundColor = newColor; -} + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + glDisable(GL_COLOR_MATERIAL); -void SofaGLFWWindow::setCamera(sofa::component::visual::BaseCamera::SPtr newCamera) -{ - m_currentCamera = newCamera; -} + // draw the scene + if (!m_currentCamera) + { + msg_error("SofaGLFWGUI") << "No camera defined."; + return; + } -void SofaGLFWWindow::centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const -{ - if (m_currentCamera) - { - int width, height; - glfwGetFramebufferSize(m_glfwWindow, &width, &height); - if (node->f_bbox.getValue().isValid()) + if (groot->f_bbox.getValue().isValid()) { - vparams->sceneBBox() = node->f_bbox.getValue(); + vparams->sceneBBox() = groot->f_bbox.getValue(); m_currentCamera->setBoundingBox(vparams->sceneBBox().minBBox(), vparams->sceneBBox().maxBBox()); } + m_currentCamera->computeZ(); + m_currentCamera->p_widthViewport.setValue(vparams->viewport()[2]); + m_currentCamera->p_heightViewport.setValue(vparams->viewport()[3]); + + // matrices + double projectionMatrix[16]; + double mvMatrix[16]; + m_currentCamera->getOpenGLProjectionMatrix(projectionMatrix); + m_currentCamera->getOpenGLModelViewMatrix(mvMatrix); + + glViewport(0, 0, vparams->viewport()[2], vparams->viewport()[3]); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMultMatrixd(projectionMatrix); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMultMatrixd(mvMatrix); // Update the visual params - vparams->viewport() = { 0, 0, width, height }; vparams->zNear() = m_currentCamera->getZNear(); vparams->zFar() = m_currentCamera->getZFar(); + vparams->setProjectionMatrix(projectionMatrix); + vparams->setModelViewMatrix(mvMatrix); + + sofa::simulation::node::draw(vparams, groot.get()); - m_currentCamera->fitBoundingBox(node->f_bbox.getValue().minBBox(), node->f_bbox.getValue().maxBBox()); } -} -void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos) -{ - switch (m_currentAction) + void SofaGLFWWindow::setBackgroundColor(const sofa::type::RGBAColor& newColor) { - case GLFW_PRESS: + m_backgroundColor = newColor; + } + + void SofaGLFWWindow::setCamera(sofa::component::visual::BaseCamera::SPtr newCamera) { - sofa::core::objectmodel::MouseEvent* mEvent = nullptr; - if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::LeftPressed, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightPressed, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); - else { - // A fallback event to rule them all... - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); - } - m_currentCamera->manageEvent(mEvent); - m_currentXPos = xpos; - m_currentYPos = ypos; - break; + m_currentCamera = newCamera; } - case GLFW_RELEASE: + + void SofaGLFWWindow::centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const { - sofa::core::objectmodel::MouseEvent* mEvent = nullptr; - if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::LeftReleased, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightReleased, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); - else { - // A fallback event to rules them all... - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); + if (m_currentCamera) + { + int width, height; + glfwGetFramebufferSize(m_glfwWindow, &width, &height); + if (node->f_bbox.getValue().isValid()) + { + vparams->sceneBBox() = node->f_bbox.getValue(); + m_currentCamera->setBoundingBox(vparams->sceneBBox().minBBox(), vparams->sceneBBox().maxBBox()); + } + + // Update the visual params + vparams->viewport() = { 0, 0, width, height }; + vparams->zNear() = m_currentCamera->getZNear(); + vparams->zFar() = m_currentCamera->getZFar(); + + m_currentCamera->fitBoundingBox(node->f_bbox.getValue().minBBox(), node->f_bbox.getValue().maxBBox()); } - m_currentCamera->manageEvent(mEvent); + } + + void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui) + { m_currentXPos = xpos; m_currentYPos = ypos; - break; + switch (m_currentAction) + { + case GLFW_PRESS: + { + sofa::core::objectmodel::MouseEvent* mEvent = nullptr; + if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::LeftPressed, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightPressed, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); + else { + // A fallback event to rule them all... + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); + } + m_currentCamera->manageEvent(mEvent); + + auto rootNode = gui->getRootNode(); + + rootNode->propagateEvent(core::execparams::defaultInstance(), mEvent); + + break; + } + case GLFW_RELEASE: + { + sofa::core::objectmodel::MouseEvent* mEvent = nullptr; + if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::LeftReleased, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightReleased, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); + else { + // A fallback event to rules them all... + mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); + } + m_currentCamera->manageEvent(mEvent); + + auto rootNode = gui->getRootNode(); + + rootNode->propagateEvent(core::execparams::defaultInstance(), mEvent); + + break; + } + + default: + { + sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Move, xpos, ypos); + m_currentCamera->manageEvent(&me); + break; + } + } + + m_currentButton = -1; + m_currentAction = -1; + m_currentMods = -1; } - default: + void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) { - sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Move, xpos, ypos); - m_currentCamera->manageEvent(&me); - break; - } + // Only change state on button press; release resets state to neutral + m_currentButton = button; + m_currentAction = action; + m_currentMods = mods; + } - m_currentButton = -1; - m_currentAction = -1; - m_currentMods = -1; -} + bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int button, int action, int mods, double xpos, double ypos) + { + std::cout<<"mouse event"; + if (!m_currentCamera) + return true; -void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) -{ - m_currentButton = button; - m_currentAction = action; - m_currentMods = mods; -} + int width, height; + glfwGetFramebufferSize(window, &width, &height); + sofa::gui::common::MousePosition mousepos; + mousepos.screenWidth = width; + mousepos.screenHeight = height; + mousepos.x = static_cast(xpos); + mousepos.y = static_cast(ypos); -void SofaGLFWWindow::scrollEvent(double xoffset, double yoffset) -{ - SOFA_UNUSED(xoffset); - const double yFactor = 10.f; - sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Wheel, static_cast(yoffset * yFactor)); - m_currentCamera->manageEvent(&me); -} + if (mods & GLFW_MOD_SHIFT) + { + auto gui = static_cast(glfwGetWindowUserPointer(window)); + auto rootNode = gui->getRootNode(); + + gui->getPickHandler()->activateRay(width, height, rootNode.get()); + gui->getPickHandler()->updateMouse2D(mousepos); + + if (action == GLFW_PRESS) + { + if (button == GLFW_MOUSE_BUTTON_LEFT) + { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::LEFT); + } + else if (button == GLFW_MOUSE_BUTTON_RIGHT) + { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::RIGHT); + } + else if (button == GLFW_MOUSE_BUTTON_MIDDLE) + { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::MIDDLE); + } + } + else if (action == GLFW_RELEASE) + { + if (button == GLFW_MOUSE_BUTTON_LEFT) + { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::LEFT); + } + else if (button == GLFW_MOUSE_BUTTON_RIGHT) + { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::RIGHT); + } + else if (button == GLFW_MOUSE_BUTTON_MIDDLE) + { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::MIDDLE); + } + } + + gui->moveRayPickInteractor(xpos, ypos); + } + else + { + auto gui = static_cast(glfwGetWindowUserPointer(window)); + auto rootNode = gui->getRootNode(); + + gui->getPickHandler()->activateRay(width, height, rootNode.get()); + } + return true; + } + + void SofaGLFWWindow::scrollEvent(double xoffset, double yoffset) + { + SOFA_UNUSED(xoffset); + const double yFactor = 10.f; + sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Wheel, static_cast(yoffset * yFactor)); + m_currentCamera->manageEvent(&me); + } } // namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h index f834c415da..b3b9562e49 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h @@ -24,38 +24,40 @@ #include #include +#include "SofaGLFWBaseGUI.h" struct GLFWwindow; namespace sofaglfw { -class SOFAGLFW_API SofaGLFWWindow -{ -public: - SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera); - virtual ~SofaGLFWWindow() = default; - - void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams); - void close(); - - void mouseMoveEvent(int xpos, int ypos); - void mouseButtonEvent(int button, int action, int mods); - void scrollEvent(double xoffset, double yoffset); - void setBackgroundColor(const sofa::type::RGBAColor& newColor); - - void setCamera(sofa::component::visual::BaseCamera::SPtr newCamera); - void centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const; - -private: - GLFWwindow* m_glfwWindow{nullptr}; - sofa::component::visual::BaseCamera::SPtr m_currentCamera; - int m_currentButton{ -1 }; - int m_currentAction{ -1 }; - int m_currentMods{ -1 }; - int m_currentXPos{ -1 }; - int m_currentYPos{ -1 }; - sofa::type::RGBAColor m_backgroundColor{ sofa::type::RGBAColor::black() }; -}; + class SOFAGLFW_API SofaGLFWWindow + { + public: + SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera); + virtual ~SofaGLFWWindow() = default; + + void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams); + void close(); + + void mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui); + void mouseButtonEvent(int button, int action, int mods); + void scrollEvent(double xoffset, double yoffset); + void setBackgroundColor(const sofa::type::RGBAColor& newColor); + + void setCamera(sofa::component::visual::BaseCamera::SPtr newCamera); + void centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const; + bool mouseEvent(GLFWwindow* window, int button, int action, int mods, double xpos, double ypos); // Declaration for mouseEvent function + + private: + GLFWwindow* m_glfwWindow{nullptr}; + sofa::component::visual::BaseCamera::SPtr m_currentCamera; + int m_currentButton{ -1 }; + int m_currentAction{ -1 }; + int m_currentMods{ -1 }; + int m_currentXPos{ -1 }; + int m_currentYPos{ -1 }; + sofa::type::RGBAColor m_backgroundColor{ sofa::type::RGBAColor::black() }; + }; } // namespace sofaglfw From 229b02207d9b93a292e92e13da83dd1cde2da84c Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 25 Jun 2024 12:18:44 +0200 Subject: [PATCH 11/41] update --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 21 ++++++++++++++++++++- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 3e10790ec5..8d5c9c9500 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -610,7 +610,6 @@ namespace sofaglfw void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { - std::cout<<"callbackkkkkkkkkkk"; auto currentGUI = s_mapGUIs.find(window); if (currentGUI == s_mapGUIs.end() || !currentGUI->second) { @@ -636,6 +635,26 @@ namespace sofaglfw return; } + if (!SofaGLFWBaseGUI::attachOperation) + { + try + { + std::cout << "Creating AttachBodyButtonSetting" << std::endl; + auto attachSetting = sofa::core::objectmodel::New(); + std::cout << "Creating AttachOperation" << std::endl; + SofaGLFWBaseGUI::attachOperation = std::make_unique(attachSetting); + std::cout << "Configuring AttachOperation" << std::endl; + SofaGLFWBaseGUI::attachOperation->configure(currentGUI->second->getPickHandler(), sofa::gui::common::LEFT); + std::cout << "Starting AttachOperation" << std::endl; + SofaGLFWBaseGUI::attachOperation->start(); + + } + catch (const std::exception& e) + { + std::cerr << "Exception during AttachOperation creation or start: " << e.what() << std::endl; + return; + } + } double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos); diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index d988574abf..7340762885 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -60,6 +60,7 @@ namespace sofaglfw std::size_t runLoop(std::size_t targetNbIterations = 0); void terminate(); + void configureAttachOperation(); int getWindowWidth() const { return m_windowWidth; } void setWindowWidth(int width) { m_windowWidth = width; } int getWindowHeight() const { return m_windowHeight; } From 1d49525ddd13020de41c562eadc677b0fa72c2dd Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 23 Jul 2024 15:08:25 +0200 Subject: [PATCH 12/41] update --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 157 ++++++++++++++------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 9 +- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 88 ++++++------ SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h | 2 +- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 2 +- 5 files changed, 159 insertions(+), 99 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 8d5c9c9500..71b9b57199 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -21,6 +21,8 @@ ******************************************************************************/ #include + + #define GLFW_INCLUDE_NONE #include @@ -54,12 +56,36 @@ using namespace sofa; using namespace sofa::gui::common; +using std::endl; +using namespace sofa::type; +using namespace sofa::defaulttype; +using namespace sofa::gl; +using sofa::simulation::getSimulation; +using namespace sofa::simulation; +using namespace sofa::gui::common; + namespace sofaglfw { - std::unique_ptr SofaGLFWBaseGUI::attachOperation; - SofaGLFWBaseGUI::SofaGLFWBaseGUI():BaseViewer() + SofaGLFWBaseGUI::SofaGLFWBaseGUI() + :BaseViewer() { m_guiEngine = std::make_shared(); + //By changing the operation, we delete the previous operation + RegisterOperation("attach").add(); + RegisterOperation("Attach").add< AttachOperation >(); + RegisterOperation("AddFrame").add< AddFrameOperation >(); + RegisterOperation("SaveCameraViewPoint").add< AddRecordedCameraOperation >(); + RegisterOperation("StartNavigation").add< StartNavigationOperation >(); + RegisterOperation("Fix") .add< FixOperation >(); + RegisterOperation("Incise").add< InciseOperation >(); + RegisterOperation("Remove").add< TopologyOperation >(); + RegisterOperation("Suture").add< AddSutureOperation >(); + RegisterOperation("ConstraintAttach").add< ConstraintAttachOperation >(); + this->pick->changeOperation( LEFT, "Attach"); + this->pick->changeOperation( MIDDLE, "Incise"); + this->pick->changeOperation( RIGHT, "Remove"); + + } SofaGLFWBaseGUI::~SofaGLFWBaseGUI() @@ -109,7 +135,7 @@ namespace sofaglfw if (m_groot) { // Initialize the pick handler - pickHandler.init(m_groot.get()); + this->pick->init(m_groot.get()); } } @@ -191,7 +217,7 @@ namespace sofaglfw sofa::helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); } - bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) + bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) { m_guiEngine->init(); @@ -414,7 +440,7 @@ namespace sofaglfw makeCurrentContext(glfwWindow); m_guiEngine->beforeDraw(glfwWindow); - sofaGlfwWindow->draw(m_groot, m_vparams); + sofaGlfwWindow->draw(m_groot, m_vparams,lastModelviewMatrix,lastProjectionMatrix); m_guiEngine->afterDraw(); m_guiEngine->startFrame(this); @@ -596,66 +622,106 @@ namespace sofaglfw case GLFW_KEY_LEFT_SHIFT: if (action == GLFW_PRESS) { - if (!currentGUI->second->getPickHandler()) std::cout<<"nooo pick"; - const int viewport[4] = {}; std::cout<<"key shft pressed\n"; currentGUI->second->getPickHandler()->activateRay(viewport[2],viewport[3], rootNode.get()); break; } + else + { + if (currentGUI->second->getPickHandler()) + currentGUI->second->getPickHandler()->deactivateRay(); + break; + } } } + void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) + { + std::cout <<"\n\nmove ray\n"; - void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) - { + const sofa::core::visual::VisualParams::Viewport& viewport = m_vparams->viewport(); + + Vec3d p0; + Vec3d px; + Vec3d py; + Vec3d pz; + Vec3d px1; + Vec3d py1; + gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); + + + px1 -= pz; + py1 -= pz; + px -= p0; + py -= p0; + pz -= p0; + const double r0 = sqrt(px.norm2() + py.norm2()); + double r1 = sqrt(px1.norm2() + py1.norm2()); + r1 = r0 + (r1 - r0) / pz.norm(); + px.normalize(); + py.normalize(); + pz.normalize(); + + Mat4x4d transform; + transform.identity(); + transform[0][0] = px[0]; + transform[1][0] = px[1]; + transform[2][0] = px[2]; + transform[0][1] = py[0]; + transform[1][1] = py[1]; + transform[2][1] = py[2]; + transform[0][2] = pz[0]; + transform[1][2] = pz[1]; + transform[2][2] = pz[2]; + transform[0][3] = p0[0]; + transform[1][3] = p0[1]; + transform[2][3] = p0[2]; + + Mat3x3d mat; + mat = transform; + Quat q; + q.fromMatrix(mat); + + Vec3d position, direction; + position = transform * Vec4d(0, 0, 0, 1); + direction = transform * Vec4d(0, 0, 1, 0); + direction.normalize(); + this->pick->updateRay(position, direction); + } + + + + + void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { auto currentGUI = s_mapGUIs.find(window); - if (currentGUI == s_mapGUIs.end() || !currentGUI->second) - { + if (currentGUI == s_mapGUIs.end() || !currentGUI->second) { return; } auto rootNode = currentGUI->second->getRootNode(); - if (!rootNode) - { + if (!rootNode) { return; } - bool shiftPressed = (mods & GLFW_MOD_SHIFT); + int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); - if (shiftPressed) + if (shiftPressed && state == GLFW_PRESS) { std::cout << "Shift key pressed: " << shiftPressed << std::endl; // Check if the animation is running - if (!currentGUI->second->simulationIsRunning()) - { + if (!currentGUI->second->simulationIsRunning()) { std::cout << "Animation is not running. Ignoring mouse interaction." << std::endl; return; } - if (!SofaGLFWBaseGUI::attachOperation) - { - try - { - std::cout << "Creating AttachBodyButtonSetting" << std::endl; - auto attachSetting = sofa::core::objectmodel::New(); - std::cout << "Creating AttachOperation" << std::endl; - SofaGLFWBaseGUI::attachOperation = std::make_unique(attachSetting); - std::cout << "Configuring AttachOperation" << std::endl; - SofaGLFWBaseGUI::attachOperation->configure(currentGUI->second->getPickHandler(), sofa::gui::common::LEFT); - std::cout << "Starting AttachOperation" << std::endl; - SofaGLFWBaseGUI::attachOperation->start(); - - } - catch (const std::exception& e) - { - std::cerr << "Exception during AttachOperation creation or start: " << e.what() << std::endl; - return; - } - } - double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos); auto currentSofaWindow = s_mapWindows.find(window); @@ -663,6 +729,7 @@ namespace sofaglfw { currentSofaWindow->second->mouseEvent(window, button, action, mods, xpos, ypos); } + } else { @@ -690,22 +757,14 @@ namespace sofaglfw return; } - int width, height; - glfwGetFramebufferSize(window, &width, &height); - currentGUI->second->getPickHandler()->updateMouse2D({ static_cast(xpos), static_cast(ypos), width, height }); - - if (SofaGLFWBaseGUI::attachOperation) - { - SofaGLFWBaseGUI::attachOperation->execution(); - } - else - { auto currentSofaWindow = s_mapWindows.find(window); if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); } - } + + + } void SofaGLFWBaseGUI::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 7340762885..680c0a0d1a 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -93,10 +93,14 @@ namespace sofaglfw void setGUIEngine(std::shared_ptr guiEngine) { m_guiEngine = guiEngine; } std::shared_ptr getGUIEngine() { return m_guiEngine; } + void moveRayPickInteractor(int eventX, int eventY) override ; private: - sofa::gui::common::PickHandler pickHandler; static std::unique_ptr attachOperation; + static void handleShiftMouseButton(GLFWwindow* window, SofaGLFWBaseGUI* gui, int button, int action, double xpos, double ypos); + static void handleRegularMouseButton(GLFWwindow* window, SofaGLFWBaseGUI* gui, int button, int action, int mods); + static void initializeAttachOperation(SofaGLFWBaseGUI* gui); + // GLFW callbacks static void error_callback(int error, const char* description); @@ -132,7 +136,8 @@ namespace sofaglfw int m_lastWindowPositionY{ 0 }; int m_lastWindowWidth{ 0 }; int m_lastWindowHeight{ 0 }; - + double lastProjectionMatrix[16]; + double lastModelviewMatrix[16]; bool m_isMouseInteractionEnabled{ false }; std::shared_ptr m_guiEngine; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 8de0b75203..01f90e7d68 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -56,7 +56,7 @@ namespace sofaglfw } - void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams) + void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]) { glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); glClearDepth(1.0); @@ -73,6 +73,14 @@ namespace sofaglfw return; } + + m_currentCamera->getProjectionMatrix( lastProjectionMatrix ); + + m_currentCamera->getModelViewMatrix( lastModelviewMatrix ); + vparams->setModelViewMatrix( lastModelviewMatrix ); + + vparams->setProjectionMatrix( lastProjectionMatrix ); + if (groot->f_bbox.getValue().isValid()) { vparams->sceneBBox() = groot->f_bbox.getValue(); @@ -82,6 +90,8 @@ namespace sofaglfw m_currentCamera->p_widthViewport.setValue(vparams->viewport()[2]); m_currentCamera->p_heightViewport.setValue(vparams->viewport()[3]); + m_currentCamera->getModelViewMatrix( lastModelviewMatrix ); + vparams->setModelViewMatrix( lastModelviewMatrix ); // matrices double projectionMatrix[16]; double mvMatrix[16]; @@ -138,7 +148,8 @@ namespace sofaglfw } } - void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui) + + void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos, SofaGLFWBaseGUI* gui) { m_currentXPos = xpos; m_currentYPos = ypos; @@ -153,7 +164,8 @@ namespace sofaglfw mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightPressed, xpos, ypos); else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); - else { + else + { // A fallback event to rule them all... mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); } @@ -174,7 +186,8 @@ namespace sofaglfw mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightReleased, xpos, ypos); else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); - else { + else + { // A fallback event to rules them all... mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); } @@ -186,7 +199,6 @@ namespace sofaglfw break; } - default: { sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Move, xpos, ypos); @@ -199,7 +211,6 @@ namespace sofaglfw m_currentAction = -1; m_currentMods = -1; } - void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) { // Only change state on button press; release resets state to neutral @@ -209,9 +220,8 @@ namespace sofaglfw } - bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int button, int action, int mods, double xpos, double ypos) - { - std::cout<<"mouse event"; + bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int button, int action, int mods, double xpos, double ypos) { + std::cout <<"mouse event glfw\n\n"; if (!m_currentCamera) return true; @@ -223,57 +233,43 @@ namespace sofaglfw mousepos.screenHeight = height; mousepos.x = static_cast(xpos); mousepos.y = static_cast(ypos); + auto gui = static_cast(glfwGetWindowUserPointer(window)); + auto rootNode = gui->getRootNode(); + if (mods & GLFW_MOD_SHIFT) { - if (mods & GLFW_MOD_SHIFT) - { - auto gui = static_cast(glfwGetWindowUserPointer(window)); - auto rootNode = gui->getRootNode(); + std::cout <<" if (mods & GLFW_MOD_SHIFT) {n\n"; gui->getPickHandler()->activateRay(width, height, rootNode.get()); gui->getPickHandler()->updateMouse2D(mousepos); - if (action == GLFW_PRESS) - { - if (button == GLFW_MOUSE_BUTTON_LEFT) - { + if (action == GLFW_PRESS) { + if (button == GLFW_MOUSE_BUTTON_LEFT) { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::LEFT); - } - else if (button == GLFW_MOUSE_BUTTON_RIGHT) - { + } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::RIGHT); - } - else if (button == GLFW_MOUSE_BUTTON_MIDDLE) - { + } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::MIDDLE); } - } - else if (action == GLFW_RELEASE) - { - if (button == GLFW_MOUSE_BUTTON_LEFT) - { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::LEFT); - } - else if (button == GLFW_MOUSE_BUTTON_RIGHT) - { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::RIGHT); - } - else if (button == GLFW_MOUSE_BUTTON_MIDDLE) - { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::MIDDLE); + } else if (action == GLFW_RELEASE) { + if (action == GLFW_RELEASE) { + if (button == GLFW_MOUSE_BUTTON_LEFT) { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::LEFT); + } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::RIGHT); + } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { + gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::MIDDLE); + } } } - gui->moveRayPickInteractor(xpos, ypos); - } - else - { - auto gui = static_cast(glfwGetWindowUserPointer(window)); - auto rootNode = gui->getRootNode(); + gui->moveRayPickInteractor(xpos, ypos); + } else { - gui->getPickHandler()->activateRay(width, height, rootNode.get()); + gui->getPickHandler()->activateRay(width, height, rootNode.get()); + } + return true; } - return true; - } + void SofaGLFWWindow::scrollEvent(double xoffset, double yoffset) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h index b3b9562e49..6baca1648a 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h @@ -37,7 +37,7 @@ namespace sofaglfw SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera); virtual ~SofaGLFWWindow() = default; - void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams); + void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams,double lastModelviewMatrix [16],double lastProjectionMatrix[16]); void close(); void mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui); diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 191b562b72..90f5247cfd 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -614,7 +614,7 @@ void ImGuiGUIEngine::beforeDraw(GLFWwindow*) if (!m_fbo) { m_fbo = std::make_unique(); - m_currentFBOSize = {500, 500}; + m_currentFBOSize = {1000, 500}; m_fbo->init(m_currentFBOSize.first, m_currentFBOSize.second); } else From a9e0de80a647aefd982d2c2f476784298506e2f4 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Mon, 29 Jul 2024 17:23:56 +0200 Subject: [PATCH 13/41] first result --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 38 ++++++++++++++++++---- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 5 ++- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 30 +++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h | 2 +- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 3 ++ 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 71b9b57199..0bddb9f3c6 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -640,8 +640,10 @@ namespace sofaglfw void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) { std::cout <<"\n\nmove ray\n"; + std::cout<<"\n\n::::moveRayPickInteractor::: xpos\t"<viewport(); + std::cout <<"\n "<< viewport.data(); Vec3d p0; Vec3d px; @@ -693,7 +695,7 @@ namespace sofaglfw position = transform * Vec4d(0, 0, 0, 1); direction = transform * Vec4d(0, 0, 1, 0); direction.normalize(); - this->pick->updateRay(position, direction); + this->pick->updateRay(position, direction); } @@ -704,17 +706,24 @@ namespace sofaglfw if (currentGUI == s_mapGUIs.end() || !currentGUI->second) { return; } + SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); + + const sofa::core::visual::VisualParams::Viewport& viewport = gui->m_vparams->viewport(); + std::cout << "Viewport Size: " << viewport[2] << "x" << viewport[3] << std::endl; auto rootNode = currentGUI->second->getRootNode(); if (!rootNode) { return; } - bool shiftPressed = (mods & GLFW_MOD_SHIFT); + bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); - - if (shiftPressed && state == GLFW_PRESS) +std::cout << "\n\n\tstate\t"<second->simulationIsRunning()) { @@ -724,12 +733,16 @@ namespace sofaglfw double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos); + + +std::cout<<"\n\n::::::::::: xpos\t"<second) { - currentSofaWindow->second->mouseEvent(window, button, action, mods, xpos, ypos); + currentSofaWindow->second->mouseEvent(window,viewport[2],viewport[3], button, action, mods, xpos, ypos); } + } else { @@ -756,10 +769,23 @@ namespace sofaglfw if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) return; } + ypos-=49; + xpos-=8; - auto currentSofaWindow = s_mapWindows.find(window); + bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); + auto currentSofaWindow = s_mapWindows.find(window); + if (shiftPressed && state == GLFW_PRESS) + { + const sofa::core::visual::VisualParams::Viewport& viewport = currentGUI->second->m_vparams->viewport(); + + currentSofaWindow->second->mouseEvent(window,viewport[2],viewport[3], 0, 1, 1, xpos, ypos); + + + } if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { + currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 680c0a0d1a..982c85136b 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -59,7 +59,10 @@ namespace sofaglfw void initVisual(); std::size_t runLoop(std::size_t targetNbIterations = 0); void terminate(); - + void convertWindowToViewportCoords(double windowX, double windowY, + int viewportX, int viewportY, + int viewportWidth, int viewportHeight, + double& viewportXOut, double& viewportYOut); void configureAttachOperation(); int getWindowWidth() const { return m_windowWidth; } void setWindowWidth(int width) { m_windowWidth = width; } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 01f90e7d68..2be971d214 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -74,12 +74,6 @@ namespace sofaglfw } - m_currentCamera->getProjectionMatrix( lastProjectionMatrix ); - - m_currentCamera->getModelViewMatrix( lastModelviewMatrix ); - vparams->setModelViewMatrix( lastModelviewMatrix ); - - vparams->setProjectionMatrix( lastProjectionMatrix ); if (groot->f_bbox.getValue().isValid()) { @@ -95,23 +89,23 @@ namespace sofaglfw // matrices double projectionMatrix[16]; double mvMatrix[16]; - m_currentCamera->getOpenGLProjectionMatrix(projectionMatrix); - m_currentCamera->getOpenGLModelViewMatrix(mvMatrix); + m_currentCamera->getOpenGLProjectionMatrix(lastProjectionMatrix); + m_currentCamera->getOpenGLModelViewMatrix(lastModelviewMatrix); glViewport(0, 0, vparams->viewport()[2], vparams->viewport()[3]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glMultMatrixd(projectionMatrix); + glMultMatrixd(lastProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glMultMatrixd(mvMatrix); + glMultMatrixd(lastModelviewMatrix); // Update the visual params vparams->zNear() = m_currentCamera->getZNear(); vparams->zFar() = m_currentCamera->getZFar(); - vparams->setProjectionMatrix(projectionMatrix); - vparams->setModelViewMatrix(mvMatrix); + vparams->setProjectionMatrix(lastProjectionMatrix); + vparams->setModelViewMatrix(lastModelviewMatrix); sofa::simulation::node::draw(vparams, groot.get()); @@ -220,22 +214,21 @@ namespace sofaglfw } - bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int button, int action, int mods, double xpos, double ypos) { + bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int width, int height,int button, int action, int mods, double xpos, double ypos) { std::cout <<"mouse event glfw\n\n"; if (!m_currentCamera) return true; - int width, height; - glfwGetFramebufferSize(window, &width, &height); + SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); + - sofa::gui::common::MousePosition mousepos; + sofa::gui::common::MousePosition mousepos; mousepos.screenWidth = width; mousepos.screenHeight = height; mousepos.x = static_cast(xpos); mousepos.y = static_cast(ypos); - auto gui = static_cast(glfwGetWindowUserPointer(window)); auto rootNode = gui->getRootNode(); - if (mods & GLFW_MOD_SHIFT) { + if ( GLFW_MOD_SHIFT) { std::cout <<" if (mods & GLFW_MOD_SHIFT) {n\n"; @@ -254,6 +247,7 @@ namespace sofaglfw if (action == GLFW_RELEASE) { if (button == GLFW_MOUSE_BUTTON_LEFT) { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::LEFT); + gui->getPickHandler()->deactivateRay(); } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::RIGHT); } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h index 6baca1648a..14b001dd69 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h @@ -47,7 +47,7 @@ namespace sofaglfw void setCamera(sofa::component::visual::BaseCamera::SPtr newCamera); void centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const; - bool mouseEvent(GLFWwindow* window, int button, int action, int mods, double xpos, double ypos); // Declaration for mouseEvent function + bool mouseEvent(GLFWwindow* window,int width,int height ,int button, int action, int mods, double xpos, double ypos); // Declaration for mouseEvent function private: GLFWwindow* m_glfwWindow{nullptr}; diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 80b0840627..d1a92f2309 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -227,9 +227,12 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; + ImGui::SetNextWindowPos(viewport->Pos); ImGui::SetNextWindowSize(viewport->Size); ImGui::SetNextWindowViewport(viewport->ID); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; From ab4a5d3744f4efd7157b20b62a4227da0d872c27 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 30 Jul 2024 18:58:38 +0200 Subject: [PATCH 14/41] everything works (not clean) --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 32 ++++++++++++--- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 11 +++-- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 11 ++--- SofaImGui/src/SofaImGui/ImGuiGUIEngine.h | 3 +- SofaImGui/src/SofaImGui/windows/ViewPort.cpp | 42 ++++++++++++++++++-- SofaImGui/src/SofaImGui/windows/ViewPort.h | 6 ++- 6 files changed, 83 insertions(+), 22 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 0bddb9f3c6..9f9db1db5c 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -257,7 +257,7 @@ namespace sofaglfw glfwSetMouseButtonCallback(glfwWindow, mouse_button_callback); glfwSetScrollCallback(glfwWindow, scroll_callback); glfwSetWindowCloseCallback(glfwWindow, close_callback); - + glfwSetWindowPosCallback(glfwWindow, window_pos_callback); // this set empty callbacks // solve a crash when glfw is quitting and tries to use nullptr callbacks // could be potentially useful in the future anyway @@ -286,6 +286,13 @@ namespace sofaglfw return false; } } + void SofaGLFWBaseGUI::updateViewportPosition(float x, float y) { + std::cout << "Updating viewport position to X: " << x << " Y: " << y << std::endl; + // Here you can add more logic to update the internal state or perform other operations as needed + viewPortPositionX=x; + viewPortPositionY=y; + + } void SofaGLFWBaseGUI::resizeWindow(int width, int height) { @@ -315,6 +322,7 @@ namespace sofaglfw glfwGetWindowPos(glfwWindow, &windowsX, &windowsY); glfwGetWindowSize(glfwWindow, &windowsWidth, &windowsHeight); monitors = glfwGetMonitors(&monitorsCount); + std::cout<<"\n\n::::::::::: windowsX\t"<(glfwGetWindowUserPointer(window)); + + std::cout<<"\n\n GLFW position X §§§§\t"<winPositionX=xpos; + gui->winPositionY=ypos; + } void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { auto currentGUI = s_mapGUIs.find(window); @@ -733,9 +750,10 @@ std::cout << "\n\n\tstate\t"<viewPortPositionY-gui->winPositionY); + xpos-=(gui->viewPortPositionX-gui->winPositionX); - -std::cout<<"\n\n::::::::::: xpos\t"<second) { @@ -762,6 +780,8 @@ std::cout<<"\n\n::::::::::: xpos\t"<second) @@ -769,8 +789,10 @@ std::cout<<"\n\n::::::::::: xpos\t"<second->getGUIEngine()->dispatchMouseEvents()) return; } - ypos-=49; - xpos-=8; + SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); + + ypos-=(gui->viewPortPositionY-gui->winPositionY); + xpos-=(gui->viewPortPositionX-gui->winPositionX); bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 982c85136b..65ddb340fc 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -59,16 +59,12 @@ namespace sofaglfw void initVisual(); std::size_t runLoop(std::size_t targetNbIterations = 0); void terminate(); - void convertWindowToViewportCoords(double windowX, double windowY, - int viewportX, int viewportY, - int viewportWidth, int viewportHeight, - double& viewportXOut, double& viewportYOut); - void configureAttachOperation(); int getWindowWidth() const { return m_windowWidth; } void setWindowWidth(int width) { m_windowWidth = width; } int getWindowHeight() const { return m_windowHeight; } void setWindowHeight(int height) { m_windowHeight = height; } void resizeWindow(int width, int height); + void updateViewportPosition(float x, float y) ; GLFWmonitor* getCurrentMonitor(GLFWwindow *window); virtual void viewAll() override { std::cout << "viewAll() Called" << std::endl; } @@ -116,7 +112,7 @@ namespace sofaglfw static void cursor_enter_callback(GLFWwindow* window, int entered); static void monitor_callback(GLFWmonitor* monitor, int event); static void character_callback(GLFWwindow* window, unsigned int codepoint); - + static void window_pos_callback(GLFWwindow* window, int xpos, int ypos); static int handleArrowKeys(int key); void makeCurrentContext(GLFWwindow* sofaWindow); @@ -142,6 +138,9 @@ namespace sofaglfw double lastProjectionMatrix[16]; double lastModelviewMatrix[16]; bool m_isMouseInteractionEnabled{ false }; + float viewPortPositionX,viewPortPositionY; + float winPositionX,winPositionY; + std::shared_ptr m_guiEngine; }; diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index d1a92f2309..1dd3a83296 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -179,12 +179,10 @@ void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow) void ImGuiGUIEngine::loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, const std::string filePathName) { sofa::simulation::node::unload(groot); - groot = sofa::simulation::node::load(filePathName.c_str()); if( !groot ) groot = sofa::simulation::getSimulation()->createNewGraph(""); baseGUI->setSimulation(groot, filePathName); - sofa::simulation::node::initRoot(groot.get()); auto camera = baseGUI->findCamera(groot); if (camera) @@ -211,6 +209,10 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) newSceneFrame->addTag(core::objectmodel::Tag("createdByGUI")); newSceneFrame->d_drawFrame.setValue(true); newSceneFrame->init(); + firstViewport=true; + x=1.0f; + y=1.0f; + std::cout << "pfkepfepkfpekpfkepfkepfkpe"; } } @@ -231,8 +233,6 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) ImGui::SetNextWindowPos(viewport->Pos); ImGui::SetNextWindowSize(viewport->Size); ImGui::SetNextWindowViewport(viewport->ID); - - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; @@ -560,7 +560,8 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) /*************************************** * Viewport window **************************************/ - windows::showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort); + windows::showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&x,&y); + /*************************************** * Performances window diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index 06dfbabaf4..67da1c6930 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -59,6 +59,8 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine void afterDraw() override; void terminate() override; bool dispatchMouseEvents() override; + bool firstViewport ; + float x,y; protected: std::unique_ptr m_fbo; @@ -66,7 +68,6 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine std::pair m_viewportWindowSize; bool isMouseOnViewport { false }; CSimpleIniA ini; - void loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, std::string filePathName); // WindowState members diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp index b8d5d81ae5..5fc3aa8387 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp @@ -33,9 +33,10 @@ #include #include #include "ViewPort.h" - - - +#include +#include +#include "SofaGLFW/SofaGLFWBaseGUI.h" +#include namespace windows { @@ -45,19 +46,51 @@ namespace windows std::unique_ptr& m_fbo, std::pair& m_viewportWindowSize, bool &isMouseOnViewport, - WindowState& winManagerViewPort) + WindowState& winManagerViewPort, + sofaglfw::SofaGLFWBaseGUI* baseGUI, + bool* firstViewport, + float * x, + float *y) { + static auto lastTime = std::chrono::steady_clock::now(); + const float precisionThreshold = 1.0f; if (*winManagerViewPort.getStatePtr()) { + std::setprecision(1); ImVec2 pos; if (ImGui::Begin(windowNameViewport, winManagerViewPort.getStatePtr()/*, ImGuiWindowFlags_MenuBar*/)) { pos = ImGui::GetWindowPos(); + ImGui::BeginChild("Render"); ImVec2 wsize = ImGui::GetWindowSize(); m_viewportWindowSize = { wsize.x, wsize.y}; + ImVec2 viewportPos = ImGui::GetWindowPos(); + auto currentTime = std::chrono::steady_clock::now(); + std::chrono::duration elapsedTime = currentTime - lastTime; + + + lastTime = currentTime; + if (*firstViewport){ + *x=viewportPos.x; + *y=viewportPos.y; + *firstViewport=false; + baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); + + } + else { + if (std::fabs(viewportPos.x - *x) > precisionThreshold || + std::fabs(viewportPos.y - *y) > precisionThreshold){ + baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); + *x=viewportPos.x; + *y=viewportPos.y; + + } + } + + ImGui::Image((ImTextureID)m_fbo->getColorTexture(), wsize, ImVec2(0, 1), ImVec2(1, 0)); isMouseOnViewport = ImGui::IsItemHovered(); @@ -147,4 +180,5 @@ namespace windows } + } \ No newline at end of file diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.h b/SofaImGui/src/SofaImGui/windows/ViewPort.h index 2549051d0b..e0981ebbb5 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.h +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.h @@ -48,6 +48,10 @@ namespace windows std::pair& m_viewportWindowSize, bool & isMouseOnViewport, - WindowState& winManagerViewPort); + WindowState& winManagerViewPort, + sofaglfw::SofaGLFWBaseGUI* baseGUI, + bool *firstViewport, + float *x, + float *y); } // namespace sofaimgui From 3d49b3181c4c29d91f903b4be6f63b8989c6814b Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Wed, 31 Jul 2024 16:00:45 +0200 Subject: [PATCH 15/41] mouse interaction (clean) --- SofaGLFW/CMakeLists.txt | 2 + SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 219 ++++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 19 +- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 127 ++++++++++ SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 73 ++++++ SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 67 +++--- 6 files changed, 346 insertions(+), 161 deletions(-) create mode 100644 SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp create mode 100644 SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h diff --git a/SofaGLFW/CMakeLists.txt b/SofaGLFW/CMakeLists.txt index a2986ab1ee..1b0dc33be8 100644 --- a/SofaGLFW/CMakeLists.txt +++ b/SofaGLFW/CMakeLists.txt @@ -38,6 +38,7 @@ set(HEADER_FILES ${SOFAGLFW_SOURCE_DIR}/SofaGLFWBaseGUI.h ${SOFAGLFW_SOURCE_DIR}/BaseGUIEngine.h ${SOFAGLFW_SOURCE_DIR}/NullGUIEngine.h + ${SOFAGLFW_SOURCE_DIR}/SofaGLFWMouseManager.h ) set(SOURCE_FILES @@ -45,6 +46,7 @@ set(SOURCE_FILES ${SOFAGLFW_SOURCE_DIR}/SofaGLFWWindow.cpp ${SOFAGLFW_SOURCE_DIR}/NullGUIEngine.cpp ${SOFAGLFW_SOURCE_DIR}/SofaGLFWBaseGUI.cpp + ${SOFAGLFW_SOURCE_DIR}/SofaGLFWMouseManager.cpp ) if(Sofa.GUI.Common_FOUND) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 9f9db1db5c..7ec06705f8 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -52,7 +52,7 @@ #include #include #include - +#include "SofaGLFW/SofaGLFWMouseManager.h" using namespace sofa; using namespace sofa::gui::common; @@ -67,24 +67,11 @@ using namespace sofa::gui::common; namespace sofaglfw { SofaGLFWBaseGUI::SofaGLFWBaseGUI() - :BaseViewer() + :BaseViewer(), + m_sofaGLFWMouseManager(nullptr) { m_guiEngine = std::make_shared(); - //By changing the operation, we delete the previous operation - RegisterOperation("attach").add(); - RegisterOperation("Attach").add< AttachOperation >(); - RegisterOperation("AddFrame").add< AddFrameOperation >(); - RegisterOperation("SaveCameraViewPoint").add< AddRecordedCameraOperation >(); - RegisterOperation("StartNavigation").add< StartNavigationOperation >(); - RegisterOperation("Fix") .add< FixOperation >(); - RegisterOperation("Incise").add< InciseOperation >(); - RegisterOperation("Remove").add< TopologyOperation >(); - RegisterOperation("Suture").add< AddSutureOperation >(); - RegisterOperation("ConstraintAttach").add< ConstraintAttachOperation >(); - this->pick->changeOperation( LEFT, "Attach"); - this->pick->changeOperation( MIDDLE, "Incise"); - this->pick->changeOperation( RIGHT, "Remove"); - + m_sofaGLFWMouseManager = new SofaGLFWMouseManager(); } @@ -136,6 +123,7 @@ namespace sofaglfw if (m_groot) { // Initialize the pick handler this->pick->init(m_groot.get()); + m_sofaGLFWMouseManager->setPickHandler(getPickHandler()); } } @@ -238,6 +226,9 @@ namespace sofaglfw m_lastWindowPositionX = 100; m_lastWindowPositionY = 100; + setWindowHeight(height); + setWindowWidth(width); + glfwWindow = glfwCreateWindow(mode->width, mode->height, title, primaryMonitor, m_firstWindow); } else @@ -322,8 +313,6 @@ namespace sofaglfw glfwGetWindowPos(glfwWindow, &windowsX, &windowsY); glfwGetWindowSize(glfwWindow, &windowsWidth, &windowsHeight); monitors = glfwGetMonitors(&monitorsCount); - std::cout<<"\n\n::::::::::: windowsX\t"<viewport()[2]; + viewPortHeight=m_vparams->viewport()[3]; bool running = true; std::size_t currentNbIterations = 0; @@ -456,6 +447,14 @@ namespace sofaglfw glfwSwapBuffers(glfwWindow); + if (viewPortHeight!=m_vparams->viewport()[3] || + viewPortWidth!=m_vparams->viewport()[2]) + { + viewPortHeight=m_vparams->viewport()[3]; + viewPortWidth=m_vparams->viewport()[2]; + } + + } else { @@ -631,7 +630,6 @@ namespace sofaglfw if (action == GLFW_PRESS) { const int viewport[4] = {}; - std::cout<<"key shft pressed\n"; currentGUI->second->getPickHandler()->activateRay(viewport[2],viewport[3], rootNode.get()); break; } @@ -641,126 +639,106 @@ namespace sofaglfw currentGUI->second->getPickHandler()->deactivateRay(); break; } - } } - void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) - { - std::cout <<"\n\nmove ray\n"; - std::cout<<"\n\n::::moveRayPickInteractor::: xpos\t"<viewport(); - std::cout <<"\n "<< viewport.data(); - - Vec3d p0; - Vec3d px; - Vec3d py; - Vec3d pz; - Vec3d px1; - Vec3d py1; - gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); - gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); - - - px1 -= pz; - py1 -= pz; - px -= p0; - py -= p0; - pz -= p0; - const double r0 = sqrt(px.norm2() + py.norm2()); - double r1 = sqrt(px1.norm2() + py1.norm2()); - r1 = r0 + (r1 - r0) / pz.norm(); - px.normalize(); - py.normalize(); - pz.normalize(); - - Mat4x4d transform; - transform.identity(); - transform[0][0] = px[0]; - transform[1][0] = px[1]; - transform[2][0] = px[2]; - transform[0][1] = py[0]; - transform[1][1] = py[1]; - transform[2][1] = py[2]; - transform[0][2] = pz[0]; - transform[1][2] = pz[1]; - transform[2][2] = pz[2]; - transform[0][3] = p0[0]; - transform[1][3] = p0[1]; - transform[2][3] = p0[2]; - - Mat3x3d mat; - mat = transform; - Quat q; - q.fromMatrix(mat); - - Vec3d position, direction; - position = transform * Vec4d(0, 0, 0, 1); - direction = transform * Vec4d(0, 0, 1, 0); - direction.normalize(); - this->pick->updateRay(position, direction); - } - - + void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) + { + const sofa::core::visual::VisualParams::Viewport& viewport = m_vparams->viewport(); + + Vec3d p0; + Vec3d px; + Vec3d py; + Vec3d pz; + Vec3d px1; + Vec3d py1; + gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); + + px1 -= pz; + py1 -= pz; + px -= p0; + py -= p0; + pz -= p0; + + const double r0 = sqrt(px.norm2() + py.norm2()); + double r1 = sqrt(px1.norm2() + py1.norm2()); + r1 = r0 + (r1 - r0) / pz.norm(); + px.normalize(); + py.normalize(); + pz.normalize(); + + Mat4x4d transform; + transform.identity(); + transform[0][0] = px[0]; + transform[1][0] = px[1]; + transform[2][0] = px[2]; + transform[0][1] = py[0]; + transform[1][1] = py[1]; + transform[2][1] = py[2]; + transform[0][2] = pz[0]; + transform[1][2] = pz[1]; + transform[2][2] = pz[2]; + transform[0][3] = p0[0]; + transform[1][3] = p0[1]; + transform[2][3] = p0[2]; + + Mat3x3d mat; + mat = transform; + Quat q; + q.fromMatrix(mat); + + Vec3d position, direction; + position = transform * Vec4d(0, 0, 0, 1); + direction = transform * Vec4d(0, 0, 1, 0); + direction.normalize(); + getPickHandler()->updateRay(position, direction); + } void SofaGLFWBaseGUI::window_pos_callback(GLFWwindow* window, int xpos, int ypos) { SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); - - std::cout<<"\n\n GLFW position X §§§§\t"<winPositionX=xpos; gui->winPositionY=ypos; } - void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { + void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) + { + double xpos, ypos; + auto currentGUI = s_mapGUIs.find(window); if (currentGUI == s_mapGUIs.end() || !currentGUI->second) { return; } - SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); - - const sofa::core::visual::VisualParams::Viewport& viewport = gui->m_vparams->viewport(); - std::cout << "Viewport Size: " << viewport[2] << "x" << viewport[3] << std::endl; + SofaGLFWBaseGUI* gui = currentGUI->second; auto rootNode = currentGUI->second->getRootNode(); if (!rootNode) { return; } + bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; - int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); -std::cout << "\n\n\tstate\t"<second->simulationIsRunning()) { std::cout << "Animation is not running. Ignoring mouse interaction." << std::endl; return; } - double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos); - ypos-=(gui->viewPortPositionY-gui->winPositionY); - xpos-=(gui->viewPortPositionX-gui->winPositionX); + translateToViewportCoordinates(gui,xpos,ypos); -//std::cout<<"\n\n::::::::::: xpos\t"<second) { - currentSofaWindow->second->mouseEvent(window,viewport[2],viewport[3], button, action, mods, xpos, ypos); + currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, button, action, mods, gui->translatedXPos, gui->translatedYpos); } - - } else { @@ -778,10 +756,14 @@ std::cout << "\n\n\tstate\t"<translatedYpos =ypos-(gui->viewPortPositionY-gui->winPositionY); + gui->translatedXPos =xpos-(gui->viewPortPositionX-gui->winPositionX); + } + void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) + { auto currentGUI = s_mapGUIs.find(window); if (currentGUI != s_mapGUIs.end() && currentGUI->second) @@ -789,31 +771,26 @@ std::cout << "\n\n\tstate\t"<second->getGUIEngine()->dispatchMouseEvents()) return; } - SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); + SofaGLFWBaseGUI* gui = currentGUI->second; - ypos-=(gui->viewPortPositionY-gui->winPositionY); - xpos-=(gui->viewPortPositionX-gui->winPositionX); + translateToViewportCoordinates(gui,xpos,ypos); bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); + auto currentSofaWindow = s_mapWindows.find(window); + if (shiftPressed && state == GLFW_PRESS) { - const sofa::core::visual::VisualParams::Viewport& viewport = currentGUI->second->m_vparams->viewport(); - - currentSofaWindow->second->mouseEvent(window,viewport[2],viewport[3], 0, 1, 1, xpos, ypos); - - + currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, 0, 1, 1, gui->translatedXPos, gui->translatedYpos); } - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) - { - - currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); - } - - + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + { + currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); + } } + void SofaGLFWBaseGUI::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { auto currentGUI = s_mapGUIs.find(window); diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 65ddb340fc..88bebc5c15 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -42,6 +42,7 @@ struct GLFWmonitor; namespace sofaglfw { + class SofaGLFWMouseManager; class SofaGLFWWindow; @@ -95,12 +96,6 @@ namespace sofaglfw void moveRayPickInteractor(int eventX, int eventY) override ; private: - static std::unique_ptr attachOperation; - static void handleShiftMouseButton(GLFWwindow* window, SofaGLFWBaseGUI* gui, int button, int action, double xpos, double ypos); - static void handleRegularMouseButton(GLFWwindow* window, SofaGLFWBaseGUI* gui, int button, int action, int mods); - static void initializeAttachOperation(SofaGLFWBaseGUI* gui); - - // GLFW callbacks static void error_callback(int error, const char* description); static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); @@ -114,6 +109,7 @@ namespace sofaglfw static void character_callback(GLFWwindow* window, unsigned int codepoint); static void window_pos_callback(GLFWwindow* window, int xpos, int ypos); static int handleArrowKeys(int key); + static void translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos); void makeCurrentContext(GLFWwindow* sofaWindow); void runStep(); @@ -138,8 +134,15 @@ namespace sofaglfw double lastProjectionMatrix[16]; double lastModelviewMatrix[16]; bool m_isMouseInteractionEnabled{ false }; - float viewPortPositionX,viewPortPositionY; - float winPositionX,winPositionY; + float viewPortPositionX {0}; + float viewPortPositionY {0}; + float winPositionX {0}; + float winPositionY {0}; + SofaGLFWMouseManager* m_sofaGLFWMouseManager; + int viewPortHeight{0}; + int viewPortWidth {0}; + double translatedXPos {0}; + double translatedYpos {0}; std::shared_ptr m_guiEngine; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp new file mode 100644 index 0000000000..3e572a546e --- /dev/null +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -0,0 +1,127 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the Free * +* Software Foundation; either version 2 of the License, or (at your option) * +* any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ + +#include "SofaGLFW/SofaGLFWMouseManager.h" + +#define GLFW_INCLUDE_NONE + +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace sofa; +using namespace sofa::gui::common; + +using std::endl; +using namespace sofa::type; +using namespace sofa::defaulttype; +using namespace sofa::gl; +using sofa::simulation::getSimulation; +using namespace sofa::simulation; +using namespace sofa::gui::common; + + +using namespace sofa; + +namespace sofaglfw { + + + SofaGLFWMouseManager::SofaGLFWMouseManager() + { + RegisterOperation("attach").add(); + RegisterOperation("Attach").add< AttachOperation >(); + RegisterOperation("AddFrame").add< AddFrameOperation >(); + RegisterOperation("SaveCameraViewPoint").add< AddRecordedCameraOperation >(); + RegisterOperation("StartNavigation").add< StartNavigationOperation >(); + RegisterOperation("Fix") .add< FixOperation >(); + RegisterOperation("Incise").add< InciseOperation >(); + RegisterOperation("Remove").add< TopologyOperation >(); + RegisterOperation("Suture").add< AddSutureOperation >(); + RegisterOperation("ConstraintAttach").add< ConstraintAttachOperation >(); + } + SofaGLFWMouseManager::~SofaGLFWMouseManager() + { + } + + void SofaGLFWMouseManager::setPickHandler(PickHandler *picker) + { + + pickHandler=picker; + updateContent(); + + updateOperation(LEFT, "Attach"); + updateOperation(MIDDLE, "Incise"); + updateOperation(RIGHT, "Remove"); + + + } + + void SofaGLFWMouseManager::updateContent() + { + } + + void SofaGLFWMouseManager::render() + { + } + + void SofaGLFWMouseManager::selectOperation(int button) + { + } + + void SofaGLFWMouseManager::updateOperation(MOUSE_BUTTON button, const std::string &id) + { + if (pickHandler) + { + Operation *operation = pickHandler->changeOperation(button, id); + updateOperation(operation); + } + } + + void SofaGLFWMouseManager::updateOperation(Operation *operation) + { + } +} \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h new file mode 100644 index 0000000000..7cb5c949fc --- /dev/null +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -0,0 +1,73 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the Free * +* Software Foundation; either version 2 of the License, or (at your option) * +* any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + + + +#include +#include +#include "SofaGLFWBaseGUI.h" + +struct GLFWwindow; +struct GLFWmonitor; +class SofaMouseManager; + +using namespace sofa::gui::common; + +namespace sofaglfw +{ + class SOFAGLFW_API SofaGLFWMouseManager { + public: + SofaGLFWMouseManager(); + ~SofaGLFWMouseManager(); + + void setPickHandler(PickHandler* picker); + void updateContent(); + void render(); + + private: + void selectOperation(int operation); + void updateOperation(MOUSE_BUTTON button, const std::string& id); + void updateOperation(Operation* operation); + + PickHandler* pickHandler; + std::map> operations; + std::map buttonOperations; + }; + +} // namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 2be971d214..5ed66b6989 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -41,7 +41,6 @@ using namespace sofa; namespace sofaglfw { - SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) : m_glfwWindow(glfwWindow) , m_currentCamera(camera) @@ -49,13 +48,11 @@ namespace sofaglfw } - void SofaGLFWWindow::close() { glfwDestroyWindow(m_glfwWindow); } - void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]) { glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); @@ -73,8 +70,6 @@ namespace sofaglfw return; } - - if (groot->f_bbox.getValue().isValid()) { vparams->sceneBBox() = groot->f_bbox.getValue(); @@ -108,7 +103,6 @@ namespace sofaglfw vparams->setModelViewMatrix(lastModelviewMatrix); sofa::simulation::node::draw(vparams, groot.get()); - } void SofaGLFWWindow::setBackgroundColor(const sofa::type::RGBAColor& newColor) @@ -142,7 +136,6 @@ namespace sofaglfw } } - void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos, SofaGLFWBaseGUI* gui) { m_currentXPos = xpos; @@ -211,59 +204,69 @@ namespace sofaglfw m_currentButton = button; m_currentAction = action; m_currentMods = mods; - } bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int width, int height,int button, int action, int mods, double xpos, double ypos) { - std::cout <<"mouse event glfw\n\n"; + if (!m_currentCamera) return true; - SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); - + SofaGLFWBaseGUI *gui = static_cast(glfwGetWindowUserPointer(window)); - sofa::gui::common::MousePosition mousepos; + sofa::gui::common::MousePosition mousepos; mousepos.screenWidth = width; mousepos.screenHeight = height; mousepos.x = static_cast(xpos); mousepos.y = static_cast(ypos); auto rootNode = gui->getRootNode(); - if ( GLFW_MOD_SHIFT) { - - std::cout <<" if (mods & GLFW_MOD_SHIFT) {n\n"; + if (GLFW_MOD_SHIFT) + { gui->getPickHandler()->activateRay(width, height, rootNode.get()); gui->getPickHandler()->updateMouse2D(mousepos); - if (action == GLFW_PRESS) { - if (button == GLFW_MOUSE_BUTTON_LEFT) { + if (action == GLFW_PRESS) + { + if (button == GLFW_MOUSE_BUTTON_LEFT) + { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::LEFT); - } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { + } + else if (button == GLFW_MOUSE_BUTTON_RIGHT) + { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::RIGHT); - } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { + } + else if (button == GLFW_MOUSE_BUTTON_MIDDLE) + { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::MIDDLE); } - } else if (action == GLFW_RELEASE) { - if (action == GLFW_RELEASE) { - if (button == GLFW_MOUSE_BUTTON_LEFT) { + } + else if (action == GLFW_RELEASE) + { + if (action == GLFW_RELEASE) + { + if (button == GLFW_MOUSE_BUTTON_LEFT) + { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::LEFT); gui->getPickHandler()->deactivateRay(); - } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { + } + else if (button == GLFW_MOUSE_BUTTON_RIGHT) + { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::RIGHT); - } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { + } + else if (button == GLFW_MOUSE_BUTTON_MIDDLE) + { gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::MIDDLE); } } } - - gui->moveRayPickInteractor(xpos, ypos); - } else { - - gui->getPickHandler()->activateRay(width, height, rootNode.get()); - } - return true; + gui->moveRayPickInteractor(xpos, ypos); } - + else + { + gui->getPickHandler()->activateRay(width, height, rootNode.get()); + } + return true; + } void SofaGLFWWindow::scrollEvent(double xoffset, double yoffset) { From 73d61aeee8b2a360c05edf8f33344baa50871f40 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Wed, 31 Jul 2024 16:41:19 +0200 Subject: [PATCH 16/41] mouse interaction (clean) --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 12 +++--- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 2 +- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 4 -- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 6 +-- SofaImGui/src/SofaImGui/ImGuiGUIEngine.h | 7 ++-- SofaImGui/src/SofaImGui/windows/ViewPort.cpp | 38 +++++++++---------- SofaImGui/src/SofaImGui/windows/ViewPort.h | 4 +- 7 files changed, 29 insertions(+), 44 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 7ec06705f8..f829c75d6f 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -248,7 +248,7 @@ namespace sofaglfw glfwSetMouseButtonCallback(glfwWindow, mouse_button_callback); glfwSetScrollCallback(glfwWindow, scroll_callback); glfwSetWindowCloseCallback(glfwWindow, close_callback); - glfwSetWindowPosCallback(glfwWindow, window_pos_callback); + glfwSetWindowPosCallback(glfwWindow, window_pos_callback); // this set empty callbacks // solve a crash when glfw is quitting and tries to use nullptr callbacks // could be potentially useful in the future anyway @@ -277,12 +277,10 @@ namespace sofaglfw return false; } } - void SofaGLFWBaseGUI::updateViewportPosition(float x, float y) { - std::cout << "Updating viewport position to X: " << x << " Y: " << y << std::endl; - // Here you can add more logic to update the internal state or perform other operations as needed - viewPortPositionX=x; - viewPortPositionY=y; - + void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) + { + viewPortPositionX=lastViewPortPosX; + viewPortPositionY=lastViewPortPosY; } void SofaGLFWBaseGUI::resizeWindow(int width, int height) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 88bebc5c15..c55a48b245 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -65,7 +65,7 @@ namespace sofaglfw int getWindowHeight() const { return m_windowHeight; } void setWindowHeight(int height) { m_windowHeight = height; } void resizeWindow(int width, int height); - void updateViewportPosition(float x, float y) ; + void updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) ; GLFWmonitor* getCurrentMonitor(GLFWwindow *window); virtual void viewAll() override { std::cout << "viewAll() Called" << std::endl; } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index 3e572a546e..3f0cf19777 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -69,7 +69,6 @@ using namespace sofa; namespace sofaglfw { - SofaGLFWMouseManager::SofaGLFWMouseManager() { RegisterOperation("attach").add(); @@ -89,15 +88,12 @@ namespace sofaglfw { void SofaGLFWMouseManager::setPickHandler(PickHandler *picker) { - pickHandler=picker; updateContent(); updateOperation(LEFT, "Attach"); updateOperation(MIDDLE, "Incise"); updateOperation(RIGHT, "Remove"); - - } void SofaGLFWMouseManager::updateContent() diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 1dd3a83296..ae7aa36a7e 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -209,10 +209,6 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) newSceneFrame->addTag(core::objectmodel::Tag("createdByGUI")); newSceneFrame->d_drawFrame.setValue(true); newSceneFrame->init(); - firstViewport=true; - x=1.0f; - y=1.0f; - std::cout << "pfkepfepkfpekpfkepfkepfkpe"; } } @@ -560,7 +556,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) /*************************************** * Viewport window **************************************/ - windows::showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&x,&y); + windows::showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&lastViewPortPosX,&lastViewPortPosY); /*************************************** diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index 67da1c6930..80f308bdff 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -31,8 +31,6 @@ #include #include "windows/WindowState.h" - - using windows::WindowState; struct GLFWwindow; @@ -59,8 +57,9 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine void afterDraw() override; void terminate() override; bool dispatchMouseEvents() override; - bool firstViewport ; - float x,y; + bool firstViewport{true} ; + float lastViewPortPosX{0.0f}; + float lastViewPortPosY{0.0f}; protected: std::unique_ptr m_fbo; diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp index 5fc3aa8387..35a36f24a1 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp @@ -49,8 +49,8 @@ namespace windows WindowState& winManagerViewPort, sofaglfw::SofaGLFWBaseGUI* baseGUI, bool* firstViewport, - float * x, - float *y) + float * lastViewPortPosX, + float * lastViewPortPosY) { static auto lastTime = std::chrono::steady_clock::now(); const float precisionThreshold = 1.0f; @@ -62,34 +62,30 @@ namespace windows { pos = ImGui::GetWindowPos(); - ImGui::BeginChild("Render"); ImVec2 wsize = ImGui::GetWindowSize(); m_viewportWindowSize = { wsize.x, wsize.y}; ImVec2 viewportPos = ImGui::GetWindowPos(); - auto currentTime = std::chrono::steady_clock::now(); - std::chrono::duration elapsedTime = currentTime - lastTime; - - lastTime = currentTime; - if (*firstViewport){ - *x=viewportPos.x; - *y=viewportPos.y; + if (*firstViewport) + { + *lastViewPortPosX=viewportPos.x; + *lastViewPortPosY=viewportPos.y; *firstViewport=false; - baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); + baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); + } + else + { + if (std::fabs(viewportPos.x - *lastViewPortPosX) > precisionThreshold || + std::fabs(viewportPos.y - *lastViewPortPosY) > precisionThreshold) + { + baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); + *lastViewPortPosX=viewportPos.x; + *lastViewPortPosY=viewportPos.y; } - else { - if (std::fabs(viewportPos.x - *x) > precisionThreshold || - std::fabs(viewportPos.y - *y) > precisionThreshold){ - baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); - *x=viewportPos.x; - *y=viewportPos.y; - - } - } - + } ImGui::Image((ImTextureID)m_fbo->getColorTexture(), wsize, ImVec2(0, 1), ImVec2(1, 0)); diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.h b/SofaImGui/src/SofaImGui/windows/ViewPort.h index e0981ebbb5..d63ccd401b 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.h +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.h @@ -51,7 +51,7 @@ namespace windows WindowState& winManagerViewPort, sofaglfw::SofaGLFWBaseGUI* baseGUI, bool *firstViewport, - float *x, - float *y); + float *lastViewPortPosX, + float *lastViewPortPosY); } // namespace sofaimgui From b559fca8c62907227347d36ae482dbab23db3194 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 1 Aug 2024 12:13:37 +0200 Subject: [PATCH 17/41] cleaning --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 111 +++++----- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 2 +- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp | 12 +- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h | 2 +- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 25 +-- SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 17 -- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 53 +++-- SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp | 2 +- SofaImGui/src/SofaImGui/AppIniFile.cpp | 2 +- SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp | 190 +++++++++--------- SofaImGui/src/SofaImGui/ImGuiGUI.cpp | 4 +- SofaImGui/src/SofaImGui/ImGuiGUI.h | 2 +- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 102 ++++------ SofaImGui/src/SofaImGui/ImGuiGUIEngine.h | 20 +- SofaImGui/src/SofaImGui/initSofaImGui.cpp | 2 +- SofaImGui/src/SofaImGui/windows/ViewPort.cpp | 23 +-- SofaImGui/src/SofaImGui/windows/ViewPort.h | 77 ++++--- 17 files changed, 304 insertions(+), 342 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index f829c75d6f..7d5e8d239f 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -45,13 +45,9 @@ #include #include -#include #include #include #include -#include -#include -#include #include "SofaGLFW/SofaGLFWMouseManager.h" using namespace sofa; using namespace sofa::gui::common; @@ -60,19 +56,22 @@ using std::endl; using namespace sofa::type; using namespace sofa::defaulttype; using namespace sofa::gl; -using sofa::simulation::getSimulation; +using simulation::getSimulation; using namespace sofa::simulation; using namespace sofa::gui::common; +using namespace core::visual; +using namespace component::visual; +using namespace core::objectmodel; namespace sofaglfw { SofaGLFWBaseGUI::SofaGLFWBaseGUI() - :BaseViewer(), - m_sofaGLFWMouseManager(nullptr) + :lastProjectionMatrix{0.0}, + lastModelviewMatrix{0.0}, + m_sofaGLFWMouseManager(nullptr) { m_guiEngine = std::make_shared(); m_sofaGLFWMouseManager = new SofaGLFWMouseManager(); - } SofaGLFWBaseGUI::~SofaGLFWBaseGUI() @@ -80,7 +79,7 @@ namespace sofaglfw terminate(); } - sofa::core::sptr SofaGLFWBaseGUI::getRootNode() const + core::sptr SofaGLFWBaseGUI::getRootNode() const { return m_groot; } @@ -99,7 +98,7 @@ namespace sofaglfw // max = 32 (MSAA with 32 samples) glfwWindowHint(GLFW_SAMPLES, std::clamp(nbMSAASamples, 0, 32) ); - m_glDrawTool = new sofa::gl::DrawToolGL(); + m_glDrawTool = new DrawToolGL(); m_bGlfwIsInitialized = true; return true; } @@ -114,11 +113,11 @@ namespace sofaglfw glfwSetErrorCallback(error_callback); } - void SofaGLFWBaseGUI::setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename) { + void SofaGLFWBaseGUI::setSimulation(NodeSPtr groot, const std::string& filename) { m_groot = groot; m_filename = filename; - sofa::core::visual::VisualParams::defaultInstance()->drawTool() = m_glDrawTool; + VisualParams::defaultInstance()->drawTool() = m_glDrawTool; if (m_groot) { // Initialize the pick handler @@ -146,14 +145,14 @@ namespace sofaglfw return false; } - sofa::component::visual::BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(sofa::simulation::NodeSPtr groot) + BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(NodeSPtr groot) { - sofa::component::visual::BaseCamera::SPtr camera; + BaseCamera::SPtr camera; groot->get(camera); if (!camera) { - camera = sofa::core::objectmodel::New(); - camera->setName(core::objectmodel::Base::shortName(camera.get())); + camera = sofa::core::objectmodel::New(); + camera->setName(Base::shortName(camera.get())); m_groot->addObject(camera); camera->bwdInit(); } @@ -180,7 +179,7 @@ namespace sofaglfw return m_windowHeight; } - void SofaGLFWBaseGUI::changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera) + void SofaGLFWBaseGUI::changeCamera(BaseCamera::SPtr newCamera) { for (auto& w : s_mapWindows) { @@ -191,9 +190,9 @@ namespace sofaglfw void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) { //STBImage relies on DataRepository to find files: it must be extended with the resource files from this plugin - sofa::helper::system::DataRepository.addFirstPath(SOFAGLFW_RESOURCES_DIR); + helper::system::DataRepository.addFirstPath(SOFAGLFW_RESOURCES_DIR); - sofa::helper::io::STBImage img; + helper::io::STBImage img; if (img.load("SOFA.png")) { GLFWimage images[1]; @@ -202,7 +201,7 @@ namespace sofaglfw images[0].pixels = img.getPixels(); glfwSetWindowIcon(glfwWindow, 1, images); } - sofa::helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); + helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); } bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) @@ -272,10 +271,9 @@ namespace sofaglfw return true; } - else - { - return false; - } + + return false; + } void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) { @@ -375,7 +373,7 @@ namespace sofaglfw } } - void SofaGLFWBaseGUI::setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int /* windowID */) + void SofaGLFWBaseGUI::setBackgroundColor(const RGBAColor& newColor, unsigned int /* windowID */) { // only manage the first window for now if (hasWindow()) @@ -413,7 +411,7 @@ namespace sofaglfw return 0; } - m_vparams = sofa::core::visual::VisualParams::defaultInstance(); + m_vparams = VisualParams::defaultInstance(); viewPortWidth=m_vparams->viewport()[2]; viewPortHeight=m_vparams->viewport()[3]; @@ -451,8 +449,6 @@ namespace sofaglfw viewPortHeight=m_vparams->viewport()[3]; viewPortWidth=m_vparams->viewport()[2]; } - - } else { @@ -473,17 +469,17 @@ namespace sofaglfw void SofaGLFWBaseGUI::initVisual() { - sofa::simulation::node::initTextures(m_groot.get()); + node::initTextures(m_groot.get()); - component::visual::VisualStyle::SPtr visualStyle = nullptr; + VisualStyle::SPtr visualStyle = nullptr; m_groot->get(visualStyle); if (!visualStyle) { - visualStyle = sofa::core::objectmodel::New(); - visualStyle->setName(sofa::helper::NameDecoder::getShortName()); + visualStyle = sofa::core::objectmodel::New(); + visualStyle->setName(helper::NameDecoder::getShortName()); - core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit(); - displayFlags->setShowVisualModels(sofa::core::visual::tristate::true_value); + DisplayFlags* displayFlags = visualStyle->d_displayFlags.beginEdit(); + displayFlags->setShowVisualModels(tristate::true_value); visualStyle->displayFlags.endEdit(); m_groot->addObject(visualStyle); @@ -519,7 +515,7 @@ namespace sofaglfw glEnable(GL_LIGHT0); - m_vparams = sofa::core::visual::VisualParams::defaultInstance(); + m_vparams = VisualParams::defaultInstance(); for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) { sofaGlfwWindow->centerCamera(m_groot, m_vparams); @@ -530,12 +526,12 @@ namespace sofaglfw { if(simulationIsRunning()) { - sofa::helper::AdvancedTimer::begin("Animate"); + helper::AdvancedTimer::begin("Animate"); - simulation::node::animate(m_groot.get(), m_groot->getDt()); - simulation::node::updateVisual(m_groot.get()); + node::animate(m_groot.get(), m_groot->getDt()); + node::updateVisual(m_groot.get()); - sofa::helper::AdvancedTimer::end("Animate"); + helper::AdvancedTimer::end("Animate"); } } @@ -571,7 +567,7 @@ namespace sofaglfw void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - const char keyName = SofaGLFWBaseGUI::handleArrowKeys(key); + const char keyName = handleArrowKeys(key); const bool isCtrlKeyPressed = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; auto currentGUI = s_mapGUIs.find(window); @@ -592,13 +588,13 @@ namespace sofaglfw { dmsg_info_when(key == GLFW_KEY_LEFT_CONTROL, "SofaGLFWBaseGUI") << "KeyPressEvent, CONTROL pressed"; - sofa::core::objectmodel::KeypressedEvent keyPressedEvent(keyName); - rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyPressedEvent); + KeypressedEvent keyPressedEvent(keyName); + rootNode->propagateEvent(core::ExecParams::defaultInstance(), &keyPressedEvent); } else if (action == GLFW_RELEASE) { - sofa::core::objectmodel::KeyreleasedEvent keyReleasedEvent(keyName); - rootNode->propagateEvent(sofa::core::ExecParams::defaultInstance(), &keyReleasedEvent); + KeyreleasedEvent keyReleasedEvent(keyName); + rootNode->propagateEvent(core::ExecParams::defaultInstance(), &keyReleasedEvent); } } @@ -625,24 +621,28 @@ namespace sofaglfw } break; case GLFW_KEY_LEFT_SHIFT: - if (action == GLFW_PRESS) + if (currentGUI->second->getPickHandler()) // Check if getPickHandler() is not null { - const int viewport[4] = {}; - currentGUI->second->getPickHandler()->activateRay(viewport[2],viewport[3], rootNode.get()); - break; - } - else - { - if (currentGUI->second->getPickHandler()) + if (action == GLFW_PRESS) + { + int viewport[4] = {}; // Properly initialize the viewport array + currentGUI->second->getPickHandler()->activateRay(viewport[2], viewport[3], rootNode.get()); + } + else if (action == GLFW_RELEASE) + { currentGUI->second->getPickHandler()->deactivateRay(); - break; + } } + break; + + default: + break; } } void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) { - const sofa::core::visual::VisualParams::Viewport& viewport = m_vparams->viewport(); + const VisualParams::Viewport& viewport = m_vparams->viewport(); Vec3d p0; Vec3d px; @@ -721,11 +721,12 @@ namespace sofaglfw } bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + if (shiftPressed ) { // Check if the animation is running if (!currentGUI->second->simulationIsRunning()) { - std::cout << "Animation is not running. Ignoring mouse interaction." << std::endl; + msg_error("SofaGLFWBaseGUI") << "Animation is not running. Ignoring mouse interaction."; return; } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index c55a48b245..eadf724358 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -145,7 +145,7 @@ namespace sofaglfw double translatedYpos {0}; - std::shared_ptr m_guiEngine; + std::shared_ptr m_guiEngine; }; } // namespace sofaglfw \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp index 6dd5c4885c..a5ab18b2e4 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp @@ -53,7 +53,7 @@ int SofaGLFWGUI::closeGUI() return 0; } -void SofaGLFWGUI::setScene(sofa::simulation::NodeSPtr groot, const char* filename, bool temporaryFile) +void SofaGLFWGUI::setScene(simulation::NodeSPtr groot, const char* filename, bool temporaryFile) { SOFA_UNUSED(temporaryFile); @@ -70,7 +70,7 @@ void SofaGLFWGUI::setScene(sofa::simulation::NodeSPtr groot, const char* filenam m_baseGUI.initVisual(); } -sofa::simulation::Node* SofaGLFWGUI::currentSimulation() +simulation::Node* SofaGLFWGUI::currentSimulation() { return m_baseGUI.getRootNode().get(); } @@ -85,7 +85,7 @@ void SofaGLFWGUI::setViewerResolution(int width, int height) } -void SofaGLFWGUI::setViewerConfiguration(sofa::component::setting::ViewerSetting* viewerConf) +void SofaGLFWGUI::setViewerConfiguration(component::setting::ViewerSetting* viewerConf) { const type::Vec<2, int>& res = viewerConf->resolution.getValue(); @@ -104,7 +104,7 @@ void SofaGLFWGUI::setFullScreen() m_baseGUI.switchFullScreen(); } -void SofaGLFWGUI::setBackgroundColor(const sofa::type::RGBAColor& color) +void SofaGLFWGUI::setBackgroundColor(const type::RGBAColor& color) { m_baseGUI.setBackgroundColor(color); } @@ -114,9 +114,9 @@ void SofaGLFWGUI::setBackgroundImage(const std::string& image) SOFA_UNUSED(image); } -sofa::gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename) +gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, simulation::NodeSPtr groot, const char* filename) { - SofaGLFWGUI::mGuiName = name; + mGuiName = name; auto* gui = new SofaGLFWGUI(); if (!gui->init()) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h index f4f55f26ec..df5006bb65 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h @@ -50,7 +50,7 @@ class SOFAGLFW_API SofaGLFWGUI : public sofa::gui::common::BaseGUI void setFullScreen() override; void setBackgroundColor(const sofa::type::RGBAColor& color) override; void setBackgroundImage(const std::string& image) override; - static sofa::gui::common::BaseGUI * CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); + static BaseGUI * CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); protected: SofaGLFWBaseGUI m_baseGUI; bool m_bCreateWithFullScreen{ false }; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index 3f0cf19777..da1821d7ff 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -24,34 +24,13 @@ #define GLFW_INCLUDE_NONE -#include - #include - -#include #include -#include #include -#include - -#include -#include - -#include - -#include -#include -#include - -#include -#include -#include #include -#include #include #include #include -#include using namespace sofa; using namespace sofa::gui::common; @@ -60,7 +39,7 @@ using std::endl; using namespace sofa::type; using namespace sofa::defaulttype; using namespace sofa::gl; -using sofa::simulation::getSimulation; +using simulation::getSimulation; using namespace sofa::simulation; using namespace sofa::gui::common; @@ -120,4 +99,4 @@ namespace sofaglfw { void SofaGLFWMouseManager::updateOperation(Operation *operation) { } -} \ No newline at end of file +}// namespace sofaglfw \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h index 7cb5c949fc..9abfc46407 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -20,27 +20,10 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #pragma once -#include #include -#include - -#include -#include #include -#include - -#include -#include #include -#include - -#include #include - - - -#include -#include #include "SofaGLFWBaseGUI.h" struct GLFWwindow; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 5ed66b6989..11f08f618d 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -33,15 +33,12 @@ #include #include #include -#include -#include -#include using namespace sofa; namespace sofaglfw { - SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) + SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, component::visual::BaseCamera::SPtr camera) : m_glfwWindow(glfwWindow) , m_currentCamera(camera) { @@ -53,7 +50,7 @@ namespace sofaglfw glfwDestroyWindow(m_glfwWindow); } - void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]) + void SofaGLFWWindow::draw(simulation::NodeSPtr groot, core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]) { glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); glClearDepth(1.0); @@ -102,20 +99,20 @@ namespace sofaglfw vparams->setProjectionMatrix(lastProjectionMatrix); vparams->setModelViewMatrix(lastModelviewMatrix); - sofa::simulation::node::draw(vparams, groot.get()); + simulation::node::draw(vparams, groot.get()); } - void SofaGLFWWindow::setBackgroundColor(const sofa::type::RGBAColor& newColor) + void SofaGLFWWindow::setBackgroundColor(const type::RGBAColor& newColor) { m_backgroundColor = newColor; } - void SofaGLFWWindow::setCamera(sofa::component::visual::BaseCamera::SPtr newCamera) + void SofaGLFWWindow::setCamera(component::visual::BaseCamera::SPtr newCamera) { m_currentCamera = newCamera; } - void SofaGLFWWindow::centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const + void SofaGLFWWindow::centerCamera(simulation::NodeSPtr node, core::visual::VisualParams* vparams) const { if (m_currentCamera) { @@ -144,17 +141,17 @@ namespace sofaglfw { case GLFW_PRESS: { - sofa::core::objectmodel::MouseEvent* mEvent = nullptr; + core::objectmodel::MouseEvent* mEvent = nullptr; if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::LeftPressed, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::LeftPressed, xpos, ypos); else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightPressed, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::RightPressed, xpos, ypos); else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); else { // A fallback event to rule them all... - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); } m_currentCamera->manageEvent(mEvent); @@ -166,17 +163,17 @@ namespace sofaglfw } case GLFW_RELEASE: { - sofa::core::objectmodel::MouseEvent* mEvent = nullptr; + core::objectmodel::MouseEvent* mEvent = nullptr; if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::LeftReleased, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::LeftReleased, xpos, ypos); else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::RightReleased, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::RightReleased, xpos, ypos); else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); else { // A fallback event to rules them all... - mEvent = new sofa::core::objectmodel::MouseEvent(sofa::core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); } m_currentCamera->manageEvent(mEvent); @@ -188,7 +185,7 @@ namespace sofaglfw } default: { - sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Move, xpos, ypos); + core::objectmodel::MouseEvent me(core::objectmodel::MouseEvent::Move, xpos, ypos); m_currentCamera->manageEvent(&me); break; } @@ -213,7 +210,7 @@ namespace sofaglfw SofaGLFWBaseGUI *gui = static_cast(glfwGetWindowUserPointer(window)); - sofa::gui::common::MousePosition mousepos; + gui::common::MousePosition mousepos; mousepos.screenWidth = width; mousepos.screenHeight = height; mousepos.x = static_cast(xpos); @@ -229,15 +226,15 @@ namespace sofaglfw { if (button == GLFW_MOUSE_BUTTON_LEFT) { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::LEFT); + gui->getPickHandler()->handleMouseEvent(gui::common::PRESSED, gui::common::LEFT); } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::RIGHT); + gui->getPickHandler()->handleMouseEvent(gui::common::PRESSED, gui::common::RIGHT); } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::PRESSED, sofa::gui::common::MIDDLE); + gui->getPickHandler()->handleMouseEvent(gui::common::PRESSED, gui::common::MIDDLE); } } else if (action == GLFW_RELEASE) @@ -246,16 +243,16 @@ namespace sofaglfw { if (button == GLFW_MOUSE_BUTTON_LEFT) { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::LEFT); + gui->getPickHandler()->handleMouseEvent(gui::common::RELEASED, gui::common::LEFT); gui->getPickHandler()->deactivateRay(); } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::RIGHT); + gui->getPickHandler()->handleMouseEvent(gui::common::RELEASED, gui::common::RIGHT); } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { - gui->getPickHandler()->handleMouseEvent(sofa::gui::common::RELEASED, sofa::gui::common::MIDDLE); + gui->getPickHandler()->handleMouseEvent(gui::common::RELEASED, gui::common::MIDDLE); } } } @@ -272,7 +269,7 @@ namespace sofaglfw { SOFA_UNUSED(xoffset); const double yFactor = 10.f; - sofa::core::objectmodel::MouseEvent me(sofa::core::objectmodel::MouseEvent::Wheel, static_cast(yoffset * yFactor)); + core::objectmodel::MouseEvent me(core::objectmodel::MouseEvent::Wheel, static_cast(yoffset * yFactor)); m_currentCamera->manageEvent(&me); } diff --git a/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp b/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp index 33d0edd81f..e47e20e792 100644 --- a/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp +++ b/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp @@ -47,7 +47,7 @@ void initExternalModule() { first = false; #if SOFAGLFW_HAVE_SOFA_GUI_COMMON - sofa::gui::common::GUIManager::RegisterGUI("glfw", &sofaglfw::SofaGLFWGUI::CreateGUI); + sofa::gui::common::GUIManager::RegisterGUI("glfw", &SofaGLFWGUI::CreateGUI); #endif // SOFAGLFW_HAVE_SOFA_GUI_COMMON } } diff --git a/SofaImGui/src/SofaImGui/AppIniFile.cpp b/SofaImGui/src/SofaImGui/AppIniFile.cpp index 40df9f4838..81377172ac 100644 --- a/SofaImGui/src/SofaImGui/AppIniFile.cpp +++ b/SofaImGui/src/SofaImGui/AppIniFile.cpp @@ -30,7 +30,7 @@ namespace sofaimgui { const std::string& AppIniFile::getAppIniFile() { - static const std::string appIniFile(sofa::helper::Utils::getExecutableDirectory() + "/settings.ini"); + static const std::string appIniFile(helper::Utils::getExecutableDirectory() + "/settings.ini"); return appIniFile; } diff --git a/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp b/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp index 353ba4eff5..b58bda3b19 100644 --- a/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp @@ -50,8 +50,8 @@ void DataWidget::showWidget(MyData& data) * Vec **********************************************************************************************************************/ -template< sofa::Size N, typename ValueType> -void showVecTableHeader(Data >&) +template< Size N, typename ValueType> +void showVecTableHeader(Data >&) { ImGui::TableSetupColumn(""); for (unsigned int i = 0; i < N; ++i) @@ -61,28 +61,28 @@ void showVecTableHeader(Data >&) } template -void showVecTableHeader(Data >&) +void showVecTableHeader(Data >&) { ImGui::TableSetupColumn("X"); } template -void showVecTableHeader(Data >&) +void showVecTableHeader(Data >&) { ImGui::TableSetupColumn("X"); ImGui::TableSetupColumn("Y"); } template -void showVecTableHeader(Data >&) +void showVecTableHeader(Data >&) { ImGui::TableSetupColumn("X"); ImGui::TableSetupColumn("Y"); ImGui::TableSetupColumn("Z"); } -template< sofa::Size N, typename ValueType> -void showWidgetT(Data >& data) +template< Size N, typename ValueType> +void showWidgetT(Data >& data) { static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX; ImGui::Text("%d elements", data.getValue().size()); @@ -93,7 +93,7 @@ void showWidgetT(Data >& data) ImGui::TableHeadersRow(); ImGui::TableNextRow(); - for (const auto& v : *sofa::helper::getReadAccessor(data)) + for (const auto& v : *helper::getReadAccessor(data)) { ImGui::TableNextColumn(); ImGui::Text("%f", v); @@ -104,49 +104,49 @@ void showWidgetT(Data >& data) } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } @@ -155,8 +155,8 @@ void DataWidget >::showWidget(MyData& data) * Vectors of Vec **********************************************************************************************************************/ -template< sofa::Size N, typename ValueType> -void showVecTableHeader(Data > >&) +template< Size N, typename ValueType> +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); for (unsigned int i = 0; i < N; ++i) @@ -166,14 +166,14 @@ void showVecTableHeader(Data > } template -void showVecTableHeader(Data > >&) +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); ImGui::TableSetupColumn("X"); } template -void showVecTableHeader(Data > >&) +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); ImGui::TableSetupColumn("X"); @@ -181,7 +181,7 @@ void showVecTableHeader(Data > } template -void showVecTableHeader(Data > >&) +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); ImGui::TableSetupColumn("X"); @@ -189,8 +189,8 @@ void showVecTableHeader(Data > ImGui::TableSetupColumn("Z"); } -template< sofa::Size N, typename ValueType> -void showWidgetT(Data > >& data) +template< Size N, typename ValueType> +void showWidgetT(Data > >& data) { static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX; ImGui::Text("%d elements", data.getValue().size()); @@ -201,7 +201,7 @@ void showWidgetT(Data > >& data ImGui::TableHeadersRow(); unsigned int counter {}; - for (const auto& vec : *sofa::helper::getReadAccessor(data)) + for (const auto& vec : *helper::getReadAccessor(data)) { ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -218,49 +218,49 @@ void showWidgetT(Data > >& data } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } @@ -269,18 +269,18 @@ void DataWidget > >::showWidget(MyD * Vectors of RigidCoord **********************************************************************************************************************/ -template< sofa::Size N, typename ValueType> -void showVecTableHeader(Data > >&) +template< Size N, typename ValueType> +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); - for (unsigned int i = 0; i < sofa::defaulttype::RigidCoord::total_size; ++i) + for (unsigned int i = 0; i < defaulttype::RigidCoord::total_size; ++i) { ImGui::TableSetupColumn(std::to_string(i).c_str()); } } template -void showVecTableHeader(Data > >&) +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); ImGui::TableSetupColumn("X"); @@ -294,7 +294,7 @@ void showVecTableHeader(Data -void showVecTableHeader(Data > >&) +void showVecTableHeader(Data > >&) { ImGui::TableSetupColumn(""); ImGui::TableSetupColumn("X"); @@ -303,19 +303,19 @@ void showVecTableHeader(Data -void showWidgetT(Data > >& data) +template< Size N, typename ValueType> +void showWidgetT(Data > >& data) { static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX; ImGui::Text("%d elements", data.getValue().size()); - if (ImGui::BeginTable((data.getName() + data.getOwner()->getPathName()).c_str(), sofa::defaulttype::RigidCoord::total_size + 1, flags)) + if (ImGui::BeginTable((data.getName() + data.getOwner()->getPathName()).c_str(), defaulttype::RigidCoord::total_size + 1, flags)) { showVecTableHeader(data); ImGui::TableHeadersRow(); unsigned int counter {}; - for (const auto& vec : *sofa::helper::getReadAccessor(data)) + for (const auto& vec : *helper::getReadAccessor(data)) { ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -346,25 +346,25 @@ void showWidgetT(Data -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } @@ -374,9 +374,9 @@ void DataWidget > >:: **********************************************************************************************************************/ template< typename GeometryElement> -void showWidgetT(Data > >& data) +void showWidgetT(Data > >& data) { - constexpr auto N = sofa::topology::Element::static_size; + constexpr auto N = topology::Element::static_size; static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX; ImGui::Text("%d elements", data.getValue().size()); if (ImGui::BeginTable((data.getName() + data.getOwner()->getPathName()).c_str(), N + 1, flags)) @@ -390,7 +390,7 @@ void showWidgetT(Data -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget >::showWidget(MyData& data) +void DataWidget >::showWidget(MyData& data) { showWidgetT(data); } @@ -453,7 +453,7 @@ void DataWidget >::showWidget(MyDat **********************************************************************************************************************/ template -void showWidgetT(Data > >& data) +void showWidgetT(Data > >& data) { const auto& label = data.getName(); const auto id = data.getName() + data.getOwner()->getPathName(); @@ -469,13 +469,13 @@ void showWidgetT(Data > >& data) } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } template<> -void DataWidget > >::showWidget(MyData& data) +void DataWidget > >::showWidget(MyData& data) { showWidgetT(data); } @@ -486,57 +486,57 @@ void DataWidget > >::showWidget( const bool dw_bool = DataWidgetFactory::Add(); -const bool dw_vec1d = DataWidgetFactory::Add >(); -const bool dw_vec1f = DataWidgetFactory::Add >(); +const bool dw_vec1d = DataWidgetFactory::Add >(); +const bool dw_vec1f = DataWidgetFactory::Add >(); -const bool dw_vec2d = DataWidgetFactory::Add >(); -const bool dw_vec2f = DataWidgetFactory::Add >(); +const bool dw_vec2d = DataWidgetFactory::Add >(); +const bool dw_vec2f = DataWidgetFactory::Add >(); -const bool dw_vec3d = DataWidgetFactory::Add >(); -const bool dw_vec3f = DataWidgetFactory::Add >(); +const bool dw_vec3d = DataWidgetFactory::Add >(); +const bool dw_vec3f = DataWidgetFactory::Add >(); -const bool dw_vec4d = DataWidgetFactory::Add >(); -const bool dw_vec4f = DataWidgetFactory::Add >(); +const bool dw_vec4d = DataWidgetFactory::Add >(); +const bool dw_vec4f = DataWidgetFactory::Add >(); -const bool dw_vec6d = DataWidgetFactory::Add >(); -const bool dw_vec6f = DataWidgetFactory::Add >(); +const bool dw_vec6d = DataWidgetFactory::Add >(); +const bool dw_vec6f = DataWidgetFactory::Add >(); -const bool dw_vec8d = DataWidgetFactory::Add >(); -const bool dw_vec8f = DataWidgetFactory::Add >(); +const bool dw_vec8d = DataWidgetFactory::Add >(); +const bool dw_vec8f = DataWidgetFactory::Add >(); -const bool dw_vector_vec1d = DataWidgetFactory::Add > >(); -const bool dw_vector_vec1f = DataWidgetFactory::Add > >(); +const bool dw_vector_vec1d = DataWidgetFactory::Add > >(); +const bool dw_vector_vec1f = DataWidgetFactory::Add > >(); -const bool dw_vector_vec2d = DataWidgetFactory::Add > >(); -const bool dw_vector_vec2f = DataWidgetFactory::Add > >(); +const bool dw_vector_vec2d = DataWidgetFactory::Add > >(); +const bool dw_vector_vec2f = DataWidgetFactory::Add > >(); -const bool dw_vector_vec3d = DataWidgetFactory::Add > >(); -const bool dw_vector_vec3f = DataWidgetFactory::Add > >(); +const bool dw_vector_vec3d = DataWidgetFactory::Add > >(); +const bool dw_vector_vec3f = DataWidgetFactory::Add > >(); -const bool dw_vector_vec4d = DataWidgetFactory::Add > >(); -const bool dw_vector_vec4f = DataWidgetFactory::Add > >(); +const bool dw_vector_vec4d = DataWidgetFactory::Add > >(); +const bool dw_vector_vec4f = DataWidgetFactory::Add > >(); -const bool dw_vector_vec6d = DataWidgetFactory::Add > >(); -const bool dw_vector_vec6f = DataWidgetFactory::Add > >(); +const bool dw_vector_vec6d = DataWidgetFactory::Add > >(); +const bool dw_vector_vec6f = DataWidgetFactory::Add > >(); -const bool dw_vector_vec8d = DataWidgetFactory::Add > >(); -const bool dw_vector_vec8f = DataWidgetFactory::Add > >(); +const bool dw_vector_vec8d = DataWidgetFactory::Add > >(); +const bool dw_vector_vec8f = DataWidgetFactory::Add > >(); -const bool dw_vector_rigid2d = DataWidgetFactory::Add > >(); -const bool dw_vector_rigid2f = DataWidgetFactory::Add > >(); +const bool dw_vector_rigid2d = DataWidgetFactory::Add > >(); +const bool dw_vector_rigid2f = DataWidgetFactory::Add > >(); -const bool dw_vector_rigid3d = DataWidgetFactory::Add > >(); -const bool dw_vector_rigid3f = DataWidgetFactory::Add > >(); +const bool dw_vector_rigid3d = DataWidgetFactory::Add > >(); +const bool dw_vector_rigid3f = DataWidgetFactory::Add > >(); -const bool dw_vector_edge = DataWidgetFactory::Add >(); -const bool dw_vector_hexa = DataWidgetFactory::Add >(); -const bool dw_vector_penta = DataWidgetFactory::Add >(); -const bool dw_vector_pyramid = DataWidgetFactory::Add >(); -const bool dw_vector_quad = DataWidgetFactory::Add >(); -const bool dw_vector_tetra = DataWidgetFactory::Add >(); -const bool dw_vector_tri = DataWidgetFactory::Add >(); +const bool dw_vector_edge = DataWidgetFactory::Add >(); +const bool dw_vector_hexa = DataWidgetFactory::Add >(); +const bool dw_vector_penta = DataWidgetFactory::Add >(); +const bool dw_vector_pyramid = DataWidgetFactory::Add >(); +const bool dw_vector_quad = DataWidgetFactory::Add >(); +const bool dw_vector_tetra = DataWidgetFactory::Add >(); +const bool dw_vector_tri = DataWidgetFactory::Add >(); -const bool dw_map_vectorf = DataWidgetFactory::Add > >(); -const bool dw_map_vectord = DataWidgetFactory::Add > >(); +const bool dw_map_vectorf = DataWidgetFactory::Add > >(); +const bool dw_map_vectord = DataWidgetFactory::Add > >(); } diff --git a/SofaImGui/src/SofaImGui/ImGuiGUI.cpp b/SofaImGui/src/SofaImGui/ImGuiGUI.cpp index 4ec99a8821..f869488cee 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUI.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUI.cpp @@ -33,7 +33,7 @@ namespace sofaimgui { ImGuiGUI::ImGuiGUI() -: sofaglfw::SofaGLFWGUI() +: SofaGLFWGUI() { auto guiEngine = std::make_shared(); this->m_baseGUI.setGUIEngine(guiEngine); @@ -42,7 +42,7 @@ ImGuiGUI::ImGuiGUI() sofa::gui::common::BaseGUI* ImGuiGUI::CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename) { - ImGuiGUI::mGuiName = name; + mGuiName = name; auto* gui = new ImGuiGUI(); if (!gui->init()) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUI.h b/SofaImGui/src/SofaImGui/ImGuiGUI.h index 52dbc53007..81cd230695 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUI.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUI.h @@ -34,7 +34,7 @@ class SOFAIMGUI_API ImGuiGUI : public sofaglfw::SofaGLFWGUI ~ImGuiGUI() override = default; - static sofa::gui::common::BaseGUI* CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); + static BaseGUI* CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); }; } // namespace sofaimgui diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index ae7aa36a7e..36079ee335 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -25,27 +25,18 @@ #include #include #include - -#include #include - -#include #include - #include #include - #include - #include - #include #include //imgui_internal.h is included in order to use the DockspaceBuilder API (which is still in development) #include #include #include #include -#include #include #include #include @@ -55,17 +46,12 @@ #include #include #include -#include #include #include -#include #include #include -#include #include #include -#include -#include #include #include #include @@ -111,7 +97,7 @@ void ImGuiGUIEngine::init() ImGuiIO& io = ImGui::GetIO(); (void)io; - static const std::string imguiIniFile(sofa::helper::Utils::getExecutableDirectory() + "/imgui.ini"); + static const std::string imguiIniFile(helper::Utils::getExecutableDirectory() + "/imgui.ini"); io.IniFilename = imguiIniFile.c_str(); io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; @@ -119,9 +105,9 @@ void ImGuiGUIEngine::init() ini.SetUnicode(); - if (sofa::helper::system::FileSystem::exists(sofaimgui::AppIniFile::getAppIniFile())) + if (helper::system::FileSystem::exists(AppIniFile::getAppIniFile())) { - SI_Error rc = ini.LoadFile(sofaimgui::AppIniFile::getAppIniFile().c_str()); + SI_Error rc = ini.LoadFile(AppIniFile::getAppIniFile().c_str()); assert(rc == SI_OK); } @@ -129,17 +115,17 @@ void ImGuiGUIEngine::init() pv = ini.GetValue("Style", "theme"); if (!pv) { - ini.SetValue("Style", "theme", sofaimgui::defaultStyle.c_str(), "# Preset of colors and properties to change the theme of the application"); - SI_Error rc = ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str()); + ini.SetValue("Style", "theme", defaultStyle.c_str(), "# Preset of colors and properties to change the theme of the application"); + SI_Error rc = ini.SaveFile(AppIniFile::getAppIniFile().c_str()); assert(rc == SI_OK); - pv = sofaimgui::defaultStyle.c_str(); + pv = defaultStyle.c_str(); } // Setup Dear ImGui style - sofaimgui::setStyle(pv); + setStyle(pv); - sofa::helper::system::PluginManager::getInstance().readFromIniFile( - sofa::gui::common::BaseGUI::getConfigDirectoryPath() + "/loadedPlugins.ini"); + helper::system::PluginManager::getInstance().readFromIniFile( + gui::common::BaseGUI::getConfigDirectoryPath() + "/loadedPlugins.ini"); } void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow) @@ -176,14 +162,14 @@ void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow) } } -void ImGuiGUIEngine::loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, const std::string filePathName) +void ImGuiGUIEngine::loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, core::sptr& groot, const std::string filePathName) { - sofa::simulation::node::unload(groot); - groot = sofa::simulation::node::load(filePathName.c_str()); + simulation::node::unload(groot); + groot = simulation::node::load(filePathName.c_str()); if( !groot ) - groot = sofa::simulation::getSimulation()->createNewGraph(""); + groot = simulation::getSimulation()->createNewGraph(""); baseGUI->setSimulation(groot, filePathName); - sofa::simulation::node::initRoot(groot.get()); + simulation::node::initRoot(groot.get()); auto camera = baseGUI->findCamera(groot); if (camera) { @@ -200,10 +186,10 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) bool alwaysShowFrame = ini.GetBoolValue("Visualization", "alwaysShowFrame", true); if (alwaysShowFrame) { - auto sceneFrame = groot->get(); + auto sceneFrame = groot->get(); if (!sceneFrame) { - auto newSceneFrame = sofa::core::objectmodel::New(); + auto newSceneFrame = sofa::core::objectmodel::New(); groot->addObject(newSceneFrame); newSceneFrame->setName("viewportFrame"); newSceneFrame->addTag(core::objectmodel::Tag("createdByGUI")); @@ -303,7 +289,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) { const auto filterName = (*it)->getFileTypeDesc(); - sofa::simulation::SceneLoader::ExtensionList extensions; + simulation::SceneLoader::ExtensionList extensions; (*it)->getExtensionList(&extensions); std::string extensionsString; for (auto itExt=extensions.begin(); itExt!=extensions.end(); ++itExt) @@ -362,9 +348,9 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) if (ImGui::MenuItem(ICON_FA_TIMES_CIRCLE " Close Simulation")) { - sofa::simulation::node::unload(groot); + simulation::node::unload(groot); baseGUI->setSimulationIsRunning(false); - sofa::simulation::node::initRoot(baseGUI->getRootNode().get()); + simulation::node::initRoot(baseGUI->getRootNode().get()); return; } ImGui::Separator(); @@ -386,7 +372,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) ImGui::Separator(); if (ImGui::MenuItem(ICON_FA_CAMERA ICON_FA_CROSSHAIRS" Center Camera")) { - sofa::component::visual::BaseCamera::SPtr camera; + component::visual::BaseCamera::SPtr camera; groot->get(camera); if (camera) { @@ -404,7 +390,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) const std::string viewFileName = baseGUI->getFilename() + VIEW_FILE_EXTENSION; if (ImGui::MenuItem(ICON_FA_CAMERA ICON_FA_ARROW_RIGHT" Save Camera")) { - sofa::component::visual::BaseCamera::SPtr camera; + component::visual::BaseCamera::SPtr camera; groot->get(camera); if (camera) { @@ -418,11 +404,11 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) } } } - bool fileExists = sofa::helper::system::FileSystem::exists(viewFileName); + bool fileExists = helper::system::FileSystem::exists(viewFileName); ImGui::BeginDisabled(!fileExists); if (ImGui::MenuItem(ICON_FA_CAMERA ICON_FA_ARROW_LEFT" Restore Camera")) { - sofa::component::visual::BaseCamera::SPtr camera; + component::visual::BaseCamera::SPtr camera; groot->get(camera); if (camera) { @@ -457,7 +443,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) if (result == NFD_OKAY) { helper::io::STBImage image; - image.init(m_currentFBOSize.first, m_currentFBOSize.second, 1, 1, sofa::helper::io::Image::DataType::UINT32, sofa::helper::io::Image::ChannelFormat::RGBA); + image.init(m_currentFBOSize.first, m_currentFBOSize.second, 1, 1, helper::io::Image::DataType::UINT32, helper::io::Image::ChannelFormat::RGBA); glBindTexture(GL_TEXTURE_2D, m_fbo->getColorTexture()); @@ -499,7 +485,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) ImGui::SetCursorPosX(ImGui::GetColumnWidth() / 2); //approximatively the center of the menu bar if (ImGui::Button(animate ? ICON_FA_PAUSE : ICON_FA_PLAY)) { - sofa::helper::getWriteOnlyAccessor(groot->animate_).wref() = !animate; + helper::getWriteOnlyAccessor(groot->animate_).wref() = !animate; } ImGui::SameLine(); if (animate) @@ -511,12 +497,12 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) { if (!animate) { - sofa::helper::AdvancedTimer::begin("Animate"); + helper::AdvancedTimer::begin("Animate"); - sofa::simulation::node::animate(groot.get(), groot->getDt()); - sofa::simulation::node::updateVisual(groot.get()); + simulation::node::animate(groot.get(), groot->getDt()); + simulation::node::updateVisual(groot.get()); - sofa::helper::AdvancedTimer::end("Animate"); + helper::AdvancedTimer::end("Animate"); } } if (animate) @@ -528,7 +514,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) if (ImGui::Button(ICON_FA_REDO_ALT)) { groot->setTime(0.); - sofa::simulation::node::reset ( groot.get() ); + simulation::node::reset ( groot.get() ); } const auto posX = ImGui::GetCursorPosX(); @@ -556,55 +542,55 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) /*************************************** * Viewport window **************************************/ - windows::showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&lastViewPortPosX,&lastViewPortPosY); + showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&lastViewPortPosX,&lastViewPortPosY); /*************************************** * Performances window **************************************/ - windows::showPerformances(windowNamePerformances, io, winManagerPerformances); + showPerformances(windowNamePerformances, io, winManagerPerformances); /*************************************** * Profiler window **************************************/ - sofa::helper::AdvancedTimer::setEnabled("Animate", winManagerProfiler.getStatePtr()); - sofa::helper::AdvancedTimer::setInterval("Animate", 1); - sofa::helper::AdvancedTimer::setOutputType("Animate", "gui"); + helper::AdvancedTimer::setEnabled("Animate", winManagerProfiler.getStatePtr()); + helper::AdvancedTimer::setInterval("Animate", 1); + helper::AdvancedTimer::setOutputType("Animate", "gui"); - windows::showProfiler(groot, windowNameProfiler, winManagerProfiler); + showProfiler(groot, windowNameProfiler, winManagerProfiler); /*************************************** * Scene graph window **************************************/ static std::set openedComponents; static std::set focusedComponents; - windows::showSceneGraph(groot, windowNameSceneGraph, openedComponents, focusedComponents, winManagerSceneGraph); + showSceneGraph(groot, windowNameSceneGraph, openedComponents, focusedComponents, winManagerSceneGraph); /*************************************** * Display flags window **************************************/ - windows::showDisplayFlags(groot, windowNameDisplayFlags, winManagerDisplayFlags); + showDisplayFlags(groot, windowNameDisplayFlags, winManagerDisplayFlags); /*************************************** * Plugins window **************************************/ - windows::showPlugins(windowNamePlugins, winManagerPlugins); + showPlugins(windowNamePlugins, winManagerPlugins); /*************************************** * Components window **************************************/ - windows::showComponents(windowNameComponents, winManagerComponents); + showComponents(windowNameComponents, winManagerComponents); /*************************************** * Log window **************************************/ - windows::showLog(windowNameLog, winManagerLog); + showLog(windowNameLog, winManagerLog); /*************************************** * Settings window **************************************/ - windows::showSettings(windowNameSettings,ini, winManagerSettings); + showSettings(windowNameSettings,ini, winManagerSettings); ImGui::Render(); #if SOFAIMGUI_FORCE_OPENGL2 == 1 @@ -628,7 +614,7 @@ void ImGuiGUIEngine::beforeDraw(GLFWwindow*) if (!m_fbo) { - m_fbo = std::make_unique(); + m_fbo = std::make_unique(); m_currentFBOSize = {1000, 500}; m_fbo->init(m_currentFBOSize.first, m_currentFBOSize.second); } @@ -641,7 +627,7 @@ void ImGuiGUIEngine::beforeDraw(GLFWwindow*) m_currentFBOSize = {static_cast(m_viewportWindowSize.first), static_cast(m_viewportWindowSize.second)}; } } - sofa::core::visual::VisualParams::defaultInstance()->viewport() = {0,0,m_currentFBOSize.first, m_currentFBOSize.second}; + core::visual::VisualParams::defaultInstance()->viewport() = {0,0,m_currentFBOSize.first, m_currentFBOSize.second}; m_fbo->start(); } diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index 80f308bdff..2d26b2264a 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -70,16 +70,16 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine void loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, std::string filePathName); // WindowState members - windows::WindowState winManagerProfiler; - windows::WindowState winManagerSceneGraph; - windows::WindowState winManagerPerformances; - windows::WindowState winManagerDisplayFlags; - windows::WindowState winManagerPlugins; - windows::WindowState winManagerComponents; - windows::WindowState winManagerLog; - windows::WindowState winManagerSettings; - windows::WindowState winManagerViewPort; - windows::WindowState firstRunState; + WindowState winManagerProfiler; + WindowState winManagerSceneGraph; + WindowState winManagerPerformances; + WindowState winManagerDisplayFlags; + WindowState winManagerPlugins; + WindowState winManagerComponents; + WindowState winManagerLog; + WindowState winManagerSettings; + WindowState winManagerViewPort; + WindowState firstRunState; }; } // namespace sofaimgui diff --git a/SofaImGui/src/SofaImGui/initSofaImGui.cpp b/SofaImGui/src/SofaImGui/initSofaImGui.cpp index bbcc25c814..a469b12240 100644 --- a/SofaImGui/src/SofaImGui/initSofaImGui.cpp +++ b/SofaImGui/src/SofaImGui/initSofaImGui.cpp @@ -48,7 +48,7 @@ void initExternalModule() sofa::helper::logging::MessageDispatcher::addHandler(&sofa::helper::logging::MainLoggingMessageHandler::getInstance()); sofa::helper::logging::MainLoggingMessageHandler::getInstance().activate(); - sofa::gui::common::GUIManager::RegisterGUI("imgui", &sofaimgui::ImGuiGUI::CreateGUI); + sofa::gui::common::GUIManager::RegisterGUI("imgui", &ImGuiGUI::CreateGUI); } } diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp index 35a36f24a1..38c20f7d13 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp @@ -20,10 +20,8 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include -#include #include #include -#include #include #include #include @@ -31,10 +29,7 @@ #include #include #include -#include #include "ViewPort.h" -#include -#include #include "SofaGLFW/SofaGLFWBaseGUI.h" #include namespace windows @@ -49,11 +44,9 @@ namespace windows WindowState& winManagerViewPort, sofaglfw::SofaGLFWBaseGUI* baseGUI, bool* firstViewport, - float * lastViewPortPosX, - float * lastViewPortPosY) + float* lastViewPortPosX, + float* lastViewPortPosY) { - static auto lastTime = std::chrono::steady_clock::now(); - const float precisionThreshold = 1.0f; if (*winManagerViewPort.getStatePtr()) { std::setprecision(1); @@ -76,15 +69,11 @@ namespace windows baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); } - else + else if (hasViewportMoved(viewportPos.x, viewportPos.y, *lastViewPortPosX, *lastViewPortPosY, precisionThreshold)) { - if (std::fabs(viewportPos.x - *lastViewPortPosX) > precisionThreshold || - std::fabs(viewportPos.y - *lastViewPortPosY) > precisionThreshold) - { baseGUI->updateViewportPosition(viewportPos.x,viewportPos.y); *lastViewPortPosX=viewportPos.x; *lastViewPortPosY=viewportPos.y; - } } ImGui::Image((ImTextureID)m_fbo->getColorTexture(), wsize, ImVec2(0, 1), ImVec2(1, 0)); @@ -173,8 +162,10 @@ namespace windows ImGui::End(); } } - } - + } + bool hasViewportMoved(float currentX, float currentY, float lastX, float lastY, float threshold) { + return (std::fabs(currentX - lastX) > threshold || std::fabs(currentY - lastY) > threshold); + } } \ No newline at end of file diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.h b/SofaImGui/src/SofaImGui/windows/ViewPort.h index d63ccd401b..82340c49fb 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.h +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.h @@ -27,31 +27,56 @@ namespace windows { - /** - * @brief Displays the viewport window. - * - * This function renders the viewport window, showing the scene rendered into a frame buffer object (FBO). - * It also provides options to show/hide grid, axis, and frame within the viewport. - * - * @param groot The root node of the scene to be rendered. - * @param windowNameViewport The name of the viewport window. - * @param isViewportWindowOpen A reference to a boolean flag indicating if the viewport window is open. - * @param ini The INI file object containing application settings. - * @param m_fbo The frame buffer object (FBO) used for rendering the scene. - * @param m_viewportWindowSize A reference to a pair representing the width and height of the viewport window. - * @param isMouseOnViewport A reference to a boolean flag indicating if the mouse cursor is over the viewport. - */ - void showViewPort(sofa::core::sptr groot, - const char* const& windowNameViewport, - CSimpleIniA &ini, - std::unique_ptr& m_fbo, - std::pair& m_viewportWindowSize, - bool & isMouseOnViewport, - WindowState& winManagerViewPort, - sofaglfw::SofaGLFWBaseGUI* baseGUI, - bool *firstViewport, - float *lastViewPortPosX, - float *lastViewPortPosY); + /** + * @brief Displays the viewport window. + * + * This function renders the viewport window, showing the scene rendered into a frame buffer object (FBO). + * It also provides options to show/hide grid, axis, and frame within the viewport. + * + * @param groot The root node of the scene to be rendered. + * @param windowNameViewport The name of the viewport window. + * @param ini The INI file object containing application settings. + * @param m_fbo The frame buffer object (FBO) used for rendering the scene. + * @param m_viewportWindowSize A reference to a pair representing the width and height of the viewport window. + * @param isMouseOnViewport A reference to a boolean flag indicating if the mouse cursor is over the viewport. + * @param winManagerViewPort The state manager for the viewport window. + * @param baseGUI A pointer to the base GUI object. + * @param firstViewport A pointer to a boolean indicating if this is the first time the viewport is being displayed. + * @param lastViewPortPosX A pointer to the last recorded X position of the viewport. + * @param lastViewPortPosY A pointer to the last recorded Y position of the viewport. + */ + void showViewPort( sofa::core::sptr groot, + const char* const& windowNameViewport, + CSimpleIniA &ini, + std::unique_ptr& m_fbo, + std::pair& m_viewportWindowSize, + bool & isMouseOnViewport, + WindowState& winManagerViewPort, + sofaglfw::SofaGLFWBaseGUI* baseGUI, + bool* firstViewport, + float* lastViewPortPosX, + float* lastViewPortPosY); + + /** + * @brief Checks if the viewport position has moved beyond a specified threshold. + * + * This function compares the current viewport position with the last recorded position + * and determines if the movement exceeds the given precision threshold. + * + * @param currentX The current X position of the viewport. + * @param currentY The current Y position of the viewport. + * @param lastX The last recorded X position of the viewport. + * @param lastY The last recorded Y position of the viewport. + * @param threshold The precision threshold to determine significant movement. + * @return True if the viewport has moved beyond the threshold, false otherwise. + */ + bool hasViewportMoved( float currentX, + float currentY, + float lastX, + float lastY, + float threshold); + + constexpr float precisionThreshold = 1.0f; } // namespace sofaimgui From 4441c0d885f1bbf547e3d3b4b79c8e68070ef49f Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 1 Aug 2024 13:11:37 +0200 Subject: [PATCH 18/41] handling merge fix bug --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 4 ++++ SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index abe5beb0ac..48c0a2d744 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -879,6 +879,10 @@ bool SofaGLFWBaseGUI::centerWindow(GLFWwindow* window) // and the main screen window = (!window) ? m_firstWindow : window; } + if (window == nullptr) + { + return false; + } int sx = 0, sy = 0; int px = 0, py = 0; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 5326f8c10c..636590d53b 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -74,14 +74,16 @@ namespace sofaglfw void updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) ; GLFWmonitor* getCurrentMonitor(GLFWwindow *window); - virtual void viewAll() ; - virtual void saveView() ; - virtual void setSizeW(int width) ; - virtual void setSizeH(int height) ; - virtual int getWidth() ; - virtual int getHeight() ; - virtual void drawScene() ; - virtual void redraw() ; bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; + virtual void viewAll() override { std::cout << "viewAll() Called" << std::endl; } + virtual void saveView() override { std::cout << "saveView() Called" << std::endl; } + virtual void setSizeW(int width) override; + virtual void setSizeH(int height) override; + virtual int getWidth() override; + virtual int getHeight() override; + virtual void drawScene() override { std::cout << "drawScene() Called" << std::endl; } + virtual void redraw() override { std::cout << "redraw() Called" << std::endl; } + + bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; void switchFullScreen(GLFWwindow* glfwWindow = nullptr, unsigned int screenID = 0); void setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int windowID = 0); virtual void setBackgroundImage(const std::string& imageFileName = "textures/SOFA_logo.bmp", unsigned int windowID = 0); From a9a2e2e3da45b978f0a24e7a4a4f37d2e503f27d Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 1 Aug 2024 14:52:28 +0200 Subject: [PATCH 19/41] fix bugs --- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 36079ee335..a15046752f 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -134,7 +134,7 @@ void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow) ImGui_ImplGlfw_InitForOpenGL(glfwWindow, true); #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL2_Init(); + ImGui_ImplOpenGL3_NewFrame; #else ImGui_ImplOpenGL3_Init(nullptr); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 @@ -200,7 +200,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) // Start the Dear ImGui frame #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL2_NewFrame(); + ImGui_ImplOpenGL3_NewFrame(); #else ImGui_ImplOpenGL3_NewFrame(); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 @@ -594,7 +594,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) ImGui::Render(); #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); #else ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 @@ -642,7 +642,7 @@ void ImGuiGUIEngine::terminate() NFD_Quit(); #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL2_Shutdown(); + ImGui_ImplOpenGL3_Shutdown(); #else ImGui_ImplOpenGL3_Shutdown(); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 From e96f2a881a31f6e9ebacad1b65266bd812964758 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 1 Aug 2024 15:26:01 +0200 Subject: [PATCH 20/41] reverse indents and remove unnecessary declarations --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 28 ++- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 219 +++++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 3 - SofaImGui/src/SofaImGui/windows/ViewPort.cpp | 1 - SofaImGui/src/SofaImGui/windows/ViewPort.h | 98 ++++----- 5 files changed, 180 insertions(+), 169 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 48c0a2d744..dd3b6a8773 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -163,22 +163,42 @@ namespace sofaglfw } - void SofaGLFWBaseGUI::setSizeW(int width) { + void SofaGLFWBaseGUI::setSizeW(int width) + { m_windowWidth = width; } - void SofaGLFWBaseGUI::setSizeH(int height) { + void SofaGLFWBaseGUI::setSizeH(int height) + { m_windowHeight = height; } - int SofaGLFWBaseGUI::getWidth() { + int SofaGLFWBaseGUI::getWidth() + { return m_windowWidth; } - int SofaGLFWBaseGUI::getHeight() { + int SofaGLFWBaseGUI::getHeight() + { return m_windowHeight; } + void SofaGLFWBaseGUI::redraw() + { + } + + void SofaGLFWBaseGUI::drawScene() + { + } + + void SofaGLFWBaseGUI::viewAll() + { + } + + void SofaGLFWBaseGUI::saveView() + { + } + void SofaGLFWBaseGUI::changeCamera(BaseCamera::SPtr newCamera) { for (auto& w : s_mapWindows) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 636590d53b..21cc582b46 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -21,7 +21,6 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #pragma once -#include #include #include @@ -33,10 +32,6 @@ #include #include -#include -#include - - struct GLFWwindow; struct GLFWmonitor; @@ -46,112 +41,112 @@ namespace sofaglfw class SofaGLFWWindow; - class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { - public: - - SofaGLFWBaseGUI(); - - virtual ~SofaGLFWBaseGUI(); - - bool init(int nbMSAASamples = 0); - void setErrorCallback() const; - void setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename = std::string()); - void setSimulationIsRunning(bool running); - bool simulationIsRunning() const; - - bool createWindow(int width, int height, const char* title, bool fullscreenAtStartup = false); - void destroyWindow(); - void initVisual(); - std::size_t runLoop(std::size_t targetNbIterations = 0); - void terminate(); - - int getWindowWidth() const { return m_windowWidth; } - void setWindowWidth(int width) { m_windowWidth = width; } - int getWindowHeight() const { return m_windowHeight; } - void setWindowHeight(int height) { m_windowHeight = height; } - void resizeWindow(int width, int height); - bool centerWindow(GLFWwindow* window = nullptr); - void updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) ; - - GLFWmonitor* getCurrentMonitor(GLFWwindow *window); - virtual void viewAll() override { std::cout << "viewAll() Called" << std::endl; } - virtual void saveView() override { std::cout << "saveView() Called" << std::endl; } - virtual void setSizeW(int width) override; - virtual void setSizeH(int height) override; - virtual int getWidth() override; - virtual int getHeight() override; - virtual void drawScene() override { std::cout << "drawScene() Called" << std::endl; } - virtual void redraw() override { std::cout << "redraw() Called" << std::endl; } - - bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; - void switchFullScreen(GLFWwindow* glfwWindow = nullptr, unsigned int screenID = 0); - void setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int windowID = 0); - virtual void setBackgroundImage(const std::string& imageFileName = "textures/SOFA_logo.bmp", unsigned int windowID = 0); - - sofa::core::sptr getRootNode() const; - bool hasWindow() const { return m_firstWindow != nullptr; } - - [[nodiscard]] std::string getFilename() const { return m_filename; } - - sofa::component::visual::BaseCamera::SPtr findCamera(sofa::simulation::NodeSPtr groot); - void changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera); - void setWindowIcon(GLFWwindow* glfwWindow); - - void setGUIEngine(std::shared_ptr guiEngine) { m_guiEngine = guiEngine; } - std::shared_ptr getGUIEngine() { return m_guiEngine; } - void moveRayPickInteractor(int eventX, int eventY) override ; - - private: - // GLFW callbacks - static void error_callback(int error, const char* description); - static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); - static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos); - static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); - static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); - static void close_callback(GLFWwindow* window); - static void window_focus_callback(GLFWwindow* window, int focused); - static void cursor_enter_callback(GLFWwindow* window, int entered); - static void monitor_callback(GLFWmonitor* monitor, int event); - static void character_callback(GLFWwindow* window, unsigned int codepoint); - static void window_pos_callback(GLFWwindow* window, int xpos, int ypos); - static int handleArrowKeys(int key); - static void translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos); - - void makeCurrentContext(GLFWwindow* sofaWindow); - void runStep(); - - inline static std::map s_mapWindows{}; - inline static std::map s_mapGUIs{}; - - bool m_bGlfwIsInitialized{ false }; - bool m_bGlewIsInitialized{ false }; - - sofa::simulation::NodeSPtr m_groot; - std::string m_filename; - sofa::gl::DrawToolGL* m_glDrawTool{ nullptr }; - sofa::core::visual::VisualParams* m_vparams{ nullptr }; - GLFWwindow* m_firstWindow{ nullptr }; - int m_windowWidth{ 0 }; - int m_windowHeight{ 0 }; - int m_lastWindowPositionX{ 0 }; - int m_lastWindowPositionY{ 0 }; - int m_lastWindowWidth{ 0 }; - int m_lastWindowHeight{ 0 }; - double lastProjectionMatrix[16]; - double lastModelviewMatrix[16]; - bool m_isMouseInteractionEnabled{ false }; - float viewPortPositionX {0}; - float viewPortPositionY {0}; - float winPositionX {0}; - float winPositionY {0}; - SofaGLFWMouseManager* m_sofaGLFWMouseManager; - int viewPortHeight{0}; - int viewPortWidth {0}; - double translatedXPos {0}; - double translatedYpos {0}; - - - std::shared_ptr m_guiEngine; - }; +class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { +public: + + SofaGLFWBaseGUI(); + + virtual ~SofaGLFWBaseGUI(); + + bool init(int nbMSAASamples = 0); + void setErrorCallback() const; + void setSimulation(sofa::simulation::NodeSPtr groot, const std::string& filename = std::string()); + void setSimulationIsRunning(bool running); + bool simulationIsRunning() const; + + bool createWindow(int width, int height, const char* title, bool fullscreenAtStartup = false); + void destroyWindow(); + void initVisual(); + std::size_t runLoop(std::size_t targetNbIterations = 0); + void terminate(); + + int getWindowWidth() const { return m_windowWidth; } + void setWindowWidth(int width) { m_windowWidth = width; } + int getWindowHeight() const { return m_windowHeight; } + void setWindowHeight(int height) { m_windowHeight = height; } + void resizeWindow(int width, int height); + bool centerWindow(GLFWwindow* window = nullptr); + void updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) ; + + GLFWmonitor* getCurrentMonitor(GLFWwindow *window); + void viewAll() override; + void saveView() override ; + void setSizeW(int width) override; + void setSizeH(int height) override; + int getWidth() override; + int getHeight() override; + void drawScene() override ; + void redraw() override; + + bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; + void switchFullScreen(GLFWwindow* glfwWindow = nullptr, unsigned int screenID = 0); + void setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int windowID = 0); + virtual void setBackgroundImage(const std::string& imageFileName = "textures/SOFA_logo.bmp", unsigned int windowID = 0); + + sofa::core::sptr getRootNode() const; + bool hasWindow() const { return m_firstWindow != nullptr; } + + [[nodiscard]] std::string getFilename() const { return m_filename; } + + sofa::component::visual::BaseCamera::SPtr findCamera(sofa::simulation::NodeSPtr groot); + void changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera); + void setWindowIcon(GLFWwindow* glfwWindow); + + void setGUIEngine(std::shared_ptr guiEngine) { m_guiEngine = guiEngine; } + std::shared_ptr getGUIEngine() { return m_guiEngine; } + void moveRayPickInteractor(int eventX, int eventY) override ; + +private: + // GLFW callbacks + static void error_callback(int error, const char* description); + static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); + static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos); + static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); + static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); + static void close_callback(GLFWwindow* window); + static void window_focus_callback(GLFWwindow* window, int focused); + static void cursor_enter_callback(GLFWwindow* window, int entered); + static void monitor_callback(GLFWmonitor* monitor, int event); + static void character_callback(GLFWwindow* window, unsigned int codepoint); + static void window_pos_callback(GLFWwindow* window, int xpos, int ypos); + static int handleArrowKeys(int key); + static void translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos); + + void makeCurrentContext(GLFWwindow* sofaWindow); + void runStep(); + + inline static std::map s_mapWindows{}; + inline static std::map s_mapGUIs{}; + + bool m_bGlfwIsInitialized{ false }; + bool m_bGlewIsInitialized{ false }; + + sofa::simulation::NodeSPtr m_groot; + std::string m_filename; + sofa::gl::DrawToolGL* m_glDrawTool{ nullptr }; + sofa::core::visual::VisualParams* m_vparams{ nullptr }; + GLFWwindow* m_firstWindow{ nullptr }; + int m_windowWidth{ 0 }; + int m_windowHeight{ 0 }; + int m_lastWindowPositionX{ 0 }; + int m_lastWindowPositionY{ 0 }; + int m_lastWindowWidth{ 0 }; + int m_lastWindowHeight{ 0 }; + double lastProjectionMatrix[16]; + double lastModelviewMatrix[16]; + bool m_isMouseInteractionEnabled{ false }; + float viewPortPositionX {0}; + float viewPortPositionY {0}; + float winPositionX {0}; + float winPositionY {0}; + SofaGLFWMouseManager* m_sofaGLFWMouseManager; + int viewPortHeight{0}; + int viewPortWidth {0}; + double translatedXPos {0}; + double translatedYpos {0}; + + + std::shared_ptr m_guiEngine; +}; } // namespace sofaglfw \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h index 9abfc46407..935dae04ab 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -26,9 +26,6 @@ #include #include "SofaGLFWBaseGUI.h" -struct GLFWwindow; -struct GLFWmonitor; -class SofaMouseManager; using namespace sofa::gui::common; diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp index 38c20f7d13..36e0c8989d 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.cpp +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.cpp @@ -49,7 +49,6 @@ namespace windows { if (*winManagerViewPort.getStatePtr()) { - std::setprecision(1); ImVec2 pos; if (ImGui::Begin(windowNameViewport, winManagerViewPort.getStatePtr()/*, ImGuiWindowFlags_MenuBar*/)) { diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.h b/SofaImGui/src/SofaImGui/windows/ViewPort.h index 82340c49fb..d341d40b09 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.h +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.h @@ -27,56 +27,56 @@ namespace windows { - /** - * @brief Displays the viewport window. - * - * This function renders the viewport window, showing the scene rendered into a frame buffer object (FBO). - * It also provides options to show/hide grid, axis, and frame within the viewport. - * - * @param groot The root node of the scene to be rendered. - * @param windowNameViewport The name of the viewport window. - * @param ini The INI file object containing application settings. - * @param m_fbo The frame buffer object (FBO) used for rendering the scene. - * @param m_viewportWindowSize A reference to a pair representing the width and height of the viewport window. - * @param isMouseOnViewport A reference to a boolean flag indicating if the mouse cursor is over the viewport. - * @param winManagerViewPort The state manager for the viewport window. - * @param baseGUI A pointer to the base GUI object. - * @param firstViewport A pointer to a boolean indicating if this is the first time the viewport is being displayed. - * @param lastViewPortPosX A pointer to the last recorded X position of the viewport. - * @param lastViewPortPosY A pointer to the last recorded Y position of the viewport. - */ - void showViewPort( sofa::core::sptr groot, - const char* const& windowNameViewport, - CSimpleIniA &ini, - std::unique_ptr& m_fbo, - std::pair& m_viewportWindowSize, - bool & isMouseOnViewport, - WindowState& winManagerViewPort, - sofaglfw::SofaGLFWBaseGUI* baseGUI, - bool* firstViewport, - float* lastViewPortPosX, - float* lastViewPortPosY); + /** + * @brief Displays the viewport window. + * + * This function renders the viewport window, showing the scene rendered into a frame buffer object (FBO). + * It also provides options to show/hide grid, axis, and frame within the viewport. + * + * @param groot The root node of the scene to be rendered. + * @param windowNameViewport The name of the viewport window. + * @param ini The INI file object containing application settings. + * @param m_fbo The frame buffer object (FBO) used for rendering the scene. + * @param m_viewportWindowSize A reference to a pair representing the width and height of the viewport window. + * @param isMouseOnViewport A reference to a boolean flag indicating if the mouse cursor is over the viewport. + * @param winManagerViewPort The state manager for the viewport window. + * @param baseGUI A pointer to the base GUI object. + * @param firstViewport A pointer to a boolean indicating if this is the first time the viewport is being displayed. + * @param lastViewPortPosX A pointer to the last recorded X position of the viewport. + * @param lastViewPortPosY A pointer to the last recorded Y position of the viewport. + */ + void showViewPort(sofa::core::sptr groot, + const char* const& windowNameViewport, + CSimpleIniA &ini, + std::unique_ptr& m_fbo, + std::pair& m_viewportWindowSize, + bool & isMouseOnViewport, + WindowState& winManagerViewPort, + sofaglfw::SofaGLFWBaseGUI* baseGUI, + bool* firstViewport, + float* lastViewPortPosX, + float* lastViewPortPosY); - /** - * @brief Checks if the viewport position has moved beyond a specified threshold. - * - * This function compares the current viewport position with the last recorded position - * and determines if the movement exceeds the given precision threshold. - * - * @param currentX The current X position of the viewport. - * @param currentY The current Y position of the viewport. - * @param lastX The last recorded X position of the viewport. - * @param lastY The last recorded Y position of the viewport. - * @param threshold The precision threshold to determine significant movement. - * @return True if the viewport has moved beyond the threshold, false otherwise. - */ - bool hasViewportMoved( float currentX, - float currentY, - float lastX, - float lastY, - float threshold); + /** + * @brief Checks if the viewport position has moved beyond a specified threshold. + * + * This function compares the current viewport position with the last recorded position + * and determines if the movement exceeds the given precision threshold. + * + * @param currentX The current X position of the viewport. + * @param currentY The current Y position of the viewport. + * @param lastX The last recorded X position of the viewport. + * @param lastY The last recorded Y position of the viewport. + * @param threshold The precision threshold to determine significant movement. + * @return True if the viewport has moved beyond the threshold, false otherwise. + */ + bool hasViewportMoved(float currentX, + float currentY, + float lastX, + float lastY, + float threshold); - constexpr float precisionThreshold = 1.0f; + constexpr float precisionThreshold = 1.0f; } // namespace sofaimgui From 7b08a8619938473f952046ca2df848d3c1439446 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 1 Aug 2024 15:29:47 +0200 Subject: [PATCH 21/41] reverse indentation --- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 48 ++++++++++++------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index d303eb3f75..199bd9ef43 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -75,30 +75,30 @@ namespace sofaglfw m_currentCamera->d_widthViewport.setValue(vparams->viewport()[2]); m_currentCamera->d_heightViewport.setValue(vparams->viewport()[3]); - m_currentCamera->getModelViewMatrix( lastModelviewMatrix ); - vparams->setModelViewMatrix( lastModelviewMatrix ); - // matrices - double projectionMatrix[16]; - double mvMatrix[16]; - m_currentCamera->getOpenGLProjectionMatrix(lastProjectionMatrix); - m_currentCamera->getOpenGLModelViewMatrix(lastModelviewMatrix); - - glViewport(0, 0, vparams->viewport()[2], vparams->viewport()[3]); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMultMatrixd(lastProjectionMatrix); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMultMatrixd(lastModelviewMatrix); - - // Update the visual params - vparams->zNear() = m_currentCamera->getZNear(); - vparams->zFar() = m_currentCamera->getZFar(); - vparams->setProjectionMatrix(lastProjectionMatrix); - vparams->setModelViewMatrix(lastModelviewMatrix); - - simulation::node::draw(vparams, groot.get()); + m_currentCamera->getModelViewMatrix( lastModelviewMatrix ); + vparams->setModelViewMatrix( lastModelviewMatrix ); + // matrices + double projectionMatrix[16]; + double mvMatrix[16]; + m_currentCamera->getOpenGLProjectionMatrix(lastProjectionMatrix); + m_currentCamera->getOpenGLModelViewMatrix(lastModelviewMatrix); + + glViewport(0, 0, vparams->viewport()[2], vparams->viewport()[3]); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMultMatrixd(lastProjectionMatrix); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMultMatrixd(lastModelviewMatrix); + + // Update the visual params + vparams->zNear() = m_currentCamera->getZNear(); + vparams->zFar() = m_currentCamera->getZFar(); + vparams->setProjectionMatrix(lastProjectionMatrix); + vparams->setModelViewMatrix(lastModelviewMatrix); + + simulation::node::draw(vparams, groot.get()); } void SofaGLFWWindow::setBackgroundColor(const type::RGBAColor& newColor) From 57dba6cfa17eabc6398237384e2e1a550b573f13 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 2 Aug 2024 11:50:52 +0200 Subject: [PATCH 22/41] fix indentation --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 412 +++++++++++----------- 1 file changed, 206 insertions(+), 206 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index dd3b6a8773..c9ede97f36 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -74,48 +74,48 @@ namespace sofaglfw m_sofaGLFWMouseManager = new SofaGLFWMouseManager(); } - SofaGLFWBaseGUI::~SofaGLFWBaseGUI() - { - terminate(); - } +SofaGLFWBaseGUI::~SofaGLFWBaseGUI() +{ + terminate(); +} - core::sptr SofaGLFWBaseGUI::getRootNode() const - { - return m_groot; - } +core::sptr SofaGLFWBaseGUI::getRootNode() const +{ + return m_groot; +} - bool SofaGLFWBaseGUI::init(int nbMSAASamples) - { - if (m_bGlfwIsInitialized) - return true; +bool SofaGLFWBaseGUI::init(int nbMSAASamples) +{ + if (m_bGlfwIsInitialized) + return true; - setErrorCallback(); + setErrorCallback(); - if (glfwInit() == GLFW_TRUE) - { - // defined samples for MSAA - // min = 0 (no MSAA Anti-aliasing) - // max = 32 (MSAA with 32 samples) - glfwWindowHint(GLFW_SAMPLES, std::clamp(nbMSAASamples, 0, 32) ); + if (glfwInit() == GLFW_TRUE) + { + // defined samples for MSAA + // min = 0 (no MSAA Anti-aliasing) + // max = 32 (MSAA with 32 samples) + glfwWindowHint(GLFW_SAMPLES, std::clamp(nbMSAASamples, 0, 32) ); - m_glDrawTool = new DrawToolGL(); - m_bGlfwIsInitialized = true; - return true; - } - else - { - return false; - } + m_glDrawTool = new DrawToolGL(); + m_bGlfwIsInitialized = true; + return true; } - - void SofaGLFWBaseGUI::setErrorCallback() const + else { - glfwSetErrorCallback(error_callback); + return false; } +} + +void SofaGLFWBaseGUI::setErrorCallback() const +{ + glfwSetErrorCallback(error_callback); +} - void SofaGLFWBaseGUI::setSimulation(NodeSPtr groot, const std::string& filename) { - m_groot = groot; - m_filename = filename; +void SofaGLFWBaseGUI::setSimulation(NodeSPtr groot, const std::string& filename) { + m_groot = groot; + m_filename = filename; VisualParams::defaultInstance()->drawTool() = m_glDrawTool; @@ -126,41 +126,41 @@ namespace sofaglfw } } - void SofaGLFWBaseGUI::setSimulationIsRunning(bool running) +void SofaGLFWBaseGUI::setSimulationIsRunning(bool running) +{ + if (m_groot) { - if (m_groot) - { - m_groot->setAnimate(running); - } + m_groot->setAnimate(running); } +} - bool SofaGLFWBaseGUI::simulationIsRunning() const +bool SofaGLFWBaseGUI::simulationIsRunning() const +{ + if (m_groot) { - if (m_groot) - { - return m_groot->getAnimate(); - } - - return false; + return m_groot->getAnimate(); } - BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(NodeSPtr groot) + return false; +} + +BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(NodeSPtr groot) +{ + BaseCamera::SPtr camera; + groot->get(camera); + if (!camera) { - BaseCamera::SPtr camera; - groot->get(camera); - if (!camera) - { - camera = sofa::core::objectmodel::New(); - camera->setName(Base::shortName(camera.get())); - m_groot->addObject(camera); - camera->bwdInit(); - } + camera = sofa::core::objectmodel::New(); + camera->setName(Base::shortName(camera.get())); + m_groot->addObject(camera); + camera->bwdInit(); + } - camera->setBoundingBox(m_groot->f_bbox.getValue().minBBox(), m_groot->f_bbox.getValue().maxBBox()); + camera->setBoundingBox(m_groot->f_bbox.getValue().minBBox(), m_groot->f_bbox.getValue().maxBBox()); - return camera; - } + return camera; +} void SofaGLFWBaseGUI::setSizeW(int width) @@ -207,94 +207,94 @@ namespace sofaglfw } } - void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) - { - //STBImage relies on DataRepository to find files: it must be extended with the resource files from this plugin - helper::system::DataRepository.addFirstPath(SOFAGLFW_RESOURCES_DIR); +void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) +{ + //STBImage relies on DataRepository to find files: it must be extended with the resource files from this plugin + helper::system::DataRepository.addFirstPath(SOFAGLFW_RESOURCES_DIR); - helper::io::STBImage img; - if (img.load("SOFA.png")) - { - GLFWimage images[1]; - images[0].height = img.getHeight(); - images[0].width = img.getWidth(); - images[0].pixels = img.getPixels(); - glfwSetWindowIcon(glfwWindow, 1, images); - } - helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); + helper::io::STBImage img; + if (img.load("SOFA.png")) + { + GLFWimage images[1]; + images[0].height = img.getHeight(); + images[0].width = img.getWidth(); + images[0].pixels = img.getPixels(); + glfwSetWindowIcon(glfwWindow, 1, images); } + helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); +} - bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) - { - m_guiEngine->init(); + bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) +{ + m_guiEngine->init(); - if (m_groot == nullptr) - { - msg_error("SofaGLFWBaseGUI") << "No simulation root has been defined. Quitting."; - return false; - } + if (m_groot == nullptr) + { + msg_error("SofaGLFWBaseGUI") << "No simulation root has been defined. Quitting."; + return false; + } - GLFWwindow* glfwWindow = nullptr; - if (fullscreenAtStartup) - { - GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor(); - const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor); + GLFWwindow* glfwWindow = nullptr; + if (fullscreenAtStartup) + { + GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor); - m_lastWindowWidth = width; - m_lastWindowHeight = height; - m_lastWindowPositionX = 100; - m_lastWindowPositionY = 100; + m_lastWindowWidth = width; + m_lastWindowHeight = height; + m_lastWindowPositionX = 100; + m_lastWindowPositionY = 100; - setWindowHeight(height); - setWindowWidth(width); + setWindowHeight(height); + setWindowWidth(width); - glfwWindow = glfwCreateWindow(mode->width, mode->height, title, primaryMonitor, m_firstWindow); - } - else - { - glfwWindow = glfwCreateWindow(width > 0 ? width : 100, height > 0 ? height : 100, title, nullptr, m_firstWindow); - } + glfwWindow = glfwCreateWindow(mode->width, mode->height, title, primaryMonitor, m_firstWindow); + } + else + { + glfwWindow = glfwCreateWindow(width > 0 ? width : 100, height > 0 ? height : 100, title, nullptr, m_firstWindow); + } - setWindowIcon(glfwWindow); + setWindowIcon(glfwWindow); - if (!m_firstWindow) - m_firstWindow = glfwWindow; + if (!m_firstWindow) + m_firstWindow = glfwWindow; - if (glfwWindow) - { - glfwSetKeyCallback(glfwWindow, key_callback); - glfwSetCursorPosCallback(glfwWindow, cursor_position_callback); - glfwSetMouseButtonCallback(glfwWindow, mouse_button_callback); - glfwSetScrollCallback(glfwWindow, scroll_callback); - glfwSetWindowCloseCallback(glfwWindow, close_callback); - glfwSetWindowPosCallback(glfwWindow, window_pos_callback); - // this set empty callbacks - // solve a crash when glfw is quitting and tries to use nullptr callbacks - // could be potentially useful in the future anyway - glfwSetWindowFocusCallback(glfwWindow, window_focus_callback); - glfwSetCursorEnterCallback(glfwWindow, cursor_enter_callback); - glfwSetMonitorCallback(monitor_callback); - glfwSetCharCallback(glfwWindow, character_callback); + if (glfwWindow) + { + glfwSetKeyCallback(glfwWindow, key_callback); + glfwSetCursorPosCallback(glfwWindow, cursor_position_callback); + glfwSetMouseButtonCallback(glfwWindow, mouse_button_callback); + glfwSetScrollCallback(glfwWindow, scroll_callback); + glfwSetWindowCloseCallback(glfwWindow, close_callback); + glfwSetWindowPosCallback(glfwWindow, window_pos_callback); + // this set empty callbacks + // solve a crash when glfw is quitting and tries to use nullptr callbacks + // could be potentially useful in the future anyway + glfwSetWindowFocusCallback(glfwWindow, window_focus_callback); + glfwSetCursorEnterCallback(glfwWindow, cursor_enter_callback); + glfwSetMonitorCallback(monitor_callback); + glfwSetCharCallback(glfwWindow, character_callback); - glfwSetWindowUserPointer(glfwWindow, this); + glfwSetWindowUserPointer(glfwWindow, this); - makeCurrentContext(glfwWindow); + makeCurrentContext(glfwWindow); - m_guiEngine->initBackend(glfwWindow); + m_guiEngine->initBackend(glfwWindow); - auto camera = findCamera(m_groot); + auto camera = findCamera(m_groot); - SofaGLFWWindow* sofaWindow = new SofaGLFWWindow(glfwWindow, camera); + SofaGLFWWindow* sofaWindow = new SofaGLFWWindow(glfwWindow, camera); - s_mapWindows[glfwWindow] = sofaWindow; - s_mapGUIs[glfwWindow] = this; + s_mapWindows[glfwWindow] = sofaWindow; + s_mapGUIs[glfwWindow] = this; - return true; - } + return true; + } - return false; + return false; - } +} void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) { viewPortPositionX=lastViewPortPosX; @@ -309,46 +309,46 @@ namespace sofaglfw } } - void SofaGLFWBaseGUI::destroyWindow() - { - } +void SofaGLFWBaseGUI::destroyWindow() +{ +} - GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) - { - int monitorsCount, i; - int windowsX, windowsY, windowsWidth, windowsHeight; - int monitorX, monitorY, monitorWidth, monitorHeight; - int overlap, bestOverlap; - GLFWmonitor *bestMonitor; - GLFWmonitor **monitors; - const GLFWvidmode *mode; +GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) +{ + int monitorsCount, i; + int windowsX, windowsY, windowsWidth, windowsHeight; + int monitorX, monitorY, monitorWidth, monitorHeight; + int overlap, bestOverlap; + GLFWmonitor *bestMonitor; + GLFWmonitor **monitors; + const GLFWvidmode *mode; - bestOverlap = 0; - bestMonitor = nullptr; + bestOverlap = 0; + bestMonitor = nullptr; - glfwGetWindowPos(glfwWindow, &windowsX, &windowsY); - glfwGetWindowSize(glfwWindow, &windowsWidth, &windowsHeight); - monitors = glfwGetMonitors(&monitorsCount); - for (i=0; iwidth; - monitorHeight = mode->height; + glfwGetWindowPos(glfwWindow, &windowsX, &windowsY); + glfwGetWindowSize(glfwWindow, &windowsWidth, &windowsHeight); + monitors = glfwGetMonitors(&monitorsCount); + for (i=0; iwidth; + monitorHeight = mode->height; - overlap = std::max(0, std::min(windowsX + windowsWidth, monitorX + monitorWidth) - std::max(windowsX, monitorX)) * - std::max(0, std::min(windowsY + windowsHeight, monitorY + monitorHeight) - std::max(windowsY, monitorY)); + overlap = std::max(0, std::min(windowsX + windowsWidth, monitorX + monitorWidth) - std::max(windowsX, monitorX)) * + std::max(0, std::min(windowsY + windowsHeight, monitorY + monitorHeight) - std::max(windowsY, monitorY)); - if (bestOverlap < overlap) - { - bestOverlap = overlap; - bestMonitor = monitors[i]; - } + if (bestOverlap < overlap) + { + bestOverlap = overlap; + bestMonitor = monitors[i]; } - - return bestMonitor; } + return bestMonitor; +} + bool SofaGLFWBaseGUI::isFullScreen(GLFWwindow* glfwWindow) const { @@ -840,56 +840,56 @@ namespace sofaglfw } } - void SofaGLFWBaseGUI::window_focus_callback(GLFWwindow* window, int focused) - { - SOFA_UNUSED(window); - SOFA_UNUSED(focused); - //if (focused) - //{ - // // The window gained input focus - //} - //else - //{ - // // The window lost input focus - //} - } - void SofaGLFWBaseGUI::cursor_enter_callback(GLFWwindow* window, int entered) - { - SOFA_UNUSED(window); - SOFA_UNUSED(entered); - - //if (entered) - //{ - // // The cursor entered the content area of the window - //} - //else - //{ - // // The cursor left the content area of the window - //} - } - void SofaGLFWBaseGUI::monitor_callback(GLFWmonitor* monitor, int event) - { - SOFA_UNUSED(monitor); - SOFA_UNUSED(event); - - //if (event == GLFW_CONNECTED) - //{ - // // The monitor was connected - //} - //else if (event == GLFW_DISCONNECTED) - //{ - // // The monitor was disconnected - //} - } +void SofaGLFWBaseGUI::window_focus_callback(GLFWwindow* window, int focused) +{ + SOFA_UNUSED(window); + SOFA_UNUSED(focused); + //if (focused) + //{ + // // The window gained input focus + //} + //else + //{ + // // The window lost input focus + //} +} +void SofaGLFWBaseGUI::cursor_enter_callback(GLFWwindow* window, int entered) +{ + SOFA_UNUSED(window); + SOFA_UNUSED(entered); + + //if (entered) + //{ + // // The cursor entered the content area of the window + //} + //else + //{ + // // The cursor left the content area of the window + //} +} +void SofaGLFWBaseGUI::monitor_callback(GLFWmonitor* monitor, int event) +{ + SOFA_UNUSED(monitor); + SOFA_UNUSED(event); + + //if (event == GLFW_CONNECTED) + //{ + // // The monitor was connected + //} + //else if (event == GLFW_DISCONNECTED) + //{ + // // The monitor was disconnected + //} +} - void SofaGLFWBaseGUI::character_callback(GLFWwindow* window, unsigned int codepoint) - { - SOFA_UNUSED(window); - SOFA_UNUSED(codepoint); +void SofaGLFWBaseGUI::character_callback(GLFWwindow* window, unsigned int codepoint) +{ + SOFA_UNUSED(window); + SOFA_UNUSED(codepoint); - // The callback function receives Unicode code points for key events - // that would have led to regular text input and generally behaves as a standard text field on that platform. - } + // The callback function receives Unicode code points for key events + // that would have led to regular text input and generally behaves as a standard text field on that platform. +} bool SofaGLFWBaseGUI::centerWindow(GLFWwindow* window) { From 4291c8e681538ac94b184dddc5ef7d4fe886c7eb Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 2 Aug 2024 16:05:54 +0200 Subject: [PATCH 23/41] fix indentation --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 475 +++++++++--------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 17 +- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 24 +- SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 10 +- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 18 +- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h | 56 +-- 6 files changed, 285 insertions(+), 315 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index c9ede97f36..956307b012 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -33,6 +33,7 @@ #include #include #include +#include "SofaGLFW/SofaGLFWMouseManager.h" #include #include @@ -48,7 +49,6 @@ #include #include #include -#include "SofaGLFW/SofaGLFWMouseManager.h" using namespace sofa; using namespace sofa::gui::common; @@ -65,14 +65,12 @@ using namespace core::objectmodel; namespace sofaglfw { - SofaGLFWBaseGUI::SofaGLFWBaseGUI() - :lastProjectionMatrix{0.0}, - lastModelviewMatrix{0.0}, - m_sofaGLFWMouseManager(nullptr) - { - m_guiEngine = std::make_shared(); - m_sofaGLFWMouseManager = new SofaGLFWMouseManager(); - } +SofaGLFWBaseGUI::SofaGLFWBaseGUI() + :lastProjectionMatrix{0.0}, + lastModelviewMatrix{0.0} +{ + m_guiEngine = std::make_shared(); +} SofaGLFWBaseGUI::~SofaGLFWBaseGUI() { @@ -113,18 +111,19 @@ void SofaGLFWBaseGUI::setErrorCallback() const glfwSetErrorCallback(error_callback); } -void SofaGLFWBaseGUI::setSimulation(NodeSPtr groot, const std::string& filename) { +void SofaGLFWBaseGUI::setSimulation(NodeSPtr groot, const std::string& filename) +{ m_groot = groot; m_filename = filename; - VisualParams::defaultInstance()->drawTool() = m_glDrawTool; + VisualParams::defaultInstance()->drawTool() = m_glDrawTool; - if (m_groot) { - // Initialize the pick handler - this->pick->init(m_groot.get()); - m_sofaGLFWMouseManager->setPickHandler(getPickHandler()); - } + if (m_groot) { + // Initialize the pick handler + this->pick->init(m_groot.get()); + m_sofaGLFWMouseManager.setPickHandler(getPickHandler()); } +} void SofaGLFWBaseGUI::setSimulationIsRunning(bool running) { @@ -199,13 +198,13 @@ BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(NodeSPtr groot) { } - void SofaGLFWBaseGUI::changeCamera(BaseCamera::SPtr newCamera) +void SofaGLFWBaseGUI::changeCamera(BaseCamera::SPtr newCamera) +{ + for (auto& w : s_mapWindows) { - for (auto& w : s_mapWindows) - { - w.second->setCamera(newCamera); - } + w.second->setCamera(newCamera); } +} void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) { @@ -224,7 +223,7 @@ void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) helper::system::DataRepository.removePath(SOFAGLFW_RESOURCES_DIR); } - bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) +bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, bool fullscreenAtStartup) { m_guiEngine->init(); @@ -297,17 +296,17 @@ void SofaGLFWBaseGUI::setWindowIcon(GLFWwindow* glfwWindow) } void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) { - viewPortPositionX=lastViewPortPosX; - viewPortPositionY=lastViewPortPosY; + viewPortPosition[0]=lastViewPortPosX; + viewPortPosition[1]=lastViewPortPosY; } - void SofaGLFWBaseGUI::resizeWindow(int width, int height) +void SofaGLFWBaseGUI::resizeWindow(int width, int height) +{ + if (hasWindow()) { - if (hasWindow()) - { - glfwSetWindowSize(m_firstWindow, width, height); - } + glfwSetWindowSize(m_firstWindow, width, height); } +} void SofaGLFWBaseGUI::destroyWindow() { @@ -350,48 +349,48 @@ GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) } - bool SofaGLFWBaseGUI::isFullScreen(GLFWwindow* glfwWindow) const +bool SofaGLFWBaseGUI::isFullScreen(GLFWwindow* glfwWindow) const +{ + if (hasWindow()) { - if (hasWindow()) - { - glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; - return glfwGetWindowMonitor(glfwWindow) != nullptr; - } - return false; + glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; + return glfwGetWindowMonitor(glfwWindow) != nullptr; } + return false; +} - void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* screenID */) +void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* screenID */) +{ + if (hasWindow()) { - if (hasWindow()) - { - // only manage the first window for now - // and the main screen - glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; + // only manage the first window for now + // and the main screen + glfwWindow = (!glfwWindow) ? m_firstWindow : glfwWindow; - bool isFullScreen = glfwGetWindowMonitor(glfwWindow) != nullptr; + bool isFullScreen = glfwGetWindowMonitor(glfwWindow) != nullptr; - if (!isFullScreen) - { - // backup window position and window size - glfwGetWindowPos(glfwWindow, &m_lastWindowPositionX, &m_lastWindowPositionY); - glfwGetWindowSize(glfwWindow, &m_lastWindowWidth, &m_lastWindowHeight); + if (!isFullScreen) + { + // backup window position and window size + glfwGetWindowPos(glfwWindow, &m_lastWindowPositionX, &m_lastWindowPositionY); + glfwGetWindowSize(glfwWindow, &m_lastWindowWidth, &m_lastWindowHeight); - GLFWmonitor* monitor = getCurrentMonitor(glfwWindow); - const GLFWvidmode* mode = glfwGetVideoMode(monitor); + GLFWmonitor* monitor = getCurrentMonitor(glfwWindow); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); - glfwSetWindowMonitor(glfwWindow, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); - } - else - { - glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_TRUE); - glfwSetWindowMonitor(glfwWindow, nullptr, m_lastWindowPositionX, m_lastWindowPositionY, m_lastWindowWidth, m_lastWindowHeight, GLFW_DONT_CARE); - } + glfwSetWindowMonitor(glfwWindow, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); } else { - msg_error("SofaGLFWBaseGUI") << "No window to set fullscreen"; // can happen with runSofa/BaseGUI + glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_TRUE); + glfwSetWindowMonitor(glfwWindow, nullptr, m_lastWindowPositionX, m_lastWindowPositionY, m_lastWindowWidth, m_lastWindowHeight, GLFW_DONT_CARE); } } + else + { + msg_error("SofaGLFWBaseGUI") << "No window to set fullscreen"; // can happen with runSofa/BaseGUI + } +} void SofaGLFWBaseGUI::setBackgroundColor(const RGBAColor& newColor, unsigned int /* windowID */) { @@ -487,60 +486,60 @@ GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) return currentNbIterations; } - void SofaGLFWBaseGUI::initVisual() - { - node::initTextures(m_groot.get()); +void SofaGLFWBaseGUI::initVisual() +{ + node::initTextures(m_groot.get()); - VisualStyle::SPtr visualStyle = nullptr; - m_groot->get(visualStyle); - if (!visualStyle) - { - visualStyle = sofa::core::objectmodel::New(); - visualStyle->setName(helper::NameDecoder::getShortName()); + VisualStyle::SPtr visualStyle = nullptr; + m_groot->get(visualStyle); + if (!visualStyle) + { + visualStyle = sofa::core::objectmodel::New(); + visualStyle->setName(helper::NameDecoder::getShortName()); - DisplayFlags* displayFlags = visualStyle->d_displayFlags.beginEdit(); - displayFlags->setShowVisualModels(tristate::true_value); - visualStyle->displayFlags.endEdit(); + DisplayFlags* displayFlags = visualStyle->d_displayFlags.beginEdit(); + displayFlags->setShowVisualModels(tristate::true_value); + visualStyle->displayFlags.endEdit(); - m_groot->addObject(visualStyle); - visualStyle->init(); - } + m_groot->addObject(visualStyle); + visualStyle->init(); + } - //init gl states - glDepthFunc(GL_LEQUAL); - glClearDepth(1.0); - glEnable(GL_NORMALIZE); + //init gl states + glDepthFunc(GL_LEQUAL); + glClearDepth(1.0); + glEnable(GL_NORMALIZE); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - // Setup 'light 0' - float lightAmbient[4] = { 0.5f, 0.5f, 0.5f,1.0f }; - float lightDiffuse[4] = { 0.9f, 0.9f, 0.9f,1.0f }; - float lightSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; - float lightPosition[4] = { -0.7f, 0.3f, 0.0f,1.0f }; - glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular); - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); + // Setup 'light 0' + float lightAmbient[4] = { 0.5f, 0.5f, 0.5f,1.0f }; + float lightDiffuse[4] = { 0.9f, 0.9f, 0.9f,1.0f }; + float lightSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; + float lightPosition[4] = { -0.7f, 0.3f, 0.0f,1.0f }; + glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular); + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - // Enable color tracking - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + // Enable color tracking + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - // All materials hereafter have full specular reflectivity with a high shine - float materialSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; - glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); - glMateriali(GL_FRONT, GL_SHININESS, 128); + // All materials hereafter have full specular reflectivity with a high shine + float materialSpecular[4] = { 1.0f, 1.0f, 1.0f,1.0f }; + glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); + glMateriali(GL_FRONT, GL_SHININESS, 128); - glShadeModel(GL_SMOOTH); + glShadeModel(GL_SMOOTH); - glEnable(GL_LIGHT0); + glEnable(GL_LIGHT0); - m_vparams = VisualParams::defaultInstance(); - for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) - { - sofaGlfwWindow->centerCamera(m_groot, m_vparams); - } + m_vparams = VisualParams::defaultInstance(); + for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) + { + sofaGlfwWindow->centerCamera(m_groot, m_vparams); } +} void SofaGLFWBaseGUI::runStep() { @@ -585,80 +584,80 @@ GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) return key; } - void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) +void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + const char keyName = handleArrowKeys(key); + const bool isCtrlKeyPressed = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; + + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI == s_mapGUIs.end() || currentGUI->second == nullptr) + { + return; + } + + auto rootNode = currentGUI->second->getRootNode(); + if (!rootNode) { - const char keyName = handleArrowKeys(key); - const bool isCtrlKeyPressed = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; + return; + } - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI == s_mapGUIs.end() || currentGUI->second == nullptr) + if (isCtrlKeyPressed) + { + if (action == GLFW_PRESS) { - return; - } + dmsg_info_when(key == GLFW_KEY_LEFT_CONTROL, "SofaGLFWBaseGUI") << "KeyPressEvent, CONTROL pressed"; - auto rootNode = currentGUI->second->getRootNode(); - if (!rootNode) + KeypressedEvent keyPressedEvent(keyName); + rootNode->propagateEvent(core::ExecParams::defaultInstance(), &keyPressedEvent); + } + else if (action == GLFW_RELEASE) { - return; + KeyreleasedEvent keyReleasedEvent(keyName); + rootNode->propagateEvent(core::ExecParams::defaultInstance(), &keyReleasedEvent); } + } - if (isCtrlKeyPressed) - { + // Handle specific keys for additional functionality + switch (key) + { + case GLFW_KEY_F: + if (action == GLFW_PRESS && (mods & GLFW_MOD_CONTROL)) + { + currentGUI->second->switchFullScreen(window); + } + break; + case GLFW_KEY_ESCAPE: if (action == GLFW_PRESS) { - dmsg_info_when(key == GLFW_KEY_LEFT_CONTROL, "SofaGLFWBaseGUI") << "KeyPressEvent, CONTROL pressed"; - - KeypressedEvent keyPressedEvent(keyName); - rootNode->propagateEvent(core::ExecParams::defaultInstance(), &keyPressedEvent); + glfwSetWindowShouldClose(window, GLFW_TRUE); } - else if (action == GLFW_RELEASE) + break; + case GLFW_KEY_SPACE: + if (action == GLFW_PRESS) { - KeyreleasedEvent keyReleasedEvent(keyName); - rootNode->propagateEvent(core::ExecParams::defaultInstance(), &keyReleasedEvent); + const bool isRunning = currentGUI->second->simulationIsRunning(); + currentGUI->second->setSimulationIsRunning(!isRunning); } - } - - // Handle specific keys for additional functionality - switch (key) - { - case GLFW_KEY_F: - if (action == GLFW_PRESS && (mods & GLFW_MOD_CONTROL)) - { - currentGUI->second->switchFullScreen(window); - } - break; - case GLFW_KEY_ESCAPE: + break; + case GLFW_KEY_LEFT_SHIFT: + if (currentGUI->second->getPickHandler()) // Check if getPickHandler() is not null + { if (action == GLFW_PRESS) { - glfwSetWindowShouldClose(window, GLFW_TRUE); + int viewport[4] = {}; // Properly initialize the viewport array + currentGUI->second->getPickHandler()->activateRay(viewport[2], viewport[3], rootNode.get()); } - break; - case GLFW_KEY_SPACE: - if (action == GLFW_PRESS) + else if (action == GLFW_RELEASE) { - const bool isRunning = currentGUI->second->simulationIsRunning(); - currentGUI->second->setSimulationIsRunning(!isRunning); + currentGUI->second->getPickHandler()->deactivateRay(); } - break; - case GLFW_KEY_LEFT_SHIFT: - if (currentGUI->second->getPickHandler()) // Check if getPickHandler() is not null - { - if (action == GLFW_PRESS) - { - int viewport[4] = {}; // Properly initialize the viewport array - currentGUI->second->getPickHandler()->activateRay(viewport[2], viewport[3], rootNode.get()); - } - else if (action == GLFW_RELEASE) - { - currentGUI->second->getPickHandler()->deactivateRay(); - } - } - break; + } + break; - default: - break; - } + default: + break; } +} void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) { @@ -720,125 +719,125 @@ GLFWmonitor* SofaGLFWBaseGUI::getCurrentMonitor(GLFWwindow *glfwWindow) void SofaGLFWBaseGUI::window_pos_callback(GLFWwindow* window, int xpos, int ypos) { SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); - gui->winPositionX=xpos; - gui->winPositionY=ypos; + gui->windowPosition[0]=xpos; + gui->windowPosition[1]=ypos; } - void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) - { - double xpos, ypos; +void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) +{ + double xpos, ypos; - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI == s_mapGUIs.end() || !currentGUI->second) { - return; - } + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI == s_mapGUIs.end() || !currentGUI->second) { + return; + } + + SofaGLFWBaseGUI* gui = currentGUI->second; - SofaGLFWBaseGUI* gui = currentGUI->second; + auto rootNode = currentGUI->second->getRootNode(); + if (!rootNode) { + return; + } - auto rootNode = currentGUI->second->getRootNode(); - if (!rootNode) { + bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + + if (shiftPressed ) + { + // Check if the animation is running + if (!currentGUI->second->simulationIsRunning()) { + msg_error("SofaGLFWBaseGUI") << "Animation is not running. Ignoring mouse interaction."; return; } - bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + glfwGetCursorPos(window, &xpos, &ypos); + translateToViewportCoordinates(gui,xpos,ypos); - if (shiftPressed ) + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { - // Check if the animation is running - if (!currentGUI->second->simulationIsRunning()) { - msg_error("SofaGLFWBaseGUI") << "Animation is not running. Ignoring mouse interaction."; - return; - } - - glfwGetCursorPos(window, &xpos, &ypos); - translateToViewportCoordinates(gui,xpos,ypos); - - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) - { - currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, button, action, mods, gui->translatedXPos, gui->translatedYpos); - } + currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, button, action, mods, gui->translatedCursorPos[0], gui->translatedCursorPos[1]); } - else + } + else + { + if (currentGUI != s_mapGUIs.end() && currentGUI->second) { - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) - return; - } + if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) + return; + } - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) - { - currentSofaWindow->second->mouseButtonEvent(button, action, mods); - } + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + { + currentSofaWindow->second->mouseButtonEvent(button, action, mods); } } +} void SofaGLFWBaseGUI::translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos) { - gui->translatedYpos =ypos-(gui->viewPortPositionY-gui->winPositionY); - gui->translatedXPos =xpos-(gui->viewPortPositionX-gui->winPositionX); + gui->translatedCursorPos[0] =xpos-(gui->viewPortPosition[0]-gui->windowPosition[0]); + gui->translatedCursorPos[1] =ypos-(gui->viewPortPosition[1]-gui->windowPosition[1]); } - void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) - { - auto currentGUI = s_mapGUIs.find(window); +void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) +{ + auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) - return; - } - SofaGLFWBaseGUI* gui = currentGUI->second; + if (currentGUI != s_mapGUIs.end() && currentGUI->second) + { + if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) + return; + } + SofaGLFWBaseGUI* gui = currentGUI->second; - translateToViewportCoordinates(gui,xpos,ypos); + translateToViewportCoordinates(gui,xpos,ypos); - bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; - int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); + bool shiftPressed = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); - auto currentSofaWindow = s_mapWindows.find(window); + auto currentSofaWindow = s_mapWindows.find(window); - if (shiftPressed && state == GLFW_PRESS) - { - currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, 0, 1, 1, gui->translatedXPos, gui->translatedYpos); - } + if (shiftPressed && state == GLFW_PRESS) + { + currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, 0, 1, 1, gui->translatedCursorPos[0], gui->translatedCursorPos[1]); + } - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) - { - currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); - } + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + { + currentSofaWindow->second->mouseMoveEvent(static_cast(xpos), static_cast(ypos), currentGUI->second); } +} - void SofaGLFWBaseGUI::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) +void SofaGLFWBaseGUI::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) +{ + auto currentGUI = s_mapGUIs.find(window); + if (currentGUI != s_mapGUIs.end() && currentGUI->second) { - auto currentGUI = s_mapGUIs.find(window); - if (currentGUI != s_mapGUIs.end() && currentGUI->second) - { - if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) - return; - } + if (!currentGUI->second->getGUIEngine()->dispatchMouseEvents()) + return; + } - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) - { - currentSofaWindow->second->scrollEvent(xoffset, yoffset); - } + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) + { + currentSofaWindow->second->scrollEvent(xoffset, yoffset); } +} - void SofaGLFWBaseGUI::close_callback(GLFWwindow* window) +void SofaGLFWBaseGUI::close_callback(GLFWwindow* window) +{ + auto currentSofaWindow = s_mapWindows.find(window); + if (currentSofaWindow != s_mapWindows.end()) { - auto currentSofaWindow = s_mapWindows.find(window); - if (currentSofaWindow != s_mapWindows.end()) + if (SofaGLFWWindow* glfwWindow = currentSofaWindow->second) { - if (SofaGLFWWindow* glfwWindow = currentSofaWindow->second) - { - glfwWindow->close(); - delete glfwWindow; - } - s_mapWindows.erase(window); + glfwWindow->close(); + delete glfwWindow; } + s_mapWindows.erase(window); } +} void SofaGLFWBaseGUI::window_focus_callback(GLFWwindow* window, int focused) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 21cc582b46..f660ae9555 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -32,15 +32,16 @@ #include #include +#include "SofaGLFW/SofaGLFWMouseManager.h" + struct GLFWwindow; struct GLFWmonitor; +using namespace sofa::type; namespace sofaglfw { - class SofaGLFWMouseManager; class SofaGLFWWindow; - class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { public: @@ -135,15 +136,13 @@ class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { double lastProjectionMatrix[16]; double lastModelviewMatrix[16]; bool m_isMouseInteractionEnabled{ false }; - float viewPortPositionX {0}; - float viewPortPositionY {0}; - float winPositionX {0}; - float winPositionY {0}; - SofaGLFWMouseManager* m_sofaGLFWMouseManager; + SofaGLFWMouseManager m_sofaGLFWMouseManager; int viewPortHeight{0}; int viewPortWidth {0}; - double translatedXPos {0}; - double translatedYpos {0}; + Vec2d translatedCursorPos; + Vec2f viewPortPosition; + Vec2f windowPosition; + std::shared_ptr m_guiEngine; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index da1821d7ff..640415e1dc 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -20,7 +20,6 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include "SofaGLFW/SofaGLFWMouseManager.h" #define GLFW_INCLUDE_NONE @@ -31,6 +30,7 @@ #include #include #include +#include "SofaGLFW/SofaGLFWMouseManager.h" using namespace sofa; using namespace sofa::gui::common; @@ -61,42 +61,22 @@ namespace sofaglfw { RegisterOperation("Suture").add< AddSutureOperation >(); RegisterOperation("ConstraintAttach").add< ConstraintAttachOperation >(); } - SofaGLFWMouseManager::~SofaGLFWMouseManager() - { - } void SofaGLFWMouseManager::setPickHandler(PickHandler *picker) { pickHandler=picker; - updateContent(); updateOperation(LEFT, "Attach"); updateOperation(MIDDLE, "Incise"); updateOperation(RIGHT, "Remove"); } - void SofaGLFWMouseManager::updateContent() - { - } - - void SofaGLFWMouseManager::render() - { - } - - void SofaGLFWMouseManager::selectOperation(int button) - { - } - void SofaGLFWMouseManager::updateOperation(MOUSE_BUTTON button, const std::string &id) { if (pickHandler) { - Operation *operation = pickHandler->changeOperation(button, id); - updateOperation(operation); + pickHandler->changeOperation(button, id); } } - void SofaGLFWMouseManager::updateOperation(Operation *operation) - { - } }// namespace sofaglfw \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h index 935dae04ab..0dedfbdd4d 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -21,10 +21,8 @@ ******************************************************************************/ #pragma once #include -#include #include #include -#include "SofaGLFWBaseGUI.h" using namespace sofa::gui::common; @@ -34,20 +32,14 @@ namespace sofaglfw class SOFAGLFW_API SofaGLFWMouseManager { public: SofaGLFWMouseManager(); - ~SofaGLFWMouseManager(); void setPickHandler(PickHandler* picker); - void updateContent(); - void render(); private: - void selectOperation(int operation); void updateOperation(MOUSE_BUTTON button, const std::string& id); - void updateOperation(Operation* operation); PickHandler* pickHandler; - std::map> operations; - std::map buttonOperations; + }; } // namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 199bd9ef43..7de0b02eea 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -55,16 +55,16 @@ namespace sofaglfw glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glEnable(GL_LIGHTING); - glEnable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + glDisable(GL_COLOR_MATERIAL); - // draw the scene - if (!m_currentCamera) - { - msg_error("SofaGLFWGUI") << "No camera defined."; - return; - } + // draw the scene + if (!m_currentCamera) + { + msg_error("SofaGLFWGUI") << "No camera defined."; + return; + } if (groot->f_bbox.getValue().isValid()) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h index 14b001dd69..27e987a19b 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h @@ -31,33 +31,33 @@ struct GLFWwindow; namespace sofaglfw { - class SOFAGLFW_API SofaGLFWWindow - { - public: - SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera); - virtual ~SofaGLFWWindow() = default; - - void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams,double lastModelviewMatrix [16],double lastProjectionMatrix[16]); - void close(); - - void mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui); - void mouseButtonEvent(int button, int action, int mods); - void scrollEvent(double xoffset, double yoffset); - void setBackgroundColor(const sofa::type::RGBAColor& newColor); - - void setCamera(sofa::component::visual::BaseCamera::SPtr newCamera); - void centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const; - bool mouseEvent(GLFWwindow* window,int width,int height ,int button, int action, int mods, double xpos, double ypos); // Declaration for mouseEvent function - - private: - GLFWwindow* m_glfwWindow{nullptr}; - sofa::component::visual::BaseCamera::SPtr m_currentCamera; - int m_currentButton{ -1 }; - int m_currentAction{ -1 }; - int m_currentMods{ -1 }; - int m_currentXPos{ -1 }; - int m_currentYPos{ -1 }; - sofa::type::RGBAColor m_backgroundColor{ sofa::type::RGBAColor::black() }; - }; +class SOFAGLFW_API SofaGLFWWindow +{ +public: + SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera); + virtual ~SofaGLFWWindow() = default; + + void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams,double lastModelviewMatrix [16],double lastProjectionMatrix[16]); + void close(); + + void mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui); + void mouseButtonEvent(int button, int action, int mods); + void scrollEvent(double xoffset, double yoffset); + void setBackgroundColor(const sofa::type::RGBAColor& newColor); + + void setCamera(sofa::component::visual::BaseCamera::SPtr newCamera); + void centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const; + bool mouseEvent(GLFWwindow* window,int width,int height ,int button, int action, int mods, double xpos, double ypos); // Declaration for mouseEvent function + +private: + GLFWwindow* m_glfwWindow{nullptr}; + sofa::component::visual::BaseCamera::SPtr m_currentCamera; + int m_currentButton{ -1 }; + int m_currentAction{ -1 }; + int m_currentMods{ -1 }; + int m_currentXPos{ -1 }; + int m_currentYPos{ -1 }; + sofa::type::RGBAColor m_backgroundColor{ sofa::type::RGBAColor::black() }; +}; } // namespace sofaglfw From 9a4b134933b0f8d4e405558c4929d83f19405dee Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 2 Aug 2024 16:23:11 +0200 Subject: [PATCH 24/41] fix indentation --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 194 +++++++++++----------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 956307b012..5a1fe5fb99 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -392,100 +392,100 @@ void SofaGLFWBaseGUI::switchFullScreen(GLFWwindow* glfwWindow, unsigned int /* s } } - void SofaGLFWBaseGUI::setBackgroundColor(const RGBAColor& newColor, unsigned int /* windowID */) +void SofaGLFWBaseGUI::setBackgroundColor(const RGBAColor& newColor, unsigned int /* windowID */) +{ + // only manage the first window for now + if (hasWindow()) { - // only manage the first window for now - if (hasWindow()) - { - s_mapWindows[m_firstWindow]->setBackgroundColor(newColor); - } - else - { - msg_error("SofaGLFWBaseGUI") << "No window to set the background in";// can happen with runSofa/BaseGUI - } + s_mapWindows[m_firstWindow]->setBackgroundColor(newColor); + } + else + { + msg_error("SofaGLFWBaseGUI") << "No window to set the background in";// can happen with runSofa/BaseGUI } +} - void SofaGLFWBaseGUI::setBackgroundImage(const std::string& /* filename */, unsigned int /* windowID */) - { +void SofaGLFWBaseGUI::setBackgroundImage(const std::string& /* filename */, unsigned int /* windowID */) +{ - } +} - void SofaGLFWBaseGUI::makeCurrentContext(GLFWwindow* glfwWindow) +void SofaGLFWBaseGUI::makeCurrentContext(GLFWwindow* glfwWindow) +{ + glfwMakeContextCurrent(glfwWindow); + glfwSwapInterval( 0 ); //request disabling vsync + if (!m_bGlewIsInitialized) { - glfwMakeContextCurrent(glfwWindow); - glfwSwapInterval( 0 ); //request disabling vsync - if (!m_bGlewIsInitialized) - { - glewInit(); - m_bGlewIsInitialized = true; - } + glewInit(); + m_bGlewIsInitialized = true; } +} - std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) +std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) +{ + if (!m_groot) { - if (!m_groot) - { - msg_error("SofaGLFWBaseGUI") << "Cannot start main loop: root node is invalid"; - return 0; - } + msg_error("SofaGLFWBaseGUI") << "Cannot start main loop: root node is invalid"; + return 0; + } - m_vparams = VisualParams::defaultInstance(); - viewPortWidth=m_vparams->viewport()[2]; - viewPortHeight=m_vparams->viewport()[3]; + m_vparams = VisualParams::defaultInstance(); + viewPortWidth=m_vparams->viewport()[2]; + viewPortHeight=m_vparams->viewport()[3]; - bool running = true; - std::size_t currentNbIterations = 0; - std::stringstream tmpStr; - while (!s_mapWindows.empty() && running) - { - SIMULATION_LOOP_SCOPE + bool running = true; + std::size_t currentNbIterations = 0; + std::stringstream tmpStr; + while (!s_mapWindows.empty() && running) + { + SIMULATION_LOOP_SCOPE - // Keep running - runStep(); + // Keep running + runStep(); - for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) + for (auto& [glfwWindow, sofaGlfwWindow] : s_mapWindows) + { + if (sofaGlfwWindow) { - if (sofaGlfwWindow) + // while user did not request to close this window (i.e press escape), draw + if (!glfwWindowShouldClose(glfwWindow)) { - // while user did not request to close this window (i.e press escape), draw - if (!glfwWindowShouldClose(glfwWindow)) - { - makeCurrentContext(glfwWindow); + makeCurrentContext(glfwWindow); - m_guiEngine->beforeDraw(glfwWindow); - sofaGlfwWindow->draw(m_groot, m_vparams,lastModelviewMatrix,lastProjectionMatrix); - m_guiEngine->afterDraw(); + m_guiEngine->beforeDraw(glfwWindow); + sofaGlfwWindow->draw(m_groot, m_vparams,lastModelviewMatrix,lastProjectionMatrix); + m_guiEngine->afterDraw(); - m_guiEngine->startFrame(this); - m_guiEngine->endFrame(); + m_guiEngine->startFrame(this); + m_guiEngine->endFrame(); - glfwSwapBuffers(glfwWindow); + glfwSwapBuffers(glfwWindow); - if (viewPortHeight!=m_vparams->viewport()[3] || - viewPortWidth!=m_vparams->viewport()[2]) - { - viewPortHeight=m_vparams->viewport()[3]; - viewPortWidth=m_vparams->viewport()[2]; - } - } - else + if (viewPortHeight!=m_vparams->viewport()[3] || + viewPortWidth!=m_vparams->viewport()[2]) { - // otherwise close this window - close_callback(glfwWindow); + viewPortHeight=m_vparams->viewport()[3]; + viewPortWidth=m_vparams->viewport()[2]; } } + else + { + // otherwise close this window + close_callback(glfwWindow); + } } - - glfwPollEvents(); - - currentNbIterations++; - running = (targetNbIterations > 0) ? currentNbIterations < targetNbIterations : true; } - return currentNbIterations; + glfwPollEvents(); + + currentNbIterations++; + running = (targetNbIterations > 0) ? currentNbIterations < targetNbIterations : true; } + return currentNbIterations; +} + void SofaGLFWBaseGUI::initVisual() { node::initTextures(m_groot.get()); @@ -541,48 +541,48 @@ void SofaGLFWBaseGUI::initVisual() } } - void SofaGLFWBaseGUI::runStep() +void SofaGLFWBaseGUI::runStep() +{ + if(simulationIsRunning()) { - if(simulationIsRunning()) - { - helper::AdvancedTimer::begin("Animate"); + helper::AdvancedTimer::begin("Animate"); - node::animate(m_groot.get(), m_groot->getDt()); - node::updateVisual(m_groot.get()); + node::animate(m_groot.get(), m_groot->getDt()); + node::updateVisual(m_groot.get()); - helper::AdvancedTimer::end("Animate"); - } + helper::AdvancedTimer::end("Animate"); } +} - void SofaGLFWBaseGUI::terminate() - { - if (!m_bGlfwIsInitialized) - return; +void SofaGLFWBaseGUI::terminate() +{ + if (!m_bGlfwIsInitialized) + return; - m_guiEngine->terminate(); + m_guiEngine->terminate(); - glfwTerminate(); - } + glfwTerminate(); +} - void SofaGLFWBaseGUI::error_callback(int error, const char* description) - { - SOFA_UNUSED(error); - msg_error("SofaGLFWBaseGUI") << "Error: " << description << "."; - } +void SofaGLFWBaseGUI::error_callback(int error, const char* description) +{ + SOFA_UNUSED(error); + msg_error("SofaGLFWBaseGUI") << "Error: " << description << "."; +} - int SofaGLFWBaseGUI::handleArrowKeys(int key) +int SofaGLFWBaseGUI::handleArrowKeys(int key) +{ + // Handling arrow keys with custom codes + switch (key) { - // Handling arrow keys with custom codes - switch (key) - { - case GLFW_KEY_UP: return 19; // Custom code for up - case GLFW_KEY_DOWN: return 21; // Custom code for down - case GLFW_KEY_LEFT: return 18; // Custom code for left - case GLFW_KEY_RIGHT: return 20; // Custom code for right - } - // Default case return the given value as GLFW handle it - return key; + case GLFW_KEY_UP: return 19; // Custom code for up + case GLFW_KEY_DOWN: return 21; // Custom code for down + case GLFW_KEY_LEFT: return 18; // Custom code for left + case GLFW_KEY_RIGHT: return 20; // Custom code for right } + // Default case return the given value as GLFW handle it + return key; +} void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { From 978e23e06430f5221afda12497adbbdd7b52c8ef Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 2 Aug 2024 16:28:30 +0200 Subject: [PATCH 25/41] fix indentation --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 10 +- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 176 +++++++++++------------ 2 files changed, 96 insertions(+), 90 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index f660ae9555..72fdb6983a 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -93,8 +93,14 @@ class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { void changeCamera(sofa::component::visual::BaseCamera::SPtr newCamera); void setWindowIcon(GLFWwindow* glfwWindow); - void setGUIEngine(std::shared_ptr guiEngine) { m_guiEngine = guiEngine; } - std::shared_ptr getGUIEngine() { return m_guiEngine; } + void setGUIEngine(std::shared_ptr guiEngine) + { + m_guiEngine = guiEngine; + } + std::shared_ptr getGUIEngine() + { + return m_guiEngine; + } void moveRayPickInteractor(int eventX, int eventY) override ; private: diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 7de0b02eea..14e9f6bb12 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -50,7 +50,7 @@ namespace sofaglfw } - void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]){ +void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]){ glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -101,107 +101,107 @@ namespace sofaglfw simulation::node::draw(vparams, groot.get()); } - void SofaGLFWWindow::setBackgroundColor(const type::RGBAColor& newColor) - { - m_backgroundColor = newColor; - } +void SofaGLFWWindow::setBackgroundColor(const type::RGBAColor& newColor) +{ + m_backgroundColor = newColor; +} - void SofaGLFWWindow::setCamera(component::visual::BaseCamera::SPtr newCamera) - { - m_currentCamera = newCamera; - } +void SofaGLFWWindow::setCamera(component::visual::BaseCamera::SPtr newCamera) +{ + m_currentCamera = newCamera; +} - void SofaGLFWWindow::centerCamera(simulation::NodeSPtr node, core::visual::VisualParams* vparams) const +void SofaGLFWWindow::centerCamera(simulation::NodeSPtr node, core::visual::VisualParams* vparams) const +{ + if (m_currentCamera) { - if (m_currentCamera) + int width, height; + glfwGetFramebufferSize(m_glfwWindow, &width, &height); + if (node->f_bbox.getValue().isValid()) { - int width, height; - glfwGetFramebufferSize(m_glfwWindow, &width, &height); - if (node->f_bbox.getValue().isValid()) - { - vparams->sceneBBox() = node->f_bbox.getValue(); - m_currentCamera->setBoundingBox(vparams->sceneBBox().minBBox(), vparams->sceneBBox().maxBBox()); - } + vparams->sceneBBox() = node->f_bbox.getValue(); + m_currentCamera->setBoundingBox(vparams->sceneBBox().minBBox(), vparams->sceneBBox().maxBBox()); + } - // Update the visual params - vparams->viewport() = { 0, 0, width, height }; - vparams->zNear() = m_currentCamera->getZNear(); - vparams->zFar() = m_currentCamera->getZFar(); + // Update the visual params + vparams->viewport() = { 0, 0, width, height }; + vparams->zNear() = m_currentCamera->getZNear(); + vparams->zFar() = m_currentCamera->getZFar(); - m_currentCamera->fitBoundingBox(node->f_bbox.getValue().minBBox(), node->f_bbox.getValue().maxBBox()); - } + m_currentCamera->fitBoundingBox(node->f_bbox.getValue().minBBox(), node->f_bbox.getValue().maxBBox()); } +} - void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos, SofaGLFWBaseGUI* gui) +void SofaGLFWWindow::mouseMoveEvent(int xpos, int ypos, SofaGLFWBaseGUI* gui) +{ + m_currentXPos = xpos; + m_currentYPos = ypos; + switch (m_currentAction) { - m_currentXPos = xpos; - m_currentYPos = ypos; - switch (m_currentAction) + case GLFW_PRESS: { - case GLFW_PRESS: + core::objectmodel::MouseEvent* mEvent = nullptr; + if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::LeftPressed, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::RightPressed, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); + else { - core::objectmodel::MouseEvent* mEvent = nullptr; - if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::LeftPressed, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::RightPressed, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::MiddlePressed, xpos, ypos); - else - { - // A fallback event to rule them all... - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); - } - m_currentCamera->manageEvent(mEvent); + // A fallback event to rule them all... + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::AnyExtraButtonPressed, xpos, ypos); + } + m_currentCamera->manageEvent(mEvent); - auto rootNode = gui->getRootNode(); + auto rootNode = gui->getRootNode(); - rootNode->propagateEvent(core::execparams::defaultInstance(), mEvent); + rootNode->propagateEvent(core::execparams::defaultInstance(), mEvent); - break; - } - case GLFW_RELEASE: + break; + } + case GLFW_RELEASE: + { + core::objectmodel::MouseEvent* mEvent = nullptr; + if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::LeftReleased, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::RightReleased, xpos, ypos); + else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); + else { - core::objectmodel::MouseEvent* mEvent = nullptr; - if (m_currentButton == GLFW_MOUSE_BUTTON_LEFT) - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::LeftReleased, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_RIGHT) - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::RightReleased, xpos, ypos); - else if (m_currentButton == GLFW_MOUSE_BUTTON_MIDDLE) - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::MiddleReleased, xpos, ypos); - else - { - // A fallback event to rules them all... - mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); - } - m_currentCamera->manageEvent(mEvent); + // A fallback event to rules them all... + mEvent = new core::objectmodel::MouseEvent(core::objectmodel::MouseEvent::AnyExtraButtonReleased, xpos, ypos); + } + m_currentCamera->manageEvent(mEvent); - auto rootNode = gui->getRootNode(); + auto rootNode = gui->getRootNode(); - rootNode->propagateEvent(core::execparams::defaultInstance(), mEvent); + rootNode->propagateEvent(core::execparams::defaultInstance(), mEvent); - break; - } - default: - { - core::objectmodel::MouseEvent me(core::objectmodel::MouseEvent::Move, xpos, ypos); - m_currentCamera->manageEvent(&me); - break; - } + break; + } + default: + { + core::objectmodel::MouseEvent me(core::objectmodel::MouseEvent::Move, xpos, ypos); + m_currentCamera->manageEvent(&me); + break; } - - m_currentButton = -1; - m_currentAction = -1; - m_currentMods = -1; - } - void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) - { - // Only change state on button press; release resets state to neutral - m_currentButton = button; - m_currentAction = action; - m_currentMods = mods; } + m_currentButton = -1; + m_currentAction = -1; + m_currentMods = -1; +} +void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) +{ + // Only change state on button press; release resets state to neutral + m_currentButton = button; + m_currentAction = action; + m_currentMods = mods; +} + bool SofaGLFWWindow::mouseEvent(GLFWwindow* window, int width, int height,int button, int action, int mods, double xpos, double ypos) { if (!m_currentCamera) @@ -264,12 +264,12 @@ namespace sofaglfw return true; } - void SofaGLFWWindow::scrollEvent(double xoffset, double yoffset) - { - SOFA_UNUSED(xoffset); - const double yFactor = 10.f; - core::objectmodel::MouseEvent me(core::objectmodel::MouseEvent::Wheel, static_cast(yoffset * yFactor)); - m_currentCamera->manageEvent(&me); - } +void SofaGLFWWindow::scrollEvent(double xoffset, double yoffset) +{ + SOFA_UNUSED(xoffset); + const double yFactor = 10.f; + core::objectmodel::MouseEvent me(core::objectmodel::MouseEvent::Wheel, static_cast(yoffset * yFactor)); + m_currentCamera->manageEvent(&me); +} } // namespace sofaglfw From 947e1cbaba39601448997261ab20ccaf497cb1eb Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 2 Aug 2024 16:29:46 +0200 Subject: [PATCH 26/41] fix indentation --- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 14e9f6bb12..8366d2f260 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -37,17 +37,17 @@ using namespace sofa; namespace sofaglfw { - SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) - : m_glfwWindow(glfwWindow) - , m_currentCamera(camera) - { +SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) + : m_glfwWindow(glfwWindow) + , m_currentCamera(camera) +{ - } +} - void SofaGLFWWindow::close() - { - glfwDestroyWindow(m_glfwWindow); - } +void SofaGLFWWindow::close() +{ + glfwDestroyWindow(m_glfwWindow); +} void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]){ @@ -99,7 +99,7 @@ void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual:: vparams->setModelViewMatrix(lastModelviewMatrix); simulation::node::draw(vparams, groot.get()); - } +} void SofaGLFWWindow::setBackgroundColor(const type::RGBAColor& newColor) { From 0ceedb3e15256a9b0dd15844af8c9ffb0497f10c Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Mon, 5 Aug 2024 11:39:01 +0200 Subject: [PATCH 27/41] update --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 2 +- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 7 +++--- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp | 10 ++++----- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h | 6 ++--- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 17 ++------------ SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 22 +++++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 20 ++++++++--------- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h | 4 ++-- SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp | 2 +- 9 files changed, 38 insertions(+), 52 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index f620256a26..e4bf8b39f5 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -206,7 +206,7 @@ void SofaGLFWBaseGUI::changeCamera(BaseCamera::SPtr newCamera) } } -void SofaGLFWBaseGUI::restoreCamera(sofa::component::visual::BaseCamera::SPtr camera) +void SofaGLFWBaseGUI::restoreCamera(BaseCamera::SPtr camera) { if (camera) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index be5ffd7aee..ec0da65938 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -42,7 +42,8 @@ namespace sofaglfw { class SofaGLFWWindow; -class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { +class SOFAGLFW_API SofaGLFWBaseGUI : public BaseViewer +{ public: SofaGLFWBaseGUI(); @@ -81,10 +82,10 @@ class SOFAGLFW_API SofaGLFWBaseGUI : public sofa::gui::common::BaseViewer { bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const; void switchFullScreen(GLFWwindow* glfwWindow = nullptr, unsigned int screenID = 0); - void setBackgroundColor(const sofa::type::RGBAColor& newColor, unsigned int windowID = 0); + void setBackgroundColor(const RGBAColor& newColor, unsigned int windowID = 0); virtual void setBackgroundImage(const std::string& imageFileName = "textures/SOFA_logo.bmp", unsigned int windowID = 0); - sofa::core::sptr getRootNode() const; + sofa::core::sptr getRootNode() const; bool hasWindow() const { return m_firstWindow != nullptr; } [[nodiscard]] std::string getFilename() const { return m_filename; } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp index 518c309f82..5001778a67 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp @@ -73,7 +73,7 @@ void SofaGLFWGUI::setScene(simulation::NodeSPtr groot, const char* filename, boo m_baseGUI.restoreCamera(m_baseGUI.findCamera(groot)); } -simulation::Node* SofaGLFWGUI::currentSimulation() +Node* SofaGLFWGUI::currentSimulation() { return m_baseGUI.getRootNode().get(); } @@ -93,9 +93,9 @@ void SofaGLFWGUI::centerWindow() [[maybe_unused]] bool centered = m_baseGUI.centerWindow(); } -void SofaGLFWGUI::setViewerConfiguration(sofa::component::setting::ViewerSetting* viewerConf) +void SofaGLFWGUI::setViewerConfiguration(component::setting::ViewerSetting* viewerConf) { - const type::Vec<2, int>& res = viewerConf->resolution.getValue(); + const Vec<2, int>& res = viewerConf->resolution.getValue(); if (viewerConf->fullscreen.getValue()) { @@ -112,7 +112,7 @@ void SofaGLFWGUI::setFullScreen() m_baseGUI.switchFullScreen(); } -void SofaGLFWGUI::setBackgroundColor(const type::RGBAColor& color) +void SofaGLFWGUI::setBackgroundColor(const RGBAColor& color) { m_baseGUI.setBackgroundColor(color); } @@ -122,7 +122,7 @@ void SofaGLFWGUI::setBackgroundImage(const std::string& image) SOFA_UNUSED(image); } -gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, simulation::NodeSPtr groot, const char* filename) +BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, simulation::NodeSPtr groot, const char* filename) { mGuiName = name; auto* gui = new SofaGLFWGUI(); diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h index 11ffd5fb13..d2631052d8 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h @@ -32,7 +32,7 @@ namespace sofaglfw class SofaGLFWWindow; -class SOFAGLFW_API SofaGLFWGUI : public sofa::gui::common::BaseGUI +class SOFAGLFW_API SofaGLFWGUI : public BaseGUI { public: SofaGLFWGUI() = default; @@ -44,12 +44,12 @@ class SOFAGLFW_API SofaGLFWGUI : public sofa::gui::common::BaseGUI void redraw() override; int closeGUI() override; void setScene(sofa::simulation::NodeSPtr groot, const char* filename = nullptr, bool temporaryFile = false) override; - sofa::simulation::Node* currentSimulation() override; + Node* currentSimulation() override; void setViewerResolution(int width, int height) override; void centerWindow() override; void setViewerConfiguration(sofa::component::setting::ViewerSetting* viewerConf) override; void setFullScreen() override; - void setBackgroundColor(const sofa::type::RGBAColor& color) override; + void setBackgroundColor(const RGBAColor& color) override; void setBackgroundImage(const std::string& image) override; static BaseGUI * CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); protected: diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index 640415e1dc..86ff24b5ab 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -20,33 +20,20 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ - -#define GLFW_INCLUDE_NONE - #include #include #include -#include #include #include #include #include "SofaGLFW/SofaGLFWMouseManager.h" using namespace sofa; -using namespace sofa::gui::common; - -using std::endl; using namespace sofa::type; using namespace sofa::defaulttype; -using namespace sofa::gl; -using simulation::getSimulation; -using namespace sofa::simulation; -using namespace sofa::gui::common; - - -using namespace sofa; -namespace sofaglfw { +namespace sofaglfw +{ SofaGLFWMouseManager::SofaGLFWMouseManager() { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h index 0dedfbdd4d..eb4a3d9d18 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -29,17 +29,15 @@ using namespace sofa::gui::common; namespace sofaglfw { - class SOFAGLFW_API SofaGLFWMouseManager { - public: - SofaGLFWMouseManager(); - - void setPickHandler(PickHandler* picker); - - private: - void updateOperation(MOUSE_BUTTON button, const std::string& id); - - PickHandler* pickHandler; - - }; +class SOFAGLFW_API SofaGLFWMouseManager +{ +public: + SofaGLFWMouseManager(); + void setPickHandler(PickHandler* picker); + +private: + void updateOperation(MOUSE_BUTTON button, const std::string& id); + PickHandler* pickHandler; +}; } // namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 8366d2f260..26f2825b43 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -37,7 +37,7 @@ using namespace sofa; namespace sofaglfw { -SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera) +SofaGLFWWindow::SofaGLFWWindow(GLFWwindow* glfwWindow, component::visual::BaseCamera::SPtr camera) : m_glfwWindow(glfwWindow) , m_currentCamera(camera) { @@ -50,7 +50,7 @@ void SofaGLFWWindow::close() } -void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]){ +void SofaGLFWWindow::draw(simulation::NodeSPtr groot, core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]){ glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -101,7 +101,7 @@ void SofaGLFWWindow::draw(sofa::simulation::NodeSPtr groot, sofa::core::visual:: simulation::node::draw(vparams, groot.get()); } -void SofaGLFWWindow::setBackgroundColor(const type::RGBAColor& newColor) +void SofaGLFWWindow::setBackgroundColor(const RGBAColor& newColor) { m_backgroundColor = newColor; } @@ -209,7 +209,7 @@ void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) SofaGLFWBaseGUI *gui = static_cast(glfwGetWindowUserPointer(window)); - gui::common::MousePosition mousepos; + MousePosition mousepos; mousepos.screenWidth = width; mousepos.screenHeight = height; mousepos.x = static_cast(xpos); @@ -225,15 +225,15 @@ void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_LEFT) { - gui->getPickHandler()->handleMouseEvent(gui::common::PRESSED, gui::common::LEFT); + gui->getPickHandler()->handleMouseEvent(PRESSED, LEFT); } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { - gui->getPickHandler()->handleMouseEvent(gui::common::PRESSED, gui::common::RIGHT); + gui->getPickHandler()->handleMouseEvent(PRESSED, RIGHT); } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { - gui->getPickHandler()->handleMouseEvent(gui::common::PRESSED, gui::common::MIDDLE); + gui->getPickHandler()->handleMouseEvent(PRESSED, MIDDLE); } } else if (action == GLFW_RELEASE) @@ -242,16 +242,16 @@ void SofaGLFWWindow::mouseButtonEvent(int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_LEFT) { - gui->getPickHandler()->handleMouseEvent(gui::common::RELEASED, gui::common::LEFT); + gui->getPickHandler()->handleMouseEvent(RELEASED, LEFT); gui->getPickHandler()->deactivateRay(); } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { - gui->getPickHandler()->handleMouseEvent(gui::common::RELEASED, gui::common::RIGHT); + gui->getPickHandler()->handleMouseEvent(RELEASED, RIGHT); } else if (button == GLFW_MOUSE_BUTTON_MIDDLE) { - gui->getPickHandler()->handleMouseEvent(gui::common::RELEASED, gui::common::MIDDLE); + gui->getPickHandler()->handleMouseEvent(RELEASED, MIDDLE); } } } diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h index 27e987a19b..54fdf7ae4e 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h @@ -43,7 +43,7 @@ class SOFAGLFW_API SofaGLFWWindow void mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui); void mouseButtonEvent(int button, int action, int mods); void scrollEvent(double xoffset, double yoffset); - void setBackgroundColor(const sofa::type::RGBAColor& newColor); + void setBackgroundColor(const RGBAColor& newColor); void setCamera(sofa::component::visual::BaseCamera::SPtr newCamera); void centerCamera(sofa::simulation::NodeSPtr node, sofa::core::visual::VisualParams* vparams) const; @@ -57,7 +57,7 @@ class SOFAGLFW_API SofaGLFWWindow int m_currentMods{ -1 }; int m_currentXPos{ -1 }; int m_currentYPos{ -1 }; - sofa::type::RGBAColor m_backgroundColor{ sofa::type::RGBAColor::black() }; + RGBAColor m_backgroundColor{ RGBAColor::black() }; }; } // namespace sofaglfw diff --git a/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp b/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp index e47e20e792..5a18528d01 100644 --- a/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp +++ b/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp @@ -47,7 +47,7 @@ void initExternalModule() { first = false; #if SOFAGLFW_HAVE_SOFA_GUI_COMMON - sofa::gui::common::GUIManager::RegisterGUI("glfw", &SofaGLFWGUI::CreateGUI); + GUIManager::RegisterGUI("glfw", &SofaGLFWGUI::CreateGUI); #endif // SOFAGLFW_HAVE_SOFA_GUI_COMMON } } From f3474bd6521f67aab08978afb6ce5da96c4e4312 Mon Sep 17 00:00:00 2001 From: MOHAMED SAID AIMEN LAMRI <89317946+lamriaimen@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:49:10 +0200 Subject: [PATCH 28/41] Update SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp Co-authored-by: Frederick Roy --- SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index 86ff24b5ab..63bcf86960 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -37,7 +37,6 @@ namespace sofaglfw SofaGLFWMouseManager::SofaGLFWMouseManager() { - RegisterOperation("attach").add(); RegisterOperation("Attach").add< AttachOperation >(); RegisterOperation("AddFrame").add< AddFrameOperation >(); RegisterOperation("SaveCameraViewPoint").add< AddRecordedCameraOperation >(); From 398f2790797e97c36c2fe4d714539919b70280c6 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Tue, 6 Aug 2024 09:10:28 +0900 Subject: [PATCH 29/41] reverting calling OpenGL2 api --- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 10df868723..b6dfde86af 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -143,7 +143,7 @@ void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow) ImGui_ImplGlfw_InitForOpenGL(glfwWindow, true); #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL3_NewFrame; + ImGui_ImplOpenGL2_Init(); #else ImGui_ImplOpenGL3_Init(nullptr); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 @@ -212,7 +212,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) // Start the Dear ImGui frame #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplOpenGL2_NewFrame(); #else ImGui_ImplOpenGL3_NewFrame(); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 @@ -643,7 +643,7 @@ void ImGuiGUIEngine::terminate() NFD_Quit(); #if SOFAIMGUI_FORCE_OPENGL2 == 1 - ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplOpenGL2_Shutdown(); #else ImGui_ImplOpenGL3_Shutdown(); #endif // SOFAIMGUI_FORCE_OPENGL2 == 1 From 00e4ae28b998b01356c7a1324e0b8485afef2ccc Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 6 Aug 2024 12:14:36 +0200 Subject: [PATCH 30/41] apply some changes --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 73 +++++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 5 +- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 2 +- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index e4bf8b39f5..51d2586952 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -162,41 +162,41 @@ BaseCamera::SPtr SofaGLFWBaseGUI::findCamera(NodeSPtr groot) } - void SofaGLFWBaseGUI::setSizeW(int width) - { - m_windowWidth = width; - } +void SofaGLFWBaseGUI::setSizeW(int width) +{ + m_windowWidth = width; +} - void SofaGLFWBaseGUI::setSizeH(int height) - { - m_windowHeight = height; - } +void SofaGLFWBaseGUI::setSizeH(int height) +{ + m_windowHeight = height; +} - int SofaGLFWBaseGUI::getWidth() - { - return m_windowWidth; - } +int SofaGLFWBaseGUI::getWidth() +{ + return m_windowWidth; +} - int SofaGLFWBaseGUI::getHeight() - { - return m_windowHeight; - } +int SofaGLFWBaseGUI::getHeight() +{ + return m_windowHeight; +} - void SofaGLFWBaseGUI::redraw() - { - } +void SofaGLFWBaseGUI::redraw() +{ +} - void SofaGLFWBaseGUI::drawScene() - { - } +void SofaGLFWBaseGUI::drawScene() +{ +} - void SofaGLFWBaseGUI::viewAll() - { - } +void SofaGLFWBaseGUI::viewAll() +{ +} - void SofaGLFWBaseGUI::saveView() - { - } +void SofaGLFWBaseGUI::saveView() +{ +} void SofaGLFWBaseGUI::changeCamera(BaseCamera::SPtr newCamera) { @@ -478,12 +478,10 @@ std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) glfwSwapBuffers(glfwWindow); - if (viewPortHeight!=m_vparams->viewport()[3] || - viewPortWidth!=m_vparams->viewport()[2]) - { - viewPortHeight=m_vparams->viewport()[3]; - viewPortWidth=m_vparams->viewport()[2]; - } + + viewPortHeight=m_vparams->viewport()[3]; + viewPortWidth=m_vparams->viewport()[2]; + } else { @@ -656,7 +654,7 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in } break; case GLFW_KEY_LEFT_SHIFT: - if (currentGUI->second->getPickHandler()) // Check if getPickHandler() is not null + if (currentGUI->second->getPickHandler()) { if (action == GLFW_PRESS) { @@ -761,7 +759,7 @@ void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int { // Check if the animation is running if (!currentGUI->second->simulationIsRunning()) { - msg_error("SofaGLFWBaseGUI") << "Animation is not running. Ignoring mouse interaction."; + msg_info("SofaGLFWBaseGUI") << "Animation is not running. Ignoring mouse interaction."; return; } @@ -792,8 +790,7 @@ void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int void SofaGLFWBaseGUI::translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos) { - gui->translatedCursorPos[0] =xpos-(gui->viewPortPosition[0]-gui->windowPosition[0]); - gui->translatedCursorPos[1] =ypos-(gui->viewPortPosition[1]-gui->windowPosition[1]); + gui->translatedCursorPos = Vec2d{xpos, ypos} - (gui->viewPortPosition - gui->windowPosition); } void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index ec0da65938..1a8ea23641 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -1,4 +1,3 @@ - /****************************************************************************** * SOFA, Simulation Open-Framework Architecture * * (c) 2006 INRIA, USTL, UJF, CNRS, MGH * @@ -32,7 +31,7 @@ #include #include -#include "SofaGLFW/SofaGLFWMouseManager.h" +#include struct GLFWwindow; struct GLFWmonitor; @@ -41,7 +40,7 @@ using namespace sofa::type; namespace sofaglfw { - class SofaGLFWWindow; +class SofaGLFWWindow; class SOFAGLFW_API SofaGLFWBaseGUI : public BaseViewer { public: diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index 86ff24b5ab..4ed47b0cde 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -42,7 +42,7 @@ namespace sofaglfw RegisterOperation("AddFrame").add< AddFrameOperation >(); RegisterOperation("SaveCameraViewPoint").add< AddRecordedCameraOperation >(); RegisterOperation("StartNavigation").add< StartNavigationOperation >(); - RegisterOperation("Fix") .add< FixOperation >(); + RegisterOperation("Fix").add< FixOperation >(); RegisterOperation("Incise").add< InciseOperation >(); RegisterOperation("Remove").add< TopologyOperation >(); RegisterOperation("Suture").add< AddSutureOperation >(); From a6f1e1cea134e58b325d4efe8b5a7bed2c74ccef Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 6 Aug 2024 15:44:26 +0200 Subject: [PATCH 31/41] apply some changes --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 45 +++++++++---------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 17 +++---- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 2 +- SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 1 + 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 51d2586952..c0607c9a76 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -33,7 +33,7 @@ #include #include #include -#include "SofaGLFW/SofaGLFWMouseManager.h" +#include #include #include @@ -66,8 +66,6 @@ using namespace core::objectmodel; namespace sofaglfw { SofaGLFWBaseGUI::SofaGLFWBaseGUI() - :lastProjectionMatrix{0.0}, - lastModelviewMatrix{0.0} { m_guiEngine = std::make_shared(); } @@ -312,8 +310,8 @@ bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, boo } void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) { - viewPortPosition[0]=lastViewPortPosX; - viewPortPosition[1]=lastViewPortPosY; + m_viewPortPosition[0]=lastViewPortPosX; + m_viewPortPosition[1]=lastViewPortPosY; } void SofaGLFWBaseGUI::resizeWindow(int width, int height) @@ -447,8 +445,8 @@ std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) } m_vparams = VisualParams::defaultInstance(); - viewPortWidth=m_vparams->viewport()[2]; - viewPortHeight=m_vparams->viewport()[3]; + m_viewPortWidth=m_vparams->viewport()[2]; + m_viewPortHeight=m_vparams->viewport()[3]; bool running = true; std::size_t currentNbIterations = 0; @@ -470,7 +468,7 @@ std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) makeCurrentContext(glfwWindow); m_guiEngine->beforeDraw(glfwWindow); - sofaGlfwWindow->draw(m_groot, m_vparams,lastModelviewMatrix,lastProjectionMatrix); + sofaGlfwWindow->draw(m_groot, m_vparams, const_cast(m_lastModelviewMatrix.data()), const_cast(m_lastProjectionMatrix.data())); m_guiEngine->afterDraw(); m_guiEngine->startFrame(this); @@ -479,8 +477,8 @@ std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) glfwSwapBuffers(glfwWindow); - viewPortHeight=m_vparams->viewport()[3]; - viewPortWidth=m_vparams->viewport()[2]; + m_viewPortHeight=m_vparams->viewport()[3]; + m_viewPortWidth=m_vparams->viewport()[2]; } else @@ -658,9 +656,8 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in { if (action == GLFW_PRESS) { - int viewport[4] = {}; // Properly initialize the viewport array - currentGUI->second->getPickHandler()->activateRay(viewport[2], viewport[3], rootNode.get()); - } + fixed_array viewport; + currentGUI->second->getPickHandler()->activateRay(viewport[3], viewport[4], rootNode.get()); } else if (action == GLFW_RELEASE) { currentGUI->second->getPickHandler()->deactivateRay(); @@ -683,12 +680,12 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in Vec3d pz; Vec3d px1; Vec3d py1; - gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); - gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(px[0]), &(px[1]), &(px[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(py[0]), &(py[1]), &(py[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); px1 -= pz; py1 -= pz; @@ -733,8 +730,8 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in void SofaGLFWBaseGUI::window_pos_callback(GLFWwindow* window, int xpos, int ypos) { SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); - gui->windowPosition[0]=xpos; - gui->windowPosition[1]=ypos; + gui->m_windowPosition[0]=xpos; + gui->m_windowPosition[1]=ypos; } void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) @@ -769,7 +766,7 @@ void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int auto currentSofaWindow = s_mapWindows.find(window); if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) { - currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, button, action, mods, gui->translatedCursorPos[0], gui->translatedCursorPos[1]); + currentSofaWindow->second->mouseEvent(window,gui->m_viewPortWidth,gui->m_viewPortHeight, button, action, mods, gui->m_translatedCursorPos[0], gui->m_translatedCursorPos[1]); } } else @@ -790,7 +787,7 @@ void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int void SofaGLFWBaseGUI::translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos) { - gui->translatedCursorPos = Vec2d{xpos, ypos} - (gui->viewPortPosition - gui->windowPosition); + gui->m_translatedCursorPos = Vec2d{xpos, ypos} - (gui->m_viewPortPosition - gui->m_windowPosition); } void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) @@ -813,7 +810,7 @@ void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, if (shiftPressed && state == GLFW_PRESS) { - currentSofaWindow->second->mouseEvent(window,gui->viewPortWidth,gui->viewPortHeight, 0, 1, 1, gui->translatedCursorPos[0], gui->translatedCursorPos[1]); + currentSofaWindow->second->mouseEvent(window,gui->m_viewPortWidth,gui->m_viewPortHeight, 0, 1, 1, gui->m_translatedCursorPos[0], gui->m_translatedCursorPos[1]); } if (currentSofaWindow != s_mapWindows.end() && currentSofaWindow->second) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 1a8ea23641..3870b15cb3 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -142,17 +142,14 @@ class SOFAGLFW_API SofaGLFWBaseGUI : public BaseViewer int m_lastWindowPositionY{ 0 }; int m_lastWindowWidth{ 0 }; int m_lastWindowHeight{ 0 }; - double lastProjectionMatrix[16]; - double lastModelviewMatrix[16]; - bool m_isMouseInteractionEnabled{ false }; + fixed_array m_lastProjectionMatrix; + fixed_array m_lastModelviewMatrix; SofaGLFWMouseManager m_sofaGLFWMouseManager; - int viewPortHeight{0}; - int viewPortWidth {0}; - Vec2d translatedCursorPos; - Vec2f viewPortPosition; - Vec2f windowPosition; - - + int m_viewPortHeight{0}; + int m_viewPortWidth {0}; + Vec2d m_translatedCursorPos; + Vec2f m_viewPortPosition; + Vec2f m_windowPosition; std::shared_ptr m_guiEngine; }; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index 5948e9653c..df44b85895 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -26,7 +26,7 @@ #include #include #include -#include "SofaGLFW/SofaGLFWMouseManager.h" +#include using namespace sofa; using namespace sofa::type; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h index eb4a3d9d18..99a0a67503 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -34,6 +34,7 @@ class SOFAGLFW_API SofaGLFWMouseManager public: SofaGLFWMouseManager(); void setPickHandler(PickHandler* picker); + bool m_isMouseInteractionEnabled{ false }; private: void updateOperation(MOUSE_BUTTON button, const std::string& id); From 5d7f0ab5fb2b92665e51d2e7c9c8f2146cef5b58 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 6 Aug 2024 16:45:12 +0200 Subject: [PATCH 32/41] update --- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp | 15 ++++++++------- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h | 8 ++++---- SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp | 2 +- SofaImGui/src/SofaImGui/AppIniFile.cpp | 2 +- SofaImGui/src/SofaImGui/ImGuiGUI.cpp | 4 ++-- SofaImGui/src/SofaImGui/ImGuiGUI.h | 2 +- SofaImGui/src/SofaImGui/ImGuiGUIEngine.h | 20 ++++++++++---------- SofaImGui/src/SofaImGui/initSofaImGui.cpp | 2 +- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp index 5001778a67..9cecd20608 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp @@ -53,7 +53,7 @@ int SofaGLFWGUI::closeGUI() return 0; } -void SofaGLFWGUI::setScene(simulation::NodeSPtr groot, const char* filename, bool temporaryFile) +void SofaGLFWGUI::setScene(sofa::simulation::NodeSPtr groot, const char* filename, bool temporaryFile) { SOFA_UNUSED(temporaryFile); @@ -73,7 +73,7 @@ void SofaGLFWGUI::setScene(simulation::NodeSPtr groot, const char* filename, boo m_baseGUI.restoreCamera(m_baseGUI.findCamera(groot)); } -Node* SofaGLFWGUI::currentSimulation() +sofa::simulation::Node* SofaGLFWGUI::currentSimulation() { return m_baseGUI.getRootNode().get(); } @@ -93,9 +93,9 @@ void SofaGLFWGUI::centerWindow() [[maybe_unused]] bool centered = m_baseGUI.centerWindow(); } -void SofaGLFWGUI::setViewerConfiguration(component::setting::ViewerSetting* viewerConf) +void SofaGLFWGUI::setViewerConfiguration(sofa::component::setting::ViewerSetting* viewerConf) { - const Vec<2, int>& res = viewerConf->resolution.getValue(); + const type::Vec<2, int>& res = viewerConf->resolution.getValue(); if (viewerConf->fullscreen.getValue()) { @@ -112,7 +112,7 @@ void SofaGLFWGUI::setFullScreen() m_baseGUI.switchFullScreen(); } -void SofaGLFWGUI::setBackgroundColor(const RGBAColor& color) +void SofaGLFWGUI::setBackgroundColor(const sofa::type::RGBAColor& color) { m_baseGUI.setBackgroundColor(color); } @@ -122,9 +122,10 @@ void SofaGLFWGUI::setBackgroundImage(const std::string& image) SOFA_UNUSED(image); } -BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, simulation::NodeSPtr groot, const char* filename) + +sofa::gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename) { - mGuiName = name; + SofaGLFWGUI::mGuiName = name; auto* gui = new SofaGLFWGUI(); if (!gui->init()) { diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h index d2631052d8..c806b51606 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.h @@ -32,7 +32,7 @@ namespace sofaglfw class SofaGLFWWindow; -class SOFAGLFW_API SofaGLFWGUI : public BaseGUI +class SOFAGLFW_API SofaGLFWGUI : public sofa::gui::common::BaseGUI { public: SofaGLFWGUI() = default; @@ -44,14 +44,14 @@ class SOFAGLFW_API SofaGLFWGUI : public BaseGUI void redraw() override; int closeGUI() override; void setScene(sofa::simulation::NodeSPtr groot, const char* filename = nullptr, bool temporaryFile = false) override; - Node* currentSimulation() override; + sofa::simulation::Node* currentSimulation() override; void setViewerResolution(int width, int height) override; void centerWindow() override; void setViewerConfiguration(sofa::component::setting::ViewerSetting* viewerConf) override; void setFullScreen() override; - void setBackgroundColor(const RGBAColor& color) override; + void setBackgroundColor(const sofa::type::RGBAColor& color) override; void setBackgroundImage(const std::string& image) override; - static BaseGUI * CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); + static sofa::gui::common::BaseGUI * CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); protected: SofaGLFWBaseGUI m_baseGUI; bool m_bCreateWithFullScreen{ false }; diff --git a/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp b/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp index 5a18528d01..33d0edd81f 100644 --- a/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp +++ b/SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp @@ -47,7 +47,7 @@ void initExternalModule() { first = false; #if SOFAGLFW_HAVE_SOFA_GUI_COMMON - GUIManager::RegisterGUI("glfw", &SofaGLFWGUI::CreateGUI); + sofa::gui::common::GUIManager::RegisterGUI("glfw", &sofaglfw::SofaGLFWGUI::CreateGUI); #endif // SOFAGLFW_HAVE_SOFA_GUI_COMMON } } diff --git a/SofaImGui/src/SofaImGui/AppIniFile.cpp b/SofaImGui/src/SofaImGui/AppIniFile.cpp index 81377172ac..40df9f4838 100644 --- a/SofaImGui/src/SofaImGui/AppIniFile.cpp +++ b/SofaImGui/src/SofaImGui/AppIniFile.cpp @@ -30,7 +30,7 @@ namespace sofaimgui { const std::string& AppIniFile::getAppIniFile() { - static const std::string appIniFile(helper::Utils::getExecutableDirectory() + "/settings.ini"); + static const std::string appIniFile(sofa::helper::Utils::getExecutableDirectory() + "/settings.ini"); return appIniFile; } diff --git a/SofaImGui/src/SofaImGui/ImGuiGUI.cpp b/SofaImGui/src/SofaImGui/ImGuiGUI.cpp index f869488cee..4ec99a8821 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUI.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUI.cpp @@ -33,7 +33,7 @@ namespace sofaimgui { ImGuiGUI::ImGuiGUI() -: SofaGLFWGUI() +: sofaglfw::SofaGLFWGUI() { auto guiEngine = std::make_shared(); this->m_baseGUI.setGUIEngine(guiEngine); @@ -42,7 +42,7 @@ ImGuiGUI::ImGuiGUI() sofa::gui::common::BaseGUI* ImGuiGUI::CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename) { - mGuiName = name; + ImGuiGUI::mGuiName = name; auto* gui = new ImGuiGUI(); if (!gui->init()) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUI.h b/SofaImGui/src/SofaImGui/ImGuiGUI.h index 81cd230695..52dbc53007 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUI.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUI.h @@ -34,7 +34,7 @@ class SOFAIMGUI_API ImGuiGUI : public sofaglfw::SofaGLFWGUI ~ImGuiGUI() override = default; - static BaseGUI* CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); + static sofa::gui::common::BaseGUI* CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename); }; } // namespace sofaimgui diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index 2d26b2264a..80f308bdff 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -70,16 +70,16 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine void loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, std::string filePathName); // WindowState members - WindowState winManagerProfiler; - WindowState winManagerSceneGraph; - WindowState winManagerPerformances; - WindowState winManagerDisplayFlags; - WindowState winManagerPlugins; - WindowState winManagerComponents; - WindowState winManagerLog; - WindowState winManagerSettings; - WindowState winManagerViewPort; - WindowState firstRunState; + windows::WindowState winManagerProfiler; + windows::WindowState winManagerSceneGraph; + windows::WindowState winManagerPerformances; + windows::WindowState winManagerDisplayFlags; + windows::WindowState winManagerPlugins; + windows::WindowState winManagerComponents; + windows::WindowState winManagerLog; + windows::WindowState winManagerSettings; + windows::WindowState winManagerViewPort; + windows::WindowState firstRunState; }; } // namespace sofaimgui diff --git a/SofaImGui/src/SofaImGui/initSofaImGui.cpp b/SofaImGui/src/SofaImGui/initSofaImGui.cpp index a469b12240..bbcc25c814 100644 --- a/SofaImGui/src/SofaImGui/initSofaImGui.cpp +++ b/SofaImGui/src/SofaImGui/initSofaImGui.cpp @@ -48,7 +48,7 @@ void initExternalModule() sofa::helper::logging::MessageDispatcher::addHandler(&sofa::helper::logging::MainLoggingMessageHandler::getInstance()); sofa::helper::logging::MainLoggingMessageHandler::getInstance().activate(); - sofa::gui::common::GUIManager::RegisterGUI("imgui", &ImGuiGUI::CreateGUI); + sofa::gui::common::GUIManager::RegisterGUI("imgui", &sofaimgui::ImGuiGUI::CreateGUI); } } From 73875912f40822a41795b625d38788f07fed6710 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Tue, 6 Aug 2024 16:45:49 +0200 Subject: [PATCH 33/41] update --- SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp index 9cecd20608..b8a4d74704 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp @@ -122,7 +122,6 @@ void SofaGLFWGUI::setBackgroundImage(const std::string& image) SOFA_UNUSED(image); } - sofa::gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, sofa::simulation::NodeSPtr groot, const char* filename) { SofaGLFWGUI::mGuiName = name; From 41e7631055395b8258b15c1365b52263ebf143cc Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Wed, 7 Aug 2024 09:58:56 +0200 Subject: [PATCH 34/41] update --- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index 26f2825b43..efe421a488 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -75,11 +75,6 @@ void SofaGLFWWindow::draw(simulation::NodeSPtr groot, core::visual::VisualParams m_currentCamera->d_widthViewport.setValue(vparams->viewport()[2]); m_currentCamera->d_heightViewport.setValue(vparams->viewport()[3]); - m_currentCamera->getModelViewMatrix( lastModelviewMatrix ); - vparams->setModelViewMatrix( lastModelviewMatrix ); - // matrices - double projectionMatrix[16]; - double mvMatrix[16]; m_currentCamera->getOpenGLProjectionMatrix(lastProjectionMatrix); m_currentCamera->getOpenGLModelViewMatrix(lastModelviewMatrix); From b94406d030f683f4a83ca5adbaf0292f9f97f435 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Wed, 7 Aug 2024 10:25:48 +0200 Subject: [PATCH 35/41] update to use m_vprams methods --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 20 +++++++++++++------- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h | 2 -- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp | 9 ++++++++- SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index c0607c9a76..5a80653002 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -468,7 +468,7 @@ std::size_t SofaGLFWBaseGUI::runLoop(std::size_t targetNbIterations) makeCurrentContext(glfwWindow); m_guiEngine->beforeDraw(glfwWindow); - sofaGlfwWindow->draw(m_groot, m_vparams, const_cast(m_lastModelviewMatrix.data()), const_cast(m_lastProjectionMatrix.data())); + sofaGlfwWindow->draw(m_groot, m_vparams); m_guiEngine->afterDraw(); m_guiEngine->startFrame(this); @@ -674,18 +674,24 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in { const VisualParams::Viewport& viewport = m_vparams->viewport(); + double lastProjectionMatrix[16]; + double lastModelviewMatrix[16]; + + m_vparams->getProjectionMatrix(lastProjectionMatrix); + m_vparams->getModelViewMatrix(lastModelviewMatrix); + Vec3d p0; Vec3d px; Vec3d py; Vec3d pz; Vec3d px1; Vec3d py1; - gluUnProject(eventX, viewport[3]-1-(eventY), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(px[0]), &(px[1]), &(px[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(py[0]), &(py[1]), &(py[2])); - gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, m_lastModelviewMatrix.data(), m_lastProjectionMatrix.data(), viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); px1 -= pz; py1 -= pz; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h index 3870b15cb3..53524bd731 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h @@ -142,8 +142,6 @@ class SOFAGLFW_API SofaGLFWBaseGUI : public BaseViewer int m_lastWindowPositionY{ 0 }; int m_lastWindowWidth{ 0 }; int m_lastWindowHeight{ 0 }; - fixed_array m_lastProjectionMatrix; - fixed_array m_lastModelviewMatrix; SofaGLFWMouseManager m_sofaGLFWMouseManager; int m_viewPortHeight{0}; int m_viewPortWidth {0}; diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp index efe421a488..083a957917 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.cpp @@ -50,7 +50,7 @@ void SofaGLFWWindow::close() } -void SofaGLFWWindow::draw(simulation::NodeSPtr groot, core::visual::VisualParams* vparams, double lastModelviewMatrix [16], double lastProjectionMatrix [16]){ +void SofaGLFWWindow::draw(simulation::NodeSPtr groot, core::visual::VisualParams* vparams){ glClearColor(m_backgroundColor.r(), m_backgroundColor.g(), m_backgroundColor.b(), m_backgroundColor.a()); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -75,6 +75,13 @@ void SofaGLFWWindow::draw(simulation::NodeSPtr groot, core::visual::VisualParams m_currentCamera->d_widthViewport.setValue(vparams->viewport()[2]); m_currentCamera->d_heightViewport.setValue(vparams->viewport()[3]); + // matrices + double lastModelviewMatrix [16]; + double lastProjectionMatrix [16]; + + vparams->getModelViewMatrix(lastModelviewMatrix); + vparams->getProjectionMatrix(lastProjectionMatrix); + m_currentCamera->getOpenGLProjectionMatrix(lastProjectionMatrix); m_currentCamera->getOpenGLModelViewMatrix(lastModelviewMatrix); diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h index 54fdf7ae4e..fbf78a586d 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWWindow.h @@ -37,7 +37,7 @@ class SOFAGLFW_API SofaGLFWWindow SofaGLFWWindow(GLFWwindow* glfwWindow, sofa::component::visual::BaseCamera::SPtr camera); virtual ~SofaGLFWWindow() = default; - void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams,double lastModelviewMatrix [16],double lastProjectionMatrix[16]); + void draw(sofa::simulation::NodeSPtr groot, sofa::core::visual::VisualParams* vparams); void close(); void mouseMoveEvent(int xpos, int ypos,SofaGLFWBaseGUI* gui); From a604c73e983ed858e42093a1cb81c7635d58946c Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Wed, 7 Aug 2024 10:28:34 +0200 Subject: [PATCH 36/41] fix indentation issues --- SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp | 156 +++++++++++----------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp index 5a80653002..72d80a3095 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp @@ -308,11 +308,11 @@ bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, boo return false; } - void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) - { - m_viewPortPosition[0]=lastViewPortPosX; - m_viewPortPosition[1]=lastViewPortPosY; - } +void SofaGLFWBaseGUI::updateViewportPosition(float lastViewPortPosX, float lastViewPortPosY) +{ + m_viewPortPosition[0]=lastViewPortPosX; + m_viewPortPosition[1]=lastViewPortPosY; +} void SofaGLFWBaseGUI::resizeWindow(int width, int height) { @@ -670,75 +670,75 @@ void SofaGLFWBaseGUI::key_callback(GLFWwindow* window, int key, int scancode, in } } - void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) - { - const VisualParams::Viewport& viewport = m_vparams->viewport(); - - double lastProjectionMatrix[16]; - double lastModelviewMatrix[16]; - - m_vparams->getProjectionMatrix(lastProjectionMatrix); - m_vparams->getModelViewMatrix(lastModelviewMatrix); - - Vec3d p0; - Vec3d px; - Vec3d py; - Vec3d pz; - Vec3d px1; - Vec3d py1; - gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); - gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); - gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); - gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); - - px1 -= pz; - py1 -= pz; - px -= p0; - py -= p0; - pz -= p0; - - const double r0 = sqrt(px.norm2() + py.norm2()); - double r1 = sqrt(px1.norm2() + py1.norm2()); - r1 = r0 + (r1 - r0) / pz.norm(); - px.normalize(); - py.normalize(); - pz.normalize(); - - Mat4x4d transform; - transform.identity(); - transform[0][0] = px[0]; - transform[1][0] = px[1]; - transform[2][0] = px[2]; - transform[0][1] = py[0]; - transform[1][1] = py[1]; - transform[2][1] = py[2]; - transform[0][2] = pz[0]; - transform[1][2] = pz[1]; - transform[2][2] = pz[2]; - transform[0][3] = p0[0]; - transform[1][3] = p0[1]; - transform[2][3] = p0[2]; - - Mat3x3d mat; - mat = transform; - Quat q; - q.fromMatrix(mat); - - Vec3d position, direction; - position = transform * Vec4d(0, 0, 0, 1); - direction = transform * Vec4d(0, 0, 1, 0); - direction.normalize(); - getPickHandler()->updateRay(position, direction); - } - - void SofaGLFWBaseGUI::window_pos_callback(GLFWwindow* window, int xpos, int ypos) - { - SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); - gui->m_windowPosition[0]=xpos; - gui->m_windowPosition[1]=ypos; - } +void SofaGLFWBaseGUI::moveRayPickInteractor(int eventX, int eventY) +{ + const VisualParams::Viewport& viewport = m_vparams->viewport(); + + double lastProjectionMatrix[16]; + double lastModelviewMatrix[16]; + + m_vparams->getProjectionMatrix(lastProjectionMatrix); + m_vparams->getModelViewMatrix(lastModelviewMatrix); + + Vec3d p0; + Vec3d px; + Vec3d py; + Vec3d pz; + Vec3d px1; + Vec3d py1; + gluUnProject(eventX, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(p0[0]), &(p0[1]), &(p0[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px[0]), &(px[1]), &(px[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py[0]), &(py[1]), &(py[2])); + gluUnProject(eventX, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(pz[0]), &(pz[1]), &(pz[2])); + gluUnProject(eventX+1, viewport[3]-1-(eventY), 0.1, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(px1[0]), &(px1[1]), &(px1[2])); + gluUnProject(eventX, viewport[3]-1-(eventY+1), 0, lastModelviewMatrix, lastProjectionMatrix, viewport.data(), &(py1[0]), &(py1[1]), &(py1[2])); + + px1 -= pz; + py1 -= pz; + px -= p0; + py -= p0; + pz -= p0; + + const double r0 = sqrt(px.norm2() + py.norm2()); + double r1 = sqrt(px1.norm2() + py1.norm2()); + r1 = r0 + (r1 - r0) / pz.norm(); + px.normalize(); + py.normalize(); + pz.normalize(); + + Mat4x4d transform; + transform.identity(); + transform[0][0] = px[0]; + transform[1][0] = px[1]; + transform[2][0] = px[2]; + transform[0][1] = py[0]; + transform[1][1] = py[1]; + transform[2][1] = py[2]; + transform[0][2] = pz[0]; + transform[1][2] = pz[1]; + transform[2][2] = pz[2]; + transform[0][3] = p0[0]; + transform[1][3] = p0[1]; + transform[2][3] = p0[2]; + + Mat3x3d mat; + mat = transform; + Quat q; + q.fromMatrix(mat); + + Vec3d position, direction; + position = transform * Vec4d(0, 0, 0, 1); + direction = transform * Vec4d(0, 0, 1, 0); + direction.normalize(); + getPickHandler()->updateRay(position, direction); +} + +void SofaGLFWBaseGUI::window_pos_callback(GLFWwindow* window, int xpos, int ypos) +{ + SofaGLFWBaseGUI* gui = static_cast(glfwGetWindowUserPointer(window)); + gui->m_windowPosition[0]=xpos; + gui->m_windowPosition[1]=ypos; +} void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { @@ -791,10 +791,10 @@ void SofaGLFWBaseGUI::mouse_button_callback(GLFWwindow* window, int button, int } } - void SofaGLFWBaseGUI::translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos) - { - gui->m_translatedCursorPos = Vec2d{xpos, ypos} - (gui->m_viewPortPosition - gui->m_windowPosition); - } +void SofaGLFWBaseGUI::translateToViewportCoordinates (SofaGLFWBaseGUI* gui,double xpos, double ypos) +{ + gui->m_translatedCursorPos = Vec2d{xpos, ypos} - (gui->m_viewPortPosition - gui->m_windowPosition); +} void SofaGLFWBaseGUI::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) { From ff81cf609199faca4c70e1dcc80f1c938c6284bd Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Wed, 7 Aug 2024 14:09:10 +0200 Subject: [PATCH 37/41] start --- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 48 ++++++++++++++++++++-- SofaImGui/src/SofaImGui/ImGuiGUIEngine.h | 3 +- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index b6dfde86af..24317da973 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -93,7 +93,8 @@ ImGuiGUIEngine::ImGuiGUIEngine() winManagerLog("log.txt"), winManagerSettings("settings.txt"), winManagerViewPort("viewport.txt"), - firstRunState("firstrun.txt") + firstRunState("firstrun.txt"), + mousemanager("mouse") { } @@ -191,6 +192,45 @@ void ImGuiGUIEngine::loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sp baseGUI->initVisual(); } + // Example settings + struct OperationSettings { + float stiffness = 1.0f; + float arrowSize = 10.0f; + float showFactorSize = 1.0f; +}; + + // Global settings + OperationSettings settings; + int selectedOperation = 0; // 0: Attach, 1: Fix, 2: Incise, etc. + + // Function to create and display the main window + void ImGuiGUIEngine:: showMainWindow(bool* p_open) { + ImGui::Begin("Operations", p_open); + + const char* operations[] = {"Attach", "Fix", "Incise"}; + ImGui::Combo("Operation", &selectedOperation, operations, IM_ARRAYSIZE(operations)); + + switch (selectedOperation) { + case 0: + ImGui::Text("Attach Operation"); + ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 10.0f); + ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 20.0f); + ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 0.0f, 5.0f); + break; + case 1: + ImGui::Text("Fix Operation"); + ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 10.0f); + break; + case 2: + ImGui::Text("Incise Operation"); + ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 10.0f); + ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 20.0f); + ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 0.0f, 5.0f); + break; + } + + ImGui::End(); + } void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) { auto groot = baseGUI->getRootNode(); @@ -249,6 +289,8 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) static constexpr auto windowNameComponents = ICON_FA_LIST " Components"; static constexpr auto windowNameLog = ICON_FA_TERMINAL " Log"; static constexpr auto windowNameSettings = ICON_FA_SLIDERS_H " Settings"; + static constexpr auto mousemanagername = ICON_FA_SLIDERS_H " mouse mamanger"; + if (!*firstRunState.getStatePtr()) @@ -463,7 +505,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) { ImGui::Checkbox(windowNameViewport, winManagerViewPort.getStatePtr()); ImGui::Checkbox(windowNamePerformances, winManagerPerformances.getStatePtr()); - + ImGui::Checkbox(mousemanagername,mousemanager.getStatePtr()); ImGui::Checkbox(windowNameProfiler, winManagerProfiler.getStatePtr()); ImGui::Checkbox(windowNameSceneGraph, winManagerSceneGraph.getStatePtr()); @@ -545,7 +587,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) **************************************/ showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&lastViewPortPosX,&lastViewPortPosY); - + ImGuiGUIEngine::showMainWindow(mousemanager.getStatePtr()); /*************************************** * Performances window **************************************/ diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index 80f308bdff..7fa024994d 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -68,7 +68,7 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine bool isMouseOnViewport { false }; CSimpleIniA ini; void loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, std::string filePathName); - + void showMainWindow(bool* p_open) ; // WindowState members windows::WindowState winManagerProfiler; windows::WindowState winManagerSceneGraph; @@ -80,6 +80,7 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine windows::WindowState winManagerSettings; windows::WindowState winManagerViewPort; windows::WindowState firstRunState; + windows::WindowState mousemanager; }; } // namespace sofaimgui From 66c2c3d497f0322bcf6e00faa8a1aba54be238d2 Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 8 Aug 2024 11:07:12 +0200 Subject: [PATCH 38/41] update --- SofaImGui/CMakeLists.txt | 7 +-- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 51 +++--------------- SofaImGui/src/SofaImGui/ImGuiGUIEngine.h | 4 +- .../SofaImGui/windows/viewMouseManager.cpp | 52 +++++++++++++++++++ .../src/SofaImGui/windows/viewMouseManager.h | 31 +++++++++++ 5 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp create mode 100644 SofaImGui/src/SofaImGui/windows/viewMouseManager.h diff --git a/SofaImGui/CMakeLists.txt b/SofaImGui/CMakeLists.txt index ce90671465..013bfe55a6 100644 --- a/SofaImGui/CMakeLists.txt +++ b/SofaImGui/CMakeLists.txt @@ -97,10 +97,7 @@ set(HEADER_FILES ${SOFAIMGUI_SOURCE_DIR}/windows/ViewPort.h ${SOFAIMGUI_SOURCE_DIR}/AppIniFile.h ${SOFAIMGUI_SOURCE_DIR}/windows/WindowState.h - - - - + ${SOFAIMGUI_SOURCE_DIR}/windows/viewMouseManager.h ) set(SOURCE_FILES @@ -120,7 +117,7 @@ set(SOURCE_FILES ${SOFAIMGUI_SOURCE_DIR}/windows/ViewPort.cpp ${SOFAIMGUI_SOURCE_DIR}/AppIniFile.cpp ${SOFAIMGUI_SOURCE_DIR}/windows/WindowState.cpp - + ${SOFAIMGUI_SOURCE_DIR}/windows/viewMouseManager.cpp ) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 24317da973..089fe762c5 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -75,6 +75,7 @@ #include "windows/Components.h" #include "windows/Settings.h" #include "AppIniFile.h" +#include "windows/viewMouseManager.h" #include "windows/ViewPort.h" #include "windows/WindowState.h" @@ -94,7 +95,7 @@ ImGuiGUIEngine::ImGuiGUIEngine() winManagerSettings("settings.txt"), winManagerViewPort("viewport.txt"), firstRunState("firstrun.txt"), - mousemanager("mouse") + winManagerMouse("mousemanager.txt") { } @@ -192,45 +193,6 @@ void ImGuiGUIEngine::loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sp baseGUI->initVisual(); } - // Example settings - struct OperationSettings { - float stiffness = 1.0f; - float arrowSize = 10.0f; - float showFactorSize = 1.0f; -}; - - // Global settings - OperationSettings settings; - int selectedOperation = 0; // 0: Attach, 1: Fix, 2: Incise, etc. - - // Function to create and display the main window - void ImGuiGUIEngine:: showMainWindow(bool* p_open) { - ImGui::Begin("Operations", p_open); - - const char* operations[] = {"Attach", "Fix", "Incise"}; - ImGui::Combo("Operation", &selectedOperation, operations, IM_ARRAYSIZE(operations)); - - switch (selectedOperation) { - case 0: - ImGui::Text("Attach Operation"); - ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 10.0f); - ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 20.0f); - ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 0.0f, 5.0f); - break; - case 1: - ImGui::Text("Fix Operation"); - ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 10.0f); - break; - case 2: - ImGui::Text("Incise Operation"); - ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 10.0f); - ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 20.0f); - ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 0.0f, 5.0f); - break; - } - - ImGui::End(); - } void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) { auto groot = baseGUI->getRootNode(); @@ -289,7 +251,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) static constexpr auto windowNameComponents = ICON_FA_LIST " Components"; static constexpr auto windowNameLog = ICON_FA_TERMINAL " Log"; static constexpr auto windowNameSettings = ICON_FA_SLIDERS_H " Settings"; - static constexpr auto mousemanagername = ICON_FA_SLIDERS_H " mouse mamanger"; + static constexpr auto windowNameMouseManager = ICON_FA_MOUSE " Mouse Manager"; @@ -505,7 +467,6 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) { ImGui::Checkbox(windowNameViewport, winManagerViewPort.getStatePtr()); ImGui::Checkbox(windowNamePerformances, winManagerPerformances.getStatePtr()); - ImGui::Checkbox(mousemanagername,mousemanager.getStatePtr()); ImGui::Checkbox(windowNameProfiler, winManagerProfiler.getStatePtr()); ImGui::Checkbox(windowNameSceneGraph, winManagerSceneGraph.getStatePtr()); @@ -522,6 +483,10 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) ImGui::Checkbox(windowNameSettings, winManagerSettings.getStatePtr()); + ImGui::Separator(); + + ImGui::Checkbox(windowNameMouseManager,winManagerMouse.getStatePtr()); + ImGui::EndMenu(); } @@ -587,7 +552,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) **************************************/ showViewPort(groot, windowNameViewport,ini,m_fbo,m_viewportWindowSize,isMouseOnViewport, winManagerViewPort,baseGUI,&firstViewport,&lastViewPortPosX,&lastViewPortPosY); - ImGuiGUIEngine::showMainWindow(mousemanager.getStatePtr()); + showMainWindow(windowNameMouseManager,winManagerMouse); /*************************************** * Performances window **************************************/ diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index 7fa024994d..4847854846 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -68,7 +68,7 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine bool isMouseOnViewport { false }; CSimpleIniA ini; void loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sptr& groot, std::string filePathName); - void showMainWindow(bool* p_open) ; + // WindowState members windows::WindowState winManagerProfiler; windows::WindowState winManagerSceneGraph; @@ -80,7 +80,7 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine windows::WindowState winManagerSettings; windows::WindowState winManagerViewPort; windows::WindowState firstRunState; - windows::WindowState mousemanager; + windows::WindowState winManagerMouse; }; } // namespace sofaimgui diff --git a/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp b/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp new file mode 100644 index 0000000000..d22cbbf163 --- /dev/null +++ b/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp @@ -0,0 +1,52 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the Free * +* Software Foundation; either version 2 of the License, or (at your option) * +* any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ + +#include "viewMouseManager.h" + +#include "SofaImGui/ImGuiGUIEngine.h" +namespace windows { + struct OperationSettings { + float stiffness = 1.0f; + float arrowSize = 10.0f; + float showFactorSize = 1.0f; + }; + + OperationSettings settings; + int selectedOperation = 0; + + void showMainWindow(const char* const&windowNameMouseManager,WindowState& winManagerMouse) { + if(*winManagerMouse.getStatePtr()){ + ImGui::Begin(windowNameMouseManager, winManagerMouse.getStatePtr()); + ImGui::Text("Left Button"); + ImGui::BeginGroup(); + const char* operations[] = {"Attach", "Fix", "Incise"}; + ImGui::Combo("Operation", &selectedOperation, operations, IM_ARRAYSIZE(operations)); + + ImGui::Text("Attach Operation"); + ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 1000.0f); + ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 0.0f); + ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 1.0f, 5.0f); + ImGui::EndGroup(); + ImGui::End(); + } + } +} \ No newline at end of file diff --git a/SofaImGui/src/SofaImGui/windows/viewMouseManager.h b/SofaImGui/src/SofaImGui/windows/viewMouseManager.h new file mode 100644 index 0000000000..92a1401796 --- /dev/null +++ b/SofaImGui/src/SofaImGui/windows/viewMouseManager.h @@ -0,0 +1,31 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the Free * +* Software Foundation; either version 2 of the License, or (at your option) * +* any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include "SofaImGui/ImGuiGUIEngine.h" +#include "WindowState.h" + +using namespace sofaimgui; +namespace windows +{ + void showMainWindow(const char* const&windowNameMouseManager,WindowState &winManagerMouse) ; + +} // namespace sofaimgui From 1e6a3dc60be0eb2d10b6d3906e9dc342e69cfffa Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Thu, 8 Aug 2024 15:44:05 +0200 Subject: [PATCH 39/41] update --- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 63 ++++++++++++++++++- SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h | 7 +++ .../SofaImGui/windows/viewMouseManager.cpp | 3 + 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index df44b85895..c94d00739d 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -51,7 +51,7 @@ namespace sofaglfw void SofaGLFWMouseManager::setPickHandler(PickHandler *picker) { pickHandler=picker; - + updateContent(); updateOperation(LEFT, "Attach"); updateOperation(MIDDLE, "Incise"); updateOperation(RIGHT, "Remove"); @@ -64,5 +64,66 @@ namespace sofaglfw pickHandler->changeOperation(button, id); } } + #include +#include + +// Assuming that updateOperation, pickHandler, mapIndexOperation, and usedOperations are class members. + +void SofaGLFWMouseManager::updateContent() { + // Get the registry + const OperationFactory::RegisterStorage ®istry = OperationFactory::getInstance()->registry; + + // Start of the function + std::cout << "updateContent() called." << std::endl; + std::cout << "Registry size: " << registry.size() << std::endl; + + // Print contents of usedOperations + std::cout << "usedOperations: " << std::endl; + for (int i = 0; i < sofa::gui::common::NONE; ++i) { + std::cout << "usedOperations[" << i << "]: " << usedOperations[i] << std::endl; + } + + // Print pickHandler details + std::cout << "pickHandler address: " << pickHandler << std::endl; + if (pickHandler != nullptr) { + std::cout << "pickHandler type: " << typeid(*pickHandler).name() << std::endl; + } else { + std::cout << "pickHandler is nullptr." << std::endl; + } + + int idx = 0; + for (OperationFactory::RegisterStorage::const_iterator it = registry.begin(); it != registry.end(); ++it) { + // Print each operation's description + std::cout << "Operation " << idx << " ID: " << it->first << std::endl; + std::cout << "Operation Description: " << OperationFactory::GetDescription(it->first) << std::endl; + + // Debug comparisons with usedOperations + std::cout << "Comparing with LEFT: " << OperationFactory::GetDescription(usedOperations[LEFT]) << std::endl; + std::cout << "Comparing with MIDDLE: " << OperationFactory::GetDescription(usedOperations[MIDDLE]) << std::endl; + std::cout << "Comparing with RIGHT: " << OperationFactory::GetDescription(usedOperations[RIGHT]) << std::endl; + + // Check each operation + if (OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[LEFT])) { + std::cout << "Matched LEFT operation" << std::endl; + } + if (OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[MIDDLE])) { + std::cout << "Matched MIDDLE operation" << std::endl; + } + if (OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[RIGHT])) { + std::cout << "Matched RIGHT operation" << std::endl; + } + + // Insert into map + mapIndexOperation.insert(std::make_pair(idx++, it->first)); + std::cout << "Inserted into mapIndexOperation: " << idx-1 << " -> " << it->first << std::endl; + } + + // Print final mapIndexOperation contents + std::cout << "Final mapIndexOperation contents:" << std::endl; + for (const auto& entry : mapIndexOperation) { + std::cout << "Index: " << entry.first << " -> Operation ID: " << entry.second << std::endl; + } +} + }// namespace sofaglfw \ No newline at end of file diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h index 99a0a67503..c6f138516b 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.h @@ -23,6 +23,8 @@ #include #include #include +#include +#include using namespace sofa::gui::common; @@ -38,6 +40,11 @@ class SOFAGLFW_API SofaGLFWMouseManager private: void updateOperation(MOUSE_BUTTON button, const std::string& id); + + void updateContent(); + std::map< int, std::string > mapIndexOperation; + sofa::type::fixed_array< std::string, sofa::gui::common::NONE > usedOperations; + PickHandler* pickHandler; }; diff --git a/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp b/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp index 7eed294f5c..140e4e734e 100644 --- a/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp +++ b/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp @@ -47,6 +47,9 @@ namespace windows { ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 1.0f, 5.0f); ImGui::EndGroup(); ImGui::End(); + + } } + } \ No newline at end of file From c053db7d11a2f1930d3a78eebd1b2a1636e8265c Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 9 Aug 2024 15:12:35 +0200 Subject: [PATCH 40/41] update --- .../src/SofaGLFW/SofaGLFWMouseManager.cpp | 63 +++---------------- .../SofaImGui/windows/viewMouseManager.cpp | 9 ++- 2 files changed, 14 insertions(+), 58 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp index c94d00739d..b1c4709037 100644 --- a/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp +++ b/SofaGLFW/src/SofaGLFW/SofaGLFWMouseManager.cpp @@ -64,66 +64,19 @@ namespace sofaglfw pickHandler->changeOperation(button, id); } } - #include -#include -// Assuming that updateOperation, pickHandler, mapIndexOperation, and usedOperations are class members. + void SofaGLFWMouseManager::updateContent() { + const OperationFactory::RegisterStorage ®istry = OperationFactory::getInstance()->registry; -void SofaGLFWMouseManager::updateContent() { - // Get the registry - const OperationFactory::RegisterStorage ®istry = OperationFactory::getInstance()->registry; + int idx = 0; + for (OperationFactory::RegisterStorage::const_iterator it = registry.begin(); it != registry.end(); ++it) { - // Start of the function - std::cout << "updateContent() called." << std::endl; - std::cout << "Registry size: " << registry.size() << std::endl; - - // Print contents of usedOperations - std::cout << "usedOperations: " << std::endl; - for (int i = 0; i < sofa::gui::common::NONE; ++i) { - std::cout << "usedOperations[" << i << "]: " << usedOperations[i] << std::endl; - } - - // Print pickHandler details - std::cout << "pickHandler address: " << pickHandler << std::endl; - if (pickHandler != nullptr) { - std::cout << "pickHandler type: " << typeid(*pickHandler).name() << std::endl; - } else { - std::cout << "pickHandler is nullptr." << std::endl; - } - - int idx = 0; - for (OperationFactory::RegisterStorage::const_iterator it = registry.begin(); it != registry.end(); ++it) { - // Print each operation's description - std::cout << "Operation " << idx << " ID: " << it->first << std::endl; - std::cout << "Operation Description: " << OperationFactory::GetDescription(it->first) << std::endl; - - // Debug comparisons with usedOperations - std::cout << "Comparing with LEFT: " << OperationFactory::GetDescription(usedOperations[LEFT]) << std::endl; - std::cout << "Comparing with MIDDLE: " << OperationFactory::GetDescription(usedOperations[MIDDLE]) << std::endl; - std::cout << "Comparing with RIGHT: " << OperationFactory::GetDescription(usedOperations[RIGHT]) << std::endl; - - // Check each operation - if (OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[LEFT])) { - std::cout << "Matched LEFT operation" << std::endl; - } - if (OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[MIDDLE])) { - std::cout << "Matched MIDDLE operation" << std::endl; - } - if (OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[RIGHT])) { - std::cout << "Matched RIGHT operation" << std::endl; + OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[LEFT]) ; + OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[MIDDLE]); + OperationFactory::GetDescription(it->first) == OperationFactory::GetDescription(usedOperations[RIGHT]); + mapIndexOperation.insert(std::make_pair(idx++, it->first)); } - - // Insert into map - mapIndexOperation.insert(std::make_pair(idx++, it->first)); - std::cout << "Inserted into mapIndexOperation: " << idx-1 << " -> " << it->first << std::endl; - } - - // Print final mapIndexOperation contents - std::cout << "Final mapIndexOperation contents:" << std::endl; - for (const auto& entry : mapIndexOperation) { - std::cout << "Index: " << entry.first << " -> Operation ID: " << entry.second << std::endl; } -} }// namespace sofaglfw \ No newline at end of file diff --git a/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp b/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp index 140e4e734e..dea618d4a1 100644 --- a/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp +++ b/SofaImGui/src/SofaImGui/windows/viewMouseManager.cpp @@ -38,13 +38,16 @@ namespace windows { ImGui::Begin(windowNameMouseManager, winManagerMouse.getStatePtr()); ImGui::Text("Left Button"); ImGui::BeginGroup(); - const char* operations[] = {"Attach", "Fix", "Incise"}; + + ///todo: get operations descriptions from SofaGlFWMouseManager (update content) + + const char* operations[] = {"Attach an object to the Mouse using a spring force field"}; ImGui::Combo("Operation", &selectedOperation, operations, IM_ARRAYSIZE(operations)); - ImGui::Text("Attach Operation"); ImGui::SliderFloat("Stiffness", &settings.stiffness, 0.0f, 1000.0f); - ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 0.0f); + ImGui::SliderFloat("Arrow Size", &settings.arrowSize, 0.0f, 10.0f); ImGui::SliderFloat("Show Factor Size", &settings.showFactorSize, 1.0f, 5.0f); + ImGui::EndGroup(); ImGui::End(); From c98866a000ce32e5ac8ee4e44a26e8fb8f0d0f6e Mon Sep 17 00:00:00 2001 From: lamriaimen Date: Fri, 9 Aug 2024 15:28:18 +0200 Subject: [PATCH 41/41] update --- SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index fd067907da..4621741db9 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -96,7 +96,7 @@ ImGuiGUIEngine::ImGuiGUIEngine() winManagerSettings(helper::system::FileSystem::append(sofaimgui::getConfigurationFolderPath(), std::string("settings.txt"))), winManagerViewPort(helper::system::FileSystem::append(sofaimgui::getConfigurationFolderPath(), std::string("viewport.txt"))), firstRunState(helper::system::FileSystem::append(sofaimgui::getConfigurationFolderPath(), std::string("firstrun.txt"))), - winManagerMouse("mousemanager.txt") + winManagerMouse(helper::system::FileSystem::append(sofaimgui::getConfigurationFolderPath(), std::string("mousemanager.txt"))) { } @@ -252,7 +252,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI) static constexpr auto windowNameComponents = ICON_FA_LIST " Components"; static constexpr auto windowNameLog = ICON_FA_TERMINAL " Log"; static constexpr auto windowNameSettings = ICON_FA_SLIDERS_H " Settings"; - static constexpr auto windowNameMouseManager = ICON_FA_MOUSE " MouseManager"; + static constexpr auto windowNameMouseManager = ICON_FA_MOUSE_POINTER " MouseManager"; if (!*firstRunState.getStatePtr()) {