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-2021 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>
30 #include <layer_ids.h>
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 FOOTPRINT;
43 class NETCLASS;
44 class NETCLASSES;
45 class ZONE;
46 class PCB_DIMENSION_BASE;
47 class NETINFO_ITEM;
48 class FP_TEXT;
49 class PAD;
50 struct LP_CACHE;
51 
52 
58 class LEGACY_PLUGIN : public PLUGIN
59 {
60  friend struct LP_CACHE;
61 
62 public:
63  LEGACY_PLUGIN();
65 
66  const wxString PluginName() const override
67  {
68  return wxT( "KiCad-Legacy" );
69  }
70 
71  const wxString GetFileExtension() const override
72  {
73  return wxT( "brd" );
74  }
75 
76  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
77  const PROPERTIES* aProperties = nullptr, PROJECT* aProject = nullptr,
78  PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
79 
80  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
81  bool aBestEfforts,
82  const PROPERTIES* aProperties = nullptr ) override;
83 
84  FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
85  bool aKeepUUID = false,
86  const PROPERTIES* aProperties = nullptr ) override;
87 
88  bool FootprintLibDelete( const wxString& aLibraryPath,
89  const PROPERTIES* aProperties = nullptr ) override;
90 
91  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
92 
93  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;
94 
95  typedef int BIU;
96 
97  void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
98 
99  // return the new .kicad_pcb layer id from the old (legacy) layer id
100  static PCB_LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum );
101 
102  static LSET leg_mask2new( int cu_count, unsigned aMask );
103 
104 protected:
106  void init( const PROPERTIES* aProperties );
107 
108  void checkpoint();
109 
112  inline int getNetCode( int aNetCode )
113  {
114  if( (unsigned int) aNetCode < m_netCodes.size() )
115  return m_netCodes[aNetCode];
116 
117  return aNetCode;
118  }
119 
131  BIU biuParse( const char* aValue, const char** nptrptr = nullptr );
132 
145  double degParse( const char* aValue, const char** nptrptr = nullptr );
146 
147  void checkVersion();
148 
149  void loadAllSections( bool doAppend );
150 
151 
152  void loadGENERAL();
153  void loadSETUP();
154  void loadSHEET();
155 
156  void load3D( FOOTPRINT* aFootprint );
157  void loadPAD( FOOTPRINT* aFootprint );
158  void loadMODULE_TEXT( FP_TEXT* aText );
159  void loadFP_SHAPE( FOOTPRINT* aFootprint );
160 
161  void loadPCB_LINE();
162  void loadNETINFO_ITEM();
163  void loadPCB_TEXT();
164  void loadNETCLASS();
165  void loadFOOTPRINT( FOOTPRINT* aFootprint );
166 
173  void loadTrackList( int aStructType );
174 
175  void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
176  void loadDIMENSION(); // "$COTATION"
177  void loadPCB_TARGET(); // "$PCB_TARGET"
178 
180  void cacheLib( const wxString& aLibraryPath );
181 
182 protected:
184 
185  wxString m_error;
191  unsigned m_lineCount;
192 
194  FILE* m_fp;
195 
196  wxString m_field;
200 
201  std::vector<int> m_netCodes;
202 
203  double biuToDisk;
204 
206  double diskToBiu;
207 };
209 
210 #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).
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
Container for project specific data.
Definition: project.h:62
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
bool m_showLegacyZoneWarning
A progress reporter interface for use in multi-threaded environments.
BIU biuParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value and scales it into a BIU according to the current value o...
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:41
Abstract dimension API.
Definition: pcb_dimension.h:95
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
wxString m_field
reused to stuff FOOTPRINT fields.
A name/value tuple with unique names and optional values.
Definition: properties.h:33
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Delete an existing footprint library and returns true, or if library does not exist returns false,...
void SetReader(LINE_READER *aReader)
Definition: legacy_plugin.h:97
FILE * m_fp
no ownership here.
double degParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value which is certainly an angle.
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
The footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN, so therefore is private to t...
std::vector< int > m_netCodes
net codes mapping for boards being loaded
unsigned m_lineCount
for progress reporting
LINE_READER * m_reader
no ownership here.
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
A container for NETCLASS instances.
Definition: netclass.h:218
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
A PLUGIN derivation which could possibly be put into a DLL/DSO.
Definition: legacy_plugin.h:58
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
void loadFP_SHAPE(FOOTPRINT *aFootprint)
void loadMODULE_TEXT(FP_TEXT *aText)
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
LEGACY_PLUGIN::BIU BIU
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
BOARD * m_board
which BOARD, no ownership here
void loadAllSections(bool doAppend)
void checkpoint()
Converts net code using the mapping table if available, otherwise returns unchanged net code.
void loadFOOTPRINT(FOOTPRINT *aFootprint)
void loadZONE_CONTAINER()
static LSET leg_mask2new(int cu_count, unsigned aMask)
Handle the data for a net.
Definition: netinfo.h:64
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
Definition: legacy_plugin.h:66
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
wxString m_error
for throwing exceptions
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:269
unsigned m_lastProgressLine
PROGRESS_REPORTER * m_progressReporter
may be NULL, no ownership
void load3D(FOOTPRINT *aFootprint)
Definition: pad.h:57
int getNetCode(int aNetCode)
void loadPAD(FOOTPRINT *aFootprint)
void loadTrackList(int aStructType)
Read a list of segments (Tracks and Vias, or Segzones)
LP_CACHE * m_cache
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
Definition: legacy_plugin.h:71
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.