Ember
Loading...
Searching...
No Matches
MainFrame.cpp
Go to the documentation of this file.
1#include "App/MainFrame.h"
2#include "Adapters/DirectTreeAdapter.h" // NEW: Include DirectTreeAdapter
3#include "Adapters/NodeAdapter.h" // NEW: Include adapter for abstraction compatibility
4#include "Components/TabFactory.h" // Tab factory for creating tabs
5#include "Core/BehaviorTree.h" // BehaviorTree class for tree storage
6#include "Core/BehaviorTreeValidator.h" // NEW: Include unified validator
7#include "Dialogs/BehaviorTreeProjectDialog.h" // Project creation/editing dialog
8#include "Dialogs/LoadingDialog.h" // NEW: Include LoadingDialog for detailed loading window
9#include "Dialogs/OverrideSceneDialog.h" // NEW: Include custom override scene dialog
10#include "Dialogs/ParserConfigDialog.h" // Parser configuration dialog
11#include "Dialogs/PreferencesDialog.h" // NEW: Include preferences dialog
12#include "Dialogs/ProjectManagerDialog.h" // Project opening dialog
13#include "Panels/BottomPanel.h"
15#include "Panels/MainPanel.h"
17#include "Parsers/BehaviorTreeProject.h" // BehaviorTree project class
18#include "Parsers/ConfigManager.h" // NEW: Include ConfigManager for parser profiles
19#include "Parsers/LibXMLBehaviorTreeParser.h" // Include libxml2 parser
20#include "Parsers/LibXMLBehaviorTreeSerializer.h" // NEW: Include libxml2 serializer
21#include "Parsers/ProjectManager.h" // Project manager singleton
23#include "Scenes/BehaviorTreeScene.h" // NEW: Include for scene casting
25#include "Tabs/PropertiesTab.h"
28#include "Utils/AppPreferences.h" // NEW: Include application preferences system
29#include "Utils/BehaviorTreeConfig.h" // NEW: Include configuration system
30#include "Utils/CustomAuiNotebook.h" // CustomAuiNotebook for panel notebooks
31#include "Utils/Logger.h" // NEW: Include unified logging system
32#include "Utils/PerformanceMonitor.h" // NEW: Include performance monitoring
33#include "Utils/ResourcePath.h" // Centralized resource path management
34#include <chrono>
35#include <ctime>
36#include <fstream>
37#include <wx/artprov.h> // Include for wxArtProvider
38#include <wx/aui/aui.h>
39#include <wx/filename.h> // NEW: Include wxFileName for file operations
40#include <wx/splitter.h>
41#include <wx/stdpaths.h> // NEW: Include wxStandardPaths for getting executable directory
42#include <wx/tglbtn.h> // Include for wxToggleButton
43
45 EVT_MENU(ID_LoadXML, MainFrame::OnLoadXML) // Event for XML loading (libxml2)
46 EVT_MENU(ID_SaveXML, MainFrame::OnSaveXML) // Event for XML saving
47 EVT_MENU(ID_SaveAsXML, MainFrame::OnSaveAsXML) // Event for XML save as
48 EVT_MENU(ID_ResetZoom, MainFrame::OnResetZoom) // Event for reset zoom hotkey
49
50 // Project menu events
53 EVT_MENU(ID_ProjectSettings, MainFrame::OnProjectSettings)
54
55 // View menu events
58
59 // Settings menu events
61
62 // Updated tool button events for new 3-button layout
64 EVT_BUTTON(ID_LogReplayTool, MainFrame::OnLogReplayTool)
65
66 // Panel toggle events
67 EVT_BUTTON(ID_ToggleLeftPanel, MainFrame::OnToggleLeftPanel)
68 EVT_BUTTON(ID_ToggleBottomPanel, MainFrame::OnToggleBottomPanel)
69 EVT_BUTTON(ID_ToggleRightPanel, MainFrame::OnToggleRightPanel)
70
71 // Performance monitoring events
72 EVT_PAINT(MainFrame::OnPaint) EVT_IDLE(MainFrame::OnIdle) wxEND_EVENT_TABLE()
73
74 MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size, long style)
75 : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_auiManager(nullptr), m_bottomPanel(nullptr),
76 m_hierarchyTab(nullptr), m_scenePanel(nullptr), m_panelToggleToolbar(nullptr) {
77 // Initialize unified AUI manager
78 m_auiManager = new wxAuiManager(this);
79
80 // Increase sash size for easier resizing
81 m_auiManager->GetArtProvider()->SetMetric(wxAUI_DOCKART_SASH_SIZE, 8);
82
83 LOG_INFO("AUI", "Initialized unified AUI manager for MainFrame");
84
85 // Load application preferences
88 if (prefs.LoadFromFile(configPath)) {
89 LOG_INFO("Preferences", "Application preferences loaded from: " + configPath);
90 } else {
91 LOG_INFO("Preferences", "Using default preferences (config file not found or invalid)");
92 }
93
94 CreateMenuAndStatusBar();
95 CreatePanelToggleToolbar();
96 InitializeConfigurationMenu();
97 CreatePanelLayout();
98
99 // Apply window startup mode preferences
100 const auto &windowSettings = prefs.GetWindowSettings();
101
102 // Apply status bar visibility preference
103 if (windowSettings.showStatusBar) {
104 GetStatusBar()->Show();
105 LOG_INFO("Preferences", "Status bar enabled");
106 } else {
107 GetStatusBar()->Hide();
108 LOG_INFO("Preferences", "Status bar hidden");
109 }
110 switch (windowSettings.startupMode) {
112 // Maximize window but keep menu bar and title bar visible
113 Maximize(true);
114 LOG_INFO("Preferences", "Starting in maximized mode");
115 break;
117 default:
118 LOG_INFO("Preferences", "Starting in normal windowed mode");
119 break;
120 }
121
122 // Apply window appearance settings
123 if (windowSettings.alwaysOnTop) {
124 SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP);
125 LOG_INFO("Preferences", "Window set to always on top");
126 }
127
128 // Apply minimum window size constraints
129 SetMinSize(wxSize(windowSettings.minWindowWidth, windowSettings.minWindowHeight));
130 LOG_INFO("Preferences", "Minimum window size set to " + std::to_string(windowSettings.minWindowWidth) + "x" +
131 std::to_string(windowSettings.minWindowHeight));
132
133 // Apply maximum window size constraints
134 if (windowSettings.maxWindowWidth > 0 && windowSettings.maxWindowHeight > 0) {
135 SetMaxSize(wxSize(windowSettings.maxWindowWidth, windowSettings.maxWindowHeight));
136 LOG_INFO("Preferences", "Maximum window size set to " + std::to_string(windowSettings.maxWindowWidth) + "x" +
137 std::to_string(windowSettings.maxWindowHeight));
138 }
139
140 // Apply aspect ratio constraint (if enabled)
141 if (windowSettings.enforceAspectRatio) {
142 // Note: wxWidgets doesn't have built-in aspect ratio enforcement
143 // This would require custom resize handling in EVT_SIZE
144 LOG_INFO("Preferences", "Aspect ratio enforcement requested: " + std::to_string(windowSettings.aspectRatio) +
145 " (requires custom implementation)");
146 }
147
148 // Apply Main Panel settings on startup
149 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
150 if (m_scenePanel) {
151 // Apply canvas background color
152 wxColour bgColor(mainPanelSettings.canvasBackgroundColor.r, mainPanelSettings.canvasBackgroundColor.g,
153 mainPanelSettings.canvasBackgroundColor.b);
154 m_scenePanel->ApplyCanvasBackgroundColor(bgColor);
155
156 LOG_INFO("Preferences", "Main Panel settings applied on startup");
157 }
158
159 // Initialize performance monitoring
161 monitor.SetEnabled(true);
162 LOG_INFO("Performance", "Performance monitoring initialized in MainFrame");
163
164 // Auto-load last opened file if enabled in preferences
165 const auto &parserSettings = prefs.GetParserSettings();
166 bool fileAutoLoaded = false;
167 if (parserSettings.autoLoadLastFile && !parserSettings.lastOpenedFilePath.empty()) {
168 wxString lastFilePath = wxString::FromUTF8(parserSettings.lastOpenedFilePath);
169 if (wxFileExists(lastFilePath)) {
170 LOG_INFO("Preferences", "Auto-loading last opened file: " + parserSettings.lastOpenedFilePath);
171 // Use CallAfter to ensure the UI is fully initialized before loading
172 CallAfter([this, lastFilePath]() {
173 LoadXMLFile(lastFilePath, false); // false = don't show confirmation dialog
174 });
175 fileAutoLoaded = true;
176 } else {
177 LOG_WARNING("Preferences", "Last opened file no longer exists: " + parserSettings.lastOpenedFilePath);
178 }
179 }
180
181 // Show project selector on startup if no project is active and no file was auto-loaded
182 if (!fileAutoLoaded && !HasActiveProject()) {
183 CallAfter([this]() {
184 LOG_INFO("Project", "No active project on startup - showing project selector");
185 wxCommandEvent dummyEvent;
186 OnOpenProject(dummyEvent);
187 });
188 }
189}
190
192 // Save panel states before cleanup
193 if (m_leftPanel) {
194 m_leftPanel->SaveState();
195 LOG_INFO("MainFrame", "Saved left panel state");
196 }
197
198 if (m_rightPanel) {
199 m_rightPanel->SaveState();
200 LOG_INFO("MainFrame", "Saved right panel state");
201 }
202
203 if (m_bottomPanel) {
204 m_bottomPanel->SaveState();
205 LOG_INFO("MainFrame", "Saved bottom panel state");
206 }
207
208 // Save panel visibility states for "RememberLast" option
209 if (m_auiManager) {
211
212 // Save individual panel visibility
213 wxAuiPaneInfo &leftPaneInfo = m_auiManager->GetPane("left_panel");
214 wxAuiPaneInfo &rightPaneInfo = m_auiManager->GetPane("right_panel");
215 wxAuiPaneInfo &bottomPaneInfo = m_auiManager->GetPane("bottom_panel");
216
217 auto &leftSettings = prefs.GetLeftPanelSettings();
218 auto &rightSettings = prefs.GetRightPanelSettings();
219 auto &bottomSettings = prefs.GetBottomPanelSettings();
220
221 leftSettings.lastPanelVisible = leftPaneInfo.IsShown();
222 rightSettings.lastPanelVisible = rightPaneInfo.IsShown();
223 bottomSettings.lastPanelVisible = bottomPaneInfo.IsShown();
224
225 LOG_INFO("MainFrame", wxString::Format("Saved panel visibility - left: %d, right: %d, bottom: %d",
226 leftSettings.lastPanelVisible, rightSettings.lastPanelVisible,
227 bottomSettings.lastPanelVisible)
228 .ToStdString());
229 }
230
231 // Save preferences to disk
233 std::string configPath = EmberForge::AppPreferences::GetDefaultConfigPath();
234 if (prefManager.GetPreferences().SaveToFile(configPath)) {
235 LOG_INFO("MainFrame", "Saved preferences to disk: " + configPath);
236 } else {
237 LOG_ERROR("MainFrame", "Failed to save preferences to disk");
238 }
239
240 // Clean up unified AUI manager
241 if (m_auiManager) {
242 m_auiManager->UnInit();
243 delete m_auiManager;
244 m_auiManager = nullptr;
245 LOG_INFO("AUI", "Cleaned up unified AUI manager");
246 }
247}
248
250 // Get hotkey settings from preferences
252 auto &prefs = prefsMgr.GetPreferences();
253 const auto &windowSettings = prefs.GetWindowSettings();
254 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
255 const auto &btViewSettings = prefs.GetBehaviorTreeViewSettings();
256
257 // Create menu bar
258 wxMenu *menuFile = new wxMenu;
259
260 // Project operations (at the top) with configured hotkeys
261 wxString newProjectLabel = wxString::Format("New &Project...\t%s", windowSettings.newProjectHotkey);
262 menuFile->Append(ID_NewProject, newProjectLabel, "Create a new BehaviorTree project");
263
264 wxString openProjectLabel = wxString::Format("Open Pro&ject...\t%s", windowSettings.openProjectHotkey);
265 menuFile->Append(ID_OpenProject, openProjectLabel, "Open an existing BehaviorTree project");
266
267 menuFile->Append(ID_CloseProject, "&Close Project", "Close the current project");
268 menuFile->Append(ID_SaveProject, "Save Project", "Save the current project");
269 menuFile->Append(ID_ProjectSettings, "Project Settings...", "Edit project settings");
270 menuFile->AppendSeparator();
271
272 // Single file operations with configured hotkeys
273 wxString openFileLabel = wxString::Format("&Open XML File...\t%s", windowSettings.openFileHotkey);
274 menuFile->Append(ID_LoadXML, openFileLabel, "Load a behavior tree from XML file");
275 menuFile->AppendSeparator();
276
277 wxString saveLabel = wxString::Format("&Save\t%s", windowSettings.saveHotkey);
278 menuFile->Append(ID_SaveXML, saveLabel, "Save current behavior tree to XML file");
279
280 wxString saveAsLabel = wxString::Format("Save &As...\t%s", windowSettings.saveAsHotkey);
281 menuFile->Append(ID_SaveAsXML, saveAsLabel, "Save behavior tree to new XML file");
282 menuFile->AppendSeparator();
283 menuFile->Append(wxID_EXIT);
284
285 wxMenu *menuHelp = new wxMenu;
286 menuHelp->Append(wxID_ABOUT);
287
288 // Create View menu with configured hotkeys
289 wxMenu *menuView = new wxMenu;
290
291 wxString maximizeLabel = wxString::Format("&Maximize\t%s", windowSettings.maximizeHotkey);
292 menuView->Append(ID_ToggleMaximize, maximizeLabel, "Toggle maximize window");
293
294 menuView->AppendSeparator();
295
296 // Scene navigation with configured hotkeys
297 wxString nextSceneLabel = wxString::Format("&Next Scene\t%s", mainPanelSettings.nextSceneHotkey);
298 menuView->Append(ID_NextScene, nextSceneLabel, "Switch to next scene");
299
300 wxString prevSceneLabel = wxString::Format("&Previous Scene\t%s", mainPanelSettings.previousSceneHotkey);
301 menuView->Append(ID_PreviousScene, prevSceneLabel, "Switch to previous scene");
302
303 menuView->AppendSeparator();
304
305 // Reset view control with configured hotkey
306 wxString resetViewLabel = wxString::Format("&Reset View\t%s", btViewSettings.resetViewHotkey);
307 menuView->Append(ID_ResetZoom, resetViewLabel, "Reset zoom and pan to default");
308
309 menuView->AppendSeparator();
310
311 // Reset UI option with configured hotkey
312 wxString resetUILabel = wxString::Format("Reset &UI\t%s", windowSettings.resetUIHotkey);
313 menuView->Append(ID_ResetUI, resetUILabel, "Reset all panels and preferences to defaults");
314
315 // Create Settings menu with configured hotkeys
316 wxMenu *menuSettings = new wxMenu;
317
318 wxString preferencesLabel = wxString::Format("&Preferences...\t%s", windowSettings.preferencesHotkey);
319 menuSettings->Append(ID_Preferences, preferencesLabel,
320 "Open the preferences dialog to configure EmberForge settings");
321
322 wxString parserConfigLabel = wxString::Format("&Parser Configuration...\t%s", windowSettings.parserConfigHotkey);
323 menuSettings->Append(ID_ParserConfig, parserConfigLabel,
324 "Configure XML parser behavior and create custom profiles");
325
326 wxMenuBar *menuBar = new wxMenuBar;
327 menuBar->Append(menuFile, "&File");
328 menuBar->Append(menuView, "&View"); // Add View menu
329 menuBar->Append(menuSettings, "&Settings"); // NEW: Add Settings menu
330 menuBar->Append(menuHelp, "&Help");
331
332 SetMenuBar(menuBar);
333
334 // Create status bar
335 CreateStatusBar();
336 SetStatusText("Welcome to EmberForge!");
337}
338
340 // Create toolbar at the top
341 m_panelToggleToolbar = CreateToolBar(wxTB_FLAT | wxTB_HORIZONTAL | wxTB_NODIVIDER, wxID_ANY);
342 m_panelToggleToolbar->SetToolBitmapSize(wxSize(22, 22));
343
344 // Note: Tree selector is now embedded in the BehaviorTreeScene canvas (top-right corner)
345
346 // Add a stretchable spacer to push buttons to the right
347 m_panelToggleToolbar->AddStretchableSpace();
348
349 // Load custom icons from resources folder
350 wxString resourcePath = EmberForge::ResourcePath::GetDir("buttons");
351
352 // Left panel button with all states
353 wxBitmap leftNormal(resourcePath + "left_panel/Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG);
354 wxBitmap leftHovered(resourcePath + "left_panel/Left_Panel_Hovered_22.png", wxBITMAP_TYPE_PNG);
355 wxBitmap leftPressed(resourcePath + "left_panel/Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG);
356 wxBitmap leftDisabled(resourcePath + "left_panel/Left_Panel_Disabled_22.png", wxBITMAP_TYPE_PNG);
357
358 wxBitmapButton *leftBtn = new wxBitmapButton(m_panelToggleToolbar, ID_ToggleLeftPanel, leftNormal,
359 wxDefaultPosition, wxSize(32, 32), wxBORDER_NONE | wxBU_EXACTFIT);
360 leftBtn->SetBitmapHover(leftHovered);
361 leftBtn->SetBitmapPressed(leftPressed);
362 leftBtn->SetBitmapDisabled(leftDisabled);
363 leftBtn->SetToolTip("Toggle Left Panel");
364 m_panelToggleToolbar->AddControl(leftBtn);
365
366 // Bottom panel button with all states
367 wxBitmap bottomNormal(resourcePath + "bottom_panel/Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG);
368 wxBitmap bottomHovered(resourcePath + "bottom_panel/Bottom_Panel_Hovered_22.png", wxBITMAP_TYPE_PNG);
369 wxBitmap bottomPressed(resourcePath + "bottom_panel/Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG);
370 wxBitmap bottomDisabled(resourcePath + "bottom_panel/Bottom_Panel_Disabled_22.png", wxBITMAP_TYPE_PNG);
371
372 wxBitmapButton *bottomBtn = new wxBitmapButton(m_panelToggleToolbar, ID_ToggleBottomPanel, bottomNormal,
373 wxDefaultPosition, wxSize(32, 32), wxBORDER_NONE | wxBU_EXACTFIT);
374 bottomBtn->SetBitmapHover(bottomHovered);
375 bottomBtn->SetBitmapPressed(bottomPressed);
376 bottomBtn->SetBitmapDisabled(bottomDisabled);
377 bottomBtn->SetToolTip("Toggle Bottom Panel");
378 m_panelToggleToolbar->AddControl(bottomBtn);
379
380 // Right panel button with all states
381 wxBitmap rightNormal(resourcePath + "right_panel/Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG);
382 wxBitmap rightHovered(resourcePath + "right_panel/Right_Panel_Hovered_22.png", wxBITMAP_TYPE_PNG);
383 wxBitmap rightPressed(resourcePath + "right_panel/Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG);
384 wxBitmap rightDisabled(resourcePath + "right_panel/Right_Panel_Disabled_22.png", wxBITMAP_TYPE_PNG);
385
386 wxBitmapButton *rightBtn = new wxBitmapButton(m_panelToggleToolbar, ID_ToggleRightPanel, rightNormal,
387 wxDefaultPosition, wxSize(32, 32), wxBORDER_NONE | wxBU_EXACTFIT);
388 rightBtn->SetBitmapHover(rightHovered);
389 rightBtn->SetBitmapPressed(rightPressed);
390 rightBtn->SetBitmapDisabled(rightDisabled);
391 rightBtn->SetToolTip("Toggle Right Panel");
392 m_panelToggleToolbar->AddControl(rightBtn);
393
394 m_panelToggleToolbar->Realize();
395
396 LOG_INFO("UI", "Panel toggle toolbar created with state-aware custom icons");
397}
398
400 // No menu initialization needed for preferences dialog approach
401 LOG_INFO("Config", "Configuration system initialized - use Settings > Preferences to configure");
402}
403
405 // Get updated hotkey settings from preferences
407 auto &prefs = prefsMgr.GetPreferences();
408 const auto &windowSettings = prefs.GetWindowSettings();
409 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
410 const auto &btViewSettings = prefs.GetBehaviorTreeViewSettings();
411
412 wxMenuBar *menuBar = GetMenuBar();
413 if (!menuBar)
414 return;
415
416 // Update File menu hotkeys
417 int fileMenuIndex = menuBar->FindMenu("File");
418 if (fileMenuIndex != wxNOT_FOUND) {
419 wxMenu *menuFile = menuBar->GetMenu(fileMenuIndex);
420 if (menuFile) {
421 wxMenuItem *newProjectItem = menuFile->FindItem(ID_NewProject);
422 if (newProjectItem) {
423 newProjectItem->SetItemLabel(wxString::Format("New &Project...\t%s", windowSettings.newProjectHotkey));
424 }
425
426 wxMenuItem *openProjectItem = menuFile->FindItem(ID_OpenProject);
427 if (openProjectItem) {
428 openProjectItem->SetItemLabel(
429 wxString::Format("Open Pro&ject...\t%s", windowSettings.openProjectHotkey));
430 }
431
432 wxMenuItem *openFileItem = menuFile->FindItem(ID_LoadXML);
433 if (openFileItem) {
434 openFileItem->SetItemLabel(wxString::Format("&Open XML File...\t%s", windowSettings.openFileHotkey));
435 }
436
437 wxMenuItem *saveItem = menuFile->FindItem(ID_SaveXML);
438 if (saveItem) {
439 saveItem->SetItemLabel(wxString::Format("&Save\t%s", windowSettings.saveHotkey));
440 }
441
442 wxMenuItem *saveAsItem = menuFile->FindItem(ID_SaveAsXML);
443 if (saveAsItem) {
444 saveAsItem->SetItemLabel(wxString::Format("Save &As...\t%s", windowSettings.saveAsHotkey));
445 }
446 }
447 }
448
449 // Update View menu hotkeys
450 int viewMenuIndex = menuBar->FindMenu("View");
451 if (viewMenuIndex != wxNOT_FOUND) {
452 wxMenu *menuView = menuBar->GetMenu(viewMenuIndex);
453 if (menuView) {
454 wxMenuItem *maximizeItem = menuView->FindItem(ID_ToggleMaximize);
455 if (maximizeItem) {
456 maximizeItem->SetItemLabel(wxString::Format("&Maximize\t%s", windowSettings.maximizeHotkey));
457 }
458
459 wxMenuItem *nextSceneItem = menuView->FindItem(ID_NextScene);
460 if (nextSceneItem) {
461 nextSceneItem->SetItemLabel(wxString::Format("&Next Scene\t%s", mainPanelSettings.nextSceneHotkey));
462 }
463
464 wxMenuItem *prevSceneItem = menuView->FindItem(ID_PreviousScene);
465 if (prevSceneItem) {
466 prevSceneItem->SetItemLabel(
467 wxString::Format("&Previous Scene\t%s", mainPanelSettings.previousSceneHotkey));
468 }
469
470 wxMenuItem *resetViewItem = menuView->FindItem(ID_ResetZoom);
471 if (resetViewItem) {
472 resetViewItem->SetItemLabel(wxString::Format("&Reset View\t%s", btViewSettings.resetViewHotkey));
473 }
474
475 wxMenuItem *resetUIItem = menuView->FindItem(ID_ResetUI);
476 if (resetUIItem) {
477 resetUIItem->SetItemLabel(wxString::Format("Reset &UI\t%s", windowSettings.resetUIHotkey));
478 }
479 }
480 }
481
482 // Update Settings menu hotkeys
483 int settingsMenuIndex = menuBar->FindMenu("Settings");
484 if (settingsMenuIndex != wxNOT_FOUND) {
485 wxMenu *menuSettings = menuBar->GetMenu(settingsMenuIndex);
486 if (menuSettings) {
487 wxMenuItem *preferencesItem = menuSettings->FindItem(ID_Preferences);
488 if (preferencesItem) {
489 preferencesItem->SetItemLabel(
490 wxString::Format("&Preferences...\t%s", windowSettings.preferencesHotkey));
491 }
492
493 wxMenuItem *parserConfigItem = menuSettings->FindItem(ID_ParserConfig);
494 if (parserConfigItem) {
495 parserConfigItem->SetItemLabel(
496 wxString::Format("&Parser Configuration...\t%s", windowSettings.parserConfigHotkey));
497 }
498 }
499 }
500
501 LOG_INFO("Preferences", "Menu hotkeys refreshed");
502}
503
505 // Refresh the canvas visualization to show tree structure changes
506 if (!m_scenePanel)
507 return;
508
509 auto activeScene = m_scenePanel->GetActiveScene();
510 if (!activeScene || activeScene->GetSceneType() != "BehaviorTree")
511 return;
512
513 auto *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
514 if (!btScene)
515 return;
516
517 auto *treeVis = btScene->GetTreeVisualization();
518 if (treeVis) {
519 // Get the current behavior tree adapter
520 auto currentTree = treeVis->GetBehaviorTree();
521 if (currentTree) {
522 // Re-set the behavior tree to trigger layout recalculation
523 // This ensures new nodes are positioned correctly
524 treeVis->SetBehaviorTree(currentTree);
525 }
526
527 treeVis->RefreshVisualization();
528 treeVis->Refresh();
529 treeVis->Update();
530 }
531
532 btScene->Refresh();
533 m_scenePanel->Refresh();
534 m_scenePanel->Update();
535}
536
538 // Refresh menu hotkeys
540
541 // Apply preferences
543 const auto &windowSettings = prefs.GetWindowSettings();
544
545 // Apply status bar visibility
546 if (windowSettings.showStatusBar) {
547 GetStatusBar()->Show();
548 } else {
549 GetStatusBar()->Hide();
550 }
551
552 // Apply panel caption visibility
553 if (m_auiManager) {
554 wxAuiPaneInfo &leftPane = m_auiManager->GetPane("left_panel");
555 if (leftPane.IsOk()) {
556 leftPane.CaptionVisible(windowSettings.showPanelCaptions);
557 }
558
559 wxAuiPaneInfo &rightPane = m_auiManager->GetPane("right_panel");
560 if (rightPane.IsOk()) {
561 rightPane.CaptionVisible(windowSettings.showPanelCaptions);
562 }
563
564 wxAuiPaneInfo &bottomPane = m_auiManager->GetPane("bottom_panel");
565 if (bottomPane.IsOk()) {
566 bottomPane.CaptionVisible(windowSettings.showPanelCaptions);
567 }
568
569 wxAuiPaneInfo &scenePane = m_auiManager->GetPane("scene_panel");
570 if (scenePane.IsOk()) {
571 scenePane.CaptionVisible(windowSettings.showPanelCaptions);
572 }
573
574 m_auiManager->Update();
575 LOG_INFO("Preferences",
576 std::string("Panel captions ") + (windowSettings.showPanelCaptions ? "shown" : "hidden"));
577 }
578
579 // Apply always on top
580 long currentStyle = GetWindowStyle();
581 bool styleChanged = false;
582
583 if (windowSettings.alwaysOnTop) {
584 if (!(currentStyle & wxSTAY_ON_TOP)) {
585 SetWindowStyle(currentStyle | wxSTAY_ON_TOP);
586 LOG_INFO("Preferences", "Window set to always on top");
587 styleChanged = true;
588 }
589 } else {
590 if (currentStyle & wxSTAY_ON_TOP) {
591 SetWindowStyle(currentStyle & ~wxSTAY_ON_TOP);
592 LOG_INFO("Preferences", "Window always on top disabled");
593 styleChanged = true;
594 }
595 }
596
597 // If style changed, force a proper refresh
598 if (styleChanged) {
599 // Ensure menu bar accelerators are preserved
600 wxMenuBar *menuBar = GetMenuBar();
601 if (menuBar) {
602 // Detach and reattach menu bar to ensure accelerators work
603 SetMenuBar(nullptr);
604 SetMenuBar(menuBar);
605 }
606 Update();
607 }
608
609 // Apply Main Panel settings
610 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
611 if (m_scenePanel) {
612 // Apply canvas background color
613 wxColour bgColor(mainPanelSettings.canvasBackgroundColor.r, mainPanelSettings.canvasBackgroundColor.g,
614 mainPanelSettings.canvasBackgroundColor.b);
615 m_scenePanel->ApplyCanvasBackgroundColor(bgColor);
616
617 // Reload zoom/pan preferences for all scenes
618 int sceneCount = m_scenePanel->GetSceneCount();
619 for (int i = 0; i < sceneCount; i++) {
620 IScene *scene = m_scenePanel->GetScene(i);
621 if (scene) {
622 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(scene);
623 if (btScene) {
624 // Reload preferences in TreeVisualization
625 if (auto *treeVis = btScene->GetTreeVisualization()) {
626 treeVis->LoadPreferences();
627 LOG_INFO("Preferences",
628 wxString::Format("Reloaded zoom/pan preferences for scene %d", i).ToStdString());
629 }
630 }
631 }
632 }
633
634 LOG_INFO("Preferences", "Main Panel settings applied");
635 }
636
637 // Force layout refresh to account for status bar visibility change
638 SendSizeEvent();
639
640 LOG_INFO("Preferences", "Preferences refreshed and applied to UI");
641}
642
644 // ====== CREATE PANEL INSTANCES ======
645
646 // Create left panel container (parent is MainFrame now, not splitter)
647 m_leftPanel = new LeftSidePanel(this, this);
648
649 // Create main scene panel (center)
650 m_scenePanel = new MainPanel(this);
651
652 // Set up scene change callback to update hierarchy when switching scene tabs
653 m_scenePanel->SetSceneChangedCallback([this](IScene *newScene, int) {
654 if (!newScene || newScene->GetSceneType() != "BehaviorTree")
655 return;
656
657 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(newScene);
658 if (!btScene)
659 return;
660
661 // Get the tree from the new scene and update hierarchy
662 EmberCore::Node *rawTree = btScene->GetBehaviorTree();
663 if (rawTree && m_hierarchyTab) {
664 auto rootNode = std::shared_ptr<EmberCore::Node>(rawTree, [](EmberCore::Node *) {});
665 m_hierarchyTab->SetRootNode(rootNode);
666 }
667 });
668
669 // Create right panel container
670 m_rightPanel = new RightSidePanel(this, this);
671
672 // Create unified bottom panel
673 m_bottomPanel = new BottomPanel(this, this);
674
675 // ====== FINISH PANEL SETUP (AFTER CONSTRUCTION) ======
676 // Call FinishSetup() after derived classes are fully constructed to ensure
677 // proper virtual dispatch for OnPanelSpecificSetup() which creates default tabs
678 m_leftPanel->FinishSetup();
679 m_rightPanel->FinishSetup();
680 m_bottomPanel->FinishSetup();
681
682 // ====== GET REFERENCES TO TABS ======
683 // Note: Tabs are now created by OnPanelSpecificSetup() and RestoreState()
684 // We just need to get references to specific tabs that MainFrame needs
685
686 // Get hierarchy tab reference from left panel (will be created by panel initialization)
687 // We'll set this up after RestoreState is called
688 m_hierarchyTab = nullptr;
689 m_propertiesTab = nullptr;
690 m_treeSelectorTab = nullptr;
691
692 // ====== INITIAL SCENE SETUP ======
693
694 // Create an empty behavior tree scene
695 auto behaviorTreeScene = std::make_unique<BehaviorTreeScene>(m_scenePanel->GetNotebook());
696
697 // Set up bidirectional selection synchronization
698 behaviorTreeScene->SetNodeSelectionCallback([this](EmberCore::ITreeNode *node) { OnSceneSelectionChanged(node); });
699
700 m_scenePanel->AddScene(std::move(behaviorTreeScene));
701
702 // Note: We'll set the root node on the hierarchy tab AFTER RestoreState creates it
703
704 // ====== SETUP AUI LAYOUT ======
705
706 // Get preferences for all panels
708 const auto &leftSettings = prefs.GetLeftPanelSettings();
709 const auto &rightSettings = prefs.GetRightPanelSettings();
710 const auto &bottomSettings = prefs.GetBottomPanelSettings();
711
712 // Determine initial visibility for left panel based on startup preference
713 bool showLeftPanel = true;
714 switch (leftSettings.panelStartupState) {
716 showLeftPanel = true;
717 break;
719 showLeftPanel = false;
720 break;
722 showLeftPanel = leftSettings.lastPanelVisible;
723 break;
724 }
725
726 // Get window settings for caption visibility
727 const auto &windowSettings = prefs.GetWindowSettings();
728
729 // Add all panels to the unified AUI manager
730 m_auiManager->AddPane(m_leftPanel, wxAuiPaneInfo()
731 .Name("left_panel")
732 .Caption("Left Panel")
733 .CaptionVisible(windowSettings.showPanelCaptions)
734 .Left()
735 .BestSize(wxSize(leftSettings.defaultPanelWidth, -1))
736 .MinSize(wxSize(leftSettings.minimumPanelWidth, -1))
737 .Dockable(true)
738 .Floatable(false)
739 .CloseButton(false)
740 .Resizable(leftSettings.allowPanelCollapse)
741 .Show(showLeftPanel));
742
743 m_auiManager->AddPane(m_scenePanel, wxAuiPaneInfo()
744 .Name("scene_panel")
745 .Caption("Main Panel")
746 .CenterPane()
747 .CaptionVisible(windowSettings.showPanelCaptions)
748 .Dockable(true)
749 .Floatable(false)
750 .CloseButton(false)
751 .Resizable(true));
752
753 // Determine initial visibility for right panel based on startup preference
754 bool showRightPanel = true;
755 switch (rightSettings.panelStartupState) {
757 showRightPanel = true;
758 break;
760 showRightPanel = false;
761 break;
763 showRightPanel = rightSettings.lastPanelVisible;
764 break;
765 }
766
767 m_auiManager->AddPane(m_rightPanel, wxAuiPaneInfo()
768 .Name("right_panel")
769 .Caption("Right Panel")
770 .CaptionVisible(windowSettings.showPanelCaptions)
771 .Right()
772 .BestSize(wxSize(rightSettings.defaultPanelWidth, -1))
773 .MinSize(wxSize(rightSettings.minimumPanelWidth, -1))
774 .Dockable(true)
775 .Floatable(false)
776 .CloseButton(false)
777 .Resizable(rightSettings.allowPanelCollapse)
778 .Show(showRightPanel));
779
780 // Determine initial visibility for bottom panel based on startup preference
781 bool showBottomPanel = true;
782 switch (bottomSettings.panelStartupState) {
784 showBottomPanel = true;
785 break;
787 showBottomPanel = false;
788 break;
790 showBottomPanel = bottomSettings.lastPanelVisible;
791 break;
792 }
793
794 m_auiManager->AddPane(m_bottomPanel, wxAuiPaneInfo()
795 .Name("bottom_panel")
796 .Caption("Bottom Panel")
797 .CaptionVisible(windowSettings.showPanelCaptions)
798 .Bottom()
799 .BestSize(wxSize(-1, bottomSettings.defaultPanelHeight))
800 .MinSize(wxSize(-1, bottomSettings.minimumPanelHeight))
801 .Dockable(true)
802 .Floatable(false)
803 .CloseButton(false)
804 .Resizable(bottomSettings.allowPanelCollapse)
805 .Show(showBottomPanel));
806
807 // Update the AUI layout
808 m_auiManager->Update();
809
810 // Apply panel preferences after AUI setup
811 m_leftPanel->ApplyPreferences();
812 m_leftPanel->RestoreState();
813
814 // Get reference to hierarchy tab after it's created by RestoreState
815 auto *notebook = m_leftPanel->GetNotebook();
816 if (notebook) {
817 for (size_t i = 0; i < notebook->GetPageCount(); ++i) {
818 auto *page = notebook->GetPage(i);
819 auto *tab = dynamic_cast<ITab *>(page);
820 if (tab && tab->GetTabType() == "SceneHierarchy") {
821 m_hierarchyTab = dynamic_cast<SceneHierarchyTab *>(page);
822 LOG_INFO("MainFrame", "Found hierarchy tab reference");
823 break;
824 }
825 }
826 }
827
828 // Note: Hierarchy tab will be populated when a project is loaded or file is opened
829
830 m_rightPanel->ApplyPreferences();
831 m_rightPanel->RestoreState();
832
833 // Get reference to properties tab after it's created by RestoreState
834 auto *rightNotebook = m_rightPanel->GetNotebook();
835 if (rightNotebook) {
836 for (size_t i = 0; i < rightNotebook->GetPageCount(); ++i) {
837 auto *page = rightNotebook->GetPage(i);
838 auto *tab = dynamic_cast<ITab *>(page);
839 if (tab && tab->GetTabType() == "Properties") {
840 m_propertiesTab = dynamic_cast<PropertiesTab *>(page);
841 LOG_INFO("MainFrame", "Found properties tab reference");
842 break;
843 }
844 }
845 }
846
847 m_bottomPanel->ApplyPreferences();
848 m_bottomPanel->RestoreState();
849
850 // Update button bitmaps to match initial panel visibility
852 wxString resourcePath = EmberForge::ResourcePath::GetDir("buttons");
853
854 // Update left panel button
855 wxWindow *leftWin = m_panelToggleToolbar->FindWindow(ID_ToggleLeftPanel);
856 if (leftWin) {
857 wxBitmapButton *leftBtn = dynamic_cast<wxBitmapButton *>(leftWin);
858 if (leftBtn) {
859 if (showLeftPanel) {
860 leftBtn->SetBitmap(
861 wxBitmap(resourcePath + "left_panel/Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
862 } else {
863 leftBtn->SetBitmap(
864 wxBitmap(resourcePath + "left_panel/Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
865 }
866 }
867 }
868
869 // Update bottom panel button
870 wxWindow *bottomWin = m_panelToggleToolbar->FindWindow(ID_ToggleBottomPanel);
871 if (bottomWin) {
872 wxBitmapButton *bottomBtn = dynamic_cast<wxBitmapButton *>(bottomWin);
873 if (bottomBtn) {
874 if (showBottomPanel) {
875 bottomBtn->SetBitmap(
876 wxBitmap(resourcePath + "bottom_panel/Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
877 } else {
878 bottomBtn->SetBitmap(
879 wxBitmap(resourcePath + "bottom_panel/Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
880 }
881 }
882 }
883
884 // Update right panel button
885 wxWindow *rightWin = m_panelToggleToolbar->FindWindow(ID_ToggleRightPanel);
886 if (rightWin) {
887 wxBitmapButton *rightBtn = dynamic_cast<wxBitmapButton *>(rightWin);
888 if (rightBtn) {
889 if (showRightPanel) {
890 rightBtn->SetBitmap(
891 wxBitmap(resourcePath + "right_panel/Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
892 } else {
893 rightBtn->SetBitmap(
894 wxBitmap(resourcePath + "right_panel/Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
895 }
896 }
897 }
898 }
899
900 LOG_INFO("AUI", wxString::Format(
901 "Created unified AUI layout - left panel: width=%d, minWidth=%d, visible=%d; right panel: "
902 "width=%d, minWidth=%d, visible=%d; bottom panel: height=%d, minHeight=%d, visible=%d",
903 leftSettings.defaultPanelWidth, leftSettings.minimumPanelWidth, showLeftPanel,
904 rightSettings.defaultPanelWidth, rightSettings.minimumPanelWidth, showRightPanel,
905 bottomSettings.defaultPanelHeight, bottomSettings.minimumPanelHeight, showBottomPanel)
906 .ToStdString());
907}
908
909// ====== PERFORMANCE MONITORING EVENT HANDLERS ======
910
911void MainFrame::OnPaint(wxPaintEvent &event) {
912 // Standard paint handling
913 event.Skip();
914}
915
916void MainFrame::OnIdle(wxIdleEvent &event) {
917 // Update system metrics periodically during idle time
918 static int idleCount = 0;
919 if (++idleCount % 100 == 0) { // Every 100 idle events
921 if (monitor.IsEnabled()) {
922 monitor.UpdateSystemMetrics();
923 }
924 }
925 event.Skip();
926}
927
928// ====== EVENT HANDLERS (SIMPLIFIED) ======
929
930void MainFrame::OnExit(wxCommandEvent &event) { Close(true); }
931
932void MainFrame::OnAbout(wxCommandEvent &event) {
933 wxMessageBox("This is a refactored wxWidgets application for EmberForge\n\n"
934 "Now with better code organization using separate panel classes!",
935 "About EmberForge", wxOK | wxICON_INFORMATION);
936}
937
938void MainFrame::OnLoadXML(wxCommandEvent &event) {
939 wxFileDialog openFileDialog(this, "Open Behavior Tree", "", "", "XML files (*.xml)|*.xml|All files (*.*)|*.*",
940 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
941
942 if (openFileDialog.ShowModal() == wxID_CANCEL)
943 return; // the user changed their mind
944
945 wxString filePath = openFileDialog.GetPath();
946 wxString ext = wxFileName(filePath).GetExt().Lower();
947
948 // Check if file is XML
949 if (ext != "xml") {
950 wxString message = wxString::Format("Unsupported File Format\n\n"
951 "File: %s\n"
952 "Extension: .%s\n\n"
953 "EmberForge currently only supports opening XML behavior tree files.\n"
954 "Please select an XML file (.xml) to open.",
955 wxFileName(filePath).GetFullName(), ext.IsEmpty() ? "none" : ext);
956
957 wxMessageBox(message, "Unsupported File Format", wxOK | wxICON_WARNING, this);
958 LOG_WARNING("FileOpen", std::string("Attempted to open unsupported file type: .") + ext.ToStdString());
959 return;
960 }
961
962 LoadXMLFile(filePath);
963}
964
965void MainFrame::LoadXMLFile(const wxString &filePath, bool confirmOverride) {
966 LOG_INFO("Parser", std::string("Loading XML file: ") + filePath.ToStdString());
967
968 // Variables to track user preferences for renaming
969 bool shouldRename = false;
970 wxString newSceneName;
971
972 // NOTE: OverrideSceneDialog is temporarily disabled
973 // If confirmation is requested, show custom dialog with rename options
974 // if (confirmOverride) {
975 // wxFileName fileName(filePath);
976 // EmberForge::OverrideSceneDialog confirmDialog(this, fileName.GetFullName());
977 //
978 // if (confirmDialog.ShowModal() != wxID_OK) {
979 // LOG_INFO("Parser", "User cancelled XML loading");
980 // return;
981 // }
982 //
983 // // Get user preferences from dialog
984 // shouldRename = confirmDialog.ShouldRename();
985 // newSceneName = confirmDialog.GetSceneName();
986 // }
987 (void)confirmOverride; // Suppress unused parameter warning
988
989 // Create detailed loading dialog with scrollable log
990 LoadingDialog loadingDialog(this, "Loading Behavior Tree (libxml2)");
991 loadingDialog.SetMaxProgress(5);
992 loadingDialog.Show(true);
993 loadingDialog.AppendLog("Selected file: " + filePath, "[FILE]");
994 wxYield(); // Force UI update
995
996 // Create a progress callback adapter
997 class ProgressCallback : public EmberCore::IParseProgressCallback {
998 private:
999 LoadingDialog *dialog_;
1000
1001 public:
1002 explicit ProgressCallback(LoadingDialog *dialog) : dialog_(dialog) {}
1003
1004 bool OnProgress(const EmberCore::String &message, int current, int total) override {
1005 if (dialog_) {
1006 // Update progress with detailed message
1007 bool shouldContinue = dialog_->UpdateProgress(current, total, message);
1008
1009 // Add a small delay to make progress visible (especially for small files)
1010 wxMilliSleep(50);
1011
1012 return shouldContinue;
1013 }
1014 return true;
1015 }
1016
1017 // Additional method to append detailed log messages
1018 void AppendLog(const wxString &message, const wxString &prefix = "") {
1019 if (dialog_) {
1020 dialog_->AppendLog(message, prefix);
1021 }
1022 }
1023 };
1024
1025 ProgressCallback progressCallback(&loadingDialog);
1026
1027 // Get parser config from ConfigManager
1028 auto &configMgr = EmberCore::ConfigManager::GetInstance();
1029 auto activeProfile = configMgr.GetActiveProfile();
1030 auto parserConfig = activeProfile ? activeProfile->GetConfig() : EmberCore::ParserConfig::CreateDefault();
1031
1032 // Create libxml2 parser with active config and set progress callback
1033 EmberCore::LibXMLBehaviorTreeParser parser(parserConfig);
1034 parser.SetProgressCallback(&progressCallback);
1035
1036 // Add initial parsing logs
1037 progressCallback.AppendLog("libxml2 parser initialized", "[INIT]");
1038 progressCallback.AppendLog("Starting file parsing with libxml2...", "[INFO]");
1039
1040 // Load the XML with progress reporting
1041 auto behaviorTree = parser.ParseFromFile(filePath.ToStdString());
1042
1043 // Show completion
1044 if (!loadingDialog.WasCancelled()) {
1045 loadingDialog.UpdateProgress(5, 5, "Complete!");
1046 loadingDialog.AppendLog("libxml2 parsing completed successfully", "[COMPLETE]");
1047 wxMilliSleep(800); // Show completion message briefly
1048 }
1049
1050 // Mark as complete and keep dialog open for review
1051 loadingDialog.MarkComplete();
1052
1053 if (!behaviorTree) {
1054 // Show parsing errors in the dialog
1055 const auto &errors = parser.GetErrors();
1056 for (const auto &error : errors) {
1057 loadingDialog.AppendLog(wxString::FromUTF8(error.message), "[ERROR]");
1058 }
1059
1060 // Keep dialog open for user to review
1061 loadingDialog.ShowModal();
1062
1063 wxString errorMessage = "Failed to parse XML file with libxml2:\n\n";
1064 for (const auto &error : errors) {
1065 errorMessage += "• " + error.message + "\n";
1066 }
1067
1068 wxMessageBox(errorMessage, "libxml2 XML Parsing Error", wxOK | wxICON_ERROR);
1069 LOG_ERROR("Parser", "libxml2 XML parsing failed");
1070 return;
1071 }
1072
1073 // Keep dialog open for user to review logs before continuing
1074 loadingDialog.ShowModal();
1075
1076 LOG_INFO("Parser", "libxml2 XML parsed successfully, loading into scene view");
1077
1078 // Validate that the main tree has actual content (not just empty nodes)
1079 if (behaviorTree->HasRootNode()) {
1080 EmberCore::Node *rootNode = behaviorTree->GetRootNode();
1081 if (rootNode) {
1082 // Check if the root node has no children (likely due to skipped SubTree nodes)
1083 if (rootNode->GetChildCount() == 0) {
1084 wxMessageBox("Cannot load behavior tree: The main tree appears to be empty.\n\n"
1085 "This usually happens when the tree contains only SubTree nodes,\n"
1086 "which are not yet implemented in the parser.",
1087 "Empty Behavior Tree", wxOK | wxICON_WARNING);
1088 LOG_WARNING("Parser", "Refusing to load empty behavior tree - root node '" + rootNode->GetName() +
1089 "' has no children");
1090 return;
1091 }
1092 }
1093 }
1094
1095 // Get the scene panel and load the parsed tree
1096 if (m_scenePanel) {
1097 auto activeScene = m_scenePanel->GetActiveScene();
1098 if (activeScene) {
1099 auto treeVis = dynamic_cast<BehaviorTreeScene *>(activeScene);
1100 if (treeVis) {
1101 // Load the parsed tree into the scene
1102 // Create DirectTreeAdapter from the parsed BehaviorTree (same as old parser)
1103 auto directAdapter = std::make_shared<EmberCore::DirectTreeAdapter>(behaviorTree);
1104 treeVis->SetBehaviorTree(directAdapter);
1105
1106 // Update hierarchy tab with the new tree structure
1107 if (m_hierarchyTab && behaviorTree->HasRootNode()) {
1108 // Get the root node as raw pointer first
1109 EmberCore::Node *rawRootNode = behaviorTree->GetRootNode();
1110 if (rawRootNode) {
1111 // Create a shared_ptr that doesn't delete the node (non-owning)
1112 // The BehaviorTree owns the node, we just need to reference it
1113 auto rootNode = std::shared_ptr<EmberCore::Node>(rawRootNode, [](EmberCore::Node *) {});
1114 m_hierarchyTab->SetRootNode(rootNode);
1115 LOG_INFO("Parser", "Behavior tree loaded into hierarchy tab");
1116 } else {
1117 LOG_ERROR("Parser", "Root node is null even though HasRootNode() returned true");
1118 }
1119 }
1120
1121 // Force a refresh of the scene view to display the new tree
1122 // Get the actual TreeVisualization widget and force it to redraw
1123 if (auto *visualization = treeVis->GetTreeVisualization()) {
1124 visualization->RefreshVisualization();
1125 visualization->Refresh();
1126 visualization->Update();
1127
1128 // Center view on root node after loading
1129 if (directAdapter && directAdapter->HasRootNode()) {
1130 CallAfter([visualization, directAdapter]() {
1131 visualization->CenterOnNode(directAdapter->GetRootNode());
1132 LOG_INFO("Parser", "Centered view on root node after loading XML (UniParser)");
1133 });
1134 }
1135 }
1136 treeVis->Refresh();
1137 m_scenePanel->Refresh();
1138 m_scenePanel->Update();
1139
1140 // Track the current file path for save operations
1141 m_currentFilePath = filePath;
1142 m_treeModified = false;
1143
1144 // Save the last opened file path to preferences
1145 auto &parserPrefs =
1147 parserPrefs.lastOpenedFilePath = filePath.ToStdString();
1150 LOG_INFO("Preferences", "Saved last opened file path: " + filePath.ToStdString());
1151
1152 // Update the scene title with the filename
1153 // NOTE: Custom rename via OverrideSceneDialog is temporarily disabled
1154 {
1155 wxFileName fileName(filePath);
1156 wxString sceneName = fileName.GetName();
1157 m_scenePanel->UpdateActiveSceneTitle(sceneName);
1158 }
1159 (void)shouldRename; // Suppress unused variable warning
1160 (void)newSceneName; // Suppress unused variable warning
1161
1162 LOG_INFO("Parser", "Behavior tree loaded into scene view");
1163 SetStatusText("Loaded with libxml2: " + wxFileName(filePath).GetName());
1164 } else {
1165 LOG_ERROR("Parser", "Active scene is not a behavior tree scene");
1166 wxMessageBox("Active scene is not a behavior tree scene", "Error", wxOK | wxICON_ERROR);
1167 }
1168 } else {
1169 LOG_ERROR("Parser", "No active scene available");
1170 wxMessageBox("No active scene available", "Error", wxOK | wxICON_ERROR);
1171 }
1172 } else {
1173 LOG_ERROR("Parser", "Scene panel not available");
1174 wxMessageBox("Scene panel not available", "Error", wxOK | wxICON_ERROR);
1175 }
1176}
1177
1178void MainFrame::LoadXMLFileInNewScene(const wxString &filePath) {
1179 if (!m_scenePanel) {
1180 LOG_ERROR("Parser", "Scene panel not available");
1181 wxMessageBox("Scene panel not available", "Error", wxOK | wxICON_ERROR);
1182 return;
1183 }
1184
1185 // Extract filename without extension to use as scene name
1186 wxFileName fileName(filePath);
1187 wxString sceneName = fileName.GetName();
1188
1189 // Create a new scene with the XML filename
1190 LOG_INFO("Parser", std::string("Creating new scene: ") + sceneName.ToStdString());
1191 int sceneIndex = m_scenePanel->CreateNewScene(sceneName);
1192
1193 if (sceneIndex < 0) {
1194 LOG_ERROR("Parser", "Failed to create new scene (limit may have been reached)");
1195 // Don't show another popup - AddScene already showed a specific warning
1196 return;
1197 }
1198
1199 // The new scene is now active, so load the XML into it
1200 LoadXMLFile(filePath);
1201}
1202
1203void MainFrame::OnSaveXML(wxCommandEvent &event) {
1204 // If no current file path, redirect to Save As
1205 if (m_currentFilePath.IsEmpty()) {
1206 OnSaveAsXML(event);
1207 return;
1208 }
1209
1210 // Save to existing path
1212}
1213
1214void MainFrame::OnSaveAsXML(wxCommandEvent &event) {
1215 wxFileDialog saveFileDialog(this, "Save Behavior Tree XML", "", "", "XML files (*.xml)|*.xml",
1216 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1217
1218 if (saveFileDialog.ShowModal() == wxID_CANCEL)
1219 return;
1220
1221 wxString filePath = saveFileDialog.GetPath();
1222 DoSaveXML(filePath);
1223}
1224
1225void MainFrame::DoSaveXML(const wxString &filePath) {
1226 LOG_INFO("Serializer", "Saving behavior tree to: " + filePath.ToStdString());
1227
1228 // 1. Get current behavior tree from scene
1229 auto behaviorTreeScene = dynamic_cast<BehaviorTreeScene *>(m_scenePanel->GetActiveScene());
1230 if (!behaviorTreeScene) {
1231 wxMessageBox("No behavior tree scene is currently active", "Save Error", wxOK | wxICON_ERROR);
1232 LOG_ERROR("Serializer", "No behavior tree scene is active");
1233 return;
1234 }
1235
1236 // Get the abstracted tree (ITreeStructure)
1237 auto treeStructure = behaviorTreeScene->GetAbstractedTree();
1238 if (!treeStructure) {
1239 wxMessageBox("No behavior tree is currently loaded", "Save Error", wxOK | wxICON_ERROR);
1240 LOG_ERROR("Serializer", "No behavior tree is loaded");
1241 return;
1242 }
1243
1244 // Cast to DirectTreeAdapter to access GetTree()
1245 auto adapter = dynamic_cast<EmberCore::DirectTreeAdapter *>(treeStructure);
1246 if (!adapter) {
1247 wxMessageBox("Unexpected tree adapter type", "Save Error", wxOK | wxICON_ERROR);
1248 LOG_ERROR("Serializer", "Tree adapter is not a DirectTreeAdapter");
1249 return;
1250 }
1251
1252 // 2. Get BehaviorTree from adapter
1253 std::shared_ptr<EmberCore::BehaviorTree> tree = adapter->GetTree();
1254 if (!tree) {
1255 wxMessageBox("Failed to access behavior tree data", "Save Error", wxOK | wxICON_ERROR);
1256 LOG_ERROR("Serializer", "Failed to get tree from adapter");
1257 return;
1258 }
1259
1260 // 3. Get parser config for validation
1261 auto &configMgr = EmberCore::ConfigManager::GetInstance();
1262 auto activeProfile = configMgr.GetActiveProfile();
1263 auto parserConfig = activeProfile ? activeProfile->GetConfig() : EmberCore::ParserConfig::CreateDefault();
1264
1265 // 4. Validate tree using unified validator
1266 EmberCore::BehaviorTreeValidator validator(parserConfig);
1267 auto validation = validator.Validate(tree.get());
1268
1269 // Build validation message with clear separation of errors and warnings
1270 bool hasIssues = validation.HasErrors() || validation.HasWarnings();
1271 if (hasIssues) {
1272 wxString msg;
1273
1274 // Show errors (during development, these are warnings that can be overridden)
1275 if (validation.HasErrors()) {
1276 msg += "⚠️ VALIDATION ERRORS (development mode allows saving):\n\n";
1277 for (const auto &issue : validation.issues) {
1279 wxString path = wxString::FromUTF8(issue.node_path.c_str());
1280 wxString message = wxString::FromUTF8(issue.message.c_str());
1281 if (!path.empty()) {
1282 msg += "• [" + path + "] " + message + "\n";
1283 } else {
1284 msg += "• " + message + "\n";
1285 }
1286 LOG_WARNING("Serializer", "Validation error: " + issue.message);
1287 }
1288 }
1289 msg += "\n";
1290 }
1291
1292 // Show warnings
1293 if (validation.HasWarnings()) {
1294 msg += "ℹ️ VALIDATION WARNINGS:\n\n";
1295 for (const auto &issue : validation.issues) {
1297 wxString path = wxString::FromUTF8(issue.node_path.c_str());
1298 wxString message = wxString::FromUTF8(issue.message.c_str());
1299 if (!path.empty()) {
1300 msg += "• [" + path + "] " + message + "\n";
1301 } else {
1302 msg += "• " + message + "\n";
1303 }
1304 LOG_INFO("Serializer", "Validation warning: " + issue.message);
1305 }
1306 }
1307 msg += "\n";
1308 }
1309
1310 msg += "These issues may cause problems when loading the file.\n";
1311 msg += "Save anyway? (Development workflow)";
1312
1313 wxString title = validation.HasErrors() ? "Validation Issues" : "Validation Warnings";
1314 int result = wxMessageBox(msg, title, wxYES_NO | wxICON_WARNING);
1315 if (result != wxYES) {
1316 LOG_INFO("Serializer", "Save cancelled by user due to validation issues");
1317 return;
1318 }
1319 }
1320
1321 // 5. Serialize using LibXMLBehaviorTreeSerializer
1322 EmberCore::LibXMLBehaviorTreeSerializer serializer(parserConfig);
1323 if (serializer.SerializeToFile(tree, filePath.ToStdString())) {
1324 m_currentFilePath = filePath;
1325 m_treeModified = false;
1326 SetStatusText("Saved: " + wxFileName(filePath).GetName());
1327 LOG_INFO("Serializer", "Tree saved successfully to: " + filePath.ToStdString());
1328
1329 wxMessageBox("Behavior tree saved successfully!", "Save Complete", wxOK | wxICON_INFORMATION);
1330 } else {
1331 // Show serialization errors
1332 wxString errorMessage = "Failed to save XML file:\n\n";
1333 const auto &errors = serializer.GetErrors();
1334 for (const auto &error : errors) {
1335 errorMessage += "• " + wxString::FromUTF8(error.message.c_str()) + "\n";
1336 }
1337
1338 wxMessageBox(errorMessage, "Save Error", wxOK | wxICON_ERROR);
1339 LOG_ERROR("Serializer", "Failed to save tree to: " + filePath.ToStdString());
1340 }
1341}
1342
1343// Settings menu event handlers
1344void MainFrame::OnPreferences(wxCommandEvent &event) {
1345 PreferencesDialog dialog(this);
1346 int result = dialog.ShowModal();
1347
1348 if (result == wxID_OK) {
1349 LOG_INFO("Config", "Preferences dialog closed with OK - settings applied");
1350 SetStatusText("Preferences updated");
1351
1352 // Apply preferences immediately
1354 } else {
1355 LOG_INFO("Config", "Preferences dialog cancelled");
1356 SetStatusText("Preferences cancelled");
1357 }
1358}
1359
1360void MainFrame::OnToggleLeftPanel(wxCommandEvent &event) {
1361 if (!m_auiManager)
1362 return;
1363
1364 wxAuiPaneInfo &pane = m_auiManager->GetPane("left_panel");
1365 if (pane.IsOk()) {
1366 pane.Show(!pane.IsShown());
1367 m_auiManager->Update();
1368
1369 // Update button bitmap to reflect toggle state
1370 wxBitmapButton *btn = dynamic_cast<wxBitmapButton *>(event.GetEventObject());
1371 if (btn) {
1372 wxString resourcePath = EmberForge::ResourcePath::GetDir("buttons/left_panel");
1373 if (pane.IsShown()) {
1374 btn->SetBitmap(wxBitmap(resourcePath + "Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1375 } else {
1376 btn->SetBitmap(wxBitmap(resourcePath + "Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1377 }
1378 }
1379
1380 LOG_INFO("UI", std::string("Left panel ") + (pane.IsShown() ? "shown" : "hidden"));
1381 SetStatusText(pane.IsShown() ? "Left panel shown" : "Left panel hidden");
1382 }
1383}
1384
1385void MainFrame::OnToggleBottomPanel(wxCommandEvent &event) {
1386 if (!m_auiManager)
1387 return;
1388
1389 wxAuiPaneInfo &pane = m_auiManager->GetPane("bottom_panel");
1390 if (pane.IsOk()) {
1391 pane.Show(!pane.IsShown());
1392 m_auiManager->Update();
1393
1394 // Update button bitmap to reflect toggle state
1395 wxBitmapButton *btn = dynamic_cast<wxBitmapButton *>(event.GetEventObject());
1396 if (btn) {
1397 wxString resourcePath = EmberForge::ResourcePath::GetDir("buttons/bottom_panel");
1398 if (pane.IsShown()) {
1399 btn->SetBitmap(wxBitmap(resourcePath + "Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1400 } else {
1401 btn->SetBitmap(wxBitmap(resourcePath + "Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1402 }
1403 }
1404
1405 LOG_INFO("UI", std::string("Bottom panel ") + (pane.IsShown() ? "shown" : "hidden"));
1406 SetStatusText(pane.IsShown() ? "Bottom panel shown" : "Bottom panel hidden");
1407 }
1408}
1409
1410void MainFrame::OnToggleRightPanel(wxCommandEvent &event) {
1411 if (!m_auiManager)
1412 return;
1413
1414 wxAuiPaneInfo &pane = m_auiManager->GetPane("right_panel");
1415 if (pane.IsOk()) {
1416 pane.Show(!pane.IsShown());
1417 m_auiManager->Update();
1418
1419 // Update button bitmap to reflect toggle state
1420 wxBitmapButton *btn = dynamic_cast<wxBitmapButton *>(event.GetEventObject());
1421 if (btn) {
1422 wxString resourcePath = EmberForge::ResourcePath::GetDir("buttons/right_panel");
1423 if (pane.IsShown()) {
1424 btn->SetBitmap(wxBitmap(resourcePath + "Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1425 } else {
1426 btn->SetBitmap(wxBitmap(resourcePath + "Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1427 }
1428 }
1429
1430 LOG_INFO("UI", std::string("Right panel ") + (pane.IsShown() ? "shown" : "hidden"));
1431 SetStatusText(pane.IsShown() ? "Right panel shown" : "Right panel hidden");
1432 }
1433}
1434
1437 return;
1438
1439 wxString resourcePath = EmberForge::ResourcePath::GetDir("buttons");
1440
1441 // Update left panel button
1442 wxAuiPaneInfo &leftPane = m_auiManager->GetPane("left_panel");
1443 wxWindow *leftWin = m_panelToggleToolbar->FindWindow(ID_ToggleLeftPanel);
1444 if (leftWin && leftPane.IsOk()) {
1445 wxBitmapButton *leftBtn = dynamic_cast<wxBitmapButton *>(leftWin);
1446 if (leftBtn) {
1447 if (leftPane.IsShown()) {
1448 leftBtn->SetBitmap(wxBitmap(resourcePath + "left_panel/Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1449 } else {
1450 leftBtn->SetBitmap(wxBitmap(resourcePath + "left_panel/Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1451 }
1452 }
1453 }
1454
1455 // Update bottom panel button
1456 wxAuiPaneInfo &bottomPane = m_auiManager->GetPane("bottom_panel");
1457 wxWindow *bottomWin = m_panelToggleToolbar->FindWindow(ID_ToggleBottomPanel);
1458 if (bottomWin && bottomPane.IsOk()) {
1459 wxBitmapButton *bottomBtn = dynamic_cast<wxBitmapButton *>(bottomWin);
1460 if (bottomBtn) {
1461 if (bottomPane.IsShown()) {
1462 bottomBtn->SetBitmap(
1463 wxBitmap(resourcePath + "bottom_panel/Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1464 } else {
1465 bottomBtn->SetBitmap(
1466 wxBitmap(resourcePath + "bottom_panel/Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1467 }
1468 }
1469 }
1470
1471 // Update right panel button
1472 wxAuiPaneInfo &rightPane = m_auiManager->GetPane("right_panel");
1473 wxWindow *rightWin = m_panelToggleToolbar->FindWindow(ID_ToggleRightPanel);
1474 if (rightWin && rightPane.IsOk()) {
1475 wxBitmapButton *rightBtn = dynamic_cast<wxBitmapButton *>(rightWin);
1476 if (rightBtn) {
1477 if (rightPane.IsShown()) {
1478 rightBtn->SetBitmap(
1479 wxBitmap(resourcePath + "right_panel/Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1480 } else {
1481 rightBtn->SetBitmap(
1482 wxBitmap(resourcePath + "right_panel/Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1483 }
1484 }
1485 }
1486}
1487
1488int MainFrame::CountTabGlobally(const wxString &tabName) const {
1489 int count = 0;
1490 if (m_leftPanel && m_leftPanel->HasTabWithName(tabName)) {
1491 count++;
1492 }
1493 if (m_rightPanel && m_rightPanel->HasTabWithName(tabName)) {
1494 count++;
1495 }
1496 if (m_bottomPanel && m_bottomPanel->HasTabWithName(tabName)) {
1497 count++;
1498 }
1499 return count;
1500}
1501
1502void MainFrame::OnParserConfig(wxCommandEvent &event) {
1503 ParserConfigDialog dialog(this);
1504 int result = dialog.ShowModal();
1505
1506 if (result == wxID_OK) {
1507 LOG_INFO("Config", "Parser configuration updated");
1508 SetStatusText("Parser configuration saved");
1509 } else {
1510 LOG_INFO("Config", "Parser configuration cancelled");
1511 SetStatusText("Parser configuration cancelled");
1512 }
1513}
1514
1515// Tool button event handlers (delegated to panels)
1516void MainFrame::OnEditorTool(wxCommandEvent &event) {
1517 PERF_TIME_BEGIN(editor_tool_operation);
1518 LOG_INFO("Tool", "Editor Tool activated - Opening editor for BT configuration");
1519 PERF_TIME_END(editor_tool_operation);
1520}
1521
1522void MainFrame::OnMonitorTool(wxCommandEvent &event) {
1523 PERF_TIME_BEGIN(monitor_tool_operation);
1524 LOG_INFO("Tool", "Monitor Tool activated - Opening performance monitor");
1525 PERF_TIME_END(monitor_tool_operation);
1526}
1527
1528void MainFrame::OnLogReplayTool(wxCommandEvent &event) {
1529 PERF_TIME_BEGIN(log_replay_tool_operation);
1530 LOG_INFO("Tool", "Log Replay Tool activated - Replaying performance logs");
1531 PERF_TIME_END(log_replay_tool_operation);
1532}
1533
1534// View menu event handlers
1535void MainFrame::OnToggleMaximize(wxCommandEvent &event) {
1536 PERF_TIME_BEGIN(maximize_toggle);
1537 bool isMaximized = IsMaximized();
1538 if (!isMaximized) {
1539 Maximize(true);
1540 LOG_INFO("View", "Maximized window");
1541 } else {
1542 Maximize(false);
1543 LOG_INFO("View", "Restored window to normal size");
1544 }
1545 PERF_TIME_END(maximize_toggle);
1546}
1547
1548void MainFrame::OnNextScene(wxCommandEvent &event) {
1549 if (m_scenePanel) {
1550 m_scenePanel->SwitchToNextScene();
1551 }
1552}
1553
1554void MainFrame::OnPreviousScene(wxCommandEvent &event) {
1555 if (m_scenePanel) {
1556 m_scenePanel->SwitchToPreviousScene();
1557 }
1558}
1559
1560void MainFrame::OnResetZoom(wxCommandEvent &event) {
1561 if (m_scenePanel) {
1562 IScene *activeScene = m_scenePanel->GetActiveScene();
1563 if (activeScene) {
1564 // Try to cast to BehaviorTreeScene to access view reset functionality
1565 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
1566 if (btScene && btScene->GetTreeVisualization()) {
1567 // Reset view (zoom + pan to default)
1568 btScene->GetTreeVisualization()->ResetView();
1569
1571 float defaultZoom = prefs.GetMainPanelSettings().defaultZoomLevel;
1572 int zoomPercent = static_cast<int>(defaultZoom * 100);
1573
1574 SetStatusText(wxString::Format("View reset (zoom: %d%%)", zoomPercent));
1575 LOG_INFO("View", "View reset to default (zoom + pan)");
1576 }
1577 }
1578 }
1579}
1580
1581void MainFrame::OnResetUI(wxCommandEvent &event) {
1582 // Confirm with user
1583 int result = wxMessageBox("This will:\n"
1584 "- Close the current project (if open)\n"
1585 "- Reset all preferences to defaults\n"
1586 "- Reset all panels to their default tabs\n\n"
1587 "Are you sure you want to reset the UI?",
1588 "Reset UI", wxYES_NO | wxICON_WARNING, this);
1589
1590 if (result != wxYES) {
1591 return;
1592 }
1593
1594 LOG_INFO("UI", "Resetting UI to defaults");
1595
1596 // 1. Close the project if one is open
1597 if (m_activeProject) {
1598 CloseProject();
1599 LOG_INFO("UI", "Closed active project");
1600 }
1601
1602 // 2. Reset preferences to defaults
1604 EmberForge::AppPreferences defaultPrefs;
1605 prefsMgr.GetPreferences() = defaultPrefs;
1606
1607 std::string configPath = EmberForge::AppPreferences::GetDefaultConfigPath();
1608 prefsMgr.GetPreferences().SaveToFile(configPath);
1609 LOG_INFO("Preferences", "Reset preferences to defaults and saved to: " + configPath);
1610
1611 // 3. Reset panels - show them if hidden and set to default tabs only
1612 // Show all panels first
1613 if (m_auiManager) {
1614 wxAuiPaneInfo &leftPane = m_auiManager->GetPane("left_panel");
1615 if (leftPane.IsOk() && !leftPane.IsShown()) {
1616 leftPane.Show();
1617 }
1618
1619 wxAuiPaneInfo &rightPane = m_auiManager->GetPane("right_panel");
1620 if (rightPane.IsOk() && !rightPane.IsShown()) {
1621 rightPane.Show();
1622 }
1623
1624 wxAuiPaneInfo &bottomPane = m_auiManager->GetPane("bottom_panel");
1625 if (bottomPane.IsOk() && !bottomPane.IsShown()) {
1626 bottomPane.Show();
1627 }
1628
1629 m_auiManager->Update();
1630 }
1631
1632 // Reset each panel to its default tab
1633 // Phase 1: Clear all panels first to avoid global instance limit conflicts
1634 // (e.g., if SceneHierarchy was moved from left to right panel, clearing first
1635 // ensures the global count is 0 when we create the default tabs)
1636 if (m_leftPanel) {
1637 m_leftPanel->ClearAllTabs();
1638 }
1639 if (m_rightPanel) {
1640 m_rightPanel->ClearAllTabs();
1641 }
1642 if (m_bottomPanel) {
1643 m_bottomPanel->ClearAllTabs();
1644 }
1645
1646 // Phase 2: Now create default tabs (global instance checks will pass)
1647 if (m_leftPanel) {
1649 }
1650 if (m_rightPanel) {
1652 }
1653 if (m_bottomPanel) {
1655 }
1656
1657 // 4. Update the visuals
1661
1662 // Force a full layout update
1663 if (m_auiManager) {
1664 m_auiManager->Update();
1665 }
1666 Layout();
1667 Refresh();
1668
1669 SetStatusText("UI reset to defaults");
1670 LOG_INFO("UI", "UI reset complete");
1671}
1672
1673void MainFrame::LogMessage(const wxString &message) {
1674 if (m_bottomPanel && m_bottomPanel->GetLogOutput()) {
1675 wxDateTime now = wxDateTime::Now();
1676 wxString timestamp = now.Format("%Y-%m-%d %H:%M:%S");
1677 wxString logEntry = wxString::Format("%s %s\n", timestamp, message);
1678
1679 m_bottomPanel->GetLogOutput()->AppendText(logEntry);
1680 m_bottomPanel->GetLogOutput()->SetInsertionPointEnd();
1681 }
1682}
1683
1685 // Check if hierarchy → scene sync is enabled
1687 if (!config.GetSyncSettings().enableHierarchyToScene) {
1688 if (config.GetDebugSettings().enableSyncLogging) {
1689 LOG_INFO("Sync", "Hierarchy → Scene: Disabled by configuration");
1690 }
1691 return;
1692 }
1693
1694 // Prevent infinite loops
1696 if (config.GetDebugSettings().enableSyncLogging) {
1697 LOG_INFO("Sync", "Hierarchy → Scene: Skipped (already updating from scene)");
1698 }
1699 return;
1700 }
1701
1702 // Debug logging
1703 if (config.GetDebugSettings().enableSyncLogging) {
1704 LOG_INFO("Sync", "Hierarchy → Scene: Node selected in hierarchy tab");
1705 }
1706
1707 // Set flag to prevent loops
1709
1710 // Safety check: Ensure scene panel exists and is valid
1711 if (!m_scenePanel) {
1712 LOG_ERROR("Sync", "Scene panel is null");
1714 return;
1715 }
1716
1717 // Get the active scene and check if it's a behavior tree scene
1718 IScene *activeScene = m_scenePanel->GetActiveScene();
1719 if (!activeScene || activeScene->GetSceneType() != "BehaviorTree") {
1720 LOG_ERROR("Sync", "No active behavior tree scene");
1722 return;
1723 }
1724
1725 // Cast to BehaviorTreeScene to access tree visualization
1726 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
1727 if (!btScene) {
1728 LOG_ERROR("Sync", "Failed to cast to BehaviorTreeScene");
1730 return;
1731 }
1732
1734 if (!treeVis) {
1735 LOG_ERROR("Sync", "Tree visualization is null");
1737 return;
1738 }
1739
1740 // Additional safety: Check if the scene's panel is still valid
1741 wxPanel *scenePanel = btScene->GetPanel();
1742 if (!scenePanel || !scenePanel->IsShown()) {
1743 LOG_ERROR("Sync", "Scene panel is not shown");
1745 return;
1746 }
1747
1748 // Set the selected node in the scene view if highlighting is enabled
1749 // Note: Centering on node is NOT done here - it's only done on double-click
1750 // when the doubleClickAction preference is set to CenterInCanvas
1751 if (config.GetSyncSettings().enableSelectionHighlight) {
1752 if (config.GetDebugSettings().enableSyncLogging) {
1753 LOG_INFO("Sync", "Hierarchy → Scene: Calling treeVis->SetSelectedNode()");
1754 }
1755 treeVis->SetSelectedNode(selectedNode);
1756 }
1757
1758 // Update properties view
1759 if (m_propertiesTab) {
1760 if (selectedNode) {
1761 // Convert ITreeNode back to Node for properties tab
1762 auto nodeAdapter = dynamic_cast<const EmberCore::NodeAdapter *>(selectedNode);
1763 if (nodeAdapter) {
1764 EmberCore::Node *legacyNode = nodeAdapter->GetWrappedNode();
1765 if (config.GetDebugSettings().enableSyncLogging) {
1766 LOG_INFO("Sync", "Hierarchy → Properties: Updating properties with node: " + legacyNode->GetName());
1767 }
1768 m_propertiesTab->SetSelectedNode(legacyNode);
1769 }
1770 } else {
1771 if (config.GetDebugSettings().enableSyncLogging) {
1772 LOG_INFO("Sync", "Hierarchy → Properties: Clearing properties selection");
1773 }
1774 m_propertiesTab->ClearSelection();
1775 }
1776 }
1777
1778 if (config.GetDebugSettings().enableSyncLogging) {
1779 LOG_INFO("Sync", "Hierarchy → Scene: Sync operations completed");
1780 }
1781
1782 // Clear flag
1784}
1785
1787 // Check if scene → hierarchy sync is enabled
1789 if (!config.GetSyncSettings().enableSceneToHierarchy) {
1790 if (config.GetDebugSettings().enableSyncLogging) {
1791 LOG_INFO("Sync", "Scene → Hierarchy: Disabled by configuration");
1792 }
1793 return;
1794 }
1795
1796 // Prevent infinite loops
1798 if (config.GetDebugSettings().enableSyncLogging) {
1799 LOG_INFO("Sync", "Scene → Hierarchy: Skipped (already updating from hierarchy)");
1800 }
1801 return;
1802 }
1803
1804 // Debug logging
1805 if (config.GetDebugSettings().enableSyncLogging) {
1806 LOG_INFO("Sync", "Scene → Hierarchy: Node selected in scene view");
1807 }
1808
1809 // Set flag to prevent loops
1810 m_isUpdatingFromScene = true;
1811
1812 // Safety check: Ensure hierarchy tab exists and is valid
1813 if (!m_hierarchyTab) {
1814 LOG_ERROR("Sync", "Hierarchy tab is null");
1815 m_isUpdatingFromScene = false;
1816 return;
1817 }
1818
1819 // Convert ITreeNode back to Node for legacy hierarchy tab
1820 // TODO: Update hierarchy tab to use abstraction layer in the future
1821 EmberCore::Node *legacyNode = nullptr;
1822 if (selectedNode) {
1823 // Check if this is a NodeAdapter and extract the wrapped node
1824 auto nodeAdapter = dynamic_cast<const EmberCore::NodeAdapter *>(selectedNode);
1825 if (nodeAdapter) {
1826 legacyNode = nodeAdapter->GetWrappedNode();
1827
1828 if (config.GetDebugSettings().enableSyncLogging) {
1829 LOG_INFO("Sync", "Scene → Hierarchy: Converted ITreeNode to Node: " + legacyNode->GetName());
1830 }
1831 } else {
1832 LOG_WARNING("Sync", "Selected node is not a NodeAdapter");
1833 }
1834 } else {
1835 LOG_INFO("Sync", "Scene → Hierarchy: No node selected (null)");
1836 }
1837
1838 // Update the hierarchy tab selection to match the scene view
1839 LOG_INFO("Sync", "Scene → Hierarchy: Calling hierarchyTab->SelectNode()");
1840 m_hierarchyTab->SelectNode(legacyNode);
1841 LOG_INFO("Sync", "Scene → Hierarchy: Selection update completed");
1842
1843 // Update properties view
1844 if (m_propertiesTab) {
1845 if (legacyNode) {
1846 LOG_INFO("Sync", "Scene → Properties: Updating properties with node: " + legacyNode->GetName());
1847 m_propertiesTab->SetSelectedNode(legacyNode);
1848 } else {
1849 LOG_INFO("Sync", "Scene → Properties: Clearing properties selection");
1850 m_propertiesTab->ClearSelection();
1851 }
1852 }
1853
1854 // Clear flag
1855 m_isUpdatingFromScene = false;
1856}
1857
1859 LOG_INFO("MainFrame", "PropertiesTab is being closed, nullifying pointer");
1860 m_propertiesTab = nullptr;
1861}
1862
1864 LOG_INFO("MainFrame", "HierarchyTab is being closed, nullifying pointer");
1865 m_hierarchyTab = nullptr;
1866}
1867
1869 LOG_INFO("MainFrame", "TreeSelectorTab is being closed, nullifying pointer");
1870 m_treeSelectorTab = nullptr;
1871}
1872
1874 m_treeSelectorTab = treeSelectorTab;
1875
1876 if (m_treeSelectorTab) {
1877 // Wire up the selection callback
1878 m_treeSelectorTab->SetTreeSelectionCallback([this](const std::string &treeId) {
1879 if (treeId != m_currentTreeId) {
1880 LoadTreeIntoScene(treeId);
1882 }
1883 });
1884
1885 // Populate with current project trees if a project is loaded
1886 if (!m_projectTrees.empty()) {
1888 }
1889
1890 LOG_INFO("MainFrame", "Tree selector tab reference updated and wired");
1891 }
1892}
1893
1894std::shared_ptr<EmberCore::Node> MainFrame::GetSharedBehaviorTree() const {
1895 if (!m_scenePanel) {
1896 return nullptr;
1897 }
1898
1899 // Get the active scene
1900 IScene *activeScene = m_scenePanel->GetActiveScene();
1901 if (!activeScene || activeScene->GetSceneType() != "BehaviorTree") {
1902 return nullptr;
1903 }
1904
1905 // Cast to BehaviorTreeScene to access the behavior tree
1906 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
1907 if (!btScene) {
1908 return nullptr;
1909 }
1910
1911 // Get the behavior tree root and wrap in shared_ptr
1912 EmberCore::Node *rawTree = btScene->GetBehaviorTree();
1913 if (!rawTree) {
1914 return nullptr;
1915 }
1916
1917 // Return as shared_ptr (the scene owns it, so we use a non-owning shared_ptr)
1918 return std::shared_ptr<EmberCore::Node>(rawTree, [](EmberCore::Node *) {});
1919}
1920
1922 m_hierarchyTab = hierarchyTab;
1923
1924 // If we have both a hierarchy tab and a behavior tree, set it
1925 if (m_hierarchyTab) {
1926 auto sharedTree = GetSharedBehaviorTree();
1927 if (sharedTree) {
1928 m_hierarchyTab->SetRootNode(sharedTree);
1929 LOG_INFO("MainFrame", "Set behavior tree on newly created hierarchy tab");
1930 }
1931 }
1932}
1933
1935 m_propertiesTab = propertiesTab;
1936
1937 // If we have a properties tab, set the currently selected node (if any)
1939 IScene *activeScene = m_scenePanel->GetActiveScene();
1940 if (activeScene && activeScene->GetSceneType() == "BehaviorTree") {
1941 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
1942 if (btScene) {
1944 if (treeVis) {
1945 EmberCore::ITreeNode *selectedNode = treeVis->GetSelectedNode();
1946 if (selectedNode) {
1947 // Convert ITreeNode to Node for properties tab
1948 auto nodeAdapter = dynamic_cast<const EmberCore::NodeAdapter *>(selectedNode);
1949 if (nodeAdapter) {
1950 EmberCore::Node *legacyNode = nodeAdapter->GetWrappedNode();
1951 m_propertiesTab->SetSelectedNode(legacyNode);
1952 LOG_INFO("MainFrame", "Set selected node on newly created properties tab");
1953 }
1954 }
1955 }
1956 }
1957 }
1958 }
1959}
1960
1962 // Safety checks: Ensure scene panel and node are valid
1963 if (!m_scenePanel || !node) {
1964 return;
1965 }
1966
1967 // Get the active scene and check if it's a behavior tree scene
1968 IScene *activeScene = m_scenePanel->GetActiveScene();
1969 if (!activeScene || activeScene->GetSceneType() != "BehaviorTree") {
1970 return;
1971 }
1972
1973 // Cast to BehaviorTreeScene to access tree visualization
1974 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
1975 if (!btScene) {
1976 return;
1977 }
1978
1980 if (!treeVis) {
1981 return;
1982 }
1983
1984 // Additional safety: Check if the scene's panel is still valid
1985 wxPanel *scenePanel = btScene->GetPanel();
1986 if (!scenePanel || !scenePanel->IsShown()) {
1987 return;
1988 }
1989
1990 // Center the view on the selected node
1991 treeVis->CenterOnNode(node);
1992}
1993
1995 // Prevent infinite loops between views
1996 static bool updating = false;
1997 if (updating) {
1998 LOG_INFO("Sync", "SyncSelection: Prevented infinite loop");
1999 return;
2000 }
2001 updating = true;
2002
2003 LOG_INFO("Sync", "SyncSelection: Synchronizing selection to: " + (selectedNode ? selectedNode->GetName() : "null"));
2004
2005 // Update hierarchy view
2006 if (m_hierarchyTab && selectedNode) {
2007 // Convert ITreeNode back to Node for hierarchy tab
2008 auto nodeAdapter = dynamic_cast<const EmberCore::NodeAdapter *>(selectedNode);
2009 if (nodeAdapter) {
2010 EmberCore::Node *legacyNode = nodeAdapter->GetWrappedNode();
2011 LOG_INFO("Sync", "SyncSelection: Updating hierarchy with node: " + legacyNode->GetName());
2012 m_hierarchyTab->SelectNode(legacyNode);
2013 }
2014 }
2015
2016 // Update properties view
2017 if (m_propertiesTab) {
2018 if (selectedNode) {
2019 // Convert ITreeNode back to Node for properties tab
2020 auto nodeAdapter = dynamic_cast<const EmberCore::NodeAdapter *>(selectedNode);
2021 if (nodeAdapter) {
2022 EmberCore::Node *legacyNode = nodeAdapter->GetWrappedNode();
2023 LOG_INFO("Sync", "SyncSelection: Updating properties with node: " + legacyNode->GetName());
2024 m_propertiesTab->SetSelectedNode(legacyNode);
2025 }
2026 } else {
2027 LOG_INFO("Sync", "SyncSelection: Clearing properties selection");
2028 m_propertiesTab->ClearSelection();
2029 }
2030 }
2031
2032 // Update scene view
2033 if (m_scenePanel) {
2034 IScene *activeScene = m_scenePanel->GetActiveScene();
2035 if (activeScene && activeScene->GetSceneType() == "BehaviorTree") {
2036 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(activeScene);
2037 if (btScene && btScene->GetTreeVisualization()) {
2038 LOG_INFO("Sync", "SyncSelection: Updating scene view");
2039 btScene->GetTreeVisualization()->SetSelectedNode(selectedNode);
2040 }
2041 }
2042 }
2043
2044 updating = false;
2045 LOG_INFO("Sync", "SyncSelection: Synchronization completed");
2046}
2047
2048// ============================================================================
2049// Project Operations
2050// ============================================================================
2051
2052void MainFrame::OnNewProject(wxCommandEvent &event) { NewProject(); }
2053
2054void MainFrame::OnOpenProject(wxCommandEvent &event) { OpenProject(); }
2055
2056void MainFrame::OnCloseProject(wxCommandEvent &event) { CloseProject(); }
2057
2058void MainFrame::OnSaveProject(wxCommandEvent &event) { SaveProject(); }
2059
2060void MainFrame::OnProjectSettings(wxCommandEvent &event) {
2061 LOG_INFO("Menu", "OnProjectSettings called");
2063}
2064
2066 LOG_INFO("Project", "Creating new project...");
2067
2068 BehaviorTreeProjectDialog dialog(this, nullptr);
2069 int result = dialog.ShowModal();
2070
2071 if (result == wxID_OK) {
2072 auto project = dialog.GetProject();
2073 if (project) {
2074 // Get default my_projects directory
2075 wxString defaultProjectsDir = EmberForge::ResourcePath::GetDir("my_projects");
2076
2077 // Create directory if it doesn't exist
2078 if (!wxFileName::DirExists(defaultProjectsDir)) {
2079 wxFileName::Mkdir(defaultProjectsDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
2080 }
2081
2082 // Ask where to save the project
2083 wxFileDialog saveDialog(this, "Save BehaviorTree Project", defaultProjectsDir,
2084 wxString::FromUTF8(project->GetName()) + ".btproj",
2085 "BehaviorTree Project (*.btproj)|*.btproj", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
2086
2087 if (saveDialog.ShowModal() == wxID_OK) {
2088 wxString projectPath = saveDialog.GetPath();
2089 project->SetProjectFilePath(projectPath.ToStdString());
2090
2091 if (project->SaveToFile(projectPath.ToStdString())) {
2092 m_activeProject = project;
2093
2094 // Add to recent projects
2095 auto &projectManager = EmberCore::ProjectManager::GetInstance();
2096 projectManager.AddToRecentProjects(projectPath.ToStdString());
2097
2098 // Parse and load the project
2099 OpenProject(projectPath);
2100
2101 LOG_INFO("Project", "Project created and saved: " + projectPath.ToStdString());
2102 SetStatusText("Project created: " + wxString::FromUTF8(project->GetName()));
2103 } else {
2104 wxMessageBox("Failed to save project file.", "Error", wxOK | wxICON_ERROR, this);
2105 LOG_ERROR("Project", "Failed to save project file");
2106 }
2107 }
2108 }
2109 }
2110}
2111
2113 LOG_INFO("Project", "Opening project dialog...");
2114
2115 ProjectManagerDialog dialog(this);
2116 int result = dialog.ShowModal();
2117
2118 if (result == wxID_OK && dialog.HasSelectedProject()) {
2120 }
2121}
2122
2123void MainFrame::OpenProject(const wxString &projectPath) {
2124 LOG_INFO("Project", "Opening project: " + projectPath.ToStdString());
2125
2126 // Load the project
2127 auto project = std::make_shared<EmberCore::BehaviorTreeProject>();
2128 if (!project->LoadFromFile(projectPath.ToStdString())) {
2129 wxMessageBox("Failed to load project file.", "Error", wxOK | wxICON_ERROR, this);
2130 LOG_ERROR("Project", "Failed to load project from: " + projectPath.ToStdString());
2131 return;
2132 }
2133
2134 // Close any existing project
2135 if (m_activeProject) {
2136 CloseProject();
2137 }
2138
2139 m_activeProject = project;
2140
2141 // Add to recent projects
2142 auto &projectManager = EmberCore::ProjectManager::GetInstance();
2143 projectManager.AddToRecentProjects(projectPath.ToStdString());
2144
2145 // Get the parser profile
2146 auto &configManager = EmberCore::ConfigManager::GetInstance();
2147 auto profile = configManager.GetProfile(project->GetParserProfileName());
2148 if (!profile) {
2149 profile = configManager.GetActiveProfile();
2150 }
2151
2152 // Create parser and parse project files
2153 EmberCore::LibXMLBehaviorTreeParser parser(profile->GetConfig());
2154
2155 // Show loading dialog
2156 LoadingDialog loadingDialog(this, "Loading Project: " + wxString::FromUTF8(project->GetName()));
2157 loadingDialog.Show();
2158 wxYield();
2159
2160 // Progress callback to forward parser progress to the dialog
2161 class ProjectProgressCallback : public EmberCore::IParseProgressCallback {
2162 private:
2163 LoadingDialog *dialog_;
2164
2165 public:
2166 explicit ProjectProgressCallback(LoadingDialog *dialog) : dialog_(dialog) {}
2167
2168 bool OnProgress(const EmberCore::String &message, int current, int total) override {
2169 if (dialog_) {
2170 bool shouldContinue = dialog_->UpdateProgress(current, total, message);
2171 wxMilliSleep(30); // Small delay to make progress visible
2172 return shouldContinue;
2173 }
2174 return true;
2175 }
2176 };
2177
2178 ProjectProgressCallback progressCallback(&loadingDialog);
2179 parser.SetProgressCallback(&progressCallback);
2180
2181 // Log project information before parsing
2182 loadingDialog.AppendLog("Project: " + wxString::FromUTF8(project->GetName()), "[INFO]");
2183 loadingDialog.AppendLog("Parser Profile: " + wxString::FromUTF8(profile->GetName()), "[INFO]");
2184 loadingDialog.AppendLog("Resource Files: " + wxString::Format("%zu", project->GetResourceCount()), "[INFO]");
2185 loadingDialog.AppendLog("", ""); // Blank line
2186
2187 // List files to be parsed
2188 const auto &resources = project->GetResources();
2189 for (size_t i = 0; i < resources.size(); ++i) {
2190 wxFileName fn(wxString::FromUTF8(project->ResolveResourcePath(resources[i])));
2191 loadingDialog.AppendLog(wxString::Format(" %zu. %s", i + 1, fn.GetFullName()), "[FILE]");
2192 }
2193 loadingDialog.AppendLog("", ""); // Blank line
2194 loadingDialog.AppendLog("Starting parser...", "[INIT]");
2195 wxYield();
2196
2197 // Parse the project
2198 auto parseResult = parser.ParseProject(project.get());
2199
2200 // Log per-file parsing results
2201 loadingDialog.AppendLog("", ""); // Blank line
2202 loadingDialog.AppendLog("=== Per-File Parsing Results ===", "[INFO]");
2203
2204 int totalTrees = 0;
2205 int totalBlackboards = 0;
2206 int totalWarnings = 0;
2207 int totalErrors = 0;
2208
2209 for (const auto &fileInfo : parseResult.file_infos) {
2210 wxFileName fn(wxString::FromUTF8(fileInfo.filepath));
2211 wxString filename = fn.GetFullName();
2212
2213 if (fileInfo.parsed_successfully) {
2214 loadingDialog.AppendLog(filename + " - Parsed successfully", "[SUCCESS]");
2215 } else {
2216 loadingDialog.AppendLog(filename + " - Parse FAILED", "[ERROR]");
2217 }
2218
2219 // Show trees found
2220 if (fileInfo.tree_count > 0) {
2221 wxString treeList;
2222 for (size_t i = 0; i < fileInfo.tree_ids.size(); ++i) {
2223 if (i > 0)
2224 treeList += ", ";
2225 treeList += wxString::FromUTF8(fileInfo.tree_ids[i]);
2226 }
2227 loadingDialog.AppendLog(wxString::Format(" Trees: %d (%s)", fileInfo.tree_count, treeList), "[INFO]");
2228 totalTrees += fileInfo.tree_count;
2229 }
2230
2231 // Show blackboards found
2232 if (fileInfo.blackboard_count > 0) {
2233 wxString bbList;
2234 for (size_t i = 0; i < fileInfo.blackboard_ids.size(); ++i) {
2235 if (i > 0)
2236 bbList += ", ";
2237 bbList += wxString::FromUTF8(fileInfo.blackboard_ids[i]);
2238 }
2239 loadingDialog.AppendLog(wxString::Format(" Blackboards: %d (%s)", fileInfo.blackboard_count, bbList),
2240 "[INFO]");
2241 totalBlackboards += fileInfo.blackboard_count;
2242 }
2243
2244 // Show SubTree references
2245 if (!fileInfo.subtree_refs.empty()) {
2246 wxString refList;
2247 for (size_t i = 0; i < fileInfo.subtree_refs.size(); ++i) {
2248 if (i > 0)
2249 refList += ", ";
2250 refList += wxString::FromUTF8(fileInfo.subtree_refs[i]);
2251 }
2252 loadingDialog.AppendLog(" SubTree refs: " + refList, "[INFO]");
2253 }
2254
2255 // Show warnings
2256 for (const auto &warning : fileInfo.warnings) {
2257 loadingDialog.AppendLog(" " + wxString::FromUTF8(warning), "[WARN]");
2258 totalWarnings++;
2259 }
2260
2261 // Show errors
2262 for (const auto &error : fileInfo.errors) {
2263 loadingDialog.AppendLog(" " + wxString::FromUTF8(error), "[ERROR]");
2264 totalErrors++;
2265 }
2266 }
2267
2268 // Log project-level issues
2269 if (!parseResult.unimplemented_references.empty()) {
2270 loadingDialog.AppendLog("", "");
2271 loadingDialog.AppendLog("=== Unimplemented Tree References ===", "[WARN]");
2272 for (const auto &ref : parseResult.unimplemented_references) {
2273 loadingDialog.AppendLog(" " + wxString::FromUTF8(ref), "[WARN]");
2274 }
2275 }
2276
2277 if (!parseResult.duplicate_tree_ids.empty()) {
2278 loadingDialog.AppendLog("", "");
2279 loadingDialog.AppendLog("=== Duplicate Tree IDs ===", "[WARN]");
2280 for (const auto &dup : parseResult.duplicate_tree_ids) {
2281 loadingDialog.AppendLog(" " + wxString::FromUTF8(dup), "[WARN]");
2282 }
2283 }
2284
2285 if (!parseResult.duplicate_blackboard_ids.empty()) {
2286 loadingDialog.AppendLog("", "");
2287 loadingDialog.AppendLog("=== Duplicate Blackboard IDs ===", "[WARN]");
2288 for (const auto &dup : parseResult.duplicate_blackboard_ids) {
2289 loadingDialog.AppendLog(" " + wxString::FromUTF8(dup), "[WARN]");
2290 }
2291 }
2292
2293 if (!parseResult.unresolved_blackboard_includes.empty()) {
2294 loadingDialog.AppendLog("", "");
2295 loadingDialog.AppendLog("=== Unresolved Blackboard Includes ===", "[WARN]");
2296 for (const auto &unres : parseResult.unresolved_blackboard_includes) {
2297 loadingDialog.AppendLog(" " + wxString::FromUTF8(unres), "[WARN]");
2298 }
2299 }
2300
2301 // Summary
2302 loadingDialog.AppendLog("", "");
2303 loadingDialog.AppendLog("=== Summary ===", "[INFO]");
2304 loadingDialog.AppendLog(wxString::Format("Files parsed: %zu", parseResult.file_infos.size()), "[INFO]");
2305 loadingDialog.AppendLog(wxString::Format("Total trees: %d", totalTrees), "[INFO]");
2306 loadingDialog.AppendLog(wxString::Format("Total blackboards: %d", totalBlackboards), "[INFO]");
2307 if (totalWarnings > 0) {
2308 loadingDialog.AppendLog(wxString::Format("Warnings: %d", totalWarnings), "[WARN]");
2309 }
2310 if (totalErrors > 0) {
2311 loadingDialog.AppendLog(wxString::Format("Errors: %d", totalErrors), "[ERROR]");
2312 }
2313
2314 wxYield();
2315
2316 if (parseResult.success) {
2317 // Update project with tree statuses
2318 project->SetTreeImplementationStatus(parseResult.tree_statuses);
2319
2320 // Store ALL parsed trees (not just main)
2321 m_projectTrees = parseResult.parsed_trees;
2322
2323 // Check if there's a valid main tree entry point
2324 bool hasMainTreeEntryPoint = !parseResult.main_tree_name.empty() &&
2325 m_projectTrees.find(parseResult.main_tree_name) != m_projectTrees.end();
2326
2327 if (hasMainTreeEntryPoint) {
2328 // Found main tree entry point - load it normally
2329 LOG_INFO("Project", "Found main tree entry point: " + parseResult.main_tree_name);
2330 loadingDialog.AppendLog("Main tree: " + wxString::FromUTF8(parseResult.main_tree_name), "[INFO]");
2331 LoadTreeIntoScene(parseResult.main_tree_name);
2332 } else if (!m_projectTrees.empty()) {
2333 // No main tree entry point found
2334 // FIXED: Skip expensive overview scene creation for large projects (>20 trees)
2335 // Instead, user can select trees from the dropdown
2336 if (m_projectTrees.size() > 20) {
2337 LOG_INFO("Project", "No main tree entry point found - project has " +
2338 std::to_string(m_projectTrees.size()) +
2339 " trees. Use tree selector to view individual trees.");
2340 loadingDialog.AppendLog("No main tree - loading first tree", "[INFO]");
2341
2342 // Load the first tree as a starting point
2343 if (!m_projectTrees.empty()) {
2344 LoadTreeIntoScene(m_projectTrees.begin()->first);
2345 }
2346 } else {
2347 // Small project - create overview scene with all trees side-by-side
2348 LOG_INFO("Project", "No main tree entry point found - creating project overview with all trees");
2349 loadingDialog.AppendLog("No main tree - creating project overview", "[INFO]");
2351 }
2352 }
2353
2354 // Update tree selector dropdown
2356
2357 loadingDialog.AppendLog("", "");
2358 loadingDialog.AppendLog("Project loaded successfully!", "[COMPLETE]");
2359 loadingDialog.UpdateProgress(100, 100, "Project loaded successfully");
2360 wxYield();
2361
2362 // Mark as complete and keep dialog open for review
2363 loadingDialog.MarkComplete();
2364
2365 LOG_INFO("Project", "Project loaded successfully: " + project->GetName() + " with " +
2366 std::to_string(m_projectTrees.size()) + " trees");
2367 SetStatusText("Project: " + wxString::FromUTF8(project->GetName()) + " (" +
2368 wxString::Format("%zu", m_projectTrees.size()) + " trees)");
2369
2370 // Keep dialog open until user closes it
2371 loadingDialog.ShowModal();
2372 } else {
2373 // Mark as complete even on error so user can review logs
2374 loadingDialog.AppendLog("Project parsing failed", "[ERROR]");
2375
2376 wxString errorMsg = "Failed to parse project files:\n\n";
2377 for (const auto &err : parseResult.errors) {
2378 errorMsg += "- " + wxString::FromUTF8(err.message) + "\n";
2379 }
2380
2381 // Log errors to the dialog
2382 for (const auto &err : parseResult.errors) {
2383 loadingDialog.AppendLog(wxString::FromUTF8(err.message), "[ERROR]");
2384 }
2385
2386 loadingDialog.MarkComplete();
2387
2388 LOG_ERROR("Project", "Failed to parse project files");
2389
2390 // Keep dialog open until user closes it
2391 loadingDialog.ShowModal();
2392
2393 wxMessageBox(errorMsg, "Error", wxOK | wxICON_ERROR, this);
2394
2395 m_activeProject = nullptr;
2396 m_projectTrees.clear();
2397 m_currentTreeId.clear();
2398 }
2399}
2400
2401void MainFrame::LoadTreeIntoScene(const std::string &treeId) {
2402 if (m_projectTrees.find(treeId) == m_projectTrees.end()) {
2403 LOG_WARNING("MainFrame", "Tree not found: " + treeId);
2404 return;
2405 }
2406
2407 auto tree = m_projectTrees[treeId];
2408 m_currentTreeId = treeId;
2409
2410 if (tree && m_scenePanel) {
2411 IScene *scene = m_scenePanel->GetActiveScene();
2412 if (scene && scene->GetSceneType() == "BehaviorTree") {
2413 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(scene);
2414 if (btScene) {
2415 EmberCore::Node *rootNodePtr = tree->GetRootNode();
2416 if (rootNodePtr) {
2417 // Use aliasing constructor to create shared_ptr that shares ownership with tree
2418 std::shared_ptr<EmberCore::Node> rootNode(tree, rootNodePtr);
2419 btScene->SetBehaviorTree(rootNode);
2420
2421 // Update hierarchy if available
2422 if (m_hierarchyTab) {
2423 m_hierarchyTab->SetRootNode(rootNode);
2424 }
2425
2426 // Update status bar
2427 SetStatusText("Viewing tree: " + wxString::FromUTF8(treeId));
2428 LOG_INFO("MainFrame", "Loaded tree into scene: " + treeId);
2429 }
2430 }
2431 }
2432 }
2433}
2434
2435void MainFrame::OpenTreeInNewScene(const std::string &treeId) {
2436 if (m_projectTrees.find(treeId) == m_projectTrees.end()) {
2437 LOG_WARNING("MainFrame", "Tree not found: " + treeId);
2438 return;
2439 }
2440
2441 if (!m_scenePanel) {
2442 LOG_ERROR("MainFrame", "Scene panel not available");
2443 return;
2444 }
2445
2446 auto tree = m_projectTrees[treeId];
2447 if (!tree)
2448 return;
2449
2450 int sceneIdx = m_scenePanel->CreateNewScene(wxString::FromUTF8(treeId));
2451 if (sceneIdx < 0)
2452 return;
2453
2454 IScene *scene = m_scenePanel->GetScene(sceneIdx);
2455 if (!scene || scene->GetSceneType() != "BehaviorTree")
2456 return;
2457
2458 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(scene);
2459 if (!btScene)
2460 return;
2461
2462 EmberCore::Node *rootNodePtr = tree->GetRootNode();
2463 if (rootNodePtr) {
2464 std::shared_ptr<EmberCore::Node> rootNode(tree, rootNodePtr);
2465 btScene->SetBehaviorTree(rootNode);
2466
2468
2469 // Update hierarchy tab
2470 if (m_hierarchyTab) {
2471 m_hierarchyTab->SetRootNode(rootNode);
2472 }
2473 }
2474
2475 m_scenePanel->SetActiveScene(sceneIdx);
2476 m_currentTreeId = treeId;
2478 SetStatusText("Viewing tree: " + wxString::FromUTF8(treeId));
2479 LOG_INFO("MainFrame", "Opened tree '" + treeId + "' in new scene");
2480}
2481
2483 if (!m_scenePanel || m_projectTrees.empty()) {
2484 return;
2485 }
2486
2487 LOG_INFO("MainFrame", "Creating project overview scene with " + std::to_string(m_projectTrees.size()) + " trees");
2488
2489 IScene *scene = m_scenePanel->GetActiveScene();
2490 if (!scene || scene->GetSceneType() != "BehaviorTree") {
2491 return;
2492 }
2493
2494 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(scene);
2495 if (!btScene) {
2496 return;
2497 }
2498
2499 // Get the tree visualization panel
2501 if (!treeVis) {
2502 return;
2503 }
2504
2505 // Create a scrolled window to hold all trees
2506 wxScrolled<wxPanel> *overviewPanel = new wxScrolled<wxPanel>(btScene->GetPanel(), wxID_ANY);
2507 overviewPanel->SetBackgroundColour(wxColour(45, 45, 50));
2508 overviewPanel->SetScrollRate(20, 20);
2509
2510 // Use horizontal box sizer to arrange trees side-by-side
2511 wxBoxSizer *horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
2512
2513 // Create a tree visualization for each tree
2514 size_t treeIndex = 0;
2515 for (const auto &pair : m_projectTrees) {
2516 const std::string &treeId = pair.first;
2517 auto tree = pair.second;
2518
2519 EmberCore::Node *rootNodePtr = tree->GetRootNode();
2520 if (!rootNodePtr) {
2521 continue;
2522 }
2523
2524 // Create a panel for this tree
2525 wxPanel *treePanel = new wxPanel(overviewPanel, wxID_ANY);
2526 treePanel->SetBackgroundColour(wxColour(45, 45, 50));
2527 wxBoxSizer *treeSizer = new wxBoxSizer(wxVERTICAL);
2528
2529 // Add tree label
2530 wxStaticText *label = new wxStaticText(treePanel, wxID_ANY, wxString::FromUTF8(treeId));
2531 wxFont labelFont = label->GetFont();
2532 labelFont.SetPointSize(labelFont.GetPointSize() + 2);
2533 labelFont.MakeBold();
2534 label->SetFont(labelFont);
2535 label->SetForegroundColour(wxColour(200, 200, 200));
2536 treeSizer->Add(label, 0, wxALL | wxALIGN_CENTER, 10);
2537
2538 // Create tree visualization
2540 vis->SetMinSize(wxSize(600, 400)); // Minimum size for each tree
2541
2542 // Create adapter and set tree
2543 auto behaviorTree = std::make_shared<EmberCore::BehaviorTree>(treeId);
2544 std::shared_ptr<EmberCore::Node> rootNode(tree, rootNodePtr);
2545 behaviorTree->SetRootNode(rootNode);
2546 auto treeAdapter = std::make_shared<EmberCore::DirectTreeAdapter>(behaviorTree);
2547 vis->SetBehaviorTree(treeAdapter);
2548
2549 treeSizer->Add(vis, 1, wxEXPAND | wxALL, 5);
2550 treePanel->SetSizer(treeSizer);
2551
2552 // Add to horizontal layout with separator
2553 horizontalSizer->Add(treePanel, 0, wxEXPAND | wxALL, 10);
2554
2555 if (treeIndex < m_projectTrees.size() - 1) {
2556 // Add vertical separator line
2557 wxPanel *separator = new wxPanel(overviewPanel, wxID_ANY, wxDefaultPosition, wxSize(2, -1));
2558 separator->SetBackgroundColour(wxColour(80, 80, 85));
2559 horizontalSizer->Add(separator, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
2560 }
2561
2562 treeIndex++;
2563 }
2564
2565 overviewPanel->SetSizer(horizontalSizer);
2566 overviewPanel->FitInside(); // Adjust scrollbar
2567
2568 // Replace the tree visualization with the overview panel
2569 wxSizer *panelSizer = btScene->GetPanel()->GetSizer();
2570 if (panelSizer) {
2571 panelSizer->Clear(false); // Don't delete children yet
2572 panelSizer->Add(overviewPanel, 1, wxEXPAND | wxALL, 5);
2573 btScene->GetPanel()->Layout();
2574 }
2575
2576 SetStatusText("Project Overview: " + wxString::Format("%zu trees", m_projectTrees.size()));
2577 LOG_INFO("MainFrame", "Project overview scene created successfully");
2578}
2579
2581 LOG_INFO("MainFrame",
2582 "UpdateTreeSelector called - tab pointer: " + std::string(m_treeSelectorTab ? "valid" : "null") +
2583 ", trees: " + std::to_string(m_projectTrees.size()));
2584
2585 if (m_treeSelectorTab) {
2587 LOG_INFO("MainFrame", "Tree selector UpdateTreeList called successfully");
2588 } else {
2589 LOG_WARNING("MainFrame", "Tree selector tab is null - cannot update");
2590 }
2591}
2592
2594 if (!m_activeProject) {
2595 LOG_INFO("Project", "No project to close");
2596 return;
2597 }
2598
2599 LOG_INFO("Project", "Closing project: " + m_activeProject->GetName());
2600
2601 // TODO: Check for unsaved changes and prompt
2602
2603 // Clear the scene and tree selector
2604 if (m_scenePanel) {
2605 IScene *scene = m_scenePanel->GetActiveScene();
2606 if (scene && scene->GetSceneType() == "BehaviorTree") {
2607 BehaviorTreeScene *btScene = dynamic_cast<BehaviorTreeScene *>(scene);
2608 if (btScene) {
2609 btScene->SetBehaviorTree(std::shared_ptr<EmberCore::Node>(nullptr)); // Clear the tree from the scene
2610
2611 // Clear the tree visualization
2613 if (treeViz) {
2614 treeViz->SetBehaviorTree(nullptr); // Clear the visualization
2615 treeViz->RefreshVisualization(); // Refresh to show empty canvas
2616 }
2617 }
2618 }
2619 }
2620
2621 // Clear the hierarchy tab
2622 if (m_hierarchyTab) {
2623 m_hierarchyTab->SetRootNode(nullptr);
2624 }
2625
2626 // Clear the properties tab
2627 if (m_propertiesTab) {
2628 m_propertiesTab->ClearSelection();
2629 }
2630
2631 // Clear the tree selector tab
2632 if (m_treeSelectorTab) {
2633 m_treeSelectorTab->ClearTreeList();
2634 }
2635
2636 // Clear tree data
2637 m_activeProject = nullptr;
2638 m_projectTrees.clear();
2639 m_currentTreeId.clear();
2640
2641 SetStatusText("Project closed");
2642}
2643
2645 if (!m_activeProject) {
2646 wxMessageBox("No project is currently open.", "Information", wxOK | wxICON_INFORMATION, this);
2647 return;
2648 }
2649
2650 wxString projectPath = wxString::FromUTF8(m_activeProject->GetProjectFilePath());
2651
2652 if (projectPath.IsEmpty()) {
2653 // Need to choose a save location
2654 wxFileDialog saveDialog(this, "Save BehaviorTree Project", "",
2655 wxString::FromUTF8(m_activeProject->GetName()) + ".btproj",
2656 "BehaviorTree Project (*.btproj)|*.btproj", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
2657
2658 if (saveDialog.ShowModal() != wxID_OK) {
2659 return;
2660 }
2661
2662 projectPath = saveDialog.GetPath();
2663 }
2664
2665 if (m_activeProject->SaveToFile(projectPath.ToStdString())) {
2666 LOG_INFO("Project", "Project saved: " + projectPath.ToStdString());
2667 SetStatusText("Project saved");
2668 } else {
2669 wxMessageBox("Failed to save project.", "Error", wxOK | wxICON_ERROR, this);
2670 LOG_ERROR("Project", "Failed to save project");
2671 }
2672}
2673
2675 if (!m_activeProject) {
2676 wxMessageBox("No project is currently open.", "Information", wxOK | wxICON_INFORMATION, this);
2677 return;
2678 }
2679
2681 int result = dialog.ShowModal();
2682
2683 if (result == wxID_OK) {
2684 // Project settings may have changed
2685 SaveProject();
2686 LOG_INFO("Project", "Project settings updated");
2687 SetStatusText("Project settings saved");
2688 }
2689}
2690
2691bool MainFrame::HasActiveProject() const { return m_activeProject != nullptr; }
2692
2693std::shared_ptr<EmberCore::BehaviorTreeProject> MainFrame::GetActiveProject() const { return m_activeProject; }
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
#define LOG_ERROR(category, message)
Definition Logger.h:116
#define LOG_WARNING(category, message)
Definition Logger.h:115
#define LOG_INFO(category, message)
Definition Logger.h:114
MainFrame::OnExit MainFrame::OnNewProject MainFrame::OnCloseProject MainFrame::OnToggleMaximize MainFrame::OnPreviousScene MainFrame::OnPreferences MainFrame::OnEditorTool EVT_BUTTON(ID_MonitorTool, MainFrame::OnMonitorTool) EVT_PAINT(MainFrame
Definition MainFrame.cpp:63
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) EVT_MENU(wxID_EXIT
MainFrame::OnExit EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) EVT_MENU(ID_NewProject
@ ID_EditorTool
Definition MainFrame.h:246
@ ID_NewProject
Definition MainFrame.h:228
@ ID_ToggleBottomPanel
Definition MainFrame.h:252
@ ID_PreviousScene
Definition MainFrame.h:237
@ ID_ToggleMaximize
Definition MainFrame.h:235
@ ID_SaveProject
Definition MainFrame.h:231
@ ID_ResetZoom
Definition MainFrame.h:238
@ ID_ParserConfig
Definition MainFrame.h:243
@ ID_MonitorTool
Definition MainFrame.h:247
@ ID_ResetUI
Definition MainFrame.h:239
@ ID_NextScene
Definition MainFrame.h:236
@ ID_OpenProject
Definition MainFrame.h:229
@ ID_Preferences
Definition MainFrame.h:242
@ ID_LogReplayTool
Definition MainFrame.h:248
@ ID_LoadXML
Definition MainFrame.h:223
@ ID_SaveAsXML
Definition MainFrame.h:225
@ ID_ToggleRightPanel
Definition MainFrame.h:253
@ ID_ToggleLeftPanel
Definition MainFrame.h:251
@ ID_CloseProject
Definition MainFrame.h:230
@ ID_SaveXML
Definition MainFrame.h:224
@ ID_ProjectSettings
Definition MainFrame.h:232
#define PERF_TIME_END(name)
#define PERF_TIME_BEGIN(name)
Centralized resource path management for EmberForge.
Dialog for creating and configuring BehaviorTree projects.
std::shared_ptr< EmberCore::BehaviorTreeProject > GetProject() const
Get the configured project (after dialog is closed with OK)
Scene implementation for behavior tree visualization.
EmberCore::ITreeStructure * GetAbstractedTree() const
Get the abstracted tree structure.
EmberCore::TreeVisualization * GetTreeVisualization() const
Get the tree visualization component.
wxPanel * GetPanel() override
Get the main panel widget for this scene.
EmberCore::Node * GetBehaviorTree() const
Get the behavior tree root node (legacy interface)
void SetNodeSelectionCallback(NodeSelectionCallback callback)
Set callback for node selection events.
void SetBehaviorTree(std::shared_ptr< EmberCore::Node > root)
Set the behavior tree for this scene using legacy Node interface.
Bottom dockable panel for logs and output.
Definition BottomPanel.h:45
static BehaviorTreeConfigManager & GetInstance()
Unified validation system for behavior trees.
ValidationResult Validate(const BehaviorTree *tree) const
Validate a behavior tree against the parser profile.
static ConfigManager & GetInstance()
Direct tree adapter that wraps BehaviorTree for unified tree operations.
std::shared_ptr< BehaviorTree > GetTree() const
Callback interface for reporting parsing progress.
Abstract interface for tree nodes that can be visualized.
Definition ITreeNode.h:31
virtual const String & GetName() const =0
Thread-safe XML parser using libxml2 for behavior tree files.
void SetProgressCallback(IParseProgressCallback *callback)
const std::vector< ParseError > & GetErrors() const
ProjectParseResult ParseProject(BehaviorTreeProject *project)
std::shared_ptr< BehaviorTree > ParseFromFile(const EmberCore::String &filepath)
XML serializer using libxml2 for behavior tree files.
const std::vector< SerializeError > & GetErrors() const
bool SerializeToFile(std::shared_ptr< BehaviorTree > tree, const EmberCore::String &filepath)
Serialize behavior tree to file.
Adapter class that wraps the current Node implementation to work with ITreeNode interface.
Definition NodeAdapter.h:16
Represents a node in a behavior tree structure.
Definition Node.h:20
const String & GetName() const
Definition Node.h:81
size_t GetChildCount() const
Definition Node.h:76
static ParserConfig CreateDefault()
static ProjectManager & GetInstance()
Tree visualization panel that renders behavior trees in a grid-based layout.
ITreeNode * GetSelectedNode() const
void SetBehaviorTree(std::shared_ptr< ITreeStructure > tree)
void SetSelectedNode(ITreeNode *node)
void CenterOnNode(ITreeNode *node)
static AppPreferencesManager & GetInstance()
Application preferences configuration.
LeftPanelSettings & GetLeftPanelSettings()
bool SaveToFile(const EmberCore::String &filename) const
MainPanelSettings & GetMainPanelSettings()
ParserSettings & GetParserSettings()
WindowSettings & GetWindowSettings()
static EmberCore::String GetDefaultConfigPath()
System performance monitoring class.
static PerformanceMonitor & GetInstance()
static wxString GetDir(const wxString &relativeDir)
Get the full path to a resource directory.
Abstract interface for different scene types in the MainPanel.
Definition IScene.h:25
virtual wxString GetSceneType() const =0
Get a unique identifier for this scene type.
Abstract interface for individual tabs that can be moved between panels.
Definition ITab.h:28
Left sidebar panel specialized for left-side functionality.
Custom loading dialog with detailed progress information.
void MarkComplete()
Mark loading as complete and change button to "Close".
void SetMaxProgress(int max)
Set the maximum value for the progress bar.
bool UpdateProgress(int current, int max, const wxString &message=wxEmptyString)
Update progress and optionally add a log message.
bool WasCancelled() const
Check if the user requested cancellation.
void AppendLog(const wxString &message, const wxString &prefix="")
Add a log message without updating progress.
Main application window for EmberForge.
Definition MainFrame.h:65
std::string m_currentTreeId
Definition MainFrame.h:213
void SyncSelection(EmberCore::ITreeNode *selectedNode)
virtual ~MainFrame()
Destructor - cleans up AUI manager and panels.
int CountTabGlobally(const wxString &tabName) const
void LogMessage(const wxString &message)
void UpdateTreeSelector()
void OnTreeSelectorTabClosed()
bool m_isUpdatingFromHierarchy
Definition MainFrame.h:216
void OnSaveProject(wxCommandEvent &event)
void OnPreferences(wxCommandEvent &event)
MainPanel * m_scenePanel
Definition MainFrame.h:203
void OnToggleLeftPanel(wxCommandEvent &event)
void UpdatePropertiesTabReference(PropertiesTab *propertiesTab)
void OnPaint(wxPaintEvent &event)
void OnParserConfig(wxCommandEvent &event)
void OnCloseProject(wxCommandEvent &event)
std::shared_ptr< EmberCore::BehaviorTreeProject > GetActiveProject() const
void OnPreviousScene(wxCommandEvent &event)
void OnNewProject(wxCommandEvent &event)
void OpenProject()
void OnToggleMaximize(wxCommandEvent &event)
void RefreshPreferences()
void OpenTreeInNewScene(const std::string &treeId)
void CreateProjectOverviewScene()
bool m_isUpdatingFromScene
Definition MainFrame.h:217
void OnSaveAsXML(wxCommandEvent &event)
void OnMonitorTool(wxCommandEvent &event)
void OnIdle(wxIdleEvent &event)
void OnToggleRightPanel(wxCommandEvent &event)
LeftSidePanel * m_leftPanel
Definition MainFrame.h:197
void CreateMenuAndStatusBar()
void OnHierarchySelectionChanged(EmberCore::ITreeNode *selectedNode)
void CenterOnNode(EmberCore::ITreeNode *node)
void ShowProjectSettings()
void UpdateTreeSelectorTabReference(TreeSelectorTab *treeSelectorTab)
void OnOpenProject(wxCommandEvent &event)
RightSidePanel * m_rightPanel
Definition MainFrame.h:198
void DoSaveXML(const wxString &filePath)
void OnPropertiesTabClosed()
void OnLogReplayTool(wxCommandEvent &event)
void OnResetZoom(wxCommandEvent &event)
void OnToggleBottomPanel(wxCommandEvent &event)
void LoadTreeIntoScene(const std::string &treeId)
void LoadXMLFile(const wxString &filePath, bool confirmOverride=false)
void CloseProject()
std::shared_ptr< EmberCore::BehaviorTreeProject > m_activeProject
Definition MainFrame.h:211
void OnNextScene(wxCommandEvent &event)
void OnAbout(wxCommandEvent &event)
wxToolBar * m_panelToggleToolbar
Definition MainFrame.h:204
void OnSaveXML(wxCommandEvent &event)
BottomPanel * m_bottomPanel
Definition MainFrame.h:199
void OnLoadXML(wxCommandEvent &event)
TreeSelectorTab * m_treeSelectorTab
Definition MainFrame.h:202
void OnSceneSelectionChanged(EmberCore::ITreeNode *selectedNode)
std::map< std::string, std::shared_ptr< EmberCore::BehaviorTree > > m_projectTrees
Definition MainFrame.h:212
void NewProject()
bool HasActiveProject() const
void OnEditorTool(wxCommandEvent &event)
wxString m_currentFilePath
Definition MainFrame.h:207
bool m_treeModified
Definition MainFrame.h:208
SceneHierarchyTab * m_hierarchyTab
Definition MainFrame.h:200
void SaveProject()
void OnResetUI(wxCommandEvent &event)
void OnHierarchyTabClosed()
PropertiesTab * m_propertiesTab
Definition MainFrame.h:201
void OnProjectSettings(wxCommandEvent &event)
void InitializeConfigurationMenu()
void UpdatePanelToggleButtons()
void CreatePanelLayout()
void UpdateHierarchyTabReference(SceneHierarchyTab *hierarchyTab)
void RefreshMenuHotkeys()
std::shared_ptr< EmberCore::Node > GetSharedBehaviorTree() const
void RefreshCanvasVisualization()
void LoadXMLFileInNewScene(const wxString &filePath)
void OnExit(wxCommandEvent &event)
void CreatePanelToggleToolbar()
wxAuiManager * m_auiManager
Definition MainFrame.h:196
Central panel for managing and displaying behavior tree scenes.
Definition MainPanel.h:41
Comprehensive dialog for managing parser configuration profiles.
Preferences dialog for configuring EmberForge application settings.
Dialog for opening and managing BehaviorTree projects.
wxString GetSelectedProjectPath() const
Get the selected project path (after dialog is closed with OK)
bool HasSelectedProject() const
Check if a project was selected.
Tab for editing node properties and blackboard entries.
Right sidebar panel specialized for right-side functionality.
Tab displaying the behavior tree hierarchy.
std::string String
Framework-agnostic string type.
Definition String.h:14