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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
30
31
37
38#include <plotters/plotter.h>
39#include <string_utils.h>
40#include <macros.h>
41#include <pcb_edit_frame.h>
42#include <build_version.h>
43#include <math/util.h> // for KiROUND
44#include <trigo.h>
45
46#include <pcbplot.h>
47#include <board.h>
50#include <reporter.h>
51#include <gbr_metadata.h>
52
53#include <fmt/format.h>
54
55
56// Oblong holes can be drilled by a "canned slot" command (G85) or a routing command
57// a linear routing command (G01) is perhaps more usual for drill files
58//
59// set m_useRouteModeForOval to false to use a canned slot hole (old way)
60// set m_useRouteModeForOval to true (preferred mode) to use a linear routed hole (new way)
61
62
64 : GENDRILL_WRITER_BASE( aPcb )
65{
66 m_file = nullptr;
68 m_conversionUnits = 0.0001;
69 m_mirror = false;
70 m_merge_PTH_NPTH = false;
71 m_minimalHeader = false;
74 m_mantissaLenght = 3; // suitable to print coordinates in mm
75}
76
77
78bool EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill,
79 bool aGenMap, REPORTER * aReporter )
80{
81 bool success = true;
82 wxFileName fn;
83 wxString msg;
84
85 std::vector<DRILL_SPAN> hole_sets = getUniqueLayerPairs();
86
87 if( !m_merge_PTH_NPTH )
88 hole_sets.emplace_back( F_Cu, B_Cu, false, true );
89
90 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
91 it != hole_sets.end(); ++it )
92 {
93 const DRILL_SPAN& span = *it;
94 bool doing_npth = m_merge_PTH_NPTH ? false : span.m_IsNonPlatedFile;
95
96 buildHolesList( span, doing_npth );
97
98 // The file is created if it has holes, or if it is the non plated drill file to be
99 // sure the NPTH file is up to date in separate files mode.
100 // Also a PTH drill/map file is always created, to be sure at least one plated hole
101 // drill file is created (do not create any PTH drill file can be seen as not working
102 // drill generator).
103 if( getHolesCount() > 0 || doing_npth || span.Pair() == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
104 {
105 fn = getDrillFileName( span, doing_npth, m_merge_PTH_NPTH );
106 fn.SetPath( aPlotDirectory );
107
108 if( aGenDrill )
109 {
110 wxString fullFilename = fn.GetFullPath();
111
112 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
113
114 if( file == nullptr )
115 {
116 if( aReporter )
117 {
118 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
119 aReporter->Report( msg, RPT_SEVERITY_ERROR );
120 success = false;
121 }
122
123 break;
124 }
125 else
126 {
127 if( aReporter )
128 {
129 msg.Printf( _( "Created file '%s'" ), fullFilename );
130 aReporter->Report( msg, RPT_SEVERITY_ACTION );
131 }
132 }
133
134 TYPE_FILE file_type = TYPE_FILE::PTH_FILE;
135
136 if( span.Pair() == DRILL_LAYER_PAIR( F_Cu, B_Cu ) && !span.m_IsBackdrill )
137 {
138 if( m_merge_PTH_NPTH )
139 file_type = TYPE_FILE::MIXED_FILE;
140 else if( doing_npth )
141 file_type = TYPE_FILE::NPTH_FILE;
142 }
143 else if( span.m_IsBackdrill )
144 {
145 file_type = TYPE_FILE::NPTH_FILE;
146 }
147
148 bool wroteDrillFile = false;
149
150 try
151 {
152 createDrillFile( file, span, file_type );
153 wroteDrillFile = true;
154 }
155 catch( ... ) // Capture fmt::print exception on write issues
156 {
157 fclose( file );
158 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
159 aReporter->Report( msg, RPT_SEVERITY_ERROR );
160 success = false;
161 }
162
163 if( wroteDrillFile && span.m_IsBackdrill && getHolesCount() > 0 )
164 {
165 if( !writeBackdrillLayerPairFile( aPlotDirectory, aReporter, span ) )
166 {
167 success = false;
168 break;
169 }
170 }
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
203 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,BackDrill\n" );
204 break;
205
207 //case HOLE_ATTRIBUTE::HOLE_PAD_CASTELLATED:
208 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
209 break;
210
212 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
213 break;
214
216 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
217 break;
218
220 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
221 break;
222
224 fmt::print( m_file, "{}", "; #@! TD\n" );
225 break;
226 }
227 }
228}
229
230
231int EXCELLON_WRITER::createDrillFile( FILE* aFile, const DRILL_SPAN& aSpan,
232 TYPE_FILE aHolesType, bool aTagBackdrillHit )
233{
234 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
235 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
237
238 m_file = aFile;
239
240 int diam, holes_count;
241 int x0, y0, xf, yf, xc, yc;
242 double xt, yt;
243 char line[1024];
244
245 writeEXCELLONHeader( aSpan, aHolesType );
246
247 holes_count = 0;
248
249 /* Write the tool list */
250 for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
251 {
252 DRILL_TOOL& tool_descr = m_toolListBuffer[ii];
253
254#if USE_ATTRIB_FOR_HOLES
256#endif
257 fmt::print( m_file, "T{}C{:.{}f}\n", ii + 1, tool_descr.m_Diameter * m_conversionUnits, m_mantissaLenght );
258
259 if( !m_minimalHeader )
260 {
261 if( tool_descr.m_IsBackdrill )
262 {
263 auto formatStub = [&]( int aStubLength )
264 {
265 double stubMM = pcbIUScale.IUTomm( aStubLength );
266 double stubInches = stubMM / 25.4;
267 wxString tmp = fmt::format( "{:.3f}mm ({:.4f}\")", stubMM, stubInches );
268 return tmp;
269 };
270
271 wxString comment = wxT( "; Backdrill" );
272
273 if( tool_descr.m_MinStubLength.has_value() )
274 {
275 comment += wxT( " stub " );
276 comment += formatStub( *tool_descr.m_MinStubLength );;
277
278 if( tool_descr.m_MaxStubLength.has_value()
279 && tool_descr.m_MaxStubLength != tool_descr.m_MinStubLength )
280 {
281 comment += wxT( " to " );
282 comment += formatStub( *tool_descr.m_MaxStubLength );;
283 }
284 }
285
286 if( tool_descr.m_HasPostMachining )
287 comment += wxT( ", post-machining" );
288
289 comment += wxT( "\n" );
290 fmt::print( m_file, "{}", TO_UTF8( comment ) );
291 }
292 else if( tool_descr.m_HasPostMachining )
293 {
294 fmt::print( m_file, "{}", "; Post-machining\n" );
295 }
296 }
297 }
298
299 fmt::print( m_file, "{}", "%\n" ); // End of header info
300 fmt::print( m_file, "{}", "G90\n" ); // Absolute mode
301 fmt::print( m_file, "{}", "G05\n" ); // Drill mode
302
303 /* Read the hole list and generate data for normal holes (oblong
304 * holes will be created later) */
305 int tool_reference = -2;
306
307 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
308 {
309 HOLE_INFO& hole_descr = m_holeListBuffer[ii];
310
311 if( hole_descr.m_Hole_Shape )
312 continue; // oblong holes will be created later
313
314 if( tool_reference != hole_descr.m_Tool_Reference )
315 {
316 tool_reference = hole_descr.m_Tool_Reference;
317 fmt::print( m_file, "T{}\n", tool_reference );
318 }
319
320 x0 = hole_descr.m_Hole_Pos.x - m_offset.x;
321 y0 = hole_descr.m_Hole_Pos.y - m_offset.y;
322
323 if( !m_mirror )
324 y0 *= -1;
325
326 xt = x0 * m_conversionUnits;
327 yt = y0 * m_conversionUnits;
328 writeHoleComments( hole_descr, aTagBackdrillHit );
329 writeCoordinates( line, sizeof( line ), xt, yt );
330
331 fmt::print( m_file, "{}", line );
332 holes_count++;
333 }
334
335 /* Read the hole list and generate data for oblong holes
336 */
337 tool_reference = -2; // set to a value not used for
338 // m_holeListBuffer[ii].m_Tool_Reference
339
340 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
341 {
342 HOLE_INFO& hole_descr = m_holeListBuffer[ii];
343
344 if( hole_descr.m_Hole_Shape == 0 )
345 continue; // wait for oblong holes
346
347 if( tool_reference != hole_descr.m_Tool_Reference )
348 {
349 tool_reference = hole_descr.m_Tool_Reference;
350 fmt::print( m_file, "T{}\n", tool_reference );
351 }
352
353 diam = std::min( hole_descr.m_Hole_Size.x, hole_descr.m_Hole_Size.y );
354
355 if( diam == 0 )
356 continue;
357
358 /* Compute the hole coordinates: */
359 xc = x0 = xf = hole_descr.m_Hole_Pos.x - m_offset.x;
360 yc = y0 = yf = hole_descr.m_Hole_Pos.y - m_offset.y;
361
362 /* Compute the start and end coordinates for the shape */
363 if( hole_descr.m_Hole_Size.x < hole_descr.m_Hole_Size.y )
364 {
365 int delta = ( hole_descr.m_Hole_Size.y - hole_descr.m_Hole_Size.x ) / 2;
366 y0 -= delta;
367 yf += delta;
368 }
369 else
370 {
371 int delta = ( hole_descr.m_Hole_Size.x - hole_descr.m_Hole_Size.y ) / 2;
372 x0 -= delta;
373 xf += delta;
374 }
375
376 RotatePoint( &x0, &y0, xc, yc, hole_descr.m_Hole_Orient );
377 RotatePoint( &xf, &yf, xc, yc, hole_descr.m_Hole_Orient );
378
379 if( !m_mirror )
380 {
381 y0 *= -1;
382 yf *= -1;
383 }
384
385 xt = x0 * m_conversionUnits;
386 yt = y0 * m_conversionUnits;
387 writeHoleComments( hole_descr, aTagBackdrillHit );
388
390 fmt::print( m_file, "{}", "G00" ); // Select the routing mode
391
392 writeCoordinates( line, sizeof( line ), xt, yt );
393
395 {
396 /* remove the '\n' from end of line, because we must add the "G85"
397 * command to the line: */
398 for( int kk = 0; line[kk] != 0; kk++ )
399 {
400 if( line[kk] < ' ' )
401 line[kk] = 0;
402 }
403
404 fmt::print( m_file, "{}", line );
405 fmt::print( m_file, "{}", "G85" ); // add the "G85" command
406 }
407 else
408 {
409 fmt::print( m_file, "{}", line );
410 fmt::print( m_file, "{}", "M15\nG01" ); // tool down and linear routing from last coordinates
411 }
412
413 xt = xf * m_conversionUnits;
414 yt = yf * m_conversionUnits;
415 writeCoordinates( line, sizeof( line ), xt, yt );
416
417 fmt::print( m_file, "{}",line );
418
420 fmt::print( m_file, "{}", "M16\n" ); // Tool up (end routing)
421
422 fmt::print( m_file, "{}", "G05\n" ); // Select drill mode
423 holes_count++;
424 }
425
427
428 return holes_count;
429}
430
431
432void EXCELLON_WRITER::SetFormat( bool aMetric, ZEROS_FMT aZerosFmt, int aLeftDigits,
433 int aRightDigits )
434{
435 m_unitsMetric = aMetric;
436 m_zeroFormat = aZerosFmt;
437
438 /* Set conversion scale depending on drill file units */
439 if( m_unitsMetric )
440 m_conversionUnits = 1.0 / pcbIUScale.IU_PER_MM; // EXCELLON units = mm
441 else
442 m_conversionUnits = 0.001 / pcbIUScale.IU_PER_MILS; // EXCELLON units = in
443
444 // Set the zero counts. if aZerosFmt == DECIMAL_FORMAT, these values
445 // will be set, but not used.
446 if( aLeftDigits <= 0 )
447 aLeftDigits = m_unitsMetric ? 3 : 2;
448
449 if( aRightDigits <= 0 )
450 aRightDigits = m_unitsMetric ? 3 : 4;
451
452 m_precision.m_Lhs = aLeftDigits;
453 m_precision.m_Rhs = aRightDigits;
454}
455
456
457void EXCELLON_WRITER::writeCoordinates( char* aLine, size_t aLineSize, double aCoordX,
458 double aCoordY )
459{
460 wxString xs, ys;
461 int xpad = m_precision.m_Lhs + m_precision.m_Rhs;
462 int ypad = xpad;
463
464 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
465 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
466 // in DECIMAL_FORMAT we could use more digits.
467
468 switch( m_zeroFormat )
469 {
470 default:
471 case DECIMAL_FORMAT:
472 /* In Excellon files, resolution is 1/1000 mm or 1/10000 inch (0.1 mil)
473 * Although in decimal format, Excellon specifications do not specify
474 * clearly the resolution. However it seems to be usually 1/1000mm or 0.1 mil
475 * like in non decimal formats, so we trunk coordinates to m_mantissaLenght in mantissa
476 * Decimal format just prohibit useless leading 0:
477 * 0.45 or .45 is right, but 00.54 is incorrect.
478 */
479 xs = fmt::format( "{:.{}f}", aCoordX, m_mantissaLenght );
480 ys = fmt::format( "{:.{}f}", aCoordY, m_mantissaLenght );
481
482 //Remove useless trailing 0
483 while( xs.Last() == '0' )
484 xs.RemoveLast();
485
486 if( xs.Last() == '.' ) // however keep a trailing 0 after the floating point separator
487 xs << '0';
488
489 while( ys.Last() == '0' )
490 ys.RemoveLast();
491
492 if( ys.Last() == '.' )
493 ys << '0';
494
495 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
496 break;
497
498 case SUPPRESS_LEADING:
499 for( int i = 0; i< m_precision.m_Rhs; i++ )
500 {
501 aCoordX *= 10; aCoordY *= 10;
502 }
503
504 std::snprintf( aLine, aLineSize, "X%dY%d\n", KiROUND( aCoordX ), KiROUND( aCoordY ) );
505 break;
506
508 {
509 for( int i = 0; i < m_precision.m_Rhs; i++ )
510 {
511 aCoordX *= 10;
512 aCoordY *= 10;
513 }
514
515 if( aCoordX < 0 )
516 xpad++;
517
518 if( aCoordY < 0 )
519 ypad++;
520
521 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
522 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
523
524 size_t j = xs.Len() - 1;
525
526 while( xs[j] == '0' && j )
527 xs.Truncate( j-- );
528
529 j = ys.Len() - 1;
530
531 while( ys[j] == '0' && j )
532 ys.Truncate( j-- );
533
534 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
535 break;
536 }
537
538 case KEEP_ZEROS:
539 for( int i = 0; i< m_precision.m_Rhs; i++ )
540 {
541 aCoordX *= 10; aCoordY *= 10;
542 }
543
544 if( aCoordX < 0 )
545 xpad++;
546
547 if( aCoordY < 0 )
548 ypad++;
549
550 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
551 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
552 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
553 break;
554 }
555}
556
557
559{
560 fmt::print( m_file, "{}", "M48\n" ); // The beginning of a header
561
562 if( !m_minimalHeader )
563 {
564 // The next lines in EXCELLON files are comments:
565 wxString msg;
566 msg << wxT( "KiCad " ) << GetBuildVersion();
567
568 fmt::print( m_file, "; DRILL file {} date {}\n",
570 msg = wxT( "; FORMAT={" );
571
572 // Print precision:
573 // Note in decimal format the precision is not used.
574 // the floating point notation has higher priority than the precision.
576 msg << m_precision.GetPrecisionString();
577 else
578 msg << wxT( "-:-" ); // in decimal format the precision is irrelevant
579
580 msg << wxT( "/ absolute / " );
581 msg << ( m_unitsMetric ? wxT( "metric" ) : wxT( "inch" ) );
582
583 /* Adding numbers notation format.
584 * this is same as m_Choice_Zeros_Format strings, but NOT translated
585 * because some EXCELLON parsers do not like non ASCII values
586 * so we use ONLY English (ASCII) strings.
587 * if new options are added in m_Choice_Zeros_Format, they must also
588 * be added here
589 */
590 msg << wxT( " / " );
591
592 const wxString zero_fmt[4] =
593 {
594 wxT( "decimal" ),
595 wxT( "suppress leading zeros" ),
596 wxT( "suppress trailing zeros" ),
597 wxT( "keep zeros" )
598 };
599
600 msg << zero_fmt[m_zeroFormat] << wxT( "}\n" );
601 fmt::print( m_file, "{}", TO_UTF8( msg ) );
602
603 // add the structured comment TF.CreationDate:
604 // The attribute value must conform to the full version of the ISO 8601
606 fmt::print( m_file, "{}", TO_UTF8( msg ) );
607
608 // Add the application name that created the drill file
609 msg = wxT( "; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
610 msg << GetBuildVersion() << wxT( "\n" );
611 fmt::print( m_file, "{}", TO_UTF8( msg ) );
612
613 // Add the standard X2 FileFunction for drill files
614 // TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH]
615 msg = BuildFileFunctionAttributeString( aSpan, aHolesType , true ) + wxT( "\n" );
616 fmt::print( m_file, "{}", TO_UTF8( msg ) );
617
618 fmt::print( m_file, "{}", "FMAT,2\n" ); // Use Format 2 commands (version used since 1979)
619 }
620
621 fmt::print( m_file, "{}", m_unitsMetric ? "METRIC" : "INCH" );
622
623 switch( m_zeroFormat )
624 {
625 case DECIMAL_FORMAT:
626 fmt::print( m_file, "{}", "\n" );
627 break;
628
629 case SUPPRESS_LEADING:
630 fmt::print( m_file, "{}", ",TZ\n" );
631 break;
632
634 fmt::print( m_file, "{}", ",LZ\n" );
635 break;
636
637 case KEEP_ZEROS:
638 // write nothing, but TZ is acceptable when all zeros are kept
639 fmt::print( m_file, "{}", "\n" );
640 break;
641 }
642}
643
644
646{
647 // add if minimal here
648 fmt::print( m_file, "{}", "M30\n" );
649 fclose( m_file );
650}
651
652
654{
655 wxFileName fn = m_pcb->GetFileName();
656 wxString extend;
657
658 extend << wxT( "-" )
659 << wxString::FromUTF8( layerPairName( aSpan.Pair() ).c_str() )
660 << wxT( "-backdrill" );
661
662 fn.SetName( fn.GetName() + extend );
663 fn.SetExt( m_drillFileExtension );
664
665 return fn;
666}
667
668
669bool EXCELLON_WRITER::writeBackdrillLayerPairFile( const wxString& aPlotDirectory,
670 REPORTER* aReporter, const DRILL_SPAN& aSpan )
671{
672 wxFileName fn = getBackdrillLayerPairFileName( aSpan );
673 fn.SetPath( aPlotDirectory );
674
675 wxString fullFilename = fn.GetFullPath();
676 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
677
678 if( file == nullptr )
679 {
680 if( aReporter )
681 {
682 wxString msg;
683 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
684 aReporter->Report( msg, RPT_SEVERITY_ERROR );
685 }
686
687 return false;
688 }
689 else if( aReporter )
690 {
691 wxString msg;
692 msg.Printf( _( "Created file '%s'" ), fullFilename );
693 aReporter->Report( msg, RPT_SEVERITY_ACTION );
694 }
695
696 try
697 {
698 createDrillFile( file, aSpan, TYPE_FILE::NPTH_FILE, true );
699 }
700 catch( ... )
701 {
702 fclose( file );
703
704 if( aReporter )
705 {
706 wxString msg;
707 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
708 aReporter->Report( msg, RPT_SEVERITY_ERROR );
709 }
710
711 return false;
712 }
713
714 return true;
715}
716
717
718void EXCELLON_WRITER::writeHoleComments( const HOLE_INFO& aHole, bool aTagBackdrillHit )
719{
720 if( aTagBackdrillHit && aHole.m_IsBackdrill )
721 fmt::print( m_file, "{}", "; backdrill\n" );
722
725 wxT( "front" ) );
726
729 wxT( "back" ) );
730}
731
732
734 int aSizeIU, int aDepthIU, int aAngleDeciDegree,
735 const wxString& aSideLabel )
736{
739 {
740 return;
741 }
742
743 wxString comment;
744 comment << wxT( "; Post-machining " ) << aSideLabel << wxT( " " )
745 << ( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK ? wxT( "countersink" )
746 : wxT( "counterbore" ) );
747
748 wxString sizeStr = formatLinearValue( aSizeIU );
749
750 if( !sizeStr.IsEmpty() )
751 comment << wxT( " dia " ) << sizeStr;
752
753 wxString depthStr = formatLinearValue( aDepthIU );
754
755 if( !depthStr.IsEmpty() )
756 comment << wxT( " depth " ) << depthStr;
757
758 if( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK && aAngleDeciDegree > 0 )
759 {
760 double angle = aAngleDeciDegree / 10.0;
761 wxString angleStr;
762
763 if( ( aAngleDeciDegree % 10 ) == 0 )
764 angleStr = fmt::format( "{:.0f}deg", angle );
765 else
766 angleStr = fmt::format( "{:.1f}deg", angle );
767
768 comment << wxT( " angle " ) << angleStr;
769 }
770
771 comment << wxT( "\n" );
772 fmt::print( m_file, "{}", TO_UTF8( comment ) );
773}
774
775
776wxString EXCELLON_WRITER::formatLinearValue( int aValueIU ) const
777{
778 if( aValueIU <= 0 )
779 return wxString();
780
781 double converted = aValueIU * m_conversionUnits;
782 wxString value;
783 value = fmt::format( "{:.{}f}", converted, m_mantissaLenght );
784 value << ( m_unitsMetric ? wxT( "mm" ) : wxT( "in" ) );
785
786 return value;
787}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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.
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
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.
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.
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...
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).
PAD_DRILL_POST_MACHINING_MODE m_FrontPostMachining
PAD_DRILL_POST_MACHINING_MODE m_BackPostMachining
EDA_ANGLE m_Hole_Orient
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:112
#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.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
static const std::string DrillFileExtension
@ B_Cu
Definition layer_ids.h:65
@ F_Cu
Definition layer_ids.h:64
This file contains miscellaneous commonly used macros and functions.
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:76
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
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
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:229
Definition of file extensions used in Kicad.