kicad/eeschema/locate.cpp

75 lines
2.0 KiB
C++
Raw Normal View History

2007-09-02 15:49:11 +00:00
/******************************************************/
/* Routines for locating an element of a schematic. */
2007-09-02 15:49:11 +00:00
/******************************************************/
#include "fctsys.h"
#include "common.h"
#include "trigo.h"
#include "macros.h"
#include "class_sch_screen.h"
#include "general.h"
#include "protos.h"
#include "class_library.h"
#include "sch_bus_entry.h"
#include "sch_marker.h"
#include "sch_junction.h"
#include "sch_component.h"
#include "sch_line.h"
#include "sch_no_connect.h"
#include "sch_polyline.h"
#include "sch_sheet.h"
#include "lib_pin.h"
#include "template_fieldnames.h"
/**
* Search the smaller (considering its area) component under the mouse
* cursor or the pcb cursor
*
* If more than 1 component is found, a pointer to the smaller component is
* returned
2007-09-02 15:49:11 +00:00
*/
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
{
double area;
EDA_Rect rect;
PICKED_ITEMS_LIST itemList;
SCH_COMPONENT* component = NULL;
SCH_COMPONENT* lastcomponent = NULL;
2007-09-02 15:49:11 +00:00
if( Screen->GetItems( Screen->RefPos( true ), itemList, COMPONENT_T ) == 0 )
2007-09-02 15:49:11 +00:00
{
if( Screen->GetItems( Screen->GetCrossHairPosition(), itemList, COMPONENT_T ) == 0 )
return NULL;
}
if( itemList.GetCount() == 1 )
return (SCH_COMPONENT*) itemList.GetPickedItem( 0 );
for( size_t i = 0; i < itemList.GetCount(); i++ )
{
component = (SCH_COMPONENT*) itemList.GetPickedItem( i );
if( lastcomponent == NULL ) // First component
2007-09-02 15:49:11 +00:00
{
lastcomponent = component;
rect = lastcomponent->GetBoundingBox();
area = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
2007-09-02 15:49:11 +00:00
}
else
{
rect = component->GetBoundingBox();
double tmp = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
if( area > tmp ) // a smaller component is found
2007-09-02 15:49:11 +00:00
{
area = tmp;
lastcomponent = component;
2007-09-02 15:49:11 +00:00
}
}
}
return lastcomponent;
}