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

Pcbnew: read netlist enhancements: add option to remove single pads nets, add...

Pcbnew: read netlist enhancements: add option to remove single pads nets, add enforce tests to report non existing netnames in zones.
Fix also some very minor errors in comments.
parent 3d40bd7e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1451,6 +1451,8 @@ public:
     * @param aSelectByTimestamp if true, use timestamp instead of reference to identify
     *                           footprints from components (use after reannotation of the
     *                           schematic)
     * @param aDeleteSinglePadNets if true, remove nets counting only one pad
     *                             and set net code to 0 for these pads
     * @param aIsDryRun performs a dry run without making any changes if true.
     */
    void ReadPcbNetlist( const wxString&  aNetlistFileName,
@@ -1460,6 +1462,7 @@ public:
                         bool             aDeleteBadTracks,
                         bool             aDeleteExtraFootprints,
                         bool             aSelectByTimestamp,
                         bool             aDeleteSinglePadNets,
                         bool             aIsDryRun );

    /**
+75 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
#include <msgpanel.h>
#include <netlist_reader.h>
#include <reporter.h>
#include <base_units.h>

#include <pcbnew.h>
#include <colors_selection.h>
@@ -2332,7 +2333,8 @@ bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE_CONTAI
}


void BOARD::ReplaceNetlist( NETLIST& aNetlist, REPORTER* aReporter )
void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
                            REPORTER* aReporter )
{
    unsigned       i;
    wxPoint        bestPosition;
@@ -2603,7 +2605,53 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, REPORTER* aReporter )
        }
    }

    // Last step: verify all pads found in netlist:
    // If needed, remove the single pad nets:
    if( aDeleteSinglePadNets && !aNetlist.IsDryRun() )
    {
        BuildListOfNets();
        std::vector<D_PAD*> padlist = GetPads();
        // padlist is the list of pads, sorted by netname.
        int count = 0;
        wxString netname;
        D_PAD * pad = NULL;
        D_PAD * previouspad = NULL;
        for( unsigned ii = 0; ii < padlist.size(); ii++ )
        {
            pad = padlist[ii];

            if( pad->GetNetname().IsEmpty() )
                continue;

            if( netname != pad->GetNetname() )  // End of net
            {
                if( previouspad && count == 1 )
                {
                    if( aReporter && aReporter->ReportAll() )
                    {
                        msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad <%s>\n" ),
                                    GetChars( pad->GetNetname() ),
                                    GetChars( pad->GetParent()->GetReference() ),
                                    GetChars( previouspad->GetPadName() ) );
                        aReporter->Report( msg );
                    }
                    previouspad->SetNetname( wxEmptyString );
                }
                netname = pad->GetNetname();
                count = 1;
            }
            else
                count++;

            previouspad = pad;
        }

        // Examine last pad
        if( pad && count == 1 )
            pad->SetNetname( wxEmptyString );
    }

    // Last step: Some tests:
    // verify all pads found in netlist:
    // They should exist in footprints, otherwise the footprint is wrong
    // note also references or time stamps are updated, so we use only
    // the reference to find a footprint
@@ -2636,5 +2684,30 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, REPORTER* aReporter )
            }
        }
    }

    // Verify zone net names validity:
    // After schematic changes, a zone can have a non existing net name.
    // It should be reported
    if( aReporter && aReporter->ReportErrors() )
    {
        //Loop through all copper zones
        for( i = 0; i < m_ZoneDescriptorList.size(); i++ )
        {
            ZONE_CONTAINER* zone = m_ZoneDescriptorList[i];

            if( zone->GetNet() >= 0 || !zone->IsOnCopperLayer() )
                continue;

            // Net name not valid, report error
            wxString coord;
            coord << zone->GetPosition();
            msg.Printf( _( "** Error: Zone %s layer <%s>"
                           " has non-existent net name \"%s\" **\n" ),
                        GetChars( coord ),
                        GetChars( zone->GetLayerName() ),
                        GetChars( zone->GetNetName() ) );
            aReporter->Report( msg );
        }
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -927,10 +927,13 @@ public:
     *   any extra unlock footprints are removed from the #BOARD.
     *
     * @param aNetlist is the new netlist to revise the contents of the #BOARD with.
     * @param aDeleteSinglePadNets if true, remove nets counting only one pad
     *                             and set net code to 0 for these pads
     * @param aReporter is a #REPORTER object to report the changes \a aNetlist makes to
     *                  the #BOARD.  If NULL, no change reporting occurs.
     */
    void ReplaceNetlist( NETLIST& aNetlist, REPORTER* aReporter = NULL );
    void ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
                         REPORTER* aReporter = NULL );

    /**
     * Function ReturnSortedNetnamesList
+1 −1
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ private:
    void clear();

    /**
     * Function BuildListOfNets
     * Function buildListOfNets
     * builds or rebuilds the list of NETINFO_ITEMs
     * The list is sorted by names.
     */
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ static bool padlistSortByNetnames( const D_PAD* a, const D_PAD* b )
 * Be aware NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname )
 * when search a net by its net name does a binary search
 * and expects to have a nets list sorted by an alphabetic case sensitive sort
 * So do not change Build_Pads_Full_List() taht build a sorted list of pads
 * So do not change Build_Pads_Full_List() which build a sorted list of pads
 */
void NETINFO_LIST::buildListOfNets()
{
Loading