From 461410f1a9fc93c742314d45cbcfaeb008361fb6 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 27 Jul 2018 20:21:42 +0300 Subject: [PATCH] * fix automatic connection names resolving of cloned entities issue was: create entity 1, clone to 2,3; connect 1-2, 2-3 = 1-3 connected; 2-3, 1-2/3-2 2-1 = ok; create all ones via menu/clone-make-unique/ctrl+c +v = ok clone-make-unique is broken, when operating with cloned entities, connected 3-2, 2-1 (ctrl+c +v too) --- libs/uniquenames.h | 21 +++++++++++---------- radiant/mainframe.cpp | 8 +++----- radiant/map.cpp | 12 +++++++----- radiant/map.h | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libs/uniquenames.h b/libs/uniquenames.h index 9f89ba45..b9a2f363 100644 --- a/libs/uniquenames.h +++ b/libs/uniquenames.h @@ -184,28 +184,21 @@ typedef std::map names_t; names_t m_names; public: name_t make_unique( const name_t& name ) const { +#if 0 //debug char buf[80]; name_t r( "","" ); name_write( buf, name ); - #ifdef _DEBUG globalErrorStream() << "find unique name for " << buf << "\n"; globalErrorStream() << "> currently registered names:\n"; - #endif for ( names_t::const_iterator i = m_names.begin(); i != m_names.end(); ++i ) { - #ifdef _DEBUG globalErrorStream() << ">> " << i->first.c_str() << ": "; - #endif for ( PostFixes::postfixes_t::const_iterator j = i->second.m_postfixes.begin(); j != i->second.m_postfixes.end(); ++j ) { j->first.write( buf ); - #ifdef _DEBUG globalErrorStream() << " '" << buf << "'"; - #endif } - #ifdef _DEBUG globalErrorStream() << "\n"; - #endif } names_t::const_iterator i = m_names.find( name.first ); if ( i == m_names.end() ) { @@ -216,10 +209,18 @@ name_t make_unique( const name_t& name ) const { r = name_t( name.first, ( *i ).second.make_unique( name.second ) ); } name_write( buf, r ); - #ifdef _DEBUG globalErrorStream() << "> unique name is " << buf << "\n"; - #endif return r; +#else + names_t::const_iterator i = m_names.find( name.first ); + if ( i == m_names.end() ) { + return name; + } + else + { + return name_t( name.first, ( *i ).second.make_unique( name.second ) ); + } +#endif } void insert( const name_t& name ){ diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index a79a56cb..b81ab9c2 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -1227,7 +1227,7 @@ bool pre( const scene::Path& path, scene::Instance& instance ) const { && selectable->isSelected() ) { return false; } - if( m_makeUnique && instance.childSelected() ){ + if( m_makeUnique && instance.childSelected() ){ /* clone group entity primitives to new group entity */ NodeSmartReference clone( Node_Clone_Selected( path.top() ) ); Map_gatherNamespaced( clone ); Node_getTraversable( path.parent().get() )->insert( clone ); @@ -1251,9 +1251,7 @@ void post( const scene::Path& path, scene::Instance& instance ) const { if ( selectable != 0 && selectable->isSelected() ) { NodeSmartReference clone( Node_Clone( path.top() ) ); - if ( m_makeUnique ) { - Map_gatherNamespaced( clone ); - } + Map_gatherNamespaced( clone ); Node_getTraversable( path.parent().get() )->insert( clone ); } } @@ -1263,7 +1261,7 @@ void post( const scene::Path& path, scene::Instance& instance ) const { void Scene_Clone_Selected( scene::Graph& graph, bool makeUnique ){ graph.traverse( CloneSelected( makeUnique ) ); - Map_mergeClonedNames(); + Map_mergeClonedNames( makeUnique ); } enum ENudgeDirection diff --git a/radiant/map.cpp b/radiant/map.cpp index e9828d19..1070f2bf 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -240,12 +240,14 @@ void Map_gatherNamespaced( scene::Node& root ){ Node_traverseSubgraph( root, GatherNamespaced() ); } -void Map_mergeClonedNames(){ - for ( std::list::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i ) - { - ( *i )->setNamespace( g_cloneNamespace ); +void Map_mergeClonedNames( bool makeUnique /*= true*/ ){ + if( makeUnique ){ + for ( std::list::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i ) + { + ( *i )->setNamespace( g_cloneNamespace ); + } + g_cloneNamespace.mergeNames( g_defaultNamespace ); } - g_cloneNamespace.mergeNames( g_defaultNamespace ); for ( std::list::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i ) { ( *i )->setNamespace( g_defaultNamespace ); diff --git a/radiant/map.h b/radiant/map.h index e8abdfd1..2a2d0713 100644 --- a/radiant/map.h +++ b/radiant/map.h @@ -159,7 +159,7 @@ void Map_Destroy(); void Map_gatherNamespaced( scene::Node& root ); -void Map_mergeClonedNames(); +void Map_mergeClonedNames( bool makeUnique = true ); const char* getMapsPath();