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.

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