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-2024 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
35class EDA_TEXT;
36class KIWAY;
37class LINE_READER;
38class SCH_SCREEN;
39class SCH_SHEET;
40class SCH_BITMAP;
41class SCH_JUNCTION;
42class SCH_NO_CONNECT;
43class SCH_SHAPE;
44class SCH_LINE;
46class SCH_TEXT;
47class SCH_GLOBALLABEL;
48class SCH_SYMBOL;
49class SCH_FIELD;
50class STRING_UTF8_MAP;
51class LIB_SYMBOL;
52class SYMBOL_LIB;
53class SCH_PIN;
54class wxXmlNode;
55
56
58{
59 wxString name;
60 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> KiCadSymbols;
61
69 std::unordered_map<wxString, int> GateToUnitMap;
70 std::unordered_map<wxString, wxString> package;
71};
72
73
79class SCH_IO_EAGLE : public SCH_IO
80{
81public:
82 const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
83
86
88 {
89 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
90 }
91
93 {
94 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
95 }
96
97 bool CanReadSchematicFile( const wxString& aFileName ) const override;
98 bool CanReadLibrary( const wxString& aFileName ) const override;
99
100 int GetModifyHash() const override;
101
102 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
103 SCH_SHEET* aAppendToMe = nullptr,
104 const STRING_UTF8_MAP* aProperties = nullptr ) override;
105
106 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
107 const STRING_UTF8_MAP* aProperties ) override;
108
109 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
110 const STRING_UTF8_MAP* aProperties ) override;
111
112 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
113 const STRING_UTF8_MAP* aProperties ) override;
114
115 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
116
117private:
118 bool checkHeader( const wxString& aFileName ) const;
119 wxXmlDocument loadXmlDocument( const wxString& aFileName );
120 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
121 void ensureLoadedLibrary( const wxString& aLibraryPath );
122
123 void loadDrawing( const std::unique_ptr<EDRAWING>& aDrawing );
124 void loadLayerDefs( const std::vector<std::unique_ptr<ELAYER>>& aLayers );
125 void loadSchematic( const ESCHEMATIC& aSchematic );
126 void loadSheet( const std::unique_ptr<ESHEET>& aSheet );
127 void loadInstance( const std::unique_ptr<EINSTANCE>& aInstance,
128 const std::map<wxString, std::unique_ptr<EPART>>& aParts );
129
130 SCH_SHEET* loadModuleInstance( const std::unique_ptr<EMODULEINST>& aModuleInstance );
131
132 EAGLE_LIBRARY* loadLibrary( const ELIBRARY* aLibrary, EAGLE_LIBRARY* aEagleLib );
133 void countNets( const ESCHEMATIC& aSchematic );
134
136 void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
137
140 void addBusEntries();
141
143 SCH_LAYER_ID kiCadLayer( int aEagleLayer );
144
145 std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
146 const std::vector<SEG>& aLines ) const;
147
148 void loadSegments( const std::vector<std::unique_ptr<ESEGMENT>>& aSegments,
149 const wxString& aNetName,
150 const wxString& aNetClass );
151 SCH_SHAPE* loadPolyLine( const std::unique_ptr<EPOLYGON>& aPolygon );
152 SCH_ITEM* loadWire( const std::unique_ptr<EWIRE>& aWire, SEG& endpoints );
153 SCH_SHAPE* loadCircle( const std::unique_ptr<ECIRCLE>& aCircle );
154 SCH_SHAPE* loadRectangle( const std::unique_ptr<ERECT>& aRect );
155 SCH_TEXT* loadLabel( const std::unique_ptr<ELABEL>& aLabel, const wxString& aNetName );
156 SCH_JUNCTION* loadJunction( const std::unique_ptr<EJUNCTION>& aJunction );
157 SCH_TEXT* loadPlainText( const std::unique_ptr<ETEXT>& aSchText );
158 void loadFrame( const std::unique_ptr<EFRAME>& aFrame,
159 std::vector<SCH_ITEM*>& aItems );
160
161 bool loadSymbol( const std::unique_ptr<ESYMBOL>& aEsymbol,
162 std::unique_ptr<LIB_SYMBOL>& aSymbol,
163 const std::unique_ptr<EDEVICE>& aDevice, int aGateNumber,
164 const wxString& aGateName );
165 SCH_SHAPE* loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
166 const std::unique_ptr<ECIRCLE>& aCircle,
167 int aGateNumber );
168 SCH_SHAPE* loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
169 const std::unique_ptr<ERECT>& aRectangle,
170 int aGateNumber );
171 SCH_SHAPE* loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
172 const std::unique_ptr<EPOLYGON>& aPolygon, int aGateNumber );
173 SCH_ITEM* loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol,
174 const std::unique_ptr<EWIRE>& aWire,
175 int aGateNumber );
176 SCH_PIN* loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, const std::unique_ptr<EPIN>& aPin,
177 int aGateNumber );
178 SCH_TEXT* loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol,
179 const std::unique_ptr<ETEXT>& aText,
180 int aGateNumber );
181 void loadTextAttributes( EDA_TEXT* aText,
182 const std::unique_ptr<ETEXT>& aAttributes ) const;
183 void loadFieldAttributes( SCH_FIELD* aField, const SCH_TEXT* aText ) const;
184
186 void adjustNetLabels();
187
196 wxString translateEagleBusName( const wxString& aEagleName ) const;
197
198 wxString getLibName();
199 wxFileName getLibFileName();
200
202 bool checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const;
203
216 void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
217
218 bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
219
220 void getEagleSymbolFieldAttributes( const std::unique_ptr<EINSTANCE>& aInstance,
221 const wxString& aEagleFieldName,
222 SCH_FIELD* aField );
223 const ESYMBOL* getEagleSymbol( const std::unique_ptr<EINSTANCE>& aInstance );
224
227
228 // Describe missing units containing pins creating implicit connections
229 // (named power pins in Eagle).
231 {
232 EAGLE_MISSING_CMP( const SCH_SYMBOL* aSymbol = nullptr )
233 : cmp( aSymbol )
234 {
235 }
236
239
240 /* Map of the symbol units: for each unit there is a flag saying
241 * whether the unit needs to be instantiated with appropriate net labels to
242 * emulate implicit connections as is done in Eagle.
243 */
244 std::map<int, bool> units;
245 };
246
248 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
249
252 wxString m_version;
253 wxFileName m_filename;
254 wxString m_libName;
257
258 std::map<wxString, const EPART*> m_partlist;
259 std::map<wxString, long long> m_timestamps;
260 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
261 std::map<wxString, std::unique_ptr<EMODULE>> m_eagleModules;
262
263 std::unordered_map<wxString, bool> m_userValue;
264
266 std::unique_ptr<STRING_UTF8_MAP> m_properties;
267
269
270 std::map<wxString, int> m_netCounts;
271 std::map<int, SCH_LAYER_ID> m_layerMap;
272 std::map<wxString, wxString> m_powerPorts;
274
277 std::vector<VECTOR2I> m_wireIntersections;
278
280 struct SEG_DESC
281 {
283 const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
284
285 std::vector<SCH_TEXT*> labels;
286 std::vector<SEG> segs;
287 };
288
290 std::vector<SEG_DESC> m_segments;
291
293 std::map<wxString, ENET> m_nets;
294
296 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
297
299 std::unique_ptr<EAGLE_DOC> m_eagleDoc;
300};
301
302#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:79
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:78
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:76
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:80
std::unique_ptr< EAGLE_DOC > m_eagleDoc
Definition: sch_io_eagle.h:299
SCH_ITEM * loadWire(const std::unique_ptr< EWIRE > &aWire, SEG &endpoints)
void loadTextAttributes(EDA_TEXT *aText, const std::unique_ptr< ETEXT > &aAttributes) const
std::map< wxString, std::unique_ptr< EMODULE > > m_eagleModules
Definition: sch_io_eagle.h:261
SCH_TEXT * loadLabel(const std::unique_ptr< ELABEL > &aLabel, const wxString &aNetName)
void ensureLoadedLibrary(const wxString &aLibraryPath)
void loadSchematic(const ESCHEMATIC &aSchematic)
SCH_TEXT * loadPlainText(const std::unique_ptr< ETEXT > &aSchText)
void loadSheet(const std::unique_ptr< ESHEET > &aSheet)
bool netHasPowerDriver(SCH_LINE *aLine, const wxString &aNetName) const
void loadLayerDefs(const std::vector< std::unique_ptr< ELAYER > > &aLayers)
const ESYMBOL * getEagleSymbol(const std::unique_ptr< EINSTANCE > &aInstance)
EAGLE_LIBRARY * loadLibrary(const ELIBRARY *aLibrary, EAGLE_LIBRARY *aEagleLib)
std::unique_ptr< STRING_UTF8_MAP > m_properties
Library plugin properties.
Definition: sch_io_eagle.h:266
wxXmlDocument loadXmlDocument(const wxString &aFileName)
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:272
SCH_SHEET_PATH m_sheetPath
The current sheet path of the schematic being loaded.
Definition: sch_io_eagle.h:251
wxString m_libName
Library name to save symbols.
Definition: sch_io_eagle.h:254
EMODULE * m_module
The current module being loaded or nullptr.
Definition: sch_io_eagle.h:256
SCH_TEXT * loadSymbolText(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ETEXT > &aText, int aGateNumber)
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...
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const VECTOR2I &aPoint, const std::vector< SEG > &aLines) const
const double ARC_ACCURACY
Definition: sch_io_eagle.h:82
std::map< wxString, long long > m_timestamps
Definition: sch_io_eagle.h:259
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 loadInstance(const std::unique_ptr< EINSTANCE > &aInstance, const std::map< wxString, std::unique_ptr< EPART > > &aParts)
std::unordered_map< wxString, bool > m_userValue
deviceset/@uservalue for device.
Definition: sch_io_eagle.h:263
int GetModifyHash() const override
Return the modification hash from the library cache.
std::map< wxString, int > m_netCounts
Definition: sch_io_eagle.h:270
wxFileName m_filename
Definition: sch_io_eagle.h:253
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
Definition: sch_io_eagle.h:260
std::map< wxString, ENET > m_nets
Positions of pins and wire endings mapped to its parent.
Definition: sch_io_eagle.h:293
bool loadSymbol(const std::unique_ptr< ESYMBOL > &aEsymbol, std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EDEVICE > &aDevice, int aGateNumber, const wxString &aGateName)
SCH_SHEET * getCurrentSheet()
void loadDrawing(const std::unique_ptr< EDRAWING > &aDrawing)
SCH_SHAPE * loadSymbolPolyLine(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EPOLYGON > &aPolygon, int aGateNumber)
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
Definition: sch_io_eagle.h:277
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
The fully parsed Eagle schematic file.
Definition: sch_io_eagle.h:296
void loadSegments(const std::vector< std::unique_ptr< ESEGMENT > > &aSegments, const wxString &aNetName, const wxString &aNetClass)
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:265
SCH_SHAPE * loadRectangle(const std::unique_ptr< ERECT > &aRect)
void addBusEntries()
This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Ea...
SCH_SHEET * loadModuleInstance(const std::unique_ptr< EMODULEINST > &aModuleInstance)
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:271
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
wxString getLibName()
SCH_PIN * loadPin(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EPIN > &aPin, int aGateNumber)
SCH_SHAPE * loadCircle(const std::unique_ptr< ECIRCLE > &aCircle)
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
SCH_SHAPE * loadSymbolRectangle(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ERECT > &aRectangle, int aGateNumber)
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:87
SCH_JUNCTION * loadJunction(const std::unique_ptr< EJUNCTION > &aJunction)
wxString m_version
Eagle file version.
Definition: sch_io_eagle.h:252
void getEagleSymbolFieldAttributes(const std::unique_ptr< EINSTANCE > &aInstance, const wxString &aEagleFieldName, SCH_FIELD *aField)
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:92
std::map< wxString, const EPART * > m_partlist
Definition: sch_io_eagle.h:258
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:255
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: sch_io_eagle.h:115
void countNets(const ESCHEMATIC &aSchematic)
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
Definition: sch_io_eagle.h:250
SCH_SHAPE * loadPolyLine(const std::unique_ptr< EPOLYGON > &aPolygon)
SCH_SHAPE * loadSymbolCircle(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ECIRCLE > &aCircle, int aGateNumber)
SCH_SCREEN * getCurrentScreen()
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:248
void loadFrame(const std::unique_ptr< EFRAME > &aFrame, std::vector< SCH_ITEM * > &aItems)
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
Definition: sch_io_eagle.h:290
SCH_ITEM * loadSymbolWire(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EWIRE > &aWire, int aGateNumber)
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:166
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::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:354
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > KiCadSymbols
Definition: sch_io_eagle.h:60
std::unordered_map< wxString, wxString > package
Definition: sch_io_eagle.h:70
wxString name
Definition: sch_io_eagle.h:59
std::unordered_map< wxString, int > GateToUnitMap
Map Eagle gate unit number (which are strings) to KiCad library symbol unit number.
Definition: sch_io_eagle.h:69
Container that describes file type info.
Definition: io_base.h:40
Map references to missing symbol units data.
Definition: sch_io_eagle.h:231
EAGLE_MISSING_CMP(const SCH_SYMBOL *aSymbol=nullptr)
Link to the parent symbol.
Definition: sch_io_eagle.h:232
std::map< int, bool > units
Definition: sch_io_eagle.h:244
Segments representing wires for intersection checking.
Definition: sch_io_eagle.h:281
std::vector< SEG > segs
Definition: sch_io_eagle.h:286
std::vector< SCH_TEXT * > labels
Definition: sch_io_eagle.h:285
const SEG * LabelAttached(const SCH_TEXT *aLabel) const
< Test if a particular label is attached to any of the stored segments