/
GlobalXYWnd.cpp
701 lines (581 loc) · 19.9 KB
/
GlobalXYWnd.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
#include "GlobalXYWnd.h"
#include "i18n.h"
#include "ui/ieventmanager.h"
#include "ui/istatusbarmanager.h"
#include "ui/imainframe.h"
#include "ipreferencesystem.h"
#include "ui/iuserinterface.h"
#include "registry/registry.h"
#include "module/StaticModule.h"
#include "camera/CameraWndManager.h"
#include "wxutil/MouseButton.h"
#include "tools/BrushCreatorTool.h"
#include "tools/ClipperTool.h"
#include "tools/ZoomTool.h"
#include "tools/CameraAngleTool.h"
#include "tools/CameraMoveTool.h"
#include "tools/MoveViewTool.h"
#include "tools/MeasurementTool.h"
#include "debugging/ScopedDebugTimer.h"
#include <functional>
namespace ui
{
namespace
{
const std::string RKEY_XYVIEW_ROOT = "user/ui/xyview";
const std::string RKEY_CHASE_MOUSE = RKEY_XYVIEW_ROOT + "/chaseMouse";
const std::string RKEY_CHASE_MOUSE_CAP = RKEY_XYVIEW_ROOT + "/chaseMouseCap";
const std::string RKEY_CAMERA_XY_UPDATE = RKEY_XYVIEW_ROOT + "/camXYUpdate";
const std::string RKEY_SHOW_CROSSHAIRS = RKEY_XYVIEW_ROOT + "/showCrossHairs";
const std::string RKEY_SHOW_GRID = RKEY_XYVIEW_ROOT + "/showGrid";
const std::string RKEY_SHOW_SIZE_INFO = RKEY_XYVIEW_ROOT + "/showSizeInfo";
const std::string RKEY_SHOW_ENTITY_ANGLES = RKEY_XYVIEW_ROOT + "/showEntityAngles";
const std::string RKEY_SHOW_ENTITY_NAMES = RKEY_XYVIEW_ROOT + "/showEntityNames";
const std::string RKEY_SHOW_BLOCKS = RKEY_XYVIEW_ROOT + "/showBlocks";
const std::string RKEY_SHOW_COORDINATES = RKEY_XYVIEW_ROOT + "/showCoordinates";
const std::string RKEY_SHOW_OUTLINE = RKEY_XYVIEW_ROOT + "/showOutline";
const std::string RKEY_SHOW_AXES = RKEY_XYVIEW_ROOT + "/showAxes";
const std::string RKEY_SHOW_WORKZONE = RKEY_XYVIEW_ROOT + "/showWorkzone";
const std::string RKEY_DEFAULT_BLOCKSIZE = "user/ui/xyview/defaultBlockSize";
const std::string RKEY_TRANSLATE_CONSTRAINED = "user/ui/xyview/translateConstrained";
const std::string RKEY_FONT_SIZE = "user/ui/xyview/fontSize";
const std::string RKEY_FONT_STYLE = "user/ui/xyview/fontStyle";
const std::string RKEY_MAX_ZOOM_FACTOR = "user/ui/xyview/maxZoomFactor";
const std::string RKEY_CURSOR_CENTERED_ZOOM = "user/ui/xyview/cursorCenteredZoom";
const int DEFAULT_CHASE_MOUSE_CAP = 32; // pixels per chase moue timer interval
}
class OrthoviewControl :
public IUserControl
{
public:
std::string getControlName() override
{
return UserControl::OrthoView;
}
std::string getDisplayName() override
{
return _("2D View");
}
wxWindow* createWidget(wxWindow* parent) override
{
auto xyWnd = GlobalXYWnd().createEmbeddedOrthoView(XY, parent);
return xyWnd->getGLWidget();
}
};
// Constructor
XYWndManager::XYWndManager() :
_maxZoomFactor(1024)
{}
void XYWndManager::destroyViews()
{
// Discard the whole list
for (auto i = _xyWnds.begin(); i != _xyWnds.end(); /* in-loop incr.*/)
{
// Extract the pointer to prevent the destructor from firing
XYWndPtr candidate = i->second;
// Now remove the item from the map, increase the iterator
_xyWnds.erase(i++);
// greebo: Release the shared_ptr, this fires the destructor chain
// which eventually reaches notifyXYWndDestroy(). This is safe at this
// point, because the id is not found in the map anymore, thus
// double-deletions are prevented.
candidate = XYWndPtr();
}
_activeXY = XYWndPtr();
}
void XYWndManager::registerCommands()
{
GlobalMainFrame().signal_MainFrameConstructed().connect([&]()
{
GlobalMainFrame().addControl(UserControl::OrthoView, { IMainFrame::Location::FloatingWindow, false });
});
GlobalCommandSystem().addStatement("NewOrthoView", fmt::format("CreateControl {0}", UserControl::OrthoView), false);
GlobalCommandSystem().addCommand("NextView", std::bind(&XYWndManager::toggleActiveView, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("ZoomIn", std::bind(&XYWndManager::zoomIn, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("ZoomOut", std::bind(&XYWndManager::zoomOut, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("ViewTop", std::bind(&XYWndManager::setActiveViewXY, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("ViewSide", std::bind(&XYWndManager::setActiveViewXZ, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("ViewFront", std::bind(&XYWndManager::setActiveViewYZ, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("CenterXYViews", std::bind(&XYWndManager::splitViewFocus, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("CenterXYView", std::bind(&XYWndManager::focusActiveView, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("Zoom100", std::bind(&XYWndManager::zoom100, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("RunBenchmark", std::bind(&XYWndManager::runBenchmark, this, std::placeholders::_1),
{ cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL });
GlobalEventManager().addRegistryToggle("ToggleCrosshairs", RKEY_SHOW_CROSSHAIRS);
GlobalEventManager().addRegistryToggle("ToggleGrid", RKEY_SHOW_GRID);
GlobalEventManager().addRegistryToggle("ShowAngles", RKEY_SHOW_ENTITY_ANGLES);
GlobalEventManager().addRegistryToggle("ShowNames", RKEY_SHOW_ENTITY_NAMES);
GlobalEventManager().addRegistryToggle("ShowBlocks", RKEY_SHOW_BLOCKS);
GlobalEventManager().addRegistryToggle("ShowCoordinates", RKEY_SHOW_COORDINATES);
GlobalEventManager().addRegistryToggle("ShowWindowOutline", RKEY_SHOW_OUTLINE);
GlobalEventManager().addRegistryToggle("ShowAxes", RKEY_SHOW_AXES);
GlobalEventManager().addRegistryToggle("ShowWorkzone", RKEY_SHOW_WORKZONE);
GlobalEventManager().addRegistryToggle("ToggleShowSizeInfo", RKEY_SHOW_SIZE_INFO);
}
void XYWndManager::constructPreferences()
{
IPreferencePage& page = GlobalPreferenceSystem().getPage(_("Settings/Orthoview"));
page.appendCheckBox(_("View chases Mouse Cursor during Drags"), RKEY_CHASE_MOUSE);
page.appendSlider(_("Maximum Chase Mouse Speed"), RKEY_CHASE_MOUSE_CAP, 0, 512, 1, 16);
page.appendCheckBox(_("Update Views on Camera Movement"), RKEY_CAMERA_XY_UPDATE);
page.appendCheckBox(_("Show Crosshairs"), RKEY_SHOW_CROSSHAIRS);
page.appendCheckBox(_("Show Grid"), RKEY_SHOW_GRID);
page.appendCheckBox(_("Show Size Info"), RKEY_SHOW_SIZE_INFO);
page.appendCheckBox(_("Show Entity Angle Arrow"), RKEY_SHOW_ENTITY_ANGLES);
page.appendCheckBox(_("Show Entity Names"), RKEY_SHOW_ENTITY_NAMES);
page.appendCheckBox(_("Show Blocks"), RKEY_SHOW_BLOCKS);
page.appendCheckBox(_("Show Coordinates"), RKEY_SHOW_COORDINATES);
page.appendCheckBox(_("Show Axes"), RKEY_SHOW_AXES);
page.appendCheckBox(_("Show Window Outline"), RKEY_SHOW_OUTLINE);
page.appendCheckBox(_("Show Workzone"), RKEY_SHOW_WORKZONE);
page.appendCheckBox(_("Translate Manipulator always constrained to Axis"), RKEY_TRANSLATE_CONSTRAINED);
page.appendCheckBox(_("Higher Selection Priority for Entities"), RKEY_HIGHER_ENTITY_PRIORITY);
page.appendSpinner(_("Maximum Zoom Factor"), RKEY_MAX_ZOOM_FACTOR, 1, 65536, 0);
page.appendCheckBox(_("Zoom centers on Mouse Cursor"), RKEY_CURSOR_CENTERED_ZOOM);
page.appendCombo(_("Font Style"), RKEY_FONT_STYLE, { "Sans", "Mono" }, true);
page.appendSpinner(_("Font Size"), RKEY_FONT_SIZE, 4, 48, 0);
}
// Load/Reload the values from the registry
void XYWndManager::refreshFromRegistry()
{
_chaseMouse = registry::getValue<bool>(RKEY_CHASE_MOUSE);
_chaseMouseCap = registry::getValue<int>(RKEY_CHASE_MOUSE_CAP, DEFAULT_CHASE_MOUSE_CAP);
_camXYUpdate = registry::getValue<bool>(RKEY_CAMERA_XY_UPDATE);
_showCrossHairs = registry::getValue<bool>(RKEY_SHOW_CROSSHAIRS);
_showGrid = registry::getValue<bool>(RKEY_SHOW_GRID);
_showSizeInfo = registry::getValue<bool>(RKEY_SHOW_SIZE_INFO);
_showBlocks = registry::getValue<bool>(RKEY_SHOW_BLOCKS);
_showCoordinates = registry::getValue<bool>(RKEY_SHOW_COORDINATES);
_showOutline = registry::getValue<bool>(RKEY_SHOW_OUTLINE);
_showAxes = registry::getValue<bool>(RKEY_SHOW_AXES);
_showWorkzone = registry::getValue<bool>(RKEY_SHOW_WORKZONE);
_defaultBlockSize = registry::getValue<int>(RKEY_DEFAULT_BLOCKSIZE);
_fontSize = registry::getValue<int>(RKEY_FONT_SIZE);
_fontStyle = registry::getValue<std::string>(RKEY_FONT_STYLE) == "Sans" ? IGLFont::Style::Sans : IGLFont::Style::Mono;
_maxZoomFactor = registry::getValue<float>(RKEY_MAX_ZOOM_FACTOR);
_zoomCenteredOnMouseCursor = registry::getValue<bool>(RKEY_CURSOR_CENTERED_ZOOM);
updateAllViews();
for (const auto& xyWnd : _xyWnds)
{
xyWnd.second->updateFont();
}
}
bool XYWndManager::chaseMouse() const {
return _chaseMouse;
}
int XYWndManager::chaseMouseCap() const
{
return _chaseMouseCap;
}
bool XYWndManager::camXYUpdate() const {
return _camXYUpdate;
}
bool XYWndManager::showCrossHairs() const {
return _showCrossHairs;
}
bool XYWndManager::showBlocks() const {
return _showBlocks;
}
unsigned int XYWndManager::defaultBlockSize() const {
return _defaultBlockSize;
}
bool XYWndManager::showCoordinates() const {
return _showCoordinates;
}
bool XYWndManager::showOutline() const {
return _showOutline;
}
bool XYWndManager::showAxes() const {
return _showAxes;
}
bool XYWndManager::showWorkzone() const {
return _showWorkzone;
}
bool XYWndManager::showGrid() const {
return _showGrid;
}
bool XYWndManager::showSizeInfo() const {
return _showSizeInfo;
}
int XYWndManager::fontSize() const
{
return _fontSize;
}
IGLFont::Style XYWndManager::fontStyle() const
{
return _fontStyle;
}
float XYWndManager::maxZoomFactor() const
{
return _maxZoomFactor;
}
bool XYWndManager::zoomCenteredOnMouseCursor() const
{
return _zoomCenteredOnMouseCursor;
}
void XYWndManager::updateAllViews(bool force)
{
for (const XYWndMap::value_type& i : _xyWnds)
{
if (force)
{
i.second->forceRedraw();
}
else
{
i.second->queueDraw();
}
}
}
void XYWndManager::zoomIn(const cmd::ArgumentList& args) {
if (_activeXY != NULL) {
_activeXY->zoomIn();
}
}
void XYWndManager::zoomOut(const cmd::ArgumentList& args) {
if (_activeXY != NULL) {
_activeXY->zoomOut();
}
}
XYWndPtr XYWndManager::getActiveXY() const {
return _activeXY;
}
void XYWndManager::setOrigin(const Vector3& origin) {
// Cycle through the list of views and set the origin
for (XYWndMap::iterator i = _xyWnds.begin();
i != _xyWnds.end();
++i)
{
i->second->setOrigin(origin);
}
}
Vector3 XYWndManager::getActiveViewOrigin()
{
if (!_activeXY)
{
throw std::runtime_error("No active view found");
}
return _activeXY->getOrigin();
}
IOrthoView& XYWndManager::getActiveView()
{
if (!_activeXY)
{
throw std::runtime_error("No active view found");
}
return *_activeXY;
}
// Return the first view matching the given viewType
IOrthoView& XYWndManager::getViewByType(EViewType viewType)
{
for (auto& pair : _xyWnds)
{
if (pair.second->getViewType() == viewType)
{
return *pair.second;
}
}
throw std::runtime_error("No matching view found");
}
void XYWndManager::setScale(float scale) {
for (XYWndMap::iterator i = _xyWnds.begin();
i != _xyWnds.end();
++i)
{
i->second->setScale(scale);
}
}
void XYWndManager::positionAllViews(const Vector3& origin) {
for (XYWndMap::iterator i = _xyWnds.begin();
i != _xyWnds.end();
++i)
{
i->second->positionView(origin);
}
}
void XYWndManager::positionActiveView(const Vector3& origin) {
if (_activeXY != NULL) {
return _activeXY->positionView(origin);
}
}
EViewType XYWndManager::getActiveViewType() const {
if (_activeXY != NULL) {
return _activeXY->getViewType();
}
// Return at least anything
return XY;
}
void XYWndManager::setActiveViewType(EViewType viewType) {
if (_activeXY != NULL) {
return _activeXY->setViewType(viewType);
}
}
void XYWndManager::toggleActiveView(const cmd::ArgumentList& args) {
if (_activeXY != NULL) {
if (_activeXY->getViewType() == XY) {
_activeXY->setViewType(XZ);
}
else if (_activeXY->getViewType() == XZ) {
_activeXY->setViewType(YZ);
}
else {
_activeXY->setViewType(XY);
}
positionActiveView(getFocusPosition());
}
}
void XYWndManager::setActiveViewXY(const cmd::ArgumentList& args) {
setActiveViewType(XY);
positionActiveView(getFocusPosition());
}
void XYWndManager::setActiveViewXZ(const cmd::ArgumentList& args) {
setActiveViewType(XZ);
positionActiveView(getFocusPosition());
}
void XYWndManager::setActiveViewYZ(const cmd::ArgumentList& args) {
setActiveViewType(YZ);
positionActiveView(getFocusPosition());
}
void XYWndManager::splitViewFocus(const cmd::ArgumentList& args) {
positionAllViews(getFocusPosition());
}
void XYWndManager::zoom100(const cmd::ArgumentList& args) {
setScale(1);
}
void XYWndManager::focusActiveView(const cmd::ArgumentList& args) {
positionActiveView(getFocusPosition());
}
XYWndPtr XYWndManager::getView(EViewType viewType)
{
// Cycle through the list of views and get the one matching the type
for (XYWndMap::iterator i = _xyWnds.begin();
i != _xyWnds.end();
++i)
{
// If the view matches, return the pointer
if (i->second->getViewType() == viewType) {
return i->second;
}
}
return XYWndPtr();
}
// Change the active XYWnd
void XYWndManager::setActiveXY(int index) {
// Notify the currently active XYView that is has been deactivated
if (_activeXY != NULL)
{
_activeXY->setActive(false);
}
// Find the ID in the map and update the active pointer
XYWndMap::const_iterator it = _xyWnds.find(index);
if (it != _xyWnds.end())
{
_activeXY = it->second;
}
else
{
throw std::logic_error(
"Cannot set XYWnd with ID " + string::to_string(index) + " as active, "
+ " ID not found in map."
);
}
// Notify the new active XYView about its activation
if (_activeXY != NULL)
{
_activeXY->setActive(true);
}
}
void XYWndManager::destroyXYWnd(int id)
{
XYWndMap::iterator found = _xyWnds.find(id);
if (found != _xyWnds.end())
{
// Remove the shared_ptr from the map
_xyWnds.erase(found);
}
// Also check if the activeXY is holding a strong reference of the XYWnd
// which prevents destruction - release the shared_ptr
if (_activeXY != NULL && _activeXY->getId() == id)
{
_activeXY.reset();
// Set the activeXY to the next possible XYWnd
if (!_xyWnds.empty())
{
_activeXY = _xyWnds.begin()->second;
_activeXY->setActive(true);
}
}
}
int XYWndManager::getUniqueID() const
{
for (int i = 0; i < INT_MAX; ++i)
{
if (_xyWnds.count(i) == 0)
return i;
}
throw std::runtime_error(
"Cannot create unique ID for ortho view: no more IDs."
);
}
// Create a standard (non-floating) ortho view
XYWndPtr XYWndManager::createEmbeddedOrthoView()
{
// Allocate a new window and add it to the map
int id = getUniqueID();
XYWndPtr newWnd = XYWndPtr(new XYWnd(id, GlobalMainFrame().getWxTopLevelWindow()));
std::pair<XYWndMap::iterator, bool> result = _xyWnds.insert(
XYWndMap::value_type(id, newWnd));
// Ensure that the insertion is successful
assert(result.second == true);
// Tag the new view as active, if there is no active view yet
if (_activeXY == NULL)
{
_activeXY = newWnd;
}
return newWnd;
}
XYWndPtr XYWndManager::createEmbeddedOrthoView(EViewType viewType, wxWindow* parent)
{
// Allocate a new window and add it to the map
int id = getUniqueID();
XYWndPtr newWnd = XYWndPtr(new XYWnd(id, parent));
std::pair<XYWndMap::iterator, bool> result = _xyWnds.insert(
XYWndMap::value_type(id, newWnd));
// Ensure that the insertion is successful
assert(result.second == true);
// Tag the new view as active, if there is no active view yet
if (_activeXY == NULL)
{
_activeXY = newWnd;
}
newWnd->setViewType(viewType);
return newWnd;
}
/* greebo: This function determines the point currently being "looked" at, it is used for toggling the ortho views
* If something is selected the center of the selection is taken as new origin, otherwise the camera
* position is considered to be the new origin of the toggled orthoview.
*/
Vector3 XYWndManager::getFocusPosition()
{
Vector3 position(0,0,0);
if (GlobalSelectionSystem().countSelected() != 0)
{
position = GlobalSelectionSystem().getCurrentSelectionCenter();
}
else {
auto cam = GlobalCamera().getActiveCamWnd();
if (cam != NULL) {
position = cam->getCameraOrigin();
}
}
return position;
}
const std::string& XYWndManager::getName() const
{
static std::string _name(MODULE_ORTHOVIEWMANAGER);
return _name;
}
const StringSet& XYWndManager::getDependencies() const
{
static StringSet _dependencies
{
MODULE_XMLREGISTRY,
MODULE_EVENTMANAGER,
MODULE_RENDERSYSTEM,
MODULE_PREFERENCESYSTEM,
MODULE_COMMANDSYSTEM,
MODULE_MOUSETOOLMANAGER,
MODULE_STATUSBARMANAGER,
MODULE_USERINTERFACE,
MODULE_MAINFRAME,
};
return _dependencies;
}
void XYWndManager::observeKey(const std::string& key)
{
GlobalRegistry().signalForKey(key).connect(
sigc::mem_fun(this, &XYWndManager::refreshFromRegistry)
);
}
void XYWndManager::initialiseModule(const IApplicationContext& ctx)
{
// Connect self to the according registry keys
observeKey(RKEY_CHASE_MOUSE);
observeKey(RKEY_CHASE_MOUSE_CAP);
observeKey(RKEY_CAMERA_XY_UPDATE);
observeKey(RKEY_SHOW_CROSSHAIRS);
observeKey(RKEY_SHOW_GRID);
observeKey(RKEY_SHOW_SIZE_INFO);
observeKey(RKEY_SHOW_ENTITY_ANGLES);
observeKey(RKEY_SHOW_ENTITY_NAMES);
observeKey(RKEY_SHOW_BLOCKS);
observeKey(RKEY_SHOW_COORDINATES);
observeKey(RKEY_SHOW_OUTLINE);
observeKey(RKEY_SHOW_AXES);
observeKey(RKEY_SHOW_WORKZONE);
observeKey(RKEY_DEFAULT_BLOCKSIZE);
observeKey(RKEY_FONT_SIZE);
observeKey(RKEY_FONT_STYLE);
observeKey(RKEY_MAX_ZOOM_FACTOR);
observeKey(RKEY_CURSOR_CENTERED_ZOOM);
// Trigger loading the values of the observed registry keys
refreshFromRegistry();
// Construct the preference settings widgets
constructPreferences();
// Add the commands to the EventManager
registerCommands();
GlobalStatusBarManager().addTextElement(
"XYZPos",
"", // no icon
statusbar::StandardPosition::OrthoViewPosition,
_("Shows the mouse position in the orthoview")
);
XYWnd::captureStates();
// Add default XY tools
IMouseToolGroup& toolGroup = GlobalMouseToolManager().getGroup(IMouseToolGroup::Type::OrthoView);
toolGroup.registerMouseTool(std::make_shared<BrushCreatorTool>());
toolGroup.registerMouseTool(std::make_shared<ClipperTool>());
toolGroup.registerMouseTool(std::make_shared<ZoomTool>());
toolGroup.registerMouseTool(std::make_shared<CameraAngleTool>());
toolGroup.registerMouseTool(std::make_shared<CameraMoveTool>());
toolGroup.registerMouseTool(std::make_shared<MoveViewTool>());
toolGroup.registerMouseTool(std::make_shared<MeasurementTool>());
GlobalUserInterface().registerControl(std::make_shared<OrthoviewControl>());
}
void XYWndManager::shutdownModule()
{
GlobalUserInterface().unregisterControl(UserControl::OrthoView);
// Release all owned XYWndPtrs
destroyViews();
XYWnd::releaseStates();
}
MouseToolStack XYWndManager::getMouseToolsForEvent(wxMouseEvent& ev)
{
unsigned int state = wxutil::MouseButton::GetButtonStateChangeForMouseEvent(ev);
return GlobalMouseToolManager().getMouseToolsForEvent(IMouseToolGroup::Type::OrthoView, state);
}
void XYWndManager::foreachMouseTool(const std::function<void(const MouseToolPtr&)>& func)
{
GlobalMouseToolManager().getGroup(IMouseToolGroup::Type::OrthoView).foreachMouseTool(func);
}
void XYWndManager::runBenchmark(const cmd::ArgumentList& args)
{
auto cam = GlobalCamera().getActiveCamWnd();
cam->getCamera().setCameraOrigin({ 2517, -4511, 713 });
cam->getCamera().setCameraAngles({ -2.1, 123.91, 0 });
int numRuns = args.empty() ? 1 : args[0].getInt();
ScopedDebugTimer timer("Camera refresh, " + string::to_string(numRuns) + " runs");
for (int i = 0; i < numRuns; ++i)
{
cam->getCamera().forceRedraw();
}
}
// Define the static GlobalXYWnd module
module::StaticModuleRegistration<XYWndManager> xyWndModule;
} // namespace
// Accessor function returning the reference
ui::XYWndManager& GlobalXYWnd()
{
return *std::static_pointer_cast<ui::XYWndManager>(
module::GlobalModuleRegistry().getModule(MODULE_ORTHOVIEWMANAGER));
}