Loading pcbnew/class_pad.cpp +35 −16 Original line number Diff line number Diff line Loading @@ -141,6 +141,9 @@ const wxPoint D_PAD::ReturnShapePos() const wxString D_PAD::GetPadName() const { #if 0 // m_Padname is not ASCII and not UTF8, it is LATIN1 basically, whatever // 8 bit font is supported in KiCad plotting and drawing. // Return pad name as wxString, assume it starts as a non-terminated // utf8 character sequence Loading @@ -151,11 +154,21 @@ const wxString D_PAD::GetPadName() const temp[sizeof(m_Padname)] = 0; return FROM_UTF8( temp ); #else wxString name; ReturnStringPadName( name ); return name; #endif } void D_PAD::ReturnStringPadName( wxString& text ) const { #if 0 // m_Padname is not ASCII and not UTF8, it is LATIN1 basically, whatever // 8 bit font is supported in KiCad plotting and drawing. // Return pad name as wxString, assume it starts as a non-terminated // utf8 character sequence Loading @@ -166,6 +179,20 @@ void D_PAD::ReturnStringPadName( wxString& text ) const temp[sizeof(m_Padname)] = 0; text = FROM_UTF8( temp ); #else text.Empty(); for( int ii = 0; ii < PADNAMEZ; ii++ ) { if( !m_Padname[ii] ) break; // add an unsigned 8 bit byte, which is LATIN1 or CRYLIC text.Append( (unsigned char) m_Padname[ii] ); } #endif } Loading @@ -176,25 +203,17 @@ void D_PAD::SetPadName( const wxString& name ) len = name.Length(); if( len > 4 ) len = 4; if( len > PADNAMEZ ) len = PADNAMEZ; for( ii = 0; ii < len; ii++ ) m_Padname[ii] = name.GetChar( ii ); // m_Padname[] is not UTF8, it is an 8 bit character that matches the KiCad font, // so only copy the lower 8 bits of each character. for( ii = len; ii < 4; ii++ ) m_Padname[ii] = 0; } void D_PAD::SetPadName( const char* aName ) { unsigned i; for( i=0; i<sizeof(m_Padname) && *aName; ++i ) m_Padname[i] = *aName++; for( ii = 0; ii < len; ii++ ) m_Padname[ii] = (char) name.GetChar( ii ); while( i < sizeof(m_Padname) ) m_Padname[i++] = 0; for( ii = len; ii < PADNAMEZ; ii++ ) m_Padname[ii] = '\0'; } Loading pcbnew/class_pad.h +19 −16 Original line number Diff line number Diff line Loading @@ -71,18 +71,21 @@ private: wxString m_Netname; // Full net name like /mysheet/mysubsheet/vout used by Eeschema wxString m_ShortNetname; // short net name, like vout from /mysheet/mysubsheet/vout public: wxPoint m_Pos; // pad Position on board /// Pad name (4 char) or a long identifier (used in pad name /// comparisons because this is faster than string comparison) union { unsigned long m_NumPadName; char m_Padname[4]; /* Pad name (4 char) or a long identifier (used in pad name * comparisons because this is faster than string comparison) */ #define PADNAMEZ 4 char m_Padname[PADNAMEZ]; // zero padded at end to full size wxUint32 m_NumPadName; // same number of bytes as m_Padname[] }; int m_SubRatsnest; // variable used in rats nest computations // handle subnet (block) number in ratsnest connection public: wxPoint m_Pos; // pad Position on board int m_layerMask; // Bitwise layer :1= copper layer, 15= cmp, // 2..14 = internal layers // 16 .. 31 = technical layers Loading Loading @@ -134,10 +137,6 @@ public: double m_LocalSolderPasteMarginRatio; // Local solder mask margin ratio value of pad size // The final margin is the sum of these 2 values private: int m_SubRatsnest; // variable used in rats nest computations // handle subnet (block) number in ratsnest connection public: D_PAD( MODULE* parent ); D_PAD( D_PAD* pad ); Loading @@ -147,6 +146,14 @@ public: D_PAD* Next() { return (D_PAD*) Pnext; } void SetPadName( const wxString& name ); // Change pad name const wxString GetPadName() const; bool PadNameEqual( const D_PAD* other ) const { return m_NumPadName == other->m_NumPadName; // hide tricks behind sensible API } /** * Function SetNetname * @param aNetname: the new netname Loading Loading @@ -347,10 +354,6 @@ public: */ int BuildSegmentFromOvalShape( wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation ) const; void SetPadName( const wxString& name ); // Change pad name void SetPadName( const char* aName ); const wxString GetPadName() const; void ReturnStringPadName( wxString& text ) const; // Return pad name as string in a buffer void ComputeShapeMaxRadius(); // compute radius Loading pcbnew/drc.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -664,7 +664,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_li // one can argue that this 2nd test is not necessary, that any // two pads from a single module are acceptable. This 2nd test // should eventually be a configuration option. if( pad->m_NumPadName == aRefPad->m_NumPadName ) if( pad->PadNameEqual( aRefPad ) ) continue; } Loading pcbnew/gen_modules_placefile.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -435,7 +435,7 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) for( pad = Module->m_Pads; pad != NULL; pad = pad->Next() ) { fprintf( rptfile, "$PAD \"%.4s\"\n", pad->m_Padname ); fprintf( rptfile, "$PAD \"%s\"\n", TO_UTF8( pad->GetPadName() ) ); sprintf( line, "position %9.6f %9.6f\n", pad->m_Pos0.x * conv_unit, pad->m_Pos0.y * conv_unit ); Loading pcbnew/kicad_plugin.cpp +53 −15 Original line number Diff line number Diff line Loading @@ -60,13 +60,7 @@ #include <auto_ptr.h> #include <kicad_string.h> #include <macros.h> #include <build_version.h> //#include <fctsys.h> //#include <confirm.h> //#include <wxPcbStruct.h"> //#include <pcbcommon.h> //#include <build_version.h> #include <zones.h> #ifdef CVPCB Loading @@ -90,17 +84,15 @@ #include <wx/ffile.h> //#define KICAD_NANOMETRE #define VERSION_ERROR_FORMAT _( "File '%s' is format version: %d.\nI only support format version <= %d.\nPlease upgrade PCBNew to load this file." ) #define UNKNOWN_GRAPHIC_FORMAT _( "unknown graphic type: %d") #define UNKNOWN_PAD_FORMAT _( "unknown pad type: %d") #define UNKNOWN_PAD_ATTRIBUTE _( "unknown pad attribute: %d" ) /* #include <pcbnew.h> #include <pcbnew_id.h> #include <autorout.h> */ /// C string compare test for a specific length of characters. Loading Loading @@ -330,6 +322,8 @@ void KICAD_PLUGIN::checkVersion() m_error.Printf( VERSION_ERROR_FORMAT, ver ); THROW_IO_ERROR( m_error ); } m_loading_format_version = ver; } Loading Loading @@ -1039,11 +1033,15 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule ) // e.g. "Sh "A2" C 520 520 0 0 900" // or "Sh "1" R 157 1378 0 0 900" char padname[sizeof(pad->m_Padname)+1]; // mypadname is LATIN1/CRYLIC for BOARD_FORMAT_VERSION 1, // but for BOARD_FORMAT_VERSION 2, it is UTF8 from disk. // So we have to go through two code paths. Moving forward // padnames will be in UTF8 on disk, as are all KiCad strings on disk. char mypadname[50]; data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace data = data + ReadDelimitedText( padname, data, sizeof(padname) ) + 1; // +1 trailing whitespace data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1; // +1 trailing whitespace // sscanf( PtLine, " %s %d %d %d %d %d", BufCar, &m_Size.x, &m_Size.y, &m_DeltaSize.x, &m_DeltaSize.y, &m_Orient ); Loading @@ -1066,6 +1064,26 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule ) THROW_IO_ERROR( m_error ); } // go through a wxString to establish a universal character set properly wxString padname; if( m_loading_format_version == 1 ) { // add 8 bit bytes, file format 1 was KiCad font type byte, // simply promote those 8 bit bytes up into UNICODE. (subset of LATIN1) const unsigned char* cp = (unsigned char*) mypadname; while( *cp ) { padname += *cp++; // unsigned, ls 8 bits only } } else { // version 2, which is UTF8. padname = FROM_UTF8( mypadname ); } // chances are both were ASCII, but why take chances? pad->SetPadName( padname ); pad->SetShape( padshape ); pad->SetSize( wxSize( size_x, size_y ) ); Loading Loading @@ -3059,8 +3077,28 @@ void KICAD_PLUGIN::savePAD( const D_PAD* me ) const THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_FORMAT, me->GetShape() ) ); } // universal character set padname wxString padname = me->GetPadName(); #if BOARD_FORMAT_VERSION == 1 char mypadname[PADNAMEZ+1]; int i; for( i = 0; i<PADNAMEZ && padname[i]; ++i ) { // truncate from universal character down to 8 bit foreign jibber jabber byte mypadname[i] = (char) padname[i]; } mypadname[i] = 0; fprintf( m_fp, "Sh \"%s\" %c %s %s %s\n", mypadname, // probably ASCII, but possibly jibber jabber #else fprintf( m_fp, "Sh %s %c %s %s %s\n", EscapedUTF8( me->GetPadName() ).c_str(), #endif cshape, fmtBIUSize( me->GetSize() ).c_str(), fmtBIUSize( me->GetDelta() ).c_str(), Loading Loading
pcbnew/class_pad.cpp +35 −16 Original line number Diff line number Diff line Loading @@ -141,6 +141,9 @@ const wxPoint D_PAD::ReturnShapePos() const wxString D_PAD::GetPadName() const { #if 0 // m_Padname is not ASCII and not UTF8, it is LATIN1 basically, whatever // 8 bit font is supported in KiCad plotting and drawing. // Return pad name as wxString, assume it starts as a non-terminated // utf8 character sequence Loading @@ -151,11 +154,21 @@ const wxString D_PAD::GetPadName() const temp[sizeof(m_Padname)] = 0; return FROM_UTF8( temp ); #else wxString name; ReturnStringPadName( name ); return name; #endif } void D_PAD::ReturnStringPadName( wxString& text ) const { #if 0 // m_Padname is not ASCII and not UTF8, it is LATIN1 basically, whatever // 8 bit font is supported in KiCad plotting and drawing. // Return pad name as wxString, assume it starts as a non-terminated // utf8 character sequence Loading @@ -166,6 +179,20 @@ void D_PAD::ReturnStringPadName( wxString& text ) const temp[sizeof(m_Padname)] = 0; text = FROM_UTF8( temp ); #else text.Empty(); for( int ii = 0; ii < PADNAMEZ; ii++ ) { if( !m_Padname[ii] ) break; // add an unsigned 8 bit byte, which is LATIN1 or CRYLIC text.Append( (unsigned char) m_Padname[ii] ); } #endif } Loading @@ -176,25 +203,17 @@ void D_PAD::SetPadName( const wxString& name ) len = name.Length(); if( len > 4 ) len = 4; if( len > PADNAMEZ ) len = PADNAMEZ; for( ii = 0; ii < len; ii++ ) m_Padname[ii] = name.GetChar( ii ); // m_Padname[] is not UTF8, it is an 8 bit character that matches the KiCad font, // so only copy the lower 8 bits of each character. for( ii = len; ii < 4; ii++ ) m_Padname[ii] = 0; } void D_PAD::SetPadName( const char* aName ) { unsigned i; for( i=0; i<sizeof(m_Padname) && *aName; ++i ) m_Padname[i] = *aName++; for( ii = 0; ii < len; ii++ ) m_Padname[ii] = (char) name.GetChar( ii ); while( i < sizeof(m_Padname) ) m_Padname[i++] = 0; for( ii = len; ii < PADNAMEZ; ii++ ) m_Padname[ii] = '\0'; } Loading
pcbnew/class_pad.h +19 −16 Original line number Diff line number Diff line Loading @@ -71,18 +71,21 @@ private: wxString m_Netname; // Full net name like /mysheet/mysubsheet/vout used by Eeschema wxString m_ShortNetname; // short net name, like vout from /mysheet/mysubsheet/vout public: wxPoint m_Pos; // pad Position on board /// Pad name (4 char) or a long identifier (used in pad name /// comparisons because this is faster than string comparison) union { unsigned long m_NumPadName; char m_Padname[4]; /* Pad name (4 char) or a long identifier (used in pad name * comparisons because this is faster than string comparison) */ #define PADNAMEZ 4 char m_Padname[PADNAMEZ]; // zero padded at end to full size wxUint32 m_NumPadName; // same number of bytes as m_Padname[] }; int m_SubRatsnest; // variable used in rats nest computations // handle subnet (block) number in ratsnest connection public: wxPoint m_Pos; // pad Position on board int m_layerMask; // Bitwise layer :1= copper layer, 15= cmp, // 2..14 = internal layers // 16 .. 31 = technical layers Loading Loading @@ -134,10 +137,6 @@ public: double m_LocalSolderPasteMarginRatio; // Local solder mask margin ratio value of pad size // The final margin is the sum of these 2 values private: int m_SubRatsnest; // variable used in rats nest computations // handle subnet (block) number in ratsnest connection public: D_PAD( MODULE* parent ); D_PAD( D_PAD* pad ); Loading @@ -147,6 +146,14 @@ public: D_PAD* Next() { return (D_PAD*) Pnext; } void SetPadName( const wxString& name ); // Change pad name const wxString GetPadName() const; bool PadNameEqual( const D_PAD* other ) const { return m_NumPadName == other->m_NumPadName; // hide tricks behind sensible API } /** * Function SetNetname * @param aNetname: the new netname Loading Loading @@ -347,10 +354,6 @@ public: */ int BuildSegmentFromOvalShape( wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation ) const; void SetPadName( const wxString& name ); // Change pad name void SetPadName( const char* aName ); const wxString GetPadName() const; void ReturnStringPadName( wxString& text ) const; // Return pad name as string in a buffer void ComputeShapeMaxRadius(); // compute radius Loading
pcbnew/drc.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -664,7 +664,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_li // one can argue that this 2nd test is not necessary, that any // two pads from a single module are acceptable. This 2nd test // should eventually be a configuration option. if( pad->m_NumPadName == aRefPad->m_NumPadName ) if( pad->PadNameEqual( aRefPad ) ) continue; } Loading
pcbnew/gen_modules_placefile.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -435,7 +435,7 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) for( pad = Module->m_Pads; pad != NULL; pad = pad->Next() ) { fprintf( rptfile, "$PAD \"%.4s\"\n", pad->m_Padname ); fprintf( rptfile, "$PAD \"%s\"\n", TO_UTF8( pad->GetPadName() ) ); sprintf( line, "position %9.6f %9.6f\n", pad->m_Pos0.x * conv_unit, pad->m_Pos0.y * conv_unit ); Loading
pcbnew/kicad_plugin.cpp +53 −15 Original line number Diff line number Diff line Loading @@ -60,13 +60,7 @@ #include <auto_ptr.h> #include <kicad_string.h> #include <macros.h> #include <build_version.h> //#include <fctsys.h> //#include <confirm.h> //#include <wxPcbStruct.h"> //#include <pcbcommon.h> //#include <build_version.h> #include <zones.h> #ifdef CVPCB Loading @@ -90,17 +84,15 @@ #include <wx/ffile.h> //#define KICAD_NANOMETRE #define VERSION_ERROR_FORMAT _( "File '%s' is format version: %d.\nI only support format version <= %d.\nPlease upgrade PCBNew to load this file." ) #define UNKNOWN_GRAPHIC_FORMAT _( "unknown graphic type: %d") #define UNKNOWN_PAD_FORMAT _( "unknown pad type: %d") #define UNKNOWN_PAD_ATTRIBUTE _( "unknown pad attribute: %d" ) /* #include <pcbnew.h> #include <pcbnew_id.h> #include <autorout.h> */ /// C string compare test for a specific length of characters. Loading Loading @@ -330,6 +322,8 @@ void KICAD_PLUGIN::checkVersion() m_error.Printf( VERSION_ERROR_FORMAT, ver ); THROW_IO_ERROR( m_error ); } m_loading_format_version = ver; } Loading Loading @@ -1039,11 +1033,15 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule ) // e.g. "Sh "A2" C 520 520 0 0 900" // or "Sh "1" R 157 1378 0 0 900" char padname[sizeof(pad->m_Padname)+1]; // mypadname is LATIN1/CRYLIC for BOARD_FORMAT_VERSION 1, // but for BOARD_FORMAT_VERSION 2, it is UTF8 from disk. // So we have to go through two code paths. Moving forward // padnames will be in UTF8 on disk, as are all KiCad strings on disk. char mypadname[50]; data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace data = data + ReadDelimitedText( padname, data, sizeof(padname) ) + 1; // +1 trailing whitespace data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1; // +1 trailing whitespace // sscanf( PtLine, " %s %d %d %d %d %d", BufCar, &m_Size.x, &m_Size.y, &m_DeltaSize.x, &m_DeltaSize.y, &m_Orient ); Loading @@ -1066,6 +1064,26 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule ) THROW_IO_ERROR( m_error ); } // go through a wxString to establish a universal character set properly wxString padname; if( m_loading_format_version == 1 ) { // add 8 bit bytes, file format 1 was KiCad font type byte, // simply promote those 8 bit bytes up into UNICODE. (subset of LATIN1) const unsigned char* cp = (unsigned char*) mypadname; while( *cp ) { padname += *cp++; // unsigned, ls 8 bits only } } else { // version 2, which is UTF8. padname = FROM_UTF8( mypadname ); } // chances are both were ASCII, but why take chances? pad->SetPadName( padname ); pad->SetShape( padshape ); pad->SetSize( wxSize( size_x, size_y ) ); Loading Loading @@ -3059,8 +3077,28 @@ void KICAD_PLUGIN::savePAD( const D_PAD* me ) const THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_FORMAT, me->GetShape() ) ); } // universal character set padname wxString padname = me->GetPadName(); #if BOARD_FORMAT_VERSION == 1 char mypadname[PADNAMEZ+1]; int i; for( i = 0; i<PADNAMEZ && padname[i]; ++i ) { // truncate from universal character down to 8 bit foreign jibber jabber byte mypadname[i] = (char) padname[i]; } mypadname[i] = 0; fprintf( m_fp, "Sh \"%s\" %c %s %s %s\n", mypadname, // probably ASCII, but possibly jibber jabber #else fprintf( m_fp, "Sh %s %c %s %s %s\n", EscapedUTF8( me->GetPadName() ).c_str(), #endif cshape, fmtBIUSize( me->GetSize() ).c_str(), fmtBIUSize( me->GetDelta() ).c_str(), Loading