Skip to content

Commit

Permalink
#5746: "Select Related" texture tool command implemented. Fix copy&pa…
Browse files Browse the repository at this point in the history
…ste error in unit test code.
  • Loading branch information
codereader committed Sep 26, 2021
1 parent 520a24c commit 030f8fa
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
8 changes: 8 additions & 0 deletions include/itexturetoolmodel.h
Expand Up @@ -72,6 +72,10 @@ class IComponentSelectable

// Returns the bounds containing all the selected vertices
virtual AABB getSelectedComponentBounds() = 0;

// If this node has selected components, this selects all related items too
// E.g. a single winding vertex expands to the entire winding
virtual void expandComponentSelectionToRelated() = 0;
};

// A Texture Tool node that allows its components to be transformed
Expand All @@ -98,6 +102,10 @@ class INode :

// Renders this node, with all coords relative to UV space origin
virtual void render(SelectionMode mode) = 0;

// If this node is selected, this selects all related items too:
// a single face expands to all faces of the same brush
virtual void expandSelectionToRelated() = 0;
};

// Node representing a single brush face
Expand Down
23 changes: 23 additions & 0 deletions radiantcore/selection/textool/FaceNode.h
Expand Up @@ -216,6 +216,29 @@ class FaceNode :
}
}

void expandSelectionToRelated() override
{
if (!isSelected())
{
return;
}

// Expand the selection to all faces with the same brush
auto& brush = _face.getBrush();

GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
auto face = std::dynamic_pointer_cast<FaceNode>(node);

if (face && &(face->getFace().getBrush()) == &brush)
{
face->setSelected(true);
}

return true;
});
}

private:
// Locates the index of the vertex that is farthest away from the given texcoord
// the indices contained in exludedIndices are not returned
Expand Down
13 changes: 13 additions & 0 deletions radiantcore/selection/textool/NodeBase.h
Expand Up @@ -102,6 +102,19 @@ class NodeBase :
return bounds;
}

virtual void expandComponentSelectionToRelated() override
{
if (!hasSelectedComponents())
{
return;
}

for (auto& vertex : _vertices)
{
vertex.setSelected(true);
}
}

protected:
virtual void renderComponents()
{
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/selection/textool/PatchNode.h
Expand Up @@ -164,6 +164,9 @@ class PatchNode :
}
}

void expandSelectionToRelated() override
{}

private:
void foreachVertex(const std::function<void(PatchControl&)>& functor) const
{
Expand Down
26 changes: 25 additions & 1 deletion radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -540,7 +540,31 @@ void TextureToolSelectionSystem::onComponentSelectionChanged(ISelectable& select

void TextureToolSelectionSystem::selectRelatedCmd(const cmd::ArgumentList& args)
{
// TODO
// Accumulate all selected nodes in a copied list, we're going to alter the selection
std::vector<INode::Ptr> nodes;

foreachSelectedNodeOfAnyType([&](const INode::Ptr& node)
{
nodes.push_back(node);
return true;
});

for (const auto& node : nodes)
{
if (getSelectionMode() == textool::SelectionMode::Surface)
{
node->expandSelectionToRelated();
}
else
{
auto componentSelectable = std::dynamic_pointer_cast<IComponentSelectable>(node);

if (componentSelectable)
{
componentSelectable->expandComponentSelectionToRelated();
}
}
}
}

module::StaticModule<TextureToolSelectionSystem> _textureToolSelectionSystemModule;
Expand Down
2 changes: 1 addition & 1 deletion test/TextureTool.cpp
Expand Up @@ -1542,7 +1542,7 @@ TEST_F(TextureToolTest, SelectRelatedOfFaceNode)
// Execute "Select Related"
GlobalCommandSystem().executeCommand("TexToolSelectRelated");

EXPECT_EQ(getAllSelectedComponentNodes().size(), 6) << "All 6 faces should be selected";
EXPECT_EQ(getAllSelectedTextoolNodes().size(), 6) << "All 6 faces should be selected";
}

}

0 comments on commit 030f8fa

Please sign in to comment.