Ember
Loading...
Searching...
No Matches
MonitorTreeCanvas.cpp
Go to the documentation of this file.
3
4namespace Ember {
5namespace Monitor {
6
7MonitorTreeCanvas::MonitorTreeCanvas(wxWindow *parent, wxWindowID id) : EmberUI::TreeCanvas(parent, id) {
9}
10
12 auto &cfg = GetConfig();
13
14 cfg.background_color = wxColour(0x2A, 0x2A, 0x2A);
15 cfg.grid_color = wxColour(0x3E, 0x3E, 0x3E);
16 cfg.grid_size = 20;
17
18 cfg.node_color = wxColour(0x4B, 0x4B, 0x4B);
19 cfg.border_color = wxColour(0x78, 0x78, 0x78);
20 cfg.text_color = wxColour(0xB4, 0xB4, 0xB4);
21 cfg.selected_border_color = wxColour(0x30, 0x5C, 0xDE);
22 cfg.hovered_border_color = wxColour(0x90, 0xEE, 0x90);
23 cfg.connection_color = wxColour(0xFF, 0xFF, 0xFF);
24
25 cfg.action_type_color = wxColour(0x4A, 0x90, 0xD9);
26 cfg.control_type_color = wxColour(0x5C, 0xB8, 0x5C);
27 cfg.condition_type_color = wxColour(0xF0, 0xAD, 0x4E);
28 cfg.decorator_type_color = wxColour(0x9B, 0x59, 0xB6);
29 cfg.behavior_tree_type_color = wxColour(0xD9, 0x53, 0x4F);
30
31 cfg.highlight_path_to_selected = true;
32 cfg.path_highlight_color = wxColour(0x90, 0xEE, 0x90);
33
34 cfg.enable_viewport_culling = true;
35 cfg.viewport_culling_margin = 1500;
36
37 cfg.show_navigation_info = false;
38
39 SetShowGrid(true);
40 SetShowMinimap(true);
42 SetShowOverlayInfo(false);
43}
44
45void MonitorTreeCanvas::SetConnectionInfo(bool connected, int tickCount) {
46 m_connected = connected;
47 m_tickCount = tickCount;
48}
49
50wxColour MonitorTreeCanvas::GetNodeFillColor(EmberCore::ITreeNode *node, bool selected, bool hovered) {
51 auto *statusProvider = GetStatusProvider();
52 if (statusProvider) {
53 int status = statusProvider->GetNodeStatus(static_cast<int64_t>(node->GetId()));
54 if (status != 0)
56 }
57
58 wxColour base = GetConfig().node_color;
59 if (selected) {
60 return wxColour(std::min(255, base.Red() + 20), std::min(255, base.Green() + 20),
61 std::min(255, base.Blue() + 20));
62 }
63 if (hovered) {
64 return wxColour(std::min(255, base.Red() + 10), std::min(255, base.Green() + 10),
65 std::min(255, base.Blue() + 10));
66 }
67 return base;
68}
69
70wxColour MonitorTreeCanvas::GetNodeBorderColor(EmberCore::ITreeNode *node, bool selected, bool hovered) {
71 int64_t nodeId = static_cast<int64_t>(node->GetId());
72 auto *statusProvider = GetStatusProvider();
73
74 if (selected)
76 if (hovered)
78
79 if (statusProvider) {
80 if (statusProvider->IsNodeInExecutionPath(nodeId))
82
83 int status = statusProvider->GetNodeStatus(nodeId);
84 if (status != 0)
86 }
87
88 return GetConfig().border_color;
89}
90
92 auto *statusProvider = GetStatusProvider();
93 if (statusProvider) {
94 int status = statusProvider->GetNodeStatus(static_cast<int64_t>(node->GetId()));
95 if (status != 0)
97 }
98 return GetConfig().text_color;
99}
100
102 dc.SetUserScale(1.0, 1.0);
103 dc.SetDeviceOrigin(0, 0);
104
105 wxSize panelSize = GetSize();
106 int y = 10;
107 int rightX = panelSize.x - 10;
108
109 wxFont infoFont(9, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
110 dc.SetFont(infoFont);
111
112 wxString connText = m_connected ? wxString::Format("Connected | Ticks: %d", m_tickCount) : "Disconnected";
113 wxColour connColor = m_connected ? wxColour(100, 200, 100) : wxColour(200, 100, 100);
114 dc.SetTextForeground(connColor);
115 wxSize connExtent = dc.GetTextExtent(connText);
116 dc.DrawText(connText, rightX - connExtent.x, y);
117 y += connExtent.y + 4;
118
119 dc.SetTextForeground(wxColour(160, 160, 160));
120 wxPoint viewOfs = GetViewOffset();
121 wxString zoomText = wxString::Format("Zoom: %.0f%% | Pan: (%d, %d)", GetZoom() * 100, viewOfs.x, viewOfs.y);
122 if (IsInFocusMode())
123 zoomText += " | FOCUS MODE";
124 wxSize zoomExtent = dc.GetTextExtent(zoomText);
125 dc.DrawText(zoomText, rightX - zoomExtent.x, y);
126 y += zoomExtent.y + 4;
127
128 auto *selectedNode = GetSelectedNode();
129 if (selectedNode) {
130 wxString selText = "Selected: " + selectedNode->GetName() + " [" + selectedNode->GetTypeString() + "]";
131
132 auto *statusProvider = GetStatusProvider();
133 if (statusProvider) {
134 int status = statusProvider->GetNodeStatus(static_cast<int64_t>(selectedNode->GetId()));
135 wxString statusNames[] = {"Idle", "Running", "Success", "Failure", "Halted"};
136 if (status >= 0 && status <= 4)
137 selText += " | " + statusNames[status];
138 }
139
140 dc.SetTextForeground(wxColour(200, 200, 200));
141 wxSize selExtent = dc.GetTextExtent(selText);
142 dc.DrawText(selText, rightX - selExtent.x, y);
143 y += selExtent.y + 4;
144 }
145
146 auto tree = GetTree();
147 if (tree && tree->HasRootNode()) {
148 dc.SetTextForeground(wxColour(130, 130, 130));
149 wxString statsText = wxString::Format("Nodes: %lu", static_cast<unsigned long>(tree->GetNodeCount()));
150 wxSize statsExtent = dc.GetTextExtent(statsText);
151 dc.DrawText(statsText, rightX - statsExtent.x, y);
152 }
153}
154
155} // namespace Monitor
156} // namespace Ember
Abstract interface for tree nodes that can be visualized.
Definition ITreeNode.h:31
virtual size_t GetId() const =0
float GetZoom() const
Returns the current zoom factor.
Definition TreeCanvas.h:120
TreeCanvas(wxWindow *parent, wxWindowID id=wxID_ANY)
Constructor.
void SetShowMinimap(bool show)
Enables or disables minimap display.
Definition TreeCanvas.h:140
IStatusProvider * GetStatusProvider() const
Returns the status overlay provider.
Definition TreeCanvas.h:99
void SetShowOverlayInfo(bool show)
Enables or disables overlay info display.
Definition TreeCanvas.h:138
void SetShowBreadcrumb(bool show)
Enables or disables breadcrumb display.
Definition TreeCanvas.h:142
EmberCore::ITreeNode * GetSelectedNode() const
Returns the currently selected node.
Definition TreeCanvas.h:102
void SetShowGrid(bool show)
Enables or disables grid display.
Definition TreeCanvas.h:136
TreeCanvasConfig & GetConfig()
Returns mutable configuration.
Definition TreeCanvas.h:92
bool IsInFocusMode() const
Returns whether focus mode is active.
Definition TreeCanvas.h:149
std::shared_ptr< EmberCore::ITreeStructure > GetTree() const
Returns the current tree structure.
Definition TreeCanvas.h:89
wxPoint GetViewOffset() const
Returns the current view offset.
Definition TreeCanvas.h:173
wxColour GetNodeBorderColor(EmberCore::ITreeNode *node, bool selected, bool hovered) override
Returns border color based on node status, selection, and hover.
wxColour GetNodeTextColor(EmberCore::ITreeNode *node, bool selected, bool hovered) override
Returns text color based on node status, selection, and hover.
MonitorTreeCanvas(wxWindow *parent, wxWindowID id=wxID_ANY)
void ApplyBaseConfig()
Applies base visualization configuration (colors, layout, etc.).
void OnBeforePaintOverlays(wxDC &dc) override
Paints connection info overlay before other overlays.
wxColour GetNodeFillColor(EmberCore::ITreeNode *node, bool selected, bool hovered) override
Returns fill color based on node status, selection, and hover.
void SetConnectionInfo(bool connected, int tickCount)
Sets connection state and tick count for the overlay display.
Definition Panel.h:8
static wxColour GetExecutionPathColor()
Color for nodes in the execution path.
static wxColour GetBorderColor(int status)
Returns border color for the given status code.
static wxColour GetTextColor(int status)
Returns text color for the given status code.
static wxColour GetFillColor(int status)
Returns fill color for the given status code.