KiCad PCB EDA Suite
legacy_plugin.h
Go to the documentation of this file.
1 #ifndef LEGACY_PLUGIN_H_
2 #define LEGACY_PLUGIN_H_
3 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
8  * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <io_mgr.h>
29 #include <string>
31 #include <memory>
32 
33 
34 // FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
35 // a footprint library. A few variants may have been used, and so we can only be
36 // sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
37 
38 #define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
39 #define FOOTPRINT_LIBRARY_HEADER_CNT 18
40 
41 class PCB_TARGET;
42 class MODULE;
43 class DRAWSEGMENT;
44 class NETINFO;
45 class TEXTE_PCB;
46 class TRACK;
47 class NETCLASS;
48 class NETCLASSES;
49 class ZONE_CONTAINER;
50 class DIMENSION;
51 class NETINFO_ITEM;
52 class NETINFO_MAPPING;
53 class TEXTE_MODULE;
54 class EDGE_MODULE;
55 class TRACK;
56 class SEGZONE;
57 class D_PAD;
58 struct LP_CACHE;
59 
60 
66 class LEGACY_PLUGIN : public PLUGIN
67 {
68  friend struct LP_CACHE;
69 
70 public:
71 
72  //-----<PLUGIN API>---------------------------------------------------------
73 
74  const wxString PluginName() const override
75  {
76  return wxT( "KiCad-Legacy" );
77  }
78 
79  const wxString GetFileExtension() const override
80  {
81  return wxT( "brd" );
82  }
83 
84  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
85  const PROPERTIES* aProperties = NULL ) override;
86 
87  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
88  const PROPERTIES* aProperties = NULL ) override;
89 
90  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
91  const PROPERTIES* aProperties = NULL ) override;
92 
93  bool FootprintLibDelete( const wxString& aLibraryPath,
94  const PROPERTIES* aProperties = NULL ) override;
95 
96  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
97 
98  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;
99 
100  //-----</PLUGIN API>--------------------------------------------------------
101 
102  typedef int BIU;
103 
104  LEGACY_PLUGIN();
105  ~LEGACY_PLUGIN();
106 
107  void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
108  void SetFilePtr( FILE* aFile ) { m_fp = aFile; }
109 
110  void SaveModule3D( const MODULE* aModule ) const;
111 
112  // return the new .kicad_pcb layer id from the old (legacy) layer id
113  static PCB_LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum );
114 
115  static LSET leg_mask2new( int cu_count, unsigned aMask );
116 
117 protected:
118 
120 
121  wxString m_error;
124 
126  FILE* m_fp;
127 
128  wxString m_field;
131 
133  std::vector<int> m_netCodes;
135 
137  void init( const PROPERTIES* aProperties );
138 
139  double biuToDisk;
140 
142  double diskToBiu;
143 
147  inline int getNetCode( int aNetCode )
148  {
149  if( (unsigned int) aNetCode < m_netCodes.size() )
150  return m_netCodes[aNetCode];
151 
152  return aNetCode;
153  }
154 
168  BIU biuParse( const char* aValue, const char** nptrptr = NULL );
169 
184  double degParse( const char* aValue, const char** nptrptr = NULL );
185 
186  //-----<load/parse functions>-----------------------------------------------
187 
188  void checkVersion();
189 
190  void loadAllSections( bool doAppend );
191 
192 
193  void loadGENERAL();
194  void loadSETUP();
195  void loadSHEET();
196 
197  void load3D( MODULE* aModule );
198  void loadPAD( MODULE* aModule );
199  void loadMODULE_TEXT( TEXTE_MODULE* aText );
200  void loadMODULE_EDGE( MODULE* aModule );
201 
202  void loadPCB_LINE();
203  void loadNETINFO_ITEM();
204  void loadPCB_TEXT();
205  void loadNETCLASS();
206  void loadMODULE( MODULE* aModule );
207 
215  void loadTrackList( int aStructType );
216 
217  void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
218  void loadDIMENSION(); // "$COTATION"
219  void loadPCB_TARGET(); // "$PCB_TARGET"
220 
221  //-----</ load/parse functions>---------------------------------------------
222 
224  void cacheLib( const wxString& aLibraryPath );
225 };
226 
227 #endif // LEGACY_PLUGIN_H_
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory)...
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
void loadMODULE_TEXT(TEXTE_MODULE *aText)
void loadMODULE(MODULE *aModule)
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
Function Load loads information from some input file format that this PLUGIN implementation knows abo...
bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
wxString m_field
reused to stuff MODULE fields.
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
void SetReader(LINE_READER *aReader)
FILE * m_fp
no ownership here.
void load3D(MODULE *aModule)
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
Class LP_CACHE assists only for the footprint portion of the PLUGIN API, and only for the LEGACY_PLUG...
void SaveModule3D(const MODULE *aModule) const
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
std::vector< int > m_netCodes
net codes mapping for boards being loaded
PCB_LAYER_ID
A quick note on layer IDs:
LINE_READER * m_reader
no ownership here.
Class LSET is a set of PCB_LAYER_IDs.
Class NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:231
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Class LEGACY_PLUGIN is a PLUGIN derivation which could possibly be put into a DLL/DSO.
Definition: legacy_plugin.h:66
void loadMODULE_EDGE(MODULE *aModule)
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
Definition: netclass.h:55
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
void SetFilePtr(FILE *aFile)
BOARD * m_board
which BOARD, no ownership here
void loadAllSections(bool doAppend)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void loadZONE_CONTAINER()
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle...
static LSET leg_mask2new(int cu_count, unsigned aMask)
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
Board layer functions and definitions.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
Definition: legacy_plugin.h:74
wxString m_error
for throwing exceptions
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
void loadPAD(MODULE *aModule)
int getNetCode(int aNetCode)
Converts net code using the mapping table if available, otherwise returns unchanged net code ...
void loadTrackList(int aStructType)
Function loadTrackList reads a list of segments (Tracks and Vias, or Segzones)
Class DIMENSION.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty nets are stored with consecutive integers as net codes ...
LP_CACHE * m_cache
MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
Definition: legacy_plugin.h:79
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.