kicad/eeschema/dangling_ends.cpp

85 lines
2.4 KiB
C++
Raw Normal View History

/*********************/
/* dangling_ends.cpp */
/*********************/
#include "fctsys.h"
#include "gr_basic.h"
#include "sch_item_struct.h"
#include "wxEeschemaStruct.h"
#include "general.h"
#include "protos.h"
#include "class_libentry.h"
#include "lib_pin.h"
#include "sch_component.h"
2010-07-17 11:14:57 +00:00
/* Returns true if the point P is on the segment S. */
bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint )
{
wxPoint vectSeg = aSegEnd - aSegStart; // Vector from S1 to S2
2010-07-17 11:14:57 +00:00
wxPoint vectPoint = aTestPoint - aSegStart; // Vector from S1 to P
2008-04-22 16:38:23 +00:00
2010-07-17 11:14:57 +00:00
// Use long long here to avoid overflow in calculations
if( (long long) vectSeg.x * vectPoint.y - (long long) vectSeg.y * vectPoint.x )
2010-07-17 11:14:57 +00:00
return false; /* Cross product non-zero, vectors not parallel */
2008-04-22 16:38:23 +00:00
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
2010-07-17 11:14:57 +00:00
return false; /* Point not on segment */
2008-04-22 16:38:23 +00:00
2010-07-17 11:14:57 +00:00
return true;
}
void SCH_EDIT_FRAME::TestDanglingEnds( SCH_ITEM* aDrawList, wxDC* aDC )
{
SCH_ITEM* item;
std::vector< DANGLING_END_ITEM > endPoints;
for( item = aDrawList; item != NULL; item = item->Next() )
item->GetEndPoints( endPoints );
for( item = aDrawList; item; item = item->Next() )
{
if( item->IsDanglingStateChanged( endPoints ) && aDC != NULL )
{
RedrawOneStruct( DrawPanel, aDC, item, g_XorMode );
RedrawOneStruct( DrawPanel, aDC, item, GR_DEFAULT_DRAWMODE );
}
}
}
/**
* Test if point pos is on a pin end.
*
* @param DrawList = List of SCH_ITEMs to check.
2010-02-01 08:19:31 +00:00
* @return a LIB_PIN pointer to the located pin or NULL if no pin was found.
*/
LIB_PIN* SCH_EDIT_FRAME::LocatePinEnd( SCH_ITEM* DrawList, const wxPoint& pos )
{
2008-03-20 01:50:21 +00:00
SCH_COMPONENT* DrawLibItem;
LIB_PIN* Pin;
wxPoint pinpos;
Pin = LocateAnyPin( DrawList, pos, &DrawLibItem );
if( !Pin )
return NULL;
pinpos = Pin->GetPosition();
if( DrawLibItem == NULL )
2010-02-01 08:19:31 +00:00
NEGATE( pinpos.y ); // In libraries Y axis is bottom to top
// and in schematic Y axis is top to bottom
2010-07-17 11:14:57 +00:00
else // calculate the pin position in schematic
pinpos = DrawLibItem->m_Transform.TransformCoordinate( pinpos ) + DrawLibItem->m_Pos;
2009-01-02 13:19:34 +00:00
if( pos == pinpos )
return Pin;
return NULL;
}