KiCad PCB EDA Suite
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 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Alejandro GarcĂ­a Montoro <>
8  * @author Maciej Suminski <>
9  * @author Russell Oliver <>
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 <wx/xml/xml.h>
30 #include <sch_line.h>
31 #include <sch_io_mgr.h>
33 #include <lib_item.h>
34 #include <geometry/seg.h>
36 #include <boost/ptr_container/ptr_map.hpp>
38 class EDA_TEXT;
39 class KIWAY;
40 class LINE_READER;
41 class SCH_SCREEN;
42 class SCH_SHEET;
43 class SCH_BITMAP;
44 class SCH_JUNCTION;
45 class SCH_NO_CONNECT;
46 class SCH_LINE;
48 class SCH_TEXT;
51 class SCH_FIELD;
52 class PROPERTIES;
54 class LIB_PART;
55 class PART_LIB;
56 class LIB_CIRCLE;
57 class LIB_FIELD;
59 class LIB_POLYLINE;
60 class LIB_PIN;
61 class LIB_TEXT;
64 typedef struct EAGLE_LIBRARY
65 {
66  wxString name;
67  boost::ptr_map<wxString, LIB_PART> KiCadSymbols;
68  std::unordered_map<wxString, wxXmlNode*> SymbolNodes;
69  std::unordered_map<wxString, int> GateUnit;
70  std::unordered_map<wxString, wxString> package;
73 typedef boost::ptr_map<wxString, EPART> EPART_LIST;
82 {
83 public:
87  const wxString GetName() const override;
89  void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
91  const wxString GetFileExtension() const override;
93  const wxString GetLibraryFileExtension() const override;
95  int GetModifyHash() const override;
97  SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
98  SCH_SHEET* aAppendToMe = nullptr,
99  const PROPERTIES* aProperties = nullptr ) override;
101  bool CheckHeader( const wxString& aFileName ) override;
104 private:
105  void loadDrawing( wxXmlNode* aDrawingNode );
106  void loadLayerDefs( wxXmlNode* aLayers );
107  void loadSchematic( wxXmlNode* aSchematicNode );
108  void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
109  void loadInstance( wxXmlNode* aInstanceNode );
110  EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
111  void countNets( wxXmlNode* aSchematicNode );
114  void moveLabels( SCH_ITEM* aWire, const wxPoint& aNewEndPoint );
118  void addBusEntries();
121  SCH_LAYER_ID kiCadLayer( int aEagleLayer );
123  std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const wxPoint& aPoint,
124  const std::vector<SEG>& aLines ) const;
126  void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
127  const wxString& aNetClass );
128  SCH_LINE* loadWire( wxXmlNode* aWireNode );
129  SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
130  SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
131  SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
132  void loadFrame( wxXmlNode* aFrameNode, std::vector<SCH_LINE*>& aLines );
134  bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_PART>& aPart,
135  EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
136  LIB_CIRCLE* loadSymbolCircle( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aCircleNode,
137  int aGateNumber );
138  LIB_RECTANGLE* loadSymbolRectangle( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aRectNode,
139  int aGateNumber );
140  LIB_POLYLINE* loadSymbolPolyLine( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPolygonNode,
141  int aGateNumber );
142  LIB_ITEM* loadSymbolWire( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aWireNode,
143  int aGateNumber );
144  LIB_PIN* loadPin( std::unique_ptr<LIB_PART>& aPart, wxXmlNode*, EPIN* epin,
145  int aGateNumber );
146  LIB_TEXT* loadSymbolText( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aLibText,
147  int aGateNumber );
148  void loadFrame( wxXmlNode* aFrameNode, std::vector<LIB_ITEM*>& aLines );
150  void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
151  void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
154  void adjustNetLabels();
164  wxString translateEagleBusName( const wxString& aEagleName ) const;
166  wxString getLibName();
167  wxFileName getLibFileName();
170  bool checkConnections( const SCH_COMPONENT* aComponent, const LIB_PIN* aPin ) const;
184  void addImplicitConnections( SCH_COMPONENT* aComponent, SCH_SCREEN* aScreen, bool aUpdateSet );
186  bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
196  static wxString fixSymbolName( const wxString& aName );
198  // Describe missing units containing pins creating implicit connections
199  // (named power pins in Eagle).
201  {
202  EAGLE_MISSING_CMP( const SCH_COMPONENT* aComponent = nullptr )
203  : cmp( aComponent )
204  {
205  }
210  /* Map of the component units: for each unit there is a flag saying
211  * whether the unit needs to be instantiated with appropriate net labels to
212  * emulate implicit connections as is done in Eagle.
213  */
214  std::map<int, bool> units;
215  };
220  std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
224  wxString m_version;
225  wxFileName m_filename;
226  wxString m_libName;
230  std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
233  std::unique_ptr< PROPERTIES > m_properties;
235  std::map<wxString, int> m_netCounts;
236  std::map<int, SCH_LAYER_ID> m_layerMap;
240  std::vector<VECTOR2I> m_wireIntersections;
243  typedef struct SEG_DESC_STRUCT
244  {
246  const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
248  std::vector<SCH_TEXT*> labels;
249  std::vector<SEG> segs;
250  } SEG_DESC;
253  std::vector<SEG_DESC> m_segments;
256  std::map<wxString, ENET> m_nets;
259  std::map<wxPoint, std::set<const EDA_ITEM*>> m_connPoints;
260 };
262 #endif // _SCH_EAGLE_PLUGIN_H_
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
EAGLE_MISSING_CMP(const SCH_COMPONENT *aComponent=nullptr)
Link to the parent component.
Instances are attached to a symbol or sheet and provide a place for the component's value,...
Definition: sch_field.h:50
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const wxPoint &aPoint, const std::vector< SEG > &aLines) const
const wxString GetLibraryFileExtension() const override
Return the library file extension for the SCH_PLUGIN object.
std::unordered_map< wxString, wxXmlNode * > SymbolNodes
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
void loadSchematic(wxXmlNode *aSchematicNode)
EAGLE_LIBRARY * loadLibrary(wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
Holds all the data relating to one schematic.
Definition: schematic.h:59
SCH_LINE * loadWire(wxXmlNode *aWireNode)
Define a symbol library graphical text item.
Definition: lib_text.h:39
std::unordered_map< wxString, wxString > package
bool checkConnections(const SCH_COMPONENT *aComponent, const LIB_PIN *aPin) const
std::map< wxString, int > m_netCounts
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetReporter(REPORTER *aReporter) override
Set an optional reporter for warnings/errors.
int GetModifyHash() const override
Return the modification hash from the library cache.
A SCH_PLUGIN derivation for loading 6.x+ Eagle schematic files.
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
A name/value tuple with unique names and optional values.
Definition: properties.h:33
LIB_RECTANGLE * loadSymbolRectangle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aRectNode, int aGateNumber)
Eagle text element.
Definition: eagle_parser.h:637
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
Eagle pin element.
Definition: eagle_parser.h:741
wxString m_libName
Library name to save symbols.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:42
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
bool netHasPowerDriver(SCH_LINE *aLine, const wxString &aNetName) const
LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *, EPIN *epin, int aGateNumber)
static wxString fixSymbolName(const wxString &aName)
Fix invalid characters in Eagle symbol names.
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:151
bool CheckHeader(const wxString &aFileName) override
Return true if the first line in aFileName begins with the expected header.
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
LIB_CIRCLE * loadSymbolCircle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aCircleNode, int aGateNumber)
void addImplicitConnections(SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
Create net labels to emulate implicit connections in Eagle.
boost::ptr_map< wxString, EPART > EPART_LIST
Plugin to create the KiCad symbol library.
SCH_TEXT * loadLabel(wxXmlNode *aLabelNode, const wxString &aNetName)
bool loadSymbol(wxXmlNode *aSymbolNode, std::unique_ptr< LIB_PART > &aPart, EDEVICE *aDevice, int aGateNumber, const wxString &aGateName)
Define a library symbol object.
Definition: lib_symbol.h:93
void loadSegments(wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
wxString m_version
Eagle file version.
void loadFrame(wxXmlNode *aFrameNode, std::vector< SCH_LINE * > &aLines)
Eeschema drawing layers.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
LIB_ITEM * loadSymbolWire(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aWireNode, int aGateNumber)
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void addBusEntries()
This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Ea...
std::unordered_map< wxString, int > GateUnit
void loadLayerDefs(wxXmlNode *aLayers)
void loadInstance(wxXmlNode *aInstanceNode)
Definition: seg.h:41
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:473
std::map< int, SCH_LAYER_ID > m_layerMap
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
void loadFieldAttributes(LIB_FIELD *aField, const LIB_TEXT *aText) const
Move net labels that are detached from any wire to the nearest wire.
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
void loadDrawing(wxXmlNode *aDrawingNode)
wxString translateEagleBusName(const wxString &aEagleName) const
Translate an Eagle-style bus name into one that is KiCad-compatible.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
Translates Eagle special characters to their counterparts in KiCad.
Definition: eagle_parser.h:52
REPORTER * m_reporter
Reporter for warnings/errors.
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
Schematic symbol object.
Definition: sch_symbol.h:78
void moveLabels(SCH_ITEM *aWire, const wxPoint &aNewEndPoint)
Move any labels on the wire to the new end point of the wire.
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
LIB_TEXT * loadSymbolText(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aLibText, int aGateNumber)
Segments representing wires for intersection checking.
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
void countNets(wxXmlNode *aSchematicNode)
const wxString GetFileExtension() const override
Return the file extension for the SCH_PLUGIN.
void loadSheet(wxXmlNode *aSheetNode, int sheetcount)
boost::ptr_map< wxString, LIB_PART > KiCadSymbols
const SEG * LabelAttached(const SCH_TEXT *aLabel) const
< Test if a particular label is attached to any of the stored segments
Object used to load, save, search, and otherwise manipulate symbol library files.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
std::vector< SCH_TEXT * > labels
LIB_POLYLINE * loadSymbolPolyLine(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aPolygonNode, int aGateNumber)
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
std::map< wxString, ENET > m_nets
Positions of pins and wire endings mapped to its parent.