zones_polygons_insulated_copper_islands.cpp 5.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/////////////////////////////////////////////////////////////////////////////

// Name:        zones_polygons_insulated_copper_islands.cpp
// Licence:     GPL License
/////////////////////////////////////////////////////////////////////////////

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif


// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

using namespace std;

#include "fctsys.h"

#include "common.h"
#include "pcbnew.h"
#include "PolyLine.h"

#include "zones.h"


/***************************************************************************************/
31
void ZONE_CONTAINER::Test_For_Copper_Island_And_Remove_Insulated_Islands( BOARD * aPcb )
32 33 34 35 36 37 38 39 40 41 42
/***************************************************************************************/

/**
 * Function Test_For_Copper_Island_And_Remove__Insulated_Islands
 * Remove insulated copper islands found in m_FilledPolysList.
 * @param aPcb = the board to analyse
 */
{
    if( m_FilledPolysList.size() == 0 )
        return;

43 44 45 46 47
    // Build a list of points connected to the net:
    std::vector <wxPoint> ListPointsCandidates;                                         // list of coordinates of pads and vias on this layer and on this net.
    for( MODULE* module = aPcb->m_Modules;
        module;
        module = module->Next() )
48
    {
49 50 51
        for( D_PAD* pad = module->m_Pads;
            pad != NULL;
            pad = pad->Next() )
52 53 54 55 56 57 58
        {
            if( !pad->IsOnLayer( GetLayer() ) )
                continue;

            if( pad->GetNet() != GetNet() )
                continue;

59
            ListPointsCandidates.push_back( pad->m_Pos );
60 61 62
        }
    }

63 64 65
    for( TRACK* track = aPcb->m_Track;
        track;
        track = track->Next() )
66 67 68 69 70
    {
        if( !track->IsOnLayer( GetLayer() ) )
            continue;
        if( track->GetNet() != GetNet() )
            continue;
71
        ListPointsCandidates.push_back( track->m_Start );
72
        if( track->Type() != TYPE_VIA )
73
            ListPointsCandidates.push_back( track->m_End );
74 75 76 77 78
    }

    // test if a point is inside
    unsigned indexstart = 0, indexend;
    bool     connected  = false;
79 80 81
    for( indexend = 0;
         indexend < m_FilledPolysList.size();
         indexend++ )
82
    {
83
        if( m_FilledPolysList[indexend].end_contour )                                         // end of a filled sub-area found
84
        {
85 86 87 88 89 90 91 92
            EDA_Rect bbox =
                CalculateSubAreaBoundaryBox( indexstart,
                    indexend );
            for( unsigned ic = 0;
                 ic < ListPointsCandidates.size();
                 ic++ )
            {                                         // test if this area is connected to a board item:
                wxPoint pos = ListPointsCandidates[ic];
93 94
                if( !bbox.Inside( pos ) )
                    continue;
95 96 97 98
                if( TestPointInsidePolygon(
                       m_FilledPolysList, indexstart,
                       indexend, pos.x,
                       pos.y ) )
99 100 101 102 103 104
                {
                    connected = true;
                    break;
                }
            }

105
            if( connected )                                                         // this polygon is connected: analyse next polygon
106
            {
107
                indexstart = indexend + 1;                                          // indexstart points the first point of the next polygon
108 109
                connected  = false;
            }
110
            else                                         // Not connected: remove this polygon
111 112 113
            {
                m_FilledPolysList.erase(
                    m_FilledPolysList.begin() + indexstart,
114 115 116 117
                    m_FilledPolysList.begin() + indexend +
                    1 );
                indexend = indexstart;                                         /* indexstart points the first point of the next polygon
                                                                                * because the current poly is removed */
118 119 120 121 122 123
            }
        }
    }
}


124 125 126
/**************************************************************************************/
EDA_Rect ZONE_CONTAINER::CalculateSubAreaBoundaryBox( int aIndexStart, int aIndexEnd )
/**************************************************************************************/
127 128

/** function CalculateSubAreaBoundaryBox
129 130 131 132 133
 * 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
134 135
 */
{
136 137
    CPolyPt  start_point, end_point;
    EDA_Rect bbox;
138

139
    start_point = m_FilledPolysList[aIndexStart];
140 141 142
    end_point   = start_point;
    for( int ii = aIndexStart; ii <= aIndexEnd; ii++ )
    {
143
        CPolyPt ptst = m_FilledPolysList[ii];
144 145 146 147 148 149 150 151 152 153
        if( start_point.x > ptst.x )
            start_point.x = ptst.x;
        if( start_point.y > ptst.y )
            start_point.y = ptst.y;
        if( end_point.x < ptst.x )
            end_point.x = ptst.x;
        if( end_point.y < ptst.y )
            end_point.y = ptst.y;
    }

154 155 156 157
    bbox.SetOrigin( start_point.x, start_point.y );
    bbox.SetEnd( wxPoint( end_point.x, end_point.y ) );

    return bbox;
158
}