Eagle plugin: Code formatting

This commit is contained in:
Maciej Suminski 2017-06-19 15:43:55 +02:00
parent f049b01a59
commit e03bc32e49
3 changed files with 94 additions and 81 deletions

View File

@ -181,7 +181,8 @@ EWIRE::EWIRE( wxXmlNode* aWire )
cap = EWIRE::FLAT; cap = EWIRE::FLAT;
} }
EJUNCTION::EJUNCTION( wxXmlNode* aJunction)
EJUNCTION::EJUNCTION( wxXmlNode* aJunction )
{ {
/* /*
<!ELEMENT junction EMPTY> <!ELEMENT junction EMPTY>
@ -195,6 +196,7 @@ EJUNCTION::EJUNCTION( wxXmlNode* aJunction)
y = parseRequiredAttribute<double>( aJunction, "y" ); y = parseRequiredAttribute<double>( aJunction, "y" );
} }
ELABEL::ELABEL( wxXmlNode* aLabel, const wxString& aNetName ) ELABEL::ELABEL( wxXmlNode* aLabel, const wxString& aNetName )
{ {
/* /*
@ -211,15 +213,13 @@ ELABEL::ELABEL( wxXmlNode* aLabel, const wxString& aNetName )
> >
*/ */
x = parseRequiredAttribute<double>( aLabel, "x" ); x = parseRequiredAttribute<double>( aLabel, "x" );
y = parseRequiredAttribute<double>( aLabel, "y" ); y = parseRequiredAttribute<double>( aLabel, "y" );
size = parseRequiredAttribute<double>( aLabel, "size" ); size = parseRequiredAttribute<double>( aLabel, "size" );
layer = parseRequiredAttribute<int>( aLabel, "layer" ); layer = parseRequiredAttribute<int>( aLabel, "layer" );
rot = parseOptionalAttribute<EROT>( aLabel, "rot" ); rot = parseOptionalAttribute<EROT>( aLabel, "rot" );
xref = parseOptionalAttribute<string>(aLabel, "xref"); xref = parseOptionalAttribute<string>( aLabel, "xref" );
netname = aNetName; netname = aNetName;
} }
@ -507,7 +507,9 @@ ESMD::ESMD( wxXmlNode* aSMD )
cream = parseOptionalAttribute<bool>( aSMD, "cream" ); cream = parseOptionalAttribute<bool>( aSMD, "cream" );
} }
EPIN::EPIN( wxXmlNode* aPin ){
EPIN::EPIN( wxXmlNode* aPin )
{
/* /*
<!ELEMENT pin EMPTY> <!ELEMENT pin EMPTY>
<!ATTLIST pin <!ATTLIST pin
@ -532,12 +534,11 @@ EPIN::EPIN( wxXmlNode* aPin ){
length = parseOptionalAttribute<string>( aPin, "length" ); length = parseOptionalAttribute<string>( aPin, "length" );
direction = parseOptionalAttribute<string>( aPin, "direction" ); direction = parseOptionalAttribute<string>( aPin, "direction" );
function = parseOptionalAttribute<string>( aPin, "function" ); function = parseOptionalAttribute<string>( aPin, "function" );
swaplevel = parseOptionalAttribute<int>(aPin, "swaplevel"); swaplevel = parseOptionalAttribute<int>( aPin, "swaplevel" );
rot = parseOptionalAttribute<EROT>(aPin, "rot"); rot = parseOptionalAttribute<EROT>( aPin, "rot" );
} }
EVERTEX::EVERTEX( wxXmlNode* aVertex ) EVERTEX::EVERTEX( wxXmlNode* aVertex )
{ {
/* /*

View File

@ -46,7 +46,7 @@
constexpr double EUNIT_TO_MIL = 1000.0 / 25.4; constexpr double EUNIT_TO_MIL = 1000.0 / 25.4;
// Eagle schematic axes are aligned with x increasing left to right and Y increasing bottom to top // Eagle schematic axes are aligned with x increasing left to right and Y increasing bottom to top
// Kicad schematic axes are algigned with x increasing left to rigth and Y increasing top to bottom. // Kicad schematic axes are aligned with x increasing left to rigth and Y increasing top to bottom.
using namespace std; using namespace std;
@ -71,6 +71,7 @@ static NODE_MAP mapChildren( wxXmlNode* aCurrentNode )
return nodesMap; return nodesMap;
} }
static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName ) static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName )
{ {
// Map node_name -> node_pointer // Map node_name -> node_pointer
@ -78,9 +79,12 @@ static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName )
// Loop through all children counting them if they match the given name // Loop through all children counting them if they match the given name
aCurrentNode = aCurrentNode->GetChildren(); aCurrentNode = aCurrentNode->GetChildren();
while( aCurrentNode ) while( aCurrentNode )
{ {
if(aCurrentNode->GetName().ToStdString() == name) count++; if( aCurrentNode->GetName().ToStdString() == aName )
count++;
// Get next child // Get next child
aCurrentNode = aCurrentNode->GetNext(); aCurrentNode = aCurrentNode->GetNext();
} }
@ -89,7 +93,7 @@ static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName )
} }
void kicadLayer( int aEagleLayer ) static void kicadLayer( int aEagleLayer )
{ {
/** /**
* Layers in Kicad schematics are not actually layers, but abstract groups mainly used to * Layers in Kicad schematics are not actually layers, but abstract groups mainly used to
@ -194,14 +198,16 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
// Create a schematic symbol library // Create a schematic symbol library
wxFileName libfn = fn; wxFileName libfn = fn;
libfn.SetName(libfn.GetName()+wxString("-cache")); libfn.SetName( libfn.GetName() + wxString( "-cache" ) );
libfn.SetExt( SchematicLibraryFileExtension ); libfn.SetExt( SchematicLibraryFileExtension );
std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, libfn.GetFullPath() ) ); std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, libfn.GetFullPath() ) );
lib->EnableBuffering(); lib->EnableBuffering();
if( !wxFileName::FileExists( lib->GetFullFileName() ) ) if( !wxFileName::FileExists( lib->GetFullFileName() ) )
{ {
lib->Create(); lib->Create();
} }
m_partlib = lib.release(); m_partlib = lib.release();
// Retrieve the root as current node // Retrieve the root as current node
@ -220,7 +226,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
// Load drawing // Load drawing
loadDrawing( children["drawing"] ); loadDrawing( children["drawing"] );
m_partlib->Save(false); m_partlib->Save( false );
deleter.release(); deleter.release();
return m_rootSheet; return m_rootSheet;
} }
@ -294,16 +300,18 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
// If eagle schematic has multiple sheets. // If eagle schematic has multiple sheets.
if(sheet_count > 1){ if( sheet_count > 1 )
{
// TODO: set up a heirachical sheet for each Eagle sheet. // TODO: set up a heirachical sheet for each Eagle sheet.
int x, y; int x, y;
x = 1; x = 1;
y = 1; y = 1;
while( sheetNode ){ while( sheetNode )
wxPoint pos = wxPoint(x*1000, y*1000); {
std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET(pos) ); wxPoint pos = wxPoint( x*1000, y*1000);
SCH_SCREEN* screen = new SCH_SCREEN(m_kiway) ; std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( pos ) );
SCH_SCREEN* screen = new SCH_SCREEN( m_kiway );
sheet->SetTimeStamp( GetNewTimeStamp() ); sheet->SetTimeStamp( GetNewTimeStamp() );
sheet->SetParent( m_rootSheet->GetScreen() ); sheet->SetParent( m_rootSheet->GetScreen() );
@ -312,18 +320,20 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
m_currentSheet = sheet.get(); m_currentSheet = sheet.get();
loadSheet( sheetNode ); loadSheet( sheetNode );
sheet->GetScreen()->SetFileName( sheet->GetFileName() ); sheet->GetScreen()->SetFileName( sheet->GetFileName() );
m_rootSheet->GetScreen()->Append(sheet.release()); m_rootSheet->GetScreen()->Append( sheet.release() );
sheetNode = sheetNode->GetNext(); sheetNode = sheetNode->GetNext();
x+=2; x += 2;
if(x>10)
if( x > 10 )
{ {
x = 1; x = 1;
y+=2; y += 2;
} }
} }
}
} else { else
{
while( sheetNode ) while( sheetNode )
{ {
m_currentSheet = m_rootSheet; m_currentSheet = m_rootSheet;
@ -331,7 +341,6 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
sheetNode = sheetNode->GetNext(); sheetNode = sheetNode->GetNext();
} }
} }
} }
@ -343,25 +352,22 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
// Get description node // Get description node
wxXmlNode* descriptionNode = getChildrenNodes( sheetChildren, "description" ); wxXmlNode* descriptionNode = getChildrenNodes( sheetChildren, "description" );
if( descriptionNode ) if( descriptionNode )
{ {
wxString des = descriptionNode->GetContent(); wxString des = descriptionNode->GetContent();
m_currentSheet->SetName(des); m_currentSheet->SetName( des );
std::string filename = des.ToStdString(); std::string filename = des.ToStdString();
ReplaceIllegalFileNameChars(&filename); ReplaceIllegalFileNameChars( &filename );
replace(filename.begin(),filename.end(), ' ', '_'); replace( filename.begin(), filename.end(), ' ', '_' );
wxString fn = wxString(filename+".sch"); wxString fn = wxString( filename + ".sch" );
m_currentSheet->SetFileName(fn); m_currentSheet->SetFileName( fn );
wxFileName fileName = m_currentSheet->GetFileName(); wxFileName fileName = m_currentSheet->GetFileName();
m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() ); m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
} }
// Loop through all busses // Loop through all busses
// From the DTD: "Buses receive names which determine which signals they include. // From the DTD: "Buses receive names which determine which signals they include.
// A bus is a drawing object. It does not create any electrical connections. // A bus is a drawing object. It does not create any electrical connections.
@ -391,7 +397,7 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
wxString netClass = netNode->GetAttribute( "class" ); wxString netClass = netNode->GetAttribute( "class" );
// Load segments of this net // Load segments of this net
loadSegments( netNode , netName, netClass); loadSegments( netNode, netName, netClass );
// Get next net // Get next net
netNode = netNode->GetNext(); netNode = netNode->GetNext();
@ -431,7 +437,8 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
} }
void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, wxString netName, wxString netClass) void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& netName,
const wxString& netClass )
{ {
// Loop through all segments // Loop through all segments
wxXmlNode* currentSegment = aSegmentsNode->GetChildren(); wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
@ -451,7 +458,7 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, wxString netName,
// TODO: handle junctions attributes // TODO: handle junctions attributes
segmentAttribute->GetAttribute( "x" ); segmentAttribute->GetAttribute( "x" );
segmentAttribute->GetAttribute( "y" ); segmentAttribute->GetAttribute( "y" );
screen->Append(loadJunction(segmentAttribute)); screen->Append( loadJunction( segmentAttribute ) );
} }
else if( nodeName == "label" ) else if( nodeName == "label" )
{ {
@ -465,8 +472,7 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, wxString netName,
segmentAttribute->GetAttribute( "rot" ); // Defaults to "R0" segmentAttribute->GetAttribute( "rot" ); // Defaults to "R0"
segmentAttribute->GetAttribute( "xref" ); // Defaults to "no" segmentAttribute->GetAttribute( "xref" ); // Defaults to "no"
screen->Append(loadLabel(segmentAttribute, netName)); screen->Append( loadLabel( segmentAttribute, netName ) );
} }
else if( nodeName == "pinref" ) else if( nodeName == "pinref" )
{ {
@ -531,11 +537,11 @@ SCH_LINE* SCH_EAGLE_PLUGIN::loadSignalWire( wxXmlNode* aWireNode )
} }
SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction( wxXmlNode* aJunction )
SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction(wxXmlNode* aJunction){ {
std::unique_ptr<SCH_JUNCTION> junction( new SCH_JUNCTION ); std::unique_ptr<SCH_JUNCTION> junction( new SCH_JUNCTION );
auto ejunction = EJUNCTION(aJunction); auto ejunction = EJUNCTION( aJunction );
junction->SetPosition( wxPoint( ejunction.x*EUNIT_TO_MIL, -ejunction.y*EUNIT_TO_MIL ) ); junction->SetPosition( wxPoint( ejunction.x*EUNIT_TO_MIL, -ejunction.y*EUNIT_TO_MIL ) );
@ -543,10 +549,11 @@ SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction(wxXmlNode* aJunction){
} }
SCH_GLOBALLABEL* SCH_EAGLE_PLUGIN::loadLabel(wxXmlNode* aLabelNode, wxString aNetName){ SCH_GLOBALLABEL* SCH_EAGLE_PLUGIN::loadLabel(wxXmlNode* aLabelNode, const wxString& aNetName )
{
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL ); std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
auto elabel = ELABEL(aLabelNode, aNetName); auto elabel = ELABEL( aLabelNode, aNetName );
glabel->SetPosition( wxPoint( elabel.x*EUNIT_TO_MIL, -elabel.y*EUNIT_TO_MIL ) ); glabel->SetPosition( wxPoint( elabel.x*EUNIT_TO_MIL, -elabel.y*EUNIT_TO_MIL ) );
glabel->SetText(elabel.netname); glabel->SetText(elabel.netname);
@ -601,7 +608,7 @@ void SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
while( symbolNode ) while( symbolNode )
{ {
m_partlib->AddPart(loadSymbol( symbolNode )); m_partlib->AddPart( loadSymbol( symbolNode ) );
symbolNode = symbolNode->GetNext(); symbolNode = symbolNode->GetNext();
} }
} }
@ -710,6 +717,7 @@ LIB_RECTANGLE* SCH_EAGLE_PLUGIN::loadSymbolRectangle( LIB_PART* aPart, wxXmlNode
return rectangle.release(); return rectangle.release();
} }
LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWireNode ) LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWireNode )
{ {
// TODO: Layer map // TODO: Layer map
@ -729,6 +737,7 @@ LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWir
return polyLine.release(); return polyLine.release();
} }
LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( LIB_PART* aPart, wxXmlNode* aPolygonNode ) LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( LIB_PART* aPart, wxXmlNode* aPolygonNode )
{ {
// TODO: Layer map // TODO: Layer map
@ -737,9 +746,10 @@ LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( LIB_PART* aPart, wxXmlNode*
NODE_MAP polygonChildren = mapChildren( aPolygonNode ); NODE_MAP polygonChildren = mapChildren( aPolygonNode );
wxXmlNode* vertex = getChildrenNodes( polygonChildren, "vertex" ); wxXmlNode* vertex = getChildrenNodes( polygonChildren, "vertex" );
while(vertex) { while( vertex )
auto evertex = EVERTEX( vertex); {
auto v = wxPoint(evertex.x*EUNIT_TO_MIL, -evertex.y*EUNIT_TO_MIL); auto evertex = EVERTEX( vertex );
auto v = wxPoint( evertex.x*EUNIT_TO_MIL, -evertex.y*EUNIT_TO_MIL );
polyLine->AddPoint( v ); polyLine->AddPoint( v );
vertex->GetNext(); vertex->GetNext();
@ -748,6 +758,7 @@ LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( LIB_PART* aPart, wxXmlNode*
return polyLine.release(); return polyLine.release();
} }
LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( LIB_PART* aPart, wxXmlNode* aPin ) LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( LIB_PART* aPart, wxXmlNode* aPin )
{ {
std::unique_ptr<LIB_PIN> pin( new LIB_PIN( aPart ) ); std::unique_ptr<LIB_PIN> pin( new LIB_PIN( aPart ) );
@ -761,7 +772,7 @@ LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( LIB_PART* aPart, wxXmlNode* aPin )
if( epin.rot ) if( epin.rot )
{ {
roti = int(epin.rot->degrees); roti = int( epin.rot->degrees );
} }
switch( roti ) switch( roti )
@ -808,6 +819,7 @@ LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( LIB_PART* aPart, wxXmlNode* aPin )
return pin.release(); return pin.release();
} }
LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibText ) LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibText )
{ {
std::unique_ptr<LIB_TEXT> libtext( new LIB_TEXT( aPart ) ); std::unique_ptr<LIB_TEXT> libtext( new LIB_TEXT( aPart ) );
@ -816,7 +828,8 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibTex
libtext->SetPosition( wxPoint( etext.x * EUNIT_TO_MIL, -etext.y * EUNIT_TO_MIL ) ); libtext->SetPosition( wxPoint( etext.x * EUNIT_TO_MIL, -etext.y * EUNIT_TO_MIL ) );
libtext->SetText( aLibText->GetNodeContent() ); libtext->SetText( aLibText->GetNodeContent() );
libtext->SetTextSize(wxSize(int(etext.size*EUNIT_TO_MIL), int(etext.size*EUNIT_TO_MIL))); libtext->SetTextSize( wxSize( int( etext.size * EUNIT_TO_MIL ),
int( etext.size * EUNIT_TO_MIL ) ) );
return libtext.release(); return libtext.release();
} }

View File

@ -447,7 +447,6 @@ struct ELABEL
opt_string xref; opt_string xref;
wxString netname; wxString netname;
ELABEL( wxXmlNode* aLabel, const wxString& aNetName ); ELABEL( wxXmlNode* aLabel, const wxString& aNetName );
}; };