KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_eagle.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) 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
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <http://www.gnu.org/licenses/>.
23 */
24
25#ifndef SCH_IO_EAGLE_H_
26#define SCH_IO_EAGLE_H_
27
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>
33
34#include <boost/ptr_container/ptr_map.hpp>
35
36class EDA_TEXT;
37class KIWAY;
38class LINE_READER;
39class SCH_SCREEN;
40class SCH_SHEET;
41class SCH_BITMAP;
42class SCH_JUNCTION;
43class SCH_NO_CONNECT;
44class SCH_SHAPE;
45class SCH_LINE;
47class SCH_TEXT;
48class SCH_GLOBALLABEL;
49class SCH_SYMBOL;
50class SCH_FIELD;
51class STRING_UTF8_MAP;
52class LIB_SYMBOL;
53class SYMBOL_LIB;
54class SCH_PIN;
55class wxXmlNode;
56
57
59{
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;
65};
66
67typedef boost::ptr_map<wxString, EPART> EPART_LIST;
68
69
75class SCH_IO_EAGLE : public SCH_IO
76{
77public:
78 const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
79
82
84 {
85 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
86 }
87
89 {
90 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
91 }
92
93 bool CanReadSchematicFile( const wxString& aFileName ) const override;
94 bool CanReadLibrary( const wxString& aFileName ) const override;
95
96 int GetModifyHash() const override;
97
98 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
99 SCH_SHEET* aAppendToMe = nullptr,
100 const STRING_UTF8_MAP* aProperties = nullptr ) override;
101
102 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
103 const STRING_UTF8_MAP* aProperties ) override;
104
105 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
106 const STRING_UTF8_MAP* aProperties ) override;
107
108 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
109 const STRING_UTF8_MAP* aProperties ) override;
110
111 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
112
113private:
114 void checkpoint();
115
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 );
120
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 );
128
130 void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
131
134 void addBusEntries();
135
137 SCH_LAYER_ID kiCadLayer( int aEagleLayer );
138
139 std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
140 const std::vector<SEG>& aLines ) const;
141
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 );
152
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 );
163
164 void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
165 void loadFieldAttributes( SCH_FIELD* aField, const SCH_TEXT* aText ) const;
166
168 void adjustNetLabels();
169
178 wxString translateEagleBusName( const wxString& aEagleName ) const;
179
180 wxString getLibName();
181 wxFileName getLibFileName();
182
184 bool checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const;
185
198 void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
199
200 bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
201
204
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 }
213
216
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 };
223
225 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
226
229 wxString m_version;
230 wxFileName m_filename;
231 wxString m_libName;
233
235 std::map<wxString, long long> m_timestamps;
236 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
237 std::unordered_map<wxString, bool> m_userValue;
238
240 std::unique_ptr<STRING_UTF8_MAP> m_properties;
241
242 unsigned m_doneCount;
244 unsigned m_totalCount;
245
246 std::map<wxString, int> m_netCounts;
247 std::map<int, SCH_LAYER_ID> m_layerMap;
248 std::map<wxString, wxString> m_powerPorts;
250
253 std::vector<VECTOR2I> m_wireIntersections;
254
256 struct SEG_DESC
257 {
259 const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
260
261 std::vector<SCH_TEXT*> labels;
262 std::vector<SEG> segs;
263 };
264
266 std::vector<SEG_DESC> m_segments;
267
269 std::map<wxString, ENET> m_nets;
270
272 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
273};
274
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
IO_RELEASER< SCH_IO > m_pi
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:40
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
SCH_LAYER_ID
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