95 bool last_notplated_opt =
false;
177 int ly_id = ( aLayer -
B_Cu ) / 2;
178 return fmt::format(
"in{}", ly_id );
186 std::string ret =
layerName( aPair.first );
195 bool aMerge_PTH_NPTH )
const
203 int conventional_layer_num = 1;
207 if( layer == aLayer )
208 return conventional_layer_num;
210 conventional_layer_num++;
213 return conventional_layer_num;
218 extend.Printf( wxT(
"_Backdrills_Drill_%d_%d" ),
224 extend = wxT(
"-NPTH" );
228 if( !aMerge_PTH_NPTH )
229 extend = wxT(
"-PTH" );
238 wxFileName fn =
m_pcb->GetFileName();
240 fn.SetName( fn.GetName() + extend );
243 wxString ret = fn.GetFullName();
259 extend << wxT(
"-filling-" );
263 extend << wxT(
"-capping-" );
267 extend << wxT(
"-covering-" );
271 extend << wxT(
"-covering-" );
275 extend << wxT(
"-plugging-" );
279 extend << wxT(
"-plugging-" );
283 extend << wxT(
"-tenting-" );
287 extend << wxT(
"-tenting-" );
292 wxFileName fn =
m_pcb->GetFileName();
294 fn.SetName( fn.GetName() + extend );
297 wxString ret = fn.GetFullName();
311 hole_sets.emplace_back(
F_Cu,
B_Cu,
false,
true );
313 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin(); it != hole_sets.end(); ++it )
323 fn.SetPath( aPlotDirectory );
325 fn.SetExt( wxEmptyString );
326 wxString fullfilename = fn.GetFullPath() + wxT(
"-drl_map" );
335 msg.Printf(
_(
"Failed to create file '%s'." ), fullfilename );
345 msg.Printf(
_(
"Created file '%s'." ), fullfilename );
360 bool aCompatNCdrill )
const
367 text = wxT(
"; #@! " );
371 text << wxT(
"TF.FileFunction," );
374 text << wxT(
"NonPlated," );
376 text << wxT(
"MixedPlating," );
378 text << wxT(
"Plated," );
380 int layer1 = aSpan.
Pair().first;
381 int layer2 = aSpan.
Pair().second;
391 else if( layer1 ==
B_Cu )
392 layer1 =
m_pcb->GetCopperLayerCount();
394 layer1 = ( ( layer1 -
B_Cu ) / 2 ) + 1;
398 else if( layer2 ==
B_Cu )
399 layer2 =
m_pcb->GetCopperLayerCount();
401 layer2 = ( ( layer2 -
B_Cu ) / 2) + 1;
404 if( layer1 > layer2 )
405 std::swap( layer1, layer2 );
407 text << layer1 << wxT(
"," ) << layer2;
411 int bottomlayer =
m_pcb->GetCopperLayerCount();
414 text << wxT(
",Blind" );
416 text << wxT(
",NPTH" );
419 else if( layer1 == toplayer && layer2 == bottomlayer )
420 text << wxT(
",PTH" );
421 else if( layer1 == toplayer || layer2 == bottomlayer )
422 text << wxT(
",Blind" );
424 text << wxT(
",Buried" );
435 bool hasOblong =
false;
436 bool hasDrill =
false;
448 if( hasOblong && hasDrill )
449 text << wxT(
",Mixed" );
451 text << wxT(
",Drill" );
453 text << wxT(
",Rout" );
481 int bestsize = aMarkerDiameter / 10;
483 const double MIN_SIZE_MM = 0.1;
484 bestsize = std::max( bestsize,
pcbIUScale.mmToIU( MIN_SIZE_MM ) );
493 const double SKETCH_LINE_WIDTH_MM = 0.1;
494 return pcbIUScale.mmToIU( SKETCH_LINE_WIDTH_MM );
501 const double DEFAULT_LINE_WIDTH_MM = 0.2;
502 return pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH_MM );
516 int bottom_limit = 0;
524 LSET visibleLayers =
m_pcb->GetVisibleLayers();
526 BOX2I bbbox =
m_pcb->GetBoardEdgesBoundingBox();
527 m_pcb->SetVisibleLayers( visibleLayers );
557 double Xscale = double( pageSizeIU.
x - ( 2 * margin ) ) / bbbox.
GetWidth();
561 int ypagesize_for_board =
KiROUND( pageSizeIU.
y * 0.6 );
562 double Yscale = double( ypagesize_for_board - margin ) / bbbox.
GetHeight();
564 scale = std::min( Xscale, Yscale );
577 bottom_limit = ( pageSizeIU.
y - margin ) / std::min(
scale, 1.0 );
597 plotter = dxf_plotter;
612 if( !plotter->
OpenFile( aFullFileName ) )
635 text =
"%TF.FileFunction,Drillmap*%";
639 text = wxT(
"%TF.FilePolarity,Positive*%" );
657 switch( item->Type() )
675 for(
BOARD_ITEM* item : footprint->GraphicalItems() )
680 switch( item->Type() )
696 int plotX, plotY, TextWidth;
700 int textmarginaftersymbol =
pcbIUScale.mmToIU( 2 );
716 double charScale = std::min( 1.0, 1.0 /
scale );
718 TextWidth =
KiROUND( ( charSize * charScale ) / 10.0 );
719 intervalle =
KiROUND( charSize * charScale ) + TextWidth;
722 plotX =
KiROUND( bbbox.
GetX() + textmarginaftersymbol * charScale );
726 wxString Text = wxT(
"Drill Map:" );
731 attrs.
m_Size =
KiROUND( charSize * charScale, charSize * charScale );
742 int max_line_len = 0;
754 if( bottom_limit && ( plotY + intervalle > bottom_limit ) )
757 plotX += max_line_len +
pcbIUScale.mmToIU( 10 );
764 plot_diam = std::min( plot_diam,
KiROUND( charSize * charScale ) );
765 int x =
KiROUND( plotX - textmarginaftersymbol * charScale - plot_diam / 2.0 );
766 int y =
KiROUND( plotY + charSize * charScale );
780 extraInfo += wxT(
", castellated" );
782 extraInfo += wxT(
", press-fit" );
793 extraInfo += wxString::Format( wxT(
", backdrill stub %.3f-%.3fmm" ), minStub, maxStub );
797 extraInfo += wxString::Format( wxT(
", backdrill stub %.3fmm" ), minStub );
802 extraInfo += wxT(
", backdrill" );
807 extraInfo += wxT(
", post-machined" );
812 counts.Printf( wxT(
"(1 hole%s)" ), extraInfo );
814 counts.Printf( wxT(
"(1 slot%s)" ), extraInfo );
816 counts.Printf( wxT(
"(%d holes%s)" ), tool.
m_TotalCount, extraInfo );
818 counts.Printf( wxT(
"(%d holes + 1 slot%s)" ), tool.
m_TotalCount - 1, extraInfo );
827 msg += wxT(
" (not plated)" );
832 intervalle =
KiROUND( ( ( charSize * charScale ) + TextWidth ) * 1.2 );
834 if( intervalle < ( plot_diam + ( 1 *
pcbIUScale.IU_PER_MM /
scale ) + TextWidth ) )
835 intervalle = plot_diam + ( 1 *
pcbIUScale.IU_PER_MM /
scale ) + TextWidth;
839 int text_len = msg.Len() * ( ( charSize * charScale ) + TextWidth );
840 max_line_len = std::max( max_line_len, text_len + plot_diam );
852 wxFFile out( aFullFileName,
"wb" );
854 if( !out.IsOpened() )
858 wxString msg = wxString::Format(
_(
"Error creating drill report file '%s'" ),
866 FILE* outFp = out.fp();
868 static const char separator[] =
869 " =============================================================\n";
873 unsigned totalHoleCount;
874 wxFileName brdFilename(
m_pcb->GetFileName() );
878 bool writeError =
false;
882 fmt::print( outFp,
"Drill report for {}\n",
TO_UTF8( brdFilename.GetFullName() ) );
886 fmt::print( outFp,
"Copper Layer Stackup:\n" );
887 fmt::print( outFp,
"{}", separator );
889 int conventional_layer_num = 1;
893 fmt::print( outFp,
" L{:<2}: {:<25} {}\n", conventional_layer_num++,
898 fmt::print( outFp,
"\n\n" );
906 bool buildNPTHlist =
false;
909 for(
unsigned pair_ndx = 0; pair_ndx < hole_sets.size(); ++pair_ndx )
917 fmt::print( outFp,
"Drill file '{}' contains\n",
920 fmt::print( outFp,
" plated through holes:\n" );
921 fmt::print( outFp,
"{}", separator );
923 fmt::print( outFp,
" Total plated holes count {}\n", totalHoleCount );
927 fmt::print( outFp,
"Drill file '{}' contains\n",
930 fmt::print( outFp,
" backdrill span: '{}' to '{}':\n",
934 fmt::print( outFp,
"{}", separator );
936 fmt::print( outFp,
" Total backdrilled holes count {}\n", totalHoleCount );
940 fmt::print( outFp,
"Drill file '{}' contains\n",
943 fmt::print( outFp,
" holes connecting layer pair: '{} and {}' ({} vias):\n",
946 span.
Pair().first ==
F_Cu || span.
Pair().second ==
B_Cu ?
"blind" :
"buried" );
948 fmt::print( outFp,
"{}", separator );
950 fmt::print( outFp,
" Total plated holes count {}\n", totalHoleCount );
953 fmt::print( outFp,
"\n\n" );
959 buildNPTHlist =
true;
967 fmt::print( outFp,
"Not plated through holes are merged with plated holes\n" );
969 fmt::print( outFp,
"Drill file '{}' contains\n",
972 fmt::print( outFp,
" unplated through holes:\n" );
973 fmt::print( outFp,
"{}", separator );
975 fmt::print( outFp,
" Total unplated holes count {}\n", totalHoleCount );
977 catch(
const std::system_error& )
981 catch(
const fmt::format_error& )
986 if( writeError && aReporter )
988 wxString msg = wxString::Format(
_(
"Error writing drill report file '%s'" ), aFullFileName );
1024 unsigned totalHoleCount = 0;
1035 if( bucket != aSummary )
1039 int tool_number = ii+1;
1040 fmt::print( out,
" T{} {:2.3f}mm {:2.4f}\" ", tool_number,
1046 fmt::print( out,
"(1 hole" );
1048 fmt::print( out,
"(1 hole) (with 1 slot" );
1052 fmt::print( out,
"({} holes) (with 1 slot", tool.
m_TotalCount );
1057 fmt::print( out,
", castellated" );
1060 fmt::print( out,
", press-fit" );
1062 fmt::print( out,
")\n" );
1067 fmt::print( out,
"\n" );
1069 return totalHoleCount;
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr coord_type GetX() const
constexpr size_type GetHeight() const
constexpr coord_type GetBottom() const
void SetLayerSet(const LSET &aLayerMask)
void PlotShape(const PCB_SHAPE *aShape)
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
virtual void SetParentGroup(EDA_GROUP *aGroup)
virtual const wxString getProtectionFileName(const DRILL_SPAN &aSpan, IPC4761_FEATURES aFeature) const
const PAGE_INFO * m_pageInfo
unsigned printToolSummary(FILE *aOut, TOOL_SUMMARY aSummary) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
void AddCreatedFile(const wxString &aPath)
wxString m_drillFileExtension
TOOL_SUMMARY
Selects which subset of m_toolListBuffer a summary covers.
@ UNPLATED
Non-plated holes, excluding backdrills.
@ BACKDRILL
Backdrills, which are non-plated by construction.
void buildHolesList(const DRILL_SPAN &aSpan, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
bool genDrillMapFile(const wxString &aFullFileName, PLOT_FORMAT aFormat)
Plot a map of drill marks for holes.
VECTOR2I GetOffset()
Return the plot offset (usually the position of the drill/place origin).
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...
const std::string layerName(PCB_LAYER_ID aLayer) const
std::vector< int > m_holeToolReferences
int getHolesCount() const
std::vector< DRILL_OPERATION > m_holeListBuffer
virtual const wxString getDrillFileName(const DRILL_SPAN &aSpan, bool aNPTH, bool aMerge_PTH_NPTH) const
bool plotDrillMarks(PLOTTER *aPlotter)
Write the drill marks in PDF, POSTSCRIPT or other supported formats/.
const wxString BuildFileFunctionAttributeString(const DRILL_SPAN &aSpan, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
The standard X2 FileFunction for drill files is %TF.FileFunction,Plated[NonPlated],...
bool GenDrillReportFile(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Create a plain text report file giving a list of drill values and drill count for through holes,...
void UseX2format(bool aEnable)
void UseX2NetAttributes(bool aEnable)
void DisableApertMacros(bool aDisable)
Disable Aperture Macro (AM) command, only for broken Gerber Readers.
static const METRICS & Default()
PCB specific render settings.
void SetDefaultPenWidth(int aWidth)
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Describe the page size and margins of a paper page on which to eventually print or plot.
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Parameters and options when plotting/printing a board.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Base plotter engine class.
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
void Marker(const VECTOR2I &aPosition, int aDiameter, unsigned aShapeId)
Draw a pattern shape number aShapeId, to coord position.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetRenderSettings(RENDER_SETTINGS *aSettings)
static const int USE_DEFAULT_LINE_WIDTH
virtual void ThickOval(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, int aWidth, void *aData)
virtual bool StartPlot(const wxString &aPageNumber)=0
virtual void SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false)
virtual PLOT_FORMAT GetPlotterType() const =0
Return the effective plot engine in use.
virtual void SetCreator(const wxString &aCreator)
void ClearHeaderLinesList()
Remove all lines from the list of free lines to print at the beginning of the file.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror)=0
Set the plot offset and scaling for the current plot.
void AddLineToHeader(const wxString &aExtraString)
Add a line to the list of free lines to print at the beginning of the file.
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont=nullptr, const KIFONT::METRICS &aFontMetrics=KIFONT::METRICS::Default(), void *aData=nullptr)
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.
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
wxString GetDefaultPlotExtension(PLOT_FORMAT aFormat)
Return the default plot extension for a format.
std::vector< DRILL_SPAN > EnumerateDrillSpans(const BOARD &aBoard, bool aPadBackdrills)
Every drill span present on the board, through-holes first.
std::vector< DRILL_OPERATION > EnumerateDrillOperations(const BOARD &aBoard, const DRILL_QUERY &aQuery)
The one place that decides what the board's holes are.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
double diameter_in_mm(double ius)
double diameter_in_inches(double ius)
static int getMarkerBestPenSize(int aMarkerDiameter)
static bool cmpHoleSorting(const DRILL_OPERATION &a, const DRILL_OPERATION &b)
int getSketchOvalBestPenSize()
helper classes to handle hole info for drill files generators.
#define USE_ATTRIB_FOR_HOLES
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
PCB_LAYER_ID
A quick note on layer IDs:
PCB_LAYER_ID ToLAYER_ID(int aLayer)
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
void AddGerberX2Header(PLOTTER *aPlotter, const BOARD *aBoard, bool aUseX1CompatibilityMode)
Calculate some X2 attributes as defined in the Gerber file format specification J4 (chapter 5) and ad...
PLOT_FORMAT
The set of supported output plot formats.
Plotting engines similar to ps (PostScript, Gerber, svg)
std::vector< FAB_LAYER_COLOR > dummy
wxString GetISO8601CurrentDateTime()
One machining action, which is also one NC hit and one tool assignment.
DRILL_POST_MACHINING m_BackPostMachining
VECTOR2I m_SizeXY
Source axes, never normalized to (width, length).
DRILL_POST_MACHINING m_FrontPostMachining
std::optional< int > m_StubLength
HOLE_ATTRIBUTE m_Attribute
PAD_DRILL_POST_MACHINING_MODE m_Mode
Selects which operations EnumerateDrillOperations() returns.
bool m_NonPlatedOnly
Emit only non-plated holes.
bool m_MergePTHNPTH
Emit plated and non-plated together, as the merged drill file does.
DRILL_LAYER_PAIR Pair() const
PCB_LAYER_ID DrillEndLayer() const
PCB_LAYER_ID DrillStartLayer() const
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
VECTOR2< int32_t > VECTOR2I