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
20
#include "
sch_footprint_field_reconciler.h
"
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
29
SCH_FOOTPRINT_FIELD_RECONCILER::SCH_FOOTPRINT_FIELD_RECONCILER
(
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
39
SCH_FP_FIELD_RECONCILE_RESULT
SCH_FOOTPRINT_FIELD_RECONCILER::Reconcile
(
SCHEMATIC
& aSchematic )
40
{
41
SCH_FP_FIELD_RECONCILE_RESULT
result
;
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
76
fpid.
SetLibNickname
(
m_cacheNickname
);
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
),
88
RPT_SEVERITY_INFO
);
89
}
90
91
return
result
;
92
}
LIB_ID
A logical library item identifier and consists of various portions much like a URI.
Definition
lib_id.h:45
LIB_ID::Parse
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition
lib_id.cpp:65
LIB_ID::SetLibNickname
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition
lib_id.cpp:113
LIB_ID::Format
UTF8 Format() const
Definition
lib_id.cpp:132
LIB_ID::GetUniStringLibItemName
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition
lib_id.h:108
LIB_ID::GetUniStringLibNickname
const wxString GetUniStringLibNickname() const
Definition
lib_id.h:84
REPORTER
A pure virtual class used to derive REPORTER objects from.
Definition
reporter.h:72
SCHEMATIC
Holds all the data relating to one schematic.
Definition
schematic.h:90
SCHEMATIC::Root
SCH_SHEET & Root() const
Definition
schematic.h:134
SCH_FIELD::GetText
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition
sch_field.h:128
SCH_FOOTPRINT_FIELD_RECONCILER::m_reporter
REPORTER * m_reporter
Definition
sch_footprint_field_reconciler.h:54
SCH_FOOTPRINT_FIELD_RECONCILER::SCH_FOOTPRINT_FIELD_RECONCILER
SCH_FOOTPRINT_FIELD_RECONCILER(const wxString &aCacheNickname, const std::vector< wxString > &aSourceLibNicknames, REPORTER *aReporter=nullptr)
Definition
sch_footprint_field_reconciler.cpp:29
SCH_FOOTPRINT_FIELD_RECONCILER::Reconcile
SCH_FP_FIELD_RECONCILE_RESULT Reconcile(SCHEMATIC &aSchematic)
Definition
sch_footprint_field_reconciler.cpp:39
SCH_FOOTPRINT_FIELD_RECONCILER::m_sourceLibs
std::set< wxString > m_sourceLibs
Definition
sch_footprint_field_reconciler.h:53
SCH_FOOTPRINT_FIELD_RECONCILER::m_cacheNickname
wxString m_cacheNickname
Definition
sch_footprint_field_reconciler.h:52
SCH_ITEM
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition
sch_item.h:162
SCH_SCREENS
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition
sch_screen.h:746
SCH_SCREENS::GetNext
SCH_SCREEN * GetNext()
Definition
sch_screen.cpp:2072
SCH_SCREENS::GetFirst
SCH_SCREEN * GetFirst()
Definition
sch_screen.cpp:2061
SCH_SCREEN
Definition
sch_screen.h:97
SCH_SYMBOL
Schematic symbol object.
Definition
sch_symbol.h:69
SCH_SYMBOL::SetFootprintFieldText
void SetFootprintFieldText(const wxString &aFootprint)
Definition
sch_symbol.cpp:1720
SCH_SYMBOL::GetField
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition
sch_symbol.cpp:1726
UTF8::wx_str
wxString wx_str() const
Definition
utf8.cpp:41
_
#define _(s)
Definition
eda_3d_actions.cpp:36
lib_id.h
RPT_SEVERITY_INFO
@ RPT_SEVERITY_INFO
Definition
report_severity.h:31
reporter.h
sch_footprint_field_reconciler.h
sch_screen.h
sch_symbol.h
schematic.h
SCH_FP_FIELD_RECONCILE_RESULT
Definition
sch_footprint_field_reconciler.h:31
FIELD_T::FOOTPRINT
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
Definition
template_fieldnames.h:46
end
VECTOR2I end
Definition
test_shape_arc.cpp:622
result
wxString result
Test unit parsing edge cases and error handling.
Definition
test_text_eval_numeric_compat.cpp:598
SCH_SYMBOL_T
@ SCH_SYMBOL_T
Definition
typeinfo.h:169
src
eeschema
sch_footprint_field_reconciler.cpp
Generated on Sat Jul 25 2026 00:05:55 for KiCad PCB EDA Suite by
1.13.2