Commit ebb967c4 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Pcbnew: fix issues and potential issues when reading board files and mainly...

Pcbnew: fix issues and potential issues when reading board files and mainly old board files, and enhance the DRC tests and Delete Single Pad Net option when reading a netlist:
* Delete Single Pad Net option does not delete the net if a zone use this net (i.e. is attached to this pad).
* pcb_parser accept now negative netcodes in zones (can happen with old files, which previously could crash Pcbnew)
* pcb_parser accept now files with incorrect or missing net count  (can happen with old files, which previously could crash Pcbnew)
* if a zone has a non-existent net name it now keep this net name, and DRC detect it (previously, the net name was lost, and the DRC did not tected this issue).
* Drc test: now detect a "dead" net, i.e. a net with 0 pads, but still used by a zone. It happens easily after a schematic modification, when a net disappears or is renamed.
parent 64dd1f74
Loading
Loading
Loading
Loading
+58 −14
Original line number Original line Diff line number Diff line
@@ -6,11 +6,11 @@
/*
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 *
 *
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
 * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
 *
 *
 * This program is free software; you can redistribute it and/or
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * modify it under the terms of the GNU General Public License
@@ -2459,14 +2459,14 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
        }
        }
    }
    }


    // If needed, remove the single pad nets:
    // We need the pad list, for next tests.
    if( aDeleteSinglePadNets && !aNetlist.IsDryRun() )
    // padlist is the list of pads, sorted by netname.
    {
    BuildListOfNets();
    BuildListOfNets();

    std::vector<D_PAD*> padlist = GetPads();
    std::vector<D_PAD*> padlist = GetPads();


        // padlist is the list of pads, sorted by netname.
    // If needed, remove the single pad nets:
    if( aDeleteSinglePadNets && !aNetlist.IsDryRun() )
    {
        int         count = 0;
        int         count = 0;
        wxString    netname;
        wxString    netname;
        D_PAD*      pad = NULL;
        D_PAD*      pad = NULL;
@@ -2482,6 +2482,28 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
            if( netname != pad->GetNetname() )  // End of net
            if( netname != pad->GetNetname() )  // End of net
            {
            {
                if( previouspad && count == 1 )
                if( previouspad && count == 1 )
                {
                    // First, see if we have a copper zone attached to this pad.
                    // If so, this is not really a single pad net

                    for( int ii = 0; ii < GetAreaCount(); ii++ )
                    {
                        ZONE_CONTAINER* zone = GetArea( ii );

                        if( !zone->IsOnCopperLayer() )
                            continue;

                        if( zone->GetIsKeepout() )
                            continue;

                        if( zone->GetNet() == previouspad->GetNet() )
                        {
                            count++;
                            break;
                        }
                    }

                    if( count == 1 )    // Really one pad, and nothing else
                    {
                    {
                        if( aReporter && aReporter->ReportAll() )
                        if( aReporter && aReporter->ReportAll() )
                        {
                        {
@@ -2494,6 +2516,8 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,


                        previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
                        previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
                    }
                    }
                }

                netname = pad->GetNetname();
                netname = pad->GetNetname();
                count = 1;
                count = 1;
            }
            }
@@ -2515,6 +2539,10 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
    // They should exist in footprints, otherwise the footprint is wrong
    // They should exist in footprints, otherwise the footprint is wrong
    // note also references or time stamps are updated, so we use only
    // note also references or time stamps are updated, so we use only
    // the reference to find a footprint
    // the reference to find a footprint
    //
    // Also verify if zones have acceptable nets, i.e. nets with pads.
    // Zone with no pad belongs to a "dead" net which happens after changes in schematic
    // when no more pad use this net name.
    if( aReporter && aReporter->ReportErrors() )
    if( aReporter && aReporter->ReportErrors() )
    {
    {
        wxString padname;
        wxString padname;
@@ -2543,6 +2571,22 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
                aReporter->Report( msg );
                aReporter->Report( msg );
            }
            }
        }
        }

        // Test copper zones to detect "dead" nets (nets without any pad):
        for( int ii = 0; ii < GetAreaCount(); ii++ )
        {
            ZONE_CONTAINER* zone = GetArea( ii );

            if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
                continue;

            if( zone->GetNet()->GetNodesCount() == 0 )
            {
                msg.Printf( _( "* Warning: copper zone (net name '%s'): net has no pad*\n" ),
                           GetChars( zone->GetNet()->GetNetname() ) );
                aReporter->Report( msg );
            }
        }
    }
    }
}
}


+4 −4
Original line number Original line Diff line number Diff line
/*
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
 * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
 *
 *
 * This program is free software; you can redistribute it and/or
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * modify it under the terms of the GNU General Public License
@@ -50,10 +50,10 @@ BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem )


void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode )
void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode )
{
{
    assert( aNetCode >= 0 );
//    assert( aNetCode >= 0 );
    BOARD* board = GetBoard();
    BOARD* board = GetBoard();


    if( board )
    if( ( aNetCode >= 0 ) && board )
        m_netinfo = board->FindNet( aNetCode );
        m_netinfo = board->FindNet( aNetCode );
    else
    else
        m_netinfo = &NETINFO_LIST::ORPHANED;
        m_netinfo = &NETINFO_LIST::ORPHANED;
+5 −3
Original line number Original line Diff line number Diff line
@@ -2,7 +2,7 @@
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 2007 Dick Hollenbeck, dick@softplc.com
 * Copyright (C) 2007 Dick Hollenbeck, dick@softplc.com
 * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
 * Copyright (C) 2015 KiCad Developers, see change_log.txt for contributors.
 *
 *
 * This program is free software; you can redistribute it and/or
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * modify it under the terms of the GNU General Public License
@@ -75,8 +75,10 @@ wxString DRC_ITEM::GetErrorText() const
        return wxString( _( "Copper area inside copper area" ) );
        return wxString( _( "Copper area inside copper area" ) );
    case COPPERAREA_CLOSE_TO_COPPERAREA:
    case COPPERAREA_CLOSE_TO_COPPERAREA:
        return wxString( _( "Copper areas intersect or are too close" ) );
        return wxString( _( "Copper areas intersect or are too close" ) );
    case DRCE_NON_EXISTANT_NET_FOR_ZONE_OUTLINE:

        return wxString( _( "Copper area has a nonexistent net name" ) );
    case DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE:
        return wxString( _( "Copper area belongs a net which has no pads. This is strange" ) );

    case DRCE_HOLE_NEAR_PAD:
    case DRCE_HOLE_NEAR_PAD:
        return wxString( _( "Hole near pad" ) );
        return wxString( _( "Hole near pad" ) );
    case DRCE_HOLE_NEAR_TRACK:
    case DRCE_HOLE_NEAR_TRACK:
+1 −1
Original line number Original line Diff line number Diff line
@@ -320,7 +320,7 @@ public:
            return NULL;
            return NULL;
    }
    }


    ///> Constant that holds the unconnected net number
    ///> Constant that holds the unconnected net number (typically 0)
    static const int UNCONNECTED;
    static const int UNCONNECTED;


    ///> NETINFO_ITEM meaning that there was no net assigned for an item, as there was no
    ///> NETINFO_ITEM meaning that there was no net assigned for an item, as there was no
+9 −15
Original line number Original line Diff line number Diff line
/*
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
 * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
 *
 *
 * This program is free software; you can redistribute it and/or
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * modify it under the terms of the GNU General Public License
@@ -625,27 +625,21 @@ void ZONE_CONTAINER::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
    {
    {
        if( GetNetCode() >= 0 )
        if( GetNetCode() >= 0 )
        {
        {
            NETINFO_ITEM* equipot = GetNet();
            NETINFO_ITEM* net = GetNet();


            if( equipot )
            if( net )
                msg = equipot->GetNetname();
                msg = net->GetNetname();
            else
            else    // Should not occur
                msg = wxT( "<noname>" );
                msg = _( "<unknown>" );
        }
        }
        else    // a netcode < 0 is an error
        else    // a netcode < 0 is an error
        {
            msg = wxT( "<error>" );
            msg = wxT( " [" );
            msg << GetNetname() + wxT( "]" );
            msg << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
        }


        aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
        aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );


#if 1
        // Display net code : (useful in test or debug)
        // Display net code : (useful in test or debug)
        msg.Printf( wxT( "%d" ), GetNetCode() );
        msg.Printf( wxT( "%d" ), GetNetCode() );
        aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
        aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
#endif


        // Display priority level
        // Display priority level
        msg.Printf( wxT( "%d" ), GetPriority() );
        msg.Printf( wxT( "%d" ), GetPriority() );
Loading