Eeschema: Remove wire under a placed component

CHANGE: In Eeschema, when placing a component directly over an existing
wire, the wire is automatically removed where it shorted pins.

This helps workflow in Eeschema, allowing one to quickly add components
to existing lines.

Fixes: lp:1678449
* https://bugs.launchpad.net/kicad/+bug/1678449
This commit is contained in:
Seth Hillbrand 2017-12-01 14:53:23 -08:00 committed by Wayne Stambaugh
parent c74437a44e
commit a240f88785
3 changed files with 63 additions and 5 deletions

View File

@ -437,6 +437,45 @@ void SCH_EDIT_FRAME::SaveWireImage()
}
void SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend )
{
SCH_LINE* line;
if( aStart == aEnd )
return;
for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = item->Next() )
{
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( item->Type() != SCH_LINE_T || item->GetLayer() != LAYER_WIRE )
continue;
line = (SCH_LINE*) item;
if( !IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aStart ) ||
!IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aEnd ) )
continue;
// Step 1: break the segment on one end. return_line remains line if not broken.
// Ensure that *line points to the segment containing aEnd
SCH_LINE* return_line = line;
aAppend |= BreakSegment( line, aStart, aAppend, &return_line );
if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aEnd ) )
line = return_line;
// Step 2: break the remaining segment. return_line remains line if not broken.
// Ensure that *line _also_ contains aStart. This is our overlapping segment
aAppend |= BreakSegment( line, aEnd, aAppend, &return_line );
if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aStart ) )
line = return_line;
SaveCopyInUndoList( (SCH_ITEM*)line, UR_DELETED, aAppend );
GetScreen()->Remove( (SCH_ITEM*)line );
}
}
bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend )
{
SCH_ITEM* item = NULL;
@ -531,7 +570,8 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend )
}
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE *aSegment, const wxPoint& aPoint, bool aAppend )
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend,
SCH_LINE** aNewSegment )
{
if( !IsPointOnSegment( aSegment->GetStartPoint(), aSegment->GetEndPoint(), aPoint )
|| aSegment->IsEndPoint( aPoint ) )
@ -545,6 +585,9 @@ bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE *aSegment, const wxPoint& aPoint, bo
aSegment->SetEndPoint( aPoint );
GetScreen()->Append( newSegment );
if( aNewSegment )
*aNewSegment = newSegment;
return true;
}

View File

@ -1446,10 +1446,13 @@ void SCH_EDIT_FRAME::addCurrentItemToList( bool aRedraw )
{
std::vector< wxPoint > pts;
item->GetConnectionPoints( pts );
for( auto i : pts )
for( auto i = pts.begin(); i != pts.end(); i++ )
{
if( screen->IsJunctionNeeded( i, true ) )
AddJunction( i, true );
for( auto j = i + 1; j != pts.end(); j++ )
TrimWire( *i, *j, true );
if( screen->IsJunctionNeeded( *i, true ) )
AddJunction( *i, true );
}
screen->TestDanglingEnds();
}

View File

@ -471,9 +471,11 @@ public:
* @param aSegment Line segment to break
* @param aPoint Point at which to break the segment
* @param aAppend Add the changes to the previous undo state
* @param aNewSegment Pointer to the newly created segment (if given and created)
* @return True if any wires or buses were broken.
*/
bool BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend = false );
bool BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend = false,
SCH_LINE** aNewSegment = NULL );
/**
* Checks every wire and bus for a intersection at \a aPoint and break into two segments
@ -957,6 +959,16 @@ private:
*/
bool SchematicCleanUp( bool aAppend = false );
/**
* If any single wire passes through _both points_, remove the portion between the two points,
* potentially splitting the wire into two.
*
* @param aStart The starting point for trimmming
* @param aEnd The ending point for trimming
* @param aAppend Should the line changes be appended to a previous undo state
*/
void TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend = true );
/**
* Start moving \a aItem using the mouse.
*