← Back to team overview

kicad-developers team mailing list archive

Re: Segvia and zone filling.

 

> With this patch, DRC recognizes that the vias are connected, and doesn't complain at all
> about them.


Dan & Tom,

Please re-test the revised patch, which has a better chance of being committed if it still
works.

And Dan, if you are interested in learning about what was changed, you might apply this to
a pristine testing checkout, then compare that branch to the other one you have now.


Thanks,

Dick


=== modified file 'pcbnew/class_netinfo.h'
--- pcbnew/class_netinfo.h	2012-04-17 01:35:43 +0000
+++ pcbnew/class_netinfo.h	2012-04-20 08:16:24 +0000
@@ -6,13 +6,14 @@
  *  Classes to handle info on nets
  */
 
-#ifndef __CLASSES_NETINFO__
-#define __CLASSES_NETINFO__
+#ifndef CLASSES_NETINFO_
+#define CLASSES_NETINFO_
 
 
 #include <vector>
 
 #include <class_netclass.h>
+#include <class_track.h>
 
 
 class wxDC;
@@ -90,6 +91,14 @@
 };
 
 
+typedef std::vector< NETINFO_ITEM* >    NETINFO_ITEMS;  ///< non-owning container
+
+typedef std::vector< D_PAD* >           D_PADS;         ///< non-owning container
+
+typedef std::vector< TRACK* >           TRACKS;         /// a non-owning container
+typedef TRACKS::iterator                TRACK_ITER;
+typedef TRACKS::const_iterator          TRACK_CITER;
+
 
 /**
  * Class NETINFO
@@ -101,6 +110,7 @@
     friend class BOARD;
 
 public:
+
     NETINFO_LIST( BOARD* aParent );
     ~NETINFO_LIST();
 
@@ -184,11 +194,23 @@
      */
     void buildPadsFullList();
 
-    BOARD*                      m_Parent;
-    std::vector<NETINFO_ITEM*>  m_NetBuffer;    ///< net list (name, design constraints ..)
-
-    std::vector<D_PAD*>         m_PadsFullList; ///< contains all pads, sorted by pad's netname.
-                                                ///< can be used in ratsnest calculations.
+    /**
+     * Function buildFloatingTracksList
+     * builds a list of floating tracks.
+     * Useful because tracks netcodes are propagateed from pads.
+     * if the track isn't connected to a pad its netcode is never updated
+     */
+    void buildFloatingTracksList();
+
+    BOARD*              m_Parent;
+
+    NETINFO_ITEMS       m_NetBuffer;    ///< net list (name, design constraints ..)
+
+    D_PADS              m_PadsFullList; ///< contains all pads, sorted by pad's netname.
+                                        ///< can be used in ratsnest calculations.
+
+    /// contains all tracks and segvia, sorted by netName.  No ownership.
+    TRACKS              m_floatingTracksList;
 };
 
 
@@ -410,4 +432,4 @@
 };
 
 
-#endif  // __CLASSES_NETINFO__
+#endif  // CLASSES_NETINFO_

=== modified file 'pcbnew/class_netinfolist.cpp'
--- pcbnew/class_netinfolist.cpp	2012-01-23 04:33:36 +0000
+++ pcbnew/class_netinfolist.cpp	2012-04-20 08:18:49 +0000
@@ -59,9 +59,8 @@
     return ( a->GetNetname().Cmp( b->GetNetname() ) ) < 0;
 }
 
-
 /**
- *  Compute and update the net_codes for PADS et and equipots (.m_NetCode member)
+ *  Compute and update the net_codes for PADS and floating tracks/vias (.m_NetCode member)
  *  net_codes are >= 1 (net_code = 0 means not connected)
  *  Update the net buffer
  *  Must be called after editing pads (netname, or deleting) or after read a netlist
@@ -87,6 +86,7 @@
 
     // Build the PAD list, sorted by net
     buildPadsFullList();
+    buildFloatingTracksList();
 
     // Build netnames list, and create a netcode for each netname
     D_PAD* last_pad = NULL;
@@ -102,13 +102,32 @@
             continue;
         }
 
-        /* if the current netname was already found: add pad to the current net_item ,
-         *  else create a new net_code and a new net_item
-         */
+        // if the current netname was already found: add pad to the current net_item ,
+        // else create a new net_code and a new net_item
         if( last_pad == NULL || ( pad->GetNetname() != last_pad->GetNetname() ) )
         {
+            // the netcode before it got switched;
+            int oldNetCode = pad->GetNet();
+
             netcode++;
-            net_item = new NETINFO_ITEM( (BOARD_ITEM*)m_Parent );
+
+            // Only ever get here once per net.
+            // Go through the track list and reset the netcode of all tracks
+            // having the same netcode as pad.  Then remove it from the list
+            for( TRACK_ITER it = m_floatingTracksList.begin(); it != m_floatingTracksList.end();  )
+            {
+                if( (*it)->GetNet() == oldNetCode )
+                {
+                    (*it)->SetNet( netcode );
+
+                    // no TRACK ownership here, so simply remove pointer.
+                    m_floatingTracksList.erase( it );
+                }
+                else
+                    ++it;
+            }
+
+            net_item = new NETINFO_ITEM( (BOARD_ITEM*) m_Parent );
             net_item->SetNet( netcode );
             net_item->SetNetname( pad->GetNetname() );
             AppendNet( net_item );
@@ -178,3 +197,19 @@
 
     m_Parent->m_Status_Pcb = LISTE_PAD_OK;
 }
+
+
+void NETINFO_LIST::buildFloatingTracksList()
+{
+    m_floatingTracksList.clear();
+    m_Parent->m_FullRatsnest.clear();
+
+    // Add the track to the floating track list
+    for( TRACK* track = m_Parent->m_Track;  track;  track = track->Next() )
+    {
+        if( track->IsFloating() )
+        {
+            m_floatingTracksList.push_back( track );
+        }
+    }
+}

=== modified file 'pcbnew/class_track.cpp'
--- pcbnew/class_track.cpp	2012-04-19 06:55:45 +0000
+++ pcbnew/class_track.cpp	2012-04-20 07:33:57 +0000
@@ -122,6 +122,7 @@
 TRACK::TRACK( BOARD_ITEM* aParent, KICAD_T idtype ) :
     BOARD_CONNECTED_ITEM( aParent, idtype )
 {
+    m_floating = true;
     m_Width = 0;
     m_Shape = S_SEGMENT;
     start   = end = NULL;

=== modified file 'pcbnew/class_track.h'
--- pcbnew/class_track.h	2012-04-17 01:35:43 +0000
+++ pcbnew/class_track.h	2012-04-20 08:03:22 +0000
@@ -27,8 +27,8 @@
  * @brief Definitions for tracks, vias and zones.
  */
 
-#ifndef CLASS_TRACK_H
-#define CLASS_TRACK_H
+#ifndef CLASS_TRACK_H_
+#define CLASS_TRACK_H_
 
 
 #include <class_board_item.h>
@@ -71,28 +71,18 @@
 
 class TRACK : public BOARD_CONNECTED_ITEM
 {
-    // make SetNext() and SetBack() private so that they may not be called from anywhere.
-    // list management is done on TRACKs using DLIST<TRACK> only.
-private:
-    void SetNext( EDA_ITEM* aNext )       { Pnext = aNext; }
-    void SetBack( EDA_ITEM* aBack )       { Pback = aBack; }
-
-
 public:
     int         m_Width;            // Thickness of track, or via diameter
     wxPoint     m_Start;            // Line start point
     wxPoint     m_End;              // Line end point
     int         m_Shape;            // vias: shape and type, Track = shape..
 
-protected:
-    int         m_Drill;            // for vias: via drill (- 1 for default value)
-
-public:
     BOARD_CONNECTED_ITEM* start;    // pointers to a connected item (pad or track)
     BOARD_CONNECTED_ITEM* end;
 
     double      m_Param;            // Auxiliary variable ( used in some computations )
 
+
 public:
     TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
 
@@ -111,6 +101,9 @@
 
     virtual void Flip( const wxPoint& aCentre );
 
+    void SetFloating( bool aFloating )          { m_floating = aFloating; }
+    bool IsFloating()                           { return m_floating; }
+
     void SetPosition( const wxPoint& aPos )     { m_Start = aPos; }     // was overload
     const wxPoint& GetPosition() const          { return m_Start; }     // was overload
 
@@ -348,6 +341,19 @@
     static wxString ShowState( int stateBits );
 
 #endif
+
+
+protected:
+    int         m_Drill;            // for vias: via drill (- 1 for default value)
+
+
+private:
+    // make SetNext() and SetBack() private so that they may not be called from anywhere.
+    // list management is done on TRACKs using DLIST<TRACK> only.
+    void SetNext( EDA_ITEM* aNext )       { Pnext = aNext; }
+    void SetBack( EDA_ITEM* aBack )       { Pback = aBack; }
+
+    bool        m_floating;         // True if this track is not connected to a pad somewhere in its subnet.
 };
 
 
@@ -426,5 +432,4 @@
 #endif
 };
 
-
-#endif /* CLASS_TRACK_H */
+#endif // CLASS_TRACK_H_

=== modified file 'pcbnew/connect.cpp'
--- pcbnew/connect.cpp	2012-02-19 04:02:19 +0000
+++ pcbnew/connect.cpp	2012-04-20 08:08:09 +0000
@@ -79,6 +79,7 @@
     const wxPoint & GetPoint() const { return m_point; }
 };
 
+
 // A helper class to handle connections calculations:
 class CONNECTIONS
 {
@@ -481,6 +482,7 @@
     sort( m_candidates.begin(), m_candidates.end(), sortConnectedPointByXthenYCoordinates );
 }
 
+
 int CONNECTIONS::SearchConnectedTracks( const TRACK * aTrack )
 {
     int count = 0;
@@ -527,6 +529,7 @@
     return count;
 }
 
+
 int CONNECTIONS::searchEntryPointInCandidatesList( const wxPoint & aPoint)
 {
     // Search the aPoint coordinates in m_Candidates
@@ -583,6 +586,7 @@
     return -1;
 }
 
+
 /* Used after a track change (delete a track ou add a track)
  * Connections to pads are recalculated
  * Note also aFirstTrack (and aLastTrack ) can be NULL
@@ -982,16 +986,18 @@
     GetBoard()->BuildListOfNets();
 
     // Reset variables and flags used in computation
-    curr_track = m_Pcb->m_Track;
-    for( ; curr_track != NULL; curr_track = curr_track->Next() )
+    for( curr_track = m_Pcb->m_Track;  curr_track;  curr_track = curr_track->Next() )
     {
         curr_track->m_TracksConnected.clear();
         curr_track->m_PadsConnected.clear();
         curr_track->start = NULL;
         curr_track->end = NULL;
         curr_track->SetState( BUSY | IN_EDIT | BEGIN_ONPAD | END_ONPAD, OFF );
+
+        curr_track->SetFloating( true );    // Set all tracks as floating
+
         curr_track->SetZoneSubNet( 0 );
-        curr_track->SetNet( 0 );    // net code = 0 means not connected
+//      curr_track->SetNet( 0 );    // net code = 0 means not connected
     }
 
     // If no pad, reset pointers and netcode, and do nothing else
@@ -1012,7 +1018,11 @@
     for( ; curr_track != NULL; curr_track = curr_track->Next() )
     {
         if( curr_track->m_PadsConnected.size() )
+        {
             curr_track->SetNet( curr_track->m_PadsConnected[0]->GetNet() );
+            curr_track->SetFloating( false );
+        }
+
     }
 
     // Pass 2: build connections between track ends
@@ -1024,37 +1034,47 @@
 
     // Propagate net codes from a segment to other connected segments
     bool new_pass_request = true;   // set to true if a track has its netcode changed from 0
-                                    // to a known netcode to re-evaluate netcodes
-                                    // of connected items
+    // to a known netcode to re-evaluate netcodes
+    // of connected items
     while( new_pass_request )
     {
         new_pass_request = false;
 
         for( curr_track = m_Pcb->m_Track; curr_track; curr_track = curr_track->Next() )
         {
-            int netcode = curr_track->GetNet();
-            if( netcode == 0 )
-            {   // try to find a connected item having a netcode
+            int     netcode = curr_track->GetNet();
+            bool    isFloating = curr_track->IsFloating();
+
+            if( isFloating )
+            {
+                // try to find a connected item having a which is not floating
                 for( unsigned kk = 0; kk < curr_track->m_TracksConnected.size(); kk++ )
                 {
-                    int altnetcode = curr_track->m_TracksConnected[kk]->GetNet();
-                    if( altnetcode )
+                    int     altnetcode  = curr_track->m_TracksConnected[kk]->GetNet();
+                    bool    altFloating = curr_track->m_TracksConnected[kk]->IsFloating();
+
+                    if( !altFloating )
                     {
                         new_pass_request = true;
                         netcode = altnetcode;
-                        curr_track->SetNet(netcode);
+                        curr_track->SetNet( netcode );
+                        curr_track->SetFloating( false );
+                        isFloating = altFloating;
                         break;
                     }
                 }
             }
-            if( netcode )    // this track has a netcode
-            {   // propagate this netcode to connected tracks having no netcode
+
+            if( !isFloating )    // this track is connected to something
+            {
+                // propagate this netcode to connected tracks that are still marked as floating
                 for( unsigned kk = 0; kk < curr_track->m_TracksConnected.size(); kk++ )
                 {
-                    int altnetcode = curr_track->m_TracksConnected[kk]->GetNet();
-                    if( altnetcode == 0 )
+                    bool altFloating = curr_track->m_TracksConnected[kk]->IsFloating();
+                    if( altFloating )
                     {
-                        curr_track->m_TracksConnected[kk]->SetNet(netcode);
+                        curr_track->m_TracksConnected[kk]->SetNet( netcode );
+                        curr_track->SetFloating( false );
                         new_pass_request = true;
                     }
                 }
@@ -1067,7 +1087,6 @@
 }
 
 
-
 /*
  * Function SortTracksByNetCode used in RebuildTrackChain()
  * to sort track segments by net code.
@@ -1077,6 +1096,7 @@
     return ref->GetNet() < compare->GetNet();
 }
 
+
 /**
  * Helper function RebuildTrackChain
  * rebuilds the track segment linked list in order to have a chain


Follow ups

References