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.

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