|
1 | 1 | #include "RadiantTest.h" |
2 | 2 |
|
3 | 3 | #include "ieclass.h" |
| 4 | +#include "ilayer.h" |
| 5 | +#include "iselection.h" |
4 | 6 | #include "scene/EntityNode.h" |
5 | 7 | #include "itransformable.h" |
6 | 8 | #include "icommandsystem.h" |
|
9 | 11 | #include "selection/SelectedPlaneSet.h" |
10 | 12 | #include "render/View.h" |
11 | 13 | #include "algorithm/View.h" |
| 14 | +#include "algorithm/Entity.h" |
| 15 | +#include "algorithm/Primitives.h" |
12 | 16 |
|
13 | 17 | namespace test |
14 | 18 | { |
@@ -151,4 +155,94 @@ TEST_F(TransformationTest, UniformLightDragResize) |
151 | 155 | EXPECT_EQ(entityNode->worldAABB().getExtents(), Vector3(320, 320, 320)); |
152 | 156 | } |
153 | 157 |
|
| 158 | +TEST_F(TransformationTest, CloneSelectedPlacesNodeInActiveLayer) |
| 159 | +{ |
| 160 | + auto& layerManager = GlobalMapModule().getRoot()->getLayerManager(); |
| 161 | + |
| 162 | + // Create a non-default layer and make it active |
| 163 | + auto testLayerId = layerManager.createLayer("TestLayer"); |
| 164 | + layerManager.setActiveLayer(testLayerId); |
| 165 | + |
| 166 | + // Create an entity on the default layer and select it |
| 167 | + auto entityNode = algorithm::createEntityByClassName("fixed_size_entity"); |
| 168 | + GlobalMapModule().getRoot()->addChildNode(entityNode); |
| 169 | + entityNode->moveToLayer(0); |
| 170 | + Node_setSelected(entityNode, true); |
| 171 | + |
| 172 | + EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 }); |
| 173 | + |
| 174 | + // Clone the selection |
| 175 | + GlobalCommandSystem().executeCommand("CloneSelection"); |
| 176 | + |
| 177 | + // The original should still be on layer 0 |
| 178 | + EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 }); |
| 179 | + |
| 180 | + // The clone should be on the active layer |
| 181 | + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1); |
| 182 | + GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node) |
| 183 | + { |
| 184 | + EXPECT_EQ(node->getLayers(), scene::LayerList{ testLayerId }) |
| 185 | + << "Cloned node should be placed in the active layer"; |
| 186 | + }); |
| 187 | +} |
| 188 | + |
| 189 | +TEST_F(TransformationTest, CloneSelectedDefaultLayerStaysOnDefault) |
| 190 | +{ |
| 191 | + auto& layerManager = GlobalMapModule().getRoot()->getLayerManager(); |
| 192 | + |
| 193 | + // Active layer is already the default |
| 194 | + EXPECT_EQ(layerManager.getActiveLayer(), 0); |
| 195 | + |
| 196 | + auto entityNode = algorithm::createEntityByClassName("fixed_size_entity"); |
| 197 | + GlobalMapModule().getRoot()->addChildNode(entityNode); |
| 198 | + Node_setSelected(entityNode, true); |
| 199 | + |
| 200 | + EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 }); |
| 201 | + |
| 202 | + GlobalCommandSystem().executeCommand("CloneSelection"); |
| 203 | + |
| 204 | + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1); |
| 205 | + GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node) |
| 206 | + { |
| 207 | + EXPECT_EQ(node->getLayers(), scene::LayerList{ 0 }) |
| 208 | + << "Cloned node should be on the default layer when it is active"; |
| 209 | + }); |
| 210 | +} |
| 211 | + |
| 212 | +TEST_F(TransformationTest, CloneSelectedMovesChildrenToActiveLayer) |
| 213 | +{ |
| 214 | + auto& layerManager = GlobalMapModule().getRoot()->getLayerManager(); |
| 215 | + |
| 216 | + auto testLayerId = layerManager.createLayer("TestLayer"); |
| 217 | + layerManager.setActiveLayer(testLayerId); |
| 218 | + |
| 219 | + // Create a func_static entity with a child brush on the default layer |
| 220 | + auto entityNode = algorithm::createEntityByClassName("func_static"); |
| 221 | + GlobalMapModule().getRoot()->addChildNode(entityNode); |
| 222 | + auto brushNode = algorithm::createCubicBrush(entityNode); |
| 223 | + entityNode->moveToLayer(0); |
| 224 | + brushNode->moveToLayer(0); |
| 225 | + Node_setSelected(entityNode, true); |
| 226 | + |
| 227 | + EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 }); |
| 228 | + EXPECT_EQ(brushNode->getLayers(), scene::LayerList{ 0 }); |
| 229 | + |
| 230 | + GlobalCommandSystem().executeCommand("CloneSelection"); |
| 231 | + |
| 232 | + // The cloned entity and its child brush should both be on the active layer |
| 233 | + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1); |
| 234 | + GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node) |
| 235 | + { |
| 236 | + EXPECT_EQ(node->getLayers(), scene::LayerList{ testLayerId }) |
| 237 | + << "Cloned entity should be on the active layer"; |
| 238 | + |
| 239 | + node->foreachNode([&](const scene::INodePtr& child) |
| 240 | + { |
| 241 | + EXPECT_EQ(child->getLayers(), scene::LayerList{ testLayerId }) |
| 242 | + << "Cloned child brush should be on the active layer"; |
| 243 | + return true; |
| 244 | + }); |
| 245 | + }); |
| 246 | +} |
| 247 | + |
154 | 248 | } |
0 commit comments