2008-02-08 00:16:59 +00:00
|
|
|
/**************************************************/
|
|
|
|
/* Edition des pistes */
|
|
|
|
/* Routines de modification automatique de pistes */
|
|
|
|
/**************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
/*********************************************************************/
|
2008-02-08 00:16:59 +00:00
|
|
|
int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
|
|
|
|
TRACK* pt_new_track, int nbptnewpiste )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
/* Routine d'effacement de la piste redondante a la piste nouvellement cree
|
|
|
|
* pointee par pt_new_track (nbptnewpiste segments)
|
|
|
|
*
|
|
|
|
* la piste cree est supposee constituee de segments contigus en memoire avec:
|
|
|
|
* point de depart pt_newtrack->m_Start.x,y
|
|
|
|
* point d'arrivee pt_newtrack->m_End.x,y
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-08 00:16:59 +00:00
|
|
|
TRACK* StartTrack, * EndTrack;/* Pointeurs des segments de debut et fin
|
|
|
|
* (extremites) de la nouvelle piste */
|
2008-12-04 04:28:11 +00:00
|
|
|
TRACK* pt_segm;
|
|
|
|
TRACK* pt_del;
|
2008-02-08 00:16:59 +00:00
|
|
|
int ii, jj, nb_segm, nbconnect;
|
|
|
|
wxPoint start; /* coord du point de depart de la piste */
|
|
|
|
wxPoint end; /* coord du point de fin de la piste */
|
|
|
|
int startmasklayer, endmasklayer; /* masque couche de depart et de fin */
|
|
|
|
TRACK* BufDeb, * BufEnd; /* Pointeurs de debut et de fin de la zone
|
|
|
|
* des pistes equipotentielles */
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
int netcode = pt_new_track->GetNet();
|
|
|
|
|
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
/* Reconstitution de la piste complete ( la nouvelle piste
|
2008-12-04 04:28:11 +00:00
|
|
|
* a pu demarrer sur un segment de piste en l'air
|
|
|
|
*/
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
ListSetState( pt_new_track, nbptnewpiste, BUSY, OFF );
|
|
|
|
|
|
|
|
/* si la novelle piste commence par une via, il est plus sur de rechercher
|
|
|
|
* la piste complete en utilisant le segment suivant comme reference, car
|
|
|
|
* une via est souvent sur un carrefour de segments, et ne caracterise pas
|
|
|
|
* une piste */
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_new_track->Type() == TYPE_VIA && (nbptnewpiste > 1 ) )
|
2008-11-24 06:53:43 +00:00
|
|
|
pt_new_track = pt_new_track->Next();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
pt_new_track = Marque_Une_Piste( frame, DC, pt_new_track, &nbptnewpiste, 0 );
|
2008-12-04 04:28:11 +00:00
|
|
|
wxASSERT( pt_new_track );
|
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
|
|
|
TRACK* EndNewTrack; /* Pointeur sur le dernier segment de la liste
|
|
|
|
* chainee de la mouvelle piste */
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
EndNewTrack = pt_new_track;
|
|
|
|
for( ii = 1; ii < nbptnewpiste; ii++ )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
wxASSERT( EndNewTrack->GetState(-1) != 0 );
|
|
|
|
D(printf("track %p is newly part of net %d\n", EndNewTrack, netcode );)
|
2008-11-24 06:53:43 +00:00
|
|
|
EndNewTrack = EndNewTrack->Next();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
wxASSERT( EndNewTrack->GetState(-1) != 0 );
|
|
|
|
D(printf("track %p is newly part of net %d\n", EndNewTrack, netcode );)
|
|
|
|
|
|
|
|
for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
|
|
|
|
track->Show( 0, std::cout );
|
|
|
|
#endif
|
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
/* Calcul des limites de recherche des segments de piste */
|
|
|
|
/* BufDeb pointe le 1er segment utile */
|
2008-12-04 04:28:11 +00:00
|
|
|
BufDeb = Pcb->m_Track->GetStartNetCode( netcode );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
/* BufEnd Pointe le dernier segment */
|
2008-12-04 04:28:11 +00:00
|
|
|
BufEnd = BufDeb->GetEndNetCode( netcode );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
/* nettoyage des flags pour tout le net */
|
2009-03-05 15:58:06 +00:00
|
|
|
for( pt_del = BufDeb; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
D(printf("track %p turning off BUSY | EDIT | CHAIN\n", pt_del );)
|
2008-02-08 00:16:59 +00:00
|
|
|
pt_del->SetState( BUSY | EDIT | CHAIN, OFF );
|
2009-03-05 15:58:06 +00:00
|
|
|
if( pt_del == BufEnd ) // Last segment reached
|
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calcul des points limites de la nouvelle piste */
|
|
|
|
if( ReturnEndsTrack( pt_new_track, nbptnewpiste,
|
|
|
|
&StartTrack, &EndTrack ) == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( (StartTrack == NULL) || (EndTrack == NULL) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Calcul des caracteristiques des points de debut et de fin */
|
|
|
|
start = StartTrack->m_Start;
|
|
|
|
end = EndTrack->m_End;
|
|
|
|
|
|
|
|
/* Les points de depart et de fin doivent etre distincts */
|
|
|
|
if( start == end )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Determinations des couches interconnectees a ces points */
|
|
|
|
startmasklayer = StartTrack->ReturnMaskLayer();
|
|
|
|
endmasklayer = EndTrack->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
/* Il peut y avoir une via ou un pad sur les extremites: */
|
|
|
|
pt_segm = Fast_Locate_Via( Pcb->m_Track, NULL, start, startmasklayer );
|
|
|
|
if( pt_segm )
|
|
|
|
startmasklayer |= pt_segm->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
if( StartTrack->start && (StartTrack->start->Type() == TYPE_PAD) )
|
|
|
|
{
|
|
|
|
/* start sur pad */
|
2008-02-08 00:16:59 +00:00
|
|
|
D_PAD* pt_pad = (D_PAD*) (StartTrack->start);
|
|
|
|
startmasklayer |= pt_pad->m_Masque_Layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
pt_segm = Fast_Locate_Via( Pcb->m_Track, NULL, end, endmasklayer );
|
|
|
|
if( pt_segm )
|
|
|
|
endmasklayer |= pt_segm->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
if( EndTrack->end && ( EndTrack->end->Type() == TYPE_PAD) )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
|
|
|
D_PAD* pt_pad = (D_PAD*) (EndTrack->end);
|
|
|
|
endmasklayer |= pt_pad->m_Masque_Layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Marquage a DELETED de la piste nouvelle (qui ne doit pas intervenir
|
2008-12-04 04:28:11 +00:00
|
|
|
* dans la recherche d'autres connexions)
|
|
|
|
*/
|
2008-02-08 00:16:59 +00:00
|
|
|
ListSetState( pt_new_track, nbptnewpiste, DELETED, ON );
|
|
|
|
|
|
|
|
/* test : un segment doit etre connecte au point de depart car sinon
|
2008-12-04 04:28:11 +00:00
|
|
|
* il est inutile d'analyser l'autre point
|
|
|
|
*/
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
pt_segm = Fast_Locate_Piste( BufDeb, BufEnd, start, startmasklayer );
|
|
|
|
|
|
|
|
if( pt_segm == NULL ) /* Pas de piste reliee au point de depart */
|
|
|
|
{
|
|
|
|
/* Suppression du flag DELETED */
|
|
|
|
ListSetState( pt_new_track, nbptnewpiste, DELETED, OFF );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Marquage a CHAIN des segments candidats connectes au point de fin
|
|
|
|
* Remarque: les vias ne sont pas prises en compte car elles ne permettent
|
|
|
|
* pas de definir une piste, puisque elles sont sur un carrefour */
|
|
|
|
for( pt_del = BufDeb, nbconnect = 0; ; )
|
|
|
|
{
|
|
|
|
pt_segm = Fast_Locate_Piste( pt_del, BufEnd, end, endmasklayer );
|
|
|
|
if( pt_segm == NULL )
|
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_segm->Type() != TYPE_VIA )
|
|
|
|
{
|
|
|
|
/* Segment trouve */
|
2008-02-08 00:16:59 +00:00
|
|
|
if( pt_segm->GetState( CHAIN ) == 0 )
|
|
|
|
{
|
|
|
|
pt_segm->SetState( CHAIN, ON );
|
|
|
|
nbconnect++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( pt_del == BufEnd )
|
|
|
|
break;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
pt_del = pt_segm->Next();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( nbconnect == 0 )
|
|
|
|
{
|
2009-03-05 15:58:06 +00:00
|
|
|
/* Clear used flagss */
|
|
|
|
for( pt_del = BufDeb; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2009-03-05 15:58:06 +00:00
|
|
|
pt_del->SetState( BUSY | DELETED | EDIT | CHAIN, OFF );
|
|
|
|
if( pt_del == BufEnd ) // Last segment reached
|
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Marquage a EDIT de la piste nouvelle (qui ne doit pas intervenir
|
|
|
|
* dans la recherche d'autres pistes) */
|
|
|
|
ListSetState( pt_new_track, nbptnewpiste, DELETED, OFF );
|
|
|
|
|
|
|
|
ListSetState( pt_new_track, nbptnewpiste, EDIT, ON );
|
|
|
|
|
|
|
|
/* Examen de tous les segments marques */
|
|
|
|
while( nbconnect )
|
|
|
|
{
|
2009-03-05 15:58:06 +00:00
|
|
|
for( pt_del = BufDeb; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
|
|
|
if( pt_del->GetState( CHAIN ) )
|
|
|
|
break;
|
2009-03-05 15:58:06 +00:00
|
|
|
if( pt_del == BufEnd ) // Last segment reached
|
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
nbconnect--;
|
|
|
|
pt_del->SetState( CHAIN, OFF );
|
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
pt_del = Marque_Une_Piste( frame, DC, pt_del, &nb_segm, 0 );
|
|
|
|
|
|
|
|
/* Test si La piste marquee est redondante, c'est a dire si l'un des
|
2008-12-04 04:28:11 +00:00
|
|
|
* segments marques est connecte au point de depart de la piste nouvelle
|
2008-02-08 00:16:59 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
ii = 0;
|
|
|
|
pt_segm = pt_del;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_segm && (ii < nb_segm); pt_segm = pt_segm->Next(), ii++ )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_segm->GetState( BUSY ) == 0 )
|
2008-02-08 00:16:59 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_segm->m_Start == start || pt_segm->m_End == start )
|
|
|
|
{
|
|
|
|
/* la piste marquee peut etre effacee */
|
2008-02-08 00:16:59 +00:00
|
|
|
TRACK* NextS;
|
|
|
|
Trace_Une_Piste( frame->DrawPanel, DC, pt_del, nb_segm, GR_XOR | GR_SURBRILL );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
for( jj = 0; jj < nb_segm; jj++, pt_del = NextS )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
NextS = pt_del->Next();
|
2008-02-08 00:16:59 +00:00
|
|
|
pt_del->DeleteStructure();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nettoyage des flags */
|
2008-11-24 06:53:43 +00:00
|
|
|
for( pt_del = Pcb->m_Track; pt_del != NULL; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
|
|
|
if( pt_del->GetState( EDIT ) )
|
|
|
|
{
|
|
|
|
pt_del->SetState( EDIT, OFF );
|
|
|
|
pt_del->Draw( frame->DrawPanel, DC, GR_OR );
|
|
|
|
}
|
|
|
|
pt_del->SetState( EDIT | CHAIN, OFF );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nettoyage du flag BUSY puisque ici la piste marquee n'a pas
|
|
|
|
* ete retenuee */
|
|
|
|
ListSetState( pt_del, nb_segm, BUSY, OFF );
|
|
|
|
}
|
|
|
|
|
2009-03-05 15:58:06 +00:00
|
|
|
/* Clear used flags */
|
|
|
|
for( pt_del = Pcb->m_Track; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2009-03-05 15:58:06 +00:00
|
|
|
pt_del->SetState( BUSY | DELETED | EDIT | CHAIN, OFF );
|
|
|
|
if( pt_del == BufEnd ) // Last segment reached
|
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|