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.

741 lines
23 KiB

11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <board_design_settings.h>
  24. #include <charconv>
  25. #include <layer_ids.h>
  26. #include <string_utils.h>
  27. #include <math/util.h> // for KiROUND
  28. #include <pcb_plot_params.h>
  29. #include <pcb_plot_params_parser.h>
  30. #include <plotters/plotter.h>
  31. #include <io/kicad/kicad_io_utils.h>
  32. #include <settings/color_settings.h>
  33. #define PLOT_LINEWIDTH_DEFAULT ( DEFAULT_TEXT_WIDTH * IU_PER_MM )
  34. #define HPGL_PEN_DIAMETER_MIN 0
  35. #define HPGL_PEN_DIAMETER_MAX 100.0 // Unit = mil
  36. #define HPGL_PEN_SPEED_MIN 1 // this param is always in cm/s
  37. #define HPGL_PEN_SPEED_MAX 99 // this param is always in cm/s
  38. #define HPGL_PEN_NUMBER_MIN 1
  39. #define HPGL_PEN_NUMBER_MAX 16
  40. #define SVG_PRECISION_MIN 3U
  41. #define SVG_PRECISION_MAX 6U
  42. #define SVG_PRECISION_DEFAULT 4
  43. // default trailing digits in Gerber coordinates, when units are mm
  44. // This is also the max usable precision (i.e. internal Pcbnew Units)
  45. static const int gbrDefaultPrecision = 6;
  46. using namespace PCBPLOTPARAMS_T;
  47. static const char* getTokenName( T aTok )
  48. {
  49. return PCB_PLOT_PARAMS_LEXER::TokenName( aTok );
  50. }
  51. static bool setInt( int* aTarget, int aValue, int aMin, int aMax )
  52. {
  53. int temp = aValue;
  54. if( aValue < aMin )
  55. temp = aMin;
  56. else if( aValue > aMax )
  57. temp = aMax;
  58. *aTarget = temp;
  59. return ( temp == aValue );
  60. }
  61. static bool setDouble( double* aTarget, double aValue, double aMin, double aMax )
  62. {
  63. double temp = aValue;
  64. if( aValue < aMin )
  65. temp = aMin;
  66. else if( aValue > aMax )
  67. temp = aMax;
  68. *aTarget = temp;
  69. return ( temp == aValue );
  70. }
  71. PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
  72. {
  73. m_useGerberProtelExtensions = false;
  74. m_gerberDisableApertMacros = false;
  75. m_useGerberX2format = true;
  76. m_includeGerberNetlistInfo = true;
  77. m_createGerberJobFile = true;
  78. m_gerberPrecision = gbrDefaultPrecision;
  79. m_dashedLineDashRatio = 12.0; // From ISO 128-2
  80. m_dashedLineGapRatio = 3.0; // From ISO 128-2
  81. // we used 0.1mils for SVG step before, but nm precision is more accurate, so we use nm
  82. m_svgPrecision = SVG_PRECISION_DEFAULT;
  83. m_plotDrawingSheet = false;
  84. m_plotMode = FILLED;
  85. m_DXFPolygonMode = true;
  86. m_DXFUnits = DXF_UNITS::INCHES;
  87. m_useAuxOrigin = false;
  88. m_HPGLPenNum = 1;
  89. m_HPGLPenSpeed = 20; // this param is always in cm/s
  90. m_HPGLPenDiam = 15; // in mils
  91. m_negative = false;
  92. m_A4Output = false;
  93. m_plotReference = true;
  94. m_plotValue = true;
  95. m_plotFPText = true;
  96. m_plotInvisibleText = false;
  97. m_sketchPadsOnFabLayers = false;
  98. m_plotPadNumbers = false;
  99. m_subtractMaskFromSilk = false;
  100. m_format = PLOT_FORMAT::GERBER;
  101. m_mirror = false;
  102. m_drillMarks = DRILL_MARKS::SMALL_DRILL_SHAPE;
  103. m_autoScale = false;
  104. m_scale = 1.0;
  105. m_scaleSelection = 1;
  106. m_fineScaleAdjustX = 1.0;
  107. m_fineScaleAdjustY = 1.0;
  108. m_widthAdjust = 0.;
  109. m_textMode = PLOT_TEXT_MODE::DEFAULT;
  110. m_outputDirectory.clear();
  111. m_layerSelection = LSET( 7, F_SilkS, B_SilkS, F_Mask, B_Mask,
  112. F_Paste, B_Paste, Edge_Cuts )
  113. | LSET::AllCuMask();
  114. m_PDFFrontFPPropertyPopups = true;
  115. m_PDFBackFPPropertyPopups = true;
  116. m_PDFMetadata = true;
  117. // This parameter controls if the NPTH pads will be plotted or not
  118. // it is a "local" parameter
  119. m_skipNPTH_Pads = false;
  120. // line width to plot items in outline mode.
  121. m_sketchPadLineWidth = pcbIUScale.mmToIU( 0.1 );
  122. m_default_colors = std::make_shared<COLOR_SETTINGS>();
  123. m_colors = m_default_colors.get();
  124. m_blackAndWhite = true;
  125. }
  126. void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision )
  127. {
  128. // Currently Gerber files use mm.
  129. // accepted precision is only 6 (max value, this is the resolution of Pcbnew)
  130. // or 5, min value for professional boards, when 6 creates problems
  131. // to board makers.
  132. m_gerberPrecision = aPrecision == gbrDefaultPrecision-1 ? gbrDefaultPrecision-1 :
  133. gbrDefaultPrecision;
  134. }
  135. void PCB_PLOT_PARAMS::SetSvgPrecision( unsigned aPrecision )
  136. {
  137. m_svgPrecision = Clamp( SVG_PRECISION_MIN, aPrecision, SVG_PRECISION_MAX );
  138. }
  139. void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
  140. int aNestLevel, int aControl ) const
  141. {
  142. aFormatter->Print( aNestLevel, "(pcbplotparams\n" );
  143. aFormatter->Print( aNestLevel+1, "(layerselection 0x%s)\n",
  144. m_layerSelection.FmtHex().c_str() );
  145. aFormatter->Print( aNestLevel+1, "(plot_on_all_layers_selection 0x%s)\n",
  146. m_plotOnAllLayersSelection.FmtHex().c_str() );
  147. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "disableapertmacros",
  148. m_gerberDisableApertMacros );
  149. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "usegerberextensions",
  150. m_useGerberProtelExtensions );
  151. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "usegerberattributes",
  152. GetUseGerberX2format() );
  153. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "usegerberadvancedattributes",
  154. GetIncludeGerberNetlistInfo() );
  155. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "creategerberjobfile",
  156. GetCreateGerberJobFile() );
  157. // save this option only if it is not the default value,
  158. // to avoid incompatibility with older Pcbnew version
  159. if( m_gerberPrecision != gbrDefaultPrecision )
  160. aFormatter->Print( aNestLevel+1, "(gerberprecision %d)\n", m_gerberPrecision );
  161. aFormatter->Print( aNestLevel+1, "(dashed_line_dash_ratio %f)\n", GetDashedLineDashRatio() );
  162. aFormatter->Print( aNestLevel+1, "(dashed_line_gap_ratio %f)\n", GetDashedLineGapRatio() );
  163. // SVG options
  164. aFormatter->Print( aNestLevel+1, "(svgprecision %d)\n", m_svgPrecision );
  165. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotframeref", m_plotDrawingSheet );
  166. aFormatter->Print( aNestLevel+1, "(mode %d)\n", GetPlotMode() == SKETCH ? 2 : 1 );
  167. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "useauxorigin", m_useAuxOrigin );
  168. // HPGL options
  169. aFormatter->Print( aNestLevel+1, "(hpglpennumber %d)\n", m_HPGLPenNum );
  170. aFormatter->Print( aNestLevel+1, "(hpglpenspeed %d)\n", m_HPGLPenSpeed );
  171. aFormatter->Print( aNestLevel+1, "(hpglpendiameter %f)\n", m_HPGLPenDiam );
  172. // PDF options
  173. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1,
  174. getTokenName( T_pdf_front_fp_property_popups ),
  175. m_PDFFrontFPPropertyPopups );
  176. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1,
  177. getTokenName( T_pdf_back_fp_property_popups ),
  178. m_PDFBackFPPropertyPopups );
  179. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1,
  180. getTokenName( T_pdf_metadata ),
  181. m_PDFMetadata );
  182. // DXF options
  183. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfpolygonmode ),
  184. m_DXFPolygonMode );
  185. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfimperialunits ),
  186. m_DXFUnits == DXF_UNITS::INCHES );
  187. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfusepcbnewfont ),
  188. m_textMode != PLOT_TEXT_MODE::NATIVE );
  189. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_psnegative ),
  190. m_negative );
  191. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_psa4output ),
  192. m_A4Output );
  193. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotreference", m_plotReference );
  194. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotvalue", m_plotValue );
  195. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotfptext", m_plotFPText );
  196. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotinvisibletext", m_plotInvisibleText );
  197. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "sketchpadsonfab", m_sketchPadsOnFabLayers );
  198. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotpadnumbers", m_plotPadNumbers );
  199. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "subtractmaskfromsilk", m_subtractMaskFromSilk );
  200. aFormatter->Print( aNestLevel+1, "(outputformat %d)\n", static_cast<int>( m_format ) );
  201. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "mirror", m_mirror );
  202. aFormatter->Print( aNestLevel+1, "(drillshape %d)\n", (int)m_drillMarks );
  203. aFormatter->Print( aNestLevel+1, "(scaleselection %d)\n", m_scaleSelection );
  204. aFormatter->Print( aNestLevel+1, "(outputdirectory \"%s\")",
  205. (const char*) m_outputDirectory.utf8_str() );
  206. aFormatter->Print( 0, "\n" );
  207. aFormatter->Print( aNestLevel, ")\n" );
  208. }
  209. void PCB_PLOT_PARAMS::Parse( PCB_PLOT_PARAMS_PARSER* aParser )
  210. {
  211. aParser->Parse( this );
  212. }
  213. bool PCB_PLOT_PARAMS::IsSameAs( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
  214. {
  215. if( m_layerSelection != aPcbPlotParams.m_layerSelection )
  216. return false;
  217. if( m_plotOnAllLayersSelection != aPcbPlotParams.m_plotOnAllLayersSelection )
  218. return false;
  219. if( m_useGerberProtelExtensions != aPcbPlotParams.m_useGerberProtelExtensions )
  220. return false;
  221. if( m_gerberDisableApertMacros != aPcbPlotParams.m_gerberDisableApertMacros )
  222. return false;
  223. if( m_useGerberX2format != aPcbPlotParams.m_useGerberX2format )
  224. return false;
  225. if( m_includeGerberNetlistInfo != aPcbPlotParams.m_includeGerberNetlistInfo )
  226. return false;
  227. if( m_createGerberJobFile != aPcbPlotParams.m_createGerberJobFile )
  228. return false;
  229. if( m_gerberPrecision != aPcbPlotParams.m_gerberPrecision )
  230. return false;
  231. if( m_dashedLineDashRatio != aPcbPlotParams.m_dashedLineDashRatio )
  232. return false;
  233. if( m_dashedLineGapRatio != aPcbPlotParams.m_dashedLineGapRatio )
  234. return false;
  235. if( m_plotDrawingSheet != aPcbPlotParams.m_plotDrawingSheet )
  236. return false;
  237. if( m_plotMode != aPcbPlotParams.m_plotMode )
  238. return false;
  239. if( m_DXFPolygonMode != aPcbPlotParams.m_DXFPolygonMode )
  240. return false;
  241. if( m_DXFUnits != aPcbPlotParams.m_DXFUnits )
  242. return false;
  243. if( m_svgPrecision != aPcbPlotParams.m_svgPrecision )
  244. return false;
  245. if( m_useAuxOrigin != aPcbPlotParams.m_useAuxOrigin )
  246. return false;
  247. if( m_HPGLPenNum != aPcbPlotParams.m_HPGLPenNum )
  248. return false;
  249. if( m_HPGLPenSpeed != aPcbPlotParams.m_HPGLPenSpeed )
  250. return false;
  251. if( m_HPGLPenDiam != aPcbPlotParams.m_HPGLPenDiam )
  252. return false;
  253. if( m_negative != aPcbPlotParams.m_negative )
  254. return false;
  255. if( m_PDFFrontFPPropertyPopups != aPcbPlotParams.m_PDFFrontFPPropertyPopups )
  256. return false;
  257. if( m_PDFBackFPPropertyPopups != aPcbPlotParams.m_PDFBackFPPropertyPopups )
  258. return false;
  259. if( m_PDFMetadata != aPcbPlotParams.m_PDFMetadata )
  260. return false;
  261. if( m_A4Output != aPcbPlotParams.m_A4Output )
  262. return false;
  263. if( m_plotReference != aPcbPlotParams.m_plotReference )
  264. return false;
  265. if( m_plotValue != aPcbPlotParams.m_plotValue )
  266. return false;
  267. if( m_plotFPText != aPcbPlotParams.m_plotFPText )
  268. return false;
  269. if( m_plotInvisibleText != aPcbPlotParams.m_plotInvisibleText )
  270. return false;
  271. if( m_sketchPadsOnFabLayers != aPcbPlotParams.m_sketchPadsOnFabLayers )
  272. return false;
  273. if( m_plotPadNumbers != aPcbPlotParams.m_plotPadNumbers )
  274. return false;
  275. if( m_subtractMaskFromSilk != aPcbPlotParams.m_subtractMaskFromSilk )
  276. return false;
  277. if( m_format != aPcbPlotParams.m_format )
  278. return false;
  279. if( m_mirror != aPcbPlotParams.m_mirror )
  280. return false;
  281. if( m_drillMarks != aPcbPlotParams.m_drillMarks )
  282. return false;
  283. if( m_scaleSelection != aPcbPlotParams.m_scaleSelection )
  284. return false;
  285. if( m_autoScale != aPcbPlotParams.m_autoScale )
  286. return false;
  287. if( m_scale != aPcbPlotParams.m_scale )
  288. return false;
  289. if( m_fineScaleAdjustX != aPcbPlotParams.m_fineScaleAdjustX )
  290. return false;
  291. if( m_fineScaleAdjustY != aPcbPlotParams.m_fineScaleAdjustY )
  292. return false;
  293. if( m_widthAdjust != aPcbPlotParams.m_widthAdjust )
  294. return false;
  295. if( m_textMode != aPcbPlotParams.m_textMode )
  296. return false;
  297. if( m_blackAndWhite != aPcbPlotParams.m_blackAndWhite )
  298. return false;
  299. if( !m_outputDirectory.IsSameAs( aPcbPlotParams.m_outputDirectory ) )
  300. return false;
  301. return true;
  302. }
  303. bool PCB_PLOT_PARAMS::SetHPGLPenDiameter( double aValue )
  304. {
  305. return setDouble( &m_HPGLPenDiam, aValue, HPGL_PEN_DIAMETER_MIN, HPGL_PEN_DIAMETER_MAX );
  306. }
  307. bool PCB_PLOT_PARAMS::SetHPGLPenSpeed( int aValue )
  308. {
  309. return setInt( &m_HPGLPenSpeed, aValue, HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
  310. }
  311. PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( LINE_READER* aReader ) :
  312. PCB_PLOT_PARAMS_LEXER( aReader )
  313. {
  314. }
  315. PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( char* aLine, const wxString& aSource ) :
  316. PCB_PLOT_PARAMS_LEXER( aLine, aSource )
  317. {
  318. }
  319. void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
  320. {
  321. T token;
  322. while( ( token = NextTok() ) != T_RIGHT )
  323. {
  324. if( token == T_EOF)
  325. Unexpected( T_EOF );
  326. if( token == T_LEFT )
  327. token = NextTok();
  328. if( token == T_pcbplotparams )
  329. continue;
  330. bool skip_right = false;
  331. switch( token )
  332. {
  333. case T_layerselection:
  334. {
  335. token = NeedSYMBOLorNUMBER();
  336. const std::string& cur = CurStr();
  337. if( token == T_NUMBER ) // pretty 3 format had legacy Cu stack.
  338. {
  339. // It's not possible to convert a legacy Cu layer number to a new Cu layer
  340. // number without knowing the number or total Cu layers in the legacy board.
  341. // We do not have that information here, so simply set all layers ON. User
  342. // can turn them off in the UI.
  343. aPcbPlotParams->m_layerSelection = LSET( 2, F_SilkS, B_SilkS ) | LSET::AllCuMask();
  344. }
  345. else if( cur.find_first_of( "0x" ) == 0 ) // pretty ver. 4.
  346. {
  347. // skip the leading 2 0x bytes.
  348. aPcbPlotParams->m_layerSelection.ParseHex( cur.c_str() + 2, cur.size() - 2 );
  349. }
  350. else
  351. {
  352. Expecting( "integer or hex layerSelection" );
  353. }
  354. break;
  355. }
  356. case T_plot_on_all_layers_selection:
  357. {
  358. token = NeedSYMBOLorNUMBER();
  359. const std::string& cur = CurStr();
  360. if( cur.find_first_of( "0x" ) == 0 )
  361. {
  362. // skip the leading 2 0x bytes.
  363. aPcbPlotParams->m_plotOnAllLayersSelection.ParseHex( cur.c_str() + 2,
  364. cur.size() - 2 );
  365. }
  366. else
  367. {
  368. Expecting( "hex plot_on_all_layers_selection" );
  369. }
  370. break;
  371. }
  372. case T_disableapertmacros:
  373. aPcbPlotParams->m_gerberDisableApertMacros = parseBool();
  374. break;
  375. case T_usegerberextensions:
  376. aPcbPlotParams->m_useGerberProtelExtensions = parseBool();
  377. break;
  378. case T_usegerberattributes:
  379. aPcbPlotParams->m_useGerberX2format = parseBool();
  380. break;
  381. case T_usegerberadvancedattributes:
  382. aPcbPlotParams->m_includeGerberNetlistInfo = parseBool();
  383. break;
  384. case T_creategerberjobfile:
  385. aPcbPlotParams->m_createGerberJobFile = parseBool();
  386. break;
  387. case T_gerberprecision:
  388. aPcbPlotParams->m_gerberPrecision = parseInt( gbrDefaultPrecision - 1,
  389. gbrDefaultPrecision);
  390. break;
  391. case T_dashed_line_dash_ratio:
  392. aPcbPlotParams->m_dashedLineDashRatio = parseDouble();
  393. break;
  394. case T_dashed_line_gap_ratio:
  395. aPcbPlotParams->m_dashedLineGapRatio = parseDouble();
  396. break;
  397. case T_svgprecision:
  398. aPcbPlotParams->m_svgPrecision = parseInt( SVG_PRECISION_MIN, SVG_PRECISION_MAX );
  399. break;
  400. case T_svguseinch:
  401. parseBool(); // Unused. For compatibility
  402. break;
  403. case T_psa4output:
  404. aPcbPlotParams->m_A4Output = parseBool();
  405. break;
  406. case T_excludeedgelayer:
  407. if( !parseBool() )
  408. aPcbPlotParams->m_plotOnAllLayersSelection.set( Edge_Cuts );
  409. break;
  410. case T_plotframeref:
  411. aPcbPlotParams->m_plotDrawingSheet = parseBool();
  412. break;
  413. case T_viasonmask:
  414. aPcbPlotParams->m_plotViaOnMaskLayer = parseBool();
  415. break;
  416. case T_mode:
  417. aPcbPlotParams->SetPlotMode( parseInt( 0, 2 ) > 1 ? SKETCH : FILLED );
  418. break;
  419. case T_useauxorigin:
  420. aPcbPlotParams->m_useAuxOrigin = parseBool();
  421. break;
  422. case T_hpglpennumber:
  423. aPcbPlotParams->m_HPGLPenNum = parseInt( HPGL_PEN_NUMBER_MIN, HPGL_PEN_NUMBER_MAX );
  424. break;
  425. case T_hpglpenspeed:
  426. aPcbPlotParams->m_HPGLPenSpeed = parseInt( HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
  427. break;
  428. case T_hpglpendiameter:
  429. aPcbPlotParams->m_HPGLPenDiam = parseDouble();
  430. break;
  431. case T_hpglpenoverlay:
  432. // No more used. just here for compatibility with old versions
  433. parseInt( 0, HPGL_PEN_DIAMETER_MAX );
  434. break;
  435. case T_pdf_front_fp_property_popups:
  436. aPcbPlotParams->m_PDFFrontFPPropertyPopups = parseBool();
  437. break;
  438. case T_pdf_back_fp_property_popups:
  439. aPcbPlotParams->m_PDFFrontFPPropertyPopups = parseBool();
  440. break;
  441. case T_pdf_metadata:
  442. aPcbPlotParams->m_PDFMetadata = parseBool();
  443. break;
  444. case T_dxfpolygonmode:
  445. aPcbPlotParams->m_DXFPolygonMode = parseBool();
  446. break;
  447. case T_dxfimperialunits:
  448. aPcbPlotParams->m_DXFUnits = parseBool() ? DXF_UNITS::INCHES
  449. : DXF_UNITS::MILLIMETERS;
  450. break;
  451. case T_dxfusepcbnewfont:
  452. aPcbPlotParams->m_textMode = parseBool() ? PLOT_TEXT_MODE::DEFAULT
  453. : PLOT_TEXT_MODE::NATIVE;
  454. break;
  455. case T_pscolor:
  456. NeedSYMBOL(); // This actually was never used...
  457. break;
  458. case T_psnegative:
  459. aPcbPlotParams->m_negative = parseBool();
  460. break;
  461. case T_plotreference:
  462. aPcbPlotParams->m_plotReference = parseBool();
  463. break;
  464. case T_plotfptext:
  465. aPcbPlotParams->m_plotFPText = parseBool();
  466. break;
  467. case T_plotvalue:
  468. aPcbPlotParams->m_plotValue = parseBool();
  469. break;
  470. case T_plotinvisibletext:
  471. aPcbPlotParams->m_plotInvisibleText = parseBool();
  472. break;
  473. case T_sketchpadsonfab:
  474. aPcbPlotParams->m_sketchPadsOnFabLayers= parseBool();
  475. break;
  476. case T_plotpadnumbers:
  477. aPcbPlotParams->m_plotPadNumbers = parseBool();
  478. break;
  479. case T_subtractmaskfromsilk:
  480. aPcbPlotParams->m_subtractMaskFromSilk = parseBool();
  481. break;
  482. case T_outputformat:
  483. aPcbPlotParams->m_format = static_cast<PLOT_FORMAT>(
  484. parseInt( static_cast<int>( PLOT_FORMAT::FIRST_FORMAT ),
  485. static_cast<int>( PLOT_FORMAT::LAST_FORMAT ) ) );
  486. break;
  487. case T_mirror:
  488. aPcbPlotParams->m_mirror = parseBool();
  489. break;
  490. case T_drillshape:
  491. aPcbPlotParams->m_drillMarks = static_cast<DRILL_MARKS> ( parseInt( 0, 2 ) );
  492. break;
  493. case T_scaleselection:
  494. aPcbPlotParams->m_scaleSelection = parseInt( 0, 4 );
  495. break;
  496. case T_outputdirectory:
  497. NeedSYMBOLorNUMBER(); // a dir name can be like a number
  498. aPcbPlotParams->m_outputDirectory = From_UTF8( CurText() );
  499. break;
  500. default:
  501. skipCurrent(); // skip unknown or outdated plot parameter
  502. skip_right = true; // the closing right token is already read.
  503. break;
  504. }
  505. if( ! skip_right )
  506. NeedRIGHT();
  507. }
  508. }
  509. bool PCB_PLOT_PARAMS_PARSER::parseBool()
  510. {
  511. T token = NeedSYMBOL();
  512. switch( token )
  513. {
  514. case T_false:
  515. case T_no:
  516. return false;
  517. case T_true:
  518. case T_yes:
  519. return true;
  520. default:
  521. Expecting( "true, false, yes, or no" );
  522. return false;
  523. }
  524. }
  525. int PCB_PLOT_PARAMS_PARSER::parseInt( int aMin, int aMax )
  526. {
  527. T token = NextTok();
  528. if( token != T_NUMBER )
  529. Expecting( T_NUMBER );
  530. int val = atoi( CurText() );
  531. if( val < aMin )
  532. val = aMin;
  533. else if( val > aMax )
  534. val = aMax;
  535. return val;
  536. }
  537. double PCB_PLOT_PARAMS_PARSER::parseDouble()
  538. {
  539. T token = NextTok();
  540. if( token != T_NUMBER )
  541. Expecting( T_NUMBER );
  542. return DSNLEXER::parseDouble();
  543. }
  544. void PCB_PLOT_PARAMS_PARSER::skipCurrent()
  545. {
  546. int curr_level = 0;
  547. T token;
  548. while( ( token = NextTok() ) != T_EOF )
  549. {
  550. if( token == T_LEFT )
  551. curr_level--;
  552. if( token == T_RIGHT )
  553. {
  554. curr_level++;
  555. if( curr_level > 0 )
  556. return;
  557. }
  558. }
  559. }