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 const std::string DesignRulesFileExtension( "kicad_dru" );
144 
145 const std::string PdfFileExtension( "pdf" );
146 const std::string MacrosFileExtension( "mcr" );
147 const std::string DrillFileExtension( "drl" );
148 const std::string SVGFileExtension( "svg" );
149 const std::string ReportFileExtension( "rpt" );
150 const std::string FootprintPlaceFileExtension( "pos" );
151 
152 const std::string KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
153 const std::string LegacyFootprintLibPathExtension( "mod" ); // this is a file
154 const std::string EagleFootprintLibPathExtension( "lbr" ); // this is a file
155 const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
156 
157 const std::string KiCadFootprintFileExtension( "kicad_mod" );
158 const std::string SpecctraDsnFileExtension( "dsn" );
159 const std::string IpcD356FileExtension( "d356" );
160 
161 const std::string PngFileExtension( "png" );
162 const std::string JpegFileExtension( "jpg" );
163 
164 
165 bool IsProtelExtension( const wxString& ext )
166 {
167  static wxRegEx protelRE( wxT( "(gm1)|(g[tb][lapos])|(g\\d\\d*)" ), wxRE_ICASE );
168 
169  return protelRE.Matches( ext );
170 }
171 
172 
174 {
175  return _( "All files" ) + AddFileExtListToFilter( {} );
176 }
177 
178 
180 {
181  return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
182 }
183 
184 
186 {
187  return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym" } );
188 }
189 
190 
192 {
193  return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
194 }
195 
196 
198 {
199  return _( "All KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym", "lib" } );
200 }
201 
202 
204 {
205  return _( "KiCad project files" ) + AddFileExtListToFilter( { "kicad_pro" } );
206 }
207 
208 
210 {
211  return _( "KiCad legacy project files" ) + AddFileExtListToFilter( { "pro" } );
212 }
213 
214 
216 {
217  return _( "All KiCad project files" ) + AddFileExtListToFilter( { "kicad_pro", "pro" } );
218 }
219 
220 
222 {
223  return _( "KiCad legacy schematic files" ) + AddFileExtListToFilter( { "sch" } );
224 }
225 
226 
228 {
229  return _( "KiCad s-expression schematic files" ) + AddFileExtListToFilter( { "kicad_sch" } );
230 }
231 
232 
234 {
235  return _( "Altium schematic files" ) + AddFileExtListToFilter( { "SchDoc" } );
236 }
237 
238 
240 {
241  return _( "CADSTAR Schematic Archive files" ) + AddFileExtListToFilter( { "csa" } );
242 }
243 
244 
246 {
247  return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
248 }
249 
250 
252 {
253  return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
254 }
255 
256 
258 {
259  return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
260 }
261 
262 
264 {
265  return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
266 }
267 
268 
270 {
271  return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
272 }
273 
274 
276 {
277  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
278 }
279 
280 
282 {
283  return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
284 }
285 
287 {
288  return _( "CADSTAR PCB Archive files" ) + AddFileExtListToFilter( { "cpa" } );
289 }
290 
292 {
293  return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
294 }
295 
297 {
298  return _( "Altium Designer PCB files" ) + AddFileExtListToFilter( { "PcbDoc" } );
299 }
300 
302 {
303  return _( "Altium Circuit Studio PCB files" ) + AddFileExtListToFilter( { "CSPcbDoc" } );
304 }
305 
307 {
308  return _( "Altium Circuit Maker PCB files" ) + AddFileExtListToFilter( { "CMPcbDoc" } );
309 }
310 
312 {
313  return _( "Fabmaster PCB files" ) + AddFileExtListToFilter( { "txt", "fab" } );
314 }
315 
316 wxString PcbFileWildcard()
317 {
318  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "kicad_pcb" } );
319 }
320 
321 
323 {
324  return _( "KiCad footprint files" ) + AddFileExtListToFilter( { "kicad_mod" } );
325 }
326 
327 
329 {
330  return _( "KiCad footprint library paths" ) + AddFileExtListToFilter( { "pretty" } );
331 }
332 
333 
335 {
336  return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
337 }
338 
339 
341 {
342  return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
343 }
344 
345 
347 {
348  return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
349 }
350 
351 
353 {
354  return _( "Page layout design files" ) + AddFileExtListToFilter( { "kicad_wks" } );
355 }
356 
357 
358 // Wildcard for cvpcb component to footprint link file
360 {
361  return _( "KiCad symbol footprint link files" ) + AddFileExtListToFilter( { "cmp" } );
362 }
363 
364 
365 // Wildcard for reports and fabrication documents
367 {
368  return _( "Drill files" ) + AddFileExtListToFilter( { "drl", "nc", "xnc", "txt" } );
369 }
370 
371 
372 wxString SVGFileWildcard()
373 {
374  return _( "SVG files" ) + AddFileExtListToFilter( { "svg" } );
375 }
376 
377 
379 {
380  return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
381 }
382 
383 
384 wxString CsvFileWildcard()
385 {
386  return _( "CSV Files" ) + AddFileExtListToFilter( { "csv" } );
387 }
388 
389 
390 wxString PdfFileWildcard()
391 {
392  return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
393 }
394 
395 
396 wxString PSFileWildcard()
397 {
398  return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
399 }
400 
401 
403 {
404  return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
405 }
406 
407 
409 {
410  return _( "Footprint place files" ) + AddFileExtListToFilter( { "pos" } );
411 }
412 
413 
415 {
416  return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
417 }
418 
419 
421 {
422  return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
423 }
424 
425 
427 {
428  return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
429 }
430 
431 
433 {
434  return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
435 }
436 
437 
438 wxString ErcFileWildcard()
439 {
440  return _( "Electronic rule check file" ) + AddFileExtListToFilter( { "erc" } );
441 }
442 
443 
445 {
446  return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
447 }
448 
449 
451 {
452  return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
453 }
454 
455 
457 {
458  return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
459 }
460 
461 
462 wxString EquFileWildcard()
463 {
464  return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
465 }
466 
467 
468 wxString ZipFileWildcard()
469 {
470  return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
471 }
472 
473 
475 {
476  return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
477 }
478 
479 
480 wxString DxfFileWildcard()
481 {
482  return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
483 }
484 
485 
487 {
488  return _( "Gerber job file" ) + AddFileExtListToFilter( { "gbrjob" } );
489 }
490 
491 
493 {
494  return _( "Specctra DSN file" ) + AddFileExtListToFilter( { "dsn" } );
495 }
496 
497 
499 {
500  return _( "IPC-D-356 Test Files" ) + AddFileExtListToFilter( { "d356" } );
501 }
502 
503 
505 {
506  return _( "Workbook file" ) + AddFileExtListToFilter( { "wbk" } );
507 }
508 
509 
510 wxString PngFileWildcard()
511 {
512  return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
513 }
514 
515 
517 {
518  return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
519 }
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()
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:201
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 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")