KiCad PCB EDA Suite
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-2021 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>
28 #include <geometry/shape_null.h>
29 #include <core/mirror.h>
30 #include <advanced_config.h>
31 #include <pcb_edit_frame.h>
32 #include <pcb_screen.h>
33 #include <board.h>
34 #include <board_design_settings.h>
35 #include <pad.h>
36 #include <zone.h>
37 #include <kicad_string.h>
38 #include <math_for_graphics.h>
41 #include <trigo.h>
42 #include <i18n_utility.h>
43 
44 ZONE::ZONE( BOARD_ITEM_CONTAINER* aParent, bool aInFP ) :
45  BOARD_CONNECTED_ITEM( aParent, aInFP ? PCB_FP_ZONE_T : PCB_ZONE_T ),
46  m_area( 0.0 )
47 {
48  m_CornerSelection = nullptr; // no corner is selected
49  m_isFilled = false; // fill status : true when the zone is filled
53  m_hv45 = false;
54  m_hatchThickness = 0;
55  m_hatchGap = 0;
56  m_hatchOrientation = 0.0;
57  m_hatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
58  m_hatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
59  // used only if m_hatchSmoothingLevel > 0
60  m_hatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
61  m_hatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
62  m_priority = 0;
64  SetIsRuleArea( aInFP ); // Zones living in footprints have the rule area option
65  SetDoNotAllowCopperPour( false ); // has meaning only if m_isRuleArea == true
66  SetDoNotAllowVias( true ); // has meaning only if m_isRuleArea == true
67  SetDoNotAllowTracks( true ); // has meaning only if m_isRuleArea == true
68  SetDoNotAllowPads( true ); // has meaning only if m_isRuleArea == true
69  SetDoNotAllowFootprints( false ); // has meaning only if m_isRuleArea == true
70  m_cornerRadius = 0;
71  SetLocalFlags( 0 ); // flags temporary used in zone calculations
72  m_Poly = new SHAPE_POLY_SET(); // Outlines
73  m_fillVersion = 5; // set the "old" way to build filled polygon areas (< 6.0.x)
75  aParent->GetZoneSettings().ExportSetting( *this );
76 
77  m_needRefill = false; // True only after some edition.
78 }
79 
80 
81 ZONE::ZONE( const ZONE& aZone )
82  : BOARD_CONNECTED_ITEM( aZone ),
83  m_Poly( nullptr ),
84  m_CornerSelection( nullptr )
85 {
87 }
88 
89 
90 ZONE& ZONE::operator=( const ZONE& aOther )
91 {
93 
94  InitDataFromSrcInCopyCtor( aOther );
95 
96  return *this;
97 }
98 
99 
101 {
102  delete m_Poly;
103  delete m_CornerSelection;
104 }
105 
106 
108 {
109  // members are expected non initialize in this.
110  // InitDataFromSrcInCopyCtor() is expected to be called
111  // only from a copy constructor.
112 
113  // Copy only useful EDA_ITEM flags:
114  m_flags = aZone.m_flags;
116 
117  // Replace the outlines for aZone outlines.
118  delete m_Poly;
119  m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
120 
123  m_zoneName = aZone.m_zoneName;
124  m_priority = aZone.m_priority;
125  m_isRuleArea = aZone.m_isRuleArea;
126  SetLayerSet( aZone.GetLayerSet() );
127 
133 
135  m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
140 
141  m_isFilled = aZone.m_isFilled;
142  m_needRefill = aZone.m_needRefill;
143 
146 
147  m_fillMode = aZone.m_fillMode; // solid vs. hatched
149  m_hatchGap = aZone.m_hatchGap;
155 
156  // For corner moving, corner index to drag, or nullptr if no selection
157  delete m_CornerSelection;
158  m_CornerSelection = nullptr;
159 
160  for( PCB_LAYER_ID layer : aZone.GetLayerSet().Seq() )
161  {
162  m_FilledPolysList[layer] = aZone.m_FilledPolysList.at( layer );
163  m_RawPolysList[layer] = aZone.m_RawPolysList.at( layer );
164  m_filledPolysHash[layer] = aZone.m_filledPolysHash.at( layer );
165  m_FillSegmList[layer] = aZone.m_FillSegmList.at( layer ); // vector <> copy
166  m_insulatedIslands[layer] = aZone.m_insulatedIslands.at( layer );
167  }
168 
172 
173  SetLocalFlags( aZone.GetLocalFlags() );
174 
175  m_netinfo = aZone.m_netinfo;
176 
177  m_hv45 = aZone.m_hv45;
178  m_area = aZone.m_area;
179 }
180 
181 
183 {
184  return new ZONE( *this );
185 }
186 
187 
189 {
190  bool change = false;
191 
192  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
193  {
194  change |= !pair.second.IsEmpty();
195  m_insulatedIslands[pair.first].clear();
196  pair.second.RemoveAllContours();
197  }
198 
199  for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
200  {
201  change |= !pair.second.empty();
202  pair.second.clear();
203  }
204 
205  m_isFilled = false;
206  m_fillFlags.clear();
207 
208  return change;
209 }
210 
211 
212 wxPoint ZONE::GetPosition() const
213 {
214  return (wxPoint) GetCornerPosition( 0 );
215 }
216 
217 
219 {
220  return BOARD_ITEM::GetLayer();
221 }
222 
223 
225 {
226  return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
227 }
228 
229 
230 bool ZONE::CommonLayerExists( const LSET aLayerSet ) const
231 {
232  LSET common = GetLayerSet() & aLayerSet;
233 
234  return common.count() > 0;
235 }
236 
237 
239 {
240  SetLayerSet( LSET( aLayer ) );
241 
242  m_layer = aLayer;
243 }
244 
245 
246 void ZONE::SetLayerSet( LSET aLayerSet )
247 {
248  if( GetIsRuleArea() )
249  {
250  // Rule areas can only exist on copper layers
251  aLayerSet &= LSET::AllCuMask();
252  }
253 
254  if( aLayerSet.count() == 0 )
255  return;
256 
257  if( m_layerSet != aLayerSet )
258  {
259  SetNeedRefill( true );
260 
261  UnFill();
262 
263  m_FillSegmList.clear();
264  m_FilledPolysList.clear();
265  m_RawPolysList.clear();
266  m_filledPolysHash.clear();
267  m_insulatedIslands.clear();
268 
269  for( PCB_LAYER_ID layer : aLayerSet.Seq() )
270  {
271  m_FillSegmList[layer] = {};
272  m_FilledPolysList[layer] = {};
273  m_RawPolysList[layer] = {};
274  m_filledPolysHash[layer] = {};
275  m_insulatedIslands[layer] = {};
276  }
277  }
278 
279  m_layerSet = aLayerSet;
280 
281  // Set the single layer parameter. For zones that can be on many layers, this parameter
282  // is arbitrary at best, but some code still uses it.
283  // Priority is F_Cu then B_Cu then to the first selected layer
284  m_layer = aLayerSet.Seq()[0];
285 
286  if( m_layer != F_Cu && aLayerSet[B_Cu] )
287  m_layer = B_Cu;
288 }
289 
290 
292 {
293  return m_layerSet;
294 }
295 
296 
297 void ZONE::ViewGetLayers( int aLayers[], int& aCount ) const
298 {
299  LSEQ layers = m_layerSet.Seq();
300 
301  for( unsigned int idx = 0; idx < layers.size(); idx++ )
302  aLayers[idx] = LAYER_ZONE_START + layers[idx];
303 
304  aCount = layers.size();
305 }
306 
307 
308 double ZONE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
309 {
310  constexpr double HIDE = std::numeric_limits<double>::max();
311 
312  return aView->IsLayerVisible( LAYER_ZONES ) ? 0.0 : HIDE;
313 }
314 
315 
316 bool ZONE::IsOnLayer( PCB_LAYER_ID aLayer ) const
317 {
318  return m_layerSet.test( aLayer );
319 }
320 
321 
323 {
324  auto bb = m_Poly->BBox();
325 
326  EDA_RECT ret( (wxPoint) bb.GetOrigin(), wxSize( bb.GetWidth(), bb.GetHeight() ) );
327 
328  return ret;
329 }
330 
331 
332 int ZONE::GetThermalReliefGap( PAD* aPad, wxString* aSource ) const
333 {
334  if( aPad->GetEffectiveThermalGap() == 0 )
335  {
336  if( aSource )
337  *aSource = _( "zone" );
338 
339  return m_thermalReliefGap;
340  }
341 
342  return aPad->GetEffectiveThermalGap( aSource );
343 
344 }
345 
346 
347 int ZONE::GetThermalReliefSpokeWidth( PAD* aPad, wxString* aSource ) const
348 {
349  if( aPad->GetEffectiveThermalSpokeWidth() == 0 )
350  {
351  if( aSource )
352  *aSource = _( "zone" );
353 
355  }
356 
357  return aPad->GetEffectiveThermalSpokeWidth( aSource );
358 }
359 
360 
361 void ZONE::SetCornerRadius( unsigned int aRadius )
362 {
363  if( m_cornerRadius != aRadius )
364  SetNeedRefill( true );
365 
366  m_cornerRadius = aRadius;
367 }
368 
369 
371 {
372  if( ADVANCED_CFG::GetCfg().m_DebugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
373  return false;
374 
376 }
377 
378 
380 
381 
383 {
384  if( !m_filledPolysHash.count( aLayer ) )
385  return g_nullPoly.GetHash();
386  else
387  return m_filledPolysHash.at( aLayer );
388 }
389 
390 
392 {
393  if( !m_FilledPolysList.count( aLayer ) )
395  else
396  m_filledPolysHash[aLayer] = m_FilledPolysList.at( aLayer ).GetHash();
397 }
398 
399 
400 bool ZONE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
401 {
402  // When looking for an "exact" hit aAccuracy will be 0 which works poorly for very thin
403  // lines. Give it a floor.
404  int accuracy = std::max( aAccuracy, Millimeter2iu( 0.1 ) );
405 
406  return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
407 }
408 
409 
410 void ZONE::SetSelectedCorner( const wxPoint& aPosition, int aAccuracy )
411 {
413 
414  // If there is some corner to be selected, assign it to m_CornerSelection
415  if( HitTestForCorner( aPosition, aAccuracy * 2, corner )
416  || HitTestForEdge( aPosition, aAccuracy, corner ) )
417  {
418  if( m_CornerSelection == nullptr )
420 
421  *m_CornerSelection = corner;
422  }
423 }
424 
425 bool ZONE::HitTestForCorner( const wxPoint& refPos, int aAccuracy,
426  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
427 {
428  return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, aAccuracy );
429 }
430 
431 
432 bool ZONE::HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const
433 {
435  return HitTestForCorner( refPos, aAccuracy, dummy );
436 }
437 
438 
439 bool ZONE::HitTestForEdge( const wxPoint& refPos, int aAccuracy,
440  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
441 {
442  return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, aAccuracy );
443 }
444 
445 
446 bool ZONE::HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const
447 {
449  return HitTestForEdge( refPos, aAccuracy, dummy );
450 }
451 
452 
453 bool ZONE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
454 {
455  // Calculate bounding box for zone
456  EDA_RECT bbox = GetBoundingBox();
457  bbox.Normalize();
458 
459  EDA_RECT arect = aRect;
460  arect.Normalize();
461  arect.Inflate( aAccuracy );
462 
463  if( aContained )
464  {
465  return arect.Contains( bbox );
466  }
467  else
468  {
469  // Fast test: if aBox is outside the polygon bounding box, rectangles cannot intersect
470  if( !arect.Intersects( bbox ) )
471  return false;
472 
473  int count = m_Poly->TotalVertices();
474 
475  for( int ii = 0; ii < count; ii++ )
476  {
477  auto vertex = m_Poly->CVertex( ii );
478  auto vertexNext = m_Poly->CVertex( ( ii + 1 ) % count );
479 
480  // Test if the point is within the rect
481  if( arect.Contains( ( wxPoint ) vertex ) )
482  return true;
483 
484  // Test if this edge intersects the rect
485  if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
486  return true;
487  }
488 
489  return false;
490  }
491 }
492 
493 
494 int ZONE::GetLocalClearance( wxString* aSource ) const
495 {
496  if( m_isRuleArea )
497  return 0;
498 
499  if( aSource )
500  *aSource = _( "zone" );
501 
502  return m_ZoneClearance;
503 }
504 
505 
506 bool ZONE::HitTestFilledArea( PCB_LAYER_ID aLayer, const wxPoint &aRefPos, int aAccuracy ) const
507 {
508  // Rule areas have no filled area, but it's generally nice to treat their interior as if it were
509  // filled so that people don't have to select them by their outline (which is min-width)
510  if( GetIsRuleArea() )
511  return m_Poly->Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1, aAccuracy );
512 
513  if( !m_FilledPolysList.count( aLayer ) )
514  return false;
515 
516  return m_FilledPolysList.at( aLayer ).Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1,
517  aAccuracy );
518 }
519 
520 
521 bool ZONE::HitTestCutout( const VECTOR2I& aRefPos, int* aOutlineIdx, int* aHoleIdx ) const
522 {
523  // Iterate over each outline polygon in the zone and then iterate over
524  // each hole it has to see if the point is in it.
525  for( int i = 0; i < m_Poly->OutlineCount(); i++ )
526  {
527  for( int j = 0; j < m_Poly->HoleCount( i ); j++ )
528  {
529  if( m_Poly->Hole( i, j ).PointInside( aRefPos ) )
530  {
531  if( aOutlineIdx )
532  *aOutlineIdx = i;
533 
534  if( aHoleIdx )
535  *aHoleIdx = j;
536 
537  return true;
538  }
539  }
540  }
541 
542  return false;
543 }
544 
545 
546 void ZONE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
547 {
548  EDA_UNITS units = aFrame->GetUserUnits();
549  wxString msg;
550 
551  if( GetIsRuleArea() )
552  msg = _( "Rule Area" );
553  else if( IsOnCopperLayer() )
554  msg = _( "Copper Zone" );
555  else
556  msg = _( "Non-copper Zone" );
557 
558  // Display Cutout instead of Outline for holes inside a zone (i.e. when num contour !=0).
559  // Check whether the selected corner is in a hole; i.e., in any contour but the first one.
560  if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
561  msg << wxT( " " ) << _( "Cutout" );
562 
563  aList.emplace_back( _( "Type" ), msg );
564 
565  if( GetIsRuleArea() )
566  {
567  msg.Empty();
568 
569  if( GetDoNotAllowVias() )
570  AccumulateDescription( msg, _( "No vias" ) );
571 
572  if( GetDoNotAllowTracks() )
573  AccumulateDescription( msg, _( "No tracks" ) );
574 
575  if( GetDoNotAllowPads() )
576  AccumulateDescription( msg, _( "No pads" ) );
577 
579  AccumulateDescription( msg, _( "No copper zones" ) );
580 
582  AccumulateDescription( msg, _( "No footprints" ) );
583 
584  if( !msg.IsEmpty() )
585  aList.emplace_back( MSG_PANEL_ITEM( _( "Restrictions" ), msg ) );
586  }
587  else if( IsOnCopperLayer() )
588  {
589  aList.emplace_back( _( "Net" ), UnescapeString( GetNetname() ) );
590 
591  aList.emplace_back( _( "NetClass" ), UnescapeString( GetNetClass()->GetName() ) );
592 
593  // Display priority level
594  aList.emplace_back( _( "Priority" ), wxString::Format( "%d", GetPriority() ) );
595  }
596 
597  if( IsLocked() )
598  aList.emplace_back( _( "Status" ), _( "Locked" ) );
599 
600  wxString layerDesc;
601  int count = 0;
602 
603  for( PCB_LAYER_ID layer : m_layerSet.Seq() )
604  {
605  if( count == 0 )
606  layerDesc = GetBoard()->GetLayerName( layer );
607 
608  count++;
609  }
610 
611  if( count > 1 )
612  layerDesc.Printf( _( "%s and %d more" ), layerDesc, count - 1 );
613 
614  aList.emplace_back( _( "Layer" ), layerDesc );
615 
616  if( !m_zoneName.empty() )
617  aList.emplace_back( _( "Name" ), m_zoneName );
618 
619  switch( m_fillMode )
620  {
621  case ZONE_FILL_MODE::POLYGONS: msg = _( "Solid" ); break;
622  case ZONE_FILL_MODE::HATCH_PATTERN: msg = _( "Hatched" ); break;
623  default: msg = _( "Unknown" ); break;
624  }
625 
626  aList.emplace_back( _( "Fill Mode" ), msg );
627 
628  msg = MessageTextFromValue( units, m_area, true, EDA_DATA_TYPE::AREA );
629  aList.emplace_back( _( "Filled Area" ), msg );
630 
631  wxString source;
632  int clearance = GetOwnClearance( GetLayer(), &source );
633 
634  aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
635  MessageTextFromValue( units, clearance ) ),
636  wxString::Format( _( "(from %s)" ), source ) );
637 
638  // Useful for statistics, especially when zones are complex the number of hatches
639  // and filled polygons can explain the display and DRC calculation time:
640  msg.Printf( wxT( "%d" ), (int) m_borderHatchLines.size() );
641  aList.emplace_back( MSG_PANEL_ITEM( _( "HatchBorder Lines" ), msg ) );
642 
643  PCB_LAYER_ID layer = m_layer;
644 
645  // NOTE: This brings in dependence on PCB_EDIT_FRAME to the qa tests, which isn't ideal.
646  // TODO: Figure out a way for items to know the active layer without the whole edit frame?
647 #if 0
648  if( PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( aFrame ) )
649  {
650  if( m_FilledPolysList.count( pcbframe->GetActiveLayer() ) )
651  layer = pcbframe->GetActiveLayer();
652  }
653 #endif
654 
655  if( !GetIsRuleArea() )
656  {
657  auto layer_it = m_FilledPolysList.find( layer );
658 
659  if( layer_it == m_FilledPolysList.end() )
660  layer_it = m_FilledPolysList.begin();
661 
662  if( layer_it != m_FilledPolysList.end() )
663  {
664  msg.Printf( wxT( "%d" ), layer_it->second.TotalVertices() );
665  aList.emplace_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg ) );
666  }
667  }
668 }
669 
670 
671 void ZONE::Move( const wxPoint& offset )
672 {
673  /* move outlines */
674  m_Poly->Move( offset );
675 
676  HatchBorder();
677 
678  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
679  pair.second.Move( offset );
680 
681  for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
682  {
683  for( SEG& seg : pair.second )
684  {
685  seg.A += VECTOR2I( offset );
686  seg.B += VECTOR2I( offset );
687  }
688  }
689 }
690 
691 
692 void ZONE::MoveEdge( const wxPoint& offset, int aEdge )
693 {
694  int next_corner;
695 
696  if( m_Poly->GetNeighbourIndexes( aEdge, nullptr, &next_corner ) )
697  {
698  m_Poly->SetVertex( aEdge, m_Poly->CVertex( aEdge ) + VECTOR2I( offset ) );
699  m_Poly->SetVertex( next_corner, m_Poly->CVertex( next_corner ) + VECTOR2I( offset ) );
700  HatchBorder();
701 
702  SetNeedRefill( true );
703  }
704 }
705 
706 
707 void ZONE::Rotate( const wxPoint& aCentre, double aAngle )
708 {
709  aAngle = -DECIDEG2RAD( aAngle );
710 
711  m_Poly->Rotate( aAngle, VECTOR2I( aCentre ) );
712  HatchBorder();
713 
714  /* rotate filled areas: */
715  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
716  pair.second.Rotate( aAngle, VECTOR2I( aCentre ) );
717 
718  for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
719  {
720  for( SEG& seg : pair.second )
721  {
722  wxPoint a( seg.A );
723  RotatePoint( &a, aCentre, aAngle );
724  seg.A = a;
725  wxPoint b( seg.B );
726  RotatePoint( &b, aCentre, aAngle );
727  seg.B = a;
728  }
729  }
730 }
731 
732 
733 void ZONE::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
734 {
735  Mirror( aCentre, aFlipLeftRight );
736  int copperLayerCount = GetBoard()->GetCopperLayerCount();
737 
738  if( GetIsRuleArea() )
739  SetLayerSet( FlipLayerMask( GetLayerSet(), copperLayerCount ) );
740  else
741  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
742 }
743 
744 
745 void ZONE::Mirror( const wxPoint& aMirrorRef, bool aMirrorLeftRight )
746 {
747  // ZONEs mirror about the x-axis (why?!?)
748  m_Poly->Mirror( aMirrorLeftRight, !aMirrorLeftRight, VECTOR2I( aMirrorRef ) );
749 
750  HatchBorder();
751 
752  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
753  pair.second.Mirror( aMirrorLeftRight, !aMirrorLeftRight, VECTOR2I( aMirrorRef ) );
754 
755  for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
756  {
757  for( SEG& seg : pair.second )
758  {
759  if( aMirrorLeftRight )
760  {
761  MIRROR( seg.A.x, aMirrorRef.x );
762  MIRROR( seg.B.x, aMirrorRef.x );
763  }
764  else
765  {
766  MIRROR( seg.A.y, aMirrorRef.y );
767  MIRROR( seg.B.y, aMirrorRef.y );
768  }
769  }
770  }
771 }
772 
773 
774 ZONE_CONNECTION ZONE::GetPadConnection( PAD* aPad, wxString* aSource ) const
775 {
776  if( aPad == nullptr || aPad->GetEffectiveZoneConnection() == ZONE_CONNECTION::INHERITED )
777  {
778  if( aSource )
779  *aSource = _( "zone" );
780 
781  return m_PadConnection;
782  }
783  else
784  {
785  return aPad->GetEffectiveZoneConnection( aSource );
786  }
787 }
788 
789 
790 void ZONE::RemoveCutout( int aOutlineIdx, int aHoleIdx )
791 {
792  // Ensure the requested cutout is valid
793  if( m_Poly->OutlineCount() < aOutlineIdx || m_Poly->HoleCount( aOutlineIdx ) < aHoleIdx )
794  return;
795 
796  SHAPE_POLY_SET cutPoly( m_Poly->Hole( aOutlineIdx, aHoleIdx ) );
797 
798  // Add the cutout back to the zone
800 
801  SetNeedRefill( true );
802 }
803 
804 
805 void ZONE::AddPolygon( const SHAPE_LINE_CHAIN& aPolygon )
806 {
807  wxASSERT( aPolygon.IsClosed() );
808 
809  // Add the outline as a new polygon in the polygon set
810  if( m_Poly->OutlineCount() == 0 )
811  m_Poly->AddOutline( aPolygon );
812  else
813  m_Poly->AddHole( aPolygon );
814 
815  SetNeedRefill( true );
816 }
817 
818 
819 void ZONE::AddPolygon( std::vector< wxPoint >& aPolygon )
820 {
821  if( aPolygon.empty() )
822  return;
823 
824  SHAPE_LINE_CHAIN outline;
825 
826  // Create an outline and populate it with the points of aPolygon
827  for( const wxPoint& pt : aPolygon)
828  outline.Append( pt );
829 
830  outline.SetClosed( true );
831 
832  AddPolygon( outline );
833 }
834 
835 
836 bool ZONE::AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication )
837 {
838  // Ensure the main outline exists:
839  if( m_Poly->OutlineCount() == 0 )
840  m_Poly->NewOutline();
841 
842  // If aHoleIdx >= 0, the corner musty be added to the hole, index aHoleIdx.
843  // (remember: the index of the first hole is 0)
844  // Return error if if does dot exist.
845  if( aHoleIdx >= m_Poly->HoleCount( 0 ) )
846  return false;
847 
848  m_Poly->Append( aPosition.x, aPosition.y, -1, aHoleIdx, aAllowDuplication );
849 
850  SetNeedRefill( true );
851 
852  return true;
853 }
854 
855 
856 wxString ZONE::GetSelectMenuText( EDA_UNITS aUnits ) const
857 {
858  wxString layerDesc;
859  int count = 0;
860 
861  for( PCB_LAYER_ID layer : m_layerSet.Seq() )
862  {
863  if( count == 0 )
864  layerDesc = GetBoard()->GetLayerName( layer );
865 
866  count++;
867  }
868 
869  if( count > 1 )
870  layerDesc.Printf( _( "%s and %d more" ), layerDesc, count - 1 );
871 
872  // Check whether the selected contour is a hole (contour index > 0)
873  if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
874  {
875  if( GetIsRuleArea() )
876  return wxString::Format( _( "Rule Area Cutout on %s" ), layerDesc );
877  else
878  return wxString::Format( _( "Zone Cutout on %s" ), layerDesc );
879  }
880  else
881  {
882  if( GetIsRuleArea() )
883  return wxString::Format( _( "Rule Area on %s" ), layerDesc );
884  else
885  return wxString::Format( _( "Zone %s on %s" ), GetNetnameMsg(), layerDesc );
886  }
887 }
888 
889 
891 {
892  return m_borderHatchPitch;
893 }
894 
895 
896 void ZONE::SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch,
897  bool aRebuildHatch )
898 {
899  SetHatchPitch( aHatchPitch );
900  m_borderStyle = aHatchStyle;
901 
902  if( aRebuildHatch )
903  HatchBorder();
904 }
905 
906 
907 void ZONE::SetHatchPitch( int aPitch )
908 {
909  m_borderHatchPitch = aPitch;
910 }
911 
912 
914 {
915  m_borderHatchLines.clear();
916 }
917 
918 
919 // Creates hatch lines inside the outline of the complex polygon
920 // sort function used in ::HatchBorder to sort points by descending wxPoint.x values
921 bool sortEndsByDescendingX( const VECTOR2I& ref, const VECTOR2I& tst )
922 {
923  return tst.x < ref.x;
924 }
925 
926 
928 {
929  UnHatchBorder();
930 
932  || m_borderHatchPitch == 0
933  || m_Poly->IsEmpty() )
934  {
935  return;
936  }
937 
938  // define range for hatch lines
939  int min_x = m_Poly->CVertex( 0 ).x;
940  int max_x = m_Poly->CVertex( 0 ).x;
941  int min_y = m_Poly->CVertex( 0 ).y;
942  int max_y = m_Poly->CVertex( 0 ).y;
943 
944  for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
945  {
946  if( iterator->x < min_x )
947  min_x = iterator->x;
948 
949  if( iterator->x > max_x )
950  max_x = iterator->x;
951 
952  if( iterator->y < min_y )
953  min_y = iterator->y;
954 
955  if( iterator->y > max_y )
956  max_y = iterator->y;
957  }
958 
959  // Calculate spacing between 2 hatch lines
960  int spacing;
961 
963  spacing = m_borderHatchPitch;
964  else
965  spacing = m_borderHatchPitch * 2;
966 
967  // set the "length" of hatch lines (the length on horizontal axis)
968  int hatch_line_len = m_borderHatchPitch;
969 
970  // To have a better look, give a slope depending on the layer
971  LAYER_NUM layer = GetLayer();
972  int slope_flag = (layer & 1) ? 1 : -1; // 1 or -1
973  double slope = 0.707106 * slope_flag; // 45 degrees slope
974  int max_a, min_a;
975 
976  if( slope_flag == 1 )
977  {
978  max_a = KiROUND( max_y - slope * min_x );
979  min_a = KiROUND( min_y - slope * max_x );
980  }
981  else
982  {
983  max_a = KiROUND( max_y - slope * max_x );
984  min_a = KiROUND( min_y - slope * min_x );
985  }
986 
987  min_a = (min_a / spacing) * spacing;
988 
989  // calculate an offset depending on layer number,
990  // for a better look of hatches on a multilayer board
991  int offset = (layer * 7) / 8;
992  min_a += offset;
993 
994  // loop through hatch lines
995  #define MAXPTS 200 // Usually we store only few values per one hatch line
996  // depending on the complexity of the zone outline
997 
998  static std::vector<VECTOR2I> pointbuffer;
999  pointbuffer.clear();
1000  pointbuffer.reserve( MAXPTS + 2 );
1001 
1002  for( int a = min_a; a < max_a; a += spacing )
1003  {
1004  // get intersection points for this hatch line
1005 
1006  // Note: because we should have an even number of intersections with the
1007  // current hatch line and the zone outline (a closed polygon,
1008  // or a set of closed polygons), if an odd count is found
1009  // we skip this line (should not occur)
1010  pointbuffer.clear();
1011 
1012  // Iterate through all vertices
1013  for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
1014  {
1015  double x, y;
1016  bool ok;
1017 
1018  SEG segment = *iterator;
1019 
1020  ok = FindLineSegmentIntersection( a, slope, segment.A.x, segment.A.y, segment.B.x,
1021  segment.B.y, x, y );
1022 
1023  if( ok )
1024  {
1025  VECTOR2I point( KiROUND( x ), KiROUND( y ) );
1026  pointbuffer.push_back( point );
1027  }
1028 
1029  if( pointbuffer.size() >= MAXPTS ) // overflow
1030  {
1031  wxASSERT( 0 );
1032  break;
1033  }
1034  }
1035 
1036  // ensure we have found an even intersection points count
1037  // because intersections are the ends of segments
1038  // inside the polygon(s) and a segment has 2 ends.
1039  // if not, this is a strange case (a bug ?) so skip this hatch
1040  if( pointbuffer.size() % 2 != 0 )
1041  continue;
1042 
1043  // sort points in order of descending x (if more than 2) to
1044  // ensure the starting point and the ending point of the same segment
1045  // are stored one just after the other.
1046  if( pointbuffer.size() > 2 )
1047  sort( pointbuffer.begin(), pointbuffer.end(), sortEndsByDescendingX );
1048 
1049  // creates lines or short segments inside the complex polygon
1050  for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
1051  {
1052  int dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
1053 
1054  // Push only one line for diagonal hatch,
1055  // or for small lines < twice the line length
1056  // else push 2 small lines
1058  || std::abs( dx ) < 2 * hatch_line_len )
1059  {
1060  m_borderHatchLines.emplace_back( SEG( pointbuffer[ip], pointbuffer[ ip + 1] ) );
1061  }
1062  else
1063  {
1064  double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
1065  slope = dy / dx;
1066 
1067  if( dx > 0 )
1068  dx = hatch_line_len;
1069  else
1070  dx = -hatch_line_len;
1071 
1072  int x1 = KiROUND( pointbuffer[ip].x + dx );
1073  int x2 = KiROUND( pointbuffer[ip + 1].x - dx );
1074  int y1 = KiROUND( pointbuffer[ip].y + dx * slope );
1075  int y2 = KiROUND( pointbuffer[ip + 1].y - dx * slope );
1076 
1077  m_borderHatchLines.emplace_back( SEG( pointbuffer[ip].x, pointbuffer[ip].y,
1078  x1, y1 ) );
1079 
1080  m_borderHatchLines.emplace_back( SEG( pointbuffer[ip+1].x, pointbuffer[ip+1].y,
1081  x2, y2 ) );
1082  }
1083  }
1084  }
1085 }
1086 
1087 
1089 {
1090  return Mils2iu( 20 );
1091 }
1092 
1093 
1095 {
1096  return BITMAPS::add_zone;
1097 }
1098 
1099 
1101 {
1102  assert( aImage->Type() == PCB_ZONE_T || aImage->Type() == PCB_FP_ZONE_T );
1103 
1104  std::swap( *((ZONE*) this), *((ZONE*) aImage) );
1105 }
1106 
1107 
1109 {
1110  if( aLayer == UNDEFINED_LAYER )
1111  {
1112  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
1113  pair.second.CacheTriangulation();
1114  }
1115  else
1116  {
1117  if( m_FilledPolysList.count( aLayer ) )
1119  }
1120 }
1121 
1122 
1123 bool ZONE::IsIsland( PCB_LAYER_ID aLayer, int aPolyIdx ) const
1124 {
1125  if( GetNetCode() < 1 )
1126  return true;
1127 
1128  if( !m_insulatedIslands.count( aLayer ) )
1129  return false;
1130 
1131  return m_insulatedIslands.at( aLayer ).count( aPolyIdx );
1132 }
1133 
1134 
1135 void ZONE::GetInteractingZones( PCB_LAYER_ID aLayer, std::vector<ZONE*>* aZones ) const
1136 {
1137  int epsilon = Millimeter2iu( 0.001 );
1138 
1139  for( ZONE* candidate : GetBoard()->Zones() )
1140  {
1141  if( candidate == this )
1142  continue;
1143 
1144  if( !candidate->GetLayerSet().test( aLayer ) )
1145  continue;
1146 
1147  if( candidate->GetIsRuleArea() )
1148  continue;
1149 
1150  if( candidate->GetNetCode() != GetNetCode() )
1151  continue;
1152 
1153  for( auto iter = m_Poly->CIterate(); iter; iter++ )
1154  {
1155  if( candidate->m_Poly->Collide( iter.Get(), epsilon ) )
1156  {
1157  aZones->push_back( candidate );
1158  break;
1159  }
1160  }
1161  }
1162 }
1163 
1164 
1166  SHAPE_POLY_SET* aBoardOutline,
1167  SHAPE_POLY_SET* aSmoothedPolyWithApron ) const
1168 {
1169  if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations will not like it ...
1170  return false;
1171 
1172  if( GetIsRuleArea() )
1173  {
1174  // We like keepouts just the way they are....
1175  aSmoothedPoly = *m_Poly;
1176  return true;
1177  }
1178 
1179  BOARD* board = GetBoard();
1180  int maxError = ARC_HIGH_DEF;
1181  bool keepExternalFillets = false;
1182 
1183  if( board )
1184  {
1185  BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
1186 
1187  maxError = bds.m_MaxError;
1188  keepExternalFillets = bds.m_ZoneKeepExternalFillets;
1189  }
1190 
1191  auto smooth = [&]( SHAPE_POLY_SET& aPoly )
1192  {
1193  switch( m_cornerSmoothingType )
1194  {
1196  aPoly = aPoly.Chamfer( (int) m_cornerRadius );
1197  break;
1198 
1200  {
1201  aPoly = aPoly.Fillet( (int) m_cornerRadius, maxError );
1202  break;
1203  }
1204 
1205  default:
1206  break;
1207  }
1208  };
1209 
1210  std::vector<ZONE*> interactingZones;
1211  GetInteractingZones( aLayer, &interactingZones );
1212 
1213  SHAPE_POLY_SET* maxExtents = m_Poly;
1214  SHAPE_POLY_SET withFillets;
1215 
1216  aSmoothedPoly = *m_Poly;
1217 
1218  // Should external fillets (that is, those applied to concave corners) be kept? While it
1219  // seems safer to never have copper extend outside the zone outline, 5.1.x and prior did
1220  // indeed fill them so we leave the mode available.
1221  if( keepExternalFillets )
1222  {
1223  withFillets = *m_Poly;
1224  smooth( withFillets );
1225  withFillets.BooleanAdd( *m_Poly, SHAPE_POLY_SET::PM_FAST );
1226  maxExtents = &withFillets;
1227  }
1228 
1229  for( ZONE* zone : interactingZones )
1230  aSmoothedPoly.BooleanAdd( *zone->Outline(), SHAPE_POLY_SET::PM_FAST );
1231 
1232  if( aBoardOutline )
1233  {
1234  SHAPE_POLY_SET poly = *aBoardOutline;
1236  }
1237 
1238  smooth( aSmoothedPoly );
1239 
1240  if( aSmoothedPolyWithApron )
1241  {
1242  SHAPE_POLY_SET poly = *maxExtents;
1243  poly.Inflate( m_ZoneMinThickness, 64 );
1244  *aSmoothedPolyWithApron = aSmoothedPoly;
1245  aSmoothedPolyWithApron->BooleanIntersection( poly, SHAPE_POLY_SET::PM_FAST );
1246  }
1247 
1248  aSmoothedPoly.BooleanIntersection( *maxExtents, SHAPE_POLY_SET::PM_FAST );
1249 
1250  return true;
1251 }
1252 
1253 
1255 {
1256  m_area = 0.0;
1257 
1258  // Iterate over each outline polygon in the zone and then iterate over
1259  // each hole it has to compute the total area.
1260  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
1261  {
1262  SHAPE_POLY_SET& poly = pair.second;
1263 
1264  for( int i = 0; i < poly.OutlineCount(); i++ )
1265  {
1266  m_area += poly.Outline( i ).Area();
1267 
1268  for( int j = 0; j < poly.HoleCount( i ); j++ )
1269  m_area -= poly.Hole( i, j ).Area();
1270  }
1271  }
1272 
1273  return m_area;
1274 }
1275 
1276 
1277 void ZONE::TransformSmoothedOutlineToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearance,
1278  SHAPE_POLY_SET* aBoardOutline ) const
1279 {
1280  // Creates the zone outline polygon (with holes if any)
1281  SHAPE_POLY_SET polybuffer;
1282  BuildSmoothedPoly( polybuffer, GetLayer(), aBoardOutline );
1283 
1284  // Calculate the polygon with clearance
1285  // holes are linked to the main outline, so only one polygon is created.
1286  if( aClearance )
1287  {
1288  BOARD* board = GetBoard();
1289  int maxError = ARC_HIGH_DEF;
1290 
1291  if( board )
1292  maxError = board->GetDesignSettings().m_MaxError;
1293 
1294  int segCount = GetArcToSegmentCount( aClearance, maxError, 360.0 );
1295  polybuffer.Inflate( aClearance, segCount );
1296  }
1297 
1298  polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
1299  aCornerBuffer.Append( polybuffer );
1300 }
1301 
1302 
1303 bool ZONE::IsKeepout() const
1304 {
1307 }
1308 
1309 
1310 bool ZONE::KeepoutAll() const
1311 {
1314 }
1315 
1316 
1318  ZONE( aParent, true )
1319 {
1320  // in a footprint, net classes are not managed.
1321  // so set the net to NETINFO_LIST::ORPHANED_ITEM
1322  SetNetCode( -1, true );
1323 }
1324 
1325 
1326 FP_ZONE::FP_ZONE( const FP_ZONE& aZone ) :
1327  ZONE( aZone.GetParent(), true )
1328 {
1329  InitDataFromSrcInCopyCtor( aZone );
1330 }
1331 
1332 
1334 {
1335  ZONE::operator=( aOther );
1336  return *this;
1337 }
1338 
1339 
1341 {
1342  return new FP_ZONE( *this );
1343 }
1344 
1345 
1346 double FP_ZONE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
1347 {
1348  constexpr double HIDE = (double)std::numeric_limits<double>::max();
1349 
1350  if( !aView )
1351  return 0;
1352 
1353  if( !aView->IsLayerVisible( LAYER_ZONES ) )
1354  return HIDE;
1355 
1356  bool flipped = GetParent() && GetParent()->GetLayer() == B_Cu;
1357 
1358  // Handle Render tab switches
1359  if( !flipped && !aView->IsLayerVisible( LAYER_MOD_FR ) )
1360  return HIDE;
1361 
1362  if( flipped && !aView->IsLayerVisible( LAYER_MOD_BK ) )
1363  return HIDE;
1364 
1365  // Other layers are shown without any conditions
1366  return 0.0;
1367 }
1368 
1369 
1370 std::shared_ptr<SHAPE> ZONE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
1371 {
1372  std::shared_ptr<SHAPE> shape;
1373 
1374  if( m_FilledPolysList.find( aLayer ) == m_FilledPolysList.end() )
1375  {
1376  shape = std::make_shared<SHAPE_NULL>();
1377  }
1378  else
1379  {
1380  shape.reset( m_FilledPolysList.at( aLayer ).Clone() );
1381  }
1382 
1383  return shape;
1384 }
1385 
1386 
1387 static struct ZONE_DESC
1388 {
1390  {
1392  .Map( ZONE_CONNECTION::INHERITED, _HKI( "Inherited" ) )
1393  .Map( ZONE_CONNECTION::NONE, _HKI( "None" ) )
1394  .Map( ZONE_CONNECTION::THERMAL, _HKI( "Thermal reliefs" ) )
1395  .Map( ZONE_CONNECTION::FULL, _HKI( "Solid" ) )
1396  .Map( ZONE_CONNECTION::THT_THERMAL, _HKI( "Reliefs for PTH" ) );
1397 
1399  REGISTER_TYPE( ZONE );
1401  propMgr.AddProperty( new PROPERTY<ZONE, unsigned>( _HKI( "Priority" ),
1403  //propMgr.AddProperty( new PROPERTY<ZONE, bool>( "Filled",
1404  //&ZONE::SetIsFilled, &ZONE::IsFilled ) );
1405  propMgr.AddProperty( new PROPERTY<ZONE, wxString>( _HKI( "Name" ),
1407  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Clearance Override" ),
1410  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Min Width" ),
1413  propMgr.AddProperty( new PROPERTY_ENUM<ZONE, ZONE_CONNECTION>( _HKI( "Pad Connections" ),
1415  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thermal Relief Gap" ),
1418  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thermal Relief Width" ),
1421  }
1422 } _ZONE_DESC;
1423 
ZONE_BORDER_DISPLAY_STYLE m_borderStyle
Definition: zone.h:924
int TotalVertices() const
Delete aIdx-th polygon from the set.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: zone.h:520
Virtual layers for stacking zones and tracks on a given copper layer.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: zone.cpp:1094
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:41
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:238
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
bool m_doNotAllowFootprints
Definition: zone.h:847
void SetCornerRadius(unsigned int aRadius)
Definition: zone.cpp:361
void CacheTriangulation(PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Create a list of triangles that "fill" the solid areas used for instance to draw these solid areas on...
Definition: zone.cpp:1108
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
unsigned int m_cornerRadius
Definition: zone.h:822
void TransformSmoothedOutlineToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearance, SHAPE_POLY_SET *aBoardOutline) const
Convert the outlines shape to a polygon with no holes inflated (optional) by max( aClearanceValue,...
Definition: zone.cpp:1277
#define TYPE_HASH(x)
Definition: property.h:59
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount)
Calculate the mask layer when flipping a footprint.
Definition: lset.cpp:567
ENUM_TO_WXANY(ZONE_CONNECTION)
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
Definition: zone.cpp:790
void SetZoneName(const wxString &aName)
Definition: zone.h:130
bool GetDoNotAllowFootprints() const
Definition: zone.h:735
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:360
void SetDoNotAllowTracks(bool aEnable)
Definition: zone.h:742
void UnHatchBorder()
Clear the zone's hatch.
Definition: zone.cpp:913
ZONE_FILL_MODE m_fillMode
How to fill areas:
Definition: zone.h:882
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Return an iterator object, for the aOutline-th outline in the set (with holes).
int m_ZoneClearance
Definition: zone.h:850
unsigned GetPriority() const
Definition: zone.h:122
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
NETCLASS * GetNetClass() const override
Return the NETCLASS for this item.
Definition: zone.h:88
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:730
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
int m_cornerSmoothingType
Definition: zone.h:821
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:896
SHAPE_POLY_SET * m_Poly
Outline of the zone.
Definition: zone.h:820
int GetBorderHatchPitch() const
HatchBorder related methods.
Definition: zone.cpp:890
wxString m_zoneName
An optional unique name for this zone, used for identifying it in DRC checking.
Definition: zone.h:825
Control for copper zone opacity/visibility (color ignored)
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the aGlobalIndex-th vertex in the poly set.
int m_hatchSmoothingLevel
Definition: zone.h:886
void SetLayerSet(LSET aLayerSet) override
Definition: zone.cpp:246
ZONE_CONNECTION m_PadConnection
Definition: zone.h:849
bool GetDoNotAllowVias() const
Definition: zone.h:732
double m_area
Definition: zone.h:933
bool m_doNotAllowTracks
Definition: zone.h:845
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:521
bool IsEmpty() const
~ZONE()
Definition: zone.cpp:100
long long int m_minIslandArea
When island removal mode is set to AREA, islands below this area will be removed.
Definition: zone.h:860
double m_hatchOrientation
Definition: zone.h:885
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:291
show footprints on back
static ENUM_MAP< T > & Instance()
Definition: property.h:510
bool CommonLayerExists(const LSET aLayerSet) const
Test if this zone shares a common layer with the given layer set.
Definition: zone.cpp:230
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the aIndex-th subpolygon in the set.
std::map< PCB_LAYER_ID, std::set< int > > m_insulatedIslands
For each layer, a set of insulated islands that were not removed.
Definition: zone.h:929
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aBoardOutline, SHAPE_POLY_SET *aSmoothedPolyWithApron=nullptr) const
Definition: zone.cpp:1165
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition: zone.cpp:316
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
int GetEffectiveThermalGap(wxString *aSource=nullptr) const
Return the effective thermal gap having resolved any inheritance.
Definition: pad.cpp:832
double Area(bool aAbsolute=true) const
Return the area of this chain.
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:481
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
The base class for create windows for drawing purpose.
MD5_HASH GetHashValue(PCB_LAYER_ID aLayer)
Definition: zone.cpp:382
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: zone.cpp:546
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
virtual bool IsLocked() const
Definition: board_item.cpp:65
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
void SetPriority(unsigned aPriority)
Definition: zone.h:117
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:588
ZONE(BOARD_ITEM_CONTAINER *parent, bool aInFP=false)
The ctor to build ZONE, but compatible with FP_ZONE requirement.
Definition: zone.cpp:44
int m_hatchThickness
Definition: zone.h:883
#define REGISTER_TYPE(x)
Definition: property_mgr.h:248
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const wxPoint &aRefPos, int aAccuracy=0) const
Test if the given wxPoint is within the bounds of a filled area of this zone.
Definition: zone.cpp:506
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
LSET m_layerSet
Definition: zone.h:827
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
Definition: zone.cpp:1100
bool HitTestForCorner(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Test if the given wxPoint is near a corner.
Definition: zone.cpp:425
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: zone.cpp:733
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both)
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
bool m_doNotAllowVias
Definition: zone.h:844
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
void SetIsRuleArea(bool aEnable)
Definition: zone.h:739
std::map< PCB_LAYER_ID, ZONE_SEGMENT_FILL > m_FillSegmList
Segments used to fill the zone (#m_FillMode ==1 ), when fill zone by segment is used.
Definition: zone.h:904
show footprints on front
int GetThermalReliefGap() const
Definition: zone.h:190
bool GetNeighbourIndexes(int aGlobalIndex, int *aPrevious, int *aNext)
Return the global indexes of the previous and the next corner of the aGlobalIndex-th corner of a cont...
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
int GetEffectiveThermalSpokeWidth(wxString *aSource=nullptr) const
Return the effective thermal spoke width having resolved any inheritance.
Definition: pad.cpp:813
void Rotate(const wxPoint &aCentre, double aAngle) override
Move the outlines.
Definition: zone.cpp:707
void SetVertex(const VERTEX_INDEX &aIndex, const VECTOR2I &aPos)
Accessor function to set the position of a specific point.
void GetInteractingZones(PCB_LAYER_ID aLayer, std::vector< ZONE * > *aZones) const
Some intersecting zones, despite being on the same layer with the same net, cannot be merged due to o...
Definition: zone.cpp:1135
bool HitTestCutout(const VECTOR2I &aRefPos, int *aOutlineIdx=nullptr, int *aHoleIdx=nullptr) const
Test if the given point is contained within a cutout of the zone.
Definition: zone.cpp:521
std::map< PCB_LAYER_ID, bool > m_fillFlags
Definition: zone.h:919
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
Definition: kicad_string.h:316
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
bool GetDoNotAllowPads() const
Definition: zone.h:734
void MoveEdge(const wxPoint &offset, int aEdge)
Move the outline Edge.
Definition: zone.cpp:692
PCB_LAYER_ID
A quick note on layer IDs:
Display value expressed in distance units (mm/inch)
Definition: property.h:53
bool GetDoNotAllowCopperPour() const
Definition: zone.h:731
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: zone.cpp:297
LSET is a set of PCB_LAYER_IDs.
pads are covered by copper
int GetLocalClearance() const
Definition: zone.h:157
int GetMinThickness() const
Definition: zone.h:241
const EDA_RECT GetBoundingBox() const override
Definition: zone.cpp:322
MD5_HASH GetHash() const
void Move(const VECTOR2I &aVector) override
bool IsClosed() const override
static int GetDefaultHatchPitch()
Definition: zone.cpp:1088
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
void SetDoNotAllowPads(bool aEnable)
Definition: zone.h:743
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
Definition: zone.cpp:927
ITERATOR IterateWithHoles(int aOutline)
Represent a set of closed polygons.
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: zone.cpp:1370
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if a point is near an outline edge or a corner of this zone.
Definition: zone.cpp:400
SHAPE_LINE_CHAIN & Outline(int aIndex)
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: zone.cpp:218
void SetSelectedCorner(int aCorner)
Definition: zone.h:282
ZONE_CONNECTION GetEffectiveZoneConnection(wxString *aSource=nullptr) const
Return the zone connection in effect (either locally overridden or overridden in the parent footprint...
Definition: pad.cpp:792
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:51
int GetLocalFlags() const
Definition: zone.h:302
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
bool GetDoNotAllowTracks() const
Definition: zone.h:733
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
int m_thermalReliefGap
Definition: zone.h:872
bool m_hv45
Definition: zone.h:931
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:710
void InitDataFromSrcInCopyCtor(const ZONE &aZone)
Copy aZone data to me.
Definition: zone.cpp:107
SHAPE_POLY_SET::VERTEX_INDEX * m_CornerSelection
The index of the corner being moved or nullptr if no corner is selected.
Definition: zone.h:896
#define _(s)
ISLAND_REMOVAL_MODE m_islandRemovalMode
Definition: zone.h:854
void SetDoNotAllowVias(bool aEnable)
Definition: zone.h:741
a few functions useful in geometry calculations.
#define MAXPTS
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
bool sortEndsByDescendingX(const VECTOR2I &ref, const VECTOR2I &tst)
Definition: zone.cpp:921
static SHAPE_POLY_SET g_nullPoly
Definition: zone.cpp:379
void SetMinThickness(int aMinThickness)
Definition: zone.h:242
std::map< PCB_LAYER_ID, MD5_HASH > m_filledPolysHash
A hash value used in zone filling calculations to see if the filled areas are up to date.
Definition: zone.h:922
virtual const ZONE_SETTINGS & GetZoneSettings() const
Fetch the zone settings for this container.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union between a and b, store the result in it self For aFastMode meaning,...
int NewOutline()
Creates a new hole in a given outline.
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
int m_ZoneMinThickness
Definition: zone.h:851
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:180
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Return the area of this poly set.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Thermal relief only for THT pads.
std::map< PCB_LAYER_ID, SHAPE_POLY_SET > m_RawPolysList
Definition: zone.h:915
int LAYER_NUM
This can be replaced with int and removed.
wxString GetNetnameMsg() const
void BuildHashValue(PCB_LAYER_ID aLayer)
Build the hash value of m_FilledPolysList, and store it internally in m_filledPolysHash.
Definition: zone.cpp:391
bool m_isRuleArea
Definition: zone.h:838
void Inflate(int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Perform outline inflation/deflation.
Some functions to handle hotkeys in KiCad.
void Move(const wxPoint &offset) override
Move the outlines.
Definition: zone.cpp:671
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int m_borderHatchPitch
Definition: zone.h:925
Definition: seg.h:40
EDA_UNITS
Definition: eda_units.h:38
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
bool IsKeepout() const
Definition: zone.cpp:1303
Use thermal relief for pads.
std::vector< SEG > m_borderHatchLines
Definition: zone.h:926
void SetLocalFlags(int aFlags)
Definition: zone.h:303
bool CollideEdge(const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0) const
Check whether aPoint collides with any edge of any of the contours of the polygon.
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: zone.h:239
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: zone.cpp:836
int m_hatchBorderAlgorithm
Definition: zone.h:892
bool HitTestForEdge(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Test if the given wxPoint is near a segment defined by 2 corners.
Definition: zone.cpp:439
ZONE_DESC()
Definition: zone.cpp:1389
wxPoint GetPosition() const override
Definition: zone.cpp:212
bool m_isFilled
True when a zone was filled, false after deleting the filled areas.
Definition: zone.h:863
FP_ZONE & operator=(const FP_ZONE &aOther)
Definition: zone.cpp:1333
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetDoNotAllowCopperPour(bool aEnable)
Definition: zone.h:740
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
Definition: zone.cpp:1123
Represent a polyline (an zero-thickness chain of connected line segments).
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
void SetHatchPitch(int aPitch)
Set the hatch pitch parameter for the zone.
Definition: zone.cpp:907
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:222
int m_hatchGap
Definition: zone.h:884
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
int GetCopperLayerCount() const
Definition: board.cpp:453
class ZONE, managed by a footprint
Definition: typeinfo.h:94
VECTOR2I A
Definition: seg.h:48
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: zone.h:560
Handle the component boundary box.
Definition: eda_rect.h:42
double DECIDEG2RAD(double deg)
Definition: trigo.h:235
FP_ZONE(BOARD_ITEM_CONTAINER *aParent)
Definition: zone.cpp:1317
The main frame for Pcbnew.
void Mirror(const wxPoint &aMirrorRef, bool aMirrorLeftRight)
Mirror the outlines relative to a given horizontal axis the layer is not changed.
Definition: zone.cpp:745
bool IsOnCopperLayer() const override
Definition: zone.cpp:224
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:73
bool m_doNotAllowCopperPour
Definition: zone.h:843
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
Pads are not covered.
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: zone.cpp:182
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
PCB_LAYER_ID m_layer
Definition: board_item.h:352
int m_fillVersion
Definition: zone.h:852
void SetThermalReliefGap(int aThermalReliefGap)
Definition: zone.h:183
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.
Definition: zone_settings.h:46
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: zone.cpp:238
void SetNeedRefill(bool aNeedRefill)
Definition: zone.h:235
double m_hatchHoleMinArea
Definition: zone.h:891
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
Definition: zone.cpp:1254
void SetLocalClearance(int aClearance)
Definition: zone.h:158
bool m_needRefill
False when a zone was refilled, true after changes in zone params.
Definition: zone.h:870
void AddPolygon(std::vector< wxPoint > &aPolygon)
Add a polygon to the zone outline.
Definition: zone.cpp:819
int GetThermalReliefSpokeWidth() const
Definition: zone.h:200
Abstract interface for BOARD_ITEMs capable of storing other items inside.
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
ZONE & operator=(const ZONE &aOther)
Definition: zone.cpp:90
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: zone.cpp:856
Definition: pad.h:57
bool UnFill()
Removes the zone filling.
Definition: zone.cpp:188
wxString GetZoneName() const
Definition: zone.h:129
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: zone.cpp:1346
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
bool m_forceVisible
Definition: eda_item.h:480
static constexpr int Millimeter2iu(double mm)
#define _HKI(x)
std::map< PCB_LAYER_ID, SHAPE_POLY_SET > m_FilledPolysList
Definition: zone.h:914
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: zone.cpp:308
unsigned m_priority
Definition: zone.h:833
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
double m_hatchSmoothingValue
Definition: zone.h:890
A specialization of ZONE for use in footprints.
Definition: zone.h:943
bool CollideVertex(const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0) const
Check whether aPoint collides with any vertex of any of the contours of the polygon.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
int m_thermalReliefSpokeWidth
Definition: zone.h:873
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
static struct ZONE_DESC _ZONE_DESC
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:744
bool GetFilledPolysUseThickness() const
Definition: zone.h:686
bool KeepoutAll() const
Definition: zone.cpp:1310
Container for design settings for a BOARD object.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:404
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition: zone.h:193
bool m_doNotAllowPads
Definition: zone.h:846
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: zone.cpp:1340
VECTOR2I B
Definition: seg.h:49