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