* 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)
This commit is contained in:
Garux 2018-07-27 20:21:42 +03:00
parent cc997fd5a1
commit 461410f1a9
4 changed files with 22 additions and 21 deletions

View File

@ -184,28 +184,21 @@ typedef std::map<CopiedString, PostFixes> names_t;
names_t m_names; names_t m_names;
public: public:
name_t make_unique( const name_t& name ) const { name_t make_unique( const name_t& name ) const {
#if 0 //debug
char buf[80]; char buf[80];
name_t r( "","" ); name_t r( "","" );
name_write( buf, name ); name_write( buf, name );
#ifdef _DEBUG
globalErrorStream() << "find unique name for " << buf << "\n"; globalErrorStream() << "find unique name for " << buf << "\n";
globalErrorStream() << "> currently registered names:\n"; globalErrorStream() << "> currently registered names:\n";
#endif
for ( names_t::const_iterator i = m_names.begin(); i != m_names.end(); ++i ) for ( names_t::const_iterator i = m_names.begin(); i != m_names.end(); ++i )
{ {
#ifdef _DEBUG
globalErrorStream() << ">> " << i->first.c_str() << ": "; 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 ) for ( PostFixes::postfixes_t::const_iterator j = i->second.m_postfixes.begin(); j != i->second.m_postfixes.end(); ++j )
{ {
j->first.write( buf ); j->first.write( buf );
#ifdef _DEBUG
globalErrorStream() << " '" << buf << "'"; globalErrorStream() << " '" << buf << "'";
#endif
} }
#ifdef _DEBUG
globalErrorStream() << "\n"; globalErrorStream() << "\n";
#endif
} }
names_t::const_iterator i = m_names.find( name.first ); names_t::const_iterator i = m_names.find( name.first );
if ( i == m_names.end() ) { 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 ) ); r = name_t( name.first, ( *i ).second.make_unique( name.second ) );
} }
name_write( buf, r ); name_write( buf, r );
#ifdef _DEBUG
globalErrorStream() << "> unique name is " << buf << "\n"; globalErrorStream() << "> unique name is " << buf << "\n";
#endif
return r; 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 ){ void insert( const name_t& name ){

View File

@ -1227,7 +1227,7 @@ bool pre( const scene::Path& path, scene::Instance& instance ) const {
&& selectable->isSelected() ) { && selectable->isSelected() ) {
return false; 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() ) ); NodeSmartReference clone( Node_Clone_Selected( path.top() ) );
Map_gatherNamespaced( clone ); Map_gatherNamespaced( clone );
Node_getTraversable( path.parent().get() )->insert( 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 if ( selectable != 0
&& selectable->isSelected() ) { && selectable->isSelected() ) {
NodeSmartReference clone( Node_Clone( path.top() ) ); NodeSmartReference clone( Node_Clone( path.top() ) );
if ( m_makeUnique ) {
Map_gatherNamespaced( clone ); Map_gatherNamespaced( clone );
}
Node_getTraversable( path.parent().get() )->insert( 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 ){ void Scene_Clone_Selected( scene::Graph& graph, bool makeUnique ){
graph.traverse( CloneSelected( makeUnique ) ); graph.traverse( CloneSelected( makeUnique ) );
Map_mergeClonedNames(); Map_mergeClonedNames( makeUnique );
} }
enum ENudgeDirection enum ENudgeDirection

View File

@ -240,12 +240,14 @@ void Map_gatherNamespaced( scene::Node& root ){
Node_traverseSubgraph( root, GatherNamespaced() ); Node_traverseSubgraph( root, GatherNamespaced() );
} }
void Map_mergeClonedNames(){ void Map_mergeClonedNames( bool makeUnique /*= true*/ ){
if( makeUnique ){
for ( std::list<Namespaced*>::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i ) for ( std::list<Namespaced*>::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i )
{ {
( *i )->setNamespace( g_cloneNamespace ); ( *i )->setNamespace( g_cloneNamespace );
} }
g_cloneNamespace.mergeNames( g_defaultNamespace ); g_cloneNamespace.mergeNames( g_defaultNamespace );
}
for ( std::list<Namespaced*>::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i ) for ( std::list<Namespaced*>::const_iterator i = g_cloned.begin(); i != g_cloned.end(); ++i )
{ {
( *i )->setNamespace( g_defaultNamespace ); ( *i )->setNamespace( g_defaultNamespace );

View File

@ -159,7 +159,7 @@ void Map_Destroy();
void Map_gatherNamespaced( scene::Node& root ); void Map_gatherNamespaced( scene::Node& root );
void Map_mergeClonedNames(); void Map_mergeClonedNames( bool makeUnique = true );
const char* getMapsPath(); const char* getMapsPath();