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

View File

@ -253,6 +253,11 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
{ {
if( tree == NULL ) if( tree == NULL )
return; 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 // 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 // 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. // Now: sort all items according to match score, libraries first.
std::sort( nodes.begin(), nodes.end(), scoreComparator ); 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 // 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. // items is pretty complex, so we just re-build the whole tree.
tree->Freeze(); tree->Freeze();
@ -392,7 +401,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
if( node->Type == TREE_NODE::TYPE_ALIAS if( node->Type == TREE_NODE::TYPE_ALIAS
&& ( node->MatchScore > kLowestDefaultScore || libraries_added == 1 ) ) && ( node->MatchScore > kLowestDefaultScore || libraries_added == 1 ) )
{ {
tree->EnsureVisible( node->TreeId ); tree->Expand( node->TreeId );
if( first_match == NULL ) if( first_match == NULL )
first_match = node; // First, highest scoring: the "I am feeling lucky" element. 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. if( first_match ) // Highest score search match pre-selected.
{
tree->SelectItem( first_match->TreeId ); tree->SelectItem( first_match->TreeId );
tree->EnsureVisible( first_match->TreeId );
}
else if( preselected_node ) // No search, so history item preselected. else if( preselected_node ) // No search, so history item preselected.
{
tree->SelectItem( preselected_node->TreeId ); tree->SelectItem( preselected_node->TreeId );
tree->EnsureVisible( preselected_node->TreeId );
}
tree->Thaw(); 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
} }