2009-11-14 22:15:22 +00:00
|
|
|
/*******************/
|
|
|
|
/* Locate element. */
|
|
|
|
/*******************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Locates a via point pX, pY
|
|
|
|
* If layer < 0 will be located via whatever layer
|
|
|
|
* If layer = 0 .. 15 Via will be located according to its type:
|
|
|
|
* - Traverse: all layers
|
|
|
|
* - = Blind between layers useful
|
|
|
|
* - Blind idem
|
|
|
|
* Entry: coord point of reference, layer
|
|
|
|
* Output: NULL if not via
|
|
|
|
* (* TRACK) address via
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
TRACK* Locate_Via( BOARD* Pcb, const wxPoint& pos, int layer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
TRACK* track;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
for( track = Pcb->m_Track; track; track = track->Next() )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->Type() != TYPE_VIA )
|
2007-08-03 18:59:14 +00:00
|
|
|
continue;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( track->m_Start != pos )
|
2007-08-03 18:59:14 +00:00
|
|
|
continue;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-02-13 17:53:48 +00:00
|
|
|
if( track->GetState( BUSY | IS_DELETED ) )
|
2007-08-03 18:59:14 +00:00
|
|
|
continue;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( layer < 0 )
|
2008-03-04 19:17:19 +00:00
|
|
|
break;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( track->IsOnLayer( layer ) )
|
|
|
|
break;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
return track;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
TRACK* Locate_Via_Area( TRACK* aStart, const wxPoint& pos, int layer )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
TRACK* track;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
for( track = aStart; track; track = track->Next() )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->Type() != TYPE_VIA )
|
2008-02-26 21:12:08 +00:00
|
|
|
continue;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( !track->HitTest(pos) )
|
2008-02-26 21:12:08 +00:00
|
|
|
continue;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-02-13 17:53:48 +00:00
|
|
|
if( track->GetState( BUSY | IS_DELETED ) )
|
2008-02-26 21:12:08 +00:00
|
|
|
continue;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2008-02-26 21:12:08 +00:00
|
|
|
if( layer < 0 )
|
2008-03-04 19:17:19 +00:00
|
|
|
break;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( track->IsOnLayer( layer ) )
|
|
|
|
break;
|
2008-02-26 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
return track;
|
2008-02-26 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 10:23:29 +00:00
|
|
|
/* Locate the pad CONNECTED to a track
|
2011-09-07 19:41:04 +00:00
|
|
|
* input: ptr_trace: pointer to the segment of track
|
2009-11-14 22:15:22 +00:00
|
|
|
* Extr = flag = START -> beginning of the test segment
|
|
|
|
* END -> end of the segment to be tested
|
|
|
|
* Returns:
|
|
|
|
* A pointer to the description of the pad if found.
|
|
|
|
* NULL pointer if pad NOT FOUND
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
D_PAD* Locate_Pad_Connecte( BOARD* Pcb, TRACK* ptr_trace, int extr )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
D_PAD* ptr_pad = NULL;
|
|
|
|
wxPoint ref_pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
int aLayerMask = g_TabOneLayerMask[ptr_trace->GetLayer()];
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( extr == START )
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
ref_pos = ptr_trace->m_Start;
|
2007-08-03 18:59:14 +00:00
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
else
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
ref_pos = ptr_trace->m_End;
|
2007-08-03 18:59:14 +00:00
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
for( MODULE* module = Pcb->m_Modules; module; module = module->Next() )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
ptr_pad = Locate_Pads( module, ref_pos, aLayerMask );
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( ptr_pad != NULL )
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
return ptr_pad;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-02-02 10:52:00 +00:00
|
|
|
* Locate a pad pointed to by the coordinates ref_pos.x, ref_pos.y
|
|
|
|
* aLayerMask is allowed layers ( bitmap mask)
|
2009-11-14 22:15:22 +00:00
|
|
|
* Returns:
|
2011-02-02 10:52:00 +00:00
|
|
|
* Pointer to a pad if found or NULL
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-02-01 15:46:25 +00:00
|
|
|
D_PAD* Locate_Any_Pad( BOARD* Pcb, const wxPoint& ref_pos, int aLayerMask )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-01 15:46:25 +00:00
|
|
|
D_PAD* pad = NULL;
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2011-02-02 10:52:00 +00:00
|
|
|
for( MODULE* module=Pcb->m_Modules; module && ( pad == NULL ); module = module->Next() )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2011-02-01 15:46:25 +00:00
|
|
|
if( aLayerMask )
|
|
|
|
pad = Locate_Pads( module, ref_pos, aLayerMask );
|
|
|
|
else
|
|
|
|
pad = Locate_Pads( module, ref_pos, ALL_LAYERS );
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
return pad;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-02 10:52:00 +00:00
|
|
|
/* Locate the pad pointed to by the coordinate ref_pos.x,, ref_pos.y
|
2009-11-14 22:15:22 +00:00
|
|
|
* Input:
|
2011-02-02 10:52:00 +00:00
|
|
|
* - the footprint to test
|
|
|
|
* - masque_layer layer(s) (bit_masque) which must be the pad
|
2009-11-14 22:15:22 +00:00
|
|
|
* Returns:
|
2011-02-02 10:52:00 +00:00
|
|
|
* A pointer to the pad if found or NULL
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
D_PAD* Locate_Pads( MODULE* module, const wxPoint& ref_pos, int aLayerMask )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-19 23:02:11 +00:00
|
|
|
for( D_PAD* pt_pad = module->m_Pads; pt_pad; pt_pad = pt_pad->Next() )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
/* ... and on the correct layer. */
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ( pt_pad->m_layerMask & aLayerMask ) == 0 )
|
2007-08-03 18:59:14 +00:00
|
|
|
continue;
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( pt_pad->HitTest( ref_pos ) )
|
|
|
|
return pt_pad;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2007-08-03 18:59:14 +00:00
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
/**
|
|
|
|
* Function Locate_Prefered_Module
|
|
|
|
* locates a footprint by its bounding rectangle. If several footprints
|
2009-11-14 22:15:22 +00:00
|
|
|
* are possible, then the priority is: the closest on the active layer, then
|
|
|
|
* closest.
|
2007-08-22 05:11:01 +00:00
|
|
|
* The current mouse or cursor coordinates are grabbed from the active window
|
2009-11-14 22:15:22 +00:00
|
|
|
* to perform hit-testing.
|
|
|
|
* distance is calculated via manhattan distance from the center of the
|
|
|
|
* bounding rectangle to the cursor position.
|
2007-08-22 05:11:01 +00:00
|
|
|
*
|
2011-02-01 15:46:25 +00:00
|
|
|
* @param aPcb The BOARD to search within.
|
|
|
|
* @param aPosition Flag bits, tuning the search, see pcbnew.h
|
|
|
|
* @param aActiveLayer Layer to test.
|
|
|
|
* @param aVisibleOnly Search only the visible layers if true.
|
2011-02-05 02:21:11 +00:00
|
|
|
* @param aIgnoreLocked Ignore locked modules when true.
|
2011-02-01 15:46:25 +00:00
|
|
|
* @return MODULE* The best module or NULL if none.
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-02-01 15:46:25 +00:00
|
|
|
MODULE* Locate_Prefered_Module( BOARD* aPcb, const wxPoint& aPosition, int aActiveLayer,
|
|
|
|
bool aVisibleOnly, bool aIgnoreLocked )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
MODULE* pt_module;
|
2009-11-14 22:15:22 +00:00
|
|
|
MODULE* module = NULL;
|
|
|
|
MODULE* Altmodule = NULL;
|
|
|
|
int min_dim = 0x7FFFFFFF;
|
|
|
|
int alt_min_dim = 0x7FFFFFFF;
|
|
|
|
int layer;
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
pt_module = aPcb->m_Modules;
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_module; pt_module = (MODULE*) pt_module->Next() )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
// is the ref point within the module's bounds?
|
2011-02-01 15:46:25 +00:00
|
|
|
if( !pt_module->HitTest( aPosition ) )
|
2007-06-15 16:08:55 +00:00
|
|
|
continue;
|
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
// if caller wants to ignore locked modules, and this one is locked, skip it.
|
|
|
|
if( aIgnoreLocked && pt_module->IsLocked() )
|
2007-06-15 16:08:55 +00:00
|
|
|
continue;
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate priority: the priority is given to the layer of the
|
|
|
|
* module and the copper layer if the module layer is indelible,
|
|
|
|
* adhesive copper, a layer if cmp module layer is indelible,
|
|
|
|
* adhesive component.
|
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
layer = pt_module->GetLayer();
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2009-12-21 17:56:25 +00:00
|
|
|
if( layer==ADHESIVE_N_BACK || layer==SILKSCREEN_N_BACK )
|
2009-12-07 03:46:13 +00:00
|
|
|
layer = LAYER_N_BACK;
|
2009-12-21 17:56:25 +00:00
|
|
|
else if( layer==ADHESIVE_N_FRONT || layer==SILKSCREEN_N_FRONT )
|
2009-12-07 03:46:13 +00:00
|
|
|
layer = LAYER_N_FRONT;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Test of minimum size to choosing the best candidate. */
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2011-09-01 21:39:38 +00:00
|
|
|
EDA_RECT bb = pt_module->GetFootPrintRect();
|
|
|
|
int offx = bb.GetX() + bb.GetWidth() / 2;
|
|
|
|
int offy = bb.GetY() + bb.GetHeight() / 2;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
//off x & offy point to the middle of the box.
|
2011-02-01 15:46:25 +00:00
|
|
|
int dist = abs( aPosition.x - offx ) + abs( aPosition.y - offy );
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
//int dist = MIN(lx, ly); // to pick the smallest module (kinda
|
|
|
|
// screwy with same-sized modules -- this is bad!)
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
if( aActiveLayer == layer )
|
2009-11-14 22:15:22 +00:00
|
|
|
{
|
|
|
|
if( dist <= min_dim )
|
|
|
|
{
|
|
|
|
/* better footprint shown on the active layer */
|
2008-03-04 04:22:27 +00:00
|
|
|
module = pt_module;
|
2008-02-12 21:12:46 +00:00
|
|
|
min_dim = dist;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-01 15:46:25 +00:00
|
|
|
else if( aVisibleOnly && aPcb->IsModuleLayerVisible( layer ) )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
if( dist <= alt_min_dim )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
/* better footprint shown on other layers */
|
2007-08-03 18:59:14 +00:00
|
|
|
Altmodule = pt_module;
|
2008-02-12 21:12:46 +00:00
|
|
|
alt_min_dim = dist;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Altmodule )
|
|
|
|
{
|
|
|
|
return Altmodule;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2007-10-16 19:05:33 +00:00
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* return true if the dist between p1 and p2 < max_dist
|
|
|
|
* Currently in test (currently rasnest algos work only if p1 == p2)
|
2007-10-16 19:05:33 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
inline bool IsPointsAreNear(wxPoint & p1, wxPoint & p2, int max_dist)
|
2007-10-16 19:05:33 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
#if 0 // Do not change it: does not work
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
2007-10-16 19:05:33 +00:00
|
|
|
int dist;
|
2008-03-04 04:22:27 +00:00
|
|
|
dist = abs(p1.x - p2.x) + abs (p1.y - p2.y);
|
|
|
|
dist *= 7;
|
|
|
|
dist /= 10;
|
|
|
|
if ( dist < max_dist ) return true;
|
2007-10-17 14:35:59 +00:00
|
|
|
}
|
2007-10-19 08:32:10 +00:00
|
|
|
#else
|
2008-03-04 04:22:27 +00:00
|
|
|
if ( p1 == p2 ) return true;
|
2007-10-19 08:32:10 +00:00
|
|
|
#endif
|
2008-03-04 04:22:27 +00:00
|
|
|
return false;
|
2007-10-16 19:05:33 +00:00
|
|
|
}
|
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
/**
|
|
|
|
* Search for the track (or via) segment which is connected to the track
|
2009-11-14 22:15:22 +00:00
|
|
|
* segment PtRefSegm
|
|
|
|
* if extr == START, the starting track segment PtRefSegm is used to locate
|
|
|
|
* a connected segment
|
2007-10-17 14:35:59 +00:00
|
|
|
* if extr == END, the ending track segment PtRefSegm is used
|
|
|
|
* The test connection consider only end track segments
|
2008-03-04 04:22:27 +00:00
|
|
|
*
|
2007-10-17 14:35:59 +00:00
|
|
|
* Search is made from pt_base to pt_lim (in the track linked list)
|
|
|
|
* if pt_lim == NULL, the search is made from pt_base to the end of list
|
|
|
|
*
|
|
|
|
* In order to have a fast computation time:
|
2009-11-14 22:15:22 +00:00
|
|
|
* a first search is made considering only the +/- 50 next door neighbor
|
|
|
|
* of PtRefSegm.
|
2007-10-17 14:35:59 +00:00
|
|
|
* if no track is found : the entire list is tested
|
|
|
|
*
|
|
|
|
* @param PtRefSegm = reference segment
|
|
|
|
* @param pt_base = lower limit for search
|
|
|
|
* @param pt_lim = upper limit for search (can be NULL)
|
|
|
|
* @param extr = START or END = end of ref track segment to use in tests
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
TRACK* GetConnectedTrace( TRACK* PtRefSegm, TRACK* pt_base, TRACK* pt_lim, int extr )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
const int NEIGHTBOUR_COUNT_MAX = 50;
|
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
TRACK* PtSegmB, * PtSegmN;
|
|
|
|
int Reflayer;
|
|
|
|
wxPoint pos_ref;
|
|
|
|
int ii;
|
2008-03-04 04:22:27 +00:00
|
|
|
int max_dist;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( extr == START )
|
|
|
|
pos_ref = PtRefSegm->m_Start;
|
|
|
|
else
|
|
|
|
pos_ref = PtRefSegm->m_End;
|
2007-06-15 16:08:55 +00:00
|
|
|
|
|
|
|
Reflayer = PtRefSegm->ReturnMaskLayer();
|
|
|
|
|
|
|
|
PtSegmB = PtSegmN = PtRefSegm;
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
for( ii = 0; ii < NEIGHTBOUR_COUNT_MAX; ii++ )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
|
|
|
if( (PtSegmN == NULL) && (PtSegmB == NULL) )
|
|
|
|
break;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-06-15 16:08:55 +00:00
|
|
|
if( PtSegmN )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( PtSegmN->GetState( BUSY | IS_DELETED ) )
|
2007-08-03 18:59:14 +00:00
|
|
|
goto suite;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegmN == PtRefSegm )
|
|
|
|
goto suite;
|
2007-10-16 19:05:33 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* max_dist is the max distance between 2 track ends which
|
|
|
|
* ensure a copper continuity */
|
2008-03-04 04:22:27 +00:00
|
|
|
max_dist = (PtSegmN->m_Width + PtRefSegm->m_Width)/2;
|
2007-10-16 19:05:33 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
if( IsPointsAreNear(pos_ref, PtSegmN->m_Start, max_dist) )
|
2009-11-14 22:15:22 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( Reflayer & PtSegmN->ReturnMaskLayer() )
|
|
|
|
return PtSegmN;
|
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
if( IsPointsAreNear(pos_ref, PtSegmN->m_End, max_dist) )
|
2009-11-14 22:15:22 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( Reflayer & PtSegmN->ReturnMaskLayer() )
|
|
|
|
return PtSegmN;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2007-08-03 18:59:14 +00:00
|
|
|
suite:
|
|
|
|
if( PtSegmN == pt_lim )
|
|
|
|
PtSegmN = NULL;
|
|
|
|
else
|
2008-11-24 06:53:43 +00:00
|
|
|
PtSegmN = PtSegmN->Next();
|
2007-08-03 18:59:14 +00:00
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
|
|
|
if( PtSegmB )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( PtSegmB->GetState( BUSY | IS_DELETED ) )
|
2007-08-03 18:59:14 +00:00
|
|
|
goto suite1;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegmB == PtRefSegm )
|
|
|
|
goto suite1;
|
2007-10-16 19:05:33 +00:00
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
max_dist = (PtSegmB->m_Width + PtRefSegm->m_Width)/2;
|
2007-10-16 19:05:33 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
if( IsPointsAreNear(pos_ref, PtSegmB->m_Start, max_dist) )
|
2009-11-14 22:15:22 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( Reflayer & PtSegmB->ReturnMaskLayer() )
|
|
|
|
return PtSegmB;
|
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
if( IsPointsAreNear(pos_ref, PtSegmB->m_End, max_dist) )
|
2009-11-14 22:15:22 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( Reflayer & PtSegmB->ReturnMaskLayer() )
|
|
|
|
return PtSegmB;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2007-08-03 18:59:14 +00:00
|
|
|
suite1:
|
|
|
|
if( PtSegmB == pt_base )
|
|
|
|
PtSegmB = NULL;
|
2008-12-04 04:28:11 +00:00
|
|
|
else if( PtSegmB->Type() != TYPE_PCB )
|
2008-11-24 06:53:43 +00:00
|
|
|
PtSegmB = PtSegmB->Back();
|
2007-08-03 18:59:14 +00:00
|
|
|
else
|
|
|
|
PtSegmB = NULL;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2007-08-03 18:59:14 +00:00
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* General search. */
|
2008-11-24 06:53:43 +00:00
|
|
|
for( PtSegmN = pt_base; PtSegmN != NULL; PtSegmN = PtSegmN->Next() )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( PtSegmN->GetState( IS_DELETED | BUSY ) )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegmN == pt_lim )
|
|
|
|
break;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-06-15 16:08:55 +00:00
|
|
|
continue;
|
2007-08-03 18:59:14 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegmN == PtRefSegm )
|
|
|
|
{
|
|
|
|
if( PtSegmN == pt_lim )
|
|
|
|
break;
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-06-15 16:08:55 +00:00
|
|
|
continue;
|
2007-08-03 18:59:14 +00:00
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
max_dist = ( PtSegmN->m_Width + PtRefSegm->m_Width ) / 2;
|
2007-10-16 19:05:33 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( IsPointsAreNear( pos_ref, PtSegmN->m_Start, max_dist ) )
|
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( Reflayer & PtSegmN->ReturnMaskLayer() )
|
|
|
|
return PtSegmN;
|
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( IsPointsAreNear( pos_ref, PtSegmN->m_End, max_dist ) )
|
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( Reflayer & PtSegmN->ReturnMaskLayer() )
|
|
|
|
return PtSegmN;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegmN == pt_lim )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* 1 - Locate segment of track leading from the mouse.
|
|
|
|
* 2 - Locate segment of track point by point
|
|
|
|
* ref_pos.x, ref_pos.y.r
|
2008-03-04 04:22:27 +00:00
|
|
|
*
|
2009-11-14 22:15:22 +00:00
|
|
|
* The search begins to address start_adresse
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
TRACK* GetTrace( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, int LayerMask )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
for( TRACK* track = start_adresse; track; track = track->Next() )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
int layer = track->GetLayer();
|
|
|
|
|
2011-02-13 17:53:48 +00:00
|
|
|
if( track->GetState( BUSY | IS_DELETED ) )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
// D( printf( "track %p is BUSY | IS_DELETED. BUSY=%d IS_DELETED=%d\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
// track, track->GetState( BUSY ),
|
2011-02-13 17:53:48 +00:00
|
|
|
// track->GetState( IS_DELETED ) );)
|
2007-08-03 18:59:14 +00:00
|
|
|
continue;
|
2008-12-04 04:28:11 +00:00
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( aPcb->GetBoardDesignSettings()->IsLayerVisible( layer ) == false )
|
2007-06-15 16:08:55 +00:00
|
|
|
continue;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( track->Type() == TYPE_VIA ) /* VIA encountered. */
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->HitTest( ref_pos ) )
|
|
|
|
return track;
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( (g_TabOneLayerMask[layer] & LayerMask) == 0 )
|
2009-11-14 22:15:22 +00:00
|
|
|
continue; /* Segments on different layers. */
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->HitTest( ref_pos ) )
|
|
|
|
return track;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* 1 - Locate zone area by the mouse.
|
|
|
|
* 2 - Locate zone area by point
|
|
|
|
* def_pos.x, ref_pos.y.r
|
2008-03-04 04:22:27 +00:00
|
|
|
*
|
2009-11-14 22:15:22 +00:00
|
|
|
* If layer == -1, tst layer is not
|
2008-03-04 04:22:27 +00:00
|
|
|
*
|
2009-11-14 22:15:22 +00:00
|
|
|
* The search begins to address start_adresse
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
|
|
|
TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
for( TRACK* Zone = start_adresse; Zone; Zone = Zone->Next() )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
if( (layer != -1) && (Zone->GetLayer() != layer) )
|
2007-08-03 18:59:14 +00:00
|
|
|
continue;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
if( Zone->HitTest( ref_pos ) )
|
2007-08-03 18:59:14 +00:00
|
|
|
return Zone;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Find the pad center px, py,
|
2011-09-07 19:41:04 +00:00
|
|
|
* The layer INDICATED BY aLayerMask (bitwise)
|
2009-11-14 22:15:22 +00:00
|
|
|
* (Runway end)
|
|
|
|
* The list of pads must already exist.
|
2008-03-04 04:22:27 +00:00
|
|
|
*
|
2009-11-14 22:15:22 +00:00
|
|
|
* Returns:
|
|
|
|
* NULL if no pad located.
|
|
|
|
* Pointer to the structure corresponding descr_pad if pad found
|
|
|
|
* (Good position and good layer).
|
2007-08-03 18:59:14 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int aLayerMask )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-06-06 18:08:49 +00:00
|
|
|
for( unsigned i=0; i<Pcb->GetPadsCount(); ++i )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
D_PAD* pad = Pcb->m_NetInfo->GetPad(i);
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( pad->m_Pos != ref_pos )
|
|
|
|
continue;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Pad found, it must be on the correct layer */
|
2011-09-07 19:41:04 +00:00
|
|
|
if( pad->m_layerMask & aLayerMask )
|
2007-08-03 18:59:14 +00:00
|
|
|
return pad;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Locate segment with one end that coincides with the point x, y
|
|
|
|
* Data on layers by masklayer
|
|
|
|
* Research is done to address start_adr has end_adr
|
|
|
|
* If end_adr = NULL, end search list
|
2011-02-13 17:53:48 +00:00
|
|
|
* The segments of track marks with the flag are not IS_DELETED or taken
|
2009-11-14 22:15:22 +00:00
|
|
|
* into account
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
TRACK* GetTrace( TRACK* start_adr, TRACK* end_adr, const wxPoint& ref_pos, int MaskLayer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
TRACK* PtSegm;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( start_adr == NULL )
|
|
|
|
return NULL;
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( PtSegm = start_adr; PtSegm != NULL; PtSegm = PtSegm->Next() )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( PtSegm->GetState( IS_DELETED | BUSY ) == 0 )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
|
|
|
if( ref_pos == PtSegm->m_Start )
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( MaskLayer & PtSegm->ReturnMaskLayer() )
|
|
|
|
return PtSegm;
|
|
|
|
}
|
2007-06-15 16:08:55 +00:00
|
|
|
|
|
|
|
if( ref_pos == PtSegm->m_End )
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( MaskLayer & PtSegm->ReturnMaskLayer() )
|
|
|
|
return PtSegm;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegm == end_adr )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Locates via through the point x, y, on layer data by masklayer.
|
|
|
|
* Search is done to address start_adr has end_adr.
|
|
|
|
* If end_adr = NULL, end search list
|
2011-02-13 17:53:48 +00:00
|
|
|
* Vias whose parameter has the State or IS_DELETED bit BUSY = 1 are ignored
|
2009-11-14 22:15:22 +00:00
|
|
|
*/
|
2011-02-01 15:46:25 +00:00
|
|
|
TRACK* Fast_Locate_Via( TRACK* start_adr, TRACK* end_adr, const wxPoint& pos, int MaskLayer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
TRACK* PtSegm;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( PtSegm = start_adr; PtSegm != NULL; PtSegm = PtSegm->Next() )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtSegm->Type() == TYPE_VIA )
|
2007-06-15 16:08:55 +00:00
|
|
|
{
|
|
|
|
if( pos == PtSegm->m_Start )
|
2007-08-03 18:59:14 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( PtSegm->GetState( BUSY | IS_DELETED ) == 0 )
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
2007-08-03 18:59:14 +00:00
|
|
|
if( MaskLayer & PtSegm->ReturnMaskLayer() )
|
|
|
|
return PtSegm;
|
2007-06-15 16:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-08-03 18:59:14 +00:00
|
|
|
if( PtSegm == end_adr )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|