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.

251 lines
10 KiB

13 years ago
13 years ago
* 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.
12 years ago
* 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.
12 years ago
  1. /**
  2. * @file zones_convert_to_polygons_aux_functions.cpp
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2013 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  8. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <fctsys.h>
  28. #include <PolyLine.h>
  29. #include <wxPcbStruct.h>
  30. #include <trigo.h>
  31. #include <class_board.h>
  32. #include <class_module.h>
  33. #include <class_zone.h>
  34. #include <pcbnew.h>
  35. #include <zones.h>
  36. /* Function TransformOutlinesShapeWithClearanceToPolygon
  37. * Convert the zone filled areas polygons to polygons
  38. * inflated (optional) by max( aClearanceValue, the zone clearance)
  39. * and copy them in aCornerBuffer
  40. * param aClearanceValue = the clearance around polygons
  41. * param aAddClearance = true to add a clearance area to the polygon
  42. * false to create the outline polygon.
  43. */
  44. void ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(
  45. SHAPE_POLY_SET& aCornerBuffer, int aMinClearanceValue, bool aUseNetClearance )
  46. {
  47. // Creates the zone outline polygon (with holes if any)
  48. SHAPE_POLY_SET polybuffer;
  49. BuildFilledSolidAreasPolygons( NULL, &polybuffer );
  50. // add clearance to outline
  51. int clearance = aMinClearanceValue;
  52. if( aUseNetClearance && IsOnCopperLayer() )
  53. {
  54. clearance = GetClearance();
  55. if( aMinClearanceValue > clearance )
  56. clearance = aMinClearanceValue;
  57. }
  58. // Calculate the polygon with clearance
  59. // holes are linked to the main outline, so only one polygon is created.
  60. if( clearance )
  61. polybuffer.Inflate( clearance, 16 );
  62. polybuffer.Fracture();
  63. aCornerBuffer.Append( polybuffer );
  64. }
  65. /**
  66. * Function BuildUnconnectedThermalStubsPolygonList
  67. * Creates a set of polygons corresponding to stubs created by thermal shapes on pads
  68. * which are not connected to a zone (dangling bridges)
  69. * @param aCornerBuffer = a SHAPE_POLY_SET where to store polygons
  70. * @param aPcb = the board.
  71. * @param aZone = a pointer to the ZONE_CONTAINER to examine.
  72. * @param aArcCorrection = a pointer to the ZONE_CONTAINER to examine.
  73. * @param aRoundPadThermalRotation = the rotation in 1.0 degree for thermal stubs in round pads
  74. */
  75. void BuildUnconnectedThermalStubsPolygonList( SHAPE_POLY_SET& aCornerBuffer,
  76. BOARD* aPcb,
  77. ZONE_CONTAINER* aZone,
  78. double aArcCorrection,
  79. double aRoundPadThermalRotation )
  80. {
  81. std::vector<wxPoint> corners_buffer; // a local polygon buffer to store one stub
  82. corners_buffer.reserve( 4 );
  83. wxPoint ptTest[4];
  84. int zone_clearance = aZone->GetZoneClearance();
  85. EDA_RECT item_boundingbox;
  86. EDA_RECT zone_boundingbox = aZone->GetBoundingBox();
  87. int biggest_clearance = aPcb->GetDesignSettings().GetBiggestClearanceValue();
  88. biggest_clearance = std::max( biggest_clearance, zone_clearance );
  89. zone_boundingbox.Inflate( biggest_clearance );
  90. // half size of the pen used to draw/plot zones outlines
  91. int pen_radius = aZone->GetMinThickness() / 2;
  92. for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
  93. {
  94. for( D_PAD* pad = module->Pads(); pad != NULL; pad = pad->Next() )
  95. {
  96. // Rejects non-standard pads with tht-only thermal reliefs
  97. if( aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_THT_THERMAL
  98. && pad->GetAttribute() != PAD_ATTRIB_STANDARD )
  99. continue;
  100. if( aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THERMAL
  101. && aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THT_THERMAL )
  102. continue;
  103. // check
  104. if( !pad->IsOnLayer( aZone->GetLayer() ) )
  105. continue;
  106. if( pad->GetNetCode() != aZone->GetNetCode() )
  107. continue;
  108. // Calculate thermal bridge half width
  109. int thermalBridgeWidth = aZone->GetThermalReliefCopperBridge( pad )
  110. - aZone->GetMinThickness();
  111. if( thermalBridgeWidth <= 0 )
  112. continue;
  113. // we need the thermal bridge half width
  114. // with a small extra size to be sure we create a stub
  115. // slightly larger than the actual stub
  116. thermalBridgeWidth = ( thermalBridgeWidth + 4 ) / 2;
  117. int thermalReliefGap = aZone->GetThermalReliefGap( pad );
  118. item_boundingbox = pad->GetBoundingBox();
  119. item_boundingbox.Inflate( thermalReliefGap );
  120. if( !( item_boundingbox.Intersects( zone_boundingbox ) ) )
  121. continue;
  122. // Thermal bridges are like a segment from a starting point inside the pad
  123. // to an ending point outside the pad
  124. // calculate the ending point of the thermal pad, outside the pad
  125. wxPoint endpoint;
  126. endpoint.x = ( pad->GetSize().x / 2 ) + thermalReliefGap;
  127. endpoint.y = ( pad->GetSize().y / 2 ) + thermalReliefGap;
  128. // Calculate the starting point of the thermal stub
  129. // inside the pad
  130. wxPoint startpoint;
  131. int copperThickness = aZone->GetThermalReliefCopperBridge( pad )
  132. - aZone->GetMinThickness();
  133. if( copperThickness < 0 )
  134. copperThickness = 0;
  135. // Leave a small extra size to the copper area inside to pad
  136. copperThickness += KiROUND( IU_PER_MM * 0.04 );
  137. startpoint.x = std::min( pad->GetSize().x, copperThickness );
  138. startpoint.y = std::min( pad->GetSize().y, copperThickness );
  139. startpoint.x /= 2;
  140. startpoint.y /= 2;
  141. // This is a CIRCLE pad tweak
  142. // for circle pads, the thermal stubs orientation is 45 deg
  143. double fAngle = pad->GetOrientation();
  144. if( pad->GetShape() == PAD_SHAPE_CIRCLE )
  145. {
  146. endpoint.x = KiROUND( endpoint.x * aArcCorrection );
  147. endpoint.y = endpoint.x;
  148. fAngle = aRoundPadThermalRotation;
  149. }
  150. // contour line width has to be taken into calculation to avoid "thermal stub bleed"
  151. endpoint.x += pen_radius;
  152. endpoint.y += pen_radius;
  153. // compute north, south, west and east points for zone connection.
  154. ptTest[0] = wxPoint( 0, endpoint.y ); // lower point
  155. ptTest[1] = wxPoint( 0, -endpoint.y ); // upper point
  156. ptTest[2] = wxPoint( endpoint.x, 0 ); // right point
  157. ptTest[3] = wxPoint( -endpoint.x, 0 ); // left point
  158. // Test all sides
  159. for( int i = 0; i < 4; i++ )
  160. {
  161. // rotate point
  162. RotatePoint( &ptTest[i], fAngle );
  163. // translate point
  164. ptTest[i] += pad->ShapePos();
  165. if( aZone->HitTestFilledArea( ptTest[i] ) )
  166. continue;
  167. corners_buffer.clear();
  168. // polygons are rectangles with width of copper bridge value
  169. switch( i )
  170. {
  171. case 0: // lower stub
  172. corners_buffer.push_back( wxPoint( -thermalBridgeWidth, endpoint.y ) );
  173. corners_buffer.push_back( wxPoint( +thermalBridgeWidth, endpoint.y ) );
  174. corners_buffer.push_back( wxPoint( +thermalBridgeWidth, startpoint.y ) );
  175. corners_buffer.push_back( wxPoint( -thermalBridgeWidth, startpoint.y ) );
  176. break;
  177. case 1: // upper stub
  178. corners_buffer.push_back( wxPoint( -thermalBridgeWidth, -endpoint.y ) );
  179. corners_buffer.push_back( wxPoint( +thermalBridgeWidth, -endpoint.y ) );
  180. corners_buffer.push_back( wxPoint( +thermalBridgeWidth, -startpoint.y ) );
  181. corners_buffer.push_back( wxPoint( -thermalBridgeWidth, -startpoint.y ) );
  182. break;
  183. case 2: // right stub
  184. corners_buffer.push_back( wxPoint( endpoint.x, -thermalBridgeWidth ) );
  185. corners_buffer.push_back( wxPoint( endpoint.x, thermalBridgeWidth ) );
  186. corners_buffer.push_back( wxPoint( +startpoint.x, thermalBridgeWidth ) );
  187. corners_buffer.push_back( wxPoint( +startpoint.x, -thermalBridgeWidth ) );
  188. break;
  189. case 3: // left stub
  190. corners_buffer.push_back( wxPoint( -endpoint.x, -thermalBridgeWidth ) );
  191. corners_buffer.push_back( wxPoint( -endpoint.x, thermalBridgeWidth ) );
  192. corners_buffer.push_back( wxPoint( -startpoint.x, thermalBridgeWidth ) );
  193. corners_buffer.push_back( wxPoint( -startpoint.x, -thermalBridgeWidth ) );
  194. break;
  195. }
  196. aCornerBuffer.NewOutline();
  197. // add computed polygon to list
  198. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  199. {
  200. wxPoint cpos = corners_buffer[ic];
  201. RotatePoint( &cpos, fAngle ); // Rotate according to module orientation
  202. cpos += pad->ShapePos(); // Shift origin to position
  203. aCornerBuffer.Append( cpos.x, cpos.y );
  204. }
  205. }
  206. }
  207. }
  208. }