KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
7 *
8 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <iterator>
25#include <algorithm>
26#include <unordered_map>
27
28#include <wx/log.h>
29#include <wx/filename.h>
30
31#include <drc/drc_engine.h>
32#include <drc/drc_rtree.h>
37#include <pcb_drill_map.h>
38#include <board_commit.h>
39#include <board.h>
40#include <collectors.h>
42#include <core/arraydim.h>
43#include <core/kicad_algo.h>
46#include <footprint.h>
49#include <font/outline_font.h>
51#include <layer_range.h>
52#include <lset.h>
53#include <pad.h>
54#include <pcb_base_frame.h>
55#include <pcb_track.h>
56#include <pcb_marker.h>
57#include <api/board/board_rules.pb.h>
58#include <pcb_group.h>
59#include <pcb_generator.h>
60#include <pcb_point.h>
62#include <pcb_target.h>
63#include <pcb_shape.h>
64#include <pcb_barcode.h>
65#include <pcb_3d_body.h>
66#include <pcb_text.h>
67#include <pcb_textbox.h>
68#include <pcb_table.h>
69#include <pcb_dimension.h>
70#include <pgm_base.h>
71#include <pcbnew_settings.h>
72#include <progress_reporter.h>
73#include <project.h>
79#include <reporter.h>
80#include <tool/tool_manager.h>
82#include <string_utils.h>
83#include <thread_pool.h>
84#include <zone.h>
85#include <mutex>
86#include <pcb_board_outline.h>
87#include <local_history.h>
88#include <pcb_io/pcb_io_mgr.h>
90#include <advanced_config.h>
91#include <richio.h>
92#include <trace_helpers.h>
93
94// This is an odd place for this, but CvPcb won't link if it's in board_item.cpp like I first
95// tried it.
97
98
100 BOARD_ITEM_CONTAINER( nullptr, PCB_T ),
105 m_timeStamp( 1 ),
106 m_itemIndex( *this ),
108 m_project( nullptr ),
110 m_designSettings( new BOARD_DESIGN_SETTINGS( nullptr, "board.design_settings" ) ),
111 m_NetInfo( this ),
112 m_embedFonts( false ),
113 m_embeddedFilesDelegate( nullptr ),
114 m_componentClassManager( std::make_unique<COMPONENT_CLASS_MANAGER>( this ) ),
115 m_lengthDelayCalc( std::make_unique<LENGTH_DELAY_CALCULATION>( this ) )
116{
117 // A too small value do not allow connecting 2 shapes (i.e. segments) not exactly connected
118 // A too large value do not allow safely connecting 2 shapes like very short segments.
120
123 m_boardOutline = new PCB_BOARD_OUTLINE( this );
124
125 // we have not loaded a board yet, assume latest until then.
126 m_fileFormatVersionAtLoad = LEGACY_BOARD_FILE_VERSION;
129
130 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
131 {
132 m_layers[layer].m_name = GetStandardLayerName( ToLAYER_ID( layer ) );
133
134 if( IsCopperLayer( layer ) )
135 m_layers[layer].m_type = LT_SIGNAL;
136 else if( layer >= User_1 && layer & 1 )
137 m_layers[layer].m_type = LT_AUX;
138 else
139 m_layers[layer].m_type = LT_UNDEFINED;
140 }
141
143
144 // Creates a zone to show sloder mask bridges created by a min web value
145 // it it just to show them
146 m_SolderMaskBridges = new ZONE( this );
148 m_SolderMaskBridges->SetLayerSet( LSET().set( F_Mask ).set( B_Mask ) );
149 int infinity = ( std::numeric_limits<int>::max() / 2 ) - pcbIUScale.mmToIU( 1 );
150 m_SolderMaskBridges->Outline()->NewOutline();
151 m_SolderMaskBridges->Outline()->Append( VECTOR2I( -infinity, -infinity ) );
152 m_SolderMaskBridges->Outline()->Append( VECTOR2I( -infinity, +infinity ) );
153 m_SolderMaskBridges->Outline()->Append( VECTOR2I( +infinity, +infinity ) );
154 m_SolderMaskBridges->Outline()->Append( VECTOR2I( +infinity, -infinity ) );
155 m_SolderMaskBridges->SetMinThickness( 0 );
156
158
159 // Initialize default netclass.
160 bds.m_NetSettings->SetDefaultNetclass( std::make_shared<NETCLASS>( NETCLASS::Default ) );
161 bds.m_NetSettings->GetDefaultNetclass()->SetDescription( _( "This is the default net class." ) );
162
163 bds.UseCustomTrackViaSize( false );
164
165 // Initialize ratsnest
166 m_connectivity.reset( new CONNECTIVITY_DATA() );
167
168 // Set flag bits on these that will only be cleared if these are loaded from a legacy file
169 m_LegacyVisibleLayers.reset().set( Rescue );
171
172 // Install the text-variable dependency adapter as a listener so subsequent
173 // BOARD_COMMIT pushes and undo/redo events reach the tracker. No items
174 // exist yet — RebuildIndex is invoked after load by callers that bypass
175 // per-item notifications.
176 m_textVarAdapter = std::make_unique<BOARD_TEXT_VAR_ADAPTER>( *this );
178}
179
180
185
186
187// Footprints count because the board editor promotes a pad edit to its parent, so watching
188// PAD_T alone would miss every drill change made through the normal editing path
189static bool affectsDrillModel( const BOARD_ITEM* aItem )
190{
191 if( !aItem )
192 return false;
193
194 switch( aItem->Type() )
195 {
196 case PCB_PAD_T:
197 case PCB_VIA_T:
198 case PCB_FOOTPRINT_T:
199 return true;
200
201 default:
202 return false;
203 }
204}
205
206
207std::vector<const PCB_DRILL_MAP*> BOARD::DrillMapsOnLayer( PCB_LAYER_ID aLayer ) const
208{
209 std::vector<const PCB_DRILL_MAP*> maps;
210
211 for( BOARD_ITEM* item : m_drawings )
212 {
213 if( item->Type() == PCB_DRILL_MAP_T && item->GetLayer() == aLayer )
214 maps.push_back( static_cast<const PCB_DRILL_MAP*>( item ) );
215 }
216
217 return maps;
218}
219
220
222{
223 if( !aItem )
224 return;
225
226 // A deleted map keeps drawing until the holes themselves are told
227 if( aItem->Type() == PCB_DRILL_MAP_T )
228 {
231 }
232 else if( affectsDrillModel( aItem ) )
233 {
235 }
236}
237
238
240{
241 LSET layers;
242 std::vector<std::pair<VECTOR2I, int>> placements;
243
244 for( BOARD_ITEM* item : m_drawings )
245 {
246 if( item->Type() != PCB_DRILL_MAP_T )
247 continue;
248
249 const PCB_DRILL_MAP* map = static_cast<const PCB_DRILL_MAP*>( item );
250
251 layers.set( map->GetLayer() );
252 placements.emplace_back( map->GetOffset(), map->GetSymbolExtent() );
253 }
254
255 // Both, because a map can change layer without moving and can move without changing layer
256 if( m_drillSymbolLayers == layers && m_drillSymbolPlacements == placements )
257 return;
258
259 m_drillSymbolLayers = layers;
260 m_drillSymbolPlacements = std::move( placements );
261
262}
263
264
265std::shared_ptr<const DRILL_SYMBOL_CACHE> BOARD::DrillSymbolCache() const
266{
267 std::lock_guard<std::mutex> lock( m_drillSymbolCacheMutex );
268
269 const uint64_t profileKey = GetDesignSettings().GetDrillSymbolProfile().Fingerprint();
270
272 && m_drillSymbolCache->m_Profile == profileKey )
273 {
274 return m_drillSymbolCache;
275 }
276
277 std::shared_ptr<DRILL_SYMBOL_CACHE> rebuilt = std::make_shared<DRILL_SYMBOL_CACHE>();
278 rebuilt->m_ByGroup = ResolveDrillSymbols( *this );
279 rebuilt->m_ByItem = ResolveDrillSymbolsByItem( *this, rebuilt->m_ByGroup );
280
281 DRILL_CHART_MODEL totalsModel( GetDesignSettings().GetDrillSymbolProfile() );
282 totalsModel.Build( *this, EnumerateDrillSpans( *this ) );
283 rebuilt->m_Totals = totalsModel.Totals();
284
285 for( const auto& [itemId, entries] : rebuilt->m_ByItem )
286 {
287 for( const DRILL_SYMBOL_ENTRY& entry : entries )
288 rebuilt->m_HoleExtent.Merge( entry.m_Position );
289 }
290
291 rebuilt->m_Generation = m_drillModelGeneration;
292 rebuilt->m_Profile = profileKey;
293
294 m_drillSymbolCache = rebuilt;
295
296 return m_drillSymbolCache;
297}
298
299
301{
302 if( m_drillSymbolPlacements.empty() )
303 return aBoundingBox;
304
305 BOX2I result = aBoundingBox;
306
307 for( const auto& [offset, extent] : m_drillSymbolPlacements )
308 {
309 BOX2I symbolBox = aBoundingBox;
310 symbolBox.Move( offset );
311 symbolBox.Inflate( extent );
312 result.Merge( symbolBox );
313 }
314
315 return result;
316}
317
318
319void BOARD::bumpDrillModelFor( const std::vector<BOARD_ITEM*>& aItems )
320{
321 for( const BOARD_ITEM* item : aItems )
322 {
323 if( affectsDrillModel( item ) )
324 {
326 return;
327 }
328 }
329}
330
331
333{
334 // Clears m_owningIndex as it goes. Items that outlive the board rely on that to know
335 // ~BOARD_ITEM must not walk their parent chain back into freed memory
337
338 // Clean up the owned elements
340
341 delete m_SolderMaskBridges;
342
343 std::vector<BOARD_ITEM*> ownedItems = collectOwnedItems();
344
345 std::sort( ownedItems.begin(), ownedItems.end() );
346 ownedItems.erase( std::unique( ownedItems.begin(), ownedItems.end() ), ownedItems.end() );
347
348 m_zones.clear();
349 m_footprints.clear();
350 m_tracks.clear();
351 m_drawings.clear();
352 m_groups.clear();
353 m_constraints.clear();
354 m_points.clear();
355
356 delete m_boardOutline;
357 m_generators.clear();
358
359 // Delete the owned items after clearing the containers, because some item dtors
360 // cause call chains that query the containers
361 for( BOARD_ITEM* item : ownedItems )
362 delete item;
363
364 // Remove any listeners
366}
367
368
370{
371 if( !GetConnectivity()->Build( this, aReporter ) )
372 return false;
373
375 return true;
376}
377
378
379void BOARD::SetProject( PROJECT* aProject, bool aReferenceOnly )
380{
381 if( m_project == aProject )
382 return;
383
384 if( m_project )
385 ClearProject();
386
387 m_project = aProject;
388
389 if( aProject && !aReferenceOnly )
390 {
391 PROJECT_FILE& project = aProject->GetProjectFile();
392
393 // Link the design settings object to the project file
394 project.m_BoardSettings = m_designSettings;
395
396 // Set parent, which also will load the values from JSON stored in the project if we don't
397 // have legacy design settings loaded already
398 project.m_BoardSettings->SetParent( &project, !m_LegacyDesignSettingsLoaded );
399
400 // The DesignSettings' netclasses pointer will be pointing to its internal netclasses
401 // list at this point. If we loaded anything into it from a legacy board file then we
402 // want to transfer it over to the project netclasses list.
404 {
405 std::shared_ptr<NET_SETTINGS> legacySettings = GetDesignSettings().m_NetSettings;
406 std::shared_ptr<NET_SETTINGS>& projectSettings = project.NetSettings();
407
408 projectSettings->SetDefaultNetclass( legacySettings->GetDefaultNetclass() );
409 projectSettings->SetNetclasses( legacySettings->GetNetclasses() );
410 projectSettings->SetNetclassPatternAssignments(
411 std::move( legacySettings->GetNetclassPatternAssignments() ) );
412 }
413
414 // Now update the DesignSettings' netclass pointer to point into the project.
415 GetDesignSettings().m_NetSettings = project.NetSettings();
416 }
417}
418
419
421{
422 if( !m_project )
423 return;
424
425 PROJECT_FILE& project = m_project->GetProjectFile();
426
427 // Release this board's own design settings, not project.m_BoardSettings; a second board
428 // sharing the project (e.g. diffing a file against itself) overwrites m_BoardSettings, so
429 // trusting it would orphan our settings as a dangling entry in the project's nested list
430 project.ReleaseNestedSettings( m_designSettings.get() );
431
433 m_project = nullptr;
434}
435
436
438{
439 if( m_fileName.IsEmpty() || !m_project )
440 return wxEmptyString;
441
442 wxFileName fn( m_fileName );
444 return m_project->AbsolutePath( fn.GetFullName() );
445}
446
447
449{
450 std::unique_lock<std::shared_mutex> writeLock( m_CachesMutex );
451
452 m_timeStamp++;
453
455
456 if( !m_IntersectsAreaCache.Empty()
457 || !m_IntersectsKeepoutCache.Empty()
458 || !m_EnclosedByAreaCache.Empty()
468 || !m_LayerExpressionCache.empty()
469 || !m_ZoneBBoxCache.empty()
471 || m_maxClearanceValue.has_value()
472 || !m_ZonesByNameCache.empty()
474 || !m_ItemFieldCache.Empty()
475 || m_StackedMicroviaCache.has_value() )
476 {
477 m_IntersectsAreaCache.Clear();
479 m_EnclosedByAreaCache.Clear();
489 m_ItemFieldCache.Clear();
492 m_ZonesByNameCache.clear();
494
495 m_ZoneBBoxCache.clear();
496
497 m_CopperItemRTreeCache = nullptr;
498
499 // These are always regenerated before use, but still probably safer to clear them
500 // while we're here.
503 m_DRCZones.clear();
504 m_DRCCopperZones.clear();
508
509 m_maxClearanceValue.reset();
510 }
511}
512
513
514std::shared_ptr<const FOOTPRINT_COURTYARD_INDEX> BOARD::GetFootprintCourtyardIndex()
515{
516 {
517 std::shared_lock<std::shared_mutex> readLock( m_CachesMutex );
518
521 }
522
523 // Build outside the lock; FOOTPRINT::GetCourtyard guards its own cache with a per-footprint
524 // mutex, so building here is safe even when it has to lazily populate that cache. Publish under
525 // the write lock, letting the first builder win if several worker threads race here on the
526 // first courtyard predicate.
527 auto index = std::make_shared<FOOTPRINT_COURTYARD_INDEX>( this );
528
529 std::unique_lock<std::shared_mutex> writeLock( m_CachesMutex );
530
532 m_footprintCourtyardIndex = std::move( index );
533
535}
536
537
539{
540 std::set<std::pair<KIID, KIID>> m_ratsnestExclusions;
541
542 for( PCB_MARKER* marker : GetBoard()->Markers() )
543 {
544 if( marker->GetMarkerType() == MARKER_BASE::MARKER_RATSNEST && marker->IsExcluded() )
545 {
546 const std::shared_ptr<RC_ITEM>& rcItem = marker->GetRCItem();
547 m_ratsnestExclusions.emplace( rcItem->GetMainItemID(), rcItem->GetAuxItemID() );
548 m_ratsnestExclusions.emplace( rcItem->GetAuxItemID(), rcItem->GetMainItemID() );
549 }
550 }
551
553 [&]( CN_EDGE& aEdge )
554 {
555 if( aEdge.GetSourceNode() && aEdge.GetTargetNode() && !aEdge.GetSourceNode()->Dirty()
556 && !aEdge.GetTargetNode()->Dirty() )
557 {
558 std::pair<KIID, KIID> ids = { aEdge.GetSourceNode()->Parent()->m_Uuid,
559 aEdge.GetTargetNode()->Parent()->m_Uuid };
560
561 aEdge.SetVisible( m_ratsnestExclusions.count( ids ) == 0 );
562 }
563
564 return true;
565 } );
566}
567
568
570{
571 m_designSettings->m_DrcExclusions.clear();
572
573 for( PCB_MARKER* marker : m_markers )
574 {
575 // DRC_EXCLUSION::FromMarker() dereferences the RC_ITEM, so a marker carrying none would
576 // fault while persisting exclusions during a save or window close.
577 if( !marker->GetRCItem() )
578 continue;
579
580 if( marker->IsExcluded() )
581 m_designSettings->m_DrcExclusions.insert( DRC_EXCLUSION::FromMarker( *marker ) );
582 }
583
584 if( m_project )
585 {
586 if( PROJECT_FILE* projectFile = &m_project->GetProjectFile() )
587 {
588 if( projectFile->m_BoardSettings )
589 projectFile->m_BoardSettings->m_DrcExclusions = m_designSettings->m_DrcExclusions;
590 }
591 }
592}
593
594
595std::vector<PCB_MARKER*> BOARD::ResolveDRCExclusions( bool aCreateMarkers )
596{
597 std::set<DRC_EXCLUSION, DRC_EXCLUSION_COMPARE> exclusions = m_designSettings->m_DrcExclusions;
598 m_designSettings->m_DrcExclusions.clear();
599
600 for( PCB_MARKER* marker : GetBoard()->Markers() )
601 {
602 if( !marker->GetRCItem() )
603 continue;
604
605 DRC_EXCLUSION lookup = DRC_EXCLUSION::FromMarker( *marker );
606
607 if( auto it = exclusions.find( lookup ); it != exclusions.end() )
608 {
609 marker->SetExcluded( true, it->GetComment() );
610 m_designSettings->m_DrcExclusions.insert( *it );
611 }
612 }
613
614 std::vector<PCB_MARKER*> newMarkers;
615
616 if( aCreateMarkers )
617 {
618 for( const DRC_EXCLUSION& exclusion : exclusions )
619 {
620 if( m_designSettings->m_DrcExclusions.contains( exclusion ) )
621 continue;
622
623 PCB_MARKER* marker = PCB_MARKER::FromProto( exclusion.ToProto().marker() );
624
625 if( !marker )
626 continue;
627
628 std::vector<KIID> ids = marker->GetRCItem()->GetIDs();
629
630 for( const KIID& uuid : ids )
631 {
632 if( uuid != niluuid && !ResolveItem( uuid, true ) )
633 {
634 delete marker;
635 marker = nullptr;
636 break;
637 }
638 }
639
640 if( marker )
641 {
642 marker->SetExcluded( true, exclusion.GetComment() );
643 newMarkers.push_back( marker );
644 m_designSettings->m_DrcExclusions.insert( exclusion );
645 }
646 }
647 }
648
649 return newMarkers;
650}
651
652
653std::vector<PCB_MARKER*> BOARD::ReloadDRCExclusions( std::vector<PCB_MARKER*>& aStale )
654{
655 std::vector<PCB_MARKER*> wereExcluded;
656
657 for( PCB_MARKER* marker : m_markers )
658 {
659 if( marker->IsExcluded() )
660 {
661 wereExcluded.push_back( marker );
662 marker->SetExcluded( false );
663 }
664 }
665
666 std::vector<PCB_MARKER*> newMarkers = ResolveDRCExclusions( true );
667
668 for( PCB_MARKER* marker : wereExcluded )
669 {
670 if( !marker->IsExcluded() )
671 aStale.push_back( marker );
672 }
673
674 return newMarkers;
675}
676
677
678void BOARD::GetContextualTextVars( wxArrayString* aVars ) const
679{
680 auto add = [&]( const wxString& aVar )
681 {
682 if( !alg::contains( *aVars, aVar ) )
683 aVars->push_back( aVar );
684 };
685
686 add( wxT( "LAYER" ) );
687 add( wxT( "FILENAME" ) );
688 add( wxT( "FILEPATH" ) );
689 add( wxT( "PROJECTNAME" ) );
690 add( wxT( "DRC_ERROR <message_text>" ) );
691 add( wxT( "DRC_WARNING <message_text>" ) );
692 add( wxT( "VARIANT" ) );
693 add( wxT( "VARIANT_DESC" ) );
694 add( wxT( "DRILL_OPERATIONS" ) );
695 add( wxT( "DRILL_SITES" ) );
696 add( wxT( "DRILL_GROUPS" ) );
697
699
700 if( GetProject() )
701 {
702 for( std::pair<wxString, wxString> entry : GetProject()->GetTextVars() )
703 add( entry.first );
704 }
705}
706
707
708bool BOARD::ResolveTextVar( wxString* token, int aDepth ) const
709{
710 return ResolveTextVar( token, GetCurrentVariant(), aDepth );
711}
712
713
714bool BOARD::ResolveTextVar( wxString* token, const wxString& aVariantName, int aDepth ) const
715{
716 if( token->Contains( ':' ) )
717 {
718 wxString remainder;
719 wxString ref = token->BeforeFirst( ':', &remainder );
720 BOARD_ITEM* refItem = ResolveItem( KIID( ref ), true );
721
722 if( refItem && refItem->Type() == PCB_FOOTPRINT_T )
723 {
724 FOOTPRINT* refFP = static_cast<FOOTPRINT*>( refItem );
725
726 if( refFP->ResolveTextVar( &remainder, aVariantName, aDepth + 1 ) )
727 *token = std::move( remainder );
728 else
729 *token = wxString::Format( wxT( "<Unresolved: %s:%s>" ), refFP->GetReference(), remainder );
730
731 return true;
732 }
733
734 // If UUID resolution failed, try to resolve by reference designator
735 // This handles typing ${U1:VALUE} directly without save/reload
736 if( !refItem )
737 {
738 for( const FOOTPRINT* footprint : Footprints() )
739 {
740 if( footprint->GetReference().CmpNoCase( ref ) == 0 )
741 {
742 if( footprint->ResolveTextVar( &remainder, aVariantName, aDepth + 1 ) )
743 *token = std::move( remainder );
744 else
745 *token = wxString::Format( wxT( "<Unresolved: %s:%s>" ), ref, remainder );
746
747 return true;
748 }
749 }
750 }
751
752 if( !refItem )
753 {
754 *token = wxString::Format( wxT( "<Unresolved: %s:%s>" ), ref, remainder );
755 return true;
756 }
757 }
758
759 if( token->IsSameAs( wxT( "FILENAME" ) ) )
760 {
761 wxFileName fn( GetFileName() );
762 *token = fn.GetFullName();
763 return true;
764 }
765 else if( token->IsSameAs( wxT( "FILEPATH" ) ) )
766 {
767 wxFileName fn( GetFileName() );
768 *token = fn.GetFullPath();
769 return true;
770 }
771 else if( token->IsSameAs( wxT( "VARIANT" ) ) )
772 {
773 *token = aVariantName;
774 return true;
775 }
776 else if( token->IsSameAs( wxT( "VARIANT_DESC" ) ) )
777 {
778 *token = GetVariantDescription( aVariantName );
779 return true;
780 }
781 else if( token->IsSameAs( wxT( "PROJECTNAME" ) ) && GetProject() )
782 {
783 *token = GetProject()->GetProjectName();
784 return true;
785 }
786 else if( token->IsSameAs( wxT( "DRILL_OPERATIONS" ) )
787 || token->IsSameAs( wxT( "DRILL_SITES" ) )
788 || token->IsSameAs( wxT( "DRILL_GROUPS" ) ) )
789 {
790 // Cached, because this resolves on every redraw of every text item and the model
791 // walks every hole on every span
793
794 if( token->IsSameAs( wxT( "DRILL_OPERATIONS" ) ) )
795 *token = wxString::Format( wxT( "%d" ), totals.m_Operations );
796 else if( token->IsSameAs( wxT( "DRILL_SITES" ) ) )
797 *token = wxString::Format( wxT( "%d" ), totals.m_Sites );
798 else
799 *token = wxString::Format( wxT( "%d" ), totals.m_Groups );
800
801 return true;
802 }
803
804 wxString var = *token;
805
806 if( GetTitleBlock().TextVarResolver( token, m_project, INTERNAL ) )
807 return true;
808
809 // Resolve from the project's live text variables before the board's cached properties so
810 // changes made outside the board (schematic, project settings) are always reflected.
811 if( GetProject() && GetProject()->TextVarResolver( token ) )
812 return true;
813
814 // Fall back to the board's cached properties for backward compatibility with boards that
815 // may carry properties not present in the project.
816 if( m_properties.count( var ) )
817 {
818 *token = m_properties.at( var );
819 return true;
820 }
821
822 return false;
823}
824
825
826bool BOARD::IsEmpty() const
827{
828 return m_drawings.empty() && m_footprints.empty() && m_tracks.empty() && m_zones.empty() && m_points.empty();
829}
830
831
833{
834 return ZeroOffset;
835}
836
837
838void BOARD::SetPosition( const VECTOR2I& aPos )
839{
840 wxLogWarning( wxT( "This should not be called on the BOARD object" ) );
841}
842
843
844void BOARD::Move( const VECTOR2I& aMoveVector ) // overload
845{
846 INSPECTOR_FUNC inspector = [&]( EDA_ITEM* item, void* testData )
847 {
848 if( item->IsBOARD_ITEM() )
849 {
850 BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
851
852 // aMoveVector was snapshotted, don't need "data".
853 // Only move the top level group
854 if( !board_item->GetParentGroup() && !board_item->GetParentFootprint() )
855 board_item->Move( aMoveVector );
856 }
857
859 };
860
861 Visit( inspector, nullptr, GENERAL_COLLECTOR::BoardLevelItems );
862}
863
864
865void BOARD::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const
866{
867 try
868 {
869 for( PCB_TRACK* track : m_tracks )
870 aFunction( track );
871
872 for( ZONE* zone : m_zones )
873 aFunction( zone );
874
875 for( PCB_MARKER* marker : m_markers )
876 aFunction( marker );
877
878 for( PCB_GROUP* group : m_groups )
879 aFunction( group );
880
881 for( PCB_CONSTRAINT* constraint : m_constraints )
882 aFunction( constraint );
883
884 for( PCB_POINT* point : m_points )
885 aFunction( point );
886
887 for( FOOTPRINT* footprint : m_footprints )
888 {
889 aFunction( footprint );
890
891 if( aMode == RECURSE_MODE::RECURSE )
892 footprint->RunOnChildren( aFunction, RECURSE_MODE::RECURSE );
893 }
894
895 for( BOARD_ITEM* drawing : m_drawings )
896 {
897 aFunction( drawing );
898
899 if( aMode == RECURSE_MODE::RECURSE )
900 drawing->RunOnChildren( aFunction, RECURSE_MODE::RECURSE );
901 }
902 }
903 catch( std::bad_function_call& )
904 {
905 wxFAIL_MSG( wxT( "Error running BOARD::RunOnChildren" ) );
906 }
907}
908
909
911{
912 TRACKS ret;
913
914 INSPECTOR_FUNC inspector = [aNetCode, &ret]( EDA_ITEM* item, void* testData )
915 {
916 PCB_TRACK* t = static_cast<PCB_TRACK*>( item );
917
918 if( t->GetNetCode() == aNetCode )
919 ret.push_back( t );
920
922 };
923
924 // visit this BOARD's PCB_TRACKs and PCB_VIAs with above TRACK INSPECTOR which
925 // appends all in aNetCode to ret.
926 Visit( inspector, nullptr, GENERAL_COLLECTOR::Tracks );
927
928 return ret;
929}
930
931
932bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer )
933{
934 m_layers[aIndex] = aLayer;
936 return true;
937}
938
939
940PCB_LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
941{
942 // Check the BOARD physical layer names.
943 for( auto& [layer_id, layer] : m_layers )
944 {
945 if( layer.m_name == aLayerName || layer.m_userName == aLayerName )
946 return ToLAYER_ID( layer_id );
947 }
948
949 // Otherwise fall back to the system standard layer names for virtual layers.
950 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
951 {
952 if( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName )
953 return ToLAYER_ID( layer );
954 }
955
956 return UNDEFINED_LAYER;
957}
958
959
960const wxString BOARD::GetLayerName( PCB_LAYER_ID aLayer ) const
961{
962 // All layer names are stored in the BOARD.
963 if( IsLayerEnabled( aLayer ) )
964 {
965 auto it = m_layers.find( aLayer );
966
967 // Standard names were set in BOARD::BOARD() but they may be over-ridden by
968 // BOARD::SetLayerName(). For copper layers, return the user defined layer name,
969 // if it was set. Otherwise return the Standard English layer name.
970 if( it != m_layers.end() && !it->second.m_userName.IsEmpty() )
971 return it->second.m_userName;
972 }
973
974 return GetStandardLayerName( aLayer );
975}
976
977
978bool BOARD::SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName )
979{
980 if( aLayerName.IsEmpty() )
981 {
982 // If the name is empty, we clear the user name.
983 m_layers[aLayer].m_userName.clear();
985 }
986 else
987 {
988 // no quote chars in the name allowed
989 if( aLayerName.Find( wxChar( '"' ) ) != wxNOT_FOUND )
990 return false;
991
992 if( IsLayerEnabled( aLayer ) )
993 {
994 m_layers[aLayer].m_userName = aLayerName;
996
997 // A chart prints the span using layer names, so a rename changes what it says
999 return true;
1000 }
1001 }
1002
1003 return false;
1004}
1005
1006
1008{
1009 return ::IsFrontLayer( aLayer ) || GetLayerType( aLayer ) == LT_FRONT;
1010}
1011
1012
1014{
1015 return ::IsBackLayer( aLayer ) || GetLayerType( aLayer ) == LT_BACK;
1016}
1017
1018
1020{
1021 if( IsLayerEnabled( aLayer ) )
1022 {
1023 auto it = m_layers.find( aLayer );
1024
1025 if( it != m_layers.end() )
1026 return it->second.m_type;
1027 }
1028
1029 if( aLayer >= User_1 && !IsCopperLayer( aLayer ) )
1030 return LT_AUX;
1031 else if( IsCopperLayer( aLayer ) )
1032 return LT_SIGNAL;
1033 else
1034 return LT_UNDEFINED;
1035}
1036
1037
1038bool BOARD::SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType )
1039{
1040 if( IsLayerEnabled( aLayer ) )
1041 {
1042 m_layers[aLayer].m_type = aLayerType;
1044 return true;
1045 }
1046
1047 return false;
1048}
1049
1050
1051const char* LAYER::ShowType( LAYER_T aType )
1052{
1053 switch( aType )
1054 {
1055 default:
1056 case LT_SIGNAL: return "signal";
1057 case LT_POWER: return "power";
1058 case LT_MIXED: return "mixed";
1059 case LT_JUMPER: return "jumper";
1060 case LT_AUX: return "auxiliary";
1061 case LT_FRONT: return "front";
1062 case LT_BACK: return "back";
1063 }
1064}
1065
1066
1067LAYER_T LAYER::ParseType( const char* aType )
1068{
1069 if( strcmp( aType, "signal" ) == 0 )
1070 return LT_SIGNAL;
1071 else if( strcmp( aType, "power" ) == 0 )
1072 return LT_POWER;
1073 else if( strcmp( aType, "mixed" ) == 0 )
1074 return LT_MIXED;
1075 else if( strcmp( aType, "jumper" ) == 0 )
1076 return LT_JUMPER;
1077 else if( strcmp( aType, "auxiliary" ) == 0 )
1078 return LT_AUX;
1079 else if( strcmp( aType, "front" ) == 0 )
1080 return LT_FRONT;
1081 else if( strcmp( aType, "back" ) == 0 )
1082 return LT_BACK;
1083 else
1084 return LT_UNDEFINED;
1085}
1086
1087
1089{
1090 for( int layer = F_Cu; layer < PCB_LAYER_ID_COUNT; ++layer )
1091 m_layers[layer].m_opposite = ::FlipLayer( ToLAYER_ID( layer ), GetCopperLayerCount() );
1092
1093 // Match up similary-named front/back user layers
1094 for( int layer = User_1; layer <= PCB_LAYER_ID_COUNT; layer += 2 )
1095 {
1096 if( m_layers[layer].m_opposite != layer ) // already paired
1097 continue;
1098
1099 if( m_layers[layer].m_type != LT_FRONT && m_layers[layer].m_type != LT_BACK )
1100 continue;
1101
1102 wxString principalName = m_layers[layer].m_userName.AfterFirst( '.' );
1103
1104 for( int ii = layer + 2; ii <= PCB_LAYER_ID_COUNT; ii += 2 )
1105 {
1106 if( m_layers[ii].m_opposite != ii ) // already paired
1107 continue;
1108
1109 if( m_layers[ii].m_type != LT_FRONT && m_layers[ii].m_type != LT_BACK )
1110 continue;
1111
1112 if( m_layers[layer].m_type == m_layers[ii].m_type )
1113 continue;
1114
1115 wxString candidate = m_layers[ii].m_userName.AfterFirst( '.' );
1116
1117 if( !candidate.IsEmpty() && candidate == principalName )
1118 {
1119 m_layers[layer].m_opposite = ii;
1120 m_layers[ii].m_opposite = layer;
1121 break;
1122 }
1123 }
1124 }
1125
1126 // Match up non-custom-named consecutive front/back user layer pairs
1127 for( int layer = User_1; layer < PCB_LAYER_ID_COUNT - 2; layer += 2 )
1128 {
1129 int next = layer + 2;
1130
1131 // ignore already-matched layers
1132 if( m_layers[layer].m_opposite != layer || m_layers[next].m_opposite != next )
1133 continue;
1134
1135 // ignore layer pairs that aren't consecutive front/back
1136 if( m_layers[layer].m_type != LT_FRONT || m_layers[next].m_type != LT_BACK )
1137 continue;
1138
1139 if( m_layers[layer].m_userName != m_layers[layer].m_name && m_layers[next].m_userName != m_layers[next].m_name )
1140 {
1141 m_layers[layer].m_opposite = next;
1142 m_layers[next].m_opposite = layer;
1143 }
1144 }
1145}
1146
1147
1149{
1150 auto it = m_layers.find( aLayer );
1151 return it == m_layers.end() ? aLayer : ToLAYER_ID( it->second.m_opposite );
1152}
1153
1154
1159
1160
1162{
1165
1166 // A chart prints layer spans, so the count and order change what it says
1168}
1169
1170
1175
1176
1178{
1180}
1181
1183{
1184 int imax = GetCopperLayerCount();
1185
1186 // layers IDs are F_Cu, B_Cu, and even IDs values (imax values)
1187 if( imax <= 2 ) // at least 2 layers are expected
1188 return B_Cu;
1189
1190 // For a 4 layer, last ID is In2_Cu = 6 (IDs are 0, 2, 4, 6)
1191 return static_cast<PCB_LAYER_ID>( ( imax - 1 ) * 2 );
1192}
1193
1194
1195int BOARD::LayerDepth( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer ) const
1196{
1197 // Copper IDs are not in stack order (B_Cu=2, In1_Cu=4), so count in stack positions
1198 return static_cast<int>( LAYER_RANGE( aStartLayer, aEndLayer, GetCopperLayerCount() ).size() ) - 1;
1199}
1200
1201
1203{
1205}
1206
1207
1209{
1210 // If there is no project, assume layer is visible always
1211 return GetDesignSettings().IsLayerEnabled( aLayer )
1212 && ( !m_project || m_project->GetLocalSettings().m_VisibleLayers[aLayer] );
1213}
1214
1215
1217{
1218 return m_project ? m_project->GetLocalSettings().m_VisibleLayers : LSET::AllLayersMask();
1219}
1220
1221
1222void BOARD::SetEnabledLayers( const LSET& aLayerSet )
1223{
1224 GetDesignSettings().SetEnabledLayers( aLayerSet );
1226}
1227
1228
1230{
1231 return GetDesignSettings().IsLayerEnabled( aLayer );
1232}
1233
1234
1235void BOARD::SetVisibleLayers( const LSET& aLayerSet )
1236{
1237 if( m_project )
1238 m_project->GetLocalSettings().m_VisibleLayers = aLayerSet;
1239}
1240
1241
1243{
1244 // Call SetElementVisibility for each item
1245 // to ensure specific calculations that can be needed by some items,
1246 // just changing the visibility flags could be not sufficient.
1247 for( size_t i = 0; i < aSet.size(); i++ )
1248 SetElementVisibility( GAL_LAYER_ID_START + static_cast<int>( i ), aSet[i] );
1249}
1250
1251
1253{
1254 SetVisibleLayers( LSET().set() );
1255
1256 // Call SetElementVisibility for each item,
1257 // to ensure specific calculations that can be needed by some items
1259 SetElementVisibility( ii, true );
1260}
1261
1262
1264{
1265 return m_project ? m_project->GetLocalSettings().m_VisibleItems : GAL_SET::DefaultVisible();
1266}
1267
1268
1270{
1271 return !m_project || m_project->GetLocalSettings().m_VisibleItems[aLayer - GAL_LAYER_ID_START];
1272}
1273
1274
1275void BOARD::SetElementVisibility( GAL_LAYER_ID aLayer, bool isEnabled )
1276{
1277 if( m_project )
1278 m_project->GetLocalSettings().m_VisibleItems.set( aLayer - GAL_LAYER_ID_START, isEnabled );
1279
1280 switch( aLayer )
1281 {
1282 case LAYER_RATSNEST:
1283 {
1284 // because we have a tool to show/hide ratsnest relative to a pad or a footprint
1285 // so the hide/show option is a per item selection
1286
1287 for( PCB_TRACK* track : Tracks() )
1288 track->SetLocalRatsnestVisible( isEnabled );
1289
1290 for( FOOTPRINT* footprint : Footprints() )
1291 {
1292 for( PAD* pad : footprint->Pads() )
1293 pad->SetLocalRatsnestVisible( isEnabled );
1294 }
1295
1296 for( ZONE* zone : Zones() )
1297 zone->SetLocalRatsnestVisible( isEnabled );
1298
1299 break;
1300 }
1301
1302 default:;
1303 }
1304}
1305
1306
1308{
1309 switch( aLayer )
1310 {
1313 default: wxFAIL_MSG( wxT( "BOARD::IsModuleLayerVisible(): bad layer" ) ); return true;
1314 }
1315}
1316
1317
1322
1323
1325{
1326 return *m_designSettings;
1327}
1328
1329
1331{
1332 std::unique_lock<std::shared_mutex> writeLock( m_CachesMutex );
1333
1334 *m_designSettings = aSettings;
1335 m_maxClearanceValue.reset();
1336}
1337
1338
1340{
1341 if( m_designSettings && m_designSettings->m_DRCEngine )
1342 m_designSettings->m_DRCEngine->InvalidateClearanceCache( aUuid );
1343}
1344
1345
1347{
1348 if( m_designSettings && m_designSettings->m_DRCEngine )
1349 m_designSettings->m_DRCEngine->InitializeClearanceCache();
1350}
1351
1352
1354{
1355 if( !m_maxClearanceValue.has_value() )
1356 {
1357 std::unique_lock<std::shared_mutex> writeLock( m_CachesMutex );
1358
1359 int worstClearance = m_designSettings->GetBiggestClearanceValue();
1360
1361 for( ZONE* zone : m_zones )
1362 worstClearance = std::max( worstClearance, zone->GetLocalClearance().value() );
1363
1364 for( FOOTPRINT* footprint : m_footprints )
1365 {
1366 for( PAD* pad : footprint->Pads() )
1367 {
1368 std::optional<int> override = pad->GetClearanceOverrides( nullptr );
1369
1370 if( override.has_value() )
1371 worstClearance = std::max( worstClearance, override.value() );
1372 }
1373
1374 for( ZONE* zone : footprint->Zones() )
1375 worstClearance = std::max( worstClearance, zone->GetLocalClearance().value() );
1376 }
1377
1378 m_maxClearanceValue = worstClearance;
1379 }
1380
1381 return m_maxClearanceValue.value_or( 0 );
1382};
1383
1384
1385void BOARD::CacheTriangulation( PROGRESS_REPORTER* aReporter, const std::vector<ZONE*>& aZones )
1386{
1387 std::vector<ZONE*> zones = aZones;
1388
1389 if( zones.empty() )
1390 zones = m_zones;
1391
1392 if( zones.empty() )
1393 return;
1394
1395 if( aReporter )
1396 aReporter->Report( _( "Tessellating copper zones..." ) );
1397
1399
1401 [&tp]( std::function<void()> aTask )
1402 {
1403 tp.detach_task( std::move( aTask ) );
1404 };
1405
1406 // Per layer, not per zone; a plane repeated across inner layers is otherwise one thread
1407 std::vector<std::pair<ZONE*, PCB_LAYER_ID>> work;
1408
1409 for( ZONE* zone : zones )
1410 {
1411 // The format stores each fill's layer independently, so the layer set can miss one
1412 for( PCB_LAYER_ID layer : zone->GetFilledLayers() )
1413 work.emplace_back( zone, layer );
1414 }
1415
1416 std::vector<std::future<size_t>> returns;
1417
1418 returns.reserve( work.size() );
1419
1420 for( const std::pair<ZONE*, PCB_LAYER_ID>& item : work )
1421 {
1422 ZONE* zone = item.first;
1423 PCB_LAYER_ID layer = item.second;
1424
1425 returns.emplace_back( tp.submit_task(
1426 [aReporter, &submitter, zone, layer]() -> size_t
1427 {
1428 if( aReporter && aReporter->IsCancelled() )
1429 return 0;
1430
1431 zone->CacheTriangulation( layer, submitter );
1432
1433 return 1;
1434 } ) );
1435 }
1436
1437 // Finalize the triangulation threads
1438 for( const std::future<size_t>& ret : returns )
1439 {
1440 std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
1441
1442 while( status != std::future_status::ready )
1443 {
1444 if( aReporter )
1445 aReporter->KeepRefreshing();
1446
1447 status = ret.wait_for( std::chrono::milliseconds( 250 ) );
1448 }
1449 }
1450
1451 // A few hundred points board-wide, so not worth a task
1452 for( ZONE* zone : zones )
1453 {
1454 if( aReporter && aReporter->IsCancelled() )
1455 break;
1456
1457 zone->CacheOutlineTriangulation();
1458
1459 if( aReporter )
1460 aReporter->AdvanceProgress();
1461 }
1462}
1463
1464
1465void BOARD::RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction )
1466{
1467 for( FOOTPRINT* footprint : m_footprints )
1468 aFunction( footprint->GetEmbeddedFiles() );
1469}
1470
1471
1473{
1475 [&]( EMBEDDED_FILES* nested )
1476 {
1477 for( auto& [filename, embeddedFile] : nested->EmbeddedFileMap() )
1478 {
1480
1481 if( file )
1482 {
1483 embeddedFile->compressedEncodedData = file->compressedEncodedData;
1484 embeddedFile->decompressedData = file->decompressedData;
1485 embeddedFile->data_hash = file->data_hash;
1486 embeddedFile->is_valid = file->is_valid;
1487 }
1488 }
1489 } );
1490}
1491
1492
1493wxString BOARD::GetUniqueZoneName( const wxString& aBaseName, const ZONE* aExclude ) const
1494{
1495 auto inUse =
1496 [&]( const wxString& aName )
1497 {
1498 for( const ZONE* zone : m_zones )
1499 {
1500 if( zone != aExclude && zone->GetZoneName() == aName )
1501 return true;
1502 }
1503
1504 return false;
1505 };
1506
1507 return MakeUniqueZoneName( aBaseName, inUse );
1508}
1509
1510
1511wxString BOARD::MakeUniqueZoneName( const wxString& aBaseName, const std::function<bool( const wxString& )>& aInUse )
1512{
1513 if( aBaseName.IsEmpty() || !aInUse( aBaseName ) )
1514 return aBaseName;
1515
1516 // Strip a trailing _<number> so repeated copies increment the root (foo_1 -> foo_2),
1517 // instead of stacking suffixes (foo_1_1_1).
1518 wxString root = aBaseName;
1519
1520 if( aBaseName.Find( '_' ) != wxNOT_FOUND )
1521 {
1522 wxString suffix = aBaseName.AfterLast( '_' );
1523 bool allDigits = !suffix.IsEmpty();
1524
1525 for( wxUniChar ch : suffix )
1526 {
1527 if( !wxIsdigit( ch ) )
1528 {
1529 allDigits = false;
1530 break;
1531 }
1532 }
1533
1534 if( allDigits )
1535 root = aBaseName.BeforeLast( '_' );
1536 }
1537
1538 for( int i = 1;; ++i )
1539 {
1540 wxString candidate = wxString::Format( wxT( "%s_%d" ), root, i );
1541
1542 if( !aInUse( candidate ) )
1543 return candidate;
1544 }
1545}
1546
1547
1548void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode, bool aSkipConnectivity )
1549{
1550 if( aBoardItem == nullptr )
1551 {
1552 wxFAIL_MSG( wxT( "BOARD::Add() param error: aBoardItem nullptr" ) );
1553 return;
1554 }
1555
1556 switch( aBoardItem->Type() )
1557 {
1558 case PCB_NETINFO_T:
1559 // A duplicate net is deleted here, so nothing below may touch it
1560 if( !m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem ) )
1561 return;
1562
1563 break;
1564
1565 // this one uses a vector
1566 case PCB_MARKER_T:
1567 m_markers.push_back( (PCB_MARKER*) aBoardItem );
1568 break;
1569
1570 // this one uses a vector
1571 case PCB_GROUP_T:
1572 m_groups.push_back( (PCB_GROUP*) aBoardItem );
1573 break;
1574
1575 case PCB_CONSTRAINT_T:
1576 m_constraints.push_back( (PCB_CONSTRAINT*) aBoardItem );
1577 break;
1578
1579 // this one uses a vector
1580 case PCB_GENERATOR_T:
1581 m_generators.push_back( (PCB_GENERATOR*) aBoardItem );
1582 break;
1583
1584 // this one uses a vector
1585 case PCB_ZONE_T:
1586 m_zones.push_back( (ZONE*) aBoardItem );
1587 break;
1588
1589 case PCB_VIA_T:
1590 if( aMode == ADD_MODE::APPEND || aMode == ADD_MODE::BULK_APPEND )
1591 m_tracks.push_back( static_cast<PCB_VIA*>( aBoardItem ) );
1592 else
1593 m_tracks.push_front( static_cast<PCB_VIA*>( aBoardItem ) );
1594
1595 break;
1596
1597 case PCB_TRACE_T:
1598 case PCB_ARC_T:
1599 if( !IsCopperLayer( aBoardItem->GetLayer() ) )
1600 {
1601 // The only current known source of these is SWIG (KICAD-BY7, et al).
1602 // N.B. This inserts a small memory leak as we lose the track/via/arc.
1603 wxFAIL_MSG( wxString::Format( "BOARD::Add() Cannot place Track on non-copper layer: %d = %s",
1604 static_cast<int>( aBoardItem->GetLayer() ),
1605 GetLayerName( aBoardItem->GetLayer() ) ) );
1606 return;
1607 }
1608
1609 if( aMode == ADD_MODE::APPEND || aMode == ADD_MODE::BULK_APPEND )
1610 m_tracks.push_back( static_cast<PCB_TRACK*>( aBoardItem ) );
1611 else
1612 m_tracks.push_front( static_cast<PCB_TRACK*>( aBoardItem ) );
1613
1614 break;
1615
1616 case PCB_FOOTPRINT_T:
1617 {
1618 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aBoardItem );
1619
1620 if( aMode == ADD_MODE::APPEND || aMode == ADD_MODE::BULK_APPEND )
1621 m_footprints.push_back( footprint );
1622 else
1623 m_footprints.push_front( footprint );
1624
1625 break;
1626 }
1627
1628 case PCB_BARCODE_T:
1629 case PCB_DIM_ALIGNED_T:
1630 case PCB_DIM_CENTER_T:
1631 case PCB_DIM_RADIAL_T:
1633 case PCB_DIM_LEADER_T:
1634 case PCB_SHAPE_T:
1636 case PCB_FIELD_T:
1637 case PCB_TEXT_T:
1638 case PCB_TEXTBOX_T:
1639 case PCB_TABLE_T:
1640 case PCB_DRILL_CHART_T:
1642 case PCB_DRILL_MAP_T:
1643 case PCB_TARGET_T:
1644 case PCB_GRID_ITEM_T:
1645 if( aMode == ADD_MODE::APPEND || aMode == ADD_MODE::BULK_APPEND )
1646 m_drawings.push_back( aBoardItem );
1647 else
1648 m_drawings.push_front( aBoardItem );
1649
1650 break;
1651
1652 case PCB_POINT_T:
1653 // These aren't graphics as they have no physical presence
1654 m_points.push_back( static_cast<PCB_POINT*>( aBoardItem ) );
1655 break;
1656
1657 case PCB_TABLECELL_T:
1658 // Handled by parent table
1659 break;
1660
1661 default:
1662 wxFAIL_MSG( wxString::Format( wxT( "BOARD::Add() item type %s not handled" ), aBoardItem->GetClass() ) );
1663 return;
1664 }
1665
1666 aBoardItem->SetParent( this );
1667 aBoardItem->ClearEditFlags();
1668
1669 // Index only after the item is accepted and parented, so a rejected item never lingers as a
1670 // dangling cache entry and an indexed item can always reach its board through its parent.
1671 CacheItemById( *aBoardItem );
1672
1673 if( aBoardItem->Type() == PCB_FOOTPRINT_T || BaseType( aBoardItem->Type() ) == PCB_TABLE_T )
1674 CacheChildrenById( *aBoardItem );
1675
1676 if( !aSkipConnectivity )
1677 m_connectivity->Add( aBoardItem );
1678
1679 if( aMode != ADD_MODE::BULK_INSERT && aMode != ADD_MODE::BULK_APPEND )
1681
1682 noteDrillModelChange( aBoardItem );
1683}
1684
1685
1686void BOARD::FinalizeBulkAdd( std::vector<BOARD_ITEM*>& aNewItems )
1687{
1689
1690 for( BOARD_ITEM* item : aNewItems )
1691 noteDrillModelChange( item );
1692}
1693
1694
1695void BOARD::FinalizeBulkRemove( std::vector<BOARD_ITEM*>& aRemovedItems )
1696{
1697 InvokeListeners( &BOARD_LISTENER::OnBoardItemsRemoved, *this, aRemovedItems );
1698
1699 for( BOARD_ITEM* item : aRemovedItems )
1700 noteDrillModelChange( item );
1701}
1702
1703
1705{
1706 for( int ii = (int) m_zones.size() - 1; ii >= 0; --ii )
1707 {
1708 ZONE* zone = m_zones[ii];
1709
1710 if( zone->IsTeardropArea() && zone->HasFlag( STRUCT_DELETED ) )
1711 {
1712 m_itemIndex.Unbind( zone->m_Uuid );
1713 m_zones.erase( m_zones.begin() + ii );
1715 m_connectivity->Remove( zone );
1716
1717 aCommit.Removed( zone );
1718 }
1719 }
1720}
1721
1722
1723void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
1724{
1725 // find these calls and fix them! Don't send me no stinking' nullptr.
1726 wxASSERT( aBoardItem );
1727
1728 // This is redundant with BOARD_COMMIT::Push but necessary to support SWIG interaction
1729 // until the SWIG API is completely removed (since it doesn't use the commit system)
1730 if( EDA_GROUP* parentGroup = aBoardItem->GetParentGroup();
1731 parentGroup && !( parentGroup->AsEdaItem()->GetFlags() & STRUCT_DELETED ) )
1732 {
1733 parentGroup->RemoveItem( aBoardItem );
1734 }
1735
1736 m_itemIndex.Unbind( aBoardItem->m_Uuid );
1737
1738 switch( aBoardItem->Type() )
1739 {
1740 case PCB_NETINFO_T:
1741 {
1742 NETINFO_ITEM* netItem = static_cast<NETINFO_ITEM*>( aBoardItem );
1743 NETINFO_ITEM* unconnected = m_NetInfo.GetNetItem( NETINFO_LIST::UNCONNECTED );
1744
1745 for( BOARD_CONNECTED_ITEM* boardItem : AllConnectedItems() )
1746 {
1747 if( boardItem->GetNet() == netItem )
1748 boardItem->SetNet( unconnected );
1749 }
1750
1751 m_NetInfo.RemoveNet( netItem );
1752 break;
1753 }
1754
1755 case PCB_MARKER_T:
1756 std::erase( m_markers, aBoardItem );
1757 break;
1758
1759 case PCB_GROUP_T:
1760 std::erase( m_groups, aBoardItem );
1761 break;
1762
1763 case PCB_CONSTRAINT_T:
1764 std::erase( m_constraints, aBoardItem );
1765 break;
1766
1767 case PCB_ZONE_T:
1768 std::erase( m_zones, aBoardItem );
1769 break;
1770
1771 case PCB_POINT_T:
1772 std::erase( m_points, aBoardItem );
1773 break;
1774
1775 case PCB_GENERATOR_T:
1776 std::erase( m_generators, aBoardItem );
1777 break;
1778
1779 case PCB_FOOTPRINT_T:
1780 std::erase( m_footprints, aBoardItem );
1781 UncacheChildrenById( *aBoardItem );
1782
1783 break;
1784
1785 case PCB_TRACE_T:
1786 case PCB_ARC_T:
1787 case PCB_VIA_T:
1788 std::erase( m_tracks, aBoardItem );
1789 break;
1790
1791 case PCB_BARCODE_T:
1792 case PCB_DIM_ALIGNED_T:
1793 case PCB_DIM_CENTER_T:
1794 case PCB_DIM_RADIAL_T:
1796 case PCB_DIM_LEADER_T:
1797 case PCB_SHAPE_T:
1799 case PCB_FIELD_T:
1800 case PCB_TEXT_T:
1801 case PCB_TEXTBOX_T:
1802 case PCB_TABLE_T:
1803 case PCB_DRILL_CHART_T:
1805 case PCB_DRILL_MAP_T:
1806 case PCB_TARGET_T:
1807 case PCB_GRID_ITEM_T:
1808 std::erase( m_drawings, aBoardItem );
1809
1810 if( BaseType( aBoardItem->Type() ) == PCB_TABLE_T )
1811 UncacheChildrenById( *aBoardItem );
1812
1813 break;
1814
1815 case PCB_TABLECELL_T:
1816 // Handled by parent table
1817 break;
1818
1819 // other types may use linked list
1820 default:
1821 wxFAIL_MSG( wxString::Format( wxT( "BOARD::Remove() item type %s not handled" ), aBoardItem->GetClass() ) );
1822 }
1823
1824 aBoardItem->SetFlags( STRUCT_DELETED );
1825
1826 m_connectivity->Remove( aBoardItem );
1827
1828 // Bump here, not in ~FOOTPRINT/~ZONE, so an item kept alive after removal (undo) still invalidates
1830
1831 if( aRemoveMode != REMOVE_MODE::BULK )
1833
1834 noteDrillModelChange( aBoardItem );
1835}
1836
1837
1838void BOARD::RemoveAll( std::initializer_list<KICAD_T> aTypes )
1839{
1840 std::vector<BOARD_ITEM*> removed;
1841 std::vector<NETINFO_ITEM*> removedNets;
1842
1843 for( const KICAD_T& type : aTypes )
1844 {
1845 switch( type )
1846 {
1847 case PCB_NETINFO_T:
1848 for( NETINFO_ITEM* item : m_NetInfo )
1849 {
1850 removed.emplace_back( item );
1851 removedNets.emplace_back( item );
1852 }
1853
1854 // Listeners must observe live pointers during FinalizeBulkRemove;
1855 // free after notification (issue 24100).
1856 m_NetInfo.detachAll();
1857 break;
1858
1859 case PCB_MARKER_T:
1860 std::copy( m_markers.begin(), m_markers.end(), std::back_inserter( removed ) );
1861 m_markers.clear();
1862 break;
1863
1864 case PCB_GROUP_T:
1865 std::copy( m_groups.begin(), m_groups.end(), std::back_inserter( removed ) );
1866 m_groups.clear();
1867 break;
1868
1869 case PCB_CONSTRAINT_T:
1870 std::copy( m_constraints.begin(), m_constraints.end(), std::back_inserter( removed ) );
1871 m_constraints.clear();
1872 break;
1873
1874 case PCB_POINT_T:
1875 std::copy( m_points.begin(), m_points.end(), std::back_inserter( removed ) );
1876 m_points.clear();
1877 break;
1878
1879 case PCB_ZONE_T:
1880 std::copy( m_zones.begin(), m_zones.end(), std::back_inserter( removed ) );
1881 m_zones.clear();
1882 break;
1883
1884 case PCB_GENERATOR_T:
1885 std::copy( m_generators.begin(), m_generators.end(), std::back_inserter( removed ) );
1886 m_generators.clear();
1887 break;
1888
1889 case PCB_FOOTPRINT_T:
1890 std::copy( m_footprints.begin(), m_footprints.end(), std::back_inserter( removed ) );
1891 m_footprints.clear();
1892 break;
1893
1894 case PCB_TRACE_T:
1895 std::copy( m_tracks.begin(), m_tracks.end(), std::back_inserter( removed ) );
1896 m_tracks.clear();
1897 break;
1898
1899 case PCB_ARC_T:
1900 case PCB_VIA_T:
1901 wxFAIL_MSG( wxT( "Use PCB_TRACE_T to remove all tracks, arcs, and vias" ) );
1902 break;
1903
1904 case PCB_SHAPE_T:
1905 std::copy( m_drawings.begin(), m_drawings.end(), std::back_inserter( removed ) );
1906 m_drawings.clear();
1907 break;
1908
1909 case PCB_DIM_ALIGNED_T:
1910 case PCB_DIM_CENTER_T:
1911 case PCB_DIM_RADIAL_T:
1913 case PCB_DIM_LEADER_T:
1915 case PCB_FIELD_T:
1916 case PCB_TEXT_T:
1917 case PCB_TEXTBOX_T:
1918 case PCB_TABLE_T:
1919 case PCB_DRILL_CHART_T:
1921 case PCB_DRILL_MAP_T:
1922 case PCB_TARGET_T:
1923 case PCB_BARCODE_T:
1924 wxFAIL_MSG( wxT( "Use PCB_SHAPE_T to remove all graphics and text" ) );
1925 break;
1926
1927 default:
1928 wxFAIL_MSG( wxT( "BOARD::RemoveAll() needs more ::Type() support" ) );
1929 }
1930 }
1931
1932 for( BOARD_ITEM* item : removed )
1933 m_connectivity->Remove( item );
1934
1936
1938
1939 FinalizeBulkRemove( removed );
1940
1941 for( NETINFO_ITEM* item : removedNets )
1942 delete item;
1943}
1944
1945
1947{
1948 PCB_LAYER_COLLECTOR collector;
1949
1950 collector.SetLayerId( aLayer );
1952
1953 if( collector.GetCount() != 0 )
1954 {
1955 // Skip items owned by footprints and footprints when building
1956 // the actual list of removed layers: these items are not removed
1957 for( int i = 0; i < collector.GetCount(); i++ )
1958 {
1959 BOARD_ITEM* item = collector[i];
1960
1961 if( item->Type() == PCB_FOOTPRINT_T || item->GetParentFootprint() )
1962 continue;
1963
1964 // Vias are on multiple adjacent layers, but only the top and
1965 // the bottom layers are stored. So there are issues only if one
1966 // is on a removed layer
1967 if( item->Type() == PCB_VIA_T )
1968 {
1969 PCB_VIA* via = static_cast<PCB_VIA*>( item );
1970
1971 if( via->GetViaType() == VIATYPE::THROUGH )
1972 continue;
1973 else
1974 {
1975 PCB_LAYER_ID top_layer;
1976 PCB_LAYER_ID bottom_layer;
1977 via->LayerPair( &top_layer, &bottom_layer );
1978
1979 if( top_layer != aLayer && bottom_layer != aLayer )
1980 continue;
1981 }
1982 }
1983
1984 return true;
1985 }
1986 }
1987
1988 return false;
1989}
1990
1991
1993{
1994 bool modified = false;
1995 bool removedItemLayers = false;
1996 PCB_LAYER_COLLECTOR collector;
1997
1998 collector.SetLayerId( aLayer );
2000
2001 for( int i = 0; i < collector.GetCount(); i++ )
2002 {
2003 BOARD_ITEM* item = collector[i];
2004
2005 // Do not remove/change an item owned by a footprint
2006 if( item->GetParentFootprint() )
2007 continue;
2008
2009 // Do not remove footprints
2010 if( item->Type() == PCB_FOOTPRINT_T )
2011 continue;
2012
2013 // Note: vias are specific. They are only on copper layers, and
2014 // do not use a layer set, only store the copper top and the copper bottom.
2015 // So reinit the layer set does not work with vias
2016 if( item->Type() == PCB_VIA_T )
2017 {
2018 PCB_VIA* via = static_cast<PCB_VIA*>( item );
2019
2020 if( via->GetViaType() == VIATYPE::THROUGH )
2021 {
2022 removedItemLayers = true;
2023 continue;
2024 }
2025 else if( via->IsOnLayer( aLayer ) )
2026 {
2027 PCB_LAYER_ID top_layer;
2028 PCB_LAYER_ID bottom_layer;
2029 via->LayerPair( &top_layer, &bottom_layer );
2030
2031 if( top_layer == aLayer || bottom_layer == aLayer )
2032 {
2033 // blind/buried vias with a top or bottom layer on a removed layer
2034 // are removed. Perhaps one could just modify the top/bottom layer,
2035 // but I am not sure this is better.
2036 Remove( item );
2037 delete item;
2038 modified = true;
2039 }
2040
2041 removedItemLayers = true;
2042 }
2043 }
2044 else if( item->IsOnLayer( aLayer ) )
2045 {
2046 LSET layers = item->GetLayerSet();
2047
2048 layers.reset( aLayer );
2049
2050 if( layers.any() )
2051 {
2052 item->SetLayerSet( layers );
2053 }
2054 else
2055 {
2056 Remove( item );
2057 delete item;
2058 modified = true;
2059 }
2060
2061 removedItemLayers = true;
2062 }
2063 }
2064
2065 if( removedItemLayers )
2067
2068 return modified;
2069}
2070
2071
2072wxString BOARD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
2073{
2074 return wxString::Format( _( "PCB" ) );
2075}
2076
2077
2079{
2080 INSPECTOR_FUNC inspector = [&]( EDA_ITEM* descendant, void* aTestData )
2081 {
2082 PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( descendant );
2083
2084 if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
2085 {
2086 dimension->UpdateUnits();
2087
2088 if( aView )
2089 aView->Update( dimension );
2090 }
2091
2093 };
2094
2095 aItem->Visit( inspector, nullptr,
2097}
2098
2099
2101{
2102 for( PCB_MARKER* marker : m_markers )
2103 m_itemIndex.Unbind( marker->m_Uuid );
2104
2105 for( PCB_MARKER* marker : m_markers )
2106 delete marker;
2107
2108 m_markers.clear();
2110}
2111
2112
2113void BOARD::DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions )
2114{
2115 // Deleting lots of items from a vector can be very slow. Copy remaining items instead.
2116 std::vector<PCB_MARKER*> remaining;
2117
2118 for( PCB_MARKER* marker : m_markers )
2119 {
2120 if( ( marker->GetSeverity() == RPT_SEVERITY_EXCLUSION && aExclusions )
2121 || ( marker->GetSeverity() != RPT_SEVERITY_EXCLUSION && aWarningsAndErrors ) )
2122 {
2123 m_itemIndex.Unbind( marker->m_Uuid );
2124 delete marker;
2125 }
2126 else
2127 {
2128 remaining.push_back( marker );
2129 }
2130 }
2131
2132 m_markers = std::move( remaining );
2134}
2135
2136
2138{
2139 std::vector<FOOTPRINT*> footprints;
2140 std::copy( m_footprints.begin(), m_footprints.end(), std::back_inserter( footprints ) );
2141
2143
2144 for( FOOTPRINT* footprint : footprints )
2145 delete footprint;
2146}
2147
2148
2150{
2151 std::vector<FOOTPRINT*> footprints;
2152 std::copy( m_footprints.begin(), m_footprints.end(), std::back_inserter( footprints ) );
2153
2155
2156 for( FOOTPRINT* footprint : footprints )
2157 footprint->SetParent( nullptr );
2158}
2159
2160
2161static PCB_TABLECELL* findTableCell( const BOARD_ITEM* aDrawing, const KIID& aID )
2162{
2163 if( BaseType( aDrawing->Type() ) != PCB_TABLE_T )
2164 return nullptr;
2165
2166 for( PCB_TABLECELL* cell : static_cast<const PCB_TABLE*>( aDrawing )->GetCells() )
2167 {
2168 if( cell->m_Uuid == aID )
2169 return cell;
2170 }
2171
2172 return nullptr;
2173}
2174
2175
2176BOARD_ITEM* BOARD::ResolveItem( const KIID& aID, bool aAllowNullptrReturn ) const
2177{
2178 if( aID == niluuid )
2179 return nullptr;
2180
2181 if( BOARD_ITEM* cached = m_itemIndex.Find( aID ) )
2182 return cached;
2183
2184 // Cache the item and return it.
2185 // The item MUST match the requested UUID.
2186 const auto cacheAndReturn =
2187 [&]( BOARD_ITEM& aItem ) -> BOARD_ITEM*
2188 {
2189 wxASSERT_MSG( aItem.m_Uuid == aID,
2190 wxT( "BOARD::ResolveItem() must only return an item that carries the requested UUID" ) );
2191 CacheItemById( aItem );
2192 return &aItem;
2193 };
2194
2195 // Linear scan fallback for items not in the cache. Any hit is cached so
2196 // subsequent lookups for the same item are O(1).
2197
2198 for( PCB_GROUP* group : m_groups )
2199 {
2200 if( group->m_Uuid == aID )
2201 return cacheAndReturn( *group );
2202 }
2203
2204 for( PCB_CONSTRAINT* constraint : m_constraints )
2205 {
2206 if( constraint->m_Uuid == aID )
2207 return cacheAndReturn( *constraint );
2208 }
2209
2210 for( PCB_GENERATOR* generator : m_generators )
2211 {
2212 if( generator->m_Uuid == aID )
2213 return cacheAndReturn( *generator );
2214 }
2215
2216 for( PCB_TRACK* track : Tracks() )
2217 {
2218 if( track->m_Uuid == aID )
2219 return cacheAndReturn( *track );
2220 }
2221
2222 for( FOOTPRINT* footprint : Footprints() )
2223 {
2224 if( footprint->m_Uuid == aID )
2225 return cacheAndReturn( *footprint );
2226
2227 for( PAD* pad : footprint->Pads() )
2228 {
2229 if( pad->m_Uuid == aID )
2230 return cacheAndReturn( *pad );
2231 }
2232
2233 for( PCB_FIELD* field : footprint->GetFields() )
2234 {
2235 wxCHECK2( field, continue );
2236
2237 if( field && field->m_Uuid == aID )
2238 return cacheAndReturn( *field );
2239 }
2240
2241 for( BOARD_ITEM* drawing : footprint->GraphicalItems() )
2242 {
2243 if( PCB_TABLECELL* cell = findTableCell( drawing, aID ) )
2244 return cacheAndReturn( *cell );
2245
2246 if( drawing->m_Uuid == aID )
2247 return cacheAndReturn( *drawing );
2248 }
2249
2250 for( BOARD_ITEM* zone : footprint->Zones() )
2251 {
2252 if( zone->m_Uuid == aID )
2253 return cacheAndReturn( *zone );
2254 }
2255
2256 for( PCB_GROUP* group : footprint->Groups() )
2257 {
2258 if( group->m_Uuid == aID )
2259 return cacheAndReturn( *group );
2260 }
2261
2262 for( PCB_CONSTRAINT* constraint : footprint->Constraints() )
2263 {
2264 if( constraint->m_Uuid == aID )
2265 return cacheAndReturn( *constraint );
2266 }
2267
2268 for( PCB_POINT* point : footprint->Points() )
2269 {
2270 if( point->m_Uuid == aID )
2271 return cacheAndReturn( *point );
2272 }
2273
2274 for( PCB_3D_BODY* body : footprint->Bodies() )
2275 {
2276 if( body->m_Uuid == aID )
2277 return cacheAndReturn( *body );
2278 }
2279 }
2280
2281 for( ZONE* zone : Zones() )
2282 {
2283 if( zone->m_Uuid == aID )
2284 return cacheAndReturn( *zone );
2285 }
2286
2287 for( BOARD_ITEM* drawing : Drawings() )
2288 {
2289 if( PCB_TABLECELL* cell = findTableCell( drawing, aID ) )
2290 return cacheAndReturn( *cell );
2291
2292 if( drawing->m_Uuid == aID )
2293 return cacheAndReturn( *drawing );
2294 }
2295
2296 for( PCB_MARKER* marker : m_markers )
2297 {
2298 if( marker->m_Uuid == aID )
2299 return cacheAndReturn( *marker );
2300 }
2301
2302 for( PCB_POINT* point : m_points )
2303 {
2304 if( point->m_Uuid == aID )
2305 return cacheAndReturn( *point );
2306 }
2307
2308 for( NETINFO_ITEM* netInfo : m_NetInfo )
2309 {
2310 if( netInfo->m_Uuid == aID )
2311 return cacheAndReturn( *netInfo );
2312 }
2313
2314 if( m_Uuid == aID )
2315 return const_cast<BOARD*>( this );
2316
2317 // Not found; weak reference has been deleted.
2318 if( aAllowNullptrReturn )
2319 return nullptr;
2320
2322}
2323
2324
2325
2327{
2328 std::set<KIID> ids;
2329 int duplicates = 0;
2330
2331 auto processItem =
2332 [&]( BOARD_ITEM* aItem )
2333 {
2334 wxCHECK2( aItem, return );
2335
2336 if( ids.count( aItem->m_Uuid ) )
2337 {
2338 duplicates++;
2339 RebindItemUuid( *aItem, KIID() );
2340 }
2341
2342 ids.insert( aItem->m_Uuid );
2343 };
2344
2345 // Footprint IDs are the most important, so give them the first crack at "claiming" a
2346 // particular KIID.
2347 for( FOOTPRINT* footprint : Footprints() )
2348 processItem( footprint );
2349
2350 // After that the principal use is for DRC marker pointers, which are most likely to pads
2351 // or tracks.
2352 for( FOOTPRINT* footprint : Footprints() )
2353 {
2354 for( PAD* pad : footprint->Pads() )
2355 processItem( pad );
2356 }
2357
2358 for( PCB_TRACK* track : Tracks() )
2359 processItem( track );
2360
2361 // From here out I don't think order matters much.
2362 for( FOOTPRINT* footprint : Footprints() )
2363 {
2364 processItem( &footprint->Reference() );
2365 processItem( &footprint->Value() );
2366
2367 for( BOARD_ITEM* item : footprint->GraphicalItems() )
2368 processItem( item );
2369
2370 for( PCB_3D_BODY* body : footprint->Bodies() )
2371 processItem( body );
2372
2373 for( ZONE* zone : footprint->Zones() )
2374 processItem( zone );
2375
2376 for( PCB_GROUP* group : footprint->Groups() )
2377 processItem( group );
2378 }
2379
2380 // Everything owned by the board not handled above.
2381 for( BOARD_ITEM* item : GetItemSet() )
2382 {
2383 // Top-level footprints and tracks were handled above.
2384 switch( item->Type() )
2385 {
2386 case PCB_FOOTPRINT_T:
2387 case PCB_TRACE_T:
2388 case PCB_ARC_T:
2389 case PCB_VIA_T:
2390 break;
2391
2392 default:
2393 processItem( item );
2394 break;
2395 }
2396 }
2397
2398 return duplicates;
2399}
2400
2401
2402wxString BOARD::ConvertCrossReferencesToKIIDs( const wxString& aSource ) const
2403{
2404 wxString newbuf;
2405 size_t sourceLen = aSource.length();
2406
2407 for( size_t i = 0; i < sourceLen; ++i )
2408 {
2409 // Check for escaped expressions: \${ or \@{
2410 // These should be copied verbatim without any ref→KIID conversion
2411 if( aSource[i] == '\\' && i + 2 < sourceLen && aSource[i + 2] == '{' &&
2412 ( aSource[i + 1] == '$' || aSource[i + 1] == '@' ) )
2413 {
2414 // Copy the escape sequence and the entire escaped expression
2415 newbuf.append( aSource[i] ); // backslash
2416 newbuf.append( aSource[i + 1] ); // $ or @
2417 newbuf.append( aSource[i + 2] ); // {
2418 i += 2;
2419
2420 // Find and copy everything until the matching closing brace
2421 int braceDepth = 1;
2422 for( i = i + 1; i < sourceLen && braceDepth > 0; ++i )
2423 {
2424 if( aSource[i] == '{' )
2425 braceDepth++;
2426 else if( aSource[i] == '}' )
2427 braceDepth--;
2428
2429 newbuf.append( aSource[i] );
2430 }
2431 i--; // Back up one since the for loop will increment
2432 continue;
2433 }
2434
2435 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i + 1] == '{' )
2436 {
2437 wxString token;
2438 bool isCrossRef = false;
2439
2440 for( i = i + 2; i < sourceLen; ++i )
2441 {
2442 if( aSource[i] == '}' )
2443 break;
2444
2445 if( aSource[i] == ':' )
2446 isCrossRef = true;
2447
2448 token.append( aSource[i] );
2449 }
2450
2451 if( isCrossRef )
2452 {
2453 wxString remainder;
2454 wxString ref = token.BeforeFirst( ':', &remainder );
2455
2456 for( const FOOTPRINT* footprint : Footprints() )
2457 {
2458 if( footprint->GetReference().CmpNoCase( ref ) == 0 )
2459 {
2460 wxString test( remainder );
2461
2462 if( footprint->ResolveTextVar( &test ) )
2463 token = footprint->m_Uuid.AsString() + wxT( ":" ) + remainder;
2464
2465 break;
2466 }
2467 }
2468 }
2469
2470 newbuf.append( wxT( "${" ) + token + wxT( "}" ) );
2471 }
2472 else
2473 {
2474 newbuf.append( aSource[i] );
2475 }
2476 }
2477
2478 return newbuf;
2479}
2480
2481
2482wxString BOARD::ConvertKIIDsToCrossReferences( const wxString& aSource ) const
2483{
2484 wxString newbuf;
2485 size_t sourceLen = aSource.length();
2486
2487 for( size_t i = 0; i < sourceLen; ++i )
2488 {
2489 // Check for escaped expressions: \${ or \@{
2490 // These should be copied verbatim without any KIID→ref conversion
2491 if( aSource[i] == '\\' && i + 2 < sourceLen && aSource[i + 2] == '{' &&
2492 ( aSource[i + 1] == '$' || aSource[i + 1] == '@' ) )
2493 {
2494 // Copy the escape sequence and the entire escaped expression
2495 newbuf.append( aSource[i] ); // backslash
2496 newbuf.append( aSource[i + 1] ); // $ or @
2497 newbuf.append( aSource[i + 2] ); // {
2498 i += 2;
2499
2500 // Find and copy everything until the matching closing brace
2501 int braceDepth = 1;
2502 for( i = i + 1; i < sourceLen && braceDepth > 0; ++i )
2503 {
2504 if( aSource[i] == '{' )
2505 braceDepth++;
2506 else if( aSource[i] == '}' )
2507 braceDepth--;
2508
2509 newbuf.append( aSource[i] );
2510 }
2511 i--; // Back up one since the for loop will increment
2512 continue;
2513 }
2514
2515 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i + 1] == '{' )
2516 {
2517 wxString token;
2518 bool isCrossRef = false;
2519
2520 for( i = i + 2; i < sourceLen; ++i )
2521 {
2522 if( aSource[i] == '}' )
2523 break;
2524
2525 if( aSource[i] == ':' )
2526 isCrossRef = true;
2527
2528 token.append( aSource[i] );
2529 }
2530
2531 if( isCrossRef )
2532 {
2533 wxString remainder;
2534 wxString ref = token.BeforeFirst( ':', &remainder );
2535 BOARD_ITEM* refItem = ResolveItem( KIID( ref ), true );
2536
2537 if( refItem && refItem->Type() == PCB_FOOTPRINT_T )
2538 {
2539 token = static_cast<FOOTPRINT*>( refItem )->GetReference() + wxT( ":" ) + remainder;
2540 }
2541 }
2542
2543 newbuf.append( wxT( "${" ) + token + wxT( "}" ) );
2544 }
2545 else
2546 {
2547 newbuf.append( aSource[i] );
2548 }
2549 }
2550
2551 return newbuf;
2552}
2553
2554
2555unsigned BOARD::GetNodesCount( int aNet ) const
2556{
2557 unsigned retval = 0;
2558
2559 for( FOOTPRINT* footprint : Footprints() )
2560 {
2561 for( PAD* pad : footprint->Pads() )
2562 {
2563 if( ( aNet == -1 && pad->GetNetCode() > 0 ) || aNet == pad->GetNetCode() )
2564 retval++;
2565 }
2566 }
2567
2568 return retval;
2569}
2570
2571
2572BOX2I BOARD::ComputeBoundingBox( bool aBoardEdgesOnly, bool aPhysicalLayersOnly ) const
2573{
2574 BOX2I bbox;
2575 LSET visible = GetVisibleLayers();
2576
2577 if( aPhysicalLayersOnly )
2578 visible &= LSET::PhysicalLayersMask();
2579
2580 // If the board is just showing a footprint, we want all footprint layers included in the
2581 // bounding box
2582 if( IsFootprintHolder() )
2583 visible.set();
2584
2585 if( aBoardEdgesOnly )
2586 visible.set( Edge_Cuts );
2587
2588 // Check shapes, dimensions, texts, and fiducials
2589 for( BOARD_ITEM* item : m_drawings )
2590 {
2591 if( aBoardEdgesOnly && ( item->Type() != PCB_SHAPE_T || item->GetLayer() != Edge_Cuts ) )
2592 continue;
2593
2594 if( ( item->GetLayerSet() & visible ).any() )
2595 bbox.Merge( item->GetBoundingBox() );
2596 }
2597
2598 // Check footprints
2599 for( FOOTPRINT* footprint : m_footprints )
2600 {
2601 if( aBoardEdgesOnly )
2602 {
2603 for( const BOARD_ITEM* edge : footprint->GraphicalItems() )
2604 {
2605 if( edge->GetLayer() == Edge_Cuts && edge->Type() == PCB_SHAPE_T )
2606 bbox.Merge( edge->GetBoundingBox() );
2607 }
2608 }
2609 else if( ( footprint->GetLayerSet() & visible ).any() )
2610 {
2611 bbox.Merge( footprint->GetBoundingBox( true ) );
2612 }
2613 }
2614
2615 if( !aBoardEdgesOnly )
2616 {
2617 // Check tracks
2618 for( PCB_TRACK* track : m_tracks )
2619 {
2620 if( ( track->GetLayerSet() & visible ).any() )
2621 bbox.Merge( track->GetBoundingBox() );
2622 }
2623
2624 // Check zones
2625 for( ZONE* aZone : m_zones )
2626 {
2627 if( ( aZone->GetLayerSet() & visible ).any() )
2628 bbox.Merge( aZone->GetBoundingBox() );
2629 }
2630
2631 if( !aPhysicalLayersOnly )
2632 {
2633 for( PCB_POINT* point : m_points )
2634 bbox.Merge( point->GetBoundingBox() );
2635 }
2636 }
2637
2638 return bbox;
2639}
2640
2641
2642void BOARD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
2643{
2644 int padCount = 0;
2645 int viaCount = 0;
2646 int trackSegmentCount = 0;
2647 std::set<int> netCodes;
2648 int unconnected = GetConnectivity()->GetUnconnectedCount( true );
2649
2650 for( PCB_TRACK* item : m_tracks )
2651 {
2652 if( item->Type() == PCB_VIA_T )
2653 viaCount++;
2654 else
2655 trackSegmentCount++;
2656
2657 if( item->GetNetCode() > 0 )
2658 netCodes.insert( item->GetNetCode() );
2659 }
2660
2661 for( FOOTPRINT* footprint : Footprints() )
2662 {
2663 for( PAD* pad : footprint->Pads() )
2664 {
2665 padCount++;
2666
2667 if( pad->GetNetCode() > 0 )
2668 netCodes.insert( pad->GetNetCode() );
2669 }
2670 }
2671
2672 aList.emplace_back( _( "Pads" ), wxString::Format( wxT( "%d" ), padCount ) );
2673 aList.emplace_back( _( "Vias" ), wxString::Format( wxT( "%d" ), viaCount ) );
2674 aList.emplace_back( _( "Track Segments" ), wxString::Format( wxT( "%d" ), trackSegmentCount ) );
2675 aList.emplace_back( _( "Nets" ), wxString::Format( wxT( "%d" ), (int) netCodes.size() ) );
2676 aList.emplace_back( _( "Unrouted" ), wxString::Format( wxT( "%d" ), unconnected ) );
2677}
2678
2679
2680INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const std::vector<KICAD_T>& scanTypes )
2681{
2682#if 0 && defined( DEBUG )
2683 std::cout << GetClass().mb_str() << ' ';
2684#endif
2685
2686 bool footprintsScanned = false;
2687 bool drawingsScanned = false;
2688 bool tracksScanned = false;
2689
2690 for( KICAD_T scanType : scanTypes )
2691 {
2692 switch( scanType )
2693 {
2694 case PCB_T:
2695 if( inspector( this, testData ) == INSPECT_RESULT::QUIT )
2696 return INSPECT_RESULT::QUIT;
2697
2698 break;
2699
2700 /*
2701 * Instances of the requested KICAD_T live in a list, either one that I manage, or one
2702 * that my footprints manage. If it's a type managed by class FOOTPRINT, then simply
2703 * pass it on to each footprint's Visit() function via IterateForward( m_footprints, ... ).
2704 */
2705
2706 case PCB_FOOTPRINT_T:
2707 case PCB_PAD_T:
2708 case PCB_SHAPE_T:
2710 case PCB_FIELD_T:
2711 case PCB_TEXT_T:
2712 case PCB_TEXTBOX_T:
2713 case PCB_TABLE_T:
2714 case PCB_DRILL_CHART_T:
2716 case PCB_DRILL_MAP_T:
2717 case PCB_TABLECELL_T:
2718 case PCB_DIM_ALIGNED_T:
2719 case PCB_DIM_CENTER_T:
2720 case PCB_DIM_RADIAL_T:
2722 case PCB_DIM_LEADER_T:
2723 case PCB_TARGET_T:
2724 case PCB_BARCODE_T:
2725 case PCB_GRID_ITEM_T:
2726 if( !footprintsScanned )
2727 {
2728 if( IterateForward<FOOTPRINT*>( m_footprints, inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
2729 return INSPECT_RESULT::QUIT;
2730
2731 footprintsScanned = true;
2732 }
2733
2734 if( !drawingsScanned )
2735 {
2736 if( IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
2737 return INSPECT_RESULT::QUIT;
2738
2739 drawingsScanned = true;
2740 }
2741
2742 break;
2743
2744 case PCB_VIA_T:
2745 case PCB_TRACE_T:
2746 case PCB_ARC_T:
2747 if( !tracksScanned )
2748 {
2749 if( IterateForward<PCB_TRACK*>( m_tracks, inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
2750 return INSPECT_RESULT::QUIT;
2751
2752 tracksScanned = true;
2753 }
2754
2755 break;
2756
2757 case PCB_MARKER_T:
2758 for( PCB_MARKER* marker : m_markers )
2759 {
2760 if( marker->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
2761 return INSPECT_RESULT::QUIT;
2762 }
2763
2764 break;
2765
2766 case PCB_POINT_T:
2767 for( PCB_POINT* point : m_points )
2768 {
2769 if( point->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
2770 return INSPECT_RESULT::QUIT;
2771 }
2772
2773 break;
2774
2775 case PCB_ZONE_T:
2776 if( !footprintsScanned )
2777 {
2778 if( IterateForward<FOOTPRINT*>( m_footprints, inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
2779 return INSPECT_RESULT::QUIT;
2780
2781 footprintsScanned = true;
2782 }
2783
2784 for( ZONE* zone : m_zones )
2785 {
2786 if( zone->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
2787 return INSPECT_RESULT::QUIT;
2788 }
2789
2790 break;
2791
2792 case PCB_GENERATOR_T:
2793 if( !footprintsScanned )
2794 {
2795 if( IterateForward<FOOTPRINT*>( m_footprints, inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
2796 return INSPECT_RESULT::QUIT;
2797
2798 footprintsScanned = true;
2799 }
2800
2801 if( IterateForward<PCB_GENERATOR*>( m_generators, inspector, testData, { scanType } )
2803 {
2804 return INSPECT_RESULT::QUIT;
2805 }
2806
2807 break;
2808
2809 case PCB_GROUP_T:
2810 if( IterateForward<PCB_GROUP*>( m_groups, inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
2811 return INSPECT_RESULT::QUIT;
2812
2813 break;
2814
2815 case PCB_CONSTRAINT_T:
2816 if( IterateForward<PCB_CONSTRAINT*>( m_constraints, inspector, testData, { scanType } )
2818 {
2819 return INSPECT_RESULT::QUIT;
2820 }
2821
2822 break;
2823
2824 default:
2825 break;
2826 }
2827 }
2828
2830}
2831
2832
2833NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const
2834{
2835 // the first valid netcode is 1 and the last is m_NetInfo.GetCount()-1.
2836 // zero is reserved for "no connection" and is not actually a net.
2837 // nullptr is returned for non valid netcodes
2838
2839 if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 )
2841 else
2842 return m_NetInfo.GetNetItem( aNetcode );
2843}
2844
2845
2846NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const
2847{
2848 return m_NetInfo.GetNetItem( aNetname );
2849}
2850
2851
2852NETINFO_ITEM* BOARD::FindOrAddNet( const wxString& aNetName, int aNetCode, ADD_MODE aMode, bool aSkipConnectivity )
2853{
2854 if( NETINFO_ITEM* existing = FindNet( aNetName ) )
2855 return existing;
2856
2857 NETINFO_ITEM* net = new NETINFO_ITEM( this, aNetName, aNetCode );
2858 Add( net, aMode, aSkipConnectivity );
2859 return net;
2860}
2861
2862
2863int BOARD::MatchDpSuffix( const wxString& aNetName, wxString& aComplementNet )
2864{
2865 int rv = 0;
2866 int count = 0;
2867
2868 for( auto it = aNetName.rbegin(); it != aNetName.rend() && rv == 0; ++it, ++count )
2869 {
2870 int ch = *it;
2871
2872 if( ( ch >= '0' && ch <= '9' ) || ch == '_' )
2873 {
2874 continue;
2875 }
2876 else if( ch == '+' )
2877 {
2878 aComplementNet = wxT( "-" );
2879 rv = 1;
2880 }
2881 else if( ch == '-' )
2882 {
2883 aComplementNet = wxT( "+" );
2884 rv = -1;
2885 }
2886 else if( ch == 'N' )
2887 {
2888 aComplementNet = wxT( "P" );
2889 rv = -1;
2890 }
2891 else if( ch == 'P' )
2892 {
2893 aComplementNet = wxT( "N" );
2894 rv = 1;
2895 }
2896 else
2897 {
2898 break;
2899 }
2900 }
2901
2902 if( rv != 0 && count >= 1 )
2903 {
2904 aComplementNet = aNetName.Left( aNetName.length() - count ) + aComplementNet + aNetName.Right( count - 1 );
2905 }
2906
2907 return rv;
2908}
2909
2910
2912{
2913 if( aNet )
2914 {
2915 wxString refName = aNet->GetNetname();
2916 wxString coupledNetName;
2917
2918 if( MatchDpSuffix( refName, coupledNetName ) )
2919 return FindNet( coupledNetName );
2920 }
2921
2922 return nullptr;
2923}
2924
2925
2926FOOTPRINT* BOARD::FindFootprintByReference( const wxString& aReference ) const
2927{
2928 for( FOOTPRINT* footprint : m_footprints )
2929 {
2930 if( aReference == footprint->GetReference() )
2931 return footprint;
2932 }
2933
2934 return nullptr;
2935}
2936
2937
2939{
2940 for( FOOTPRINT* footprint : m_footprints )
2941 {
2942 if( footprint->GetPath() == aPath )
2943 return footprint;
2944 }
2945
2946 return nullptr;
2947}
2948
2949
2950PAD* BOARD::FindPadByUuid( const KIID& aUuid ) const
2951{
2952 for( FOOTPRINT* footprint : m_footprints )
2953 {
2954 if( PAD* pad = footprint->FindPadByUuid( aUuid ) )
2955 return pad;
2956 }
2957
2958 return nullptr;
2959}
2960
2961
2962void BOARD::ReplaceNetChainTerminalPad( const wxString& aNetChain, const KIID& aPrev, const KIID& aNew )
2963{
2964 PAD* newPad = FindPadByUuid( aNew );
2965
2966 for( NETINFO_ITEM* net : m_NetInfo )
2967 {
2968 if( net->GetNetChain() == aNetChain )
2969 {
2970 for( int i = 0; i < 2; ++i )
2971 {
2972 PAD* pad = net->GetTerminalPad( i );
2973
2974 if( pad && pad->m_Uuid == aPrev )
2975 net->SetTerminalPad( i, newPad );
2976 }
2977 }
2978 }
2979}
2980
2981
2983{
2984 std::set<wxString> names;
2985
2986 for( const NETINFO_ITEM* net : m_NetInfo )
2987 {
2988 if( !net->GetNetname().IsEmpty() )
2989 names.insert( net->GetNetname() );
2990 }
2991
2992 return names;
2993}
2994
2995
2997{
2998 if( m_project && !m_project->IsNullProject() )
2999 SetProperties( m_project->GetTextVars() );
3000}
3001
3002
3003static wxString FindVariantNameCaseInsensitive( const std::vector<wxString>& aNames,
3004 const wxString& aVariantName )
3005{
3006 for( const wxString& name : aNames )
3007 {
3008 if( name.CmpNoCase( aVariantName ) == 0 )
3009 return name;
3010 }
3011
3012 return wxEmptyString;
3013}
3014
3015
3016void BOARD::SetCurrentVariant( const wxString& aVariant )
3017{
3018 const wxString previous = m_currentVariant;
3019
3020 if( aVariant.IsEmpty() || aVariant.CmpNoCase( GetDefaultVariantName() ) == 0 )
3021 {
3022 m_currentVariant.Clear();
3023 }
3024 else
3025 {
3026 wxString actualName = FindVariantNameCaseInsensitive( m_variantNames, aVariant );
3027
3028 if( actualName.IsEmpty() )
3029 m_currentVariant.Clear();
3030 else
3031 m_currentVariant = actualName;
3032 }
3033
3034 // Variant overrides on footprint fields change `${REFDES:FIELD}` resolution,
3035 // so every cross-ref dependent must repaint on switch. Skip the fan-out if
3036 // the active variant did not actually change (e.g. redundant UI callback).
3037 if( previous != m_currentVariant && m_textVarAdapter )
3038 m_textVarAdapter->Tracker().InvalidateVariantScoped();
3039}
3040
3041
3042bool BOARD::HasVariant( const wxString& aVariantName ) const
3043{
3044 return !FindVariantNameCaseInsensitive( m_variantNames, aVariantName ).IsEmpty();
3045}
3046
3047
3048void BOARD::AddVariant( const wxString& aVariantName )
3049{
3050 if( aVariantName.IsEmpty()
3051 || aVariantName.CmpNoCase( GetDefaultVariantName() ) == 0
3052 || HasVariant( aVariantName ) )
3053 {
3054 return;
3055 }
3056
3057 m_variantNames.push_back( aVariantName );
3058}
3059
3060
3061void BOARD::DeleteVariant( const wxString& aVariantName )
3062{
3063 if( aVariantName.IsEmpty() || aVariantName.CmpNoCase( GetDefaultVariantName() ) == 0 )
3064 return;
3065
3066 auto it = std::find_if( m_variantNames.begin(), m_variantNames.end(),
3067 [&]( const wxString& name )
3068 {
3069 return name.CmpNoCase( aVariantName ) == 0;
3070 } );
3071
3072 if( it != m_variantNames.end() )
3073 {
3074 wxString actualName = *it;
3075 m_variantNames.erase( it );
3076 m_variantDescriptions.erase( actualName );
3077
3078 // Clear current variant if it was the deleted one
3079 if( m_currentVariant.CmpNoCase( aVariantName ) == 0 )
3080 m_currentVariant.Clear();
3081
3082 // Remove variant from all footprints
3083 for( FOOTPRINT* fp : m_footprints )
3084 fp->DeleteVariant( actualName );
3085 }
3086}
3087
3088
3089void BOARD::RenameVariant( const wxString& aOldName, const wxString& aNewName )
3090{
3091 if( aNewName.IsEmpty() || aNewName.CmpNoCase( GetDefaultVariantName() ) == 0 )
3092 return;
3093
3094 auto it = std::find_if( m_variantNames.begin(), m_variantNames.end(),
3095 [&]( const wxString& name )
3096 {
3097 return name.CmpNoCase( aOldName ) == 0;
3098 } );
3099
3100 if( it != m_variantNames.end() )
3101 {
3102 wxString actualOldName = *it;
3103
3104 // Check if new name already exists (case-insensitive) and isn't the same variant
3105 wxString existingName = FindVariantNameCaseInsensitive( m_variantNames, aNewName );
3106
3107 if( !existingName.IsEmpty() && existingName.CmpNoCase( actualOldName ) != 0 )
3108 return;
3109
3110 if( actualOldName == aNewName )
3111 return;
3112
3113 *it = aNewName;
3114
3115 // Transfer description
3116 auto descIt = m_variantDescriptions.find( actualOldName );
3117
3118 if( descIt != m_variantDescriptions.end() )
3119 {
3120 if( !descIt->second.IsEmpty() )
3121 m_variantDescriptions[aNewName] = descIt->second;
3122
3123 m_variantDescriptions.erase( descIt );
3124 }
3125
3126 // Update current variant if it was the renamed one
3127 if( m_currentVariant.CmpNoCase( aOldName ) == 0 )
3128 m_currentVariant = aNewName;
3129
3130 // Rename variant in all footprints
3131 for( FOOTPRINT* fp : m_footprints )
3132 fp->RenameVariant( actualOldName, aNewName );
3133 }
3134}
3135
3136
3137void BOARD::CopyVariant( const wxString& aOldName, const wxString& aNewName, const wxString& aNewDescription )
3138{
3139 if( aOldName.IsEmpty() || aNewName.IsEmpty()
3140 || aNewName.CmpNoCase( GetDefaultVariantName() ) == 0 )
3141 {
3142 return;
3143 }
3144
3145 wxString actualOldName = FindVariantNameCaseInsensitive( m_variantNames, aOldName );
3146
3147 if( actualOldName.IsEmpty() )
3148 return;
3149
3150 if( wxString existingName = FindVariantNameCaseInsensitive( m_variantNames, aNewName ); !existingName.IsEmpty() )
3151 return;
3152
3153 AddVariant( aNewName );
3154
3155 if( !aNewDescription.IsEmpty() )
3156 SetVariantDescription( aNewName, aNewDescription );
3157 else
3158 SetVariantDescription( aNewName, GetVariantDescription( actualOldName ) );
3159
3160 for( FOOTPRINT* fp : m_footprints )
3161 {
3162 if( const FOOTPRINT_VARIANT* variant = fp->GetVariant( actualOldName ) )
3163 {
3164 FOOTPRINT_VARIANT copied = *variant;
3165 copied.SetName( aNewName );
3166 fp->SetVariant( copied );
3167 }
3168 }
3169}
3170
3171
3172wxString BOARD::GetVariantDescription( const wxString& aVariantName ) const
3173{
3174 if( aVariantName.IsEmpty() || aVariantName.CmpNoCase( GetDefaultVariantName() ) == 0 )
3175 return wxEmptyString;
3176
3177 wxString actualName = FindVariantNameCaseInsensitive( m_variantNames, aVariantName );
3178
3179 if( actualName.IsEmpty() )
3180 return wxEmptyString;
3181
3182 auto it = m_variantDescriptions.find( actualName );
3183
3184 if( it != m_variantDescriptions.end() )
3185 return it->second;
3186
3187 return wxEmptyString;
3188}
3189
3190
3191void BOARD::SetVariantDescription( const wxString& aVariantName, const wxString& aDescription )
3192{
3193 if( aVariantName.IsEmpty() || aVariantName.CmpNoCase( GetDefaultVariantName() ) == 0 )
3194 return;
3195
3196 wxString actualName = FindVariantNameCaseInsensitive( m_variantNames, aVariantName );
3197
3198 if( actualName.IsEmpty() )
3199 return;
3200
3201 if( aDescription.IsEmpty() )
3202 m_variantDescriptions.erase( actualName );
3203 else
3204 m_variantDescriptions[actualName] = aDescription;
3205}
3206
3207
3208wxArrayString BOARD::GetVariantNamesForUI() const
3209{
3210 wxArrayString names;
3211 names.Add( GetDefaultVariantName() );
3212
3213 for( const wxString& name : m_variantNames )
3214 names.Add( name );
3215
3216 names.Sort( SortVariantNames ); // SortVariantNames ensures the default is always first
3217
3218 return names;
3219}
3220
3221
3223{
3224 m_lengthDelayCalc->SynchronizeTuningProfileProperties();
3225}
3226
3227
3229{
3230 if( !m_project )
3231 return;
3232
3233 const std::shared_ptr<NET_SETTINGS>& netSettings = GetDesignSettings().m_NetSettings;
3234
3235 if( !netSettings )
3236 return;
3237
3238 const std::map<wxString, wxString>& chainNetclasses = netSettings->GetNetChainNetClasses();
3239
3240 // Nothing to derive and nothing left from a prior pass, so skip the cache wipe a rebuild
3241 // would cost on every resync of a board without chain overrides.
3242 if( chainNetclasses.empty()
3243 && !netSettings->HasChainPatternAssignments( NET_CHAIN_SOURCE::BOARD ) )
3244 {
3245 return;
3246 }
3247
3248 netSettings->ClearChainPatternAssignments( NET_CHAIN_SOURCE::BOARD );
3249
3250 for( NETINFO_ITEM* net : m_NetInfo )
3251 {
3252 const wxString& chainName = net->GetNetChain();
3253
3254 if( chainName.IsEmpty() )
3255 continue;
3256
3257 auto it = chainNetclasses.find( chainName );
3258
3259 if( it == chainNetclasses.end() || !netSettings->HasNetclass( it->second ) )
3260 continue;
3261
3262 netSettings->SetChainPatternAssignment( NET_CHAIN_SOURCE::BOARD, net->GetNetname(),
3263 it->second );
3264 }
3265}
3266
3267
3268void BOARD::SynchronizeNetsAndNetClasses( bool aResetTrackAndViaSizes )
3269{
3270 if( !m_project )
3271 return;
3272
3274 const std::shared_ptr<NETCLASS>& defaultNetClass = bds.m_NetSettings->GetDefaultNetclass();
3275
3277
3279
3280 for( NETINFO_ITEM* net : m_NetInfo )
3281 net->SetNetClass( bds.m_NetSettings->GetEffectiveNetClass( net->GetNetname() ) );
3282
3283 if( aResetTrackAndViaSizes )
3284 {
3285 // Set initial values for custom track width & via size to match the default
3286 // netclass settings
3287 bds.UseCustomTrackViaSize( false );
3288 bds.SetCustomTrackWidth( defaultNetClass->GetTrackWidth() );
3289 bds.SetCustomViaSize( defaultNetClass->GetViaDiameter() );
3290 bds.SetCustomViaDrill( defaultNetClass->GetViaDrill() );
3291
3292 if( defaultNetClass->HasDiffPairWidth() )
3293 bds.SetCustomDiffPairWidth( defaultNetClass->GetDiffPairWidth() );
3294 else
3295 bds.SetCustomDiffPairWidth( defaultNetClass->GetTrackWidth() );
3296
3297 if( defaultNetClass->HasDiffPairGap() )
3298 bds.SetCustomDiffPairGap( defaultNetClass->GetDiffPairGap() );
3299 else
3300 bds.SetCustomDiffPairGap( defaultNetClass->GetClearance() );
3301
3302 if( defaultNetClass->HasDiffPairViaGap() )
3303 bds.SetCustomDiffPairViaGap( defaultNetClass->GetDiffPairViaGap() );
3304 else
3306 }
3307
3309}
3310
3311
3312bool BOARD::SynchronizeComponentClasses( const std::unordered_set<wxString>& aNewSheetPaths ) const
3313{
3315
3316 return m_componentClassManager->SyncDynamicComponentClassAssignments( settings->GetComponentClassAssignments(),
3318 aNewSheetPaths );
3319}
3320
3321
3323{
3324 int error_count = 0;
3325
3326 for( ZONE* zone : Zones() )
3327 {
3328 if( !zone->IsOnCopperLayer() )
3329 {
3330 zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
3331 continue;
3332 }
3333
3334 if( zone->GetNetCode() != 0 ) // i.e. if this zone is connected to a net
3335 {
3336 const NETINFO_ITEM* net = zone->GetNet();
3337
3338 if( net )
3339 {
3340 zone->SetNetCode( net->GetNetCode() );
3341 }
3342 else
3343 {
3344 error_count++;
3345
3346 // keep Net Name and set m_NetCode to -1 : error flag.
3347 zone->SetNetCode( -1 );
3348 }
3349 }
3350 }
3351
3352 return error_count;
3353}
3354
3355
3356PAD* BOARD::GetPad( const VECTOR2I& aPosition, const LSET& aLayerSet ) const
3357{
3358 for( FOOTPRINT* footprint : m_footprints )
3359 {
3360 PAD* pad = nullptr;
3361
3362 if( footprint->HitTest( aPosition ) )
3363 pad = footprint->GetPad( aPosition, aLayerSet.any() ? aLayerSet : LSET::AllCuMask() );
3364
3365 if( pad )
3366 return pad;
3367 }
3368
3369 return nullptr;
3370}
3371
3372
3373PAD* BOARD::GetPad( const PCB_TRACK* aTrace, ENDPOINT_T aEndPoint ) const
3374{
3375 const VECTOR2I& aPosition = aTrace->GetEndPoint( aEndPoint );
3376
3377 LSET lset( { aTrace->GetLayer() } );
3378
3379 return GetPad( aPosition, lset );
3380}
3381
3382
3383PAD* BOARD::GetPad( std::vector<PAD*>& aPadList, const VECTOR2I& aPosition, const LSET& aLayerSet ) const
3384{
3385 // Search aPadList for aPosition
3386 // aPadList is sorted by X then Y values, and a fast binary search is used
3387 int idxmax = aPadList.size() - 1;
3388
3389 int delta = aPadList.size();
3390
3391 int idx = 0; // Starting index is the beginning of list
3392
3393 while( delta )
3394 {
3395 // Calculate half size of remaining interval to test.
3396 // Ensure the computed value is not truncated (too small)
3397 if( ( delta & 1 ) && ( delta > 1 ) )
3398 delta++;
3399
3400 delta /= 2;
3401
3402 PAD* pad = aPadList[idx];
3403
3404 if( pad->GetPosition() == aPosition ) // candidate found
3405 {
3406 // The pad must match the layer mask:
3407 if( ( aLayerSet & pad->GetLayerSet() ).any() )
3408 return pad;
3409
3410 // More than one pad can be at aPosition
3411 // search for a pad at aPosition that matched this mask
3412
3413 // search next
3414 for( int ii = idx + 1; ii <= idxmax; ii++ )
3415 {
3416 pad = aPadList[ii];
3417
3418 if( pad->GetPosition() != aPosition )
3419 break;
3420
3421 if( ( aLayerSet & pad->GetLayerSet() ).any() )
3422 return pad;
3423 }
3424 // search previous
3425 for( int ii = idx - 1; ii >= 0; ii-- )
3426 {
3427 pad = aPadList[ii];
3428
3429 if( pad->GetPosition() != aPosition )
3430 break;
3431
3432 if( ( aLayerSet & pad->GetLayerSet() ).any() )
3433 return pad;
3434 }
3435
3436 // Not found:
3437 return nullptr;
3438 }
3439
3440 if( pad->GetPosition().x == aPosition.x ) // Must search considering Y coordinate
3441 {
3442 if( pad->GetPosition().y < aPosition.y ) // Must search after this item
3443 {
3444 idx += delta;
3445
3446 if( idx > idxmax )
3447 idx = idxmax;
3448 }
3449 else // Must search before this item
3450 {
3451 idx -= delta;
3452
3453 if( idx < 0 )
3454 idx = 0;
3455 }
3456 }
3457 else if( pad->GetPosition().x < aPosition.x ) // Must search after this item
3458 {
3459 idx += delta;
3460
3461 if( idx > idxmax )
3462 idx = idxmax;
3463 }
3464 else // Must search before this item
3465 {
3466 idx -= delta;
3467
3468 if( idx < 0 )
3469 idx = 0;
3470 }
3471 }
3472
3473 return nullptr;
3474}
3475
3476
3482bool sortPadsByXthenYCoord( PAD* const& aLH, PAD* const& aRH )
3483{
3484 if( aLH->GetPosition().x == aRH->GetPosition().x )
3485 return aLH->GetPosition().y < aRH->GetPosition().y;
3486
3487 return aLH->GetPosition().x < aRH->GetPosition().x;
3488}
3489
3490
3491void BOARD::GetSortedPadListByXthenYCoord( std::vector<PAD*>& aVector, int aNetCode ) const
3492{
3493 for( FOOTPRINT* footprint : Footprints() )
3494 {
3495 for( PAD* pad : footprint->Pads() )
3496 {
3497 if( aNetCode < 0 || pad->GetNetCode() == aNetCode )
3498 aVector.push_back( pad );
3499 }
3500 }
3501
3502 std::sort( aVector.begin(), aVector.end(), sortPadsByXthenYCoord );
3503}
3504
3505
3507{
3508 if( GetDesignSettings().m_HasStackup )
3510
3511 BOARD_STACKUP stackup;
3513 return stackup;
3514}
3515
3516
3517std::tuple<int, double, double, double, double> BOARD::GetTrackLength( const PCB_TRACK& aTrack ) const
3518{
3519 std::shared_ptr<CONNECTIVITY_DATA> connectivity = GetBoard()->GetConnectivity();
3520 std::vector<LENGTH_DELAY_CALCULATION_ITEM> items;
3521
3522 for( BOARD_CONNECTED_ITEM* boardItem : connectivity->GetConnectedItems( &aTrack, EXCLUDE_ZONES ) )
3523 {
3525
3526 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
3527 items.push_back( std::move( item ) );
3528 }
3529
3530 constexpr PATH_OPTIMISATIONS opts = {
3531 .OptimiseVias = true, .MergeTracks = true, .OptimiseTracesInPads = true, .InferViaInPad = false
3532 };
3534 items, opts, nullptr, nullptr, LENGTH_DELAY_LAYER_OPT::NO_LAYER_DETAIL,
3536
3537 return std::make_tuple( items.size(), details.TrackLength + details.ViaLength, details.PadToDieLength,
3538 details.TrackDelay + details.ViaDelay, details.PadToDieDelay );
3539}
3540
3541
3542FOOTPRINT* BOARD::GetFootprint( const VECTOR2I& aPosition, PCB_LAYER_ID aActiveLayer, bool aVisibleOnly,
3543 bool aIgnoreLocked ) const
3544{
3545 FOOTPRINT* footprint = nullptr;
3546 FOOTPRINT* alt_footprint = nullptr;
3547 int min_dim = 0x7FFFFFFF;
3548 int alt_min_dim = 0x7FFFFFFF;
3549 bool current_layer_back = IsBackLayer( aActiveLayer );
3550
3551 for( FOOTPRINT* candidate : m_footprints )
3552 {
3553 // is the ref point within the footprint's bounds?
3554 if( !candidate->HitTest( aPosition ) )
3555 continue;
3556
3557 // if caller wants to ignore locked footprints, and this one is locked, skip it.
3558 if( aIgnoreLocked && candidate->IsLocked() )
3559 continue;
3560
3561 PCB_LAYER_ID layer = candidate->GetLayer();
3562
3563 // Filter non visible footprints if requested
3564 if( !aVisibleOnly || IsFootprintLayerVisible( layer ) )
3565 {
3566 BOX2I bb = candidate->GetBoundingBox( false );
3567
3568 int offx = bb.GetX() + bb.GetWidth() / 2;
3569 int offy = bb.GetY() + bb.GetHeight() / 2;
3570
3571 // off x & offy point to the middle of the box.
3572 int dist =
3573 ( aPosition.x - offx ) * ( aPosition.x - offx ) + ( aPosition.y - offy ) * ( aPosition.y - offy );
3574
3575 if( current_layer_back == IsBackLayer( layer ) )
3576 {
3577 if( dist <= min_dim )
3578 {
3579 // better footprint shown on the active side
3580 footprint = candidate;
3581 min_dim = dist;
3582 }
3583 }
3584 else if( aVisibleOnly && IsFootprintLayerVisible( layer ) )
3585 {
3586 if( dist <= alt_min_dim )
3587 {
3588 // better footprint shown on the other side
3589 alt_footprint = candidate;
3590 alt_min_dim = dist;
3591 }
3592 }
3593 }
3594 }
3595
3596 if( footprint )
3597 return footprint;
3598
3599 if( alt_footprint )
3600 return alt_footprint;
3601
3602 return nullptr;
3603}
3604
3605
3606std::list<ZONE*> BOARD::GetZoneList( bool aIncludeZonesInFootprints ) const
3607{
3608 std::list<ZONE*> zones;
3609
3610 for( ZONE* zone : Zones() )
3611 zones.push_back( zone );
3612
3613 if( aIncludeZonesInFootprints )
3614 {
3615 for( FOOTPRINT* footprint : m_footprints )
3616 {
3617 for( ZONE* zone : footprint->Zones() )
3618 zones.push_back( zone );
3619 }
3620 }
3621
3622 return zones;
3623}
3624
3625
3626ZONE* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer, VECTOR2I aStartPointPosition,
3628{
3629 ZONE* new_area = new ZONE( this );
3630
3631 new_area->SetNetCode( aNetcode );
3632 new_area->SetLayer( aLayer );
3633
3634 m_zones.push_back( new_area );
3635
3636 new_area->SetHatchStyle( (ZONE_BORDER_DISPLAY_STYLE) aHatch );
3637
3638 // Add the first corner to the new zone
3639 new_area->AppendCorner( aStartPointPosition, -1 );
3640
3641 if( aNewZonesList )
3642 {
3643 ITEM_PICKER picker( nullptr, new_area, UNDO_REDO::NEWITEM );
3644 aNewZonesList->PushItem( picker );
3645 }
3646
3647 return new_area;
3648}
3649
3650
3651bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, bool aInferOutlineIfNecessary,
3652 OUTLINE_ERROR_HANDLER* aErrorHandler, bool aAllowUseArcsInPolygons,
3653 bool aIncludeNPTHAsOutlines )
3654{
3655 // max dist from one endPt to next startPt: use the current value
3656 int chainingEpsilon = GetOutlinesChainingEpsilon();
3657
3658 bool success = BuildBoardPolygonOutlines( this, aOutlines, GetDesignSettings().m_MaxError, chainingEpsilon,
3659 aInferOutlineIfNecessary, aErrorHandler, aAllowUseArcsInPolygons );
3660
3661 // Now subtract NPTH oval holes from outlines if required
3662 if( aIncludeNPTHAsOutlines )
3663 {
3664 for( FOOTPRINT* fp : Footprints() )
3665 {
3666 for( PAD* pad : fp->Pads() )
3667 {
3668 if( pad->GetAttribute() != PAD_ATTRIB::NPTH )
3669 continue;
3670
3671 SHAPE_POLY_SET hole;
3672 pad->TransformHoleToPolygon( hole, 0, pad->GetMaxError(), ERROR_INSIDE );
3673
3674 if( hole.OutlineCount() > 0 ) // can be not the case for malformed NPTH holes
3675 {
3676 // Issue #20159: BooleanSubtract correctly clips holes extending past board
3677 // edges (common with oval holes near irregular boards). O(n log n) per hole
3678 // vs O(1) for AddHole, but only used for 3D viewer generation, not a hot path.
3679 aOutlines.BooleanSubtract( hole );
3680 }
3681 }
3682 }
3683 }
3684
3685 // Make polygon strictly simple to avoid issues (especially in 3D viewer)
3686 if( aOutlines.ArcCount() > 0 && aOutlines.OutlineCount() > 1 )
3687 {
3688 // Boolean ops keep arcs only within a single outline, so simplify each island alone
3689 SHAPE_POLY_SET simplified;
3690
3691 for( int ii = 0; ii < aOutlines.OutlineCount(); ++ii )
3692 {
3693 SHAPE_POLY_SET island( aOutlines.Polygon( ii ) );
3694 island.Simplify();
3695 simplified.Append( island );
3696 }
3697
3698 aOutlines = std::move( simplified );
3699 }
3700 else
3701 {
3702 aOutlines.Simplify();
3703 }
3704
3705 return success;
3706}
3707
3708
3710{
3712 return static_cast<EMBEDDED_FILES*>( m_embeddedFilesDelegate );
3713
3714 return static_cast<EMBEDDED_FILES*>( this );
3715}
3716
3717
3719{
3721 return static_cast<const EMBEDDED_FILES*>( m_embeddedFilesDelegate );
3722
3723 return static_cast<const EMBEDDED_FILES*>( this );
3724}
3725
3726
3727std::set<KIFONT::OUTLINE_FONT*> BOARD::GetFonts() const
3728{
3730
3731 std::set<KIFONT::OUTLINE_FONT*> fonts;
3732
3733 for( BOARD_ITEM* item : Drawings() )
3734 {
3735 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item ) )
3736 {
3737 KIFONT::FONT* font = text->GetFont();
3738
3739 if( font && font->IsOutline() )
3740 {
3741 KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
3742 PERMISSION permission = outlineFont->GetEmbeddingPermission();
3743
3744 if( permission == PERMISSION::EDITABLE || permission == PERMISSION::INSTALLABLE )
3745 fonts.insert( outlineFont );
3746 }
3747 }
3748 }
3749
3750 return fonts;
3751}
3752
3753
3755{
3756 for( KIFONT::OUTLINE_FONT* font : GetFonts() )
3757 {
3758 EMBEDDED_FILES::EMBEDDED_FILE* file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
3759
3760 if( !file )
3761 {
3762 wxLogTrace( "EMBED", "Failed to add font file: %s", font->GetFileName() );
3763 continue;
3764 }
3765
3767 }
3768}
3769
3770
3771const std::vector<PAD*> BOARD::GetPads() const
3772{
3773 std::vector<PAD*> allPads;
3774
3775 for( FOOTPRINT* footprint : Footprints() )
3776 {
3777 for( PAD* pad : footprint->Pads() )
3778 allPads.push_back( pad );
3779 }
3780
3781 return allPads;
3782}
3783
3784
3785const std::vector<BOARD_CONNECTED_ITEM*> BOARD::AllConnectedItems()
3786{
3787 std::vector<BOARD_CONNECTED_ITEM*> items;
3788
3789 for( PCB_TRACK* track : Tracks() )
3790 items.push_back( track );
3791
3792 for( FOOTPRINT* footprint : Footprints() )
3793 {
3794 for( PAD* pad : footprint->Pads() )
3795 items.push_back( pad );
3796
3797 for( ZONE* zone : footprint->Zones() )
3798 items.push_back( zone );
3799
3800 for( BOARD_ITEM* dwg : footprint->GraphicalItems() )
3801 {
3802 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( dwg ) )
3803 items.push_back( bci );
3804 }
3805 }
3806
3807 for( ZONE* zone : Zones() )
3808 items.push_back( zone );
3809
3810 for( BOARD_ITEM* item : Drawings() )
3811 {
3812 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
3813 items.push_back( bci );
3814 }
3815
3816 return items;
3817}
3818
3819
3820void BOARD::MapNets( BOARD* aDestBoard )
3821{
3823 {
3824 NETINFO_ITEM* netInfo = aDestBoard->FindNet( item->GetNetname() );
3825
3826 if( netInfo )
3827 item->SetNet( netInfo );
3828 else
3829 {
3830 NETINFO_ITEM* newNet = new NETINFO_ITEM( aDestBoard, item->GetNetname() );
3831 aDestBoard->Add( newNet );
3832 item->SetNet( newNet );
3833 }
3834 }
3835}
3836
3837
3839{
3841 {
3842 if( FindNet( item->GetNetCode() ) == nullptr )
3843 item->SetNetCode( NETINFO_LIST::ORPHANED );
3844 }
3845}
3846
3847
3848void BOARD::OnZonesFilled( const std::vector<ZONE*>& aZones )
3849{
3850 if( aZones.empty() )
3851 return;
3852
3853 for( PCB_GENERATOR* generator : m_generators )
3854 generator->OnZoneFillChanged( aZones );
3855}
3856
3857
3859{
3860 if( !alg::contains( m_listeners, aListener ) )
3861 m_listeners.push_back( aListener );
3862}
3863
3864
3866{
3867 auto i = std::find( m_listeners.begin(), m_listeners.end(), aListener );
3868
3869 if( i != m_listeners.end() )
3870 {
3871 std::iter_swap( i, m_listeners.end() - 1 );
3872 m_listeners.pop_back();
3873 }
3874}
3875
3876
3878{
3879 m_listeners.clear();
3880}
3881
3882
3884{
3885 if( affectsDrillModel( aItem ) )
3887
3889}
3890
3891
3892void BOARD::OnItemsChanged( std::vector<BOARD_ITEM*>& aItems )
3893{
3894 bumpDrillModelFor( aItems );
3895
3897}
3898
3899
3904
3905
3906void BOARD::OnItemsCompositeUpdate( std::vector<BOARD_ITEM*>& aAddedItems, std::vector<BOARD_ITEM*>& aRemovedItems,
3907 std::vector<BOARD_ITEM*>& aChangedItems )
3908{
3909 bumpDrillModelFor( aAddedItems );
3910 bumpDrillModelFor( aRemovedItems );
3911 bumpDrillModelFor( aChangedItems );
3912
3913 InvokeListeners( &BOARD_LISTENER::OnBoardCompositeUpdate, *this, aAddedItems, aRemovedItems, aChangedItems );
3914}
3915
3916
3921
3922
3929
3930
3938
3939
3940void BOARD::SetHighLightNet( int aNetCode, bool aMulti )
3941{
3942 bool already = m_highLight.m_netCodes.count( aNetCode );
3943
3944 if( !already )
3945 {
3946 if( !aMulti )
3947 m_highLight.m_netCodes.clear();
3948
3949 m_highLight.m_netCodes.insert( aNetCode );
3951 }
3952}
3953
3954
3955void BOARD::HighLightON( bool aValue )
3956{
3957 if( m_highLight.m_highLightOn != aValue )
3958 {
3959 m_highLight.m_highLightOn = aValue;
3961 }
3962}
3963
3964
3965wxString BOARD::GroupsSanityCheck( bool repair )
3966{
3967 if( repair )
3968 {
3969 while( GroupsSanityCheckInternal( repair ) != wxEmptyString )
3970 {
3971 };
3972
3973 return wxEmptyString;
3974 }
3975 return GroupsSanityCheckInternal( repair );
3976}
3977
3978
3980{
3981 // Cycle detection
3982 //
3983 // Each group has at most one parent group.
3984 // So we start at group 0 and traverse the parent chain, marking groups seen along the way.
3985 // If we ever see a group that we've already marked, that's a cycle.
3986 // If we reach the end of the chain, we know all groups in that chain are not part of any cycle.
3987 //
3988 // Algorithm below is linear in the # of groups because each group is visited only once.
3989 // There may be extra time taken due to the container access calls and iterators.
3990 //
3991 // Groups we know are cycle free
3992 std::unordered_set<EDA_GROUP*> knownCycleFreeGroups;
3993 // Groups in the current chain we're exploring.
3994 std::unordered_set<EDA_GROUP*> currentChainGroups;
3995 // Groups we haven't checked yet.
3996 std::unordered_set<EDA_GROUP*> toCheckGroups;
3997
3998 // Initialize set of groups and generators to check that could participate in a cycle.
3999 for( PCB_GROUP* group : Groups() )
4000 toCheckGroups.insert( group );
4001
4002 for( PCB_GENERATOR* gen : Generators() )
4003 toCheckGroups.insert( gen );
4004
4005 while( !toCheckGroups.empty() )
4006 {
4007 currentChainGroups.clear();
4008 EDA_GROUP* group = *toCheckGroups.begin();
4009
4010 while( true )
4011 {
4012 if( currentChainGroups.find( group ) != currentChainGroups.end() )
4013 {
4014 if( repair )
4015 Remove( static_cast<BOARD_ITEM*>( group->AsEdaItem() ) );
4016
4017 return "Cycle detected in group membership";
4018 }
4019 else if( knownCycleFreeGroups.find( group ) != knownCycleFreeGroups.end() )
4020 {
4021 // Parent is a group we know does not lead to a cycle
4022 break;
4023 }
4024
4025 currentChainGroups.insert( group );
4026 // We haven't visited currIdx yet, so it must be in toCheckGroups
4027 toCheckGroups.erase( group );
4028
4029 group = group->AsEdaItem()->GetParentGroup();
4030
4031 if( !group )
4032 {
4033 // end of chain and no cycles found in this chain
4034 break;
4035 }
4036 }
4037
4038 // No cycles found in chain, so add it to set of groups we know don't participate
4039 // in a cycle.
4040 knownCycleFreeGroups.insert( currentChainGroups.begin(), currentChainGroups.end() );
4041 }
4042
4043 // Success
4044 return "";
4045}
4046
4047
4049{
4050 if( a->Type() != b->Type() )
4051 return a->Type() < b->Type();
4052
4053 if( a->GetLayer() != b->GetLayer() )
4054 return a->GetLayer() < b->GetLayer();
4055
4056 if( a->GetPosition().x != b->GetPosition().x )
4057 return a->GetPosition().x < b->GetPosition().x;
4058
4059 if( a->GetPosition().y != b->GetPosition().y )
4060 return a->GetPosition().y < b->GetPosition().y;
4061
4062 if( a->m_Uuid != b->m_Uuid ) // shopuld be always the case foer valid boards
4063 return a->m_Uuid < b->m_Uuid;
4064
4065 return a < b;
4066}
4067
4068
4069bool BOARD::cmp_drawings::operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const
4070{
4071 if( aFirst->Type() != aSecond->Type() )
4072 return aFirst->Type() < aSecond->Type();
4073
4074 // Layer-free drawings (grid items) assert in GetLayer(); they sort by uuid below.
4075 if( IsSingleLayerType( aFirst->Type() ) && aFirst->GetLayer() != aSecond->GetLayer() )
4076 return aFirst->GetLayer() < aSecond->GetLayer();
4077
4078 // Callers keep these in a std::set, so any branch reporting equality for two distinct items
4079 // loses one of them. Every branch has to fall through to the uuid
4080 int cmp = 0;
4081
4082 if( aFirst->Type() == PCB_SHAPE_T )
4083 {
4084 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aFirst );
4085 const PCB_SHAPE* other = static_cast<const PCB_SHAPE*>( aSecond );
4086
4087 cmp = shape->Compare( other );
4088 }
4089 else if( aFirst->Type() == PCB_TEXT_T || aFirst->Type() == PCB_FIELD_T )
4090 {
4091 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( aFirst );
4092 const PCB_TEXT* other = static_cast<const PCB_TEXT*>( aSecond );
4093
4094 cmp = text->Compare( other );
4095 }
4096 else if( aFirst->Type() == PCB_TEXTBOX_T )
4097 {
4098 const PCB_TEXTBOX* textbox = static_cast<const PCB_TEXTBOX*>( aFirst );
4099 const PCB_TEXTBOX* other = static_cast<const PCB_TEXTBOX*>( aSecond );
4100
4101 cmp = textbox->PCB_SHAPE::Compare( other );
4102
4103 if( cmp == 0 )
4104 cmp = textbox->EDA_TEXT::Compare( other );
4105 }
4106 else if( BaseType( aFirst->Type() ) == PCB_TABLE_T )
4107 {
4108 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( aFirst );
4109 const PCB_TABLE* other = static_cast<const PCB_TABLE*>( aSecond );
4110
4111 cmp = PCB_TABLE::Compare( table, other );
4112 }
4113 else if( aFirst->Type() == PCB_BARCODE_T )
4114 {
4115 const PCB_BARCODE* barcode = static_cast<const PCB_BARCODE*>( aFirst );
4116 const PCB_BARCODE* other = static_cast<const PCB_BARCODE*>( aSecond );
4117
4118 cmp = PCB_BARCODE::Compare( barcode, other );
4119 }
4120
4121 if( cmp != 0 )
4122 return cmp < 0;
4123
4124 if( aFirst->m_Uuid != aSecond->m_Uuid )
4125 return aFirst->m_Uuid < aSecond->m_Uuid;
4126
4127 return aFirst < aSecond;
4128}
4129
4130
4132 KIGFX::RENDER_SETTINGS* aRenderSettings ) const
4133{
4134 int maxError = GetDesignSettings().m_MaxError;
4135
4136 // convert tracks and vias:
4137 for( const PCB_TRACK* track : m_tracks )
4138 {
4139 if( !track->IsOnLayer( aLayer ) )
4140 continue;
4141
4142 track->TransformShapeToPolygon( aOutlines, aLayer, 0, maxError, ERROR_INSIDE );
4143 }
4144
4145 // convert pads and other copper items in footprints
4146 for( const FOOTPRINT* footprint : m_footprints )
4147 {
4148 footprint->TransformPadsToPolySet( aOutlines, aLayer, 0, maxError, ERROR_INSIDE );
4149
4150 footprint->TransformFPShapesToPolySet( aOutlines, aLayer, 0, maxError, ERROR_INSIDE, true, /* include text */
4151 true, /* include shapes */
4152 false /* include private items */ );
4153
4154 for( const ZONE* zone : footprint->Zones() )
4155 {
4156 if( zone->GetLayerSet().test( aLayer ) )
4157 zone->TransformSolidAreasShapesToPolygon( aLayer, aOutlines );
4158 }
4159 }
4160
4161 // convert copper zones
4162 for( const ZONE* zone : Zones() )
4163 {
4164 if( zone->GetLayerSet().test( aLayer ) )
4165 zone->TransformSolidAreasShapesToPolygon( aLayer, aOutlines );
4166 }
4167
4168 // convert graphic items on copper layers (texts)
4169 for( const BOARD_ITEM* item : m_drawings )
4170 {
4171 if( !item->IsOnLayer( aLayer ) )
4172 continue;
4173
4174 switch( item->Type() )
4175 {
4176 case PCB_SHAPE_T:
4177 {
4178 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( item );
4179 shape->TransformShapeToPolygon( aOutlines, aLayer, 0, maxError, ERROR_INSIDE );
4180 break;
4181 }
4182
4183 case PCB_BARCODE_T:
4184 {
4185 const PCB_BARCODE* barcode = static_cast<const PCB_BARCODE*>( item );
4186 barcode->TransformShapeToPolygon( aOutlines, aLayer, 0, maxError, ERROR_INSIDE );
4187 break;
4188 }
4189
4190 case PCB_FIELD_T:
4191 case PCB_TEXT_T:
4192 {
4193 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( item );
4194 text->TransformTextToPolySet( aOutlines, 0, maxError, ERROR_INSIDE );
4195 break;
4196 }
4197
4198 case PCB_TEXTBOX_T:
4199 {
4200 const PCB_TEXTBOX* textbox = static_cast<const PCB_TEXTBOX*>( item );
4201 // border
4202 textbox->PCB_SHAPE::TransformShapeToPolygon( aOutlines, aLayer, 0, maxError, ERROR_INSIDE );
4203 // text
4204 textbox->TransformTextToPolySet( aOutlines, 0, maxError, ERROR_INSIDE );
4205 break;
4206 }
4207
4208 case PCB_TABLE_T:
4209 case PCB_DRILL_CHART_T:
4211 {
4212 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( item );
4213 table->TransformGraphicItemsToPolySet( aOutlines, maxError, ERROR_INSIDE, aRenderSettings );
4214 break;
4215 }
4216
4217 // Configuration only. The symbols it asks for are drawn by the holes themselves
4218 case PCB_DRILL_MAP_T:
4219 break;
4220
4221 case PCB_DIM_ALIGNED_T:
4222 case PCB_DIM_CENTER_T:
4223 case PCB_DIM_RADIAL_T:
4225 case PCB_DIM_LEADER_T:
4226 {
4227 const PCB_DIMENSION_BASE* dim = static_cast<const PCB_DIMENSION_BASE*>( item );
4228 dim->TransformShapeToPolygon( aOutlines, aLayer, 0, maxError, ERROR_INSIDE );
4229 dim->TransformTextToPolySet( aOutlines, 0, maxError, ERROR_INSIDE );
4230 break;
4231 }
4232
4233 default:
4234 break;
4235 }
4236 }
4237}
4238
4239
4240std::vector<BOARD_ITEM*> BOARD::collectOwnedItems() const
4241{
4242 std::vector<BOARD_ITEM*> items;
4243
4244 items.reserve( m_tracks.size() + m_zones.size() + m_generators.size() + m_footprints.size()
4245 + m_drawings.size() + m_markers.size() + m_groups.size() + m_constraints.size()
4246 + m_points.size() );
4247
4248 items.insert( items.end(), m_tracks.begin(), m_tracks.end() );
4249 items.insert( items.end(), m_zones.begin(), m_zones.end() );
4250 items.insert( items.end(), m_generators.begin(), m_generators.end() );
4251 items.insert( items.end(), m_footprints.begin(), m_footprints.end() );
4252 items.insert( items.end(), m_drawings.begin(), m_drawings.end() );
4253 items.insert( items.end(), m_markers.begin(), m_markers.end() );
4254 items.insert( items.end(), m_groups.begin(), m_groups.end() );
4255 items.insert( items.end(), m_constraints.begin(), m_constraints.end() );
4256 items.insert( items.end(), m_points.begin(), m_points.end() );
4257
4258 return items;
4259}
4260
4261
4263{
4264 std::vector<BOARD_ITEM*> items = collectOwnedItems();
4265
4266 return BOARD_ITEM_SET( items.begin(), items.end() );
4267}
4268
4269
4271{
4272 // Delegate to the non-const overload via a single safe const_cast on the
4273 // *this pointer. GetItemSet doesn't mutate the BOARD; the non-const
4274 // signature is historical.
4275 return const_cast<BOARD*>( this )->GetItemSet();
4276}
4277
4278
4279bool BOARD::operator==( const BOARD_ITEM& aItem ) const
4280{
4281 if( aItem.Type() != Type() )
4282 return false;
4283
4284 const BOARD& other = static_cast<const BOARD&>( aItem );
4285
4286 if( *m_designSettings != *other.m_designSettings )
4287 return false;
4288
4289 if( m_NetInfo.GetNetCount() != other.m_NetInfo.GetNetCount() )
4290 return false;
4291
4292 const NETNAMES_MAP& thisNetNames = m_NetInfo.NetsByName();
4293 const NETNAMES_MAP& otherNetNames = other.m_NetInfo.NetsByName();
4294
4295 for( auto it1 = thisNetNames.begin(), it2 = otherNetNames.begin();
4296 it1 != thisNetNames.end() && it2 != otherNetNames.end(); ++it1, ++it2 )
4297 {
4298 // We only compare the names in order here, not the index values
4299 // as the index values are auto-generated and the names are not.
4300 if( it1->first != it2->first )
4301 return false;
4302 }
4303
4304 if( m_properties.size() != other.m_properties.size() )
4305 return false;
4306
4307 for( auto it1 = m_properties.begin(), it2 = other.m_properties.begin();
4308 it1 != m_properties.end() && it2 != other.m_properties.end(); ++it1, ++it2 )
4309 {
4310 if( *it1 != *it2 )
4311 return false;
4312 }
4313
4314 if( m_paper.GetCustomHeightMils() != other.m_paper.GetCustomHeightMils() )
4315 return false;
4316
4317 if( m_paper.GetCustomWidthMils() != other.m_paper.GetCustomWidthMils() )
4318 return false;
4319
4320 if( m_paper.GetSizeMils() != other.m_paper.GetSizeMils() )
4321 return false;
4322
4323 if( m_paper.GetPaperId() != other.m_paper.GetPaperId() )
4324 return false;
4325
4326 if( m_paper.GetWxOrientation() != other.m_paper.GetWxOrientation() )
4327 return false;
4328
4329 for( int ii = 0; !m_titles.GetComment( ii ).empty(); ++ii )
4330 {
4331 if( m_titles.GetComment( ii ) != other.m_titles.GetComment( ii ) )
4332 return false;
4333 }
4334
4335 wxArrayString ourVars;
4336 m_titles.GetContextualTextVars( &ourVars );
4337
4338 wxArrayString otherVars;
4339 other.m_titles.GetContextualTextVars( &otherVars );
4340
4341 if( ourVars != otherVars )
4342 return false;
4343
4344 return true;
4345}
4346
4348{
4350 m_boardOutline->GetOutline().RemoveAllContours();
4351
4352 bool has_outline = GetBoardPolygonOutlines( m_boardOutline->GetOutline(), false );
4353
4354 if( has_outline )
4355 m_boardOutline->GetOutline().Fracture();
4356}
4357
4358
4360{
4361 // return the number of PTH with Press-Fit fabr attribute
4362 int count = 0;
4363
4364 for( FOOTPRINT* footprint : Footprints() )
4365 {
4366 for( PAD* pad : footprint->Pads() )
4367 {
4368 if( pad->GetProperty() == PAD_PROP::PRESSFIT )
4369 count++;
4370 }
4371 }
4372
4373 return count;
4374}
4375
4376
4378{
4379 // @return the number of PTH with Castellated fabr attribute
4380 int count = 0;
4381
4382 for( FOOTPRINT* footprint : Footprints() )
4383 {
4384 for( PAD* pad : footprint->Pads() )
4385 {
4386 if( pad->GetProperty() == PAD_PROP::CASTELLATED )
4387 count++;
4388 }
4389 }
4390
4391 return count;
4392}
4393
4394
4395void BOARD::SaveToHistory( const wxString& aProjectPath, std::vector<HISTORY_FILE_DATA>& aFileData )
4396{
4397 // The board can transiently have no project (e.g. during a non-KiCad import while the old
4398 // project is being unloaded and the new one has not yet been linked). The autosave timer can
4399 // fire in that window, so guard against a null project here rather than dereferencing it.
4401
4402 if( !project )
4403 return;
4404
4405 wxString projPath = project->GetProjectPath();
4406
4407 if( projPath.IsEmpty() )
4408 return;
4409
4410 // Verify we're saving for the correct project
4411 if( !projPath.IsSameAs( aProjectPath ) )
4412 {
4413 wxLogTrace( traceAutoSave, wxS( "[history] pcb saver skipping - project path mismatch: %s vs %s" ), projPath,
4414 aProjectPath );
4415 return;
4416 }
4417
4418 if( GetFileName().IsEmpty() )
4419 return; // unsaved board
4420
4421 // A loaded board's name uses forward slashes, which never prefix a Windows project path
4422 wxString boardPath = wxFileName( GetFileName() ).GetFullPath();
4423
4424 // Derive relative path from project root.
4425 if( !boardPath.Left( projPath.length() ).IsSameAs( projPath, wxFileName::IsCaseSensitive() ) )
4426 {
4427 wxLogTrace( traceAutoSave, wxS( "[history] pcb saver skipping - board not under project: %s" ), boardPath );
4428 return; // not under project
4429 }
4430
4431 wxString rel = boardPath.Mid( projPath.length() );
4432
4433 try
4434 {
4436 STRING_FORMATTER formatter;
4437
4438 pi.FormatBoardToFormatter( &formatter, this, nullptr );
4439
4440 HISTORY_FILE_DATA entry;
4441 entry.relativePath = rel;
4442 entry.content = std::move( formatter.MutableString() );
4443 entry.prettify = true;
4444
4445 if( ADVANCED_CFG::GetCfg().m_CompactSave )
4446 entry.formatMode = KICAD_FORMAT::FORMAT_MODE::COMPACT_TEXT_PROPERTIES;
4447
4448 aFileData.push_back( std::move( entry ) );
4449
4450 wxLogTrace( traceAutoSave, wxS( "[history] pcb saver serialized %zu bytes for '%s'" ),
4451 aFileData.back().content.size(), rel );
4452 }
4453 catch( const IO_ERROR& ioe )
4454 {
4455 wxLogTrace( traceAutoSave, wxS( "[history] pcb saver serialize failed: %s" ),
4456 wxString::FromUTF8( ioe.What() ) );
4457 }
4458}
int index
const char * name
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
static PCB_TABLECELL * findTableCell(const BOARD_ITEM *aDrawing, const KIID &aID)
Definition board.cpp:2161
static bool affectsDrillModel(const BOARD_ITEM *aItem)
Definition board.cpp:189
bool sortPadsByXthenYCoord(PAD *const &aLH, PAD *const &aRH)
Used by BOARD::GetSortedPadListByXthenYCoord to sort a pad list by X coordinate value.
Definition board.cpp:3482
static wxString FindVariantNameCaseInsensitive(const std::vector< wxString > &aNames, const wxString &aVariantName)
Definition board.cpp:3003
#define DEFAULT_CHAINING_EPSILON_MM
Definition board.h:95
BOARD_USE
Flags to specify how the board is being used.
Definition board.h:401
@ NORMAL
Definition board.h:402
LAYER_T
The allowed types of layers, same as Specctra DSN spec.
Definition board.h:243
@ LT_POWER
Definition board.h:246
@ LT_FRONT
Definition board.h:250
@ LT_MIXED
Definition board.h:247
@ LT_BACK
Definition board.h:251
@ LT_UNDEFINED
Definition board.h:244
@ LT_JUMPER
Definition board.h:248
@ LT_AUX
Definition board.h:249
@ LT_SIGNAL
Definition board.h:245
std::set< BOARD_ITEM *, CompareByUuid > BOARD_ITEM_SET
Set of BOARD_ITEMs ordered by UUID.
Definition board.h:395
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
BASE_SET & reset(size_t pos)
Definition base_set.h:153
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,...
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Container for design settings for a BOARD object.
void UseCustomTrackViaSize(bool aEnabled)
Enables/disables custom track/via size settings.
void SetCustomDiffPairWidth(int aWidth)
Sets custom track width for differential pairs (i.e.
void SetEnabledLayers(const LSET &aMask)
Change the bit-mask of enabled layers to aMask.
std::shared_ptr< NET_SETTINGS > m_NetSettings
void SetCustomTrackWidth(int aWidth)
Sets custom width for track (i.e.
DRILL_SYMBOL_PROFILE & GetDrillSymbolProfile()
void SetCustomViaSize(int aSize)
Set custom size for via diameter (i.e.
const LSET & GetEnabledLayers() const
Return a bit-mask of all the layers that are enabled.
void SetCustomDiffPairGap(int aGap)
Sets custom gap for differential pairs (i.e.
bool IsLayerEnabled(PCB_LAYER_ID aLayerId) const
Test whether a given layer aLayerId is enabled.
void SetUserDefinedLayerCount(int aNewLayerCount)
Set the number of user defined layers to aNewLayerCount.
BOARD_STACKUP & GetStackupDescriptor()
void SetCustomViaDrill(int aDrill)
Sets custom size for via drill (i.e.
void SetCopperLayerCount(int aNewLayerCount)
Set the copper layer count to aNewLayerCount.
void SetCustomDiffPairViaGap(int aGap)
Sets custom via gap for differential pairs (i.e.
BOARD_ITEM_CONTAINER(BOARD_ITEM *aParent, KICAD_T aType)
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
virtual void SetLayerSet(const LSET &aLayers)
Definition board_item.h:377
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:459
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:432
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:369
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition board_item.h:247
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
virtual void OnBoardNetSettingsChanged(BOARD &aBoard)
Definition board.h:379
virtual void OnBoardRatsnestChanged(BOARD &aBoard)
Definition board.h:384
virtual void OnBoardItemsAdded(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems)
Definition board.h:376
virtual void OnBoardItemChanged(BOARD &aBoard, BOARD_ITEM *aBoardItem)
Definition board.h:380
virtual void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aBoardItem)
Definition board.h:377
virtual void OnBoardItemAdded(BOARD &aBoard, BOARD_ITEM *aBoardItem)
Definition board.h:375
virtual void OnBoardHighlightNetChanged(BOARD &aBoard)
Definition board.h:383
virtual void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems)
Definition board.h:378
virtual void OnBoardCompositeUpdate(BOARD &aBoard, std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aChangedItems)
Definition board.h:385
virtual void OnBoardItemsChanged(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems)
Definition board.h:381
virtual void OnBoardSelectionChanged(BOARD &aBoard)
Definition board.h:382
Manage layers needed to make a physical board.
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition board.cpp:2680
ZONE * m_SolderMaskBridges
Definition board.h:1835
void ApplyNetChainNetclasses()
Expand the project's chain-to-netclass assignments into per-net pattern assignments,...
Definition board.cpp:3228
void GetContextualTextVars(wxArrayString *aVars) const
Definition board.cpp:678
bool IsFootprintLayerVisible(PCB_LAYER_ID aLayer) const
Expect either of the two layers on which a footprint can reside, and returns whether that layer is vi...
Definition board.cpp:1307
BOARD_STACKUP GetStackupOrDefault() const
Definition board.cpp:3506
std::map< ZONE *, std::map< PCB_LAYER_ID, ISOLATED_ISLANDS > > m_ZoneIsolatedIslandsMap
Definition board.h:1836
PCB_LAYER_ID GetCopperLayerStackMaxId() const
Definition board.cpp:1182
std::vector< const PCB_DRILL_MAP * > DrillMapsOnLayer(PCB_LAYER_ID aLayer) const
Every map on this layer.
Definition board.cpp:207
GENERATORS m_generators
Definition board.h:1891
void OnItemChanged(BOARD_ITEM *aItem)
Notify the board and its listeners that an item on the board has been modified in some way.
Definition board.cpp:3883
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
Definition board.h:565
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
Definition board.h:441
PAD * GetPad(const VECTOR2I &aPosition, const LSET &aLayerMask) const
Find a pad aPosition on aLayer.
Definition board.cpp:3356
SHARDED_CACHE< PTR_PTR_LAYER_CACHE_KEY, bool > m_IntersectsAreaCache
Definition board.h:1798
void CacheChildrenById(const BOARD_ITEM &aParent)
Definition board.h:1755
int GetUserDefinedLayerCount() const
Definition board.cpp:1171
void recalcOpposites()
Definition board.cpp:1088
void SetPosition(const VECTOR2I &aPos) override
Definition board.cpp:838
std::map< wxString, wxString > m_properties
Definition board.h:1920
SHARDED_CACHE< ITEM_SELECTOR_LAYER_CACHE_KEY, bool > m_IntersectsCourtyardResultCache
Definition board.h:1801
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition board.cpp:3709
SHARDED_CACHE< PTR_PTR_LAYER_CACHE_KEY, bool > m_EnclosedByAreaCache
Definition board.h:1800
int m_fileFormatVersionAtLoad
Definition board.h:1905
NETINFO_ITEM * DpCoupledNet(const NETINFO_ITEM *aNet)
Definition board.cpp:2911
void SetCurrentVariant(const wxString &aVariant)
Definition board.cpp:3016
std::vector< ZONE * > m_DRCCopperZones
Definition board.h:1831
void SetVisibleLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition board.cpp:1235
void CacheItemById(BOARD_ITEM &aItem) const
Add an item to the item-by-id cache.
Definition board.h:1751
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
std::shared_ptr< const DRILL_SYMBOL_CACHE > m_drillSymbolCache
Definition board.h:1916
SHARDED_CACHE< ITEM_SELECTOR_LAYER_CACHE_KEY, bool > m_EnclosedByAreaResultCache
Definition board.h:1806
void MapNets(BOARD *aDestBoard)
Map all nets in the given board to nets with the same name (if any) in the destination board.
Definition board.cpp:3820
TITLE_BLOCK m_titles
Definition board.h:1927
GAL_SET m_LegacyVisibleItems
Definition board.h:562
NETINFO_ITEM * FindOrAddNet(const wxString &aNetName, int aNetCode=-1, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)
Return the net with the given name, adding it to the board if there is none.
Definition board.cpp:2852
std::vector< wxString > m_variantNames
Definition board.h:1934
LENGTH_DELAY_CALCULATION * GetLengthCalculation() const
Returns the track length calculator.
Definition board.h:1703
wxArrayString GetVariantNamesForUI() const
Return the variant names for UI display.
Definition board.cpp:3208
void RunOnNestedEmbeddedFiles(const std::function< void(EMBEDDED_FILES *)> &aFunction) override
Provide access to nested embedded files, such as symbols in schematics and footprints in boards.
Definition board.cpp:1465
const GENERATORS & Generators() const
Definition board.h:485
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition board.h:1131
const std::vector< BOARD_CONNECTED_ITEM * > AllConnectedItems()
Definition board.cpp:3785
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition board.cpp:1269
int m_outlinesChainingEpsilon
the max distance between 2 end point to see them connected when building the board outlines
Definition board.h:1873
uint64_t m_drillModelGeneration
Definition board.h:1906
std::tuple< int, double, double, double, double > GetTrackLength(const PCB_TRACK &aTrack) const
Return data on the length and number of track segments connected to a given track.
Definition board.cpp:3517
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition board.cpp:2982
BOARD_USE m_boardUse
What is this board being used for.
Definition board.h:1876
void RefreshDrillSymbolLayers()
Definition board.cpp:239
void CopyVariant(const wxString &aOldName, const wxString &aNewName, const wxString &aNewDescription=wxEmptyString)
Definition board.cpp:3137
PAGE_INFO m_paper
Definition board.h:1926
void RemoveAllListeners()
Remove all listeners.
Definition board.cpp:3877
SHARDED_CACHE< PTR_PTR_CACHE_KEY, bool > m_IntersectsBCourtyardCache
Definition board.h:1797
FOOTPRINTS m_footprints
Definition board.h:1886
void ConvertBrdLayerToPolygonalContours(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aOutlines, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const
Build a set of polygons which are the outlines of copper items (pads, tracks, vias,...
Definition board.cpp:4131
void AddListener(BOARD_LISTENER *aListener)
Add a listener to the board to receive calls whenever something on the board has been modified.
Definition board.cpp:3858
void UpdateUserUnits(BOARD_ITEM *aItem, KIGFX::VIEW *aView)
Update any references within aItem (or its descendants) to the user units.
Definition board.cpp:2078
void SetProperties(const std::map< wxString, wxString > &aProps)
Definition board.h:527
std::vector< PCB_MARKER * > ReloadDRCExclusions(std::vector< PCB_MARKER * > &aStale)
Resolve exclusions again after the project file was reread.
Definition board.cpp:653
bool IsBackLayer(PCB_LAYER_ID aLayer) const
Definition board.cpp:1013
std::shared_ptr< BOARD_DESIGN_SETTINGS > m_designSettings
All of the board design settings are stored as a JSON object inside the project file.
Definition board.h:1947
GAL_SET GetVisibleElements() const
Return a set of all the element categories that are visible.
Definition board.cpp:1263
void SetHighLightNet(int aNetCode, bool aMulti=false)
Select the netcode to be highlighted.
Definition board.cpp:3940
void CompileRatsnest()
Rebuild the entire board ratsnest.
Definition board.cpp:3923
HIGH_LIGHT_INFO m_highLight
Definition board.h:1902
std::map< wxString, wxString > m_variantDescriptions
Definition board.h:1935
bool SetLayerDescr(PCB_LAYER_ID aIndex, const LAYER &aLayer)
Return the type of the copper layer given by aLayer.
Definition board.cpp:932
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2833
EDA_UNITS m_userUnits
Definition board.h:1930
CONSTRAINTS m_constraints
Definition board.h:1889
void UpdateBoardOutline()
Definition board.cpp:4347
const ZONES & Zones() const
Definition board.h:469
void BulkRemoveStaleTeardrops(BOARD_COMMIT &aCommit)
Remove all teardrop zones with the STRUCT_DELETED flag set.
Definition board.cpp:1704
void ClearItemByIdCache()
Definition board.h:1763
void DeleteVariant(const wxString &aVariantName)
Definition board.cpp:3061
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition board.h:1857
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings)
Definition board.cpp:1330
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1216
void SanitizeNetcodes()
Definition board.cpp:3838
void InitializeClearanceCache()
Initialize the clearance cache for all board items.
Definition board.cpp:1346
EMBEDDED_FILES * m_embeddedFilesDelegate
Definition board.h:1963
ZONE * AddArea(PICKED_ITEMS_LIST *aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer, VECTOR2I aStartPointPosition, ZONE_BORDER_DISPLAY_STYLE aHatch)
Add an empty copper area to board areas list.
Definition board.cpp:3626
bool IsFrontLayer(PCB_LAYER_ID aLayer) const
Definition board.cpp:1007
const GROUPS & Groups() const
The groups must maintain the following invariants.
Definition board.h:518
~BOARD()
Definition board.cpp:332
void SaveToHistory(const wxString &aProjectPath, std::vector< HISTORY_FILE_DATA > &aFileData)
Serialize board into HISTORY_FILE_DATA for non-blocking history commit.
Definition board.cpp:4395
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition board.cpp:369
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition board.cpp:1229
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
Definition board.cpp:1019
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition board.cpp:569
void RebindItemUuid(BOARD_ITEM &aItem, const KIID &aNewId)
Rebind the UUID of an attached item and keep the item-by-id cache coherent.
Definition board.h:737
DRAWINGS m_drawings
Definition board.h:1885
uint64_t m_boardOutlineGeneration
Definition board.h:1907
void OnItemsCompositeUpdate(std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aChangedItems)
Notify the board and its listeners that items on the board have been modified in a composite operatio...
Definition board.cpp:3906
int SetAreasNetCodesFromNetNames()
Set the .m_NetCode member of all copper areas, according to the area Net Name The SetNetCodesFromNetN...
Definition board.cpp:3322
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition board.cpp:3268
void ResetNetHighLight()
Reset all high light data to the init state.
Definition board.cpp:3931
SHARDED_CACHE< PTR_PTR_CACHE_KEY, bool > m_IntersectsCourtyardCache
Definition board.h:1795
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition board.cpp:978
std::list< ZONE * > GetZoneList(bool aIncludeZonesInFootprints=false) const
Definition board.cpp:3606
bool ResolveTextVar(wxString *token, int aDepth) const
Definition board.cpp:708
const MARKERS & Markers() const
Definition board.h:497
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayer) const
Definition board.cpp:1148
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition board.cpp:3771
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition board.cpp:844
TITLE_BLOCK & GetTitleBlock()
Definition board.h:1035
void FixupEmbeddedData()
After loading a file from disk, the footprints do not yet contain the full data for their embedded fi...
Definition board.cpp:1472
int GetMaxClearanceValue() const
Returns the maximum clearance value for any object on the board.
Definition board.cpp:1353
ZONES m_zones
Definition board.h:1890
void InvalidateClearanceCache(const KIID &aUuid)
Invalidate the clearance cache for a specific item.
Definition board.cpp:1339
PAD * FindPadByUuid(const KIID &aUuid) const
Definition board.cpp:2950
void OnBoardSelectionChanged()
Notify the board and its listeners that the editor selection has changed.
Definition board.cpp:3900
PCB_LAYER_ID GetLayerID(const wxString &aLayerName) const
Return the ID of a layer.
Definition board.cpp:940
HIGH_LIGHT_INFO m_highLightPrevious
Definition board.h:1903
NETINFO_LIST m_NetInfo
Definition board.h:1955
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition board.h:561
void SetVisibleAlls()
Change the bit-mask of visible element categories and layers.
Definition board.cpp:1252
std::shared_ptr< const DRILL_SYMBOL_CACHE > DrillSymbolCache() const
Resolved drill symbols, by group and by owning item.
Definition board.cpp:265
bool HasVariant(const wxString &aVariantName) const
Definition board.cpp:3042
void AddVariant(const wxString &aVariantName)
Definition board.cpp:3048
int GetCopperLayerCount() const
Definition board.cpp:1155
std::vector< BOARD_LISTENER * > m_listeners
Definition board.h:1957
bool RemoveAllItemsOnLayer(PCB_LAYER_ID aLayer)
Removes all owned items other than footprints existing on the given board layer, and modifies the sta...
Definition board.cpp:1992
SHARDED_CACHE< PTR_PTR_LAYER_CACHE_KEY, bool > m_IntersectsKeepoutCache
Definition board.h:1799
void IncrementTimeStamp()
Definition board.cpp:448
int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet)
Fetch the coupled netname for a given net.
Definition board.cpp:2863
wxString GetUniqueZoneName(const wxString &aBaseName, const ZONE *aExclude=nullptr) const
Return a name based on aBaseName that is not used by any other zone or rule area on the board.
Definition board.cpp:1493
PCB_POINTS m_points
Definition board.h:1893
std::unique_ptr< LENGTH_DELAY_CALCULATION > m_lengthDelayCalc
Definition board.h:1966
const FOOTPRINTS & Footprints() const
Definition board.h:465
std::shared_ptr< CONNECTIVITY_DATA > m_connectivity
Definition board.h:1921
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get the list of all outline fonts used in the board.
Definition board.cpp:3727
void RemoveAll(std::initializer_list< KICAD_T > aTypes={ PCB_NETINFO_T, PCB_MARKER_T, PCB_GROUP_T, PCB_ZONE_T, PCB_GENERATOR_T, PCB_FOOTPRINT_T, PCB_TRACE_T, PCB_SHAPE_T })
An efficient way to remove all items of a certain type from the board.
Definition board.cpp:1838
const BOARD_ITEM_SET GetItemSet()
Collect every owned item (tracks, zones, generators, footprints, drawings, markers,...
Definition board.cpp:4262
const TRACKS & Tracks() const
Definition board.h:463
int m_DRCMaxPhysicalClearance
Definition board.h:1834
FOOTPRINT * FindFootprintByPath(const KIID_PATH &aPath) const
Search for a FOOTPRINT within this board with the given path.
Definition board.cpp:2938
void FinalizeBulkRemove(std::vector< BOARD_ITEM * > &aRemovedItems)
Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event for listeners.
Definition board.cpp:1695
BOARD_ITEM_INDEX m_itemIndex
Definition board.h:1898
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition board.h:1808
bool m_embedFonts
Definition board.h:1959
wxString GroupsSanityCheckInternal(bool repair)
Definition board.cpp:3979
std::shared_ptr< const FOOTPRINT_COURTYARD_INDEX > m_footprintCourtyardIndex
Definition board.h:1827
void OnRatsnestChanged()
Notify the board and its listeners that the ratsnest has been recomputed.
Definition board.cpp:3917
wxString ConvertCrossReferencesToKIIDs(const wxString &aSource) const
Convert cross-references back and forth between ${refDes:field} and ${kiid:field}.
Definition board.cpp:2402
wxString GetClass() const override
Return the class name.
Definition board.h:1433
std::unique_ptr< COMPONENT_CLASS_MANAGER > m_componentClassManager
Definition board.h:1965
SHARDED_CACHE< PTR_PTR_CACHE_KEY, bool > m_IntersectsFCourtyardCache
Definition board.h:1796
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, bool aInferOutlineIfNecessary, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition board.cpp:3651
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
Definition board.h:569
void SetCopperLayerCount(int aCount)
Definition board.cpp:1161
std::unordered_map< const ZONE *, BOX2I > m_ZoneBBoxCache
Definition board.h:1811
std::unordered_map< const ZONE *, SHAPE_POLY_SET > m_DeflatedZoneOutlineCache
Definition board.h:1824
std::vector< BOARD_ITEM * > collectOwnedItems() const
Get a simple vector of the board's pointers.
Definition board.cpp:4240
SHARDED_CACHE< ITEM_SELECTOR_LAYER_CACHE_KEY, bool > m_IntersectsFCourtyardResultCache
Definition board.h:1802
TRACKS TracksInNet(int aNetCode)
Collect all the TRACKs and VIAs that are members of a net given by aNetCode.
Definition board.cpp:910
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:379
PROJECT * m_project
Definition board.h:1929
FOOTPRINT * GetFootprint(const VECTOR2I &aPosition, PCB_LAYER_ID aActiveLayer, bool aVisibleOnly, bool aIgnoreLocked=false) const
Get a footprint by its bounding rectangle at aPosition on aLayer.
Definition board.cpp:3542
bool HasItemsOnLayer(PCB_LAYER_ID aLayer)
Definition board.cpp:1946
const wxString & GetFileName() const
Definition board.h:454
bool operator==(const BOARD_ITEM &aOther) const override
Definition board.cpp:4279
std::vector< PCB_MARKER * > ResolveDRCExclusions(bool aCreateMarkers)
Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
Definition board.cpp:595
int GetPadWithCastellatedAttrCount()
Definition board.cpp:4377
SHARDED_CACHE< ITEM_SELECTOR_LAYER_CACHE_KEY, bool > m_IntersectsKeepoutResultCache
Definition board.h:1805
wxString GetVariantDescription(const wxString &aVariantName) const
Definition board.cpp:3172
FOOTPRINT * FindFootprintByReference(const wxString &aReference) const
Search for a FOOTPRINT within this board with the given reference designator.
Definition board.cpp:2926
unsigned GetNodesCount(int aNet=-1) const
Definition board.cpp:2555
SHARDED_CACHE< ITEM_FIELD_CACHE_KEY, wxString > m_ItemFieldCache
Definition board.h:1807
std::map< PCB_LAYER_ID, std::vector< ZONE * > > m_DRCCopperZonesByLayer
Definition board.h:1832
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Change the visibility of an element category.
Definition board.cpp:1275
std::shared_ptr< DRC_RTREE > m_CopperItemRTreeCache
Definition board.h:1810
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Change the type of the layer given by aLayer.
Definition board.cpp:1038
std::optional< std::set< const PCB_VIA * > > m_StackedMicroviaCache
Definition board.h:1816
wxString m_fileName
Definition board.h:1879
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:960
BOX2I ExpandBoundingBoxForDrillSymbols(const BOX2I &aBoundingBox) const
Include every displaced copy of a hole-owned drill symbol in its view bounds.
Definition board.cpp:300
void DetachAllFootprints()
Remove all footprints without deleting.
Definition board.cpp:2149
std::map< int, LAYER > m_layers
Definition board.h:1900
void noteDrillModelChange(BOARD_ITEM *aItem)
Container-boundary notification, so an item that arrives or leaves without going through a commit sti...
Definition board.cpp:221
wxString GetCurrentVariant() const
Definition board.h:530
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
Definition board.cpp:865
int GetOutlinesChainingEpsilon()
Definition board.h:1081
void BumpDrillModelGeneration()
Bumped whenever anything a drill chart or map reports on has moved.
Definition board.cpp:181
void GetSortedPadListByXthenYCoord(std::vector< PAD * > &aVector, int aNetCode=-1) const
First empties then fills the vector with all pads and sorts them by increasing x coordinate,...
Definition board.cpp:3491
void OnZonesFilled(const std::vector< ZONE * > &aZones)
Notify the board that the listed zones were just refilled.
Definition board.cpp:3848
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition board.cpp:1208
SHARDED_CACHE< ITEM_SELECTOR_LAYER_CACHE_KEY, bool > m_IntersectsAreaResultCache
Definition board.h:1804
int m_DRCMaxClearance
Definition board.h:1833
void ClearProject()
Definition board.cpp:420
void ReplaceNetChainTerminalPad(const wxString &aNetChain, const KIID &aPrev, const KIID &aNew)
Definition board.cpp:2962
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition board.h:1809
void FinalizeBulkAdd(std::vector< BOARD_ITEM * > &aNewItems)
Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for listeners.
Definition board.cpp:1686
wxString m_currentVariant
Definition board.h:1933
int LayerDepth(PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer) const
Definition board.cpp:1195
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
Definition board.cpp:2137
PROJECT * GetProject() const
Definition board.h:774
bool IsEmpty() const
Definition board.cpp:826
int GetPadWithPressFitAttrCount()
Definition board.cpp:4359
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 board.cpp:2642
wxString GetDesignRulesPath() const
Return the absolute path to the design rules file for this board.
Definition board.cpp:437
wxString GroupsSanityCheck(bool repair=false)
Consistency check of internal m_groups structure.
Definition board.cpp:3965
void RenameVariant(const wxString &aOldName, const wxString &aNewName)
Definition board.cpp:3089
std::vector< ZONE * > m_DRCZones
Definition board.h:1830
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
BOARD()
Definition board.cpp:99
void bumpDrillModelFor(const std::vector< BOARD_ITEM * > &aItems)
Definition board.cpp:319
std::vector< std::pair< VECTOR2I, int > > m_drillSymbolPlacements
Offset and symbol reach of every drill map, so a pad or track ViewBBox() does not walk the drawings l...
Definition board.h:1914
void UpdateRatsnestExclusions()
Update the visibility flags on the current unconnected ratsnest lines.
Definition board.cpp:538
wxString ConvertKIIDsToCrossReferences(const wxString &aSource) const
Definition board.cpp:2482
int RepairDuplicateItemUuids()
Rebind duplicate attached-item UUIDs so each live board item has a unique ID.
Definition board.cpp:2326
void SynchronizeProperties()
Copy the current project's text variables into the boards property cache.
Definition board.cpp:2996
void RemoveListener(BOARD_LISTENER *aListener)
Remove the specified listener.
Definition board.cpp:3865
std::unique_ptr< BOARD_TEXT_VAR_ADAPTER > m_textVarAdapter
Definition board.h:1970
std::shared_mutex m_CachesMutex
Definition board.h:1792
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aPhysicalLayersOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition board.cpp:2572
std::shared_ptr< const FOOTPRINT_COURTYARD_INDEX > GetFootprintCourtyardIndex()
Return a spatial index of footprint courtyards, building it on first use.
Definition board.cpp:514
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
std::atomic< int > m_timeStamp
Definition board.h:1877
std::mutex m_drillSymbolCacheMutex
Definition board.h:1917
bool SynchronizeComponentClasses(const std::unordered_set< wxString > &aNewSheetPaths) const
Copy component class / component class generator information from the project settings.
Definition board.cpp:3312
void UncacheChildrenById(const BOARD_ITEM &aParent)
Definition board.h:1761
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition board.cpp:2100
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition board.cpp:1723
std::unordered_map< wxString, std::vector< ZONE * > > m_ZonesByNameCache
Definition board.h:1820
GROUPS m_groups
Definition board.h:1888
MARKERS m_markers
Definition board.h:1884
LSET m_drillSymbolLayers
Definition board.h:1908
std::optional< int > m_maxClearanceValue
Definition board.h:1812
void HighLightON(bool aValue=true)
Enable or disable net highlighting.
Definition board.cpp:3955
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1222
void SynchronizeTuningProfileProperties()
Ensure that all time domain properties providers are in sync with current settings.
Definition board.cpp:3222
TRACKS m_tracks
Definition board.h:1887
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2176
bool m_LegacyCopperEdgeClearanceLoaded
Definition board.h:566
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
void OnItemsChanged(std::vector< BOARD_ITEM * > &aItems)
Notify the board and its listeners that an item on the board has been modified in some way.
Definition board.cpp:3892
SHARDED_CACHE< ITEM_SELECTOR_LAYER_CACHE_KEY, bool > m_IntersectsBCourtyardResultCache
Definition board.h:1803
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:758
VECTOR2I GetPosition() const override
Definition board.cpp:832
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
Definition board.cpp:3191
void CacheTriangulation(PROGRESS_REPORTER *aReporter=nullptr, const std::vector< ZONE * > &aZones={})
Definition board.cpp:1385
void SetVisibleElements(const GAL_SET &aMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1242
void EmbedFonts() override
Finds all fonts used in the board and embeds them in the file if permissions allow.
Definition board.cpp:3754
PCB_BOARD_OUTLINE * m_boardOutline
Definition board.h:1892
void SetUserDefinedLayerCount(int aCount)
Definition board.cpp:1177
const DRAWINGS & Drawings() const
Definition board.h:467
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition board.cpp:2072
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 coord_type GetY() const
Definition box2.h:211
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr coord_type GetX() const
Definition box2.h:210
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition box2.h:141
bool Dirty() const
BOARD_CONNECTED_ITEM * Parent() const
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
std::shared_ptr< const CN_ANCHOR > GetSourceNode() const
void SetVisible(bool aVisible)
std::shared_ptr< const CN_ANCHOR > GetTargetNode() const
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been removed.
Definition commit.h:92
A class to manage Component Classes in a board context.
COMPONENT_CLASS_SETTINGS stores data for component classes, including rules for automatic generation ...
bool GetEnableSheetComponentClasses() const
Gets whether component classes should be generated for components in hierarchical sheets.
const std::vector< COMPONENT_CLASS_ASSIGNMENT_DATA > & GetComponentClassAssignments() const
Gets all dynamic component class assignments.
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Update the ratsnest for the board.
void RunOnUnconnectedEdges(std::function< bool(CN_EDGE &)> aFunc)
unsigned int GetUnconnectedCount(bool aVisibleOnly) const
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:666
Container for an DRC exclusion, which is a PCB_MARKER plus an optional comment.
static DRC_EXCLUSION FromMarker(const PCB_MARKER &aMarker)
void Build(const BOARD &aBoard, const std::vector< DRILL_SPAN > &aSpans)
const DRILL_CHART_TOTALS & Totals() const
uint64_t Fingerprint() const
Cheap value used to notice an edit.
The base class for create windows for drawing purpose.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
virtual void ClearEditFlags()
Definition eda_item.h:178
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
static INSPECT_RESULT IterateForward(std::deque< T > &aList, INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes)
This changes first parameter to avoid the DList and use the main queue instead.
Definition eda_item.h:401
virtual INSPECT_RESULT Visit(INSPECTOR aInspector, void *aTestData, const std::vector< KICAD_T > &aScanTypes)
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition eda_item.cpp:297
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:168
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
int Compare(const EDA_SHAPE *aOther) const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
EMBEDDED_FILE * GetEmbeddedFile(const wxString &aName) const
Returns the embedded file with the given name or nullptr if it does not exist.
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, std::shared_ptr< EMBEDDED_FILE > > & EmbeddedFileMap() const
Provide an iterable view of the file collection.
EMBEDDED_FILES()=default
Variant information for a footprint.
Definition footprint.h:178
bool ResolveTextVar(wxString *aToken, int aDepth=0) const
Resolve any references to system tokens supported by the component.
const wxString & GetReference() const
Definition footprint.h:793
Helper for storing and iterating over GAL_LAYER_IDs.
Definition layer_ids.h:434
static GAL_SET DefaultVisible()
Definition lset.cpp:782
static const std::vector< KICAD_T > BoardLevelItems
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition collectors.h:70
static const std::vector< KICAD_T > Tracks
A scan list for only TRACKs and ARCs.
Definition collectors.h:134
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
virtual bool IsOutline() const
Definition font.h:102
Implement outline font drawing.
EMBEDDING_PERMISSION GetEmbeddingPermission() const
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool IsBOARD_ITEM() const
Definition view_item.h:98
virtual wxString GetClass() const =0
Return the class name.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:2630
Definition kiid.h:46
size_t size() const
Lightweight class which holds a pad, via, or a routed trace outline.
TYPE Type() const
Gets the routing item type.
Class which calculates lengths (and associated routing statistics) in a BOARD context.
LENGTH_DELAY_STATS CalculateLengthDetails(std::vector< LENGTH_DELAY_CALCULATION_ITEM > &aItems, PATH_OPTIMISATIONS aOptimisations, const PAD *aStartPad=nullptr, const PAD *aEndPad=nullptr, LENGTH_DELAY_LAYER_OPT aLayerOpt=LENGTH_DELAY_LAYER_OPT::NO_LAYER_DETAIL, LENGTH_DELAY_DOMAIN_OPT aDomain=LENGTH_DELAY_DOMAIN_OPT::NO_DELAY_DETAIL, LENGTH_DELAY_ITEM_DETAILS *aPerItemLengthDelays=nullptr) const
Calculates the electrical length of the given items.
LENGTH_DELAY_CALCULATION_ITEM GetLengthCalculationItem(const BOARD_CONNECTED_ITEM *aBoardItem) const
Return a LENGTH_CALCULATION_ITEM constructed from the given BOARD_CONNECTED_ITEM.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
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 const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:693
std::shared_ptr< RC_ITEM > GetRCItem() const
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
Definition marker_base.h:89
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:46
void SetDescription(const wxString &aDesc)
Definition netclass.h:139
Handle the data for a net.
Definition netinfo.h:50
wxString GetClass() const override
Return the class name.
Definition netinfo.h:61
const wxString & GetNetname() const
Definition netinfo.h:110
int GetNetCode() const
Definition netinfo.h:104
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition netinfo.h:66
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:281
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:285
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition netinfo.h:289
unsigned GetNetCount() const
Definition netinfo.h:255
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:258
void ClearAllCaches()
Clears the effective netclass cache for all nets.
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const wxString &aNetName)
Fetches the effective (may be aggregate) netclass for the given net name.
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
void SetDefaultNetclass(std::shared_ptr< NETCLASS > netclass)
Sets the default netclass for the project Calling user is responsible for resetting the effective net...
Definition pad.h:61
VECTOR2I GetPosition() const override
Definition pad.cpp:255
const VECTOR2D & GetSizeMils() const
Definition page_info.h:145
wxPrintOrientation GetWxOrientation() const
Definition page_info.h:128
static double GetCustomHeightMils()
Definition page_info.h:197
wxPaperSize GetPaperId() const
Definition page_info.h:133
static double GetCustomWidthMils()
Definition page_info.h:192
A 3D body attached to a footprint (or, later, placed on a board).
Definition pcb_3d_body.h:93
static int Compare(const PCB_BARCODE *aBarcode, const PCB_BARCODE *aOther)
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the barcode (text + symbol shapes) to polygonal geometry suitable for filling/collision tests...
A geometric constraint between board items (issue #2329).
Abstract dimension API.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
DIM_UNITS_MODE GetUnitsMode() const
Turns on drill symbols at the holes, for one layer.
int GetSymbolExtent() const
const VECTOR2I & GetOffset() const
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
A PCB_IO derivation for saving and loading Pcbnew s-expression formatted files.
void FormatBoardToFormatter(OUTPUTFORMATTER *aOut, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr)
Serialize a BOARD to an OUTPUTFORMATTER without file I/O or Prettify.
Collect all BOARD_ITEM objects on a given layer.
Definition collectors.h:546
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Test a BOARD_ITEM using this class's Inspector method, which does the collection.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition collectors.h:552
static PCB_MARKER * FromProto(const kiapi::board::DrcMarker &aMsg)
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:39
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
Definition pcb_text.cpp:784
const VECTOR2I & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition pcb_track.h:115
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
A progress reporter interface for use in multi-threaded environments.
virtual bool IsCancelled() const =0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
The backing store for a PROJECT, in JSON format.
std::shared_ptr< COMPONENT_CLASS_SETTINGS > & ComponentClassSettings()
Container for project specific data.
Definition project.h:63
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition project.cpp:289
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
std::vector< KIID > GetIDs() const
Definition rc_item.h:188
Represent a set of closed polygons.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
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)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int ArcCount() const
Count the number of arc shapes present.
int OutlineCount() const
Return the number of outlines in the set.
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.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:430
std::string & MutableString()
Definition richio.h:458
const wxString & GetComment(int aIdx) const
static void GetContextualTextVars(wxArrayString *aVars)
Handle a list of polygons defining a copper zone.
Definition zone.h:70
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
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
void SetHatchStyle(ZONE_BORDER_DISPLAY_STYLE aStyle)
Definition zone.h:690
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
const wxString & GetZoneName() const
Definition zone.h:160
bool IsTeardropArea() const
Definition zone.h:809
@ INTERNAL
Definition common.h:96
#define EXCLUDE_ZONES
bool BuildBoardPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, bool aInferOutlineIfNecessary, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const VECTOR2I &pt)> OUTLINE_ERROR_HANDLER
static bool empty(const wxTextEntryBase *aCtrl)
std::vector< DRILL_SPAN > EnumerateDrillSpans(const BOARD &aBoard, bool aPadBackdrills)
Every drill span present on the board, through-holes first.
std::map< KIID, std::vector< DRILL_SYMBOL_ENTRY > > ResolveDrillSymbolsByItem(const BOARD &aBoard, const std::map< std::string, DRILL_SYMBOL_ASSIGNMENT > &aResolved)
The same answer keyed by the item that owns the holes.
std::map< std::string, DRILL_SYMBOL_ASSIGNMENT > ResolveDrillSymbols(const BOARD &aBoard)
The symbol every hole should carry, without touching the board.
#define _(s)
RECURSE_MODE
Definition eda_item.h:50
@ RECURSE
Definition eda_item.h:51
INSPECT_RESULT
Definition eda_item.h:44
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:91
std::function< INSPECT_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Used to inspect and possibly collect the (search) results of iterating over a list or tree of KICAD_T...
Definition eda_item.h:88
#define STRUCT_DELETED
flag indication structures to be erased
EDA_UNITS
Definition eda_units.h:45
static const std::string DesignRulesFileExtension
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
KIID niluuid(0)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition layer_ids.h:224
@ GAL_LAYER_ID_START
Definition layer_ids.h:225
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ GAL_LAYER_ID_BITMASK_END
This is the end of the layers used for visibility bit masks in legacy board files.
Definition layer_ids.h:283
@ LAYER_RATSNEST
Definition layer_ids.h:249
@ 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
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ Rescue
Definition layer_ids.h:117
@ User_1
Definition layer_ids.h:120
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
@ F_Cu
Definition layer_ids.h:60
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
Definition layer_ids.h:392
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
STL namespace.
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:225
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ PRESSFIT
a PTH with a hole diameter with tight tolerances for press fit pin
Definition padstack.h:127
@ CASTELLATED
a pad with a castellated through hole
Definition padstack.h:125
PAGE_SIZE_TYPE
Definition page_info.h:46
BARCODE class definition.
Class to handle a set of BOARD_ITEMs.
std::deque< PCB_TRACK * > TRACKS
ENDPOINT_T
see class PGM_BASE
CITER next(CITER it)
Definition ptree.cpp:120
Class that computes missing connections on a PCB.
@ RPT_SEVERITY_EXCLUSION
wxString GetDefaultVariantName()
int SortVariantNames(const wxString &aLhs, const wxString &aRhs)
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
Definition board.cpp:4069
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
Definition board.cpp:4048
DRILL_CHART_TOTALS m_Totals
Counts for the ${DRILL_*} text variables.
Definition board.h:358
One drawable mark, with the geometry the renderer needs to place it.
std::vector< char > decompressedData
Data produced by a registered saver on the UI thread, consumed by either the background local-history...
std::string content
Serialized content (mutually exclusive with sourcePath)
KICAD_FORMAT::FORMAT_MODE formatMode
wxString relativePath
Destination path relative to the project root.
Container to hold information pertinent to a layer of a BOARD.
Definition board.h:259
static LAYER_T ParseType(const char *aType)
Convert a string to a LAYER_T.
Definition board.cpp:1067
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
Definition board.cpp:1051
Holds length measurement result details and statistics.
Struct to control which optimisations the length calculation code runs on the given path objects.
m_board BuildConnectivity()
const std::string table
bool copied
static const long long MM
wxString result
Test unit parsing edge cases and error handling.
int delta
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
static thread_pool * tp
BS::priority_thread_pool thread_pool
Definition thread_pool.h:27
wxLogTrace helper definitions.
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition typeinfo.h:261
constexpr bool IsSingleLayerType(const KICAD_T aType)
Definition typeinfo.h:527
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_T
Definition typeinfo.h:74
@ PCB_CONSTRAINT_T
a geometric constraint between board items
Definition typeinfo.h:237
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
Definition typeinfo.h:240
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:91
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:99
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:102
@ PCB_STACKUP_TABLE_T
class PCB_STACKUP_TABLE, a live stackup table derived from PCB_TABLE
Definition typeinfo.h:242
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
Definition typeinfo.h:239
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.