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-2019 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 SchematicSymbolFileExtension( "sym" );
118 const std::string SchematicLibraryFileExtension( "lib" );
119 
120 const std::string VrmlFileExtension( "wrl" );
121 
122 const std::string ProjectFileExtension( "pro" );
123 const std::string SchematicFileExtension( "sch" );
124 const std::string NetlistFileExtension( "net" );
125 const std::string ComponentFileExtension( "cmp" );
126 const std::string GerberFileExtension( "gbr" );
127 const std::string GerberJobFileExtension( "gbrjob" );
128 const std::string HtmlFileExtension( "html" );
129 const std::string EquFileExtension( "equ" );
130 
131 const std::string LegacyPcbFileExtension( "brd" );
132 const std::string KiCadPcbFileExtension( "kicad_pcb" );
133 const std::string PageLayoutDescrFileExtension( "kicad_wks" );
134 
135 const std::string PdfFileExtension( "pdf" );
136 const std::string MacrosFileExtension( "mcr" );
137 const std::string DrillFileExtension( "drl" );
138 const std::string SVGFileExtension( "svg" );
139 const std::string ReportFileExtension( "rpt" );
140 const std::string FootprintPlaceFileExtension( "pos" );
141 const std::string KiCadLib3DShapesPathExtension( "3dshapes" );
142 
143 const std::string KiCadFootprintLibPathExtension( "pretty" );
144 const std::string LegacyFootprintLibPathExtension( "mod" );
145 const std::string EagleFootprintLibPathExtension( "lbr" );
146 
147 const std::string KiCadFootprintFileExtension( "kicad_mod" );
148 const std::string GedaPcbFootprintLibFileExtension( "fp" );
149 const std::string SpecctraDsnFileExtension( "dsn" );
150 const std::string IpcD356FileExtension( "d356" );
151 
152 const std::string PngFileExtension( "png" );
153 const std::string JpegFileExtension( "jpg" );
154 
155 
156 bool IsProtelExtension( const wxString& ext )
157 {
158  static wxRegEx protelRE( wxT( "(gm1)|(g[tb][lapos])|(g\\d\\d*)" ), wxRE_ICASE );
159 
160  return protelRE.Matches( ext );
161 }
162 
163 
165 {
166  return _( "All files" ) + AddFileExtListToFilter( {} );
167 }
168 
169 
171 {
172  return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
173 }
174 
175 
177 {
178  return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "lib" } );
179 }
180 
181 
183 {
184  return _( "KiCad project files" ) + AddFileExtListToFilter( { "pro" } );
185 }
186 
187 
189 {
190  return _( "KiCad schematic files" ) + AddFileExtListToFilter( { "sch" } );
191 }
192 
193 
195 {
196  return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
197 }
198 
199 
201 {
202  return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
203 }
204 
205 
207 {
208  return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
209 }
210 
211 
213 {
214  return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
215 }
216 
217 
219 {
220  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
221 }
222 
223 
225 {
226  return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
227 }
228 
229 
231 {
232  return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
233 }
234 
235 
236 wxString PcbFileWildcard()
237 {
238  return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "kicad_pcb" } );
239 }
240 
241 
243 {
244  return _( "KiCad footprint files" ) + AddFileExtListToFilter( { "kicad_mod" } );
245 }
246 
247 
249 {
250  return _( "KiCad footprint library paths" ) + AddFileExtListToFilter( { "pretty" } );
251 }
252 
253 
255 {
256  return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
257 }
258 
259 
261 {
262  return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
263 }
264 
265 
267 {
268  return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
269 }
270 
271 
273 {
274  return _( "Page layout design files" ) + AddFileExtListToFilter( { "kicad_wks" } );
275 }
276 
277 
278 // Wildcard for cvpcb component to footprint link file
280 {
281  return _( "KiCad symbol footprint link files" ) + AddFileExtListToFilter( { "cmp" } );
282 }
283 
284 
285 // Wildcard for reports and fabrication documents
287 {
288  return _( "Drill files" ) + AddFileExtListToFilter( { "drl", "nc", "xnc" } );
289 }
290 
291 
292 wxString SVGFileWildcard()
293 {
294  return _( "SVG files" ) + AddFileExtListToFilter( { "svg" } );
295 }
296 
297 
299 {
300  return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
301 }
302 
303 
304 wxString CsvFileWildcard()
305 {
306  return _( "CSV Files" ) + AddFileExtListToFilter( { "csv" } );
307 }
308 
309 
310 wxString PdfFileWildcard()
311 {
312  return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
313 }
314 
315 
316 wxString PSFileWildcard()
317 {
318  return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
319 }
320 
321 
323 {
324  return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
325 }
326 
327 
329 {
330  return _( "Footprint place files" ) + AddFileExtListToFilter( { "pos" } );
331 }
332 
333 
335 {
336  return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
337 }
338 
339 
341 {
342  return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
343 }
344 
345 
347 {
348  return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
349 }
350 
351 
353 {
354  return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
355 }
356 
357 
358 wxString ErcFileWildcard()
359 {
360  return _( "Electronic rule check file" ) + AddFileExtListToFilter( { "erc" } );
361 }
362 
363 
365 {
366  return _( "Spice library file" ) + AddFileExtListToFilter( { "lib", "mod" } );
367 }
368 
369 
371 {
372  return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
373 }
374 
375 
377 {
378  return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
379 }
380 
381 
382 wxString EquFileWildcard()
383 {
384  return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
385 }
386 
387 
388 wxString ZipFileWildcard()
389 {
390  return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
391 }
392 
393 
395 {
396  return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
397 }
398 
399 
400 wxString DxfFileWildcard()
401 {
402  return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
403 }
404 
405 
407 {
408  return _( "Gerber job file" ) + AddFileExtListToFilter( { "gbrjob" } );
409 }
410 
411 
413 {
414  return _( "Specctra DSN file" ) + AddFileExtListToFilter( { "dsn" } );
415 }
416 
417 
419 {
420  return _( "IPC-D-356 Test Files" ) + AddFileExtListToFilter( { "d356" } );
421 }
422 
423 
425 {
426  return _( "Workbook file" ) + AddFileExtListToFilter( { "wbk" } );
427 }
428 
429 
430 wxString PngFileWildcard()
431 {
432  return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
433 }
434 
435 
437 {
438  return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
439 }
wxString GerberFileWildcard()
wxString SchematicSymbolFileWildcard()
const std::string GerberFileExtension("gbr")
wxString PageLayoutDescrFileWildcard()
const std::string ComponentFileExtension("cmp")
const std::string KiCadFootprintFileExtension("kicad_mod")
wxString SchematicFileWildcard()
wxString EaglePcbFileWildcard()
wxString EagleFootprintLibPathWildcard()
wxString SVGFileWildcard()
wxString ComponentFileWildcard()
wxString SpiceNetlistFileWildcard()
wxString PdfFileWildcard()
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 KiCadLib3DShapesPathExtension("3dshapes")
3D shapes default libpath
const std::string SchematicLibraryFileExtension("lib")
wxString LegacyPcbFileWildcard()
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")
const std::string MacrosFileExtension("mcr")
#define _(s)
wxString DrillFileWildcard()
wxString IpcD356FileWildcard()
wxString PngFileWildcard()
const std::string KiCadFootprintLibPathExtension("pretty")
KICAD PLUGIN libpath.
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()
wxString FootprintPlaceFileWildcard()
const std::string SchematicFileExtension("sch")
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")