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.

1353 lines
38 KiB

14 years ago
14 years ago
8 years ago
11 years ago
11 years ago
11 years ago
13 years ago
11 years ago
11 years ago
13 years ago
14 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file class_zone.cpp
  27. * @brief Implementation of class to handle copper zones.
  28. */
  29. #include <fctsys.h>
  30. #include <trigo.h>
  31. #include <pcb_screen.h>
  32. #include <class_drawpanel.h>
  33. #include <kicad_string.h>
  34. #include <richio.h>
  35. #include <macros.h>
  36. #include <pcb_base_frame.h>
  37. #include <msgpanel.h>
  38. #include <bitmaps.h>
  39. #include <convert_to_biu.h>
  40. #include <class_board.h>
  41. #include <class_zone.h>
  42. #include <pcbnew.h>
  43. #include <zones.h>
  44. #include <math_for_graphics.h>
  45. #include <polygon_test_point_inside.h>
  46. ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) :
  47. BOARD_CONNECTED_ITEM( aBoard, PCB_ZONE_AREA_T )
  48. {
  49. m_CornerSelection = nullptr; // no corner is selected
  50. m_IsFilled = false; // fill status : true when the zone is filled
  51. m_FillMode = ZFM_POLYGONS;
  52. m_hatchStyle = DIAGONAL_EDGE;
  53. m_hatchPitch = GetDefaultHatchPitch();
  54. m_hv45 = false;
  55. m_priority = 0;
  56. m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
  57. SetIsKeepout( false );
  58. SetDoNotAllowCopperPour( false ); // has meaning only if m_isKeepout == true
  59. SetDoNotAllowVias( true ); // has meaning only if m_isKeepout == true
  60. SetDoNotAllowTracks( true ); // has meaning only if m_isKeepout == true
  61. m_cornerRadius = 0;
  62. SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
  63. m_Poly = new SHAPE_POLY_SET(); // Outlines
  64. aBoard->GetZoneSettings().ExportSetting( *this );
  65. }
  66. ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) :
  67. BOARD_CONNECTED_ITEM( aZone )
  68. {
  69. // Should the copy be on the same net?
  70. SetNetCode( aZone.GetNetCode() );
  71. m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
  72. // For corner moving, corner index to drag, or nullptr if no selection
  73. m_CornerSelection = nullptr;
  74. m_IsFilled = aZone.m_IsFilled;
  75. m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
  76. m_ZoneMinThickness = aZone.m_ZoneMinThickness;
  77. m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons)
  78. m_hv45 = aZone.m_hv45;
  79. m_priority = aZone.m_priority;
  80. m_ArcToSegmentsCount = aZone.m_ArcToSegmentsCount;
  81. m_PadConnection = aZone.m_PadConnection;
  82. m_ThermalReliefGap = aZone.m_ThermalReliefGap;
  83. m_ThermalReliefCopperBridge = aZone.m_ThermalReliefCopperBridge;
  84. m_FilledPolysList.Append( aZone.m_FilledPolysList );
  85. m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
  86. m_isKeepout = aZone.m_isKeepout;
  87. m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
  88. m_doNotAllowVias = aZone.m_doNotAllowVias;
  89. m_doNotAllowTracks = aZone.m_doNotAllowTracks;
  90. m_cornerSmoothingType = aZone.m_cornerSmoothingType;
  91. m_cornerRadius = aZone.m_cornerRadius;
  92. m_hatchStyle = aZone.m_hatchStyle;
  93. m_hatchPitch = aZone.m_hatchPitch;
  94. m_HatchLines = aZone.m_HatchLines;
  95. SetLayerSet( aZone.GetLayerSet() );
  96. SetLocalFlags( aZone.GetLocalFlags() );
  97. }
  98. ZONE_CONTAINER& ZONE_CONTAINER::operator=( const ZONE_CONTAINER& aOther )
  99. {
  100. BOARD_CONNECTED_ITEM::operator=( aOther );
  101. // Replace the outlines for aOther outlines.
  102. delete m_Poly;
  103. m_Poly = new SHAPE_POLY_SET( *aOther.m_Poly );
  104. m_CornerSelection = nullptr; // for corner moving, corner index to (null if no selection)
  105. m_ZoneClearance = aOther.m_ZoneClearance; // clearance value
  106. m_ZoneMinThickness = aOther.m_ZoneMinThickness;
  107. m_FillMode = aOther.m_FillMode; // filling mode (segments/polygons)
  108. m_ArcToSegmentsCount = aOther.m_ArcToSegmentsCount;
  109. m_PadConnection = aOther.m_PadConnection;
  110. m_ThermalReliefGap = aOther.m_ThermalReliefGap;
  111. m_ThermalReliefCopperBridge = aOther.m_ThermalReliefCopperBridge;
  112. SetHatchStyle( aOther.GetHatchStyle() );
  113. SetHatchPitch( aOther.GetHatchPitch() );
  114. m_HatchLines = aOther.m_HatchLines; // copy vector <SEG>
  115. m_FilledPolysList.RemoveAllContours();
  116. m_FilledPolysList.Append( aOther.m_FilledPolysList );
  117. m_FillSegmList.clear();
  118. m_FillSegmList = aOther.m_FillSegmList;
  119. SetLayerSet( aOther.GetLayerSet() );
  120. return *this;
  121. }
  122. ZONE_CONTAINER::~ZONE_CONTAINER()
  123. {
  124. delete m_Poly;
  125. delete m_CornerSelection;
  126. }
  127. EDA_ITEM* ZONE_CONTAINER::Clone() const
  128. {
  129. return new ZONE_CONTAINER( *this );
  130. }
  131. bool ZONE_CONTAINER::UnFill()
  132. {
  133. bool change = ( !m_FilledPolysList.IsEmpty() ) ||
  134. ( m_FillSegmList.size() > 0 );
  135. m_FilledPolysList.RemoveAllContours();
  136. m_FillSegmList.clear();
  137. m_IsFilled = false;
  138. return change;
  139. }
  140. const wxPoint ZONE_CONTAINER::GetPosition() const
  141. {
  142. return (wxPoint) GetCornerPosition( 0 );
  143. }
  144. PCB_LAYER_ID ZONE_CONTAINER::GetLayer() const
  145. {
  146. return BOARD_ITEM::GetLayer();
  147. }
  148. bool ZONE_CONTAINER::IsOnCopperLayer() const
  149. {
  150. if( GetIsKeepout() )
  151. {
  152. return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
  153. }
  154. else
  155. {
  156. return IsCopperLayer( GetLayer() );
  157. }
  158. }
  159. bool ZONE_CONTAINER::CommonLayerExists( const LSET aLayerSet ) const
  160. {
  161. LSET common = GetLayerSet() & aLayerSet;
  162. return common.count() > 0;
  163. }
  164. void ZONE_CONTAINER::SetLayer( PCB_LAYER_ID aLayer )
  165. {
  166. SetLayerSet( LSET( aLayer ) );
  167. m_Layer = aLayer;
  168. }
  169. void ZONE_CONTAINER::SetLayerSet( LSET aLayerSet )
  170. {
  171. if( GetIsKeepout() )
  172. {
  173. // Keepouts can only exist on copper layers
  174. aLayerSet &= LSET::AllCuMask();
  175. }
  176. if( aLayerSet.count() == 0 )
  177. {
  178. return;
  179. }
  180. m_layerSet = aLayerSet;
  181. // Set the single layer to the first selected layer
  182. m_Layer = aLayerSet.Seq()[0];
  183. }
  184. LSET ZONE_CONTAINER::GetLayerSet() const
  185. {
  186. // TODO - Enable multi-layer zones for all zone types
  187. // not just keepout zones
  188. if( GetIsKeepout() )
  189. {
  190. return m_layerSet;
  191. }
  192. else
  193. {
  194. return LSET( m_Layer );
  195. }
  196. }
  197. void ZONE_CONTAINER::ViewGetLayers( int aLayers[], int& aCount ) const
  198. {
  199. if( GetIsKeepout() )
  200. {
  201. LSEQ layers = m_layerSet.Seq();
  202. for( unsigned int idx = 0; idx < layers.size(); idx++ )
  203. {
  204. aLayers[idx] = layers[idx];
  205. }
  206. aCount = layers.size();
  207. }
  208. else
  209. {
  210. aLayers[0] = m_Layer;
  211. aCount = 1;
  212. }
  213. }
  214. bool ZONE_CONTAINER::IsOnLayer( PCB_LAYER_ID aLayer ) const
  215. {
  216. if( GetIsKeepout() )
  217. {
  218. return m_layerSet.test( aLayer );
  219. }
  220. return BOARD_ITEM::IsOnLayer( aLayer );
  221. }
  222. void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
  223. const wxPoint& offset )
  224. {
  225. if( !DC )
  226. return;
  227. wxPoint seg_start, seg_end;
  228. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  229. BOARD* brd = GetBoard();
  230. auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
  231. PCB_LAYER_ID draw_layer = UNDEFINED_LAYER;
  232. LSET layers = GetLayerSet() & brd->GetVisibleLayers();
  233. // If there are no visible layers and the zone is not highlighted, return
  234. if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
  235. {
  236. return;
  237. }
  238. /* Keepout zones can exist on multiple layers
  239. * Thus, determining which color to use to render them is a bit tricky.
  240. * In descending order of priority:
  241. *
  242. * 1. If in GR_HIGHLIGHT mode:
  243. * a. If zone is on selected layer, use layer color!
  244. * b. Else, use grey
  245. * 1. Not in GR_HIGHLIGHT mode
  246. * a. If zone is on selected layer, use layer color
  247. * b. Else, use color of top-most (visible) layer
  248. *
  249. */
  250. if( GetIsKeepout() )
  251. {
  252. // At least one layer must be provided!
  253. assert( GetLayerSet().count() > 0 );
  254. // Not on any visible layer?
  255. if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
  256. {
  257. return;
  258. }
  259. // Is keepout zone present on the selected layer?
  260. if( layers.test( curr_layer ) )
  261. {
  262. draw_layer = curr_layer;
  263. }
  264. else
  265. {
  266. // Select the first (top) visible layer
  267. if( layers.count() > 0 )
  268. {
  269. draw_layer = layers.Seq()[0];
  270. }
  271. else
  272. {
  273. draw_layer = GetLayerSet().Seq()[0];
  274. }
  275. }
  276. }
  277. /* Non-keepout zones are easier to deal with
  278. */
  279. else
  280. {
  281. if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
  282. {
  283. return;
  284. }
  285. draw_layer = GetLayer();
  286. }
  287. assert( draw_layer != UNDEFINED_LAYER );
  288. auto color = frame->Settings().Colors().GetLayerColor( draw_layer );
  289. GRSetDrawMode( DC, aDrawMode );
  290. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
  291. if( displ_opts->m_ContrastModeDisplay )
  292. {
  293. if( !IsOnLayer( curr_layer ) )
  294. {
  295. color = COLOR4D( DARKDARKGRAY );
  296. }
  297. }
  298. if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
  299. {
  300. color.SetToLegacyHighlightColor();
  301. }
  302. color.a = 0.588;
  303. // draw the lines
  304. std::vector<wxPoint> lines;
  305. lines.reserve( (GetNumCorners() * 2) + 2 );
  306. // Iterate through the segments of the outline
  307. for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
  308. {
  309. // Create the segment
  310. SEG segment = *iterator;
  311. lines.push_back( static_cast<wxPoint>( segment.A ) + offset );
  312. lines.push_back( static_cast<wxPoint>( segment.B ) + offset );
  313. }
  314. GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
  315. // draw hatches
  316. lines.clear();
  317. lines.reserve( (m_HatchLines.size() * 2) + 2 );
  318. for( unsigned ic = 0; ic < m_HatchLines.size(); ic++ )
  319. {
  320. seg_start = static_cast<wxPoint>( m_HatchLines[ic].A ) + offset;
  321. seg_end = static_cast<wxPoint>( m_HatchLines[ic].B ) + offset;
  322. lines.push_back( seg_start );
  323. lines.push_back( seg_end );
  324. }
  325. GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
  326. }
  327. void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
  328. wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
  329. {
  330. static std::vector <wxPoint> CornersBuffer;
  331. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
  332. // outline_mode is false to show filled polys,
  333. // and true to show polygons outlines only (test and debug purposes)
  334. bool outline_mode = displ_opts->m_DisplayZonesMode == 2 ? true : false;
  335. if( DC == NULL )
  336. return;
  337. if( displ_opts->m_DisplayZonesMode == 1 ) // Do not show filled areas
  338. return;
  339. if( m_FilledPolysList.IsEmpty() ) // Nothing to draw
  340. return;
  341. BOARD* brd = GetBoard();
  342. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  343. auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
  344. auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
  345. if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
  346. return;
  347. GRSetDrawMode( DC, aDrawMode );
  348. if( displ_opts->m_ContrastModeDisplay )
  349. {
  350. if( !IsOnLayer( curr_layer ) )
  351. color = COLOR4D( DARKDARKGRAY );
  352. }
  353. if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
  354. color.SetToLegacyHighlightColor();
  355. color.a = 0.588;
  356. for ( int ic = 0; ic < m_FilledPolysList.OutlineCount(); ic++ )
  357. {
  358. const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( ic );
  359. CornersBuffer.clear();
  360. wxPoint p0;
  361. for( int j = 0; j < path.PointCount(); j++ )
  362. {
  363. const VECTOR2I& corner = path.CPoint( j );
  364. wxPoint coord( corner.x + offset.x, corner.y + offset.y );
  365. if( j == 0 )
  366. p0 = coord;
  367. CornersBuffer.push_back( coord );
  368. }
  369. CornersBuffer.push_back( p0 );
  370. // Draw outlines:
  371. if( ( m_ZoneMinThickness > 1 ) || outline_mode )
  372. {
  373. int ilim = CornersBuffer.size() - 1;
  374. for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
  375. {
  376. int x0 = CornersBuffer[is].x;
  377. int y0 = CornersBuffer[is].y;
  378. int x1 = CornersBuffer[ie].x;
  379. int y1 = CornersBuffer[ie].y;
  380. // Draw only basic outlines, not extra segments.
  381. if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
  382. GRCSegm( panel->GetClipBox(), DC,
  383. x0, y0, x1, y1,
  384. m_ZoneMinThickness, color );
  385. else
  386. GRFillCSegm( panel->GetClipBox(), DC,
  387. x0, y0, x1, y1, m_ZoneMinThickness, color );
  388. }
  389. }
  390. // Draw areas:
  391. if( m_FillMode == ZFM_POLYGONS && !outline_mode )
  392. GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
  393. true, 0, color, color );
  394. }
  395. if( m_FillMode == 1 && !outline_mode ) // filled with segments
  396. {
  397. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  398. {
  399. wxPoint start = (wxPoint) ( m_FillSegmList[ic].A + VECTOR2I(offset) );
  400. wxPoint end = (wxPoint) ( m_FillSegmList[ic].B + VECTOR2I(offset) );
  401. if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
  402. GRCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
  403. m_ZoneMinThickness, color );
  404. else
  405. GRFillCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
  406. m_ZoneMinThickness, color );
  407. }
  408. }
  409. }
  410. const EDA_RECT ZONE_CONTAINER::GetBoundingBox() const
  411. {
  412. const int PRELOAD = 0x7FFFFFFF; // Biggest integer (32 bits)
  413. int ymax = -PRELOAD;
  414. int ymin = PRELOAD;
  415. int xmin = PRELOAD;
  416. int xmax = -PRELOAD;
  417. int count = GetNumCorners();
  418. for( int i = 0; i<count; ++i )
  419. {
  420. wxPoint corner = static_cast<wxPoint>( GetCornerPosition( i ) );
  421. ymax = std::max( ymax, corner.y );
  422. xmax = std::max( xmax, corner.x );
  423. ymin = std::min( ymin, corner.y );
  424. xmin = std::min( xmin, corner.x );
  425. }
  426. EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
  427. return ret;
  428. }
  429. void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC,
  430. GR_DRAWMODE draw_mode )
  431. {
  432. GR_DRAWMODE current_gr_mode = draw_mode;
  433. bool is_close_segment = false;
  434. if( !DC )
  435. return;
  436. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  437. auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
  438. auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
  439. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
  440. if( displ_opts->m_ContrastModeDisplay )
  441. {
  442. if( !IsOnLayer( curr_layer ) )
  443. color = COLOR4D( DARKDARKGRAY );
  444. }
  445. // Object to iterate through the corners of the outlines
  446. SHAPE_POLY_SET::ITERATOR iterator = m_Poly->Iterate();
  447. // Segment start and end
  448. VECTOR2I seg_start, seg_end;
  449. // Remember the first point of this contour
  450. VECTOR2I contour_first_point = *iterator;
  451. // Iterate through all the corners of the outlines and build the segments to draw
  452. while( iterator )
  453. {
  454. // Get the first point of the current segment
  455. seg_start = *iterator;
  456. // Get the last point of the current segment, handling the case where the end of the
  457. // contour is reached, when the last point of the segment is the first point of the
  458. // contour
  459. if( !iterator.IsEndContour() )
  460. {
  461. // Set GR mode to default
  462. current_gr_mode = draw_mode;
  463. SHAPE_POLY_SET::ITERATOR iterator_copy = iterator;
  464. iterator_copy++;
  465. if( iterator_copy.IsEndContour() )
  466. current_gr_mode = GR_XOR;
  467. is_close_segment = false;
  468. iterator++;
  469. seg_end = *iterator;
  470. }
  471. else
  472. {
  473. is_close_segment = true;
  474. seg_end = contour_first_point;
  475. // Reassign first point of the contour to the next contour start
  476. iterator++;
  477. if( iterator )
  478. contour_first_point = *iterator;
  479. // Set GR mode to XOR
  480. current_gr_mode = GR_XOR;
  481. }
  482. GRSetDrawMode( DC, current_gr_mode );
  483. if( is_close_segment )
  484. GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
  485. WHITE );
  486. else
  487. GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
  488. color );
  489. }
  490. }
  491. int ZONE_CONTAINER::GetThermalReliefGap( D_PAD* aPad ) const
  492. {
  493. if( aPad == NULL || aPad->GetThermalGap() == 0 )
  494. return m_ThermalReliefGap;
  495. else
  496. return aPad->GetThermalGap();
  497. }
  498. int ZONE_CONTAINER::GetThermalReliefCopperBridge( D_PAD* aPad ) const
  499. {
  500. if( aPad == NULL || aPad->GetThermalWidth() == 0 )
  501. return m_ThermalReliefCopperBridge;
  502. else
  503. return aPad->GetThermalWidth();
  504. }
  505. void ZONE_CONTAINER::SetCornerRadius( unsigned int aRadius )
  506. {
  507. m_cornerRadius = aRadius;
  508. }
  509. bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) const
  510. {
  511. return HitTestForCorner( aPosition ) || HitTestForEdge( aPosition ) ||
  512. HitTestFilledArea( aPosition );
  513. }
  514. void ZONE_CONTAINER::SetSelectedCorner( const wxPoint& aPosition )
  515. {
  516. SHAPE_POLY_SET::VERTEX_INDEX corner;
  517. // If there is some corner to be selected, assign it to m_CornerSelection
  518. if( HitTestForCorner( aPosition, corner ) || HitTestForEdge( aPosition, corner ) )
  519. {
  520. if( m_CornerSelection == nullptr )
  521. m_CornerSelection = new SHAPE_POLY_SET::VERTEX_INDEX;
  522. *m_CornerSelection = corner;
  523. }
  524. }
  525. // Zones outlines have no thickness, so it Hit Test functions
  526. // we must have a default distance between the test point
  527. // and a corner or a zone edge:
  528. #define MAX_DIST_IN_MM 0.25
  529. bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos,
  530. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
  531. {
  532. int distmax = Millimeter2iu( MAX_DIST_IN_MM );
  533. return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, distmax );
  534. }
  535. bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) const
  536. {
  537. SHAPE_POLY_SET::VERTEX_INDEX dummy;
  538. return HitTestForCorner( refPos, dummy );
  539. }
  540. bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos,
  541. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
  542. {
  543. int distmax = Millimeter2iu( MAX_DIST_IN_MM );
  544. return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, distmax );
  545. }
  546. bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) const
  547. {
  548. SHAPE_POLY_SET::VERTEX_INDEX dummy;
  549. return HitTestForEdge( refPos, dummy );
  550. }
  551. bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  552. {
  553. // Calculate bounding box for zone
  554. EDA_RECT bbox = GetBoundingBox();
  555. bbox.Normalize();
  556. EDA_RECT arect = aRect;
  557. arect.Normalize();
  558. arect.Inflate( aAccuracy );
  559. if( aContained )
  560. {
  561. return arect.Contains( bbox );
  562. }
  563. else // Test for intersection between aBox and the polygon
  564. // For a polygon, using its bounding box has no sense here
  565. {
  566. // Fast test: if aBox is outside the polygon bounding box,
  567. // rectangles cannot intersect
  568. if( !arect.Intersects( bbox ) )
  569. return false;
  570. // aBox is inside the polygon bounding box,
  571. // and can intersect the polygon: use a fine test.
  572. // aBox intersects the polygon if at least one aBox corner
  573. // is inside the polygon
  574. /*
  575. wxPoint origin = arect.GetOrigin();
  576. int w = arect.GetWidth();
  577. int h = arect.GetHeight();
  578. if ( HitTestInsideZone( origin ) ||
  579. HitTestInsideZone( origin + wxPoint( w, 0 ) ) ||
  580. HitTestInsideZone( origin + wxPoint( w, h ) ) ||
  581. HitTestInsideZone( origin + wxPoint( 0, h ) ) )
  582. {
  583. return true;
  584. }
  585. */
  586. // No corner inside aBox, but outlines can intersect aBox
  587. // if one of outline corners is inside aBox
  588. int count = m_Poly->TotalVertices();
  589. for( int ii =0; ii < count; ii++ )
  590. {
  591. auto vertex = m_Poly->Vertex( ii );
  592. auto vertexNext = m_Poly->Vertex( ( ii + 1 ) % count );
  593. // Test if the point is within the rect
  594. if( arect.Contains( ( wxPoint ) vertex ) )
  595. {
  596. return true;
  597. }
  598. // Test if this edge intersects the rect
  599. if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
  600. {
  601. return true;
  602. }
  603. }
  604. return false;
  605. }
  606. }
  607. int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
  608. {
  609. int myClearance = m_ZoneClearance;
  610. #if 1 // Maybe the netclass clearance should not come into play for a zone?
  611. // At least the policy decision can be controlled by the zone
  612. // itself, i.e. here. On reasons of insufficient documentation,
  613. // the user will be less bewildered if we simply respect the
  614. // "zone clearance" setting in the zone properties dialog. (At least
  615. // until there is a UI boolean for this.)
  616. NETCLASSPTR myClass = GetNetClass();
  617. if( myClass )
  618. myClearance = std::max( myClearance, myClass->GetClearance() );
  619. #endif
  620. if( aItem )
  621. {
  622. int hisClearance = aItem->GetClearance( NULL );
  623. myClearance = std::max( hisClearance, myClearance );
  624. }
  625. return myClearance;
  626. }
  627. bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
  628. {
  629. return m_FilledPolysList.Contains( VECTOR2I( aRefPos.x, aRefPos.y ) );
  630. }
  631. void ZONE_CONTAINER::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
  632. {
  633. wxString msg;
  634. msg = _( "Zone Outline" );
  635. // Display Cutout instead of Outline for holes inside a zone
  636. // i.e. when num contour !=0
  637. // Check whether the selected corner is in a hole; i.e., in any contour but the first one.
  638. if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
  639. msg << wxT( " " ) << _( "(Cutout)" );
  640. aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, DARKCYAN ) );
  641. if( GetIsKeepout() )
  642. {
  643. msg.Empty();
  644. if( GetDoNotAllowVias() )
  645. AccumulateDescription( msg, _( "No via" ) );
  646. if( GetDoNotAllowTracks() )
  647. AccumulateDescription( msg, _("No track") );
  648. if( GetDoNotAllowCopperPour() )
  649. AccumulateDescription( msg, _("No copper pour") );
  650. aList.push_back( MSG_PANEL_ITEM( _( "Keepout" ), msg, RED ) );
  651. }
  652. else if( IsOnCopperLayer() )
  653. {
  654. if( GetNetCode() >= 0 )
  655. {
  656. NETINFO_ITEM* net = GetNet();
  657. if( net )
  658. msg = net->GetNetname();
  659. else // Should not occur
  660. msg = _( "<unknown>" );
  661. }
  662. else // a netcode < 0 is an error
  663. msg = wxT( "<error>" );
  664. aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
  665. // Display net code : (useful in test or debug)
  666. msg.Printf( wxT( "%d" ), GetNetCode() );
  667. aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
  668. // Display priority level
  669. msg.Printf( wxT( "%d" ), GetPriority() );
  670. aList.push_back( MSG_PANEL_ITEM( _( "Priority" ), msg, BLUE ) );
  671. }
  672. else
  673. {
  674. aList.push_back( MSG_PANEL_ITEM( _( "Non Copper Zone" ), wxEmptyString, RED ) );
  675. }
  676. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BROWN ) );
  677. msg.Printf( wxT( "%d" ), (int) m_Poly->TotalVertices() );
  678. aList.push_back( MSG_PANEL_ITEM( _( "Corners" ), msg, BLUE ) );
  679. if( m_FillMode )
  680. msg = _( "Segments" );
  681. else
  682. msg = _( "Polygons" );
  683. aList.push_back( MSG_PANEL_ITEM( _( "Fill Mode" ), msg, BROWN ) );
  684. // Useful for statistics :
  685. msg.Printf( wxT( "%d" ), (int) m_HatchLines.size() );
  686. aList.push_back( MSG_PANEL_ITEM( _( "Hatch Lines" ), msg, BLUE ) );
  687. if( !m_FilledPolysList.IsEmpty() )
  688. {
  689. msg.Printf( wxT( "%d" ), m_FilledPolysList.TotalVertices() );
  690. aList.push_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) );
  691. }
  692. }
  693. /* Geometric transforms: */
  694. void ZONE_CONTAINER::Move( const wxPoint& offset )
  695. {
  696. /* move outlines */
  697. m_Poly->Move( VECTOR2I( offset ) );
  698. Hatch();
  699. m_FilledPolysList.Move( VECTOR2I( offset.x, offset.y ) );
  700. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  701. {
  702. m_FillSegmList[ic].A += VECTOR2I(offset);
  703. m_FillSegmList[ic].B += VECTOR2I(offset);
  704. }
  705. }
  706. void ZONE_CONTAINER::MoveEdge( const wxPoint& offset, int aEdge )
  707. {
  708. int next_corner;
  709. if( m_Poly->GetNeighbourIndexes( aEdge, nullptr, &next_corner ) )
  710. {
  711. m_Poly->Vertex( aEdge ) += VECTOR2I( offset );
  712. m_Poly->Vertex( next_corner ) += VECTOR2I( offset );
  713. Hatch();
  714. }
  715. }
  716. void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle )
  717. {
  718. wxPoint pos;
  719. for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
  720. {
  721. pos = static_cast<wxPoint>( *iterator );
  722. RotatePoint( &pos, centre, angle );
  723. iterator->x = pos.x;
  724. iterator->y = pos.y;
  725. }
  726. Hatch();
  727. /* rotate filled areas: */
  728. for( auto ic = m_FilledPolysList.Iterate(); ic; ++ic )
  729. RotatePoint( &ic->x, &ic->y, centre.x, centre.y, angle );
  730. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  731. {
  732. wxPoint a( m_FillSegmList[ic].A );
  733. RotatePoint( &a, centre, angle );
  734. m_FillSegmList[ic].A = a;
  735. wxPoint b( m_FillSegmList[ic].B );
  736. RotatePoint( &b, centre, angle );
  737. m_FillSegmList[ic].B = a;
  738. }
  739. }
  740. void ZONE_CONTAINER::Flip( const wxPoint& aCentre )
  741. {
  742. Mirror( aCentre );
  743. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  744. if( GetIsKeepout() )
  745. {
  746. SetLayerSet( FlipLayerMask( GetLayerSet(), copperLayerCount ) );
  747. }
  748. else
  749. {
  750. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  751. }
  752. }
  753. void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
  754. {
  755. for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
  756. {
  757. int py = mirror_ref.y - iterator->y;
  758. iterator->y = py + mirror_ref.y;
  759. }
  760. Hatch();
  761. for( auto ic = m_FilledPolysList.Iterate(); ic; ++ic )
  762. {
  763. int py = mirror_ref.y - ic->y;
  764. ic->y = py + mirror_ref.y;
  765. }
  766. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  767. {
  768. MIRROR( m_FillSegmList[ic].A.y, mirror_ref.y );
  769. MIRROR( m_FillSegmList[ic].B.y, mirror_ref.y );
  770. }
  771. }
  772. ZoneConnection ZONE_CONTAINER::GetPadConnection( D_PAD* aPad ) const
  773. {
  774. if( aPad == NULL || aPad->GetZoneConnection() == PAD_ZONE_CONN_INHERITED )
  775. return m_PadConnection;
  776. else
  777. return aPad->GetZoneConnection();
  778. }
  779. void ZONE_CONTAINER::AddPolygon( std::vector< wxPoint >& aPolygon )
  780. {
  781. if( aPolygon.empty() )
  782. return;
  783. SHAPE_LINE_CHAIN outline;
  784. // Create an outline and populate it with the points of aPolygon
  785. for( unsigned i = 0; i < aPolygon.size(); i++ )
  786. {
  787. outline.Append( VECTOR2I( aPolygon[i] ) );
  788. }
  789. outline.SetClosed( true );
  790. // Add the outline as a new polygon in the polygon set
  791. if( m_Poly->OutlineCount() == 0 )
  792. m_Poly->AddOutline( outline );
  793. else
  794. m_Poly->AddHole( outline );
  795. }
  796. bool ZONE_CONTAINER::AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication )
  797. {
  798. // Ensure the main outline exists:
  799. if( m_Poly->OutlineCount() == 0 )
  800. m_Poly->NewOutline();
  801. // If aHoleIdx >= 0, the corner musty be added to the hole, index aHoleIdx.
  802. // (remember: the index of the first hole is 0)
  803. // Return error if if does dot exist.
  804. if( aHoleIdx >= m_Poly->HoleCount( 0 ) )
  805. return false;
  806. m_Poly->Append( aPosition.x, aPosition.y, -1, aHoleIdx, aAllowDuplication );
  807. return true;
  808. }
  809. wxString ZONE_CONTAINER::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  810. {
  811. wxString text;
  812. // Check whether the selected contour is a hole (contour index > 0)
  813. if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
  814. text << wxT( " " ) << _( "(Cutout)" );
  815. if( GetIsKeepout() )
  816. text << wxT( " " ) << _( "(Keepout)" );
  817. else
  818. text << GetNetnameMsg();
  819. return wxString::Format( _( "Zone Outline %s on %s" ), text, GetLayerName() );
  820. }
  821. int ZONE_CONTAINER::GetHatchPitch() const
  822. {
  823. return m_hatchPitch;
  824. }
  825. void ZONE_CONTAINER::SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch )
  826. {
  827. SetHatchPitch( aHatchPitch );
  828. m_hatchStyle = (ZONE_CONTAINER::HATCH_STYLE) aHatchStyle;
  829. if( aRebuildHatch )
  830. Hatch();
  831. }
  832. void ZONE_CONTAINER::SetHatchPitch( int aPitch )
  833. {
  834. m_hatchPitch = aPitch;
  835. }
  836. void ZONE_CONTAINER::UnHatch()
  837. {
  838. m_HatchLines.clear();
  839. }
  840. // Creates hatch lines inside the outline of the complex polygon
  841. // sort function used in ::Hatch to sort points by descending wxPoint.x values
  842. bool sortEndsByDescendingX( const VECTOR2I& ref, const VECTOR2I& tst )
  843. {
  844. return tst.x < ref.x;
  845. }
  846. void ZONE_CONTAINER::Hatch()
  847. {
  848. UnHatch();
  849. if( m_hatchStyle == NO_HATCH || m_hatchPitch == 0 || m_Poly->IsEmpty() )
  850. return;
  851. // define range for hatch lines
  852. int min_x = m_Poly->Vertex( 0 ).x;
  853. int max_x = m_Poly->Vertex( 0 ).x;
  854. int min_y = m_Poly->Vertex( 0 ).y;
  855. int max_y = m_Poly->Vertex( 0 ).y;
  856. for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
  857. {
  858. if( iterator->x < min_x )
  859. min_x = iterator->x;
  860. if( iterator->x > max_x )
  861. max_x = iterator->x;
  862. if( iterator->y < min_y )
  863. min_y = iterator->y;
  864. if( iterator->y > max_y )
  865. max_y = iterator->y;
  866. }
  867. // Calculate spacing between 2 hatch lines
  868. int spacing;
  869. if( m_hatchStyle == DIAGONAL_EDGE )
  870. spacing = m_hatchPitch;
  871. else
  872. spacing = m_hatchPitch * 2;
  873. // set the "length" of hatch lines (the length on horizontal axis)
  874. int hatch_line_len = m_hatchPitch;
  875. // To have a better look, give a slope depending on the layer
  876. LAYER_NUM layer = GetLayer();
  877. int slope_flag = (layer & 1) ? 1 : -1; // 1 or -1
  878. double slope = 0.707106 * slope_flag; // 45 degrees slope
  879. int max_a, min_a;
  880. if( slope_flag == 1 )
  881. {
  882. max_a = KiROUND( max_y - slope * min_x );
  883. min_a = KiROUND( min_y - slope * max_x );
  884. }
  885. else
  886. {
  887. max_a = KiROUND( max_y - slope * max_x );
  888. min_a = KiROUND( min_y - slope * min_x );
  889. }
  890. min_a = (min_a / spacing) * spacing;
  891. // calculate an offset depending on layer number,
  892. // for a better look of hatches on a multilayer board
  893. int offset = (layer * 7) / 8;
  894. min_a += offset;
  895. // loop through hatch lines
  896. #define MAXPTS 200 // Usually we store only few values per one hatch line
  897. // depending on the complexity of the zone outline
  898. static std::vector<VECTOR2I> pointbuffer;
  899. pointbuffer.clear();
  900. pointbuffer.reserve( MAXPTS + 2 );
  901. for( int a = min_a; a < max_a; a += spacing )
  902. {
  903. // get intersection points for this hatch line
  904. // Note: because we should have an even number of intersections with the
  905. // current hatch line and the zone outline (a closed polygon,
  906. // or a set of closed polygons), if an odd count is found
  907. // we skip this line (should not occur)
  908. pointbuffer.clear();
  909. // Iterate through all vertices
  910. for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
  911. {
  912. double x, y, x2, y2;
  913. int ok;
  914. SEG segment = *iterator;
  915. ok = FindLineSegmentIntersection( a, slope,
  916. segment.A.x, segment.A.y,
  917. segment.B.x, segment.B.y,
  918. &x, &y, &x2, &y2 );
  919. if( ok )
  920. {
  921. VECTOR2I point( KiROUND( x ), KiROUND( y ) );
  922. pointbuffer.push_back( point );
  923. }
  924. if( ok == 2 )
  925. {
  926. VECTOR2I point( KiROUND( x2 ), KiROUND( y2 ) );
  927. pointbuffer.push_back( point );
  928. }
  929. if( pointbuffer.size() >= MAXPTS ) // overflow
  930. {
  931. wxASSERT( 0 );
  932. break;
  933. }
  934. }
  935. // ensure we have found an even intersection points count
  936. // because intersections are the ends of segments
  937. // inside the polygon(s) and a segment has 2 ends.
  938. // if not, this is a strange case (a bug ?) so skip this hatch
  939. if( pointbuffer.size() % 2 != 0 )
  940. continue;
  941. // sort points in order of descending x (if more than 2) to
  942. // ensure the starting point and the ending point of the same segment
  943. // are stored one just after the other.
  944. if( pointbuffer.size() > 2 )
  945. sort( pointbuffer.begin(), pointbuffer.end(), sortEndsByDescendingX );
  946. // creates lines or short segments inside the complex polygon
  947. for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
  948. {
  949. int dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
  950. // Push only one line for diagonal hatch,
  951. // or for small lines < twice the line length
  952. // else push 2 small lines
  953. if( m_hatchStyle == DIAGONAL_FULL || std::abs( dx ) < 2 * hatch_line_len )
  954. {
  955. m_HatchLines.push_back( SEG( pointbuffer[ip], pointbuffer[ip + 1] ) );
  956. }
  957. else
  958. {
  959. double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
  960. slope = dy / dx;
  961. if( dx > 0 )
  962. dx = hatch_line_len;
  963. else
  964. dx = -hatch_line_len;
  965. int x1 = KiROUND( pointbuffer[ip].x + dx );
  966. int x2 = KiROUND( pointbuffer[ip + 1].x - dx );
  967. int y1 = KiROUND( pointbuffer[ip].y + dx * slope );
  968. int y2 = KiROUND( pointbuffer[ip + 1].y - dx * slope );
  969. m_HatchLines.push_back(SEG(pointbuffer[ip].x, pointbuffer[ip].y, x1, y1));
  970. m_HatchLines.push_back( SEG( pointbuffer[ip+1].x, pointbuffer[ip+1].y, x2, y2 ) );
  971. }
  972. }
  973. }
  974. }
  975. int ZONE_CONTAINER::GetDefaultHatchPitch()
  976. {
  977. return Mils2iu( 20 );
  978. }
  979. BITMAP_DEF ZONE_CONTAINER::GetMenuImage() const
  980. {
  981. return add_zone_xpm;
  982. }
  983. void ZONE_CONTAINER::SwapData( BOARD_ITEM* aImage )
  984. {
  985. assert( aImage->Type() == PCB_ZONE_AREA_T );
  986. std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) );
  987. }
  988. void ZONE_CONTAINER::CacheTriangulation()
  989. {
  990. m_FilledPolysList.CacheTriangulation();
  991. }
  992. bool ZONE_CONTAINER::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly ) const
  993. {
  994. if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations do not like it ...
  995. return false;
  996. // Make a smoothed polygon out of the user-drawn polygon if required
  997. switch( m_cornerSmoothingType )
  998. {
  999. case ZONE_SETTINGS::SMOOTHING_CHAMFER:
  1000. aSmoothedPoly = m_Poly->Chamfer( m_cornerRadius );
  1001. break;
  1002. case ZONE_SETTINGS::SMOOTHING_FILLET:
  1003. // Note: we're now using m_ArcToSegmentsCount only as a hint to determine accuracy
  1004. // vs. speed.
  1005. if( m_ArcToSegmentsCount > SEGMENT_COUNT_CROSSOVER )
  1006. aSmoothedPoly = m_Poly->Fillet( m_cornerRadius, ARC_HIGH_DEF );
  1007. else
  1008. aSmoothedPoly = m_Poly->Fillet( m_cornerRadius, ARC_LOW_DEF );
  1009. break;
  1010. default:
  1011. // Acute angles between adjacent edges can create issues in calculations,
  1012. // in inflate/deflate outlines transforms, especially when the angle is very small.
  1013. // We can avoid issues by creating a very small chamfer which remove acute angles,
  1014. // or left it without chamfer and use only CPOLYGONS_LIST::InflateOutline to create
  1015. // clearance areas
  1016. aSmoothedPoly = m_Poly->Chamfer( Millimeter2iu( 0.0 ) );
  1017. break;
  1018. }
  1019. return true;
  1020. };
  1021. /* Function TransformOutlinesShapeWithClearanceToPolygon
  1022. * Convert the zone filled areas polygons to polygons
  1023. * inflated (optional) by max( aClearanceValue, the zone clearance)
  1024. * and copy them in aCornerBuffer
  1025. * param aClearanceValue = the clearance around polygons
  1026. * param aAddClearance = true to add a clearance area to the polygon
  1027. * false to create the outline polygon.
  1028. */
  1029. void ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(
  1030. SHAPE_POLY_SET& aCornerBuffer, int aMinClearanceValue, bool aUseNetClearance ) const
  1031. {
  1032. // Creates the zone outline polygon (with holes if any)
  1033. SHAPE_POLY_SET polybuffer;
  1034. BuildSmoothedPoly( polybuffer );
  1035. // add clearance to outline
  1036. int clearance = aMinClearanceValue;
  1037. if( aUseNetClearance && IsOnCopperLayer() )
  1038. {
  1039. clearance = GetClearance();
  1040. if( aMinClearanceValue > clearance )
  1041. clearance = aMinClearanceValue;
  1042. }
  1043. // Calculate the polygon with clearance
  1044. // holes are linked to the main outline, so only one polygon is created.
  1045. if( clearance )
  1046. polybuffer.Inflate( clearance, 16 );
  1047. polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
  1048. aCornerBuffer.Append( polybuffer );
  1049. }