2007-08-24 15:10:46 +00:00
|
|
|
/*********************/
|
|
|
|
/* dangling_ends.cpp */
|
|
|
|
/*********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "sch_item_struct.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-11-03 14:13:15 +00:00
|
|
|
#include "class_libentry.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
|
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 )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
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
|
2010-09-05 17:01:48 +00:00
|
|
|
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
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
|
2010-11-03 14:13:15 +00:00
|
|
|
( (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;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::TestDanglingEnds( SCH_ITEM* aDrawList, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
SCH_ITEM* item;
|
|
|
|
std::vector< DANGLING_END_ITEM > endPoints;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
for( item = aDrawList; item != NULL; item = item->Next() )
|
|
|
|
item->GetEndPoints( endPoints );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
for( item = aDrawList; item; item = item->Next() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
if( item->IsDanglingStateChanged( endPoints ) && aDC != NULL )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
RedrawOneStruct( DrawPanel, aDC, item, g_XorMode );
|
|
|
|
RedrawOneStruct( DrawPanel, aDC, item, GR_DEFAULT_DRAWMODE );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
/**
|
|
|
|
* Test if point pos is on a pin end.
|
|
|
|
*
|
|
|
|
* @param DrawList = List of SCH_ITEMs to check.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param pos - Position of pin end to locate.
|
2010-02-01 08:19:31 +00:00
|
|
|
* @return a LIB_PIN pointer to the located pin or NULL if no pin was found.
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
LIB_PIN* SCH_EDIT_FRAME::LocatePinEnd( SCH_ITEM* DrawList, const wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* DrawLibItem;
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_PIN* Pin;
|
2007-08-24 15:10:46 +00:00
|
|
|
wxPoint pinpos;
|
|
|
|
|
|
|
|
Pin = LocateAnyPin( DrawList, pos, &DrawLibItem );
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
if( !Pin )
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
pinpos = Pin->GetPosition();
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
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
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
else // calculate the pin position in schematic
|
2010-12-14 21:39:31 +00:00
|
|
|
pinpos = DrawLibItem->GetTransform().TransformCoordinate( pinpos ) + DrawLibItem->m_Pos;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
if( pos == pinpos )
|
2007-08-24 15:10:46 +00:00
|
|
|
return Pin;
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|