37#include <wx/artprov.h>
38#include <wx/aui/aui.h>
39#include <wx/filename.h>
40#include <wx/splitter.h>
41#include <wx/stdpaths.h>
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) {
78 m_auiManager =
new wxAuiManager(
this);
81 m_auiManager->GetArtProvider()->SetMetric(wxAUI_DOCKART_SASH_SIZE, 8);
83 LOG_INFO(
"AUI",
"Initialized unified AUI manager for MainFrame");
88 if (prefs.LoadFromFile(configPath)) {
89 LOG_INFO(
"Preferences",
"Application preferences loaded from: " + configPath);
91 LOG_INFO(
"Preferences",
"Using default preferences (config file not found or invalid)");
94 CreateMenuAndStatusBar();
95 CreatePanelToggleToolbar();
96 InitializeConfigurationMenu();
100 const auto &windowSettings = prefs.GetWindowSettings();
103 if (windowSettings.showStatusBar) {
104 GetStatusBar()->Show();
105 LOG_INFO(
"Preferences",
"Status bar enabled");
107 GetStatusBar()->Hide();
108 LOG_INFO(
"Preferences",
"Status bar hidden");
110 switch (windowSettings.startupMode) {
114 LOG_INFO(
"Preferences",
"Starting in maximized mode");
118 LOG_INFO(
"Preferences",
"Starting in normal windowed mode");
123 if (windowSettings.alwaysOnTop) {
124 SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP);
125 LOG_INFO(
"Preferences",
"Window set to always on top");
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));
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));
141 if (windowSettings.enforceAspectRatio) {
144 LOG_INFO(
"Preferences",
"Aspect ratio enforcement requested: " + std::to_string(windowSettings.aspectRatio) +
145 " (requires custom implementation)");
149 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
152 wxColour bgColor(mainPanelSettings.canvasBackgroundColor.r, mainPanelSettings.canvasBackgroundColor.g,
153 mainPanelSettings.canvasBackgroundColor.b);
154 m_scenePanel->ApplyCanvasBackgroundColor(bgColor);
156 LOG_INFO(
"Preferences",
"Main Panel settings applied on startup");
162 LOG_INFO(
"Performance",
"Performance monitoring initialized in MainFrame");
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);
172 CallAfter([
this, lastFilePath]() {
173 LoadXMLFile(lastFilePath,
false);
175 fileAutoLoaded =
true;
177 LOG_WARNING(
"Preferences",
"Last opened file no longer exists: " + parserSettings.lastOpenedFilePath);
182 if (!fileAutoLoaded && !HasActiveProject()) {
184 LOG_INFO(
"Project",
"No active project on startup - showing project selector");
185 wxCommandEvent dummyEvent;
186 OnOpenProject(dummyEvent);
195 LOG_INFO(
"MainFrame",
"Saved left panel state");
200 LOG_INFO(
"MainFrame",
"Saved right panel state");
205 LOG_INFO(
"MainFrame",
"Saved bottom panel state");
213 wxAuiPaneInfo &leftPaneInfo =
m_auiManager->GetPane(
"left_panel");
214 wxAuiPaneInfo &rightPaneInfo =
m_auiManager->GetPane(
"right_panel");
215 wxAuiPaneInfo &bottomPaneInfo =
m_auiManager->GetPane(
"bottom_panel");
217 auto &leftSettings = prefs.GetLeftPanelSettings();
218 auto &rightSettings = prefs.GetRightPanelSettings();
219 auto &bottomSettings = prefs.GetBottomPanelSettings();
221 leftSettings.lastPanelVisible = leftPaneInfo.IsShown();
222 rightSettings.lastPanelVisible = rightPaneInfo.IsShown();
223 bottomSettings.lastPanelVisible = bottomPaneInfo.IsShown();
225 LOG_INFO(
"MainFrame", wxString::Format(
"Saved panel visibility - left: %d, right: %d, bottom: %d",
226 leftSettings.lastPanelVisible, rightSettings.lastPanelVisible,
227 bottomSettings.lastPanelVisible)
234 if (prefManager.GetPreferences().SaveToFile(configPath)) {
235 LOG_INFO(
"MainFrame",
"Saved preferences to disk: " + configPath);
237 LOG_ERROR(
"MainFrame",
"Failed to save preferences to disk");
245 LOG_INFO(
"AUI",
"Cleaned up unified AUI manager");
252 auto &prefs = prefsMgr.GetPreferences();
253 const auto &windowSettings = prefs.GetWindowSettings();
254 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
255 const auto &btViewSettings = prefs.GetBehaviorTreeViewSettings();
258 wxMenu *menuFile =
new wxMenu;
261 wxString newProjectLabel = wxString::Format(
"New &Project...\t%s", windowSettings.newProjectHotkey);
262 menuFile->Append(
ID_NewProject, newProjectLabel,
"Create a new BehaviorTree project");
264 wxString openProjectLabel = wxString::Format(
"Open Pro&ject...\t%s", windowSettings.openProjectHotkey);
265 menuFile->Append(
ID_OpenProject, openProjectLabel,
"Open an existing BehaviorTree project");
267 menuFile->Append(
ID_CloseProject,
"&Close Project",
"Close the current project");
268 menuFile->Append(
ID_SaveProject,
"Save Project",
"Save the current project");
270 menuFile->AppendSeparator();
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();
277 wxString saveLabel = wxString::Format(
"&Save\t%s", windowSettings.saveHotkey);
278 menuFile->Append(
ID_SaveXML, saveLabel,
"Save current behavior tree to XML file");
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);
285 wxMenu *menuHelp =
new wxMenu;
286 menuHelp->Append(wxID_ABOUT);
289 wxMenu *menuView =
new wxMenu;
291 wxString maximizeLabel = wxString::Format(
"&Maximize\t%s", windowSettings.maximizeHotkey);
294 menuView->AppendSeparator();
297 wxString nextSceneLabel = wxString::Format(
"&Next Scene\t%s", mainPanelSettings.nextSceneHotkey);
298 menuView->Append(
ID_NextScene, nextSceneLabel,
"Switch to next scene");
300 wxString prevSceneLabel = wxString::Format(
"&Previous Scene\t%s", mainPanelSettings.previousSceneHotkey);
301 menuView->Append(
ID_PreviousScene, prevSceneLabel,
"Switch to previous scene");
303 menuView->AppendSeparator();
306 wxString resetViewLabel = wxString::Format(
"&Reset View\t%s", btViewSettings.resetViewHotkey);
307 menuView->Append(
ID_ResetZoom, resetViewLabel,
"Reset zoom and pan to default");
309 menuView->AppendSeparator();
312 wxString resetUILabel = wxString::Format(
"Reset &UI\t%s", windowSettings.resetUIHotkey);
313 menuView->Append(
ID_ResetUI, resetUILabel,
"Reset all panels and preferences to defaults");
316 wxMenu *menuSettings =
new wxMenu;
318 wxString preferencesLabel = wxString::Format(
"&Preferences...\t%s", windowSettings.preferencesHotkey);
320 "Open the preferences dialog to configure EmberForge settings");
322 wxString parserConfigLabel = wxString::Format(
"&Parser Configuration...\t%s", windowSettings.parserConfigHotkey);
324 "Configure XML parser behavior and create custom profiles");
326 wxMenuBar *menuBar =
new wxMenuBar;
327 menuBar->Append(menuFile,
"&File");
328 menuBar->Append(menuView,
"&View");
329 menuBar->Append(menuSettings,
"&Settings");
330 menuBar->Append(menuHelp,
"&Help");
336 SetStatusText(
"Welcome to EmberForge!");
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);
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");
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);
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");
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);
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");
396 LOG_INFO(
"UI",
"Panel toggle toolbar created with state-aware custom icons");
401 LOG_INFO(
"Config",
"Configuration system initialized - use Settings > Preferences to configure");
407 auto &prefs = prefsMgr.GetPreferences();
408 const auto &windowSettings = prefs.GetWindowSettings();
409 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
410 const auto &btViewSettings = prefs.GetBehaviorTreeViewSettings();
412 wxMenuBar *menuBar = GetMenuBar();
417 int fileMenuIndex = menuBar->FindMenu(
"File");
418 if (fileMenuIndex != wxNOT_FOUND) {
419 wxMenu *menuFile = menuBar->GetMenu(fileMenuIndex);
421 wxMenuItem *newProjectItem = menuFile->FindItem(
ID_NewProject);
422 if (newProjectItem) {
423 newProjectItem->SetItemLabel(wxString::Format(
"New &Project...\t%s", windowSettings.newProjectHotkey));
427 if (openProjectItem) {
428 openProjectItem->SetItemLabel(
429 wxString::Format(
"Open Pro&ject...\t%s", windowSettings.openProjectHotkey));
432 wxMenuItem *openFileItem = menuFile->FindItem(
ID_LoadXML);
434 openFileItem->SetItemLabel(wxString::Format(
"&Open XML File...\t%s", windowSettings.openFileHotkey));
437 wxMenuItem *saveItem = menuFile->FindItem(
ID_SaveXML);
439 saveItem->SetItemLabel(wxString::Format(
"&Save\t%s", windowSettings.saveHotkey));
442 wxMenuItem *saveAsItem = menuFile->FindItem(
ID_SaveAsXML);
444 saveAsItem->SetItemLabel(wxString::Format(
"Save &As...\t%s", windowSettings.saveAsHotkey));
450 int viewMenuIndex = menuBar->FindMenu(
"View");
451 if (viewMenuIndex != wxNOT_FOUND) {
452 wxMenu *menuView = menuBar->GetMenu(viewMenuIndex);
456 maximizeItem->SetItemLabel(wxString::Format(
"&Maximize\t%s", windowSettings.maximizeHotkey));
459 wxMenuItem *nextSceneItem = menuView->FindItem(
ID_NextScene);
461 nextSceneItem->SetItemLabel(wxString::Format(
"&Next Scene\t%s", mainPanelSettings.nextSceneHotkey));
466 prevSceneItem->SetItemLabel(
467 wxString::Format(
"&Previous Scene\t%s", mainPanelSettings.previousSceneHotkey));
470 wxMenuItem *resetViewItem = menuView->FindItem(
ID_ResetZoom);
472 resetViewItem->SetItemLabel(wxString::Format(
"&Reset View\t%s", btViewSettings.resetViewHotkey));
475 wxMenuItem *resetUIItem = menuView->FindItem(
ID_ResetUI);
477 resetUIItem->SetItemLabel(wxString::Format(
"Reset &UI\t%s", windowSettings.resetUIHotkey));
483 int settingsMenuIndex = menuBar->FindMenu(
"Settings");
484 if (settingsMenuIndex != wxNOT_FOUND) {
485 wxMenu *menuSettings = menuBar->GetMenu(settingsMenuIndex);
487 wxMenuItem *preferencesItem = menuSettings->FindItem(
ID_Preferences);
488 if (preferencesItem) {
489 preferencesItem->SetItemLabel(
490 wxString::Format(
"&Preferences...\t%s", windowSettings.preferencesHotkey));
493 wxMenuItem *parserConfigItem = menuSettings->FindItem(
ID_ParserConfig);
494 if (parserConfigItem) {
495 parserConfigItem->SetItemLabel(
496 wxString::Format(
"&Parser Configuration...\t%s", windowSettings.parserConfigHotkey));
501 LOG_INFO(
"Preferences",
"Menu hotkeys refreshed");
510 if (!activeScene || activeScene->GetSceneType() !=
"BehaviorTree")
520 auto currentTree = treeVis->GetBehaviorTree();
524 treeVis->SetBehaviorTree(currentTree);
527 treeVis->RefreshVisualization();
546 if (windowSettings.showStatusBar) {
547 GetStatusBar()->Show();
549 GetStatusBar()->Hide();
554 wxAuiPaneInfo &leftPane =
m_auiManager->GetPane(
"left_panel");
555 if (leftPane.IsOk()) {
556 leftPane.CaptionVisible(windowSettings.showPanelCaptions);
559 wxAuiPaneInfo &rightPane =
m_auiManager->GetPane(
"right_panel");
560 if (rightPane.IsOk()) {
561 rightPane.CaptionVisible(windowSettings.showPanelCaptions);
564 wxAuiPaneInfo &bottomPane =
m_auiManager->GetPane(
"bottom_panel");
565 if (bottomPane.IsOk()) {
566 bottomPane.CaptionVisible(windowSettings.showPanelCaptions);
569 wxAuiPaneInfo &scenePane =
m_auiManager->GetPane(
"scene_panel");
570 if (scenePane.IsOk()) {
571 scenePane.CaptionVisible(windowSettings.showPanelCaptions);
576 std::string(
"Panel captions ") + (windowSettings.showPanelCaptions ?
"shown" :
"hidden"));
580 long currentStyle = GetWindowStyle();
581 bool styleChanged =
false;
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");
590 if (currentStyle & wxSTAY_ON_TOP) {
591 SetWindowStyle(currentStyle & ~wxSTAY_ON_TOP);
592 LOG_INFO(
"Preferences",
"Window always on top disabled");
600 wxMenuBar *menuBar = GetMenuBar();
610 const auto &mainPanelSettings = prefs.GetMainPanelSettings();
613 wxColour bgColor(mainPanelSettings.canvasBackgroundColor.r, mainPanelSettings.canvasBackgroundColor.g,
614 mainPanelSettings.canvasBackgroundColor.b);
619 for (
int i = 0; i < sceneCount; i++) {
626 treeVis->LoadPreferences();
628 wxString::Format(
"Reloaded zoom/pan preferences for scene %d", i).ToStdString());
634 LOG_INFO(
"Preferences",
"Main Panel settings applied");
640 LOG_INFO(
"Preferences",
"Preferences refreshed and applied to UI");
654 if (!newScene || newScene->
GetSceneType() !=
"BehaviorTree")
664 auto rootNode = std::shared_ptr<EmberCore::Node>(rawTree, [](
EmberCore::Node *) {});
695 auto behaviorTreeScene = std::make_unique<BehaviorTreeScene>(
m_scenePanel->GetNotebook());
709 const auto &rightSettings = prefs.GetRightPanelSettings();
710 const auto &bottomSettings = prefs.GetBottomPanelSettings();
713 bool showLeftPanel =
true;
714 switch (leftSettings.panelStartupState) {
716 showLeftPanel =
true;
719 showLeftPanel =
false;
722 showLeftPanel = leftSettings.lastPanelVisible;
727 const auto &windowSettings = prefs.GetWindowSettings();
732 .Caption(
"Left Panel")
733 .CaptionVisible(windowSettings.showPanelCaptions)
735 .BestSize(wxSize(leftSettings.defaultPanelWidth, -1))
736 .MinSize(wxSize(leftSettings.minimumPanelWidth, -1))
740 .Resizable(leftSettings.allowPanelCollapse)
741 .Show(showLeftPanel));
745 .Caption(
"Main Panel")
747 .CaptionVisible(windowSettings.showPanelCaptions)
754 bool showRightPanel =
true;
755 switch (rightSettings.panelStartupState) {
757 showRightPanel =
true;
760 showRightPanel =
false;
763 showRightPanel = rightSettings.lastPanelVisible;
769 .Caption(
"Right Panel")
770 .CaptionVisible(windowSettings.showPanelCaptions)
772 .BestSize(wxSize(rightSettings.defaultPanelWidth, -1))
773 .MinSize(wxSize(rightSettings.minimumPanelWidth, -1))
777 .Resizable(rightSettings.allowPanelCollapse)
778 .Show(showRightPanel));
781 bool showBottomPanel =
true;
782 switch (bottomSettings.panelStartupState) {
784 showBottomPanel =
true;
787 showBottomPanel =
false;
790 showBottomPanel = bottomSettings.lastPanelVisible;
795 .Name(
"bottom_panel")
796 .Caption(
"Bottom Panel")
797 .CaptionVisible(windowSettings.showPanelCaptions)
799 .BestSize(wxSize(-1, bottomSettings.defaultPanelHeight))
800 .MinSize(wxSize(-1, bottomSettings.minimumPanelHeight))
804 .Resizable(bottomSettings.allowPanelCollapse)
805 .Show(showBottomPanel));
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") {
822 LOG_INFO(
"MainFrame",
"Found hierarchy tab reference");
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") {
841 LOG_INFO(
"MainFrame",
"Found properties tab reference");
857 wxBitmapButton *leftBtn =
dynamic_cast<wxBitmapButton *
>(leftWin);
861 wxBitmap(resourcePath +
"left_panel/Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
864 wxBitmap(resourcePath +
"left_panel/Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
872 wxBitmapButton *bottomBtn =
dynamic_cast<wxBitmapButton *
>(bottomWin);
874 if (showBottomPanel) {
875 bottomBtn->SetBitmap(
876 wxBitmap(resourcePath +
"bottom_panel/Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
878 bottomBtn->SetBitmap(
879 wxBitmap(resourcePath +
"bottom_panel/Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
887 wxBitmapButton *rightBtn =
dynamic_cast<wxBitmapButton *
>(rightWin);
889 if (showRightPanel) {
891 wxBitmap(resourcePath +
"right_panel/Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
894 wxBitmap(resourcePath +
"right_panel/Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
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)
918 static int idleCount = 0;
919 if (++idleCount % 100 == 0) {
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);
939 wxFileDialog openFileDialog(
this,
"Open Behavior Tree",
"",
"",
"XML files (*.xml)|*.xml|All files (*.*)|*.*",
940 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
942 if (openFileDialog.ShowModal() == wxID_CANCEL)
945 wxString filePath = openFileDialog.GetPath();
946 wxString ext = wxFileName(filePath).GetExt().Lower();
950 wxString message = wxString::Format(
"Unsupported File Format\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);
957 wxMessageBox(message,
"Unsupported File Format", wxOK | wxICON_WARNING,
this);
958 LOG_WARNING(
"FileOpen", std::string(
"Attempted to open unsupported file type: .") + ext.ToStdString());
966 LOG_INFO(
"Parser", std::string(
"Loading XML file: ") + filePath.ToStdString());
969 bool shouldRename =
false;
970 wxString newSceneName;
987 (void)confirmOverride;
990 LoadingDialog loadingDialog(
this,
"Loading Behavior Tree (libxml2)");
992 loadingDialog.Show(
true);
993 loadingDialog.
AppendLog(
"Selected file: " + filePath,
"[FILE]");
1002 explicit ProgressCallback(
LoadingDialog *dialog) : dialog_(dialog) {}
1004 bool OnProgress(
const EmberCore::String &message,
int current,
int total)
override {
1007 bool shouldContinue = dialog_->
UpdateProgress(current, total, message);
1012 return shouldContinue;
1018 void AppendLog(
const wxString &message,
const wxString &prefix =
"") {
1025 ProgressCallback progressCallback(&loadingDialog);
1029 auto activeProfile = configMgr.GetActiveProfile();
1037 progressCallback.AppendLog(
"libxml2 parser initialized",
"[INIT]");
1038 progressCallback.AppendLog(
"Starting file parsing with libxml2...",
"[INFO]");
1041 auto behaviorTree = parser.
ParseFromFile(filePath.ToStdString());
1046 loadingDialog.
AppendLog(
"libxml2 parsing completed successfully",
"[COMPLETE]");
1053 if (!behaviorTree) {
1055 const auto &errors = parser.
GetErrors();
1056 for (
const auto &error : errors) {
1057 loadingDialog.
AppendLog(wxString::FromUTF8(error.message),
"[ERROR]");
1061 loadingDialog.ShowModal();
1063 wxString errorMessage =
"Failed to parse XML file with libxml2:\n\n";
1064 for (
const auto &error : errors) {
1065 errorMessage +=
"• " + error.message +
"\n";
1068 wxMessageBox(errorMessage,
"libxml2 XML Parsing Error", wxOK | wxICON_ERROR);
1069 LOG_ERROR(
"Parser",
"libxml2 XML parsing failed");
1074 loadingDialog.ShowModal();
1076 LOG_INFO(
"Parser",
"libxml2 XML parsed successfully, loading into scene view");
1079 if (behaviorTree->HasRootNode()) {
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");
1103 auto directAdapter = std::make_shared<EmberCore::DirectTreeAdapter>(behaviorTree);
1104 treeVis->SetBehaviorTree(directAdapter);
1113 auto rootNode = std::shared_ptr<EmberCore::Node>(rawRootNode, [](
EmberCore::Node *) {});
1115 LOG_INFO(
"Parser",
"Behavior tree loaded into hierarchy tab");
1117 LOG_ERROR(
"Parser",
"Root node is null even though HasRootNode() returned true");
1123 if (
auto *visualization = treeVis->GetTreeVisualization()) {
1124 visualization->RefreshVisualization();
1125 visualization->Refresh();
1126 visualization->Update();
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)");
1150 LOG_INFO(
"Preferences",
"Saved last opened file path: " + filePath.ToStdString());
1155 wxFileName fileName(filePath);
1156 wxString sceneName = fileName.GetName();
1162 LOG_INFO(
"Parser",
"Behavior tree loaded into scene view");
1163 SetStatusText(
"Loaded with libxml2: " + wxFileName(filePath).GetName());
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);
1169 LOG_ERROR(
"Parser",
"No active scene available");
1170 wxMessageBox(
"No active scene available",
"Error", wxOK | wxICON_ERROR);
1173 LOG_ERROR(
"Parser",
"Scene panel not available");
1174 wxMessageBox(
"Scene panel not available",
"Error", wxOK | wxICON_ERROR);
1180 LOG_ERROR(
"Parser",
"Scene panel not available");
1181 wxMessageBox(
"Scene panel not available",
"Error", wxOK | wxICON_ERROR);
1186 wxFileName fileName(filePath);
1187 wxString sceneName = fileName.GetName();
1190 LOG_INFO(
"Parser", std::string(
"Creating new scene: ") + sceneName.ToStdString());
1191 int sceneIndex =
m_scenePanel->CreateNewScene(sceneName);
1193 if (sceneIndex < 0) {
1194 LOG_ERROR(
"Parser",
"Failed to create new scene (limit may have been reached)");
1215 wxFileDialog saveFileDialog(
this,
"Save Behavior Tree XML",
"",
"",
"XML files (*.xml)|*.xml",
1216 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1218 if (saveFileDialog.ShowModal() == wxID_CANCEL)
1221 wxString filePath = saveFileDialog.GetPath();
1226 LOG_INFO(
"Serializer",
"Saving behavior tree to: " + filePath.ToStdString());
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");
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");
1247 wxMessageBox(
"Unexpected tree adapter type",
"Save Error", wxOK | wxICON_ERROR);
1248 LOG_ERROR(
"Serializer",
"Tree adapter is not a DirectTreeAdapter");
1253 std::shared_ptr<EmberCore::BehaviorTree> tree = adapter->
GetTree();
1255 wxMessageBox(
"Failed to access behavior tree data",
"Save Error", wxOK | wxICON_ERROR);
1256 LOG_ERROR(
"Serializer",
"Failed to get tree from adapter");
1262 auto activeProfile = configMgr.GetActiveProfile();
1267 auto validation = validator.
Validate(tree.get());
1270 bool hasIssues = validation.
HasErrors() || validation.HasWarnings();
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";
1284 msg +=
"• " + message +
"\n";
1286 LOG_WARNING(
"Serializer",
"Validation error: " + issue.message);
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";
1302 msg +=
"• " + message +
"\n";
1304 LOG_INFO(
"Serializer",
"Validation warning: " + issue.message);
1310 msg +=
"These issues may cause problems when loading the file.\n";
1311 msg +=
"Save anyway? (Development workflow)";
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");
1326 SetStatusText(
"Saved: " + wxFileName(filePath).GetName());
1327 LOG_INFO(
"Serializer",
"Tree saved successfully to: " + filePath.ToStdString());
1329 wxMessageBox(
"Behavior tree saved successfully!",
"Save Complete", wxOK | wxICON_INFORMATION);
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";
1338 wxMessageBox(errorMessage,
"Save Error", wxOK | wxICON_ERROR);
1339 LOG_ERROR(
"Serializer",
"Failed to save tree to: " + filePath.ToStdString());
1346 int result = dialog.ShowModal();
1348 if (result == wxID_OK) {
1349 LOG_INFO(
"Config",
"Preferences dialog closed with OK - settings applied");
1350 SetStatusText(
"Preferences updated");
1355 LOG_INFO(
"Config",
"Preferences dialog cancelled");
1356 SetStatusText(
"Preferences cancelled");
1364 wxAuiPaneInfo &pane =
m_auiManager->GetPane(
"left_panel");
1366 pane.Show(!pane.IsShown());
1370 wxBitmapButton *btn =
dynamic_cast<wxBitmapButton *
>(
event.GetEventObject());
1373 if (pane.IsShown()) {
1374 btn->SetBitmap(wxBitmap(resourcePath +
"Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1376 btn->SetBitmap(wxBitmap(resourcePath +
"Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1380 LOG_INFO(
"UI", std::string(
"Left panel ") + (pane.IsShown() ?
"shown" :
"hidden"));
1381 SetStatusText(pane.IsShown() ?
"Left panel shown" :
"Left panel hidden");
1389 wxAuiPaneInfo &pane =
m_auiManager->GetPane(
"bottom_panel");
1391 pane.Show(!pane.IsShown());
1395 wxBitmapButton *btn =
dynamic_cast<wxBitmapButton *
>(
event.GetEventObject());
1398 if (pane.IsShown()) {
1399 btn->SetBitmap(wxBitmap(resourcePath +
"Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1401 btn->SetBitmap(wxBitmap(resourcePath +
"Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1405 LOG_INFO(
"UI", std::string(
"Bottom panel ") + (pane.IsShown() ?
"shown" :
"hidden"));
1406 SetStatusText(pane.IsShown() ?
"Bottom panel shown" :
"Bottom panel hidden");
1414 wxAuiPaneInfo &pane =
m_auiManager->GetPane(
"right_panel");
1416 pane.Show(!pane.IsShown());
1420 wxBitmapButton *btn =
dynamic_cast<wxBitmapButton *
>(
event.GetEventObject());
1423 if (pane.IsShown()) {
1424 btn->SetBitmap(wxBitmap(resourcePath +
"Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1426 btn->SetBitmap(wxBitmap(resourcePath +
"Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1430 LOG_INFO(
"UI", std::string(
"Right panel ") + (pane.IsShown() ?
"shown" :
"hidden"));
1431 SetStatusText(pane.IsShown() ?
"Right panel shown" :
"Right panel hidden");
1442 wxAuiPaneInfo &leftPane =
m_auiManager->GetPane(
"left_panel");
1444 if (leftWin && leftPane.IsOk()) {
1445 wxBitmapButton *leftBtn =
dynamic_cast<wxBitmapButton *
>(leftWin);
1447 if (leftPane.IsShown()) {
1448 leftBtn->SetBitmap(wxBitmap(resourcePath +
"left_panel/Left_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1450 leftBtn->SetBitmap(wxBitmap(resourcePath +
"left_panel/Left_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1456 wxAuiPaneInfo &bottomPane =
m_auiManager->GetPane(
"bottom_panel");
1458 if (bottomWin && bottomPane.IsOk()) {
1459 wxBitmapButton *bottomBtn =
dynamic_cast<wxBitmapButton *
>(bottomWin);
1461 if (bottomPane.IsShown()) {
1462 bottomBtn->SetBitmap(
1463 wxBitmap(resourcePath +
"bottom_panel/Bottom_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1465 bottomBtn->SetBitmap(
1466 wxBitmap(resourcePath +
"bottom_panel/Bottom_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1472 wxAuiPaneInfo &rightPane =
m_auiManager->GetPane(
"right_panel");
1474 if (rightWin && rightPane.IsOk()) {
1475 wxBitmapButton *rightBtn =
dynamic_cast<wxBitmapButton *
>(rightWin);
1477 if (rightPane.IsShown()) {
1478 rightBtn->SetBitmap(
1479 wxBitmap(resourcePath +
"right_panel/Right_Panel_Pressed_22.png", wxBITMAP_TYPE_PNG));
1481 rightBtn->SetBitmap(
1482 wxBitmap(resourcePath +
"right_panel/Right_Panel_Normal_22.png", wxBITMAP_TYPE_PNG));
1504 int result = dialog.ShowModal();
1506 if (result == wxID_OK) {
1507 LOG_INFO(
"Config",
"Parser configuration updated");
1508 SetStatusText(
"Parser configuration saved");
1510 LOG_INFO(
"Config",
"Parser configuration cancelled");
1511 SetStatusText(
"Parser configuration cancelled");
1518 LOG_INFO(
"Tool",
"Editor Tool activated - Opening editor for BT configuration");
1524 LOG_INFO(
"Tool",
"Monitor Tool activated - Opening performance monitor");
1530 LOG_INFO(
"Tool",
"Log Replay Tool activated - Replaying performance logs");
1537 bool isMaximized = IsMaximized();
1540 LOG_INFO(
"View",
"Maximized window");
1543 LOG_INFO(
"View",
"Restored window to normal size");
1572 int zoomPercent =
static_cast<int>(defaultZoom * 100);
1574 SetStatusText(wxString::Format(
"View reset (zoom: %d%%)", zoomPercent));
1575 LOG_INFO(
"View",
"View reset to default (zoom + pan)");
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);
1590 if (result != wxYES) {
1594 LOG_INFO(
"UI",
"Resetting UI to defaults");
1599 LOG_INFO(
"UI",
"Closed active project");
1605 prefsMgr.GetPreferences() = defaultPrefs;
1608 prefsMgr.GetPreferences().SaveToFile(configPath);
1609 LOG_INFO(
"Preferences",
"Reset preferences to defaults and saved to: " + configPath);
1614 wxAuiPaneInfo &leftPane =
m_auiManager->GetPane(
"left_panel");
1615 if (leftPane.IsOk() && !leftPane.IsShown()) {
1619 wxAuiPaneInfo &rightPane =
m_auiManager->GetPane(
"right_panel");
1620 if (rightPane.IsOk() && !rightPane.IsShown()) {
1624 wxAuiPaneInfo &bottomPane =
m_auiManager->GetPane(
"bottom_panel");
1625 if (bottomPane.IsOk() && !bottomPane.IsShown()) {
1669 SetStatusText(
"UI reset to defaults");
1670 LOG_INFO(
"UI",
"UI reset complete");
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);
1687 if (!config.GetSyncSettings().enableHierarchyToScene) {
1688 if (config.GetDebugSettings().enableSyncLogging) {
1689 LOG_INFO(
"Sync",
"Hierarchy → Scene: Disabled by configuration");
1696 if (config.GetDebugSettings().enableSyncLogging) {
1697 LOG_INFO(
"Sync",
"Hierarchy → Scene: Skipped (already updating from scene)");
1703 if (config.GetDebugSettings().enableSyncLogging) {
1704 LOG_INFO(
"Sync",
"Hierarchy → Scene: Node selected in hierarchy tab");
1712 LOG_ERROR(
"Sync",
"Scene panel is null");
1719 if (!activeScene || activeScene->
GetSceneType() !=
"BehaviorTree") {
1720 LOG_ERROR(
"Sync",
"No active behavior tree scene");
1728 LOG_ERROR(
"Sync",
"Failed to cast to BehaviorTreeScene");
1735 LOG_ERROR(
"Sync",
"Tree visualization is null");
1741 wxPanel *scenePanel = btScene->
GetPanel();
1742 if (!scenePanel || !scenePanel->IsShown()) {
1743 LOG_ERROR(
"Sync",
"Scene panel is not shown");
1751 if (config.GetSyncSettings().enableSelectionHighlight) {
1752 if (config.GetDebugSettings().enableSyncLogging) {
1753 LOG_INFO(
"Sync",
"Hierarchy → Scene: Calling treeVis->SetSelectedNode()");
1765 if (config.GetDebugSettings().enableSyncLogging) {
1766 LOG_INFO(
"Sync",
"Hierarchy → Properties: Updating properties with node: " + legacyNode->
GetName());
1771 if (config.GetDebugSettings().enableSyncLogging) {
1772 LOG_INFO(
"Sync",
"Hierarchy → Properties: Clearing properties selection");
1778 if (config.GetDebugSettings().enableSyncLogging) {
1779 LOG_INFO(
"Sync",
"Hierarchy → Scene: Sync operations completed");
1789 if (!config.GetSyncSettings().enableSceneToHierarchy) {
1790 if (config.GetDebugSettings().enableSyncLogging) {
1791 LOG_INFO(
"Sync",
"Scene → Hierarchy: Disabled by configuration");
1798 if (config.GetDebugSettings().enableSyncLogging) {
1799 LOG_INFO(
"Sync",
"Scene → Hierarchy: Skipped (already updating from hierarchy)");
1805 if (config.GetDebugSettings().enableSyncLogging) {
1806 LOG_INFO(
"Sync",
"Scene → Hierarchy: Node selected in scene view");
1814 LOG_ERROR(
"Sync",
"Hierarchy tab is null");
1826 legacyNode = nodeAdapter->GetWrappedNode();
1828 if (config.GetDebugSettings().enableSyncLogging) {
1829 LOG_INFO(
"Sync",
"Scene → Hierarchy: Converted ITreeNode to Node: " + legacyNode->
GetName());
1832 LOG_WARNING(
"Sync",
"Selected node is not a NodeAdapter");
1835 LOG_INFO(
"Sync",
"Scene → Hierarchy: No node selected (null)");
1839 LOG_INFO(
"Sync",
"Scene → Hierarchy: Calling hierarchyTab->SelectNode()");
1841 LOG_INFO(
"Sync",
"Scene → Hierarchy: Selection update completed");
1846 LOG_INFO(
"Sync",
"Scene → Properties: Updating properties with node: " + legacyNode->
GetName());
1849 LOG_INFO(
"Sync",
"Scene → Properties: Clearing properties selection");
1859 LOG_INFO(
"MainFrame",
"PropertiesTab is being closed, nullifying pointer");
1864 LOG_INFO(
"MainFrame",
"HierarchyTab is being closed, nullifying pointer");
1869 LOG_INFO(
"MainFrame",
"TreeSelectorTab is being closed, nullifying pointer");
1890 LOG_INFO(
"MainFrame",
"Tree selector tab reference updated and wired");
1901 if (!activeScene || activeScene->
GetSceneType() !=
"BehaviorTree") {
1918 return std::shared_ptr<EmberCore::Node>(rawTree, [](
EmberCore::Node *) {});
1929 LOG_INFO(
"MainFrame",
"Set behavior tree on newly created hierarchy tab");
1940 if (activeScene && activeScene->
GetSceneType() ==
"BehaviorTree") {
1952 LOG_INFO(
"MainFrame",
"Set selected node on newly created properties tab");
1969 if (!activeScene || activeScene->
GetSceneType() !=
"BehaviorTree") {
1985 wxPanel *scenePanel = btScene->
GetPanel();
1986 if (!scenePanel || !scenePanel->IsShown()) {
1996 static bool updating =
false;
1998 LOG_INFO(
"Sync",
"SyncSelection: Prevented infinite loop");
2003 LOG_INFO(
"Sync",
"SyncSelection: Synchronizing selection to: " + (selectedNode ? selectedNode->
GetName() :
"null"));
2011 LOG_INFO(
"Sync",
"SyncSelection: Updating hierarchy with node: " + legacyNode->
GetName());
2023 LOG_INFO(
"Sync",
"SyncSelection: Updating properties with node: " + legacyNode->
GetName());
2027 LOG_INFO(
"Sync",
"SyncSelection: Clearing properties selection");
2035 if (activeScene && activeScene->
GetSceneType() ==
"BehaviorTree") {
2038 LOG_INFO(
"Sync",
"SyncSelection: Updating scene view");
2045 LOG_INFO(
"Sync",
"SyncSelection: Synchronization completed");
2061 LOG_INFO(
"Menu",
"OnProjectSettings called");
2066 LOG_INFO(
"Project",
"Creating new project...");
2069 int result = dialog.ShowModal();
2071 if (result == wxID_OK) {
2078 if (!wxFileName::DirExists(defaultProjectsDir)) {
2079 wxFileName::Mkdir(defaultProjectsDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
2083 wxFileDialog saveDialog(
this,
"Save BehaviorTree Project", defaultProjectsDir,
2084 wxString::FromUTF8(project->GetName()) +
".btproj",
2085 "BehaviorTree Project (*.btproj)|*.btproj", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
2087 if (saveDialog.ShowModal() == wxID_OK) {
2088 wxString projectPath = saveDialog.GetPath();
2089 project->SetProjectFilePath(projectPath.ToStdString());
2091 if (project->SaveToFile(projectPath.ToStdString())) {
2096 projectManager.AddToRecentProjects(projectPath.ToStdString());
2101 LOG_INFO(
"Project",
"Project created and saved: " + projectPath.ToStdString());
2102 SetStatusText(
"Project created: " + wxString::FromUTF8(project->GetName()));
2104 wxMessageBox(
"Failed to save project file.",
"Error", wxOK | wxICON_ERROR,
this);
2105 LOG_ERROR(
"Project",
"Failed to save project file");
2113 LOG_INFO(
"Project",
"Opening project dialog...");
2116 int result = dialog.ShowModal();
2124 LOG_INFO(
"Project",
"Opening project: " + projectPath.ToStdString());
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());
2143 projectManager.AddToRecentProjects(projectPath.ToStdString());
2147 auto profile = configManager.GetProfile(project->GetParserProfileName());
2149 profile = configManager.GetActiveProfile();
2156 LoadingDialog loadingDialog(
this,
"Loading Project: " + wxString::FromUTF8(project->GetName()));
2157 loadingDialog.Show();
2166 explicit ProjectProgressCallback(
LoadingDialog *dialog) : dialog_(dialog) {}
2168 bool OnProgress(
const EmberCore::String &message,
int current,
int total)
override {
2170 bool shouldContinue = dialog_->
UpdateProgress(current, total, message);
2172 return shouldContinue;
2178 ProjectProgressCallback progressCallback(&loadingDialog);
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]");
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]");
2194 loadingDialog.
AppendLog(
"Starting parser...",
"[INIT]");
2202 loadingDialog.
AppendLog(
"=== Per-File Parsing Results ===",
"[INFO]");
2205 int totalBlackboards = 0;
2206 int totalWarnings = 0;
2207 int totalErrors = 0;
2209 for (
const auto &fileInfo : parseResult.file_infos) {
2210 wxFileName fn(wxString::FromUTF8(fileInfo.filepath));
2211 wxString filename = fn.GetFullName();
2213 if (fileInfo.parsed_successfully) {
2214 loadingDialog.
AppendLog(filename +
" - Parsed successfully",
"[SUCCESS]");
2216 loadingDialog.
AppendLog(filename +
" - Parse FAILED",
"[ERROR]");
2220 if (fileInfo.tree_count > 0) {
2222 for (
size_t i = 0; i < fileInfo.tree_ids.size(); ++i) {
2225 treeList += wxString::FromUTF8(fileInfo.tree_ids[i]);
2227 loadingDialog.
AppendLog(wxString::Format(
" Trees: %d (%s)", fileInfo.tree_count, treeList),
"[INFO]");
2228 totalTrees += fileInfo.tree_count;
2232 if (fileInfo.blackboard_count > 0) {
2234 for (
size_t i = 0; i < fileInfo.blackboard_ids.size(); ++i) {
2237 bbList += wxString::FromUTF8(fileInfo.blackboard_ids[i]);
2239 loadingDialog.
AppendLog(wxString::Format(
" Blackboards: %d (%s)", fileInfo.blackboard_count, bbList),
2241 totalBlackboards += fileInfo.blackboard_count;
2245 if (!fileInfo.subtree_refs.empty()) {
2247 for (
size_t i = 0; i < fileInfo.subtree_refs.size(); ++i) {
2250 refList += wxString::FromUTF8(fileInfo.subtree_refs[i]);
2252 loadingDialog.
AppendLog(
" SubTree refs: " + refList,
"[INFO]");
2256 for (
const auto &warning : fileInfo.warnings) {
2257 loadingDialog.
AppendLog(
" " + wxString::FromUTF8(warning),
"[WARN]");
2262 for (
const auto &error : fileInfo.errors) {
2263 loadingDialog.
AppendLog(
" " + wxString::FromUTF8(error),
"[ERROR]");
2269 if (!parseResult.unimplemented_references.empty()) {
2271 loadingDialog.
AppendLog(
"=== Unimplemented Tree References ===",
"[WARN]");
2272 for (
const auto &ref : parseResult.unimplemented_references) {
2273 loadingDialog.
AppendLog(
" " + wxString::FromUTF8(ref),
"[WARN]");
2277 if (!parseResult.duplicate_tree_ids.empty()) {
2279 loadingDialog.
AppendLog(
"=== Duplicate Tree IDs ===",
"[WARN]");
2280 for (
const auto &dup : parseResult.duplicate_tree_ids) {
2281 loadingDialog.
AppendLog(
" " + wxString::FromUTF8(dup),
"[WARN]");
2285 if (!parseResult.duplicate_blackboard_ids.empty()) {
2287 loadingDialog.
AppendLog(
"=== Duplicate Blackboard IDs ===",
"[WARN]");
2288 for (
const auto &dup : parseResult.duplicate_blackboard_ids) {
2289 loadingDialog.
AppendLog(
" " + wxString::FromUTF8(dup),
"[WARN]");
2293 if (!parseResult.unresolved_blackboard_includes.empty()) {
2295 loadingDialog.
AppendLog(
"=== Unresolved Blackboard Includes ===",
"[WARN]");
2296 for (
const auto &unres : parseResult.unresolved_blackboard_includes) {
2297 loadingDialog.
AppendLog(
" " + wxString::FromUTF8(unres),
"[WARN]");
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]");
2310 if (totalErrors > 0) {
2311 loadingDialog.
AppendLog(wxString::Format(
"Errors: %d", totalErrors),
"[ERROR]");
2316 if (parseResult.success) {
2318 project->SetTreeImplementationStatus(parseResult.tree_statuses);
2324 bool hasMainTreeEntryPoint = !parseResult.main_tree_name.empty() &&
2327 if (hasMainTreeEntryPoint) {
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]");
2337 LOG_INFO(
"Project",
"No main tree entry point found - project has " +
2339 " trees. Use tree selector to view individual trees.");
2340 loadingDialog.
AppendLog(
"No main tree - loading first tree",
"[INFO]");
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]");
2358 loadingDialog.
AppendLog(
"Project loaded successfully!",
"[COMPLETE]");
2359 loadingDialog.
UpdateProgress(100, 100,
"Project loaded successfully");
2365 LOG_INFO(
"Project",
"Project loaded successfully: " + project->GetName() +
" with " +
2367 SetStatusText(
"Project: " + wxString::FromUTF8(project->GetName()) +
" (" +
2371 loadingDialog.ShowModal();
2374 loadingDialog.
AppendLog(
"Project parsing failed",
"[ERROR]");
2376 wxString errorMsg =
"Failed to parse project files:\n\n";
2377 for (
const auto &err : parseResult.errors) {
2378 errorMsg +=
"- " + wxString::FromUTF8(err.message) +
"\n";
2382 for (
const auto &err : parseResult.errors) {
2383 loadingDialog.
AppendLog(wxString::FromUTF8(err.message),
"[ERROR]");
2388 LOG_ERROR(
"Project",
"Failed to parse project files");
2391 loadingDialog.ShowModal();
2393 wxMessageBox(errorMsg,
"Error", wxOK | wxICON_ERROR,
this);
2403 LOG_WARNING(
"MainFrame",
"Tree not found: " + treeId);
2412 if (scene && scene->
GetSceneType() ==
"BehaviorTree") {
2418 std::shared_ptr<EmberCore::Node> rootNode(tree, rootNodePtr);
2427 SetStatusText(
"Viewing tree: " + wxString::FromUTF8(treeId));
2428 LOG_INFO(
"MainFrame",
"Loaded tree into scene: " + treeId);
2437 LOG_WARNING(
"MainFrame",
"Tree not found: " + treeId);
2442 LOG_ERROR(
"MainFrame",
"Scene panel not available");
2450 int sceneIdx =
m_scenePanel->CreateNewScene(wxString::FromUTF8(treeId));
2464 std::shared_ptr<EmberCore::Node> rootNode(tree, rootNodePtr);
2478 SetStatusText(
"Viewing tree: " + wxString::FromUTF8(treeId));
2479 LOG_INFO(
"MainFrame",
"Opened tree '" + treeId +
"' in new scene");
2487 LOG_INFO(
"MainFrame",
"Creating project overview scene with " + std::to_string(
m_projectTrees.size()) +
" trees");
2490 if (!scene || scene->
GetSceneType() !=
"BehaviorTree") {
2506 wxScrolled<wxPanel> *overviewPanel =
new wxScrolled<wxPanel>(btScene->
GetPanel(), wxID_ANY);
2507 overviewPanel->SetBackgroundColour(wxColour(45, 45, 50));
2508 overviewPanel->SetScrollRate(20, 20);
2511 wxBoxSizer *horizontalSizer =
new wxBoxSizer(wxHORIZONTAL);
2514 size_t treeIndex = 0;
2516 const std::string &treeId = pair.first;
2517 auto tree = pair.second;
2525 wxPanel *treePanel =
new wxPanel(overviewPanel, wxID_ANY);
2526 treePanel->SetBackgroundColour(wxColour(45, 45, 50));
2527 wxBoxSizer *treeSizer =
new wxBoxSizer(wxVERTICAL);
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);
2540 vis->SetMinSize(wxSize(600, 400));
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);
2549 treeSizer->Add(vis, 1, wxEXPAND | wxALL, 5);
2550 treePanel->SetSizer(treeSizer);
2553 horizontalSizer->Add(treePanel, 0, wxEXPAND | wxALL, 10);
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);
2565 overviewPanel->SetSizer(horizontalSizer);
2566 overviewPanel->FitInside();
2569 wxSizer *panelSizer = btScene->
GetPanel()->GetSizer();
2571 panelSizer->Clear(
false);
2572 panelSizer->Add(overviewPanel, 1, wxEXPAND | wxALL, 5);
2576 SetStatusText(
"Project Overview: " + wxString::Format(
"%zu trees",
m_projectTrees.size()));
2577 LOG_INFO(
"MainFrame",
"Project overview scene created successfully");
2582 "UpdateTreeSelector called - tab pointer: " + std::string(
m_treeSelectorTab ?
"valid" :
"null") +
2587 LOG_INFO(
"MainFrame",
"Tree selector UpdateTreeList called successfully");
2589 LOG_WARNING(
"MainFrame",
"Tree selector tab is null - cannot update");
2595 LOG_INFO(
"Project",
"No project to close");
2606 if (scene && scene->
GetSceneType() ==
"BehaviorTree") {
2641 SetStatusText(
"Project closed");
2646 wxMessageBox(
"No project is currently open.",
"Information", wxOK | wxICON_INFORMATION,
this);
2650 wxString projectPath = wxString::FromUTF8(
m_activeProject->GetProjectFilePath());
2652 if (projectPath.IsEmpty()) {
2654 wxFileDialog saveDialog(
this,
"Save BehaviorTree Project",
"",
2656 "BehaviorTree Project (*.btproj)|*.btproj", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
2658 if (saveDialog.ShowModal() != wxID_OK) {
2662 projectPath = saveDialog.GetPath();
2666 LOG_INFO(
"Project",
"Project saved: " + projectPath.ToStdString());
2667 SetStatusText(
"Project saved");
2669 wxMessageBox(
"Failed to save project.",
"Error", wxOK | wxICON_ERROR,
this);
2670 LOG_ERROR(
"Project",
"Failed to save project");
2676 wxMessageBox(
"No project is currently open.",
"Information", wxOK | wxICON_INFORMATION,
this);
2681 int result = dialog.ShowModal();
2683 if (result == wxID_OK) {
2686 LOG_INFO(
"Project",
"Project settings updated");
2687 SetStatusText(
"Project settings saved");
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
#define LOG_ERROR(category, message)
#define LOG_WARNING(category, message)
#define LOG_INFO(category, message)
MainFrame::OnExit MainFrame::OnNewProject MainFrame::OnCloseProject MainFrame::OnToggleMaximize MainFrame::OnPreviousScene MainFrame::OnPreferences MainFrame::OnEditorTool EVT_BUTTON(ID_MonitorTool, MainFrame::OnMonitorTool) EVT_PAINT(MainFrame
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) EVT_MENU(wxID_EXIT
MainFrame::OnExit EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) EVT_MENU(ID_NewProject
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.
BehaviorTreeConfig & GetConfig()
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.
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.
Represents a node in a behavior tree structure.
const String & GetName() const
size_t GetChildCount() const
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 RefreshVisualization()
void CenterOnNode(ITreeNode *node)
AppPreferences & GetPreferences()
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()
static wxString GetDir(const wxString &relativeDir)
Get the full path to a resource directory.
Abstract interface for different scene types in the MainPanel.
virtual wxString GetSceneType() const =0
Get a unique identifier for this scene type.
Abstract interface for individual tabs that can be moved between panels.
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.
std::string m_currentTreeId
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
void OnSaveProject(wxCommandEvent &event)
void OnPreferences(wxCommandEvent &event)
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 OnToggleMaximize(wxCommandEvent &event)
void RefreshPreferences()
void OpenTreeInNewScene(const std::string &treeId)
void CreateProjectOverviewScene()
bool m_isUpdatingFromScene
void OnSaveAsXML(wxCommandEvent &event)
void OnMonitorTool(wxCommandEvent &event)
void OnIdle(wxIdleEvent &event)
void OnToggleRightPanel(wxCommandEvent &event)
LeftSidePanel * m_leftPanel
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
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)
std::shared_ptr< EmberCore::BehaviorTreeProject > m_activeProject
void OnNextScene(wxCommandEvent &event)
void OnAbout(wxCommandEvent &event)
wxToolBar * m_panelToggleToolbar
void OnSaveXML(wxCommandEvent &event)
BottomPanel * m_bottomPanel
void OnLoadXML(wxCommandEvent &event)
TreeSelectorTab * m_treeSelectorTab
void OnSceneSelectionChanged(EmberCore::ITreeNode *selectedNode)
std::map< std::string, std::shared_ptr< EmberCore::BehaviorTree > > m_projectTrees
bool HasActiveProject() const
void OnEditorTool(wxCommandEvent &event)
wxString m_currentFilePath
SceneHierarchyTab * m_hierarchyTab
void OnResetUI(wxCommandEvent &event)
void OnHierarchyTabClosed()
PropertiesTab * m_propertiesTab
void OnProjectSettings(wxCommandEvent &event)
void InitializeConfigurationMenu()
void UpdatePanelToggleButtons()
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
Central panel for managing and displaying behavior tree scenes.
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.
EmberCore::String lastOpenedFilePath