From: Mattia Basaglia Date: Thu, 23 Jul 2015 13:46:18 +0000 (+0200) Subject: Only clone leaves (not groups) with CloneSelected X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=dfb1dcf4facacdd732459fa77a0fd3ff7afe3ca1;p=xonotic%2Fnetradiant.git Only clone leaves (not groups) with CloneSelected Closes #35 --- 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 ){