KiCad PCB EDA Suite
gerber_jobfile_writer.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 Jean_Pierre Charras <jp.charras at wanadoo.fr>
5  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <fctsys.h>
31 
32 #include <fstream>
33 #include <iomanip>
34 #include <vector>
35 
36 #include <build_version.h>
37 #include <pcb_edit_frame.h>
38 #include <plotter.h>
39 
40 #include <class_board.h>
41 #include <class_module.h>
42 #include <class_track.h>
43 #include <class_zone.h>
44 
46 #include <gbr_metadata.h>
47 #include <gerber_jobfile_writer.h>
48 #include <pcbnew.h>
49 #include <pcbplot.h>
50 #include <reporter.h>
52 
54 {
55  m_pcb = aPcb;
56  m_reporter = aReporter;
57  m_conversionUnits = 1.0 / IU_PER_MM; // Gerber units = mm
58 }
59 
60 std::string GERBER_JOBFILE_WRITER::formatStringFromUTF32( const wxString& aText )
61 {
62  std::string fmt_text; // the text after UTF32 to UTF8 conversion
63 
64  for( unsigned long letter : aText )
65  {
66  if( letter >= ' ' && letter <= 0x7F )
67  fmt_text += char( letter );
68  else
69  {
70  char buff[16];
71  sprintf( buff, "\\u%4.4lX", letter );
72  fmt_text += buff;
73  }
74  }
75  return fmt_text;
76 }
77 
78 
80 {
81  int flag = SIDE_NONE;
82 
83  for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
84  {
85  if( m_params.m_LayerId[ii] == B_SilkS )
86  flag |= SIDE_BOTTOM;
87 
88  if( m_params.m_LayerId[ii] == F_SilkS )
89  flag |= SIDE_TOP;
90  }
91 
92  return (enum ONSIDE) flag;
93 }
94 
95 
97 {
98  int flag = SIDE_NONE;
99 
100  for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
101  {
102  if( m_params.m_LayerId[ii] == B_Mask )
103  flag |= SIDE_BOTTOM;
104 
105  if( m_params.m_LayerId[ii] == F_Mask )
106  flag |= SIDE_TOP;
107  }
108 
109  return (enum ONSIDE) flag;
110 }
111 
112 const char* GERBER_JOBFILE_WRITER::sideKeyValue( enum ONSIDE aValue )
113 {
114  // return the key associated to sides used for some layers
115  // "No, TopOnly, BotOnly or Both"
116  const char* value = nullptr;
117 
118  switch( aValue )
119  {
120  case SIDE_NONE:
121  value = "No";
122  break;
123 
124  case SIDE_TOP:
125  value = "TopOnly";
126  break;
127 
128  case SIDE_BOTTOM:
129  value = "BotOnly";
130  break;
131 
132  case SIDE_BOTH:
133  value = "Both";
134  break;
135  }
136 
137  return value;
138 }
139 
140 
141 bool GERBER_JOBFILE_WRITER::CreateJobFile( const wxString& aFullFilename )
142 {
143  bool success;
144  wxString msg;
145 
146  success = WriteJSONJobFile( aFullFilename );
147 
148  if( !success )
149  {
150  if( m_reporter )
151  {
152  msg.Printf( _( "Unable to create job file \"%s\"" ), aFullFilename );
154  }
155  }
156  else if( m_reporter )
157  {
158  msg.Printf( _( "Create Gerber job file \"%s\"" ), aFullFilename );
160  }
161 
162  return success;
163 }
164 
165 
167 {
168  wxString text;
169 
170  m_json["Header"] = {
171  {
172  "GenerationSoftware",
173  {
174  { "Vendor", "KiCad" },
175  { "Application", "Pcbnew" },
176  { "Version", GetBuildVersion() }
177  }
178  },
179  {
180  // The attribute value must conform to the full version of the ISO 8601
181  // date and time format, including time and time zone.
183  }
184  };
185 }
186 
187 
188 bool GERBER_JOBFILE_WRITER::WriteJSONJobFile( const wxString& aFullFilename )
189 {
190  // Note: in Gerber job file, dimensions are in mm, and are floating numbers
191  std::ofstream file( aFullFilename.ToUTF8() );
192 
194 
195  m_json = nlohmann::ordered_json( {} );
196 
197  // output the job file header
198  addJSONHeader();
199 
200  // Add the General Specs
202 
203  // Job file support a few design rules:
205 
206  // output the gerber file list:
208 
209  // output the board stackup:
211 
212  file << std::setw( 2 ) << m_json << std::endl;
213 
214  return true;
215 }
216 
217 
218 double GERBER_JOBFILE_WRITER::mapValue( double aUiValue )
219 {
220  // A helper function to convert aUiValue in Json units (mm) and to have
221  // 4 digits in Json in mantissa when using %g to print it
222  // i.e. displays values truncated in 0.1 microns.
223  // This is enough for a Json file
224  char buffer[128];
225  sprintf( buffer, "%.4f", aUiValue * m_conversionUnits );
226 
227  long double output;
228  sscanf( buffer, "%Lg", &output );
229 
230  return output;
231 
232 }
233 
234 
236 {
237  m_json["GeneralSpecs"] = nlohmann::ordered_json( {} );
238  m_json["GeneralSpecs"]["ProjectId"] = nlohmann::ordered_json( {} );
239 
240  // Creates the ProjectId. Format is (from Gerber file format doc):
241  // ProjectId,<project id>,<project GUID>,<revision id>*%
242  // <project id> is the name of the project, restricted to basic ASCII symbols only,
243  // and comma not accepted
244  // All illegal chars will be replaced by underscore
245  // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
246  //
247  // <project GUID> is a string which is an unique id of a project.
248  // However Kicad does not handle such a project GUID, so it is built from the board name
249  wxFileName fn = m_pcb->GetFileName();
250  wxString msg = fn.GetFullName();
251 
252  // Build a <project GUID>, from the board name
253  wxString guid = GbrMakeProjectGUIDfromString( msg );
254 
255  // build the <project id> string: this is the board short filename (without ext)
256  // and all non ASCII chars are replaced by '_', to be compatible with .gbr files.
257  msg = fn.GetName();
258 
259  // build the <rec> string. All non ASCII chars and comma are replaced by '_'
260  wxString rev = m_pcb->GetTitleBlock().GetRevision();
261 
262  if( rev.IsEmpty() )
263  rev = wxT( "rev?" );
264 
265  m_json["GeneralSpecs"]["ProjectId"]["Name"] = msg.ToAscii();
266  m_json["GeneralSpecs"]["ProjectId"]["GUID"] = guid;
267  m_json["GeneralSpecs"]["ProjectId"]["Revision"] = rev.ToAscii();
268 
269  // output the bord size in mm:
271 
272  m_json["GeneralSpecs"]["Size"]["X"] = mapValue( brect.GetWidth() );
273  m_json["GeneralSpecs"]["Size"]["Y"] = mapValue( brect.GetHeight() );
274 
275 
276  // Add some data to the JSON header, GeneralSpecs:
277  // number of copper layers
278  m_json["GeneralSpecs"]["LayerNumber"] = m_pcb->GetCopperLayerCount();
279 
280  // Board thickness
281  m_json["GeneralSpecs"]["BoardThickness"] =
283 
284  // Copper finish
286 
287  if( !brd_stackup.m_FinishType.IsEmpty() )
288  m_json["GeneralSpecs"]["Finish"] = brd_stackup.m_FinishType;
289 
290  if( brd_stackup.m_CastellatedPads )
291  m_json["GeneralSpecs"]["Castellated"] = true;
292 
293  if( brd_stackup.m_EdgePlating )
294  m_json["GeneralSpecs"]["EdgePlating"] = true;
295 
296  if( brd_stackup.m_EdgeConnectorConstraints )
297  {
298  m_json["GeneralSpecs"]["EdgeConnector"] = true;
299 
300  m_json["GeneralSpecs"]["EdgeConnectorBevelled"] =
301  ( brd_stackup.m_EdgeConnectorConstraints == BS_EDGE_CONNECTOR_BEVELLED );
302  }
303 
304 #if 0 // Not yet in use
305  /* The board type according to IPC-2221. There are six primary board types:
306  - Type 1 - Single-sided
307  - Type 2 - Double-sided
308  - Type 3 - Multilayer, TH components only
309  - Type 4 - Multilayer, with TH, blind and/or buried vias.
310  - Type 5 - Multilayer metal-core board, TH components only
311  - Type 6 - Multilayer metal-core
312  */
313  m_json["GeneralSpecs"]["IPC-2221-Type"] = 4;
314 
315  /* Via protection: key words:
316  Ia Tented - Single-sided
317  Ib Tented - Double-sided
318  IIa Tented and Covered - Single-sided
319  IIb Tented and Covered - Double-sided
320  IIIa Plugged - Single-sided
321  IIIb Plugged - Double-sided
322  IVa Plugged and Covered - Single-sided
323  IVb Plugged and Covered - Double-sided
324  V Filled (fully plugged)
325  VI Filled and Covered
326  VIII Filled and Capped
327  None...No protection
328  */
329  m_json["GeneralSpecs"]["ViaProtection"] = "Ib";
330 #endif
331 }
332 
333 
335 {
336  // Add the Files Attributes section in JSON format to m_JSONbuffer
337  m_json["FilesAttributes"] = nlohmann::ordered_json::array();
338 
339  for( unsigned ii = 0; ii < m_params.m_GerberFileList.GetCount(); ii++ )
340  {
341  wxString& name = m_params.m_GerberFileList[ii];
342  PCB_LAYER_ID layer = m_params.m_LayerId[ii];
343  wxString gbr_layer_id;
344  bool skip_file = false; // true to skip files which should not be in job file
345  const char* polarity = "Positive";
346 
347  nlohmann::ordered_json file_json;
348 
349  if( layer <= B_Cu )
350  {
351  gbr_layer_id = "Copper,L";
352 
353  if( layer == B_Cu )
354  gbr_layer_id << m_pcb->GetCopperLayerCount();
355  else
356  gbr_layer_id << layer + 1;
357 
358  gbr_layer_id << ",";
359 
360  if( layer == B_Cu )
361  gbr_layer_id << "Bot";
362  else if( layer == F_Cu )
363  gbr_layer_id << "Top";
364  else
365  gbr_layer_id << "Inr";
366  }
367 
368  else
369  {
370  switch( layer )
371  {
372  case B_Adhes:
373  gbr_layer_id = "Glue,Bot";
374  break;
375  case F_Adhes:
376  gbr_layer_id = "Glue,Top";
377  break;
378 
379  case B_Paste:
380  gbr_layer_id = "SolderPaste,Bot";
381  break;
382  case F_Paste:
383  gbr_layer_id = "SolderPaste,Top";
384  break;
385 
386  case B_SilkS:
387  gbr_layer_id = "Legend,Bot";
388  break;
389  case F_SilkS:
390  gbr_layer_id = "Legend,Top";
391  break;
392 
393  case B_Mask:
394  gbr_layer_id = "SolderMask,Bot";
395  polarity = "Negative";
396  break;
397  case F_Mask:
398  gbr_layer_id = "SolderMask,Top";
399  polarity = "Negative";
400  break;
401 
402  case Edge_Cuts:
403  gbr_layer_id = "Profile";
404  break;
405 
406  case B_Fab:
407  gbr_layer_id = "AssemblyDrawing,Bot";
408  break;
409  case F_Fab:
410  gbr_layer_id = "AssemblyDrawing,Top";
411  break;
412 
413  case Dwgs_User:
414  case Cmts_User:
415  case Eco1_User:
416  case Eco2_User:
417  case Margin:
418  case B_CrtYd:
419  case F_CrtYd:
420  skip_file = true;
421  break;
422 
423  default:
424  skip_file = true;
425  m_reporter->Report( "Unexpected layer id in job file", RPT_SEVERITY_ERROR );
426  break;
427  }
428  }
429 
430  if( !skip_file )
431  {
432  // name can contain non ASCII7 chars.
433  // Ensure the name is JSON compatible.
434  std::string strname = formatStringFromUTF32( name );
435 
436  file_json["Path"] = strname.c_str();
437  file_json["FileFunction"] = gbr_layer_id;
438  file_json["FilePolarity"] = polarity;
439 
440  m_json["FilesAttributes"] += file_json;
441  }
442  }
443 }
444 
445 
447 {
448  // Add the Design Rules section in JSON format to m_JSONbuffer
449  // Job file support a few design rules:
450  const BOARD_DESIGN_SETTINGS& dsnSettings = m_pcb->GetDesignSettings();
451  NETCLASS defaultNC = *dsnSettings.GetDefault();
452  int minclearanceOuter = defaultNC.GetClearance();
453  bool hasInnerLayers = m_pcb->GetCopperLayerCount() > 2;
454 
455  // Search a smaller clearance in other net classes, if any.
456  for( const std::pair<const wxString, NETCLASSPTR>& entry : dsnSettings.GetNetClasses() )
457  minclearanceOuter = std::min( minclearanceOuter, entry.second->GetClearance() );
458 
459  // job file knows different clearance types.
460  // Kicad knows only one clearance for pads and tracks
461  int minclearance_track2track = minclearanceOuter;
462 
463  // However, pads can have a specific clearance defined for a pad or a footprint,
464  // and min clearance can be dependent on layers.
465  // Search for a minimal pad clearance:
466  int minPadClearanceOuter = defaultNC.GetClearance();
467  int minPadClearanceInner = defaultNC.GetClearance();
468 
469  for( MODULE* module : m_pcb->Modules() )
470  {
471  for( D_PAD* pad : module->Pads() )
472  {
473  for( PCB_LAYER_ID layer : pad->GetLayerSet().Seq() )
474  {
475  int padClearance = pad->GetClearance( layer );
476 
477  if( layer == B_Cu || layer == F_Cu )
478  minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
479  else
480  minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
481  }
482  }
483  }
484 
485  m_json["DesignRules"] = { {
486  { "Layers", "Outer" },
487  { "PadToPad", mapValue( minPadClearanceOuter ) },
488  { "PadToTrack", mapValue( minPadClearanceOuter ) },
489  { "TrackToTrack", mapValue( minclearance_track2track ) }
490  } };
491 
492  // Until this is changed in Kicad, use the same value for internal tracks
493  int minclearanceInner = minclearanceOuter;
494 
495  // Output the minimal track width
496  int mintrackWidthOuter = INT_MAX;
497  int mintrackWidthInner = INT_MAX;
498 
499  for( TRACK* track : m_pcb->Tracks() )
500  {
501  if( track->Type() == PCB_VIA_T )
502  continue;
503 
504  if( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
505  mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
506  else
507  mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
508  }
509 
510  if( mintrackWidthOuter != INT_MAX )
511  m_json["DesignRules"][0]["MinLineWidth"] = mapValue( mintrackWidthOuter );
512 
513  // Output the minimal zone to xx clearance
514  // Note: zones can have a zone clearance set to 0
515  // if happens, the actual zone clearance is the clearance of its class
516  minclearanceOuter = INT_MAX;
517  minclearanceInner = INT_MAX;
518 
519  for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
520  {
521  ZONE_CONTAINER* zone = m_pcb->GetArea( ii );
522 
523  if( zone->GetIsKeepout() || !zone->IsOnCopperLayer() )
524  continue;
525 
526  for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
527  {
528  int zclerance = zone->GetClearance( layer );
529 
530  if( layer == B_Cu || layer == F_Cu )
531  minclearanceOuter = std::min( minclearanceOuter, zclerance );
532  else
533  minclearanceInner = std::min( minclearanceInner, zclerance );
534  }
535  }
536 
537  if( minclearanceOuter != INT_MAX )
538  m_json["DesignRules"][0]["TrackToRegion"] = mapValue( minclearanceOuter );
539 
540  if( minclearanceOuter != INT_MAX )
541  m_json["DesignRules"][0]["RegionToRegion"] = mapValue( minclearanceOuter );
542 
543  if( hasInnerLayers )
544  {
545  m_json["DesignRules"] += nlohmann::ordered_json( {
546  { "Layers", "Inner" },
547  { "PadToPad", mapValue( minPadClearanceInner ) },
548  { "PadToTrack", mapValue( minPadClearanceInner ) },
549  { "TrackToTrack", mapValue( minclearance_track2track ) }
550  } );
551 
552  if( mintrackWidthInner != INT_MAX )
553  m_json["DesignRules"][1]["MinLineWidth"] = mapValue( mintrackWidthInner );
554 
555  if( minclearanceInner != INT_MAX )
556  m_json["DesignRules"][1]["TrackToRegion"] = mapValue( minclearanceInner );
557 
558  if( minclearanceInner != INT_MAX )
559  m_json["DesignRules"][1]["RegionToRegion"] = mapValue( minclearanceInner );
560  }
561 }
562 
563 
565 {
566  // Add the Material Stackup section in JSON format to m_JSONbuffer
567  m_json["MaterialStackup"] = nlohmann::ordered_json::array();
568 
569  // Build the candidates list:
570  LSET maskLayer;
572 
573  // Ensure brd_stackup is up to date (i.e. no change made by SynchronizeWithBoard() )
574  bool uptodate = not brd_stackup.SynchronizeWithBoard( &m_pcb->GetDesignSettings() );
575 
576  if( !uptodate && m_pcb->GetDesignSettings().m_HasStackup )
577  m_reporter->Report( _( "Board stackup settings not up to date\n"
578  "Please fix the stackup" ),
580 
581  PCB_LAYER_ID last_copper_layer = F_Cu;
582 
583  // Generate the list (top to bottom):
584  for( int ii = 0; ii < brd_stackup.GetCount(); ++ii )
585  {
586  BOARD_STACKUP_ITEM* item = brd_stackup.GetStackupLayer( ii );
587 
588  int sub_layer_count =
589  item->GetType() == BS_ITEM_TYPE_DIELECTRIC ? item->GetSublayersCount() : 1;
590 
591  for( int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
592  {
593  // layer thickness is always in mm
594  double thickness = mapValue( item->GetThickness( sub_idx ) );
595  wxString layer_type;
596  std::string layer_name; // for comment
597 
598  nlohmann::ordered_json layer_json;
599 
600  switch( item->GetType() )
601  {
602  case BS_ITEM_TYPE_COPPER:
603  layer_type = "Copper";
604  layer_name = formatStringFromUTF32( m_pcb->GetLayerName( item->GetBrdLayerId() ) );
605  last_copper_layer = item->GetBrdLayerId();
606  break;
607 
609  layer_type = "Legend";
610  layer_name = formatStringFromUTF32( item->GetTypeName() );
611  break;
612 
614  layer_type = "SolderMask";
615  layer_name = formatStringFromUTF32( item->GetTypeName() );
616  break;
617 
619  layer_type = "SolderPaste";
620  layer_name = formatStringFromUTF32( item->GetTypeName() );
621  break;
622 
624  layer_type = "Dielectric";
625  // The option core or prepreg is not added here, as it creates constraints
626  // in build process, not necessary wanted.
627  if( sub_layer_count > 1 )
628  {
629  layer_name =
630  formatStringFromUTF32( wxString::Format( "dielectric layer %d - %d/%d",
631  item->GetDielectricLayerId(), sub_idx + 1, sub_layer_count ) );
632  }
633  else
635  "dielectric layer %d", item->GetDielectricLayerId() ) );
636  break;
637 
638  default:
639  break;
640  }
641 
642  layer_json["Type"] = layer_type;
643 
644  if( item->IsColorEditable() && uptodate )
645  {
646  if( IsPrmSpecified( item->GetColor() ) )
647  {
648  wxString colorName = item->GetColor();
649 
650  if( colorName.StartsWith( "#" ) ) // This is a user defined color.
651  {
652  // In job file a color can be given by its RGB values (0...255)
653  wxColor color( colorName );
654  colorName.Printf( "R%dG%dB%d", color.Red(), color.Green(), color.Blue() );
655  }
656 
657  layer_json["Color"] = colorName;
658  }
659  }
660 
661  if( item->IsThicknessEditable() && uptodate )
662  layer_json["Thickness"] = thickness;
663 
664  if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
665  {
666  if( item->HasMaterialValue() )
667  {
668  layer_json["Material"] = item->GetMaterial( sub_idx );
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  // Generate Epsilon R if > 1.0 (value <= 1.0 means not specified: it is not
676  // a possible value
677  if( item->GetEpsilonR() > 1.0 )
678  layer_json["DielectricConstant"] = item->FormatEpsilonR( sub_idx );
679 
680  // Generate LossTangent > 0.0 (value <= 0.0 means not specified: it is not
681  // a possible value
682  if( item->GetLossTangent() > 0.0 )
683  layer_json["LossTangent"] = item->FormatLossTangent( sub_idx );
684  }
685  }
686 
687  PCB_LAYER_ID next_copper_layer = ( PCB_LAYER_ID )( last_copper_layer + 1 );
688 
689  // If the next_copper_layer is the last copper layer, the next layer id is B_Cu
690  if( next_copper_layer >= m_pcb->GetCopperLayerCount() - 1 )
691  next_copper_layer = B_Cu;
692 
693  wxString subLayerName;
694 
695  if( sub_layer_count > 1 )
696  subLayerName.Printf( " (%d/%d)", sub_idx + 1, sub_layer_count );
697 
698  wxString name = wxString::Format( "%s/%s%s",
699  formatStringFromUTF32( m_pcb->GetLayerName( last_copper_layer ) ),
700  formatStringFromUTF32( m_pcb->GetLayerName( next_copper_layer ) ),
701  subLayerName );
702 
703  layer_json["Name"] = name;
704 
705  // Add a comment ("Notes"):
706  wxString note;
707 
708  note << wxString::Format( "Type: %s", layer_name.c_str() );
709 
710  note << wxString::Format( " (from %s to %s)",
711  formatStringFromUTF32( m_pcb->GetLayerName( last_copper_layer ) ),
712  formatStringFromUTF32( m_pcb->GetLayerName( next_copper_layer ) ) );
713 
714  layer_json["Notes"] = note;
715  }
716  else if( item->GetType() == BS_ITEM_TYPE_SOLDERMASK
717  || item->GetType() == BS_ITEM_TYPE_SILKSCREEN )
718  {
719  if( item->HasMaterialValue() )
720  {
721  layer_json["Material"] = item->GetMaterial();
722 
723  // These constrains are only written if the board has impedance controlled tracks.
724  // If the board is not impedance controlled, they are useless.
725  // Do not add constrains that create more expensive boards.
726  if( brd_stackup.m_HasDielectricConstrains )
727  {
728  // Generate Epsilon R if > 1.0 (value <= 1.0 means not specified: it is not
729  // a possible value
730  if( item->GetEpsilonR() > 1.0 )
731  layer_json["DielectricConstant"] = item->FormatEpsilonR();
732 
733  // Generate LossTangent > 0.0 (value <= 0.0 means not specified: it is not
734  // a possible value
735  if( item->GetLossTangent() > 0.0 )
736  layer_json["LossTangent"] = item->FormatLossTangent();
737  }
738  }
739 
740  layer_json["Name"] = layer_name.c_str();
741  }
742  else
743  {
744  layer_json["Name"] = layer_name.c_str();
745  }
746 
747  m_json["MaterialStackup"].insert( m_json["MaterialStackup"].end(), layer_json );
748  }
749  }
750 }
BOARD_STACKUP_ITEM_TYPE GetType() const
nlohmann::ordered_json m_json
std::string formatStringFromUTF32(const wxString &aText)
A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a e...
a class to handle special data (items attributes) during plot.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
BOARD_STACKUP_ITEM * GetStackupLayer(int aIndex)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
bool HasMaterialValue(int aDielectricSubLayer=0) const
double mapValue(double aUiValue)
A helper function to convert a double in Pcbnew internal units to a JSON double value (in mm),...
bool CreateJobFile(const wxString &aFullFilename)
Creates a Gerber job file.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
this class manage the layers needed to make a physical board they are solder mask,...
static constexpr double IU_PER_MM
Mock up a conversion function.
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:824
void addJSONHeader()
Add the job file header in JSON format to m_JSONbuffer.
bool IsPrmSpecified(const wxString &aPrmValue)
int color
Definition: DXF_plotter.cpp:61
int GetWidth() const
Definition: eda_rect.h:119
const char * sideKeyValue(enum ONSIDE aValue)
wxString GetColor() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:577
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
int GetClearance(wxString *aSource=nullptr) const
Definition: netclass.h:158
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:377
const wxString & GetFileName() const
Definition: class_board.h:262
Classes used to generate a Gerber job file in JSON.
void addJSONFilesAttributes()
Add the Files Attributes section in JSON format to m_JSONbuffer.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
double GetLossTangent(int aDielectricSubLayer=0) const
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
Board plot function definition file.
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_zone.cpp:288
wxArrayString m_GerberFileList
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
virtual int GetClearance(PCB_LAYER_ID aLayer, BOARD_ITEM *aItem=nullptr, wxString *aSource=nullptr) const
Function GetClearance returns the clearance in internal units.
BOARD_STACKUP & GetStackupDescriptor()
PCB_LAYER_ID
A quick note on layer IDs:
bool IsThicknessEditable() const
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:958
LSET is a set of PCB_LAYER_IDs.
MODULES & Modules()
Definition: class_board.h:273
wxString GetBuildVersion()
Get the full KiCad version string.
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,...
int GetThickness(int aDielectricSubLayer=0) const
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:49
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString FormatEpsilonR(int aDielectricSubLayer=0) const
Definition of file extensions used in Kicad.
wxString GetTypeName() const
wxString FormatLossTangent(int aDielectricSubLayer=0) const
NETCLASSES & GetNetClasses() const
this class manage one layer needed to make a physical board it can be a solder mask,...
int GetHeight() const
Definition: eda_rect.h:120
bool WriteJSONJobFile(const wxString &aFullFilename)
Creates an Gerber job file in JSON format.
PCB_LAYER_ID GetBrdLayerId() const
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:701
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:604
const char * name
Definition: DXF_plotter.cpp:60
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 GetDielectricLayerId() const
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:184
#define _(s)
Definition: 3d_actions.cpp:33
void addJSONDesignRules()
Add the Design Rules section in JSON format to m_JSONbuffer.
int GetCopperLayerCount() const
Function GetCopperLayerCount.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
NETCLASS * GetDefault() const
Function GetDefault.
std::vector< PCB_LAYER_ID > m_LayerId
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:923
bool m_HasStackup
Set to true if the board has a stackup management.
void addJSONMaterialStackup()
Add the Material Stackup section in JSON format to m_JSONbuffer This is the ordered list of stackup l...
wxString GetMaterial(int aDielectricSubLayer=0) const
void addJSONGeneralSpecs()
Add the General Specs in JSON format to m_JSONbuffer.
TRACKS & Tracks()
Definition: class_board.h:264
bool IsOnCopperLayer() const override
Function IsOnCopperLayer.
Definition: class_zone.cpp:218
GERBER_JOBFILE_WRITER(BOARD *aPcb, REPORTER *aReporter=nullptr)
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.