KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2022 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 <fstream>
31#include <iomanip>
32#include <vector>
33
34#include <build_version.h>
35#include <locale_io.h>
36#include <pcb_edit_frame.h>
37#include <plotters/plotter.h>
38
39#include <board.h>
41#include <footprint.h>
42#include <pad.h>
43#include <pcb_track.h>
44#include <zone.h>
45
47#include <gbr_metadata.h>
49#include <pcbplot.h>
50#include <reporter.h>
52
53
55{
56 m_pcb = aPcb;
57 m_reporter = aReporter;
58 m_conversionUnits = 1.0 / pcbIUScale.IU_PER_MM; // Gerber units = mm
59}
60
61std::string GERBER_JOBFILE_WRITER::formatStringFromUTF32( const wxString& aText )
62{
63 std::string fmt_text; // the text after UTF32 to UTF8 conversion
64 fmt_text = aText.utf8_string();
65
66 return fmt_text;
67}
68
69
71{
72 int flag = SIDE_NONE;
73
74 for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
75 {
76 if( m_params.m_LayerId[ii] == B_SilkS )
78
79 if( m_params.m_LayerId[ii] == F_SilkS )
80 flag |= SIDE_TOP;
81 }
82
83 return (enum ONSIDE) flag;
84}
85
86
88{
89 int flag = SIDE_NONE;
90
91 for( unsigned ii = 0; ii < m_params.m_LayerId.size(); ii++ )
92 {
93 if( m_params.m_LayerId[ii] == B_Mask )
95
96 if( m_params.m_LayerId[ii] == F_Mask )
97 flag |= SIDE_TOP;
98 }
99
100 return (enum ONSIDE) flag;
101}
102
104{
105 // return the key associated to sides used for some layers
106 // "No, TopOnly, BotOnly or Both"
107 const char* value = nullptr;
108
109 switch( aValue )
110 {
111 case SIDE_NONE:
112 value = "No";
113 break;
114
115 case SIDE_TOP:
116 value = "TopOnly";
117 break;
118
119 case SIDE_BOTTOM:
120 value = "BotOnly";
121 break;
122
123 case SIDE_BOTH:
124 value = "Both";
125 break;
126 }
127
128 return value;
129}
130
131
132bool GERBER_JOBFILE_WRITER::CreateJobFile( const wxString& aFullFilename )
133{
134 bool success;
135 wxString msg;
136
137 success = WriteJSONJobFile( aFullFilename );
138
139 if( !success )
140 {
141 if( m_reporter )
142 {
143 msg.Printf( _( "Failed to create file '%s'." ), aFullFilename );
145 }
146 }
147 else if( m_reporter )
148 {
149 msg.Printf( _( "Created Gerber job file '%s'." ), aFullFilename );
151 }
152
153 return success;
154}
155
156
158{
159 m_json["Header"] = {
160 {
161 "GenerationSoftware",
162 {
163 { "Vendor", "KiCad" },
164 { "Application", "Pcbnew" },
165 { "Version", GetBuildVersion() }
166 }
167 },
168 {
169 // The attribute value must conform to the full version of the ISO 8601
170 // date and time format, including time and time zone.
172 }
173 };
174}
175
176
177bool GERBER_JOBFILE_WRITER::WriteJSONJobFile( const wxString& aFullFilename )
178{
179 // Note: in Gerber job file, dimensions are in mm, and are floating numbers
180 std::ofstream file( aFullFilename.ToUTF8() );
181
183
184 m_json = nlohmann::ordered_json( {} );
185
186 // output the job file header
188
189 // Add the General Specs
191
192 // Job file support a few design rules:
194
195 // output the gerber file list:
197
198 // output the board stackup:
200
201 file << std::setw( 2 ) << m_json << std::endl;
202
203 return true;
204}
205
206
207double GERBER_JOBFILE_WRITER::mapValue( double aUiValue )
208{
209 // A helper function to convert aUiValue in Json units (mm) and to have
210 // 4 digits in Json in mantissa when using %g to print it
211 // i.e. displays values truncated in 0.1 microns.
212 // This is enough for a Json file
213 char buffer[128];
214 std::snprintf( buffer, sizeof( buffer ), "%.4f", aUiValue * m_conversionUnits );
215
216 long double output;
217 sscanf( buffer, "%Lg", &output );
218
219 return output;
220
221}
222
223
225{
226 m_json["GeneralSpecs"] = nlohmann::ordered_json( {} );
227 m_json["GeneralSpecs"]["ProjectId"] = nlohmann::ordered_json( {} );
228
229 // Creates the ProjectId. Format is (from Gerber file format doc):
230 // ProjectId,<project id>,<project GUID>,<revision id>*%
231 // <project id> is the name of the project, restricted to basic ASCII symbols only,
232 // and comma not accepted
233 // All illegal chars will be replaced by underscore
234 // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
235 //
236 // <project GUID> is a string which is an unique id of a project.
237 // However Kicad does not handle such a project GUID, so it is built from the board name
238 wxFileName fn = m_pcb->GetFileName();
239 wxString msg = fn.GetFullName();
240
241 // Build a <project GUID>, from the board name
242 wxString guid = GbrMakeProjectGUIDfromString( msg );
243
244 // build the <project id> string: this is the board short filename (without ext)
245 // and in UTF8 format.
246 msg = fn.GetName();
247
248 // build the <rev> string. All non ASCII chars are in UTF8 form
250
251 if( rev.IsEmpty() )
252 rev = wxT( "rev?" );
253
254 m_json["GeneralSpecs"]["ProjectId"]["Name"] = msg.utf8_string().c_str();
255 m_json["GeneralSpecs"]["ProjectId"]["GUID"] = guid;
256 m_json["GeneralSpecs"]["ProjectId"]["Revision"] = rev.utf8_string().c_str();
257
258 // output the board size in mm:
260
261 m_json["GeneralSpecs"]["Size"]["X"] = mapValue( brect.GetWidth() );
262 m_json["GeneralSpecs"]["Size"]["Y"] = mapValue( brect.GetHeight() );
263
264
265 // Add some data to the JSON header, GeneralSpecs:
266 // number of copper layers
267 m_json["GeneralSpecs"]["LayerNumber"] = m_pcb->GetCopperLayerCount();
268
269 // Board thickness
270 m_json["GeneralSpecs"]["BoardThickness"] =
272
273 // Copper finish
275
276 if( !brd_stackup.m_FinishType.IsEmpty() )
277 m_json["GeneralSpecs"]["Finish"] = brd_stackup.m_FinishType;
278
279 if( brd_stackup.m_HasDielectricConstrains )
280 m_json["GeneralSpecs"]["ImpedanceControlled"] = true;
281
282 if( brd_stackup.m_CastellatedPads )
283 m_json["GeneralSpecs"]["Castellated"] = true;
284
285 if( brd_stackup.m_EdgePlating )
286 m_json["GeneralSpecs"]["EdgePlating"] = true;
287
288 if( brd_stackup.m_EdgeConnectorConstraints )
289 {
290 m_json["GeneralSpecs"]["EdgeConnector"] = true;
291
292 m_json["GeneralSpecs"]["EdgeConnectorBevelled"] =
294 }
295
296#if 0 // Not yet in use
297 /* The board type according to IPC-2221. There are six primary board types:
298 - Type 1 - Single-sided
299 - Type 2 - Double-sided
300 - Type 3 - Multilayer, TH components only
301 - Type 4 - Multilayer, with TH, blind and/or buried vias.
302 - Type 5 - Multilayer metal-core board, TH components only
303 - Type 6 - Multilayer metal-core
304 */
305 m_json["GeneralSpecs"]["IPC-2221-Type"] = 4;
306
307 /* Via protection: key words:
308 Ia Tented - Single-sided
309 Ib Tented - Double-sided
310 IIa Tented and Covered - Single-sided
311 IIb Tented and Covered - Double-sided
312 IIIa Plugged - Single-sided
313 IIIb Plugged - Double-sided
314 IVa Plugged and Covered - Single-sided
315 IVb Plugged and Covered - Double-sided
316 V Filled (fully plugged)
317 VI Filled and Covered
318 VIII Filled and Capped
319 None...No protection
320 */
321 m_json["GeneralSpecs"]["ViaProtection"] = "Ib";
322#endif
323}
324
325
327{
328 // Add the Files Attributes section in JSON format to m_JSONbuffer
329 m_json["FilesAttributes"] = nlohmann::ordered_json::array();
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 nlohmann::ordered_json file_json;
340
341 if( layer <= B_Cu )
342 {
343 gbr_layer_id = wxT( "Copper,L" );
344
345 if( layer == B_Cu )
346 gbr_layer_id << m_pcb->GetCopperLayerCount();
347 else
348 gbr_layer_id << layer + 1;
349
350 gbr_layer_id << wxT( "," );
351
352 if( layer == B_Cu )
353 gbr_layer_id << wxT( "Bot" );
354 else if( layer == F_Cu )
355 gbr_layer_id << wxT( "Top" );
356 else
357 gbr_layer_id << wxT( "Inr" );
358 }
359
360 else
361 {
362 switch( layer )
363 {
364 case B_Adhes:
365 gbr_layer_id = wxT( "Glue,Bot" );
366 break;
367 case F_Adhes:
368 gbr_layer_id = wxT( "Glue,Top" );
369 break;
370
371 case B_Paste:
372 gbr_layer_id = wxT( "SolderPaste,Bot" );
373 break;
374 case F_Paste:
375 gbr_layer_id = wxT( "SolderPaste,Top" );
376 break;
377
378 case B_SilkS:
379 gbr_layer_id = wxT( "Legend,Bot" );
380 break;
381 case F_SilkS:
382 gbr_layer_id = wxT( "Legend,Top" );
383 break;
384
385 case B_Mask:
386 gbr_layer_id = wxT( "SolderMask,Bot" );
387 polarity = "Negative";
388 break;
389 case F_Mask:
390 gbr_layer_id = wxT( "SolderMask,Top" );
391 polarity = "Negative";
392 break;
393
394 case Edge_Cuts:
395 gbr_layer_id = wxT( "Profile" );
396 break;
397
398 case B_Fab:
399 gbr_layer_id = wxT( "AssemblyDrawing,Bot" );
400 break;
401 case F_Fab:
402 gbr_layer_id = wxT( "AssemblyDrawing,Top" );
403 break;
404
405 case Margin:
406 case B_CrtYd:
407 case F_CrtYd:
408 skip_file = true;
409 break;
410
411 case Dwgs_User:
412 case Cmts_User:
413 case Eco1_User:
414 case Eco2_User:
415 case User_1:
416 case User_2:
417 case User_3:
418 case User_4:
419 case User_5:
420 case User_6:
421 case User_7:
422 case User_8:
423 case User_9:
424 gbr_layer_id = wxT( "Other,User" );
425 break;
426
427 default:
428 skip_file = true;
429
430 if( m_reporter )
431 m_reporter->Report( wxT( "Unexpected layer id in job file" ), RPT_SEVERITY_ERROR );
432
433 break;
434 }
435 }
436
437 if( !skip_file )
438 {
439 // name can contain non ASCII7 chars.
440 // Ensure the name is JSON compatible.
441 std::string strname = formatStringFromUTF32( name );
442
443 file_json["Path"] = strname.c_str();
444 file_json["FileFunction"] = gbr_layer_id;
445 file_json["FilePolarity"] = polarity;
446
447 m_json["FilesAttributes"] += file_json;
448 }
449 }
450}
451
452
454{
455 // Add the Design Rules section in JSON format to m_JSONbuffer
456 // Job file support a few design rules:
457 std::shared_ptr<NET_SETTINGS>& netSettings = m_pcb->GetDesignSettings().m_NetSettings;
458
459 int minclearanceOuter = netSettings->m_DefaultNetClass->GetClearance();
460 bool hasInnerLayers = m_pcb->GetCopperLayerCount() > 2;
461
462 // Search a smaller clearance in other net classes, if any.
463 for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
464 minclearanceOuter = std::min( minclearanceOuter, netclass->GetClearance() );
465
466 // job file knows different clearance types.
467 // Kicad knows only one clearance for pads and tracks
468 int minclearance_track2track = minclearanceOuter;
469
470 // However, pads can have a specific clearance defined for a pad or a footprint,
471 // and min clearance can be dependent on layers.
472 // Search for a minimal pad clearance:
473 int minPadClearanceOuter = netSettings->m_DefaultNetClass->GetClearance();
474 int minPadClearanceInner = netSettings->m_DefaultNetClass->GetClearance();
475
476 for( FOOTPRINT* footprint : m_pcb->Footprints() )
477 {
478 for( PAD* pad : footprint->Pads() )
479 {
480 for( PCB_LAYER_ID layer : pad->GetLayerSet().Seq() )
481 {
482 int padClearance = pad->GetOwnClearance( layer );
483
484 if( layer == B_Cu || layer == F_Cu )
485 minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
486 else
487 minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
488 }
489 }
490 }
491
492 m_json["DesignRules"] = { {
493 { "Layers", "Outer" },
494 { "PadToPad", mapValue( minPadClearanceOuter ) },
495 { "PadToTrack", mapValue( minPadClearanceOuter ) },
496 { "TrackToTrack", mapValue( minclearance_track2track ) }
497 } };
498
499 // Until this is changed in Kicad, use the same value for internal tracks
500 int minclearanceInner = minclearanceOuter;
501
502 // Output the minimal track width
503 int mintrackWidthOuter = INT_MAX;
504 int mintrackWidthInner = INT_MAX;
505
506 for( PCB_TRACK* track : m_pcb->Tracks() )
507 {
508 if( track->Type() == PCB_VIA_T )
509 continue;
510
511 if( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
512 mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
513 else
514 mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
515 }
516
517 if( mintrackWidthOuter != INT_MAX )
518 m_json["DesignRules"][0]["MinLineWidth"] = mapValue( mintrackWidthOuter );
519
520 // Output the minimal zone to xx clearance
521 // Note: zones can have a zone clearance set to 0
522 // if happens, the actual zone clearance is the clearance of its class
523 minclearanceOuter = INT_MAX;
524 minclearanceInner = INT_MAX;
525
526 for( ZONE* zone : m_pcb->Zones() )
527 {
528 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
529 continue;
530
531 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
532 {
533 int zclerance = zone->GetOwnClearance( layer );
534
535 if( layer == B_Cu || layer == F_Cu )
536 minclearanceOuter = std::min( minclearanceOuter, zclerance );
537 else
538 minclearanceInner = std::min( minclearanceInner, zclerance );
539 }
540 }
541
542 if( minclearanceOuter != INT_MAX )
543 m_json["DesignRules"][0]["TrackToRegion"] = mapValue( minclearanceOuter );
544
545 if( minclearanceOuter != INT_MAX )
546 m_json["DesignRules"][0]["RegionToRegion"] = mapValue( minclearanceOuter );
547
548 if( hasInnerLayers )
549 {
550 m_json["DesignRules"] += nlohmann::ordered_json( {
551 { "Layers", "Inner" },
552 { "PadToPad", mapValue( minPadClearanceInner ) },
553 { "PadToTrack", mapValue( minPadClearanceInner ) },
554 { "TrackToTrack", mapValue( minclearance_track2track ) }
555 } );
556
557 if( mintrackWidthInner != INT_MAX )
558 m_json["DesignRules"][1]["MinLineWidth"] = mapValue( mintrackWidthInner );
559
560 if( minclearanceInner != INT_MAX )
561 m_json["DesignRules"][1]["TrackToRegion"] = mapValue( minclearanceInner );
562
563 if( minclearanceInner != INT_MAX )
564 m_json["DesignRules"][1]["RegionToRegion"] = mapValue( minclearanceInner );
565 }
566}
567
568
570{
571 // Add the Material Stackup section in JSON format to m_JSONbuffer
572 m_json["MaterialStackup"] = nlohmann::ordered_json::array();
573
574 // Build the candidates list:
575 LSET maskLayer;
577
578 // Ensure brd_stackup is up to date (i.e. no change made by SynchronizeWithBoard() )
579 bool uptodate = not brd_stackup.SynchronizeWithBoard( &m_pcb->GetDesignSettings() );
580
581 if( m_reporter && !uptodate && m_pcb->GetDesignSettings().m_HasStackup )
582 m_reporter->Report( _( "Board stackup settings not up to date." ), RPT_SEVERITY_ERROR );
583
584 PCB_LAYER_ID last_copper_layer = F_Cu;
585
586 // Generate the list (top to bottom):
587 for( int ii = 0; ii < brd_stackup.GetCount(); ++ii )
588 {
589 BOARD_STACKUP_ITEM* item = brd_stackup.GetStackupLayer( ii );
590
591 int sub_layer_count =
592 item->GetType() == BS_ITEM_TYPE_DIELECTRIC ? item->GetSublayersCount() : 1;
593
594 for( int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
595 {
596 // layer thickness is always in mm
597 double thickness = mapValue( item->GetThickness( sub_idx ) );
598 wxString layer_type;
599 std::string layer_name; // for comment
600
601 nlohmann::ordered_json layer_json;
602
603 switch( item->GetType() )
604 {
606 layer_type = wxT( "Copper" );
607 layer_name = formatStringFromUTF32( m_pcb->GetLayerName( item->GetBrdLayerId() ) );
608 last_copper_layer = item->GetBrdLayerId();
609 break;
610
612 layer_type = wxT( "Legend" );
613 layer_name = formatStringFromUTF32( item->GetTypeName() );
614 break;
615
617 layer_type = wxT( "SolderMask" );
618 layer_name = formatStringFromUTF32( item->GetTypeName() );
619 break;
620
622 layer_type = wxT( "SolderPaste" );
623 layer_name = formatStringFromUTF32( item->GetTypeName() );
624 break;
625
627 layer_type = wxT( "Dielectric" );
628 // The option core or prepreg is not added here, as it creates constraints
629 // in build process, not necessary wanted.
630 if( sub_layer_count > 1 )
631 {
632 layer_name =
633 formatStringFromUTF32( wxString::Format( wxT( "dielectric layer %d - %d/%d" ),
634 item->GetDielectricLayerId(), sub_idx + 1, sub_layer_count ) );
635 }
636 else
637 layer_name = formatStringFromUTF32( wxString::Format(
638 wxT( "dielectric layer %d" ), item->GetDielectricLayerId() ) );
639 break;
640
641 default:
642 break;
643 }
644
645 layer_json["Type"] = layer_type;
646
647 if( item->IsColorEditable() && uptodate )
648 {
649 if( IsPrmSpecified( item->GetColor( sub_idx ) ) )
650 {
651 wxString colorName = item->GetColor( sub_idx );
652
653 if( colorName.StartsWith( wxT( "#" ) ) ) // This is a user defined color,
654 // not in standard color list.
655 {
656 // In job file a color can be given by its RGB values (0...255)
657 // like R<number><G<number>B<number> notation
658 wxColor color( COLOR4D( colorName ).ToColour() );
659 colorName.Printf( wxT( "R%dG%dB%d" ),
660 color.Red(),
661 color.Green(),
662 color.Blue() );
663 }
664 else
665 {
666 const std::vector<FAB_LAYER_COLOR>& color_list =
667 GetStandardColors( item->GetType() );
668
669 // Colors for dielectric use a color list that is mainly not normalized in
670 // job file names. So if a color is in the dielectric standard color list
671 // it can be a standard name or not.
672 // Colors for solder mask and silk screen use a mainly normalized
673 // color list, but this list can also contain not normalized colors.
674 // If not normalized, use the R<number><G<number>B<number> notation
675 for( const FAB_LAYER_COLOR& prm_color : color_list )
676 {
677 if( colorName == prm_color.GetName() )
678 {
679 colorName = prm_color.GetColorAsString();
680 break;
681 }
682 }
683 }
684
685 layer_json["Color"] = colorName;
686 }
687 }
688
689 if( item->IsThicknessEditable() && uptodate )
690 layer_json["Thickness"] = thickness;
691
692 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
693 {
694 if( item->HasMaterialValue() )
695 {
696 layer_json["Material"] = item->GetMaterial( sub_idx );
697
698 // These constrains are only written if the board has impedance controlled tracks.
699 // If the board is not impedance controlled, they are useless.
700 // Do not add constrains that create more expensive boards.
701
702 if( brd_stackup.m_HasDielectricConstrains )
703 {
704 // Generate Epsilon R if > 1.0 (value <= 1.0 means not specified: it is not
705 // a possible value
706 if( item->GetEpsilonR() > 1.0 )
707 layer_json["DielectricConstant"] = item->FormatEpsilonR( sub_idx );
708
709 // Generate LossTangent > 0.0 (value <= 0.0 means not specified: it is not
710 // a possible value
711 if( item->GetLossTangent() > 0.0 )
712 layer_json["LossTangent"] = item->FormatLossTangent( sub_idx );
713 }
714 }
715
716 PCB_LAYER_ID next_copper_layer = ( PCB_LAYER_ID )( last_copper_layer + 1 );
717
718 // If the next_copper_layer is the last copper layer, the next layer id is B_Cu
719 if( next_copper_layer >= m_pcb->GetCopperLayerCount() - 1 )
720 next_copper_layer = B_Cu;
721
722 wxString subLayerName;
723
724 if( sub_layer_count > 1 )
725 subLayerName.Printf( wxT( " (%d/%d)" ), sub_idx + 1, sub_layer_count );
726
727 wxString name = wxString::Format( wxT( "%s/%s%s" ),
728 formatStringFromUTF32( m_pcb->GetLayerName( last_copper_layer ) ),
729 formatStringFromUTF32( m_pcb->GetLayerName( next_copper_layer ) ),
730 subLayerName );
731
732 layer_json["Name"] = name;
733
734 // Add a comment ("Notes"):
735 wxString note;
736
737 note << wxString::Format( wxT( "Type: %s" ), layer_name.c_str() );
738
739 note << wxString::Format( wxT( " (from %s to %s)" ),
740 formatStringFromUTF32( m_pcb->GetLayerName( last_copper_layer ) ),
741 formatStringFromUTF32( m_pcb->GetLayerName( next_copper_layer ) ) );
742
743 layer_json["Notes"] = note;
744 }
745 else if( item->GetType() == BS_ITEM_TYPE_SOLDERMASK
746 || item->GetType() == BS_ITEM_TYPE_SILKSCREEN )
747 {
748 if( item->HasMaterialValue() )
749 {
750 layer_json["Material"] = item->GetMaterial();
751
752 // These constrains are only written if the board has impedance controlled tracks.
753 // If the board is not impedance controlled, they are useless.
754 // Do not add constrains that create more expensive boards.
755 if( brd_stackup.m_HasDielectricConstrains )
756 {
757 // Generate Epsilon R if > 1.0 (value <= 1.0 means not specified: it is not
758 // a possible value
759 if( item->GetEpsilonR() > 1.0 )
760 layer_json["DielectricConstant"] = item->FormatEpsilonR();
761
762 // Generate LossTangent > 0.0 (value <= 0.0 means not specified: it is not
763 // a possible value
764 if( item->GetLossTangent() > 0.0 )
765 layer_json["LossTangent"] = item->FormatLossTangent();
766 }
767 }
768
769 layer_json["Name"] = layer_name.c_str();
770 }
771 else
772 {
773 layer_json["Name"] = layer_name.c_str();
774 }
775
776 m_json["MaterialStackup"].insert( m_json["MaterialStackup"].end(), layer_json );
777 }
778 }
779}
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_EDGE_CONNECTOR_BEVELLED
Definition: board_stackup.h:58
@ BS_ITEM_TYPE_COPPER
Definition: board_stackup.h:44
@ BS_ITEM_TYPE_SILKSCREEN
Definition: board_stackup.h:50
@ BS_ITEM_TYPE_DIELECTRIC
Definition: board_stackup.h:45
@ BS_ITEM_TYPE_SOLDERPASTE
Definition: board_stackup.h:47
@ BS_ITEM_TYPE_SOLDERMASK
Definition: board_stackup.h:48
wxString GetBuildVersion()
Get the full KiCad version string.
std::shared_ptr< NET_SETTINGS > m_NetSettings
int GetBoardThickness() const
The full thickness of the board including copper and masks.
BOARD_STACKUP & GetStackupDescriptor()
Manage one layer needed to make a physical board.
Definition: board_stackup.h:95
wxString GetTypeName() const
int GetSublayersCount() const
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetColor(int aDielectricSubLayer=0) const
bool HasMaterialValue(int aDielectricSubLayer=0) const
PCB_LAYER_ID GetBrdLayerId() const
bool IsThicknessEditable() const
int GetThickness(int aDielectricSubLayer=0) const
BOARD_STACKUP_ITEM_TYPE GetType() const
wxString GetMaterial(int aDielectricSubLayer=0) const
wxString FormatEpsilonR(int aDielectricSubLayer=0) const
int GetDielectricLayerId() const
bool IsColorEditable() const
wxString FormatLossTangent(int aDielectricSubLayer=0) const
double GetLossTangent(int aDielectricSubLayer=0) const
Manage layers needed to make a physical board.
bool m_CastellatedPads
True if castellated pads exist.
int GetCount() const
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
BOARD_STACKUP_ITEM * GetStackupLayer(int aIndex)
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 specified in job file: BS_EDGE_CONNECTO...
wxString m_FinishType
The name of external copper finish.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:908
const ZONES & Zones() const
Definition: board.h:326
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:674
int GetCopperLayerCount() const
Definition: board.cpp:656
const FOOTPRINTS & Footprints() const
Definition: board.h:322
const TRACKS & Tracks() const
Definition: board.h:320
const wxString & GetFileName() const
Definition: board.h:318
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:567
PROJECT * GetProject() const
Definition: board.h:475
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
size_type GetHeight() const
Definition: box2.h:205
size_type GetWidth() const
Definition: box2.h:204
void addJSONHeader()
Add the job file header 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 addJSONFilesAttributes()
Add the Files Attributes section in JSON format to m_JSONbuffer.
nlohmann::ordered_json m_json
bool CreateJobFile(const wxString &aFullFilename)
Creates a Gerber job file.
void addJSONGeneralSpecs()
Add the General Specs in JSON format to m_JSONbuffer.
bool WriteJSONJobFile(const wxString &aFullFilename)
Creates an Gerber job file in JSON format.
double mapValue(double aUiValue)
A helper function to convert a double in Pcbnew internal units to a JSON double value (in mm),...
const char * sideKeyValue(enum ONSIDE aValue)
void addJSONDesignRules()
Add the Design Rules section in JSON format to m_JSONbuffer.
std::string formatStringFromUTF32(const wxString &aText)
A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a e...
GERBER_JOBFILE_WRITER(BOARD *aPcb, REPORTER *aReporter=nullptr)
wxArrayString m_GerberFileList
std::vector< PCB_LAYER_ID > m_LayerId
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
Definition: pad.h:59
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
const wxString & GetRevision() const
Definition: title_block.h:86
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:58
#define _(s)
wxString GbrMakeProjectGUIDfromString(const wxString &aText)
Build a project GUID using format RFC4122 Version 1 or 4 from the project name, because a KiCad proje...
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
Handle special data (items attributes) during plot.
@ GBR_NC_STRING_FORMAT_GBRJOB
Definition: gbr_metadata.h:63
Classes used to generate a Gerber job file in JSON.
@ SIDE_BOTTOM
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ User_8
Definition: layer_ids.h:130
@ F_CrtYd
Definition: layer_ids.h:117
@ B_Adhes
Definition: layer_ids.h:97
@ Edge_Cuts
Definition: layer_ids.h:113
@ Dwgs_User
Definition: layer_ids.h:109
@ F_Paste
Definition: layer_ids.h:101
@ Cmts_User
Definition: layer_ids.h:110
@ User_6
Definition: layer_ids.h:128
@ User_7
Definition: layer_ids.h:129
@ F_Adhes
Definition: layer_ids.h:98
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ User_5
Definition: layer_ids.h:127
@ Eco1_User
Definition: layer_ids.h:111
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ User_9
Definition: layer_ids.h:131
@ F_Fab
Definition: layer_ids.h:120
@ Margin
Definition: layer_ids.h:114
@ F_SilkS
Definition: layer_ids.h:104
@ B_CrtYd
Definition: layer_ids.h:116
@ Eco2_User
Definition: layer_ids.h:112
@ User_3
Definition: layer_ids.h:125
@ User_1
Definition: layer_ids.h:123
@ B_SilkS
Definition: layer_ids.h:103
@ User_4
Definition: layer_ids.h:126
@ User_2
Definition: layer_ids.h:124
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:119
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_ACTION
std::vector< FAB_LAYER_COLOR > dummy
const std::vector< FAB_LAYER_COLOR > & GetStandardColors(BOARD_STACKUP_ITEM_TYPE aType)
const double IU_PER_MM
Definition: base_units.h:76
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
Definition of file extensions used in Kicad.