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)
 
std::string formatStringFromUTF32 (const wxString &aText)
 A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a escaped unicode sequence of 4 hexa). More...
 

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::GERBER_JOBFILE_WRITER ( BOARD aPcb,
REPORTER aReporter = nullptr 
)

Definition at line 51 of file gerber_jobfile_writer.cpp.

52 {
53  m_pcb = aPcb;
54  m_reporter = aReporter;
55  m_conversionUnits = 1.0 / IU_PER_MM; // Gerber units = mm
56  m_indent = 0;
57 }

References m_conversionUnits, m_indent, m_pcb, and m_reporter.

◆ ~GERBER_JOBFILE_WRITER()

virtual GERBER_JOBFILE_WRITER::~GERBER_JOBFILE_WRITER ( )
inlinevirtual

Definition at line 74 of file gerber_jobfile_writer.h.

75  {
76  }

Member Function Documentation

◆ AddGbrFile()

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.

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

References JOBFILE_PARAMS::m_GerberFileList, JOBFILE_PARAMS::m_LayerId, and m_params.

Referenced by DIALOG_PLOT::Plot().

◆ addIndent()

void GERBER_JOBFILE_WRITER::addIndent ( )
inlineprivate

add m_indent spaces in m_JSONbuffer

Definition at line 160 of file gerber_jobfile_writer.h.

References m_indent, and m_JSONbuffer.

Referenced by addJSONObject(), closeArrayBlock(), closeArrayBlockWithSep(), closeBlock(), closeBlockWithSep(), openArrayBlock(), and openBlock().

◆ addJSONDesignRules()

void GERBER_JOBFILE_WRITER::addJSONDesignRules ( )
private

Add the Design Rules section in JSON format to m_JSONbuffer.

Definition at line 459 of file gerber_jobfile_writer.cpp.

460 {
461  // Add the Design Rules section in JSON format to m_JSONbuffer
462  // Job file support a few design rules:
463  const BOARD_DESIGN_SETTINGS& dsnSettings = m_pcb->GetDesignSettings();
464  NETCLASS defaultNC = *dsnSettings.GetDefault();
465  int minclearanceOuter = defaultNC.GetClearance();
466  bool hasInnerLayers = m_pcb->GetCopperLayerCount() > 2;
467 
468  // Search a smaller clearance in other net classes, if any.
469  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
470  it != dsnSettings.m_NetClasses.end();
471  ++it )
472  {
473  NETCLASS netclass = *it->second;
474  minclearanceOuter = std::min( minclearanceOuter, netclass.GetClearance() );
475  }
476 
477  // job file knows different clearance types.
478  // Kicad knows only one clearance for pads and tracks
479  int minclearance_track2track = minclearanceOuter;
480 
481  // However, pads can have a specific clearance defined for a pad or a footprint,
482  // and min clearance can be dependent on layers.
483  // Search for a minimal pad clearance:
484  int minPadClearanceOuter = defaultNC.GetClearance();
485  int minPadClearanceInner = defaultNC.GetClearance();
486 
487  for( MODULE* module : m_pcb->Modules() )
488  {
489  for( auto& pad : module->Pads() )
490  {
491  if( ( pad->GetLayerSet() & LSET::InternalCuMask() ).any() )
492  minPadClearanceInner = std::min( minPadClearanceInner, pad->GetClearance() );
493 
494  if( ( pad->GetLayerSet() & LSET::ExternalCuMask() ).any() )
495  minPadClearanceOuter = std::min( minPadClearanceOuter, pad->GetClearance() );
496  }
497  }
498 
499 
500  addJSONObject( "\"DesignRules\":\n" );
501  openArrayBlock();
502 
503  openBlock();
504  addJSONObject( "\"Layers\": \"Outer\",\n" );
505  addJSONObject( wxString::Format( "\"PadToPad\": %.3f,\n", minPadClearanceOuter*m_conversionUnits ) );
506  addJSONObject( wxString::Format( "\"PadToTrack\": %.3f,\n", minPadClearanceOuter*m_conversionUnits ) );
507  addJSONObject( wxString::Format( "\"TrackToTrack\": %.3f,\n", minclearance_track2track*m_conversionUnits ) );
508 
509  // Until this is changed in Kicad, use the same value for internal tracks
510  int minclearanceInner = minclearanceOuter;
511 
512  // Output the minimal track width
513  int mintrackWidthOuter = INT_MAX;
514  int mintrackWidthInner = INT_MAX;
515 
516  for( TRACK* track : m_pcb->Tracks() )
517  {
518  if( track->Type() == PCB_VIA_T )
519  continue;
520 
521  if( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
522  mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
523  else
524  mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
525  }
526 
527  if( mintrackWidthOuter != INT_MAX )
528  addJSONObject( wxString::Format( "\"MinLineWidth\": %.3f,\n",
529  mintrackWidthOuter*m_conversionUnits ) );
530 
531  // Output the minimal zone to xx clearance
532  // Note: zones can have a zone clearance set to 0
533  // if happens, the actual zone clearance is the clearance of its class
534  minclearanceOuter = INT_MAX;
535  minclearanceInner = INT_MAX;
536 
537  for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
538  {
539  ZONE_CONTAINER* zone = m_pcb->GetArea( ii );
540 
541  if( zone->GetIsKeepout() || !zone->IsOnCopperLayer() )
542  continue;
543 
544  int zclerance = zone->GetClearance();
545 
546  if( zone->GetLayer() == B_Cu || zone->GetLayer() == F_Cu )
547  minclearanceOuter = std::min( minclearanceOuter, zclerance );
548  else
549  minclearanceInner = std::min( minclearanceInner, zclerance );
550  }
551 
552  if( minclearanceOuter != INT_MAX )
553  addJSONObject( wxString::Format( "\"TrackToRegion\": %.3f,\n",
554  minclearanceOuter*m_conversionUnits ) );
555 
556  if( minclearanceOuter != INT_MAX )
557  addJSONObject( wxString::Format( "\"RegionToRegion\": %.3f,\n",
558  minclearanceOuter*m_conversionUnits ) );
559 
560  removeJSONSepararator(); // remove the last separator
561 
562  if( !hasInnerLayers )
563  closeBlock();
564  else
566 
567 
568  if( hasInnerLayers )
569  {
570  openBlock();
571  addJSONObject( "\"Layers\": \"Inner\",\n" );
572  addJSONObject( wxString::Format( "\"PadToPad\": %.3f,\n", minPadClearanceInner*m_conversionUnits ) );
573  addJSONObject( wxString::Format( "\"PadToTrack\": %.3f,\n", minPadClearanceInner*m_conversionUnits ) );
574  addJSONObject( wxString::Format( "\"TrackToTrack\": %.3f,\n", minclearance_track2track*m_conversionUnits ) );
575 
576  if( mintrackWidthInner != INT_MAX )
577  addJSONObject( wxString::Format( "\"MinLineWidth\": %.3f,\n", mintrackWidthInner*m_conversionUnits ) );
578 
579  if( minclearanceInner != INT_MAX )
580  addJSONObject( wxString::Format( "\"TrackToRegion\": %.3f,\n", minclearanceInner*m_conversionUnits ) );
581 
582  if( minclearanceInner != INT_MAX )
583  addJSONObject( wxString::Format( "\"RegionToRegion\": %.3f,\n", minclearanceInner*m_conversionUnits ) );
584 
585  removeJSONSepararator(); // remove the last separator
586  closeBlock();
587  }
588 
589  // Close DesignRules
591 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:178
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
iterator end()
Definition: netclass.h:249
void closeBlock()
close a JSON block: decrement indentation and add '}'
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:616
void openBlock()
open a JSON block: add '{' and increment indentation
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:955
iterator begin()
Definition: netclass.h:248
MODULES & Modules()
Definition: class_board.h:236
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:636
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:706
void openArrayBlock()
open a JSON array block: add '[' and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add '}' and ','
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:621
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add ']' and ','
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
NETCLASSPTR GetDefault() const
Function GetDefault.
int GetClearance() const
Definition: netclass.h:162
int GetCopperLayerCount() const
Function GetCopperLayerCount.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:926
TRACKS & Tracks()
Definition: class_board.h:227
bool IsOnCopperLayer() const override
Function IsOnCopperLayer.
Definition: class_zone.cpp:184
#define min(a, b)
Definition: auxiliary.h:85
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

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().

◆ addJSONFilesAttributes()

void GERBER_JOBFILE_WRITER::addJSONFilesAttributes ( )
private

Add the Files Attributes section in JSON format to m_JSONbuffer.

Definition at line 358 of file gerber_jobfile_writer.cpp.

359 {
360  // Add the Files Attributes section in JSON format to m_JSONbuffer
361  addJSONObject( "\"FilesAttributes\":\n" );
362  openArrayBlock();
363 
364  for( unsigned ii = 0; ii < m_params.m_GerberFileList.GetCount(); ii ++ )
365  {
366  wxString& name = m_params.m_GerberFileList[ii];
367  PCB_LAYER_ID layer = m_params.m_LayerId[ii];
368  wxString gbr_layer_id;
369  bool skip_file = false; // true to skip files which should not be in job file
370  const char* polarity = "Positive";
371 
372  if( layer <= B_Cu )
373  {
374  gbr_layer_id = "Copper,L";
375 
376  if( layer == B_Cu )
377  gbr_layer_id << m_pcb->GetCopperLayerCount();
378  else
379  gbr_layer_id << layer+1;
380 
381  gbr_layer_id << ",";
382 
383  if( layer == B_Cu )
384  gbr_layer_id << "Bot";
385  else if( layer == F_Cu )
386  gbr_layer_id << "Top";
387  else
388  gbr_layer_id << "Inr";
389  }
390 
391  else
392  {
393  switch( layer )
394  {
395  case B_Adhes:
396  gbr_layer_id = "Glue,Bot"; break;
397  case F_Adhes:
398  gbr_layer_id = "Glue,Top"; break;
399 
400  case B_Paste:
401  gbr_layer_id = "SolderPaste,Bot"; break;
402  case F_Paste:
403  gbr_layer_id = "SolderPaste,Top"; break;
404 
405  case B_SilkS:
406  gbr_layer_id = "Legend,Bot"; break;
407  case F_SilkS:
408  gbr_layer_id = "Legend,Top"; break;
409 
410  case B_Mask:
411  gbr_layer_id = "SolderMask,Bot"; polarity = "Negative"; break;
412  case F_Mask:
413  gbr_layer_id = "SolderMask,Top"; polarity = "Negative"; break;
414 
415  case Edge_Cuts:
416  gbr_layer_id = "Profile"; break;
417 
418  case B_Fab:
419  gbr_layer_id = "AssemblyDrawing,Bot"; break;
420  case F_Fab:
421  gbr_layer_id = "AssemblyDrawing,Top"; break;
422 
423  case Dwgs_User:
424  case Cmts_User:
425  case Eco1_User:
426  case Eco2_User:
427  case Margin:
428  case B_CrtYd:
429  case F_CrtYd:
430  skip_file = true; break;
431 
432  default:
433  skip_file = true;
434  m_reporter->Report( "Unexpected layer id in job file",
436  break;
437  }
438  }
439 
440  if( !skip_file )
441  {
442  // name can contain non ASCII7 chars.
443  // Ensure the name is JSON compatible.
444  std::string strname = formatStringFromUTF32( name );
445 
446  openBlock();
447  addJSONObject( wxString::Format( "\"Path\": \"%s\",\n", strname.c_str() ) );
448  addJSONObject( wxString::Format( "\"FileFunction\": \"%s\",\n", gbr_layer_id ) ),
449  addJSONObject( wxString::Format( "\"FilePolarity\": \"%s\"\n", polarity ) );
451  }
452  }
453  // Close the file list:
454  removeJSONSepararator(); // remove the last separator
456 }
std::string formatStringFromUTF32(const wxString &aText)
A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a e...
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 addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
void openBlock()
open a JSON block: add '{' and increment indentation
wxArrayString m_GerberFileList
PCB_LAYER_ID
A quick note on layer IDs:
void openArrayBlock()
open a JSON array block: add '[' and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add '}' and ','
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add ']' and ','
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
int GetCopperLayerCount() const
Function GetCopperLayerCount.
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.

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(), formatStringFromUTF32(), 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().

◆ addJSONGeneralSpecs()

void GERBER_JOBFILE_WRITER::addJSONGeneralSpecs ( )
private

Add the General Specs in JSON format to m_JSONbuffer.

Definition at line 247 of file gerber_jobfile_writer.cpp.

248 {
249  addJSONObject( "\"GeneralSpecs\":\n" );
250  openBlock();
251 
252  addJSONObject( "\"ProjectId\":\n" );
253  openBlock();
254 
255  // Creates the ProjectId. Format is (from Gerber file format doc):
256  // ProjectId,<project id>,<project GUID>,<revision id>*%
257  // <project id> is the name of the project, restricted to basic ASCII symbols only,
258  // and comma not accepted
259  // All illegal chars will be replaced by underscore
260  // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
261  //
262  // <project GUID> is a string which is an unique id of a project.
263  // However Kicad does not handle such a project GUID, so it is built from the board name
264  wxFileName fn = m_pcb->GetFileName();
265  wxString msg = fn.GetFullName();
266 
267  // Build a <project GUID>, from the board name
268  wxString guid = GbrMakeProjectGUIDfromString( msg );
269 
270  // build the <project id> string: this is the board short filename (without ext)
271  // and all non ASCII chars are replaced by '_', to be compatible with .gbr files.
272  msg = fn.GetName();
273 
274  // build the <rec> string. All non ASCII chars and comma are replaced by '_'
275  wxString rev = m_pcb->GetTitleBlock().GetRevision();
276 
277  if( rev.IsEmpty() )
278  rev = wxT( "rev?" );
279 
280  addJSONObject( wxString::Format( "\"Name\": \"%s\",\n", msg.ToAscii() ) );
281  addJSONObject( wxString::Format( "\"GUID\": \"%s\",\n", guid ) );
282  addJSONObject( wxString::Format( "\"Revision\": \"%s\"\n", rev.ToAscii() ) );
283 
285 
286  // output the bord size in mm:
288  addJSONObject( "\"Size\":\n" );
289  openBlock();
290 
291  addJSONObject( wxString::Format( "\"X\": %.3f,\n", brect.GetWidth()*m_conversionUnits ) );
292  addJSONObject( wxString::Format( "\"Y\": %.3f\n", brect.GetHeight()*m_conversionUnits ) );
294 
295  // Add some data to the JSON header, GeneralSpecs:
296  // number of copper layers
297  addJSONObject( wxString::Format( "\"LayerNumber\": %d,\n", m_pcb->GetCopperLayerCount() ) );
298 
299  // Board thickness
300  addJSONObject( wxString::Format( "\"BoardThickness\": %.3f,\n",
302 
303 
304  // Copper finish
306 
307  if( !brd_stackup.m_FinishType.IsEmpty() )
308  addJSONObject( wxString::Format( "\"Finish\": \"%s\",\n", brd_stackup.m_FinishType ) );
309 
310  if( brd_stackup.m_CastellatedPads )
311  addJSONObject( "\"Castellated\": \"true\",\n" );
312 
313  if( brd_stackup.m_EdgePlating )
314  addJSONObject( "\"EdgePlating\": \"true\",\n" );
315 
316  if( brd_stackup.m_EdgeConnectorConstraints )
317  {
318  addJSONObject( "\"EdgeConnector\": \"true\",\n" );
319 
321  addJSONObject( "\"EdgeConnectorBevelled\": \"true\",\n" );
322  else
323  addJSONObject( "\"EdgeConnectorBevelled\": \"false\",\n" );
324  }
325 
326 #if 0 // Not yet in use
327  /* The board type according to IPC-2221. There are six primary board types:
328  - Type 1 - Single-sided
329  - Type 2 - Double-sided
330  - Type 3 - Multilayer, TH components only
331  - Type 4 - Multilayer, with TH, blind and/or buried vias.
332  - Type 5 - Multilayer metal-core board, TH components only
333  - Type 6 - Multilayer metal-core
334  */
335  addJSONObject( wxString::Format( "\"IPC-2221-Type\": \"%d\",\n", 4 ) );
336 
337  /* Via protection: key words:
338  Ia Tented - Single-sided
339  Ib Tented - Double-sided
340  IIa Tented and Covered - Single-sided
341  IIb Tented and Covered - Double-sided
342  IIIa Plugged - Single-sided
343  IIIb Plugged - Double-sided
344  IVa Plugged and Covered - Single-sided
345  IVb Plugged and Covered - Double-sided
346  V Filled (fully plugged)
347  VI Filled and Covered
348  VIII Filled and Capped
349  None...No protection
350  */
351  addJSONObject( wxString::Format( "\"ViaProtection\": \"%s\",\n", "Ib" ) );
352 #endif
355 }
this class manage the layers needed to make a physical board they are solder mask,...
void removeJSONSepararator()
Remove the comma if it is the last char in m_JSONbuffer, or the previous char if the last char is a ...
wxString m_FinishType
The name of external copper finish.
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:804
bool m_EdgePlating
True if the edge board is plated.
BS_EDGE_CONNECTOR_CONSTRAINTS m_EdgeConnectorConstraints
If the board has edge connector cards, some constrains can be specifed in job file: BS_EDGE_CONNECTOR...
int GetWidth() const
Definition: eda_rect.h:117
bool m_CastellatedPads
True if castellated pads exist.
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
const wxString & GetFileName() const
Definition: class_board.h:225
void openBlock()
open a JSON block: add '{' and increment indentation
BOARD_STACKUP & GetStackupDescriptor()
const wxString & GetRevision() const
Definition: title_block.h:89
wxString GbrMakeProjectGUIDfromString(wxString &aText)
A helper function to build a project GUID using format RFC4122 Version 1 or 4 from the project name,...
void closeBlockWithSep()
close a JSON block: decrement indentation and add '}' and ','
int GetHeight() const
Definition: eda_rect.h:118
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:561
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
int GetCopperLayerCount() const
Function GetCopperLayerCount.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

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

Referenced by WriteJSONJobFile().

◆ addJSONHeader()

void GERBER_JOBFILE_WRITER::addJSONHeader ( )
private

Add the job file header in JSON format to m_JSONbuffer.

Definition at line 162 of file gerber_jobfile_writer.cpp.

163 {
164  wxString text;
165  openBlock();
166  addJSONObject( "\"Header\":\n" );
167  openBlock();
168 
169  // Creates the GenerationSoftware
170  addJSONObject( "\"GenerationSoftware\":\n" );
171  openBlock();
172  addJSONObject( "\"Vendor\": \"KiCad\",\n" );
173  addJSONObject( "\"Application\": \"Pcbnew\",\n" );
174  text.Printf( "\"Version\": \"%s\"\n", GetBuildVersion() );
175  addJSONObject( text );
177 
178  // creates the CreationDate attribute:
179  // The attribute value must conform to the full version of the ISO 8601
180  // date and time format, including time and time zone.
182  addJSONObject( text );
183 
185 }
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
void openBlock()
open a JSON block: add '{' and increment indentation
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void closeBlockWithSep()
close a JSON block: decrement indentation and add '}' and ','

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

Referenced by WriteJSONJobFile().

◆ addJSONMaterialStackup()

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 594 of file gerber_jobfile_writer.cpp.

595 {
596  // Add the Material Stackup section in JSON format to m_JSONbuffer
597  addJSONObject( "\"MaterialStackup\":\n" );
598  openArrayBlock();
599 
600  // Build the candidates list:
601  LSET maskLayer;
603 
604  // Ensure brd_stackup is up to date (i.e. no change made by SynchronizeWithBoard() )
605  bool uptodate = not brd_stackup.SynchronizeWithBoard( &m_pcb->GetDesignSettings() );
606 
607  if( !uptodate && m_pcb->GetDesignSettings().m_HasStackup )
608  m_reporter->Report( _( "Board stackup settings not up to date\n"
609  "Please fix the stackup" ), REPORTER::RPT_ERROR );
610 
611  PCB_LAYER_ID last_copper_layer = F_Cu;
612 
613  // Generate the list (top to bottom):
614  for( int ii = 0; ii < brd_stackup.GetCount(); ++ii )
615  {
616  BOARD_STACKUP_ITEM* item = brd_stackup.GetStackupLayer( ii );
617  double thickness = item->m_Thickness*m_conversionUnits; // layer thickness is always in mm
618  wxString layer_type;
619  std::string layer_name; // for comment
620 
621  switch( item->m_Type )
622  {
623  case BS_ITEM_TYPE_COPPER:
624  layer_type = "Copper";
625  layer_name = formatStringFromUTF32( m_pcb->GetLayerName( item->m_LayerId ) );
626  last_copper_layer = item->m_LayerId;
627  break;
628 
630  layer_type = "Legend";
631  layer_name = formatStringFromUTF32( item->m_TypeName );
632  break;
633 
635  layer_type = "SolderMask";
636  layer_name = formatStringFromUTF32( item->m_TypeName );
637  break;
638 
640  layer_type = "SolderPaste";
641  layer_name = formatStringFromUTF32( item->m_TypeName );
642  break;
643 
645  layer_type = "Dielectric";
646  layer_name = formatStringFromUTF32( wxString::Format( "dielectric layer %d (%s)",
647  item->m_DielectricLayerId, item->m_TypeName ) );
648  break;
649 
650  default:
651  break;
652  }
653 
654  openBlock();
655  addJSONObject( wxString::Format( "\"Type\": \"%s\",\n", layer_type ) );
656 
657  if( item->IsColorEditable() && uptodate )
658  {
659  if( !item->m_Color.IsEmpty() && item->m_Color != NOT_SPECIFIED )
660  addJSONObject( wxString::Format( "\"Color\": \"%s\",\n", item->m_Color ) );
661  }
662 
663  if( item->IsThicknessEditable() && uptodate )
664  addJSONObject( wxString::Format( "\"Thickness\": %.3f,\n", thickness ) );
665 
666  if( item->m_Type == BS_ITEM_TYPE_DIELECTRIC )
667  {
668  addJSONObject( wxString::Format( "\"Material\": \"%s\",\n", item->m_Material ) );
669 
670  // These constrains are only written if the board has impedance controlled tracks.
671  // If the board is not impedance controlled, they are useless.
672  // Do not add constrains that create more expensive boards.
673  if( brd_stackup.m_HasDielectricConstrains )
674  {
675  addJSONObject( wxString::Format( "\"DielectricConstant\": %.1f,\n", item->m_EpsilonR ) );
676  addJSONObject( wxString::Format( "\"LossTangent\": %f,\n", item->m_LossTangent ) );
677  }
678 
679  PCB_LAYER_ID next_copper_layer = (PCB_LAYER_ID) (last_copper_layer+1);
680 
681  // If the next_copper_layer is the last copper layer, the next layer id is B_Cu
682  if( next_copper_layer >= m_pcb->GetCopperLayerCount()-1 )
683  next_copper_layer = B_Cu;
684 
685  // Add a comment ("Notes"):
686  wxString note = "\"Notes\": ";
687 
688  if( uptodate ) // We can add the dielectric variant ("core" "prepreg" ...):
689  note << wxString::Format( " \"Type: %s", layer_name.c_str() );
690 
691  note << wxString::Format( " \"(from %s to %s)\"\n",
692  formatStringFromUTF32( m_pcb->GetLayerName( last_copper_layer ) ),
693  formatStringFromUTF32( m_pcb->GetLayerName( next_copper_layer ) ) );
694 
695  addJSONObject( note );
696  }
697  else
698  {
699  addJSONObject( wxString::Format( "\"Notes\": \"Layer: %s\",\n", layer_name.c_str() ) );
700  }
701 
704  }
705 
708 }
std::string formatStringFromUTF32(const wxString &aText)
A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a e...
double m_EpsilonR
the physical layer thickness in internal units
BOARD_STACKUP_ITEM * GetStackupLayer(int aIndex)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
this class manage the layers needed to make a physical board they are solder mask,...
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 addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
int m_Thickness
mainly for silkscreen and solder mask
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
wxString m_Material
type name of layer (copper, silk screen, core, prepreg ...)
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
void openBlock()
open a JSON block: add '{' and increment indentation
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
BOARD_STACKUP & GetStackupDescriptor()
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
PCB_LAYER_ID m_LayerId
For dielectric (and solder mask) the dielectric loss.
void openArrayBlock()
open a JSON array block: add '[' and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add '}' and ','
this class manage one layer needed to make a physical board it can be a solder mask,...
#define _(s)
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add ']' and ','
wxString m_Color
the "layer" id for dielectric layers, from 1 (top) to 32 (bottom)
double m_LossTangent
For dielectric (and solder mask) the dielectric constant.
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
int GetCopperLayerCount() const
Function GetCopperLayerCount.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
bool m_HasStackup
Set to true if the board has a stackup management.
BOARD_STACKUP_ITEM_TYPE m_Type
#define NOT_SPECIFIED
int m_DielectricLayerId
type of material (has meaning only for dielectric

References _, addJSONObject(), B_Cu, BS_ITEM_TYPE_COPPER, BS_ITEM_TYPE_DIELECTRIC, BS_ITEM_TYPE_SILKSCREEN, BS_ITEM_TYPE_SOLDERMASK, BS_ITEM_TYPE_SOLDERPASTE, closeArrayBlockWithSep(), closeBlockWithSep(), F_Cu, Format(), formatStringFromUTF32(), BOARD::GetCopperLayerCount(), BOARD_STACKUP::GetCount(), BOARD::GetDesignSettings(), BOARD::GetLayerName(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), BOARD_STACKUP::GetStackupLayer(), BOARD_STACKUP_ITEM::IsColorEditable(), BOARD_STACKUP_ITEM::IsThicknessEditable(), BOARD_STACKUP_ITEM::m_Color, m_conversionUnits, BOARD_STACKUP_ITEM::m_DielectricLayerId, BOARD_STACKUP_ITEM::m_EpsilonR, BOARD_STACKUP::m_HasDielectricConstrains, BOARD_DESIGN_SETTINGS::m_HasStackup, BOARD_STACKUP_ITEM::m_LayerId, BOARD_STACKUP_ITEM::m_LossTangent, BOARD_STACKUP_ITEM::m_Material, m_pcb, m_reporter, BOARD_STACKUP_ITEM::m_Thickness, BOARD_STACKUP_ITEM::m_Type, BOARD_STACKUP_ITEM::m_TypeName, NOT_SPECIFIED, openArrayBlock(), openBlock(), removeJSONSepararator(), REPORTER::Report(), REPORTER::RPT_ERROR, and BOARD_STACKUP::SynchronizeWithBoard().

Referenced by WriteJSONJobFile().

◆ addJSONObject() [1/2]

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.

196  {
197  addIndent(); m_JSONbuffer << aParam;
198  }
void addIndent()
add m_indent spaces in m_JSONbuffer

References addIndent(), and m_JSONbuffer.

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

◆ addJSONObject() [2/2]

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

References addIndent(), and m_JSONbuffer.

◆ closeArrayBlock()

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

References addIndent(), m_indent, and m_JSONbuffer.

◆ closeArrayBlockWithSep()

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.

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

References addIndent(), m_indent, and m_JSONbuffer.

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

◆ closeBlock()

void GERBER_JOBFILE_WRITER::closeBlock ( )
inlineprivate

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

Definition at line 175 of file gerber_jobfile_writer.h.

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

References addIndent(), m_indent, and m_JSONbuffer.

Referenced by addJSONDesignRules(), and WriteJSONJobFile().

◆ closeBlockWithSep()

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.

180 { m_indent -= 2; addIndent(); m_JSONbuffer << "},\n"; }
void addIndent()
add m_indent spaces in m_JSONbuffer

References addIndent(), m_indent, and m_JSONbuffer.

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

◆ CreateJobFile()

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 137 of file gerber_jobfile_writer.cpp.

138 {
139  bool success;
140  wxString msg;
141 
142  success = WriteJSONJobFile( aFullFilename );
143 
144  if( !success )
145  {
146  if( m_reporter )
147  {
148  msg.Printf( _( "Unable to create job file \"%s\"" ), aFullFilename );
150  }
151  }
152  else if( m_reporter )
153  {
154  msg.Printf( _( "Create Gerber job file \"%s\"" ), aFullFilename );
156  }
157 
158  return success;
159 }
#define _(s)
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.

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

Referenced by DIALOG_PLOT::Plot().

◆ formatStringFromUTF32()

std::string GERBER_JOBFILE_WRITER::formatStringFromUTF32 ( const wxString &  aText)
private

A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a escaped unicode sequence of 4 hexa).

Definition at line 59 of file gerber_jobfile_writer.cpp.

60 {
61  std::string fmt_text; // the text after UTF32 to UTF8 conversion
62 
63  for( unsigned long letter: aText )
64  {
65  if( letter >= ' ' && letter <= 0x7F )
66  fmt_text += char( letter );
67  else
68  {
69  char buff[16];
70  sprintf( buff, "\\u%4.4lX", letter );
71  fmt_text += buff;
72  }
73  }
74  return fmt_text;
75 }

Referenced by addJSONFilesAttributes(), and addJSONMaterialStackup().

◆ hasSilkLayers()

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 78 of file gerber_jobfile_writer.cpp.

79 {
80  int flag = SIDE_NONE;
81 
82  for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
83  {
84  if( m_params.m_LayerId[ii] == B_SilkS )
85  flag |= SIDE_BOTTOM;
86 
87  if( m_params.m_LayerId[ii] == F_SilkS )
88  flag |= SIDE_TOP;
89  }
90 
91  return (enum ONSIDE)flag;
92 }
std::vector< PCB_LAYER_ID > m_LayerId

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

◆ hasSolderMasks()

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 95 of file gerber_jobfile_writer.cpp.

96 {
97  int flag = SIDE_NONE;
98 
99  for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
100  {
101  if( m_params.m_LayerId[ii] == B_Mask )
102  flag |= SIDE_BOTTOM;
103 
104  if( m_params.m_LayerId[ii] == F_Mask )
105  flag |= SIDE_TOP;
106  }
107 
108  return (enum ONSIDE)flag;
109 }
std::vector< PCB_LAYER_ID > m_LayerId

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

◆ openArrayBlock()

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.

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

References addIndent(), m_indent, and m_JSONbuffer.

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

◆ openBlock()

void GERBER_JOBFILE_WRITER::openBlock ( )
inlineprivate

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

Definition at line 165 of file gerber_jobfile_writer.h.

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

References addIndent(), m_indent, and m_JSONbuffer.

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

◆ removeJSONSepararator()

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 188 of file gerber_jobfile_writer.cpp.

189 {
190  if( m_JSONbuffer.Last() == ',' )
191  {
192  m_JSONbuffer.RemoveLast();
193  return;
194  }
195 
196  if( m_JSONbuffer.Last() == '\n' )
197  {
198  m_JSONbuffer.RemoveLast();
199 
200  if( m_JSONbuffer.Last() == ',' )
201  m_JSONbuffer.RemoveLast();
202 
203  m_JSONbuffer.Append( '\n' );
204  }
205 }

References m_JSONbuffer.

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

◆ sideKeyValue()

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 111 of file gerber_jobfile_writer.cpp.

112 {
113  // return the key associated to sides used for some layers
114  // "No, TopOnly, BotOnly or Both"
115  const char* value = nullptr;
116 
117  switch( aValue )
118  {
119  case SIDE_NONE:
120  value = "No"; break;
121 
122  case SIDE_TOP:
123  value = "TopOnly"; break;
124 
125  case SIDE_BOTTOM:
126  value = "BotOnly"; break;
127 
128  case SIDE_BOTH:
129  value = "Both"; break;
130 
131  }
132 
133  return value;
134 }

References SIDE_BOTH, SIDE_BOTTOM, SIDE_NONE, and SIDE_TOP.

◆ WriteJSONJobFile()

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 207 of file gerber_jobfile_writer.cpp.

208 {
209  // Note: in Gerber job file, dimensions are in mm, and are floating numbers
210  FILE* jobFile = wxFopen( aFullFilename, "wt" );
211 
212  m_JSONbuffer.Empty();
213  m_indent = 0;
214 
215  if( jobFile == nullptr )
216  return false;
217 
219 
220  // output the job file header
221  addJSONHeader();
222 
223  // Add the General Specs
225 
226  // Job file support a few design rules:
228 
229  // output the gerber file list:
231 
232  // output the board stackup:
234 
235  // Close job file full block data
236  removeJSONSepararator(); // remove the last separator
237  closeBlock();
238 
239  fputs( TO_UTF8( m_JSONbuffer ), jobFile );
240 
241  fclose( jobFile );
242 
243  return true;
244 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:175
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 '}'
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:48
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
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.

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

Referenced by CreateJobFile().

Member Data Documentation

◆ m_conversionUnits

double GERBER_JOBFILE_WRITER::m_conversionUnits
private

◆ m_indent

◆ m_JSONbuffer

◆ m_params

JOBFILE_PARAMS GERBER_JOBFILE_WRITER::m_params
private

◆ m_pcb

BOARD* GERBER_JOBFILE_WRITER::m_pcb
private

◆ m_reporter

REPORTER* GERBER_JOBFILE_WRITER::m_reporter
private

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