KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
6 * Copyright The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <advanced_config.h>
23#include <bitmaps.h>
25#include <geometry/shape_null.h>
26#include <pcb_edit_frame.h>
27#include <pcb_screen.h>
28#include <board.h>
30#include <lset.h>
31#include <pad.h>
32#include <zone.h>
33#include <footprint.h>
34#include <string_utils.h>
36#include <properties/property.h>
40#include <trigo.h>
41#include <i18n_utility.h>
42#include <mutex>
43#include <magic_enum.hpp>
44
45#include <google/protobuf/any.pb.h>
46#include <api/api_enums.h>
47#include <api/api_utils.h>
48#include <api/api_pcb_utils.h>
49#include <api/board/board_types.pb.h>
50
51
54 m_Poly( nullptr ),
55 m_cornerRadius( 0 ),
56 m_priority( 0 ),
57 m_isRuleArea( false ),
62 m_ZoneClearance( 0 ),
65 m_isFilled( false ),
70 m_hatchGap( 0 ),
74 m_area( 0.0 ),
75 m_outlinearea( 0.0 )
76{
77 m_Poly = new SHAPE_POLY_SET(); // Outlines
78 SetLocalFlags( 0 ); // flags temporary used in zone calculations
79 m_fillVersion = 5; // set the "old" way to build filled polygon areas (< 6.0.x)
80
81 if( GetParentFootprint() )
82 SetIsRuleArea( true ); // Zones living in footprints have the rule area option
83
84 if( aParent->GetBoard() )
85 aParent->GetBoard()->GetDesignSettings().GetDefaultZoneSettings().ExportSetting( *this, false );
86 else
87 ZONE_SETTINGS().ExportSetting( *this, false );
88
89 m_needRefill = false; // True only after edits.
90}
91
92
93ZONE::ZONE( const ZONE& aZone ) :
94 BOARD_CONNECTED_ITEM( aZone ),
95 m_Poly( nullptr )
96{
98}
99
100
101ZONE& ZONE::operator=( const ZONE& aOther )
102{
104
106
107 return *this;
108}
109
110
111void ZONE::CopyFrom( const BOARD_ITEM* aOther )
112{
113 wxCHECK( aOther && aOther->Type() == PCB_ZONE_T, /* void */ );
114 *this = *static_cast<const ZONE*>( aOther );
115}
116
117
119{
120 delete m_Poly;
121}
122
123
125{
126 // members are expected non initialize in this.
127 // InitDataFromSrcInCopyCtor() is expected to be called only from a copy constructor.
128
129 // Copy only useful EDA_ITEM flags:
130 m_flags = aZone.m_flags;
132
133 // Replace the outlines for aZone outlines.
134 delete m_Poly;
135 m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
136
139 m_zoneName = aZone.m_zoneName;
140 m_priority = aZone.m_priority;
145
146 m_fillMode = aZone.m_fillMode; // solid vs. hatched
147
148 if( aLayer == UNDEFINED_LAYER )
149 SetLayerSet( aZone.GetLayerSet() );
150 else
151 SetLayerSet( { aLayer } );
152
158
160 m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
165
166 m_isFilled = aZone.m_isFilled;
167 m_needRefill = aZone.m_needRefill.load();
169
172
174 m_hatchGap = aZone.m_hatchGap;
181
182 aZone.GetLayerSet().RunOnLayers(
183 [&]( PCB_LAYER_ID layer )
184 {
185 if( aLayer != UNDEFINED_LAYER && aLayer != layer )
186 return;
187
188 std::shared_ptr<SHAPE_POLY_SET> fill = aZone.m_FilledPolysList.at( layer );
189
190 if( fill )
191 m_FilledPolysList[layer] = std::make_shared<SHAPE_POLY_SET>( *fill );
192 else
193 m_FilledPolysList[layer] = std::make_shared<SHAPE_POLY_SET>();
194
195 m_filledPolysHash[layer] = aZone.m_filledPolysHash.at( layer );
196 m_insulatedIslands[layer] = aZone.m_insulatedIslands.at( layer );
197 } );
198
200
204
205 SetLocalFlags( aZone.GetLocalFlags() );
206
207 m_netinfo = aZone.m_netinfo;
208 m_area = aZone.m_area;
210
211 // Fresh outline; lock-free bbox cache starts invalid.
212 m_bboxCacheTimeStamp.store( -1, std::memory_order_relaxed );
213}
214
215
217{
218 return new ZONE( *this );
219}
220
221
223{
224 ZONE* clone = new ZONE( BOARD_ITEM::GetParent() );
225 clone->InitDataFromSrcInCopyCtor( *this, aLayer );
226 return clone;
227}
228
229
230BOARD_ITEM* ZONE::Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit ) const
231{
232 BOARD_ITEM* dupe = BOARD_ITEM::Duplicate( addToParentGroup, aCommit );
233
234 if( const BOARD* board = GetBoard() )
235 {
236 ZONE* newZone = static_cast<ZONE*>( dupe );
237
238 // Give the copy its own name so it does not collide with the original (issue 23131)
239 if( !newZone->GetZoneName().IsEmpty() )
240 newZone->SetZoneName( board->GetUniqueZoneName( newZone->GetZoneName(), newZone ) );
241 }
242
243 return dupe;
244}
245
246
247void ZONE::Serialize( google::protobuf::Any& aContainer ) const
248{
249 using namespace kiapi::board;
250 types::Zone zone;
252
253 zone.mutable_id()->set_value( m_Uuid.AsStdString() );
254 PackLayerSet( *zone.mutable_layers(), GetLayerSet() );
255
256 if( m_isRuleArea )
257 zone.set_type( types::ZT_RULE_AREA );
259 zone.set_type( types::ZT_TEARDROP );
260 else if( IsOnCopperLayer() )
261 zone.set_type( types::ZT_COPPER );
262 else
263 zone.set_type( types::ZT_GRAPHICAL );
264
265 kiapi::common::PackPolySet( *zone.mutable_outline(), *m_Poly );
266
267 zone.set_name( m_zoneName.ToUTF8() );
268 zone.set_priority( m_priority );
269 zone.set_filled( m_isFilled );
270
271 if( FOOTPRINT* parent = GetParentFootprint() )
272 zone.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
273 else if( const BOARD* board = GetBoard() )
274 zone.mutable_parent()->set_value( board->m_Uuid.AsStdString() );
275
276 if( m_isRuleArea )
277 {
278 types::RuleAreaSettings* ra = zone.mutable_rule_area_settings();
279 ra->set_keepout_copper( m_doNotAllowZoneFills );
280 ra->set_keepout_footprints( m_doNotAllowFootprints );
281 ra->set_keepout_pads( m_doNotAllowPads );
282 ra->set_keepout_tracks( m_doNotAllowTracks );
283 ra->set_keepout_vias( m_doNotAllowVias );
284
285 ra->set_placement_enabled( m_placementAreaEnabled );
286 ra->set_placement_source( m_placementAreaSource.ToUTF8() );
287 ra->set_placement_source_type( ToProtoEnum<PLACEMENT_SOURCE_T,
288 types::PlacementRuleSourceType>( m_placementAreaSourceType ) );
289 }
290 else
291 {
292 types::CopperZoneSettings* cu = zone.mutable_copper_settings();
293 cu->mutable_connection()->set_zone_connection(
295
296 types::ThermalSpokeSettings* thermals = cu->mutable_connection()->mutable_thermal_spokes();
297 thermals->mutable_width()->set_value_nm( m_thermalReliefSpokeWidth );
298 thermals->mutable_gap()->set_value_nm( m_thermalReliefGap );
299 // n.b. zones don't currently have an overall thermal angle override
300
301 cu->mutable_clearance()->set_value_nm( m_ZoneClearance );
302 cu->mutable_min_thickness()->set_value_nm( m_ZoneMinThickness );
303 cu->set_island_mode(
305 cu->set_min_island_area( m_minIslandArea );
307
308 cu->set_corner_smoothing(
310
311 if( m_cornerRadius != 0 )
312 cu->mutable_corner_radius()->set_value_nm( m_cornerRadius );
313
314 types::HatchFillSettings* hatch = cu->mutable_hatch_settings();
315 hatch->mutable_thickness()->set_value_nm( m_hatchThickness );
316 hatch->mutable_gap()->set_value_nm( m_hatchGap );
317 hatch->mutable_orientation()->set_value_degrees( m_hatchOrientation.GetAngle().AsDegrees() );
318 hatch->set_hatch_smoothing_ratio( m_hatchSmoothingValue );
319 hatch->set_hatch_hole_min_area_ratio( m_hatchHoleMinArea );
320
321 switch( m_hatchBorderAlgorithm )
322 {
323 default:
324 case 0: hatch->set_border_mode( types::ZHFBM_USE_MIN_ZONE_THICKNESS ); break;
325 case 1: hatch->set_border_mode( types::ZHFBM_USE_HATCH_THICKNESS ); break;
326 }
327
328 PackNet( cu->mutable_net() );
329 cu->mutable_teardrop()->set_type(
331
332 types::ThievingFillSettings* thieving = cu->mutable_thieving_settings();
333 thieving->set_pattern(
335 thieving->mutable_element_size()->set_value_nm( m_thievingSettings.element_size );
336 thieving->mutable_gap()->set_value_nm( m_thievingSettings.gap );
337 thieving->mutable_line_width()->set_value_nm( m_thievingSettings.line_width );
338 thieving->set_stagger( m_thievingSettings.stagger );
339 thieving->mutable_orientation()->set_value_degrees( m_thievingSettings.orientation.GetAngle().AsDegrees() );
340 }
341
342 for( const auto& [layer, shape] : m_FilledPolysList )
343 {
344 types::ZoneFilledPolygons* filledLayer = zone.add_filled_polygons();
345 filledLayer->set_layer( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( layer ) );
346 kiapi::common::PackPolySet( *filledLayer->mutable_shapes(), *shape );
347 }
348
349 for( const auto& [layer, properties] : m_layerProperties )
350 {
351 types::ZoneLayerProperties* layerProperties = zone.add_layer_properties();
352 layerProperties->set_layer( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( layer ) );
353
354 if( properties.hatching_offset.has_value() )
355 {
356 PackVector2( *layerProperties->mutable_hatching_offset(),
357 properties.hatching_offset.value() );
358 }
359 }
360
361 zone.mutable_border()->set_style(
363 zone.mutable_border()->mutable_pitch()->set_value_nm( m_borderHatchPitch );
364
365 kiapi::common::PackCustomProperties( zone.mutable_custom_properties(), *this );
366 aContainer.PackFrom( zone );
367}
368
369
370bool ZONE::Deserialize( const google::protobuf::Any& aContainer )
371{
372 using namespace kiapi::board;
373 types::Zone zone;
375
376 if( !aContainer.UnpackTo( &zone ) )
377 return false;
378
379 SetUuidDirect( KIID( zone.id().value() ) );
380 SetLayerSet( UnpackLayerSet( zone.layers() ) );
381 SetAssignedPriority( zone.priority() );
382 SetZoneName( wxString::FromUTF8( zone.name() ) );
383 kiapi::common::UnpackCustomProperties( zone.custom_properties(), *this );
384
385 if( zone.type() == types::ZoneType::ZT_RULE_AREA )
386 m_isRuleArea = true;
387
388 if( !m_Poly )
390
391 *m_Poly = kiapi::common::UnpackPolySet( zone.outline() );
392
393 if( m_Poly->OutlineCount() == 0 )
394 return false;
395
396 if( m_isRuleArea )
397 {
398 const types::RuleAreaSettings& ra = zone.rule_area_settings();
399 m_doNotAllowZoneFills = ra.keepout_copper();
400 m_doNotAllowFootprints = ra.keepout_footprints();
401 m_doNotAllowPads = ra.keepout_pads();
402 m_doNotAllowTracks = ra.keepout_tracks();
403 m_doNotAllowVias = ra.keepout_vias();
404
405 m_placementAreaEnabled = ra.placement_enabled();
406 m_placementAreaSource = wxString::FromUTF8( ra.placement_source() );
407 m_placementAreaSourceType = FromProtoEnum<PLACEMENT_SOURCE_T>( ra.placement_source_type() );
408 }
409 else
410 {
411 const types::CopperZoneSettings& cu = zone.copper_settings();
412 m_PadConnection = FromProtoEnum<ZONE_CONNECTION>( cu.connection().zone_connection() );
413 m_thermalReliefSpokeWidth = cu.connection().thermal_spokes().width().value_nm();
414 m_thermalReliefGap = cu.connection().thermal_spokes().gap().value_nm();
415 m_ZoneClearance = cu.clearance().value_nm();
416 m_ZoneMinThickness = cu.min_thickness().value_nm();
418 m_minIslandArea = cu.min_island_area();
419 // Route through SetFillMode so the thieving single-layer / net-less invariants
420 // are enforced on protobuf imports — a direct m_fillMode assignment would leave
421 // the multi-layer set unpacked at line 355 in place for ZFM_COPPER_THIEVING.
422 SetFillMode( FromProtoEnum<ZONE_FILL_MODE>( cu.fill_mode() ) );
423
425
426 if( cu.has_corner_radius() )
427 SetCornerRadius( cu.corner_radius().value_nm() );
428 else
429 SetCornerRadius( 0 );
430
431 m_hatchThickness = cu.hatch_settings().thickness().value_nm();
432 m_hatchGap = cu.hatch_settings().gap().value_nm();
433 m_hatchOrientation = EDA_ANGLE( cu.hatch_settings().orientation().value_degrees(), DEGREES_T );
434 m_hatchSmoothingValue = cu.hatch_settings().hatch_smoothing_ratio();
435 m_hatchHoleMinArea = cu.hatch_settings().hatch_hole_min_area_ratio();
436
437 switch( cu.hatch_settings().border_mode() )
438 {
439 default:
440 case types::ZHFBM_USE_MIN_ZONE_THICKNESS: m_hatchBorderAlgorithm = 0; break;
441 case types::ZHFBM_USE_HATCH_THICKNESS: m_hatchBorderAlgorithm = 1; break;
442 }
443
444 UnpackNet( cu.net() );
445 m_teardropType = FromProtoEnum<TEARDROP_TYPE>( cu.teardrop().type() );
446
447 if( cu.has_thieving_settings() )
448 {
449 const types::ThievingFillSettings& thieving = cu.thieving_settings();
450 m_thievingSettings.pattern =
451 FromProtoEnum<THIEVING_PATTERN>( thieving.pattern() );
452
453 auto assignIfPositive = []( int aProtoValue, int& aTarget )
454 {
455 if( aProtoValue > 0 )
456 aTarget = aProtoValue;
457 };
458
459 assignIfPositive( thieving.element_size().value_nm(), m_thievingSettings.element_size );
460 assignIfPositive( thieving.gap().value_nm(), m_thievingSettings.gap );
461 assignIfPositive( thieving.line_width().value_nm(), m_thievingSettings.line_width );
462
463 m_thievingSettings.stagger = thieving.stagger();
464 m_thievingSettings.orientation =
465 EDA_ANGLE( thieving.orientation().value_degrees(), DEGREES_T );
466 }
467
468 for( const auto& properties : zone.layer_properties() )
469 {
470 PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( properties.layer() );
471
472 ZONE_LAYER_PROPERTIES layerProperties;
473
474 if( properties.has_hatching_offset() )
475 layerProperties.hatching_offset = UnpackVector2( properties.hatching_offset() );
476
477 m_layerProperties[layer] = layerProperties;
478 }
479 }
480
482 m_borderHatchPitch = zone.border().pitch().value_nm();
483
484 if( zone.filled() )
485 {
486 SetIsFilled( true );
487 SetNeedRefill( false );
488
489 for( const types::ZoneFilledPolygons& fillLayer : zone.filled_polygons() )
490 {
491 PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( fillLayer.layer() );
492 SHAPE_POLY_SET shape = kiapi::common::UnpackPolySet( fillLayer.shapes() );
493 m_FilledPolysList[layer] = std::make_shared<SHAPE_POLY_SET>( shape );
494 }
495 }
496 else
497 {
498 UnFill();
499 }
500
501
502 HatchBorder();
503
504 return true;
505}
506
507
508bool ZONE::HigherPriority( const ZONE* aOther ) const
509{
510 // Teardrops are always higher priority than regular zones, so if one zone is a teardrop
511 // and the other is not, then return higher priority as the teardrop
513 return static_cast<int>( m_teardropType ) > static_cast<int>( aOther->m_teardropType );
514
515 if( m_priority != aOther->m_priority )
516 return m_priority > aOther->m_priority;
517
518 return m_Uuid > aOther->m_Uuid;
519}
520
521
522bool ZONE::SameNet( const ZONE* aOther ) const
523{
524 return GetNetCode() == aOther->GetNetCode();
525}
526
527
529{
530 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
531
532 return unFillLocked();
533}
534
535
537{
538 bool change = false;
539
540 for( std::pair<const PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>>& pair : m_FilledPolysList )
541 {
542 change |= !pair.second->IsEmpty();
543 m_insulatedIslands[pair.first].clear();
544
545 // Replace the shared_ptr with a new empty object rather than clearing the existing one.
546 // This ensures that any CN_ZONE_LAYERs holding shared_ptr copies still have valid data
547 // (the old, now orphaned SHAPE_POLY_SET) while we get a fresh container.
548 pair.second = std::make_shared<SHAPE_POLY_SET>();
549 }
550
551 m_isFilled = false;
552 m_fillFlags.reset();
553
554 return change;
555}
556
557
559{
560 return HasFlag( COURTYARD_CONFLICT );
561}
562
563
565{
566 if( m_Poly->OutlineCount() == 0 || m_Poly->TotalVertices() == 0 )
567 return VECTOR2I( 0, 0 );
568
569 return GetCornerPosition( 0 );
570}
571
572
574{
575 std::lock_guard<std::mutex> lock( m_layerSetMutex );
576
577 if( m_layerSet.count() == 1 )
578 {
579 // GetFirstLayer would try to acquire the mutex again, so inline its logic here
580 if( m_layerSet.count() == 0 )
581 return UNDEFINED_LAYER;
582
583 const LSEQ uiLayers = m_layerSet.UIOrder();
584
585 if( uiLayers.size() )
586 return uiLayers[0];
587
588 return m_layerSet.Seq()[0];
589 }
590
591 return UNDEFINED_LAYER;
592}
593
594
596{
597 std::lock_guard<std::mutex> lock( m_layerSetMutex );
598
599 if( m_layerSet.count() == 0 )
600 return UNDEFINED_LAYER;
601
602 const LSEQ uiLayers = m_layerSet.UIOrder();
603
604 // This can't use m_layerSet.count() because it's possible to have a zone on
605 // a rescue layer that is not in the UI order.
606 if( uiLayers.size() )
607 return uiLayers[0];
608
609 // If it's not in the UI set at all, just return the first layer in the set.
610 // (we know the count > 0)
611 return m_layerSet.Seq()[0];
612}
613
614
616{
617 std::lock_guard<std::mutex> lock( m_layerSetMutex );
618 return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
619}
620
621
622bool ZONE::SetNetCode( int aNetCode, bool aNoAssert )
623{
624 if( IsCopperThieving() )
625 aNetCode = 0;
626
627 return BOARD_CONNECTED_ITEM::SetNetCode( aNetCode, aNoAssert );
628}
629
630
631void ZONE::SetNet( NETINFO_ITEM* aNetInfo )
632{
633 if( IsCopperThieving() )
634 aNetInfo = nullptr;
635
637}
638
639
641{
642 SetLayerSet( LSET( { aLayer } ) );
643}
644
645
647{
648 if( m_fillMode == aFillMode )
649 return;
650
651 SetNeedRefill( true );
652 m_fillMode = aFillMode;
653
654 // Thieving zones are net-less and single-layer; clamp on transition so a
655 // multi-layer netted POLYGONS zone converted via the property panel or a
656 // load-time SetLayerSet-then-SetFillMode sequence cannot keep stale state.
658 {
661 }
662}
663
664
665void ZONE::SetLayerSet( const LSET& aLayerSet )
666{
667 if( aLayerSet.count() == 0 )
668 return;
669
670 // Thieving zones are single-layer; clamp here so direct callers cannot violate
671 // the invariant. UIOrder().front() matches GetFirstLayer().
672 const LSET effectiveSet = ( IsCopperThieving() && aLayerSet.count() > 1 )
673 ? LSET( { aLayerSet.UIOrder().front() } )
674 : aLayerSet;
675
676 std::scoped_lock lock( m_layerSetMutex, m_filledPolysListMutex );
677
678 if( m_layerSet != effectiveSet )
679 {
680 SetNeedRefill( true );
681
682 unFillLocked();
683
684 m_FilledPolysList.clear();
685 m_filledPolysHash.clear();
686 m_insulatedIslands.clear();
687
688 effectiveSet.RunOnLayers(
689 [&]( PCB_LAYER_ID layer )
690 {
691 m_FilledPolysList[layer] = std::make_shared<SHAPE_POLY_SET>();
692 m_filledPolysHash[layer] = {};
693 m_insulatedIslands[layer] = {};
694 } );
695
696 std::erase_if( m_layerProperties,
697 [&]( const auto& item )
698 {
699 return !effectiveSet.Contains( item.first );
700 } );
701 }
702
703 m_layerSet = effectiveSet;
704}
705
706
707void ZONE::SetLayerProperties( const std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES>& aOther )
708{
709 m_layerProperties = aOther;
710}
711
712
713std::vector<int> ZONE::ViewGetLayers() const
714{
715 std::lock_guard<std::mutex> lock( m_layerSetMutex );
716
717 std::vector<int> layers;
718 layers.reserve( 2 * m_layerSet.count() + 1 );
719
720 m_layerSet.RunOnLayers(
721 [&]( PCB_LAYER_ID layer )
722 {
723 layers.push_back( layer );
724 layers.push_back( layer + static_cast<int>( LAYER_ZONE_START ) );
725 } );
726
727 layers.push_back( LAYER_CONFLICTS_SHADOW );
728
729 return layers;
730}
731
732
733double ZONE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
734{
735 if( !aView )
736 return LOD_SHOW;
737
738 if( !aView->IsLayerVisibleCached( LAYER_ZONES ) )
739 return LOD_HIDE;
740
741 if( FOOTPRINT* parentFP = GetParentFootprint() )
742 {
743 const LSET zl = GetLayerSet();
744 bool onFront = ( zl & LSET::FrontMask() ).any();
745 bool onBack = ( zl & LSET::BackMask() ).any();
746
747 if( !onFront && !onBack )
748 {
749 onFront = parentFP->GetLayer() == F_Cu;
750 onBack = parentFP->GetLayer() == B_Cu;
751 }
752
753 const bool frHidden = !aView->IsLayerVisibleCached( LAYER_FOOTPRINTS_FR );
754 const bool bkHidden = !aView->IsLayerVisibleCached( LAYER_FOOTPRINTS_BK );
755
756 if( onFront && !onBack && frHidden )
757 return LOD_HIDE;
758
759 if( onBack && !onFront && bkHidden )
760 return LOD_HIDE;
761
762 if( onFront && onBack && frHidden && bkHidden )
763 return LOD_HIDE;
764 }
765
766 // Other layers are shown without any conditions
767 return LOD_SHOW;
768}
769
770
771bool ZONE::IsOnLayer( PCB_LAYER_ID aLayer ) const
772{
773 std::lock_guard<std::mutex> lock( m_layerSetMutex );
774 return m_layerSet.test( aLayer );
775}
776
777
779{
780 if( GetParentFootprint() )
781 return GetBoardOutline().BBox();
782
783 return m_Poly->BBox();
784}
785
786
788{
789 if( const BOARD* board = GetBoard() )
790 {
791 // Lock-free fast path, valid while the board timestamp matches what we cached for.
792 // Skips the caches mutex that otherwise serializes every fill worker.
793 if( m_bboxCacheTimeStamp.load( std::memory_order_acquire ) == board->GetTimeStamp() )
794 return m_bboxCache;
795
796 std::unordered_map<const ZONE*, BOX2I>& cache = board->m_ZoneBBoxCache;
797
798 {
799 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
800
801 auto cacheIter = cache.find( this );
802
803 if( cacheIter != cache.end() )
804 return cacheIter->second;
805 }
806
807 BOX2I bbox = computeBoundingBox();
808
809 {
810 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
811 cache[ this ] = bbox;
812 }
813
814 return bbox;
815 }
816
817 return computeBoundingBox();
818}
819
820
822{
823 if( const BOARD* board = GetBoard() )
824 {
825 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
826 board->m_ZoneBBoxCache.erase( this );
827 }
828
829 m_bboxCacheTimeStamp.store( -1, std::memory_order_release );
830}
831
832
834{
835 // Footprint zone bounding boxes are derived through the parent transform
837 SetNeedRefill( true );
838 UnFill();
839}
840
841
843{
844 const BOARD* board = GetBoard();
845 BOX2I bbox = computeBoundingBox();
846
847 if( board )
848 {
849 // Board cache, for callers that read it directly.
850 {
851 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
852 board->m_ZoneBBoxCache[this] = bbox;
853 }
854
855 // Per-zone lock-free copy. Single-threaded per zone, so box-before-timestamp (release)
856 // suffices for the acquiring reader in GetBoundingBox().
857 m_bboxCache = bbox;
858 m_bboxCacheTimeStamp.store( board->GetTimeStamp(), std::memory_order_release );
859 }
860}
861
862
863int ZONE::GetThermalReliefGap( PAD* aPad, wxString* aSource ) const
864{
865 if( aPad->GetLocalThermalGapOverride() == 0 )
866 {
867 if( aSource )
868 *aSource = _( "zone" );
869
870 return m_thermalReliefGap;
871 }
872
873 return aPad->GetLocalThermalGapOverride( aSource );
874
875}
876
877
878void ZONE::SetCornerRadius( unsigned int aRadius )
879{
880 if( m_cornerRadius != aRadius )
881 SetNeedRefill( true );
882
883 m_cornerRadius = aRadius;
884}
885
886
888
889
891{
892 if( !m_filledPolysHash.count( aLayer ) )
893 return g_nullPoly.GetHash();
894 else
895 return m_filledPolysHash.at( aLayer );
896}
897
898
900{
901 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
902
903 if( !m_FilledPolysList.count( aLayer ) )
904 m_filledPolysHash[aLayer] = g_nullPoly.GetHash();
905 else
906 m_filledPolysHash[aLayer] = m_FilledPolysList.at( aLayer )->GetHash();
907}
908
909
914
915
917{
918 SHAPE_POLY_SET poly;
919
920 if( const FOOTPRINT* fp = GetParentFootprint() )
921 {
922 if( m_Poly )
923 poly = m_Poly->CloneDropTriangulation();
924
925 const TRANSFORM_TRS& xform = fp->GetTransform();
926
927 for( auto it = poly.IterateWithHoles(); it; it++ )
928 poly.SetVertex( it.GetIndex(), xform.Apply( *it ) );
929 }
930 else
931 {
932 if( m_Poly )
933 poly = m_Poly->CloneDropTriangulation();
934 }
935
936 return poly;
937}
938
939
940bool ZONE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
941{
942 // When looking for an "exact" hit aAccuracy will be 0 which works poorly for very thin
943 // lines. Give it a floor.
944 int accuracy = std::max( aAccuracy, pcbIUScale.mmToIU( 0.1 ) );
945
946 return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
947}
948
949
950bool ZONE::HitTestForCorner( const VECTOR2I& refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX* aCornerHit ) const
951{
952 VECTOR2I libPos = refPos;
953
954 if( const FOOTPRINT* fp = GetParentFootprint() )
955 libPos = fp->GetTransform().InverseApply( refPos );
956
957 return m_Poly->CollideVertex( libPos, aCornerHit, aAccuracy );
958}
959
960
961bool ZONE::HitTestForEdge( const VECTOR2I& refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX* aCornerHit ) const
962{
963 VECTOR2I libPos = refPos;
964
965 if( const FOOTPRINT* fp = GetParentFootprint() )
966 libPos = fp->GetTransform().InverseApply( refPos );
967
968 return m_Poly->CollideEdge( libPos, aCornerHit, aAccuracy );
969}
970
971
972bool ZONE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
973{
974 // Calculate bounding box for zone
975 BOX2I bbox = GetBoundingBox();
976 bbox.Normalize();
977
978 BOX2I arect = aRect;
979 arect.Normalize();
980 arect.Inflate( aAccuracy );
981
982 if( aContained )
983 {
984 return arect.Contains( bbox );
985 }
986 else
987 {
988 // Fast test: if aBox is outside the polygon bounding box, rectangles cannot intersect
989 if( !arect.Intersects( bbox ) )
990 return false;
991
992 SHAPE_POLY_SET boardOutline = GetBoardOutline();
993 int count = boardOutline.TotalVertices();
994
995 for( int ii = 0; ii < count; ii++ )
996 {
997 const VECTOR2I& vertex = boardOutline.CVertex( ii );
998 const VECTOR2I& vertexNext = boardOutline.CVertex( ( ii + 1 ) % count );
999
1000 // Test if the point is within the rect
1001 if( arect.Contains( vertex ) )
1002 return true;
1003
1004 // Test if this edge intersects the rect
1005 if( arect.Intersects( vertex, vertexNext ) )
1006 return true;
1007 }
1008
1009 return false;
1010 }
1011}
1012
1013
1014bool ZONE::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
1015{
1016 SHAPE_POLY_SET outline = GetBoardOutline();
1017
1018 if( aContained )
1019 {
1020 auto outlineIntersectingSelection =
1021 [&]()
1022 {
1023 for( auto segment = outline.IterateSegments(); segment; segment++ )
1024 {
1025 if( aPoly.Intersects( *segment ) )
1026 return true;
1027 }
1028
1029 return false;
1030 };
1031
1032 // In the case of contained selection, all vertices of the zone outline must be inside
1033 // the selection polygon, so we can check only the first vertex.
1034 auto vertexInsideSelection =
1035 [&]()
1036 {
1037 return aPoly.PointInside( outline.CVertex( 0 ) );
1038 };
1039
1040 return vertexInsideSelection() && !outlineIntersectingSelection();
1041 }
1042 else
1043 {
1044 // Touching selection - check if any segment of the zone contours collides with the
1045 // selection shape.
1046 for( auto segment = outline.IterateSegmentsWithHoles(); segment; segment++ )
1047 {
1048 if( aPoly.PointInside( ( *segment ).A ) )
1049 return true;
1050
1051 if( aPoly.Intersects( *segment ) )
1052 return true;
1053
1054 // Note: aPoly.Collide() could be used instead of two test above, but it is 3x slower.
1055 }
1056
1057 return false;
1058 }
1059}
1060
1061
1062std::optional<int> ZONE::GetLocalClearance() const
1063{
1064 return m_isRuleArea ? 0 : m_ZoneClearance;
1065}
1066
1067
1068bool ZONE::HitTestFilledArea( PCB_LAYER_ID aLayer, const VECTOR2I& aRefPos, int aAccuracy ) const
1069{
1070 // Rule areas have no filled area, but it's generally nice to treat their interior as if it were
1071 // filled so that people don't have to select them by their outline (which is min-width)
1072 if( GetIsRuleArea() )
1073 {
1074 VECTOR2I libPos = aRefPos;
1075
1076 if( const FOOTPRINT* fp = GetParentFootprint() )
1077 libPos = fp->GetTransform().InverseApply( aRefPos );
1078
1079 return m_Poly->Contains( libPos, -1, aAccuracy );
1080 }
1081
1082 std::shared_ptr<SHAPE_POLY_SET> fillPolys;
1083
1084 {
1085 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
1086
1087 if( !m_FilledPolysList.count( aLayer ) )
1088 return false;
1089
1090 fillPolys = m_FilledPolysList.at( aLayer );
1091 }
1092
1093 return fillPolys->Contains( aRefPos, -1, aAccuracy );
1094}
1095
1096
1097bool ZONE::HitTestCutout( const VECTOR2I& aRefPos, int* aOutlineIdx, int* aHoleIdx ) const
1098{
1099 VECTOR2I libPos = aRefPos;
1100
1101 if( const FOOTPRINT* fp = GetParentFootprint() )
1102 libPos = fp->GetTransform().InverseApply( aRefPos );
1103
1104 // Iterate over each outline polygon in the zone and then iterate over
1105 // each hole it has to see if the point is in it.
1106 for( int i = 0; i < m_Poly->OutlineCount(); i++ )
1107 {
1108 for( int j = 0; j < m_Poly->HoleCount( i ); j++ )
1109 {
1110 if( m_Poly->Hole( i, j ).PointInside( libPos ) )
1111 {
1112 if( aOutlineIdx )
1113 *aOutlineIdx = i;
1114
1115 if( aHoleIdx )
1116 *aHoleIdx = j;
1117
1118 return true;
1119 }
1120 }
1121 }
1122
1123 return false;
1124}
1125
1126
1127void ZONE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1128{
1129 wxString msg = GetFriendlyName();
1130
1131 aList.emplace_back( _( "Type" ), msg );
1132
1133 if( GetIsRuleArea() )
1134 {
1135 msg.Empty();
1136
1137 if( GetDoNotAllowVias() )
1138 AccumulateDescription( msg, _( "No vias" ) );
1139
1140 if( GetDoNotAllowTracks() )
1141 AccumulateDescription( msg, _( "No tracks" ) );
1142
1143 if( GetDoNotAllowPads() )
1144 AccumulateDescription( msg, _( "No pads" ) );
1145
1147 AccumulateDescription( msg, _( "No zone fills" ) );
1148
1150 AccumulateDescription( msg, _( "No footprints" ) );
1151
1152 if( !msg.IsEmpty() )
1153 aList.emplace_back( _( "Restrictions" ), msg );
1154
1156 aList.emplace_back( _( "Placement source" ), UnescapeString( GetPlacementAreaSource() ) );
1157 }
1158 else if( IsOnCopperLayer() )
1159 {
1160 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME )
1161 {
1162 aList.emplace_back( _( "Net" ), UnescapeString( GetNetname() ) );
1163
1164 aList.emplace_back( _( "Resolved Netclass" ),
1165 UnescapeString( GetEffectiveNetClass()->GetHumanReadableName() ) );
1166 }
1167
1168 // Display priority level
1169 aList.emplace_back( _( "Priority" ), wxString::Format( wxT( "%d" ), GetAssignedPriority() ) );
1170 }
1171
1172 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME )
1173 {
1174 if( IsLocked() )
1175 aList.emplace_back( _( "Status" ), _( "Locked" ) );
1176 }
1177
1178 LSEQ layers = m_layerSet.Seq();
1179 wxString layerDesc;
1180
1181 if( layers.size() == 1 )
1182 {
1183 layerDesc.Printf( _( "%s" ), GetLayerName( layers[0] ) );
1184 }
1185 else if( layers.size() == 2 )
1186 {
1187 layerDesc.Printf( _( "%s and %s" ), GetLayerName( layers[0] ), GetLayerName( layers[1] ) );
1188 }
1189 else if( layers.size() == 3 )
1190 {
1191 layerDesc.Printf( _( "%s, %s and %s" ), GetLayerName( layers[0] ), GetLayerName( layers[1] ),
1192 GetLayerName( layers[2] ) );
1193 }
1194 else if( layers.size() > 3 )
1195 {
1196 layerDesc.Printf( _( "%s, %s and %d more" ), GetLayerName( layers[0] ), GetLayerName( layers[1] ),
1197 static_cast<int>( layers.size() - 2 ) );
1198 }
1199
1200 aList.emplace_back( _( "Layer" ), layerDesc );
1201
1202 if( !m_zoneName.empty() )
1203 aList.emplace_back( _( "Name" ), m_zoneName );
1204
1205 if( !GetIsRuleArea() ) // Show fill mode only for not rule areas
1206 {
1207 switch( m_fillMode )
1208 {
1209 case ZONE_FILL_MODE::POLYGONS: msg = _( "Solid" ); break;
1210 case ZONE_FILL_MODE::HATCH_PATTERN: msg = _( "Hatched" ); break;
1211 default: msg = _( "Unknown" ); break;
1212 }
1213
1214 aList.emplace_back( _( "Fill Mode" ), msg );
1215
1216 aList.emplace_back( _( "Filled Area" ),
1218
1219 wxString source;
1221
1222 if( !source.IsEmpty() )
1223 {
1224 aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ), aFrame->MessageTextFromValue( clearance ) ),
1225 wxString::Format( _( "(from %s)" ), source ) );
1226 }
1227 }
1228
1229 int count = 0;
1230
1231 if( GetIsRuleArea() )
1232 {
1233 double outline_area = CalculateOutlineArea();
1234 aList.emplace_back( _( "Outline Area" ),
1235 aFrame->MessageTextFromValue( outline_area, true, EDA_DATA_TYPE::AREA ) );
1236
1237 // No need to determine board vs. library outline. They'll have the same number of points.
1238 const SHAPE_POLY_SET* area_outline = Outline();
1239 count = area_outline->FullPointCount();
1240 }
1241 else if( !m_FilledPolysList.empty() )
1242 {
1243 for( std::pair<const PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>>& ii: m_FilledPolysList )
1244 count += ii.second->TotalVertices();
1245 }
1246
1247 aList.emplace_back( _( "Corner Count" ), wxString::Format( wxT( "%d" ), count ) );
1248}
1249
1250
1251void ZONE::Move( const VECTOR2I& offset )
1252{
1253 VECTOR2I outlineOffset = offset;
1254
1255 if( const FOOTPRINT* fp = GetParentFootprint() )
1256 {
1257 const TRANSFORM_TRS& xform = fp->GetTransform();
1258 outlineOffset = xform.InverseApply( offset ) - xform.InverseApply( VECTOR2I( 0, 0 ) );
1259 }
1260
1261 m_Poly->Move( outlineOffset );
1262
1263 // Translate existing hatch lines instead of regenerating them. HatchBorder() is expensive
1264 // (O(n*m) segment intersections + point-in-polygon tests) and the hatch pattern is
1265 // invariant under translation.
1266 for( SEG& seg : m_borderHatchLines )
1267 {
1268 seg.A += outlineOffset;
1269 seg.B += outlineOffset;
1270 }
1271
1272 /* move fills */
1273 for( std::pair<const PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>>& pair : m_FilledPolysList )
1274 pair.second->Move( offset );
1275
1276 /*
1277 * move boundingbox cache
1278 *
1279 * While the cache will get nuked at the conclusion of the operation, we use it for some
1280 * things (such as drawing the parent group) during the move.
1281 */
1282 if( GetBoard() )
1283 {
1284 auto it = GetBoard()->m_ZoneBBoxCache.find( this );
1285
1286 if( it != GetBoard()->m_ZoneBBoxCache.end() )
1287 it->second.Move( offset );
1288 }
1289
1290 // Move doesn't bump the board timestamp, so invalidate the lock-free copy rather than race
1291 // readers by mutating it. GetBoundingBox() falls back to the board cache (moved above).
1292 m_bboxCacheTimeStamp.store( -1, std::memory_order_release );
1293}
1294
1295
1297{
1298 if( GetIsRuleArea() )
1299 return _( "Rule Area" );
1300 else if( IsTeardropArea() )
1301 return _( "Teardrop Area" );
1302 else if( IsOnCopperLayer() )
1303 return _( "Copper Zone" );
1304 else
1305 return _( "Non-copper Zone" );
1306}
1307
1308
1309void ZONE::MoveEdge( const VECTOR2I& offset, int aEdge )
1310{
1311 int next_corner;
1312
1313 if( m_Poly->GetNeighbourIndexes( aEdge, nullptr, &next_corner ) )
1314 {
1315 VECTOR2I libOffset = offset;
1316
1317 if( const FOOTPRINT* fp = GetParentFootprint() )
1318 {
1319 const TRANSFORM_TRS& xform = fp->GetTransform();
1320 libOffset = xform.InverseApply( offset ) - xform.InverseApply( VECTOR2I( 0, 0 ) );
1321 }
1322
1323 m_Poly->SetVertex( aEdge, m_Poly->CVertex( aEdge ) + libOffset );
1324 m_Poly->SetVertex( next_corner, m_Poly->CVertex( next_corner ) + libOffset );
1325 HatchBorder();
1326
1327 SetNeedRefill( true );
1328 }
1329}
1330
1331
1332void ZONE::Rotate( const VECTOR2I& aCentre, const EDA_ANGLE& aAngle )
1333{
1334 VECTOR2I outlineCentre = aCentre;
1335
1336 if( const FOOTPRINT* fp = GetParentFootprint() )
1337 outlineCentre = fp->GetTransform().InverseApply( aCentre );
1338
1339 m_Poly->Rotate( aAngle, outlineCentre );
1341 HatchBorder();
1342
1343 /* rotate filled areas: */
1344 for( std::pair<const PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>>& pair : m_FilledPolysList )
1345 pair.second->Rotate( aAngle, aCentre );
1346}
1347
1348
1349void ZONE::OnFootprintRescaled( double aRatioX, double aRatioY, double /* aLinearFactor */,
1350 const VECTOR2I& /* aAnchor */, const EDA_ANGLE& /* aParentRotate */ )
1351{
1352 if( aRatioX == 1.0 && aRatioY == 1.0 )
1353 return;
1354
1355 // Zone outline auto-derives from lib storage through the parent transform.
1356 // Just invalidate the fill since geometry-on-screen has changed.
1358 SetNeedRefill( true );
1359 UnFill();
1360}
1361
1362
1363void ZONE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
1364{
1365 Mirror( aCentre, aFlipDirection );
1366
1367 std::map<PCB_LAYER_ID, SHAPE_POLY_SET> fillsCopy;
1368
1369 for( auto& [oldLayer, shapePtr] : m_FilledPolysList )
1370 fillsCopy[oldLayer] = *shapePtr;
1371
1372 std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES> layerPropertiesCopy = m_layerProperties;
1373
1374 LSET flipped;
1375
1376 for( PCB_LAYER_ID layer : GetLayerSet() )
1377 flipped.set( GetFlippedLayer( layer ) );
1378
1379 SetLayerSet( flipped );
1380
1381 for( auto& [oldLayer, properties] : layerPropertiesCopy )
1382 {
1383 PCB_LAYER_ID newLayer = GetFlippedLayer( oldLayer );
1384 m_layerProperties[newLayer] = properties;
1385 }
1386
1387 for( auto& [oldLayer, shape] : fillsCopy )
1388 {
1389 PCB_LAYER_ID newLayer = GetFlippedLayer( oldLayer );
1390 SetFilledPolysList( newLayer, shape );
1391 }
1392}
1393
1394
1395void ZONE::Mirror( const VECTOR2I& aMirrorRef, FLIP_DIRECTION aFlipDirection )
1396{
1397 VECTOR2I outlineRef = aMirrorRef;
1398
1399 if( const FOOTPRINT* fp = GetParentFootprint() )
1400 outlineRef = fp->GetTransform().InverseApply( aMirrorRef );
1401
1402 m_Poly->Mirror( outlineRef, aFlipDirection );
1404
1405 HatchBorder();
1406
1407 for( std::pair<const PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>>& pair : m_FilledPolysList )
1408 pair.second->Mirror( aMirrorRef, aFlipDirection );
1409}
1410
1411
1412void ZONE::RemoveCutout( int aOutlineIdx, int aHoleIdx )
1413{
1414 // Ensure the requested cutout is valid
1415 if( m_Poly->OutlineCount() < aOutlineIdx || m_Poly->HoleCount( aOutlineIdx ) < aHoleIdx )
1416 return;
1417
1418 SHAPE_POLY_SET cutPoly( m_Poly->Hole( aOutlineIdx, aHoleIdx ) );
1419
1420 // Add the cutout back to the zone
1421 m_Poly->BooleanAdd( cutPoly );
1422
1423 SetNeedRefill( true );
1424}
1425
1426
1427void ZONE::AddPolygon( const SHAPE_LINE_CHAIN& aPolygon )
1428{
1429 wxASSERT( aPolygon.IsClosed() );
1430
1431 // Add the outline as a new polygon in the polygon set
1432 if( m_Poly->OutlineCount() == 0 )
1433 m_Poly->AddOutline( aPolygon );
1434 else
1435 m_Poly->AddHole( aPolygon );
1436
1437 SetNeedRefill( true );
1438}
1439
1440
1441void ZONE::AddPolygon( std::vector<VECTOR2I>& aPolygon )
1442{
1443 if( aPolygon.empty() )
1444 return;
1445
1446 SHAPE_LINE_CHAIN outline;
1447
1448 // Create an outline and populate it with the points of aPolygon
1449 for( const VECTOR2I& pt : aPolygon )
1450 outline.Append( pt );
1451
1452 outline.SetClosed( true );
1453
1454 AddPolygon( outline );
1455}
1456
1457
1458bool ZONE::AppendCorner( const VECTOR2I& aPosition, int aHoleIdx, bool aAllowDuplication )
1459{
1460 // Ensure the main outline exists:
1461 if( m_Poly->OutlineCount() == 0 )
1462 m_Poly->NewOutline();
1463
1464 // If aHoleIdx >= 0, the corner musty be added to the hole, index aHoleIdx.
1465 // (remember: the index of the first hole is 0)
1466 // Return error if it does not exist.
1467 if( aHoleIdx >= m_Poly->HoleCount( 0 ) )
1468 return false;
1469
1470 m_Poly->Append( aPosition.x, aPosition.y, -1, aHoleIdx, aAllowDuplication );
1471
1472 SetNeedRefill( true );
1473
1474 return true;
1475}
1476
1477
1478wxString ZONE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1479{
1480 LSEQ layers = m_layerSet.Seq();
1481 wxString layerDesc;
1482
1483 auto layerName =
1484 [this]( PCB_LAYER_ID aLayer ) -> wxString
1485 {
1486 if( const BOARD* board = GetBoard() )
1487 return board->GetLayerName( aLayer );
1488
1489 return BOARD::GetStandardLayerName( aLayer );
1490 };
1491
1492 if( layers.size() == 1 )
1493 {
1494 layerDesc.Printf( _( "on %s" ), layerName( layers[0] ) );
1495 }
1496 else if (layers.size() == 2 )
1497 {
1498 layerDesc.Printf( _( "on %s and %s" ),
1499 layerName( layers[0] ),
1500 layerName( layers[1] ) );
1501 }
1502 else if (layers.size() == 3 )
1503 {
1504 layerDesc.Printf( _( "on %s, %s and %s" ),
1505 layerName( layers[0] ),
1506 layerName( layers[1] ),
1507 layerName( layers[2] ) );
1508 }
1509 else if( layers.size() > 3 )
1510 {
1511 layerDesc.Printf( _( "on %s, %s and %zu more" ),
1512 layerName( layers[0] ),
1513 layerName( layers[1] ),
1514 layers.size() - 2 );
1515 }
1516
1517 if( GetIsRuleArea() )
1518 {
1519 if( GetZoneName().IsEmpty() )
1520 {
1521 return wxString::Format( _( "Rule Area %s" ), layerDesc );
1522 }
1523 else
1524 {
1525 return wxString::Format( _( "Rule area '%s' %s" ),
1526 GetZoneName(),
1527 layerDesc );
1528 }
1529 }
1530 else if( IsTeardropArea() )
1531 {
1532 return wxString::Format( _( "Teardrop %s %s" ),
1533 GetNetnameMsg(),
1534 layerDesc );
1535 }
1536 else
1537 {
1538 if( GetZoneName().IsEmpty() )
1539 {
1540 return wxString::Format( _( "Zone %s %s, priority %d" ),
1541 GetNetnameMsg(),
1542 layerDesc,
1544 }
1545 else
1546 {
1547 return wxString::Format( _( "Zone '%s' %s %s, priority %d" ),
1548 GetZoneName(),
1549 GetNetnameMsg(),
1550 layerDesc,
1552 }
1553 }
1554}
1555
1556
1557void ZONE::SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch,
1558 bool aRebuildBorderHatch )
1559{
1560 aBorderHatchPitch = std::max( aBorderHatchPitch, pcbIUScale.mmToIU( ZONE_BORDER_HATCH_MINDIST_MM ) );
1561 aBorderHatchPitch = std::min( aBorderHatchPitch, pcbIUScale.mmToIU( ZONE_BORDER_HATCH_MAXDIST_MM ) );
1562 SetBorderHatchPitch( aBorderHatchPitch );
1563 m_borderStyle = aBorderHatchStyle;
1564
1565 if( aRebuildBorderHatch )
1566 HatchBorder();
1567}
1568
1569
1571{
1572 m_borderHatchLines.clear();
1573}
1574
1575
1577{
1578 UnHatchBorder();
1579
1581 || m_borderHatchPitch == 0
1582 || m_Poly->IsEmpty() )
1583 {
1584 return;
1585 }
1586
1587 // set the "length" of hatch lines (the length on horizontal axis)
1588 int hatch_line_len = m_borderHatchPitch; // OK for DIAGONAL_EDGE style
1589
1590 // Calculate spacing between 2 hatch lines
1591 int spacing = m_borderHatchPitch; // OK for DIAGONAL_EDGE style
1592
1594 {
1595 // The spacing is twice the spacing for DIAGONAL_EDGE because one
1596 // full diagonal replaces 2 edge diagonal hatch segments in code
1597 spacing = m_borderHatchPitch * 2;
1598 hatch_line_len = -1; // Use full diagonal hatch line
1599 }
1600
1601 // To have a better look, give a slope depending on the layer
1602 int layer = GetFirstLayer();
1603 std::vector<double> slopes;
1604
1605 if( IsTeardropArea() )
1606 slopes = { 0.7, -0.7 };
1607 else if( layer & 1 )
1608 slopes = { 1 };
1609 else
1610 slopes = { -1 };
1611
1612 m_borderHatchLines = m_Poly->GenerateHatchLines( slopes, spacing, hatch_line_len );
1613}
1614
1615
1616std::vector<SEG> ZONE::GetHatchLines() const
1617{
1618 const FOOTPRINT* fp = GetParentFootprint();
1619
1620 if( !fp )
1621 return m_borderHatchLines;
1622
1623 const TRANSFORM_TRS& xform = fp->GetTransform();
1624 std::vector<SEG> result;
1625 result.reserve( m_borderHatchLines.size() );
1626
1627 for( const SEG& seg : m_borderHatchLines )
1628 result.emplace_back( xform.Apply( seg.A ), xform.Apply( seg.B ) );
1629
1630 return result;
1631}
1632
1633
1635{
1636 return pcbIUScale.mmToIU( ZONE_BORDER_HATCH_DIST_MM );
1637}
1638
1639
1641{
1642 return BITMAPS::add_zone;
1643}
1644
1645
1647{
1648 wxASSERT( aImage->Type() == PCB_ZONE_T );
1649
1650 std::swap( *static_cast<ZONE*>( this ), *static_cast<ZONE*>( aImage) );
1651}
1652
1653
1654std::vector<PCB_LAYER_ID> ZONE::GetFilledLayers() const
1655{
1656 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
1657
1658 std::vector<PCB_LAYER_ID> layers;
1659
1660 layers.reserve( m_FilledPolysList.size() );
1661
1662 for( const auto& [ layer, poly ] : m_FilledPolysList )
1663 layers.push_back( layer );
1664
1665 return layers;
1666}
1667
1668
1670{
1671 m_Poly->CacheTriangulation();
1672}
1673
1674
1676{
1677 if( aLayer == UNDEFINED_LAYER )
1678 {
1679 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
1680
1681 for( auto& [ layer, poly ] : m_FilledPolysList )
1682 poly->CacheTriangulation( false, aSubmitter );
1683
1684 m_Poly->CacheTriangulation();
1685 }
1686 else
1687 {
1688 // Grab a shared_ptr copy under the lock, then triangulate outside it.
1689 // Each layer's SHAPE_POLY_SET is independent, so concurrent triangulation
1690 // of different layers is safe once we have the shared_ptr.
1691 std::shared_ptr<SHAPE_POLY_SET> poly;
1692
1693 {
1694 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
1695
1696 auto it = m_FilledPolysList.find( aLayer );
1697
1698 if( it != m_FilledPolysList.end() )
1699 poly = it->second;
1700 }
1701
1702 if( poly )
1703 poly->CacheTriangulation( false, aSubmitter );
1704 }
1705}
1706
1707
1708bool ZONE::IsIsland( PCB_LAYER_ID aLayer, int aPolyIdx ) const
1709{
1710 if( GetNetCode() < 1 )
1711 return true;
1712
1713 if( !m_insulatedIslands.count( aLayer ) )
1714 return false;
1715
1716 return m_insulatedIslands.at( aLayer ).count( aPolyIdx );
1717}
1718
1719
1720void ZONE::GetInteractingZones( PCB_LAYER_ID aLayer, std::vector<ZONE*>* aSameNetCollidingZones,
1721 std::vector<ZONE*>* aOtherNetIntersectingZones ) const
1722{
1723 if( !GetBoard() )
1724 return;
1725
1726 int epsilon = pcbIUScale.mmToIU( 0.001 );
1727 BOX2I bbox = GetBoundingBox();
1728
1729 bbox.Inflate( epsilon );
1730
1731 for( ZONE* candidate : GetBoard()->Zones() )
1732 {
1733 if( candidate == this )
1734 continue;
1735
1736 if( !candidate->GetLayerSet().test( aLayer ) )
1737 continue;
1738
1739 if( candidate->GetIsRuleArea() || candidate->IsTeardropArea() )
1740 continue;
1741
1742 if( !candidate->GetBoundingBox().Intersects( bbox ) )
1743 continue;
1744
1745 if( candidate->GetNetCode() == GetNetCode() )
1746 {
1747 SHAPE_POLY_SET selfOutlineStorage;
1748 const SHAPE_POLY_SET* selfOutline = &selfOutlineStorage;
1749 SHAPE_POLY_SET candidateOutlineStorage;
1750 const SHAPE_POLY_SET* candidateOutline = &candidateOutlineStorage;
1751
1752 // GetBoardOutline() is expensive. Don't use it in Zone Filler unless we have to.
1753 if( GetParentFootprint() )
1754 selfOutlineStorage = GetBoardOutline();
1755 else
1756 selfOutline = Outline();
1757
1758 if( candidate->GetParentFootprint() )
1759 candidateOutlineStorage = candidate->GetBoardOutline();
1760 else
1761 candidateOutline = candidate->Outline();
1762
1763 if( selfOutline->Collide( candidateOutline ) )
1764 aSameNetCollidingZones->push_back( candidate );
1765 }
1766 else
1767 {
1768 aOtherNetIntersectingZones->push_back( candidate );
1769 }
1770 }
1771}
1772
1773
1774bool ZONE::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET* aBoardOutline,
1775 SHAPE_POLY_SET* aSmoothedPolyWithApron ) const
1776{
1777 if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations will not like it ...
1778 return false;
1779
1780 // Processing of arc shapes in zones is not yet supported because Clipper can't do boolean
1781 // operations on them. The poly outline must be converted to segments first.
1782 SHAPE_POLY_SET flattened = GetBoardOutline();
1783 flattened.ClearArcs();
1784
1785 if( GetIsRuleArea() )
1786 {
1787 // We like keepouts just the way they are....
1788 aSmoothedPoly = std::move( flattened );
1789 return true;
1790 }
1791
1792 const BOARD* board = GetBoard();
1793 bool keepExternalFillets = false;
1794
1797
1798 if( IsTeardropArea() )
1799 {
1800 // We use teardrop shapes with no smoothing; these shapes are already optimized
1801 smooth_requested = false;
1802 }
1803
1804 if( board )
1805 keepExternalFillets = board->GetDesignSettings().m_ZoneKeepExternalFillets;
1806
1807 auto smooth =
1808 [&]( SHAPE_POLY_SET& aPoly )
1809 {
1810 if( !smooth_requested )
1811 return;
1812
1813 switch( m_cornerSmoothingType )
1814 {
1816 aPoly = aPoly.Chamfer( (int) m_cornerRadius );
1817 break;
1818
1820 aPoly = aPoly.Fillet( (int) m_cornerRadius, GetMaxError() );
1821 break;
1822
1823 default:
1824 break;
1825 }
1826 };
1827
1828 SHAPE_POLY_SET* maxExtents = &flattened;
1829 SHAPE_POLY_SET withFillets;
1830
1831 aSmoothedPoly = flattened;
1832
1833 // Should external fillets (that is, those applied to concave corners) be kept? While it
1834 // seems safer to never have copper extend outside the zone outline, 5.1.x and prior did
1835 // indeed fill them so we leave the mode available.
1836 if( keepExternalFillets && smooth_requested )
1837 {
1838 withFillets = flattened;
1839 smooth( withFillets );
1840 withFillets.BooleanAdd( flattened );
1841 maxExtents = &withFillets;
1842 }
1843
1844 // We now add in the areas of any same-net, intersecting zones. This keeps us from smoothing
1845 // corners at an intersection (which often produces undesired divots between the intersecting
1846 // zones -- see #2752).
1847 //
1848 // After smoothing, we'll subtract back out everything outside of our zone.
1849 std::vector<ZONE*> sameNetCollidingZones;
1850 std::vector<ZONE*> diffNetIntersectingZones;
1851 GetInteractingZones( aLayer, &sameNetCollidingZones, &diffNetIntersectingZones );
1852
1853 for( ZONE* sameNetZone : sameNetCollidingZones )
1854 {
1855 BOX2I sameNetBoundingBox = sameNetZone->GetBoundingBox();
1856
1857 // Note: a two-pass algorithm could use sameNetZone's actual fill instead of its outline.
1858 // This would obviate the need for the below wrinkles, in addition to fixing both issues
1859 // in #16095.
1860 // (And we wouldn't need to collect all the diffNetIntersectingZones either.)
1861
1862 SHAPE_POLY_SET sameNetPoly = sameNetZone->GetBoardOutline();
1863 sameNetPoly.ClearArcs();
1864
1865 SHAPE_POLY_SET diffNetPoly;
1866
1867 // Of course there's always a wrinkle. The same-net intersecting zone *might* get knocked
1868 // out along the border by a higher-priority, different-net zone. #12797
1869 for( ZONE* diffNetZone : diffNetIntersectingZones )
1870 {
1871 if( diffNetZone->HigherPriority( sameNetZone )
1872 && diffNetZone->GetBoundingBox().Intersects( sameNetBoundingBox ) )
1873 {
1874 SHAPE_POLY_SET diffNetOutline = diffNetZone->GetBoardOutline();
1875 diffNetOutline.ClearArcs();
1876
1877 diffNetPoly.BooleanAdd( diffNetOutline );
1878 }
1879 }
1880
1881 // Second wrinkle. After unioning the higher priority, different net zones together, we
1882 // need to check to see if they completely enclose our zone. If they do, then we need to
1883 // treat the enclosed zone as isolated, not connected to the outer zone. #13915
1884 bool isolated = false;
1885
1886 if( diffNetPoly.OutlineCount() )
1887 {
1888 SHAPE_POLY_SET thisPoly = GetBoardOutline();
1889 thisPoly.ClearArcs();
1890
1891 thisPoly.BooleanSubtract( diffNetPoly );
1892 isolated = thisPoly.OutlineCount() == 0;
1893 }
1894
1895 if( !isolated )
1896 aSmoothedPoly.BooleanAdd( sameNetPoly );
1897 }
1898
1899 if( aBoardOutline )
1900 {
1901 SHAPE_POLY_SET boardOutline = aBoardOutline->CloneDropTriangulation();
1902 boardOutline.ClearArcs();
1903
1904 aSmoothedPoly.BooleanIntersection( boardOutline );
1905 }
1906
1907 SHAPE_POLY_SET withSameNetIntersectingZones = aSmoothedPoly.CloneDropTriangulation();
1908
1909 smooth( aSmoothedPoly );
1910
1911 if( aSmoothedPolyWithApron )
1912 {
1913 // The same-net intersecting-zone code above makes sure the corner-smoothing algorithm
1914 // doesn't produce divots. But the min-thickness algorithm applied in fillCopperZone()
1915 // is *also* going to perform a deflate/inflate cycle, again leading to divots. So we
1916 // pre-inflate the contour by the min-thickness within the same-net-intersecting-zones
1917 // envelope.
1918 SHAPE_POLY_SET poly = maxExtents->CloneDropTriangulation();
1920
1921 if( !keepExternalFillets )
1922 poly.BooleanIntersection( withSameNetIntersectingZones );
1923
1924 *aSmoothedPolyWithApron = aSmoothedPoly;
1925 aSmoothedPolyWithApron->BooleanIntersection( poly );
1926 }
1927
1928 aSmoothedPoly.BooleanIntersection( *maxExtents );
1929
1930 return true;
1931}
1932
1933
1935{
1936 m_area = 0.0;
1937
1938 for( const auto& [layer, poly] : m_FilledPolysList )
1939 m_area += poly->Area();
1940
1941 return m_area;
1942}
1943
1944
1946{
1947 m_outlinearea = std::abs( m_Poly->Area() );
1948 return m_outlinearea;
1949}
1950
1951
1953 int aMaxError, ERROR_LOC aErrorLoc, SHAPE_POLY_SET* aBoardOutline ) const
1954{
1955 // Creates the zone outline polygon (with holes if any)
1956 SHAPE_POLY_SET polybuffer;
1957
1958 BuildSmoothedPoly( polybuffer, aLayer, aBoardOutline );
1959
1960 // Calculate the polygon with clearance
1961 // holes are linked to the main outline, so only one polygon is created.
1962 if( aClearance )
1963 {
1964 if( aErrorLoc == ERROR_OUTSIDE )
1965 aClearance += GetMaxError();
1966
1967 polybuffer.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, GetMaxError() );
1968 }
1969
1970 polybuffer.Fracture();
1971 aBuffer.Append( polybuffer );
1972}
1973
1974
1975std::shared_ptr<SHAPE> ZONE::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING, DRC_CONSTRAINT_T ) const
1976{
1977 // Rule areas are never filled, so fall back to the outline. DRC relies on this to collide tracks,
1978 // vias and pads against keepout areas.
1979 if( GetIsRuleArea() )
1980 {
1981 // GetBoardOutline() is expensive. Don't use it in DRC if we don't have to.
1982 if( GetParentFootprint() )
1983 return std::make_shared<SHAPE_POLY_SET>( GetBoardOutline() );
1984 else
1985 return std::make_shared<SHAPE_POLY_SET>( *Outline() );
1986 }
1987
1988 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
1989
1990 if( m_FilledPolysList.find( aLayer ) == m_FilledPolysList.end() )
1991 return std::make_shared<SHAPE_NULL>();
1992 else
1993 return m_FilledPolysList.at( aLayer );
1994}
1995
1996
1997double ZONE::GetCoverageArea( int aTextMargin ) const
1998{
1999 if( !GetIsRuleArea() )
2000 {
2001 // Unioning the layer fills stalls selection on a hatched plane. The largest layer is
2002 // exact for a single layer and bounds the union for the rest, which is enough to rank
2003 bool filled = false;
2004 double largest = 0.0;
2005
2006 for( PCB_LAYER_ID layer : GetLayerSet() )
2007 {
2008 if( !HasFilledPolysForLayer( layer ) )
2009 continue;
2010
2011 std::shared_ptr<SHAPE_POLY_SET> fill = GetFilledPolysList( layer );
2012
2013 if( fill->OutlineCount() == 0 )
2014 continue;
2015
2016 filled = true;
2017 largest = std::max( largest, fill->Area() );
2018 }
2019
2020 if( filled )
2021 return largest;
2022 }
2023
2024 // Rule areas are never filled, so TransformShapeToPolygon would report a zero coverage
2025 // area and make them appear as the smallest item under the cursor. That incorrectly
2026 // gives them selection precedence over the pads, tracks and footprints they enclose.
2027 // Use the outline area so an enclosed item is selected first while the rule area stays
2028 // available via its border and the disambiguation menu. An unfilled zone falls back the
2029 // same way so it does not collapse to a zero coverage area.
2030 SHAPE_POLY_SET outline = *m_Poly;
2031 return polygonArea( outline );
2032}
2033
2034
2035void ZONE::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
2036 int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth ) const
2037{
2038 wxASSERT_MSG( !aIgnoreLineWidth, wxT( "IgnoreLineWidth has no meaning for zones." ) );
2039
2040 std::shared_ptr<SHAPE_POLY_SET> fillPolys;
2041
2042 {
2043 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
2044
2045 if( !m_FilledPolysList.count( aLayer ) )
2046 return;
2047
2048 fillPolys = m_FilledPolysList.at( aLayer );
2049 }
2050
2051 if( !aClearance )
2052 {
2053 aBuffer.Append( *fillPolys );
2054 return;
2055 }
2056
2057 SHAPE_POLY_SET temp_buf = fillPolys->CloneDropTriangulation();
2058
2059 // Rebuild filled areas only if clearance is not 0
2060 if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
2061 {
2062 if( aErrorLoc == ERROR_OUTSIDE )
2063 aClearance += aError;
2064
2065 temp_buf.InflateWithLinkedHoles( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aError );
2066 }
2067
2068 aBuffer.Append( temp_buf );
2069}
2070
2071
2073{
2074 std::lock_guard<std::mutex> lock( m_filledPolysListMutex );
2075
2076 if( m_FilledPolysList.count( aLayer ) && !m_FilledPolysList.at( aLayer )->IsEmpty() )
2077 aBuffer.Append( *m_FilledPolysList.at( aLayer ) );
2078}
2079
2080
2082{
2083 if( aLayerSet.count() == 0 )
2084 return;
2085
2086 std::scoped_lock lock( m_layerSetMutex, m_filledPolysListMutex );
2087
2088 if( m_layerSet != aLayerSet )
2089 {
2090 aLayerSet.RunOnLayers(
2091 [&]( PCB_LAYER_ID layer )
2092 {
2093 // Only keep layers that are present in the new set
2094 if( !aLayerSet.Contains( layer ) )
2095 {
2096 m_FilledPolysList[layer] = std::make_shared<SHAPE_POLY_SET>();
2097 m_filledPolysHash[layer] = {};
2098 m_insulatedIslands[layer] = {};
2099 }
2100 } );
2101 }
2102
2103 m_layerSet = aLayerSet;
2104}
2105
2106
2107bool ZONE::operator==( const BOARD_ITEM& aOther ) const
2108{
2109 if( aOther.Type() != Type() )
2110 return false;
2111
2112 const ZONE& other = static_cast<const ZONE&>( aOther );
2113 return *this == other;
2114}
2115
2116
2117bool ZONE::operator==( const ZONE& aOther ) const
2118
2119{
2120 if( aOther.Type() != Type() )
2121 return false;
2122
2123 const ZONE& other = static_cast<const ZONE&>( aOther );
2124
2125 if( GetIsRuleArea() != other.GetIsRuleArea() )
2126 return false;
2127
2128 if( GetIsRuleArea() )
2129 {
2131 return false;
2132
2133 if( GetDoNotAllowTracks() != other.GetDoNotAllowTracks() )
2134 return false;
2135
2136 if( GetDoNotAllowVias() != other.GetDoNotAllowVias() )
2137 return false;
2138
2140 return false;
2141
2142 if( GetDoNotAllowPads() != other.GetDoNotAllowPads() )
2143 return false;
2144
2146 return false;
2147
2149 return false;
2150
2152 return false;
2153 }
2154 else
2155 {
2156 if( GetAssignedPriority() != other.GetAssignedPriority() )
2157 return false;
2158
2159 if( GetMinThickness() != other.GetMinThickness() )
2160 return false;
2161
2163 return false;
2164
2165 if( GetCornerRadius() != other.GetCornerRadius() )
2166 return false;
2167
2168 if( GetTeardropParams() != other.GetTeardropParams() )
2169 return false;
2170 }
2171
2172 if( GetNumCorners() != other.GetNumCorners() )
2173 return false;
2174
2175 for( int ii = 0; ii < GetNumCorners(); ii++ )
2176 {
2177 if( GetCornerPosition( ii ) != other.GetCornerPosition( ii ) )
2178 return false;
2179 }
2180
2181 return true;
2182}
2183
2184
2185double ZONE::Similarity( const BOARD_ITEM& aOther ) const
2186{
2187 if( aOther.Type() != Type() )
2188 return 0.0;
2189
2190 const ZONE& other = static_cast<const ZONE&>( aOther );
2191
2192 if( GetIsRuleArea() != other.GetIsRuleArea() )
2193 return 0.0;
2194
2195 double similarity = 1.0;
2196
2197 if( GetLayerSet() != other.GetLayerSet() )
2198 similarity *= 0.9;
2199
2200 if( GetNetCode() != other.GetNetCode() )
2201 similarity *= 0.9;
2202
2203 if( !GetIsRuleArea() )
2204 {
2205 if( GetAssignedPriority() != other.GetAssignedPriority() )
2206 similarity *= 0.9;
2207
2208 if( GetMinThickness() != other.GetMinThickness() )
2209 similarity *= 0.9;
2210
2212 similarity *= 0.9;
2213
2214 if( GetCornerRadius() != other.GetCornerRadius() )
2215 similarity *= 0.9;
2216
2217 if( GetTeardropParams() != other.GetTeardropParams() )
2218 similarity *= 0.9;
2219 }
2220 else
2221 {
2223 similarity *= 0.9;
2224 if( GetDoNotAllowTracks() != other.GetDoNotAllowTracks() )
2225 similarity *= 0.9;
2226 if( GetDoNotAllowVias() != other.GetDoNotAllowVias() )
2227 similarity *= 0.9;
2229 similarity *= 0.9;
2230 if( GetDoNotAllowPads() != other.GetDoNotAllowPads() )
2231 similarity *= 0.9;
2232 }
2233
2234 std::vector<VECTOR2I> corners;
2235 std::vector<VECTOR2I> otherCorners;
2236 VECTOR2I lastCorner( 0, 0 );
2237
2238 for( int ii = 0; ii < GetNumCorners(); ii++ )
2239 {
2240 corners.push_back( lastCorner - GetCornerPosition( ii ) );
2241 lastCorner = GetCornerPosition( ii );
2242 }
2243
2244 lastCorner = VECTOR2I( 0, 0 );
2245 for( int ii = 0; ii < other.GetNumCorners(); ii++ )
2246 {
2247 otherCorners.push_back( lastCorner - other.GetCornerPosition( ii ) );
2248 lastCorner = other.GetCornerPosition( ii );
2249 }
2250
2251 size_t longest = alg::longest_common_subset( corners, otherCorners );
2252
2253 similarity *= std::pow( 0.9, GetNumCorners() + other.GetNumCorners() - 2 * longest );
2254
2255 return similarity;
2256}
2257
2258
2259static struct ZONE_DESC
2260{
2262 {
2264
2265 if( layerEnum.Choices().GetCount() == 0 )
2266 {
2267 layerEnum.Undefined( UNDEFINED_LAYER );
2268
2269 for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
2270 layerEnum.Map( layer, LSET::Name( layer ) );
2271 }
2272
2274
2275 if( zcMap.Choices().GetCount() == 0 )
2276 {
2278 zcMap.Map( ZONE_CONNECTION::INHERITED, _HKI( "Inherited" ) )
2279 .Map( ZONE_CONNECTION::NONE, _HKI( "None" ) )
2280 .Map( ZONE_CONNECTION::THERMAL, _HKI( "Thermal reliefs" ) )
2281 .Map( ZONE_CONNECTION::FULL, _HKI( "Solid" ) )
2282 .Map( ZONE_CONNECTION::THT_THERMAL, _HKI( "Thermal reliefs for PTH" ) );
2283 }
2284
2286
2287 if( zfmMap.Choices().GetCount() == 0 )
2288 {
2290 zfmMap.Map( ZONE_FILL_MODE::POLYGONS, _HKI( "Solid fill" ) )
2291 .Map( ZONE_FILL_MODE::HATCH_PATTERN, _HKI( "Hatch pattern" ) )
2292 .Map( ZONE_FILL_MODE::COPPER_THIEVING, _HKI( "Copper thieving" ) );
2293 }
2294
2296
2297 if( tpMap.Choices().GetCount() == 0 )
2298 {
2300 tpMap.Map( THIEVING_PATTERN::DOTS, _HKI( "Dots" ) )
2301 .Map( THIEVING_PATTERN::SQUARES, _HKI( "Squares" ) )
2302 .Map( THIEVING_PATTERN::HATCH, _HKI( "Hatch" ) );
2303 }
2304
2306
2307 if( irmMap.Choices().GetCount() == 0 )
2308 {
2310 irmMap.Map( ISLAND_REMOVAL_MODE::ALWAYS, _HKI( "Always" ) )
2311 .Map( ISLAND_REMOVAL_MODE::NEVER, _HKI( "Never" ) )
2312 .Map( ISLAND_REMOVAL_MODE::AREA, _HKI( "Below area limit" ) );
2313 }
2314
2316
2317 if( rapstMap.Choices().GetCount() == 0 )
2318 {
2320 rapstMap.Map( PLACEMENT_SOURCE_T::SHEETNAME, _HKI( "Sheet Name" ) )
2321 .Map( PLACEMENT_SOURCE_T::COMPONENT_CLASS, _HKI( "Component Class" ) )
2323 .Map( PLACEMENT_SOURCE_T::DESIGN_BLOCK, _HKI( "Design Block" ) );
2324 }
2325
2329
2330 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ),
2331 new PROPERTY<ZONE, int>( _HKI( "Position X" ),
2332 NO_SETTER( ZONE, int ), static_cast<int ( ZONE::* )() const>( &ZONE::GetX ),
2335
2336 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ),
2337 new PROPERTY<ZONE, int>( _HKI( "Position Y" ),
2338 NO_SETTER( ZONE, int ), static_cast<int ( ZONE::* )() const>( &ZONE::GetY ),
2341
2342 auto isCopperZone =
2343 []( INSPECTABLE* aItem ) -> bool
2344 {
2345 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2346 return !zone->GetIsRuleArea() && IsCopperLayer( zone->GetFirstLayer() );
2347
2348 return false;
2349 };
2350
2351 // Hide net-bearing and hatch/island properties for copper-thieving zones.
2352 // Same predicate gates both kinds of properties.
2353 auto isNonThievingCopperZone =
2354 []( INSPECTABLE* aItem ) -> bool
2355 {
2356 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2357 {
2358 return !zone->GetIsRuleArea() && IsCopperLayer( zone->GetFirstLayer() )
2359 && !zone->IsCopperThieving();
2360 }
2361
2362 return false;
2363 };
2364
2365 auto isRuleArea =
2366 []( INSPECTABLE* aItem ) -> bool
2367 {
2368 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2369 return zone->GetIsRuleArea();
2370
2371 return false;
2372 };
2373
2374 auto isHatchedFill =
2375 []( INSPECTABLE* aItem ) -> bool
2376 {
2377 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2378 return zone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN;
2379
2380 return false;
2381 };
2382
2383 auto isThievingFill =
2384 []( INSPECTABLE* aItem ) -> bool
2385 {
2386 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2387 return zone->IsCopperThieving();
2388
2389 return false;
2390 };
2391
2392 auto isThievingHatch =
2393 []( INSPECTABLE* aItem ) -> bool
2394 {
2395 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2396 return zone->IsCopperThieving() && zone->GetThievingPattern() == THIEVING_PATTERN::HATCH;
2397
2398 return false;
2399 };
2400
2401 auto isThievingNonHatch =
2402 []( INSPECTABLE* aItem ) -> bool
2403 {
2404 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2405 return zone->IsCopperThieving() && zone->GetThievingPattern() != THIEVING_PATTERN::HATCH;
2406
2407 return false;
2408 };
2409
2410 auto isAreaBasedIslandRemoval =
2411 []( INSPECTABLE* aItem ) -> bool
2412 {
2413 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
2414 return zone->GetIslandRemovalMode() == ISLAND_REMOVAL_MODE::AREA;
2415
2416 return false;
2417 };
2418
2419 // Visible for thieving zones only; ordinary zones use a layer set, not a single layer.
2420 propMgr.ReplaceProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ),
2423 .SetAvailableFunc( isThievingFill );
2424
2426 isNonThievingCopperZone );
2427 propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net Class" ),
2428 isNonThievingCopperZone );
2429
2430 propMgr.AddProperty( new PROPERTY<ZONE, unsigned>( _HKI( "Priority" ),
2432 .SetAvailableFunc( isCopperZone );
2433
2434 propMgr.AddProperty( new PROPERTY<ZONE, wxString>( _HKI( "Name" ),
2436
2437 const wxString groupKeepout = _HKI( "Keepout" );
2438
2439 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Keep Out Tracks" ),
2441 groupKeepout )
2442 .SetAvailableFunc( isRuleArea ).SetIsCopyable();
2443
2444 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Keep Out Vias" ),
2446 groupKeepout )
2447 .SetAvailableFunc( isRuleArea ).SetIsCopyable();
2448
2449 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Keep Out Pads" ),
2451 groupKeepout )
2452 .SetAvailableFunc( isRuleArea ).SetIsCopyable();
2453
2454 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Keep Out Zone Fills" ),
2456 groupKeepout )
2457 .SetAvailableFunc( isRuleArea ).SetIsCopyable();
2458
2459 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Keep Out Footprints" ),
2461 groupKeepout )
2462 .SetAvailableFunc( isRuleArea ).SetIsCopyable();
2463
2464
2465 const wxString groupPlacement = _HKI( "Placement" );
2466
2467 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Enable" ),
2469 groupPlacement )
2470 .SetAvailableFunc( isRuleArea );
2471
2472 propMgr.AddProperty( new PROPERTY_ENUM<ZONE, PLACEMENT_SOURCE_T>( _HKI( "Source Type" ),
2474 groupPlacement )
2475 .SetAvailableFunc( isRuleArea );
2476
2477 propMgr.AddProperty( new PROPERTY<ZONE, wxString>( _HKI( "Source Name" ),
2479 groupPlacement )
2480 .SetAvailableFunc( isRuleArea );
2481
2482
2483 const wxString groupFill = _HKI( "Fill Style" );
2484
2485 propMgr.AddProperty( new PROPERTY_ENUM<ZONE, ZONE_FILL_MODE>( _HKI( "Fill Mode" ),
2487 groupFill )
2488 .SetAvailableFunc( isCopperZone ).SetIsCopyable();
2489
2490 propMgr.AddProperty( new PROPERTY<ZONE, EDA_ANGLE>( _HKI( "Hatch Orientation" ),
2492 groupFill )
2493 .SetAvailableFunc( isNonThievingCopperZone )
2494 .SetWriteableFunc( isHatchedFill ).SetIsCopyable();
2495
2496 auto atLeastMinWidthValidator =
2497 []( const wxAny&& aValue, EDA_ITEM* aZone ) -> VALIDATOR_RESULT
2498 {
2499 int val = aValue.As<int>();
2500 ZONE* zone = dynamic_cast<ZONE*>( aZone );
2501 wxCHECK( zone, std::nullopt );
2502
2503 if( val < zone->GetMinThickness() )
2504 return std::make_unique<VALIDATION_ERROR_MSG>( _( "Cannot be less than zone minimum width" ) );
2505
2506 return std::nullopt;
2507 };
2508
2509 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Hatch Width" ),
2511 groupFill )
2512 .SetAvailableFunc( isNonThievingCopperZone )
2513 .SetWriteableFunc( isHatchedFill )
2514 .SetValidator( atLeastMinWidthValidator ).SetIsCopyable();
2515
2516 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Hatch Gap" ),
2518 groupFill )
2519 .SetAvailableFunc( isNonThievingCopperZone )
2520 .SetWriteableFunc( isHatchedFill )
2521 .SetValidator( atLeastMinWidthValidator ).SetIsCopyable();
2522
2523 propMgr.AddProperty( new PROPERTY<ZONE, double>( _HKI( "Hatch Minimum Hole Ratio" ),
2525 groupFill )
2526 .SetAvailableFunc( isNonThievingCopperZone )
2527 .SetWriteableFunc( isHatchedFill )
2529
2530 // TODO: Smoothing effort needs to change to enum (in dialog too)
2531 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Smoothing Effort" ),
2533 groupFill )
2534 .SetAvailableFunc( isNonThievingCopperZone )
2535 .SetWriteableFunc( isHatchedFill ).SetIsCopyable();
2536
2537 propMgr.AddProperty( new PROPERTY<ZONE, double>( _HKI( "Smoothing Amount" ),
2539 groupFill )
2540 .SetAvailableFunc( isNonThievingCopperZone )
2541 .SetWriteableFunc( isHatchedFill ).SetIsCopyable();
2542
2543 propMgr.AddProperty( new PROPERTY_ENUM<ZONE, THIEVING_PATTERN>( _HKI( "Thieving Pattern" ),
2545 groupFill )
2546 .SetAvailableFunc( isThievingFill ).SetIsCopyable();
2547
2548 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thieving Element Size" ),
2551 groupFill )
2552 .SetAvailableFunc( isThievingFill )
2553 .SetWriteableFunc( isThievingNonHatch )
2555
2556 // Gap is meaningful for all three patterns: edge-to-edge spacing between
2557 // adjacent stamps for dots/squares, line-to-line edge spacing for hatch.
2558 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thieving Gap" ),
2560 groupFill )
2561 .SetAvailableFunc( isThievingFill )
2563
2564 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thieving Line Width" ),
2567 groupFill )
2568 .SetAvailableFunc( isThievingFill )
2569 .SetWriteableFunc( isThievingHatch )
2571
2572 propMgr.AddProperty( new PROPERTY<ZONE, bool>( _HKI( "Thieving Stagger" ),
2574 groupFill )
2575 .SetAvailableFunc( isThievingFill ).SetIsCopyable();
2576
2577 propMgr.AddProperty( new PROPERTY<ZONE, EDA_ANGLE>( _HKI( "Thieving Orientation" ),
2580 groupFill )
2581 .SetAvailableFunc( isThievingFill ).SetIsCopyable();
2582
2583 propMgr.AddProperty( new PROPERTY_ENUM<ZONE, ISLAND_REMOVAL_MODE>( _HKI( "Remove Islands" ),
2585 groupFill )
2586 .SetAvailableFunc( isNonThievingCopperZone ).SetIsCopyable();
2587
2588 propMgr.AddProperty( new PROPERTY<ZONE, long long int>( _HKI( "Minimum Island Area" ),
2590 groupFill )
2591 .SetAvailableFunc( isNonThievingCopperZone )
2592 .SetWriteableFunc( isAreaBasedIslandRemoval ).SetIsCopyable();
2593
2594 const wxString groupElectrical = _HKI( "Electrical" );
2595
2596 constexpr int maxClearance = pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM );
2597 constexpr int minMinWidth = pcbIUScale.mmToIU( ZONE_THICKNESS_MIN_VALUE_MM );
2598
2599 propMgr.AddProperty( new PROPERTY<ZONE, std::optional<int>>( _HKI( "Clearance" ),
2601 groupElectrical )
2602 .SetAvailableFunc( isCopperZone )
2604
2605 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Minimum Width" ),
2607 groupElectrical )
2608 .SetAvailableFunc( isCopperZone )
2610
2611 // Pad connections and thermal-relief controls require a net to act on.
2612 // Thieving zones are netless and explicitly use ZONE_CONNECTION::NONE,
2613 // so hide these for them while keeping them visible for solid + hatched zones.
2614
2615 propMgr.AddProperty( new PROPERTY_ENUM<ZONE, ZONE_CONNECTION>( _HKI( "Pad Connections" ),
2617 groupElectrical )
2618 .SetAvailableFunc( isNonThievingCopperZone );
2619
2620 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thermal Relief Gap" ),
2622 groupElectrical )
2623 .SetAvailableFunc( isNonThievingCopperZone )
2625
2626 propMgr.AddProperty( new PROPERTY<ZONE, int>( _HKI( "Thermal Relief Spoke Width" ),
2628 groupElectrical )
2629 .SetAvailableFunc( isNonThievingCopperZone )
2630 .SetValidator( atLeastMinWidthValidator );
2631 }
2633
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:55
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_OUTSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
BASE_SET & set(size_t pos)
Definition base_set.h:126
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
void PackNet(kiapi::board::types::Net *aProto) const
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
void UnpackNet(const kiapi::board::types::Net &aProto)
Assigns a net to this item from an API message.
TEARDROP_PARAMETERS & GetTeardropParams()
ZONE_SETTINGS & GetDefaultZoneSettings()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
friend class BOARD
Definition board_item.h:606
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
int GetY() const
Definition board_item.h:139
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
static double polygonArea(SHAPE_POLY_SET &aPolySet)
Area of aPolySet with every contour closed first, holes subtracted.
int GetX() const
Definition board_item.h:133
bool IsLocked() const override
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
Definition board_item.h:103
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:266
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
int GetMaxError() const
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition board.h:1120
std::unordered_map< const ZONE *, BOX2I > m_ZoneBBoxCache
Definition board.h:1845
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1292
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:143
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:165
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:308
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
bool m_forceVisible
Definition eda_item.h:614
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:608
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:168
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:783
static ENUM_MAP< T > & Instance()
Definition property.h:777
ENUM_MAP & Undefined(T aValue)
Definition property.h:790
wxPGChoices & Choices()
Definition property.h:828
const TRANSFORM_TRS & GetTransform() const
Definition footprint.h:452
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:176
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:181
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
bool IsLayerVisibleCached(int aLayer) const
Definition view.h:450
Definition kiid.h:46
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition lset.cpp:718
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:725
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
Definition lset.h:275
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static const LSET & AllLayersMask()
Definition lset.cpp:637
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
Handle the data for a net.
Definition netinfo.h:50
Definition pad.h:61
int GetLocalThermalGapOverride(wxString *aSource) const
Definition pad.cpp:2195
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:263
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition property.h:293
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition property.h:368
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
Definition property.h:359
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition property.h:325
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
static VALIDATOR_RESULT PositiveRatioValidator(const wxAny &&aValue, EDA_ITEM *aItem)
static VALIDATOR_RESULT PositiveIntValidator(const wxAny &&aValue, EDA_ITEM *aItem)
static VALIDATOR_RESULT RangeIntValidator(const wxAny &&aValue, EDA_ITEM *aItem)
Definition seg.h:38
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
bool Intersects(const SEG &aSeg) const
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
ITERATOR IterateWithHoles(int aOutline)
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
void SetVertex(const VERTEX_INDEX &aIndex, const VECTOR2I &aPos)
Accessor function to set the position of a specific point.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int TotalVertices() const
Return total number of vertices stored in the set.
int FullPointCount() const
Return the number of points in the shape poly set.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
SEGMENT_ITERATOR IterateSegments(int aFirst, int aLast, bool aIterateHoles=false)
Return an iterator object, for iterating between aFirst and aLast outline, with or without holes (def...
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
int OutlineCount() const
Return the number of outlines in the set.
void InflateWithLinkedHoles(int aFactor, CORNER_STRATEGY aCornerStrategy, int aMaxError)
Perform outline inflation/deflation, using round corners.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
SHAPE_POLY_SET CloneDropTriangulation() const
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
std::function< void(std::function< void()>)> TASK_SUBMITTER
Callback that submits a unit of work for asynchronous execution.
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
VECTOR2I InverseApply(const VECTOR2I &aPoint) const
VECTOR2I Apply(const VECTOR2I &aPoint) const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
Handle zones parameters.
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Copy settings to a given zone.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetHatchThickness(int aThickness)
Definition zone.h:326
void CacheTriangulation(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, const SHAPE_POLY_SET::TASK_SUBMITTER &aSubmitter={})
Definition zone.cpp:1675
void SetNeedRefill(bool aNeedRefill)
Definition zone.h:310
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if a point is near an outline edge or a corner of this zone.
Definition zone.cpp:940
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition zone.cpp:1478
int m_borderHatchPitch
Definition zone.h:1054
wxString m_placementAreaSource
Definition zone.h:973
bool m_isRuleArea
A zone outline can be a rule area.
Definition zone.h:966
void SetDoNotAllowPads(bool aEnable)
Definition zone.h:851
void SetLayerProperties(const std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > &aOther)
Definition zone.cpp:707
ZONE & operator=(const ZONE &aOther)
Definition zone.cpp:101
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:832
PLACEMENT_SOURCE_T m_placementAreaSourceType
Definition zone.h:972
std::optional< int > GetLocalClearance() const override
Definition zone.cpp:1062
void SetLocalClearance(std::optional< int > aClearance)
Definition zone.h:183
bool m_doNotAllowVias
Definition zone.h:987
bool UnFill()
Removes the zone filling.
Definition zone.cpp:528
bool GetDoNotAllowVias() const
Definition zone.h:843
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition zone.cpp:1458
void TransformSolidAreasShapesToPolygon(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer) const
Convert solid areas full shapes to polygon set (the full shape is the polygon area with a thick outli...
Definition zone.cpp:2072
void SetCornerRadius(unsigned int aRadius)
Definition zone.cpp:878
ZONE_FILL_MODE m_fillMode
Definition zone.h:1018
THIEVING_SETTINGS m_thievingSettings
Definition zone.h:1031
bool m_doNotAllowFootprints
Definition zone.h:990
bool unFillLocked()
Internal implementation of UnFill() that assumes the caller already holds m_filledPolysListMutex.
Definition zone.cpp:536
void TransformSmoothedOutlineToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, SHAPE_POLY_SET *aBoardOutline) const
Convert the outlines shape to a polygon with no holes inflated (optional) by max( aClearanceValue,...
Definition zone.cpp:1952
int m_ZoneMinThickness
Definition zone.h:994
BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const override
Create a copy of this BOARD_ITEM.
Definition zone.cpp:230
int GetThievingLineWidth() const
Definition zone.h:387
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
Definition zone.cpp:1441
double m_hatchSmoothingValue
Definition zone.h:1026
void SetLocalFlags(int aFlags)
Definition zone.h:419
int m_thermalReliefSpokeWidth
Definition zone.h:1016
wxString GetPlacementAreaSource() const
Definition zone.h:837
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:1097
void Mirror(const VECTOR2I &aMirrorRef, FLIP_DIRECTION aFlipDirection) override
Mirror the outlines relative to a given horizontal axis the layer is not changed.
Definition zone.cpp:1395
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:1058
wxString m_zoneName
An optional unique name for this zone, used for identifying it in DRC checking.
Definition zone.h:948
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
Definition zone.cpp:1576
std::map< PCB_LAYER_ID, std::shared_ptr< SHAPE_POLY_SET > > m_FilledPolysList
Definition zone.h:1044
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:699
bool GetDoNotAllowPads() const
Definition zone.h:845
const BOX2I GetBoundingBox() const override
Definition zone.cpp:787
void SetMinThickness(int aMinThickness)
Definition zone.h:316
void SetPlacementAreaSource(const wxString &aSource)
Definition zone.h:838
BOX2I computeBoundingBox() const
Compute the bbox from scratch. Shared so the cached value can't diverge from the live one.
Definition zone.cpp:778
void SetThievingOrientation(const EDA_ANGLE &aOrientation)
Definition zone.h:407
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition zone.cpp:733
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
Definition zone.h:839
double m_outlinearea
Definition zone.h:1061
std::mutex m_filledPolysListMutex
Definition zone.h:1043
void SetThievingPattern(THIEVING_PATTERN aPattern)
Definition zone.h:361
wxString GetFriendlyName() const override
Definition zone.cpp:1296
bool GetDoNotAllowTracks() const
Definition zone.h:844
int GetLocalFlags() const
Definition zone.h:418
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition zone.cpp:216
void SetHatchOrientation(const EDA_ANGLE &aStep)
Definition zone.h:332
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuildBorderHatch)
Set all hatch parameters for the zone.
Definition zone.cpp:1557
void SetThievingElementSize(int aSize)
Definition zone.h:370
void SetHatchSmoothingValue(double aValue)
Definition zone.h:338
void CacheOutlineTriangulation()
Triangulate the zone outline only.
Definition zone.cpp:1669
std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > m_layerProperties
Definition zone.h:953
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
Definition zone.cpp:833
bool HitTestForCorner(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a corner.
Definition zone.cpp:950
void SetHatchSmoothingLevel(int aLevel)
Definition zone.h:335
bool m_doNotAllowTracks
Definition zone.h:988
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition zone.h:251
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition zone.cpp:573
void SetPlacementAreaSourceType(PLACEMENT_SOURCE_T aType)
Definition zone.h:840
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:640
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition zone.h:854
LSET m_fillFlags
Definition zone.h:1048
SHAPE_POLY_SET * Outline()
Definition zone.h:421
bool m_doNotAllowPads
Definition zone.h:989
ZONE(BOARD_ITEM_CONTAINER *parent)
Definition zone.cpp:52
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition zone.cpp:247
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
Definition zone.cpp:622
void Move(const VECTOR2I &offset) override
Move the outlines.
Definition zone.cpp:1251
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
Definition zone.cpp:1708
std::atomic< int > m_bboxCacheTimeStamp
Definition zone.h:1070
bool IsCopperThieving() const
Definition zone.h:349
BOX2I m_bboxCache
Lock-free bbox cache, valid while m_bboxCacheTimeStamp matches the board timestamp.
Definition zone.h:1069
SHAPE_POLY_SET * m_Poly
Outline of the zone.
Definition zone.h:943
TEARDROP_TYPE m_teardropType
A zone outline can be a teardrop zone with different rules for priority (always bigger priority than ...
Definition zone.h:980
std::map< PCB_LAYER_ID, HASH_128 > m_filledPolysHash
A hash value used in zone filling calculations to see if the filled areas are up to date.
Definition zone.h:1051
~ZONE()
Definition zone.cpp:118
long long int GetMinIslandArea() const
Definition zone.h:857
int m_hatchSmoothingLevel
Definition zone.h:1022
void SetThievingStagger(bool aStagger)
Definition zone.h:397
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition zone.cpp:2185
LSET m_layerSet
Definition zone.h:951
void SetIsRuleArea(bool aEnable)
Definition zone.h:833
int m_ZoneClearance
Definition zone.h:993
void CopyFrom(const BOARD_ITEM *aOther) override
Definition zone.cpp:111
void SetThievingGap(int aGap)
Definition zone.h:379
void SetDoNotAllowTracks(bool aEnable)
Definition zone.h:850
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
Definition zone.h:746
bool m_placementAreaEnabled
Placement rule area data.
Definition zone.h:971
const wxString & GetZoneName() const
Definition zone.h:160
void CacheBoundingBox()
Used to preload the zone bounding box cache so we don't have to worry about mutex-locking it each tim...
Definition zone.cpp:842
int GetMinThickness() const
Definition zone.h:315
virtual void swapData(BOARD_ITEM *aImage) override
Definition zone.cpp:1646
bool HitTestForEdge(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a segment defined by 2 corners.
Definition zone.cpp:961
SHAPE_POLY_SET GetBoardOutline() const
Definition zone.cpp:916
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
Definition zone.cpp:1412
void Rotate(const VECTOR2I &aCentre, const EDA_ANGLE &aAngle) override
Rotate the outlines.
Definition zone.cpp:1332
ZONE_SETTINGS::CORNER_SMOOTHING GetCornerSmoothingType() const
Definition zone.h:771
bool HigherPriority(const ZONE *aOther) const
Definition zone.cpp:508
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const VECTOR2I &aRefPos, int aAccuracy=0) const
Test if the given VECTOR2I is within the bounds of a filled area of this zone.
Definition zone.cpp:1068
void SetIsFilled(bool isFilled)
Definition zone.h:307
std::mutex m_layerSetMutex
Definition zone.h:950
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition zone.cpp:646
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition zone.cpp:1640
int m_hatchGap
Definition zone.h:1020
ZONE_CONNECTION GetPadConnection() const
Definition zone.h:312
bool HasFilledPolysForLayer(PCB_LAYER_ID aLayer) const
Definition zone.h:690
int GetHatchThickness() const
Definition zone.h:325
double GetHatchHoleMinArea() const
Definition zone.h:340
void invalidateBoundingBoxCache() const
Definition zone.cpp:821
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:665
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:1127
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition zone.cpp:771
int m_hatchBorderAlgorithm
Definition zone.h:1028
bool GetPlacementAreaEnabled() const
Definition zone.h:834
void SetDoNotAllowVias(bool aEnable)
Definition zone.h:849
bool IsTeardropArea() const
Definition zone.h:807
std::vector< SEG > m_borderHatchLines
Definition zone.h:1055
VECTOR2I GetPosition() const override
Definition zone.cpp:564
int GetThermalReliefSpokeWidth() const
Definition zone.h:259
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
Definition zone.cpp:631
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition zone.cpp:1363
void BuildHashValue(PCB_LAYER_ID aLayer)
Build the hash value of m_FilledPolysList, and store it internally in m_filledPolysHash.
Definition zone.cpp:899
void SetThermalReliefGap(int aThermalReliefGap)
Definition zone.h:240
EDA_ANGLE GetHatchOrientation() const
Definition zone.h:331
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aBoardOutline, SHAPE_POLY_SET *aSmoothedPolyWithApron=nullptr) const
Definition zone.cpp:1774
int m_fillVersion
Definition zone.h:995
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition zone.cpp:1975
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition zone.h:657
EDA_ORIENTATION m_hatchOrientation
Definition zone.h:1021
bool GetDoNotAllowFootprints() const
Definition zone.h:846
ZONE_FILL_MODE GetFillMode() const
Definition zone.h:238
double m_hatchHoleMinArea
Definition zone.h:1027
std::vector< PCB_LAYER_ID > GetFilledLayers() const
Create a list of triangles that "fill" the solid areas used for instance to draw these solid areas on...
Definition zone.cpp:1654
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
bool GetThievingStagger() const
Definition zone.h:396
void SetDoNotAllowFootprints(bool aEnable)
Definition zone.h:852
void SetBorderHatchPitch(int aPitch)
Definition zone.h:868
void SetThievingLineWidth(int aWidth)
Definition zone.h:388
void GetInteractingZones(PCB_LAYER_ID aLayer, std::vector< ZONE * > *aSameNetCollidingZones, std::vector< ZONE * > *aOtherNetIntersectingZones) const
Some intersecting zones, despite being on the same layer with the same net, cannot be merged due to o...
Definition zone.cpp:1720
void SetLayerSetAndRemoveUnusedFills(const LSET &aLayerSet)
Set the zone to be on the aLayerSet layers and only remove the fill polygons from the unused layers,...
Definition zone.cpp:2081
int GetHatchGap() const
Definition zone.h:328
double CalculateOutlineArea()
Compute the area of the zone outline (not the filled area).
Definition zone.cpp:1945
int GetThievingGap() const
Definition zone.h:378
void SetHatchHoleMinArea(double aPct)
Definition zone.h:341
unsigned m_priority
Priority: when a zone outline is inside and other zone, if its priority is higher the other zone prio...
Definition zone.h:960
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition zone.cpp:370
bool IsConflicting() const
For rule areas which exclude footprints (and therefore participate in courtyard conflicts during move...
Definition zone.cpp:558
bool m_doNotAllowZoneFills
For keepout zones only: what is not allowed inside the keepout ( pads, tracks and vias )
Definition zone.h:986
ISLAND_REMOVAL_MODE m_islandRemovalMode
Definition zone.h:997
std::vector< SEG > GetHatchLines() const
Definition zone.cpp:1616
bool m_isFilled
True when a zone was filled, false after deleting the filled areas.
Definition zone.h:1006
double GetHatchSmoothingValue() const
Definition zone.h:337
std::atomic< bool > m_needRefill
False when a zone was refilled, true after changes in zone params.
Definition zone.h:1013
THIEVING_PATTERN GetThievingPattern() const
Definition zone.h:360
bool GetDoNotAllowZoneFills() const
Definition zone.h:842
void MoveEdge(const VECTOR2I &offset, int aEdge)
Move the outline Edge.
Definition zone.cpp:1309
int GetHatchSmoothingLevel() const
Definition zone.h:334
unsigned int GetCornerRadius() const
Definition zone.h:775
int m_thermalReliefGap
Definition zone.h:1015
int GetThievingElementSize() const
Definition zone.h:369
SHAPE_POLY_SET GetLibraryOutline() const
Definition zone.cpp:910
bool IsOnCopperLayer() const override
Definition zone.cpp:615
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
Definition zone.cpp:1934
void SetDoNotAllowZoneFills(bool aEnable)
Definition zone.h:848
int m_hatchThickness
Definition zone.h:1019
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
Definition zone.cpp:1349
ZONE_SETTINGS::CORNER_SMOOTHING m_cornerSmoothingType
Definition zone.h:944
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the zone shape to a closed polygon Used in filling zones calculations Circles and arcs are ap...
Definition zone.cpp:2035
void SetAssignedPriority(unsigned aPriority)
Definition zone.h:117
double m_area
Definition zone.h:1060
unsigned int m_cornerRadius
Definition zone.h:945
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition zone.h:313
void SetZoneName(const wxString &aName)
Definition zone.h:161
bool operator==(const ZONE &aOther) const
Definition zone.cpp:2117
void UnHatchBorder()
Clear the zone's hatch.
Definition zone.cpp:1570
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition zone.h:855
EDA_ANGLE GetThievingOrientation() const
Definition zone.h:405
double GetCoverageArea(int aTextMargin) const override
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
Definition zone.cpp:1997
void SetOutline(SHAPE_POLY_SET *aOutline)
Definition zone.h:424
PCB_LAYER_ID GetFirstLayer() const
Definition zone.cpp:595
void SetMinIslandArea(long long int aArea)
Definition zone.h:858
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition zone.cpp:713
HASH_128 GetHashValue(PCB_LAYER_ID aLayer)
Definition zone.cpp:890
ZONE_CONNECTION m_PadConnection
Definition zone.h:992
void InitDataFromSrcInCopyCtor(const ZONE &aZone, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Copy aZone data to me.
Definition zone.cpp:124
int GetThermalReliefGap() const
Definition zone.h:248
void SetHatchGap(int aStep)
Definition zone.h:329
static int GetDefaultHatchPitch()
Definition zone.cpp:1634
void SetPlacementAreaEnabled(bool aEnabled)
Definition zone.h:835
unsigned GetAssignedPriority() const
Definition zone.h:122
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition zone.h:617
bool SameNet(const ZONE *aOther) const
Definition zone.cpp:522
ZONE_BORDER_DISPLAY_STYLE m_borderStyle
Definition zone.h:1053
long long int m_minIslandArea
When island removal mode is set to AREA, islands below this area will be removed.
Definition zone.h:1003
A type-safe container of any type.
Definition ki_any.h:92
@ ROUND_ALL_CORNERS
All angles are rounded.
DRC_CONSTRAINT_T
Definition drc_rule.h:49
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:448
@ DEGREES_T
Definition eda_angle.h:30
#define PCB_EDIT_FRAME_NAME
@ NONE
Definition eda_fill.h:42
#define COURTYARD_CONFLICT
temporary set when moving footprints having courtyard overlapping
a few functions useful in geometry calculations.
Some functions to handle hotkeys in KiCad.
std::string source
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:709
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
Definition layer_ids.h:306
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
Definition layer_ids.h:291
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition layer_ids.h:351
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
FLIP_DIRECTION
Definition mirror.h:23
size_t longest_common_subset(const _Container &__c1, const _Container &__c2)
Returns the length of the longest common subset of values between two containers.
Definition kicad_algo.h:182
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
KICOMMON_API void PackPolySet(types::PolySet &aOutput, const SHAPE_POLY_SET &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
KICOMMON_API SHAPE_POLY_SET UnpackPolySet(const types::PolySet &aInput, const EDA_IU_SCALE &aScale)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:437
#define _HKI(x)
Definition page_info.cpp:40
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition property.h:882
#define NO_SETTER(owner, type)
Macro to define read-only fields (no setter method available)
Definition property.h:889
@ PT_DEGREE
Angle expressed in degrees.
Definition property.h:66
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
Definition property.h:64
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.
const double epsilon
wxString UnescapeString(const wxString &aSource)
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
A storage class for 128-bit hash value.
Definition hash_128.h:33
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
ZONE_DESC()
Definition zone.cpp:2261
std::optional< VECTOR2I > hatching_offset
TEARDROP_TYPE
define the type of a teardrop: on a via or pad, or a track end
int clearance
const int accuracy
wxString result
Test unit parsing edge cases and error handling.
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static SHAPE_POLY_SET g_nullPoly
Definition zone.cpp:887
static struct ZONE_DESC _ZONE_DESC
THIEVING_PATTERN
Shape stamped onto the grid for a copper-thieving fill.
ISLAND_REMOVAL_MODE
Whether or not to remove isolated islands from a zone.
ZONE_FILL_MODE
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.
PLACEMENT_SOURCE_T
#define ZONE_CLEARANCE_MAX_VALUE_MM
Definition zones.h:33
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition zones.h:43
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ THT_THERMAL
Thermal relief only for THT pads.
Definition zones.h:48
@ NONE
Pads are not covered.
Definition zones.h:45
@ FULL
pads are covered by copper
Definition zones.h:47
#define ZONE_BORDER_HATCH_DIST_MM
Definition zones.h:34
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition zones.h:35
#define ZONE_THICKNESS_MIN_VALUE_MM
Definition zones.h:31
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:36