Skip to content

Commit

Permalink
#6145: Extract ComponentSelectionTester
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 1, 2022
1 parent d0ac322 commit 53bb36b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
14 changes: 8 additions & 6 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -112,14 +112,16 @@ ISceneSelectionTester::Ptr RadiantSelectionSystem::createSceneSelectionTester(Se
return std::make_shared<GroupChildPrimitiveSelectionTester>();
case SelectionMode::MergeAction:
return std::make_shared<MergeActionSelectionTester>();
case SelectionMode::Component:
return std::make_shared<ComponentSelectionTester>(*this);

default:
throw std::invalid_argument("Selection Mode not supported yet");
}
}

void RadiantSelectionSystem::testSelectScene(SelectablesList& targetList, SelectionTest& test,
const VolumeTest& view, SelectionMode mode, ComponentSelectionMode componentMode)
const VolumeTest& view, SelectionMode mode)
{
// The (temporary) storage pool
SelectionPool selector;
Expand Down Expand Up @@ -190,8 +192,8 @@ void RadiantSelectionSystem::testSelectScene(SelectablesList& targetList, Select

case SelectionMode::Component:
{
ComponentSelector selectionTester(selector, test, componentMode);
SelectionSystem::foreachSelected(selectionTester);
auto tester = createSceneSelectionTester(mode);
tester->testSelectScene(view, test, selector);

std::for_each(selector.begin(), selector.end(), [&](const auto& p) { targetList.push_back(p.second); });
}
Expand Down Expand Up @@ -638,7 +640,7 @@ void RadiantSelectionSystem::selectPoint(SelectionTest& test, EModifier modifier
}
}
else {
testSelectScene(candidates, test, test.getVolume(), getSelectionMode(), ComponentMode());
testSelectScene(candidates, test, test.getVolume(), getSelectionMode());
}

// Was the selection test successful (have we found anything to select)?
Expand Down Expand Up @@ -771,7 +773,7 @@ void RadiantSelectionSystem::selectArea(SelectionTest& test, SelectionSystem::EM
}
else
{
testSelectScene(candidates, test, test.getVolume(), getSelectionMode(), ComponentMode());
testSelectScene(candidates, test, test.getVolume(), getSelectionMode());
}

// Since toggling a selectable might trigger a group-selection
Expand Down Expand Up @@ -995,7 +997,7 @@ void RadiantSelectionSystem::initialiseModule(const IApplicationContext& ctx)
_pivot.initialise();

// Add manipulators
registerManipulator(std::make_shared<DragManipulator>(_pivot, *this));
registerManipulator(std::make_shared<DragManipulator>(_pivot, *this, *this));
registerManipulator(std::make_shared<ClipManipulator>());
registerManipulator(std::make_shared<TranslateManipulator>(_pivot, 2, 64.0f));
registerManipulator(std::make_shared<RotateManipulator>(_pivot, 8, 64.0f));
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/selection/RadiantSelectionSystem.h
Expand Up @@ -175,7 +175,7 @@ class RadiantSelectionSystem final :
private:
// Traverses the scene and adds any selectable nodes matching the given SelectionTest to the "targetList".
void testSelectScene(SelectablesList& targetList, SelectionTest& test,
const VolumeTest& view, SelectionMode mode, ComponentSelectionMode componentMode);
const VolumeTest& view, SelectionMode mode);

bool higherEntitySelectionPriority() const;

Expand Down
10 changes: 10 additions & 0 deletions radiantcore/selection/SceneSelectionTesters.cpp
Expand Up @@ -24,4 +24,14 @@ void MergeActionSelectionTester::testSelectScene(const VolumeTest& view, Selecti
GlobalSceneGraph().foreachVisibleNodeInVolume(view, tester);
}

ComponentSelectionTester::ComponentSelectionTester(SelectionSystem& selectionSystem) :
_selectionSystem(selectionSystem)
{}

void ComponentSelectionTester::testSelectScene(const VolumeTest& view, SelectionTest& test, Selector& selector)
{
ComponentSelector selectionTester(selector, test, _selectionSystem.ComponentMode());
_selectionSystem.foreachSelected(selectionTester);
}

}
15 changes: 15 additions & 0 deletions radiantcore/selection/SceneSelectionTesters.h
Expand Up @@ -35,4 +35,19 @@ class MergeActionSelectionTester :
void testSelectScene(const VolumeTest& view, SelectionTest& test, Selector& selector) override;
};

/**
* Tests components of selected scene elements
*/
class ComponentSelectionTester :
public ISceneSelectionTester
{
private:
SelectionSystem& _selectionSystem;

public:
ComponentSelectionTester(SelectionSystem& selectionSystem);

void testSelectScene(const VolumeTest& view, SelectionTest& test, Selector& selector) override;
};

}
13 changes: 7 additions & 6 deletions radiantcore/selection/manipulators/DragManipulator.cpp
Expand Up @@ -13,8 +13,9 @@ namespace selection

const std::string RKEY_TRANSIENT_COMPONENT_SELECTION = "user/ui/transientComponentSelection";

DragManipulator::DragManipulator(ManipulationPivot& pivot, ISceneSelectionTesterFactory& factory) :
DragManipulator::DragManipulator(ManipulationPivot& pivot, SelectionSystem& selectionSystem, ISceneSelectionTesterFactory& factory) :
_pivot(pivot),
_selectionSystem(selectionSystem),
_testerFactory(factory),
_freeResizeComponent(_resizeTranslatable),
_resizeModeActive(false),
Expand All @@ -37,11 +38,11 @@ void DragManipulator::testSelect(SelectionTest& test, const Matrix4& pivot2world
_resizeModeActive = false;

// No drag manipulation in merge mode
if (GlobalSelectionSystem().getSelectionMode() == SelectionMode::MergeAction) return;
if (_selectionSystem.getSelectionMode() == SelectionMode::MergeAction) return;

SelectionPool selector;

switch (GlobalSelectionSystem().getSelectionMode())
switch (_selectionSystem.getSelectionMode())
{
case SelectionMode::Primitive:
testSelectPrimitiveMode(test.getVolume(), test, selector);
Expand Down Expand Up @@ -143,8 +144,8 @@ void DragManipulator::testSelectComponentMode(const VolumeTest& view, SelectionT
{
BestSelector bestSelector;

ComponentSelector selectionTester(bestSelector, test, GlobalSelectionSystem().ComponentMode());
GlobalSelectionSystem().foreachSelected(selectionTester);
auto tester = _testerFactory.createSceneSelectionTester(SelectionMode::Component);
tester->testSelectScene(view, test, bestSelector);

bool transientComponentSelection = registry::getValue<bool>(RKEY_TRANSIENT_COMPONENT_SELECTION);

Expand All @@ -154,7 +155,7 @@ void DragManipulator::testSelectComponentMode(const VolumeTest& view, SelectionT
// component will deselect all previously selected components beforehand
if (transientComponentSelection && !selectable->isSelected())
{
GlobalSelectionSystem().setSelectedAllComponents(false);
_selectionSystem.setSelectedAllComponents(false);
}

selector.addSelectable(SelectionIntersection(0, 0), selectable);
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/selection/manipulators/DragManipulator.h
Expand Up @@ -34,6 +34,7 @@ class DragManipulator :
{
private:
ManipulationPivot& _pivot;
SelectionSystem& _selectionSystem;
ISceneSelectionTesterFactory& _testerFactory;

// Resize component
Expand All @@ -49,7 +50,7 @@ class DragManipulator :
BasicSelectable _dragSelectable;

public:
DragManipulator(ManipulationPivot& pivot, ISceneSelectionTesterFactory& factory);
DragManipulator(ManipulationPivot& pivot, SelectionSystem& selectionSystem, ISceneSelectionTesterFactory& factory);

Type getType() const override;
Component* getActiveComponent() override;
Expand Down

0 comments on commit 53bb36b

Please sign in to comment.