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" );
206const std::string FILEEXT::PlyFileExtension( "ply" );
207const std::string FILEEXT::StlFileExtension( "stl" );
208
209const wxString FILEEXT::GerberFileExtensionsRegex( "(gbr|gko|pho|(g[tb][alops])|(gm?\\d\\d*)|(gp[tb]))" );
210
211const std::string FILEEXT::KiCadUriPrefix( "kicad-embed" );
212
213
214bool FILEEXT::IsGerberFileExtension( const wxString& ext )
215{
216 static wxRegEx gerberRE( GerberFileExtensionsRegex, wxRE_ICASE );
217
218 return gerberRE.Matches( ext );
219}
220
221
223{
224 return _( "All files" ) + AddFileExtListToFilter( {} );
225}
226
227
229{
230 return _( "KiCad symbol library files" )
232}
233
234
236{
237 return _( "KiCad project files" ) + AddFileExtListToFilter( { ProjectFileExtension } );
238}
239
240
242{
243 return _( "KiCad legacy project files" )
245}
246
247
249{
250 return _( "All KiCad project files" )
252}
253
254
256{
257 return _( "All KiCad schematic files" )
259}
260
261
263{
264 return _( "KiCad legacy schematic files" )
266}
267
268
270{
271 return _( "KiCad s-expression schematic files" )
273}
274
275
277{
278 return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
279}
280
281
283{
284 return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
285}
286
287
289{
290 return _( "OrcadPCB2 netlist files" )
292}
293
294
296{
297 return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
298}
299
300
302{
303 return _( "Allegro netlist files" )
305}
306
307
309{
310 return _( "PADS netlist files" ) + AddFileExtListToFilter( { PADSNetlistFileExtension } );
311}
312
313
315{
316 return _( "EasyEDA (JLCEDA) Std backup archive" ) + AddFileExtListToFilter( { "zip" } );
317}
318
319
321{
322 return _( "EasyEDA (JLCEDA) Pro files" ) + AddFileExtListToFilter( { "epro", "zip" } );
323}
324
325
327{
328 return _( "KiCad printed circuit board files" )
330}
331
332
334{
335 return _( "KiCad footprint files" ) + AddFileExtListToFilter( { KiCadFootprintFileExtension } );
336}
337
338
340{
341 return _( "KiCad footprint library paths" )
343}
344
345
347{
348 return _( "KiCad design block path" )
350}
351
352
354{
355 return _( "KiCad design block library paths" )
357}
358
359
361{
362 return _( "Drawing sheet files" )
364}
365
366
367// Wildcard for cvpcb symbol to footprint link file
369{
370 return _( "KiCad symbol footprint link files" )
372}
373
374
375// Wildcard for reports and fabrication documents
377{
378 return _( "Drill files" )
379 + AddFileExtListToFilter( { DrillFileExtension, "nc", "xnc", "txt" } );
380}
381
382
384{
385 return _( "SVG files" ) + AddFileExtListToFilter( { SVGFileExtension } );
386}
387
388
390{
391 return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
392}
393
394
396{
397 return _( "CSV Files" ) + AddFileExtListToFilter( { CsvFileExtension } );
398}
399
400
402{
403 return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
404}
405
406
408{
409 return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
410}
411
412
414{
415 return _( "Json files" ) + AddFileExtListToFilter( { JsonFileExtension } );
416}
417
418
420{
421 return _( "Report files" ) + AddFileExtListToFilter( { ReportFileExtension } );
422}
423
424
426{
427 return _( "Component placement files" ) + AddFileExtListToFilter( { "pos" } );
428}
429
430
432{
433 return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
434}
435
436
438{
439 return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
440}
441
442
444{
445 return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
446}
447
448
450{
451 return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
452}
453
454
456{
457 return _( "Electrical rule check file" ) + AddFileExtListToFilter( { "erc" } );
458}
459
460
462{
463 return _( "SPICE library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
464}
465
466
468{
469 return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
470}
471
472
474{
475 return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
476}
477
478
480{
481 return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
482}
483
484
486{
487 return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
488}
489
490
492{
493 return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
494}
495
496
498{
499 return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
500}
501
502
504{
505 return _( "Gerber job file" ) + AddFileExtListToFilter( { GerberJobFileExtension } );
506}
507
508
510{
511 return _( "Specctra DSN file" )
513}
514
515
517{
518 return _( "Specctra Session file" )
520}
521
522
524{
525 return _( "IPC-D-356 Test Files" )
527}
528
529
531{
532 return _( "Workbook file" )
534}
535
536
538{
539 return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
540}
541
542
544{
545 return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
546}
547
548
550{
551 return _( "Hotkey file" ) + AddFileExtListToFilter( { HotkeyFileExtension } );
552}
553
554
556{
557 return _( "KiCad jobset files" ) + AddFileExtListToFilter( { KiCadJobSetFileExtension } );
558}
#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 StlFileExtension
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 PlyFileExtension
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.