kicad/pcbnew/locate.cpp

681 lines
21 KiB
C++
Raw Normal View History

2007-08-03 18:59:14 +00:00
/*****************************/
/* Localisation des elements */
/*****************************/
#include "fctsys.h"
#include "common.h"
#include "pcbnew.h"
#include "protos.h"
2008-03-04 04:22:27 +00:00
/**
* Function RefPos
* returns the reference position, coming from either the mouse position or the
2008-03-04 04:22:27 +00:00
* the cursor position, based on whether the typeloc has the CURSEUR_OFF_GRILLE
* flag ORed in or not.
* @param typeloc int with possible CURSEUR_OFF_GRILLE bit on.
2008-03-04 04:22:27 +00:00
* @return wxPoint - The reference point, either the mouse position or
* the cursor position.
2007-08-03 18:59:14 +00:00
*/
wxPoint inline RefPos( int typeloc )
{
2007-08-08 03:50:44 +00:00
return ActiveScreen->RefPos( (typeloc & CURSEUR_OFF_GRILLE) != 0 );
}
2007-08-03 18:59:14 +00:00
/*******************************************************************/
2007-08-03 18:59:14 +00:00
TRACK* Locate_Via( BOARD* Pcb, const wxPoint& pos, int layer )
/*******************************************************************/
/* Localise une via au point pX,pY
2007-08-03 18:59:14 +00:00
* Si layer < 0 la via sera localisee quelle que soit la couche
* Si layer = 0 .. 15 la via sera localisee selon son type:
* - traversante : toutes couches
* - aveugle = entre couches utiles
* - borgnes idem
* Entree : coord du point de reference, couche
* Sortie: NULL si pas de via
* (TRACK*) adresse de la via
*/
{
2008-03-04 19:17:19 +00:00
TRACK* track;
2008-03-04 19:17:19 +00:00
for( track = Pcb->m_Track; track; track = track->Next() )
{
if( track->Type() != TYPE_VIA )
2007-08-03 18:59:14 +00:00
continue;
2008-03-04 19:17:19 +00:00
if( track->m_Start != pos )
2007-08-03 18:59:14 +00:00
continue;
2008-03-04 19:17:19 +00:00
if( track->GetState( BUSY | DELETED ) )
2007-08-03 18:59:14 +00:00
continue;
if( layer < 0 )
2008-03-04 19:17:19 +00:00
break;
if( track->IsOnLayer( layer ) )
break;
}
2007-08-03 18:59:14 +00:00
2008-03-04 19:17:19 +00:00
return track;
}
2008-02-26 21:12:08 +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
{
if( track->Type() != TYPE_VIA )
2008-02-26 21:12:08 +00:00
continue;
2008-03-04 19:17:19 +00:00
if( !track->HitTest(pos) )
2008-02-26 21:12:08 +00:00
continue;
2008-03-04 19:17:19 +00:00
if( track->GetState( BUSY | DELETED ) )
2008-02-26 21:12:08 +00:00
continue;
if( layer < 0 )
2008-03-04 19:17:19 +00:00
break;
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
}
/********************************************************************/
2007-08-03 18:59:14 +00:00
D_PAD* Locate_Pad_Connecte( BOARD* Pcb, TRACK* ptr_piste, int extr )
/********************************************************************/
2007-08-03 18:59:14 +00:00
/* localisation de la pastille connectee au point de piste a tester
2007-08-03 18:59:14 +00:00
* entree : ptr_piste: pointeur sur le segment de piste
* extr = flag = START -> debut du segment a tester
* = END -> fin du segment a tester
* retourne:
* un pointeur sur la description de la pastille si localisation
* pointeur NULL si pastille non trouvee
*/
{
2007-08-03 18:59:14 +00:00
D_PAD* ptr_pad = NULL;
wxPoint ref_pos;
2007-10-19 23:02:11 +00:00
int masque_layer = g_TabOneLayerMask[ptr_piste->GetLayer()];
2008-03-04 04:22:27 +00:00
2007-08-03 18:59:14 +00:00
if( extr == START )
{
ref_pos = ptr_piste->m_Start;
2007-08-03 18:59:14 +00:00
}
else
2007-08-03 18:59:14 +00:00
{
ref_pos = ptr_piste->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
{
ptr_pad = Locate_Pads( module, ref_pos, masque_layer );
if( ptr_pad != NULL )
break;
}
2007-08-03 18:59:14 +00:00
return ptr_pad;
}
2007-08-10 19:14:51 +00:00
/*************************************************
2007-08-23 04:28:46 +00:00
* D_PAD * Locate_Any_Pad( BOARD* Pcb, int typeloc, bool OnlyCurrentLayer)
* D_PAD* Locate_Any_Pad( BOARD* Pcb, int ref_pos, bool OnlyCurrentLayer)
2007-08-10 19:14:51 +00:00
*************************************************/
/*
2007-08-03 18:59:14 +00:00
* localisation de la pastille pointee par la coordonnee ref_pos.x,,ref_pos.y, ou
* par la souris, recherche faite sur toutes les empreintes.
* entree :
* - coord souris
* ou ref_pos
* retourne:
* pointeur sur la description de la pastille si localisation
* pointeur NULL si pastille non trouvee
* num_empr = numero d'empreinte du pad
2008-03-04 04:22:27 +00:00
*
* la priorit<EFBFBD> est donn<EFBFBD>e a la couche active
2007-08-03 18:59:14 +00:00
*/
D_PAD* Locate_Any_Pad( BOARD* Pcb, int typeloc, bool OnlyCurrentLayer )
{
wxPoint ref_pos = RefPos( typeloc );
2007-08-03 18:59:14 +00:00
return Locate_Any_Pad( Pcb, ref_pos, OnlyCurrentLayer );
}
2007-08-03 18:59:14 +00:00
D_PAD* Locate_Any_Pad( BOARD* Pcb, const wxPoint& ref_pos, bool OnlyCurrentLayer )
{
2007-08-03 18:59:14 +00:00
int layer_mask = g_TabOneLayerMask[ ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer];
2007-10-19 23:02:11 +00:00
for( MODULE* module=Pcb->m_Modules; module; module = module->Next() )
{
2007-10-19 23:02:11 +00:00
D_PAD* pt_pad;
2008-03-04 04:22:27 +00:00
/* First: Search a pad on the active layer: */
2007-08-03 18:59:14 +00:00
if( ( pt_pad = Locate_Pads( module, ref_pos, layer_mask ) ) != NULL )
return pt_pad;
2007-08-03 18:59:14 +00:00
/* If not found, search on other layers: */
if( !OnlyCurrentLayer )
{
2007-08-03 18:59:14 +00:00
if( ( pt_pad = Locate_Pads( module, ref_pos, ALL_LAYERS ) ) != NULL )
return pt_pad;
}
}
2007-08-03 18:59:14 +00:00
return NULL;
}
/******************************************************************************/
/* D_PAD* Locate_Pads(MODULE * module, int masque_layer,int typeloc) */
/* D_PAD* Locate_Pads(MODULE * module, const wxPoint & ref_pos,int masque_layer) */
/******************************************************************************/
/* localisation de la pastille pointee par la coordonnee ref_pos.x,,ref_pos.y, ou
2007-08-03 18:59:14 +00:00
* par la souris, concernant l'empreinte en cours.
* entree :
* - parametres generaux de l'empreinte mise a jour par caract()
* - masque_layer = couche(s) (bit_masque)sur laquelle doit etre la pastille
* retourne:
* un pointeur sur la description de la pastille si localisation
* pointeur NULL si pastille non trouvee
*/
D_PAD* Locate_Pads( MODULE* module, int masque_layer, int typeloc )
{
wxPoint ref_pos = RefPos( typeloc );
2007-08-03 18:59:14 +00:00
return Locate_Pads( module, ref_pos, masque_layer );
}
2007-08-03 18:59:14 +00:00
D_PAD* Locate_Pads( MODULE* module, const wxPoint& ref_pos, int masque_layer )
{
2007-10-19 23:02:11 +00:00
for( D_PAD* pt_pad = module->m_Pads; pt_pad; pt_pad = pt_pad->Next() )
{
/* ... et sur la bonne couche */
2007-08-03 18:59:14 +00:00
if( (pt_pad->m_Masque_Layer & masque_layer) == 0 )
continue;
2007-08-08 03:50:44 +00:00
if( pt_pad->HitTest( ref_pos ) )
return pt_pad;
}
2007-08-03 18:59:14 +00:00
return NULL;
}
2007-08-22 05:11:01 +00:00
/**
* Function Locate_Prefered_Module
* locates a footprint by its bounding rectangle. If several footprints
* 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
* to performe hit-testing.
* distance is calculated via manhattan distance from the center of the bounding rectangle
2008-03-04 04:22:27 +00:00
* to the cursor postition.
2007-08-22 05:11:01 +00:00
*
* @param Pcb The BOARD to search within.
* @param typeloc Flag bits, tuning the search, see pcbnew.h
* @return MODULE* - the best module or NULL if none.
2007-08-03 18:59:14 +00:00
*/
2007-08-22 05:11:01 +00:00
MODULE* Locate_Prefered_Module( BOARD* Pcb, int typeloc )
{
2007-08-03 18:59:14 +00:00
MODULE* pt_module;
int lx, ly; /* dimensions du rectangle d'encadrement du module */
MODULE* module = NULL; /* module localise sur la couche active */
MODULE* Altmodule = NULL; /* module localise sur les couches non actives */
int min_dim = 0x7FFFFFFF; /* dim mini du module localise sur la couche active */
int alt_min_dim = 0x7FFFFFFF; /* dim mini du module localise sur les couches non actives */
int layer; /* pour calcul de couches prioritaires */
wxPoint ref_pos; /* coord du point de reference pour la localisation */
ref_pos = RefPos( typeloc );
pt_module = Pcb->m_Modules;
for( ; pt_module; pt_module = (MODULE*) pt_module->Next() )
{
2007-08-08 03:50:44 +00:00
// is the ref point within the module's bounds?
if( !pt_module->HitTest( ref_pos ) )
continue;
// if caller wants to ignore locked modules, and this one is locked, skip it.
if( (typeloc & IGNORE_LOCKED) && pt_module->IsLocked() )
continue;
2007-08-03 18:59:14 +00:00
/* calcul de priorite: la priorite est donnee a la couche
2007-08-03 18:59:14 +00:00
* d'appartenance du module et a la couche cuivre si le module
* est sur couche serigr,adhesive cuivre, a la couche cmp si le module
* est sur couche serigr,adhesive composant */
2007-08-23 04:28:46 +00:00
layer = pt_module->GetLayer();
if( layer==ADHESIVE_N_CU || layer==SILKSCREEN_N_CU )
layer = COPPER_LAYER_N;
else if( layer==ADHESIVE_N_CMP || layer==SILKSCREEN_N_CMP )
layer = CMP_N;
2008-03-04 04:22:27 +00:00
2007-08-08 20:51:08 +00:00
/* Localisation: test des dimensions minimales, choix du meilleur candidat */
2007-08-08 03:50:44 +00:00
/* calcul des dimensions du cadre :*/
2008-03-04 04:22:27 +00:00
int offx = pt_module->m_BoundaryBox.m_Size.x/2 +
pt_module->m_BoundaryBox.m_Pos.x +
pt_module->m_Pos.x;
int offy = pt_module->m_BoundaryBox.m_Size.y/2
+ pt_module->m_BoundaryBox.m_Pos.y
+ pt_module->m_Pos.y;
//off x & offy point to the middle of the box.
int dist = abs(ref_pos.x - offx) + abs(ref_pos.y - offy);
lx = pt_module->m_BoundaryBox.GetWidth();
ly = pt_module->m_BoundaryBox.GetHeight();
//int dist = MIN(lx, ly); // to pick the smallest module (kinda screwy with same-sized modules -- this is bad!)
if( ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer == layer ){
if( dist <= min_dim ){
/* meilleure empreinte localisee sur couche active */
2008-03-04 04:22:27 +00:00
module = pt_module;
min_dim = dist;
}
}
2007-08-03 18:59:14 +00:00
else if( !(typeloc & MATCH_LAYER)
&& ( !(typeloc & VISIBLE_ONLY) || IsModuleLayerVisible( layer ) ) )
{
if( dist <= alt_min_dim )
2007-08-03 18:59:14 +00:00
{
/* meilleure empreinte localisee sur autres couches */
2007-08-03 18:59:14 +00:00
Altmodule = pt_module;
alt_min_dim = dist;
}
}
}
if( module )
{
return module;
}
if( Altmodule )
{
return Altmodule;
}
return NULL;
}
/******************************************************************/
inline bool IsPointsAreNear(wxPoint & p1, wxPoint & p2, int max_dist)
/******************************************************************/
/*
return true if the dist between p1 and p2 < max_dist
Currently in test (currently rasnest algos work only if p1 == p2)
*/
{
#if 0 // Do not change it: does not work
2008-03-04 04:22:27 +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;
}
#else
2008-03-04 04:22:27 +00:00
if ( p1 == p2 ) return true;
#endif
2008-03-04 04:22:27 +00:00
return false;
}
/**************************************************************/
2007-08-03 18:59:14 +00:00
TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base,
TRACK* pt_lim, int extr )
/**************************************************************/
2007-08-03 18:59:14 +00:00
/** Search for the track (or via) segment which is connected to the track segment PtRefSegm
* if extr == START, the starting track segment PtRefSegm is used to locate a connected segment
* 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
*
* 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:
* a first search is made considering only the +/- 50 next door neightbour of PtRefSegm.
* 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
*/
{
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-08-03 18:59:14 +00:00
if( extr == START )
pos_ref = PtRefSegm->m_Start;
else
pos_ref = PtRefSegm->m_End;
Reflayer = PtRefSegm->ReturnMaskLayer();
/* 1ere passe */
PtSegmB = PtSegmN = PtRefSegm;
for( ii = 0; ii < NEIGHTBOUR_COUNT_MAX; ii++ )
2007-08-03 18:59:14 +00:00
{
if( (PtSegmN == NULL) && (PtSegmB == NULL) )
break;
if( PtSegmN )
2007-08-03 18:59:14 +00:00
{
if( PtSegmN->GetState( BUSY | DELETED ) )
goto suite;
if( PtSegmN == PtRefSegm )
goto suite;
/* max_dist is the max distance between 2 track ends which ensure a copper continuty */
2008-03-04 04:22:27 +00:00
max_dist = (PtSegmN->m_Width + PtRefSegm->m_Width)/2;
if( IsPointsAreNear(pos_ref, PtSegmN->m_Start, max_dist) )
2007-08-03 18:59:14 +00:00
{ /* Test des couches */
if( Reflayer & PtSegmN->ReturnMaskLayer() )
return PtSegmN;
}
if( IsPointsAreNear(pos_ref, PtSegmN->m_End, max_dist) )
2007-08-03 18:59:14 +00:00
{ /* Test des couches */
if( Reflayer & PtSegmN->ReturnMaskLayer() )
return PtSegmN;
}
2007-08-03 18:59:14 +00:00
suite:
if( PtSegmN == pt_lim )
PtSegmN = NULL;
else
PtSegmN = PtSegmN->Next();
2007-08-03 18:59:14 +00:00
}
if( PtSegmB )
2007-08-03 18:59:14 +00:00
{
if( PtSegmB->GetState( BUSY | DELETED ) )
goto suite1;
if( PtSegmB == PtRefSegm )
goto suite1;
2008-03-04 04:22:27 +00:00
max_dist = (PtSegmB->m_Width + PtRefSegm->m_Width)/2;
if( IsPointsAreNear(pos_ref, PtSegmB->m_Start, max_dist) )
2007-08-03 18:59:14 +00:00
{ /* Test des couches */
if( Reflayer & PtSegmB->ReturnMaskLayer() )
return PtSegmB;
}
if( IsPointsAreNear(pos_ref, PtSegmB->m_End, max_dist) )
2007-08-03 18:59:14 +00:00
{ /* Test des couches */
if( Reflayer & PtSegmB->ReturnMaskLayer() )
return PtSegmB;
}
2007-08-03 18:59:14 +00:00
suite1:
if( PtSegmB == pt_base )
PtSegmB = NULL;
else if( PtSegmB->Type() != TYPE_PCB )
PtSegmB = PtSegmB->Back();
2007-08-03 18:59:14 +00:00
else
PtSegmB = NULL;
}
2007-08-03 18:59:14 +00:00
}
/* Recherche generale */
for( PtSegmN = pt_base; PtSegmN != NULL; PtSegmN = PtSegmN->Next() )
2007-08-03 18:59:14 +00:00
{
if( PtSegmN->GetState( DELETED | BUSY ) )
{
2007-08-03 18:59:14 +00:00
if( PtSegmN == pt_lim )
break;
continue;
2007-08-03 18:59:14 +00:00
}
if( PtSegmN == PtRefSegm )
{
if( PtSegmN == pt_lim )
break;
continue;
2007-08-03 18:59:14 +00:00
}
2008-03-04 04:22:27 +00:00
max_dist = (PtSegmN->m_Width + PtRefSegm->m_Width)/2;
if( IsPointsAreNear(pos_ref,PtSegmN->m_Start, max_dist) )
2007-08-03 18:59:14 +00:00
{ /* Test des couches */
if( Reflayer & PtSegmN->ReturnMaskLayer() )
return PtSegmN;
}
if( IsPointsAreNear(pos_ref, PtSegmN->m_End, max_dist) )
2007-08-03 18:59:14 +00:00
{ /* Test des couches */
if( Reflayer & PtSegmN->ReturnMaskLayer() )
return PtSegmN;
}
2007-08-03 18:59:14 +00:00
if( PtSegmN == pt_lim )
break;
}
return NULL;
}
2007-08-03 18:59:14 +00:00
/****************************************************************************/
/* TRACK *Locate_Pistes(TRACK * start_adresse, int MasqueLayer,int typeloc) */
/* TRACK *Locate_Pistes(TRACK * start_adresse, int ref_pos.x, int ref_pos.y,*/
/* int MasqueLayer) */
/****************************************************************************/
/*
2007-08-03 18:59:14 +00:00
* 1 - routine de localisation du segment de piste pointe par la souris.
* 2 - routine de localisation du segment de piste pointe par le point
* ref_pos.x , ref_pos.y.r
2008-03-04 04:22:27 +00:00
*
2007-08-03 18:59:14 +00:00
* La recherche commence a l'adresse start_adresse
*/
2007-08-03 18:59:14 +00:00
TRACK* Locate_Pistes( TRACK* start_adresse, int MasqueLayer, int typeloc )
{
wxPoint ref_pos = RefPos( typeloc );
2007-08-03 18:59:14 +00:00
return Locate_Pistes( start_adresse, ref_pos, MasqueLayer );
}
2007-08-03 18:59:14 +00:00
TRACK* Locate_Pistes( TRACK* start_adresse, const wxPoint& ref_pos, int MasqueLayer )
{
for( TRACK* track = start_adresse; track; track = track->Next() )
{
int layer = track->GetLayer();
if( track->GetState( BUSY | DELETED ) )
{
// D(printf("track %p is BUSY | DELETED. BUSY=%d DELETED=%d\n", track, track->GetState(BUSY), track->GetState(DELETED) );)
2007-08-03 18:59:14 +00:00
continue;
}
2008-03-04 04:22:27 +00:00
if( g_DesignSettings.m_LayerColor[layer] & ITEM_NOT_SHOW )
continue;
if( track->Type() == TYPE_VIA ) /* VIA rencontree */
{
if( track->HitTest( ref_pos ) )
return track;
2007-08-08 20:51:08 +00:00
}
else
{
if( (g_TabOneLayerMask[layer] & MasqueLayer) == 0 )
continue; /* Segments sur couches differentes */
2008-03-04 04:22:27 +00:00
if( track->HitTest( ref_pos ) )
return track;
}
}
2008-03-04 04:22:27 +00:00
2007-08-03 18:59:14 +00:00
return NULL;
}
2007-08-03 18:59:14 +00:00
/****************************************************************/
/* TRACK * Locate_Zone(TRACK * start_adresse, int layer, */
/* int typeloc) */
/* TRACK * Locate_Zone(TRACK * start_adresse, */
/* const wxPoint & ref_pos, */
/* int layer) */
/****************************************************************/
2007-08-03 18:59:14 +00:00
/*
* 1 - routine de localisation du segment de zone pointe par la souris.
* 2 - routine de localisation du segment de zone pointe par le point
* ref_pos.x , ref_pos.y.r
2008-03-04 04:22:27 +00:00
*
2007-08-03 18:59:14 +00:00
* Si layer == -1 , le tst de la couche n'est pas fait
2008-03-04 04:22:27 +00:00
*
2007-08-03 18:59:14 +00:00
* La recherche commence a l'adresse start_adresse
*/
TRACK* Locate_Zone( TRACK* start_adresse, int layer, int typeloc )
{
wxPoint ref_pos = RefPos( typeloc );
2007-08-03 18:59:14 +00:00
return Locate_Zone( start_adresse, ref_pos, layer );
}
2007-08-03 18:59:14 +00:00
TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer )
{
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-08-03 18:59:14 +00:00
return NULL;
}
2007-08-03 18:59:14 +00:00
/*******************************************************************************/
2007-08-03 18:59:14 +00:00
D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int masque_layer )
/*******************************************************************************/
2007-08-03 18:59:14 +00:00
/* Routine cherchant le pad de centre px,py,
2007-08-03 18:59:14 +00:00
* sur la couche indiquee par masque_layer (bit a bit)
* ( extremite de piste )
* La liste des pads doit deja exister.
2008-03-04 04:22:27 +00:00
*
2007-08-03 18:59:14 +00:00
* retourne :
* NULL si pas de pad localise.
* pointeur sur la structure descr_pad correspondante si pad trouve
* (bonne position ET bonne couche).
*/
{
2009-06-06 18:08:49 +00:00
for( unsigned i=0; i<Pcb->GetPadsCount(); ++i )
2007-08-03 18:59:14 +00:00
{
D_PAD* pad = Pcb->m_NetInfo->GetPad(i);
2007-08-03 18:59:14 +00:00
if( pad->m_Pos != ref_pos )
continue;
/* Pad peut-etre trouve ici : il doit etre sur la bonne couche */
2007-08-03 18:59:14 +00:00
if( pad->m_Masque_Layer & masque_layer )
return pad;
}
2007-08-03 18:59:14 +00:00
return NULL;
}
/***********************************************************************************/
2007-08-03 18:59:14 +00:00
TRACK* Fast_Locate_Piste( TRACK* start_adr, TRACK* end_adr,
const wxPoint& ref_pos, int MaskLayer )
/***********************************************************************************/
2007-08-03 18:59:14 +00:00
/* Localiste le segment dont une extremite coincide avec le point x,y
2007-08-03 18:59:14 +00:00
* sur les couches donnees par masklayer
* la recherche se fait de l'adresse start_adr a end_adr
* si end_adr = NULL, recherche jusqu'a la fin de la liste
* Les segments de piste marques avec le flag DELETED ne sont pas
* pris en compte
*/
{
2007-08-03 18:59:14 +00:00
TRACK* PtSegm;
2007-08-03 18:59:14 +00:00
if( start_adr == NULL )
return NULL;
for( PtSegm = start_adr; PtSegm != NULL; PtSegm = PtSegm->Next() )
2007-08-03 18:59:14 +00:00
{
if( PtSegm->GetState( DELETED | BUSY ) == 0 )
{
if( ref_pos == PtSegm->m_Start )
2008-03-04 04:22:27 +00:00
{
/* Test des couches */
2007-08-03 18:59:14 +00:00
if( MaskLayer & PtSegm->ReturnMaskLayer() )
return PtSegm;
}
if( ref_pos == PtSegm->m_End )
2008-03-04 04:22:27 +00:00
{
/* Test des couches */
2007-08-03 18:59:14 +00:00
if( MaskLayer & PtSegm->ReturnMaskLayer() )
return PtSegm;
}
}
2007-08-03 18:59:14 +00:00
if( PtSegm == end_adr )
break;
}
return NULL;
}
2007-08-03 18:59:14 +00:00
/*******************************************************************/
2007-08-03 18:59:14 +00:00
TRACK* Fast_Locate_Via( TRACK* start_adr, TRACK* end_adr,
const wxPoint& pos, int MaskLayer )
/*******************************************************************/
/* Localise la via de centre le point x,y , sur les couches donnees
2007-08-03 18:59:14 +00:00
* par masklayer
* la recherche se fait de l'adresse start_adr a end_adr.
* si end_adr = NULL, recherche jusqu'a la fin de la liste
* les vias dont le parametre State a le bit DELETED ou BUSY = 1 sont ignorees
*/
{
2007-08-03 18:59:14 +00:00
TRACK* PtSegm;
for( PtSegm = start_adr; PtSegm != NULL; PtSegm = PtSegm->Next() )
2007-08-03 18:59:14 +00:00
{
if( PtSegm->Type() == TYPE_VIA )
{
if( pos == PtSegm->m_Start )
2007-08-03 18:59:14 +00:00
{
if( PtSegm->GetState( BUSY | DELETED ) == 0 )
2008-03-04 04:22:27 +00:00
{
/* Test des couches */
2007-08-03 18:59:14 +00:00
if( MaskLayer & PtSegm->ReturnMaskLayer() )
return PtSegm;
}
}
}
2007-08-03 18:59:14 +00:00
if( PtSegm == end_adr )
break;
}
return NULL;
}