diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 767b78a0e0..1085e699f8 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -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; } diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index f2f28d51b8..063aaf615f 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -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(); } diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 90366584d5..e08082d7f9 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -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. *