KiCad PCB EDA Suite
sch_eagle_plugin.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 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_EAGLE_PLUGIN_H_
26#define _SCH_EAGLE_PLUGIN_H_
27
28#include <sch_line.h>
29#include <sch_io_mgr.h>
31#include <lib_item.h>
32#include <geometry/seg.h>
33
34#include <boost/ptr_container/ptr_map.hpp>
35
36class EDA_TEXT;
37class KIWAY;
38class LINE_READER;
39class SCH_SCREEN;
40class SCH_SHEET;
41class SCH_BITMAP;
42class SCH_JUNCTION;
43class SCH_NO_CONNECT;
44class SCH_LINE;
46class SCH_TEXT;
47class SCH_GLOBALLABEL;
48class SCH_SYMBOL;
49class SCH_FIELD;
50class PROPERTIES;
51class SCH_EAGLE_PLUGIN_CACHE;
52class LIB_SYMBOL;
53class SYMBOL_LIB;
54class LIB_SHAPE;
55class LIB_FIELD;
56class LIB_RECTANGLE;
57class LIB_POLYLINE;
58class LIB_PIN;
59class LIB_TEXT;
60class wxXmlNode;
61
62
64{
65 wxString name;
66 boost::ptr_map<wxString, LIB_SYMBOL> KiCadSymbols;
67 std::unordered_map<wxString, wxXmlNode*> SymbolNodes;
68 std::unordered_map<wxString, int> GateUnit;
69 std::unordered_map<wxString, wxString> package;
70};
71
72typedef boost::ptr_map<wxString, EPART> EPART_LIST;
73
74
81{
82public:
85
86 const wxString GetName() const override;
87
88 void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
89
90 void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
91 {
92 m_progressReporter = aReporter;
93 }
94
95 const wxString GetFileExtension() const override;
96
97 const wxString GetLibraryFileExtension() const override;
98
99 int GetModifyHash() const override;
100
101 SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
102 SCH_SHEET* aAppendToMe = nullptr,
103 const PROPERTIES* aProperties = nullptr ) override;
104
105 bool CheckHeader( const wxString& aFileName ) override;
106
107private:
108 void checkpoint();
109
110 void loadDrawing( wxXmlNode* aDrawingNode );
111 void loadLayerDefs( wxXmlNode* aLayers );
112 void loadSchematic( wxXmlNode* aSchematicNode );
113 void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
114 void loadInstance( wxXmlNode* aInstanceNode );
115 EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
116 void countNets( wxXmlNode* aSchematicNode );
117
119 void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
120
123 void addBusEntries();
124
126 SCH_LAYER_ID kiCadLayer( int aEagleLayer );
127
128 std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
129 const std::vector<SEG>& aLines ) const;
130
131 void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
132 const wxString& aNetClass );
133 SCH_LINE* loadWire( wxXmlNode* aWireNode );
134 SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
135 SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
136 SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
137 void loadFrame( wxXmlNode* aFrameNode, std::vector<SCH_LINE*>& aLines );
138
139 bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBOL>& aSymbol,
140 EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
141 LIB_SHAPE* loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aCircleNode,
142 int aGateNumber );
143 LIB_SHAPE* loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aRectNode,
144 int aGateNumber );
145 LIB_SHAPE* loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
146 wxXmlNode* aPolygonNode, int aGateNumber );
147 LIB_ITEM* loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aWireNode,
148 int aGateNumber );
149 LIB_PIN* loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode*, EPIN* epin,
150 int aGateNumber );
151 LIB_TEXT* loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aLibText,
152 int aGateNumber );
153 void loadFrame( wxXmlNode* aFrameNode, std::vector<LIB_ITEM*>& aLines );
154
155 void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
156 void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
157
159 void adjustNetLabels();
160
169 wxString translateEagleBusName( const wxString& aEagleName ) const;
170
171 wxString getLibName();
172 wxFileName getLibFileName();
173
175 bool checkConnections( const SCH_SYMBOL* aSymbol, const LIB_PIN* aPin ) const;
176
189 void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
190
191 bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
192
193 // Describe missing units containing pins creating implicit connections
194 // (named power pins in Eagle).
196 {
197 EAGLE_MISSING_CMP( const SCH_SYMBOL* aSymbol = nullptr )
198 : cmp( aSymbol )
199 {
200 }
201
204
205 /* Map of the symbol units: for each unit there is a flag saying
206 * whether the unit needs to be instantiated with appropriate net labels to
207 * emulate implicit connections as is done in Eagle.
208 */
209 std::map<int, bool> units;
210 };
211
213
215 std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
216
219 wxString m_version;
220 wxFileName m_filename;
221 wxString m_libName;
223
225 std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
226
228 std::unique_ptr< PROPERTIES > m_properties;
229
231 unsigned m_doneCount;
233 unsigned m_totalCount;
234
235 std::map<wxString, int> m_netCounts;
236 std::map<int, SCH_LAYER_ID> m_layerMap;
237 std::map<wxString, wxString> m_powerPorts;
239
242 std::vector<VECTOR2I> m_wireIntersections;
243
245 struct SEG_DESC
246 {
248 const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
249
250 std::vector<SCH_TEXT*> labels;
251 std::vector<SEG> segs;
252 };
253
255 std::vector<SEG_DESC> m_segments;
256
258 std::map<wxString, ENET> m_nets;
259
261 std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
262};
263
264#endif // _SCH_EAGLE_PLUGIN_H_
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:73
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:267
Field object used in symbol libraries.
Definition: lib_field.h:60
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:62
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:81
A progress reporter interface for use in multi-threaded environments.
A name/value tuple with unique names and optional values.
Definition: properties.h:34
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:60
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)
const wxString GetLibraryFileExtension() const override
Return the library file extension for the SCH_PLUGIN object.
unsigned m_totalCount
for progress reporting
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)
void SetProgressReporter(PROGRESS_REPORTER *aReporter) override
Set an optional progress reporter.
void countNets(wxXmlNode *aSchematicNode)
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
int GetModifyHash() const override
Return the modification hash from the library cache.
SCH_LINE * loadWire(wxXmlNode *aWireNode)
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
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
void loadDrawing(wxXmlNode *aDrawingNode)
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,...
LIB_SHAPE * loadSymbolRectangle(std::unique_ptr< LIB_SYMBOL > &aSymbol, wxXmlNode *aRectNode, int aGateNumber)
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
const wxString GetFileExtension() const override
Return the file extension for the SCH_PLUGIN.
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)
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)
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
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
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
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
std::map< int, SCH_LAYER_ID > m_layerMap
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
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
PI to create KiCad symbol library.
void loadFrame(wxXmlNode *aFrameNode, std::vector< SCH_LINE * > &aLines)
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
bool CheckHeader(const wxString &aFileName) override
Return true if the first line in aFileName begins with the expected header.
void moveLabels(SCH_LINE *aWire, const VECTOR2I &aNewEndPoint)
Move any labels on the wire to the new end point of the wire.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:38
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:480
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:153
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
Schematic symbol object.
Definition: sch_symbol.h:79
Definition: seg.h:42
Object used to load, save, search, and otherwise manipulate symbol library files.
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
Translates Eagle special characters to their counterparts in KiCad.
Definition: eagle_parser.h:52
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
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:740
Eagle text element.
Definition: eagle_parser.h:636
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