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_EAGLE_PLUGIN_H_
26#define _SCH_EAGLE_PLUGIN_H_
28#include <sch_line.h>
29#include <sch_io_mgr.h>
31#include <lib_item.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;
53class LIB_SYMBOL;
54class SYMBOL_LIB;
55class LIB_SHAPE;
56class LIB_FIELD;
59class LIB_PIN;
60class LIB_TEXT;
61class wxXmlNode;
66 wxString name;
67 boost::ptr_map<wxString, LIB_SYMBOL> KiCadSymbols;
68 std::unordered_map<wxString, wxXmlNode*> SymbolNodes;
69 std::unordered_map<wxString, int> GateUnit;
70 std::unordered_map<wxString, wxString> package;
73typedef boost::ptr_map<wxString, EPART> EPART_LIST;
84 const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
89 const wxString GetName() const override;
91 void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
93 void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
94 {
95 m_progressReporter = aReporter;
96 }
99 {
100 return PLUGIN_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
101 }
104 {
105 return PLUGIN_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
106 }
108 bool CanReadSchematicFile( const wxString& aFileName ) const override;
109 bool CanReadLibrary( const wxString& aFileName ) const override;
111 int GetModifyHash() const override;
113 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
114 SCH_SHEET* aAppendToMe = nullptr,
115 const STRING_UTF8_MAP* aProperties = nullptr ) override;
117 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
118 const STRING_UTF8_MAP* aProperties ) override;
120 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
121 const STRING_UTF8_MAP* aProperties ) override;
123 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
124 const STRING_UTF8_MAP* aProperties ) override;
126 bool IsSymbolLibWritable( const wxString& aLibraryPath ) override { return false; }
129 void checkpoint();
131 bool checkHeader( const wxString& aFileName ) const;
132 wxXmlDocument loadXmlDocument( const wxString& aFileName );
133 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
134 void ensureLoadedLibrary( const wxString& aLibraryPath );
136 void loadDrawing( wxXmlNode* aDrawingNode );
137 void loadLayerDefs( wxXmlNode* aLayers );
138 void loadSchematic( wxXmlNode* aSchematicNode );
139 void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
140 void loadInstance( wxXmlNode* aInstanceNode );
141 EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
142 void countNets( wxXmlNode* aSchematicNode );
145 void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
149 void addBusEntries();
152 SCH_LAYER_ID kiCadLayer( int aEagleLayer );
154 std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
155 const std::vector<SEG>& aLines ) const;
157 void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
158 const wxString& aNetClass );
159 SCH_SHAPE* loadPolyLine( wxXmlNode* aPolygonNode );
160 SCH_ITEM* loadWire( wxXmlNode* aWireNode, SEG& endpoints );
161 SCH_SHAPE* loadCircle( wxXmlNode* aCircleNode );
162 SCH_SHAPE* loadRectangle( wxXmlNode* aRectNode );
163 SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
164 SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
165 SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
166 void loadFrame( wxXmlNode* aFrameNode, std::vector<SCH_ITEM*>& aItems );
168 bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBOL>& aSymbol,
169 EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
170 LIB_SHAPE* loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aCircleNode,
171 int aGateNumber );
172 LIB_SHAPE* loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aRectNode,
173 int aGateNumber );
174 LIB_SHAPE* loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
175 wxXmlNode* aPolygonNode, int aGateNumber );
176 LIB_ITEM* loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aWireNode,
177 int aGateNumber );
178 LIB_PIN* loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode*, EPIN* epin,
179 int aGateNumber );
180 LIB_TEXT* loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aLibText,
181 int aGateNumber );
182 void loadFrame( wxXmlNode* aFrameNode, std::vector<LIB_ITEM*>& aLines );
184 void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
185 void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
188 void adjustNetLabels();
198 wxString translateEagleBusName( const wxString& aEagleName ) const;
200 wxString getLibName();
201 wxFileName getLibFileName();
204 bool checkConnections( const SCH_SYMBOL* aSymbol, const LIB_PIN* aPin ) const;
218 void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
220 bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
225 // Describe missing units containing pins creating implicit connections
226 // (named power pins in Eagle).
228 {
229 EAGLE_MISSING_CMP( const SCH_SYMBOL* aSymbol = nullptr )
230 : cmp( aSymbol )
231 {
232 }
237 /* Map of the symbol units: for each unit there is a flag saying
238 * whether the unit needs to be instantiated with appropriate net labels to
239 * emulate implicit connections as is done in Eagle.
240 */
241 std::map<int, bool> units;
242 };
247 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
251 wxString m_version;
252 wxFileName m_filename;
253 wxString m_libName;
257 std::map<wxString, long long> m_timestamps;
258 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
259 std::unordered_map<wxString, bool> m_userValue;
262 std::unique_ptr<STRING_UTF8_MAP> m_properties;
265 unsigned m_doneCount;
267 unsigned m_totalCount;
269 std::map<wxString, int> m_netCounts;
270 std::map<int, SCH_LAYER_ID> m_layerMap;
271 std::map<wxString, wxString> m_powerPorts;
276 std::vector<VECTOR2I> m_wireIntersections;
279 struct SEG_DESC
280 {
282 const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
284 std::vector<SCH_TEXT*> labels;
285 std::vector<SEG> segs;
286 };
289 std::vector<SEG_DESC> m_segments;
292 std::map<wxString, ENET> m_nets;
295 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
298#endif // _SCH_EAGLE_PLUGIN_H_
constexpr double SCH_IU_PER_MM
Definition: base_units.h:73
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:279
Field object used in symbol libraries.
Definition: lib_field.h:62
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Define a library symbol object.
Definition: lib_symbol.h:99
Define a symbol library graphical text item.
Definition: lib_text.h:40
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
A progress reporter interface for use in multi-threaded environments.
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
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
A SCH_PLUGIN derivation for loading 6.x+ Eagle schematic files.
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
bool netHasPowerDriver(SCH_LINE *aLine, const wxString &aNetName) const
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
LIB_SHAPE * loadSymbolPolyLine(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *aPolygonNode, int aGateNumber)
SCH_TEXT * loadLabel(wxXmlNode *aLabelNode, const wxString &aNetName)
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 * m_rootSheet
The root sheet of the schematic being loaded.
LIB_ITEM * loadSymbolWire(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *aWireNode, int aGateNumber)
unsigned m_totalCount
for progress reporting
wxXmlDocument loadXmlDocument(const wxString &aFileName)
long long getLibraryTimestamp(const wxString &aLibraryPath) const
std::unique_ptr< STRING_UTF8_MAP > m_properties
Library plugin properties.
void SetReporter(REPORTER *aReporter) override
Set an optional reporter for warnings/errors.
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
void loadSchematic(wxXmlNode *aSchematicNode)
std::map< wxString, long long > m_timestamps
void SetProgressReporter(PROGRESS_REPORTER *aReporter) override
Set an optional progress reporter.
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified schematic file.
SCH_SHEET * getCurrentSheet()
void countNets(wxXmlNode *aSchematicNode)
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...
SCH_SHAPE * loadCircle(wxXmlNode *aCircleNode)
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
int GetModifyHash() const override
Return the modification hash from the library cache.
SCH_SCREEN * getCurrentScreen()
bool checkHeader(const wxString &aFileName) const
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_PLUGIN.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified symbol library file.
const double ARC_ACCURACY
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.
void loadFieldAttributes(LIB_FIELD *aField, const LIB_TEXT *aText) const
Move net labels that are detached from any wire to the nearest wire.
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
std::map< wxString, int > m_netCounts
wxString m_version
Eagle file version.
void loadInstance(wxXmlNode *aInstanceNode)
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.
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
void loadDrawing(wxXmlNode *aDrawingNode)
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_PLUGIN implementation knows about,...
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
Returns symbol library description for the SCH_PLUGIN.
LIB_SHAPE * loadSymbolRectangle(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *aRectNode, int aGateNumber)
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
void loadFrame(wxXmlNode *aFrameNode, std::vector< SCH_ITEM * > &aItems)
REPORTER * m_reporter
Reporter for warnings/errors.
EAGLE_LIBRARY * loadLibrary(wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
LIB_PIN * loadPin(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *, EPIN *epin, int aGateNumber)
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
wxString translateEagleBusName(const wxString &aEagleName) const
Translate an Eagle-style bus name into one that is KiCad-compatible.
bool loadSymbol(wxXmlNode *aSymbolNode, std::unique_ptr< LIB_SYMBOL > &aSymbol, EDEVICE *aDevice, int aGateNumber, const wxString &aGateName)
std::unordered_map< wxString, bool > m_userValue
deviceset/@uservalue for device.
wxString m_libName
Library name to save symbols.
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
void loadLayerDefs(wxXmlNode *aLayers)
LIB_SHAPE * loadSymbolCircle(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *aCircleNode, int aGateNumber)
LIB_TEXT * loadSymbolText(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *aLibText, int aGateNumber)
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void addImplicitConnections(SCH_SYMBOL *aSymbol, SCH_SCREEN *aScreen, bool aUpdateSet)
Create net labels to emulate implicit connections in Eagle.
unsigned m_lastProgressCount
std::map< wxString, ENET > m_nets
Positions of pins and wire endings mapped to its parent.
void loadSegments(wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const VECTOR2I &aPoint, const std::vector< SEG > &aLines) const
std::map< int, SCH_LAYER_ID > m_layerMap
SCH_SHAPE * loadRectangle(wxXmlNode *aRectNode)
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
bool checkConnections(const SCH_SYMBOL *aSymbol, const LIB_PIN *aPin) const
PI to create KiCad symbol library.
void loadSheet(wxXmlNode *aSheetNode, int sheetcount)
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
SCH_SHAPE * loadPolyLine(wxXmlNode *aPolygonNode)
SCH_ITEM * loadWire(wxXmlNode *aWireNode, SEG &endpoints)
void moveLabels(SCH_LINE *aWire, const VECTOR2I &aNewEndPoint)
Move any labels on the wire to the new end point of the wire.
void ensureLoadedLibrary(const wxString &aLibraryPath)
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:151
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:530
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:145
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:81
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
Eeschema drawing layers.
Definition: layer_ids.h:346
boost::ptr_map< wxString, EPART > EPART_LIST
std::unordered_map< wxString, int > GateUnit
std::unordered_map< wxString, wxString > package
boost::ptr_map< wxString, LIB_SYMBOL > KiCadSymbols
std::unordered_map< wxString, wxXmlNode * > SymbolNodes
Eagle pin element.
Definition: eagle_parser.h:748
Eagle text element.
Definition: eagle_parser.h:644
Container that describes file type info.
EAGLE_MISSING_CMP(const SCH_SYMBOL *aSymbol=nullptr)
Link to the parent symbol.
Segments representing wires for intersection checking.
const SEG * LabelAttached(const SCH_TEXT *aLabel) const
< Test if a particular label is attached to any of the stored segments
std::vector< SCH_TEXT * > labels