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 auto& ext : aExts )
95  {
96  files_filter << " *." << ext;
97  }
98 
99  files_filter << ")|*.";
100 
101  // Add extensions to the filter list, using a formated string (GTK specific):
102  bool first = true;
103  for( const auto& ext : aExts )
104  {
105  if( !first )
106  files_filter << ";*.";
107 
108  first = false;
109 
110  files_filter << formatWildcardExt( ext );
111  }
112 
113  return files_filter;
114 }
115 
116 
117 const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
118 const std::string SchematicSymbolFileExtension( "sym" );
119 const std::string SchematicLibraryFileExtension( "lib" );
120 
121 const std::string VrmlFileExtension( "wrl" );
122 
123 const std::string ProjectFileExtension( "pro" );
124 const std::string LegacySchematicFileExtension( "sch" );
125 const std::string KiCadSchematicFileExtension( "kicad_sch" );
126 const std::string NetlistFileExtension( "net" );
127 const std::string ComponentFileExtension( "cmp" );
128 const std::string GerberFileExtension( "gbr" );
129 const std::string GerberJobFileExtension( "gbrjob" );
130 const std::string HtmlFileExtension( "html" );
131 const std::string EquFileExtension( "equ" );
132 
133 const std::string LegacyPcbFileExtension( "brd" );
134 const std::string KiCadPcbFileExtension( "kicad_pcb" );
135 const std::string PageLayoutDescrFileExtension( "kicad_wks" );
136 
137 const std::string PdfFileExtension( "pdf" );
138 const std::string MacrosFileExtension( "mcr" );
139 const std::string DrillFileExtension( "drl" );
140 const std::string SVGFileExtension( "svg" );
141 const std::string ReportFileExtension( "rpt" );
142 const std::string FootprintPlaceFileExtension( "pos" );
143 
144 const std::string KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
145 const std::string LegacyFootprintLibPathExtension( "mod" ); // this is a file
146 const std::string EagleFootprintLibPathExtension( "lbr" ); // this is a file
147 const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
148 
149 const std::string KiCadFootprintFileExtension( "kicad_mod" );
150 const std::string SpecctraDsnFileExtension( "dsn" );
151 const std::string IpcD356FileExtension( "d356" );
152 
153 const std::string PngFileExtension( "png" );
154 const std::string JpegFileExtension( "jpg" );
155 
156 
157 bool IsProtelExtension( const wxString& ext )
158 {
159  static wxRegEx protelRE( wxT( "(gm1)|(g[tb][lapos])|(g\\d\\d*)" ), wxRE_ICASE );
160 
161  return protelRE.Matches( ext );
162 }
163 
164 
166 {
167  return _( "All files" ) + AddFileExtListToFilter( {} );
168 }
169 
170 
172 {
173  return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
174 }
175 
176 
178 {
179  return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym" } );
180 }
181 
182 
184 {
185  return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
186 }
187 
188 
190 {
191  return _( "KiCad project files" ) + AddFileExtListToFilter( { "pro" } );
192 }
193 
194 
196 {
197  return _( "KiCad legacy schematic files" ) + AddFileExtListToFilter( { "sch" } );
198 }
199 
200 
202 {
203  return _( "KiCad s-expression schematic files" ) + AddFileExtListToFilter( { "kicad_sch" } );
204 }
205 
206 
208 {
209  return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
210 }
211 
212 
214 {
215  return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
216 }
217 
218 
220 {
221  return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
222 }
223 
224 
226 {
227  return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
228 }
229 
230 
232 {
233  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
234 }
235 
236 
238 {
239  return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
240 }
241 
242 
244 {
245  return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
246 }
247 
248 
249 wxString PcbFileWildcard()
250 {
251  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "kicad_pcb" } );
252 }
253 
254 
256 {
257  return _( "KiCad footprint files" ) + AddFileExtListToFilter( { "kicad_mod" } );
258 }
259 
260 
262 {
263  return _( "KiCad footprint library paths" ) + AddFileExtListToFilter( { "pretty" } );
264 }
265 
266 
268 {
269  return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
270 }
271 
272 
274 {
275  return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
276 }
277 
278 
280 {
281  return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
282 }
283 
284 
286 {
287  return _( "Page layout design files" ) + AddFileExtListToFilter( { "kicad_wks" } );
288 }
289 
290 
291 // Wildcard for cvpcb component to footprint link file
293 {
294  return _( "KiCad symbol footprint link files" ) + AddFileExtListToFilter( { "cmp" } );
295 }
296 
297 
298 // Wildcard for reports and fabrication documents
300 {
301  return _( "Drill files" ) + AddFileExtListToFilter( { "drl", "nc", "xnc" } );
302 }
303 
304 
305 wxString SVGFileWildcard()
306 {
307  return _( "SVG files" ) + AddFileExtListToFilter( { "svg" } );
308 }
309 
310 
312 {
313  return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
314 }
315 
316 
317 wxString CsvFileWildcard()
318 {
319  return _( "CSV Files" ) + AddFileExtListToFilter( { "csv" } );
320 }
321 
322 
323 wxString PdfFileWildcard()
324 {
325  return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
326 }
327 
328 
329 wxString PSFileWildcard()
330 {
331  return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
332 }
333 
334 
336 {
337  return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
338 }
339 
340 
342 {
343  return _( "Footprint place files" ) + AddFileExtListToFilter( { "pos" } );
344 }
345 
346 
348 {
349  return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
350 }
351 
352 
354 {
355  return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
356 }
357 
358 
360 {
361  return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
362 }
363 
364 
366 {
367  return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
368 }
369 
370 
371 wxString ErcFileWildcard()
372 {
373  return _( "Electronic rule check file" ) + AddFileExtListToFilter( { "erc" } );
374 }
375 
376 
378 {
379  return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
380 }
381 
382 
384 {
385  return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
386 }
387 
388 
390 {
391  return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
392 }
393 
394 
395 wxString EquFileWildcard()
396 {
397  return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
398 }
399 
400 
401 wxString ZipFileWildcard()
402 {
403  return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
404 }
405 
406 
408 {
409  return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
410 }
411 
412 
413 wxString DxfFileWildcard()
414 {
415  return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
416 }
417 
418 
420 {
421  return _( "Gerber job file" ) + AddFileExtListToFilter( { "gbrjob" } );
422 }
423 
424 
426 {
427  return _( "Specctra DSN file" ) + AddFileExtListToFilter( { "dsn" } );
428 }
429 
430 
432 {
433  return _( "IPC-D-356 Test Files" ) + AddFileExtListToFilter( { "d356" } );
434 }
435 
436 
438 {
439  return _( "Workbook file" ) + AddFileExtListToFilter( { "wbk" } );
440 }
441 
442 
443 wxString PngFileWildcard()
444 {
445  return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
446 }
447 
448 
450 {
451  return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
452 }
const std::string KiCadSchematicFileExtension("kicad_sch")
wxString GerberFileWildcard()
wxString SchematicSymbolFileWildcard()
const std::string GerberFileExtension("gbr")
wxString PageLayoutDescrFileWildcard()
const std::string ComponentFileExtension("cmp")
wxString LegacySchematicFileWildcard()
const std::string KiCadFootprintFileExtension("kicad_mod")
wxString EaglePcbFileWildcard()
wxString EagleFootprintLibPathWildcard()
wxString SVGFileWildcard()
wxString ComponentFileWildcard()
wxString SpiceNetlistFileWildcard()
wxString PdfFileWildcard()
wxString KiCadSchematicFileWildcard()
wxString DxfFileWildcard()
const std::string KiCadPcbFileExtension("kicad_pcb")
wxString SchematicLibraryFileWildcard()
wxString ZipFileWildcard()
wxString CsvFileWildcard()
wxString JpegFileWildcard()
const std::string PngFileExtension("png")
wxString LegacyFootprintLibPathWildcard()
wxString AllFilesWildcard()
bool IsProtelExtension(const wxString &ext)
wxString EquFileWildcard()
const std::string LegacyFootprintLibPathExtension("mod")
const std::string SchematicLibraryFileExtension("lib")
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 DrillFileWildcard()
wxString IpcD356FileWildcard()
wxString PngFileWildcard()
const std::string KiCadFootprintLibPathExtension("pretty")
const std::string ReportFileExtension("rpt")
wxString ProjectFileWildcard()
const std::string GerberJobFileExtension("gbrjob")
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
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 EquFileExtension("equ")
wxString EagleFilesWildcard()
wxString WorkbookFileWildcard()
const std::string ProjectFileExtension("pro")
wxString PCadPcbFileWildcard()
const std::string EagleFootprintLibPathExtension("lbr")
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")