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.

1272 lines
46 KiB

* 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
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /***
  25. * @file board_items_to_polygon_shape_transform.cpp
  26. * @brief function to convert shapes of items ( pads, tracks... ) to polygons
  27. */
  28. /* Function to convert pad and track shapes to polygons
  29. * Used to fill zones areas and in 3D viewer
  30. */
  31. #include <vector>
  32. #include <fctsys.h>
  33. #include <bezier_curves.h>
  34. #include <base_units.h> // for IU_PER_MM
  35. #include <gr_text.h>
  36. #include <pcbnew.h>
  37. #include <pcb_edit_frame.h>
  38. #include <trigo.h>
  39. #include <class_board.h>
  40. #include <class_pad.h>
  41. #include <class_track.h>
  42. #include <class_drawsegment.h>
  43. #include <class_pcb_text.h>
  44. #include <class_zone.h>
  45. #include <class_module.h>
  46. #include <class_edge_mod.h>
  47. #include <convert_basic_shapes_to_polygon.h>
  48. #include <geometry/geometry_utils.h>
  49. // A helper struct for the callback function
  50. // These variables are parameters used in addTextSegmToPoly.
  51. // But addTextSegmToPoly is a call-back function,
  52. // so we cannot send them as arguments.
  53. struct TSEGM_2_POLY_PRMS {
  54. int m_textWidth;
  55. int m_error;
  56. SHAPE_POLY_SET* m_cornerBuffer;
  57. };
  58. TSEGM_2_POLY_PRMS prms;
  59. // This is a call back function, used by GRText to draw the 3D text shape:
  60. static void addTextSegmToPoly( int x0, int y0, int xf, int yf, void* aData )
  61. {
  62. TSEGM_2_POLY_PRMS* prm = static_cast<TSEGM_2_POLY_PRMS*>( aData );
  63. TransformRoundedEndsSegmentToPolygon( *prm->m_cornerBuffer,
  64. wxPoint( x0, y0), wxPoint( xf, yf ),
  65. prm->m_error, prm->m_textWidth );
  66. }
  67. void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines )
  68. {
  69. // convert tracks and vias:
  70. for( auto track : m_tracks )
  71. {
  72. if( !track->IsOnLayer( aLayer ) )
  73. continue;
  74. track->TransformShapeWithClearanceToPolygon( aOutlines, 0 );
  75. }
  76. // convert pads
  77. for( auto module : m_modules )
  78. {
  79. module->TransformPadsShapesWithClearanceToPolygon( aLayer, aOutlines, 0 );
  80. // Micro-wave modules may have items on copper layers
  81. module->TransformGraphicShapesWithClearanceToPolygonSet( aLayer, aOutlines, 0 );
  82. }
  83. // convert copper zones
  84. for( int ii = 0; ii < GetAreaCount(); ii++ )
  85. {
  86. ZONE_CONTAINER* zone = GetArea( ii );
  87. PCB_LAYER_ID zonelayer = zone->GetLayer();
  88. if( zonelayer == aLayer )
  89. zone->TransformSolidAreasShapesToPolygonSet( aOutlines );
  90. }
  91. // convert graphic items on copper layers (texts)
  92. for( auto item : m_drawings )
  93. {
  94. if( !item->IsOnLayer( aLayer ) )
  95. continue;
  96. switch( item->Type() )
  97. {
  98. case PCB_LINE_T:
  99. ( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon( aOutlines, 0 );
  100. break;
  101. case PCB_TEXT_T:
  102. ( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet( aOutlines, 0 );
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. }
  109. void MODULE::TransformPadsShapesWithClearanceToPolygon( PCB_LAYER_ID aLayer,
  110. SHAPE_POLY_SET& aCornerBuffer, int aInflateValue, int aMaxError,
  111. bool aSkipNPTHPadsWihNoCopper ) const
  112. {
  113. D_PAD* pad = PadsList();
  114. wxSize margin;
  115. for( ; pad != NULL; pad = pad->Next() )
  116. {
  117. if( aLayer != UNDEFINED_LAYER && !pad->IsOnLayer(aLayer) )
  118. continue;
  119. // NPTH pads are not drawn on layers if the shape size and pos is the same
  120. // as their hole:
  121. if( aSkipNPTHPadsWihNoCopper && pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
  122. {
  123. if( pad->GetDrillSize() == pad->GetSize() && pad->GetOffset() == wxPoint( 0, 0 ) )
  124. {
  125. switch( pad->GetShape() )
  126. {
  127. case PAD_SHAPE_CIRCLE:
  128. if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
  129. continue;
  130. break;
  131. case PAD_SHAPE_OVAL:
  132. if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
  133. continue;
  134. break;
  135. default:
  136. break;
  137. }
  138. }
  139. }
  140. switch( aLayer )
  141. {
  142. case F_Mask:
  143. case B_Mask:
  144. margin.x = margin.y = pad->GetSolderMaskMargin() + aInflateValue;
  145. break;
  146. case F_Paste:
  147. case B_Paste:
  148. margin = pad->GetSolderPasteMargin();
  149. margin.x += aInflateValue;
  150. margin.y += aInflateValue;
  151. break;
  152. default:
  153. margin.x = margin.y = aInflateValue;
  154. break;
  155. }
  156. pad->BuildPadShapePolygon( aCornerBuffer, margin );
  157. }
  158. }
  159. /* generate shapes of graphic items (outlines) on layer aLayer as polygons,
  160. * and adds these polygons to aCornerBuffer
  161. * aCornerBuffer = the buffer to store polygons
  162. * aInflateValue = a value to inflate shapes
  163. * aCircleToSegmentsCount = number of segments to approximate a circle
  164. * aCorrectionFactor = the correction to apply to the circle radius
  165. * to generate the polygon.
  166. * if aCorrectionFactor = 1.0, the polygon is inside the circle
  167. * the radius of circle approximated by segments is
  168. * initial radius * aCorrectionFactor
  169. */
  170. void MODULE::TransformGraphicShapesWithClearanceToPolygonSet( PCB_LAYER_ID aLayer,
  171. SHAPE_POLY_SET& aCornerBuffer, int aInflateValue, int aError, bool aIncludeText ) const
  172. {
  173. std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
  174. EDGE_MODULE* outline;
  175. for( EDA_ITEM* item = GraphicalItemsList(); item != NULL; item = item->Next() )
  176. {
  177. switch( item->Type() )
  178. {
  179. case PCB_MODULE_TEXT_T:
  180. {
  181. TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
  182. if( ( aLayer != UNDEFINED_LAYER && text->GetLayer() == aLayer ) && text->IsVisible() )
  183. texts.push_back( text );
  184. break;
  185. }
  186. case PCB_MODULE_EDGE_T:
  187. outline = (EDGE_MODULE*) item;
  188. if( aLayer != UNDEFINED_LAYER && outline->GetLayer() != aLayer )
  189. break;
  190. outline->TransformShapeWithClearanceToPolygon( aCornerBuffer, 0, aError );
  191. break;
  192. default:
  193. break;
  194. }
  195. }
  196. if( !aIncludeText )
  197. return;
  198. // Convert texts sur modules
  199. if( Reference().GetLayer() == aLayer && Reference().IsVisible() )
  200. texts.push_back( &Reference() );
  201. if( Value().GetLayer() == aLayer && Value().IsVisible() )
  202. texts.push_back( &Value() );
  203. prms.m_cornerBuffer = &aCornerBuffer;
  204. for( unsigned ii = 0; ii < texts.size(); ii++ )
  205. {
  206. TEXTE_MODULE *textmod = texts[ii];
  207. prms.m_textWidth = textmod->GetThickness() + ( 2 * aInflateValue );
  208. prms.m_error = aError;
  209. wxSize size = textmod->GetTextSize();
  210. if( textmod->IsMirrored() )
  211. size.x = -size.x;
  212. GRText( NULL, textmod->GetTextPos(), BLACK, textmod->GetShownText(),
  213. textmod->GetDrawRotation(), size, textmod->GetHorizJustify(),
  214. textmod->GetVertJustify(), textmod->GetThickness(), textmod->IsItalic(),
  215. true, addTextSegmToPoly, &prms );
  216. }
  217. }
  218. // Same as function TransformGraphicShapesWithClearanceToPolygonSet but
  219. // this only render text
  220. void MODULE::TransformGraphicTextWithClearanceToPolygonSet(
  221. PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aCornerBuffer, int aInflateValue, int aError ) const
  222. {
  223. std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
  224. for( EDA_ITEM* item = GraphicalItemsList(); item != NULL; item = item->Next() )
  225. {
  226. switch( item->Type() )
  227. {
  228. case PCB_MODULE_TEXT_T:
  229. {
  230. TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
  231. if( text->GetLayer() == aLayer && text->IsVisible() )
  232. texts.push_back( text );
  233. break;
  234. }
  235. case PCB_MODULE_EDGE_T:
  236. // This function does not render this
  237. break;
  238. default:
  239. break;
  240. }
  241. }
  242. // Convert texts sur modules
  243. if( Reference().GetLayer() == aLayer && Reference().IsVisible() )
  244. texts.push_back( &Reference() );
  245. if( Value().GetLayer() == aLayer && Value().IsVisible() )
  246. texts.push_back( &Value() );
  247. prms.m_cornerBuffer = &aCornerBuffer;
  248. for( unsigned ii = 0; ii < texts.size(); ii++ )
  249. {
  250. TEXTE_MODULE *textmod = texts[ii];
  251. prms.m_textWidth = textmod->GetThickness() + ( 2 * aInflateValue );
  252. prms.m_error = aError;
  253. wxSize size = textmod->GetTextSize();
  254. if( textmod->IsMirrored() )
  255. size.x = -size.x;
  256. GRText( NULL, textmod->GetTextPos(), BLACK, textmod->GetShownText(),
  257. textmod->GetDrawRotation(), size, textmod->GetHorizJustify(),
  258. textmod->GetVertJustify(), textmod->GetThickness(), textmod->IsItalic(),
  259. true, addTextSegmToPoly, &prms );
  260. }
  261. }
  262. void ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(
  263. SHAPE_POLY_SET& aCornerBuffer, int aError ) const
  264. {
  265. if( GetFilledPolysList().IsEmpty() )
  266. return;
  267. // add filled areas polygons
  268. aCornerBuffer.Append( m_FilledPolysList );
  269. auto board = GetBoard();
  270. int maxError = ARC_HIGH_DEF;
  271. if( board )
  272. maxError = board->GetDesignSettings().m_MaxError;
  273. // add filled areas outlines, which are drawn with thick lines
  274. for( int i = 0; i < m_FilledPolysList.OutlineCount(); i++ )
  275. {
  276. const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( i );
  277. for( int j = 0; j < path.PointCount(); j++ )
  278. {
  279. const VECTOR2I& a = path.CPoint( j );
  280. const VECTOR2I& b = path.CPoint( j + 1 );
  281. TransformRoundedEndsSegmentToPolygon( aCornerBuffer, wxPoint( a.x, a.y ),
  282. wxPoint( b.x, b.y ), maxError, GetMinThickness() );
  283. }
  284. }
  285. }
  286. void EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon(
  287. SHAPE_POLY_SET* aCornerBuffer, int aClearanceValue ) const
  288. {
  289. // Oh dear. When in UTF-8 mode, wxString puts string iterators in a linked list, and
  290. // that linked list is not thread-safe.
  291. std::lock_guard<std::mutex> guard( m_mutex );
  292. if( GetText().Length() == 0 )
  293. return;
  294. wxPoint corners[4]; // Buffer of polygon corners
  295. EDA_RECT rect = GetTextBox( -1 );
  296. rect.Inflate( aClearanceValue );
  297. corners[0].x = rect.GetOrigin().x;
  298. corners[0].y = rect.GetOrigin().y;
  299. corners[1].y = corners[0].y;
  300. corners[1].x = rect.GetRight();
  301. corners[2].x = corners[1].x;
  302. corners[2].y = rect.GetBottom();
  303. corners[3].y = corners[2].y;
  304. corners[3].x = corners[0].x;
  305. aCornerBuffer->NewOutline();
  306. for( int ii = 0; ii < 4; ii++ )
  307. {
  308. // Rotate polygon
  309. RotatePoint( &corners[ii].x, &corners[ii].y, GetTextPos().x, GetTextPos().y, GetTextAngle() );
  310. aCornerBuffer->Append( corners[ii].x, corners[ii].y );
  311. }
  312. }
  313. /* Function TransformShapeWithClearanceToPolygonSet
  314. * Convert the text shape to a set of polygons (one by segment)
  315. * Used in filling zones calculations and 3D view
  316. * Circles and arcs are approximated by segments
  317. * aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
  318. * aClearanceValue = the clearance around the text
  319. * aCircleToSegmentsCount = the number of segments to approximate a circle
  320. * aCorrectionFactor = the correction to apply to circles radius to keep
  321. * clearance when the circle is approximated by segment bigger or equal
  322. * to the real clearance value (usually near from 1.0)
  323. */
  324. void TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(
  325. SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError ) const
  326. {
  327. wxSize size = GetTextSize();
  328. if( IsMirrored() )
  329. size.x = -size.x;
  330. prms.m_cornerBuffer = &aCornerBuffer;
  331. prms.m_textWidth = GetThickness() + ( 2 * aClearanceValue );
  332. prms.m_error = aError;
  333. COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
  334. if( IsMultilineAllowed() )
  335. {
  336. wxArrayString strings_list;
  337. wxStringSplit( GetShownText(), strings_list, '\n' );
  338. std::vector<wxPoint> positions;
  339. positions.reserve( strings_list.Count() );
  340. GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
  341. for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
  342. {
  343. wxString txt = strings_list.Item( ii );
  344. GRText( NULL, positions[ii], color, txt, GetTextAngle(), size, GetHorizJustify(),
  345. GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToPoly, &prms );
  346. }
  347. }
  348. else
  349. {
  350. GRText( NULL, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(),
  351. GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToPoly, &prms );
  352. }
  353. }
  354. void DRAWSEGMENT::TransformShapeWithClearanceToPolygon(
  355. SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError, bool ignoreLineWidth ) const
  356. {
  357. // The full width of the lines to create:
  358. int linewidth = ignoreLineWidth ? 0 : m_Width;
  359. linewidth += 2 * aClearanceValue;
  360. // Creating a reliable clearance shape for circles and arcs is not so easy, due to
  361. // the error created by segment approximation.
  362. // for a circle this is not so hard: create a polygon from a circle slightly bigger:
  363. // thickness = linewidth + s_error_max, and radius = initial radius + s_error_max/2
  364. // giving a shape with a suitable internal radius and external radius
  365. // For an arc this is more tricky: TODO
  366. switch( m_Shape )
  367. {
  368. case S_CIRCLE:
  369. TransformRingToPolygon(
  370. aCornerBuffer, GetCenter(), GetRadius(), aError, linewidth );
  371. break;
  372. case S_ARC:
  373. TransformArcToPolygon(
  374. aCornerBuffer, GetCenter(), GetArcStart(), m_Angle, aError, linewidth );
  375. break;
  376. case S_SEGMENT:
  377. TransformOvalClearanceToPolygon(
  378. aCornerBuffer, m_Start, m_End, linewidth, aError );
  379. break;
  380. case S_POLYGON:
  381. if( IsPolyShapeValid() )
  382. {
  383. // The polygon is expected to be a simple polygon
  384. // not self intersecting, no hole.
  385. MODULE* module = GetParentModule(); // NULL for items not in footprints
  386. double orientation = module ? module->GetOrientation() : 0.0;
  387. wxPoint offset;
  388. if( module )
  389. offset = module->GetPosition();
  390. // Build the polygon with the actual position and orientation:
  391. std::vector< wxPoint> poly;
  392. poly = BuildPolyPointsList();
  393. for( unsigned ii = 0; ii < poly.size(); ii++ )
  394. {
  395. RotatePoint( &poly[ii], orientation );
  396. poly[ii] += offset;
  397. }
  398. // If the polygon is not filled, treat it as a closed set of lines
  399. if( !IsPolygonFilled() )
  400. {
  401. for( size_t ii = 1; ii < poly.size(); ii++ )
  402. {
  403. TransformOvalClearanceToPolygon( aCornerBuffer, poly[ii - 1], poly[ii],
  404. linewidth, aError );
  405. }
  406. TransformOvalClearanceToPolygon( aCornerBuffer, poly.back(), poly.front(),
  407. linewidth, aError );
  408. break;
  409. }
  410. // Generate polygons for the outline + clearance
  411. // This code is compatible with a polygon with holes linked to external outline
  412. // by overlapping segments.
  413. // Insert the initial polygon:
  414. aCornerBuffer.NewOutline();
  415. for( unsigned ii = 0; ii < poly.size(); ii++ )
  416. aCornerBuffer.Append( poly[ii].x, poly[ii].y );
  417. if( linewidth ) // Add thick outlines
  418. {
  419. wxPoint corner1( poly[poly.size()-1] );
  420. for( unsigned ii = 0; ii < poly.size(); ii++ )
  421. {
  422. wxPoint corner2( poly[ii] );
  423. if( corner2 != corner1 )
  424. {
  425. TransformRoundedEndsSegmentToPolygon(
  426. aCornerBuffer, corner1, corner2, aError, linewidth );
  427. }
  428. corner1 = corner2;
  429. }
  430. }
  431. }
  432. break;
  433. case S_CURVE: // Bezier curve
  434. {
  435. std::vector<wxPoint> ctrlPoints = { m_Start, m_BezierC1, m_BezierC2, m_End };
  436. BEZIER_POLY converter( ctrlPoints );
  437. std::vector< wxPoint> poly;
  438. converter.GetPoly( poly, m_Width );
  439. for( unsigned ii = 1; ii < poly.size(); ii++ )
  440. {
  441. TransformRoundedEndsSegmentToPolygon(
  442. aCornerBuffer, poly[ii - 1], poly[ii], aError, linewidth );
  443. }
  444. }
  445. break;
  446. default:
  447. break;
  448. }
  449. }
  450. void TRACK::TransformShapeWithClearanceToPolygon(
  451. SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError, bool ignoreLineWidth ) const
  452. {
  453. wxASSERT_MSG( !ignoreLineWidth, "IgnoreLineWidth has no meaning for tracks." );
  454. int radius = ( m_Width / 2 ) + aClearanceValue;
  455. switch( Type() )
  456. {
  457. case PCB_VIA_T:
  458. {
  459. TransformCircleToPolygon( aCornerBuffer, m_Start, radius, aError );
  460. }
  461. break;
  462. default:
  463. TransformOvalClearanceToPolygon( aCornerBuffer, m_Start, m_End,
  464. m_Width + ( 2 * aClearanceValue ), aError );
  465. break;
  466. }
  467. }
  468. void D_PAD::TransformShapeWithClearanceToPolygon(
  469. SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError, bool ignoreLineWidth ) const
  470. {
  471. wxASSERT_MSG( !ignoreLineWidth, "IgnoreLineWidth has no meaning for pads." );
  472. double angle = m_Orient;
  473. int dx = (m_Size.x / 2) + aClearanceValue;
  474. int dy = (m_Size.y / 2) + aClearanceValue;
  475. wxPoint padShapePos = ShapePos(); /* Note: for pad having a shape offset,
  476. * the pad position is NOT the shape position */
  477. switch( GetShape() )
  478. {
  479. case PAD_SHAPE_CIRCLE:
  480. {
  481. TransformCircleToPolygon( aCornerBuffer, padShapePos, dx, aError );
  482. }
  483. break;
  484. case PAD_SHAPE_OVAL:
  485. // An oval pad has the same shape as a segment with rounded ends
  486. {
  487. int width;
  488. wxPoint shape_offset;
  489. if( dy > dx ) // Oval pad X/Y ratio for choosing translation axis
  490. {
  491. shape_offset.y = dy - dx;
  492. width = dx * 2;
  493. }
  494. else //if( dy <= dx )
  495. {
  496. shape_offset.x = dy - dx;
  497. width = dy * 2;
  498. }
  499. RotatePoint( &shape_offset, angle );
  500. wxPoint start = padShapePos - shape_offset;
  501. wxPoint end = padShapePos + shape_offset;
  502. TransformOvalClearanceToPolygon( aCornerBuffer, start, end, width, aError );
  503. }
  504. break;
  505. case PAD_SHAPE_TRAPEZOID:
  506. case PAD_SHAPE_RECT:
  507. {
  508. wxPoint corners[4];
  509. BuildPadPolygon( corners, wxSize( 0, 0 ), angle );
  510. SHAPE_POLY_SET outline;
  511. outline.NewOutline();
  512. for( int ii = 0; ii < 4; ii++ )
  513. {
  514. corners[ii] += padShapePos;
  515. outline.Append( corners[ii].x, corners[ii].y );
  516. }
  517. int numSegs = std::max( GetArcToSegmentCount( aClearanceValue, aError, 360.0 ), 6 );
  518. double correction = GetCircletoPolyCorrectionFactor( numSegs );
  519. int rounding_radius = KiROUND( aClearanceValue * correction );
  520. outline.Inflate( rounding_radius, numSegs );
  521. aCornerBuffer.Append( outline );
  522. }
  523. break;
  524. case PAD_SHAPE_CHAMFERED_RECT:
  525. case PAD_SHAPE_ROUNDRECT:
  526. {
  527. SHAPE_POLY_SET outline;
  528. int radius = GetRoundRectCornerRadius() + aClearanceValue;
  529. int numSegs = std::max( GetArcToSegmentCount( radius, aError, 360.0 ), 6 );
  530. double correction = GetCircletoPolyCorrectionFactor( numSegs );
  531. int clearance = KiROUND( aClearanceValue * correction );
  532. int rounding_radius = GetRoundRectCornerRadius() + clearance;
  533. wxSize shapesize( m_Size );
  534. shapesize.x += clearance * 2;
  535. shapesize.y += clearance * 2;
  536. bool doChamfer = GetShape() == PAD_SHAPE_CHAMFERED_RECT;
  537. TransformRoundChamferedRectToPolygon( outline, padShapePos, shapesize, angle,
  538. rounding_radius, doChamfer ? GetChamferRectRatio() : 0.0,
  539. doChamfer ? GetChamferPositions() : 0, aError );
  540. aCornerBuffer.Append( outline );
  541. }
  542. break;
  543. case PAD_SHAPE_CUSTOM:
  544. {
  545. int numSegs = std::max( GetArcToSegmentCount( aClearanceValue, aError, 360.0 ), 6 );
  546. double correction = GetCircletoPolyCorrectionFactor( numSegs );
  547. int clearance = KiROUND( aClearanceValue * correction );
  548. SHAPE_POLY_SET outline; // Will contain the corners in board coordinates
  549. outline.Append( m_customShapeAsPolygon );
  550. CustomShapeAsPolygonToBoardPosition( &outline, GetPosition(), GetOrientation() );
  551. outline.Simplify( SHAPE_POLY_SET::PM_FAST );
  552. outline.Inflate( clearance, numSegs );
  553. outline.Fracture( SHAPE_POLY_SET::PM_FAST );
  554. aCornerBuffer.Append( outline );
  555. }
  556. break;
  557. }
  558. }
  559. /*
  560. * Function BuildPadShapePolygon
  561. * Build the Corner list of the polygonal shape,
  562. * depending on shape, extra size (clearance ...) pad and orientation
  563. * Note: for Round and oval pads this function is equivalent to
  564. * TransformShapeWithClearanceToPolygon, but not for other shapes
  565. */
  566. void D_PAD::BuildPadShapePolygon(
  567. SHAPE_POLY_SET& aCornerBuffer, wxSize aInflateValue, int aError ) const
  568. {
  569. wxPoint corners[4];
  570. wxPoint padShapePos = ShapePos(); /* Note: for pad having a shape offset,
  571. * the pad position is NOT the shape position */
  572. switch( GetShape() )
  573. {
  574. case PAD_SHAPE_CIRCLE:
  575. case PAD_SHAPE_OVAL:
  576. case PAD_SHAPE_ROUNDRECT:
  577. case PAD_SHAPE_CHAMFERED_RECT:
  578. {
  579. // We are using TransformShapeWithClearanceToPolygon to build the shape.
  580. // Currently, this method uses only the same inflate value for X and Y dirs.
  581. // so because here this is not the case, we use a inflated dummy pad to build
  582. // the polygonal shape
  583. // TODO: remove this dummy pad when TransformShapeWithClearanceToPolygon will use
  584. // a wxSize to inflate the pad size
  585. D_PAD dummy( *this );
  586. dummy.SetSize( GetSize() + aInflateValue + aInflateValue );
  587. dummy.TransformShapeWithClearanceToPolygon( aCornerBuffer, 0 );
  588. }
  589. break;
  590. case PAD_SHAPE_TRAPEZOID:
  591. case PAD_SHAPE_RECT:
  592. aCornerBuffer.NewOutline();
  593. BuildPadPolygon( corners, aInflateValue, m_Orient );
  594. for( int ii = 0; ii < 4; ii++ )
  595. {
  596. corners[ii] += padShapePos; // Shift origin to position
  597. aCornerBuffer.Append( corners[ii].x, corners[ii].y );
  598. }
  599. break;
  600. case PAD_SHAPE_CUSTOM:
  601. // for a custom shape, that is in fact a polygon (with holes), we can use only a inflate value.
  602. // so use ( aInflateValue.x + aInflateValue.y ) / 2 as polygon inflate value.
  603. // (different values for aInflateValue.x and aInflateValue.y has no sense for a custom pad)
  604. TransformShapeWithClearanceToPolygon(
  605. aCornerBuffer, ( aInflateValue.x + aInflateValue.y ) / 2 );
  606. break;
  607. }
  608. }
  609. bool D_PAD::BuildPadDrillShapePolygon(
  610. SHAPE_POLY_SET& aCornerBuffer, int aInflateValue, int aError ) const
  611. {
  612. wxSize drillsize = GetDrillSize();
  613. if( !drillsize.x || !drillsize.y )
  614. return false;
  615. if( drillsize.x == drillsize.y ) // usual round hole
  616. {
  617. int radius = ( drillsize.x / 2 ) + aInflateValue;
  618. TransformCircleToPolygon( aCornerBuffer, GetPosition(), radius, aError );
  619. }
  620. else // Oblong hole
  621. {
  622. wxPoint start, end;
  623. int width;
  624. GetOblongDrillGeometry( start, end, width );
  625. width += aInflateValue * 2;
  626. TransformRoundedEndsSegmentToPolygon(
  627. aCornerBuffer, GetPosition() + start, GetPosition() + end, aError, width );
  628. }
  629. return true;
  630. }
  631. /**
  632. * Function CreateThermalReliefPadPolygon
  633. * Add holes around a pad to create a thermal relief
  634. * copper thickness is min (dx/2, aCopperWitdh) or min (dy/2, aCopperWitdh)
  635. * @param aCornerBuffer = a buffer to store the polygon
  636. * @param aPad = the current pad used to create the thermal shape
  637. * @param aThermalGap = gap in thermal shape
  638. * @param aCopperThickness = stubs thickness in thermal shape
  639. * @param aMinThicknessValue = min copper thickness allowed
  640. * @param aError = maximum error allowed when approximating arcs
  641. * @param aThermalRot = for rond pads the rotation of thermal stubs (450 usually for 45 deg.)
  642. */
  643. /* thermal reliefs are created as 4 polygons.
  644. * each corner of a polygon if calculated for a pad at position 0, 0, orient 0,
  645. * and then moved and rotated acroding to the pad position and orientation
  646. */
  647. /*
  648. * Note 1: polygons are drawm using outlines witk a thickness = aMinThicknessValue
  649. * so shapes must take in account this outline thickness
  650. *
  651. * Note 2:
  652. * Trapezoidal pads are not considered here because they are very special case
  653. * and are used in microwave applications and they *DO NOT* have a thermal relief that
  654. * change the shape by creating stubs and destroy their properties.
  655. */
  656. void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
  657. const D_PAD& aPad,
  658. int aThermalGap,
  659. int aCopperThickness,
  660. int aMinThicknessValue,
  661. int aError,
  662. double aThermalRot )
  663. {
  664. wxPoint corner, corner_end;
  665. wxSize copper_thickness;
  666. wxPoint padShapePos = aPad.ShapePos(); // Note: for pad having a shape offset,
  667. // the pad position is NOT the shape position
  668. /* Keep in account the polygon outline thickness
  669. * aThermalGap must be increased by aMinThicknessValue/2 because drawing external outline
  670. * with a thickness of aMinThicknessValue will reduce gap by aMinThicknessValue/2
  671. */
  672. aThermalGap += aMinThicknessValue / 2;
  673. /* Keep in account the polygon outline thickness
  674. * copper_thickness must be decreased by aMinThicknessValue because drawing outlines
  675. * with a thickness of aMinThicknessValue will increase real thickness by aMinThicknessValue
  676. */
  677. int dx = aPad.GetSize().x / 2;
  678. int dy = aPad.GetSize().y / 2;
  679. copper_thickness.x = std::min( aPad.GetSize().x, aCopperThickness ) - aMinThicknessValue;
  680. copper_thickness.y = std::min( aPad.GetSize().y, aCopperThickness ) - aMinThicknessValue;
  681. if( copper_thickness.x < 0 )
  682. copper_thickness.x = 0;
  683. if( copper_thickness.y < 0 )
  684. copper_thickness.y = 0;
  685. switch( aPad.GetShape() )
  686. {
  687. case PAD_SHAPE_CIRCLE: // Add 4 similar holes
  688. {
  689. /* we create 4 copper holes and put them in position 1, 2, 3 and 4
  690. * here is the area of the rectangular pad + its thermal gap
  691. * the 4 copper holes remove the copper in order to create the thermal gap
  692. * 4 ------ 1
  693. * | |
  694. * | |
  695. * | |
  696. * | |
  697. * 3 ------ 2
  698. * holes 2, 3, 4 are the same as hole 1, rotated 90, 180, 270 deg
  699. */
  700. // Build the hole pattern, for the hole in the X >0, Y > 0 plane:
  701. // The pattern roughtly is a 90 deg arc pie
  702. std::vector <wxPoint> corners_buffer;
  703. int numSegs = std::max( GetArcToSegmentCount( dx + aThermalGap, aError, 360.0 ), 6 );
  704. double correction = GetCircletoPolyCorrectionFactor( numSegs );
  705. double delta = 3600.0 / numSegs;
  706. // Radius of outer arcs of the shape corrected for arc approximation by lines
  707. int outer_radius = KiROUND( ( dx + aThermalGap ) * correction );
  708. // Crosspoint of thermal spoke sides, the first point of polygon buffer
  709. corners_buffer.push_back( wxPoint( copper_thickness.x / 2, copper_thickness.y / 2 ) );
  710. // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side
  711. // and first seg of arc approx
  712. corner.x = copper_thickness.x / 2;
  713. int y = outer_radius - (aThermalGap / 4);
  714. corner.y = KiROUND( sqrt( ( (double) y * y - (double) corner.x * corner.x ) ) );
  715. if( aThermalRot != 0 )
  716. corners_buffer.push_back( corner );
  717. // calculate the starting point of the outter arc
  718. corner.x = copper_thickness.x / 2;
  719. corner.y = KiROUND( sqrt( ( (double) outer_radius * outer_radius ) -
  720. ( (double) corner.x * corner.x ) ) );
  721. RotatePoint( &corner, 90 ); // 9 degrees is the spoke fillet size
  722. // calculate the ending point of the outer arc
  723. corner_end.x = corner.y;
  724. corner_end.y = corner.x;
  725. // calculate intermediate points (y coordinate from corner.y to corner_end.y
  726. while( (corner.y > corner_end.y) && (corner.x < corner_end.x) )
  727. {
  728. corners_buffer.push_back( corner );
  729. RotatePoint( &corner, delta );
  730. }
  731. corners_buffer.push_back( corner_end );
  732. /* add an intermediate point, to avoid angles < 90 deg between last arc approx line
  733. * and radius line
  734. */
  735. corner.x = corners_buffer[1].y;
  736. corner.y = corners_buffer[1].x;
  737. corners_buffer.push_back( corner );
  738. // Now, add the 4 holes ( each is the pattern, rotated by 0, 90, 180 and 270 deg
  739. // aThermalRot = 450 (45.0 degrees orientation) work fine.
  740. double angle_pad = aPad.GetOrientation(); // Pad orientation
  741. double th_angle = aThermalRot;
  742. for( unsigned ihole = 0; ihole < 4; ihole++ )
  743. {
  744. aCornerBuffer.NewOutline();
  745. for( unsigned ii = 0; ii < corners_buffer.size(); ii++ )
  746. {
  747. corner = corners_buffer[ii];
  748. RotatePoint( &corner, th_angle + angle_pad ); // Rotate by segment angle and pad orientation
  749. corner += padShapePos;
  750. aCornerBuffer.Append( corner.x, corner.y );
  751. }
  752. th_angle += 900; // Note: th_angle in in 0.1 deg.
  753. }
  754. }
  755. break;
  756. case PAD_SHAPE_OVAL:
  757. {
  758. // Oval pad support along the lines of round and rectangular pads
  759. std::vector <wxPoint> corners_buffer; // Polygon buffer as vector
  760. dx = (aPad.GetSize().x / 2) + aThermalGap; // Cutout radius x
  761. dy = (aPad.GetSize().y / 2) + aThermalGap; // Cutout radius y
  762. wxPoint shape_offset;
  763. // We want to calculate an oval shape with dx > dy.
  764. // if this is not the case, exchange dx and dy, and rotate the shape 90 deg.
  765. int supp_angle = 0;
  766. if( dx < dy )
  767. {
  768. std::swap( dx, dy );
  769. supp_angle = 900;
  770. std::swap( copper_thickness.x, copper_thickness.y );
  771. }
  772. int deltasize = dx - dy; // = distance between shape position and the 2 demi-circle ends centre
  773. // here we have dx > dy
  774. // Radius of outer arcs of the shape:
  775. int outer_radius = dy; // The radius of the outer arc is radius end + aThermalGap
  776. int numSegs = std::max( GetArcToSegmentCount( outer_radius, aError, 360.0 ), 6 );
  777. double delta = 3600.0 / numSegs;
  778. // Some coordinate fiddling, depending on the shape offset direction
  779. shape_offset = wxPoint( deltasize, 0 );
  780. // Crosspoint of thermal spoke sides, the first point of polygon buffer
  781. corner.x = copper_thickness.x / 2;
  782. corner.y = copper_thickness.y / 2;
  783. corners_buffer.push_back( corner );
  784. // Arc start point calculation, the intersecting point of cutout arc and thermal spoke edge
  785. // If copper thickness is more than shape offset, we need to calculate arc intercept point.
  786. if( copper_thickness.x > deltasize )
  787. {
  788. corner.x = copper_thickness.x / 2;
  789. corner.y = KiROUND( sqrt( ( (double) outer_radius * outer_radius ) -
  790. ( (double) ( corner.x - delta ) * ( corner.x - deltasize ) ) ) );
  791. corner.x -= deltasize;
  792. /* creates an intermediate point, to have a > 90 deg angle
  793. * between the side and the first segment of arc approximation
  794. */
  795. wxPoint intpoint = corner;
  796. intpoint.y -= aThermalGap / 4;
  797. corners_buffer.push_back( intpoint + shape_offset );
  798. RotatePoint( &corner, 90 ); // 9 degrees of thermal fillet
  799. }
  800. else
  801. {
  802. corner.x = copper_thickness.x / 2;
  803. corner.y = outer_radius;
  804. corners_buffer.push_back( corner );
  805. }
  806. // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side
  807. // and first seg of arc approx
  808. wxPoint last_corner;
  809. last_corner.y = copper_thickness.y / 2;
  810. int px = outer_radius - (aThermalGap / 4);
  811. last_corner.x =
  812. KiROUND( sqrt( ( ( (double) px * px ) - (double) last_corner.y * last_corner.y ) ) );
  813. // Arc stop point calculation, the intersecting point of cutout arc and thermal spoke edge
  814. corner_end.y = copper_thickness.y / 2;
  815. corner_end.x =
  816. KiROUND( sqrt( ( (double) outer_radius *
  817. outer_radius ) - ( (double) corner_end.y * corner_end.y ) ) );
  818. RotatePoint( &corner_end, -90 ); // 9 degrees of thermal fillet
  819. // calculate intermediate arc points till limit is reached
  820. while( (corner.y > corner_end.y) && (corner.x < corner_end.x) )
  821. {
  822. corners_buffer.push_back( corner + shape_offset );
  823. RotatePoint( &corner, delta );
  824. }
  825. //corners_buffer.push_back(corner + shape_offset); // TODO: about one mil geometry error forms somewhere.
  826. corners_buffer.push_back( corner_end + shape_offset );
  827. corners_buffer.push_back( last_corner + shape_offset ); // Enabling the line above shows intersection point.
  828. /* Create 2 holes, rotated by pad rotation.
  829. */
  830. double angle = aPad.GetOrientation() + supp_angle;
  831. for( int irect = 0; irect < 2; irect++ )
  832. {
  833. aCornerBuffer.NewOutline();
  834. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  835. {
  836. wxPoint cpos = corners_buffer[ic];
  837. RotatePoint( &cpos, angle );
  838. cpos += padShapePos;
  839. aCornerBuffer.Append( cpos.x, cpos.y );
  840. }
  841. angle = AddAngles( angle, 1800 ); // this is calculate hole 3
  842. }
  843. // Create holes, that are the mirrored from the previous holes
  844. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  845. {
  846. wxPoint swap = corners_buffer[ic];
  847. swap.x = -swap.x;
  848. corners_buffer[ic] = swap;
  849. }
  850. // Now add corner 4 and 2 (2 is the corner 4 rotated by 180 deg
  851. angle = aPad.GetOrientation() + supp_angle;
  852. for( int irect = 0; irect < 2; irect++ )
  853. {
  854. aCornerBuffer.NewOutline();
  855. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  856. {
  857. wxPoint cpos = corners_buffer[ic];
  858. RotatePoint( &cpos, angle );
  859. cpos += padShapePos;
  860. aCornerBuffer.Append( cpos.x, cpos.y );
  861. }
  862. angle = AddAngles( angle, 1800 );
  863. }
  864. }
  865. break;
  866. case PAD_SHAPE_CHAMFERED_RECT:
  867. case PAD_SHAPE_ROUNDRECT: // thermal shape is the same for rectangular shapes.
  868. case PAD_SHAPE_RECT:
  869. {
  870. /* we create 4 copper holes and put them in position 1, 2, 3 and 4
  871. * here is the area of the rectangular pad + its thermal gap
  872. * the 4 copper holes remove the copper in order to create the thermal gap
  873. * 1 ------ 4
  874. * | |
  875. * | |
  876. * | |
  877. * | |
  878. * 2 ------ 3
  879. * hole 3 is the same as hole 1, rotated 180 deg
  880. * hole 4 is the same as hole 2, rotated 180 deg and is the same as hole 1, mirrored
  881. */
  882. // First, create a rectangular hole for position 1 :
  883. // 2 ------- 3
  884. // | |
  885. // | |
  886. // | |
  887. // 1 -------4
  888. // Modified rectangles with one corner rounded. TODO: merging with oval thermals
  889. // and possibly round too.
  890. std::vector <wxPoint> corners_buffer; // Polygon buffer as vector
  891. dx = (aPad.GetSize().x / 2) + aThermalGap; // Cutout radius x
  892. dy = (aPad.GetSize().y / 2) + aThermalGap; // Cutout radius y
  893. // calculation is optimized for pad shape with dy >= dx (vertical rectangle).
  894. // if it is not the case, just rotate this shape 90 degrees:
  895. double angle = aPad.GetOrientation();
  896. wxPoint corner_origin_pos( -aPad.GetSize().x / 2, -aPad.GetSize().y / 2 );
  897. if( dy < dx )
  898. {
  899. std::swap( dx, dy );
  900. std::swap( copper_thickness.x, copper_thickness.y );
  901. std::swap( corner_origin_pos.x, corner_origin_pos.y );
  902. angle += 900.0;
  903. }
  904. // Now calculate the hole pattern in position 1 ( top left pad corner )
  905. // The first point of polygon buffer is left lower corner, second the crosspoint of
  906. // thermal spoke sides, the third is upper right corner and the rest are rounding
  907. // vertices going anticlockwise. Note the inverted Y-axis in corners_buffer y coordinates.
  908. wxPoint arc_end_point( -dx, -(aThermalGap / 4 + copper_thickness.y / 2) );
  909. corners_buffer.push_back( arc_end_point ); // Adds small miters to zone
  910. corners_buffer.push_back( wxPoint( -(dx - aThermalGap / 4), -copper_thickness.y / 2 ) ); // fill and spoke corner
  911. corners_buffer.push_back( wxPoint( -copper_thickness.x / 2, -copper_thickness.y / 2 ) );
  912. corners_buffer.push_back( wxPoint( -copper_thickness.x / 2, -(dy - aThermalGap / 4) ) );
  913. // The first point to build the rounded corner:
  914. wxPoint arc_start_point( -(aThermalGap / 4 + copper_thickness.x / 2) , -dy );
  915. corners_buffer.push_back( arc_start_point );
  916. int numSegs = std::max( GetArcToSegmentCount( aThermalGap, aError, 360.0 ), 6 );
  917. double correction = GetCircletoPolyCorrectionFactor( numSegs );
  918. int rounding_radius = KiROUND( aThermalGap * correction ); // Corner rounding radius
  919. // Calculate arc angle parameters.
  920. // the start angle id near 900 decidegrees, the final angle is near 1800.0 decidegrees.
  921. double arc_increment = 3600.0 / numSegs;
  922. // the arc_angle_start is 900.0 or slighly more, depending on the actual arc starting point
  923. double arc_angle_start = atan2( -arc_start_point.y -corner_origin_pos.y, arc_start_point.x - corner_origin_pos.x ) * 1800/M_PI;
  924. if( arc_angle_start < 900.0 )
  925. arc_angle_start = 900.0;
  926. bool first_point = true;
  927. for( double curr_angle = arc_angle_start; ; curr_angle += arc_increment )
  928. {
  929. wxPoint corner_position = wxPoint( rounding_radius, 0 );
  930. RotatePoint( &corner_position, curr_angle ); // Rounding vector rotation
  931. corner_position += corner_origin_pos; // Rounding vector + Pad corner offset
  932. // The arc angle is <= 90 degrees, therefore the arc is finished if the x coordinate
  933. // decrease or the y coordinate is smaller than the y end point
  934. if( !first_point &&
  935. ( corner_position.x >= corners_buffer.back().x || corner_position.y > arc_end_point.y ) )
  936. break;
  937. first_point = false;
  938. // Note: for hole in position 1, arc x coordinate is always < x starting point
  939. // and arc y coordinate is always <= y ending point
  940. if( corner_position != corners_buffer.back() // avoid duplicate corners.
  941. && corner_position.x <= arc_start_point.x ) // skip current point at the right of the starting point
  942. corners_buffer.push_back( corner_position );
  943. }
  944. for( int irect = 0; irect < 2; irect++ )
  945. {
  946. aCornerBuffer.NewOutline();
  947. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  948. {
  949. wxPoint cpos = corners_buffer[ic];
  950. RotatePoint( &cpos, angle ); // Rotate according to module orientation
  951. cpos += padShapePos; // Shift origin to position
  952. aCornerBuffer.Append( cpos.x, cpos.y );
  953. }
  954. angle = AddAngles( angle, 1800 ); // this is calculate hole 3
  955. }
  956. // Create holes, that are the mirrored from the previous holes
  957. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  958. {
  959. wxPoint swap = corners_buffer[ic];
  960. swap.x = -swap.x;
  961. corners_buffer[ic] = swap;
  962. }
  963. // Now add corner 4 and 2 (2 is the corner 4 rotated by 180 deg
  964. for( int irect = 0; irect < 2; irect++ )
  965. {
  966. aCornerBuffer.NewOutline();
  967. for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
  968. {
  969. wxPoint cpos = corners_buffer[ic];
  970. RotatePoint( &cpos, angle );
  971. cpos += padShapePos;
  972. aCornerBuffer.Append( cpos.x, cpos.y );
  973. }
  974. angle = AddAngles( angle, 1800 );
  975. }
  976. }
  977. break;
  978. case PAD_SHAPE_TRAPEZOID:
  979. {
  980. SHAPE_POLY_SET antipad; // The full antipad area
  981. // We need a length to build the stubs of the thermal reliefs
  982. // the value is not very important. The pad bounding box gives a reasonable value
  983. EDA_RECT bbox = aPad.GetBoundingBox();
  984. int stub_len = std::max( bbox.GetWidth(), bbox.GetHeight() );
  985. aPad.TransformShapeWithClearanceToPolygon( antipad, aThermalGap );
  986. SHAPE_POLY_SET stub; // A basic stub ( a rectangle)
  987. SHAPE_POLY_SET stubs; // the full stubs shape
  988. // We now substract the stubs (connections to the copper zone)
  989. //ClipperLib::Clipper clip_engine;
  990. // Prepare a clipping transform
  991. //clip_engine.AddPath( antipad, ClipperLib::ptSubject, true );
  992. // Create stubs and add them to clipper engine
  993. wxPoint stubBuffer[4];
  994. stubBuffer[0].x = stub_len;
  995. stubBuffer[0].y = copper_thickness.y/2;
  996. stubBuffer[1] = stubBuffer[0];
  997. stubBuffer[1].y = -copper_thickness.y/2;
  998. stubBuffer[2] = stubBuffer[1];
  999. stubBuffer[2].x = -stub_len;
  1000. stubBuffer[3] = stubBuffer[2];
  1001. stubBuffer[3].y = copper_thickness.y/2;
  1002. stub.NewOutline();
  1003. for( unsigned ii = 0; ii < arrayDim( stubBuffer ); ii++ )
  1004. {
  1005. wxPoint cpos = stubBuffer[ii];
  1006. RotatePoint( &cpos, aPad.GetOrientation() );
  1007. cpos += padShapePos;
  1008. stub.Append( cpos.x, cpos.y );
  1009. }
  1010. stubs.Append( stub );
  1011. stubBuffer[0].y = stub_len;
  1012. stubBuffer[0].x = copper_thickness.x/2;
  1013. stubBuffer[1] = stubBuffer[0];
  1014. stubBuffer[1].x = -copper_thickness.x/2;
  1015. stubBuffer[2] = stubBuffer[1];
  1016. stubBuffer[2].y = -stub_len;
  1017. stubBuffer[3] = stubBuffer[2];
  1018. stubBuffer[3].x = copper_thickness.x/2;
  1019. stub.RemoveAllContours();
  1020. stub.NewOutline();
  1021. for( unsigned ii = 0; ii < arrayDim( stubBuffer ); ii++ )
  1022. {
  1023. wxPoint cpos = stubBuffer[ii];
  1024. RotatePoint( &cpos, aPad.GetOrientation() );
  1025. cpos += padShapePos;
  1026. stub.Append( cpos.x, cpos.y );
  1027. }
  1028. stubs.Append( stub );
  1029. stubs.Simplify( SHAPE_POLY_SET::PM_FAST );
  1030. antipad.BooleanSubtract( stubs, SHAPE_POLY_SET::PM_FAST );
  1031. aCornerBuffer.Append( antipad );
  1032. break;
  1033. }
  1034. default:
  1035. ;
  1036. }
  1037. }
  1038. void ZONE_CONTAINER::TransformShapeWithClearanceToPolygon(
  1039. SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError, bool ignoreLineWidth ) const
  1040. {
  1041. wxASSERT_MSG( !ignoreLineWidth, "IgnoreLineWidth has no meaning for zones." );
  1042. aCornerBuffer = m_FilledPolysList;
  1043. aCornerBuffer.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
  1044. }