Skip to content

Commit

Permalink
#5746: Tests covering selection mode toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 19, 2021
1 parent 9e76903 commit ce03fcc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
41 changes: 41 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -38,6 +38,9 @@ void TextureToolSelectionSystem::initialiseModule(const IApplicationContext& ctx
GlobalCommandSystem().addCommand("ToggleTextureToolManipulatorMode",
std::bind(&TextureToolSelectionSystem::toggleManipulatorModeCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("ToggleTextureToolSelectionMode",
std::bind(&TextureToolSelectionSystem::toggleSelectionModeCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING });
}

void TextureToolSelectionSystem::shutdownModule()
Expand All @@ -60,6 +63,21 @@ void TextureToolSelectionSystem::setMode(SelectionMode mode)
}
}

void TextureToolSelectionSystem::toggleSelectionMode(SelectionMode mode)
{
// Switch back to Surface mode if toggling a non-default mode again
if (mode == _mode && mode != SelectionMode::Surface)
{
// Toggle back to Surface mode
toggleSelectionMode(SelectionMode::Surface);
}
else
{
// setMode will only do something if we're not already in the target mode
setMode(mode);
}
}

sigc::signal<void, SelectionMode>& TextureToolSelectionSystem::signal_selectionModeChanged()
{
return _sigSelectionModeChanged;
Expand Down Expand Up @@ -88,6 +106,29 @@ void TextureToolSelectionSystem::toggleManipulatorModeCmd(const cmd::ArgumentLis
}
}

void TextureToolSelectionSystem::toggleSelectionModeCmd(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rWarning() << "Usage: ToggleTextureToolSelectionMode <mode>" << std::endl;
rWarning() << " with <mode> being one of the following: " << std::endl;
rWarning() << " Surface" << std::endl;
rWarning() << " Vertex" << std::endl;
return;
}

auto manip = string::to_lower_copy(args[0].getString());

if (manip == "surface")
{
toggleSelectionMode(SelectionMode::Surface);
}
else if (manip == "vertex")
{
toggleSelectionMode(SelectionMode::Vertex);
}
}

void TextureToolSelectionSystem::foreachSelectedNode(const std::function<bool(const INode::Ptr&)>& functor)
{
GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.h
Expand Up @@ -60,6 +60,9 @@ class TextureToolSelectionSystem :
void toggleManipulatorModeCmd(const cmd::ArgumentList& args);
void toggleManipulatorModeById(std::size_t manipId);
std::size_t getManipulatorIdForType(selection::IManipulator::Type type);

void toggleSelectionMode(SelectionMode mode);
void toggleSelectionModeCmd(const cmd::ArgumentList& args);
};

}
44 changes: 44 additions & 0 deletions test/TextureTool.cpp
Expand Up @@ -355,6 +355,50 @@ TEST_F(TextureToolTest, ManipulatorModeChangedSignal)
conn.disconnect();
}

TEST_F(TextureToolTest, ToggleSelectionMode)
{
bool signalFired = false;
textool::SelectionMode signalArgument;

// Subscribe to the changed signal
sigc::connection conn = GlobalTextureToolSelectionSystem().signal_selectionModeChanged().connect(
[&](textool::SelectionMode mode)
{
signalFired = true;
signalArgument = mode;
});

// We're starting in Surface mode, toggle to Surface again
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Surface" });
EXPECT_EQ(GlobalTextureToolSelectionSystem().getMode(), textool::SelectionMode::Surface);
EXPECT_FALSE(signalFired) << "Signal shouldn't have fired";
signalFired = false;

// Switch to vertex mode
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Vertex" });
EXPECT_EQ(GlobalTextureToolSelectionSystem().getMode(), textool::SelectionMode::Vertex);
EXPECT_TRUE(signalFired) << "Signal should have fired";
signalFired = false;

// Toggle vertex mode again => back to surface mode
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Vertex" });
EXPECT_EQ(GlobalTextureToolSelectionSystem().getMode(), textool::SelectionMode::Surface);
EXPECT_TRUE(signalFired) << "Signal should have fired";
signalFired = false;

// Switch to vertex mode (again)
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Vertex" });
EXPECT_EQ(GlobalTextureToolSelectionSystem().getMode(), textool::SelectionMode::Vertex);
EXPECT_TRUE(signalFired) << "Signal should have fired";
signalFired = false;

// Directly toggle surface mode
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Surface" });
EXPECT_EQ(GlobalTextureToolSelectionSystem().getMode(), textool::SelectionMode::Surface);
EXPECT_TRUE(signalFired) << "Signal should have fired";
signalFired = false;
}

TEST_F(TextureToolTest, SelectionModeChangedSignal)
{
bool signalFired = false;
Expand Down

0 comments on commit ce03fcc

Please sign in to comment.