2007-09-02 15:49:11 +00:00
|
|
|
/******************************************************/
|
2009-10-30 19:26:25 +00:00
|
|
|
/* Routines for locating an element of a schematic. */
|
2007-09-02 15:49:11 +00:00
|
|
|
/******************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "macros.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "general.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_marker.h"
|
2011-01-12 21:47:54 +00:00
|
|
|
#include "sch_junction.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_line.h"
|
|
|
|
#include "sch_no_connect.h"
|
|
|
|
#include "sch_polyline.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_sheet.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "lib_pin.h"
|
|
|
|
#include "template_fieldnames.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-24 19:22:15 +00:00
|
|
|
double area = 0.0; // Quiet compiler
|
2011-03-10 19:36:30 +00:00
|
|
|
EDA_Rect rect;
|
|
|
|
PICKED_ITEMS_LIST itemList;
|
|
|
|
SCH_COMPONENT* component = NULL;
|
|
|
|
SCH_COMPONENT* lastcomponent = NULL;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
if( Screen->GetItems( Screen->RefPos( true ), itemList, COMPONENT_T ) == 0 )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
if( Screen->GetItems( Screen->GetCrossHairPosition(), itemList, COMPONENT_T ) == 0 )
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
if( itemList.GetCount() == 1 )
|
|
|
|
return (SCH_COMPONENT*) itemList.GetPickedItem( 0 );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
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
|
|
|
{
|
2009-01-31 18:08:47 +00:00
|
|
|
lastcomponent = component;
|
2011-03-10 19:36:30 +00:00
|
|
|
rect = lastcomponent->GetBoundingBox();
|
|
|
|
area = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
rect = component->GetBoundingBox();
|
|
|
|
double tmp = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
if( area > tmp ) // a smaller component is found
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
area = tmp;
|
2009-01-31 18:08:47 +00:00
|
|
|
lastcomponent = component;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
return lastcomponent;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|