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 )
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 );
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;

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 )
{
if( IsConnectable() )

View File

@ -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<DANGLING_END_ITEM>& aItemList ) override;