64 fmt_text = aText.utf8_string();
107 const char* value =
nullptr;
143 msg.Printf(
_(
"Failed to create file '%s'." ), aFullFilename );
149 msg.Printf(
_(
"Created Gerber job file '%s'." ), aFullFilename );
161 "GenerationSoftware",
163 {
"Vendor",
"KiCad" },
164 {
"Application",
"Pcbnew" },
180 std::ofstream file( aFullFilename.ToUTF8() );
184 m_json = nlohmann::ordered_json( {} );
201 file << std::setw( 2 ) <<
m_json << std::endl;
217 sscanf( buffer,
"%Lg", &output );
226 m_json[
"GeneralSpecs"] = nlohmann::ordered_json( {} );
227 m_json[
"GeneralSpecs"][
"ProjectId"] = nlohmann::ordered_json( {} );
239 wxString msg = fn.GetFullName();
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();
270 m_json[
"GeneralSpecs"][
"BoardThickness"] =
280 m_json[
"GeneralSpecs"][
"ImpedanceControlled"] =
true;
283 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
286 m_json[
"GeneralSpecs"][
"EdgePlating"] =
true;
290 m_json[
"GeneralSpecs"][
"EdgeConnector"] =
true;
292 m_json[
"GeneralSpecs"][
"EdgeConnectorBevelled"] =
305 m_json[
"GeneralSpecs"][
"IPC-2221-Type"] = 4;
321 m_json[
"GeneralSpecs"][
"ViaProtection"] =
"Ib";
329 m_json[
"FilesAttributes"] = nlohmann::ordered_json::array();
335 wxString gbr_layer_id;
336 bool skip_file =
false;
337 const char* polarity =
"Positive";
339 nlohmann::ordered_json file_json;
343 gbr_layer_id = wxT(
"Copper,L" );
348 gbr_layer_id << layer + 1;
350 gbr_layer_id << wxT(
"," );
353 gbr_layer_id << wxT(
"Bot" );
354 else if( layer ==
F_Cu )
355 gbr_layer_id << wxT(
"Top" );
357 gbr_layer_id << wxT(
"Inr" );
365 gbr_layer_id = wxT(
"Glue,Bot" );
368 gbr_layer_id = wxT(
"Glue,Top" );
372 gbr_layer_id = wxT(
"SolderPaste,Bot" );
375 gbr_layer_id = wxT(
"SolderPaste,Top" );
379 gbr_layer_id = wxT(
"Legend,Bot" );
382 gbr_layer_id = wxT(
"Legend,Top" );
386 gbr_layer_id = wxT(
"SolderMask,Bot" );
387 polarity =
"Negative";
390 gbr_layer_id = wxT(
"SolderMask,Top" );
391 polarity =
"Negative";
395 gbr_layer_id = wxT(
"Profile" );
399 gbr_layer_id = wxT(
"AssemblyDrawing,Bot" );
402 gbr_layer_id = wxT(
"AssemblyDrawing,Top" );
424 gbr_layer_id = wxT(
"Other,User" );
443 file_json[
"Path"] = strname.c_str();
444 file_json[
"FileFunction"] = gbr_layer_id;
445 file_json[
"FilePolarity"] = polarity;
447 m_json[
"FilesAttributes"] += file_json;
459 int minclearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
463 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
464 minclearanceOuter = std::min( minclearanceOuter, netclass->GetClearance() );
468 int minclearance_track2track = minclearanceOuter;
473 int minPadClearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
474 int minPadClearanceInner = netSettings->GetDefaultNetclass()->GetClearance();
478 for(
PAD*
pad : footprint->Pads() )
482 int padClearance =
pad->GetOwnClearance( layer );
484 if( layer ==
B_Cu || layer ==
F_Cu )
485 minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
487 minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
492 m_json[
"DesignRules"] = { {
493 {
"Layers",
"Outer" },
494 {
"PadToPad",
mapValue( minPadClearanceOuter ) },
495 {
"PadToTrack",
mapValue( minPadClearanceOuter ) },
496 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
500 int minclearanceInner = minclearanceOuter;
503 int mintrackWidthOuter = INT_MAX;
504 int mintrackWidthInner = INT_MAX;
511 if( track->GetLayer() ==
B_Cu || track->GetLayer() ==
F_Cu )
512 mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
514 mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
517 if( mintrackWidthOuter != INT_MAX )
518 m_json[
"DesignRules"][0][
"MinLineWidth"] =
mapValue( mintrackWidthOuter );
523 minclearanceOuter = INT_MAX;
524 minclearanceInner = INT_MAX;
528 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
533 int zclerance = zone->GetOwnClearance( layer );
535 if( layer ==
B_Cu || layer ==
F_Cu )
536 minclearanceOuter = std::min( minclearanceOuter, zclerance );
538 minclearanceInner = std::min( minclearanceInner, zclerance );
542 if( minclearanceOuter != INT_MAX )
543 m_json[
"DesignRules"][0][
"TrackToRegion"] =
mapValue( minclearanceOuter );
545 if( minclearanceOuter != INT_MAX )
546 m_json[
"DesignRules"][0][
"RegionToRegion"] =
mapValue( minclearanceOuter );
550 m_json[
"DesignRules"] += nlohmann::ordered_json( {
551 {
"Layers",
"Inner" },
552 {
"PadToPad",
mapValue( minPadClearanceInner ) },
553 {
"PadToTrack",
mapValue( minPadClearanceInner ) },
554 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
557 if( mintrackWidthInner != INT_MAX )
558 m_json[
"DesignRules"][1][
"MinLineWidth"] =
mapValue( mintrackWidthInner );
560 if( minclearanceInner != INT_MAX )
561 m_json[
"DesignRules"][1][
"TrackToRegion"] =
mapValue( minclearanceInner );
563 if( minclearanceInner != INT_MAX )
564 m_json[
"DesignRules"][1][
"RegionToRegion"] =
mapValue( minclearanceInner );
572 m_json[
"MaterialStackup"] = nlohmann::ordered_json::array();
587 for(
int ii = 0; ii < brd_stackup.
GetCount(); ++ii )
591 int sub_layer_count =
594 for(
int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
599 std::string layer_name;
601 nlohmann::ordered_json layer_json;
606 layer_type = wxT(
"Copper" );
612 layer_type = wxT(
"Legend" );
617 layer_type = wxT(
"SolderMask" );
622 layer_type = wxT(
"SolderPaste" );
627 layer_type = wxT(
"Dielectric" );
630 if( sub_layer_count > 1 )
645 layer_json[
"Type"] = layer_type;
651 wxString colorName = item->
GetColor( sub_idx );
653 if( colorName.StartsWith( wxT(
"#" ) ) )
659 colorName.Printf( wxT(
"R%dG%dB%d" ),
666 const std::vector<FAB_LAYER_COLOR>& color_list =
677 if( colorName == prm_color.GetName() )
679 colorName = prm_color.GetColorAsString();
685 layer_json[
"Color"] = colorName;
690 layer_json[
"Thickness"] = thickness;
696 layer_json[
"Material"] = item->
GetMaterial( sub_idx );
707 layer_json[
"DielectricConstant"] = item->
FormatEpsilonR( sub_idx );
721 if( last_copper_layer ==
F_Cu )
722 next_copper_layer =
In1_Cu;
726 next_copper_layer =
B_Cu;
728 wxString subLayerName;
730 if( sub_layer_count > 1 )
731 subLayerName.Printf( wxT(
" (%d/%d)" ), sub_idx + 1, sub_layer_count );
733 wxString
name = wxString::Format( wxT(
"%s/%s%s" ),
738 layer_json[
"Name"] =
name;
743 note << wxString::Format( wxT(
"Type: %s" ), layer_name.c_str() );
745 note << wxString::Format( wxT(
" (from %s to %s)" ),
749 layer_json[
"Notes"] = note;
775 layer_json[
"Name"] = layer_name.c_str();
779 layer_json[
"Name"] = layer_name.c_str();
782 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.
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.
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.
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.
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
const ZONES & Zones() const
TITLE_BLOCK & GetTitleBlock()
int GetCopperLayerCount() const
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
const wxString & GetFileName() const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
PROJECT * GetProject() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
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)
wxArrayString m_GerberFileList
std::vector< PCB_LAYER_ID > m_LayerId
A color representation with 4 components: red, green, blue, alpha.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
LSET is a set of PCB_LAYER_IDs.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
const wxString & GetRevision() const
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)
Tests whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
std::vector< FAB_LAYER_COLOR > dummy
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.