66 fmt_text = aText.utf8_string();
109 const char* value =
nullptr;
114 case SIDE_TOP: value =
"TopOnly";
break;
134 msg.Printf(
_(
"Failed to create file '%s'." ), aFullFilename );
140 msg.Printf(
_(
"Created Gerber job file '%s'." ), aFullFilename );
152 "GenerationSoftware",
154 {
"Vendor",
"KiCad" },
155 {
"Application",
"Pcbnew" },
171 std::ofstream file( aFullFilename.ToUTF8() );
173 m_json = nlohmann::ordered_json( {} );
190 file << std::setw( 2 ) <<
m_json << std::endl;
206 sscanf( buffer,
"%Lg", &output );
215 m_json[
"GeneralSpecs"] = nlohmann::ordered_json( {} );
216 m_json[
"GeneralSpecs"][
"ProjectId"] = nlohmann::ordered_json( {} );
227 wxFileName fn =
m_pcb->GetFileName();
228 wxString msg = fn.GetFullName();
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();
248 BOX2I brect =
m_pcb->GetBoardEdgesBoundingBox();
256 m_json[
"GeneralSpecs"][
"LayerNumber"] =
m_pcb->GetCopperLayerCount();
259 m_json[
"GeneralSpecs"][
"BoardThickness"] =
269 m_json[
"GeneralSpecs"][
"ImpedanceControlled"] =
true;
272 if( brd_stackup.m_CastellatedPads )
273 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
275 if(
m_pcb->GetPadWithCastellatedAttrCount() )
276 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
278 if(
m_pcb->GetPadWithPressFitAttrCount() )
279 m_json[
"GeneralSpecs"][
"Press-fit"] =
true;
282 m_json[
"GeneralSpecs"][
"EdgePlating"] =
true;
286 m_json[
"GeneralSpecs"][
"EdgeConnector"] =
true;
288 m_json[
"GeneralSpecs"][
"EdgeConnectorBevelled"] =
301 m_json[
"GeneralSpecs"][
"IPC-2221-Type"] = 4;
317 m_json[
"GeneralSpecs"][
"ViaProtection"] =
"Ib";
325 m_json[
"FilesAttributes"] = nlohmann::ordered_json::array();
327 for(
unsigned ii = 0; ii <
m_params.m_GerberFileList.GetCount(); ii++ )
331 wxString gbr_layer_id;
332 bool skip_file =
false;
333 const char* polarity =
"Positive";
335 nlohmann::ordered_json file_json;
339 gbr_layer_id = wxT(
"Copper,L" );
342 gbr_layer_id <<
m_pcb->GetCopperLayerCount();
343 else if( layer ==
F_Cu )
347 gbr_layer_id << (layer-
B_Cu) / 2 + 1;
349 gbr_layer_id << wxT(
"," );
352 gbr_layer_id << wxT(
"Bot" );
353 else if( layer ==
F_Cu )
354 gbr_layer_id << wxT(
"Top" );
356 gbr_layer_id << wxT(
"Inr" );
364 gbr_layer_id = wxT(
"Glue,Bot" );
367 gbr_layer_id = wxT(
"Glue,Top" );
371 gbr_layer_id = wxT(
"SolderPaste,Bot" );
374 gbr_layer_id = wxT(
"SolderPaste,Top" );
378 gbr_layer_id = wxT(
"Legend,Bot" );
381 gbr_layer_id = wxT(
"Legend,Top" );
385 gbr_layer_id = wxT(
"SolderMask,Bot" );
386 polarity =
"Negative";
389 gbr_layer_id = wxT(
"SolderMask,Top" );
390 polarity =
"Negative";
394 gbr_layer_id = wxT(
"Profile" );
398 gbr_layer_id = wxT(
"AssemblyDrawing,Bot" );
401 gbr_layer_id = wxT(
"AssemblyDrawing,Top" );
423 gbr_layer_id = wxT(
"Other,User" );
442 file_json[
"Path"] = strname.c_str();
443 file_json[
"FileFunction"] = gbr_layer_id;
444 file_json[
"FilePolarity"] = polarity;
446 m_json[
"FilesAttributes"] += file_json;
456 std::shared_ptr<NET_SETTINGS>& netSettings =
m_pcb->GetDesignSettings().m_NetSettings;
458 int minclearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
459 bool hasInnerLayers =
m_pcb->GetCopperLayerCount() > 2;
462 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
463 minclearanceOuter = std::min( minclearanceOuter, netclass->GetClearance() );
467 int minclearance_track2track = minclearanceOuter;
472 int minPadClearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
473 int minPadClearanceInner = netSettings->GetDefaultNetclass()->GetClearance();
477 for(
PAD*
pad : footprint->Pads() )
481 int padClearance =
pad->GetOwnClearance( layer );
483 if( layer ==
B_Cu || layer ==
F_Cu )
484 minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
486 minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
491 m_json[
"DesignRules"] = { {
492 {
"Layers",
"Outer" },
493 {
"PadToPad",
mapValue( minPadClearanceOuter ) },
494 {
"PadToTrack",
mapValue( minPadClearanceOuter ) },
495 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
499 int minclearanceInner = minclearanceOuter;
502 int mintrackWidthOuter = INT_MAX;
503 int mintrackWidthInner = INT_MAX;
510 if( track->GetLayer() ==
B_Cu || track->GetLayer() ==
F_Cu )
511 mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
513 mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
516 if( mintrackWidthOuter != INT_MAX )
517 m_json[
"DesignRules"][0][
"MinLineWidth"] =
mapValue( mintrackWidthOuter );
522 minclearanceOuter = INT_MAX;
523 minclearanceInner = INT_MAX;
527 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
532 int zclerance = zone->GetOwnClearance( layer );
534 if( layer ==
B_Cu || layer ==
F_Cu )
535 minclearanceOuter = std::min( minclearanceOuter, zclerance );
537 minclearanceInner = std::min( minclearanceInner, zclerance );
541 if( minclearanceOuter != INT_MAX )
542 m_json[
"DesignRules"][0][
"TrackToRegion"] =
mapValue( minclearanceOuter );
544 if( minclearanceOuter != INT_MAX )
545 m_json[
"DesignRules"][0][
"RegionToRegion"] =
mapValue( minclearanceOuter );
549 m_json[
"DesignRules"] += nlohmann::ordered_json( {
550 {
"Layers",
"Inner" },
551 {
"PadToPad",
mapValue( minPadClearanceInner ) },
552 {
"PadToTrack",
mapValue( minPadClearanceInner ) },
553 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
556 if( mintrackWidthInner != INT_MAX )
557 m_json[
"DesignRules"][1][
"MinLineWidth"] =
mapValue( mintrackWidthInner );
559 if( minclearanceInner != INT_MAX )
560 m_json[
"DesignRules"][1][
"TrackToRegion"] =
mapValue( minclearanceInner );
562 if( minclearanceInner != INT_MAX )
563 m_json[
"DesignRules"][1][
"RegionToRegion"] =
mapValue( minclearanceInner );
571 m_json[
"MaterialStackup"] = nlohmann::ordered_json::array();
580 if(
m_reporter && !uptodate &&
m_pcb->GetDesignSettings().m_HasStackup )
586 for(
int ii = 0; ii < brd_stackup.
GetCount(); ++ii )
590 int sub_layer_count =
593 for(
int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
598 std::string layer_name;
600 nlohmann::ordered_json layer_json;
605 layer_type = wxT(
"Copper" );
611 layer_type = wxT(
"Legend" );
616 layer_type = wxT(
"SolderMask" );
621 layer_type = wxT(
"SolderPaste" );
626 layer_type = wxT(
"Dielectric" );
629 if( sub_layer_count > 1 )
644 layer_json[
"Type"] = layer_type;
650 wxString colorName = item->
GetColor( sub_idx );
652 if( colorName.StartsWith( wxT(
"#" ) ) )
657 wxColor color(
COLOR4D( colorName ).ToColour() );
658 colorName.Printf( wxT(
"R%dG%dB%d" ),
665 const std::vector<FAB_LAYER_COLOR>& color_list =
676 if( colorName == prm_color.GetName() )
678 colorName = prm_color.GetColorAsString();
684 layer_json[
"Color"] = colorName;
689 layer_json[
"Thickness"] = thickness;
695 layer_json[
"Material"] = item->
GetMaterial( sub_idx );
706 layer_json[
"DielectricConstant"] = item->
FormatEpsilonR( sub_idx );
720 if( last_copper_layer ==
F_Cu )
721 next_copper_layer =
In1_Cu;
724 if( next_copper_layer/2 >=
m_pcb->GetCopperLayerCount() )
725 next_copper_layer =
B_Cu;
727 wxString subLayerName;
729 if( sub_layer_count > 1 )
730 subLayerName.Printf( wxT(
" (%d/%d)" ), sub_idx + 1, sub_layer_count );
732 wxString
name = wxString::Format( wxT(
"%s/%s%s" ),
737 layer_json[
"Name"] =
name;
742 note << wxString::Format( wxT(
"Type: %s" ), layer_name.c_str() );
744 note << wxString::Format( wxT(
" (from %s to %s)" ),
748 layer_json[
"Notes"] = note;
774 layer_json[
"Name"] = layer_name.c_str();
778 layer_json[
"Name"] = layer_name.c_str();
781 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.