KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_netlist_updater.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2015 CERN
6 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
7 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
8 *
9 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25
26#include <common.h> // for PAGE_INFO
27
28#include <base_units.h>
29#include <board.h>
34#include <netinfo.h>
35#include <footprint.h>
37#include <pad.h>
38#include <pcb_group.h>
39#include <pcb_track.h>
40#include <zone.h>
41#include <string_utils.h>
42#include <algorithm>
43#include <limits>
44#include <pcb_edit_frame.h>
45#include <pcbnew_settings.h>
48#include <reporter.h>
50#include <tool/tool_manager.h>
51#include <wx/log.h>
52
54
55
57 m_frame( aFrame ),
59 m_commit( aFrame->GetToolManager() ),
60 m_board( aBoard ),
61 m_reporter( &NULL_REPORTER::GetInstance() )
62{
63}
64
65
67 m_frame( nullptr ),
69 m_commit( aToolManager ),
70 m_board( aBoard ),
71 m_reporter( &NULL_REPORTER::GetInstance() )
72{
73}
74
75
79
80
82 REPORTER* aReporter, bool aDryRun )
83{
84 for( NETINFO_ITEM* net : aBoard->GetNetInfo() )
85 {
86 const wxString previous = net->GetNetChain();
87 wxString next = aNetlist.GetNetChainFor( net->GetNetname() );
88
89 if( !previous.IsEmpty() && next.IsEmpty() && aReporter && !aDryRun )
90 {
91 aReporter->Report(
92 wxString::Format(
93 _( "Net chain assignment '%s' on net '%s' cleared by netlist "
94 "update." ),
95 previous, net->GetNetname() ),
97 }
98
99 if( !aDryRun )
100 {
101 net->SetNetChain( next );
102
103 if( previous != next )
104 {
105 for( int i = 0; i < 2; ++i )
106 net->ClearTerminalPad( i );
107 }
108 }
109 }
110}
111
112
114{
115 const std::shared_ptr<NET_SETTINGS>& netSettings = aBoard->GetDesignSettings().m_NetSettings;
116
117 if( !netSettings )
118 return;
119
120 netSettings->ClearNetChainClasses();
121 netSettings->ClearNetChainNetClasses();
122
123 for( const auto& [chain, className] : aNetlist.GetSignalChainClasses() )
124 netSettings->SetNetChainClass( chain, className );
125
126 for( const auto& [chain, netclass] : aNetlist.GetNetChainNetClasses() )
127 netSettings->SetNetChainNetClass( chain, netclass );
128
129 // Chain membership on the board has just been refreshed from the netlist, so assignments
130 // derived from the previous membership are stale. The caller's
131 // SynchronizeNetsAndNetClasses() rebuilds them from the maps set above.
132 netSettings->ClearChainPatternAssignments( NET_CHAIN_SOURCE::BOARD );
133}
134
135
136// These functions allow inspection of pad nets during dry runs by keeping a cache of
137// current pad netnames indexed by pad.
138
139void BOARD_NETLIST_UPDATER::cacheNetname( PAD* aPad, const wxString& aNetname )
140{
141 m_padNets[ aPad ] = aNetname;
142}
143
144
146{
147 if( m_isDryRun && m_padNets.count( aPad ) )
148 return m_padNets[ aPad ];
149 else
150 return aPad->GetNetname();
151}
152
153
154void BOARD_NETLIST_UPDATER::cachePinFunction( PAD* aPad, const wxString& aPinFunction )
155{
156 m_padPinFunctions[ aPad ] = aPinFunction;
157}
158
159
161{
162 if( m_isDryRun && m_padPinFunctions.count( aPad ) )
163 return m_padPinFunctions[ aPad ];
164 else
165 return aPad->GetPinFunction();
166}
167
168
170{
171 VECTOR2I bestPosition;
172
173 if( !m_board->IsEmpty() )
174 {
175 // Position new components below any existing board features.
176 BOX2I bbox = m_board->GetBoardEdgesBoundingBox();
177
178 if( bbox.GetWidth() || bbox.GetHeight() )
179 {
180 bestPosition.x = bbox.Centre().x;
181 bestPosition.y = bbox.GetBottom() + pcbIUScale.mmToIU( 10 );
182 }
183 }
184 else
185 {
186 // Position new components in the center of the page when the board is empty.
187 VECTOR2I pageSize = m_board->GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS );
188
189 bestPosition.x = pageSize.x / 2;
190 bestPosition.y = pageSize.y / 2;
191 }
192
193 return bestPosition;
194}
195
196
198{
199 return addNewFootprint( aComponent, aComponent->GetFPID() );
200}
201
202
204{
205 wxString msg;
206
207 if( aFootprintId.empty() )
208 {
209 msg.Printf( _( "Cannot add %s (no footprint assigned)." ),
210 aComponent->GetReference() );
211 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
212 ++m_errorCount;
213 return nullptr;
214 }
215
216 FOOTPRINT* footprint = LoadFootprintFromProject( m_board, aFootprintId );
217
218 if( footprint == nullptr )
219 {
220 msg.Printf( _( "Cannot add %s (footprint '%s' not found)." ),
221 aComponent->GetReference(),
222 EscapeHTML( aFootprintId.Format().wx_str() ) );
223 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
224 ++m_errorCount;
225 return nullptr;
226 }
227
228 footprint->SetStaticComponentClass(
229 m_board->GetComponentClassManager().GetNoneComponentClass() );
230
231 if( m_isDryRun )
232 {
233 msg.Printf( _( "Add %s (footprint '%s')." ),
234 aComponent->GetReference(),
235 EscapeHTML( aFootprintId.Format().wx_str() ) );
236
237 delete footprint;
238 footprint = nullptr;
239 }
240 else
241 {
242 for( PAD* pad : footprint->Pads() )
243 {
244 bool showRatsnest = true;
245
246 if( m_settings )
247 showRatsnest = m_settings->m_Display.m_ShowGlobalRatsnest;
248
249 pad->SetLocalRatsnestVisible( showRatsnest );
250
251 // Pads in the library all have orphaned nets. Replace with Default.
252 pad->SetNetCode( 0 );
253 }
254
255 footprint->SetParent( m_board );
257
258 // This flag is used to prevent connectivity from considering the footprint during its
259 // initial build after the footprint is committed, because we're going to immediately start
260 // a move operation on the footprint and don't want its pads to drive nets onto vias/tracks
261 // it happens to land on at the initial position.
262 if( m_willDrag )
263 footprint->SetAttributes( footprint->GetAttributes() | FP_JUST_ADDED );
264
265 m_addedFootprints.push_back( footprint );
266 m_commit.Add( footprint );
267
268 msg.Printf( _( "Added %s (footprint '%s')." ),
269 aComponent->GetReference(),
270 EscapeHTML( aFootprintId.Format().wx_str() ) );
271 }
272
273 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
275 return footprint;
276}
277
278
280{
281 wxString curClassName, newClassName;
282 COMPONENT_CLASS* newClass = nullptr;
283
284 if( const COMPONENT_CLASS* curClass = aFootprint->GetStaticComponentClass() )
285 curClassName = curClass->GetName();
286
287 // Calculate the new component class
288 if( m_isDryRun )
289 {
291 aNewComponent->GetComponentClassNames() );
292 }
293 else
294 {
295 newClass = m_board->GetComponentClassManager().GetEffectiveStaticComponentClass(
296 aNewComponent->GetComponentClassNames() );
297 newClassName = newClass->GetName();
298 }
299
300 if( curClassName == newClassName )
301 return false;
302
303 // Create a copy for undo if the footprint has not been added during this update
304 FOOTPRINT* copy = nullptr;
305
306 if( !m_isDryRun && !m_commit.GetStatus( aFootprint ) )
307 {
308 copy = static_cast<FOOTPRINT*>( aFootprint->Clone() );
309 copy->SetParentGroup( nullptr );
310 }
311
312 wxString msg;
313
314 if( m_isDryRun )
315 {
316 if( curClassName == wxEmptyString && newClassName != wxEmptyString )
317 {
318 msg.Printf( _( "Change %s component class to '%s'." ),
319 aFootprint->GetReference(),
320 EscapeHTML( newClassName ) );
321 }
322 else if( curClassName != wxEmptyString && newClassName == wxEmptyString )
323 {
324 msg.Printf( _( "Remove %s component class (currently '%s')." ),
325 aFootprint->GetReference(),
326 EscapeHTML( curClassName ) );
327 }
328 else
329 {
330 msg.Printf( _( "Change %s component class from '%s' to '%s'." ),
331 aFootprint->GetReference(),
332 EscapeHTML( curClassName ),
333 EscapeHTML( newClassName ) );
334 }
335 }
336 else
337 {
338 wxASSERT_MSG( newClass != nullptr, "Component class should not be nullptr" );
339
340 aFootprint->SetStaticComponentClass( newClass );
341
342 if( curClassName == wxEmptyString && newClassName != wxEmptyString )
343 {
344 msg.Printf( _( "Changed %s component class to '%s'." ),
345 aFootprint->GetReference(),
346 EscapeHTML( newClassName ) );
347 }
348 else if( curClassName != wxEmptyString && newClassName == wxEmptyString )
349 {
350 msg.Printf( _( "Removed %s component class (was '%s')." ),
351 aFootprint->GetReference(),
352 EscapeHTML( curClassName ) );
353 }
354 else
355 {
356 msg.Printf( _( "Changed %s component class from '%s' to '%s'." ),
357 aFootprint->GetReference(),
358 EscapeHTML( curClassName ),
359 EscapeHTML( newClassName ) );
360 }
361 }
362
363 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
364
365 if( copy )
366 m_commit.Modified( aFootprint, copy );
367
368 return true;
369}
370
371
373 COMPONENT* aNewComponent )
374{
375 wxString msg;
376
377 if( aNewComponent->GetFPID().empty() )
378 {
379 msg.Printf( _( "Cannot update %s (no footprint assigned)." ),
380 aNewComponent->GetReference() );
381 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
382 ++m_errorCount;
383 return nullptr;
384 }
385
386 FOOTPRINT* newFootprint = LoadFootprintFromProject( m_board, aNewComponent->GetFPID() );
387
388 if( newFootprint == nullptr )
389 {
390 msg.Printf( _( "Cannot update %s (footprint '%s' not found)." ),
391 aNewComponent->GetReference(),
392 EscapeHTML( aNewComponent->GetFPID().Format().wx_str() ) );
393 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
394 ++m_errorCount;
395 return nullptr;
396 }
397
398 if( m_isDryRun )
399 {
400 if( aFootprint->IsLocked() && !m_overrideLocks )
401 {
402 msg.Printf( _( "Cannot change %s footprint from '%s' to '%s' (footprint is locked)."),
403 aFootprint->GetReference(),
404 EscapeHTML( aFootprint->GetFPID().Format().wx_str() ),
405 EscapeHTML( aNewComponent->GetFPID().Format().wx_str() ) );
406 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
408 delete newFootprint;
409 return nullptr;
410 }
411 else
412 {
413 msg.Printf( _( "Change %s footprint from '%s' to '%s'."),
414 aFootprint->GetReference(),
415 EscapeHTML( aFootprint->GetFPID().Format().wx_str() ),
416 EscapeHTML( aNewComponent->GetFPID().Format().wx_str() ) );
417 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
419 delete newFootprint;
420 return nullptr;
421 }
422 }
423 else
424 {
425 if( aFootprint->IsLocked() && !m_overrideLocks )
426 {
427 msg.Printf( _( "Could not change %s footprint from '%s' to '%s' (footprint is locked)."),
428 aFootprint->GetReference(),
429 EscapeHTML( aFootprint->GetFPID().Format().wx_str() ),
430 EscapeHTML( aNewComponent->GetFPID().Format().wx_str() ) );
431 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
433 delete newFootprint;
434 return nullptr;
435 }
436 else
437 {
438 // Expand the footprint pad layers
439 newFootprint->FixUpPadsForBoard( m_board );
440
441 m_board->ExchangeFootprint( aFootprint, newFootprint, m_commit,
442 m_frame->GetPcbNewSettings()->m_FlipDirection, true );
443
444 msg.Printf( _( "Changed %s footprint from '%s' to '%s'."),
445 aFootprint->GetReference(),
446 EscapeHTML( aFootprint->GetFPID().Format().wx_str() ),
447 EscapeHTML( aNewComponent->GetFPID().Format().wx_str() ) );
448 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
450 return newFootprint;
451 }
452 }
453 }
454
455
457{
458 wxString msg;
459
460 const COMPONENT_VARIANT* firstAssociatedVariant = nullptr;
461
462 if( !fpidsEquivalent( aFootprint->GetFPID(), aNetlistComponent->GetFPID() ) )
463 {
464 for( const auto& [_, test] : aNetlistComponent->GetVariants() )
465 {
467 && aFootprint->GetFPIDAsString()
469 {
470 firstAssociatedVariant = &test;
471 break;
472 }
473 }
474 }
475
476 // Create a copy only if the footprint has not been added during this update
477 FOOTPRINT* copy = nullptr;
478
479 if( !m_commit.GetStatus( aFootprint ) )
480 {
481 copy = static_cast<FOOTPRINT*>( aFootprint->Clone() );
482 copy->SetParentGroup( nullptr );
483 }
484
485 bool changed = false;
486
487 // Test for reference designator field change.
488 if( aFootprint->GetReference() != aNetlistComponent->GetReference() )
489 {
490 if( m_isDryRun )
491 {
492 msg.Printf( _( "Change %s reference designator to %s." ),
493 aFootprint->GetReference(),
494 aNetlistComponent->GetReference() );
495 }
496 else
497 {
498 msg.Printf( _( "Changed %s reference designator to %s." ),
499 aFootprint->GetReference(),
500 aNetlistComponent->GetReference() );
501
502 changed = true;
503 aFootprint->SetReference( aNetlistComponent->GetReference() );
504 }
505
506 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
507 }
508
509 // Test for value field change.
510 wxString netlistValue = aNetlistComponent->GetValue();
511
512 if( firstAssociatedVariant != nullptr
513 && firstAssociatedVariant->m_fields.count( GetDefaultFieldName( FIELD_T::VALUE, UNTRANSLATED ) ) )
514 {
515 netlistValue = firstAssociatedVariant->m_fields.at( GetDefaultFieldName( FIELD_T::VALUE, UNTRANSLATED ) );
516 }
517
518 if( aFootprint->GetValue() != netlistValue )
519 {
520 if( m_isDryRun )
521 {
522 msg.Printf( _( "Change %s value from %s to %s." ),
523 aFootprint->GetReference(),
524 EscapeHTML( aFootprint->GetValue() ),
526 }
527 else
528 {
529 msg.Printf( _( "Changed %s value from %s to %s." ),
530 aFootprint->GetReference(),
531 EscapeHTML( aFootprint->GetValue() ),
533
534 changed = true;
535 aFootprint->SetValue( netlistValue );
536 }
537
538 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
539 }
540
541 // Test for time stamp change.
542 KIID_PATH new_path = aNetlistComponent->GetPath();
543
544 if( !aNetlistComponent->GetKIIDs().empty() )
545 new_path.push_back( aNetlistComponent->GetKIIDs().front() );
546
547 if( aFootprint->GetPath() != new_path )
548 {
549 if( m_isDryRun )
550 {
551 msg.Printf( _( "Update %s symbol association from %s to %s." ),
552 aFootprint->GetReference(),
553 EscapeHTML( aFootprint->GetPath().AsString() ),
554 EscapeHTML( new_path.AsString() ) );
555 }
556 else
557 {
558 msg.Printf( _( "Updated %s symbol association from %s to %s." ),
559 aFootprint->GetReference(),
560 EscapeHTML( aFootprint->GetPath().AsString() ),
561 EscapeHTML( new_path.AsString() ) );
562
563 changed = true;
564 aFootprint->SetPath( new_path );
565 }
566
567 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
568 }
569
570 nlohmann::ordered_map<wxString, wxString> fpFieldsAsMap;
571
572 for( PCB_FIELD* field : aFootprint->GetFields() )
573 {
574 // These fields are individually checked above
575 if( field->IsReference() || field->IsValue() || field->IsComponentClass() )
576 {
577 continue;
578 }
579
580 fpFieldsAsMap[field->GetName()] = field->GetText();
581 }
582
583 nlohmann::ordered_map<wxString, wxString> compFields = aNetlistComponent->GetFields();
584
585 if( firstAssociatedVariant != nullptr )
586 {
587 for( const auto& [name, value] : firstAssociatedVariant->m_fields )
588 compFields[name] = value;
589 }
590
591 // Remove the ref/value/footprint fields that are individually handled
593 compFields.erase( GetDefaultFieldName( FIELD_T::VALUE, UNTRANSLATED ) );
595
596 // Remove any component class fields - these are not editable in the pcb editor
597 compFields.erase( wxT( "Component Class" ) );
598
599 // Fields are stored as an ordered map, but we don't (yet) support reordering the footprint fields to
600 // match the symbol, so we manually check the fields in the order they are stored in the symbol.
601 bool same = true;
602 bool remove_only = true;
603
604 for( const auto& [name, value] : compFields )
605 {
606 if( fpFieldsAsMap.count( name ) == 0 || fpFieldsAsMap[name] != value )
607 {
608 same = false;
609 remove_only = false;
610 break;
611 }
612 }
613
614 for( const auto& [name, value] : fpFieldsAsMap )
615 {
616 if( compFields.count( name ) == 0 )
617 {
618 same = false;
619 break;
620 }
621 }
622
623 if( !same )
624 {
625 if( m_isDryRun )
626 {
627 if( m_updateFields && ( !remove_only || m_removeExtraFields ) )
628 {
629 msg.Printf( _( "Update %s fields." ), aFootprint->GetReference() );
630 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
631 }
632
633 // Remove fields that aren't present in the symbol
634 for( PCB_FIELD* field : aFootprint->GetFields() )
635 {
636 if( field->IsMandatory() )
637 continue;
638
639 if( compFields.count( field->GetName() ) == 0 )
640 {
642 {
643 msg.Printf( _( "Remove %s footprint fields not in symbol." ), aFootprint->GetReference() );
644 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
645 }
646
647 break;
648 }
649 }
650 }
651 else
652 {
653 if( m_updateFields && ( !remove_only || m_removeExtraFields ) )
654 {
655 msg.Printf( _( "Updated %s fields." ), aFootprint->GetReference() );
656 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
657
658 changed = true;
659
660 // Add or change field value
661 for( auto& [name, value] : compFields )
662 {
663 if( aFootprint->HasField( name ) )
664 {
665 aFootprint->GetField( name )->SetText( value );
666 }
667 else
668 {
669 PCB_FIELD* newField = new PCB_FIELD( aFootprint, FIELD_T::USER );
670 aFootprint->Add( newField );
671
672 newField->SetName( name );
673 newField->SetText( value );
674 newField->SetVisible( false );
675 newField->SetLayer( aFootprint->GetLayer() == F_Cu ? F_Fab : B_Fab );
676
677 // Give the relative position (0,0) in footprint
678 newField->SetPosition( aFootprint->GetPosition() );
679 // Give the footprint orientation
680 newField->Rotate( aFootprint->GetPosition(), aFootprint->GetOrientation() );
681
682 newField->StyleFromSettings( m_board->GetDesignSettings(), true );
683 }
684 }
685 }
686
688 {
689 bool warned = false;
690
691 std::vector<PCB_FIELD*> fieldList;
692 aFootprint->GetFields( fieldList, false );
693
694 for( PCB_FIELD* field : fieldList )
695 {
696 if( field->IsMandatory() )
697 continue;
698
699 if( compFields.count( field->GetName() ) == 0 )
700 {
701 if( !warned )
702 {
703 warned = true;
704 msg.Printf( _( "Removed %s footprint fields not in symbol." ), aFootprint->GetReference() );
705 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
706 }
707
708 aFootprint->Remove( field );
709
710 if( m_frame )
711 m_frame->GetCanvas()->GetView()->Remove( field );
712
713 delete field;
714 }
715 }
716 }
717 }
718 }
719
720 wxString sheetname;
721 wxString sheetfile;
722 wxString fpFilters;
723
724 wxString humanSheetPath = aNetlistComponent->GetHumanReadablePath();
725
726 if( !humanSheetPath.empty() )
727 sheetname = humanSheetPath;
728 else if( aNetlistComponent->GetProperties().count( wxT( "Sheetname" ) ) > 0 )
729 sheetname = aNetlistComponent->GetProperties().at( wxT( "Sheetname" ) );
730
731 if( aNetlistComponent->GetProperties().count( wxT( "Sheetfile" ) ) > 0 )
732 sheetfile = aNetlistComponent->GetProperties().at( wxT( "Sheetfile" ) );
733
734 if( aNetlistComponent->GetProperties().count( wxT( "ki_fp_filters" ) ) > 0 )
735 fpFilters = aNetlistComponent->GetProperties().at( wxT( "ki_fp_filters" ) );
736
737 if( sheetname != aFootprint->GetSheetname() )
738 {
739 if( m_isDryRun )
740 {
741 msg.Printf( _( "Update %s sheetname to '%s'." ),
742 aFootprint->GetReference(),
743 EscapeHTML( sheetname ) );
744 }
745 else
746 {
747 msg.Printf( _( "Updated %s sheetname to '%s'." ),
748 aFootprint->GetReference(),
749 EscapeHTML( sheetname ) );
750
751 changed = true;
752 aFootprint->SetSheetname( sheetname );
753 }
754
755 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
756 }
757
758 if( sheetfile != aFootprint->GetSheetfile() )
759 {
760 if( m_isDryRun )
761 {
762 msg.Printf( _( "Update %s sheetfile to '%s'." ),
763 aFootprint->GetReference(),
764 EscapeHTML( sheetfile ) );
765 }
766 else
767 {
768 msg.Printf( _( "Updated %s sheetfile to '%s'." ),
769 aFootprint->GetReference(),
770 EscapeHTML( sheetfile ) );
771
772 changed = true;
773 aFootprint->SetSheetfile( sheetfile );
774 }
775
776 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
777 }
778
779 if( fpFilters != aFootprint->GetFilters() )
780 {
781 if( m_isDryRun )
782 {
783 msg.Printf( _( "Update %s footprint filters to '%s'." ),
784 aFootprint->GetReference(),
785 EscapeHTML( fpFilters ) );
786 }
787 else
788 {
789 msg.Printf( _( "Updated %s footprint filters to '%s'." ),
790 aFootprint->GetReference(),
791 EscapeHTML( fpFilters ) );
792
793 changed = true;
794 aFootprint->SetFilters( fpFilters );
795 }
796
797 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
798 }
799
800 bool netlistExcludeFromBOM = aNetlistComponent->GetProperties().count( wxT( "exclude_from_bom" ) ) > 0;
801
802 if( firstAssociatedVariant != nullptr && firstAssociatedVariant->m_hasExcludedFromBOM )
803 netlistExcludeFromBOM = firstAssociatedVariant->m_excludedFromBOM;
804
805 if( m_updateFields && netlistExcludeFromBOM != ( ( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_BOM ) > 0 ) )
806 {
807 if( m_isDryRun )
808 {
809 if( netlistExcludeFromBOM )
810 msg.Printf( _( "Add %s 'exclude from BOM' fabrication attribute." ), aFootprint->GetReference() );
811 else
812 msg.Printf( _( "Remove %s 'exclude from BOM' fabrication attribute." ), aFootprint->GetReference() );
813 }
814 else
815 {
816 int attributes = aFootprint->GetAttributes();
817
818 if( netlistExcludeFromBOM )
819 {
820 attributes |= FP_EXCLUDE_FROM_BOM;
821 msg.Printf( _( "Added %s 'exclude from BOM' fabrication attribute." ), aFootprint->GetReference() );
822 }
823 else
824 {
825 attributes &= ~FP_EXCLUDE_FROM_BOM;
826 msg.Printf( _( "Removed %s 'exclude from BOM' fabrication attribute." ), aFootprint->GetReference() );
827 }
828
829 changed = true;
830 aFootprint->SetAttributes( attributes );
831 }
832
833 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
834 }
835
836 bool netlistExcludeFromSim = aNetlistComponent->GetProperties().count( wxT( "exclude_from_sim" ) ) > 0;
837
838 if( firstAssociatedVariant != nullptr && firstAssociatedVariant->m_hasExcludedFromSim )
839 netlistExcludeFromSim = firstAssociatedVariant->m_excludedFromSim;
840
842 && netlistExcludeFromSim != ( ( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_SIM ) > 0 ) )
843 {
844 if( m_isDryRun )
845 {
846 if( netlistExcludeFromSim )
847 msg.Printf( _( "Add %s 'exclude from simulation' attribute." ), aFootprint->GetReference() );
848 else
849 msg.Printf( _( "Remove %s 'exclude from simulation' attribute." ), aFootprint->GetReference() );
850 }
851 else
852 {
853 int attributes = aFootprint->GetAttributes();
854
855 if( netlistExcludeFromSim )
856 {
857 attributes |= FP_EXCLUDE_FROM_SIM;
858 msg.Printf( _( "Added %s 'exclude from simulation' attribute." ), aFootprint->GetReference() );
859 }
860 else
861 {
862 attributes &= ~FP_EXCLUDE_FROM_SIM;
863 msg.Printf( _( "Removed %s 'exclude from simulation' attribute." ), aFootprint->GetReference() );
864 }
865
866 changed = true;
867 aFootprint->SetAttributes( attributes );
868 }
869
870 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
871 }
872
873 bool netlistDNP = aNetlistComponent->GetProperties().count( wxT( "dnp" ) ) > 0;
874
875 if( firstAssociatedVariant != nullptr && firstAssociatedVariant->m_hasDnp )
876 netlistDNP = firstAssociatedVariant->m_dnp;
877
878 if( m_updateFields && netlistDNP != ( ( aFootprint->GetAttributes() & FP_DNP ) > 0 ) )
879 {
880 if( m_isDryRun )
881 {
882 if( netlistDNP )
883 msg.Printf( _( "Add %s 'Do not place' fabrication attribute." ), aFootprint->GetReference() );
884 else
885 msg.Printf( _( "Remove %s 'Do not place' fabrication attribute." ), aFootprint->GetReference() );
886 }
887 else
888 {
889 int attributes = aFootprint->GetAttributes();
890
891 if( netlistDNP )
892 {
893 attributes |= FP_DNP;
894 msg.Printf( _( "Added %s 'Do not place' fabrication attribute." ), aFootprint->GetReference() );
895 }
896 else
897 {
898 attributes &= ~FP_DNP;
899 msg.Printf( _( "Removed %s 'Do not place' fabrication attribute." ), aFootprint->GetReference() );
900 }
901
902 changed = true;
903 aFootprint->SetAttributes( attributes );
904 }
905
906 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
907 }
908
909 bool netlistExcludeFromPosFiles = aNetlistComponent->GetProperties().count( wxT( "exclude_from_pos_files" ) ) > 0;
910
911 if( firstAssociatedVariant != nullptr && firstAssociatedVariant->m_hasExcludedFromPosFiles )
912 netlistExcludeFromPosFiles = firstAssociatedVariant->m_excludedFromPosFiles;
913
915 && netlistExcludeFromPosFiles != ( ( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES ) > 0 ) )
916 {
917 if( m_isDryRun )
918 {
919 if( netlistExcludeFromPosFiles )
920 {
921 msg.Printf( _( "Add %s 'exclude from position files' fabrication attribute." ),
922 aFootprint->GetReference() );
923 }
924 else
925 {
926 msg.Printf( _( "Remove %s 'exclude from position files' fabrication attribute." ),
927 aFootprint->GetReference() );
928 }
929 }
930 else
931 {
932 int attributes = aFootprint->GetAttributes();
933
934 if( netlistExcludeFromPosFiles )
935 {
936 attributes |= FP_EXCLUDE_FROM_POS_FILES;
937 msg.Printf( _( "Added %s 'exclude from position files' fabrication attribute." ),
938 aFootprint->GetReference() );
939 }
940 else
941 {
942 attributes &= ~FP_EXCLUDE_FROM_POS_FILES;
943 msg.Printf( _( "Removed %s 'exclude from position files' fabrication attribute." ),
944 aFootprint->GetReference() );
945 }
946
947 changed = true;
948 aFootprint->SetAttributes( attributes );
949 }
950
951 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
952 }
953
955 && aNetlistComponent->GetDuplicatePadNumbersAreJumpers() != aFootprint->GetDuplicatePadNumbersAreJumpers() )
956 {
957 bool value = aNetlistComponent->GetDuplicatePadNumbersAreJumpers();
958
959 if( !m_isDryRun )
960 {
961 changed = true;
962 aFootprint->SetDuplicatePadNumbersAreJumpers( value );
963
964 if( value )
965 {
966 msg.Printf( _( "Added %s 'duplicate pad numbers are jumpers' attribute." ),
967 aFootprint->GetReference() );
968 }
969 else
970 {
971 msg.Printf( _( "Removed %s 'duplicate pad numbers are jumpers' attribute." ),
972 aFootprint->GetReference() );
973 }
974 }
975 else
976 {
977 if( value )
978 {
979 msg.Printf( _( "Add %s 'duplicate pad numbers are jumpers' attribute." ),
980 aFootprint->GetReference() );
981 }
982 else
983 {
984 msg.Printf( _( "Remove %s 'duplicate pad numbers are jumpers' attribute." ),
985 aFootprint->GetReference() );
986 }
987 }
988
989 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
990 }
991
992 if( m_updateFields && aNetlistComponent->JumperPadGroups() != aFootprint->JumperPadGroups() )
993 {
994 if( !m_isDryRun )
995 {
996 changed = true;
997 aFootprint->JumperPadGroups() = aNetlistComponent->JumperPadGroups();
998 msg.Printf( _( "Updated %s jumper pad groups" ), aFootprint->GetReference() );
999 }
1000 else
1001 {
1002 msg.Printf( _( "Update %s jumper pad groups" ), aFootprint->GetReference() );
1003 }
1004
1005 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1006 }
1007
1008 if( changed && copy )
1009 m_commit.Modified( aFootprint, copy );
1010 else
1011 delete copy;
1012
1013 return true;
1014}
1015
1016
1018{
1019 for( PCB_GROUP* group : m_board->Groups() )
1020 {
1021 if( group->m_Uuid == aUuid )
1022 return group;
1023 }
1024
1025 return nullptr;
1026}
1027
1028
1030{
1031 PCB_GROUP* group = new PCB_GROUP( m_board );
1032 group->SetUuid( aNetlistGroup.uuid );
1033 group->SetName( aNetlistGroup.name );
1034
1035 m_board->Add( group );
1036 m_commit.Added( group );
1037 m_addedGroups.push_back( group );
1038
1039 return group;
1040}
1041
1042
1043bool BOARD_NETLIST_UPDATER::updateFootprintGroup( FOOTPRINT* aPcbFootprint, COMPONENT* aNetlistComponent )
1044{
1045 if( !m_transferGroups )
1046 return false;
1047
1048 KIID newGroupKIID = aNetlistComponent->GetGroup() ? aNetlistComponent->GetGroup()->uuid : 0;
1049 PCB_GROUP* existingGroup = static_cast<PCB_GROUP*>( aPcbFootprint->GetParentGroup() );
1050 KIID existingGroupKIID = existingGroup ? existingGroup->m_Uuid : 0;
1051
1052 // No changes, nothing to do
1053 if( newGroupKIID == existingGroupKIID )
1054 return false;
1055
1056 wxString msg;
1057
1058 // Create a copy only if the footprint has not been added during this update
1059 FOOTPRINT* copy = nullptr;
1060
1061 if( !m_isDryRun && !m_commit.GetStatus( aPcbFootprint ) )
1062 {
1063 copy = static_cast<FOOTPRINT*>( aPcbFootprint->Clone() );
1064 copy->SetParentGroup( nullptr );
1065 }
1066
1067 bool changed = false;
1068
1069 // newGroup may point to an existing group on the board if we find an
1070 // incoming group UUID that matches an existing group
1071 PCB_GROUP* newGroup = findBoardGroup( newGroupKIID );
1072
1073 // Remove from existing group
1074 if( existingGroupKIID != 0 )
1075 {
1076 if( m_isDryRun )
1077 {
1078 msg.Printf( _( "Remove %s from group '%s'." ),
1079 aPcbFootprint->GetReference(),
1080 EscapeHTML( existingGroup->GetName() ) );
1081 }
1082 else
1083 {
1084 msg.Printf( _( "Removed %s from group '%s'." ),
1085 aPcbFootprint->GetReference(),
1086 EscapeHTML( existingGroup->GetName() ) );
1087
1088 changed = true;
1089 m_commit.Modify( existingGroup, nullptr, RECURSE_MODE::NO_RECURSE );
1090 existingGroup->RemoveItem( aPcbFootprint );
1091
1092 if( existingGroup->GetItems().size() < 2 )
1093 {
1094 existingGroup->RemoveAll();
1095 m_commit.Remove( existingGroup );
1096 }
1097 }
1098
1099 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1100 }
1101
1102 // Add to new group
1103 if( newGroupKIID != 0 )
1104 {
1105 if( m_isDryRun )
1106 {
1107 msg.Printf( _( "Add %s to group '%s'." ),
1108 aPcbFootprint->GetReference(),
1109 EscapeHTML( aNetlistComponent->GetGroup()->name ) );
1110 }
1111 else
1112 {
1113 msg.Printf( _( "Added %s to group '%s'." ),
1114 aPcbFootprint->GetReference(),
1115 EscapeHTML( aNetlistComponent->GetGroup()->name ) );
1116
1117 changed = true;
1118
1119 if( newGroup == nullptr )
1120 {
1121 newGroup = addBoardGroup( *aNetlistComponent->GetGroup() );
1122 }
1123 else
1124 {
1125 m_commit.Modify( newGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
1126 }
1127
1128 newGroup->AddItem( aPcbFootprint );
1129 }
1130
1131 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1132 }
1133
1134 if( changed && copy )
1135 m_commit.Modified( aPcbFootprint, copy );
1136 else if( copy )
1137 delete copy;
1138
1139 return changed;
1140}
1141
1142
1144{
1145 wxString msg;
1146
1147 // Create a copy only if the footprint has not been added during this update
1148 FOOTPRINT* copy = nullptr;
1149
1150 if( !m_isDryRun && !m_commit.GetStatus( aFootprint ) )
1151 {
1152 copy = static_cast<FOOTPRINT*>( aFootprint->Clone() );
1153 copy->SetParentGroup( nullptr );
1154 }
1155
1156 bool changed = false;
1157
1158 // At this point, the component footprint is updated. Now update the nets.
1159 std::deque<PAD*> pads = aFootprint->Pads();
1160 std::set<wxString> padNetnames;
1161
1162 std::sort( pads.begin(), pads.end(),
1163 []( PAD* a, PAD* b )
1164 {
1165 return a->m_Uuid < b->m_Uuid;
1166 } );
1167
1168 for( PAD* pad : pads )
1169 {
1170 const COMPONENT_NET& net = aNewComponent->GetNet( pad->GetNumber() );
1171
1172 wxLogTrace( wxT( "NETLIST_UPDATE" ),
1173 wxT( "Processing pad %s of component %s" ),
1174 pad->GetNumber(),
1175 aNewComponent->GetReference() );
1176
1177 wxString pinFunction;
1178 wxString pinType;
1179
1180 if( net.IsValid() ) // i.e. the pad has a name
1181 {
1182 wxLogTrace( wxT( "NETLIST_UPDATE" ),
1183 wxT( " Found valid net: %s" ),
1184 net.GetNetName() );
1185 pinFunction = net.GetPinFunction();
1186 pinType = net.GetPinType();
1187 }
1188 else
1189 {
1190 wxLogTrace( wxT( "NETLIST_UPDATE" ),
1191 wxT( " No net found for pad %s" ),
1192 pad->GetNumber() );
1193 }
1194
1195 if( !m_isDryRun )
1196 {
1197 if( pad->GetPinFunction() != pinFunction )
1198 {
1199 changed = true;
1200 pad->SetPinFunction( pinFunction );
1201 }
1202
1203 if( pad->GetPinType() != pinType )
1204 {
1205 changed = true;
1206 pad->SetPinType( pinType );
1207 }
1208 }
1209 else
1210 {
1211 cachePinFunction( pad, pinFunction );
1212 }
1213
1214 // Test if new footprint pad has no net (pads not on copper layers have no net).
1215 if( !net.IsValid() || !pad->IsOnCopperLayer() )
1216 {
1217 if( !pad->GetNetname().IsEmpty() )
1218 {
1219 if( m_isDryRun )
1220 {
1221 msg.Printf( _( "Disconnect %s pin %s." ),
1222 aFootprint->GetReference(),
1223 EscapeHTML( pad->GetNumber() ) );
1224 }
1225 else
1226 {
1227 msg.Printf( _( "Disconnected %s pin %s." ),
1228 aFootprint->GetReference(),
1229 EscapeHTML( pad->GetNumber() ) );
1230 }
1231
1232 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1233 }
1234 else if( pad->IsOnCopperLayer() && !pad->GetNumber().IsEmpty() )
1235 {
1236 // pad is connectable but has no net found in netlist
1237 msg.Printf( _( "No net found for component %s pad %s (no pin %s in symbol)." ),
1238 aFootprint->GetReference(),
1239 EscapeHTML( pad->GetNumber() ),
1240 EscapeHTML( pad->GetNumber() ) );
1241 m_reporter->Report( msg, RPT_SEVERITY_WARNING);
1243 }
1244
1245 if( !m_isDryRun )
1246 {
1247 if( pad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1248 {
1249 changed = true;
1250 pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
1251 }
1252
1253 // If the pad has no net from netlist (i.e. not in netlist
1254 // it cannot have a pin function
1255 if( pad->GetNetname().IsEmpty() && !pad->GetPinFunction().IsEmpty() )
1256 {
1257 changed = true;
1258 pad->SetPinFunction( wxEmptyString );
1259 }
1260 }
1261 else
1262 {
1263 cacheNetname( pad, wxEmptyString );
1264 }
1265 }
1266 else // New footprint pad has a net.
1267 {
1268 wxString netName = net.GetNetName();
1269
1270 if( pad->IsNoConnectPad() )
1271 {
1272 netName = wxString::Format( wxS( "%s" ), net.GetNetName() );
1273
1274 for( int jj = 1; !padNetnames.insert( netName ).second
1275 || ( netName != net.GetNetName() && m_schematicNetNames.count( netName ) );
1276 jj++ )
1277 {
1278 netName = wxString::Format( wxS( "%s_%d" ), net.GetNetName(), jj );
1279 }
1280 }
1281
1282 NETINFO_ITEM* netinfo = m_board->FindNet( netName );
1283
1284 if( netinfo && !m_isDryRun )
1285 netinfo->SetIsCurrent( true );
1286
1287 if( pad->GetNetname() != netName )
1288 {
1289
1290 if( netinfo == nullptr )
1291 {
1292 // It might be a new net that has not been added to the board yet
1293 if( m_addedNets.count( netName ) )
1294 netinfo = m_addedNets[ netName ];
1295 }
1296
1297 if( netinfo == nullptr )
1298 {
1299 netinfo = new NETINFO_ITEM( m_board, netName );
1300
1301 // It is a new net, we have to add it
1302 if( !m_isDryRun )
1303 {
1304 changed = true;
1305 m_commit.Add( netinfo );
1306 }
1307
1308 m_addedNets[netName] = netinfo;
1309 msg.Printf( _( "Add net %s." ),
1310 EscapeHTML( UnescapeString( netName ) ) );
1311 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1312 }
1313
1314 if( !pad->GetNetname().IsEmpty() )
1315 {
1316 m_oldToNewNets[ pad->GetNetname() ] = netName;
1317
1318 if( m_isDryRun )
1319 {
1320 msg.Printf( _( "Reconnect %s pin %s from %s to %s."),
1321 aFootprint->GetReference(),
1322 EscapeHTML( pad->GetNumber() ),
1323 EscapeHTML( UnescapeString( pad->GetNetname() ) ),
1324 EscapeHTML( UnescapeString( netName ) ) );
1325 }
1326 else
1327 {
1328 msg.Printf( _( "Reconnected %s pin %s from %s to %s."),
1329 aFootprint->GetReference(),
1330 EscapeHTML( pad->GetNumber() ),
1331 EscapeHTML( UnescapeString( pad->GetNetname() ) ),
1332 EscapeHTML( UnescapeString( netName ) ) );
1333 }
1334 }
1335 else
1336 {
1337 if( m_isDryRun )
1338 {
1339 msg.Printf( _( "Connect %s pin %s to %s."),
1340 aFootprint->GetReference(),
1341 EscapeHTML( pad->GetNumber() ),
1342 EscapeHTML( UnescapeString( netName ) ) );
1343 }
1344 else
1345 {
1346 msg.Printf( _( "Connected %s pin %s to %s."),
1347 aFootprint->GetReference(),
1348 EscapeHTML( pad->GetNumber() ),
1349 EscapeHTML( UnescapeString( netName ) ) );
1350 }
1351 }
1352
1353 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1354
1355 if( !m_isDryRun )
1356 {
1357 changed = true;
1358 pad->SetNet( netinfo );
1359 }
1360 else
1361 {
1362 cacheNetname( pad, netName );
1363 }
1364 }
1365 }
1366 }
1367
1368 if( changed && copy )
1369 m_commit.Modified( aFootprint, copy );
1370 else
1371 delete copy;
1372
1373 return true;
1374}
1375
1376
1378{
1379 // Build the footprint-side representation from the netlist component
1380 std::vector<FOOTPRINT::FP_UNIT_INFO> newUnits;
1381
1382 for( const COMPONENT::UNIT_INFO& u : aNewComponent->GetUnitInfo() )
1383 newUnits.push_back( { u.m_unitName, u.m_pins } );
1384
1385 const std::vector<FOOTPRINT::FP_UNIT_INFO>& curUnits = aFootprint->GetUnitInfo();
1386
1387 if( std::ranges::equal( curUnits, newUnits,
1388 []( const auto& a, const auto& b )
1389 {
1390 return a.m_unitName == b.m_unitName && a.m_pins == b.m_pins;
1391 } ) )
1392 return false;
1393
1394 wxString msg;
1395
1396 if( m_isDryRun )
1397 {
1398 msg.Printf( _( "Update %s unit metadata." ), aFootprint->GetReference() );
1399 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1400 return false; // no actual change on board during dry run
1401 }
1402
1403 // Create a copy only if the footprint has not been added during this update
1404 FOOTPRINT* copy = nullptr;
1405
1406 if( !m_commit.GetStatus( aFootprint ) )
1407 {
1408 copy = static_cast<FOOTPRINT*>( aFootprint->Clone() );
1409 copy->SetParentGroup( nullptr );
1410 }
1411
1412 aFootprint->SetUnitInfo( newUnits );
1413
1414 msg.Printf( _( "Updated %s unit metadata." ), aFootprint->GetReference() );
1415 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1416
1417 if( copy )
1418 m_commit.Modified( aFootprint, copy );
1419
1420 return true;
1421}
1422
1423
1424bool BOARD_NETLIST_UPDATER::fpidsEquivalent( const LIB_ID& aBoardFpid, const LIB_ID& aSchematicFpid )
1425{
1426 if( aSchematicFpid.IsLegacy() )
1427 return aBoardFpid.GetLibItemName() == aSchematicFpid.GetLibItemName();
1428
1429 return aBoardFpid == aSchematicFpid;
1430}
1431
1432
1434 const std::vector<FOOTPRINT*>& aFootprints,
1435 const LIB_ID& aBaseFpid )
1436{
1437 wxString msg;
1438 const auto& variants = aComponent->GetVariants();
1439
1440 if( aBaseFpid.empty() )
1441 return;
1442
1443 const wxString FOOTPRINT_FIELD_NAME = GetDefaultFieldName( FIELD_T::FOOTPRINT, UNTRANSLATED );
1444
1445 struct VARIANT_INFO
1446 {
1447 wxString name;
1448 const COMPONENT_VARIANT* variant;
1449 LIB_ID variantFPID;
1450 };
1451
1452 std::vector<VARIANT_INFO> variantInfo;
1453 variantInfo.reserve( variants.size() );
1454
1455 for( const auto& [variantName, variant] : variants )
1456 {
1457 LIB_ID variantFPID = aBaseFpid;
1458
1459 auto fieldIt = variant.m_fields.find( FOOTPRINT_FIELD_NAME );
1460
1461 if( fieldIt != variant.m_fields.end() && !fieldIt->second.IsEmpty() )
1462 {
1463 LIB_ID parsedId;
1464
1465 if( parsedId.Parse( fieldIt->second, true ) >= 0 )
1466 {
1467 msg.Printf( _( "Invalid footprint ID '%s' for variant '%s' on %s." ),
1468 EscapeHTML( fieldIt->second ),
1469 variantName,
1470 aComponent->GetReference() );
1471 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
1472 ++m_errorCount;
1473 }
1474 else
1475 {
1476 variantFPID = parsedId;
1477 }
1478 }
1479
1480 variantInfo.push_back( { variantName, &variant, variantFPID } );
1481 }
1482
1483 for( FOOTPRINT* footprint : aFootprints )
1484 {
1485 if( !footprint )
1486 continue;
1487
1488 FOOTPRINT* copy = nullptr;
1489
1490 if( !m_isDryRun && !m_commit.GetStatus( footprint ) )
1491 {
1492 copy = static_cast<FOOTPRINT*>( footprint->Clone() );
1493 copy->SetParentGroup( nullptr );
1494 }
1495
1496 bool changed = false;
1497
1498 auto printAttributeMessage =
1499 [&]( bool add, const wxString& attrName, const wxString& variantName )
1500 {
1501 if( m_isDryRun )
1502 {
1503 if( aFootprints.size() > 1 )
1504 {
1505 msg.Printf( add ? _( "Add %s '%s' attribute to variant %s (footprint %s)." )
1506 : _( "Remove %s '%s' attribute from variant %s (footprint %s)." ),
1507 footprint->GetReference(),
1508 attrName,
1509 variantName,
1510 footprint->GetFPIDAsString() );
1511 }
1512 else
1513 {
1514 msg.Printf( add ? _( "Add %s '%s' attribute to variant %s." )
1515 : _( "Remove %s '%s' attribute from variant %s." ),
1516 footprint->GetReference(),
1517 attrName,
1518 variantName );
1519 }
1520 }
1521 else
1522 {
1523 if( aFootprints.size() > 1 )
1524 {
1525 msg.Printf( add ? _( "Added %s '%s' attribute to variant %s (footprint %s)." )
1526 : _( "Removed %s '%s' attribute from variant %s (footprint %s)." ),
1527 footprint->GetReference(),
1528 attrName,
1529 variantName,
1530 footprint->GetFPIDAsString() );
1531 }
1532 else
1533 {
1534 msg.Printf( add ? _( "Added %s '%s' attribute to variant %s." )
1535 : _( "Removed %s '%s' attribute from variant %s." ),
1536 footprint->GetReference(),
1537 attrName,
1538 variantName );
1539 }
1540 }
1541 };
1542
1543 bool isBaseFootprint = fpidsEquivalent( footprint->GetFPID(), aBaseFpid );
1544
1545 // The footprint's own DNP flag before this pass forces the default-variant hiding below.
1546 // The per-variant target for a footprint that IS the active choice must fall back to this
1547 // original flag, not the forced one, so the active footprint stays populated.
1548 const bool baseFootprintDnp = footprint->IsDNP();
1549 bool effectiveFootprintDnp = baseFootprintDnp;
1550
1551 // A footprint that is not the component's base footprint is DNP by default (it stands in
1552 // only for the variants that select it). This runs before the per-variant loop so the loop
1553 // sees the correct effective DNP when deciding whether an explicit per-variant override is
1554 // needed; otherwise a footprint kept populated for its own variant would not converge until
1555 // a second netlist update.
1556 if( !isBaseFootprint && !effectiveFootprintDnp )
1557 {
1558 msg.Printf( m_isDryRun ? _( "Add %s 'Do not place' fabrication attribute." )
1559 : _( "Added %s 'Do not place' fabrication attribute." ),
1560 footprint->GetReference() );
1561
1562 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1563
1564 if( !m_isDryRun )
1565 footprint->SetDNP( true );
1566
1567 // Track the forced DNP locally so the per-variant loop below sees the correct effective
1568 // state even in dry run, where SetDNP() is intentionally not applied.
1569 effectiveFootprintDnp = true;
1570 changed = true;
1571 }
1572
1573 std::set<wxString> excessVariants;
1574
1575 for( const auto& [variantName, _] : footprint->GetVariants() )
1576 excessVariants.insert( variantName );
1577
1578 for( const VARIANT_INFO& info : variantInfo )
1579 {
1580 const COMPONENT_VARIANT& variant = *info.variant;
1581
1582 // During dry run, just read current state. During actual run, create variant if needed.
1583 FOOTPRINT_VARIANT* currentVariant = footprint->GetVariant( info.name );
1584
1585 // Check if this footprint is the active one for this variant
1586 bool isAssociatedFootprint = fpidsEquivalent( footprint->GetFPID(), info.variantFPID );
1587
1588 // If this footprint is not active, and it's not one of multiple footprints that share
1589 // a RefDes (one per variant), then it doesn't need variant info for it.
1590 if( !isAssociatedFootprint && aFootprints.size() <= 1 )
1591 continue;
1592
1593 excessVariants.erase( info.name );
1594 bool targetDnp = variant.m_hasDnp ? variant.m_dnp : baseFootprintDnp;
1595 bool currentDnp = currentVariant ? currentVariant->GetDNP() : effectiveFootprintDnp;
1596
1597 // When multiple footprints share a RefDes (one per variant), a footprint that is not
1598 // the active choice for this variant must be DNP for it so the 3D viewer and other
1599 // consumers hide it. The base footprint carries no global DNP flag, so it needs an
1600 // explicit per-variant override; non-base footprints are already globally DNP above.
1601 if( !isAssociatedFootprint )
1602 targetDnp = true;
1603
1604 if( currentDnp != targetDnp )
1605 {
1606 printAttributeMessage( targetDnp, _( "Do not place" ), info.name );
1607
1608 if( !m_isDryRun )
1609 {
1610 if( FOOTPRINT_VARIANT* fpVariant = footprint->AddVariant( info.name ) )
1611 fpVariant->SetDNP( targetDnp );
1612 }
1613
1614 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1615 changed = true;
1616 }
1617
1618 bool targetExcludedFromBOM = variant.m_hasExcludedFromBOM ? variant.m_excludedFromBOM
1619 : footprint->IsExcludedFromBOM();
1620 bool currentExcludedFromBOM = currentVariant ? currentVariant->GetExcludedFromBOM()
1621 : footprint->IsExcludedFromBOM();
1622
1623 if( currentExcludedFromBOM != targetExcludedFromBOM )
1624 {
1625 printAttributeMessage( targetExcludedFromBOM, _( "exclude from BOM" ), info.name );
1626
1627 if( !m_isDryRun )
1628 {
1629 if( FOOTPRINT_VARIANT* fpVariant = footprint->AddVariant( info.name ) )
1630 fpVariant->SetExcludedFromBOM( targetExcludedFromBOM );
1631 }
1632
1633 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1634 changed = true;
1635 }
1636
1637 bool targetExcludedFromSim = variant.m_hasExcludedFromSim ? variant.m_excludedFromSim
1638 : footprint->IsExcludedFromSim();
1639 bool currentExcludedFromSim = currentVariant ? currentVariant->GetExcludedFromSim()
1640 : footprint->IsExcludedFromSim();
1641
1642 if( currentExcludedFromSim != targetExcludedFromSim )
1643 {
1644 printAttributeMessage( targetExcludedFromSim, _( "exclude from simulation" ), info.name );
1645
1646 if( !m_isDryRun )
1647 {
1648 if( FOOTPRINT_VARIANT* fpVariant = footprint->AddVariant( info.name ) )
1649 fpVariant->SetExcludedFromSim( targetExcludedFromSim );
1650 }
1651
1652 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1653 changed = true;
1654 }
1655
1656 bool targetExcludedFromPosFiles = variant.m_hasExcludedFromPosFiles ? variant.m_excludedFromPosFiles
1657 : footprint->IsExcludedFromPosFiles();
1658 bool currentExcludedFromPosFiles = currentVariant ? currentVariant->GetExcludedFromPosFiles()
1659 : footprint->IsExcludedFromPosFiles();
1660
1661 if( currentExcludedFromPosFiles != targetExcludedFromPosFiles )
1662 {
1663 printAttributeMessage( targetExcludedFromPosFiles, _( "exclude from position files" ), info.name );
1664
1665 if( !m_isDryRun )
1666 {
1667 if( FOOTPRINT_VARIANT* fpVariant = footprint->AddVariant( info.name ) )
1668 fpVariant->SetExcludedFromPosFiles( targetExcludedFromPosFiles );
1669 }
1670
1671 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1672 changed = true;
1673 }
1674
1675 if( m_updateFields )
1676 {
1677 std::map<wxString, wxString> fpFieldsAsMap;
1678
1679 for( PCB_FIELD* field : footprint->GetFields() )
1680 fpFieldsAsMap[field->GetName()] = field->GetText();
1681
1682 for( const auto& [fieldName, fieldValue] : variant.m_fields )
1683 {
1684 if( fieldName.CmpNoCase( FOOTPRINT_FIELD_NAME ) == 0 )
1685 continue;
1686
1687 wxString currentValue;
1688
1689 if( currentVariant && currentVariant->HasFieldValue( fieldName ) )
1690 currentValue = currentVariant->GetFieldValue( fieldName );
1691 else
1692 currentValue = fpFieldsAsMap[fieldName];
1693
1694 fpFieldsAsMap.erase( fieldName ); // leave fpFieldsAsMap containing only unprocessed fields
1695
1696 if( currentValue != fieldValue )
1697 {
1698 if( m_isDryRun )
1699 {
1700 if( aFootprints.size() > 1 )
1701 {
1702 msg.Printf( _( "Change %s field '%s' to '%s' on variant %s (footprint %s)." ),
1703 footprint->GetReference(),
1704 fieldName,
1705 fieldValue,
1706 info.name,
1707 footprint->GetFPIDAsString() );
1708 }
1709 else
1710 {
1711 msg.Printf( _( "Change %s field '%s' to '%s' on variant %s." ),
1712 footprint->GetReference(),
1713 fieldName,
1714 fieldValue,
1715 info.name );
1716 }
1717 }
1718 else
1719 {
1720 if( aFootprints.size() > 1 )
1721 {
1722 msg.Printf( _( "Changed %s field '%s' to '%s' on variant %s (footprint %s)." ),
1723 footprint->GetReference(),
1724 fieldName,
1725 fieldValue,
1726 info.name,
1727 footprint->GetFPIDAsString() );
1728 }
1729 else
1730 {
1731 msg.Printf( _( "Changed %s field '%s' to '%s' on variant %s." ),
1732 footprint->GetReference(),
1733 fieldName,
1734 fieldValue,
1735 info.name );
1736 }
1737
1738 if( FOOTPRINT_VARIANT* fpVariant = footprint->AddVariant( info.name ) )
1739 fpVariant->SetFieldValue( fieldName, fieldValue );
1740 }
1741
1742 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1743 changed = true;
1744 }
1745 }
1746
1747 // Go through everything left in fpFieldsAsMap and clear any variant field definitions
1748 // that are no longer present in the schematic
1749 for( const auto& [fieldName, fieldValue] : fpFieldsAsMap )
1750 {
1751 if( fieldName.CmpNoCase( FOOTPRINT_FIELD_NAME ) == 0 )
1752 continue;
1753
1754 if( currentVariant && currentVariant->HasFieldValue( fieldName ) )
1755 {
1756 if( m_isDryRun )
1757 {
1758 if( aFootprints.size() > 1 )
1759 {
1760 msg.Printf( _( "Remove %s field '%s' override on variant %s (footprint %s)." ),
1761 footprint->GetReference(),
1762 fieldName,
1763 info.name,
1764 footprint->GetFPIDAsString() );
1765 }
1766 else
1767 {
1768 msg.Printf( _( "Remove %s field '%s' override on variant %s." ),
1769 footprint->GetReference(),
1770 fieldName,
1771 info.name );
1772 }
1773 }
1774 else
1775 {
1776 if( aFootprints.size() > 1 )
1777 {
1778 msg.Printf( _( "Removed %s field '%s' override on variant %s (footprint %s)." ),
1779 footprint->GetReference(),
1780 fieldName,
1781 info.name,
1782 footprint->GetFPIDAsString() );
1783 }
1784 else
1785 {
1786 msg.Printf( _( "Removed %s field '%s' override on variant %s." ),
1787 footprint->GetReference(),
1788 fieldName,
1789 info.name );
1790 }
1791
1792 currentVariant->RemoveFieldValue( fieldName );
1793 }
1794
1795 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1796 changed = true;
1797 }
1798 }
1799 }
1800 }
1801
1802 for( const wxString& excess : excessVariants )
1803 {
1804 if( m_isDryRun )
1805 {
1806 msg.Printf( _( "Remove variant %s:%s no longer associated with footprint %s." ),
1807 footprint->GetReference(),
1808 excess,
1809 footprint->GetFPIDAsString() );
1810 }
1811 else
1812 {
1813 msg.Printf( _( "Removed variant %s:%s no longer associated with footprint %s." ),
1814 footprint->GetReference(),
1815 excess,
1816 footprint->GetFPIDAsString() );
1817
1818 footprint->DeleteVariant( excess );
1819 }
1820
1821 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1822 changed = true;
1823 }
1824
1825 if( !m_isDryRun && changed && copy )
1826 m_commit.Modified( footprint, copy );
1827 else
1828 delete copy;
1829 }
1830}
1831
1832
1834{
1835 for( ZONE* zone : m_board->Zones() )
1836 {
1837 if( !zone->IsOnCopperLayer() || zone->GetIsRuleArea() )
1838 continue;
1839
1840 m_zoneConnectionsCache[ zone ] = m_board->GetConnectivity()->GetConnectedPads( zone );
1841 }
1842}
1843
1844
1846{
1847 wxString msg;
1848 std::set<wxString> netlistNetnames;
1849
1850 for( int ii = 0; ii < (int) aNetlist.GetCount(); ii++ )
1851 {
1852 const COMPONENT* component = aNetlist.GetComponent( ii );
1853
1854 for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
1855 {
1856 const COMPONENT_NET& net = component->GetNet( jj );
1857 netlistNetnames.insert( net.GetNetName() );
1858 }
1859 }
1860
1861 for( PCB_TRACK* via : m_board->Tracks() )
1862 {
1863 if( via->Type() != PCB_VIA_T )
1864 continue;
1865
1866 if( netlistNetnames.count( via->GetNetname() ) == 0 )
1867 {
1868 wxString updatedNetname = wxEmptyString;
1869
1870 // Take via name from name change map if it didn't match to a new pad
1871 // (this is useful for stitching vias that don't connect to tracks)
1872 if( m_oldToNewNets.count( via->GetNetname() ) )
1873 {
1874 updatedNetname = m_oldToNewNets[via->GetNetname()];
1875 }
1876
1877 if( !updatedNetname.IsEmpty() )
1878 {
1879 if( m_isDryRun )
1880 {
1881 wxString originalNetname = via->GetNetname();
1882
1883 msg.Printf( _( "Reconnect via from %s to %s." ),
1884 EscapeHTML( UnescapeString( originalNetname ) ),
1885 EscapeHTML( UnescapeString( updatedNetname ) ) );
1886
1887 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1888 }
1889 else
1890 {
1891 NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
1892
1893 if( !netinfo )
1894 netinfo = m_addedNets[updatedNetname];
1895
1896 if( netinfo )
1897 {
1898 wxString originalNetname = via->GetNetname();
1899
1900 m_commit.Modify( via );
1901 via->SetNet( netinfo );
1902
1903 msg.Printf( _( "Reconnected via from %s to %s." ),
1904 EscapeHTML( UnescapeString( originalNetname ) ),
1905 EscapeHTML( UnescapeString( updatedNetname ) ) );
1906
1907 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1908 }
1909 }
1910 }
1911 else
1912 {
1913 msg.Printf( _( "Via connected to unknown net (%s)." ),
1914 EscapeHTML( UnescapeString( via->GetNetname() ) ) );
1915 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
1917 }
1918 }
1919 }
1920
1921 // Board connectivity net names are not the same as schematic connectivity net names.
1922 // Footprints that contain multiple overlapping pads with the same number are suffixed
1923 // with "_N" for internal use. Somewhere along the line, these pseudo net names were
1924 // exposed in the zone net name list.
1925 auto isInNetlist = [&]( const wxString& aNetName ) -> bool
1926 {
1927 if( netlistNetnames.count( aNetName ) )
1928 return true;
1929
1930 // If the zone net name is a pseudo net name, check if the root net name is in the net
1931 // list. If so, then this is a valid net.
1932 for( const wxString& netName : netlistNetnames )
1933 {
1934 if( aNetName.StartsWith( netName ) )
1935 return true;
1936 }
1937
1938 return false;
1939 };
1940
1941 // Test copper zones to detect "dead" nets (nets without any pad):
1942 for( ZONE* zone : m_board->Zones() )
1943 {
1944 if( !zone->IsOnCopperLayer() || zone->GetIsRuleArea() )
1945 continue;
1946
1947 if( !isInNetlist( zone->GetNetname() ) )
1948 {
1949 // Look for a pad in the zone's connected-pad-cache which has been updated to
1950 // a new net and use that. While this won't always be the right net, the dead
1951 // net is guaranteed to be wrong.
1952 wxString updatedNetname = wxEmptyString;
1953
1954 for( PAD* pad : m_zoneConnectionsCache[ zone ] )
1955 {
1956 if( getNetname( pad ) != zone->GetNetname() )
1957 {
1958 updatedNetname = getNetname( pad );
1959 break;
1960 }
1961 }
1962
1963 // Take zone name from name change map if it didn't match to a new pad
1964 // (this is useful for zones on internal layers)
1965 if( updatedNetname.IsEmpty() && m_oldToNewNets.count( zone->GetNetname() ) )
1966 {
1967 updatedNetname = m_oldToNewNets[ zone->GetNetname() ];
1968 }
1969
1970 if( !updatedNetname.IsEmpty() )
1971 {
1972 if( m_isDryRun )
1973 {
1974 wxString originalNetname = zone->GetNetname();
1975
1976 if( !zone->GetZoneName().IsEmpty() )
1977 {
1978 msg.Printf( _( "Reconnect copper zone '%s' from %s to %s." ),
1979 zone->GetZoneName(),
1980 EscapeHTML( UnescapeString( originalNetname ) ),
1981 EscapeHTML( UnescapeString( updatedNetname ) ) );
1982 }
1983 else
1984 {
1985 msg.Printf( _( "Reconnect copper zone from %s to %s." ),
1986 EscapeHTML( UnescapeString( originalNetname ) ),
1987 EscapeHTML( UnescapeString( updatedNetname ) ) );
1988 }
1989
1990 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
1991 }
1992 else
1993 {
1994 NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
1995
1996 if( !netinfo )
1997 netinfo = m_addedNets[ updatedNetname ];
1998
1999 if( netinfo )
2000 {
2001 wxString originalNetname = zone->GetNetname();
2002
2003 m_commit.Modify( zone );
2004 zone->SetNet( netinfo );
2005
2006 if( !zone->GetZoneName().IsEmpty() )
2007 {
2008 msg.Printf( _( "Reconnected copper zone '%s' from %s to %s." ),
2009 EscapeHTML( zone->GetZoneName() ),
2010 EscapeHTML( UnescapeString( originalNetname ) ),
2011 EscapeHTML( UnescapeString( updatedNetname ) ) );
2012 }
2013 else
2014 {
2015 msg.Printf( _( "Reconnected copper zone from %s to %s." ),
2016 EscapeHTML( UnescapeString( originalNetname ) ),
2017 EscapeHTML( UnescapeString( updatedNetname ) ) );
2018 }
2019
2020 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2021 }
2022 }
2023 }
2024 else
2025 {
2026 if( !zone->GetZoneName().IsEmpty() )
2027 {
2028 msg.Printf( _( "Copper zone '%s' has no pads connected." ),
2029 EscapeHTML( zone->GetZoneName() ) );
2030 }
2031 else
2032 {
2033 wxString layerNames = zone->LayerMaskDescribe();
2034 VECTOR2I pt = zone->GetPosition();
2035
2036 if( m_settings )
2037 {
2038 if( m_settings->m_Display.m_DisplayInvertXAxis )
2039 pt.x *= -1;
2040
2041 if( m_settings->m_Display.m_DisplayInvertYAxis )
2042 pt.y *= -1;
2043 }
2044
2045 msg.Printf( _( "Copper zone on %s at (%s, %s) has no pads connected to net \"%s\"." ),
2046 EscapeHTML( layerNames ),
2047 m_frame ? m_frame->MessageTextFromValue( pt.x )
2050 pt.x ),
2051 m_frame ? m_frame->MessageTextFromValue( pt.y )
2054 pt.y ),
2055 zone->GetNetname() );
2056 }
2057
2058 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
2060 }
2061 }
2062 }
2063
2064 return true;
2065}
2066
2067
2069{
2070 if( !m_transferGroups )
2071 return false;
2072
2073 wxString msg;
2074
2075 for( size_t ii = 0; ii < m_board->Groups().size(); ++ii )
2076 {
2077 PCB_GROUP* childGroup = m_board->Groups()[ii];
2078 NETLIST_GROUP* childNetlistGroup = aNetlist.GetGroupByUuid( childGroup->m_Uuid );
2079
2080 if( !childNetlistGroup )
2081 continue;
2082
2083 NETLIST_GROUP* parentNetlistGroup = aNetlist.GetParentGroup( childNetlistGroup->path );
2084
2085 if( !parentNetlistGroup || findBoardGroup( parentNetlistGroup->uuid ) )
2086 continue;
2087
2088 if( m_isDryRun )
2089 {
2090 msg.Printf( _( "Add group '%s' to group '%s'." ), EscapeHTML( childGroup->GetName() ),
2091 EscapeHTML( parentNetlistGroup->name ) );
2092 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2093 continue;
2094 }
2095
2096 addBoardGroup( *parentNetlistGroup );
2097 }
2098
2099 for( PCB_GROUP* pcbGroup : m_board->Groups() )
2100 {
2101 NETLIST_GROUP* netlistGroup = aNetlist.GetGroupByUuid( pcbGroup->m_Uuid );
2102
2103 if( netlistGroup == nullptr )
2104 continue;
2105
2106 if( netlistGroup->name != pcbGroup->GetName() )
2107 {
2108 if( m_isDryRun )
2109 {
2110 msg.Printf( _( "Change group name from '%s' to '%s'." ),
2111 EscapeHTML( pcbGroup->GetName() ),
2112 EscapeHTML( netlistGroup->name ) );
2113 }
2114 else
2115 {
2116 msg.Printf( _( "Changed group name from '%s' to '%s'." ),
2117 EscapeHTML( pcbGroup->GetName() ),
2118 EscapeHTML( netlistGroup->name ) );
2119 m_commit.Modify( pcbGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
2120 pcbGroup->SetName( netlistGroup->name );
2121 }
2122
2123 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2124 }
2125
2126 if( netlistGroup->libId != pcbGroup->GetDesignBlockLibId() )
2127 {
2128 if( m_isDryRun )
2129 {
2130 msg.Printf( _( "Change group library link from '%s' to '%s'." ),
2131 EscapeHTML( pcbGroup->GetDesignBlockLibId().GetUniStringLibId() ),
2132 EscapeHTML( netlistGroup->libId.GetUniStringLibId() ) );
2133 }
2134 else
2135 {
2136 msg.Printf( _( "Changed group library link from '%s' to '%s'." ),
2137 EscapeHTML( pcbGroup->GetDesignBlockLibId().GetUniStringLibId() ),
2138 EscapeHTML( netlistGroup->libId.GetUniStringLibId() ) );
2139 m_commit.Modify( pcbGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
2140 pcbGroup->SetDesignBlockLibId( netlistGroup->libId );
2141 }
2142
2143 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2144 }
2145
2146 // A group member may be another group (a nested group). Restore that parent/child
2147 // relationship on the board.
2148 for( const KIID_PATH& member : netlistGroup->members )
2149 {
2150 NETLIST_GROUP* memberGroup = aNetlist.GetGroupByPath( member );
2151
2152 if( !memberGroup )
2153 continue;
2154
2155 PCB_GROUP* childGroup = findBoardGroup( memberGroup->uuid );
2156
2157 if( !childGroup || childGroup == pcbGroup || childGroup->GetParentGroup() == pcbGroup )
2158 {
2159 continue;
2160 }
2161
2162 if( m_isDryRun )
2163 {
2164 msg.Printf( _( "Add group '%s' to group '%s'." ), EscapeHTML( childGroup->GetName() ),
2165 EscapeHTML( pcbGroup->GetName() ) );
2166 }
2167 else
2168 {
2169 msg.Printf( _( "Added group '%s' to group '%s'." ), EscapeHTML( childGroup->GetName() ),
2170 EscapeHTML( pcbGroup->GetName() ) );
2171 m_commit.Modify( pcbGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
2172 m_commit.Modify( childGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
2173 pcbGroup->AddItem( childGroup );
2174 }
2175
2176 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2177 }
2178 }
2179
2180 // Run after the nesting above so a child that moved to another parent is already there.
2181 // The netlist does not describe board-only members, so only a child group it knows about
2182 // can be said to have left its parent.
2183 for( PCB_GROUP* childGroup : m_board->Groups() )
2184 {
2185 NETLIST_GROUP* childNetlistGroup = aNetlist.GetGroupByUuid( childGroup->m_Uuid );
2186
2187 if( !childNetlistGroup || !childGroup->GetParentGroup() )
2188 continue;
2189
2190 PCB_GROUP* parentGroup = static_cast<PCB_GROUP*>( childGroup->GetParentGroup() );
2191 NETLIST_GROUP* parentNetlistGroup = aNetlist.GetGroupByUuid( parentGroup->m_Uuid );
2192
2193 if( !parentNetlistGroup )
2194 continue;
2195
2196 const std::vector<KIID_PATH>& members = parentNetlistGroup->members;
2197
2198 if( std::find( members.begin(), members.end(), childNetlistGroup->path ) != members.end() )
2199 continue;
2200
2201 if( m_isDryRun )
2202 {
2203 msg.Printf( _( "Remove group '%s' from group '%s'." ), EscapeHTML( childGroup->GetName() ),
2204 EscapeHTML( parentGroup->GetName() ) );
2205 }
2206 else
2207 {
2208 msg.Printf( _( "Removed group '%s' from group '%s'." ), EscapeHTML( childGroup->GetName() ),
2209 EscapeHTML( parentGroup->GetName() ) );
2210 m_commit.Modify( parentGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
2211 m_commit.Modify( childGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
2212 parentGroup->RemoveItem( childGroup );
2213 }
2214
2215 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2216 }
2217
2218 return true;
2219}
2220
2221
2223 std::map<COMPONENT*, FOOTPRINT*>& aFootprintMap )
2224{
2225 // Verify that board contains all pads in netlist: if it doesn't then footprints are
2226 // wrong or missing.
2227
2228 wxString msg;
2229 wxString padNumber;
2230
2231 for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
2232 {
2233 COMPONENT* component = aNetlist.GetComponent( i );
2234 FOOTPRINT* footprint = aFootprintMap[component];
2235
2236 if( !footprint ) // It can be missing in partial designs
2237 continue;
2238
2239 // Explore all pins/pads in component
2240 for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
2241 {
2242 padNumber = component->GetNet( jj ).GetPinName();
2243
2244 if( padNumber.IsEmpty() )
2245 {
2246 // bad symbol, report error
2247 msg.Printf( _( "Symbol %s has pins with no number. These pins can not be matched "
2248 "to pads in %s." ),
2249 component->GetReference(),
2250 EscapeHTML( footprint->GetFPID().Format().wx_str() ) );
2251 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
2252 ++m_errorCount;
2253 }
2254 else if( !footprint->FindPadByNumber( padNumber ) )
2255 {
2256 // not found: bad footprint, report error
2257 msg.Printf( _( "%s pad %s not found in %s." ),
2258 component->GetReference(),
2259 EscapeHTML( padNumber ),
2260 EscapeHTML( footprint->GetFPID().Format().wx_str() ) );
2261 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
2262 ++m_errorCount;
2263 }
2264 }
2265 }
2266
2267 return true;
2268}
2269
2270
2272{
2273 FOOTPRINT* lastPreexistingFootprint = nullptr;
2274 COMPONENT* component = nullptr;
2275 wxString msg;
2276 std::unordered_set<wxString> sheetPaths;
2277 std::unordered_set<FOOTPRINT*> usedFootprints;
2278
2279 m_errorCount = 0;
2280 m_warningCount = 0;
2282
2283 std::map<COMPONENT*, FOOTPRINT*> footprintMap;
2284
2285 if( !m_board->Footprints().empty() )
2286 lastPreexistingFootprint = m_board->Footprints().back();
2287
2289
2290 // First mark all nets (except <no net>) as stale; we'll update those which are current
2291 // in the following two loops. Also prepare the component class manager for updates.
2292 //
2293 if( !m_isDryRun )
2294 {
2295 for( NETINFO_ITEM* net : m_board->GetNetInfo() )
2296 net->SetIsCurrent( net->GetNetCode() == 0 );
2297
2298 m_board->GetComponentClassManager().InitNetlistUpdate();
2299 }
2300
2301 // Collect all schematic net names so NC pad deduplication can avoid collisions
2302 for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
2303 {
2304 COMPONENT* comp = aNetlist.GetComponent( ii );
2305
2306 for( unsigned jj = 0; jj < comp->GetNetCount(); jj++ )
2307 m_schematicNetNames.insert( comp->GetNet( jj ).GetNetName() );
2308 }
2309
2310 // Next go through the netlist updating all board footprints which have matching component
2311 // entries and adding new footprints for those that don't.
2312 //
2313 for( unsigned i = 0; i < aNetlist.GetCount(); i++ )
2314 {
2315 component = aNetlist.GetComponent( i );
2316
2317 if( component->GetProperties().count( wxT( "exclude_from_board" ) ) )
2318 continue;
2319
2320 msg.Printf( _( "Processing symbol '%s:%s'." ),
2321 component->GetReference(),
2322 EscapeHTML( component->GetFPID().Format().wx_str() ) );
2323 m_reporter->Report( msg, RPT_SEVERITY_INFO );
2324
2325 const LIB_ID& baseFpid = component->GetFPID();
2326 const bool hasBaseFpid = !baseFpid.empty();
2327
2328 if( baseFpid.IsLegacy() )
2329 {
2330 msg.Printf( _( "Warning: %s footprint '%s' is missing a library name. "
2331 "Use the full 'Library:Footprint' format to avoid repeated update "
2332 "notifications." ),
2333 component->GetReference(),
2334 EscapeHTML( baseFpid.Format().wx_str() ) );
2335 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
2337 }
2338
2339 std::vector<FOOTPRINT*> matchingFootprints;
2340
2341 for( FOOTPRINT* footprint : m_board->Footprints() )
2342 {
2343 bool match = false;
2344
2346 {
2347 for( const KIID& uuid : component->GetKIIDs() )
2348 {
2349 KIID_PATH base = component->GetPath();
2350 base.push_back( uuid );
2351
2352 if( footprint->GetPath() == base )
2353 {
2354 match = true;
2355 break;
2356 }
2357 }
2358 }
2359 else
2360 {
2361 match = footprint->GetReference().CmpNoCase( component->GetReference() ) == 0;
2362 }
2363
2364 if( match )
2365 {
2366 if( footprint->IsBoardOnly() )
2367 {
2368 msg.Printf( _( "Found a footprint matching %s, but the footprint's 'Not in schematic' "
2369 "flag indicates there should be no matching symbol." ),
2370 component->GetReference() );
2371 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
2373 }
2374 else
2375 {
2376 matchingFootprints.push_back( footprint );
2377 }
2378 }
2379
2380 if( footprint == lastPreexistingFootprint )
2381 {
2382 // No sense going through the newly-created footprints: end of loop
2383 break;
2384 }
2385 }
2386
2387 std::vector<LIB_ID> expectedFpids;
2388 std::unordered_set<wxString> expectedFpidKeys;
2389
2390 auto addExpectedFpid =
2391 [&]( const LIB_ID& aFpid )
2392 {
2393 if( aFpid.empty() )
2394 return;
2395
2396 wxString key = aFpid.Format();
2397
2398 if( expectedFpidKeys.insert( key ).second )
2399 expectedFpids.push_back( aFpid );
2400 };
2401
2402 addExpectedFpid( baseFpid );
2403
2404 const wxString footprintFieldName = GetDefaultFieldName( FIELD_T::FOOTPRINT, UNTRANSLATED );
2405
2406 for( const auto& [variantName, variant] : component->GetVariants() )
2407 {
2408 auto fieldIt = variant.m_fields.find( footprintFieldName );
2409
2410 if( fieldIt == variant.m_fields.end() || fieldIt->second.IsEmpty() )
2411 continue;
2412
2413 LIB_ID parsedId;
2414
2415 if( parsedId.Parse( fieldIt->second, true ) >= 0 )
2416 {
2417 msg.Printf( _( "Invalid footprint ID '%s' for variant '%s' on %s." ),
2418 EscapeHTML( fieldIt->second ),
2419 variantName,
2420 component->GetReference() );
2421 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
2422 ++m_errorCount;
2423 continue;
2424 }
2425
2426 addExpectedFpid( parsedId );
2427 }
2428
2429 auto isExpectedFpid =
2430 [&]( const LIB_ID& aFpid ) -> bool
2431 {
2432 if( aFpid.empty() )
2433 return false;
2434
2435 if( expectedFpidKeys.count( aFpid.Format() ) > 0 )
2436 return true;
2437
2438 for( const LIB_ID& expected : expectedFpids )
2439 {
2440 if( fpidsEquivalent( aFpid, expected ) )
2441 return true;
2442 }
2443
2444 return false;
2445 };
2446
2447 auto takeMatchingFootprint =
2448 [&]( const LIB_ID& aFpid ) -> FOOTPRINT*
2449 {
2450 for( FOOTPRINT* footprint : matchingFootprints )
2451 {
2452 if( usedFootprints.count( footprint ) )
2453 continue;
2454
2455 if( fpidsEquivalent( footprint->GetFPID(), aFpid ) )
2456 return footprint;
2457 }
2458
2459 return nullptr;
2460 };
2461
2462 std::vector<FOOTPRINT*> componentFootprints;
2463 componentFootprints.reserve( expectedFpids.size() );
2464 FOOTPRINT* baseFootprint = nullptr;
2465
2466 if( hasBaseFpid )
2467 baseFootprint = takeMatchingFootprint( baseFpid );
2468 else if( !matchingFootprints.empty() )
2469 baseFootprint = matchingFootprints.front();
2470
2471 if( !baseFootprint && m_replaceFootprints && !matchingFootprints.empty() )
2472 {
2473 FOOTPRINT* replaceCandidate = nullptr;
2474
2475 for( FOOTPRINT* footprint : matchingFootprints )
2476 {
2477 if( usedFootprints.count( footprint ) )
2478 continue;
2479
2480 if( isExpectedFpid( footprint->GetFPID() ) )
2481 continue;
2482
2483 replaceCandidate = footprint;
2484 break;
2485 }
2486
2487 if( replaceCandidate )
2488 {
2489 FOOTPRINT* replaced = replaceFootprint( aNetlist, replaceCandidate, component );
2490
2491 if( replaced )
2492 baseFootprint = replaced;
2493 else
2494 baseFootprint = replaceCandidate;
2495 }
2496 }
2497
2498 if( !baseFootprint && !m_replaceFootprints )
2499 {
2500 for( FOOTPRINT* footprint : matchingFootprints )
2501 {
2502 if( usedFootprints.count( footprint ) )
2503 continue;
2504
2505 if( isExpectedFpid( footprint->GetFPID() ) )
2506 continue;
2507
2508 baseFootprint = footprint;
2509 break;
2510 }
2511 }
2512
2513 if( !baseFootprint && ( hasBaseFpid || expectedFpids.empty() ) )
2514 baseFootprint = addNewFootprint( component, baseFpid );
2515
2516 if( baseFootprint )
2517 {
2518 componentFootprints.push_back( baseFootprint );
2519 usedFootprints.insert( baseFootprint );
2520 footprintMap[ component ] = baseFootprint;
2521 }
2522
2523 for( const LIB_ID& fpid : expectedFpids )
2524 {
2525 // Both IDs are schematic-derived, so either side may be legacy; compare in both
2526 // directions so a bare base name and a qualified variant name for the same
2527 // footprint are not split into a duplicate.
2528 if( fpidsEquivalent( fpid, baseFpid ) || fpidsEquivalent( baseFpid, fpid ) )
2529 continue;
2530
2531 FOOTPRINT* footprint = takeMatchingFootprint( fpid );
2532
2533 if( !footprint )
2534 footprint = addNewFootprint( component, fpid );
2535
2536 if( footprint )
2537 {
2538 componentFootprints.push_back( footprint );
2539 usedFootprints.insert( footprint );
2540 }
2541 }
2542
2543 for( FOOTPRINT* footprint : componentFootprints )
2544 {
2545 if( !footprint )
2546 continue;
2547
2548 updateFootprintParameters( footprint, component );
2549 updateFootprintGroup( footprint, component );
2550 updateComponentPadConnections( footprint, component );
2551 updateComponentClass( footprint, component );
2552 updateComponentUnits( footprint, component );
2553
2554 sheetPaths.insert( footprint->GetSheetname() );
2555 }
2556
2557 if( !componentFootprints.empty() )
2558 applyComponentVariants( component, componentFootprints, baseFpid );
2559 }
2560
2561 updateCopperZoneNets( aNetlist );
2562 updateGroups( aNetlist );
2563
2564 // Finally go through the board footprints and update all those that *don't* have matching
2565 // component entries.
2566 //
2567 for( FOOTPRINT* footprint : m_board->Footprints() )
2568 {
2569 bool matched = false;
2570 bool doDelete = m_deleteUnusedFootprints;
2571
2572 bool isStaleVariantFootprint = false;
2573
2574 if( usedFootprints.count( footprint ) )
2575 {
2576 matched = true;
2577 }
2578 else
2579 {
2581 component = aNetlist.GetComponentByPath( footprint->GetPath() );
2582 else
2583 component = aNetlist.GetComponentByReference( footprint->GetReference() );
2584
2585 if( component && component->GetProperties().count( wxT( "exclude_from_board" ) ) == 0 )
2586 {
2587 // When replace footprints is enabled and a component has variant footprints,
2588 // footprints matching by reference but not in usedFootprints are stale variant
2589 // footprints that should be replaced/removed.
2590 if( m_replaceFootprints && !component->GetVariants().empty() )
2591 {
2592 matched = false;
2593 isStaleVariantFootprint = true;
2594 }
2595 else
2596 {
2597 matched = true;
2598 }
2599 }
2600 }
2601
2602 // Stale variant footprints should be deleted when m_replaceFootprints is enabled,
2603 // regardless of m_deleteUnusedFootprints setting.
2604 if( isStaleVariantFootprint )
2605 doDelete = true;
2606
2607 if( ( footprint->GetAttributes() & FP_BOARD_ONLY ) > 0 )
2608 doDelete = false;
2609
2610 if( doDelete && !matched && footprint->IsLocked() && !m_overrideLocks )
2611 {
2612 if( m_isDryRun )
2613 {
2614 msg.Printf( _( "Cannot remove unused footprint %s (footprint is locked)." ),
2615 footprint->GetReference() );
2616 }
2617 else
2618 {
2619 msg.Printf( _( "Could not remove unused footprint %s (footprint is locked)." ),
2620 footprint->GetReference() );
2621 }
2622
2623 m_reporter->Report( msg, RPT_SEVERITY_WARNING );
2625 doDelete = false;
2626 }
2627
2628 if( doDelete && !matched )
2629 {
2630 if( m_isDryRun )
2631 {
2632 msg.Printf( _( "Remove unused footprint %s." ),
2633 footprint->GetReference() );
2634 }
2635 else
2636 {
2637 m_commit.Remove( footprint );
2638 msg.Printf( _( "Removed unused footprint %s." ),
2639 footprint->GetReference() );
2640 }
2641
2642 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2643 }
2644 else if( !m_isDryRun )
2645 {
2646 if( !matched )
2647 footprint->SetPath( KIID_PATH() );
2648
2649 for( PAD* pad : footprint->Pads() )
2650 {
2651 if( pad->GetNet() )
2652 pad->GetNet()->SetIsCurrent( true );
2653 }
2654 }
2655 }
2656
2657 if( !m_isDryRun )
2658 {
2659 m_board->ClearNetChainColors();
2660
2661 // Finalise the component class manager
2662 m_board->GetComponentClassManager().FinishNetlistUpdate();
2663 m_board->SynchronizeComponentClasses( sheetPaths );
2664
2665 m_board->BuildConnectivity();
2666 testConnectivity( aNetlist, footprintMap );
2667
2668 for( NETINFO_ITEM* net : m_board->GetNetInfo() )
2669 {
2670 if( !net->IsCurrent() )
2671 {
2672 msg.Printf( _( "Removed unused net %s." ), EscapeHTML( net->GetNetname() ) );
2673 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2674 }
2675 }
2676
2677 m_board->RemoveUnusedNets( &m_commit );
2678
2679 // Update board variant registry from netlist
2680 const std::vector<wxString>& netlistVariants = aNetlist.GetVariantNames();
2681
2682 if( !netlistVariants.empty() || !m_board->GetVariantNames().empty() )
2683 {
2684 m_reporter->Report( _( "Updating design variants..." ), RPT_SEVERITY_INFO );
2685
2686 auto findBoardVariantName =
2687 [&]( const wxString& aVariantName ) -> wxString
2688 {
2689 for( const wxString& name : m_board->GetVariantNames() )
2690 {
2691 if( name.CmpNoCase( aVariantName ) == 0 )
2692 return name;
2693 }
2694
2695 return wxEmptyString;
2696 };
2697
2698 std::vector<wxString> updatedVariantNames;
2699 updatedVariantNames.reserve( netlistVariants.size() );
2700
2701 for( const wxString& variantName : netlistVariants )
2702 {
2703 wxString actualName = findBoardVariantName( variantName );
2704
2705 if( actualName.IsEmpty() )
2706 {
2707 m_board->AddVariant( variantName );
2708 actualName = findBoardVariantName( variantName );
2709
2710 if( !actualName.IsEmpty() )
2711 {
2712 msg.Printf( _( "Added variant '%s'." ), actualName );
2713 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2714 }
2715 }
2716
2717 if( actualName.IsEmpty() )
2718 continue;
2719
2720 // Update description if changed
2721 wxString newDescription = aNetlist.GetVariantDescription( variantName );
2722 wxString oldDescription = m_board->GetVariantDescription( actualName );
2723
2724 if( newDescription != oldDescription )
2725 {
2726 m_board->SetVariantDescription( actualName, newDescription );
2727 msg.Printf( _( "Updated description for variant '%s'." ), actualName );
2728 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2729 }
2730
2731 updatedVariantNames.push_back( actualName );
2732 }
2733
2734 std::vector<wxString> variantsToRemove;
2735
2736 for( const wxString& existingName : m_board->GetVariantNames() )
2737 {
2738 bool found = false;
2739
2740 for( const wxString& variantName : netlistVariants )
2741 {
2742 if( existingName.CmpNoCase( variantName ) == 0 )
2743 {
2744 found = true;
2745 break;
2746 }
2747 }
2748
2749 if( !found )
2750 variantsToRemove.push_back( existingName );
2751 }
2752
2753 for( const wxString& variantName : variantsToRemove )
2754 {
2755 m_board->DeleteVariant( variantName );
2756 msg.Printf( _( "Removed variant '%s'." ), variantName );
2757 m_reporter->Report( msg, RPT_SEVERITY_ACTION );
2758 }
2759
2760 if( !updatedVariantNames.empty() )
2761 m_board->SetVariantNames( updatedVariantNames );
2762 }
2763
2764 // When new footprints are added, the automatic zone refill is disabled because:
2765 // * it creates crashes when calculating dynamic ratsnests if auto refill is enabled.
2766 // (the auto refills rebuild the connectivity with incomplete data)
2767 // * it is useless because zones will be refilled after placing new footprints
2768 m_commit.Push( _( "Update Netlist" ), m_newFootprintsCount ? ZONE_FILL_OP : 0 );
2769
2770 m_board->GetConnectivity()->RefreshNetcodeMap( m_board );
2771
2772 // Netlist is authoritative for chain assignment, so the terminal-pin reapplication
2773 // below starts from a clean slate.
2775
2776 // Net chains may specify a display colour override; lift that into the
2777 // board-side lookup so the PCB painter can use it when highlighting.
2778 for( const auto& [chain, colorStr] : aNetlist.GetNetChainColors() )
2779 {
2780 if( !colorStr.IsEmpty() )
2781 {
2782 KIGFX::COLOR4D color;
2783
2784 if( color.SetFromHexString( colorStr ) )
2785 m_board->SetNetChainColor( chain, color );
2786 }
2787 }
2788
2789 ApplyChainNetclasses( m_board, aNetlist );
2790
2791 // Always resync after chain cleanup so existing NETINFO_ITEM effective-netclass
2792 // pointers pick up cleared/changed chain entries even when no chain carries a netclass.
2793 m_board->SynchronizeNetsAndNetClasses( true );
2794
2795 for( const auto& [chain, terminalPins] : aNetlist.GetNetChainTerminalPins() )
2796 {
2797 PAD* pads[2] = { nullptr, nullptr };
2798
2799 for( size_t i = 0; i < terminalPins.size() && i < 2; ++i )
2800 {
2801 const wxString& ref = terminalPins[i].first;
2802 const wxString& pin = terminalPins[i].second;
2803 FOOTPRINT* fp = m_board->FindFootprintByReference( ref );
2804
2805 if( !fp )
2806 continue;
2807
2808 PAD* candidate = nullptr;
2809 PAD* best = nullptr;
2810 int bestDist = std::numeric_limits<int>::max();
2811 BOX2I bbox = fp->GetBoundingBox();
2812
2813 while( ( candidate = fp->FindPadByNumber( pin, candidate ) ) )
2814 {
2815 VECTOR2I pos = candidate->GetPosition();
2816 int dist = std::min( { pos.x - bbox.GetLeft(), bbox.GetRight() - pos.x,
2817 pos.y - bbox.GetTop(), bbox.GetBottom() - pos.y } );
2818
2819 if( !best || dist < bestDist || ( dist == bestDist && candidate->m_Uuid < best->m_Uuid ) )
2820 {
2821 best = candidate;
2822 bestDist = dist;
2823 }
2824 }
2825
2826 pads[i] = best;
2827 }
2828
2829 for( int i = 0; i < 2; ++i )
2830 {
2831 if( !pads[i] )
2832 continue;
2833
2834 NETINFO_ITEM* termNet = pads[i]->GetNet();
2835
2836 if( !termNet || termNet->GetNetChain() != chain )
2837 continue;
2838
2839 for( NETINFO_ITEM* net : m_board->GetNetInfo() )
2840 {
2841 if( net != termNet && net->GetNetChain() == chain && net->GetTerminalPad( i ) )
2842 net->ClearTerminalPad( i );
2843 }
2844
2845 termNet->SetTerminal( i, pads[i] );
2846 }
2847 }
2848
2849 // Although m_commit will probably also set this, it's not guaranteed, and we need to make
2850 // sure any modification to netclasses gets persisted to project settings through a save.
2851 if( m_frame )
2852 m_frame->OnModify();
2853 }
2854
2855 if( m_isDryRun )
2856 {
2857 for( const std::pair<const wxString, NETINFO_ITEM*>& addedNet : m_addedNets )
2858 delete addedNet.second;
2859
2860 m_addedNets.clear();
2861 }
2862
2863 // Update the ratsnest
2864 m_reporter->ReportTail( wxT( "" ), RPT_SEVERITY_ACTION );
2865 m_reporter->ReportTail( wxT( "" ), RPT_SEVERITY_ACTION );
2866
2867 msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
2868 m_reporter->ReportTail( msg, RPT_SEVERITY_INFO );
2869
2870 return true;
2871}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
#define ZONE_FILL_OP
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
std::shared_ptr< NET_SETTINGS > m_NetSettings
bool IsLocked() const override
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
std::map< PAD *, wxString > m_padNets
void cacheNetname(PAD *aPad, const wxString &aNetname)
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
wxString getPinFunction(PAD *aPad)
std::vector< FOOTPRINT * > m_addedFootprints
bool updateFootprintParameters(FOOTPRINT *aFootprint, COMPONENT *aNetlistComponent)
std::map< wxString, wxString > m_oldToNewNets
static void ApplyChainAssignments(BOARD *aBoard, const NETLIST &aNetlist, REPORTER *aReporter, bool aDryRun)
Apply the netlist's chain assignments to every NETINFO_ITEM on the board.
static void ApplyChainNetclasses(BOARD *aBoard, const NETLIST &aNetlist)
Mirror the netlist's chain-to-class and chain-to-netclass maps into the project's NET_SETTINGS.
bool updateFootprintGroup(FOOTPRINT *aPcbFootprint, COMPONENT *aNetlistComponent)
static bool fpidsEquivalent(const LIB_ID &aBoardFpid, const LIB_ID &aSchematicFpid)
Compare a board footprint ID against a schematic-derived footprint ID, ignoring the library nickname ...
PCB_GROUP * addBoardGroup(const NETLIST_GROUP &aNetlistGroup)
std::map< wxString, NETINFO_ITEM * > m_addedNets
std::vector< PCB_GROUP * > m_addedGroups
bool testConnectivity(NETLIST &aNetlist, std::map< COMPONENT *, FOOTPRINT * > &aFootprintMap)
bool updateCopperZoneNets(NETLIST &aNetlist)
void cachePinFunction(PAD *aPad, const wxString &aPinFunction)
bool updateGroups(NETLIST &aNetlist)
BOARD_NETLIST_UPDATER(PCB_EDIT_FRAME *aFrame, BOARD *aBoard)
Construct an updater for interactive use from the board editor.
bool updateComponentClass(FOOTPRINT *aFootprint, COMPONENT *aNewComponent)
bool updateComponentPadConnections(FOOTPRINT *aFootprint, COMPONENT *aNewComponent)
std::map< PAD *, wxString > m_padPinFunctions
void applyComponentVariants(COMPONENT *aComponent, const std::vector< FOOTPRINT * > &aFootprints, const LIB_ID &aBaseFpid)
std::map< ZONE *, std::vector< PAD * > > m_zoneConnectionsCache
FOOTPRINT * replaceFootprint(NETLIST &aNetlist, FOOTPRINT *aFootprint, COMPONENT *aNewComponent)
bool updateComponentUnits(FOOTPRINT *aFootprint, COMPONENT *aNewComponent)
FOOTPRINT * addNewFootprint(COMPONENT *aComponent)
std::set< wxString > m_schematicNetNames
PCB_GROUP * findBoardGroup(const KIID &aUuid) const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr Vec Centre() const
Definition box2.h:100
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr coord_type GetBottom() const
Definition box2.h:225
static wxString GetFullClassNameForConstituents(const std::unordered_set< wxString > &classNames)
Gets the full effective class name for the given set of constituent classes.
A lightweight representation of a component class.
const wxString & GetName() const
Fetches the full name of this component class.
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
const wxString & GetNetName() const
const wxString & GetPinFunction() const
const wxString & GetPinName() const
const wxString & GetPinType() const
Store all of the related component information found in a netlist.
const std::vector< UNIT_INFO > & GetUnitInfo() const
const wxString & GetHumanReadablePath() const
const COMPONENT_NET & GetNet(unsigned aIndex) const
const KIID_PATH & GetPath() const
const wxString & GetReference() const
const wxString & GetValue() const
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
const std::map< wxString, wxString > & GetProperties() const
const CASE_INSENSITIVE_MAP< COMPONENT_VARIANT > & GetVariants() const
NETLIST_GROUP * GetGroup() const
const std::vector< KIID > & GetKIIDs() const
bool GetDuplicatePadNumbersAreJumpers() const
const LIB_ID & GetFPID() const
unsigned GetNetCount() const
std::unordered_set< wxString > & GetComponentClassNames()
JUMPER_GROUP_SET & JumperPadGroups()
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:78
wxString GetName() const
Definition eda_group.h:75
void RemoveAll()
Definition eda_group.cpp:86
void RemoveItem(EDA_ITEM *aItem)
Remove item from group.
Definition eda_group.cpp:77
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
Variant information for a footprint.
Definition footprint.h:178
bool HasFieldValue(const wxString &aFieldName) const
Definition footprint.h:237
wxString GetFieldValue(const wxString &aFieldName) const
Get a field value override for this variant.
Definition footprint.h:209
bool GetExcludedFromSim() const
Definition footprint.h:198
bool GetExcludedFromBOM() const
Definition footprint.h:195
bool GetExcludedFromPosFiles() const
Definition footprint.h:201
void RemoveFieldValue(const wxString &aFieldName)
Remove a field value override for this variant.
Definition footprint.h:232
bool GetDNP() const
Definition footprint.h:192
bool GetDuplicatePadNumbersAreJumpers() const
Definition footprint.h:1133
void SetPosition(const VECTOR2I &aPos) override
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
wxString GetSheetname() const
Definition footprint.h:469
void SetPath(const KIID_PATH &aPath)
Definition footprint.h:456
void SetFilters(const wxString &aFilters)
Definition footprint.h:476
void SetStaticComponentClass(const COMPONENT_CLASS *aClass) const
Sets the component class object pointer for this footprint.
const std::vector< FP_UNIT_INFO > & GetUnitInfo() const
Definition footprint.h:909
void SetAttributes(int aAttributes)
Definition footprint.h:510
void SetSheetfile(const wxString &aSheetfile)
Definition footprint.h:473
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetDuplicatePadNumbersAreJumpers(bool aEnabled)
Definition footprint.h:1134
bool HasField(const wxString &aFieldName) const
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
std::deque< PAD * > & Pads()
Definition footprint.h:355
int GetAttributes() const
Definition footprint.h:509
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition footprint.h:393
wxString GetFPIDAsString() const
Definition footprint.h:419
wxString GetSheetfile() const
Definition footprint.h:472
const LIB_ID & GetFPID() const
Definition footprint.h:417
void SetReference(const wxString &aReference)
Definition footprint.h:799
void SetValue(const wxString &aValue)
Definition footprint.h:822
JUMPER_GROUP_SET & JumperPadGroups()
Each jumper pad group is a set of pad numbers that should be treated as internally connected.
Definition footprint.h:1140
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
void SetUnitInfo(const std::vector< FP_UNIT_INFO > &aUnits)
Definition footprint.h:908
wxString GetFilters() const
Definition footprint.h:475
void SetSheetname(const wxString &aSheetname)
Definition footprint.h:470
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
const wxString & GetValue() const
Definition footprint.h:817
const COMPONENT_CLASS * GetStaticComponentClass() const
Returns the component class for this footprint.
void FixUpPadsForBoard(BOARD *aBoard)
Used post-loading of a footprint to adjust the layers on pads to match board inner layers.
const wxString & GetReference() const
Definition footprint.h:793
const KIID_PATH & GetPath() const
Definition footprint.h:455
VECTOR2I GetPosition() const override
Definition footprint.h:379
PAD * FindPadByNumber(const wxString &aPadNumber, PAD *aSearchAfterMe=nullptr) const
Return a PAD with a matching number.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
bool SetFromHexString(const wxString &aColorString)
Definition color4d.cpp:176
wxString AsString() const
Definition kiid.cpp:423
Definition kiid.h:46
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
bool empty() const
Definition lib_id.h:189
wxString GetUniStringLibId() const
Definition lib_id.h:144
UTF8 Format() const
Definition lib_id.cpp:132
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
bool IsLegacy() const
Definition lib_id.h:176
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetChain() const
Definition netinfo.h:122
void SetTerminal(int aIndex, PAD *aPad)
Set the terminal-pad pointer and the persisted UUID at aIndex from a single pad, keeping the two view...
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:160
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:281
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
const std::map< wxString, std::vector< std::pair< wxString, wxString > > > & GetNetChainTerminalPins() const
NETLIST_GROUP * GetParentGroup(const KIID_PATH &aMemberPath)
Return the NETLIST_GROUP that lists aMemberPath among its members.
const std::vector< wxString > & GetVariantNames() const
unsigned GetCount() const
COMPONENT * GetComponentByPath(const KIID_PATH &aPath)
Return a COMPONENT by aPath.
COMPONENT * GetComponentByReference(const wxString &aReference)
Return a COMPONENT by aReference.
const std::map< wxString, wxString > & GetNetChainNetClasses() const
const std::map< wxString, wxString > & GetSignalChainClasses() const
NETLIST_GROUP * GetGroupByUuid(const KIID &aUuid)
Return a NETLIST_GROUP by aUuid.
const std::map< wxString, wxString > & GetNetChainColors() const
NETLIST_GROUP * GetGroupByPath(const KIID_PATH &aPath)
Return a NETLIST_GROUP by aPath.
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
wxString GetNetChainFor(const wxString &aNet) const
wxString GetVariantDescription(const wxString &aVariantName) const
A singleton reporter that reports to nowhere.
Definition reporter.h:267
Definition pad.h:61
const wxString & GetPinFunction() const
Definition pad.h:154
VECTOR2I GetPosition() const override
Definition pad.cpp:255
The main frame for Pcbnew.
void SetName(const wxString &aName)
Definition pcb_field.h:121
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
EDA_ITEM * AsEdaItem() override
Definition pcb_group.h:59
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
Definition pcb_text.cpp:373
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_text.h:103
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition pcb_text.cpp:585
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
Master controller class:
wxString wx_str() const
Definition utf8.cpp:41
Handle a list of polygons defining a copper zone.
Definition zone.h:70
#define _(s)
@ NO_RECURSE
Definition eda_item.h:52
@ FP_DNP
Definition footprint.h:92
@ FP_EXCLUDE_FROM_POS_FILES
Definition footprint.h:88
@ FP_BOARD_ONLY
Definition footprint.h:90
@ FP_EXCLUDE_FROM_BOM
Definition footprint.h:89
@ FP_JUST_ADDED
Definition footprint.h:91
@ FP_EXCLUDE_FROM_SIM
Definition footprint.h:93
@ F_Fab
Definition layer_ids.h:115
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
KICOMMON_API wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
Class to handle a set of BOARD_ITEMs.
FOOTPRINT * LoadFootprintFromProject(BOARD *aBoard, const LIB_ID &aFootprintId, bool aKeepUuid)
Load a footprint from the project library table and apply board default settings.
CITER next(CITER it)
Definition ptree.cpp:120
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
T * GetAppSettings(const char *aFilename)
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
wxString UnescapeString(const wxString &aSource)
bool m_hasExcludedFromPosFiles
nlohmann::ordered_map< wxString, wxString > m_fields
KIID_PATH path
std::vector< KIID > members
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
KIBIS_COMPONENT * comp
KIBIS_PIN * pin
VECTOR3I expected(15, 30, 45)
static std::string netlistValue(const SEXPR::SEXPR &aNode, const std::string &aHead)
const SHAPE_LINE_CHAIN chain
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708