/
AuiLayout.cpp
773 lines (623 loc) · 23.4 KB
/
AuiLayout.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
#include "AuiLayout.h"
#include "i18n.h"
#include "ui/imenumanager.h"
#include "ui/imainframe.h"
#include "ui/iuserinterface.h"
#include <wx/sizer.h>
#include <wx/aui/auibook.h>
#include "camera/CameraWndManager.h"
#include "command/ExecutionFailure.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "wxutil/Bitmap.h"
#include "xyview/GlobalXYWnd.h"
#include "AuiFloatingFrame.h"
namespace ui
{
namespace
{
const std::string RKEY_ROOT = "user/ui/mainFrame/aui/";
const std::string RKEY_AUI_PERSPECTIVE = RKEY_ROOT + "perspective";
const std::string RKEY_AUI_PANES = RKEY_ROOT + "panes";
const std::string RKEY_AUI_FLOATING_PANE_LOCATIONS = RKEY_ROOT + "floatingPaneLocations";
const std::string RKEY_AUI_DOCKED_PANE_LOCATIONS = RKEY_ROOT + "dockedPaneLocations";
const std::string RKEY_AUI_LAYOUT_VERSION = RKEY_ROOT + "layoutVersion";
const std::string PANE_NODE_NAME = "pane";
const std::string PANE_NAME_ATTRIBUTE = "paneName";
const std::string STATE_ATTRIBUTE = "state";
const std::string CONTROL_NAME_ATTRIBUTE = "controlName";
constexpr const char* const PROPERTIES_PANEL = "PropertiesPanel";
constexpr int AuiLayoutVersion = 1;
// Minimum size of docked panels
const wxSize MIN_SIZE(128, 128);
// Return a pane info with default options
wxAuiPaneInfo DEFAULT_PANE_INFO(const std::string& caption,
const wxSize& minSize)
{
return wxAuiPaneInfo().Caption(caption).CloseButton(false).MaximizeButton()
.BestSize(minSize).MinSize(minSize).DestroyOnClose(true);
}
void setupFloatingPane(wxAuiPaneInfo& pane)
{
pane.Float().CloseButton(true).MinSize(128, 128);
}
inline bool isCenterPane(const wxAuiPaneInfo& pane)
{
return pane.dock_direction == wxAUI_DOCK_CENTER;
}
}
AuiLayout::AuiLayout() :
_auiMgr(this),
_propertyNotebook(nullptr)
{
_auiMgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_GRADIENT_TYPE, wxAUI_GRADIENT_NONE);
_auiMgr.Bind(wxEVT_AUI_PANE_CLOSE, &AuiLayout::onPaneClose, this);
}
bool AuiLayout::paneNameExists(const std::string& name) const
{
for (const auto& info : _panes)
{
if (info.paneName == name)
{
return true;
}
}
return false;
}
bool AuiLayout::controlExists(const std::string& controlName) const
{
// Check the notebook first
if (_propertyNotebook->controlExists(controlName))
{
return true;
}
for (const auto& info : _panes)
{
if (info.controlName == controlName)
{
return true;
}
}
return false;
}
std::string AuiLayout::generateUniquePaneName(const std::string& controlName)
{
auto paneName = controlName;
auto index = 1;
while (paneNameExists(paneName))
{
paneName = fmt::format("{0}{1}", controlName, ++index);
}
return paneName;
}
void AuiLayout::addPane(const std::string& controlName, wxWindow* window, const wxAuiPaneInfo& info)
{
// Give the pane a unique name so we can restore perspectives
addPane(controlName, generateUniquePaneName(controlName), window, info);
}
void AuiLayout::addPane(const std::string& controlName, const std::string& paneName, wxWindow* window, const wxAuiPaneInfo& info)
{
wxAuiPaneInfo paneInfo = info;
paneInfo.Name(paneName);
// Add and store the pane
_auiMgr.AddPane(window, paneInfo);
// Remember this pane
_panes.push_back({ paneName, controlName, window });
}
void AuiLayout::convertPaneToPropertyTab(const std::string& paneName)
{
for (auto i = _panes.begin(); i != _panes.end(); ++i)
{
if (i->paneName != paneName) continue;
// Close the pane if it's present
if (auto paneInfo = _auiMgr.GetPane(i->paneName); paneInfo.IsOk())
{
_auiMgr.ClosePane(paneInfo);
}
_propertyNotebook->addControl(i->controlName);
_panes.erase(i);
break;
}
}
void AuiLayout::convertFloatingPaneToPropertyTab(AuiFloatingFrame* floatingWindow)
{
for (auto i = _panes.begin(); i != _panes.end(); ++i)
{
auto& paneInfo = _auiMgr.GetPane(i->paneName);
if (paneInfo.IsOk() && paneInfo.IsFloating() && paneInfo.frame == floatingWindow)
{
// Close the floating pane
convertPaneToPropertyTab(i->paneName);
break;
}
}
}
void AuiLayout::handlePaneClosed(wxAuiPaneInfo& pane)
{
// Store the position of this pane before closing
savePaneLocation(pane);
ensureControlIsInactive(pane.window);
// Find and remove the pane info structure
for (auto i = _panes.begin(); i != _panes.end(); ++i)
{
if (i->paneName != pane.name) continue;
_panes.erase(i);
break;
}
// Avoid losing focus of the main window
wxGetTopLevelParent(_auiMgr.GetManagedWindow())->SetFocus();
}
void AuiLayout::onPaneClose(wxAuiManagerEvent& ev)
{
// For floating panes, memorise the last size and position
auto closedPane = ev.GetPane();
handlePaneClosed(*closedPane);
}
void AuiLayout::saveStateToRegistry()
{
registry::setValue(RKEY_AUI_LAYOUT_VERSION, AuiLayoutVersion);
// Save the pane perspective
registry::setValue(RKEY_AUI_PERSPECTIVE, _auiMgr.SavePerspective().ToStdString());
// Save tracked panes, we need to create all named panes before we can load the perspective
GlobalRegistry().deleteXPath(RKEY_AUI_PANES);
auto panesKey = GlobalRegistry().createKey(RKEY_AUI_PANES);
for (const auto& pane : _panes)
{
auto& paneInfo = _auiMgr.GetPane(pane.control);
// Skip hidden panels
if (!paneInfo.IsShown())
{
continue;
}
auto paneNode = panesKey.createChild(PANE_NODE_NAME);
paneNode.setAttributeValue(CONTROL_NAME_ATTRIBUTE, pane.controlName);
paneNode.setAttributeValue(PANE_NAME_ATTRIBUTE, pane.paneName);
}
// Persist the floating pane locations
GlobalRegistry().deleteXPath(RKEY_AUI_FLOATING_PANE_LOCATIONS);
auto floatingPanesKey = GlobalRegistry().createKey(RKEY_AUI_FLOATING_PANE_LOCATIONS);
for (const auto& [name, state] : _floatingPaneLocations)
{
auto paneNode = floatingPanesKey.createChild(PANE_NODE_NAME);
paneNode.setAttributeValue(PANE_NAME_ATTRIBUTE, name);
paneNode.setAttributeValue(STATE_ATTRIBUTE, state);
}
// Persist the docked pane locations
GlobalRegistry().deleteXPath(RKEY_AUI_DOCKED_PANE_LOCATIONS);
auto dockedPanesKey = GlobalRegistry().createKey(RKEY_AUI_DOCKED_PANE_LOCATIONS);
for (const auto& [name, state] : _dockedPaneLocations)
{
auto paneNode = dockedPanesKey.createChild(PANE_NODE_NAME);
paneNode.setAttributeValue(PANE_NAME_ATTRIBUTE, name);
paneNode.setAttributeValue(STATE_ATTRIBUTE, state);
}
// Save property notebook stae
_propertyNotebook->saveState();
}
void AuiLayout::activate()
{
auto topLevelParent = GlobalMainFrame().getWxTopLevelWindow();
// AUI manager can't manage a Sizer, we need to create an actual wxWindow
// container
auto managedArea = new wxWindow(topLevelParent, wxID_ANY);
_auiMgr.SetManagedWindow(managedArea);
GlobalMainFrame().getWxMainContainer()->Add(managedArea, 1, wxEXPAND);
_propertyNotebook = new PropertyNotebook(managedArea, *this);
_auiMgr.SetPropertyNotebook(_propertyNotebook);
auto orthoViewControl = GlobalUserInterface().findControl(UserControl::OrthoView);
auto cameraControl = GlobalUserInterface().findControl(UserControl::Camera);
assert(cameraControl);
assert(orthoViewControl);
// Add the camera and notebook to the left, as with the Embedded layout, and
// the 2D view on the right
wxSize size = topLevelParent->GetSize();
size.Scale(0.5, 1.0);
// Force a minimum width of the camera
auto camera = cameraControl->createWidget(managedArea);
auto previousMinSize = camera->GetMinSize();
camera->SetMinSize(wxSize(600, -1));
addPane(cameraControl->getControlName(), camera,
DEFAULT_PANE_INFO(cameraControl->getDisplayName(), size).Left().Position(0));
addPane(PROPERTIES_PANEL, _propertyNotebook,
DEFAULT_PANE_INFO(_("Properties"), size).Left().Position(1).DestroyOnClose(false));
addPane(orthoViewControl->getControlName(), orthoViewControl->createWidget(managedArea),
DEFAULT_PANE_INFO(orthoViewControl->getDisplayName(), size).CenterPane());
_auiMgr.Update();
// Reset the camera min size
camera->SetMinSize(previousMinSize);
// Hide the camera toggle option for non-floating views
GlobalMenuManager().setVisibility("main/view/cameraview", false);
// Hide the console/texture browser toggles for non-floating/non-split views
GlobalMenuManager().setVisibility("main/view/textureBrowser", false);
}
void AuiLayout::deactivate()
{
// Get a reference to the managed window, it might be cleared by UnInit()
auto managedWindow = _auiMgr.GetManagedWindow();
// Unregister the AuiMgr from the event handlers of the managed window
// otherwise we run into crashes during shutdown (#5586)
_auiMgr.UnInit();
managedWindow->Destroy();
}
void AuiLayout::createPane(const std::string& controlName, const std::string& paneName,
const std::function<void(wxAuiPaneInfo&)>& setupPane)
{
auto control = GlobalUserInterface().findControl(controlName);
if (!control)
{
rError() << "Cannot find named control: " << controlName << std::endl;
return;
}
auto managedWindow = _auiMgr.GetManagedWindow();
auto pane = DEFAULT_PANE_INFO(control->getDisplayName(), MIN_SIZE);
pane.name = paneName;
// Create the widget and determine the best default size
auto widget = control->createWidget(managedWindow);
// Fit and determine the floating size automatically
widget->Fit();
// Some additional height for the window title bar
pane.FloatingSize(widget->GetSize().x, widget->GetSize().y + 30);
// Run client code to set up the pane properties, do this after setting the default size
// since the client code may also try to restore any persisted size info
setupPane(pane);
if (!control->getIcon().empty())
{
pane.Icon(wxutil::GetLocalBitmap(control->getIcon()));
}
_auiMgr.AddPane(widget, pane);
_panes.push_back({ paneName, controlName, widget });
}
void AuiLayout::createFloatingControl(const std::string& controlName)
{
auto paneName = generateUniquePaneName(controlName);
createPane(controlName, paneName, [&](auto& paneInfo)
{
setupFloatingPane(paneInfo);
// Check for the default floating size
auto defaultSettings = _defaultControlSettings.find(controlName);
if (defaultSettings != _defaultControlSettings.end())
{
paneInfo.FloatingSize(defaultSettings->second.defaultFloatingWidth,
defaultSettings->second.defaultFloatingHeight);
}
restorePaneLocation(paneInfo);
});
auto& paneInfo = _auiMgr.GetPane(paneName);
ensureControlIsActive(paneInfo.window);
_auiMgr.Update();
}
void AuiLayout::registerControl(const std::string& controlName, const IMainFrame::ControlSettings& defaultSettings)
{
_defaultControlSettings[controlName] = defaultSettings;
}
void AuiLayout::createControl(const std::string& controlName)
{
auto defaultSettings = _defaultControlSettings.find(controlName);
if (defaultSettings == _defaultControlSettings.end())
{
return;
}
switch (defaultSettings->second.location)
{
case IMainFrame::Location::PropertyPanel:
_propertyNotebook->addControl(controlName);
break;
case IMainFrame::Location::FloatingWindow:
createFloatingControl(controlName);
break;
}
}
void AuiLayout::ensureControlIsActive(wxWindow* control)
{
if (auto dockablePanel = dynamic_cast<wxutil::DockablePanel*>(control); dockablePanel)
{
dockablePanel->activatePanel();
}
}
void AuiLayout::ensureControlIsInactive(wxWindow* control)
{
if (auto dockablePanel = dynamic_cast<wxutil::DockablePanel*>(control); dockablePanel)
{
dockablePanel->deactivatePanel();
}
}
void AuiLayout::focusControl(const std::string& controlName)
{
// Locate the control, is it loaded anywhere?
if (!controlExists(controlName))
{
// Control is not loaded anywhere, check the named settings
// Check the default settings if there's a control
if (_defaultControlSettings.count(controlName) == 0)
{
throw cmd::ExecutionFailure(fmt::format(_("Cannot focus unknown control {0}"), controlName));
}
// Create the control in its default location
createControl(controlName);
}
// Focus matching controls in the property notebook
_propertyNotebook->focusControl(controlName);
// Ensure the property panel is visible when focusing a tab
auto& propertyPane = _auiMgr.GetPane(PROPERTIES_PANEL);
if (!propertyPane.IsShown())
{
propertyPane.Show(true);
_auiMgr.Update();
}
// Unset the focus of any wxPanels in floating windows
for (auto p = _panes.begin(); p != _panes.end(); ++p)
{
if (p->controlName != controlName) continue;
auto& paneInfo = _auiMgr.GetPane(p->control);
// Show hidden panes
if (!paneInfo.IsShown())
{
paneInfo.Show();
ensureControlIsActive(p->control);
_auiMgr.Update();
}
if (auto panel = wxDynamicCast(p->control, wxPanel); panel != nullptr)
{
panel->SetFocusIgnoringChildren();
}
break;
}
}
void AuiLayout::toggleControlInPropertyPanel(const std::string& controlName)
{
// If the control is a property tab, make it visible
// If the notbeook is floating, toggling a visible tab also toggles the whole notebook
auto& propertyPane = _auiMgr.GetPane(PROPERTIES_PANEL);
if (propertyPane.IsFloating())
{
// Toggling a visible tab in the floating panel hides the whole notebook
if (propertyPane.IsShown() && _propertyNotebook->controlIsVisible(controlName))
{
propertyPane.Hide();
_auiMgr.Update();
return;
}
// Tab is not visible yet, focus it
_propertyNotebook->focusControl(controlName);
// Ensure the floating pane is visible
if (!propertyPane.IsShown())
{
propertyPane.Show(true);
_auiMgr.Update();
}
}
else // Property panel is docked
{
// Focus matching controls in the property notebook
_propertyNotebook->focusControl(controlName);
// Ensure the non-floating property panel is visible
if (!propertyPane.IsShown())
{
propertyPane.Show(true);
_auiMgr.Update();
}
}
}
void AuiLayout::toggleControl(const std::string& controlName)
{
// Check the default settings if there's a control
if (_defaultControlSettings.count(controlName) == 0)
{
throw cmd::ExecutionFailure(fmt::format(_("Cannot toggle unknown control {0}"), controlName));
}
// Locate the control, is it loaded anywhere?
if (!controlExists(controlName))
{
// Control is not loaded anywhere; focusControl will create it in its default location
focusControl(controlName);
return;
}
// Control exists, we can toggle
// Controls in the property panel receive special treatment on toggling
if (_propertyNotebook->controlExists(controlName))
{
toggleControlInPropertyPanel(controlName);
return;
}
// If it's a docked pane, toggle its visibility
for (auto p = _panes.begin(); p != _panes.end(); ++p)
{
if (p->controlName != controlName) continue;
auto& paneInfo = _auiMgr.GetPane(p->control);
// Show/hide, unless it's the center pane
if (!isCenterPane(paneInfo))
{
if (paneInfo.IsShown())
{
savePaneLocation(paneInfo);
paneInfo.Hide();
ensureControlIsInactive(p->control);
}
else
{
paneInfo.Show();
restorePaneLocation(paneInfo);
if (paneInfo.dock_direction == wxAUI_DOCK_LEFT || paneInfo.dock_direction == wxAUI_DOCK_RIGHT)
{
// Set the minimum width of this restored pane otherwise the
// wxAuiManager::Update() routine is resetting the pane to its minimum dimensions
paneInfo.MinSize(paneInfo.rect.GetSize().x, -1);
}
ensureControlIsActive(p->control);
}
_auiMgr.Update();
// Reset the mininum size again to not interfere with any drag operations
if (paneInfo.IsDocked())
{
paneInfo.MinSize(MIN_SIZE);
}
}
break;
}
}
void AuiLayout::removeNonOrthoCenterPanes()
{
for (auto p = _panes.begin(); p != _panes.end();)
{
auto& paneInfo = _auiMgr.GetPane(p->paneName);
if (!isCenterPane(paneInfo) || string::starts_with(paneInfo.name.ToStdString(), UserControl::OrthoView))
{
++p;
continue;
}
ensureControlIsInactive(paneInfo.window);
paneInfo.DestroyOnClose(true);
_auiMgr.ClosePane(paneInfo);
_panes.erase(p++);
}
}
void AuiLayout::toggleMainControl(const std::string& controlName)
{
// Check the center pane to see what's currently in there
for (auto p = _panes.begin(); p != _panes.end(); ++p)
{
auto& paneInfo = _auiMgr.GetPane(p->paneName);
if (!isCenterPane(paneInfo) || !paneInfo.IsShown()) continue;
// If the existing pane has already the requested control, switch back to ortho
auto newControlName = string::starts_with(paneInfo.name.ToStdString(), controlName) ? UserControl::OrthoView : controlName;
if (newControlName == paneInfo.name) return; // nothing to do
auto control = GlobalUserInterface().findControl(newControlName);
if (!control)
{
throw std::invalid_argument("Cannot make " + newControlName + " to a main control");
}
rMessage() << "Swapping " << newControlName << " with the existing main control " <<
paneInfo.name.ToStdString() << std::endl;
// Find the hidden OrthoView pane
auto& existingOrthoView = _auiMgr.GetPane(UserControl::OrthoView);
if (newControlName == UserControl::OrthoView)
{
existingOrthoView.Show();
ensureControlIsActive(existingOrthoView.window);
removeNonOrthoCenterPanes();
}
else
{
// Hide the existing OrthoView pane
existingOrthoView.Hide();
ensureControlIsInactive(existingOrthoView.window);
// Close all other center panes, we don't need two main panels
removeNonOrthoCenterPanes();
// Add the new control as center pane
auto newWidget = control->createWidget(_auiMgr.GetManagedWindow());
addPane(newControlName, newWidget, DEFAULT_PANE_INFO(control->getDisplayName(), MIN_SIZE).CenterPane());
ensureControlIsActive(newWidget);
}
_auiMgr.Update();
break;
}
}
void AuiLayout::savePaneLocation(wxAuiPaneInfo& pane)
{
if (pane.IsFloating())
{
_floatingPaneLocations[pane.name.ToStdString()] = _auiMgr.SavePaneInfo(pane).ToStdString();
}
else
{
_dockedPaneLocations[pane.name.ToStdString()] = _auiMgr.SavePaneInfo(pane).ToStdString();
}
}
void AuiLayout::restorePaneLocation(wxAuiPaneInfo& pane)
{
// Check if we got existing size information for this floating pane
const auto& locations = pane.IsFloating() ? _floatingPaneLocations : _dockedPaneLocations;
auto existingSizeInfo = locations.find(pane.name.ToStdString());
if (existingSizeInfo != locations.end())
{
_auiMgr.LoadPaneInfo(existingSizeInfo->second, pane);
}
}
void AuiLayout::restoreStateFromRegistry()
{
// Check the saved version
if (registry::getValue<int>(RKEY_AUI_LAYOUT_VERSION) != AuiLayoutVersion)
{
rMessage() << "No compatible AUI layout state information found in registry" << std::endl;
// We still need to set up the default pages of the notebook
_propertyNotebook->restoreDefaultState();
return;
}
_floatingPaneLocations.clear();
for (const auto& node : GlobalRegistry().findXPath(RKEY_AUI_FLOATING_PANE_LOCATIONS + "//*"))
{
_floatingPaneLocations[node.getAttributeValue(PANE_NAME_ATTRIBUTE)] = node.getAttributeValue(STATE_ATTRIBUTE);
}
_dockedPaneLocations.clear();
for (const auto& node : GlobalRegistry().findXPath(RKEY_AUI_DOCKED_PANE_LOCATIONS + "//*"))
{
_dockedPaneLocations[node.getAttributeValue(PANE_NAME_ATTRIBUTE)] = node.getAttributeValue(STATE_ATTRIBUTE);
}
// Restore all missing panes, this has to be done before the perspective is restored
for (const auto& node : GlobalRegistry().findXPath(RKEY_AUI_PANES + "//*"))
{
if (node.getName() != PANE_NODE_NAME) continue;
auto controlName = node.getAttributeValue(CONTROL_NAME_ATTRIBUTE);
auto paneName = node.getAttributeValue(PANE_NAME_ATTRIBUTE);
if (paneNameExists(paneName)) continue; // this one already exists
createPane(controlName, paneName, setupFloatingPane);
}
// Restore the property notebook state (will fall back to default if nothing found)
_propertyNotebook->restoreState();
// Nasty hack to get the panes sized properly. Since BestSize() is
// completely ignored (at least on Linux), we have to add the panes with a
// large *minimum* size and then reset this size after the initial addition.
for (const auto& info : _panes)
{
_auiMgr.GetPane(info.control).MinSize(MIN_SIZE);
}
_auiMgr.Update();
// If we have a stored perspective, load it
auto storedPersp = registry::getValue<std::string>(RKEY_AUI_PERSPECTIVE);
if (!storedPersp.empty())
{
_auiMgr.LoadPerspective(storedPersp);
}
// Make sure the properties panel can be closed (the flag might still be set on the stored perspective)
auto& propertyPane = _auiMgr.GetPane(PROPERTIES_PANEL);
propertyPane.CloseButton(true).DestroyOnClose(false);
ensureVisibleCenterPane();
// After restoring the perspective, ensure all visible panes are active
for (const auto& info : _panes)
{
auto& paneInfo = _auiMgr.GetPane(info.control);
if (paneInfo.IsShown())
{
ensureControlIsActive(paneInfo.window);
}
else
{
ensureControlIsInactive(paneInfo.window);
}
}
}
void AuiLayout::ensureVisibleCenterPane()
{
// Ensure if we have a visible center pane
bool hasVisibleCenterPane = false;
wxAuiPaneInfo* centerOrthoPane = nullptr;
for (const auto& info : _panes)
{
auto& paneInfo = _auiMgr.GetPane(info.paneName);
if (!isCenterPane(paneInfo)) continue;
if (paneInfo.IsShown())
{
hasVisibleCenterPane = true;
}
if (paneInfo.name == UserControl::OrthoView)
{
centerOrthoPane = &paneInfo;
}
}
if (!hasVisibleCenterPane && centerOrthoPane != nullptr)
{
// Set the default ortho view center pane to visible
centerOrthoPane->Show();
_auiMgr.Update();
}
}
} // namespace ui