kanzi运行时节点状态展示

2024-04-03 12:28

本文主要是介绍kanzi运行时节点状态展示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

背景:有时候kanzi运行后节点不显示,可能是visible/opacity等属性设置不正确,排查困难。做一个实时节点树,方便查看节点信息。

1. 引入imgui

在vs工程里导入glad,glfw,imgui代码
vs属性-链接库,增加glfw3.lib
在这里插入图片描述

在这里插入图片描述

2. 实现框架

onProjectLoaded里创建子线程

CreateThread(NULL, 0, multiTask, 0, 0, NULL);

子线程负责创建glfw窗口,刷新,销毁窗口

DWORD WINAPI multiTask(LPVOID p) {FCreateWindow();while (!glfwWindowShouldClose(m_Window)) {Update();}Destory();return 0;
};

2.1 创建窗口

void FCreateWindow() {glfwInit();const char* glsl_version = "#version 130";glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);m_Window = glfwCreateWindow(m_WindowWidth, m_WindowHeight, "Xml", nullptr, nullptr);glfwMakeContextCurrent(m_Window);glfwSwapInterval(1); // Enable vsyncint status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);printf("status-%d\n", status);printf("Vendor-%s\n", glGetString(GL_VENDOR));printf("Renderer-%s\n", glGetString(GL_RENDERER));printf("Version-%s\n", glGetString(GL_VERSION));IMGUI_CHECKVERSION();ImGui::CreateContext();ImGuiIO &io = ImGui::GetIO();(void)io;io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls// io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controlsio.ConfigFlags |= ImGuiConfigFlags_DockingEnable;	// Enable Dockingio.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows// io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;// io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;float fontSize = 18.0f; // *2.0f;io.Fonts->AddFontFromFileTTF(("./font/Alimama_DongFangDaKai_Regular.ttf"), fontSize, NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());io.FontDefault = io.Fonts->AddFontFromFileTTF(("./font/Alimama_DongFangDaKai_Regular.ttf"), fontSize, NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());// Setup Dear ImGui styleImGui::StyleColorsDark();//ImGui::StyleColorsClassic();// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.ImGuiStyle &style = ImGui::GetStyle();if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable){style.WindowRounding = 0.0f;style.Colors[ImGuiCol_WindowBg].w = 1.0f;}// Setup Platform/Renderer bindingsImGui_ImplGlfw_InitForOpenGL(m_Window, true);ImGui_ImplOpenGL3_Init(glsl_version);
};

2.2 刷新

void Update() {glfwPollEvents();//startImGui_ImplOpenGL3_NewFrame();ImGui_ImplGlfw_NewFrame();ImGui::NewFrame();{//  bool show_demo_window = true;// ImGui::ShowDemoWindow(&show_demo_window);ImGui::Begin("Project");if (g_pApplication) {ShowProjectTreeTop();}ImGui::End();bool show_demo_window = true;ImGui::ShowDemoWindow(&show_demo_window);}//endImGuiIO &io = ImGui::GetIO();ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);// RenderingImGui::Render();int display_w, display_h;glfwGetFramebufferSize(m_Window, &display_w, &display_h);glViewport(0, 0, display_w, display_h);glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);glClear(GL_COLOR_BUFFER_BIT);ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());io.DisplaySize = ImVec2(display_w, display_h);if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable){GLFWwindow *backup_current_context = glfwGetCurrentContext();ImGui::UpdatePlatformWindows();ImGui::RenderPlatformWindowsDefault();glfwMakeContextCurrent(backup_current_context);}glfwSwapBuffers(m_Window);};

2.3 销毁窗口

void Destory() {ImGui_ImplOpenGL3_Shutdown();ImGui_ImplGlfw_Shutdown();ImGui::DestroyContext();glfwDestroyWindow(m_Window);glfwTerminate();
};

3. 实现功能逻辑

遍历kanzi运行时节点,用tree展示

void ShowProjectTreeTop()
{static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen;static bool align_label_with_current_x_position = false;static bool test_drag_and_drop = true;if (align_label_with_current_x_position)ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing());static int selection_mask = 0;int node_clicked = -1;ImGuiTreeNodeFlags node_flags = base_flags;const bool is_selected = (selection_mask & (1 << 0)) != 0;shared_ptr<Node> node = dynamic_pointer_cast<Node>(g_pApplication->getRoot());if (is_selected && node.get() == g_CurrentNode)node_flags |= ImGuiTreeNodeFlags_Selected;bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)0, node_flags, node->getName().c_str(), 0);if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) {node_clicked = 0;g_CurrentNode = node.get();}if (node_open){ShowProjectTree(node);ImGui::TreePop();}if (node_clicked != -1){// Update selection state// (process outside of tree loop to avoid visual inconsistencies during the clicking frame)if (ImGui::GetIO().KeyCtrl)selection_mask ^= (1 << node_clicked);          // CTRL+click to toggleelse //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, may want to preserve selection when clicking on item that is part of the selectionselection_mask = (1 << node_clicked);           // Click to single-select}if (align_label_with_current_x_position)ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing());}void ShowProjectTree(shared_ptr<Node>& node)
{static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen;static bool align_label_with_current_x_position = false;static bool test_drag_and_drop = false;if (align_label_with_current_x_position)ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing());static int selection_mask = 0;int node_clicked = -1;size_t size = node->getAbstractChildCountOverride();for (unsigned int i = 0; i < size; ++i){shared_ptr<Node> object = dynamic_pointer_cast<Node>(node->getAbstractChildOverride(i));// Disable the default "open on single-click behavior" + set Selected flag according to our selection.// To alter selection we use IsItemClicked() && !IsItemToggledOpen(), so clicking on an arrow doesn't alter selection.ImGuiTreeNodeFlags node_flags = base_flags;const bool is_selected = (selection_mask & (1 << i)) != 0;if (is_selected && object.get() == g_CurrentNode)node_flags |= ImGuiTreeNodeFlags_Selected;std::string name = object->getName();if (object->getProperty(Node::VisibleProperty)) {}else {name += " NoVisible";node_flags |= ImGuiTreeNodeFlags_TextDisabled;}if (object->getProperty(Node::OpacityProperty)) {}else {//ImGui::TextDisabled("NoVisible");name += " NoOpacity";node_flags |= ImGuiTreeNodeFlags_TextDisabled;}bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, (char *)name.c_str(), i);if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) {node_clicked = i;g_CurrentNode = object.get();}if (node_open){if (object->getAbstractChildCountOverride() > 0){ShowProjectTree(object);}else {Viewport2DSharedPtr v2d = dynamic_pointer_cast<Viewport2D>(object);if (v2d) {//Viewport2D                SceneSharedPtr sc = v2d->getScene();if (sc->getChildCount() > 0){shared_ptr<Node3D> node = dynamic_pointer_cast<Node3D>(sc);ShowProjectTree3D(node);}}}ImGui::TreePop();}}if (node_clicked != -1){// Update selection state// (process outside of tree loop to avoid visual inconsistencies during the clicking frame)if (ImGui::GetIO().KeyCtrl)selection_mask ^= (1 << node_clicked);          // CTRL+click to toggleelse //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, may want to preserve selection when clicking on item that is part of the selectionselection_mask = (1 << node_clicked);           // Click to single-select}if (align_label_with_current_x_position)ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing());
}void ShowProjectTree3D(shared_ptr<Node3D>& node)
{static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen;static bool align_label_with_current_x_position = false;static bool test_drag_and_drop = false;if (align_label_with_current_x_position)ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing());static int selection_mask = 0;int node_clicked = -1;size_t size = node->getChildCount();for (unsigned int i = 0; i < size; ++i){Node3DSharedPtr object = node->getChild(i);// Disable the default "open on single-click behavior" + set Selected flag according to our selection.// To alter selection we use IsItemClicked() && !IsItemToggledOpen(), so clicking on an arrow doesn't alter selection.ImGuiTreeNodeFlags node_flags = base_flags;const bool is_selected = (selection_mask & (1 << i)) != 0;if (is_selected && object.get() == g_CurrentNode)node_flags |= ImGuiTreeNodeFlags_Selected;std::string name = object->getName();if (object->getProperty(Node::VisibleProperty)) {}else {name += " NoVisible";node_flags |= ImGuiTreeNodeFlags_TextDisabled;}if (object->getProperty(Node::OpacityProperty)) {}else {//ImGui::TextDisabled("NoVisible");name += " NoOpacity";node_flags |= ImGuiTreeNodeFlags_TextDisabled;}bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, (char *)name.c_str(), i);if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) {node_clicked = i;g_CurrentNode = object.get();}if (node_open){if (object->getChildCount() > 0){ShowProjectTree3D(object);}ImGui::TreePop();}}if (node_clicked != -1){// Update selection state// (process outside of tree loop to avoid visual inconsistencies during the clicking frame)if (ImGui::GetIO().KeyCtrl)selection_mask ^= (1 << node_clicked);          // CTRL+click to toggleelse //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, may want to preserve selection when clicking on item that is part of the selectionselection_mask = (1 << node_clicked);           // Click to single-select}if (align_label_with_current_x_position)ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing());
}

4. 效果

运行kanzi程序后,会额外出来一个窗口,实时显示所有节点信息

在这里插入图片描述
节点无效置灰请参考 imgui tree节点无效置灰实现方案

5. 拓展

将来可以根据点击某一个节点,展示属性窗口。

这篇关于kanzi运行时节点状态展示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/872916

相关文章

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

如何用Docker运行Django项目

本章教程,介绍如何用Docker创建一个Django,并运行能够访问。 一、拉取镜像 这里我们使用python3.11版本的docker镜像 docker pull python:3.11 二、运行容器 这里我们将容器内部的8080端口,映射到宿主机的80端口上。 docker run -itd --name python311 -p

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

hdu1565(状态压缩)

本人第一道ac的状态压缩dp,这题的数据非常水,很容易过 题意:在n*n的矩阵中选数字使得不存在任意两个数字相邻,求最大值 解题思路: 一、因为在1<<20中有很多状态是无效的,所以第一步是选择有效状态,存到cnt[]数组中 二、dp[i][j]表示到第i行的状态cnt[j]所能得到的最大值,状态转移方程dp[i][j] = max(dp[i][j],dp[i-1][k]) ,其中k满足c

day-51 合并零之间的节点

思路 直接遍历链表即可,遇到val=0跳过,val非零则加在一起,最后返回即可 解题过程 返回链表可以有头结点,方便插入,返回head.next Code /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}*

状态dp总结

zoj 3631  N 个数中选若干数和(只能选一次)<=M 的最大值 const int Max_N = 38 ;int a[1<<16] , b[1<<16] , x[Max_N] , e[Max_N] ;void GetNum(int g[] , int n , int s[] , int &m){ int i , j , t ;m = 0 ;for(i = 0 ;

hdu3006状态dp

给你n个集合。集合中均为数字且数字的范围在[1,m]内。m<=14。现在问用这些集合能组成多少个集合自己本身也算。 import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.Inp

跨系统环境下LabVIEW程序稳定运行

在LabVIEW开发中,不同电脑的配置和操作系统(如Win11与Win7)可能对程序的稳定运行产生影响。为了确保程序在不同平台上都能正常且稳定运行,需要从兼容性、驱动、以及性能优化等多个方面入手。本文将详细介绍如何在不同系统环境下,使LabVIEW开发的程序保持稳定运行的有效策略。 LabVIEW版本兼容性 LabVIEW各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

实例:如何统计当前主机的连接状态和连接数

统计当前主机的连接状态和连接数 在 Linux 中,可使用 ss 命令来查看主机的网络连接状态。以下是统计当前主机连接状态和连接主机数量的具体操作。 1. 统计当前主机的连接状态 使用 ss 命令结合 grep、cut、sort 和 uniq 命令来统计当前主机的 TCP 连接状态。 ss -nta | grep -v '^State' | cut -d " " -f 1 | sort |