You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

422 lines
10 KiB

  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-2018 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. /**
  26. * @file wildcards_and_files_ext.cpp
  27. * Definition of file extensions used in Kicad.
  28. */
  29. #include <wildcards_and_files_ext.h>
  30. /**
  31. * Format wildcard extension to support case sensitive file dialogs.
  32. *
  33. * The file extension wildcards of the GTK+ file dialog are case sensitive so using all lower
  34. * case characters means that only file extensions that are all lower case will show up in the
  35. * file dialog. The GTK+ file dialog does support regular expressions so the file extension
  36. * is converted to a regular expression ( sch -> [sS][cC][hH] ) when wxWidgets is built against
  37. * GTK+. Please make sure you call this function when adding new file wildcards.
  38. *
  39. * @note When calling wxFileDialog with a default file defined, make sure you include the
  40. * file extension along with the file name. Otherwise, on GTK+ builds, the file
  41. * dialog will append the wildcard regular expression as the file extension which is
  42. * surely not what you want.
  43. *
  44. * @param aWildcard is the extension part of the wild card.
  45. *
  46. * @return the build appropriate file dialog wildcard filter.
  47. */
  48. static wxString formatWildcardExt( const wxString& aWildcard )
  49. {
  50. wxString wc;
  51. #if defined( __WXGTK__ )
  52. for( auto ch : aWildcard )
  53. {
  54. if( wxIsalpha( ch ) )
  55. wc += wxString::Format( "[%c%c]", wxTolower( ch ), wxToupper( ch ) );
  56. else
  57. wc += ch;
  58. }
  59. return wc;
  60. #else
  61. wc = aWildcard;
  62. return wc;
  63. #endif
  64. }
  65. wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
  66. {
  67. if( aExts.size() == 0 )
  68. {
  69. // The "all files" wildcard is different on different systems
  70. wxString filter;
  71. filter << " (" << wxFileSelectorDefaultWildcardStr << ")|"
  72. << wxFileSelectorDefaultWildcardStr;
  73. return filter;
  74. }
  75. wxString files_filter = " (";
  76. // Add extensions to the info message:
  77. for( const auto& ext : aExts )
  78. {
  79. files_filter << " *." << ext;
  80. }
  81. files_filter << ")|*.";
  82. // Add extensions to the filter list, using a formated string (GTK specific):
  83. bool first = true;
  84. for( const auto& ext : aExts )
  85. {
  86. if( !first )
  87. files_filter << ";*.";
  88. first = false;
  89. files_filter << formatWildcardExt( ext );
  90. }
  91. return files_filter;
  92. }
  93. const std::string SchematicSymbolFileExtension( "sym" );
  94. const std::string SchematicLibraryFileExtension( "lib" );
  95. const std::string SchematicBackupFileExtension( "bak" );
  96. const std::string VrmlFileExtension( "wrl" );
  97. const std::string ProjectFileExtension( "pro" );
  98. const std::string SchematicFileExtension( "sch" );
  99. const std::string NetlistFileExtension( "net" );
  100. const std::string ComponentFileExtension( "cmp" );
  101. const std::string GerberFileExtension( "gbr" );
  102. const std::string GerberJobFileExtension( "gbrjob" );
  103. const std::string HtmlFileExtension( "html" );
  104. const std::string LegacyPcbFileExtension( "brd" );
  105. const std::string KiCadPcbFileExtension( "kicad_pcb" );
  106. const std::string PageLayoutDescrFileExtension( "kicad_wks" );
  107. const std::string PdfFileExtension( "pdf" );
  108. const std::string MacrosFileExtension( "mcr" );
  109. const std::string DrillFileExtension( "drl" );
  110. const std::string SVGFileExtension( "svg" );
  111. const std::string ReportFileExtension( "rpt" );
  112. const std::string FootprintPlaceFileExtension( "pos" );
  113. const std::string KiCadLib3DShapesPathExtension( "3dshapes" ); ///< 3D shapes default libpath
  114. const std::string KiCadFootprintLibPathExtension( "pretty" ); ///< KICAD PLUGIN libpath
  115. const std::string LegacyFootprintLibPathExtension( "mod" );
  116. const std::string EagleFootprintLibPathExtension( "lbr" );
  117. const std::string KiCadFootprintFileExtension( "kicad_mod" );
  118. const std::string GedaPcbFootprintLibFileExtension( "fp" );
  119. const std::string SpecctraDsnFileExtension( "dsn" );
  120. const std::string IpcD356FileExtension( "d356" );
  121. const std::string PngFileExtension( "png" );
  122. const std::string JpegFileExtension( "jpg" );
  123. wxString AllFilesWildcard()
  124. {
  125. return _( "All files" ) + AddFileExtListToFilter( {} );
  126. }
  127. wxString SchematicSymbolFileWildcard()
  128. {
  129. return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
  130. }
  131. wxString SchematicLibraryFileWildcard()
  132. {
  133. return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "lib" } );
  134. }
  135. wxString ProjectFileWildcard()
  136. {
  137. return _( "KiCad project files" ) + AddFileExtListToFilter( { "pro" } );
  138. }
  139. wxString SchematicFileWildcard()
  140. {
  141. return _( "KiCad schematic files" ) + AddFileExtListToFilter( { "sch" } );
  142. }
  143. wxString EagleSchematicFileWildcard()
  144. {
  145. return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
  146. }
  147. wxString EagleFilesWildcard()
  148. {
  149. return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
  150. }
  151. wxString NetlistFileWildcard()
  152. {
  153. return _( "KiCad netlist files" ) + AddFileExtListToFilter( { "net" } );
  154. }
  155. wxString GerberFileWildcard()
  156. {
  157. return _( "Gerber files" ) + AddFileExtListToFilter( { "pho" } );
  158. }
  159. wxString LegacyPcbFileWildcard()
  160. {
  161. return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "brd" } );
  162. }
  163. wxString EaglePcbFileWildcard()
  164. {
  165. return _( "Eagle ver. 6.x XML PCB files" ) + AddFileExtListToFilter( { "brd" } );
  166. }
  167. wxString PCadPcbFileWildcard()
  168. {
  169. return _( "P-Cad 200x ASCII PCB files" ) + AddFileExtListToFilter( { "pcb" } );
  170. }
  171. wxString PcbFileWildcard()
  172. {
  173. return _( "KiCad printed circuit board files" ) + AddFileExtListToFilter( { "kicad_pcb" } );
  174. }
  175. wxString KiCadFootprintLibFileWildcard()
  176. {
  177. return _( "KiCad footprint files" ) + AddFileExtListToFilter( { "kicad_mod" } );
  178. }
  179. wxString KiCadFootprintLibPathWildcard()
  180. {
  181. return _( "KiCad footprint library paths" ) + AddFileExtListToFilter( { "pretty" } );
  182. }
  183. wxString LegacyFootprintLibPathWildcard()
  184. {
  185. return _( "Legacy footprint library files" ) + AddFileExtListToFilter( { "mod" } );
  186. }
  187. wxString EagleFootprintLibPathWildcard()
  188. {
  189. return _( "Eagle ver. 6.x XML library files" ) + AddFileExtListToFilter( { "lbr" } );
  190. }
  191. wxString GedaPcbFootprintLibFileWildcard()
  192. {
  193. return _( "Geda PCB footprint library files" ) + AddFileExtListToFilter( { "fp" } );
  194. }
  195. wxString PageLayoutDescrFileWildcard()
  196. {
  197. return _( "Page layout design files" ) + AddFileExtListToFilter( { "kicad_wks" } );
  198. }
  199. // Wildcard for cvpcb component to footprint link file
  200. wxString ComponentFileWildcard()
  201. {
  202. return _( "KiCad symbol footprint link files" ) + AddFileExtListToFilter( { "cmp" } );
  203. }
  204. // Wildcard for reports and fabrication documents
  205. wxString DrillFileWildcard()
  206. {
  207. return _( "Drill files" ) + AddFileExtListToFilter( { "drl", "nc", "xnc" } );
  208. }
  209. wxString SVGFileWildcard()
  210. {
  211. return _( "SVG files" ) + AddFileExtListToFilter( { "svg" } );
  212. }
  213. wxString HtmlFileWildcard()
  214. {
  215. return _( "HTML files" ) + AddFileExtListToFilter( { "htm", "html" } );
  216. }
  217. wxString CsvFileWildcard()
  218. {
  219. return _( "CSV Files" ) + AddFileExtListToFilter( { "csv" } );
  220. }
  221. wxString PdfFileWildcard()
  222. {
  223. return _( "Portable document format files" ) + AddFileExtListToFilter( { "pdf" } );
  224. }
  225. wxString PSFileWildcard()
  226. {
  227. return _( "PostScript files" ) + AddFileExtListToFilter( { "ps" } );
  228. }
  229. wxString ReportFileWildcard()
  230. {
  231. return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } );
  232. }
  233. wxString FootprintPlaceFileWildcard()
  234. {
  235. return _( "Footprint place files" ) + AddFileExtListToFilter( { "pos" } );
  236. }
  237. wxString Shapes3DFileWildcard()
  238. {
  239. return _( "VRML and X3D files" ) + AddFileExtListToFilter( { "wrl", "x3d" } );
  240. }
  241. wxString IDF3DFileWildcard()
  242. {
  243. return _( "IDFv3 footprint files" ) + AddFileExtListToFilter( { "idf" } );
  244. }
  245. wxString TextFileWildcard()
  246. {
  247. return _( "Text files" ) + AddFileExtListToFilter( { "txt" } );
  248. }
  249. wxString ModLegacyExportFileWildcard()
  250. {
  251. return _( "Legacy footprint export files" ) + AddFileExtListToFilter( { "emp" } );
  252. }
  253. wxString ErcFileWildcard()
  254. {
  255. return _( "Electronic rule check file" ) + AddFileExtListToFilter( { "erc" } );
  256. }
  257. wxString SpiceLibraryFileWildcard()
  258. {
  259. return _( "Spice library file" ) + AddFileExtListToFilter( { "lib" } );
  260. }
  261. wxString SpiceNetlistFileWildcard()
  262. {
  263. return _( "SPICE netlist file" ) + AddFileExtListToFilter( { "cir" } );
  264. }
  265. wxString CadstarNetlistFileWildcard()
  266. {
  267. return _( "CadStar netlist file" ) + AddFileExtListToFilter( { "frp" } );
  268. }
  269. wxString EquFileWildcard()
  270. {
  271. return _( "Symbol footprint association files" ) + AddFileExtListToFilter( { "equ" } );
  272. }
  273. wxString ZipFileWildcard()
  274. {
  275. return _( "Zip file" ) + AddFileExtListToFilter( { "zip" } );
  276. }
  277. wxString GencadFileWildcard()
  278. {
  279. return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
  280. }
  281. wxString DxfFileWildcard()
  282. {
  283. return _( "DXF Files" ) + AddFileExtListToFilter( { "dxf" } );
  284. }
  285. wxString GerberJobFileWildcard()
  286. {
  287. return _( "Gerber job file" ) + AddFileExtListToFilter( { "gbrjob" } );
  288. }
  289. wxString SpecctraDsnFileWildcard()
  290. {
  291. return _( "Specctra DSN file" ) + AddFileExtListToFilter( { "dsn" } );
  292. }
  293. wxString IpcD356FileWildcard()
  294. {
  295. return _( "IPC-D-356 Test Files" ) + AddFileExtListToFilter( { "d356" } );
  296. }
  297. wxString WorkbookFileWildcard()
  298. {
  299. return _( "Workbook file" ) + AddFileExtListToFilter( { "wbk" } );
  300. }
  301. wxString PngFileWildcard()
  302. {
  303. return _( "PNG file" ) + AddFileExtListToFilter( { "png" } );
  304. }
  305. wxString JpegFileWildcard()
  306. {
  307. return _( "Jpeg file" ) + AddFileExtListToFilter( { "jpg", "jpeg" } );
  308. }