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 LIB_SYMBOL;
51class SYMBOL_LIB;
52class SCH_PIN;
53class wxXmlNode;
54
55
57{
58 wxString name;
59 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> KiCadSymbols;
60
68 std::unordered_map<wxString, int> GateToUnitMap;
69 std::unordered_map<wxString, wxString> package;
70};
71
72
78class SCH_IO_EAGLE : public SCH_IO
79{
80public:
81 const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
82
85
87 {
88 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
89 }
90
92 {
93 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
94 }
95
96 bool CanReadSchematicFile( const wxString& aFileName ) const override;
97 bool CanReadLibrary( const wxString& aFileName ) const override;
98
99 int GetModifyHash() const override;
100
101 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
102 SCH_SHEET* aAppendToMe = nullptr,
103 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
104
105 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
106 const std::map<std::string, UTF8>* aProperties ) override;
107
108 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
109 const std::map<std::string, UTF8>* aProperties ) override;
110
111 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
112 const std::map<std::string, UTF8>* aProperties ) override;
113
114 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
115
116private:
117 bool checkHeader( const wxString& aFileName ) const;
118 wxXmlDocument loadXmlDocument( const wxString& aFileName );
119 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
120 void ensureLoadedLibrary( const wxString& aLibraryPath );
121
122 void loadDrawing( const std::unique_ptr<EDRAWING>& aDrawing );
123 void loadLayerDefs( const std::vector<std::unique_ptr<ELAYER>>& aLayers );
124 void loadSchematic( const ESCHEMATIC& aSchematic );
125 void loadSheet( const std::unique_ptr<ESHEET>& aSheet );
126 void loadInstance( const std::unique_ptr<EINSTANCE>& aInstance,
127 const std::map<wxString, std::unique_ptr<EPART>>& aParts );
128
129 SCH_SHEET* loadModuleInstance( const std::unique_ptr<EMODULEINST>& aModuleInstance );
130
131 EAGLE_LIBRARY* loadLibrary( const ELIBRARY* aLibrary, EAGLE_LIBRARY* aEagleLib );
132 void countNets( const ESCHEMATIC& aSchematic );
133
135 void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
136
139 void addBusEntries();
140
142 SCH_LAYER_ID kiCadLayer( int aEagleLayer );
143
144 std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
145 const std::vector<SEG>& aLines ) const;
146
147 void loadSegments( const std::vector<std::unique_ptr<ESEGMENT>>& aSegments,
148 const wxString& aNetName,
149 const wxString& aNetClass );
150 SCH_SHAPE* loadPolyLine( const std::unique_ptr<EPOLYGON>& aPolygon );
151 SCH_ITEM* loadWire( const std::unique_ptr<EWIRE>& aWire, SEG& endpoints );
152 SCH_SHAPE* loadCircle( const std::unique_ptr<ECIRCLE>& aCircle );
153 SCH_SHAPE* loadRectangle( const std::unique_ptr<ERECT>& aRect );
154 SCH_TEXT* loadLabel( const std::unique_ptr<ELABEL>& aLabel, const wxString& aNetName );
155 SCH_JUNCTION* loadJunction( const std::unique_ptr<EJUNCTION>& aJunction );
156 SCH_TEXT* loadPlainText( const std::unique_ptr<ETEXT>& aSchText );
157 void loadFrame( const std::unique_ptr<EFRAME>& aFrame,
158 std::vector<SCH_ITEM*>& aItems );
159
160 bool loadSymbol( const std::unique_ptr<ESYMBOL>& aEsymbol,
161 std::unique_ptr<LIB_SYMBOL>& aSymbol,
162 const std::unique_ptr<EDEVICE>& aDevice, int aGateNumber,
163 const wxString& aGateName );
164 SCH_SHAPE* loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
165 const std::unique_ptr<ECIRCLE>& aCircle,
166 int aGateNumber );
167 SCH_SHAPE* loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
168 const std::unique_ptr<ERECT>& aRectangle,
169 int aGateNumber );
170 SCH_SHAPE* loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
171 const std::unique_ptr<EPOLYGON>& aPolygon, int aGateNumber );
172 SCH_ITEM* loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol,
173 const std::unique_ptr<EWIRE>& aWire,
174 int aGateNumber );
175 SCH_PIN* loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, const std::unique_ptr<EPIN>& aPin,
176 int aGateNumber );
177 SCH_TEXT* loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol,
178 const std::unique_ptr<ETEXT>& aText,
179 int aGateNumber );
180 void loadTextAttributes( EDA_TEXT* aText,
181 const std::unique_ptr<ETEXT>& aAttributes ) const;
182 void loadFieldAttributes( SCH_FIELD* aField, const SCH_TEXT* aText ) const;
183
185 void adjustNetLabels();
186
195 wxString translateEagleBusName( const wxString& aEagleName ) const;
196
197 wxString getLibName();
198 wxFileName getLibFileName();
199
201 bool checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const;
202
215 void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
216
217 bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
218
219 void getEagleSymbolFieldAttributes( const std::unique_ptr<EINSTANCE>& aInstance,
220 const wxString& aEagleFieldName,
221 SCH_FIELD* aField );
222 const ESYMBOL* getEagleSymbol( const std::unique_ptr<EINSTANCE>& aInstance );
223
226
227 // Describe missing units containing pins creating implicit connections
228 // (named power pins in Eagle).
230 {
231 EAGLE_MISSING_CMP( const SCH_SYMBOL* aSymbol = nullptr )
232 : cmp( aSymbol )
233 {
234 }
235
238
239 /* Map of the symbol units: for each unit there is a flag saying
240 * whether the unit needs to be instantiated with appropriate net labels to
241 * emulate implicit connections as is done in Eagle.
242 */
243 std::map<int, bool> units;
244 };
245
247 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
248
251 wxString m_version;
252 wxFileName m_filename;
253 wxString m_libName;
256
257 std::map<wxString, const EPART*> m_partlist;
258 std::map<wxString, long long> m_timestamps;
259 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
260 std::map<wxString, std::unique_ptr<EMODULE>> m_eagleModules;
261
262 std::unordered_map<wxString, bool> m_userValue;
263
265 std::unique_ptr<std::map<std::string, UTF8>> m_properties;
266
268
269 std::map<wxString, int> m_netCounts;
270 std::map<int, SCH_LAYER_ID> m_layerMap;
271 std::map<wxString, wxString> m_powerPorts;
273
276 std::vector<VECTOR2I> m_wireIntersections;
277
279 struct SEG_DESC
280 {
282 const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
283
284 std::vector<SCH_TEXT*> labels;
285 std::vector<SEG> segs;
286 };
287
289 std::vector<SEG_DESC> m_segments;
290
292 std::map<wxString, ENET> m_nets;
293
295 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
296
298 std::unique_ptr<EAGLE_DOC> m_eagleDoc;
299};
300
301#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:80
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
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:77
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
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:79
std::unique_ptr< EAGLE_DOC > m_eagleDoc
Definition: sch_io_eagle.h:298
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:260
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)
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:271
SCH_SHEET_PATH m_sheetPath
The current sheet path of the schematic being loaded.
Definition: sch_io_eagle.h:250
wxString m_libName
Library name to save symbols.
Definition: sch_io_eagle.h:253
EMODULE * m_module
The current module being loaded or nullptr.
Definition: sch_io_eagle.h:255
SCH_TEXT * loadSymbolText(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ETEXT > &aText, int aGateNumber)
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const VECTOR2I &aPoint, const std::vector< SEG > &aLines) const
const double ARC_ACCURACY
Definition: sch_io_eagle.h:81
std::map< wxString, long long > m_timestamps
Definition: sch_io_eagle.h:258
void adjustNetLabels()
void loadInstance(const std::unique_ptr< EINSTANCE > &aInstance, const std::map< wxString, std::unique_ptr< EPART > > &aParts)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
std::unordered_map< wxString, bool > m_userValue
deviceset/@uservalue for device.
Definition: sch_io_eagle.h:262
int GetModifyHash() const override
Return the modification hash from the library cache.
std::map< wxString, int > m_netCounts
Definition: sch_io_eagle.h:269
wxFileName m_filename
Definition: sch_io_eagle.h:252
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
Definition: sch_io_eagle.h:259
std::map< wxString, ENET > m_nets
Positions of pins and wire endings mapped to its parent.
Definition: sch_io_eagle.h:292
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)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
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:276
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
The fully parsed Eagle schematic file.
Definition: sch_io_eagle.h:295
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
std::unique_ptr< std::map< std::string, UTF8 > > m_properties
Library plugin properties.
Definition: sch_io_eagle.h:265
IO_RELEASER< SCH_IO > m_pi
PI to create KiCad symbol library.
Definition: sch_io_eagle.h:264
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:270
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
wxString getLibName()
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
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)
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
Definition: sch_io_eagle.h:86
SCH_JUNCTION * loadJunction(const std::unique_ptr< EJUNCTION > &aJunction)
wxString m_version
Eagle file version.
Definition: sch_io_eagle.h:251
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:91
std::map< wxString, const EPART * > m_partlist
Definition: sch_io_eagle.h:257
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:254
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: sch_io_eagle.h:114
void countNets(const ESCHEMATIC &aSchematic)
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
Definition: sch_io_eagle.h:249
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:247
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:289
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:104
Definition: seg.h:42
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:353
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > KiCadSymbols
Definition: sch_io_eagle.h:59
std::unordered_map< wxString, wxString > package
Definition: sch_io_eagle.h:69
wxString name
Definition: sch_io_eagle.h:58
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:68
Container that describes file type info.
Definition: io_base.h:43
Map references to missing symbol units data.
Definition: sch_io_eagle.h:230
EAGLE_MISSING_CMP(const SCH_SYMBOL *aSymbol=nullptr)
Link to the parent symbol.
Definition: sch_io_eagle.h:231
std::map< int, bool > units
Definition: sch_io_eagle.h:243
Segments representing wires for intersection checking.
Definition: sch_io_eagle.h:280
std::vector< SEG > segs
Definition: sch_io_eagle.h:285
std::vector< SCH_TEXT * > labels
Definition: sch_io_eagle.h:284
const SEG * LabelAttached(const SCH_TEXT *aLabel) const
< Test if a particular label is attached to any of the stored segments