KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_footprint_field_reconciler.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <lib_id.h>
23#include <reporter.h>
24#include <schematic.h>
25#include <sch_screen.h>
26#include <sch_symbol.h>
27
28
30 const wxString& aCacheNickname, const std::vector<wxString>& aSourceLibNicknames,
31 REPORTER* aReporter ) :
32 m_cacheNickname( aCacheNickname ),
33 m_sourceLibs( aSourceLibNicknames.begin(), aSourceLibNicknames.end() ),
34 m_reporter( aReporter )
35{
36}
37
38
40{
42
43 // no cache nickname = no project lib to point fields at
44 if( m_cacheNickname.IsEmpty() )
45 return result;
46
47 SCH_SCREENS screens( aSchematic.Root() );
48
49 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
50 {
51 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
52 {
53 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
54 const wxString& fpText = symbol->GetField( FIELD_T::FOOTPRINT )->GetText();
55
56 if( fpText.IsEmpty() )
57 continue;
58
59 LIB_ID fpid;
60
61 if( fpid.Parse( fpText ) >= 0 )
62 continue; // malformed FPID, leave untouched
63
64 if( fpid.GetUniStringLibItemName().IsEmpty() )
65 continue;
66
67 wxString nick = fpid.GetUniStringLibNickname();
68
69 // field already on a registered source lib resolves there
70 if( !nick.IsEmpty() && m_sourceLibs.count( nick ) )
71 {
72 result.m_keptSource++;
73 continue;
74 }
75
77 symbol->SetFootprintFieldText( fpid.Format().wx_str() );
78 result.m_relinkedToCache++;
79 }
80 }
81
82 if( m_reporter && result.m_relinkedToCache > 0 )
83 {
84 m_reporter->Report(
85 wxString::Format( _( "Re-linked %d imported footprint assignment(s) to library "
86 "'%s'." ),
87 result.m_relinkedToCache, m_cacheNickname ),
89 }
90
91 return result;
92}
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
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition lib_id.cpp:113
UTF8 Format() const
Definition lib_id.cpp:132
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition lib_id.h:108
const wxString GetUniStringLibNickname() const
Definition lib_id.h:84
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:72
Holds all the data relating to one schematic.
Definition schematic.h:90
SCH_SHEET & Root() const
Definition schematic.h:134
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:128
SCH_FOOTPRINT_FIELD_RECONCILER(const wxString &aCacheNickname, const std::vector< wxString > &aSourceLibNicknames, REPORTER *aReporter=nullptr)
SCH_FP_FIELD_RECONCILE_RESULT Reconcile(SCHEMATIC &aSchematic)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:746
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Schematic symbol object.
Definition sch_symbol.h:69
void SetFootprintFieldText(const wxString &aFootprint)
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
wxString wx_str() const
Definition utf8.cpp:41
#define _(s)
@ RPT_SEVERITY_INFO
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
@ SCH_SYMBOL_T
Definition typeinfo.h:169