From 1a0c9297246b5af5e21be3b769aaf5de867e1ea9 Mon Sep 17 00:00:00 2001 From: Andrea Settimi Date: Fri, 16 Aug 2024 17:05:20 +0200 Subject: [PATCH 1/3] Feat: Hide TTool when collapsing the TTool panel --- src/AIAC/LayerUI.cpp | 21 ++++++++++++++------- src/AIAC/LayerUI.h | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/AIAC/LayerUI.cpp b/src/AIAC/LayerUI.cpp index 1ae0c069c..b82920f08 100644 --- a/src/AIAC/LayerUI.cpp +++ b/src/AIAC/LayerUI.cpp @@ -117,12 +117,12 @@ namespace AIAC m_LogoLightClr = AIAC::Image(AIAC_LOGO_COLOR); // Set panes UI for layers - // Label Collapse PaneContent - StackPane(PaneUI("Camera", false, AIAC_BIND_EVENT_FN(SetPaneUICamera) )); - StackPane(PaneUI("Mapping", false, AIAC_BIND_EVENT_FN(SetPaneUISlam) )); - StackPane(PaneUI("ACIM (Execution model)", false, AIAC_BIND_EVENT_FN(SetPaneUIACIM) )); - StackPane(PaneUI("Toolhead", false, AIAC_BIND_EVENT_FN(SetPaneUIToolhead) )); - StackPane(PaneUI("Utils", false, AIAC_BIND_EVENT_FN(SetPaneUIUtils) )); + // Label Collapse PaneContent + StackPane(PaneUI("Camera", false, AIAC_BIND_EVENT_FN(SetPaneUICamera) )); + StackPane(PaneUI("Mapping", false, AIAC_BIND_EVENT_FN(SetPaneUISlam) )); + StackPane(PaneUI("ACIM (Execution model)", false, AIAC_BIND_EVENT_FN(SetPaneUIACIM) )); + StackPane(PaneUI("Toolhead", false, AIAC_BIND_EVENT_FN(SetPaneUIToolhead), AIAC_BIND_EVENT_FN(OnCollapsingPaneUIToolhead))); + StackPane(PaneUI("Utils", false, AIAC_BIND_EVENT_FN(SetPaneUIUtils) )); m_IsOpen = new bool(true); } @@ -203,7 +203,10 @@ namespace AIAC ImGui::Text("This is a prototype for augmented_carpentry \n Version 01.00.00 \n Build 2021-01-01 00:00:00 \n IBOIS, EPFL"); #endif - for (auto& pane : m_PaneUIStack) pane->Show(); + for (auto& pane : m_PaneUIStack) { + pane->Show(); + pane->CheckOnCollapsing(); + } ImGui::End(); } @@ -983,6 +986,10 @@ namespace AIAC ImGui::EndChild(); } + void LayerUI::OnCollapsingPaneUIToolhead(){ + AIAC_APP.GetLayer()->IsShowSilouhette = false; + } + void LayerUI::ShowMappingPopup() { ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y)); diff --git a/src/AIAC/LayerUI.h b/src/AIAC/LayerUI.h index 2a2625dea..abb2fb4a4 100644 --- a/src/AIAC/LayerUI.h +++ b/src/AIAC/LayerUI.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "AIAC/Layer.h" #include "AIAC/Image.h" @@ -16,20 +18,48 @@ namespace AIAC { class PaneUI { public: + enum CollapseState { + OPEN, + ON_COLLAPSING, + COLLAPSE + }; + typedef std::function Func; - PaneUI(const char *label, bool isCollapsed, Func func) - : m_Label(label), m_IsCollapsed(isCollapsed), m_func(std::move(func)) {} + PaneUI(const char *label, bool isCollapsed, Func func, Func onCollapseCallback=[]{}) + : m_Label(label), m_IsCollapsed(isCollapsed), m_func(std::move(func)), m_onCollapseCallback(std::move(onCollapseCallback)) { + if (m_IsCollapsed) m_CollapseState = CollapseState::COLLAPSE; + else m_CollapseState = CollapseState::OPEN; + } template void Show(Args &&... args) { - if (ImGui::CollapsingHeader(m_Label, m_IsCollapsed ? ImGuiTreeNodeFlags_DefaultOpen : 0)) { + bool isOpened = ImGui::CollapsingHeader(m_Label, m_IsCollapsed ? ImGuiTreeNodeFlags_DefaultOpen : 0); + if (isOpened) { + m_CollapseState = CollapseState::OPEN; m_func(std::forward(args)...); } + + // check if it's just collapsed + if (!isOpened) { + if (m_CollapseState == CollapseState::OPEN) { + m_CollapseState = CollapseState::ON_COLLAPSING; + } + } + } + + template + void CheckOnCollapsing(Args &&... args) { + if (m_CollapseState == CollapseState::ON_COLLAPSING) { + m_onCollapseCallback(); + m_CollapseState = CollapseState::COLLAPSE; + } } private: + CollapseState m_CollapseState; Func m_func; + Func m_onCollapseCallback; const char *m_Label; bool m_IsCollapsed; }; @@ -69,6 +99,7 @@ namespace AIAC { void SetPaneUICamera(); void SetPaneUISlam(); void SetPaneUIToolhead(); + void OnCollapsingPaneUIToolhead(); void SetPaneUIACIM(); void SetPaneUIUtils(); From d165c0e5e1c423c00002b075d4bcc47597fc4a97 Mon Sep 17 00:00:00 2001 From: Andrea Settimi Date: Mon, 19 Aug 2024 10:28:24 +0200 Subject: [PATCH 2/3] Fix: cotas visibility --- src/AIAC/ACInfoModel.cpp | 15 +++++++++++---- src/AIAC/ACInfoModel.h | 2 +- src/AIAC/LayerUI.cpp | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/AIAC/ACInfoModel.cpp b/src/AIAC/ACInfoModel.cpp index bb557cc7b..7142032e1 100644 --- a/src/AIAC/ACInfoModel.cpp +++ b/src/AIAC/ACInfoModel.cpp @@ -304,13 +304,20 @@ namespace AIAC cut->SetVisibilityAllCotas(true); } } + this->IsShowingAllComponents = true; } - void TimberInfo::SetAllCotasVisibility(bool visible) + void TimberInfo::UpdateCotasVisibility(bool visible) { - this->IsShowingCotas = visible; - for (const auto& [_, component] : m_Components) { - if(auto cut = dynamic_cast(component)){ + if (!visible || IsShowingAllComponents) { + this->IsShowingCotas = visible; + for (const auto& [_, component] : m_Components) { + if(auto cut = dynamic_cast(component)){ + cut->SetVisibilityAllCotas(visible); + } + } + } else { + if(auto cut = dynamic_cast(this->GetCurrentComponent())){ cut->SetVisibilityAllCotas(visible); } } diff --git a/src/AIAC/ACInfoModel.h b/src/AIAC/ACInfoModel.h index 2322ec4a7..8f4d7fff5 100644 --- a/src/AIAC/ACInfoModel.h +++ b/src/AIAC/ACInfoModel.h @@ -293,7 +293,7 @@ class TimberInfo{ void HideAllComponentsExceptCurrent(); void ShowAllComponents(); - void SetAllCotasVisibility(bool visible); + void UpdateCotasVisibility(bool visible); public: ///< small utilities to calculate the progress of fabrication /// @brief Get the number of fabricate components diff --git a/src/AIAC/LayerUI.cpp b/src/AIAC/LayerUI.cpp index b82920f08..ff02bd269 100644 --- a/src/AIAC/LayerUI.cpp +++ b/src/AIAC/LayerUI.cpp @@ -615,9 +615,9 @@ namespace AIAC ImGui::SameLine(); if(ImGui::Checkbox("Show Cotas", &AIAC_APP.GetLayer()->GetACInfoModel().GetTimberInfo().IsShowingCotas)){ if(AIAC_APP.GetLayer()->GetACInfoModel().GetTimberInfo().IsShowingCotas){ - AIAC_APP.GetLayer()->GetACInfoModel().GetTimberInfo().SetAllCotasVisibility(true); + AIAC_APP.GetLayer()->GetACInfoModel().GetTimberInfo().UpdateCotasVisibility(true); } else { - AIAC_APP.GetLayer()->GetACInfoModel().GetTimberInfo().SetAllCotasVisibility(false); + AIAC_APP.GetLayer()->GetACInfoModel().GetTimberInfo().UpdateCotasVisibility(false); } } From 3290524599f6c54ba889abc28f2472b7381a940c Mon Sep 17 00:00:00 2001 From: Andrea Settimi Date: Mon, 19 Aug 2024 17:52:05 +0200 Subject: [PATCH 3/3] Feat: auto collapse panel --- src/AIAC/LayerUI.cpp | 49 ++++++++++++++++++++++++++++++++++++-------- src/AIAC/LayerUI.h | 29 +++++++------------------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/AIAC/LayerUI.cpp b/src/AIAC/LayerUI.cpp index c6b88646e..db90c9110 100644 --- a/src/AIAC/LayerUI.cpp +++ b/src/AIAC/LayerUI.cpp @@ -117,12 +117,12 @@ namespace AIAC m_LogoLightClr = AIAC::Image(AIAC_LOGO_COLOR); // Set panes UI for layers - // Label Collapse PaneContent - StackPane(PaneUI("Camera", false, AIAC_BIND_EVENT_FN(SetPaneUICamera) )); - StackPane(PaneUI("Mapping", false, AIAC_BIND_EVENT_FN(SetPaneUISlam) )); - StackPane(PaneUI("ACIM (Execution model)", false, AIAC_BIND_EVENT_FN(SetPaneUIACIM) )); - StackPane(PaneUI("Toolhead", false, AIAC_BIND_EVENT_FN(SetPaneUIToolhead), AIAC_BIND_EVENT_FN(OnCollapsingPaneUIToolhead))); - StackPane(PaneUI("Utils", false, AIAC_BIND_EVENT_FN(SetPaneUIUtils) )); + // Label Collapse PaneContent + StackPane(PaneUI("Camera", false, AIAC_BIND_EVENT_FN(SetPaneUICamera) )); + StackPane(PaneUI("Mapping", false, AIAC_BIND_EVENT_FN(SetPaneUISlam) )); + StackPane(PaneUI("ACIM (Execution model)", false, AIAC_BIND_EVENT_FN(SetPaneUIACIM) )); + StackPane(PaneUI("Toolhead", false, AIAC_BIND_EVENT_FN(SetPaneUIToolhead), AIAC_BIND_EVENT_FN(OnCollapsingPaneUIToolhead))); + StackPane(PaneUI("Utils", false, AIAC_BIND_EVENT_FN(SetPaneUIUtils) )); m_IsOpen = new bool(true); } @@ -174,6 +174,39 @@ namespace AIAC ImGui::DestroyContext(); } + template + void PaneUI::Show(Args &&... args) { + bool isOpened = ImGui::CollapsingHeader(m_Label, m_IsCollapsed ? ImGuiTreeNodeFlags_DefaultOpen : 0); + if (isOpened) { + // if this one is not opened yet, close the previously opened one + if (m_CollapseState != CollapseState::OPEN) { + auto lastOpenedPaneUI = AIAC_APP.GetLayer()->GetOpenedPaneUI(); + if (lastOpenedPaneUI != nullptr && lastOpenedPaneUI->m_Label != m_Label) { + ImGui::GetStateStorage()->SetInt(ImGui::GetID(lastOpenedPaneUI->m_Label), 0); + lastOpenedPaneUI->Show(); + } + AIAC_APP.GetLayer()->SetOpenedPaneUI(this); + } + m_CollapseState = CollapseState::OPEN; + m_func(std::forward(args)...); + } + + // check if it's just collapsed + if (!isOpened) { + if (m_CollapseState == CollapseState::OPEN) { + m_CollapseState = CollapseState::ON_COLLAPSING; + } + } + } + + template + void PaneUI::CheckOnCollapsing(Args &&... args) { + if (m_CollapseState == CollapseState::ON_COLLAPSING) { + m_onCollapseCallback(std::forward(args)...); + m_CollapseState = CollapseState::COLLAPSE; + } + } + void LayerUI::ShowMenuBar() { if (ImGui::BeginMainMenuBar()) @@ -204,8 +237,8 @@ namespace AIAC #endif for (auto& pane : m_PaneUIStack) { - pane->Show(); - pane->CheckOnCollapsing(); + pane.Show(); + pane.CheckOnCollapsing(); } ImGui::End(); diff --git a/src/AIAC/LayerUI.h b/src/AIAC/LayerUI.h index abb2fb4a4..f8b2d7bcd 100644 --- a/src/AIAC/LayerUI.h +++ b/src/AIAC/LayerUI.h @@ -33,28 +33,10 @@ namespace AIAC { } template - void Show(Args &&... args) { - bool isOpened = ImGui::CollapsingHeader(m_Label, m_IsCollapsed ? ImGuiTreeNodeFlags_DefaultOpen : 0); - if (isOpened) { - m_CollapseState = CollapseState::OPEN; - m_func(std::forward(args)...); - } - - // check if it's just collapsed - if (!isOpened) { - if (m_CollapseState == CollapseState::OPEN) { - m_CollapseState = CollapseState::ON_COLLAPSING; - } - } - } + void Show(Args &&... args); template - void CheckOnCollapsing(Args &&... args) { - if (m_CollapseState == CollapseState::ON_COLLAPSING) { - m_onCollapseCallback(); - m_CollapseState = CollapseState::COLLAPSE; - } - } + void CheckOnCollapsing(Args &&... args); private: CollapseState m_CollapseState; @@ -95,13 +77,15 @@ namespace AIAC { void ShowLogRecorderUI(); - inline void StackPane(PaneUI pane) { m_PaneUIStack.push_back(std::make_shared(pane)); } + inline void StackPane(PaneUI pane) { m_PaneUIStack.emplace_back(std::move(pane)); } void SetPaneUICamera(); void SetPaneUISlam(); void SetPaneUIToolhead(); void OnCollapsingPaneUIToolhead(); void SetPaneUIACIM(); void SetPaneUIUtils(); + PaneUI* GetOpenedPaneUI() { return m_OpenedPaneUI; } + void SetOpenedPaneUI(PaneUI* paneUI) { m_OpenedPaneUI = paneUI; } private: void SetGlobalViewUI(ImVec2 viewportSize); @@ -125,7 +109,8 @@ namespace AIAC { bool *m_IsOpen = nullptr; - std::vector> m_PaneUIStack; + std::vector m_PaneUIStack; + PaneUI* m_OpenedPaneUI = nullptr; // UI File Selection std::string m_FileSelectDefaultPath = ".";