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 const std::string& aCustomAttribute )
162{
163 std::string attribute_string; // the specific aperture attribute (TA.xxx)
164 std::string comment_string; // a optional G04 comment line to write before the TA. line
165
166 // generate a string to print a Gerber Aperture attribute
167 switch( aAttribute )
168 {
169 // Dummy value (aAttribute must be < GBR_APERTURE_ATTRIB_END).
171 case GBR_APERTURE_ATTRIB_NONE: // idle command: do nothing
172 break;
173
174 case GBR_APERTURE_ATTRIB_ETCHEDCMP: // print info associated to an item
175 // which connects 2 different nets
176 // (Net tees, microwave component)
177 attribute_string = "TA.AperFunction,EtchedComponent";
178 break;
179
180 case GBR_APERTURE_ATTRIB_CONDUCTOR: // print info associated to a track
181 attribute_string = "TA.AperFunction,Conductor";
182 break;
183
184 case GBR_APERTURE_ATTRIB_EDGECUT: // print info associated to a board outline
185 attribute_string = "TA.AperFunction,Profile";
186 break;
187
188 case GBR_APERTURE_ATTRIB_VIAPAD: // print info associated to a flashed via
189 attribute_string = "TA.AperFunction,ViaPad";
190 break;
191
192 case GBR_APERTURE_ATTRIB_NONCONDUCTOR: // print info associated to a item on a copper layer
193 // which is not a track (for instance a text)
194 attribute_string = "TA.AperFunction,NonConductor";
195 break;
196
197 case GBR_APERTURE_ATTRIB_COMPONENTPAD: // print info associated to a flashed
198 // through hole component on outer layer
199 attribute_string = "TA.AperFunction,ComponentPad";
200 break;
201
202 case GBR_APERTURE_ATTRIB_SMDPAD_SMDEF: // print info associated to a flashed for SMD pad.
203 // with solder mask defined from the copper shape
204 // Excluded BGA pads which have their own type
205 attribute_string = "TA.AperFunction,SMDPad,SMDef";
206 break;
207
208 case GBR_APERTURE_ATTRIB_SMDPAD_CUDEF: // print info associated to a flashed SMD pad with
209 // a solder mask defined by the solder mask
210 attribute_string = "TA.AperFunction,SMDPad,CuDef";
211 break;
212
213 case GBR_APERTURE_ATTRIB_BGAPAD_SMDEF: // print info associated to flashed BGA pads with
214 // a solder mask defined by the copper shape
215 attribute_string = "TA.AperFunction,BGAPad,SMDef";
216 break;
217
218 case GBR_APERTURE_ATTRIB_BGAPAD_CUDEF: // print info associated to a flashed BGA pad with
219 // a solder mask defined by the solder mask
220 attribute_string = "TA.AperFunction,BGAPad,CuDef";
221 break;
222
224 // print info associated to a flashed edge connector pad (outer layers)
225 attribute_string = "TA.AperFunction,ConnectorPad";
226 break;
227
229 // print info associated to flashed mechanical pads (NPTH)
230 attribute_string = "TA.AperFunction,WasherPad";
231 break;
232
233 case GBR_APERTURE_ATTRIB_HEATSINKPAD: // print info associated to a flashed heat sink pad
234 // (typically for SMDs)
235 attribute_string = "TA.AperFunction,HeatsinkPad";
236 break;
237
238 case GBR_APERTURE_ATTRIB_TESTPOINT: // print info associated to a flashed test point pad
239 // (typically for SMDs)
240 attribute_string = "TA.AperFunction,TestPad";
241 break;
242
243 case GBR_APERTURE_ATTRIB_FIDUCIAL_GLBL: // print info associated to a flashed fiducial pad
244 // (typically for SMDs)
245 attribute_string = "TA.AperFunction,FiducialPad,Global";
246 break;
247
248 case GBR_APERTURE_ATTRIB_FIDUCIAL_LOCAL: // print info associated to a flashed fiducial pad
249 // (typically for SMDs)
250 attribute_string = "TA.AperFunction,FiducialPad,Local";
251 break;
252
254 // print info associated to a flashed castellated pad (typically for SMDs)
255 attribute_string = "TA.AperFunction,CastellatedPad";
256 break;
257
259 // print info associated to a flashed castellated pad in drill files
260 attribute_string = "TA.AperFunction,CastellatedDrill";
261 break;
262
263 case GBR_APERTURE_ATTRIB_VIADRILL: // print info associated to a via hole in drill files
264 attribute_string = "TA.AperFunction,ViaDrill";
265 break;
266
267 case GBR_APERTURE_ATTRIB_CMP_DRILL: // print info associated to a component
268 // round pad hole in drill files
269 attribute_string = "TA.AperFunction,ComponentDrill";
270 break;
271
273 // print info associated to a flashed component pad with pressfit option in drill files
274 attribute_string = "TA.AperFunction,ComponentDrill,PressFit";
275 break;
276
277 // print info associated to a component oblong pad hole in drill files
278 // Same as a round pad hole, but is a specific aperture in drill file and
279 // a G04 comment is added to the aperture function
281 comment_string = "aperture for slot hole";
282 attribute_string = "TA.AperFunction,ComponentDrill";
283 break;
284
285 case GBR_APERTURE_ATTRIB_CMP_POSITION: // print info associated to a component
286 // flashed shape at the component position
287 // in placement files
288 attribute_string = "TA.AperFunction,ComponentMain";
289 break;
290
291 case GBR_APERTURE_ATTRIB_PAD1_POS: // print info associated to a component
292 // flashed shape at pad 1 position
293 // (pad 1 is also pad A1 or pad AA1)
294 // in placement files
295 attribute_string = "TA.AperFunction,ComponentPin";
296 break;
297
298 case GBR_APERTURE_ATTRIB_PADOTHER_POS: // print info associated to a component
299 // flashed shape at pads position (all but pad 1)
300 // in placement files
301 // Currently: (could be changed later) same as
302 // GBR_APERTURE_ATTRIB_PADOTHER_POS
303 attribute_string = "TA.AperFunction,ComponentPin";
304 break;
305
306 case GBR_APERTURE_ATTRIB_CMP_BODY: // print info associated to a component
307 // print the component physical body
308 // polygon in placement files
309 attribute_string = "TA.AperFunction,ComponentOutline,Body";
310 break;
311
312 case GBR_APERTURE_ATTRIB_CMP_LEAD2LEAD: // print info associated to a component
313 // print the component physical lead to lead
314 // polygon in placement files
315 attribute_string = "TA.AperFunction,ComponentOutline,Lead2Lead";
316 break;
317
318 case GBR_APERTURE_ATTRIB_CMP_FOOTPRINT: // print info associated to a component
319 // print the component footprint bounding box
320 // polygon in placement files
321 attribute_string = "TA.AperFunction,ComponentOutline,Footprint";
322 break;
323
324 case GBR_APERTURE_ATTRIB_CMP_COURTYARD: // print info associated to a component
325 // print the component courtyard
326 // polygon in placement files
327 attribute_string = "TA.AperFunction,ComponentOutline,Courtyard";
328 break;
329
331 attribute_string = "TA.AperFunction,Other," + aCustomAttribute;
332 break;
333 }
334
335 std::string full_attribute_string;
336 wxString eol_string;
337
338 if( !attribute_string.empty() )
339 {
340 if( !comment_string.empty() )
341 {
342 full_attribute_string = "G04 " + comment_string + "*\n";
343 }
344
345 if( aUseX1StructuredComment )
346 {
347 full_attribute_string += "G04 #@! ";
348 eol_string = "*\n";
349 }
350 else
351 {
352 full_attribute_string += "%";
353 eol_string = "*%\n";
354 }
355 }
356
357 full_attribute_string += attribute_string + eol_string;
358
359 return full_attribute_string;
360}
361
362
363// Helper function to convert a ascii hex char to its integer value
364// If the char is not a hexa char, return -1
365int char2Hex( unsigned aCode )
366{
367 if( aCode >= '0' && aCode <= '9' )
368 return aCode - '0';
369
370 if( aCode >= 'A' && aCode <= 'F' )
371 return aCode - 'A' + 10;
372
373 if( aCode >= 'a' && aCode <= 'f' )
374 return aCode - 'a' + 10;
375
376 return -1;
377}
378
379
380wxString FormatStringFromGerber( const wxString& aString )
381{
382 // make the inverse conversion of FormatStringToGerber()
383 // It converts a "normalized" gerber string containing escape sequences
384 // and convert it to a 16 bits Unicode char
385 // and return a wxString (Unicode 16) from the gerber string
386 // Note the initial gerber string can already contain Unicode chars.
387 wxString txt; // The string converted from Gerber string
388
389 unsigned count = aString.Length();
390
391 for( unsigned ii = 0; ii < count; ++ii )
392 {
393 unsigned code = aString[ii];
394
395 if( code == '\\' && ii < count-5 && aString[ii+1] == 'u' )
396 {
397 // Note the latest Gerber X2 spec (2019 06) uses \uXXXX to encode
398 // the Unicode XXXX hexadecimal value
399 // If 4 chars next to 'u' are hexadecimal chars,
400 // Convert these 4 hexadecimal digits to a 16 bit Unicode
401 // (Gerber allows only 4 hexadecimal digits)
402 // If an error occurs, the escape sequence is not translated,
403 // and used "as this"
404 long value = 0;
405 bool error = false;
406
407 for( int jj = 0; jj < 4; jj++ )
408 {
409 value <<= 4;
410 code = aString[ii+jj+2];
411
412 int hexa = char2Hex( code );
413
414 if( hexa >= 0 )
415 value += hexa;
416 else
417 {
418 error = true;
419 break;
420 }
421 }
422
423 if( !error )
424 {
425 if( value >= ' ' ) // Is a valid wxChar ?
426 txt.Append( wxChar( value ) );
427
428 ii += 5;
429 }
430 else
431 {
432 txt.Append( aString[ii] );
433 continue;
434 }
435 }
436 else
437 {
438 txt.Append( aString[ii] );
439 }
440 }
441
442 return txt;
443}
444
445
446wxString ConvertNotAllowedCharsInGerber( const wxString& aString, bool aAllowUtf8Chars,
447 bool aQuoteString )
448{
449 /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal
450 * 16 bits sequence Unicode
451 * However if aAllowUtf8Chars is true only unauthorized codes will be escaped, because some
452 * Gerber files accept UTF8 chars.
453 * unauthorized codes are ',' '*' '%' '\' '"' and are used as separators in Gerber files
454 */
455 wxString txt;
456
457 if( aQuoteString )
458 txt << "\"";
459
460 for( unsigned ii = 0; ii < aString.Length(); ++ii )
461 {
462 wxChar code = aString[ii];
463 bool convert = false;
464
465 switch( code )
466 {
467 case '\\':
468 case '%':
469 case '*':
470 case ',':
471 convert = true;
472 break;
473
474 case '"':
475 if( aQuoteString )
476 convert = true;
477 break;
478
479 default:
480 break;
481 }
482
483 if( !aAllowUtf8Chars && code > 0x7F )
484 convert = true;
485
486 if( convert )
487 {
488 // Convert code to 4 hexadecimal digit
489 // (Gerber allows only 4 hexadecimal digit) in escape seq:
490 // "\uXXXX", XXXX is the Unicode 16 bits hexa value
491 char hexa[32];
492 std::snprintf( hexa, sizeof( hexa ), "\\u%4.4X", code & 0xFFFF );
493 txt += hexa;
494 }
495 else
496 {
497 txt += code;
498 }
499 }
500
501 if( aQuoteString )
502 txt << "\"";
503
504 return txt;
505}
506
507
509{
510 wxString converted;
511
512 if( !m_field.IsEmpty() )
514
515 // Convert the char string to std::string. Be careful when converting a wxString to
516 // a std::string: using static_cast<const char*> is mandatory
517 std::string txt = static_cast<const char*>( converted.utf8_str() );
518
519 return txt;
520}
521
522
523std::string FormatStringToGerber( const wxString& aString )
524{
525 wxString converted;
526
527 /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal
528 * 16 bits sequence Unicode
529 * unauthorized codes are ',' '*' '%' '\'
530 * This conversion is not made for quoted strings, because if the string is
531 * quoted, the conversion is expected to be already made, and the returned string must use
532 * UTF8 encoding
533 */
534 if( !aString.IsEmpty() && ( aString[0] != '\"' || aString[aString.Len()-1] != '\"' ) )
535 converted = ConvertNotAllowedCharsInGerber( aString, false, false );
536 else
537 converted = aString;
538
539 // Convert the char string to std::string. Be careful when converting a wxString to
540 // a std::string: using static_cast<const char*> is mandatory
541 std::string txt = static_cast<const char*>( converted.utf8_str() );
542
543 return txt;
544}
545
546
547// Netname and Pan num fields cannot be empty in Gerber files
548// Normalized names must be used, if any
549#define NO_NET_NAME wxT( "N/C" ) // net name of not connected pads (one pad net) (normalized)
550#define NO_PAD_NAME wxT( "" ) // pad name of pads without pad name/number (not normalized)
551
552
553bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes,
554 const GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes,
555 bool aUseX1StructuredComment )
556{
557 aClearPreviousAttributes = false;
558 wxString prepend_string;
559 wxString eol_string;
560
561 if( aUseX1StructuredComment )
562 {
563 prepend_string = "G04 #@! ";
564 eol_string = "*\n";
565 }
566 else
567 {
568 prepend_string = "%";
569 eol_string = "*%\n";
570 }
571
572 // print a Gerber net attribute record.
573 // it is added to the object attributes dictionary
574 // On file, only modified or new attributes are printed.
575 if( aData == nullptr )
576 return false;
577
578 std::string pad_attribute_string;
579 std::string net_attribute_string;
580 std::string cmp_attribute_string;
581
583 return false; // idle command: do nothing
584
586 {
587 // print info associated to a flashed pad (cmpref, pad name, and optionally pin function)
588 // example1: %TO.P,R5,3*%
589 // example2: %TO.P,R5,3,reset*%
590 pad_attribute_string = prepend_string + "TO.P,";
591 pad_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + ",";
592
593 if( aData->m_Padname.IsEmpty() )
594 {
595 // Happens for "mechanical" or never connected pads
596 pad_attribute_string += FormatStringToGerber( NO_PAD_NAME );
597 }
598 else
599 {
600 pad_attribute_string += aData->m_Padname.GetGerberString();
601
602 // In Pcbnew, the pin function comes from the schematic.
603 // so it exists only for named pads
604 if( !aData->m_PadPinFunction.IsEmpty() )
605 {
606 pad_attribute_string += ',';
607 pad_attribute_string += aData->m_PadPinFunction.GetGerberString();
608 }
609 }
610
611 pad_attribute_string += eol_string;
612 }
613
615 {
616 // print info associated to a net
617 // example: %TO.N,Clk3*%
618 net_attribute_string = prepend_string + "TO.N,";
619
620 if( aData->m_Netname.IsEmpty() )
621 {
622 if( aData->m_NotInNet )
623 {
624 // Happens for not connectable pads: mechanical pads
625 // and pads with no padname/num
626 // In this case the net name must be left empty
627 }
628 else
629 {
630 // Happens for not connected pads: use a normalized
631 // dummy name
632 net_attribute_string += FormatStringToGerber( NO_NET_NAME );
633 }
634 }
635 else
636 {
637 net_attribute_string += FormatStringToGerber( aData->m_Netname );
638 }
639
640 net_attribute_string += eol_string;
641 }
642
645 {
646 // print info associated to a footprint
647 // example: %TO.C,R2*%
648 // Because GBR_NETINFO_PAD option already contains this info, it is not
649 // created here for a GBR_NETINFO_PAD attribute
650 cmp_attribute_string = prepend_string + "TO.C,";
651 cmp_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + eol_string;
652 }
653
654 // the full list of requested attributes:
655 std::string full_attribute_string = pad_attribute_string + net_attribute_string
656 + cmp_attribute_string;
657 // the short list of requested attributes
658 // (only modified or new attributes are stored here):
659 std::string short_attribute_string;
660
661 // Attributes have changed: update attribute string, and see if the previous attribute
662 // list (dictionary in Gerber language) must be cleared
663 if( aLastNetAttributes != full_attribute_string )
664 {
665 // first, remove no longer existing attributes.
666 // Because in KiCad the full attribute list is evaluated for each object,
667 // the entire dictionary is cleared
668 // If m_TryKeepPreviousAttributes is true, only the no longer existing attribute
669 // is cleared.
670 // Note: to avoid interaction between clear attributes and set attributes
671 // the clear attribute is inserted first.
672 bool clearDict = false;
673
674 if( aLastNetAttributes.find( "TO.P," ) != std::string::npos )
675 {
676 if( pad_attribute_string.empty() ) // No more this attribute
677 {
678 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
679 short_attribute_string.insert( 0, prepend_string + "TO.P" + eol_string );
680 else
681 clearDict = true;
682 }
683 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
684 {
685 // This attribute has changed
686 short_attribute_string += pad_attribute_string;
687 }
688 }
689 else // New attribute
690 {
691 short_attribute_string += pad_attribute_string;
692 }
693
694 if( aLastNetAttributes.find( "TO.N," ) != std::string::npos )
695 {
696 if( net_attribute_string.empty() ) // No more this attribute
697 {
698 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
699 short_attribute_string.insert( 0, prepend_string + "TO.N" + eol_string );
700 else
701 clearDict = true;
702 }
703 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
704 {
705 // This attribute has changed.
706 short_attribute_string += net_attribute_string;
707 }
708 }
709 else // New attribute
710 {
711 short_attribute_string += net_attribute_string;
712 }
713
714 if( aLastNetAttributes.find( "TO.C," ) != std::string::npos )
715 {
716 if( cmp_attribute_string.empty() ) // No more this attribute
717 {
718 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
719 {
720 // Refinement:
721 // the attribute will be cleared only if there is no pad attribute.
722 // If a pad attribute exists, the component name exists so the old
723 // TO.C value will be updated, therefore no need to clear it before updating
724 if( pad_attribute_string.empty() )
725 short_attribute_string.insert( 0, prepend_string + "TO.C" + eol_string );
726 }
727 else
728 {
729 clearDict = true;
730 }
731 }
732 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
733 {
734 // This attribute has changed.
735 short_attribute_string += cmp_attribute_string;
736 }
737 }
738 else // New attribute
739 {
740 short_attribute_string += cmp_attribute_string;
741 }
742
743 aClearPreviousAttributes = clearDict;
744
745 aLastNetAttributes = full_attribute_string;
746
747 if( clearDict )
748 aPrintedText = full_attribute_string;
749 else
750 aPrintedText = short_attribute_string;
751 }
752
753 return true;
754}
755
756
758{
759 // Clear all strings
760 m_Orientation = 0.0;
761 m_Manufacturer.Clear();
762 m_MPN.Clear();
763 m_Package.Clear();
764 m_Value.Clear();
766}
767
768
770{
771 wxString text;
772 wxString start_of_line( "%TO." );
773 wxString end_of_line( "*%\n" );
774
775 wxString mountTypeStrings[] =
776 {
777 "Other", "SMD", "TH"
778 };
779
780 if( !m_Manufacturer.IsEmpty() )
781 text << start_of_line << "CMfr," << m_Manufacturer << end_of_line;
782
783 if( !m_MPN.IsEmpty() )
784 text << start_of_line << "CMPN," << m_MPN << end_of_line;
785
786 if( !m_Package.IsEmpty() )
787 text << start_of_line << "Cpkg," << m_Package << end_of_line;
788
789 if( !m_Footprint.IsEmpty() )
790 text << start_of_line << "CFtp," << m_Footprint << end_of_line;
791
792 if( !m_Value.IsEmpty() )
793 text << start_of_line << "CVal," << m_Value << end_of_line;
794
795 if( !m_LibraryName.IsEmpty() )
796 text << start_of_line << "CLbN," << m_LibraryName << end_of_line;
797
798 if( !m_LibraryDescr.IsEmpty() )
799 text << start_of_line << "CLbD," << m_LibraryDescr << end_of_line;
800
801 text << start_of_line << "CMnt," << mountTypeStrings[m_MountType] << end_of_line;
802 text << start_of_line << "CRot," << m_Orientation << end_of_line;
803
804 return text;
805}
@ GBR_APERTURE_ATTRIB_CMP_DRILL
Aperture used for pad holes in drill files.
Definition: gbr_metadata.h:145
@ 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_PRESSFITDRILL
Aperture used for pressfit pads in drill files.
Definition: gbr_metadata.h:142
@ GBR_APERTURE_ATTRIB_PAD1_POS
Aperture used for flashed pin 1 (or A1 or AA1) position in placement files.
Definition: gbr_metadata.h:154
@ 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:148
@ GBR_APERTURE_ATTRIB_CMP_COURTYARD
Aperture used to draw component outline courtyard in placement files.
Definition: gbr_metadata.h:169
@ 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:173
@ GBR_APERTURE_ATTRIB_CMP_POSITION
Aperture used for flashed cmp position in placement files.
Definition: gbr_metadata.h:151
@ GBR_APERTURE_ATTRIB_CMP_BODY
Aperture used to draw component physical body outline without pins in placement files.
Definition: gbr_metadata.h:160
@ 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:157
@ 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:144
@ GBR_APERTURE_ATTRIB_CMP_FOOTPRINT
Aperture used to draw component footprint bounding box in placement files.
Definition: gbr_metadata.h:166
@ GBR_APERTURE_ATTRIB_CMP_LEAD2LEAD
Aperture used to draw component physical body outline with pins in placement files.
Definition: gbr_metadata.h:163
@ 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, const std::string &aCustomAttribute)
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