Skip to content

Commit

Permalink
search pattern adapted to new tree displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Nov 30, 2024
1 parent 957895e commit c2eab08
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/headers/LogToGraphBuild.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define LogToGraph_Prefix "LogToGraph"
#define LogToGraph_BuildNumber 1038
#define LogToGraph_BuildNumber 1046
#define LogToGraph_MinorNumber 2
#define LogToGraph_MajorNumber 0
#define LogToGraph_BuildId "0.2.1038"
#define LogToGraph_BuildId "0.2.1046"
48 changes: 31 additions & 17 deletions src/models/log/SignalTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,50 @@ void SignalTree::prepare(const std::string& vSearchString) {

for (const auto& signal_cnt : LogEngine::Instance()->GetSignalSeries()) {
prepareRecurs(vSearchString, signal_cnt.first, signal_cnt.second, m_RootItem);
/*const auto& arr = ez::str::splitStringToVector(item_cat.first, "/");
for (auto& item_name : item_cat.second) {
if (item_name.second) {
if (item_name.second->low_case_name_for_search.find(searchPattern) == std::string::npos) {
continue;
}
m_SignalSeriesOld[item_name.first] = item_name.second;
m_SignalSeries[item_name.first];
}
}*/
}
}

void SignalTree::prepareRecurs(const std::string& vSearchString, const SignalCategory& vCategory, const SignalContainer& vSignals, SignalItem& vSignalItemRef) {
// split category
std::string left_category = vCategory, right_category;
size_t p = left_category.find('/');
if (p != std::string::npos) {
right_category = left_category.substr(p + 1); // right part
left_category = left_category.substr(0, p); // legt part
}

if (vSignalItemRef.childs.find(left_category) == vSignalItemRef.childs.end()) { // we need to insert a item
if (vSignalItemRef.childs.find(left_category) == vSignalItemRef.childs.end()) { // not found, we need to insert a item
vSignalItemRef.childs[left_category];
}

auto& item = vSignalItemRef.childs.at(left_category);
if (!right_category.empty()) { // no leaf, recurs
prepareRecurs(vSearchString, right_category, vSignals, item);
item.count = static_cast<uint32_t>(item.childs.size());

} else { // leaf : add
item.count = static_cast<uint32_t>(vSignals.size());
for (const auto& sig : vSignals) {
item.signals[sig.first] = sig.second;
if (sig.second != nullptr) {
if (vSearchString.empty() || sig.second->low_case_name_for_search.find(vSearchString) != std::string::npos) {
item.signals[sig.first] = sig.second;
}
}
}
}
item.label = ez::str::toStr("%s (%u)", left_category.c_str(), item.count);

// we will remove items with empty childs and empty signals
// can be the case if search pattern filtering blocked some insertions
if (item.isEmpty()) {
vSignalItemRef.childs.erase(left_category);
}
}

void SignalTree::displayTree(bool vCollapseAll, bool vExpandAll) {
displayItemRecurs(m_RootItem);
displayItemRecurs(m_RootItem, vCollapseAll, vExpandAll);
}

void SignalTree::displayItemRecurs(SignalItem& vSignalItemRef) {
void SignalTree::displayItemRecurs(SignalItem& vSignalItemRef, bool vCollapseAll, bool vExpandAll) {
if (vSignalItemRef.isLeaf()) {
for (auto& signal : vSignalItemRef.signals) {
if (!signal.second.expired()) {
Expand All @@ -79,9 +79,23 @@ void SignalTree::displayItemRecurs(SignalItem& vSignalItemRef) {
}
} else { // display categories
for (auto& child : vSignalItemRef.childs) {
if (ImGui::TreeNode(child.second.label.c_str())) {
if (vCollapseAll) {
// can close only the first item for now
// or we need to reach the leaf
// and close from leaf so to do on many frames
// can be anoying for the user
// todo : by the way
ImGui::SetNextItemOpen(false);
}

if (vExpandAll) {
// will open all tree during recursion
ImGui::SetNextItemOpen(true);
}

if (ImGui::TreeNode(&child.second, "%s", child.second.label.c_str())) {
ImGui::Indent();
displayItemRecurs(child.second);
displayItemRecurs(child.second, vCollapseAll, vExpandAll);
ImGui::Unindent();
ImGui::TreePop();
}
Expand Down
3 changes: 2 additions & 1 deletion src/models/log/SignalTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct SignalItem {
SignalContainerWeak signals;
SignalItemContainer childs;
bool isLeaf() const { return childs.empty(); }
bool isEmpty() const { return childs.empty() && signals.empty(); }
void clear() {
signals.clear();
childs.clear();
Expand All @@ -31,5 +32,5 @@ class SignalTree {

private:
void prepareRecurs(const std::string& vSearchString, const SignalCategory& vCategory, const SignalContainer& vSignals, SignalItem& vSignalItemRef);
void displayItemRecurs(SignalItem& vSignalItemRef);
void displayItemRecurs(SignalItem& vSignalItemRef, bool vCollapseAll, bool vExpandAll);
};
16 changes: 7 additions & 9 deletions src/panes/ToolPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,15 @@ void ToolPane::DrawTree() {

const float fw = ImGui::GetContentRegionAvail().x;

if (search_string.empty()) {
const float aw = (fw - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
if (ImGui::ContrastedButton("Collapse All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
_collapse_all = true;
}
const float aw = (fw - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
if (ImGui::ContrastedButton("Collapse All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
_collapse_all = true;
}

ImGui::SameLine();
ImGui::SameLine();

if (ImGui::ContrastedButton("Expand All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
_expand_all = true;
}
if (ImGui::ContrastedButton("Expand All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
_expand_all = true;
}

if (ImGui::ContrastedButton("Hide All Graphs##ToolPane_DrawTree", nullptr, nullptr, fw)) {
Expand Down

0 comments on commit c2eab08

Please sign in to comment.