KiCad PCB EDA Suite
zones_polygons_test_connections.cpp File Reference
#include <algorithm>
#include <fctsys.h>
#include <common.h>
#include <macros.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <pcbnew.h>
#include <zones.h>
#include <polygon_test_point_inside.h>

Go to the source code of this file.

Functions

static bool CmpZoneSubnetValue (const BOARD_CONNECTED_ITEM *a, const BOARD_CONNECTED_ITEM *b)
 
void Merge_SubNets_Connected_By_CopperAreas (BOARD *aPcb, int aNetcode)
 Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb, int aNetcode) Used after connections by tracks calculations Merge subnets, in tracks ans pads when they are connected by a filled copper area for pads, this is the .m_physical_connexion member which is tested and modified for tracks, this is the .m_Subnet member which is tested and modified these members are block numbers (or cluster numbers) for a given net, calculated by Build_Pads_Info_Connections_By_Tracks() The result is merging 2 blocks (or subnets) More...
 
bool sort_areas (const ZONE_CONTAINER *ref, const ZONE_CONTAINER *tst)
 
void Merge_SubNets_Connected_By_CopperAreas (BOARD *aPcb)
 Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb) Calls Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode ) for each netcode found in zone list. More...
 

Function Documentation

static bool CmpZoneSubnetValue ( const BOARD_CONNECTED_ITEM a,
const BOARD_CONNECTED_ITEM b 
)
static

Definition at line 401 of file zones_polygons_test_connections.cpp.

References BOARD_CONNECTED_ITEM::GetZoneSubNet().

Referenced by Merge_SubNets_Connected_By_CopperAreas().

402 {
403  int asubnet, bsubnet;
404 
405  asubnet = a->GetZoneSubNet();
406  bsubnet = b->GetZoneSubNet();
407 
408  return asubnet < bsubnet;
409 }
int GetZoneSubNet() const
Function GetZoneSubNet.
void Merge_SubNets_Connected_By_CopperAreas ( BOARD aPcb,
int  aNetcode 
)

Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb, int aNetcode) Used after connections by tracks calculations Merge subnets, in tracks ans pads when they are connected by a filled copper area for pads, this is the .m_physical_connexion member which is tested and modified for tracks, this is the .m_Subnet member which is tested and modified these members are block numbers (or cluster numbers) for a given net, calculated by Build_Pads_Info_Connections_By_Tracks() The result is merging 2 blocks (or subnets)

Parameters
aPcb= the current board
aNetcode= netcode to consider

Definition at line 281 of file zones_polygons_test_connections.cpp.

References CmpZoneSubnetValue(), BOARD::FindNet(), BOARD::GetArea(), BOARD::GetAreaCount(), DHEAD::GetCount(), DLIST< T >::GetFirst(), BOARD_CONNECTED_ITEM::GetNetCode(), TRACK::GetStartNetCode(), BOARD_CONNECTED_ITEM::GetSubNet(), BOARD_CONNECTED_ITEM::GetZoneSubNet(), NETINFO_ITEM::m_PadInNetList, BOARD::m_Track, max, TRACK::Next(), and BOARD_CONNECTED_ITEM::SetSubNet().

Referenced by Merge_SubNets_Connected_By_CopperAreas().

282 {
283  // Ensure a zone with the given netcode exists: examine all zones:
284  bool found = false;
285 
286  for( int index = 0; index < aPcb->GetAreaCount(); index++ )
287  {
288  ZONE_CONTAINER* zone = aPcb->GetArea( index );
289 
290  if( aNetcode == zone->GetNetCode() )
291  {
292  found = true;
293  break;
294  }
295  }
296 
297  if( !found ) // No zone with this netcode, therefore no connection by zone
298  return;
299 
300  // list of pads and tracks candidates to test:
301  // It is static to avoid multiple memory realloc.
302  static std::vector <BOARD_CONNECTED_ITEM*> Candidates;
303  Candidates.clear();
304 
305  // Build the list of pads candidates connected to the net:
306  NETINFO_ITEM* net = aPcb->FindNet( aNetcode );
307  wxASSERT( net );
308  Candidates.reserve( net->m_PadInNetList.size() );
309  for( unsigned ii = 0; ii < net->m_PadInNetList.size(); ii++ )
310  Candidates.push_back( net->m_PadInNetList[ii] );
311 
312  // Build the list of track candidates connected to the net:
313  TRACK* track;
314 
315  if( aPcb->m_Track.GetCount() > 0 )
316  {
317  track = aPcb->m_Track.GetFirst()->GetStartNetCode( aNetcode );
318 
319  for( ; track; track = track->Next() )
320  {
321  if( track->GetNetCode() != aNetcode )
322  break;
323 
324  Candidates.push_back( track );
325  }
326  }
327 
328  if( Candidates.size() == 0 )
329  return;
330 
331  int next_subnet_free_number = 0;
332  for( unsigned ii = 0; ii < Candidates.size(); ii++ )
333  {
334  int subnet = Candidates[ii]->GetSubNet();
335  next_subnet_free_number = std::max( next_subnet_free_number, subnet );
336  }
337 
338  next_subnet_free_number++; // This is a subnet we can use with not connected items
339  // by tracks, but connected by zone.
340 
341  // Sort by zone_subnet:
342  sort( Candidates.begin(), Candidates.end(), CmpZoneSubnetValue );
343 
344  // Some items can be not connected, but they can be connected to a filled area:
345  // give them a subnet common to these items connected only by the area,
346  // and not already used.
347  // a value like next_subnet_free_number+zone_subnet is right
348  for( unsigned jj = 0; jj < Candidates.size(); jj++ )
349  {
350  BOARD_CONNECTED_ITEM* item = Candidates[jj];
351  if ( item->GetSubNet() == 0 && (item->GetZoneSubNet() > 0) )
352  {
353  item->SetSubNet( next_subnet_free_number + item->GetZoneSubNet() );
354  }
355  }
356 
357  // Now, for each zone subnet, we search for 2 items with different subnets.
358  // if found, the 2 subnet are merged in the whole candidate list.
359  int old_subnet = 0;
360  int old_zone_subnet = 0;
361  for( unsigned ii = 0; ii < Candidates.size(); ii++ )
362  {
363  BOARD_CONNECTED_ITEM* item = Candidates[ii];
364  int zone_subnet = item->GetZoneSubNet();
365 
366  if( zone_subnet == 0 ) // Not connected by a filled area, skip it
367  continue;
368 
369  int subnet = item->GetSubNet();
370 
371  if( zone_subnet != old_zone_subnet ) // a new zone subnet is found
372  {
373  old_subnet = subnet;
374  old_zone_subnet = zone_subnet;
375  continue;
376  }
377 
378  // 2 successive items already from the same cluster: nothing to do
379  if( subnet == old_subnet )
380  continue;
381 
382  // Here we have 2 items connected by the same area have 2 differents subnets: merge subnets
383  if( (subnet > old_subnet) || ( subnet <= 0) )
384  std::swap( subnet, old_subnet );
385 
386  for( unsigned jj = 0; jj < Candidates.size(); jj++ )
387  {
388  BOARD_CONNECTED_ITEM * item_to_merge = Candidates[jj];
389 
390  if( item_to_merge->GetSubNet() == old_subnet )
391  item_to_merge->SetSubNet( subnet );
392  }
393 
394  old_subnet = subnet;
395  }
396 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
D_PADS m_PadInNetList
List of pads connected to this net.
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
static bool CmpZoneSubnetValue(const BOARD_CONNECTED_ITEM *a, const BOARD_CONNECTED_ITEM *b)
int GetZoneSubNet() const
Function GetZoneSubNet.
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
void SetSubNet(int aSubNetCode)
int GetNetCode() const
Function GetNetCode.
Class NETINFO_ITEM handles the data for a net.
TRACK * Next() const
Definition: class_track.h:97
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:1022
TRACK * GetStartNetCode(int NetCode)
#define max(a, b)
Definition: auxiliary.h:86
int GetSubNet() const
Function GetSubNet.
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
DLIST< TRACK > m_Track
Definition: class_board.h:244
void Merge_SubNets_Connected_By_CopperAreas ( BOARD aPcb)

Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb) Calls Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode ) for each netcode found in zone list.

Parameters
aPcb= the current board

Definition at line 252 of file zones_polygons_test_connections.cpp.

References BOARD::GetArea(), BOARD::GetAreaCount(), BOARD_CONNECTED_ITEM::GetNetCode(), ZONE_CONTAINER::IsOnCopperLayer(), and Merge_SubNets_Connected_By_CopperAreas().

Referenced by PCB_BASE_FRAME::TestConnections(), and PCB_BASE_FRAME::TestNetConnection().

253 {
254  for( int index = 0; index < aPcb->GetAreaCount(); index++ )
255  {
256  ZONE_CONTAINER* zone = aPcb->GetArea( index );
257 
258  if ( ! zone->IsOnCopperLayer() )
259  continue;
260 
261  if ( zone->GetNetCode() <= 0 )
262  continue;
263 
265  }
266 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
void Merge_SubNets_Connected_By_CopperAreas(BOARD *aPcb, int aNetcode)
Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb, int aNetcode) Used after connections by ...
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
int GetNetCode() const
Function GetNetCode.
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.h:166
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:1022
bool sort_areas ( const ZONE_CONTAINER ref,
const ZONE_CONTAINER tst 
)

Definition at line 51 of file zones_polygons_test_connections.cpp.

References ZONE_CONTAINER::GetFilledPolysList(), BOARD_CONNECTED_ITEM::GetNetCode(), and SHAPE_POLY_SET::TotalVertices().

Referenced by BOARD::Test_Connections_To_Copper_Areas().

52 {
53  if( ref->GetNetCode() == tst->GetNetCode() )
54  return ref->GetFilledPolysList().TotalVertices() <
56  else
57  return ref->GetNetCode() < tst->GetNetCode();
58 }
int TotalVertices() const
Returns total number of vertices stored in the set.
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:470
int GetNetCode() const
Function GetNetCode.