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;
61  m_priority = 0;
63  SetIsKeepout( false );
64  SetDoNotAllowCopperPour( false ); // has meaning only if m_isKeepout == true
65  SetDoNotAllowVias( true ); // has meaning only if m_isKeepout == true
66  SetDoNotAllowTracks( true ); // has meaning only if m_isKeepout == true
67  m_cornerRadius = 0;
68  SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
69  m_Poly = new SHAPE_POLY_SET(); // Outlines
70  aBoard->GetZoneSettings().ExportSetting( *this );
71 
72  m_needRefill = false; // True only after some edition.
73 }
74 
75 
77  BOARD_CONNECTED_ITEM( aZone )
78 {
79  // Should the copy be on the same net?
80  SetNetCode( aZone.GetNetCode() );
81  m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
82 
83  // For corner moving, corner index to drag, or nullptr if no selection
84  m_CornerSelection = nullptr;
85  m_IsFilled = aZone.m_IsFilled;
86  m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
88  m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons)
89  m_hv45 = aZone.m_hv45;
90  m_priority = aZone.m_priority;
96  m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
97 
98  m_isKeepout = aZone.m_isKeepout;
102 
105 
106  m_hatchStyle = aZone.m_hatchStyle;
107  m_hatchPitch = aZone.m_hatchPitch;
108  m_HatchLines = aZone.m_HatchLines;
109 
110  SetLayerSet( aZone.GetLayerSet() );
111  SetLocalFlags( aZone.GetLocalFlags() );
112 
113  SetNeedRefill( aZone.NeedRefill() );
114 }
115 
116 
118 {
120 
121  // Replace the outlines for aOther outlines.
122  delete m_Poly;
123  m_Poly = new SHAPE_POLY_SET( *aOther.m_Poly );
124 
125  m_CornerSelection = nullptr; // for corner moving, corner index to (null if no selection)
126  m_ZoneClearance = aOther.m_ZoneClearance; // clearance value
128  m_FillMode = aOther.m_FillMode; // filling mode (segments/polygons)
133  SetHatchStyle( aOther.GetHatchStyle() );
134  SetHatchPitch( aOther.GetHatchPitch() );
135  m_HatchLines = aOther.m_HatchLines; // copy vector <SEG>
138  m_FillSegmList.clear();
140 
141  SetLayerSet( aOther.GetLayerSet() );
142 
143  return *this;
144 }
145 
146 
148 {
149  delete m_Poly;
150  delete m_CornerSelection;
151 }
152 
153 
155 {
156  return new ZONE_CONTAINER( *this );
157 }
158 
159 
161 {
162  bool change = ( !m_FilledPolysList.IsEmpty() ) ||
163  ( m_FillSegmList.size() > 0 );
164 
166  m_FillSegmList.clear();
167  m_IsFilled = false;
168 
169  return change;
170 }
171 
172 
173 const wxPoint ZONE_CONTAINER::GetPosition() const
174 {
175  return (wxPoint) GetCornerPosition( 0 );
176 }
177 
178 
180 {
181  return BOARD_ITEM::GetLayer();
182 }
183 
184 
186 {
187  if( GetIsKeepout() )
188  {
189  return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
190  }
191  else
192  {
193  return IsCopperLayer( GetLayer() );
194  }
195 }
196 
197 
198 bool ZONE_CONTAINER::CommonLayerExists( const LSET aLayerSet ) const
199 {
200  LSET common = GetLayerSet() & aLayerSet;
201 
202  return common.count() > 0;
203 }
204 
205 
207 {
208  SetLayerSet( LSET( aLayer ) );
209 
210  m_Layer = aLayer;
211 }
212 
213 
215 {
216  if( GetIsKeepout() )
217  {
218  // Keepouts can only exist on copper layers
219  aLayerSet &= LSET::AllCuMask();
220  }
221 
222  if( aLayerSet.count() == 0 )
223  {
224  return;
225  }
226 
227  if( m_layerSet != aLayerSet )
228  SetNeedRefill( true );
229 
230  m_layerSet = aLayerSet;
231 
232  // Set the single layer to the first selected layer
233  m_Layer = aLayerSet.Seq()[0];
234 }
235 
236 
238 {
239  // TODO - Enable multi-layer zones for all zone types
240  // not just keepout zones
241  if( GetIsKeepout() )
242  {
243  return m_layerSet;
244  }
245  else
246  {
247  return LSET( m_Layer );
248  }
249 }
250 
251 void ZONE_CONTAINER::ViewGetLayers( int aLayers[], int& aCount ) const
252 {
253  if( GetIsKeepout() )
254  {
255  LSEQ layers = m_layerSet.Seq();
256 
257  for( unsigned int idx = 0; idx < layers.size(); idx++ )
258  {
259  aLayers[idx] = layers[idx];
260  }
261 
262  aCount = layers.size();
263  }
264  else
265  {
266  aLayers[0] = m_Layer;
267  aCount = 1;
268  }
269 }
270 
271 
273 {
274  if( GetIsKeepout() )
275  {
276  return m_layerSet.test( aLayer );
277  }
278 
279  return BOARD_ITEM::IsOnLayer( aLayer );
280 }
281 
282 
283 void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
284  const wxPoint& offset )
285 {
286  if( !DC )
287  return;
288 
289  wxPoint seg_start, seg_end;
290  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
291  BOARD* brd = GetBoard();
292 
293  auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
294 
295  PCB_LAYER_ID draw_layer = UNDEFINED_LAYER;
296 
297  LSET layers = GetLayerSet() & brd->GetVisibleLayers();
298 
299  // If there are no visible layers and the zone is not highlighted, return
300  if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
301  {
302  return;
303  }
304 
305  /* Keepout zones can exist on multiple layers
306  * Thus, determining which color to use to render them is a bit tricky.
307  * In descending order of priority:
308  *
309  * 1. If in GR_HIGHLIGHT mode:
310  * a. If zone is on selected layer, use layer color!
311  * b. Else, use grey
312  * 1. Not in GR_HIGHLIGHT mode
313  * a. If zone is on selected layer, use layer color
314  * b. Else, use color of top-most (visible) layer
315  *
316  */
317  if( GetIsKeepout() )
318  {
319  // At least one layer must be provided!
320  assert( GetLayerSet().count() > 0 );
321 
322  // Not on any visible layer?
323  if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
324  {
325  return;
326  }
327 
328  // Is keepout zone present on the selected layer?
329  if( layers.test( curr_layer ) )
330  {
331  draw_layer = curr_layer;
332  }
333  else
334  {
335  // Select the first (top) visible layer
336  if( layers.count() > 0 )
337  {
338  draw_layer = layers.Seq()[0];
339  }
340  else
341  {
342  draw_layer = GetLayerSet().Seq()[0];
343  }
344  }
345 
346  }
347  /* Non-keepout zones are easier to deal with
348  */
349  else
350  {
351  if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
352  {
353  return;
354  }
355 
356  draw_layer = GetLayer();
357  }
358 
359  assert( draw_layer != UNDEFINED_LAYER );
360 
361  auto color = frame->Settings().Colors().GetLayerColor( draw_layer );
362 
363  GRSetDrawMode( DC, aDrawMode );
364  auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
365 
366  if( displ_opts->m_ContrastModeDisplay )
367  {
368  if( !IsOnLayer( curr_layer ) )
369  {
371  }
372  }
373 
374  if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
375  {
376  color.SetToLegacyHighlightColor();
377  }
378 
379  color.a = 0.588;
380 
381  // draw the lines
382  std::vector<wxPoint> lines;
383  lines.reserve( (GetNumCorners() * 2) + 2 );
384 
385  // Iterate through the segments of the outline
386  for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
387  {
388  // Create the segment
389  SEG segment = *iterator;
390 
391  lines.push_back( static_cast<wxPoint>( segment.A ) + offset );
392  lines.push_back( static_cast<wxPoint>( segment.B ) + offset );
393  }
394 
395  GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
396 
397  // draw hatches
398  lines.clear();
399  lines.reserve( (m_HatchLines.size() * 2) + 2 );
400 
401  for( unsigned ic = 0; ic < m_HatchLines.size(); ic++ )
402  {
403  seg_start = static_cast<wxPoint>( m_HatchLines[ic].A ) + offset;
404  seg_end = static_cast<wxPoint>( m_HatchLines[ic].B ) + offset;
405  lines.push_back( seg_start );
406  lines.push_back( seg_end );
407  }
408 
409  GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
410 }
411 
412 
414  wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
415 {
416 
417  static std::vector <wxPoint> CornersBuffer;
418  auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
419 
420  // outline_mode is false to show filled polys,
421  // and true to show polygons outlines only (test and debug purposes)
422  bool outline_mode = displ_opts->m_DisplayZonesMode == 2 ? true : false;
423 
424  if( DC == NULL )
425  return;
426 
427  if( displ_opts->m_DisplayZonesMode == 1 ) // Do not show filled areas
428  return;
429 
430  if( m_FilledPolysList.IsEmpty() ) // Nothing to draw
431  return;
432 
433  BOARD* brd = GetBoard();
434  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
435 
436  auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
437  auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
438 
439  if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
440  return;
441 
442  GRSetDrawMode( DC, aDrawMode );
443 
444  if( displ_opts->m_ContrastModeDisplay )
445  {
446  if( !IsOnLayer( curr_layer ) )
448  }
449 
450  if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
451  color.SetToLegacyHighlightColor();
452 
453  color.a = 0.588;
454 
455 
456  for ( int ic = 0; ic < m_FilledPolysList.OutlineCount(); ic++ )
457  {
458  const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( ic );
459 
460  CornersBuffer.clear();
461 
462  wxPoint p0;
463 
464  for( int j = 0; j < path.PointCount(); j++ )
465  {
466  const VECTOR2I& corner = path.CPoint( j );
467 
468  wxPoint coord( corner.x + offset.x, corner.y + offset.y );
469 
470  if( j == 0 )
471  p0 = coord;
472 
473  CornersBuffer.push_back( coord );
474  }
475 
476  CornersBuffer.push_back( p0 );
477 
478  // Draw outlines:
479  if( ( m_ZoneMinThickness > 1 ) || outline_mode )
480  {
481  int ilim = CornersBuffer.size() - 1;
482 
483  int line_thickness = m_ZoneMinThickness;
484 
485  for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
486  {
487  // Draw only basic outlines, not extra segments.
488  if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
489  GRCSegm( panel->GetClipBox(), DC,
490  CornersBuffer[is], CornersBuffer[ie], line_thickness, color );
491  else
492  GRFilledSegment( panel->GetClipBox(), DC,
493  CornersBuffer[is], CornersBuffer[ie], line_thickness, color );
494  }
495  }
496 
497  // Draw areas:
498  if( m_FillMode == ZFM_POLYGONS && !outline_mode )
499  GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
500  true, 0, color, color );
501  }
502 
503  if( m_FillMode == 1 && !outline_mode ) // filled with segments
504  {
505  for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
506  {
507  wxPoint start = (wxPoint) ( m_FillSegmList[ic].A + VECTOR2I(offset) );
508  wxPoint end = (wxPoint) ( m_FillSegmList[ic].B + VECTOR2I(offset) );
509 
510  if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
511  GRCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
513  else
514  GRFillCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
516  }
517  }
518 }
519 
520 
522 {
523  const int PRELOAD = 0x7FFFFFFF; // Biggest integer (32 bits)
524 
525  int ymax = -PRELOAD;
526  int ymin = PRELOAD;
527  int xmin = PRELOAD;
528  int xmax = -PRELOAD;
529 
530  int count = GetNumCorners();
531 
532  for( int i = 0; i<count; ++i )
533  {
534  wxPoint corner = static_cast<wxPoint>( GetCornerPosition( i ) );
535 
536  ymax = std::max( ymax, corner.y );
537  xmax = std::max( xmax, corner.x );
538  ymin = std::min( ymin, corner.y );
539  xmin = std::min( xmin, corner.x );
540  }
541 
542  EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
543 
544  return ret;
545 }
546 
547 
549  GR_DRAWMODE draw_mode )
550 {
551  GR_DRAWMODE current_gr_mode = draw_mode;
552  bool is_close_segment = false;
553 
554  if( !DC )
555  return;
556 
557  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
558 
559  auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
560  auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
561 
562  auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
563 
564  if( displ_opts->m_ContrastModeDisplay )
565  {
566  if( !IsOnLayer( curr_layer ) )
568  }
569 
570  // Object to iterate through the corners of the outlines
572 
573  // Segment start and end
574  VECTOR2I seg_start, seg_end;
575 
576  // Remember the first point of this contour
577  VECTOR2I contour_first_point = *iterator;
578 
579  // Iterate through all the corners of the outlines and build the segments to draw
580  while( iterator )
581  {
582  // Get the first point of the current segment
583  seg_start = *iterator;
584 
585  // Get the last point of the current segment, handling the case where the end of the
586  // contour is reached, when the last point of the segment is the first point of the
587  // contour
588  if( !iterator.IsEndContour() )
589  {
590  // Set GR mode to default
591  current_gr_mode = draw_mode;
592 
593  SHAPE_POLY_SET::ITERATOR iterator_copy = iterator;
594  iterator_copy++;
595  if( iterator_copy.IsEndContour() )
596  current_gr_mode = GR_XOR;
597 
598  is_close_segment = false;
599 
600  iterator++;
601  seg_end = *iterator;
602  }
603  else
604  {
605  is_close_segment = true;
606 
607  seg_end = contour_first_point;
608 
609  // Reassign first point of the contour to the next contour start
610  iterator++;
611 
612  if( iterator )
613  contour_first_point = *iterator;
614 
615  // Set GR mode to XOR
616  current_gr_mode = GR_XOR;
617  }
618 
619  GRSetDrawMode( DC, current_gr_mode );
620 
621  if( is_close_segment )
622  GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
623  WHITE );
624  else
625  GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
626  color );
627  }
628 }
629 
630 
632 {
633  if( aPad == NULL || aPad->GetThermalGap() == 0 )
634  return m_ThermalReliefGap;
635  else
636  return aPad->GetThermalGap();
637 }
638 
639 
641 {
642  if( aPad == NULL || aPad->GetThermalWidth() == 0 )
644  else
645  return aPad->GetThermalWidth();
646 }
647 
648 
649 void ZONE_CONTAINER::SetCornerRadius( unsigned int aRadius )
650 {
651  if( m_cornerRadius != aRadius )
652  SetNeedRefill( true );
653 
654  m_cornerRadius = aRadius;
655 }
656 
657 
658 bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) const
659 {
660  // Normally accuracy is zoom-relative, but for the generic HitTest we just use
661  // a fixed (small) value.
662  int accuracy = Millimeter2iu( 0.05 );
663 
664  return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
665 }
666 
667 
668 void ZONE_CONTAINER::SetSelectedCorner( const wxPoint& aPosition, int aAccuracy )
669 {
671 
672  // If there is some corner to be selected, assign it to m_CornerSelection
673  if( HitTestForCorner( aPosition, aAccuracy * 2, corner )
674  || HitTestForEdge( aPosition, aAccuracy, corner ) )
675  {
676  if( m_CornerSelection == nullptr )
678 
679  *m_CornerSelection = corner;
680  }
681 }
682 
683 bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy,
684  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
685 {
686  return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, aAccuracy );
687 }
688 
689 
690 bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const
691 {
693  return HitTestForCorner( refPos, aAccuracy, dummy );
694 }
695 
696 
697 bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy,
698  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
699 {
700  return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, aAccuracy );
701 }
702 
703 
704 bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const
705 {
707  return HitTestForEdge( refPos, aAccuracy, dummy );
708 }
709 
710 
711 bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
712 {
713  // Calculate bounding box for zone
714  EDA_RECT bbox = GetBoundingBox();
715  bbox.Normalize();
716 
717  EDA_RECT arect = aRect;
718  arect.Normalize();
719  arect.Inflate( aAccuracy );
720 
721  if( aContained )
722  {
723  return arect.Contains( bbox );
724  }
725  else // Test for intersection between aBox and the polygon
726  // For a polygon, using its bounding box has no sense here
727  {
728  // Fast test: if aBox is outside the polygon bounding box,
729  // rectangles cannot intersect
730  if( !arect.Intersects( bbox ) )
731  return false;
732 
733  // aBox is inside the polygon bounding box,
734  // and can intersect the polygon: use a fine test.
735  // aBox intersects the polygon if at least one aBox corner
736  // is inside the polygon
737 
738  /*
739  wxPoint origin = arect.GetOrigin();
740 
741  int w = arect.GetWidth();
742  int h = arect.GetHeight();
743 
744 
745  if ( HitTestInsideZone( origin ) ||
746  HitTestInsideZone( origin + wxPoint( w, 0 ) ) ||
747  HitTestInsideZone( origin + wxPoint( w, h ) ) ||
748  HitTestInsideZone( origin + wxPoint( 0, h ) ) )
749  {
750  return true;
751  }
752  */
753 
754  // No corner inside aBox, but outlines can intersect aBox
755  // if one of outline corners is inside aBox
756  int count = m_Poly->TotalVertices();
757  for( int ii =0; ii < count; ii++ )
758  {
759  auto vertex = m_Poly->Vertex( ii );
760  auto vertexNext = m_Poly->Vertex( ( ii + 1 ) % count );
761 
762  // Test if the point is within the rect
763  if( arect.Contains( ( wxPoint ) vertex ) )
764  {
765  return true;
766  }
767 
768  // Test if this edge intersects the rect
769  if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
770  {
771  return true;
772  }
773  }
774 
775  return false;
776  }
777 }
778 
779 
781 {
782  int myClearance = m_ZoneClearance;
783 
784 #if 1 // Maybe the netclass clearance should not come into play for a zone?
785  // At least the policy decision can be controlled by the zone
786  // itself, i.e. here. On reasons of insufficient documentation,
787  // the user will be less bewildered if we simply respect the
788  // "zone clearance" setting in the zone properties dialog. (At least
789  // until there is a UI boolean for this.)
790 
791  NETCLASSPTR myClass = GetNetClass();
792 
793  if( myClass )
794  myClearance = std::max( myClearance, myClass->GetClearance() );
795 #endif
796 
797  if( aItem )
798  {
799  int hisClearance = aItem->GetClearance( NULL );
800  myClearance = std::max( hisClearance, myClearance );
801  }
802 
803  return myClearance;
804 }
805 
806 
807 bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
808 {
809  return m_FilledPolysList.Contains( VECTOR2I( aRefPos.x, aRefPos.y ) );
810 }
811 
812 
813 void ZONE_CONTAINER::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
814 {
815  wxString msg;
816 
817  msg = _( "Zone Outline" );
818 
819  // Display Cutout instead of Outline for holes inside a zone
820  // i.e. when num contour !=0
821  // Check whether the selected corner is in a hole; i.e., in any contour but the first one.
822  if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
823  msg << wxT( " " ) << _( "(Cutout)" );
824 
825  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, DARKCYAN ) );
826 
827  if( GetIsKeepout() )
828  {
829  msg.Empty();
830 
831  if( GetDoNotAllowVias() )
832  AccumulateDescription( msg, _( "No via" ) );
833 
834  if( GetDoNotAllowTracks() )
835  AccumulateDescription( msg, _("No track") );
836 
838  AccumulateDescription( msg, _("No copper pour") );
839 
840  aList.push_back( MSG_PANEL_ITEM( _( "Keepout" ), msg, RED ) );
841  }
842  else if( IsOnCopperLayer() )
843  {
844  if( GetNetCode() >= 0 )
845  {
846  NETINFO_ITEM* net = GetNet();
847 
848  if( net )
849  msg = net->GetNetname();
850  else // Should not occur
851  msg = _( "<unknown>" );
852  }
853  else // a netcode < 0 is an error
854  msg = wxT( "<error>" );
855 
856  aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
857 
858  // Display net code : (useful in test or debug)
859  msg.Printf( wxT( "%d" ), GetNetCode() );
860  aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
861 
862  // Display priority level
863  msg.Printf( wxT( "%d" ), GetPriority() );
864  aList.push_back( MSG_PANEL_ITEM( _( "Priority" ), msg, BLUE ) );
865  }
866  else
867  {
868  aList.push_back( MSG_PANEL_ITEM( _( "Non Copper Zone" ), wxEmptyString, RED ) );
869  }
870 
871  aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BROWN ) );
872 
873  msg.Printf( wxT( "%d" ), (int) m_Poly->TotalVertices() );
874  aList.push_back( MSG_PANEL_ITEM( _( "Corners" ), msg, BLUE ) );
875 
876  if( m_FillMode )
877  msg = _( "Segments" );
878  else
879  msg = _( "Polygons" );
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:645
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:283
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:732
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:548
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:198
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:640
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:121
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:154
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:729
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox (virtual)
Definition: class_zone.cpp:521
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
void SetCornerRadius(unsigned int aRadius)
Definition: class_zone.cpp:649
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:759
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:272
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:413
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:683
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:102
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:179
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:807
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:767
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:631
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:173
#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:780
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:644
This file contains miscellaneous commonly used macros and functions.
bool GetDoNotAllowVias() const
Definition: class_zone.h:639
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:237
virtual EDA_DRAW_FRAME * GetParent() const =0
PCB_LAYER_ID m_Layer
void SetLayerSet(LSET aLayerSet)
Definition: class_zone.cpp:214
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:114
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_ArcToSegmentsCount
The number of segments to convert a circle to a polygon.
Definition: class_zone.h:737
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:752
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:533
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:782
ZoneConnection m_PadConnection
Definition: class_zone.h:731
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:117
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.
void GRFillCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:518
bool m_IsFilled
True when a zone was filled, false after deleting the filled areas.
Definition: class_zone.h:740
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:707
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:638
ZONE_CONTAINER(BOARD *parent)
Definition: class_zone.cpp:52
unsigned m_priority
Definition: class_zone.h:717
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:728
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:206
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:160
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
int m_cornerSmoothingType
Definition: class_zone.h:708
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:445
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.
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:251
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:777
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:220
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:637
unsigned int m_cornerRadius
Definition: class_zone.h:709
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
bool NeedRefill() const
Definition: class_zone.h:191
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:780
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:65
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:643
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:69
bool m_doNotAllowCopperPour
Definition: class_zone.h:727
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:458
int m_ThermalReliefGap
Width of the copper bridge in thermal reliefs.
Definition: class_zone.h:749
int m_ZoneMinThickness
Minimum thickness value in filled areas.
Definition: class_zone.h:733
ZONE_FILL_MODE m_FillMode
How to fill areas: ZFM_POLYGONS => use filled polygons, ZFM_SEGMENTS => fill with segments.
Definition: class_zone.h:756
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:97
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:171
Class SHAPE_LINE_CHAIN.
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.
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.
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if a point is near an outline edge or a corner of this zone.
Definition: class_zone.cpp:658
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:563
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:538
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
void SetLocalFlags(int aFlags)
Definition: class_zone.h:241
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:640
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:697
bool m_needRefill
False when a zone was refilled, true after changes in zone params.
Definition: class_zone.h:746
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
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:642
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:73
#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:240
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:185
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:485
EDA_UNITS_T
Definition: common.h:160
int GetLocalFlags() const
Definition: class_zone.h:240
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:201
#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:813
VECTOR2I B
Definition: seg.h:45
Definition: colors.h:62
void SetNeedRefill(bool aNeedRefill)
Definition: class_zone.h:192