49#include <fmt/format.h>
84 hole_sets.emplace_back(
F_Cu,
B_Cu,
false,
true );
86 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
87 it != hole_sets.end(); ++it )
102 fn.SetPath( aPlotDirectory );
106 wxString fullFilename = fn.GetFullPath();
108 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
110 if( file ==
nullptr )
114 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
125 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
136 else if( doing_npth )
144 bool wroteDrillFile =
false;
149 wroteDrillFile =
true;
154 msg.Printf(
_(
"Failed to write file '%s'." ), fullFilename );
191 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ViaDrill\n" );
195 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,Buried,ViaDrill\n" );
199 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,BackDrill\n" );
204 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
208 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
212 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
216 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
220 fmt::print(
m_file,
"{}",
"; #@! TD\n" );
228 TYPE_FILE aHolesType,
bool aTagBackdrillHit )
236 int diam, holes_count;
237 int x0, y0, xf, yf, xc, yc;
250#if USE_ATTRIB_FOR_HOLES
259 auto formatStub = [&](
int aStubLength )
261 double stubMM =
pcbIUScale.IUTomm( aStubLength );
262 double stubInches = stubMM / 25.4;
263 wxString tmp = fmt::format(
"{:.3f}mm ({:.4f}\")", stubMM, stubInches );
267 wxString comment = wxT(
"; Backdrill" );
271 comment += wxT(
" stub " );
277 comment += wxT(
" to " );
283 comment += wxT(
", post-machining" );
285 comment += wxT(
"\n" );
290 fmt::print(
m_file,
"{}",
"; Post-machining\n" );
295 fmt::print(
m_file,
"{}",
"%\n" );
296 fmt::print(
m_file,
"{}",
"G90\n" );
297 fmt::print(
m_file,
"{}",
"G05\n" );
301 int tool_reference = -2;
313 fmt::print(
m_file,
"T{}\n", tool_reference );
327 fmt::print(
m_file,
"{}", line );
346 fmt::print(
m_file,
"T{}\n", tool_reference );
386 fmt::print(
m_file,
"{}",
"G00" );
394 for(
int kk = 0; line[kk] != 0; kk++ )
400 fmt::print(
m_file,
"{}", line );
401 fmt::print(
m_file,
"{}",
"G85" );
405 fmt::print(
m_file,
"{}", line );
406 fmt::print(
m_file,
"{}",
"M15\nG01" );
413 fmt::print(
m_file,
"{}",line );
416 fmt::print(
m_file,
"{}",
"M16\n" );
418 fmt::print(
m_file,
"{}",
"G05\n" );
442 if( aLeftDigits <= 0 )
445 if( aRightDigits <= 0 )
479 while( xs.Last() ==
'0' )
482 if( xs.Last() ==
'.' )
485 while( ys.Last() ==
'0' )
488 if( ys.Last() ==
'.' )
491 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
497 aCoordX *= 10; aCoordY *= 10;
500 std::snprintf( aLine, aLineSize,
"X%dY%d\n",
KiROUND( aCoordX ),
KiROUND( aCoordY ) );
517 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
518 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
520 size_t j = xs.Len() - 1;
522 while( xs[j] ==
'0' && j )
527 while( ys[j] ==
'0' && j )
530 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
537 aCoordX *= 10; aCoordY *= 10;
546 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
547 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
548 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
556 fmt::print(
m_file,
"{}",
"M48\n" );
564 fmt::print(
m_file,
"; DRILL file {} date {}\n",
566 msg = wxT(
"; FORMAT={" );
576 msg << wxT(
"/ absolute / " );
588 const wxString zero_fmt[4] =
591 wxT(
"suppress leading zeros" ),
592 wxT(
"suppress trailing zeros" ),
605 msg = wxT(
"; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
614 fmt::print(
m_file,
"{}",
"FMAT,2\n" );
622 fmt::print(
m_file,
"{}",
"\n" );
626 fmt::print(
m_file,
"{}",
",TZ\n" );
630 fmt::print(
m_file,
"{}",
",LZ\n" );
635 fmt::print(
m_file,
"{}",
"\n" );
644 fmt::print(
m_file,
"{}",
"M30\n" );
651 wxFileName fn =
m_pcb->GetFileName();
656 << wxT(
"-backdrill" );
658 fn.SetName( fn.GetName() + extend );
669 fn.SetPath( aPlotDirectory );
671 wxString fullFilename = fn.GetFullPath();
672 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
674 if( file ==
nullptr )
679 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
688 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
703 msg.Printf(
_(
"Failed to write file '%s'." ), fullFilename );
717 fmt::print(
m_file,
"{}",
"; backdrill\n" );
730 int aSizeIU,
int aDepthIU,
int aAngleDeciDegree,
731 const wxString& aSideLabel )
740 comment << wxT(
"; Post-machining " ) << aSideLabel << wxT(
" " )
742 : wxT(
"counterbore" ) );
746 if( !sizeStr.IsEmpty() )
747 comment << wxT(
" dia " ) << sizeStr;
751 if( !depthStr.IsEmpty() )
752 comment << wxT(
" depth " ) << depthStr;
756 double angle = aAngleDeciDegree / 10.0;
759 if( ( aAngleDeciDegree % 10 ) == 0 )
760 angleStr = fmt::format(
"{:.0f}deg", angle );
762 angleStr = fmt::format(
"{:.1f}deg", angle );
764 comment << wxT(
" angle " ) << angleStr;
767 comment << wxT(
"\n" );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
void SetFormat(bool aMetric, ZEROS_FMT aZerosFmt=DECIMAL_FORMAT, int aLeftDigits=0, int aRightDigits=0)
Initialize internal parameters to match the given format.
bool m_useRouteModeForOval
void writeCoordinates(char *aLine, size_t aLineSize, double aCoordX, double aCoordY)
Create a line like according to the selected format.
int createDrillFile(FILE *aFile, const DRILL_SPAN &aSpan, TYPE_FILE aHolesType, bool aTagBackdrillHit=false)
Create an Excellon drill file.
void writePostMachiningComment(PAD_DRILL_POST_MACHINING_MODE aMode, int aSizeIU, int aDepthIU, int aAngleDeciDegree, const wxString &aSideLabel)
void writeHoleAttribute(HOLE_ATTRIBUTE aAttribute)
Write a comment string giving the hole attribute.
bool CreateDrillandMapFilesSet(const wxString &aPlotDirectory, bool aGenDrill, bool aGenMap, REPORTER *aReporter=nullptr)
Create the full set of Excellon drill file for the board.
EXCELLON_WRITER(BOARD *aPcb)
wxFileName getBackdrillLayerPairFileName(const DRILL_SPAN &aSpan) const
wxString formatLinearValue(int aValueIU) const
void writeEXCELLONEndOfFile()
void writeHoleComments(const HOLE_INFO &aHole, bool aTagBackdrillHit)
bool writeBackdrillLayerPairFile(const wxString &aPlotDirectory, REPORTER *aReporter, const DRILL_SPAN &aSpan)
void writeEXCELLONHeader(const DRILL_SPAN &aSpan, TYPE_FILE aHolesType)
Print the DRILL file header.
wxString m_drillFileExtension
std::vector< HOLE_INFO > m_holeListBuffer
void buildHolesList(const DRILL_SPAN &aSpan, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
DRILL_PRECISION m_precision
GENDRILL_WRITER_BASE(BOARD *aPcb)
std::vector< DRILL_SPAN > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
std::vector< DRILL_TOOL > m_toolListBuffer
const std::string layerPairName(DRILL_LAYER_PAIR aPair) const
bool CreateMapFilesSet(const wxString &aPlotDirectory, REPORTER *aReporter=nullptr)
Create the full set of map files for the board, in PS, PDF ... format (use SetMapFileFormat() to sele...
int getHolesCount() const
virtual const wxString getDrillFileName(const DRILL_SPAN &aSpan, bool aNPTH, bool aMerge_PTH_NPTH) const
const wxString BuildFileFunctionAttributeString(const DRILL_SPAN &aSpan, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
Handle hole which must be drilled (diameter, position and layers).
int m_FrontPostMachiningDepth
PAD_DRILL_POST_MACHINING_MODE m_FrontPostMachining
int m_FrontPostMachiningAngle
int m_BackPostMachiningDepth
int m_BackPostMachiningSize
PAD_DRILL_POST_MACHINING_MODE m_BackPostMachining
int m_FrontPostMachiningSize
int m_BackPostMachiningAngle
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
Classes used in drill files, map files and report files generation.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
static const std::string DrillFileExtension
This file contains miscellaneous commonly used macros and functions.
PAD_DRILL_POST_MACHINING_MODE
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
DRILL_LAYER_PAIR Pair() const
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition of file extensions used in Kicad.