-
-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathclean.cpp
1182 lines (944 loc) · 37.5 KB
/
clean.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************/
/* editeur de PCB PCBNEW */
/* Fonctions de Nettoyage et reorganisation de Pistes */
/******************************************************/
/* Fichier CLEAN.CPP */
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "autorout.h"
#include "protos.h"
/* Position of messages on the bottom display */
#define AFFICHE 1
#define POS_AFF_PASSE 40
#define POS_AFF_VAR 50
#define POS_AFF_MAX 60
#define POS_AFF_NUMSEGM 70
/* local functions : */
static int clean_segments( WinEDA_PcbFrame* frame, wxDC* DC );
static void DeleteUnconnectedTracks( WinEDA_PcbFrame* frame, wxDC* DC );
static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extremite );
static void Clean_Pcb_Items( WinEDA_PcbFrame* frame, wxDC* DC );
/* Local Variables: */
static bool a_color; /* message color */
static bool s_CleanVias = true;
static bool s_MergeSegments = true;
static bool s_DeleteUnconnectedSegm = true;
static bool s_ConnectToPads = false;
#include "cleaningoptions_dialog.cpp"
#define CONN2PAD_ENBL
#ifdef CONN2PAD_ENBL
static void ConnectDanglingEndToPad( WinEDA_PcbFrame* frame, wxDC* DC );
static void ConnectDanglingEndToVia( BOARD* pcb );
//static void Gen_Raccord_Track( WinEDA_PcbFrame* frame, wxDC* DC );
#endif
/*****************************************/
void WinEDA_PcbFrame::Clean_Pcb( wxDC* DC )
/*****************************************/
/* Install the track operation dialog frame
*/
{
s_ConnectToPads = false;
WinEDA_CleaningOptionsFrame* frame = new WinEDA_CleaningOptionsFrame( this, DC );
frame->ShowModal();
frame->Destroy();
DrawPanel->Refresh( true );
}
/************************************************************/
void Clean_Pcb_Items( WinEDA_PcbFrame* frame, wxDC* DC )
/************************************************************/
/* Main cleaning function.
* Delete
* - Redundant points on tracks (merge aligned segments)
* - vias on pad
* - null segments
* - Redundant segments
* Create segments when track ends are incorrecty connected:
* i.e. when a track end covers a pad or a via but is not exactly on the pad or the via center
*/
{
frame->MsgPanel->EraseMsgBox();
frame->m_Pcb->GetNumSegmTrack(); // update the count
/* Rebuild the pad infos (pad list and netcodes) to ensure an up to date info */
frame->m_Pcb->m_Status_Pcb = 0;
frame->build_liste_pads();
frame->recalcule_pad_net_code();
if( s_CleanVias ) // delete redundant vias
{
TRACK* track;
TRACK* next_track;
for( track = frame->m_Pcb->m_Track; track; track = track->Next() )
{
if( track->Shape() != VIA_THROUGH )
continue;
// Search and delete others vias at same location
TRACK* alt_track = track->Next();
for( ; alt_track != NULL; alt_track = next_track )
{
next_track = alt_track->Next();
if( alt_track->m_Shape != VIA_THROUGH )
continue;
if( alt_track->m_Start != track->m_Start )
continue;
/* delete via */
alt_track->UnLink();
delete alt_track;
}
}
/* Delete Via on pads at same location */
for( track = frame->m_Pcb->m_Track; track != NULL; track = next_track )
{
next_track = track->Next();
if( track->m_Shape != VIA_THROUGH )
continue;
D_PAD* pad = Fast_Locate_Pad_Connecte( frame->m_Pcb, track->m_Start, ALL_CU_LAYERS );
if( pad && (pad->m_Masque_Layer & EXTERNAL_LAYERS) == EXTERNAL_LAYERS ) // redundant Via
{
/* delete via */
track->UnLink();
delete track;
}
}
}
#ifdef CONN2PAD_ENBL
/* Create missing segments when a track end covers a pad or a via,
but is not on the pad or the via center */
if( s_ConnectToPads )
{
/* Create missing segments when a track end covers a pad, but is not on the pad center */
if( s_ConnectToPads )
ConnectDanglingEndToPad( frame, DC );
// creation of points of connections at the intersection of tracks
// Gen_Raccord_Track(frame, DC);
/* Create missing segments when a track end covers a via, but is not on the via center */
if( s_ConnectToPads )
ConnectDanglingEndToVia( frame->m_Pcb );
}
#endif
/* Remove null segments and intermediate points on aligned segments */
if( s_MergeSegments )
clean_segments( frame, DC );
/* Delete dangling tracks */
if( s_DeleteUnconnectedSegm )
DeleteUnconnectedTracks( frame, DC );
frame->Compile_Ratsnest( DC, AFFICHE );
frame->GetScreen()->SetModify();
}
/*****************************************************************************/
static void DeleteUnconnectedTracks( WinEDA_PcbFrame* frame, wxDC* DC )
/*****************************************************************************/
/*
* Delete dangling tracks
* Vias:
* If a via is only connected to a dangling track, it also will be removed
*/
{
TRACK* segment;
TRACK* other;
TRACK* startNetcode;
TRACK* next;
ZONE_CONTAINER* zone;
int nbpoints_supprimes = 0;
int masklayer, oldnetcode;
int type_end, flag_erase;
int ii, percent, oldpercent;
wxString msg;
frame->Affiche_Message( _( "Delete unconnected tracks:" ) );
frame->DrawPanel->m_AbortRequest = FALSE;
// correct via m_End defects and count number of segments
frame->m_Pcb->m_NbSegmTrack = 0;
ii = 0;
for( segment = frame->m_Pcb->m_Track; segment; segment = next )
{
frame->m_Pcb->m_NbSegmTrack++;
next = segment->Next();
if( segment->Type() == TYPEVIA )
{
if( segment->m_Start != segment->m_End )
{
segment->m_End = segment->m_Start;
ii++;
msg.Printf( wxT( "%d " ), ii );
Affiche_1_Parametre( frame, POS_AFF_PASSE, _( "ViaDef" ), msg, LIGHTRED );
}
continue;
}
}
// removal of unconnected tracks
percent = 0;
oldpercent = -1;
oldnetcode = 0;
segment = startNetcode = frame->m_Pcb->m_Track;
for( ii = 0; segment; segment = next, ii++ )
{
next = segment->Next();
// display activity
percent = (100 * ii) / frame->m_Pcb->m_NbSegmTrack;
if( percent != oldpercent )
{
oldpercent = percent;
frame->DisplayActivity( percent, wxT( "No Conn: " ) );
msg.Printf( wxT( "%d " ), frame->m_Pcb->m_NbSegmTrack );
Affiche_1_Parametre( frame, POS_AFF_MAX, wxT( "Max" ), msg, GREEN );
msg.Printf( wxT( "%d " ), ii );
Affiche_1_Parametre( frame, POS_AFF_NUMSEGM, wxT( "Segm" ), msg, CYAN );
}
if( frame->DrawPanel->m_AbortRequest )
break;
if( segment->GetNet() != oldnetcode )
{
startNetcode = segment;
oldnetcode = segment->GetNet();
}
flag_erase = 0; //Not connected indicator
type_end = 0;
/* Is a pad found on a track end ? */
masklayer = segment->ReturnMaskLayer();
D_PAD* pad;
pad = Fast_Locate_Pad_Connecte( frame->m_Pcb, segment->m_Start, masklayer );
if( pad != NULL )
{
segment->start = pad;
type_end |= START_ON_PAD;
}
pad = Fast_Locate_Pad_Connecte( frame->m_Pcb, segment->m_End, masklayer );
if( pad != NULL )
{
segment->end = pad;
type_end |= END_ON_PAD;
}
// if not connected to a pad, test if segment's START is connected to another track
// For via tests, an enhancement could to test if connected to 2 items on different layers.
// Currently a via must be connected to 2 items, taht can be on the same layer
int top_layer, bottom_layer;
if( (type_end & START_ON_PAD ) == 0 )
{
other = Locate_Piste_Connectee( segment, frame->m_Pcb->m_Track, NULL, START );
if( other == NULL ) // Test a connection to zones
{
if( segment->Type() != TYPEVIA )
{
zone = frame->m_Pcb->HitTestForAnyFilledArea(segment->m_Start, segment->GetLayer() );
}
else
{
((SEGVIA*)segment)->ReturnLayerPair( &top_layer, &bottom_layer );
zone = frame->m_Pcb->HitTestForAnyFilledArea(segment->m_Start, top_layer, bottom_layer );
}
}
if( (other == NULL) && (zone == NULL) )
flag_erase |= 1;
else // segment, via or zone connected to this end
{
segment->start = other;
// If a via is connected to this end, test if this via has a second item connected
// if no, remove it with the current segment
if( other && other->Type() == TYPEVIA )
{
// search for another segment following the via
segment->SetState( BUSY, ON );
SEGVIA* via = (SEGVIA*) other;
other = Locate_Piste_Connectee( via, frame->m_Pcb->m_Track,
NULL, START );
if( other == NULL )
{
via->ReturnLayerPair( &top_layer, &bottom_layer );
zone = frame->m_Pcb->HitTestForAnyFilledArea(via->m_Start, bottom_layer, top_layer );
}
if( (other == NULL) && (zone == NULL) )
flag_erase |= 2;
segment->SetState( BUSY, OFF );
}
}
}
// if not connected to a pad, test if segment's END is connected to another track
if( (type_end & END_ON_PAD ) == 0 )
{
other = Locate_Piste_Connectee( segment, frame->m_Pcb->m_Track,
NULL, END );
if( other == NULL ) // Test a connection to zones
{
if( segment->Type() != TYPEVIA )
zone = frame->m_Pcb->HitTestForAnyFilledArea(segment->m_End, segment->GetLayer() );
else
{
((SEGVIA*)segment)->ReturnLayerPair( &top_layer, &bottom_layer );
zone = frame->m_Pcb->HitTestForAnyFilledArea(segment->m_End,top_layer, bottom_layer );
}
}
if ( (other == NULL) && (zone == NULL) )
flag_erase |= 0x10;
else // segment, via or zone connected to this end
{
segment->end = other;
// If a via is connected to this end, test if this via has a second item connected
// if no, remove it with the current segment
if( other && other->Type() == TYPEVIA )
{
// search for another segment following the via
segment->SetState( BUSY, ON );
SEGVIA* via = (SEGVIA*) other;
other = Locate_Piste_Connectee( via, frame->m_Pcb->m_Track,
NULL, END );
if( other == NULL )
{
via->ReturnLayerPair( &top_layer, &bottom_layer );
zone = frame->m_Pcb->HitTestForAnyFilledArea(via->m_End, bottom_layer, top_layer );
}
if( (other == NULL) && (zone == NULL) )
flag_erase |= 0x20;
segment->SetState( BUSY, OFF );
}
}
}
if( flag_erase )
{
oldpercent = -1; // force dispay activity
nbpoints_supprimes++;
ii--;
msg.Printf( wxT( "%d " ), nbpoints_supprimes );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxT( "NoConn." ), msg, LIGHTRED );
// update the pointer to start of the contiguous netcode group
if( segment == startNetcode )
{
next = segment->Next();
startNetcode = next;
}
else
next = startNetcode;
// remove segment from screen and board
segment->Draw( frame->DrawPanel, DC, GR_XOR );
segment->DeleteStructure();
if( next == NULL )
break;
}
}
}
/************************************************************/
static int clean_segments( WinEDA_PcbFrame* frame, wxDC* DC )
/************************************************************/
/* Delete null lenght segments, and intermediate points .. */
{
TRACK* segment;
TRACK* other;
int ii, nbpoints_supprimes = 0;
int flag, no_inc, percent, oldpercent;
wxString msg;
frame->DrawPanel->m_AbortRequest = FALSE;
/**********************************************/
/* Delete null segments */
/**********************************************/
a_color = GREEN;
nbpoints_supprimes = 0;
percent = 0;
oldpercent = -1;
frame->MsgPanel->EraseMsgBox();
frame->Affiche_Message( _( "Clean Null Segments" ) );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxT( "NullSeg" ), wxT( "0" ), a_color );
for( segment = frame->m_Pcb->m_Track; segment; segment = segment->Next() )
{
if( !segment->IsNull() )
continue;
/* Lenght segment = 0; delete it */
segment->Draw( frame->DrawPanel, DC, GR_XOR );
segment->DeleteStructure();
nbpoints_supprimes++;
msg.Printf( wxT( " %d" ), nbpoints_supprimes );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxEmptyString, msg, a_color );
}
/**************************************/
/* Delete redundant segments */
/**************************************/
Affiche_1_Parametre( frame, POS_AFF_VAR, wxT( "Ident" ), wxT( "0" ), a_color );
percent = 0;
oldpercent = -1;
for( segment = frame->m_Pcb->m_Track, ii = 0; segment; segment = segment->Next(), ii++ )
{
/* Display activity */
percent = (100 * ii) / frame->m_Pcb->m_NbSegmTrack;
if( percent != oldpercent )
{
frame->DisplayActivity( percent, wxT( "Id segm: " ) );
oldpercent = percent;
msg.Printf( wxT( "%d" ), frame->m_Pcb->m_NbSegmTrack );
Affiche_1_Parametre( frame, POS_AFF_MAX, wxT( "Max" ), msg, GREEN );
msg.Printf( wxT( "%d" ), ii );
Affiche_1_Parametre( frame, POS_AFF_NUMSEGM, wxT( "Segm" ), msg, CYAN );
if( frame->DrawPanel->m_AbortRequest )
return -1;
}
for( other = segment->Next(); other; other = other->Next() )
{
int erase = 0;
if( segment->Type() != other->Type() )
continue;
if( segment->GetLayer() != other->GetLayer() )
continue;
if( segment->GetNet() != other->GetNet() )
break;
if( segment->m_Start == other->m_Start )
{
if( segment->m_End == other->m_End )
erase = 1;
}
if( segment->m_Start == other->m_End )
{
if( segment->m_End == other->m_Start )
erase = 1;
}
/* Delete redundant point */
if( erase )
{
ii--;
other->Draw( frame->DrawPanel, DC, GR_OR );
other->DeleteStructure();
nbpoints_supprimes++;
msg.Printf( wxT( " %d" ), nbpoints_supprimes );
Affiche_1_Parametre( frame, 50, wxEmptyString, msg, a_color );
}
}
}
/*******************************/
/* delete intermediate points */
/*******************************/
nbpoints_supprimes = 0;
percent = 0;
oldpercent = -1;
frame->Affiche_Message( _( "Merging Segments:" ) );
Affiche_1_Parametre( frame, POS_AFF_VAR, _( "Merge" ), _( "0" ), a_color );
ii = 0;
TRACK* next;
for( segment = frame->m_Pcb->m_Track; segment; segment = next )
{
TRACK* segStart;
TRACK* segEnd;
TRACK* segDelete;
next = segment->Next();
ii++;
percent = (100 * ii) / frame->m_Pcb->m_NbSegmTrack;
if( percent != oldpercent )
{
frame->DisplayActivity( percent, _( "Merge: " ) );
oldpercent = percent;
msg.Printf( wxT( "%d" ), frame->m_Pcb->m_NbSegmTrack );
Affiche_1_Parametre( frame, POS_AFF_MAX, wxT( "Max" ), msg, GREEN );
msg.Printf( wxT( "%d" ), ii );
Affiche_1_Parametre( frame, POS_AFF_NUMSEGM, wxT( "Segm" ), msg, CYAN );
if( frame->DrawPanel->m_AbortRequest )
return -1;
}
if( segment->Type() != TYPETRACK )
continue;
flag = no_inc = 0;
// search for a possible point that connects on the START point of the segment
for( segStart = segment->Next(); ; )
{
segStart = Locate_Piste_Connectee( segment, segStart,
NULL, START );
if( segStart )
{
// the two segments must have the same width
if( segment->m_Width != segStart->m_Width )
break;
// it cannot be a via
if( segStart->Type() != TYPETRACK )
break;
/* We must have only one segment connected */
segStart->SetState( BUSY, ON );
other = Locate_Piste_Connectee( segment, frame->m_Pcb->m_Track,
NULL, START );
segStart->SetState( BUSY, OFF );
if( other == NULL )
flag = 1; /* OK */
break;
}
break;
}
if( flag ) /* We have the starting point of the segment is connecte to an other segment */
{
segDelete = AlignSegment( frame->m_Pcb, segment, segStart, START );
if( segDelete )
{
nbpoints_supprimes++; no_inc = 1;
segDelete->DeleteStructure();
}
}
/* search for a possible point that connects on the END point of the segment: */
for( segEnd = segment->Next(); ; )
{
segEnd = Locate_Piste_Connectee( segment, segEnd, NULL, END );
if( segEnd )
{
if( segment->m_Width != segEnd->m_Width )
break;
if( segEnd->Type() != TYPETRACK )
break;
/* We must have only one segment connected */
segEnd->SetState( BUSY, ON );
other = Locate_Piste_Connectee( segment, frame->m_Pcb->m_Track,
NULL, END );
segEnd->SetState( BUSY, OFF );
if( other == NULL )
flag |= 2; /* Ok */
break;
}
else
break;
}
if( flag & 2 ) /* We have the ending point of the segment is connecte to an other segment */
{
segDelete = AlignSegment( frame->m_Pcb, segment, segEnd, END );
if( segDelete )
{
nbpoints_supprimes++;
no_inc = 1;
segDelete->DeleteStructure();
}
}
if( no_inc ) /* The current segment was modified, retry to merge it */
{
msg.Printf( wxT( "%d " ), nbpoints_supprimes );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxEmptyString, msg, a_color );
next = segment->Next();
}
}
return 0;
}
/****************************************************************************/
static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extremite )
/****************************************************************************/
/* Function used by clean_segments.
* Test alignement of pt_segm and pt_ref (which must have acommon end).
* and see if the common point is not on a pad (i.e. if this common point can be removed).
* the ending point of pt_ref is the start point (extremite == START)
* or the end point (extremite == FIN)
* if the common end can be deleted, this function
* change the common point coordinate of the pt_ref segm
* (and therefore connect the 2 other ending points)
* and return pt_segm (which can be deleted).
* else return NULL
*/
{
int flag = 0;
int refdx = pt_ref->m_End.x - pt_ref->m_Start.x;
int refdy = pt_ref->m_End.y - pt_ref->m_Start.y;
int segmdx = pt_segm->m_End.x - pt_segm->m_Start.x;
int segmdy = pt_segm->m_End.y - pt_segm->m_Start.y;
// test for vertical alignment (easy to handle)
if( refdx == 0 )
{
if( segmdx != 0 )
return NULL;
else
flag = 1;
}
// test for horizontal alignment (easy to handle)
if( refdy == 0 )
{
if( segmdy != 0 )
return NULL;
else
flag = 2;
}
/* tst if alignement in other cases
* We must have refdy/refdx == (+/-)segmdy/segmdx, (i.e. same orientation) */
if( flag == 0 )
{
if( (refdy * segmdx != refdx * segmdy)
&& (refdy * segmdx != -refdx * segmdy) )
return NULL;
flag = 4;
}
/* Here we have 2 aligned segments:
We must change the pt_ref common point only if not on a pad
(this function) is called when thre is only 2 connected segments,
and if this point is not on a pad, it can be removed and the 2 segments will be merged
*/
if( extremite == START )
{
/* We do not have a pad */
if( Fast_Locate_Pad_Connecte( Pcb, pt_ref->m_Start,
g_TabOneLayerMask[pt_ref->GetLayer()] ) )
return NULL;
/* change the common point coordinate of pt_segm tu use the other point
of pt_segm (pt_segm will be removed later) */
if( pt_ref->m_Start == pt_segm->m_Start )
{
pt_ref->m_Start = pt_segm->m_End;
return pt_segm;
}
else
{
pt_ref->m_Start = pt_segm->m_Start;
return pt_segm;
}
}
else /* extremite == END */
{
/* We do not have a pad */
if( Fast_Locate_Pad_Connecte( Pcb, pt_ref->m_End,
g_TabOneLayerMask[pt_ref->GetLayer()] ) )
return NULL;
/* change the common point coordinate of pt_segm tu use the other point
of pt_segm (pt_segm will be removed later) */
if( pt_ref->m_End == pt_segm->m_Start )
{
pt_ref->m_End = pt_segm->m_End;
return pt_segm;
}
else
{
pt_ref->m_End = pt_segm->m_Start;
return pt_segm;
}
}
return NULL;
}
/***************************************************************************/
int Netliste_Controle_piste( WinEDA_PcbFrame* frame, wxDC* DC, int affiche )
/***************************************************************************/
/**
* Function Netliste_Controle_piste
* finds all track segments which are mis-connected (to more than one net).
* When such a bad segment is found, mark it as needing to be removed (supression).
*/
{
TRACK* segment;
TRACK* other;
TRACK* next;
int net_code_s, net_code_e;
int nbpoints_modifies = 0;
int flag = 0;
wxString msg;
int percent = 0;
int oldpercent = -1;
a_color = RED;
frame->Affiche_Message( _( "DRC Control:" ) );
frame->DrawPanel->m_AbortRequest = FALSE;
if( affiche )
Affiche_1_Parametre( frame, POS_AFF_VAR, _( "NetCtr" ), wxT( "0 " ), a_color );
int ii = 0;
for( segment = frame->m_Pcb->m_Track; segment; segment = (TRACK*) segment->Next() )
{
// display activity
ii++;
percent = (100 * ii) / frame->m_Pcb->m_NbSegmTrack;
if( percent != oldpercent )
{
frame->DisplayActivity( percent, wxT( "Drc: " ) );
oldpercent = percent;
msg.Printf( wxT( "%d" ), frame->m_Pcb->m_NbSegmTrack );
Affiche_1_Parametre( frame, POS_AFF_MAX, wxT( "Max" ), msg, GREEN );
msg.Printf( wxT( "%d" ), frame->m_Pcb->m_NbSegmTrack );
Affiche_1_Parametre( frame, POS_AFF_NUMSEGM, wxT( "Segm" ), msg, CYAN );
if( frame->DrawPanel->m_AbortRequest )
return flag;
}
segment->SetState( FLAG0, OFF );
// find the netcode for segment using anything connected to the "start" of "segment"
net_code_s = -1;
if( segment->start && segment->start->Type()==TYPEPAD )
{
// get the netcode of the pad to propagate.
net_code_s = ((D_PAD*)(segment->start))->GetNet();
}
else
{
other = Locate_Piste_Connectee( segment, frame->m_Pcb->m_Track,
NULL, START );
if( other )
net_code_s = other->GetNet();
}
if( net_code_s < 0 )
continue; // the "start" of segment is not connected
// find the netcode for segment using anything connected to the "end" of "segment"
net_code_e = -1;
if( segment->end && segment->end->Type()==TYPEPAD )
{
net_code_e = ((D_PAD*)(segment->end))->GetNet();
}
else
{
other = Locate_Piste_Connectee( segment, frame->m_Pcb->m_Track,
NULL, END );
if( other )
net_code_e = other->GetNet();
}
if( net_code_e < 0 )
continue; // the "end" of segment is not connected
// the obtained netcodes do not agree, mark the segment as needing to be removed
if( net_code_s != net_code_e )
{
segment->SetState( FLAG0, ON );
}
}
// Removal of flagged segments
for( segment = frame->m_Pcb->m_Track; segment; segment = next )
{
next = (TRACK*) segment->Next();
if( segment->GetState( FLAG0 ) ) //* if segment is marked as needing to be removed
{
segment->SetState( FLAG0, OFF );
flag = 1;
oldpercent = -1;
frame->m_Pcb->m_Status_Pcb = 0;
frame->Remove_One_Track( DC, segment );
next = frame->m_Pcb->m_Track; /* NextS a peut etre ete efface */
if( affiche )
{
nbpoints_modifies++;
msg.Printf( wxT( "%d " ), nbpoints_modifies );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxEmptyString, msg, a_color );
}
}
}
return flag;
}
#if 0
/***************************************************************/
static void Gen_Raccord_Track( WinEDA_PcbFrame* frame, wxDC* DC )
/***************************************************************/
/**
* Function Gen_Raccord_Track
* tests the ends of segments. If and end is on a segment of other track, but not
* on other's end, the other segment is cut into 2, the point of cut being the end of
* segment first being operated on. This is done so that the subsequent tests
* of connection, which do not test segment overlaps, will see this continuity.
*/
{
TRACK* segment;
TRACK* other;
int nn = 0;
int masquelayer;
int ii, percent, oldpercent;
wxString msg;
frame->Affiche_Message( wxT( "Gen Raccords sur Pistes:" ) );
if( frame->m_Pcb->GetNumSegmTrack() == 0 )
return;
frame->DrawPanel->m_AbortRequest = FALSE;
oldpercent = -1; ii = 0;
for( segment = frame->m_Pcb->m_Track; segment; segment = segment->Next() )
{
// display activity
ii++;
percent = (100 * ii) / frame->m_Pcb->m_NbSegmTrack;
if( percent != oldpercent )
{
frame->DisplayActivity( percent, wxT( "Tracks: " ) );
oldpercent = percent;
msg.Printf( wxT( "%d" ), frame->m_Pcb->m_NbSegmTrack );
Affiche_1_Parametre( frame, POS_AFF_MAX, wxT( "Max" ), msg, GREEN );
msg.Printf( wxT( "%d" ), ii );
Affiche_1_Parametre( frame, POS_AFF_NUMSEGM, wxT( "Segm" ), msg, CYAN );
}
if( frame->DrawPanel->m_AbortRequest )
return;
masquelayer = segment->ReturnMaskLayer();
// look at the "start" of the "segment"
for( other = frame->m_Pcb->m_Track; other; other = other->Next() )
{
TRACK* newTrack;
other = Locate_Pistes( other, segment->m_Start, masquelayer );
if( other == NULL )
break;
if( other == segment )
continue;
if( other->Type() == TYPEVIA )
continue;
if( segment->m_Start == other->m_Start )
continue;
if( segment->m_Start == other->m_End )
continue;
// Test if the "end" of this segment is already connected to other
if( segment->m_End == other->m_Start )
continue;
if( segment->m_End == other->m_End )
continue;
other->Draw( frame->DrawPanel, DC, GR_XOR );
nn++;
msg.Printf( wxT( "%d" ), nn );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxT( "New <" ), msg, YELLOW );
frame->m_Pcb->m_NbSegmTrack++;
// create a new segment and insert it next to "other", then shorten other.
newTrack = other->Copy();
newTrack->Insert( frame->m_Pcb, other );
other->m_End = segment->m_Start;
newTrack->m_Start = segment->m_Start;
Trace_Une_Piste( frame->DrawPanel, DC, other, 2, GR_OR );
// skip forward one, skipping the newTrack
other = newTrack;
}
// look at the "end" of the "segment"
for( other = frame->m_Pcb->m_Track; other; other = other->Next() )
{
TRACK* newTrack;
other = Locate_Pistes( other, segment->m_End, masquelayer );
if( other == NULL )
break;
if( other == segment )
continue;
if( other->Type() == TYPEVIA )
continue;
if( segment->m_End == other->m_Start )
continue;
if( segment->m_End == other->m_End )
continue;
if( segment->m_Start == other->m_Start )
continue;
if( segment->m_Start == other->m_End )
continue;
other->Draw( frame->DrawPanel, DC, GR_XOR );
nn++;
msg.Printf( wxT( "%d" ), nn );
Affiche_1_Parametre( frame, POS_AFF_VAR, wxT( "New >" ), msg, YELLOW );
frame->m_Pcb->m_NbSegmTrack++;
// create a new segment and insert it next to "other", then shorten other.
newTrack = other->Copy();
newTrack->Insert( frame->m_Pcb, other );
other->m_End = segment->m_End;
newTrack->m_Start = segment->m_End;
Trace_Une_Piste( frame->DrawPanel, DC, other, 2, GR_OR );
// skip forward one, skipping the newTrack
other = newTrack;