KiCad PCB EDA Suite
GERBER_JOBFILE_WRITER Class Reference

GERBER_JOBFILE_WRITER is a class used to create Gerber job file a Gerber job file stores info to make a board: list of gerber files info about the board itsel: size, number of copper layers thickness of the board, copper and dielectric and some other info (colors, finish type ...) More...

#include <gerber_jobfile_writer.h>

Public Member Functions

 GERBER_JOBFILE_WRITER (BOARD *aPcb, REPORTER *aReporter=nullptr)
 
virtual ~GERBER_JOBFILE_WRITER ()
 
void AddGbrFile (PCB_LAYER_ID aLayer, wxString &aFilename)
 add a gerber file name and type in job file list More...
 
bool CreateJobFile (const wxString &aFullFilename)
 Creates a Gerber job file. More...
 
bool WriteJSONJobFile (const wxString &aFullFilename)
 Creates an Gerber job file in JSON format. More...
 

Private Member Functions

enum ONSIDE hasSilkLayers ()
 
enum ONSIDE hasSolderMasks ()
 
const char * sideKeyValue (enum ONSIDE aValue)
 
void addJSONHeader ()
 Add the job file header in JSON format to m_JSONbuffer. More...
 
void addJSONGeneralSpecs ()
 Add the General Specs in JSON format to m_JSONbuffer. More...
 
void addJSONFilesAttributes ()
 Add the Files Attributes section in JSON format to m_JSONbuffer. More...
 
void addJSONMaterialStackup ()
 Add the Material Stackup section in JSON format to m_JSONbuffer This is the ordered list of stackup layers (mask, paste, silk, copper, dielectric) used to make the physical board. More...
 
void addJSONDesignRules ()
 Add the Design Rules section in JSON format to m_JSONbuffer. More...
 
void removeJSONSepararator ()
 Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a
. More...
 
void addIndent ()
 add m_indent spaces in m_JSONbuffer More...
 
void openBlock ()
 open a JSON block: add '{' and increment indentation More...
 
void openArrayBlock ()
 open a JSON array block: add '[' and increment indentation More...
 
void closeBlock ()
 close a JSON block: decrement indentation and add '}' More...
 
void closeBlockWithSep ()
 close a JSON block: decrement indentation and add '}' and ',' More...
 
void closeArrayBlock ()
 close a JSON array block: decrement indentation and add ']' More...
 
void closeArrayBlockWithSep ()
 close a JSON array block: decrement indentation and add ']' and ',' More...
 
void addJSONObject (const wxString &aParam)
 Add aParam to m_JSONbuffer, with suitable indentation. More...
 
void addJSONObject (const char *aParam)
 

Private Attributes

BOARDm_pcb
 
REPORTERm_reporter
 
JOBFILE_PARAMS m_params
 
double m_conversionUnits
 
wxString m_JSONbuffer
 
int m_indent
 

Detailed Description

GERBER_JOBFILE_WRITER is a class used to create Gerber job file a Gerber job file stores info to make a board: list of gerber files info about the board itsel: size, number of copper layers thickness of the board, copper and dielectric and some other info (colors, finish type ...)

note: dimensions are always in mm in Kicad job file (can be also in inches in a job file) and they are in floating point notation

Definition at line 69 of file gerber_jobfile_writer.h.

Constructor & Destructor Documentation

GERBER_JOBFILE_WRITER::GERBER_JOBFILE_WRITER ( BOARD aPcb,
REPORTER aReporter = nullptr 
)

Definition at line 50 of file gerber_jobfile_writer.cpp.

References m_conversionUnits, m_indent, m_pcb, and m_reporter.

51 {
52  m_pcb = aPcb;
53  m_reporter = aReporter;
54  m_conversionUnits = 1.0 / IU_PER_MM; // Gerber units = mm
55  m_indent = 0;
56 }
virtual GERBER_JOBFILE_WRITER::~GERBER_JOBFILE_WRITER ( )
inlinevirtual

Definition at line 74 of file gerber_jobfile_writer.h.

75  {
76  }

Member Function Documentation

void GERBER_JOBFILE_WRITER::AddGbrFile ( PCB_LAYER_ID  aLayer,
wxString &  aFilename 
)
inline

add a gerber file name and type in job file list

Parameters
aLayeris the PCB_LAYER_ID corresponding to the gerber file
aFilenameis the filename (without path) of the gerber file

Definition at line 83 of file gerber_jobfile_writer.h.

Referenced by DIALOG_PLOT::Plot().

84  {
85  m_params.m_GerberFileList.Add( aFilename );
86  m_params.m_LayerId.push_back( aLayer );
87  }
wxArrayString m_GerberFileList
std::vector< PCB_LAYER_ID > m_LayerId
void GERBER_JOBFILE_WRITER::addIndent ( )
inlineprivate

add m_indent spaces in m_JSONbuffer

Definition at line 160 of file gerber_jobfile_writer.h.

void GERBER_JOBFILE_WRITER::addJSONDesignRules ( )
private

Add the Design Rules section in JSON format to m_JSONbuffer.

Definition at line 427 of file gerber_jobfile_writer.cpp.

References addJSONObject(), B_Cu, NETCLASSES::begin(), closeArrayBlockWithSep(), closeBlock(), closeBlockWithSep(), NETCLASSES::end(), LSET::ExternalCuMask(), F_Cu, Format(), BOARD::GetArea(), BOARD::GetAreaCount(), ZONE_CONTAINER::GetClearance(), NETCLASS::GetClearance(), BOARD::GetCopperLayerCount(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), ZONE_CONTAINER::GetIsKeepout(), ZONE_CONTAINER::GetLayer(), LSET::InternalCuMask(), ZONE_CONTAINER::IsOnCopperLayer(), m_conversionUnits, BOARD_DESIGN_SETTINGS::m_NetClasses, m_pcb, min, BOARD::Modules(), openArrayBlock(), openBlock(), PCB_VIA_T, removeJSONSepararator(), and BOARD::Tracks().

Referenced by WriteJSONJobFile().

428 {
429  // Add the Design Rules section in JSON format to m_JSONbuffer
430  // Job file support a few design rules:
431  const BOARD_DESIGN_SETTINGS& dsnSettings = m_pcb->GetDesignSettings();
432  NETCLASS defaultNC = *dsnSettings.GetDefault();
433  int minclearanceOuter = defaultNC.GetClearance();
434  bool hasInnerLayers = m_pcb->GetCopperLayerCount() > 2;
435 
436  // Search a smaller clearance in other net classes, if any.
437  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
438  it != dsnSettings.m_NetClasses.end();
439  ++it )
440  {
441  NETCLASS netclass = *it->second;
442  minclearanceOuter = std::min( minclearanceOuter, netclass.GetClearance() );
443  }
444 
445  // job file knows different clearance types.
446  // Kicad knows only one clearance for pads and tracks
447  int minclearance_track2track = minclearanceOuter;
448 
449  // However, pads can have a specific clearance defined for a pad or a footprint,
450  // and min clearance can be dependent on layers.
451  // Search for a minimal pad clearance:
452  int minPadClearanceOuter = defaultNC.GetClearance();
453  int minPadClearanceInner = defaultNC.GetClearance();
454 
455  for( MODULE* module : m_pcb->Modules() )
456  {
457  for( auto& pad : module->Pads() )
458  {
459  if( ( pad->GetLayerSet() & LSET::InternalCuMask() ).any() )
460  minPadClearanceInner = std::min( minPadClearanceInner, pad->GetClearance() );
461 
462  if( ( pad->GetLayerSet() & LSET::ExternalCuMask() ).any() )
463  minPadClearanceOuter = std::min( minPadClearanceOuter, pad->GetClearance() );
464  }
465  }
466 
467 
468  addJSONObject( "\"DesignRules\":\n" );
469  openArrayBlock();
470 
471  openBlock();
472  addJSONObject( "\"Layers\": \"Outer\",\n" );
473  addJSONObject( wxString::Format( "\"PadToPad\": %.3f,\n", minPadClearanceOuter*m_conversionUnits ) );
474  addJSONObject( wxString::Format( "\"PadToTrack\": %.3f,\n", minPadClearanceOuter*m_conversionUnits ) );
475  addJSONObject( wxString::Format( "\"TrackToTrack\": %.3f,\n", minclearance_track2track*m_conversionUnits ) );
476 
477  // Until this is changed in Kicad, use the same value for internal tracks
478  int minclearanceInner = minclearanceOuter;
479 
480  // Output the minimal track width
481  int mintrackWidthOuter = INT_MAX;
482  int mintrackWidthInner = INT_MAX;
483 
484  for( TRACK* track : m_pcb->Tracks() )
485  {
486  if( track->Type() == PCB_VIA_T )
487  continue;
488 
489  if( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
490  mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
491  else
492  mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
493  }
494 
495  if( mintrackWidthOuter != INT_MAX )
496  addJSONObject( wxString::Format( "\"MinLineWidth\": %.3f,\n",
497  mintrackWidthOuter*m_conversionUnits ) );
498 
499  // Output the minimal zone to xx clearance
500  // Note: zones can have a zone clearance set to 0
501  // if happens, the actual zone clearance is the clearance of its class
502  minclearanceOuter = INT_MAX;
503  minclearanceInner = INT_MAX;
504 
505  for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
506  {
507  ZONE_CONTAINER* zone = m_pcb->GetArea( ii );
508 
509  if( zone->GetIsKeepout() || !zone->IsOnCopperLayer() )
510  continue;
511 
512  int zclerance = zone->GetClearance();
513 
514  if( zone->GetLayer() == B_Cu || zone->GetLayer() == F_Cu )
515  minclearanceOuter = std::min( minclearanceOuter, zclerance );
516  else
517  minclearanceInner = std::min( minclearanceInner, zclerance );
518  }
519 
520  if( minclearanceOuter != INT_MAX )
521  addJSONObject( wxString::Format( "\"TrackToRegion\": %.3f,\n",
522  minclearanceOuter*m_conversionUnits ) );
523 
524  if( minclearanceOuter != INT_MAX )
525  addJSONObject( wxString::Format( "\"RegionToRegion\": %.3f,\n",
526  minclearanceOuter*m_conversionUnits ) );
527 
528  removeJSONSepararator(); // remove the last separator
529 
530  if( !hasInnerLayers )
531  closeBlock();
532  else
534 
535 
536  if( hasInnerLayers )
537  {
538  openBlock();
539  addJSONObject( "\"Layers\": \"Inner\",\n" );
540  addJSONObject( wxString::Format( "\"PadToPad\": %.3f,\n", minPadClearanceInner*m_conversionUnits ) );
541  addJSONObject( wxString::Format( "\"PadToTrack\": %.3f,\n", minPadClearanceInner*m_conversionUnits ) );
542  addJSONObject( wxString::Format( "\"TrackToTrack\": %.3f,\n", minclearance_track2track*m_conversionUnits ) );
543 
544  if( mintrackWidthInner != INT_MAX )
545  addJSONObject( wxString::Format( "\"MinLineWidth\": %.3f,\n", mintrackWidthInner*m_conversionUnits ) );
546 
547  if( minclearanceInner != INT_MAX )
548  addJSONObject( wxString::Format( "\"TrackToRegion\": %.3f,\n", minclearanceInner*m_conversionUnits ) );
549 
550  if( minclearanceInner != INT_MAX )
551  addJSONObject( wxString::Format( "\"RegionToRegion\": %.3f,\n", minclearanceInner*m_conversionUnits ) );
552 
553  removeJSONSepararator(); // remove the last separator
554  closeBlock();
555  }
556 
557  // Close DesignRules
559 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
NETCLASSPTR GetDefault() const
Function GetDefault.
int GetClearance() const
Definition: netclass.h:162
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
int GetCopperLayerCount() const
Function GetCopperLayerCount.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
iterator end()
Definition: netclass.h:249
void closeBlock()
close a JSON block: decrement indentation and add &#39;}&#39;
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:251
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_zone.cpp:778
void openBlock()
open a JSON block: add &#39;{&#39; and increment indentation
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:623
iterator begin()
Definition: netclass.h:248
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:254
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
Definition: netclass.h:55
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:633
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:703
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
void openArrayBlock()
open a JSON array block: add &#39;[&#39; and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add &#39;}&#39; and &#39;,&#39;
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1020
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add &#39;]&#39; and &#39;,&#39;
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:991
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:253
#define min(a, b)
Definition: auxiliary.h:85
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void GERBER_JOBFILE_WRITER::addJSONFilesAttributes ( )
private

Add the Files Attributes section in JSON format to m_JSONbuffer.

Definition at line 325 of file gerber_jobfile_writer.cpp.

References addJSONObject(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, closeArrayBlockWithSep(), closeBlockWithSep(), Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, Format(), formatStringToGerber(), BOARD::GetCopperLayerCount(), JOBFILE_PARAMS::m_GerberFileList, JOBFILE_PARAMS::m_LayerId, m_params, m_pcb, m_reporter, Margin, name, openArrayBlock(), openBlock(), removeJSONSepararator(), REPORTER::Report(), and REPORTER::RPT_ERROR.

Referenced by WriteJSONJobFile().

326 {
327  // Add the Files Attributes section in JSON format to m_JSONbuffer
328  addJSONObject( "\"FilesAttributes\":\n" );
329  openArrayBlock();
330 
331  for( unsigned ii = 0; ii < m_params.m_GerberFileList.GetCount(); ii ++ )
332  {
333  wxString& name = m_params.m_GerberFileList[ii];
334  PCB_LAYER_ID layer = m_params.m_LayerId[ii];
335  wxString gbr_layer_id;
336  bool skip_file = false; // true to skip files which should not be in job file
337  const char* polarity = "Positive";
338 
339  if( layer <= B_Cu )
340  {
341  gbr_layer_id = "Copper,L";
342 
343  if( layer == B_Cu )
344  gbr_layer_id << m_pcb->GetCopperLayerCount();
345  else
346  gbr_layer_id << layer+1;
347 
348  gbr_layer_id << ",";
349 
350  if( layer == B_Cu )
351  gbr_layer_id << "Bot";
352  else if( layer == F_Cu )
353  gbr_layer_id << "Top";
354  else
355  gbr_layer_id << "Inr";
356  }
357 
358  else
359  {
360  switch( layer )
361  {
362  case B_Adhes:
363  gbr_layer_id = "Glue,Bot"; break;
364  case F_Adhes:
365  gbr_layer_id = "Glue,Top"; break;
366 
367  case B_Paste:
368  gbr_layer_id = "SolderPaste,Bot"; break;
369  case F_Paste:
370  gbr_layer_id = "SolderPaste,Top"; break;
371 
372  case B_SilkS:
373  gbr_layer_id = "Legend,Bot"; break;
374  case F_SilkS:
375  gbr_layer_id = "Legend,Top"; break;
376 
377  case B_Mask:
378  gbr_layer_id = "SolderMask,Bot"; polarity = "Negative"; break;
379  case F_Mask:
380  gbr_layer_id = "SolderMask,Top"; polarity = "Negative"; break;
381 
382  case Edge_Cuts:
383  gbr_layer_id = "Profile"; break;
384 
385  case B_Fab:
386  gbr_layer_id = "AssemblyDrawing,Bot"; break;
387  case F_Fab:
388  gbr_layer_id = "AssemblyDrawing,Top"; break;
389 
390  case Dwgs_User:
391  case Cmts_User:
392  case Eco1_User:
393  case Eco2_User:
394  case Margin:
395  case B_CrtYd:
396  case F_CrtYd:
397  skip_file = true; break;
398 
399  default:
400  skip_file = true;
401  m_reporter->Report( "Unexpected layer id in job file",
403  break;
404  }
405  }
406 
407  if( !skip_file )
408  {
409  // name can contain non ASCII7 chars.
410  // Only ASCII7 chars are accepted in gerber files. others must be converted to
411  // a gerber hexa sequence.
412  std::string strname = formatStringToGerber( name );
413 
414  openBlock();
415  addJSONObject( wxString::Format( "\"Path\": \"%s\",\n", strname.c_str() ) );
416  addJSONObject( wxString::Format( "\"FileFunction\": \"%s\",\n", gbr_layer_id ) ),
417  addJSONObject( wxString::Format( "\"FilePolarity\": \"%s\"\n", polarity ) );
419  }
420  }
421  // Close the file list:
422  removeJSONSepararator(); // remove the last separator
424 }
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
std::string formatStringToGerber(const wxString &aString)
This helper function "normalize" aString and convert it to a Gerber std::string Normalisation means c...
void openBlock()
open a JSON block: add &#39;{&#39; and increment indentation
wxArrayString m_GerberFileList
PCB_LAYER_ID
A quick note on layer IDs:
void openArrayBlock()
open a JSON array block: add &#39;[&#39; and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add &#39;}&#39; and &#39;,&#39;
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add &#39;]&#39; and &#39;,&#39;
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
std::vector< PCB_LAYER_ID > m_LayerId
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void GERBER_JOBFILE_WRITER::addJSONGeneralSpecs ( )
private

Add the General Specs in JSON format to m_JSONbuffer.

Definition at line 237 of file gerber_jobfile_writer.cpp.

References addJSONObject(), closeBlockWithSep(), Format(), GbrMakeProjectGUIDfromString(), BOARD::GetBoardEdgesBoundingBox(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), BOARD::GetCopperLayerCount(), BOARD::GetDesignSettings(), BOARD::GetFileName(), EDA_RECT::GetHeight(), TITLE_BLOCK::GetRevision(), BOARD::GetTitleBlock(), EDA_RECT::GetWidth(), m_conversionUnits, m_pcb, openBlock(), and removeJSONSepararator().

Referenced by WriteJSONJobFile().

238 {
239  addJSONObject( "\"GeneralSpecs\":\n" );
240  openBlock();
241 
242  addJSONObject( "\"ProjectId\":\n" );
243  openBlock();
244 
245  // Creates the ProjectId. Format is (from Gerber file format doc):
246  // ProjectId,<project id>,<project GUID>,<revision id>*%
247  // <project id> is the name of the project, restricted to basic ASCII symbols only,
248  // and comma not accepted
249  // All illegal chars will be replaced by underscore
250  // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
251  //
252  // <project GUID> is a string which is an unique id of a project.
253  // However Kicad does not handle such a project GUID, so it is built from the board name
254  wxFileName fn = m_pcb->GetFileName();
255  wxString msg = fn.GetFullName();
256 
257  // Build a <project GUID>, from the board name
258  wxString guid = GbrMakeProjectGUIDfromString( msg );
259 
260  // build the <project id> string: this is the board short filename (without ext)
261  // and all non ASCII chars are replaced by '_'
262  msg = fn.GetName();
263 
264  // build the <rec> string. All non ASCII chars and comma are replaced by '_'
265  wxString rev = m_pcb->GetTitleBlock().GetRevision();
266 
267  if( rev.IsEmpty() )
268  rev = wxT( "rev?" );
269 
270  addJSONObject( wxString::Format( "\"Name\": \"%s\",\n", msg.ToAscii() ) );
271  addJSONObject( wxString::Format( "\"GUID\": \"%s\",\n", guid ) );
272  addJSONObject( wxString::Format( "\"Revision\": \"%s\"\n", rev.ToAscii() ) );
273 
275 
276  // output the bord size in mm:
278  addJSONObject( "\"Size\":\n" );
279  openBlock();
280 
281  addJSONObject( wxString::Format( "\"X\": %.3f,\n", brect.GetWidth()*m_conversionUnits ) );
282  addJSONObject( wxString::Format( "\"Y\": %.3f\n", brect.GetHeight()*m_conversionUnits ) );
284 
285  // Add some data to the JSON header, GeneralSpecs:
286  // number of copper layers
287  addJSONObject( wxString::Format( "\"LayerNumber\": %d,\n", m_pcb->GetCopperLayerCount() ) );
288 
289  // Board thickness
290  addJSONObject( wxString::Format( "\"BoardThickness\": %.3f,\n",
292 
293 #if 0 // Not yet in use
294  /* The board type according to IPC-2221. There are six primary board types:
295  - Type 1 - Single-sided
296  - Type 2 - Double-sided
297  - Type 3 - Multilayer, TH components only
298  - Type 4 - Multilayer, with TH, blind and/or buried vias.
299  - Type 5 - Multilayer metal-core board, TH components only
300  - Type 6 - Multilayer metal-core
301  */
302  addJSONObject( wxString::Format( "\"IPC-2221-Type\": \"%d\",\n", 4 ) );
303 
304  /* Via protection: key words:
305  Ia Tented - Single-sided
306  Ib Tented - Double-sided
307  IIa Tented and Covered - Single-sided
308  IIb Tented and Covered - Double-sided
309  IIIa Plugged - Single-sided
310  IIIb Plugged - Double-sided
311  IVa Plugged and Covered - Single-sided
312  IVb Plugged and Covered - Double-sided
313  V Filled (fully plugged)
314  VI Filled and Covered
315  VIII Filled and Capped
316  None...No protection
317  */
318  addJSONObject( wxString::Format( "\"ViaProtection\": \"%s\",\n", "Ib" ) );
319 #endif
322 }
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
int GetCopperLayerCount() const
Function GetCopperLayerCount.
int GetHeight() const
Definition: eda_rect.h:118
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
void openBlock()
open a JSON block: add &#39;{&#39; and increment indentation
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:804
wxString GbrMakeProjectGUIDfromString(wxString &aText)
A helper function to build a project GUID using format RFC4122 Version 1 or 4 from the project name...
const wxString & GetFileName() const
Definition: class_board.h:237
const wxString & GetRevision() const
Definition: title_block.h:89
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
void closeBlockWithSep()
close a JSON block: decrement indentation and add &#39;}&#39; and &#39;,&#39;
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:559
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetWidth() const
Definition: eda_rect.h:117
void GERBER_JOBFILE_WRITER::addJSONHeader ( )
private

Add the job file header in JSON format to m_JSONbuffer.

Definition at line 142 of file gerber_jobfile_writer.cpp.

References addJSONObject(), closeBlockWithSep(), GetBuildVersion(), and openBlock().

Referenced by WriteJSONJobFile().

143 {
144  wxString text;
145  openBlock();
146  addJSONObject( "\"Header\":\n" );
147  openBlock();
148 
149  // Creates the GenerationSoftware
150  addJSONObject( "\"GenerationSoftware\":\n" );
151  openBlock();
152  addJSONObject( "\"Vendor\": \"KiCad\",\n" );
153  addJSONObject( "\"Application\": \"Pcbnew\",\n" );
154  text.Printf( "\"Version\": \"%s\"\n", GetBuildVersion() );
155  addJSONObject( text );
157 
158  // creates the TF.CreationDate ext:
159  // The attribute value must conform to the full version of the ISO 8601
160  // date and time format, including time and time zone. Note that this is
161  // the date the Gerber file was effectively created,
162  // not the time the project of PCB was started
163  wxDateTime date( wxDateTime::GetTimeNow() );
164  // Date format: see http://www.cplusplus.com/reference/ctime/strftime
165  wxString msg = date.Format( wxT( "%z" ) ); // Extract the time zone offset
166  // The time zone offset format is + (or -) mm or hhmm (mm = number of minutes, hh = number of hours)
167  // we want +(or -) hh:mm
168  if( msg.Len() > 3 )
169  msg.insert( 3, ":", 1 );
170 
171  text.Printf( wxT( "\"CreationDate\": \"%s%s\"\n" ),date.FormatISOCombined(), msg );
172  addJSONObject( text );
173 
175 }
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
void openBlock()
open a JSON block: add &#39;{&#39; and increment indentation
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void closeBlockWithSep()
close a JSON block: decrement indentation and add &#39;}&#39; and &#39;,&#39;
void GERBER_JOBFILE_WRITER::addJSONMaterialStackup ( )
private

Add the Material Stackup section in JSON format to m_JSONbuffer This is the ordered list of stackup layers (mask, paste, silk, copper, dielectric) used to make the physical board.

Therefore not all layers are listed here

Definition at line 562 of file gerber_jobfile_writer.cpp.

References addJSONObject(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, closeArrayBlockWithSep(), closeBlockWithSep(), Cmts_User, color, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, Format(), formatStringToGerber(), BOARD::GetLayerName(), JOBFILE_PARAMS::m_GerberFileList, JOBFILE_PARAMS::m_LayerId, m_params, m_pcb, m_reporter, Margin, openArrayBlock(), openBlock(), removeJSONSepararator(), REPORTER::Report(), REPORTER::RPT_ERROR, and LSET::SeqStackupBottom2Top().

Referenced by WriteJSONJobFile().

563 {
564  // Add the Material Stackup section in JSON format to m_JSONbuffer
565  addJSONObject( "\"MaterialStackup\":\n" );
566  openArrayBlock();
567 
568  // Build the candidates: only layers on a board are candidates:
569  LSET maskLayer;
570 
571  for( unsigned ii = 0; ii < m_params.m_GerberFileList.GetCount(); ii ++ )
572  {
573  PCB_LAYER_ID layer = m_params.m_LayerId[ii];
574 
575  if( layer <= B_Cu )
576  maskLayer.set( layer );
577  else
578  {
579  switch( layer )
580  {
581  case B_Paste:
582  case F_Paste:
583  case B_SilkS:
584  case F_SilkS:
585  case B_Mask:
586  case F_Mask:
587  maskLayer.set( layer );
588  break;
589 
590  case Edge_Cuts:
591  case B_Adhes:
592  case F_Adhes:
593  case B_Fab:
594  case F_Fab:
595  case Dwgs_User:
596  case Cmts_User:
597  case Eco1_User:
598  case Eco2_User:
599  case Margin:
600  case B_CrtYd:
601  case F_CrtYd:
602  break;
603 
604  default:
606  wxString::Format( "Unexpected layer id %d in job file", layer ),
608  break;
609  }
610  }
611  }
612 
613  // build a candidate list (in reverse order: bottom to top):
614  LSEQ list = maskLayer.SeqStackupBottom2Top();
615  // Generate the list (top to bottom):
616  for( int ii = list.size()-1; ii >= 0; --ii )
617  {
618  PCB_LAYER_ID layer = list[ii];
619  wxString layer_type;
620  wxString color;
621  wxString dielectric;
622  double thickness = 0.0; // layer thickness in mm
623 
624  if( layer <= B_Cu )
625  {
626  layer_type = "Copper";
627  //thickness = 0.035;
628  }
629  else
630  {
631  switch( layer )
632  {
633  case B_Paste:
634  case F_Paste:
635  layer_type = "SolderPaste";
636  break;
637 
638  case B_SilkS:
639  case F_SilkS:
640  //color = "White";
641  layer_type = "Legend";
642  break;
643 
644  case B_Mask:
645  case F_Mask:
646  //color = "Green";
647  //thickness = 0.025;
648  layer_type = "SolderMask";
649  break;
650 
651  default:
652  break;
653  }
654  }
655 
656  openBlock();
657  addJSONObject( wxString::Format( "\"Type\": \"%s\",\n", layer_type ) );
658 
659  if( !color.IsEmpty() )
660  addJSONObject( wxString::Format( "\"Color\": \"%s\",\n", color ) );
661 
662  if( thickness > 0.0 )
663  addJSONObject( wxString::Format( "\"Thickness\": %f,\n", thickness ) );
664 
665  std::string strname = formatStringToGerber( m_pcb->GetLayerName( layer ) );
666  addJSONObject( wxString::Format( "\"Notes\": \"Layer %s\",\n", strname.c_str() ) );
669 
670  if( layer < B_Cu ) // Add dielectric between copper layers
671  {
672  dielectric = "FR4"; // Temporary
673 
674  openBlock();
675  addJSONObject( wxString::Format( "\"Type\": \"%s\",\n", "Dielectric" ) );
676 
677  if( thickness > 0.0 )
678  addJSONObject( wxString::Format( "\"Thickness\": %f,\n", color ) );
679 
680  if( !dielectric.IsEmpty() )
681  addJSONObject( wxString::Format( "\"Material\": \"%s\",\n", dielectric ) );
682 
683  addJSONObject( wxString::Format( "\"Notes\": \"Layers L%d/L%d\",\n",
684  layer+1, layer+2 ) );
687  }
688  }
689 
692 }
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
int color
Definition: DXF_plotter.cpp:62
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
std::string formatStringToGerber(const wxString &aString)
This helper function "normalize" aString and convert it to a Gerber std::string Normalisation means c...
LSEQ SeqStackupBottom2Top() const
Function SeqStackBottom2Top returns the sequence that is typical for a bottom-to-top stack-up...
Definition: lset.cpp:412
void openBlock()
open a JSON block: add &#39;{&#39; and increment indentation
wxArrayString m_GerberFileList
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
void openArrayBlock()
open a JSON array block: add &#39;[&#39; and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add &#39;}&#39; and &#39;,&#39;
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add &#39;]&#39; and &#39;,&#39;
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
std::vector< PCB_LAYER_ID > m_LayerId
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void GERBER_JOBFILE_WRITER::addJSONObject ( const wxString &  aParam)
inlineprivate

Add aParam to m_JSONbuffer, with suitable indentation.

Definition at line 195 of file gerber_jobfile_writer.h.

Referenced by addJSONDesignRules(), addJSONFilesAttributes(), addJSONGeneralSpecs(), addJSONHeader(), and addJSONMaterialStackup().

196  {
197  addIndent(); m_JSONbuffer << aParam;
198  }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::addJSONObject ( const char *  aParam)
inlineprivate

Definition at line 200 of file gerber_jobfile_writer.h.

201  {
202  addIndent(); m_JSONbuffer << aParam;
203  }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::closeArrayBlock ( )
inlineprivate

close a JSON array block: decrement indentation and add ']'

Definition at line 185 of file gerber_jobfile_writer.h.

185 { m_indent -= 2; addIndent(); m_JSONbuffer << "]\n"; }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::closeArrayBlockWithSep ( )
inlineprivate

close a JSON array block: decrement indentation and add ']' and ','

Definition at line 190 of file gerber_jobfile_writer.h.

Referenced by addJSONDesignRules(), addJSONFilesAttributes(), and addJSONMaterialStackup().

190 { m_indent -= 2; addIndent(); m_JSONbuffer << "],\n"; }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::closeBlock ( )
inlineprivate

close a JSON block: decrement indentation and add '}'

Definition at line 175 of file gerber_jobfile_writer.h.

Referenced by addJSONDesignRules(), and WriteJSONJobFile().

175 { m_indent -= 2; addIndent(); m_JSONbuffer << "}\n"; }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::closeBlockWithSep ( )
inlineprivate

close a JSON block: decrement indentation and add '}' and ','

Definition at line 180 of file gerber_jobfile_writer.h.

Referenced by addJSONDesignRules(), addJSONFilesAttributes(), addJSONGeneralSpecs(), addJSONHeader(), and addJSONMaterialStackup().

180 { m_indent -= 2; addIndent(); m_JSONbuffer << "},\n"; }
void addIndent()
add m_indent spaces in m_JSONbuffer
bool GERBER_JOBFILE_WRITER::CreateJobFile ( const wxString &  aFullFilename)

Creates a Gerber job file.

Parameters
aFullFilename= the full filename
Returns
true, or false if the file cannot be created

Definition at line 117 of file gerber_jobfile_writer.cpp.

References m_reporter, REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, and WriteJSONJobFile().

Referenced by DIALOG_PLOT::Plot().

118 {
119  bool success;
120  wxString msg;
121 
122  success = WriteJSONJobFile( aFullFilename );
123 
124  if( !success )
125  {
126  if( m_reporter )
127  {
128  msg.Printf( _( "Unable to create job file \"%s\"" ), aFullFilename );
130  }
131  }
132  else if( m_reporter )
133  {
134  msg.Printf( _( "Create Gerber job file \"%s\"" ), aFullFilename );
136  }
137 
138  return success;
139 }
bool WriteJSONJobFile(const wxString &aFullFilename)
Creates an Gerber job file in JSON format.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
enum ONSIDE GERBER_JOBFILE_WRITER::hasSilkLayers ( )
private
Returns
SIDE_NONE if no silk screen layer is in list SIDE_TOP if top silk screen layer is in list SIDE_BOTTOM if bottom silk screen layer is in list SIDE_BOTH if top and bottom silk screen layers are in list

Definition at line 58 of file gerber_jobfile_writer.cpp.

References B_SilkS, F_SilkS, JOBFILE_PARAMS::m_LayerId, m_params, SIDE_BOTTOM, SIDE_NONE, and SIDE_TOP.

59 {
60  int flag = SIDE_NONE;
61 
62  for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
63  {
64  if( m_params.m_LayerId[ii] == B_SilkS )
65  flag |= SIDE_BOTTOM;
66 
67  if( m_params.m_LayerId[ii] == F_SilkS )
68  flag |= SIDE_TOP;
69  }
70 
71  return (enum ONSIDE)flag;
72 }
std::vector< PCB_LAYER_ID > m_LayerId
enum ONSIDE GERBER_JOBFILE_WRITER::hasSolderMasks ( )
private
Returns
SIDE_NONE if no soldermask layer is in list SIDE_TOP if top soldermask layer is in list SIDE_BOTTOM if bottom soldermask layer is in list SIDE_BOTH if top and bottom soldermask layers are in list

Definition at line 75 of file gerber_jobfile_writer.cpp.

References B_Mask, F_Mask, JOBFILE_PARAMS::m_LayerId, m_params, SIDE_BOTTOM, SIDE_NONE, and SIDE_TOP.

76 {
77  int flag = SIDE_NONE;
78 
79  for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
80  {
81  if( m_params.m_LayerId[ii] == B_Mask )
82  flag |= SIDE_BOTTOM;
83 
84  if( m_params.m_LayerId[ii] == F_Mask )
85  flag |= SIDE_TOP;
86  }
87 
88  return (enum ONSIDE)flag;
89 }
std::vector< PCB_LAYER_ID > m_LayerId
void GERBER_JOBFILE_WRITER::openArrayBlock ( )
inlineprivate

open a JSON array block: add '[' and increment indentation

Definition at line 170 of file gerber_jobfile_writer.h.

Referenced by addJSONDesignRules(), addJSONFilesAttributes(), and addJSONMaterialStackup().

170 { addIndent(); m_JSONbuffer << "[\n"; m_indent += 2; }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::openBlock ( )
inlineprivate

open a JSON block: add '{' and increment indentation

Definition at line 165 of file gerber_jobfile_writer.h.

Referenced by addJSONDesignRules(), addJSONFilesAttributes(), addJSONGeneralSpecs(), addJSONHeader(), and addJSONMaterialStackup().

165 { addIndent(); m_JSONbuffer << "{\n"; m_indent += 2; }
void addIndent()
add m_indent spaces in m_JSONbuffer
void GERBER_JOBFILE_WRITER::removeJSONSepararator ( )
private

Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a
.

Definition at line 178 of file gerber_jobfile_writer.cpp.

References m_JSONbuffer.

Referenced by addJSONDesignRules(), addJSONFilesAttributes(), addJSONGeneralSpecs(), addJSONMaterialStackup(), and WriteJSONJobFile().

179 {
180  if( m_JSONbuffer.Last() == ',' )
181  {
182  m_JSONbuffer.RemoveLast();
183  return;
184  }
185 
186  if( m_JSONbuffer.Last() == '\n' )
187  {
188  m_JSONbuffer.RemoveLast();
189 
190  if( m_JSONbuffer.Last() == ',' )
191  m_JSONbuffer.RemoveLast();
192 
193  m_JSONbuffer.Append( '\n' );
194  }
195 }
const char * GERBER_JOBFILE_WRITER::sideKeyValue ( enum ONSIDE  aValue)
private
Returns
the key associated to sides used for some layers No TopOnly BotOnly Both

Definition at line 91 of file gerber_jobfile_writer.cpp.

References SIDE_BOTH, SIDE_BOTTOM, SIDE_NONE, and SIDE_TOP.

92 {
93  // return the key associated to sides used for some layers
94  // "No, TopOnly, BotOnly or Both"
95  const char* value = nullptr;
96 
97  switch( aValue )
98  {
99  case SIDE_NONE:
100  value = "No"; break;
101 
102  case SIDE_TOP:
103  value = "TopOnly"; break;
104 
105  case SIDE_BOTTOM:
106  value = "BotOnly"; break;
107 
108  case SIDE_BOTH:
109  value = "Both"; break;
110 
111  }
112 
113  return value;
114 }
bool GERBER_JOBFILE_WRITER::WriteJSONJobFile ( const wxString &  aFullFilename)

Creates an Gerber job file in JSON format.

Parameters
aFullFilename= the full filename
aParams= true for a NPTH file, false for a PTH file
Returns
true, or false if the file cannot be created

Definition at line 197 of file gerber_jobfile_writer.cpp.

References addJSONDesignRules(), addJSONFilesAttributes(), addJSONGeneralSpecs(), addJSONHeader(), addJSONMaterialStackup(), closeBlock(), dummy(), m_indent, m_JSONbuffer, removeJSONSepararator(), and TO_UTF8.

Referenced by CreateJobFile().

198 {
199  // Note: in Gerber job file, dimensions are in mm, and are floating numbers
200  FILE* jobFile = wxFopen( aFullFilename, "wt" );
201 
202  m_JSONbuffer.Empty();
203  m_indent = 0;
204 
205  if( jobFile == nullptr )
206  return false;
207 
209 
210  // output the job file header
211  addJSONHeader();
212 
213  // Add the General Specs
215 
216  // Job file support a few design rules:
218 
219  // output the gerber file list:
221 
222  // output the board stackup:
224 
225  // Close job file full block data
226  removeJSONSepararator(); // remove the last separator
227  closeBlock();
228 
229  fputs( TO_UTF8( m_JSONbuffer ), jobFile );
230 
231  fclose( jobFile );
232 
233  return true;
234 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
void addJSONHeader()
Add the job file header in JSON format to m_JSONbuffer.
void closeBlock()
close a JSON block: decrement indentation and add &#39;}&#39;
void addJSONFilesAttributes()
Add the Files Attributes section in JSON format to m_JSONbuffer.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
void addJSONDesignRules()
Add the Design Rules section in JSON format to m_JSONbuffer.
void addJSONMaterialStackup()
Add the Material Stackup section in JSON format to m_JSONbuffer This is the ordered list of stackup l...
void addJSONGeneralSpecs()
Add the General Specs in JSON format to m_JSONbuffer.

Member Data Documentation

double GERBER_JOBFILE_WRITER::m_conversionUnits
private
int GERBER_JOBFILE_WRITER::m_indent
private

Definition at line 211 of file gerber_jobfile_writer.h.

Referenced by GERBER_JOBFILE_WRITER(), and WriteJSONJobFile().

wxString GERBER_JOBFILE_WRITER::m_JSONbuffer
private

Definition at line 210 of file gerber_jobfile_writer.h.

Referenced by removeJSONSepararator(), and WriteJSONJobFile().

JOBFILE_PARAMS GERBER_JOBFILE_WRITER::m_params
private
BOARD* GERBER_JOBFILE_WRITER::m_pcb
private
REPORTER* GERBER_JOBFILE_WRITER::m_reporter
private

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