1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
#ifndef LEGACY_PLUGIN_H_
#define LEGACY_PLUGIN_H_
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <io_mgr.h>
#include <boost/shared_ptr.hpp>
#include <string>
#include <layers_id_colors_and_visibility.h>
// FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
// a footprint library. A few variants may have been used, and so we can only be
// sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
#define FOOTPRINT_LIBRARY_HEADER_CNT 18
class PCB_TARGET;
class MODULE;
class DRAWSEGMENT;
class NETINFO;
class TEXTE_PCB;
class TRACK;
class NETCLASS;
class NETCLASSES;
class ZONE_CONTAINER;
class DIMENSION;
class NETINFO_ITEM;
class NETINFO_MAPPING;
class TEXTE_MODULE;
class EDGE_MODULE;
class TRACK;
class SEGZONE;
class D_PAD;
struct LP_CACHE;
/**
* Class LEGACY_PLUGIN
* is a PLUGIN derivation which could possibly be put into a DLL/DSO.
* As with any PLUGIN, there is no UI, i.e. windowing calls allowed.
*/
class LEGACY_PLUGIN : public PLUGIN
{
friend struct LP_CACHE;
public:
//-----<PLUGIN IMPLEMENTATION>----------------------------------------------
const wxString PluginName() const
{
return wxT( "KiCad-Legacy" );
}
const wxString GetFileExtension() const
{
return wxT( "brd" );
}
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
const PROPERTIES* aProperties = NULL );
/* we let go of "save" support when the number of CU layers were expanded from 16 to 32.
void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
const PROPERTIES* aProperties = NULL );
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
*/
wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL);
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL );
bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
bool IsFootprintLibWritable( const wxString& aLibraryPath );
//-----</PLUGIN IMPLEMENTATION>---------------------------------------------
typedef int BIU;
LEGACY_PLUGIN();
~LEGACY_PLUGIN();
void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
void SetFilePtr( FILE* aFile ) { m_fp = aFile; }
void SaveModule3D( const MODULE* aModule ) const;
// return the new .kicad_pcb layer id from the old (legacy) layer id
static LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum );
static LSET leg_mask2new( int cu_count, unsigned aMask );
protected:
int m_cu_count;
wxString m_error; ///< for throwing exceptions
BOARD* m_board; ///< which BOARD, no ownership here
const PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
LINE_READER* m_reader; ///< no ownership here.
FILE* m_fp; ///< no ownership here.
wxString m_filename; ///< for saves only, name is in m_reader for loads
wxString m_field; ///< reused to stuff MODULE fields.
int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing?
LP_CACHE* m_cache;
NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty nets
///< are stored with consecutive integers as net codes
std::vector<int> m_netCodes; ///< net codes mapping for boards being loaded
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void init( const PROPERTIES* aProperties );
double biuToDisk; ///< convert from BIUs to disk engineering units
///< with this scale factor
double diskToBiu; ///< convert from disk engineering units to BIUs
///< with this scale factor
///> Converts net code using the mapping table if available,
///> otherwise returns unchanged net code
inline int getNetCode( int aNetCode )
{
if( (unsigned int) aNetCode < m_netCodes.size() )
return m_netCodes[aNetCode];
return aNetCode;
}
/**
* Function biuParse
* parses an ASCII decimal floating point value and scales it into a BIU
* according to the current value of diskToBui. This fuction is the complement of
* fmtBIU(). One has to know what the other is doing.
*
* @param aValue is the ASCII value in C locale form with possible leading whitespace
*
* @param nptrptr may be NULL, but if not, then it tells where to put a
* pointer to the next unconsumed input text. See "man strtod" for more information.
*
* @return BIU - the converted Board Internal Unit.
*/
BIU biuParse( const char* aValue, const char** nptrptr = NULL );
/**
* Function degParse
* parses an ASCII decimal floating point value which is certainly an angle. This
* is a dedicated function for encapsulating support for the migration from
* tenths of degrees to degrees in floating point. This function is the complement of
* fmtDEG(). One has to know what the other is doing.
*
* @param aValue is the ASCII value in C locale form with possible leading whitespace
*
* @param nptrptr may be NULL, but if not, then it tells where to put a
* pointer to the next unconsumed input text. See "man strtod" for more information.
*
* @return double - the string converted to a primitive double type
*/
double degParse( const char* aValue, const char** nptrptr = NULL );
//-----<load/parse functions>-----------------------------------------------
void checkVersion();
void loadAllSections( bool doAppend );
void loadGENERAL();
void loadSETUP();
void loadSHEET();
void load3D( MODULE* aModule );
void loadPAD( MODULE* aModule );
void loadMODULE_TEXT( TEXTE_MODULE* aText );
void loadMODULE_EDGE( MODULE* aModule );
void loadPCB_LINE();
void loadNETINFO_ITEM();
void loadPCB_TEXT();
void loadNETCLASS();
void loadMODULE( MODULE* aModule );
/**
* Function loadTrackList
* reads a list of segments (Tracks and Vias, or Segzones)
*
* @param aStructType is either PCB_TRACE_T to indicate tracks and vias, or
* PCB_ZONE_T to indicate oldschool zone segments (before polygons came to be).
*/
void loadTrackList( int aStructType );
void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
void loadDIMENSION(); // "$COTATION"
void loadPCB_TARGET(); // "$PCB_TARGET"
//-----</ load/parse functions>---------------------------------------------
//-----<save functions>-----------------------------------------------------
#if 0
/**
* Function writeError
* returns an error message wxString containing the filename being
* currently written.
*/
wxString writeError() const;
/// encapsulate the BIU formatting tricks in one place.
int biuSprintf( char* buf, BIU aValue ) const;
/**
* Function fmtBIU
* converts a BIU to engineering units by scaling and formatting to ASCII.
* This function is the complement of biuParse(). One has to know what the
* other is doing.
*/
std::string fmtBIU( BIU aValue ) const;
std::string fmtBIUPair( BIU first, BIU second ) const;
std::string fmtBIUPoint( const wxPoint& aPoint ) const
{
return fmtBIUPair( aPoint.x, aPoint.y );
}
std::string fmtBIUSize( const wxSize& aSize ) const
{
return fmtBIUPair( aSize.x, aSize.y );
}
/**
* Function fmtDEG
* formats an angle in a way particular to a board file format. This function
* is the opposite or complement of degParse(). One has to know what the
* other is doing.
*/
std::string fmtDEG( double aAngle ) const;
void saveGENERAL( const BOARD* aBoard ) const;
void saveSHEET( const BOARD* aBoard ) const;
void saveSETUP( const BOARD* aBoard ) const;
void saveBOARD_ITEMS( const BOARD* aBoard ) const;
void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const;
void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const;
void savePAD( const D_PAD* aPad ) const;
void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const;
void saveNETCLASSES( const NETCLASSES* aNetClasses ) const;
void saveNETCLASS( const boost::shared_ptr<NETCLASS> aNetclass ) const;
void savePCB_TEXT( const TEXTE_PCB* aText ) const;
void savePCB_TARGET( const PCB_TARGET* aTarget ) const;
void savePCB_LINE( const DRAWSEGMENT* aStroke ) const;
void saveDIMENSION( const DIMENSION* aDimension ) const;
void saveTRACK( const TRACK* aTrack ) const;
void saveBOARD( const BOARD* aBoard ) const;
/**
* Function saveZONE_CONTAINER
* saves the new polygon zones.
*/
void saveZONE_CONTAINER( const ZONE_CONTAINER* aZone ) const;
//-----</save functions>----------------------------------------------------
#endif
/// we only cache one footprint library for now, this determines which one.
void cacheLib( const wxString& aLibraryPath );
};
#endif // LEGACY_PLUGIN_H_
|