Improved the algorithm for guessing the selection candidates

Now it filters out items that are bigger than the current viewport
This commit is contained in:
Maciej Suminski 2017-08-01 18:00:30 +02:00
parent efdf0c6b84
commit 30ad7e4f99
1 changed files with 12 additions and 10 deletions

View File

@ -1609,7 +1609,7 @@ static double calcArea( const BOARD_ITEM* aItem )
} }
static double calcMinArea( GENERAL_COLLECTOR& aCollector, KICAD_T aType ) /*static double calcMinArea( GENERAL_COLLECTOR& aCollector, KICAD_T aType )
{ {
double best = std::numeric_limits<double>::max(); double best = std::numeric_limits<double>::max();
@ -1624,7 +1624,7 @@ static double calcMinArea( GENERAL_COLLECTOR& aCollector, KICAD_T aType )
} }
return best; return best;
} }*/
static double calcMaxArea( GENERAL_COLLECTOR& aCollector, KICAD_T aType ) static double calcMaxArea( GENERAL_COLLECTOR& aCollector, KICAD_T aType )
@ -1754,18 +1754,20 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
if( aCollector.CountType( PCB_MODULE_T ) > 0 ) if( aCollector.CountType( PCB_MODULE_T ) > 0 )
{ {
double minArea = calcMinArea( aCollector, PCB_MODULE_T );
double maxArea = calcMaxArea( aCollector, PCB_MODULE_T ); double maxArea = calcMaxArea( aCollector, PCB_MODULE_T );
BOX2D viewportD = getView()->GetViewport();
BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
if( calcRatio( minArea, maxArea ) <= footprintAreaRatio )
{
for( int i = 0; i < aCollector.GetCount(); ++i ) for( int i = 0; i < aCollector.GetCount(); ++i )
{ {
if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) ) if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
{ {
double normalizedArea = calcRatio( calcArea( mod ), maxArea ); double normalizedArea = calcRatio( calcArea( mod ), maxArea );
if( normalizedArea > footprintAreaRatio ) if( normalizedArea > footprintAreaRatio
// filter out components larger than the viewport
|| mod->ViewBBox().Contains( viewport ) )
{
rejected.insert( mod ); rejected.insert( mod );
} }
} }