~bidulock/kicad/kicad-brian

« back to all changes in this revision

Viewing changes to eeschema/netlist.cpp

  • Committer: Brian F. G. Bidulock
  • Date: 2010-06-30 12:43:10 UTC
  • mfrom: (2360.3.47 testing)
  • Revision ID: brian@habeascorpus-20100630124310-9p4sig3zj1gqnlqd
mergedĀ upstreamĀ changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus );
24
24
static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel );
25
 
static void ListeObjetConnection( SCH_SHEET_PATH*      sheetlist,
26
 
                                  NETLIST_OBJECT_LIST& aNetItemBuffer );
 
25
static void AddConnectedObjects( SCH_SHEET_PATH*      sheetlist,
 
26
                                 NETLIST_OBJECT_LIST& aNetItemBuffer );
27
27
static int  ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer, NETLIST_OBJECT& ObjNet );
28
28
static void PointToPointConnect( NETLIST_OBJECT* Ref, int IsBus, int start );
29
29
static void SegmentToPointConnect( NETLIST_OBJECT* Jonction, int IsBus, int start );
31
31
static void ConnectBusLabels( NETLIST_OBJECT_LIST& aNetItemBuffer );
32
32
static void SetUnconnectedFlag( NETLIST_OBJECT_LIST& aNetItemBuffer );
33
33
 
 
34
static void FindBestNetNameForEachNet( NETLIST_OBJECT_LIST& aNetItemBuffer );
 
35
static NETLIST_OBJECT* FindBestNetName( NETLIST_OBJECT_LIST& aLabelItemBuffer );
 
36
 
34
37
// Sort functions used here:
35
38
static bool SortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 );
36
39
static bool SortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 );
37
40
 
 
41
// Local variables
38
42
static int FirstNumWireBus, LastNumWireBus, RootBusNameLength;
39
43
static int LastNetCode, LastBusNetCode;
40
44
 
93
97
 
94
98
    sheet = SheetListList.GetFirst();
95
99
    for( ; sheet != NULL; sheet = SheetListList.GetNext() )
96
 
        ListeObjetConnection( sheet, g_NetObjectslist );
 
100
        AddConnectedObjects( sheet, g_NetObjectslist );
97
101
 
98
102
    if( g_NetObjectslist.size() == 0 )
99
103
        return;  // no objects
290
294
 
291
295
    /* Assignment of m_FlagOfConnection based connection or not. */
292
296
    SetUnconnectedFlag( g_NetObjectslist );
293
 
}
294
 
 
 
297
 
 
298
    /* find the best label object to give the best net name to each net */
 
299
    FindBestNetNameForEachNet( g_NetObjectslist );
 
300
}
 
301
 
 
302
 
 
303
/** function FindBestNetNameForEachNet
 
304
 * fill the .m_NetNameCandidate member of each item of aNetItemBuffer
 
305
 * with a reference to the "best" NETLIST_OBJECT usable to give a name to the net
 
306
 * If no suitable object found, .m_NetNameCandidate is filled with 0.
 
307
 * The "best" NETLIST_OBJECT is a NETLIST_OBJECT that have the type label
 
308
 * and by priority order:
 
309
 * the label is global or local
 
310
 * the label is in the first sheet in a hierarchy (the root sheet has the most priority)
 
311
 * alphabetic order.
 
312
 */
 
313
void FindBestNetNameForEachNet( NETLIST_OBJECT_LIST& aNetItemBuffer )
 
314
{
 
315
    NETLIST_OBJECT_LIST candidates;
 
316
    int netcode = 0;            // current netcode for tested items
 
317
    unsigned idxstart = 0;       // index of the first item of this net
 
318
    for( unsigned ii = 0; ii <= aNetItemBuffer.size(); ii++ )
 
319
    {
 
320
        NETLIST_OBJECT* item;
 
321
 
 
322
        if( ii == aNetItemBuffer.size() ) // last item already found
 
323
            netcode = -2;
 
324
        else
 
325
            item = aNetItemBuffer[ii];
 
326
        if( netcode != item->GetNet() )      // End of net found
 
327
        {
 
328
            if( candidates.size() )         // O,e or more labels exists, find the best
 
329
            {
 
330
                NETLIST_OBJECT* bestlabel = FindBestNetName( candidates );
 
331
                for (unsigned jj = idxstart; jj < ii; jj++ )
 
332
                    aNetItemBuffer[jj]->m_NetNameCandidate = bestlabel;
 
333
            }
 
334
            if( netcode == -2 )
 
335
                break;
 
336
            netcode = item->GetNet();
 
337
            candidates.clear();
 
338
            idxstart = ii;
 
339
        }
 
340
        switch( item->m_Type )
 
341
        {
 
342
        case NET_HIERLABEL:
 
343
        case NET_LABEL:
 
344
        case NET_PINLABEL:
 
345
            candidates.push_back( item );
 
346
            break;
 
347
 
 
348
        default:
 
349
            break;
 
350
        }
 
351
    }
 
352
}
 
353
 
 
354
/** Function FindBestNetName
 
355
 * @return a reference to the "best" label that can be used to give a name
 
356
 *  to a net.
 
357
 * @param aLabelItemBuffer = list of NETLIST_OBJECT type labels candidates.
 
358
 *  labels are local labels, hierarchical labels or pin labels
 
359
 *   labels in included sheets have a lower priority than labels in the current sheet.
 
360
 *     so labels inside the root sheet have the highter priority.
 
361
 *   pin labels are global labels and have the highter priority
 
362
 *   local labels have the lower priority
 
363
 *   labels having the same priority are sorted by alphabetic order.
 
364
 *
 
365
 */
 
366
static NETLIST_OBJECT* FindBestNetName( NETLIST_OBJECT_LIST& aLabelItemBuffer )
 
367
{
 
368
    if( aLabelItemBuffer.size() == 0 )
 
369
        return NULL;
 
370
 
 
371
    NETLIST_OBJECT*item = aLabelItemBuffer[0];
 
372
 
 
373
    for( unsigned ii = 1; ii < aLabelItemBuffer.size(); ii++ )
 
374
    {
 
375
        NETLIST_OBJECT* candidate = aLabelItemBuffer[ii];
 
376
        if( candidate->m_SheetList.Path().Length() < item->m_SheetList.Path().Length() )
 
377
        {
 
378
            item = candidate;
 
379
            continue;
 
380
        }
 
381
        switch ( item->m_Type )
 
382
        {
 
383
            case NET_HIERLABEL:
 
384
                if( candidate->m_Type == NET_PINLABEL )
 
385
                    item = candidate;
 
386
                else if( candidate->m_Type == NET_HIERLABEL )
 
387
                {
 
388
                    if( candidate->m_Label.Cmp( item->m_Label ) < 0 )
 
389
                        item = candidate;
 
390
                }
 
391
                break;
 
392
 
 
393
            case NET_LABEL:
 
394
                if( candidate->m_Type == NET_LABEL )
 
395
                {
 
396
                    if( candidate->m_Label.Cmp( item->m_Label ) < 0 )
 
397
                        item = candidate;
 
398
                }
 
399
                else
 
400
                    item = candidate;
 
401
                break;
 
402
 
 
403
            case NET_PINLABEL:
 
404
                if( candidate->m_Type != NET_PINLABEL )
 
405
                    break;
 
406
                if( candidate->m_Label.Cmp( item->m_Label ) < 0 )
 
407
                    item = candidate;
 
408
                break;
 
409
 
 
410
            default:    // Should not occur.
 
411
                break;
 
412
       }
 
413
    }
 
414
    return item;
 
415
}
295
416
 
296
417
/*
297
418
 * Connect sheets by sheetLabels
318
439
        if( ObjetNet->GetNet() == SheetLabel->GetNet() )
319
440
            continue;  //already connected.
320
441
 
321
 
        wxASSERT( ObjetNet->m_Label );
322
 
        wxASSERT( SheetLabel->m_Label );
323
 
        if( ObjetNet->m_Label->CmpNoCase( *SheetLabel->m_Label ) != 0 )
 
442
        if( ObjetNet->m_Label.CmpNoCase( SheetLabel->m_Label ) != 0 )
324
443
            continue;  //different names.
325
444
 
326
445
        /* Propagate Netcode having all the objects of the same Netcode. */
332
451
}
333
452
 
334
453
 
335
 
/** Function ListeObjetConnection
 
454
/** Function AddConnectedObjects
336
455
 * Creates the list of objects related to connections (pins of components,
337
456
 * wires, labels, junctions ...)
338
457
 *
340
459
 * @param aNetItemBuffer: a std::vector to store pointer on NETLIST_OBJECT
341
460
 *                        created
342
461
 */
343
 
static void ListeObjetConnection( SCH_SHEET_PATH*               sheetlist,
344
 
                                  std::vector<NETLIST_OBJECT*>& aNetItemBuffer )
 
462
static void AddConnectedObjects( SCH_SHEET_PATH*               sheetlist,
 
463
                                 std::vector<NETLIST_OBJECT*>& aNetItemBuffer )
345
464
{
346
465
    int             ii;
347
466
    SCH_ITEM*       DrawList;
349
468
    SCH_COMPONENT*  DrawLibItem;
350
469
    LIB_COMPONENT*  Entry;
351
470
    LIB_PIN*        pin;
352
 
    SCH_SHEET_PIN*  SheetLabel;
353
471
    SCH_SHEET_PATH  list;
354
472
 
355
473
    DrawList = sheetlist->LastScreen()->EEDrawList;
426
544
            if( STRUCT->m_Layer ==  LAYER_HIERLABEL )
427
545
                new_item->m_Type = NET_HIERLABEL;
428
546
 
429
 
            new_item->m_Label = &STRUCT->m_Text;
 
547
            new_item->m_Label = STRUCT->m_Text;
430
548
            new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
431
549
 
432
550
            aNetItemBuffer.push_back( new_item );
455
573
            if( STRUCT->m_Layer ==  LAYER_HIERLABEL )
456
574
                new_item->m_Type = NET_HIERLABEL;
457
575
 
458
 
            new_item->m_Label = &STRUCT->m_Text;
 
576
            new_item->m_Label = STRUCT->m_Text;
459
577
            new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
460
578
            aNetItemBuffer.push_back( new_item );
461
579
 
501
619
                new_item->m_Link = DrawLibItem;
502
620
                new_item->m_ElectricalType = pin->m_PinType;
503
621
                new_item->m_PinNum = pin->m_PinNum;
504
 
                new_item->m_Label  = &pin->m_PinName;
 
622
                new_item->m_Label  = pin->m_PinName;
505
623
                new_item->m_Start  = new_item->m_End = pos2;
506
624
 
507
625
                aNetItemBuffer.push_back( new_item );
515
633
                    new_item->m_Comp = NULL;
516
634
                    new_item->m_SheetList = *sheetlist;
517
635
                    new_item->m_Type  = NET_PINLABEL;
518
 
                    new_item->m_Label = &pin->m_PinName;
 
636
                    new_item->m_Label = pin->m_PinName;
519
637
                    new_item->m_Start = pos2;
520
638
                    new_item->m_End   = new_item->m_Start;
521
639
 
532
650
            break;
533
651
 
534
652
        case DRAW_SHEET_STRUCT_TYPE:
 
653
        {
535
654
            #undef STRUCT
536
655
            #define STRUCT ( (SCH_SHEET*) DrawList )
537
656
            list = *sheetlist;
538
657
            list.Push( STRUCT );
539
 
            SheetLabel = STRUCT->m_Label;
540
 
            for( ; SheetLabel != NULL; SheetLabel = SheetLabel->Next() )
 
658
            SCH_SHEET* sheet = (SCH_SHEET*) DrawList;
 
659
 
 
660
            BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() )
541
661
            {
542
 
                ii = IsBusLabel( SheetLabel->m_Text );
 
662
                ii = IsBusLabel( label.m_Text );
543
663
                new_item = new NETLIST_OBJECT();
544
664
                new_item->m_SheetListInclude = *sheetlist;
545
 
                new_item->m_Comp = SheetLabel;
 
665
                new_item->m_Comp = &label;
546
666
                new_item->m_SheetList = *sheetlist;
547
667
                new_item->m_Link = DrawList;
548
668
                new_item->m_Type = NET_SHEETLABEL;
549
 
                new_item->m_ElectricalType = SheetLabel->m_Shape;
550
 
                new_item->m_Label = &SheetLabel->m_Text;
 
669
                new_item->m_ElectricalType = label.m_Shape;
 
670
                new_item->m_Label = label.m_Text;
551
671
                new_item->m_SheetListInclude = list;
552
 
                new_item->m_Start = new_item->m_End = SheetLabel->m_Pos;
 
672
                new_item->m_Start = new_item->m_End = label.m_Pos;
553
673
                aNetItemBuffer.push_back( new_item );
554
674
 
555
675
                if( ii )
557
677
            }
558
678
 
559
679
            break;
 
680
        }
560
681
 
561
682
        case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
562
683
        default:
563
684
        {
564
685
            wxString msg;
565
686
            msg.Printf( wxT( "Netlist: unexpected struct type %d" ),
566
 
                        DrawList->Type() );
 
687
                       DrawList->Type() );
567
688
            wxMessageBox( msg );
568
689
            break;
569
690
        }
663
784
    }
664
785
 
665
786
    if( !BufLine.ToLong( &tmp ) )
666
 
        error = TRUE; ;
 
787
        error = TRUE;;
667
788
    LastNumWireBus = tmp;
668
789
 
669
790
    if( FirstNumWireBus < 0 )
707
828
        BusLabel.m_Type = NET_BUSLABELMEMBER;
708
829
 
709
830
    /* Conversion of BusLabel to the root Label name + the member id like mybus0, mybus1 ... */
710
 
    BufLine = BusLabel.m_Label->Left( RootBusNameLength );
 
831
    BufLine = BusLabel.m_Label.Left( RootBusNameLength );
711
832
 
712
833
    BusMember = FirstNumWireBus;
713
834
    BufLine << BusMember;
714
 
    BusLabel.m_Label = new wxString( BufLine );
 
835
    BusLabel.m_Label = BufLine;
715
836
 
716
837
    BusLabel.m_Member = BusMember;
717
838
    NumItem = 1;
722
843
        NumItem++;
723
844
 
724
845
        /* Conversion of BusLabel to the root name + the current member id.*/
725
 
        BufLine = BusLabel.m_Label->Left( RootBusNameLength );
 
846
        BufLine = BusLabel.m_Label.Left( RootBusNameLength );
726
847
        BufLine << BusMember;
727
 
        new_label->m_Label = new wxString( BufLine );
 
848
        new_label->m_Label = BufLine;
728
849
 
729
850
        new_label->m_Member = BusMember;
730
851
        aNetItemBuffer.push_back( new_label );
974
1095
             || ntype == NET_HIERBUSLABELMEMBER
975
1096
             || ntype == NET_PINLABEL )
976
1097
        {
977
 
            if( g_NetObjectslist[i]->m_Label->CmpNoCase( *LabelRef->m_Label )
978
 
                != 0 )
 
1098
            if( g_NetObjectslist[i]->m_Label.CmpNoCase( LabelRef->m_Label ) != 0 )
979
1099
                continue;
980
1100
 
981
1101
            if( g_NetObjectslist[i]->GetNet() )
982
 
                PropageNetCode(
983
 
                    g_NetObjectslist[i]->GetNet(), LabelRef->GetNet(), 0 );
 
1102
                PropageNetCode( g_NetObjectslist[i]->GetNet(), LabelRef->GetNet(), 0 );
984
1103
            else
985
1104
                g_NetObjectslist[i]->SetNet( LabelRef->GetNet() );
986
1105
        }