From dfb1dcf4facacdd732459fa77a0fd3ff7afe3ca1 Mon Sep 17 00:00:00 2001 From: Mattia Basaglia Date: Thu, 23 Jul 2015 15:46:18 +0200 Subject: [PATCH] Only clone leaves (not groups) with CloneSelected Closes #35 --- include/iscenegraph.h | 10 +++--- radiant/mainframe.cpp | 76 +++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/iscenegraph.h b/include/iscenegraph.h index e22a4b76..196cf7c1 100644 --- a/include/iscenegraph.h +++ b/include/iscenegraph.h @@ -76,11 +76,11 @@ STRING_CONSTANT( Name, "scenegraph" ); class Walker { public: -virtual ~Walker(){} -/// \brief Called before traversing the first child-instance of 'instance'. If the return value is false, the children of the current instance are not traversed. -virtual bool pre( const Path& path, Instance& instance ) const = 0; -/// \brief Called after traversing the last child-instance of 'instance'. -virtual void post( const Path& path, Instance& instance ) const { + virtual ~Walker(){} + /// \brief Called before traversing the first child-instance of 'instance'. If the return value is false, the children of the current instance are not traversed. + virtual bool pre( const Path& path, Instance& instance ) const = 0; + /// \brief Called after traversing the last child-instance of 'instance'. + virtual void post( const Path& path, Instance& instance ) const { } }; diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 14f131f5..bd4f1590 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -1127,55 +1127,55 @@ void SelectFaceMode(){ class CloneSelected : public scene::Graph::Walker { -bool doMakeUnique; -NodeSmartReference worldspawn; + bool doMakeUnique; + NodeSmartReference worldspawn; + public: -CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){ -} -bool pre( const scene::Path& path, scene::Instance& instance ) const { - if ( path.size() == 1 ) { - return true; - } + CloneSelected( bool d ) + : doMakeUnique( d ), + worldspawn( Map_FindOrInsertWorldspawn( g_map ) ) + {} - // ignore worldspawn, but keep checking children - NodeSmartReference me( path.top().get() ); - if ( me == worldspawn ) { - return true; - } + bool pre( const scene::Path& path, scene::Instance& instance ) const override + { + if ( path.size() == 1 ) { + return true; + } - if ( !path.top().get().isRoot() ) { - Selectable* selectable = Instance_getSelectable( instance ); - if ( selectable != 0 - && selectable->isSelected() ) { - return false; + // ignore worldspawn, but keep checking children + NodeSmartReference me( path.top().get() ); + if ( me == worldspawn ) { + return true; } - } - return true; -} -void post( const scene::Path& path, scene::Instance& instance ) const { - if ( path.size() == 1 ) { - return; + return true; } + void post( const scene::Path& path, scene::Instance& instance ) const override + { + if ( path.size() == 1 ) { + return; + } - // ignore worldspawn, but keep checking children - NodeSmartReference me( path.top().get() ); - if ( me == worldspawn ) { - return; - } + // ignore worldspawn, but keep checking children + NodeSmartReference me( path.top().get() ); + if ( me == worldspawn ) { + return; + } - if ( !path.top().get().isRoot() ) { - Selectable* selectable = Instance_getSelectable( instance ); - if ( selectable != 0 - && selectable->isSelected() ) { - NodeSmartReference clone( Node_Clone( path.top() ) ); - if ( doMakeUnique ) { - Map_gatherNamespaced( clone ); + if ( !path.top().get().isRoot() && !node_is_group(path.top().get()) ) + { + Selectable* selectable = Instance_getSelectable( instance ); + if ( selectable && selectable->isSelected() ) + { + NodeSmartReference clone( Node_Clone( path.top() ) ); + if ( doMakeUnique ) + { + Map_gatherNamespaced( clone ); + } + Node_getTraversable( path.parent().get() )->insert( clone ); } - Node_getTraversable( path.parent().get() )->insert( clone ); } } -} }; void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){ -- 2.39.2