From c4bde9c7e89c0e268165aa66d50f13efb7c805f6 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sun, 15 Jan 2023 13:28:25 +0100 Subject: [PATCH] Extract SCH_LINE::BreakAt( aP ) from SCH_EDIT_FRAME::BreakSegment --- eeschema/bus-wire-junction.cpp | 11 ++++------- eeschema/sch_line.cpp | 12 ++++++++++++ eeschema/sch_line.h | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index b56bbe3251..42e6cac181 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -275,20 +275,17 @@ void SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const VECTOR2I& aPoint, if( aScreen == nullptr ) aScreen = GetScreen(); - SCH_LINE* newSegment = static_cast( aSegment->Duplicate() ); + // Save the copy of aSegment before breaking it + SaveCopyInUndoList( aScreen, aSegment, UNDO_REDO::CHANGED, true ); - newSegment->SetStartPoint( aPoint ); - newSegment->SetConnectivityDirty( true ); + SCH_LINE* newSegment = aSegment->BreakAt( aPoint ); + aSegment->SetFlags( IS_CHANGED | IS_BROKEN ); newSegment->SetFlags( IS_NEW | IS_BROKEN ); AddToScreen( newSegment, aScreen ); SaveCopyInUndoList( aScreen, newSegment, UNDO_REDO::NEWITEM, true ); - SaveCopyInUndoList( aScreen, aSegment, UNDO_REDO::CHANGED, true ); - - aSegment->SetFlags( IS_CHANGED | IS_BROKEN ); UpdateItem( aSegment, false, true ); - aSegment->SetEndPoint( aPoint ); if( aNewSegment ) *aNewSegment = newSegment; diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 36afdf56f4..99bae09c1a 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -558,6 +558,18 @@ SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCh } +SCH_LINE* SCH_LINE::BreakAt( const VECTOR2I& aPoint ) +{ + SCH_LINE* newSegment = static_cast( Duplicate() ); + + newSegment->SetStartPoint( aPoint ); + newSegment->SetConnectivityDirty( true ); + SetEndPoint( aPoint ); + + return newSegment; +} + + void SCH_LINE::GetEndPoints( std::vector & aItemList ) { if( IsConnectable() ) diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 08c1f22dc6..4782d79cb1 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -232,6 +232,20 @@ public: */ SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions ); + /** + * Break this segment into two at the specified point. + * + * @note No checks are made to verify if aPoint is contained within the segment. That is + * the responsibility of the caller. + * + * @note It is the responsibility of the caller to add the newly created segment + * to the screen. + * + * @param aPoint Point at which to break the segment + * @return The newly created segment. + */ + SCH_LINE* BreakAt( const VECTOR2I& aPoint ); + bool IsParallel( const SCH_LINE* aLine ) const; void GetEndPoints( std::vector& aItemList ) override;