Skip to content

Commit

Permalink
3214: update face tags when the brush changes (#3218)
Browse files Browse the repository at this point in the history
Fixes #3214

Note that Brush::doSetNewGeometry clones the BrushFaces (which doesn't clone the Taggable info per face).
  • Loading branch information
ericwa authored and kduske committed May 19, 2020
1 parent 08fb5e7 commit cf27707
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions common/src/Model/Brush.cpp
Expand Up @@ -1549,6 +1549,13 @@ namespace TrenchBroom {
Taggable::clearTags();
}

void Brush::updateTags(TagManager& tagManager) {
for (auto* face : m_faces) {
face->updateTags(tagManager);
}
Taggable::updateTags(tagManager);
}

bool Brush::allFacesHaveAnyTagInMask(TagType::Type tagMask) const {
// Possible optimization: Store the shared face tag mask in the brush and updated it when a face changes.

Expand Down
1 change: 1 addition & 0 deletions common/src/Model/Brush.h
Expand Up @@ -313,6 +313,7 @@ namespace TrenchBroom {
public:
void initializeTags(TagManager& tagManager) override;
void clearTags() override;
void updateTags(TagManager& tagManager) override;

/**
* Indicates whether all of the faces of this brush have any of the given tags.
Expand Down
16 changes: 13 additions & 3 deletions common/test/src/View/TagManagementTest.cpp
Expand Up @@ -471,20 +471,30 @@ namespace TrenchBroom {
ASSERT_TRUE(brush->hasTag(tag));
}

TEST_CASE_METHOD(TagManagementTest, "TagManagementTest.tagInitializeBrushFaceTags") {
TEST_CASE_METHOD(TagManagementTest, "TagManagementTest.tagInitializeBrushFaceTags", "[TagManagementTest]") {
auto* brushWithTags = createBrush("some_texture");
document->addNode(brushWithTags, document->currentParent());
document->select(brushWithTags);

SECTION("No modification to brush") {
}
SECTION("Vertex manipulation") {
const auto verticesToMove = std::map<vm::vec3, std::vector<Model::Brush*>>{ { vm::vec3::fill(16.0), { brushWithTags } } };
const auto result = document->moveVertices(verticesToMove, vm::vec3::fill(1.0));
REQUIRE(result.success);
REQUIRE(result.hasRemainingVertices);
}

const auto& tag = document->smartTag("texture");
for (const auto* face : brushWithTags->faces()) {
ASSERT_TRUE(face->hasTag(tag));
CHECK(face->hasTag(tag));
}

auto* brushWithoutTags = createBrush("asdf");
document->addNode(brushWithoutTags, document->currentParent());

for (const auto* face : brushWithoutTags->faces()) {
ASSERT_FALSE(face->hasTag(tag));
CHECK(!face->hasTag(tag));
}
}

Expand Down

0 comments on commit cf27707

Please sign in to comment.