Extract SCH_LINE::BreakAt( aP ) from SCH_EDIT_FRAME::BreakSegment

This commit is contained in:
Roberto Fernandez Bautista 2023-01-15 13:28:25 +01:00
parent c7f33e21f8
commit c4bde9c7e8
3 changed files with 30 additions and 7 deletions

View File

@ -275,20 +275,17 @@ void SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const VECTOR2I& aPoint,
if( aScreen == nullptr ) if( aScreen == nullptr )
aScreen = GetScreen(); aScreen = GetScreen();
SCH_LINE* newSegment = static_cast<SCH_LINE*>( aSegment->Duplicate() ); // Save the copy of aSegment before breaking it
SaveCopyInUndoList( aScreen, aSegment, UNDO_REDO::CHANGED, true );
newSegment->SetStartPoint( aPoint ); SCH_LINE* newSegment = aSegment->BreakAt( aPoint );
newSegment->SetConnectivityDirty( true ); aSegment->SetFlags( IS_CHANGED | IS_BROKEN );
newSegment->SetFlags( IS_NEW | IS_BROKEN ); newSegment->SetFlags( IS_NEW | IS_BROKEN );
AddToScreen( newSegment, aScreen ); AddToScreen( newSegment, aScreen );
SaveCopyInUndoList( aScreen, newSegment, UNDO_REDO::NEWITEM, true ); SaveCopyInUndoList( aScreen, newSegment, UNDO_REDO::NEWITEM, true );
SaveCopyInUndoList( aScreen, aSegment, UNDO_REDO::CHANGED, true );
aSegment->SetFlags( IS_CHANGED | IS_BROKEN );
UpdateItem( aSegment, false, true ); UpdateItem( aSegment, false, true );
aSegment->SetEndPoint( aPoint );
if( aNewSegment ) if( aNewSegment )
*aNewSegment = newSegment; *aNewSegment = newSegment;

View File

@ -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<SCH_LINE*>( Duplicate() );
newSegment->SetStartPoint( aPoint );
newSegment->SetConnectivityDirty( true );
SetEndPoint( aPoint );
return newSegment;
}
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{ {
if( IsConnectable() ) if( IsConnectable() )

View File

@ -232,6 +232,20 @@ public:
*/ */
SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions ); 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; bool IsParallel( const SCH_LINE* aLine ) const;
void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override; void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;