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