Speed up SCH_COMPONENT::ResolveAll().
This commit is contained in:
parent
a592832886
commit
2a91d7bc21
|
@ -285,17 +285,54 @@ bool SCH_COMPONENT::Resolve( PART_LIBS* aLibs )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper sort function, used in SCH_COMPONENT::ResolveAll, to sort
|
||||||
|
// sch component by lib_id
|
||||||
|
static bool sort_by_libid( const SCH_COMPONENT* ref, SCH_COMPONENT* cmp )
|
||||||
|
{
|
||||||
|
return ref->GetLibId() < cmp->GetLibId();
|
||||||
|
}
|
||||||
|
|
||||||
void SCH_COMPONENT::ResolveAll(
|
void SCH_COMPONENT::ResolveAll(
|
||||||
const SCH_COLLECTOR& aComponents, PART_LIBS* aLibs )
|
const SCH_COLLECTOR& aComponents, PART_LIBS* aLibs )
|
||||||
{
|
{
|
||||||
|
// Usually, many components use the same part lib.
|
||||||
|
// to avoid too long calculation time the list of components is grouped
|
||||||
|
// and once the lib part is found for one member of a group, it is also
|
||||||
|
// set for all other members of this group
|
||||||
|
std::vector<SCH_COMPONENT*> cmp_list;
|
||||||
|
|
||||||
|
// build the cmp list.
|
||||||
for( int i = 0; i < aComponents.GetCount(); ++i )
|
for( int i = 0; i < aComponents.GetCount(); ++i )
|
||||||
{
|
{
|
||||||
SCH_COMPONENT* cmp = dynamic_cast<SCH_COMPONENT*>( aComponents[i] );
|
SCH_COMPONENT* cmp = dynamic_cast<SCH_COMPONENT*>( aComponents[i] );
|
||||||
wxASSERT( cmp );
|
wxASSERT( cmp );
|
||||||
|
|
||||||
if( cmp ) // cmp == NULL should not occur.
|
if( cmp ) // cmp == NULL should not occur.
|
||||||
cmp->Resolve( aLibs );
|
cmp_list.push_back( cmp );
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort it by lib part. Cmp will be grouped by same lib part.
|
||||||
|
std::sort( cmp_list.begin(), cmp_list.end(), sort_by_libid );
|
||||||
|
|
||||||
|
LIB_ID curr_libid;
|
||||||
|
|
||||||
|
for( unsigned ii = 0; ii < cmp_list.size (); ++ii )
|
||||||
|
{
|
||||||
|
SCH_COMPONENT* cmp = cmp_list[ii];
|
||||||
|
curr_libid = cmp->m_lib_id;
|
||||||
|
cmp->Resolve( aLibs );
|
||||||
|
|
||||||
|
// Propagate the m_part pointer to other members using the same lib_id
|
||||||
|
for( unsigned jj = ii+1; jj < cmp_list.size (); ++jj )
|
||||||
|
{
|
||||||
|
SCH_COMPONENT* next_cmp = cmp_list[jj];
|
||||||
|
|
||||||
|
if( curr_libid != next_cmp->m_lib_id )
|
||||||
|
break;
|
||||||
|
|
||||||
|
next_cmp->m_part = cmp->m_part;
|
||||||
|
ii = jj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue