KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wildcards_and_files_ext.cpp
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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
30#include <regex>
32#include <wx/filedlg.h>
33#include <wx/regex.h>
34#include <wx/translation.h>
35#include <regex>
36
37bool compareFileExtensions( const std::string& aExtension,
38 const std::vector<std::string>& aReference, bool aCaseSensitive )
39{
40 // Form the regular expression string by placing all possible extensions into it as alternatives
41 std::string regexString = "(";
42 bool first = true;
43
44 for( const std::string& ext : aReference )
45 {
46 // The | separate goes between the extensions
47 if( !first )
48 regexString += "|";
49 else
50 first = false;
51
52 regexString += ext;
53 }
54
55 regexString += ")";
56
57 // Create the regex and see if it matches
58 std::regex extRegex( regexString, aCaseSensitive ? std::regex::ECMAScript : std::regex::icase );
59 return std::regex_match( aExtension, extRegex );
60}
61
62
63wxString formatWildcardExt( const wxString& aWildcard )
64{
65 wxString wc;
66#if defined( __WXGTK__ )
67
68 for( const auto& ch : aWildcard )
69 {
70 if( wxIsalpha( ch ) )
71 wc += wxString::Format( "[%c%c]", wxTolower( ch ), wxToupper( ch ) );
72 else
73 wc += ch;
74 }
75
76 return wc;
77#else
78 wc = aWildcard;
79
80 return wc;
81#endif
82}
83
84
85wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
86{
87 if( aExts.size() == 0 )
88 {
89 // The "all files" wildcard is different on different systems
90 wxString filter;
91 filter << wxS( " (" ) << wxFileSelectorDefaultWildcardStr << wxS( ")|" )
92 << wxFileSelectorDefaultWildcardStr;
93 return filter;
94 }
95
96 wxString files_filter = wxS( " (" );
97
98 // Add extensions to the info message:
99 for( const std::string& ext : aExts )
100 {
101 if( files_filter.length() > 2 )
102 files_filter << wxS( "; " );
103
104 files_filter << "*." << ext;
105 }
106
107 files_filter << wxS( ")|*." );
108
109 // Add extensions to the filter list, using a formatted string (GTK specific):
110 bool first = true;
111
112 for( const std::string& ext : aExts )
113 {
114 if( !first )
115 files_filter << wxS( ";*." );
116
117 first = false;
118
119 files_filter << formatWildcardExt( ext );
120 }
121
122 return files_filter;
123}
124
125const std::string FILEEXT::BackupFileSuffix( "-bak" );
126const std::string FILEEXT::LockFilePrefix( "~" );
127const std::string FILEEXT::LockFileExtension( "lck" );
128
129const std::string FILEEXT::KiCadSymbolLibFileExtension( "kicad_sym" );
130const std::string FILEEXT::SchematicSymbolFileExtension( "sym" );
131const std::string FILEEXT::LegacySymbolLibFileExtension( "lib" );
132const std::string FILEEXT::LegacySymbolDocumentFileExtension( "dcm" );
133
134const std::string FILEEXT::VrmlFileExtension( "wrl" );
135
136const std::string FILEEXT::ProjectFileExtension( "kicad_pro" );
137const std::string FILEEXT::LegacyProjectFileExtension( "pro" );
138const std::string FILEEXT::ProjectLocalSettingsFileExtension( "kicad_prl" );
139const std::string FILEEXT::LegacySchematicFileExtension( "sch" );
140const std::string FILEEXT::CadstarSchematicFileExtension( "csa" );
141const std::string FILEEXT::CadstarPartsLibraryFileExtension( "lib" );
142const std::string FILEEXT::KiCadSchematicFileExtension( "kicad_sch" );
143const std::string FILEEXT::SpiceFileExtension( "cir" );
144const std::string FILEEXT::CadstarNetlistFileExtension( "frp" );
145const std::string FILEEXT::OrCadPcb2NetlistFileExtension( "net" );
146const std::string FILEEXT::NetlistFileExtension( "net" );
147const std::string FILEEXT::AllegroNetlistFileExtension( "txt" );
148const std::string FILEEXT::FootprintAssignmentFileExtension( "cmp" );
149const std::string FILEEXT::GerberFileExtension( "gbr" );
150const std::string FILEEXT::GerberJobFileExtension( "gbrjob" );
151const std::string FILEEXT::HtmlFileExtension( "html" );
152const std::string FILEEXT::EquFileExtension( "equ" );
153const std::string FILEEXT::HotkeyFileExtension( "hotkeys" );
154const std::string FILEEXT::DatabaseLibraryFileExtension( "kicad_dbl" );
155const std::string FILEEXT::HTTPLibraryFileExtension( "kicad_httplib" );
156
157const std::string FILEEXT::ArchiveFileExtension( "zip" );
158
159const std::string FILEEXT::LegacyPcbFileExtension( "brd" );
160const std::string FILEEXT::EaglePcbFileExtension( "brd" );
161const std::string FILEEXT::CadstarPcbFileExtension( "cpa" );
162const std::string FILEEXT::KiCadPcbFileExtension( "kicad_pcb" );
163const std::string FILEEXT::DrawingSheetFileExtension( "kicad_wks" );
164const std::string FILEEXT::DesignRulesFileExtension( "kicad_dru" );
165
166const std::string FILEEXT::PdfFileExtension( "pdf" );
167const std::string FILEEXT::MacrosFileExtension( "mcr" );
168const std::string FILEEXT::DrillFileExtension( "drl" );
169const std::string FILEEXT::SVGFileExtension( "svg" );
170const std::string FILEEXT::ReportFileExtension( "rpt" );
171const std::string FILEEXT::FootprintPlaceFileExtension( "pos" );
172
173const std::string FILEEXT::KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
174const std::string FILEEXT::LegacyFootprintLibPathExtension( "mod" ); // this is a file
175const std::string FILEEXT::AltiumFootprintLibPathExtension( "PcbLib" ); // this is a file
176const std::string FILEEXT::CadstarFootprintLibPathExtension( "cpa" ); // this is a file
177const std::string FILEEXT::EagleFootprintLibPathExtension( "lbr" ); // this is a file
178const std::string FILEEXT::GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
179
180const std::string FILEEXT::KiCadFootprintFileExtension( "kicad_mod" );
181const std::string FILEEXT::SpecctraDsnFileExtension( "dsn" );
182const std::string FILEEXT::SpecctraSessionFileExtension( "ses" );
183const std::string FILEEXT::IpcD356FileExtension( "d356" );
184const std::string FILEEXT::Ipc2581FileExtension( "xml" );
185const std::string FILEEXT::WorkbookFileExtension( "wbk" );
186
187const std::string FILEEXT::PngFileExtension( "png" );
188const std::string FILEEXT::JpegFileExtension( "jpg" );
189const std::string FILEEXT::TextFileExtension( "txt" );
190const std::string FILEEXT::MarkdownFileExtension( "md" );
191const std::string FILEEXT::CsvFileExtension( "csv" );
192const std::string FILEEXT::XmlFileExtension( "xml" );
193const std::string FILEEXT::JsonFileExtension( "json" );
194
195const std::string FILEEXT::StepFileExtension( "step" );
196const std::string FILEEXT::StepFileAbrvExtension( "stp" );
197const std::string FILEEXT::GltfBinaryFileExtension( "glb" );
198
199const wxString FILEEXT::GerberFileExtensionsRegex( "(gbr|gko|pho|(g[tb][alops])|(gm?\\d\\d*)|(gp[tb]))" );
200
201
202bool FILEEXT::IsGerberFileExtension( const wxString& ext )
203{
204 static wxRegEx gerberRE( GerberFileExtensionsRegex, wxRE_ICASE );
205
206 return gerberRE.Matches( ext );
207}
208
209
211{
212 return _( "All files" ) + AddFileExtListToFilter( {} );
213}
214
215
217{
218 return _( "KiCad symbol library files" )
220}
221
222
224{
225 return _( "KiCad project files" ) + AddFileExtListToFilter( { ProjectFileExtension } );
226}
227
228
230{
231 return _( "KiCad legacy project files" )
233}
234
235
237{
238 return _( "All KiCad project files" )
240}
241
242
244{
245 return _( "All KiCad schematic files" )
247}
248
249
251{
252 return _( "KiCad legacy schematic files" )
254}
255
256
258{
259 return _( "KiCad s-expression schematic files" )
261}
262
263
265{
266 return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
267}
268
269
271{
272 return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
273}
274
275
277{
278 return _( "OrcadPCB2 netlist files" )
280}
281
282
284{
285 return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
286}
287
288
290{
291 return _( "Allegro netlist files" )
293}
294
295
297{
298 return _( "EasyEDA (JLCEDA) Std backup archive" ) + AddFileExtListToFilter( { "zip" } );
299}
300
301
303{
304 return _( "EasyEDA (JLCEDA) Pro files" ) + AddFileExtListToFilter( { "epro", "zip" } );
305}
306
307
309{
310 return _( "KiCad printed circuit board files" )
312}
313
314
316{
317 return _( "KiCad footprint files" ) + AddFileExtListToFilter( { KiCadFootprintFileExtension } );
318}
319
320
322{
323 return _( "KiCad footprint library paths" )
325}
326
327
329{
330 return _( "Drawing sheet files" )
332}
333
334
335// Wildcard for cvpcb symbol to footprint link file
337{
338 return _( "KiCad symbol footprint link files" )
340}
341
342
343// Wildcard for reports and fabrication documents
345{
346 return _( "Drill files" )
347 + AddFileExtListToFilter( { DrillFileExtension, "nc", "xnc", "txt" } );
348}
349
350
352{
353 return _( "SVG files" ) + AddFileExtListToFilter( { SVGFileExtension } );
354}
355
356
358{
359 return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
360}
361
362
364{
365 return _( "CSV Files" ) + AddFileExtListToFilter( { CsvFileExtension } );
366}
367
368
370{
371 return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
372}
373
374
376{
377 return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
378}
379
380
382{
383 return _( "Json files" ) + AddFileExtListToFilter( { JsonFileExtension } );
384}
385
386
388{
389 return _( "Report files" ) + AddFileExtListToFilter( { ReportFileExtension } );
390}
391
392
394{
395 return _( "Component placement files" ) + AddFileExtListToFilter( { "pos" } );
396}
397
398
400{
401 return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
402}
403
404
406{
407 return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
408}
409
410
412{
413 return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
414}
415
416
418{
419 return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
420}
421
422
424{
425 return _( "Electrical rule check file" ) + AddFileExtListToFilter( { "erc" } );
426}
427
428
430{
431 return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
432}
433
434
436{
437 return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
438}
439
440
442{
443 return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
444}
445
446
448{
449 return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
450}
451
452
454{
455 return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
456}
457
458
460{
461 return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
462}
463
464
466{
467 return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
468}
469
470
472{
473 return _( "Gerber job file" ) + AddFileExtListToFilter( { GerberJobFileExtension } );
474}
475
476
478{
479 return _( "Specctra DSN file" )
481}
482
483
485{
486 return _( "Specctra Session file" )
488}
489
490
492{
493 return _( "IPC-D-356 Test Files" )
495}
496
497
499{
500 return _( "Workbook file" )
502}
503
504
506{
507 return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
508}
509
510
512{
513 return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
514}
515
516
518{
519 return _( "Hotkey file" ) + AddFileExtListToFilter( { HotkeyFileExtension } );
520}
#define _(s)
static const std::string CadstarNetlistFileExtension
static const std::string LegacySchematicFileExtension
static const std::string HtmlFileExtension
static const wxString GerberFileExtensionsRegex
static const std::string CadstarPartsLibraryFileExtension
static const std::string NetlistFileExtension
static const std::string JpegFileExtension
static const std::string GerberJobFileExtension
static const std::string StepFileAbrvExtension
static const std::string GerberFileExtension
static const std::string WorkbookFileExtension
static const std::string ReportFileExtension
static const std::string GltfBinaryFileExtension
static const std::string EquFileExtension
static const std::string LockFileExtension
static const std::string ProjectFileExtension
static const std::string PngFileExtension
static const std::string FootprintPlaceFileExtension
static const std::string JsonFileExtension
static const std::string AltiumFootprintLibPathExtension
static const std::string LegacyPcbFileExtension
static const std::string SchematicSymbolFileExtension
static const std::string XmlFileExtension
static const std::string LegacyProjectFileExtension
static const std::string ProjectLocalSettingsFileExtension
static const std::string EagleFootprintLibPathExtension
static const std::string KiCadSchematicFileExtension
static const std::string OrCadPcb2NetlistFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string LockFilePrefix
static const std::string CsvFileExtension
static const std::string KiCadSymbolLibFileExtension
static const std::string SpiceFileExtension
static const std::string PdfFileExtension
static const std::string TextFileExtension
static const std::string Ipc2581FileExtension
static const std::string DrawingSheetFileExtension
static const std::string BackupFileSuffix
static const std::string IpcD356FileExtension
static const std::string CadstarFootprintLibPathExtension
static const std::string GedaPcbFootprintLibFileExtension
static const std::string DatabaseLibraryFileExtension
static const std::string LegacyFootprintLibPathExtension
static const std::string CadstarSchematicFileExtension
static const std::string SpecctraDsnFileExtension
static const std::string StepFileExtension
static const std::string LegacySymbolDocumentFileExtension
static const std::string KiCadFootprintLibPathExtension
static const std::string FootprintAssignmentFileExtension
static const std::string SVGFileExtension
static const std::string EaglePcbFileExtension
static const std::string SpecctraSessionFileExtension
static const std::string HTTPLibraryFileExtension
static const std::string DrillFileExtension
static const std::string MacrosFileExtension
static const std::string HotkeyFileExtension
static const std::string CadstarPcbFileExtension
static const std::string DesignRulesFileExtension
static const std::string VrmlFileExtension
static const std::string MarkdownFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string ArchiveFileExtension
static const std::string AllegroNetlistFileExtension
static const std::string KiCadPcbFileExtension
static wxString ProjectFileWildcard()
static wxString SpiceNetlistFileWildcard()
static wxString PngFileWildcard()
static wxString HotkeyFileWildcard()
static wxString EasyEdaArchiveWildcard()
static wxString ModLegacyExportFileWildcard()
static wxString FootprintPlaceFileWildcard()
static wxString ErcFileWildcard()
static wxString JpegFileWildcard()
static wxString OrCadPcb2NetlistFileWildcard()
static wxString AllFilesWildcard()
static wxString AllegroNetlistFileWildcard()
static wxString CadstarArchiveFilesWildcard()
static wxString SpecctraSessionFileWildcard()
static wxString TextFileWildcard()
static wxString CadstarNetlistFileWildcard()
static wxString EasyEdaProFileWildcard()
static wxString LegacySchematicFileWildcard()
static wxString DxfFileWildcard()
static wxString PdfFileWildcard()
static wxString SVGFileWildcard()
static bool IsGerberFileExtension(const wxString &ext)
static wxString SpiceLibraryFileWildcard()
static wxString GerberJobFileWildcard()
static wxString JsonFileWildcard()
static wxString PcbFileWildcard()
static wxString KiCadSymbolLibFileWildcard()
static wxString KiCadFootprintLibFileWildcard()
static wxString KiCadFootprintLibPathWildcard()
static wxString NetlistFileWildcard()
static wxString PSFileWildcard()
static wxString EquFileWildcard()
static wxString AllSchematicFilesWildcard()
static wxString IDF3DFileWildcard()
static wxString HtmlFileWildcard()
static wxString SpecctraDsnFileWildcard()
static wxString DrawingSheetFileWildcard()
static wxString DrillFileWildcard()
static wxString FootprintAssignmentFileWildcard()
static wxString Shapes3DFileWildcard()
static wxString EagleFilesWildcard()
static wxString LegacyProjectFileWildcard()
static wxString IpcD356FileWildcard()
static wxString CsvFileWildcard()
static wxString AllProjectFilesWildcard()
static wxString KiCadSchematicFileWildcard()
static wxString GencadFileWildcard()
static wxString ReportFileWildcard()
static wxString ZipFileWildcard()
static wxString WorkbookFileWildcard()
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
bool compareFileExtensions(const std::string &aExtension, const std::vector< std::string > &aReference, bool aCaseSensitive)
Compare the given extension against the reference extensions to see if it matches any of the referenc...
Definition of file extensions used in Kicad.
KICOMMON_API wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.