kicad/pcbnew/zones_polygons_insulated_co...

150 lines
4.8 KiB
C++
Raw Normal View History

/**
* @file zones_polygons_insulated_copper_islands.cpp
*/
/*
* 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
*/
2008-11-14 22:40:31 +00:00
#include <fctsys.h>
#include <common.h>
2008-11-14 22:40:31 +00:00
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
2008-11-14 22:40:31 +00:00
#include <pcbnew.h>
#include <zones.h>
#include <polygon_test_point_inside.h>
2008-11-14 22:40:31 +00:00
void ZONE_CONTAINER::TestForCopperIslandAndRemoveInsulatedIslands( BOARD* aPcb )
2008-11-14 22:40:31 +00:00
{
if( m_FilledPolysList.GetCornersCount() == 0 )
2008-11-14 22:40:31 +00:00
return;
// Build a list of points connected to the net:
// list of coordinates of pads and vias on this layer and on this net.
2012-02-19 04:02:19 +00:00
std::vector <wxPoint> listPointsCandidates;
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
2008-11-14 22:40:31 +00:00
{
for( D_PAD* pad = module->Pads(); pad != NULL; pad = pad->Next() )
2008-11-14 22:40:31 +00:00
{
if( !pad->IsOnLayer( GetLayer() ) )
continue;
if( pad->GetNetCode() != GetNetCode() )
2008-11-14 22:40:31 +00:00
continue;
2012-02-19 04:02:19 +00:00
listPointsCandidates.push_back( pad->GetPosition() );
2008-11-14 22:40:31 +00:00
}
}
for( TRACK* track = aPcb->m_Track; track; track = track->Next() )
2008-11-14 22:40:31 +00:00
{
if( !track->IsOnLayer( GetLayer() ) )
continue;
if( track->GetNetCode() != GetNetCode() )
2008-11-14 22:40:31 +00:00
continue;
listPointsCandidates.push_back( track->GetStart() );
if( track->Type() != PCB_VIA_T )
listPointsCandidates.push_back( track->GetEnd() );
2008-11-14 22:40:31 +00:00
}
// test if a point is inside
unsigned indexstart = 0, indexend;
bool connected = false;
for( indexend = 0; indexend < m_FilledPolysList.GetCornersCount(); indexend++ )
2008-11-14 22:40:31 +00:00
{
if( m_FilledPolysList[indexend].end_contour ) // end of a filled sub-area found
2008-11-14 22:40:31 +00:00
{
EDA_RECT bbox = CalculateSubAreaBoundaryBox( indexstart, indexend );
2012-02-19 04:02:19 +00:00
for( unsigned ic = 0; ic < listPointsCandidates.size(); ic++ )
{
// test if this area is connected to a board item:
2012-02-19 04:02:19 +00:00
wxPoint pos = listPointsCandidates[ic];
if( !bbox.Contains( pos ) )
2008-11-14 22:40:31 +00:00
continue;
if( TestPointInsidePolygon( m_FilledPolysList, indexstart, indexend,
pos.x, pos.y ) )
2008-11-14 22:40:31 +00:00
{
connected = true;
break;
}
}
if( connected ) // this polygon is connected: analyse next polygon
2008-11-14 22:40:31 +00:00
{
indexstart = indexend + 1; // indexstart points the first point of the next polygon
2008-11-14 22:40:31 +00:00
connected = false;
}
else // Not connected: remove this polygon
2008-11-14 22:40:31 +00:00
{
2013-05-08 18:20:58 +00:00
m_FilledPolysList.DeleteCorners( indexstart, indexend );
indexend = indexstart; /* indexstart points the first point of the next polygon
* because the current poly is removed */
2008-11-14 22:40:31 +00:00
}
}
}
}
EDA_RECT ZONE_CONTAINER::CalculateSubAreaBoundaryBox( int aIndexStart, int aIndexEnd )
2008-11-14 22:40:31 +00:00
{
CPolyPt start_point, end_point;
EDA_RECT bbox;
2008-11-14 22:40:31 +00:00
start_point = m_FilledPolysList[aIndexStart];
2008-11-14 22:40:31 +00:00
end_point = start_point;
2008-11-14 22:40:31 +00:00
for( int ii = aIndexStart; ii <= aIndexEnd; ii++ )
{
CPolyPt ptst = m_FilledPolysList[ii];
2008-11-14 22:40:31 +00:00
if( start_point.x > ptst.x )
start_point.x = ptst.x;
2008-11-14 22:40:31 +00:00
if( start_point.y > ptst.y )
start_point.y = ptst.y;
2008-11-14 22:40:31 +00:00
if( end_point.x < ptst.x )
end_point.x = ptst.x;
2008-11-14 22:40:31 +00:00
if( end_point.y < ptst.y )
end_point.y = ptst.y;
}
bbox.SetOrigin( start_point.x, start_point.y );
bbox.SetEnd( wxPoint( end_point.x, end_point.y ) );
return bbox;
2008-11-14 22:40:31 +00:00
}