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.

729 lines
23 KiB

12 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_plotViaOnMaskLayer = false;
  85. m_plotMode = FILLED;
  86. m_DXFPolygonMode = true;
  87. m_DXFUnits = DXF_UNITS::INCHES;
  88. m_useAuxOrigin = false;
  89. m_HPGLPenNum = 1;
  90. m_HPGLPenSpeed = 20; // this param is always in cm/s
  91. m_HPGLPenDiam = 15; // in mils
  92. m_negative = false;
  93. m_A4Output = false;
  94. m_plotReference = true;
  95. m_plotValue = true;
  96. m_plotFPText = true;
  97. m_plotInvisibleText = false;
  98. m_sketchPadsOnFabLayers = 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. // This parameter controls if the NPTH pads will be plotted or not
  117. // it is a "local" parameter
  118. m_skipNPTH_Pads = false;
  119. // line width to plot items in outline mode.
  120. m_sketchPadLineWidth = pcbIUScale.mmToIU( 0.1 );
  121. m_default_colors = std::make_shared<COLOR_SETTINGS>();
  122. m_colors = m_default_colors.get();
  123. m_blackAndWhite = true;
  124. }
  125. void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision )
  126. {
  127. // Currently Gerber files use mm.
  128. // accepted precision is only 6 (max value, this is the resolution of Pcbnew)
  129. // or 5, min value for professional boards, when 6 creates problems
  130. // to board makers.
  131. m_gerberPrecision = aPrecision == gbrDefaultPrecision-1 ? gbrDefaultPrecision-1 :
  132. gbrDefaultPrecision;
  133. }
  134. void PCB_PLOT_PARAMS::SetSvgPrecision( unsigned aPrecision )
  135. {
  136. m_svgPrecision = Clamp( SVG_PRECISION_MIN, aPrecision, SVG_PRECISION_MAX );
  137. }
  138. void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
  139. int aNestLevel, int aControl ) const
  140. {
  141. aFormatter->Print( aNestLevel, "(pcbplotparams\n" );
  142. aFormatter->Print( aNestLevel+1, "(layerselection 0x%s)\n",
  143. m_layerSelection.FmtHex().c_str() );
  144. aFormatter->Print( aNestLevel+1, "(plot_on_all_layers_selection 0x%s)\n",
  145. m_plotOnAllLayersSelection.FmtHex().c_str() );
  146. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "disableapertmacros",
  147. m_gerberDisableApertMacros );
  148. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "usegerberextensions",
  149. m_useGerberProtelExtensions );
  150. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "usegerberattributes",
  151. GetUseGerberX2format() );
  152. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "usegerberadvancedattributes",
  153. GetIncludeGerberNetlistInfo() );
  154. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "creategerberjobfile",
  155. GetCreateGerberJobFile() );
  156. // save this option only if it is not the default value,
  157. // to avoid incompatibility with older Pcbnew version
  158. if( m_gerberPrecision != gbrDefaultPrecision )
  159. aFormatter->Print( aNestLevel+1, "(gerberprecision %d)\n", m_gerberPrecision );
  160. aFormatter->Print( aNestLevel+1, "(dashed_line_dash_ratio %f)\n", GetDashedLineDashRatio() );
  161. aFormatter->Print( aNestLevel+1, "(dashed_line_gap_ratio %f)\n", GetDashedLineGapRatio() );
  162. // SVG options
  163. aFormatter->Print( aNestLevel+1, "(svgprecision %d)\n", m_svgPrecision );
  164. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotframeref", m_plotDrawingSheet );
  165. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "viasonmask", m_plotViaOnMaskLayer );
  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. // DXF options
  180. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfpolygonmode ),
  181. m_DXFPolygonMode );
  182. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfimperialunits ),
  183. m_DXFUnits == DXF_UNITS::INCHES );
  184. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfusepcbnewfont ),
  185. m_textMode != PLOT_TEXT_MODE::NATIVE );
  186. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_psnegative ),
  187. m_negative );
  188. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_psa4output ),
  189. m_A4Output );
  190. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotreference", m_plotReference );
  191. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotvalue", m_plotValue );
  192. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotfptext", m_plotFPText );
  193. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "plotinvisibletext",
  194. m_plotInvisibleText );
  195. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "sketchpadsonfab",
  196. m_sketchPadsOnFabLayers );
  197. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "subtractmaskfromsilk",
  198. m_subtractMaskFromSilk );
  199. aFormatter->Print( aNestLevel+1, "(outputformat %d)\n", static_cast<int>( m_format ) );
  200. KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, "mirror", m_mirror );
  201. aFormatter->Print( aNestLevel+1, "(drillshape %d)\n", (int)m_drillMarks );
  202. aFormatter->Print( aNestLevel+1, "(scaleselection %d)\n", m_scaleSelection );
  203. aFormatter->Print( aNestLevel+1, "(outputdirectory \"%s\")",
  204. (const char*) m_outputDirectory.utf8_str() );
  205. aFormatter->Print( 0, "\n" );
  206. aFormatter->Print( aNestLevel, ")\n" );
  207. }
  208. void PCB_PLOT_PARAMS::Parse( PCB_PLOT_PARAMS_PARSER* aParser )
  209. {
  210. aParser->Parse( this );
  211. }
  212. bool PCB_PLOT_PARAMS::IsSameAs( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
  213. {
  214. if( m_layerSelection != aPcbPlotParams.m_layerSelection )
  215. return false;
  216. if( m_plotOnAllLayersSelection != aPcbPlotParams.m_plotOnAllLayersSelection )
  217. return false;
  218. if( m_useGerberProtelExtensions != aPcbPlotParams.m_useGerberProtelExtensions )
  219. return false;
  220. if( m_gerberDisableApertMacros != aPcbPlotParams.m_gerberDisableApertMacros )
  221. return false;
  222. if( m_useGerberX2format != aPcbPlotParams.m_useGerberX2format )
  223. return false;
  224. if( m_includeGerberNetlistInfo != aPcbPlotParams.m_includeGerberNetlistInfo )
  225. return false;
  226. if( m_createGerberJobFile != aPcbPlotParams.m_createGerberJobFile )
  227. return false;
  228. if( m_gerberPrecision != aPcbPlotParams.m_gerberPrecision )
  229. return false;
  230. if( m_dashedLineDashRatio != aPcbPlotParams.m_dashedLineDashRatio )
  231. return false;
  232. if( m_dashedLineGapRatio != aPcbPlotParams.m_dashedLineGapRatio )
  233. return false;
  234. if( m_plotDrawingSheet != aPcbPlotParams.m_plotDrawingSheet )
  235. return false;
  236. if( m_plotViaOnMaskLayer != aPcbPlotParams.m_plotViaOnMaskLayer )
  237. return false;
  238. if( m_plotMode != aPcbPlotParams.m_plotMode )
  239. return false;
  240. if( m_DXFPolygonMode != aPcbPlotParams.m_DXFPolygonMode )
  241. return false;
  242. if( m_DXFUnits != aPcbPlotParams.m_DXFUnits )
  243. return false;
  244. if( m_svgPrecision != aPcbPlotParams.m_svgPrecision )
  245. return false;
  246. if( m_useAuxOrigin != aPcbPlotParams.m_useAuxOrigin )
  247. return false;
  248. if( m_HPGLPenNum != aPcbPlotParams.m_HPGLPenNum )
  249. return false;
  250. if( m_HPGLPenSpeed != aPcbPlotParams.m_HPGLPenSpeed )
  251. return false;
  252. if( m_HPGLPenDiam != aPcbPlotParams.m_HPGLPenDiam )
  253. return false;
  254. if( m_negative != aPcbPlotParams.m_negative )
  255. return false;
  256. if( m_PDFFrontFPPropertyPopups != aPcbPlotParams.m_PDFFrontFPPropertyPopups )
  257. return false;
  258. if( m_PDFBackFPPropertyPopups != aPcbPlotParams.m_PDFBackFPPropertyPopups )
  259. return false;
  260. if( m_A4Output != aPcbPlotParams.m_A4Output )
  261. return false;
  262. if( m_plotReference != aPcbPlotParams.m_plotReference )
  263. return false;
  264. if( m_plotValue != aPcbPlotParams.m_plotValue )
  265. return false;
  266. if( m_plotFPText != aPcbPlotParams.m_plotFPText )
  267. return false;
  268. if( m_plotInvisibleText != aPcbPlotParams.m_plotInvisibleText )
  269. return false;
  270. if( m_sketchPadsOnFabLayers != aPcbPlotParams.m_sketchPadsOnFabLayers )
  271. return false;
  272. if( m_subtractMaskFromSilk != aPcbPlotParams.m_subtractMaskFromSilk )
  273. return false;
  274. if( m_format != aPcbPlotParams.m_format )
  275. return false;
  276. if( m_mirror != aPcbPlotParams.m_mirror )
  277. return false;
  278. if( m_drillMarks != aPcbPlotParams.m_drillMarks )
  279. return false;
  280. if( m_scaleSelection != aPcbPlotParams.m_scaleSelection )
  281. return false;
  282. if( m_autoScale != aPcbPlotParams.m_autoScale )
  283. return false;
  284. if( m_scale != aPcbPlotParams.m_scale )
  285. return false;
  286. if( m_fineScaleAdjustX != aPcbPlotParams.m_fineScaleAdjustX )
  287. return false;
  288. if( m_fineScaleAdjustY != aPcbPlotParams.m_fineScaleAdjustY )
  289. return false;
  290. if( m_widthAdjust != aPcbPlotParams.m_widthAdjust )
  291. return false;
  292. if( m_textMode != aPcbPlotParams.m_textMode )
  293. return false;
  294. if( m_blackAndWhite != aPcbPlotParams.m_blackAndWhite )
  295. return false;
  296. if( !m_outputDirectory.IsSameAs( aPcbPlotParams.m_outputDirectory ) )
  297. return false;
  298. return true;
  299. }
  300. bool PCB_PLOT_PARAMS::SetHPGLPenDiameter( double aValue )
  301. {
  302. return setDouble( &m_HPGLPenDiam, aValue, HPGL_PEN_DIAMETER_MIN, HPGL_PEN_DIAMETER_MAX );
  303. }
  304. bool PCB_PLOT_PARAMS::SetHPGLPenSpeed( int aValue )
  305. {
  306. return setInt( &m_HPGLPenSpeed, aValue, HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
  307. }
  308. PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( LINE_READER* aReader ) :
  309. PCB_PLOT_PARAMS_LEXER( aReader )
  310. {
  311. }
  312. PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( char* aLine, const wxString& aSource ) :
  313. PCB_PLOT_PARAMS_LEXER( aLine, aSource )
  314. {
  315. }
  316. void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
  317. {
  318. T token;
  319. while( ( token = NextTok() ) != T_RIGHT )
  320. {
  321. if( token == T_EOF)
  322. Unexpected( T_EOF );
  323. if( token == T_LEFT )
  324. token = NextTok();
  325. if( token == T_pcbplotparams )
  326. continue;
  327. bool skip_right = false;
  328. switch( token )
  329. {
  330. case T_layerselection:
  331. {
  332. token = NeedSYMBOLorNUMBER();
  333. const std::string& cur = CurStr();
  334. if( token == T_NUMBER ) // pretty 3 format had legacy Cu stack.
  335. {
  336. // It's not possible to convert a legacy Cu layer number to a new Cu layer
  337. // number without knowing the number or total Cu layers in the legacy board.
  338. // We do not have that information here, so simply set all layers ON. User
  339. // can turn them off in the UI.
  340. aPcbPlotParams->m_layerSelection = LSET( 2, F_SilkS, B_SilkS ) | LSET::AllCuMask();
  341. }
  342. else if( cur.find_first_of( "0x" ) == 0 ) // pretty ver. 4.
  343. {
  344. // skip the leading 2 0x bytes.
  345. aPcbPlotParams->m_layerSelection.ParseHex( cur.c_str() + 2, cur.size() - 2 );
  346. }
  347. else
  348. {
  349. Expecting( "integer or hex layerSelection" );
  350. }
  351. break;
  352. }
  353. case T_plot_on_all_layers_selection:
  354. {
  355. token = NeedSYMBOLorNUMBER();
  356. const std::string& cur = CurStr();
  357. if( cur.find_first_of( "0x" ) == 0 )
  358. {
  359. // skip the leading 2 0x bytes.
  360. aPcbPlotParams->m_plotOnAllLayersSelection.ParseHex( cur.c_str() + 2,
  361. cur.size() - 2 );
  362. }
  363. else
  364. {
  365. Expecting( "hex plot_on_all_layers_selection" );
  366. }
  367. break;
  368. }
  369. case T_disableapertmacros:
  370. aPcbPlotParams->m_gerberDisableApertMacros = parseBool();
  371. break;
  372. case T_usegerberextensions:
  373. aPcbPlotParams->m_useGerberProtelExtensions = parseBool();
  374. break;
  375. case T_usegerberattributes:
  376. aPcbPlotParams->m_useGerberX2format = parseBool();
  377. break;
  378. case T_usegerberadvancedattributes:
  379. aPcbPlotParams->m_includeGerberNetlistInfo = parseBool();
  380. break;
  381. case T_creategerberjobfile:
  382. aPcbPlotParams->m_createGerberJobFile = parseBool();
  383. break;
  384. case T_gerberprecision:
  385. aPcbPlotParams->m_gerberPrecision = parseInt( gbrDefaultPrecision - 1,
  386. gbrDefaultPrecision);
  387. break;
  388. case T_dashed_line_dash_ratio:
  389. aPcbPlotParams->m_dashedLineDashRatio = parseDouble();
  390. break;
  391. case T_dashed_line_gap_ratio:
  392. aPcbPlotParams->m_dashedLineGapRatio = parseDouble();
  393. break;
  394. case T_svgprecision:
  395. aPcbPlotParams->m_svgPrecision = parseInt( SVG_PRECISION_MIN, SVG_PRECISION_MAX );
  396. break;
  397. case T_svguseinch:
  398. parseBool(); // Unused. For compatibility
  399. break;
  400. case T_psa4output:
  401. aPcbPlotParams->m_A4Output = parseBool();
  402. break;
  403. case T_excludeedgelayer:
  404. if( !parseBool() )
  405. aPcbPlotParams->m_plotOnAllLayersSelection.set( Edge_Cuts );
  406. break;
  407. case T_plotframeref:
  408. aPcbPlotParams->m_plotDrawingSheet = parseBool();
  409. break;
  410. case T_viasonmask:
  411. aPcbPlotParams->m_plotViaOnMaskLayer = parseBool();
  412. break;
  413. case T_mode:
  414. aPcbPlotParams->SetPlotMode( parseInt( 0, 2 ) > 1 ? SKETCH : FILLED );
  415. break;
  416. case T_useauxorigin:
  417. aPcbPlotParams->m_useAuxOrigin = parseBool();
  418. break;
  419. case T_hpglpennumber:
  420. aPcbPlotParams->m_HPGLPenNum = parseInt( HPGL_PEN_NUMBER_MIN, HPGL_PEN_NUMBER_MAX );
  421. break;
  422. case T_hpglpenspeed:
  423. aPcbPlotParams->m_HPGLPenSpeed = parseInt( HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
  424. break;
  425. case T_hpglpendiameter:
  426. aPcbPlotParams->m_HPGLPenDiam = parseDouble();
  427. break;
  428. case T_hpglpenoverlay:
  429. // No more used. just here for compatibility with old versions
  430. parseInt( 0, HPGL_PEN_DIAMETER_MAX );
  431. break;
  432. case T_pdf_front_fp_property_popups:
  433. aPcbPlotParams->m_PDFFrontFPPropertyPopups = parseBool();
  434. break;
  435. case T_pdf_back_fp_property_popups:
  436. aPcbPlotParams->m_PDFFrontFPPropertyPopups = parseBool();
  437. break;
  438. case T_dxfpolygonmode:
  439. aPcbPlotParams->m_DXFPolygonMode = parseBool();
  440. break;
  441. case T_dxfimperialunits:
  442. aPcbPlotParams->m_DXFUnits = parseBool() ? DXF_UNITS::INCHES
  443. : DXF_UNITS::MILLIMETERS;
  444. break;
  445. case T_dxfusepcbnewfont:
  446. aPcbPlotParams->m_textMode = parseBool() ? PLOT_TEXT_MODE::DEFAULT
  447. : PLOT_TEXT_MODE::NATIVE;
  448. break;
  449. case T_pscolor:
  450. NeedSYMBOL(); // This actually was never used...
  451. break;
  452. case T_psnegative:
  453. aPcbPlotParams->m_negative = parseBool();
  454. break;
  455. case T_plotreference:
  456. aPcbPlotParams->m_plotReference = parseBool();
  457. break;
  458. case T_plotfptext:
  459. aPcbPlotParams->m_plotFPText = parseBool();
  460. break;
  461. case T_plotvalue:
  462. aPcbPlotParams->m_plotValue = parseBool();
  463. break;
  464. case T_plotinvisibletext:
  465. aPcbPlotParams->m_plotInvisibleText = parseBool();
  466. break;
  467. case T_sketchpadsonfab:
  468. aPcbPlotParams->m_sketchPadsOnFabLayers= parseBool();
  469. break;
  470. case T_subtractmaskfromsilk:
  471. aPcbPlotParams->m_subtractMaskFromSilk = parseBool();
  472. break;
  473. case T_outputformat:
  474. aPcbPlotParams->m_format = static_cast<PLOT_FORMAT>(
  475. parseInt( static_cast<int>( PLOT_FORMAT::FIRST_FORMAT ),
  476. static_cast<int>( PLOT_FORMAT::LAST_FORMAT ) ) );
  477. break;
  478. case T_mirror:
  479. aPcbPlotParams->m_mirror = parseBool();
  480. break;
  481. case T_drillshape:
  482. aPcbPlotParams->m_drillMarks = static_cast<DRILL_MARKS> ( parseInt( 0, 2 ) );
  483. break;
  484. case T_scaleselection:
  485. aPcbPlotParams->m_scaleSelection = parseInt( 0, 4 );
  486. break;
  487. case T_outputdirectory:
  488. NeedSYMBOLorNUMBER(); // a dir name can be like a number
  489. aPcbPlotParams->m_outputDirectory = From_UTF8( CurText() );
  490. break;
  491. default:
  492. skipCurrent(); // skip unknown or outdated plot parameter
  493. skip_right = true; // the closing right token is already read.
  494. break;
  495. }
  496. if( ! skip_right )
  497. NeedRIGHT();
  498. }
  499. }
  500. bool PCB_PLOT_PARAMS_PARSER::parseBool()
  501. {
  502. T token = NeedSYMBOL();
  503. switch( token )
  504. {
  505. case T_false:
  506. case T_no:
  507. return false;
  508. case T_true:
  509. case T_yes:
  510. return true;
  511. default:
  512. Expecting( "true, false, yes, or no" );
  513. return false;
  514. }
  515. }
  516. int PCB_PLOT_PARAMS_PARSER::parseInt( int aMin, int aMax )
  517. {
  518. T token = NextTok();
  519. if( token != T_NUMBER )
  520. Expecting( T_NUMBER );
  521. int val = atoi( CurText() );
  522. if( val < aMin )
  523. val = aMin;
  524. else if( val > aMax )
  525. val = aMax;
  526. return val;
  527. }
  528. double PCB_PLOT_PARAMS_PARSER::parseDouble()
  529. {
  530. T token = NextTok();
  531. if( token != T_NUMBER )
  532. Expecting( T_NUMBER );
  533. return DSNLEXER::parseDouble();
  534. }
  535. void PCB_PLOT_PARAMS_PARSER::skipCurrent()
  536. {
  537. int curr_level = 0;
  538. T token;
  539. while( ( token = NextTok() ) != T_EOF )
  540. {
  541. if( token == T_LEFT )
  542. curr_level--;
  543. if( token == T_RIGHT )
  544. {
  545. curr_level++;
  546. if( curr_level > 0 )
  547. return;
  548. }
  549. }
  550. }