KiCad PCB EDA Suite
Loading...
Searching...
No Matches
backannotate.h
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) 2019 Alexander Shuklin <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <deque>
24#include <map>
25#include <set>
26#include <memory>
27#include <vector>
28#include <sch_reference_list.h>
29#include <template_fieldnames.h>
30#include <wx/string.h>
31
32// Forward declarations
33class REPORTER;
34class SCH_SHEET_LIST;
35class SCH_EDIT_FRAME;
36class SCH_COMMIT;
37
39{
40 wxString m_ref;
42 std::map<wxString, wxString> m_schNetsByPin;
43 std::vector<wxString> m_unitPinNumbers;
44};
45
47{
48 size_t m_firstIndex = 0;
49 size_t m_secondIndex = 0;
50 int m_firstUnit = 0;
51 int m_secondUnit = 0;
52};
53
55{
56 bool m_mappingOk = false;
57 bool m_identity = true;
58 std::vector<BACKANNOTATE_UNIT_SWAP_STEP> m_steps;
59 std::set<size_t> m_swappedCandidateIndices;
60};
61
68bool CollectBackannotatePcbNets( const SCH_SYMBOL& aSymbol, const SCH_SHEET_PATH& aSheetPath,
69 const wxString& aVariantName, const std::map<wxString, wxString>& aPcbNetsByPad,
70 std::map<wxString, wxString>& aPcbNetsByLogicalPin );
71
80 const std::vector<BACKANNOTATE_UNIT_SWAP_CANDIDATE>& aCandidates,
81 const std::map<wxString, wxString>& aPcbPinMap );
82
84{
85 wxString m_base;
86 wxString m_error;
87};
88
99std::vector<BACKANNOTATE_REF>
100ResolveBackannotatedRefs( const std::vector<std::pair<const SCH_REFERENCE*, wxString>>& aRequests,
101 bool aShareBases );
102
117{
118public:
123 {
124 PCB_FP_DATA( const wxString& aRef, const wxString& aFootprint, const wxString& aValue, bool aDNP,
125 bool aExcludeFromBOM, bool aExcludeFromSim, bool aExcludeFromPosFiles,
126 const std::map<wxString, wxString>& aPinMap,
127 const std::map<wxString, wxString>& aFieldsMap ) :
128 m_ref( aRef ),
129 m_footprint( aFootprint ),
130 m_value( aValue ),
131 m_DNP( aDNP ),
132 m_excludeFromBOM( aExcludeFromBOM ),
133 m_excludeFromSim( aExcludeFromSim ),
134 m_excludeFromPosFiles( aExcludeFromPosFiles ),
135 m_pinMap( aPinMap ),
136 m_fieldsMap( aFieldsMap )
137 {}
138
139 wxString m_ref;
140 wxString m_footprint;
141 wxString m_value;
142 bool m_DNP;
146 std::map<wxString, wxString> m_pinMap;
147 std::map<wxString, wxString> m_fieldsMap;
148 };
149
151 using PCB_FOOTPRINTS_MAP = std::map<wxString, std::shared_ptr<PCB_FP_DATA>>;
152
153 using CHANGELIST_ITEM = std::pair<SCH_REFERENCE, std::shared_ptr<PCB_FP_DATA>>;
154
155 BACK_ANNOTATE( SCH_EDIT_FRAME* aFrame, REPORTER& aReporter, bool aRelinkFootprints,
156 bool aProcessFootprints, bool aProcessValues, bool aProcessReferences,
157 bool aProcessNetNames, bool aProcessAttributes, bool aProcessOtherFields,
158 bool aPreferUnitSwaps, bool aPreferPinSwaps, bool aDryRun );
159
160 ~BACK_ANNOTATE() = default;
161
168 bool FetchNetlistFromPCB( std::string& aNetlist );
169
170 void PushNewLinksToPCB();
171
178 bool BackAnnotateSymbols( const std::string& aNetlist );
179
180private:
186 void getPcbModulesFromString( const std::string& aPayload );
187
189 void getChangeList();
190
197
201 void applyChangelist();
202
206 std::set<wxString> applyPinSwaps( SCH_SYMBOL* aSymbol, const SCH_REFERENCE& aReference, const PCB_FP_DATA& aFpData,
207 SCH_COMMIT* aCommit );
208
209 void processNetNameChange( SCH_COMMIT* aCommit, const wxString& aRef, SCH_PIN* aPin,
210 const SCH_SHEET_PATH& aSheet, const wxString& aOldName, const wxString& aNewName );
211
212private:
214
225
229 std::deque<CHANGELIST_ITEM> m_changelist;
231
232 int m_changesCount; // Number of user-level changes
233};
std::vector< BACKANNOTATE_REF > ResolveBackannotatedRefs(const std::vector< std::pair< const SCH_REFERENCE *, wxString > > &aRequests, bool aShareBases)
Turn the references footprints carry into the base references of their schematic instances.
bool CollectBackannotatePcbNets(const SCH_SYMBOL &aSymbol, const SCH_SHEET_PATH &aSheetPath, const wxString &aVariantName, const std::map< wxString, wxString > &aPcbNetsByPad, std::map< wxString, wxString > &aPcbNetsByLogicalPin)
Append this unit's PCB nets to a map keyed by logical pin number, resolving pin-to-pad mappings.
BACKANNOTATE_UNIT_SWAP_PLAN PlanBackannotateUnitSwaps(const std::vector< BACKANNOTATE_UNIT_SWAP_CANDIDATE > &aCandidates, const std::map< wxString, wxString > &aPcbPinMap)
Compute a pure unit-swap plan from schematic-side unit definitions and PCB nets keyed by logical pin ...
~BACK_ANNOTATE()=default
bool BackAnnotateSymbols(const std::string &aNetlist)
Run back annotation algorithm.
SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs
std::deque< CHANGELIST_ITEM > m_changelist
std::pair< SCH_REFERENCE, std::shared_ptr< PCB_FP_DATA > > CHANGELIST_ITEM
bool m_processReferences
bool m_processFootprints
bool m_processOtherFields
void getPcbModulesFromString(const std::string &aPayload)
Parse netlist sent over KiWay express mail interface and fill m_pcbFootprints.
SCH_EDIT_FRAME * m_frame
void checkForUnusedSymbols()
Check if some symbols are not represented in PCB footprints and vice versa.
SCH_REFERENCE_LIST m_refs
bool FetchNetlistFromPCB(std::string &aNetlist)
Get netlist from the Pcbnew.
PCB_FOOTPRINTS_MAP m_pcbFootprints
std::map< wxString, std::shared_ptr< PCB_FP_DATA > > PCB_FOOTPRINTS_MAP
Map to hold NETLIST footprints data.
REPORTER & m_reporter
bool m_processAttributes
BACK_ANNOTATE(SCH_EDIT_FRAME *aFrame, REPORTER &aReporter, bool aRelinkFootprints, bool aProcessFootprints, bool aProcessValues, bool aProcessReferences, bool aProcessNetNames, bool aProcessAttributes, bool aProcessOtherFields, bool aPreferUnitSwaps, bool aPreferPinSwaps, bool aDryRun)
std::set< wxString > applyPinSwaps(SCH_SYMBOL *aSymbol, const SCH_REFERENCE &aReference, const PCB_FP_DATA &aFpData, SCH_COMMIT *aCommit)
Handle footprint pad net swaps with symbol pin swaps where possible.
void processNetNameChange(SCH_COMMIT *aCommit, const wxString &aRef, SCH_PIN *aPin, const SCH_SHEET_PATH &aSheet, const wxString &aOldName, const wxString &aNewName)
bool m_matchByReference
void getChangeList()
Create changelist.
void PushNewLinksToPCB()
void applyChangelist()
Apply changelist to the schematic.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
Schematic editor (Eeschema) main window.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:76
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
wxString m_base
Base reference the instance takes, when m_error is empty.
std::vector< wxString > m_unitPinNumbers
std::map< wxString, wxString > m_schNetsByPin
std::vector< BACKANNOTATE_UNIT_SWAP_STEP > m_steps
std::set< size_t > m_swappedCandidateIndices
Container for Pcbnew footprint data.
std::map< wxString, wxString > m_pinMap
PCB_FP_DATA(const wxString &aRef, const wxString &aFootprint, const wxString &aValue, bool aDNP, bool aExcludeFromBOM, bool aExcludeFromSim, bool aExcludeFromPosFiles, const std::map< wxString, wxString > &aPinMap, const std::map< wxString, wxString > &aFieldsMap)
std::map< wxString, wxString > m_fieldsMap