From 378846c2e3b5213633abd7299eb15858420554e8 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 14 Dec 2017 10:37:32 +0100 Subject: [PATCH] Eagle Schematics Importer: support for UTF-8 Fixes: lp:1736083 * https://bugs.launchpad.net/kicad/+bug/1736083 --- common/eagle_parser.cpp | 131 +++++++++++++++++++--------------- common/lib_id.cpp | 3 +- eeschema/sch_eagle_plugin.cpp | 77 ++++++++------------ eeschema/sch_eagle_plugin.h | 18 ++--- include/eagle_parser.h | 102 +++++++++++++------------- pcbnew/eagle_plugin.cpp | 57 +++++++-------- pcbnew/eagle_plugin.h | 14 ++-- 7 files changed, 199 insertions(+), 203 deletions(-) diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp index c0d2ee94ca..89f5960931 100644 --- a/common/eagle_parser.cpp +++ b/common/eagle_parser.cpp @@ -34,6 +34,16 @@ constexpr auto DEFAULT_ALIGNMENT = ETEXT::BOTTOM_LEFT; +template<> template<> +OPTIONAL_XML_ATTRIBUTE::OPTIONAL_XML_ATTRIBUTE( wxString aData ) +{ + m_isAvailable = !aData.IsEmpty(); + + if( m_isAvailable ) + Set( aData ); +} + + ECOORD::ECOORD( const wxString& aValue, enum ECOORD::EAGLE_UNIT aUnit ) { // this array is used to adjust the fraction part value basing on the number of digits in the fraction @@ -94,6 +104,7 @@ long long int ECOORD::ToNanoMeters( int aValue, enum EAGLE_UNIT aUnit ) // Template specializations below parse wxString to the used types: +// - wxString (preferred) // - string // - double // - int @@ -101,10 +112,17 @@ long long int ECOORD::ToNanoMeters( int aValue, enum EAGLE_UNIT aUnit ) // - EROT // - ECOORD -template<> -string Convert( const wxString& aValue ) +template <> +wxString Convert( const wxString& aValue ) { - return string( aValue.ToUTF8() ); + return aValue; +} + + +template <> +std::string Convert( const wxString& aValue ) +{ + return std::string( aValue.ToUTF8() ); } @@ -179,7 +197,7 @@ ECOORD Convert( const wxString& aCoord ) * @return T - the attributed parsed as the specified type. */ template -T parseRequiredAttribute( wxXmlNode* aNode, const string& aAttribute ) +T parseRequiredAttribute( wxXmlNode* aNode, const wxString& aAttribute ) { wxString value; @@ -189,6 +207,7 @@ T parseRequiredAttribute( wxXmlNode* aNode, const string& aAttribute ) throw XML_PARSER_ERROR( "The required attribute " + aAttribute + " is missing." ); } + /** * Function parseOptionalAttribute * parses the aAttribute of the XML node aNode. @@ -198,7 +217,7 @@ T parseRequiredAttribute( wxXmlNode* aNode, const string& aAttribute ) * found. */ template -OPTIONAL_XML_ATTRIBUTE parseOptionalAttribute( wxXmlNode* aNode, const string& aAttribute ) +OPTIONAL_XML_ATTRIBUTE parseOptionalAttribute( wxXmlNode* aNode, const wxString& aAttribute ) { return OPTIONAL_XML_ATTRIBUTE( aNode->GetAttribute( aAttribute ) ); } @@ -218,7 +237,7 @@ NODE_MAP MapChildren( wxXmlNode* aCurrentNode ) // Create a new pair in the map // key: current node name // value: current node pointer - nodesMap[aCurrentNode->GetName().ToStdString()] = aCurrentNode; + nodesMap[aCurrentNode->GetName()] = aCurrentNode; // Get next child aCurrentNode = aCurrentNode->GetNext(); @@ -235,10 +254,10 @@ unsigned long EagleTimeStamp( wxXmlNode* aTree ) } -time_t EagleModuleTstamp( const string& aName, const string& aValue, int aUnit ) +time_t EagleModuleTstamp( const wxString& aName, const wxString& aValue, int aUnit ) { - std::size_t h1 = std::hash{}( aName ); - std::size_t h2 = std::hash{}( aValue ); + std::size_t h1 = std::hash{}( aName ); + std::size_t h2 = std::hash{}( aValue ); std::size_t h3 = std::hash{}( aUnit ); return h1 ^ (h2 << 1) ^ (h3 << 2); @@ -319,7 +338,7 @@ EWIRE::EWIRE( wxXmlNode* aWire ) layer = parseRequiredAttribute( aWire, "layer" ); curve = parseOptionalAttribute( aWire, "curve" ); - opt_string s = parseOptionalAttribute( aWire, "style" ); + opt_wxString s = parseOptionalAttribute( aWire, "style" ); if( s == "continuous" ) style = EWIRE::CONTINUOUS; @@ -330,7 +349,7 @@ EWIRE::EWIRE( wxXmlNode* aWire ) else if( s == "dashdot" ) style = EWIRE::DASHDOT; - s = parseOptionalAttribute( aWire, "cap" ); + s = parseOptionalAttribute( aWire, "cap" ); if( s == "round" ) cap = EWIRE::ROUND; @@ -375,7 +394,7 @@ ELABEL::ELABEL( wxXmlNode* aLabel, const wxString& aNetName ) size = parseRequiredAttribute( aLabel, "size" ); layer = parseRequiredAttribute( aLabel, "layer" ); rot = parseOptionalAttribute( aLabel, "rot" ); - xref = parseOptionalAttribute( aLabel, "xref" ); + xref = parseOptionalAttribute( aLabel, "xref" ); netname = aNetName; } @@ -398,13 +417,12 @@ EVIA::EVIA( wxXmlNode* aVia ) x = parseRequiredAttribute( aVia, "x" ); y = parseRequiredAttribute( aVia, "y" ); - string ext = parseRequiredAttribute( aVia, "extent" ); - + wxString ext = parseRequiredAttribute( aVia, "extent" ); sscanf( ext.c_str(), "%d-%d", &layer_front_most, &layer_back_most ); drill = parseRequiredAttribute( aVia, "drill" ); diam = parseOptionalAttribute( aVia, "diameter" ); - shape = parseOptionalAttribute( aVia, "shape" ); + shape = parseOptionalAttribute( aVia, "shape" ); } @@ -471,8 +489,8 @@ EATTR::EATTR( wxXmlNode* aTree ) > */ - name = parseRequiredAttribute( aTree, "name" ); - value = parseOptionalAttribute( aTree, "value" ); + name = parseRequiredAttribute( aTree, "name" ); + value = parseOptionalAttribute( aTree, "value" ); x = parseOptionalAttribute( aTree, "x" ); y = parseOptionalAttribute( aTree, "y" ); @@ -484,7 +502,7 @@ EATTR::EATTR( wxXmlNode* aTree ) ratio = parseOptionalAttribute( aTree, "ratio" ); rot = parseOptionalAttribute( aTree, "rot" ); - opt_string stemp = parseOptionalAttribute( aTree, "display" ); + opt_wxString stemp = parseOptionalAttribute( aTree, "display" ); // (off | value | name | both) if( stemp == "off" ) @@ -496,7 +514,7 @@ EATTR::EATTR( wxXmlNode* aTree ) else if( stemp == "both" ) display = EATTR::BOTH; - stemp = parseOptionalAttribute( aTree, "align" ); + stemp = parseOptionalAttribute( aTree, "align" ); align = stemp ? parseAlignment( *stemp ) : DEFAULT_ALIGNMENT; } @@ -525,7 +543,7 @@ EDIMENSION::EDIMENSION( wxXmlNode* aDimension ) x3 = parseRequiredAttribute( aDimension, "x3" ); y3 = parseRequiredAttribute( aDimension, "y3" ); layer = parseRequiredAttribute( aDimension, "layer" ); - dimensionType = parseOptionalAttribute( aDimension, "dtype" ); + dimensionType = parseOptionalAttribute( aDimension, "dtype" ); } @@ -551,11 +569,11 @@ ETEXT::ETEXT( wxXmlNode* aText ) size = parseRequiredAttribute( aText, "size" ); layer = parseRequiredAttribute( aText, "layer" ); - font = parseOptionalAttribute( aText, "font" ); + font = parseOptionalAttribute( aText, "font" ); ratio = parseOptionalAttribute( aText, "ratio" ); rot = parseOptionalAttribute( aText, "rot" ); - opt_string stemp = parseOptionalAttribute( aText, "align" ); + opt_wxString stemp = parseOptionalAttribute( aText, "align" ); align = stemp ? parseAlignment( *stemp ) : DEFAULT_ALIGNMENT; } @@ -611,7 +629,7 @@ EPAD::EPAD( wxXmlNode* aPad ) */ // #REQUIRED says DTD, throw exception if not found - name = parseRequiredAttribute( aPad, "name" ); + name = parseRequiredAttribute( aPad, "name" ); x = parseRequiredAttribute( aPad, "x" ); y = parseRequiredAttribute( aPad, "y" ); drill = parseRequiredAttribute( aPad, "drill" ); @@ -619,7 +637,7 @@ EPAD::EPAD( wxXmlNode* aPad ) // Optional attributes diameter = parseOptionalAttribute( aPad, "diameter" ); - opt_string s = parseOptionalAttribute( aPad, "shape" ); + opt_wxString s = parseOptionalAttribute( aPad, "shape" ); // (square | round | octagon | long | offset) if( s == "square" ) @@ -659,7 +677,7 @@ ESMD::ESMD( wxXmlNode* aSMD ) */ // DTD #REQUIRED, throw exception if not found - name = parseRequiredAttribute( aSMD, "name" ); + name = parseRequiredAttribute( aSMD, "name" ); x = parseRequiredAttribute( aSMD, "x" ); y = parseRequiredAttribute( aSMD, "y" ); dx = parseRequiredAttribute( aSMD, "dx" ); @@ -693,14 +711,14 @@ EPIN::EPIN( wxXmlNode* aPin ) */ // DTD #REQUIRED, throw exception if not found - name = parseRequiredAttribute( aPin, "name" ); + name = parseRequiredAttribute( aPin, "name" ); x = parseRequiredAttribute( aPin, "x" ); y = parseRequiredAttribute( aPin, "y" ); - visible = parseOptionalAttribute( aPin, "visible" ); - length = parseOptionalAttribute( aPin, "length" ); - direction = parseOptionalAttribute( aPin, "direction" ); - function = parseOptionalAttribute( aPin, "function" ); + visible = parseOptionalAttribute( aPin, "visible" ); + length = parseOptionalAttribute( aPin, "length" ); + direction = parseOptionalAttribute( aPin, "direction" ); + function = parseOptionalAttribute( aPin, "function" ); swaplevel = parseOptionalAttribute( aPin, "swaplevel" ); rot = parseOptionalAttribute( aPin, "rot" ); } @@ -742,7 +760,7 @@ EPOLYGON::EPOLYGON( wxXmlNode* aPolygon ) spacing = parseOptionalAttribute( aPolygon, "spacing" ); isolate = parseOptionalAttribute( aPolygon, "isolate" ); - opt_string s = parseOptionalAttribute( aPolygon, "pour" ); + opt_wxString s = parseOptionalAttribute( aPolygon, "pour" ); // default pour to solid fill pour = EPOLYGON::SOLID; @@ -795,11 +813,12 @@ EELEMENT::EELEMENT( wxXmlNode* aElement ) */ // #REQUIRED - name = parseRequiredAttribute( aElement, "name" ); - library = parseRequiredAttribute( aElement, "library" ); - value = parseRequiredAttribute( aElement, "value" ); - package = parseRequiredAttribute( aElement, "package" ); - ReplaceIllegalFileNameChars( &package ); + name = parseRequiredAttribute( aElement, "name" ); + library = parseRequiredAttribute( aElement, "library" ); + value = parseRequiredAttribute( aElement, "value" ); + std::string p = parseRequiredAttribute( aElement, "package" ); + ReplaceIllegalFileNameChars( &p ); + package = wxString::FromUTF8( p.c_str() ); x = parseRequiredAttribute( aElement, "x" ); y = parseRequiredAttribute( aElement, "y" ); @@ -826,7 +845,7 @@ ELAYER::ELAYER( wxXmlNode* aLayer ) */ number = parseRequiredAttribute( aLayer, "number" ); - name = parseRequiredAttribute( aLayer, "name" ); + name = parseRequiredAttribute( aLayer, "name" ); color = parseRequiredAttribute( aLayer, "color" ); fill = 1; // Temporary value. visible = parseOptionalAttribute( aLayer, "visible" ); @@ -848,12 +867,12 @@ EPART::EPART( wxXmlNode* aPart ) * > */ // #REQUIRED - name = parseRequiredAttribute( aPart, "name" ); - library = parseRequiredAttribute( aPart, "library" ); - deviceset = parseRequiredAttribute( aPart, "deviceset" ); - device = parseRequiredAttribute( aPart, "device" ); - technology = parseOptionalAttribute( aPart, "technology" ); - value = parseOptionalAttribute( aPart, "value" ); + name = parseRequiredAttribute( aPart, "name" ); + library = parseRequiredAttribute( aPart, "library" ); + deviceset = parseRequiredAttribute( aPart, "deviceset" ); + device = parseRequiredAttribute( aPart, "device" ); + technology = parseOptionalAttribute( aPart, "technology" ); + value = parseOptionalAttribute( aPart, "value" ); } @@ -870,8 +889,8 @@ EINSTANCE::EINSTANCE( wxXmlNode* aInstance ) * rot %Rotation; "R0" * > */ - part = parseRequiredAttribute( aInstance, "part" ); - gate = parseRequiredAttribute( aInstance, "gate" ); + part = parseRequiredAttribute( aInstance, "part" ); + gate = parseRequiredAttribute( aInstance, "gate" ); x = parseRequiredAttribute( aInstance, "x" ); y = parseRequiredAttribute( aInstance, "y" ); @@ -896,13 +915,13 @@ EGATE::EGATE( wxXmlNode* aGate ) * > */ - name = parseRequiredAttribute( aGate, "name" ); - symbol = parseRequiredAttribute( aGate, "symbol" ); + name = parseRequiredAttribute( aGate, "name" ); + symbol = parseRequiredAttribute( aGate, "symbol" ); x = parseRequiredAttribute( aGate, "x" ); y = parseRequiredAttribute( aGate, "y" ); - opt_string stemp = parseOptionalAttribute( aGate, "addlevel" ); + opt_wxString stemp = parseOptionalAttribute( aGate, "addlevel" ); // (off | value | name | both) if( stemp == "must" ) @@ -931,9 +950,9 @@ ECONNECT::ECONNECT( wxXmlNode* aConnect ) * route %ContactRoute; "all" * > */ - gate = parseRequiredAttribute( aConnect, "gate" ); - pin = parseRequiredAttribute( aConnect, "pin" ); - pad = parseRequiredAttribute( aConnect, "pad" ); + gate = parseRequiredAttribute( aConnect, "gate" ); + pin = parseRequiredAttribute( aConnect, "pin" ); + pad = parseRequiredAttribute( aConnect, "pad" ); } @@ -946,8 +965,8 @@ EDEVICE::EDEVICE( wxXmlNode* aDevice ) package %String; #IMPLIED > */ - name = parseRequiredAttribute( aDevice, "name" ); - package = parseOptionalAttribute( aDevice, "package" ); + name = parseRequiredAttribute( aDevice, "name" ); + package = parseOptionalAttribute( aDevice, "package" ); NODE_MAP aDeviceChildren = MapChildren(aDevice); wxXmlNode* connectNode = getChildrenNodes(aDeviceChildren, "connects"); @@ -971,9 +990,9 @@ EDEVICE_SET::EDEVICE_SET( wxXmlNode* aDeviceSet ) > */ - name = parseRequiredAttribute(aDeviceSet, "name"); - prefix = parseOptionalAttribute( aDeviceSet, "prefix" ); - uservalue = parseOptionalAttribute( aDeviceSet, "uservalue" ); + name = parseRequiredAttribute(aDeviceSet, "name"); + prefix = parseOptionalAttribute( aDeviceSet, "prefix" ); + uservalue = parseOptionalAttribute( aDeviceSet, "uservalue" ); /* Russell: Parsing of devices and gates moved to sch_eagle_plugin.cpp * diff --git a/common/lib_id.cpp b/common/lib_id.cpp index 66f1335827..95f5de015b 100644 --- a/common/lib_id.cpp +++ b/common/lib_id.cpp @@ -385,8 +385,9 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName ) { UTF8 fixedName; - for( auto ch : aLibItemName ) + for( UTF8::uni_iter chIt = aLibItemName.ubegin(); chIt < aLibItemName.uend(); ++chIt ) { + auto ch = *chIt; if( !wxIsascii( ch ) ) { diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 13e7fab0a7..16dc6ce56f 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -55,8 +54,6 @@ #include -using std::string; - // Eagle schematic axes are aligned with x increasing left to right and Y increasing bottom to top // Kicad schematic axes are aligned with x increasing left to right and Y increasing top to bottom. @@ -69,7 +66,7 @@ using namespace std; * @param aName the name of the specific child names to be counted. * @return number of children with the give node name. */ -static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName ) +static int countChildren( wxXmlNode* aCurrentNode, const wxString& aName ) { // Map node_name -> node_pointer int count = 0; @@ -79,7 +76,7 @@ static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName ) while( aCurrentNode ) { - if( aCurrentNode->GetName().ToStdString() == aName ) + if( aCurrentNode->GetName() == aName ) count++; // Get next child @@ -325,13 +322,13 @@ SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN() const wxString SCH_EAGLE_PLUGIN::GetName() const { - return wxT( "EAGLE" ); + return "EAGLE"; } const wxString SCH_EAGLE_PLUGIN::GetFileExtension() const { - return wxT( "sch" ); + return "sch"; } @@ -391,8 +388,8 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, { // Create a new empty symbol library. m_pi->CreateSymbolLib( getLibFileName().GetFullPath() ); - wxString libTableUri = "${KIPRJMOD}/" + getLibFileName().GetFullName(); + // Add the new library to the project symbol library table. libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri, wxString( "Legacy" ) ) ); @@ -471,7 +468,7 @@ void SCH_EAGLE_PLUGIN::countNets( wxXmlNode* aSchematicNode ) while( netNode ) { - std::string netName = netNode->GetAttribute( "name" ).ToStdString(); + wxString netName = netNode->GetAttribute( "name" ); if( m_netCounts.count( netName ) ) m_netCounts[netName] = m_netCounts[netName] + 1; @@ -497,8 +494,7 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode ) while( partNode ) { std::unique_ptr epart( new EPART( partNode ) ); - string name = epart->name; - m_partlist[name] = std::move( epart ); + m_partlist[epart->name] = std::move( epart ); partNode = partNode->GetNext(); } @@ -511,10 +507,10 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode ) // Read the library name wxString libName = libraryNode->GetAttribute( "name" ); - EAGLE_LIBRARY* elib = &m_eagleLibs[libName.ToStdString()]; - elib->name = libName.ToStdString(); + EAGLE_LIBRARY* elib = &m_eagleLibs[libName]; + elib->name = libName; - loadLibrary( libraryNode, &m_eagleLibs[libName.ToStdString()] ); + loadLibrary( libraryNode, &m_eagleLibs[libName] ); libraryNode = libraryNode->GetNext(); } @@ -594,7 +590,7 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex ) } else { - filename = m_filename.GetName().ToStdString() + "_" + std::to_string( aSheetIndex ); + filename = wxString::Format( "%s_%d", m_filename.GetName(), aSheetIndex ); m_currentSheet->SetName( filename ); } @@ -631,8 +627,8 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex ) while( netNode ) { // Get the net name and class - wxString netName = netNode->GetAttribute( "name" ); - wxString netClass = netNode->GetAttribute( "class" ); + wxString netName = netNode->GetAttribute( "name" ); + wxString netClass = netNode->GetAttribute( "class" ); // Load segments of this net loadSegments( netNode, netName, netClass ); @@ -894,7 +890,7 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode, // Determine if the Label is a local and global label based on the number of sheets the net appears on. - if( m_netCounts[aNetName.ToStdString()] > 1 ) + if( m_netCounts[aNetName] > 1 ) { std::unique_ptr glabel( new SCH_GLOBALLABEL ); glabel->SetPosition( elabelpos ); @@ -1054,16 +1050,14 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) EPART* epart = m_partlist[einstance.part].get(); - std::string libraryname = epart->library; - std::string gatename = epart->deviceset + epart->device + einstance.gate; - - wxString sntemp = wxString( epart->deviceset + epart->device ); - sntemp.Replace( "*", "" ); - std::string symbolname = sntemp.ToStdString(); + wxString libraryname = epart->library; + wxString gatename = epart->deviceset + epart->device + einstance.gate; + wxString symbolname = wxString( epart->deviceset + epart->device ); + symbolname.Replace( "*", "" ); int unit = m_eagleLibs[libraryname].GateUnit[gatename]; - std::string package; + wxString package; EAGLE_LIBRARY* elib = &m_eagleLibs[libraryname]; auto p = elib->package.find( symbolname ); @@ -1073,10 +1067,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) package = p->second; } - std::string kisymbolname = LIB_ID::FixIllegalChars( symbolname ); - // std::replace( kisymbolname.begin(), kisymbolname.end(), ':', '_' ); - // std::replace( kisymbolname.begin(), kisymbolname.end(), '/', '_' ); - // std::replace( kisymbolname.begin(), kisymbolname.end(), '"', '_' ); + wxString kisymbolname = LIB_ID::FixIllegalChars( symbolname ); LIB_ALIAS* alias = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname, m_properties.get() ); @@ -1090,7 +1081,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) component->SetLibId( libId ); component->SetUnit( unit ); component->SetPosition( wxPoint( einstance.x.ToSchUnits(), -einstance.y.ToSchUnits() ) ); - component->GetField( FOOTPRINT )->SetText( wxString( package ) ); + component->GetField( FOOTPRINT )->SetText( package ); component->SetTimeStamp( EagleModuleTstamp( einstance.part, epart->value ? *epart->value : "", unit ) ); @@ -1128,7 +1119,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) component->AddHierarchicalReference( current_sheetpath, wxString( einstance.part ), unit ); if( epart->value ) - component->GetField( VALUE )->SetText( wxString::FromUTF8( epart->value->c_str() ) ); + component->GetField( VALUE )->SetText( *epart->value ); else component->GetField( VALUE )->SetText( symbolname ); @@ -1214,7 +1205,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, while( symbolNode ) { - string symbolName = symbolNode->GetAttribute( "name" ).ToStdString(); + wxString symbolName = symbolNode->GetAttribute( "name" ); aEagleLibrary->SymbolNodes[symbolName] = symbolNode; symbolNode = symbolNode->GetNext(); } @@ -1239,11 +1230,12 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, EDEVICE edevice = EDEVICE( deviceNode ); // Create symbol name from deviceset and device names. - wxString symbolName = wxString( edeviceset.name + edevice.name ); + wxString symbolName = edeviceset.name + edevice.name; symbolName.Replace( "*", "" ); + wxASSERT( !symbolName.IsEmpty() ); if( edevice.package ) - aEagleLibrary->package[symbolName.ToStdString()] = edevice.package.Get(); + aEagleLibrary->package[symbolName] = edevice.package.Get(); // Create KiCad symbol. unique_ptr kpart( new LIB_PART( symbolName ) ); @@ -1281,10 +1273,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, if( gates_count == 1 && ispower ) kpart->SetPower(); - string name = LIB_ID::FixIllegalChars( kpart->GetName().ToStdString() ); - // std::replace( name.begin(), name.end(), ':', '_' ); - // std::replace( name.begin(), name.end(), '/', '_' ); - // std::replace( name.begin(), name.end(), '"', '_' ); + wxString name = LIB_ID::FixIllegalChars( kpart->GetName() ); kpart->SetName( name ); m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ), m_properties.get() ); @@ -1300,11 +1289,8 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, } -bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, - std::unique_ptr& aPart, - EDEVICE* aDevice, - int aGateNumber, - string aGateName ) +bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr& aPart, + EDEVICE* aDevice, int aGateNumber, const wxString& aGateName ) { wxString symbolName = aSymbolNode->GetAttribute( "name" ); std::vector items; @@ -1376,7 +1362,7 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, { for( auto connect : aDevice->connects ) { - if( connect.gate == aGateName and pin->GetName().ToStdString() == connect.pin ) + if( connect.gate == aGateName && pin->GetName() == connect.pin ) { wxArrayString pads = wxSplit( wxString( connect.pad ), ' '); @@ -1405,8 +1391,7 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, { pin->SetPartNumber( aGateNumber ); pin->SetUnit( aGateNumber ); - wxString stringPinNum = wxString::Format( wxT( "%i" ), pincount ); - pin->SetNumber( stringPinNum ); + pin->SetNumber( wxString::Format( "%i", pincount ) ); aPart->AddDrawItem( pin.release() ); } } diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index 8c09d5984c..221bc55b16 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -62,14 +62,14 @@ class LIB_TEXT; typedef struct EAGLE_LIBRARY { - std::string name; - boost::ptr_map KiCadSymbols; - std::unordered_map SymbolNodes; - std::unordered_map GateUnit; - std::unordered_map package; + wxString name; + boost::ptr_map KiCadSymbols; + std::unordered_map SymbolNodes; + std::unordered_map GateUnit; + std::unordered_map package; } EAGLE_LIBRARY; -typedef boost::ptr_map EPART_LIST; +typedef boost::ptr_map EPART_LIST; /** @@ -161,7 +161,7 @@ private: SCH_JUNCTION* loadJunction( wxXmlNode* aJunction ); SCH_TEXT* loadPlainText( wxXmlNode* aSchText ); - bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr& aPart, EDEVICE* aDevice, int aGateNumber, string aGateName ); + bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr& aPart, EDEVICE* aDevice, int aGateNumber, const wxString& aGateName ); LIB_CIRCLE* loadSymbolCircle( std::unique_ptr& aPart, wxXmlNode* aCircleNode, int aGateNumber ); LIB_RECTANGLE* loadSymbolRectangle( std::unique_ptr& aPart, wxXmlNode* aRectNode, int aGateNumber ); LIB_POLYLINE* loadSymbolPolyLine( std::unique_ptr& aPart, wxXmlNode* aPolygonNode, int aGateNumber ); @@ -183,12 +183,12 @@ private: wxString m_libName; ///< Library name to save symbols EPART_MAP m_partlist; - std::map m_eagleLibs; + std::map m_eagleLibs; SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library. std::unique_ptr< PROPERTIES > m_properties; ///< Library plugin properties. - std::map m_netCounts; + std::map m_netCounts; std::map m_layerMap; }; diff --git a/include/eagle_parser.h b/include/eagle_parser.h index 5cfa30e018..2986422e75 100644 --- a/include/eagle_parser.h +++ b/include/eagle_parser.h @@ -40,20 +40,19 @@ #include #include #include - -using std::string; +#include class MODULE; struct EINSTANCE; struct EPART; struct ETEXT; -typedef std::unordered_map NODE_MAP; -typedef std::map MODULE_MAP; -typedef std::map EINSTANCE_MAP; -typedef std::map> EPART_MAP; +typedef std::unordered_map NODE_MAP; +typedef std::map MODULE_MAP; +typedef std::map EINSTANCE_MAP; +typedef std::map> EPART_MAP; -static inline wxXmlNode* getChildrenNodes( NODE_MAP& aMap, const string& aName ) +static inline wxXmlNode* getChildrenNodes( NODE_MAP& aMap, const wxString& aName ) { auto it = aMap.find( aName ); return it == aMap.end() ? nullptr : it->second->GetChildren(); @@ -73,7 +72,7 @@ struct XML_PARSER_ERROR : std::runtime_error * the passed message. * @param aMessage is an explanatory error message. */ - XML_PARSER_ERROR( const string& aMessage ) noexcept : + XML_PARSER_ERROR( const wxString& aMessage ) noexcept : std::runtime_error( "XML parser failed - " + aMessage ) {} }; @@ -134,11 +133,11 @@ public: } /// return the contents of the XPATH as a single string - string Contents() + wxString Contents() { typedef std::vector::const_iterator CITER_TRIPLET; - string ret; + wxString ret; for( CITER_TRIPLET it = p.begin(); it != p.end(); ++it ) { @@ -182,7 +181,7 @@ T Convert( const wxString& aValue ) * This was implemented as an alternative to OPT. This class should be replaced with a * simple typedef per type using std::optional when C++17 is published. */ -template +template class OPTIONAL_XML_ATTRIBUTE { private: @@ -220,6 +219,7 @@ public: * @param aData is the value of the XML attribute. If this constructor is called, the * attribute is available. */ + template OPTIONAL_XML_ATTRIBUTE( T aData ) : m_isAvailable( true ), m_data( aData ) @@ -361,7 +361,7 @@ NODE_MAP MapChildren( wxXmlNode* aCurrentNode ); unsigned long EagleTimeStamp( wxXmlNode* aTree ); /// Computes module timestamp basing on its name, value and unit -time_t EagleModuleTstamp( const string& aName, const string& aValue, int aUnit ); +time_t EagleModuleTstamp( const wxString& aName, const wxString& aValue, int aUnit ); /// Convert an Eagle curve end to a KiCad center for S_ARC wxPoint ConvertArcCenter( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ); @@ -369,7 +369,7 @@ wxPoint ConvertArcCenter( const wxPoint& aStart, const wxPoint& aEnd, double aAn // Pre-declare for typedefs struct EROT; struct ECOORD; -typedef OPTIONAL_XML_ATTRIBUTE opt_string; +typedef OPTIONAL_XML_ATTRIBUTE opt_wxString; typedef OPTIONAL_XML_ATTRIBUTE opt_int; typedef OPTIONAL_XML_ATTRIBUTE opt_double; typedef OPTIONAL_XML_ATTRIBUTE opt_bool; @@ -452,9 +452,9 @@ struct ECOORD struct ENET { int netcode; - string netname; + wxString netname; - ENET( int aNetCode, const string& aNetName ) : + ENET( int aNetCode, const wxString& aNetName ) : netcode( aNetCode ), netname( aNetName ) {} @@ -535,7 +535,7 @@ struct ELABEL ECOORD size; LAYER_NUM layer; opt_erot rot; - opt_string xref; + opt_wxString xref; wxString netname; ELABEL( wxXmlNode* aLabel, const wxString& aNetName ); @@ -551,7 +551,7 @@ struct EVIA int layer_back_most; /// < inclusive ECOORD drill; opt_ecoord diam; - opt_string shape; + opt_wxString shape; EVIA( wxXmlNode* aVia ); }; @@ -592,8 +592,8 @@ struct ERECT */ struct EATTR { - string name; - opt_string value; + wxString name; + opt_wxString value; opt_ecoord x; opt_ecoord y; opt_ecoord size; @@ -626,7 +626,7 @@ struct EDIMENSION ECOORD y3; int layer; - opt_string dimensionType; + opt_wxString dimensionType; EDIMENSION( wxXmlNode* aDimension ); }; @@ -635,12 +635,12 @@ struct EDIMENSION /// Eagle text element struct ETEXT { - string text; + wxString text; ECOORD x; ECOORD y; ECOORD size; int layer; - opt_string font; + opt_wxString font; opt_double ratio; opt_erot rot; @@ -670,7 +670,7 @@ struct ETEXT /// Eagle thru hol pad struct EPAD { - string name; + wxString name; ECOORD x; ECOORD y; ECOORD drill; @@ -697,7 +697,7 @@ struct EPAD /// Eagle SMD pad struct ESMD { - string name; + wxString name; ECOORD x; ECOORD y; ECOORD dx; @@ -716,14 +716,14 @@ struct ESMD /// Eagle pin element struct EPIN { - string name; + wxString name; ECOORD x; ECOORD y; - opt_string visible; - opt_string length; - opt_string direction; - opt_string function; + opt_wxString visible; + opt_wxString length; + opt_wxString direction; + opt_wxString function; opt_int swaplevel; opt_erot rot; @@ -784,10 +784,10 @@ struct EHOLE /// Eagle element element struct EELEMENT { - string name; - string library; - string package; - string value; + wxString name; + wxString library; + wxString package; + wxString value; ECOORD x; ECOORD y; opt_bool locked; @@ -801,7 +801,7 @@ struct EELEMENT struct ELAYER { int number; - string name; + wxString name; int color; int fill; opt_bool visible; @@ -895,12 +895,12 @@ struct EPART * > */ - string name; - string library; - string deviceset; - string device; - opt_string technology; - opt_string value; + wxString name; + wxString library; + wxString deviceset; + wxString device; + opt_wxString technology; + opt_wxString value; EPART( wxXmlNode* aPart ); }; @@ -920,8 +920,8 @@ struct EINSTANCE * > */ - string part; - string gate; + wxString part; + wxString gate; ECOORD x; ECOORD y; opt_bool smashed; @@ -945,8 +945,8 @@ struct EGATE * > */ - string name; - string symbol; + wxString name; + wxString symbol; ECOORD x; ECOORD y; @@ -978,9 +978,9 @@ struct ECONNECT * route %ContactRoute; "all" * > */ - string gate; - string pin; - string pad; + wxString gate; + wxString pin; + wxString pad; //int contactroute; // TODO ECONNECT( wxXmlNode* aConnect ); @@ -996,8 +996,8 @@ struct EDEVICE package %String; #IMPLIED > */ - string name; - opt_string package; + wxString name; + opt_wxString package; std::vector connects; @@ -1016,8 +1016,8 @@ struct EDEVICE_SET > */ - string name; - opt_string prefix; + wxString name; + opt_wxString prefix; opt_bool uservalue; //std::vector devices; //std::vector gates; diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index fca9dc5c38..af99fb0071 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -96,9 +96,9 @@ static int parseEagle( const wxString& aDistance ) /// Assemble a two part key as a simple concatenation of aFirst and aSecond parts, /// using a separator. -static string makeKey( const string& aFirst, const string& aSecond ) +static wxString makeKey( const wxString& aFirst, const wxString& aSecond ) { - string key = aFirst + '\x02' + aSecond; + wxString key = aFirst + '\x02' + aSecond; return key; } @@ -237,7 +237,7 @@ BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const // Catch all exceptions thrown from the parser. catch( const XML_PARSER_ERROR &exc ) { - string errmsg = exc.what(); + wxString errmsg = exc.what(); errmsg += "\n@ "; errmsg += m_xpath->Contents(); @@ -746,7 +746,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics ) } -void EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLib, const string* aLibName ) +void EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLib, const wxString* aLibName ) { m_xpath->push( "packages" ); @@ -766,14 +766,12 @@ void EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLib, const string* aLibName ) m_xpath->push( "package", "name" ); const wxString& pack_ref = package->GetAttribute( "name" ); - - string pack_name( pack_ref.ToStdString() ); - + std::string pack_name( pack_ref ); ReplaceIllegalFileNameChars( &pack_name ); m_xpath->Value( pack_name.c_str() ); - string key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name; + wxString key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name; MODULE* m = makeModule( package, pack_name ); @@ -813,12 +811,10 @@ void EAGLE_PLUGIN::loadLibraries( wxXmlNode* aLibs ) while( library ) { - const string& lib_name = library->GetAttribute( "name" ).ToStdString(); + const wxString& lib_name = library->GetAttribute( "name" ); m_xpath->Value( lib_name.c_str() ); - loadLibrary( library, &lib_name ); - library = library->GetNext(); } @@ -856,7 +852,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) m_xpath->Value( e.name.c_str() ); - string pkg_key = makeKey( e.library, e.package ); + wxString pkg_key = makeKey( e.library, e.package ); MODULE_CITER mi = m_templates.find( pkg_key ); @@ -875,7 +871,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) // update the nets within the pads of the clone for( D_PAD* pad = m->PadsList(); pad; pad = pad->Next() ) { - string pn_key = makeKey( e.name, TO_UTF8( pad->GetName() ) ); + wxString pn_key = makeKey( e.name, pad->GetName() ); NET_MAP_CITER ni = m_pads_to_nets.find( pn_key ); if( ni != m_pads_to_nets.end() ) @@ -1001,7 +997,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) switch( *a.display ) { case EATTR::VALUE : - valueAttr->value = e.value; + valueAttr->value = opt_wxString( e.value ); m->SetValue( e.value ); if( valueNamePresetInPackageLayout ) m->Value().SetVisible( true ); @@ -1016,7 +1012,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) case EATTR::BOTH : if( valueNamePresetInPackageLayout ) m->Value().SetVisible( true ); - valueAttr->value = "VALUE = " + e.value; + valueAttr->value = opt_wxString( "VALUE = " + e.value ); m->SetValue( "VALUE = " + e.value ); break; @@ -1025,7 +1021,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) break; default: - valueAttr->value = e.value; + valueAttr->value = opt_wxString( e.value ); if( valueNamePresetInPackageLayout ) m->Value().SetVisible( true ); } @@ -1182,7 +1178,7 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e, } -MODULE* EAGLE_PLUGIN::makeModule( wxXmlNode* aPackage, const string& aPkgName ) const +MODULE* EAGLE_PLUGIN::makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const { std::unique_ptr m( new MODULE( m_board ) ); @@ -1722,11 +1718,10 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals ) zones.clear(); - const string& nname = net->GetAttribute( "name" ).ToStdString(); - wxString netName = FROM_UTF8( nname.c_str() ); + const wxString& netName = net->GetAttribute( "name" ); m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) ); - m_xpath->Value( nname.c_str() ); + m_xpath->Value( netName ); // Get the first net item and iterate wxXmlNode* netItem = net->GetChildren(); @@ -1735,6 +1730,7 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals ) while( netItem ) { const wxString& itemName = netItem->GetName(); + if( itemName == "wire" ) { m_xpath->push( "wire" ); @@ -1842,14 +1838,13 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals ) m_xpath->push( "contactref" ); // - const string& reference = netItem->GetAttribute( "element" ).ToStdString(); - const string& pad = netItem->GetAttribute( "pad" ).ToStdString(); + const wxString& reference = netItem->GetAttribute( "element" ); + const wxString& pad = netItem->GetAttribute( "pad" ); + wxString key = makeKey( reference, pad ) ; - string key = makeKey( reference, pad ) ; + // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, netName.c_str() );) - // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );) - - m_pads_to_nets[ key ] = ENET( netCode, nname ); + m_pads_to_nets[ key ] = ENET( netCode, netName ); m_xpath->pop(); @@ -2030,9 +2025,9 @@ PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const } -const string& EAGLE_PLUGIN::eagle_layer_name( int aLayer ) const +const wxString& EAGLE_PLUGIN::eagle_layer_name( int aLayer ) const { - static const string unknown( "unknown" ); + static const wxString unknown( "unknown" ); auto it = m_eagleLayers.find( aLayer ); return it == m_eagleLayers.end() ? unknown : it->second.name; } @@ -2193,12 +2188,8 @@ MODULE* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxStrin const PROPERTIES* aProperties ) { init( aProperties ); - cacheLib( aLibraryPath ); - - string key = TO_UTF8( aFootprintName ); - - MODULE_CITER mi = m_templates.find( key ); + MODULE_CITER mi = m_templates.find( aFootprintName ); if( mi == m_templates.end() ) return NULL; diff --git a/pcbnew/eagle_plugin.h b/pcbnew/eagle_plugin.h index 6d41f70bb5..8ee00d5768 100644 --- a/pcbnew/eagle_plugin.h +++ b/pcbnew/eagle_plugin.h @@ -33,9 +33,9 @@ #include -typedef std::map< std::string, MODULE* > MODULE_MAP; -typedef std::map< std::string, ENET > NET_MAP; -typedef NET_MAP::const_iterator NET_MAP_CITER; +typedef std::map MODULE_MAP; +typedef std::map NET_MAP; +typedef NET_MAP::const_iterator NET_MAP_CITER; /// subset of eagle.drawing.board.designrules in the XML document @@ -170,7 +170,7 @@ private: PCB_LAYER_ID kicad_layer( int aLayer ) const; /// Get Eagle layer name by its number - const std::string& eagle_layer_name( int aLayer ) const; + const wxString& eagle_layer_name( int aLayer ) const; /// This PLUGIN only caches one footprint library, this determines which one. void cacheLib( const wxString& aLibraryPath ); @@ -197,7 +197,7 @@ private: * we are loading a *.lbr not a *.brd file and the key used in m_templates is to exclude * the library name. */ - void loadLibrary( wxXmlNode* aLib, const std::string* aLibName ); + void loadLibrary( wxXmlNode* aLib, const wxString* aLibName ); void loadLibraries( wxXmlNode* aLibs ); void loadElements( wxXmlNode* aElements ); @@ -215,13 +215,13 @@ private: * is the opposite or complement of degParse(). One has to know what the * other is doing. */ - std::string fmtDEG( double aAngle ) const; + wxString fmtDEG( double aAngle ) const; /** * Function makeModule * creates a MODULE from an Eagle package. */ - MODULE* makeModule( wxXmlNode* aPackage, const std::string& aPkgName ) const; + MODULE* makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const; void packageWire( MODULE* aModule, wxXmlNode* aTree ) const; void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;