KiCad PCB EDA Suite
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-2022 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 << " (" << wxFileSelectorDefaultWildcardStr << ")|"
92 << wxFileSelectorDefaultWildcardStr;
93 return filter;
94 }
95
96 wxString files_filter = " (";
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 << "; ";
103
104 files_filter << "*." << ext;
105 }
106
107 files_filter << ")|*.";
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 << ";*.";
116
117 first = false;
118
119 files_filter << formatWildcardExt( ext );
120 }
121
122 return files_filter;
123}
124
125const std::string BackupFileSuffix( "-bak" );
126
127const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
128const std::string SchematicSymbolFileExtension( "sym" );
129const std::string LegacySymbolLibFileExtension( "lib" );
130const std::string LegacySymbolDocumentFileExtension( "dcm" );
131
132const std::string VrmlFileExtension( "wrl" );
133
134const std::string ProjectFileExtension( "kicad_pro" );
135const std::string LegacyProjectFileExtension( "pro" );
136const std::string ProjectLocalSettingsFileExtension( "kicad_prl" );
137const std::string LegacySchematicFileExtension( "sch" );
138const std::string EagleSchematicFileExtension( "sch" );
139const std::string CadstarSchematicFileExtension( "csa" );
140const std::string KiCadSchematicFileExtension( "kicad_sch" );
141const std::string SpiceFileExtension( "cir" );
142const std::string CadstarNetlistFileExtension( "frp" );
143const std::string OrCadPcb2NetlistFileExtension( "net" );
144const std::string NetlistFileExtension( "net" );
145const std::string FootprintAssignmentFileExtension( "cmp" );
146const std::string GerberFileExtension( "gbr" );
147const std::string GerberJobFileExtension( "gbrjob" );
148const std::string HtmlFileExtension( "html" );
149const std::string EquFileExtension( "equ" );
150const std::string HotkeyFileExtension( "hotkeys" );
151const std::string DatabaseLibraryFileExtension( "kicad_dbl" );
152
153const std::string ArchiveFileExtension( "zip" );
154
155const std::string LegacyPcbFileExtension( "brd" );
156const std::string EaglePcbFileExtension( "brd" );
157const std::string CadstarPcbFileExtension( "cpa" );
158const std::string KiCadPcbFileExtension( "kicad_pcb" );
159const std::string DrawingSheetFileExtension( "kicad_wks" );
160const std::string DesignRulesFileExtension( "kicad_dru" );
161
162const std::string PdfFileExtension( "pdf" );
163const std::string MacrosFileExtension( "mcr" );
164const std::string DrillFileExtension( "drl" );
165const std::string SVGFileExtension( "svg" );
166const std::string ReportFileExtension( "rpt" );
167const std::string FootprintPlaceFileExtension( "pos" );
168
169const std::string KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
170const std::string LegacyFootprintLibPathExtension( "mod" ); // this is a file
171const std::string AltiumFootprintLibPathExtension( "PcbLib" ); // this is a file
172const std::string EagleFootprintLibPathExtension( "lbr" ); // this is a file
173const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
174
175const std::string KiCadFootprintFileExtension( "kicad_mod" );
176const std::string SpecctraDsnFileExtension( "dsn" );
177const std::string SpecctraSessionFileExtension( "ses" );
178const std::string IpcD356FileExtension( "d356" );
179const std::string WorkbookFileExtension( "wbk" );
180
181const std::string PngFileExtension( "png" );
182const std::string JpegFileExtension( "jpg" );
183const std::string TextFileExtension( "txt" );
184const std::string MarkdownFileExtension( "md" );
185const std::string CsvFileExtension( "csv" );
186
190const std::vector<std::string> GerberFileExtensions =
191{
193 "gbl", "gbo", "gbp", "gbs", "gko",
194 "gm1", "gm2", "gm3", "gm4", "gm5", "gm6", "gm7", "gm8", "gm9",
195 "g1", "g3",
196 "gpt", "gpb", "gtl", "gto", "gtp", "gts", "pho", "pos"
197};
198
199const wxString GerberFileExtensionWildCard( ".((gbr|gbrjob|(gb|gt)[alops])|pho)" );
200
201
202bool IsExtensionAccepted( const wxString& aExt, const std::vector<std::string> acceptedExts )
203{
204 for( auto extPtr = acceptedExts.begin(); extPtr != acceptedExts.end(); extPtr++ )
205 {
206 if( aExt.ToStdString() == *extPtr )
207 return true;
208 }
209 return false;
210}
211
212
213bool IsProtelExtension( const wxString& ext )
214{
215 static wxRegEx protelRE( wxT( "(gm1)|(g[tb][lapos])|(g\\d\\d*)" ), wxRE_ICASE );
216
217 return protelRE.Matches( ext );
218}
219
220
222{
223 return _( "All files" ) + AddFileExtListToFilter( {} );
224}
225
226
228{
229 return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
230}
231
232
234{
235 return _( "KiCad symbol library files" )
237}
238
239
241{
242 return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
243}
244
245
247{
248 return _( "KiCad database library files" )
250}
251
252
254{
255 return _( "All KiCad symbol library files" )
258 "lib" } );
259}
260
261
263{
264 return _( "KiCad project files" ) + AddFileExtListToFilter( { ProjectFileExtension } );
265}
266
267
269{
270 return _( "KiCad legacy project files" )
272}
273
274
276{
277 return _( "All KiCad project files" )
279}
280
281
283{
284 return _( "All KiCad schematic files" )
286}
287
288
290{
291 return _( "KiCad legacy schematic files" )
293}
294
295
297{
298 return _( "KiCad s-expression schematic files" )
300}
301
302
304{
305 return _( "Altium schematic files" ) + AddFileExtListToFilter( { "SchDoc" } );
306}
307
308
310{
311 return _( "CADSTAR Schematic Archive files" ) + AddFileExtListToFilter( { "csa" } );
312}
313
314
316{
317 return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
318}
319
320
322{
323 return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
324}
325
326
328{
329 return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
330}
331
332
334{
335 return _( "OrcadPCB2 netlist files" )
337}
338
339
341{
342 return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
343}
344
345
347{
348 return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
349}
350
351
353{
354 return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
355}
356
357
359{
360 return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
361}
362
364{
365 return _( "CADSTAR PCB Archive files" ) + AddFileExtListToFilter( { "cpa" } );
366}
367
369{
370 return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
371}
372
374{
375 return _( "Altium Designer PCB files" ) + AddFileExtListToFilter( { "PcbDoc" } );
376}
377
379{
380 return _( "Altium Circuit Studio PCB files" ) + AddFileExtListToFilter( { "CSPcbDoc" } );
381}
382
384{
385 return _( "Altium Circuit Maker PCB files" ) + AddFileExtListToFilter( { "CMPcbDoc" } );
386}
387
389{
390 return _( "Fabmaster PCB files" ) + AddFileExtListToFilter( { "txt", "fab" } );
391}
392
394{
395 return _( "KiCad printed circuit board files" ) +
397}
398
399
401{
402 return _( "KiCad footprint files" )
404}
405
406
408{
409 return _( "KiCad footprint library paths" )
411}
412
413
415{
416 return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
417}
418
419
421{
422 return _( "Altium PCB footprint library files" ) + AddFileExtListToFilter( { "PcbLib" } );
423}
424
425
427{
428 return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
429}
430
431
433{
434 return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
435}
436
437
439{
440 return _( "Drawing sheet files" )
442}
443
444
445// Wildcard for cvpcb symbol to footprint link file
447{
448 return _( "KiCad symbol footprint link files" )
450}
451
452
453// Wildcard for reports and fabrication documents
455{
456 return _( "Drill files" )
457 + AddFileExtListToFilter( { DrillFileExtension, "nc", "xnc", "txt" } );
458}
459
460
462{
463 return _( "SVG files" ) + AddFileExtListToFilter( { SVGFileExtension } );
464}
465
466
468{
469 return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
470}
471
472
474{
475 return _( "CSV Files" ) + AddFileExtListToFilter( { CsvFileExtension } );
476}
477
478
480{
481 return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
482}
483
484
486{
487 return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
488}
489
490
492{
493 return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
494}
495
496
498{
499 return _( "Component placement files" ) + AddFileExtListToFilter( { "pos" } );
500}
501
502
504{
505 return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
506}
507
508
510{
511 return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
512}
513
514
516{
517 return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
518}
519
520
522{
523 return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
524}
525
526
528{
529 return _( "Electrical rule check file" ) + AddFileExtListToFilter( { "erc" } );
530}
531
532
534{
535 return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
536}
537
538
540{
541 return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
542}
543
544
546{
547 return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
548}
549
550
552{
553 return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
554}
555
556
558{
559 return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
560}
561
562
564{
565 return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
566}
567
568
570{
571 return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
572}
573
574
576{
577 return _( "Gerber job file" ) + AddFileExtListToFilter( { GerberJobFileExtension } );
578}
579
580
582{
583 return _( "Specctra DSN file" )
585}
586
587
589{
590 return _( "Specctra Session file" )
592}
593
594
596{
597 return _( "IPC-D-356 Test Files" )
599}
600
601
603{
604 return _( "Workbook file" )
606}
607
608
610{
611 return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
612}
613
614
616{
617 return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
618}
619
620
622{
623 return _( "Hotkey file" ) + AddFileExtListToFilter( { HotkeyFileExtension } );
624}
#define _(s)
bool IsExtensionAccepted(const wxString &aExt, const std::vector< std::string > acceptedExts)
Checks if the file extension is in accepted extensions.
const std::vector< std::string > GerberFileExtensions
Gerber files extensions Kicad is to open.
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 IsProtelExtension(const wxString &ext)
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...
wxString KiCadSchematicFileWildcard()
wxString IDF3DFileWildcard()
wxString NetlistFileWildcard()
wxString SpecctraDsnFileWildcard()
wxString EagleFootprintLibPathWildcard()
wxString DatabaseLibFileWildcard()
wxString ErcFileWildcard()
wxString DxfFileWildcard()
wxString AllProjectFilesWildcard()
wxString IpcD356FileWildcard()
wxString LegacyProjectFileWildcard()
wxString ProjectFileWildcard()
wxString SpiceLibraryFileWildcard()
wxString KiCadFootprintLibPathWildcard()
wxString LegacyPcbFileWildcard()
wxString SchematicSymbolFileWildcard()
wxString FootprintPlaceFileWildcard()
wxString TextFileWildcard()
wxString LegacySymbolLibFileWildcard()
wxString DrillFileWildcard()
wxString AltiumFootprintLibPathWildcard()
wxString EagleFilesWildcard()
wxString SVGFileWildcard()
wxString CadstarPcbArchiveFileWildcard()
wxString SpecctraSessionFileWildcard()
wxString EquFileWildcard()
wxString ReportFileWildcard()
wxString LegacySchematicFileWildcard()
wxString Shapes3DFileWildcard()
wxString FootprintAssignmentFileWildcard()
wxString AltiumDesignerPcbFileWildcard()
wxString PCadPcbFileWildcard()
wxString PdfFileWildcard()
wxString WorkbookFileWildcard()
wxString ModLegacyExportFileWildcard()
wxString OrCadPcb2NetlistFileWildcard()
wxString EaglePcbFileWildcard()
wxString FabmasterPcbFileWildcard()
wxString AltiumCircuitMakerPcbFileWildcard()
wxString CadstarNetlistFileWildcard()
wxString GerberFileWildcard()
wxString KiCadFootprintLibFileWildcard()
wxString PngFileWildcard()
wxString CadstarSchematicArchiveFileWildcard()
wxString DrawingSheetFileWildcard()
wxString HtmlFileWildcard()
wxString AllSchematicFilesWildcard()
wxString AltiumSchematicFileWildcard()
wxString LegacyFootprintLibPathWildcard()
wxString AltiumCircuitStudioPcbFileWildcard()
wxString PSFileWildcard()
wxString CadstarArchiveFilesWildcard()
wxString HotkeyFileWildcard()
wxString AllFilesWildcard()
wxString SpiceNetlistFileWildcard()
wxString PcbFileWildcard()
wxString GedaPcbFootprintLibFileWildcard()
wxString GerberJobFileWildcard()
wxString GencadFileWildcard()
wxString EagleSchematicFileWildcard()
wxString KiCadSymbolLibFileWildcard()
wxString ZipFileWildcard()
wxString AllSymbolLibFilesWildcard()
wxString JpegFileWildcard()
wxString CsvFileWildcard()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const std::string SpecctraSessionFileExtension("ses")
const std::string TextFileExtension("txt")
const std::string JpegFileExtension("jpg")
const std::string DatabaseLibraryFileExtension("kicad_dbl")
const std::string ProjectFileExtension("kicad_pro")
const std::string KiCadSymbolLibFileExtension("kicad_sym")
const std::string OrCadPcb2NetlistFileExtension("net")
const std::string PdfFileExtension("pdf")
const std::string ReportFileExtension("rpt")
const std::string CadstarPcbFileExtension("cpa")
const std::string WorkbookFileExtension("wbk")
const std::string GedaPcbFootprintLibFileExtension("fp")
const std::string HtmlFileExtension("html")
const std::string SpecctraDsnFileExtension("dsn")
const std::string EaglePcbFileExtension("brd")
const std::string KiCadSchematicFileExtension("kicad_sch")
const std::string GerberJobFileExtension("gbrjob")
const std::string KiCadPcbFileExtension("kicad_pcb")
const wxString GerberFileExtensionWildCard(".((gbr|gbrjob|(gb|gt)[alops])|pho)")
const std::string EagleSchematicFileExtension("sch")
const std::string MarkdownFileExtension("md")
const std::string CsvFileExtension("csv")
const std::string SchematicSymbolFileExtension("sym")
const std::string IpcD356FileExtension("d356")
const std::string BackupFileSuffix("-bak")
const std::string HotkeyFileExtension("hotkeys")
const std::string VrmlFileExtension("wrl")
const std::string ProjectLocalSettingsFileExtension("kicad_prl")
const std::string AltiumFootprintLibPathExtension("PcbLib")
const std::string FootprintPlaceFileExtension("pos")
const std::string NetlistFileExtension("net")
const std::string ArchiveFileExtension("zip")
const std::string EquFileExtension("equ")
const std::string GerberFileExtension("gbr")
const std::string LegacySchematicFileExtension("sch")
const std::string PngFileExtension("png")
const std::string SpiceFileExtension("cir")
const std::string LegacySymbolLibFileExtension("lib")
const std::string KiCadFootprintLibPathExtension("pretty")
const std::string CadstarNetlistFileExtension("frp")
const std::string DrillFileExtension("drl")
const std::string KiCadFootprintFileExtension("kicad_mod")
const std::string DrawingSheetFileExtension("kicad_wks")
const std::string CadstarSchematicFileExtension("csa")
const std::string DesignRulesFileExtension("kicad_dru")
const std::string LegacySymbolDocumentFileExtension("dcm")
const std::string EagleFootprintLibPathExtension("lbr")
const std::string FootprintAssignmentFileExtension("cmp")
const std::string SVGFileExtension("svg")
const std::string LegacyPcbFileExtension("brd")
const std::string MacrosFileExtension("mcr")
const std::string LegacyFootprintLibPathExtension("mod")
const std::string LegacyProjectFileExtension("pro")
Definition of file extensions used in Kicad.