Skip to content

Commit

Permalink
#5746: Remove IManipulatorManager interface again, instead introduce …
Browse files Browse the repository at this point in the history
…a ITextureToolSelectionSystem interface which is the counter-part of the RadiantSelectionSystem handling the main scene.
  • Loading branch information
codereader committed Sep 17, 2021
1 parent 15bfb65 commit fe15ad0
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 243 deletions.
19 changes: 0 additions & 19 deletions include/imanipulator.h
Expand Up @@ -139,23 +139,4 @@ class ITextureToolManipulator :
virtual void renderComponents(const Matrix4& pivot2World) = 0;
};

// Factory interface instantiating new IManipulator instances for a given purpose
class IManipulatorManager :
public RegisterableModule
{
public:
virtual ~IManipulatorManager() {}

// Acquire a new instance of the given manipulator for the given context and type
virtual IManipulator::Ptr createManipulator(IManipulator::Context context, IManipulator::Type type) = 0;
};

}

const char* const MODULE_MANIPULATORMANAGER("ManipulatorManager");

inline selection::IManipulatorManager& GlobalManipulatorManager()
{
static module::InstanceReference<selection::IManipulatorManager> _reference(MODULE_MANIPULATORMANAGER);
return _reference;
}
28 changes: 28 additions & 0 deletions include/itexturetoolmodel.h
Expand Up @@ -5,6 +5,8 @@
#include "Bounded.h"
#include "iselection.h"
#include "iselectiontest.h"
#include "imanipulator.h"
#include <sigc++/signal.h>

class Matrix3;

Expand Down Expand Up @@ -76,18 +78,44 @@ class ITextureToolSceneGraph :
// Iterate over every node in this graph calling the given functor
// Collection should not be modified during iteration
virtual void foreachNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;
};

class ITextureToolSelectionSystem :
public RegisterableModule
{
public:
// Iterate over every selected node in this graph calling the given functor
// Collection should not be modified during iteration
virtual void foreachSelectedNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;

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

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

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

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

}

constexpr const char* const MODULE_TEXTOOL_SCENEGRAPH("TextureToolSceneGraph");
constexpr const char* const MODULE_TEXTOOL_SELECTIONSYSTEM("TextureToolSelectionSystem");

inline textool::ITextureToolSceneGraph& GlobalTextureToolSceneGraph()
{
static module::InstanceReference<textool::ITextureToolSceneGraph> _reference(MODULE_TEXTOOL_SCENEGRAPH);
return _reference;
}

inline textool::ITextureToolSelectionSystem& GlobalTextureToolSelectionSystem()
{
static module::InstanceReference<textool::ITextureToolSelectionSystem> _reference(MODULE_TEXTOOL_SELECTIONSYSTEM);
return _reference;
}

125 changes: 12 additions & 113 deletions radiant/textool/TexTool.cpp
Expand Up @@ -78,13 +78,6 @@ TexTool::TexTool() :
_freezePointer.connectMouseEvents(
std::bind(&TexTool::onMouseDown, this, std::placeholders::_1),
std::bind(&TexTool::onMouseUp, this, std::placeholders::_1));

registerManipulator(std::static_pointer_cast<selection::ITextureToolManipulator>(
GlobalManipulatorManager().createManipulator(
selection::IManipulator::Context::TextureTool, selection::IManipulator::Rotate)));

_defaultManipulatorType = selection::IManipulator::Rotate;
setActiveManipulator(_defaultManipulatorType);
}

TexToolPtr& TexTool::InstancePtr()
Expand Down Expand Up @@ -403,14 +396,11 @@ void TexTool::testSelect(SelectionTest& test)
Vector2 sum;
std::size_t count = 0;

GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
if (node->isSelected())
{
auto bounds = node->localAABB();
sum += Vector2(bounds.origin.x(), bounds.origin.y());
count++;
}
auto bounds = node->localAABB();
sum += Vector2(bounds.origin.x(), bounds.origin.y());
count++;

return true;
});
Expand Down Expand Up @@ -1013,9 +1003,11 @@ bool TexTool::onGLDraw()
// Draw the u/v coordinates
drawUVCoords();

if (_activeManipulator)
auto activeManipulator = GlobalTextureToolSelectionSystem().getActiveManipulator();

if (activeManipulator)
{
_activeManipulator->renderComponents(_pivot2World);
activeManipulator->renderComponents(_pivot2World);
}

if (!_activeMouseTools.empty())
Expand Down Expand Up @@ -1270,107 +1262,14 @@ TextureToolMouseEvent TexTool::createMouseEvent(const Vector2& point, const Vect
return TextureToolMouseEvent(*this, normalisedDeviceCoords, delta);
}

std::size_t TexTool::registerManipulator(const selection::ITextureToolManipulator::Ptr& manipulator)
{
std::size_t newId = 1;

while (_manipulators.count(newId) > 0)
{
++newId;

if (newId == std::numeric_limits<std::size_t>::max())
{
throw std::runtime_error("Out of manipulator IDs");
}
}

_manipulators.emplace(newId, manipulator);

manipulator->setId(newId);

if (!_activeManipulator)
{
_activeManipulator = manipulator;
}

return newId;
}

void TexTool::unregisterManipulator(const selection::ITextureToolManipulator::Ptr& manipulator)
{
for (auto i = _manipulators.begin(); i != _manipulators.end(); ++i)
{
if (i->second == manipulator)
{
i->second->setId(0);
_manipulators.erase(i);
return;
}
}
}

selection::IManipulator::Type TexTool::getActiveManipulatorType()
{
return _activeManipulator->getType();
}

const selection::ITextureToolManipulator::Ptr& TexTool::getActiveManipulator()
{
return _activeManipulator;
}

void TexTool::setActiveManipulator(std::size_t manipulatorId)
{
auto found = _manipulators.find(manipulatorId);

if (found == _manipulators.end())
{
rError() << "Cannot activate non-existent manipulator ID " << manipulatorId << std::endl;
return;
}

_activeManipulator = found->second;
#if 0
// Release the user lock when switching manipulators
_pivot.setUserLocked(false);

pivotChanged();
#endif
}

void TexTool::setActiveManipulator(selection::IManipulator::Type manipulatorType)
{
for (const Manipulators::value_type& pair : _manipulators)
{
if (pair.second->getType() == manipulatorType)
{
_activeManipulator = pair.second;
#if 0
// Release the user lock when switching manipulators
_pivot.setUserLocked(false);

pivotChanged();
#endif
return;
}
}

rError() << "Cannot activate non-existent manipulator by type " << manipulatorType << std::endl;
}

sigc::signal<void, selection::IManipulator::Type>& TexTool::signal_activeManipulatorChanged()
{
return _sigActiveManipulatorChanged;
}

Matrix4 TexTool::getPivot2World()
{
return _pivot2World;
}

void TexTool::onManipulationStart()
{
GlobalTextureToolSceneGraph().foreachSelectedNode([&] (const textool::INode::Ptr& node)
GlobalTextureToolSelectionSystem().foreachSelectedNode([&] (const textool::INode::Ptr& node)
{
node->beginTransformation();
return true;
Expand All @@ -1383,18 +1282,18 @@ void TexTool::onManipulationChanged()

void TexTool::onManipulationEnd()
{
GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->commitTransformation();
return true;
});

_activeManipulator->setSelected(false);
GlobalTextureToolSelectionSystem().getActiveManipulator()->setSelected(false);
}

void TexTool::onManipulationCancelled()
{
GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->revertTransformation();
return true;
Expand Down
19 changes: 0 additions & 19 deletions radiant/textool/TexTool.h
Expand Up @@ -90,15 +90,6 @@ class TexTool :
sigc::connection _undoHandler;
sigc::connection _redoHandler;

typedef std::map<std::size_t, selection::ITextureToolManipulator::Ptr> Manipulators;
Manipulators _manipulators;

// The currently active manipulator
selection::ITextureToolManipulator::Ptr _activeManipulator;
selection::IManipulator::Type _defaultManipulatorType;

sigc::signal<void, selection::IManipulator::Type> _sigActiveManipulatorChanged;

Matrix4 _pivot2World;

private:
Expand Down Expand Up @@ -282,16 +273,6 @@ class TexTool :
*/
static void registerCommands();

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

selection::IManipulator::Type getActiveManipulatorType();
const selection::ITextureToolManipulator::Ptr& getActiveManipulator();
void setActiveManipulator(std::size_t manipulatorId);
void setActiveManipulator(selection::IManipulator::Type manipulatorType);
sigc::signal<void, selection::IManipulator::Type>& signal_activeManipulatorChanged();

/** greebo: Returns the number of selected TexToolItems.
*/
int countSelected();
Expand Down
3 changes: 2 additions & 1 deletion radiant/textool/tools/TextureToolManipulateMouseTool.cpp
@@ -1,6 +1,7 @@
#include "TextureToolManipulateMouseTool.h"

#include "i18n.h"
#include "itexturetoolmodel.h"
#include "textool/TexTool.h"

namespace ui
Expand All @@ -20,7 +21,7 @@ const std::string& TextureToolManipulateMouseTool::getDisplayName()

selection::IManipulator::Ptr TextureToolManipulateMouseTool::getActiveManipulator()
{
return TexTool::Instance().getActiveManipulator();
return GlobalTextureToolSelectionSystem().getActiveManipulator();
}

bool TextureToolManipulateMouseTool::manipulationIsPossible()
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/CMakeLists.txt
Expand Up @@ -244,7 +244,6 @@ add_library(radiantcore MODULE
selection/manipulators/DragManipulator.cpp
selection/manipulators/ManipulatorBase.cpp
selection/manipulators/ManipulatorComponents.cpp
selection/manipulators/ManipulatorManager.cpp
selection/manipulators/ModelScaleManipulator.cpp
selection/manipulators/RotateManipulator.cpp
selection/manipulators/ScaleManipulator.cpp
Expand All @@ -261,6 +260,7 @@ add_library(radiantcore MODULE
selection/shaderclipboard/ShaderClipboard.cpp
selection/shaderclipboard/Texturable.cpp
selection/textool/TextureToolSceneGraph.cpp
selection/textool/TextureToolSelectionSystem.cpp
selection/TransformationVisitors.cpp
settings/ColourScheme.cpp
settings/ColourSchemeManager.cpp
Expand Down
68 changes: 0 additions & 68 deletions radiantcore/selection/manipulators/ManipulatorManager.cpp

This file was deleted.

Expand Up @@ -222,7 +222,7 @@ void TextureToolRotateManipulator::rotateSelected(const Vector2& pivot, double a
transform.premultiplyBy(Matrix3::getRotation(-angle));
transform.premultiplyBy(Matrix3::getTranslation(pivot));

GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->revertTransformation();
node->applyTransformToSelected(transform);
Expand Down

0 comments on commit fe15ad0

Please sign in to comment.