KiCad PCB EDA Suite
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 <Jasuramme@gmail.com>
5  * Copyright (C) 2004-2020 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, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #ifndef BACKANNOTATE_H
27 #define BACKANNOTATE_H
28 
29 #include <deque>
30 #include <map>
31 #include <memory>
32 #include <sch_reference_list.h>
33 #include <template_fieldnames.h>
34 #include <wx/string.h>
35 
36 // Forward declarations
37 class REPORTER;
38 class SCH_SHEET_LIST;
39 class SCH_EDIT_FRAME;
40 
41 
56 {
57 public:
62  {
63  PCB_MODULE_DATA( const wxString& aRef, const wxString& aFootprint,
64  const wxString& aValue, const std::map<wxString, wxString> aPinMap ) :
65  m_ref( aRef ),
66  m_footprint( aFootprint ),
67  m_value( aValue ),
68  m_pinMap( aPinMap )
69  {};
70 
71  wxString m_ref;
72  wxString m_footprint;
73  wxString m_value;
74  std::map<wxString, wxString> m_pinMap;
75  };
76 
78  using PCB_MODULES_MAP = std::map<wxString, std::shared_ptr<PCB_MODULE_DATA>>;
79 
80  using CHANGELIST_ITEM = std::pair<SCH_REFERENCE, std::shared_ptr<PCB_MODULE_DATA>>;
81 
82  BACK_ANNOTATE( SCH_EDIT_FRAME* aFrame, REPORTER& aReporter, bool aProcessFootprints,
83  bool aProcessValues, bool aProcessReferences, bool aProcessNetNames,
84  bool aIgnoreOtherProjects, bool aDryRun );
86 
92  bool FetchNetlistFromPCB( std::string& aNetlist );
93 
100  bool BackAnnotateSymbols( const std::string& aNetlist );
101 
102 private:
104 
110  bool m_dryRun;
111 
115  std::deque<CHANGELIST_ITEM> m_changelist;
117 
120 
122  wxString getTextFromField( const SCH_REFERENCE& aRef, const NumFieldType aField );
123 
131  bool checkReuseViolation( PCB_MODULE_DATA& aFirst, PCB_MODULE_DATA& aSecond );
132 
138  void getPcbModulesFromString( const std::string& aPayload );
139 
141  void getChangeList();
142 
147  void checkForUnusedSymbols();
148 
153 
157  void applyChangelist();
158 
159  void processNetNameChange( SCH_CONNECTION* aConn, const wxString& aOldName,
160  const wxString& aNewName );
161 };
162 
163 #endif
wxString getTextFromField(const SCH_REFERENCE &aRef, const NumFieldType aField)
Get text from symbol's field ( such as Footprint or Value )
SCH_SHEET_LIST.
SCH_EDIT_FRAME * m_frame
Definition: backannotate.h:116
bool m_processNetNames
Definition: backannotate.h:108
std::map< wxString, std::shared_ptr< PCB_MODULE_DATA > > PCB_MODULES_MAP
Map to hold NETLIST modules data
Definition: backannotate.h:78
std::map< wxString, wxString > m_pinMap
Definition: backannotate.h:74
bool m_processFootprints
Definition: backannotate.h:105
PCB_MODULES_MAP m_pcbModules
Definition: backannotate.h:112
Schematic editor (Eeschema) main window.
bool m_processReferences
Definition: backannotate.h:107
void getPcbModulesFromString(const std::string &aPayload)
Parse netlist sent over KiWay epress mail interface and fill m_pcbModules.
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
bool BackAnnotateSymbols(const std::string &aNetlist)
Run back annotation algorithm.
SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierarchy,...
void checkForUnusedSymbols()
Check if some symbols are not represented in PCB modules and vice versa.
REPORTER & m_reporter
Definition: backannotate.h:103
bool checkReuseViolation(PCB_MODULE_DATA &aFirst, PCB_MODULE_DATA &aSecond)
Check if modules has different data.
bool m_processValues
Definition: backannotate.h:106
bool FetchNetlistFromPCB(std::string &aNetlist)
Get netlist from the PCBnew.
std::pair< SCH_REFERENCE, std::shared_ptr< PCB_MODULE_DATA > > CHANGELIST_ITEM
Definition: backannotate.h:80
void processNetNameChange(SCH_CONNECTION *aConn, const wxString &aOldName, const wxString &aNewName)
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Type SCH_MULTI_UNIT_REFERENCE_MAP is used to create a map of reference designators for multi-unit par...
NumFieldType
Enum NumFieldType is the set of all field indices assuming an array like sequence that a SCH_COMPONEN...
void getChangeList()
Create changelist
BACK_ANNOTATE(SCH_EDIT_FRAME *aFrame, REPORTER &aReporter, bool aProcessFootprints, bool aProcessValues, bool aProcessReferences, bool aProcessNetNames, bool aIgnoreOtherProjects, bool aDryRun)
void checkSharedSchematicErrors()
Check for errors connected to reusing schematic in project or between projects.
bool m_ignoreOtherProjects
Definition: backannotate.h:109
PCB_MODULE_DATA(const wxString &aRef, const wxString &aFootprint, const wxString &aValue, const std::map< wxString, wxString > aPinMap)
Definition: backannotate.h:63
void applyChangelist()
Apply changelist to the schematic.
Struct to hold PCBnew module data.
Definition: backannotate.h:61
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Back annotation algorithm class used to recieve, check, and apply a NETLIST from PCBNEW.
Definition: backannotate.h:55
SCH_REFERENCE_LIST m_refs
Definition: backannotate.h:113
int m_changesCount
To count number of changes applied to the schematic
Definition: backannotate.h:119
std::deque< CHANGELIST_ITEM > m_changelist
Definition: backannotate.h:115
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.
SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs
Definition: backannotate.h:114