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 <stambaughw@gmail.com>
6  * Copyright (C) 1992-2021 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 
36 bool compareFileExtensions( const std::string& aExtension,
37  const std::vector<std::string>& aReference, bool aCaseSensitive )
38 {
39  // Form the regular expression string by placing all possible extensions into it as alternatives
40  std::string regexString = "(";
41  bool first = true;
42  for( const auto& ext : aReference )
43  {
44  // The | separate goes between the extensions
45  if( !first )
46  regexString += "|";
47  else
48  first = false;
49 
50  regexString += ext;
51  }
52  regexString += ")";
53 
54  // Create the regex and see if it matches
55  std::regex extRegex( regexString, aCaseSensitive ? std::regex::ECMAScript : std::regex::icase );
56  return std::regex_match( aExtension, extRegex );
57 }
58 
59 
60 wxString formatWildcardExt( const wxString& aWildcard )
61 {
62  wxString wc;
63 #if defined( __WXGTK__ )
64 
65  for( auto ch : aWildcard )
66  {
67  if( wxIsalpha( ch ) )
68  wc += wxString::Format( "[%c%c]", wxTolower( ch ), wxToupper( ch ) );
69  else
70  wc += ch;
71  }
72 
73  return wc;
74 #else
75  wc = aWildcard;
76 
77  return wc;
78 #endif
79 }
80 
81 
82 wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
83 {
84  if( aExts.size() == 0 )
85  {
86  // The "all files" wildcard is different on different systems
87  wxString filter;
88  filter << " (" << wxFileSelectorDefaultWildcardStr << ")|"
89  << wxFileSelectorDefaultWildcardStr;
90  return filter;
91  }
92 
93  wxString files_filter = " (";
94 
95  // Add extensions to the info message:
96  for( const std::string& ext : aExts )
97  {
98  if( files_filter.length() > 2 )
99  files_filter << "; ";
100 
101  files_filter << "*." << ext;
102  }
103 
104  files_filter << ")|*.";
105 
106  // Add extensions to the filter list, using a formatted string (GTK specific):
107  bool first = true;
108  for( const auto& ext : aExts )
109  {
110  if( !first )
111  files_filter << ";*.";
112 
113  first = false;
114 
115  files_filter << formatWildcardExt( ext );
116  }
117 
118  return files_filter;
119 }
120 
121 const std::string BackupFileSuffix( "-bak" );
122 
123 const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
124 const std::string SchematicSymbolFileExtension( "sym" );
125 const std::string LegacySymbolLibFileExtension( "lib" );
126 const std::string LegacySymbolDocumentFileExtension( "dcm" );
127 
128 const std::string VrmlFileExtension( "wrl" );
129 
130 const std::string ProjectFileExtension( "kicad_pro" );
131 const std::string LegacyProjectFileExtension( "pro" );
132 const std::string ProjectLocalSettingsFileExtension( "kicad_prl" );
133 const std::string LegacySchematicFileExtension( "sch" );
134 const std::string KiCadSchematicFileExtension( "kicad_sch" );
135 const std::string NetlistFileExtension( "net" );
136 const std::string FootprintAssignmentFileExtension( "cmp" );
137 const std::string GerberFileExtension( "gbr" );
138 const std::string GerberJobFileExtension( "gbrjob" );
139 const std::string HtmlFileExtension( "html" );
140 const std::string EquFileExtension( "equ" );
141 const std::string HotkeyFileExtension( "hotkeys" );
142 
143 const std::string ArchiveFileExtension( "zip" );
144 
145 const std::string LegacyPcbFileExtension( "brd" );
146 const std::string KiCadPcbFileExtension( "kicad_pcb" );
147 const std::string DrawingSheetFileExtension( "kicad_wks" );
148 const std::string DesignRulesFileExtension( "kicad_dru" );
149 
150 const std::string PdfFileExtension( "pdf" );
151 const std::string MacrosFileExtension( "mcr" );
152 const std::string DrillFileExtension( "drl" );
153 const std::string SVGFileExtension( "svg" );
154 const std::string ReportFileExtension( "rpt" );
155 const std::string FootprintPlaceFileExtension( "pos" );
156 
157 const std::string KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
158 const std::string LegacyFootprintLibPathExtension( "mod" ); // this is a file
159 const std::string EagleFootprintLibPathExtension( "lbr" ); // this is a file
160 const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
161 
162 const std::string KiCadFootprintFileExtension( "kicad_mod" );
163 const std::string SpecctraDsnFileExtension( "dsn" );
164 const std::string SpecctraSessionFileExtension( "ses" );
165 const std::string IpcD356FileExtension( "d356" );
166 const std::string WorkbookFileExtension( "wbk" );
167 
168 const std::string PngFileExtension( "png" );
169 const std::string JpegFileExtension( "jpg" );
170 const std::string TextFileExtension( "txt" );
171 
172 
173 bool IsProtelExtension( const wxString& ext )
174 {
175  static wxRegEx protelRE( wxT( "(gm1)|(g[tb][lapos])|(g\\d\\d*)" ), wxRE_ICASE );
176 
177  return protelRE.Matches( ext );
178 }
179 
180 
182 {
183  return _( "All files" ) + AddFileExtListToFilter( {} );
184 }
185 
186 
188 {
189  return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
190 }
191 
192 
194 {
195  return _( "KiCad symbol library files" )
197 }
198 
199 
201 {
202  return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
203 }
204 
205 
207 {
208  return _( "All KiCad symbol library files" )
210 }
211 
212 
214 {
215  return _( "KiCad project files" ) + AddFileExtListToFilter( { ProjectFileExtension } );
216 }
217 
218 
220 {
221  return _( "KiCad legacy project files" )
223 }
224 
225 
227 {
228  return _( "All KiCad project files" )
230 }
231 
232 
234 {
235  return _( "KiCad legacy schematic files" )
237 }
238 
239 
241 {
242  return _( "KiCad s-expression schematic files" )
244 }
245 
246 
248 {
249  return _( "Altium schematic files" ) + AddFileExtListToFilter( { "SchDoc" } );
250 }
251 
252 
254 {
255  return _( "CADSTAR Schematic Archive files" ) + AddFileExtListToFilter( { "csa" } );
256 }
257 
258 
260 {
261  return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
262 }
263 
264 
266 {
267  return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
268 }
269 
270 
272 {
273  return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
274 }
275 
276 
278 {
279  return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
280 }
281 
282 
284 {
285  return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
286 }
287 
288 
290 {
291  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
292 }
293 
294 
296 {
297  return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
298 }
299 
301 {
302  return _( "CADSTAR PCB Archive files" ) + AddFileExtListToFilter( { "cpa" } );
303 }
304 
306 {
307  return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
308 }
309 
311 {
312  return _( "Altium Designer PCB files" ) + AddFileExtListToFilter( { "PcbDoc" } );
313 }
314 
316 {
317  return _( "Altium Circuit Studio PCB files" ) + AddFileExtListToFilter( { "CSPcbDoc" } );
318 }
319 
321 {
322  return _( "Altium Circuit Maker PCB files" ) + AddFileExtListToFilter( { "CMPcbDoc" } );
323 }
324 
326 {
327  return _( "Fabmaster PCB files" ) + AddFileExtListToFilter( { "txt", "fab" } );
328 }
329 
330 wxString PcbFileWildcard()
331 {
332  return _( "KiCad printed circuit board files" ) +
334 }
335 
336 
338 {
339  return _( "KiCad footprint files" )
341 }
342 
343 
345 {
346  return _( "KiCad footprint library paths" )
348 }
349 
350 
352 {
353  return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
354 }
355 
356 
358 {
359  return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
360 }
361 
362 
364 {
365  return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
366 }
367 
368 
370 {
371  return _( "Drawing sheet files" )
373 }
374 
375 
376 // Wildcard for cvpcb symbol to footprint link file
378 {
379  return _( "KiCad symbol footprint link files" )
381 }
382 
383 
384 // Wildcard for reports and fabrication documents
386 {
387  return _( "Drill files" )
388  + AddFileExtListToFilter( { DrillFileExtension, "nc", "xnc", "txt" } );
389 }
390 
391 
392 wxString SVGFileWildcard()
393 {
394  return _( "SVG files" ) + AddFileExtListToFilter( { SVGFileExtension } );
395 }
396 
397 
399 {
400  return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
401 }
402 
403 
404 wxString CsvFileWildcard()
405 {
406  return _( "CSV Files" ) + AddFileExtListToFilter( { "csv" } );
407 }
408 
409 
410 wxString PdfFileWildcard()
411 {
412  return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
413 }
414 
415 
416 wxString PSFileWildcard()
417 {
418  return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
419 }
420 
421 
423 {
424  return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
425 }
426 
427 
429 {
430  return _( "Component placement files" ) + AddFileExtListToFilter( { "pos" } );
431 }
432 
433 
435 {
436  return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
437 }
438 
439 
441 {
442  return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
443 }
444 
445 
447 {
448  return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
449 }
450 
451 
453 {
454  return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
455 }
456 
457 
458 wxString ErcFileWildcard()
459 {
460  return _( "Electrical rule check file" ) + AddFileExtListToFilter( { "erc" } );
461 }
462 
463 
465 {
466  return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
467 }
468 
469 
471 {
472  return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
473 }
474 
475 
477 {
478  return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
479 }
480 
481 
482 wxString EquFileWildcard()
483 {
484  return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
485 }
486 
487 
488 wxString ZipFileWildcard()
489 {
490  return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
491 }
492 
493 
495 {
496  return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
497 }
498 
499 
500 wxString DxfFileWildcard()
501 {
502  return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
503 }
504 
505 
507 {
508  return _( "Gerber job file" ) + AddFileExtListToFilter( { GerberJobFileExtension } );
509 }
510 
511 
513 {
514  return _( "Specctra DSN file" )
516 }
517 
518 
520 {
521  return _( "Specctra Session file" )
523 }
524 
525 
527 {
528  return _( "IPC-D-356 Test Files" )
530 }
531 
532 
534 {
535  return _( "Workbook file" )
537 }
538 
539 
540 wxString PngFileWildcard()
541 {
542  return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
543 }
544 
545 
547 {
548  return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
549 }
550 
551 
553 {
554  return _( "Hotkey file" ) + AddFileExtListToFilter( { HotkeyFileExtension } );
555 }
const std::string KiCadSchematicFileExtension("kicad_sch")
wxString AllProjectFilesWildcard()
wxString GerberFileWildcard()
wxString SchematicSymbolFileWildcard()
const std::string GerberFileExtension("gbr")
wxString LegacySchematicFileWildcard()
wxString AllSymbolLibFilesWildcard()
const std::string KiCadFootprintFileExtension("kicad_mod")
wxString EaglePcbFileWildcard()
wxString EagleFootprintLibPathWildcard()
wxString SVGFileWildcard()
wxString LegacyProjectFileWildcard()
const std::string LegacyProjectFileExtension("pro")
wxString SpiceNetlistFileWildcard()
wxString PdfFileWildcard()
wxString KiCadSchematicFileWildcard()
wxString DxfFileWildcard()
const std::string KiCadPcbFileExtension("kicad_pcb")
wxString ZipFileWildcard()
wxString CsvFileWildcard()
wxString JpegFileWildcard()
const std::string DrawingSheetFileExtension("kicad_wks")
wxString AltiumCircuitMakerPcbFileWildcard()
const std::string PngFileExtension("png")
const std::string HotkeyFileExtension("hotkeys")
wxString LegacyFootprintLibPathWildcard()
const std::string SpecctraSessionFileExtension("ses")
wxString AllFilesWildcard()
const std::string ProjectLocalSettingsFileExtension("kicad_prl")
bool IsProtelExtension(const wxString &ext)
wxString EquFileWildcard()
const std::string LegacyFootprintLibPathExtension("mod")
wxString FabmasterPcbFileWildcard()
wxString LegacyPcbFileWildcard()
wxString CadstarSchematicArchiveFileWildcard()
const std::string KiCadSymbolLibFileExtension("kicad_sym")
const std::string IpcD356FileExtension("d356")
wxString PSFileWildcard()
wxString SpecctraSessionFileWildcard()
const std::string SVGFileExtension("svg")
wxString GencadFileWildcard()
wxString ReportFileWildcard()
const std::string SchematicSymbolFileExtension("sym")
const std::string HtmlFileExtension("html")
wxString NetlistFileWildcard()
wxString HtmlFileWildcard()
wxString FootprintAssignmentFileWildcard()
const std::string FootprintAssignmentFileExtension("cmp")
const std::string DrillFileExtension("drl")
wxString ModLegacyExportFileWildcard()
Definition of file extensions used in Kicad.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
wxString HotkeyFileWildcard()
const std::string VrmlFileExtension("wrl")
const std::string LegacyPcbFileExtension("brd")
#define _(s)
wxString KiCadSymbolLibFileWildcard()
const std::string MacrosFileExtension("mcr")
wxString LegacySymbolLibFileWildcard()
wxString DrillFileWildcard()
wxString AltiumDesignerPcbFileWildcard()
wxString IpcD356FileWildcard()
wxString PngFileWildcard()
const std::string KiCadFootprintLibPathExtension("pretty")
const std::string ReportFileExtension("rpt")
const std::string DesignRulesFileExtension("kicad_dru")
wxString ProjectFileWildcard()
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 GerberJobFileExtension("gbrjob")
wxString AltiumCircuitStudioPcbFileWildcard()
const std::string GedaPcbFootprintLibFileExtension("fp")
wxString ErcFileWildcard()
wxString KiCadFootprintLibPathWildcard()
wxString GerberJobFileWildcard()
wxString EagleSchematicFileWildcard()
const std::string ProjectFileExtension("kicad_pro")
wxString FootprintPlaceFileWildcard()
wxString Shapes3DFileWildcard()
wxString SpiceLibraryFileWildcard()
const std::string JpegFileExtension("jpg")
const std::string PdfFileExtension("pdf")
wxString PcbFileWildcard()
const std::string SpecctraDsnFileExtension("dsn")
wxString TextFileWildcard()
const std::string WorkbookFileExtension("wbk")
const std::string LegacySymbolDocumentFileExtension("dcm")
wxString SpecctraDsnFileWildcard()
wxString IDF3DFileWildcard()
wxString DrawingSheetFileWildcard()
const std::string NetlistFileExtension("net")
const std::string LegacySymbolLibFileExtension("lib")
const std::string EquFileExtension("equ")
wxString EagleFilesWildcard()
const std::string BackupFileSuffix("-bak")
wxString CadstarPcbArchiveFileWildcard()
wxString WorkbookFileWildcard()
const std::string TextFileExtension("txt")
wxString PCadPcbFileWildcard()
const std::string EagleFootprintLibPathExtension("lbr")
const std::string ArchiveFileExtension("zip")
wxString AltiumSchematicFileWildcard()
wxString KiCadFootprintLibFileWildcard()
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 CadstarArchiveFilesWildcard()
wxString GedaPcbFootprintLibFileWildcard()
wxString CadstarNetlistFileWildcard()
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
const std::string FootprintPlaceFileExtension("pos")
const std::string LegacySchematicFileExtension("sch")