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
|
#include "SceneSelectionTesters.h"
#include "iscenegraph.h"
#include "SelectionTestWalkers.h"
#include "selection/EntitiesFirstSelector.h"
#include "selection/SelectionPool.h"
namespace selection
{
SelectionTesterBase::SelectionTesterBase(const NodePredicate& nodePredicate) :
_nodePredicate(nodePredicate)
{}
bool SelectionTesterBase::nodeIsEligible(const scene::INodePtr& node) const
{
return _nodePredicate ? _nodePredicate(node) : true;
}
void SelectionTesterBase::testNode(const scene::INodePtr& node, SelectionTestWalker& tester)
{
if (nodeIsEligible(node))
{
tester.testNode(node);
}
}
bool SelectionTesterBase::hasSelectables() const
{
return !_selectables.empty();
}
void SelectionTesterBase::foreachSelectable(const std::function<void(ISelectable*)>& functor)
{
for (auto selectable : _selectables)
{
functor(selectable);
}
}
void SelectionTesterBase::testSelectScene(const VolumeTest& view, SelectionTest& test)
{
// Forward to the specialised overload using an empty predicate
testSelectSceneWithFilter(view, test, [](ISelectable*) { return true; });
}
void SelectionTesterBase::storeSelectable(ISelectable* selectable)
{
_selectables.push_back(selectable);
}
void SelectionTesterBase::storeSelectablesInPool(Selector& selector,
const std::function<bool(ISelectable*)>& predicate)
{
selector.foreachSelectable([&](auto selectable)
{
if (predicate(selectable))
{
storeSelectable(selectable);
}
});
}
PrimitiveSelectionTester::PrimitiveSelectionTester(const NodePredicate& nodePredicate) :
SelectionTesterBase(nodePredicate)
{}
void PrimitiveSelectionTester::testSelectSceneWithFilter(const VolumeTest& view, SelectionTest& test,
const std::function<bool(ISelectable*)>& predicate)
{
SelectionPool simplePool;
EntitiesFirstSelector sortedPool;
// Sort entities before primitives if required, by referencing the correct selector
auto& targetPool = !view.fill() && higherEntitySelectionPriority() ?
static_cast<Selector&>(sortedPool) : simplePool;
AnySelector anyTester(targetPool, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, [&](const scene::INodePtr& node)
{
testNode(node, anyTester);
return true;
});
storeSelectablesInPool(targetPool, predicate);
}
bool PrimitiveSelectionTester::higherEntitySelectionPriority() const
{
return registry::getValue<bool>(RKEY_HIGHER_ENTITY_PRIORITY);
}
EntitySelectionTester::EntitySelectionTester(const NodePredicate& nodePredicate) :
SelectionTesterBase(nodePredicate)
{}
void EntitySelectionTester::testSelectSceneWithFilter(const VolumeTest& view, SelectionTest& test,
const std::function<bool(ISelectable*)>& predicate)
{
SelectionPool selector;
EntitySelector tester(selector, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, [&](const scene::INodePtr& node)
{
testNode(node, tester);
return true;
});
storeSelectablesInPool(selector, predicate);
}
GroupChildPrimitiveSelectionTester::GroupChildPrimitiveSelectionTester(const NodePredicate& nodePredicate) :
SelectionTesterBase(nodePredicate)
{}
void GroupChildPrimitiveSelectionTester::testSelectSceneWithFilter(const VolumeTest& view, SelectionTest& test,
const std::function<bool(ISelectable*)>& predicate)
{
SelectionPool selector;
GroupChildPrimitiveSelector tester(selector, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, [&](const scene::INodePtr& node)
{
testNode(node, tester);
return true;
});
storeSelectablesInPool(selector, predicate);
}
MergeActionSelectionTester::MergeActionSelectionTester(const NodePredicate& nodePredicate) :
SelectionTesterBase(nodePredicate)
{}
void MergeActionSelectionTester::testSelectSceneWithFilter(const VolumeTest& view, SelectionTest& test,
const std::function<bool(ISelectable*)>& predicate)
{
SelectionPool selector;
MergeActionSelector tester(selector, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, [&](const scene::INodePtr& node)
{
testNode(node, tester);
return true;
});
storeSelectablesInPool(selector, predicate);
}
ComponentSelectionTester::ComponentSelectionTester(SelectionSystem& selectionSystem, const NodePredicate& nodePredicate) :
SelectionTesterBase(nodePredicate),
_selectionSystem(selectionSystem)
{}
void ComponentSelectionTester::testSelectSceneWithFilter(const VolumeTest& view, SelectionTest& test,
const std::function<bool(ISelectable*)>& predicate)
{
SelectionPool selector;
ComponentSelector tester(selector, test, _selectionSystem.ComponentMode());
_selectionSystem.foreachSelected([&](const scene::INodePtr& node)
{
testNode(node, tester);
});
storeSelectablesInPool(selector, predicate);
}
}
|