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 The 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_LABEL_BASE;
45class SCH_LINE;
47class SCH_TEXT;
48class SCH_GLOBALLABEL;
49class SCH_SYMBOL;
50class SCH_FIELD;
51class LIB_SYMBOL;
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 int ARC_ACCURACY = KiROUND( 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 std::map<std::string, UTF8>* aProperties = nullptr ) override;
105
106 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
107 const std::map<std::string, UTF8>* aProperties ) override;
108
109 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
110 const std::map<std::string, UTF8>* aProperties ) override;
111
112 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
113 const std::map<std::string, UTF8>* 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 void 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_LABEL_BASE* 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, SCH_SCREEN* aScreen = nullptr )
233 : cmp( aSymbol ), screen( aScreen )
234 {
235 }
236
239
242
243 /* Map of the symbol units: for each unit there is a flag saying
244 * whether the unit needs to be instantiated with appropriate net labels to
245 * emulate implicit connections as is done in Eagle.
246 */
247 std::map<int, bool> units;
248 };
249
251 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
252
255 wxString m_version;
256 wxFileName m_filename;
257 wxString m_libName;
259 std::vector<EMODULE*> m_modules;
260 std::vector<EMODULEINST*> m_moduleInstances;
261
262 std::map<wxString, const EPART*> m_partlist;
263 std::map<wxString, long long> m_timestamps;
264 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
265 std::map<wxString, std::unique_ptr<EMODULE>> m_eagleModules;
266
267 std::unordered_map<wxString, bool> m_userValue;
268
270
272 std::map<wxString, int> m_netCounts;
273 std::map<int, SCH_LAYER_ID> m_layerMap;
274 std::map<wxString, wxString> m_powerPorts;
276
279 std::vector<VECTOR2I> m_wireIntersections;
280
282 struct SEG_DESC
283 {
285 const SEG* LabelAttached( const SCH_LABEL_BASE* aLabel ) const;
286
287 std::vector<SCH_LABEL_BASE*> labels;
288 std::vector<SEG> segs;
289 };
290
292 std::vector<SEG_DESC> m_segments;
293
295 std::map<wxString, ENET> m_nets;
296
298 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
299
301 std::unique_ptr<EAGLE_DOC> m_eagleDoc;
302};
303
304#endif // SCH_IO_EAGLE_H_
constexpr double SCH_IU_PER_MM
Schematic internal units 1=100nm.
Definition base_units.h:74
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:93
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:315
Object used to load, save, search, and otherwise manipulate symbol library files.
Define a library symbol object.
Definition lib_symbol.h:83
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:66
Holds all the data relating to one schematic.
Definition schematic.h:89
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.
std::unique_ptr< EAGLE_DOC > m_eagleDoc
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
void loadModuleInstance(const std::unique_ptr< EMODULEINST > &aModuleInstance)
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
SCH_SHEET_PATH m_sheetPath
The current sheet path of the schematic being loaded.
wxString m_libName
Library name to save symbols.
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
std::map< wxString, long long > m_timestamps
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.
int GetModifyHash() const override
Return the modification hash from the library cache.
std::map< wxString, int > m_netCounts
wxFileName m_filename
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
std::map< wxString, ENET > m_nets
Positions of pins and wire endings mapped to its parent.
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_LABEL_BASE * loadLabel(const std::unique_ptr< ELABEL > &aLabel, const wxString &aNetName)
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)
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
The fully parsed Eagle schematic file.
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.
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...
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
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.
SCH_JUNCTION * loadJunction(const std::unique_ptr< EJUNCTION > &aJunction)
wxString m_version
Eagle file version.
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.
std::map< wxString, const EPART * > m_partlist
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.
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void countNets(const ESCHEMATIC &aSchematic)
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
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
void loadFrame(const std::unique_ptr< EFRAME > &aFrame, std::vector< SCH_ITEM * > &aItems)
const int ARC_ACCURACY
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
std::vector< EMODULE * > m_modules
The current module stack being loaded.
std::vector< EMODULEINST * > m_moduleInstances
SCH_ITEM * loadSymbolWire(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EWIRE > &aWire, int aGateNumber)
long long getLibraryTimestamp(const wxString &aLibraryPath) const
SCH_IO(const wxString &aName)
Definition sch_io.h:375
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
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:48
Schematic symbol object.
Definition sch_symbol.h:76
Definition seg.h:42
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:451
#define _HKI(x)
Definition page_info.cpp:44
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > KiCadSymbols
std::unordered_map< wxString, wxString > package
wxString name
std::unordered_map< wxString, int > GateToUnitMap
Map Eagle gate unit number (which are strings) to KiCad library symbol unit number.
Container that describes file type info.
Definition io_base.h:43
const SCH_SYMBOL * cmp
Screen where the parent symbol is located.
EAGLE_MISSING_CMP(const SCH_SYMBOL *aSymbol=nullptr, SCH_SCREEN *aScreen=nullptr)
Link to the parent symbol.
std::map< int, bool > units
Segments representing wires for intersection checking.
std::vector< SEG > segs
std::vector< SCH_LABEL_BASE * > labels
const SEG * LabelAttached(const SCH_LABEL_BASE *aLabel) const
< Test if a particular label is attached to any of the stored segments
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687