27#include <boost/property_tree/ptree.hpp>
44 bool aProcessFootprints,
bool aProcessValues,
45 bool aProcessReferences,
bool aProcessNetNames,
bool aDryRun ) :
46 m_reporter( aReporter ),
47 m_matchByReference( aRelinkFootprints ),
48 m_processFootprints( aProcessFootprints ),
49 m_processValues( aProcessValues ),
50 m_processReferences( aProcessReferences ),
51 m_processNetNames( aProcessNetNames ),
98 "in stand-alone mode.\n"
99 "You must launch the KiCad project manager and create "
122 std::string nullPayload;
130 auto getStr = [](
const PTREE& pt ) -> wxString
132 return UTF8( pt.front().first );
142 Scan( &doc, &lexer );
144 PTREE& tree = doc.get_child(
"pcb_netlist" );
148 for(
const std::pair<const std::string, PTREE>& item : tree )
150 wxString
path, value, footprint;
151 std::map<wxString, wxString> pinNetMap;
152 wxASSERT( item.first ==
"ref" );
153 wxString ref = getStr( item.second );
160 path = getStr( item.second.get_child(
"timestamp" ) );
164 msg.Printf(
_(
"Footprint '%s' has no assigned symbol." ), ref );
169 footprint = getStr( item.second.get_child(
"fpid" ) );
170 value = getStr( item.second.get_child(
"value" ) );
172 boost::optional<const PTREE&> nets = item.second.get_child_optional(
"nets" );
176 for(
const std::pair<const std::string, PTREE>& pin_net : nets.get() )
178 wxASSERT( pin_net.first ==
"pin_net" );
179 wxString pinNumber =
UTF8( pin_net.second.front().first );
180 wxString netName =
UTF8( pin_net.second.back().first );
181 pinNetMap[ pinNumber ] = netName;
187 wxLogWarning(
"Cannot parse PCB netlist for back-annotation." );
196 msg.Printf(
_(
"Footprints '%s' and '%s' linked to same symbol." ),
197 nearestItem->second->m_ref,
204 auto data = std::make_shared<PCB_FP_DATA>( ref, footprint, value, pinNetMap );
213 for( std::pair<
const wxString, std::shared_ptr<PCB_FP_DATA>>& fpData :
m_pcbFootprints )
215 const wxString& pcbPath = fpData.first;
216 auto& pcbData = fpData.second;
218 bool foundInMultiunit =
false;
220 for( std::pair<const wxString, SCH_REFERENCE_LIST>& item :
m_multiUnitsRefs )
225 refIndex = refList.
FindRef( pcbPath );
233 foundInMultiunit =
true;
235 for(
size_t i = 0; i < refList.
GetCount(); ++i )
237 refList[ i ].GetSymbol()->ClearFlags(
SKIP_STRUCT );
245 if( foundInMultiunit )
275 return SCH_REFERENCE_LIST::sortByTimeStamp( a.first, b.first );
291 "Corresponding symbols in schematic must be "
292 "manually deleted (if desired)." ),
304 "annotated schematic." ) ) )
329 msg.Printf(
_(
"Change '%s' reference designator to '%s'." ),
346 msg.Printf(
_(
"Change %s footprint assignment from '%s' to '%s'." ),
364 msg.Printf(
_(
"Change %s value from '%s' to '%s'." ),
381 for(
const std::pair<const wxString, wxString>& entry : fpData.
m_pinMap )
383 const wxString& pinNumber = entry.first;
384 const wxString& shortNetName = entry.second;
389 msg.Printf(
_(
"Cannot find %s pin '%s'." ),
399 if( connection && connection->
Name(
true ) != shortNetName )
402 connection->
Name(
true ), shortNetName );
455 ORIENT o = orientations[ 0 ];
464 for(
auto& i : orientations )
466 if( i.flag == symbolOrientation )
473 for(
int i = 0; i < o.n_rots; i++ )
487 std::set<SCH_ITEM*>& connectedItems )
489 if( connectedItems.insert( aItem ).second )
499 const wxString& aOldName,
const wxString& aNewName )
507 std::set<SCH_ITEM*> connectedItems;
513 for(
SCH_ITEM* item : connectedItems )
517 if( priority > driverPriority )
520 driverPriority = priority;
524 switch( driver->
Type() )
532 msg.Printf(
_(
"Change %s pin %s net label from '%s' to '%s'." ),
557 msg.Printf(
_(
"Net %s cannot be changed to %s because it is driven by a power pin." ),
566 msg.Printf(
_(
"Add label '%s' to %s pin %s net." ),
void addConnections(SCH_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath, std::set< SCH_ITEM * > &connectedItems)
static TEXT_SPIN_STYLE orientLabel(SCH_PIN *aPin)
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void processNetNameChange(const wxString &aRef, SCH_PIN *aPin, const SCH_CONNECTION *aConnection, const wxString &aOldName, const wxString &aNewName)
bool BackAnnotateSymbols(const std::string &aNetlist)
Run back annotation algorithm.
BACK_ANNOTATE(SCH_EDIT_FRAME *aFrame, REPORTER &aReporter, bool aRelinkFootprints, bool aProcessFootprints, bool aProcessValues, bool aProcessReferences, bool aProcessNetNames, bool aDryRun)
SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs
std::deque< CHANGELIST_ITEM > m_changelist
void getPcbModulesFromString(const std::string &aPayload)
Parse netlist sent over KiWay express mail interface and fill m_pcbModules.
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::pair< SCH_REFERENCE, std::shared_ptr< PCB_FP_DATA > > CHANGELIST_ITEM
void applyChangelist()
Apply changelist to the schematic.
PRIORITY GetDriverPriority()
Implement a lexical analyzer for the SPECCTRA DSN file format.
virtual VECTOR2I GetPosition() const
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
EDA_ITEM_FLAGS GetFlags() const
void SetTextSize(const VECTOR2I &aNewSize)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
int GetOrientation() const
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the beginning of the list for objects that support ordering.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
These settings were stored in SCH_BASE_FRAME previously.
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
SCH_SHEET_PATH Sheet() const
wxString Name(bool aIgnoreSheet=false) const
Schematic editor (Eeschema) main window.
void AddItemToScreenAndUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItem, bool aUndoAppend)
Add an item to the schematic and adds the changes to the undo/redo container.
bool ReadyToNetlist(const wxString &aAnnotateMessage)
Check if we are ready to write a netlist file for the current schematic.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
SCHEMATIC & Schematic() const
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void UpdateNetHighlightStatus()
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
wxString GetShownNumber() const
bool IsGlobalPower() const
LIB_PIN * GetLibPin() const
SCH_SYMBOL * GetParentSymbol() const
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void SortByTimeStamp()
Sort the flat list by Time Stamp (sheet path + timestamp).
int FindRef(const wxString &aPath) const
Search the list for a symbol with a given reference.
int FindRefByFullPath(const wxString &aFullPath) const
Search the list for a symbol with the given KIID path (as string).
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
const wxString GetFootprint() const
SCH_SYMBOL * GetSymbol() const
const wxString GetValue() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the li...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void SetValueFieldText(const wxString &aValue)
bool GetIncludeOnBoard() const
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void SetFootprintFieldText(const wxString &aFootprint)
int GetOrientation() const
Get the display symbol orientation.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
virtual void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
TEXT_SPIN_STYLE MirrorY()
Mirror the label spin style across the Y axis or simply swaps left and right.
TEXT_SPIN_STYLE RotateCCW()
TEXT_SPIN_STYLE MirrorX()
Mirror the label spin style across the X axis or simply swaps up and bottom.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define IS_NEW
New item, just created.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void Scan(PTREE *aTree, DSNLEXER *aLexer)
Fill an empty PTREE with information from a KiCad s-expression stream.
boost::property_tree::ptree PTREE
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Container for Pcbnew footprint data.Map to hold NETLIST footprints data.
std::map< wxString, wxString > m_pinMap
Definition of file extensions used in Kicad.