65 for(
unsigned long letter : aText )
67 if( letter >=
' ' && letter <= 0x7F )
68 fmt_text += char( letter );
72 std::snprintf( buff,
sizeof( buff ),
"\\u%4.4lX", letter );
117 const char* value =
nullptr;
153 msg.Printf(
_(
"Failed to create file '%s'." ), aFullFilename );
159 msg.Printf(
_(
"Created Gerber job file '%s'." ), aFullFilename );
171 "GenerationSoftware",
173 {
"Vendor",
"KiCad" },
174 {
"Application",
"Pcbnew" },
190 std::ofstream file( aFullFilename.ToUTF8() );
194 m_json = nlohmann::ordered_json( {} );
211 file << std::setw( 2 ) <<
m_json << std::endl;
227 sscanf( buffer,
"%Lg", &output );
236 m_json[
"GeneralSpecs"] = nlohmann::ordered_json( {} );
237 m_json[
"GeneralSpecs"][
"ProjectId"] = nlohmann::ordered_json( {} );
249 wxString msg = fn.GetFullName();
264 m_json[
"GeneralSpecs"][
"ProjectId"][
"Name"] = msg.ToAscii();
265 m_json[
"GeneralSpecs"][
"ProjectId"][
"GUID"] = guid;
266 m_json[
"GeneralSpecs"][
"ProjectId"][
"Revision"] = rev.ToAscii();
280 m_json[
"GeneralSpecs"][
"BoardThickness"] =
290 m_json[
"GeneralSpecs"][
"ImpedanceControlled"] =
true;
293 m_json[
"GeneralSpecs"][
"Castellated"] =
true;
296 m_json[
"GeneralSpecs"][
"EdgePlating"] =
true;
300 m_json[
"GeneralSpecs"][
"EdgeConnector"] =
true;
302 m_json[
"GeneralSpecs"][
"EdgeConnectorBevelled"] =
315 m_json[
"GeneralSpecs"][
"IPC-2221-Type"] = 4;
331 m_json[
"GeneralSpecs"][
"ViaProtection"] =
"Ib";
339 m_json[
"FilesAttributes"] = nlohmann::ordered_json::array();
345 wxString gbr_layer_id;
346 bool skip_file =
false;
347 const char* polarity =
"Positive";
349 nlohmann::ordered_json file_json;
353 gbr_layer_id = wxT(
"Copper,L" );
358 gbr_layer_id << layer + 1;
360 gbr_layer_id << wxT(
"," );
363 gbr_layer_id << wxT(
"Bot" );
364 else if( layer ==
F_Cu )
365 gbr_layer_id << wxT(
"Top" );
367 gbr_layer_id << wxT(
"Inr" );
375 gbr_layer_id = wxT(
"Glue,Bot" );
378 gbr_layer_id = wxT(
"Glue,Top" );
382 gbr_layer_id = wxT(
"SolderPaste,Bot" );
385 gbr_layer_id = wxT(
"SolderPaste,Top" );
389 gbr_layer_id = wxT(
"Legend,Bot" );
392 gbr_layer_id = wxT(
"Legend,Top" );
396 gbr_layer_id = wxT(
"SolderMask,Bot" );
397 polarity =
"Negative";
400 gbr_layer_id = wxT(
"SolderMask,Top" );
401 polarity =
"Negative";
405 gbr_layer_id = wxT(
"Profile" );
409 gbr_layer_id = wxT(
"AssemblyDrawing,Bot" );
412 gbr_layer_id = wxT(
"AssemblyDrawing,Top" );
434 gbr_layer_id = wxT(
"Other,User" );
453 file_json[
"Path"] = strname.c_str();
454 file_json[
"FileFunction"] = gbr_layer_id;
455 file_json[
"FilePolarity"] = polarity;
457 m_json[
"FilesAttributes"] += file_json;
469 int minclearanceOuter = netSettings->m_DefaultNetClass->GetClearance();
473 for(
const auto& [
name, netclass ] : netSettings->m_NetClasses )
474 minclearanceOuter = std::min( minclearanceOuter, netclass->GetClearance() );
478 int minclearance_track2track = minclearanceOuter;
483 int minPadClearanceOuter = netSettings->m_DefaultNetClass->GetClearance();
484 int minPadClearanceInner = netSettings->m_DefaultNetClass->GetClearance();
488 for(
PAD*
pad : footprint->Pads() )
492 int padClearance =
pad->GetOwnClearance( layer );
494 if( layer ==
B_Cu || layer ==
F_Cu )
495 minPadClearanceOuter = std::min( minPadClearanceOuter, padClearance );
497 minPadClearanceInner = std::min( minPadClearanceInner, padClearance );
502 m_json[
"DesignRules"] = { {
503 {
"Layers",
"Outer" },
504 {
"PadToPad",
mapValue( minPadClearanceOuter ) },
505 {
"PadToTrack",
mapValue( minPadClearanceOuter ) },
506 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
510 int minclearanceInner = minclearanceOuter;
513 int mintrackWidthOuter = INT_MAX;
514 int mintrackWidthInner = INT_MAX;
521 if( track->GetLayer() ==
B_Cu || track->GetLayer() ==
F_Cu )
522 mintrackWidthOuter = std::min( mintrackWidthOuter, track->GetWidth() );
524 mintrackWidthInner = std::min( mintrackWidthInner, track->GetWidth() );
527 if( mintrackWidthOuter != INT_MAX )
528 m_json[
"DesignRules"][0][
"MinLineWidth"] =
mapValue( mintrackWidthOuter );
533 minclearanceOuter = INT_MAX;
534 minclearanceInner = INT_MAX;
538 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
543 int zclerance = zone->GetOwnClearance( layer );
545 if( layer ==
B_Cu || layer ==
F_Cu )
546 minclearanceOuter = std::min( minclearanceOuter, zclerance );
548 minclearanceInner = std::min( minclearanceInner, zclerance );
552 if( minclearanceOuter != INT_MAX )
553 m_json[
"DesignRules"][0][
"TrackToRegion"] =
mapValue( minclearanceOuter );
555 if( minclearanceOuter != INT_MAX )
556 m_json[
"DesignRules"][0][
"RegionToRegion"] =
mapValue( minclearanceOuter );
560 m_json[
"DesignRules"] += nlohmann::ordered_json( {
561 {
"Layers",
"Inner" },
562 {
"PadToPad",
mapValue( minPadClearanceInner ) },
563 {
"PadToTrack",
mapValue( minPadClearanceInner ) },
564 {
"TrackToTrack",
mapValue( minclearance_track2track ) }
567 if( mintrackWidthInner != INT_MAX )
568 m_json[
"DesignRules"][1][
"MinLineWidth"] =
mapValue( mintrackWidthInner );
570 if( minclearanceInner != INT_MAX )
571 m_json[
"DesignRules"][1][
"TrackToRegion"] =
mapValue( minclearanceInner );
573 if( minclearanceInner != INT_MAX )
574 m_json[
"DesignRules"][1][
"RegionToRegion"] =
mapValue( minclearanceInner );
582 m_json[
"MaterialStackup"] = nlohmann::ordered_json::array();
597 for(
int ii = 0; ii < brd_stackup.
GetCount(); ++ii )
601 int sub_layer_count =
604 for(
int sub_idx = 0; sub_idx < sub_layer_count; sub_idx++ )
609 std::string layer_name;
611 nlohmann::ordered_json layer_json;
616 layer_type = wxT(
"Copper" );
622 layer_type = wxT(
"Legend" );
627 layer_type = wxT(
"SolderMask" );
632 layer_type = wxT(
"SolderPaste" );
637 layer_type = wxT(
"Dielectric" );
640 if( sub_layer_count > 1 )
655 layer_json[
"Type"] = layer_type;
661 wxString colorName = item->
GetColor( sub_idx );
663 if( colorName.StartsWith( wxT(
"#" ) ) )
669 colorName.Printf( wxT(
"R%dG%dB%d" ),
676 const std::vector<FAB_LAYER_COLOR>& color_list =
687 if( colorName == prm_color.GetName() )
689 colorName = prm_color.GetColorAsString();
695 layer_json[
"Color"] = colorName;
700 layer_json[
"Thickness"] = thickness;
706 layer_json[
"Material"] = item->
GetMaterial( sub_idx );
717 layer_json[
"DielectricConstant"] = item->
FormatEpsilonR( sub_idx );
730 next_copper_layer =
B_Cu;
732 wxString subLayerName;
734 if( sub_layer_count > 1 )
735 subLayerName.Printf( wxT(
" (%d/%d)" ), sub_idx + 1, sub_layer_count );
737 wxString
name = wxString::Format( wxT(
"%s/%s%s" ),
742 layer_json[
"Name"] =
name;
747 note << wxString::Format( wxT(
"Type: %s" ), layer_name.c_str() );
749 note << wxString::Format( wxT(
" (from %s to %s)" ),
753 layer_json[
"Notes"] = note;
779 layer_json[
"Name"] = layer_name.c_str();
783 layer_json[
"Name"] = layer_name.c_str();
786 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....
TITLE_BLOCK & GetTitleBlock()
FOOTPRINTS & Footprints()
int GetCopperLayerCount() 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
coord_type GetHeight() const
coord_type GetWidth() 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)
Classes used to generate a Gerber job file in JSON.
PCB_LAYER_ID
A quick note on layer IDs:
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
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.