Fixes for Eagle importer.

1) Make sure we set an absolute path on the sheet.
2) Don't mix RTree iterators; wires get skipped between buses.
3) Implement a real ERC error so we don't assert.

Fixes https://gitlab.com/kicad/code/kicad/issues/7042
This commit is contained in:
Jeff Young 2021-06-16 21:02:39 +01:00
parent decfe89091
commit 4b28bac89a
4 changed files with 444 additions and 485 deletions

View File

@ -150,6 +150,10 @@ ERC_ITEM ERC_ITEM::duplicateReference( ERCE_DUPLICATE_REFERENCE,
_( "Duplicate reference designators" ), _( "Duplicate reference designators" ),
wxT( "duplicate_reference" ) ); wxT( "duplicate_reference" ) );
ERC_ITEM ERC_ITEM::busEntryNeeded( ERCE_BUS_ENTRY_NEEDED,
_( "Bus Entry needed" ),
wxT( "bus_entry_needed" ) );
std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( { std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( {
ERC_ITEM::heading_connections, ERC_ITEM::heading_connections,
ERC_ITEM::pinNotConnected, ERC_ITEM::pinNotConnected,
@ -160,6 +164,7 @@ std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( {
ERC_ITEM::labelDangling, ERC_ITEM::labelDangling,
ERC_ITEM::globalLabelDangling, ERC_ITEM::globalLabelDangling,
ERC_ITEM::wireDangling, ERC_ITEM::wireDangling,
ERC_ITEM::busEntryNeeded,
ERC_ITEM::heading_conflicts, ERC_ITEM::heading_conflicts,
ERC_ITEM::duplicateReference, ERC_ITEM::duplicateReference,
@ -217,6 +222,7 @@ std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
case ERCE_EXTRA_UNITS: return std::make_shared<ERC_ITEM>( extraUnits ); case ERCE_EXTRA_UNITS: return std::make_shared<ERC_ITEM>( extraUnits );
case ERCE_DIFFERENT_UNIT_VALUE: return std::make_shared<ERC_ITEM>( differentUnitValue ); case ERCE_DIFFERENT_UNIT_VALUE: return std::make_shared<ERC_ITEM>( differentUnitValue );
case ERCE_DUPLICATE_REFERENCE: return std::make_shared<ERC_ITEM>( duplicateReference ); case ERCE_DUPLICATE_REFERENCE: return std::make_shared<ERC_ITEM>( duplicateReference );
case ERCE_BUS_ENTRY_NEEDED: return std::make_shared<ERC_ITEM>( busEntryNeeded );
case ERCE_UNSPECIFIED: case ERCE_UNSPECIFIED:
default: default:
wxFAIL_MSG( "Unknown ERC error code" ); wxFAIL_MSG( "Unknown ERC error code" );

View File

@ -98,6 +98,7 @@ private:
static ERC_ITEM extraUnits; static ERC_ITEM extraUnits;
static ERC_ITEM differentUnitValue; static ERC_ITEM differentUnitValue;
static ERC_ITEM duplicateReference; static ERC_ITEM duplicateReference;
static ERC_ITEM busEntryNeeded;
/// True if this item is specific to a sheet instance (as opposed to applying to all instances) /// True if this item is specific to a sheet instance (as opposed to applying to all instances)
bool m_sheetSpecific; bool m_sheetSpecific;

View File

@ -69,8 +69,9 @@ enum ERCE_T
ERCE_EXTRA_UNITS, ///< Symbol has more units than are defined. ERCE_EXTRA_UNITS, ///< Symbol has more units than are defined.
ERCE_DIFFERENT_UNIT_VALUE, ///< Units of same symbol have different values. ERCE_DIFFERENT_UNIT_VALUE, ///< Units of same symbol have different values.
ERCE_DUPLICATE_REFERENCE, ///< More than one symbol with the same reference. ERCE_DUPLICATE_REFERENCE, ///< More than one symbol with the same reference.
ERCE_BUS_ENTRY_NEEDED, ///< Importer failed to auto-place a bus entry.
ERCE_LAST = ERCE_DUPLICATE_REFERENCE, ERCE_LAST = ERCE_BUS_ENTRY_NEEDED,
// Errors after this point will not automatically appear in the Severities Panel // Errors after this point will not automatically appear in the Severities Panel

View File

@ -718,10 +718,12 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex )
ReplaceIllegalFileNameChars( &filename ); ReplaceIllegalFileNameChars( &filename );
replace( filename.begin(), filename.end(), ' ', '_' ); replace( filename.begin(), filename.end(), ' ', '_' );
wxString fn = wxString( filename + "." + KiCadSchematicFileExtension ); wxFileName fn( m_filename );
filenameField.SetText( fn ); fn.SetName( filename );
wxFileName fileName( fn ); fn.SetExt( KiCadSchematicFileExtension );
m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
filenameField.SetText( fn.GetFullName() );
m_currentSheet->GetScreen()->SetFileName( fn.GetFullPath() );
m_currentSheet->AutoplaceFields( m_currentSheet->GetScreen(), true ); m_currentSheet->AutoplaceFields( m_currentSheet->GetScreen(), true );
@ -2249,17 +2251,15 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
// for each wire segment, compare each end with all busses. // for each wire segment, compare each end with all busses.
// If the wire end is found to end on a bus segment, place a bus entry symbol. // If the wire end is found to end on a bus segment, place a bus entry symbol.
for( auto it1 = m_currentSheet->GetScreen()->Items().OfType( SCH_LINE_T ).begin(); for( SCH_ITEM* ii : m_currentSheet->GetScreen()->Items().OfType( SCH_LINE_T ) )
it1 != m_currentSheet->GetScreen()->Items().end(); ++it1 )
{ {
SCH_LINE* bus = static_cast<SCH_LINE*>( *it1 ); SCH_LINE* bus = static_cast<SCH_LINE*>( ii );
// Check line type for wire if( !bus->IsBus() )
if( bus->GetLayer() != LAYER_BUS )
continue; continue;
wxPoint busstart = bus->GetStartPoint(); wxPoint busStart = bus->GetStartPoint();
wxPoint busend = bus->GetEndPoint(); wxPoint busEnd = bus->GetEndPoint();
auto entrySize = auto entrySize =
[]( int signX, int signY ) -> wxPoint []( int signX, int signY ) -> wxPoint
@ -2271,39 +2271,35 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
auto testBusHit = auto testBusHit =
[&]( const wxPoint& aPt ) -> bool [&]( const wxPoint& aPt ) -> bool
{ {
return TestSegmentHit( aPt, busstart, busend, 0 ); return TestSegmentHit( aPt, busStart, busEnd, 0 );
}; };
auto it2 = it1; for( SCH_ITEM* jj : m_currentSheet->GetScreen()->Items().OfType( SCH_LINE_T ) )
++it2;
for( ; it2 != m_currentSheet->GetScreen()->Items().end(); ++it2 )
{ {
SCH_LINE* line = static_cast<SCH_LINE*>( *it2 ); SCH_LINE* wire = static_cast<SCH_LINE*>( jj );
// Check line type for bus if( !wire->IsWire() )
if( ( (SCH_LINE*) *it2 )->GetLayer() == LAYER_WIRE ) continue;
{
// Get points of both segments. wxPoint wireStart = wire->GetStartPoint();
wxPoint linestart = line->GetStartPoint(); wxPoint wireEnd = wire->GetEndPoint();
wxPoint lineend = line->GetEndPoint();
// Test for horizontal wire and vertical bus // Test for horizontal wire and vertical bus
if( linestart.y == lineend.y && busstart.x == busend.x ) if( wireStart.y == wireEnd.y && busStart.x == busEnd.x )
{ {
if( testBusHit( linestart ) ) if( testBusHit( wireStart ) )
{ {
// Wire start is on the vertical bus // Wire start is on the vertical bus
if( lineend.x < busstart.x ) if( wireEnd.x < busStart.x )
{ {
// the end of the wire is to the left of the bus // the end of the wire is to the left of the bus
// | // |
// ----| // ----|
// | // |
wxPoint p = linestart + entrySize( -1, 0 ); wxPoint p = wireStart + entrySize( -1, 0 );
if( testBusHit( linestart + entrySize( 0, -1 ) ) ) if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
{ {
// there is room above the wire for the bus entry // there is room above the wire for the bus entry
// | // |
@ -2312,10 +2308,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else if( testBusHit( linestart + entrySize( 0, 1 ) ) ) else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
{ {
// there is room below the wire for the bus entry // there is room below the wire for the bus entry
// ___ | // ___ |
@ -2324,15 +2320,13 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
@ -2342,9 +2336,9 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
// | // |
// |---- // |----
// | // |
wxPoint p = linestart + entrySize( 1, 0 ); wxPoint p = wireStart + entrySize( 1, 0 );
if( testBusHit( linestart + entrySize( 0, -1 ) ) ) if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
{ {
// There is room above the wire for the bus entry // There is room above the wire for the bus entry
// | // |
@ -2353,10 +2347,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p , 4 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p , 4 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else if( testBusHit( linestart + entrySize( 0, 1 ) ) ) else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
{ {
// There is room below the wire for the bus entry // There is room below the wire for the bus entry
// | ___ // | ___
@ -2365,34 +2359,32 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
} }
// Same thing but test end of the wire instead. // Same thing but test end of the wire instead.
if( testBusHit( lineend ) ) if( testBusHit( wireEnd ) )
{ {
// Wire end is on the vertical bus // Wire end is on the vertical bus
if( linestart.x < busstart.x ) if( wireStart.x < busStart.x )
{ {
// start of the wire is to the left of the bus // start of the wire is to the left of the bus
// | // |
// ----| // ----|
// | // |
wxPoint p = lineend + entrySize( -1, 0 ); wxPoint p = wireEnd + entrySize( -1, 0 );
if( testBusHit( lineend + entrySize( 0, -1 ) ) ) if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
{ {
// there is room above the wire for the bus entry // there is room above the wire for the bus entry
// | // |
@ -2401,10 +2393,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else if( testBusHit( lineend + entrySize( 0, -1 ) ) ) else if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
{ {
// there is room below the wire for the bus entry // there is room below the wire for the bus entry
// ___ | // ___ |
@ -2413,15 +2405,13 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, lineend + entrySize( -1, 0 ) ); moveLabels( wire, wireEnd + entrySize( -1, 0 ) );
line->SetEndPoint( lineend + entrySize( -1, 0 ) ); wire->SetEndPoint( wireEnd + entrySize( -1, 0 ) );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
@ -2431,9 +2421,9 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
// | // |
// |---- // |----
// | // |
wxPoint p = lineend + entrySize( 1, 0 ); wxPoint p = wireEnd + entrySize( 1, 0 );
if( testBusHit( lineend + entrySize( 0, -1 ) ) ) if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
{ {
// There is room above the wire for the bus entry // There is room above the wire for the bus entry
// | // |
@ -2442,10 +2432,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else if( testBusHit( lineend + entrySize( 0, 1 ) ) ) else if( testBusHit( wireEnd + entrySize( 0, 1 ) ) )
{ {
// There is room below the wire for the bus entry // There is room below the wire for the bus entry
// | ___ // | ___
@ -2454,37 +2444,35 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
} }
} // if( linestart.y == lineend.y && busstart.x == busend.x) } // if( wireStart.y == wireEnd.y && busStart.x == busEnd.x)
// Test for vertical wire and horizontal bus // Test for vertical wire and horizontal bus
if( linestart.x == lineend.x && busstart.y == busend.y ) if( wireStart.x == wireEnd.x && busStart.y == busEnd.y )
{ {
if( testBusHit( linestart ) ) if( testBusHit( wireStart ) )
{ {
// Wire start is on the bus // Wire start is on the bus
if( lineend.y < busstart.y ) if( wireEnd.y < busStart.y )
{ {
// the end of the wire is above the bus // the end of the wire is above the bus
// | // |
// | // |
// ----- // -----
wxPoint p = linestart + entrySize( 0, -1 ); wxPoint p = wireStart + entrySize( 0, -1 );
if( testBusHit( linestart + entrySize( -1, 0 ) ) ) if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
{ {
// there is room to the left of the wire for the bus entry // there is room to the left of the wire for the bus entry
// | // |
@ -2494,10 +2482,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else if( testBusHit( linestart + entrySize( 1, 0 ) ) ) else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
{ {
// there is room to the right of the wire for the bus entry // there is room to the right of the wire for the bus entry
// | // |
@ -2507,15 +2495,13 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
@ -2525,9 +2511,9 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
// ----- // -----
// | // |
// | // |
wxPoint p = linestart + entrySize( 0, 1 ); wxPoint p = wireStart + entrySize( 0, 1 );
if( testBusHit( linestart + entrySize( -1, 0 ) ) ) if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
{ {
// there is room to the left of the wire for the bus entry // there is room to the left of the wire for the bus entry
// ----- // -----
@ -2537,10 +2523,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else if( testBusHit( linestart + entrySize( 1, 0 ) ) ) else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
{ {
// there is room to the right of the wire for the bus entry // there is room to the right of the wire for the bus entry
// ----- // -----
@ -2550,33 +2536,31 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetStartPoint( p ); wire->SetStartPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
} }
if( testBusHit( lineend ) ) if( testBusHit( wireEnd ) )
{ {
// Wire end is on the bus // Wire end is on the bus
if( linestart.y < busstart.y ) if( wireStart.y < busStart.y )
{ {
// the start of the wire is above the bus // the start of the wire is above the bus
// | // |
// | // |
// ----- // -----
wxPoint p = lineend + entrySize( 0, -1 ); wxPoint p = wireEnd + entrySize( 0, -1 );
if( testBusHit( lineend + entrySize( -1, 0 ) ) ) if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
{ {
// there is room to the left of the wire for the bus entry // there is room to the left of the wire for the bus entry
// | // |
@ -2586,10 +2570,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else if( testBusHit( lineend + entrySize( 1, 0 ) ) ) else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
{ {
// there is room to the right of the wire for the bus entry // there is room to the right of the wire for the bus entry
// | // |
@ -2599,15 +2583,13 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
@ -2617,9 +2599,9 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
// ----- // -----
// | // |
// | // |
wxPoint p = lineend + entrySize( 0, 1 ); wxPoint p = wireEnd + entrySize( 0, 1 );
if( testBusHit( lineend + entrySize( -1, 0 ) ) ) if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
{ {
// there is room to the left of the wire for the bus entry // there is room to the left of the wire for the bus entry
// ----- // -----
@ -2629,10 +2611,10 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else if( testBusHit( lineend + entrySize( 1, 0 ) ) ) else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
{ {
// there is room to the right of the wire for the bus entry // there is room to the right of the wire for the bus entry
// ----- // -----
@ -2642,160 +2624,129 @@ void SCH_EAGLE_PLUGIN::addBusEntries()
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
line->SetEndPoint( p ); wire->SetEndPoint( p );
} }
else else
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 ); auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
m_currentSheet->GetScreen()->Append( marker ); m_currentSheet->GetScreen()->Append( marker );
} }
} }
} }
} }
linestart = line->GetStartPoint(); wireStart = wire->GetStartPoint();
lineend = line->GetEndPoint(); wireEnd = wire->GetEndPoint();
busstart = bus->GetStartPoint(); busStart = bus->GetStartPoint();
busend = bus->GetEndPoint(); busEnd = bus->GetEndPoint();
// bus entry wire isn't horizontal or vertical // bus entry wire isn't horizontal or vertical
if( testBusHit( linestart ) ) if( testBusHit( wireStart ) )
{ {
wxPoint wirevector = linestart - lineend; wxPoint wirevector = wireStart - wireEnd;
if( wirevector.x > 0 ) if( wirevector.x > 0 )
{ {
if( wirevector.y > 0 ) if( wirevector.y > 0 )
{ {
wxPoint p = linestart + entrySize( -1, -1 ); wxPoint p = wireStart + entrySize( -1, -1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p );
if( p == lineend ) // wire is overlapped by bus entry symbol moveLabels( wire, p );
m_currentSheet->GetScreen()->DeleteItem( line ); wire->SetStartPoint( p );
else
line->SetStartPoint( p );
} }
else else
{ {
wxPoint p = linestart + entrySize( -1, 1 ); wxPoint p = wireStart + entrySize( -1, 1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
wire->SetStartPoint( p );
if( p == lineend ) // wire is overlapped by bus entry symbol
m_currentSheet->GetScreen()->DeleteItem( line );
else
line->SetStartPoint( p );
} }
} }
else else
{ {
if( wirevector.y > 0 ) if( wirevector.y > 0 )
{ {
wxPoint p = linestart + entrySize( 1, -1 ); wxPoint p = wireStart + entrySize( 1, -1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
wire->SetStartPoint( p );
if( p == lineend ) // wire is overlapped by bus entry symbol
m_currentSheet->GetScreen()->DeleteItem( line );
else
line->SetStartPoint( p );
} }
else else
{ {
wxPoint p = linestart + entrySize( 1, 1 ); wxPoint p = wireStart + entrySize( 1, 1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p );
if( p == lineend ) // wire is overlapped by bus entry symbol moveLabels( wire, p );
m_currentSheet->GetScreen()->DeleteItem( line ); wire->SetStartPoint( p );
else
line->SetStartPoint( p );
} }
} }
} }
else if( testBusHit( lineend ) ) else if( testBusHit( wireEnd ) )
{ {
wxPoint wirevector = linestart - lineend; wxPoint wirevector = wireStart - wireEnd;
if( wirevector.x > 0 ) if( wirevector.x > 0 )
{ {
if( wirevector.y > 0 ) if( wirevector.y > 0 )
{ {
wxPoint p = lineend + entrySize( 1, 1 ); wxPoint p = wireEnd + entrySize( 1, 1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
wire->SetEndPoint( p );
if( p == linestart ) // wire is overlapped by bus entry symbol
m_currentSheet->GetScreen()->DeleteItem( line );
else
line->SetEndPoint( p );
} }
else else
{ {
wxPoint p = lineend + entrySize( 1, -1 ); wxPoint p = wireEnd + entrySize( 1, -1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p ); moveLabels( wire, p );
wire->SetEndPoint( p );
if( p == linestart ) // wire is overlapped by bus entry symbol
m_currentSheet->GetScreen()->DeleteItem( line );
else
line->SetEndPoint( p );
} }
} }
else else
{ {
if( wirevector.y > 0 ) if( wirevector.y > 0 )
{ {
wxPoint p = lineend + entrySize( -1, 1 ); wxPoint p = wireEnd + entrySize( -1, 1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p );
if( p == linestart ) // wire is overlapped by bus entry symbol moveLabels( wire, p );
m_currentSheet->GetScreen()->DeleteItem( line ); wire->SetEndPoint( p );
else
line->SetEndPoint( p );
} }
else else
{ {
wxPoint p = lineend + entrySize( -1, -1 ); wxPoint p = wireEnd + entrySize( -1, -1 );
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( busEntry ); m_currentSheet->GetScreen()->Append( busEntry );
moveLabels( line, p );
if( p == linestart ) // wire is overlapped by bus entry symbol moveLabels( wire, p );
m_currentSheet->GetScreen()->DeleteItem( line ); wire->SetEndPoint( p );
else
line->SetEndPoint( p );
} }
} }
} }
} }
} }
} // for ( bus ..
} }