Commit 6b222d19 authored by Maciej Suminski's avatar Maciej Suminski

Added preference for selecting tracks/vias/graphics if there is a module...

Added preference for selecting tracks/vias/graphics if there is a module present in the selection point.
parent 7fd9fc49
...@@ -227,6 +227,7 @@ bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambigua ...@@ -227,6 +227,7 @@ bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambigua
BOARD_ITEM* item; BOARD_ITEM* item;
GENERAL_COLLECTORS_GUIDE guide = getEditFrame<PCB_EDIT_FRAME>()->GetCollectorsGuide(); GENERAL_COLLECTORS_GUIDE guide = getEditFrame<PCB_EDIT_FRAME>()->GetCollectorsGuide();
GENERAL_COLLECTOR collector; GENERAL_COLLECTOR collector;
const KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_LINE_T, EOT }; // preferred types
collector.Collect( pcb, GENERAL_COLLECTOR::AllBoardItems, collector.Collect( pcb, GENERAL_COLLECTOR::AllBoardItems,
wxPoint( aWhere.x, aWhere.y ), guide ); wxPoint( aWhere.x, aWhere.y ), guide );
...@@ -252,6 +253,14 @@ bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambigua ...@@ -252,6 +253,14 @@ bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambigua
collector.Remove( i ); collector.Remove( i );
} }
// Check if among the selection candidates there is only one instance of preferred type
if( item = prefer( collector, types ) )
{
toggleSelection( item );
return true;
}
// Let's see if there is still disambiguation in selection.. // Let's see if there is still disambiguation in selection..
if( collector.GetCount() == 1 ) if( collector.GetCount() == 1 )
{ {
...@@ -681,6 +690,38 @@ void SELECTION_TOOL::highlightNet( const VECTOR2I& aPoint ) ...@@ -681,6 +690,38 @@ void SELECTION_TOOL::highlightNet( const VECTOR2I& aPoint )
} }
BOARD_ITEM* SELECTION_TOOL::prefer( GENERAL_COLLECTOR& aCollector, const KICAD_T aTypes[] ) const
{
BOARD_ITEM* preferred = NULL;
int typesNr = 0;
while( aTypes[typesNr++] != EOT ); // count number of types, excluding the sentinel (EOT)
for( int i = 0; i < aCollector.GetCount(); ++i )
{
KICAD_T type = aCollector[i]->Type();
for( int j = 0; j < typesNr - 1; ++j ) // Check if the item's type is in our list
{
if( aTypes[j] == type )
{
if( preferred == NULL )
{
preferred = aCollector[i]; // save the first matching item
break;
}
else
{
return NULL; // there is more than one preferred item, so there is no clear choice
}
}
}
}
return preferred;
}
void SELECTION_TOOL::SELECTION::clear() void SELECTION_TOOL::SELECTION::clear()
{ {
items.ClearItemsList(); items.ClearItemsList();
......
...@@ -229,6 +229,16 @@ private: ...@@ -229,6 +229,16 @@ private:
*/ */
void highlightNet( const VECTOR2I& aPoint ); void highlightNet( const VECTOR2I& aPoint );
/**
* Function prefer()
* Checks if collector's list contains only single entry of asked types. If so, it returns it.
* @param aCollector is the collector that has a list of items to be queried.
* @param aTypes is the list of searched/preferred types.
* @return Pointer to the preferred item, if there is only one entry of given type or NULL
* if there are more entries or no entries at all.
*/
BOARD_ITEM* prefer( GENERAL_COLLECTOR& aCollector, const KICAD_T aTypes[] ) const;
/// Visual representation of selection box /// Visual representation of selection box
SELECTION_AREA* m_selArea; SELECTION_AREA* m_selArea;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment