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