KiCad PCB EDA Suite
class_zone.cpp
Go to the documentation of this file.
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-2019 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 
31 #include <fctsys.h>
32 #include <trigo.h>
33 #include <pcb_screen.h>
34 #include <class_drawpanel.h>
35 #include <kicad_string.h>
36 #include <richio.h>
37 #include <macros.h>
38 #include <pcb_base_frame.h>
39 #include <msgpanel.h>
40 #include <bitmaps.h>
41 
42 #include <convert_to_biu.h>
43 #include <class_board.h>
44 #include <class_zone.h>
45 
46 #include <pcbnew.h>
47 #include <zones.h>
48 #include <math_for_graphics.h>
50 
51 
54 {
55  m_CornerSelection = nullptr; // no corner is selected
56  m_IsFilled = false; // fill status : true when the zone is filled
60  m_hv45 = false;
64  m_HatchFillTypeSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
65  m_HatchFillTypeSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
66  // used only if m_HatchFillTypeSmoothingLevel > 0
67  m_priority = 0;
69  SetIsKeepout( false );
70  SetDoNotAllowCopperPour( false ); // has meaning only if m_isKeepout == true
71  SetDoNotAllowVias( true ); // has meaning only if m_isKeepout == true
72  SetDoNotAllowTracks( true ); // has meaning only if m_isKeepout == true
73  m_cornerRadius = 0;
74  SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
75  m_Poly = new SHAPE_POLY_SET(); // Outlines
76  aBoard->GetZoneSettings().ExportSetting( *this );
77 
78  m_needRefill = false; // True only after some edition.
79 }
80 
81 
83  BOARD_CONNECTED_ITEM( aZone )
84 {
85  // Should the copy be on the same net?
86  SetNetCode( aZone.GetNetCode() );
87  m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
88 
89  // For corner moving, corner index to drag, or nullptr if no selection
90  m_CornerSelection = nullptr;
91  m_IsFilled = aZone.m_IsFilled;
92  m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
94  m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons)
95  m_hv45 = aZone.m_hv45;
96  m_priority = aZone.m_priority;
102  m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
103 
104  m_isKeepout = aZone.m_isKeepout;
108 
111 
112  m_hatchStyle = aZone.m_hatchStyle;
113  m_hatchPitch = aZone.m_hatchPitch;
114  m_HatchLines = aZone.m_HatchLines;
115 
116  SetLayerSet( aZone.GetLayerSet() );
117  SetLocalFlags( aZone.GetLocalFlags() );
118 
119  SetNeedRefill( aZone.NeedRefill() );
120 }
121 
122 
124 {
126 
127  // Replace the outlines for aOther outlines.
128  delete m_Poly;
129  m_Poly = new SHAPE_POLY_SET( *aOther.m_Poly );
130 
131  m_CornerSelection = nullptr; // for corner moving, corner index to (null if no selection)
132  m_ZoneClearance = aOther.m_ZoneClearance; // clearance value
134  m_FillMode = aOther.m_FillMode; // filling mode (segments/polygons)
139  SetHatchStyle( aOther.GetHatchStyle() );
140  SetHatchPitch( aOther.GetHatchPitch() );
141  m_HatchLines = aOther.m_HatchLines; // copy vector <SEG>
144  m_FillSegmList.clear();
146 
147  SetLayerSet( aOther.GetLayerSet() );
148 
149  return *this;
150 }
151 
152 
154 {
155  delete m_Poly;
156  delete m_CornerSelection;
157 }
158 
159 
161 {
162  return new ZONE_CONTAINER( *this );
163 }
164 
165 
167 {
168  bool change = ( !m_FilledPolysList.IsEmpty() ) ||
169  ( m_FillSegmList.size() > 0 );
170 
172  m_FillSegmList.clear();
173  m_IsFilled = false;
174 
175  return change;
176 }
177 
178 
179 const wxPoint ZONE_CONTAINER::GetPosition() const
180 {
181  return (wxPoint) GetCornerPosition( 0 );
182 }
183 
184 
186 {
187  return BOARD_ITEM::GetLayer();
188 }
189 
190 
192 {
193  if( GetIsKeepout() )
194  {
195  return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
196  }
197  else
198  {
199  return IsCopperLayer( GetLayer() );
200  }
201 }
202 
203 
204 bool ZONE_CONTAINER::CommonLayerExists( const LSET aLayerSet ) const
205 {
206  LSET common = GetLayerSet() & aLayerSet;
207 
208  return common.count() > 0;
209 }
210 
211 
213 {
214  SetLayerSet( LSET( aLayer ) );
215 
216  m_Layer = aLayer;
217 }
218 
219 
221 {
222  if( GetIsKeepout() )
223  {
224  // Keepouts can only exist on copper layers
225  aLayerSet &= LSET::AllCuMask();
226  }
227 
228  if( aLayerSet.count() == 0 )
229  {
230  return;
231  }
232 
233  if( m_layerSet != aLayerSet )
234  SetNeedRefill( true );
235 
236  m_layerSet = aLayerSet;
237 
238  // Set the single layer to the first selected layer
239  m_Layer = aLayerSet.Seq()[0];
240 }
241 
242 
244 {
245  // TODO - Enable multi-layer zones for all zone types
246  // not just keepout zones
247  if( GetIsKeepout() )
248  {
249  return m_layerSet;
250  }
251  else
252  {
253  return LSET( m_Layer );
254  }
255 }
256 
257 void ZONE_CONTAINER::ViewGetLayers( int aLayers[], int& aCount ) const
258 {
259  if( GetIsKeepout() )
260  {
261  LSEQ layers = m_layerSet.Seq();
262 
263  for( unsigned int idx = 0; idx < layers.size(); idx++ )
264  {
265  aLayers[idx] = layers[idx];
266  }
267 
268  aCount = layers.size();
269  }
270  else
271  {
272  aLayers[0] = m_Layer;
273  aCount = 1;
274  }
275 }
276 
277 
279 {
280  if( GetIsKeepout() )
281  {
282  return m_layerSet.test( aLayer );
283  }
284 
285  return BOARD_ITEM::IsOnLayer( aLayer );
286 }
287 
288 
289 void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
290  const wxPoint& offset )
291 {
292  if( !DC )
293  return;
294 
295  wxPoint seg_start, seg_end;
296  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
297  BOARD* brd = GetBoard();
298 
299  auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
300 
301  PCB_LAYER_ID draw_layer = UNDEFINED_LAYER;
302 
303  LSET layers = GetLayerSet() & brd->GetVisibleLayers();
304 
305  // If there are no visible layers and the zone is not highlighted, return
306  if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
307  {
308  return;
309  }
310 
311  /* Keepout zones can exist on multiple layers
312  * Thus, determining which color to use to render them is a bit tricky.
313  * In descending order of priority:
314  *
315  * 1. If in GR_HIGHLIGHT mode:
316  * a. If zone is on selected layer, use layer color!
317  * b. Else, use grey
318  * 1. Not in GR_HIGHLIGHT mode
319  * a. If zone is on selected layer, use layer color
320  * b. Else, use color of top-most (visible) layer
321  *
322  */
323  if( GetIsKeepout() )
324  {
325  // At least one layer must be provided!
326  assert( GetLayerSet().count() > 0 );
327 
328  // Not on any visible layer?
329  if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
330  {
331  return;
332  }
333 
334  // Is keepout zone present on the selected layer?
335  if( layers.test( curr_layer ) )
336  {
337  draw_layer = curr_layer;
338  }
339  else
340  {
341  // Select the first (top) visible layer
342  if( layers.count() > 0 )
343  {
344  draw_layer = layers.Seq()[0];
345  }
346  else
347  {
348  draw_layer = GetLayerSet().Seq()[0];
349  }
350  }
351 
352  }
353  /* Non-keepout zones are easier to deal with
354  */
355  else
356  {
357  if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
358  {
359  return;
360  }
361 
362  draw_layer = GetLayer();
363  }
364 
365  assert( draw_layer != UNDEFINED_LAYER );
366 
367  auto color = frame->Settings().Colors().GetLayerColor( draw_layer );
368 
369  GRSetDrawMode( DC, aDrawMode );
370  auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
371 
372  if( displ_opts->m_ContrastModeDisplay )
373  {
374  if( !IsOnLayer( curr_layer ) )
375  {
377  }
378  }
379 
380  if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
381  {
382  color.SetToLegacyHighlightColor();
383  }
384 
385  color.a = 0.588;
386 
387  // draw the lines
388  std::vector<wxPoint> lines;
389  lines.reserve( (GetNumCorners() * 2) + 2 );
390 
391  // Iterate through the segments of the outline
392  for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
393  {
394  // Create the segment
395  SEG segment = *iterator;
396 
397  lines.push_back( static_cast<wxPoint>( segment.A ) + offset );
398  lines.push_back( static_cast<wxPoint>( segment.B ) + offset );
399  }
400 
401  GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
402 
403  // draw hatches
404  lines.clear();
405  lines.reserve( (m_HatchLines.size() * 2) + 2 );
406 
407  for( unsigned ic = 0; ic < m_HatchLines.size(); ic++ )
408  {
409  seg_start = static_cast<wxPoint>( m_HatchLines[ic].A ) + offset;
410  seg_end = static_cast<wxPoint>( m_HatchLines[ic].B ) + offset;
411  lines.push_back( seg_start );
412  lines.push_back( seg_end );
413  }
414 
415  GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
416 }
417 
418 
420  wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
421 {
422 
423  static std::vector <wxPoint> CornersBuffer;
424  auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
425 
426  // outline_mode is false to show filled polys,
427  // and true to show polygons outlines only (test and debug purposes)
428  bool outline_mode = displ_opts->m_DisplayZonesMode == 2 ? true : false;
429 
430  if( DC == NULL )
431  return;
432 
433  if( displ_opts->m_DisplayZonesMode == 1 ) // Do not show filled areas
434  return;
435 
436  if( m_FilledPolysList.IsEmpty() ) // Nothing to draw
437  return;
438 
439  BOARD* brd = GetBoard();
440  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
441 
442  auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
443  auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
444 
445  if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
446  return;
447 
448  GRSetDrawMode( DC, aDrawMode );
449 
450  if( displ_opts->m_ContrastModeDisplay )
451  {
452  if( !IsOnLayer( curr_layer ) )
454  }
455 
456  if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
457  color.SetToLegacyHighlightColor();
458 
459  color.a = 0.588;
460 
461 
462  for( int ic = 0; ic < m_FilledPolysList.OutlineCount(); ic++ )
463  {
464  const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( ic );
465 
466  CornersBuffer.clear();
467 
468  wxPoint p0;
469 
470  for( int j = 0; j < path.PointCount(); j++ )
471  {
472  const VECTOR2I& corner = path.CPoint( j );
473 
474  wxPoint coord( corner.x + offset.x, corner.y + offset.y );
475 
476  if( j == 0 )
477  p0 = coord;
478 
479  CornersBuffer.push_back( coord );
480  }
481 
482  CornersBuffer.push_back( p0 );
483 
484  // Draw outlines:
485  if( ( m_ZoneMinThickness > 1 ) || outline_mode )
486  {
487  int ilim = CornersBuffer.size() - 1;
488  int line_thickness = m_ZoneMinThickness;
489 
490  for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
491  {
492  // Draw only basic outlines, not extra segments.
493  if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
494  {
495  GRCSegm( panel->GetClipBox(), DC, CornersBuffer[is], CornersBuffer[ie],
496  line_thickness, color );
497  }
498  else
499  {
500  GRFilledSegment( panel->GetClipBox(), DC, CornersBuffer[is], CornersBuffer[ie],
501  line_thickness, color );
502  }
503  }
504  }
505 
506  // Draw fill:
507  if( !outline_mode )
508  {
509  GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0], true, 0,
510  color, color );
511  }
512  }
513 }
514 
515 
517 {
518  const int PRELOAD = 0x7FFFFFFF; // Biggest integer (32 bits)
519 
520  int ymax = -PRELOAD;
521  int ymin = PRELOAD;
522  int xmin = PRELOAD;
523  int xmax = -PRELOAD;
524 
525  int count = GetNumCorners();
526 
527  for( int i = 0; i<count; ++i )
528  {
529  wxPoint corner = static_cast<wxPoint>( GetCornerPosition( i ) );
530 
531  ymax = std::max( ymax, corner.y );
532  xmax = std::max( xmax, corner.x );
533  ymin = std::min( ymin, corner.y );
534  xmin = std::min( xmin, corner.x );
535  }
536 
537  EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
538 
539  return ret;
540 }
541 
542 
544  GR_DRAWMODE draw_mode )
545 {
546  GR_DRAWMODE current_gr_mode = draw_mode;
547  bool is_close_segment = false;
548 
549  if( !DC )
550  return;
551 
552  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
553 
554  auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
555  auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
556 
557  auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
558 
559  if( displ_opts->m_ContrastModeDisplay )
560  {
561  if( !IsOnLayer( curr_layer ) )
563  }
564 
565  // Object to iterate through the corners of the outlines
567 
568  // Segment start and end
569  VECTOR2I seg_start, seg_end;
570 
571  // Remember the first point of this contour
572  VECTOR2I contour_first_point = *iterator;
573 
574  // Iterate through all the corners of the outlines and build the segments to draw
575  while( iterator )
576  {
577  // Get the first point of the current segment
578  seg_start = *iterator;
579 
580  // Get the last point of the current segment, handling the case where the end of the
581  // contour is reached, when the last point of the segment is the first point of the
582  // contour
583  if( !iterator.IsEndContour() )
584  {
585  // Set GR mode to default
586  current_gr_mode = draw_mode;
587 
588  SHAPE_POLY_SET::ITERATOR iterator_copy = iterator;
589  iterator_copy++;
590  if( iterator_copy.IsEndContour() )
591  current_gr_mode = GR_XOR;
592 
593  is_close_segment = false;
594 
595  iterator++;
596  seg_end = *iterator;
597  }
598  else
599  {
600  is_close_segment = true;
601 
602  seg_end = contour_first_point;
603 
604  // Reassign first point of the contour to the next contour start
605  iterator++;
606 
607  if( iterator )
608  contour_first_point = *iterator;
609 
610  // Set GR mode to XOR
611  current_gr_mode = GR_XOR;
612  }
613 
614  GRSetDrawMode( DC, current_gr_mode );
615 
616  if( is_close_segment )
617  GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
618  WHITE );
619  else
620  GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
621  color );
622  }
623 }
624 
625 
627 {
628  if( aPad == NULL || aPad->GetThermalGap() == 0 )
629  return m_ThermalReliefGap;
630  else
631  return aPad->GetThermalGap();
632 }
633 
634 
636 {
637  if( aPad == NULL || aPad->GetThermalWidth() == 0 )
639  else
640  return aPad->GetThermalWidth();
641 }
642 
643 
644 void ZONE_CONTAINER::SetCornerRadius( unsigned int aRadius )
645 {
646  if( m_cornerRadius != aRadius )
647  SetNeedRefill( true );
648 
649  m_cornerRadius = aRadius;
650 }
651 
652 
653 bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
654 {
655  // Normally accuracy is zoom-relative, but for the generic HitTest we just use
656  // a fixed (small) value.
657  int accuracy = std::max( aAccuracy, Millimeter2iu( 0.1 ) );
658 
659  return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
660 }
661 
662 
663 void ZONE_CONTAINER::SetSelectedCorner( const wxPoint& aPosition, int aAccuracy )
664 {
666 
667  // If there is some corner to be selected, assign it to m_CornerSelection
668  if( HitTestForCorner( aPosition, aAccuracy * 2, corner )
669  || HitTestForEdge( aPosition, aAccuracy, corner ) )
670  {
671  if( m_CornerSelection == nullptr )
673 
674  *m_CornerSelection = corner;
675  }
676 }
677 
678 bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy,
679  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
680 {
681  return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, aAccuracy );
682 }
683 
684 
685 bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const
686 {
688  return HitTestForCorner( refPos, aAccuracy, dummy );
689 }
690 
691 
692 bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy,
693  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
694 {
695  return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, aAccuracy );
696 }
697 
698 
699 bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const
700 {
702  return HitTestForEdge( refPos, aAccuracy, dummy );
703 }
704 
705 
706 bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
707 {
708  // Calculate bounding box for zone
709  EDA_RECT bbox = GetBoundingBox();
710  bbox.Normalize();
711 
712  EDA_RECT arect = aRect;
713  arect.Normalize();
714  arect.Inflate( aAccuracy );
715 
716  if( aContained )
717  {
718  return arect.Contains( bbox );
719  }
720  else // Test for intersection between aBox and the polygon
721  // For a polygon, using its bounding box has no sense here
722  {
723  // Fast test: if aBox is outside the polygon bounding box,
724  // rectangles cannot intersect
725  if( !arect.Intersects( bbox ) )
726  return false;
727 
728  // aBox is inside the polygon bounding box,
729  // and can intersect the polygon: use a fine test.
730  // aBox intersects the polygon if at least one aBox corner
731  // is inside the polygon
732 
733  /*
734  wxPoint origin = arect.GetOrigin();
735 
736  int w = arect.GetWidth();
737  int h = arect.GetHeight();
738 
739 
740  if ( HitTestInsideZone( origin ) ||
741  HitTestInsideZone( origin + wxPoint( w, 0 ) ) ||
742  HitTestInsideZone( origin + wxPoint( w, h ) ) ||
743  HitTestInsideZone( origin + wxPoint( 0, h ) ) )
744  {
745  return true;
746  }
747  */
748 
749  // No corner inside aBox, but outlines can intersect aBox
750  // if one of outline corners is inside aBox
751  int count = m_Poly->TotalVertices();
752  for( int ii =0; ii < count; ii++ )
753  {
754  auto vertex = m_Poly->Vertex( ii );
755  auto vertexNext = m_Poly->Vertex( ( ii + 1 ) % count );
756 
757  // Test if the point is within the rect
758  if( arect.Contains( ( wxPoint ) vertex ) )
759  {
760  return true;
761  }
762 
763  // Test if this edge intersects the rect
764  if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
765  {
766  return true;
767  }
768  }
769 
770  return false;
771  }
772 }
773 
774 
776 {
777  int myClearance = m_ZoneClearance;
778 
779 #if 1 // Maybe the netclass clearance should not come into play for a zone?
780  // At least the policy decision can be controlled by the zone
781  // itself, i.e. here. On reasons of insufficient documentation,
782  // the user will be less bewildered if we simply respect the
783  // "zone clearance" setting in the zone properties dialog. (At least
784  // until there is a UI boolean for this.)
785 
786  NETCLASSPTR myClass = GetNetClass();
787 
788  if( myClass )
789  myClearance = std::max( myClearance, myClass->GetClearance() );
790 #endif
791 
792  if( aItem )
793  {
794  int hisClearance = aItem->GetClearance( NULL );
795  myClearance = std::max( hisClearance, myClearance );
796  }
797 
798  return myClearance;
799 }
800 
801 
802 bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
803 {
804  return m_FilledPolysList.Contains( VECTOR2I( aRefPos.x, aRefPos.y ) );
805 }
806 
807 
808 void ZONE_CONTAINER::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
809 {
810  wxString msg;
811 
812  msg = _( "Zone Outline" );
813 
814  // Display Cutout instead of Outline for holes inside a zone
815  // i.e. when num contour !=0
816  // Check whether the selected corner is in a hole; i.e., in any contour but the first one.
817  if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
818  msg << wxT( " " ) << _( "(Cutout)" );
819 
820  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, DARKCYAN ) );
821 
822  if( GetIsKeepout() )
823  {
824  msg.Empty();
825 
826  if( GetDoNotAllowVias() )
827  AccumulateDescription( msg, _( "No via" ) );
828 
829  if( GetDoNotAllowTracks() )
830  AccumulateDescription( msg, _("No track") );
831 
833  AccumulateDescription( msg, _("No copper pour") );
834 
835  aList.push_back( MSG_PANEL_ITEM( _( "Keepout" ), msg, RED ) );
836  }
837  else if( IsOnCopperLayer() )
838  {
839  if( GetNetCode() >= 0 )
840  {
841  NETINFO_ITEM* net = GetNet();
842 
843  if( net )
844  msg = UnescapeString( net->GetNetname() );
845  else // Should not occur
846  msg = _( "<unknown>" );
847  }
848  else // a netcode < 0 is an error
849  msg = wxT( "<error>" );
850 
851  aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
852 
853  // Display net code : (useful in test or debug)
854  msg.Printf( wxT( "%d" ), GetNetCode() );
855  aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
856 
857  // Display priority level
858  msg.Printf( wxT( "%d" ), GetPriority() );
859  aList.push_back( MSG_PANEL_ITEM( _( "Priority" ), msg, BLUE ) );
860  }
861  else
862  {
863  aList.push_back( MSG_PANEL_ITEM( _( "Non Copper Zone" ), wxEmptyString, RED ) );
864  }
865 
866  aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BROWN ) );
867 
868  msg.Printf( wxT( "%d" ), (int) m_Poly->TotalVertices() );
869  aList.push_back( MSG_PANEL_ITEM( _( "Vertices" ), msg, BLUE ) );
870 
871  switch( m_FillMode )
872  {
873  case ZFM_POLYGONS:
874  msg = _( "Solid" ); break;
875  case ZFM_HATCH_PATTERN:
876  msg = _( "Hatched" ); break;
877  default:
878  msg = _( "Unknown" ); break;
879  }
880 
881  aList.push_back( MSG_PANEL_ITEM( _( "Fill Mode" ), msg, BROWN ) );
882 
883  // Useful for statistics :
884  msg.Printf( wxT( "%d" ), (int) m_HatchLines.size() );
885  aList.push_back( MSG_PANEL_ITEM( _( "Hatch Lines" ), msg, BLUE ) );
886 
887  if( !m_FilledPolysList.IsEmpty() )
888  {
889  msg.Printf( wxT( "%d" ), m_FilledPolysList.TotalVertices() );
890  aList.push_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) );
891  }
892 }
893 
894 
895 /* Geometric transforms: */
896 
897 void ZONE_CONTAINER::Move( const wxPoint& offset )
898 {
899  /* move outlines */
900  m_Poly->Move( VECTOR2I( offset ) );
901 
902  Hatch();
903 
904  m_FilledPolysList.Move( VECTOR2I( offset.x, offset.y ) );
905 
906  for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
907  {
908  m_FillSegmList[ic].A += VECTOR2I(offset);
909  m_FillSegmList[ic].B += VECTOR2I(offset);
910  }
911 }
912 
913 
914 void ZONE_CONTAINER::MoveEdge( const wxPoint& offset, int aEdge )
915 {
916  int next_corner;
917 
918  if( m_Poly->GetNeighbourIndexes( aEdge, nullptr, &next_corner ) )
919  {
920  m_Poly->Vertex( aEdge ) += VECTOR2I( offset );
921  m_Poly->Vertex( next_corner ) += VECTOR2I( offset );
922  Hatch();
923 
924  SetNeedRefill( true );
925  }
926 }
927 
928 
929 void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle )
930 {
931  wxPoint pos;
932 
933  for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
934  {
935  pos = static_cast<wxPoint>( *iterator );
936  RotatePoint( &pos, centre, angle );
937  iterator->x = pos.x;
938  iterator->y = pos.y;
939  }
940 
941  Hatch();
942 
943  /* rotate filled areas: */
944  for( auto ic = m_FilledPolysList.Iterate(); ic; ++ic )
945  RotatePoint( &ic->x, &ic->y, centre.x, centre.y, angle );
946 
947  for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
948  {
949  wxPoint a( m_FillSegmList[ic].A );
950  RotatePoint( &a, centre, angle );
951  m_FillSegmList[ic].A = a;
952  wxPoint b( m_FillSegmList[ic].B );
953  RotatePoint( &b, centre, angle );
954  m_FillSegmList[ic].B = a;
955  }
956 }
957 
958 
959 void ZONE_CONTAINER::Flip( const wxPoint& aCentre )
960 {
961  Mirror( aCentre );
962  int copperLayerCount = GetBoard()->GetCopperLayerCount();
963 
964  if( GetIsKeepout() )
965  {
966  SetLayerSet( FlipLayerMask( GetLayerSet(), copperLayerCount ) );
967  }
968  else
969  {
970  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
971  }
972 }
973 
974 
975 void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
976 {
977  for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
978  {
979  int py = mirror_ref.y - iterator->y;
980  iterator->y = py + mirror_ref.y;
981  }
982 
983  Hatch();
984 
985  for( auto ic = m_FilledPolysList.Iterate(); ic; ++ic )
986  {
987  int py = mirror_ref.y - ic->y;
988  ic->y = py + mirror_ref.y;
989  }
990 
991  for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
992  {
993  MIRROR( m_FillSegmList[ic].A.y, mirror_ref.y );
994  MIRROR( m_FillSegmList[ic].B.y, mirror_ref.y );
995  }
996 }
997 
998 
1000 {
1001  if( aPad == NULL || aPad->GetZoneConnection() == PAD_ZONE_CONN_INHERITED )
1002  return m_PadConnection;
1003  else
1004  return aPad->GetZoneConnection();
1005 }
1006 
1007 
1008 void ZONE_CONTAINER::AddPolygon( std::vector< wxPoint >& aPolygon )
1009 {
1010  if( aPolygon.empty() )
1011  return;
1012 
1013  SHAPE_LINE_CHAIN outline;
1014 
1015  // Create an outline and populate it with the points of aPolygon
1016  for( unsigned i = 0; i < aPolygon.size(); i++ )
1017  {
1018  outline.Append( VECTOR2I( aPolygon[i] ) );
1019  }
1020 
1021  outline.SetClosed( true );
1022 
1023  // Add the outline as a new polygon in the polygon set
1024  if( m_Poly->OutlineCount() == 0 )
1025  m_Poly->AddOutline( outline );
1026  else
1027  m_Poly->AddHole( outline );
1028 
1029  SetNeedRefill( true );
1030 }
1031 
1032 
1033 bool ZONE_CONTAINER::AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication )
1034 {
1035  // Ensure the main outline exists:
1036  if( m_Poly->OutlineCount() == 0 )
1037  m_Poly->NewOutline();
1038 
1039  // If aHoleIdx >= 0, the corner musty be added to the hole, index aHoleIdx.
1040  // (remember: the index of the first hole is 0)
1041  // Return error if if does dot exist.
1042  if( aHoleIdx >= m_Poly->HoleCount( 0 ) )
1043  return false;
1044 
1045  m_Poly->Append( aPosition.x, aPosition.y, -1, aHoleIdx, aAllowDuplication );
1046 
1047  SetNeedRefill( true );
1048 
1049  return true;
1050 }
1051 
1052 
1054 {
1055  wxString text;
1056 
1057  // Check whether the selected contour is a hole (contour index > 0)
1058  if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
1059  text << wxT( " " ) << _( "(Cutout)" );
1060 
1061  if( GetIsKeepout() )
1062  text << wxT( " " ) << _( "(Keepout)" );
1063  else
1064  text << GetNetnameMsg();
1065 
1066  return wxString::Format( _( "Zone Outline %s on %s" ), text, GetLayerName() );
1067 }
1068 
1069 
1071 {
1072  return m_hatchPitch;
1073 }
1074 
1075 
1076 void ZONE_CONTAINER::SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch )
1077 {
1078  SetHatchPitch( aHatchPitch );
1079  m_hatchStyle = (ZONE_CONTAINER::HATCH_STYLE) aHatchStyle;
1080 
1081  if( aRebuildHatch )
1082  Hatch();
1083 }
1084 
1085 
1087 {
1088  m_hatchPitch = aPitch;
1089 }
1090 
1091 
1093 {
1094  m_HatchLines.clear();
1095 }
1096 
1097 
1098 // Creates hatch lines inside the outline of the complex polygon
1099 // sort function used in ::Hatch to sort points by descending wxPoint.x values
1100 bool sortEndsByDescendingX( const VECTOR2I& ref, const VECTOR2I& tst )
1101 {
1102  return tst.x < ref.x;
1103 }
1104 
1105 
1107 {
1108  UnHatch();
1109 
1110  if( m_hatchStyle == NO_HATCH || m_hatchPitch == 0 || m_Poly->IsEmpty() )
1111  return;
1112 
1113  // define range for hatch lines
1114  int min_x = m_Poly->Vertex( 0 ).x;
1115  int max_x = m_Poly->Vertex( 0 ).x;
1116  int min_y = m_Poly->Vertex( 0 ).y;
1117  int max_y = m_Poly->Vertex( 0 ).y;
1118 
1119  for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
1120  {
1121  if( iterator->x < min_x )
1122  min_x = iterator->x;
1123 
1124  if( iterator->x > max_x )
1125  max_x = iterator->x;
1126 
1127  if( iterator->y < min_y )
1128  min_y = iterator->y;
1129 
1130  if( iterator->y > max_y )
1131  max_y = iterator->y;
1132  }
1133 
1134  // Calculate spacing between 2 hatch lines
1135  int spacing;
1136 
1137  if( m_hatchStyle == DIAGONAL_EDGE )
1138  spacing = m_hatchPitch;
1139  else
1140  spacing = m_hatchPitch * 2;
1141 
1142  // set the "length" of hatch lines (the length on horizontal axis)
1143  int hatch_line_len = m_hatchPitch;
1144 
1145  // To have a better look, give a slope depending on the layer
1146  LAYER_NUM layer = GetLayer();
1147  int slope_flag = (layer & 1) ? 1 : -1; // 1 or -1
1148  double slope = 0.707106 * slope_flag; // 45 degrees slope
1149  int max_a, min_a;
1150 
1151  if( slope_flag == 1 )
1152  {
1153  max_a = KiROUND( max_y - slope * min_x );
1154  min_a = KiROUND( min_y - slope * max_x );
1155  }
1156  else
1157  {
1158  max_a = KiROUND( max_y - slope * max_x );
1159  min_a = KiROUND( min_y - slope * min_x );
1160  }
1161 
1162  min_a = (min_a / spacing) * spacing;
1163 
1164  // calculate an offset depending on layer number,
1165  // for a better look of hatches on a multilayer board
1166  int offset = (layer * 7) / 8;
1167  min_a += offset;
1168 
1169  // loop through hatch lines
1170  #define MAXPTS 200 // Usually we store only few values per one hatch line
1171  // depending on the complexity of the zone outline
1172 
1173  static std::vector<VECTOR2I> pointbuffer;
1174  pointbuffer.clear();
1175  pointbuffer.reserve( MAXPTS + 2 );
1176 
1177  for( int a = min_a; a < max_a; a += spacing )
1178  {
1179  // get intersection points for this hatch line
1180 
1181  // Note: because we should have an even number of intersections with the
1182  // current hatch line and the zone outline (a closed polygon,
1183  // or a set of closed polygons), if an odd count is found
1184  // we skip this line (should not occur)
1185  pointbuffer.clear();
1186 
1187  // Iterate through all vertices
1188  for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
1189  {
1190  double x, y, x2, y2;
1191  int ok;
1192 
1193  SEG segment = *iterator;
1194 
1195  ok = FindLineSegmentIntersection( a, slope,
1196  segment.A.x, segment.A.y,
1197  segment.B.x, segment.B.y,
1198  &x, &y, &x2, &y2 );
1199 
1200  if( ok )
1201  {
1202  VECTOR2I point( KiROUND( x ), KiROUND( y ) );
1203  pointbuffer.push_back( point );
1204  }
1205 
1206  if( ok == 2 )
1207  {
1208  VECTOR2I point( KiROUND( x2 ), KiROUND( y2 ) );
1209  pointbuffer.push_back( point );
1210  }
1211 
1212  if( pointbuffer.size() >= MAXPTS ) // overflow
1213  {
1214  wxASSERT( 0 );
1215  break;
1216  }
1217  }
1218 
1219  // ensure we have found an even intersection points count
1220  // because intersections are the ends of segments
1221  // inside the polygon(s) and a segment has 2 ends.
1222  // if not, this is a strange case (a bug ?) so skip this hatch
1223  if( pointbuffer.size() % 2 != 0 )
1224  continue;
1225 
1226  // sort points in order of descending x (if more than 2) to
1227  // ensure the starting point and the ending point of the same segment
1228  // are stored one just after the other.
1229  if( pointbuffer.size() > 2 )
1230  sort( pointbuffer.begin(), pointbuffer.end(), sortEndsByDescendingX );
1231 
1232  // creates lines or short segments inside the complex polygon
1233  for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
1234  {
1235  int dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
1236 
1237  // Push only one line for diagonal hatch,
1238  // or for small lines < twice the line length
1239  // else push 2 small lines
1240  if( m_hatchStyle == DIAGONAL_FULL || std::abs( dx ) < 2 * hatch_line_len )
1241  {
1242  m_HatchLines.push_back( SEG( pointbuffer[ip], pointbuffer[ip + 1] ) );
1243  }
1244  else
1245  {
1246  double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
1247  slope = dy / dx;
1248 
1249  if( dx > 0 )
1250  dx = hatch_line_len;
1251  else
1252  dx = -hatch_line_len;
1253 
1254  int x1 = KiROUND( pointbuffer[ip].x + dx );
1255  int x2 = KiROUND( pointbuffer[ip + 1].x - dx );
1256  int y1 = KiROUND( pointbuffer[ip].y + dx * slope );
1257  int y2 = KiROUND( pointbuffer[ip + 1].y - dx * slope );
1258 
1259  m_HatchLines.push_back(SEG(pointbuffer[ip].x, pointbuffer[ip].y, x1, y1));
1260 
1261  m_HatchLines.push_back( SEG( pointbuffer[ip+1].x, pointbuffer[ip+1].y, x2, y2 ) );
1262  }
1263  }
1264  }
1265 }
1266 
1267 
1269 {
1270  return Mils2iu( 20 );
1271 }
1272 
1273 
1275 {
1276  return add_zone_xpm;
1277 }
1278 
1279 
1281 {
1282  assert( aImage->Type() == PCB_ZONE_AREA_T );
1283 
1284  std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) );
1285 }
1286 
1287 
1289 {
1291 }
1292 
1293 
1295 {
1296  if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations do not like it ...
1297  return false;
1298 
1299  // Make a smoothed polygon out of the user-drawn polygon if required
1300  switch( m_cornerSmoothingType )
1301  {
1303  aSmoothedPoly = m_Poly->Chamfer( m_cornerRadius );
1304  break;
1305 
1307  // Note: we're now using m_ArcToSegmentsCount only as a hint to determine accuracy
1308  // vs. speed.
1310  aSmoothedPoly = m_Poly->Fillet( m_cornerRadius, ARC_HIGH_DEF );
1311  else
1312  aSmoothedPoly = m_Poly->Fillet( m_cornerRadius, ARC_LOW_DEF );
1313  break;
1314 
1315  default:
1316  // Acute angles between adjacent edges can create issues in calculations,
1317  // in inflate/deflate outlines transforms, especially when the angle is very small.
1318  // We can avoid issues by creating a very small chamfer which remove acute angles,
1319  // or left it without chamfer and use only CPOLYGONS_LIST::InflateOutline to create
1320  // clearance areas
1321  aSmoothedPoly = m_Poly->Chamfer( Millimeter2iu( 0.0 ) );
1322  break;
1323  }
1324 
1325  return true;
1326 };
1327 
1328 /* Function TransformOutlinesShapeWithClearanceToPolygon
1329  * Convert the zone filled areas polygons to polygons
1330  * inflated (optional) by max( aClearanceValue, the zone clearance)
1331  * and copy them in aCornerBuffer
1332  * param aClearanceValue = the clearance around polygons
1333  * param aAddClearance = true to add a clearance area to the polygon
1334  * false to create the outline polygon.
1335  */
1337  SHAPE_POLY_SET& aCornerBuffer, int aMinClearanceValue, bool aUseNetClearance ) const
1338 {
1339  // Creates the zone outline polygon (with holes if any)
1340  SHAPE_POLY_SET polybuffer;
1341  BuildSmoothedPoly( polybuffer );
1342 
1343  // add clearance to outline
1344  int clearance = aMinClearanceValue;
1345 
1346  if( aUseNetClearance && IsOnCopperLayer() )
1347  {
1348  clearance = GetClearance();
1349  if( aMinClearanceValue > clearance )
1350  clearance = aMinClearanceValue;
1351  }
1352 
1353  // Calculate the polygon with clearance
1354  // holes are linked to the main outline, so only one polygon is created.
1355  if( clearance )
1356  polybuffer.Inflate( clearance, ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF );
1357 
1358  polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
1359  aCornerBuffer.Append( polybuffer );
1360 }
virtual BASE_SCREEN * GetScreen()=0
Definition: colors.h:57
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:659
int TotalVertices() const
Returns total number of vertices stored in the set.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:914
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, bool aIgnoreHoles=false) const
Returns true if a given subpolygon contains the point aP.
void SetHatchPitch(int aPitch)
Function SetHatchPitch sets the hatch pitch parameter for the zone.
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw Draws the zone outline.
Definition: class_zone.cpp:289
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, wxPoint Points[], bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:701
int m_ZoneClearance
Clearance value in internal units.
Definition: class_zone.h:759
void DrawWhileCreateOutline(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE draw_mode=GR_OR)
Function DrawWhileCreateOutline Draws the zone outline when it is created.
Definition: class_zone.cpp:543
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask,...
Definition: lset.cpp:521
int GetNetCode() const
Function GetNetCode.
int OutlineCount() const
Returns the number of outlines in the set
#define SEGMENT_COUNT_CROSSOVER
Definition: pcbnew.h:46
bool IsEndContour() const
Function IsEndContour.
bool CommonLayerExists(const LSET aLayerSet) const
Function CommonLayerExist Test if this zone shares a common layer with the given layer set.
Definition: class_zone.cpp:204
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:635
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:118
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_zone.cpp:160
bool CollideEdge(const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0)
Function CollideEdge Checks whether aPoint collides with any edge of any of the contours of the polyg...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
bool m_doNotAllowTracks
Definition: class_zone.h:756
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox (virtual)
Definition: class_zone.cpp:516
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
void SetCornerRadius(unsigned int aRadius)
Definition: class_zone.cpp:644
void TransformOutlinesShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aMinClearanceValue, bool aUseNetClearance) const
Function TransformOutlinesShapeWithClearanceToPolygon Convert the outlines shape to a polygon with no...
SHAPE_POLY_SET::VERTEX_INDEX * m_CornerSelection
The index of the corner being moved or nullptr if no corner is selected.
Definition: class_zone.h:806
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_zone.cpp:278
Class BOARD to handle a board.
void DrawFilledArea(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)
Function DrawDrawFilledArea Draws the filled area for this zone (polygon list .m_FilledPolysList)
Definition: class_zone.cpp:419
bool HitTestForCorner(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Function HitTestForCorner tests if the given wxPoint is near a corner.
Definition: class_zone.cpp:678
ZoneConnection
How pads are covered by copper in zone.
Definition: zones.h:50
int color
Definition: DXF_plotter.cpp:62
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:475
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:185
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
Struct VERTEX_INDEX.
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, COLOR4D Color)
Definition: gr_basic.cpp:415
bool HitTestFilledArea(const wxPoint &aRefPos) const
Function HitTestFilledArea tests if the given wxPoint is within the bounds of a filled area of this z...
Definition: class_zone.cpp:802
Classes to handle copper zones.
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
SHAPE_POLY_SET Fillet(int aRadius, int aErrorMax)
Function Fillet returns a filleted version of the polygon set.
virtual EDA_RECT * GetClipBox()
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
ZONE_SEGMENT_FILL m_FillSegmList
Segments used to fill the zone (m_FillMode ==1 ), when fill zone by segment is used.
Definition: class_zone.h:814
ITERATOR Iterate(int aFirst, int aLast, bool aIterateHoles=false)
Function Iterate returns an object to iterate through the points of the polygons between aFirst and a...
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:626
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
int GetThermalGap() const
Definition: class_pad.cpp:759
int PointCount() const
Function PointCount()
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:367
const wxPoint GetPosition() const override
Definition: class_zone.cpp:179
#define abs(a)
Definition: auxiliary.h:84
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
bool Contains(const wxPoint &aPoint) const
Function Contains.
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_zone.cpp:775
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:658
This file contains miscellaneous commonly used macros and functions.
bool GetDoNotAllowVias() const
Definition: class_zone.h:653
Classes used in Pcbnew, CvPcb and GerbView.
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
bool GetNeighbourIndexes(int aGlobalIndex, int *aPrevious, int *aNext)
Returns the global indexes of the previous and the next corner of the aGlobalIndex-th corner of a con...
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_zone.cpp:243
virtual EDA_DRAW_FRAME * GetParent() const =0
PCB_LAYER_ID m_Layer
void SetLayerSet(LSET aLayerSet)
Definition: class_zone.cpp:220
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:122
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
#define MAXPTS
void SetClosed(bool aClosed)
Function SetClosed()
bool sortEndsByDescendingX(const VECTOR2I &ref, const VECTOR2I &tst)
int m_HatchFillTypeSmoothingLevel
Grid pattern smoothing type, similar to corner smoothing type 0 = no smoothing, 1 = fillet,...
Definition: class_zone.h:799
int m_ArcToSegmentsCount
The number of segments to convert a circle to a polygon.
Definition: class_zone.h:764
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
int m_ThermalReliefCopperBridge
Definition: class_zone.h:779
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:547
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
std::vector< SEG > m_HatchLines
Definition: class_zone.h:831
ZoneConnection m_PadConnection
Definition: class_zone.h:758
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
void Move(const VECTOR2I &aVector) override
ZONE_CONTAINER & operator=(const ZONE_CONTAINER &aOther)
Definition: class_zone.cpp:123
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
ITERATOR IterateWithHoles(int aOutline)
Function IterateWithHoles.
Class SHAPE_POLY_SET.
double m_HatchFillTypeOrientation
Grid style shape: orientation in degrees of the grid lines.
Definition: class_zone.h:795
bool m_IsFilled
True when a zone was filled, false after deleting the filled areas.
Definition: class_zone.h:767
virtual void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
Definition: class_zone.cpp:959
int GetThermalWidth() const
Definition: class_pad.cpp:748
SHAPE_POLY_SET * m_Poly
Outline of the zone.
Definition: class_zone.h:734
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if a point is near an outline edge or a corner of this zone.
Definition: class_zone.cpp:653
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:652
ZONE_CONTAINER(BOARD *parent)
Definition: class_zone.cpp:52
unsigned m_priority
Definition: class_zone.h:744
void Rotate(const wxPoint &centre, double angle) override
Function Rotate Move the outlines.
Definition: class_zone.cpp:929
bool m_doNotAllowVias
Definition: class_zone.h:755
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:212
bool CollideVertex(const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0)
Function CollideVertex Checks whether aPoint collides with any vertex of any of the contours of the p...
bool UnFill()
Function UnFill Removes the zone filling.
Definition: class_zone.cpp:166
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:235
int m_cornerSmoothingType
Definition: class_zone.h:735
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:459
void CacheTriangulation()
(re)create a list of triangles that "fill" the solid areas.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
double m_HatchFillTypeSmoothingValue
Grid pattern smoothing value for smoothing shape size calculations this is the ratio between the gap ...
Definition: class_zone.h:803
Definition: colors.h:60
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:66
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
Definition: class_zone.cpp:257
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:285
int NewOutline()
Creates a new empty polygon in the set and returns its index
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
void AddPolygon(std::vector< wxPoint > &aPolygon)
add a polygon to the zone outline if the zone outline is empty, this is the main outline else it is a...
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
SHAPE_POLY_SET m_FilledPolysList
Definition: class_zone.h:824
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index
void SetSelectedCorner(int aCorner)
Definition: class_zone.h:234
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:651
unsigned int m_cornerRadius
Definition: class_zone.h:736
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
bool NeedRefill() const
Definition: class_zone.h:190
wxString GetNetnameMsg() const
Function GetNetnameMsg.
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:897
HATCH_STYLE m_hatchStyle
Definition: class_zone.h:829
Definition: seg.h:36
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
void Normalize()
Function Normalize ensures that the height ant width are positive.
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
Definition: macros.h:73
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:657
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly) const
Function GetSmoothedPoly returns a pointer to the corner-smoothed version of m_Poly if it exists,...
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
bool m_doNotAllowCopperPour
Definition: class_zone.h:754
bool FindLineSegmentIntersection(double a, double b, int xi, int yi, int xf, int yf, double *x1, double *y1, double *x2, double *y2, double *dist=NULL)
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:453
int m_ThermalReliefGap
Width of the copper bridge in thermal reliefs.
Definition: class_zone.h:776
int m_ZoneMinThickness
Minimum thickness value in filled areas.
Definition: class_zone.h:760
ZONE_FILL_MODE m_FillMode
How to fill areas: ZFM_POLYGONS => use solid polygons ZFM_HATCH_PATTERN => use a grid pattern as shap...
Definition: class_zone.h:786
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:96
SHAPE_POLY_SET Chamfer(int aDistance)
Function Chamfer returns a chamfered version of the polygon set.
void UnHatch()
Function UnHatch clears the zone's hatch.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
ZoneConnection GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:999
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
Class SHAPE_LINE_CHAIN.
int m_HatchFillTypeThickness
Grid style shape: thickness of lines (if 0 -> solid shape)
Definition: class_zone.h:789
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const
Function GetClearance returns the clearance in internal units.
std::shared_ptr< NETCLASS > GetNetClass() const
Function GetNetClass returns the NETCLASS for this item.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:123
void GRFilledSegment(EDA_RECT *aClipBox, wxDC *aDC, wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor)
Definition: gr_basic.cpp:526
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
Class ITERATOR_TEMPLATE.
size_t i
Definition: json11.cpp:597
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
VECTOR2I A
Definition: seg.h:44
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void Hatch()
Function Hatch computes the hatch lines depending on the hatch parameters and stores it in the zone's...
int GetHatchPitch() const
Hatch related methods.
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:558
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:552
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
void SetLocalFlags(int aFlags)
Definition: class_zone.h:255
void GRLineArray(EDA_RECT *aClipBox, wxDC *aDC, std::vector< wxPoint > &aLines, int aWidth, COLOR4D aColor)
Function GRLineArray draws an array of lines (not a polygon).
Definition: gr_basic.cpp:361
Definition: colors.h:49
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
bool GetDoNotAllowTracks() const
Definition: class_zone.h:654
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
bool HitTestForEdge(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Function HitTestForEdge tests if the given wxPoint is near a segment defined by 2 corners.
Definition: class_zone.cpp:692
bool m_needRefill
False when a zone was refilled, true after changes in zone params.
Definition: class_zone.h:773
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
void Mirror(const wxPoint &mirror_ref)
Function Mirror Mirror the outlines , relative to a given horizontal axis the layer is not changed.
Definition: class_zone.cpp:975
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
int m_HatchFillTypeGap
Grid style shape: dist between center of lines (grid size) (0 -> solid shape)
Definition: class_zone.h:792
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:656
ZoneConnection GetZoneConnection() const
Definition: class_pad.cpp:737
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Message panel definition file.
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
#define FORCE_SKETCH
Definition: pcbnew.h:67
#define ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF
Definition: pcbnew.h:42
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
int GetState(int type) const
Definition: base_struct.h:243
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:191
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:499
EDA_UNITS_T
Definition: common.h:157
int GetLocalFlags() const
Definition: class_zone.h:254
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204
#define min(a, b)
Definition: auxiliary.h:85
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: class_zone.cpp:808
VECTOR2I B
Definition: seg.h:45
Definition: colors.h:62
void SetNeedRefill(bool aNeedRefill)
Definition: class_zone.h:191