From bf3d5aa84b5f5a3357b45c2952df4891fe283baf Mon Sep 17 00:00:00 2001 From: Mattia Basaglia Date: Thu, 23 Jul 2015 10:55:54 +0200 Subject: [PATCH] Remove empty entities when regrouping primitives --- radiant/map.cpp | 79 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/radiant/map.cpp b/radiant/map.cpp index 44633afa..7493c088 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -1598,38 +1598,65 @@ bool Map_SaveSelected( const char* filename ){ class ParentSelectedBrushesToEntityWalker : public scene::Graph::Walker { -scene::Node& m_parent; + scene::Node& m_parent; + mutable bool m_emptyOldParent {false}; + public: -ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ){ -} -bool pre( const scene::Path& path, scene::Instance& instance ) const { - if ( path.top().get_pointer() != &m_parent - && Node_isPrimitive( path.top() ) ) { - Selectable* selectable = Instance_getSelectable( instance ); - if ( selectable != 0 - && selectable->isSelected() - && path.size() > 1 ) { - return false; + + ParentSelectedBrushesToEntityWalker( scene::Node& parent ) + : m_parent( parent ) + {} + + bool pre( const scene::Path& path, scene::Instance& instance ) const override + { + if ( path.top().get_pointer() != &m_parent && + ( Node_isPrimitive( path.top() ) || m_emptyOldParent ) ) + { + Selectable* selectable = Instance_getSelectable( instance ); + if ( selectable && selectable->isSelected() && path.size() > 1 ) + { + return false; + } } + return true; } - return true; -} -void post( const scene::Path& path, scene::Instance& instance ) const { - if ( path.top().get_pointer() != &m_parent - && Node_isPrimitive( path.top() ) ) { - Selectable* selectable = Instance_getSelectable( instance ); - if ( selectable != 0 - && selectable->isSelected() - && path.size() > 1 ) { - scene::Node& parent = path.parent(); - if ( &parent != &m_parent ) { - NodeSmartReference node( path.top().get() ); - Node_getTraversable( parent )->erase( node ); - Node_getTraversable( m_parent )->insert( node ); + + void post( const scene::Path& path, scene::Instance& instance ) const override + { + if ( path.top().get_pointer() == &m_parent ) + return; + + if ( Node_isPrimitive( path.top() ) ) + { + m_emptyOldParent = false; + Selectable* selectable = Instance_getSelectable( instance ); + + if ( selectable && selectable->isSelected() && path.size() > 1 ) + { + scene::Node& parent = path.parent(); + if ( &parent != &m_parent ) + { + NodeSmartReference node( path.top().get() ); + auto traversable_parent = Node_getTraversable( parent ); + traversable_parent->erase( node ); + Node_getTraversable( m_parent )->insert( node ); + if ( traversable_parent->empty() ) + m_emptyOldParent = true; + } + } + } + else if ( m_emptyOldParent ) + { + m_emptyOldParent = false; + // delete empty entities + Entity* entity = Node_getEntity( path.top() ); + if ( entity != 0 + && path.top().get_pointer() != Map_FindWorldspawn( g_map ) + && Node_getTraversable( path.top() )->empty() ) { + Path_deleteTop( path ); } } } -} }; void Scene_parentSelectedBrushesToEntity( scene::Graph& graph, scene::Node& parent ){ -- 2.39.2