File: fp_lib_table.h

package info (click to toggle)
kicad 5.0.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 234,592 kB
  • sloc: cpp: 505,330; ansic: 57,038; python: 4,886; sh: 879; awk: 294; makefile: 253; xml: 103; perl: 5
file content (307 lines) | stat: -rw-r--r-- 10,601 bytes parent folder | download
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
303
304
305
306
307
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012-2017 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2012-2017 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
 */

#ifndef FP_LIB_TABLE_H_
#define FP_LIB_TABLE_H_

#include <lib_table_base.h>
#include <io_mgr.h>

class MODULE;
class FP_LIB_TABLE_GRID;


/**
 * Class FP_LIB_TABLE_ROW
 *
 * holds a record identifying a library accessed by the appropriate footprint library #PLUGIN
 * object in the #FP_LIB_TABLE.
 */
class FP_LIB_TABLE_ROW : public LIB_TABLE_ROW
{
    friend class FP_LIB_TABLE;

public:
    typedef IO_MGR::PCB_FILE_T LIB_T;

    FP_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
                      const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
        LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
    {
        SetType( aType );
    }

    FP_LIB_TABLE_ROW() :
        type( IO_MGR::KICAD_SEXP )
    {
    }

    bool operator==( const FP_LIB_TABLE_ROW& aRow ) const;

    bool operator!=( const FP_LIB_TABLE_ROW& aRow ) const   { return !( *this == aRow ); }

    /**
     * Function GetType
     *
     * returns the type of footprint library table represented by this row.
     */
    const wxString GetType() const override         { return IO_MGR::ShowType( type ); }

    /**
     * Function SetType
     *
     * changes the type represented by this row.
     */
    void SetType( const wxString& aType ) override;

protected:
    FP_LIB_TABLE_ROW( const FP_LIB_TABLE_ROW& aRow ) :
        LIB_TABLE_ROW( aRow ),
        type( aRow.type )
    {
    }

private:

    virtual LIB_TABLE_ROW* do_clone() const override
    {
        return new FP_LIB_TABLE_ROW( *this );
    }

    void setPlugin( PLUGIN* aPlugin )
    {
        plugin.set( aPlugin );
    }

    PLUGIN::RELEASER  plugin;
    LIB_T             type;
};


class FP_LIB_TABLE : public LIB_TABLE
{
    friend class FP_LIB_TABLE_GRID;

public:

    virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;

    virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;

    /**
     * Constructor FP_LIB_TABLE
     *
     * builds a footprint library table by pre-pending this table fragment in front of
     * @a aFallBackTable.  Loading of this table fragment is done by using Parse().
     *
     * @param aFallBackTable is another FP_LIB_TABLE which is searched only when
     *                       a row is not found in this table.  No ownership is
     *                       taken of aFallBackTable.
     */
    FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = NULL );


    bool operator==( const FP_LIB_TABLE& aFpTable ) const;

    bool operator!=( const FP_LIB_TABLE& r ) const  { return !( *this == r ); }

    /**
     * Function FindRow
     *
     * returns an FP_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained
     * fallBack table fragment.  The #PLUGIN is loaded and attached to the "plugin" field
     * of the #FP_LIB_TABLE_ROW if not already loaded.
     *
     * @throw IO_ERROR if \a aNickName cannot be found.
     */
    const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName );

    //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------

    /**
     * Return a list of footprint names contained within the library given by @a aNickname.
     *
     * @param aFootprintNames is the list to fill with the footprint names found in \a aNickname
     *
     * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
     *
     * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
     */
    void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname );

    /**
     * Generate a hashed timestamp representing the last-mod-times of the library indicated
     * by \a aNickname, or all libraries if \a aNickname is NULL.
     */
    long long GenerateTimestamp( const wxString* aNickname );

    /**
     * Function PrefetchLib
     * If possible, prefetches the specified library (e.g. performing downloads). Does not parse.
     * Threadsafe.
     *
     * This is a no-op for libraries that cannot be prefetched.
     *
     * @param aNickname is a locator for the library; it is a name in LIB_TABLE_ROW.
     *
     * @throw IO_ERROR if there is an error prefetching the library.
     */
    void PrefetchLib( const wxString& aNickname );

    /**
     * Function FootprintLoad
     *
     * loads a footprint having @a aFootprintName from the library given by @a aNickname.
     *
     * @param aNickname is a locator for the "library", it is a "name" in #LIB_TABLE_ROW
     *
     * @param aFootprintName is the name of the footprint to load.
     *
     * @return  MODULE* - if found caller owns it, else NULL if not found.
     *
     * @throw   IO_ERROR if the library cannot be found or read.  No exception
     *          is thrown in the case where aFootprintName cannot be found.
     */
    MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName );

    /**
     * Function LoadEnumeratedFootprint
     *
     * a version of FootprintLoad() for use after FootprintEnumerate() for more efficient
     * cache management.
     */
    MODULE* LoadEnumeratedFootprint( const wxString& aNickname, const wxString& aFootprintName );
    /**
     * Enum SAVE_T
     * is the set of return values from FootprintSave() below.
     */
    enum SAVE_T
    {
        SAVE_OK,
        SAVE_SKIPPED,
    };

    /**
     * Function FootprintSave
     *
     * will write @a aFootprint to an existing library given by @a aNickname.
     * If a footprint by the same name already exists, it is replaced.
     *
     * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW
     *
     * @param aFootprint is what to store in the library. The caller continues to own the
     *                   footprint after this call.
     *
     * @param aOverwrite when true means overwrite any existing footprint by the same name,
     *                   else if false means skip the write and return SAVE_SKIPPED.
     *
     * @return SAVE_T - SAVE_OK or SAVE_SKIPPED.  If error saving, then IO_ERROR is thrown.
     *
     * @throw IO_ERROR if there is a problem saving.
     */
    SAVE_T FootprintSave( const wxString& aNickname, const MODULE* aFootprint,
                          bool aOverwrite = true );

    /**
     * Function FootprintDelete
     *
     * deletes the @a aFootprintName from the library given by @a aNickname.
     *
     * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
     *
     * @param aFootprintName is the name of a footprint to delete from the specified library.
     *
     * @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
     */
    void FootprintDelete( const wxString& aNickname, const wxString& aFootprintName );

    /**
     * Function IsFootprintLibWritable
     *
     * returns true if the library given by @a aNickname is writable.  (Often
     * system libraries are read only because of where they are installed.)
     *
     * @throw IO_ERROR if no library at aLibraryPath exists.
     */
    bool IsFootprintLibWritable( const wxString& aNickname );

    void FootprintLibDelete( const wxString& aNickname );

    void FootprintLibCreate( const wxString& aNickname );

    //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------

    /**
     * Function FootprintLoadWithOptionalNickname
     * loads a footprint having @a aFootprintId with possibly an empty nickname.
     *
     * @param aFootprintId the [nickname] & footprint name of the footprint to load.
     *
     * @return  MODULE* - if found caller owns it, else NULL if not found.
     *
     * @throw   IO_ERROR if the library cannot be found or read.  No exception
     *          is thrown in the case where aFootprintName cannot be found.
     * @throw   PARSE_ERROR if @a aFootprintId is not parsed OK.
     */
    MODULE* FootprintLoadWithOptionalNickname( const LIB_ID& aFootprintId );

    /**
     * Function LoadGlobalTable
     * loads the global footprint library table into \a aTable.
     *
     * This probably should be move into the application object when KiCad is changed
     * to a single process application.  This is the least painful solution for the
     * time being.
     *
     * @param aTable the #FP_LIB_TABLE object to load.
     * @return true if the global library table exists and is loaded properly.
     * @throw IO_ERROR if an error occurs attempting to load the footprint library
     *                 table.
     */
    static bool LoadGlobalTable( FP_LIB_TABLE& aTable );

    /**
     * Function GetGlobalTableFileName
     *
     * @return the platform specific global footprint library path and file name.
     */
    static wxString GetGlobalTableFileName();

    /**
     * Function GlobalPathEnvVarVariableName
     *
     * returns the name of the environment variable used to hold the directory of
     * locally installed "KiCad sponsored" system footprint libraries.  These can
     * be either legacy or pretty format.  The only thing special about this
     * particular environment variable is that it is set automatically by
     * KiCad on program start up, <b>if</b> it is not set already in the environment.
     */
    static const wxString GlobalPathEnvVariableName();
};


extern FP_LIB_TABLE GFootprintTable;        // KIFACE scope.

#endif  // FP_LIB_TABLE_H_