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