Ember
Loading...
Searching...
No Matches
TabFactory.cpp
Go to the documentation of this file.
2#include "App/MainFrame.h"
4#include "Tabs/LogTab.h"
8#include "Utils/Logger.h"
10
11namespace EmberForge {
12
13std::unique_ptr<ITab> TabFactory::CreateTab(TabType type, wxWindow *parent, MainFrame *mainFrame) {
14 if (!parent) {
15 LOG_ERROR("TabFactory", "Cannot create tab: parent window is null");
16 return nullptr;
17 }
18
19 try {
20 switch (type) {
22 LOG_INFO("TabFactory", "Creating Scene Hierarchy tab");
23 auto tab = std::make_unique<SceneHierarchyTab>(parent, mainFrame);
24
25 // If we have a main frame, update its reference and set the tree
26 if (mainFrame) {
27 mainFrame->UpdateHierarchyTabReference(tab.get());
28 }
29
30 return tab;
31 }
32
34 LOG_INFO("TabFactory", "Creating Properties tab");
35 auto tab = std::make_unique<PropertiesTab>(parent, mainFrame);
36
37 // If we have a main frame, update its reference and set the selected node
38 if (mainFrame) {
39 mainFrame->UpdatePropertiesTabReference(tab.get());
40 }
41
42 return tab;
43 }
44
45 case TabType::Log: {
46 LOG_INFO("TabFactory", "Creating Log tab");
47 return std::make_unique<LogTab>(parent);
48 }
49
51 LOG_INFO("TabFactory", "Creating Performance tab");
52 return std::make_unique<EmberForge::PerformancePanel>(parent);
53 }
54
56 LOG_INFO("TabFactory", "Creating File Explorer tab");
57 return std::make_unique<FileExplorerTab>(parent);
58 }
59
61 LOG_INFO("TabFactory", "Creating Tree Selector tab");
62 auto tab = std::make_unique<TreeSelectorTab>(parent, mainFrame);
63
64 if (mainFrame) {
65 mainFrame->UpdateTreeSelectorTabReference(tab.get());
66 }
67
68 return tab;
69 }
70
71 default:
72 LOG_ERROR("TabFactory", "Unknown tab type requested: " + std::to_string(static_cast<int>(type)));
73 return nullptr;
74 }
75 } catch (const std::exception &e) {
76 LOG_ERROR("TabFactory", "Exception while creating tab: " + std::string(e.what()));
77 return nullptr;
78 } catch (...) {
79 LOG_ERROR("TabFactory", "Unknown exception while creating tab");
80 return nullptr;
81 }
82}
83
85 switch (type) {
87 return "Scene Hierarchy";
89 return "Properties";
90 case TabType::Log:
91 return "Log";
93 return "Performance";
95 return "File Explorer";
97 return "Tree Selector";
98 default:
99 return "Unknown Tab";
100 }
101}
102
104 switch (type) {
106 return "Display and navigate the behavior tree hierarchy";
108 return "View and edit object properties";
109 case TabType::Log:
110 return "View application logs and debug information";
112 return "Monitor application performance metrics";
114 return "Browse and manage project files";
116 return "Select and switch between behavior trees in the project";
117 default:
118 return "Unknown tab type";
119 }
120}
121
123 switch (type) {
125 return false; // Only one hierarchy view per panel makes sense
127 return false; // Only one properties panel per panel makes sense
128 case TabType::Log:
129 return false; // Only one log panel per panel makes sense
131 return false; // Only one performance panel per panel makes sense
133 return false; // Only one file explorer per panel makes sense
135 return false; // Only one tree selector per panel makes sense
136 default:
137 return false; // Default to single instance
138 }
139}
140
142 // Configure the maximum number of instances allowed across ALL panels.
143 // Return 0 = unlimited instances
144 // Return 1 = single global instance (default for most tabs)
145 // Return 2+ = allow that many instances across panels
146 switch (type) {
148 return 1; // Only one hierarchy view in the entire app
149 case TabType::Log:
150 return 1; // Only one log output
152 return 1; // Only one performance monitor
154 return 1; // Only one file explorer
156 return 1; // Change to 2 to allow in two panels
158 return 1; // Only one tree selector in the entire app
159 default:
160 return 1; // Default: single global instance
161 }
162}
163
165 // Configure which tabs are allowed in which panel types.
166 // This provides fine-grained control over tab placement.
167 switch (tabType) {
169 // Scene Hierarchy: only in side panels (left/right)
170 return panelType == PanelType::LeftPanel || panelType == PanelType::RightPanel;
171
173 // Properties: only in side panels (left/right)
174 return panelType == PanelType::LeftPanel || panelType == PanelType::RightPanel;
175
176 case TabType::Log:
177 // Log: only in bottom panel
178 return panelType == PanelType::BottomPanel;
179
181 // Performance: only in bottom panel
182 return panelType == PanelType::BottomPanel;
183
185 // File Explorer: only in bottom panel
186 return panelType == PanelType::BottomPanel;
187
189 // Tree Selector: only in side panels (left/right)
190 return panelType == PanelType::LeftPanel || panelType == PanelType::RightPanel;
191
192 default:
193 return true; // Allow by default
194 }
195}
196
201
205
209
211 switch (type) {
213 return "SceneHierarchy";
215 return "Properties";
216 case TabType::Log:
217 return "Log";
219 return "Performance";
221 return "FileExplorer";
223 return "TreeSelector";
224 default:
225 return "FileExplorer";
226 }
227}
228
229TabType TabFactory::StringToTabType(const std::string &str) {
230 if (str == "SceneHierarchy")
232 if (str == "Properties")
233 return TabType::Properties;
234 if (str == "Log")
235 return TabType::Log;
236 if (str == "Performance")
238 if (str == "FileExplorer")
240 if (str == "TreeSelector")
242 return TabType::FileExplorer; // Default
243}
244
245} // namespace EmberForge
#define LOG_ERROR(category, message)
Definition Logger.h:116
#define LOG_INFO(category, message)
Definition Logger.h:114
static wxString GetTabDisplayName(TabType type)
Get the display name for a tab type.
static wxString GetTabTooltip(TabType type)
Get the tooltip text for a tab type.
static std::unique_ptr< ITab > CreateTab(TabType type, wxWindow *parent, MainFrame *mainFrame=nullptr)
Create a tab of the specified type.
static std::vector< TabType > GetSidePanelTabTypes()
Get tab types supported by the side panels.
static std::string TabTypeToString(TabType type)
Convert tab type to string identifier (for preferences storage)
static int GetMaxGlobalInstances(TabType type)
Get the maximum number of instances allowed globally across all panels.
static std::vector< TabType > GetAvailableTabTypes()
Get all available tab types.
static bool IsTabAllowedInPanel(TabType tabType, EmberForge::PanelType panelType)
Check if a tab type is allowed in a specific panel type.
static bool AllowMultipleInstances(TabType type)
Check if a tab type can be created multiple times within a single panel.
static TabType StringToTabType(const std::string &str)
Convert string identifier to tab type.
static std::vector< TabType > GetBottomPanelTabTypes()
Get tab types supported by the bottom panel.
Main application window for EmberForge.
Definition MainFrame.h:65
void UpdatePropertiesTabReference(PropertiesTab *propertiesTab)
void UpdateTreeSelectorTabReference(TreeSelectorTab *treeSelectorTab)
void UpdateHierarchyTabReference(SceneHierarchyTab *hierarchyTab)
PanelType
Defines the type of panel in the UI hierarchy.
TabType
Enumeration of available tab types.
Definition TabFactory.h:17