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() );
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( {} );
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();
259 m_json[
"GeneralSpecs"][
"BoardThickness"] =
269 m_json[
"GeneralSpecs"][
"ImpedanceControlled"] =
true;
272 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
275 m_json[
"GeneralSpecs"][
"EdgePlating"] =
true;
279 m_json[
"GeneralSpecs"][
"EdgeConnector"] =
true;
281 m_json[
"GeneralSpecs"][
"EdgeConnectorBevelled"] =
294 m_json[
"GeneralSpecs"][
"IPC-2221-Type"] = 4;
310 m_json[
"GeneralSpecs"][
"ViaProtection"] =
"Ib";
318 m_json[
"FilesAttributes"] = nlohmann::ordered_json::array();
324 wxString gbr_layer_id;
325 bool skip_file =
false;
326 const char* polarity =
"Positive";
328 nlohmann::ordered_json file_json;
332 gbr_layer_id = wxT(
"Copper,L" );
337 gbr_layer_id << layer + 1;
339 gbr_layer_id << wxT(
"," );
342 gbr_layer_id << wxT(
"Bot" );
343 else if( layer ==
F_Cu )
344 gbr_layer_id << wxT(
"Top" );
346 gbr_layer_id << wxT(
"Inr" );
354 gbr_layer_id = wxT(
"Glue,Bot" );
357 gbr_layer_id = wxT(
"Glue,Top" );
361 gbr_layer_id = wxT(
"SolderPaste,Bot" );
364 gbr_layer_id = wxT(
"SolderPaste,Top" );
368 gbr_layer_id = wxT(
"Legend,Bot" );
371 gbr_layer_id = wxT(
"Legend,Top" );
375 gbr_layer_id = wxT(
"SolderMask,Bot" );
376 polarity =
"Negative";
379 gbr_layer_id = wxT(
"SolderMask,Top" );
380 polarity =
"Negative";
384 gbr_layer_id = wxT(
"Profile" );
388 gbr_layer_id = wxT(
"AssemblyDrawing,Bot" );
391 gbr_layer_id = wxT(
"AssemblyDrawing,Top" );
413 gbr_layer_id = wxT(
"Other,User" );
432 file_json[
"Path"] = strname.c_str();
433 file_json[
"FileFunction"] = gbr_layer_id;
434 file_json[
"FilePolarity"] = polarity;
436 m_json[
"FilesAttributes"] += file_json;
448 int minclearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
452 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
453 minclearanceOuter = std::min( minclearanceOuter, netclass->GetClearance() );
457 int minclearance_track2track = minclearanceOuter;
462 int minPadClearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
463 int minPadClearanceInner = netSettings->GetDefaultNetclass()->GetClearance();
467 for(
PAD*
pad : footprint->Pads() )
471 int padClearance =
pad->GetOwnClearance( layer );
473 if( layer ==
B_Cu || layer ==
F_Cu )
474 minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
476 minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
481 m_json[
"DesignRules"] = { {
482 {
"Layers",
"Outer" },
483 {
"PadToPad",
mapValue( minPadClearanceOuter ) },
484 {
"PadToTrack",
mapValue( minPadClearanceOuter ) },
485 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
489 int minclearanceInner = minclearanceOuter;
492 int mintrackWidthOuter = INT_MAX;
493 int mintrackWidthInner = INT_MAX;
500 if( track->GetLayer() ==
B_Cu || track->GetLayer() ==
F_Cu )
501 mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
503 mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
506 if( mintrackWidthOuter != INT_MAX )
507 m_json[
"DesignRules"][0][
"MinLineWidth"] =
mapValue( mintrackWidthOuter );
512 minclearanceOuter = INT_MAX;
513 minclearanceInner = INT_MAX;
517 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
522 int zclerance = zone->GetOwnClearance( layer );
524 if( layer ==
B_Cu || layer ==
F_Cu )
525 minclearanceOuter = std::min( minclearanceOuter, zclerance );
527 minclearanceInner = std::min( minclearanceInner, zclerance );
531 if( minclearanceOuter != INT_MAX )
532 m_json[
"DesignRules"][0][
"TrackToRegion"] =
mapValue( minclearanceOuter );
534 if( minclearanceOuter != INT_MAX )
535 m_json[
"DesignRules"][0][
"RegionToRegion"] =
mapValue( minclearanceOuter );
539 m_json[
"DesignRules"] += nlohmann::ordered_json( {
540 {
"Layers",
"Inner" },
541 {
"PadToPad",
mapValue( minPadClearanceInner ) },
542 {
"PadToTrack",
mapValue( minPadClearanceInner ) },
543 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
546 if( mintrackWidthInner != INT_MAX )
547 m_json[
"DesignRules"][1][
"MinLineWidth"] =
mapValue( mintrackWidthInner );
549 if( minclearanceInner != INT_MAX )
550 m_json[
"DesignRules"][1][
"TrackToRegion"] =
mapValue( minclearanceInner );
552 if( minclearanceInner != INT_MAX )
553 m_json[
"DesignRules"][1][
"RegionToRegion"] =
mapValue( minclearanceInner );
561 m_json[
"MaterialStackup"] = nlohmann::ordered_json::array();
576 for(
int ii = 0; ii < brd_stackup.
GetCount(); ++ii )
580 int sub_layer_count =
583 for(
int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
588 std::string layer_name;
590 nlohmann::ordered_json layer_json;
595 layer_type = wxT(
"Copper" );
601 layer_type = wxT(
"Legend" );
606 layer_type = wxT(
"SolderMask" );
611 layer_type = wxT(
"SolderPaste" );
616 layer_type = wxT(
"Dielectric" );
619 if( sub_layer_count > 1 )
634 layer_json[
"Type"] = layer_type;
640 wxString colorName = item->
GetColor( sub_idx );
642 if( colorName.StartsWith( wxT(
"#" ) ) )
648 colorName.Printf( wxT(
"R%dG%dB%d" ),
655 const std::vector<FAB_LAYER_COLOR>& color_list =
666 if( colorName == prm_color.GetName() )
668 colorName = prm_color.GetColorAsString();
674 layer_json[
"Color"] = colorName;
679 layer_json[
"Thickness"] = thickness;
685 layer_json[
"Material"] = item->
GetMaterial( sub_idx );
696 layer_json[
"DielectricConstant"] = item->
FormatEpsilonR( sub_idx );
710 if( last_copper_layer ==
F_Cu )
711 next_copper_layer =
In1_Cu;
715 next_copper_layer =
B_Cu;
717 wxString subLayerName;
719 if( sub_layer_count > 1 )
720 subLayerName.Printf( wxT(
" (%d/%d)" ), sub_idx + 1, sub_layer_count );
722 wxString
name = wxString::Format( wxT(
"%s/%s%s" ),
727 layer_json[
"Name"] =
name;
732 note << wxString::Format( wxT(
"Type: %s" ), layer_name.c_str() );
734 note << wxString::Format( wxT(
" (from %s to %s)" ),
738 layer_json[
"Notes"] = note;
764 layer_json[
"Name"] = layer_name.c_str();
768 layer_json[
"Name"] = layer_name.c_str();
771 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)
Test 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.