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 
120 const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
121 const std::string SchematicSymbolFileExtension( "sym" );
122 const std::string LegacySymbolLibFileExtension( "lib" );
123 
124 const std::string VrmlFileExtension( "wrl" );
125 
126 const std::string ProjectFileExtension( "kicad_pro" );
127 const std::string LegacyProjectFileExtension( "pro" );
128 const std::string ProjectLocalSettingsFileExtension( "kicad_prl" );
129 const std::string LegacySchematicFileExtension( "sch" );
130 const std::string KiCadSchematicFileExtension( "kicad_sch" );
131 const std::string NetlistFileExtension( "net" );
132 const std::string ComponentFileExtension( "cmp" );
133 const std::string GerberFileExtension( "gbr" );
134 const std::string GerberJobFileExtension( "gbrjob" );
135 const std::string HtmlFileExtension( "html" );
136 const std::string EquFileExtension( "equ" );
137 
138 const std::string ArchiveFileExtension( "zip" );
139 
140 const std::string LegacyPcbFileExtension( "brd" );
141 const std::string KiCadPcbFileExtension( "kicad_pcb" );
142 const std::string PageLayoutDescrFileExtension( "kicad_wks" );
143 
144 const std::string PdfFileExtension( "pdf" );
145 const std::string MacrosFileExtension( "mcr" );
146 const std::string DrillFileExtension( "drl" );
147 const std::string SVGFileExtension( "svg" );
148 const std::string ReportFileExtension( "rpt" );
149 const std::string FootprintPlaceFileExtension( "pos" );
150 
151 const std::string KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
152 const std::string LegacyFootprintLibPathExtension( "mod" ); // this is a file
153 const std::string EagleFootprintLibPathExtension( "lbr" ); // this is a file
154 const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
155 
156 const std::string KiCadFootprintFileExtension( "kicad_mod" );
157 const std::string SpecctraDsnFileExtension( "dsn" );
158 const std::string IpcD356FileExtension( "d356" );
159 
160 const std::string PngFileExtension( "png" );
161 const std::string JpegFileExtension( "jpg" );
162 
163 
164 bool IsProtelExtension( const wxString& ext )
165 {
166  static wxRegEx protelRE( wxT( "(gm1)|(g[tb][lapos])|(g\\d\\d*)" ), wxRE_ICASE );
167 
168  return protelRE.Matches( ext );
169 }
170 
171 
173 {
174  return _( "All files" ) + AddFileExtListToFilter( {} );
175 }
176 
177 
179 {
180  return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
181 }
182 
183 
185 {
186  return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym" } );
187 }
188 
189 
191 {
192  return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
193 }
194 
195 
197 {
198  return _( "All KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym", "lib" } );
199 }
200 
201 
203 {
204  return _( "KiCad project files" ) + AddFileExtListToFilter( { "kicad_pro" } );
205 }
206 
207 
209 {
210  return _( "KiCad legacy project files" ) + AddFileExtListToFilter( { "pro" } );
211 }
212 
213 
215 {
216  return _( "All KiCad project files" ) + AddFileExtListToFilter( { "kicad_pro", "pro" } );
217 }
218 
219 
221 {
222  return _( "KiCad legacy schematic files" ) + AddFileExtListToFilter( { "sch" } );
223 }
224 
225 
227 {
228  return _( "KiCad s-expression schematic files" ) + AddFileExtListToFilter( { "kicad_sch" } );
229 }
230 
231 
233 {
234  return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
235 }
236 
237 
239 {
240  return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
241 }
242 
243 
245 {
246  return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
247 }
248 
249 
251 {
252  return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
253 }
254 
255 
257 {
258  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
259 }
260 
261 
263 {
264  return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
265 }
266 
267 
269 {
270  return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
271 }
272 
274 {
275  return _( "Altium Designer PCB files" ) + AddFileExtListToFilter( { "PcbDoc" } );
276 }
277 
279 {
280  return _( "Altium Circuit Studio PCB files" ) + AddFileExtListToFilter( { "CSPcbDoc" } );
281 }
282 
284 {
285  return _( "Altium Circuit Maker PCB files" ) + AddFileExtListToFilter( { "CMPcbDoc" } );
286 }
287 
289 {
290  return _( "Fabmaster PCB files" ) + AddFileExtListToFilter( { "txt", "fab" } );
291 }
292 
293 wxString PcbFileWildcard()
294 {
295  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "kicad_pcb" } );
296 }
297 
298 
300 {
301  return _( "KiCad footprint files" ) + AddFileExtListToFilter( { "kicad_mod" } );
302 }
303 
304 
306 {
307  return _( "KiCad footprint library paths" ) + AddFileExtListToFilter( { "pretty" } );
308 }
309 
310 
312 {
313  return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
314 }
315 
316 
318 {
319  return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
320 }
321 
322 
324 {
325  return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
326 }
327 
328 
330 {
331  return _( "Page layout design files" ) + AddFileExtListToFilter( { "kicad_wks" } );
332 }
333 
334 
335 // Wildcard for cvpcb component to footprint link file
337 {
338  return _( "KiCad symbol footprint link files" ) + AddFileExtListToFilter( { "cmp" } );
339 }
340 
341 
342 // Wildcard for reports and fabrication documents
344 {
345  return _( "Drill files" ) + AddFileExtListToFilter( { "drl", "nc", "xnc", "txt" } );
346 }
347 
348 
349 wxString SVGFileWildcard()
350 {
351  return _( "SVG files" ) + AddFileExtListToFilter( { "svg" } );
352 }
353 
354 
356 {
357  return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
358 }
359 
360 
361 wxString CsvFileWildcard()
362 {
363  return _( "CSV Files" ) + AddFileExtListToFilter( { "csv" } );
364 }
365 
366 
367 wxString PdfFileWildcard()
368 {
369  return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
370 }
371 
372 
373 wxString PSFileWildcard()
374 {
375  return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
376 }
377 
378 
380 {
381  return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
382 }
383 
384 
386 {
387  return _( "Footprint place files" ) + AddFileExtListToFilter( { "pos" } );
388 }
389 
390 
392 {
393  return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
394 }
395 
396 
398 {
399  return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
400 }
401 
402 
404 {
405  return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
406 }
407 
408 
410 {
411  return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
412 }
413 
414 
415 wxString ErcFileWildcard()
416 {
417  return _( "Electronic rule check file" ) + AddFileExtListToFilter( { "erc" } );
418 }
419 
420 
422 {
423  return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
424 }
425 
426 
428 {
429  return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
430 }
431 
432 
434 {
435  return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
436 }
437 
438 
439 wxString EquFileWildcard()
440 {
441  return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
442 }
443 
444 
445 wxString ZipFileWildcard()
446 {
447  return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
448 }
449 
450 
452 {
453  return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
454 }
455 
456 
457 wxString DxfFileWildcard()
458 {
459  return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
460 }
461 
462 
464 {
465  return _( "Gerber job file" ) + AddFileExtListToFilter( { "gbrjob" } );
466 }
467 
468 
470 {
471  return _( "Specctra DSN file" ) + AddFileExtListToFilter( { "dsn" } );
472 }
473 
474 
476 {
477  return _( "IPC-D-356 Test Files" ) + AddFileExtListToFilter( { "d356" } );
478 }
479 
480 
482 {
483  return _( "Workbook file" ) + AddFileExtListToFilter( { "wbk" } );
484 }
485 
486 
487 wxString PngFileWildcard()
488 {
489  return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
490 }
491 
492 
494 {
495  return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
496 }
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()
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")
wxString ProjectFileWildcard()
const std::string GerberJobFileExtension("gbrjob")
wxString AltiumCircuitStudioPcbFileWildcard()
const std::string GedaPcbFootprintLibFileExtension("fp")
wxString ErcFileWildcard()
wxString KiCadFootprintLibPathWildcard()
wxString GerberJobFileWildcard()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
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()
wxString SpecctraDsnFileWildcard()
wxString IDF3DFileWildcard()
const std::string NetlistFileExtension("net")
const std::string LegacySymbolLibFileExtension("lib")
const std::string EquFileExtension("equ")
wxString EagleFilesWildcard()
wxString WorkbookFileWildcard()
wxString PCadPcbFileWildcard()
const std::string EagleFootprintLibPathExtension("lbr")
const std::string ArchiveFileExtension("zip")
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 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")