]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Only clone leaves (not groups) with CloneSelected
authorMattia Basaglia <mattia.basaglia@gmail.com>
Thu, 23 Jul 2015 13:46:18 +0000 (15:46 +0200)
committerMattia Basaglia <mattia.basaglia@gmail.com>
Thu, 23 Jul 2015 13:46:24 +0000 (15:46 +0200)
Closes #35

include/iscenegraph.h
radiant/mainframe.cpp

index e22a4b765d3b876cfd98650140e4130a1db0db40..196cf7c1685b8eb9d8b7e050c22adeef7afe2073 100644 (file)
@@ -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 {
 }
 };
 
index 14f131f51daa1ad04fe250c4fc7501cc649c0f49..bd4f1590add854c50f61a2ddbc8bbc24e949f384 100644 (file)
@@ -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 ){