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 * @author Alejandro GarcĂ­a Montoro <alejandro.garciamontoro@gmail.com>
6 * @author Maciej Suminski <maciej.suminski@cern.ch>
7 * @author Russell Oliver <roliver8143@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef _SCH_EAGLE_PLUGIN_H_
24 #define _SCH_EAGLE_PLUGIN_H_
25 
26 #include <wx/xml/xml.h>
27 
28 #include <sch_line.h>
29 #include <sch_io_mgr.h>
30 #include <eagle_parser.h>
31 #include <lib_item.h>
32 #include <geometry/seg.h>
33 #include <dlist.h>
34 
35 #include <boost/ptr_container/ptr_map.hpp>
36 
37 class EDA_TEXT;
38 class KIWAY;
39 class LINE_READER;
40 class SCH_SCREEN;
41 class SCH_SHEET;
42 class SCH_BITMAP;
43 class SCH_JUNCTION;
44 class SCH_NO_CONNECT;
45 class SCH_LINE;
46 class SCH_BUS_ENTRY_BASE;
47 class SCH_TEXT;
48 class SCH_GLOBALLABEL;
49 class SCH_COMPONENT;
50 class SCH_FIELD;
51 class PROPERTIES;
52 class SCH_EAGLE_PLUGIN_CACHE;
53 class LIB_PART;
54 class PART_LIB;
55 class LIB_ALIAS;
56 class LIB_CIRCLE;
57 class LIB_FIELD;
58 class LIB_RECTANGLE;
59 class LIB_POLYLINE;
60 class LIB_PIN;
61 class LIB_TEXT;
62 
63 
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;
72 
73 typedef boost::ptr_map<wxString, EPART> EPART_LIST;
74 
75 
83 {
84 public:
87 
88  const wxString GetName() const override;
89 
90  const wxString GetFileExtension() const override;
91 
92  int GetModifyHash() const override;
93 
94  SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway, SCH_SHEET* aAppendToMe = NULL,
95  const PROPERTIES* aProperties = NULL ) override;
96 
97  bool CheckHeader( const wxString& aFileName ) override;
98 
99 
100  // unimplemented functions. Will trigger a not_implemented IO error.
101  //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
102 
103  //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
104  // const PROPERTIES* aProperties = NULL ) override;
105 
106  //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath,
107  // const PROPERTIES* aProperties = NULL ) override;
108 
109  //LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
110  // const PROPERTIES* aProperties = NULL ) override;
111 
112  //void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
113  // const PROPERTIES* aProperties = NULL ) override;
114 
115  //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
116  // const PROPERTIES* aProperties = NULL ) override;
117 
118  //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
119  // const PROPERTIES* aProperties = NULL ) override;
120 
121  //void CreateSymbolLib( const wxString& aLibraryPath,
122  // const PROPERTIES* aProperties = NULL ) override;
123 
124  // bool DeleteSymbolLib( const wxString& aLibraryPath,
125  // const PROPERTIES* aProperties = NULL ) override;
126 
127  //bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
128 
129  //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
130 
131 private:
132  void loadDrawing( wxXmlNode* aDrawingNode );
133  void loadLayerDefs( wxXmlNode* aLayers );
134  void loadSchematic( wxXmlNode* aSchematicNode );
135  void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
136  void loadInstance( wxXmlNode* aInstanceNode );
137  EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
138  void countNets( wxXmlNode* aSchematicNode );
139 
141  void moveLabels( SCH_ITEM* aWire, const wxPoint& aNewEndPoint );
142 
145  void addBusEntries();
146 
148  SCH_LAYER_ID kiCadLayer( int aEagleLayer );
149 
150  std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const wxPoint& aPoint,
151  const std::vector<SEG>& aLines ) const;
152 
153  void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
154  const wxString& aNetClass );
155  SCH_LINE* loadWire( wxXmlNode* aWireNode );
156  SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
157  SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
158  SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
159 
160  bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_PART>& aPart, EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
161  LIB_CIRCLE* loadSymbolCircle( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aCircleNode, int aGateNumber );
162  LIB_RECTANGLE* loadSymbolRectangle( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aRectNode, int aGateNumber );
163  LIB_POLYLINE* loadSymbolPolyLine( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPolygonNode, int aGateNumber );
164  LIB_ITEM* loadSymbolWire( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aWireNode, int aGateNumber );
165  LIB_PIN* loadPin( std::unique_ptr<LIB_PART>& aPart, wxXmlNode*, EPIN* epin, int aGateNumber );
166  LIB_TEXT* loadSymbolText( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aLibText, int aGateNumber );
167 
168  void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
169  void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
170 
172  void adjustNetLabels();
173 
180  wxString translateEagleBusName( const wxString& aEagleName ) const;
181 
182  wxString getLibName();
183  wxFileName getLibFileName();
184 
188  wxString m_version;
189  wxFileName m_filename;
190  wxString m_libName;
191 
193  std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
194 
196  std::unique_ptr< PROPERTIES > m_properties;
197 
198  std::map<wxString, int> m_netCounts;
199  std::map<int, SCH_LAYER_ID> m_layerMap;
200 
203  std::vector<VECTOR2I> m_wireIntersections;
204 
206  typedef struct {
208  const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
209 
210  std::vector<SCH_TEXT*> labels;
211  std::vector<SEG> segs;
212  } SEG_DESC;
213 
215  std::vector<SEG_DESC> m_segments;
216 
218  std::map<wxPoint, std::set<const EDA_ITEM*>> m_connPoints;
219 
221  bool checkConnections( const SCH_COMPONENT* aComponent, const LIB_PIN* aPin ) const;
222 
223  // Structure describing missing units containing pins creating implicit connections
224  // (named power pins in Eagle).
226  {
227  EAGLE_MISSING_CMP( const SCH_COMPONENT* aComponent = nullptr )
228  : cmp( aComponent )
229  {
230  }
231 
234 
235  /* Map of the component units: for each unit there is a flag saying
236  * whether the unit needs to be instantiated with appropriate net labels to
237  * emulate implicit connections as is done in Eagle.
238  */
239  std::map<int, bool> units;
240  };
241 
243  std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
244 
257  void addImplicitConnections( SCH_COMPONENT* aComponent, SCH_SCREEN* aScreen, bool aUpdateSet );
258 
266  static wxString fixSymbolName( const wxString& aName );
267 };
268 
269 #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)
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const wxPoint &aPoint, const std::vector< SEG > &aLines) const
std::unordered_map< wxString, wxXmlNode * > SymbolNodes
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
Part library alias object definition.
void loadSchematic(wxXmlNode *aSchematicNode)
EAGLE_LIBRARY * loadLibrary(wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
SCH_LINE * loadWire(wxXmlNode *aWireNode)
Define a symbol library graphical text item.
Definition: lib_text.h:40
std::unordered_map< wxString, wxString > package
bool checkConnections(const SCH_COMPONENT *aComponent, const LIB_PIN *aPin) const
Checks if there are other wires or pins at the position of the tested pin
std::map< wxString, int > m_netCounts
Field object used in symbol libraries.
Definition: lib_field.h:59
int GetModifyHash() const override
Return the modification hash from the library cache.
KIWAY * m_kiway
For creating sub sheets.
Class SCH_EAGLE_PLUGIN is a SCH_PLUGIN derivation for loading 6.x+ Eagle schematic files.
std::vector< VECTOR2I > m_wireIntersections
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
LIB_RECTANGLE * loadSymbolRectangle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aRectNode, int aGateNumber)
Eagle text element.
Definition: eagle_parser.h:646
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
Map references to missing component units data
Eagle pin element.
Definition: eagle_parser.h:729
wxString m_libName
Library name to save symbols.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels,...
Definition: eda_text.h:109
LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *, EPIN *epin, int aGateNumber)
static wxString fixSymbolName(const wxString &aName)
Fixes 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:188
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
struct EAGLE_LIBRARY EAGLE_LIBRARY
void adjustNetLabels()
Moves net labels that are detached from any wire to the nearest wire
LIB_CIRCLE * loadSymbolCircle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aCircleNode, int aGateNumber)
void addImplicitConnections(SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
Creates net labels to emulate implicit connections in Eagle.
boost::ptr_map< wxString, EPART > EPART_LIST
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
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.
void loadSegments(wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
wxFileName getLibFileName()
wxString m_version
Eagle file version.
SCH_LAYER_ID
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:42
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
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:36
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:520
const SCH_COMPONENT * cmp
Link to the parent component
std::map< int, SCH_LAYER_ID > m_layerMap
std::vector< SEG_DESC > m_segments
Segments representing wires for intersection checking
void loadFieldAttributes(LIB_FIELD *aField, const LIB_TEXT *aText) const
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
void loadDrawing(wxXmlNode *aDrawingNode)
wxString translateEagleBusName(const wxString &aEagleName) const
Translates 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
Definition: eagle_parser.h:53
const wxString GetName() const override
Returns a brief hard coded name for this SCH_PLUGIN.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
void moveLabels(SCH_ITEM *aWire, const wxPoint &aNewEndPoint)
Moves any labels on the wire to the new end point of the wire.
SCH_SHEET * Load(const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
std::vector< SCH_TEXT * > labels
LIB_TEXT * loadSymbolText(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aLibText, int aGateNumber)
Wires and labels of a single connection (segment in Eagle nomenclature)
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
void countNets(wxXmlNode *aSchematicNode)
const wxString GetFileExtension() const override
Returns the file extension for the SCH_PLUGIN.
void loadSheet(wxXmlNode *aSheetNode, int sheetcount)
boost::ptr_map< wxString, LIB_PART > KiCadSymbols
Object used to load, save, search, and otherwise manipulate symbol library files.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
LIB_POLYLINE * loadSymbolPolyLine(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aPolygonNode, int aGateNumber)
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent