2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file zones_polygons_test_connections.cpp
|
|
|
|
*/
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* 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) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
#include <algorithm> // sort
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_zone.h>
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <zones.h>
|
2012-07-31 17:51:58 +00:00
|
|
|
#include <polygon_test_point_inside.h>
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
static bool CmpZoneSubnetValue( const BOARD_CONNECTED_ITEM* a, const BOARD_CONNECTED_ITEM* b );
|
2013-01-25 17:29:54 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode );
|
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// This helper function sort a list of zones by netcode,
|
|
|
|
// and for a given netcode by zone size
|
|
|
|
// zone size = size of the m_FilledPolysList buffer
|
|
|
|
bool sort_areas( const ZONE_CONTAINER* ref, const ZONE_CONTAINER* tst )
|
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
if( ref->GetNetCode() == tst->GetNetCode() )
|
2015-07-27 19:45:57 +00:00
|
|
|
return ref->GetFilledPolysList().TotalVertices() <
|
|
|
|
tst->GetFilledPolysList().TotalVertices();
|
2012-01-04 19:10:33 +00:00
|
|
|
else
|
2014-02-25 10:40:34 +00:00
|
|
|
return ref->GetNetCode() < tst->GetNetCode();
|
2012-01-04 19:10:33 +00:00
|
|
|
}
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Test_Connection_To_Copper_Areas
|
|
|
|
* init .m_ZoneSubnet parameter in tracks and pads according to the connections to areas found
|
|
|
|
* @param aNetcode = netcode to analyse. if -1, analyse all nets
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
void BOARD::Test_Connections_To_Copper_Areas( int aNetcode )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2011-09-23 13:57:12 +00:00
|
|
|
// list of pads and tracks candidates on this layer and on this net.
|
2011-12-22 08:07:50 +00:00
|
|
|
// It is static to avoid multiple memory realloc.
|
2013-01-25 17:29:54 +00:00
|
|
|
static std::vector <BOARD_CONNECTED_ITEM*> candidates;
|
2011-12-22 08:07:50 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
// clear .m_ZoneSubnet parameter for pads
|
|
|
|
for( MODULE* module = m_Modules; module; module = module->Next() )
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
|
|
|
|
if( aNetcode < 0 || aNetcode == pad->GetNetCode() )
|
2008-11-18 18:13:55 +00:00
|
|
|
pad->SetZoneSubNet( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear .m_ZoneSubnet parameter for tracks and vias
|
|
|
|
for( TRACK* track = m_Track; track; track = track->Next() )
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
if( aNetcode < 0 || aNetcode == track->GetNetCode() )
|
2008-11-18 18:13:55 +00:00
|
|
|
track->SetZoneSubNet( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// examine all zones, net by net:
|
2011-12-22 08:07:50 +00:00
|
|
|
int subnet = 0;
|
2012-01-04 19:10:33 +00:00
|
|
|
|
|
|
|
// Build zones candidates list
|
|
|
|
std::vector<ZONE_CONTAINER*> zones_candidates;
|
2014-06-30 04:40:16 +00:00
|
|
|
|
|
|
|
zones_candidates.reserve( GetAreaCount() );
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
for( int index = 0; index < GetAreaCount(); index++ )
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
ZONE_CONTAINER* zone = GetArea( index );
|
|
|
|
|
|
|
|
if( !zone->IsOnCopperLayer() )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2014-06-30 04:40:16 +00:00
|
|
|
|
|
|
|
if( aNetcode >= 0 && aNetcode != zone->GetNetCode() )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( zone->GetFilledPolysList().IsEmpty() )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2014-06-30 04:40:16 +00:00
|
|
|
|
|
|
|
zones_candidates.push_back( zone );
|
2012-01-04 19:10:33 +00:00
|
|
|
}
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// sort them by netcode then vertices count.
|
|
|
|
// For a given net, examine the smaller zones first slightly speed up calculation
|
|
|
|
// (25% faster)
|
|
|
|
// this is only noticeable with very large boards and depends on board zones topology
|
2013-01-25 17:29:54 +00:00
|
|
|
// This is due to the fact some items are connected by small zones ares,
|
2012-01-04 19:10:33 +00:00
|
|
|
// before examining large zones areas and these items are not tested after a connection is found
|
2014-06-30 04:40:16 +00:00
|
|
|
sort( zones_candidates.begin(), zones_candidates.end(), sort_areas );
|
2012-01-04 19:10:33 +00:00
|
|
|
|
|
|
|
int oldnetcode = -1;
|
|
|
|
for( unsigned idx = 0; idx < zones_candidates.size(); idx++ )
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
ZONE_CONTAINER* zone = zones_candidates[idx];
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
int netcode = zone->GetNetCode();
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Build a list of candidates connected to the net:
|
2011-09-23 13:57:12 +00:00
|
|
|
// At this point, layers are not considered, because areas on different layers can
|
|
|
|
// be connected by a via or a pad.
|
2012-01-04 19:10:33 +00:00
|
|
|
// (because zones are sorted by netcode, there is made only once per net)
|
2011-12-22 08:07:50 +00:00
|
|
|
NETINFO_ITEM* net = FindNet( netcode );
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2011-12-22 08:07:50 +00:00
|
|
|
wxASSERT( net );
|
|
|
|
if( net == NULL )
|
|
|
|
continue;
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
if( oldnetcode != netcode )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2012-01-04 19:10:33 +00:00
|
|
|
oldnetcode = netcode;
|
2013-01-25 17:29:54 +00:00
|
|
|
candidates.clear();
|
2012-01-04 19:10:33 +00:00
|
|
|
|
|
|
|
// Build the list of pads candidates connected to the net:
|
2013-01-25 17:29:54 +00:00
|
|
|
candidates.reserve( net->m_PadInNetList.size() );
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
for( unsigned ii = 0; ii < net->m_PadInNetList.size(); ii++ )
|
2013-01-25 17:29:54 +00:00
|
|
|
candidates.push_back( net->m_PadInNetList[ii] );
|
2012-01-04 19:10:33 +00:00
|
|
|
|
2016-08-03 08:20:52 +00:00
|
|
|
// If we have any tracks...
|
|
|
|
if( m_Track.GetCount() > 0 )
|
2012-01-04 19:10:33 +00:00
|
|
|
{
|
2016-08-03 08:20:52 +00:00
|
|
|
// Build the list of track candidates connected to the net:
|
|
|
|
TRACK* track = m_Track.GetFirst()->GetStartNetCode( netcode );
|
|
|
|
|
|
|
|
for( ; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( track->GetNetCode() != netcode )
|
|
|
|
break;
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2016-08-03 08:20:52 +00:00
|
|
|
candidates.push_back( track );
|
|
|
|
}
|
2012-01-04 19:10:33 +00:00
|
|
|
}
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test if a candidate is inside a filled area of this zone
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_POLY_SET& polysList = zone->GetFilledPolysList();
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int outline = 0; outline < polysList.OutlineCount(); outline++ )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
|
|
|
subnet++;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2013-01-25 17:29:54 +00:00
|
|
|
for( unsigned ic = 0; ic < candidates.size(); ic++ )
|
2014-06-30 04:40:16 +00:00
|
|
|
{
|
|
|
|
// test if this area is connected to a board item:
|
2013-01-25 17:29:54 +00:00
|
|
|
BOARD_CONNECTED_ITEM* item = candidates[ic];
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
if( item->GetZoneSubNet() == subnet ) // Already merged
|
|
|
|
continue;
|
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if( !item->IsOnLayer( zone->GetLayer() ) )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
wxPoint pos1, pos2;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( item->Type() == PCB_PAD_T )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2013-03-09 19:36:31 +00:00
|
|
|
// For pads we use the shape position instead of
|
|
|
|
// the pad position, because the zones are connected
|
|
|
|
// to the center of the shape, not the pad position
|
|
|
|
// (this is important for pads with thermal relief)
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
pos1 = pos2 = ( (D_PAD*) item )->ShapePos();
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
2011-10-01 19:24:27 +00:00
|
|
|
else if( item->Type() == PCB_VIA_T )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
const VIA *via = static_cast<const VIA*>( item );
|
|
|
|
pos1 = via->GetStart();
|
|
|
|
pos2 = pos1;
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
2011-10-01 19:24:27 +00:00
|
|
|
else if( item->Type() == PCB_TRACE_T )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
const TRACK *trk = static_cast<const TRACK*>( item );
|
|
|
|
pos1 = trk->GetStart();
|
|
|
|
pos2 = trk->GetEnd();
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-23 13:57:12 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
bool connected = false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( polysList.Contains( VECTOR2I( pos1.x, pos1.y ), outline ) )
|
|
|
|
connected = true;
|
|
|
|
|
|
|
|
if( !connected && ( pos1 != pos2 ) )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
if( polysList.Contains( VECTOR2I( pos2.x, pos2.y ), outline ) )
|
2008-11-18 18:13:55 +00:00
|
|
|
connected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connected )
|
2013-01-25 17:29:54 +00:00
|
|
|
{
|
|
|
|
// Set ZoneSubnet to the current subnet value.
|
2011-09-23 13:57:12 +00:00
|
|
|
// If the previous subnet is not 0, merge all items with old subnet
|
|
|
|
// to the new one
|
2012-01-04 19:10:33 +00:00
|
|
|
int old_subnet = item->GetZoneSubNet();
|
2008-11-18 18:13:55 +00:00
|
|
|
item->SetZoneSubNet( subnet );
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
// Merge previous subnet with the current
|
|
|
|
if( (old_subnet > 0) && (old_subnet != subnet) )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2013-01-25 17:29:54 +00:00
|
|
|
for( unsigned jj = 0; jj < candidates.size(); jj++ )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2013-01-25 17:29:54 +00:00
|
|
|
BOARD_CONNECTED_ITEM* item_to_merge = candidates[jj];
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
if( old_subnet == item_to_merge->GetZoneSubNet() )
|
2013-01-25 17:29:54 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
item_to_merge->SetZoneSubNet( subnet );
|
2013-01-25 17:29:54 +00:00
|
|
|
}
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
|
|
|
} // End if ( old_subnet > 0 )
|
|
|
|
} // End if( connected )
|
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
2012-01-04 19:10:33 +00:00
|
|
|
} // End read all zones candidates
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb)
|
2011-09-23 13:57:12 +00:00
|
|
|
* Calls Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode ) for each
|
|
|
|
* netcode found in zone list
|
2008-11-18 18:13:55 +00:00
|
|
|
* @param aPcb = the current board
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
|
|
|
for( int index = 0; index < aPcb->GetAreaCount(); index++ )
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
ZONE_CONTAINER* zone = aPcb->GetArea( index );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if ( ! zone->IsOnCopperLayer() )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if ( zone->GetNetCode() <= 0 )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
Merge_SubNets_Connected_By_CopperAreas( aPcb, zone->GetNetCode() );
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Merge_SubNets_Connected_By_CopperAreas(BOARD* aPcb, int aNetcode)
|
2008-11-18 18:13:55 +00:00
|
|
|
* 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)
|
|
|
|
* @param aPcb = the current board
|
|
|
|
* @param aNetcode = netcode to consider
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
|
|
|
// Ensure a zone with the given netcode exists: examine all zones:
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( int index = 0; index < aPcb->GetAreaCount(); index++ )
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
ZONE_CONTAINER* zone = aPcb->GetArea( index );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if( aNetcode == zone->GetNetCode() )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found ) // No zone with this netcode, therefore no connection by zone
|
|
|
|
return;
|
|
|
|
|
2011-12-22 08:07:50 +00:00
|
|
|
// list of pads and tracks candidates to test:
|
|
|
|
// It is static to avoid multiple memory realloc.
|
|
|
|
static std::vector <BOARD_CONNECTED_ITEM*> Candidates;
|
|
|
|
Candidates.clear();
|
|
|
|
|
|
|
|
// Build the list of pads candidates connected to the net:
|
|
|
|
NETINFO_ITEM* net = aPcb->FindNet( aNetcode );
|
|
|
|
wxASSERT( net );
|
|
|
|
Candidates.reserve( net->m_PadInNetList.size() );
|
|
|
|
for( unsigned ii = 0; ii < net->m_PadInNetList.size(); ii++ )
|
|
|
|
Candidates.push_back( net->m_PadInNetList[ii] );
|
|
|
|
|
|
|
|
// Build the list of track candidates connected to the net:
|
|
|
|
TRACK* track;
|
2016-08-03 08:20:52 +00:00
|
|
|
|
|
|
|
if( aPcb->m_Track.GetCount() > 0 )
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
2016-08-03 08:20:52 +00:00
|
|
|
track = aPcb->m_Track.GetFirst()->GetStartNetCode( aNetcode );
|
|
|
|
|
|
|
|
for( ; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( track->GetNetCode() != aNetcode )
|
|
|
|
break;
|
|
|
|
|
|
|
|
Candidates.push_back( track );
|
|
|
|
}
|
2008-11-18 18:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Candidates.size() == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-12-22 08:07:50 +00:00
|
|
|
int next_subnet_free_number = 0;
|
|
|
|
for( unsigned ii = 0; ii < Candidates.size(); ii++ )
|
|
|
|
{
|
|
|
|
int subnet = Candidates[ii]->GetSubNet();
|
2012-09-22 11:19:37 +00:00
|
|
|
next_subnet_free_number = std::max( next_subnet_free_number, subnet );
|
2011-12-22 08:07:50 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
next_subnet_free_number++; // This is a subnet we can use with not connected items
|
|
|
|
// by tracks, but connected by zone.
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
// Sort by zone_subnet:
|
|
|
|
sort( Candidates.begin(), Candidates.end(), CmpZoneSubnetValue );
|
|
|
|
|
|
|
|
// Some items can be not connected, but they can be connected to a filled area:
|
2011-12-22 08:07:50 +00:00
|
|
|
// give them a subnet common to these items connected only by the area,
|
|
|
|
// and not already used.
|
2008-11-18 18:13:55 +00:00
|
|
|
// a value like next_subnet_free_number+zone_subnet is right
|
|
|
|
for( unsigned jj = 0; jj < Candidates.size(); jj++ )
|
|
|
|
{
|
2011-12-22 08:07:50 +00:00
|
|
|
BOARD_CONNECTED_ITEM* item = Candidates[jj];
|
2008-11-18 18:13:55 +00:00
|
|
|
if ( item->GetSubNet() == 0 && (item->GetZoneSubNet() > 0) )
|
|
|
|
{
|
|
|
|
item->SetSubNet( next_subnet_free_number + item->GetZoneSubNet() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, for each zone subnet, we search for 2 items with different subnets.
|
|
|
|
// if found, the 2 subnet are merged in the whole candidate list.
|
2011-12-22 08:07:50 +00:00
|
|
|
int old_subnet = 0;
|
|
|
|
int old_zone_subnet = 0;
|
2008-11-18 18:13:55 +00:00
|
|
|
for( unsigned ii = 0; ii < Candidates.size(); ii++ )
|
|
|
|
{
|
2011-12-22 08:07:50 +00:00
|
|
|
BOARD_CONNECTED_ITEM* item = Candidates[ii];
|
|
|
|
int zone_subnet = item->GetZoneSubNet();
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
if( zone_subnet == 0 ) // Not connected by a filled area, skip it
|
|
|
|
continue;
|
|
|
|
|
2011-12-22 08:07:50 +00:00
|
|
|
int subnet = item->GetSubNet();
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
if( zone_subnet != old_zone_subnet ) // a new zone subnet is found
|
|
|
|
{
|
|
|
|
old_subnet = subnet;
|
|
|
|
old_zone_subnet = zone_subnet;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
// 2 successive items already from the same cluster: nothing to do
|
|
|
|
if( subnet == old_subnet )
|
2008-11-18 18:13:55 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Here we have 2 items connected by the same area have 2 differents subnets: merge subnets
|
|
|
|
if( (subnet > old_subnet) || ( subnet <= 0) )
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( subnet, old_subnet );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
for( unsigned jj = 0; jj < Candidates.size(); jj++ )
|
|
|
|
{
|
|
|
|
BOARD_CONNECTED_ITEM * item_to_merge = Candidates[jj];
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
if( item_to_merge->GetSubNet() == old_subnet )
|
|
|
|
item_to_merge->SetSubNet( subnet );
|
|
|
|
}
|
|
|
|
|
|
|
|
old_subnet = subnet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-07 15:20:15 +00:00
|
|
|
/* Compare function used for sorting candidates by increasing zone subnet
|
2008-11-18 18:13:55 +00:00
|
|
|
*/
|
|
|
|
static bool CmpZoneSubnetValue( const BOARD_CONNECTED_ITEM* a, const BOARD_CONNECTED_ITEM* b )
|
|
|
|
{
|
|
|
|
int asubnet, bsubnet;
|
|
|
|
|
|
|
|
asubnet = a->GetZoneSubNet();
|
|
|
|
bsubnet = b->GetZoneSubNet();
|
|
|
|
|
|
|
|
return asubnet < bsubnet;
|
|
|
|
}
|