Skip to content

Commit

Permalink
#6120: SnapToGrid is now automatically removing degenerate brushes fr…
Browse files Browse the repository at this point in the history
…om the scene
  • Loading branch information
codereader committed Oct 8, 2022
1 parent 72700e3 commit e5df2d9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
47 changes: 26 additions & 21 deletions radiantcore/selection/SceneWalkers.h
Expand Up @@ -46,32 +46,37 @@ class RemoveDegenerateBrushWalker :
mutable std::list<scene::INodePtr> _eraseList;
public:
// Destructor removes marked paths
~RemoveDegenerateBrushWalker() {
for (std::list<scene::INodePtr>::iterator i = _eraseList.begin(); i != _eraseList.end(); ++i) {
// Check if the parent has any children left at all
scene::INodePtr parent = (*i)->getParent();

// Remove the node from the scene
scene::removeNodeFromParent(*i);

if (parent != NULL && !parent->hasChildNodes()) {
rError() << "Warning: removing empty parent entity." << std::endl;
scene::removeNodeFromParent(parent);
}
}
~RemoveDegenerateBrushWalker() override
{
for (const auto& node : _eraseList)
{
// Check if the parent has any children left at all
auto parent = node->getParent();

// Remove the node from the scene
removeNodeFromParent(node);

if (parent && !parent->hasChildNodes())
{
rError() << "Warning: removing empty parent entity." << std::endl;
removeNodeFromParent(parent);
}
}
}

void visit(const scene::INodePtr& node) const
void visit(const scene::INodePtr& node) const override
{
Brush* brush = Node_getBrush(node);

if (brush != NULL && !brush->hasContributingFaces())
if (auto brush = Node_getBrush(node); brush)
{
// greebo: Mark this path for removal
_eraseList.push_back(node);
brush->evaluateBRep();

rError() << "Warning: removed degenerate brush!\n";
return;
if (!brush->hasContributingFaces())
{
// greebo: Mark this path for removal
_eraseList.push_back(node);

rError() << "Warning: removed degenerate brush!\n";
}
}
}
};
Expand Down
11 changes: 5 additions & 6 deletions radiantcore/selection/algorithm/General.cpp
Expand Up @@ -730,9 +730,7 @@ void snapSelectionToGrid(const cmd::ArgumentList& args)
if (!node->visible()) return;

// Check if the visited instance is componentSnappable
ComponentSnappablePtr componentSnappable = Node_getComponentSnappable(node);

if (componentSnappable)
if (auto componentSnappable = Node_getComponentSnappable(node); componentSnappable)
{
componentSnappable->snapComponents(gridSize);
}
Expand All @@ -746,14 +744,15 @@ void snapSelectionToGrid(const cmd::ArgumentList& args)
// Don't do anything with hidden nodes
if (!node->visible()) return;

SnappablePtr snappable = Node_getSnappable(node);

if (snappable)
if (auto snappable = Node_getSnappable(node); snappable)
{
snappable->snapto(gridSize);
}
});
}

// Remove all degenerated brushes after this operation
GlobalSelectionSystem().foreachSelected(RemoveDegenerateBrushWalker());
}

class IntersectionFinder :
Expand Down

0 comments on commit e5df2d9

Please sign in to comment.