KiCad PCB EDA Suite
PCB_PLOT_PARAMS_PARSER Class Reference

PCB_PLOT_PARAMS_PARSER is the parser class for PCB_PLOT_PARAMS. More...

#include <pcb_plot_params_parser.h>

Inheritance diagram for PCB_PLOT_PARAMS_PARSER:

Public Member Functions

 PCB_PLOT_PARAMS_PARSER (LINE_READER *aReader)
 
 PCB_PLOT_PARAMS_PARSER (char *aLine, const wxString &aSource)
 
LINE_READERGetReader ()
 
void Parse (PCB_PLOT_PARAMS *aPcbPlotParams)
 

Private Member Functions

bool parseBool ()
 
int parseInt (int aMin, int aMax)
 Function parseInt parses an integer and constrains it between two values. More...
 
double parseDouble ()
 Function parseDouble parses a double. More...
 
void skipCurrent ()
 Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes the current description. More...
 

Detailed Description

PCB_PLOT_PARAMS_PARSER is the parser class for PCB_PLOT_PARAMS.

Definition at line 36 of file pcb_plot_params_parser.h.

Constructor & Destructor Documentation

◆ PCB_PLOT_PARAMS_PARSER() [1/2]

PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER ( LINE_READER aReader)

Definition at line 343 of file pcb_plot_params.cpp.

343  :
344  PCB_PLOT_PARAMS_LEXER( aReader )
345 {
346 }

◆ PCB_PLOT_PARAMS_PARSER() [2/2]

PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER ( char *  aLine,
const wxString &  aSource 
)

Definition at line 349 of file pcb_plot_params.cpp.

349  :
350  PCB_PLOT_PARAMS_LEXER( aLine, aSource )
351 {
352 }

Member Function Documentation

◆ GetReader()

LINE_READER* PCB_PLOT_PARAMS_PARSER::GetReader ( )
inline

Definition at line 42 of file pcb_plot_params_parser.h.

42 { return reader; };

◆ Parse()

void PCB_PLOT_PARAMS_PARSER::Parse ( PCB_PLOT_PARAMS aPcbPlotParams)

Definition at line 355 of file pcb_plot_params.cpp.

356 {
357  T token;
358 
359  while( ( token = NextTok() ) != T_RIGHT )
360  {
361  if( token == T_EOF)
362  Unexpected( T_EOF );
363 
364  if( token == T_LEFT )
365  token = NextTok();
366 
367  if( token == T_pcbplotparams )
368  continue;
369 
370  bool skip_right = false;
371 
372  switch( token )
373  {
374  case T_layerselection:
375  {
376  token = NeedSYMBOLorNUMBER();
377 
378  const std::string& cur = CurStr();
379 
380  if( token == T_NUMBER ) // pretty 3 format had legacy Cu stack.
381  {
382  // unsigned legacy_mask = atol( cur.c_str() );
383 
384  /* It's not possible to convert a legacy Cu layer number to a new
385  Cu layer number without knowing the number or total Cu layers
386  in the legacy board. We do not have that information here.
387  So simply set all layers ON. User can turn them off in the UI.
388  This is one of the superiorities of the new Cu sequence.
389  aPcbPlotParams->m_layerSelection = LEGACY_PLUGIN::leg_mask2new( cu_count, legacy_mask );
390  */
391 
392  // sorry, use the UI once to fix:
393  aPcbPlotParams->m_layerSelection = LSET( 2, F_SilkS, B_SilkS) | LSET::AllCuMask();
394  }
395  else if( cur.find_first_of( "0x" ) == 0 ) // pretty ver. 4.
396  {
397  // skip the leading 2 0x bytes.
398  aPcbPlotParams->m_layerSelection.ParseHex( cur.c_str()+2, cur.size()-2 );
399  }
400  else
401  Expecting( "integer or hex layerSelection" );
402  }
403  break;
404 
405  case T_usegerberextensions:
406  aPcbPlotParams->m_useGerberProtelExtensions = parseBool();
407  break;
408 
409  case T_usegerberattributes:
410  aPcbPlotParams->m_useGerberX2format = parseBool();
411  break;
412 
413  case T_usegerberadvancedattributes:
414  aPcbPlotParams->m_includeGerberNetlistInfo = parseBool();
415  break;
416 
417  case T_creategerberjobfile:
418  aPcbPlotParams->m_createGerberJobFile = parseBool();
419  break;
420 
421  case T_gerberprecision:
422  aPcbPlotParams->m_gerberPrecision =
424  break;
425 
426  case T_psa4output:
427  aPcbPlotParams->m_A4Output = parseBool();
428  break;
429 
430  case T_excludeedgelayer:
431  aPcbPlotParams->m_excludeEdgeLayer = parseBool();
432  break;
433 
434  case T_linewidth:
435  {
436  // Due to a bug, this (minor) parameter was saved in biu
437  // and now is saved in mm
438  // If the read value is outside bounds, force a default value
439  double tmp = parseDouble();
440  if( !aPcbPlotParams->SetLineWidth( KiROUND( tmp * IU_PER_MM ) ) )
441  aPcbPlotParams->SetLineWidth( PLOT_LINEWIDTH_DEFAULT );
442  }
443  break;
444 
445  case T_plotframeref:
446  aPcbPlotParams->m_plotFrameRef = parseBool();
447  break;
448 
449  case T_viasonmask:
450  aPcbPlotParams->m_plotViaOnMaskLayer = parseBool();
451  break;
452 
453  case T_mode:
454  aPcbPlotParams->SetPlotMode( parseInt( 0, 2 ) > 1 ? SKETCH : FILLED );
455  break;
456 
457  case T_useauxorigin:
458  aPcbPlotParams->m_useAuxOrigin = parseBool();
459  break;
460 
461  case T_hpglpennumber:
462  aPcbPlotParams->m_HPGLPenNum = parseInt( HPGL_PEN_NUMBER_MIN,
464  break;
465 
466  case T_hpglpenspeed:
467  aPcbPlotParams->m_HPGLPenSpeed = parseInt( HPGL_PEN_SPEED_MIN,
469  break;
470 
471  case T_hpglpendiameter:
472  aPcbPlotParams->m_HPGLPenDiam = parseDouble();
473  break;
474 
475  case T_hpglpenoverlay:
476  // No more used. juste here for compatibility with old versions
478  break;
479 
480  case T_pscolor:
481  NeedSYMBOL(); // This actually was never used...
482  break;
483 
484  case T_psnegative:
485  aPcbPlotParams->m_negative = parseBool();
486  break;
487 
488  case T_plotreference:
489  aPcbPlotParams->m_plotReference = parseBool();
490  break;
491 
492  case T_plotvalue:
493  aPcbPlotParams->m_plotValue = parseBool();
494  break;
495 
496  case T_plotinvisibletext:
497  aPcbPlotParams->m_plotInvisibleText = parseBool();
498  break;
499 
500  case T_padsonsilk:
501  aPcbPlotParams->m_plotPadsOnSilkLayer= parseBool();
502  break;
503 
504  case T_subtractmaskfromsilk:
505  aPcbPlotParams->m_subtractMaskFromSilk = parseBool();
506  break;
507 
508  case T_outputformat:
509  aPcbPlotParams->m_format = static_cast<PLOT_FORMAT>(
510  parseInt( static_cast<int>( PLOT_FORMAT::FIRST_FORMAT ),
511  static_cast<int>( PLOT_FORMAT::LAST_FORMAT ) ) );
512  break;
513 
514  case T_mirror:
515  aPcbPlotParams->m_mirror = parseBool();
516  break;
517 
518  case T_drillshape:
519  aPcbPlotParams->m_drillMarks = static_cast<PCB_PLOT_PARAMS::DrillMarksType>
520  ( parseInt( 0, 2 ) );
521  break;
522 
523  case T_scaleselection:
524  aPcbPlotParams->m_scaleSelection = parseInt( 0, 4 );
525  break;
526 
527  case T_outputdirectory:
528  NeedSYMBOLorNUMBER(); // a dir name can be like a number
529  aPcbPlotParams->m_outputDirectory = FROM_UTF8( CurText() );
530  break;
531 
532  default:
533  skipCurrent(); // skip unknown or outdated plot parameter
534  skip_right = true; // the closing right token is already read.
535  break;
536  }
537 
538  if( ! skip_right )
539  NeedRIGHT();
540  }
541 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
#define HPGL_PEN_NUMBER_MAX
bool m_plotValue
Enable plotting of part values.
#define HPGL_PEN_SPEED_MAX
double parseDouble()
Function parseDouble parses a double.
#define PLOT_LINEWIDTH_DEFAULT
wxString m_outputDirectory
Output directory for plot files (usually relative to the board file)
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
bool m_mirror
Mirror the plot around the X axis.
bool m_excludeEdgeLayer
If false always plot (merge) the pcb edge layer on other layers.
static const int gbrDefaultPrecision
bool m_plotPadsOnSilkLayer
Allows pads outlines on silkscreen layer (when pads are also on silk screen)
bool m_useGerberX2format
Include attributes from the Gerber X2 format (chapter 5 in revision J2)
bool m_plotReference
Enable plotting of part references.
bool m_useGerberProtelExtensions
When plotting gerber files, use a conventional set of Protel extensions instead of ....
int m_scaleSelection
Scale ratio index (UI only)
bool m_negative
Plot in negative color (supported only by some drivers)
bool m_plotFrameRef
True to plot/print frame references.
double m_HPGLPenDiam
HPGL only: pen diameter in MILS, useful to fill areas However, it is in mm in hpgl files.
bool SetLineWidth(int aValue)
bool m_includeGerberNetlistInfo
Include netlist info (only in Gerber X2 format) (chapter ? in revision ?)
bool m_plotInvisibleText
Force plotting of fields marked invisible.
bool m_A4Output
Autoscale the plot to fit an A4 (landscape?) sheet.
LSET is a set of PCB_LAYER_IDs.
bool m_subtractMaskFromSilk
On gerbers 'scrape' away the solder mask from silkscreen (trim silks)
#define HPGL_PEN_DIAMETER_MAX
bool m_plotViaOnMaskLayer
True if vias are drawn on Mask layer (ie untented, exposed by mask)
bool m_useAuxOrigin
Plot gerbers using auxiliary (drill) origin instead of absolue coordinates.
PLOT_FORMAT m_format
Plot format type (chooses the driver to be used)
bool m_createGerberJobFile
generate the auxiliary "job file" in gerber format
void SetPlotMode(EDA_DRAW_MODE_T aPlotMode)
int m_HPGLPenNum
HPGL only: pen number selection(1 to 9)
LSET m_layerSelection
Set of layers to plot.
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
#define HPGL_PEN_NUMBER_MIN
#define HPGL_PEN_SPEED_MIN
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
int m_HPGLPenSpeed
HPGL only: pen speed, always in cm/s (1 to 99 cm/s)
int parseInt(int aMin, int aMax)
Function parseInt parses an integer and constrains it between two values.
int ParseHex(const char *aStart, int aCount)
Function ParseHex understands the output of FmtHex() and replaces this set's values with those given ...
Definition: lset.cpp:325
DrillMarksType m_drillMarks
Holes can be not plotted, have a small mark or plotted in actual size.
int m_gerberPrecision
precision of coordinates in Gerber files: accepted 5 or 6 when units are in mm (6 or 7 in inches,...

References LSET::AllCuMask(), B_SilkS, F_SilkS, FILLED, FIRST_FORMAT, FROM_UTF8(), gbrDefaultPrecision, HPGL_PEN_DIAMETER_MAX, HPGL_PEN_NUMBER_MAX, HPGL_PEN_NUMBER_MIN, HPGL_PEN_SPEED_MAX, HPGL_PEN_SPEED_MIN, KiROUND(), LAST_FORMAT, PCB_PLOT_PARAMS::m_A4Output, PCB_PLOT_PARAMS::m_createGerberJobFile, PCB_PLOT_PARAMS::m_drillMarks, PCB_PLOT_PARAMS::m_excludeEdgeLayer, PCB_PLOT_PARAMS::m_format, PCB_PLOT_PARAMS::m_gerberPrecision, PCB_PLOT_PARAMS::m_HPGLPenDiam, PCB_PLOT_PARAMS::m_HPGLPenNum, PCB_PLOT_PARAMS::m_HPGLPenSpeed, PCB_PLOT_PARAMS::m_includeGerberNetlistInfo, PCB_PLOT_PARAMS::m_layerSelection, PCB_PLOT_PARAMS::m_mirror, PCB_PLOT_PARAMS::m_negative, PCB_PLOT_PARAMS::m_outputDirectory, PCB_PLOT_PARAMS::m_plotFrameRef, PCB_PLOT_PARAMS::m_plotInvisibleText, PCB_PLOT_PARAMS::m_plotPadsOnSilkLayer, PCB_PLOT_PARAMS::m_plotReference, PCB_PLOT_PARAMS::m_plotValue, PCB_PLOT_PARAMS::m_plotViaOnMaskLayer, PCB_PLOT_PARAMS::m_scaleSelection, PCB_PLOT_PARAMS::m_subtractMaskFromSilk, PCB_PLOT_PARAMS::m_useAuxOrigin, PCB_PLOT_PARAMS::m_useGerberProtelExtensions, PCB_PLOT_PARAMS::m_useGerberX2format, parseBool(), parseDouble(), LSET::ParseHex(), parseInt(), PLOT_LINEWIDTH_DEFAULT, PCB_PLOT_PARAMS::SetLineWidth(), PCB_PLOT_PARAMS::SetPlotMode(), SKETCH, and skipCurrent().

Referenced by PCB_PLOT_PARAMS::Parse().

◆ parseBool()

bool PCB_PLOT_PARAMS_PARSER::parseBool ( )
private

Definition at line 544 of file pcb_plot_params.cpp.

545 {
546  T token = NeedSYMBOL();
547 
548  if( token != T_false && token != T_true )
549  Expecting( "true|false" );
550 
551  return token == T_true;
552 }

Referenced by Parse().

◆ parseDouble()

double PCB_PLOT_PARAMS_PARSER::parseDouble ( )
private

Function parseDouble parses a double.

Returns
double - the parsed double.

Definition at line 573 of file pcb_plot_params.cpp.

574 {
575  T token = NextTok();
576 
577  if( token != T_NUMBER )
578  Expecting( T_NUMBER );
579 
580  double val = strtod( CurText(), NULL );
581 
582  return val;
583 }
#define NULL

References NULL.

Referenced by Parse().

◆ parseInt()

int PCB_PLOT_PARAMS_PARSER::parseInt ( int  aMin,
int  aMax 
)
private

Function parseInt parses an integer and constrains it between two values.

Parameters
aMinis the smallest return value.
aMaxis the largest return value.
Returns
int - the parsed integer.

Definition at line 555 of file pcb_plot_params.cpp.

556 {
557  T token = NextTok();
558 
559  if( token != T_NUMBER )
560  Expecting( T_NUMBER );
561 
562  int val = atoi( CurText() );
563 
564  if( val < aMin )
565  val = aMin;
566  else if( val > aMax )
567  val = aMax;
568 
569  return val;
570 }

Referenced by Parse().

◆ skipCurrent()

void PCB_PLOT_PARAMS_PARSER::skipCurrent ( )
private

Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes the current description.

Definition at line 586 of file pcb_plot_params.cpp.

587 {
588  int curr_level = 0;
589  T token;
590 
591  while( ( token = NextTok() ) != T_EOF )
592  {
593  if( token == T_LEFT )
594  curr_level--;
595 
596  if( token == T_RIGHT )
597  {
598  curr_level++;
599 
600  if( curr_level > 0 )
601  return;
602  }
603  }
604 }

Referenced by Parse().


The documentation for this class was generated from the following files: