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.

684 lines
21 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 <macros.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 <settings/color_settings.h>
  32. #define PLOT_LINEWIDTH_DEFAULT ( DEFAULT_TEXT_WIDTH * IU_PER_MM )
  33. #define HPGL_PEN_DIAMETER_MIN 0
  34. #define HPGL_PEN_DIAMETER_MAX 100.0 // Unit = mil
  35. #define HPGL_PEN_SPEED_MIN 1 // this param is always in cm/s
  36. #define HPGL_PEN_SPEED_MAX 99 // this param is always in cm/s
  37. #define HPGL_PEN_NUMBER_MIN 1
  38. #define HPGL_PEN_NUMBER_MAX 16
  39. #define SVG_PRECISION_MIN 3U
  40. #define SVG_PRECISION_MAX 6U
  41. #define SVG_PRECISION_DEFAULT 4
  42. // default trailing digits in Gerber coordinates, when units are mm
  43. // This is also the max usable precision (i.e. internal Pcbnew Units)
  44. static const int gbrDefaultPrecision = 6;
  45. using namespace PCBPLOTPARAMS_T;
  46. static const char* getTokenName( T aTok )
  47. {
  48. return PCB_PLOT_PARAMS_LEXER::TokenName( aTok );
  49. }
  50. static bool setInt( int* aTarget, int aValue, int aMin, int aMax )
  51. {
  52. int temp = aValue;
  53. if( aValue < aMin )
  54. temp = aMin;
  55. else if( aValue > aMax )
  56. temp = aMax;
  57. *aTarget = temp;
  58. return ( temp == aValue );
  59. }
  60. static bool setDouble( double* aTarget, double aValue, double aMin, double aMax )
  61. {
  62. double temp = aValue;
  63. if( aValue < aMin )
  64. temp = aMin;
  65. else if( aValue > aMax )
  66. temp = aMax;
  67. *aTarget = temp;
  68. return ( temp == aValue );
  69. }
  70. PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
  71. {
  72. m_useGerberProtelExtensions = false;
  73. m_gerberDisableApertMacros = false;
  74. m_useGerberX2format = true;
  75. m_includeGerberNetlistInfo = true;
  76. m_createGerberJobFile = true;
  77. m_gerberPrecision = gbrDefaultPrecision;
  78. m_dashedLineDashRatio = 12.0; // From ISO 128-2
  79. m_dashedLineGapRatio = 3.0; // From ISO 128-2
  80. // we used 0.1mils for SVG step before, but nm precision is more accurate, so we use nm
  81. m_svgPrecision = SVG_PRECISION_DEFAULT;
  82. m_plotFrameRef = false;
  83. m_plotViaOnMaskLayer = false;
  84. m_plotMode = FILLED;
  85. m_DXFplotPolygonMode = true;
  86. m_DXFplotUnits = 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_plotInvisibleText = false;
  96. m_sketchPadsOnFabLayers = false;
  97. m_subtractMaskFromSilk = false;
  98. m_format = PLOT_FORMAT::GERBER;
  99. m_mirror = false;
  100. m_drillMarks = SMALL_DRILL_SHAPE;
  101. m_autoScale = false;
  102. m_scale = 1.0;
  103. m_scaleSelection = 1;
  104. m_fineScaleAdjustX = 1.0;
  105. m_fineScaleAdjustY = 1.0;
  106. m_widthAdjust = 0.;
  107. m_textMode = PLOT_TEXT_MODE::DEFAULT;
  108. m_outputDirectory.clear();
  109. m_layerSelection = LSET( 7, F_SilkS, B_SilkS, F_Mask, B_Mask,
  110. F_Paste, B_Paste, Edge_Cuts )
  111. | LSET::AllCuMask();
  112. // This parameter controls if the NPTH pads will be plotted or not
  113. // it is a "local" parameter
  114. m_skipNPTH_Pads = false;
  115. // line width to plot items in outline mode.
  116. m_sketchPadLineWidth = pcbIUScale.mmToIU( 0.1 );
  117. m_default_colors = std::make_shared<COLOR_SETTINGS>();
  118. m_colors = m_default_colors.get();
  119. }
  120. void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision )
  121. {
  122. // Currently Gerber files use mm.
  123. // accepted precision is only 6 (max value, this is the resolution of Pcbnew)
  124. // or 5, min value for professional boards, when 6 creates problems
  125. // to board makers.
  126. m_gerberPrecision = aPrecision == gbrDefaultPrecision-1 ? gbrDefaultPrecision-1 :
  127. gbrDefaultPrecision;
  128. }
  129. void PCB_PLOT_PARAMS::SetSvgPrecision( unsigned aPrecision )
  130. {
  131. m_svgPrecision = Clamp( SVG_PRECISION_MIN, aPrecision, SVG_PRECISION_MAX );
  132. }
  133. void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
  134. int aNestLevel, int aControl ) const
  135. {
  136. auto printBool =
  137. []( bool aBool ) -> const char*
  138. {
  139. return aBool ? "true" : "false";
  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. aFormatter->Print( aNestLevel+1, "(disableapertmacros %s)\n",
  147. printBool( m_gerberDisableApertMacros ) );
  148. aFormatter->Print( aNestLevel+1, "(usegerberextensions %s)\n",
  149. printBool( m_useGerberProtelExtensions) );
  150. aFormatter->Print( aNestLevel+1, "(usegerberattributes %s)\n",
  151. printBool( GetUseGerberX2format()) );
  152. aFormatter->Print( aNestLevel+1, "(usegerberadvancedattributes %s)\n",
  153. printBool( GetIncludeGerberNetlistInfo()) );
  154. aFormatter->Print( aNestLevel+1, "(creategerberjobfile %s)\n",
  155. printBool( 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. aFormatter->Print( aNestLevel+1, "(plotframeref %s)\n", printBool( m_plotFrameRef ) );
  165. aFormatter->Print( aNestLevel+1, "(viasonmask %s)\n", printBool( m_plotViaOnMaskLayer ) );
  166. aFormatter->Print( aNestLevel+1, "(mode %d)\n", GetPlotMode() == SKETCH ? 2 : 1 );
  167. aFormatter->Print( aNestLevel+1, "(useauxorigin %s)\n", printBool( 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. // DXF options
  173. aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_dxfpolygonmode ),
  174. printBool( m_DXFplotPolygonMode ) );
  175. aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_dxfimperialunits ),
  176. printBool( m_DXFplotUnits == DXF_UNITS::INCHES ) );
  177. aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_dxfusepcbnewfont ),
  178. printBool( m_textMode != PLOT_TEXT_MODE::NATIVE ) );
  179. aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_psnegative ),
  180. printBool( m_negative ) );
  181. aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_psa4output ),
  182. printBool( m_A4Output ) );
  183. aFormatter->Print( aNestLevel+1, "(plotreference %s)\n", printBool( m_plotReference ) );
  184. aFormatter->Print( aNestLevel+1, "(plotvalue %s)\n", printBool( m_plotValue ) );
  185. aFormatter->Print( aNestLevel+1, "(plotinvisibletext %s)\n", printBool( m_plotInvisibleText ) );
  186. aFormatter->Print( aNestLevel+1, "(sketchpadsonfab %s)\n",
  187. printBool( m_sketchPadsOnFabLayers ) );
  188. aFormatter->Print( aNestLevel+1, "(subtractmaskfromsilk %s)\n",
  189. printBool( m_subtractMaskFromSilk ) );
  190. aFormatter->Print( aNestLevel+1, "(outputformat %d)\n", static_cast<int>( m_format ) );
  191. aFormatter->Print( aNestLevel+1, "(mirror %s)\n", printBool( m_mirror ) );
  192. aFormatter->Print( aNestLevel+1, "(drillshape %d)\n", m_drillMarks );
  193. aFormatter->Print( aNestLevel+1, "(scaleselection %d)\n", m_scaleSelection );
  194. aFormatter->Print( aNestLevel+1, "(outputdirectory \"%s\")",
  195. (const char*) m_outputDirectory.utf8_str() );
  196. aFormatter->Print( 0, "\n" );
  197. aFormatter->Print( aNestLevel, ")\n" );
  198. }
  199. void PCB_PLOT_PARAMS::Parse( PCB_PLOT_PARAMS_PARSER* aParser )
  200. {
  201. aParser->Parse( this );
  202. }
  203. bool PCB_PLOT_PARAMS::IsSameAs( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
  204. {
  205. if( m_layerSelection != aPcbPlotParams.m_layerSelection )
  206. return false;
  207. if( m_plotOnAllLayersSelection != aPcbPlotParams.m_plotOnAllLayersSelection )
  208. return false;
  209. if( m_useGerberProtelExtensions != aPcbPlotParams.m_useGerberProtelExtensions )
  210. return false;
  211. if( m_gerberDisableApertMacros != aPcbPlotParams.m_gerberDisableApertMacros )
  212. return false;
  213. if( m_useGerberX2format != aPcbPlotParams.m_useGerberX2format )
  214. return false;
  215. if( m_includeGerberNetlistInfo != aPcbPlotParams.m_includeGerberNetlistInfo )
  216. return false;
  217. if( m_createGerberJobFile != aPcbPlotParams.m_createGerberJobFile )
  218. return false;
  219. if( m_gerberPrecision != aPcbPlotParams.m_gerberPrecision )
  220. return false;
  221. if( m_dashedLineDashRatio != aPcbPlotParams.m_dashedLineDashRatio )
  222. return false;
  223. if( m_dashedLineGapRatio != aPcbPlotParams.m_dashedLineGapRatio )
  224. return false;
  225. if( m_plotFrameRef != aPcbPlotParams.m_plotFrameRef )
  226. return false;
  227. if( m_plotViaOnMaskLayer != aPcbPlotParams.m_plotViaOnMaskLayer )
  228. return false;
  229. if( m_plotMode != aPcbPlotParams.m_plotMode )
  230. return false;
  231. if( m_DXFplotPolygonMode != aPcbPlotParams.m_DXFplotPolygonMode )
  232. return false;
  233. if( m_DXFplotUnits != aPcbPlotParams.m_DXFplotUnits )
  234. return false;
  235. if( m_svgPrecision != aPcbPlotParams.m_svgPrecision )
  236. return false;
  237. if( m_useAuxOrigin != aPcbPlotParams.m_useAuxOrigin )
  238. return false;
  239. if( m_HPGLPenNum != aPcbPlotParams.m_HPGLPenNum )
  240. return false;
  241. if( m_HPGLPenSpeed != aPcbPlotParams.m_HPGLPenSpeed )
  242. return false;
  243. if( m_HPGLPenDiam != aPcbPlotParams.m_HPGLPenDiam )
  244. return false;
  245. if( m_negative != aPcbPlotParams.m_negative )
  246. return false;
  247. if( m_A4Output != aPcbPlotParams.m_A4Output )
  248. return false;
  249. if( m_plotReference != aPcbPlotParams.m_plotReference )
  250. return false;
  251. if( m_plotValue != aPcbPlotParams.m_plotValue )
  252. return false;
  253. if( m_plotInvisibleText != aPcbPlotParams.m_plotInvisibleText )
  254. return false;
  255. if( m_sketchPadsOnFabLayers != aPcbPlotParams.m_sketchPadsOnFabLayers )
  256. return false;
  257. if( m_subtractMaskFromSilk != aPcbPlotParams.m_subtractMaskFromSilk )
  258. return false;
  259. if( m_format != aPcbPlotParams.m_format )
  260. return false;
  261. if( m_mirror != aPcbPlotParams.m_mirror )
  262. return false;
  263. if( m_drillMarks != aPcbPlotParams.m_drillMarks )
  264. return false;
  265. if( m_scaleSelection != aPcbPlotParams.m_scaleSelection )
  266. return false;
  267. if( m_autoScale != aPcbPlotParams.m_autoScale )
  268. return false;
  269. if( m_scale != aPcbPlotParams.m_scale )
  270. return false;
  271. if( m_fineScaleAdjustX != aPcbPlotParams.m_fineScaleAdjustX )
  272. return false;
  273. if( m_fineScaleAdjustY != aPcbPlotParams.m_fineScaleAdjustY )
  274. return false;
  275. if( m_widthAdjust != aPcbPlotParams.m_widthAdjust )
  276. return false;
  277. if( m_textMode != aPcbPlotParams.m_textMode )
  278. return false;
  279. if( !m_outputDirectory.IsSameAs( aPcbPlotParams.m_outputDirectory ) )
  280. return false;
  281. return true;
  282. }
  283. bool PCB_PLOT_PARAMS::SetHPGLPenDiameter( double aValue )
  284. {
  285. return setDouble( &m_HPGLPenDiam, aValue, HPGL_PEN_DIAMETER_MIN, HPGL_PEN_DIAMETER_MAX );
  286. }
  287. bool PCB_PLOT_PARAMS::SetHPGLPenSpeed( int aValue )
  288. {
  289. return setInt( &m_HPGLPenSpeed, aValue, HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
  290. }
  291. PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( LINE_READER* aReader ) :
  292. PCB_PLOT_PARAMS_LEXER( aReader )
  293. {
  294. }
  295. PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( char* aLine, const wxString& aSource ) :
  296. PCB_PLOT_PARAMS_LEXER( aLine, aSource )
  297. {
  298. }
  299. void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
  300. {
  301. T token;
  302. while( ( token = NextTok() ) != T_RIGHT )
  303. {
  304. if( token == T_EOF)
  305. Unexpected( T_EOF );
  306. if( token == T_LEFT )
  307. token = NextTok();
  308. if( token == T_pcbplotparams )
  309. continue;
  310. bool skip_right = false;
  311. switch( token )
  312. {
  313. case T_layerselection:
  314. {
  315. token = NeedSYMBOLorNUMBER();
  316. const std::string& cur = CurStr();
  317. if( token == T_NUMBER ) // pretty 3 format had legacy Cu stack.
  318. {
  319. // It's not possible to convert a legacy Cu layer number to a new Cu layer
  320. // number without knowing the number or total Cu layers in the legacy board.
  321. // We do not have that information here, so simply set all layers ON. User
  322. // can turn them off in the UI.
  323. aPcbPlotParams->m_layerSelection = LSET( 2, F_SilkS, B_SilkS ) | LSET::AllCuMask();
  324. }
  325. else if( cur.find_first_of( "0x" ) == 0 ) // pretty ver. 4.
  326. {
  327. // skip the leading 2 0x bytes.
  328. aPcbPlotParams->m_layerSelection.ParseHex( cur.c_str() + 2, cur.size() - 2 );
  329. }
  330. else
  331. {
  332. Expecting( "integer or hex layerSelection" );
  333. }
  334. break;
  335. }
  336. case T_plot_on_all_layers_selection:
  337. {
  338. token = NeedSYMBOLorNUMBER();
  339. const std::string& cur = CurStr();
  340. if( cur.find_first_of( "0x" ) == 0 )
  341. {
  342. // skip the leading 2 0x bytes.
  343. aPcbPlotParams->m_plotOnAllLayersSelection.ParseHex( cur.c_str() + 2,
  344. cur.size() - 2 );
  345. }
  346. else
  347. {
  348. Expecting( "hex plot_on_all_layers_selection" );
  349. }
  350. break;
  351. }
  352. case T_disableapertmacros:
  353. aPcbPlotParams->m_gerberDisableApertMacros = parseBool();
  354. break;
  355. case T_usegerberextensions:
  356. aPcbPlotParams->m_useGerberProtelExtensions = parseBool();
  357. break;
  358. case T_usegerberattributes:
  359. aPcbPlotParams->m_useGerberX2format = parseBool();
  360. break;
  361. case T_usegerberadvancedattributes:
  362. aPcbPlotParams->m_includeGerberNetlistInfo = parseBool();
  363. break;
  364. case T_creategerberjobfile:
  365. aPcbPlotParams->m_createGerberJobFile = parseBool();
  366. break;
  367. case T_gerberprecision:
  368. aPcbPlotParams->m_gerberPrecision = parseInt( gbrDefaultPrecision - 1,
  369. gbrDefaultPrecision);
  370. break;
  371. case T_dashed_line_dash_ratio:
  372. aPcbPlotParams->m_dashedLineDashRatio = parseDouble();
  373. break;
  374. case T_dashed_line_gap_ratio:
  375. aPcbPlotParams->m_dashedLineGapRatio = parseDouble();
  376. break;
  377. case T_svgprecision:
  378. aPcbPlotParams->m_svgPrecision = parseInt( SVG_PRECISION_MIN, SVG_PRECISION_MAX );
  379. break;
  380. case T_svguseinch:
  381. parseBool(); // Unused. For compatibility
  382. break;
  383. case T_psa4output:
  384. aPcbPlotParams->m_A4Output = parseBool();
  385. break;
  386. case T_excludeedgelayer:
  387. if( !parseBool() )
  388. aPcbPlotParams->m_plotOnAllLayersSelection.set( Edge_Cuts );
  389. break;
  390. case T_plotframeref:
  391. aPcbPlotParams->m_plotFrameRef = parseBool();
  392. break;
  393. case T_viasonmask:
  394. aPcbPlotParams->m_plotViaOnMaskLayer = parseBool();
  395. break;
  396. case T_mode:
  397. aPcbPlotParams->SetPlotMode( parseInt( 0, 2 ) > 1 ? SKETCH : FILLED );
  398. break;
  399. case T_useauxorigin:
  400. aPcbPlotParams->m_useAuxOrigin = parseBool();
  401. break;
  402. case T_hpglpennumber:
  403. aPcbPlotParams->m_HPGLPenNum = parseInt( HPGL_PEN_NUMBER_MIN, HPGL_PEN_NUMBER_MAX );
  404. break;
  405. case T_hpglpenspeed:
  406. aPcbPlotParams->m_HPGLPenSpeed = parseInt( HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
  407. break;
  408. case T_hpglpendiameter:
  409. aPcbPlotParams->m_HPGLPenDiam = parseDouble();
  410. break;
  411. case T_hpglpenoverlay:
  412. // No more used. just here for compatibility with old versions
  413. parseInt( 0, HPGL_PEN_DIAMETER_MAX );
  414. break;
  415. case T_dxfpolygonmode:
  416. aPcbPlotParams->m_DXFplotPolygonMode = parseBool();
  417. break;
  418. case T_dxfimperialunits:
  419. aPcbPlotParams->m_DXFplotUnits = parseBool() ? DXF_UNITS::INCHES
  420. : DXF_UNITS::MILLIMETERS;
  421. break;
  422. case T_dxfusepcbnewfont:
  423. aPcbPlotParams->m_textMode = parseBool() ? PLOT_TEXT_MODE::DEFAULT
  424. : PLOT_TEXT_MODE::NATIVE;
  425. break;
  426. case T_pscolor:
  427. NeedSYMBOL(); // This actually was never used...
  428. break;
  429. case T_psnegative:
  430. aPcbPlotParams->m_negative = parseBool();
  431. break;
  432. case T_plotreference:
  433. aPcbPlotParams->m_plotReference = parseBool();
  434. break;
  435. case T_plotvalue:
  436. aPcbPlotParams->m_plotValue = parseBool();
  437. break;
  438. case T_plotinvisibletext:
  439. aPcbPlotParams->m_plotInvisibleText = parseBool();
  440. break;
  441. case T_sketchpadsonfab:
  442. aPcbPlotParams->m_sketchPadsOnFabLayers= parseBool();
  443. break;
  444. case T_subtractmaskfromsilk:
  445. aPcbPlotParams->m_subtractMaskFromSilk = parseBool();
  446. break;
  447. case T_outputformat:
  448. aPcbPlotParams->m_format = static_cast<PLOT_FORMAT>(
  449. parseInt( static_cast<int>( PLOT_FORMAT::FIRST_FORMAT ),
  450. static_cast<int>( PLOT_FORMAT::LAST_FORMAT ) ) );
  451. break;
  452. case T_mirror:
  453. aPcbPlotParams->m_mirror = parseBool();
  454. break;
  455. case T_drillshape:
  456. aPcbPlotParams->m_drillMarks = static_cast<PCB_PLOT_PARAMS::DrillMarksType>
  457. ( parseInt( 0, 2 ) );
  458. break;
  459. case T_scaleselection:
  460. aPcbPlotParams->m_scaleSelection = parseInt( 0, 4 );
  461. break;
  462. case T_outputdirectory:
  463. NeedSYMBOLorNUMBER(); // a dir name can be like a number
  464. aPcbPlotParams->m_outputDirectory = FROM_UTF8( CurText() );
  465. break;
  466. default:
  467. skipCurrent(); // skip unknown or outdated plot parameter
  468. skip_right = true; // the closing right token is already read.
  469. break;
  470. }
  471. if( ! skip_right )
  472. NeedRIGHT();
  473. }
  474. }
  475. bool PCB_PLOT_PARAMS_PARSER::parseBool()
  476. {
  477. T token = NeedSYMBOL();
  478. if( token != T_false && token != T_true )
  479. Expecting( "true|false" );
  480. return token == T_true;
  481. }
  482. int PCB_PLOT_PARAMS_PARSER::parseInt( int aMin, int aMax )
  483. {
  484. T token = NextTok();
  485. if( token != T_NUMBER )
  486. Expecting( T_NUMBER );
  487. int val = atoi( CurText() );
  488. if( val < aMin )
  489. val = aMin;
  490. else if( val > aMax )
  491. val = aMax;
  492. return val;
  493. }
  494. double PCB_PLOT_PARAMS_PARSER::parseDouble()
  495. {
  496. T token = NextTok();
  497. if( token != T_NUMBER )
  498. Expecting( T_NUMBER );
  499. return DSNLEXER::parseDouble();
  500. }
  501. void PCB_PLOT_PARAMS_PARSER::skipCurrent()
  502. {
  503. int curr_level = 0;
  504. T token;
  505. while( ( token = NextTok() ) != T_EOF )
  506. {
  507. if( token == T_LEFT )
  508. curr_level--;
  509. if( token == T_RIGHT )
  510. {
  511. curr_level++;
  512. if( curr_level > 0 )
  513. return;
  514. }
  515. }
  516. }