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_draw_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  //size_t GetSymbolLibCount( const wxString& aLibraryPath,
107  // const PROPERTIES* aProperties = NULL ) override;
108 
109  //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath,
110  // const PROPERTIES* aProperties = NULL ) override;
111 
112  //LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
113  // const PROPERTIES* aProperties = NULL ) override;
114 
115  //void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
116  // const PROPERTIES* aProperties = NULL ) override;
117 
118  //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
119  // const PROPERTIES* aProperties = NULL ) override;
120 
121  //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
122  // const PROPERTIES* aProperties = NULL ) override;
123 
124  //void CreateSymbolLib( const wxString& aLibraryPath,
125  // const PROPERTIES* aProperties = NULL ) override;
126 
127  // bool DeleteSymbolLib( const wxString& aLibraryPath,
128  // const PROPERTIES* aProperties = NULL ) override;
129 
130  //bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
131 
132  //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
133 
134 private:
135  void loadDrawing( wxXmlNode* aDrawingNode );
136  void loadLayerDefs( wxXmlNode* aLayers );
137  void loadSchematic( wxXmlNode* aSchematicNode );
138  void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
139  void loadInstance( wxXmlNode* aInstanceNode );
140  EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
141  void countNets( wxXmlNode* aSchematicNode );
142 
144  void moveLabels( SCH_ITEM* aWire, const wxPoint& aNewEndPoint );
145 
148  void addBusEntries();
149 
151  SCH_LAYER_ID kiCadLayer( int aEagleLayer );
152 
153  std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const wxPoint& aPoint,
154  const std::vector<SEG>& aLines ) const;
155 
156  void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
157  const wxString& aNetClass );
158  SCH_LINE* loadWire( wxXmlNode* aWireNode );
159  SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
160  SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
161  SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
162 
163  bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_PART>& aPart, EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
164  LIB_CIRCLE* loadSymbolCircle( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aCircleNode, int aGateNumber );
165  LIB_RECTANGLE* loadSymbolRectangle( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aRectNode, int aGateNumber );
166  LIB_POLYLINE* loadSymbolPolyLine( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPolygonNode, int aGateNumber );
167  LIB_ITEM* loadSymbolWire( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aWireNode, int aGateNumber );
168  LIB_PIN* loadPin( std::unique_ptr<LIB_PART>& aPart, wxXmlNode*, EPIN* epin, int aGateNumber );
169  LIB_TEXT* loadSymbolText( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aLibText, int aGateNumber );
170 
171  void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
172  void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
173 
175  void adjustNetLabels();
176 
177  wxString getLibName();
178  wxFileName getLibFileName();
179 
183  wxString m_version;
184  wxFileName m_filename;
185  wxString m_libName;
186 
188  std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
189 
191  std::unique_ptr< PROPERTIES > m_properties;
192 
193  std::map<wxString, int> m_netCounts;
194  std::map<int, SCH_LAYER_ID> m_layerMap;
195 
198  std::vector<VECTOR2I> m_wireIntersections;
199 
201  typedef struct {
203  const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
204 
205  std::vector<SCH_TEXT*> labels;
206  std::vector<SEG> segs;
207  } SEG_DESC;
208 
210  std::vector<SEG_DESC> m_segments;
211 
213  std::map<wxPoint, std::set<const EDA_ITEM*>> m_connPoints;
214 
216  bool checkConnections( const SCH_COMPONENT* aComponent, const LIB_PIN* aPin ) const;
217 
218  // Structure describing missing units containing pins creating implicit connections
219  // (named power pins in Eagle).
221  {
222  EAGLE_MISSING_CMP( const SCH_COMPONENT* aComponent = nullptr )
223  : cmp( aComponent )
224  {
225  }
226 
229 
230  /* Map of the component units: for each unit there is a flag saying
231  * whether the unit needs to be instantiated with appropriate net labels to
232  * emulate implicit connections as is done in Eagle.
233  */
234  std::map<int, bool> units;
235  };
236 
238  std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
239 
252  void addImplicitConnections( SCH_COMPONENT* aComponent, SCH_SCREEN* aScreen, bool aUpdateSet );
253 
261  static wxString fixSymbolName( const wxString& aName );
262 };
263 
264 #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&#39;s value...
Definition: sch_field.h:56
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.
Define a symbol library graphical text item.
Definition: lib_text.h:44
std::unordered_map< wxString, wxString > package
std::map< wxString, int > m_netCounts
Field object used in symbol libraries.
Definition: lib_field.h:59
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...
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
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:728
wxString m_libName
Library name to save symbols.
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:188
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
struct EAGLE_LIBRARY EAGLE_LIBRARY
boost::ptr_map< wxString, EPART > EPART_LIST
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
Define a library symbol object.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
wxString m_version
Eagle file version.
SCH_LAYER_ID
Eeschema drawing layers.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
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
std::unordered_map< wxString, int > GateUnit
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:523
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
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
Definition: eagle_parser.h:53
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_TEXT * > labels
Wires and labels of a single connection (segment in Eagle nomenclature)
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
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...
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent