Eeschema, select component dialog: speed up (up to 20 to 30 times) the tree rebuild process, when the filter is used.

3d_draw_helper_functions.cpp: minor cleanup, and fix a very minor issue in 3D grid.
This commit is contained in:
jean-pierre charras 2015-06-20 11:19:57 +02:00
parent bea46ddde3
commit fe7bc2784a
2 changed files with 39 additions and 13 deletions

View File

@ -221,8 +221,8 @@ void EDA_3D_CANVAS::draw3DGrid( double aGriSizeMM )
wxPoint brd_center_pos = getBoardCenter();
NEGATE( brd_center_pos.y );
int xsize = std::max( brd_size.x, Millimeter2iu( 100 ) );
int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) );
int xsize = std::max( brd_size.x, Millimeter2iu( 100 ) ) * 1.2;
int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) ) * 1.2;
// Grid limits, in 3D units
double xmin = (brd_center_pos.x - xsize / 2) * scale;
@ -278,10 +278,12 @@ void EDA_3D_CANVAS::draw3DGrid( double aGriSizeMM )
break;
}
// Draw vertical grid n Z axis
// Draw vertical grid on Z axis
glNormal3f( 0.0, -1.0, 0.0 );
// Draw vertical grid lines (parallel to Z axis)
double posy = -brd_center_pos.y * scale;
for( int ii = 0; ; ii++ )
{
if( (ii % 5) )
@ -292,15 +294,18 @@ void EDA_3D_CANVAS::draw3DGrid( double aGriSizeMM )
double delta = ii * aGriSizeMM * IU_PER_MM;
glBegin( GL_LINES );
glVertex3f( (brd_center_pos.x + delta) * scale, -brd_center_pos.y * scale, zmin );
glVertex3f( (brd_center_pos.x + delta) * scale, -brd_center_pos.y * scale, zmax );
xmax = (brd_center_pos.x + delta) * scale;
glVertex3f( xmax, posy, zmin );
glVertex3f( xmax, posy, zmax );
glEnd();
if( ii != 0 )
{
glBegin( GL_LINES );
glVertex3f( (brd_center_pos.x - delta) * scale, -brd_center_pos.y * scale, zmin );
glVertex3f( (brd_center_pos.x - delta) * scale, -brd_center_pos.y * scale, zmax );
xmin = (brd_center_pos.x - delta) * scale;
glVertex3f( xmin, posy, zmin );
glVertex3f( xmin, posy, zmax );
glEnd();
}
@ -308,7 +313,7 @@ void EDA_3D_CANVAS::draw3DGrid( double aGriSizeMM )
break;
}
// Draw horizontal grid lines on Z axis
// Draw horizontal grid lines on Z axis (parallel to X axis)
for( int ii = 0; ; ii++ )
{
if( (ii % 5) )
@ -322,8 +327,8 @@ void EDA_3D_CANVAS::draw3DGrid( double aGriSizeMM )
{
// Draw grid lines on Z axis (positive Z axis coordinates)
glBegin( GL_LINES );
glVertex3f( xmin, -brd_center_pos.y * scale, delta );
glVertex3f( xmax, -brd_center_pos.y * scale, delta );
glVertex3f( xmin, posy, delta );
glVertex3f( xmax, posy, delta );
glEnd();
}
@ -331,8 +336,8 @@ void EDA_3D_CANVAS::draw3DGrid( double aGriSizeMM )
{
// Draw grid lines on Z axis (negative Z axis coordinates)
glBegin( GL_LINES );
glVertex3f( xmin, -brd_center_pos.y * scale, -delta );
glVertex3f( xmax, -brd_center_pos.y * scale, -delta );
glVertex3f( xmin, posy, -delta );
glVertex3f( xmax, posy, -delta );
glEnd();
}

View File

@ -253,6 +253,11 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
{
if( tree == NULL )
return;
//#define SHOW_CALC_TIME // uncomment this to show calculation time
#ifdef SHOW_CALC_TIME
unsigned starttime = GetRunningMicroSecs();
#endif
// We score the list by going through it several time, essentially with a complexity
// of O(n). For the default library of 2000+ items, this typically takes less than 5ms
@ -354,6 +359,10 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
// Now: sort all items according to match score, libraries first.
std::sort( nodes.begin(), nodes.end(), scoreComparator );
#ifdef SHOW_CALC_TIME
unsigned sorttime = GetRunningMicroSecs();
#endif
// Fill the tree with all items that have a match. Re-arranging, adding and removing changed
// items is pretty complex, so we just re-build the whole tree.
tree->Freeze();
@ -392,7 +401,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
if( node->Type == TREE_NODE::TYPE_ALIAS
&& ( node->MatchScore > kLowestDefaultScore || libraries_added == 1 ) )
{
tree->EnsureVisible( node->TreeId );
tree->Expand( node->TreeId );
if( first_match == NULL )
first_match = node; // First, highest scoring: the "I am feeling lucky" element.
@ -414,9 +423,21 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
}
if( first_match ) // Highest score search match pre-selected.
{
tree->SelectItem( first_match->TreeId );
tree->EnsureVisible( first_match->TreeId );
}
else if( preselected_node ) // No search, so history item preselected.
{
tree->SelectItem( preselected_node->TreeId );
tree->EnsureVisible( preselected_node->TreeId );
}
tree->Thaw();
#ifdef SHOW_CALC_TIME
unsigned endtime = GetRunningMicroSecs();
wxLogMessage( wxT("sort components %.1f ms, rebuild tree %.1f ms"),
double(sorttime-starttime)/1000.0, double(endtime-sorttime)/1000.0 );
#endif
}