27#include <wx/datetime.h>
40 wxDateTime date( wxDateTime::GetTimeNow() );
43 wxString timezone_offset;
44 timezone_offset = date.Format(
"%z" );
49 if( timezone_offset.Len() > 3 )
51 timezone_offset.insert( 3,
":", 1 );
58 msg.Printf( wxS(
"%%TF.CreationDate,%s%s*%%" ), date.FormatISOCombined(), timezone_offset );
62 msg.Printf( wxS(
"G04 #@! TF.CreationDate,%s%s*" ), date.FormatISOCombined(), timezone_offset );
66 msg.Printf( wxS(
"%s%s" ), date.FormatISOCombined(), timezone_offset );
70 msg.Printf( wxS(
"; #@! TF.CreationDate,%s%s" ), date.FormatISOCombined(), timezone_offset );
100 wxString bname = aText;
101 int cnt = 16 - bname.Len();
104 bname.Append(
'X', cnt );
109 for(
unsigned ii = 0; ii < 4; ii++ )
111 int cc = int( bname[chr_idx++] ) & 0xFF;
112 guid << wxString::Format(
"%2.2x", cc );
118 for(
unsigned ii = 0; ii < 2; ii++ )
120 int cc = int( bname[chr_idx++] ) & 0xFF;
121 guid << wxString::Format(
"%2.2x", cc );
127 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
128 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
129 guid << wxString::Format(
"%3.3x", cc );
135 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
136 cc += int( bname[chr_idx++] ) & 0xFF;
137 guid << wxString::Format(
"%3.3x", cc );
143 for(
unsigned ii = 0; ii < 6; ii++ )
145 int cc = int( bname[chr_idx++] ) & 0xFF;
146 guid << wxString::Format(
"%2.2x", cc );
154 bool aUseX1StructuredComment,
155 const std::string& aCustomAttribute )
157 std::string attribute_string;
158 std::string comment_string;
171 attribute_string =
"TA.AperFunction,EtchedComponent";
175 attribute_string =
"TA.AperFunction,Conductor";
179 attribute_string =
"TA.AperFunction,Profile";
183 attribute_string =
"TA.AperFunction,ViaPad";
188 attribute_string =
"TA.AperFunction,NonConductor";
193 attribute_string =
"TA.AperFunction,ComponentPad";
199 attribute_string =
"TA.AperFunction,SMDPad,SMDef";
204 attribute_string =
"TA.AperFunction,SMDPad,CuDef";
209 attribute_string =
"TA.AperFunction,BGAPad,SMDef";
214 attribute_string =
"TA.AperFunction,BGAPad,CuDef";
219 attribute_string =
"TA.AperFunction,ConnectorPad";
224 attribute_string =
"TA.AperFunction,WasherPad";
229 attribute_string =
"TA.AperFunction,HeatsinkPad";
234 attribute_string =
"TA.AperFunction,TestPad";
239 attribute_string =
"TA.AperFunction,FiducialPad,Global";
244 attribute_string =
"TA.AperFunction,FiducialPad,Local";
249 attribute_string =
"TA.AperFunction,CastellatedPad";
254 attribute_string =
"TA.AperFunction,CastellatedDrill";
258 attribute_string =
"TA.AperFunction,ViaDrill";
262 attribute_string =
"TA.AperFunction,BackDrill";
267 attribute_string =
"TA.AperFunction,ComponentDrill";
272 attribute_string =
"TA.AperFunction,ComponentDrill,PressFit";
279 comment_string =
"aperture for slot hole";
280 attribute_string =
"TA.AperFunction,ComponentDrill";
286 attribute_string =
"TA.AperFunction,ComponentMain";
293 attribute_string =
"TA.AperFunction,ComponentPin";
301 attribute_string =
"TA.AperFunction,ComponentPin";
307 attribute_string =
"TA.AperFunction,ComponentOutline,Body";
313 attribute_string =
"TA.AperFunction,ComponentOutline,Lead2Lead";
319 attribute_string =
"TA.AperFunction,ComponentOutline,Footprint";
325 attribute_string =
"TA.AperFunction,ComponentOutline,Courtyard";
329 attribute_string =
"TA.AperFunction,Other," + aCustomAttribute;
333 std::string full_attribute_string;
336 if( !attribute_string.empty() )
338 if( !comment_string.empty() )
340 full_attribute_string =
"G04 " + comment_string +
"*\n";
343 if( aUseX1StructuredComment )
345 full_attribute_string +=
"G04 #@! ";
350 full_attribute_string +=
"%";
355 full_attribute_string += attribute_string + eol_string;
357 return full_attribute_string;
365 if( aCode >=
'0' && aCode <=
'9' )
368 if( aCode >=
'A' && aCode <=
'F' )
369 return aCode -
'A' + 10;
371 if( aCode >=
'a' && aCode <=
'f' )
372 return aCode -
'a' + 10;
387 unsigned count = aString.Length();
389 for(
unsigned ii = 0; ii < count; ++ii )
391 unsigned code = aString[ii];
393 if( code ==
'\\' && ii < count-5 && aString[ii+1] ==
'u' )
405 for(
int jj = 0; jj < 4; jj++ )
408 code = aString[ii+jj+2];
424 txt.Append( wxChar( value ) );
430 txt.Append( aString[ii] );
436 txt.Append( aString[ii] );
458 for(
unsigned ii = 0; ii < aString.Length(); ++ii )
460 wxChar code = aString[ii];
481 if( !aAllowUtf8Chars && code > 0x7F )
490 std::snprintf( hexa,
sizeof( hexa ),
"\\u%4.4X", code & 0xFFFF );
515 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
532 if( !aString.IsEmpty() && ( aString[0] !=
'\"' || aString[aString.Len()-1] !=
'\"' ) )
539 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
547#define NO_NET_NAME wxT( "N/C" )
548#define NO_PAD_NAME wxT( "" )
553 bool aUseX1StructuredComment )
555 aClearPreviousAttributes =
false;
556 wxString prepend_string;
559 if( aUseX1StructuredComment )
561 prepend_string =
"G04 #@! ";
566 prepend_string =
"%";
573 if( aData ==
nullptr )
576 std::string pad_attribute_string;
577 std::string net_attribute_string;
578 std::string cmp_attribute_string;
588 pad_attribute_string = prepend_string +
"TO.P,";
604 pad_attribute_string +=
',';
609 pad_attribute_string += eol_string;
616 net_attribute_string = prepend_string +
"TO.N,";
638 net_attribute_string += eol_string;
648 cmp_attribute_string = prepend_string +
"TO.C,";
653 std::string full_attribute_string = pad_attribute_string + net_attribute_string
654 + cmp_attribute_string;
657 std::string short_attribute_string;
661 if( aLastNetAttributes != full_attribute_string )
670 bool clearDict =
false;
672 if( aLastNetAttributes.find(
"TO.P," ) != std::string::npos )
674 if( pad_attribute_string.empty() )
677 short_attribute_string.insert( 0, prepend_string +
"TO.P" + eol_string );
681 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
684 short_attribute_string += pad_attribute_string;
689 short_attribute_string += pad_attribute_string;
692 if( aLastNetAttributes.find(
"TO.N," ) != std::string::npos )
694 if( net_attribute_string.empty() )
697 short_attribute_string.insert( 0, prepend_string +
"TO.N" + eol_string );
701 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
704 short_attribute_string += net_attribute_string;
709 short_attribute_string += net_attribute_string;
712 if( aLastNetAttributes.find(
"TO.C," ) != std::string::npos )
714 if( cmp_attribute_string.empty() )
722 if( pad_attribute_string.empty() )
723 short_attribute_string.insert( 0, prepend_string +
"TO.C" + eol_string );
730 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
733 short_attribute_string += cmp_attribute_string;
738 short_attribute_string += cmp_attribute_string;
741 aClearPreviousAttributes = clearDict;
743 aLastNetAttributes = full_attribute_string;
746 aPrintedText = full_attribute_string;
748 aPrintedText = short_attribute_string;
770 wxString start_of_line(
"%TO." );
771 wxString end_of_line(
"*%\n" );
773 wxString mountTypeStrings[] =
781 if( !
m_MPN.IsEmpty() )
782 text << start_of_line <<
"CMPN," <<
m_MPN << end_of_line;
785 text << start_of_line <<
"Cpkg," <<
m_Package << end_of_line;
791 text << start_of_line <<
"CVal," <<
m_Value << end_of_line;
799 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