31#include <wx/datetime.h>
44 wxDateTime date( wxDateTime::GetTimeNow() );
47 wxString timezone_offset;
48 timezone_offset = date.Format(
"%z" );
53 if( timezone_offset.Len() > 3 )
55 timezone_offset.insert( 3,
":", 1 );
62 msg.Printf( wxS(
"%%TF.CreationDate,%s%s*%%" ), date.FormatISOCombined(), timezone_offset );
66 msg.Printf( wxS(
"G04 #@! TF.CreationDate,%s%s*" ), date.FormatISOCombined(),
71 msg.Printf( wxS(
"%s%s" ), date.FormatISOCombined(), timezone_offset );
75 msg.Printf( wxS(
"; #@! TF.CreationDate,%s%s" ), date.FormatISOCombined(),
106 wxString bname = aText;
107 int cnt = 16 - bname.Len();
110 bname.Append(
'X', cnt );
115 for(
unsigned ii = 0; ii < 4; ii++ )
117 int cc = int( bname[chr_idx++] ) & 0xFF;
118 guid << wxString::Format(
"%2.2x", cc );
124 for(
unsigned ii = 0; ii < 2; ii++ )
126 int cc = int( bname[chr_idx++] ) & 0xFF;
127 guid << wxString::Format(
"%2.2x", cc );
133 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
134 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
135 guid << wxString::Format(
"%3.3x", cc );
141 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
142 cc += int( bname[chr_idx++] ) & 0xFF;
143 guid << wxString::Format(
"%3.3x", cc );
149 for(
unsigned ii = 0; ii < 6; ii++ )
151 int cc = int( bname[chr_idx++] ) & 0xFF;
152 guid << wxString::Format(
"%2.2x", cc );
160 bool aUseX1StructuredComment )
162 std::string attribute_string;
163 std::string comment_string;
176 attribute_string =
"TA.AperFunction,EtchedComponent";
180 attribute_string =
"TA.AperFunction,Conductor";
184 attribute_string =
"TA.AperFunction,Profile";
188 attribute_string =
"TA.AperFunction,ViaPad";
193 attribute_string =
"TA.AperFunction,NonConductor";
198 attribute_string =
"TA.AperFunction,ComponentPad";
204 attribute_string =
"TA.AperFunction,SMDPad,SMDef";
209 attribute_string =
"TA.AperFunction,SMDPad,CuDef";
214 attribute_string =
"TA.AperFunction,BGAPad,SMDef";
219 attribute_string =
"TA.AperFunction,BGAPad,CuDef";
224 attribute_string =
"TA.AperFunction,ConnectorPad";
229 attribute_string =
"TA.AperFunction,WasherPad";
234 attribute_string =
"TA.AperFunction,HeatsinkPad";
239 attribute_string =
"TA.AperFunction,TestPad";
244 attribute_string =
"TA.AperFunction,FiducialPad,Global";
249 attribute_string =
"TA.AperFunction,FiducialPad,Local";
254 attribute_string =
"TA.AperFunction,CastellatedPad";
259 attribute_string =
"TA.AperFunction,CastellatedDrill";
263 attribute_string =
"TA.AperFunction,ViaDrill";
268 attribute_string =
"TA.AperFunction,ComponentDrill";
275 comment_string =
"aperture for slot hole";
276 attribute_string =
"TA.AperFunction,ComponentDrill";
282 attribute_string =
"TA.AperFunction,ComponentMain";
289 attribute_string =
"TA.AperFunction,ComponentPin";
297 attribute_string =
"TA.AperFunction,ComponentPin";
303 attribute_string =
"TA.AperFunction,ComponentOutline,Body";
309 attribute_string =
"TA.AperFunction,ComponentOutline,Lead2Lead";
315 attribute_string =
"TA.AperFunction,ComponentOutline,Footprint";
321 attribute_string =
"TA.AperFunction,ComponentOutline,Courtyard";
327 std::string full_attribute_string;
330 if( !attribute_string.empty() )
332 if( !comment_string.empty() )
334 full_attribute_string =
"G04 " + comment_string +
"*\n";
337 if( aUseX1StructuredComment )
339 full_attribute_string +=
"G04 #@! ";
344 full_attribute_string +=
"%";
349 full_attribute_string += attribute_string + eol_string;
351 return full_attribute_string;
359 if( aCode >=
'0' && aCode <=
'9' )
362 if( aCode >=
'A' && aCode <=
'F' )
363 return aCode -
'A' + 10;
365 if( aCode >=
'a' && aCode <=
'f' )
366 return aCode -
'a' + 10;
381 unsigned count = aString.Length();
383 for(
unsigned ii = 0; ii < count; ++ii )
385 unsigned code = aString[ii];
387 if( code ==
'\\' && ii < count-5 && aString[ii+1] ==
'u' )
399 for(
int jj = 0; jj < 4; jj++ )
402 code = aString[ii+jj+2];
418 txt.Append( wxChar( value ) );
424 txt.Append( aString[ii] );
430 txt.Append( aString[ii] );
452 for(
unsigned ii = 0; ii < aString.Length(); ++ii )
454 wxChar code = aString[ii];
475 if( !aAllowUtf8Chars && code > 0x7F )
484 std::snprintf( hexa,
sizeof( hexa ),
"\\u%4.4X", code & 0xFFFF );
509 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
526 if( !aString.IsEmpty() && ( aString[0] !=
'\"' || aString[aString.Len()-1] !=
'\"' ) )
533 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
541#define NO_NET_NAME wxT( "N/C" )
542#define NO_PAD_NAME wxT( "" )
547 bool aUseX1StructuredComment )
549 aClearPreviousAttributes =
false;
550 wxString prepend_string;
553 if( aUseX1StructuredComment )
555 prepend_string =
"G04 #@! ";
560 prepend_string =
"%";
567 if( aData ==
nullptr )
570 std::string pad_attribute_string;
571 std::string net_attribute_string;
572 std::string cmp_attribute_string;
582 pad_attribute_string = prepend_string +
"TO.P,";
598 pad_attribute_string +=
',';
603 pad_attribute_string += eol_string;
610 net_attribute_string = prepend_string +
"TO.N,";
632 net_attribute_string += eol_string;
642 cmp_attribute_string = prepend_string +
"TO.C,";
647 std::string full_attribute_string = pad_attribute_string + net_attribute_string
648 + cmp_attribute_string;
651 std::string short_attribute_string;
655 if( aLastNetAttributes != full_attribute_string )
664 bool clearDict =
false;
666 if( aLastNetAttributes.find(
"TO.P," ) != std::string::npos )
668 if( pad_attribute_string.empty() )
671 short_attribute_string.insert( 0, prepend_string +
"TO.P" + eol_string );
675 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
678 short_attribute_string += pad_attribute_string;
683 short_attribute_string += pad_attribute_string;
686 if( aLastNetAttributes.find(
"TO.N," ) != std::string::npos )
688 if( net_attribute_string.empty() )
691 short_attribute_string.insert( 0, prepend_string +
"TO.N" + eol_string );
695 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
698 short_attribute_string += net_attribute_string;
703 short_attribute_string += net_attribute_string;
706 if( aLastNetAttributes.find(
"TO.C," ) != std::string::npos )
708 if( cmp_attribute_string.empty() )
716 if( pad_attribute_string.empty() )
717 short_attribute_string.insert( 0, prepend_string +
"TO.C" + eol_string );
724 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
727 short_attribute_string += cmp_attribute_string;
732 short_attribute_string += cmp_attribute_string;
735 aClearPreviousAttributes = clearDict;
737 aLastNetAttributes = full_attribute_string;
740 aPrintedText = full_attribute_string;
742 aPrintedText = short_attribute_string;
764 wxString start_of_line(
"%TO." );
765 wxString end_of_line(
"*%\n" );
767 wxString mountTypeStrings[] =
775 if( !
m_MPN.IsEmpty() )
776 text << start_of_line <<
"CMPN," <<
m_MPN << end_of_line;
779 text << start_of_line <<
"Cpkg," <<
m_Package << end_of_line;
785 text << start_of_line <<
"CVal," <<
m_Value << end_of_line;
793 text << start_of_line <<
"CMnt," << mountTypeStrings[
m_MountType] << end_of_line;
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