27 #include <boost/property_tree/ptree.hpp> 41 bool aProcessFootprints,
bool aProcessValues,
42 bool aProcessReferences,
bool aProcessNetNames,
bool aDryRun ) :
43 m_reporter( aReporter ),
44 m_matchByReference( aRelinkFootprints ),
45 m_processFootprints( aProcessFootprints ),
46 m_processValues( aProcessValues ),
47 m_processReferences( aProcessReferences ),
48 m_processNetNames( aProcessNetNames ),
96 "in stand-alone mode.\n" 97 "You must launch the KiCad project manager and create " 120 std::string nullPayload;
128 auto getStr = [](
const PTREE& pt ) -> wxString
130 return UTF8( pt.front().first );
140 Scan( &doc, &lexer );
142 PTREE& tree = doc.get_child(
"pcb_netlist" );
146 for(
const std::pair<const std::string, PTREE>& item : tree )
148 wxString path, value, footprint;
149 std::map<wxString, wxString> pinNetMap;
150 wxASSERT( item.first ==
"ref" );
151 wxString ref = getStr( item.second );
158 path = getStr( item.second.get_child(
"timestamp" ) );
162 msg.Printf(
_(
"Footprint '%s' has no assigned symbol." ),
168 footprint = getStr( item.second.get_child(
"fpid" ) );
169 value = getStr( item.second.get_child(
"value" ) );
171 boost::optional<const PTREE&> nets = item.second.get_child_optional(
"nets" );
175 for(
const std::pair<const std::string, PTREE>& pin_net : nets.get() )
177 wxASSERT( pin_net.first ==
"pin_net" );
178 wxString pinNumber =
UTF8( pin_net.second.front().first );
179 wxString netName =
UTF8( pin_net.second.back().first );
180 pinNetMap[ pinNumber ] = netName;
186 wxLogWarning(
"Cannot parse PCB netlist for back-annotation." );
192 if( nearestItem !=
m_pcbFootprints.end() && nearestItem->first == path )
195 msg.Printf(
_(
"Footprints '%s' and '%s' linked to same symbol." ),
196 nearestItem->second->m_ref,
203 auto data = std::make_shared<PCB_FP_DATA>( ref, footprint, value, pinNetMap );
212 for( std::pair<
const wxString, std::shared_ptr<PCB_FP_DATA>>& fpData :
m_pcbFootprints )
214 const wxString& pcbPath = fpData.first;
215 auto& pcbData = fpData.second;
217 bool foundInMultiunit =
false;
219 for( std::pair<const wxString, SCH_REFERENCE_LIST>& item :
m_multiUnitsRefs )
224 refIndex = refList.
FindRef( pcbPath );
232 foundInMultiunit =
true;
234 for(
size_t i = 0; i < refList.
GetCount(); ++i )
236 refList[ i ].GetSymbol()->ClearFlags(
SKIP_STRUCT );
244 if( foundInMultiunit )
290 "Corresponding symbols in schematic must be " 291 "manually deleted (if desired)." ),
303 "annotated schematic." ) ) )
328 msg.Printf(
_(
"Change '%s' reference designator to '%s'." ),
345 msg.Printf(
_(
"Change %s footprint assignment from '%s' to '%s'." ),
363 msg.Printf(
_(
"Change %s value from '%s' to '%s'." ),
380 for(
const std::pair<const wxString, wxString>& entry : fpData.
m_pinMap )
382 const wxString& pinNumber = entry.first;
383 const wxString& shortNetName = entry.second;
388 msg.Printf(
_(
"Cannot find %s pin '%s'." ),
398 if( connection && connection->
Name(
true ) != shortNetName )
401 connection->
Name(
true ), shortNetName );
454 ORIENT o = orientations[ 0 ];
463 for(
auto& i : orientations )
465 if( i.flag == symbolOrientation )
472 for(
int i = 0; i < o.n_rots; i++ )
486 std::set<SCH_ITEM*>& connectedItems )
488 if( connectedItems.insert( aItem ).second )
498 const wxString& aOldName,
const wxString& aNewName )
506 std::set<SCH_ITEM*> connectedItems;
512 for(
SCH_ITEM* item : connectedItems )
516 if( priority > driverPriority )
519 driverPriority = priority;
523 switch( driver->
Type() )
531 msg.Printf(
_(
"Change %s pin %s net label from '%s' to '%s'." ),
543 static_cast<SCH_TEXT*>( driver )->SetText( aNewName );
551 SCH_PIN* schPin = static_cast<SCH_PIN*>( driver );
556 msg.Printf(
_(
"Net %s cannot be changed to '%s' because it is driven by a power pin." ),
565 msg.Printf(
_(
"Add label '%s' to %s pin %s net." ),
bool ReadyToNetlist(const wxString &aAnnotateMessage)
Checks if we are ready to write a netlist file for the current schematic.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
LIB_PIN * GetLibPin() const
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
BACK_ANNOTATE(SCH_EDIT_FRAME *aFrame, REPORTER &aReporter, bool aRelinkFootprints, bool aProcessFootprints, bool aProcessValues, bool aProcessReferences, bool aProcessNetNames, bool aDryRun)
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
void UpdateNetHighlightStatus()
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
int GetOrientation()
Get the display symbol orientation.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Add a SCH_REFERENCE object to aReferences for each component in the list of sheets.
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generates the connection data for the entire schematic 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...
This file is part of the common library.
int FindRefByPath(const wxString &aPath) const
Search the list for a symbol with the given KIID path.
const SCH_SHEET_PATH & GetSheetPath() const
bool GetIncludeOnBoard() const
int GetOrientation() const
void Scan(PTREE *aTree, DSNLEXER *aLexer)
Fill an empty PTREE with information from a KiCad s-expression stream.
SCH_COMPONENT * GetParentSymbol() const
SCHEMATIC_SETTINGS & Settings() const
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.
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.
Schematic editor (Eeschema) main window.
wxString GetNumber() const
void getPcbModulesFromString(const std::string &aPayload)
Parse netlist sent over KiWay express mail interface and fill m_pcbModules.
void SetTextSize(const wxSize &aNewSize)
virtual wxPoint GetPosition() const
A pure virtual class used to derive REPORTER objects from.
std::map< wxString, wxString > m_pinMap
bool BackAnnotateSymbols(const std::string &aNetlist)
Run back annotation algorithm.
virtual void SetParent(EDA_ITEM *aParent)
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
int FindRef(const wxString &aPath) const
Search the list for a symbol with a given reference.
void checkForUnusedSymbols()
Check if some symbols are not represented in PCB footprints and vice versa.
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
boost::property_tree::ptree PTREE
void SortByTimeStamp()
Sort the flat list by Time Stamp (sheet path + timestamp).
void processNetNameChange(const wxString &aRef, SCH_PIN *aPin, const SCH_CONNECTION *aConnection, const wxString &aOldName, const wxString &aNewName)
void SetFlags(STATUS_FLAGS aMask)
wxString Name(bool aIgnoreSheet=false) const
void addConnections(SCH_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath, std::set< SCH_ITEM * > &connectedItems)
bool FetchNetlistFromPCB(std::string &aNetlist)
Get netlist from the Pcbnew.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
SCHEMATIC & Schematic() const
Definition of file extensions used in Kicad.
const wxString GetFootprint() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
LABEL_SPIN_STYLE MirrorY()
std::pair< SCH_REFERENCE, std::shared_ptr< PCB_FP_DATA > > CHANGELIST_ITEM
SCH_COMPONENT * GetSymbol() const
LABEL_SPIN_STYLE RotateCCW()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
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.
unsigned GetCount() const
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
SCH_SHEET_PATH Sheet() const
LABEL_SPIN_STYLE MirrorX()
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.
SCH_SCREEN * LastScreen()
void applyChangelist()
Apply changelist to the schematic.
static LABEL_SPIN_STYLE orientLabel(SCH_PIN *aPin)
SCH_ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieves the set of items connected to this item on the given sheet.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
These settings were stored in SCH_BASE_FRAME previously.
const wxString GetValue() const
SCH_REFERENCE_LIST m_refs
bool IsPowerConnection() const
std::deque< CHANGELIST_ITEM > m_changelist
#define SKIP_STRUCT
flag indicating that the structure should be ignored
virtual void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Struct to hold Pcbnew footprint data.Map to hold NETLIST footprints data.
STATUS_FLAGS GetFlags() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Implement a lexical analyzer for the SPECCTRA DSN file format.
PCB_FOOTPRINTS_MAP m_pcbFootprints
#define IS_NEW
New item, just created.
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
A helper to define a symbol's reference designator in a schematic.
PRIORITY GetDriverPriority()
SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs
KICAD_T Type() const
Returns the type of object.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.