Eeschema Eagle Plugin: Code Cleanup

This commit is contained in:
Russell Oliver 2017-07-06 22:31:11 +10:00 committed by Maciej Suminski
parent 3741793f77
commit b8f98eaffe
1 changed files with 183 additions and 179 deletions

View File

@ -48,7 +48,6 @@
#include <sch_eagle_plugin.h>
using std::string;
// Eagle schematic internal units are millimeters
@ -67,6 +66,7 @@ static NODE_MAP mapChildren( wxXmlNode* aCurrentNode )
// Loop through all children mapping them in nodesMap
aCurrentNode = aCurrentNode->GetChildren();
while( aCurrentNode )
{
// Create a new pair in the map
@ -124,15 +124,32 @@ static void kicadLayer( int aEagleLayer )
switch( aEagleLayer )
{
case 90: break;
case 91: break;
case 92: break;
case 93: break;
case 94: break;
case 95: break;
case 96: break;
case 97: break;
case 98: break;
case 90:
break;
case 91:
break;
case 92:
break;
case 93:
break;
case 94:
break;
case 95:
break;
case 96:
break;
case 97:
break;
case 98:
break;
}
}
@ -207,11 +224,13 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
// Load the document
wxXmlDocument xmlDocument;
m_filename = aFileName;
m_kiway = aKiway;
if( !xmlDocument.Load( m_filename.GetFullPath() ) )
THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ), m_filename.GetFullPath() ) );
THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
m_filename.GetFullPath() ) );
// Delete on exception, if I own m_rootSheet, according to aAppendToMe
unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
@ -318,6 +337,7 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
// wxXmlNode* modules = schematicChildren["modules"];
wxXmlNode* partNode = schematicChildren["parts"]->GetChildren();
while( partNode )
{
std::unique_ptr<EPART> epart( new EPART( partNode ) );
@ -338,7 +358,6 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
while( libraryNode )
{
auto elib = loadLibrary( libraryNode );
m_eaglelibraries[elib->name] = elib;
libraryNode = libraryNode->GetNext();
@ -491,7 +510,6 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
plainNode = plainNode->GetNext();
}
}
@ -501,6 +519,7 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n
// Loop through all segments
wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
SCH_SCREEN* screen = m_currentSheet->GetScreen();
// wxCHECK( screen, [>void<] );
while( currentSegment )
{
@ -633,30 +652,21 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
// Find the part in the list for the sheet.
// Assign the component its value from the part entry
// Calculate the unit number from the gate entry of the instance
// Find the relevent LIB_PART using the
// Find the device from the part entry, and its LIB_PART.
// Assign the the LIB_ID from deviceset and device names
EPART* epart = m_partlist[einstance.part];
//std::cout << "Part> name: " << epart->name << " library: " << epart->library << " deviceset: " << epart->deviceset << epart->device << '\n';
std::string gatename = epart->deviceset + epart->device + einstance.gate;
std::string symbolname = epart->deviceset + epart->device;
//std::cout << gatename << '\n';
//std::cout << "Gate to unit number " << m_eaglelibraries[epart->library]->gate_unit[gatename] << '\n';
int unit = m_eaglelibraries[epart->library]->gate_unit[gatename];
std::string package = m_eaglelibraries[epart->library]->package[symbolname];
//LIB_PART* part = m_eaglelibraries[epart->library]->kicadsymbols[symbolname];
// std::cout << "Instance> part: " << einstance.part << " Gate: " << einstance.gate << " " << symbolname << '\n';
std::cout << "Instance> part: " << einstance.part << " Gate: " << einstance.gate << " " << symbolname << '\n';
//SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, int convert, const wxPoint& pos, bool setNewItemFlag )
std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT() );
LIB_ID libId( wxEmptyString, symbolname );
component->SetLibId( libId );
component->SetUnit( unit );
component->SetConvert( 0 );
@ -669,10 +679,10 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
if( einstance.rot )
{
component->SetOrientation( kicadComponentRotation( einstance.rot->degrees ) );
if( einstance.rot->mirror )
{
component->MirrorY( einstance.x * EUNIT_TO_MIL );
std::cout << "Mirror" << '\n';
}
}
@ -686,14 +696,11 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
void SCH_EAGLE_PLUGIN::loadModuleinst( wxXmlNode* aModuleinstNode )
{
}
EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
{
unique_ptr<EAGLE_LIBRARY> elib( new EAGLE_LIBRARY );
std::map<std::string, wxXmlNode*> gate;
@ -731,24 +738,26 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
// Loop through the devicesets and load each of them
wxXmlNode* devicesetNode = libraryChildren["devicesets"]->GetChildren();
while( devicesetNode )
{
// Get Device set information
EDEVICESET edeviceset = EDEVICESET( devicesetNode );
////std::cout << "Importing Eagle device set "<< edeviceset.name << std::endl;
// std::cout << "Importing Eagle device set "<< edeviceset.name << std::endl;
NODE_MAP aDeviceSetChildren = MapChildren( devicesetNode );
wxXmlNode* deviceNode = getChildrenNodes( aDeviceSetChildren, "devices" );
// For each device in the device set:
while(deviceNode){
while( deviceNode )
{
// Get device information
EDEVICE edevice = EDEVICE( deviceNode );
// Create symbol name from deviceset and device names.
wxString symbolName = wxString( edeviceset.name + edevice.name );
////std::cout << "Creating Kicad Symbol: " << symbolName.ToStdString() << '\n';
// std::cout << "Creating Kicad Symbol: " << symbolName.ToStdString() << '\n';
elib.get()->package[symbolName.ToStdString()] = edevice.package.Get();
// Create kicad symbol.
@ -757,23 +766,26 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
// Process each gate in the deviceset for this device.
wxXmlNode* gateNode = getChildrenNodes( aDeviceSetChildren, "gates" );
int gates_count = countChildren( aDeviceSetChildren["gates"], "gate" );
//std::cout << "Gate count " << gates_count << '\n';
kpart->SetUnitCount( gates_count );
int gateindex;
if(gates_count>1){
if( gates_count>1 )
{
gateindex = 1;
}
else
{
gateindex = 0;
}
while(gateNode){
//std::cout << gateindex << '\n';
while( gateNode )
{
EGATE egate = EGATE( gateNode );
elib.get()->gate_unit[edeviceset.name + edevice.name + egate.name] = gates_count;
loadSymbol(elib->symbolnodes[egate.symbol], (LIB_PART*)kpart.get(), &edevice, gateindex, egate.name);
loadSymbol( elib->symbolnodes[egate.symbol],
(LIB_PART*) kpart.get(), &edevice, gateindex, egate.name );
gateindex++;
gateNode = gateNode->GetNext();
@ -791,16 +803,16 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
devicesetNode = devicesetNode->GetNext();
} // devicesetNode
return elib.release();
}
void SCH_EAGLE_PLUGIN::loadSymbol(wxXmlNode *aSymbolNode, LIB_PART* aPart, EDEVICE* aDevice, int gateNumber, string gateName)
void SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode,
LIB_PART* aPart,
EDEVICE* aDevice,
int gateNumber,
string gateName )
{
////std::cout << "loadsymbol" << '\n';
// Create a new part with the symbol name
wxString symbolName = aSymbolNode->GetAttribute( "name" );
std::vector<LIB_ITEM*> items;
@ -808,9 +820,8 @@ void SCH_EAGLE_PLUGIN::loadSymbol(wxXmlNode *aSymbolNode, LIB_PART* aPart, EDEV
while( currentNode )
{
wxString nodeName = currentNode->GetName();
////std::cout << "symbolnode " << nodeName.ToStdString() <<'\n';
if( nodeName == "description" )
{
// TODO
@ -836,20 +847,17 @@ void SCH_EAGLE_PLUGIN::loadSymbol(wxXmlNode *aSymbolNode, LIB_PART* aPart, EDEV
for( auto connect : aDevice->connects )
{
if(connect.gate == gateName and pin->GetName().ToStdString() == connect.pin){
if( connect.gate == gateName and pin->GetName().ToStdString() == connect.pin )
{
wxString padname( connect.pad );
pin->SetPinNumFromString( padname );
pin->SetPartNumber( gateNumber );
pin->SetUnit( gateNumber );
//std::cout << pin->GetName().ToStdString() << " " << pin->GetNumberString().ToStdString() << std::endl;
aPart->AddDrawItem( pin );
break;
}
}
}
else if( nodeName == "polygon" )
{
@ -874,7 +882,6 @@ void SCH_EAGLE_PLUGIN::loadSymbol(wxXmlNode *aSymbolNode, LIB_PART* aPart, EDEV
aPart->GetReferenceField().SetTextSize( libtext->GetTextSize() );
aPart->GetReferenceField().SetTextAngle( libtext->GetTextAngle() );
aPart->GetReferenceField().SetBold( libtext->IsBold() );
}
else if( libtext->GetText() == ">VALUE" )
{
@ -897,8 +904,6 @@ void SCH_EAGLE_PLUGIN::loadSymbol(wxXmlNode *aSymbolNode, LIB_PART* aPart, EDEV
currentNode = currentNode->GetNext();
}
}
@ -993,6 +998,7 @@ LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( LIB_PART* aPart, wxXmlNode* aPin )
{
default:
wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
// fall through
case 0:
pin->SetOrientation( 'R' );
@ -1063,7 +1069,6 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibText
}
SCH_TEXT* SCH_EAGLE_PLUGIN::loadplaintext( wxXmlNode* aSchText )
{
std::unique_ptr<SCH_TEXT> schtext( new SCH_TEXT() );
@ -1077,8 +1082,6 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadplaintext( wxXmlNode* aSchText )
if( etext.ratio )
{
std::cout << etext.ratio.Get() << '\n';
if( etext.ratio.Get()>12 )
{
schtext->SetBold( true );
@ -1224,6 +1227,7 @@ void SCH_EAGLE_PLUGIN::SymbolLibOptions( PROPERTIES* aListToAppendTo ) const
{
}
// approved
// attribute
// circle