/
Selection.cpp
736 lines (552 loc) · 29.4 KB
/
Selection.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
#include "RadiantTest.h"
#include "ishaders.h"
#include "imap.h"
#include "ifilter.h"
#include "ilightnode.h"
#include "ibrush.h"
#include "ipatch.h"
#include "ientity.h"
#include "ieclass.h"
#include "algorithm/Scene.h"
#include "algorithm/Primitives.h"
#include "scenelib.h"
#include "selectionlib.h"
#include "string/convert.h"
#include "render/View.h"
#include "render/CameraView.h"
#include "selection/SelectionVolume.h"
#include "Rectangle.h"
#include "algorithm/View.h"
#include "algorithm/XmlUtils.h"
namespace test
{
using SelectionTest = RadiantTest;
TEST_F(SelectionTest, DefaultSelectionMode)
{
EXPECT_EQ(GlobalSelectionSystem().Mode(), selection::SelectionSystem::ePrimitive);
}
TEST_F(SelectionTest, ApplyShadersToForcedVisibleObjects)
{
loadMap("primitives_with_clip_material.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/common/clip");
auto patch = algorithm::findFirstPatchWithMaterial(worldspawn, "textures/common/clip");
// Filter out the objects using the clip material
GlobalFilterSystem().setFilterState("Clip Textures", true);
// Glitch: Since this brush is completely filtered out, this won't be called by the filter system
Node_getIBrush(brush)->updateFaceVisibility();
EXPECT_FALSE(brush->visible());
EXPECT_FALSE(patch->visible());
Node_setSelected(brush, true);
Node_setSelected(patch, true);
EXPECT_TRUE(brush->visible());
EXPECT_TRUE(patch->visible());
// Apply the caulk material to the selection
selection::applyShaderToSelection("textures/common/caulk");
auto brushNode = std::dynamic_pointer_cast<IBrushNode>(brush);
auto patchNode = std::dynamic_pointer_cast<IPatchNode>(patch);
EXPECT_TRUE(brushNode->getIBrush().hasShader("textures/common/caulk"));
EXPECT_EQ(patchNode->getPatch().getShader(), ("textures/common/caulk"));
}
// #5443: Size display of lights doesn't change when modifying "light_radius"
TEST_F(SelectionTest, LightBoundsChangedAfterRadiusChange)
{
auto eclass = GlobalEntityClassManager().findOrInsert("light", false);
auto entityNode = GlobalEntityModule().createEntity(eclass);
EXPECT_TRUE(Node_getLightNode(entityNode));
auto* entity = Node_getEntity(entityNode);
entity->setKeyValue("light_radius", "300 200 100");
GlobalMapModule().getRoot()->addChildNode(entityNode);
Node_setSelected(entityNode, true);
auto defaultBounds = string::convert<Vector3>(entity->getKeyValue("light_radius"));
EXPECT_TRUE(math::isNear(GlobalSelectionSystem().getWorkZone().bounds.getExtents(), defaultBounds, 0.01));
// Modify just the light_radius spawnarg
entity->setKeyValue("light_radius", "30 20 10");
// The work zone should have adapted itself to the new bounds
// assuming that the LightNode recalculates its AABB
auto changedBounds = string::convert<Vector3>(entity->getKeyValue("light_radius"));
EXPECT_TRUE(math::isNear(GlobalSelectionSystem().getWorkZone().bounds.getExtents(), changedBounds, 0.01));
}
// #5484: Projected lights don't rotate around their origin anymore
TEST_F(SelectionTest, SelectionBoundsOfProjectedLights)
{
auto eclass = GlobalEntityClassManager().findOrInsert("light", false);
auto entityNode = GlobalEntityModule().createEntity(eclass);
EXPECT_TRUE(Node_getLightNode(entityNode));
auto* entity = Node_getEntity(entityNode);
entity->setKeyValue("origin", "0 0 0");
entity->setKeyValue("light_target", "0 0 -256");
entity->setKeyValue("light_right", "128 0 0");
entity->setKeyValue("light_up", "0 128 0");
entity->setKeyValue("light_start", "");
entity->setKeyValue("light_end", "");
GlobalMapModule().getRoot()->addChildNode(entityNode);
Node_setSelected(entityNode, true);
// The center of the selection AABB needs to be at its origin
EXPECT_EQ(Node_getLightNode(entityNode)->getSelectAABB().getOrigin(), Vector3(0,0,0));
}
// #4846: Rotation widget does not re-center on selected object
TEST_F(SelectionTest, PivotIsResetAfterCancelingOperation)
{
loadMap("selection_test.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/1");
GlobalSelectionSystem().setActiveManipulator(selection::IManipulator::Translate);
// Select the node, the pivot should now be at the node center
Node_setSelected(brush, true);
Vector3 originalBrushPosition = brush->worldAABB().getOrigin();
Matrix4 originalPivot = GlobalSelectionSystem().getPivot2World();
EXPECT_EQ(originalPivot.translation(), originalBrushPosition);
const auto& activeManipulator = GlobalSelectionSystem().getActiveManipulator();
// Construct an orthoview to test-select the manipulator
render::View view(false);
algorithm::constructCenteredOrthoview(view, originalBrushPosition);
SelectionVolume test = algorithm::constructOrthoviewSelectionTest(view);
activeManipulator->testSelect(test, originalPivot);
EXPECT_TRUE(activeManipulator->isSelected());
GlobalSelectionSystem().onManipulationStart();
activeManipulator->getActiveComponent()->beginTransformation(originalPivot, view, Vector2(0, 0));
// Transform by dragging stuff around
activeManipulator->getActiveComponent()->transform(originalPivot, view, Vector2(0.5, 0.5), false);
GlobalSelectionSystem().onManipulationChanged();
// The brush should have been moved
EXPECT_NE(brush->worldAABB().getOrigin(), originalBrushPosition);
// Pivot should have been moved
EXPECT_NE(GlobalSelectionSystem().getPivot2World().translation(), originalBrushPosition);
// Now cancel the operation
GlobalSelectionSystem().onManipulationCancelled();
// Brush should be back at its original position
EXPECT_EQ(brush->worldAABB().getOrigin(), originalBrushPosition);
// And as of #4846 the pivot should be back as well
EXPECT_EQ(GlobalSelectionSystem().getPivot2World().translation(), originalBrushPosition);
}
// #5460: Workzone not recalculated after selection change if XY view "Show Size Info" setting is off
TEST_F(SelectionTest, WorkzoneIsRecalculatedAfterSelectionChange)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
AABB tallBounds(Vector3(0, 0, 0), Vector3(64, 256, 128));
AABB smallBounds(Vector3(300, 300, 300), Vector3(64, 32, 64));
auto tallBrush = algorithm::createCuboidBrush(worldspawn, tallBounds);
auto smallBrush = algorithm::createCuboidBrush(worldspawn, smallBounds);
EXPECT_EQ(tallBrush->worldAABB().getOrigin(), tallBounds.getOrigin());
EXPECT_EQ(tallBrush->worldAABB().getExtents(), tallBounds.getExtents());
EXPECT_EQ(smallBrush->worldAABB().getOrigin(), smallBounds.getOrigin());
EXPECT_EQ(smallBrush->worldAABB().getExtents(), smallBounds.getExtents());
GlobalSelectionSystem().setSelectedAll(false);
render::View orthoView(false);
// Construct an orthoview to test-select the tall brush
algorithm::constructCenteredOrthoview(orthoView, tallBrush->worldAABB().getOrigin());
auto tallBrushTest = algorithm::constructOrthoviewSelectionTest(orthoView);
// Select and de-select first brush
GlobalSelectionSystem().selectPoint(tallBrushTest, selection::SelectionSystem::eToggle, false);
EXPECT_TRUE(Node_isSelected(tallBrush));
// Workzone should match the size of the tall brush
EXPECT_EQ(GlobalSelectionSystem().getWorkZone().bounds, tallBounds);
// De-select the tall brush
GlobalSelectionSystem().selectPoint(tallBrushTest, selection::SelectionSystem::eToggle, false);
EXPECT_FALSE(Node_isSelected(tallBrush));
// Workzone should still match the size of the tall brush
EXPECT_EQ(GlobalSelectionSystem().getWorkZone().bounds, tallBounds);
// Construct an orthoview to test-select the smaller brush
algorithm::constructCenteredOrthoview(orthoView, smallBrush->worldAABB().getOrigin());
auto smallBrushTest = algorithm::constructOrthoviewSelectionTest(orthoView);
// Select and de-select second brush (no getWorkZone() call in between)
GlobalSelectionSystem().selectPoint(smallBrushTest, selection::SelectionSystem::eToggle, false);
EXPECT_TRUE(Node_isSelected(smallBrush));
GlobalSelectionSystem().selectPoint(smallBrushTest, selection::SelectionSystem::eToggle, false);
EXPECT_FALSE(Node_isSelected(smallBrush));
// Workzone should match the size of the small brush now
EXPECT_EQ(GlobalSelectionSystem().getWorkZone().bounds, smallBounds);
}
class ViewSelectionTest :
public SelectionTest
{
protected:
virtual render::View createView() = 0;
virtual void constructView(render::View& view, const AABB& objectAABB) = 0;
void performViewSelectionTest(render::View& view, const scene::INodePtr& node, bool expectNodeIsSelectable)
{
// Selection Point
auto rectangle = selection::Rectangle::ConstructFromPoint(Vector2(0, 0), Vector2(8.0 / algorithm::DeviceWidth, 8.0 / algorithm::DeviceHeight));
ConstructSelectionTest(view, rectangle);
EXPECT_FALSE(Node_isSelected(node));
SelectionVolume test(view);
GlobalSelectionSystem().selectPoint(test, selection::SelectionSystem::eToggle, false);
EXPECT_EQ(Node_isSelected(node), expectNodeIsSelectable);
// De-select to be sure
Node_setSelected(node, false);
}
void performSelectionTest(const scene::INodePtr& node, bool expectNodeIsSelectable)
{
// Move the orthoview exactly to the center of this object
render::View view = createView();
constructView(view, node->worldAABB());
performViewSelectionTest(view, node, expectNodeIsSelectable);
}
void performBrushSelectionTest(const std::string& materialName, bool expectNodeIsSelectable)
{
// Filter caulk faces
auto material = GlobalMaterialManager().getMaterial("textures/common/caulk");
material->setVisible(false);
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::findFirstBrushWithMaterial(worldspawn, materialName);
EXPECT_TRUE(brush);
Node_getIBrush(brush)->updateFaceVisibility();
performSelectionTest(brush, expectNodeIsSelectable);
}
void performPatchSelectionTest(const std::string& materialName, bool expectNodeIsSelectable)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto patch = algorithm::findFirstPatchWithMaterial(worldspawn, materialName);
EXPECT_TRUE(patch);
performSelectionTest(patch, expectNodeIsSelectable);
}
void performModelSelectionTest(const std::string& entityName, bool expectNodeIsSelectable)
{
auto entity = algorithm::getEntityByName(GlobalMapModule().getRoot(), entityName);
EXPECT_TRUE(entity);
performSelectionTest(entity, expectNodeIsSelectable);
}
};
class OrthoViewSelectionTest :
public ViewSelectionTest
{
protected:
virtual render::View createView() override
{
return render::View();
}
virtual void constructView(render::View& view, const AABB& objectAABB) override
{
algorithm::constructCenteredOrthoview(view, objectAABB.getOrigin());
}
};
class CameraViewSelectionTest :
public ViewSelectionTest
{
protected:
virtual render::View createView() override
{
return render::View(true);
}
virtual void constructView(render::View& view, const AABB& objectAABB) override
{
algorithm::constructCameraView(view, objectAABB, Vector3(0, 0, -1), Vector3(-90, 0, 0));
}
};
// --------- Brush with one-sided material -----
TEST_F(OrthoViewSelectionTest, OnesidedBrushFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/numbers/1", true);
}
TEST_F(CameraViewSelectionTest, OnesidedBrushFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/numbers/1", true);
}
// #5444: Brushes faces facing away were unselectable in orthoview
TEST_F(OrthoViewSelectionTest, OnesidedBrushFacingAwayFromViewIsSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/numbers/2", true); // selectable in ortho
}
TEST_F(CameraViewSelectionTest, OnesidedBrushFacingAwayFromViewIsNotSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/numbers/2", false); // not selectable in camera
}
// --------- Brush face with two-sided material -----
TEST_F(OrthoViewSelectionTest, TwosidedBrushFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces", true);
}
TEST_F(CameraViewSelectionTest, TwosidedBrushFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces", true);
}
TEST_F(OrthoViewSelectionTest, TwosidedBrushFacingAwayFromViewIsSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces2", true); // selectable in ortho
}
TEST_F(CameraViewSelectionTest, TwosidedBrushFacingAwayFromViewIsNotSelectable)
{
loadMap("selection_test.map");
performBrushSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces2", false); // not selectable in camera, face is not visible
}
// --------- Patch with one-sided material -----
TEST_F(OrthoViewSelectionTest, OnesidedPatchFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/numbers/1", true);
}
TEST_F(CameraViewSelectionTest, OnesidedPatchFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/numbers/1", true);
}
TEST_F(OrthoViewSelectionTest, OnesidedPatchFacingAwayFromViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/numbers/2", true);
}
TEST_F(CameraViewSelectionTest, OnesidedPatchFacingAwayFromViewIsNotSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/numbers/2", false);
}
// --------- Patch with two-sided material -----
TEST_F(OrthoViewSelectionTest, TwosidedPatchFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces2", true);
}
TEST_F(CameraViewSelectionTest, TwosidedPatchFacingTowardsViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces2", true);
}
TEST_F(OrthoViewSelectionTest, TwosidedPatchFacingAwayFromViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces2", true); // selectable in ortho
}
TEST_F(CameraViewSelectionTest, TwosidedPatchFacingAwayFromViewIsSelectable)
{
loadMap("selection_test.map");
performPatchSelectionTest("textures/darkmod/decals/vegetation/ivy_mixed_pieces2", true); // selectable in camera
}
// --------- Model with one-sided material -----
TEST_F(OrthoViewSelectionTest, OnesidedModelFacingAwayIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("onesided_ivy_facing_down", true);
}
TEST_F(CameraViewSelectionTest, OnesidedModelFacingAwayIsNotSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("onesided_ivy_facing_down", false);
}
TEST_F(OrthoViewSelectionTest, OnesidedModelFacingUpIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("onesided_ivy_facing_up", true);
}
TEST_F(CameraViewSelectionTest, OnesidedModelFacingUpIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("onesided_ivy_facing_up", true);
}
// --------- Model with two-sided material -----
TEST_F(OrthoViewSelectionTest, TwosidedModelFacingAwayIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("twosided_ivy_facing_down", true);
}
TEST_F(CameraViewSelectionTest, TwosidedModelFacingAwayIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("twosided_ivy_facing_down", true);
}
TEST_F(OrthoViewSelectionTest, TwosidedModelFacingUpIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("twosided_ivy_facing_up", true);
}
TEST_F(CameraViewSelectionTest, TwosidedModelFacingUpIsSelectable)
{
loadMap("twosided_ivy.mapx");
performModelSelectionTest("twosided_ivy_facing_up", true);
}
void performPointSelectionOnNodePosition(const scene::INodePtr& node, selection::SelectionSystem::EModifier modifier)
{
auto nodePosition = node->worldAABB().getOrigin();
// Construct an orthoview centered at the node's location
render::View view(false);
algorithm::constructCenteredOrthoview(view, nodePosition);
auto test = algorithm::constructOrthoviewSelectionTest(view);
GlobalSelectionSystem().selectPoint(test, modifier, false);
}
// Ortho: Toggle worldspawn brush selection in primitive mode
TEST_F(OrthoViewSelectionTest, ToggleSelectPointPrimitiveMode)
{
loadMap("selection_test2.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/2");
auto unrelatedBrush = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/1");
EXPECT_FALSE(Node_isSelected(brush)) << "Brush should be unselected at first";
EXPECT_FALSE(Node_isSelected(unrelatedBrush)) << "Unrelated brush should be unselected at first";
performPointSelectionOnNodePosition(brush, selection::SelectionSystem::eToggle);
EXPECT_TRUE(Node_isSelected(brush)) << "Brush should be selected now";
EXPECT_FALSE(Node_isSelected(unrelatedBrush)) << "Unrelated brush should still be unselected";
performPointSelectionOnNodePosition(brush, selection::SelectionSystem::eToggle);
EXPECT_FALSE(Node_isSelected(brush)) << "Brush should be unselected again";
}
// Ortho: Toggle selection in primitive mode favours entities over brushes
TEST_F(OrthoViewSelectionTest, ToggleSelectPointPrimitiveModeFavoursEntities)
{
loadMap("selection_test2.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto funcStatic = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_1");
auto brush = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/1");
// Assume that the entity is located below the brush
Vector3 funcStaticOrigin = funcStatic->worldAABB().getOrigin();
Vector3 originalBrushPosition = brush->worldAABB().getOrigin();
EXPECT_LT(funcStaticOrigin.z() + funcStatic->worldAABB().extents.z(),
originalBrushPosition.z() + brush->worldAABB().extents.z()) << "Entity should be located below the brush";
EXPECT_FALSE(Node_isSelected(brush)) << "Brush should be unselected at first";
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected at first";
performPointSelectionOnNodePosition(brush, selection::SelectionSystem::eToggle);
EXPECT_TRUE(Node_isSelected(funcStatic)) << "func_static_1 should be selected now";
EXPECT_FALSE(Node_isSelected(brush)) << "Brush should still be unselected";
performPointSelectionOnNodePosition(brush, selection::SelectionSystem::eToggle);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected again";
EXPECT_FALSE(Node_isSelected(brush)) << "Brush should still be unselected";
}
// Ortho: Replace selection in primitive mode, check that current selection is replaced
TEST_F(OrthoViewSelectionTest, ReplaceSelectPointPrimitiveMode)
{
loadMap("selection_test2.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto funcStatic = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_1");
auto brush1 = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/1");
auto brush2 = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/2");
EXPECT_FALSE(Node_isSelected(brush2)) << "Brush 2 should be unselected at first";
// Select the func_static_1
Node_setSelected(brush1, true);
Node_setSelected(funcStatic, true);
// Run selection in replace mode, this should unselect the previous items
performPointSelectionOnNodePosition(brush2, selection::SelectionSystem::eReplace);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected now";
EXPECT_FALSE(Node_isSelected(brush1)) << "Brush 1 should be unselected now";
EXPECT_TRUE(Node_isSelected(brush2)) << "Brush 2 should be selected now";
}
// Ortho: Cycle selection in primitive mode (brush 1 on top of brush 3 on top of a func_static)
TEST_F(OrthoViewSelectionTest, CycleSelectPointPrimitiveMode)
{
loadMap("selection_test2.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto funcStatic = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_1");
auto brush1 = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/1");
auto brush3 = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/3");
EXPECT_FALSE(Node_isSelected(brush1)) << "Brush 1 should be unselected at first";
EXPECT_FALSE(Node_isSelected(brush3)) << "Brush 3 should be unselected at first";
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected at first";
// First selection in replace mode should select the func_static, since entities are favoured
performPointSelectionOnNodePosition(brush1, selection::SelectionSystem::eReplace);
EXPECT_TRUE(Node_isSelected(funcStatic)) << "func_static_1 should be selected now";
EXPECT_FALSE(Node_isSelected(brush1)) << "Brush 1 should still be unselected";
EXPECT_FALSE(Node_isSelected(brush3)) << "Brush 3 should still be unselected";
// Second cycle should have the topmost brush selected
performPointSelectionOnNodePosition(brush1, selection::SelectionSystem::eCycle);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected again";
EXPECT_TRUE(Node_isSelected(brush1)) << "Brush 1 should be selected now";
EXPECT_FALSE(Node_isSelected(brush3)) << "Brush 3 should still be unselected";
// Third cycle should select the brush in between the func_static and brush 1
performPointSelectionOnNodePosition(brush1, selection::SelectionSystem::eCycle);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should still be unselected";
EXPECT_FALSE(Node_isSelected(brush1)) << "Brush 1 should be unselected";
EXPECT_TRUE(Node_isSelected(brush3)) << "Brush 3 should be selected now";
// Fourth cycle should select func_static_1 again
performPointSelectionOnNodePosition(brush1, selection::SelectionSystem::eCycle);
EXPECT_TRUE(Node_isSelected(funcStatic)) << "func_static_1 should be selected again";
EXPECT_FALSE(Node_isSelected(brush1)) << "Brush 1 should be unselected again";
EXPECT_FALSE(Node_isSelected(brush3)) << "Brush 3 should be unselected again";
}
// Cycle select is not changing the selection if there's only one selectable in the pool
TEST_F(OrthoViewSelectionTest, CycleSelectPointOnlyOneCandidate)
{
loadMap("selection_test2.map");
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush2 = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/2");
EXPECT_FALSE(Node_isSelected(brush2)) << "Brush 2 should be unselected at first";
// First selection in replace mode should select brush 2
performPointSelectionOnNodePosition(brush2, selection::SelectionSystem::eReplace);
EXPECT_TRUE(Node_isSelected(brush2)) << "brush 2 should be selected now";
// Second cycle should have the topmost brush selected
performPointSelectionOnNodePosition(brush2, selection::SelectionSystem::eCycle);
EXPECT_TRUE(Node_isSelected(brush2)) << "brush 2 should remain selected";
performPointSelectionOnNodePosition(brush2, selection::SelectionSystem::eCycle);
EXPECT_TRUE(Node_isSelected(brush2)) << "brush 2 should remain selected";
}
// Ortho: Toggle point selection in entity mode
TEST_F(OrthoViewSelectionTest, ToggleSelectPointEntityMode)
{
loadMap("selection_test2.map");
GlobalSelectionSystem().SetMode(selection::SelectionSystem::eEntity);
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto funcStatic = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_above_torches");
auto torch1 = algorithm::getEntityByName(GlobalMapModule().getRoot(), "torch1");
// These two are positioned right above the torches and the func_static, but are worldspawn primitives
auto brush4 = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/4");
auto patch4 = algorithm::findFirstPatchWithMaterial(worldspawn, "textures/numbers/4");
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static should be unselected at first";
EXPECT_FALSE(Node_isSelected(torch1)) << "torch1 should be unselected at first";
EXPECT_FALSE(Node_isSelected(brush4)) << "brush4 should be unselected at first";
EXPECT_FALSE(Node_isSelected(patch4)) << "patch4 should be unselected at first";
// Since the func_static is located above the torch, it should get selected first
// The worldspawn primitives should be ignored
performPointSelectionOnNodePosition(torch1, selection::SelectionSystem::eToggle);
EXPECT_TRUE(Node_isSelected(funcStatic)) << "func_static should be selected now";
EXPECT_FALSE(Node_isSelected(torch1)) << "torch1 should still be unselected";
EXPECT_FALSE(Node_isSelected(brush4)) << "brush4 should still be unselected";
EXPECT_FALSE(Node_isSelected(patch4)) << "patch4 should still be unselected";
performPointSelectionOnNodePosition(torch1, selection::SelectionSystem::eToggle);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static should be unselected again";
EXPECT_FALSE(Node_isSelected(torch1)) << "torch1 should still be unselected";
EXPECT_FALSE(Node_isSelected(brush4)) << "brush4 should still be unselected";
EXPECT_FALSE(Node_isSelected(patch4)) << "patch4 should still be unselected";
}
// Ortho: Cycle point selection in entity mode
TEST_F(OrthoViewSelectionTest, CycleSelectPointEntityMode)
{
loadMap("selection_test2.map");
GlobalSelectionSystem().SetMode(selection::SelectionSystem::eEntity);
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto funcStatic = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_above_torches");
auto torch1 = algorithm::getEntityByName(GlobalMapModule().getRoot(), "torch1");
auto torch2 = algorithm::getEntityByName(GlobalMapModule().getRoot(), "torch2");
EXPECT_FALSE(Node_isSelected(torch1)) << "Torch 1 should be unselected at first";
EXPECT_FALSE(Node_isSelected(torch2)) << "Torch 2 should be unselected at first";
EXPECT_FALSE(Node_isSelected(funcStatic)) << "funcStatic should be unselected at first";
// First selection in replace mode should select the func_static, since entities are favoured
performPointSelectionOnNodePosition(torch1, selection::SelectionSystem::eReplace);
EXPECT_TRUE(Node_isSelected(funcStatic)) << "func_static_1 should be selected now";
EXPECT_FALSE(Node_isSelected(torch1)) << "Torch 1 should still be unselected";
EXPECT_FALSE(Node_isSelected(torch2)) << "Torch 2 should still be unselected";
// Second cycle should have the topmost torch selected
performPointSelectionOnNodePosition(torch1, selection::SelectionSystem::eCycle);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected again";
EXPECT_TRUE(Node_isSelected(torch1)) << "Torch 1 should be selected now";
EXPECT_FALSE(Node_isSelected(torch2)) << "Torch 2 should still be unselected";
// Third cycle should have the second torch selected
performPointSelectionOnNodePosition(torch1, selection::SelectionSystem::eCycle);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should still be unselected";
EXPECT_FALSE(Node_isSelected(torch1)) << "Torch 1 should be unselected again";
EXPECT_TRUE(Node_isSelected(torch2)) << "Torch 2 should be selected now";
// Fourth cycle should select func_static again
performPointSelectionOnNodePosition(torch1, selection::SelectionSystem::eCycle);
EXPECT_TRUE(Node_isSelected(funcStatic)) << "func_static_1 should be selected again";
EXPECT_FALSE(Node_isSelected(torch1)) << "Torch 1 should be unselected";
EXPECT_FALSE(Node_isSelected(torch2)) << "Torch 2 should be unselected";
}
// Ortho: Replace selection in entity mode, check that current selection is replaced
TEST_F(OrthoViewSelectionTest, ReplaceSelectPointEntityMode)
{
loadMap("selection_test2.map");
GlobalSelectionSystem().SetMode(selection::SelectionSystem::eEntity);
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto funcStatic = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_1");
auto funcStaticAboveTorches = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_above_torches");
EXPECT_FALSE(Node_isSelected(funcStaticAboveTorches)) << "funcStaticAboveTorches should be unselected at first";
// Select the func_static_1
Node_setSelected(funcStatic, true);
// Run selection in replace mode, this should unselect the previous items
performPointSelectionOnNodePosition(funcStaticAboveTorches, selection::SelectionSystem::eReplace);
EXPECT_FALSE(Node_isSelected(funcStatic)) << "func_static_1 should be unselected now";
EXPECT_TRUE(Node_isSelected(funcStaticAboveTorches)) << "funcStaticAboveTorches should be selected now";
}
}