16#include "../NodeGraphShared/BehaviorTreeGraphAdapter.h"
17#include "../AI/AIGraphPlugin_BT/BTNodePalette.h"
18#include "../AI/BehaviorTree.h"
19#include "../DataManager.h"
20#include "../third_party/imgui/imgui.h"
21#include "../system/system_utils.h"
31 , m_canvasPanelWidth(0.75f)
32 , m_rightPanelTabSelection(0)
35 m_palette = std::make_unique<AI::BTNodePalette>();
71 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Failed to create new BehaviorTree graph\n";
76 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Created new BehaviorTree graph: '" << name
105 ImGui::SetCursorPosX(10.0f);
106 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5.0f);
108 if (ImGui::Button(
"Run Graph",
ImVec2(100, 0)))
114 ImGui::Text(
"(Ctrl+Shift+R to run)");
119 float totalWidth = ImGui::GetContentRegionAvail().x;
141 if (ImGui::IsItemHovered())
149 ImGui::PopStyleColor(3);
167 if (ImGui::BeginDragDropTarget())
175 ImGui::EndDragDropTarget();
187 if (ImGui::BeginTabItem(
"Palette"))
198 if (ImGui::BeginTabItem(
"Properties"))
237 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Failed to load graph: " << path <<
"\n";
244 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Loaded BT graph: " << path
259 if (
ok && !path.empty())
275 return "BehaviorTree";
288 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Cannot drop node: no active graph\n";
295 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Cannot drop node: graph not found (id=" <<
m_graphId <<
")\n";
321 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Created node from drop: type=" << nodeType
329 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Failed to create node from drop: type=" << nodeType <<
"\n";
353 graph->CopyNodesToClipboard(nodeIds);
361 if (!
graph->m_clipboardData.empty())
396 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Cannot run simulation: no active graph\n";
403 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Cannot run simulation: graph not found (id=" <<
m_graphId <<
")\n";
407 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Starting BehaviorTree simulation for: " <<
graph->
name <<
"\n";
431 SYSTEM_LOG <<
"[BehaviorTreeRenderer] WARNING: No Root node found in graph. Using ID 0 as fallback.\n";
447 for (
int childId :
gNode->childIds)
469 btNode.stringParams[
"actionType"] =
gNode->actionType;
502 SYSTEM_LOG <<
"[BehaviorTreeRenderer] Converted NodeGraph to BehaviorTreeAsset: "
503 <<
btAsset.nodes.size() <<
" nodes\n";
513 SYSTEM_LOG <<
"[BehaviorTreeRenderer] BehaviorTree execution completed with status: "
529 SYSTEM_LOG <<
"[BehaviorTreeRenderer] BehaviorTree simulation completed successfully\n";
Native BehaviorTree execution for simulation and tracing.
IGraphRenderer adapter for BehaviorTree graphs (wraps BTNodeGraphManager).
BTStatus
Behavior tree node execution status.
@ Success
Node completed successfully.
@ Action
Leaf node - performs an action.
@ Selector
OR node - succeeds if any child succeeds.
@ OnEvent
Phase 38b: OnEvent root - event-driven entry point (orange, event-triggered)
@ Sequence
AND node - succeeds if all children succeed.
@ Inverter
Decorator - inverts child result.
@ Condition
Leaf node - checks a condition.
@ Repeater
Decorator - repeats child N times.
@ Root
Phase 38b: Root node - entry point of behavior tree (green, fixed position)
ComponentTypeID GetComponentTypeID_Static()
Panel for executing and testing blueprint graphs with simulation.
Graph execution tracing for simulation and validation.
static DataManager & Get()
void RenderFilePickerModal()
Renders the file picker modal if one is open.
void Render()
Render the property panel.
void ClearSelection()
Clear the current selection.
bool HasSelectedNode() const
Check if a node is currently selected.
void SetSelectedNode(int graphId, int nodeId)
Set the currently selected node ID.
void Initialize()
Initialize the panel.
Executes a BehaviorTree and collects trace information.
BTStatus ExecuteTree(const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a BehaviorTree and collect trace information.
void SetCanvasStateJSON(const std::string &json) override
Restore canvas state from JSON string.
struct Olympe::BehaviorTreeRenderer::CanvasState m_savedCanvasState
std::string m_filePath
Path that was loaded.
void RenderLayoutWithTabs()
std::string GetGraphType() const override
Returns the graph type string, e.g.
bool CreateNew(const std::string &name="Untitled BehaviorTree")
Create a new empty BehaviorTree graph and set it active.
float m_canvasPanelWidth
Split ratio: 75% canvas, 25% right panel.
BehaviorTreeRenderer(NodeGraphPanel &panel)
std::unique_ptr< GraphExecutionTracer > m_lastTracer
Last simulation trace for results display.
int m_graphId
ID in BTNodeGraphManager; -1 if not loaded.
std::unique_ptr< AI::BTNodePalette > m_palette
BTNodePalette for drag-drop.
void Render() override
Renders the graph canvas into the current ImGui child window.
void AcceptNodeDrop(const std::string &nodeType, float screenX, float screenY)
Handle drop of node type at screen position.
void OnRunGraphClicked()
Run graph simulation via BehaviorTreeGraphAdapter + GraphExecutionSimulator Converts BT to graph form...
void RestoreCanvasState() override
Restore previously saved canvas viewport state Called when tab is reactivated.
NodeGraphPanel & m_panel
Shared panel reference (not owned)
BTNodePropertyPanel m_propertyPanel
Property editor for node properties.
void SaveCanvasState() override
Save the current canvas viewport state (pan, zoom, etc.) Called when tab is deactivated.
std::string GetCurrentPath() const override
Returns the last path successfully loaded/saved, or empty string.
std::string GetCanvasStateJSON() const override
Get canvas state as JSON string for persistence.
bool Save(const std::string &path) override
Saves the current graph state to disk.
bool IsDirty() const override
Returns true when the graph has unsaved changes.
std::unique_ptr< ExecutionTestPanel > m_executionTestPanel
REUSED: Simulation results panel.
ImVec2 m_canvasScreenPos
Screen position of canvas for drag-drop coordinate transformation.
void HandleKeyboardShortcuts()
Handle keyboard shortcuts for copy/paste/duplicate operations Ctrl+C: Copy selected node Ctrl+V: Past...
bool Load(const std::string &path) override
Loads a graph from a file on disk.
void RenderRightPanelTabs()
Records execution trace during graph simulation.
bool CloseGraph(int graphId)
int LoadGraph(const std::string &filepath)
void SetActiveGraph(int graphId)
NodeGraph * GetGraph(int graphId)
int CreateGraph(const std::string &name, const std::string &type)
bool SaveGraph(int graphId, const std::string &filepath)
static NodeGraphManager & Get()
NodeGraphPanel - ImGui/ImNodes panel for node graph editing Provides visual editor for behavior trees...
bool m_SuppressGraphTabs
When true, RenderGraphTabs() is skipped (used by BehaviorTreeRenderer)
< Provides AssetID and INVALID_ASSET_ID
@ BT_OnEvent
Phase 38b: Event-driven root (green, event-triggered)
@ BT_Root
Phase 38b: Root entry point (green, fixed position)
NodeType StringToNodeType(const std::string &str)
Represents a single node in a behavior tree.
uint32_t id
Unique node ID within tree.