Skip to content

Commit

Permalink
#5128: Add ComponentSelectionModeToggleRequest to make it interceptab…
Browse files Browse the repository at this point in the history
…le by client code.

Move SelectionSystem interface to selection namespace. Move ComponentSelectionMode enumeration to selection namespace and refactor the references.
  • Loading branch information
codereader committed Sep 24, 2021
1 parent e817477 commit b1d91be
Show file tree
Hide file tree
Showing 56 changed files with 305 additions and 222 deletions.
1 change: 1 addition & 0 deletions include/imessagebus.h
Expand Up @@ -52,6 +52,7 @@ class IMessage
FileOverwriteConfirmation,
UnselectSelectionRequest,
ManipulatorModeToggleRequest,
ComponentSelectionModeToggleRequest,

UserDefinedMessagesGoHigherThanThis = 999,
};
Expand Down
54 changes: 32 additions & 22 deletions include/iselection.h
Expand Up @@ -36,7 +36,23 @@ class IFace;
class Brush;
class IPatch;

namespace selection { struct WorkZone; }
namespace selection
{
struct WorkZone;

// The possible modes when in "component manipulation mode"
// Used by the SelectionSystem as well as the Texture Tool
enum class ComponentSelectionMode
{
Default,
Vertex,
Edge,
Face,
};
}

namespace selection
{

class SelectionSystem :
public RegisterableModule
Expand All @@ -58,14 +74,6 @@ class SelectionSystem :
eMergeAction,
};

// The possible modes when in "component manipulation mode"
enum EComponentMode {
eDefault,
eVertex,
eEdge,
eFace,
};

/** greebo: An SelectionSystem::Observer gets notified
* as soon as the selection is changed.
*/
Expand All @@ -85,27 +93,27 @@ class SelectionSystem :
virtual void removeObserver(Observer* observer) = 0;

// Returns the ID of the registered manipulator
virtual std::size_t registerManipulator(const selection::ISceneManipulator::Ptr& manipulator) = 0;
virtual void unregisterManipulator(const selection::ISceneManipulator::Ptr& manipulator) = 0;
virtual std::size_t registerManipulator(const ISceneManipulator::Ptr& manipulator) = 0;
virtual void unregisterManipulator(const ISceneManipulator::Ptr& manipulator) = 0;

virtual selection::IManipulator::Type getActiveManipulatorType() = 0;
virtual IManipulator::Type getActiveManipulatorType() = 0;

// Returns the currently active Manipulator, which is always non-null
virtual const selection::ISceneManipulator::Ptr& getActiveManipulator() = 0;
virtual const ISceneManipulator::Ptr& getActiveManipulator() = 0;
virtual void setActiveManipulator(std::size_t manipulatorId) = 0;
virtual void setActiveManipulator(selection::IManipulator::Type manipulatorType) = 0;
virtual void setActiveManipulator(IManipulator::Type manipulatorType) = 0;

virtual sigc::signal<void, selection::IManipulator::Type>& signal_activeManipulatorChanged() = 0;
virtual sigc::signal<void, IManipulator::Type>& signal_activeManipulatorChanged() = 0;

virtual const SelectionInfo& getSelectionInfo() = 0;

virtual void SetMode(EMode mode) = 0;
virtual EMode Mode() const = 0;
virtual void SetComponentMode(EComponentMode mode) = 0;
virtual EComponentMode ComponentMode() const = 0;
virtual void SetComponentMode(ComponentSelectionMode mode) = 0;
virtual ComponentSelectionMode ComponentMode() const = 0;

virtual sigc::signal<void, EMode>& signal_selectionModeChanged() = 0;
virtual sigc::signal<void, EComponentMode>& signal_componentModeChanged() = 0;
virtual sigc::signal<void, ComponentSelectionMode>& signal_componentModeChanged() = 0;

virtual std::size_t countSelected() const = 0;
virtual std::size_t countSelectedComponents() const = 0;
Expand Down Expand Up @@ -216,16 +224,18 @@ class SelectionSystem :
*
* Note: the struct is defined in selectionlib.h.
*/
virtual const selection::WorkZone& getWorkZone() = 0;
virtual const WorkZone& getWorkZone() = 0;

// Returns the center point of the current selection
virtual Vector3 getCurrentSelectionCenter() = 0;
};

const char* const MODULE_SELECTIONSYSTEM("SelectionSystem");
}

constexpr const char* const MODULE_SELECTIONSYSTEM("SelectionSystem");

inline SelectionSystem& GlobalSelectionSystem()
inline selection::SelectionSystem& GlobalSelectionSystem()
{
static module::InstanceReference<SelectionSystem> _reference(MODULE_SELECTIONSYSTEM);
static module::InstanceReference<selection::SelectionSystem> _reference(MODULE_SELECTIONSYSTEM);
return _reference;
}
6 changes: 3 additions & 3 deletions include/iselectiontest.h
Expand Up @@ -278,9 +278,9 @@ class ComponentSelectionTestable {
public:
virtual ~ComponentSelectionTestable() {}
virtual bool isSelectedComponents() const = 0;
virtual void setSelectedComponents(bool select, SelectionSystem::EComponentMode mode) = 0;
virtual void invertSelectedComponents(SelectionSystem::EComponentMode mode) = 0;
virtual void testSelectComponents(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode) = 0;
virtual void setSelectedComponents(bool select, selection::ComponentSelectionMode mode) = 0;
virtual void invertSelectedComponents(selection::ComponentSelectionMode mode) = 0;
virtual void testSelectComponents(Selector& selector, SelectionTest& test, selection::ComponentSelectionMode mode) = 0;
};
typedef std::shared_ptr<ComponentSelectionTestable> ComponentSelectionTestablePtr;

Expand Down
4 changes: 2 additions & 2 deletions include/itexturetoolmodel.h
Expand Up @@ -177,8 +177,8 @@ class ITextureToolSelectionSystem :
virtual void setMode(SelectionMode mode) = 0;
virtual sigc::signal<void, SelectionMode>& signal_selectionModeChanged() = 0;

virtual void selectPoint(SelectionTest& test, SelectionSystem::EModifier modifier) = 0;
virtual void selectArea(SelectionTest& test, SelectionSystem::EModifier modifier) = 0;
virtual void selectPoint(SelectionTest& test, selection::SelectionSystem::EModifier modifier) = 0;
virtual void selectArea(SelectionTest& test, selection::SelectionSystem::EModifier modifier) = 0;

// Returns the ID of the registered manipulator
virtual std::size_t registerManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) = 0;
Expand Down
52 changes: 52 additions & 0 deletions libs/messages/ComponentSelectionModeToggleRequest.h
@@ -0,0 +1,52 @@
#pragma once

#include "imessagebus.h"
#include "iselection.h"

namespace selection
{

/**
* Message sent out by the main selection system when the user
* hits a shortcut to toggle the component selection mode.
* This gives listeners a chance to react to the request
* before it is handled by the RadiantSelectionSystem itself.
* Unhandled requests will be processed as usual.
*/
class ComponentSelectionModeToggleRequest :
public radiant::IMessage
{
private:
bool _handled;
ComponentSelectionMode _mode;

public:
ComponentSelectionModeToggleRequest(ComponentSelectionMode mode) :
_handled(false),
_mode(mode)
{}

std::size_t getId() const override
{
return Type::ComponentSelectionModeToggleRequest;
}

ComponentSelectionMode getMode() const
{
return _mode;
}

// Handled requests will not be processed by the selection system
void setHandled(bool handled)
{
_handled = true;
}

// TRUE whether this request has been handled
bool isHandled() const
{
return _handled;
}
};

}
2 changes: 1 addition & 1 deletion libs/render/RenderableCollectionWalker.h
Expand Up @@ -120,7 +120,7 @@ class RenderableCollectionWalker :

if (highlightFlags & Renderable::Highlight::Selected)
{
if (GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
if (GlobalSelectionSystem().Mode() != selection::SelectionSystem::eComponent)
{
_collector.setHighlightFlag(RenderableCollector::Highlight::Faces, true);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/scene/GroupNodeChecker.h
Expand Up @@ -9,7 +9,7 @@ namespace scene
// Checks the current selection to see whether it consists of
// group nodes only.
class GroupNodeChecker :
public SelectionSystem::Visitor
public selection::SelectionSystem::Visitor
{
private:
mutable bool _onlyGroups;
Expand Down
2 changes: 1 addition & 1 deletion libs/scene/ModelFinder.h
Expand Up @@ -9,7 +9,7 @@ namespace scene

// Visitor that checks the current selection for models
class ModelFinder :
public SelectionSystem::Visitor
public selection::SelectionSystem::Visitor
{
public:
typedef std::vector<scene::INodePtr> ModelList;
Expand Down
2 changes: 1 addition & 1 deletion libs/scene/PrefabBoundsAccumulator.h
Expand Up @@ -14,7 +14,7 @@ namespace scene
*/
class PrefabBoundsAccumulator final :
public scene::NodeVisitor,
public SelectionSystem::Visitor
public selection::SelectionSystem::Visitor
{
private:
mutable AABB _bounds;
Expand Down
2 changes: 1 addition & 1 deletion libs/shaderlib.h
Expand Up @@ -103,7 +103,7 @@ inline int findAndReplaceShader(const std::string& find, const std::string& repl

if (selectedOnly)
{
if (GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
if (GlobalSelectionSystem().Mode() != selection::SelectionSystem::eComponent)
{
// Find & replace all the brush and patch shaders
GlobalSelectionSystem().foreachFace(std::ref(replacer));
Expand Down
8 changes: 4 additions & 4 deletions plugins/script/interfaces/SelectionInterface.cpp
Expand Up @@ -8,12 +8,12 @@ const SelectionInfo& SelectionInterface::getSelectionInfo()
return GlobalSelectionSystem().getSelectionInfo();
}

void SelectionInterface::foreachSelected(const SelectionSystem::Visitor& visitor)
void SelectionInterface::foreachSelected(const selection::SelectionSystem::Visitor& visitor)
{
GlobalSelectionSystem().foreachSelected(visitor);
}

void SelectionInterface::foreachSelectedComponent(const SelectionSystem::Visitor& visitor)
void SelectionInterface::foreachSelectedComponent(const selection::SelectionSystem::Visitor& visitor)
{
GlobalSelectionSystem().foreachSelectedComponent(visitor);
}
Expand Down Expand Up @@ -59,9 +59,9 @@ void SelectionInterface::registerInterface(py::module& scope, py::dict& globals)
selInfo.def_readonly("componentCount", &SelectionInfo::componentCount);

// Expose the SelectionSystem::Visitor interface
py::class_<SelectionSystem::Visitor, SelectionVisitorWrapper> visitor(scope, "SelectionVisitor");
py::class_<selection::SelectionSystem::Visitor, SelectionVisitorWrapper> visitor(scope, "SelectionVisitor");
visitor.def(py::init<>());
visitor.def("visit", &SelectionSystem::Visitor::visit);
visitor.def("visit", &selection::SelectionSystem::Visitor::visit);

// Expose the SelectionFaceVisitor interface
py::class_<SelectedFaceVisitor, SelectedFaceVisitorWrapper> faceVisitor(scope, "SelectedFaceVisitor");
Expand Down
8 changes: 4 additions & 4 deletions plugins/script/interfaces/SelectionInterface.h
Expand Up @@ -17,15 +17,15 @@ namespace script

// Wrap around the SelectionSystem::Visitor interface
class SelectionVisitorWrapper :
public SelectionSystem::Visitor
public selection::SelectionSystem::Visitor
{
public:
void visit(const scene::INodePtr& node) const override
{
// Wrap this method to python
PYBIND11_OVERLOAD_PURE(
void, /* Return type */
SelectionSystem::Visitor, /* Parent class */
selection::SelectionSystem::Visitor, /* Parent class */
visit, /* Name of function in C++ (must match Python name) */
ScriptSceneNode(node) /* Argument(s) */
);
Expand Down Expand Up @@ -64,8 +64,8 @@ class SelectionInterface :
// SelectionSystem wrappers
const SelectionInfo& getSelectionInfo();

void foreachSelected(const SelectionSystem::Visitor& visitor);
void foreachSelectedComponent(const SelectionSystem::Visitor& visitor);
void foreachSelected(const selection::SelectionSystem::Visitor& visitor);
void foreachSelectedComponent(const selection::SelectionSystem::Visitor& visitor);
void foreachSelectedFace(SelectedFaceVisitor& visitor);

void setSelectedAll(int selected);
Expand Down
10 changes: 5 additions & 5 deletions radiant/selection/SceneManipulateMouseTool.cpp
Expand Up @@ -31,7 +31,7 @@ bool SceneManipulateMouseTool::manipulationIsPossible()
assert(activeManipulator);

bool dragComponentMode = activeManipulator->getType() == selection::IManipulator::Drag &&
GlobalSelectionSystem().Mode() == SelectionSystem::eComponent;
GlobalSelectionSystem().Mode() == selection::SelectionSystem::eComponent;

return dragComponentMode || !nothingSelected();
}
Expand Down Expand Up @@ -65,12 +65,12 @@ bool SceneManipulateMouseTool::nothingSelected() const
{
switch (GlobalSelectionSystem().Mode())
{
case SelectionSystem::eComponent:
case selection::SelectionSystem::eComponent:
return GlobalSelectionSystem().countSelectedComponents() == 0;

case SelectionSystem::eGroupPart:
case SelectionSystem::ePrimitive:
case SelectionSystem::eEntity:
case selection::SelectionSystem::eGroupPart:
case selection::SelectionSystem::ePrimitive:
case selection::SelectionSystem::eEntity:
return GlobalSelectionSystem().countSelected() == 0;

default:
Expand Down
6 changes: 3 additions & 3 deletions radiant/selection/SelectionMouseTools.cpp
Expand Up @@ -128,11 +128,11 @@ void BasicSelectionTool::performSelectionTest(SelectionVolume& volume, Selection
{
if (type == SelectionType::Area)
{
GlobalSelectionSystem().selectArea(volume, SelectionSystem::eToggle, selectFacesOnly());
GlobalSelectionSystem().selectArea(volume, selection::SelectionSystem::eToggle, selectFacesOnly());
}
else
{
GlobalSelectionSystem().selectPoint(volume, SelectionSystem::eToggle, selectFacesOnly());
GlobalSelectionSystem().selectPoint(volume, selection::SelectionSystem::eToggle, selectFacesOnly());
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ void CycleSelectionMouseTool::testSelect(MouseTool::Event& ev)

// If we already replaced a selection, switch to cycle mode
// eReplace should only be active during the first call without mouse movement
SelectionSystem::EModifier modifier = _mouseMovedSinceLastSelect ? SelectionSystem::eReplace : SelectionSystem::eCycle;
auto modifier = _mouseMovedSinceLastSelect ? selection::SelectionSystem::eReplace : selection::SelectionSystem::eCycle;

// Copy the view to create a scissored volume
render::View scissored(_view);
Expand Down
4 changes: 2 additions & 2 deletions radiant/textool/tools/TextureToolSelectionTool.h
Expand Up @@ -39,11 +39,11 @@ class TextureToolSelectionTool :

if (type == SelectionType::Area)
{
GlobalTextureToolSelectionSystem().selectArea(volume, SelectionSystem::eToggle);
GlobalTextureToolSelectionSystem().selectArea(volume, selection::SelectionSystem::eToggle);
}
else
{
GlobalTextureToolSelectionSystem().selectPoint(volume, SelectionSystem::eToggle);
GlobalTextureToolSelectionSystem().selectPoint(volume, selection::SelectionSystem::eToggle);
}
}
};
Expand Down

0 comments on commit b1d91be

Please sign in to comment.