kicad/pcbnew/zones_polygons_insulated_co...

144 lines
4.3 KiB
C++
Raw Normal View History

/**
* @file zones_polygons_insulated_copper_islands.cpp
*/
2008-11-14 22:40:31 +00:00
using namespace std;
#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>
2008-11-14 22:40:31 +00:00
/**
* Function Test_For_Copper_Island_And_Remove__Insulated_Islands
* Remove insulated copper islands found in m_FilledPolysList.
* @param aPcb = the board to analyse
*/
void ZONE_CONTAINER::Test_For_Copper_Island_And_Remove_Insulated_Islands( BOARD * aPcb )
2008-11-14 22:40:31 +00:00
{
if( m_FilledPolysList.size() == 0 )
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->m_Pads; pad != NULL; pad = pad->Next() )
2008-11-14 22:40:31 +00:00
{
if( !pad->IsOnLayer( GetLayer() ) )
continue;
if( pad->GetNet() != GetNet() )
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;
2008-11-14 22:40:31 +00:00
if( track->GetNet() != GetNet() )
continue;
2012-02-19 04:02:19 +00:00
listPointsCandidates.push_back( track->m_Start );
if( track->Type() != PCB_VIA_T )
2012-02-19 04:02:19 +00:00
listPointsCandidates.push_back( track->m_End );
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.size(); 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
{
m_FilledPolysList.erase( m_FilledPolysList.begin() + indexstart,
m_FilledPolysList.begin() + indexend + 1 );
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
}
}
}
}
/**
* Function CalculateSubAreaBoundaryBox
* Calculates the bounding box of a a filled area ( list of CPolyPt )
* use m_FilledPolysList as list of CPolyPt (that are the corners of one or more polygons or
* filled areas )
* @return an EDA_RECT as bounding box
* @param aIndexStart = index of the first corner of a polygon (filled area) in m_FilledPolysList
* @param aIndexEnd = index of the last corner of a polygon in m_FilledPolysList
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
}