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