You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: zones_polygons_insulated_copper_islands.cpp
  3. // Licence: GPL License
  4. /////////////////////////////////////////////////////////////////////////////
  5. #ifndef WX_PRECOMP
  6. #include "wx/wx.h"
  7. #endif
  8. // For compilers that support precompilation, includes "wx/wx.h".
  9. #include "wx/wxprec.h"
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. using namespace std;
  14. #include "fctsys.h"
  15. #include "common.h"
  16. #include "pcbnew.h"
  17. #include "PolyLine.h"
  18. #include "zones.h"
  19. /***************************************************************************************/
  20. void ZONE_CONTAINER::Test_For_Copper_Island_And_Remove_Insulated_Islands( BOARD * aPcb )
  21. /***************************************************************************************/
  22. /**
  23. * Function Test_For_Copper_Island_And_Remove__Insulated_Islands
  24. * Remove insulated copper islands found in m_FilledPolysList.
  25. * @param aPcb = the board to analyse
  26. */
  27. {
  28. if( m_FilledPolysList.size() == 0 )
  29. return;
  30. // Build a list of points connected to the net:
  31. std::vector <wxPoint> ListPointsCandidates; // list of coordinates of pads and vias on this layer and on this net.
  32. for( MODULE* module = aPcb->m_Modules;
  33. module;
  34. module = module->Next() )
  35. {
  36. for( D_PAD* pad = module->m_Pads;
  37. pad != NULL;
  38. pad = pad->Next() )
  39. {
  40. if( !pad->IsOnLayer( GetLayer() ) )
  41. continue;
  42. if( pad->GetNet() != GetNet() )
  43. continue;
  44. ListPointsCandidates.push_back( pad->m_Pos );
  45. }
  46. }
  47. for( TRACK* track = aPcb->m_Track;
  48. track;
  49. track = track->Next() )
  50. {
  51. if( !track->IsOnLayer( GetLayer() ) )
  52. continue;
  53. if( track->GetNet() != GetNet() )
  54. continue;
  55. ListPointsCandidates.push_back( track->m_Start );
  56. if( track->Type() != TYPE_VIA )
  57. ListPointsCandidates.push_back( track->m_End );
  58. }
  59. // test if a point is inside
  60. unsigned indexstart = 0, indexend;
  61. bool connected = false;
  62. for( indexend = 0;
  63. indexend < m_FilledPolysList.size();
  64. indexend++ )
  65. {
  66. if( m_FilledPolysList[indexend].end_contour ) // end of a filled sub-area found
  67. {
  68. EDA_Rect bbox =
  69. CalculateSubAreaBoundaryBox( indexstart,
  70. indexend );
  71. for( unsigned ic = 0;
  72. ic < ListPointsCandidates.size();
  73. ic++ )
  74. { // test if this area is connected to a board item:
  75. wxPoint pos = ListPointsCandidates[ic];
  76. if( !bbox.Inside( pos ) )
  77. continue;
  78. if( TestPointInsidePolygon(
  79. m_FilledPolysList, indexstart,
  80. indexend, pos.x,
  81. pos.y ) )
  82. {
  83. connected = true;
  84. break;
  85. }
  86. }
  87. if( connected ) // this polygon is connected: analyse next polygon
  88. {
  89. indexstart = indexend + 1; // indexstart points the first point of the next polygon
  90. connected = false;
  91. }
  92. else // Not connected: remove this polygon
  93. {
  94. m_FilledPolysList.erase(
  95. m_FilledPolysList.begin() + indexstart,
  96. m_FilledPolysList.begin() + indexend +
  97. 1 );
  98. indexend = indexstart; /* indexstart points the first point of the next polygon
  99. * because the current poly is removed */
  100. }
  101. }
  102. }
  103. }
  104. /**************************************************************************************/
  105. EDA_Rect ZONE_CONTAINER::CalculateSubAreaBoundaryBox( int aIndexStart, int aIndexEnd )
  106. /**************************************************************************************/
  107. /** function CalculateSubAreaBoundaryBox
  108. * Calculates the bounding box of a a filled area ( list of CPolyPt )
  109. * use m_FilledPolysList as list of CPolyPt (that are the corners of one or more polygons or filled areas )
  110. * @return an EDA_Rect as bounding box
  111. * @param aIndexStart = index of the first corner of a polygon (filled area) in m_FilledPolysList
  112. * @param aIndexEnd = index of the last corner of a polygon in m_FilledPolysList
  113. */
  114. {
  115. CPolyPt start_point, end_point;
  116. EDA_Rect bbox;
  117. start_point = m_FilledPolysList[aIndexStart];
  118. end_point = start_point;
  119. for( int ii = aIndexStart; ii <= aIndexEnd; ii++ )
  120. {
  121. CPolyPt ptst = m_FilledPolysList[ii];
  122. if( start_point.x > ptst.x )
  123. start_point.x = ptst.x;
  124. if( start_point.y > ptst.y )
  125. start_point.y = ptst.y;
  126. if( end_point.x < ptst.x )
  127. end_point.x = ptst.x;
  128. if( end_point.y < ptst.y )
  129. end_point.y = ptst.y;
  130. }
  131. bbox.SetOrigin( start_point.x, start_point.y );
  132. bbox.SetEnd( wxPoint( end_point.x, end_point.y ) );
  133. return bbox;
  134. }