64 fmt_text = aText.utf8_string();
107 const char* value =
nullptr;
112 case SIDE_TOP: value =
"TopOnly";
break;
132 msg.Printf(
_(
"Failed to create file '%s'." ), aFullFilename );
138 msg.Printf(
_(
"Created Gerber job file '%s'." ), aFullFilename );
150 "GenerationSoftware",
152 {
"Vendor",
"KiCad" },
153 {
"Application",
"Pcbnew" },
169 std::ofstream file( aFullFilename.ToUTF8() );
171 m_json = nlohmann::ordered_json( {} );
188 file << std::setw( 2 ) <<
m_json << std::endl;
204 sscanf( buffer,
"%Lg", &output );
213 m_json[
"GeneralSpecs"] = nlohmann::ordered_json( {} );
214 m_json[
"GeneralSpecs"][
"ProjectId"] = nlohmann::ordered_json( {} );
225 wxFileName fn =
m_pcb->GetFileName();
226 wxString msg = fn.GetFullName();
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();
246 BOX2I brect =
m_pcb->GetBoardEdgesBoundingBox();
254 m_json[
"GeneralSpecs"][
"LayerNumber"] =
m_pcb->GetCopperLayerCount();
257 m_json[
"GeneralSpecs"][
"BoardThickness"] =
267 m_json[
"GeneralSpecs"][
"ImpedanceControlled"] =
true;
270 if( brd_stackup.m_CastellatedPads )
271 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
273 if(
m_pcb->GetPadWithCastellatedAttrCount() )
274 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
276 if(
m_pcb->GetPadWithPressFitAttrCount() )
277 m_json[
"GeneralSpecs"][
"Press-fit"] =
true;
280 m_json[
"GeneralSpecs"][
"EdgePlating"] =
true;
284 m_json[
"GeneralSpecs"][
"EdgeConnector"] =
true;
286 m_json[
"GeneralSpecs"][
"EdgeConnectorBevelled"] =
299 m_json[
"GeneralSpecs"][
"IPC-2221-Type"] = 4;
315 m_json[
"GeneralSpecs"][
"ViaProtection"] =
"Ib";
323 m_json[
"FilesAttributes"] = nlohmann::ordered_json::array();
325 for(
unsigned ii = 0; ii <
m_params.m_GerberFileList.GetCount(); ii++ )
329 wxString gbr_layer_id;
330 bool skip_file =
false;
331 const char* polarity =
"Positive";
333 nlohmann::ordered_json file_json;
337 gbr_layer_id = wxT(
"Copper,L" );
340 gbr_layer_id <<
m_pcb->GetCopperLayerCount();
341 else if( layer ==
F_Cu )
345 gbr_layer_id << (layer-
B_Cu) / 2 + 1;
347 gbr_layer_id << wxT(
"," );
350 gbr_layer_id << wxT(
"Bot" );
351 else if( layer ==
F_Cu )
352 gbr_layer_id << wxT(
"Top" );
354 gbr_layer_id << wxT(
"Inr" );
362 gbr_layer_id = wxT(
"Glue,Bot" );
365 gbr_layer_id = wxT(
"Glue,Top" );
369 gbr_layer_id = wxT(
"SolderPaste,Bot" );
372 gbr_layer_id = wxT(
"SolderPaste,Top" );
376 gbr_layer_id = wxT(
"Legend,Bot" );
379 gbr_layer_id = wxT(
"Legend,Top" );
383 gbr_layer_id = wxT(
"SolderMask,Bot" );
384 polarity =
"Negative";
387 gbr_layer_id = wxT(
"SolderMask,Top" );
388 polarity =
"Negative";
392 gbr_layer_id = wxT(
"Profile" );
396 gbr_layer_id = wxT(
"AssemblyDrawing,Bot" );
399 gbr_layer_id = wxT(
"AssemblyDrawing,Top" );
421 gbr_layer_id = wxT(
"Other,User" );
440 file_json[
"Path"] = strname.c_str();
441 file_json[
"FileFunction"] = gbr_layer_id;
442 file_json[
"FilePolarity"] = polarity;
444 m_json[
"FilesAttributes"] += file_json;
454 std::shared_ptr<NET_SETTINGS>& netSettings =
m_pcb->GetDesignSettings().m_NetSettings;
456 int minclearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
457 bool hasInnerLayers =
m_pcb->GetCopperLayerCount() > 2;
460 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
461 minclearanceOuter = std::min( minclearanceOuter, netclass->GetClearance() );
465 int minclearance_track2track = minclearanceOuter;
470 int minPadClearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
471 int minPadClearanceInner = netSettings->GetDefaultNetclass()->GetClearance();
475 for(
PAD*
pad : footprint->Pads() )
479 int padClearance =
pad->GetOwnClearance( layer );
481 if( layer ==
B_Cu || layer ==
F_Cu )
482 minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
484 minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
489 m_json[
"DesignRules"] = { {
490 {
"Layers",
"Outer" },
491 {
"PadToPad",
mapValue( minPadClearanceOuter ) },
492 {
"PadToTrack",
mapValue( minPadClearanceOuter ) },
493 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
497 int minclearanceInner = minclearanceOuter;
500 int mintrackWidthOuter = INT_MAX;
501 int mintrackWidthInner = INT_MAX;
508 if( track->GetLayer() ==
B_Cu || track->GetLayer() ==
F_Cu )
509 mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
511 mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
514 if( mintrackWidthOuter != INT_MAX )
515 m_json[
"DesignRules"][0][
"MinLineWidth"] =
mapValue( mintrackWidthOuter );
520 minclearanceOuter = INT_MAX;
521 minclearanceInner = INT_MAX;
525 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
530 int zclerance = zone->GetOwnClearance( layer );
532 if( layer ==
B_Cu || layer ==
F_Cu )
533 minclearanceOuter = std::min( minclearanceOuter, zclerance );
535 minclearanceInner = std::min( minclearanceInner, zclerance );
539 if( minclearanceOuter != INT_MAX )
540 m_json[
"DesignRules"][0][
"TrackToRegion"] =
mapValue( minclearanceOuter );
542 if( minclearanceOuter != INT_MAX )
543 m_json[
"DesignRules"][0][
"RegionToRegion"] =
mapValue( minclearanceOuter );
547 m_json[
"DesignRules"] += nlohmann::ordered_json( {
548 {
"Layers",
"Inner" },
549 {
"PadToPad",
mapValue( minPadClearanceInner ) },
550 {
"PadToTrack",
mapValue( minPadClearanceInner ) },
551 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
554 if( mintrackWidthInner != INT_MAX )
555 m_json[
"DesignRules"][1][
"MinLineWidth"] =
mapValue( mintrackWidthInner );
557 if( minclearanceInner != INT_MAX )
558 m_json[
"DesignRules"][1][
"TrackToRegion"] =
mapValue( minclearanceInner );
560 if( minclearanceInner != INT_MAX )
561 m_json[
"DesignRules"][1][
"RegionToRegion"] =
mapValue( minclearanceInner );
569 m_json[
"MaterialStackup"] = nlohmann::ordered_json::array();
578 if(
m_reporter && !uptodate &&
m_pcb->GetDesignSettings().m_HasStackup )
584 for(
int ii = 0; ii < brd_stackup.
GetCount(); ++ii )
588 int sub_layer_count =
591 for(
int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
596 std::string layer_name;
598 nlohmann::ordered_json layer_json;
603 layer_type = wxT(
"Copper" );
609 layer_type = wxT(
"Legend" );
614 layer_type = wxT(
"SolderMask" );
619 layer_type = wxT(
"SolderPaste" );
624 layer_type = wxT(
"Dielectric" );
627 if( sub_layer_count > 1 )
642 layer_json[
"Type"] = layer_type;
648 wxString colorName = item->
GetColor( sub_idx );
650 if( colorName.StartsWith( wxT(
"#" ) ) )
656 colorName.Printf( wxT(
"R%dG%dB%d" ),
663 const std::vector<FAB_LAYER_COLOR>& color_list =
674 if( colorName == prm_color.GetName() )
676 colorName = prm_color.GetColorAsString();
682 layer_json[
"Color"] = colorName;
687 layer_json[
"Thickness"] = thickness;
693 layer_json[
"Material"] = item->
GetMaterial( sub_idx );
704 layer_json[
"DielectricConstant"] = item->
FormatEpsilonR( sub_idx );
718 if( last_copper_layer ==
F_Cu )
719 next_copper_layer =
In1_Cu;
722 if( next_copper_layer/2 >=
m_pcb->GetCopperLayerCount() )
723 next_copper_layer =
B_Cu;
725 wxString subLayerName;
727 if( sub_layer_count > 1 )
728 subLayerName.Printf( wxT(
" (%d/%d)" ), sub_idx + 1, sub_layer_count );
730 wxString
name = wxString::Format( wxT(
"%s/%s%s" ),
735 layer_json[
"Name"] =
name;
740 note << wxString::Format( wxT(
"Type: %s" ), layer_name.c_str() );
742 note << wxString::Format( wxT(
" (from %s to %s)" ),
746 layer_json[
"Notes"] = note;
772 layer_json[
"Name"] = layer_name.c_str();
776 layer_json[
"Name"] = layer_name.c_str();
779 m_json[
"MaterialStackup"].insert(
m_json[
"MaterialStackup"].
end(), layer_json );
constexpr EDA_IU_SCALE pcbIUScale
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_EDGE_CONNECTOR_BEVELLED
@ BS_ITEM_TYPE_SILKSCREEN
@ BS_ITEM_TYPE_DIELECTRIC
@ BS_ITEM_TYPE_SOLDERPASTE
@ BS_ITEM_TYPE_SOLDERMASK
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.
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.
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
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
enum ONSIDE hasSilkLayers()
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.
enum ONSIDE hasSolderMasks()
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.
LSET is a set of PCB_LAYER_IDs.
A pure virtual class used to derive REPORTER objects from.
Handle a list of polygons defining a copper zone.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Classes used to generate a Gerber job file in JSON.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
const std::vector< FAB_LAYER_COLOR > & GetStandardColors(BOARD_STACKUP_ITEM_TYPE aType)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition of file extensions used in Kicad.