KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gbr_metadata.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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#include <wx/string.h>
31#include <wx/datetime.h>
32
33#include <gbr_metadata.h>
34#include <core/utf8.h>
35
36
38{
39 // creates the CreationDate attribute:
40 // The attribute value must conform to the full version of the ISO 8601
41 // date and time format, including time and time zone. Note that this is
42 // the date the Gerber file was effectively created,
43 // not the time the project of PCB was started
44 wxDateTime date( wxDateTime::GetTimeNow() );
45
46 // Date format: see http://www.cplusplus.com/reference/ctime/strftime
47 wxString timezone_offset; // ISO 8601 offset from UTC in timezone
48 timezone_offset = date.Format( "%z" ); // Extract the time zone offset
49
50 // The time zone offset format is +mm or +hhmm (or -mm or -hhmm)
51 // (mm = number of minutes, hh = number of hours. 1h00mn is returned as +0100)
52 // we want +(or -) hh:mm
53 if( timezone_offset.Len() > 3 ) // format +hhmm or -hhmm found
54 // Add separator between hours and minutes
55 timezone_offset.insert( 3, ":", 1 );
56
57 wxString msg;
58
59 switch( aFormat )
60 {
62 msg.Printf( wxS( "%%TF.CreationDate,%s%s*%%" ), date.FormatISOCombined(), timezone_offset );
63 break;
64
66 msg.Printf( wxS( "G04 #@! TF.CreationDate,%s%s*" ), date.FormatISOCombined(),
67 timezone_offset );
68 break;
69
71 msg.Printf( wxS( "%s%s" ), date.FormatISOCombined(), timezone_offset );
72 break;
73
75 msg.Printf( wxS( "; #@! TF.CreationDate,%s%s" ), date.FormatISOCombined(),
76 timezone_offset );
77 break;
78 }
79
80 return msg;
81}
82
83
84wxString GbrMakeProjectGUIDfromString( const wxString& aText )
85{
86 /* Gerber GUID format should be RFC4122 Version 1 or 4.
87 * See en.wikipedia.org/wiki/Universally_unique_identifier
88 * The format is:
89 * xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
90 * with
91 * x = hexDigit lower/upper case
92 * and
93 * M = '1' or '4' (UUID version: 1 (basic) or 4 (random)) (we use 4: UUID random)
94 * and
95 * N = '8' or '9' or 'A|a' or 'B|b' : UUID variant 1: 2 MSB bits have meaning) (we use N = 9)
96 * N = 1000 or 1001 or 1010 or 1011 : 10xx means Variant 1 (Variant2: 110x and 111x are
97 * reserved)
98 */
99
100 wxString guid;
101
102 // Build a 32 digits GUID from the board name:
103 // guid has 32 digits, so add chars in name to be sure we can build a 32 digits guid
104 // (i.e. from a 16 char string name)
105 // In fact only 30 digits are used, and 2 UID id
106 wxString bname = aText;
107 int cnt = 16 - bname.Len();
108
109 if( cnt > 0 )
110 bname.Append( 'X', cnt );
111
112 int chr_idx = 0;
113
114 // Output the 8 first hex digits:
115 for( unsigned ii = 0; ii < 4; ii++ )
116 {
117 int cc = int( bname[chr_idx++] ) & 0xFF;
118 guid << wxString::Format( "%2.2x", cc );
119 }
120
121 // Output the 4 next hex digits:
122 guid << '-';
123
124 for( unsigned ii = 0; ii < 2; ii++ )
125 {
126 int cc = int( bname[chr_idx++] ) & 0xFF;
127 guid << wxString::Format( "%2.2x", cc );
128 }
129
130 // Output the 4 next hex digits (UUID version and 3 digits):
131 guid << "-4"; // first digit: UUID version 4 (M = 4)
132 {
133 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
134 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
135 guid << wxString::Format( "%3.3x", cc );
136 }
137
138 // Output the 4 next hex digits (UUID variant and 3 digits):
139 guid << "-9"; // first digit: UUID variant 1 (N = 9)
140 {
141 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
142 cc += int( bname[chr_idx++] ) & 0xFF;
143 guid << wxString::Format( "%3.3x", cc );
144 }
145
146 // Output the 12 last hex digits:
147 guid << '-';
148
149 for( unsigned ii = 0; ii < 6; ii++ )
150 {
151 int cc = int( bname[chr_idx++] ) & 0xFF;
152 guid << wxString::Format( "%2.2x", cc );
153 }
154
155 return guid;
156}
157
158
160 bool aUseX1StructuredComment )
161{
162 std::string attribute_string; // the specific aperture attribute (TA.xxx)
163 std::string comment_string; // a optional G04 comment line to write before the TA. line
164
165 // generate a string to print a Gerber Aperture attribute
166 switch( aAttribute )
167 {
168 // Dummy value (aAttribute must be < GBR_APERTURE_ATTRIB_END).
170 case GBR_APERTURE_ATTRIB_NONE: // idle command: do nothing
171 break;
172
173 case GBR_APERTURE_ATTRIB_ETCHEDCMP: // print info associated to an item
174 // which connects 2 different nets
175 // (Net tees, microwave component)
176 attribute_string = "TA.AperFunction,EtchedComponent";
177 break;
178
179 case GBR_APERTURE_ATTRIB_CONDUCTOR: // print info associated to a track
180 attribute_string = "TA.AperFunction,Conductor";
181 break;
182
183 case GBR_APERTURE_ATTRIB_EDGECUT: // print info associated to a board outline
184 attribute_string = "TA.AperFunction,Profile";
185 break;
186
187 case GBR_APERTURE_ATTRIB_VIAPAD: // print info associated to a flashed via
188 attribute_string = "TA.AperFunction,ViaPad";
189 break;
190
191 case GBR_APERTURE_ATTRIB_NONCONDUCTOR: // print info associated to a item on a copper layer
192 // which is not a track (for instance a text)
193 attribute_string = "TA.AperFunction,NonConductor";
194 break;
195
196 case GBR_APERTURE_ATTRIB_COMPONENTPAD: // print info associated to a flashed
197 // through hole component on outer layer
198 attribute_string = "TA.AperFunction,ComponentPad";
199 break;
200
201 case GBR_APERTURE_ATTRIB_SMDPAD_SMDEF: // print info associated to a flashed for SMD pad.
202 // with solder mask defined from the copper shape
203 // Excluded BGA pads which have their own type
204 attribute_string = "TA.AperFunction,SMDPad,SMDef";
205 break;
206
207 case GBR_APERTURE_ATTRIB_SMDPAD_CUDEF: // print info associated to a flashed SMD pad with
208 // a solder mask defined by the solder mask
209 attribute_string = "TA.AperFunction,SMDPad,CuDef";
210 break;
211
212 case GBR_APERTURE_ATTRIB_BGAPAD_SMDEF: // print info associated to flashed BGA pads with
213 // a solder mask defined by the copper shape
214 attribute_string = "TA.AperFunction,BGAPad,SMDef";
215 break;
216
217 case GBR_APERTURE_ATTRIB_BGAPAD_CUDEF: // print info associated to a flashed BGA pad with
218 // a solder mask defined by the solder mask
219 attribute_string = "TA.AperFunction,BGAPad,CuDef";
220 break;
221
223 // print info associated to a flashed edge connector pad (outer layers)
224 attribute_string = "TA.AperFunction,ConnectorPad";
225 break;
226
228 // print info associated to flashed mechanical pads (NPTH)
229 attribute_string = "TA.AperFunction,WasherPad";
230 break;
231
232 case GBR_APERTURE_ATTRIB_HEATSINKPAD: // print info associated to a flashed heat sink pad
233 // (typically for SMDs)
234 attribute_string = "TA.AperFunction,HeatsinkPad";
235 break;
236
237 case GBR_APERTURE_ATTRIB_TESTPOINT: // print info associated to a flashed test point pad
238 // (typically for SMDs)
239 attribute_string = "TA.AperFunction,TestPad";
240 break;
241
242 case GBR_APERTURE_ATTRIB_FIDUCIAL_GLBL: // print info associated to a flashed fiducial pad
243 // (typically for SMDs)
244 attribute_string = "TA.AperFunction,FiducialPad,Global";
245 break;
246
247 case GBR_APERTURE_ATTRIB_FIDUCIAL_LOCAL: // print info associated to a flashed fiducial pad
248 // (typically for SMDs)
249 attribute_string = "TA.AperFunction,FiducialPad,Local";
250 break;
251
253 // print info associated to a flashed castellated pad (typically for SMDs)
254 attribute_string = "TA.AperFunction,CastellatedPad";
255 break;
256
258 // print info associated to a flashed castellated pad in drill files
259 attribute_string = "TA.AperFunction,CastellatedDrill";
260 break;
261
262 case GBR_APERTURE_ATTRIB_VIADRILL: // print info associated to a via hole in drill files
263 attribute_string = "TA.AperFunction,ViaDrill";
264 break;
265
266 case GBR_APERTURE_ATTRIB_CMP_DRILL: // print info associated to a component
267 // round pad hole in drill files
268 attribute_string = "TA.AperFunction,ComponentDrill";
269 break;
270
271 // print info associated to a component oblong pad hole in drill files
272 // Same as a round pad hole, but is a specific aperture in drill file and
273 // a G04 comment is added to the aperture function
275 comment_string = "aperture for slot hole";
276 attribute_string = "TA.AperFunction,ComponentDrill";
277 break;
278
279 case GBR_APERTURE_ATTRIB_CMP_POSITION: // print info associated to a component
280 // flashed shape at the component position
281 // in placement files
282 attribute_string = "TA.AperFunction,ComponentMain";
283 break;
284
285 case GBR_APERTURE_ATTRIB_PAD1_POS: // print info associated to a component
286 // flashed shape at pad 1 position
287 // (pad 1 is also pad A1 or pad AA1)
288 // in placement files
289 attribute_string = "TA.AperFunction,ComponentPin";
290 break;
291
292 case GBR_APERTURE_ATTRIB_PADOTHER_POS: // print info associated to a component
293 // flashed shape at pads position (all but pad 1)
294 // in placement files
295 // Currently: (could be changed later) same as
296 // GBR_APERTURE_ATTRIB_PADOTHER_POS
297 attribute_string = "TA.AperFunction,ComponentPin";
298 break;
299
300 case GBR_APERTURE_ATTRIB_CMP_BODY: // print info associated to a component
301 // print the component physical body
302 // polygon in placement files
303 attribute_string = "TA.AperFunction,ComponentOutline,Body";
304 break;
305
306 case GBR_APERTURE_ATTRIB_CMP_LEAD2LEAD: // print info associated to a component
307 // print the component physical lead to lead
308 // polygon in placement files
309 attribute_string = "TA.AperFunction,ComponentOutline,Lead2Lead";
310 break;
311
312 case GBR_APERTURE_ATTRIB_CMP_FOOTPRINT: // print info associated to a component
313 // print the component footprint bounding box
314 // polygon in placement files
315 attribute_string = "TA.AperFunction,ComponentOutline,Footprint";
316 break;
317
318 case GBR_APERTURE_ATTRIB_CMP_COURTYARD: // print info associated to a component
319 // print the component courtyard
320 // polygon in placement files
321 attribute_string = "TA.AperFunction,ComponentOutline,Courtyard";
322 break;
323
324 break;
325 }
326
327 std::string full_attribute_string;
328 wxString eol_string;
329
330 if( !attribute_string.empty() )
331 {
332 if( !comment_string.empty() )
333 {
334 full_attribute_string = "G04 " + comment_string + "*\n";
335 }
336
337 if( aUseX1StructuredComment )
338 {
339 full_attribute_string += "G04 #@! ";
340 eol_string = "*\n";
341 }
342 else
343 {
344 full_attribute_string += "%";
345 eol_string = "*%\n";
346 }
347 }
348
349 full_attribute_string += attribute_string + eol_string;
350
351 return full_attribute_string;
352}
353
354
355// Helper function to convert a ascii hex char to its integer value
356// If the char is not a hexa char, return -1
357int char2Hex( unsigned aCode )
358{
359 if( aCode >= '0' && aCode <= '9' )
360 return aCode - '0';
361
362 if( aCode >= 'A' && aCode <= 'F' )
363 return aCode - 'A' + 10;
364
365 if( aCode >= 'a' && aCode <= 'f' )
366 return aCode - 'a' + 10;
367
368 return -1;
369}
370
371
372wxString FormatStringFromGerber( const wxString& aString )
373{
374 // make the inverse conversion of FormatStringToGerber()
375 // It converts a "normalized" gerber string containing escape sequences
376 // and convert it to a 16 bits Unicode char
377 // and return a wxString (Unicode 16) from the gerber string
378 // Note the initial gerber string can already contain Unicode chars.
379 wxString txt; // The string converted from Gerber string
380
381 unsigned count = aString.Length();
382
383 for( unsigned ii = 0; ii < count; ++ii )
384 {
385 unsigned code = aString[ii];
386
387 if( code == '\\' && ii < count-5 && aString[ii+1] == 'u' )
388 {
389 // Note the latest Gerber X2 spec (2019 06) uses \uXXXX to encode
390 // the Unicode XXXX hexadecimal value
391 // If 4 chars next to 'u' are hexadecimal chars,
392 // Convert these 4 hexadecimal digits to a 16 bit Unicode
393 // (Gerber allows only 4 hexadecimal digits)
394 // If an error occurs, the escape sequence is not translated,
395 // and used "as this"
396 long value = 0;
397 bool error = false;
398
399 for( int jj = 0; jj < 4; jj++ )
400 {
401 value <<= 4;
402 code = aString[ii+jj+2];
403
404 int hexa = char2Hex( code );
405
406 if( hexa >= 0 )
407 value += hexa;
408 else
409 {
410 error = true;
411 break;
412 }
413 }
414
415 if( !error )
416 {
417 if( value >= ' ' ) // Is a valid wxChar ?
418 txt.Append( wxChar( value ) );
419
420 ii += 5;
421 }
422 else
423 {
424 txt.Append( aString[ii] );
425 continue;
426 }
427 }
428 else
429 {
430 txt.Append( aString[ii] );
431 }
432 }
433
434 return txt;
435}
436
437
438wxString ConvertNotAllowedCharsInGerber( const wxString& aString, bool aAllowUtf8Chars,
439 bool aQuoteString )
440{
441 /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal
442 * 16 bits sequence Unicode
443 * However if aAllowUtf8Chars is true only unauthorized codes will be escaped, because some
444 * Gerber files accept UTF8 chars.
445 * unauthorized codes are ',' '*' '%' '\' '"' and are used as separators in Gerber files
446 */
447 wxString txt;
448
449 if( aQuoteString )
450 txt << "\"";
451
452 for( unsigned ii = 0; ii < aString.Length(); ++ii )
453 {
454 wxChar code = aString[ii];
455 bool convert = false;
456
457 switch( code )
458 {
459 case '\\':
460 case '%':
461 case '*':
462 case ',':
463 convert = true;
464 break;
465
466 case '"':
467 if( aQuoteString )
468 convert = true;
469 break;
470
471 default:
472 break;
473 }
474
475 if( !aAllowUtf8Chars && code > 0x7F )
476 convert = true;
477
478 if( convert )
479 {
480 // Convert code to 4 hexadecimal digit
481 // (Gerber allows only 4 hexadecimal digit) in escape seq:
482 // "\uXXXX", XXXX is the Unicode 16 bits hexa value
483 char hexa[32];
484 std::snprintf( hexa, sizeof( hexa ), "\\u%4.4X", code & 0xFFFF );
485 txt += hexa;
486 }
487 else
488 {
489 txt += code;
490 }
491 }
492
493 if( aQuoteString )
494 txt << "\"";
495
496 return txt;
497}
498
499
501{
502 wxString converted;
503
504 if( !m_field.IsEmpty() )
506
507 // Convert the char string to std::string. Be careful when converting a wxString to
508 // a std::string: using static_cast<const char*> is mandatory
509 std::string txt = static_cast<const char*>( converted.utf8_str() );
510
511 return txt;
512}
513
514
515std::string FormatStringToGerber( const wxString& aString )
516{
517 wxString converted;
518
519 /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal
520 * 16 bits sequence Unicode
521 * unauthorized codes are ',' '*' '%' '\'
522 * This conversion is not made for quoted strings, because if the string is
523 * quoted, the conversion is expected to be already made, and the returned string must use
524 * UTF8 encoding
525 */
526 if( !aString.IsEmpty() && ( aString[0] != '\"' || aString[aString.Len()-1] != '\"' ) )
527 converted = ConvertNotAllowedCharsInGerber( aString, false, false );
528 else
529 converted = aString;
530
531 // Convert the char string to std::string. Be careful when converting a wxString to
532 // a std::string: using static_cast<const char*> is mandatory
533 std::string txt = static_cast<const char*>( converted.utf8_str() );
534
535 return txt;
536}
537
538
539// Netname and Pan num fields cannot be empty in Gerber files
540// Normalized names must be used, if any
541#define NO_NET_NAME wxT( "N/C" ) // net name of not connected pads (one pad net) (normalized)
542#define NO_PAD_NAME wxT( "" ) // pad name of pads without pad name/number (not normalized)
543
544
545bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes,
546 const GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes,
547 bool aUseX1StructuredComment )
548{
549 aClearPreviousAttributes = false;
550 wxString prepend_string;
551 wxString eol_string;
552
553 if( aUseX1StructuredComment )
554 {
555 prepend_string = "G04 #@! ";
556 eol_string = "*\n";
557 }
558 else
559 {
560 prepend_string = "%";
561 eol_string = "*%\n";
562 }
563
564 // print a Gerber net attribute record.
565 // it is added to the object attributes dictionary
566 // On file, only modified or new attributes are printed.
567 if( aData == nullptr )
568 return false;
569
570 std::string pad_attribute_string;
571 std::string net_attribute_string;
572 std::string cmp_attribute_string;
573
575 return false; // idle command: do nothing
576
578 {
579 // print info associated to a flashed pad (cmpref, pad name, and optionally pin function)
580 // example1: %TO.P,R5,3*%
581 // example2: %TO.P,R5,3,reset*%
582 pad_attribute_string = prepend_string + "TO.P,";
583 pad_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + ",";
584
585 if( aData->m_Padname.IsEmpty() )
586 {
587 // Happens for "mechanical" or never connected pads
588 pad_attribute_string += FormatStringToGerber( NO_PAD_NAME );
589 }
590 else
591 {
592 pad_attribute_string += aData->m_Padname.GetGerberString();
593
594 // In Pcbnew, the pin function comes from the schematic.
595 // so it exists only for named pads
596 if( !aData->m_PadPinFunction.IsEmpty() )
597 {
598 pad_attribute_string += ',';
599 pad_attribute_string += aData->m_PadPinFunction.GetGerberString();
600 }
601 }
602
603 pad_attribute_string += eol_string;
604 }
605
607 {
608 // print info associated to a net
609 // example: %TO.N,Clk3*%
610 net_attribute_string = prepend_string + "TO.N,";
611
612 if( aData->m_Netname.IsEmpty() )
613 {
614 if( aData->m_NotInNet )
615 {
616 // Happens for not connectable pads: mechanical pads
617 // and pads with no padname/num
618 // In this case the net name must be left empty
619 }
620 else
621 {
622 // Happens for not connected pads: use a normalized
623 // dummy name
624 net_attribute_string += FormatStringToGerber( NO_NET_NAME );
625 }
626 }
627 else
628 {
629 net_attribute_string += FormatStringToGerber( aData->m_Netname );
630 }
631
632 net_attribute_string += eol_string;
633 }
634
637 {
638 // print info associated to a footprint
639 // example: %TO.C,R2*%
640 // Because GBR_NETINFO_PAD option already contains this info, it is not
641 // created here for a GBR_NETINFO_PAD attribute
642 cmp_attribute_string = prepend_string + "TO.C,";
643 cmp_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + eol_string;
644 }
645
646 // the full list of requested attributes:
647 std::string full_attribute_string = pad_attribute_string + net_attribute_string
648 + cmp_attribute_string;
649 // the short list of requested attributes
650 // (only modified or new attributes are stored here):
651 std::string short_attribute_string;
652
653 // Attributes have changed: update attribute string, and see if the previous attribute
654 // list (dictionary in Gerber language) must be cleared
655 if( aLastNetAttributes != full_attribute_string )
656 {
657 // first, remove no longer existing attributes.
658 // Because in KiCad the full attribute list is evaluated for each object,
659 // the entire dictionary is cleared
660 // If m_TryKeepPreviousAttributes is true, only the no longer existing attribute
661 // is cleared.
662 // Note: to avoid interaction between clear attributes and set attributes
663 // the clear attribute is inserted first.
664 bool clearDict = false;
665
666 if( aLastNetAttributes.find( "TO.P," ) != std::string::npos )
667 {
668 if( pad_attribute_string.empty() ) // No more this attribute
669 {
670 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
671 short_attribute_string.insert( 0, prepend_string + "TO.P" + eol_string );
672 else
673 clearDict = true;
674 }
675 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
676 {
677 // This attribute has changed
678 short_attribute_string += pad_attribute_string;
679 }
680 }
681 else // New attribute
682 {
683 short_attribute_string += pad_attribute_string;
684 }
685
686 if( aLastNetAttributes.find( "TO.N," ) != std::string::npos )
687 {
688 if( net_attribute_string.empty() ) // No more this attribute
689 {
690 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
691 short_attribute_string.insert( 0, prepend_string + "TO.N" + eol_string );
692 else
693 clearDict = true;
694 }
695 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
696 {
697 // This attribute has changed.
698 short_attribute_string += net_attribute_string;
699 }
700 }
701 else // New attribute
702 {
703 short_attribute_string += net_attribute_string;
704 }
705
706 if( aLastNetAttributes.find( "TO.C," ) != std::string::npos )
707 {
708 if( cmp_attribute_string.empty() ) // No more this attribute
709 {
710 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
711 {
712 // Refinement:
713 // the attribute will be cleared only if there is no pad attribute.
714 // If a pad attribute exists, the component name exists so the old
715 // TO.C value will be updated, therefore no need to clear it before updating
716 if( pad_attribute_string.empty() )
717 short_attribute_string.insert( 0, prepend_string + "TO.C" + eol_string );
718 }
719 else
720 {
721 clearDict = true;
722 }
723 }
724 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
725 {
726 // This attribute has changed.
727 short_attribute_string += cmp_attribute_string;
728 }
729 }
730 else // New attribute
731 {
732 short_attribute_string += cmp_attribute_string;
733 }
734
735 aClearPreviousAttributes = clearDict;
736
737 aLastNetAttributes = full_attribute_string;
738
739 if( clearDict )
740 aPrintedText = full_attribute_string;
741 else
742 aPrintedText = short_attribute_string;
743 }
744
745 return true;
746}
747
748
750{
751 // Clear all strings
752 m_Orientation = 0.0;
753 m_Manufacturer.Clear();
754 m_MPN.Clear();
755 m_Package.Clear();
756 m_Value.Clear();
758}
759
760
762{
763 wxString text;
764 wxString start_of_line( "%TO." );
765 wxString end_of_line( "*%\n" );
766
767 wxString mountTypeStrings[] =
768 {
769 "Other", "SMD", "TH"
770 };
771
772 if( !m_Manufacturer.IsEmpty() )
773 text << start_of_line << "CMfr," << m_Manufacturer << end_of_line;
774
775 if( !m_MPN.IsEmpty() )
776 text << start_of_line << "CMPN," << m_MPN << end_of_line;
777
778 if( !m_Package.IsEmpty() )
779 text << start_of_line << "Cpkg," << m_Package << end_of_line;
780
781 if( !m_Footprint.IsEmpty() )
782 text << start_of_line << "CFtp," << m_Footprint << end_of_line;
783
784 if( !m_Value.IsEmpty() )
785 text << start_of_line << "CVal," << m_Value << end_of_line;
786
787 if( !m_LibraryName.IsEmpty() )
788 text << start_of_line << "CLbN," << m_LibraryName << end_of_line;
789
790 if( !m_LibraryDescr.IsEmpty() )
791 text << start_of_line << "CLbD," << m_LibraryDescr << end_of_line;
792
793 text << start_of_line << "CMnt," << mountTypeStrings[m_MountType] << end_of_line;
794 text << start_of_line << "CRot," << m_Orientation << end_of_line;
795
796 return text;
797}
@ GBR_APERTURE_ATTRIB_CMP_DRILL
Aperture used for pad holes in drill files.
Definition: gbr_metadata.h:141
@ GBR_APERTURE_ATTRIB_CONDUCTOR
Aperture used for connected items like tracks (not vias).
Definition: gbr_metadata.h:98
@ GBR_APERTURE_ATTRIB_VIAPAD
Aperture used for vias.
Definition: gbr_metadata.h:103
@ GBR_APERTURE_ATTRIB_ETCHEDCMP
Aperture used for etched components.
Definition: gbr_metadata.h:95
@ GBR_APERTURE_ATTRIB_BGAPAD_CUDEF
Aperture used for BGA pad with a solder mask defined by the solder mask.
Definition: gbr_metadata.h:118
@ GBR_APERTURE_ATTRIB_PAD1_POS
Aperture used for flashed pin 1 (or A1 or AA1) position in placement files.
Definition: gbr_metadata.h:150
@ GBR_APERTURE_ATTRIB_HEATSINKPAD
Aperture used for heat sink pad (typically for SMDs).
Definition: gbr_metadata.h:132
@ GBR_APERTURE_ATTRIB_CMP_OBLONG_DRILL
Aperture used for pads oblong holes in drill files.
Definition: gbr_metadata.h:144
@ GBR_APERTURE_ATTRIB_CMP_COURTYARD
Aperture used to draw component outline courtyard in placement files.
Definition: gbr_metadata.h:165
@ GBR_APERTURE_ATTRIB_TESTPOINT
Aperture used for test point pad (outer layers).
Definition: gbr_metadata.h:123
@ GBR_APERTURE_ATTRIB_SMDPAD_SMDEF
Aperture used for SMD pad. Excluded BGA pads which have their own type.
Definition: gbr_metadata.h:109
@ GBR_APERTURE_ATTRIB_SMDPAD_CUDEF
Aperture used for SMD pad with a solder mask defined by the solder mask.
Definition: gbr_metadata.h:112
@ GBR_APERTURE_ATTRIB_NONE
uninitialized attribute.
Definition: gbr_metadata.h:94
@ GBR_APERTURE_ATTRIB_CONNECTORPAD
Aperture used for edge connector pad (outer layers).
Definition: gbr_metadata.h:121
@ GBR_APERTURE_ATTRIB_CASTELLATEDDRILL
Aperture used for castellated pads in drill files.
Definition: gbr_metadata.h:138
@ GBR_APERTURE_ATTRIB_NONCONDUCTOR
Aperture used for not connected items (texts, outlines on copper).
Definition: gbr_metadata.h:102
@ GBR_APERTURE_ATTRIB_END
sentinel: max value
Definition: gbr_metadata.h:166
@ GBR_APERTURE_ATTRIB_CMP_POSITION
Aperture used for flashed cmp position in placement files.
Definition: gbr_metadata.h:147
@ GBR_APERTURE_ATTRIB_CMP_BODY
Aperture used to draw component physical body outline without pins in placement files.
Definition: gbr_metadata.h:156
@ GBR_APERTURE_ATTRIB_BGAPAD_SMDEF
Aperture used for BGA pads with a solder mask defined by the copper shape.
Definition: gbr_metadata.h:115
@ GBR_APERTURE_ATTRIB_WASHERPAD
Aperture used for mechanical pads (NPTH).
Definition: gbr_metadata.h:122
@ GBR_APERTURE_ATTRIB_PADOTHER_POS
Aperture used for flashed pads position in placement files.
Definition: gbr_metadata.h:153
@ GBR_APERTURE_ATTRIB_COMPONENTPAD
Aperture used for through hole component on outer layer.
Definition: gbr_metadata.h:106
@ GBR_APERTURE_ATTRIB_VIADRILL
Aperture used for via holes in drill files.
Definition: gbr_metadata.h:140
@ GBR_APERTURE_ATTRIB_CMP_FOOTPRINT
Aperture used to draw component footprint bounding box in placement files.
Definition: gbr_metadata.h:162
@ GBR_APERTURE_ATTRIB_CMP_LEAD2LEAD
Aperture used to draw component physical body outline with pins in placement files.
Definition: gbr_metadata.h:159
@ GBR_APERTURE_ATTRIB_FIDUCIAL_GLBL
Aperture used for fiducial pad (outer layers), at board level.
Definition: gbr_metadata.h:126
@ GBR_APERTURE_ATTRIB_CASTELLATEDPAD
Aperture used for castellated pads in copper layer files.
Definition: gbr_metadata.h:135
@ GBR_APERTURE_ATTRIB_FIDUCIAL_LOCAL
Aperture used for fiducial pad (outer layers), at footprint level.
Definition: gbr_metadata.h:129
@ GBR_APERTURE_ATTRIB_EDGECUT
Aperture used for board cutout,.
Definition: gbr_metadata.h:99
static std::string FormatAttribute(GBR_APERTURE_ATTRIB aAttribute, bool aUseX1StructuredComment)
wxString FormatCmpPnPMetadata()
One line by non empty data the orientation (.CRot) and mount type (.CMnt) are always generated.
std::string GetGerberString() const
wxString m_field
the Unicode text to print in Gbr file (after escape and quoting)
bool m_useUTF8
true to use UTF8, false to escape non ASCII7 chars
bool m_escapeString
true to quote the field in gbr file
Information which can be added in a gerber file as attribute of an object.
int m_NetAttribType
the type of net info (used to define the gerber string to create)
wxString m_Cmpref
the component reference parent of the data
@ GBR_NETINFO_NET
print info associated to a net (TO.N attribute)
@ GBR_NETINFO_UNSPECIFIED
idle command (no command)
@ GBR_NETINFO_CMP
print info associated to a component (TO.C attribute)
@ GBR_NETINFO_PAD
print info associated to a flashed pad (TO.P attribute)
GBR_DATA_FIELD m_PadPinFunction
for a pad: the pin function (defined in schematic)
bool m_TryKeepPreviousAttributes
If true, do not clear all attributes when a attribute has changed.
bool m_NotInNet
true if a pad of a footprint cannot be connected (for instance a mechanical NPTH, ot a not named pad)...
GBR_DATA_FIELD m_Padname
for a flashed pad: the pad name ((TO.P attribute)
wxString m_Netname
for items associated to a net: the netname
wxString GbrMakeProjectGUIDfromString(const wxString &aText)
Build a project GUID using format RFC4122 Version 1 or 4 from the project name, because a KiCad proje...
#define NO_NET_NAME
#define NO_PAD_NAME
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
std::string FormatStringToGerber(const wxString &aString)
Normalize aString and convert it to a Gerber std::string.
wxString ConvertNotAllowedCharsInGerber(const wxString &aString, bool aAllowUtf8Chars, bool aQuoteString)
Normalize aString and convert it to a Gerber compatible wxString.
wxString FormatStringFromGerber(const wxString &aString)
Convert a gerber string into a 16 bit Unicode string.
int char2Hex(unsigned aCode)
bool FormatNetAttribute(std::string &aPrintedText, std::string &aLastNetAttributes, const GBR_NETLIST_METADATA *aData, bool &aClearPreviousAttributes, bool aUseX1StructuredComment)
Generate the string to set a net attribute for a graphic object to print to a gerber file.
Handle special data (items attributes) during plot.
GBR_NC_STRING_FORMAT
Create a gerber TF.CreationDate attribute.
Definition: gbr_metadata.h:60
@ GBR_NC_STRING_FORMAT_X1
Definition: gbr_metadata.h:61
@ GBR_NC_STRING_FORMAT_NCDRILL
Definition: gbr_metadata.h:64
@ GBR_NC_STRING_FORMAT_X2
Definition: gbr_metadata.h:62
@ GBR_NC_STRING_FORMAT_GBRJOB
Definition: gbr_metadata.h:63