KiCad PCB EDA Suite
No Matches
Go to the documentation of this file.
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 CERN
5 * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Alejandro GarcĂ­a Montoro <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 * @author Russell Oliver <[email protected]>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program. If not, see <>.
23 */
25#ifndef SCH_IO_EAGLE_H_
26#define SCH_IO_EAGLE_H_
28#include <sch_line.h>
29#include <sch_io/sch_io.h>
30#include <sch_io/sch_io_mgr.h>
32#include <geometry/seg.h>
34#include <boost/ptr_container/ptr_map.hpp>
36class EDA_TEXT;
37class KIWAY;
38class LINE_READER;
39class SCH_SCREEN;
40class SCH_SHEET;
41class SCH_BITMAP;
44class SCH_SHAPE;
45class SCH_LINE;
47class SCH_TEXT;
49class SCH_SYMBOL;
50class SCH_FIELD;
51class STRING_UTF8_MAP;
52class LIB_SYMBOL;
53class SYMBOL_LIB;
54class SCH_PIN;
55class wxXmlNode;
60 wxString name;
61 boost::ptr_map<wxString, LIB_SYMBOL> KiCadSymbols;
62 std::unordered_map<wxString, wxXmlNode*> SymbolNodes;
63 std::unordered_map<wxString, int> GateUnit;
64 std::unordered_map<wxString, wxString> package;
67typedef boost::ptr_map<wxString, EPART> EPART_LIST;
75class SCH_IO_EAGLE : public SCH_IO
78 const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
84 {
85 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
86 }
89 {
90 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
91 }
93 bool CanReadSchematicFile( const wxString& aFileName ) const override;
94 bool CanReadLibrary( const wxString& aFileName ) const override;
96 int GetModifyHash() const override;
98 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
99 SCH_SHEET* aAppendToMe = nullptr,
100 const STRING_UTF8_MAP* aProperties = nullptr ) override;
102 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
103 const STRING_UTF8_MAP* aProperties ) override;
105 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
106 const STRING_UTF8_MAP* aProperties ) override;
108 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
109 const STRING_UTF8_MAP* aProperties ) override;
111 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
114 void checkpoint();
116 bool checkHeader( const wxString& aFileName ) const;
117 wxXmlDocument loadXmlDocument( const wxString& aFileName );
118 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
119 void ensureLoadedLibrary( const wxString& aLibraryPath );
121 void loadDrawing( wxXmlNode* aDrawingNode );
122 void loadLayerDefs( wxXmlNode* aLayers );
123 void loadSchematic( wxXmlNode* aSchematicNode );
124 void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
125 void loadInstance( wxXmlNode* aInstanceNode );
126 EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
127 void countNets( wxXmlNode* aSchematicNode );
130 void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
134 void addBusEntries();
137 SCH_LAYER_ID kiCadLayer( int aEagleLayer );
139 std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
140 const std::vector<SEG>& aLines ) const;
142 void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
143 const wxString& aNetClass );
144 SCH_SHAPE* loadPolyLine( wxXmlNode* aPolygonNode );
145 SCH_ITEM* loadWire( wxXmlNode* aWireNode, SEG& endpoints );
146 SCH_SHAPE* loadCircle( wxXmlNode* aCircleNode );
147 SCH_SHAPE* loadRectangle( wxXmlNode* aRectNode );
148 SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
149 SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
150 SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
151 void loadFrame( wxXmlNode* aFrameNode, std::vector<SCH_ITEM*>& aItems );
153 bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBOL>& aSymbol,
154 EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
155 SCH_SHAPE* loadSymbolCircle( wxXmlNode* aCircleNode, int aGateNumber );
156 SCH_SHAPE* loadSymbolRectangle( wxXmlNode* aRectNode, int aGateNumber );
157 SCH_SHAPE* loadSymbolPolyLine( wxXmlNode* aPolygonNode, int aGateNumber );
158 SCH_ITEM* loadSymbolWire( wxXmlNode* aWireNode, int aGateNumber );
159 SCH_PIN* loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode*, EPIN* epin,
160 int aGateNumber );
161 SCH_TEXT* loadSymbolText( wxXmlNode* aLibText, int aGateNumber );
162 void loadSymbolFrame( wxXmlNode* aFrameNode, std::vector<SCH_ITEM*>& aLines );
164 void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
165 void loadFieldAttributes( SCH_FIELD* aField, const SCH_TEXT* aText ) const;
168 void adjustNetLabels();
178 wxString translateEagleBusName( const wxString& aEagleName ) const;
180 wxString getLibName();
181 wxFileName getLibFileName();
184 bool checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const;
198 void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
200 bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
205 // Describe missing units containing pins creating implicit connections
206 // (named power pins in Eagle).
208 {
209 EAGLE_MISSING_CMP( const SCH_SYMBOL* aSymbol = nullptr )
210 : cmp( aSymbol )
211 {
212 }
217 /* Map of the symbol units: for each unit there is a flag saying
218 * whether the unit needs to be instantiated with appropriate net labels to
219 * emulate implicit connections as is done in Eagle.
220 */
221 std::map<int, bool> units;
222 };
225 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
229 wxString m_version;
230 wxFileName m_filename;
231 wxString m_libName;
235 std::map<wxString, long long> m_timestamps;
236 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
237 std::unordered_map<wxString, bool> m_userValue;
240 std::unique_ptr<STRING_UTF8_MAP> m_properties;
242 unsigned m_doneCount;
244 unsigned m_totalCount;
246 std::map<wxString, int> m_netCounts;
247 std::map<int, SCH_LAYER_ID> m_layerMap;
248 std::map<wxString, wxString> m_powerPorts;
253 std::vector<VECTOR2I> m_wireIntersections;
256 struct SEG_DESC
257 {
259 const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
261 std::vector<SCH_TEXT*> labels;
262 std::vector<SEG> segs;
263 };
266 std::vector<SEG_DESC> m_segments;
269 std::map<wxString, ENET> m_nets;
272 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
275#endif // SCH_IO_EAGLE_H_
constexpr double SCH_IU_PER_MM
Definition: base_units.h:72
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
Define a library symbol object.
Definition: lib_symbol.h:77
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
Holds all the data relating to one schematic.
Definition: schematic.h:75
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:41
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
A SCH_IO derivation for loading 6.x+ Eagle schematic files.
Definition: sch_io_eagle.h:76
SCH_SHAPE * loadSymbolRectangle(wxXmlNode *aRectNode, int aGateNumber)
SCH_PIN * loadPin(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *, EPIN *epin, int aGateNumber)
SCH_SHAPE * loadSymbolCircle(wxXmlNode *aCircleNode, int aGateNumber)
void ensureLoadedLibrary(const wxString &aLibraryPath)
bool netHasPowerDriver(SCH_LINE *aLine, const wxString &aNetName) const
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
void loadSegments(wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
EAGLE_LIBRARY * loadLibrary(wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
std::unique_ptr< STRING_UTF8_MAP > m_properties
Library plugin properties.
Definition: sch_io_eagle.h:240
wxXmlDocument loadXmlDocument(const wxString &aFileName)
void loadSheet(wxXmlNode *aSheetNode, int sheetcount)
wxString translateEagleBusName(const wxString &aEagleName) const
Translate an Eagle-style bus name into one that is KiCad-compatible.
void loadFieldAttributes(SCH_FIELD *aField, const SCH_TEXT *aText) const
Move net labels that are detached from any wire to the nearest wire.
std::map< wxString, wxString > m_powerPorts
map from symbol reference to global label equivalent
Definition: sch_io_eagle.h:248
SCH_SHEET_PATH m_sheetPath
The current sheet path of the schematic being loaded.
Definition: sch_io_eagle.h:228
wxString m_libName
Library name to save symbols.
Definition: sch_io_eagle.h:231
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
void loadInstance(wxXmlNode *aInstanceNode)
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const VECTOR2I &aPoint, const std::vector< SEG > &aLines) const
SCH_SHAPE * loadCircle(wxXmlNode *aCircleNode)
SCH_TEXT * loadLabel(wxXmlNode *aLabelNode, const wxString &aNetName)
const double ARC_ACCURACY
Definition: sch_io_eagle.h:78
std::map< wxString, long long > m_timestamps
Definition: sch_io_eagle.h:235
void adjustNetLabels()
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
void loadSymbolFrame(wxXmlNode *aFrameNode, std::vector< SCH_ITEM * > &aLines)
std::unordered_map< wxString, bool > m_userValue
deviceset/@uservalue for device.
Definition: sch_io_eagle.h:237
int GetModifyHash() const override
Return the modification hash from the library cache.
EPART_MAP m_partlist
Definition: sch_io_eagle.h:234
std::map< wxString, int > m_netCounts
Definition: sch_io_eagle.h:246
SCH_ITEM * loadWire(wxXmlNode *aWireNode, SEG &endpoints)
wxFileName m_filename
Definition: sch_io_eagle.h:230
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
Definition: sch_io_eagle.h:236
SCH_SHAPE * loadPolyLine(wxXmlNode *aPolygonNode)
std::map< wxString, ENET > m_nets
Positions of pins and wire endings mapped to its parent.
Definition: sch_io_eagle.h:269
void countNets(wxXmlNode *aSchematicNode)
SCH_SHEET * getCurrentSheet()
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
Definition: sch_io_eagle.h:253
void loadSchematic(wxXmlNode *aSchematicNode)
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
Definition: sch_io_eagle.h:272
bool checkConnections(const SCH_SYMBOL *aSymbol, const SCH_PIN *aPin) const
PI to create KiCad symbol library.
Definition: sch_io_eagle.h:239
void addBusEntries()
This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Ea...
SCH_SHAPE * loadSymbolPolyLine(wxXmlNode *aPolygonNode, int aGateNumber)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
void addImplicitConnections(SCH_SYMBOL *aSymbol, SCH_SCREEN *aScreen, bool aUpdateSet)
Create net labels to emulate implicit connections in Eagle.
std::map< int, SCH_LAYER_ID > m_layerMap
Definition: sch_io_eagle.h:247
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
wxString getLibName()
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
Definition: sch_io_eagle.h:83
SCH_ITEM * loadSymbolWire(wxXmlNode *aWireNode, int aGateNumber)
wxString m_version
Eagle file version.
Definition: sch_io_eagle.h:229
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
SCH_SHAPE * loadRectangle(wxXmlNode *aRectNode)
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
Definition: sch_io_eagle.h:88
void moveLabels(SCH_LINE *aWire, const VECTOR2I &aNewEndPoint)
Move any labels on the wire to the new end point of the wire.
bool checkHeader(const wxString &aFileName) const
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
Definition: sch_io_eagle.h:232
bool loadSymbol(wxXmlNode *aSymbolNode, std::unique_ptr< LIB_SYMBOL > &aSymbol, EDEVICE *aDevice, int aGateNumber, const wxString &aGateName)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: sch_io_eagle.h:111
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
Definition: sch_io_eagle.h:227
SCH_SCREEN * getCurrentScreen()
unsigned m_lastProgressCount
Definition: sch_io_eagle.h:243
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
Definition: sch_io_eagle.h:225
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
void loadFrame(wxXmlNode *aFrameNode, std::vector< SCH_ITEM * > &aItems)
SCH_TEXT * loadSymbolText(wxXmlNode *aLibText, int aGateNumber)
unsigned m_doneCount
Definition: sch_io_eagle.h:242
void loadLayerDefs(wxXmlNode *aLayers)
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
Definition: sch_io_eagle.h:266
void loadDrawing(wxXmlNode *aDrawingNode)
unsigned m_totalCount
for progress reporting
Definition: sch_io_eagle.h:244
long long getLibraryTimestamp(const wxString &aLibraryPath) const
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
Schematic symbol object.
Definition: sch_symbol.h:105
Definition: seg.h:42
A name/value tuple with unique names and optional values.
Object used to load, save, search, and otherwise manipulate symbol library files.
#define _HKI(x)
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
Translates Eagle special characters to their counterparts in KiCad.
Definition: eagle_parser.h:51
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
Eeschema drawing layers.
Definition: layer_ids.h:353
boost::ptr_map< wxString, EPART > EPART_LIST
Definition: sch_io_eagle.h:67
std::unordered_map< wxString, int > GateUnit
Definition: sch_io_eagle.h:63
std::unordered_map< wxString, wxString > package
Definition: sch_io_eagle.h:64
boost::ptr_map< wxString, LIB_SYMBOL > KiCadSymbols
Definition: sch_io_eagle.h:61
wxString name
Definition: sch_io_eagle.h:60
std::unordered_map< wxString, wxXmlNode * > SymbolNodes
Definition: sch_io_eagle.h:62
Eagle pin element.
Definition: eagle_parser.h:748
Eagle text element.
Definition: eagle_parser.h:644
Container that describes file type info.
Definition: io_base.h:39
Map references to missing symbol units data.
Definition: sch_io_eagle.h:208
EAGLE_MISSING_CMP(const SCH_SYMBOL *aSymbol=nullptr)
Link to the parent symbol.
Definition: sch_io_eagle.h:209
std::map< int, bool > units
Definition: sch_io_eagle.h:221
Segments representing wires for intersection checking.
Definition: sch_io_eagle.h:257
std::vector< SEG > segs
Definition: sch_io_eagle.h:262
std::vector< SCH_TEXT * > labels
Definition: sch_io_eagle.h:261
const SEG * LabelAttached(const SCH_TEXT *aLabel) const
< Test if a particular label is attached to any of the stored segments