KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gendrill_excellon_writer.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 Jean_Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
26
27
33
34#include <plotters/plotter.h>
35#include <string_utils.h>
36#include <macros.h>
37#include <pcb_edit_frame.h>
38#include <build_version.h>
39#include <math/util.h> // for KiROUND
40#include <trigo.h>
41
42#include <pcbplot.h>
43#include <board.h>
47#include <reporter.h>
48#include <gbr_metadata.h>
49
50#include <fmt/format.h>
51
52
53// Oblong holes can be drilled by a "canned slot" command (G85) or a routing command
54// a linear routing command (G01) is perhaps more usual for drill files
55//
56// set m_useRouteModeForOval to false to use a canned slot hole (old way)
57// set m_useRouteModeForOval to true (preferred mode) to use a linear routed hole (new way)
58
59
61 : GENDRILL_WRITER_BASE( aPcb )
62{
63 m_file = nullptr;
65 m_conversionUnits = 0.0001;
66 m_mirror = false;
67 m_merge_PTH_NPTH = false;
68 m_minimalHeader = false;
71 m_mantissaLenght = 3; // suitable to print coordinates in mm
72}
73
74
75bool EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill,
76 bool aGenMap, REPORTER * aReporter )
77{
78 bool success = true;
79 wxFileName fn;
80 wxString msg;
81
82 std::vector<DRILL_SPAN> hole_sets = EnumerateDrillSpans( *m_pcb );
83
84 if( !m_merge_PTH_NPTH )
85 hole_sets.emplace_back( F_Cu, B_Cu, false, true );
86
87 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
88 it != hole_sets.end(); ++it )
89 {
90 const DRILL_SPAN& span = *it;
91 bool doing_npth = m_merge_PTH_NPTH ? false : span.m_IsNonPlatedFile;
92
93 buildHolesList( span, doing_npth );
94
95 // The file is created if it has holes, or if it is the non plated drill file to be
96 // sure the NPTH file is up to date in separate files mode.
97 // Also a PTH drill/map file is always created, to be sure at least one plated hole
98 // drill file is created (do not create any PTH drill file can be seen as not working
99 // drill generator).
100 if( getHolesCount() > 0 || doing_npth || span.Pair() == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
101 {
102 fn = getDrillFileName( span, doing_npth, m_merge_PTH_NPTH );
103 fn.SetPath( aPlotDirectory );
104
105 if( aGenDrill )
106 {
107 wxString fullFilename = fn.GetFullPath();
108
109 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
110
111 if( file == nullptr )
112 {
113 if( aReporter )
114 {
115 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
116 aReporter->Report( msg, RPT_SEVERITY_ERROR );
117 success = false;
118 }
119
120 break;
121 }
122 else
123 {
124 if( aReporter )
125 {
126 msg.Printf( _( "Created file '%s'" ), fullFilename );
127 aReporter->Report( msg, RPT_SEVERITY_ACTION );
128 }
129 }
130
131 TYPE_FILE file_type = TYPE_FILE::PTH_FILE;
132
133 if( span.Pair() == DRILL_LAYER_PAIR( F_Cu, B_Cu ) && !span.m_IsBackdrill )
134 {
135 if( m_merge_PTH_NPTH )
136 file_type = TYPE_FILE::MIXED_FILE;
137 else if( doing_npth )
138 file_type = TYPE_FILE::NPTH_FILE;
139 }
140 else if( span.m_IsBackdrill )
141 {
142 file_type = TYPE_FILE::NPTH_FILE;
143 }
144
145 bool wroteDrillFile = false;
146
147 try
148 {
149 createDrillFile( file, span, file_type );
150 wroteDrillFile = true;
151 }
152 catch( ... ) // Capture fmt::print exception on write issues
153 {
154 fclose( file );
155 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
156 aReporter->Report( msg, RPT_SEVERITY_ERROR );
157 success = false;
158 }
159
160 if( wroteDrillFile && span.m_IsBackdrill && getHolesCount() > 0 )
161 {
162 if( !writeBackdrillLayerPairFile( aPlotDirectory, aReporter, span ) )
163 {
164 success = false;
165 break;
166 }
167 }
168
169 if( wroteDrillFile )
170 AddCreatedFile( fullFilename );
171 }
172 }
173 }
174
175 if( aGenMap )
176 success &= CreateMapFilesSet( aPlotDirectory, aReporter );
177
178 if( aReporter )
179 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
180
181 return success;
182}
183
184
186{
187 // Hole attributes are comments (lines starting by ';') in the drill files
188 // For tools (file header), they are similar to X2 apertures attributes.
189 // for attributes added in coordinate list, they are just comments.
190 if( !m_minimalHeader )
191 {
192 switch( aAttribute )
193 {
195 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ViaDrill\n" );
196 break;
197
199 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,Buried,ViaDrill\n" );
200 break;
201
204 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,BackDrill\n" );
205 break;
206
208 //case HOLE_ATTRIBUTE::HOLE_PAD_CASTELLATED:
209 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
210 break;
211
213 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
214 break;
215
217 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
218 break;
219
221 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
222 break;
223
225 fmt::print( m_file, "{}", "; #@! TD\n" );
226 break;
227 }
228 }
229}
230
231
232int EXCELLON_WRITER::createDrillFile( FILE* aFile, const DRILL_SPAN& aSpan,
233 TYPE_FILE aHolesType, bool aTagBackdrillHit )
234{
235 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
236 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
238
239 m_file = aFile;
240
241 int diam, holes_count;
242 int x0, y0, xf, yf, xc, yc;
243 double xt, yt;
244 char line[1024];
245
246 writeEXCELLONHeader( aSpan, aHolesType );
247
248 holes_count = 0;
249
250 /* Write the tool list */
251 for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
252 {
253 DRILL_TOOL& tool_descr = m_toolListBuffer[ii];
254
255#if USE_ATTRIB_FOR_HOLES
257#endif
258 fmt::print( m_file, "T{}C{:.{}f}\n", ii + 1, tool_descr.m_Diameter * m_conversionUnits, m_mantissaLenght );
259
260 if( !m_minimalHeader )
261 {
262 if( tool_descr.m_IsBackdrill )
263 {
264 auto formatStub = [&]( int aStubLength )
265 {
266 double stubMM = pcbIUScale.IUTomm( aStubLength );
267 double stubInches = stubMM / 25.4;
268 wxString tmp = fmt::format( "{:.3f}mm ({:.4f}\")", stubMM, stubInches );
269 return tmp;
270 };
271
272 wxString comment = wxT( "; Backdrill" );
273
274 if( tool_descr.m_MinStubLength.has_value() )
275 {
276 comment += wxT( " stub " );
277 comment += formatStub( *tool_descr.m_MinStubLength );;
278
279 if( tool_descr.m_MaxStubLength.has_value()
280 && tool_descr.m_MaxStubLength != tool_descr.m_MinStubLength )
281 {
282 comment += wxT( " to " );
283 comment += formatStub( *tool_descr.m_MaxStubLength );;
284 }
285 }
286
287 if( tool_descr.m_HasPostMachining )
288 comment += wxT( ", post-machining" );
289
290 comment += wxT( "\n" );
291 fmt::print( m_file, "{}", TO_UTF8( comment ) );
292 }
293 else if( tool_descr.m_HasPostMachining )
294 {
295 fmt::print( m_file, "{}", "; Post-machining\n" );
296 }
297 }
298 }
299
300 fmt::print( m_file, "{}", "%\n" ); // End of header info
301 fmt::print( m_file, "{}", "G90\n" ); // Absolute mode
302 fmt::print( m_file, "{}", "G05\n" ); // Drill mode
303
304 /* Read the hole list and generate data for normal holes (oblong
305 * holes will be created later) */
306 int tool_reference = -2;
307
308 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
309 {
310 const DRILL_OPERATION& hole_descr = m_holeListBuffer[ii];
311
312 if( hole_descr.m_IsSlot )
313 continue; // oblong holes will be created later
314
315 if( tool_reference != m_holeToolReferences[ii] )
316 {
317 tool_reference = m_holeToolReferences[ii];
318 fmt::print( m_file, "T{}\n", tool_reference );
319 }
320
321 x0 = hole_descr.m_Position.x - m_offset.x;
322 y0 = hole_descr.m_Position.y - m_offset.y;
323
324 if( !m_mirror )
325 y0 *= -1;
326
327 xt = x0 * m_conversionUnits;
328 yt = y0 * m_conversionUnits;
329 writeHoleComments( hole_descr, aTagBackdrillHit );
330 writeCoordinates( line, sizeof( line ), xt, yt );
331
332 fmt::print( m_file, "{}", line );
333 holes_count++;
334 }
335
336 /* Read the hole list and generate data for oblong holes
337 */
338 tool_reference = -2; // set to a value not used for
339 // m_holeToolReferences[ii]
340
341 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
342 {
343 const DRILL_OPERATION& hole_descr = m_holeListBuffer[ii];
344
345 if( !hole_descr.m_IsSlot )
346 continue; // wait for oblong holes
347
348 if( tool_reference != m_holeToolReferences[ii] )
349 {
350 tool_reference = m_holeToolReferences[ii];
351 fmt::print( m_file, "T{}\n", tool_reference );
352 }
353
354 diam = std::min( hole_descr.m_SizeXY.x, hole_descr.m_SizeXY.y );
355
356 if( diam == 0 )
357 continue;
358
359 /* Compute the hole coordinates: */
360 xc = x0 = xf = hole_descr.m_Position.x - m_offset.x;
361 yc = y0 = yf = hole_descr.m_Position.y - m_offset.y;
362
363 /* Compute the start and end coordinates for the shape */
364 if( hole_descr.m_SizeXY.x < hole_descr.m_SizeXY.y )
365 {
366 int delta = ( hole_descr.m_SizeXY.y - hole_descr.m_SizeXY.x ) / 2;
367 y0 -= delta;
368 yf += delta;
369 }
370 else
371 {
372 int delta = ( hole_descr.m_SizeXY.x - hole_descr.m_SizeXY.y ) / 2;
373 x0 -= delta;
374 xf += delta;
375 }
376
377 RotatePoint( &x0, &y0, xc, yc, hole_descr.m_Orientation );
378 RotatePoint( &xf, &yf, xc, yc, hole_descr.m_Orientation );
379
380 if( !m_mirror )
381 {
382 y0 *= -1;
383 yf *= -1;
384 }
385
386 xt = x0 * m_conversionUnits;
387 yt = y0 * m_conversionUnits;
388 writeHoleComments( hole_descr, aTagBackdrillHit );
389
391 fmt::print( m_file, "{}", "G00" ); // Select the routing mode
392
393 writeCoordinates( line, sizeof( line ), xt, yt );
394
396 {
397 /* remove the '\n' from end of line, because we must add the "G85"
398 * command to the line: */
399 for( int kk = 0; line[kk] != 0; kk++ )
400 {
401 if( line[kk] < ' ' )
402 line[kk] = 0;
403 }
404
405 fmt::print( m_file, "{}", line );
406 fmt::print( m_file, "{}", "G85" ); // add the "G85" command
407 }
408 else
409 {
410 fmt::print( m_file, "{}", line );
411 fmt::print( m_file, "{}", "M15\nG01" ); // tool down and linear routing from last coordinates
412 }
413
414 xt = xf * m_conversionUnits;
415 yt = yf * m_conversionUnits;
416 writeCoordinates( line, sizeof( line ), xt, yt );
417
418 fmt::print( m_file, "{}",line );
419
421 fmt::print( m_file, "{}", "M16\n" ); // Tool up (end routing)
422
423 fmt::print( m_file, "{}", "G05\n" ); // Select drill mode
424 holes_count++;
425 }
426
428
429 return holes_count;
430}
431
432
433void EXCELLON_WRITER::SetFormat( bool aMetric, ZEROS_FMT aZerosFmt, int aLeftDigits,
434 int aRightDigits )
435{
436 m_unitsMetric = aMetric;
437 m_zeroFormat = aZerosFmt;
438
439 /* Set conversion scale depending on drill file units */
440 if( m_unitsMetric )
441 m_conversionUnits = 1.0 / pcbIUScale.IU_PER_MM; // EXCELLON units = mm
442 else
443 m_conversionUnits = 0.001 / pcbIUScale.IU_PER_MILS; // EXCELLON units = in
444
445 // Set the zero counts. if aZerosFmt == DECIMAL_FORMAT, these values
446 // will be set, but not used.
447 if( aLeftDigits <= 0 )
448 aLeftDigits = m_unitsMetric ? 3 : 2;
449
450 if( aRightDigits <= 0 )
451 aRightDigits = m_unitsMetric ? 3 : 4;
452
453 m_precision.m_Lhs = aLeftDigits;
454 m_precision.m_Rhs = aRightDigits;
455}
456
457
458void EXCELLON_WRITER::writeCoordinates( char* aLine, size_t aLineSize, double aCoordX,
459 double aCoordY )
460{
461 wxString xs, ys;
462 int xpad = m_precision.m_Lhs + m_precision.m_Rhs;
463 int ypad = xpad;
464
465 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
466 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
467 // in DECIMAL_FORMAT we could use more digits.
468
469 switch( m_zeroFormat )
470 {
471 default:
472 case DECIMAL_FORMAT:
473 /* In Excellon files, resolution is 1/1000 mm or 1/10000 inch (0.1 mil)
474 * Although in decimal format, Excellon specifications do not specify
475 * clearly the resolution. However it seems to be usually 1/1000mm or 0.1 mil
476 * like in non decimal formats, so we trunk coordinates to m_mantissaLenght in mantissa
477 * Decimal format just prohibit useless leading 0:
478 * 0.45 or .45 is right, but 00.54 is incorrect.
479 */
480 xs = fmt::format( "{:.{}f}", aCoordX, m_mantissaLenght );
481 ys = fmt::format( "{:.{}f}", aCoordY, m_mantissaLenght );
482
483 //Remove useless trailing 0
484 while( xs.Last() == '0' )
485 xs.RemoveLast();
486
487 if( xs.Last() == '.' ) // however keep a trailing 0 after the floating point separator
488 xs << '0';
489
490 while( ys.Last() == '0' )
491 ys.RemoveLast();
492
493 if( ys.Last() == '.' )
494 ys << '0';
495
496 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
497 break;
498
499 case SUPPRESS_LEADING:
500 for( int i = 0; i< m_precision.m_Rhs; i++ )
501 {
502 aCoordX *= 10; aCoordY *= 10;
503 }
504
505 std::snprintf( aLine, aLineSize, "X%dY%d\n", KiROUND( aCoordX ), KiROUND( aCoordY ) );
506 break;
507
509 {
510 for( int i = 0; i < m_precision.m_Rhs; i++ )
511 {
512 aCoordX *= 10;
513 aCoordY *= 10;
514 }
515
516 if( aCoordX < 0 )
517 xpad++;
518
519 if( aCoordY < 0 )
520 ypad++;
521
522 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
523 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
524
525 size_t j = xs.Len() - 1;
526
527 while( xs[j] == '0' && j )
528 xs.Truncate( j-- );
529
530 j = ys.Len() - 1;
531
532 while( ys[j] == '0' && j )
533 ys.Truncate( j-- );
534
535 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
536 break;
537 }
538
539 case KEEP_ZEROS:
540 for( int i = 0; i< m_precision.m_Rhs; i++ )
541 {
542 aCoordX *= 10; aCoordY *= 10;
543 }
544
545 if( aCoordX < 0 )
546 xpad++;
547
548 if( aCoordY < 0 )
549 ypad++;
550
551 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
552 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
553 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
554 break;
555 }
556}
557
558
560{
561 fmt::print( m_file, "{}", "M48\n" ); // The beginning of a header
562
563 if( !m_minimalHeader )
564 {
565 // The next lines in EXCELLON files are comments:
566 wxString msg;
567 msg << wxT( "KiCad " ) << GetBuildVersion();
568
569 fmt::print( m_file, "; DRILL file {} date {}\n",
571 msg = wxT( "; FORMAT={" );
572
573 // Print precision:
574 // Note in decimal format the precision is not used.
575 // the floating point notation has higher priority than the precision.
577 msg << m_precision.GetPrecisionString();
578 else
579 msg << wxT( "-:-" ); // in decimal format the precision is irrelevant
580
581 msg << wxT( "/ absolute / " );
582 msg << ( m_unitsMetric ? wxT( "metric" ) : wxT( "inch" ) );
583
584 /* Adding numbers notation format.
585 * this is same as m_Choice_Zeros_Format strings, but NOT translated
586 * because some EXCELLON parsers do not like non ASCII values
587 * so we use ONLY English (ASCII) strings.
588 * if new options are added in m_Choice_Zeros_Format, they must also
589 * be added here
590 */
591 msg << wxT( " / " );
592
593 const wxString zero_fmt[4] =
594 {
595 wxT( "decimal" ),
596 wxT( "suppress leading zeros" ),
597 wxT( "suppress trailing zeros" ),
598 wxT( "keep zeros" )
599 };
600
601 msg << zero_fmt[m_zeroFormat] << wxT( "}\n" );
602 fmt::print( m_file, "{}", TO_UTF8( msg ) );
603
604 // add the structured comment TF.CreationDate:
605 // The attribute value must conform to the full version of the ISO 8601
607 fmt::print( m_file, "{}", TO_UTF8( msg ) );
608
609 // Add the application name that created the drill file
610 msg = wxT( "; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
611 msg << GetBuildVersion() << wxT( "\n" );
612 fmt::print( m_file, "{}", TO_UTF8( msg ) );
613
614 // Add the standard X2 FileFunction for drill files
615 // TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH]
616 msg = BuildFileFunctionAttributeString( aSpan, aHolesType , true ) + wxT( "\n" );
617 fmt::print( m_file, "{}", TO_UTF8( msg ) );
618
619 fmt::print( m_file, "{}", "FMAT,2\n" ); // Use Format 2 commands (version used since 1979)
620 }
621
622 fmt::print( m_file, "{}", m_unitsMetric ? "METRIC" : "INCH" );
623
624 switch( m_zeroFormat )
625 {
626 case DECIMAL_FORMAT:
627 fmt::print( m_file, "{}", "\n" );
628 break;
629
630 case SUPPRESS_LEADING:
631 fmt::print( m_file, "{}", ",TZ\n" );
632 break;
633
635 fmt::print( m_file, "{}", ",LZ\n" );
636 break;
637
638 case KEEP_ZEROS:
639 // write nothing, but TZ is acceptable when all zeros are kept
640 fmt::print( m_file, "{}", "\n" );
641 break;
642 }
643}
644
645
647{
648 // add if minimal here
649 fmt::print( m_file, "{}", "M30\n" );
650 fclose( m_file );
651}
652
653
655{
656 wxFileName fn = m_pcb->GetFileName();
657 wxString extend;
658
659 extend << wxT( "-" )
660 << wxString::FromUTF8( layerPairName( aSpan.Pair() ).c_str() )
661 << wxT( "-backdrill" );
662
663 fn.SetName( fn.GetName() + extend );
664 fn.SetExt( m_drillFileExtension );
665
666 return fn;
667}
668
669
670bool EXCELLON_WRITER::writeBackdrillLayerPairFile( const wxString& aPlotDirectory,
671 REPORTER* aReporter, const DRILL_SPAN& aSpan )
672{
673 wxFileName fn = getBackdrillLayerPairFileName( aSpan );
674 fn.SetPath( aPlotDirectory );
675
676 wxString fullFilename = fn.GetFullPath();
677 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
678
679 if( file == nullptr )
680 {
681 if( aReporter )
682 {
683 wxString msg;
684 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
685 aReporter->Report( msg, RPT_SEVERITY_ERROR );
686 }
687
688 return false;
689 }
690 else if( aReporter )
691 {
692 wxString msg;
693 msg.Printf( _( "Created file '%s'" ), fullFilename );
694 aReporter->Report( msg, RPT_SEVERITY_ACTION );
695 }
696
697 try
698 {
699 createDrillFile( file, aSpan, TYPE_FILE::NPTH_FILE, true );
700 }
701 catch( ... )
702 {
703 fclose( file );
704
705 if( aReporter )
706 {
707 wxString msg;
708 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
709 aReporter->Report( msg, RPT_SEVERITY_ERROR );
710 }
711
712 return false;
713 }
714
715 AddCreatedFile( fullFilename );
716
717 return true;
718}
719
720void EXCELLON_WRITER::writeHoleComments( const DRILL_OPERATION& aHole, bool aTagBackdrillHit )
721{
722 if( aTagBackdrillHit && aHole.IsBackdrill() )
723 fmt::print( m_file, "{}", "; backdrill\n" );
724
727 wxT( "front" ) );
728
731 wxT( "back" ) );
732}
733
734
736 int aSizeIU, int aDepthIU, int aAngleDeciDegree,
737 const wxString& aSideLabel )
738{
741 {
742 return;
743 }
744
745 wxString comment;
746 comment << wxT( "; Post-machining " ) << aSideLabel << wxT( " " )
747 << ( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK ? wxT( "countersink" )
748 : wxT( "counterbore" ) );
749
750 wxString sizeStr = formatLinearValue( aSizeIU );
751
752 if( !sizeStr.IsEmpty() )
753 comment << wxT( " dia " ) << sizeStr;
754
755 wxString depthStr = formatLinearValue( aDepthIU );
756
757 if( !depthStr.IsEmpty() )
758 comment << wxT( " depth " ) << depthStr;
759
760 if( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK && aAngleDeciDegree > 0 )
761 {
762 double angle = aAngleDeciDegree / 10.0;
763 wxString angleStr;
764
765 if( ( aAngleDeciDegree % 10 ) == 0 )
766 angleStr = fmt::format( "{:.0f}deg", angle );
767 else
768 angleStr = fmt::format( "{:.1f}deg", angle );
769
770 comment << wxT( " angle " ) << angleStr;
771 }
772
773 comment << wxT( "\n" );
774 fmt::print( m_file, "{}", TO_UTF8( comment ) );
775}
776
777
778wxString EXCELLON_WRITER::formatLinearValue( int aValueIU ) const
779{
780 if( aValueIU <= 0 )
781 return wxString();
782
783 double converted = aValueIU * m_conversionUnits;
784 wxString value;
785 value = fmt::format( "{:.{}f}", converted, m_mantissaLenght );
786 value << ( m_unitsMetric ? wxT( "mm" ) : wxT( "in" ) );
787
788 return value;
789}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:982
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
std::optional< int > m_MinStubLength
HOLE_ATTRIBUTE m_HoleAttribute
std::optional< int > m_MaxStubLength
void SetFormat(bool aMetric, ZEROS_FMT aZerosFmt=DECIMAL_FORMAT, int aLeftDigits=0, int aRightDigits=0)
Initialize internal parameters to match the given format.
void writeCoordinates(char *aLine, size_t aLineSize, double aCoordX, double aCoordY)
Create a line like according to the selected format.
void writeHoleComments(const DRILL_OPERATION &aHole, bool aTagBackdrillHit)
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.
wxFileName getBackdrillLayerPairFileName(const DRILL_SPAN &aSpan) const
wxString formatLinearValue(int aValueIU) const
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.
void AddCreatedFile(const wxString &aPath)
void buildHolesList(const DRILL_SPAN &aSpan, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
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...
std::vector< int > m_holeToolReferences
std::vector< DRILL_OPERATION > m_holeListBuffer
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
The standard X2 FileFunction for drill files is %TF.FileFunction,Plated[NonPlated],...
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
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.
Definition reporter.h:121
std::vector< DRILL_SPAN > EnumerateDrillSpans(const BOARD &aBoard, bool aPadBackdrills)
Every drill span present on the board, through-holes first.
HOLE_ATTRIBUTE
Definition drill_span.h:36
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
Definition drill_span.h:49
#define _(s)
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
Handle special data (items attributes) during plot.
@ GBR_NC_STRING_FORMAT_NCDRILL
Classes used in drill files, map files and report files generation.
static const std::string DrillFileExtension
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition idf_helpers.h:37
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:75
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
wxString GetISO8601CurrentDateTime()
One machining action, which is also one NC hit and one tool assignment.
bool IsBackdrill() const
DRILL_POST_MACHINING m_BackPostMachining
VECTOR2I m_SizeXY
Source axes, never normalized to (width, length).
EDA_ANGLE m_Orientation
DRILL_POST_MACHINING m_FrontPostMachining
int m_Size
int m_Depth
int m_Angle
PAD_DRILL_POST_MACHINING_MODE m_Mode
DRILL_LAYER_PAIR Pair() const
Definition drill_span.h:93
bool m_IsNonPlatedFile
Definition drill_span.h:131
bool m_IsBackdrill
Definition drill_span.h:130
int delta
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 trigo.cpp:227
Definition of file extensions used in Kicad.