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,6 +181,7 @@ EWIRE::EWIRE( wxXmlNode* aWire )
cap = EWIRE::FLAT; cap = EWIRE::FLAT;
} }
EJUNCTION::EJUNCTION( wxXmlNode* aJunction ) EJUNCTION::EJUNCTION( wxXmlNode* aJunction )
{ {
/* /*
@ -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,7 +213,6 @@ 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" );
@ -219,7 +220,6 @@ ELABEL::ELABEL( wxXmlNode* aLabel, const wxString& aNetName )
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
@ -534,10 +536,9 @@ EPIN::EPIN( wxXmlNode* aPin ){
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
@ -198,10 +202,12 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
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
@ -294,13 +300,15 @@ 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); wxPoint pos = wxPoint( x*1000, y*1000);
std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( pos ) ); std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( pos ) );
SCH_SCREEN* screen = new SCH_SCREEN( m_kiway ); SCH_SCREEN* screen = new SCH_SCREEN( m_kiway );
@ -316,14 +324,16 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
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,6 +352,7 @@ 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();
@ -356,12 +366,8 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
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.
@ -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();
@ -466,7 +473,6 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, wxString netName,
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,8 +537,8 @@ 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 );
@ -543,7 +549,8 @@ 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 );
@ -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,7 +746,8 @@ 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 evertex = EVERTEX( vertex );
auto v = wxPoint( evertex.x*EUNIT_TO_MIL, -evertex.y*EUNIT_TO_MIL ); auto v = wxPoint( evertex.x*EUNIT_TO_MIL, -evertex.y*EUNIT_TO_MIL );
polyLine->AddPoint( v ); polyLine->AddPoint( v );
@ -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 ) );
@ -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 );
}; };