Eagle importer: use only global net labels

Local net labels are preceded with sheetpath (even for single sheet
schematics it is '/') causing net name conflicts between schematics and
layout. It can be easily avoided by using exclusively global net
labels, at the cost having uglier schematics.
This commit is contained in:
Maciej Suminski 2018-02-16 23:48:58 +01:00
parent de72ef8518
commit b1f456fade
2 changed files with 44 additions and 153 deletions

View File

@ -471,38 +471,6 @@ void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode )
}
void SCH_EAGLE_PLUGIN::countNets( wxXmlNode* aSchematicNode )
{
// Map all children into a readable dictionary
NODE_MAP schematicChildren = MapChildren( aSchematicNode );
// Loop through all the sheets
wxXmlNode* sheetNode = schematicChildren["sheets"]->GetChildren();
while( sheetNode )
{
NODE_MAP sheetChildren = MapChildren( sheetNode );
// Loop through all nets
// From the DTD: "Net is an electrical connection in a schematic."
wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" );
while( netNode )
{
wxString netName = netNode->GetAttribute( "name" );
if( m_netCounts.count( netName ) )
m_netCounts[netName] = m_netCounts[netName] + 1;
else
m_netCounts[netName] = 1;
// Get next net
netNode = netNode->GetNext();
}
sheetNode = sheetNode->GetNext();
}
}
void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
{
// Map all children into a readable dictionary
@ -534,10 +502,6 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
libraryNode = libraryNode->GetNext();
}
// find all nets and count how many sheets they appear on.
// local labels will be used for nets found only on that sheet.
countNets( aSchematicNode );
// Loop through all the sheets
wxXmlNode* sheetNode = schematicChildren["sheets"]->GetChildren();
@ -757,8 +721,6 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n
wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
SCH_SCREEN* screen = m_currentSheet->GetScreen();
int segmentCount = countChildren( aSegmentsNode, "segment" );
// wxCHECK( screen, [>void<] );
while( currentSegment )
{
@ -826,25 +788,12 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n
{
wxString netname = escapeName( netName );
// Add a global label if the net appears on more than one Eagle sheet
if( m_netCounts[netName.ToStdString()] > 1 )
{
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
glabel->SetPosition( wire->GetStartPoint() );
glabel->SetText( netname );
glabel->SetTextSize( wxSize( 10, 10 ) );
glabel->SetLabelSpinStyle( 0 );
screen->Append( glabel.release() );
}
else if( segmentCount > 1 )
{
std::unique_ptr<SCH_LABEL> label( new SCH_LABEL );
label->SetPosition( wire->GetStartPoint() );
label->SetText( netname );
label->SetTextSize( wxSize( 10, 10 ) );
label->SetLabelSpinStyle( 0 );
screen->Append( label.release() );
}
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
glabel->SetPosition( wire->GetStartPoint() );
glabel->SetText( netname );
glabel->SetTextSize( wxSize( 20, 20 ) );
glabel->SetLabelSpinStyle( 0 );
screen->Append( glabel.release() );
}
@ -902,112 +851,56 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode,
const DLIST<SCH_LINE>& segmentWires )
{
auto elabel = ELABEL( aLabelNode, aNetName );
wxPoint elabelpos( elabel.x.ToSchUnits(), -elabel.y.ToSchUnits() );
wxString netname = escapeName( elabel.netname );
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
glabel->SetPosition( elabelpos );
glabel->SetText( netname );
glabel->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
glabel->SetLabelSpinStyle( 2 );
// Determine if the Label is a local and global label based on the number of sheets the net appears on.
if( m_netCounts[aNetName] > 1 )
if( elabel.rot )
{
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
glabel->SetPosition( elabelpos );
glabel->SetText( netname );
glabel->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
glabel->SetLabelSpinStyle( 2 );
glabel->SetLabelSpinStyle( ( int( elabel.rot->degrees ) / 90 + 2 ) % 4 );
if( elabel.rot )
{
glabel->SetLabelSpinStyle( ( int( elabel.rot->degrees ) / 90 + 2 ) % 4 );
if( elabel.rot->mirror
&& ( glabel->GetLabelSpinStyle() == 0 || glabel->GetLabelSpinStyle() == 2 ) )
glabel->SetLabelSpinStyle( glabel->GetLabelSpinStyle() % 4 );
}
SCH_LINE* wire;
SCH_LINE* next_wire;
bool labelOnWire = false;
auto glabelPosition = glabel->GetPosition();
// determine if the segment has been labelled.
for( wire = segmentWires.begin(); wire; wire = next_wire )
{
next_wire = wire->Next();
if( wire->HitTest( glabelPosition, 0 ) )
{
labelOnWire = true;
break;
}
}
wire = segmentWires.begin();
// Reposition label if necessary
if( labelOnWire == false )
{
wxPoint newLabelPos = findNearestLinePoint( elabelpos, segmentWires );
if( wire )
{
glabel->SetPosition( newLabelPos );
}
}
return glabel.release();
if( elabel.rot->mirror
&& ( glabel->GetLabelSpinStyle() == 0 || glabel->GetLabelSpinStyle() == 2 ) )
glabel->SetLabelSpinStyle( glabel->GetLabelSpinStyle() % 4 );
}
else
SCH_LINE* wire;
SCH_LINE* next_wire;
bool labelOnWire = false;
auto glabelPosition = glabel->GetPosition();
// determine if the segment has been labelled.
for( wire = segmentWires.begin(); wire; wire = next_wire )
{
std::unique_ptr<SCH_LABEL> label( new SCH_LABEL );
label->SetPosition( elabelpos );
label->SetText( netname );
label->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
next_wire = wire->Next();
label->SetLabelSpinStyle( 0 );
if( elabel.rot )
if( wire->HitTest( glabelPosition, 0 ) )
{
label->SetLabelSpinStyle( int(elabel.rot->degrees / 90) % 4 );
if( elabel.rot->mirror
&& ( label->GetLabelSpinStyle() == 0 || label->GetLabelSpinStyle() == 2 ) )
label->SetLabelSpinStyle( (label->GetLabelSpinStyle() + 2) % 4 );
labelOnWire = true;
break;
}
SCH_LINE* wire;
SCH_LINE* next_wire;
bool labelOnWire = false;
auto labelPosition = label->GetPosition();
for( wire = segmentWires.begin(); wire; wire = next_wire )
{
next_wire = wire->Next();
if( wire->HitTest( labelPosition, 0 ) )
{
labelOnWire = true;
break;
}
}
wire = segmentWires.begin();
// Reposition label if necessary
if( labelOnWire == false )
{
if( wire )
{
wxPoint newLabelPos = findNearestLinePoint( elabelpos, segmentWires );
label->SetPosition( newLabelPos );
}
}
return label.release();
}
wire = segmentWires.begin();
// Reposition label if necessary
if( labelOnWire == false )
{
wxPoint newLabelPos = findNearestLinePoint( elabelpos, segmentWires );
if( wire )
{
glabel->SetPosition( newLabelPos );
}
}
return glabel.release();
}

View File

@ -137,7 +137,6 @@ private:
void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
void loadInstance( wxXmlNode* aInstanceNode );
EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
void countNets( wxXmlNode* aSchematicNode );
/// Moves any labels on the wire to the new end point of the wire.
void moveLabels( SCH_ITEM* aWire, const wxPoint& aNewEndPoint );
@ -188,7 +187,6 @@ private:
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<wxString, int> m_netCounts;
std::map<int, SCH_LAYER_ID> m_layerMap;
};