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 <zone.h>
35 #include <kicad_string.h>
36 #include <math_for_graphics.h>
39 #include <trigo.h>
40 #include <i18n_utility.h>
41 
42 ZONE::ZONE( BOARD_ITEM_CONTAINER* aParent, bool aInFP ) :
43  BOARD_CONNECTED_ITEM( aParent, aInFP ? PCB_FP_ZONE_T : PCB_ZONE_T ),
44  m_area( 0.0 )
45 {
46  m_CornerSelection = nullptr; // no corner is selected
47  m_isFilled = false; // fill status : true when the zone is filled
51  m_hv45 = false;
52  m_hatchThickness = 0;
53  m_hatchGap = 0;
54  m_hatchOrientation = 0.0;
55  m_hatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
56  m_hatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
57  // used only if m_hatchSmoothingLevel > 0
58  m_hatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
59  m_hatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
60  m_priority = 0;
62  SetIsRuleArea( aInFP ); // Zones living in footprints have the rule area option
63  SetDoNotAllowCopperPour( false ); // has meaning only if m_isRuleArea == true
64  SetDoNotAllowVias( true ); // has meaning only if m_isRuleArea == true
65  SetDoNotAllowTracks( true ); // has meaning only if m_isRuleArea == true
66  SetDoNotAllowPads( true ); // has meaning only if m_isRuleArea == true
67  SetDoNotAllowFootprints( false ); // has meaning only if m_isRuleArea == true
68  m_cornerRadius = 0;
69  SetLocalFlags( 0 ); // flags temporary used in zone calculations
70  m_Poly = new SHAPE_POLY_SET(); // Outlines
71  m_fillVersion = 5; // set the "old" way to build filled polygon areas (< 6.0.x)
73  aParent->GetZoneSettings().ExportSetting( *this );
74 
75  m_needRefill = false; // True only after some edition.
76 }
77 
78 
79 ZONE::ZONE( const ZONE& aZone )
80  : BOARD_CONNECTED_ITEM( aZone ),
81  m_Poly( nullptr ),
82  m_CornerSelection( nullptr )
83 {
85 }
86 
87 
88 ZONE& ZONE::operator=( const ZONE& aOther )
89 {
91 
92  InitDataFromSrcInCopyCtor( aOther );
93 
94  return *this;
95 }
96 
97 
99 {
100  delete m_Poly;
101  delete m_CornerSelection;
102 }
103 
104 
106 {
107  // members are expected non initialize in this.
108  // InitDataFromSrcInCopyCtor() is expected to be called
109  // only from a copy constructor.
110 
111  // Copy only useful EDA_ITEM flags:
112  m_flags = aZone.m_flags;
114 
115  // Replace the outlines for aZone outlines.
116  delete m_Poly;
117  m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
118 
121  m_zoneName = aZone.m_zoneName;
122  m_priority = aZone.m_priority;
123  m_isRuleArea = aZone.m_isRuleArea;
124  SetLayerSet( aZone.GetLayerSet() );
125 
131 
133  m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
138 
139  m_isFilled = aZone.m_isFilled;
140  m_needRefill = aZone.m_needRefill;
141 
144 
145  m_fillMode = aZone.m_fillMode; // solid vs. hatched
147  m_hatchGap = aZone.m_hatchGap;
153 
154  // For corner moving, corner index to drag, or nullptr if no selection
155  delete m_CornerSelection;
156  m_CornerSelection = nullptr;
157 
158  for( PCB_LAYER_ID layer : aZone.GetLayerSet().Seq() )
159  {
160  m_FilledPolysList[layer] = aZone.m_FilledPolysList.at( layer );
161  m_RawPolysList[layer] = aZone.m_RawPolysList.at( layer );
162  m_filledPolysHash[layer] = aZone.m_filledPolysHash.at( layer );
163  m_FillSegmList[layer] = aZone.m_FillSegmList.at( layer ); // vector <> copy
164  m_insulatedIslands[layer] = aZone.m_insulatedIslands.at( layer );
165  }
166 
170 
171  SetLocalFlags( aZone.GetLocalFlags() );
172 
173  m_netinfo = aZone.m_netinfo;
174 
175  m_hv45 = aZone.m_hv45;
176  m_area = aZone.m_area;
177 }
178 
179 
181 {
182  return new ZONE( *this );
183 }
184 
185 
187 {
188  bool change = false;
189 
190  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
191  {
192  change |= !pair.second.IsEmpty();
193  m_insulatedIslands[pair.first].clear();
194  pair.second.RemoveAllContours();
195  }
196 
197  for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
198  {
199  change |= !pair.second.empty();
200  pair.second.clear();
201  }
202 
203  m_isFilled = false;
204  m_fillFlags.clear();
205 
206  return change;
207 }
208 
209 
210 wxPoint ZONE::GetPosition() const
211 {
212  return (wxPoint) GetCornerPosition( 0 );
213 }
214 
215 
217 {
218  return BOARD_ITEM::GetLayer();
219 }
220 
221 
223 {
224  return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
225 }
226 
227 
228 bool ZONE::CommonLayerExists( const LSET aLayerSet ) const
229 {
230  LSET common = GetLayerSet() & aLayerSet;
231 
232  return common.count() > 0;
233 }
234 
235 
237 {
238  SetLayerSet( LSET( aLayer ) );
239 
240  m_layer = aLayer;
241 }
242 
243 
244 void ZONE::SetLayerSet( LSET aLayerSet )
245 {
246  if( GetIsRuleArea() )
247  {
248  // Rule areas can only exist on copper layers
249  aLayerSet &= LSET::AllCuMask();
250  }
251 
252  if( aLayerSet.count() == 0 )
253  return;
254 
255  if( m_layerSet != aLayerSet )
256  {
257  SetNeedRefill( true );
258 
259  UnFill();
260 
261  m_FillSegmList.clear();
262  m_FilledPolysList.clear();
263  m_RawPolysList.clear();
264  m_filledPolysHash.clear();
265  m_insulatedIslands.clear();
266 
267  for( PCB_LAYER_ID layer : aLayerSet.Seq() )
268  {
269  m_FillSegmList[layer] = {};
270  m_FilledPolysList[layer] = {};
271  m_RawPolysList[layer] = {};
272  m_filledPolysHash[layer] = {};
273  m_insulatedIslands[layer] = {};
274  }
275  }
276 
277  m_layerSet = aLayerSet;
278 
279  // Set the single layer parameter. For zones that can be on many layers, this parameter
280  // is arbitrary at best, but some code still uses it.
281  // Priority is F_Cu then B_Cu then to the first selected layer
282  m_layer = aLayerSet.Seq()[0];
283 
284  if( m_layer != F_Cu && aLayerSet[B_Cu] )
285  m_layer = B_Cu;
286 }
287 
288 
290 {
291  return m_layerSet;
292 }
293 
294 
295 void ZONE::ViewGetLayers( int aLayers[], int& aCount ) const
296 {
297  LSEQ layers = m_layerSet.Seq();
298 
299  for( unsigned int idx = 0; idx < layers.size(); idx++ )
300  aLayers[idx] = LAYER_ZONE_START + layers[idx];
301 
302  aCount = layers.size();
303 }
304 
305 
306 double ZONE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
307 {
308  constexpr double HIDE = std::numeric_limits<double>::max();
309 
310  return aView->IsLayerVisible( LAYER_ZONES ) ? 0.0 : HIDE;
311 }
312 
313 
314 bool ZONE::IsOnLayer( PCB_LAYER_ID aLayer ) const
315 {
316  return m_layerSet.test( aLayer );
317 }
318 
319 
321 {
322  auto bb = m_Poly->BBox();
323 
324  EDA_RECT ret( (wxPoint) bb.GetOrigin(), wxSize( bb.GetWidth(), bb.GetHeight() ) );
325 
326  return ret;
327 }
328 
329 
330 int ZONE::GetThermalReliefGap( PAD* aPad, wxString* aSource ) const
331 {
332  if( aPad->GetEffectiveThermalGap() == 0 )
333  {
334  if( aSource )
335  *aSource = _( "zone" );
336 
337  return m_thermalReliefGap;
338  }
339 
340  return aPad->GetEffectiveThermalGap( aSource );
341 
342 }
343 
344 
345 int ZONE::GetThermalReliefSpokeWidth( PAD* aPad, wxString* aSource ) const
346 {
347  if( aPad->GetEffectiveThermalSpokeWidth() == 0 )
348  {
349  if( aSource )
350  *aSource = _( "zone" );
351 
353  }
354 
355  return aPad->GetEffectiveThermalSpokeWidth( aSource );
356 }
357 
358 
359 void ZONE::SetCornerRadius( unsigned int aRadius )
360 {
361  if( m_cornerRadius != aRadius )
362  SetNeedRefill( true );
363 
364  m_cornerRadius = aRadius;
365 }
366 
367 
369 {
370  if( ADVANCED_CFG::GetCfg().m_DebugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
371  return false;
372 
374 }
375 
376 
378 
379 
381 {
382  if( !m_filledPolysHash.count( aLayer ) )
383  return g_nullPoly.GetHash();
384  else
385  return m_filledPolysHash.at( aLayer );
386 }
387 
388 
390 {
391  if( !m_FilledPolysList.count( aLayer ) )
393  else
394  m_filledPolysHash[aLayer] = m_FilledPolysList.at( aLayer ).GetHash();
395 }
396 
397 
398 bool ZONE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
399 {
400  // Normally accuracy is zoom-relative, but for the generic HitTest we just use
401  // a fixed (small) value.
402  int accuracy = std::max( aAccuracy, Millimeter2iu( 0.1 ) );
403 
404  return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
405 }
406 
407 
408 void ZONE::SetSelectedCorner( const wxPoint& aPosition, int aAccuracy )
409 {
411 
412  // If there is some corner to be selected, assign it to m_CornerSelection
413  if( HitTestForCorner( aPosition, aAccuracy * 2, corner )
414  || HitTestForEdge( aPosition, aAccuracy, corner ) )
415  {
416  if( m_CornerSelection == nullptr )
418 
419  *m_CornerSelection = corner;
420  }
421 }
422 
423 bool ZONE::HitTestForCorner( const wxPoint& refPos, int aAccuracy,
424  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
425 {
426  return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, aAccuracy );
427 }
428 
429 
430 bool ZONE::HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const
431 {
433  return HitTestForCorner( refPos, aAccuracy, dummy );
434 }
435 
436 
437 bool ZONE::HitTestForEdge( const wxPoint& refPos, int aAccuracy,
438  SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
439 {
440  return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, aAccuracy );
441 }
442 
443 
444 bool ZONE::HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const
445 {
447  return HitTestForEdge( refPos, aAccuracy, dummy );
448 }
449 
450 
451 bool ZONE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
452 {
453  // Calculate bounding box for zone
454  EDA_RECT bbox = GetBoundingBox();
455  bbox.Normalize();
456 
457  EDA_RECT arect = aRect;
458  arect.Normalize();
459  arect.Inflate( aAccuracy );
460 
461  if( aContained )
462  {
463  return arect.Contains( bbox );
464  }
465  else
466  {
467  // Fast test: if aBox is outside the polygon bounding box, rectangles cannot intersect
468  if( !arect.Intersects( bbox ) )
469  return false;
470 
471  int count = m_Poly->TotalVertices();
472 
473  for( int ii = 0; ii < count; ii++ )
474  {
475  auto vertex = m_Poly->CVertex( ii );
476  auto vertexNext = m_Poly->CVertex( ( ii + 1 ) % count );
477 
478  // Test if the point is within the rect
479  if( arect.Contains( ( wxPoint ) vertex ) )
480  return true;
481 
482  // Test if this edge intersects the rect
483  if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
484  return true;
485  }
486 
487  return false;
488  }
489 }
490 
491 
492 int ZONE::GetLocalClearance( wxString* aSource ) const
493 {
494  if( m_isRuleArea )
495  return 0;
496 
497  if( aSource )
498  *aSource = _( "zone" );
499 
500  return m_ZoneClearance;
501 }
502 
503 
504 bool ZONE::HitTestFilledArea( PCB_LAYER_ID aLayer, const wxPoint &aRefPos, int aAccuracy ) const
505 {
506  // Rule areas have no filled area, but it's generally nice to treat their interior as if it were
507  // filled so that people don't have to select them by their outline (which is min-width)
508  if( GetIsRuleArea() )
509  return m_Poly->Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1, aAccuracy );
510 
511  if( !m_FilledPolysList.count( aLayer ) )
512  return false;
513 
514  return m_FilledPolysList.at( aLayer ).Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1,
515  aAccuracy );
516 }
517 
518 
519 bool ZONE::HitTestCutout( const VECTOR2I& aRefPos, int* aOutlineIdx, int* aHoleIdx ) const
520 {
521  // Iterate over each outline polygon in the zone and then iterate over
522  // each hole it has to see if the point is in it.
523  for( int i = 0; i < m_Poly->OutlineCount(); i++ )
524  {
525  for( int j = 0; j < m_Poly->HoleCount( i ); j++ )
526  {
527  if( m_Poly->Hole( i, j ).PointInside( aRefPos ) )
528  {
529  if( aOutlineIdx )
530  *aOutlineIdx = i;
531 
532  if( aHoleIdx )
533  *aHoleIdx = j;
534 
535  return true;
536  }
537  }
538  }
539 
540  return false;
541 }
542 
543 
544 void ZONE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
545 {
546  EDA_UNITS units = aFrame->GetUserUnits();
547  wxString msg;
548 
549  if( GetIsRuleArea() )
550  msg = _( "Rule Area" );
551  else if( IsOnCopperLayer() )
552  msg = _( "Copper Zone" );
553  else
554  msg = _( "Non-copper Zone" );
555 
556  // Display Cutout instead of Outline for holes inside a zone (i.e. when num contour !=0).
557  // Check whether the selected corner is in a hole; i.e., in any contour but the first one.
558  if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
559  msg << wxT( " " ) << _( "Cutout" );
560 
561  aList.emplace_back( _( "Type" ), msg );
562 
563  if( GetIsRuleArea() )
564  {
565  msg.Empty();
566 
567  if( GetDoNotAllowVias() )
568  AccumulateDescription( msg, _( "No vias" ) );
569 
570  if( GetDoNotAllowTracks() )
571  AccumulateDescription( msg, _( "No tracks" ) );
572 
573  if( GetDoNotAllowPads() )
574  AccumulateDescription( msg, _( "No pads" ) );
575 
577  AccumulateDescription( msg, _( "No copper zones" ) );
578 
580  AccumulateDescription( msg, _( "No footprints" ) );
581 
582  if( !msg.IsEmpty() )
583  aList.emplace_back( MSG_PANEL_ITEM( _( "Restrictions" ), msg ) );
584  }
585  else if( IsOnCopperLayer() )
586  {
587  aList.emplace_back( _( "Net" ), UnescapeString( GetNetname() ) );
588 
589  aList.emplace_back( _( "NetClass" ), UnescapeString( GetNetClass()->GetName() ) );
590 
591  // Display priority level
592  aList.emplace_back( _( "Priority" ), wxString::Format( "%d", GetPriority() ) );
593  }
594 
595  if( IsLocked() )
596  aList.emplace_back( _( "Status" ), _( "Locked" ) );
597 
598  wxString layerDesc;
599  int count = 0;
600 
601  for( PCB_LAYER_ID layer : m_layerSet.Seq() )
602  {
603  if( count == 0 )
604  layerDesc = GetBoard()->GetLayerName( layer );
605 
606  count++;
607  }
608 
609  if( count > 1 )
610  layerDesc.Printf( _( "%s and %d more" ), layerDesc, count - 1 );
611 
612  aList.emplace_back( _( "Layer" ), layerDesc );
613 
614  if( !m_zoneName.empty() )
615  aList.emplace_back( _( "Name" ), m_zoneName );
616 
617  switch( m_fillMode )
618  {
619  case ZONE_FILL_MODE::POLYGONS: msg = _( "Solid" ); break;
620  case ZONE_FILL_MODE::HATCH_PATTERN: msg = _( "Hatched" ); break;
621  default: msg = _( "Unknown" ); break;
622  }
623 
624  aList.emplace_back( _( "Fill Mode" ), msg );
625 
626  msg = MessageTextFromValue( units, m_area, true, EDA_DATA_TYPE::AREA );
627  aList.emplace_back( _( "Filled Area" ), msg );
628 
629  wxString source;
630  int clearance = GetOwnClearance( GetLayer(), &source );
631 
632  aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
633  MessageTextFromValue( units, clearance ) ),
634  wxString::Format( _( "(from %s)" ), source ) );
635 
636  // Useful for statistics, especially when zones are complex the number of hatches
637  // and filled polygons can explain the display and DRC calculation time:
638  msg.Printf( wxT( "%d" ), (int) m_borderHatchLines.size() );
639  aList.emplace_back( MSG_PANEL_ITEM( _( "HatchBorder Lines" ), msg ) );
640 
641  PCB_LAYER_ID layer = m_layer;
642 
643  // NOTE: This brings in dependence on PCB_EDIT_FRAME to the qa tests, which isn't ideal.
644  // TODO: Figure out a way for items to know the active layer without the whole edit frame?
645 #if 0
646  if( PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( aFrame ) )
647  {
648  if( m_FilledPolysList.count( pcbframe->GetActiveLayer() ) )
649  layer = pcbframe->GetActiveLayer();
650  }
651 #endif
652 
653  if( !GetIsRuleArea() )
654  {
655  auto layer_it = m_FilledPolysList.find( layer );
656 
657  if( layer_it == m_FilledPolysList.end() )
658  layer_it = m_FilledPolysList.begin();
659 
660  if( layer_it != m_FilledPolysList.end() )
661  {
662  msg.Printf( wxT( "%d" ), layer_it->second.TotalVertices() );
663  aList.emplace_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg ) );
664  }
665  }
666 }
667 
668 
669 /* Geometric transforms: */
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 {
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,
1021  segment.A.x, segment.A.y,
1022  segment.B.x, segment.B.y,
1023  x, y );
1024 
1025  if( ok )
1026  {
1027  VECTOR2I point( KiROUND( x ), KiROUND( y ) );
1028  pointbuffer.push_back( point );
1029  }
1030 
1031  if( pointbuffer.size() >= MAXPTS ) // overflow
1032  {
1033  wxASSERT( 0 );
1034  break;
1035  }
1036  }
1037 
1038  // ensure we have found an even intersection points count
1039  // because intersections are the ends of segments
1040  // inside the polygon(s) and a segment has 2 ends.
1041  // if not, this is a strange case (a bug ?) so skip this hatch
1042  if( pointbuffer.size() % 2 != 0 )
1043  continue;
1044 
1045  // sort points in order of descending x (if more than 2) to
1046  // ensure the starting point and the ending point of the same segment
1047  // are stored one just after the other.
1048  if( pointbuffer.size() > 2 )
1049  sort( pointbuffer.begin(), pointbuffer.end(), sortEndsByDescendingX );
1050 
1051  // creates lines or short segments inside the complex polygon
1052  for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
1053  {
1054  int dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
1055 
1056  // Push only one line for diagonal hatch,
1057  // or for small lines < twice the line length
1058  // else push 2 small lines
1060  || std::abs( dx ) < 2 * hatch_line_len )
1061  {
1062  m_borderHatchLines.emplace_back( SEG( pointbuffer[ip], pointbuffer[ ip + 1] ) );
1063  }
1064  else
1065  {
1066  double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
1067  slope = dy / dx;
1068 
1069  if( dx > 0 )
1070  dx = hatch_line_len;
1071  else
1072  dx = -hatch_line_len;
1073 
1074  int x1 = KiROUND( pointbuffer[ip].x + dx );
1075  int x2 = KiROUND( pointbuffer[ip + 1].x - dx );
1076  int y1 = KiROUND( pointbuffer[ip].y + dx * slope );
1077  int y2 = KiROUND( pointbuffer[ip + 1].y - dx * slope );
1078 
1079  m_borderHatchLines.emplace_back( SEG( pointbuffer[ip].x, pointbuffer[ip].y,
1080  x1, y1 ) );
1081 
1082  m_borderHatchLines.emplace_back( SEG( pointbuffer[ip+1].x, pointbuffer[ip+1].y,
1083  x2, y2 ) );
1084  }
1085  }
1086  }
1087 }
1088 
1089 
1091 {
1092  return Mils2iu( 20 );
1093 }
1094 
1095 
1097 {
1098  return BITMAPS::add_zone;
1099 }
1100 
1101 
1103 {
1104  assert( aImage->Type() == PCB_ZONE_T || aImage->Type() == PCB_FP_ZONE_T );
1105 
1106  std::swap( *((ZONE*) this), *((ZONE*) aImage) );
1107 }
1108 
1109 
1111 {
1112  if( aLayer == UNDEFINED_LAYER )
1113  {
1114  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
1115  pair.second.CacheTriangulation();
1116  }
1117  else
1118  {
1119  if( m_FilledPolysList.count( aLayer ) )
1121  }
1122 }
1123 
1124 
1125 bool ZONE::IsIsland( PCB_LAYER_ID aLayer, int aPolyIdx ) const
1126 {
1127  if( GetNetCode() < 1 )
1128  return true;
1129 
1130  if( !m_insulatedIslands.count( aLayer ) )
1131  return false;
1132 
1133  return m_insulatedIslands.at( aLayer ).count( aPolyIdx );
1134 }
1135 
1136 
1137 void ZONE::GetInteractingZones( PCB_LAYER_ID aLayer, std::vector<ZONE*>* aZones ) const
1138 {
1139  int epsilon = Millimeter2iu( 0.001 );
1140 
1141  for( ZONE* candidate : GetBoard()->Zones() )
1142  {
1143  if( candidate == this )
1144  continue;
1145 
1146  if( !candidate->GetLayerSet().test( aLayer ) )
1147  continue;
1148 
1149  if( candidate->GetIsRuleArea() )
1150  continue;
1151 
1152  if( candidate->GetNetCode() != GetNetCode() )
1153  continue;
1154 
1155  for( auto iter = m_Poly->CIterate(); iter; iter++ )
1156  {
1157  if( candidate->m_Poly->Collide( iter.Get(), epsilon ) )
1158  {
1159  aZones->push_back( candidate );
1160  break;
1161  }
1162  }
1163  }
1164 }
1165 
1166 
1168  SHAPE_POLY_SET* aBoardOutline,
1169  SHAPE_POLY_SET* aSmoothedPolyWithApron ) const
1170 {
1171  if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations will not like it ...
1172  return false;
1173 
1174  int zoneClearance = m_ZoneClearance;
1175 
1176  if( GetIsRuleArea() )
1177  {
1178  // We like keepouts just the way they are....
1179  aSmoothedPoly = *m_Poly;
1180  return true;
1181  }
1182  else if( !IsOnCopperLayer() )
1183  {
1184  // Non-copper zones don't have electrical clearances
1185  zoneClearance = 0;
1186  }
1187 
1188  BOARD* board = GetBoard();
1189  int edgeClearance = 0;
1190  int maxError = ARC_HIGH_DEF;
1191  bool keepExternalFillets = false;
1192 
1193  if( board )
1194  {
1195  BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
1196 
1197  DRC_CONSTRAINT c = bds.m_DRCEngine->EvalRules( EDGE_CLEARANCE_CONSTRAINT, this, nullptr,
1198  aLayer );
1199  edgeClearance = c.Value().Min();
1200  maxError = bds.m_MaxError;
1201  keepExternalFillets = bds.m_ZoneKeepExternalFillets;
1202  }
1203 
1204  auto smooth = [&]( SHAPE_POLY_SET& aPoly )
1205  {
1206  switch( m_cornerSmoothingType )
1207  {
1209  aPoly = aPoly.Chamfer( (int) m_cornerRadius );
1210  break;
1211 
1213  {
1214  aPoly = aPoly.Fillet( (int) m_cornerRadius, maxError );
1215  break;
1216  }
1217 
1218  default:
1219  break;
1220  }
1221  };
1222 
1223  std::vector<ZONE*> interactingZones;
1224  GetInteractingZones( aLayer, &interactingZones );
1225 
1226  SHAPE_POLY_SET* maxExtents = m_Poly;
1227  SHAPE_POLY_SET withFillets;
1228 
1229  aSmoothedPoly = *m_Poly;
1230 
1231  // Should external fillets (that is, those applied to concave corners) be kept? While it
1232  // seems safer to never have copper extend outside the zone outline, 5.1.x and prior did
1233  // indeed fill them so we leave the mode available.
1234  if( keepExternalFillets )
1235  {
1236  withFillets = *m_Poly;
1237  smooth( withFillets );
1238  withFillets.BooleanAdd( *m_Poly, SHAPE_POLY_SET::PM_FAST );
1239  maxExtents = &withFillets;
1240  }
1241 
1242  for( ZONE* zone : interactingZones )
1243  aSmoothedPoly.BooleanAdd( *zone->Outline(), SHAPE_POLY_SET::PM_FAST );
1244 
1245  if( aBoardOutline )
1246  {
1247  SHAPE_POLY_SET poly = *aBoardOutline;
1248  poly.Deflate( std::max( zoneClearance, edgeClearance ), 16 );
1250  }
1251 
1252  smooth( aSmoothedPoly );
1253 
1254  if( aSmoothedPolyWithApron )
1255  {
1256  SHAPE_POLY_SET poly = *maxExtents;
1257  poly.Inflate( m_ZoneMinThickness, 16 );
1258  *aSmoothedPolyWithApron = aSmoothedPoly;
1259  aSmoothedPolyWithApron->BooleanIntersection( poly, SHAPE_POLY_SET::PM_FAST );
1260  }
1261 
1262  aSmoothedPoly.BooleanIntersection( *maxExtents, SHAPE_POLY_SET::PM_FAST );
1263 
1264  return true;
1265 }
1266 
1267 
1269 {
1270  m_area = 0.0;
1271 
1272  // Iterate over each outline polygon in the zone and then iterate over
1273  // each hole it has to compute the total area.
1274  for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
1275  {
1276  SHAPE_POLY_SET& poly = pair.second;
1277 
1278  for( int i = 0; i < poly.OutlineCount(); i++ )
1279  {
1280  m_area += poly.Outline( i ).Area();
1281 
1282  for( int j = 0; j < poly.HoleCount( i ); j++ )
1283  m_area -= poly.Hole( i, j ).Area();
1284  }
1285  }
1286 
1287  return m_area;
1288 }
1289 
1290 
1291 void ZONE::TransformSmoothedOutlineToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearance,
1292  SHAPE_POLY_SET* aBoardOutline ) const
1293 {
1294  // Creates the zone outline polygon (with holes if any)
1295  SHAPE_POLY_SET polybuffer;
1296  BuildSmoothedPoly( polybuffer, GetLayer(), aBoardOutline );
1297 
1298  // Calculate the polygon with clearance
1299  // holes are linked to the main outline, so only one polygon is created.
1300  if( aClearance )
1301  {
1302  BOARD* board = GetBoard();
1303  int maxError = ARC_HIGH_DEF;
1304 
1305  if( board )
1306  maxError = board->GetDesignSettings().m_MaxError;
1307 
1308  int segCount = GetArcToSegmentCount( aClearance, maxError, 360.0 );
1309  polybuffer.Inflate( aClearance, segCount );
1310  }
1311 
1312  polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
1313  aCornerBuffer.Append( polybuffer );
1314 }
1315 
1316 
1317 bool ZONE::IsKeepout() const
1318 {
1321 }
1322 
1323 
1324 bool ZONE::KeepoutAll() const
1325 {
1328 }
1329 
1330 
1331 //
1332 /********* FP_ZONE **************/
1333 //
1335  ZONE( aParent, true )
1336 {
1337  // in a footprint, net classes are not managed.
1338  // so set the net to NETINFO_LIST::ORPHANED_ITEM
1339  SetNetCode( -1, true );
1340 }
1341 
1342 
1343 FP_ZONE::FP_ZONE( const FP_ZONE& aZone ) :
1344  ZONE( aZone.GetParent(), true )
1345 {
1346  InitDataFromSrcInCopyCtor( aZone );
1347 }
1348 
1349 
1351 {
1352  ZONE::operator=( aOther );
1353  return *this;
1354 }
1355 
1356 
1358 {
1359  return new FP_ZONE( *this );
1360 }
1361 
1362 
1363 double FP_ZONE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
1364 {
1365  constexpr double HIDE = (double)std::numeric_limits<double>::max();
1366 
1367  if( !aView )
1368  return 0;
1369 
1370  if( !aView->IsLayerVisible( LAYER_ZONES ) )
1371  return HIDE;
1372 
1373  bool flipped = GetParent() && GetParent()->GetLayer() == B_Cu;
1374 
1375  // Handle Render tab switches
1376  if( !flipped && !aView->IsLayerVisible( LAYER_MOD_FR ) )
1377  return HIDE;
1378 
1379  if( flipped && !aView->IsLayerVisible( LAYER_MOD_BK ) )
1380  return HIDE;
1381 
1382  // Other layers are shown without any conditions
1383  return 0.0;
1384 }
1385 
1386 
1387 std::shared_ptr<SHAPE> ZONE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
1388 {
1389  std::shared_ptr<SHAPE> shape;
1390 
1391  if( m_FilledPolysList.find( aLayer ) == m_FilledPolysList.end() )
1392  {
1393  shape = std::make_shared<SHAPE_NULL>();
1394  }
1395  else
1396  {
1397  shape.reset( m_FilledPolysList.at( aLayer ).Clone() );
1398  }
1399 
1400  return shape;
1401 }
1402 
1403 
1404 static struct ZONE_DESC
1405 {
1407  {
1409  .Map( ZONE_CONNECTION::INHERITED, _HKI( "Inherited" ) )
1410  .Map( ZONE_CONNECTION::NONE, _HKI( "None" ) )
1411  .Map( ZONE_CONNECTION::THERMAL, _HKI( "Thermal reliefs" ) )
1412  .Map( ZONE_CONNECTION::FULL, _HKI( "Solid" ) )
1413  .Map( ZONE_CONNECTION::THT_THERMAL, _HKI( "Reliefs for PTH" ) );
1414 
1416  REGISTER_TYPE( ZONE );
1418  propMgr.AddProperty( new PROPERTY<ZONE, unsigned>( _HKI( "Priority" ),
1420  //propMgr.AddProperty( new PROPERTY<ZONE, bool>( "Filled",
1421  //&ZONE::SetIsFilled, &ZONE::IsFilled ) );
1422  propMgr.AddProperty( new PROPERTY<ZONE, wxString>( _HKI( "Name" ),
1424  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Clearance" ),
1427  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Min Width" ),
1430  propMgr.AddProperty( new PROPERTY_ENUM<ZONE, ZONE_CONNECTION>( _HKI( "Pad Connections" ),
1432  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thermal Clearance" ),
1435  propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thermal Spoke Width" ),
1438  }
1439 } _ZONE_DESC;
1440 
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:1096
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:90
bool m_doNotAllowFootprints
Definition: zone.h:847
void SetCornerRadius(unsigned int aRadius)
Definition: zone.cpp:359
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:1110
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:1291
#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:342
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:82
int m_cornerSmoothingType
Definition: zone.h:821
MINOPTMAX< int > & Value()
Definition: drc_rule.h:122
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:244
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:98
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:289
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:228
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.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
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:1167
wxString GetNetname() const
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition: zone.cpp:314
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
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:831
T Min() const
Definition: minoptmax.h:33
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
void Inflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Perform outline inflation/deflation.
The base class for create windows for drawing purpose.
MD5_HASH GetHashValue(PCB_LAYER_ID aLayer)
Definition: zone.cpp:380
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:544
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
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,...
ZONE(BOARD_ITEM_CONTAINER *parent, bool aInFP=false)
The ctor to build ZONE, but compatible with FP_ZONE requirement.
Definition: zone.cpp:42
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:504
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:1102
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
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:423
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)
Function Append()
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...
int GetEffectiveThermalSpokeWidth(wxString *aSource=nullptr) const
Return the effective thermal spoke width having resolved any inheritance.
Definition: pad.cpp:812
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:1137
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:519
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:304
void SetClosed(bool aClosed)
Function SetClosed()
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:295
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:320
#define NULL
MD5_HASH GetHash() const
void Move(const VECTOR2I &aVector) override
bool IsClosed() const override
Function IsClosed()
static int GetDefaultHatchPitch()
Definition: zone.cpp:1090
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:1387
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:398
SHAPE_LINE_CHAIN & Outline(int aIndex)
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: zone.cpp:216
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:791
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
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
void Deflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
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:105
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
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:377
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:177
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:389
bool m_isRuleArea
Definition: zone.h:838
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:41
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:1317
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
virtual bool IsLocked() const
Definition: board_item.h:249
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:437
ZONE_DESC()
Definition: zone.cpp:1406
wxPoint GetPosition() const override
Definition: zone.cpp:210
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:1350
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:1125
#define _(s)
Definition: 3d_actions.cpp:33
SHAPE_LINE_CHAIN.
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:151
int m_hatchGap
Definition: zone.h:884
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
int GetCopperLayerCount() const
Definition: board.cpp:435
class ZONE, managed by a footprint
Definition: typeinfo.h:94
VECTOR2I A
Definition: seg.h:49
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:1334
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:222
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:68
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:150
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:180
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:363
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:236
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:1268
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_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
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:88
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:60
STATUS_FLAGS m_flags
Definition: eda_item.h:531
bool UnFill()
Removes the zone filling.
Definition: zone.cpp:186
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:1363
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
bool m_forceVisible
Definition: eda_item.h:530
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:173
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:306
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.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
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:363
static struct ZONE_DESC _ZONE_DESC
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:744
bool GetFilledPolysUseThickness() const
Definition: zone.h:686
bool KeepoutAll() const
Definition: zone.cpp:1324
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:1357
VECTOR2I B
Definition: seg.h:50