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-2024 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" );
128const std::string FILEEXT::AutoSaveFilePrefix( "_autosave-" );
129
130const std::string FILEEXT::KiCadSymbolLibFileExtension( "kicad_sym" );
131const std::string FILEEXT::SchematicSymbolFileExtension( "sym" );
132const std::string FILEEXT::LegacySymbolLibFileExtension( "lib" );
133const std::string FILEEXT::LegacySymbolDocumentFileExtension( "dcm" );
134
135const std::string FILEEXT::VrmlFileExtension( "wrl" );
136
137const std::string FILEEXT::ProjectFileExtension( "kicad_pro" );
138const std::string FILEEXT::LegacyProjectFileExtension( "pro" );
139const std::string FILEEXT::ProjectLocalSettingsFileExtension( "kicad_prl" );
140const std::string FILEEXT::LegacySchematicFileExtension( "sch" );
141const std::string FILEEXT::CadstarSchematicFileExtension( "csa" );
142const std::string FILEEXT::CadstarPartsLibraryFileExtension( "lib" );
143const std::string FILEEXT::KiCadSchematicFileExtension( "kicad_sch" );
144const std::string FILEEXT::SpiceFileExtension( "cir" );
145const std::string FILEEXT::CadstarNetlistFileExtension( "frp" );
146const std::string FILEEXT::OrCadPcb2NetlistFileExtension( "net" );
147const std::string FILEEXT::NetlistFileExtension( "net" );
148const std::string FILEEXT::AllegroNetlistFileExtension( "txt" );
149const std::string FILEEXT::PADSNetlistFileExtension( "asc" );
150const std::string FILEEXT::FootprintAssignmentFileExtension( "cmp" );
151const std::string FILEEXT::GerberFileExtension( "gbr" );
152const std::string FILEEXT::GerberJobFileExtension( "gbrjob" );
153const std::string FILEEXT::HtmlFileExtension( "html" );
154const std::string FILEEXT::EquFileExtension( "equ" );
155const std::string FILEEXT::HotkeyFileExtension( "hotkeys" );
156const std::string FILEEXT::DatabaseLibraryFileExtension( "kicad_dbl" );
157const std::string FILEEXT::HTTPLibraryFileExtension( "kicad_httplib" );
158const std::string FILEEXT::KiCadJobSetFileExtension( "kicad_jobset" );
159
160const std::string FILEEXT::ArchiveFileExtension( "zip" );
161
162const std::string FILEEXT::LegacyPcbFileExtension( "brd" );
163const std::string FILEEXT::EaglePcbFileExtension( "brd" );
164const std::string FILEEXT::CadstarPcbFileExtension( "cpa" );
165const std::string FILEEXT::KiCadPcbFileExtension( "kicad_pcb" );
166const std::string FILEEXT::DrawingSheetFileExtension( "kicad_wks" );
167const std::string FILEEXT::DesignRulesFileExtension( "kicad_dru" );
168
169const std::string FILEEXT::PdfFileExtension( "pdf" );
170const std::string FILEEXT::MacrosFileExtension( "mcr" );
171const std::string FILEEXT::DrillFileExtension( "drl" );
172const std::string FILEEXT::SVGFileExtension( "svg" );
173const std::string FILEEXT::ReportFileExtension( "rpt" );
174const std::string FILEEXT::FootprintPlaceFileExtension( "pos" );
175
176const std::string FILEEXT::KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
177const std::string FILEEXT::LegacyFootprintLibPathExtension( "mod" ); // this is a file
178const std::string FILEEXT::AltiumFootprintLibPathExtension( "PcbLib" ); // this is a file
179const std::string FILEEXT::CadstarFootprintLibPathExtension( "cpa" ); // this is a file
180const std::string FILEEXT::EagleFootprintLibPathExtension( "lbr" ); // this is a file
181const std::string FILEEXT::GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
182
183const std::string FILEEXT::KiCadFootprintFileExtension( "kicad_mod" );
184const std::string FILEEXT::SpecctraDsnFileExtension( "dsn" );
185const std::string FILEEXT::SpecctraSessionFileExtension( "ses" );
186const std::string FILEEXT::IpcD356FileExtension( "d356" );
187const std::string FILEEXT::Ipc2581FileExtension( "xml" );
188const std::string FILEEXT::WorkbookFileExtension( "wbk" );
189
190const std::string FILEEXT::KiCadDesignBlockLibPathExtension( "blocks" ); // this is a directory
191const std::string FILEEXT::KiCadDesignBlockPathExtension( "block" ); // this is a directory
192
193const std::string FILEEXT::PngFileExtension( "png" );
194const std::string FILEEXT::JpegFileExtension( "jpg" );
195const std::string FILEEXT::TextFileExtension( "txt" );
196const std::string FILEEXT::MarkdownFileExtension( "md" );
197const std::string FILEEXT::CsvFileExtension( "csv" );
198const std::string FILEEXT::XmlFileExtension( "xml" );
199const std::string FILEEXT::JsonFileExtension( "json" );
200
201const std::string FILEEXT::StepFileExtension( "step" );
202const std::string FILEEXT::StepFileAbrvExtension( "stp" );
203const std::string FILEEXT::GltfBinaryFileExtension( "glb" );
204const std::string FILEEXT::BrepFileExtension( "brep" );
205const std::string FILEEXT::XaoFileExtension( "xao" );
206
207const wxString FILEEXT::GerberFileExtensionsRegex( "(gbr|gko|pho|(g[tb][alops])|(gm?\\d\\d*)|(gp[tb]))" );
208
209const std::string FILEEXT::KiCadUriPrefix( "kicad-embed" );
210
211
212bool FILEEXT::IsGerberFileExtension( const wxString& ext )
213{
214 static wxRegEx gerberRE( GerberFileExtensionsRegex, wxRE_ICASE );
215
216 return gerberRE.Matches( ext );
217}
218
219
221{
222 return _( "All files" ) + AddFileExtListToFilter( {} );
223}
224
225
227{
228 return _( "KiCad symbol library files" )
230}
231
232
234{
235 return _( "KiCad project files" ) + AddFileExtListToFilter( { ProjectFileExtension } );
236}
237
238
240{
241 return _( "KiCad legacy project files" )
243}
244
245
247{
248 return _( "All KiCad project files" )
250}
251
252
254{
255 return _( "All KiCad schematic files" )
257}
258
259
261{
262 return _( "KiCad legacy schematic files" )
264}
265
266
268{
269 return _( "KiCad s-expression schematic files" )
271}
272
273
275{
276 return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
277}
278
279
281{
282 return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
283}
284
285
287{
288 return _( "OrcadPCB2 netlist files" )
290}
291
292
294{
295 return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
296}
297
298
300{
301 return _( "Allegro netlist files" )
303}
304
305
307{
308 return _( "PADS netlist files" ) + AddFileExtListToFilter( { PADSNetlistFileExtension } );
309}
310
311
313{
314 return _( "EasyEDA (JLCEDA) Std backup archive" ) + AddFileExtListToFilter( { "zip" } );
315}
316
317
319{
320 return _( "EasyEDA (JLCEDA) Pro files" ) + AddFileExtListToFilter( { "epro", "zip" } );
321}
322
323
325{
326 return _( "KiCad printed circuit board files" )
328}
329
330
332{
333 return _( "KiCad footprint files" ) + AddFileExtListToFilter( { KiCadFootprintFileExtension } );
334}
335
336
338{
339 return _( "KiCad footprint library paths" )
341}
342
343
345{
346 return _( "KiCad design block path" )
348}
349
350
352{
353 return _( "KiCad design block library paths" )
355}
356
357
359{
360 return _( "Drawing sheet files" )
362}
363
364
365// Wildcard for cvpcb symbol to footprint link file
367{
368 return _( "KiCad symbol footprint link files" )
370}
371
372
373// Wildcard for reports and fabrication documents
375{
376 return _( "Drill files" )
377 + AddFileExtListToFilter( { DrillFileExtension, "nc", "xnc", "txt" } );
378}
379
380
382{
383 return _( "SVG files" ) + AddFileExtListToFilter( { SVGFileExtension } );
384}
385
386
388{
389 return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
390}
391
392
394{
395 return _( "CSV Files" ) + AddFileExtListToFilter( { CsvFileExtension } );
396}
397
398
400{
401 return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
402}
403
404
406{
407 return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
408}
409
410
412{
413 return _( "Json files" ) + AddFileExtListToFilter( { JsonFileExtension } );
414}
415
416
418{
419 return _( "Report files" ) + AddFileExtListToFilter( { ReportFileExtension } );
420}
421
422
424{
425 return _( "Component placement files" ) + AddFileExtListToFilter( { "pos" } );
426}
427
428
430{
431 return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
432}
433
434
436{
437 return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
438}
439
440
442{
443 return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
444}
445
446
448{
449 return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
450}
451
452
454{
455 return _( "Electrical rule check file" ) + AddFileExtListToFilter( { "erc" } );
456}
457
458
460{
461 return _( "SPICE library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
462}
463
464
466{
467 return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
468}
469
470
472{
473 return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
474}
475
476
478{
479 return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
480}
481
482
484{
485 return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
486}
487
488
490{
491 return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
492}
493
494
496{
497 return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
498}
499
500
502{
503 return _( "Gerber job file" ) + AddFileExtListToFilter( { GerberJobFileExtension } );
504}
505
506
508{
509 return _( "Specctra DSN file" )
511}
512
513
515{
516 return _( "Specctra Session file" )
518}
519
520
522{
523 return _( "IPC-D-356 Test Files" )
525}
526
527
529{
530 return _( "Workbook file" )
532}
533
534
536{
537 return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
538}
539
540
542{
543 return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
544}
545
546
548{
549 return _( "Hotkey file" ) + AddFileExtListToFilter( { HotkeyFileExtension } );
550}
551
552
554{
555 return _( "KiCad jobset files" ) + AddFileExtListToFilter( { KiCadJobSetFileExtension } );
556}
#define _(s)
static const std::string CadstarNetlistFileExtension
static const std::string LegacySchematicFileExtension
static const std::string KiCadDesignBlockLibPathExtension
static const std::string HtmlFileExtension
static const wxString GerberFileExtensionsRegex
static const std::string BrepFileExtension
static const std::string CadstarPartsLibraryFileExtension
static const std::string NetlistFileExtension
static const std::string KiCadDesignBlockPathExtension
static const std::string JpegFileExtension
static const std::string GerberJobFileExtension
static const std::string StepFileAbrvExtension
static const std::string GerberFileExtension
static const std::string XaoFileExtension
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 KiCadUriPrefix
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 PADSNetlistFileExtension
static const std::string DrawingSheetFileExtension
static const std::string BackupFileSuffix
static const std::string AutoSaveFilePrefix
static const std::string IpcD356FileExtension
static const std::string KiCadJobSetFileExtension
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 KiCadDesignBlockLibPathWildcard()
static wxString EasyEdaProFileWildcard()
static wxString LegacySchematicFileWildcard()
static wxString DxfFileWildcard()
static wxString PdfFileWildcard()
static wxString KiCadDesignBlockPathWildcard()
static wxString SVGFileWildcard()
static wxString PADSNetlistFileWildcard()
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 JobsetFileWildcard()
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.